]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.8.0-201302222047.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.8.0-201302222047.patch
CommitLineData
8048c530
PK
1diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2index b89a739..dba90c5 100644
3--- a/Documentation/dontdiff
4+++ b/Documentation/dontdiff
5@@ -2,9 +2,11 @@
6 *.aux
7 *.bin
8 *.bz2
9+*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13+*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17@@ -14,6 +16,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21+*.gmo
22 *.grep
23 *.grp
24 *.gz
25@@ -48,14 +51,17 @@
26 *.tab.h
27 *.tex
28 *.ver
29+*.vim
30 *.xml
31 *.xz
32 *_MODULES
33+*_reg_safe.h
34 *_vga16.c
35 *~
36 \#*#
37 *.9
38-.*
39+.[^g]*
40+.gen*
41 .*.d
42 .mm
43 53c700_d.h
44@@ -69,6 +75,7 @@ Image
45 Module.markers
46 Module.symvers
47 PENDING
48+PERF*
49 SCCS
50 System.map*
51 TAGS
52@@ -80,6 +87,7 @@ aic7*seq.h*
53 aicasm
54 aicdb.h*
55 altivec*.c
56+ashldi3.S
57 asm-offsets.h
58 asm_offsets.h
59 autoconf.h*
60@@ -92,19 +100,24 @@ bounds.h
61 bsetup
62 btfixupprep
63 build
64+builtin-policy.h
65 bvmlinux
66 bzImage*
67 capability_names.h
68 capflags.c
69 classlist.h*
70+clut_vga16.c
71+common-cmds.h
72 comp*.log
73 compile.h*
74 conf
75 config
76 config-*
77 config_data.h*
78+config.c
79 config.mak
80 config.mak.autogen
81+config.tmp
82 conmakehash
83 consolemap_deftbl.c*
84 cpustr.h
85@@ -115,9 +128,11 @@ devlist.h*
86 dnotify_test
87 docproc
88 dslm
89+dtc-lexer.lex.c
90 elf2ecoff
91 elfconfig.h*
92 evergreen_reg_safe.h
93+exception_policy.conf
94 fixdep
95 flask.h
96 fore200e_mkfirm
97@@ -125,12 +140,15 @@ fore200e_pca_fw.c*
98 gconf
99 gconf.glade.h
100 gen-devlist
101+gen-kdb_cmds.c
102 gen_crc32table
103 gen_init_cpio
104 generated
105 genheaders
106 genksyms
107 *_gray256.c
108+hash
109+hid-example
110 hpet_example
111 hugepage-mmap
112 hugepage-shm
113@@ -145,14 +163,14 @@ int32.c
114 int4.c
115 int8.c
116 kallsyms
117-kconfig
118+kern_constants.h
119 keywords.c
120 ksym.c*
121 ksym.h*
122 kxgettext
123 lex.c
124 lex.*.c
125-linux
126+lib1funcs.S
127 logo_*.c
128 logo_*_clut224.c
129 logo_*_mono.c
130@@ -162,14 +180,15 @@ mach-types.h
131 machtypes.h
132 map
133 map_hugetlb
134-media
135 mconf
136+mdp
137 miboot*
138 mk_elfconfig
139 mkboot
140 mkbugboot
141 mkcpustr
142 mkdep
143+mkpiggy
144 mkprep
145 mkregtable
146 mktables
147@@ -185,6 +204,8 @@ oui.c*
148 page-types
149 parse.c
150 parse.h
151+parse-events*
152+pasyms.h
153 patches*
154 pca200e.bin
155 pca200e_ecd.bin2
156@@ -194,6 +215,7 @@ perf-archive
157 piggyback
158 piggy.gzip
159 piggy.S
160+pmu-*
161 pnmtologo
162 ppc_defs.h*
163 pss_boot.h
164@@ -203,7 +225,10 @@ r200_reg_safe.h
165 r300_reg_safe.h
166 r420_reg_safe.h
167 r600_reg_safe.h
168+realmode.lds
169+realmode.relocs
170 recordmcount
171+regdb.c
172 relocs
173 rlim_names.h
174 rn50_reg_safe.h
175@@ -213,8 +238,11 @@ series
176 setup
177 setup.bin
178 setup.elf
179+size_overflow_hash.h
180 sImage
181+slabinfo
182 sm_tbl*
183+sortextable
184 split-include
185 syscalltab.h
186 tables.c
187@@ -224,6 +252,7 @@ tftpboot.img
188 timeconst.h
189 times.h*
190 trix_boot.h
191+user_constants.h
192 utsrelease.h*
193 vdso-syms.lds
194 vdso.lds
195@@ -235,13 +264,17 @@ vdso32.lds
196 vdso32.so.dbg
197 vdso64.lds
198 vdso64.so.dbg
199+vdsox32.lds
200+vdsox32-syms.lds
201 version.h*
202 vmImage
203 vmlinux
204 vmlinux-*
205 vmlinux.aout
206 vmlinux.bin.all
207+vmlinux.bin.bz2
208 vmlinux.lds
209+vmlinux.relocs
210 vmlinuz
211 voffset.h
212 vsyscall.lds
213@@ -249,9 +282,11 @@ vsyscall_32.lds
214 wanxlfw.inc
215 uImage
216 unifdef
217+utsrelease.h
218 wakeup.bin
219 wakeup.elf
220 wakeup.lds
221 zImage*
222 zconf.hash.c
223+zconf.lex.c
224 zoffset.h
225diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
226index 6c72381..2fe9ae4 100644
227--- a/Documentation/kernel-parameters.txt
228+++ b/Documentation/kernel-parameters.txt
229@@ -917,6 +917,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
230 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
231 Default: 1024
232
233+ grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
234+ ignore grsecurity's /proc restrictions
235+
236+
237 hashdist= [KNL,NUMA] Large hashes allocated during boot
238 are distributed across NUMA nodes. Defaults on
239 for 64-bit NUMA, off otherwise.
240@@ -2116,6 +2120,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
241 the specified number of seconds. This is to be used if
242 your oopses keep scrolling off the screen.
243
244+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
245+ virtualization environments that don't cope well with the
246+ expand down segment used by UDEREF on X86-32 or the frequent
247+ page table updates on X86-64.
248+
249+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
250+
251 pcbit= [HW,ISDN]
252
253 pcd. [PARIDE]
254diff --git a/Makefile b/Makefile
255index d69266c..e4f6593 100644
256--- a/Makefile
257+++ b/Makefile
258@@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
259
260 HOSTCC = gcc
261 HOSTCXX = g++
262-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
263-HOSTCXXFLAGS = -O2
264+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
265+HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
266+HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
267
268 # Decide whether to build built-in, modular, or both.
269 # Normally, just do built-in.
270@@ -414,8 +415,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
271 # Rules shared between *config targets and build targets
272
273 # Basic helpers built in scripts/
274-PHONY += scripts_basic
275-scripts_basic:
276+PHONY += scripts_basic gcc-plugins
277+scripts_basic: gcc-plugins
278 $(Q)$(MAKE) $(build)=scripts/basic
279 $(Q)rm -f .tmp_quiet_recordmcount
280
281@@ -575,6 +576,64 @@ else
282 KBUILD_CFLAGS += -O2
283 endif
284
285+ifndef DISABLE_PAX_PLUGINS
286+ifeq ($(call cc-ifversion, -ge, 0408, y), y)
287+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
288+else
289+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
290+endif
291+ifneq ($(PLUGINCC),)
292+ifndef DISABLE_PAX_CONSTIFY_PLUGIN
293+ifndef CONFIG_UML
294+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
295+endif
296+endif
297+ifdef CONFIG_PAX_MEMORY_STACKLEAK
298+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
299+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
300+endif
301+ifdef CONFIG_KALLOCSTAT_PLUGIN
302+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
303+endif
304+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
305+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
306+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
307+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
308+endif
309+ifdef CONFIG_CHECKER_PLUGIN
310+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
311+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
312+endif
313+endif
314+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
315+ifdef CONFIG_PAX_SIZE_OVERFLOW
316+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
317+endif
318+ifdef CONFIG_PAX_LATENT_ENTROPY
319+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
320+endif
321+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
322+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
323+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS)
324+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
325+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
326+ifeq ($(KBUILD_EXTMOD),)
327+gcc-plugins:
328+ $(Q)$(MAKE) $(build)=tools/gcc
329+else
330+gcc-plugins: ;
331+endif
332+else
333+gcc-plugins:
334+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
335+ $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
336+else
337+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
338+endif
339+ $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
340+endif
341+endif
342+
343 include $(srctree)/arch/$(SRCARCH)/Makefile
344
345 ifdef CONFIG_READABLE_ASM
346@@ -731,7 +790,7 @@ export mod_sign_cmd
347
348
349 ifeq ($(KBUILD_EXTMOD),)
350-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
351+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
352
353 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
354 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
355@@ -778,6 +837,8 @@ endif
356
357 # The actual objects are generated when descending,
358 # make sure no implicit rule kicks in
359+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
360+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
361 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
362
363 # Handle descending into subdirectories listed in $(vmlinux-dirs)
364@@ -787,7 +848,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
365 # Error messages still appears in the original language
366
367 PHONY += $(vmlinux-dirs)
368-$(vmlinux-dirs): prepare scripts
369+$(vmlinux-dirs): gcc-plugins prepare scripts
370 $(Q)$(MAKE) $(build)=$@
371
372 # Store (new) KERNELRELASE string in include/config/kernel.release
373@@ -831,6 +892,7 @@ prepare0: archprepare FORCE
374 $(Q)$(MAKE) $(build)=.
375
376 # All the preparing..
377+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
378 prepare: prepare0
379
380 # Generate some files
381@@ -938,6 +1000,8 @@ all: modules
382 # using awk while concatenating to the final file.
383
384 PHONY += modules
385+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
386+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
387 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
388 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
389 @$(kecho) ' Building modules, stage 2.';
390@@ -953,7 +1017,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
391
392 # Target to prepare building external modules
393 PHONY += modules_prepare
394-modules_prepare: prepare scripts
395+modules_prepare: gcc-plugins prepare scripts
396
397 # Target to install modules
398 PHONY += modules_install
399@@ -1019,7 +1083,7 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
400 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
401 signing_key.priv signing_key.x509 x509.genkey \
402 extra_certificates signing_key.x509.keyid \
403- signing_key.x509.signer
404+ signing_key.x509.signer tools/gcc/size_overflow_hash.h
405
406 # clean - Delete most, but leave enough to build external modules
407 #
408@@ -1059,6 +1123,7 @@ distclean: mrproper
409 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
410 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
411 -o -name '.*.rej' \
412+ -o -name '.*.rej' -o -name '*.so' \
413 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
414 -type f -print | xargs rm -f
415
416@@ -1219,6 +1284,8 @@ PHONY += $(module-dirs) modules
417 $(module-dirs): crmodverdir $(objtree)/Module.symvers
418 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
419
420+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
421+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
422 modules: $(module-dirs)
423 @$(kecho) ' Building modules, stage 2.';
424 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
425@@ -1355,17 +1422,21 @@ else
426 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
427 endif
428
429-%.s: %.c prepare scripts FORCE
430+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
431+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
432+%.s: %.c gcc-plugins prepare scripts FORCE
433 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
434 %.i: %.c prepare scripts FORCE
435 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
436-%.o: %.c prepare scripts FORCE
437+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
438+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
439+%.o: %.c gcc-plugins prepare scripts FORCE
440 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
441 %.lst: %.c prepare scripts FORCE
442 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
443-%.s: %.S prepare scripts FORCE
444+%.s: %.S gcc-plugins prepare scripts FORCE
445 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
446-%.o: %.S prepare scripts FORCE
447+%.o: %.S gcc-plugins prepare scripts FORCE
448 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
449 %.symtypes: %.c prepare scripts FORCE
450 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
451@@ -1375,11 +1446,15 @@ endif
452 $(cmd_crmodverdir)
453 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
454 $(build)=$(build-dir)
455-%/: prepare scripts FORCE
456+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
457+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
458+%/: gcc-plugins prepare scripts FORCE
459 $(cmd_crmodverdir)
460 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
461 $(build)=$(build-dir)
462-%.ko: prepare scripts FORCE
463+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
464+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
465+%.ko: gcc-plugins prepare scripts FORCE
466 $(cmd_crmodverdir)
467 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
468 $(build)=$(build-dir) $(@:.ko=.o)
469diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
470index c2cbe4f..f7264b4 100644
471--- a/arch/alpha/include/asm/atomic.h
472+++ b/arch/alpha/include/asm/atomic.h
473@@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
474 #define atomic_dec(v) atomic_sub(1,(v))
475 #define atomic64_dec(v) atomic64_sub(1,(v))
476
477+#define atomic64_read_unchecked(v) atomic64_read(v)
478+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
479+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
480+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
481+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
482+#define atomic64_inc_unchecked(v) atomic64_inc(v)
483+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
484+#define atomic64_dec_unchecked(v) atomic64_dec(v)
485+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
486+
487 #define smp_mb__before_atomic_dec() smp_mb()
488 #define smp_mb__after_atomic_dec() smp_mb()
489 #define smp_mb__before_atomic_inc() smp_mb()
490diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
491index ad368a9..fbe0f25 100644
492--- a/arch/alpha/include/asm/cache.h
493+++ b/arch/alpha/include/asm/cache.h
494@@ -4,19 +4,19 @@
495 #ifndef __ARCH_ALPHA_CACHE_H
496 #define __ARCH_ALPHA_CACHE_H
497
498+#include <linux/const.h>
499
500 /* Bytes per L1 (data) cache line. */
501 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
502-# define L1_CACHE_BYTES 64
503 # define L1_CACHE_SHIFT 6
504 #else
505 /* Both EV4 and EV5 are write-through, read-allocate,
506 direct-mapped, physical.
507 */
508-# define L1_CACHE_BYTES 32
509 # define L1_CACHE_SHIFT 5
510 #endif
511
512+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
513 #define SMP_CACHE_BYTES L1_CACHE_BYTES
514
515 #endif
516diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
517index 968d999..d36b2df 100644
518--- a/arch/alpha/include/asm/elf.h
519+++ b/arch/alpha/include/asm/elf.h
520@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
521
522 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
523
524+#ifdef CONFIG_PAX_ASLR
525+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
526+
527+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
528+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
529+#endif
530+
531 /* $0 is set by ld.so to a pointer to a function which might be
532 registered using atexit. This provides a mean for the dynamic
533 linker to call DT_FINI functions for shared libraries that have
534diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
535index bc2a0da..8ad11ee 100644
536--- a/arch/alpha/include/asm/pgalloc.h
537+++ b/arch/alpha/include/asm/pgalloc.h
538@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
539 pgd_set(pgd, pmd);
540 }
541
542+static inline void
543+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
544+{
545+ pgd_populate(mm, pgd, pmd);
546+}
547+
548 extern pgd_t *pgd_alloc(struct mm_struct *mm);
549
550 static inline void
551diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
552index 81a4342..348b927 100644
553--- a/arch/alpha/include/asm/pgtable.h
554+++ b/arch/alpha/include/asm/pgtable.h
555@@ -102,6 +102,17 @@ struct vm_area_struct;
556 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
557 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
558 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
559+
560+#ifdef CONFIG_PAX_PAGEEXEC
561+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
562+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
563+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
564+#else
565+# define PAGE_SHARED_NOEXEC PAGE_SHARED
566+# define PAGE_COPY_NOEXEC PAGE_COPY
567+# define PAGE_READONLY_NOEXEC PAGE_READONLY
568+#endif
569+
570 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
571
572 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
573diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
574index 2fd00b7..cfd5069 100644
575--- a/arch/alpha/kernel/module.c
576+++ b/arch/alpha/kernel/module.c
577@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
578
579 /* The small sections were sorted to the end of the segment.
580 The following should definitely cover them. */
581- gp = (u64)me->module_core + me->core_size - 0x8000;
582+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
583 got = sechdrs[me->arch.gotsecindex].sh_addr;
584
585 for (i = 0; i < n; i++) {
586diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
587index 14db93e..47bed62 100644
588--- a/arch/alpha/kernel/osf_sys.c
589+++ b/arch/alpha/kernel/osf_sys.c
590@@ -1295,16 +1295,16 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
591 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
592
593 static unsigned long
594-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
595- unsigned long limit)
596+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
597+ unsigned long limit, unsigned long flags)
598 {
599 struct vm_area_struct *vma = find_vma(current->mm, addr);
600-
601+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
602 while (1) {
603 /* At this point: (!vma || addr < vma->vm_end). */
604 if (limit - len < addr)
605 return -ENOMEM;
606- if (!vma || addr + len <= vma->vm_start)
607+ if (check_heap_stack_gap(vma, addr, len, offset))
608 return addr;
609 addr = vma->vm_end;
610 vma = vma->vm_next;
611@@ -1340,20 +1340,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
612 merely specific addresses, but regions of memory -- perhaps
613 this feature should be incorporated into all ports? */
614
615+#ifdef CONFIG_PAX_RANDMMAP
616+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
617+#endif
618+
619 if (addr) {
620- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
621+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
622 if (addr != (unsigned long) -ENOMEM)
623 return addr;
624 }
625
626 /* Next, try allocating at TASK_UNMAPPED_BASE. */
627- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
628- len, limit);
629+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
630+
631 if (addr != (unsigned long) -ENOMEM)
632 return addr;
633
634 /* Finally, try allocating in low memory. */
635- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
636+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
637
638 return addr;
639 }
640diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
641index 0c4132d..88f0d53 100644
642--- a/arch/alpha/mm/fault.c
643+++ b/arch/alpha/mm/fault.c
644@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
645 __reload_thread(pcb);
646 }
647
648+#ifdef CONFIG_PAX_PAGEEXEC
649+/*
650+ * PaX: decide what to do with offenders (regs->pc = fault address)
651+ *
652+ * returns 1 when task should be killed
653+ * 2 when patched PLT trampoline was detected
654+ * 3 when unpatched PLT trampoline was detected
655+ */
656+static int pax_handle_fetch_fault(struct pt_regs *regs)
657+{
658+
659+#ifdef CONFIG_PAX_EMUPLT
660+ int err;
661+
662+ do { /* PaX: patched PLT emulation #1 */
663+ unsigned int ldah, ldq, jmp;
664+
665+ err = get_user(ldah, (unsigned int *)regs->pc);
666+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
667+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
668+
669+ if (err)
670+ break;
671+
672+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
673+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
674+ jmp == 0x6BFB0000U)
675+ {
676+ unsigned long r27, addr;
677+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
678+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
679+
680+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
681+ err = get_user(r27, (unsigned long *)addr);
682+ if (err)
683+ break;
684+
685+ regs->r27 = r27;
686+ regs->pc = r27;
687+ return 2;
688+ }
689+ } while (0);
690+
691+ do { /* PaX: patched PLT emulation #2 */
692+ unsigned int ldah, lda, br;
693+
694+ err = get_user(ldah, (unsigned int *)regs->pc);
695+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
696+ err |= get_user(br, (unsigned int *)(regs->pc+8));
697+
698+ if (err)
699+ break;
700+
701+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
702+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
703+ (br & 0xFFE00000U) == 0xC3E00000U)
704+ {
705+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
706+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
707+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
708+
709+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
710+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
711+ return 2;
712+ }
713+ } while (0);
714+
715+ do { /* PaX: unpatched PLT emulation */
716+ unsigned int br;
717+
718+ err = get_user(br, (unsigned int *)regs->pc);
719+
720+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
721+ unsigned int br2, ldq, nop, jmp;
722+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
723+
724+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
725+ err = get_user(br2, (unsigned int *)addr);
726+ err |= get_user(ldq, (unsigned int *)(addr+4));
727+ err |= get_user(nop, (unsigned int *)(addr+8));
728+ err |= get_user(jmp, (unsigned int *)(addr+12));
729+ err |= get_user(resolver, (unsigned long *)(addr+16));
730+
731+ if (err)
732+ break;
733+
734+ if (br2 == 0xC3600000U &&
735+ ldq == 0xA77B000CU &&
736+ nop == 0x47FF041FU &&
737+ jmp == 0x6B7B0000U)
738+ {
739+ regs->r28 = regs->pc+4;
740+ regs->r27 = addr+16;
741+ regs->pc = resolver;
742+ return 3;
743+ }
744+ }
745+ } while (0);
746+#endif
747+
748+ return 1;
749+}
750+
751+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
752+{
753+ unsigned long i;
754+
755+ printk(KERN_ERR "PAX: bytes at PC: ");
756+ for (i = 0; i < 5; i++) {
757+ unsigned int c;
758+ if (get_user(c, (unsigned int *)pc+i))
759+ printk(KERN_CONT "???????? ");
760+ else
761+ printk(KERN_CONT "%08x ", c);
762+ }
763+ printk("\n");
764+}
765+#endif
766
767 /*
768 * This routine handles page faults. It determines the address,
769@@ -133,8 +251,29 @@ retry:
770 good_area:
771 si_code = SEGV_ACCERR;
772 if (cause < 0) {
773- if (!(vma->vm_flags & VM_EXEC))
774+ if (!(vma->vm_flags & VM_EXEC)) {
775+
776+#ifdef CONFIG_PAX_PAGEEXEC
777+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
778+ goto bad_area;
779+
780+ up_read(&mm->mmap_sem);
781+ switch (pax_handle_fetch_fault(regs)) {
782+
783+#ifdef CONFIG_PAX_EMUPLT
784+ case 2:
785+ case 3:
786+ return;
787+#endif
788+
789+ }
790+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
791+ do_group_exit(SIGKILL);
792+#else
793 goto bad_area;
794+#endif
795+
796+ }
797 } else if (!cause) {
798 /* Allow reads even for write-only mappings */
799 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
800diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
801index 67874b8..0e40765 100644
802--- a/arch/arm/Kconfig
803+++ b/arch/arm/Kconfig
804@@ -1813,7 +1813,7 @@ config ALIGNMENT_TRAP
805
806 config UACCESS_WITH_MEMCPY
807 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
808- depends on MMU
809+ depends on MMU && !PAX_MEMORY_UDEREF
810 default y if CPU_FEROCEON
811 help
812 Implement faster copy_to_user and clear_user methods for CPU
813diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
814index c79f61f..9ac0642 100644
815--- a/arch/arm/include/asm/atomic.h
816+++ b/arch/arm/include/asm/atomic.h
817@@ -17,17 +17,35 @@
818 #include <asm/barrier.h>
819 #include <asm/cmpxchg.h>
820
821+#ifdef CONFIG_GENERIC_ATOMIC64
822+#include <asm-generic/atomic64.h>
823+#endif
824+
825 #define ATOMIC_INIT(i) { (i) }
826
827 #ifdef __KERNEL__
828
829+#define _ASM_EXTABLE(from, to) \
830+" .pushsection __ex_table,\"a\"\n"\
831+" .align 3\n" \
832+" .long " #from ", " #to"\n" \
833+" .popsection"
834+
835 /*
836 * On ARM, ordinary assignment (str instruction) doesn't clear the local
837 * strex/ldrex monitor on some implementations. The reason we can use it for
838 * atomic_set() is the clrex or dummy strex done on every exception return.
839 */
840 #define atomic_read(v) (*(volatile int *)&(v)->counter)
841+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
842+{
843+ return v->counter;
844+}
845 #define atomic_set(v,i) (((v)->counter) = (i))
846+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
847+{
848+ v->counter = i;
849+}
850
851 #if __LINUX_ARM_ARCH__ >= 6
852
853@@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
854 int result;
855
856 __asm__ __volatile__("@ atomic_add\n"
857+"1: ldrex %1, [%3]\n"
858+" adds %0, %1, %4\n"
859+
860+#ifdef CONFIG_PAX_REFCOUNT
861+" bvc 3f\n"
862+"2: bkpt 0xf103\n"
863+"3:\n"
864+#endif
865+
866+" strex %1, %0, [%3]\n"
867+" teq %1, #0\n"
868+" bne 1b"
869+
870+#ifdef CONFIG_PAX_REFCOUNT
871+"\n4:\n"
872+ _ASM_EXTABLE(2b, 4b)
873+#endif
874+
875+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
876+ : "r" (&v->counter), "Ir" (i)
877+ : "cc");
878+}
879+
880+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
881+{
882+ unsigned long tmp;
883+ int result;
884+
885+ __asm__ __volatile__("@ atomic_add_unchecked\n"
886 "1: ldrex %0, [%3]\n"
887 " add %0, %0, %4\n"
888 " strex %1, %0, [%3]\n"
889@@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
890 smp_mb();
891
892 __asm__ __volatile__("@ atomic_add_return\n"
893+"1: ldrex %1, [%3]\n"
894+" adds %0, %1, %4\n"
895+
896+#ifdef CONFIG_PAX_REFCOUNT
897+" bvc 3f\n"
898+" mov %0, %1\n"
899+"2: bkpt 0xf103\n"
900+"3:\n"
901+#endif
902+
903+" strex %1, %0, [%3]\n"
904+" teq %1, #0\n"
905+" bne 1b"
906+
907+#ifdef CONFIG_PAX_REFCOUNT
908+"\n4:\n"
909+ _ASM_EXTABLE(2b, 4b)
910+#endif
911+
912+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
913+ : "r" (&v->counter), "Ir" (i)
914+ : "cc");
915+
916+ smp_mb();
917+
918+ return result;
919+}
920+
921+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
922+{
923+ unsigned long tmp;
924+ int result;
925+
926+ smp_mb();
927+
928+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
929 "1: ldrex %0, [%3]\n"
930 " add %0, %0, %4\n"
931 " strex %1, %0, [%3]\n"
932@@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
933 int result;
934
935 __asm__ __volatile__("@ atomic_sub\n"
936+"1: ldrex %1, [%3]\n"
937+" subs %0, %1, %4\n"
938+
939+#ifdef CONFIG_PAX_REFCOUNT
940+" bvc 3f\n"
941+"2: bkpt 0xf103\n"
942+"3:\n"
943+#endif
944+
945+" strex %1, %0, [%3]\n"
946+" teq %1, #0\n"
947+" bne 1b"
948+
949+#ifdef CONFIG_PAX_REFCOUNT
950+"\n4:\n"
951+ _ASM_EXTABLE(2b, 4b)
952+#endif
953+
954+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
955+ : "r" (&v->counter), "Ir" (i)
956+ : "cc");
957+}
958+
959+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
960+{
961+ unsigned long tmp;
962+ int result;
963+
964+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
965 "1: ldrex %0, [%3]\n"
966 " sub %0, %0, %4\n"
967 " strex %1, %0, [%3]\n"
968@@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
969 smp_mb();
970
971 __asm__ __volatile__("@ atomic_sub_return\n"
972-"1: ldrex %0, [%3]\n"
973-" sub %0, %0, %4\n"
974+"1: ldrex %1, [%3]\n"
975+" subs %0, %1, %4\n"
976+
977+#ifdef CONFIG_PAX_REFCOUNT
978+" bvc 3f\n"
979+" mov %0, %1\n"
980+"2: bkpt 0xf103\n"
981+"3:\n"
982+#endif
983+
984 " strex %1, %0, [%3]\n"
985 " teq %1, #0\n"
986 " bne 1b"
987+
988+#ifdef CONFIG_PAX_REFCOUNT
989+"\n4:\n"
990+ _ASM_EXTABLE(2b, 4b)
991+#endif
992+
993 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
994 : "r" (&v->counter), "Ir" (i)
995 : "cc");
996@@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
997 return oldval;
998 }
999
1000+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1001+{
1002+ unsigned long oldval, res;
1003+
1004+ smp_mb();
1005+
1006+ do {
1007+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1008+ "ldrex %1, [%3]\n"
1009+ "mov %0, #0\n"
1010+ "teq %1, %4\n"
1011+ "strexeq %0, %5, [%3]\n"
1012+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1013+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1014+ : "cc");
1015+ } while (res);
1016+
1017+ smp_mb();
1018+
1019+ return oldval;
1020+}
1021+
1022 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1023 {
1024 unsigned long tmp, tmp2;
1025@@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1026
1027 return val;
1028 }
1029+
1030+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1031+{
1032+ return atomic_add_return(i, v);
1033+}
1034+
1035 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1036+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1037+{
1038+ (void) atomic_add_return(i, v);
1039+}
1040
1041 static inline int atomic_sub_return(int i, atomic_t *v)
1042 {
1043@@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1044 return val;
1045 }
1046 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1047+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1048+{
1049+ (void) atomic_sub_return(i, v);
1050+}
1051
1052 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1053 {
1054@@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1055 return ret;
1056 }
1057
1058+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1059+{
1060+ return atomic_cmpxchg(v, old, new);
1061+}
1062+
1063 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1064 {
1065 unsigned long flags;
1066@@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1067 #endif /* __LINUX_ARM_ARCH__ */
1068
1069 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1070+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1071+{
1072+ return xchg(&v->counter, new);
1073+}
1074
1075 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1076 {
1077@@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1078 }
1079
1080 #define atomic_inc(v) atomic_add(1, v)
1081+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1082+{
1083+ atomic_add_unchecked(1, v);
1084+}
1085 #define atomic_dec(v) atomic_sub(1, v)
1086+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1087+{
1088+ atomic_sub_unchecked(1, v);
1089+}
1090
1091 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1092+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1093+{
1094+ return atomic_add_return_unchecked(1, v) == 0;
1095+}
1096 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1097 #define atomic_inc_return(v) (atomic_add_return(1, v))
1098+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1099+{
1100+ return atomic_add_return_unchecked(1, v);
1101+}
1102 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1103 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1104
1105@@ -241,6 +428,14 @@ typedef struct {
1106 u64 __aligned(8) counter;
1107 } atomic64_t;
1108
1109+#ifdef CONFIG_PAX_REFCOUNT
1110+typedef struct {
1111+ u64 __aligned(8) counter;
1112+} atomic64_unchecked_t;
1113+#else
1114+typedef atomic64_t atomic64_unchecked_t;
1115+#endif
1116+
1117 #define ATOMIC64_INIT(i) { (i) }
1118
1119 static inline u64 atomic64_read(const atomic64_t *v)
1120@@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1121 return result;
1122 }
1123
1124+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1125+{
1126+ u64 result;
1127+
1128+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1129+" ldrexd %0, %H0, [%1]"
1130+ : "=&r" (result)
1131+ : "r" (&v->counter), "Qo" (v->counter)
1132+ );
1133+
1134+ return result;
1135+}
1136+
1137 static inline void atomic64_set(atomic64_t *v, u64 i)
1138 {
1139 u64 tmp;
1140@@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1141 : "cc");
1142 }
1143
1144+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1145+{
1146+ u64 tmp;
1147+
1148+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1149+"1: ldrexd %0, %H0, [%2]\n"
1150+" strexd %0, %3, %H3, [%2]\n"
1151+" teq %0, #0\n"
1152+" bne 1b"
1153+ : "=&r" (tmp), "=Qo" (v->counter)
1154+ : "r" (&v->counter), "r" (i)
1155+ : "cc");
1156+}
1157+
1158 static inline void atomic64_add(u64 i, atomic64_t *v)
1159 {
1160 u64 result;
1161@@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1162 __asm__ __volatile__("@ atomic64_add\n"
1163 "1: ldrexd %0, %H0, [%3]\n"
1164 " adds %0, %0, %4\n"
1165+" adcs %H0, %H0, %H4\n"
1166+
1167+#ifdef CONFIG_PAX_REFCOUNT
1168+" bvc 3f\n"
1169+"2: bkpt 0xf103\n"
1170+"3:\n"
1171+#endif
1172+
1173+" strexd %1, %0, %H0, [%3]\n"
1174+" teq %1, #0\n"
1175+" bne 1b"
1176+
1177+#ifdef CONFIG_PAX_REFCOUNT
1178+"\n4:\n"
1179+ _ASM_EXTABLE(2b, 4b)
1180+#endif
1181+
1182+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1183+ : "r" (&v->counter), "r" (i)
1184+ : "cc");
1185+}
1186+
1187+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1188+{
1189+ u64 result;
1190+ unsigned long tmp;
1191+
1192+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1193+"1: ldrexd %0, %H0, [%3]\n"
1194+" adds %0, %0, %4\n"
1195 " adc %H0, %H0, %H4\n"
1196 " strexd %1, %0, %H0, [%3]\n"
1197 " teq %1, #0\n"
1198@@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1199
1200 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1201 {
1202- u64 result;
1203- unsigned long tmp;
1204+ u64 result, tmp;
1205
1206 smp_mb();
1207
1208 __asm__ __volatile__("@ atomic64_add_return\n"
1209+"1: ldrexd %1, %H1, [%3]\n"
1210+" adds %0, %1, %4\n"
1211+" adcs %H0, %H1, %H4\n"
1212+
1213+#ifdef CONFIG_PAX_REFCOUNT
1214+" bvc 3f\n"
1215+" mov %0, %1\n"
1216+" mov %H0, %H1\n"
1217+"2: bkpt 0xf103\n"
1218+"3:\n"
1219+#endif
1220+
1221+" strexd %1, %0, %H0, [%3]\n"
1222+" teq %1, #0\n"
1223+" bne 1b"
1224+
1225+#ifdef CONFIG_PAX_REFCOUNT
1226+"\n4:\n"
1227+ _ASM_EXTABLE(2b, 4b)
1228+#endif
1229+
1230+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1231+ : "r" (&v->counter), "r" (i)
1232+ : "cc");
1233+
1234+ smp_mb();
1235+
1236+ return result;
1237+}
1238+
1239+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1240+{
1241+ u64 result;
1242+ unsigned long tmp;
1243+
1244+ smp_mb();
1245+
1246+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1247 "1: ldrexd %0, %H0, [%3]\n"
1248 " adds %0, %0, %4\n"
1249 " adc %H0, %H0, %H4\n"
1250@@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1251 __asm__ __volatile__("@ atomic64_sub\n"
1252 "1: ldrexd %0, %H0, [%3]\n"
1253 " subs %0, %0, %4\n"
1254+" sbcs %H0, %H0, %H4\n"
1255+
1256+#ifdef CONFIG_PAX_REFCOUNT
1257+" bvc 3f\n"
1258+"2: bkpt 0xf103\n"
1259+"3:\n"
1260+#endif
1261+
1262+" strexd %1, %0, %H0, [%3]\n"
1263+" teq %1, #0\n"
1264+" bne 1b"
1265+
1266+#ifdef CONFIG_PAX_REFCOUNT
1267+"\n4:\n"
1268+ _ASM_EXTABLE(2b, 4b)
1269+#endif
1270+
1271+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1272+ : "r" (&v->counter), "r" (i)
1273+ : "cc");
1274+}
1275+
1276+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1277+{
1278+ u64 result;
1279+ unsigned long tmp;
1280+
1281+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1282+"1: ldrexd %0, %H0, [%3]\n"
1283+" subs %0, %0, %4\n"
1284 " sbc %H0, %H0, %H4\n"
1285 " strexd %1, %0, %H0, [%3]\n"
1286 " teq %1, #0\n"
1287@@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1288
1289 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1290 {
1291- u64 result;
1292- unsigned long tmp;
1293+ u64 result, tmp;
1294
1295 smp_mb();
1296
1297 __asm__ __volatile__("@ atomic64_sub_return\n"
1298-"1: ldrexd %0, %H0, [%3]\n"
1299-" subs %0, %0, %4\n"
1300-" sbc %H0, %H0, %H4\n"
1301+"1: ldrexd %1, %H1, [%3]\n"
1302+" subs %0, %1, %4\n"
1303+" sbcs %H0, %H1, %H4\n"
1304+
1305+#ifdef CONFIG_PAX_REFCOUNT
1306+" bvc 3f\n"
1307+" mov %0, %1\n"
1308+" mov %H0, %H1\n"
1309+"2: bkpt 0xf103\n"
1310+"3:\n"
1311+#endif
1312+
1313 " strexd %1, %0, %H0, [%3]\n"
1314 " teq %1, #0\n"
1315 " bne 1b"
1316+
1317+#ifdef CONFIG_PAX_REFCOUNT
1318+"\n4:\n"
1319+ _ASM_EXTABLE(2b, 4b)
1320+#endif
1321+
1322 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1323 : "r" (&v->counter), "r" (i)
1324 : "cc");
1325@@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1326 return oldval;
1327 }
1328
1329+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1330+{
1331+ u64 oldval;
1332+ unsigned long res;
1333+
1334+ smp_mb();
1335+
1336+ do {
1337+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1338+ "ldrexd %1, %H1, [%3]\n"
1339+ "mov %0, #0\n"
1340+ "teq %1, %4\n"
1341+ "teqeq %H1, %H4\n"
1342+ "strexdeq %0, %5, %H5, [%3]"
1343+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1344+ : "r" (&ptr->counter), "r" (old), "r" (new)
1345+ : "cc");
1346+ } while (res);
1347+
1348+ smp_mb();
1349+
1350+ return oldval;
1351+}
1352+
1353 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1354 {
1355 u64 result;
1356@@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1357
1358 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1359 {
1360- u64 result;
1361- unsigned long tmp;
1362+ u64 result, tmp;
1363
1364 smp_mb();
1365
1366 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1367-"1: ldrexd %0, %H0, [%3]\n"
1368-" subs %0, %0, #1\n"
1369-" sbc %H0, %H0, #0\n"
1370+"1: ldrexd %1, %H1, [%3]\n"
1371+" subs %0, %1, #1\n"
1372+" sbcs %H0, %H1, #0\n"
1373+
1374+#ifdef CONFIG_PAX_REFCOUNT
1375+" bvc 3f\n"
1376+" mov %0, %1\n"
1377+" mov %H0, %H1\n"
1378+"2: bkpt 0xf103\n"
1379+"3:\n"
1380+#endif
1381+
1382 " teq %H0, #0\n"
1383-" bmi 2f\n"
1384+" bmi 4f\n"
1385 " strexd %1, %0, %H0, [%3]\n"
1386 " teq %1, #0\n"
1387 " bne 1b\n"
1388-"2:"
1389+"4:\n"
1390+
1391+#ifdef CONFIG_PAX_REFCOUNT
1392+ _ASM_EXTABLE(2b, 4b)
1393+#endif
1394+
1395 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1396 : "r" (&v->counter)
1397 : "cc");
1398@@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1399 " teq %0, %5\n"
1400 " teqeq %H0, %H5\n"
1401 " moveq %1, #0\n"
1402-" beq 2f\n"
1403+" beq 4f\n"
1404 " adds %0, %0, %6\n"
1405-" adc %H0, %H0, %H6\n"
1406+" adcs %H0, %H0, %H6\n"
1407+
1408+#ifdef CONFIG_PAX_REFCOUNT
1409+" bvc 3f\n"
1410+"2: bkpt 0xf103\n"
1411+"3:\n"
1412+#endif
1413+
1414 " strexd %2, %0, %H0, [%4]\n"
1415 " teq %2, #0\n"
1416 " bne 1b\n"
1417-"2:"
1418+"4:\n"
1419+
1420+#ifdef CONFIG_PAX_REFCOUNT
1421+ _ASM_EXTABLE(2b, 4b)
1422+#endif
1423+
1424 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1425 : "r" (&v->counter), "r" (u), "r" (a)
1426 : "cc");
1427@@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1428
1429 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1430 #define atomic64_inc(v) atomic64_add(1LL, (v))
1431+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1432 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1433+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1434 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1435 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1436 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1437+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1438 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1439 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1440 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1441diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1442index 75fe66b..ba3dee4 100644
1443--- a/arch/arm/include/asm/cache.h
1444+++ b/arch/arm/include/asm/cache.h
1445@@ -4,8 +4,10 @@
1446 #ifndef __ASMARM_CACHE_H
1447 #define __ASMARM_CACHE_H
1448
1449+#include <linux/const.h>
1450+
1451 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1452-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1453+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1454
1455 /*
1456 * Memory returned by kmalloc() may be used for DMA, so we must make
1457@@ -24,5 +26,6 @@
1458 #endif
1459
1460 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1461+#define __read_only __attribute__ ((__section__(".data..read_only")))
1462
1463 #endif
1464diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1465index e1489c5..d418304 100644
1466--- a/arch/arm/include/asm/cacheflush.h
1467+++ b/arch/arm/include/asm/cacheflush.h
1468@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1469 void (*dma_unmap_area)(const void *, size_t, int);
1470
1471 void (*dma_flush_range)(const void *, const void *);
1472-};
1473+} __no_const;
1474
1475 /*
1476 * Select the calling method
1477diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1478index 6dcc164..b14d917 100644
1479--- a/arch/arm/include/asm/checksum.h
1480+++ b/arch/arm/include/asm/checksum.h
1481@@ -37,7 +37,19 @@ __wsum
1482 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1483
1484 __wsum
1485-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1486+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1487+
1488+static inline __wsum
1489+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1490+{
1491+ __wsum ret;
1492+ pax_open_userland();
1493+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1494+ pax_close_userland();
1495+ return ret;
1496+}
1497+
1498+
1499
1500 /*
1501 * Fold a partial checksum without adding pseudo headers
1502diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1503index 7eb18c1..e38b6d2 100644
1504--- a/arch/arm/include/asm/cmpxchg.h
1505+++ b/arch/arm/include/asm/cmpxchg.h
1506@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1507
1508 #define xchg(ptr,x) \
1509 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1510+#define xchg_unchecked(ptr,x) \
1511+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1512
1513 #include <asm-generic/cmpxchg-local.h>
1514
1515diff --git a/arch/arm/include/asm/delay.h b/arch/arm/include/asm/delay.h
1516index ab98fdd..6b19938 100644
1517--- a/arch/arm/include/asm/delay.h
1518+++ b/arch/arm/include/asm/delay.h
1519@@ -24,9 +24,9 @@ extern struct arm_delay_ops {
1520 void (*delay)(unsigned long);
1521 void (*const_udelay)(unsigned long);
1522 void (*udelay)(unsigned long);
1523-} arm_delay_ops;
1524+} *arm_delay_ops;
1525
1526-#define __delay(n) arm_delay_ops.delay(n)
1527+#define __delay(n) arm_delay_ops->delay(n)
1528
1529 /*
1530 * This function intentionally does not exist; if you see references to
1531@@ -47,8 +47,8 @@ extern void __bad_udelay(void);
1532 * first constant multiplications gets optimized away if the delay is
1533 * a constant)
1534 */
1535-#define __udelay(n) arm_delay_ops.udelay(n)
1536-#define __const_udelay(n) arm_delay_ops.const_udelay(n)
1537+#define __udelay(n) arm_delay_ops->udelay(n)
1538+#define __const_udelay(n) arm_delay_ops->const_udelay(n)
1539
1540 #define udelay(n) \
1541 (__builtin_constant_p(n) ? \
1542diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1543index 6ddbe44..0bae1e9 100644
1544--- a/arch/arm/include/asm/domain.h
1545+++ b/arch/arm/include/asm/domain.h
1546@@ -48,18 +48,36 @@
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 #else
1556+
1557+#ifdef CONFIG_PAX_KERNEXEC
1558 #define DOMAIN_MANAGER 1
1559+#define DOMAIN_KERNEXEC 3
1560+#else
1561+#define DOMAIN_MANAGER 1
1562+#endif
1563+
1564+#ifdef CONFIG_PAX_MEMORY_UDEREF
1565+#define DOMAIN_USERCLIENT 0
1566+#define DOMAIN_UDEREF 1
1567+#define DOMAIN_VECTORS DOMAIN_KERNEL
1568+#else
1569+#define DOMAIN_USERCLIENT 1
1570+#define DOMAIN_VECTORS DOMAIN_USER
1571+#endif
1572+#define DOMAIN_KERNELCLIENT 1
1573+
1574 #endif
1575
1576 #define domain_val(dom,type) ((type) << (2*(dom)))
1577
1578 #ifndef __ASSEMBLY__
1579
1580-#ifdef CONFIG_CPU_USE_DOMAINS
1581+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1582 static inline void set_domain(unsigned val)
1583 {
1584 asm volatile(
1585@@ -68,15 +86,7 @@ static inline void set_domain(unsigned val)
1586 isb();
1587 }
1588
1589-#define modify_domain(dom,type) \
1590- do { \
1591- struct thread_info *thread = current_thread_info(); \
1592- unsigned int domain = thread->cpu_domain; \
1593- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1594- thread->cpu_domain = domain | domain_val(dom, type); \
1595- set_domain(thread->cpu_domain); \
1596- } while (0)
1597-
1598+extern void modify_domain(unsigned int dom, unsigned int type);
1599 #else
1600 static inline void set_domain(unsigned val) { }
1601 static inline void modify_domain(unsigned dom, unsigned type) { }
1602diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1603index 38050b1..9d90e8b 100644
1604--- a/arch/arm/include/asm/elf.h
1605+++ b/arch/arm/include/asm/elf.h
1606@@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1607 the loader. We need to make sure that it is out of the way of the program
1608 that it will "exec", and that there is sufficient room for the brk. */
1609
1610-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1611+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1612+
1613+#ifdef CONFIG_PAX_ASLR
1614+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1615+
1616+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1617+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1618+#endif
1619
1620 /* When the program starts, a1 contains a pointer to a function to be
1621 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1622@@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1623 extern void elf_set_personality(const struct elf32_hdr *);
1624 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1625
1626-struct mm_struct;
1627-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1628-#define arch_randomize_brk arch_randomize_brk
1629-
1630 #endif
1631diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1632index de53547..52b9a28 100644
1633--- a/arch/arm/include/asm/fncpy.h
1634+++ b/arch/arm/include/asm/fncpy.h
1635@@ -81,7 +81,9 @@
1636 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1637 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1638 \
1639+ pax_open_kernel(); \
1640 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1641+ pax_close_kernel(); \
1642 flush_icache_range((unsigned long)(dest_buf), \
1643 (unsigned long)(dest_buf) + (size)); \
1644 \
1645diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1646index e42cf59..7b94b8f 100644
1647--- a/arch/arm/include/asm/futex.h
1648+++ b/arch/arm/include/asm/futex.h
1649@@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1650 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1651 return -EFAULT;
1652
1653+ pax_open_userland();
1654+
1655 smp_mb();
1656 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1657 "1: ldrex %1, [%4]\n"
1658@@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1659 : "cc", "memory");
1660 smp_mb();
1661
1662+ pax_close_userland();
1663+
1664 *uval = val;
1665 return ret;
1666 }
1667@@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1668 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1669 return -EFAULT;
1670
1671+ pax_open_userland();
1672+
1673 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1674 "1: " TUSER(ldr) " %1, [%4]\n"
1675 " teq %1, %2\n"
1676@@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1677 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1678 : "cc", "memory");
1679
1680+ pax_close_userland();
1681+
1682 *uval = val;
1683 return ret;
1684 }
1685@@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1686 return -EFAULT;
1687
1688 pagefault_disable(); /* implies preempt_disable() */
1689+ pax_open_userland();
1690
1691 switch (op) {
1692 case FUTEX_OP_SET:
1693@@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1694 ret = -ENOSYS;
1695 }
1696
1697+ pax_close_userland();
1698 pagefault_enable(); /* subsumes preempt_enable() */
1699
1700 if (!ret) {
1701diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1702index 83eb2f7..ed77159 100644
1703--- a/arch/arm/include/asm/kmap_types.h
1704+++ b/arch/arm/include/asm/kmap_types.h
1705@@ -4,6 +4,6 @@
1706 /*
1707 * This is the "bare minimum". AIO seems to require this.
1708 */
1709-#define KM_TYPE_NR 16
1710+#define KM_TYPE_NR 17
1711
1712 #endif
1713diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1714index 9e614a1..3302cca 100644
1715--- a/arch/arm/include/asm/mach/dma.h
1716+++ b/arch/arm/include/asm/mach/dma.h
1717@@ -22,7 +22,7 @@ struct dma_ops {
1718 int (*residue)(unsigned int, dma_t *); /* optional */
1719 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1720 const char *type;
1721-};
1722+} __do_const;
1723
1724 struct dma_struct {
1725 void *addr; /* single DMA address */
1726diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1727index 2fe141f..192dc01 100644
1728--- a/arch/arm/include/asm/mach/map.h
1729+++ b/arch/arm/include/asm/mach/map.h
1730@@ -27,13 +27,16 @@ struct map_desc {
1731 #define MT_MINICLEAN 6
1732 #define MT_LOW_VECTORS 7
1733 #define MT_HIGH_VECTORS 8
1734-#define MT_MEMORY 9
1735+#define MT_MEMORY_RWX 9
1736 #define MT_ROM 10
1737-#define MT_MEMORY_NONCACHED 11
1738+#define MT_MEMORY_NONCACHED_RX 11
1739 #define MT_MEMORY_DTCM 12
1740 #define MT_MEMORY_ITCM 13
1741 #define MT_MEMORY_SO 14
1742 #define MT_MEMORY_DMA_READY 15
1743+#define MT_MEMORY_RW 16
1744+#define MT_MEMORY_RX 17
1745+#define MT_MEMORY_NONCACHED_RW 18
1746
1747 #ifdef CONFIG_MMU
1748 extern void iotable_init(struct map_desc *, int);
1749diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1750index 53426c6..c7baff3 100644
1751--- a/arch/arm/include/asm/outercache.h
1752+++ b/arch/arm/include/asm/outercache.h
1753@@ -35,7 +35,7 @@ struct outer_cache_fns {
1754 #endif
1755 void (*set_debug)(unsigned long);
1756 void (*resume)(void);
1757-};
1758+} __no_const;
1759
1760 #ifdef CONFIG_OUTER_CACHE
1761
1762diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1763index 812a494..71fc0b6 100644
1764--- a/arch/arm/include/asm/page.h
1765+++ b/arch/arm/include/asm/page.h
1766@@ -114,7 +114,7 @@ struct cpu_user_fns {
1767 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1768 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1769 unsigned long vaddr, struct vm_area_struct *vma);
1770-};
1771+} __no_const;
1772
1773 #ifdef MULTI_USER
1774 extern struct cpu_user_fns cpu_user;
1775diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1776index 943504f..c37a730 100644
1777--- a/arch/arm/include/asm/pgalloc.h
1778+++ b/arch/arm/include/asm/pgalloc.h
1779@@ -17,6 +17,7 @@
1780 #include <asm/processor.h>
1781 #include <asm/cacheflush.h>
1782 #include <asm/tlbflush.h>
1783+#include <asm/system_info.h>
1784
1785 #define check_pgt_cache() do { } while (0)
1786
1787@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1788 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1789 }
1790
1791+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1792+{
1793+ pud_populate(mm, pud, pmd);
1794+}
1795+
1796 #else /* !CONFIG_ARM_LPAE */
1797
1798 /*
1799@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1800 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1801 #define pmd_free(mm, pmd) do { } while (0)
1802 #define pud_populate(mm,pmd,pte) BUG()
1803+#define pud_populate_kernel(mm,pmd,pte) BUG()
1804
1805 #endif /* CONFIG_ARM_LPAE */
1806
1807@@ -126,6 +133,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1808 __free_page(pte);
1809 }
1810
1811+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1812+{
1813+#ifdef CONFIG_ARM_LPAE
1814+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1815+#else
1816+ if (addr & SECTION_SIZE)
1817+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1818+ else
1819+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1820+#endif
1821+ flush_pmd_entry(pmdp);
1822+}
1823+
1824 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1825 pmdval_t prot)
1826 {
1827@@ -155,7 +175,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1828 static inline void
1829 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1830 {
1831- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1832+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1833 }
1834 #define pmd_pgtable(pmd) pmd_page(pmd)
1835
1836diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1837index 5cfba15..f415e1a 100644
1838--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1839+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1840@@ -20,12 +20,15 @@
1841 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1842 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1843 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1844+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1845 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1846 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1847 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1848+
1849 /*
1850 * - section
1851 */
1852+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1853 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1854 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1855 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1856@@ -37,6 +40,7 @@
1857 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1858 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1859 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1860+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1861
1862 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1863 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1864@@ -66,6 +70,7 @@
1865 * - extended small page/tiny page
1866 */
1867 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1868+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1869 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1870 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1871 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1872diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1873index f97ee02..07f1be5 100644
1874--- a/arch/arm/include/asm/pgtable-2level.h
1875+++ b/arch/arm/include/asm/pgtable-2level.h
1876@@ -125,6 +125,7 @@
1877 #define L_PTE_XN (_AT(pteval_t, 1) << 9)
1878 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1879 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1880+#define L_PTE_PXN (_AT(pteval_t, 1) << 12) /* v7*/
1881
1882 /*
1883 * These are the memory types, defined to be compatible with
1884diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1885index d795282..a43ea90 100644
1886--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1887+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1888@@ -32,15 +32,18 @@
1889 #define PMD_TYPE_SECT (_AT(pmdval_t, 1) << 0)
1890 #define PMD_BIT4 (_AT(pmdval_t, 0))
1891 #define PMD_DOMAIN(x) (_AT(pmdval_t, 0))
1892+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 59) /* PXNTable */
1893
1894 /*
1895 * - section
1896 */
1897 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1898 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1899+#define PMD_SECT_RDONLY (_AT(pmdval_t, 1) << 7)
1900 #define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
1901 #define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
1902 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 11)
1903+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 53)
1904 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 54)
1905 #define PMD_SECT_AP_WRITE (_AT(pmdval_t, 0))
1906 #define PMD_SECT_AP_READ (_AT(pmdval_t, 0))
1907@@ -66,6 +69,7 @@
1908 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1909 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1910 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1911+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1912 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1913
1914 /*
1915diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1916index a3f3792..7b932a6 100644
1917--- a/arch/arm/include/asm/pgtable-3level.h
1918+++ b/arch/arm/include/asm/pgtable-3level.h
1919@@ -74,6 +74,7 @@
1920 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1921 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1922 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1923+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1924 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1925 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1926 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1927@@ -82,6 +83,7 @@
1928 /*
1929 * To be used in assembly code with the upper page attributes.
1930 */
1931+#define L_PTE_PXN_HIGH (1 << (53 - 32))
1932 #define L_PTE_XN_HIGH (1 << (54 - 32))
1933 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1934
1935diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1936index 9c82f988..514705a 100644
1937--- a/arch/arm/include/asm/pgtable.h
1938+++ b/arch/arm/include/asm/pgtable.h
1939@@ -30,6 +30,9 @@
1940 #include <asm/pgtable-2level.h>
1941 #endif
1942
1943+#define ktla_ktva(addr) (addr)
1944+#define ktva_ktla(addr) (addr)
1945+
1946 /*
1947 * Just any arbitrary offset to the start of the vmalloc VM area: the
1948 * current 8MB value just means that there will be a 8MB "hole" after the
1949@@ -45,6 +48,9 @@
1950 #define LIBRARY_TEXT_START 0x0c000000
1951
1952 #ifndef __ASSEMBLY__
1953+extern pteval_t __supported_pte_mask;
1954+extern pmdval_t __supported_pmd_mask;
1955+
1956 extern void __pte_error(const char *file, int line, pte_t);
1957 extern void __pmd_error(const char *file, int line, pmd_t);
1958 extern void __pgd_error(const char *file, int line, pgd_t);
1959@@ -53,6 +59,50 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1960 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1961 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1962
1963+#define __HAVE_ARCH_PAX_OPEN_KERNEL
1964+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
1965+
1966+#ifdef CONFIG_PAX_KERNEXEC
1967+#include <asm/domain.h>
1968+#include <linux/thread_info.h>
1969+#include <linux/preempt.h>
1970+#endif
1971+
1972+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1973+static inline int test_domain(int domain, int domaintype)
1974+{
1975+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
1976+}
1977+#endif
1978+
1979+#ifdef CONFIG_PAX_KERNEXEC
1980+static inline unsigned long pax_open_kernel(void) {
1981+#ifdef CONFIG_ARM_LPAE
1982+ /* TODO */
1983+#else
1984+ preempt_disable();
1985+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
1986+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
1987+#endif
1988+ return 0;
1989+}
1990+
1991+static inline unsigned long pax_close_kernel(void) {
1992+#ifdef CONFIG_ARM_LPAE
1993+ /* TODO */
1994+#else
1995+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
1996+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
1997+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
1998+ preempt_enable_no_resched();
1999+#endif
2000+ return 0;
2001+}
2002+#else
2003+static inline unsigned long pax_open_kernel(void) { return 0; }
2004+static inline unsigned long pax_close_kernel(void) { return 0; }
2005+#endif
2006+
2007 /*
2008 * This is the lowest virtual address we can permit any user space
2009 * mapping to be mapped at. This is particularly important for
2010@@ -63,8 +113,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2011 /*
2012 * The pgprot_* and protection_map entries will be fixed up in runtime
2013 * to include the cachable and bufferable bits based on memory policy,
2014- * as well as any architecture dependent bits like global/ASID and SMP
2015- * shared mapping bits.
2016+ * as well as any architecture dependent bits like global/ASID, PXN,
2017+ * and SMP shared mapping bits.
2018 */
2019 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2020
2021@@ -240,7 +290,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2022
2023 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2024 {
2025- const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER | L_PTE_NONE;
2026+ const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER | L_PTE_NONE | __supported_pte_mask;
2027 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2028 return pte;
2029 }
2030diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2031index f3628fb..a0672dd 100644
2032--- a/arch/arm/include/asm/proc-fns.h
2033+++ b/arch/arm/include/asm/proc-fns.h
2034@@ -75,7 +75,7 @@ extern struct processor {
2035 unsigned int suspend_size;
2036 void (*do_suspend)(void *);
2037 void (*do_resume)(void *);
2038-} processor;
2039+} __do_const processor;
2040
2041 #ifndef MULTI_CPU
2042 extern void cpu_proc_init(void);
2043diff --git a/arch/arm/include/asm/processor.h b/arch/arm/include/asm/processor.h
2044index 06e7d50..8a8e251 100644
2045--- a/arch/arm/include/asm/processor.h
2046+++ b/arch/arm/include/asm/processor.h
2047@@ -65,9 +65,8 @@ struct thread_struct {
2048 regs->ARM_cpsr |= PSR_ENDSTATE; \
2049 regs->ARM_pc = pc & ~1; /* pc */ \
2050 regs->ARM_sp = sp; /* sp */ \
2051- regs->ARM_r2 = stack[2]; /* r2 (envp) */ \
2052- regs->ARM_r1 = stack[1]; /* r1 (argv) */ \
2053- regs->ARM_r0 = stack[0]; /* r0 (argc) */ \
2054+ /* r2 (envp), r1 (argv), r0 (argc) */ \
2055+ (void)copy_from_user(&regs->ARM_r0, (const char __user *)stack, 3 * sizeof(unsigned long)); \
2056 nommu_start_thread(regs); \
2057 })
2058
2059diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2060index d3a22be..3a69ad5 100644
2061--- a/arch/arm/include/asm/smp.h
2062+++ b/arch/arm/include/asm/smp.h
2063@@ -107,7 +107,7 @@ struct smp_operations {
2064 int (*cpu_disable)(unsigned int cpu);
2065 #endif
2066 #endif
2067-};
2068+} __no_const;
2069
2070 /*
2071 * set platform specific SMP operations
2072diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2073index cddda1f..ff357f7 100644
2074--- a/arch/arm/include/asm/thread_info.h
2075+++ b/arch/arm/include/asm/thread_info.h
2076@@ -77,9 +77,9 @@ struct thread_info {
2077 .flags = 0, \
2078 .preempt_count = INIT_PREEMPT_COUNT, \
2079 .addr_limit = KERNEL_DS, \
2080- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2081- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2082- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2083+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2084+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2085+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2086 .restart_block = { \
2087 .fn = do_no_restart_syscall, \
2088 }, \
2089@@ -152,6 +152,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2090 #define TIF_SYSCALL_AUDIT 9
2091 #define TIF_SYSCALL_TRACEPOINT 10
2092 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2093+
2094+/* within 8 bits of TIF_SYSCALL_TRACE
2095+ * to meet flexible second operand requirements
2096+ */
2097+#define TIF_GRSEC_SETXID 12
2098+
2099 #define TIF_USING_IWMMXT 17
2100 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2101 #define TIF_RESTORE_SIGMASK 20
2102@@ -165,10 +171,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2103 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2104 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2105 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2106+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2107
2108 /* Checks for any syscall work in entry-common.S */
2109 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2110- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2111+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2112
2113 /*
2114 * Change these and you break ASM code in entry-common.S
2115diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2116index 7e1f760..752fcb7 100644
2117--- a/arch/arm/include/asm/uaccess.h
2118+++ b/arch/arm/include/asm/uaccess.h
2119@@ -18,6 +18,7 @@
2120 #include <asm/domain.h>
2121 #include <asm/unified.h>
2122 #include <asm/compiler.h>
2123+#include <asm/pgtable.h>
2124
2125 #define VERIFY_READ 0
2126 #define VERIFY_WRITE 1
2127@@ -60,10 +61,34 @@ extern int __put_user_bad(void);
2128 #define USER_DS TASK_SIZE
2129 #define get_fs() (current_thread_info()->addr_limit)
2130
2131+static inline void pax_open_userland(void)
2132+{
2133+
2134+#ifdef CONFIG_PAX_MEMORY_UDEREF
2135+ if (get_fs() == USER_DS) {
2136+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2137+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2138+ }
2139+#endif
2140+
2141+}
2142+
2143+static inline void pax_close_userland(void)
2144+{
2145+
2146+#ifdef CONFIG_PAX_MEMORY_UDEREF
2147+ if (get_fs() == USER_DS) {
2148+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2149+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2150+ }
2151+#endif
2152+
2153+}
2154+
2155 static inline void set_fs(mm_segment_t fs)
2156 {
2157 current_thread_info()->addr_limit = fs;
2158- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2159+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2160 }
2161
2162 #define segment_eq(a,b) ((a) == (b))
2163@@ -143,8 +168,12 @@ extern int __get_user_4(void *);
2164
2165 #define get_user(x,p) \
2166 ({ \
2167+ int __e; \
2168 might_fault(); \
2169- __get_user_check(x,p); \
2170+ pax_open_userland(); \
2171+ __e = __get_user_check(x,p); \
2172+ pax_close_userland(); \
2173+ __e; \
2174 })
2175
2176 extern int __put_user_1(void *, unsigned int);
2177@@ -188,8 +217,12 @@ extern int __put_user_8(void *, unsigned long long);
2178
2179 #define put_user(x,p) \
2180 ({ \
2181+ int __e; \
2182 might_fault(); \
2183- __put_user_check(x,p); \
2184+ pax_open_userland(); \
2185+ __e = __put_user_check(x,p); \
2186+ pax_close_userland(); \
2187+ __e; \
2188 })
2189
2190 #else /* CONFIG_MMU */
2191@@ -230,13 +263,17 @@ static inline void set_fs(mm_segment_t fs)
2192 #define __get_user(x,ptr) \
2193 ({ \
2194 long __gu_err = 0; \
2195+ pax_open_userland(); \
2196 __get_user_err((x),(ptr),__gu_err); \
2197+ pax_close_userland(); \
2198 __gu_err; \
2199 })
2200
2201 #define __get_user_error(x,ptr,err) \
2202 ({ \
2203+ pax_open_userland(); \
2204 __get_user_err((x),(ptr),err); \
2205+ pax_close_userland(); \
2206 (void) 0; \
2207 })
2208
2209@@ -312,13 +349,17 @@ do { \
2210 #define __put_user(x,ptr) \
2211 ({ \
2212 long __pu_err = 0; \
2213+ pax_open_userland(); \
2214 __put_user_err((x),(ptr),__pu_err); \
2215+ pax_close_userland(); \
2216 __pu_err; \
2217 })
2218
2219 #define __put_user_error(x,ptr,err) \
2220 ({ \
2221+ pax_open_userland(); \
2222 __put_user_err((x),(ptr),err); \
2223+ pax_close_userland(); \
2224 (void) 0; \
2225 })
2226
2227@@ -418,11 +459,44 @@ do { \
2228
2229
2230 #ifdef CONFIG_MMU
2231-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2232-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2233+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2234+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2235+
2236+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2237+{
2238+ unsigned long ret;
2239+
2240+ check_object_size(to, n, false);
2241+ pax_open_userland();
2242+ ret = ___copy_from_user(to, from, n);
2243+ pax_close_userland();
2244+ return ret;
2245+}
2246+
2247+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2248+{
2249+ unsigned long ret;
2250+
2251+ check_object_size(from, n, true);
2252+ pax_open_userland();
2253+ ret = ___copy_to_user(to, from, n);
2254+ pax_close_userland();
2255+ return ret;
2256+}
2257+
2258 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2259-extern unsigned long __must_check __clear_user(void __user *addr, 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_std(void __user *addr, unsigned long n);
2262+
2263+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2264+{
2265+ unsigned long ret;
2266+ pax_open_userland();
2267+ ret = ___clear_user(addr, n);
2268+ pax_close_userland();
2269+ return ret;
2270+}
2271+
2272 #else
2273 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2274 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2275@@ -431,6 +505,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2276
2277 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2278 {
2279+ if ((long)n < 0)
2280+ return n;
2281+
2282 if (access_ok(VERIFY_READ, from, n))
2283 n = __copy_from_user(to, from, n);
2284 else /* security hole - plug it */
2285@@ -440,6 +517,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2286
2287 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2288 {
2289+ if ((long)n < 0)
2290+ return n;
2291+
2292 if (access_ok(VERIFY_WRITE, to, n))
2293 n = __copy_to_user(to, from, n);
2294 return n;
2295diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2296index 96ee092..37f1844 100644
2297--- a/arch/arm/include/uapi/asm/ptrace.h
2298+++ b/arch/arm/include/uapi/asm/ptrace.h
2299@@ -73,7 +73,7 @@
2300 * ARMv7 groups of PSR bits
2301 */
2302 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2303-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2304+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2305 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2306 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2307
2308diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2309index 60d3b73..9168db0 100644
2310--- a/arch/arm/kernel/armksyms.c
2311+++ b/arch/arm/kernel/armksyms.c
2312@@ -89,8 +89,8 @@ EXPORT_SYMBOL(__memzero);
2313 #ifdef CONFIG_MMU
2314 EXPORT_SYMBOL(copy_page);
2315
2316-EXPORT_SYMBOL(__copy_from_user);
2317-EXPORT_SYMBOL(__copy_to_user);
2318+EXPORT_SYMBOL(___copy_from_user);
2319+EXPORT_SYMBOL(___copy_to_user);
2320 EXPORT_SYMBOL(__clear_user);
2321
2322 EXPORT_SYMBOL(__get_user_1);
2323diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2324index 0f82098..3dbd3ee 100644
2325--- a/arch/arm/kernel/entry-armv.S
2326+++ b/arch/arm/kernel/entry-armv.S
2327@@ -47,6 +47,87 @@
2328 9997:
2329 .endm
2330
2331+ .macro pax_enter_kernel
2332+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2333+ @ make aligned space for saved DACR
2334+ sub sp, sp, #8
2335+ @ save regs
2336+ stmdb sp!, {r1, r2}
2337+ @ read DACR from cpu_domain into r1
2338+ mov r2, sp
2339+ @ assume 8K pages, since we have to split the immediate in two
2340+ bic r2, r2, #(0x1fc0)
2341+ bic r2, r2, #(0x3f)
2342+ ldr r1, [r2, #TI_CPU_DOMAIN]
2343+ @ store old DACR on stack
2344+ str r1, [sp, #8]
2345+#ifdef CONFIG_PAX_KERNEXEC
2346+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2347+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2348+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2349+#endif
2350+#ifdef CONFIG_PAX_MEMORY_UDEREF
2351+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2352+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2353+#endif
2354+ @ write r1 to current_thread_info()->cpu_domain
2355+ str r1, [r2, #TI_CPU_DOMAIN]
2356+ @ write r1 to DACR
2357+ mcr p15, 0, r1, c3, c0, 0
2358+ @ instruction sync
2359+ instr_sync
2360+ @ restore regs
2361+ ldmia sp!, {r1, r2}
2362+#endif
2363+ .endm
2364+
2365+ .macro pax_open_userland
2366+#ifdef CONFIG_PAX_MEMORY_UDEREF
2367+ @ save regs
2368+ stmdb sp!, {r0, r1}
2369+ @ read DACR from cpu_domain into r1
2370+ mov r0, sp
2371+ @ assume 8K pages, since we have to split the immediate in two
2372+ bic r0, r0, #(0x1fc0)
2373+ bic r0, r0, #(0x3f)
2374+ ldr r1, [r0, #TI_CPU_DOMAIN]
2375+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2376+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2377+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2378+ @ write r1 to current_thread_info()->cpu_domain
2379+ str r1, [r0, #TI_CPU_DOMAIN]
2380+ @ write r1 to DACR
2381+ mcr p15, 0, r1, c3, c0, 0
2382+ @ instruction sync
2383+ instr_sync
2384+ @ restore regs
2385+ ldmia sp!, {r0, r1}
2386+#endif
2387+ .endm
2388+
2389+ .macro pax_close_userland
2390+#ifdef CONFIG_PAX_MEMORY_UDEREF
2391+ @ save regs
2392+ stmdb sp!, {r0, r1}
2393+ @ read DACR from cpu_domain into r1
2394+ mov r0, sp
2395+ @ assume 8K pages, since we have to split the immediate in two
2396+ bic r0, r0, #(0x1fc0)
2397+ bic r0, r0, #(0x3f)
2398+ ldr r1, [r0, #TI_CPU_DOMAIN]
2399+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2400+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2401+ @ write r1 to current_thread_info()->cpu_domain
2402+ str r1, [r0, #TI_CPU_DOMAIN]
2403+ @ write r1 to DACR
2404+ mcr p15, 0, r1, c3, c0, 0
2405+ @ instruction sync
2406+ instr_sync
2407+ @ restore regs
2408+ ldmia sp!, {r0, r1}
2409+#endif
2410+ .endm
2411+
2412 .macro pabt_helper
2413 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2414 #ifdef MULTI_PABORT
2415@@ -89,11 +170,15 @@
2416 * Invalid mode handlers
2417 */
2418 .macro inv_entry, reason
2419+
2420+ pax_enter_kernel
2421+
2422 sub sp, sp, #S_FRAME_SIZE
2423 ARM( stmib sp, {r1 - lr} )
2424 THUMB( stmia sp, {r0 - r12} )
2425 THUMB( str sp, [sp, #S_SP] )
2426 THUMB( str lr, [sp, #S_LR] )
2427+
2428 mov r1, #\reason
2429 .endm
2430
2431@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2432 .macro svc_entry, stack_hole=0
2433 UNWIND(.fnstart )
2434 UNWIND(.save {r0 - pc} )
2435+
2436+ pax_enter_kernel
2437+
2438 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2439+
2440 #ifdef CONFIG_THUMB2_KERNEL
2441 SPFIX( str r0, [sp] ) @ temporarily saved
2442 SPFIX( mov r0, sp )
2443@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2444 ldmia r0, {r3 - r5}
2445 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2446 mov r6, #-1 @ "" "" "" ""
2447+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2448+ @ offset sp by 8 as done in pax_enter_kernel
2449+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2450+#else
2451 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2452+#endif
2453 SPFIX( addeq r2, r2, #4 )
2454 str r3, [sp, #-4]! @ save the "real" r0 copied
2455 @ from the exception stack
2456@@ -359,6 +453,9 @@ ENDPROC(__pabt_svc)
2457 .macro usr_entry
2458 UNWIND(.fnstart )
2459 UNWIND(.cantunwind ) @ don't unwind the user space
2460+
2461+ pax_enter_kernel_user
2462+
2463 sub sp, sp, #S_FRAME_SIZE
2464 ARM( stmib sp, {r1 - r12} )
2465 THUMB( stmia sp, {r0 - r12} )
2466@@ -456,7 +553,9 @@ __und_usr:
2467 tst r3, #PSR_T_BIT @ Thumb mode?
2468 bne __und_usr_thumb
2469 sub r4, r2, #4 @ ARM instr at LR - 4
2470+ pax_open_userland
2471 1: ldrt r0, [r4]
2472+ pax_close_userland
2473 #ifdef CONFIG_CPU_ENDIAN_BE8
2474 rev r0, r0 @ little endian instruction
2475 #endif
2476@@ -491,10 +590,14 @@ __und_usr_thumb:
2477 */
2478 .arch armv6t2
2479 #endif
2480+ pax_open_userland
2481 2: ldrht r5, [r4]
2482+ pax_close_userland
2483 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2484 blo __und_usr_fault_16 @ 16bit undefined instruction
2485+ pax_open_userland
2486 3: ldrht r0, [r2]
2487+ pax_close_userland
2488 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2489 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2490 orr r0, r0, r5, lsl #16
2491@@ -733,7 +836,7 @@ ENTRY(__switch_to)
2492 THUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stack
2493 THUMB( str sp, [ip], #4 )
2494 THUMB( str lr, [ip], #4 )
2495-#ifdef CONFIG_CPU_USE_DOMAINS
2496+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC)
2497 ldr r6, [r2, #TI_CPU_DOMAIN]
2498 #endif
2499 set_tls r3, r4, r5
2500@@ -742,7 +845,7 @@ ENTRY(__switch_to)
2501 ldr r8, =__stack_chk_guard
2502 ldr r7, [r7, #TSK_STACK_CANARY]
2503 #endif
2504-#ifdef CONFIG_CPU_USE_DOMAINS
2505+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC)
2506 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2507 #endif
2508 mov r5, r0
2509diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2510index a6c301e..908821b 100644
2511--- a/arch/arm/kernel/entry-common.S
2512+++ b/arch/arm/kernel/entry-common.S
2513@@ -10,18 +10,46 @@
2514
2515 #include <asm/unistd.h>
2516 #include <asm/ftrace.h>
2517+#include <asm/domain.h>
2518 #include <asm/unwind.h>
2519
2520+#include "entry-header.S"
2521+
2522 #ifdef CONFIG_NEED_RET_TO_USER
2523 #include <mach/entry-macro.S>
2524 #else
2525 .macro arch_ret_to_user, tmp1, tmp2
2526+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2527+ @ save regs
2528+ stmdb sp!, {r1, r2}
2529+ @ read DACR from cpu_domain into r1
2530+ mov r2, sp
2531+ @ assume 8K pages, since we have to split the immediate in two
2532+ bic r2, r2, #(0x1fc0)
2533+ bic r2, r2, #(0x3f)
2534+ ldr r1, [r2, #TI_CPU_DOMAIN]
2535+#ifdef CONFIG_PAX_KERNEXEC
2536+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2537+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2538+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2539+#endif
2540+#ifdef CONFIG_PAX_MEMORY_UDEREF
2541+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2542+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2543+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2544+#endif
2545+ @ write r1 to current_thread_info()->cpu_domain
2546+ str r1, [r2, #TI_CPU_DOMAIN]
2547+ @ write r1 to DACR
2548+ mcr p15, 0, r1, c3, c0, 0
2549+ @ instruction sync
2550+ instr_sync
2551+ @ restore regs
2552+ ldmia sp!, {r1, r2}
2553+#endif
2554 .endm
2555 #endif
2556
2557-#include "entry-header.S"
2558-
2559-
2560 .align 5
2561 /*
2562 * This is the fast syscall return path. We do as little as
2563@@ -339,6 +367,7 @@ ENDPROC(ftrace_stub)
2564
2565 .align 5
2566 ENTRY(vector_swi)
2567+
2568 sub sp, sp, #S_FRAME_SIZE
2569 stmia sp, {r0 - r12} @ Calling r0 - r12
2570 ARM( add r8, sp, #S_PC )
2571@@ -388,6 +417,12 @@ ENTRY(vector_swi)
2572 ldr scno, [lr, #-4] @ get SWI instruction
2573 #endif
2574
2575+ /*
2576+ * do this here to avoid a performance hit of wrapping the code above
2577+ * that directly dereferences userland to parse the SWI instruction
2578+ */
2579+ pax_enter_kernel_user
2580+
2581 #ifdef CONFIG_ALIGNMENT_TRAP
2582 ldr ip, __cr_alignment
2583 ldr ip, [ip]
2584diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2585index 9a8531e..812e287 100644
2586--- a/arch/arm/kernel/entry-header.S
2587+++ b/arch/arm/kernel/entry-header.S
2588@@ -73,9 +73,66 @@
2589 msr cpsr_c, \rtemp @ switch back to the SVC mode
2590 .endm
2591
2592+ .macro pax_enter_kernel_user
2593+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2594+ @ save regs
2595+ stmdb sp!, {r0, r1}
2596+ @ read DACR from cpu_domain into r1
2597+ mov r0, sp
2598+ @ assume 8K pages, since we have to split the immediate in two
2599+ bic r0, r0, #(0x1fc0)
2600+ bic r0, r0, #(0x3f)
2601+ ldr r1, [r0, #TI_CPU_DOMAIN]
2602+#ifdef CONFIG_PAX_MEMORY_UDEREF
2603+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2604+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2605+#endif
2606+#ifdef CONFIG_PAX_KERNEXEC
2607+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2608+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2609+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2610+#endif
2611+ @ write r1 to current_thread_info()->cpu_domain
2612+ str r1, [r0, #TI_CPU_DOMAIN]
2613+ @ write r1 to DACR
2614+ mcr p15, 0, r1, c3, c0, 0
2615+ @ instruction sync
2616+ instr_sync
2617+ @ restore regs
2618+ ldmia sp!, {r0, r1}
2619+#endif
2620+ .endm
2621+
2622+ .macro pax_exit_kernel
2623+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2624+ @ save regs
2625+ stmdb sp!, {r0, r1}
2626+ @ read old DACR from stack into r1
2627+ ldr r1, [sp, #(8 + S_SP)]
2628+ sub r1, r1, #8
2629+ ldr r1, [r1]
2630+
2631+ @ write r1 to current_thread_info()->cpu_domain
2632+ mov r0, sp
2633+ @ assume 8K pages, since we have to split the immediate in two
2634+ bic r0, r0, #(0x1fc0)
2635+ bic r0, r0, #(0x3f)
2636+ str r1, [r0, #TI_CPU_DOMAIN]
2637+ @ write r1 to DACR
2638+ mcr p15, 0, r1, c3, c0, 0
2639+ @ instruction sync
2640+ instr_sync
2641+ @ restore regs
2642+ ldmia sp!, {r0, r1}
2643+#endif
2644+ .endm
2645+
2646 #ifndef CONFIG_THUMB2_KERNEL
2647 .macro svc_exit, rpsr
2648 msr spsr_cxsf, \rpsr
2649+
2650+ pax_exit_kernel
2651+
2652 #if defined(CONFIG_CPU_V6)
2653 ldr r0, [sp]
2654 strex r1, r2, [sp] @ clear the exclusive monitor
2655@@ -121,6 +178,9 @@
2656 .endm
2657 #else /* CONFIG_THUMB2_KERNEL */
2658 .macro svc_exit, rpsr
2659+
2660+ pax_exit_kernel
2661+
2662 ldr lr, [sp, #S_SP] @ top of the stack
2663 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2664 clrex @ clear the exclusive monitor
2665diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2666index 2adda11..7fbe958 100644
2667--- a/arch/arm/kernel/fiq.c
2668+++ b/arch/arm/kernel/fiq.c
2669@@ -82,7 +82,9 @@ void set_fiq_handler(void *start, unsigned int length)
2670 #if defined(CONFIG_CPU_USE_DOMAINS)
2671 memcpy((void *)0xffff001c, start, length);
2672 #else
2673+ pax_open_kernel();
2674 memcpy(vectors_page + 0x1c, start, length);
2675+ pax_close_kernel();
2676 #endif
2677 flush_icache_range(0xffff001c, 0xffff001c + length);
2678 if (!vectors_high())
2679diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2680index 486a15a..2d6880e 100644
2681--- a/arch/arm/kernel/head.S
2682+++ b/arch/arm/kernel/head.S
2683@@ -52,7 +52,9 @@
2684 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2685
2686 .macro pgtbl, rd, phys
2687- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2688+ mov \rd, #TEXT_OFFSET
2689+ sub \rd, #PG_DIR_SIZE
2690+ add \rd, \rd, \phys
2691 .endm
2692
2693 /*
2694@@ -416,7 +418,7 @@ __enable_mmu:
2695 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2696 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2697 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2698- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2699+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2700 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2701 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2702 #endif
2703diff --git a/arch/arm/kernel/hw_breakpoint.c b/arch/arm/kernel/hw_breakpoint.c
2704index 5ff2e77..556d030 100644
2705--- a/arch/arm/kernel/hw_breakpoint.c
2706+++ b/arch/arm/kernel/hw_breakpoint.c
2707@@ -1011,7 +1011,7 @@ static int __cpuinit dbg_reset_notify(struct notifier_block *self,
2708 return NOTIFY_OK;
2709 }
2710
2711-static struct notifier_block __cpuinitdata dbg_reset_nb = {
2712+static struct notifier_block dbg_reset_nb = {
2713 .notifier_call = dbg_reset_notify,
2714 };
2715
2716diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2717index 1e9be5d..03edbc2 100644
2718--- a/arch/arm/kernel/module.c
2719+++ b/arch/arm/kernel/module.c
2720@@ -37,12 +37,37 @@
2721 #endif
2722
2723 #ifdef CONFIG_MMU
2724-void *module_alloc(unsigned long size)
2725+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2726 {
2727+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2728+ return NULL;
2729 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2730- GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2731+ GFP_KERNEL, prot, -1,
2732 __builtin_return_address(0));
2733 }
2734+
2735+void *module_alloc(unsigned long size)
2736+{
2737+
2738+#ifdef CONFIG_PAX_KERNEXEC
2739+ return __module_alloc(size, PAGE_KERNEL);
2740+#else
2741+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2742+#endif
2743+
2744+}
2745+
2746+#ifdef CONFIG_PAX_KERNEXEC
2747+void module_free_exec(struct module *mod, void *module_region)
2748+{
2749+ module_free(mod, module_region);
2750+}
2751+
2752+void *module_alloc_exec(unsigned long size)
2753+{
2754+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2755+}
2756+#endif
2757 #endif
2758
2759 int
2760diff --git a/arch/arm/kernel/perf_event_cpu.c b/arch/arm/kernel/perf_event_cpu.c
2761index 5f66206..dce492f 100644
2762--- a/arch/arm/kernel/perf_event_cpu.c
2763+++ b/arch/arm/kernel/perf_event_cpu.c
2764@@ -171,7 +171,7 @@ static int __cpuinit cpu_pmu_notify(struct notifier_block *b,
2765 return NOTIFY_OK;
2766 }
2767
2768-static struct notifier_block __cpuinitdata cpu_pmu_hotplug_notifier = {
2769+static struct notifier_block cpu_pmu_hotplug_notifier = {
2770 .notifier_call = cpu_pmu_notify,
2771 };
2772
2773diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2774index c6dec5f..f853532 100644
2775--- a/arch/arm/kernel/process.c
2776+++ b/arch/arm/kernel/process.c
2777@@ -28,7 +28,6 @@
2778 #include <linux/tick.h>
2779 #include <linux/utsname.h>
2780 #include <linux/uaccess.h>
2781-#include <linux/random.h>
2782 #include <linux/hw_breakpoint.h>
2783 #include <linux/cpuidle.h>
2784 #include <linux/leds.h>
2785@@ -256,9 +255,10 @@ void machine_power_off(void)
2786 machine_shutdown();
2787 if (pm_power_off)
2788 pm_power_off();
2789+ BUG();
2790 }
2791
2792-void machine_restart(char *cmd)
2793+__noreturn void machine_restart(char *cmd)
2794 {
2795 machine_shutdown();
2796
2797@@ -283,8 +283,8 @@ void __show_regs(struct pt_regs *regs)
2798 init_utsname()->release,
2799 (int)strcspn(init_utsname()->version, " "),
2800 init_utsname()->version);
2801- print_symbol("PC is at %s\n", instruction_pointer(regs));
2802- print_symbol("LR is at %s\n", regs->ARM_lr);
2803+ printk("PC is at %pA\n", instruction_pointer(regs));
2804+ printk("LR is at %pA\n", regs->ARM_lr);
2805 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2806 "sp : %08lx ip : %08lx fp : %08lx\n",
2807 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2808@@ -452,12 +452,6 @@ unsigned long get_wchan(struct task_struct *p)
2809 return 0;
2810 }
2811
2812-unsigned long arch_randomize_brk(struct mm_struct *mm)
2813-{
2814- unsigned long range_end = mm->brk + 0x02000000;
2815- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2816-}
2817-
2818 #ifdef CONFIG_MMU
2819 /*
2820 * The vectors page is always readable from user space for the
2821diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2822index 03deeff..741ce88 100644
2823--- a/arch/arm/kernel/ptrace.c
2824+++ b/arch/arm/kernel/ptrace.c
2825@@ -937,10 +937,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2826 return current_thread_info()->syscall;
2827 }
2828
2829+#ifdef CONFIG_GRKERNSEC_SETXID
2830+extern void gr_delayed_cred_worker(void);
2831+#endif
2832+
2833 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2834 {
2835 current_thread_info()->syscall = scno;
2836
2837+#ifdef CONFIG_GRKERNSEC_SETXID
2838+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2839+ gr_delayed_cred_worker();
2840+#endif
2841+
2842 /* Do the secure computing check first; failures should be fast. */
2843 if (secure_computing(scno) == -1)
2844 return -1;
2845diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2846index 3f6cbb2..6d856f5 100644
2847--- a/arch/arm/kernel/setup.c
2848+++ b/arch/arm/kernel/setup.c
2849@@ -97,21 +97,23 @@ EXPORT_SYMBOL(system_serial_high);
2850 unsigned int elf_hwcap __read_mostly;
2851 EXPORT_SYMBOL(elf_hwcap);
2852
2853+pteval_t __supported_pte_mask __read_only;
2854+pmdval_t __supported_pmd_mask __read_only;
2855
2856 #ifdef MULTI_CPU
2857-struct processor processor __read_mostly;
2858+struct processor processor;
2859 #endif
2860 #ifdef MULTI_TLB
2861-struct cpu_tlb_fns cpu_tlb __read_mostly;
2862+struct cpu_tlb_fns cpu_tlb __read_only;
2863 #endif
2864 #ifdef MULTI_USER
2865-struct cpu_user_fns cpu_user __read_mostly;
2866+struct cpu_user_fns cpu_user __read_only;
2867 #endif
2868 #ifdef MULTI_CACHE
2869-struct cpu_cache_fns cpu_cache __read_mostly;
2870+struct cpu_cache_fns cpu_cache __read_only;
2871 #endif
2872 #ifdef CONFIG_OUTER_CACHE
2873-struct outer_cache_fns outer_cache __read_mostly;
2874+struct outer_cache_fns outer_cache __read_only;
2875 EXPORT_SYMBOL(outer_cache);
2876 #endif
2877
2878@@ -236,9 +238,13 @@ static int __get_cpu_architecture(void)
2879 asm("mrc p15, 0, %0, c0, c1, 4"
2880 : "=r" (mmfr0));
2881 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2882- (mmfr0 & 0x000000f0) >= 0x00000030)
2883+ (mmfr0 & 0x000000f0) >= 0x00000030) {
2884 cpu_arch = CPU_ARCH_ARMv7;
2885- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2886+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2887+ __supported_pte_mask |= L_PTE_PXN;
2888+ __supported_pmd_mask |= PMD_PXNTABLE;
2889+ }
2890+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2891 (mmfr0 & 0x000000f0) == 0x00000020)
2892 cpu_arch = CPU_ARCH_ARMv6;
2893 else
2894@@ -462,7 +468,7 @@ static void __init setup_processor(void)
2895 __cpu_architecture = __get_cpu_architecture();
2896
2897 #ifdef MULTI_CPU
2898- processor = *list->proc;
2899+ memcpy((void *)&processor, list->proc, sizeof processor);
2900 #endif
2901 #ifdef MULTI_TLB
2902 cpu_tlb = *list->tlb;
2903diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
2904index 84f4cbf..672f5b8 100644
2905--- a/arch/arm/kernel/smp.c
2906+++ b/arch/arm/kernel/smp.c
2907@@ -70,7 +70,7 @@ enum ipi_msg_type {
2908
2909 static DECLARE_COMPLETION(cpu_running);
2910
2911-static struct smp_operations smp_ops;
2912+static struct smp_operations smp_ops __read_only;
2913
2914 void __init smp_set_ops(struct smp_operations *ops)
2915 {
2916diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
2917index b0179b8..b7b16c7 100644
2918--- a/arch/arm/kernel/traps.c
2919+++ b/arch/arm/kernel/traps.c
2920@@ -57,7 +57,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
2921 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
2922 {
2923 #ifdef CONFIG_KALLSYMS
2924- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
2925+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
2926 #else
2927 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
2928 #endif
2929@@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
2930 static int die_owner = -1;
2931 static unsigned int die_nest_count;
2932
2933+extern void gr_handle_kernel_exploit(void);
2934+
2935 static unsigned long oops_begin(void)
2936 {
2937 int cpu;
2938@@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
2939 panic("Fatal exception in interrupt");
2940 if (panic_on_oops)
2941 panic("Fatal exception");
2942+
2943+ gr_handle_kernel_exploit();
2944+
2945 if (signr)
2946 do_exit(signr);
2947 }
2948@@ -601,7 +606,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
2949 * The user helper at 0xffff0fe0 must be used instead.
2950 * (see entry-armv.S for details)
2951 */
2952+ pax_open_kernel();
2953 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
2954+ pax_close_kernel();
2955 }
2956 return 0;
2957
2958@@ -849,5 +856,9 @@ void __init early_trap_init(void *vectors_base)
2959 sigreturn_codes, sizeof(sigreturn_codes));
2960
2961 flush_icache_range(vectors, vectors + PAGE_SIZE);
2962- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
2963+
2964+#ifndef CONFIG_PAX_MEMORY_UDEREF
2965+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
2966+#endif
2967+
2968 }
2969diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
2970index 11c1785..c67d54c 100644
2971--- a/arch/arm/kernel/vmlinux.lds.S
2972+++ b/arch/arm/kernel/vmlinux.lds.S
2973@@ -8,7 +8,11 @@
2974 #include <asm/thread_info.h>
2975 #include <asm/memory.h>
2976 #include <asm/page.h>
2977-
2978+
2979+#ifdef CONFIG_PAX_KERNEXEC
2980+#include <asm/pgtable.h>
2981+#endif
2982+
2983 #define PROC_INFO \
2984 . = ALIGN(4); \
2985 VMLINUX_SYMBOL(__proc_info_begin) = .; \
2986@@ -90,6 +94,11 @@ SECTIONS
2987 _text = .;
2988 HEAD_TEXT
2989 }
2990+
2991+#ifdef CONFIG_PAX_KERNEXEC
2992+ . = ALIGN(1<<SECTION_SHIFT);
2993+#endif
2994+
2995 .text : { /* Real text segment */
2996 _stext = .; /* Text and read-only data */
2997 __exception_text_start = .;
2998@@ -144,6 +153,10 @@ SECTIONS
2999
3000 _etext = .; /* End of text and rodata section */
3001
3002+#ifdef CONFIG_PAX_KERNEXEC
3003+ . = ALIGN(1<<SECTION_SHIFT);
3004+#endif
3005+
3006 #ifndef CONFIG_XIP_KERNEL
3007 . = ALIGN(PAGE_SIZE);
3008 __init_begin = .;
3009@@ -203,6 +216,11 @@ SECTIONS
3010 . = PAGE_OFFSET + TEXT_OFFSET;
3011 #else
3012 __init_end = .;
3013+
3014+#ifdef CONFIG_PAX_KERNEXEC
3015+ . = ALIGN(1<<SECTION_SHIFT);
3016+#endif
3017+
3018 . = ALIGN(THREAD_SIZE);
3019 __data_loc = .;
3020 #endif
3021diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3022index 14a0d98..7771a7d 100644
3023--- a/arch/arm/lib/clear_user.S
3024+++ b/arch/arm/lib/clear_user.S
3025@@ -12,14 +12,14 @@
3026
3027 .text
3028
3029-/* Prototype: int __clear_user(void *addr, size_t sz)
3030+/* Prototype: int ___clear_user(void *addr, size_t sz)
3031 * Purpose : clear some user memory
3032 * Params : addr - user memory address to clear
3033 * : sz - number of bytes to clear
3034 * Returns : number of bytes NOT cleared
3035 */
3036 ENTRY(__clear_user_std)
3037-WEAK(__clear_user)
3038+WEAK(___clear_user)
3039 stmfd sp!, {r1, lr}
3040 mov r2, #0
3041 cmp r1, #4
3042@@ -44,7 +44,7 @@ WEAK(__clear_user)
3043 USER( strnebt r2, [r0])
3044 mov r0, #0
3045 ldmfd sp!, {r1, pc}
3046-ENDPROC(__clear_user)
3047+ENDPROC(___clear_user)
3048 ENDPROC(__clear_user_std)
3049
3050 .pushsection .fixup,"ax"
3051diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3052index 66a477a..bee61d3 100644
3053--- a/arch/arm/lib/copy_from_user.S
3054+++ b/arch/arm/lib/copy_from_user.S
3055@@ -16,7 +16,7 @@
3056 /*
3057 * Prototype:
3058 *
3059- * size_t __copy_from_user(void *to, const void *from, size_t n)
3060+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3061 *
3062 * Purpose:
3063 *
3064@@ -84,11 +84,11 @@
3065
3066 .text
3067
3068-ENTRY(__copy_from_user)
3069+ENTRY(___copy_from_user)
3070
3071 #include "copy_template.S"
3072
3073-ENDPROC(__copy_from_user)
3074+ENDPROC(___copy_from_user)
3075
3076 .pushsection .fixup,"ax"
3077 .align 0
3078diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3079index 6ee2f67..d1cce76 100644
3080--- a/arch/arm/lib/copy_page.S
3081+++ b/arch/arm/lib/copy_page.S
3082@@ -10,6 +10,7 @@
3083 * ASM optimised string functions
3084 */
3085 #include <linux/linkage.h>
3086+#include <linux/const.h>
3087 #include <asm/assembler.h>
3088 #include <asm/asm-offsets.h>
3089 #include <asm/cache.h>
3090diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3091index d066df6..df28194 100644
3092--- a/arch/arm/lib/copy_to_user.S
3093+++ b/arch/arm/lib/copy_to_user.S
3094@@ -16,7 +16,7 @@
3095 /*
3096 * Prototype:
3097 *
3098- * size_t __copy_to_user(void *to, const void *from, size_t n)
3099+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3100 *
3101 * Purpose:
3102 *
3103@@ -88,11 +88,11 @@
3104 .text
3105
3106 ENTRY(__copy_to_user_std)
3107-WEAK(__copy_to_user)
3108+WEAK(___copy_to_user)
3109
3110 #include "copy_template.S"
3111
3112-ENDPROC(__copy_to_user)
3113+ENDPROC(___copy_to_user)
3114 ENDPROC(__copy_to_user_std)
3115
3116 .pushsection .fixup,"ax"
3117diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3118index 7d08b43..f7ca7ea 100644
3119--- a/arch/arm/lib/csumpartialcopyuser.S
3120+++ b/arch/arm/lib/csumpartialcopyuser.S
3121@@ -57,8 +57,8 @@
3122 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3123 */
3124
3125-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3126-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3127+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3128+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3129
3130 #include "csumpartialcopygeneric.S"
3131
3132diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3133index 0dc5385..45833ef 100644
3134--- a/arch/arm/lib/delay.c
3135+++ b/arch/arm/lib/delay.c
3136@@ -28,12 +28,14 @@
3137 /*
3138 * Default to the loop-based delay implementation.
3139 */
3140-struct arm_delay_ops arm_delay_ops = {
3141+static struct arm_delay_ops arm_loop_delay_ops = {
3142 .delay = __loop_delay,
3143 .const_udelay = __loop_const_udelay,
3144 .udelay = __loop_udelay,
3145 };
3146
3147+struct arm_delay_ops *arm_delay_ops __read_only = &arm_loop_delay_ops;
3148+
3149 static const struct delay_timer *delay_timer;
3150 static bool delay_calibrated;
3151
3152@@ -67,6 +69,12 @@ static void __timer_udelay(unsigned long usecs)
3153 __timer_const_udelay(usecs * UDELAY_MULT);
3154 }
3155
3156+static struct arm_delay_ops arm_timer_delay_ops = {
3157+ .delay = __timer_delay,
3158+ .const_udelay = __timer_const_udelay,
3159+ .udelay = __timer_udelay,
3160+};
3161+
3162 void __init register_current_timer_delay(const struct delay_timer *timer)
3163 {
3164 if (!delay_calibrated) {
3165@@ -74,9 +82,7 @@ void __init register_current_timer_delay(const struct delay_timer *timer)
3166 delay_timer = timer;
3167 lpj_fine = timer->freq / HZ;
3168 loops_per_jiffy = lpj_fine;
3169- arm_delay_ops.delay = __timer_delay;
3170- arm_delay_ops.const_udelay = __timer_const_udelay;
3171- arm_delay_ops.udelay = __timer_udelay;
3172+ arm_delay_ops = &arm_timer_delay_ops;
3173 delay_calibrated = true;
3174 } else {
3175 pr_info("Ignoring duplicate/late registration of read_current_timer delay\n");
3176diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3177index 025f742..8432b08 100644
3178--- a/arch/arm/lib/uaccess_with_memcpy.c
3179+++ b/arch/arm/lib/uaccess_with_memcpy.c
3180@@ -104,7 +104,7 @@ out:
3181 }
3182
3183 unsigned long
3184-__copy_to_user(void __user *to, const void *from, unsigned long n)
3185+___copy_to_user(void __user *to, const void *from, unsigned long n)
3186 {
3187 /*
3188 * This test is stubbed out of the main function above to keep
3189diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3190index bac21a5..b67ef8e 100644
3191--- a/arch/arm/mach-kirkwood/common.c
3192+++ b/arch/arm/mach-kirkwood/common.c
3193@@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3194 clk_gate_ops.disable(hw);
3195 }
3196
3197-static struct clk_ops clk_gate_fn_ops;
3198+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3199+{
3200+ return clk_gate_ops.is_enabled(hw);
3201+}
3202+
3203+static struct clk_ops clk_gate_fn_ops = {
3204+ .enable = clk_gate_fn_enable,
3205+ .disable = clk_gate_fn_disable,
3206+ .is_enabled = clk_gate_fn_is_enabled,
3207+};
3208
3209 static struct clk __init *clk_register_gate_fn(struct device *dev,
3210 const char *name,
3211@@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3212 gate_fn->fn_en = fn_en;
3213 gate_fn->fn_dis = fn_dis;
3214
3215- /* ops is the gate ops, but with our enable/disable functions */
3216- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3217- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3218- clk_gate_fn_ops = clk_gate_ops;
3219- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3220- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3221- }
3222-
3223 clk = clk_register(dev, &gate_fn->gate.hw);
3224
3225 if (IS_ERR(clk))
3226diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3227index 0abb30f..54064da 100644
3228--- a/arch/arm/mach-omap2/board-n8x0.c
3229+++ b/arch/arm/mach-omap2/board-n8x0.c
3230@@ -631,7 +631,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3231 }
3232 #endif
3233
3234-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3235+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3236 .late_init = n8x0_menelaus_late_init,
3237 };
3238
3239diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3240index 5d3b4f4..ddba3c0 100644
3241--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3242+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3243@@ -340,7 +340,7 @@ static int __cpuinit irq_cpu_hotplug_notify(struct notifier_block *self,
3244 return NOTIFY_OK;
3245 }
3246
3247-static struct notifier_block __refdata irq_hotplug_notifier = {
3248+static struct notifier_block irq_hotplug_notifier = {
3249 .notifier_call = irq_cpu_hotplug_notify,
3250 };
3251
3252diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3253index 4653efb..8c60bf7 100644
3254--- a/arch/arm/mach-omap2/omap_hwmod.c
3255+++ b/arch/arm/mach-omap2/omap_hwmod.c
3256@@ -189,10 +189,10 @@ struct omap_hwmod_soc_ops {
3257 int (*init_clkdm)(struct omap_hwmod *oh);
3258 void (*update_context_lost)(struct omap_hwmod *oh);
3259 int (*get_context_lost)(struct omap_hwmod *oh);
3260-};
3261+} __no_const;
3262
3263 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3264-static struct omap_hwmod_soc_ops soc_ops;
3265+static struct omap_hwmod_soc_ops soc_ops __read_only;
3266
3267 /* omap_hwmod_list contains all registered struct omap_hwmods */
3268 static LIST_HEAD(omap_hwmod_list);
3269diff --git a/arch/arm/mach-ux500/include/mach/setup.h b/arch/arm/mach-ux500/include/mach/setup.h
3270index 6be4c4d..32ac32a 100644
3271--- a/arch/arm/mach-ux500/include/mach/setup.h
3272+++ b/arch/arm/mach-ux500/include/mach/setup.h
3273@@ -38,13 +38,6 @@ extern struct sys_timer ux500_timer;
3274 .type = MT_DEVICE, \
3275 }
3276
3277-#define __MEM_DEV_DESC(x, sz) { \
3278- .virtual = IO_ADDRESS(x), \
3279- .pfn = __phys_to_pfn(x), \
3280- .length = sz, \
3281- .type = MT_MEMORY, \
3282-}
3283-
3284 extern struct smp_operations ux500_smp_ops;
3285 extern void ux500_cpu_die(unsigned int cpu);
3286
3287diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3288index 3fd629d..8b1aca9 100644
3289--- a/arch/arm/mm/Kconfig
3290+++ b/arch/arm/mm/Kconfig
3291@@ -425,7 +425,7 @@ config CPU_32v5
3292
3293 config CPU_32v6
3294 bool
3295- select CPU_USE_DOMAINS if CPU_V6 && MMU
3296+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC
3297 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3298
3299 config CPU_32v6K
3300@@ -577,6 +577,7 @@ config CPU_CP15_MPU
3301
3302 config CPU_USE_DOMAINS
3303 bool
3304+ depends on !ARM_LPAE && !PAX_KERNEXEC
3305 help
3306 This option enables or disables the use of domain switching
3307 via the set_fs() function.
3308diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3309index 5dbf13f..6393f55 100644
3310--- a/arch/arm/mm/fault.c
3311+++ b/arch/arm/mm/fault.c
3312@@ -25,6 +25,7 @@
3313 #include <asm/system_misc.h>
3314 #include <asm/system_info.h>
3315 #include <asm/tlbflush.h>
3316+#include <asm/sections.h>
3317
3318 #include "fault.h"
3319
3320@@ -138,6 +139,20 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3321 if (fixup_exception(regs))
3322 return;
3323
3324+#ifdef CONFIG_PAX_KERNEXEC
3325+ if ((fsr & FSR_WRITE) &&
3326+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3327+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3328+ {
3329+ if (current->signal->curr_ip)
3330+ 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),
3331+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
3332+ else
3333+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3334+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
3335+ }
3336+#endif
3337+
3338 /*
3339 * No handler, we'll have to terminate things with extreme prejudice.
3340 */
3341@@ -174,6 +189,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3342 }
3343 #endif
3344
3345+#ifdef CONFIG_PAX_PAGEEXEC
3346+ if (fsr & FSR_LNX_PF) {
3347+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3348+ do_group_exit(SIGKILL);
3349+ }
3350+#endif
3351+
3352 tsk->thread.address = addr;
3353 tsk->thread.error_code = fsr;
3354 tsk->thread.trap_no = 14;
3355@@ -398,6 +420,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3356 }
3357 #endif /* CONFIG_MMU */
3358
3359+#ifdef CONFIG_PAX_PAGEEXEC
3360+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3361+{
3362+ long i;
3363+
3364+ printk(KERN_ERR "PAX: bytes at PC: ");
3365+ for (i = 0; i < 20; i++) {
3366+ unsigned char c;
3367+ if (get_user(c, (__force unsigned char __user *)pc+i))
3368+ printk(KERN_CONT "?? ");
3369+ else
3370+ printk(KERN_CONT "%02x ", c);
3371+ }
3372+ printk("\n");
3373+
3374+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3375+ for (i = -1; i < 20; i++) {
3376+ unsigned long c;
3377+ if (get_user(c, (__force unsigned long __user *)sp+i))
3378+ printk(KERN_CONT "???????? ");
3379+ else
3380+ printk(KERN_CONT "%08lx ", c);
3381+ }
3382+ printk("\n");
3383+}
3384+#endif
3385+
3386 /*
3387 * First Level Translation Fault Handler
3388 *
3389@@ -543,9 +592,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3390 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3391 struct siginfo info;
3392
3393+#ifdef CONFIG_PAX_MEMORY_UDEREF
3394+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3395+ if (current->signal->curr_ip)
3396+ 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),
3397+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()), addr);
3398+ else
3399+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3400+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()), addr);
3401+ goto die;
3402+ }
3403+#endif
3404+
3405 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3406 return;
3407
3408+die:
3409 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3410 inf->name, fsr, addr);
3411
3412@@ -575,9 +637,38 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3413 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3414 struct siginfo info;
3415
3416+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3417+ if (!user_mode(regs) && (is_domain_fault(ifsr) || is_xn_fault(ifsr))) {
3418+ if (current->signal->curr_ip)
3419+ 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),
3420+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()),
3421+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3422+ else
3423+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3424+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()),
3425+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3426+ goto die;
3427+ }
3428+#endif
3429+
3430+#ifdef CONFIG_PAX_REFCOUNT
3431+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3432+ unsigned int bkpt;
3433+
3434+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
3435+ current->thread.error_code = ifsr;
3436+ current->thread.trap_no = 0;
3437+ pax_report_refcount_overflow(regs);
3438+ fixup_exception(regs);
3439+ return;
3440+ }
3441+ }
3442+#endif
3443+
3444 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
3445 return;
3446
3447+die:
3448 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
3449 inf->name, ifsr, addr);
3450
3451diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
3452index cf08bdf..772656c 100644
3453--- a/arch/arm/mm/fault.h
3454+++ b/arch/arm/mm/fault.h
3455@@ -3,6 +3,7 @@
3456
3457 /*
3458 * Fault status register encodings. We steal bit 31 for our own purposes.
3459+ * Set when the FSR value is from an instruction fault.
3460 */
3461 #define FSR_LNX_PF (1 << 31)
3462 #define FSR_WRITE (1 << 11)
3463@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
3464 }
3465 #endif
3466
3467+/* valid for LPAE and !LPAE */
3468+static inline int is_xn_fault(unsigned int fsr)
3469+{
3470+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
3471+}
3472+
3473+static inline int is_domain_fault(unsigned int fsr)
3474+{
3475+ return ((fsr_fs(fsr) & 0xD) == 0x9);
3476+}
3477+
3478 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
3479 unsigned long search_exception_table(unsigned long addr);
3480
3481diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
3482index ad722f1..763fdd3 100644
3483--- a/arch/arm/mm/init.c
3484+++ b/arch/arm/mm/init.c
3485@@ -30,6 +30,8 @@
3486 #include <asm/setup.h>
3487 #include <asm/tlb.h>
3488 #include <asm/fixmap.h>
3489+#include <asm/system_info.h>
3490+#include <asm/cp15.h>
3491
3492 #include <asm/mach/arch.h>
3493 #include <asm/mach/map.h>
3494@@ -736,7 +738,46 @@ void free_initmem(void)
3495 {
3496 #ifdef CONFIG_HAVE_TCM
3497 extern char __tcm_start, __tcm_end;
3498+#endif
3499
3500+#ifdef CONFIG_PAX_KERNEXEC
3501+ unsigned long addr;
3502+ pgd_t *pgd;
3503+ pud_t *pud;
3504+ pmd_t *pmd;
3505+ int cpu_arch = cpu_architecture();
3506+ unsigned int cr = get_cr();
3507+
3508+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
3509+ /* make pages tables, etc before .text NX */
3510+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
3511+ pgd = pgd_offset_k(addr);
3512+ pud = pud_offset(pgd, addr);
3513+ pmd = pmd_offset(pud, addr);
3514+ __section_update(pmd, addr, PMD_SECT_XN);
3515+ }
3516+ /* make init NX */
3517+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
3518+ pgd = pgd_offset_k(addr);
3519+ pud = pud_offset(pgd, addr);
3520+ pmd = pmd_offset(pud, addr);
3521+ __section_update(pmd, addr, PMD_SECT_XN);
3522+ }
3523+ /* make kernel code/rodata RX */
3524+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
3525+ pgd = pgd_offset_k(addr);
3526+ pud = pud_offset(pgd, addr);
3527+ pmd = pmd_offset(pud, addr);
3528+#ifdef CONFIG_ARM_LPAE
3529+ __section_update(pmd, addr, PMD_SECT_RDONLY);
3530+#else
3531+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
3532+#endif
3533+ }
3534+ }
3535+#endif
3536+
3537+#ifdef CONFIG_HAVE_TCM
3538 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
3539 totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)),
3540 __phys_to_pfn(__pa(&__tcm_end)),
3541diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
3542index 88fd86c..7a224ce 100644
3543--- a/arch/arm/mm/ioremap.c
3544+++ b/arch/arm/mm/ioremap.c
3545@@ -335,9 +335,9 @@ __arm_ioremap_exec(unsigned long phys_addr, size_t size, bool cached)
3546 unsigned int mtype;
3547
3548 if (cached)
3549- mtype = MT_MEMORY;
3550+ mtype = MT_MEMORY_RX;
3551 else
3552- mtype = MT_MEMORY_NONCACHED;
3553+ mtype = MT_MEMORY_NONCACHED_RX;
3554
3555 return __arm_ioremap_caller(phys_addr, size, mtype,
3556 __builtin_return_address(0));
3557diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
3558index 10062ce..aa96dd7 100644
3559--- a/arch/arm/mm/mmap.c
3560+++ b/arch/arm/mm/mmap.c
3561@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3562 struct vm_area_struct *vma;
3563 int do_align = 0;
3564 int aliasing = cache_is_vipt_aliasing();
3565+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3566 struct vm_unmapped_area_info info;
3567
3568 /*
3569@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3570 if (len > TASK_SIZE)
3571 return -ENOMEM;
3572
3573+#ifdef CONFIG_PAX_RANDMMAP
3574+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3575+#endif
3576+
3577 if (addr) {
3578 if (do_align)
3579 addr = COLOUR_ALIGN(addr, pgoff);
3580@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3581 addr = PAGE_ALIGN(addr);
3582
3583 vma = find_vma(mm, addr);
3584- if (TASK_SIZE - len >= addr &&
3585- (!vma || addr + len <= vma->vm_start))
3586+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3587 return addr;
3588 }
3589
3590@@ -112,6 +116,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3591 unsigned long addr = addr0;
3592 int do_align = 0;
3593 int aliasing = cache_is_vipt_aliasing();
3594+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3595 struct vm_unmapped_area_info info;
3596
3597 /*
3598@@ -132,6 +137,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3599 return addr;
3600 }
3601
3602+#ifdef CONFIG_PAX_RANDMMAP
3603+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3604+#endif
3605+
3606 /* requesting a specific address */
3607 if (addr) {
3608 if (do_align)
3609@@ -139,8 +148,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3610 else
3611 addr = PAGE_ALIGN(addr);
3612 vma = find_vma(mm, addr);
3613- if (TASK_SIZE - len >= addr &&
3614- (!vma || addr + len <= vma->vm_start))
3615+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3616 return addr;
3617 }
3618
3619@@ -162,6 +170,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3620 VM_BUG_ON(addr != -ENOMEM);
3621 info.flags = 0;
3622 info.low_limit = mm->mmap_base;
3623+
3624+#ifdef CONFIG_PAX_RANDMMAP
3625+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3626+ info.low_limit += mm->delta_mmap;
3627+#endif
3628+
3629 info.high_limit = TASK_SIZE;
3630 addr = vm_unmapped_area(&info);
3631 }
3632@@ -173,6 +187,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3633 {
3634 unsigned long random_factor = 0UL;
3635
3636+#ifdef CONFIG_PAX_RANDMMAP
3637+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3638+#endif
3639+
3640 /* 8 bits of randomness in 20 address space bits */
3641 if ((current->flags & PF_RANDOMIZE) &&
3642 !(current->personality & ADDR_NO_RANDOMIZE))
3643@@ -180,10 +198,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3644
3645 if (mmap_is_legacy()) {
3646 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
3647+
3648+#ifdef CONFIG_PAX_RANDMMAP
3649+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3650+ mm->mmap_base += mm->delta_mmap;
3651+#endif
3652+
3653 mm->get_unmapped_area = arch_get_unmapped_area;
3654 mm->unmap_area = arch_unmap_area;
3655 } else {
3656 mm->mmap_base = mmap_base(random_factor);
3657+
3658+#ifdef CONFIG_PAX_RANDMMAP
3659+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3660+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3661+#endif
3662+
3663 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3664 mm->unmap_area = arch_unmap_area_topdown;
3665 }
3666diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
3667index ce328c7..f82bebb 100644
3668--- a/arch/arm/mm/mmu.c
3669+++ b/arch/arm/mm/mmu.c
3670@@ -35,6 +35,23 @@
3671
3672 #include "mm.h"
3673
3674+
3675+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3676+void modify_domain(unsigned int dom, unsigned int type)
3677+{
3678+ struct thread_info *thread = current_thread_info();
3679+ unsigned int domain = thread->cpu_domain;
3680+ /*
3681+ * DOMAIN_MANAGER might be defined to some other value,
3682+ * use the arch-defined constant
3683+ */
3684+ domain &= ~domain_val(dom, 3);
3685+ thread->cpu_domain = domain | domain_val(dom, type);
3686+ set_domain(thread->cpu_domain);
3687+}
3688+EXPORT_SYMBOL(modify_domain);
3689+#endif
3690+
3691 /*
3692 * empty_zero_page is a special page that is used for
3693 * zero-initialized data and COW.
3694@@ -195,10 +212,18 @@ void adjust_cr(unsigned long mask, unsigned long set)
3695 }
3696 #endif
3697
3698-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
3699+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
3700 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
3701
3702-static struct mem_type mem_types[] = {
3703+#ifdef CONFIG_PAX_KERNEXEC
3704+#define L_PTE_KERNEXEC L_PTE_RDONLY
3705+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
3706+#else
3707+#define L_PTE_KERNEXEC L_PTE_DIRTY
3708+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
3709+#endif
3710+
3711+static struct mem_type mem_types[] __read_only = {
3712 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
3713 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
3714 L_PTE_SHARED,
3715@@ -227,16 +252,16 @@ static struct mem_type mem_types[] = {
3716 [MT_UNCACHED] = {
3717 .prot_pte = PROT_PTE_DEVICE,
3718 .prot_l1 = PMD_TYPE_TABLE,
3719- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3720+ .prot_sect = PROT_SECT_DEVICE,
3721 .domain = DOMAIN_IO,
3722 },
3723 [MT_CACHECLEAN] = {
3724- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3725+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
3726 .domain = DOMAIN_KERNEL,
3727 },
3728 #ifndef CONFIG_ARM_LPAE
3729 [MT_MINICLEAN] = {
3730- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
3731+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
3732 .domain = DOMAIN_KERNEL,
3733 },
3734 #endif
3735@@ -244,36 +269,54 @@ static struct mem_type mem_types[] = {
3736 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3737 L_PTE_RDONLY,
3738 .prot_l1 = PMD_TYPE_TABLE,
3739- .domain = DOMAIN_USER,
3740+ .domain = DOMAIN_VECTORS,
3741 },
3742 [MT_HIGH_VECTORS] = {
3743 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3744 L_PTE_USER | L_PTE_RDONLY,
3745 .prot_l1 = PMD_TYPE_TABLE,
3746- .domain = DOMAIN_USER,
3747+ .domain = DOMAIN_VECTORS,
3748 },
3749- [MT_MEMORY] = {
3750+ [MT_MEMORY_RWX] = {
3751 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
3752 .prot_l1 = PMD_TYPE_TABLE,
3753 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
3754 .domain = DOMAIN_KERNEL,
3755 },
3756+ [MT_MEMORY_RW] = {
3757+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
3758+ .prot_l1 = PMD_TYPE_TABLE,
3759+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
3760+ .domain = DOMAIN_KERNEL,
3761+ },
3762+ [MT_MEMORY_RX] = {
3763+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
3764+ .prot_l1 = PMD_TYPE_TABLE,
3765+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
3766+ .domain = DOMAIN_KERNEL,
3767+ },
3768 [MT_ROM] = {
3769- .prot_sect = PMD_TYPE_SECT,
3770+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
3771 .domain = DOMAIN_KERNEL,
3772 },
3773- [MT_MEMORY_NONCACHED] = {
3774+ [MT_MEMORY_NONCACHED_RW] = {
3775 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3776 L_PTE_MT_BUFFERABLE,
3777 .prot_l1 = PMD_TYPE_TABLE,
3778 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
3779 .domain = DOMAIN_KERNEL,
3780 },
3781+ [MT_MEMORY_NONCACHED_RX] = {
3782+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
3783+ L_PTE_MT_BUFFERABLE,
3784+ .prot_l1 = PMD_TYPE_TABLE,
3785+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
3786+ .domain = DOMAIN_KERNEL,
3787+ },
3788 [MT_MEMORY_DTCM] = {
3789- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3790- L_PTE_XN,
3791+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
3792 .prot_l1 = PMD_TYPE_TABLE,
3793- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3794+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
3795 .domain = DOMAIN_KERNEL,
3796 },
3797 [MT_MEMORY_ITCM] = {
3798@@ -283,10 +326,10 @@ static struct mem_type mem_types[] = {
3799 },
3800 [MT_MEMORY_SO] = {
3801 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3802- L_PTE_MT_UNCACHED | L_PTE_XN,
3803+ L_PTE_MT_UNCACHED,
3804 .prot_l1 = PMD_TYPE_TABLE,
3805 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
3806- PMD_SECT_UNCACHED | PMD_SECT_XN,
3807+ PMD_SECT_UNCACHED,
3808 .domain = DOMAIN_KERNEL,
3809 },
3810 [MT_MEMORY_DMA_READY] = {
3811@@ -371,9 +414,35 @@ static void __init build_mem_type_table(void)
3812 * to prevent speculative instruction fetches.
3813 */
3814 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
3815+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
3816 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
3817+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
3818 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
3819+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
3820 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
3821+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
3822+
3823+ /* Mark other regions on ARMv6+ as execute-never */
3824+
3825+#ifdef CONFIG_PAX_KERNEXEC
3826+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
3827+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
3828+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
3829+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
3830+#ifndef CONFIG_ARM_LPAE
3831+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
3832+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
3833+#endif
3834+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
3835+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
3836+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
3837+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
3838+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
3839+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
3840+#endif
3841+
3842+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
3843+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
3844 }
3845 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
3846 /*
3847@@ -432,6 +501,9 @@ static void __init build_mem_type_table(void)
3848 * from SVC mode and no access from userspace.
3849 */
3850 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
3851+#ifdef CONFIG_PAX_KERNEXEC
3852+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
3853+#endif
3854 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
3855 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
3856 #endif
3857@@ -448,11 +520,17 @@ static void __init build_mem_type_table(void)
3858 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
3859 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
3860 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
3861- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
3862- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
3863+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
3864+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
3865+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
3866+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
3867+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
3868+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
3869 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
3870- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
3871- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
3872+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
3873+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
3874+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
3875+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
3876 }
3877 }
3878
3879@@ -463,15 +541,20 @@ static void __init build_mem_type_table(void)
3880 if (cpu_arch >= CPU_ARCH_ARMv6) {
3881 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
3882 /* Non-cacheable Normal is XCB = 001 */
3883- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
3884+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
3885+ PMD_SECT_BUFFERED;
3886+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
3887 PMD_SECT_BUFFERED;
3888 } else {
3889 /* For both ARMv6 and non-TEX-remapping ARMv7 */
3890- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
3891+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
3892+ PMD_SECT_TEX(1);
3893+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
3894 PMD_SECT_TEX(1);
3895 }
3896 } else {
3897- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
3898+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
3899+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
3900 }
3901
3902 #ifdef CONFIG_ARM_LPAE
3903@@ -487,6 +570,8 @@ static void __init build_mem_type_table(void)
3904 vecs_pgprot |= PTE_EXT_AF;
3905 #endif
3906
3907+ user_pgprot |= __supported_pte_mask;
3908+
3909 for (i = 0; i < 16; i++) {
3910 pteval_t v = pgprot_val(protection_map[i]);
3911 protection_map[i] = __pgprot(v | user_pgprot);
3912@@ -501,10 +586,15 @@ static void __init build_mem_type_table(void)
3913
3914 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
3915 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
3916- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
3917- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
3918+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
3919+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
3920+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
3921+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
3922+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
3923+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
3924 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
3925- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
3926+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
3927+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
3928 mem_types[MT_ROM].prot_sect |= cp->pmd;
3929
3930 switch (cp->pmd) {
3931@@ -1105,18 +1195,15 @@ void __init arm_mm_memblock_reserve(void)
3932 * called function. This means you can't use any function or debugging
3933 * method which may touch any device, otherwise the kernel _will_ crash.
3934 */
3935+
3936+static char vectors[PAGE_SIZE] __read_only __aligned(PAGE_SIZE);
3937+
3938 static void __init devicemaps_init(struct machine_desc *mdesc)
3939 {
3940 struct map_desc map;
3941 unsigned long addr;
3942- void *vectors;
3943
3944- /*
3945- * Allocate the vector page early.
3946- */
3947- vectors = early_alloc(PAGE_SIZE);
3948-
3949- early_trap_init(vectors);
3950+ early_trap_init(&vectors);
3951
3952 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
3953 pmd_clear(pmd_off_k(addr));
3954@@ -1156,7 +1243,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
3955 * location (0xffff0000). If we aren't using high-vectors, also
3956 * create a mapping at the low-vectors virtual address.
3957 */
3958- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
3959+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
3960 map.virtual = 0xffff0000;
3961 map.length = PAGE_SIZE;
3962 map.type = MT_HIGH_VECTORS;
3963@@ -1214,8 +1301,39 @@ static void __init map_lowmem(void)
3964 map.pfn = __phys_to_pfn(start);
3965 map.virtual = __phys_to_virt(start);
3966 map.length = end - start;
3967- map.type = MT_MEMORY;
3968
3969+#ifdef CONFIG_PAX_KERNEXEC
3970+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
3971+ struct map_desc kernel;
3972+ struct map_desc initmap;
3973+
3974+ /* when freeing initmem we will make this RW */
3975+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
3976+ initmap.virtual = (unsigned long)__init_begin;
3977+ initmap.length = _sdata - __init_begin;
3978+ initmap.type = MT_MEMORY_RWX;
3979+ create_mapping(&initmap);
3980+
3981+ /* when freeing initmem we will make this RX */
3982+ kernel.pfn = __phys_to_pfn(__pa(_stext));
3983+ kernel.virtual = (unsigned long)_stext;
3984+ kernel.length = __init_begin - _stext;
3985+ kernel.type = MT_MEMORY_RWX;
3986+ create_mapping(&kernel);
3987+
3988+ if (map.virtual < (unsigned long)_stext) {
3989+ map.length = (unsigned long)_stext - map.virtual;
3990+ map.type = MT_MEMORY_RWX;
3991+ create_mapping(&map);
3992+ }
3993+
3994+ map.pfn = __phys_to_pfn(__pa(_sdata));
3995+ map.virtual = (unsigned long)_sdata;
3996+ map.length = end - __pa(_sdata);
3997+ }
3998+#endif
3999+
4000+ map.type = MT_MEMORY_RW;
4001 create_mapping(&map);
4002 }
4003 }
4004diff --git a/arch/arm/mm/proc-v7-2level.S b/arch/arm/mm/proc-v7-2level.S
4005index 6d98c13..3cfb174 100644
4006--- a/arch/arm/mm/proc-v7-2level.S
4007+++ b/arch/arm/mm/proc-v7-2level.S
4008@@ -99,6 +99,9 @@ ENTRY(cpu_v7_set_pte_ext)
4009 tst r1, #L_PTE_XN
4010 orrne r3, r3, #PTE_EXT_XN
4011
4012+ tst r1, #L_PTE_PXN
4013+ orrne r3, r3, #PTE_EXT_PXN
4014+
4015 tst r1, #L_PTE_YOUNG
4016 tstne r1, #L_PTE_VALID
4017 #ifndef CONFIG_CPU_USE_DOMAINS
4018diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4019index a5bc92d..0bb4730 100644
4020--- a/arch/arm/plat-omap/sram.c
4021+++ b/arch/arm/plat-omap/sram.c
4022@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4023 * Looks like we need to preserve some bootloader code at the
4024 * beginning of SRAM for jumping to flash for reboot to work...
4025 */
4026+ pax_open_kernel();
4027 memset_io(omap_sram_base + omap_sram_skip, 0,
4028 omap_sram_size - omap_sram_skip);
4029+ pax_close_kernel();
4030 }
4031diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
4032index b76c065..b6e766b 100644
4033--- a/arch/arm/plat-orion/include/plat/addr-map.h
4034+++ b/arch/arm/plat-orion/include/plat/addr-map.h
4035@@ -27,7 +27,7 @@ struct orion_addr_map_cfg {
4036 value in bridge_virt_base */
4037 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
4038 const int win);
4039-};
4040+} __no_const;
4041
4042 /*
4043 * Information needed to setup one address mapping.
4044diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4045index f5144cd..71f6d1f 100644
4046--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4047+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4048@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4049 int (*started)(unsigned ch);
4050 int (*flush)(unsigned ch);
4051 int (*stop)(unsigned ch);
4052-};
4053+} __no_const;
4054
4055 extern void *samsung_dmadev_get_ops(void);
4056 extern void *s3c_dma_get_ops(void);
4057diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
4058index 0c3ba9f..95722b3 100644
4059--- a/arch/arm64/kernel/debug-monitors.c
4060+++ b/arch/arm64/kernel/debug-monitors.c
4061@@ -151,7 +151,7 @@ static int __cpuinit os_lock_notify(struct notifier_block *self,
4062 return NOTIFY_OK;
4063 }
4064
4065-static struct notifier_block __cpuinitdata os_lock_nb = {
4066+static struct notifier_block os_lock_nb = {
4067 .notifier_call = os_lock_notify,
4068 };
4069
4070diff --git a/arch/arm64/kernel/hw_breakpoint.c b/arch/arm64/kernel/hw_breakpoint.c
4071index 5ab825c..96aaec8 100644
4072--- a/arch/arm64/kernel/hw_breakpoint.c
4073+++ b/arch/arm64/kernel/hw_breakpoint.c
4074@@ -831,7 +831,7 @@ static int __cpuinit hw_breakpoint_reset_notify(struct notifier_block *self,
4075 return NOTIFY_OK;
4076 }
4077
4078-static struct notifier_block __cpuinitdata hw_breakpoint_reset_nb = {
4079+static struct notifier_block hw_breakpoint_reset_nb = {
4080 .notifier_call = hw_breakpoint_reset_notify,
4081 };
4082
4083diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4084index c3a58a1..78fbf54 100644
4085--- a/arch/avr32/include/asm/cache.h
4086+++ b/arch/avr32/include/asm/cache.h
4087@@ -1,8 +1,10 @@
4088 #ifndef __ASM_AVR32_CACHE_H
4089 #define __ASM_AVR32_CACHE_H
4090
4091+#include <linux/const.h>
4092+
4093 #define L1_CACHE_SHIFT 5
4094-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4095+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4096
4097 /*
4098 * Memory returned by kmalloc() may be used for DMA, so we must make
4099diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4100index e2c3287..6c4f98c 100644
4101--- a/arch/avr32/include/asm/elf.h
4102+++ b/arch/avr32/include/asm/elf.h
4103@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4104 the loader. We need to make sure that it is out of the way of the program
4105 that it will "exec", and that there is sufficient room for the brk. */
4106
4107-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4108+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4109
4110+#ifdef CONFIG_PAX_ASLR
4111+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4112+
4113+#define PAX_DELTA_MMAP_LEN 15
4114+#define PAX_DELTA_STACK_LEN 15
4115+#endif
4116
4117 /* This yields a mask that user programs can use to figure out what
4118 instruction set this CPU supports. This could be done in user space,
4119diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4120index 479330b..53717a8 100644
4121--- a/arch/avr32/include/asm/kmap_types.h
4122+++ b/arch/avr32/include/asm/kmap_types.h
4123@@ -2,9 +2,9 @@
4124 #define __ASM_AVR32_KMAP_TYPES_H
4125
4126 #ifdef CONFIG_DEBUG_HIGHMEM
4127-# define KM_TYPE_NR 29
4128+# define KM_TYPE_NR 30
4129 #else
4130-# define KM_TYPE_NR 14
4131+# define KM_TYPE_NR 15
4132 #endif
4133
4134 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4135diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4136index b2f2d2d..d1c85cb 100644
4137--- a/arch/avr32/mm/fault.c
4138+++ b/arch/avr32/mm/fault.c
4139@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4140
4141 int exception_trace = 1;
4142
4143+#ifdef CONFIG_PAX_PAGEEXEC
4144+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4145+{
4146+ unsigned long i;
4147+
4148+ printk(KERN_ERR "PAX: bytes at PC: ");
4149+ for (i = 0; i < 20; i++) {
4150+ unsigned char c;
4151+ if (get_user(c, (unsigned char *)pc+i))
4152+ printk(KERN_CONT "???????? ");
4153+ else
4154+ printk(KERN_CONT "%02x ", c);
4155+ }
4156+ printk("\n");
4157+}
4158+#endif
4159+
4160 /*
4161 * This routine handles page faults. It determines the address and the
4162 * problem, and then passes it off to one of the appropriate routines.
4163@@ -174,6 +191,16 @@ bad_area:
4164 up_read(&mm->mmap_sem);
4165
4166 if (user_mode(regs)) {
4167+
4168+#ifdef CONFIG_PAX_PAGEEXEC
4169+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4170+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4171+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4172+ do_group_exit(SIGKILL);
4173+ }
4174+ }
4175+#endif
4176+
4177 if (exception_trace && printk_ratelimit())
4178 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4179 "sp %08lx ecr %lu\n",
4180diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4181index 568885a..f8008df 100644
4182--- a/arch/blackfin/include/asm/cache.h
4183+++ b/arch/blackfin/include/asm/cache.h
4184@@ -7,6 +7,7 @@
4185 #ifndef __ARCH_BLACKFIN_CACHE_H
4186 #define __ARCH_BLACKFIN_CACHE_H
4187
4188+#include <linux/const.h>
4189 #include <linux/linkage.h> /* for asmlinkage */
4190
4191 /*
4192@@ -14,7 +15,7 @@
4193 * Blackfin loads 32 bytes for cache
4194 */
4195 #define L1_CACHE_SHIFT 5
4196-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4197+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4198 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4199
4200 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4201diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4202index aea2718..3639a60 100644
4203--- a/arch/cris/include/arch-v10/arch/cache.h
4204+++ b/arch/cris/include/arch-v10/arch/cache.h
4205@@ -1,8 +1,9 @@
4206 #ifndef _ASM_ARCH_CACHE_H
4207 #define _ASM_ARCH_CACHE_H
4208
4209+#include <linux/const.h>
4210 /* Etrax 100LX have 32-byte cache-lines. */
4211-#define L1_CACHE_BYTES 32
4212 #define L1_CACHE_SHIFT 5
4213+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4214
4215 #endif /* _ASM_ARCH_CACHE_H */
4216diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4217index 7caf25d..ee65ac5 100644
4218--- a/arch/cris/include/arch-v32/arch/cache.h
4219+++ b/arch/cris/include/arch-v32/arch/cache.h
4220@@ -1,11 +1,12 @@
4221 #ifndef _ASM_CRIS_ARCH_CACHE_H
4222 #define _ASM_CRIS_ARCH_CACHE_H
4223
4224+#include <linux/const.h>
4225 #include <arch/hwregs/dma.h>
4226
4227 /* A cache-line is 32 bytes. */
4228-#define L1_CACHE_BYTES 32
4229 #define L1_CACHE_SHIFT 5
4230+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4231
4232 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4233
4234diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4235index b86329d..6709906 100644
4236--- a/arch/frv/include/asm/atomic.h
4237+++ b/arch/frv/include/asm/atomic.h
4238@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4239 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4240 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4241
4242+#define atomic64_read_unchecked(v) atomic64_read(v)
4243+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4244+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4245+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4246+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4247+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4248+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4249+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4250+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4251+
4252 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4253 {
4254 int c, old;
4255diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4256index 2797163..c2a401d 100644
4257--- a/arch/frv/include/asm/cache.h
4258+++ b/arch/frv/include/asm/cache.h
4259@@ -12,10 +12,11 @@
4260 #ifndef __ASM_CACHE_H
4261 #define __ASM_CACHE_H
4262
4263+#include <linux/const.h>
4264
4265 /* bytes per L1 cache line */
4266 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4267-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4268+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4269
4270 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4271 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4272diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4273index 43901f2..0d8b865 100644
4274--- a/arch/frv/include/asm/kmap_types.h
4275+++ b/arch/frv/include/asm/kmap_types.h
4276@@ -2,6 +2,6 @@
4277 #ifndef _ASM_KMAP_TYPES_H
4278 #define _ASM_KMAP_TYPES_H
4279
4280-#define KM_TYPE_NR 17
4281+#define KM_TYPE_NR 18
4282
4283 #endif
4284diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4285index 385fd30..3aaf4fe 100644
4286--- a/arch/frv/mm/elf-fdpic.c
4287+++ b/arch/frv/mm/elf-fdpic.c
4288@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4289 {
4290 struct vm_area_struct *vma;
4291 unsigned long limit;
4292+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4293
4294 if (len > TASK_SIZE)
4295 return -ENOMEM;
4296@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4297 if (addr) {
4298 addr = PAGE_ALIGN(addr);
4299 vma = find_vma(current->mm, addr);
4300- if (TASK_SIZE - len >= addr &&
4301- (!vma || addr + len <= vma->vm_start))
4302+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4303 goto success;
4304 }
4305
4306@@ -89,7 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4307 for (; vma; vma = vma->vm_next) {
4308 if (addr > limit)
4309 break;
4310- if (addr + len <= vma->vm_start)
4311+ if (check_heap_stack_gap(vma, addr, len, offset))
4312 goto success;
4313 addr = vma->vm_end;
4314 }
4315@@ -104,7 +104,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4316 for (; vma; vma = vma->vm_next) {
4317 if (addr > limit)
4318 break;
4319- if (addr + len <= vma->vm_start)
4320+ if (check_heap_stack_gap(vma, addr, len, offset))
4321 goto success;
4322 addr = vma->vm_end;
4323 }
4324diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4325index f4ca594..adc72fd6 100644
4326--- a/arch/hexagon/include/asm/cache.h
4327+++ b/arch/hexagon/include/asm/cache.h
4328@@ -21,9 +21,11 @@
4329 #ifndef __ASM_CACHE_H
4330 #define __ASM_CACHE_H
4331
4332+#include <linux/const.h>
4333+
4334 /* Bytes per L1 cache line */
4335-#define L1_CACHE_SHIFT (5)
4336-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4337+#define L1_CACHE_SHIFT 5
4338+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4339
4340 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4341 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4342diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4343index 6e6fe18..a6ae668 100644
4344--- a/arch/ia64/include/asm/atomic.h
4345+++ b/arch/ia64/include/asm/atomic.h
4346@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4347 #define atomic64_inc(v) atomic64_add(1, (v))
4348 #define atomic64_dec(v) atomic64_sub(1, (v))
4349
4350+#define atomic64_read_unchecked(v) atomic64_read(v)
4351+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4352+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4353+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4354+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4355+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4356+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4357+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4358+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4359+
4360 /* Atomic operations are already serializing */
4361 #define smp_mb__before_atomic_dec() barrier()
4362 #define smp_mb__after_atomic_dec() barrier()
4363diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4364index 988254a..e1ee885 100644
4365--- a/arch/ia64/include/asm/cache.h
4366+++ b/arch/ia64/include/asm/cache.h
4367@@ -1,6 +1,7 @@
4368 #ifndef _ASM_IA64_CACHE_H
4369 #define _ASM_IA64_CACHE_H
4370
4371+#include <linux/const.h>
4372
4373 /*
4374 * Copyright (C) 1998-2000 Hewlett-Packard Co
4375@@ -9,7 +10,7 @@
4376
4377 /* Bytes per L1 (data) cache line. */
4378 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4379-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4380+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4381
4382 #ifdef CONFIG_SMP
4383 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4384diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4385index b5298eb..67c6e62 100644
4386--- a/arch/ia64/include/asm/elf.h
4387+++ b/arch/ia64/include/asm/elf.h
4388@@ -42,6 +42,13 @@
4389 */
4390 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4391
4392+#ifdef CONFIG_PAX_ASLR
4393+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4394+
4395+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4396+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4397+#endif
4398+
4399 #define PT_IA_64_UNWIND 0x70000001
4400
4401 /* IA-64 relocations: */
4402diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4403index 96a8d92..617a1cf 100644
4404--- a/arch/ia64/include/asm/pgalloc.h
4405+++ b/arch/ia64/include/asm/pgalloc.h
4406@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4407 pgd_val(*pgd_entry) = __pa(pud);
4408 }
4409
4410+static inline void
4411+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4412+{
4413+ pgd_populate(mm, pgd_entry, pud);
4414+}
4415+
4416 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4417 {
4418 return quicklist_alloc(0, GFP_KERNEL, NULL);
4419@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4420 pud_val(*pud_entry) = __pa(pmd);
4421 }
4422
4423+static inline void
4424+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4425+{
4426+ pud_populate(mm, pud_entry, pmd);
4427+}
4428+
4429 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4430 {
4431 return quicklist_alloc(0, GFP_KERNEL, NULL);
4432diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4433index 815810c..d60bd4c 100644
4434--- a/arch/ia64/include/asm/pgtable.h
4435+++ b/arch/ia64/include/asm/pgtable.h
4436@@ -12,7 +12,7 @@
4437 * David Mosberger-Tang <davidm@hpl.hp.com>
4438 */
4439
4440-
4441+#include <linux/const.h>
4442 #include <asm/mman.h>
4443 #include <asm/page.h>
4444 #include <asm/processor.h>
4445@@ -142,6 +142,17 @@
4446 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4447 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4448 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4449+
4450+#ifdef CONFIG_PAX_PAGEEXEC
4451+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4452+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4453+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4454+#else
4455+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4456+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4457+# define PAGE_COPY_NOEXEC PAGE_COPY
4458+#endif
4459+
4460 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4461 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4462 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4463diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4464index 54ff557..70c88b7 100644
4465--- a/arch/ia64/include/asm/spinlock.h
4466+++ b/arch/ia64/include/asm/spinlock.h
4467@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4468 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4469
4470 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4471- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4472+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4473 }
4474
4475 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4476diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4477index 449c8c0..50cdf87 100644
4478--- a/arch/ia64/include/asm/uaccess.h
4479+++ b/arch/ia64/include/asm/uaccess.h
4480@@ -42,6 +42,8 @@
4481 #include <asm/pgtable.h>
4482 #include <asm/io.h>
4483
4484+extern void check_object_size(const void *ptr, unsigned long n, bool to);
4485+
4486 /*
4487 * For historical reasons, the following macros are grossly misnamed:
4488 */
4489@@ -240,12 +242,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4490 static inline unsigned long
4491 __copy_to_user (void __user *to, const void *from, unsigned long count)
4492 {
4493+ if (count > INT_MAX)
4494+ return count;
4495+
4496+ if (!__builtin_constant_p(count))
4497+ check_object_size(from, count, true);
4498+
4499 return __copy_user(to, (__force void __user *) from, count);
4500 }
4501
4502 static inline unsigned long
4503 __copy_from_user (void *to, const void __user *from, unsigned long count)
4504 {
4505+ if (count > INT_MAX)
4506+ return count;
4507+
4508+ if (!__builtin_constant_p(count))
4509+ check_object_size(to, count, false);
4510+
4511 return __copy_user((__force void __user *) to, from, count);
4512 }
4513
4514@@ -255,10 +269,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4515 ({ \
4516 void __user *__cu_to = (to); \
4517 const void *__cu_from = (from); \
4518- long __cu_len = (n); \
4519+ unsigned long __cu_len = (n); \
4520 \
4521- if (__access_ok(__cu_to, __cu_len, get_fs())) \
4522+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
4523+ if (!__builtin_constant_p(n)) \
4524+ check_object_size(__cu_from, __cu_len, true); \
4525 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
4526+ } \
4527 __cu_len; \
4528 })
4529
4530@@ -266,11 +283,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4531 ({ \
4532 void *__cu_to = (to); \
4533 const void __user *__cu_from = (from); \
4534- long __cu_len = (n); \
4535+ unsigned long __cu_len = (n); \
4536 \
4537 __chk_user_ptr(__cu_from); \
4538- if (__access_ok(__cu_from, __cu_len, get_fs())) \
4539+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
4540+ if (!__builtin_constant_p(n)) \
4541+ check_object_size(__cu_to, __cu_len, false); \
4542 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
4543+ } \
4544 __cu_len; \
4545 })
4546
4547diff --git a/arch/ia64/kernel/err_inject.c b/arch/ia64/kernel/err_inject.c
4548index 2d67317..07d8bfa 100644
4549--- a/arch/ia64/kernel/err_inject.c
4550+++ b/arch/ia64/kernel/err_inject.c
4551@@ -256,7 +256,7 @@ static int __cpuinit err_inject_cpu_callback(struct notifier_block *nfb,
4552 return NOTIFY_OK;
4553 }
4554
4555-static struct notifier_block __cpuinitdata err_inject_cpu_notifier =
4556+static struct notifier_block err_inject_cpu_notifier =
4557 {
4558 .notifier_call = err_inject_cpu_callback,
4559 };
4560diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
4561index 65bf9cd..794f06b 100644
4562--- a/arch/ia64/kernel/mca.c
4563+++ b/arch/ia64/kernel/mca.c
4564@@ -1922,7 +1922,7 @@ static int __cpuinit mca_cpu_callback(struct notifier_block *nfb,
4565 return NOTIFY_OK;
4566 }
4567
4568-static struct notifier_block mca_cpu_notifier __cpuinitdata = {
4569+static struct notifier_block mca_cpu_notifier = {
4570 .notifier_call = mca_cpu_callback
4571 };
4572
4573diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
4574index 24603be..948052d 100644
4575--- a/arch/ia64/kernel/module.c
4576+++ b/arch/ia64/kernel/module.c
4577@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
4578 void
4579 module_free (struct module *mod, void *module_region)
4580 {
4581- if (mod && mod->arch.init_unw_table &&
4582- module_region == mod->module_init) {
4583+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
4584 unw_remove_unwind_table(mod->arch.init_unw_table);
4585 mod->arch.init_unw_table = NULL;
4586 }
4587@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
4588 }
4589
4590 static inline int
4591+in_init_rx (const struct module *mod, uint64_t addr)
4592+{
4593+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
4594+}
4595+
4596+static inline int
4597+in_init_rw (const struct module *mod, uint64_t addr)
4598+{
4599+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
4600+}
4601+
4602+static inline int
4603 in_init (const struct module *mod, uint64_t addr)
4604 {
4605- return addr - (uint64_t) mod->module_init < mod->init_size;
4606+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
4607+}
4608+
4609+static inline int
4610+in_core_rx (const struct module *mod, uint64_t addr)
4611+{
4612+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
4613+}
4614+
4615+static inline int
4616+in_core_rw (const struct module *mod, uint64_t addr)
4617+{
4618+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
4619 }
4620
4621 static inline int
4622 in_core (const struct module *mod, uint64_t addr)
4623 {
4624- return addr - (uint64_t) mod->module_core < mod->core_size;
4625+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
4626 }
4627
4628 static inline int
4629@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
4630 break;
4631
4632 case RV_BDREL:
4633- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
4634+ if (in_init_rx(mod, val))
4635+ val -= (uint64_t) mod->module_init_rx;
4636+ else if (in_init_rw(mod, val))
4637+ val -= (uint64_t) mod->module_init_rw;
4638+ else if (in_core_rx(mod, val))
4639+ val -= (uint64_t) mod->module_core_rx;
4640+ else if (in_core_rw(mod, val))
4641+ val -= (uint64_t) mod->module_core_rw;
4642 break;
4643
4644 case RV_LTV:
4645@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
4646 * addresses have been selected...
4647 */
4648 uint64_t gp;
4649- if (mod->core_size > MAX_LTOFF)
4650+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
4651 /*
4652 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
4653 * at the end of the module.
4654 */
4655- gp = mod->core_size - MAX_LTOFF / 2;
4656+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
4657 else
4658- gp = mod->core_size / 2;
4659- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
4660+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
4661+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
4662 mod->arch.gp = gp;
4663 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
4664 }
4665diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
4666index 77597e5..6f28f3f 100644
4667--- a/arch/ia64/kernel/palinfo.c
4668+++ b/arch/ia64/kernel/palinfo.c
4669@@ -1045,7 +1045,7 @@ static int __cpuinit palinfo_cpu_callback(struct notifier_block *nfb,
4670 return NOTIFY_OK;
4671 }
4672
4673-static struct notifier_block __refdata palinfo_cpu_notifier =
4674+static struct notifier_block palinfo_cpu_notifier =
4675 {
4676 .notifier_call = palinfo_cpu_callback,
4677 .priority = 0,
4678diff --git a/arch/ia64/kernel/salinfo.c b/arch/ia64/kernel/salinfo.c
4679index 79802e5..1a89ec5 100644
4680--- a/arch/ia64/kernel/salinfo.c
4681+++ b/arch/ia64/kernel/salinfo.c
4682@@ -616,7 +616,7 @@ salinfo_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu
4683 return NOTIFY_OK;
4684 }
4685
4686-static struct notifier_block salinfo_cpu_notifier __cpuinitdata =
4687+static struct notifier_block salinfo_cpu_notifier =
4688 {
4689 .notifier_call = salinfo_cpu_callback,
4690 .priority = 0,
4691diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
4692index d9439ef..d0cac6b 100644
4693--- a/arch/ia64/kernel/sys_ia64.c
4694+++ b/arch/ia64/kernel/sys_ia64.c
4695@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4696 unsigned long start_addr, align_mask = PAGE_SIZE - 1;
4697 struct mm_struct *mm = current->mm;
4698 struct vm_area_struct *vma;
4699+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4700
4701 if (len > RGN_MAP_LIMIT)
4702 return -ENOMEM;
4703@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4704 if (REGION_NUMBER(addr) == RGN_HPAGE)
4705 addr = 0;
4706 #endif
4707+
4708+#ifdef CONFIG_PAX_RANDMMAP
4709+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4710+ addr = mm->free_area_cache;
4711+ else
4712+#endif
4713+
4714 if (!addr)
4715 addr = mm->free_area_cache;
4716
4717@@ -61,14 +69,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4718 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
4719 /* At this point: (!vma || addr < vma->vm_end). */
4720 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
4721- if (start_addr != TASK_UNMAPPED_BASE) {
4722+ if (start_addr != mm->mmap_base) {
4723 /* Start a new search --- just in case we missed some holes. */
4724- addr = TASK_UNMAPPED_BASE;
4725+ addr = mm->mmap_base;
4726 goto full_search;
4727 }
4728 return -ENOMEM;
4729 }
4730- if (!vma || addr + len <= vma->vm_start) {
4731+ if (check_heap_stack_gap(vma, addr, len, offset)) {
4732 /* Remember the address where we stopped this search: */
4733 mm->free_area_cache = addr + len;
4734 return addr;
4735diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
4736index dc00b2c..cce53c2 100644
4737--- a/arch/ia64/kernel/topology.c
4738+++ b/arch/ia64/kernel/topology.c
4739@@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
4740 return NOTIFY_OK;
4741 }
4742
4743-static struct notifier_block __cpuinitdata cache_cpu_notifier =
4744+static struct notifier_block cache_cpu_notifier =
4745 {
4746 .notifier_call = cache_cpu_callback
4747 };
4748diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
4749index 0ccb28f..8992469 100644
4750--- a/arch/ia64/kernel/vmlinux.lds.S
4751+++ b/arch/ia64/kernel/vmlinux.lds.S
4752@@ -198,7 +198,7 @@ SECTIONS {
4753 /* Per-cpu data: */
4754 . = ALIGN(PERCPU_PAGE_SIZE);
4755 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
4756- __phys_per_cpu_start = __per_cpu_load;
4757+ __phys_per_cpu_start = per_cpu_load;
4758 /*
4759 * ensure percpu data fits
4760 * into percpu page size
4761diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
4762index 6cf0341..d352594 100644
4763--- a/arch/ia64/mm/fault.c
4764+++ b/arch/ia64/mm/fault.c
4765@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
4766 return pte_present(pte);
4767 }
4768
4769+#ifdef CONFIG_PAX_PAGEEXEC
4770+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4771+{
4772+ unsigned long i;
4773+
4774+ printk(KERN_ERR "PAX: bytes at PC: ");
4775+ for (i = 0; i < 8; i++) {
4776+ unsigned int c;
4777+ if (get_user(c, (unsigned int *)pc+i))
4778+ printk(KERN_CONT "???????? ");
4779+ else
4780+ printk(KERN_CONT "%08x ", c);
4781+ }
4782+ printk("\n");
4783+}
4784+#endif
4785+
4786 # define VM_READ_BIT 0
4787 # define VM_WRITE_BIT 1
4788 # define VM_EXEC_BIT 2
4789@@ -149,8 +166,21 @@ retry:
4790 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
4791 goto bad_area;
4792
4793- if ((vma->vm_flags & mask) != mask)
4794+ if ((vma->vm_flags & mask) != mask) {
4795+
4796+#ifdef CONFIG_PAX_PAGEEXEC
4797+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
4798+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
4799+ goto bad_area;
4800+
4801+ up_read(&mm->mmap_sem);
4802+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
4803+ do_group_exit(SIGKILL);
4804+ }
4805+#endif
4806+
4807 goto bad_area;
4808+ }
4809
4810 /*
4811 * If for any reason at all we couldn't handle the fault, make
4812diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
4813index 5ca674b..127c3cb 100644
4814--- a/arch/ia64/mm/hugetlbpage.c
4815+++ b/arch/ia64/mm/hugetlbpage.c
4816@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
4817 unsigned long pgoff, unsigned long flags)
4818 {
4819 struct vm_area_struct *vmm;
4820+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
4821
4822 if (len > RGN_MAP_LIMIT)
4823 return -ENOMEM;
4824@@ -171,7 +172,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
4825 /* At this point: (!vmm || addr < vmm->vm_end). */
4826 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
4827 return -ENOMEM;
4828- if (!vmm || (addr + len) <= vmm->vm_start)
4829+ if (check_heap_stack_gap(vmm, addr, len, offset))
4830 return addr;
4831 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
4832 }
4833diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
4834index b755ea9..b9a969e 100644
4835--- a/arch/ia64/mm/init.c
4836+++ b/arch/ia64/mm/init.c
4837@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
4838 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
4839 vma->vm_end = vma->vm_start + PAGE_SIZE;
4840 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
4841+
4842+#ifdef CONFIG_PAX_PAGEEXEC
4843+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
4844+ vma->vm_flags &= ~VM_EXEC;
4845+
4846+#ifdef CONFIG_PAX_MPROTECT
4847+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
4848+ vma->vm_flags &= ~VM_MAYEXEC;
4849+#endif
4850+
4851+ }
4852+#endif
4853+
4854 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
4855 down_write(&current->mm->mmap_sem);
4856 if (insert_vm_struct(current->mm, vma)) {
4857diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
4858index 40b3ee9..8c2c112 100644
4859--- a/arch/m32r/include/asm/cache.h
4860+++ b/arch/m32r/include/asm/cache.h
4861@@ -1,8 +1,10 @@
4862 #ifndef _ASM_M32R_CACHE_H
4863 #define _ASM_M32R_CACHE_H
4864
4865+#include <linux/const.h>
4866+
4867 /* L1 cache line size */
4868 #define L1_CACHE_SHIFT 4
4869-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4870+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4871
4872 #endif /* _ASM_M32R_CACHE_H */
4873diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
4874index 82abd15..d95ae5d 100644
4875--- a/arch/m32r/lib/usercopy.c
4876+++ b/arch/m32r/lib/usercopy.c
4877@@ -14,6 +14,9 @@
4878 unsigned long
4879 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
4880 {
4881+ if ((long)n < 0)
4882+ return n;
4883+
4884 prefetch(from);
4885 if (access_ok(VERIFY_WRITE, to, n))
4886 __copy_user(to,from,n);
4887@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
4888 unsigned long
4889 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
4890 {
4891+ if ((long)n < 0)
4892+ return n;
4893+
4894 prefetchw(to);
4895 if (access_ok(VERIFY_READ, from, n))
4896 __copy_user_zeroing(to,from,n);
4897diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
4898index 0395c51..5f26031 100644
4899--- a/arch/m68k/include/asm/cache.h
4900+++ b/arch/m68k/include/asm/cache.h
4901@@ -4,9 +4,11 @@
4902 #ifndef __ARCH_M68K_CACHE_H
4903 #define __ARCH_M68K_CACHE_H
4904
4905+#include <linux/const.h>
4906+
4907 /* bytes per L1 cache line */
4908 #define L1_CACHE_SHIFT 4
4909-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
4910+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4911
4912 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4913
4914diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
4915index 4efe96a..60e8699 100644
4916--- a/arch/microblaze/include/asm/cache.h
4917+++ b/arch/microblaze/include/asm/cache.h
4918@@ -13,11 +13,12 @@
4919 #ifndef _ASM_MICROBLAZE_CACHE_H
4920 #define _ASM_MICROBLAZE_CACHE_H
4921
4922+#include <linux/const.h>
4923 #include <asm/registers.h>
4924
4925 #define L1_CACHE_SHIFT 5
4926 /* word-granular cache in microblaze */
4927-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4928+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4929
4930 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4931
4932diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
4933index 01cc6ba..bcb7a5d 100644
4934--- a/arch/mips/include/asm/atomic.h
4935+++ b/arch/mips/include/asm/atomic.h
4936@@ -21,6 +21,10 @@
4937 #include <asm/cmpxchg.h>
4938 #include <asm/war.h>
4939
4940+#ifdef CONFIG_GENERIC_ATOMIC64
4941+#include <asm-generic/atomic64.h>
4942+#endif
4943+
4944 #define ATOMIC_INIT(i) { (i) }
4945
4946 /*
4947@@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
4948 */
4949 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
4950
4951+#define atomic64_read_unchecked(v) atomic64_read(v)
4952+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4953+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4954+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4955+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4956+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4957+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4958+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4959+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4960+
4961 #endif /* CONFIG_64BIT */
4962
4963 /*
4964diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
4965index b4db69f..8f3b093 100644
4966--- a/arch/mips/include/asm/cache.h
4967+++ b/arch/mips/include/asm/cache.h
4968@@ -9,10 +9,11 @@
4969 #ifndef _ASM_CACHE_H
4970 #define _ASM_CACHE_H
4971
4972+#include <linux/const.h>
4973 #include <kmalloc.h>
4974
4975 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
4976-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4977+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4978
4979 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4980 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4981diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
4982index 455c0ac..ad65fbe 100644
4983--- a/arch/mips/include/asm/elf.h
4984+++ b/arch/mips/include/asm/elf.h
4985@@ -372,13 +372,16 @@ extern const char *__elf_platform;
4986 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4987 #endif
4988
4989+#ifdef CONFIG_PAX_ASLR
4990+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
4991+
4992+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
4993+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
4994+#endif
4995+
4996 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4997 struct linux_binprm;
4998 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
4999 int uses_interp);
5000
5001-struct mm_struct;
5002-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5003-#define arch_randomize_brk arch_randomize_brk
5004-
5005 #endif /* _ASM_ELF_H */
5006diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
5007index c1f6afa..38cc6e9 100644
5008--- a/arch/mips/include/asm/exec.h
5009+++ b/arch/mips/include/asm/exec.h
5010@@ -12,6 +12,6 @@
5011 #ifndef _ASM_EXEC_H
5012 #define _ASM_EXEC_H
5013
5014-extern unsigned long arch_align_stack(unsigned long sp);
5015+#define arch_align_stack(x) ((x) & ~0xfUL)
5016
5017 #endif /* _ASM_EXEC_H */
5018diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
5019index dbaec94..6a14935 100644
5020--- a/arch/mips/include/asm/page.h
5021+++ b/arch/mips/include/asm/page.h
5022@@ -96,7 +96,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
5023 #ifdef CONFIG_CPU_MIPS32
5024 typedef struct { unsigned long pte_low, pte_high; } pte_t;
5025 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
5026- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
5027+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
5028 #else
5029 typedef struct { unsigned long long pte; } pte_t;
5030 #define pte_val(x) ((x).pte)
5031diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
5032index 881d18b..cea38bc 100644
5033--- a/arch/mips/include/asm/pgalloc.h
5034+++ b/arch/mips/include/asm/pgalloc.h
5035@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5036 {
5037 set_pud(pud, __pud((unsigned long)pmd));
5038 }
5039+
5040+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5041+{
5042+ pud_populate(mm, pud, pmd);
5043+}
5044 #endif
5045
5046 /*
5047diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
5048index b2050b9..d71bb1b 100644
5049--- a/arch/mips/include/asm/thread_info.h
5050+++ b/arch/mips/include/asm/thread_info.h
5051@@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
5052 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
5053 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
5054 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
5055+/* li takes a 32bit immediate */
5056+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
5057 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
5058
5059 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
5060@@ -126,15 +128,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
5061 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
5062 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
5063 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
5064+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5065+
5066+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5067
5068 /* work to do in syscall_trace_leave() */
5069-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
5070+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5071
5072 /* work to do on interrupt/exception return */
5073 #define _TIF_WORK_MASK \
5074 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
5075 /* work to do on any return to u-space */
5076-#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
5077+#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
5078
5079 #endif /* __KERNEL__ */
5080
5081diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
5082index 9fdd8bc..4bd7f1a 100644
5083--- a/arch/mips/kernel/binfmt_elfn32.c
5084+++ b/arch/mips/kernel/binfmt_elfn32.c
5085@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5086 #undef ELF_ET_DYN_BASE
5087 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5088
5089+#ifdef CONFIG_PAX_ASLR
5090+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5091+
5092+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5093+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5094+#endif
5095+
5096 #include <asm/processor.h>
5097 #include <linux/module.h>
5098 #include <linux/elfcore.h>
5099diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
5100index ff44823..97f8906 100644
5101--- a/arch/mips/kernel/binfmt_elfo32.c
5102+++ b/arch/mips/kernel/binfmt_elfo32.c
5103@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5104 #undef ELF_ET_DYN_BASE
5105 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5106
5107+#ifdef CONFIG_PAX_ASLR
5108+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5109+
5110+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5111+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5112+#endif
5113+
5114 #include <asm/processor.h>
5115
5116 /*
5117diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
5118index a11c6f9..be5e164 100644
5119--- a/arch/mips/kernel/process.c
5120+++ b/arch/mips/kernel/process.c
5121@@ -460,15 +460,3 @@ unsigned long get_wchan(struct task_struct *task)
5122 out:
5123 return pc;
5124 }
5125-
5126-/*
5127- * Don't forget that the stack pointer must be aligned on a 8 bytes
5128- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
5129- */
5130-unsigned long arch_align_stack(unsigned long sp)
5131-{
5132- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5133- sp -= get_random_int() & ~PAGE_MASK;
5134-
5135- return sp & ALMASK;
5136-}
5137diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
5138index 4812c6d..2069554 100644
5139--- a/arch/mips/kernel/ptrace.c
5140+++ b/arch/mips/kernel/ptrace.c
5141@@ -528,6 +528,10 @@ static inline int audit_arch(void)
5142 return arch;
5143 }
5144
5145+#ifdef CONFIG_GRKERNSEC_SETXID
5146+extern void gr_delayed_cred_worker(void);
5147+#endif
5148+
5149 /*
5150 * Notification of system call entry/exit
5151 * - triggered by current->work.syscall_trace
5152@@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
5153 /* do the secure computing check first */
5154 secure_computing_strict(regs->regs[2]);
5155
5156+#ifdef CONFIG_GRKERNSEC_SETXID
5157+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5158+ gr_delayed_cred_worker();
5159+#endif
5160+
5161 if (!(current->ptrace & PT_PTRACED))
5162 goto out;
5163
5164diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
5165index d20a4bc..7096ae5 100644
5166--- a/arch/mips/kernel/scall32-o32.S
5167+++ b/arch/mips/kernel/scall32-o32.S
5168@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5169
5170 stack_done:
5171 lw t0, TI_FLAGS($28) # syscall tracing enabled?
5172- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5173+ li t1, _TIF_SYSCALL_WORK
5174 and t0, t1
5175 bnez t0, syscall_trace_entry # -> yes
5176
5177diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
5178index b64f642..0fe6eab 100644
5179--- a/arch/mips/kernel/scall64-64.S
5180+++ b/arch/mips/kernel/scall64-64.S
5181@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
5182
5183 sd a3, PT_R26(sp) # save a3 for syscall restarting
5184
5185- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5186+ li t1, _TIF_SYSCALL_WORK
5187 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5188 and t0, t1, t0
5189 bnez t0, syscall_trace_entry
5190diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
5191index c29ac19..c592d05 100644
5192--- a/arch/mips/kernel/scall64-n32.S
5193+++ b/arch/mips/kernel/scall64-n32.S
5194@@ -47,7 +47,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
5195
5196 sd a3, PT_R26(sp) # save a3 for syscall restarting
5197
5198- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5199+ li t1, _TIF_SYSCALL_WORK
5200 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5201 and t0, t1, t0
5202 bnez t0, n32_syscall_trace_entry
5203diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
5204index cf3e75e..72e93fe 100644
5205--- a/arch/mips/kernel/scall64-o32.S
5206+++ b/arch/mips/kernel/scall64-o32.S
5207@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5208 PTR 4b, bad_stack
5209 .previous
5210
5211- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5212+ li t1, _TIF_SYSCALL_WORK
5213 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5214 and t0, t1, t0
5215 bnez t0, trace_a_syscall
5216diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
5217index ddcec1e..c7f983e 100644
5218--- a/arch/mips/mm/fault.c
5219+++ b/arch/mips/mm/fault.c
5220@@ -27,6 +27,23 @@
5221 #include <asm/highmem.h> /* For VMALLOC_END */
5222 #include <linux/kdebug.h>
5223
5224+#ifdef CONFIG_PAX_PAGEEXEC
5225+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5226+{
5227+ unsigned long i;
5228+
5229+ printk(KERN_ERR "PAX: bytes at PC: ");
5230+ for (i = 0; i < 5; i++) {
5231+ unsigned int c;
5232+ if (get_user(c, (unsigned int *)pc+i))
5233+ printk(KERN_CONT "???????? ");
5234+ else
5235+ printk(KERN_CONT "%08x ", c);
5236+ }
5237+ printk("\n");
5238+}
5239+#endif
5240+
5241 /*
5242 * This routine handles page faults. It determines the address,
5243 * and the problem, and then passes it off to one of the appropriate
5244diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
5245index 7e5fe27..479a219 100644
5246--- a/arch/mips/mm/mmap.c
5247+++ b/arch/mips/mm/mmap.c
5248@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5249 struct vm_area_struct *vma;
5250 unsigned long addr = addr0;
5251 int do_color_align;
5252+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5253 struct vm_unmapped_area_info info;
5254
5255 if (unlikely(len > TASK_SIZE))
5256@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5257 do_color_align = 1;
5258
5259 /* requesting a specific address */
5260+
5261+#ifdef CONFIG_PAX_RANDMMAP
5262+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
5263+#endif
5264+
5265 if (addr) {
5266 if (do_color_align)
5267 addr = COLOUR_ALIGN(addr, pgoff);
5268@@ -91,8 +97,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5269 addr = PAGE_ALIGN(addr);
5270
5271 vma = find_vma(mm, addr);
5272- if (TASK_SIZE - len >= addr &&
5273- (!vma || addr + len <= vma->vm_start))
5274+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
5275 return addr;
5276 }
5277
5278@@ -146,6 +151,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5279 {
5280 unsigned long random_factor = 0UL;
5281
5282+#ifdef CONFIG_PAX_RANDMMAP
5283+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5284+#endif
5285+
5286 if (current->flags & PF_RANDOMIZE) {
5287 random_factor = get_random_int();
5288 random_factor = random_factor << PAGE_SHIFT;
5289@@ -157,42 +166,27 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5290
5291 if (mmap_is_legacy()) {
5292 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5293+
5294+#ifdef CONFIG_PAX_RANDMMAP
5295+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5296+ mm->mmap_base += mm->delta_mmap;
5297+#endif
5298+
5299 mm->get_unmapped_area = arch_get_unmapped_area;
5300 mm->unmap_area = arch_unmap_area;
5301 } else {
5302 mm->mmap_base = mmap_base(random_factor);
5303+
5304+#ifdef CONFIG_PAX_RANDMMAP
5305+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5306+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5307+#endif
5308+
5309 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5310 mm->unmap_area = arch_unmap_area_topdown;
5311 }
5312 }
5313
5314-static inline unsigned long brk_rnd(void)
5315-{
5316- unsigned long rnd = get_random_int();
5317-
5318- rnd = rnd << PAGE_SHIFT;
5319- /* 8MB for 32bit, 256MB for 64bit */
5320- if (TASK_IS_32BIT_ADDR)
5321- rnd = rnd & 0x7ffffful;
5322- else
5323- rnd = rnd & 0xffffffful;
5324-
5325- return rnd;
5326-}
5327-
5328-unsigned long arch_randomize_brk(struct mm_struct *mm)
5329-{
5330- unsigned long base = mm->brk;
5331- unsigned long ret;
5332-
5333- ret = PAGE_ALIGN(base + brk_rnd());
5334-
5335- if (ret < mm->brk)
5336- return mm->brk;
5337-
5338- return ret;
5339-}
5340-
5341 int __virt_addr_valid(const volatile void *kaddr)
5342 {
5343 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
5344diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5345index 967d144..db12197 100644
5346--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
5347+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5348@@ -11,12 +11,14 @@
5349 #ifndef _ASM_PROC_CACHE_H
5350 #define _ASM_PROC_CACHE_H
5351
5352+#include <linux/const.h>
5353+
5354 /* L1 cache */
5355
5356 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5357 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
5358-#define L1_CACHE_BYTES 16 /* bytes per entry */
5359 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
5360+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5361 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
5362
5363 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5364diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5365index bcb5df2..84fabd2 100644
5366--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5367+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5368@@ -16,13 +16,15 @@
5369 #ifndef _ASM_PROC_CACHE_H
5370 #define _ASM_PROC_CACHE_H
5371
5372+#include <linux/const.h>
5373+
5374 /*
5375 * L1 cache
5376 */
5377 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5378 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
5379-#define L1_CACHE_BYTES 32 /* bytes per entry */
5380 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
5381+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5382 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
5383
5384 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5385diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
5386index 4ce7a01..449202a 100644
5387--- a/arch/openrisc/include/asm/cache.h
5388+++ b/arch/openrisc/include/asm/cache.h
5389@@ -19,11 +19,13 @@
5390 #ifndef __ASM_OPENRISC_CACHE_H
5391 #define __ASM_OPENRISC_CACHE_H
5392
5393+#include <linux/const.h>
5394+
5395 /* FIXME: How can we replace these with values from the CPU...
5396 * they shouldn't be hard-coded!
5397 */
5398
5399-#define L1_CACHE_BYTES 16
5400 #define L1_CACHE_SHIFT 4
5401+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5402
5403 #endif /* __ASM_OPENRISC_CACHE_H */
5404diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
5405index af9cf30..2aae9b2 100644
5406--- a/arch/parisc/include/asm/atomic.h
5407+++ b/arch/parisc/include/asm/atomic.h
5408@@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5409
5410 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5411
5412+#define atomic64_read_unchecked(v) atomic64_read(v)
5413+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5414+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5415+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5416+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5417+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5418+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5419+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5420+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5421+
5422 #endif /* !CONFIG_64BIT */
5423
5424
5425diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
5426index 47f11c7..3420df2 100644
5427--- a/arch/parisc/include/asm/cache.h
5428+++ b/arch/parisc/include/asm/cache.h
5429@@ -5,6 +5,7 @@
5430 #ifndef __ARCH_PARISC_CACHE_H
5431 #define __ARCH_PARISC_CACHE_H
5432
5433+#include <linux/const.h>
5434
5435 /*
5436 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
5437@@ -15,13 +16,13 @@
5438 * just ruin performance.
5439 */
5440 #ifdef CONFIG_PA20
5441-#define L1_CACHE_BYTES 64
5442 #define L1_CACHE_SHIFT 6
5443 #else
5444-#define L1_CACHE_BYTES 32
5445 #define L1_CACHE_SHIFT 5
5446 #endif
5447
5448+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5449+
5450 #ifndef __ASSEMBLY__
5451
5452 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5453diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
5454index 19f6cb1..6c78cf2 100644
5455--- a/arch/parisc/include/asm/elf.h
5456+++ b/arch/parisc/include/asm/elf.h
5457@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
5458
5459 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
5460
5461+#ifdef CONFIG_PAX_ASLR
5462+#define PAX_ELF_ET_DYN_BASE 0x10000UL
5463+
5464+#define PAX_DELTA_MMAP_LEN 16
5465+#define PAX_DELTA_STACK_LEN 16
5466+#endif
5467+
5468 /* This yields a mask that user programs can use to figure out what
5469 instruction set this CPU supports. This could be done in user space,
5470 but it's not easy, and we've already done it here. */
5471diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
5472index fc987a1..6e068ef 100644
5473--- a/arch/parisc/include/asm/pgalloc.h
5474+++ b/arch/parisc/include/asm/pgalloc.h
5475@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5476 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
5477 }
5478
5479+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5480+{
5481+ pgd_populate(mm, pgd, pmd);
5482+}
5483+
5484 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
5485 {
5486 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
5487@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
5488 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
5489 #define pmd_free(mm, x) do { } while (0)
5490 #define pgd_populate(mm, pmd, pte) BUG()
5491+#define pgd_populate_kernel(mm, pmd, pte) BUG()
5492
5493 #endif
5494
5495diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
5496index ee99f23..802b0a1 100644
5497--- a/arch/parisc/include/asm/pgtable.h
5498+++ b/arch/parisc/include/asm/pgtable.h
5499@@ -212,6 +212,17 @@ struct vm_area_struct;
5500 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
5501 #define PAGE_COPY PAGE_EXECREAD
5502 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
5503+
5504+#ifdef CONFIG_PAX_PAGEEXEC
5505+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
5506+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5507+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5508+#else
5509+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5510+# define PAGE_COPY_NOEXEC PAGE_COPY
5511+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5512+#endif
5513+
5514 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
5515 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
5516 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
5517diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
5518index 4ba2c93..f5e3974 100644
5519--- a/arch/parisc/include/asm/uaccess.h
5520+++ b/arch/parisc/include/asm/uaccess.h
5521@@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
5522 const void __user *from,
5523 unsigned long n)
5524 {
5525- int sz = __compiletime_object_size(to);
5526+ size_t sz = __compiletime_object_size(to);
5527 int ret = -EFAULT;
5528
5529- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
5530+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
5531 ret = __copy_from_user(to, from, n);
5532 else
5533 copy_from_user_overflow();
5534diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
5535index 2a625fb..9908930 100644
5536--- a/arch/parisc/kernel/module.c
5537+++ b/arch/parisc/kernel/module.c
5538@@ -98,16 +98,38 @@
5539
5540 /* three functions to determine where in the module core
5541 * or init pieces the location is */
5542+static inline int in_init_rx(struct module *me, void *loc)
5543+{
5544+ return (loc >= me->module_init_rx &&
5545+ loc < (me->module_init_rx + me->init_size_rx));
5546+}
5547+
5548+static inline int in_init_rw(struct module *me, void *loc)
5549+{
5550+ return (loc >= me->module_init_rw &&
5551+ loc < (me->module_init_rw + me->init_size_rw));
5552+}
5553+
5554 static inline int in_init(struct module *me, void *loc)
5555 {
5556- return (loc >= me->module_init &&
5557- loc <= (me->module_init + me->init_size));
5558+ return in_init_rx(me, loc) || in_init_rw(me, loc);
5559+}
5560+
5561+static inline int in_core_rx(struct module *me, void *loc)
5562+{
5563+ return (loc >= me->module_core_rx &&
5564+ loc < (me->module_core_rx + me->core_size_rx));
5565+}
5566+
5567+static inline int in_core_rw(struct module *me, void *loc)
5568+{
5569+ return (loc >= me->module_core_rw &&
5570+ loc < (me->module_core_rw + me->core_size_rw));
5571 }
5572
5573 static inline int in_core(struct module *me, void *loc)
5574 {
5575- return (loc >= me->module_core &&
5576- loc <= (me->module_core + me->core_size));
5577+ return in_core_rx(me, loc) || in_core_rw(me, loc);
5578 }
5579
5580 static inline int in_local(struct module *me, void *loc)
5581@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
5582 }
5583
5584 /* align things a bit */
5585- me->core_size = ALIGN(me->core_size, 16);
5586- me->arch.got_offset = me->core_size;
5587- me->core_size += gots * sizeof(struct got_entry);
5588+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
5589+ me->arch.got_offset = me->core_size_rw;
5590+ me->core_size_rw += gots * sizeof(struct got_entry);
5591
5592- me->core_size = ALIGN(me->core_size, 16);
5593- me->arch.fdesc_offset = me->core_size;
5594- me->core_size += fdescs * sizeof(Elf_Fdesc);
5595+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
5596+ me->arch.fdesc_offset = me->core_size_rw;
5597+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
5598
5599 me->arch.got_max = gots;
5600 me->arch.fdesc_max = fdescs;
5601@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5602
5603 BUG_ON(value == 0);
5604
5605- got = me->module_core + me->arch.got_offset;
5606+ got = me->module_core_rw + me->arch.got_offset;
5607 for (i = 0; got[i].addr; i++)
5608 if (got[i].addr == value)
5609 goto out;
5610@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5611 #ifdef CONFIG_64BIT
5612 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5613 {
5614- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
5615+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
5616
5617 if (!value) {
5618 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
5619@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5620
5621 /* Create new one */
5622 fdesc->addr = value;
5623- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5624+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5625 return (Elf_Addr)fdesc;
5626 }
5627 #endif /* CONFIG_64BIT */
5628@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
5629
5630 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
5631 end = table + sechdrs[me->arch.unwind_section].sh_size;
5632- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5633+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5634
5635 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
5636 me->arch.unwind_section, table, end, gp);
5637diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
5638index f76c108..92bad82 100644
5639--- a/arch/parisc/kernel/sys_parisc.c
5640+++ b/arch/parisc/kernel/sys_parisc.c
5641@@ -33,9 +33,11 @@
5642 #include <linux/utsname.h>
5643 #include <linux/personality.h>
5644
5645-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5646+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
5647+ unsigned long flags)
5648 {
5649 struct vm_area_struct *vma;
5650+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5651
5652 addr = PAGE_ALIGN(addr);
5653
5654@@ -43,7 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5655 /* At this point: (!vma || addr < vma->vm_end). */
5656 if (TASK_SIZE - len < addr)
5657 return -ENOMEM;
5658- if (!vma || addr + len <= vma->vm_start)
5659+ if (check_heap_stack_gap(vma, addr, len, offset))
5660 return addr;
5661 addr = vma->vm_end;
5662 }
5663@@ -67,11 +69,12 @@ static int get_offset(struct address_space *mapping)
5664 return offset & 0x3FF000;
5665 }
5666
5667-static unsigned long get_shared_area(struct address_space *mapping,
5668- unsigned long addr, unsigned long len, unsigned long pgoff)
5669+static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
5670+ unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
5671 {
5672 struct vm_area_struct *vma;
5673 int offset = mapping ? get_offset(mapping) : 0;
5674+ unsigned long rand_offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5675
5676 offset = (offset + (pgoff << PAGE_SHIFT)) & 0x3FF000;
5677
5678@@ -81,7 +84,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
5679 /* At this point: (!vma || addr < vma->vm_end). */
5680 if (TASK_SIZE - len < addr)
5681 return -ENOMEM;
5682- if (!vma || addr + len <= vma->vm_start)
5683+ if (check_heap_stack_gap(vma, addr, len, rand_offset))
5684 return addr;
5685 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
5686 if (addr < vma->vm_end) /* handle wraparound */
5687@@ -100,14 +103,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5688 if (flags & MAP_FIXED)
5689 return addr;
5690 if (!addr)
5691- addr = TASK_UNMAPPED_BASE;
5692+ addr = current->mm->mmap_base;
5693
5694 if (filp) {
5695- addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
5696+ addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
5697 } else if(flags & MAP_SHARED) {
5698- addr = get_shared_area(NULL, addr, len, pgoff);
5699+ addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
5700 } else {
5701- addr = get_unshared_area(addr, len);
5702+ addr = get_unshared_area(filp, addr, len, flags);
5703 }
5704 return addr;
5705 }
5706diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
5707index 45ba99f..8e22c33 100644
5708--- a/arch/parisc/kernel/traps.c
5709+++ b/arch/parisc/kernel/traps.c
5710@@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
5711
5712 down_read(&current->mm->mmap_sem);
5713 vma = find_vma(current->mm,regs->iaoq[0]);
5714- if (vma && (regs->iaoq[0] >= vma->vm_start)
5715- && (vma->vm_flags & VM_EXEC)) {
5716-
5717+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
5718 fault_address = regs->iaoq[0];
5719 fault_space = regs->iasq[0];
5720
5721diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
5722index 18162ce..94de376 100644
5723--- a/arch/parisc/mm/fault.c
5724+++ b/arch/parisc/mm/fault.c
5725@@ -15,6 +15,7 @@
5726 #include <linux/sched.h>
5727 #include <linux/interrupt.h>
5728 #include <linux/module.h>
5729+#include <linux/unistd.h>
5730
5731 #include <asm/uaccess.h>
5732 #include <asm/traps.h>
5733@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
5734 static unsigned long
5735 parisc_acctyp(unsigned long code, unsigned int inst)
5736 {
5737- if (code == 6 || code == 16)
5738+ if (code == 6 || code == 7 || code == 16)
5739 return VM_EXEC;
5740
5741 switch (inst & 0xf0000000) {
5742@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
5743 }
5744 #endif
5745
5746+#ifdef CONFIG_PAX_PAGEEXEC
5747+/*
5748+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
5749+ *
5750+ * returns 1 when task should be killed
5751+ * 2 when rt_sigreturn trampoline was detected
5752+ * 3 when unpatched PLT trampoline was detected
5753+ */
5754+static int pax_handle_fetch_fault(struct pt_regs *regs)
5755+{
5756+
5757+#ifdef CONFIG_PAX_EMUPLT
5758+ int err;
5759+
5760+ do { /* PaX: unpatched PLT emulation */
5761+ unsigned int bl, depwi;
5762+
5763+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
5764+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
5765+
5766+ if (err)
5767+ break;
5768+
5769+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
5770+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
5771+
5772+ err = get_user(ldw, (unsigned int *)addr);
5773+ err |= get_user(bv, (unsigned int *)(addr+4));
5774+ err |= get_user(ldw2, (unsigned int *)(addr+8));
5775+
5776+ if (err)
5777+ break;
5778+
5779+ if (ldw == 0x0E801096U &&
5780+ bv == 0xEAC0C000U &&
5781+ ldw2 == 0x0E881095U)
5782+ {
5783+ unsigned int resolver, map;
5784+
5785+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
5786+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
5787+ if (err)
5788+ break;
5789+
5790+ regs->gr[20] = instruction_pointer(regs)+8;
5791+ regs->gr[21] = map;
5792+ regs->gr[22] = resolver;
5793+ regs->iaoq[0] = resolver | 3UL;
5794+ regs->iaoq[1] = regs->iaoq[0] + 4;
5795+ return 3;
5796+ }
5797+ }
5798+ } while (0);
5799+#endif
5800+
5801+#ifdef CONFIG_PAX_EMUTRAMP
5802+
5803+#ifndef CONFIG_PAX_EMUSIGRT
5804+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
5805+ return 1;
5806+#endif
5807+
5808+ do { /* PaX: rt_sigreturn emulation */
5809+ unsigned int ldi1, ldi2, bel, nop;
5810+
5811+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
5812+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
5813+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
5814+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
5815+
5816+ if (err)
5817+ break;
5818+
5819+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
5820+ ldi2 == 0x3414015AU &&
5821+ bel == 0xE4008200U &&
5822+ nop == 0x08000240U)
5823+ {
5824+ regs->gr[25] = (ldi1 & 2) >> 1;
5825+ regs->gr[20] = __NR_rt_sigreturn;
5826+ regs->gr[31] = regs->iaoq[1] + 16;
5827+ regs->sr[0] = regs->iasq[1];
5828+ regs->iaoq[0] = 0x100UL;
5829+ regs->iaoq[1] = regs->iaoq[0] + 4;
5830+ regs->iasq[0] = regs->sr[2];
5831+ regs->iasq[1] = regs->sr[2];
5832+ return 2;
5833+ }
5834+ } while (0);
5835+#endif
5836+
5837+ return 1;
5838+}
5839+
5840+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5841+{
5842+ unsigned long i;
5843+
5844+ printk(KERN_ERR "PAX: bytes at PC: ");
5845+ for (i = 0; i < 5; i++) {
5846+ unsigned int c;
5847+ if (get_user(c, (unsigned int *)pc+i))
5848+ printk(KERN_CONT "???????? ");
5849+ else
5850+ printk(KERN_CONT "%08x ", c);
5851+ }
5852+ printk("\n");
5853+}
5854+#endif
5855+
5856 int fixup_exception(struct pt_regs *regs)
5857 {
5858 const struct exception_table_entry *fix;
5859@@ -192,8 +303,33 @@ good_area:
5860
5861 acc_type = parisc_acctyp(code,regs->iir);
5862
5863- if ((vma->vm_flags & acc_type) != acc_type)
5864+ if ((vma->vm_flags & acc_type) != acc_type) {
5865+
5866+#ifdef CONFIG_PAX_PAGEEXEC
5867+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
5868+ (address & ~3UL) == instruction_pointer(regs))
5869+ {
5870+ up_read(&mm->mmap_sem);
5871+ switch (pax_handle_fetch_fault(regs)) {
5872+
5873+#ifdef CONFIG_PAX_EMUPLT
5874+ case 3:
5875+ return;
5876+#endif
5877+
5878+#ifdef CONFIG_PAX_EMUTRAMP
5879+ case 2:
5880+ return;
5881+#endif
5882+
5883+ }
5884+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
5885+ do_group_exit(SIGKILL);
5886+ }
5887+#endif
5888+
5889 goto bad_area;
5890+ }
5891
5892 /*
5893 * If for any reason at all we couldn't handle the fault, make
5894diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
5895index e3b1d41..8e81edf 100644
5896--- a/arch/powerpc/include/asm/atomic.h
5897+++ b/arch/powerpc/include/asm/atomic.h
5898@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
5899 return t1;
5900 }
5901
5902+#define atomic64_read_unchecked(v) atomic64_read(v)
5903+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5904+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5905+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5906+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5907+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5908+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5909+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5910+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5911+
5912 #endif /* __powerpc64__ */
5913
5914 #endif /* __KERNEL__ */
5915diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
5916index 9e495c9..b6878e5 100644
5917--- a/arch/powerpc/include/asm/cache.h
5918+++ b/arch/powerpc/include/asm/cache.h
5919@@ -3,6 +3,7 @@
5920
5921 #ifdef __KERNEL__
5922
5923+#include <linux/const.h>
5924
5925 /* bytes per L1 cache line */
5926 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
5927@@ -22,7 +23,7 @@
5928 #define L1_CACHE_SHIFT 7
5929 #endif
5930
5931-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5932+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5933
5934 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5935
5936diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
5937index 6abf0a1..459d0f1 100644
5938--- a/arch/powerpc/include/asm/elf.h
5939+++ b/arch/powerpc/include/asm/elf.h
5940@@ -28,8 +28,19 @@
5941 the loader. We need to make sure that it is out of the way of the program
5942 that it will "exec", and that there is sufficient room for the brk. */
5943
5944-extern unsigned long randomize_et_dyn(unsigned long base);
5945-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
5946+#define ELF_ET_DYN_BASE (0x20000000)
5947+
5948+#ifdef CONFIG_PAX_ASLR
5949+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
5950+
5951+#ifdef __powerpc64__
5952+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
5953+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
5954+#else
5955+#define PAX_DELTA_MMAP_LEN 15
5956+#define PAX_DELTA_STACK_LEN 15
5957+#endif
5958+#endif
5959
5960 /*
5961 * Our registers are always unsigned longs, whether we're a 32 bit
5962@@ -124,10 +135,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
5963 (0x7ff >> (PAGE_SHIFT - 12)) : \
5964 (0x3ffff >> (PAGE_SHIFT - 12)))
5965
5966-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5967-#define arch_randomize_brk arch_randomize_brk
5968-
5969-
5970 #ifdef CONFIG_SPU_BASE
5971 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
5972 #define NT_SPU 1
5973diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
5974index 8196e9c..d83a9f3 100644
5975--- a/arch/powerpc/include/asm/exec.h
5976+++ b/arch/powerpc/include/asm/exec.h
5977@@ -4,6 +4,6 @@
5978 #ifndef _ASM_POWERPC_EXEC_H
5979 #define _ASM_POWERPC_EXEC_H
5980
5981-extern unsigned long arch_align_stack(unsigned long sp);
5982+#define arch_align_stack(x) ((x) & ~0xfUL)
5983
5984 #endif /* _ASM_POWERPC_EXEC_H */
5985diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
5986index 5acabbd..7ea14fa 100644
5987--- a/arch/powerpc/include/asm/kmap_types.h
5988+++ b/arch/powerpc/include/asm/kmap_types.h
5989@@ -10,7 +10,7 @@
5990 * 2 of the License, or (at your option) any later version.
5991 */
5992
5993-#define KM_TYPE_NR 16
5994+#define KM_TYPE_NR 17
5995
5996 #endif /* __KERNEL__ */
5997 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
5998diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
5999index 8565c25..2865190 100644
6000--- a/arch/powerpc/include/asm/mman.h
6001+++ b/arch/powerpc/include/asm/mman.h
6002@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
6003 }
6004 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
6005
6006-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
6007+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
6008 {
6009 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
6010 }
6011diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
6012index f072e97..b436dee 100644
6013--- a/arch/powerpc/include/asm/page.h
6014+++ b/arch/powerpc/include/asm/page.h
6015@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
6016 * and needs to be executable. This means the whole heap ends
6017 * up being executable.
6018 */
6019-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6020- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6021+#define VM_DATA_DEFAULT_FLAGS32 \
6022+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6023+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6024
6025 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6026 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6027@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
6028 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
6029 #endif
6030
6031+#define ktla_ktva(addr) (addr)
6032+#define ktva_ktla(addr) (addr)
6033+
6034 /*
6035 * Use the top bit of the higher-level page table entries to indicate whether
6036 * the entries we point to contain hugepages. This works because we know that
6037diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
6038index cd915d6..c10cee8 100644
6039--- a/arch/powerpc/include/asm/page_64.h
6040+++ b/arch/powerpc/include/asm/page_64.h
6041@@ -154,15 +154,18 @@ do { \
6042 * stack by default, so in the absence of a PT_GNU_STACK program header
6043 * we turn execute permission off.
6044 */
6045-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6046- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6047+#define VM_STACK_DEFAULT_FLAGS32 \
6048+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6049+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6050
6051 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6052 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6053
6054+#ifndef CONFIG_PAX_PAGEEXEC
6055 #define VM_STACK_DEFAULT_FLAGS \
6056 (is_32bit_task() ? \
6057 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
6058+#endif
6059
6060 #include <asm-generic/getorder.h>
6061
6062diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
6063index 292725c..f87ae14 100644
6064--- a/arch/powerpc/include/asm/pgalloc-64.h
6065+++ b/arch/powerpc/include/asm/pgalloc-64.h
6066@@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6067 #ifndef CONFIG_PPC_64K_PAGES
6068
6069 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
6070+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
6071
6072 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
6073 {
6074@@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6075 pud_set(pud, (unsigned long)pmd);
6076 }
6077
6078+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6079+{
6080+ pud_populate(mm, pud, pmd);
6081+}
6082+
6083 #define pmd_populate(mm, pmd, pte_page) \
6084 pmd_populate_kernel(mm, pmd, page_address(pte_page))
6085 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
6086@@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6087 #else /* CONFIG_PPC_64K_PAGES */
6088
6089 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
6090+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
6091
6092 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
6093 pte_t *pte)
6094diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
6095index a9cbd3b..3b67efa 100644
6096--- a/arch/powerpc/include/asm/pgtable.h
6097+++ b/arch/powerpc/include/asm/pgtable.h
6098@@ -2,6 +2,7 @@
6099 #define _ASM_POWERPC_PGTABLE_H
6100 #ifdef __KERNEL__
6101
6102+#include <linux/const.h>
6103 #ifndef __ASSEMBLY__
6104 #include <asm/processor.h> /* For TASK_SIZE */
6105 #include <asm/mmu.h>
6106diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
6107index 4aad413..85d86bf 100644
6108--- a/arch/powerpc/include/asm/pte-hash32.h
6109+++ b/arch/powerpc/include/asm/pte-hash32.h
6110@@ -21,6 +21,7 @@
6111 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
6112 #define _PAGE_USER 0x004 /* usermode access allowed */
6113 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
6114+#define _PAGE_EXEC _PAGE_GUARDED
6115 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
6116 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
6117 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
6118diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
6119index 3d5c9dc..62f8414 100644
6120--- a/arch/powerpc/include/asm/reg.h
6121+++ b/arch/powerpc/include/asm/reg.h
6122@@ -215,6 +215,7 @@
6123 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
6124 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
6125 #define DSISR_NOHPTE 0x40000000 /* no translation found */
6126+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
6127 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
6128 #define DSISR_ISSTORE 0x02000000 /* access was a store */
6129 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
6130diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
6131index 406b7b9..af63426 100644
6132--- a/arch/powerpc/include/asm/thread_info.h
6133+++ b/arch/powerpc/include/asm/thread_info.h
6134@@ -97,7 +97,6 @@ static inline struct thread_info *current_thread_info(void)
6135 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
6136 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
6137 #define TIF_SINGLESTEP 8 /* singlestepping active */
6138-#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
6139 #define TIF_SECCOMP 10 /* secure computing */
6140 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
6141 #define TIF_NOERROR 12 /* Force successful syscall return */
6142@@ -106,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6143 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
6144 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
6145 for stack store? */
6146+#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
6147+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
6148+#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
6149
6150 /* as above, but as bit values */
6151 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6152@@ -124,8 +126,10 @@ static inline struct thread_info *current_thread_info(void)
6153 #define _TIF_UPROBE (1<<TIF_UPROBE)
6154 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6155 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
6156+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6157 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
6158- _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
6159+ _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
6160+ _TIF_GRSEC_SETXID)
6161
6162 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
6163 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
6164diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
6165index 4db4959..335e00c 100644
6166--- a/arch/powerpc/include/asm/uaccess.h
6167+++ b/arch/powerpc/include/asm/uaccess.h
6168@@ -13,6 +13,8 @@
6169 #define VERIFY_READ 0
6170 #define VERIFY_WRITE 1
6171
6172+extern void check_object_size(const void *ptr, unsigned long n, bool to);
6173+
6174 /*
6175 * The fs value determines whether argument validity checking should be
6176 * performed or not. If get_fs() == USER_DS, checking is performed, with
6177@@ -318,52 +320,6 @@ do { \
6178 extern unsigned long __copy_tofrom_user(void __user *to,
6179 const void __user *from, unsigned long size);
6180
6181-#ifndef __powerpc64__
6182-
6183-static inline unsigned long copy_from_user(void *to,
6184- const void __user *from, unsigned long n)
6185-{
6186- unsigned long over;
6187-
6188- if (access_ok(VERIFY_READ, from, n))
6189- return __copy_tofrom_user((__force void __user *)to, from, n);
6190- if ((unsigned long)from < TASK_SIZE) {
6191- over = (unsigned long)from + n - TASK_SIZE;
6192- return __copy_tofrom_user((__force void __user *)to, from,
6193- n - over) + over;
6194- }
6195- return n;
6196-}
6197-
6198-static inline unsigned long copy_to_user(void __user *to,
6199- const void *from, unsigned long n)
6200-{
6201- unsigned long over;
6202-
6203- if (access_ok(VERIFY_WRITE, to, n))
6204- return __copy_tofrom_user(to, (__force void __user *)from, n);
6205- if ((unsigned long)to < TASK_SIZE) {
6206- over = (unsigned long)to + n - TASK_SIZE;
6207- return __copy_tofrom_user(to, (__force void __user *)from,
6208- n - over) + over;
6209- }
6210- return n;
6211-}
6212-
6213-#else /* __powerpc64__ */
6214-
6215-#define __copy_in_user(to, from, size) \
6216- __copy_tofrom_user((to), (from), (size))
6217-
6218-extern unsigned long copy_from_user(void *to, const void __user *from,
6219- unsigned long n);
6220-extern unsigned long copy_to_user(void __user *to, const void *from,
6221- unsigned long n);
6222-extern unsigned long copy_in_user(void __user *to, const void __user *from,
6223- unsigned long n);
6224-
6225-#endif /* __powerpc64__ */
6226-
6227 static inline unsigned long __copy_from_user_inatomic(void *to,
6228 const void __user *from, unsigned long n)
6229 {
6230@@ -387,6 +343,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
6231 if (ret == 0)
6232 return 0;
6233 }
6234+
6235+ if (!__builtin_constant_p(n))
6236+ check_object_size(to, n, false);
6237+
6238 return __copy_tofrom_user((__force void __user *)to, from, n);
6239 }
6240
6241@@ -413,6 +373,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
6242 if (ret == 0)
6243 return 0;
6244 }
6245+
6246+ if (!__builtin_constant_p(n))
6247+ check_object_size(from, n, true);
6248+
6249 return __copy_tofrom_user(to, (__force const void __user *)from, n);
6250 }
6251
6252@@ -430,6 +394,92 @@ static inline unsigned long __copy_to_user(void __user *to,
6253 return __copy_to_user_inatomic(to, from, size);
6254 }
6255
6256+#ifndef __powerpc64__
6257+
6258+static inline unsigned long __must_check copy_from_user(void *to,
6259+ const void __user *from, unsigned long n)
6260+{
6261+ unsigned long over;
6262+
6263+ if ((long)n < 0)
6264+ return n;
6265+
6266+ if (access_ok(VERIFY_READ, from, n)) {
6267+ if (!__builtin_constant_p(n))
6268+ check_object_size(to, n, false);
6269+ return __copy_tofrom_user((__force void __user *)to, from, n);
6270+ }
6271+ if ((unsigned long)from < TASK_SIZE) {
6272+ over = (unsigned long)from + n - TASK_SIZE;
6273+ if (!__builtin_constant_p(n - over))
6274+ check_object_size(to, n - over, false);
6275+ return __copy_tofrom_user((__force void __user *)to, from,
6276+ n - over) + over;
6277+ }
6278+ return n;
6279+}
6280+
6281+static inline unsigned long __must_check copy_to_user(void __user *to,
6282+ const void *from, unsigned long n)
6283+{
6284+ unsigned long over;
6285+
6286+ if ((long)n < 0)
6287+ return n;
6288+
6289+ if (access_ok(VERIFY_WRITE, to, n)) {
6290+ if (!__builtin_constant_p(n))
6291+ check_object_size(from, n, true);
6292+ return __copy_tofrom_user(to, (__force void __user *)from, n);
6293+ }
6294+ if ((unsigned long)to < TASK_SIZE) {
6295+ over = (unsigned long)to + n - TASK_SIZE;
6296+ if (!__builtin_constant_p(n))
6297+ check_object_size(from, n - over, true);
6298+ return __copy_tofrom_user(to, (__force void __user *)from,
6299+ n - over) + over;
6300+ }
6301+ return n;
6302+}
6303+
6304+#else /* __powerpc64__ */
6305+
6306+#define __copy_in_user(to, from, size) \
6307+ __copy_tofrom_user((to), (from), (size))
6308+
6309+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
6310+{
6311+ if ((long)n < 0 || n > INT_MAX)
6312+ return n;
6313+
6314+ if (!__builtin_constant_p(n))
6315+ check_object_size(to, n, false);
6316+
6317+ if (likely(access_ok(VERIFY_READ, from, n)))
6318+ n = __copy_from_user(to, from, n);
6319+ else
6320+ memset(to, 0, n);
6321+ return n;
6322+}
6323+
6324+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
6325+{
6326+ if ((long)n < 0 || n > INT_MAX)
6327+ return n;
6328+
6329+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
6330+ if (!__builtin_constant_p(n))
6331+ check_object_size(from, n, true);
6332+ n = __copy_to_user(to, from, n);
6333+ }
6334+ return n;
6335+}
6336+
6337+extern unsigned long copy_in_user(void __user *to, const void __user *from,
6338+ unsigned long n);
6339+
6340+#endif /* __powerpc64__ */
6341+
6342 extern unsigned long __clear_user(void __user *addr, unsigned long size);
6343
6344 static inline unsigned long clear_user(void __user *addr, unsigned long size)
6345diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
6346index 4684e33..acc4d19e 100644
6347--- a/arch/powerpc/kernel/exceptions-64e.S
6348+++ b/arch/powerpc/kernel/exceptions-64e.S
6349@@ -715,6 +715,7 @@ storage_fault_common:
6350 std r14,_DAR(r1)
6351 std r15,_DSISR(r1)
6352 addi r3,r1,STACK_FRAME_OVERHEAD
6353+ bl .save_nvgprs
6354 mr r4,r14
6355 mr r5,r15
6356 ld r14,PACA_EXGEN+EX_R14(r13)
6357@@ -723,8 +724,7 @@ storage_fault_common:
6358 cmpdi r3,0
6359 bne- 1f
6360 b .ret_from_except_lite
6361-1: bl .save_nvgprs
6362- mr r5,r3
6363+1: mr r5,r3
6364 addi r3,r1,STACK_FRAME_OVERHEAD
6365 ld r4,_DAR(r1)
6366 bl .bad_page_fault
6367diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
6368index 4665e82..080ea99 100644
6369--- a/arch/powerpc/kernel/exceptions-64s.S
6370+++ b/arch/powerpc/kernel/exceptions-64s.S
6371@@ -1206,10 +1206,10 @@ handle_page_fault:
6372 11: ld r4,_DAR(r1)
6373 ld r5,_DSISR(r1)
6374 addi r3,r1,STACK_FRAME_OVERHEAD
6375+ bl .save_nvgprs
6376 bl .do_page_fault
6377 cmpdi r3,0
6378 beq+ 12f
6379- bl .save_nvgprs
6380 mr r5,r3
6381 addi r3,r1,STACK_FRAME_OVERHEAD
6382 lwz r4,_DAR(r1)
6383diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
6384index 2e3200c..72095ce 100644
6385--- a/arch/powerpc/kernel/module_32.c
6386+++ b/arch/powerpc/kernel/module_32.c
6387@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
6388 me->arch.core_plt_section = i;
6389 }
6390 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
6391- printk("Module doesn't contain .plt or .init.plt sections.\n");
6392+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
6393 return -ENOEXEC;
6394 }
6395
6396@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
6397
6398 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
6399 /* Init, or core PLT? */
6400- if (location >= mod->module_core
6401- && location < mod->module_core + mod->core_size)
6402+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
6403+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
6404 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
6405- else
6406+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
6407+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
6408 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
6409+ else {
6410+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
6411+ return ~0UL;
6412+ }
6413
6414 /* Find this entry, or if that fails, the next avail. entry */
6415 while (entry->jump[0]) {
6416diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
6417index 8143067..21ae55b 100644
6418--- a/arch/powerpc/kernel/process.c
6419+++ b/arch/powerpc/kernel/process.c
6420@@ -680,8 +680,8 @@ void show_regs(struct pt_regs * regs)
6421 * Lookup NIP late so we have the best change of getting the
6422 * above info out without failing
6423 */
6424- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
6425- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
6426+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
6427+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
6428 #endif
6429 show_stack(current, (unsigned long *) regs->gpr[1]);
6430 if (!user_mode(regs))
6431@@ -1129,10 +1129,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6432 newsp = stack[0];
6433 ip = stack[STACK_FRAME_LR_SAVE];
6434 if (!firstframe || ip != lr) {
6435- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
6436+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
6437 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6438 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
6439- printk(" (%pS)",
6440+ printk(" (%pA)",
6441 (void *)current->ret_stack[curr_frame].ret);
6442 curr_frame--;
6443 }
6444@@ -1152,7 +1152,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6445 struct pt_regs *regs = (struct pt_regs *)
6446 (sp + STACK_FRAME_OVERHEAD);
6447 lr = regs->link;
6448- printk("--- Exception: %lx at %pS\n LR = %pS\n",
6449+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
6450 regs->trap, (void *)regs->nip, (void *)lr);
6451 firstframe = 1;
6452 }
6453@@ -1194,58 +1194,3 @@ void __ppc64_runlatch_off(void)
6454 mtspr(SPRN_CTRLT, ctrl);
6455 }
6456 #endif /* CONFIG_PPC64 */
6457-
6458-unsigned long arch_align_stack(unsigned long sp)
6459-{
6460- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6461- sp -= get_random_int() & ~PAGE_MASK;
6462- return sp & ~0xf;
6463-}
6464-
6465-static inline unsigned long brk_rnd(void)
6466-{
6467- unsigned long rnd = 0;
6468-
6469- /* 8MB for 32bit, 1GB for 64bit */
6470- if (is_32bit_task())
6471- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
6472- else
6473- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
6474-
6475- return rnd << PAGE_SHIFT;
6476-}
6477-
6478-unsigned long arch_randomize_brk(struct mm_struct *mm)
6479-{
6480- unsigned long base = mm->brk;
6481- unsigned long ret;
6482-
6483-#ifdef CONFIG_PPC_STD_MMU_64
6484- /*
6485- * If we are using 1TB segments and we are allowed to randomise
6486- * the heap, we can put it above 1TB so it is backed by a 1TB
6487- * segment. Otherwise the heap will be in the bottom 1TB
6488- * which always uses 256MB segments and this may result in a
6489- * performance penalty.
6490- */
6491- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
6492- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
6493-#endif
6494-
6495- ret = PAGE_ALIGN(base + brk_rnd());
6496-
6497- if (ret < mm->brk)
6498- return mm->brk;
6499-
6500- return ret;
6501-}
6502-
6503-unsigned long randomize_et_dyn(unsigned long base)
6504-{
6505- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
6506-
6507- if (ret < base)
6508- return base;
6509-
6510- return ret;
6511-}
6512diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
6513index c497000..8fde506 100644
6514--- a/arch/powerpc/kernel/ptrace.c
6515+++ b/arch/powerpc/kernel/ptrace.c
6516@@ -1737,6 +1737,10 @@ long arch_ptrace(struct task_struct *child, long request,
6517 return ret;
6518 }
6519
6520+#ifdef CONFIG_GRKERNSEC_SETXID
6521+extern void gr_delayed_cred_worker(void);
6522+#endif
6523+
6524 /*
6525 * We must return the syscall number to actually look up in the table.
6526 * This can be -1L to skip running any syscall at all.
6527@@ -1747,6 +1751,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
6528
6529 secure_computing_strict(regs->gpr[0]);
6530
6531+#ifdef CONFIG_GRKERNSEC_SETXID
6532+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6533+ gr_delayed_cred_worker();
6534+#endif
6535+
6536 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
6537 tracehook_report_syscall_entry(regs))
6538 /*
6539@@ -1781,6 +1790,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
6540 {
6541 int step;
6542
6543+#ifdef CONFIG_GRKERNSEC_SETXID
6544+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6545+ gr_delayed_cred_worker();
6546+#endif
6547+
6548 audit_syscall_exit(regs);
6549
6550 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6551diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
6552index 804e323..79181c1 100644
6553--- a/arch/powerpc/kernel/signal_32.c
6554+++ b/arch/powerpc/kernel/signal_32.c
6555@@ -851,7 +851,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
6556 /* Save user registers on the stack */
6557 frame = &rt_sf->uc.uc_mcontext;
6558 addr = frame;
6559- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
6560+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6561 if (save_user_regs(regs, frame, 0, 1))
6562 goto badframe;
6563 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
6564diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
6565index 1ca045d..139c3f7 100644
6566--- a/arch/powerpc/kernel/signal_64.c
6567+++ b/arch/powerpc/kernel/signal_64.c
6568@@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
6569 current->thread.fpscr.val = 0;
6570
6571 /* Set up to return from userspace. */
6572- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
6573+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6574 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
6575 } else {
6576 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
6577diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
6578index 3ce1f86..c30e629 100644
6579--- a/arch/powerpc/kernel/sysfs.c
6580+++ b/arch/powerpc/kernel/sysfs.c
6581@@ -522,7 +522,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
6582 return NOTIFY_OK;
6583 }
6584
6585-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
6586+static struct notifier_block sysfs_cpu_nb = {
6587 .notifier_call = sysfs_cpu_notify,
6588 };
6589
6590diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
6591index 3251840..3f7c77a 100644
6592--- a/arch/powerpc/kernel/traps.c
6593+++ b/arch/powerpc/kernel/traps.c
6594@@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
6595 return flags;
6596 }
6597
6598+extern void gr_handle_kernel_exploit(void);
6599+
6600 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6601 int signr)
6602 {
6603@@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6604 panic("Fatal exception in interrupt");
6605 if (panic_on_oops)
6606 panic("Fatal exception");
6607+
6608+ gr_handle_kernel_exploit();
6609+
6610 do_exit(signr);
6611 }
6612
6613diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
6614index 1b2076f..835e4be 100644
6615--- a/arch/powerpc/kernel/vdso.c
6616+++ b/arch/powerpc/kernel/vdso.c
6617@@ -34,6 +34,7 @@
6618 #include <asm/firmware.h>
6619 #include <asm/vdso.h>
6620 #include <asm/vdso_datapage.h>
6621+#include <asm/mman.h>
6622
6623 #include "setup.h"
6624
6625@@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6626 vdso_base = VDSO32_MBASE;
6627 #endif
6628
6629- current->mm->context.vdso_base = 0;
6630+ current->mm->context.vdso_base = ~0UL;
6631
6632 /* vDSO has a problem and was disabled, just don't "enable" it for the
6633 * process
6634@@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6635 vdso_base = get_unmapped_area(NULL, vdso_base,
6636 (vdso_pages << PAGE_SHIFT) +
6637 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
6638- 0, 0);
6639+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
6640 if (IS_ERR_VALUE(vdso_base)) {
6641 rc = vdso_base;
6642 goto fail_mmapsem;
6643diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
6644index 5eea6f3..5d10396 100644
6645--- a/arch/powerpc/lib/usercopy_64.c
6646+++ b/arch/powerpc/lib/usercopy_64.c
6647@@ -9,22 +9,6 @@
6648 #include <linux/module.h>
6649 #include <asm/uaccess.h>
6650
6651-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
6652-{
6653- if (likely(access_ok(VERIFY_READ, from, n)))
6654- n = __copy_from_user(to, from, n);
6655- else
6656- memset(to, 0, n);
6657- return n;
6658-}
6659-
6660-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
6661-{
6662- if (likely(access_ok(VERIFY_WRITE, to, n)))
6663- n = __copy_to_user(to, from, n);
6664- return n;
6665-}
6666-
6667 unsigned long copy_in_user(void __user *to, const void __user *from,
6668 unsigned long n)
6669 {
6670@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
6671 return n;
6672 }
6673
6674-EXPORT_SYMBOL(copy_from_user);
6675-EXPORT_SYMBOL(copy_to_user);
6676 EXPORT_SYMBOL(copy_in_user);
6677
6678diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
6679index 3a8489a..6a63b3b 100644
6680--- a/arch/powerpc/mm/fault.c
6681+++ b/arch/powerpc/mm/fault.c
6682@@ -32,6 +32,10 @@
6683 #include <linux/perf_event.h>
6684 #include <linux/magic.h>
6685 #include <linux/ratelimit.h>
6686+#include <linux/slab.h>
6687+#include <linux/pagemap.h>
6688+#include <linux/compiler.h>
6689+#include <linux/unistd.h>
6690
6691 #include <asm/firmware.h>
6692 #include <asm/page.h>
6693@@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
6694 }
6695 #endif
6696
6697+#ifdef CONFIG_PAX_PAGEEXEC
6698+/*
6699+ * PaX: decide what to do with offenders (regs->nip = fault address)
6700+ *
6701+ * returns 1 when task should be killed
6702+ */
6703+static int pax_handle_fetch_fault(struct pt_regs *regs)
6704+{
6705+ return 1;
6706+}
6707+
6708+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6709+{
6710+ unsigned long i;
6711+
6712+ printk(KERN_ERR "PAX: bytes at PC: ");
6713+ for (i = 0; i < 5; i++) {
6714+ unsigned int c;
6715+ if (get_user(c, (unsigned int __user *)pc+i))
6716+ printk(KERN_CONT "???????? ");
6717+ else
6718+ printk(KERN_CONT "%08x ", c);
6719+ }
6720+ printk("\n");
6721+}
6722+#endif
6723+
6724 /*
6725 * Check whether the instruction at regs->nip is a store using
6726 * an update addressing form which will update r1.
6727@@ -213,7 +244,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
6728 * indicate errors in DSISR but can validly be set in SRR1.
6729 */
6730 if (trap == 0x400)
6731- error_code &= 0x48200000;
6732+ error_code &= 0x58200000;
6733 else
6734 is_write = error_code & DSISR_ISSTORE;
6735 #else
6736@@ -364,7 +395,7 @@ good_area:
6737 * "undefined". Of those that can be set, this is the only
6738 * one which seems bad.
6739 */
6740- if (error_code & 0x10000000)
6741+ if (error_code & DSISR_GUARDED)
6742 /* Guarded storage error. */
6743 goto bad_area;
6744 #endif /* CONFIG_8xx */
6745@@ -379,7 +410,7 @@ good_area:
6746 * processors use the same I/D cache coherency mechanism
6747 * as embedded.
6748 */
6749- if (error_code & DSISR_PROTFAULT)
6750+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
6751 goto bad_area;
6752 #endif /* CONFIG_PPC_STD_MMU */
6753
6754@@ -462,6 +493,23 @@ bad_area:
6755 bad_area_nosemaphore:
6756 /* User mode accesses cause a SIGSEGV */
6757 if (user_mode(regs)) {
6758+
6759+#ifdef CONFIG_PAX_PAGEEXEC
6760+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
6761+#ifdef CONFIG_PPC_STD_MMU
6762+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
6763+#else
6764+ if (is_exec && regs->nip == address) {
6765+#endif
6766+ switch (pax_handle_fetch_fault(regs)) {
6767+ }
6768+
6769+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
6770+ do_group_exit(SIGKILL);
6771+ }
6772+ }
6773+#endif
6774+
6775 _exception(SIGSEGV, regs, code, address);
6776 return 0;
6777 }
6778diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
6779index 67a42ed..cd463e0 100644
6780--- a/arch/powerpc/mm/mmap_64.c
6781+++ b/arch/powerpc/mm/mmap_64.c
6782@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
6783 {
6784 unsigned long rnd = 0;
6785
6786+#ifdef CONFIG_PAX_RANDMMAP
6787+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6788+#endif
6789+
6790 if (current->flags & PF_RANDOMIZE) {
6791 /* 8MB for 32bit, 1GB for 64bit */
6792 if (is_32bit_task())
6793@@ -91,10 +95,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6794 */
6795 if (mmap_is_legacy()) {
6796 mm->mmap_base = TASK_UNMAPPED_BASE;
6797+
6798+#ifdef CONFIG_PAX_RANDMMAP
6799+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6800+ mm->mmap_base += mm->delta_mmap;
6801+#endif
6802+
6803 mm->get_unmapped_area = arch_get_unmapped_area;
6804 mm->unmap_area = arch_unmap_area;
6805 } else {
6806 mm->mmap_base = mmap_base();
6807+
6808+#ifdef CONFIG_PAX_RANDMMAP
6809+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6810+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6811+#endif
6812+
6813 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6814 mm->unmap_area = arch_unmap_area_topdown;
6815 }
6816diff --git a/arch/powerpc/mm/mmu_context_nohash.c b/arch/powerpc/mm/mmu_context_nohash.c
6817index e779642..e5bb889 100644
6818--- a/arch/powerpc/mm/mmu_context_nohash.c
6819+++ b/arch/powerpc/mm/mmu_context_nohash.c
6820@@ -363,7 +363,7 @@ static int __cpuinit mmu_context_cpu_notify(struct notifier_block *self,
6821 return NOTIFY_OK;
6822 }
6823
6824-static struct notifier_block __cpuinitdata mmu_context_cpu_nb = {
6825+static struct notifier_block mmu_context_cpu_nb = {
6826 .notifier_call = mmu_context_cpu_notify,
6827 };
6828
6829diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
6830index bba87ca..c346a33 100644
6831--- a/arch/powerpc/mm/numa.c
6832+++ b/arch/powerpc/mm/numa.c
6833@@ -932,7 +932,7 @@ static void __init *careful_zallocation(int nid, unsigned long size,
6834 return ret;
6835 }
6836
6837-static struct notifier_block __cpuinitdata ppc64_numa_nb = {
6838+static struct notifier_block ppc64_numa_nb = {
6839 .notifier_call = cpu_numa_callback,
6840 .priority = 1 /* Must run before sched domains notifier. */
6841 };
6842diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
6843index cf9dada..241529f 100644
6844--- a/arch/powerpc/mm/slice.c
6845+++ b/arch/powerpc/mm/slice.c
6846@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
6847 if ((mm->task_size - len) < addr)
6848 return 0;
6849 vma = find_vma(mm, addr);
6850- return (!vma || (addr + len) <= vma->vm_start);
6851+ return check_heap_stack_gap(vma, addr, len, 0);
6852 }
6853
6854 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
6855@@ -272,7 +272,7 @@ full_search:
6856 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
6857 continue;
6858 }
6859- if (!vma || addr + len <= vma->vm_start) {
6860+ if (check_heap_stack_gap(vma, addr, len, 0)) {
6861 /*
6862 * Remember the place where we stopped the search:
6863 */
6864@@ -329,10 +329,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
6865 }
6866 }
6867
6868- addr = mm->mmap_base;
6869- while (addr > len) {
6870+ if (mm->mmap_base < len)
6871+ addr = -ENOMEM;
6872+ else
6873+ addr = mm->mmap_base - len;
6874+
6875+ while (!IS_ERR_VALUE(addr)) {
6876 /* Go down by chunk size */
6877- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
6878+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
6879
6880 /* Check for hit with different page size */
6881 mask = slice_range_to_mask(addr, len);
6882@@ -352,7 +356,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
6883 * return with success:
6884 */
6885 vma = find_vma(mm, addr);
6886- if (!vma || (addr + len) <= vma->vm_start) {
6887+ if (check_heap_stack_gap(vma, addr, len, 0)) {
6888 /* remember the address as a hint for next time */
6889 if (use_cache)
6890 mm->free_area_cache = addr;
6891@@ -364,7 +368,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
6892 mm->cached_hole_size = vma->vm_start - addr;
6893
6894 /* try just below the current vma->vm_start */
6895- addr = vma->vm_start;
6896+ addr = skip_heap_stack_gap(vma, len, 0);
6897 }
6898
6899 /*
6900@@ -442,6 +446,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
6901 if (fixed && addr > (mm->task_size - len))
6902 return -EINVAL;
6903
6904+#ifdef CONFIG_PAX_RANDMMAP
6905+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
6906+ addr = 0;
6907+#endif
6908+
6909 /* If hint, make sure it matches our alignment restrictions */
6910 if (!fixed && addr) {
6911 addr = _ALIGN_UP(addr, 1ul << pshift);
6912diff --git a/arch/powerpc/platforms/powermac/smp.c b/arch/powerpc/platforms/powermac/smp.c
6913index bdb738a..49c9f95 100644
6914--- a/arch/powerpc/platforms/powermac/smp.c
6915+++ b/arch/powerpc/platforms/powermac/smp.c
6916@@ -885,7 +885,7 @@ static int smp_core99_cpu_notify(struct notifier_block *self,
6917 return NOTIFY_OK;
6918 }
6919
6920-static struct notifier_block __cpuinitdata smp_core99_cpu_nb = {
6921+static struct notifier_block smp_core99_cpu_nb = {
6922 .notifier_call = smp_core99_cpu_notify,
6923 };
6924 #endif /* CONFIG_HOTPLUG_CPU */
6925diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
6926index c797832..ce575c8 100644
6927--- a/arch/s390/include/asm/atomic.h
6928+++ b/arch/s390/include/asm/atomic.h
6929@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
6930 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
6931 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
6932
6933+#define atomic64_read_unchecked(v) atomic64_read(v)
6934+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6935+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6936+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6937+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6938+#define atomic64_inc_unchecked(v) atomic64_inc(v)
6939+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6940+#define atomic64_dec_unchecked(v) atomic64_dec(v)
6941+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6942+
6943 #define smp_mb__before_atomic_dec() smp_mb()
6944 #define smp_mb__after_atomic_dec() smp_mb()
6945 #define smp_mb__before_atomic_inc() smp_mb()
6946diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
6947index 4d7ccac..d03d0ad 100644
6948--- a/arch/s390/include/asm/cache.h
6949+++ b/arch/s390/include/asm/cache.h
6950@@ -9,8 +9,10 @@
6951 #ifndef __ARCH_S390_CACHE_H
6952 #define __ARCH_S390_CACHE_H
6953
6954-#define L1_CACHE_BYTES 256
6955+#include <linux/const.h>
6956+
6957 #define L1_CACHE_SHIFT 8
6958+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6959 #define NET_SKB_PAD 32
6960
6961 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
6962diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
6963index 178ff96..8c93bd1 100644
6964--- a/arch/s390/include/asm/elf.h
6965+++ b/arch/s390/include/asm/elf.h
6966@@ -160,8 +160,14 @@ extern unsigned int vdso_enabled;
6967 the loader. We need to make sure that it is out of the way of the program
6968 that it will "exec", and that there is sufficient room for the brk. */
6969
6970-extern unsigned long randomize_et_dyn(unsigned long base);
6971-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
6972+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
6973+
6974+#ifdef CONFIG_PAX_ASLR
6975+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
6976+
6977+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
6978+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
6979+#endif
6980
6981 /* This yields a mask that user programs can use to figure out what
6982 instruction set this CPU supports. */
6983@@ -210,9 +216,6 @@ struct linux_binprm;
6984 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6985 int arch_setup_additional_pages(struct linux_binprm *, int);
6986
6987-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6988-#define arch_randomize_brk arch_randomize_brk
6989-
6990 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
6991
6992 #endif
6993diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
6994index c4a93d6..4d2a9b4 100644
6995--- a/arch/s390/include/asm/exec.h
6996+++ b/arch/s390/include/asm/exec.h
6997@@ -7,6 +7,6 @@
6998 #ifndef __ASM_EXEC_H
6999 #define __ASM_EXEC_H
7000
7001-extern unsigned long arch_align_stack(unsigned long sp);
7002+#define arch_align_stack(x) ((x) & ~0xfUL)
7003
7004 #endif /* __ASM_EXEC_H */
7005diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
7006index 34268df..ea97318 100644
7007--- a/arch/s390/include/asm/uaccess.h
7008+++ b/arch/s390/include/asm/uaccess.h
7009@@ -252,6 +252,10 @@ static inline unsigned long __must_check
7010 copy_to_user(void __user *to, const void *from, unsigned long n)
7011 {
7012 might_fault();
7013+
7014+ if ((long)n < 0)
7015+ return n;
7016+
7017 if (access_ok(VERIFY_WRITE, to, n))
7018 n = __copy_to_user(to, from, n);
7019 return n;
7020@@ -277,6 +281,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
7021 static inline unsigned long __must_check
7022 __copy_from_user(void *to, const void __user *from, unsigned long n)
7023 {
7024+ if ((long)n < 0)
7025+ return n;
7026+
7027 if (__builtin_constant_p(n) && (n <= 256))
7028 return uaccess.copy_from_user_small(n, from, to);
7029 else
7030@@ -308,10 +315,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
7031 static inline unsigned long __must_check
7032 copy_from_user(void *to, const void __user *from, unsigned long n)
7033 {
7034- unsigned int sz = __compiletime_object_size(to);
7035+ size_t sz = __compiletime_object_size(to);
7036
7037 might_fault();
7038- if (unlikely(sz != -1 && sz < n)) {
7039+
7040+ if ((long)n < 0)
7041+ return n;
7042+
7043+ if (unlikely(sz != (size_t)-1 && sz < n)) {
7044 copy_from_user_overflow();
7045 return n;
7046 }
7047diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
7048index 4610dea..cf0af21 100644
7049--- a/arch/s390/kernel/module.c
7050+++ b/arch/s390/kernel/module.c
7051@@ -171,11 +171,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
7052
7053 /* Increase core size by size of got & plt and set start
7054 offsets for got and plt. */
7055- me->core_size = ALIGN(me->core_size, 4);
7056- me->arch.got_offset = me->core_size;
7057- me->core_size += me->arch.got_size;
7058- me->arch.plt_offset = me->core_size;
7059- me->core_size += me->arch.plt_size;
7060+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
7061+ me->arch.got_offset = me->core_size_rw;
7062+ me->core_size_rw += me->arch.got_size;
7063+ me->arch.plt_offset = me->core_size_rx;
7064+ me->core_size_rx += me->arch.plt_size;
7065 return 0;
7066 }
7067
7068@@ -252,7 +252,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7069 if (info->got_initialized == 0) {
7070 Elf_Addr *gotent;
7071
7072- gotent = me->module_core + me->arch.got_offset +
7073+ gotent = me->module_core_rw + me->arch.got_offset +
7074 info->got_offset;
7075 *gotent = val;
7076 info->got_initialized = 1;
7077@@ -276,7 +276,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7078 else if (r_type == R_390_GOTENT ||
7079 r_type == R_390_GOTPLTENT)
7080 *(unsigned int *) loc =
7081- (val + (Elf_Addr) me->module_core - loc) >> 1;
7082+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
7083 else if (r_type == R_390_GOT64 ||
7084 r_type == R_390_GOTPLT64)
7085 *(unsigned long *) loc = val;
7086@@ -290,7 +290,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7087 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
7088 if (info->plt_initialized == 0) {
7089 unsigned int *ip;
7090- ip = me->module_core + me->arch.plt_offset +
7091+ ip = me->module_core_rx + me->arch.plt_offset +
7092 info->plt_offset;
7093 #ifndef CONFIG_64BIT
7094 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
7095@@ -315,7 +315,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7096 val - loc + 0xffffUL < 0x1ffffeUL) ||
7097 (r_type == R_390_PLT32DBL &&
7098 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
7099- val = (Elf_Addr) me->module_core +
7100+ val = (Elf_Addr) me->module_core_rx +
7101 me->arch.plt_offset +
7102 info->plt_offset;
7103 val += rela->r_addend - loc;
7104@@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7105 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
7106 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
7107 val = val + rela->r_addend -
7108- ((Elf_Addr) me->module_core + me->arch.got_offset);
7109+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
7110 if (r_type == R_390_GOTOFF16)
7111 *(unsigned short *) loc = val;
7112 else if (r_type == R_390_GOTOFF32)
7113@@ -347,7 +347,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7114 break;
7115 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
7116 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
7117- val = (Elf_Addr) me->module_core + me->arch.got_offset +
7118+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
7119 rela->r_addend - loc;
7120 if (r_type == R_390_GOTPC)
7121 *(unsigned int *) loc = val;
7122diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
7123index 536d645..4a5bd9e 100644
7124--- a/arch/s390/kernel/process.c
7125+++ b/arch/s390/kernel/process.c
7126@@ -250,39 +250,3 @@ unsigned long get_wchan(struct task_struct *p)
7127 }
7128 return 0;
7129 }
7130-
7131-unsigned long arch_align_stack(unsigned long sp)
7132-{
7133- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7134- sp -= get_random_int() & ~PAGE_MASK;
7135- return sp & ~0xf;
7136-}
7137-
7138-static inline unsigned long brk_rnd(void)
7139-{
7140- /* 8MB for 32bit, 1GB for 64bit */
7141- if (is_32bit_task())
7142- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
7143- else
7144- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
7145-}
7146-
7147-unsigned long arch_randomize_brk(struct mm_struct *mm)
7148-{
7149- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
7150-
7151- if (ret < mm->brk)
7152- return mm->brk;
7153- return ret;
7154-}
7155-
7156-unsigned long randomize_et_dyn(unsigned long base)
7157-{
7158- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
7159-
7160- if (!(current->flags & PF_RANDOMIZE))
7161- return base;
7162- if (ret < base)
7163- return base;
7164- return ret;
7165-}
7166diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
7167index c59a5ef..3fae59c 100644
7168--- a/arch/s390/mm/mmap.c
7169+++ b/arch/s390/mm/mmap.c
7170@@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7171 */
7172 if (mmap_is_legacy()) {
7173 mm->mmap_base = TASK_UNMAPPED_BASE;
7174+
7175+#ifdef CONFIG_PAX_RANDMMAP
7176+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7177+ mm->mmap_base += mm->delta_mmap;
7178+#endif
7179+
7180 mm->get_unmapped_area = arch_get_unmapped_area;
7181 mm->unmap_area = arch_unmap_area;
7182 } else {
7183 mm->mmap_base = mmap_base();
7184+
7185+#ifdef CONFIG_PAX_RANDMMAP
7186+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7187+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7188+#endif
7189+
7190 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7191 mm->unmap_area = arch_unmap_area_topdown;
7192 }
7193@@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7194 */
7195 if (mmap_is_legacy()) {
7196 mm->mmap_base = TASK_UNMAPPED_BASE;
7197+
7198+#ifdef CONFIG_PAX_RANDMMAP
7199+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7200+ mm->mmap_base += mm->delta_mmap;
7201+#endif
7202+
7203 mm->get_unmapped_area = s390_get_unmapped_area;
7204 mm->unmap_area = arch_unmap_area;
7205 } else {
7206 mm->mmap_base = mmap_base();
7207+
7208+#ifdef CONFIG_PAX_RANDMMAP
7209+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7210+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7211+#endif
7212+
7213 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
7214 mm->unmap_area = arch_unmap_area_topdown;
7215 }
7216diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
7217index ae3d59f..f65f075 100644
7218--- a/arch/score/include/asm/cache.h
7219+++ b/arch/score/include/asm/cache.h
7220@@ -1,7 +1,9 @@
7221 #ifndef _ASM_SCORE_CACHE_H
7222 #define _ASM_SCORE_CACHE_H
7223
7224+#include <linux/const.h>
7225+
7226 #define L1_CACHE_SHIFT 4
7227-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7228+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7229
7230 #endif /* _ASM_SCORE_CACHE_H */
7231diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
7232index f9f3cd5..58ff438 100644
7233--- a/arch/score/include/asm/exec.h
7234+++ b/arch/score/include/asm/exec.h
7235@@ -1,6 +1,6 @@
7236 #ifndef _ASM_SCORE_EXEC_H
7237 #define _ASM_SCORE_EXEC_H
7238
7239-extern unsigned long arch_align_stack(unsigned long sp);
7240+#define arch_align_stack(x) (x)
7241
7242 #endif /* _ASM_SCORE_EXEC_H */
7243diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
7244index 7956846..5f37677 100644
7245--- a/arch/score/kernel/process.c
7246+++ b/arch/score/kernel/process.c
7247@@ -134,8 +134,3 @@ unsigned long get_wchan(struct task_struct *task)
7248
7249 return task_pt_regs(task)->cp0_epc;
7250 }
7251-
7252-unsigned long arch_align_stack(unsigned long sp)
7253-{
7254- return sp;
7255-}
7256diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
7257index ef9e555..331bd29 100644
7258--- a/arch/sh/include/asm/cache.h
7259+++ b/arch/sh/include/asm/cache.h
7260@@ -9,10 +9,11 @@
7261 #define __ASM_SH_CACHE_H
7262 #ifdef __KERNEL__
7263
7264+#include <linux/const.h>
7265 #include <linux/init.h>
7266 #include <cpu/cache.h>
7267
7268-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7269+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7270
7271 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7272
7273diff --git a/arch/sh/kernel/cpu/sh4a/smp-shx3.c b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7274index 03f2b55..b027032 100644
7275--- a/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7276+++ b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7277@@ -143,7 +143,7 @@ shx3_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
7278 return NOTIFY_OK;
7279 }
7280
7281-static struct notifier_block __cpuinitdata shx3_cpu_notifier = {
7282+static struct notifier_block shx3_cpu_notifier = {
7283 .notifier_call = shx3_cpu_callback,
7284 };
7285
7286diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
7287index 6777177..cb5e44f 100644
7288--- a/arch/sh/mm/mmap.c
7289+++ b/arch/sh/mm/mmap.c
7290@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7291 struct mm_struct *mm = current->mm;
7292 struct vm_area_struct *vma;
7293 int do_colour_align;
7294+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7295 struct vm_unmapped_area_info info;
7296
7297 if (flags & MAP_FIXED) {
7298@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7299 if (filp || (flags & MAP_SHARED))
7300 do_colour_align = 1;
7301
7302+#ifdef CONFIG_PAX_RANDMMAP
7303+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7304+#endif
7305+
7306 if (addr) {
7307 if (do_colour_align)
7308 addr = COLOUR_ALIGN(addr, pgoff);
7309@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7310 addr = PAGE_ALIGN(addr);
7311
7312 vma = find_vma(mm, addr);
7313- if (TASK_SIZE - len >= addr &&
7314- (!vma || addr + len <= vma->vm_start))
7315+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7316 return addr;
7317 }
7318
7319 info.flags = 0;
7320 info.length = len;
7321- info.low_limit = TASK_UNMAPPED_BASE;
7322+ info.low_limit = mm->mmap_base;
7323 info.high_limit = TASK_SIZE;
7324 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
7325 info.align_offset = pgoff << PAGE_SHIFT;
7326@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7327 struct mm_struct *mm = current->mm;
7328 unsigned long addr = addr0;
7329 int do_colour_align;
7330+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7331 struct vm_unmapped_area_info info;
7332
7333 if (flags & MAP_FIXED) {
7334@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7335 if (filp || (flags & MAP_SHARED))
7336 do_colour_align = 1;
7337
7338+#ifdef CONFIG_PAX_RANDMMAP
7339+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7340+#endif
7341+
7342 /* requesting a specific address */
7343 if (addr) {
7344 if (do_colour_align)
7345@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7346 addr = PAGE_ALIGN(addr);
7347
7348 vma = find_vma(mm, addr);
7349- if (TASK_SIZE - len >= addr &&
7350- (!vma || addr + len <= vma->vm_start))
7351+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7352 return addr;
7353 }
7354
7355@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7356 VM_BUG_ON(addr != -ENOMEM);
7357 info.flags = 0;
7358 info.low_limit = TASK_UNMAPPED_BASE;
7359+
7360+#ifdef CONFIG_PAX_RANDMMAP
7361+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7362+ info.low_limit += mm->delta_mmap;
7363+#endif
7364+
7365 info.high_limit = TASK_SIZE;
7366 addr = vm_unmapped_area(&info);
7367 }
7368diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
7369index be56a24..443328f 100644
7370--- a/arch/sparc/include/asm/atomic_64.h
7371+++ b/arch/sparc/include/asm/atomic_64.h
7372@@ -14,18 +14,40 @@
7373 #define ATOMIC64_INIT(i) { (i) }
7374
7375 #define atomic_read(v) (*(volatile int *)&(v)->counter)
7376+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
7377+{
7378+ return v->counter;
7379+}
7380 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
7381+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
7382+{
7383+ return v->counter;
7384+}
7385
7386 #define atomic_set(v, i) (((v)->counter) = i)
7387+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7388+{
7389+ v->counter = i;
7390+}
7391 #define atomic64_set(v, i) (((v)->counter) = i)
7392+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
7393+{
7394+ v->counter = i;
7395+}
7396
7397 extern void atomic_add(int, atomic_t *);
7398+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
7399 extern void atomic64_add(long, atomic64_t *);
7400+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
7401 extern void atomic_sub(int, atomic_t *);
7402+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
7403 extern void atomic64_sub(long, atomic64_t *);
7404+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
7405
7406 extern int atomic_add_ret(int, atomic_t *);
7407+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
7408 extern long atomic64_add_ret(long, atomic64_t *);
7409+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
7410 extern int atomic_sub_ret(int, atomic_t *);
7411 extern long atomic64_sub_ret(long, atomic64_t *);
7412
7413@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7414 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
7415
7416 #define atomic_inc_return(v) atomic_add_ret(1, v)
7417+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7418+{
7419+ return atomic_add_ret_unchecked(1, v);
7420+}
7421 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
7422+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
7423+{
7424+ return atomic64_add_ret_unchecked(1, v);
7425+}
7426
7427 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
7428 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
7429
7430 #define atomic_add_return(i, v) atomic_add_ret(i, v)
7431+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
7432+{
7433+ return atomic_add_ret_unchecked(i, v);
7434+}
7435 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
7436+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
7437+{
7438+ return atomic64_add_ret_unchecked(i, v);
7439+}
7440
7441 /*
7442 * atomic_inc_and_test - increment and test
7443@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7444 * other cases.
7445 */
7446 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
7447+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7448+{
7449+ return atomic_inc_return_unchecked(v) == 0;
7450+}
7451 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
7452
7453 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
7454@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7455 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
7456
7457 #define atomic_inc(v) atomic_add(1, v)
7458+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7459+{
7460+ atomic_add_unchecked(1, v);
7461+}
7462 #define atomic64_inc(v) atomic64_add(1, v)
7463+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
7464+{
7465+ atomic64_add_unchecked(1, v);
7466+}
7467
7468 #define atomic_dec(v) atomic_sub(1, v)
7469+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
7470+{
7471+ atomic_sub_unchecked(1, v);
7472+}
7473 #define atomic64_dec(v) atomic64_sub(1, v)
7474+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
7475+{
7476+ atomic64_sub_unchecked(1, v);
7477+}
7478
7479 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
7480 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
7481
7482 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
7483+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7484+{
7485+ return cmpxchg(&v->counter, old, new);
7486+}
7487 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
7488+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7489+{
7490+ return xchg(&v->counter, new);
7491+}
7492
7493 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7494 {
7495- int c, old;
7496+ int c, old, new;
7497 c = atomic_read(v);
7498 for (;;) {
7499- if (unlikely(c == (u)))
7500+ if (unlikely(c == u))
7501 break;
7502- old = atomic_cmpxchg((v), c, c + (a));
7503+
7504+ asm volatile("addcc %2, %0, %0\n"
7505+
7506+#ifdef CONFIG_PAX_REFCOUNT
7507+ "tvs %%icc, 6\n"
7508+#endif
7509+
7510+ : "=r" (new)
7511+ : "0" (c), "ir" (a)
7512+ : "cc");
7513+
7514+ old = atomic_cmpxchg(v, c, new);
7515 if (likely(old == c))
7516 break;
7517 c = old;
7518@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7519 #define atomic64_cmpxchg(v, o, n) \
7520 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
7521 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
7522+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
7523+{
7524+ return xchg(&v->counter, new);
7525+}
7526
7527 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7528 {
7529- long c, old;
7530+ long c, old, new;
7531 c = atomic64_read(v);
7532 for (;;) {
7533- if (unlikely(c == (u)))
7534+ if (unlikely(c == u))
7535 break;
7536- old = atomic64_cmpxchg((v), c, c + (a));
7537+
7538+ asm volatile("addcc %2, %0, %0\n"
7539+
7540+#ifdef CONFIG_PAX_REFCOUNT
7541+ "tvs %%xcc, 6\n"
7542+#endif
7543+
7544+ : "=r" (new)
7545+ : "0" (c), "ir" (a)
7546+ : "cc");
7547+
7548+ old = atomic64_cmpxchg(v, c, new);
7549 if (likely(old == c))
7550 break;
7551 c = old;
7552 }
7553- return c != (u);
7554+ return c != u;
7555 }
7556
7557 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7558diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
7559index 5bb6991..5c2132e 100644
7560--- a/arch/sparc/include/asm/cache.h
7561+++ b/arch/sparc/include/asm/cache.h
7562@@ -7,10 +7,12 @@
7563 #ifndef _SPARC_CACHE_H
7564 #define _SPARC_CACHE_H
7565
7566+#include <linux/const.h>
7567+
7568 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
7569
7570 #define L1_CACHE_SHIFT 5
7571-#define L1_CACHE_BYTES 32
7572+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7573
7574 #ifdef CONFIG_SPARC32
7575 #define SMP_CACHE_BYTES_SHIFT 5
7576diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
7577index ac74a2c..a9e58af 100644
7578--- a/arch/sparc/include/asm/elf_32.h
7579+++ b/arch/sparc/include/asm/elf_32.h
7580@@ -114,6 +114,13 @@ typedef struct {
7581
7582 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
7583
7584+#ifdef CONFIG_PAX_ASLR
7585+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7586+
7587+#define PAX_DELTA_MMAP_LEN 16
7588+#define PAX_DELTA_STACK_LEN 16
7589+#endif
7590+
7591 /* This yields a mask that user programs can use to figure out what
7592 instruction set this cpu supports. This can NOT be done in userspace
7593 on Sparc. */
7594diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
7595index 370ca1e..d4f4a98 100644
7596--- a/arch/sparc/include/asm/elf_64.h
7597+++ b/arch/sparc/include/asm/elf_64.h
7598@@ -189,6 +189,13 @@ typedef struct {
7599 #define ELF_ET_DYN_BASE 0x0000010000000000UL
7600 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
7601
7602+#ifdef CONFIG_PAX_ASLR
7603+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
7604+
7605+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
7606+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
7607+#endif
7608+
7609 extern unsigned long sparc64_elf_hwcap;
7610 #define ELF_HWCAP sparc64_elf_hwcap
7611
7612diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
7613index 9b1c36d..209298b 100644
7614--- a/arch/sparc/include/asm/pgalloc_32.h
7615+++ b/arch/sparc/include/asm/pgalloc_32.h
7616@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
7617 }
7618
7619 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
7620+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
7621
7622 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
7623 unsigned long address)
7624diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
7625index bcfe063..b333142 100644
7626--- a/arch/sparc/include/asm/pgalloc_64.h
7627+++ b/arch/sparc/include/asm/pgalloc_64.h
7628@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7629 }
7630
7631 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
7632+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
7633
7634 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
7635 {
7636diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
7637index 6fc1348..390c50a 100644
7638--- a/arch/sparc/include/asm/pgtable_32.h
7639+++ b/arch/sparc/include/asm/pgtable_32.h
7640@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
7641 #define PAGE_SHARED SRMMU_PAGE_SHARED
7642 #define PAGE_COPY SRMMU_PAGE_COPY
7643 #define PAGE_READONLY SRMMU_PAGE_RDONLY
7644+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
7645+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
7646+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
7647 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
7648
7649 /* Top-level page directory - dummy used by init-mm.
7650@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
7651
7652 /* xwr */
7653 #define __P000 PAGE_NONE
7654-#define __P001 PAGE_READONLY
7655-#define __P010 PAGE_COPY
7656-#define __P011 PAGE_COPY
7657+#define __P001 PAGE_READONLY_NOEXEC
7658+#define __P010 PAGE_COPY_NOEXEC
7659+#define __P011 PAGE_COPY_NOEXEC
7660 #define __P100 PAGE_READONLY
7661 #define __P101 PAGE_READONLY
7662 #define __P110 PAGE_COPY
7663 #define __P111 PAGE_COPY
7664
7665 #define __S000 PAGE_NONE
7666-#define __S001 PAGE_READONLY
7667-#define __S010 PAGE_SHARED
7668-#define __S011 PAGE_SHARED
7669+#define __S001 PAGE_READONLY_NOEXEC
7670+#define __S010 PAGE_SHARED_NOEXEC
7671+#define __S011 PAGE_SHARED_NOEXEC
7672 #define __S100 PAGE_READONLY
7673 #define __S101 PAGE_READONLY
7674 #define __S110 PAGE_SHARED
7675diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
7676index 79da178..c2eede8 100644
7677--- a/arch/sparc/include/asm/pgtsrmmu.h
7678+++ b/arch/sparc/include/asm/pgtsrmmu.h
7679@@ -115,6 +115,11 @@
7680 SRMMU_EXEC | SRMMU_REF)
7681 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
7682 SRMMU_EXEC | SRMMU_REF)
7683+
7684+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
7685+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7686+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7687+
7688 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
7689 SRMMU_DIRTY | SRMMU_REF)
7690
7691diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
7692index 9689176..63c18ea 100644
7693--- a/arch/sparc/include/asm/spinlock_64.h
7694+++ b/arch/sparc/include/asm/spinlock_64.h
7695@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
7696
7697 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
7698
7699-static void inline arch_read_lock(arch_rwlock_t *lock)
7700+static inline void arch_read_lock(arch_rwlock_t *lock)
7701 {
7702 unsigned long tmp1, tmp2;
7703
7704 __asm__ __volatile__ (
7705 "1: ldsw [%2], %0\n"
7706 " brlz,pn %0, 2f\n"
7707-"4: add %0, 1, %1\n"
7708+"4: addcc %0, 1, %1\n"
7709+
7710+#ifdef CONFIG_PAX_REFCOUNT
7711+" tvs %%icc, 6\n"
7712+#endif
7713+
7714 " cas [%2], %0, %1\n"
7715 " cmp %0, %1\n"
7716 " bne,pn %%icc, 1b\n"
7717@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
7718 " .previous"
7719 : "=&r" (tmp1), "=&r" (tmp2)
7720 : "r" (lock)
7721- : "memory");
7722+ : "memory", "cc");
7723 }
7724
7725-static int inline arch_read_trylock(arch_rwlock_t *lock)
7726+static inline int arch_read_trylock(arch_rwlock_t *lock)
7727 {
7728 int tmp1, tmp2;
7729
7730@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
7731 "1: ldsw [%2], %0\n"
7732 " brlz,a,pn %0, 2f\n"
7733 " mov 0, %0\n"
7734-" add %0, 1, %1\n"
7735+" addcc %0, 1, %1\n"
7736+
7737+#ifdef CONFIG_PAX_REFCOUNT
7738+" tvs %%icc, 6\n"
7739+#endif
7740+
7741 " cas [%2], %0, %1\n"
7742 " cmp %0, %1\n"
7743 " bne,pn %%icc, 1b\n"
7744@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
7745 return tmp1;
7746 }
7747
7748-static void inline arch_read_unlock(arch_rwlock_t *lock)
7749+static inline void arch_read_unlock(arch_rwlock_t *lock)
7750 {
7751 unsigned long tmp1, tmp2;
7752
7753 __asm__ __volatile__(
7754 "1: lduw [%2], %0\n"
7755-" sub %0, 1, %1\n"
7756+" subcc %0, 1, %1\n"
7757+
7758+#ifdef CONFIG_PAX_REFCOUNT
7759+" tvs %%icc, 6\n"
7760+#endif
7761+
7762 " cas [%2], %0, %1\n"
7763 " cmp %0, %1\n"
7764 " bne,pn %%xcc, 1b\n"
7765@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
7766 : "memory");
7767 }
7768
7769-static void inline arch_write_lock(arch_rwlock_t *lock)
7770+static inline void arch_write_lock(arch_rwlock_t *lock)
7771 {
7772 unsigned long mask, tmp1, tmp2;
7773
7774@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
7775 : "memory");
7776 }
7777
7778-static void inline arch_write_unlock(arch_rwlock_t *lock)
7779+static inline void arch_write_unlock(arch_rwlock_t *lock)
7780 {
7781 __asm__ __volatile__(
7782 " stw %%g0, [%0]"
7783@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
7784 : "memory");
7785 }
7786
7787-static int inline arch_write_trylock(arch_rwlock_t *lock)
7788+static inline int arch_write_trylock(arch_rwlock_t *lock)
7789 {
7790 unsigned long mask, tmp1, tmp2, result;
7791
7792diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
7793index 25849ae..924c54b 100644
7794--- a/arch/sparc/include/asm/thread_info_32.h
7795+++ b/arch/sparc/include/asm/thread_info_32.h
7796@@ -49,6 +49,8 @@ struct thread_info {
7797 unsigned long w_saved;
7798
7799 struct restart_block restart_block;
7800+
7801+ unsigned long lowest_stack;
7802 };
7803
7804 /*
7805diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
7806index 269bd92..e46a9b8 100644
7807--- a/arch/sparc/include/asm/thread_info_64.h
7808+++ b/arch/sparc/include/asm/thread_info_64.h
7809@@ -63,6 +63,8 @@ struct thread_info {
7810 struct pt_regs *kern_una_regs;
7811 unsigned int kern_una_insn;
7812
7813+ unsigned long lowest_stack;
7814+
7815 unsigned long fpregs[0] __attribute__ ((aligned(64)));
7816 };
7817
7818@@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
7819 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
7820 /* flag bit 6 is available */
7821 #define TIF_32BIT 7 /* 32-bit binary */
7822-/* flag bit 8 is available */
7823+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
7824 #define TIF_SECCOMP 9 /* secure computing */
7825 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
7826 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
7827+
7828 /* NOTE: Thread flags >= 12 should be ones we have no interest
7829 * in using in assembly, else we can't use the mask as
7830 * an immediate value in instructions such as andcc.
7831@@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
7832 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
7833 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
7834 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
7835+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
7836
7837 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
7838 _TIF_DO_NOTIFY_RESUME_MASK | \
7839 _TIF_NEED_RESCHED)
7840 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
7841
7842+#define _TIF_WORK_SYSCALL \
7843+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
7844+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
7845+
7846+
7847 /*
7848 * Thread-synchronous status.
7849 *
7850diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
7851index 0167d26..9acd8ed 100644
7852--- a/arch/sparc/include/asm/uaccess.h
7853+++ b/arch/sparc/include/asm/uaccess.h
7854@@ -1,5 +1,13 @@
7855 #ifndef ___ASM_SPARC_UACCESS_H
7856 #define ___ASM_SPARC_UACCESS_H
7857+
7858+#ifdef __KERNEL__
7859+#ifndef __ASSEMBLY__
7860+#include <linux/types.h>
7861+extern void check_object_size(const void *ptr, unsigned long n, bool to);
7862+#endif
7863+#endif
7864+
7865 #if defined(__sparc__) && defined(__arch64__)
7866 #include <asm/uaccess_64.h>
7867 #else
7868diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
7869index 53a28dd..50c38c3 100644
7870--- a/arch/sparc/include/asm/uaccess_32.h
7871+++ b/arch/sparc/include/asm/uaccess_32.h
7872@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
7873
7874 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
7875 {
7876- if (n && __access_ok((unsigned long) to, n))
7877+ if ((long)n < 0)
7878+ return n;
7879+
7880+ if (n && __access_ok((unsigned long) to, n)) {
7881+ if (!__builtin_constant_p(n))
7882+ check_object_size(from, n, true);
7883 return __copy_user(to, (__force void __user *) from, n);
7884- else
7885+ } else
7886 return n;
7887 }
7888
7889 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
7890 {
7891+ if ((long)n < 0)
7892+ return n;
7893+
7894+ if (!__builtin_constant_p(n))
7895+ check_object_size(from, n, true);
7896+
7897 return __copy_user(to, (__force void __user *) from, n);
7898 }
7899
7900 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
7901 {
7902- if (n && __access_ok((unsigned long) from, n))
7903+ if ((long)n < 0)
7904+ return n;
7905+
7906+ if (n && __access_ok((unsigned long) from, n)) {
7907+ if (!__builtin_constant_p(n))
7908+ check_object_size(to, n, false);
7909 return __copy_user((__force void __user *) to, from, n);
7910- else
7911+ } else
7912 return n;
7913 }
7914
7915 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
7916 {
7917+ if ((long)n < 0)
7918+ return n;
7919+
7920 return __copy_user((__force void __user *) to, from, n);
7921 }
7922
7923diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
7924index e562d3c..191f176 100644
7925--- a/arch/sparc/include/asm/uaccess_64.h
7926+++ b/arch/sparc/include/asm/uaccess_64.h
7927@@ -10,6 +10,7 @@
7928 #include <linux/compiler.h>
7929 #include <linux/string.h>
7930 #include <linux/thread_info.h>
7931+#include <linux/kernel.h>
7932 #include <asm/asi.h>
7933 #include <asm/spitfire.h>
7934 #include <asm-generic/uaccess-unaligned.h>
7935@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
7936 static inline unsigned long __must_check
7937 copy_from_user(void *to, const void __user *from, unsigned long size)
7938 {
7939- unsigned long ret = ___copy_from_user(to, from, size);
7940+ unsigned long ret;
7941
7942+ if ((long)size < 0 || size > INT_MAX)
7943+ return size;
7944+
7945+ if (!__builtin_constant_p(size))
7946+ check_object_size(to, size, false);
7947+
7948+ ret = ___copy_from_user(to, from, size);
7949 if (unlikely(ret))
7950 ret = copy_from_user_fixup(to, from, size);
7951
7952@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
7953 static inline unsigned long __must_check
7954 copy_to_user(void __user *to, const void *from, unsigned long size)
7955 {
7956- unsigned long ret = ___copy_to_user(to, from, size);
7957+ unsigned long ret;
7958
7959+ if ((long)size < 0 || size > INT_MAX)
7960+ return size;
7961+
7962+ if (!__builtin_constant_p(size))
7963+ check_object_size(from, size, true);
7964+
7965+ ret = ___copy_to_user(to, from, size);
7966 if (unlikely(ret))
7967 ret = copy_to_user_fixup(to, from, size);
7968 return ret;
7969diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
7970index 6cf591b..b49e65a 100644
7971--- a/arch/sparc/kernel/Makefile
7972+++ b/arch/sparc/kernel/Makefile
7973@@ -3,7 +3,7 @@
7974 #
7975
7976 asflags-y := -ansi
7977-ccflags-y := -Werror
7978+#ccflags-y := -Werror
7979
7980 extra-y := head_$(BITS).o
7981
7982diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
7983index be8e862..5b50b12 100644
7984--- a/arch/sparc/kernel/process_32.c
7985+++ b/arch/sparc/kernel/process_32.c
7986@@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
7987
7988 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
7989 r->psr, r->pc, r->npc, r->y, print_tainted());
7990- printk("PC: <%pS>\n", (void *) r->pc);
7991+ printk("PC: <%pA>\n", (void *) r->pc);
7992 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
7993 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
7994 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
7995 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
7996 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
7997 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
7998- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
7999+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
8000
8001 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8002 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
8003@@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8004 rw = (struct reg_window32 *) fp;
8005 pc = rw->ins[7];
8006 printk("[%08lx : ", pc);
8007- printk("%pS ] ", (void *) pc);
8008+ printk("%pA ] ", (void *) pc);
8009 fp = rw->ins[6];
8010 } while (++count < 16);
8011 printk("\n");
8012diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
8013index cdb80b2..5ca141d 100644
8014--- a/arch/sparc/kernel/process_64.c
8015+++ b/arch/sparc/kernel/process_64.c
8016@@ -181,14 +181,14 @@ static void show_regwindow(struct pt_regs *regs)
8017 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
8018 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
8019 if (regs->tstate & TSTATE_PRIV)
8020- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
8021+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
8022 }
8023
8024 void show_regs(struct pt_regs *regs)
8025 {
8026 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
8027 regs->tpc, regs->tnpc, regs->y, print_tainted());
8028- printk("TPC: <%pS>\n", (void *) regs->tpc);
8029+ printk("TPC: <%pA>\n", (void *) regs->tpc);
8030 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
8031 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
8032 regs->u_regs[3]);
8033@@ -201,7 +201,7 @@ void show_regs(struct pt_regs *regs)
8034 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
8035 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
8036 regs->u_regs[15]);
8037- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
8038+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
8039 show_regwindow(regs);
8040 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
8041 }
8042@@ -290,7 +290,7 @@ void arch_trigger_all_cpu_backtrace(void)
8043 ((tp && tp->task) ? tp->task->pid : -1));
8044
8045 if (gp->tstate & TSTATE_PRIV) {
8046- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
8047+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
8048 (void *) gp->tpc,
8049 (void *) gp->o7,
8050 (void *) gp->i7,
8051diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
8052index 7ff45e4..a58f271 100644
8053--- a/arch/sparc/kernel/ptrace_64.c
8054+++ b/arch/sparc/kernel/ptrace_64.c
8055@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
8056 return ret;
8057 }
8058
8059+#ifdef CONFIG_GRKERNSEC_SETXID
8060+extern void gr_delayed_cred_worker(void);
8061+#endif
8062+
8063 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8064 {
8065 int ret = 0;
8066@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8067 /* do the secure computing check first */
8068 secure_computing_strict(regs->u_regs[UREG_G1]);
8069
8070+#ifdef CONFIG_GRKERNSEC_SETXID
8071+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8072+ gr_delayed_cred_worker();
8073+#endif
8074+
8075 if (test_thread_flag(TIF_SYSCALL_TRACE))
8076 ret = tracehook_report_syscall_entry(regs);
8077
8078@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8079
8080 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
8081 {
8082+#ifdef CONFIG_GRKERNSEC_SETXID
8083+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8084+ gr_delayed_cred_worker();
8085+#endif
8086+
8087 audit_syscall_exit(regs);
8088
8089 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8090diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
8091index 2da0bdc..79128d2 100644
8092--- a/arch/sparc/kernel/sys_sparc_32.c
8093+++ b/arch/sparc/kernel/sys_sparc_32.c
8094@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8095 if (len > TASK_SIZE - PAGE_SIZE)
8096 return -ENOMEM;
8097 if (!addr)
8098- addr = TASK_UNMAPPED_BASE;
8099+ addr = current->mm->mmap_base;
8100
8101 info.flags = 0;
8102 info.length = len;
8103diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
8104index 708bc29..f0129cb 100644
8105--- a/arch/sparc/kernel/sys_sparc_64.c
8106+++ b/arch/sparc/kernel/sys_sparc_64.c
8107@@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8108 struct vm_area_struct * vma;
8109 unsigned long task_size = TASK_SIZE;
8110 int do_color_align;
8111+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8112 struct vm_unmapped_area_info info;
8113
8114 if (flags & MAP_FIXED) {
8115 /* We do not accept a shared mapping if it would violate
8116 * cache aliasing constraints.
8117 */
8118- if ((flags & MAP_SHARED) &&
8119+ if ((filp || (flags & MAP_SHARED)) &&
8120 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8121 return -EINVAL;
8122 return addr;
8123@@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8124 if (filp || (flags & MAP_SHARED))
8125 do_color_align = 1;
8126
8127+#ifdef CONFIG_PAX_RANDMMAP
8128+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8129+#endif
8130+
8131 if (addr) {
8132 if (do_color_align)
8133 addr = COLOR_ALIGN(addr, pgoff);
8134@@ -118,14 +123,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8135 addr = PAGE_ALIGN(addr);
8136
8137 vma = find_vma(mm, addr);
8138- if (task_size - len >= addr &&
8139- (!vma || addr + len <= vma->vm_start))
8140+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8141 return addr;
8142 }
8143
8144 info.flags = 0;
8145 info.length = len;
8146- info.low_limit = TASK_UNMAPPED_BASE;
8147+ info.low_limit = mm->mmap_base;
8148 info.high_limit = min(task_size, VA_EXCLUDE_START);
8149 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
8150 info.align_offset = pgoff << PAGE_SHIFT;
8151@@ -134,6 +138,12 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8152 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
8153 VM_BUG_ON(addr != -ENOMEM);
8154 info.low_limit = VA_EXCLUDE_END;
8155+
8156+#ifdef CONFIG_PAX_RANDMMAP
8157+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8158+ info.low_limit += mm->delta_mmap;
8159+#endif
8160+
8161 info.high_limit = task_size;
8162 addr = vm_unmapped_area(&info);
8163 }
8164@@ -151,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8165 unsigned long task_size = STACK_TOP32;
8166 unsigned long addr = addr0;
8167 int do_color_align;
8168+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8169 struct vm_unmapped_area_info info;
8170
8171 /* This should only ever run for 32-bit processes. */
8172@@ -160,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8173 /* We do not accept a shared mapping if it would violate
8174 * cache aliasing constraints.
8175 */
8176- if ((flags & MAP_SHARED) &&
8177+ if ((filp || (flags & MAP_SHARED)) &&
8178 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8179 return -EINVAL;
8180 return addr;
8181@@ -173,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8182 if (filp || (flags & MAP_SHARED))
8183 do_color_align = 1;
8184
8185+#ifdef CONFIG_PAX_RANDMMAP
8186+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8187+#endif
8188+
8189 /* requesting a specific address */
8190 if (addr) {
8191 if (do_color_align)
8192@@ -181,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8193 addr = PAGE_ALIGN(addr);
8194
8195 vma = find_vma(mm, addr);
8196- if (task_size - len >= addr &&
8197- (!vma || addr + len <= vma->vm_start))
8198+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8199 return addr;
8200 }
8201
8202@@ -204,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8203 VM_BUG_ON(addr != -ENOMEM);
8204 info.flags = 0;
8205 info.low_limit = TASK_UNMAPPED_BASE;
8206+
8207+#ifdef CONFIG_PAX_RANDMMAP
8208+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8209+ info.low_limit += mm->delta_mmap;
8210+#endif
8211+
8212 info.high_limit = STACK_TOP32;
8213 addr = vm_unmapped_area(&info);
8214 }
8215@@ -264,6 +284,10 @@ static unsigned long mmap_rnd(void)
8216 {
8217 unsigned long rnd = 0UL;
8218
8219+#ifdef CONFIG_PAX_RANDMMAP
8220+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8221+#endif
8222+
8223 if (current->flags & PF_RANDOMIZE) {
8224 unsigned long val = get_random_int();
8225 if (test_thread_flag(TIF_32BIT))
8226@@ -289,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8227 gap == RLIM_INFINITY ||
8228 sysctl_legacy_va_layout) {
8229 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
8230+
8231+#ifdef CONFIG_PAX_RANDMMAP
8232+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8233+ mm->mmap_base += mm->delta_mmap;
8234+#endif
8235+
8236 mm->get_unmapped_area = arch_get_unmapped_area;
8237 mm->unmap_area = arch_unmap_area;
8238 } else {
8239@@ -301,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8240 gap = (task_size / 6 * 5);
8241
8242 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
8243+
8244+#ifdef CONFIG_PAX_RANDMMAP
8245+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8246+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8247+#endif
8248+
8249 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8250 mm->unmap_area = arch_unmap_area_topdown;
8251 }
8252diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
8253index e0fed77..604a7e5 100644
8254--- a/arch/sparc/kernel/syscalls.S
8255+++ b/arch/sparc/kernel/syscalls.S
8256@@ -58,7 +58,7 @@ sys32_rt_sigreturn:
8257 #endif
8258 .align 32
8259 1: ldx [%g6 + TI_FLAGS], %l5
8260- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8261+ andcc %l5, _TIF_WORK_SYSCALL, %g0
8262 be,pt %icc, rtrap
8263 nop
8264 call syscall_trace_leave
8265@@ -190,7 +190,7 @@ linux_sparc_syscall32:
8266
8267 srl %i5, 0, %o5 ! IEU1
8268 srl %i2, 0, %o2 ! IEU0 Group
8269- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8270+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8271 bne,pn %icc, linux_syscall_trace32 ! CTI
8272 mov %i0, %l5 ! IEU1
8273 call %l7 ! CTI Group brk forced
8274@@ -213,7 +213,7 @@ linux_sparc_syscall:
8275
8276 mov %i3, %o3 ! IEU1
8277 mov %i4, %o4 ! IEU0 Group
8278- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8279+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8280 bne,pn %icc, linux_syscall_trace ! CTI Group
8281 mov %i0, %l5 ! IEU0
8282 2: call %l7 ! CTI Group brk forced
8283@@ -229,7 +229,7 @@ ret_sys_call:
8284
8285 cmp %o0, -ERESTART_RESTARTBLOCK
8286 bgeu,pn %xcc, 1f
8287- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8288+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8289 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
8290
8291 2:
8292diff --git a/arch/sparc/kernel/sysfs.c b/arch/sparc/kernel/sysfs.c
8293index 654e8aa..45f431b 100644
8294--- a/arch/sparc/kernel/sysfs.c
8295+++ b/arch/sparc/kernel/sysfs.c
8296@@ -266,7 +266,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
8297 return NOTIFY_OK;
8298 }
8299
8300-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
8301+static struct notifier_block sysfs_cpu_nb = {
8302 .notifier_call = sysfs_cpu_notify,
8303 };
8304
8305diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
8306index a5785ea..405c5f7 100644
8307--- a/arch/sparc/kernel/traps_32.c
8308+++ b/arch/sparc/kernel/traps_32.c
8309@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
8310 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
8311 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
8312
8313+extern void gr_handle_kernel_exploit(void);
8314+
8315 void die_if_kernel(char *str, struct pt_regs *regs)
8316 {
8317 static int die_counter;
8318@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8319 count++ < 30 &&
8320 (((unsigned long) rw) >= PAGE_OFFSET) &&
8321 !(((unsigned long) rw) & 0x7)) {
8322- printk("Caller[%08lx]: %pS\n", rw->ins[7],
8323+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
8324 (void *) rw->ins[7]);
8325 rw = (struct reg_window32 *)rw->ins[6];
8326 }
8327 }
8328 printk("Instruction DUMP:");
8329 instruction_dump ((unsigned long *) regs->pc);
8330- if(regs->psr & PSR_PS)
8331+ if(regs->psr & PSR_PS) {
8332+ gr_handle_kernel_exploit();
8333 do_exit(SIGKILL);
8334+ }
8335 do_exit(SIGSEGV);
8336 }
8337
8338diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
8339index e7ecf15..6520e65 100644
8340--- a/arch/sparc/kernel/traps_64.c
8341+++ b/arch/sparc/kernel/traps_64.c
8342@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
8343 i + 1,
8344 p->trapstack[i].tstate, p->trapstack[i].tpc,
8345 p->trapstack[i].tnpc, p->trapstack[i].tt);
8346- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
8347+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
8348 }
8349 }
8350
8351@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
8352
8353 lvl -= 0x100;
8354 if (regs->tstate & TSTATE_PRIV) {
8355+
8356+#ifdef CONFIG_PAX_REFCOUNT
8357+ if (lvl == 6)
8358+ pax_report_refcount_overflow(regs);
8359+#endif
8360+
8361 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
8362 die_if_kernel(buffer, regs);
8363 }
8364@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
8365 void bad_trap_tl1(struct pt_regs *regs, long lvl)
8366 {
8367 char buffer[32];
8368-
8369+
8370 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
8371 0, lvl, SIGTRAP) == NOTIFY_STOP)
8372 return;
8373
8374+#ifdef CONFIG_PAX_REFCOUNT
8375+ if (lvl == 6)
8376+ pax_report_refcount_overflow(regs);
8377+#endif
8378+
8379 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
8380
8381 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
8382@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
8383 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
8384 printk("%s" "ERROR(%d): ",
8385 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
8386- printk("TPC<%pS>\n", (void *) regs->tpc);
8387+ printk("TPC<%pA>\n", (void *) regs->tpc);
8388 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
8389 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
8390 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
8391@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8392 smp_processor_id(),
8393 (type & 0x1) ? 'I' : 'D',
8394 regs->tpc);
8395- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
8396+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
8397 panic("Irrecoverable Cheetah+ parity error.");
8398 }
8399
8400@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8401 smp_processor_id(),
8402 (type & 0x1) ? 'I' : 'D',
8403 regs->tpc);
8404- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
8405+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
8406 }
8407
8408 struct sun4v_error_entry {
8409@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
8410
8411 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
8412 regs->tpc, tl);
8413- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
8414+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
8415 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8416- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
8417+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
8418 (void *) regs->u_regs[UREG_I7]);
8419 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
8420 "pte[%lx] error[%lx]\n",
8421@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
8422
8423 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
8424 regs->tpc, tl);
8425- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
8426+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
8427 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8428- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
8429+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
8430 (void *) regs->u_regs[UREG_I7]);
8431 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
8432 "pte[%lx] error[%lx]\n",
8433@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8434 fp = (unsigned long)sf->fp + STACK_BIAS;
8435 }
8436
8437- printk(" [%016lx] %pS\n", pc, (void *) pc);
8438+ printk(" [%016lx] %pA\n", pc, (void *) pc);
8439 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8440 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
8441 int index = tsk->curr_ret_stack;
8442 if (tsk->ret_stack && index >= graph) {
8443 pc = tsk->ret_stack[index - graph].ret;
8444- printk(" [%016lx] %pS\n", pc, (void *) pc);
8445+ printk(" [%016lx] %pA\n", pc, (void *) pc);
8446 graph++;
8447 }
8448 }
8449@@ -2367,6 +2378,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
8450 return (struct reg_window *) (fp + STACK_BIAS);
8451 }
8452
8453+extern void gr_handle_kernel_exploit(void);
8454+
8455 void die_if_kernel(char *str, struct pt_regs *regs)
8456 {
8457 static int die_counter;
8458@@ -2395,7 +2408,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8459 while (rw &&
8460 count++ < 30 &&
8461 kstack_valid(tp, (unsigned long) rw)) {
8462- printk("Caller[%016lx]: %pS\n", rw->ins[7],
8463+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
8464 (void *) rw->ins[7]);
8465
8466 rw = kernel_stack_up(rw);
8467@@ -2408,8 +2421,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8468 }
8469 user_instruction_dump ((unsigned int __user *) regs->tpc);
8470 }
8471- if (regs->tstate & TSTATE_PRIV)
8472+ if (regs->tstate & TSTATE_PRIV) {
8473+ gr_handle_kernel_exploit();
8474 do_exit(SIGKILL);
8475+ }
8476 do_exit(SIGSEGV);
8477 }
8478 EXPORT_SYMBOL(die_if_kernel);
8479diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
8480index 8201c25e..072a2a7 100644
8481--- a/arch/sparc/kernel/unaligned_64.c
8482+++ b/arch/sparc/kernel/unaligned_64.c
8483@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
8484 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
8485
8486 if (__ratelimit(&ratelimit)) {
8487- printk("Kernel unaligned access at TPC[%lx] %pS\n",
8488+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
8489 regs->tpc, (void *) regs->tpc);
8490 }
8491 }
8492diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
8493index 8410065f2..4fd4ca22 100644
8494--- a/arch/sparc/lib/Makefile
8495+++ b/arch/sparc/lib/Makefile
8496@@ -2,7 +2,7 @@
8497 #
8498
8499 asflags-y := -ansi -DST_DIV0=0x02
8500-ccflags-y := -Werror
8501+#ccflags-y := -Werror
8502
8503 lib-$(CONFIG_SPARC32) += ashrdi3.o
8504 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
8505diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
8506index 85c233d..68500e0 100644
8507--- a/arch/sparc/lib/atomic_64.S
8508+++ b/arch/sparc/lib/atomic_64.S
8509@@ -17,7 +17,12 @@
8510 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8511 BACKOFF_SETUP(%o2)
8512 1: lduw [%o1], %g1
8513- add %g1, %o0, %g7
8514+ addcc %g1, %o0, %g7
8515+
8516+#ifdef CONFIG_PAX_REFCOUNT
8517+ tvs %icc, 6
8518+#endif
8519+
8520 cas [%o1], %g1, %g7
8521 cmp %g1, %g7
8522 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8523@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8524 2: BACKOFF_SPIN(%o2, %o3, 1b)
8525 ENDPROC(atomic_add)
8526
8527+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8528+ BACKOFF_SETUP(%o2)
8529+1: lduw [%o1], %g1
8530+ add %g1, %o0, %g7
8531+ cas [%o1], %g1, %g7
8532+ cmp %g1, %g7
8533+ bne,pn %icc, 2f
8534+ nop
8535+ retl
8536+ nop
8537+2: BACKOFF_SPIN(%o2, %o3, 1b)
8538+ENDPROC(atomic_add_unchecked)
8539+
8540 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8541 BACKOFF_SETUP(%o2)
8542 1: lduw [%o1], %g1
8543- sub %g1, %o0, %g7
8544+ subcc %g1, %o0, %g7
8545+
8546+#ifdef CONFIG_PAX_REFCOUNT
8547+ tvs %icc, 6
8548+#endif
8549+
8550 cas [%o1], %g1, %g7
8551 cmp %g1, %g7
8552 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8553@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8554 2: BACKOFF_SPIN(%o2, %o3, 1b)
8555 ENDPROC(atomic_sub)
8556
8557+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8558+ BACKOFF_SETUP(%o2)
8559+1: lduw [%o1], %g1
8560+ sub %g1, %o0, %g7
8561+ cas [%o1], %g1, %g7
8562+ cmp %g1, %g7
8563+ bne,pn %icc, 2f
8564+ nop
8565+ retl
8566+ nop
8567+2: BACKOFF_SPIN(%o2, %o3, 1b)
8568+ENDPROC(atomic_sub_unchecked)
8569+
8570 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8571 BACKOFF_SETUP(%o2)
8572 1: lduw [%o1], %g1
8573- add %g1, %o0, %g7
8574+ addcc %g1, %o0, %g7
8575+
8576+#ifdef CONFIG_PAX_REFCOUNT
8577+ tvs %icc, 6
8578+#endif
8579+
8580 cas [%o1], %g1, %g7
8581 cmp %g1, %g7
8582 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8583@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8584 2: BACKOFF_SPIN(%o2, %o3, 1b)
8585 ENDPROC(atomic_add_ret)
8586
8587+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8588+ BACKOFF_SETUP(%o2)
8589+1: lduw [%o1], %g1
8590+ addcc %g1, %o0, %g7
8591+ cas [%o1], %g1, %g7
8592+ cmp %g1, %g7
8593+ bne,pn %icc, 2f
8594+ add %g7, %o0, %g7
8595+ sra %g7, 0, %o0
8596+ retl
8597+ nop
8598+2: BACKOFF_SPIN(%o2, %o3, 1b)
8599+ENDPROC(atomic_add_ret_unchecked)
8600+
8601 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
8602 BACKOFF_SETUP(%o2)
8603 1: lduw [%o1], %g1
8604- sub %g1, %o0, %g7
8605+ subcc %g1, %o0, %g7
8606+
8607+#ifdef CONFIG_PAX_REFCOUNT
8608+ tvs %icc, 6
8609+#endif
8610+
8611 cas [%o1], %g1, %g7
8612 cmp %g1, %g7
8613 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8614@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
8615 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8616 BACKOFF_SETUP(%o2)
8617 1: ldx [%o1], %g1
8618- add %g1, %o0, %g7
8619+ addcc %g1, %o0, %g7
8620+
8621+#ifdef CONFIG_PAX_REFCOUNT
8622+ tvs %xcc, 6
8623+#endif
8624+
8625 casx [%o1], %g1, %g7
8626 cmp %g1, %g7
8627 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8628@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8629 2: BACKOFF_SPIN(%o2, %o3, 1b)
8630 ENDPROC(atomic64_add)
8631
8632+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8633+ BACKOFF_SETUP(%o2)
8634+1: ldx [%o1], %g1
8635+ addcc %g1, %o0, %g7
8636+ casx [%o1], %g1, %g7
8637+ cmp %g1, %g7
8638+ bne,pn %xcc, 2f
8639+ nop
8640+ retl
8641+ nop
8642+2: BACKOFF_SPIN(%o2, %o3, 1b)
8643+ENDPROC(atomic64_add_unchecked)
8644+
8645 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8646 BACKOFF_SETUP(%o2)
8647 1: ldx [%o1], %g1
8648- sub %g1, %o0, %g7
8649+ subcc %g1, %o0, %g7
8650+
8651+#ifdef CONFIG_PAX_REFCOUNT
8652+ tvs %xcc, 6
8653+#endif
8654+
8655 casx [%o1], %g1, %g7
8656 cmp %g1, %g7
8657 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8658@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8659 2: BACKOFF_SPIN(%o2, %o3, 1b)
8660 ENDPROC(atomic64_sub)
8661
8662+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8663+ BACKOFF_SETUP(%o2)
8664+1: ldx [%o1], %g1
8665+ subcc %g1, %o0, %g7
8666+ casx [%o1], %g1, %g7
8667+ cmp %g1, %g7
8668+ bne,pn %xcc, 2f
8669+ nop
8670+ retl
8671+ nop
8672+2: BACKOFF_SPIN(%o2, %o3, 1b)
8673+ENDPROC(atomic64_sub_unchecked)
8674+
8675 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8676 BACKOFF_SETUP(%o2)
8677 1: ldx [%o1], %g1
8678- add %g1, %o0, %g7
8679+ addcc %g1, %o0, %g7
8680+
8681+#ifdef CONFIG_PAX_REFCOUNT
8682+ tvs %xcc, 6
8683+#endif
8684+
8685 casx [%o1], %g1, %g7
8686 cmp %g1, %g7
8687 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8688@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8689 2: BACKOFF_SPIN(%o2, %o3, 1b)
8690 ENDPROC(atomic64_add_ret)
8691
8692+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8693+ BACKOFF_SETUP(%o2)
8694+1: ldx [%o1], %g1
8695+ addcc %g1, %o0, %g7
8696+ casx [%o1], %g1, %g7
8697+ cmp %g1, %g7
8698+ bne,pn %xcc, 2f
8699+ add %g7, %o0, %g7
8700+ mov %g7, %o0
8701+ retl
8702+ nop
8703+2: BACKOFF_SPIN(%o2, %o3, 1b)
8704+ENDPROC(atomic64_add_ret_unchecked)
8705+
8706 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
8707 BACKOFF_SETUP(%o2)
8708 1: ldx [%o1], %g1
8709- sub %g1, %o0, %g7
8710+ subcc %g1, %o0, %g7
8711+
8712+#ifdef CONFIG_PAX_REFCOUNT
8713+ tvs %xcc, 6
8714+#endif
8715+
8716 casx [%o1], %g1, %g7
8717 cmp %g1, %g7
8718 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8719diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
8720index 0c4e35e..745d3e4 100644
8721--- a/arch/sparc/lib/ksyms.c
8722+++ b/arch/sparc/lib/ksyms.c
8723@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
8724
8725 /* Atomic counter implementation. */
8726 EXPORT_SYMBOL(atomic_add);
8727+EXPORT_SYMBOL(atomic_add_unchecked);
8728 EXPORT_SYMBOL(atomic_add_ret);
8729+EXPORT_SYMBOL(atomic_add_ret_unchecked);
8730 EXPORT_SYMBOL(atomic_sub);
8731+EXPORT_SYMBOL(atomic_sub_unchecked);
8732 EXPORT_SYMBOL(atomic_sub_ret);
8733 EXPORT_SYMBOL(atomic64_add);
8734+EXPORT_SYMBOL(atomic64_add_unchecked);
8735 EXPORT_SYMBOL(atomic64_add_ret);
8736+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
8737 EXPORT_SYMBOL(atomic64_sub);
8738+EXPORT_SYMBOL(atomic64_sub_unchecked);
8739 EXPORT_SYMBOL(atomic64_sub_ret);
8740 EXPORT_SYMBOL(atomic64_dec_if_positive);
8741
8742diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
8743index 30c3ecc..736f015 100644
8744--- a/arch/sparc/mm/Makefile
8745+++ b/arch/sparc/mm/Makefile
8746@@ -2,7 +2,7 @@
8747 #
8748
8749 asflags-y := -ansi
8750-ccflags-y := -Werror
8751+#ccflags-y := -Werror
8752
8753 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
8754 obj-y += fault_$(BITS).o
8755diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
8756index e98bfda..ea8d221 100644
8757--- a/arch/sparc/mm/fault_32.c
8758+++ b/arch/sparc/mm/fault_32.c
8759@@ -21,6 +21,9 @@
8760 #include <linux/perf_event.h>
8761 #include <linux/interrupt.h>
8762 #include <linux/kdebug.h>
8763+#include <linux/slab.h>
8764+#include <linux/pagemap.h>
8765+#include <linux/compiler.h>
8766
8767 #include <asm/page.h>
8768 #include <asm/pgtable.h>
8769@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
8770 return safe_compute_effective_address(regs, insn);
8771 }
8772
8773+#ifdef CONFIG_PAX_PAGEEXEC
8774+#ifdef CONFIG_PAX_DLRESOLVE
8775+static void pax_emuplt_close(struct vm_area_struct *vma)
8776+{
8777+ vma->vm_mm->call_dl_resolve = 0UL;
8778+}
8779+
8780+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8781+{
8782+ unsigned int *kaddr;
8783+
8784+ vmf->page = alloc_page(GFP_HIGHUSER);
8785+ if (!vmf->page)
8786+ return VM_FAULT_OOM;
8787+
8788+ kaddr = kmap(vmf->page);
8789+ memset(kaddr, 0, PAGE_SIZE);
8790+ kaddr[0] = 0x9DE3BFA8U; /* save */
8791+ flush_dcache_page(vmf->page);
8792+ kunmap(vmf->page);
8793+ return VM_FAULT_MAJOR;
8794+}
8795+
8796+static const struct vm_operations_struct pax_vm_ops = {
8797+ .close = pax_emuplt_close,
8798+ .fault = pax_emuplt_fault
8799+};
8800+
8801+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
8802+{
8803+ int ret;
8804+
8805+ INIT_LIST_HEAD(&vma->anon_vma_chain);
8806+ vma->vm_mm = current->mm;
8807+ vma->vm_start = addr;
8808+ vma->vm_end = addr + PAGE_SIZE;
8809+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
8810+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
8811+ vma->vm_ops = &pax_vm_ops;
8812+
8813+ ret = insert_vm_struct(current->mm, vma);
8814+ if (ret)
8815+ return ret;
8816+
8817+ ++current->mm->total_vm;
8818+ return 0;
8819+}
8820+#endif
8821+
8822+/*
8823+ * PaX: decide what to do with offenders (regs->pc = fault address)
8824+ *
8825+ * returns 1 when task should be killed
8826+ * 2 when patched PLT trampoline was detected
8827+ * 3 when unpatched PLT trampoline was detected
8828+ */
8829+static int pax_handle_fetch_fault(struct pt_regs *regs)
8830+{
8831+
8832+#ifdef CONFIG_PAX_EMUPLT
8833+ int err;
8834+
8835+ do { /* PaX: patched PLT emulation #1 */
8836+ unsigned int sethi1, sethi2, jmpl;
8837+
8838+ err = get_user(sethi1, (unsigned int *)regs->pc);
8839+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
8840+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
8841+
8842+ if (err)
8843+ break;
8844+
8845+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
8846+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
8847+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
8848+ {
8849+ unsigned int addr;
8850+
8851+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
8852+ addr = regs->u_regs[UREG_G1];
8853+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
8854+ regs->pc = addr;
8855+ regs->npc = addr+4;
8856+ return 2;
8857+ }
8858+ } while (0);
8859+
8860+ do { /* PaX: patched PLT emulation #2 */
8861+ unsigned int ba;
8862+
8863+ err = get_user(ba, (unsigned int *)regs->pc);
8864+
8865+ if (err)
8866+ break;
8867+
8868+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
8869+ unsigned int addr;
8870+
8871+ if ((ba & 0xFFC00000U) == 0x30800000U)
8872+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
8873+ else
8874+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
8875+ regs->pc = addr;
8876+ regs->npc = addr+4;
8877+ return 2;
8878+ }
8879+ } while (0);
8880+
8881+ do { /* PaX: patched PLT emulation #3 */
8882+ unsigned int sethi, bajmpl, nop;
8883+
8884+ err = get_user(sethi, (unsigned int *)regs->pc);
8885+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
8886+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
8887+
8888+ if (err)
8889+ break;
8890+
8891+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
8892+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
8893+ nop == 0x01000000U)
8894+ {
8895+ unsigned int addr;
8896+
8897+ addr = (sethi & 0x003FFFFFU) << 10;
8898+ regs->u_regs[UREG_G1] = addr;
8899+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
8900+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
8901+ else
8902+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
8903+ regs->pc = addr;
8904+ regs->npc = addr+4;
8905+ return 2;
8906+ }
8907+ } while (0);
8908+
8909+ do { /* PaX: unpatched PLT emulation step 1 */
8910+ unsigned int sethi, ba, nop;
8911+
8912+ err = get_user(sethi, (unsigned int *)regs->pc);
8913+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
8914+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
8915+
8916+ if (err)
8917+ break;
8918+
8919+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
8920+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
8921+ nop == 0x01000000U)
8922+ {
8923+ unsigned int addr, save, call;
8924+
8925+ if ((ba & 0xFFC00000U) == 0x30800000U)
8926+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
8927+ else
8928+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
8929+
8930+ err = get_user(save, (unsigned int *)addr);
8931+ err |= get_user(call, (unsigned int *)(addr+4));
8932+ err |= get_user(nop, (unsigned int *)(addr+8));
8933+ if (err)
8934+ break;
8935+
8936+#ifdef CONFIG_PAX_DLRESOLVE
8937+ if (save == 0x9DE3BFA8U &&
8938+ (call & 0xC0000000U) == 0x40000000U &&
8939+ nop == 0x01000000U)
8940+ {
8941+ struct vm_area_struct *vma;
8942+ unsigned long call_dl_resolve;
8943+
8944+ down_read(&current->mm->mmap_sem);
8945+ call_dl_resolve = current->mm->call_dl_resolve;
8946+ up_read(&current->mm->mmap_sem);
8947+ if (likely(call_dl_resolve))
8948+ goto emulate;
8949+
8950+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
8951+
8952+ down_write(&current->mm->mmap_sem);
8953+ if (current->mm->call_dl_resolve) {
8954+ call_dl_resolve = current->mm->call_dl_resolve;
8955+ up_write(&current->mm->mmap_sem);
8956+ if (vma)
8957+ kmem_cache_free(vm_area_cachep, vma);
8958+ goto emulate;
8959+ }
8960+
8961+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
8962+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
8963+ up_write(&current->mm->mmap_sem);
8964+ if (vma)
8965+ kmem_cache_free(vm_area_cachep, vma);
8966+ return 1;
8967+ }
8968+
8969+ if (pax_insert_vma(vma, call_dl_resolve)) {
8970+ up_write(&current->mm->mmap_sem);
8971+ kmem_cache_free(vm_area_cachep, vma);
8972+ return 1;
8973+ }
8974+
8975+ current->mm->call_dl_resolve = call_dl_resolve;
8976+ up_write(&current->mm->mmap_sem);
8977+
8978+emulate:
8979+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8980+ regs->pc = call_dl_resolve;
8981+ regs->npc = addr+4;
8982+ return 3;
8983+ }
8984+#endif
8985+
8986+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
8987+ if ((save & 0xFFC00000U) == 0x05000000U &&
8988+ (call & 0xFFFFE000U) == 0x85C0A000U &&
8989+ nop == 0x01000000U)
8990+ {
8991+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8992+ regs->u_regs[UREG_G2] = addr + 4;
8993+ addr = (save & 0x003FFFFFU) << 10;
8994+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
8995+ regs->pc = addr;
8996+ regs->npc = addr+4;
8997+ return 3;
8998+ }
8999+ }
9000+ } while (0);
9001+
9002+ do { /* PaX: unpatched PLT emulation step 2 */
9003+ unsigned int save, call, nop;
9004+
9005+ err = get_user(save, (unsigned int *)(regs->pc-4));
9006+ err |= get_user(call, (unsigned int *)regs->pc);
9007+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
9008+ if (err)
9009+ break;
9010+
9011+ if (save == 0x9DE3BFA8U &&
9012+ (call & 0xC0000000U) == 0x40000000U &&
9013+ nop == 0x01000000U)
9014+ {
9015+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
9016+
9017+ regs->u_regs[UREG_RETPC] = regs->pc;
9018+ regs->pc = dl_resolve;
9019+ regs->npc = dl_resolve+4;
9020+ return 3;
9021+ }
9022+ } while (0);
9023+#endif
9024+
9025+ return 1;
9026+}
9027+
9028+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9029+{
9030+ unsigned long i;
9031+
9032+ printk(KERN_ERR "PAX: bytes at PC: ");
9033+ for (i = 0; i < 8; i++) {
9034+ unsigned int c;
9035+ if (get_user(c, (unsigned int *)pc+i))
9036+ printk(KERN_CONT "???????? ");
9037+ else
9038+ printk(KERN_CONT "%08x ", c);
9039+ }
9040+ printk("\n");
9041+}
9042+#endif
9043+
9044 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
9045 int text_fault)
9046 {
9047@@ -230,6 +504,24 @@ good_area:
9048 if (!(vma->vm_flags & VM_WRITE))
9049 goto bad_area;
9050 } else {
9051+
9052+#ifdef CONFIG_PAX_PAGEEXEC
9053+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
9054+ up_read(&mm->mmap_sem);
9055+ switch (pax_handle_fetch_fault(regs)) {
9056+
9057+#ifdef CONFIG_PAX_EMUPLT
9058+ case 2:
9059+ case 3:
9060+ return;
9061+#endif
9062+
9063+ }
9064+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
9065+ do_group_exit(SIGKILL);
9066+ }
9067+#endif
9068+
9069 /* Allow reads even for write-only mappings */
9070 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
9071 goto bad_area;
9072diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
9073index 097aee7..5ca6697 100644
9074--- a/arch/sparc/mm/fault_64.c
9075+++ b/arch/sparc/mm/fault_64.c
9076@@ -21,6 +21,9 @@
9077 #include <linux/kprobes.h>
9078 #include <linux/kdebug.h>
9079 #include <linux/percpu.h>
9080+#include <linux/slab.h>
9081+#include <linux/pagemap.h>
9082+#include <linux/compiler.h>
9083
9084 #include <asm/page.h>
9085 #include <asm/pgtable.h>
9086@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
9087 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
9088 regs->tpc);
9089 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
9090- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
9091+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
9092 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
9093 dump_stack();
9094 unhandled_fault(regs->tpc, current, regs);
9095@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
9096 show_regs(regs);
9097 }
9098
9099+#ifdef CONFIG_PAX_PAGEEXEC
9100+#ifdef CONFIG_PAX_DLRESOLVE
9101+static void pax_emuplt_close(struct vm_area_struct *vma)
9102+{
9103+ vma->vm_mm->call_dl_resolve = 0UL;
9104+}
9105+
9106+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9107+{
9108+ unsigned int *kaddr;
9109+
9110+ vmf->page = alloc_page(GFP_HIGHUSER);
9111+ if (!vmf->page)
9112+ return VM_FAULT_OOM;
9113+
9114+ kaddr = kmap(vmf->page);
9115+ memset(kaddr, 0, PAGE_SIZE);
9116+ kaddr[0] = 0x9DE3BFA8U; /* save */
9117+ flush_dcache_page(vmf->page);
9118+ kunmap(vmf->page);
9119+ return VM_FAULT_MAJOR;
9120+}
9121+
9122+static const struct vm_operations_struct pax_vm_ops = {
9123+ .close = pax_emuplt_close,
9124+ .fault = pax_emuplt_fault
9125+};
9126+
9127+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9128+{
9129+ int ret;
9130+
9131+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9132+ vma->vm_mm = current->mm;
9133+ vma->vm_start = addr;
9134+ vma->vm_end = addr + PAGE_SIZE;
9135+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9136+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9137+ vma->vm_ops = &pax_vm_ops;
9138+
9139+ ret = insert_vm_struct(current->mm, vma);
9140+ if (ret)
9141+ return ret;
9142+
9143+ ++current->mm->total_vm;
9144+ return 0;
9145+}
9146+#endif
9147+
9148+/*
9149+ * PaX: decide what to do with offenders (regs->tpc = fault address)
9150+ *
9151+ * returns 1 when task should be killed
9152+ * 2 when patched PLT trampoline was detected
9153+ * 3 when unpatched PLT trampoline was detected
9154+ */
9155+static int pax_handle_fetch_fault(struct pt_regs *regs)
9156+{
9157+
9158+#ifdef CONFIG_PAX_EMUPLT
9159+ int err;
9160+
9161+ do { /* PaX: patched PLT emulation #1 */
9162+ unsigned int sethi1, sethi2, jmpl;
9163+
9164+ err = get_user(sethi1, (unsigned int *)regs->tpc);
9165+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
9166+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
9167+
9168+ if (err)
9169+ break;
9170+
9171+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9172+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9173+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9174+ {
9175+ unsigned long addr;
9176+
9177+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9178+ addr = regs->u_regs[UREG_G1];
9179+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9180+
9181+ if (test_thread_flag(TIF_32BIT))
9182+ addr &= 0xFFFFFFFFUL;
9183+
9184+ regs->tpc = addr;
9185+ regs->tnpc = addr+4;
9186+ return 2;
9187+ }
9188+ } while (0);
9189+
9190+ do { /* PaX: patched PLT emulation #2 */
9191+ unsigned int ba;
9192+
9193+ err = get_user(ba, (unsigned int *)regs->tpc);
9194+
9195+ if (err)
9196+ break;
9197+
9198+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9199+ unsigned long addr;
9200+
9201+ if ((ba & 0xFFC00000U) == 0x30800000U)
9202+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9203+ else
9204+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9205+
9206+ if (test_thread_flag(TIF_32BIT))
9207+ addr &= 0xFFFFFFFFUL;
9208+
9209+ regs->tpc = addr;
9210+ regs->tnpc = addr+4;
9211+ return 2;
9212+ }
9213+ } while (0);
9214+
9215+ do { /* PaX: patched PLT emulation #3 */
9216+ unsigned int sethi, bajmpl, nop;
9217+
9218+ err = get_user(sethi, (unsigned int *)regs->tpc);
9219+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
9220+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9221+
9222+ if (err)
9223+ break;
9224+
9225+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9226+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9227+ nop == 0x01000000U)
9228+ {
9229+ unsigned long addr;
9230+
9231+ addr = (sethi & 0x003FFFFFU) << 10;
9232+ regs->u_regs[UREG_G1] = addr;
9233+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9234+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9235+ else
9236+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9237+
9238+ if (test_thread_flag(TIF_32BIT))
9239+ addr &= 0xFFFFFFFFUL;
9240+
9241+ regs->tpc = addr;
9242+ regs->tnpc = addr+4;
9243+ return 2;
9244+ }
9245+ } while (0);
9246+
9247+ do { /* PaX: patched PLT emulation #4 */
9248+ unsigned int sethi, mov1, call, mov2;
9249+
9250+ err = get_user(sethi, (unsigned int *)regs->tpc);
9251+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
9252+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
9253+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
9254+
9255+ if (err)
9256+ break;
9257+
9258+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9259+ mov1 == 0x8210000FU &&
9260+ (call & 0xC0000000U) == 0x40000000U &&
9261+ mov2 == 0x9E100001U)
9262+ {
9263+ unsigned long addr;
9264+
9265+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
9266+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9267+
9268+ if (test_thread_flag(TIF_32BIT))
9269+ addr &= 0xFFFFFFFFUL;
9270+
9271+ regs->tpc = addr;
9272+ regs->tnpc = addr+4;
9273+ return 2;
9274+ }
9275+ } while (0);
9276+
9277+ do { /* PaX: patched PLT emulation #5 */
9278+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
9279+
9280+ err = get_user(sethi, (unsigned int *)regs->tpc);
9281+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9282+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9283+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
9284+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
9285+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
9286+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
9287+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
9288+
9289+ if (err)
9290+ break;
9291+
9292+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9293+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
9294+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9295+ (or1 & 0xFFFFE000U) == 0x82106000U &&
9296+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
9297+ sllx == 0x83287020U &&
9298+ jmpl == 0x81C04005U &&
9299+ nop == 0x01000000U)
9300+ {
9301+ unsigned long addr;
9302+
9303+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9304+ regs->u_regs[UREG_G1] <<= 32;
9305+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9306+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9307+ regs->tpc = addr;
9308+ regs->tnpc = addr+4;
9309+ return 2;
9310+ }
9311+ } while (0);
9312+
9313+ do { /* PaX: patched PLT emulation #6 */
9314+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
9315+
9316+ err = get_user(sethi, (unsigned int *)regs->tpc);
9317+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9318+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9319+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
9320+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
9321+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
9322+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
9323+
9324+ if (err)
9325+ break;
9326+
9327+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9328+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
9329+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9330+ sllx == 0x83287020U &&
9331+ (or & 0xFFFFE000U) == 0x8A116000U &&
9332+ jmpl == 0x81C04005U &&
9333+ nop == 0x01000000U)
9334+ {
9335+ unsigned long addr;
9336+
9337+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
9338+ regs->u_regs[UREG_G1] <<= 32;
9339+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
9340+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9341+ regs->tpc = addr;
9342+ regs->tnpc = addr+4;
9343+ return 2;
9344+ }
9345+ } while (0);
9346+
9347+ do { /* PaX: unpatched PLT emulation step 1 */
9348+ unsigned int sethi, ba, nop;
9349+
9350+ err = get_user(sethi, (unsigned int *)regs->tpc);
9351+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9352+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9353+
9354+ if (err)
9355+ break;
9356+
9357+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9358+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9359+ nop == 0x01000000U)
9360+ {
9361+ unsigned long addr;
9362+ unsigned int save, call;
9363+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
9364+
9365+ if ((ba & 0xFFC00000U) == 0x30800000U)
9366+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9367+ else
9368+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9369+
9370+ if (test_thread_flag(TIF_32BIT))
9371+ addr &= 0xFFFFFFFFUL;
9372+
9373+ err = get_user(save, (unsigned int *)addr);
9374+ err |= get_user(call, (unsigned int *)(addr+4));
9375+ err |= get_user(nop, (unsigned int *)(addr+8));
9376+ if (err)
9377+ break;
9378+
9379+#ifdef CONFIG_PAX_DLRESOLVE
9380+ if (save == 0x9DE3BFA8U &&
9381+ (call & 0xC0000000U) == 0x40000000U &&
9382+ nop == 0x01000000U)
9383+ {
9384+ struct vm_area_struct *vma;
9385+ unsigned long call_dl_resolve;
9386+
9387+ down_read(&current->mm->mmap_sem);
9388+ call_dl_resolve = current->mm->call_dl_resolve;
9389+ up_read(&current->mm->mmap_sem);
9390+ if (likely(call_dl_resolve))
9391+ goto emulate;
9392+
9393+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9394+
9395+ down_write(&current->mm->mmap_sem);
9396+ if (current->mm->call_dl_resolve) {
9397+ call_dl_resolve = current->mm->call_dl_resolve;
9398+ up_write(&current->mm->mmap_sem);
9399+ if (vma)
9400+ kmem_cache_free(vm_area_cachep, vma);
9401+ goto emulate;
9402+ }
9403+
9404+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9405+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9406+ up_write(&current->mm->mmap_sem);
9407+ if (vma)
9408+ kmem_cache_free(vm_area_cachep, vma);
9409+ return 1;
9410+ }
9411+
9412+ if (pax_insert_vma(vma, call_dl_resolve)) {
9413+ up_write(&current->mm->mmap_sem);
9414+ kmem_cache_free(vm_area_cachep, vma);
9415+ return 1;
9416+ }
9417+
9418+ current->mm->call_dl_resolve = call_dl_resolve;
9419+ up_write(&current->mm->mmap_sem);
9420+
9421+emulate:
9422+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9423+ regs->tpc = call_dl_resolve;
9424+ regs->tnpc = addr+4;
9425+ return 3;
9426+ }
9427+#endif
9428+
9429+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9430+ if ((save & 0xFFC00000U) == 0x05000000U &&
9431+ (call & 0xFFFFE000U) == 0x85C0A000U &&
9432+ nop == 0x01000000U)
9433+ {
9434+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9435+ regs->u_regs[UREG_G2] = addr + 4;
9436+ addr = (save & 0x003FFFFFU) << 10;
9437+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9438+
9439+ if (test_thread_flag(TIF_32BIT))
9440+ addr &= 0xFFFFFFFFUL;
9441+
9442+ regs->tpc = addr;
9443+ regs->tnpc = addr+4;
9444+ return 3;
9445+ }
9446+
9447+ /* PaX: 64-bit PLT stub */
9448+ err = get_user(sethi1, (unsigned int *)addr);
9449+ err |= get_user(sethi2, (unsigned int *)(addr+4));
9450+ err |= get_user(or1, (unsigned int *)(addr+8));
9451+ err |= get_user(or2, (unsigned int *)(addr+12));
9452+ err |= get_user(sllx, (unsigned int *)(addr+16));
9453+ err |= get_user(add, (unsigned int *)(addr+20));
9454+ err |= get_user(jmpl, (unsigned int *)(addr+24));
9455+ err |= get_user(nop, (unsigned int *)(addr+28));
9456+ if (err)
9457+ break;
9458+
9459+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
9460+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9461+ (or1 & 0xFFFFE000U) == 0x88112000U &&
9462+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
9463+ sllx == 0x89293020U &&
9464+ add == 0x8A010005U &&
9465+ jmpl == 0x89C14000U &&
9466+ nop == 0x01000000U)
9467+ {
9468+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9469+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9470+ regs->u_regs[UREG_G4] <<= 32;
9471+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9472+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
9473+ regs->u_regs[UREG_G4] = addr + 24;
9474+ addr = regs->u_regs[UREG_G5];
9475+ regs->tpc = addr;
9476+ regs->tnpc = addr+4;
9477+ return 3;
9478+ }
9479+ }
9480+ } while (0);
9481+
9482+#ifdef CONFIG_PAX_DLRESOLVE
9483+ do { /* PaX: unpatched PLT emulation step 2 */
9484+ unsigned int save, call, nop;
9485+
9486+ err = get_user(save, (unsigned int *)(regs->tpc-4));
9487+ err |= get_user(call, (unsigned int *)regs->tpc);
9488+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
9489+ if (err)
9490+ break;
9491+
9492+ if (save == 0x9DE3BFA8U &&
9493+ (call & 0xC0000000U) == 0x40000000U &&
9494+ nop == 0x01000000U)
9495+ {
9496+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9497+
9498+ if (test_thread_flag(TIF_32BIT))
9499+ dl_resolve &= 0xFFFFFFFFUL;
9500+
9501+ regs->u_regs[UREG_RETPC] = regs->tpc;
9502+ regs->tpc = dl_resolve;
9503+ regs->tnpc = dl_resolve+4;
9504+ return 3;
9505+ }
9506+ } while (0);
9507+#endif
9508+
9509+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
9510+ unsigned int sethi, ba, nop;
9511+
9512+ err = get_user(sethi, (unsigned int *)regs->tpc);
9513+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9514+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9515+
9516+ if (err)
9517+ break;
9518+
9519+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9520+ (ba & 0xFFF00000U) == 0x30600000U &&
9521+ nop == 0x01000000U)
9522+ {
9523+ unsigned long addr;
9524+
9525+ addr = (sethi & 0x003FFFFFU) << 10;
9526+ regs->u_regs[UREG_G1] = addr;
9527+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9528+
9529+ if (test_thread_flag(TIF_32BIT))
9530+ addr &= 0xFFFFFFFFUL;
9531+
9532+ regs->tpc = addr;
9533+ regs->tnpc = addr+4;
9534+ return 2;
9535+ }
9536+ } while (0);
9537+
9538+#endif
9539+
9540+ return 1;
9541+}
9542+
9543+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9544+{
9545+ unsigned long i;
9546+
9547+ printk(KERN_ERR "PAX: bytes at PC: ");
9548+ for (i = 0; i < 8; i++) {
9549+ unsigned int c;
9550+ if (get_user(c, (unsigned int *)pc+i))
9551+ printk(KERN_CONT "???????? ");
9552+ else
9553+ printk(KERN_CONT "%08x ", c);
9554+ }
9555+ printk("\n");
9556+}
9557+#endif
9558+
9559 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
9560 {
9561 struct mm_struct *mm = current->mm;
9562@@ -341,6 +804,29 @@ retry:
9563 if (!vma)
9564 goto bad_area;
9565
9566+#ifdef CONFIG_PAX_PAGEEXEC
9567+ /* PaX: detect ITLB misses on non-exec pages */
9568+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
9569+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
9570+ {
9571+ if (address != regs->tpc)
9572+ goto good_area;
9573+
9574+ up_read(&mm->mmap_sem);
9575+ switch (pax_handle_fetch_fault(regs)) {
9576+
9577+#ifdef CONFIG_PAX_EMUPLT
9578+ case 2:
9579+ case 3:
9580+ return;
9581+#endif
9582+
9583+ }
9584+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
9585+ do_group_exit(SIGKILL);
9586+ }
9587+#endif
9588+
9589 /* Pure DTLB misses do not tell us whether the fault causing
9590 * load/store/atomic was a write or not, it only says that there
9591 * was no match. So in such a case we (carefully) read the
9592diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
9593index d2b5944..bd813f2 100644
9594--- a/arch/sparc/mm/hugetlbpage.c
9595+++ b/arch/sparc/mm/hugetlbpage.c
9596@@ -38,7 +38,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9597
9598 info.flags = 0;
9599 info.length = len;
9600- info.low_limit = TASK_UNMAPPED_BASE;
9601+ info.low_limit = mm->mmap_base;
9602 info.high_limit = min(task_size, VA_EXCLUDE_START);
9603 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
9604 info.align_offset = 0;
9605@@ -47,6 +47,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9606 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9607 VM_BUG_ON(addr != -ENOMEM);
9608 info.low_limit = VA_EXCLUDE_END;
9609+
9610+#ifdef CONFIG_PAX_RANDMMAP
9611+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9612+ info.low_limit += mm->delta_mmap;
9613+#endif
9614+
9615 info.high_limit = task_size;
9616 addr = vm_unmapped_area(&info);
9617 }
9618@@ -85,6 +91,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9619 VM_BUG_ON(addr != -ENOMEM);
9620 info.flags = 0;
9621 info.low_limit = TASK_UNMAPPED_BASE;
9622+
9623+#ifdef CONFIG_PAX_RANDMMAP
9624+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9625+ info.low_limit += mm->delta_mmap;
9626+#endif
9627+
9628 info.high_limit = STACK_TOP32;
9629 addr = vm_unmapped_area(&info);
9630 }
9631@@ -99,6 +111,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9632 struct mm_struct *mm = current->mm;
9633 struct vm_area_struct *vma;
9634 unsigned long task_size = TASK_SIZE;
9635+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
9636
9637 if (test_thread_flag(TIF_32BIT))
9638 task_size = STACK_TOP32;
9639@@ -114,11 +127,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9640 return addr;
9641 }
9642
9643+#ifdef CONFIG_PAX_RANDMMAP
9644+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9645+#endif
9646+
9647 if (addr) {
9648 addr = ALIGN(addr, HPAGE_SIZE);
9649 vma = find_vma(mm, addr);
9650- if (task_size - len >= addr &&
9651- (!vma || addr + len <= vma->vm_start))
9652+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9653 return addr;
9654 }
9655 if (mm->get_unmapped_area == arch_get_unmapped_area)
9656diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
9657index f4500c6..889656c 100644
9658--- a/arch/tile/include/asm/atomic_64.h
9659+++ b/arch/tile/include/asm/atomic_64.h
9660@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9661
9662 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9663
9664+#define atomic64_read_unchecked(v) atomic64_read(v)
9665+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9666+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9667+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9668+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9669+#define atomic64_inc_unchecked(v) atomic64_inc(v)
9670+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9671+#define atomic64_dec_unchecked(v) atomic64_dec(v)
9672+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9673+
9674 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
9675 #define smp_mb__before_atomic_dec() smp_mb()
9676 #define smp_mb__after_atomic_dec() smp_mb()
9677diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
9678index a9a5299..0fce79e 100644
9679--- a/arch/tile/include/asm/cache.h
9680+++ b/arch/tile/include/asm/cache.h
9681@@ -15,11 +15,12 @@
9682 #ifndef _ASM_TILE_CACHE_H
9683 #define _ASM_TILE_CACHE_H
9684
9685+#include <linux/const.h>
9686 #include <arch/chip.h>
9687
9688 /* bytes per L1 data cache line */
9689 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
9690-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9691+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9692
9693 /* bytes per L2 cache line */
9694 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
9695diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
9696index 9ab078a..d6635c2 100644
9697--- a/arch/tile/include/asm/uaccess.h
9698+++ b/arch/tile/include/asm/uaccess.h
9699@@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
9700 const void __user *from,
9701 unsigned long n)
9702 {
9703- int sz = __compiletime_object_size(to);
9704+ size_t sz = __compiletime_object_size(to);
9705
9706- if (likely(sz == -1 || sz >= n))
9707+ if (likely(sz == (size_t)-1 || sz >= n))
9708 n = _copy_from_user(to, from, n);
9709 else
9710 copy_from_user_overflow();
9711diff --git a/arch/um/Makefile b/arch/um/Makefile
9712index 133f7de..1d6f2f1 100644
9713--- a/arch/um/Makefile
9714+++ b/arch/um/Makefile
9715@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
9716 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
9717 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
9718
9719+ifdef CONSTIFY_PLUGIN
9720+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
9721+endif
9722+
9723 #This will adjust *FLAGS accordingly to the platform.
9724 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
9725
9726diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
9727index 19e1bdd..3665b77 100644
9728--- a/arch/um/include/asm/cache.h
9729+++ b/arch/um/include/asm/cache.h
9730@@ -1,6 +1,7 @@
9731 #ifndef __UM_CACHE_H
9732 #define __UM_CACHE_H
9733
9734+#include <linux/const.h>
9735
9736 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
9737 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
9738@@ -12,6 +13,6 @@
9739 # define L1_CACHE_SHIFT 5
9740 #endif
9741
9742-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9743+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9744
9745 #endif
9746diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
9747index 2e0a6b1..a64d0f5 100644
9748--- a/arch/um/include/asm/kmap_types.h
9749+++ b/arch/um/include/asm/kmap_types.h
9750@@ -8,6 +8,6 @@
9751
9752 /* No more #include "asm/arch/kmap_types.h" ! */
9753
9754-#define KM_TYPE_NR 14
9755+#define KM_TYPE_NR 15
9756
9757 #endif
9758diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
9759index 5ff53d9..5850cdf 100644
9760--- a/arch/um/include/asm/page.h
9761+++ b/arch/um/include/asm/page.h
9762@@ -14,6 +14,9 @@
9763 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
9764 #define PAGE_MASK (~(PAGE_SIZE-1))
9765
9766+#define ktla_ktva(addr) (addr)
9767+#define ktva_ktla(addr) (addr)
9768+
9769 #ifndef __ASSEMBLY__
9770
9771 struct page;
9772diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
9773index 0032f92..cd151e0 100644
9774--- a/arch/um/include/asm/pgtable-3level.h
9775+++ b/arch/um/include/asm/pgtable-3level.h
9776@@ -58,6 +58,7 @@
9777 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
9778 #define pud_populate(mm, pud, pmd) \
9779 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
9780+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
9781
9782 #ifdef CONFIG_64BIT
9783 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
9784diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
9785index b462b13..e7a19aa 100644
9786--- a/arch/um/kernel/process.c
9787+++ b/arch/um/kernel/process.c
9788@@ -386,22 +386,6 @@ int singlestepping(void * t)
9789 return 2;
9790 }
9791
9792-/*
9793- * Only x86 and x86_64 have an arch_align_stack().
9794- * All other arches have "#define arch_align_stack(x) (x)"
9795- * in their asm/system.h
9796- * As this is included in UML from asm-um/system-generic.h,
9797- * we can use it to behave as the subarch does.
9798- */
9799-#ifndef arch_align_stack
9800-unsigned long arch_align_stack(unsigned long sp)
9801-{
9802- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9803- sp -= get_random_int() % 8192;
9804- return sp & ~0xf;
9805-}
9806-#endif
9807-
9808 unsigned long get_wchan(struct task_struct *p)
9809 {
9810 unsigned long stack_page, sp, ip;
9811diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
9812index ad8f795..2c7eec6 100644
9813--- a/arch/unicore32/include/asm/cache.h
9814+++ b/arch/unicore32/include/asm/cache.h
9815@@ -12,8 +12,10 @@
9816 #ifndef __UNICORE_CACHE_H__
9817 #define __UNICORE_CACHE_H__
9818
9819-#define L1_CACHE_SHIFT (5)
9820-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9821+#include <linux/const.h>
9822+
9823+#define L1_CACHE_SHIFT 5
9824+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9825
9826 /*
9827 * Memory returned by kmalloc() may be used for DMA, so we must make
9828diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
9829index 225543b..f12405b 100644
9830--- a/arch/x86/Kconfig
9831+++ b/arch/x86/Kconfig
9832@@ -238,7 +238,7 @@ config X86_HT
9833
9834 config X86_32_LAZY_GS
9835 def_bool y
9836- depends on X86_32 && !CC_STACKPROTECTOR
9837+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
9838
9839 config ARCH_HWEIGHT_CFLAGS
9840 string
9841@@ -1031,6 +1031,7 @@ config MICROCODE_OLD_INTERFACE
9842
9843 config X86_MSR
9844 tristate "/dev/cpu/*/msr - Model-specific register support"
9845+ depends on !GRKERNSEC_KMEM
9846 ---help---
9847 This device gives privileged processes access to the x86
9848 Model-Specific Registers (MSRs). It is a character device with
9849@@ -1054,7 +1055,7 @@ choice
9850
9851 config NOHIGHMEM
9852 bool "off"
9853- depends on !X86_NUMAQ
9854+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
9855 ---help---
9856 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
9857 However, the address space of 32-bit x86 processors is only 4
9858@@ -1091,7 +1092,7 @@ config NOHIGHMEM
9859
9860 config HIGHMEM4G
9861 bool "4GB"
9862- depends on !X86_NUMAQ
9863+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
9864 ---help---
9865 Select this if you have a 32-bit processor and between 1 and 4
9866 gigabytes of physical RAM.
9867@@ -1145,7 +1146,7 @@ config PAGE_OFFSET
9868 hex
9869 default 0xB0000000 if VMSPLIT_3G_OPT
9870 default 0x80000000 if VMSPLIT_2G
9871- default 0x78000000 if VMSPLIT_2G_OPT
9872+ default 0x70000000 if VMSPLIT_2G_OPT
9873 default 0x40000000 if VMSPLIT_1G
9874 default 0xC0000000
9875 depends on X86_32
9876@@ -1546,6 +1547,7 @@ config SECCOMP
9877
9878 config CC_STACKPROTECTOR
9879 bool "Enable -fstack-protector buffer overflow detection"
9880+ depends on X86_64 || !PAX_MEMORY_UDEREF
9881 ---help---
9882 This option turns on the -fstack-protector GCC feature. This
9883 feature puts, at the beginning of functions, a canary value on
9884@@ -1603,6 +1605,7 @@ config KEXEC_JUMP
9885 config PHYSICAL_START
9886 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
9887 default "0x1000000"
9888+ range 0x400000 0x40000000
9889 ---help---
9890 This gives the physical address where the kernel is loaded.
9891
9892@@ -1666,6 +1669,7 @@ config X86_NEED_RELOCS
9893 config PHYSICAL_ALIGN
9894 hex "Alignment value to which kernel should be aligned" if X86_32
9895 default "0x1000000"
9896+ range 0x400000 0x1000000 if PAX_KERNEXEC
9897 range 0x2000 0x1000000
9898 ---help---
9899 This value puts the alignment restrictions on physical address
9900@@ -1741,9 +1745,10 @@ config DEBUG_HOTPLUG_CPU0
9901 If unsure, say N.
9902
9903 config COMPAT_VDSO
9904- def_bool y
9905+ def_bool n
9906 prompt "Compat VDSO support"
9907 depends on X86_32 || IA32_EMULATION
9908+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
9909 ---help---
9910 Map the 32-bit VDSO to the predictable old-style address too.
9911
9912diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
9913index c026cca..14657ae 100644
9914--- a/arch/x86/Kconfig.cpu
9915+++ b/arch/x86/Kconfig.cpu
9916@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
9917
9918 config X86_F00F_BUG
9919 def_bool y
9920- depends on M586MMX || M586TSC || M586 || M486
9921+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
9922
9923 config X86_INVD_BUG
9924 def_bool y
9925@@ -327,7 +327,7 @@ config X86_INVD_BUG
9926
9927 config X86_ALIGNMENT_16
9928 def_bool y
9929- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
9930+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
9931
9932 config X86_INTEL_USERCOPY
9933 def_bool y
9934@@ -373,7 +373,7 @@ config X86_CMPXCHG64
9935 # generates cmov.
9936 config X86_CMOV
9937 def_bool y
9938- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
9939+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
9940
9941 config X86_MINIMUM_CPU_FAMILY
9942 int
9943diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
9944index b322f12..652d0d9 100644
9945--- a/arch/x86/Kconfig.debug
9946+++ b/arch/x86/Kconfig.debug
9947@@ -84,7 +84,7 @@ config X86_PTDUMP
9948 config DEBUG_RODATA
9949 bool "Write protect kernel read-only data structures"
9950 default y
9951- depends on DEBUG_KERNEL
9952+ depends on DEBUG_KERNEL && BROKEN
9953 ---help---
9954 Mark the kernel read-only data as write-protected in the pagetables,
9955 in order to catch accidental (and incorrect) writes to such const
9956@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
9957
9958 config DEBUG_SET_MODULE_RONX
9959 bool "Set loadable kernel module data as NX and text as RO"
9960- depends on MODULES
9961+ depends on MODULES && BROKEN
9962 ---help---
9963 This option helps catch unintended modifications to loadable
9964 kernel module's text and read-only data. It also prevents execution
9965@@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
9966
9967 config DEBUG_STRICT_USER_COPY_CHECKS
9968 bool "Strict copy size checks"
9969- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
9970+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
9971 ---help---
9972 Enabling this option turns a certain set of sanity checks for user
9973 copy operations into compile time failures.
9974diff --git a/arch/x86/Makefile b/arch/x86/Makefile
9975index e71fc42..7829607 100644
9976--- a/arch/x86/Makefile
9977+++ b/arch/x86/Makefile
9978@@ -50,6 +50,7 @@ else
9979 UTS_MACHINE := x86_64
9980 CHECKFLAGS += -D__x86_64__ -m64
9981
9982+ biarch := $(call cc-option,-m64)
9983 KBUILD_AFLAGS += -m64
9984 KBUILD_CFLAGS += -m64
9985
9986@@ -230,3 +231,12 @@ define archhelp
9987 echo ' FDARGS="..." arguments for the booted kernel'
9988 echo ' FDINITRD=file initrd for the booted kernel'
9989 endef
9990+
9991+define OLD_LD
9992+
9993+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
9994+*** Please upgrade your binutils to 2.18 or newer
9995+endef
9996+
9997+archprepare:
9998+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
9999diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
10000index 379814b..add62ce 100644
10001--- a/arch/x86/boot/Makefile
10002+++ b/arch/x86/boot/Makefile
10003@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
10004 $(call cc-option, -fno-stack-protector) \
10005 $(call cc-option, -mpreferred-stack-boundary=2)
10006 KBUILD_CFLAGS += $(call cc-option, -m32)
10007+ifdef CONSTIFY_PLUGIN
10008+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10009+endif
10010 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10011 GCOV_PROFILE := n
10012
10013diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
10014index 878e4b9..20537ab 100644
10015--- a/arch/x86/boot/bitops.h
10016+++ b/arch/x86/boot/bitops.h
10017@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10018 u8 v;
10019 const u32 *p = (const u32 *)addr;
10020
10021- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10022+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10023 return v;
10024 }
10025
10026@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10027
10028 static inline void set_bit(int nr, void *addr)
10029 {
10030- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10031+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10032 }
10033
10034 #endif /* BOOT_BITOPS_H */
10035diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
10036index 18997e5..83d9c67 100644
10037--- a/arch/x86/boot/boot.h
10038+++ b/arch/x86/boot/boot.h
10039@@ -85,7 +85,7 @@ static inline void io_delay(void)
10040 static inline u16 ds(void)
10041 {
10042 u16 seg;
10043- asm("movw %%ds,%0" : "=rm" (seg));
10044+ asm volatile("movw %%ds,%0" : "=rm" (seg));
10045 return seg;
10046 }
10047
10048@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
10049 static inline int memcmp(const void *s1, const void *s2, size_t len)
10050 {
10051 u8 diff;
10052- asm("repe; cmpsb; setnz %0"
10053+ asm volatile("repe; cmpsb; setnz %0"
10054 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
10055 return diff;
10056 }
10057diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
10058index 8a84501..b2d165f 100644
10059--- a/arch/x86/boot/compressed/Makefile
10060+++ b/arch/x86/boot/compressed/Makefile
10061@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
10062 KBUILD_CFLAGS += $(cflags-y)
10063 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
10064 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
10065+ifdef CONSTIFY_PLUGIN
10066+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10067+endif
10068
10069 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10070 GCOV_PROFILE := n
10071diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
10072index f8fa411..c570c53 100644
10073--- a/arch/x86/boot/compressed/eboot.c
10074+++ b/arch/x86/boot/compressed/eboot.c
10075@@ -145,7 +145,6 @@ again:
10076 *addr = max_addr;
10077 }
10078
10079-free_pool:
10080 efi_call_phys1(sys_table->boottime->free_pool, map);
10081
10082 fail:
10083@@ -209,7 +208,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
10084 if (i == map_size / desc_size)
10085 status = EFI_NOT_FOUND;
10086
10087-free_pool:
10088 efi_call_phys1(sys_table->boottime->free_pool, map);
10089 fail:
10090 return status;
10091diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
10092index 1e3184f..0d11e2e 100644
10093--- a/arch/x86/boot/compressed/head_32.S
10094+++ b/arch/x86/boot/compressed/head_32.S
10095@@ -118,7 +118,7 @@ preferred_addr:
10096 notl %eax
10097 andl %eax, %ebx
10098 #else
10099- movl $LOAD_PHYSICAL_ADDR, %ebx
10100+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10101 #endif
10102
10103 /* Target address to relocate to for decompression */
10104@@ -204,7 +204,7 @@ relocated:
10105 * and where it was actually loaded.
10106 */
10107 movl %ebp, %ebx
10108- subl $LOAD_PHYSICAL_ADDR, %ebx
10109+ subl $____LOAD_PHYSICAL_ADDR, %ebx
10110 jz 2f /* Nothing to be done if loaded at compiled addr. */
10111 /*
10112 * Process relocations.
10113@@ -212,8 +212,7 @@ relocated:
10114
10115 1: subl $4, %edi
10116 movl (%edi), %ecx
10117- testl %ecx, %ecx
10118- jz 2f
10119+ jecxz 2f
10120 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
10121 jmp 1b
10122 2:
10123diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
10124index f5d1aaa..cce11dc 100644
10125--- a/arch/x86/boot/compressed/head_64.S
10126+++ b/arch/x86/boot/compressed/head_64.S
10127@@ -91,7 +91,7 @@ ENTRY(startup_32)
10128 notl %eax
10129 andl %eax, %ebx
10130 #else
10131- movl $LOAD_PHYSICAL_ADDR, %ebx
10132+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10133 #endif
10134
10135 /* Target address to relocate to for decompression */
10136@@ -273,7 +273,7 @@ preferred_addr:
10137 notq %rax
10138 andq %rax, %rbp
10139 #else
10140- movq $LOAD_PHYSICAL_ADDR, %rbp
10141+ movq $____LOAD_PHYSICAL_ADDR, %rbp
10142 #endif
10143
10144 /* Target address to relocate to for decompression */
10145diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
10146index 88f7ff6..ed695dd 100644
10147--- a/arch/x86/boot/compressed/misc.c
10148+++ b/arch/x86/boot/compressed/misc.c
10149@@ -303,7 +303,7 @@ static void parse_elf(void *output)
10150 case PT_LOAD:
10151 #ifdef CONFIG_RELOCATABLE
10152 dest = output;
10153- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
10154+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
10155 #else
10156 dest = (void *)(phdr->p_paddr);
10157 #endif
10158@@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
10159 error("Destination address too large");
10160 #endif
10161 #ifndef CONFIG_RELOCATABLE
10162- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
10163+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
10164 error("Wrong destination address");
10165 #endif
10166
10167diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
10168index 4d3ff03..e4972ff 100644
10169--- a/arch/x86/boot/cpucheck.c
10170+++ b/arch/x86/boot/cpucheck.c
10171@@ -74,7 +74,7 @@ static int has_fpu(void)
10172 u16 fcw = -1, fsw = -1;
10173 u32 cr0;
10174
10175- asm("movl %%cr0,%0" : "=r" (cr0));
10176+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
10177 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
10178 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
10179 asm volatile("movl %0,%%cr0" : : "r" (cr0));
10180@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
10181 {
10182 u32 f0, f1;
10183
10184- asm("pushfl ; "
10185+ asm volatile("pushfl ; "
10186 "pushfl ; "
10187 "popl %0 ; "
10188 "movl %0,%1 ; "
10189@@ -115,7 +115,7 @@ static void get_flags(void)
10190 set_bit(X86_FEATURE_FPU, cpu.flags);
10191
10192 if (has_eflag(X86_EFLAGS_ID)) {
10193- asm("cpuid"
10194+ asm volatile("cpuid"
10195 : "=a" (max_intel_level),
10196 "=b" (cpu_vendor[0]),
10197 "=d" (cpu_vendor[1]),
10198@@ -124,7 +124,7 @@ static void get_flags(void)
10199
10200 if (max_intel_level >= 0x00000001 &&
10201 max_intel_level <= 0x0000ffff) {
10202- asm("cpuid"
10203+ asm volatile("cpuid"
10204 : "=a" (tfms),
10205 "=c" (cpu.flags[4]),
10206 "=d" (cpu.flags[0])
10207@@ -136,7 +136,7 @@ static void get_flags(void)
10208 cpu.model += ((tfms >> 16) & 0xf) << 4;
10209 }
10210
10211- asm("cpuid"
10212+ asm volatile("cpuid"
10213 : "=a" (max_amd_level)
10214 : "a" (0x80000000)
10215 : "ebx", "ecx", "edx");
10216@@ -144,7 +144,7 @@ static void get_flags(void)
10217 if (max_amd_level >= 0x80000001 &&
10218 max_amd_level <= 0x8000ffff) {
10219 u32 eax = 0x80000001;
10220- asm("cpuid"
10221+ asm volatile("cpuid"
10222 : "+a" (eax),
10223 "=c" (cpu.flags[6]),
10224 "=d" (cpu.flags[1])
10225@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10226 u32 ecx = MSR_K7_HWCR;
10227 u32 eax, edx;
10228
10229- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10230+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10231 eax &= ~(1 << 15);
10232- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10233+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10234
10235 get_flags(); /* Make sure it really did something */
10236 err = check_flags();
10237@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10238 u32 ecx = MSR_VIA_FCR;
10239 u32 eax, edx;
10240
10241- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10242+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10243 eax |= (1<<1)|(1<<7);
10244- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10245+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10246
10247 set_bit(X86_FEATURE_CX8, cpu.flags);
10248 err = check_flags();
10249@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10250 u32 eax, edx;
10251 u32 level = 1;
10252
10253- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10254- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10255- asm("cpuid"
10256+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10257+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10258+ asm volatile("cpuid"
10259 : "+a" (level), "=d" (cpu.flags[0])
10260 : : "ecx", "ebx");
10261- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10262+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10263
10264 err = check_flags();
10265 }
10266diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
10267index 944ce59..87ee37a 100644
10268--- a/arch/x86/boot/header.S
10269+++ b/arch/x86/boot/header.S
10270@@ -401,10 +401,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
10271 # single linked list of
10272 # struct setup_data
10273
10274-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
10275+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
10276
10277 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
10278+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
10279+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
10280+#else
10281 #define VO_INIT_SIZE (VO__end - VO__text)
10282+#endif
10283 #if ZO_INIT_SIZE > VO_INIT_SIZE
10284 #define INIT_SIZE ZO_INIT_SIZE
10285 #else
10286diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
10287index db75d07..8e6d0af 100644
10288--- a/arch/x86/boot/memory.c
10289+++ b/arch/x86/boot/memory.c
10290@@ -19,7 +19,7 @@
10291
10292 static int detect_memory_e820(void)
10293 {
10294- int count = 0;
10295+ unsigned int count = 0;
10296 struct biosregs ireg, oreg;
10297 struct e820entry *desc = boot_params.e820_map;
10298 static struct e820entry buf; /* static so it is zeroed */
10299diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
10300index 11e8c6e..fdbb1ed 100644
10301--- a/arch/x86/boot/video-vesa.c
10302+++ b/arch/x86/boot/video-vesa.c
10303@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
10304
10305 boot_params.screen_info.vesapm_seg = oreg.es;
10306 boot_params.screen_info.vesapm_off = oreg.di;
10307+ boot_params.screen_info.vesapm_size = oreg.cx;
10308 }
10309
10310 /*
10311diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
10312index 43eda28..5ab5fdb 100644
10313--- a/arch/x86/boot/video.c
10314+++ b/arch/x86/boot/video.c
10315@@ -96,7 +96,7 @@ static void store_mode_params(void)
10316 static unsigned int get_entry(void)
10317 {
10318 char entry_buf[4];
10319- int i, len = 0;
10320+ unsigned int i, len = 0;
10321 int key;
10322 unsigned int v;
10323
10324diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
10325index 5b577d5..3c1fed4 100644
10326--- a/arch/x86/crypto/aes-x86_64-asm_64.S
10327+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
10328@@ -8,6 +8,8 @@
10329 * including this sentence is retained in full.
10330 */
10331
10332+#include <asm/alternative-asm.h>
10333+
10334 .extern crypto_ft_tab
10335 .extern crypto_it_tab
10336 .extern crypto_fl_tab
10337@@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
10338 je B192; \
10339 leaq 32(r9),r9;
10340
10341+#define ret pax_force_retaddr 0, 1; ret
10342+
10343 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
10344 movq r1,r2; \
10345 movq r3,r4; \
10346diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
10347index 3470624..201259d 100644
10348--- a/arch/x86/crypto/aesni-intel_asm.S
10349+++ b/arch/x86/crypto/aesni-intel_asm.S
10350@@ -31,6 +31,7 @@
10351
10352 #include <linux/linkage.h>
10353 #include <asm/inst.h>
10354+#include <asm/alternative-asm.h>
10355
10356 #ifdef __x86_64__
10357 .data
10358@@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
10359 pop %r14
10360 pop %r13
10361 pop %r12
10362+ pax_force_retaddr 0, 1
10363 ret
10364+ENDPROC(aesni_gcm_dec)
10365
10366
10367 /*****************************************************************************
10368@@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
10369 pop %r14
10370 pop %r13
10371 pop %r12
10372+ pax_force_retaddr 0, 1
10373 ret
10374+ENDPROC(aesni_gcm_enc)
10375
10376 #endif
10377
10378@@ -1714,6 +1719,7 @@ _key_expansion_256a:
10379 pxor %xmm1, %xmm0
10380 movaps %xmm0, (TKEYP)
10381 add $0x10, TKEYP
10382+ pax_force_retaddr_bts
10383 ret
10384
10385 .align 4
10386@@ -1738,6 +1744,7 @@ _key_expansion_192a:
10387 shufps $0b01001110, %xmm2, %xmm1
10388 movaps %xmm1, 0x10(TKEYP)
10389 add $0x20, TKEYP
10390+ pax_force_retaddr_bts
10391 ret
10392
10393 .align 4
10394@@ -1757,6 +1764,7 @@ _key_expansion_192b:
10395
10396 movaps %xmm0, (TKEYP)
10397 add $0x10, TKEYP
10398+ pax_force_retaddr_bts
10399 ret
10400
10401 .align 4
10402@@ -1769,6 +1777,7 @@ _key_expansion_256b:
10403 pxor %xmm1, %xmm2
10404 movaps %xmm2, (TKEYP)
10405 add $0x10, TKEYP
10406+ pax_force_retaddr_bts
10407 ret
10408
10409 /*
10410@@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
10411 #ifndef __x86_64__
10412 popl KEYP
10413 #endif
10414+ pax_force_retaddr 0, 1
10415 ret
10416+ENDPROC(aesni_set_key)
10417
10418 /*
10419 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
10420@@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
10421 popl KLEN
10422 popl KEYP
10423 #endif
10424+ pax_force_retaddr 0, 1
10425 ret
10426+ENDPROC(aesni_enc)
10427
10428 /*
10429 * _aesni_enc1: internal ABI
10430@@ -1959,6 +1972,7 @@ _aesni_enc1:
10431 AESENC KEY STATE
10432 movaps 0x70(TKEYP), KEY
10433 AESENCLAST KEY STATE
10434+ pax_force_retaddr_bts
10435 ret
10436
10437 /*
10438@@ -2067,6 +2081,7 @@ _aesni_enc4:
10439 AESENCLAST KEY STATE2
10440 AESENCLAST KEY STATE3
10441 AESENCLAST KEY STATE4
10442+ pax_force_retaddr_bts
10443 ret
10444
10445 /*
10446@@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
10447 popl KLEN
10448 popl KEYP
10449 #endif
10450+ pax_force_retaddr 0, 1
10451 ret
10452+ENDPROC(aesni_dec)
10453
10454 /*
10455 * _aesni_dec1: internal ABI
10456@@ -2146,6 +2163,7 @@ _aesni_dec1:
10457 AESDEC KEY STATE
10458 movaps 0x70(TKEYP), KEY
10459 AESDECLAST KEY STATE
10460+ pax_force_retaddr_bts
10461 ret
10462
10463 /*
10464@@ -2254,6 +2272,7 @@ _aesni_dec4:
10465 AESDECLAST KEY STATE2
10466 AESDECLAST KEY STATE3
10467 AESDECLAST KEY STATE4
10468+ pax_force_retaddr_bts
10469 ret
10470
10471 /*
10472@@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
10473 popl KEYP
10474 popl LEN
10475 #endif
10476+ pax_force_retaddr 0, 1
10477 ret
10478+ENDPROC(aesni_ecb_enc)
10479
10480 /*
10481 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10482@@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
10483 popl KEYP
10484 popl LEN
10485 #endif
10486+ pax_force_retaddr 0, 1
10487 ret
10488+ENDPROC(aesni_ecb_dec)
10489
10490 /*
10491 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10492@@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
10493 popl LEN
10494 popl IVP
10495 #endif
10496+ pax_force_retaddr 0, 1
10497 ret
10498+ENDPROC(aesni_cbc_enc)
10499
10500 /*
10501 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10502@@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
10503 popl LEN
10504 popl IVP
10505 #endif
10506+ pax_force_retaddr 0, 1
10507 ret
10508+ENDPROC(aesni_cbc_dec)
10509
10510 #ifdef __x86_64__
10511 .align 16
10512@@ -2526,6 +2553,7 @@ _aesni_inc_init:
10513 mov $1, TCTR_LOW
10514 MOVQ_R64_XMM TCTR_LOW INC
10515 MOVQ_R64_XMM CTR TCTR_LOW
10516+ pax_force_retaddr_bts
10517 ret
10518
10519 /*
10520@@ -2554,6 +2582,7 @@ _aesni_inc:
10521 .Linc_low:
10522 movaps CTR, IV
10523 PSHUFB_XMM BSWAP_MASK IV
10524+ pax_force_retaddr_bts
10525 ret
10526
10527 /*
10528@@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
10529 .Lctr_enc_ret:
10530 movups IV, (IVP)
10531 .Lctr_enc_just_ret:
10532+ pax_force_retaddr 0, 1
10533 ret
10534+ENDPROC(aesni_ctr_enc)
10535 #endif
10536diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10537index 391d245..67f35c2 100644
10538--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
10539+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10540@@ -20,6 +20,8 @@
10541 *
10542 */
10543
10544+#include <asm/alternative-asm.h>
10545+
10546 .file "blowfish-x86_64-asm.S"
10547 .text
10548
10549@@ -151,9 +153,11 @@ __blowfish_enc_blk:
10550 jnz __enc_xor;
10551
10552 write_block();
10553+ pax_force_retaddr 0, 1
10554 ret;
10555 __enc_xor:
10556 xor_block();
10557+ pax_force_retaddr 0, 1
10558 ret;
10559
10560 .align 8
10561@@ -188,6 +192,7 @@ blowfish_dec_blk:
10562
10563 movq %r11, %rbp;
10564
10565+ pax_force_retaddr 0, 1
10566 ret;
10567
10568 /**********************************************************************
10569@@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
10570
10571 popq %rbx;
10572 popq %rbp;
10573+ pax_force_retaddr 0, 1
10574 ret;
10575
10576 __enc_xor4:
10577@@ -349,6 +355,7 @@ __enc_xor4:
10578
10579 popq %rbx;
10580 popq %rbp;
10581+ pax_force_retaddr 0, 1
10582 ret;
10583
10584 .align 8
10585@@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
10586 popq %rbx;
10587 popq %rbp;
10588
10589+ pax_force_retaddr 0, 1
10590 ret;
10591
10592diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
10593index 0b33743..7a56206 100644
10594--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
10595+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
10596@@ -20,6 +20,8 @@
10597 *
10598 */
10599
10600+#include <asm/alternative-asm.h>
10601+
10602 .file "camellia-x86_64-asm_64.S"
10603 .text
10604
10605@@ -229,12 +231,14 @@ __enc_done:
10606 enc_outunpack(mov, RT1);
10607
10608 movq RRBP, %rbp;
10609+ pax_force_retaddr 0, 1
10610 ret;
10611
10612 __enc_xor:
10613 enc_outunpack(xor, RT1);
10614
10615 movq RRBP, %rbp;
10616+ pax_force_retaddr 0, 1
10617 ret;
10618
10619 .global camellia_dec_blk;
10620@@ -275,6 +279,7 @@ __dec_rounds16:
10621 dec_outunpack();
10622
10623 movq RRBP, %rbp;
10624+ pax_force_retaddr 0, 1
10625 ret;
10626
10627 /**********************************************************************
10628@@ -468,6 +473,7 @@ __enc2_done:
10629
10630 movq RRBP, %rbp;
10631 popq %rbx;
10632+ pax_force_retaddr 0, 1
10633 ret;
10634
10635 __enc2_xor:
10636@@ -475,6 +481,7 @@ __enc2_xor:
10637
10638 movq RRBP, %rbp;
10639 popq %rbx;
10640+ pax_force_retaddr 0, 1
10641 ret;
10642
10643 .global camellia_dec_blk_2way;
10644@@ -517,4 +524,5 @@ __dec2_rounds16:
10645
10646 movq RRBP, %rbp;
10647 movq RXOR, %rbx;
10648+ pax_force_retaddr 0, 1
10649 ret;
10650diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10651index 15b00ac..2071784 100644
10652--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10653+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10654@@ -23,6 +23,8 @@
10655 *
10656 */
10657
10658+#include <asm/alternative-asm.h>
10659+
10660 .file "cast5-avx-x86_64-asm_64.S"
10661
10662 .extern cast_s1
10663@@ -281,6 +283,7 @@ __skip_enc:
10664 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
10665 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
10666
10667+ pax_force_retaddr 0, 1
10668 ret;
10669
10670 .align 16
10671@@ -353,6 +356,7 @@ __dec_tail:
10672 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
10673 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
10674
10675+ pax_force_retaddr 0, 1
10676 ret;
10677
10678 __skip_dec:
10679@@ -392,6 +396,7 @@ cast5_ecb_enc_16way:
10680 vmovdqu RR4, (6*4*4)(%r11);
10681 vmovdqu RL4, (7*4*4)(%r11);
10682
10683+ pax_force_retaddr
10684 ret;
10685
10686 .align 16
10687@@ -427,6 +432,7 @@ cast5_ecb_dec_16way:
10688 vmovdqu RR4, (6*4*4)(%r11);
10689 vmovdqu RL4, (7*4*4)(%r11);
10690
10691+ pax_force_retaddr
10692 ret;
10693
10694 .align 16
10695@@ -479,6 +485,7 @@ cast5_cbc_dec_16way:
10696
10697 popq %r12;
10698
10699+ pax_force_retaddr
10700 ret;
10701
10702 .align 16
10703@@ -555,4 +562,5 @@ cast5_ctr_16way:
10704
10705 popq %r12;
10706
10707+ pax_force_retaddr
10708 ret;
10709diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
10710index 2569d0d..637c289 100644
10711--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
10712+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
10713@@ -23,6 +23,8 @@
10714 *
10715 */
10716
10717+#include <asm/alternative-asm.h>
10718+
10719 #include "glue_helper-asm-avx.S"
10720
10721 .file "cast6-avx-x86_64-asm_64.S"
10722@@ -294,6 +296,7 @@ __cast6_enc_blk8:
10723 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
10724 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
10725
10726+ pax_force_retaddr 0, 1
10727 ret;
10728
10729 .align 8
10730@@ -340,6 +343,7 @@ __cast6_dec_blk8:
10731 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
10732 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
10733
10734+ pax_force_retaddr 0, 1
10735 ret;
10736
10737 .align 8
10738@@ -361,6 +365,7 @@ cast6_ecb_enc_8way:
10739
10740 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10741
10742+ pax_force_retaddr
10743 ret;
10744
10745 .align 8
10746@@ -382,6 +387,7 @@ cast6_ecb_dec_8way:
10747
10748 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10749
10750+ pax_force_retaddr
10751 ret;
10752
10753 .align 8
10754@@ -408,6 +414,7 @@ cast6_cbc_dec_8way:
10755
10756 popq %r12;
10757
10758+ pax_force_retaddr
10759 ret;
10760
10761 .align 8
10762@@ -436,4 +443,5 @@ cast6_ctr_8way:
10763
10764 popq %r12;
10765
10766+ pax_force_retaddr
10767 ret;
10768diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
10769index 6214a9b..1f4fc9a 100644
10770--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
10771+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
10772@@ -1,3 +1,5 @@
10773+#include <asm/alternative-asm.h>
10774+
10775 # enter ECRYPT_encrypt_bytes
10776 .text
10777 .p2align 5
10778@@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
10779 add %r11,%rsp
10780 mov %rdi,%rax
10781 mov %rsi,%rdx
10782+ pax_force_retaddr 0, 1
10783 ret
10784 # bytesatleast65:
10785 ._bytesatleast65:
10786@@ -891,6 +894,7 @@ ECRYPT_keysetup:
10787 add %r11,%rsp
10788 mov %rdi,%rax
10789 mov %rsi,%rdx
10790+ pax_force_retaddr
10791 ret
10792 # enter ECRYPT_ivsetup
10793 .text
10794@@ -917,4 +921,5 @@ ECRYPT_ivsetup:
10795 add %r11,%rsp
10796 mov %rdi,%rax
10797 mov %rsi,%rdx
10798+ pax_force_retaddr
10799 ret
10800diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
10801index 02b0e9f..cf4cf5c 100644
10802--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
10803+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
10804@@ -24,6 +24,8 @@
10805 *
10806 */
10807
10808+#include <asm/alternative-asm.h>
10809+
10810 #include "glue_helper-asm-avx.S"
10811
10812 .file "serpent-avx-x86_64-asm_64.S"
10813@@ -618,6 +620,7 @@ __serpent_enc_blk8_avx:
10814 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
10815 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
10816
10817+ pax_force_retaddr
10818 ret;
10819
10820 .align 8
10821@@ -673,6 +676,7 @@ __serpent_dec_blk8_avx:
10822 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
10823 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
10824
10825+ pax_force_retaddr
10826 ret;
10827
10828 .align 8
10829@@ -692,6 +696,7 @@ serpent_ecb_enc_8way_avx:
10830
10831 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10832
10833+ pax_force_retaddr
10834 ret;
10835
10836 .align 8
10837@@ -711,6 +716,7 @@ serpent_ecb_dec_8way_avx:
10838
10839 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
10840
10841+ pax_force_retaddr
10842 ret;
10843
10844 .align 8
10845@@ -730,6 +736,7 @@ serpent_cbc_dec_8way_avx:
10846
10847 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
10848
10849+ pax_force_retaddr
10850 ret;
10851
10852 .align 8
10853@@ -751,4 +758,5 @@ serpent_ctr_8way_avx:
10854
10855 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10856
10857+ pax_force_retaddr
10858 ret;
10859diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
10860index 3ee1ff0..cbc568b 100644
10861--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
10862+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
10863@@ -24,6 +24,8 @@
10864 *
10865 */
10866
10867+#include <asm/alternative-asm.h>
10868+
10869 .file "serpent-sse2-x86_64-asm_64.S"
10870 .text
10871
10872@@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
10873 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
10874 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
10875
10876+ pax_force_retaddr
10877 ret;
10878
10879 __enc_xor8:
10880 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
10881 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
10882
10883+ pax_force_retaddr
10884 ret;
10885
10886 .align 8
10887@@ -755,4 +759,5 @@ serpent_dec_blk_8way:
10888 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
10889 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
10890
10891+ pax_force_retaddr
10892 ret;
10893diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
10894index 49d6987..df66bd4 100644
10895--- a/arch/x86/crypto/sha1_ssse3_asm.S
10896+++ b/arch/x86/crypto/sha1_ssse3_asm.S
10897@@ -28,6 +28,8 @@
10898 * (at your option) any later version.
10899 */
10900
10901+#include <asm/alternative-asm.h>
10902+
10903 #define CTX %rdi // arg1
10904 #define BUF %rsi // arg2
10905 #define CNT %rdx // arg3
10906@@ -104,6 +106,7 @@
10907 pop %r12
10908 pop %rbp
10909 pop %rbx
10910+ pax_force_retaddr 0, 1
10911 ret
10912
10913 .size \name, .-\name
10914diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
10915index ebac16b..8092eb9 100644
10916--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
10917+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
10918@@ -23,6 +23,8 @@
10919 *
10920 */
10921
10922+#include <asm/alternative-asm.h>
10923+
10924 #include "glue_helper-asm-avx.S"
10925
10926 .file "twofish-avx-x86_64-asm_64.S"
10927@@ -283,6 +285,7 @@ __twofish_enc_blk8:
10928 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
10929 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
10930
10931+ pax_force_retaddr 0, 1
10932 ret;
10933
10934 .align 8
10935@@ -324,6 +327,7 @@ __twofish_dec_blk8:
10936 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
10937 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
10938
10939+ pax_force_retaddr 0, 1
10940 ret;
10941
10942 .align 8
10943@@ -345,6 +349,7 @@ twofish_ecb_enc_8way:
10944
10945 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
10946
10947+ pax_force_retaddr 0, 1
10948 ret;
10949
10950 .align 8
10951@@ -366,6 +371,7 @@ twofish_ecb_dec_8way:
10952
10953 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10954
10955+ pax_force_retaddr 0, 1
10956 ret;
10957
10958 .align 8
10959@@ -392,6 +398,7 @@ twofish_cbc_dec_8way:
10960
10961 popq %r12;
10962
10963+ pax_force_retaddr 0, 1
10964 ret;
10965
10966 .align 8
10967@@ -420,4 +427,5 @@ twofish_ctr_8way:
10968
10969 popq %r12;
10970
10971+ pax_force_retaddr 0, 1
10972 ret;
10973diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
10974index 5b012a2..36d5364 100644
10975--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
10976+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
10977@@ -20,6 +20,8 @@
10978 *
10979 */
10980
10981+#include <asm/alternative-asm.h>
10982+
10983 .file "twofish-x86_64-asm-3way.S"
10984 .text
10985
10986@@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
10987 popq %r13;
10988 popq %r14;
10989 popq %r15;
10990+ pax_force_retaddr 0, 1
10991 ret;
10992
10993 __enc_xor3:
10994@@ -271,6 +274,7 @@ __enc_xor3:
10995 popq %r13;
10996 popq %r14;
10997 popq %r15;
10998+ pax_force_retaddr 0, 1
10999 ret;
11000
11001 .global twofish_dec_blk_3way
11002@@ -312,5 +316,6 @@ twofish_dec_blk_3way:
11003 popq %r13;
11004 popq %r14;
11005 popq %r15;
11006+ pax_force_retaddr 0, 1
11007 ret;
11008
11009diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
11010index 7bcf3fc..f53832f 100644
11011--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
11012+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
11013@@ -21,6 +21,7 @@
11014 .text
11015
11016 #include <asm/asm-offsets.h>
11017+#include <asm/alternative-asm.h>
11018
11019 #define a_offset 0
11020 #define b_offset 4
11021@@ -268,6 +269,7 @@ twofish_enc_blk:
11022
11023 popq R1
11024 movq $1,%rax
11025+ pax_force_retaddr 0, 1
11026 ret
11027
11028 twofish_dec_blk:
11029@@ -319,4 +321,5 @@ twofish_dec_blk:
11030
11031 popq R1
11032 movq $1,%rax
11033+ pax_force_retaddr 0, 1
11034 ret
11035diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
11036index a703af1..f5b9c36 100644
11037--- a/arch/x86/ia32/ia32_aout.c
11038+++ b/arch/x86/ia32/ia32_aout.c
11039@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
11040 unsigned long dump_start, dump_size;
11041 struct user32 dump;
11042
11043+ memset(&dump, 0, sizeof(dump));
11044+
11045 fs = get_fs();
11046 set_fs(KERNEL_DS);
11047 has_dumped = 1;
11048diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
11049index a1daf4a..f8c4537 100644
11050--- a/arch/x86/ia32/ia32_signal.c
11051+++ b/arch/x86/ia32/ia32_signal.c
11052@@ -348,7 +348,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
11053 sp -= frame_size;
11054 /* Align the stack pointer according to the i386 ABI,
11055 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
11056- sp = ((sp + 4) & -16ul) - 4;
11057+ sp = ((sp - 12) & -16ul) - 4;
11058 return (void __user *) sp;
11059 }
11060
11061@@ -406,7 +406,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
11062 * These are actually not used anymore, but left because some
11063 * gdb versions depend on them as a marker.
11064 */
11065- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11066+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11067 } put_user_catch(err);
11068
11069 if (err)
11070@@ -448,7 +448,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
11071 0xb8,
11072 __NR_ia32_rt_sigreturn,
11073 0x80cd,
11074- 0,
11075+ 0
11076 };
11077
11078 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
11079@@ -471,16 +471,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
11080
11081 if (ka->sa.sa_flags & SA_RESTORER)
11082 restorer = ka->sa.sa_restorer;
11083+ else if (current->mm->context.vdso)
11084+ /* Return stub is in 32bit vsyscall page */
11085+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
11086 else
11087- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
11088- rt_sigreturn);
11089+ restorer = &frame->retcode;
11090 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
11091
11092 /*
11093 * Not actually used anymore, but left because some gdb
11094 * versions need it.
11095 */
11096- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11097+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11098 } put_user_catch(err);
11099
11100 err |= copy_siginfo_to_user32(&frame->info, info);
11101diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
11102index 142c4ce..19b683f 100644
11103--- a/arch/x86/ia32/ia32entry.S
11104+++ b/arch/x86/ia32/ia32entry.S
11105@@ -15,8 +15,10 @@
11106 #include <asm/irqflags.h>
11107 #include <asm/asm.h>
11108 #include <asm/smap.h>
11109+#include <asm/pgtable.h>
11110 #include <linux/linkage.h>
11111 #include <linux/err.h>
11112+#include <asm/alternative-asm.h>
11113
11114 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
11115 #include <linux/elf-em.h>
11116@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
11117 ENDPROC(native_irq_enable_sysexit)
11118 #endif
11119
11120+ .macro pax_enter_kernel_user
11121+ pax_set_fptr_mask
11122+#ifdef CONFIG_PAX_MEMORY_UDEREF
11123+ call pax_enter_kernel_user
11124+#endif
11125+ .endm
11126+
11127+ .macro pax_exit_kernel_user
11128+#ifdef CONFIG_PAX_MEMORY_UDEREF
11129+ call pax_exit_kernel_user
11130+#endif
11131+#ifdef CONFIG_PAX_RANDKSTACK
11132+ pushq %rax
11133+ pushq %r11
11134+ call pax_randomize_kstack
11135+ popq %r11
11136+ popq %rax
11137+#endif
11138+ .endm
11139+
11140+.macro pax_erase_kstack
11141+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
11142+ call pax_erase_kstack
11143+#endif
11144+.endm
11145+
11146 /*
11147 * 32bit SYSENTER instruction entry.
11148 *
11149@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
11150 CFI_REGISTER rsp,rbp
11151 SWAPGS_UNSAFE_STACK
11152 movq PER_CPU_VAR(kernel_stack), %rsp
11153- addq $(KERNEL_STACK_OFFSET),%rsp
11154- /*
11155- * No need to follow this irqs on/off section: the syscall
11156- * disabled irqs, here we enable it straight after entry:
11157- */
11158- ENABLE_INTERRUPTS(CLBR_NONE)
11159 movl %ebp,%ebp /* zero extension */
11160 pushq_cfi $__USER32_DS
11161 /*CFI_REL_OFFSET ss,0*/
11162@@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
11163 CFI_REL_OFFSET rsp,0
11164 pushfq_cfi
11165 /*CFI_REL_OFFSET rflags,0*/
11166- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
11167- CFI_REGISTER rip,r10
11168+ orl $X86_EFLAGS_IF,(%rsp)
11169+ GET_THREAD_INFO(%r11)
11170+ movl TI_sysenter_return(%r11), %r11d
11171+ CFI_REGISTER rip,r11
11172 pushq_cfi $__USER32_CS
11173 /*CFI_REL_OFFSET cs,0*/
11174 movl %eax, %eax
11175- pushq_cfi %r10
11176+ pushq_cfi %r11
11177 CFI_REL_OFFSET rip,0
11178 pushq_cfi %rax
11179 cld
11180 SAVE_ARGS 0,1,0
11181+ pax_enter_kernel_user
11182+
11183+#ifdef CONFIG_PAX_RANDKSTACK
11184+ pax_erase_kstack
11185+#endif
11186+
11187+ /*
11188+ * No need to follow this irqs on/off section: the syscall
11189+ * disabled irqs, here we enable it straight after entry:
11190+ */
11191+ ENABLE_INTERRUPTS(CLBR_NONE)
11192 /* no need to do an access_ok check here because rbp has been
11193 32bit zero extended */
11194+
11195+#ifdef CONFIG_PAX_MEMORY_UDEREF
11196+ mov $PAX_USER_SHADOW_BASE,%r11
11197+ add %r11,%rbp
11198+#endif
11199+
11200 ASM_STAC
11201 1: movl (%rbp),%ebp
11202 _ASM_EXTABLE(1b,ia32_badarg)
11203 ASM_CLAC
11204- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11205- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11206+ GET_THREAD_INFO(%r11)
11207+ orl $TS_COMPAT,TI_status(%r11)
11208+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11209 CFI_REMEMBER_STATE
11210 jnz sysenter_tracesys
11211 cmpq $(IA32_NR_syscalls-1),%rax
11212@@ -162,12 +204,15 @@ sysenter_do_call:
11213 sysenter_dispatch:
11214 call *ia32_sys_call_table(,%rax,8)
11215 movq %rax,RAX-ARGOFFSET(%rsp)
11216+ GET_THREAD_INFO(%r11)
11217 DISABLE_INTERRUPTS(CLBR_NONE)
11218 TRACE_IRQS_OFF
11219- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11220+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11221 jnz sysexit_audit
11222 sysexit_from_sys_call:
11223- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11224+ pax_exit_kernel_user
11225+ pax_erase_kstack
11226+ andl $~TS_COMPAT,TI_status(%r11)
11227 /* clear IF, that popfq doesn't enable interrupts early */
11228 andl $~0x200,EFLAGS-R11(%rsp)
11229 movl RIP-R11(%rsp),%edx /* User %eip */
11230@@ -193,6 +238,9 @@ sysexit_from_sys_call:
11231 movl %eax,%esi /* 2nd arg: syscall number */
11232 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
11233 call __audit_syscall_entry
11234+
11235+ pax_erase_kstack
11236+
11237 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
11238 cmpq $(IA32_NR_syscalls-1),%rax
11239 ja ia32_badsys
11240@@ -204,7 +252,7 @@ sysexit_from_sys_call:
11241 .endm
11242
11243 .macro auditsys_exit exit
11244- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11245+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11246 jnz ia32_ret_from_sys_call
11247 TRACE_IRQS_ON
11248 ENABLE_INTERRUPTS(CLBR_NONE)
11249@@ -215,11 +263,12 @@ sysexit_from_sys_call:
11250 1: setbe %al /* 1 if error, 0 if not */
11251 movzbl %al,%edi /* zero-extend that into %edi */
11252 call __audit_syscall_exit
11253+ GET_THREAD_INFO(%r11)
11254 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
11255 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
11256 DISABLE_INTERRUPTS(CLBR_NONE)
11257 TRACE_IRQS_OFF
11258- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11259+ testl %edi,TI_flags(%r11)
11260 jz \exit
11261 CLEAR_RREGS -ARGOFFSET
11262 jmp int_with_check
11263@@ -237,7 +286,7 @@ sysexit_audit:
11264
11265 sysenter_tracesys:
11266 #ifdef CONFIG_AUDITSYSCALL
11267- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11268+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11269 jz sysenter_auditsys
11270 #endif
11271 SAVE_REST
11272@@ -249,6 +298,9 @@ sysenter_tracesys:
11273 RESTORE_REST
11274 cmpq $(IA32_NR_syscalls-1),%rax
11275 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
11276+
11277+ pax_erase_kstack
11278+
11279 jmp sysenter_do_call
11280 CFI_ENDPROC
11281 ENDPROC(ia32_sysenter_target)
11282@@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
11283 ENTRY(ia32_cstar_target)
11284 CFI_STARTPROC32 simple
11285 CFI_SIGNAL_FRAME
11286- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
11287+ CFI_DEF_CFA rsp,0
11288 CFI_REGISTER rip,rcx
11289 /*CFI_REGISTER rflags,r11*/
11290 SWAPGS_UNSAFE_STACK
11291 movl %esp,%r8d
11292 CFI_REGISTER rsp,r8
11293 movq PER_CPU_VAR(kernel_stack),%rsp
11294+ SAVE_ARGS 8*6,0,0
11295+ pax_enter_kernel_user
11296+
11297+#ifdef CONFIG_PAX_RANDKSTACK
11298+ pax_erase_kstack
11299+#endif
11300+
11301 /*
11302 * No need to follow this irqs on/off section: the syscall
11303 * disabled irqs and here we enable it straight after entry:
11304 */
11305 ENABLE_INTERRUPTS(CLBR_NONE)
11306- SAVE_ARGS 8,0,0
11307 movl %eax,%eax /* zero extension */
11308 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
11309 movq %rcx,RIP-ARGOFFSET(%rsp)
11310@@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
11311 /* no need to do an access_ok check here because r8 has been
11312 32bit zero extended */
11313 /* hardware stack frame is complete now */
11314+
11315+#ifdef CONFIG_PAX_MEMORY_UDEREF
11316+ mov $PAX_USER_SHADOW_BASE,%r11
11317+ add %r11,%r8
11318+#endif
11319+
11320 ASM_STAC
11321 1: movl (%r8),%r9d
11322 _ASM_EXTABLE(1b,ia32_badarg)
11323 ASM_CLAC
11324- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11325- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11326+ GET_THREAD_INFO(%r11)
11327+ orl $TS_COMPAT,TI_status(%r11)
11328+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11329 CFI_REMEMBER_STATE
11330 jnz cstar_tracesys
11331 cmpq $IA32_NR_syscalls-1,%rax
11332@@ -319,12 +384,15 @@ cstar_do_call:
11333 cstar_dispatch:
11334 call *ia32_sys_call_table(,%rax,8)
11335 movq %rax,RAX-ARGOFFSET(%rsp)
11336+ GET_THREAD_INFO(%r11)
11337 DISABLE_INTERRUPTS(CLBR_NONE)
11338 TRACE_IRQS_OFF
11339- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11340+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11341 jnz sysretl_audit
11342 sysretl_from_sys_call:
11343- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11344+ pax_exit_kernel_user
11345+ pax_erase_kstack
11346+ andl $~TS_COMPAT,TI_status(%r11)
11347 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
11348 movl RIP-ARGOFFSET(%rsp),%ecx
11349 CFI_REGISTER rip,rcx
11350@@ -352,7 +420,7 @@ sysretl_audit:
11351
11352 cstar_tracesys:
11353 #ifdef CONFIG_AUDITSYSCALL
11354- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11355+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11356 jz cstar_auditsys
11357 #endif
11358 xchgl %r9d,%ebp
11359@@ -366,6 +434,9 @@ cstar_tracesys:
11360 xchgl %ebp,%r9d
11361 cmpq $(IA32_NR_syscalls-1),%rax
11362 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
11363+
11364+ pax_erase_kstack
11365+
11366 jmp cstar_do_call
11367 END(ia32_cstar_target)
11368
11369@@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
11370 CFI_REL_OFFSET rip,RIP-RIP
11371 PARAVIRT_ADJUST_EXCEPTION_FRAME
11372 SWAPGS
11373- /*
11374- * No need to follow this irqs on/off section: the syscall
11375- * disabled irqs and here we enable it straight after entry:
11376- */
11377- ENABLE_INTERRUPTS(CLBR_NONE)
11378 movl %eax,%eax
11379 pushq_cfi %rax
11380 cld
11381 /* note the registers are not zero extended to the sf.
11382 this could be a problem. */
11383 SAVE_ARGS 0,1,0
11384- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11385- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11386+ pax_enter_kernel_user
11387+
11388+#ifdef CONFIG_PAX_RANDKSTACK
11389+ pax_erase_kstack
11390+#endif
11391+
11392+ /*
11393+ * No need to follow this irqs on/off section: the syscall
11394+ * disabled irqs and here we enable it straight after entry:
11395+ */
11396+ ENABLE_INTERRUPTS(CLBR_NONE)
11397+ GET_THREAD_INFO(%r11)
11398+ orl $TS_COMPAT,TI_status(%r11)
11399+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11400 jnz ia32_tracesys
11401 cmpq $(IA32_NR_syscalls-1),%rax
11402 ja ia32_badsys
11403@@ -442,6 +520,9 @@ ia32_tracesys:
11404 RESTORE_REST
11405 cmpq $(IA32_NR_syscalls-1),%rax
11406 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
11407+
11408+ pax_erase_kstack
11409+
11410 jmp ia32_do_call
11411 END(ia32_syscall)
11412
11413diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
11414index d0b689b..34be51d 100644
11415--- a/arch/x86/ia32/sys_ia32.c
11416+++ b/arch/x86/ia32/sys_ia32.c
11417@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
11418 */
11419 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
11420 {
11421- typeof(ubuf->st_uid) uid = 0;
11422- typeof(ubuf->st_gid) gid = 0;
11423+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
11424+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
11425 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
11426 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
11427 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
11428@@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
11429 mm_segment_t old_fs = get_fs();
11430
11431 set_fs(KERNEL_DS);
11432- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
11433+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
11434 set_fs(old_fs);
11435 if (put_compat_timespec(&t, interval))
11436 return -EFAULT;
11437@@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
11438 mm_segment_t old_fs = get_fs();
11439
11440 set_fs(KERNEL_DS);
11441- ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
11442+ ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
11443 set_fs(old_fs);
11444 if (!ret) {
11445 switch (_NSIG_WORDS) {
11446@@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
11447 if (copy_siginfo_from_user32(&info, uinfo))
11448 return -EFAULT;
11449 set_fs(KERNEL_DS);
11450- ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
11451+ ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
11452 set_fs(old_fs);
11453 return ret;
11454 }
11455@@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
11456 return -EFAULT;
11457
11458 set_fs(KERNEL_DS);
11459- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
11460+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
11461 count);
11462 set_fs(old_fs);
11463
11464diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
11465index 372231c..a5aa1a1 100644
11466--- a/arch/x86/include/asm/alternative-asm.h
11467+++ b/arch/x86/include/asm/alternative-asm.h
11468@@ -18,6 +18,45 @@
11469 .endm
11470 #endif
11471
11472+#ifdef KERNEXEC_PLUGIN
11473+ .macro pax_force_retaddr_bts rip=0
11474+ btsq $63,\rip(%rsp)
11475+ .endm
11476+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11477+ .macro pax_force_retaddr rip=0, reload=0
11478+ btsq $63,\rip(%rsp)
11479+ .endm
11480+ .macro pax_force_fptr ptr
11481+ btsq $63,\ptr
11482+ .endm
11483+ .macro pax_set_fptr_mask
11484+ .endm
11485+#endif
11486+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
11487+ .macro pax_force_retaddr rip=0, reload=0
11488+ .if \reload
11489+ pax_set_fptr_mask
11490+ .endif
11491+ orq %r10,\rip(%rsp)
11492+ .endm
11493+ .macro pax_force_fptr ptr
11494+ orq %r10,\ptr
11495+ .endm
11496+ .macro pax_set_fptr_mask
11497+ movabs $0x8000000000000000,%r10
11498+ .endm
11499+#endif
11500+#else
11501+ .macro pax_force_retaddr rip=0, reload=0
11502+ .endm
11503+ .macro pax_force_fptr ptr
11504+ .endm
11505+ .macro pax_force_retaddr_bts rip=0
11506+ .endm
11507+ .macro pax_set_fptr_mask
11508+ .endm
11509+#endif
11510+
11511 .macro altinstruction_entry orig alt feature orig_len alt_len
11512 .long \orig - .
11513 .long \alt - .
11514diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
11515index 58ed6d9..f1cbe58 100644
11516--- a/arch/x86/include/asm/alternative.h
11517+++ b/arch/x86/include/asm/alternative.h
11518@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11519 ".pushsection .discard,\"aw\",@progbits\n" \
11520 DISCARD_ENTRY(1) \
11521 ".popsection\n" \
11522- ".pushsection .altinstr_replacement, \"ax\"\n" \
11523+ ".pushsection .altinstr_replacement, \"a\"\n" \
11524 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
11525 ".popsection"
11526
11527@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11528 DISCARD_ENTRY(1) \
11529 DISCARD_ENTRY(2) \
11530 ".popsection\n" \
11531- ".pushsection .altinstr_replacement, \"ax\"\n" \
11532+ ".pushsection .altinstr_replacement, \"a\"\n" \
11533 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
11534 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
11535 ".popsection"
11536diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
11537index 3388034..050f0b9 100644
11538--- a/arch/x86/include/asm/apic.h
11539+++ b/arch/x86/include/asm/apic.h
11540@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
11541
11542 #ifdef CONFIG_X86_LOCAL_APIC
11543
11544-extern unsigned int apic_verbosity;
11545+extern int apic_verbosity;
11546 extern int local_apic_timer_c2_ok;
11547
11548 extern int disable_apic;
11549diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
11550index 20370c6..a2eb9b0 100644
11551--- a/arch/x86/include/asm/apm.h
11552+++ b/arch/x86/include/asm/apm.h
11553@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
11554 __asm__ __volatile__(APM_DO_ZERO_SEGS
11555 "pushl %%edi\n\t"
11556 "pushl %%ebp\n\t"
11557- "lcall *%%cs:apm_bios_entry\n\t"
11558+ "lcall *%%ss:apm_bios_entry\n\t"
11559 "setc %%al\n\t"
11560 "popl %%ebp\n\t"
11561 "popl %%edi\n\t"
11562@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
11563 __asm__ __volatile__(APM_DO_ZERO_SEGS
11564 "pushl %%edi\n\t"
11565 "pushl %%ebp\n\t"
11566- "lcall *%%cs:apm_bios_entry\n\t"
11567+ "lcall *%%ss:apm_bios_entry\n\t"
11568 "setc %%bl\n\t"
11569 "popl %%ebp\n\t"
11570 "popl %%edi\n\t"
11571diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
11572index 722aa3b..3a0bb27 100644
11573--- a/arch/x86/include/asm/atomic.h
11574+++ b/arch/x86/include/asm/atomic.h
11575@@ -22,7 +22,18 @@
11576 */
11577 static inline int atomic_read(const atomic_t *v)
11578 {
11579- return (*(volatile int *)&(v)->counter);
11580+ return (*(volatile const int *)&(v)->counter);
11581+}
11582+
11583+/**
11584+ * atomic_read_unchecked - read atomic variable
11585+ * @v: pointer of type atomic_unchecked_t
11586+ *
11587+ * Atomically reads the value of @v.
11588+ */
11589+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
11590+{
11591+ return (*(volatile const int *)&(v)->counter);
11592 }
11593
11594 /**
11595@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
11596 }
11597
11598 /**
11599+ * atomic_set_unchecked - set atomic variable
11600+ * @v: pointer of type atomic_unchecked_t
11601+ * @i: required value
11602+ *
11603+ * Atomically sets the value of @v to @i.
11604+ */
11605+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
11606+{
11607+ v->counter = i;
11608+}
11609+
11610+/**
11611 * atomic_add - add integer to atomic variable
11612 * @i: integer value to add
11613 * @v: pointer of type atomic_t
11614@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
11615 */
11616 static inline void atomic_add(int i, atomic_t *v)
11617 {
11618- asm volatile(LOCK_PREFIX "addl %1,%0"
11619+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
11620+
11621+#ifdef CONFIG_PAX_REFCOUNT
11622+ "jno 0f\n"
11623+ LOCK_PREFIX "subl %1,%0\n"
11624+ "int $4\n0:\n"
11625+ _ASM_EXTABLE(0b, 0b)
11626+#endif
11627+
11628+ : "+m" (v->counter)
11629+ : "ir" (i));
11630+}
11631+
11632+/**
11633+ * atomic_add_unchecked - add integer to atomic variable
11634+ * @i: integer value to add
11635+ * @v: pointer of type atomic_unchecked_t
11636+ *
11637+ * Atomically adds @i to @v.
11638+ */
11639+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
11640+{
11641+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
11642 : "+m" (v->counter)
11643 : "ir" (i));
11644 }
11645@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
11646 */
11647 static inline void atomic_sub(int i, atomic_t *v)
11648 {
11649- asm volatile(LOCK_PREFIX "subl %1,%0"
11650+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
11651+
11652+#ifdef CONFIG_PAX_REFCOUNT
11653+ "jno 0f\n"
11654+ LOCK_PREFIX "addl %1,%0\n"
11655+ "int $4\n0:\n"
11656+ _ASM_EXTABLE(0b, 0b)
11657+#endif
11658+
11659+ : "+m" (v->counter)
11660+ : "ir" (i));
11661+}
11662+
11663+/**
11664+ * atomic_sub_unchecked - subtract integer from atomic variable
11665+ * @i: integer value to subtract
11666+ * @v: pointer of type atomic_unchecked_t
11667+ *
11668+ * Atomically subtracts @i from @v.
11669+ */
11670+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
11671+{
11672+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
11673 : "+m" (v->counter)
11674 : "ir" (i));
11675 }
11676@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
11677 {
11678 unsigned char c;
11679
11680- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
11681+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
11682+
11683+#ifdef CONFIG_PAX_REFCOUNT
11684+ "jno 0f\n"
11685+ LOCK_PREFIX "addl %2,%0\n"
11686+ "int $4\n0:\n"
11687+ _ASM_EXTABLE(0b, 0b)
11688+#endif
11689+
11690+ "sete %1\n"
11691 : "+m" (v->counter), "=qm" (c)
11692 : "ir" (i) : "memory");
11693 return c;
11694@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
11695 */
11696 static inline void atomic_inc(atomic_t *v)
11697 {
11698- asm volatile(LOCK_PREFIX "incl %0"
11699+ asm volatile(LOCK_PREFIX "incl %0\n"
11700+
11701+#ifdef CONFIG_PAX_REFCOUNT
11702+ "jno 0f\n"
11703+ LOCK_PREFIX "decl %0\n"
11704+ "int $4\n0:\n"
11705+ _ASM_EXTABLE(0b, 0b)
11706+#endif
11707+
11708+ : "+m" (v->counter));
11709+}
11710+
11711+/**
11712+ * atomic_inc_unchecked - increment atomic variable
11713+ * @v: pointer of type atomic_unchecked_t
11714+ *
11715+ * Atomically increments @v by 1.
11716+ */
11717+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
11718+{
11719+ asm volatile(LOCK_PREFIX "incl %0\n"
11720 : "+m" (v->counter));
11721 }
11722
11723@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
11724 */
11725 static inline void atomic_dec(atomic_t *v)
11726 {
11727- asm volatile(LOCK_PREFIX "decl %0"
11728+ asm volatile(LOCK_PREFIX "decl %0\n"
11729+
11730+#ifdef CONFIG_PAX_REFCOUNT
11731+ "jno 0f\n"
11732+ LOCK_PREFIX "incl %0\n"
11733+ "int $4\n0:\n"
11734+ _ASM_EXTABLE(0b, 0b)
11735+#endif
11736+
11737+ : "+m" (v->counter));
11738+}
11739+
11740+/**
11741+ * atomic_dec_unchecked - decrement atomic variable
11742+ * @v: pointer of type atomic_unchecked_t
11743+ *
11744+ * Atomically decrements @v by 1.
11745+ */
11746+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
11747+{
11748+ asm volatile(LOCK_PREFIX "decl %0\n"
11749 : "+m" (v->counter));
11750 }
11751
11752@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
11753 {
11754 unsigned char c;
11755
11756- asm volatile(LOCK_PREFIX "decl %0; sete %1"
11757+ asm volatile(LOCK_PREFIX "decl %0\n"
11758+
11759+#ifdef CONFIG_PAX_REFCOUNT
11760+ "jno 0f\n"
11761+ LOCK_PREFIX "incl %0\n"
11762+ "int $4\n0:\n"
11763+ _ASM_EXTABLE(0b, 0b)
11764+#endif
11765+
11766+ "sete %1\n"
11767 : "+m" (v->counter), "=qm" (c)
11768 : : "memory");
11769 return c != 0;
11770@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
11771 {
11772 unsigned char c;
11773
11774- asm volatile(LOCK_PREFIX "incl %0; sete %1"
11775+ asm volatile(LOCK_PREFIX "incl %0\n"
11776+
11777+#ifdef CONFIG_PAX_REFCOUNT
11778+ "jno 0f\n"
11779+ LOCK_PREFIX "decl %0\n"
11780+ "int $4\n0:\n"
11781+ _ASM_EXTABLE(0b, 0b)
11782+#endif
11783+
11784+ "sete %1\n"
11785+ : "+m" (v->counter), "=qm" (c)
11786+ : : "memory");
11787+ return c != 0;
11788+}
11789+
11790+/**
11791+ * atomic_inc_and_test_unchecked - increment and test
11792+ * @v: pointer of type atomic_unchecked_t
11793+ *
11794+ * Atomically increments @v by 1
11795+ * and returns true if the result is zero, or false for all
11796+ * other cases.
11797+ */
11798+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
11799+{
11800+ unsigned char c;
11801+
11802+ asm volatile(LOCK_PREFIX "incl %0\n"
11803+ "sete %1\n"
11804 : "+m" (v->counter), "=qm" (c)
11805 : : "memory");
11806 return c != 0;
11807@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
11808 {
11809 unsigned char c;
11810
11811- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
11812+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
11813+
11814+#ifdef CONFIG_PAX_REFCOUNT
11815+ "jno 0f\n"
11816+ LOCK_PREFIX "subl %2,%0\n"
11817+ "int $4\n0:\n"
11818+ _ASM_EXTABLE(0b, 0b)
11819+#endif
11820+
11821+ "sets %1\n"
11822 : "+m" (v->counter), "=qm" (c)
11823 : "ir" (i) : "memory");
11824 return c;
11825@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
11826 */
11827 static inline int atomic_add_return(int i, atomic_t *v)
11828 {
11829+ return i + xadd_check_overflow(&v->counter, i);
11830+}
11831+
11832+/**
11833+ * atomic_add_return_unchecked - add integer and return
11834+ * @i: integer value to add
11835+ * @v: pointer of type atomic_unchecked_t
11836+ *
11837+ * Atomically adds @i to @v and returns @i + @v
11838+ */
11839+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
11840+{
11841 return i + xadd(&v->counter, i);
11842 }
11843
11844@@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
11845 }
11846
11847 #define atomic_inc_return(v) (atomic_add_return(1, v))
11848+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
11849+{
11850+ return atomic_add_return_unchecked(1, v);
11851+}
11852 #define atomic_dec_return(v) (atomic_sub_return(1, v))
11853
11854 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
11855@@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
11856 return cmpxchg(&v->counter, old, new);
11857 }
11858
11859+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
11860+{
11861+ return cmpxchg(&v->counter, old, new);
11862+}
11863+
11864 static inline int atomic_xchg(atomic_t *v, int new)
11865 {
11866 return xchg(&v->counter, new);
11867 }
11868
11869+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
11870+{
11871+ return xchg(&v->counter, new);
11872+}
11873+
11874 /**
11875 * __atomic_add_unless - add unless the number is already a given value
11876 * @v: pointer of type atomic_t
11877@@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
11878 */
11879 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
11880 {
11881- int c, old;
11882+ int c, old, new;
11883 c = atomic_read(v);
11884 for (;;) {
11885- if (unlikely(c == (u)))
11886+ if (unlikely(c == u))
11887 break;
11888- old = atomic_cmpxchg((v), c, c + (a));
11889+
11890+ asm volatile("addl %2,%0\n"
11891+
11892+#ifdef CONFIG_PAX_REFCOUNT
11893+ "jno 0f\n"
11894+ "subl %2,%0\n"
11895+ "int $4\n0:\n"
11896+ _ASM_EXTABLE(0b, 0b)
11897+#endif
11898+
11899+ : "=r" (new)
11900+ : "0" (c), "ir" (a));
11901+
11902+ old = atomic_cmpxchg(v, c, new);
11903 if (likely(old == c))
11904 break;
11905 c = old;
11906@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
11907 }
11908
11909 /**
11910+ * atomic_inc_not_zero_hint - increment if not null
11911+ * @v: pointer of type atomic_t
11912+ * @hint: probable value of the atomic before the increment
11913+ *
11914+ * This version of atomic_inc_not_zero() gives a hint of probable
11915+ * value of the atomic. This helps processor to not read the memory
11916+ * before doing the atomic read/modify/write cycle, lowering
11917+ * number of bus transactions on some arches.
11918+ *
11919+ * Returns: 0 if increment was not done, 1 otherwise.
11920+ */
11921+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
11922+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
11923+{
11924+ int val, c = hint, new;
11925+
11926+ /* sanity test, should be removed by compiler if hint is a constant */
11927+ if (!hint)
11928+ return __atomic_add_unless(v, 1, 0);
11929+
11930+ do {
11931+ asm volatile("incl %0\n"
11932+
11933+#ifdef CONFIG_PAX_REFCOUNT
11934+ "jno 0f\n"
11935+ "decl %0\n"
11936+ "int $4\n0:\n"
11937+ _ASM_EXTABLE(0b, 0b)
11938+#endif
11939+
11940+ : "=r" (new)
11941+ : "0" (c));
11942+
11943+ val = atomic_cmpxchg(v, c, new);
11944+ if (val == c)
11945+ return 1;
11946+ c = val;
11947+ } while (c);
11948+
11949+ return 0;
11950+}
11951+
11952+/**
11953 * atomic_inc_short - increment of a short integer
11954 * @v: pointer to type int
11955 *
11956@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
11957 #endif
11958
11959 /* These are x86-specific, used by some header files */
11960-#define atomic_clear_mask(mask, addr) \
11961- asm volatile(LOCK_PREFIX "andl %0,%1" \
11962- : : "r" (~(mask)), "m" (*(addr)) : "memory")
11963+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
11964+{
11965+ asm volatile(LOCK_PREFIX "andl %1,%0"
11966+ : "+m" (v->counter)
11967+ : "r" (~(mask))
11968+ : "memory");
11969+}
11970
11971-#define atomic_set_mask(mask, addr) \
11972- asm volatile(LOCK_PREFIX "orl %0,%1" \
11973- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
11974- : "memory")
11975+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
11976+{
11977+ asm volatile(LOCK_PREFIX "andl %1,%0"
11978+ : "+m" (v->counter)
11979+ : "r" (~(mask))
11980+ : "memory");
11981+}
11982+
11983+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
11984+{
11985+ asm volatile(LOCK_PREFIX "orl %1,%0"
11986+ : "+m" (v->counter)
11987+ : "r" (mask)
11988+ : "memory");
11989+}
11990+
11991+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
11992+{
11993+ asm volatile(LOCK_PREFIX "orl %1,%0"
11994+ : "+m" (v->counter)
11995+ : "r" (mask)
11996+ : "memory");
11997+}
11998
11999 /* Atomic operations are already serializing on x86 */
12000 #define smp_mb__before_atomic_dec() barrier()
12001diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
12002index b154de7..aadebd8 100644
12003--- a/arch/x86/include/asm/atomic64_32.h
12004+++ b/arch/x86/include/asm/atomic64_32.h
12005@@ -12,6 +12,14 @@ typedef struct {
12006 u64 __aligned(8) counter;
12007 } atomic64_t;
12008
12009+#ifdef CONFIG_PAX_REFCOUNT
12010+typedef struct {
12011+ u64 __aligned(8) counter;
12012+} atomic64_unchecked_t;
12013+#else
12014+typedef atomic64_t atomic64_unchecked_t;
12015+#endif
12016+
12017 #define ATOMIC64_INIT(val) { (val) }
12018
12019 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
12020@@ -37,21 +45,31 @@ typedef struct {
12021 ATOMIC64_DECL_ONE(sym##_386)
12022
12023 ATOMIC64_DECL_ONE(add_386);
12024+ATOMIC64_DECL_ONE(add_unchecked_386);
12025 ATOMIC64_DECL_ONE(sub_386);
12026+ATOMIC64_DECL_ONE(sub_unchecked_386);
12027 ATOMIC64_DECL_ONE(inc_386);
12028+ATOMIC64_DECL_ONE(inc_unchecked_386);
12029 ATOMIC64_DECL_ONE(dec_386);
12030+ATOMIC64_DECL_ONE(dec_unchecked_386);
12031 #endif
12032
12033 #define alternative_atomic64(f, out, in...) \
12034 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
12035
12036 ATOMIC64_DECL(read);
12037+ATOMIC64_DECL(read_unchecked);
12038 ATOMIC64_DECL(set);
12039+ATOMIC64_DECL(set_unchecked);
12040 ATOMIC64_DECL(xchg);
12041 ATOMIC64_DECL(add_return);
12042+ATOMIC64_DECL(add_return_unchecked);
12043 ATOMIC64_DECL(sub_return);
12044+ATOMIC64_DECL(sub_return_unchecked);
12045 ATOMIC64_DECL(inc_return);
12046+ATOMIC64_DECL(inc_return_unchecked);
12047 ATOMIC64_DECL(dec_return);
12048+ATOMIC64_DECL(dec_return_unchecked);
12049 ATOMIC64_DECL(dec_if_positive);
12050 ATOMIC64_DECL(inc_not_zero);
12051 ATOMIC64_DECL(add_unless);
12052@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
12053 }
12054
12055 /**
12056+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
12057+ * @p: pointer to type atomic64_unchecked_t
12058+ * @o: expected value
12059+ * @n: new value
12060+ *
12061+ * Atomically sets @v to @n if it was equal to @o and returns
12062+ * the old value.
12063+ */
12064+
12065+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
12066+{
12067+ return cmpxchg64(&v->counter, o, n);
12068+}
12069+
12070+/**
12071 * atomic64_xchg - xchg atomic64 variable
12072 * @v: pointer to type atomic64_t
12073 * @n: value to assign
12074@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
12075 }
12076
12077 /**
12078+ * atomic64_set_unchecked - set atomic64 variable
12079+ * @v: pointer to type atomic64_unchecked_t
12080+ * @n: value to assign
12081+ *
12082+ * Atomically sets the value of @v to @n.
12083+ */
12084+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
12085+{
12086+ unsigned high = (unsigned)(i >> 32);
12087+ unsigned low = (unsigned)i;
12088+ alternative_atomic64(set, /* no output */,
12089+ "S" (v), "b" (low), "c" (high)
12090+ : "eax", "edx", "memory");
12091+}
12092+
12093+/**
12094 * atomic64_read - read atomic64 variable
12095 * @v: pointer to type atomic64_t
12096 *
12097@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
12098 }
12099
12100 /**
12101+ * atomic64_read_unchecked - read atomic64 variable
12102+ * @v: pointer to type atomic64_unchecked_t
12103+ *
12104+ * Atomically reads the value of @v and returns it.
12105+ */
12106+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
12107+{
12108+ long long r;
12109+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
12110+ return r;
12111+ }
12112+
12113+/**
12114 * atomic64_add_return - add and return
12115 * @i: integer value to add
12116 * @v: pointer to type atomic64_t
12117@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
12118 return i;
12119 }
12120
12121+/**
12122+ * atomic64_add_return_unchecked - add and return
12123+ * @i: integer value to add
12124+ * @v: pointer to type atomic64_unchecked_t
12125+ *
12126+ * Atomically adds @i to @v and returns @i + *@v
12127+ */
12128+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
12129+{
12130+ alternative_atomic64(add_return_unchecked,
12131+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12132+ ASM_NO_INPUT_CLOBBER("memory"));
12133+ return i;
12134+}
12135+
12136 /*
12137 * Other variants with different arithmetic operators:
12138 */
12139@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
12140 return a;
12141 }
12142
12143+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12144+{
12145+ long long a;
12146+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
12147+ "S" (v) : "memory", "ecx");
12148+ return a;
12149+}
12150+
12151 static inline long long atomic64_dec_return(atomic64_t *v)
12152 {
12153 long long a;
12154@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
12155 }
12156
12157 /**
12158+ * atomic64_add_unchecked - add integer to atomic64 variable
12159+ * @i: integer value to add
12160+ * @v: pointer to type atomic64_unchecked_t
12161+ *
12162+ * Atomically adds @i to @v.
12163+ */
12164+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
12165+{
12166+ __alternative_atomic64(add_unchecked, add_return_unchecked,
12167+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12168+ ASM_NO_INPUT_CLOBBER("memory"));
12169+ return i;
12170+}
12171+
12172+/**
12173 * atomic64_sub - subtract the atomic64 variable
12174 * @i: integer value to subtract
12175 * @v: pointer to type atomic64_t
12176diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
12177index 0e1cbfc..5623683 100644
12178--- a/arch/x86/include/asm/atomic64_64.h
12179+++ b/arch/x86/include/asm/atomic64_64.h
12180@@ -18,7 +18,19 @@
12181 */
12182 static inline long atomic64_read(const atomic64_t *v)
12183 {
12184- return (*(volatile long *)&(v)->counter);
12185+ return (*(volatile const long *)&(v)->counter);
12186+}
12187+
12188+/**
12189+ * atomic64_read_unchecked - read atomic64 variable
12190+ * @v: pointer of type atomic64_unchecked_t
12191+ *
12192+ * Atomically reads the value of @v.
12193+ * Doesn't imply a read memory barrier.
12194+ */
12195+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
12196+{
12197+ return (*(volatile const long *)&(v)->counter);
12198 }
12199
12200 /**
12201@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
12202 }
12203
12204 /**
12205+ * atomic64_set_unchecked - set atomic64 variable
12206+ * @v: pointer to type atomic64_unchecked_t
12207+ * @i: required value
12208+ *
12209+ * Atomically sets the value of @v to @i.
12210+ */
12211+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
12212+{
12213+ v->counter = i;
12214+}
12215+
12216+/**
12217 * atomic64_add - add integer to atomic64 variable
12218 * @i: integer value to add
12219 * @v: pointer to type atomic64_t
12220@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
12221 */
12222 static inline void atomic64_add(long i, atomic64_t *v)
12223 {
12224+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
12225+
12226+#ifdef CONFIG_PAX_REFCOUNT
12227+ "jno 0f\n"
12228+ LOCK_PREFIX "subq %1,%0\n"
12229+ "int $4\n0:\n"
12230+ _ASM_EXTABLE(0b, 0b)
12231+#endif
12232+
12233+ : "=m" (v->counter)
12234+ : "er" (i), "m" (v->counter));
12235+}
12236+
12237+/**
12238+ * atomic64_add_unchecked - add integer to atomic64 variable
12239+ * @i: integer value to add
12240+ * @v: pointer to type atomic64_unchecked_t
12241+ *
12242+ * Atomically adds @i to @v.
12243+ */
12244+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
12245+{
12246 asm volatile(LOCK_PREFIX "addq %1,%0"
12247 : "=m" (v->counter)
12248 : "er" (i), "m" (v->counter));
12249@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
12250 */
12251 static inline void atomic64_sub(long i, atomic64_t *v)
12252 {
12253- asm volatile(LOCK_PREFIX "subq %1,%0"
12254+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
12255+
12256+#ifdef CONFIG_PAX_REFCOUNT
12257+ "jno 0f\n"
12258+ LOCK_PREFIX "addq %1,%0\n"
12259+ "int $4\n0:\n"
12260+ _ASM_EXTABLE(0b, 0b)
12261+#endif
12262+
12263+ : "=m" (v->counter)
12264+ : "er" (i), "m" (v->counter));
12265+}
12266+
12267+/**
12268+ * atomic64_sub_unchecked - subtract the atomic64 variable
12269+ * @i: integer value to subtract
12270+ * @v: pointer to type atomic64_unchecked_t
12271+ *
12272+ * Atomically subtracts @i from @v.
12273+ */
12274+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
12275+{
12276+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
12277 : "=m" (v->counter)
12278 : "er" (i), "m" (v->counter));
12279 }
12280@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12281 {
12282 unsigned char c;
12283
12284- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
12285+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
12286+
12287+#ifdef CONFIG_PAX_REFCOUNT
12288+ "jno 0f\n"
12289+ LOCK_PREFIX "addq %2,%0\n"
12290+ "int $4\n0:\n"
12291+ _ASM_EXTABLE(0b, 0b)
12292+#endif
12293+
12294+ "sete %1\n"
12295 : "=m" (v->counter), "=qm" (c)
12296 : "er" (i), "m" (v->counter) : "memory");
12297 return c;
12298@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12299 */
12300 static inline void atomic64_inc(atomic64_t *v)
12301 {
12302+ asm volatile(LOCK_PREFIX "incq %0\n"
12303+
12304+#ifdef CONFIG_PAX_REFCOUNT
12305+ "jno 0f\n"
12306+ LOCK_PREFIX "decq %0\n"
12307+ "int $4\n0:\n"
12308+ _ASM_EXTABLE(0b, 0b)
12309+#endif
12310+
12311+ : "=m" (v->counter)
12312+ : "m" (v->counter));
12313+}
12314+
12315+/**
12316+ * atomic64_inc_unchecked - increment atomic64 variable
12317+ * @v: pointer to type atomic64_unchecked_t
12318+ *
12319+ * Atomically increments @v by 1.
12320+ */
12321+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
12322+{
12323 asm volatile(LOCK_PREFIX "incq %0"
12324 : "=m" (v->counter)
12325 : "m" (v->counter));
12326@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
12327 */
12328 static inline void atomic64_dec(atomic64_t *v)
12329 {
12330- asm volatile(LOCK_PREFIX "decq %0"
12331+ asm volatile(LOCK_PREFIX "decq %0\n"
12332+
12333+#ifdef CONFIG_PAX_REFCOUNT
12334+ "jno 0f\n"
12335+ LOCK_PREFIX "incq %0\n"
12336+ "int $4\n0:\n"
12337+ _ASM_EXTABLE(0b, 0b)
12338+#endif
12339+
12340+ : "=m" (v->counter)
12341+ : "m" (v->counter));
12342+}
12343+
12344+/**
12345+ * atomic64_dec_unchecked - decrement atomic64 variable
12346+ * @v: pointer to type atomic64_t
12347+ *
12348+ * Atomically decrements @v by 1.
12349+ */
12350+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
12351+{
12352+ asm volatile(LOCK_PREFIX "decq %0\n"
12353 : "=m" (v->counter)
12354 : "m" (v->counter));
12355 }
12356@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
12357 {
12358 unsigned char c;
12359
12360- asm volatile(LOCK_PREFIX "decq %0; sete %1"
12361+ asm volatile(LOCK_PREFIX "decq %0\n"
12362+
12363+#ifdef CONFIG_PAX_REFCOUNT
12364+ "jno 0f\n"
12365+ LOCK_PREFIX "incq %0\n"
12366+ "int $4\n0:\n"
12367+ _ASM_EXTABLE(0b, 0b)
12368+#endif
12369+
12370+ "sete %1\n"
12371 : "=m" (v->counter), "=qm" (c)
12372 : "m" (v->counter) : "memory");
12373 return c != 0;
12374@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
12375 {
12376 unsigned char c;
12377
12378- asm volatile(LOCK_PREFIX "incq %0; sete %1"
12379+ asm volatile(LOCK_PREFIX "incq %0\n"
12380+
12381+#ifdef CONFIG_PAX_REFCOUNT
12382+ "jno 0f\n"
12383+ LOCK_PREFIX "decq %0\n"
12384+ "int $4\n0:\n"
12385+ _ASM_EXTABLE(0b, 0b)
12386+#endif
12387+
12388+ "sete %1\n"
12389 : "=m" (v->counter), "=qm" (c)
12390 : "m" (v->counter) : "memory");
12391 return c != 0;
12392@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12393 {
12394 unsigned char c;
12395
12396- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
12397+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
12398+
12399+#ifdef CONFIG_PAX_REFCOUNT
12400+ "jno 0f\n"
12401+ LOCK_PREFIX "subq %2,%0\n"
12402+ "int $4\n0:\n"
12403+ _ASM_EXTABLE(0b, 0b)
12404+#endif
12405+
12406+ "sets %1\n"
12407 : "=m" (v->counter), "=qm" (c)
12408 : "er" (i), "m" (v->counter) : "memory");
12409 return c;
12410@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12411 */
12412 static inline long atomic64_add_return(long i, atomic64_t *v)
12413 {
12414+ return i + xadd_check_overflow(&v->counter, i);
12415+}
12416+
12417+/**
12418+ * atomic64_add_return_unchecked - add and return
12419+ * @i: integer value to add
12420+ * @v: pointer to type atomic64_unchecked_t
12421+ *
12422+ * Atomically adds @i to @v and returns @i + @v
12423+ */
12424+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
12425+{
12426 return i + xadd(&v->counter, i);
12427 }
12428
12429@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
12430 }
12431
12432 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
12433+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12434+{
12435+ return atomic64_add_return_unchecked(1, v);
12436+}
12437 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
12438
12439 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12440@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12441 return cmpxchg(&v->counter, old, new);
12442 }
12443
12444+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
12445+{
12446+ return cmpxchg(&v->counter, old, new);
12447+}
12448+
12449 static inline long atomic64_xchg(atomic64_t *v, long new)
12450 {
12451 return xchg(&v->counter, new);
12452@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
12453 */
12454 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
12455 {
12456- long c, old;
12457+ long c, old, new;
12458 c = atomic64_read(v);
12459 for (;;) {
12460- if (unlikely(c == (u)))
12461+ if (unlikely(c == u))
12462 break;
12463- old = atomic64_cmpxchg((v), c, c + (a));
12464+
12465+ asm volatile("add %2,%0\n"
12466+
12467+#ifdef CONFIG_PAX_REFCOUNT
12468+ "jno 0f\n"
12469+ "sub %2,%0\n"
12470+ "int $4\n0:\n"
12471+ _ASM_EXTABLE(0b, 0b)
12472+#endif
12473+
12474+ : "=r" (new)
12475+ : "0" (c), "ir" (a));
12476+
12477+ old = atomic64_cmpxchg(v, c, new);
12478 if (likely(old == c))
12479 break;
12480 c = old;
12481 }
12482- return c != (u);
12483+ return c != u;
12484 }
12485
12486 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12487diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
12488index 6dfd019..0c6699f 100644
12489--- a/arch/x86/include/asm/bitops.h
12490+++ b/arch/x86/include/asm/bitops.h
12491@@ -40,7 +40,7 @@
12492 * a mask operation on a byte.
12493 */
12494 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
12495-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
12496+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
12497 #define CONST_MASK(nr) (1 << ((nr) & 7))
12498
12499 /**
12500diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
12501index 4fa687a..60f2d39 100644
12502--- a/arch/x86/include/asm/boot.h
12503+++ b/arch/x86/include/asm/boot.h
12504@@ -6,10 +6,15 @@
12505 #include <uapi/asm/boot.h>
12506
12507 /* Physical address where kernel should be loaded. */
12508-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12509+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12510 + (CONFIG_PHYSICAL_ALIGN - 1)) \
12511 & ~(CONFIG_PHYSICAL_ALIGN - 1))
12512
12513+#ifndef __ASSEMBLY__
12514+extern unsigned char __LOAD_PHYSICAL_ADDR[];
12515+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
12516+#endif
12517+
12518 /* Minimum kernel alignment, as a power of two */
12519 #ifdef CONFIG_X86_64
12520 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
12521diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
12522index 48f99f1..d78ebf9 100644
12523--- a/arch/x86/include/asm/cache.h
12524+++ b/arch/x86/include/asm/cache.h
12525@@ -5,12 +5,13 @@
12526
12527 /* L1 cache line size */
12528 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12529-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12530+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12531
12532 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
12533+#define __read_only __attribute__((__section__(".data..read_only")))
12534
12535 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
12536-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
12537+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
12538
12539 #ifdef CONFIG_X86_VSMP
12540 #ifdef CONFIG_SMP
12541diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
12542index 9863ee3..4a1f8e1 100644
12543--- a/arch/x86/include/asm/cacheflush.h
12544+++ b/arch/x86/include/asm/cacheflush.h
12545@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
12546 unsigned long pg_flags = pg->flags & _PGMT_MASK;
12547
12548 if (pg_flags == _PGMT_DEFAULT)
12549- return -1;
12550+ return ~0UL;
12551 else if (pg_flags == _PGMT_WC)
12552 return _PAGE_CACHE_WC;
12553 else if (pg_flags == _PGMT_UC_MINUS)
12554diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
12555index 46fc474..b02b0f9 100644
12556--- a/arch/x86/include/asm/checksum_32.h
12557+++ b/arch/x86/include/asm/checksum_32.h
12558@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
12559 int len, __wsum sum,
12560 int *src_err_ptr, int *dst_err_ptr);
12561
12562+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
12563+ int len, __wsum sum,
12564+ int *src_err_ptr, int *dst_err_ptr);
12565+
12566+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
12567+ int len, __wsum sum,
12568+ int *src_err_ptr, int *dst_err_ptr);
12569+
12570 /*
12571 * Note: when you get a NULL pointer exception here this means someone
12572 * passed in an incorrect kernel address to one of these functions.
12573@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
12574 int *err_ptr)
12575 {
12576 might_sleep();
12577- return csum_partial_copy_generic((__force void *)src, dst,
12578+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
12579 len, sum, err_ptr, NULL);
12580 }
12581
12582@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
12583 {
12584 might_sleep();
12585 if (access_ok(VERIFY_WRITE, dst, len))
12586- return csum_partial_copy_generic(src, (__force void *)dst,
12587+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
12588 len, sum, NULL, err_ptr);
12589
12590 if (len)
12591diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
12592index 8d871ea..c1a0dc9 100644
12593--- a/arch/x86/include/asm/cmpxchg.h
12594+++ b/arch/x86/include/asm/cmpxchg.h
12595@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
12596 __compiletime_error("Bad argument size for cmpxchg");
12597 extern void __xadd_wrong_size(void)
12598 __compiletime_error("Bad argument size for xadd");
12599+extern void __xadd_check_overflow_wrong_size(void)
12600+ __compiletime_error("Bad argument size for xadd_check_overflow");
12601 extern void __add_wrong_size(void)
12602 __compiletime_error("Bad argument size for add");
12603+extern void __add_check_overflow_wrong_size(void)
12604+ __compiletime_error("Bad argument size for add_check_overflow");
12605
12606 /*
12607 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
12608@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
12609 __ret; \
12610 })
12611
12612+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
12613+ ({ \
12614+ __typeof__ (*(ptr)) __ret = (arg); \
12615+ switch (sizeof(*(ptr))) { \
12616+ case __X86_CASE_L: \
12617+ asm volatile (lock #op "l %0, %1\n" \
12618+ "jno 0f\n" \
12619+ "mov %0,%1\n" \
12620+ "int $4\n0:\n" \
12621+ _ASM_EXTABLE(0b, 0b) \
12622+ : "+r" (__ret), "+m" (*(ptr)) \
12623+ : : "memory", "cc"); \
12624+ break; \
12625+ case __X86_CASE_Q: \
12626+ asm volatile (lock #op "q %q0, %1\n" \
12627+ "jno 0f\n" \
12628+ "mov %0,%1\n" \
12629+ "int $4\n0:\n" \
12630+ _ASM_EXTABLE(0b, 0b) \
12631+ : "+r" (__ret), "+m" (*(ptr)) \
12632+ : : "memory", "cc"); \
12633+ break; \
12634+ default: \
12635+ __ ## op ## _check_overflow_wrong_size(); \
12636+ } \
12637+ __ret; \
12638+ })
12639+
12640 /*
12641 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
12642 * Since this is generally used to protect other memory information, we
12643@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
12644 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
12645 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
12646
12647+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
12648+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
12649+
12650 #define __add(ptr, inc, lock) \
12651 ({ \
12652 __typeof__ (*(ptr)) __ret = (inc); \
12653diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
12654index 2d9075e..b75a844 100644
12655--- a/arch/x86/include/asm/cpufeature.h
12656+++ b/arch/x86/include/asm/cpufeature.h
12657@@ -206,7 +206,7 @@
12658 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
12659 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
12660 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
12661-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
12662+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
12663 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
12664 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
12665 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
12666@@ -375,7 +375,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
12667 ".section .discard,\"aw\",@progbits\n"
12668 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
12669 ".previous\n"
12670- ".section .altinstr_replacement,\"ax\"\n"
12671+ ".section .altinstr_replacement,\"a\"\n"
12672 "3: movb $1,%0\n"
12673 "4:\n"
12674 ".previous\n"
12675diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
12676index 8bf1c06..f723dfd 100644
12677--- a/arch/x86/include/asm/desc.h
12678+++ b/arch/x86/include/asm/desc.h
12679@@ -4,6 +4,7 @@
12680 #include <asm/desc_defs.h>
12681 #include <asm/ldt.h>
12682 #include <asm/mmu.h>
12683+#include <asm/pgtable.h>
12684
12685 #include <linux/smp.h>
12686 #include <linux/percpu.h>
12687@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
12688
12689 desc->type = (info->read_exec_only ^ 1) << 1;
12690 desc->type |= info->contents << 2;
12691+ desc->type |= info->seg_not_present ^ 1;
12692
12693 desc->s = 1;
12694 desc->dpl = 0x3;
12695@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
12696 }
12697
12698 extern struct desc_ptr idt_descr;
12699-extern gate_desc idt_table[];
12700 extern struct desc_ptr nmi_idt_descr;
12701-extern gate_desc nmi_idt_table[];
12702-
12703-struct gdt_page {
12704- struct desc_struct gdt[GDT_ENTRIES];
12705-} __attribute__((aligned(PAGE_SIZE)));
12706-
12707-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
12708+extern gate_desc idt_table[256];
12709+extern gate_desc nmi_idt_table[256];
12710
12711+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
12712 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
12713 {
12714- return per_cpu(gdt_page, cpu).gdt;
12715+ return cpu_gdt_table[cpu];
12716 }
12717
12718 #ifdef CONFIG_X86_64
12719@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
12720 unsigned long base, unsigned dpl, unsigned flags,
12721 unsigned short seg)
12722 {
12723- gate->a = (seg << 16) | (base & 0xffff);
12724- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
12725+ gate->gate.offset_low = base;
12726+ gate->gate.seg = seg;
12727+ gate->gate.reserved = 0;
12728+ gate->gate.type = type;
12729+ gate->gate.s = 0;
12730+ gate->gate.dpl = dpl;
12731+ gate->gate.p = 1;
12732+ gate->gate.offset_high = base >> 16;
12733 }
12734
12735 #endif
12736@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
12737
12738 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
12739 {
12740+ pax_open_kernel();
12741 memcpy(&idt[entry], gate, sizeof(*gate));
12742+ pax_close_kernel();
12743 }
12744
12745 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
12746 {
12747+ pax_open_kernel();
12748 memcpy(&ldt[entry], desc, 8);
12749+ pax_close_kernel();
12750 }
12751
12752 static inline void
12753@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
12754 default: size = sizeof(*gdt); break;
12755 }
12756
12757+ pax_open_kernel();
12758 memcpy(&gdt[entry], desc, size);
12759+ pax_close_kernel();
12760 }
12761
12762 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
12763@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
12764
12765 static inline void native_load_tr_desc(void)
12766 {
12767+ pax_open_kernel();
12768 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
12769+ pax_close_kernel();
12770 }
12771
12772 static inline void native_load_gdt(const struct desc_ptr *dtr)
12773@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
12774 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
12775 unsigned int i;
12776
12777+ pax_open_kernel();
12778 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
12779 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
12780+ pax_close_kernel();
12781 }
12782
12783 #define _LDT_empty(info) \
12784@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
12785 }
12786
12787 #ifdef CONFIG_X86_64
12788-static inline void set_nmi_gate(int gate, void *addr)
12789+static inline void set_nmi_gate(int gate, const void *addr)
12790 {
12791 gate_desc s;
12792
12793@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
12794 }
12795 #endif
12796
12797-static inline void _set_gate(int gate, unsigned type, void *addr,
12798+static inline void _set_gate(int gate, unsigned type, const void *addr,
12799 unsigned dpl, unsigned ist, unsigned seg)
12800 {
12801 gate_desc s;
12802@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
12803 * Pentium F0 0F bugfix can have resulted in the mapped
12804 * IDT being write-protected.
12805 */
12806-static inline void set_intr_gate(unsigned int n, void *addr)
12807+static inline void set_intr_gate(unsigned int n, const void *addr)
12808 {
12809 BUG_ON((unsigned)n > 0xFF);
12810 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
12811@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
12812 /*
12813 * This routine sets up an interrupt gate at directory privilege level 3.
12814 */
12815-static inline void set_system_intr_gate(unsigned int n, void *addr)
12816+static inline void set_system_intr_gate(unsigned int n, const void *addr)
12817 {
12818 BUG_ON((unsigned)n > 0xFF);
12819 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
12820 }
12821
12822-static inline void set_system_trap_gate(unsigned int n, void *addr)
12823+static inline void set_system_trap_gate(unsigned int n, const void *addr)
12824 {
12825 BUG_ON((unsigned)n > 0xFF);
12826 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
12827 }
12828
12829-static inline void set_trap_gate(unsigned int n, void *addr)
12830+static inline void set_trap_gate(unsigned int n, const void *addr)
12831 {
12832 BUG_ON((unsigned)n > 0xFF);
12833 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
12834@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
12835 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
12836 {
12837 BUG_ON((unsigned)n > 0xFF);
12838- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
12839+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
12840 }
12841
12842-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
12843+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
12844 {
12845 BUG_ON((unsigned)n > 0xFF);
12846 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
12847 }
12848
12849-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
12850+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
12851 {
12852 BUG_ON((unsigned)n > 0xFF);
12853 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
12854 }
12855
12856+#ifdef CONFIG_X86_32
12857+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
12858+{
12859+ struct desc_struct d;
12860+
12861+ if (likely(limit))
12862+ limit = (limit - 1UL) >> PAGE_SHIFT;
12863+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
12864+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
12865+}
12866+#endif
12867+
12868 #endif /* _ASM_X86_DESC_H */
12869diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
12870index 278441f..b95a174 100644
12871--- a/arch/x86/include/asm/desc_defs.h
12872+++ b/arch/x86/include/asm/desc_defs.h
12873@@ -31,6 +31,12 @@ struct desc_struct {
12874 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
12875 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
12876 };
12877+ struct {
12878+ u16 offset_low;
12879+ u16 seg;
12880+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
12881+ unsigned offset_high: 16;
12882+ } gate;
12883 };
12884 } __attribute__((packed));
12885
12886diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
12887index 9c999c1..3860cb8 100644
12888--- a/arch/x86/include/asm/elf.h
12889+++ b/arch/x86/include/asm/elf.h
12890@@ -243,7 +243,25 @@ extern int force_personality32;
12891 the loader. We need to make sure that it is out of the way of the program
12892 that it will "exec", and that there is sufficient room for the brk. */
12893
12894+#ifdef CONFIG_PAX_SEGMEXEC
12895+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
12896+#else
12897 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
12898+#endif
12899+
12900+#ifdef CONFIG_PAX_ASLR
12901+#ifdef CONFIG_X86_32
12902+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
12903+
12904+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
12905+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
12906+#else
12907+#define PAX_ELF_ET_DYN_BASE 0x400000UL
12908+
12909+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
12910+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
12911+#endif
12912+#endif
12913
12914 /* This yields a mask that user programs can use to figure out what
12915 instruction set this CPU supports. This could be done in user space,
12916@@ -296,16 +314,12 @@ do { \
12917
12918 #define ARCH_DLINFO \
12919 do { \
12920- if (vdso_enabled) \
12921- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
12922- (unsigned long)current->mm->context.vdso); \
12923+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
12924 } while (0)
12925
12926 #define ARCH_DLINFO_X32 \
12927 do { \
12928- if (vdso_enabled) \
12929- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
12930- (unsigned long)current->mm->context.vdso); \
12931+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
12932 } while (0)
12933
12934 #define AT_SYSINFO 32
12935@@ -320,7 +334,7 @@ else \
12936
12937 #endif /* !CONFIG_X86_32 */
12938
12939-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
12940+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
12941
12942 #define VDSO_ENTRY \
12943 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
12944@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
12945 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
12946 #define compat_arch_setup_additional_pages syscall32_setup_pages
12947
12948-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
12949-#define arch_randomize_brk arch_randomize_brk
12950-
12951 /*
12952 * True on X86_32 or when emulating IA32 on X86_64
12953 */
12954diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
12955index 75ce3f4..882e801 100644
12956--- a/arch/x86/include/asm/emergency-restart.h
12957+++ b/arch/x86/include/asm/emergency-restart.h
12958@@ -13,6 +13,6 @@ enum reboot_type {
12959
12960 extern enum reboot_type reboot_type;
12961
12962-extern void machine_emergency_restart(void);
12963+extern void machine_emergency_restart(void) __noreturn;
12964
12965 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
12966diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
12967index 41ab26e..a88c9e6 100644
12968--- a/arch/x86/include/asm/fpu-internal.h
12969+++ b/arch/x86/include/asm/fpu-internal.h
12970@@ -126,7 +126,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
12971 ({ \
12972 int err; \
12973 asm volatile(ASM_STAC "\n" \
12974- "1:" #insn "\n\t" \
12975+ "1:" \
12976+ __copyuser_seg \
12977+ #insn "\n\t" \
12978 "2: " ASM_CLAC "\n" \
12979 ".section .fixup,\"ax\"\n" \
12980 "3: movl $-1,%[err]\n" \
12981@@ -299,7 +301,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
12982 "emms\n\t" /* clear stack tags */
12983 "fildl %P[addr]", /* set F?P to defined value */
12984 X86_FEATURE_FXSAVE_LEAK,
12985- [addr] "m" (tsk->thread.fpu.has_fpu));
12986+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
12987
12988 return fpu_restore_checking(&tsk->thread.fpu);
12989 }
12990diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
12991index be27ba1..8f13ff9 100644
12992--- a/arch/x86/include/asm/futex.h
12993+++ b/arch/x86/include/asm/futex.h
12994@@ -12,6 +12,7 @@
12995 #include <asm/smap.h>
12996
12997 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
12998+ typecheck(u32 __user *, uaddr); \
12999 asm volatile("\t" ASM_STAC "\n" \
13000 "1:\t" insn "\n" \
13001 "2:\t" ASM_CLAC "\n" \
13002@@ -20,15 +21,16 @@
13003 "\tjmp\t2b\n" \
13004 "\t.previous\n" \
13005 _ASM_EXTABLE(1b, 3b) \
13006- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
13007+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
13008 : "i" (-EFAULT), "0" (oparg), "1" (0))
13009
13010 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
13011+ typecheck(u32 __user *, uaddr); \
13012 asm volatile("\t" ASM_STAC "\n" \
13013 "1:\tmovl %2, %0\n" \
13014 "\tmovl\t%0, %3\n" \
13015 "\t" insn "\n" \
13016- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
13017+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
13018 "\tjnz\t1b\n" \
13019 "3:\t" ASM_CLAC "\n" \
13020 "\t.section .fixup,\"ax\"\n" \
13021@@ -38,7 +40,7 @@
13022 _ASM_EXTABLE(1b, 4b) \
13023 _ASM_EXTABLE(2b, 4b) \
13024 : "=&a" (oldval), "=&r" (ret), \
13025- "+m" (*uaddr), "=&r" (tem) \
13026+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
13027 : "r" (oparg), "i" (-EFAULT), "1" (0))
13028
13029 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13030@@ -59,10 +61,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13031
13032 switch (op) {
13033 case FUTEX_OP_SET:
13034- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
13035+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
13036 break;
13037 case FUTEX_OP_ADD:
13038- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
13039+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
13040 uaddr, oparg);
13041 break;
13042 case FUTEX_OP_OR:
13043@@ -116,14 +118,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
13044 return -EFAULT;
13045
13046 asm volatile("\t" ASM_STAC "\n"
13047- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
13048+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
13049 "2:\t" ASM_CLAC "\n"
13050 "\t.section .fixup, \"ax\"\n"
13051 "3:\tmov %3, %0\n"
13052 "\tjmp 2b\n"
13053 "\t.previous\n"
13054 _ASM_EXTABLE(1b, 3b)
13055- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
13056+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
13057 : "i" (-EFAULT), "r" (newval), "1" (oldval)
13058 : "memory"
13059 );
13060diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
13061index eb92a6e..b98b2f4 100644
13062--- a/arch/x86/include/asm/hw_irq.h
13063+++ b/arch/x86/include/asm/hw_irq.h
13064@@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
13065 extern void enable_IO_APIC(void);
13066
13067 /* Statistics */
13068-extern atomic_t irq_err_count;
13069-extern atomic_t irq_mis_count;
13070+extern atomic_unchecked_t irq_err_count;
13071+extern atomic_unchecked_t irq_mis_count;
13072
13073 /* EISA */
13074 extern void eisa_set_level_irq(unsigned int irq);
13075diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
13076index d8e8eef..15b1179 100644
13077--- a/arch/x86/include/asm/io.h
13078+++ b/arch/x86/include/asm/io.h
13079@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
13080 return ioremap_nocache(offset, size);
13081 }
13082
13083-extern void iounmap(volatile void __iomem *addr);
13084+extern void iounmap(const volatile void __iomem *addr);
13085
13086 extern void set_iounmap_nonlazy(void);
13087
13088@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
13089
13090 #include <linux/vmalloc.h>
13091
13092+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
13093+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
13094+{
13095+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13096+}
13097+
13098+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
13099+{
13100+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13101+}
13102+
13103 /*
13104 * Convert a virtual cached pointer to an uncached pointer
13105 */
13106diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
13107index bba3cf8..06bc8da 100644
13108--- a/arch/x86/include/asm/irqflags.h
13109+++ b/arch/x86/include/asm/irqflags.h
13110@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
13111 sti; \
13112 sysexit
13113
13114+#define GET_CR0_INTO_RDI mov %cr0, %rdi
13115+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
13116+#define GET_CR3_INTO_RDI mov %cr3, %rdi
13117+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
13118+
13119 #else
13120 #define INTERRUPT_RETURN iret
13121 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
13122diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
13123index d3ddd17..c9fb0cc 100644
13124--- a/arch/x86/include/asm/kprobes.h
13125+++ b/arch/x86/include/asm/kprobes.h
13126@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
13127 #define RELATIVEJUMP_SIZE 5
13128 #define RELATIVECALL_OPCODE 0xe8
13129 #define RELATIVE_ADDR_SIZE 4
13130-#define MAX_STACK_SIZE 64
13131-#define MIN_STACK_SIZE(ADDR) \
13132- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
13133- THREAD_SIZE - (unsigned long)(ADDR))) \
13134- ? (MAX_STACK_SIZE) \
13135- : (((unsigned long)current_thread_info()) + \
13136- THREAD_SIZE - (unsigned long)(ADDR)))
13137+#define MAX_STACK_SIZE 64UL
13138+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
13139
13140 #define flush_insn_slot(p) do { } while (0)
13141
13142diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
13143index 2d89e39..baee879 100644
13144--- a/arch/x86/include/asm/local.h
13145+++ b/arch/x86/include/asm/local.h
13146@@ -10,33 +10,97 @@ typedef struct {
13147 atomic_long_t a;
13148 } local_t;
13149
13150+typedef struct {
13151+ atomic_long_unchecked_t a;
13152+} local_unchecked_t;
13153+
13154 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
13155
13156 #define local_read(l) atomic_long_read(&(l)->a)
13157+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
13158 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
13159+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
13160
13161 static inline void local_inc(local_t *l)
13162 {
13163- asm volatile(_ASM_INC "%0"
13164+ asm volatile(_ASM_INC "%0\n"
13165+
13166+#ifdef CONFIG_PAX_REFCOUNT
13167+ "jno 0f\n"
13168+ _ASM_DEC "%0\n"
13169+ "int $4\n0:\n"
13170+ _ASM_EXTABLE(0b, 0b)
13171+#endif
13172+
13173+ : "+m" (l->a.counter));
13174+}
13175+
13176+static inline void local_inc_unchecked(local_unchecked_t *l)
13177+{
13178+ asm volatile(_ASM_INC "%0\n"
13179 : "+m" (l->a.counter));
13180 }
13181
13182 static inline void local_dec(local_t *l)
13183 {
13184- asm volatile(_ASM_DEC "%0"
13185+ asm volatile(_ASM_DEC "%0\n"
13186+
13187+#ifdef CONFIG_PAX_REFCOUNT
13188+ "jno 0f\n"
13189+ _ASM_INC "%0\n"
13190+ "int $4\n0:\n"
13191+ _ASM_EXTABLE(0b, 0b)
13192+#endif
13193+
13194+ : "+m" (l->a.counter));
13195+}
13196+
13197+static inline void local_dec_unchecked(local_unchecked_t *l)
13198+{
13199+ asm volatile(_ASM_DEC "%0\n"
13200 : "+m" (l->a.counter));
13201 }
13202
13203 static inline void local_add(long i, local_t *l)
13204 {
13205- asm volatile(_ASM_ADD "%1,%0"
13206+ asm volatile(_ASM_ADD "%1,%0\n"
13207+
13208+#ifdef CONFIG_PAX_REFCOUNT
13209+ "jno 0f\n"
13210+ _ASM_SUB "%1,%0\n"
13211+ "int $4\n0:\n"
13212+ _ASM_EXTABLE(0b, 0b)
13213+#endif
13214+
13215+ : "+m" (l->a.counter)
13216+ : "ir" (i));
13217+}
13218+
13219+static inline void local_add_unchecked(long i, local_unchecked_t *l)
13220+{
13221+ asm volatile(_ASM_ADD "%1,%0\n"
13222 : "+m" (l->a.counter)
13223 : "ir" (i));
13224 }
13225
13226 static inline void local_sub(long i, local_t *l)
13227 {
13228- asm volatile(_ASM_SUB "%1,%0"
13229+ asm volatile(_ASM_SUB "%1,%0\n"
13230+
13231+#ifdef CONFIG_PAX_REFCOUNT
13232+ "jno 0f\n"
13233+ _ASM_ADD "%1,%0\n"
13234+ "int $4\n0:\n"
13235+ _ASM_EXTABLE(0b, 0b)
13236+#endif
13237+
13238+ : "+m" (l->a.counter)
13239+ : "ir" (i));
13240+}
13241+
13242+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
13243+{
13244+ asm volatile(_ASM_SUB "%1,%0\n"
13245 : "+m" (l->a.counter)
13246 : "ir" (i));
13247 }
13248@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
13249 {
13250 unsigned char c;
13251
13252- asm volatile(_ASM_SUB "%2,%0; sete %1"
13253+ asm volatile(_ASM_SUB "%2,%0\n"
13254+
13255+#ifdef CONFIG_PAX_REFCOUNT
13256+ "jno 0f\n"
13257+ _ASM_ADD "%2,%0\n"
13258+ "int $4\n0:\n"
13259+ _ASM_EXTABLE(0b, 0b)
13260+#endif
13261+
13262+ "sete %1\n"
13263 : "+m" (l->a.counter), "=qm" (c)
13264 : "ir" (i) : "memory");
13265 return c;
13266@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
13267 {
13268 unsigned char c;
13269
13270- asm volatile(_ASM_DEC "%0; sete %1"
13271+ asm volatile(_ASM_DEC "%0\n"
13272+
13273+#ifdef CONFIG_PAX_REFCOUNT
13274+ "jno 0f\n"
13275+ _ASM_INC "%0\n"
13276+ "int $4\n0:\n"
13277+ _ASM_EXTABLE(0b, 0b)
13278+#endif
13279+
13280+ "sete %1\n"
13281 : "+m" (l->a.counter), "=qm" (c)
13282 : : "memory");
13283 return c != 0;
13284@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
13285 {
13286 unsigned char c;
13287
13288- asm volatile(_ASM_INC "%0; sete %1"
13289+ asm volatile(_ASM_INC "%0\n"
13290+
13291+#ifdef CONFIG_PAX_REFCOUNT
13292+ "jno 0f\n"
13293+ _ASM_DEC "%0\n"
13294+ "int $4\n0:\n"
13295+ _ASM_EXTABLE(0b, 0b)
13296+#endif
13297+
13298+ "sete %1\n"
13299 : "+m" (l->a.counter), "=qm" (c)
13300 : : "memory");
13301 return c != 0;
13302@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
13303 {
13304 unsigned char c;
13305
13306- asm volatile(_ASM_ADD "%2,%0; sets %1"
13307+ asm volatile(_ASM_ADD "%2,%0\n"
13308+
13309+#ifdef CONFIG_PAX_REFCOUNT
13310+ "jno 0f\n"
13311+ _ASM_SUB "%2,%0\n"
13312+ "int $4\n0:\n"
13313+ _ASM_EXTABLE(0b, 0b)
13314+#endif
13315+
13316+ "sets %1\n"
13317 : "+m" (l->a.counter), "=qm" (c)
13318 : "ir" (i) : "memory");
13319 return c;
13320@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
13321 static inline long local_add_return(long i, local_t *l)
13322 {
13323 long __i = i;
13324+ asm volatile(_ASM_XADD "%0, %1\n"
13325+
13326+#ifdef CONFIG_PAX_REFCOUNT
13327+ "jno 0f\n"
13328+ _ASM_MOV "%0,%1\n"
13329+ "int $4\n0:\n"
13330+ _ASM_EXTABLE(0b, 0b)
13331+#endif
13332+
13333+ : "+r" (i), "+m" (l->a.counter)
13334+ : : "memory");
13335+ return i + __i;
13336+}
13337+
13338+/**
13339+ * local_add_return_unchecked - add and return
13340+ * @i: integer value to add
13341+ * @l: pointer to type local_unchecked_t
13342+ *
13343+ * Atomically adds @i to @l and returns @i + @l
13344+ */
13345+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
13346+{
13347+ long __i = i;
13348 asm volatile(_ASM_XADD "%0, %1;"
13349 : "+r" (i), "+m" (l->a.counter)
13350 : : "memory");
13351@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
13352
13353 #define local_cmpxchg(l, o, n) \
13354 (cmpxchg_local(&((l)->a.counter), (o), (n)))
13355+#define local_cmpxchg_unchecked(l, o, n) \
13356+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
13357 /* Always has a lock prefix */
13358 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
13359
13360diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
13361new file mode 100644
13362index 0000000..2bfd3ba
13363--- /dev/null
13364+++ b/arch/x86/include/asm/mman.h
13365@@ -0,0 +1,15 @@
13366+#ifndef _X86_MMAN_H
13367+#define _X86_MMAN_H
13368+
13369+#include <uapi/asm/mman.h>
13370+
13371+#ifdef __KERNEL__
13372+#ifndef __ASSEMBLY__
13373+#ifdef CONFIG_X86_32
13374+#define arch_mmap_check i386_mmap_check
13375+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
13376+#endif
13377+#endif
13378+#endif
13379+
13380+#endif /* X86_MMAN_H */
13381diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
13382index 5f55e69..e20bfb1 100644
13383--- a/arch/x86/include/asm/mmu.h
13384+++ b/arch/x86/include/asm/mmu.h
13385@@ -9,7 +9,7 @@
13386 * we put the segment information here.
13387 */
13388 typedef struct {
13389- void *ldt;
13390+ struct desc_struct *ldt;
13391 int size;
13392
13393 #ifdef CONFIG_X86_64
13394@@ -18,7 +18,19 @@ typedef struct {
13395 #endif
13396
13397 struct mutex lock;
13398- void *vdso;
13399+ unsigned long vdso;
13400+
13401+#ifdef CONFIG_X86_32
13402+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
13403+ unsigned long user_cs_base;
13404+ unsigned long user_cs_limit;
13405+
13406+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13407+ cpumask_t cpu_user_cs_mask;
13408+#endif
13409+
13410+#endif
13411+#endif
13412 } mm_context_t;
13413
13414 #ifdef CONFIG_SMP
13415diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
13416index cdbf367..adb37ac 100644
13417--- a/arch/x86/include/asm/mmu_context.h
13418+++ b/arch/x86/include/asm/mmu_context.h
13419@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
13420
13421 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
13422 {
13423+
13424+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13425+ unsigned int i;
13426+ pgd_t *pgd;
13427+
13428+ pax_open_kernel();
13429+ pgd = get_cpu_pgd(smp_processor_id());
13430+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
13431+ set_pgd_batched(pgd+i, native_make_pgd(0));
13432+ pax_close_kernel();
13433+#endif
13434+
13435 #ifdef CONFIG_SMP
13436 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
13437 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
13438@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13439 struct task_struct *tsk)
13440 {
13441 unsigned cpu = smp_processor_id();
13442+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13443+ int tlbstate = TLBSTATE_OK;
13444+#endif
13445
13446 if (likely(prev != next)) {
13447 #ifdef CONFIG_SMP
13448+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13449+ tlbstate = this_cpu_read(cpu_tlbstate.state);
13450+#endif
13451 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13452 this_cpu_write(cpu_tlbstate.active_mm, next);
13453 #endif
13454 cpumask_set_cpu(cpu, mm_cpumask(next));
13455
13456 /* Re-load page tables */
13457+#ifdef CONFIG_PAX_PER_CPU_PGD
13458+ pax_open_kernel();
13459+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13460+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13461+ pax_close_kernel();
13462+ load_cr3(get_cpu_pgd(cpu));
13463+#else
13464 load_cr3(next->pgd);
13465+#endif
13466
13467 /* stop flush ipis for the previous mm */
13468 cpumask_clear_cpu(cpu, mm_cpumask(prev));
13469@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13470 */
13471 if (unlikely(prev->context.ldt != next->context.ldt))
13472 load_LDT_nolock(&next->context);
13473- }
13474+
13475+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13476+ if (!(__supported_pte_mask & _PAGE_NX)) {
13477+ smp_mb__before_clear_bit();
13478+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
13479+ smp_mb__after_clear_bit();
13480+ cpu_set(cpu, next->context.cpu_user_cs_mask);
13481+ }
13482+#endif
13483+
13484+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13485+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
13486+ prev->context.user_cs_limit != next->context.user_cs_limit))
13487+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13488 #ifdef CONFIG_SMP
13489+ else if (unlikely(tlbstate != TLBSTATE_OK))
13490+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13491+#endif
13492+#endif
13493+
13494+ }
13495 else {
13496+
13497+#ifdef CONFIG_PAX_PER_CPU_PGD
13498+ pax_open_kernel();
13499+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13500+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13501+ pax_close_kernel();
13502+ load_cr3(get_cpu_pgd(cpu));
13503+#endif
13504+
13505+#ifdef CONFIG_SMP
13506 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13507 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
13508
13509@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13510 * tlb flush IPI delivery. We must reload CR3
13511 * to make sure to use no freed page tables.
13512 */
13513+
13514+#ifndef CONFIG_PAX_PER_CPU_PGD
13515 load_cr3(next->pgd);
13516+#endif
13517+
13518 load_LDT_nolock(&next->context);
13519+
13520+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
13521+ if (!(__supported_pte_mask & _PAGE_NX))
13522+ cpu_set(cpu, next->context.cpu_user_cs_mask);
13523+#endif
13524+
13525+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13526+#ifdef CONFIG_PAX_PAGEEXEC
13527+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
13528+#endif
13529+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13530+#endif
13531+
13532 }
13533+#endif
13534 }
13535-#endif
13536 }
13537
13538 #define activate_mm(prev, next) \
13539diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
13540index e3b7819..b257c64 100644
13541--- a/arch/x86/include/asm/module.h
13542+++ b/arch/x86/include/asm/module.h
13543@@ -5,6 +5,7 @@
13544
13545 #ifdef CONFIG_X86_64
13546 /* X86_64 does not define MODULE_PROC_FAMILY */
13547+#define MODULE_PROC_FAMILY ""
13548 #elif defined CONFIG_M486
13549 #define MODULE_PROC_FAMILY "486 "
13550 #elif defined CONFIG_M586
13551@@ -57,8 +58,20 @@
13552 #error unknown processor family
13553 #endif
13554
13555-#ifdef CONFIG_X86_32
13556-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
13557+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
13558+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
13559+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
13560+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
13561+#else
13562+#define MODULE_PAX_KERNEXEC ""
13563 #endif
13564
13565+#ifdef CONFIG_PAX_MEMORY_UDEREF
13566+#define MODULE_PAX_UDEREF "UDEREF "
13567+#else
13568+#define MODULE_PAX_UDEREF ""
13569+#endif
13570+
13571+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
13572+
13573 #endif /* _ASM_X86_MODULE_H */
13574diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
13575index 320f7bb..e89f8f8 100644
13576--- a/arch/x86/include/asm/page_64_types.h
13577+++ b/arch/x86/include/asm/page_64_types.h
13578@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
13579
13580 /* duplicated to the one in bootmem.h */
13581 extern unsigned long max_pfn;
13582-extern unsigned long phys_base;
13583+extern const unsigned long phys_base;
13584
13585 extern unsigned long __phys_addr(unsigned long);
13586 #define __phys_reloc_hide(x) (x)
13587diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
13588index 5edd174..9cf5821 100644
13589--- a/arch/x86/include/asm/paravirt.h
13590+++ b/arch/x86/include/asm/paravirt.h
13591@@ -630,6 +630,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
13592 val);
13593 }
13594
13595+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
13596+{
13597+ pgdval_t val = native_pgd_val(pgd);
13598+
13599+ if (sizeof(pgdval_t) > sizeof(long))
13600+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
13601+ val, (u64)val >> 32);
13602+ else
13603+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
13604+ val);
13605+}
13606+
13607 static inline void pgd_clear(pgd_t *pgdp)
13608 {
13609 set_pgd(pgdp, __pgd(0));
13610@@ -711,6 +723,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
13611 pv_mmu_ops.set_fixmap(idx, phys, flags);
13612 }
13613
13614+#ifdef CONFIG_PAX_KERNEXEC
13615+static inline unsigned long pax_open_kernel(void)
13616+{
13617+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
13618+}
13619+
13620+static inline unsigned long pax_close_kernel(void)
13621+{
13622+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
13623+}
13624+#else
13625+static inline unsigned long pax_open_kernel(void) { return 0; }
13626+static inline unsigned long pax_close_kernel(void) { return 0; }
13627+#endif
13628+
13629 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
13630
13631 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
13632@@ -927,7 +954,7 @@ extern void default_banner(void);
13633
13634 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
13635 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
13636-#define PARA_INDIRECT(addr) *%cs:addr
13637+#define PARA_INDIRECT(addr) *%ss:addr
13638 #endif
13639
13640 #define INTERRUPT_RETURN \
13641@@ -1002,6 +1029,21 @@ extern void default_banner(void);
13642 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
13643 CLBR_NONE, \
13644 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
13645+
13646+#define GET_CR0_INTO_RDI \
13647+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
13648+ mov %rax,%rdi
13649+
13650+#define SET_RDI_INTO_CR0 \
13651+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
13652+
13653+#define GET_CR3_INTO_RDI \
13654+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
13655+ mov %rax,%rdi
13656+
13657+#define SET_RDI_INTO_CR3 \
13658+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
13659+
13660 #endif /* CONFIG_X86_32 */
13661
13662 #endif /* __ASSEMBLY__ */
13663diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
13664index 142236e..5446ffbc 100644
13665--- a/arch/x86/include/asm/paravirt_types.h
13666+++ b/arch/x86/include/asm/paravirt_types.h
13667@@ -84,7 +84,7 @@ struct pv_init_ops {
13668 */
13669 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
13670 unsigned long addr, unsigned len);
13671-};
13672+} __no_const;
13673
13674
13675 struct pv_lazy_ops {
13676@@ -97,7 +97,7 @@ struct pv_time_ops {
13677 unsigned long long (*sched_clock)(void);
13678 unsigned long long (*steal_clock)(int cpu);
13679 unsigned long (*get_tsc_khz)(void);
13680-};
13681+} __no_const;
13682
13683 struct pv_cpu_ops {
13684 /* hooks for various privileged instructions */
13685@@ -191,7 +191,7 @@ struct pv_cpu_ops {
13686
13687 void (*start_context_switch)(struct task_struct *prev);
13688 void (*end_context_switch)(struct task_struct *next);
13689-};
13690+} __no_const;
13691
13692 struct pv_irq_ops {
13693 /*
13694@@ -222,7 +222,7 @@ struct pv_apic_ops {
13695 unsigned long start_eip,
13696 unsigned long start_esp);
13697 #endif
13698-};
13699+} __no_const;
13700
13701 struct pv_mmu_ops {
13702 unsigned long (*read_cr2)(void);
13703@@ -312,6 +312,7 @@ struct pv_mmu_ops {
13704 struct paravirt_callee_save make_pud;
13705
13706 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
13707+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
13708 #endif /* PAGETABLE_LEVELS == 4 */
13709 #endif /* PAGETABLE_LEVELS >= 3 */
13710
13711@@ -323,6 +324,12 @@ struct pv_mmu_ops {
13712 an mfn. We can tell which is which from the index. */
13713 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
13714 phys_addr_t phys, pgprot_t flags);
13715+
13716+#ifdef CONFIG_PAX_KERNEXEC
13717+ unsigned long (*pax_open_kernel)(void);
13718+ unsigned long (*pax_close_kernel)(void);
13719+#endif
13720+
13721 };
13722
13723 struct arch_spinlock;
13724@@ -333,7 +340,7 @@ struct pv_lock_ops {
13725 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
13726 int (*spin_trylock)(struct arch_spinlock *lock);
13727 void (*spin_unlock)(struct arch_spinlock *lock);
13728-};
13729+} __no_const;
13730
13731 /* This contains all the paravirt structures: we get a convenient
13732 * number for each function using the offset which we use to indicate
13733diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
13734index b4389a4..7024269 100644
13735--- a/arch/x86/include/asm/pgalloc.h
13736+++ b/arch/x86/include/asm/pgalloc.h
13737@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
13738 pmd_t *pmd, pte_t *pte)
13739 {
13740 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
13741+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
13742+}
13743+
13744+static inline void pmd_populate_user(struct mm_struct *mm,
13745+ pmd_t *pmd, pte_t *pte)
13746+{
13747+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
13748 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
13749 }
13750
13751@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
13752
13753 #ifdef CONFIG_X86_PAE
13754 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
13755+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
13756+{
13757+ pud_populate(mm, pudp, pmd);
13758+}
13759 #else /* !CONFIG_X86_PAE */
13760 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
13761 {
13762 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
13763 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
13764 }
13765+
13766+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
13767+{
13768+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
13769+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
13770+}
13771 #endif /* CONFIG_X86_PAE */
13772
13773 #if PAGETABLE_LEVELS > 3
13774@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
13775 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
13776 }
13777
13778+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
13779+{
13780+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
13781+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
13782+}
13783+
13784 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
13785 {
13786 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
13787diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
13788index f2b489c..4f7e2e5 100644
13789--- a/arch/x86/include/asm/pgtable-2level.h
13790+++ b/arch/x86/include/asm/pgtable-2level.h
13791@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
13792
13793 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
13794 {
13795+ pax_open_kernel();
13796 *pmdp = pmd;
13797+ pax_close_kernel();
13798 }
13799
13800 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
13801diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
13802index 4cc9f2b..5fd9226 100644
13803--- a/arch/x86/include/asm/pgtable-3level.h
13804+++ b/arch/x86/include/asm/pgtable-3level.h
13805@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
13806
13807 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
13808 {
13809+ pax_open_kernel();
13810 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
13811+ pax_close_kernel();
13812 }
13813
13814 static inline void native_set_pud(pud_t *pudp, pud_t pud)
13815 {
13816+ pax_open_kernel();
13817 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
13818+ pax_close_kernel();
13819 }
13820
13821 /*
13822diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
13823index 1c1a955..50f828c 100644
13824--- a/arch/x86/include/asm/pgtable.h
13825+++ b/arch/x86/include/asm/pgtable.h
13826@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
13827
13828 #ifndef __PAGETABLE_PUD_FOLDED
13829 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
13830+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
13831 #define pgd_clear(pgd) native_pgd_clear(pgd)
13832 #endif
13833
13834@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
13835
13836 #define arch_end_context_switch(prev) do {} while(0)
13837
13838+#define pax_open_kernel() native_pax_open_kernel()
13839+#define pax_close_kernel() native_pax_close_kernel()
13840 #endif /* CONFIG_PARAVIRT */
13841
13842+#define __HAVE_ARCH_PAX_OPEN_KERNEL
13843+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
13844+
13845+#ifdef CONFIG_PAX_KERNEXEC
13846+static inline unsigned long native_pax_open_kernel(void)
13847+{
13848+ unsigned long cr0;
13849+
13850+ preempt_disable();
13851+ barrier();
13852+ cr0 = read_cr0() ^ X86_CR0_WP;
13853+ BUG_ON(cr0 & X86_CR0_WP);
13854+ write_cr0(cr0);
13855+ return cr0 ^ X86_CR0_WP;
13856+}
13857+
13858+static inline unsigned long native_pax_close_kernel(void)
13859+{
13860+ unsigned long cr0;
13861+
13862+ cr0 = read_cr0() ^ X86_CR0_WP;
13863+ BUG_ON(!(cr0 & X86_CR0_WP));
13864+ write_cr0(cr0);
13865+ barrier();
13866+ preempt_enable_no_resched();
13867+ return cr0 ^ X86_CR0_WP;
13868+}
13869+#else
13870+static inline unsigned long native_pax_open_kernel(void) { return 0; }
13871+static inline unsigned long native_pax_close_kernel(void) { return 0; }
13872+#endif
13873+
13874 /*
13875 * The following only work if pte_present() is true.
13876 * Undefined behaviour if not..
13877 */
13878+static inline int pte_user(pte_t pte)
13879+{
13880+ return pte_val(pte) & _PAGE_USER;
13881+}
13882+
13883 static inline int pte_dirty(pte_t pte)
13884 {
13885 return pte_flags(pte) & _PAGE_DIRTY;
13886@@ -200,9 +240,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
13887 return pte_clear_flags(pte, _PAGE_RW);
13888 }
13889
13890+static inline pte_t pte_mkread(pte_t pte)
13891+{
13892+ return __pte(pte_val(pte) | _PAGE_USER);
13893+}
13894+
13895 static inline pte_t pte_mkexec(pte_t pte)
13896 {
13897- return pte_clear_flags(pte, _PAGE_NX);
13898+#ifdef CONFIG_X86_PAE
13899+ if (__supported_pte_mask & _PAGE_NX)
13900+ return pte_clear_flags(pte, _PAGE_NX);
13901+ else
13902+#endif
13903+ return pte_set_flags(pte, _PAGE_USER);
13904+}
13905+
13906+static inline pte_t pte_exprotect(pte_t pte)
13907+{
13908+#ifdef CONFIG_X86_PAE
13909+ if (__supported_pte_mask & _PAGE_NX)
13910+ return pte_set_flags(pte, _PAGE_NX);
13911+ else
13912+#endif
13913+ return pte_clear_flags(pte, _PAGE_USER);
13914 }
13915
13916 static inline pte_t pte_mkdirty(pte_t pte)
13917@@ -394,6 +454,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
13918 #endif
13919
13920 #ifndef __ASSEMBLY__
13921+
13922+#ifdef CONFIG_PAX_PER_CPU_PGD
13923+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
13924+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
13925+{
13926+ return cpu_pgd[cpu];
13927+}
13928+#endif
13929+
13930 #include <linux/mm_types.h>
13931
13932 static inline int pte_none(pte_t pte)
13933@@ -583,7 +652,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
13934
13935 static inline int pgd_bad(pgd_t pgd)
13936 {
13937- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
13938+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
13939 }
13940
13941 static inline int pgd_none(pgd_t pgd)
13942@@ -606,7 +675,12 @@ static inline int pgd_none(pgd_t pgd)
13943 * pgd_offset() returns a (pgd_t *)
13944 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
13945 */
13946-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
13947+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
13948+
13949+#ifdef CONFIG_PAX_PER_CPU_PGD
13950+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
13951+#endif
13952+
13953 /*
13954 * a shortcut which implies the use of the kernel's pgd, instead
13955 * of a process's
13956@@ -617,6 +691,20 @@ static inline int pgd_none(pgd_t pgd)
13957 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
13958 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
13959
13960+#ifdef CONFIG_X86_32
13961+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
13962+#else
13963+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
13964+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
13965+
13966+#ifdef CONFIG_PAX_MEMORY_UDEREF
13967+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
13968+#else
13969+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
13970+#endif
13971+
13972+#endif
13973+
13974 #ifndef __ASSEMBLY__
13975
13976 extern int direct_gbpages;
13977@@ -781,11 +869,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
13978 * dst and src can be on the same page, but the range must not overlap,
13979 * and must not cross a page boundary.
13980 */
13981-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
13982+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
13983 {
13984- memcpy(dst, src, count * sizeof(pgd_t));
13985+ pax_open_kernel();
13986+ while (count--)
13987+ *dst++ = *src++;
13988+ pax_close_kernel();
13989 }
13990
13991+#ifdef CONFIG_PAX_PER_CPU_PGD
13992+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
13993+#endif
13994+
13995+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13996+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
13997+#else
13998+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
13999+#endif
14000
14001 #include <asm-generic/pgtable.h>
14002 #endif /* __ASSEMBLY__ */
14003diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
14004index 8faa215..a8a17ea 100644
14005--- a/arch/x86/include/asm/pgtable_32.h
14006+++ b/arch/x86/include/asm/pgtable_32.h
14007@@ -25,9 +25,6 @@
14008 struct mm_struct;
14009 struct vm_area_struct;
14010
14011-extern pgd_t swapper_pg_dir[1024];
14012-extern pgd_t initial_page_table[1024];
14013-
14014 static inline void pgtable_cache_init(void) { }
14015 static inline void check_pgt_cache(void) { }
14016 void paging_init(void);
14017@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14018 # include <asm/pgtable-2level.h>
14019 #endif
14020
14021+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
14022+extern pgd_t initial_page_table[PTRS_PER_PGD];
14023+#ifdef CONFIG_X86_PAE
14024+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
14025+#endif
14026+
14027 #if defined(CONFIG_HIGHPTE)
14028 #define pte_offset_map(dir, address) \
14029 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
14030@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14031 /* Clear a kernel PTE and flush it from the TLB */
14032 #define kpte_clear_flush(ptep, vaddr) \
14033 do { \
14034+ pax_open_kernel(); \
14035 pte_clear(&init_mm, (vaddr), (ptep)); \
14036+ pax_close_kernel(); \
14037 __flush_tlb_one((vaddr)); \
14038 } while (0)
14039
14040@@ -75,6 +80,9 @@ do { \
14041
14042 #endif /* !__ASSEMBLY__ */
14043
14044+#define HAVE_ARCH_UNMAPPED_AREA
14045+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
14046+
14047 /*
14048 * kern_addr_valid() is (1) for FLATMEM and (0) for
14049 * SPARSEMEM and DISCONTIGMEM
14050diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
14051index ed5903b..c7fe163 100644
14052--- a/arch/x86/include/asm/pgtable_32_types.h
14053+++ b/arch/x86/include/asm/pgtable_32_types.h
14054@@ -8,7 +8,7 @@
14055 */
14056 #ifdef CONFIG_X86_PAE
14057 # include <asm/pgtable-3level_types.h>
14058-# define PMD_SIZE (1UL << PMD_SHIFT)
14059+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
14060 # define PMD_MASK (~(PMD_SIZE - 1))
14061 #else
14062 # include <asm/pgtable-2level_types.h>
14063@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
14064 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
14065 #endif
14066
14067+#ifdef CONFIG_PAX_KERNEXEC
14068+#ifndef __ASSEMBLY__
14069+extern unsigned char MODULES_EXEC_VADDR[];
14070+extern unsigned char MODULES_EXEC_END[];
14071+#endif
14072+#include <asm/boot.h>
14073+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
14074+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
14075+#else
14076+#define ktla_ktva(addr) (addr)
14077+#define ktva_ktla(addr) (addr)
14078+#endif
14079+
14080 #define MODULES_VADDR VMALLOC_START
14081 #define MODULES_END VMALLOC_END
14082 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
14083diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
14084index 47356f9..deb94a2 100644
14085--- a/arch/x86/include/asm/pgtable_64.h
14086+++ b/arch/x86/include/asm/pgtable_64.h
14087@@ -16,10 +16,14 @@
14088
14089 extern pud_t level3_kernel_pgt[512];
14090 extern pud_t level3_ident_pgt[512];
14091+extern pud_t level3_vmalloc_start_pgt[512];
14092+extern pud_t level3_vmalloc_end_pgt[512];
14093+extern pud_t level3_vmemmap_pgt[512];
14094+extern pud_t level2_vmemmap_pgt[512];
14095 extern pmd_t level2_kernel_pgt[512];
14096 extern pmd_t level2_fixmap_pgt[512];
14097-extern pmd_t level2_ident_pgt[512];
14098-extern pgd_t init_level4_pgt[];
14099+extern pmd_t level2_ident_pgt[512*2];
14100+extern pgd_t init_level4_pgt[512];
14101
14102 #define swapper_pg_dir init_level4_pgt
14103
14104@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14105
14106 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14107 {
14108+ pax_open_kernel();
14109 *pmdp = pmd;
14110+ pax_close_kernel();
14111 }
14112
14113 static inline void native_pmd_clear(pmd_t *pmd)
14114@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
14115
14116 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14117 {
14118+ pax_open_kernel();
14119 *pudp = pud;
14120+ pax_close_kernel();
14121 }
14122
14123 static inline void native_pud_clear(pud_t *pud)
14124@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
14125
14126 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
14127 {
14128+ pax_open_kernel();
14129+ *pgdp = pgd;
14130+ pax_close_kernel();
14131+}
14132+
14133+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14134+{
14135 *pgdp = pgd;
14136 }
14137
14138diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
14139index 766ea16..5b96cb3 100644
14140--- a/arch/x86/include/asm/pgtable_64_types.h
14141+++ b/arch/x86/include/asm/pgtable_64_types.h
14142@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
14143 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
14144 #define MODULES_END _AC(0xffffffffff000000, UL)
14145 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
14146+#define MODULES_EXEC_VADDR MODULES_VADDR
14147+#define MODULES_EXEC_END MODULES_END
14148+
14149+#define ktla_ktva(addr) (addr)
14150+#define ktva_ktla(addr) (addr)
14151
14152 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
14153diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
14154index 3c32db8..1ddccf5 100644
14155--- a/arch/x86/include/asm/pgtable_types.h
14156+++ b/arch/x86/include/asm/pgtable_types.h
14157@@ -16,13 +16,12 @@
14158 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
14159 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
14160 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
14161-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
14162+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
14163 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
14164 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
14165 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
14166-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
14167-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
14168-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
14169+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
14170+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
14171 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
14172
14173 /* If _PAGE_BIT_PRESENT is clear, we use these: */
14174@@ -40,7 +39,6 @@
14175 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
14176 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
14177 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
14178-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
14179 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
14180 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
14181 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
14182@@ -57,8 +55,10 @@
14183
14184 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
14185 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
14186-#else
14187+#elif defined(CONFIG_KMEMCHECK)
14188 #define _PAGE_NX (_AT(pteval_t, 0))
14189+#else
14190+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
14191 #endif
14192
14193 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
14194@@ -116,6 +116,9 @@
14195 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
14196 _PAGE_ACCESSED)
14197
14198+#define PAGE_READONLY_NOEXEC PAGE_READONLY
14199+#define PAGE_SHARED_NOEXEC PAGE_SHARED
14200+
14201 #define __PAGE_KERNEL_EXEC \
14202 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
14203 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
14204@@ -126,7 +129,7 @@
14205 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
14206 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
14207 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
14208-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
14209+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
14210 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
14211 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
14212 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
14213@@ -188,8 +191,8 @@
14214 * bits are combined, this will alow user to access the high address mapped
14215 * VDSO in the presence of CONFIG_COMPAT_VDSO
14216 */
14217-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
14218-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
14219+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14220+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14221 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
14222 #endif
14223
14224@@ -227,7 +230,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
14225 {
14226 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
14227 }
14228+#endif
14229
14230+#if PAGETABLE_LEVELS == 3
14231+#include <asm-generic/pgtable-nopud.h>
14232+#endif
14233+
14234+#if PAGETABLE_LEVELS == 2
14235+#include <asm-generic/pgtable-nopmd.h>
14236+#endif
14237+
14238+#ifndef __ASSEMBLY__
14239 #if PAGETABLE_LEVELS > 3
14240 typedef struct { pudval_t pud; } pud_t;
14241
14242@@ -241,8 +254,6 @@ static inline pudval_t native_pud_val(pud_t pud)
14243 return pud.pud;
14244 }
14245 #else
14246-#include <asm-generic/pgtable-nopud.h>
14247-
14248 static inline pudval_t native_pud_val(pud_t pud)
14249 {
14250 return native_pgd_val(pud.pgd);
14251@@ -262,8 +273,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
14252 return pmd.pmd;
14253 }
14254 #else
14255-#include <asm-generic/pgtable-nopmd.h>
14256-
14257 static inline pmdval_t native_pmd_val(pmd_t pmd)
14258 {
14259 return native_pgd_val(pmd.pud.pgd);
14260@@ -303,7 +312,6 @@ typedef struct page *pgtable_t;
14261
14262 extern pteval_t __supported_pte_mask;
14263 extern void set_nx(void);
14264-extern int nx_enabled;
14265
14266 #define pgprot_writecombine pgprot_writecombine
14267 extern pgprot_t pgprot_writecombine(pgprot_t prot);
14268diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
14269index 888184b..a07ac89 100644
14270--- a/arch/x86/include/asm/processor.h
14271+++ b/arch/x86/include/asm/processor.h
14272@@ -287,7 +287,7 @@ struct tss_struct {
14273
14274 } ____cacheline_aligned;
14275
14276-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
14277+extern struct tss_struct init_tss[NR_CPUS];
14278
14279 /*
14280 * Save the original ist values for checking stack pointers during debugging
14281@@ -827,11 +827,18 @@ static inline void spin_lock_prefetch(const void *x)
14282 */
14283 #define TASK_SIZE PAGE_OFFSET
14284 #define TASK_SIZE_MAX TASK_SIZE
14285+
14286+#ifdef CONFIG_PAX_SEGMEXEC
14287+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
14288+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
14289+#else
14290 #define STACK_TOP TASK_SIZE
14291-#define STACK_TOP_MAX STACK_TOP
14292+#endif
14293+
14294+#define STACK_TOP_MAX TASK_SIZE
14295
14296 #define INIT_THREAD { \
14297- .sp0 = sizeof(init_stack) + (long)&init_stack, \
14298+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14299 .vm86_info = NULL, \
14300 .sysenter_cs = __KERNEL_CS, \
14301 .io_bitmap_ptr = NULL, \
14302@@ -845,7 +852,7 @@ static inline void spin_lock_prefetch(const void *x)
14303 */
14304 #define INIT_TSS { \
14305 .x86_tss = { \
14306- .sp0 = sizeof(init_stack) + (long)&init_stack, \
14307+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14308 .ss0 = __KERNEL_DS, \
14309 .ss1 = __KERNEL_CS, \
14310 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
14311@@ -856,11 +863,7 @@ static inline void spin_lock_prefetch(const void *x)
14312 extern unsigned long thread_saved_pc(struct task_struct *tsk);
14313
14314 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
14315-#define KSTK_TOP(info) \
14316-({ \
14317- unsigned long *__ptr = (unsigned long *)(info); \
14318- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
14319-})
14320+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
14321
14322 /*
14323 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
14324@@ -875,7 +878,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14325 #define task_pt_regs(task) \
14326 ({ \
14327 struct pt_regs *__regs__; \
14328- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
14329+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
14330 __regs__ - 1; \
14331 })
14332
14333@@ -885,13 +888,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14334 /*
14335 * User space process size. 47bits minus one guard page.
14336 */
14337-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
14338+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
14339
14340 /* This decides where the kernel will search for a free chunk of vm
14341 * space during mmap's.
14342 */
14343 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
14344- 0xc0000000 : 0xFFFFe000)
14345+ 0xc0000000 : 0xFFFFf000)
14346
14347 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
14348 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
14349@@ -902,11 +905,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14350 #define STACK_TOP_MAX TASK_SIZE_MAX
14351
14352 #define INIT_THREAD { \
14353- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14354+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14355 }
14356
14357 #define INIT_TSS { \
14358- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14359+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14360 }
14361
14362 /*
14363@@ -934,6 +937,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
14364 */
14365 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
14366
14367+#ifdef CONFIG_PAX_SEGMEXEC
14368+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
14369+#endif
14370+
14371 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
14372
14373 /* Get/set a process' ability to use the timestamp counter instruction */
14374@@ -994,12 +1001,12 @@ extern bool cpu_has_amd_erratum(const int *);
14375 #define cpu_has_amd_erratum(x) (false)
14376 #endif /* CONFIG_CPU_SUP_AMD */
14377
14378-extern unsigned long arch_align_stack(unsigned long sp);
14379+#define arch_align_stack(x) ((x) & ~0xfUL)
14380 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
14381
14382 void default_idle(void);
14383 bool set_pm_idle_to_default(void);
14384
14385-void stop_this_cpu(void *dummy);
14386+void stop_this_cpu(void *dummy) __noreturn;
14387
14388 #endif /* _ASM_X86_PROCESSOR_H */
14389diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
14390index 942a086..6c26446 100644
14391--- a/arch/x86/include/asm/ptrace.h
14392+++ b/arch/x86/include/asm/ptrace.h
14393@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
14394 }
14395
14396 /*
14397- * user_mode_vm(regs) determines whether a register set came from user mode.
14398+ * user_mode(regs) determines whether a register set came from user mode.
14399 * This is true if V8086 mode was enabled OR if the register set was from
14400 * protected mode with RPL-3 CS value. This tricky test checks that with
14401 * one comparison. Many places in the kernel can bypass this full check
14402- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
14403+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
14404+ * be used.
14405 */
14406-static inline int user_mode(struct pt_regs *regs)
14407+static inline int user_mode_novm(struct pt_regs *regs)
14408 {
14409 #ifdef CONFIG_X86_32
14410 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
14411 #else
14412- return !!(regs->cs & 3);
14413+ return !!(regs->cs & SEGMENT_RPL_MASK);
14414 #endif
14415 }
14416
14417-static inline int user_mode_vm(struct pt_regs *regs)
14418+static inline int user_mode(struct pt_regs *regs)
14419 {
14420 #ifdef CONFIG_X86_32
14421 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
14422 USER_RPL;
14423 #else
14424- return user_mode(regs);
14425+ return user_mode_novm(regs);
14426 #endif
14427 }
14428
14429@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
14430 #ifdef CONFIG_X86_64
14431 static inline bool user_64bit_mode(struct pt_regs *regs)
14432 {
14433+ unsigned long cs = regs->cs & 0xffff;
14434 #ifndef CONFIG_PARAVIRT
14435 /*
14436 * On non-paravirt systems, this is the only long mode CPL 3
14437 * selector. We do not allow long mode selectors in the LDT.
14438 */
14439- return regs->cs == __USER_CS;
14440+ return cs == __USER_CS;
14441 #else
14442 /* Headers are too twisted for this to go in paravirt.h. */
14443- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
14444+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
14445 #endif
14446 }
14447
14448@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
14449 * Traps from the kernel do not save sp and ss.
14450 * Use the helper function to retrieve sp.
14451 */
14452- if (offset == offsetof(struct pt_regs, sp) &&
14453- regs->cs == __KERNEL_CS)
14454- return kernel_stack_pointer(regs);
14455+ if (offset == offsetof(struct pt_regs, sp)) {
14456+ unsigned long cs = regs->cs & 0xffff;
14457+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
14458+ return kernel_stack_pointer(regs);
14459+ }
14460 #endif
14461 return *(unsigned long *)((unsigned long)regs + offset);
14462 }
14463diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
14464index fe1ec5b..dc5c3fe 100644
14465--- a/arch/x86/include/asm/realmode.h
14466+++ b/arch/x86/include/asm/realmode.h
14467@@ -22,16 +22,14 @@ struct real_mode_header {
14468 #endif
14469 /* APM/BIOS reboot */
14470 u32 machine_real_restart_asm;
14471-#ifdef CONFIG_X86_64
14472 u32 machine_real_restart_seg;
14473-#endif
14474 };
14475
14476 /* This must match data at trampoline_32/64.S */
14477 struct trampoline_header {
14478 #ifdef CONFIG_X86_32
14479 u32 start;
14480- u16 gdt_pad;
14481+ u16 boot_cs;
14482 u16 gdt_limit;
14483 u32 gdt_base;
14484 #else
14485diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
14486index a82c4f1..ac45053 100644
14487--- a/arch/x86/include/asm/reboot.h
14488+++ b/arch/x86/include/asm/reboot.h
14489@@ -6,13 +6,13 @@
14490 struct pt_regs;
14491
14492 struct machine_ops {
14493- void (*restart)(char *cmd);
14494- void (*halt)(void);
14495- void (*power_off)(void);
14496+ void (* __noreturn restart)(char *cmd);
14497+ void (* __noreturn halt)(void);
14498+ void (* __noreturn power_off)(void);
14499 void (*shutdown)(void);
14500 void (*crash_shutdown)(struct pt_regs *);
14501- void (*emergency_restart)(void);
14502-};
14503+ void (* __noreturn emergency_restart)(void);
14504+} __no_const;
14505
14506 extern struct machine_ops machine_ops;
14507
14508diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
14509index 2dbe4a7..ce1db00 100644
14510--- a/arch/x86/include/asm/rwsem.h
14511+++ b/arch/x86/include/asm/rwsem.h
14512@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
14513 {
14514 asm volatile("# beginning down_read\n\t"
14515 LOCK_PREFIX _ASM_INC "(%1)\n\t"
14516+
14517+#ifdef CONFIG_PAX_REFCOUNT
14518+ "jno 0f\n"
14519+ LOCK_PREFIX _ASM_DEC "(%1)\n"
14520+ "int $4\n0:\n"
14521+ _ASM_EXTABLE(0b, 0b)
14522+#endif
14523+
14524 /* adds 0x00000001 */
14525 " jns 1f\n"
14526 " call call_rwsem_down_read_failed\n"
14527@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
14528 "1:\n\t"
14529 " mov %1,%2\n\t"
14530 " add %3,%2\n\t"
14531+
14532+#ifdef CONFIG_PAX_REFCOUNT
14533+ "jno 0f\n"
14534+ "sub %3,%2\n"
14535+ "int $4\n0:\n"
14536+ _ASM_EXTABLE(0b, 0b)
14537+#endif
14538+
14539 " jle 2f\n\t"
14540 LOCK_PREFIX " cmpxchg %2,%0\n\t"
14541 " jnz 1b\n\t"
14542@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
14543 long tmp;
14544 asm volatile("# beginning down_write\n\t"
14545 LOCK_PREFIX " xadd %1,(%2)\n\t"
14546+
14547+#ifdef CONFIG_PAX_REFCOUNT
14548+ "jno 0f\n"
14549+ "mov %1,(%2)\n"
14550+ "int $4\n0:\n"
14551+ _ASM_EXTABLE(0b, 0b)
14552+#endif
14553+
14554 /* adds 0xffff0001, returns the old value */
14555 " test %1,%1\n\t"
14556 /* was the count 0 before? */
14557@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
14558 long tmp;
14559 asm volatile("# beginning __up_read\n\t"
14560 LOCK_PREFIX " xadd %1,(%2)\n\t"
14561+
14562+#ifdef CONFIG_PAX_REFCOUNT
14563+ "jno 0f\n"
14564+ "mov %1,(%2)\n"
14565+ "int $4\n0:\n"
14566+ _ASM_EXTABLE(0b, 0b)
14567+#endif
14568+
14569 /* subtracts 1, returns the old value */
14570 " jns 1f\n\t"
14571 " call call_rwsem_wake\n" /* expects old value in %edx */
14572@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
14573 long tmp;
14574 asm volatile("# beginning __up_write\n\t"
14575 LOCK_PREFIX " xadd %1,(%2)\n\t"
14576+
14577+#ifdef CONFIG_PAX_REFCOUNT
14578+ "jno 0f\n"
14579+ "mov %1,(%2)\n"
14580+ "int $4\n0:\n"
14581+ _ASM_EXTABLE(0b, 0b)
14582+#endif
14583+
14584 /* subtracts 0xffff0001, returns the old value */
14585 " jns 1f\n\t"
14586 " call call_rwsem_wake\n" /* expects old value in %edx */
14587@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
14588 {
14589 asm volatile("# beginning __downgrade_write\n\t"
14590 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
14591+
14592+#ifdef CONFIG_PAX_REFCOUNT
14593+ "jno 0f\n"
14594+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
14595+ "int $4\n0:\n"
14596+ _ASM_EXTABLE(0b, 0b)
14597+#endif
14598+
14599 /*
14600 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
14601 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
14602@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
14603 */
14604 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
14605 {
14606- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
14607+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
14608+
14609+#ifdef CONFIG_PAX_REFCOUNT
14610+ "jno 0f\n"
14611+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
14612+ "int $4\n0:\n"
14613+ _ASM_EXTABLE(0b, 0b)
14614+#endif
14615+
14616 : "+m" (sem->count)
14617 : "er" (delta));
14618 }
14619@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
14620 */
14621 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
14622 {
14623- return delta + xadd(&sem->count, delta);
14624+ return delta + xadd_check_overflow(&sem->count, delta);
14625 }
14626
14627 #endif /* __KERNEL__ */
14628diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
14629index c48a950..c6d7468 100644
14630--- a/arch/x86/include/asm/segment.h
14631+++ b/arch/x86/include/asm/segment.h
14632@@ -64,10 +64,15 @@
14633 * 26 - ESPFIX small SS
14634 * 27 - per-cpu [ offset to per-cpu data area ]
14635 * 28 - stack_canary-20 [ for stack protector ]
14636- * 29 - unused
14637- * 30 - unused
14638+ * 29 - PCI BIOS CS
14639+ * 30 - PCI BIOS DS
14640 * 31 - TSS for double fault handler
14641 */
14642+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
14643+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
14644+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
14645+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
14646+
14647 #define GDT_ENTRY_TLS_MIN 6
14648 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
14649
14650@@ -79,6 +84,8 @@
14651
14652 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
14653
14654+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
14655+
14656 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
14657
14658 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
14659@@ -104,6 +111,12 @@
14660 #define __KERNEL_STACK_CANARY 0
14661 #endif
14662
14663+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
14664+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
14665+
14666+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
14667+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
14668+
14669 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
14670
14671 /*
14672@@ -141,7 +154,7 @@
14673 */
14674
14675 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
14676-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
14677+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
14678
14679
14680 #else
14681@@ -165,6 +178,8 @@
14682 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
14683 #define __USER32_DS __USER_DS
14684
14685+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
14686+
14687 #define GDT_ENTRY_TSS 8 /* needs two entries */
14688 #define GDT_ENTRY_LDT 10 /* needs two entries */
14689 #define GDT_ENTRY_TLS_MIN 12
14690@@ -185,6 +200,7 @@
14691 #endif
14692
14693 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
14694+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
14695 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
14696 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
14697 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
14698@@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
14699 {
14700 unsigned long __limit;
14701 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
14702- return __limit + 1;
14703+ return __limit;
14704 }
14705
14706 #endif /* !__ASSEMBLY__ */
14707diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
14708index b073aae..39f9bdd 100644
14709--- a/arch/x86/include/asm/smp.h
14710+++ b/arch/x86/include/asm/smp.h
14711@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
14712 /* cpus sharing the last level cache: */
14713 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
14714 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
14715-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
14716+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
14717
14718 static inline struct cpumask *cpu_sibling_mask(int cpu)
14719 {
14720@@ -79,7 +79,7 @@ struct smp_ops {
14721
14722 void (*send_call_func_ipi)(const struct cpumask *mask);
14723 void (*send_call_func_single_ipi)(int cpu);
14724-};
14725+} __no_const;
14726
14727 /* Globals due to paravirt */
14728 extern void set_cpu_sibling_map(int cpu);
14729@@ -191,14 +191,8 @@ extern unsigned disabled_cpus __cpuinitdata;
14730 extern int safe_smp_processor_id(void);
14731
14732 #elif defined(CONFIG_X86_64_SMP)
14733-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
14734-
14735-#define stack_smp_processor_id() \
14736-({ \
14737- struct thread_info *ti; \
14738- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
14739- ti->cpu; \
14740-})
14741+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
14742+#define stack_smp_processor_id() raw_smp_processor_id()
14743 #define safe_smp_processor_id() smp_processor_id()
14744
14745 #endif
14746diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
14747index 33692ea..350a534 100644
14748--- a/arch/x86/include/asm/spinlock.h
14749+++ b/arch/x86/include/asm/spinlock.h
14750@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
14751 static inline void arch_read_lock(arch_rwlock_t *rw)
14752 {
14753 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
14754+
14755+#ifdef CONFIG_PAX_REFCOUNT
14756+ "jno 0f\n"
14757+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
14758+ "int $4\n0:\n"
14759+ _ASM_EXTABLE(0b, 0b)
14760+#endif
14761+
14762 "jns 1f\n"
14763 "call __read_lock_failed\n\t"
14764 "1:\n"
14765@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
14766 static inline void arch_write_lock(arch_rwlock_t *rw)
14767 {
14768 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
14769+
14770+#ifdef CONFIG_PAX_REFCOUNT
14771+ "jno 0f\n"
14772+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
14773+ "int $4\n0:\n"
14774+ _ASM_EXTABLE(0b, 0b)
14775+#endif
14776+
14777 "jz 1f\n"
14778 "call __write_lock_failed\n\t"
14779 "1:\n"
14780@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
14781
14782 static inline void arch_read_unlock(arch_rwlock_t *rw)
14783 {
14784- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
14785+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
14786+
14787+#ifdef CONFIG_PAX_REFCOUNT
14788+ "jno 0f\n"
14789+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
14790+ "int $4\n0:\n"
14791+ _ASM_EXTABLE(0b, 0b)
14792+#endif
14793+
14794 :"+m" (rw->lock) : : "memory");
14795 }
14796
14797 static inline void arch_write_unlock(arch_rwlock_t *rw)
14798 {
14799- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
14800+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
14801+
14802+#ifdef CONFIG_PAX_REFCOUNT
14803+ "jno 0f\n"
14804+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
14805+ "int $4\n0:\n"
14806+ _ASM_EXTABLE(0b, 0b)
14807+#endif
14808+
14809 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
14810 }
14811
14812diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
14813index 6a99859..03cb807 100644
14814--- a/arch/x86/include/asm/stackprotector.h
14815+++ b/arch/x86/include/asm/stackprotector.h
14816@@ -47,7 +47,7 @@
14817 * head_32 for boot CPU and setup_per_cpu_areas() for others.
14818 */
14819 #define GDT_STACK_CANARY_INIT \
14820- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
14821+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
14822
14823 /*
14824 * Initialize the stackprotector canary value.
14825@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
14826
14827 static inline void load_stack_canary_segment(void)
14828 {
14829-#ifdef CONFIG_X86_32
14830+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
14831 asm volatile ("mov %0, %%gs" : : "r" (0));
14832 #endif
14833 }
14834diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
14835index 70bbe39..4ae2bd4 100644
14836--- a/arch/x86/include/asm/stacktrace.h
14837+++ b/arch/x86/include/asm/stacktrace.h
14838@@ -11,28 +11,20 @@
14839
14840 extern int kstack_depth_to_print;
14841
14842-struct thread_info;
14843+struct task_struct;
14844 struct stacktrace_ops;
14845
14846-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
14847- unsigned long *stack,
14848- unsigned long bp,
14849- const struct stacktrace_ops *ops,
14850- void *data,
14851- unsigned long *end,
14852- int *graph);
14853+typedef unsigned long walk_stack_t(struct task_struct *task,
14854+ void *stack_start,
14855+ unsigned long *stack,
14856+ unsigned long bp,
14857+ const struct stacktrace_ops *ops,
14858+ void *data,
14859+ unsigned long *end,
14860+ int *graph);
14861
14862-extern unsigned long
14863-print_context_stack(struct thread_info *tinfo,
14864- unsigned long *stack, unsigned long bp,
14865- const struct stacktrace_ops *ops, void *data,
14866- unsigned long *end, int *graph);
14867-
14868-extern unsigned long
14869-print_context_stack_bp(struct thread_info *tinfo,
14870- unsigned long *stack, unsigned long bp,
14871- const struct stacktrace_ops *ops, void *data,
14872- unsigned long *end, int *graph);
14873+extern walk_stack_t print_context_stack;
14874+extern walk_stack_t print_context_stack_bp;
14875
14876 /* Generic stack tracer with callbacks */
14877
14878@@ -40,7 +32,7 @@ struct stacktrace_ops {
14879 void (*address)(void *data, unsigned long address, int reliable);
14880 /* On negative return stop dumping */
14881 int (*stack)(void *data, char *name);
14882- walk_stack_t walk_stack;
14883+ walk_stack_t *walk_stack;
14884 };
14885
14886 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
14887diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
14888index 4ec45b3..a4f0a8a 100644
14889--- a/arch/x86/include/asm/switch_to.h
14890+++ b/arch/x86/include/asm/switch_to.h
14891@@ -108,7 +108,7 @@ do { \
14892 "call __switch_to\n\t" \
14893 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
14894 __switch_canary \
14895- "movq %P[thread_info](%%rsi),%%r8\n\t" \
14896+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
14897 "movq %%rax,%%rdi\n\t" \
14898 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
14899 "jnz ret_from_fork\n\t" \
14900@@ -119,7 +119,7 @@ do { \
14901 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
14902 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
14903 [_tif_fork] "i" (_TIF_FORK), \
14904- [thread_info] "i" (offsetof(struct task_struct, stack)), \
14905+ [thread_info] "m" (current_tinfo), \
14906 [current_task] "m" (current_task) \
14907 __switch_canary_iparam \
14908 : "memory", "cc" __EXTRA_CLOBBER)
14909diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
14910index 2d946e6..e453ec4 100644
14911--- a/arch/x86/include/asm/thread_info.h
14912+++ b/arch/x86/include/asm/thread_info.h
14913@@ -10,6 +10,7 @@
14914 #include <linux/compiler.h>
14915 #include <asm/page.h>
14916 #include <asm/types.h>
14917+#include <asm/percpu.h>
14918
14919 /*
14920 * low level task data that entry.S needs immediate access to
14921@@ -24,7 +25,6 @@ struct exec_domain;
14922 #include <linux/atomic.h>
14923
14924 struct thread_info {
14925- struct task_struct *task; /* main task structure */
14926 struct exec_domain *exec_domain; /* execution domain */
14927 __u32 flags; /* low level flags */
14928 __u32 status; /* thread synchronous flags */
14929@@ -34,19 +34,13 @@ struct thread_info {
14930 mm_segment_t addr_limit;
14931 struct restart_block restart_block;
14932 void __user *sysenter_return;
14933-#ifdef CONFIG_X86_32
14934- unsigned long previous_esp; /* ESP of the previous stack in
14935- case of nested (IRQ) stacks
14936- */
14937- __u8 supervisor_stack[0];
14938-#endif
14939+ unsigned long lowest_stack;
14940 unsigned int sig_on_uaccess_error:1;
14941 unsigned int uaccess_err:1; /* uaccess failed */
14942 };
14943
14944-#define INIT_THREAD_INFO(tsk) \
14945+#define INIT_THREAD_INFO \
14946 { \
14947- .task = &tsk, \
14948 .exec_domain = &default_exec_domain, \
14949 .flags = 0, \
14950 .cpu = 0, \
14951@@ -57,7 +51,7 @@ struct thread_info {
14952 }, \
14953 }
14954
14955-#define init_thread_info (init_thread_union.thread_info)
14956+#define init_thread_info (init_thread_union.stack)
14957 #define init_stack (init_thread_union.stack)
14958
14959 #else /* !__ASSEMBLY__ */
14960@@ -98,6 +92,7 @@ struct thread_info {
14961 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
14962 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
14963 #define TIF_X32 30 /* 32-bit native x86-64 binary */
14964+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
14965
14966 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
14967 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
14968@@ -122,17 +117,18 @@ struct thread_info {
14969 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
14970 #define _TIF_ADDR32 (1 << TIF_ADDR32)
14971 #define _TIF_X32 (1 << TIF_X32)
14972+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
14973
14974 /* work to do in syscall_trace_enter() */
14975 #define _TIF_WORK_SYSCALL_ENTRY \
14976 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
14977 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
14978- _TIF_NOHZ)
14979+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
14980
14981 /* work to do in syscall_trace_leave() */
14982 #define _TIF_WORK_SYSCALL_EXIT \
14983 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
14984- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
14985+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
14986
14987 /* work to do on interrupt/exception return */
14988 #define _TIF_WORK_MASK \
14989@@ -143,7 +139,7 @@ struct thread_info {
14990 /* work to do on any return to user space */
14991 #define _TIF_ALLWORK_MASK \
14992 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
14993- _TIF_NOHZ)
14994+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
14995
14996 /* Only used for 64 bit */
14997 #define _TIF_DO_NOTIFY_MASK \
14998@@ -159,45 +155,40 @@ struct thread_info {
14999
15000 #define PREEMPT_ACTIVE 0x10000000
15001
15002-#ifdef CONFIG_X86_32
15003-
15004-#define STACK_WARN (THREAD_SIZE/8)
15005-/*
15006- * macros/functions for gaining access to the thread information structure
15007- *
15008- * preempt_count needs to be 1 initially, until the scheduler is functional.
15009- */
15010-#ifndef __ASSEMBLY__
15011-
15012-
15013-/* how to get the current stack pointer from C */
15014-register unsigned long current_stack_pointer asm("esp") __used;
15015-
15016-/* how to get the thread information struct from C */
15017-static inline struct thread_info *current_thread_info(void)
15018-{
15019- return (struct thread_info *)
15020- (current_stack_pointer & ~(THREAD_SIZE - 1));
15021-}
15022-
15023-#else /* !__ASSEMBLY__ */
15024-
15025+#ifdef __ASSEMBLY__
15026 /* how to get the thread information struct from ASM */
15027 #define GET_THREAD_INFO(reg) \
15028- movl $-THREAD_SIZE, reg; \
15029- andl %esp, reg
15030+ mov PER_CPU_VAR(current_tinfo), reg
15031
15032 /* use this one if reg already contains %esp */
15033-#define GET_THREAD_INFO_WITH_ESP(reg) \
15034- andl $-THREAD_SIZE, reg
15035+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
15036+#else
15037+/* how to get the thread information struct from C */
15038+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
15039+
15040+static __always_inline struct thread_info *current_thread_info(void)
15041+{
15042+ return this_cpu_read_stable(current_tinfo);
15043+}
15044+#endif
15045+
15046+#ifdef CONFIG_X86_32
15047+
15048+#define STACK_WARN (THREAD_SIZE/8)
15049+/*
15050+ * macros/functions for gaining access to the thread information structure
15051+ *
15052+ * preempt_count needs to be 1 initially, until the scheduler is functional.
15053+ */
15054+#ifndef __ASSEMBLY__
15055+
15056+/* how to get the current stack pointer from C */
15057+register unsigned long current_stack_pointer asm("esp") __used;
15058
15059 #endif
15060
15061 #else /* X86_32 */
15062
15063-#include <asm/percpu.h>
15064-#define KERNEL_STACK_OFFSET (5*8)
15065-
15066 /*
15067 * macros/functions for gaining access to the thread information structure
15068 * preempt_count needs to be 1 initially, until the scheduler is functional.
15069@@ -205,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
15070 #ifndef __ASSEMBLY__
15071 DECLARE_PER_CPU(unsigned long, kernel_stack);
15072
15073-static inline struct thread_info *current_thread_info(void)
15074-{
15075- struct thread_info *ti;
15076- ti = (void *)(this_cpu_read_stable(kernel_stack) +
15077- KERNEL_STACK_OFFSET - THREAD_SIZE);
15078- return ti;
15079-}
15080-
15081-#else /* !__ASSEMBLY__ */
15082-
15083-/* how to get the thread information struct from ASM */
15084-#define GET_THREAD_INFO(reg) \
15085- movq PER_CPU_VAR(kernel_stack),reg ; \
15086- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
15087-
15088-/*
15089- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
15090- * a certain register (to be used in assembler memory operands).
15091- */
15092-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
15093-
15094+/* how to get the current stack pointer from C */
15095+register unsigned long current_stack_pointer asm("rsp") __used;
15096 #endif
15097
15098 #endif /* !X86_32 */
15099@@ -286,5 +258,12 @@ static inline bool is_ia32_task(void)
15100 extern void arch_task_cache_init(void);
15101 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
15102 extern void arch_release_task_struct(struct task_struct *tsk);
15103+
15104+#define __HAVE_THREAD_FUNCTIONS
15105+#define task_thread_info(task) (&(task)->tinfo)
15106+#define task_stack_page(task) ((task)->stack)
15107+#define setup_thread_stack(p, org) do {} while (0)
15108+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
15109+
15110 #endif
15111 #endif /* _ASM_X86_THREAD_INFO_H */
15112diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
15113index 1709801..0a60f2f 100644
15114--- a/arch/x86/include/asm/uaccess.h
15115+++ b/arch/x86/include/asm/uaccess.h
15116@@ -7,6 +7,7 @@
15117 #include <linux/compiler.h>
15118 #include <linux/thread_info.h>
15119 #include <linux/string.h>
15120+#include <linux/sched.h>
15121 #include <asm/asm.h>
15122 #include <asm/page.h>
15123 #include <asm/smap.h>
15124@@ -29,7 +30,12 @@
15125
15126 #define get_ds() (KERNEL_DS)
15127 #define get_fs() (current_thread_info()->addr_limit)
15128+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15129+void __set_fs(mm_segment_t x);
15130+void set_fs(mm_segment_t x);
15131+#else
15132 #define set_fs(x) (current_thread_info()->addr_limit = (x))
15133+#endif
15134
15135 #define segment_eq(a, b) ((a).seg == (b).seg)
15136
15137@@ -77,8 +83,33 @@
15138 * checks that the pointer is in the user space range - after calling
15139 * this function, memory access functions may still return -EFAULT.
15140 */
15141-#define access_ok(type, addr, size) \
15142- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15143+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15144+#define access_ok(type, addr, size) \
15145+({ \
15146+ long __size = size; \
15147+ unsigned long __addr = (unsigned long)addr; \
15148+ unsigned long __addr_ao = __addr & PAGE_MASK; \
15149+ unsigned long __end_ao = __addr + __size - 1; \
15150+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
15151+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
15152+ while(__addr_ao <= __end_ao) { \
15153+ char __c_ao; \
15154+ __addr_ao += PAGE_SIZE; \
15155+ if (__size > PAGE_SIZE) \
15156+ cond_resched(); \
15157+ if (__get_user(__c_ao, (char __user *)__addr)) \
15158+ break; \
15159+ if (type != VERIFY_WRITE) { \
15160+ __addr = __addr_ao; \
15161+ continue; \
15162+ } \
15163+ if (__put_user(__c_ao, (char __user *)__addr)) \
15164+ break; \
15165+ __addr = __addr_ao; \
15166+ } \
15167+ } \
15168+ __ret_ao; \
15169+})
15170
15171 /*
15172 * The exception table consists of pairs of addresses relative to the
15173@@ -189,13 +220,21 @@ extern int __get_user_bad(void);
15174 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
15175 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
15176
15177-
15178+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15179+#define __copyuser_seg "gs;"
15180+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
15181+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
15182+#else
15183+#define __copyuser_seg
15184+#define __COPYUSER_SET_ES
15185+#define __COPYUSER_RESTORE_ES
15186+#endif
15187
15188 #ifdef CONFIG_X86_32
15189 #define __put_user_asm_u64(x, addr, err, errret) \
15190 asm volatile(ASM_STAC "\n" \
15191- "1: movl %%eax,0(%2)\n" \
15192- "2: movl %%edx,4(%2)\n" \
15193+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
15194+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
15195 "3: " ASM_CLAC "\n" \
15196 ".section .fixup,\"ax\"\n" \
15197 "4: movl %3,%0\n" \
15198@@ -208,8 +247,8 @@ extern int __get_user_bad(void);
15199
15200 #define __put_user_asm_ex_u64(x, addr) \
15201 asm volatile(ASM_STAC "\n" \
15202- "1: movl %%eax,0(%1)\n" \
15203- "2: movl %%edx,4(%1)\n" \
15204+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
15205+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
15206 "3: " ASM_CLAC "\n" \
15207 _ASM_EXTABLE_EX(1b, 2b) \
15208 _ASM_EXTABLE_EX(2b, 3b) \
15209@@ -259,7 +298,7 @@ extern void __put_user_8(void);
15210 __typeof__(*(ptr)) __pu_val; \
15211 __chk_user_ptr(ptr); \
15212 might_fault(); \
15213- __pu_val = x; \
15214+ __pu_val = (x); \
15215 switch (sizeof(*(ptr))) { \
15216 case 1: \
15217 __put_user_x(1, __pu_val, ptr, __ret_pu); \
15218@@ -358,7 +397,7 @@ do { \
15219
15220 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15221 asm volatile(ASM_STAC "\n" \
15222- "1: mov"itype" %2,%"rtype"1\n" \
15223+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
15224 "2: " ASM_CLAC "\n" \
15225 ".section .fixup,\"ax\"\n" \
15226 "3: mov %3,%0\n" \
15227@@ -366,7 +405,7 @@ do { \
15228 " jmp 2b\n" \
15229 ".previous\n" \
15230 _ASM_EXTABLE(1b, 3b) \
15231- : "=r" (err), ltype(x) \
15232+ : "=r" (err), ltype (x) \
15233 : "m" (__m(addr)), "i" (errret), "0" (err))
15234
15235 #define __get_user_size_ex(x, ptr, size) \
15236@@ -391,7 +430,7 @@ do { \
15237 } while (0)
15238
15239 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
15240- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
15241+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
15242 "2:\n" \
15243 _ASM_EXTABLE_EX(1b, 2b) \
15244 : ltype(x) : "m" (__m(addr)))
15245@@ -408,13 +447,24 @@ do { \
15246 int __gu_err; \
15247 unsigned long __gu_val; \
15248 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
15249- (x) = (__force __typeof__(*(ptr)))__gu_val; \
15250+ (x) = (__typeof__(*(ptr)))__gu_val; \
15251 __gu_err; \
15252 })
15253
15254 /* FIXME: this hack is definitely wrong -AK */
15255 struct __large_struct { unsigned long buf[100]; };
15256-#define __m(x) (*(struct __large_struct __user *)(x))
15257+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15258+#define ____m(x) \
15259+({ \
15260+ unsigned long ____x = (unsigned long)(x); \
15261+ if (____x < PAX_USER_SHADOW_BASE) \
15262+ ____x += PAX_USER_SHADOW_BASE; \
15263+ (void __user *)____x; \
15264+})
15265+#else
15266+#define ____m(x) (x)
15267+#endif
15268+#define __m(x) (*(struct __large_struct __user *)____m(x))
15269
15270 /*
15271 * Tell gcc we read from memory instead of writing: this is because
15272@@ -423,7 +473,7 @@ struct __large_struct { unsigned long buf[100]; };
15273 */
15274 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15275 asm volatile(ASM_STAC "\n" \
15276- "1: mov"itype" %"rtype"1,%2\n" \
15277+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
15278 "2: " ASM_CLAC "\n" \
15279 ".section .fixup,\"ax\"\n" \
15280 "3: mov %3,%0\n" \
15281@@ -431,10 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
15282 ".previous\n" \
15283 _ASM_EXTABLE(1b, 3b) \
15284 : "=r"(err) \
15285- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
15286+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
15287
15288 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
15289- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
15290+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
15291 "2:\n" \
15292 _ASM_EXTABLE_EX(1b, 2b) \
15293 : : ltype(x), "m" (__m(addr)))
15294@@ -473,8 +523,12 @@ struct __large_struct { unsigned long buf[100]; };
15295 * On error, the variable @x is set to zero.
15296 */
15297
15298+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15299+#define __get_user(x, ptr) get_user((x), (ptr))
15300+#else
15301 #define __get_user(x, ptr) \
15302 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
15303+#endif
15304
15305 /**
15306 * __put_user: - Write a simple value into user space, with less checking.
15307@@ -496,8 +550,12 @@ struct __large_struct { unsigned long buf[100]; };
15308 * Returns zero on success, or -EFAULT on error.
15309 */
15310
15311+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15312+#define __put_user(x, ptr) put_user((x), (ptr))
15313+#else
15314 #define __put_user(x, ptr) \
15315 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
15316+#endif
15317
15318 #define __get_user_unaligned __get_user
15319 #define __put_user_unaligned __put_user
15320@@ -515,7 +573,7 @@ struct __large_struct { unsigned long buf[100]; };
15321 #define get_user_ex(x, ptr) do { \
15322 unsigned long __gue_val; \
15323 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
15324- (x) = (__force __typeof__(*(ptr)))__gue_val; \
15325+ (x) = (__typeof__(*(ptr)))__gue_val; \
15326 } while (0)
15327
15328 #define put_user_try uaccess_try
15329@@ -532,8 +590,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
15330 extern __must_check long strlen_user(const char __user *str);
15331 extern __must_check long strnlen_user(const char __user *str, long n);
15332
15333-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
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) __size_overflow(2);
15336+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15337
15338 /*
15339 * movsl can be slow when source and dest are not both 8-byte aligned
15340diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
15341index 7f760a9..04b1c65 100644
15342--- a/arch/x86/include/asm/uaccess_32.h
15343+++ b/arch/x86/include/asm/uaccess_32.h
15344@@ -11,15 +11,15 @@
15345 #include <asm/page.h>
15346
15347 unsigned long __must_check __copy_to_user_ll
15348- (void __user *to, const void *from, unsigned long n);
15349+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
15350 unsigned long __must_check __copy_from_user_ll
15351- (void *to, const void __user *from, unsigned long n);
15352+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15353 unsigned long __must_check __copy_from_user_ll_nozero
15354- (void *to, const void __user *from, unsigned long n);
15355+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15356 unsigned long __must_check __copy_from_user_ll_nocache
15357- (void *to, const void __user *from, unsigned long n);
15358+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15359 unsigned long __must_check __copy_from_user_ll_nocache_nozero
15360- (void *to, const void __user *from, unsigned long n);
15361+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15362
15363 /**
15364 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
15365@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
15366 static __always_inline unsigned long __must_check
15367 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
15368 {
15369+ if ((long)n < 0)
15370+ return n;
15371+
15372+ check_object_size(from, n, true);
15373+
15374 if (__builtin_constant_p(n)) {
15375 unsigned long ret;
15376
15377@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
15378 __copy_to_user(void __user *to, const void *from, unsigned long n)
15379 {
15380 might_fault();
15381+
15382 return __copy_to_user_inatomic(to, from, n);
15383 }
15384
15385 static __always_inline unsigned long
15386 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
15387 {
15388+ if ((long)n < 0)
15389+ return n;
15390+
15391 /* Avoid zeroing the tail if the copy fails..
15392 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
15393 * but as the zeroing behaviour is only significant when n is not
15394@@ -137,6 +146,12 @@ static __always_inline unsigned long
15395 __copy_from_user(void *to, const void __user *from, unsigned long n)
15396 {
15397 might_fault();
15398+
15399+ if ((long)n < 0)
15400+ return n;
15401+
15402+ check_object_size(to, n, false);
15403+
15404 if (__builtin_constant_p(n)) {
15405 unsigned long ret;
15406
15407@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
15408 const void __user *from, unsigned long n)
15409 {
15410 might_fault();
15411+
15412+ if ((long)n < 0)
15413+ return n;
15414+
15415 if (__builtin_constant_p(n)) {
15416 unsigned long ret;
15417
15418@@ -181,15 +200,19 @@ static __always_inline unsigned long
15419 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
15420 unsigned long n)
15421 {
15422- return __copy_from_user_ll_nocache_nozero(to, from, n);
15423+ if ((long)n < 0)
15424+ return n;
15425+
15426+ return __copy_from_user_ll_nocache_nozero(to, from, n);
15427 }
15428
15429-unsigned long __must_check copy_to_user(void __user *to,
15430- const void *from, unsigned long n);
15431-unsigned long __must_check _copy_from_user(void *to,
15432- const void __user *from,
15433- unsigned long n);
15434-
15435+extern void copy_to_user_overflow(void)
15436+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15437+ __compiletime_error("copy_to_user() buffer size is not provably correct")
15438+#else
15439+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
15440+#endif
15441+;
15442
15443 extern void copy_from_user_overflow(void)
15444 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15445@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
15446 #endif
15447 ;
15448
15449-static inline unsigned long __must_check copy_from_user(void *to,
15450- const void __user *from,
15451- unsigned long n)
15452+/**
15453+ * copy_to_user: - Copy a block of data into user space.
15454+ * @to: Destination address, in user space.
15455+ * @from: Source address, in kernel space.
15456+ * @n: Number of bytes to copy.
15457+ *
15458+ * Context: User context only. This function may sleep.
15459+ *
15460+ * Copy data from kernel space to user space.
15461+ *
15462+ * Returns number of bytes that could not be copied.
15463+ * On success, this will be zero.
15464+ */
15465+static inline unsigned long __must_check
15466+copy_to_user(void __user *to, const void *from, unsigned long n)
15467 {
15468- int sz = __compiletime_object_size(to);
15469+ size_t sz = __compiletime_object_size(from);
15470
15471- if (likely(sz == -1 || sz >= n))
15472- n = _copy_from_user(to, from, n);
15473- else
15474+ if (unlikely(sz != (size_t)-1 && sz < n))
15475+ copy_to_user_overflow();
15476+ else if (access_ok(VERIFY_WRITE, to, n))
15477+ n = __copy_to_user(to, from, n);
15478+ return n;
15479+}
15480+
15481+/**
15482+ * copy_from_user: - Copy a block of data from user space.
15483+ * @to: Destination address, in kernel space.
15484+ * @from: Source address, in user space.
15485+ * @n: Number of bytes to copy.
15486+ *
15487+ * Context: User context only. This function may sleep.
15488+ *
15489+ * Copy data from user space to kernel space.
15490+ *
15491+ * Returns number of bytes that could not be copied.
15492+ * On success, this will be zero.
15493+ *
15494+ * If some data could not be copied, this function will pad the copied
15495+ * data to the requested size using zero bytes.
15496+ */
15497+static inline unsigned long __must_check
15498+copy_from_user(void *to, const void __user *from, unsigned long n)
15499+{
15500+ size_t sz = __compiletime_object_size(to);
15501+
15502+ check_object_size(to, n, false);
15503+
15504+ if (unlikely(sz != (size_t)-1 && sz < n))
15505 copy_from_user_overflow();
15506-
15507+ else if (access_ok(VERIFY_READ, from, n))
15508+ n = __copy_from_user(to, from, n);
15509+ else if ((long)n > 0)
15510+ memset(to, 0, n);
15511 return n;
15512 }
15513
15514diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
15515index 142810c..747941a 100644
15516--- a/arch/x86/include/asm/uaccess_64.h
15517+++ b/arch/x86/include/asm/uaccess_64.h
15518@@ -10,6 +10,9 @@
15519 #include <asm/alternative.h>
15520 #include <asm/cpufeature.h>
15521 #include <asm/page.h>
15522+#include <asm/pgtable.h>
15523+
15524+#define set_fs(x) (current_thread_info()->addr_limit = (x))
15525
15526 /*
15527 * Copy To/From Userspace
15528@@ -17,13 +20,13 @@
15529
15530 /* Handles exceptions in both to and from, but doesn't do access_ok */
15531 __must_check unsigned long
15532-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
15533+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
15534 __must_check unsigned long
15535-copy_user_generic_string(void *to, const void *from, unsigned len);
15536+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
15537 __must_check unsigned long
15538-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
15539+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
15540
15541-static __always_inline __must_check unsigned long
15542+static __always_inline __must_check __size_overflow(3) unsigned long
15543 copy_user_generic(void *to, const void *from, unsigned len)
15544 {
15545 unsigned ret;
15546@@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
15547 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
15548 "=d" (len)),
15549 "1" (to), "2" (from), "3" (len)
15550- : "memory", "rcx", "r8", "r9", "r10", "r11");
15551+ : "memory", "rcx", "r8", "r9", "r11");
15552 return ret;
15553 }
15554
15555+static __always_inline __must_check unsigned long
15556+__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
15557+static __always_inline __must_check unsigned long
15558+__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
15559 __must_check unsigned long
15560-_copy_to_user(void __user *to, const void *from, unsigned len);
15561-__must_check unsigned long
15562-_copy_from_user(void *to, const void __user *from, unsigned len);
15563-__must_check unsigned long
15564-copy_in_user(void __user *to, const void __user *from, unsigned len);
15565+copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
15566+
15567+extern void copy_to_user_overflow(void)
15568+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15569+ __compiletime_error("copy_to_user() buffer size is not provably correct")
15570+#else
15571+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
15572+#endif
15573+;
15574+
15575+extern void copy_from_user_overflow(void)
15576+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15577+ __compiletime_error("copy_from_user() buffer size is not provably correct")
15578+#else
15579+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
15580+#endif
15581+;
15582
15583 static inline unsigned long __must_check copy_from_user(void *to,
15584 const void __user *from,
15585 unsigned long n)
15586 {
15587- int sz = __compiletime_object_size(to);
15588-
15589 might_fault();
15590- if (likely(sz == -1 || sz >= n))
15591- n = _copy_from_user(to, from, n);
15592-#ifdef CONFIG_DEBUG_VM
15593- else
15594- WARN(1, "Buffer overflow detected!\n");
15595-#endif
15596+
15597+ check_object_size(to, n, false);
15598+
15599+ if (access_ok(VERIFY_READ, from, n))
15600+ n = __copy_from_user(to, from, n);
15601+ else if (n < INT_MAX)
15602+ memset(to, 0, n);
15603 return n;
15604 }
15605
15606 static __always_inline __must_check
15607-int copy_to_user(void __user *dst, const void *src, unsigned size)
15608+int copy_to_user(void __user *dst, const void *src, unsigned long size)
15609 {
15610 might_fault();
15611
15612- return _copy_to_user(dst, src, size);
15613+ if (access_ok(VERIFY_WRITE, dst, size))
15614+ size = __copy_to_user(dst, src, size);
15615+ return size;
15616 }
15617
15618 static __always_inline __must_check
15619-int __copy_from_user(void *dst, const void __user *src, unsigned size)
15620+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
15621 {
15622- int ret = 0;
15623+ size_t sz = __compiletime_object_size(dst);
15624+ unsigned ret = 0;
15625
15626 might_fault();
15627+
15628+ if (size > INT_MAX)
15629+ return size;
15630+
15631+ check_object_size(dst, size, false);
15632+
15633+#ifdef CONFIG_PAX_MEMORY_UDEREF
15634+ if (!__access_ok(VERIFY_READ, src, size))
15635+ return size;
15636+#endif
15637+
15638+ if (unlikely(sz != (size_t)-1 && sz < size)) {
15639+ copy_from_user_overflow();
15640+ return size;
15641+ }
15642+
15643 if (!__builtin_constant_p(size))
15644- return copy_user_generic(dst, (__force void *)src, size);
15645+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
15646 switch (size) {
15647- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
15648+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
15649 ret, "b", "b", "=q", 1);
15650 return ret;
15651- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
15652+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
15653 ret, "w", "w", "=r", 2);
15654 return ret;
15655- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
15656+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
15657 ret, "l", "k", "=r", 4);
15658 return ret;
15659- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
15660+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
15661 ret, "q", "", "=r", 8);
15662 return ret;
15663 case 10:
15664- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
15665+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
15666 ret, "q", "", "=r", 10);
15667 if (unlikely(ret))
15668 return ret;
15669 __get_user_asm(*(u16 *)(8 + (char *)dst),
15670- (u16 __user *)(8 + (char __user *)src),
15671+ (const u16 __user *)(8 + (const char __user *)src),
15672 ret, "w", "w", "=r", 2);
15673 return ret;
15674 case 16:
15675- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
15676+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
15677 ret, "q", "", "=r", 16);
15678 if (unlikely(ret))
15679 return ret;
15680 __get_user_asm(*(u64 *)(8 + (char *)dst),
15681- (u64 __user *)(8 + (char __user *)src),
15682+ (const u64 __user *)(8 + (const char __user *)src),
15683 ret, "q", "", "=r", 8);
15684 return ret;
15685 default:
15686- return copy_user_generic(dst, (__force void *)src, size);
15687+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
15688 }
15689 }
15690
15691 static __always_inline __must_check
15692-int __copy_to_user(void __user *dst, const void *src, unsigned size)
15693+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
15694 {
15695- int ret = 0;
15696+ size_t sz = __compiletime_object_size(src);
15697+ unsigned ret = 0;
15698
15699 might_fault();
15700+
15701+ if (size > INT_MAX)
15702+ return size;
15703+
15704+ check_object_size(src, size, true);
15705+
15706+#ifdef CONFIG_PAX_MEMORY_UDEREF
15707+ if (!__access_ok(VERIFY_WRITE, dst, size))
15708+ return size;
15709+#endif
15710+
15711+ if (unlikely(sz != (size_t)-1 && sz < size)) {
15712+ copy_to_user_overflow();
15713+ return size;
15714+ }
15715+
15716 if (!__builtin_constant_p(size))
15717- return copy_user_generic((__force void *)dst, src, size);
15718+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
15719 switch (size) {
15720- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
15721+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
15722 ret, "b", "b", "iq", 1);
15723 return ret;
15724- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
15725+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
15726 ret, "w", "w", "ir", 2);
15727 return ret;
15728- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
15729+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
15730 ret, "l", "k", "ir", 4);
15731 return ret;
15732- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
15733+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
15734 ret, "q", "", "er", 8);
15735 return ret;
15736 case 10:
15737- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
15738+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
15739 ret, "q", "", "er", 10);
15740 if (unlikely(ret))
15741 return ret;
15742 asm("":::"memory");
15743- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
15744+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
15745 ret, "w", "w", "ir", 2);
15746 return ret;
15747 case 16:
15748- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
15749+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
15750 ret, "q", "", "er", 16);
15751 if (unlikely(ret))
15752 return ret;
15753 asm("":::"memory");
15754- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
15755+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
15756 ret, "q", "", "er", 8);
15757 return ret;
15758 default:
15759- return copy_user_generic((__force void *)dst, src, size);
15760+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
15761 }
15762 }
15763
15764 static __always_inline __must_check
15765-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15766+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
15767 {
15768- int ret = 0;
15769+ unsigned ret = 0;
15770
15771 might_fault();
15772+
15773+ if (size > INT_MAX)
15774+ return size;
15775+
15776+#ifdef CONFIG_PAX_MEMORY_UDEREF
15777+ if (!__access_ok(VERIFY_READ, src, size))
15778+ return size;
15779+ if (!__access_ok(VERIFY_WRITE, dst, size))
15780+ return size;
15781+#endif
15782+
15783 if (!__builtin_constant_p(size))
15784- return copy_user_generic((__force void *)dst,
15785- (__force void *)src, size);
15786+ return copy_user_generic((__force_kernel void *)____m(dst),
15787+ (__force_kernel const void *)____m(src), size);
15788 switch (size) {
15789 case 1: {
15790 u8 tmp;
15791- __get_user_asm(tmp, (u8 __user *)src,
15792+ __get_user_asm(tmp, (const u8 __user *)src,
15793 ret, "b", "b", "=q", 1);
15794 if (likely(!ret))
15795 __put_user_asm(tmp, (u8 __user *)dst,
15796@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15797 }
15798 case 2: {
15799 u16 tmp;
15800- __get_user_asm(tmp, (u16 __user *)src,
15801+ __get_user_asm(tmp, (const u16 __user *)src,
15802 ret, "w", "w", "=r", 2);
15803 if (likely(!ret))
15804 __put_user_asm(tmp, (u16 __user *)dst,
15805@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15806
15807 case 4: {
15808 u32 tmp;
15809- __get_user_asm(tmp, (u32 __user *)src,
15810+ __get_user_asm(tmp, (const u32 __user *)src,
15811 ret, "l", "k", "=r", 4);
15812 if (likely(!ret))
15813 __put_user_asm(tmp, (u32 __user *)dst,
15814@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15815 }
15816 case 8: {
15817 u64 tmp;
15818- __get_user_asm(tmp, (u64 __user *)src,
15819+ __get_user_asm(tmp, (const u64 __user *)src,
15820 ret, "q", "", "=r", 8);
15821 if (likely(!ret))
15822 __put_user_asm(tmp, (u64 __user *)dst,
15823@@ -212,41 +277,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15824 return ret;
15825 }
15826 default:
15827- return copy_user_generic((__force void *)dst,
15828- (__force void *)src, size);
15829+ return copy_user_generic((__force_kernel void *)____m(dst),
15830+ (__force_kernel const void *)____m(src), size);
15831 }
15832 }
15833
15834 static __must_check __always_inline int
15835-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
15836+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
15837 {
15838- return copy_user_generic(dst, (__force const void *)src, size);
15839+ if (size > INT_MAX)
15840+ return size;
15841+
15842+#ifdef CONFIG_PAX_MEMORY_UDEREF
15843+ if (!__access_ok(VERIFY_READ, src, size))
15844+ return size;
15845+#endif
15846+
15847+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
15848 }
15849
15850-static __must_check __always_inline int
15851-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
15852+static __must_check __always_inline unsigned long
15853+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
15854 {
15855- return copy_user_generic((__force void *)dst, src, size);
15856+ if (size > INT_MAX)
15857+ return size;
15858+
15859+#ifdef CONFIG_PAX_MEMORY_UDEREF
15860+ if (!__access_ok(VERIFY_WRITE, dst, size))
15861+ return size;
15862+#endif
15863+
15864+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
15865 }
15866
15867-extern long __copy_user_nocache(void *dst, const void __user *src,
15868- unsigned size, int zerorest);
15869+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
15870+ unsigned long size, int zerorest) __size_overflow(3);
15871
15872-static inline int
15873-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
15874+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
15875 {
15876 might_sleep();
15877+
15878+ if (size > INT_MAX)
15879+ return size;
15880+
15881+#ifdef CONFIG_PAX_MEMORY_UDEREF
15882+ if (!__access_ok(VERIFY_READ, src, size))
15883+ return size;
15884+#endif
15885+
15886 return __copy_user_nocache(dst, src, size, 1);
15887 }
15888
15889-static inline int
15890-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
15891- unsigned size)
15892+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
15893+ unsigned long size)
15894 {
15895+ if (size > INT_MAX)
15896+ return size;
15897+
15898+#ifdef CONFIG_PAX_MEMORY_UDEREF
15899+ if (!__access_ok(VERIFY_READ, src, size))
15900+ return size;
15901+#endif
15902+
15903 return __copy_user_nocache(dst, src, size, 0);
15904 }
15905
15906-unsigned long
15907-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
15908+extern unsigned long
15909+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
15910
15911 #endif /* _ASM_X86_UACCESS_64_H */
15912diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
15913index 5b238981..77fdd78 100644
15914--- a/arch/x86/include/asm/word-at-a-time.h
15915+++ b/arch/x86/include/asm/word-at-a-time.h
15916@@ -11,7 +11,7 @@
15917 * and shift, for example.
15918 */
15919 struct word_at_a_time {
15920- const unsigned long one_bits, high_bits;
15921+ unsigned long one_bits, high_bits;
15922 };
15923
15924 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
15925diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
15926index 5769349..a3d3e2a 100644
15927--- a/arch/x86/include/asm/x86_init.h
15928+++ b/arch/x86/include/asm/x86_init.h
15929@@ -141,7 +141,7 @@ struct x86_init_ops {
15930 struct x86_init_timers timers;
15931 struct x86_init_iommu iommu;
15932 struct x86_init_pci pci;
15933-};
15934+} __no_const;
15935
15936 /**
15937 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
15938@@ -152,7 +152,7 @@ struct x86_cpuinit_ops {
15939 void (*setup_percpu_clockev)(void);
15940 void (*early_percpu_clock_init)(void);
15941 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
15942-};
15943+} __no_const;
15944
15945 /**
15946 * struct x86_platform_ops - platform specific runtime functions
15947@@ -178,7 +178,7 @@ struct x86_platform_ops {
15948 void (*save_sched_clock_state)(void);
15949 void (*restore_sched_clock_state)(void);
15950 void (*apic_post_init)(void);
15951-};
15952+} __no_const;
15953
15954 struct pci_dev;
15955
15956@@ -187,14 +187,14 @@ struct x86_msi_ops {
15957 void (*teardown_msi_irq)(unsigned int irq);
15958 void (*teardown_msi_irqs)(struct pci_dev *dev);
15959 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
15960-};
15961+} __no_const;
15962
15963 struct x86_io_apic_ops {
15964 void (*init) (void);
15965 unsigned int (*read) (unsigned int apic, unsigned int reg);
15966 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
15967 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
15968-};
15969+} __no_const;
15970
15971 extern struct x86_init_ops x86_init;
15972 extern struct x86_cpuinit_ops x86_cpuinit;
15973diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
15974index 0415cda..b43d877 100644
15975--- a/arch/x86/include/asm/xsave.h
15976+++ b/arch/x86/include/asm/xsave.h
15977@@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
15978 return -EFAULT;
15979
15980 __asm__ __volatile__(ASM_STAC "\n"
15981- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
15982+ "1:"
15983+ __copyuser_seg
15984+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
15985 "2: " ASM_CLAC "\n"
15986 ".section .fixup,\"ax\"\n"
15987 "3: movl $-1,%[err]\n"
15988@@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
15989 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
15990 {
15991 int err;
15992- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
15993+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
15994 u32 lmask = mask;
15995 u32 hmask = mask >> 32;
15996
15997 __asm__ __volatile__(ASM_STAC "\n"
15998- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
15999+ "1:"
16000+ __copyuser_seg
16001+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16002 "2: " ASM_CLAC "\n"
16003 ".section .fixup,\"ax\"\n"
16004 "3: movl $-1,%[err]\n"
16005diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
16006index bbae024..e1528f9 100644
16007--- a/arch/x86/include/uapi/asm/e820.h
16008+++ b/arch/x86/include/uapi/asm/e820.h
16009@@ -63,7 +63,7 @@ struct e820map {
16010 #define ISA_START_ADDRESS 0xa0000
16011 #define ISA_END_ADDRESS 0x100000
16012
16013-#define BIOS_BEGIN 0x000a0000
16014+#define BIOS_BEGIN 0x000c0000
16015 #define BIOS_END 0x00100000
16016
16017 #define BIOS_ROM_BASE 0xffe00000
16018diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
16019index 34e923a..0c6bb6e 100644
16020--- a/arch/x86/kernel/Makefile
16021+++ b/arch/x86/kernel/Makefile
16022@@ -22,7 +22,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
16023 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
16024 obj-$(CONFIG_IRQ_WORK) += irq_work.o
16025 obj-y += probe_roms.o
16026-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
16027+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
16028 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
16029 obj-y += syscall_$(BITS).o
16030 obj-$(CONFIG_X86_64) += vsyscall_64.o
16031diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
16032index d5e0d71..6533e08 100644
16033--- a/arch/x86/kernel/acpi/sleep.c
16034+++ b/arch/x86/kernel/acpi/sleep.c
16035@@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
16036 #else /* CONFIG_64BIT */
16037 #ifdef CONFIG_SMP
16038 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
16039+
16040+ pax_open_kernel();
16041 early_gdt_descr.address =
16042 (unsigned long)get_cpu_gdt_table(smp_processor_id());
16043+ pax_close_kernel();
16044+
16045 initial_gs = per_cpu_offset(smp_processor_id());
16046 #endif
16047 initial_code = (unsigned long)wakeup_long64;
16048diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
16049index 13ab720..95d5442 100644
16050--- a/arch/x86/kernel/acpi/wakeup_32.S
16051+++ b/arch/x86/kernel/acpi/wakeup_32.S
16052@@ -30,13 +30,11 @@ wakeup_pmode_return:
16053 # and restore the stack ... but you need gdt for this to work
16054 movl saved_context_esp, %esp
16055
16056- movl %cs:saved_magic, %eax
16057- cmpl $0x12345678, %eax
16058+ cmpl $0x12345678, saved_magic
16059 jne bogus_magic
16060
16061 # jump to place where we left off
16062- movl saved_eip, %eax
16063- jmp *%eax
16064+ jmp *(saved_eip)
16065
16066 bogus_magic:
16067 jmp bogus_magic
16068diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
16069index ef5ccca..bd83949 100644
16070--- a/arch/x86/kernel/alternative.c
16071+++ b/arch/x86/kernel/alternative.c
16072@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
16073 */
16074 for (a = start; a < end; a++) {
16075 instr = (u8 *)&a->instr_offset + a->instr_offset;
16076+
16077+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16078+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16079+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
16080+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16081+#endif
16082+
16083 replacement = (u8 *)&a->repl_offset + a->repl_offset;
16084 BUG_ON(a->replacementlen > a->instrlen);
16085 BUG_ON(a->instrlen > sizeof(insnbuf));
16086@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
16087 for (poff = start; poff < end; poff++) {
16088 u8 *ptr = (u8 *)poff + *poff;
16089
16090+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16091+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16092+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16093+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16094+#endif
16095+
16096 if (!*poff || ptr < text || ptr >= text_end)
16097 continue;
16098 /* turn DS segment override prefix into lock prefix */
16099- if (*ptr == 0x3e)
16100+ if (*ktla_ktva(ptr) == 0x3e)
16101 text_poke(ptr, ((unsigned char []){0xf0}), 1);
16102 }
16103 mutex_unlock(&text_mutex);
16104@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
16105 for (poff = start; poff < end; poff++) {
16106 u8 *ptr = (u8 *)poff + *poff;
16107
16108+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16109+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16110+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16111+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16112+#endif
16113+
16114 if (!*poff || ptr < text || ptr >= text_end)
16115 continue;
16116 /* turn lock prefix into DS segment override prefix */
16117- if (*ptr == 0xf0)
16118+ if (*ktla_ktva(ptr) == 0xf0)
16119 text_poke(ptr, ((unsigned char []){0x3E}), 1);
16120 }
16121 mutex_unlock(&text_mutex);
16122@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
16123
16124 BUG_ON(p->len > MAX_PATCH_LEN);
16125 /* prep the buffer with the original instructions */
16126- memcpy(insnbuf, p->instr, p->len);
16127+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
16128 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
16129 (unsigned long)p->instr, p->len);
16130
16131@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
16132 if (!uniproc_patched || num_possible_cpus() == 1)
16133 free_init_pages("SMP alternatives",
16134 (unsigned long)__smp_locks,
16135- (unsigned long)__smp_locks_end);
16136+ PAGE_ALIGN((unsigned long)__smp_locks_end));
16137 #endif
16138
16139 apply_paravirt(__parainstructions, __parainstructions_end);
16140@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
16141 * instructions. And on the local CPU you need to be protected again NMI or MCE
16142 * handlers seeing an inconsistent instruction while you patch.
16143 */
16144-void *__init_or_module text_poke_early(void *addr, const void *opcode,
16145+void *__kprobes text_poke_early(void *addr, const void *opcode,
16146 size_t len)
16147 {
16148 unsigned long flags;
16149 local_irq_save(flags);
16150- memcpy(addr, opcode, len);
16151+
16152+ pax_open_kernel();
16153+ memcpy(ktla_ktva(addr), opcode, len);
16154 sync_core();
16155+ pax_close_kernel();
16156+
16157 local_irq_restore(flags);
16158 /* Could also do a CLFLUSH here to speed up CPU recovery; but
16159 that causes hangs on some VIA CPUs. */
16160@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
16161 */
16162 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
16163 {
16164- unsigned long flags;
16165- char *vaddr;
16166+ unsigned char *vaddr = ktla_ktva(addr);
16167 struct page *pages[2];
16168- int i;
16169+ size_t i;
16170
16171 if (!core_kernel_text((unsigned long)addr)) {
16172- pages[0] = vmalloc_to_page(addr);
16173- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
16174+ pages[0] = vmalloc_to_page(vaddr);
16175+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
16176 } else {
16177- pages[0] = virt_to_page(addr);
16178+ pages[0] = virt_to_page(vaddr);
16179 WARN_ON(!PageReserved(pages[0]));
16180- pages[1] = virt_to_page(addr + PAGE_SIZE);
16181+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
16182 }
16183 BUG_ON(!pages[0]);
16184- local_irq_save(flags);
16185- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
16186- if (pages[1])
16187- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
16188- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
16189- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
16190- clear_fixmap(FIX_TEXT_POKE0);
16191- if (pages[1])
16192- clear_fixmap(FIX_TEXT_POKE1);
16193- local_flush_tlb();
16194- sync_core();
16195- /* Could also do a CLFLUSH here to speed up CPU recovery; but
16196- that causes hangs on some VIA CPUs. */
16197+ text_poke_early(addr, opcode, len);
16198 for (i = 0; i < len; i++)
16199- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
16200- local_irq_restore(flags);
16201+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
16202 return addr;
16203 }
16204
16205diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
16206index b994cc8..812b537 100644
16207--- a/arch/x86/kernel/apic/apic.c
16208+++ b/arch/x86/kernel/apic/apic.c
16209@@ -131,7 +131,7 @@ static int __init parse_lapic(char *arg)
16210 {
16211 if (config_enabled(CONFIG_X86_32) && !arg)
16212 force_enable_local_apic = 1;
16213- else if (!strncmp(arg, "notscdeadline", 13))
16214+ else if (arg && !strncmp(arg, "notscdeadline", 13))
16215 setup_clear_cpu_cap(X86_FEATURE_TSC_DEADLINE_TIMER);
16216 return 0;
16217 }
16218@@ -189,7 +189,7 @@ int first_system_vector = 0xfe;
16219 /*
16220 * Debug level, exported for io_apic.c
16221 */
16222-unsigned int apic_verbosity;
16223+int apic_verbosity;
16224
16225 int pic_mode;
16226
16227@@ -1956,7 +1956,7 @@ void smp_error_interrupt(struct pt_regs *regs)
16228 apic_write(APIC_ESR, 0);
16229 v1 = apic_read(APIC_ESR);
16230 ack_APIC_irq();
16231- atomic_inc(&irq_err_count);
16232+ atomic_inc_unchecked(&irq_err_count);
16233
16234 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
16235 smp_processor_id(), v0 , v1);
16236diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
16237index 00c77cf..2dc6a2d 100644
16238--- a/arch/x86/kernel/apic/apic_flat_64.c
16239+++ b/arch/x86/kernel/apic/apic_flat_64.c
16240@@ -157,7 +157,7 @@ static int flat_probe(void)
16241 return 1;
16242 }
16243
16244-static struct apic apic_flat = {
16245+static struct apic apic_flat __read_only = {
16246 .name = "flat",
16247 .probe = flat_probe,
16248 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
16249@@ -271,7 +271,7 @@ static int physflat_probe(void)
16250 return 0;
16251 }
16252
16253-static struct apic apic_physflat = {
16254+static struct apic apic_physflat __read_only = {
16255
16256 .name = "physical flat",
16257 .probe = physflat_probe,
16258diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
16259index d50e364..543bee3 100644
16260--- a/arch/x86/kernel/apic/bigsmp_32.c
16261+++ b/arch/x86/kernel/apic/bigsmp_32.c
16262@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
16263 return dmi_bigsmp;
16264 }
16265
16266-static struct apic apic_bigsmp = {
16267+static struct apic apic_bigsmp __read_only = {
16268
16269 .name = "bigsmp",
16270 .probe = probe_bigsmp,
16271diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
16272index 0874799..24a836e 100644
16273--- a/arch/x86/kernel/apic/es7000_32.c
16274+++ b/arch/x86/kernel/apic/es7000_32.c
16275@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
16276 return ret && es7000_apic_is_cluster();
16277 }
16278
16279-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
16280-static struct apic __refdata apic_es7000_cluster = {
16281+static struct apic apic_es7000_cluster __read_only = {
16282
16283 .name = "es7000",
16284 .probe = probe_es7000,
16285@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
16286 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
16287 };
16288
16289-static struct apic __refdata apic_es7000 = {
16290+static struct apic __refdata apic_es7000 __read_only = {
16291
16292 .name = "es7000",
16293 .probe = probe_es7000,
16294diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
16295index b739d39..6e4f1db 100644
16296--- a/arch/x86/kernel/apic/io_apic.c
16297+++ b/arch/x86/kernel/apic/io_apic.c
16298@@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
16299 }
16300 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
16301
16302-void lock_vector_lock(void)
16303+void lock_vector_lock(void) __acquires(vector_lock)
16304 {
16305 /* Used to the online set of cpus does not change
16306 * during assign_irq_vector.
16307@@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
16308 raw_spin_lock(&vector_lock);
16309 }
16310
16311-void unlock_vector_lock(void)
16312+void unlock_vector_lock(void) __releases(vector_lock)
16313 {
16314 raw_spin_unlock(&vector_lock);
16315 }
16316@@ -2399,7 +2399,7 @@ static void ack_apic_edge(struct irq_data *data)
16317 ack_APIC_irq();
16318 }
16319
16320-atomic_t irq_mis_count;
16321+atomic_unchecked_t irq_mis_count;
16322
16323 #ifdef CONFIG_GENERIC_PENDING_IRQ
16324 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
16325@@ -2540,7 +2540,7 @@ static void ack_apic_level(struct irq_data *data)
16326 * at the cpu.
16327 */
16328 if (!(v & (1 << (i & 0x1f)))) {
16329- atomic_inc(&irq_mis_count);
16330+ atomic_inc_unchecked(&irq_mis_count);
16331
16332 eoi_ioapic_irq(irq, cfg);
16333 }
16334diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
16335index d661ee9..791fd33 100644
16336--- a/arch/x86/kernel/apic/numaq_32.c
16337+++ b/arch/x86/kernel/apic/numaq_32.c
16338@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
16339 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
16340 }
16341
16342-/* Use __refdata to keep false positive warning calm. */
16343-static struct apic __refdata apic_numaq = {
16344+static struct apic apic_numaq __read_only = {
16345
16346 .name = "NUMAQ",
16347 .probe = probe_numaq,
16348diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
16349index eb35ef9..f184a21 100644
16350--- a/arch/x86/kernel/apic/probe_32.c
16351+++ b/arch/x86/kernel/apic/probe_32.c
16352@@ -72,7 +72,7 @@ static int probe_default(void)
16353 return 1;
16354 }
16355
16356-static struct apic apic_default = {
16357+static struct apic apic_default __read_only = {
16358
16359 .name = "default",
16360 .probe = probe_default,
16361diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
16362index 77c95c0..434f8a4 100644
16363--- a/arch/x86/kernel/apic/summit_32.c
16364+++ b/arch/x86/kernel/apic/summit_32.c
16365@@ -486,7 +486,7 @@ void setup_summit(void)
16366 }
16367 #endif
16368
16369-static struct apic apic_summit = {
16370+static struct apic apic_summit __read_only = {
16371
16372 .name = "summit",
16373 .probe = probe_summit,
16374diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
16375index c88baa4..757aee1 100644
16376--- a/arch/x86/kernel/apic/x2apic_cluster.c
16377+++ b/arch/x86/kernel/apic/x2apic_cluster.c
16378@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
16379 return notifier_from_errno(err);
16380 }
16381
16382-static struct notifier_block __refdata x2apic_cpu_notifier = {
16383+static struct notifier_block x2apic_cpu_notifier = {
16384 .notifier_call = update_clusterinfo,
16385 };
16386
16387@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
16388 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
16389 }
16390
16391-static struct apic apic_x2apic_cluster = {
16392+static struct apic apic_x2apic_cluster __read_only = {
16393
16394 .name = "cluster x2apic",
16395 .probe = x2apic_cluster_probe,
16396diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
16397index 562a76d..a003c0f 100644
16398--- a/arch/x86/kernel/apic/x2apic_phys.c
16399+++ b/arch/x86/kernel/apic/x2apic_phys.c
16400@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
16401 return apic == &apic_x2apic_phys;
16402 }
16403
16404-static struct apic apic_x2apic_phys = {
16405+static struct apic apic_x2apic_phys __read_only = {
16406
16407 .name = "physical x2apic",
16408 .probe = x2apic_phys_probe,
16409diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
16410index 8cfade9..b9d04fc 100644
16411--- a/arch/x86/kernel/apic/x2apic_uv_x.c
16412+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
16413@@ -333,7 +333,7 @@ static int uv_probe(void)
16414 return apic == &apic_x2apic_uv_x;
16415 }
16416
16417-static struct apic __refdata apic_x2apic_uv_x = {
16418+static struct apic apic_x2apic_uv_x __read_only = {
16419
16420 .name = "UV large system",
16421 .probe = uv_probe,
16422diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
16423index d65464e..1035d31 100644
16424--- a/arch/x86/kernel/apm_32.c
16425+++ b/arch/x86/kernel/apm_32.c
16426@@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
16427 * This is for buggy BIOS's that refer to (real mode) segment 0x40
16428 * even though they are called in protected mode.
16429 */
16430-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
16431+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
16432 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
16433
16434 static const char driver_version[] = "1.16ac"; /* no spaces */
16435@@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
16436 BUG_ON(cpu != 0);
16437 gdt = get_cpu_gdt_table(cpu);
16438 save_desc_40 = gdt[0x40 / 8];
16439+
16440+ pax_open_kernel();
16441 gdt[0x40 / 8] = bad_bios_desc;
16442+ pax_close_kernel();
16443
16444 apm_irq_save(flags);
16445 APM_DO_SAVE_SEGS;
16446@@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
16447 &call->esi);
16448 APM_DO_RESTORE_SEGS;
16449 apm_irq_restore(flags);
16450+
16451+ pax_open_kernel();
16452 gdt[0x40 / 8] = save_desc_40;
16453+ pax_close_kernel();
16454+
16455 put_cpu();
16456
16457 return call->eax & 0xff;
16458@@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
16459 BUG_ON(cpu != 0);
16460 gdt = get_cpu_gdt_table(cpu);
16461 save_desc_40 = gdt[0x40 / 8];
16462+
16463+ pax_open_kernel();
16464 gdt[0x40 / 8] = bad_bios_desc;
16465+ pax_close_kernel();
16466
16467 apm_irq_save(flags);
16468 APM_DO_SAVE_SEGS;
16469@@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
16470 &call->eax);
16471 APM_DO_RESTORE_SEGS;
16472 apm_irq_restore(flags);
16473+
16474+ pax_open_kernel();
16475 gdt[0x40 / 8] = save_desc_40;
16476+ pax_close_kernel();
16477+
16478 put_cpu();
16479 return error;
16480 }
16481@@ -2345,12 +2359,15 @@ static int __init apm_init(void)
16482 * code to that CPU.
16483 */
16484 gdt = get_cpu_gdt_table(0);
16485+
16486+ pax_open_kernel();
16487 set_desc_base(&gdt[APM_CS >> 3],
16488 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
16489 set_desc_base(&gdt[APM_CS_16 >> 3],
16490 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
16491 set_desc_base(&gdt[APM_DS >> 3],
16492 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
16493+ pax_close_kernel();
16494
16495 proc_create("apm", 0, NULL, &apm_file_ops);
16496
16497diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
16498index 2861082..6d4718e 100644
16499--- a/arch/x86/kernel/asm-offsets.c
16500+++ b/arch/x86/kernel/asm-offsets.c
16501@@ -33,6 +33,8 @@ void common(void) {
16502 OFFSET(TI_status, thread_info, status);
16503 OFFSET(TI_addr_limit, thread_info, addr_limit);
16504 OFFSET(TI_preempt_count, thread_info, preempt_count);
16505+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
16506+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
16507
16508 BLANK();
16509 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
16510@@ -53,8 +55,26 @@ void common(void) {
16511 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
16512 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
16513 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
16514+
16515+#ifdef CONFIG_PAX_KERNEXEC
16516+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
16517 #endif
16518
16519+#ifdef CONFIG_PAX_MEMORY_UDEREF
16520+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
16521+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
16522+#ifdef CONFIG_X86_64
16523+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
16524+#endif
16525+#endif
16526+
16527+#endif
16528+
16529+ BLANK();
16530+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
16531+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
16532+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
16533+
16534 #ifdef CONFIG_XEN
16535 BLANK();
16536 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
16537diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
16538index 1b4754f..fbb4227 100644
16539--- a/arch/x86/kernel/asm-offsets_64.c
16540+++ b/arch/x86/kernel/asm-offsets_64.c
16541@@ -76,6 +76,7 @@ int main(void)
16542 BLANK();
16543 #undef ENTRY
16544
16545+ DEFINE(TSS_size, sizeof(struct tss_struct));
16546 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
16547 BLANK();
16548
16549diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
16550index a0e067d..9c7db16 100644
16551--- a/arch/x86/kernel/cpu/Makefile
16552+++ b/arch/x86/kernel/cpu/Makefile
16553@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
16554 CFLAGS_REMOVE_perf_event.o = -pg
16555 endif
16556
16557-# Make sure load_percpu_segment has no stackprotector
16558-nostackp := $(call cc-option, -fno-stack-protector)
16559-CFLAGS_common.o := $(nostackp)
16560-
16561 obj-y := intel_cacheinfo.o scattered.o topology.o
16562 obj-y += proc.o capflags.o powerflags.o common.o
16563 obj-y += vmware.o hypervisor.o mshyperv.o
16564diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
16565index 15239ff..e23e04e 100644
16566--- a/arch/x86/kernel/cpu/amd.c
16567+++ b/arch/x86/kernel/cpu/amd.c
16568@@ -733,7 +733,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
16569 unsigned int size)
16570 {
16571 /* AMD errata T13 (order #21922) */
16572- if ((c->x86 == 6)) {
16573+ if (c->x86 == 6) {
16574 /* Duron Rev A0 */
16575 if (c->x86_model == 3 && c->x86_mask == 0)
16576 size = 64;
16577diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
16578index 9c3ab43..51e6366 100644
16579--- a/arch/x86/kernel/cpu/common.c
16580+++ b/arch/x86/kernel/cpu/common.c
16581@@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
16582
16583 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
16584
16585-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
16586-#ifdef CONFIG_X86_64
16587- /*
16588- * We need valid kernel segments for data and code in long mode too
16589- * IRET will check the segment types kkeil 2000/10/28
16590- * Also sysret mandates a special GDT layout
16591- *
16592- * TLS descriptors are currently at a different place compared to i386.
16593- * Hopefully nobody expects them at a fixed place (Wine?)
16594- */
16595- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
16596- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
16597- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
16598- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
16599- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
16600- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
16601-#else
16602- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
16603- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
16604- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
16605- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
16606- /*
16607- * Segments used for calling PnP BIOS have byte granularity.
16608- * They code segments and data segments have fixed 64k limits,
16609- * the transfer segment sizes are set at run time.
16610- */
16611- /* 32-bit code */
16612- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
16613- /* 16-bit code */
16614- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
16615- /* 16-bit data */
16616- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
16617- /* 16-bit data */
16618- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
16619- /* 16-bit data */
16620- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
16621- /*
16622- * The APM segments have byte granularity and their bases
16623- * are set at run time. All have 64k limits.
16624- */
16625- /* 32-bit code */
16626- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
16627- /* 16-bit code */
16628- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
16629- /* data */
16630- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
16631-
16632- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
16633- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
16634- GDT_STACK_CANARY_INIT
16635-#endif
16636-} };
16637-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
16638-
16639 static int __init x86_xsave_setup(char *s)
16640 {
16641 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
16642@@ -389,7 +335,7 @@ void switch_to_new_gdt(int cpu)
16643 {
16644 struct desc_ptr gdt_descr;
16645
16646- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
16647+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
16648 gdt_descr.size = GDT_SIZE - 1;
16649 load_gdt(&gdt_descr);
16650 /* Reload the per-cpu base */
16651@@ -885,6 +831,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
16652 /* Filter out anything that depends on CPUID levels we don't have */
16653 filter_cpuid_features(c, true);
16654
16655+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
16656+ setup_clear_cpu_cap(X86_FEATURE_SEP);
16657+#endif
16658+
16659 /* If the model name is still unset, do table lookup. */
16660 if (!c->x86_model_id[0]) {
16661 const char *p;
16662@@ -1068,10 +1018,12 @@ static __init int setup_disablecpuid(char *arg)
16663 }
16664 __setup("clearcpuid=", setup_disablecpuid);
16665
16666+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
16667+EXPORT_PER_CPU_SYMBOL(current_tinfo);
16668+
16669 #ifdef CONFIG_X86_64
16670 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
16671-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
16672- (unsigned long) nmi_idt_table };
16673+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
16674
16675 DEFINE_PER_CPU_FIRST(union irq_stack_union,
16676 irq_stack_union) __aligned(PAGE_SIZE);
16677@@ -1085,7 +1037,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
16678 EXPORT_PER_CPU_SYMBOL(current_task);
16679
16680 DEFINE_PER_CPU(unsigned long, kernel_stack) =
16681- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
16682+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
16683 EXPORT_PER_CPU_SYMBOL(kernel_stack);
16684
16685 DEFINE_PER_CPU(char *, irq_stack_ptr) =
16686@@ -1224,7 +1176,7 @@ void __cpuinit cpu_init(void)
16687 int i;
16688
16689 cpu = stack_smp_processor_id();
16690- t = &per_cpu(init_tss, cpu);
16691+ t = init_tss + cpu;
16692 oist = &per_cpu(orig_ist, cpu);
16693
16694 #ifdef CONFIG_NUMA
16695@@ -1250,7 +1202,7 @@ void __cpuinit cpu_init(void)
16696 switch_to_new_gdt(cpu);
16697 loadsegment(fs, 0);
16698
16699- load_idt((const struct desc_ptr *)&idt_descr);
16700+ load_idt(&idt_descr);
16701
16702 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
16703 syscall_init();
16704@@ -1259,7 +1211,6 @@ void __cpuinit cpu_init(void)
16705 wrmsrl(MSR_KERNEL_GS_BASE, 0);
16706 barrier();
16707
16708- x86_configure_nx();
16709 enable_x2apic();
16710
16711 /*
16712@@ -1311,7 +1262,7 @@ void __cpuinit cpu_init(void)
16713 {
16714 int cpu = smp_processor_id();
16715 struct task_struct *curr = current;
16716- struct tss_struct *t = &per_cpu(init_tss, cpu);
16717+ struct tss_struct *t = init_tss + cpu;
16718 struct thread_struct *thread = &curr->thread;
16719
16720 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
16721diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
16722index fcaabd0..7b55a26 100644
16723--- a/arch/x86/kernel/cpu/intel.c
16724+++ b/arch/x86/kernel/cpu/intel.c
16725@@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
16726 * Update the IDT descriptor and reload the IDT so that
16727 * it uses the read-only mapped virtual address.
16728 */
16729- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
16730+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
16731 load_idt(&idt_descr);
16732 }
16733 #endif
16734diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
16735index 84c1309..39b7224 100644
16736--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
16737+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
16738@@ -1017,6 +1017,22 @@ static struct attribute *default_attrs[] = {
16739 };
16740
16741 #ifdef CONFIG_AMD_NB
16742+static struct attribute *default_attrs_amd_nb[] = {
16743+ &type.attr,
16744+ &level.attr,
16745+ &coherency_line_size.attr,
16746+ &physical_line_partition.attr,
16747+ &ways_of_associativity.attr,
16748+ &number_of_sets.attr,
16749+ &size.attr,
16750+ &shared_cpu_map.attr,
16751+ &shared_cpu_list.attr,
16752+ NULL,
16753+ NULL,
16754+ NULL,
16755+ NULL
16756+};
16757+
16758 static struct attribute ** __cpuinit amd_l3_attrs(void)
16759 {
16760 static struct attribute **attrs;
16761@@ -1027,18 +1043,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
16762
16763 n = ARRAY_SIZE(default_attrs);
16764
16765- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
16766- n += 2;
16767-
16768- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
16769- n += 1;
16770-
16771- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
16772- if (attrs == NULL)
16773- return attrs = default_attrs;
16774-
16775- for (n = 0; default_attrs[n]; n++)
16776- attrs[n] = default_attrs[n];
16777+ attrs = default_attrs_amd_nb;
16778
16779 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
16780 attrs[n++] = &cache_disable_0.attr;
16781@@ -1089,6 +1094,13 @@ static struct kobj_type ktype_cache = {
16782 .default_attrs = default_attrs,
16783 };
16784
16785+#ifdef CONFIG_AMD_NB
16786+static struct kobj_type ktype_cache_amd_nb = {
16787+ .sysfs_ops = &sysfs_ops,
16788+ .default_attrs = default_attrs_amd_nb,
16789+};
16790+#endif
16791+
16792 static struct kobj_type ktype_percpu_entry = {
16793 .sysfs_ops = &sysfs_ops,
16794 };
16795@@ -1154,20 +1166,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
16796 return retval;
16797 }
16798
16799+#ifdef CONFIG_AMD_NB
16800+ amd_l3_attrs();
16801+#endif
16802+
16803 for (i = 0; i < num_cache_leaves; i++) {
16804+ struct kobj_type *ktype;
16805+
16806 this_object = INDEX_KOBJECT_PTR(cpu, i);
16807 this_object->cpu = cpu;
16808 this_object->index = i;
16809
16810 this_leaf = CPUID4_INFO_IDX(cpu, i);
16811
16812- ktype_cache.default_attrs = default_attrs;
16813+ ktype = &ktype_cache;
16814 #ifdef CONFIG_AMD_NB
16815 if (this_leaf->base.nb)
16816- ktype_cache.default_attrs = amd_l3_attrs();
16817+ ktype = &ktype_cache_amd_nb;
16818 #endif
16819 retval = kobject_init_and_add(&(this_object->kobj),
16820- &ktype_cache,
16821+ ktype,
16822 per_cpu(ici_cache_kobject, cpu),
16823 "index%1lu", i);
16824 if (unlikely(retval)) {
16825@@ -1222,7 +1240,7 @@ static int __cpuinit cacheinfo_cpu_callback(struct notifier_block *nfb,
16826 return NOTIFY_OK;
16827 }
16828
16829-static struct notifier_block __cpuinitdata cacheinfo_cpu_notifier = {
16830+static struct notifier_block cacheinfo_cpu_notifier = {
16831 .notifier_call = cacheinfo_cpu_callback,
16832 };
16833
16834diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
16835index 80dbda8..b45ebad 100644
16836--- a/arch/x86/kernel/cpu/mcheck/mce.c
16837+++ b/arch/x86/kernel/cpu/mcheck/mce.c
16838@@ -45,6 +45,7 @@
16839 #include <asm/processor.h>
16840 #include <asm/mce.h>
16841 #include <asm/msr.h>
16842+#include <asm/local.h>
16843
16844 #include "mce-internal.h"
16845
16846@@ -246,7 +247,7 @@ static void print_mce(struct mce *m)
16847 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
16848 m->cs, m->ip);
16849
16850- if (m->cs == __KERNEL_CS)
16851+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
16852 print_symbol("{%s}", m->ip);
16853 pr_cont("\n");
16854 }
16855@@ -279,10 +280,10 @@ static void print_mce(struct mce *m)
16856
16857 #define PANIC_TIMEOUT 5 /* 5 seconds */
16858
16859-static atomic_t mce_paniced;
16860+static atomic_unchecked_t mce_paniced;
16861
16862 static int fake_panic;
16863-static atomic_t mce_fake_paniced;
16864+static atomic_unchecked_t mce_fake_paniced;
16865
16866 /* Panic in progress. Enable interrupts and wait for final IPI */
16867 static void wait_for_panic(void)
16868@@ -306,7 +307,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
16869 /*
16870 * Make sure only one CPU runs in machine check panic
16871 */
16872- if (atomic_inc_return(&mce_paniced) > 1)
16873+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
16874 wait_for_panic();
16875 barrier();
16876
16877@@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
16878 console_verbose();
16879 } else {
16880 /* Don't log too much for fake panic */
16881- if (atomic_inc_return(&mce_fake_paniced) > 1)
16882+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
16883 return;
16884 }
16885 /* First print corrected ones that are still unlogged */
16886@@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
16887 * might have been modified by someone else.
16888 */
16889 rmb();
16890- if (atomic_read(&mce_paniced))
16891+ if (atomic_read_unchecked(&mce_paniced))
16892 wait_for_panic();
16893 if (!mca_cfg.monarch_timeout)
16894 goto out;
16895@@ -1662,7 +1663,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
16896 }
16897
16898 /* Call the installed machine check handler for this CPU setup. */
16899-void (*machine_check_vector)(struct pt_regs *, long error_code) =
16900+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
16901 unexpected_machine_check;
16902
16903 /*
16904@@ -1685,7 +1686,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
16905 return;
16906 }
16907
16908+ pax_open_kernel();
16909 machine_check_vector = do_machine_check;
16910+ pax_close_kernel();
16911
16912 __mcheck_cpu_init_generic();
16913 __mcheck_cpu_init_vendor(c);
16914@@ -1699,7 +1702,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
16915 */
16916
16917 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
16918-static int mce_chrdev_open_count; /* #times opened */
16919+static local_t mce_chrdev_open_count; /* #times opened */
16920 static int mce_chrdev_open_exclu; /* already open exclusive? */
16921
16922 static int mce_chrdev_open(struct inode *inode, struct file *file)
16923@@ -1707,7 +1710,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
16924 spin_lock(&mce_chrdev_state_lock);
16925
16926 if (mce_chrdev_open_exclu ||
16927- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
16928+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
16929 spin_unlock(&mce_chrdev_state_lock);
16930
16931 return -EBUSY;
16932@@ -1715,7 +1718,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
16933
16934 if (file->f_flags & O_EXCL)
16935 mce_chrdev_open_exclu = 1;
16936- mce_chrdev_open_count++;
16937+ local_inc(&mce_chrdev_open_count);
16938
16939 spin_unlock(&mce_chrdev_state_lock);
16940
16941@@ -1726,7 +1729,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
16942 {
16943 spin_lock(&mce_chrdev_state_lock);
16944
16945- mce_chrdev_open_count--;
16946+ local_dec(&mce_chrdev_open_count);
16947 mce_chrdev_open_exclu = 0;
16948
16949 spin_unlock(&mce_chrdev_state_lock);
16950@@ -2372,7 +2375,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
16951 return NOTIFY_OK;
16952 }
16953
16954-static struct notifier_block mce_cpu_notifier __cpuinitdata = {
16955+static struct notifier_block mce_cpu_notifier = {
16956 .notifier_call = mce_cpu_callback,
16957 };
16958
16959@@ -2450,7 +2453,7 @@ struct dentry *mce_get_debugfs_dir(void)
16960 static void mce_reset(void)
16961 {
16962 cpu_missing = 0;
16963- atomic_set(&mce_fake_paniced, 0);
16964+ atomic_set_unchecked(&mce_fake_paniced, 0);
16965 atomic_set(&mce_executing, 0);
16966 atomic_set(&mce_callin, 0);
16967 atomic_set(&global_nwo, 0);
16968diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
16969index 2d5454c..51987eb 100644
16970--- a/arch/x86/kernel/cpu/mcheck/p5.c
16971+++ b/arch/x86/kernel/cpu/mcheck/p5.c
16972@@ -11,6 +11,7 @@
16973 #include <asm/processor.h>
16974 #include <asm/mce.h>
16975 #include <asm/msr.h>
16976+#include <asm/pgtable.h>
16977
16978 /* By default disabled */
16979 int mce_p5_enabled __read_mostly;
16980@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
16981 if (!cpu_has(c, X86_FEATURE_MCE))
16982 return;
16983
16984+ pax_open_kernel();
16985 machine_check_vector = pentium_machine_check;
16986+ pax_close_kernel();
16987 /* Make sure the vector pointer is visible before we enable MCEs: */
16988 wmb();
16989
16990diff --git a/arch/x86/kernel/cpu/mcheck/therm_throt.c b/arch/x86/kernel/cpu/mcheck/therm_throt.c
16991index 47a1870..8c019a7 100644
16992--- a/arch/x86/kernel/cpu/mcheck/therm_throt.c
16993+++ b/arch/x86/kernel/cpu/mcheck/therm_throt.c
16994@@ -288,7 +288,7 @@ thermal_throttle_cpu_callback(struct notifier_block *nfb,
16995 return notifier_from_errno(err);
16996 }
16997
16998-static struct notifier_block thermal_throttle_cpu_notifier __cpuinitdata =
16999+static struct notifier_block thermal_throttle_cpu_notifier =
17000 {
17001 .notifier_call = thermal_throttle_cpu_callback,
17002 };
17003diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
17004index 2d7998f..17c9de1 100644
17005--- a/arch/x86/kernel/cpu/mcheck/winchip.c
17006+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
17007@@ -10,6 +10,7 @@
17008 #include <asm/processor.h>
17009 #include <asm/mce.h>
17010 #include <asm/msr.h>
17011+#include <asm/pgtable.h>
17012
17013 /* Machine check handler for WinChip C6: */
17014 static void winchip_machine_check(struct pt_regs *regs, long error_code)
17015@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
17016 {
17017 u32 lo, hi;
17018
17019+ pax_open_kernel();
17020 machine_check_vector = winchip_machine_check;
17021+ pax_close_kernel();
17022 /* Make sure the vector pointer is visible before we enable MCEs: */
17023 wmb();
17024
17025diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
17026index 726bf96..81f0526 100644
17027--- a/arch/x86/kernel/cpu/mtrr/main.c
17028+++ b/arch/x86/kernel/cpu/mtrr/main.c
17029@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
17030 u64 size_or_mask, size_and_mask;
17031 static bool mtrr_aps_delayed_init;
17032
17033-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
17034+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
17035
17036 const struct mtrr_ops *mtrr_if;
17037
17038diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
17039index df5e41f..816c719 100644
17040--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
17041+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
17042@@ -25,7 +25,7 @@ struct mtrr_ops {
17043 int (*validate_add_page)(unsigned long base, unsigned long size,
17044 unsigned int type);
17045 int (*have_wrcomb)(void);
17046-};
17047+} __do_const;
17048
17049 extern int generic_get_free_region(unsigned long base, unsigned long size,
17050 int replace_reg);
17051diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
17052index 6774c17..a691911 100644
17053--- a/arch/x86/kernel/cpu/perf_event.c
17054+++ b/arch/x86/kernel/cpu/perf_event.c
17055@@ -1880,7 +1880,7 @@ static unsigned long get_segment_base(unsigned int segment)
17056 if (idx > GDT_ENTRIES)
17057 return 0;
17058
17059- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
17060+ desc = get_cpu_gdt_table(smp_processor_id());
17061 }
17062
17063 return get_desc_base(desc + idx);
17064@@ -1970,7 +1970,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
17065 break;
17066
17067 perf_callchain_store(entry, frame.return_address);
17068- fp = frame.next_frame;
17069+ fp = (const void __force_user *)frame.next_frame;
17070 }
17071 }
17072
17073diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
17074index 4914e94..60b06e3 100644
17075--- a/arch/x86/kernel/cpu/perf_event_intel.c
17076+++ b/arch/x86/kernel/cpu/perf_event_intel.c
17077@@ -1958,10 +1958,10 @@ __init int intel_pmu_init(void)
17078 * v2 and above have a perf capabilities MSR
17079 */
17080 if (version > 1) {
17081- u64 capabilities;
17082+ u64 capabilities = x86_pmu.intel_cap.capabilities;
17083
17084- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
17085- x86_pmu.intel_cap.capabilities = capabilities;
17086+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
17087+ x86_pmu.intel_cap.capabilities = capabilities;
17088 }
17089
17090 intel_ds_init();
17091diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17092index b43200d..62cddfe 100644
17093--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17094+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17095@@ -2826,7 +2826,7 @@ static int
17096 return NOTIFY_OK;
17097 }
17098
17099-static struct notifier_block uncore_cpu_nb __cpuinitdata = {
17100+static struct notifier_block uncore_cpu_nb = {
17101 .notifier_call = uncore_cpu_notifier,
17102 /*
17103 * to migrate uncore events, our notifier should be executed
17104diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
17105index 60c7891..9e911d3 100644
17106--- a/arch/x86/kernel/cpuid.c
17107+++ b/arch/x86/kernel/cpuid.c
17108@@ -171,7 +171,7 @@ static int __cpuinit cpuid_class_cpu_callback(struct notifier_block *nfb,
17109 return notifier_from_errno(err);
17110 }
17111
17112-static struct notifier_block __refdata cpuid_class_cpu_notifier =
17113+static struct notifier_block cpuid_class_cpu_notifier =
17114 {
17115 .notifier_call = cpuid_class_cpu_callback,
17116 };
17117diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
17118index 74467fe..18793d5 100644
17119--- a/arch/x86/kernel/crash.c
17120+++ b/arch/x86/kernel/crash.c
17121@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
17122 {
17123 #ifdef CONFIG_X86_32
17124 struct pt_regs fixed_regs;
17125-#endif
17126
17127-#ifdef CONFIG_X86_32
17128- if (!user_mode_vm(regs)) {
17129+ if (!user_mode(regs)) {
17130 crash_fixup_ss_esp(&fixed_regs, regs);
17131 regs = &fixed_regs;
17132 }
17133diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
17134index 37250fe..bf2ec74 100644
17135--- a/arch/x86/kernel/doublefault_32.c
17136+++ b/arch/x86/kernel/doublefault_32.c
17137@@ -11,7 +11,7 @@
17138
17139 #define DOUBLEFAULT_STACKSIZE (1024)
17140 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
17141-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
17142+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
17143
17144 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
17145
17146@@ -21,7 +21,7 @@ static void doublefault_fn(void)
17147 unsigned long gdt, tss;
17148
17149 store_gdt(&gdt_desc);
17150- gdt = gdt_desc.address;
17151+ gdt = (unsigned long)gdt_desc.address;
17152
17153 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
17154
17155@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
17156 /* 0x2 bit is always set */
17157 .flags = X86_EFLAGS_SF | 0x2,
17158 .sp = STACK_START,
17159- .es = __USER_DS,
17160+ .es = __KERNEL_DS,
17161 .cs = __KERNEL_CS,
17162 .ss = __KERNEL_DS,
17163- .ds = __USER_DS,
17164+ .ds = __KERNEL_DS,
17165 .fs = __KERNEL_PERCPU,
17166
17167 .__cr3 = __pa_nodebug(swapper_pg_dir),
17168diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
17169index ae42418b..787c16b 100644
17170--- a/arch/x86/kernel/dumpstack.c
17171+++ b/arch/x86/kernel/dumpstack.c
17172@@ -2,6 +2,9 @@
17173 * Copyright (C) 1991, 1992 Linus Torvalds
17174 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
17175 */
17176+#ifdef CONFIG_GRKERNSEC_HIDESYM
17177+#define __INCLUDED_BY_HIDESYM 1
17178+#endif
17179 #include <linux/kallsyms.h>
17180 #include <linux/kprobes.h>
17181 #include <linux/uaccess.h>
17182@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
17183 static void
17184 print_ftrace_graph_addr(unsigned long addr, void *data,
17185 const struct stacktrace_ops *ops,
17186- struct thread_info *tinfo, int *graph)
17187+ struct task_struct *task, int *graph)
17188 {
17189- struct task_struct *task;
17190 unsigned long ret_addr;
17191 int index;
17192
17193 if (addr != (unsigned long)return_to_handler)
17194 return;
17195
17196- task = tinfo->task;
17197 index = task->curr_ret_stack;
17198
17199 if (!task->ret_stack || index < *graph)
17200@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17201 static inline void
17202 print_ftrace_graph_addr(unsigned long addr, void *data,
17203 const struct stacktrace_ops *ops,
17204- struct thread_info *tinfo, int *graph)
17205+ struct task_struct *task, int *graph)
17206 { }
17207 #endif
17208
17209@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17210 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
17211 */
17212
17213-static inline int valid_stack_ptr(struct thread_info *tinfo,
17214- void *p, unsigned int size, void *end)
17215+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
17216 {
17217- void *t = tinfo;
17218 if (end) {
17219 if (p < end && p >= (end-THREAD_SIZE))
17220 return 1;
17221@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
17222 }
17223
17224 unsigned long
17225-print_context_stack(struct thread_info *tinfo,
17226+print_context_stack(struct task_struct *task, void *stack_start,
17227 unsigned long *stack, unsigned long bp,
17228 const struct stacktrace_ops *ops, void *data,
17229 unsigned long *end, int *graph)
17230 {
17231 struct stack_frame *frame = (struct stack_frame *)bp;
17232
17233- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
17234+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
17235 unsigned long addr;
17236
17237 addr = *stack;
17238@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
17239 } else {
17240 ops->address(data, addr, 0);
17241 }
17242- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17243+ print_ftrace_graph_addr(addr, data, ops, task, graph);
17244 }
17245 stack++;
17246 }
17247@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
17248 EXPORT_SYMBOL_GPL(print_context_stack);
17249
17250 unsigned long
17251-print_context_stack_bp(struct thread_info *tinfo,
17252+print_context_stack_bp(struct task_struct *task, void *stack_start,
17253 unsigned long *stack, unsigned long bp,
17254 const struct stacktrace_ops *ops, void *data,
17255 unsigned long *end, int *graph)
17256@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17257 struct stack_frame *frame = (struct stack_frame *)bp;
17258 unsigned long *ret_addr = &frame->return_address;
17259
17260- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
17261+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
17262 unsigned long addr = *ret_addr;
17263
17264 if (!__kernel_text_address(addr))
17265@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17266 ops->address(data, addr, 1);
17267 frame = frame->next_frame;
17268 ret_addr = &frame->return_address;
17269- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17270+ print_ftrace_graph_addr(addr, data, ops, task, graph);
17271 }
17272
17273 return (unsigned long)frame;
17274@@ -189,7 +188,7 @@ void dump_stack(void)
17275
17276 bp = stack_frame(current, NULL);
17277 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
17278- current->pid, current->comm, print_tainted(),
17279+ task_pid_nr(current), current->comm, print_tainted(),
17280 init_utsname()->release,
17281 (int)strcspn(init_utsname()->version, " "),
17282 init_utsname()->version);
17283@@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
17284 }
17285 EXPORT_SYMBOL_GPL(oops_begin);
17286
17287+extern void gr_handle_kernel_exploit(void);
17288+
17289 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17290 {
17291 if (regs && kexec_should_crash(current))
17292@@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17293 panic("Fatal exception in interrupt");
17294 if (panic_on_oops)
17295 panic("Fatal exception");
17296- do_exit(signr);
17297+
17298+ gr_handle_kernel_exploit();
17299+
17300+ do_group_exit(signr);
17301 }
17302
17303 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17304@@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17305 print_modules();
17306 show_regs(regs);
17307 #ifdef CONFIG_X86_32
17308- if (user_mode_vm(regs)) {
17309+ if (user_mode(regs)) {
17310 sp = regs->sp;
17311 ss = regs->ss & 0xffff;
17312 } else {
17313@@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
17314 unsigned long flags = oops_begin();
17315 int sig = SIGSEGV;
17316
17317- if (!user_mode_vm(regs))
17318+ if (!user_mode(regs))
17319 report_bug(regs->ip, regs);
17320
17321 if (__die(str, regs, err))
17322diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
17323index 1038a41..db2c12b 100644
17324--- a/arch/x86/kernel/dumpstack_32.c
17325+++ b/arch/x86/kernel/dumpstack_32.c
17326@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17327 bp = stack_frame(task, regs);
17328
17329 for (;;) {
17330- struct thread_info *context;
17331+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
17332
17333- context = (struct thread_info *)
17334- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
17335- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
17336+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
17337
17338- stack = (unsigned long *)context->previous_esp;
17339- if (!stack)
17340+ if (stack_start == task_stack_page(task))
17341 break;
17342+ stack = *(unsigned long **)stack_start;
17343 if (ops->stack(data, "IRQ") < 0)
17344 break;
17345 touch_nmi_watchdog();
17346@@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
17347 {
17348 int i;
17349
17350- __show_regs(regs, !user_mode_vm(regs));
17351+ __show_regs(regs, !user_mode(regs));
17352
17353 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
17354 TASK_COMM_LEN, current->comm, task_pid_nr(current),
17355@@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
17356 * When in-kernel, we also print out the stack and code at the
17357 * time of the fault..
17358 */
17359- if (!user_mode_vm(regs)) {
17360+ if (!user_mode(regs)) {
17361 unsigned int code_prologue = code_bytes * 43 / 64;
17362 unsigned int code_len = code_bytes;
17363 unsigned char c;
17364 u8 *ip;
17365+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
17366
17367 pr_emerg("Stack:\n");
17368 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
17369
17370 pr_emerg("Code:");
17371
17372- ip = (u8 *)regs->ip - code_prologue;
17373+ ip = (u8 *)regs->ip - code_prologue + cs_base;
17374 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
17375 /* try starting at IP */
17376- ip = (u8 *)regs->ip;
17377+ ip = (u8 *)regs->ip + cs_base;
17378 code_len = code_len - code_prologue + 1;
17379 }
17380 for (i = 0; i < code_len; i++, ip++) {
17381@@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
17382 pr_cont(" Bad EIP value.");
17383 break;
17384 }
17385- if (ip == (u8 *)regs->ip)
17386+ if (ip == (u8 *)regs->ip + cs_base)
17387 pr_cont(" <%02x>", c);
17388 else
17389 pr_cont(" %02x", c);
17390@@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
17391 {
17392 unsigned short ud2;
17393
17394+ ip = ktla_ktva(ip);
17395 if (ip < PAGE_OFFSET)
17396 return 0;
17397 if (probe_kernel_address((unsigned short *)ip, ud2))
17398@@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
17399
17400 return ud2 == 0x0b0f;
17401 }
17402+
17403+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17404+void pax_check_alloca(unsigned long size)
17405+{
17406+ unsigned long sp = (unsigned long)&sp, stack_left;
17407+
17408+ /* all kernel stacks are of the same size */
17409+ stack_left = sp & (THREAD_SIZE - 1);
17410+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
17411+}
17412+EXPORT_SYMBOL(pax_check_alloca);
17413+#endif
17414diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
17415index b653675..51cc8c0 100644
17416--- a/arch/x86/kernel/dumpstack_64.c
17417+++ b/arch/x86/kernel/dumpstack_64.c
17418@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17419 unsigned long *irq_stack_end =
17420 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
17421 unsigned used = 0;
17422- struct thread_info *tinfo;
17423 int graph = 0;
17424 unsigned long dummy;
17425+ void *stack_start;
17426
17427 if (!task)
17428 task = current;
17429@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17430 * current stack address. If the stacks consist of nested
17431 * exceptions
17432 */
17433- tinfo = task_thread_info(task);
17434 for (;;) {
17435 char *id;
17436 unsigned long *estack_end;
17437+
17438 estack_end = in_exception_stack(cpu, (unsigned long)stack,
17439 &used, &id);
17440
17441@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17442 if (ops->stack(data, id) < 0)
17443 break;
17444
17445- bp = ops->walk_stack(tinfo, stack, bp, ops,
17446+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
17447 data, estack_end, &graph);
17448 ops->stack(data, "<EOE>");
17449 /*
17450@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17451 * second-to-last pointer (index -2 to end) in the
17452 * exception stack:
17453 */
17454+ if ((u16)estack_end[-1] != __KERNEL_DS)
17455+ goto out;
17456 stack = (unsigned long *) estack_end[-2];
17457 continue;
17458 }
17459@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17460 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
17461 if (ops->stack(data, "IRQ") < 0)
17462 break;
17463- bp = ops->walk_stack(tinfo, stack, bp,
17464+ bp = ops->walk_stack(task, irq_stack, stack, bp,
17465 ops, data, irq_stack_end, &graph);
17466 /*
17467 * We link to the next stack (which would be
17468@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17469 /*
17470 * This handles the process stack:
17471 */
17472- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
17473+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
17474+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
17475+out:
17476 put_cpu();
17477 }
17478 EXPORT_SYMBOL(dump_trace);
17479@@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
17480 {
17481 int i;
17482 unsigned long sp;
17483- const int cpu = smp_processor_id();
17484+ const int cpu = raw_smp_processor_id();
17485 struct task_struct *cur = current;
17486
17487 sp = regs->sp;
17488@@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
17489
17490 return ud2 == 0x0b0f;
17491 }
17492+
17493+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17494+void pax_check_alloca(unsigned long size)
17495+{
17496+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
17497+ unsigned cpu, used;
17498+ char *id;
17499+
17500+ /* check the process stack first */
17501+ stack_start = (unsigned long)task_stack_page(current);
17502+ stack_end = stack_start + THREAD_SIZE;
17503+ if (likely(stack_start <= sp && sp < stack_end)) {
17504+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
17505+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
17506+ return;
17507+ }
17508+
17509+ cpu = get_cpu();
17510+
17511+ /* check the irq stacks */
17512+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
17513+ stack_start = stack_end - IRQ_STACK_SIZE;
17514+ if (stack_start <= sp && sp < stack_end) {
17515+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
17516+ put_cpu();
17517+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
17518+ return;
17519+ }
17520+
17521+ /* check the exception stacks */
17522+ used = 0;
17523+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
17524+ stack_start = stack_end - EXCEPTION_STKSZ;
17525+ if (stack_end && stack_start <= sp && sp < stack_end) {
17526+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
17527+ put_cpu();
17528+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
17529+ return;
17530+ }
17531+
17532+ put_cpu();
17533+
17534+ /* unknown stack */
17535+ BUG();
17536+}
17537+EXPORT_SYMBOL(pax_check_alloca);
17538+#endif
17539diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
17540index 9b9f18b..9fcaa04 100644
17541--- a/arch/x86/kernel/early_printk.c
17542+++ b/arch/x86/kernel/early_printk.c
17543@@ -7,6 +7,7 @@
17544 #include <linux/pci_regs.h>
17545 #include <linux/pci_ids.h>
17546 #include <linux/errno.h>
17547+#include <linux/sched.h>
17548 #include <asm/io.h>
17549 #include <asm/processor.h>
17550 #include <asm/fcntl.h>
17551diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
17552index 6ed91d9..6cc365b 100644
17553--- a/arch/x86/kernel/entry_32.S
17554+++ b/arch/x86/kernel/entry_32.S
17555@@ -177,13 +177,153 @@
17556 /*CFI_REL_OFFSET gs, PT_GS*/
17557 .endm
17558 .macro SET_KERNEL_GS reg
17559+
17560+#ifdef CONFIG_CC_STACKPROTECTOR
17561 movl $(__KERNEL_STACK_CANARY), \reg
17562+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17563+ movl $(__USER_DS), \reg
17564+#else
17565+ xorl \reg, \reg
17566+#endif
17567+
17568 movl \reg, %gs
17569 .endm
17570
17571 #endif /* CONFIG_X86_32_LAZY_GS */
17572
17573-.macro SAVE_ALL
17574+.macro pax_enter_kernel
17575+#ifdef CONFIG_PAX_KERNEXEC
17576+ call pax_enter_kernel
17577+#endif
17578+.endm
17579+
17580+.macro pax_exit_kernel
17581+#ifdef CONFIG_PAX_KERNEXEC
17582+ call pax_exit_kernel
17583+#endif
17584+.endm
17585+
17586+#ifdef CONFIG_PAX_KERNEXEC
17587+ENTRY(pax_enter_kernel)
17588+#ifdef CONFIG_PARAVIRT
17589+ pushl %eax
17590+ pushl %ecx
17591+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
17592+ mov %eax, %esi
17593+#else
17594+ mov %cr0, %esi
17595+#endif
17596+ bts $16, %esi
17597+ jnc 1f
17598+ mov %cs, %esi
17599+ cmp $__KERNEL_CS, %esi
17600+ jz 3f
17601+ ljmp $__KERNEL_CS, $3f
17602+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
17603+2:
17604+#ifdef CONFIG_PARAVIRT
17605+ mov %esi, %eax
17606+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17607+#else
17608+ mov %esi, %cr0
17609+#endif
17610+3:
17611+#ifdef CONFIG_PARAVIRT
17612+ popl %ecx
17613+ popl %eax
17614+#endif
17615+ ret
17616+ENDPROC(pax_enter_kernel)
17617+
17618+ENTRY(pax_exit_kernel)
17619+#ifdef CONFIG_PARAVIRT
17620+ pushl %eax
17621+ pushl %ecx
17622+#endif
17623+ mov %cs, %esi
17624+ cmp $__KERNEXEC_KERNEL_CS, %esi
17625+ jnz 2f
17626+#ifdef CONFIG_PARAVIRT
17627+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
17628+ mov %eax, %esi
17629+#else
17630+ mov %cr0, %esi
17631+#endif
17632+ btr $16, %esi
17633+ ljmp $__KERNEL_CS, $1f
17634+1:
17635+#ifdef CONFIG_PARAVIRT
17636+ mov %esi, %eax
17637+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
17638+#else
17639+ mov %esi, %cr0
17640+#endif
17641+2:
17642+#ifdef CONFIG_PARAVIRT
17643+ popl %ecx
17644+ popl %eax
17645+#endif
17646+ ret
17647+ENDPROC(pax_exit_kernel)
17648+#endif
17649+
17650+.macro pax_erase_kstack
17651+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17652+ call pax_erase_kstack
17653+#endif
17654+.endm
17655+
17656+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17657+/*
17658+ * ebp: thread_info
17659+ */
17660+ENTRY(pax_erase_kstack)
17661+ pushl %edi
17662+ pushl %ecx
17663+ pushl %eax
17664+
17665+ mov TI_lowest_stack(%ebp), %edi
17666+ mov $-0xBEEF, %eax
17667+ std
17668+
17669+1: mov %edi, %ecx
17670+ and $THREAD_SIZE_asm - 1, %ecx
17671+ shr $2, %ecx
17672+ repne scasl
17673+ jecxz 2f
17674+
17675+ cmp $2*16, %ecx
17676+ jc 2f
17677+
17678+ mov $2*16, %ecx
17679+ repe scasl
17680+ jecxz 2f
17681+ jne 1b
17682+
17683+2: cld
17684+ mov %esp, %ecx
17685+ sub %edi, %ecx
17686+
17687+ cmp $THREAD_SIZE_asm, %ecx
17688+ jb 3f
17689+ ud2
17690+3:
17691+
17692+ shr $2, %ecx
17693+ rep stosl
17694+
17695+ mov TI_task_thread_sp0(%ebp), %edi
17696+ sub $128, %edi
17697+ mov %edi, TI_lowest_stack(%ebp)
17698+
17699+ popl %eax
17700+ popl %ecx
17701+ popl %edi
17702+ ret
17703+ENDPROC(pax_erase_kstack)
17704+#endif
17705+
17706+.macro __SAVE_ALL _DS
17707 cld
17708 PUSH_GS
17709 pushl_cfi %fs
17710@@ -206,7 +346,7 @@
17711 CFI_REL_OFFSET ecx, 0
17712 pushl_cfi %ebx
17713 CFI_REL_OFFSET ebx, 0
17714- movl $(__USER_DS), %edx
17715+ movl $\_DS, %edx
17716 movl %edx, %ds
17717 movl %edx, %es
17718 movl $(__KERNEL_PERCPU), %edx
17719@@ -214,6 +354,15 @@
17720 SET_KERNEL_GS %edx
17721 .endm
17722
17723+.macro SAVE_ALL
17724+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
17725+ __SAVE_ALL __KERNEL_DS
17726+ pax_enter_kernel
17727+#else
17728+ __SAVE_ALL __USER_DS
17729+#endif
17730+.endm
17731+
17732 .macro RESTORE_INT_REGS
17733 popl_cfi %ebx
17734 CFI_RESTORE ebx
17735@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
17736 popfl_cfi
17737 jmp syscall_exit
17738 CFI_ENDPROC
17739-END(ret_from_fork)
17740+ENDPROC(ret_from_fork)
17741
17742 ENTRY(ret_from_kernel_thread)
17743 CFI_STARTPROC
17744@@ -344,7 +493,15 @@ ret_from_intr:
17745 andl $SEGMENT_RPL_MASK, %eax
17746 #endif
17747 cmpl $USER_RPL, %eax
17748+
17749+#ifdef CONFIG_PAX_KERNEXEC
17750+ jae resume_userspace
17751+
17752+ pax_exit_kernel
17753+ jmp resume_kernel
17754+#else
17755 jb resume_kernel # not returning to v8086 or userspace
17756+#endif
17757
17758 ENTRY(resume_userspace)
17759 LOCKDEP_SYS_EXIT
17760@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
17761 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
17762 # int/exception return?
17763 jne work_pending
17764- jmp restore_all
17765-END(ret_from_exception)
17766+ jmp restore_all_pax
17767+ENDPROC(ret_from_exception)
17768
17769 #ifdef CONFIG_PREEMPT
17770 ENTRY(resume_kernel)
17771@@ -372,7 +529,7 @@ need_resched:
17772 jz restore_all
17773 call preempt_schedule_irq
17774 jmp need_resched
17775-END(resume_kernel)
17776+ENDPROC(resume_kernel)
17777 #endif
17778 CFI_ENDPROC
17779 /*
17780@@ -406,30 +563,45 @@ sysenter_past_esp:
17781 /*CFI_REL_OFFSET cs, 0*/
17782 /*
17783 * Push current_thread_info()->sysenter_return to the stack.
17784- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
17785- * pushed above; +8 corresponds to copy_thread's esp0 setting.
17786 */
17787- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
17788+ pushl_cfi $0
17789 CFI_REL_OFFSET eip, 0
17790
17791 pushl_cfi %eax
17792 SAVE_ALL
17793+ GET_THREAD_INFO(%ebp)
17794+ movl TI_sysenter_return(%ebp),%ebp
17795+ movl %ebp,PT_EIP(%esp)
17796 ENABLE_INTERRUPTS(CLBR_NONE)
17797
17798 /*
17799 * Load the potential sixth argument from user stack.
17800 * Careful about security.
17801 */
17802+ movl PT_OLDESP(%esp),%ebp
17803+
17804+#ifdef CONFIG_PAX_MEMORY_UDEREF
17805+ mov PT_OLDSS(%esp),%ds
17806+1: movl %ds:(%ebp),%ebp
17807+ push %ss
17808+ pop %ds
17809+#else
17810 cmpl $__PAGE_OFFSET-3,%ebp
17811 jae syscall_fault
17812 ASM_STAC
17813 1: movl (%ebp),%ebp
17814 ASM_CLAC
17815+#endif
17816+
17817 movl %ebp,PT_EBP(%esp)
17818 _ASM_EXTABLE(1b,syscall_fault)
17819
17820 GET_THREAD_INFO(%ebp)
17821
17822+#ifdef CONFIG_PAX_RANDKSTACK
17823+ pax_erase_kstack
17824+#endif
17825+
17826 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
17827 jnz sysenter_audit
17828 sysenter_do_call:
17829@@ -444,12 +616,24 @@ sysenter_do_call:
17830 testl $_TIF_ALLWORK_MASK, %ecx
17831 jne sysexit_audit
17832 sysenter_exit:
17833+
17834+#ifdef CONFIG_PAX_RANDKSTACK
17835+ pushl_cfi %eax
17836+ movl %esp, %eax
17837+ call pax_randomize_kstack
17838+ popl_cfi %eax
17839+#endif
17840+
17841+ pax_erase_kstack
17842+
17843 /* if something modifies registers it must also disable sysexit */
17844 movl PT_EIP(%esp), %edx
17845 movl PT_OLDESP(%esp), %ecx
17846 xorl %ebp,%ebp
17847 TRACE_IRQS_ON
17848 1: mov PT_FS(%esp), %fs
17849+2: mov PT_DS(%esp), %ds
17850+3: mov PT_ES(%esp), %es
17851 PTGS_TO_GS
17852 ENABLE_INTERRUPTS_SYSEXIT
17853
17854@@ -466,6 +650,9 @@ sysenter_audit:
17855 movl %eax,%edx /* 2nd arg: syscall number */
17856 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
17857 call __audit_syscall_entry
17858+
17859+ pax_erase_kstack
17860+
17861 pushl_cfi %ebx
17862 movl PT_EAX(%esp),%eax /* reload syscall number */
17863 jmp sysenter_do_call
17864@@ -491,10 +678,16 @@ sysexit_audit:
17865
17866 CFI_ENDPROC
17867 .pushsection .fixup,"ax"
17868-2: movl $0,PT_FS(%esp)
17869+4: movl $0,PT_FS(%esp)
17870+ jmp 1b
17871+5: movl $0,PT_DS(%esp)
17872+ jmp 1b
17873+6: movl $0,PT_ES(%esp)
17874 jmp 1b
17875 .popsection
17876- _ASM_EXTABLE(1b,2b)
17877+ _ASM_EXTABLE(1b,4b)
17878+ _ASM_EXTABLE(2b,5b)
17879+ _ASM_EXTABLE(3b,6b)
17880 PTGS_TO_GS_EX
17881 ENDPROC(ia32_sysenter_target)
17882
17883@@ -509,6 +702,11 @@ ENTRY(system_call)
17884 pushl_cfi %eax # save orig_eax
17885 SAVE_ALL
17886 GET_THREAD_INFO(%ebp)
17887+
17888+#ifdef CONFIG_PAX_RANDKSTACK
17889+ pax_erase_kstack
17890+#endif
17891+
17892 # system call tracing in operation / emulation
17893 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
17894 jnz syscall_trace_entry
17895@@ -527,6 +725,15 @@ syscall_exit:
17896 testl $_TIF_ALLWORK_MASK, %ecx # current->work
17897 jne syscall_exit_work
17898
17899+restore_all_pax:
17900+
17901+#ifdef CONFIG_PAX_RANDKSTACK
17902+ movl %esp, %eax
17903+ call pax_randomize_kstack
17904+#endif
17905+
17906+ pax_erase_kstack
17907+
17908 restore_all:
17909 TRACE_IRQS_IRET
17910 restore_all_notrace:
17911@@ -583,14 +790,34 @@ ldt_ss:
17912 * compensating for the offset by changing to the ESPFIX segment with
17913 * a base address that matches for the difference.
17914 */
17915-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
17916+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
17917 mov %esp, %edx /* load kernel esp */
17918 mov PT_OLDESP(%esp), %eax /* load userspace esp */
17919 mov %dx, %ax /* eax: new kernel esp */
17920 sub %eax, %edx /* offset (low word is 0) */
17921+#ifdef CONFIG_SMP
17922+ movl PER_CPU_VAR(cpu_number), %ebx
17923+ shll $PAGE_SHIFT_asm, %ebx
17924+ addl $cpu_gdt_table, %ebx
17925+#else
17926+ movl $cpu_gdt_table, %ebx
17927+#endif
17928 shr $16, %edx
17929- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
17930- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
17931+
17932+#ifdef CONFIG_PAX_KERNEXEC
17933+ mov %cr0, %esi
17934+ btr $16, %esi
17935+ mov %esi, %cr0
17936+#endif
17937+
17938+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
17939+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
17940+
17941+#ifdef CONFIG_PAX_KERNEXEC
17942+ bts $16, %esi
17943+ mov %esi, %cr0
17944+#endif
17945+
17946 pushl_cfi $__ESPFIX_SS
17947 pushl_cfi %eax /* new kernel esp */
17948 /* Disable interrupts, but do not irqtrace this section: we
17949@@ -619,20 +846,18 @@ work_resched:
17950 movl TI_flags(%ebp), %ecx
17951 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
17952 # than syscall tracing?
17953- jz restore_all
17954+ jz restore_all_pax
17955 testb $_TIF_NEED_RESCHED, %cl
17956 jnz work_resched
17957
17958 work_notifysig: # deal with pending signals and
17959 # notify-resume requests
17960+ movl %esp, %eax
17961 #ifdef CONFIG_VM86
17962 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
17963- movl %esp, %eax
17964 jne work_notifysig_v86 # returning to kernel-space or
17965 # vm86-space
17966 1:
17967-#else
17968- movl %esp, %eax
17969 #endif
17970 TRACE_IRQS_ON
17971 ENABLE_INTERRUPTS(CLBR_NONE)
17972@@ -653,7 +878,7 @@ work_notifysig_v86:
17973 movl %eax, %esp
17974 jmp 1b
17975 #endif
17976-END(work_pending)
17977+ENDPROC(work_pending)
17978
17979 # perform syscall exit tracing
17980 ALIGN
17981@@ -661,11 +886,14 @@ syscall_trace_entry:
17982 movl $-ENOSYS,PT_EAX(%esp)
17983 movl %esp, %eax
17984 call syscall_trace_enter
17985+
17986+ pax_erase_kstack
17987+
17988 /* What it returned is what we'll actually use. */
17989 cmpl $(NR_syscalls), %eax
17990 jnae syscall_call
17991 jmp syscall_exit
17992-END(syscall_trace_entry)
17993+ENDPROC(syscall_trace_entry)
17994
17995 # perform syscall exit tracing
17996 ALIGN
17997@@ -678,21 +906,25 @@ syscall_exit_work:
17998 movl %esp, %eax
17999 call syscall_trace_leave
18000 jmp resume_userspace
18001-END(syscall_exit_work)
18002+ENDPROC(syscall_exit_work)
18003 CFI_ENDPROC
18004
18005 RING0_INT_FRAME # can't unwind into user space anyway
18006 syscall_fault:
18007+#ifdef CONFIG_PAX_MEMORY_UDEREF
18008+ push %ss
18009+ pop %ds
18010+#endif
18011 ASM_CLAC
18012 GET_THREAD_INFO(%ebp)
18013 movl $-EFAULT,PT_EAX(%esp)
18014 jmp resume_userspace
18015-END(syscall_fault)
18016+ENDPROC(syscall_fault)
18017
18018 syscall_badsys:
18019 movl $-ENOSYS,PT_EAX(%esp)
18020 jmp resume_userspace
18021-END(syscall_badsys)
18022+ENDPROC(syscall_badsys)
18023 CFI_ENDPROC
18024 /*
18025 * End of kprobes section
18026@@ -753,8 +985,15 @@ PTREGSCALL1(vm86old)
18027 * normal stack and adjusts ESP with the matching offset.
18028 */
18029 /* fixup the stack */
18030- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
18031- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
18032+#ifdef CONFIG_SMP
18033+ movl PER_CPU_VAR(cpu_number), %ebx
18034+ shll $PAGE_SHIFT_asm, %ebx
18035+ addl $cpu_gdt_table, %ebx
18036+#else
18037+ movl $cpu_gdt_table, %ebx
18038+#endif
18039+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
18040+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
18041 shl $16, %eax
18042 addl %esp, %eax /* the adjusted stack pointer */
18043 pushl_cfi $__KERNEL_DS
18044@@ -807,7 +1046,7 @@ vector=vector+1
18045 .endr
18046 2: jmp common_interrupt
18047 .endr
18048-END(irq_entries_start)
18049+ENDPROC(irq_entries_start)
18050
18051 .previous
18052 END(interrupt)
18053@@ -858,7 +1097,7 @@ ENTRY(coprocessor_error)
18054 pushl_cfi $do_coprocessor_error
18055 jmp error_code
18056 CFI_ENDPROC
18057-END(coprocessor_error)
18058+ENDPROC(coprocessor_error)
18059
18060 ENTRY(simd_coprocessor_error)
18061 RING0_INT_FRAME
18062@@ -880,7 +1119,7 @@ ENTRY(simd_coprocessor_error)
18063 #endif
18064 jmp error_code
18065 CFI_ENDPROC
18066-END(simd_coprocessor_error)
18067+ENDPROC(simd_coprocessor_error)
18068
18069 ENTRY(device_not_available)
18070 RING0_INT_FRAME
18071@@ -889,18 +1128,18 @@ ENTRY(device_not_available)
18072 pushl_cfi $do_device_not_available
18073 jmp error_code
18074 CFI_ENDPROC
18075-END(device_not_available)
18076+ENDPROC(device_not_available)
18077
18078 #ifdef CONFIG_PARAVIRT
18079 ENTRY(native_iret)
18080 iret
18081 _ASM_EXTABLE(native_iret, iret_exc)
18082-END(native_iret)
18083+ENDPROC(native_iret)
18084
18085 ENTRY(native_irq_enable_sysexit)
18086 sti
18087 sysexit
18088-END(native_irq_enable_sysexit)
18089+ENDPROC(native_irq_enable_sysexit)
18090 #endif
18091
18092 ENTRY(overflow)
18093@@ -910,7 +1149,7 @@ ENTRY(overflow)
18094 pushl_cfi $do_overflow
18095 jmp error_code
18096 CFI_ENDPROC
18097-END(overflow)
18098+ENDPROC(overflow)
18099
18100 ENTRY(bounds)
18101 RING0_INT_FRAME
18102@@ -919,7 +1158,7 @@ ENTRY(bounds)
18103 pushl_cfi $do_bounds
18104 jmp error_code
18105 CFI_ENDPROC
18106-END(bounds)
18107+ENDPROC(bounds)
18108
18109 ENTRY(invalid_op)
18110 RING0_INT_FRAME
18111@@ -928,7 +1167,7 @@ ENTRY(invalid_op)
18112 pushl_cfi $do_invalid_op
18113 jmp error_code
18114 CFI_ENDPROC
18115-END(invalid_op)
18116+ENDPROC(invalid_op)
18117
18118 ENTRY(coprocessor_segment_overrun)
18119 RING0_INT_FRAME
18120@@ -937,7 +1176,7 @@ ENTRY(coprocessor_segment_overrun)
18121 pushl_cfi $do_coprocessor_segment_overrun
18122 jmp error_code
18123 CFI_ENDPROC
18124-END(coprocessor_segment_overrun)
18125+ENDPROC(coprocessor_segment_overrun)
18126
18127 ENTRY(invalid_TSS)
18128 RING0_EC_FRAME
18129@@ -945,7 +1184,7 @@ ENTRY(invalid_TSS)
18130 pushl_cfi $do_invalid_TSS
18131 jmp error_code
18132 CFI_ENDPROC
18133-END(invalid_TSS)
18134+ENDPROC(invalid_TSS)
18135
18136 ENTRY(segment_not_present)
18137 RING0_EC_FRAME
18138@@ -953,7 +1192,7 @@ ENTRY(segment_not_present)
18139 pushl_cfi $do_segment_not_present
18140 jmp error_code
18141 CFI_ENDPROC
18142-END(segment_not_present)
18143+ENDPROC(segment_not_present)
18144
18145 ENTRY(stack_segment)
18146 RING0_EC_FRAME
18147@@ -961,7 +1200,7 @@ ENTRY(stack_segment)
18148 pushl_cfi $do_stack_segment
18149 jmp error_code
18150 CFI_ENDPROC
18151-END(stack_segment)
18152+ENDPROC(stack_segment)
18153
18154 ENTRY(alignment_check)
18155 RING0_EC_FRAME
18156@@ -969,7 +1208,7 @@ ENTRY(alignment_check)
18157 pushl_cfi $do_alignment_check
18158 jmp error_code
18159 CFI_ENDPROC
18160-END(alignment_check)
18161+ENDPROC(alignment_check)
18162
18163 ENTRY(divide_error)
18164 RING0_INT_FRAME
18165@@ -978,7 +1217,7 @@ ENTRY(divide_error)
18166 pushl_cfi $do_divide_error
18167 jmp error_code
18168 CFI_ENDPROC
18169-END(divide_error)
18170+ENDPROC(divide_error)
18171
18172 #ifdef CONFIG_X86_MCE
18173 ENTRY(machine_check)
18174@@ -988,7 +1227,7 @@ ENTRY(machine_check)
18175 pushl_cfi machine_check_vector
18176 jmp error_code
18177 CFI_ENDPROC
18178-END(machine_check)
18179+ENDPROC(machine_check)
18180 #endif
18181
18182 ENTRY(spurious_interrupt_bug)
18183@@ -998,7 +1237,7 @@ ENTRY(spurious_interrupt_bug)
18184 pushl_cfi $do_spurious_interrupt_bug
18185 jmp error_code
18186 CFI_ENDPROC
18187-END(spurious_interrupt_bug)
18188+ENDPROC(spurious_interrupt_bug)
18189 /*
18190 * End of kprobes section
18191 */
18192@@ -1101,7 +1340,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
18193
18194 ENTRY(mcount)
18195 ret
18196-END(mcount)
18197+ENDPROC(mcount)
18198
18199 ENTRY(ftrace_caller)
18200 cmpl $0, function_trace_stop
18201@@ -1134,7 +1373,7 @@ ftrace_graph_call:
18202 .globl ftrace_stub
18203 ftrace_stub:
18204 ret
18205-END(ftrace_caller)
18206+ENDPROC(ftrace_caller)
18207
18208 ENTRY(ftrace_regs_caller)
18209 pushf /* push flags before compare (in cs location) */
18210@@ -1235,7 +1474,7 @@ trace:
18211 popl %ecx
18212 popl %eax
18213 jmp ftrace_stub
18214-END(mcount)
18215+ENDPROC(mcount)
18216 #endif /* CONFIG_DYNAMIC_FTRACE */
18217 #endif /* CONFIG_FUNCTION_TRACER */
18218
18219@@ -1253,7 +1492,7 @@ ENTRY(ftrace_graph_caller)
18220 popl %ecx
18221 popl %eax
18222 ret
18223-END(ftrace_graph_caller)
18224+ENDPROC(ftrace_graph_caller)
18225
18226 .globl return_to_handler
18227 return_to_handler:
18228@@ -1309,15 +1548,18 @@ error_code:
18229 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
18230 REG_TO_PTGS %ecx
18231 SET_KERNEL_GS %ecx
18232- movl $(__USER_DS), %ecx
18233+ movl $(__KERNEL_DS), %ecx
18234 movl %ecx, %ds
18235 movl %ecx, %es
18236+
18237+ pax_enter_kernel
18238+
18239 TRACE_IRQS_OFF
18240 movl %esp,%eax # pt_regs pointer
18241 call *%edi
18242 jmp ret_from_exception
18243 CFI_ENDPROC
18244-END(page_fault)
18245+ENDPROC(page_fault)
18246
18247 /*
18248 * Debug traps and NMI can happen at the one SYSENTER instruction
18249@@ -1360,7 +1602,7 @@ debug_stack_correct:
18250 call do_debug
18251 jmp ret_from_exception
18252 CFI_ENDPROC
18253-END(debug)
18254+ENDPROC(debug)
18255
18256 /*
18257 * NMI is doubly nasty. It can happen _while_ we're handling
18258@@ -1398,6 +1640,9 @@ nmi_stack_correct:
18259 xorl %edx,%edx # zero error code
18260 movl %esp,%eax # pt_regs pointer
18261 call do_nmi
18262+
18263+ pax_exit_kernel
18264+
18265 jmp restore_all_notrace
18266 CFI_ENDPROC
18267
18268@@ -1434,12 +1679,15 @@ nmi_espfix_stack:
18269 FIXUP_ESPFIX_STACK # %eax == %esp
18270 xorl %edx,%edx # zero error code
18271 call do_nmi
18272+
18273+ pax_exit_kernel
18274+
18275 RESTORE_REGS
18276 lss 12+4(%esp), %esp # back to espfix stack
18277 CFI_ADJUST_CFA_OFFSET -24
18278 jmp irq_return
18279 CFI_ENDPROC
18280-END(nmi)
18281+ENDPROC(nmi)
18282
18283 ENTRY(int3)
18284 RING0_INT_FRAME
18285@@ -1452,14 +1700,14 @@ ENTRY(int3)
18286 call do_int3
18287 jmp ret_from_exception
18288 CFI_ENDPROC
18289-END(int3)
18290+ENDPROC(int3)
18291
18292 ENTRY(general_protection)
18293 RING0_EC_FRAME
18294 pushl_cfi $do_general_protection
18295 jmp error_code
18296 CFI_ENDPROC
18297-END(general_protection)
18298+ENDPROC(general_protection)
18299
18300 #ifdef CONFIG_KVM_GUEST
18301 ENTRY(async_page_fault)
18302@@ -1468,7 +1716,7 @@ ENTRY(async_page_fault)
18303 pushl_cfi $do_async_page_fault
18304 jmp error_code
18305 CFI_ENDPROC
18306-END(async_page_fault)
18307+ENDPROC(async_page_fault)
18308 #endif
18309
18310 /*
18311diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
18312index cb3c591..bc63707 100644
18313--- a/arch/x86/kernel/entry_64.S
18314+++ b/arch/x86/kernel/entry_64.S
18315@@ -59,6 +59,8 @@
18316 #include <asm/context_tracking.h>
18317 #include <asm/smap.h>
18318 #include <linux/err.h>
18319+#include <asm/pgtable.h>
18320+#include <asm/alternative-asm.h>
18321
18322 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
18323 #include <linux/elf-em.h>
18324@@ -80,8 +82,9 @@
18325 #ifdef CONFIG_DYNAMIC_FTRACE
18326
18327 ENTRY(function_hook)
18328+ pax_force_retaddr
18329 retq
18330-END(function_hook)
18331+ENDPROC(function_hook)
18332
18333 /* skip is set if stack has been adjusted */
18334 .macro ftrace_caller_setup skip=0
18335@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
18336 #endif
18337
18338 GLOBAL(ftrace_stub)
18339+ pax_force_retaddr
18340 retq
18341-END(ftrace_caller)
18342+ENDPROC(ftrace_caller)
18343
18344 ENTRY(ftrace_regs_caller)
18345 /* Save the current flags before compare (in SS location)*/
18346@@ -191,7 +195,7 @@ ftrace_restore_flags:
18347 popfq
18348 jmp ftrace_stub
18349
18350-END(ftrace_regs_caller)
18351+ENDPROC(ftrace_regs_caller)
18352
18353
18354 #else /* ! CONFIG_DYNAMIC_FTRACE */
18355@@ -212,6 +216,7 @@ ENTRY(function_hook)
18356 #endif
18357
18358 GLOBAL(ftrace_stub)
18359+ pax_force_retaddr
18360 retq
18361
18362 trace:
18363@@ -225,12 +230,13 @@ trace:
18364 #endif
18365 subq $MCOUNT_INSN_SIZE, %rdi
18366
18367+ pax_force_fptr ftrace_trace_function
18368 call *ftrace_trace_function
18369
18370 MCOUNT_RESTORE_FRAME
18371
18372 jmp ftrace_stub
18373-END(function_hook)
18374+ENDPROC(function_hook)
18375 #endif /* CONFIG_DYNAMIC_FTRACE */
18376 #endif /* CONFIG_FUNCTION_TRACER */
18377
18378@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
18379
18380 MCOUNT_RESTORE_FRAME
18381
18382+ pax_force_retaddr
18383 retq
18384-END(ftrace_graph_caller)
18385+ENDPROC(ftrace_graph_caller)
18386
18387 GLOBAL(return_to_handler)
18388 subq $24, %rsp
18389@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
18390 movq 8(%rsp), %rdx
18391 movq (%rsp), %rax
18392 addq $24, %rsp
18393+ pax_force_fptr %rdi
18394 jmp *%rdi
18395+ENDPROC(return_to_handler)
18396 #endif
18397
18398
18399@@ -284,6 +293,273 @@ ENTRY(native_usergs_sysret64)
18400 ENDPROC(native_usergs_sysret64)
18401 #endif /* CONFIG_PARAVIRT */
18402
18403+ .macro ljmpq sel, off
18404+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
18405+ .byte 0x48; ljmp *1234f(%rip)
18406+ .pushsection .rodata
18407+ .align 16
18408+ 1234: .quad \off; .word \sel
18409+ .popsection
18410+#else
18411+ pushq $\sel
18412+ pushq $\off
18413+ lretq
18414+#endif
18415+ .endm
18416+
18417+ .macro pax_enter_kernel
18418+ pax_set_fptr_mask
18419+#ifdef CONFIG_PAX_KERNEXEC
18420+ call pax_enter_kernel
18421+#endif
18422+ .endm
18423+
18424+ .macro pax_exit_kernel
18425+#ifdef CONFIG_PAX_KERNEXEC
18426+ call pax_exit_kernel
18427+#endif
18428+ .endm
18429+
18430+#ifdef CONFIG_PAX_KERNEXEC
18431+ENTRY(pax_enter_kernel)
18432+ pushq %rdi
18433+
18434+#ifdef CONFIG_PARAVIRT
18435+ PV_SAVE_REGS(CLBR_RDI)
18436+#endif
18437+
18438+ GET_CR0_INTO_RDI
18439+ bts $16,%rdi
18440+ jnc 3f
18441+ mov %cs,%edi
18442+ cmp $__KERNEL_CS,%edi
18443+ jnz 2f
18444+1:
18445+
18446+#ifdef CONFIG_PARAVIRT
18447+ PV_RESTORE_REGS(CLBR_RDI)
18448+#endif
18449+
18450+ popq %rdi
18451+ pax_force_retaddr
18452+ retq
18453+
18454+2: ljmpq __KERNEL_CS,1f
18455+3: ljmpq __KERNEXEC_KERNEL_CS,4f
18456+4: SET_RDI_INTO_CR0
18457+ jmp 1b
18458+ENDPROC(pax_enter_kernel)
18459+
18460+ENTRY(pax_exit_kernel)
18461+ pushq %rdi
18462+
18463+#ifdef CONFIG_PARAVIRT
18464+ PV_SAVE_REGS(CLBR_RDI)
18465+#endif
18466+
18467+ mov %cs,%rdi
18468+ cmp $__KERNEXEC_KERNEL_CS,%edi
18469+ jz 2f
18470+1:
18471+
18472+#ifdef CONFIG_PARAVIRT
18473+ PV_RESTORE_REGS(CLBR_RDI);
18474+#endif
18475+
18476+ popq %rdi
18477+ pax_force_retaddr
18478+ retq
18479+
18480+2: GET_CR0_INTO_RDI
18481+ btr $16,%rdi
18482+ ljmpq __KERNEL_CS,3f
18483+3: SET_RDI_INTO_CR0
18484+ jmp 1b
18485+ENDPROC(pax_exit_kernel)
18486+#endif
18487+
18488+ .macro pax_enter_kernel_user
18489+ pax_set_fptr_mask
18490+#ifdef CONFIG_PAX_MEMORY_UDEREF
18491+ call pax_enter_kernel_user
18492+#endif
18493+ .endm
18494+
18495+ .macro pax_exit_kernel_user
18496+#ifdef CONFIG_PAX_MEMORY_UDEREF
18497+ call pax_exit_kernel_user
18498+#endif
18499+#ifdef CONFIG_PAX_RANDKSTACK
18500+ pushq %rax
18501+ call pax_randomize_kstack
18502+ popq %rax
18503+#endif
18504+ .endm
18505+
18506+#ifdef CONFIG_PAX_MEMORY_UDEREF
18507+ENTRY(pax_enter_kernel_user)
18508+ pushq %rdi
18509+ pushq %rbx
18510+
18511+#ifdef CONFIG_PARAVIRT
18512+ PV_SAVE_REGS(CLBR_RDI)
18513+#endif
18514+
18515+ GET_CR3_INTO_RDI
18516+ mov %rdi,%rbx
18517+ add $__START_KERNEL_map,%rbx
18518+ sub phys_base(%rip),%rbx
18519+
18520+#ifdef CONFIG_PARAVIRT
18521+ pushq %rdi
18522+ cmpl $0, pv_info+PARAVIRT_enabled
18523+ jz 1f
18524+ i = 0
18525+ .rept USER_PGD_PTRS
18526+ mov i*8(%rbx),%rsi
18527+ mov $0,%sil
18528+ lea i*8(%rbx),%rdi
18529+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
18530+ i = i + 1
18531+ .endr
18532+ jmp 2f
18533+1:
18534+#endif
18535+
18536+ i = 0
18537+ .rept USER_PGD_PTRS
18538+ movb $0,i*8(%rbx)
18539+ i = i + 1
18540+ .endr
18541+
18542+#ifdef CONFIG_PARAVIRT
18543+2: popq %rdi
18544+#endif
18545+ SET_RDI_INTO_CR3
18546+
18547+#ifdef CONFIG_PAX_KERNEXEC
18548+ GET_CR0_INTO_RDI
18549+ bts $16,%rdi
18550+ SET_RDI_INTO_CR0
18551+#endif
18552+
18553+#ifdef CONFIG_PARAVIRT
18554+ PV_RESTORE_REGS(CLBR_RDI)
18555+#endif
18556+
18557+ popq %rbx
18558+ popq %rdi
18559+ pax_force_retaddr
18560+ retq
18561+ENDPROC(pax_enter_kernel_user)
18562+
18563+ENTRY(pax_exit_kernel_user)
18564+ push %rdi
18565+
18566+#ifdef CONFIG_PARAVIRT
18567+ pushq %rbx
18568+ PV_SAVE_REGS(CLBR_RDI)
18569+#endif
18570+
18571+#ifdef CONFIG_PAX_KERNEXEC
18572+ GET_CR0_INTO_RDI
18573+ btr $16,%rdi
18574+ SET_RDI_INTO_CR0
18575+#endif
18576+
18577+ GET_CR3_INTO_RDI
18578+ add $__START_KERNEL_map,%rdi
18579+ sub phys_base(%rip),%rdi
18580+
18581+#ifdef CONFIG_PARAVIRT
18582+ cmpl $0, pv_info+PARAVIRT_enabled
18583+ jz 1f
18584+ mov %rdi,%rbx
18585+ i = 0
18586+ .rept USER_PGD_PTRS
18587+ mov i*8(%rbx),%rsi
18588+ mov $0x67,%sil
18589+ lea i*8(%rbx),%rdi
18590+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
18591+ i = i + 1
18592+ .endr
18593+ jmp 2f
18594+1:
18595+#endif
18596+
18597+ i = 0
18598+ .rept USER_PGD_PTRS
18599+ movb $0x67,i*8(%rdi)
18600+ i = i + 1
18601+ .endr
18602+
18603+#ifdef CONFIG_PARAVIRT
18604+2: PV_RESTORE_REGS(CLBR_RDI)
18605+ popq %rbx
18606+#endif
18607+
18608+ popq %rdi
18609+ pax_force_retaddr
18610+ retq
18611+ENDPROC(pax_exit_kernel_user)
18612+#endif
18613+
18614+.macro pax_erase_kstack
18615+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18616+ call pax_erase_kstack
18617+#endif
18618+.endm
18619+
18620+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18621+ENTRY(pax_erase_kstack)
18622+ pushq %rdi
18623+ pushq %rcx
18624+ pushq %rax
18625+ pushq %r11
18626+
18627+ GET_THREAD_INFO(%r11)
18628+ mov TI_lowest_stack(%r11), %rdi
18629+ mov $-0xBEEF, %rax
18630+ std
18631+
18632+1: mov %edi, %ecx
18633+ and $THREAD_SIZE_asm - 1, %ecx
18634+ shr $3, %ecx
18635+ repne scasq
18636+ jecxz 2f
18637+
18638+ cmp $2*8, %ecx
18639+ jc 2f
18640+
18641+ mov $2*8, %ecx
18642+ repe scasq
18643+ jecxz 2f
18644+ jne 1b
18645+
18646+2: cld
18647+ mov %esp, %ecx
18648+ sub %edi, %ecx
18649+
18650+ cmp $THREAD_SIZE_asm, %rcx
18651+ jb 3f
18652+ ud2
18653+3:
18654+
18655+ shr $3, %ecx
18656+ rep stosq
18657+
18658+ mov TI_task_thread_sp0(%r11), %rdi
18659+ sub $256, %rdi
18660+ mov %rdi, TI_lowest_stack(%r11)
18661+
18662+ popq %r11
18663+ popq %rax
18664+ popq %rcx
18665+ popq %rdi
18666+ pax_force_retaddr
18667+ ret
18668+ENDPROC(pax_erase_kstack)
18669+#endif
18670
18671 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
18672 #ifdef CONFIG_TRACE_IRQFLAGS
18673@@ -375,8 +651,8 @@ ENDPROC(native_usergs_sysret64)
18674 .endm
18675
18676 .macro UNFAKE_STACK_FRAME
18677- addq $8*6, %rsp
18678- CFI_ADJUST_CFA_OFFSET -(6*8)
18679+ addq $8*6 + ARG_SKIP, %rsp
18680+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
18681 .endm
18682
18683 /*
18684@@ -463,7 +739,7 @@ ENDPROC(native_usergs_sysret64)
18685 movq %rsp, %rsi
18686
18687 leaq -RBP(%rsp),%rdi /* arg1 for handler */
18688- testl $3, CS-RBP(%rsi)
18689+ testb $3, CS-RBP(%rsi)
18690 je 1f
18691 SWAPGS
18692 /*
18693@@ -498,9 +774,10 @@ ENTRY(save_rest)
18694 movq_cfi r15, R15+16
18695 movq %r11, 8(%rsp) /* return address */
18696 FIXUP_TOP_OF_STACK %r11, 16
18697+ pax_force_retaddr
18698 ret
18699 CFI_ENDPROC
18700-END(save_rest)
18701+ENDPROC(save_rest)
18702
18703 /* save complete stack frame */
18704 .pushsection .kprobes.text, "ax"
18705@@ -529,9 +806,10 @@ ENTRY(save_paranoid)
18706 js 1f /* negative -> in kernel */
18707 SWAPGS
18708 xorl %ebx,%ebx
18709-1: ret
18710+1: pax_force_retaddr_bts
18711+ ret
18712 CFI_ENDPROC
18713-END(save_paranoid)
18714+ENDPROC(save_paranoid)
18715 .popsection
18716
18717 /*
18718@@ -553,7 +831,7 @@ ENTRY(ret_from_fork)
18719
18720 RESTORE_REST
18721
18722- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
18723+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
18724 jz 1f
18725
18726 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
18727@@ -571,7 +849,7 @@ ENTRY(ret_from_fork)
18728 RESTORE_REST
18729 jmp int_ret_from_sys_call
18730 CFI_ENDPROC
18731-END(ret_from_fork)
18732+ENDPROC(ret_from_fork)
18733
18734 /*
18735 * System call entry. Up to 6 arguments in registers are supported.
18736@@ -608,7 +886,7 @@ END(ret_from_fork)
18737 ENTRY(system_call)
18738 CFI_STARTPROC simple
18739 CFI_SIGNAL_FRAME
18740- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
18741+ CFI_DEF_CFA rsp,0
18742 CFI_REGISTER rip,rcx
18743 /*CFI_REGISTER rflags,r11*/
18744 SWAPGS_UNSAFE_STACK
18745@@ -621,16 +899,23 @@ GLOBAL(system_call_after_swapgs)
18746
18747 movq %rsp,PER_CPU_VAR(old_rsp)
18748 movq PER_CPU_VAR(kernel_stack),%rsp
18749+ SAVE_ARGS 8*6,0
18750+ pax_enter_kernel_user
18751+
18752+#ifdef CONFIG_PAX_RANDKSTACK
18753+ pax_erase_kstack
18754+#endif
18755+
18756 /*
18757 * No need to follow this irqs off/on section - it's straight
18758 * and short:
18759 */
18760 ENABLE_INTERRUPTS(CLBR_NONE)
18761- SAVE_ARGS 8,0
18762 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
18763 movq %rcx,RIP-ARGOFFSET(%rsp)
18764 CFI_REL_OFFSET rip,RIP-ARGOFFSET
18765- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
18766+ GET_THREAD_INFO(%rcx)
18767+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
18768 jnz tracesys
18769 system_call_fastpath:
18770 #if __SYSCALL_MASK == ~0
18771@@ -640,7 +925,7 @@ system_call_fastpath:
18772 cmpl $__NR_syscall_max,%eax
18773 #endif
18774 ja badsys
18775- movq %r10,%rcx
18776+ movq R10-ARGOFFSET(%rsp),%rcx
18777 call *sys_call_table(,%rax,8) # XXX: rip relative
18778 movq %rax,RAX-ARGOFFSET(%rsp)
18779 /*
18780@@ -654,10 +939,13 @@ sysret_check:
18781 LOCKDEP_SYS_EXIT
18782 DISABLE_INTERRUPTS(CLBR_NONE)
18783 TRACE_IRQS_OFF
18784- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
18785+ GET_THREAD_INFO(%rcx)
18786+ movl TI_flags(%rcx),%edx
18787 andl %edi,%edx
18788 jnz sysret_careful
18789 CFI_REMEMBER_STATE
18790+ pax_exit_kernel_user
18791+ pax_erase_kstack
18792 /*
18793 * sysretq will re-enable interrupts:
18794 */
18795@@ -709,14 +997,18 @@ badsys:
18796 * jump back to the normal fast path.
18797 */
18798 auditsys:
18799- movq %r10,%r9 /* 6th arg: 4th syscall arg */
18800+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
18801 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
18802 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
18803 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
18804 movq %rax,%rsi /* 2nd arg: syscall number */
18805 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
18806 call __audit_syscall_entry
18807+
18808+ pax_erase_kstack
18809+
18810 LOAD_ARGS 0 /* reload call-clobbered registers */
18811+ pax_set_fptr_mask
18812 jmp system_call_fastpath
18813
18814 /*
18815@@ -737,7 +1029,7 @@ sysret_audit:
18816 /* Do syscall tracing */
18817 tracesys:
18818 #ifdef CONFIG_AUDITSYSCALL
18819- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
18820+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
18821 jz auditsys
18822 #endif
18823 SAVE_REST
18824@@ -745,12 +1037,16 @@ tracesys:
18825 FIXUP_TOP_OF_STACK %rdi
18826 movq %rsp,%rdi
18827 call syscall_trace_enter
18828+
18829+ pax_erase_kstack
18830+
18831 /*
18832 * Reload arg registers from stack in case ptrace changed them.
18833 * We don't reload %rax because syscall_trace_enter() returned
18834 * the value it wants us to use in the table lookup.
18835 */
18836 LOAD_ARGS ARGOFFSET, 1
18837+ pax_set_fptr_mask
18838 RESTORE_REST
18839 #if __SYSCALL_MASK == ~0
18840 cmpq $__NR_syscall_max,%rax
18841@@ -759,7 +1055,7 @@ tracesys:
18842 cmpl $__NR_syscall_max,%eax
18843 #endif
18844 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
18845- movq %r10,%rcx /* fixup for C */
18846+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
18847 call *sys_call_table(,%rax,8)
18848 movq %rax,RAX-ARGOFFSET(%rsp)
18849 /* Use IRET because user could have changed frame */
18850@@ -780,7 +1076,9 @@ GLOBAL(int_with_check)
18851 andl %edi,%edx
18852 jnz int_careful
18853 andl $~TS_COMPAT,TI_status(%rcx)
18854- jmp retint_swapgs
18855+ pax_exit_kernel_user
18856+ pax_erase_kstack
18857+ jmp retint_swapgs_pax
18858
18859 /* Either reschedule or signal or syscall exit tracking needed. */
18860 /* First do a reschedule test. */
18861@@ -826,7 +1124,7 @@ int_restore_rest:
18862 TRACE_IRQS_OFF
18863 jmp int_with_check
18864 CFI_ENDPROC
18865-END(system_call)
18866+ENDPROC(system_call)
18867
18868 /*
18869 * Certain special system calls that need to save a complete full stack frame.
18870@@ -842,7 +1140,7 @@ ENTRY(\label)
18871 call \func
18872 jmp ptregscall_common
18873 CFI_ENDPROC
18874-END(\label)
18875+ENDPROC(\label)
18876 .endm
18877
18878 .macro FORK_LIKE func
18879@@ -856,9 +1154,10 @@ ENTRY(stub_\func)
18880 DEFAULT_FRAME 0 8 /* offset 8: return address */
18881 call sys_\func
18882 RESTORE_TOP_OF_STACK %r11, 8
18883+ pax_force_retaddr
18884 ret $REST_SKIP /* pop extended registers */
18885 CFI_ENDPROC
18886-END(stub_\func)
18887+ENDPROC(stub_\func)
18888 .endm
18889
18890 FORK_LIKE clone
18891@@ -875,9 +1174,10 @@ ENTRY(ptregscall_common)
18892 movq_cfi_restore R12+8, r12
18893 movq_cfi_restore RBP+8, rbp
18894 movq_cfi_restore RBX+8, rbx
18895+ pax_force_retaddr
18896 ret $REST_SKIP /* pop extended registers */
18897 CFI_ENDPROC
18898-END(ptregscall_common)
18899+ENDPROC(ptregscall_common)
18900
18901 ENTRY(stub_execve)
18902 CFI_STARTPROC
18903@@ -891,7 +1191,7 @@ ENTRY(stub_execve)
18904 RESTORE_REST
18905 jmp int_ret_from_sys_call
18906 CFI_ENDPROC
18907-END(stub_execve)
18908+ENDPROC(stub_execve)
18909
18910 /*
18911 * sigreturn is special because it needs to restore all registers on return.
18912@@ -909,7 +1209,7 @@ ENTRY(stub_rt_sigreturn)
18913 RESTORE_REST
18914 jmp int_ret_from_sys_call
18915 CFI_ENDPROC
18916-END(stub_rt_sigreturn)
18917+ENDPROC(stub_rt_sigreturn)
18918
18919 #ifdef CONFIG_X86_X32_ABI
18920 ENTRY(stub_x32_rt_sigreturn)
18921@@ -975,7 +1275,7 @@ vector=vector+1
18922 2: jmp common_interrupt
18923 .endr
18924 CFI_ENDPROC
18925-END(irq_entries_start)
18926+ENDPROC(irq_entries_start)
18927
18928 .previous
18929 END(interrupt)
18930@@ -995,6 +1295,16 @@ END(interrupt)
18931 subq $ORIG_RAX-RBP, %rsp
18932 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
18933 SAVE_ARGS_IRQ
18934+#ifdef CONFIG_PAX_MEMORY_UDEREF
18935+ testb $3, CS(%rdi)
18936+ jnz 1f
18937+ pax_enter_kernel
18938+ jmp 2f
18939+1: pax_enter_kernel_user
18940+2:
18941+#else
18942+ pax_enter_kernel
18943+#endif
18944 call \func
18945 .endm
18946
18947@@ -1027,7 +1337,7 @@ ret_from_intr:
18948
18949 exit_intr:
18950 GET_THREAD_INFO(%rcx)
18951- testl $3,CS-ARGOFFSET(%rsp)
18952+ testb $3,CS-ARGOFFSET(%rsp)
18953 je retint_kernel
18954
18955 /* Interrupt came from user space */
18956@@ -1049,12 +1359,16 @@ retint_swapgs: /* return to user-space */
18957 * The iretq could re-enable interrupts:
18958 */
18959 DISABLE_INTERRUPTS(CLBR_ANY)
18960+ pax_exit_kernel_user
18961+retint_swapgs_pax:
18962 TRACE_IRQS_IRETQ
18963 SWAPGS
18964 jmp restore_args
18965
18966 retint_restore_args: /* return to kernel space */
18967 DISABLE_INTERRUPTS(CLBR_ANY)
18968+ pax_exit_kernel
18969+ pax_force_retaddr (RIP-ARGOFFSET)
18970 /*
18971 * The iretq could re-enable interrupts:
18972 */
18973@@ -1137,7 +1451,7 @@ ENTRY(retint_kernel)
18974 #endif
18975
18976 CFI_ENDPROC
18977-END(common_interrupt)
18978+ENDPROC(common_interrupt)
18979 /*
18980 * End of kprobes section
18981 */
18982@@ -1155,7 +1469,7 @@ ENTRY(\sym)
18983 interrupt \do_sym
18984 jmp ret_from_intr
18985 CFI_ENDPROC
18986-END(\sym)
18987+ENDPROC(\sym)
18988 .endm
18989
18990 #ifdef CONFIG_SMP
18991@@ -1211,12 +1525,22 @@ ENTRY(\sym)
18992 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
18993 call error_entry
18994 DEFAULT_FRAME 0
18995+#ifdef CONFIG_PAX_MEMORY_UDEREF
18996+ testb $3, CS(%rsp)
18997+ jnz 1f
18998+ pax_enter_kernel
18999+ jmp 2f
19000+1: pax_enter_kernel_user
19001+2:
19002+#else
19003+ pax_enter_kernel
19004+#endif
19005 movq %rsp,%rdi /* pt_regs pointer */
19006 xorl %esi,%esi /* no error code */
19007 call \do_sym
19008 jmp error_exit /* %ebx: no swapgs flag */
19009 CFI_ENDPROC
19010-END(\sym)
19011+ENDPROC(\sym)
19012 .endm
19013
19014 .macro paranoidzeroentry sym do_sym
19015@@ -1229,15 +1553,25 @@ ENTRY(\sym)
19016 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19017 call save_paranoid
19018 TRACE_IRQS_OFF
19019+#ifdef CONFIG_PAX_MEMORY_UDEREF
19020+ testb $3, CS(%rsp)
19021+ jnz 1f
19022+ pax_enter_kernel
19023+ jmp 2f
19024+1: pax_enter_kernel_user
19025+2:
19026+#else
19027+ pax_enter_kernel
19028+#endif
19029 movq %rsp,%rdi /* pt_regs pointer */
19030 xorl %esi,%esi /* no error code */
19031 call \do_sym
19032 jmp paranoid_exit /* %ebx: no swapgs flag */
19033 CFI_ENDPROC
19034-END(\sym)
19035+ENDPROC(\sym)
19036 .endm
19037
19038-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
19039+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
19040 .macro paranoidzeroentry_ist sym do_sym ist
19041 ENTRY(\sym)
19042 INTR_FRAME
19043@@ -1248,14 +1582,30 @@ ENTRY(\sym)
19044 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19045 call save_paranoid
19046 TRACE_IRQS_OFF_DEBUG
19047+#ifdef CONFIG_PAX_MEMORY_UDEREF
19048+ testb $3, CS(%rsp)
19049+ jnz 1f
19050+ pax_enter_kernel
19051+ jmp 2f
19052+1: pax_enter_kernel_user
19053+2:
19054+#else
19055+ pax_enter_kernel
19056+#endif
19057 movq %rsp,%rdi /* pt_regs pointer */
19058 xorl %esi,%esi /* no error code */
19059+#ifdef CONFIG_SMP
19060+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
19061+ lea init_tss(%r12), %r12
19062+#else
19063+ lea init_tss(%rip), %r12
19064+#endif
19065 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19066 call \do_sym
19067 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19068 jmp paranoid_exit /* %ebx: no swapgs flag */
19069 CFI_ENDPROC
19070-END(\sym)
19071+ENDPROC(\sym)
19072 .endm
19073
19074 .macro errorentry sym do_sym
19075@@ -1267,13 +1617,23 @@ ENTRY(\sym)
19076 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19077 call error_entry
19078 DEFAULT_FRAME 0
19079+#ifdef CONFIG_PAX_MEMORY_UDEREF
19080+ testb $3, CS(%rsp)
19081+ jnz 1f
19082+ pax_enter_kernel
19083+ jmp 2f
19084+1: pax_enter_kernel_user
19085+2:
19086+#else
19087+ pax_enter_kernel
19088+#endif
19089 movq %rsp,%rdi /* pt_regs pointer */
19090 movq ORIG_RAX(%rsp),%rsi /* get error code */
19091 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19092 call \do_sym
19093 jmp error_exit /* %ebx: no swapgs flag */
19094 CFI_ENDPROC
19095-END(\sym)
19096+ENDPROC(\sym)
19097 .endm
19098
19099 /* error code is on the stack already */
19100@@ -1287,13 +1647,23 @@ ENTRY(\sym)
19101 call save_paranoid
19102 DEFAULT_FRAME 0
19103 TRACE_IRQS_OFF
19104+#ifdef CONFIG_PAX_MEMORY_UDEREF
19105+ testb $3, CS(%rsp)
19106+ jnz 1f
19107+ pax_enter_kernel
19108+ jmp 2f
19109+1: pax_enter_kernel_user
19110+2:
19111+#else
19112+ pax_enter_kernel
19113+#endif
19114 movq %rsp,%rdi /* pt_regs pointer */
19115 movq ORIG_RAX(%rsp),%rsi /* get error code */
19116 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19117 call \do_sym
19118 jmp paranoid_exit /* %ebx: no swapgs flag */
19119 CFI_ENDPROC
19120-END(\sym)
19121+ENDPROC(\sym)
19122 .endm
19123
19124 zeroentry divide_error do_divide_error
19125@@ -1323,9 +1693,10 @@ gs_change:
19126 2: mfence /* workaround */
19127 SWAPGS
19128 popfq_cfi
19129+ pax_force_retaddr
19130 ret
19131 CFI_ENDPROC
19132-END(native_load_gs_index)
19133+ENDPROC(native_load_gs_index)
19134
19135 _ASM_EXTABLE(gs_change,bad_gs)
19136 .section .fixup,"ax"
19137@@ -1353,9 +1724,10 @@ ENTRY(call_softirq)
19138 CFI_DEF_CFA_REGISTER rsp
19139 CFI_ADJUST_CFA_OFFSET -8
19140 decl PER_CPU_VAR(irq_count)
19141+ pax_force_retaddr
19142 ret
19143 CFI_ENDPROC
19144-END(call_softirq)
19145+ENDPROC(call_softirq)
19146
19147 #ifdef CONFIG_XEN
19148 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
19149@@ -1393,7 +1765,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
19150 decl PER_CPU_VAR(irq_count)
19151 jmp error_exit
19152 CFI_ENDPROC
19153-END(xen_do_hypervisor_callback)
19154+ENDPROC(xen_do_hypervisor_callback)
19155
19156 /*
19157 * Hypervisor uses this for application faults while it executes.
19158@@ -1452,7 +1824,7 @@ ENTRY(xen_failsafe_callback)
19159 SAVE_ALL
19160 jmp error_exit
19161 CFI_ENDPROC
19162-END(xen_failsafe_callback)
19163+ENDPROC(xen_failsafe_callback)
19164
19165 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
19166 xen_hvm_callback_vector xen_evtchn_do_upcall
19167@@ -1501,16 +1873,31 @@ ENTRY(paranoid_exit)
19168 TRACE_IRQS_OFF_DEBUG
19169 testl %ebx,%ebx /* swapgs needed? */
19170 jnz paranoid_restore
19171- testl $3,CS(%rsp)
19172+ testb $3,CS(%rsp)
19173 jnz paranoid_userspace
19174+#ifdef CONFIG_PAX_MEMORY_UDEREF
19175+ pax_exit_kernel
19176+ TRACE_IRQS_IRETQ 0
19177+ SWAPGS_UNSAFE_STACK
19178+ RESTORE_ALL 8
19179+ pax_force_retaddr_bts
19180+ jmp irq_return
19181+#endif
19182 paranoid_swapgs:
19183+#ifdef CONFIG_PAX_MEMORY_UDEREF
19184+ pax_exit_kernel_user
19185+#else
19186+ pax_exit_kernel
19187+#endif
19188 TRACE_IRQS_IRETQ 0
19189 SWAPGS_UNSAFE_STACK
19190 RESTORE_ALL 8
19191 jmp irq_return
19192 paranoid_restore:
19193+ pax_exit_kernel
19194 TRACE_IRQS_IRETQ_DEBUG 0
19195 RESTORE_ALL 8
19196+ pax_force_retaddr_bts
19197 jmp irq_return
19198 paranoid_userspace:
19199 GET_THREAD_INFO(%rcx)
19200@@ -1539,7 +1926,7 @@ paranoid_schedule:
19201 TRACE_IRQS_OFF
19202 jmp paranoid_userspace
19203 CFI_ENDPROC
19204-END(paranoid_exit)
19205+ENDPROC(paranoid_exit)
19206
19207 /*
19208 * Exception entry point. This expects an error code/orig_rax on the stack.
19209@@ -1566,12 +1953,13 @@ ENTRY(error_entry)
19210 movq_cfi r14, R14+8
19211 movq_cfi r15, R15+8
19212 xorl %ebx,%ebx
19213- testl $3,CS+8(%rsp)
19214+ testb $3,CS+8(%rsp)
19215 je error_kernelspace
19216 error_swapgs:
19217 SWAPGS
19218 error_sti:
19219 TRACE_IRQS_OFF
19220+ pax_force_retaddr_bts
19221 ret
19222
19223 /*
19224@@ -1598,7 +1986,7 @@ bstep_iret:
19225 movq %rcx,RIP+8(%rsp)
19226 jmp error_swapgs
19227 CFI_ENDPROC
19228-END(error_entry)
19229+ENDPROC(error_entry)
19230
19231
19232 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
19233@@ -1618,7 +2006,7 @@ ENTRY(error_exit)
19234 jnz retint_careful
19235 jmp retint_swapgs
19236 CFI_ENDPROC
19237-END(error_exit)
19238+ENDPROC(error_exit)
19239
19240 /*
19241 * Test if a given stack is an NMI stack or not.
19242@@ -1676,9 +2064,11 @@ ENTRY(nmi)
19243 * If %cs was not the kernel segment, then the NMI triggered in user
19244 * space, which means it is definitely not nested.
19245 */
19246+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
19247+ je 1f
19248 cmpl $__KERNEL_CS, 16(%rsp)
19249 jne first_nmi
19250-
19251+1:
19252 /*
19253 * Check the special variable on the stack to see if NMIs are
19254 * executing.
19255@@ -1847,6 +2237,17 @@ end_repeat_nmi:
19256 */
19257 movq %cr2, %r12
19258
19259+#ifdef CONFIG_PAX_MEMORY_UDEREF
19260+ testb $3, CS(%rsp)
19261+ jnz 1f
19262+ pax_enter_kernel
19263+ jmp 2f
19264+1: pax_enter_kernel_user
19265+2:
19266+#else
19267+ pax_enter_kernel
19268+#endif
19269+
19270 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
19271 movq %rsp,%rdi
19272 movq $-1,%rsi
19273@@ -1862,23 +2263,34 @@ end_repeat_nmi:
19274 testl %ebx,%ebx /* swapgs needed? */
19275 jnz nmi_restore
19276 nmi_swapgs:
19277+#ifdef CONFIG_PAX_MEMORY_UDEREF
19278+ pax_exit_kernel_user
19279+#else
19280+ pax_exit_kernel
19281+#endif
19282 SWAPGS_UNSAFE_STACK
19283+ RESTORE_ALL 6*8
19284+ /* Clear the NMI executing stack variable */
19285+ movq $0, 5*8(%rsp)
19286+ jmp irq_return
19287 nmi_restore:
19288+ pax_exit_kernel
19289 /* Pop the extra iret frame at once */
19290 RESTORE_ALL 6*8
19291+ pax_force_retaddr_bts
19292
19293 /* Clear the NMI executing stack variable */
19294 movq $0, 5*8(%rsp)
19295 jmp irq_return
19296 CFI_ENDPROC
19297-END(nmi)
19298+ENDPROC(nmi)
19299
19300 ENTRY(ignore_sysret)
19301 CFI_STARTPROC
19302 mov $-ENOSYS,%eax
19303 sysret
19304 CFI_ENDPROC
19305-END(ignore_sysret)
19306+ENDPROC(ignore_sysret)
19307
19308 /*
19309 * End of kprobes section
19310diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
19311index 1d41402..af9a46a 100644
19312--- a/arch/x86/kernel/ftrace.c
19313+++ b/arch/x86/kernel/ftrace.c
19314@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
19315 {
19316 unsigned char replaced[MCOUNT_INSN_SIZE];
19317
19318+ ip = ktla_ktva(ip);
19319+
19320 /*
19321 * Note: Due to modules and __init, code can
19322 * disappear and change, we need to protect against faulting
19323@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
19324 unsigned char old[MCOUNT_INSN_SIZE], *new;
19325 int ret;
19326
19327- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
19328+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
19329 new = ftrace_call_replace(ip, (unsigned long)func);
19330
19331 /* See comment above by declaration of modifying_ftrace_code */
19332@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
19333 /* Also update the regs callback function */
19334 if (!ret) {
19335 ip = (unsigned long)(&ftrace_regs_call);
19336- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
19337+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
19338 new = ftrace_call_replace(ip, (unsigned long)func);
19339 ret = ftrace_modify_code(ip, old, new);
19340 }
19341@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
19342 * kernel identity mapping to modify code.
19343 */
19344 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
19345- ip = (unsigned long)__va(__pa(ip));
19346+ ip = (unsigned long)__va(__pa(ktla_ktva(ip)));
19347
19348 return probe_kernel_write((void *)ip, val, size);
19349 }
19350@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
19351 unsigned char replaced[MCOUNT_INSN_SIZE];
19352 unsigned char brk = BREAKPOINT_INSTRUCTION;
19353
19354- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
19355+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
19356 return -EFAULT;
19357
19358 /* Make sure it is what we expect it to be */
19359@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
19360 return ret;
19361
19362 fail_update:
19363- probe_kernel_write((void *)ip, &old_code[0], 1);
19364+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
19365 goto out;
19366 }
19367
19368@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
19369 {
19370 unsigned char code[MCOUNT_INSN_SIZE];
19371
19372+ ip = ktla_ktva(ip);
19373+
19374 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
19375 return -EFAULT;
19376
19377diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
19378index c18f59d..9c0c9f6 100644
19379--- a/arch/x86/kernel/head32.c
19380+++ b/arch/x86/kernel/head32.c
19381@@ -18,6 +18,7 @@
19382 #include <asm/io_apic.h>
19383 #include <asm/bios_ebda.h>
19384 #include <asm/tlbflush.h>
19385+#include <asm/boot.h>
19386
19387 static void __init i386_default_early_setup(void)
19388 {
19389@@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
19390
19391 void __init i386_start_kernel(void)
19392 {
19393- memblock_reserve(__pa_symbol(&_text),
19394- __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
19395+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
19396
19397 #ifdef CONFIG_BLK_DEV_INITRD
19398 /* Reserve INITRD */
19399diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
19400index c8932c7..d56b622 100644
19401--- a/arch/x86/kernel/head_32.S
19402+++ b/arch/x86/kernel/head_32.S
19403@@ -26,6 +26,12 @@
19404 /* Physical address */
19405 #define pa(X) ((X) - __PAGE_OFFSET)
19406
19407+#ifdef CONFIG_PAX_KERNEXEC
19408+#define ta(X) (X)
19409+#else
19410+#define ta(X) ((X) - __PAGE_OFFSET)
19411+#endif
19412+
19413 /*
19414 * References to members of the new_cpu_data structure.
19415 */
19416@@ -55,11 +61,7 @@
19417 * and small than max_low_pfn, otherwise will waste some page table entries
19418 */
19419
19420-#if PTRS_PER_PMD > 1
19421-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
19422-#else
19423-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
19424-#endif
19425+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
19426
19427 /* Number of possible pages in the lowmem region */
19428 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
19429@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
19430 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
19431
19432 /*
19433+ * Real beginning of normal "text" segment
19434+ */
19435+ENTRY(stext)
19436+ENTRY(_stext)
19437+
19438+/*
19439 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
19440 * %esi points to the real-mode code as a 32-bit pointer.
19441 * CS and DS must be 4 GB flat segments, but we don't depend on
19442@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
19443 * can.
19444 */
19445 __HEAD
19446+
19447+#ifdef CONFIG_PAX_KERNEXEC
19448+ jmp startup_32
19449+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
19450+.fill PAGE_SIZE-5,1,0xcc
19451+#endif
19452+
19453 ENTRY(startup_32)
19454 movl pa(stack_start),%ecx
19455
19456@@ -106,6 +121,59 @@ ENTRY(startup_32)
19457 2:
19458 leal -__PAGE_OFFSET(%ecx),%esp
19459
19460+#ifdef CONFIG_SMP
19461+ movl $pa(cpu_gdt_table),%edi
19462+ movl $__per_cpu_load,%eax
19463+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
19464+ rorl $16,%eax
19465+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
19466+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
19467+ movl $__per_cpu_end - 1,%eax
19468+ subl $__per_cpu_start,%eax
19469+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
19470+#endif
19471+
19472+#ifdef CONFIG_PAX_MEMORY_UDEREF
19473+ movl $NR_CPUS,%ecx
19474+ movl $pa(cpu_gdt_table),%edi
19475+1:
19476+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
19477+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
19478+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
19479+ addl $PAGE_SIZE_asm,%edi
19480+ loop 1b
19481+#endif
19482+
19483+#ifdef CONFIG_PAX_KERNEXEC
19484+ movl $pa(boot_gdt),%edi
19485+ movl $__LOAD_PHYSICAL_ADDR,%eax
19486+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
19487+ rorl $16,%eax
19488+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
19489+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
19490+ rorl $16,%eax
19491+
19492+ ljmp $(__BOOT_CS),$1f
19493+1:
19494+
19495+ movl $NR_CPUS,%ecx
19496+ movl $pa(cpu_gdt_table),%edi
19497+ addl $__PAGE_OFFSET,%eax
19498+1:
19499+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
19500+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
19501+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
19502+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
19503+ rorl $16,%eax
19504+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
19505+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
19506+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
19507+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
19508+ rorl $16,%eax
19509+ addl $PAGE_SIZE_asm,%edi
19510+ loop 1b
19511+#endif
19512+
19513 /*
19514 * Clear BSS first so that there are no surprises...
19515 */
19516@@ -196,8 +264,11 @@ ENTRY(startup_32)
19517 movl %eax, pa(max_pfn_mapped)
19518
19519 /* Do early initialization of the fixmap area */
19520- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
19521- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
19522+#ifdef CONFIG_COMPAT_VDSO
19523+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
19524+#else
19525+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
19526+#endif
19527 #else /* Not PAE */
19528
19529 page_pde_offset = (__PAGE_OFFSET >> 20);
19530@@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
19531 movl %eax, pa(max_pfn_mapped)
19532
19533 /* Do early initialization of the fixmap area */
19534- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
19535- movl %eax,pa(initial_page_table+0xffc)
19536+#ifdef CONFIG_COMPAT_VDSO
19537+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
19538+#else
19539+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
19540+#endif
19541 #endif
19542
19543 #ifdef CONFIG_PARAVIRT
19544@@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
19545 cmpl $num_subarch_entries, %eax
19546 jae bad_subarch
19547
19548- movl pa(subarch_entries)(,%eax,4), %eax
19549- subl $__PAGE_OFFSET, %eax
19550- jmp *%eax
19551+ jmp *pa(subarch_entries)(,%eax,4)
19552
19553 bad_subarch:
19554 WEAK(lguest_entry)
19555@@ -256,10 +328,10 @@ WEAK(xen_entry)
19556 __INITDATA
19557
19558 subarch_entries:
19559- .long default_entry /* normal x86/PC */
19560- .long lguest_entry /* lguest hypervisor */
19561- .long xen_entry /* Xen hypervisor */
19562- .long default_entry /* Moorestown MID */
19563+ .long ta(default_entry) /* normal x86/PC */
19564+ .long ta(lguest_entry) /* lguest hypervisor */
19565+ .long ta(xen_entry) /* Xen hypervisor */
19566+ .long ta(default_entry) /* Moorestown MID */
19567 num_subarch_entries = (. - subarch_entries) / 4
19568 .previous
19569 #else
19570@@ -335,6 +407,7 @@ default_entry:
19571 movl pa(mmu_cr4_features),%eax
19572 movl %eax,%cr4
19573
19574+#ifdef CONFIG_X86_PAE
19575 testb $X86_CR4_PAE, %al # check if PAE is enabled
19576 jz 6f
19577
19578@@ -363,6 +436,9 @@ default_entry:
19579 /* Make changes effective */
19580 wrmsr
19581
19582+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
19583+#endif
19584+
19585 6:
19586
19587 /*
19588@@ -460,14 +536,20 @@ is386: movl $2,%ecx # set MP
19589 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
19590 movl %eax,%ss # after changing gdt.
19591
19592- movl $(__USER_DS),%eax # DS/ES contains default USER segment
19593+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
19594 movl %eax,%ds
19595 movl %eax,%es
19596
19597 movl $(__KERNEL_PERCPU), %eax
19598 movl %eax,%fs # set this cpu's percpu
19599
19600+#ifdef CONFIG_CC_STACKPROTECTOR
19601 movl $(__KERNEL_STACK_CANARY),%eax
19602+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
19603+ movl $(__USER_DS),%eax
19604+#else
19605+ xorl %eax,%eax
19606+#endif
19607 movl %eax,%gs
19608
19609 xorl %eax,%eax # Clear LDT
19610@@ -544,8 +626,11 @@ setup_once:
19611 * relocation. Manually set base address in stack canary
19612 * segment descriptor.
19613 */
19614- movl $gdt_page,%eax
19615+ movl $cpu_gdt_table,%eax
19616 movl $stack_canary,%ecx
19617+#ifdef CONFIG_SMP
19618+ addl $__per_cpu_load,%ecx
19619+#endif
19620 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
19621 shrl $16, %ecx
19622 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
19623@@ -576,7 +661,7 @@ ENDPROC(early_idt_handlers)
19624 /* This is global to keep gas from relaxing the jumps */
19625 ENTRY(early_idt_handler)
19626 cld
19627- cmpl $2,%ss:early_recursion_flag
19628+ cmpl $1,%ss:early_recursion_flag
19629 je hlt_loop
19630 incl %ss:early_recursion_flag
19631
19632@@ -614,8 +699,8 @@ ENTRY(early_idt_handler)
19633 pushl (20+6*4)(%esp) /* trapno */
19634 pushl $fault_msg
19635 call printk
19636-#endif
19637 call dump_stack
19638+#endif
19639 hlt_loop:
19640 hlt
19641 jmp hlt_loop
19642@@ -634,8 +719,11 @@ ENDPROC(early_idt_handler)
19643 /* This is the default interrupt "handler" :-) */
19644 ALIGN
19645 ignore_int:
19646- cld
19647 #ifdef CONFIG_PRINTK
19648+ cmpl $2,%ss:early_recursion_flag
19649+ je hlt_loop
19650+ incl %ss:early_recursion_flag
19651+ cld
19652 pushl %eax
19653 pushl %ecx
19654 pushl %edx
19655@@ -644,9 +732,6 @@ ignore_int:
19656 movl $(__KERNEL_DS),%eax
19657 movl %eax,%ds
19658 movl %eax,%es
19659- cmpl $2,early_recursion_flag
19660- je hlt_loop
19661- incl early_recursion_flag
19662 pushl 16(%esp)
19663 pushl 24(%esp)
19664 pushl 32(%esp)
19665@@ -680,29 +765,43 @@ ENTRY(setup_once_ref)
19666 /*
19667 * BSS section
19668 */
19669-__PAGE_ALIGNED_BSS
19670- .align PAGE_SIZE
19671 #ifdef CONFIG_X86_PAE
19672+.section .initial_pg_pmd,"a",@progbits
19673 initial_pg_pmd:
19674 .fill 1024*KPMDS,4,0
19675 #else
19676+.section .initial_page_table,"a",@progbits
19677 ENTRY(initial_page_table)
19678 .fill 1024,4,0
19679 #endif
19680+.section .initial_pg_fixmap,"a",@progbits
19681 initial_pg_fixmap:
19682 .fill 1024,4,0
19683+.section .empty_zero_page,"a",@progbits
19684 ENTRY(empty_zero_page)
19685 .fill 4096,1,0
19686+.section .swapper_pg_dir,"a",@progbits
19687 ENTRY(swapper_pg_dir)
19688+#ifdef CONFIG_X86_PAE
19689+ .fill 4,8,0
19690+#else
19691 .fill 1024,4,0
19692+#endif
19693+
19694+/*
19695+ * The IDT has to be page-aligned to simplify the Pentium
19696+ * F0 0F bug workaround.. We have a special link segment
19697+ * for this.
19698+ */
19699+.section .idt,"a",@progbits
19700+ENTRY(idt_table)
19701+ .fill 256,8,0
19702
19703 /*
19704 * This starts the data section.
19705 */
19706 #ifdef CONFIG_X86_PAE
19707-__PAGE_ALIGNED_DATA
19708- /* Page-aligned for the benefit of paravirt? */
19709- .align PAGE_SIZE
19710+.section .initial_page_table,"a",@progbits
19711 ENTRY(initial_page_table)
19712 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
19713 # if KPMDS == 3
19714@@ -721,12 +820,20 @@ ENTRY(initial_page_table)
19715 # error "Kernel PMDs should be 1, 2 or 3"
19716 # endif
19717 .align PAGE_SIZE /* needs to be page-sized too */
19718+
19719+#ifdef CONFIG_PAX_PER_CPU_PGD
19720+ENTRY(cpu_pgd)
19721+ .rept NR_CPUS
19722+ .fill 4,8,0
19723+ .endr
19724+#endif
19725+
19726 #endif
19727
19728 .data
19729 .balign 4
19730 ENTRY(stack_start)
19731- .long init_thread_union+THREAD_SIZE
19732+ .long init_thread_union+THREAD_SIZE-8
19733
19734 __INITRODATA
19735 int_msg:
19736@@ -754,7 +861,7 @@ fault_msg:
19737 * segment size, and 32-bit linear address value:
19738 */
19739
19740- .data
19741+.section .rodata,"a",@progbits
19742 .globl boot_gdt_descr
19743 .globl idt_descr
19744
19745@@ -763,7 +870,7 @@ fault_msg:
19746 .word 0 # 32 bit align gdt_desc.address
19747 boot_gdt_descr:
19748 .word __BOOT_DS+7
19749- .long boot_gdt - __PAGE_OFFSET
19750+ .long pa(boot_gdt)
19751
19752 .word 0 # 32-bit align idt_desc.address
19753 idt_descr:
19754@@ -774,7 +881,7 @@ idt_descr:
19755 .word 0 # 32 bit align gdt_desc.address
19756 ENTRY(early_gdt_descr)
19757 .word GDT_ENTRIES*8-1
19758- .long gdt_page /* Overwritten for secondary CPUs */
19759+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
19760
19761 /*
19762 * The boot_gdt must mirror the equivalent in setup.S and is
19763@@ -783,5 +890,65 @@ ENTRY(early_gdt_descr)
19764 .align L1_CACHE_BYTES
19765 ENTRY(boot_gdt)
19766 .fill GDT_ENTRY_BOOT_CS,8,0
19767- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
19768- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
19769+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
19770+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
19771+
19772+ .align PAGE_SIZE_asm
19773+ENTRY(cpu_gdt_table)
19774+ .rept NR_CPUS
19775+ .quad 0x0000000000000000 /* NULL descriptor */
19776+ .quad 0x0000000000000000 /* 0x0b reserved */
19777+ .quad 0x0000000000000000 /* 0x13 reserved */
19778+ .quad 0x0000000000000000 /* 0x1b reserved */
19779+
19780+#ifdef CONFIG_PAX_KERNEXEC
19781+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
19782+#else
19783+ .quad 0x0000000000000000 /* 0x20 unused */
19784+#endif
19785+
19786+ .quad 0x0000000000000000 /* 0x28 unused */
19787+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
19788+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
19789+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
19790+ .quad 0x0000000000000000 /* 0x4b reserved */
19791+ .quad 0x0000000000000000 /* 0x53 reserved */
19792+ .quad 0x0000000000000000 /* 0x5b reserved */
19793+
19794+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
19795+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
19796+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
19797+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
19798+
19799+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
19800+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
19801+
19802+ /*
19803+ * Segments used for calling PnP BIOS have byte granularity.
19804+ * The code segments and data segments have fixed 64k limits,
19805+ * the transfer segment sizes are set at run time.
19806+ */
19807+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
19808+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
19809+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
19810+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
19811+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
19812+
19813+ /*
19814+ * The APM segments have byte granularity and their bases
19815+ * are set at run time. All have 64k limits.
19816+ */
19817+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
19818+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
19819+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
19820+
19821+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
19822+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
19823+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
19824+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
19825+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
19826+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
19827+
19828+ /* Be sure this is zeroed to avoid false validations in Xen */
19829+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
19830+ .endr
19831diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
19832index 980053c..74d3b44 100644
19833--- a/arch/x86/kernel/head_64.S
19834+++ b/arch/x86/kernel/head_64.S
19835@@ -20,6 +20,8 @@
19836 #include <asm/processor-flags.h>
19837 #include <asm/percpu.h>
19838 #include <asm/nops.h>
19839+#include <asm/cpufeature.h>
19840+#include <asm/alternative-asm.h>
19841
19842 #ifdef CONFIG_PARAVIRT
19843 #include <asm/asm-offsets.h>
19844@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
19845 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
19846 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
19847 L3_START_KERNEL = pud_index(__START_KERNEL_map)
19848+L4_VMALLOC_START = pgd_index(VMALLOC_START)
19849+L3_VMALLOC_START = pud_index(VMALLOC_START)
19850+L4_VMALLOC_END = pgd_index(VMALLOC_END)
19851+L3_VMALLOC_END = pud_index(VMALLOC_END)
19852+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
19853+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
19854
19855 .text
19856 __HEAD
19857@@ -88,35 +96,23 @@ startup_64:
19858 */
19859 addq %rbp, init_level4_pgt + 0(%rip)
19860 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
19861+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
19862+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
19863+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
19864 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
19865
19866 addq %rbp, level3_ident_pgt + 0(%rip)
19867+#ifndef CONFIG_XEN
19868+ addq %rbp, level3_ident_pgt + 8(%rip)
19869+#endif
19870
19871- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
19872- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
19873+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
19874+
19875+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
19876+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
19877
19878 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
19879-
19880- /* Add an Identity mapping if I am above 1G */
19881- leaq _text(%rip), %rdi
19882- andq $PMD_PAGE_MASK, %rdi
19883-
19884- movq %rdi, %rax
19885- shrq $PUD_SHIFT, %rax
19886- andq $(PTRS_PER_PUD - 1), %rax
19887- jz ident_complete
19888-
19889- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
19890- leaq level3_ident_pgt(%rip), %rbx
19891- movq %rdx, 0(%rbx, %rax, 8)
19892-
19893- movq %rdi, %rax
19894- shrq $PMD_SHIFT, %rax
19895- andq $(PTRS_PER_PMD - 1), %rax
19896- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
19897- leaq level2_spare_pgt(%rip), %rbx
19898- movq %rdx, 0(%rbx, %rax, 8)
19899-ident_complete:
19900+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
19901
19902 /*
19903 * Fixup the kernel text+data virtual addresses. Note that
19904@@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
19905 * after the boot processor executes this code.
19906 */
19907
19908- /* Enable PAE mode and PGE */
19909- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
19910+ /* Enable PAE mode and PSE/PGE */
19911+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
19912 movq %rax, %cr4
19913
19914 /* Setup early boot stage 4 level pagetables. */
19915@@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
19916 movl $MSR_EFER, %ecx
19917 rdmsr
19918 btsl $_EFER_SCE, %eax /* Enable System Call */
19919- btl $20,%edi /* No Execute supported? */
19920+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
19921 jnc 1f
19922 btsl $_EFER_NX, %eax
19923+ leaq init_level4_pgt(%rip), %rdi
19924+#ifndef CONFIG_EFI
19925+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
19926+#endif
19927+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
19928+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
19929+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
19930+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
19931 1: wrmsr /* Make changes effective */
19932
19933 /* Setup cr0 */
19934@@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
19935 * jump. In addition we need to ensure %cs is set so we make this
19936 * a far return.
19937 */
19938+ pax_set_fptr_mask
19939 movq initial_code(%rip),%rax
19940 pushq $0 # fake return address to stop unwinder
19941 pushq $__KERNEL_CS # set correct cs
19942@@ -284,7 +289,7 @@ ENDPROC(start_cpu0)
19943 bad_address:
19944 jmp bad_address
19945
19946- .section ".init.text","ax"
19947+ __INIT
19948 .globl early_idt_handlers
19949 early_idt_handlers:
19950 # 104(%rsp) %rflags
19951@@ -343,7 +348,7 @@ ENTRY(early_idt_handler)
19952 call dump_stack
19953 #ifdef CONFIG_KALLSYMS
19954 leaq early_idt_ripmsg(%rip),%rdi
19955- movq 40(%rsp),%rsi # %rip again
19956+ movq 88(%rsp),%rsi # %rip again
19957 call __print_symbol
19958 #endif
19959 #endif /* EARLY_PRINTK */
19960@@ -363,11 +368,15 @@ ENTRY(early_idt_handler)
19961 addq $16,%rsp # drop vector number and error code
19962 decl early_recursion_flag(%rip)
19963 INTERRUPT_RETURN
19964+ .previous
19965
19966+ __INITDATA
19967 .balign 4
19968 early_recursion_flag:
19969 .long 0
19970+ .previous
19971
19972+ .section .rodata,"a",@progbits
19973 #ifdef CONFIG_EARLY_PRINTK
19974 early_idt_msg:
19975 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
19976@@ -376,6 +385,7 @@ early_idt_ripmsg:
19977 #endif /* CONFIG_EARLY_PRINTK */
19978 .previous
19979
19980+ .section .rodata,"a",@progbits
19981 #define NEXT_PAGE(name) \
19982 .balign PAGE_SIZE; \
19983 ENTRY(name)
19984@@ -388,7 +398,6 @@ ENTRY(name)
19985 i = i + 1 ; \
19986 .endr
19987
19988- .data
19989 /*
19990 * This default setting generates an ident mapping at address 0x100000
19991 * and a mapping for the kernel that precisely maps virtual address
19992@@ -399,13 +408,41 @@ NEXT_PAGE(init_level4_pgt)
19993 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
19994 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
19995 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
19996+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
19997+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
19998+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
19999+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
20000+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
20001+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20002 .org init_level4_pgt + L4_START_KERNEL*8, 0
20003 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
20004 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
20005
20006+#ifdef CONFIG_PAX_PER_CPU_PGD
20007+NEXT_PAGE(cpu_pgd)
20008+ .rept NR_CPUS
20009+ .fill 512,8,0
20010+ .endr
20011+#endif
20012+
20013 NEXT_PAGE(level3_ident_pgt)
20014 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20015+#ifdef CONFIG_XEN
20016 .fill 511,8,0
20017+#else
20018+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
20019+ .fill 510,8,0
20020+#endif
20021+
20022+NEXT_PAGE(level3_vmalloc_start_pgt)
20023+ .fill 512,8,0
20024+
20025+NEXT_PAGE(level3_vmalloc_end_pgt)
20026+ .fill 512,8,0
20027+
20028+NEXT_PAGE(level3_vmemmap_pgt)
20029+ .fill L3_VMEMMAP_START,8,0
20030+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20031
20032 NEXT_PAGE(level3_kernel_pgt)
20033 .fill L3_START_KERNEL,8,0
20034@@ -413,20 +450,23 @@ NEXT_PAGE(level3_kernel_pgt)
20035 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
20036 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20037
20038+NEXT_PAGE(level2_vmemmap_pgt)
20039+ .fill 512,8,0
20040+
20041 NEXT_PAGE(level2_fixmap_pgt)
20042- .fill 506,8,0
20043- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20044- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
20045- .fill 5,8,0
20046+ .fill 507,8,0
20047+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
20048+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
20049+ .fill 4,8,0
20050
20051-NEXT_PAGE(level1_fixmap_pgt)
20052+NEXT_PAGE(level1_vsyscall_pgt)
20053 .fill 512,8,0
20054
20055-NEXT_PAGE(level2_ident_pgt)
20056- /* Since I easily can, map the first 1G.
20057+ /* Since I easily can, map the first 2G.
20058 * Don't set NX because code runs from these pages.
20059 */
20060- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
20061+NEXT_PAGE(level2_ident_pgt)
20062+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
20063
20064 NEXT_PAGE(level2_kernel_pgt)
20065 /*
20066@@ -439,37 +479,59 @@ NEXT_PAGE(level2_kernel_pgt)
20067 * If you want to increase this then increase MODULES_VADDR
20068 * too.)
20069 */
20070- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
20071- KERNEL_IMAGE_SIZE/PMD_SIZE)
20072-
20073-NEXT_PAGE(level2_spare_pgt)
20074- .fill 512, 8, 0
20075+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
20076
20077 #undef PMDS
20078 #undef NEXT_PAGE
20079
20080- .data
20081+ .align PAGE_SIZE
20082+ENTRY(cpu_gdt_table)
20083+ .rept NR_CPUS
20084+ .quad 0x0000000000000000 /* NULL descriptor */
20085+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
20086+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
20087+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
20088+ .quad 0x00cffb000000ffff /* __USER32_CS */
20089+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
20090+ .quad 0x00affb000000ffff /* __USER_CS */
20091+
20092+#ifdef CONFIG_PAX_KERNEXEC
20093+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
20094+#else
20095+ .quad 0x0 /* unused */
20096+#endif
20097+
20098+ .quad 0,0 /* TSS */
20099+ .quad 0,0 /* LDT */
20100+ .quad 0,0,0 /* three TLS descriptors */
20101+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
20102+ /* asm/segment.h:GDT_ENTRIES must match this */
20103+
20104+ /* zero the remaining page */
20105+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
20106+ .endr
20107+
20108 .align 16
20109 .globl early_gdt_descr
20110 early_gdt_descr:
20111 .word GDT_ENTRIES*8-1
20112 early_gdt_descr_base:
20113- .quad INIT_PER_CPU_VAR(gdt_page)
20114+ .quad cpu_gdt_table
20115
20116 ENTRY(phys_base)
20117 /* This must match the first entry in level2_kernel_pgt */
20118 .quad 0x0000000000000000
20119
20120 #include "../../x86/xen/xen-head.S"
20121-
20122- .section .bss, "aw", @nobits
20123+
20124+ .section .rodata,"a",@progbits
20125 .align L1_CACHE_BYTES
20126 ENTRY(idt_table)
20127- .skip IDT_ENTRIES * 16
20128+ .fill 512,8,0
20129
20130 .align L1_CACHE_BYTES
20131 ENTRY(nmi_idt_table)
20132- .skip IDT_ENTRIES * 16
20133+ .fill 512,8,0
20134
20135 __PAGE_ALIGNED_BSS
20136 .align PAGE_SIZE
20137diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
20138index 9c3bd4a..e1d9b35 100644
20139--- a/arch/x86/kernel/i386_ksyms_32.c
20140+++ b/arch/x86/kernel/i386_ksyms_32.c
20141@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
20142 EXPORT_SYMBOL(cmpxchg8b_emu);
20143 #endif
20144
20145+EXPORT_SYMBOL_GPL(cpu_gdt_table);
20146+
20147 /* Networking helper routines. */
20148 EXPORT_SYMBOL(csum_partial_copy_generic);
20149+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
20150+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
20151
20152 EXPORT_SYMBOL(__get_user_1);
20153 EXPORT_SYMBOL(__get_user_2);
20154@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
20155
20156 EXPORT_SYMBOL(csum_partial);
20157 EXPORT_SYMBOL(empty_zero_page);
20158+
20159+#ifdef CONFIG_PAX_KERNEXEC
20160+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
20161+#endif
20162diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
20163index 245a71d..89d9ce4 100644
20164--- a/arch/x86/kernel/i387.c
20165+++ b/arch/x86/kernel/i387.c
20166@@ -55,7 +55,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
20167 static inline bool interrupted_user_mode(void)
20168 {
20169 struct pt_regs *regs = get_irq_regs();
20170- return regs && user_mode_vm(regs);
20171+ return regs && user_mode(regs);
20172 }
20173
20174 /*
20175diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
20176index 9a5c460..dc4374d 100644
20177--- a/arch/x86/kernel/i8259.c
20178+++ b/arch/x86/kernel/i8259.c
20179@@ -209,7 +209,7 @@ spurious_8259A_irq:
20180 "spurious 8259A interrupt: IRQ%d.\n", irq);
20181 spurious_irq_mask |= irqmask;
20182 }
20183- atomic_inc(&irq_err_count);
20184+ atomic_inc_unchecked(&irq_err_count);
20185 /*
20186 * Theoretically we do not have to handle this IRQ,
20187 * but in Linux this does not cause problems and is
20188diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
20189index 8c96897..be66bfa 100644
20190--- a/arch/x86/kernel/ioport.c
20191+++ b/arch/x86/kernel/ioport.c
20192@@ -6,6 +6,7 @@
20193 #include <linux/sched.h>
20194 #include <linux/kernel.h>
20195 #include <linux/capability.h>
20196+#include <linux/security.h>
20197 #include <linux/errno.h>
20198 #include <linux/types.h>
20199 #include <linux/ioport.h>
20200@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20201
20202 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
20203 return -EINVAL;
20204+#ifdef CONFIG_GRKERNSEC_IO
20205+ if (turn_on && grsec_disable_privio) {
20206+ gr_handle_ioperm();
20207+ return -EPERM;
20208+ }
20209+#endif
20210 if (turn_on && !capable(CAP_SYS_RAWIO))
20211 return -EPERM;
20212
20213@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20214 * because the ->io_bitmap_max value must match the bitmap
20215 * contents:
20216 */
20217- tss = &per_cpu(init_tss, get_cpu());
20218+ tss = init_tss + get_cpu();
20219
20220 if (turn_on)
20221 bitmap_clear(t->io_bitmap_ptr, from, num);
20222@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
20223 return -EINVAL;
20224 /* Trying to gain more privileges? */
20225 if (level > old) {
20226+#ifdef CONFIG_GRKERNSEC_IO
20227+ if (grsec_disable_privio) {
20228+ gr_handle_iopl();
20229+ return -EPERM;
20230+ }
20231+#endif
20232 if (!capable(CAP_SYS_RAWIO))
20233 return -EPERM;
20234 }
20235diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
20236index e4595f1..ee3bfb8 100644
20237--- a/arch/x86/kernel/irq.c
20238+++ b/arch/x86/kernel/irq.c
20239@@ -18,7 +18,7 @@
20240 #include <asm/mce.h>
20241 #include <asm/hw_irq.h>
20242
20243-atomic_t irq_err_count;
20244+atomic_unchecked_t irq_err_count;
20245
20246 /* Function pointer for generic interrupt vector handling */
20247 void (*x86_platform_ipi_callback)(void) = NULL;
20248@@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
20249 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
20250 seq_printf(p, " Machine check polls\n");
20251 #endif
20252- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
20253+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
20254 #if defined(CONFIG_X86_IO_APIC)
20255- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
20256+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
20257 #endif
20258 return 0;
20259 }
20260@@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
20261
20262 u64 arch_irq_stat(void)
20263 {
20264- u64 sum = atomic_read(&irq_err_count);
20265+ u64 sum = atomic_read_unchecked(&irq_err_count);
20266
20267 #ifdef CONFIG_X86_IO_APIC
20268- sum += atomic_read(&irq_mis_count);
20269+ sum += atomic_read_unchecked(&irq_mis_count);
20270 #endif
20271 return sum;
20272 }
20273diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
20274index 344faf8..355f60d 100644
20275--- a/arch/x86/kernel/irq_32.c
20276+++ b/arch/x86/kernel/irq_32.c
20277@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
20278 __asm__ __volatile__("andl %%esp,%0" :
20279 "=r" (sp) : "0" (THREAD_SIZE - 1));
20280
20281- return sp < (sizeof(struct thread_info) + STACK_WARN);
20282+ return sp < STACK_WARN;
20283 }
20284
20285 static void print_stack_overflow(void)
20286@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
20287 * per-CPU IRQ handling contexts (thread information and stack)
20288 */
20289 union irq_ctx {
20290- struct thread_info tinfo;
20291- u32 stack[THREAD_SIZE/sizeof(u32)];
20292+ unsigned long previous_esp;
20293+ u32 stack[THREAD_SIZE/sizeof(u32)];
20294 } __attribute__((aligned(THREAD_SIZE)));
20295
20296 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
20297@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
20298 static inline int
20299 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20300 {
20301- union irq_ctx *curctx, *irqctx;
20302+ union irq_ctx *irqctx;
20303 u32 *isp, arg1, arg2;
20304
20305- curctx = (union irq_ctx *) current_thread_info();
20306 irqctx = __this_cpu_read(hardirq_ctx);
20307
20308 /*
20309@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20310 * handler) we can't do that and just have to keep using the
20311 * current stack (which is the irq stack already after all)
20312 */
20313- if (unlikely(curctx == irqctx))
20314+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
20315 return 0;
20316
20317 /* build the stack frame on the IRQ stack */
20318- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
20319- irqctx->tinfo.task = curctx->tinfo.task;
20320- irqctx->tinfo.previous_esp = current_stack_pointer;
20321+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
20322+ irqctx->previous_esp = current_stack_pointer;
20323
20324- /* Copy the preempt_count so that the [soft]irq checks work. */
20325- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
20326+#ifdef CONFIG_PAX_MEMORY_UDEREF
20327+ __set_fs(MAKE_MM_SEG(0));
20328+#endif
20329
20330 if (unlikely(overflow))
20331 call_on_stack(print_stack_overflow, isp);
20332@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20333 : "0" (irq), "1" (desc), "2" (isp),
20334 "D" (desc->handle_irq)
20335 : "memory", "cc", "ecx");
20336+
20337+#ifdef CONFIG_PAX_MEMORY_UDEREF
20338+ __set_fs(current_thread_info()->addr_limit);
20339+#endif
20340+
20341 return 1;
20342 }
20343
20344@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20345 */
20346 void __cpuinit irq_ctx_init(int cpu)
20347 {
20348- union irq_ctx *irqctx;
20349-
20350 if (per_cpu(hardirq_ctx, cpu))
20351 return;
20352
20353- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
20354- THREADINFO_GFP,
20355- THREAD_SIZE_ORDER));
20356- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
20357- irqctx->tinfo.cpu = cpu;
20358- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
20359- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
20360-
20361- per_cpu(hardirq_ctx, cpu) = irqctx;
20362-
20363- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
20364- THREADINFO_GFP,
20365- THREAD_SIZE_ORDER));
20366- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
20367- irqctx->tinfo.cpu = cpu;
20368- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
20369-
20370- per_cpu(softirq_ctx, cpu) = irqctx;
20371+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
20372+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
20373+
20374+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
20375+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
20376
20377 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
20378 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
20379@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
20380 asmlinkage void do_softirq(void)
20381 {
20382 unsigned long flags;
20383- struct thread_info *curctx;
20384 union irq_ctx *irqctx;
20385 u32 *isp;
20386
20387@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
20388 local_irq_save(flags);
20389
20390 if (local_softirq_pending()) {
20391- curctx = current_thread_info();
20392 irqctx = __this_cpu_read(softirq_ctx);
20393- irqctx->tinfo.task = curctx->task;
20394- irqctx->tinfo.previous_esp = current_stack_pointer;
20395+ irqctx->previous_esp = current_stack_pointer;
20396
20397 /* build the stack frame on the softirq stack */
20398- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
20399+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
20400+
20401+#ifdef CONFIG_PAX_MEMORY_UDEREF
20402+ __set_fs(MAKE_MM_SEG(0));
20403+#endif
20404
20405 call_on_stack(__do_softirq, isp);
20406+
20407+#ifdef CONFIG_PAX_MEMORY_UDEREF
20408+ __set_fs(current_thread_info()->addr_limit);
20409+#endif
20410+
20411 /*
20412 * Shouldn't happen, we returned above if in_interrupt():
20413 */
20414@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
20415 if (unlikely(!desc))
20416 return false;
20417
20418- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
20419+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
20420 if (unlikely(overflow))
20421 print_stack_overflow();
20422 desc->handle_irq(irq, desc);
20423diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
20424index d04d3ec..ea4b374 100644
20425--- a/arch/x86/kernel/irq_64.c
20426+++ b/arch/x86/kernel/irq_64.c
20427@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
20428 u64 estack_top, estack_bottom;
20429 u64 curbase = (u64)task_stack_page(current);
20430
20431- if (user_mode_vm(regs))
20432+ if (user_mode(regs))
20433 return;
20434
20435 if (regs->sp >= curbase + sizeof(struct thread_info) +
20436diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
20437index dc1404b..bbc43e7 100644
20438--- a/arch/x86/kernel/kdebugfs.c
20439+++ b/arch/x86/kernel/kdebugfs.c
20440@@ -27,7 +27,7 @@ struct setup_data_node {
20441 u32 len;
20442 };
20443
20444-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
20445+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
20446 size_t count, loff_t *ppos)
20447 {
20448 struct setup_data_node *node = file->private_data;
20449diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
20450index 836f832..a8bda67 100644
20451--- a/arch/x86/kernel/kgdb.c
20452+++ b/arch/x86/kernel/kgdb.c
20453@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
20454 #ifdef CONFIG_X86_32
20455 switch (regno) {
20456 case GDB_SS:
20457- if (!user_mode_vm(regs))
20458+ if (!user_mode(regs))
20459 *(unsigned long *)mem = __KERNEL_DS;
20460 break;
20461 case GDB_SP:
20462- if (!user_mode_vm(regs))
20463+ if (!user_mode(regs))
20464 *(unsigned long *)mem = kernel_stack_pointer(regs);
20465 break;
20466 case GDB_GS:
20467@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
20468 bp->attr.bp_addr = breakinfo[breakno].addr;
20469 bp->attr.bp_len = breakinfo[breakno].len;
20470 bp->attr.bp_type = breakinfo[breakno].type;
20471- info->address = breakinfo[breakno].addr;
20472+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
20473+ info->address = ktla_ktva(breakinfo[breakno].addr);
20474+ else
20475+ info->address = breakinfo[breakno].addr;
20476 info->len = breakinfo[breakno].len;
20477 info->type = breakinfo[breakno].type;
20478 val = arch_install_hw_breakpoint(bp);
20479@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
20480 case 'k':
20481 /* clear the trace bit */
20482 linux_regs->flags &= ~X86_EFLAGS_TF;
20483- atomic_set(&kgdb_cpu_doing_single_step, -1);
20484+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
20485
20486 /* set the trace bit if we're stepping */
20487 if (remcomInBuffer[0] == 's') {
20488 linux_regs->flags |= X86_EFLAGS_TF;
20489- atomic_set(&kgdb_cpu_doing_single_step,
20490+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
20491 raw_smp_processor_id());
20492 }
20493
20494@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
20495
20496 switch (cmd) {
20497 case DIE_DEBUG:
20498- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
20499+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
20500 if (user_mode(regs))
20501 return single_step_cont(regs, args);
20502 break;
20503@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
20504 #endif /* CONFIG_DEBUG_RODATA */
20505
20506 bpt->type = BP_BREAKPOINT;
20507- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
20508+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
20509 BREAK_INSTR_SIZE);
20510 if (err)
20511 return err;
20512- err = probe_kernel_write((char *)bpt->bpt_addr,
20513+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
20514 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
20515 #ifdef CONFIG_DEBUG_RODATA
20516 if (!err)
20517@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
20518 return -EBUSY;
20519 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
20520 BREAK_INSTR_SIZE);
20521- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
20522+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
20523 if (err)
20524 return err;
20525 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
20526@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
20527 if (mutex_is_locked(&text_mutex))
20528 goto knl_write;
20529 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
20530- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
20531+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
20532 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
20533 goto knl_write;
20534 return err;
20535 knl_write:
20536 #endif /* CONFIG_DEBUG_RODATA */
20537- return probe_kernel_write((char *)bpt->bpt_addr,
20538+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
20539 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
20540 }
20541
20542diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
20543index c5e410e..ed5a7f0 100644
20544--- a/arch/x86/kernel/kprobes-opt.c
20545+++ b/arch/x86/kernel/kprobes-opt.c
20546@@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
20547 * Verify if the address gap is in 2GB range, because this uses
20548 * a relative jump.
20549 */
20550- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
20551+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
20552 if (abs(rel) > 0x7fffffff)
20553 return -ERANGE;
20554
20555@@ -353,16 +353,16 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
20556 op->optinsn.size = ret;
20557
20558 /* Copy arch-dep-instance from template */
20559- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
20560+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
20561
20562 /* Set probe information */
20563 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
20564
20565 /* Set probe function call */
20566- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
20567+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
20568
20569 /* Set returning jmp instruction at the tail of out-of-line buffer */
20570- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
20571+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
20572 (u8 *)op->kp.addr + op->optinsn.size);
20573
20574 flush_icache_range((unsigned long) buf,
20575@@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
20576 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
20577
20578 /* Backup instructions which will be replaced by jump address */
20579- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
20580+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
20581 RELATIVE_ADDR_SIZE);
20582
20583 insn_buf[0] = RELATIVEJUMP_OPCODE;
20584@@ -483,7 +483,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
20585 /* This kprobe is really able to run optimized path. */
20586 op = container_of(p, struct optimized_kprobe, kp);
20587 /* Detour through copied instructions */
20588- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
20589+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
20590 if (!reenter)
20591 reset_current_kprobe();
20592 preempt_enable_no_resched();
20593diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
20594index 57916c0..9e0b9d0 100644
20595--- a/arch/x86/kernel/kprobes.c
20596+++ b/arch/x86/kernel/kprobes.c
20597@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
20598 s32 raddr;
20599 } __attribute__((packed)) *insn;
20600
20601- insn = (struct __arch_relative_insn *)from;
20602+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
20603+
20604+ pax_open_kernel();
20605 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
20606 insn->op = op;
20607+ pax_close_kernel();
20608 }
20609
20610 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
20611@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
20612 kprobe_opcode_t opcode;
20613 kprobe_opcode_t *orig_opcodes = opcodes;
20614
20615- if (search_exception_tables((unsigned long)opcodes))
20616+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
20617 return 0; /* Page fault may occur on this address. */
20618
20619 retry:
20620@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
20621 * for the first byte, we can recover the original instruction
20622 * from it and kp->opcode.
20623 */
20624- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
20625+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
20626 buf[0] = kp->opcode;
20627- return (unsigned long)buf;
20628+ return ktva_ktla((unsigned long)buf);
20629 }
20630
20631 /*
20632@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
20633 /* Another subsystem puts a breakpoint, failed to recover */
20634 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
20635 return 0;
20636+ pax_open_kernel();
20637 memcpy(dest, insn.kaddr, insn.length);
20638+ pax_close_kernel();
20639
20640 #ifdef CONFIG_X86_64
20641 if (insn_rip_relative(&insn)) {
20642@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
20643 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
20644 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
20645 disp = (u8 *) dest + insn_offset_displacement(&insn);
20646+ pax_open_kernel();
20647 *(s32 *) disp = (s32) newdisp;
20648+ pax_close_kernel();
20649 }
20650 #endif
20651 return insn.length;
20652@@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
20653 * nor set current_kprobe, because it doesn't use single
20654 * stepping.
20655 */
20656- regs->ip = (unsigned long)p->ainsn.insn;
20657+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
20658 preempt_enable_no_resched();
20659 return;
20660 }
20661@@ -502,9 +509,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
20662 regs->flags &= ~X86_EFLAGS_IF;
20663 /* single step inline if the instruction is an int3 */
20664 if (p->opcode == BREAKPOINT_INSTRUCTION)
20665- regs->ip = (unsigned long)p->addr;
20666+ regs->ip = ktla_ktva((unsigned long)p->addr);
20667 else
20668- regs->ip = (unsigned long)p->ainsn.insn;
20669+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
20670 }
20671
20672 /*
20673@@ -600,7 +607,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
20674 setup_singlestep(p, regs, kcb, 0);
20675 return 1;
20676 }
20677- } else if (*addr != BREAKPOINT_INSTRUCTION) {
20678+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
20679 /*
20680 * The breakpoint instruction was removed right
20681 * after we hit it. Another cpu has removed
20682@@ -651,6 +658,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
20683 " movq %rax, 152(%rsp)\n"
20684 RESTORE_REGS_STRING
20685 " popfq\n"
20686+#ifdef KERNEXEC_PLUGIN
20687+ " btsq $63,(%rsp)\n"
20688+#endif
20689 #else
20690 " pushf\n"
20691 SAVE_REGS_STRING
20692@@ -788,7 +798,7 @@ static void __kprobes
20693 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
20694 {
20695 unsigned long *tos = stack_addr(regs);
20696- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
20697+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
20698 unsigned long orig_ip = (unsigned long)p->addr;
20699 kprobe_opcode_t *insn = p->ainsn.insn;
20700
20701@@ -970,7 +980,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
20702 struct die_args *args = data;
20703 int ret = NOTIFY_DONE;
20704
20705- if (args->regs && user_mode_vm(args->regs))
20706+ if (args->regs && user_mode(args->regs))
20707 return ret;
20708
20709 switch (val) {
20710diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
20711index 9c2bd8b..bb1131c 100644
20712--- a/arch/x86/kernel/kvm.c
20713+++ b/arch/x86/kernel/kvm.c
20714@@ -452,7 +452,7 @@ static int __cpuinit kvm_cpu_notify(struct notifier_block *self,
20715 return NOTIFY_OK;
20716 }
20717
20718-static struct notifier_block __cpuinitdata kvm_cpu_notifier = {
20719+static struct notifier_block kvm_cpu_notifier = {
20720 .notifier_call = kvm_cpu_notify,
20721 };
20722 #endif
20723diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
20724index ebc9873..1b9724b 100644
20725--- a/arch/x86/kernel/ldt.c
20726+++ b/arch/x86/kernel/ldt.c
20727@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
20728 if (reload) {
20729 #ifdef CONFIG_SMP
20730 preempt_disable();
20731- load_LDT(pc);
20732+ load_LDT_nolock(pc);
20733 if (!cpumask_equal(mm_cpumask(current->mm),
20734 cpumask_of(smp_processor_id())))
20735 smp_call_function(flush_ldt, current->mm, 1);
20736 preempt_enable();
20737 #else
20738- load_LDT(pc);
20739+ load_LDT_nolock(pc);
20740 #endif
20741 }
20742 if (oldsize) {
20743@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
20744 return err;
20745
20746 for (i = 0; i < old->size; i++)
20747- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
20748+ write_ldt_entry(new->ldt, i, old->ldt + i);
20749 return 0;
20750 }
20751
20752@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
20753 retval = copy_ldt(&mm->context, &old_mm->context);
20754 mutex_unlock(&old_mm->context.lock);
20755 }
20756+
20757+ if (tsk == current) {
20758+ mm->context.vdso = 0;
20759+
20760+#ifdef CONFIG_X86_32
20761+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
20762+ mm->context.user_cs_base = 0UL;
20763+ mm->context.user_cs_limit = ~0UL;
20764+
20765+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
20766+ cpus_clear(mm->context.cpu_user_cs_mask);
20767+#endif
20768+
20769+#endif
20770+#endif
20771+
20772+ }
20773+
20774 return retval;
20775 }
20776
20777@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
20778 }
20779 }
20780
20781+#ifdef CONFIG_PAX_SEGMEXEC
20782+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
20783+ error = -EINVAL;
20784+ goto out_unlock;
20785+ }
20786+#endif
20787+
20788 fill_ldt(&ldt, &ldt_info);
20789 if (oldmode)
20790 ldt.avl = 0;
20791diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
20792index 5b19e4d..6476a76 100644
20793--- a/arch/x86/kernel/machine_kexec_32.c
20794+++ b/arch/x86/kernel/machine_kexec_32.c
20795@@ -26,7 +26,7 @@
20796 #include <asm/cacheflush.h>
20797 #include <asm/debugreg.h>
20798
20799-static void set_idt(void *newidt, __u16 limit)
20800+static void set_idt(struct desc_struct *newidt, __u16 limit)
20801 {
20802 struct desc_ptr curidt;
20803
20804@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
20805 }
20806
20807
20808-static void set_gdt(void *newgdt, __u16 limit)
20809+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
20810 {
20811 struct desc_ptr curgdt;
20812
20813@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
20814 }
20815
20816 control_page = page_address(image->control_code_page);
20817- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
20818+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
20819
20820 relocate_kernel_ptr = control_page;
20821 page_list[PA_CONTROL_PAGE] = __pa(control_page);
20822diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
20823index 3a04b22..1d2eb09 100644
20824--- a/arch/x86/kernel/microcode_core.c
20825+++ b/arch/x86/kernel/microcode_core.c
20826@@ -512,7 +512,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
20827 return NOTIFY_OK;
20828 }
20829
20830-static struct notifier_block __refdata mc_cpu_notifier = {
20831+static struct notifier_block mc_cpu_notifier = {
20832 .notifier_call = mc_cpu_callback,
20833 };
20834
20835diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
20836index 3544aed..01ddc1c 100644
20837--- a/arch/x86/kernel/microcode_intel.c
20838+++ b/arch/x86/kernel/microcode_intel.c
20839@@ -431,13 +431,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
20840
20841 static int get_ucode_user(void *to, const void *from, size_t n)
20842 {
20843- return copy_from_user(to, from, n);
20844+ return copy_from_user(to, (const void __force_user *)from, n);
20845 }
20846
20847 static enum ucode_state
20848 request_microcode_user(int cpu, const void __user *buf, size_t size)
20849 {
20850- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
20851+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
20852 }
20853
20854 static void microcode_fini_cpu(int cpu)
20855diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
20856index 216a4d7..228255a 100644
20857--- a/arch/x86/kernel/module.c
20858+++ b/arch/x86/kernel/module.c
20859@@ -43,15 +43,60 @@ do { \
20860 } while (0)
20861 #endif
20862
20863-void *module_alloc(unsigned long size)
20864+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
20865 {
20866- if (PAGE_ALIGN(size) > MODULES_LEN)
20867+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
20868 return NULL;
20869 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
20870- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
20871+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
20872 -1, __builtin_return_address(0));
20873 }
20874
20875+void *module_alloc(unsigned long size)
20876+{
20877+
20878+#ifdef CONFIG_PAX_KERNEXEC
20879+ return __module_alloc(size, PAGE_KERNEL);
20880+#else
20881+ return __module_alloc(size, PAGE_KERNEL_EXEC);
20882+#endif
20883+
20884+}
20885+
20886+#ifdef CONFIG_PAX_KERNEXEC
20887+#ifdef CONFIG_X86_32
20888+void *module_alloc_exec(unsigned long size)
20889+{
20890+ struct vm_struct *area;
20891+
20892+ if (size == 0)
20893+ return NULL;
20894+
20895+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
20896+ return area ? area->addr : NULL;
20897+}
20898+EXPORT_SYMBOL(module_alloc_exec);
20899+
20900+void module_free_exec(struct module *mod, void *module_region)
20901+{
20902+ vunmap(module_region);
20903+}
20904+EXPORT_SYMBOL(module_free_exec);
20905+#else
20906+void module_free_exec(struct module *mod, void *module_region)
20907+{
20908+ module_free(mod, module_region);
20909+}
20910+EXPORT_SYMBOL(module_free_exec);
20911+
20912+void *module_alloc_exec(unsigned long size)
20913+{
20914+ return __module_alloc(size, PAGE_KERNEL_RX);
20915+}
20916+EXPORT_SYMBOL(module_alloc_exec);
20917+#endif
20918+#endif
20919+
20920 #ifdef CONFIG_X86_32
20921 int apply_relocate(Elf32_Shdr *sechdrs,
20922 const char *strtab,
20923@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
20924 unsigned int i;
20925 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
20926 Elf32_Sym *sym;
20927- uint32_t *location;
20928+ uint32_t *plocation, location;
20929
20930 DEBUGP("Applying relocate section %u to %u\n",
20931 relsec, sechdrs[relsec].sh_info);
20932 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
20933 /* This is where to make the change */
20934- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
20935- + rel[i].r_offset;
20936+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
20937+ location = (uint32_t)plocation;
20938+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
20939+ plocation = ktla_ktva((void *)plocation);
20940 /* This is the symbol it is referring to. Note that all
20941 undefined symbols have been resolved. */
20942 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
20943@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
20944 switch (ELF32_R_TYPE(rel[i].r_info)) {
20945 case R_386_32:
20946 /* We add the value into the location given */
20947- *location += sym->st_value;
20948+ pax_open_kernel();
20949+ *plocation += sym->st_value;
20950+ pax_close_kernel();
20951 break;
20952 case R_386_PC32:
20953 /* Add the value, subtract its position */
20954- *location += sym->st_value - (uint32_t)location;
20955+ pax_open_kernel();
20956+ *plocation += sym->st_value - location;
20957+ pax_close_kernel();
20958 break;
20959 default:
20960 pr_err("%s: Unknown relocation: %u\n",
20961@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
20962 case R_X86_64_NONE:
20963 break;
20964 case R_X86_64_64:
20965+ pax_open_kernel();
20966 *(u64 *)loc = val;
20967+ pax_close_kernel();
20968 break;
20969 case R_X86_64_32:
20970+ pax_open_kernel();
20971 *(u32 *)loc = val;
20972+ pax_close_kernel();
20973 if (val != *(u32 *)loc)
20974 goto overflow;
20975 break;
20976 case R_X86_64_32S:
20977+ pax_open_kernel();
20978 *(s32 *)loc = val;
20979+ pax_close_kernel();
20980 if ((s64)val != *(s32 *)loc)
20981 goto overflow;
20982 break;
20983 case R_X86_64_PC32:
20984 val -= (u64)loc;
20985+ pax_open_kernel();
20986 *(u32 *)loc = val;
20987+ pax_close_kernel();
20988+
20989 #if 0
20990 if ((s64)val != *(s32 *)loc)
20991 goto overflow;
20992diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
20993index 4929502..686c291 100644
20994--- a/arch/x86/kernel/msr.c
20995+++ b/arch/x86/kernel/msr.c
20996@@ -234,7 +234,7 @@ static int __cpuinit msr_class_cpu_callback(struct notifier_block *nfb,
20997 return notifier_from_errno(err);
20998 }
20999
21000-static struct notifier_block __refdata msr_class_cpu_notifier = {
21001+static struct notifier_block msr_class_cpu_notifier = {
21002 .notifier_call = msr_class_cpu_callback,
21003 };
21004
21005diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
21006index f84f5c5..e27e54b 100644
21007--- a/arch/x86/kernel/nmi.c
21008+++ b/arch/x86/kernel/nmi.c
21009@@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
21010 dotraplinkage notrace __kprobes void
21011 do_nmi(struct pt_regs *regs, long error_code)
21012 {
21013+
21014+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21015+ if (!user_mode(regs)) {
21016+ unsigned long cs = regs->cs & 0xFFFF;
21017+ unsigned long ip = ktva_ktla(regs->ip);
21018+
21019+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
21020+ regs->ip = ip;
21021+ }
21022+#endif
21023+
21024 nmi_nesting_preprocess(regs);
21025
21026 nmi_enter();
21027diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
21028index 676b8c7..870ba04 100644
21029--- a/arch/x86/kernel/paravirt-spinlocks.c
21030+++ b/arch/x86/kernel/paravirt-spinlocks.c
21031@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
21032 arch_spin_lock(lock);
21033 }
21034
21035-struct pv_lock_ops pv_lock_ops = {
21036+struct pv_lock_ops pv_lock_ops __read_only = {
21037 #ifdef CONFIG_SMP
21038 .spin_is_locked = __ticket_spin_is_locked,
21039 .spin_is_contended = __ticket_spin_is_contended,
21040diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
21041index 17fff18..5cfa0f4 100644
21042--- a/arch/x86/kernel/paravirt.c
21043+++ b/arch/x86/kernel/paravirt.c
21044@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
21045 {
21046 return x;
21047 }
21048+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21049+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
21050+#endif
21051
21052 void __init default_banner(void)
21053 {
21054@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
21055 if (opfunc == NULL)
21056 /* If there's no function, patch it with a ud2a (BUG) */
21057 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
21058- else if (opfunc == _paravirt_nop)
21059+ else if (opfunc == (void *)_paravirt_nop)
21060 /* If the operation is a nop, then nop the callsite */
21061 ret = paravirt_patch_nop();
21062
21063 /* identity functions just return their single argument */
21064- else if (opfunc == _paravirt_ident_32)
21065+ else if (opfunc == (void *)_paravirt_ident_32)
21066 ret = paravirt_patch_ident_32(insnbuf, len);
21067- else if (opfunc == _paravirt_ident_64)
21068+ else if (opfunc == (void *)_paravirt_ident_64)
21069 ret = paravirt_patch_ident_64(insnbuf, len);
21070+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21071+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
21072+ ret = paravirt_patch_ident_64(insnbuf, len);
21073+#endif
21074
21075 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
21076 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
21077@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
21078 if (insn_len > len || start == NULL)
21079 insn_len = len;
21080 else
21081- memcpy(insnbuf, start, insn_len);
21082+ memcpy(insnbuf, ktla_ktva(start), insn_len);
21083
21084 return insn_len;
21085 }
21086@@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
21087 preempt_enable();
21088 }
21089
21090-struct pv_info pv_info = {
21091+struct pv_info pv_info __read_only = {
21092 .name = "bare hardware",
21093 .paravirt_enabled = 0,
21094 .kernel_rpl = 0,
21095@@ -315,16 +322,16 @@ struct pv_info pv_info = {
21096 #endif
21097 };
21098
21099-struct pv_init_ops pv_init_ops = {
21100+struct pv_init_ops pv_init_ops __read_only = {
21101 .patch = native_patch,
21102 };
21103
21104-struct pv_time_ops pv_time_ops = {
21105+struct pv_time_ops pv_time_ops __read_only = {
21106 .sched_clock = native_sched_clock,
21107 .steal_clock = native_steal_clock,
21108 };
21109
21110-struct pv_irq_ops pv_irq_ops = {
21111+struct pv_irq_ops pv_irq_ops __read_only = {
21112 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
21113 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
21114 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
21115@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
21116 #endif
21117 };
21118
21119-struct pv_cpu_ops pv_cpu_ops = {
21120+struct pv_cpu_ops pv_cpu_ops __read_only = {
21121 .cpuid = native_cpuid,
21122 .get_debugreg = native_get_debugreg,
21123 .set_debugreg = native_set_debugreg,
21124@@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
21125 .end_context_switch = paravirt_nop,
21126 };
21127
21128-struct pv_apic_ops pv_apic_ops = {
21129+struct pv_apic_ops pv_apic_ops __read_only= {
21130 #ifdef CONFIG_X86_LOCAL_APIC
21131 .startup_ipi_hook = paravirt_nop,
21132 #endif
21133 };
21134
21135-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
21136+#ifdef CONFIG_X86_32
21137+#ifdef CONFIG_X86_PAE
21138+/* 64-bit pagetable entries */
21139+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
21140+#else
21141 /* 32-bit pagetable entries */
21142 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
21143+#endif
21144 #else
21145 /* 64-bit pagetable entries */
21146 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
21147 #endif
21148
21149-struct pv_mmu_ops pv_mmu_ops = {
21150+struct pv_mmu_ops pv_mmu_ops __read_only = {
21151
21152 .read_cr2 = native_read_cr2,
21153 .write_cr2 = native_write_cr2,
21154@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
21155 .make_pud = PTE_IDENT,
21156
21157 .set_pgd = native_set_pgd,
21158+ .set_pgd_batched = native_set_pgd_batched,
21159 #endif
21160 #endif /* PAGETABLE_LEVELS >= 3 */
21161
21162@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
21163 },
21164
21165 .set_fixmap = native_set_fixmap,
21166+
21167+#ifdef CONFIG_PAX_KERNEXEC
21168+ .pax_open_kernel = native_pax_open_kernel,
21169+ .pax_close_kernel = native_pax_close_kernel,
21170+#endif
21171+
21172 };
21173
21174 EXPORT_SYMBOL_GPL(pv_time_ops);
21175diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
21176index 35ccf75..7a15747 100644
21177--- a/arch/x86/kernel/pci-iommu_table.c
21178+++ b/arch/x86/kernel/pci-iommu_table.c
21179@@ -2,7 +2,7 @@
21180 #include <asm/iommu_table.h>
21181 #include <linux/string.h>
21182 #include <linux/kallsyms.h>
21183-
21184+#include <linux/sched.h>
21185
21186 #define DEBUG 1
21187
21188diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
21189index 2ed787f..f70c9f6 100644
21190--- a/arch/x86/kernel/process.c
21191+++ b/arch/x86/kernel/process.c
21192@@ -36,7 +36,8 @@
21193 * section. Since TSS's are completely CPU-local, we want them
21194 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
21195 */
21196-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
21197+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
21198+EXPORT_SYMBOL(init_tss);
21199
21200 #ifdef CONFIG_X86_64
21201 static DEFINE_PER_CPU(unsigned char, is_idle);
21202@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
21203 task_xstate_cachep =
21204 kmem_cache_create("task_xstate", xstate_size,
21205 __alignof__(union thread_xstate),
21206- SLAB_PANIC | SLAB_NOTRACK, NULL);
21207+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
21208 }
21209
21210 /*
21211@@ -105,7 +106,7 @@ void exit_thread(void)
21212 unsigned long *bp = t->io_bitmap_ptr;
21213
21214 if (bp) {
21215- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
21216+ struct tss_struct *tss = init_tss + get_cpu();
21217
21218 t->io_bitmap_ptr = NULL;
21219 clear_thread_flag(TIF_IO_BITMAP);
21220@@ -136,7 +137,7 @@ void show_regs_common(void)
21221 board = dmi_get_system_info(DMI_BOARD_NAME);
21222
21223 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
21224- current->pid, current->comm, print_tainted(),
21225+ task_pid_nr(current), current->comm, print_tainted(),
21226 init_utsname()->release,
21227 (int)strcspn(init_utsname()->version, " "),
21228 init_utsname()->version,
21229@@ -149,6 +150,9 @@ void flush_thread(void)
21230 {
21231 struct task_struct *tsk = current;
21232
21233+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
21234+ loadsegment(gs, 0);
21235+#endif
21236 flush_ptrace_hw_breakpoint(tsk);
21237 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
21238 drop_init_fpu(tsk);
21239@@ -301,7 +305,7 @@ static void __exit_idle(void)
21240 void exit_idle(void)
21241 {
21242 /* idle loop has pid 0 */
21243- if (current->pid)
21244+ if (task_pid_nr(current))
21245 return;
21246 __exit_idle();
21247 }
21248@@ -404,7 +408,7 @@ bool set_pm_idle_to_default(void)
21249
21250 return ret;
21251 }
21252-void stop_this_cpu(void *dummy)
21253+__noreturn void stop_this_cpu(void *dummy)
21254 {
21255 local_irq_disable();
21256 /*
21257@@ -632,16 +636,37 @@ static int __init idle_setup(char *str)
21258 }
21259 early_param("idle", idle_setup);
21260
21261-unsigned long arch_align_stack(unsigned long sp)
21262+#ifdef CONFIG_PAX_RANDKSTACK
21263+void pax_randomize_kstack(struct pt_regs *regs)
21264 {
21265- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
21266- sp -= get_random_int() % 8192;
21267- return sp & ~0xf;
21268-}
21269+ struct thread_struct *thread = &current->thread;
21270+ unsigned long time;
21271
21272-unsigned long arch_randomize_brk(struct mm_struct *mm)
21273-{
21274- unsigned long range_end = mm->brk + 0x02000000;
21275- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
21276-}
21277+ if (!randomize_va_space)
21278+ return;
21279+
21280+ if (v8086_mode(regs))
21281+ return;
21282
21283+ rdtscl(time);
21284+
21285+ /* P4 seems to return a 0 LSB, ignore it */
21286+#ifdef CONFIG_MPENTIUM4
21287+ time &= 0x3EUL;
21288+ time <<= 2;
21289+#elif defined(CONFIG_X86_64)
21290+ time &= 0xFUL;
21291+ time <<= 4;
21292+#else
21293+ time &= 0x1FUL;
21294+ time <<= 3;
21295+#endif
21296+
21297+ thread->sp0 ^= time;
21298+ load_sp0(init_tss + smp_processor_id(), thread);
21299+
21300+#ifdef CONFIG_X86_64
21301+ this_cpu_write(kernel_stack, thread->sp0);
21302+#endif
21303+}
21304+#endif
21305diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
21306index b5a8905..d9cacac 100644
21307--- a/arch/x86/kernel/process_32.c
21308+++ b/arch/x86/kernel/process_32.c
21309@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
21310 unsigned long thread_saved_pc(struct task_struct *tsk)
21311 {
21312 return ((unsigned long *)tsk->thread.sp)[3];
21313+//XXX return tsk->thread.eip;
21314 }
21315
21316 void __show_regs(struct pt_regs *regs, int all)
21317@@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
21318 unsigned long sp;
21319 unsigned short ss, gs;
21320
21321- if (user_mode_vm(regs)) {
21322+ if (user_mode(regs)) {
21323 sp = regs->sp;
21324 ss = regs->ss & 0xffff;
21325- gs = get_user_gs(regs);
21326 } else {
21327 sp = kernel_stack_pointer(regs);
21328 savesegment(ss, ss);
21329- savesegment(gs, gs);
21330 }
21331+ gs = get_user_gs(regs);
21332
21333 show_regs_common();
21334
21335 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
21336 (u16)regs->cs, regs->ip, regs->flags,
21337- smp_processor_id());
21338+ raw_smp_processor_id());
21339 print_symbol("EIP is at %s\n", regs->ip);
21340
21341 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
21342@@ -130,20 +130,21 @@ void release_thread(struct task_struct *dead_task)
21343 int copy_thread(unsigned long clone_flags, unsigned long sp,
21344 unsigned long arg, struct task_struct *p)
21345 {
21346- struct pt_regs *childregs = task_pt_regs(p);
21347+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
21348 struct task_struct *tsk;
21349 int err;
21350
21351 p->thread.sp = (unsigned long) childregs;
21352 p->thread.sp0 = (unsigned long) (childregs+1);
21353+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
21354
21355 if (unlikely(p->flags & PF_KTHREAD)) {
21356 /* kernel thread */
21357 memset(childregs, 0, sizeof(struct pt_regs));
21358 p->thread.ip = (unsigned long) ret_from_kernel_thread;
21359- task_user_gs(p) = __KERNEL_STACK_CANARY;
21360- childregs->ds = __USER_DS;
21361- childregs->es = __USER_DS;
21362+ savesegment(gs, childregs->gs);
21363+ childregs->ds = __KERNEL_DS;
21364+ childregs->es = __KERNEL_DS;
21365 childregs->fs = __KERNEL_PERCPU;
21366 childregs->bx = sp; /* function */
21367 childregs->bp = arg;
21368@@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21369 struct thread_struct *prev = &prev_p->thread,
21370 *next = &next_p->thread;
21371 int cpu = smp_processor_id();
21372- struct tss_struct *tss = &per_cpu(init_tss, cpu);
21373+ struct tss_struct *tss = init_tss + cpu;
21374 fpu_switch_t fpu;
21375
21376 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
21377@@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21378 */
21379 lazy_save_gs(prev->gs);
21380
21381+#ifdef CONFIG_PAX_MEMORY_UDEREF
21382+ __set_fs(task_thread_info(next_p)->addr_limit);
21383+#endif
21384+
21385 /*
21386 * Load the per-thread Thread-Local Storage descriptor.
21387 */
21388@@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21389 */
21390 arch_end_context_switch(next_p);
21391
21392+ this_cpu_write(current_task, next_p);
21393+ this_cpu_write(current_tinfo, &next_p->tinfo);
21394+
21395 /*
21396 * Restore %gs if needed (which is common)
21397 */
21398@@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21399
21400 switch_fpu_finish(next_p, fpu);
21401
21402- this_cpu_write(current_task, next_p);
21403-
21404 return prev_p;
21405 }
21406
21407@@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
21408 } while (count++ < 16);
21409 return 0;
21410 }
21411-
21412diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
21413index 6e68a61..955a9a5 100644
21414--- a/arch/x86/kernel/process_64.c
21415+++ b/arch/x86/kernel/process_64.c
21416@@ -152,10 +152,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
21417 struct pt_regs *childregs;
21418 struct task_struct *me = current;
21419
21420- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
21421+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
21422 childregs = task_pt_regs(p);
21423 p->thread.sp = (unsigned long) childregs;
21424 p->thread.usersp = me->thread.usersp;
21425+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
21426 set_tsk_thread_flag(p, TIF_FORK);
21427 p->fpu_counter = 0;
21428 p->thread.io_bitmap_ptr = NULL;
21429@@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21430 struct thread_struct *prev = &prev_p->thread;
21431 struct thread_struct *next = &next_p->thread;
21432 int cpu = smp_processor_id();
21433- struct tss_struct *tss = &per_cpu(init_tss, cpu);
21434+ struct tss_struct *tss = init_tss + cpu;
21435 unsigned fsindex, gsindex;
21436 fpu_switch_t fpu;
21437
21438@@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21439 prev->usersp = this_cpu_read(old_rsp);
21440 this_cpu_write(old_rsp, next->usersp);
21441 this_cpu_write(current_task, next_p);
21442+ this_cpu_write(current_tinfo, &next_p->tinfo);
21443
21444- this_cpu_write(kernel_stack,
21445- (unsigned long)task_stack_page(next_p) +
21446- THREAD_SIZE - KERNEL_STACK_OFFSET);
21447+ this_cpu_write(kernel_stack, next->sp0);
21448
21449 /*
21450 * Now maybe reload the debug registers and handle I/O bitmaps
21451@@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
21452 if (!p || p == current || p->state == TASK_RUNNING)
21453 return 0;
21454 stack = (unsigned long)task_stack_page(p);
21455- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
21456+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
21457 return 0;
21458 fp = *(u64 *)(p->thread.sp);
21459 do {
21460- if (fp < (unsigned long)stack ||
21461- fp >= (unsigned long)stack+THREAD_SIZE)
21462+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
21463 return 0;
21464 ip = *(u64 *)(fp+8);
21465 if (!in_sched_functions(ip))
21466diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
21467index b629bbe..0fa615a 100644
21468--- a/arch/x86/kernel/ptrace.c
21469+++ b/arch/x86/kernel/ptrace.c
21470@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
21471 {
21472 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
21473 unsigned long sp = (unsigned long)&regs->sp;
21474- struct thread_info *tinfo;
21475
21476- if (context == (sp & ~(THREAD_SIZE - 1)))
21477+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
21478 return sp;
21479
21480- tinfo = (struct thread_info *)context;
21481- if (tinfo->previous_esp)
21482- return tinfo->previous_esp;
21483+ sp = *(unsigned long *)context;
21484+ if (sp)
21485+ return sp;
21486
21487 return (unsigned long)regs;
21488 }
21489@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
21490 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
21491 {
21492 int i;
21493- int dr7 = 0;
21494+ unsigned long dr7 = 0;
21495 struct arch_hw_breakpoint *info;
21496
21497 for (i = 0; i < HBP_NUM; i++) {
21498@@ -856,7 +855,7 @@ long arch_ptrace(struct task_struct *child, long request,
21499 unsigned long addr, unsigned long data)
21500 {
21501 int ret;
21502- unsigned long __user *datap = (unsigned long __user *)data;
21503+ unsigned long __user *datap = (__force unsigned long __user *)data;
21504
21505 switch (request) {
21506 /* read the word at location addr in the USER area. */
21507@@ -941,14 +940,14 @@ long arch_ptrace(struct task_struct *child, long request,
21508 if ((int) addr < 0)
21509 return -EIO;
21510 ret = do_get_thread_area(child, addr,
21511- (struct user_desc __user *)data);
21512+ (__force struct user_desc __user *) data);
21513 break;
21514
21515 case PTRACE_SET_THREAD_AREA:
21516 if ((int) addr < 0)
21517 return -EIO;
21518 ret = do_set_thread_area(child, addr,
21519- (struct user_desc __user *)data, 0);
21520+ (__force struct user_desc __user *) data, 0);
21521 break;
21522 #endif
21523
21524@@ -1326,7 +1325,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
21525
21526 #ifdef CONFIG_X86_64
21527
21528-static struct user_regset x86_64_regsets[] __read_mostly = {
21529+static user_regset_no_const x86_64_regsets[] __read_only = {
21530 [REGSET_GENERAL] = {
21531 .core_note_type = NT_PRSTATUS,
21532 .n = sizeof(struct user_regs_struct) / sizeof(long),
21533@@ -1367,7 +1366,7 @@ static const struct user_regset_view user_x86_64_view = {
21534 #endif /* CONFIG_X86_64 */
21535
21536 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
21537-static struct user_regset x86_32_regsets[] __read_mostly = {
21538+static user_regset_no_const x86_32_regsets[] __read_only = {
21539 [REGSET_GENERAL] = {
21540 .core_note_type = NT_PRSTATUS,
21541 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
21542@@ -1420,7 +1419,7 @@ static const struct user_regset_view user_x86_32_view = {
21543 */
21544 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
21545
21546-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
21547+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
21548 {
21549 #ifdef CONFIG_X86_64
21550 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
21551@@ -1455,7 +1454,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
21552 memset(info, 0, sizeof(*info));
21553 info->si_signo = SIGTRAP;
21554 info->si_code = si_code;
21555- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
21556+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
21557 }
21558
21559 void user_single_step_siginfo(struct task_struct *tsk,
21560@@ -1484,6 +1483,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
21561 # define IS_IA32 0
21562 #endif
21563
21564+#ifdef CONFIG_GRKERNSEC_SETXID
21565+extern void gr_delayed_cred_worker(void);
21566+#endif
21567+
21568 /*
21569 * We must return the syscall number to actually look up in the table.
21570 * This can be -1L to skip running any syscall at all.
21571@@ -1494,6 +1497,11 @@ long syscall_trace_enter(struct pt_regs *regs)
21572
21573 user_exit();
21574
21575+#ifdef CONFIG_GRKERNSEC_SETXID
21576+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
21577+ gr_delayed_cred_worker();
21578+#endif
21579+
21580 /*
21581 * If we stepped into a sysenter/syscall insn, it trapped in
21582 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
21583@@ -1549,6 +1557,11 @@ void syscall_trace_leave(struct pt_regs *regs)
21584 */
21585 user_exit();
21586
21587+#ifdef CONFIG_GRKERNSEC_SETXID
21588+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
21589+ gr_delayed_cred_worker();
21590+#endif
21591+
21592 audit_syscall_exit(regs);
21593
21594 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
21595diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
21596index 85c3959..76b89f9 100644
21597--- a/arch/x86/kernel/pvclock.c
21598+++ b/arch/x86/kernel/pvclock.c
21599@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
21600 return pv_tsc_khz;
21601 }
21602
21603-static atomic64_t last_value = ATOMIC64_INIT(0);
21604+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
21605
21606 void pvclock_resume(void)
21607 {
21608- atomic64_set(&last_value, 0);
21609+ atomic64_set_unchecked(&last_value, 0);
21610 }
21611
21612 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
21613@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
21614 * updating at the same time, and one of them could be slightly behind,
21615 * making the assumption that last_value always go forward fail to hold.
21616 */
21617- last = atomic64_read(&last_value);
21618+ last = atomic64_read_unchecked(&last_value);
21619 do {
21620 if (ret < last)
21621 return last;
21622- last = atomic64_cmpxchg(&last_value, last, ret);
21623+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
21624 } while (unlikely(last != ret));
21625
21626 return ret;
21627diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
21628index 76fa1e9..abf09ea 100644
21629--- a/arch/x86/kernel/reboot.c
21630+++ b/arch/x86/kernel/reboot.c
21631@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
21632 EXPORT_SYMBOL(pm_power_off);
21633
21634 static const struct desc_ptr no_idt = {};
21635-static int reboot_mode;
21636+static unsigned short reboot_mode;
21637 enum reboot_type reboot_type = BOOT_ACPI;
21638 int reboot_force;
21639
21640@@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
21641
21642 void __noreturn machine_real_restart(unsigned int type)
21643 {
21644+
21645+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21646+ struct desc_struct *gdt;
21647+#endif
21648+
21649 local_irq_disable();
21650
21651 /*
21652@@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
21653
21654 /* Jump to the identity-mapped low memory code */
21655 #ifdef CONFIG_X86_32
21656- asm volatile("jmpl *%0" : :
21657+
21658+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21659+ gdt = get_cpu_gdt_table(smp_processor_id());
21660+ pax_open_kernel();
21661+#ifdef CONFIG_PAX_MEMORY_UDEREF
21662+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
21663+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
21664+ loadsegment(ds, __KERNEL_DS);
21665+ loadsegment(es, __KERNEL_DS);
21666+ loadsegment(ss, __KERNEL_DS);
21667+#endif
21668+#ifdef CONFIG_PAX_KERNEXEC
21669+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
21670+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
21671+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
21672+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
21673+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
21674+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
21675+#endif
21676+ pax_close_kernel();
21677+#endif
21678+
21679+ asm volatile("ljmpl *%0" : :
21680 "rm" (real_mode_header->machine_real_restart_asm),
21681 "a" (type));
21682 #else
21683@@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
21684 * try to force a triple fault and then cycle between hitting the keyboard
21685 * controller and doing that
21686 */
21687-static void native_machine_emergency_restart(void)
21688+static void __noreturn native_machine_emergency_restart(void)
21689 {
21690 int i;
21691 int attempt = 0;
21692@@ -654,13 +681,13 @@ void native_machine_shutdown(void)
21693 #endif
21694 }
21695
21696-static void __machine_emergency_restart(int emergency)
21697+static void __noreturn __machine_emergency_restart(int emergency)
21698 {
21699 reboot_emergency = emergency;
21700 machine_ops.emergency_restart();
21701 }
21702
21703-static void native_machine_restart(char *__unused)
21704+static void __noreturn native_machine_restart(char *__unused)
21705 {
21706 pr_notice("machine restart\n");
21707
21708@@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
21709 __machine_emergency_restart(0);
21710 }
21711
21712-static void native_machine_halt(void)
21713+static void __noreturn native_machine_halt(void)
21714 {
21715 /* Stop other cpus and apics */
21716 machine_shutdown();
21717@@ -679,7 +706,7 @@ static void native_machine_halt(void)
21718 stop_this_cpu(NULL);
21719 }
21720
21721-static void native_machine_power_off(void)
21722+static void __noreturn native_machine_power_off(void)
21723 {
21724 if (pm_power_off) {
21725 if (!reboot_force)
21726@@ -688,9 +715,10 @@ static void native_machine_power_off(void)
21727 }
21728 /* A fallback in case there is no PM info available */
21729 tboot_shutdown(TB_SHUTDOWN_HALT);
21730+ unreachable();
21731 }
21732
21733-struct machine_ops machine_ops = {
21734+struct machine_ops machine_ops __read_only = {
21735 .power_off = native_machine_power_off,
21736 .shutdown = native_machine_shutdown,
21737 .emergency_restart = native_machine_emergency_restart,
21738diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
21739index 7a6f3b3..bed145d7 100644
21740--- a/arch/x86/kernel/relocate_kernel_64.S
21741+++ b/arch/x86/kernel/relocate_kernel_64.S
21742@@ -11,6 +11,7 @@
21743 #include <asm/kexec.h>
21744 #include <asm/processor-flags.h>
21745 #include <asm/pgtable_types.h>
21746+#include <asm/alternative-asm.h>
21747
21748 /*
21749 * Must be relocatable PIC code callable as a C function
21750@@ -160,13 +161,14 @@ identity_mapped:
21751 xorq %rbp, %rbp
21752 xorq %r8, %r8
21753 xorq %r9, %r9
21754- xorq %r10, %r9
21755+ xorq %r10, %r10
21756 xorq %r11, %r11
21757 xorq %r12, %r12
21758 xorq %r13, %r13
21759 xorq %r14, %r14
21760 xorq %r15, %r15
21761
21762+ pax_force_retaddr 0, 1
21763 ret
21764
21765 1:
21766diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
21767index 8b24289..d37b58b 100644
21768--- a/arch/x86/kernel/setup.c
21769+++ b/arch/x86/kernel/setup.c
21770@@ -437,7 +437,7 @@ static void __init parse_setup_data(void)
21771
21772 switch (data->type) {
21773 case SETUP_E820_EXT:
21774- parse_e820_ext(data);
21775+ parse_e820_ext((struct setup_data __force_kernel *)data);
21776 break;
21777 case SETUP_DTB:
21778 add_dtb(pa_data);
21779@@ -706,7 +706,7 @@ static void __init trim_bios_range(void)
21780 * area (640->1Mb) as ram even though it is not.
21781 * take them out.
21782 */
21783- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
21784+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
21785
21786 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
21787 }
21788@@ -830,14 +830,14 @@ void __init setup_arch(char **cmdline_p)
21789
21790 if (!boot_params.hdr.root_flags)
21791 root_mountflags &= ~MS_RDONLY;
21792- init_mm.start_code = (unsigned long) _text;
21793- init_mm.end_code = (unsigned long) _etext;
21794+ init_mm.start_code = ktla_ktva((unsigned long) _text);
21795+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
21796 init_mm.end_data = (unsigned long) _edata;
21797 init_mm.brk = _brk_end;
21798
21799- code_resource.start = virt_to_phys(_text);
21800- code_resource.end = virt_to_phys(_etext)-1;
21801- data_resource.start = virt_to_phys(_etext);
21802+ code_resource.start = virt_to_phys(ktla_ktva(_text));
21803+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
21804+ data_resource.start = virt_to_phys(_sdata);
21805 data_resource.end = virt_to_phys(_edata)-1;
21806 bss_resource.start = virt_to_phys(&__bss_start);
21807 bss_resource.end = virt_to_phys(&__bss_stop)-1;
21808diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
21809index 5cdff03..5810740 100644
21810--- a/arch/x86/kernel/setup_percpu.c
21811+++ b/arch/x86/kernel/setup_percpu.c
21812@@ -21,19 +21,17 @@
21813 #include <asm/cpu.h>
21814 #include <asm/stackprotector.h>
21815
21816-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
21817+#ifdef CONFIG_SMP
21818+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
21819 EXPORT_PER_CPU_SYMBOL(cpu_number);
21820+#endif
21821
21822-#ifdef CONFIG_X86_64
21823 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
21824-#else
21825-#define BOOT_PERCPU_OFFSET 0
21826-#endif
21827
21828 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
21829 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
21830
21831-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
21832+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
21833 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
21834 };
21835 EXPORT_SYMBOL(__per_cpu_offset);
21836@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
21837 {
21838 #ifdef CONFIG_X86_32
21839 struct desc_struct gdt;
21840+ unsigned long base = per_cpu_offset(cpu);
21841
21842- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
21843- 0x2 | DESCTYPE_S, 0x8);
21844- gdt.s = 1;
21845+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
21846+ 0x83 | DESCTYPE_S, 0xC);
21847 write_gdt_entry(get_cpu_gdt_table(cpu),
21848 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
21849 #endif
21850@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
21851 /* alrighty, percpu areas up and running */
21852 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
21853 for_each_possible_cpu(cpu) {
21854+#ifdef CONFIG_CC_STACKPROTECTOR
21855+#ifdef CONFIG_X86_32
21856+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
21857+#endif
21858+#endif
21859 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
21860 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
21861 per_cpu(cpu_number, cpu) = cpu;
21862@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
21863 */
21864 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
21865 #endif
21866+#ifdef CONFIG_CC_STACKPROTECTOR
21867+#ifdef CONFIG_X86_32
21868+ if (!cpu)
21869+ per_cpu(stack_canary.canary, cpu) = canary;
21870+#endif
21871+#endif
21872 /*
21873 * Up to this point, the boot CPU has been using .init.data
21874 * area. Reload any changed state for the boot CPU.
21875diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
21876index d6bf1f3..3ffce5a 100644
21877--- a/arch/x86/kernel/signal.c
21878+++ b/arch/x86/kernel/signal.c
21879@@ -196,7 +196,7 @@ static unsigned long align_sigframe(unsigned long sp)
21880 * Align the stack pointer according to the i386 ABI,
21881 * i.e. so that on function entry ((sp + 4) & 15) == 0.
21882 */
21883- sp = ((sp + 4) & -16ul) - 4;
21884+ sp = ((sp - 12) & -16ul) - 4;
21885 #else /* !CONFIG_X86_32 */
21886 sp = round_down(sp, 16) - 8;
21887 #endif
21888@@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
21889 }
21890
21891 if (current->mm->context.vdso)
21892- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
21893+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
21894 else
21895- restorer = &frame->retcode;
21896+ restorer = (void __user *)&frame->retcode;
21897 if (ka->sa.sa_flags & SA_RESTORER)
21898 restorer = ka->sa.sa_restorer;
21899
21900@@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
21901 * reasons and because gdb uses it as a signature to notice
21902 * signal handler stack frames.
21903 */
21904- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
21905+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
21906
21907 if (err)
21908 return -EFAULT;
21909@@ -367,7 +367,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
21910 err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
21911
21912 /* Set up to return from userspace. */
21913- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
21914+ if (current->mm->context.vdso)
21915+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
21916+ else
21917+ restorer = (void __user *)&frame->retcode;
21918 if (ka->sa.sa_flags & SA_RESTORER)
21919 restorer = ka->sa.sa_restorer;
21920 put_user_ex(restorer, &frame->pretcode);
21921@@ -379,7 +382,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
21922 * reasons and because gdb uses it as a signature to notice
21923 * signal handler stack frames.
21924 */
21925- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
21926+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
21927 } put_user_catch(err);
21928
21929 err |= copy_siginfo_to_user(&frame->info, info);
21930diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
21931index 48d2b7d..90d328a 100644
21932--- a/arch/x86/kernel/smp.c
21933+++ b/arch/x86/kernel/smp.c
21934@@ -285,7 +285,7 @@ static int __init nonmi_ipi_setup(char *str)
21935
21936 __setup("nonmi_ipi", nonmi_ipi_setup);
21937
21938-struct smp_ops smp_ops = {
21939+struct smp_ops smp_ops __read_only = {
21940 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
21941 .smp_prepare_cpus = native_smp_prepare_cpus,
21942 .smp_cpus_done = native_smp_cpus_done,
21943diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
21944index ed0fe38..87fc692 100644
21945--- a/arch/x86/kernel/smpboot.c
21946+++ b/arch/x86/kernel/smpboot.c
21947@@ -748,6 +748,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
21948 idle->thread.sp = (unsigned long) (((struct pt_regs *)
21949 (THREAD_SIZE + task_stack_page(idle))) - 1);
21950 per_cpu(current_task, cpu) = idle;
21951+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
21952
21953 #ifdef CONFIG_X86_32
21954 /* Stack for startup_32 can be just as for start_secondary onwards */
21955@@ -755,11 +756,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
21956 #else
21957 clear_tsk_thread_flag(idle, TIF_FORK);
21958 initial_gs = per_cpu_offset(cpu);
21959- per_cpu(kernel_stack, cpu) =
21960- (unsigned long)task_stack_page(idle) -
21961- KERNEL_STACK_OFFSET + THREAD_SIZE;
21962+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
21963 #endif
21964+
21965+ pax_open_kernel();
21966 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21967+ pax_close_kernel();
21968+
21969 initial_code = (unsigned long)start_secondary;
21970 stack_start = idle->thread.sp;
21971
21972@@ -908,6 +911,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
21973 /* the FPU context is blank, nobody can own it */
21974 __cpu_disable_lazy_restore(cpu);
21975
21976+#ifdef CONFIG_PAX_PER_CPU_PGD
21977+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
21978+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
21979+ KERNEL_PGD_PTRS);
21980+#endif
21981+
21982+ /* the FPU context is blank, nobody can own it */
21983+ __cpu_disable_lazy_restore(cpu);
21984+
21985 err = do_boot_cpu(apicid, cpu, tidle);
21986 if (err) {
21987 pr_debug("do_boot_cpu failed %d\n", err);
21988diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
21989index 9b4d51d..5d28b58 100644
21990--- a/arch/x86/kernel/step.c
21991+++ b/arch/x86/kernel/step.c
21992@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
21993 struct desc_struct *desc;
21994 unsigned long base;
21995
21996- seg &= ~7UL;
21997+ seg >>= 3;
21998
21999 mutex_lock(&child->mm->context.lock);
22000- if (unlikely((seg >> 3) >= child->mm->context.size))
22001+ if (unlikely(seg >= child->mm->context.size))
22002 addr = -1L; /* bogus selector, access would fault */
22003 else {
22004 desc = child->mm->context.ldt + seg;
22005@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22006 addr += base;
22007 }
22008 mutex_unlock(&child->mm->context.lock);
22009- }
22010+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
22011+ addr = ktla_ktva(addr);
22012
22013 return addr;
22014 }
22015@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
22016 unsigned char opcode[15];
22017 unsigned long addr = convert_ip_to_linear(child, regs);
22018
22019+ if (addr == -EINVAL)
22020+ return 0;
22021+
22022 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
22023 for (i = 0; i < copied; i++) {
22024 switch (opcode[i]) {
22025diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
22026new file mode 100644
22027index 0000000..26bb1af
22028--- /dev/null
22029+++ b/arch/x86/kernel/sys_i386_32.c
22030@@ -0,0 +1,249 @@
22031+/*
22032+ * This file contains various random system calls that
22033+ * have a non-standard calling sequence on the Linux/i386
22034+ * platform.
22035+ */
22036+
22037+#include <linux/errno.h>
22038+#include <linux/sched.h>
22039+#include <linux/mm.h>
22040+#include <linux/fs.h>
22041+#include <linux/smp.h>
22042+#include <linux/sem.h>
22043+#include <linux/msg.h>
22044+#include <linux/shm.h>
22045+#include <linux/stat.h>
22046+#include <linux/syscalls.h>
22047+#include <linux/mman.h>
22048+#include <linux/file.h>
22049+#include <linux/utsname.h>
22050+#include <linux/ipc.h>
22051+
22052+#include <linux/uaccess.h>
22053+#include <linux/unistd.h>
22054+
22055+#include <asm/syscalls.h>
22056+
22057+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
22058+{
22059+ unsigned long pax_task_size = TASK_SIZE;
22060+
22061+#ifdef CONFIG_PAX_SEGMEXEC
22062+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
22063+ pax_task_size = SEGMEXEC_TASK_SIZE;
22064+#endif
22065+
22066+ if (len > pax_task_size || addr > pax_task_size - len)
22067+ return -EINVAL;
22068+
22069+ return 0;
22070+}
22071+
22072+unsigned long
22073+arch_get_unmapped_area(struct file *filp, unsigned long addr,
22074+ unsigned long len, unsigned long pgoff, unsigned long flags)
22075+{
22076+ struct mm_struct *mm = current->mm;
22077+ struct vm_area_struct *vma;
22078+ unsigned long start_addr, pax_task_size = TASK_SIZE;
22079+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22080+
22081+#ifdef CONFIG_PAX_SEGMEXEC
22082+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22083+ pax_task_size = SEGMEXEC_TASK_SIZE;
22084+#endif
22085+
22086+ pax_task_size -= PAGE_SIZE;
22087+
22088+ if (len > pax_task_size)
22089+ return -ENOMEM;
22090+
22091+ if (flags & MAP_FIXED)
22092+ return addr;
22093+
22094+#ifdef CONFIG_PAX_RANDMMAP
22095+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22096+#endif
22097+
22098+ if (addr) {
22099+ addr = PAGE_ALIGN(addr);
22100+ if (pax_task_size - len >= addr) {
22101+ vma = find_vma(mm, addr);
22102+ if (check_heap_stack_gap(vma, addr, len, offset))
22103+ return addr;
22104+ }
22105+ }
22106+ if (len > mm->cached_hole_size) {
22107+ start_addr = addr = mm->free_area_cache;
22108+ } else {
22109+ start_addr = addr = mm->mmap_base;
22110+ mm->cached_hole_size = 0;
22111+ }
22112+
22113+#ifdef CONFIG_PAX_PAGEEXEC
22114+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
22115+ start_addr = 0x00110000UL;
22116+
22117+#ifdef CONFIG_PAX_RANDMMAP
22118+ if (mm->pax_flags & MF_PAX_RANDMMAP)
22119+ start_addr += mm->delta_mmap & 0x03FFF000UL;
22120+#endif
22121+
22122+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
22123+ start_addr = addr = mm->mmap_base;
22124+ else
22125+ addr = start_addr;
22126+ }
22127+#endif
22128+
22129+full_search:
22130+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
22131+ /* At this point: (!vma || addr < vma->vm_end). */
22132+ if (pax_task_size - len < addr) {
22133+ /*
22134+ * Start a new search - just in case we missed
22135+ * some holes.
22136+ */
22137+ if (start_addr != mm->mmap_base) {
22138+ start_addr = addr = mm->mmap_base;
22139+ mm->cached_hole_size = 0;
22140+ goto full_search;
22141+ }
22142+ return -ENOMEM;
22143+ }
22144+ if (check_heap_stack_gap(vma, addr, len, offset))
22145+ break;
22146+ if (addr + mm->cached_hole_size < vma->vm_start)
22147+ mm->cached_hole_size = vma->vm_start - addr;
22148+ addr = vma->vm_end;
22149+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
22150+ start_addr = addr = mm->mmap_base;
22151+ mm->cached_hole_size = 0;
22152+ goto full_search;
22153+ }
22154+ }
22155+
22156+ /*
22157+ * Remember the place where we stopped the search:
22158+ */
22159+ mm->free_area_cache = addr + len;
22160+ return addr;
22161+}
22162+
22163+unsigned long
22164+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
22165+ const unsigned long len, const unsigned long pgoff,
22166+ const unsigned long flags)
22167+{
22168+ struct vm_area_struct *vma;
22169+ struct mm_struct *mm = current->mm;
22170+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
22171+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22172+
22173+#ifdef CONFIG_PAX_SEGMEXEC
22174+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22175+ pax_task_size = SEGMEXEC_TASK_SIZE;
22176+#endif
22177+
22178+ pax_task_size -= PAGE_SIZE;
22179+
22180+ /* requested length too big for entire address space */
22181+ if (len > pax_task_size)
22182+ return -ENOMEM;
22183+
22184+ if (flags & MAP_FIXED)
22185+ return addr;
22186+
22187+#ifdef CONFIG_PAX_PAGEEXEC
22188+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
22189+ goto bottomup;
22190+#endif
22191+
22192+#ifdef CONFIG_PAX_RANDMMAP
22193+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22194+#endif
22195+
22196+ /* requesting a specific address */
22197+ if (addr) {
22198+ addr = PAGE_ALIGN(addr);
22199+ if (pax_task_size - len >= addr) {
22200+ vma = find_vma(mm, addr);
22201+ if (check_heap_stack_gap(vma, addr, len, offset))
22202+ return addr;
22203+ }
22204+ }
22205+
22206+ /* check if free_area_cache is useful for us */
22207+ if (len <= mm->cached_hole_size) {
22208+ mm->cached_hole_size = 0;
22209+ mm->free_area_cache = mm->mmap_base;
22210+ }
22211+
22212+ /* either no address requested or can't fit in requested address hole */
22213+ addr = mm->free_area_cache;
22214+
22215+ /* make sure it can fit in the remaining address space */
22216+ if (addr > len) {
22217+ vma = find_vma(mm, addr-len);
22218+ if (check_heap_stack_gap(vma, addr - len, len, offset))
22219+ /* remember the address as a hint for next time */
22220+ return (mm->free_area_cache = addr-len);
22221+ }
22222+
22223+ if (mm->mmap_base < len)
22224+ goto bottomup;
22225+
22226+ addr = mm->mmap_base-len;
22227+
22228+ do {
22229+ /*
22230+ * Lookup failure means no vma is above this address,
22231+ * else if new region fits below vma->vm_start,
22232+ * return with success:
22233+ */
22234+ vma = find_vma(mm, addr);
22235+ if (check_heap_stack_gap(vma, addr, len, offset))
22236+ /* remember the address as a hint for next time */
22237+ return (mm->free_area_cache = addr);
22238+
22239+ /* remember the largest hole we saw so far */
22240+ if (addr + mm->cached_hole_size < vma->vm_start)
22241+ mm->cached_hole_size = vma->vm_start - addr;
22242+
22243+ /* try just below the current vma->vm_start */
22244+ addr = skip_heap_stack_gap(vma, len, offset);
22245+ } while (!IS_ERR_VALUE(addr));
22246+
22247+bottomup:
22248+ /*
22249+ * A failed mmap() very likely causes application failure,
22250+ * so fall back to the bottom-up function here. This scenario
22251+ * can happen with large stack limits and large mmap()
22252+ * allocations.
22253+ */
22254+
22255+#ifdef CONFIG_PAX_SEGMEXEC
22256+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22257+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
22258+ else
22259+#endif
22260+
22261+ mm->mmap_base = TASK_UNMAPPED_BASE;
22262+
22263+#ifdef CONFIG_PAX_RANDMMAP
22264+ if (mm->pax_flags & MF_PAX_RANDMMAP)
22265+ mm->mmap_base += mm->delta_mmap;
22266+#endif
22267+
22268+ mm->free_area_cache = mm->mmap_base;
22269+ mm->cached_hole_size = ~0UL;
22270+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
22271+ /*
22272+ * Restore the topdown base:
22273+ */
22274+ mm->mmap_base = base;
22275+ mm->free_area_cache = base;
22276+ mm->cached_hole_size = ~0UL;
22277+
22278+ return addr;
22279+}
22280diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
22281index 97ef74b..57a1882 100644
22282--- a/arch/x86/kernel/sys_x86_64.c
22283+++ b/arch/x86/kernel/sys_x86_64.c
22284@@ -81,8 +81,8 @@ out:
22285 return error;
22286 }
22287
22288-static void find_start_end(unsigned long flags, unsigned long *begin,
22289- unsigned long *end)
22290+static void find_start_end(struct mm_struct *mm, unsigned long flags,
22291+ unsigned long *begin, unsigned long *end)
22292 {
22293 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
22294 unsigned long new_begin;
22295@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
22296 *begin = new_begin;
22297 }
22298 } else {
22299- *begin = TASK_UNMAPPED_BASE;
22300+ *begin = mm->mmap_base;
22301 *end = TASK_SIZE;
22302 }
22303 }
22304@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
22305 struct vm_area_struct *vma;
22306 struct vm_unmapped_area_info info;
22307 unsigned long begin, end;
22308+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22309
22310 if (flags & MAP_FIXED)
22311 return addr;
22312
22313- find_start_end(flags, &begin, &end);
22314+ find_start_end(mm, flags, &begin, &end);
22315
22316 if (len > end)
22317 return -ENOMEM;
22318
22319+#ifdef CONFIG_PAX_RANDMMAP
22320+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22321+#endif
22322+
22323 if (addr) {
22324 addr = PAGE_ALIGN(addr);
22325 vma = find_vma(mm, addr);
22326- if (end - len >= addr &&
22327- (!vma || addr + len <= vma->vm_start))
22328+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
22329 return addr;
22330 }
22331
22332@@ -161,6 +165,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
22333 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
22334 goto bottomup;
22335
22336+#ifdef CONFIG_PAX_RANDMMAP
22337+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22338+#endif
22339+
22340 /* requesting a specific address */
22341 if (addr) {
22342 addr = PAGE_ALIGN(addr);
22343diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
22344index f84fe00..f41d9f1 100644
22345--- a/arch/x86/kernel/tboot.c
22346+++ b/arch/x86/kernel/tboot.c
22347@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
22348
22349 void tboot_shutdown(u32 shutdown_type)
22350 {
22351- void (*shutdown)(void);
22352+ void (* __noreturn shutdown)(void);
22353
22354 if (!tboot_enabled())
22355 return;
22356@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
22357
22358 switch_to_tboot_pt();
22359
22360- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
22361+ shutdown = (void *)tboot->shutdown_entry;
22362 shutdown();
22363
22364 /* should not reach here */
22365@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
22366 return 0;
22367 }
22368
22369-static atomic_t ap_wfs_count;
22370+static atomic_unchecked_t ap_wfs_count;
22371
22372 static int tboot_wait_for_aps(int num_aps)
22373 {
22374@@ -324,16 +324,16 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
22375 {
22376 switch (action) {
22377 case CPU_DYING:
22378- atomic_inc(&ap_wfs_count);
22379+ atomic_inc_unchecked(&ap_wfs_count);
22380 if (num_online_cpus() == 1)
22381- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
22382+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
22383 return NOTIFY_BAD;
22384 break;
22385 }
22386 return NOTIFY_OK;
22387 }
22388
22389-static struct notifier_block tboot_cpu_notifier __cpuinitdata =
22390+static struct notifier_block tboot_cpu_notifier =
22391 {
22392 .notifier_call = tboot_cpu_callback,
22393 };
22394@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
22395
22396 tboot_create_trampoline();
22397
22398- atomic_set(&ap_wfs_count, 0);
22399+ atomic_set_unchecked(&ap_wfs_count, 0);
22400 register_hotcpu_notifier(&tboot_cpu_notifier);
22401
22402 acpi_os_set_prepare_sleep(&tboot_sleep);
22403diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
22404index 24d3c91..d06b473 100644
22405--- a/arch/x86/kernel/time.c
22406+++ b/arch/x86/kernel/time.c
22407@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
22408 {
22409 unsigned long pc = instruction_pointer(regs);
22410
22411- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
22412+ if (!user_mode(regs) && in_lock_functions(pc)) {
22413 #ifdef CONFIG_FRAME_POINTER
22414- return *(unsigned long *)(regs->bp + sizeof(long));
22415+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
22416 #else
22417 unsigned long *sp =
22418 (unsigned long *)kernel_stack_pointer(regs);
22419@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
22420 * or above a saved flags. Eflags has bits 22-31 zero,
22421 * kernel addresses don't.
22422 */
22423+
22424+#ifdef CONFIG_PAX_KERNEXEC
22425+ return ktla_ktva(sp[0]);
22426+#else
22427 if (sp[0] >> 22)
22428 return sp[0];
22429 if (sp[1] >> 22)
22430 return sp[1];
22431 #endif
22432+
22433+#endif
22434 }
22435 return pc;
22436 }
22437diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
22438index 9d9d2f9..cad418a 100644
22439--- a/arch/x86/kernel/tls.c
22440+++ b/arch/x86/kernel/tls.c
22441@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
22442 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
22443 return -EINVAL;
22444
22445+#ifdef CONFIG_PAX_SEGMEXEC
22446+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
22447+ return -EINVAL;
22448+#endif
22449+
22450 set_tls_desc(p, idx, &info, 1);
22451
22452 return 0;
22453@@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
22454
22455 if (kbuf)
22456 info = kbuf;
22457- else if (__copy_from_user(infobuf, ubuf, count))
22458+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
22459 return -EFAULT;
22460 else
22461 info = infobuf;
22462diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
22463index ecffca1..95c4d13 100644
22464--- a/arch/x86/kernel/traps.c
22465+++ b/arch/x86/kernel/traps.c
22466@@ -68,12 +68,6 @@
22467 #include <asm/setup.h>
22468
22469 asmlinkage int system_call(void);
22470-
22471-/*
22472- * The IDT has to be page-aligned to simplify the Pentium
22473- * F0 0F bug workaround.
22474- */
22475-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
22476 #endif
22477
22478 DECLARE_BITMAP(used_vectors, NR_VECTORS);
22479@@ -106,11 +100,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
22480 }
22481
22482 static int __kprobes
22483-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
22484+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
22485 struct pt_regs *regs, long error_code)
22486 {
22487 #ifdef CONFIG_X86_32
22488- if (regs->flags & X86_VM_MASK) {
22489+ if (v8086_mode(regs)) {
22490 /*
22491 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
22492 * On nmi (interrupt 2), do_trap should not be called.
22493@@ -123,12 +117,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
22494 return -1;
22495 }
22496 #endif
22497- if (!user_mode(regs)) {
22498+ if (!user_mode_novm(regs)) {
22499 if (!fixup_exception(regs)) {
22500 tsk->thread.error_code = error_code;
22501 tsk->thread.trap_nr = trapnr;
22502+
22503+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22504+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
22505+ str = "PAX: suspicious stack segment fault";
22506+#endif
22507+
22508 die(str, regs, error_code);
22509 }
22510+
22511+#ifdef CONFIG_PAX_REFCOUNT
22512+ if (trapnr == 4)
22513+ pax_report_refcount_overflow(regs);
22514+#endif
22515+
22516 return 0;
22517 }
22518
22519@@ -136,7 +142,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
22520 }
22521
22522 static void __kprobes
22523-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
22524+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
22525 long error_code, siginfo_t *info)
22526 {
22527 struct task_struct *tsk = current;
22528@@ -160,7 +166,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
22529 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
22530 printk_ratelimit()) {
22531 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
22532- tsk->comm, tsk->pid, str,
22533+ tsk->comm, task_pid_nr(tsk), str,
22534 regs->ip, regs->sp, error_code);
22535 print_vma_addr(" in ", regs->ip);
22536 pr_cont("\n");
22537@@ -266,7 +272,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
22538 conditional_sti(regs);
22539
22540 #ifdef CONFIG_X86_32
22541- if (regs->flags & X86_VM_MASK) {
22542+ if (v8086_mode(regs)) {
22543 local_irq_enable();
22544 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
22545 goto exit;
22546@@ -274,18 +280,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
22547 #endif
22548
22549 tsk = current;
22550- if (!user_mode(regs)) {
22551+ if (!user_mode_novm(regs)) {
22552 if (fixup_exception(regs))
22553 goto exit;
22554
22555 tsk->thread.error_code = error_code;
22556 tsk->thread.trap_nr = X86_TRAP_GP;
22557 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
22558- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
22559+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
22560+
22561+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22562+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
22563+ die("PAX: suspicious general protection fault", regs, error_code);
22564+ else
22565+#endif
22566+
22567 die("general protection fault", regs, error_code);
22568+ }
22569 goto exit;
22570 }
22571
22572+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
22573+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
22574+ struct mm_struct *mm = tsk->mm;
22575+ unsigned long limit;
22576+
22577+ down_write(&mm->mmap_sem);
22578+ limit = mm->context.user_cs_limit;
22579+ if (limit < TASK_SIZE) {
22580+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
22581+ up_write(&mm->mmap_sem);
22582+ return;
22583+ }
22584+ up_write(&mm->mmap_sem);
22585+ }
22586+#endif
22587+
22588 tsk->thread.error_code = error_code;
22589 tsk->thread.trap_nr = X86_TRAP_GP;
22590
22591@@ -440,7 +470,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
22592 /* It's safe to allow irq's after DR6 has been saved */
22593 preempt_conditional_sti(regs);
22594
22595- if (regs->flags & X86_VM_MASK) {
22596+ if (v8086_mode(regs)) {
22597 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
22598 X86_TRAP_DB);
22599 preempt_conditional_cli(regs);
22600@@ -455,7 +485,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
22601 * We already checked v86 mode above, so we can check for kernel mode
22602 * by just checking the CPL of CS.
22603 */
22604- if ((dr6 & DR_STEP) && !user_mode(regs)) {
22605+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
22606 tsk->thread.debugreg6 &= ~DR_STEP;
22607 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
22608 regs->flags &= ~X86_EFLAGS_TF;
22609@@ -487,7 +517,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
22610 return;
22611 conditional_sti(regs);
22612
22613- if (!user_mode_vm(regs))
22614+ if (!user_mode(regs))
22615 {
22616 if (!fixup_exception(regs)) {
22617 task->thread.error_code = error_code;
22618diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
22619index c71025b..b117501 100644
22620--- a/arch/x86/kernel/uprobes.c
22621+++ b/arch/x86/kernel/uprobes.c
22622@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
22623 int ret = NOTIFY_DONE;
22624
22625 /* We are only interested in userspace traps */
22626- if (regs && !user_mode_vm(regs))
22627+ if (regs && !user_mode(regs))
22628 return NOTIFY_DONE;
22629
22630 switch (val) {
22631diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
22632index b9242ba..50c5edd 100644
22633--- a/arch/x86/kernel/verify_cpu.S
22634+++ b/arch/x86/kernel/verify_cpu.S
22635@@ -20,6 +20,7 @@
22636 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
22637 * arch/x86/kernel/trampoline_64.S: secondary processor verification
22638 * arch/x86/kernel/head_32.S: processor startup
22639+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
22640 *
22641 * verify_cpu, returns the status of longmode and SSE in register %eax.
22642 * 0: Success 1: Failure
22643diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
22644index 1dfe69c..a3df6f6 100644
22645--- a/arch/x86/kernel/vm86_32.c
22646+++ b/arch/x86/kernel/vm86_32.c
22647@@ -43,6 +43,7 @@
22648 #include <linux/ptrace.h>
22649 #include <linux/audit.h>
22650 #include <linux/stddef.h>
22651+#include <linux/grsecurity.h>
22652
22653 #include <asm/uaccess.h>
22654 #include <asm/io.h>
22655@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
22656 do_exit(SIGSEGV);
22657 }
22658
22659- tss = &per_cpu(init_tss, get_cpu());
22660+ tss = init_tss + get_cpu();
22661 current->thread.sp0 = current->thread.saved_sp0;
22662 current->thread.sysenter_cs = __KERNEL_CS;
22663 load_sp0(tss, &current->thread);
22664@@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
22665 struct task_struct *tsk;
22666 int tmp, ret = -EPERM;
22667
22668+#ifdef CONFIG_GRKERNSEC_VM86
22669+ if (!capable(CAP_SYS_RAWIO)) {
22670+ gr_handle_vm86();
22671+ goto out;
22672+ }
22673+#endif
22674+
22675 tsk = current;
22676 if (tsk->thread.saved_sp0)
22677 goto out;
22678@@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
22679 int tmp, ret;
22680 struct vm86plus_struct __user *v86;
22681
22682+#ifdef CONFIG_GRKERNSEC_VM86
22683+ if (!capable(CAP_SYS_RAWIO)) {
22684+ gr_handle_vm86();
22685+ ret = -EPERM;
22686+ goto out;
22687+ }
22688+#endif
22689+
22690 tsk = current;
22691 switch (cmd) {
22692 case VM86_REQUEST_IRQ:
22693@@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
22694 tsk->thread.saved_fs = info->regs32->fs;
22695 tsk->thread.saved_gs = get_user_gs(info->regs32);
22696
22697- tss = &per_cpu(init_tss, get_cpu());
22698+ tss = init_tss + get_cpu();
22699 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
22700 if (cpu_has_sep)
22701 tsk->thread.sysenter_cs = 0;
22702@@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
22703 goto cannot_handle;
22704 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
22705 goto cannot_handle;
22706- intr_ptr = (unsigned long __user *) (i << 2);
22707+ intr_ptr = (__force unsigned long __user *) (i << 2);
22708 if (get_user(segoffs, intr_ptr))
22709 goto cannot_handle;
22710 if ((segoffs >> 16) == BIOSSEG)
22711diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
22712index 22a1530..8fbaaad 100644
22713--- a/arch/x86/kernel/vmlinux.lds.S
22714+++ b/arch/x86/kernel/vmlinux.lds.S
22715@@ -26,6 +26,13 @@
22716 #include <asm/page_types.h>
22717 #include <asm/cache.h>
22718 #include <asm/boot.h>
22719+#include <asm/segment.h>
22720+
22721+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22722+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
22723+#else
22724+#define __KERNEL_TEXT_OFFSET 0
22725+#endif
22726
22727 #undef i386 /* in case the preprocessor is a 32bit one */
22728
22729@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
22730
22731 PHDRS {
22732 text PT_LOAD FLAGS(5); /* R_E */
22733+#ifdef CONFIG_X86_32
22734+ module PT_LOAD FLAGS(5); /* R_E */
22735+#endif
22736+#ifdef CONFIG_XEN
22737+ rodata PT_LOAD FLAGS(5); /* R_E */
22738+#else
22739+ rodata PT_LOAD FLAGS(4); /* R__ */
22740+#endif
22741 data PT_LOAD FLAGS(6); /* RW_ */
22742-#ifdef CONFIG_X86_64
22743+ init.begin PT_LOAD FLAGS(6); /* RW_ */
22744 #ifdef CONFIG_SMP
22745 percpu PT_LOAD FLAGS(6); /* RW_ */
22746 #endif
22747+ text.init PT_LOAD FLAGS(5); /* R_E */
22748+ text.exit PT_LOAD FLAGS(5); /* R_E */
22749 init PT_LOAD FLAGS(7); /* RWE */
22750-#endif
22751 note PT_NOTE FLAGS(0); /* ___ */
22752 }
22753
22754 SECTIONS
22755 {
22756 #ifdef CONFIG_X86_32
22757- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
22758- phys_startup_32 = startup_32 - LOAD_OFFSET;
22759+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
22760 #else
22761- . = __START_KERNEL;
22762- phys_startup_64 = startup_64 - LOAD_OFFSET;
22763+ . = __START_KERNEL;
22764 #endif
22765
22766 /* Text and read-only data */
22767- .text : AT(ADDR(.text) - LOAD_OFFSET) {
22768- _text = .;
22769+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
22770 /* bootstrapping code */
22771+#ifdef CONFIG_X86_32
22772+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
22773+#else
22774+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
22775+#endif
22776+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
22777+ _text = .;
22778 HEAD_TEXT
22779 #ifdef CONFIG_X86_32
22780 . = ALIGN(PAGE_SIZE);
22781@@ -108,13 +128,48 @@ SECTIONS
22782 IRQENTRY_TEXT
22783 *(.fixup)
22784 *(.gnu.warning)
22785- /* End of text section */
22786- _etext = .;
22787 } :text = 0x9090
22788
22789- NOTES :text :note
22790+ . += __KERNEL_TEXT_OFFSET;
22791
22792- EXCEPTION_TABLE(16) :text = 0x9090
22793+#ifdef CONFIG_X86_32
22794+ . = ALIGN(PAGE_SIZE);
22795+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
22796+
22797+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
22798+ MODULES_EXEC_VADDR = .;
22799+ BYTE(0)
22800+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
22801+ . = ALIGN(HPAGE_SIZE) - 1;
22802+ MODULES_EXEC_END = .;
22803+#endif
22804+
22805+ } :module
22806+#endif
22807+
22808+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
22809+ /* End of text section */
22810+ BYTE(0)
22811+ _etext = . - __KERNEL_TEXT_OFFSET;
22812+ }
22813+
22814+#ifdef CONFIG_X86_32
22815+ . = ALIGN(PAGE_SIZE);
22816+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
22817+ *(.idt)
22818+ . = ALIGN(PAGE_SIZE);
22819+ *(.empty_zero_page)
22820+ *(.initial_pg_fixmap)
22821+ *(.initial_pg_pmd)
22822+ *(.initial_page_table)
22823+ *(.swapper_pg_dir)
22824+ } :rodata
22825+#endif
22826+
22827+ . = ALIGN(PAGE_SIZE);
22828+ NOTES :rodata :note
22829+
22830+ EXCEPTION_TABLE(16) :rodata
22831
22832 #if defined(CONFIG_DEBUG_RODATA)
22833 /* .text should occupy whole number of pages */
22834@@ -126,16 +181,20 @@ SECTIONS
22835
22836 /* Data */
22837 .data : AT(ADDR(.data) - LOAD_OFFSET) {
22838+
22839+#ifdef CONFIG_PAX_KERNEXEC
22840+ . = ALIGN(HPAGE_SIZE);
22841+#else
22842+ . = ALIGN(PAGE_SIZE);
22843+#endif
22844+
22845 /* Start of data section */
22846 _sdata = .;
22847
22848 /* init_task */
22849 INIT_TASK_DATA(THREAD_SIZE)
22850
22851-#ifdef CONFIG_X86_32
22852- /* 32 bit has nosave before _edata */
22853 NOSAVE_DATA
22854-#endif
22855
22856 PAGE_ALIGNED_DATA(PAGE_SIZE)
22857
22858@@ -176,12 +235,19 @@ SECTIONS
22859 #endif /* CONFIG_X86_64 */
22860
22861 /* Init code and data - will be freed after init */
22862- . = ALIGN(PAGE_SIZE);
22863 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
22864+ BYTE(0)
22865+
22866+#ifdef CONFIG_PAX_KERNEXEC
22867+ . = ALIGN(HPAGE_SIZE);
22868+#else
22869+ . = ALIGN(PAGE_SIZE);
22870+#endif
22871+
22872 __init_begin = .; /* paired with __init_end */
22873- }
22874+ } :init.begin
22875
22876-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
22877+#ifdef CONFIG_SMP
22878 /*
22879 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
22880 * output PHDR, so the next output section - .init.text - should
22881@@ -190,12 +256,27 @@ SECTIONS
22882 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
22883 #endif
22884
22885- INIT_TEXT_SECTION(PAGE_SIZE)
22886-#ifdef CONFIG_X86_64
22887- :init
22888-#endif
22889+ . = ALIGN(PAGE_SIZE);
22890+ init_begin = .;
22891+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
22892+ VMLINUX_SYMBOL(_sinittext) = .;
22893+ INIT_TEXT
22894+ VMLINUX_SYMBOL(_einittext) = .;
22895+ . = ALIGN(PAGE_SIZE);
22896+ } :text.init
22897
22898- INIT_DATA_SECTION(16)
22899+ /*
22900+ * .exit.text is discard at runtime, not link time, to deal with
22901+ * references from .altinstructions and .eh_frame
22902+ */
22903+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
22904+ EXIT_TEXT
22905+ . = ALIGN(16);
22906+ } :text.exit
22907+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
22908+
22909+ . = ALIGN(PAGE_SIZE);
22910+ INIT_DATA_SECTION(16) :init
22911
22912 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
22913 __x86_cpu_dev_start = .;
22914@@ -257,19 +338,12 @@ SECTIONS
22915 }
22916
22917 . = ALIGN(8);
22918- /*
22919- * .exit.text is discard at runtime, not link time, to deal with
22920- * references from .altinstructions and .eh_frame
22921- */
22922- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
22923- EXIT_TEXT
22924- }
22925
22926 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
22927 EXIT_DATA
22928 }
22929
22930-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
22931+#ifndef CONFIG_SMP
22932 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
22933 #endif
22934
22935@@ -288,16 +362,10 @@ SECTIONS
22936 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
22937 __smp_locks = .;
22938 *(.smp_locks)
22939- . = ALIGN(PAGE_SIZE);
22940 __smp_locks_end = .;
22941+ . = ALIGN(PAGE_SIZE);
22942 }
22943
22944-#ifdef CONFIG_X86_64
22945- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
22946- NOSAVE_DATA
22947- }
22948-#endif
22949-
22950 /* BSS */
22951 . = ALIGN(PAGE_SIZE);
22952 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
22953@@ -313,6 +381,7 @@ SECTIONS
22954 __brk_base = .;
22955 . += 64 * 1024; /* 64k alignment slop space */
22956 *(.brk_reservation) /* areas brk users have reserved */
22957+ . = ALIGN(HPAGE_SIZE);
22958 __brk_limit = .;
22959 }
22960
22961@@ -339,13 +408,12 @@ SECTIONS
22962 * for the boot processor.
22963 */
22964 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
22965-INIT_PER_CPU(gdt_page);
22966 INIT_PER_CPU(irq_stack_union);
22967
22968 /*
22969 * Build-time check on the image size:
22970 */
22971-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
22972+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
22973 "kernel image bigger than KERNEL_IMAGE_SIZE");
22974
22975 #ifdef CONFIG_SMP
22976diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
22977index 9a907a6..f83f921 100644
22978--- a/arch/x86/kernel/vsyscall_64.c
22979+++ b/arch/x86/kernel/vsyscall_64.c
22980@@ -56,15 +56,13 @@
22981 DEFINE_VVAR(int, vgetcpu_mode);
22982 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
22983
22984-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
22985+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
22986
22987 static int __init vsyscall_setup(char *str)
22988 {
22989 if (str) {
22990 if (!strcmp("emulate", str))
22991 vsyscall_mode = EMULATE;
22992- else if (!strcmp("native", str))
22993- vsyscall_mode = NATIVE;
22994 else if (!strcmp("none", str))
22995 vsyscall_mode = NONE;
22996 else
22997@@ -323,8 +321,7 @@ do_ret:
22998 return true;
22999
23000 sigsegv:
23001- force_sig(SIGSEGV, current);
23002- return true;
23003+ do_group_exit(SIGKILL);
23004 }
23005
23006 /*
23007@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
23008 extern char __vvar_page;
23009 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
23010
23011- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
23012- vsyscall_mode == NATIVE
23013- ? PAGE_KERNEL_VSYSCALL
23014- : PAGE_KERNEL_VVAR);
23015+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
23016 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
23017 (unsigned long)VSYSCALL_START);
23018
23019diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
23020index 1330dd1..d220b99 100644
23021--- a/arch/x86/kernel/x8664_ksyms_64.c
23022+++ b/arch/x86/kernel/x8664_ksyms_64.c
23023@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
23024 EXPORT_SYMBOL(copy_user_generic_unrolled);
23025 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
23026 EXPORT_SYMBOL(__copy_user_nocache);
23027-EXPORT_SYMBOL(_copy_from_user);
23028-EXPORT_SYMBOL(_copy_to_user);
23029
23030 EXPORT_SYMBOL(copy_page);
23031 EXPORT_SYMBOL(clear_page);
23032diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
23033index 7a3d075..6cb373d 100644
23034--- a/arch/x86/kernel/x86_init.c
23035+++ b/arch/x86/kernel/x86_init.c
23036@@ -88,7 +88,7 @@ struct x86_init_ops x86_init __initdata = {
23037 },
23038 };
23039
23040-struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23041+struct x86_cpuinit_ops x86_cpuinit __cpuinitconst = {
23042 .early_percpu_clock_init = x86_init_noop,
23043 .setup_percpu_clockev = setup_secondary_APIC_clock,
23044 };
23045@@ -96,7 +96,7 @@ struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23046 static void default_nmi_init(void) { };
23047 static int default_i8042_detect(void) { return 1; };
23048
23049-struct x86_platform_ops x86_platform = {
23050+struct x86_platform_ops x86_platform __read_only = {
23051 .calibrate_tsc = native_calibrate_tsc,
23052 .get_wallclock = mach_get_cmos_time,
23053 .set_wallclock = mach_set_rtc_mmss,
23054@@ -110,14 +110,14 @@ struct x86_platform_ops x86_platform = {
23055 };
23056
23057 EXPORT_SYMBOL_GPL(x86_platform);
23058-struct x86_msi_ops x86_msi = {
23059+struct x86_msi_ops x86_msi __read_only = {
23060 .setup_msi_irqs = native_setup_msi_irqs,
23061 .teardown_msi_irq = native_teardown_msi_irq,
23062 .teardown_msi_irqs = default_teardown_msi_irqs,
23063 .restore_msi_irqs = default_restore_msi_irqs,
23064 };
23065
23066-struct x86_io_apic_ops x86_io_apic_ops = {
23067+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
23068 .init = native_io_apic_init_mappings,
23069 .read = native_io_apic_read,
23070 .write = native_io_apic_write,
23071diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
23072index ada87a3..afea76d 100644
23073--- a/arch/x86/kernel/xsave.c
23074+++ b/arch/x86/kernel/xsave.c
23075@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
23076 {
23077 int err;
23078
23079+ buf = (struct xsave_struct __user *)____m(buf);
23080 if (use_xsave())
23081 err = xsave_user(buf);
23082 else if (use_fxsr())
23083@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
23084 */
23085 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
23086 {
23087+ buf = (void __user *)____m(buf);
23088 if (use_xsave()) {
23089 if ((unsigned long)buf % 64 || fx_only) {
23090 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
23091diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
23092index a20ecb5..d0e2194 100644
23093--- a/arch/x86/kvm/cpuid.c
23094+++ b/arch/x86/kvm/cpuid.c
23095@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
23096 struct kvm_cpuid2 *cpuid,
23097 struct kvm_cpuid_entry2 __user *entries)
23098 {
23099- int r;
23100+ int r, i;
23101
23102 r = -E2BIG;
23103 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
23104 goto out;
23105 r = -EFAULT;
23106- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
23107- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23108+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23109 goto out;
23110+ for (i = 0; i < cpuid->nent; ++i) {
23111+ struct kvm_cpuid_entry2 cpuid_entry;
23112+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
23113+ goto out;
23114+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
23115+ }
23116 vcpu->arch.cpuid_nent = cpuid->nent;
23117 kvm_apic_set_version(vcpu);
23118 kvm_x86_ops->cpuid_update(vcpu);
23119@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
23120 struct kvm_cpuid2 *cpuid,
23121 struct kvm_cpuid_entry2 __user *entries)
23122 {
23123- int r;
23124+ int r, i;
23125
23126 r = -E2BIG;
23127 if (cpuid->nent < vcpu->arch.cpuid_nent)
23128 goto out;
23129 r = -EFAULT;
23130- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
23131- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
23132+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
23133 goto out;
23134+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
23135+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
23136+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
23137+ goto out;
23138+ }
23139 return 0;
23140
23141 out:
23142diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
23143index a27e763..54bfe43 100644
23144--- a/arch/x86/kvm/emulate.c
23145+++ b/arch/x86/kvm/emulate.c
23146@@ -292,6 +292,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23147
23148 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
23149 do { \
23150+ unsigned long _tmp; \
23151 __asm__ __volatile__ ( \
23152 _PRE_EFLAGS("0", "4", "2") \
23153 _op _suffix " %"_x"3,%1; " \
23154@@ -306,8 +307,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23155 /* Raw emulation: instruction has two explicit operands. */
23156 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
23157 do { \
23158- unsigned long _tmp; \
23159- \
23160 switch ((ctxt)->dst.bytes) { \
23161 case 2: \
23162 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
23163@@ -323,7 +322,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23164
23165 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
23166 do { \
23167- unsigned long _tmp; \
23168 switch ((ctxt)->dst.bytes) { \
23169 case 1: \
23170 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
23171diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
23172index 9392f52..0e56d77 100644
23173--- a/arch/x86/kvm/lapic.c
23174+++ b/arch/x86/kvm/lapic.c
23175@@ -55,7 +55,7 @@
23176 #define APIC_BUS_CYCLE_NS 1
23177
23178 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
23179-#define apic_debug(fmt, arg...)
23180+#define apic_debug(fmt, arg...) do {} while (0)
23181
23182 #define APIC_LVT_NUM 6
23183 /* 14 is the version for Xeon and Pentium 8.4.8*/
23184diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
23185index 891eb6d..e027900 100644
23186--- a/arch/x86/kvm/paging_tmpl.h
23187+++ b/arch/x86/kvm/paging_tmpl.h
23188@@ -208,7 +208,7 @@ retry_walk:
23189 if (unlikely(kvm_is_error_hva(host_addr)))
23190 goto error;
23191
23192- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
23193+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
23194 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
23195 goto error;
23196 walker->ptep_user[walker->level - 1] = ptep_user;
23197diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
23198index d29d3cd..ec9d522 100644
23199--- a/arch/x86/kvm/svm.c
23200+++ b/arch/x86/kvm/svm.c
23201@@ -3507,7 +3507,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
23202 int cpu = raw_smp_processor_id();
23203
23204 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
23205+
23206+ pax_open_kernel();
23207 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
23208+ pax_close_kernel();
23209+
23210 load_TR_desc();
23211 }
23212
23213@@ -3881,6 +3885,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
23214 #endif
23215 #endif
23216
23217+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
23218+ __set_fs(current_thread_info()->addr_limit);
23219+#endif
23220+
23221 reload_tss(vcpu);
23222
23223 local_irq_disable();
23224diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
23225index 9120ae1..238abc0 100644
23226--- a/arch/x86/kvm/vmx.c
23227+++ b/arch/x86/kvm/vmx.c
23228@@ -1370,7 +1370,11 @@ static void reload_tss(void)
23229 struct desc_struct *descs;
23230
23231 descs = (void *)gdt->address;
23232+
23233+ pax_open_kernel();
23234 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
23235+ pax_close_kernel();
23236+
23237 load_TR_desc();
23238 }
23239
23240@@ -1594,6 +1598,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
23241 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
23242 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
23243
23244+#ifdef CONFIG_PAX_PER_CPU_PGD
23245+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
23246+#endif
23247+
23248 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
23249 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
23250 vmx->loaded_vmcs->cpu = cpu;
23251@@ -2738,8 +2746,11 @@ static __init int hardware_setup(void)
23252 if (!cpu_has_vmx_flexpriority())
23253 flexpriority_enabled = 0;
23254
23255- if (!cpu_has_vmx_tpr_shadow())
23256- kvm_x86_ops->update_cr8_intercept = NULL;
23257+ if (!cpu_has_vmx_tpr_shadow()) {
23258+ pax_open_kernel();
23259+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
23260+ pax_close_kernel();
23261+ }
23262
23263 if (enable_ept && !cpu_has_vmx_ept_2m_page())
23264 kvm_disable_largepages();
23265@@ -3782,7 +3793,10 @@ static void vmx_set_constant_host_state(void)
23266
23267 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
23268 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
23269+
23270+#ifndef CONFIG_PAX_PER_CPU_PGD
23271 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
23272+#endif
23273
23274 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
23275 #ifdef CONFIG_X86_64
23276@@ -3803,7 +3817,7 @@ static void vmx_set_constant_host_state(void)
23277 native_store_idt(&dt);
23278 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
23279
23280- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
23281+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
23282
23283 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
23284 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
23285@@ -6355,6 +6369,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23286 "jmp 2f \n\t"
23287 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
23288 "2: "
23289+
23290+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23291+ "ljmp %[cs],$3f\n\t"
23292+ "3: "
23293+#endif
23294+
23295 /* Save guest registers, load host registers, keep flags */
23296 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
23297 "pop %0 \n\t"
23298@@ -6407,6 +6427,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23299 #endif
23300 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
23301 [wordsize]"i"(sizeof(ulong))
23302+
23303+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23304+ ,[cs]"i"(__KERNEL_CS)
23305+#endif
23306+
23307 : "cc", "memory"
23308 #ifdef CONFIG_X86_64
23309 , "rax", "rbx", "rdi", "rsi"
23310@@ -6420,7 +6445,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23311 if (debugctlmsr)
23312 update_debugctlmsr(debugctlmsr);
23313
23314-#ifndef CONFIG_X86_64
23315+#ifdef CONFIG_X86_32
23316 /*
23317 * The sysexit path does not restore ds/es, so we must set them to
23318 * a reasonable value ourselves.
23319@@ -6429,8 +6454,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23320 * may be executed in interrupt context, which saves and restore segments
23321 * around it, nullifying its effect.
23322 */
23323- loadsegment(ds, __USER_DS);
23324- loadsegment(es, __USER_DS);
23325+ loadsegment(ds, __KERNEL_DS);
23326+ loadsegment(es, __KERNEL_DS);
23327+ loadsegment(ss, __KERNEL_DS);
23328+
23329+#ifdef CONFIG_PAX_KERNEXEC
23330+ loadsegment(fs, __KERNEL_PERCPU);
23331+#endif
23332+
23333+#ifdef CONFIG_PAX_MEMORY_UDEREF
23334+ __set_fs(current_thread_info()->addr_limit);
23335+#endif
23336+
23337 #endif
23338
23339 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
23340diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
23341index c243b81..9eb193f 100644
23342--- a/arch/x86/kvm/x86.c
23343+++ b/arch/x86/kvm/x86.c
23344@@ -1692,8 +1692,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
23345 {
23346 struct kvm *kvm = vcpu->kvm;
23347 int lm = is_long_mode(vcpu);
23348- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
23349- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
23350+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
23351+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
23352 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
23353 : kvm->arch.xen_hvm_config.blob_size_32;
23354 u32 page_num = data & ~PAGE_MASK;
23355@@ -2571,6 +2571,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
23356 if (n < msr_list.nmsrs)
23357 goto out;
23358 r = -EFAULT;
23359+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
23360+ goto out;
23361 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
23362 num_msrs_to_save * sizeof(u32)))
23363 goto out;
23364@@ -2700,7 +2702,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
23365 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
23366 struct kvm_interrupt *irq)
23367 {
23368- if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
23369+ if (irq->irq >= KVM_NR_INTERRUPTS)
23370 return -EINVAL;
23371 if (irqchip_in_kernel(vcpu->kvm))
23372 return -ENXIO;
23373@@ -5213,7 +5215,7 @@ static struct notifier_block pvclock_gtod_notifier = {
23374 };
23375 #endif
23376
23377-int kvm_arch_init(void *opaque)
23378+int kvm_arch_init(const void *opaque)
23379 {
23380 int r;
23381 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
23382diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
23383index df4176c..23ce092 100644
23384--- a/arch/x86/lguest/boot.c
23385+++ b/arch/x86/lguest/boot.c
23386@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
23387 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
23388 * Launcher to reboot us.
23389 */
23390-static void lguest_restart(char *reason)
23391+static __noreturn void lguest_restart(char *reason)
23392 {
23393 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
23394+ BUG();
23395 }
23396
23397 /*G:050
23398diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
23399index 00933d5..3a64af9 100644
23400--- a/arch/x86/lib/atomic64_386_32.S
23401+++ b/arch/x86/lib/atomic64_386_32.S
23402@@ -48,6 +48,10 @@ BEGIN(read)
23403 movl (v), %eax
23404 movl 4(v), %edx
23405 RET_ENDP
23406+BEGIN(read_unchecked)
23407+ movl (v), %eax
23408+ movl 4(v), %edx
23409+RET_ENDP
23410 #undef v
23411
23412 #define v %esi
23413@@ -55,6 +59,10 @@ BEGIN(set)
23414 movl %ebx, (v)
23415 movl %ecx, 4(v)
23416 RET_ENDP
23417+BEGIN(set_unchecked)
23418+ movl %ebx, (v)
23419+ movl %ecx, 4(v)
23420+RET_ENDP
23421 #undef v
23422
23423 #define v %esi
23424@@ -70,6 +78,20 @@ RET_ENDP
23425 BEGIN(add)
23426 addl %eax, (v)
23427 adcl %edx, 4(v)
23428+
23429+#ifdef CONFIG_PAX_REFCOUNT
23430+ jno 0f
23431+ subl %eax, (v)
23432+ sbbl %edx, 4(v)
23433+ int $4
23434+0:
23435+ _ASM_EXTABLE(0b, 0b)
23436+#endif
23437+
23438+RET_ENDP
23439+BEGIN(add_unchecked)
23440+ addl %eax, (v)
23441+ adcl %edx, 4(v)
23442 RET_ENDP
23443 #undef v
23444
23445@@ -77,6 +99,24 @@ RET_ENDP
23446 BEGIN(add_return)
23447 addl (v), %eax
23448 adcl 4(v), %edx
23449+
23450+#ifdef CONFIG_PAX_REFCOUNT
23451+ into
23452+1234:
23453+ _ASM_EXTABLE(1234b, 2f)
23454+#endif
23455+
23456+ movl %eax, (v)
23457+ movl %edx, 4(v)
23458+
23459+#ifdef CONFIG_PAX_REFCOUNT
23460+2:
23461+#endif
23462+
23463+RET_ENDP
23464+BEGIN(add_return_unchecked)
23465+ addl (v), %eax
23466+ adcl 4(v), %edx
23467 movl %eax, (v)
23468 movl %edx, 4(v)
23469 RET_ENDP
23470@@ -86,6 +126,20 @@ RET_ENDP
23471 BEGIN(sub)
23472 subl %eax, (v)
23473 sbbl %edx, 4(v)
23474+
23475+#ifdef CONFIG_PAX_REFCOUNT
23476+ jno 0f
23477+ addl %eax, (v)
23478+ adcl %edx, 4(v)
23479+ int $4
23480+0:
23481+ _ASM_EXTABLE(0b, 0b)
23482+#endif
23483+
23484+RET_ENDP
23485+BEGIN(sub_unchecked)
23486+ subl %eax, (v)
23487+ sbbl %edx, 4(v)
23488 RET_ENDP
23489 #undef v
23490
23491@@ -96,6 +150,27 @@ BEGIN(sub_return)
23492 sbbl $0, %edx
23493 addl (v), %eax
23494 adcl 4(v), %edx
23495+
23496+#ifdef CONFIG_PAX_REFCOUNT
23497+ into
23498+1234:
23499+ _ASM_EXTABLE(1234b, 2f)
23500+#endif
23501+
23502+ movl %eax, (v)
23503+ movl %edx, 4(v)
23504+
23505+#ifdef CONFIG_PAX_REFCOUNT
23506+2:
23507+#endif
23508+
23509+RET_ENDP
23510+BEGIN(sub_return_unchecked)
23511+ negl %edx
23512+ negl %eax
23513+ sbbl $0, %edx
23514+ addl (v), %eax
23515+ adcl 4(v), %edx
23516 movl %eax, (v)
23517 movl %edx, 4(v)
23518 RET_ENDP
23519@@ -105,6 +180,20 @@ RET_ENDP
23520 BEGIN(inc)
23521 addl $1, (v)
23522 adcl $0, 4(v)
23523+
23524+#ifdef CONFIG_PAX_REFCOUNT
23525+ jno 0f
23526+ subl $1, (v)
23527+ sbbl $0, 4(v)
23528+ int $4
23529+0:
23530+ _ASM_EXTABLE(0b, 0b)
23531+#endif
23532+
23533+RET_ENDP
23534+BEGIN(inc_unchecked)
23535+ addl $1, (v)
23536+ adcl $0, 4(v)
23537 RET_ENDP
23538 #undef v
23539
23540@@ -114,6 +203,26 @@ BEGIN(inc_return)
23541 movl 4(v), %edx
23542 addl $1, %eax
23543 adcl $0, %edx
23544+
23545+#ifdef CONFIG_PAX_REFCOUNT
23546+ into
23547+1234:
23548+ _ASM_EXTABLE(1234b, 2f)
23549+#endif
23550+
23551+ movl %eax, (v)
23552+ movl %edx, 4(v)
23553+
23554+#ifdef CONFIG_PAX_REFCOUNT
23555+2:
23556+#endif
23557+
23558+RET_ENDP
23559+BEGIN(inc_return_unchecked)
23560+ movl (v), %eax
23561+ movl 4(v), %edx
23562+ addl $1, %eax
23563+ adcl $0, %edx
23564 movl %eax, (v)
23565 movl %edx, 4(v)
23566 RET_ENDP
23567@@ -123,6 +232,20 @@ RET_ENDP
23568 BEGIN(dec)
23569 subl $1, (v)
23570 sbbl $0, 4(v)
23571+
23572+#ifdef CONFIG_PAX_REFCOUNT
23573+ jno 0f
23574+ addl $1, (v)
23575+ adcl $0, 4(v)
23576+ int $4
23577+0:
23578+ _ASM_EXTABLE(0b, 0b)
23579+#endif
23580+
23581+RET_ENDP
23582+BEGIN(dec_unchecked)
23583+ subl $1, (v)
23584+ sbbl $0, 4(v)
23585 RET_ENDP
23586 #undef v
23587
23588@@ -132,6 +255,26 @@ BEGIN(dec_return)
23589 movl 4(v), %edx
23590 subl $1, %eax
23591 sbbl $0, %edx
23592+
23593+#ifdef CONFIG_PAX_REFCOUNT
23594+ into
23595+1234:
23596+ _ASM_EXTABLE(1234b, 2f)
23597+#endif
23598+
23599+ movl %eax, (v)
23600+ movl %edx, 4(v)
23601+
23602+#ifdef CONFIG_PAX_REFCOUNT
23603+2:
23604+#endif
23605+
23606+RET_ENDP
23607+BEGIN(dec_return_unchecked)
23608+ movl (v), %eax
23609+ movl 4(v), %edx
23610+ subl $1, %eax
23611+ sbbl $0, %edx
23612 movl %eax, (v)
23613 movl %edx, 4(v)
23614 RET_ENDP
23615@@ -143,6 +286,13 @@ BEGIN(add_unless)
23616 adcl %edx, %edi
23617 addl (v), %eax
23618 adcl 4(v), %edx
23619+
23620+#ifdef CONFIG_PAX_REFCOUNT
23621+ into
23622+1234:
23623+ _ASM_EXTABLE(1234b, 2f)
23624+#endif
23625+
23626 cmpl %eax, %ecx
23627 je 3f
23628 1:
23629@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
23630 1:
23631 addl $1, %eax
23632 adcl $0, %edx
23633+
23634+#ifdef CONFIG_PAX_REFCOUNT
23635+ into
23636+1234:
23637+ _ASM_EXTABLE(1234b, 2f)
23638+#endif
23639+
23640 movl %eax, (v)
23641 movl %edx, 4(v)
23642 movl $1, %eax
23643@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
23644 movl 4(v), %edx
23645 subl $1, %eax
23646 sbbl $0, %edx
23647+
23648+#ifdef CONFIG_PAX_REFCOUNT
23649+ into
23650+1234:
23651+ _ASM_EXTABLE(1234b, 1f)
23652+#endif
23653+
23654 js 1f
23655 movl %eax, (v)
23656 movl %edx, 4(v)
23657diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
23658index f5cc9eb..51fa319 100644
23659--- a/arch/x86/lib/atomic64_cx8_32.S
23660+++ b/arch/x86/lib/atomic64_cx8_32.S
23661@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
23662 CFI_STARTPROC
23663
23664 read64 %ecx
23665+ pax_force_retaddr
23666 ret
23667 CFI_ENDPROC
23668 ENDPROC(atomic64_read_cx8)
23669
23670+ENTRY(atomic64_read_unchecked_cx8)
23671+ CFI_STARTPROC
23672+
23673+ read64 %ecx
23674+ pax_force_retaddr
23675+ ret
23676+ CFI_ENDPROC
23677+ENDPROC(atomic64_read_unchecked_cx8)
23678+
23679 ENTRY(atomic64_set_cx8)
23680 CFI_STARTPROC
23681
23682@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
23683 cmpxchg8b (%esi)
23684 jne 1b
23685
23686+ pax_force_retaddr
23687 ret
23688 CFI_ENDPROC
23689 ENDPROC(atomic64_set_cx8)
23690
23691+ENTRY(atomic64_set_unchecked_cx8)
23692+ CFI_STARTPROC
23693+
23694+1:
23695+/* we don't need LOCK_PREFIX since aligned 64-bit writes
23696+ * are atomic on 586 and newer */
23697+ cmpxchg8b (%esi)
23698+ jne 1b
23699+
23700+ pax_force_retaddr
23701+ ret
23702+ CFI_ENDPROC
23703+ENDPROC(atomic64_set_unchecked_cx8)
23704+
23705 ENTRY(atomic64_xchg_cx8)
23706 CFI_STARTPROC
23707
23708@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
23709 cmpxchg8b (%esi)
23710 jne 1b
23711
23712+ pax_force_retaddr
23713 ret
23714 CFI_ENDPROC
23715 ENDPROC(atomic64_xchg_cx8)
23716
23717-.macro addsub_return func ins insc
23718-ENTRY(atomic64_\func\()_return_cx8)
23719+.macro addsub_return func ins insc unchecked=""
23720+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
23721 CFI_STARTPROC
23722 SAVE ebp
23723 SAVE ebx
23724@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
23725 movl %edx, %ecx
23726 \ins\()l %esi, %ebx
23727 \insc\()l %edi, %ecx
23728+
23729+.ifb \unchecked
23730+#ifdef CONFIG_PAX_REFCOUNT
23731+ into
23732+2:
23733+ _ASM_EXTABLE(2b, 3f)
23734+#endif
23735+.endif
23736+
23737 LOCK_PREFIX
23738 cmpxchg8b (%ebp)
23739 jne 1b
23740-
23741-10:
23742 movl %ebx, %eax
23743 movl %ecx, %edx
23744+
23745+.ifb \unchecked
23746+#ifdef CONFIG_PAX_REFCOUNT
23747+3:
23748+#endif
23749+.endif
23750+
23751 RESTORE edi
23752 RESTORE esi
23753 RESTORE ebx
23754 RESTORE ebp
23755+ pax_force_retaddr
23756 ret
23757 CFI_ENDPROC
23758-ENDPROC(atomic64_\func\()_return_cx8)
23759+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
23760 .endm
23761
23762 addsub_return add add adc
23763 addsub_return sub sub sbb
23764+addsub_return add add adc _unchecked
23765+addsub_return sub sub sbb _unchecked
23766
23767-.macro incdec_return func ins insc
23768-ENTRY(atomic64_\func\()_return_cx8)
23769+.macro incdec_return func ins insc unchecked=""
23770+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
23771 CFI_STARTPROC
23772 SAVE ebx
23773
23774@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
23775 movl %edx, %ecx
23776 \ins\()l $1, %ebx
23777 \insc\()l $0, %ecx
23778+
23779+.ifb \unchecked
23780+#ifdef CONFIG_PAX_REFCOUNT
23781+ into
23782+2:
23783+ _ASM_EXTABLE(2b, 3f)
23784+#endif
23785+.endif
23786+
23787 LOCK_PREFIX
23788 cmpxchg8b (%esi)
23789 jne 1b
23790
23791-10:
23792 movl %ebx, %eax
23793 movl %ecx, %edx
23794+
23795+.ifb \unchecked
23796+#ifdef CONFIG_PAX_REFCOUNT
23797+3:
23798+#endif
23799+.endif
23800+
23801 RESTORE ebx
23802+ pax_force_retaddr
23803 ret
23804 CFI_ENDPROC
23805-ENDPROC(atomic64_\func\()_return_cx8)
23806+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
23807 .endm
23808
23809 incdec_return inc add adc
23810 incdec_return dec sub sbb
23811+incdec_return inc add adc _unchecked
23812+incdec_return dec sub sbb _unchecked
23813
23814 ENTRY(atomic64_dec_if_positive_cx8)
23815 CFI_STARTPROC
23816@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
23817 movl %edx, %ecx
23818 subl $1, %ebx
23819 sbb $0, %ecx
23820+
23821+#ifdef CONFIG_PAX_REFCOUNT
23822+ into
23823+1234:
23824+ _ASM_EXTABLE(1234b, 2f)
23825+#endif
23826+
23827 js 2f
23828 LOCK_PREFIX
23829 cmpxchg8b (%esi)
23830@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
23831 movl %ebx, %eax
23832 movl %ecx, %edx
23833 RESTORE ebx
23834+ pax_force_retaddr
23835 ret
23836 CFI_ENDPROC
23837 ENDPROC(atomic64_dec_if_positive_cx8)
23838@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
23839 movl %edx, %ecx
23840 addl %ebp, %ebx
23841 adcl %edi, %ecx
23842+
23843+#ifdef CONFIG_PAX_REFCOUNT
23844+ into
23845+1234:
23846+ _ASM_EXTABLE(1234b, 3f)
23847+#endif
23848+
23849 LOCK_PREFIX
23850 cmpxchg8b (%esi)
23851 jne 1b
23852@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
23853 CFI_ADJUST_CFA_OFFSET -8
23854 RESTORE ebx
23855 RESTORE ebp
23856+ pax_force_retaddr
23857 ret
23858 4:
23859 cmpl %edx, 4(%esp)
23860@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
23861 xorl %ecx, %ecx
23862 addl $1, %ebx
23863 adcl %edx, %ecx
23864+
23865+#ifdef CONFIG_PAX_REFCOUNT
23866+ into
23867+1234:
23868+ _ASM_EXTABLE(1234b, 3f)
23869+#endif
23870+
23871 LOCK_PREFIX
23872 cmpxchg8b (%esi)
23873 jne 1b
23874@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
23875 movl $1, %eax
23876 3:
23877 RESTORE ebx
23878+ pax_force_retaddr
23879 ret
23880 CFI_ENDPROC
23881 ENDPROC(atomic64_inc_not_zero_cx8)
23882diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
23883index 2af5df3..62b1a5a 100644
23884--- a/arch/x86/lib/checksum_32.S
23885+++ b/arch/x86/lib/checksum_32.S
23886@@ -29,7 +29,8 @@
23887 #include <asm/dwarf2.h>
23888 #include <asm/errno.h>
23889 #include <asm/asm.h>
23890-
23891+#include <asm/segment.h>
23892+
23893 /*
23894 * computes a partial checksum, e.g. for TCP/UDP fragments
23895 */
23896@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
23897
23898 #define ARGBASE 16
23899 #define FP 12
23900-
23901-ENTRY(csum_partial_copy_generic)
23902+
23903+ENTRY(csum_partial_copy_generic_to_user)
23904 CFI_STARTPROC
23905+
23906+#ifdef CONFIG_PAX_MEMORY_UDEREF
23907+ pushl_cfi %gs
23908+ popl_cfi %es
23909+ jmp csum_partial_copy_generic
23910+#endif
23911+
23912+ENTRY(csum_partial_copy_generic_from_user)
23913+
23914+#ifdef CONFIG_PAX_MEMORY_UDEREF
23915+ pushl_cfi %gs
23916+ popl_cfi %ds
23917+#endif
23918+
23919+ENTRY(csum_partial_copy_generic)
23920 subl $4,%esp
23921 CFI_ADJUST_CFA_OFFSET 4
23922 pushl_cfi %edi
23923@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
23924 jmp 4f
23925 SRC(1: movw (%esi), %bx )
23926 addl $2, %esi
23927-DST( movw %bx, (%edi) )
23928+DST( movw %bx, %es:(%edi) )
23929 addl $2, %edi
23930 addw %bx, %ax
23931 adcl $0, %eax
23932@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
23933 SRC(1: movl (%esi), %ebx )
23934 SRC( movl 4(%esi), %edx )
23935 adcl %ebx, %eax
23936-DST( movl %ebx, (%edi) )
23937+DST( movl %ebx, %es:(%edi) )
23938 adcl %edx, %eax
23939-DST( movl %edx, 4(%edi) )
23940+DST( movl %edx, %es:4(%edi) )
23941
23942 SRC( movl 8(%esi), %ebx )
23943 SRC( movl 12(%esi), %edx )
23944 adcl %ebx, %eax
23945-DST( movl %ebx, 8(%edi) )
23946+DST( movl %ebx, %es:8(%edi) )
23947 adcl %edx, %eax
23948-DST( movl %edx, 12(%edi) )
23949+DST( movl %edx, %es:12(%edi) )
23950
23951 SRC( movl 16(%esi), %ebx )
23952 SRC( movl 20(%esi), %edx )
23953 adcl %ebx, %eax
23954-DST( movl %ebx, 16(%edi) )
23955+DST( movl %ebx, %es:16(%edi) )
23956 adcl %edx, %eax
23957-DST( movl %edx, 20(%edi) )
23958+DST( movl %edx, %es:20(%edi) )
23959
23960 SRC( movl 24(%esi), %ebx )
23961 SRC( movl 28(%esi), %edx )
23962 adcl %ebx, %eax
23963-DST( movl %ebx, 24(%edi) )
23964+DST( movl %ebx, %es:24(%edi) )
23965 adcl %edx, %eax
23966-DST( movl %edx, 28(%edi) )
23967+DST( movl %edx, %es:28(%edi) )
23968
23969 lea 32(%esi), %esi
23970 lea 32(%edi), %edi
23971@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
23972 shrl $2, %edx # This clears CF
23973 SRC(3: movl (%esi), %ebx )
23974 adcl %ebx, %eax
23975-DST( movl %ebx, (%edi) )
23976+DST( movl %ebx, %es:(%edi) )
23977 lea 4(%esi), %esi
23978 lea 4(%edi), %edi
23979 dec %edx
23980@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
23981 jb 5f
23982 SRC( movw (%esi), %cx )
23983 leal 2(%esi), %esi
23984-DST( movw %cx, (%edi) )
23985+DST( movw %cx, %es:(%edi) )
23986 leal 2(%edi), %edi
23987 je 6f
23988 shll $16,%ecx
23989 SRC(5: movb (%esi), %cl )
23990-DST( movb %cl, (%edi) )
23991+DST( movb %cl, %es:(%edi) )
23992 6: addl %ecx, %eax
23993 adcl $0, %eax
23994 7:
23995@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
23996
23997 6001:
23998 movl ARGBASE+20(%esp), %ebx # src_err_ptr
23999- movl $-EFAULT, (%ebx)
24000+ movl $-EFAULT, %ss:(%ebx)
24001
24002 # zero the complete destination - computing the rest
24003 # is too much work
24004@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
24005
24006 6002:
24007 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24008- movl $-EFAULT,(%ebx)
24009+ movl $-EFAULT,%ss:(%ebx)
24010 jmp 5000b
24011
24012 .previous
24013
24014+ pushl_cfi %ss
24015+ popl_cfi %ds
24016+ pushl_cfi %ss
24017+ popl_cfi %es
24018 popl_cfi %ebx
24019 CFI_RESTORE ebx
24020 popl_cfi %esi
24021@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
24022 popl_cfi %ecx # equivalent to addl $4,%esp
24023 ret
24024 CFI_ENDPROC
24025-ENDPROC(csum_partial_copy_generic)
24026+ENDPROC(csum_partial_copy_generic_to_user)
24027
24028 #else
24029
24030 /* Version for PentiumII/PPro */
24031
24032 #define ROUND1(x) \
24033+ nop; nop; nop; \
24034 SRC(movl x(%esi), %ebx ) ; \
24035 addl %ebx, %eax ; \
24036- DST(movl %ebx, x(%edi) ) ;
24037+ DST(movl %ebx, %es:x(%edi)) ;
24038
24039 #define ROUND(x) \
24040+ nop; nop; nop; \
24041 SRC(movl x(%esi), %ebx ) ; \
24042 adcl %ebx, %eax ; \
24043- DST(movl %ebx, x(%edi) ) ;
24044+ DST(movl %ebx, %es:x(%edi)) ;
24045
24046 #define ARGBASE 12
24047-
24048-ENTRY(csum_partial_copy_generic)
24049+
24050+ENTRY(csum_partial_copy_generic_to_user)
24051 CFI_STARTPROC
24052+
24053+#ifdef CONFIG_PAX_MEMORY_UDEREF
24054+ pushl_cfi %gs
24055+ popl_cfi %es
24056+ jmp csum_partial_copy_generic
24057+#endif
24058+
24059+ENTRY(csum_partial_copy_generic_from_user)
24060+
24061+#ifdef CONFIG_PAX_MEMORY_UDEREF
24062+ pushl_cfi %gs
24063+ popl_cfi %ds
24064+#endif
24065+
24066+ENTRY(csum_partial_copy_generic)
24067 pushl_cfi %ebx
24068 CFI_REL_OFFSET ebx, 0
24069 pushl_cfi %edi
24070@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
24071 subl %ebx, %edi
24072 lea -1(%esi),%edx
24073 andl $-32,%edx
24074- lea 3f(%ebx,%ebx), %ebx
24075+ lea 3f(%ebx,%ebx,2), %ebx
24076 testl %esi, %esi
24077 jmp *%ebx
24078 1: addl $64,%esi
24079@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
24080 jb 5f
24081 SRC( movw (%esi), %dx )
24082 leal 2(%esi), %esi
24083-DST( movw %dx, (%edi) )
24084+DST( movw %dx, %es:(%edi) )
24085 leal 2(%edi), %edi
24086 je 6f
24087 shll $16,%edx
24088 5:
24089 SRC( movb (%esi), %dl )
24090-DST( movb %dl, (%edi) )
24091+DST( movb %dl, %es:(%edi) )
24092 6: addl %edx, %eax
24093 adcl $0, %eax
24094 7:
24095 .section .fixup, "ax"
24096 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
24097- movl $-EFAULT, (%ebx)
24098+ movl $-EFAULT, %ss:(%ebx)
24099 # zero the complete destination (computing the rest is too much work)
24100 movl ARGBASE+8(%esp),%edi # dst
24101 movl ARGBASE+12(%esp),%ecx # len
24102@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
24103 rep; stosb
24104 jmp 7b
24105 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24106- movl $-EFAULT, (%ebx)
24107+ movl $-EFAULT, %ss:(%ebx)
24108 jmp 7b
24109 .previous
24110
24111+#ifdef CONFIG_PAX_MEMORY_UDEREF
24112+ pushl_cfi %ss
24113+ popl_cfi %ds
24114+ pushl_cfi %ss
24115+ popl_cfi %es
24116+#endif
24117+
24118 popl_cfi %esi
24119 CFI_RESTORE esi
24120 popl_cfi %edi
24121@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
24122 CFI_RESTORE ebx
24123 ret
24124 CFI_ENDPROC
24125-ENDPROC(csum_partial_copy_generic)
24126+ENDPROC(csum_partial_copy_generic_to_user)
24127
24128 #undef ROUND
24129 #undef ROUND1
24130diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
24131index f2145cf..cea889d 100644
24132--- a/arch/x86/lib/clear_page_64.S
24133+++ b/arch/x86/lib/clear_page_64.S
24134@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
24135 movl $4096/8,%ecx
24136 xorl %eax,%eax
24137 rep stosq
24138+ pax_force_retaddr
24139 ret
24140 CFI_ENDPROC
24141 ENDPROC(clear_page_c)
24142@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
24143 movl $4096,%ecx
24144 xorl %eax,%eax
24145 rep stosb
24146+ pax_force_retaddr
24147 ret
24148 CFI_ENDPROC
24149 ENDPROC(clear_page_c_e)
24150@@ -43,6 +45,7 @@ ENTRY(clear_page)
24151 leaq 64(%rdi),%rdi
24152 jnz .Lloop
24153 nop
24154+ pax_force_retaddr
24155 ret
24156 CFI_ENDPROC
24157 .Lclear_page_end:
24158@@ -58,7 +61,7 @@ ENDPROC(clear_page)
24159
24160 #include <asm/cpufeature.h>
24161
24162- .section .altinstr_replacement,"ax"
24163+ .section .altinstr_replacement,"a"
24164 1: .byte 0xeb /* jmp <disp8> */
24165 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
24166 2: .byte 0xeb /* jmp <disp8> */
24167diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
24168index 1e572c5..2a162cd 100644
24169--- a/arch/x86/lib/cmpxchg16b_emu.S
24170+++ b/arch/x86/lib/cmpxchg16b_emu.S
24171@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
24172
24173 popf
24174 mov $1, %al
24175+ pax_force_retaddr
24176 ret
24177
24178 not_same:
24179 popf
24180 xor %al,%al
24181+ pax_force_retaddr
24182 ret
24183
24184 CFI_ENDPROC
24185diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
24186index 176cca6..1166c50 100644
24187--- a/arch/x86/lib/copy_page_64.S
24188+++ b/arch/x86/lib/copy_page_64.S
24189@@ -9,6 +9,7 @@ copy_page_rep:
24190 CFI_STARTPROC
24191 movl $4096/8, %ecx
24192 rep movsq
24193+ pax_force_retaddr
24194 ret
24195 CFI_ENDPROC
24196 ENDPROC(copy_page_rep)
24197@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
24198
24199 ENTRY(copy_page)
24200 CFI_STARTPROC
24201- subq $2*8, %rsp
24202- CFI_ADJUST_CFA_OFFSET 2*8
24203+ subq $3*8, %rsp
24204+ CFI_ADJUST_CFA_OFFSET 3*8
24205 movq %rbx, (%rsp)
24206 CFI_REL_OFFSET rbx, 0
24207 movq %r12, 1*8(%rsp)
24208 CFI_REL_OFFSET r12, 1*8
24209+ movq %r13, 2*8(%rsp)
24210+ CFI_REL_OFFSET r13, 2*8
24211
24212 movl $(4096/64)-5, %ecx
24213 .p2align 4
24214@@ -36,7 +39,7 @@ ENTRY(copy_page)
24215 movq 0x8*2(%rsi), %rdx
24216 movq 0x8*3(%rsi), %r8
24217 movq 0x8*4(%rsi), %r9
24218- movq 0x8*5(%rsi), %r10
24219+ movq 0x8*5(%rsi), %r13
24220 movq 0x8*6(%rsi), %r11
24221 movq 0x8*7(%rsi), %r12
24222
24223@@ -47,7 +50,7 @@ ENTRY(copy_page)
24224 movq %rdx, 0x8*2(%rdi)
24225 movq %r8, 0x8*3(%rdi)
24226 movq %r9, 0x8*4(%rdi)
24227- movq %r10, 0x8*5(%rdi)
24228+ movq %r13, 0x8*5(%rdi)
24229 movq %r11, 0x8*6(%rdi)
24230 movq %r12, 0x8*7(%rdi)
24231
24232@@ -66,7 +69,7 @@ ENTRY(copy_page)
24233 movq 0x8*2(%rsi), %rdx
24234 movq 0x8*3(%rsi), %r8
24235 movq 0x8*4(%rsi), %r9
24236- movq 0x8*5(%rsi), %r10
24237+ movq 0x8*5(%rsi), %r13
24238 movq 0x8*6(%rsi), %r11
24239 movq 0x8*7(%rsi), %r12
24240
24241@@ -75,7 +78,7 @@ ENTRY(copy_page)
24242 movq %rdx, 0x8*2(%rdi)
24243 movq %r8, 0x8*3(%rdi)
24244 movq %r9, 0x8*4(%rdi)
24245- movq %r10, 0x8*5(%rdi)
24246+ movq %r13, 0x8*5(%rdi)
24247 movq %r11, 0x8*6(%rdi)
24248 movq %r12, 0x8*7(%rdi)
24249
24250@@ -87,8 +90,11 @@ ENTRY(copy_page)
24251 CFI_RESTORE rbx
24252 movq 1*8(%rsp), %r12
24253 CFI_RESTORE r12
24254- addq $2*8, %rsp
24255- CFI_ADJUST_CFA_OFFSET -2*8
24256+ movq 2*8(%rsp), %r13
24257+ CFI_RESTORE r13
24258+ addq $3*8, %rsp
24259+ CFI_ADJUST_CFA_OFFSET -3*8
24260+ pax_force_retaddr
24261 ret
24262 .Lcopy_page_end:
24263 CFI_ENDPROC
24264@@ -99,7 +105,7 @@ ENDPROC(copy_page)
24265
24266 #include <asm/cpufeature.h>
24267
24268- .section .altinstr_replacement,"ax"
24269+ .section .altinstr_replacement,"a"
24270 1: .byte 0xeb /* jmp <disp8> */
24271 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
24272 2:
24273diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
24274index a30ca15..d25fab6 100644
24275--- a/arch/x86/lib/copy_user_64.S
24276+++ b/arch/x86/lib/copy_user_64.S
24277@@ -18,6 +18,7 @@
24278 #include <asm/alternative-asm.h>
24279 #include <asm/asm.h>
24280 #include <asm/smap.h>
24281+#include <asm/pgtable.h>
24282
24283 /*
24284 * By placing feature2 after feature1 in altinstructions section, we logically
24285@@ -31,7 +32,7 @@
24286 .byte 0xe9 /* 32bit jump */
24287 .long \orig-1f /* by default jump to orig */
24288 1:
24289- .section .altinstr_replacement,"ax"
24290+ .section .altinstr_replacement,"a"
24291 2: .byte 0xe9 /* near jump with 32bit immediate */
24292 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
24293 3: .byte 0xe9 /* near jump with 32bit immediate */
24294@@ -70,47 +71,20 @@
24295 #endif
24296 .endm
24297
24298-/* Standard copy_to_user with segment limit checking */
24299-ENTRY(_copy_to_user)
24300- CFI_STARTPROC
24301- GET_THREAD_INFO(%rax)
24302- movq %rdi,%rcx
24303- addq %rdx,%rcx
24304- jc bad_to_user
24305- cmpq TI_addr_limit(%rax),%rcx
24306- ja bad_to_user
24307- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
24308- copy_user_generic_unrolled,copy_user_generic_string, \
24309- copy_user_enhanced_fast_string
24310- CFI_ENDPROC
24311-ENDPROC(_copy_to_user)
24312-
24313-/* Standard copy_from_user with segment limit checking */
24314-ENTRY(_copy_from_user)
24315- CFI_STARTPROC
24316- GET_THREAD_INFO(%rax)
24317- movq %rsi,%rcx
24318- addq %rdx,%rcx
24319- jc bad_from_user
24320- cmpq TI_addr_limit(%rax),%rcx
24321- ja bad_from_user
24322- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
24323- copy_user_generic_unrolled,copy_user_generic_string, \
24324- copy_user_enhanced_fast_string
24325- CFI_ENDPROC
24326-ENDPROC(_copy_from_user)
24327-
24328 .section .fixup,"ax"
24329 /* must zero dest */
24330 ENTRY(bad_from_user)
24331 bad_from_user:
24332 CFI_STARTPROC
24333+ testl %edx,%edx
24334+ js bad_to_user
24335 movl %edx,%ecx
24336 xorl %eax,%eax
24337 rep
24338 stosb
24339 bad_to_user:
24340 movl %edx,%eax
24341+ pax_force_retaddr
24342 ret
24343 CFI_ENDPROC
24344 ENDPROC(bad_from_user)
24345@@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
24346 jz 17f
24347 1: movq (%rsi),%r8
24348 2: movq 1*8(%rsi),%r9
24349-3: movq 2*8(%rsi),%r10
24350+3: movq 2*8(%rsi),%rax
24351 4: movq 3*8(%rsi),%r11
24352 5: movq %r8,(%rdi)
24353 6: movq %r9,1*8(%rdi)
24354-7: movq %r10,2*8(%rdi)
24355+7: movq %rax,2*8(%rdi)
24356 8: movq %r11,3*8(%rdi)
24357 9: movq 4*8(%rsi),%r8
24358 10: movq 5*8(%rsi),%r9
24359-11: movq 6*8(%rsi),%r10
24360+11: movq 6*8(%rsi),%rax
24361 12: movq 7*8(%rsi),%r11
24362 13: movq %r8,4*8(%rdi)
24363 14: movq %r9,5*8(%rdi)
24364-15: movq %r10,6*8(%rdi)
24365+15: movq %rax,6*8(%rdi)
24366 16: movq %r11,7*8(%rdi)
24367 leaq 64(%rsi),%rsi
24368 leaq 64(%rdi),%rdi
24369@@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
24370 jnz 21b
24371 23: xor %eax,%eax
24372 ASM_CLAC
24373+ pax_force_retaddr
24374 ret
24375
24376 .section .fixup,"ax"
24377@@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
24378 movsb
24379 4: xorl %eax,%eax
24380 ASM_CLAC
24381+ pax_force_retaddr
24382 ret
24383
24384 .section .fixup,"ax"
24385@@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
24386 movsb
24387 2: xorl %eax,%eax
24388 ASM_CLAC
24389+ pax_force_retaddr
24390 ret
24391
24392 .section .fixup,"ax"
24393diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
24394index 6a4f43c..f5f9e26 100644
24395--- a/arch/x86/lib/copy_user_nocache_64.S
24396+++ b/arch/x86/lib/copy_user_nocache_64.S
24397@@ -8,6 +8,7 @@
24398
24399 #include <linux/linkage.h>
24400 #include <asm/dwarf2.h>
24401+#include <asm/alternative-asm.h>
24402
24403 #define FIX_ALIGNMENT 1
24404
24405@@ -16,6 +17,7 @@
24406 #include <asm/thread_info.h>
24407 #include <asm/asm.h>
24408 #include <asm/smap.h>
24409+#include <asm/pgtable.h>
24410
24411 .macro ALIGN_DESTINATION
24412 #ifdef FIX_ALIGNMENT
24413@@ -49,6 +51,15 @@
24414 */
24415 ENTRY(__copy_user_nocache)
24416 CFI_STARTPROC
24417+
24418+#ifdef CONFIG_PAX_MEMORY_UDEREF
24419+ mov $PAX_USER_SHADOW_BASE,%rcx
24420+ cmp %rcx,%rsi
24421+ jae 1f
24422+ add %rcx,%rsi
24423+1:
24424+#endif
24425+
24426 ASM_STAC
24427 cmpl $8,%edx
24428 jb 20f /* less then 8 bytes, go to byte copy loop */
24429@@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
24430 jz 17f
24431 1: movq (%rsi),%r8
24432 2: movq 1*8(%rsi),%r9
24433-3: movq 2*8(%rsi),%r10
24434+3: movq 2*8(%rsi),%rax
24435 4: movq 3*8(%rsi),%r11
24436 5: movnti %r8,(%rdi)
24437 6: movnti %r9,1*8(%rdi)
24438-7: movnti %r10,2*8(%rdi)
24439+7: movnti %rax,2*8(%rdi)
24440 8: movnti %r11,3*8(%rdi)
24441 9: movq 4*8(%rsi),%r8
24442 10: movq 5*8(%rsi),%r9
24443-11: movq 6*8(%rsi),%r10
24444+11: movq 6*8(%rsi),%rax
24445 12: movq 7*8(%rsi),%r11
24446 13: movnti %r8,4*8(%rdi)
24447 14: movnti %r9,5*8(%rdi)
24448-15: movnti %r10,6*8(%rdi)
24449+15: movnti %rax,6*8(%rdi)
24450 16: movnti %r11,7*8(%rdi)
24451 leaq 64(%rsi),%rsi
24452 leaq 64(%rdi),%rdi
24453@@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
24454 23: xorl %eax,%eax
24455 ASM_CLAC
24456 sfence
24457+ pax_force_retaddr
24458 ret
24459
24460 .section .fixup,"ax"
24461diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
24462index 2419d5f..953ee51 100644
24463--- a/arch/x86/lib/csum-copy_64.S
24464+++ b/arch/x86/lib/csum-copy_64.S
24465@@ -9,6 +9,7 @@
24466 #include <asm/dwarf2.h>
24467 #include <asm/errno.h>
24468 #include <asm/asm.h>
24469+#include <asm/alternative-asm.h>
24470
24471 /*
24472 * Checksum copy with exception handling.
24473@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
24474 CFI_RESTORE rbp
24475 addq $7*8, %rsp
24476 CFI_ADJUST_CFA_OFFSET -7*8
24477+ pax_force_retaddr 0, 1
24478 ret
24479 CFI_RESTORE_STATE
24480
24481diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
24482index 25b7ae8..169fafc 100644
24483--- a/arch/x86/lib/csum-wrappers_64.c
24484+++ b/arch/x86/lib/csum-wrappers_64.c
24485@@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
24486 len -= 2;
24487 }
24488 }
24489- isum = csum_partial_copy_generic((__force const void *)src,
24490+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
24491 dst, len, isum, errp, NULL);
24492 if (unlikely(*errp))
24493 goto out_err;
24494@@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
24495 }
24496
24497 *errp = 0;
24498- return csum_partial_copy_generic(src, (void __force *)dst,
24499+ return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
24500 len, isum, NULL, errp);
24501 }
24502 EXPORT_SYMBOL(csum_partial_copy_to_user);
24503diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
24504index 156b9c8..b144132 100644
24505--- a/arch/x86/lib/getuser.S
24506+++ b/arch/x86/lib/getuser.S
24507@@ -34,17 +34,40 @@
24508 #include <asm/thread_info.h>
24509 #include <asm/asm.h>
24510 #include <asm/smap.h>
24511+#include <asm/segment.h>
24512+#include <asm/pgtable.h>
24513+#include <asm/alternative-asm.h>
24514+
24515+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
24516+#define __copyuser_seg gs;
24517+#else
24518+#define __copyuser_seg
24519+#endif
24520
24521 .text
24522 ENTRY(__get_user_1)
24523 CFI_STARTPROC
24524+
24525+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24526 GET_THREAD_INFO(%_ASM_DX)
24527 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24528 jae bad_get_user
24529 ASM_STAC
24530-1: movzb (%_ASM_AX),%edx
24531+
24532+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24533+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24534+ cmp %_ASM_DX,%_ASM_AX
24535+ jae 1234f
24536+ add %_ASM_DX,%_ASM_AX
24537+1234:
24538+#endif
24539+
24540+#endif
24541+
24542+1: __copyuser_seg movzb (%_ASM_AX),%edx
24543 xor %eax,%eax
24544 ASM_CLAC
24545+ pax_force_retaddr
24546 ret
24547 CFI_ENDPROC
24548 ENDPROC(__get_user_1)
24549@@ -52,14 +75,28 @@ ENDPROC(__get_user_1)
24550 ENTRY(__get_user_2)
24551 CFI_STARTPROC
24552 add $1,%_ASM_AX
24553+
24554+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24555 jc bad_get_user
24556 GET_THREAD_INFO(%_ASM_DX)
24557 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24558 jae bad_get_user
24559 ASM_STAC
24560-2: movzwl -1(%_ASM_AX),%edx
24561+
24562+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24563+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24564+ cmp %_ASM_DX,%_ASM_AX
24565+ jae 1234f
24566+ add %_ASM_DX,%_ASM_AX
24567+1234:
24568+#endif
24569+
24570+#endif
24571+
24572+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
24573 xor %eax,%eax
24574 ASM_CLAC
24575+ pax_force_retaddr
24576 ret
24577 CFI_ENDPROC
24578 ENDPROC(__get_user_2)
24579@@ -67,14 +104,28 @@ ENDPROC(__get_user_2)
24580 ENTRY(__get_user_4)
24581 CFI_STARTPROC
24582 add $3,%_ASM_AX
24583+
24584+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24585 jc bad_get_user
24586 GET_THREAD_INFO(%_ASM_DX)
24587 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24588 jae bad_get_user
24589 ASM_STAC
24590-3: mov -3(%_ASM_AX),%edx
24591+
24592+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24593+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24594+ cmp %_ASM_DX,%_ASM_AX
24595+ jae 1234f
24596+ add %_ASM_DX,%_ASM_AX
24597+1234:
24598+#endif
24599+
24600+#endif
24601+
24602+3: __copyuser_seg mov -3(%_ASM_AX),%edx
24603 xor %eax,%eax
24604 ASM_CLAC
24605+ pax_force_retaddr
24606 ret
24607 CFI_ENDPROC
24608 ENDPROC(__get_user_4)
24609@@ -87,10 +138,20 @@ ENTRY(__get_user_8)
24610 GET_THREAD_INFO(%_ASM_DX)
24611 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24612 jae bad_get_user
24613+
24614+#ifdef CONFIG_PAX_MEMORY_UDEREF
24615+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24616+ cmp %_ASM_DX,%_ASM_AX
24617+ jae 1234f
24618+ add %_ASM_DX,%_ASM_AX
24619+1234:
24620+#endif
24621+
24622 ASM_STAC
24623 4: movq -7(%_ASM_AX),%_ASM_DX
24624 xor %eax,%eax
24625 ASM_CLAC
24626+ pax_force_retaddr
24627 ret
24628 CFI_ENDPROC
24629 ENDPROC(__get_user_8)
24630@@ -101,6 +162,7 @@ bad_get_user:
24631 xor %edx,%edx
24632 mov $(-EFAULT),%_ASM_AX
24633 ASM_CLAC
24634+ pax_force_retaddr
24635 ret
24636 CFI_ENDPROC
24637 END(bad_get_user)
24638diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
24639index 54fcffe..7be149e 100644
24640--- a/arch/x86/lib/insn.c
24641+++ b/arch/x86/lib/insn.c
24642@@ -20,8 +20,10 @@
24643
24644 #ifdef __KERNEL__
24645 #include <linux/string.h>
24646+#include <asm/pgtable_types.h>
24647 #else
24648 #include <string.h>
24649+#define ktla_ktva(addr) addr
24650 #endif
24651 #include <asm/inat.h>
24652 #include <asm/insn.h>
24653@@ -53,8 +55,8 @@
24654 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
24655 {
24656 memset(insn, 0, sizeof(*insn));
24657- insn->kaddr = kaddr;
24658- insn->next_byte = kaddr;
24659+ insn->kaddr = ktla_ktva(kaddr);
24660+ insn->next_byte = ktla_ktva(kaddr);
24661 insn->x86_64 = x86_64 ? 1 : 0;
24662 insn->opnd_bytes = 4;
24663 if (x86_64)
24664diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
24665index 05a95e7..326f2fa 100644
24666--- a/arch/x86/lib/iomap_copy_64.S
24667+++ b/arch/x86/lib/iomap_copy_64.S
24668@@ -17,6 +17,7 @@
24669
24670 #include <linux/linkage.h>
24671 #include <asm/dwarf2.h>
24672+#include <asm/alternative-asm.h>
24673
24674 /*
24675 * override generic version in lib/iomap_copy.c
24676@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
24677 CFI_STARTPROC
24678 movl %edx,%ecx
24679 rep movsd
24680+ pax_force_retaddr
24681 ret
24682 CFI_ENDPROC
24683 ENDPROC(__iowrite32_copy)
24684diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
24685index 1c273be..da9cc0e 100644
24686--- a/arch/x86/lib/memcpy_64.S
24687+++ b/arch/x86/lib/memcpy_64.S
24688@@ -33,6 +33,7 @@
24689 rep movsq
24690 movl %edx, %ecx
24691 rep movsb
24692+ pax_force_retaddr
24693 ret
24694 .Lmemcpy_e:
24695 .previous
24696@@ -49,6 +50,7 @@
24697 movq %rdi, %rax
24698 movq %rdx, %rcx
24699 rep movsb
24700+ pax_force_retaddr
24701 ret
24702 .Lmemcpy_e_e:
24703 .previous
24704@@ -76,13 +78,13 @@ ENTRY(memcpy)
24705 */
24706 movq 0*8(%rsi), %r8
24707 movq 1*8(%rsi), %r9
24708- movq 2*8(%rsi), %r10
24709+ movq 2*8(%rsi), %rcx
24710 movq 3*8(%rsi), %r11
24711 leaq 4*8(%rsi), %rsi
24712
24713 movq %r8, 0*8(%rdi)
24714 movq %r9, 1*8(%rdi)
24715- movq %r10, 2*8(%rdi)
24716+ movq %rcx, 2*8(%rdi)
24717 movq %r11, 3*8(%rdi)
24718 leaq 4*8(%rdi), %rdi
24719 jae .Lcopy_forward_loop
24720@@ -105,12 +107,12 @@ ENTRY(memcpy)
24721 subq $0x20, %rdx
24722 movq -1*8(%rsi), %r8
24723 movq -2*8(%rsi), %r9
24724- movq -3*8(%rsi), %r10
24725+ movq -3*8(%rsi), %rcx
24726 movq -4*8(%rsi), %r11
24727 leaq -4*8(%rsi), %rsi
24728 movq %r8, -1*8(%rdi)
24729 movq %r9, -2*8(%rdi)
24730- movq %r10, -3*8(%rdi)
24731+ movq %rcx, -3*8(%rdi)
24732 movq %r11, -4*8(%rdi)
24733 leaq -4*8(%rdi), %rdi
24734 jae .Lcopy_backward_loop
24735@@ -130,12 +132,13 @@ ENTRY(memcpy)
24736 */
24737 movq 0*8(%rsi), %r8
24738 movq 1*8(%rsi), %r9
24739- movq -2*8(%rsi, %rdx), %r10
24740+ movq -2*8(%rsi, %rdx), %rcx
24741 movq -1*8(%rsi, %rdx), %r11
24742 movq %r8, 0*8(%rdi)
24743 movq %r9, 1*8(%rdi)
24744- movq %r10, -2*8(%rdi, %rdx)
24745+ movq %rcx, -2*8(%rdi, %rdx)
24746 movq %r11, -1*8(%rdi, %rdx)
24747+ pax_force_retaddr
24748 retq
24749 .p2align 4
24750 .Lless_16bytes:
24751@@ -148,6 +151,7 @@ ENTRY(memcpy)
24752 movq -1*8(%rsi, %rdx), %r9
24753 movq %r8, 0*8(%rdi)
24754 movq %r9, -1*8(%rdi, %rdx)
24755+ pax_force_retaddr
24756 retq
24757 .p2align 4
24758 .Lless_8bytes:
24759@@ -161,6 +165,7 @@ ENTRY(memcpy)
24760 movl -4(%rsi, %rdx), %r8d
24761 movl %ecx, (%rdi)
24762 movl %r8d, -4(%rdi, %rdx)
24763+ pax_force_retaddr
24764 retq
24765 .p2align 4
24766 .Lless_3bytes:
24767@@ -179,6 +184,7 @@ ENTRY(memcpy)
24768 movb %cl, (%rdi)
24769
24770 .Lend:
24771+ pax_force_retaddr
24772 retq
24773 CFI_ENDPROC
24774 ENDPROC(memcpy)
24775diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
24776index ee16461..c39c199 100644
24777--- a/arch/x86/lib/memmove_64.S
24778+++ b/arch/x86/lib/memmove_64.S
24779@@ -61,13 +61,13 @@ ENTRY(memmove)
24780 5:
24781 sub $0x20, %rdx
24782 movq 0*8(%rsi), %r11
24783- movq 1*8(%rsi), %r10
24784+ movq 1*8(%rsi), %rcx
24785 movq 2*8(%rsi), %r9
24786 movq 3*8(%rsi), %r8
24787 leaq 4*8(%rsi), %rsi
24788
24789 movq %r11, 0*8(%rdi)
24790- movq %r10, 1*8(%rdi)
24791+ movq %rcx, 1*8(%rdi)
24792 movq %r9, 2*8(%rdi)
24793 movq %r8, 3*8(%rdi)
24794 leaq 4*8(%rdi), %rdi
24795@@ -81,10 +81,10 @@ ENTRY(memmove)
24796 4:
24797 movq %rdx, %rcx
24798 movq -8(%rsi, %rdx), %r11
24799- lea -8(%rdi, %rdx), %r10
24800+ lea -8(%rdi, %rdx), %r9
24801 shrq $3, %rcx
24802 rep movsq
24803- movq %r11, (%r10)
24804+ movq %r11, (%r9)
24805 jmp 13f
24806 .Lmemmove_end_forward:
24807
24808@@ -95,14 +95,14 @@ ENTRY(memmove)
24809 7:
24810 movq %rdx, %rcx
24811 movq (%rsi), %r11
24812- movq %rdi, %r10
24813+ movq %rdi, %r9
24814 leaq -8(%rsi, %rdx), %rsi
24815 leaq -8(%rdi, %rdx), %rdi
24816 shrq $3, %rcx
24817 std
24818 rep movsq
24819 cld
24820- movq %r11, (%r10)
24821+ movq %r11, (%r9)
24822 jmp 13f
24823
24824 /*
24825@@ -127,13 +127,13 @@ ENTRY(memmove)
24826 8:
24827 subq $0x20, %rdx
24828 movq -1*8(%rsi), %r11
24829- movq -2*8(%rsi), %r10
24830+ movq -2*8(%rsi), %rcx
24831 movq -3*8(%rsi), %r9
24832 movq -4*8(%rsi), %r8
24833 leaq -4*8(%rsi), %rsi
24834
24835 movq %r11, -1*8(%rdi)
24836- movq %r10, -2*8(%rdi)
24837+ movq %rcx, -2*8(%rdi)
24838 movq %r9, -3*8(%rdi)
24839 movq %r8, -4*8(%rdi)
24840 leaq -4*8(%rdi), %rdi
24841@@ -151,11 +151,11 @@ ENTRY(memmove)
24842 * Move data from 16 bytes to 31 bytes.
24843 */
24844 movq 0*8(%rsi), %r11
24845- movq 1*8(%rsi), %r10
24846+ movq 1*8(%rsi), %rcx
24847 movq -2*8(%rsi, %rdx), %r9
24848 movq -1*8(%rsi, %rdx), %r8
24849 movq %r11, 0*8(%rdi)
24850- movq %r10, 1*8(%rdi)
24851+ movq %rcx, 1*8(%rdi)
24852 movq %r9, -2*8(%rdi, %rdx)
24853 movq %r8, -1*8(%rdi, %rdx)
24854 jmp 13f
24855@@ -167,9 +167,9 @@ ENTRY(memmove)
24856 * Move data from 8 bytes to 15 bytes.
24857 */
24858 movq 0*8(%rsi), %r11
24859- movq -1*8(%rsi, %rdx), %r10
24860+ movq -1*8(%rsi, %rdx), %r9
24861 movq %r11, 0*8(%rdi)
24862- movq %r10, -1*8(%rdi, %rdx)
24863+ movq %r9, -1*8(%rdi, %rdx)
24864 jmp 13f
24865 10:
24866 cmpq $4, %rdx
24867@@ -178,9 +178,9 @@ ENTRY(memmove)
24868 * Move data from 4 bytes to 7 bytes.
24869 */
24870 movl (%rsi), %r11d
24871- movl -4(%rsi, %rdx), %r10d
24872+ movl -4(%rsi, %rdx), %r9d
24873 movl %r11d, (%rdi)
24874- movl %r10d, -4(%rdi, %rdx)
24875+ movl %r9d, -4(%rdi, %rdx)
24876 jmp 13f
24877 11:
24878 cmp $2, %rdx
24879@@ -189,9 +189,9 @@ ENTRY(memmove)
24880 * Move data from 2 bytes to 3 bytes.
24881 */
24882 movw (%rsi), %r11w
24883- movw -2(%rsi, %rdx), %r10w
24884+ movw -2(%rsi, %rdx), %r9w
24885 movw %r11w, (%rdi)
24886- movw %r10w, -2(%rdi, %rdx)
24887+ movw %r9w, -2(%rdi, %rdx)
24888 jmp 13f
24889 12:
24890 cmp $1, %rdx
24891@@ -202,6 +202,7 @@ ENTRY(memmove)
24892 movb (%rsi), %r11b
24893 movb %r11b, (%rdi)
24894 13:
24895+ pax_force_retaddr
24896 retq
24897 CFI_ENDPROC
24898
24899@@ -210,6 +211,7 @@ ENTRY(memmove)
24900 /* Forward moving data. */
24901 movq %rdx, %rcx
24902 rep movsb
24903+ pax_force_retaddr
24904 retq
24905 .Lmemmove_end_forward_efs:
24906 .previous
24907diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
24908index 2dcb380..963660a 100644
24909--- a/arch/x86/lib/memset_64.S
24910+++ b/arch/x86/lib/memset_64.S
24911@@ -30,6 +30,7 @@
24912 movl %edx,%ecx
24913 rep stosb
24914 movq %r9,%rax
24915+ pax_force_retaddr
24916 ret
24917 .Lmemset_e:
24918 .previous
24919@@ -52,6 +53,7 @@
24920 movq %rdx,%rcx
24921 rep stosb
24922 movq %r9,%rax
24923+ pax_force_retaddr
24924 ret
24925 .Lmemset_e_e:
24926 .previous
24927@@ -59,7 +61,7 @@
24928 ENTRY(memset)
24929 ENTRY(__memset)
24930 CFI_STARTPROC
24931- movq %rdi,%r10
24932+ movq %rdi,%r11
24933
24934 /* expand byte value */
24935 movzbl %sil,%ecx
24936@@ -117,7 +119,8 @@ ENTRY(__memset)
24937 jnz .Lloop_1
24938
24939 .Lende:
24940- movq %r10,%rax
24941+ movq %r11,%rax
24942+ pax_force_retaddr
24943 ret
24944
24945 CFI_RESTORE_STATE
24946diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
24947index c9f2d9b..e7fd2c0 100644
24948--- a/arch/x86/lib/mmx_32.c
24949+++ b/arch/x86/lib/mmx_32.c
24950@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
24951 {
24952 void *p;
24953 int i;
24954+ unsigned long cr0;
24955
24956 if (unlikely(in_interrupt()))
24957 return __memcpy(to, from, len);
24958@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
24959 kernel_fpu_begin();
24960
24961 __asm__ __volatile__ (
24962- "1: prefetch (%0)\n" /* This set is 28 bytes */
24963- " prefetch 64(%0)\n"
24964- " prefetch 128(%0)\n"
24965- " prefetch 192(%0)\n"
24966- " prefetch 256(%0)\n"
24967+ "1: prefetch (%1)\n" /* This set is 28 bytes */
24968+ " prefetch 64(%1)\n"
24969+ " prefetch 128(%1)\n"
24970+ " prefetch 192(%1)\n"
24971+ " prefetch 256(%1)\n"
24972 "2: \n"
24973 ".section .fixup, \"ax\"\n"
24974- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
24975+ "3: \n"
24976+
24977+#ifdef CONFIG_PAX_KERNEXEC
24978+ " movl %%cr0, %0\n"
24979+ " movl %0, %%eax\n"
24980+ " andl $0xFFFEFFFF, %%eax\n"
24981+ " movl %%eax, %%cr0\n"
24982+#endif
24983+
24984+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
24985+
24986+#ifdef CONFIG_PAX_KERNEXEC
24987+ " movl %0, %%cr0\n"
24988+#endif
24989+
24990 " jmp 2b\n"
24991 ".previous\n"
24992 _ASM_EXTABLE(1b, 3b)
24993- : : "r" (from));
24994+ : "=&r" (cr0) : "r" (from) : "ax");
24995
24996 for ( ; i > 5; i--) {
24997 __asm__ __volatile__ (
24998- "1: prefetch 320(%0)\n"
24999- "2: movq (%0), %%mm0\n"
25000- " movq 8(%0), %%mm1\n"
25001- " movq 16(%0), %%mm2\n"
25002- " movq 24(%0), %%mm3\n"
25003- " movq %%mm0, (%1)\n"
25004- " movq %%mm1, 8(%1)\n"
25005- " movq %%mm2, 16(%1)\n"
25006- " movq %%mm3, 24(%1)\n"
25007- " movq 32(%0), %%mm0\n"
25008- " movq 40(%0), %%mm1\n"
25009- " movq 48(%0), %%mm2\n"
25010- " movq 56(%0), %%mm3\n"
25011- " movq %%mm0, 32(%1)\n"
25012- " movq %%mm1, 40(%1)\n"
25013- " movq %%mm2, 48(%1)\n"
25014- " movq %%mm3, 56(%1)\n"
25015+ "1: prefetch 320(%1)\n"
25016+ "2: movq (%1), %%mm0\n"
25017+ " movq 8(%1), %%mm1\n"
25018+ " movq 16(%1), %%mm2\n"
25019+ " movq 24(%1), %%mm3\n"
25020+ " movq %%mm0, (%2)\n"
25021+ " movq %%mm1, 8(%2)\n"
25022+ " movq %%mm2, 16(%2)\n"
25023+ " movq %%mm3, 24(%2)\n"
25024+ " movq 32(%1), %%mm0\n"
25025+ " movq 40(%1), %%mm1\n"
25026+ " movq 48(%1), %%mm2\n"
25027+ " movq 56(%1), %%mm3\n"
25028+ " movq %%mm0, 32(%2)\n"
25029+ " movq %%mm1, 40(%2)\n"
25030+ " movq %%mm2, 48(%2)\n"
25031+ " movq %%mm3, 56(%2)\n"
25032 ".section .fixup, \"ax\"\n"
25033- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25034+ "3:\n"
25035+
25036+#ifdef CONFIG_PAX_KERNEXEC
25037+ " movl %%cr0, %0\n"
25038+ " movl %0, %%eax\n"
25039+ " andl $0xFFFEFFFF, %%eax\n"
25040+ " movl %%eax, %%cr0\n"
25041+#endif
25042+
25043+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25044+
25045+#ifdef CONFIG_PAX_KERNEXEC
25046+ " movl %0, %%cr0\n"
25047+#endif
25048+
25049 " jmp 2b\n"
25050 ".previous\n"
25051 _ASM_EXTABLE(1b, 3b)
25052- : : "r" (from), "r" (to) : "memory");
25053+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25054
25055 from += 64;
25056 to += 64;
25057@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
25058 static void fast_copy_page(void *to, void *from)
25059 {
25060 int i;
25061+ unsigned long cr0;
25062
25063 kernel_fpu_begin();
25064
25065@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
25066 * but that is for later. -AV
25067 */
25068 __asm__ __volatile__(
25069- "1: prefetch (%0)\n"
25070- " prefetch 64(%0)\n"
25071- " prefetch 128(%0)\n"
25072- " prefetch 192(%0)\n"
25073- " prefetch 256(%0)\n"
25074+ "1: prefetch (%1)\n"
25075+ " prefetch 64(%1)\n"
25076+ " prefetch 128(%1)\n"
25077+ " prefetch 192(%1)\n"
25078+ " prefetch 256(%1)\n"
25079 "2: \n"
25080 ".section .fixup, \"ax\"\n"
25081- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25082+ "3: \n"
25083+
25084+#ifdef CONFIG_PAX_KERNEXEC
25085+ " movl %%cr0, %0\n"
25086+ " movl %0, %%eax\n"
25087+ " andl $0xFFFEFFFF, %%eax\n"
25088+ " movl %%eax, %%cr0\n"
25089+#endif
25090+
25091+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25092+
25093+#ifdef CONFIG_PAX_KERNEXEC
25094+ " movl %0, %%cr0\n"
25095+#endif
25096+
25097 " jmp 2b\n"
25098 ".previous\n"
25099- _ASM_EXTABLE(1b, 3b) : : "r" (from));
25100+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
25101
25102 for (i = 0; i < (4096-320)/64; i++) {
25103 __asm__ __volatile__ (
25104- "1: prefetch 320(%0)\n"
25105- "2: movq (%0), %%mm0\n"
25106- " movntq %%mm0, (%1)\n"
25107- " movq 8(%0), %%mm1\n"
25108- " movntq %%mm1, 8(%1)\n"
25109- " movq 16(%0), %%mm2\n"
25110- " movntq %%mm2, 16(%1)\n"
25111- " movq 24(%0), %%mm3\n"
25112- " movntq %%mm3, 24(%1)\n"
25113- " movq 32(%0), %%mm4\n"
25114- " movntq %%mm4, 32(%1)\n"
25115- " movq 40(%0), %%mm5\n"
25116- " movntq %%mm5, 40(%1)\n"
25117- " movq 48(%0), %%mm6\n"
25118- " movntq %%mm6, 48(%1)\n"
25119- " movq 56(%0), %%mm7\n"
25120- " movntq %%mm7, 56(%1)\n"
25121+ "1: prefetch 320(%1)\n"
25122+ "2: movq (%1), %%mm0\n"
25123+ " movntq %%mm0, (%2)\n"
25124+ " movq 8(%1), %%mm1\n"
25125+ " movntq %%mm1, 8(%2)\n"
25126+ " movq 16(%1), %%mm2\n"
25127+ " movntq %%mm2, 16(%2)\n"
25128+ " movq 24(%1), %%mm3\n"
25129+ " movntq %%mm3, 24(%2)\n"
25130+ " movq 32(%1), %%mm4\n"
25131+ " movntq %%mm4, 32(%2)\n"
25132+ " movq 40(%1), %%mm5\n"
25133+ " movntq %%mm5, 40(%2)\n"
25134+ " movq 48(%1), %%mm6\n"
25135+ " movntq %%mm6, 48(%2)\n"
25136+ " movq 56(%1), %%mm7\n"
25137+ " movntq %%mm7, 56(%2)\n"
25138 ".section .fixup, \"ax\"\n"
25139- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25140+ "3:\n"
25141+
25142+#ifdef CONFIG_PAX_KERNEXEC
25143+ " movl %%cr0, %0\n"
25144+ " movl %0, %%eax\n"
25145+ " andl $0xFFFEFFFF, %%eax\n"
25146+ " movl %%eax, %%cr0\n"
25147+#endif
25148+
25149+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25150+
25151+#ifdef CONFIG_PAX_KERNEXEC
25152+ " movl %0, %%cr0\n"
25153+#endif
25154+
25155 " jmp 2b\n"
25156 ".previous\n"
25157- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
25158+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25159
25160 from += 64;
25161 to += 64;
25162@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
25163 static void fast_copy_page(void *to, void *from)
25164 {
25165 int i;
25166+ unsigned long cr0;
25167
25168 kernel_fpu_begin();
25169
25170 __asm__ __volatile__ (
25171- "1: prefetch (%0)\n"
25172- " prefetch 64(%0)\n"
25173- " prefetch 128(%0)\n"
25174- " prefetch 192(%0)\n"
25175- " prefetch 256(%0)\n"
25176+ "1: prefetch (%1)\n"
25177+ " prefetch 64(%1)\n"
25178+ " prefetch 128(%1)\n"
25179+ " prefetch 192(%1)\n"
25180+ " prefetch 256(%1)\n"
25181 "2: \n"
25182 ".section .fixup, \"ax\"\n"
25183- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25184+ "3: \n"
25185+
25186+#ifdef CONFIG_PAX_KERNEXEC
25187+ " movl %%cr0, %0\n"
25188+ " movl %0, %%eax\n"
25189+ " andl $0xFFFEFFFF, %%eax\n"
25190+ " movl %%eax, %%cr0\n"
25191+#endif
25192+
25193+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25194+
25195+#ifdef CONFIG_PAX_KERNEXEC
25196+ " movl %0, %%cr0\n"
25197+#endif
25198+
25199 " jmp 2b\n"
25200 ".previous\n"
25201- _ASM_EXTABLE(1b, 3b) : : "r" (from));
25202+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
25203
25204 for (i = 0; i < 4096/64; i++) {
25205 __asm__ __volatile__ (
25206- "1: prefetch 320(%0)\n"
25207- "2: movq (%0), %%mm0\n"
25208- " movq 8(%0), %%mm1\n"
25209- " movq 16(%0), %%mm2\n"
25210- " movq 24(%0), %%mm3\n"
25211- " movq %%mm0, (%1)\n"
25212- " movq %%mm1, 8(%1)\n"
25213- " movq %%mm2, 16(%1)\n"
25214- " movq %%mm3, 24(%1)\n"
25215- " movq 32(%0), %%mm0\n"
25216- " movq 40(%0), %%mm1\n"
25217- " movq 48(%0), %%mm2\n"
25218- " movq 56(%0), %%mm3\n"
25219- " movq %%mm0, 32(%1)\n"
25220- " movq %%mm1, 40(%1)\n"
25221- " movq %%mm2, 48(%1)\n"
25222- " movq %%mm3, 56(%1)\n"
25223+ "1: prefetch 320(%1)\n"
25224+ "2: movq (%1), %%mm0\n"
25225+ " movq 8(%1), %%mm1\n"
25226+ " movq 16(%1), %%mm2\n"
25227+ " movq 24(%1), %%mm3\n"
25228+ " movq %%mm0, (%2)\n"
25229+ " movq %%mm1, 8(%2)\n"
25230+ " movq %%mm2, 16(%2)\n"
25231+ " movq %%mm3, 24(%2)\n"
25232+ " movq 32(%1), %%mm0\n"
25233+ " movq 40(%1), %%mm1\n"
25234+ " movq 48(%1), %%mm2\n"
25235+ " movq 56(%1), %%mm3\n"
25236+ " movq %%mm0, 32(%2)\n"
25237+ " movq %%mm1, 40(%2)\n"
25238+ " movq %%mm2, 48(%2)\n"
25239+ " movq %%mm3, 56(%2)\n"
25240 ".section .fixup, \"ax\"\n"
25241- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25242+ "3:\n"
25243+
25244+#ifdef CONFIG_PAX_KERNEXEC
25245+ " movl %%cr0, %0\n"
25246+ " movl %0, %%eax\n"
25247+ " andl $0xFFFEFFFF, %%eax\n"
25248+ " movl %%eax, %%cr0\n"
25249+#endif
25250+
25251+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25252+
25253+#ifdef CONFIG_PAX_KERNEXEC
25254+ " movl %0, %%cr0\n"
25255+#endif
25256+
25257 " jmp 2b\n"
25258 ".previous\n"
25259 _ASM_EXTABLE(1b, 3b)
25260- : : "r" (from), "r" (to) : "memory");
25261+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25262
25263 from += 64;
25264 to += 64;
25265diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
25266index f6d13ee..aca5f0b 100644
25267--- a/arch/x86/lib/msr-reg.S
25268+++ b/arch/x86/lib/msr-reg.S
25269@@ -3,6 +3,7 @@
25270 #include <asm/dwarf2.h>
25271 #include <asm/asm.h>
25272 #include <asm/msr.h>
25273+#include <asm/alternative-asm.h>
25274
25275 #ifdef CONFIG_X86_64
25276 /*
25277@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
25278 CFI_STARTPROC
25279 pushq_cfi %rbx
25280 pushq_cfi %rbp
25281- movq %rdi, %r10 /* Save pointer */
25282+ movq %rdi, %r9 /* Save pointer */
25283 xorl %r11d, %r11d /* Return value */
25284 movl (%rdi), %eax
25285 movl 4(%rdi), %ecx
25286@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
25287 movl 28(%rdi), %edi
25288 CFI_REMEMBER_STATE
25289 1: \op
25290-2: movl %eax, (%r10)
25291+2: movl %eax, (%r9)
25292 movl %r11d, %eax /* Return value */
25293- movl %ecx, 4(%r10)
25294- movl %edx, 8(%r10)
25295- movl %ebx, 12(%r10)
25296- movl %ebp, 20(%r10)
25297- movl %esi, 24(%r10)
25298- movl %edi, 28(%r10)
25299+ movl %ecx, 4(%r9)
25300+ movl %edx, 8(%r9)
25301+ movl %ebx, 12(%r9)
25302+ movl %ebp, 20(%r9)
25303+ movl %esi, 24(%r9)
25304+ movl %edi, 28(%r9)
25305 popq_cfi %rbp
25306 popq_cfi %rbx
25307+ pax_force_retaddr
25308 ret
25309 3:
25310 CFI_RESTORE_STATE
25311diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
25312index fc6ba17..04471c5 100644
25313--- a/arch/x86/lib/putuser.S
25314+++ b/arch/x86/lib/putuser.S
25315@@ -16,7 +16,9 @@
25316 #include <asm/errno.h>
25317 #include <asm/asm.h>
25318 #include <asm/smap.h>
25319-
25320+#include <asm/segment.h>
25321+#include <asm/pgtable.h>
25322+#include <asm/alternative-asm.h>
25323
25324 /*
25325 * __put_user_X
25326@@ -30,57 +32,125 @@
25327 * as they get called from within inline assembly.
25328 */
25329
25330-#define ENTER CFI_STARTPROC ; \
25331- GET_THREAD_INFO(%_ASM_BX)
25332-#define EXIT ASM_CLAC ; \
25333- ret ; \
25334+#define ENTER CFI_STARTPROC
25335+#define EXIT ASM_CLAC ; \
25336+ pax_force_retaddr ; \
25337+ ret ; \
25338 CFI_ENDPROC
25339
25340+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25341+#define _DEST %_ASM_CX,%_ASM_BX
25342+#else
25343+#define _DEST %_ASM_CX
25344+#endif
25345+
25346+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
25347+#define __copyuser_seg gs;
25348+#else
25349+#define __copyuser_seg
25350+#endif
25351+
25352 .text
25353 ENTRY(__put_user_1)
25354 ENTER
25355+
25356+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25357+ GET_THREAD_INFO(%_ASM_BX)
25358 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
25359 jae bad_put_user
25360 ASM_STAC
25361-1: movb %al,(%_ASM_CX)
25362+
25363+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25364+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25365+ cmp %_ASM_BX,%_ASM_CX
25366+ jb 1234f
25367+ xor %ebx,%ebx
25368+1234:
25369+#endif
25370+
25371+#endif
25372+
25373+1: __copyuser_seg movb %al,(_DEST)
25374 xor %eax,%eax
25375 EXIT
25376 ENDPROC(__put_user_1)
25377
25378 ENTRY(__put_user_2)
25379 ENTER
25380+
25381+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25382+ GET_THREAD_INFO(%_ASM_BX)
25383 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
25384 sub $1,%_ASM_BX
25385 cmp %_ASM_BX,%_ASM_CX
25386 jae bad_put_user
25387 ASM_STAC
25388-2: movw %ax,(%_ASM_CX)
25389+
25390+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25391+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25392+ cmp %_ASM_BX,%_ASM_CX
25393+ jb 1234f
25394+ xor %ebx,%ebx
25395+1234:
25396+#endif
25397+
25398+#endif
25399+
25400+2: __copyuser_seg movw %ax,(_DEST)
25401 xor %eax,%eax
25402 EXIT
25403 ENDPROC(__put_user_2)
25404
25405 ENTRY(__put_user_4)
25406 ENTER
25407+
25408+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25409+ GET_THREAD_INFO(%_ASM_BX)
25410 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
25411 sub $3,%_ASM_BX
25412 cmp %_ASM_BX,%_ASM_CX
25413 jae bad_put_user
25414 ASM_STAC
25415-3: movl %eax,(%_ASM_CX)
25416+
25417+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25418+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25419+ cmp %_ASM_BX,%_ASM_CX
25420+ jb 1234f
25421+ xor %ebx,%ebx
25422+1234:
25423+#endif
25424+
25425+#endif
25426+
25427+3: __copyuser_seg movl %eax,(_DEST)
25428 xor %eax,%eax
25429 EXIT
25430 ENDPROC(__put_user_4)
25431
25432 ENTRY(__put_user_8)
25433 ENTER
25434+
25435+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25436+ GET_THREAD_INFO(%_ASM_BX)
25437 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
25438 sub $7,%_ASM_BX
25439 cmp %_ASM_BX,%_ASM_CX
25440 jae bad_put_user
25441 ASM_STAC
25442-4: mov %_ASM_AX,(%_ASM_CX)
25443+
25444+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25445+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25446+ cmp %_ASM_BX,%_ASM_CX
25447+ jb 1234f
25448+ xor %ebx,%ebx
25449+1234:
25450+#endif
25451+
25452+#endif
25453+
25454+4: __copyuser_seg mov %_ASM_AX,(_DEST)
25455 #ifdef CONFIG_X86_32
25456-5: movl %edx,4(%_ASM_CX)
25457+5: __copyuser_seg movl %edx,4(_DEST)
25458 #endif
25459 xor %eax,%eax
25460 EXIT
25461diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
25462index 1cad221..de671ee 100644
25463--- a/arch/x86/lib/rwlock.S
25464+++ b/arch/x86/lib/rwlock.S
25465@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
25466 FRAME
25467 0: LOCK_PREFIX
25468 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
25469+
25470+#ifdef CONFIG_PAX_REFCOUNT
25471+ jno 1234f
25472+ LOCK_PREFIX
25473+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
25474+ int $4
25475+1234:
25476+ _ASM_EXTABLE(1234b, 1234b)
25477+#endif
25478+
25479 1: rep; nop
25480 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
25481 jne 1b
25482 LOCK_PREFIX
25483 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
25484+
25485+#ifdef CONFIG_PAX_REFCOUNT
25486+ jno 1234f
25487+ LOCK_PREFIX
25488+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
25489+ int $4
25490+1234:
25491+ _ASM_EXTABLE(1234b, 1234b)
25492+#endif
25493+
25494 jnz 0b
25495 ENDFRAME
25496+ pax_force_retaddr
25497 ret
25498 CFI_ENDPROC
25499 END(__write_lock_failed)
25500@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
25501 FRAME
25502 0: LOCK_PREFIX
25503 READ_LOCK_SIZE(inc) (%__lock_ptr)
25504+
25505+#ifdef CONFIG_PAX_REFCOUNT
25506+ jno 1234f
25507+ LOCK_PREFIX
25508+ READ_LOCK_SIZE(dec) (%__lock_ptr)
25509+ int $4
25510+1234:
25511+ _ASM_EXTABLE(1234b, 1234b)
25512+#endif
25513+
25514 1: rep; nop
25515 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
25516 js 1b
25517 LOCK_PREFIX
25518 READ_LOCK_SIZE(dec) (%__lock_ptr)
25519+
25520+#ifdef CONFIG_PAX_REFCOUNT
25521+ jno 1234f
25522+ LOCK_PREFIX
25523+ READ_LOCK_SIZE(inc) (%__lock_ptr)
25524+ int $4
25525+1234:
25526+ _ASM_EXTABLE(1234b, 1234b)
25527+#endif
25528+
25529 js 0b
25530 ENDFRAME
25531+ pax_force_retaddr
25532 ret
25533 CFI_ENDPROC
25534 END(__read_lock_failed)
25535diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
25536index 5dff5f0..cadebf4 100644
25537--- a/arch/x86/lib/rwsem.S
25538+++ b/arch/x86/lib/rwsem.S
25539@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
25540 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
25541 CFI_RESTORE __ASM_REG(dx)
25542 restore_common_regs
25543+ pax_force_retaddr
25544 ret
25545 CFI_ENDPROC
25546 ENDPROC(call_rwsem_down_read_failed)
25547@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
25548 movq %rax,%rdi
25549 call rwsem_down_write_failed
25550 restore_common_regs
25551+ pax_force_retaddr
25552 ret
25553 CFI_ENDPROC
25554 ENDPROC(call_rwsem_down_write_failed)
25555@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
25556 movq %rax,%rdi
25557 call rwsem_wake
25558 restore_common_regs
25559-1: ret
25560+1: pax_force_retaddr
25561+ ret
25562 CFI_ENDPROC
25563 ENDPROC(call_rwsem_wake)
25564
25565@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
25566 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
25567 CFI_RESTORE __ASM_REG(dx)
25568 restore_common_regs
25569+ pax_force_retaddr
25570 ret
25571 CFI_ENDPROC
25572 ENDPROC(call_rwsem_downgrade_wake)
25573diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
25574index a63efd6..ccecad8 100644
25575--- a/arch/x86/lib/thunk_64.S
25576+++ b/arch/x86/lib/thunk_64.S
25577@@ -8,6 +8,7 @@
25578 #include <linux/linkage.h>
25579 #include <asm/dwarf2.h>
25580 #include <asm/calling.h>
25581+#include <asm/alternative-asm.h>
25582
25583 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
25584 .macro THUNK name, func, put_ret_addr_in_rdi=0
25585@@ -41,5 +42,6 @@
25586 SAVE_ARGS
25587 restore:
25588 RESTORE_ARGS
25589+ pax_force_retaddr
25590 ret
25591 CFI_ENDPROC
25592diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
25593index f0312d7..9c39d63 100644
25594--- a/arch/x86/lib/usercopy_32.c
25595+++ b/arch/x86/lib/usercopy_32.c
25596@@ -42,11 +42,13 @@ do { \
25597 int __d0; \
25598 might_fault(); \
25599 __asm__ __volatile__( \
25600+ __COPYUSER_SET_ES \
25601 ASM_STAC "\n" \
25602 "0: rep; stosl\n" \
25603 " movl %2,%0\n" \
25604 "1: rep; stosb\n" \
25605 "2: " ASM_CLAC "\n" \
25606+ __COPYUSER_RESTORE_ES \
25607 ".section .fixup,\"ax\"\n" \
25608 "3: lea 0(%2,%0,4),%0\n" \
25609 " jmp 2b\n" \
25610@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
25611
25612 #ifdef CONFIG_X86_INTEL_USERCOPY
25613 static unsigned long
25614-__copy_user_intel(void __user *to, const void *from, unsigned long size)
25615+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
25616 {
25617 int d0, d1;
25618 __asm__ __volatile__(
25619@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
25620 " .align 2,0x90\n"
25621 "3: movl 0(%4), %%eax\n"
25622 "4: movl 4(%4), %%edx\n"
25623- "5: movl %%eax, 0(%3)\n"
25624- "6: movl %%edx, 4(%3)\n"
25625+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
25626+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
25627 "7: movl 8(%4), %%eax\n"
25628 "8: movl 12(%4),%%edx\n"
25629- "9: movl %%eax, 8(%3)\n"
25630- "10: movl %%edx, 12(%3)\n"
25631+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
25632+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
25633 "11: movl 16(%4), %%eax\n"
25634 "12: movl 20(%4), %%edx\n"
25635- "13: movl %%eax, 16(%3)\n"
25636- "14: movl %%edx, 20(%3)\n"
25637+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
25638+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
25639 "15: movl 24(%4), %%eax\n"
25640 "16: movl 28(%4), %%edx\n"
25641- "17: movl %%eax, 24(%3)\n"
25642- "18: movl %%edx, 28(%3)\n"
25643+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
25644+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
25645 "19: movl 32(%4), %%eax\n"
25646 "20: movl 36(%4), %%edx\n"
25647- "21: movl %%eax, 32(%3)\n"
25648- "22: movl %%edx, 36(%3)\n"
25649+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
25650+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
25651 "23: movl 40(%4), %%eax\n"
25652 "24: movl 44(%4), %%edx\n"
25653- "25: movl %%eax, 40(%3)\n"
25654- "26: movl %%edx, 44(%3)\n"
25655+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
25656+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
25657 "27: movl 48(%4), %%eax\n"
25658 "28: movl 52(%4), %%edx\n"
25659- "29: movl %%eax, 48(%3)\n"
25660- "30: movl %%edx, 52(%3)\n"
25661+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
25662+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
25663 "31: movl 56(%4), %%eax\n"
25664 "32: movl 60(%4), %%edx\n"
25665- "33: movl %%eax, 56(%3)\n"
25666- "34: movl %%edx, 60(%3)\n"
25667+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
25668+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
25669 " addl $-64, %0\n"
25670 " addl $64, %4\n"
25671 " addl $64, %3\n"
25672@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
25673 " shrl $2, %0\n"
25674 " andl $3, %%eax\n"
25675 " cld\n"
25676+ __COPYUSER_SET_ES
25677 "99: rep; movsl\n"
25678 "36: movl %%eax, %0\n"
25679 "37: rep; movsb\n"
25680 "100:\n"
25681+ __COPYUSER_RESTORE_ES
25682 ".section .fixup,\"ax\"\n"
25683 "101: lea 0(%%eax,%0,4),%0\n"
25684 " jmp 100b\n"
25685@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
25686 }
25687
25688 static unsigned long
25689+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
25690+{
25691+ int d0, d1;
25692+ __asm__ __volatile__(
25693+ " .align 2,0x90\n"
25694+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
25695+ " cmpl $67, %0\n"
25696+ " jbe 3f\n"
25697+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
25698+ " .align 2,0x90\n"
25699+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
25700+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
25701+ "5: movl %%eax, 0(%3)\n"
25702+ "6: movl %%edx, 4(%3)\n"
25703+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
25704+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
25705+ "9: movl %%eax, 8(%3)\n"
25706+ "10: movl %%edx, 12(%3)\n"
25707+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
25708+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
25709+ "13: movl %%eax, 16(%3)\n"
25710+ "14: movl %%edx, 20(%3)\n"
25711+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
25712+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
25713+ "17: movl %%eax, 24(%3)\n"
25714+ "18: movl %%edx, 28(%3)\n"
25715+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
25716+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
25717+ "21: movl %%eax, 32(%3)\n"
25718+ "22: movl %%edx, 36(%3)\n"
25719+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
25720+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
25721+ "25: movl %%eax, 40(%3)\n"
25722+ "26: movl %%edx, 44(%3)\n"
25723+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
25724+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
25725+ "29: movl %%eax, 48(%3)\n"
25726+ "30: movl %%edx, 52(%3)\n"
25727+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
25728+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
25729+ "33: movl %%eax, 56(%3)\n"
25730+ "34: movl %%edx, 60(%3)\n"
25731+ " addl $-64, %0\n"
25732+ " addl $64, %4\n"
25733+ " addl $64, %3\n"
25734+ " cmpl $63, %0\n"
25735+ " ja 1b\n"
25736+ "35: movl %0, %%eax\n"
25737+ " shrl $2, %0\n"
25738+ " andl $3, %%eax\n"
25739+ " cld\n"
25740+ "99: rep; "__copyuser_seg" movsl\n"
25741+ "36: movl %%eax, %0\n"
25742+ "37: rep; "__copyuser_seg" movsb\n"
25743+ "100:\n"
25744+ ".section .fixup,\"ax\"\n"
25745+ "101: lea 0(%%eax,%0,4),%0\n"
25746+ " jmp 100b\n"
25747+ ".previous\n"
25748+ _ASM_EXTABLE(1b,100b)
25749+ _ASM_EXTABLE(2b,100b)
25750+ _ASM_EXTABLE(3b,100b)
25751+ _ASM_EXTABLE(4b,100b)
25752+ _ASM_EXTABLE(5b,100b)
25753+ _ASM_EXTABLE(6b,100b)
25754+ _ASM_EXTABLE(7b,100b)
25755+ _ASM_EXTABLE(8b,100b)
25756+ _ASM_EXTABLE(9b,100b)
25757+ _ASM_EXTABLE(10b,100b)
25758+ _ASM_EXTABLE(11b,100b)
25759+ _ASM_EXTABLE(12b,100b)
25760+ _ASM_EXTABLE(13b,100b)
25761+ _ASM_EXTABLE(14b,100b)
25762+ _ASM_EXTABLE(15b,100b)
25763+ _ASM_EXTABLE(16b,100b)
25764+ _ASM_EXTABLE(17b,100b)
25765+ _ASM_EXTABLE(18b,100b)
25766+ _ASM_EXTABLE(19b,100b)
25767+ _ASM_EXTABLE(20b,100b)
25768+ _ASM_EXTABLE(21b,100b)
25769+ _ASM_EXTABLE(22b,100b)
25770+ _ASM_EXTABLE(23b,100b)
25771+ _ASM_EXTABLE(24b,100b)
25772+ _ASM_EXTABLE(25b,100b)
25773+ _ASM_EXTABLE(26b,100b)
25774+ _ASM_EXTABLE(27b,100b)
25775+ _ASM_EXTABLE(28b,100b)
25776+ _ASM_EXTABLE(29b,100b)
25777+ _ASM_EXTABLE(30b,100b)
25778+ _ASM_EXTABLE(31b,100b)
25779+ _ASM_EXTABLE(32b,100b)
25780+ _ASM_EXTABLE(33b,100b)
25781+ _ASM_EXTABLE(34b,100b)
25782+ _ASM_EXTABLE(35b,100b)
25783+ _ASM_EXTABLE(36b,100b)
25784+ _ASM_EXTABLE(37b,100b)
25785+ _ASM_EXTABLE(99b,101b)
25786+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
25787+ : "1"(to), "2"(from), "0"(size)
25788+ : "eax", "edx", "memory");
25789+ return size;
25790+}
25791+
25792+static unsigned long __size_overflow(3)
25793 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
25794 {
25795 int d0, d1;
25796 __asm__ __volatile__(
25797 " .align 2,0x90\n"
25798- "0: movl 32(%4), %%eax\n"
25799+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
25800 " cmpl $67, %0\n"
25801 " jbe 2f\n"
25802- "1: movl 64(%4), %%eax\n"
25803+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
25804 " .align 2,0x90\n"
25805- "2: movl 0(%4), %%eax\n"
25806- "21: movl 4(%4), %%edx\n"
25807+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
25808+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
25809 " movl %%eax, 0(%3)\n"
25810 " movl %%edx, 4(%3)\n"
25811- "3: movl 8(%4), %%eax\n"
25812- "31: movl 12(%4),%%edx\n"
25813+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
25814+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
25815 " movl %%eax, 8(%3)\n"
25816 " movl %%edx, 12(%3)\n"
25817- "4: movl 16(%4), %%eax\n"
25818- "41: movl 20(%4), %%edx\n"
25819+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
25820+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
25821 " movl %%eax, 16(%3)\n"
25822 " movl %%edx, 20(%3)\n"
25823- "10: movl 24(%4), %%eax\n"
25824- "51: movl 28(%4), %%edx\n"
25825+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
25826+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
25827 " movl %%eax, 24(%3)\n"
25828 " movl %%edx, 28(%3)\n"
25829- "11: movl 32(%4), %%eax\n"
25830- "61: movl 36(%4), %%edx\n"
25831+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
25832+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
25833 " movl %%eax, 32(%3)\n"
25834 " movl %%edx, 36(%3)\n"
25835- "12: movl 40(%4), %%eax\n"
25836- "71: movl 44(%4), %%edx\n"
25837+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
25838+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
25839 " movl %%eax, 40(%3)\n"
25840 " movl %%edx, 44(%3)\n"
25841- "13: movl 48(%4), %%eax\n"
25842- "81: movl 52(%4), %%edx\n"
25843+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
25844+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
25845 " movl %%eax, 48(%3)\n"
25846 " movl %%edx, 52(%3)\n"
25847- "14: movl 56(%4), %%eax\n"
25848- "91: movl 60(%4), %%edx\n"
25849+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
25850+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
25851 " movl %%eax, 56(%3)\n"
25852 " movl %%edx, 60(%3)\n"
25853 " addl $-64, %0\n"
25854@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
25855 " shrl $2, %0\n"
25856 " andl $3, %%eax\n"
25857 " cld\n"
25858- "6: rep; movsl\n"
25859+ "6: rep; "__copyuser_seg" movsl\n"
25860 " movl %%eax,%0\n"
25861- "7: rep; movsb\n"
25862+ "7: rep; "__copyuser_seg" movsb\n"
25863 "8:\n"
25864 ".section .fixup,\"ax\"\n"
25865 "9: lea 0(%%eax,%0,4),%0\n"
25866@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
25867 * hyoshiok@miraclelinux.com
25868 */
25869
25870-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
25871+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
25872 const void __user *from, unsigned long size)
25873 {
25874 int d0, d1;
25875
25876 __asm__ __volatile__(
25877 " .align 2,0x90\n"
25878- "0: movl 32(%4), %%eax\n"
25879+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
25880 " cmpl $67, %0\n"
25881 " jbe 2f\n"
25882- "1: movl 64(%4), %%eax\n"
25883+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
25884 " .align 2,0x90\n"
25885- "2: movl 0(%4), %%eax\n"
25886- "21: movl 4(%4), %%edx\n"
25887+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
25888+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
25889 " movnti %%eax, 0(%3)\n"
25890 " movnti %%edx, 4(%3)\n"
25891- "3: movl 8(%4), %%eax\n"
25892- "31: movl 12(%4),%%edx\n"
25893+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
25894+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
25895 " movnti %%eax, 8(%3)\n"
25896 " movnti %%edx, 12(%3)\n"
25897- "4: movl 16(%4), %%eax\n"
25898- "41: movl 20(%4), %%edx\n"
25899+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
25900+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
25901 " movnti %%eax, 16(%3)\n"
25902 " movnti %%edx, 20(%3)\n"
25903- "10: movl 24(%4), %%eax\n"
25904- "51: movl 28(%4), %%edx\n"
25905+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
25906+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
25907 " movnti %%eax, 24(%3)\n"
25908 " movnti %%edx, 28(%3)\n"
25909- "11: movl 32(%4), %%eax\n"
25910- "61: movl 36(%4), %%edx\n"
25911+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
25912+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
25913 " movnti %%eax, 32(%3)\n"
25914 " movnti %%edx, 36(%3)\n"
25915- "12: movl 40(%4), %%eax\n"
25916- "71: movl 44(%4), %%edx\n"
25917+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
25918+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
25919 " movnti %%eax, 40(%3)\n"
25920 " movnti %%edx, 44(%3)\n"
25921- "13: movl 48(%4), %%eax\n"
25922- "81: movl 52(%4), %%edx\n"
25923+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
25924+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
25925 " movnti %%eax, 48(%3)\n"
25926 " movnti %%edx, 52(%3)\n"
25927- "14: movl 56(%4), %%eax\n"
25928- "91: movl 60(%4), %%edx\n"
25929+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
25930+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
25931 " movnti %%eax, 56(%3)\n"
25932 " movnti %%edx, 60(%3)\n"
25933 " addl $-64, %0\n"
25934@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
25935 " shrl $2, %0\n"
25936 " andl $3, %%eax\n"
25937 " cld\n"
25938- "6: rep; movsl\n"
25939+ "6: rep; "__copyuser_seg" movsl\n"
25940 " movl %%eax,%0\n"
25941- "7: rep; movsb\n"
25942+ "7: rep; "__copyuser_seg" movsb\n"
25943 "8:\n"
25944 ".section .fixup,\"ax\"\n"
25945 "9: lea 0(%%eax,%0,4),%0\n"
25946@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
25947 return size;
25948 }
25949
25950-static unsigned long __copy_user_intel_nocache(void *to,
25951+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
25952 const void __user *from, unsigned long size)
25953 {
25954 int d0, d1;
25955
25956 __asm__ __volatile__(
25957 " .align 2,0x90\n"
25958- "0: movl 32(%4), %%eax\n"
25959+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
25960 " cmpl $67, %0\n"
25961 " jbe 2f\n"
25962- "1: movl 64(%4), %%eax\n"
25963+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
25964 " .align 2,0x90\n"
25965- "2: movl 0(%4), %%eax\n"
25966- "21: movl 4(%4), %%edx\n"
25967+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
25968+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
25969 " movnti %%eax, 0(%3)\n"
25970 " movnti %%edx, 4(%3)\n"
25971- "3: movl 8(%4), %%eax\n"
25972- "31: movl 12(%4),%%edx\n"
25973+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
25974+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
25975 " movnti %%eax, 8(%3)\n"
25976 " movnti %%edx, 12(%3)\n"
25977- "4: movl 16(%4), %%eax\n"
25978- "41: movl 20(%4), %%edx\n"
25979+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
25980+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
25981 " movnti %%eax, 16(%3)\n"
25982 " movnti %%edx, 20(%3)\n"
25983- "10: movl 24(%4), %%eax\n"
25984- "51: movl 28(%4), %%edx\n"
25985+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
25986+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
25987 " movnti %%eax, 24(%3)\n"
25988 " movnti %%edx, 28(%3)\n"
25989- "11: movl 32(%4), %%eax\n"
25990- "61: movl 36(%4), %%edx\n"
25991+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
25992+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
25993 " movnti %%eax, 32(%3)\n"
25994 " movnti %%edx, 36(%3)\n"
25995- "12: movl 40(%4), %%eax\n"
25996- "71: movl 44(%4), %%edx\n"
25997+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
25998+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
25999 " movnti %%eax, 40(%3)\n"
26000 " movnti %%edx, 44(%3)\n"
26001- "13: movl 48(%4), %%eax\n"
26002- "81: movl 52(%4), %%edx\n"
26003+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26004+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26005 " movnti %%eax, 48(%3)\n"
26006 " movnti %%edx, 52(%3)\n"
26007- "14: movl 56(%4), %%eax\n"
26008- "91: movl 60(%4), %%edx\n"
26009+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26010+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26011 " movnti %%eax, 56(%3)\n"
26012 " movnti %%edx, 60(%3)\n"
26013 " addl $-64, %0\n"
26014@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
26015 " shrl $2, %0\n"
26016 " andl $3, %%eax\n"
26017 " cld\n"
26018- "6: rep; movsl\n"
26019+ "6: rep; "__copyuser_seg" movsl\n"
26020 " movl %%eax,%0\n"
26021- "7: rep; movsb\n"
26022+ "7: rep; "__copyuser_seg" movsb\n"
26023 "8:\n"
26024 ".section .fixup,\"ax\"\n"
26025 "9: lea 0(%%eax,%0,4),%0\n"
26026@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
26027 */
26028 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
26029 unsigned long size);
26030-unsigned long __copy_user_intel(void __user *to, const void *from,
26031+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
26032+ unsigned long size);
26033+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
26034 unsigned long size);
26035 unsigned long __copy_user_zeroing_intel_nocache(void *to,
26036 const void __user *from, unsigned long size);
26037 #endif /* CONFIG_X86_INTEL_USERCOPY */
26038
26039 /* Generic arbitrary sized copy. */
26040-#define __copy_user(to, from, size) \
26041+#define __copy_user(to, from, size, prefix, set, restore) \
26042 do { \
26043 int __d0, __d1, __d2; \
26044 __asm__ __volatile__( \
26045+ set \
26046 " cmp $7,%0\n" \
26047 " jbe 1f\n" \
26048 " movl %1,%0\n" \
26049 " negl %0\n" \
26050 " andl $7,%0\n" \
26051 " subl %0,%3\n" \
26052- "4: rep; movsb\n" \
26053+ "4: rep; "prefix"movsb\n" \
26054 " movl %3,%0\n" \
26055 " shrl $2,%0\n" \
26056 " andl $3,%3\n" \
26057 " .align 2,0x90\n" \
26058- "0: rep; movsl\n" \
26059+ "0: rep; "prefix"movsl\n" \
26060 " movl %3,%0\n" \
26061- "1: rep; movsb\n" \
26062+ "1: rep; "prefix"movsb\n" \
26063 "2:\n" \
26064+ restore \
26065 ".section .fixup,\"ax\"\n" \
26066 "5: addl %3,%0\n" \
26067 " jmp 2b\n" \
26068@@ -538,14 +650,14 @@ do { \
26069 " negl %0\n" \
26070 " andl $7,%0\n" \
26071 " subl %0,%3\n" \
26072- "4: rep; movsb\n" \
26073+ "4: rep; "__copyuser_seg"movsb\n" \
26074 " movl %3,%0\n" \
26075 " shrl $2,%0\n" \
26076 " andl $3,%3\n" \
26077 " .align 2,0x90\n" \
26078- "0: rep; movsl\n" \
26079+ "0: rep; "__copyuser_seg"movsl\n" \
26080 " movl %3,%0\n" \
26081- "1: rep; movsb\n" \
26082+ "1: rep; "__copyuser_seg"movsb\n" \
26083 "2:\n" \
26084 ".section .fixup,\"ax\"\n" \
26085 "5: addl %3,%0\n" \
26086@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
26087 {
26088 stac();
26089 if (movsl_is_ok(to, from, n))
26090- __copy_user(to, from, n);
26091+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
26092 else
26093- n = __copy_user_intel(to, from, n);
26094+ n = __generic_copy_to_user_intel(to, from, n);
26095 clac();
26096 return n;
26097 }
26098@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
26099 {
26100 stac();
26101 if (movsl_is_ok(to, from, n))
26102- __copy_user(to, from, n);
26103+ __copy_user(to, from, n, __copyuser_seg, "", "");
26104 else
26105- n = __copy_user_intel((void __user *)to,
26106- (const void *)from, n);
26107+ n = __generic_copy_from_user_intel(to, from, n);
26108 clac();
26109 return n;
26110 }
26111@@ -632,66 +743,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
26112 if (n > 64 && cpu_has_xmm2)
26113 n = __copy_user_intel_nocache(to, from, n);
26114 else
26115- __copy_user(to, from, n);
26116+ __copy_user(to, from, n, __copyuser_seg, "", "");
26117 #else
26118- __copy_user(to, from, n);
26119+ __copy_user(to, from, n, __copyuser_seg, "", "");
26120 #endif
26121 clac();
26122 return n;
26123 }
26124 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
26125
26126-/**
26127- * copy_to_user: - Copy a block of data into user space.
26128- * @to: Destination address, in user space.
26129- * @from: Source address, in kernel space.
26130- * @n: Number of bytes to copy.
26131- *
26132- * Context: User context only. This function may sleep.
26133- *
26134- * Copy data from kernel space to user space.
26135- *
26136- * Returns number of bytes that could not be copied.
26137- * On success, this will be zero.
26138- */
26139-unsigned long
26140-copy_to_user(void __user *to, const void *from, unsigned long n)
26141-{
26142- if (access_ok(VERIFY_WRITE, to, n))
26143- n = __copy_to_user(to, from, n);
26144- return n;
26145-}
26146-EXPORT_SYMBOL(copy_to_user);
26147-
26148-/**
26149- * copy_from_user: - Copy a block of data from user space.
26150- * @to: Destination address, in kernel space.
26151- * @from: Source address, in user space.
26152- * @n: Number of bytes to copy.
26153- *
26154- * Context: User context only. This function may sleep.
26155- *
26156- * Copy data from user space to kernel space.
26157- *
26158- * Returns number of bytes that could not be copied.
26159- * On success, this will be zero.
26160- *
26161- * If some data could not be copied, this function will pad the copied
26162- * data to the requested size using zero bytes.
26163- */
26164-unsigned long
26165-_copy_from_user(void *to, const void __user *from, unsigned long n)
26166-{
26167- if (access_ok(VERIFY_READ, from, n))
26168- n = __copy_from_user(to, from, n);
26169- else
26170- memset(to, 0, n);
26171- return n;
26172-}
26173-EXPORT_SYMBOL(_copy_from_user);
26174-
26175 void copy_from_user_overflow(void)
26176 {
26177 WARN(1, "Buffer overflow detected!\n");
26178 }
26179 EXPORT_SYMBOL(copy_from_user_overflow);
26180+
26181+void copy_to_user_overflow(void)
26182+{
26183+ WARN(1, "Buffer overflow detected!\n");
26184+}
26185+EXPORT_SYMBOL(copy_to_user_overflow);
26186+
26187+#ifdef CONFIG_PAX_MEMORY_UDEREF
26188+void __set_fs(mm_segment_t x)
26189+{
26190+ switch (x.seg) {
26191+ case 0:
26192+ loadsegment(gs, 0);
26193+ break;
26194+ case TASK_SIZE_MAX:
26195+ loadsegment(gs, __USER_DS);
26196+ break;
26197+ case -1UL:
26198+ loadsegment(gs, __KERNEL_DS);
26199+ break;
26200+ default:
26201+ BUG();
26202+ }
26203+ return;
26204+}
26205+EXPORT_SYMBOL(__set_fs);
26206+
26207+void set_fs(mm_segment_t x)
26208+{
26209+ current_thread_info()->addr_limit = x;
26210+ __set_fs(x);
26211+}
26212+EXPORT_SYMBOL(set_fs);
26213+#endif
26214diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
26215index 05928aa..b33dea1 100644
26216--- a/arch/x86/lib/usercopy_64.c
26217+++ b/arch/x86/lib/usercopy_64.c
26218@@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
26219 _ASM_EXTABLE(0b,3b)
26220 _ASM_EXTABLE(1b,2b)
26221 : [size8] "=&c"(size), [dst] "=&D" (__d0)
26222- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
26223+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
26224 [zero] "r" (0UL), [eight] "r" (8UL));
26225 clac();
26226 return size;
26227@@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
26228 }
26229 EXPORT_SYMBOL(clear_user);
26230
26231-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
26232+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
26233 {
26234- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
26235- return copy_user_generic((__force void *)to, (__force void *)from, len);
26236- }
26237- return len;
26238+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
26239+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
26240+ return len;
26241 }
26242 EXPORT_SYMBOL(copy_in_user);
26243
26244@@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
26245 * it is not necessary to optimize tail handling.
26246 */
26247 unsigned long
26248-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
26249+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
26250 {
26251 char c;
26252 unsigned zero_len;
26253@@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
26254 clac();
26255 return len;
26256 }
26257+
26258+void copy_from_user_overflow(void)
26259+{
26260+ WARN(1, "Buffer overflow detected!\n");
26261+}
26262+EXPORT_SYMBOL(copy_from_user_overflow);
26263+
26264+void copy_to_user_overflow(void)
26265+{
26266+ WARN(1, "Buffer overflow detected!\n");
26267+}
26268+EXPORT_SYMBOL(copy_to_user_overflow);
26269diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
26270index 903ec1e..c4166b2 100644
26271--- a/arch/x86/mm/extable.c
26272+++ b/arch/x86/mm/extable.c
26273@@ -6,12 +6,24 @@
26274 static inline unsigned long
26275 ex_insn_addr(const struct exception_table_entry *x)
26276 {
26277- return (unsigned long)&x->insn + x->insn;
26278+ unsigned long reloc = 0;
26279+
26280+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26281+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26282+#endif
26283+
26284+ return (unsigned long)&x->insn + x->insn + reloc;
26285 }
26286 static inline unsigned long
26287 ex_fixup_addr(const struct exception_table_entry *x)
26288 {
26289- return (unsigned long)&x->fixup + x->fixup;
26290+ unsigned long reloc = 0;
26291+
26292+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26293+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26294+#endif
26295+
26296+ return (unsigned long)&x->fixup + x->fixup + reloc;
26297 }
26298
26299 int fixup_exception(struct pt_regs *regs)
26300@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
26301 unsigned long new_ip;
26302
26303 #ifdef CONFIG_PNPBIOS
26304- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
26305+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
26306 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
26307 extern u32 pnp_bios_is_utter_crap;
26308 pnp_bios_is_utter_crap = 1;
26309@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
26310 i += 4;
26311 p->fixup -= i;
26312 i += 4;
26313+
26314+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26315+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
26316+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26317+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26318+#endif
26319+
26320 }
26321 }
26322
26323diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
26324index fb674fd..272f369 100644
26325--- a/arch/x86/mm/fault.c
26326+++ b/arch/x86/mm/fault.c
26327@@ -13,12 +13,19 @@
26328 #include <linux/perf_event.h> /* perf_sw_event */
26329 #include <linux/hugetlb.h> /* hstate_index_to_shift */
26330 #include <linux/prefetch.h> /* prefetchw */
26331+#include <linux/unistd.h>
26332+#include <linux/compiler.h>
26333
26334 #include <asm/traps.h> /* dotraplinkage, ... */
26335 #include <asm/pgalloc.h> /* pgd_*(), ... */
26336 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
26337 #include <asm/fixmap.h> /* VSYSCALL_START */
26338 #include <asm/context_tracking.h> /* exception_enter(), ... */
26339+#include <asm/tlbflush.h>
26340+
26341+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26342+#include <asm/stacktrace.h>
26343+#endif
26344
26345 /*
26346 * Page fault error code bits:
26347@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
26348 int ret = 0;
26349
26350 /* kprobe_running() needs smp_processor_id() */
26351- if (kprobes_built_in() && !user_mode_vm(regs)) {
26352+ if (kprobes_built_in() && !user_mode(regs)) {
26353 preempt_disable();
26354 if (kprobe_running() && kprobe_fault_handler(regs, 14))
26355 ret = 1;
26356@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
26357 return !instr_lo || (instr_lo>>1) == 1;
26358 case 0x00:
26359 /* Prefetch instruction is 0x0F0D or 0x0F18 */
26360- if (probe_kernel_address(instr, opcode))
26361+ if (user_mode(regs)) {
26362+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
26363+ return 0;
26364+ } else if (probe_kernel_address(instr, opcode))
26365 return 0;
26366
26367 *prefetch = (instr_lo == 0xF) &&
26368@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
26369 while (instr < max_instr) {
26370 unsigned char opcode;
26371
26372- if (probe_kernel_address(instr, opcode))
26373+ if (user_mode(regs)) {
26374+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
26375+ break;
26376+ } else if (probe_kernel_address(instr, opcode))
26377 break;
26378
26379 instr++;
26380@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
26381 force_sig_info(si_signo, &info, tsk);
26382 }
26383
26384+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26385+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
26386+#endif
26387+
26388+#ifdef CONFIG_PAX_EMUTRAMP
26389+static int pax_handle_fetch_fault(struct pt_regs *regs);
26390+#endif
26391+
26392+#ifdef CONFIG_PAX_PAGEEXEC
26393+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
26394+{
26395+ pgd_t *pgd;
26396+ pud_t *pud;
26397+ pmd_t *pmd;
26398+
26399+ pgd = pgd_offset(mm, address);
26400+ if (!pgd_present(*pgd))
26401+ return NULL;
26402+ pud = pud_offset(pgd, address);
26403+ if (!pud_present(*pud))
26404+ return NULL;
26405+ pmd = pmd_offset(pud, address);
26406+ if (!pmd_present(*pmd))
26407+ return NULL;
26408+ return pmd;
26409+}
26410+#endif
26411+
26412 DEFINE_SPINLOCK(pgd_lock);
26413 LIST_HEAD(pgd_list);
26414
26415@@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
26416 for (address = VMALLOC_START & PMD_MASK;
26417 address >= TASK_SIZE && address < FIXADDR_TOP;
26418 address += PMD_SIZE) {
26419+
26420+#ifdef CONFIG_PAX_PER_CPU_PGD
26421+ unsigned long cpu;
26422+#else
26423 struct page *page;
26424+#endif
26425
26426 spin_lock(&pgd_lock);
26427+
26428+#ifdef CONFIG_PAX_PER_CPU_PGD
26429+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
26430+ pgd_t *pgd = get_cpu_pgd(cpu);
26431+ pmd_t *ret;
26432+#else
26433 list_for_each_entry(page, &pgd_list, lru) {
26434+ pgd_t *pgd = page_address(page);
26435 spinlock_t *pgt_lock;
26436 pmd_t *ret;
26437
26438@@ -243,8 +296,13 @@ void vmalloc_sync_all(void)
26439 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
26440
26441 spin_lock(pgt_lock);
26442- ret = vmalloc_sync_one(page_address(page), address);
26443+#endif
26444+
26445+ ret = vmalloc_sync_one(pgd, address);
26446+
26447+#ifndef CONFIG_PAX_PER_CPU_PGD
26448 spin_unlock(pgt_lock);
26449+#endif
26450
26451 if (!ret)
26452 break;
26453@@ -278,6 +336,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
26454 * an interrupt in the middle of a task switch..
26455 */
26456 pgd_paddr = read_cr3();
26457+
26458+#ifdef CONFIG_PAX_PER_CPU_PGD
26459+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
26460+#endif
26461+
26462 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
26463 if (!pmd_k)
26464 return -1;
26465@@ -373,7 +436,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
26466 * happen within a race in page table update. In the later
26467 * case just flush:
26468 */
26469+
26470+#ifdef CONFIG_PAX_PER_CPU_PGD
26471+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
26472+ pgd = pgd_offset_cpu(smp_processor_id(), address);
26473+#else
26474 pgd = pgd_offset(current->active_mm, address);
26475+#endif
26476+
26477 pgd_ref = pgd_offset_k(address);
26478 if (pgd_none(*pgd_ref))
26479 return -1;
26480@@ -541,7 +611,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
26481 static int is_errata100(struct pt_regs *regs, unsigned long address)
26482 {
26483 #ifdef CONFIG_X86_64
26484- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
26485+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
26486 return 1;
26487 #endif
26488 return 0;
26489@@ -568,7 +638,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
26490 }
26491
26492 static const char nx_warning[] = KERN_CRIT
26493-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
26494+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
26495
26496 static void
26497 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
26498@@ -577,15 +647,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
26499 if (!oops_may_print())
26500 return;
26501
26502- if (error_code & PF_INSTR) {
26503+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
26504 unsigned int level;
26505
26506 pte_t *pte = lookup_address(address, &level);
26507
26508 if (pte && pte_present(*pte) && !pte_exec(*pte))
26509- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
26510+ printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
26511 }
26512
26513+#ifdef CONFIG_PAX_KERNEXEC
26514+ if (init_mm.start_code <= address && address < init_mm.end_code) {
26515+ if (current->signal->curr_ip)
26516+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
26517+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
26518+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
26519+ else
26520+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
26521+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
26522+ }
26523+#endif
26524+
26525 printk(KERN_ALERT "BUG: unable to handle kernel ");
26526 if (address < PAGE_SIZE)
26527 printk(KERN_CONT "NULL pointer dereference");
26528@@ -748,6 +830,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
26529 return;
26530 }
26531 #endif
26532+
26533+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26534+ if (pax_is_fetch_fault(regs, error_code, address)) {
26535+
26536+#ifdef CONFIG_PAX_EMUTRAMP
26537+ switch (pax_handle_fetch_fault(regs)) {
26538+ case 2:
26539+ return;
26540+ }
26541+#endif
26542+
26543+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
26544+ do_group_exit(SIGKILL);
26545+ }
26546+#endif
26547+
26548 /* Kernel addresses are always protection faults: */
26549 if (address >= TASK_SIZE)
26550 error_code |= PF_PROT;
26551@@ -833,7 +931,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
26552 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
26553 printk(KERN_ERR
26554 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
26555- tsk->comm, tsk->pid, address);
26556+ tsk->comm, task_pid_nr(tsk), address);
26557 code = BUS_MCEERR_AR;
26558 }
26559 #endif
26560@@ -896,6 +994,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
26561 return 1;
26562 }
26563
26564+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
26565+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
26566+{
26567+ pte_t *pte;
26568+ pmd_t *pmd;
26569+ spinlock_t *ptl;
26570+ unsigned char pte_mask;
26571+
26572+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
26573+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
26574+ return 0;
26575+
26576+ /* PaX: it's our fault, let's handle it if we can */
26577+
26578+ /* PaX: take a look at read faults before acquiring any locks */
26579+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
26580+ /* instruction fetch attempt from a protected page in user mode */
26581+ up_read(&mm->mmap_sem);
26582+
26583+#ifdef CONFIG_PAX_EMUTRAMP
26584+ switch (pax_handle_fetch_fault(regs)) {
26585+ case 2:
26586+ return 1;
26587+ }
26588+#endif
26589+
26590+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
26591+ do_group_exit(SIGKILL);
26592+ }
26593+
26594+ pmd = pax_get_pmd(mm, address);
26595+ if (unlikely(!pmd))
26596+ return 0;
26597+
26598+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
26599+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
26600+ pte_unmap_unlock(pte, ptl);
26601+ return 0;
26602+ }
26603+
26604+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
26605+ /* write attempt to a protected page in user mode */
26606+ pte_unmap_unlock(pte, ptl);
26607+ return 0;
26608+ }
26609+
26610+#ifdef CONFIG_SMP
26611+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
26612+#else
26613+ if (likely(address > get_limit(regs->cs)))
26614+#endif
26615+ {
26616+ set_pte(pte, pte_mkread(*pte));
26617+ __flush_tlb_one(address);
26618+ pte_unmap_unlock(pte, ptl);
26619+ up_read(&mm->mmap_sem);
26620+ return 1;
26621+ }
26622+
26623+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
26624+
26625+ /*
26626+ * PaX: fill DTLB with user rights and retry
26627+ */
26628+ __asm__ __volatile__ (
26629+ "orb %2,(%1)\n"
26630+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
26631+/*
26632+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
26633+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
26634+ * page fault when examined during a TLB load attempt. this is true not only
26635+ * for PTEs holding a non-present entry but also present entries that will
26636+ * raise a page fault (such as those set up by PaX, or the copy-on-write
26637+ * mechanism). in effect it means that we do *not* need to flush the TLBs
26638+ * for our target pages since their PTEs are simply not in the TLBs at all.
26639+
26640+ * the best thing in omitting it is that we gain around 15-20% speed in the
26641+ * fast path of the page fault handler and can get rid of tracing since we
26642+ * can no longer flush unintended entries.
26643+ */
26644+ "invlpg (%0)\n"
26645+#endif
26646+ __copyuser_seg"testb $0,(%0)\n"
26647+ "xorb %3,(%1)\n"
26648+ :
26649+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
26650+ : "memory", "cc");
26651+ pte_unmap_unlock(pte, ptl);
26652+ up_read(&mm->mmap_sem);
26653+ return 1;
26654+}
26655+#endif
26656+
26657 /*
26658 * Handle a spurious fault caused by a stale TLB entry.
26659 *
26660@@ -968,6 +1159,9 @@ int show_unhandled_signals = 1;
26661 static inline int
26662 access_error(unsigned long error_code, struct vm_area_struct *vma)
26663 {
26664+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
26665+ return 1;
26666+
26667 if (error_code & PF_WRITE) {
26668 /* write, present and write, not present: */
26669 if (unlikely(!(vma->vm_flags & VM_WRITE)))
26670@@ -996,7 +1190,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
26671 if (error_code & PF_USER)
26672 return false;
26673
26674- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
26675+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
26676 return false;
26677
26678 return true;
26679@@ -1012,18 +1206,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
26680 {
26681 struct vm_area_struct *vma;
26682 struct task_struct *tsk;
26683- unsigned long address;
26684 struct mm_struct *mm;
26685 int fault;
26686 int write = error_code & PF_WRITE;
26687 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
26688 (write ? FAULT_FLAG_WRITE : 0);
26689
26690- tsk = current;
26691- mm = tsk->mm;
26692-
26693 /* Get the faulting address: */
26694- address = read_cr2();
26695+ unsigned long address = read_cr2();
26696+
26697+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26698+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
26699+ if (!search_exception_tables(regs->ip)) {
26700+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
26701+ bad_area_nosemaphore(regs, error_code, address);
26702+ return;
26703+ }
26704+ if (address < PAX_USER_SHADOW_BASE) {
26705+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
26706+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
26707+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
26708+ } else
26709+ address -= PAX_USER_SHADOW_BASE;
26710+ }
26711+#endif
26712+
26713+ tsk = current;
26714+ mm = tsk->mm;
26715
26716 /*
26717 * Detect and handle instructions that would cause a page fault for
26718@@ -1084,7 +1293,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
26719 * User-mode registers count as a user access even for any
26720 * potential system fault or CPU buglet:
26721 */
26722- if (user_mode_vm(regs)) {
26723+ if (user_mode(regs)) {
26724 local_irq_enable();
26725 error_code |= PF_USER;
26726 } else {
26727@@ -1146,6 +1355,11 @@ retry:
26728 might_sleep();
26729 }
26730
26731+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
26732+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
26733+ return;
26734+#endif
26735+
26736 vma = find_vma(mm, address);
26737 if (unlikely(!vma)) {
26738 bad_area(regs, error_code, address);
26739@@ -1157,18 +1371,24 @@ retry:
26740 bad_area(regs, error_code, address);
26741 return;
26742 }
26743- if (error_code & PF_USER) {
26744- /*
26745- * Accessing the stack below %sp is always a bug.
26746- * The large cushion allows instructions like enter
26747- * and pusha to work. ("enter $65535, $31" pushes
26748- * 32 pointers and then decrements %sp by 65535.)
26749- */
26750- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
26751- bad_area(regs, error_code, address);
26752- return;
26753- }
26754+ /*
26755+ * Accessing the stack below %sp is always a bug.
26756+ * The large cushion allows instructions like enter
26757+ * and pusha to work. ("enter $65535, $31" pushes
26758+ * 32 pointers and then decrements %sp by 65535.)
26759+ */
26760+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
26761+ bad_area(regs, error_code, address);
26762+ return;
26763 }
26764+
26765+#ifdef CONFIG_PAX_SEGMEXEC
26766+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
26767+ bad_area(regs, error_code, address);
26768+ return;
26769+ }
26770+#endif
26771+
26772 if (unlikely(expand_stack(vma, address))) {
26773 bad_area(regs, error_code, address);
26774 return;
26775@@ -1232,3 +1452,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
26776 __do_page_fault(regs, error_code);
26777 exception_exit(regs);
26778 }
26779+
26780+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26781+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
26782+{
26783+ struct mm_struct *mm = current->mm;
26784+ unsigned long ip = regs->ip;
26785+
26786+ if (v8086_mode(regs))
26787+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
26788+
26789+#ifdef CONFIG_PAX_PAGEEXEC
26790+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
26791+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
26792+ return true;
26793+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
26794+ return true;
26795+ return false;
26796+ }
26797+#endif
26798+
26799+#ifdef CONFIG_PAX_SEGMEXEC
26800+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
26801+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
26802+ return true;
26803+ return false;
26804+ }
26805+#endif
26806+
26807+ return false;
26808+}
26809+#endif
26810+
26811+#ifdef CONFIG_PAX_EMUTRAMP
26812+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
26813+{
26814+ int err;
26815+
26816+ do { /* PaX: libffi trampoline emulation */
26817+ unsigned char mov, jmp;
26818+ unsigned int addr1, addr2;
26819+
26820+#ifdef CONFIG_X86_64
26821+ if ((regs->ip + 9) >> 32)
26822+ break;
26823+#endif
26824+
26825+ err = get_user(mov, (unsigned char __user *)regs->ip);
26826+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
26827+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
26828+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
26829+
26830+ if (err)
26831+ break;
26832+
26833+ if (mov == 0xB8 && jmp == 0xE9) {
26834+ regs->ax = addr1;
26835+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
26836+ return 2;
26837+ }
26838+ } while (0);
26839+
26840+ do { /* PaX: gcc trampoline emulation #1 */
26841+ unsigned char mov1, mov2;
26842+ unsigned short jmp;
26843+ unsigned int addr1, addr2;
26844+
26845+#ifdef CONFIG_X86_64
26846+ if ((regs->ip + 11) >> 32)
26847+ break;
26848+#endif
26849+
26850+ err = get_user(mov1, (unsigned char __user *)regs->ip);
26851+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
26852+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
26853+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
26854+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
26855+
26856+ if (err)
26857+ break;
26858+
26859+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
26860+ regs->cx = addr1;
26861+ regs->ax = addr2;
26862+ regs->ip = addr2;
26863+ return 2;
26864+ }
26865+ } while (0);
26866+
26867+ do { /* PaX: gcc trampoline emulation #2 */
26868+ unsigned char mov, jmp;
26869+ unsigned int addr1, addr2;
26870+
26871+#ifdef CONFIG_X86_64
26872+ if ((regs->ip + 9) >> 32)
26873+ break;
26874+#endif
26875+
26876+ err = get_user(mov, (unsigned char __user *)regs->ip);
26877+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
26878+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
26879+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
26880+
26881+ if (err)
26882+ break;
26883+
26884+ if (mov == 0xB9 && jmp == 0xE9) {
26885+ regs->cx = addr1;
26886+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
26887+ return 2;
26888+ }
26889+ } while (0);
26890+
26891+ return 1; /* PaX in action */
26892+}
26893+
26894+#ifdef CONFIG_X86_64
26895+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
26896+{
26897+ int err;
26898+
26899+ do { /* PaX: libffi trampoline emulation */
26900+ unsigned short mov1, mov2, jmp1;
26901+ unsigned char stcclc, jmp2;
26902+ unsigned long addr1, addr2;
26903+
26904+ err = get_user(mov1, (unsigned short __user *)regs->ip);
26905+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
26906+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
26907+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
26908+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
26909+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
26910+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
26911+
26912+ if (err)
26913+ break;
26914+
26915+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
26916+ regs->r11 = addr1;
26917+ regs->r10 = addr2;
26918+ if (stcclc == 0xF8)
26919+ regs->flags &= ~X86_EFLAGS_CF;
26920+ else
26921+ regs->flags |= X86_EFLAGS_CF;
26922+ regs->ip = addr1;
26923+ return 2;
26924+ }
26925+ } while (0);
26926+
26927+ do { /* PaX: gcc trampoline emulation #1 */
26928+ unsigned short mov1, mov2, jmp1;
26929+ unsigned char jmp2;
26930+ unsigned int addr1;
26931+ unsigned long addr2;
26932+
26933+ err = get_user(mov1, (unsigned short __user *)regs->ip);
26934+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
26935+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
26936+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
26937+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
26938+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
26939+
26940+ if (err)
26941+ break;
26942+
26943+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
26944+ regs->r11 = addr1;
26945+ regs->r10 = addr2;
26946+ regs->ip = addr1;
26947+ return 2;
26948+ }
26949+ } while (0);
26950+
26951+ do { /* PaX: gcc trampoline emulation #2 */
26952+ unsigned short mov1, mov2, jmp1;
26953+ unsigned char jmp2;
26954+ unsigned long addr1, addr2;
26955+
26956+ err = get_user(mov1, (unsigned short __user *)regs->ip);
26957+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
26958+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
26959+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
26960+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
26961+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
26962+
26963+ if (err)
26964+ break;
26965+
26966+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
26967+ regs->r11 = addr1;
26968+ regs->r10 = addr2;
26969+ regs->ip = addr1;
26970+ return 2;
26971+ }
26972+ } while (0);
26973+
26974+ return 1; /* PaX in action */
26975+}
26976+#endif
26977+
26978+/*
26979+ * PaX: decide what to do with offenders (regs->ip = fault address)
26980+ *
26981+ * returns 1 when task should be killed
26982+ * 2 when gcc trampoline was detected
26983+ */
26984+static int pax_handle_fetch_fault(struct pt_regs *regs)
26985+{
26986+ if (v8086_mode(regs))
26987+ return 1;
26988+
26989+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
26990+ return 1;
26991+
26992+#ifdef CONFIG_X86_32
26993+ return pax_handle_fetch_fault_32(regs);
26994+#else
26995+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
26996+ return pax_handle_fetch_fault_32(regs);
26997+ else
26998+ return pax_handle_fetch_fault_64(regs);
26999+#endif
27000+}
27001+#endif
27002+
27003+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27004+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
27005+{
27006+ long i;
27007+
27008+ printk(KERN_ERR "PAX: bytes at PC: ");
27009+ for (i = 0; i < 20; i++) {
27010+ unsigned char c;
27011+ if (get_user(c, (unsigned char __force_user *)pc+i))
27012+ printk(KERN_CONT "?? ");
27013+ else
27014+ printk(KERN_CONT "%02x ", c);
27015+ }
27016+ printk("\n");
27017+
27018+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
27019+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
27020+ unsigned long c;
27021+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
27022+#ifdef CONFIG_X86_32
27023+ printk(KERN_CONT "???????? ");
27024+#else
27025+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
27026+ printk(KERN_CONT "???????? ???????? ");
27027+ else
27028+ printk(KERN_CONT "???????????????? ");
27029+#endif
27030+ } else {
27031+#ifdef CONFIG_X86_64
27032+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
27033+ printk(KERN_CONT "%08x ", (unsigned int)c);
27034+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
27035+ } else
27036+#endif
27037+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
27038+ }
27039+ }
27040+ printk("\n");
27041+}
27042+#endif
27043+
27044+/**
27045+ * probe_kernel_write(): safely attempt to write to a location
27046+ * @dst: address to write to
27047+ * @src: pointer to the data that shall be written
27048+ * @size: size of the data chunk
27049+ *
27050+ * Safely write to address @dst from the buffer at @src. If a kernel fault
27051+ * happens, handle that and return -EFAULT.
27052+ */
27053+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
27054+{
27055+ long ret;
27056+ mm_segment_t old_fs = get_fs();
27057+
27058+ set_fs(KERNEL_DS);
27059+ pagefault_disable();
27060+ pax_open_kernel();
27061+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
27062+ pax_close_kernel();
27063+ pagefault_enable();
27064+ set_fs(old_fs);
27065+
27066+ return ret ? -EFAULT : 0;
27067+}
27068diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
27069index dd74e46..7d26398 100644
27070--- a/arch/x86/mm/gup.c
27071+++ b/arch/x86/mm/gup.c
27072@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
27073 addr = start;
27074 len = (unsigned long) nr_pages << PAGE_SHIFT;
27075 end = start + len;
27076- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27077+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27078 (void __user *)start, len)))
27079 return 0;
27080
27081diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
27082index 6f31ee5..8ee4164 100644
27083--- a/arch/x86/mm/highmem_32.c
27084+++ b/arch/x86/mm/highmem_32.c
27085@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
27086 idx = type + KM_TYPE_NR*smp_processor_id();
27087 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
27088 BUG_ON(!pte_none(*(kmap_pte-idx)));
27089+
27090+ pax_open_kernel();
27091 set_pte(kmap_pte-idx, mk_pte(page, prot));
27092+ pax_close_kernel();
27093+
27094 arch_flush_lazy_mmu_mode();
27095
27096 return (void *)vaddr;
27097diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
27098index ae1aa71..56316db 100644
27099--- a/arch/x86/mm/hugetlbpage.c
27100+++ b/arch/x86/mm/hugetlbpage.c
27101@@ -279,6 +279,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
27102 info.flags = 0;
27103 info.length = len;
27104 info.low_limit = TASK_UNMAPPED_BASE;
27105+
27106+#ifdef CONFIG_PAX_RANDMMAP
27107+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
27108+ info.low_limit += current->mm->delta_mmap;
27109+#endif
27110+
27111 info.high_limit = TASK_SIZE;
27112 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
27113 info.align_offset = 0;
27114@@ -311,6 +317,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
27115 VM_BUG_ON(addr != -ENOMEM);
27116 info.flags = 0;
27117 info.low_limit = TASK_UNMAPPED_BASE;
27118+
27119+#ifdef CONFIG_PAX_RANDMMAP
27120+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
27121+ info.low_limit += current->mm->delta_mmap;
27122+#endif
27123+
27124 info.high_limit = TASK_SIZE;
27125 addr = vm_unmapped_area(&info);
27126 }
27127@@ -325,10 +337,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
27128 struct hstate *h = hstate_file(file);
27129 struct mm_struct *mm = current->mm;
27130 struct vm_area_struct *vma;
27131+ unsigned long pax_task_size = TASK_SIZE;
27132+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
27133
27134 if (len & ~huge_page_mask(h))
27135 return -EINVAL;
27136- if (len > TASK_SIZE)
27137+
27138+#ifdef CONFIG_PAX_SEGMEXEC
27139+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27140+ pax_task_size = SEGMEXEC_TASK_SIZE;
27141+#endif
27142+
27143+ pax_task_size -= PAGE_SIZE;
27144+
27145+ if (len > pax_task_size)
27146 return -ENOMEM;
27147
27148 if (flags & MAP_FIXED) {
27149@@ -337,11 +359,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
27150 return addr;
27151 }
27152
27153+#ifdef CONFIG_PAX_RANDMMAP
27154+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27155+#endif
27156+
27157 if (addr) {
27158 addr = ALIGN(addr, huge_page_size(h));
27159 vma = find_vma(mm, addr);
27160- if (TASK_SIZE - len >= addr &&
27161- (!vma || addr + len <= vma->vm_start))
27162+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27163 return addr;
27164 }
27165 if (mm->get_unmapped_area == arch_get_unmapped_area)
27166diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
27167index d7aea41..0fc945b 100644
27168--- a/arch/x86/mm/init.c
27169+++ b/arch/x86/mm/init.c
27170@@ -4,6 +4,7 @@
27171 #include <linux/swap.h>
27172 #include <linux/memblock.h>
27173 #include <linux/bootmem.h> /* for max_low_pfn */
27174+#include <linux/tboot.h>
27175
27176 #include <asm/cacheflush.h>
27177 #include <asm/e820.h>
27178@@ -16,6 +17,8 @@
27179 #include <asm/tlb.h>
27180 #include <asm/proto.h>
27181 #include <asm/dma.h> /* for MAX_DMA_PFN */
27182+#include <asm/desc.h>
27183+#include <asm/bios_ebda.h>
27184
27185 unsigned long __initdata pgt_buf_start;
27186 unsigned long __meminitdata pgt_buf_end;
27187@@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
27188 {
27189 int i;
27190 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
27191- unsigned long start = 0, good_end;
27192+ unsigned long start = 0x100000, good_end;
27193 phys_addr_t base;
27194
27195 for (i = 0; i < nr_range; i++) {
27196@@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
27197 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
27198 * mmio resources as well as potential bios/acpi data regions.
27199 */
27200+
27201+#ifdef CONFIG_GRKERNSEC_KMEM
27202+static unsigned int ebda_start __read_only;
27203+static unsigned int ebda_end __read_only;
27204+#endif
27205+
27206 int devmem_is_allowed(unsigned long pagenr)
27207 {
27208- if (pagenr < 256)
27209+#ifdef CONFIG_GRKERNSEC_KMEM
27210+ /* allow BDA */
27211+ if (!pagenr)
27212 return 1;
27213+ /* allow EBDA */
27214+ if (pagenr >= ebda_start && pagenr < ebda_end)
27215+ return 1;
27216+ /* if tboot is in use, allow access to its hardcoded serial log range */
27217+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
27218+ return 1;
27219+#else
27220+ if (!pagenr)
27221+ return 1;
27222+#ifdef CONFIG_VM86
27223+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
27224+ return 1;
27225+#endif
27226+#endif
27227+
27228+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
27229+ return 1;
27230+#ifdef CONFIG_GRKERNSEC_KMEM
27231+ /* throw out everything else below 1MB */
27232+ if (pagenr <= 256)
27233+ return 0;
27234+#endif
27235 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
27236 return 0;
27237 if (!page_is_ram(pagenr))
27238@@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
27239 #endif
27240 }
27241
27242+#ifdef CONFIG_GRKERNSEC_KMEM
27243+static inline void gr_init_ebda(void)
27244+{
27245+ unsigned int ebda_addr;
27246+ unsigned int ebda_size = 0;
27247+
27248+ ebda_addr = get_bios_ebda();
27249+ if (ebda_addr) {
27250+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
27251+ ebda_size <<= 10;
27252+ }
27253+ if (ebda_addr && ebda_size) {
27254+ ebda_start = ebda_addr >> PAGE_SHIFT;
27255+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
27256+ } else {
27257+ ebda_start = 0x9f000 >> PAGE_SHIFT;
27258+ ebda_end = 0xa0000 >> PAGE_SHIFT;
27259+ }
27260+}
27261+#else
27262+static inline void gr_init_ebda(void) { }
27263+#endif
27264+
27265 void free_initmem(void)
27266 {
27267+#ifdef CONFIG_PAX_KERNEXEC
27268+#ifdef CONFIG_X86_32
27269+ /* PaX: limit KERNEL_CS to actual size */
27270+ unsigned long addr, limit;
27271+ struct desc_struct d;
27272+ int cpu;
27273+#else
27274+ pgd_t *pgd;
27275+ pud_t *pud;
27276+ pmd_t *pmd;
27277+ unsigned long addr, end;
27278+#endif
27279+#endif
27280+
27281+ gr_init_ebda();
27282+
27283+#ifdef CONFIG_PAX_KERNEXEC
27284+#ifdef CONFIG_X86_32
27285+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
27286+ limit = (limit - 1UL) >> PAGE_SHIFT;
27287+
27288+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
27289+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
27290+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
27291+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
27292+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
27293+ }
27294+
27295+ /* PaX: make KERNEL_CS read-only */
27296+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
27297+ if (!paravirt_enabled())
27298+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
27299+/*
27300+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
27301+ pgd = pgd_offset_k(addr);
27302+ pud = pud_offset(pgd, addr);
27303+ pmd = pmd_offset(pud, addr);
27304+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
27305+ }
27306+*/
27307+#ifdef CONFIG_X86_PAE
27308+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
27309+/*
27310+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
27311+ pgd = pgd_offset_k(addr);
27312+ pud = pud_offset(pgd, addr);
27313+ pmd = pmd_offset(pud, addr);
27314+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
27315+ }
27316+*/
27317+#endif
27318+
27319+#ifdef CONFIG_MODULES
27320+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
27321+#endif
27322+
27323+#else
27324+ /* PaX: make kernel code/rodata read-only, rest non-executable */
27325+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
27326+ pgd = pgd_offset_k(addr);
27327+ pud = pud_offset(pgd, addr);
27328+ pmd = pmd_offset(pud, addr);
27329+ if (!pmd_present(*pmd))
27330+ continue;
27331+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
27332+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
27333+ else
27334+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
27335+ }
27336+
27337+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
27338+ end = addr + KERNEL_IMAGE_SIZE;
27339+ for (; addr < end; addr += PMD_SIZE) {
27340+ pgd = pgd_offset_k(addr);
27341+ pud = pud_offset(pgd, addr);
27342+ pmd = pmd_offset(pud, addr);
27343+ if (!pmd_present(*pmd))
27344+ continue;
27345+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
27346+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
27347+ }
27348+#endif
27349+
27350+ flush_tlb_all();
27351+#endif
27352+
27353 free_init_pages("unused kernel memory",
27354 (unsigned long)(&__init_begin),
27355 (unsigned long)(&__init_end));
27356diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
27357index 745d66b..56bf568 100644
27358--- a/arch/x86/mm/init_32.c
27359+++ b/arch/x86/mm/init_32.c
27360@@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
27361 }
27362
27363 /*
27364- * Creates a middle page table and puts a pointer to it in the
27365- * given global directory entry. This only returns the gd entry
27366- * in non-PAE compilation mode, since the middle layer is folded.
27367- */
27368-static pmd_t * __init one_md_table_init(pgd_t *pgd)
27369-{
27370- pud_t *pud;
27371- pmd_t *pmd_table;
27372-
27373-#ifdef CONFIG_X86_PAE
27374- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
27375- if (after_bootmem)
27376- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
27377- else
27378- pmd_table = (pmd_t *)alloc_low_page();
27379- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
27380- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
27381- pud = pud_offset(pgd, 0);
27382- BUG_ON(pmd_table != pmd_offset(pud, 0));
27383-
27384- return pmd_table;
27385- }
27386-#endif
27387- pud = pud_offset(pgd, 0);
27388- pmd_table = pmd_offset(pud, 0);
27389-
27390- return pmd_table;
27391-}
27392-
27393-/*
27394 * Create a page table and place a pointer to it in a middle page
27395 * directory entry:
27396 */
27397@@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
27398 page_table = (pte_t *)alloc_low_page();
27399
27400 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
27401+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27402+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
27403+#else
27404 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
27405+#endif
27406 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
27407 }
27408
27409 return pte_offset_kernel(pmd, 0);
27410 }
27411
27412+static pmd_t * __init one_md_table_init(pgd_t *pgd)
27413+{
27414+ pud_t *pud;
27415+ pmd_t *pmd_table;
27416+
27417+ pud = pud_offset(pgd, 0);
27418+ pmd_table = pmd_offset(pud, 0);
27419+
27420+ return pmd_table;
27421+}
27422+
27423 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
27424 {
27425 int pgd_idx = pgd_index(vaddr);
27426@@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
27427 int pgd_idx, pmd_idx;
27428 unsigned long vaddr;
27429 pgd_t *pgd;
27430+ pud_t *pud;
27431 pmd_t *pmd;
27432 pte_t *pte = NULL;
27433
27434@@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
27435 pgd = pgd_base + pgd_idx;
27436
27437 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
27438- pmd = one_md_table_init(pgd);
27439- pmd = pmd + pmd_index(vaddr);
27440+ pud = pud_offset(pgd, vaddr);
27441+ pmd = pmd_offset(pud, vaddr);
27442+
27443+#ifdef CONFIG_X86_PAE
27444+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
27445+#endif
27446+
27447 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
27448 pmd++, pmd_idx++) {
27449 pte = page_table_kmap_check(one_page_table_init(pmd),
27450@@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
27451 }
27452 }
27453
27454-static inline int is_kernel_text(unsigned long addr)
27455+static inline int is_kernel_text(unsigned long start, unsigned long end)
27456 {
27457- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
27458- return 1;
27459- return 0;
27460+ if ((start > ktla_ktva((unsigned long)_etext) ||
27461+ end <= ktla_ktva((unsigned long)_stext)) &&
27462+ (start > ktla_ktva((unsigned long)_einittext) ||
27463+ end <= ktla_ktva((unsigned long)_sinittext)) &&
27464+
27465+#ifdef CONFIG_ACPI_SLEEP
27466+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
27467+#endif
27468+
27469+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
27470+ return 0;
27471+ return 1;
27472 }
27473
27474 /*
27475@@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
27476 unsigned long last_map_addr = end;
27477 unsigned long start_pfn, end_pfn;
27478 pgd_t *pgd_base = swapper_pg_dir;
27479- int pgd_idx, pmd_idx, pte_ofs;
27480+ unsigned int pgd_idx, pmd_idx, pte_ofs;
27481 unsigned long pfn;
27482 pgd_t *pgd;
27483+ pud_t *pud;
27484 pmd_t *pmd;
27485 pte_t *pte;
27486 unsigned pages_2m, pages_4k;
27487@@ -280,8 +281,13 @@ repeat:
27488 pfn = start_pfn;
27489 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
27490 pgd = pgd_base + pgd_idx;
27491- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
27492- pmd = one_md_table_init(pgd);
27493+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
27494+ pud = pud_offset(pgd, 0);
27495+ pmd = pmd_offset(pud, 0);
27496+
27497+#ifdef CONFIG_X86_PAE
27498+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
27499+#endif
27500
27501 if (pfn >= end_pfn)
27502 continue;
27503@@ -293,14 +299,13 @@ repeat:
27504 #endif
27505 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
27506 pmd++, pmd_idx++) {
27507- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
27508+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
27509
27510 /*
27511 * Map with big pages if possible, otherwise
27512 * create normal page tables:
27513 */
27514 if (use_pse) {
27515- unsigned int addr2;
27516 pgprot_t prot = PAGE_KERNEL_LARGE;
27517 /*
27518 * first pass will use the same initial
27519@@ -310,11 +315,7 @@ repeat:
27520 __pgprot(PTE_IDENT_ATTR |
27521 _PAGE_PSE);
27522
27523- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
27524- PAGE_OFFSET + PAGE_SIZE-1;
27525-
27526- if (is_kernel_text(addr) ||
27527- is_kernel_text(addr2))
27528+ if (is_kernel_text(address, address + PMD_SIZE))
27529 prot = PAGE_KERNEL_LARGE_EXEC;
27530
27531 pages_2m++;
27532@@ -331,7 +332,7 @@ repeat:
27533 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
27534 pte += pte_ofs;
27535 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
27536- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
27537+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
27538 pgprot_t prot = PAGE_KERNEL;
27539 /*
27540 * first pass will use the same initial
27541@@ -339,7 +340,7 @@ repeat:
27542 */
27543 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
27544
27545- if (is_kernel_text(addr))
27546+ if (is_kernel_text(address, address + PAGE_SIZE))
27547 prot = PAGE_KERNEL_EXEC;
27548
27549 pages_4k++;
27550@@ -465,7 +466,7 @@ void __init native_pagetable_init(void)
27551
27552 pud = pud_offset(pgd, va);
27553 pmd = pmd_offset(pud, va);
27554- if (!pmd_present(*pmd))
27555+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
27556 break;
27557
27558 pte = pte_offset_kernel(pmd, va);
27559@@ -514,12 +515,10 @@ void __init early_ioremap_page_table_range_init(void)
27560
27561 static void __init pagetable_init(void)
27562 {
27563- pgd_t *pgd_base = swapper_pg_dir;
27564-
27565- permanent_kmaps_init(pgd_base);
27566+ permanent_kmaps_init(swapper_pg_dir);
27567 }
27568
27569-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
27570+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
27571 EXPORT_SYMBOL_GPL(__supported_pte_mask);
27572
27573 /* user-defined highmem size */
27574@@ -728,6 +727,12 @@ void __init mem_init(void)
27575
27576 pci_iommu_alloc();
27577
27578+#ifdef CONFIG_PAX_PER_CPU_PGD
27579+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
27580+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27581+ KERNEL_PGD_PTRS);
27582+#endif
27583+
27584 #ifdef CONFIG_FLATMEM
27585 BUG_ON(!mem_map);
27586 #endif
27587@@ -754,7 +759,7 @@ void __init mem_init(void)
27588 reservedpages++;
27589
27590 codesize = (unsigned long) &_etext - (unsigned long) &_text;
27591- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
27592+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
27593 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
27594
27595 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
27596@@ -795,10 +800,10 @@ void __init mem_init(void)
27597 ((unsigned long)&__init_end -
27598 (unsigned long)&__init_begin) >> 10,
27599
27600- (unsigned long)&_etext, (unsigned long)&_edata,
27601- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
27602+ (unsigned long)&_sdata, (unsigned long)&_edata,
27603+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
27604
27605- (unsigned long)&_text, (unsigned long)&_etext,
27606+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
27607 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
27608
27609 /*
27610@@ -876,6 +881,7 @@ void set_kernel_text_rw(void)
27611 if (!kernel_set_to_readonly)
27612 return;
27613
27614+ start = ktla_ktva(start);
27615 pr_debug("Set kernel text: %lx - %lx for read write\n",
27616 start, start+size);
27617
27618@@ -890,6 +896,7 @@ void set_kernel_text_ro(void)
27619 if (!kernel_set_to_readonly)
27620 return;
27621
27622+ start = ktla_ktva(start);
27623 pr_debug("Set kernel text: %lx - %lx for read only\n",
27624 start, start+size);
27625
27626@@ -918,6 +925,7 @@ void mark_rodata_ro(void)
27627 unsigned long start = PFN_ALIGN(_text);
27628 unsigned long size = PFN_ALIGN(_etext) - start;
27629
27630+ start = ktla_ktva(start);
27631 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
27632 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
27633 size >> 10);
27634diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
27635index 75c9a6a..498d677 100644
27636--- a/arch/x86/mm/init_64.c
27637+++ b/arch/x86/mm/init_64.c
27638@@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
27639 * around without checking the pgd every time.
27640 */
27641
27642-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
27643+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
27644 EXPORT_SYMBOL_GPL(__supported_pte_mask);
27645
27646 int force_personality32;
27647@@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
27648
27649 for (address = start; address <= end; address += PGDIR_SIZE) {
27650 const pgd_t *pgd_ref = pgd_offset_k(address);
27651+
27652+#ifdef CONFIG_PAX_PER_CPU_PGD
27653+ unsigned long cpu;
27654+#else
27655 struct page *page;
27656+#endif
27657
27658 if (pgd_none(*pgd_ref))
27659 continue;
27660
27661 spin_lock(&pgd_lock);
27662+
27663+#ifdef CONFIG_PAX_PER_CPU_PGD
27664+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
27665+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
27666+#else
27667 list_for_each_entry(page, &pgd_list, lru) {
27668 pgd_t *pgd;
27669 spinlock_t *pgt_lock;
27670@@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
27671 /* the pgt_lock only for Xen */
27672 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
27673 spin_lock(pgt_lock);
27674+#endif
27675
27676 if (pgd_none(*pgd))
27677 set_pgd(pgd, *pgd_ref);
27678@@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
27679 BUG_ON(pgd_page_vaddr(*pgd)
27680 != pgd_page_vaddr(*pgd_ref));
27681
27682+#ifndef CONFIG_PAX_PER_CPU_PGD
27683 spin_unlock(pgt_lock);
27684+#endif
27685+
27686 }
27687 spin_unlock(&pgd_lock);
27688 }
27689@@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
27690 {
27691 if (pgd_none(*pgd)) {
27692 pud_t *pud = (pud_t *)spp_getpage();
27693- pgd_populate(&init_mm, pgd, pud);
27694+ pgd_populate_kernel(&init_mm, pgd, pud);
27695 if (pud != pud_offset(pgd, 0))
27696 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
27697 pud, pud_offset(pgd, 0));
27698@@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
27699 {
27700 if (pud_none(*pud)) {
27701 pmd_t *pmd = (pmd_t *) spp_getpage();
27702- pud_populate(&init_mm, pud, pmd);
27703+ pud_populate_kernel(&init_mm, pud, pmd);
27704 if (pmd != pmd_offset(pud, 0))
27705 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
27706 pmd, pmd_offset(pud, 0));
27707@@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
27708 pmd = fill_pmd(pud, vaddr);
27709 pte = fill_pte(pmd, vaddr);
27710
27711+ pax_open_kernel();
27712 set_pte(pte, new_pte);
27713+ pax_close_kernel();
27714
27715 /*
27716 * It's enough to flush this one mapping.
27717@@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
27718 pgd = pgd_offset_k((unsigned long)__va(phys));
27719 if (pgd_none(*pgd)) {
27720 pud = (pud_t *) spp_getpage();
27721- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
27722- _PAGE_USER));
27723+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
27724 }
27725 pud = pud_offset(pgd, (unsigned long)__va(phys));
27726 if (pud_none(*pud)) {
27727 pmd = (pmd_t *) spp_getpage();
27728- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
27729- _PAGE_USER));
27730+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
27731 }
27732 pmd = pmd_offset(pud, phys);
27733 BUG_ON(!pmd_none(*pmd));
27734@@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
27735 if (pfn >= pgt_buf_top)
27736 panic("alloc_low_page: ran out of memory");
27737
27738- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
27739+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
27740 clear_page(adr);
27741 *phys = pfn * PAGE_SIZE;
27742 return adr;
27743@@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
27744
27745 phys = __pa(virt);
27746 left = phys & (PAGE_SIZE - 1);
27747- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
27748+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
27749 adr = (void *)(((unsigned long)adr) | left);
27750
27751 return adr;
27752@@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
27753 unmap_low_page(pmd);
27754
27755 spin_lock(&init_mm.page_table_lock);
27756- pud_populate(&init_mm, pud, __va(pmd_phys));
27757+ pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
27758 spin_unlock(&init_mm.page_table_lock);
27759 }
27760 __flush_tlb_all();
27761@@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
27762 unmap_low_page(pud);
27763
27764 spin_lock(&init_mm.page_table_lock);
27765- pgd_populate(&init_mm, pgd, __va(pud_phys));
27766+ pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
27767 spin_unlock(&init_mm.page_table_lock);
27768 pgd_changed = true;
27769 }
27770@@ -693,6 +707,12 @@ void __init mem_init(void)
27771
27772 pci_iommu_alloc();
27773
27774+#ifdef CONFIG_PAX_PER_CPU_PGD
27775+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
27776+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27777+ KERNEL_PGD_PTRS);
27778+#endif
27779+
27780 /* clear_bss() already clear the empty_zero_page */
27781
27782 reservedpages = 0;
27783@@ -856,8 +876,8 @@ int kern_addr_valid(unsigned long addr)
27784 static struct vm_area_struct gate_vma = {
27785 .vm_start = VSYSCALL_START,
27786 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
27787- .vm_page_prot = PAGE_READONLY_EXEC,
27788- .vm_flags = VM_READ | VM_EXEC
27789+ .vm_page_prot = PAGE_READONLY,
27790+ .vm_flags = VM_READ
27791 };
27792
27793 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27794@@ -891,7 +911,7 @@ int in_gate_area_no_mm(unsigned long addr)
27795
27796 const char *arch_vma_name(struct vm_area_struct *vma)
27797 {
27798- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27799+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27800 return "[vdso]";
27801 if (vma == &gate_vma)
27802 return "[vsyscall]";
27803diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
27804index 7b179b4..6bd1777 100644
27805--- a/arch/x86/mm/iomap_32.c
27806+++ b/arch/x86/mm/iomap_32.c
27807@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
27808 type = kmap_atomic_idx_push();
27809 idx = type + KM_TYPE_NR * smp_processor_id();
27810 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
27811+
27812+ pax_open_kernel();
27813 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
27814+ pax_close_kernel();
27815+
27816 arch_flush_lazy_mmu_mode();
27817
27818 return (void *)vaddr;
27819diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
27820index 78fe3f1..2f9433c 100644
27821--- a/arch/x86/mm/ioremap.c
27822+++ b/arch/x86/mm/ioremap.c
27823@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
27824 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
27825 int is_ram = page_is_ram(pfn);
27826
27827- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
27828+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
27829 return NULL;
27830 WARN_ON_ONCE(is_ram);
27831 }
27832@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
27833 *
27834 * Caller must ensure there is only one unmapping for the same pointer.
27835 */
27836-void iounmap(volatile void __iomem *addr)
27837+void iounmap(const volatile void __iomem *addr)
27838 {
27839 struct vm_struct *p, *o;
27840
27841@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
27842
27843 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
27844 if (page_is_ram(start >> PAGE_SHIFT))
27845+#ifdef CONFIG_HIGHMEM
27846+ if ((start >> PAGE_SHIFT) < max_low_pfn)
27847+#endif
27848 return __va(phys);
27849
27850 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
27851@@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
27852 early_param("early_ioremap_debug", early_ioremap_debug_setup);
27853
27854 static __initdata int after_paging_init;
27855-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
27856+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
27857
27858 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
27859 {
27860@@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
27861 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
27862
27863 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
27864- memset(bm_pte, 0, sizeof(bm_pte));
27865- pmd_populate_kernel(&init_mm, pmd, bm_pte);
27866+ pmd_populate_user(&init_mm, pmd, bm_pte);
27867
27868 /*
27869 * The boot-ioremap range spans multiple pmds, for which
27870diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
27871index d87dd6d..bf3fa66 100644
27872--- a/arch/x86/mm/kmemcheck/kmemcheck.c
27873+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
27874@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
27875 * memory (e.g. tracked pages)? For now, we need this to avoid
27876 * invoking kmemcheck for PnP BIOS calls.
27877 */
27878- if (regs->flags & X86_VM_MASK)
27879+ if (v8086_mode(regs))
27880 return false;
27881- if (regs->cs != __KERNEL_CS)
27882+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
27883 return false;
27884
27885 pte = kmemcheck_pte_lookup(address);
27886diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
27887index 845df68..1d8d29f 100644
27888--- a/arch/x86/mm/mmap.c
27889+++ b/arch/x86/mm/mmap.c
27890@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
27891 * Leave an at least ~128 MB hole with possible stack randomization.
27892 */
27893 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
27894-#define MAX_GAP (TASK_SIZE/6*5)
27895+#define MAX_GAP (pax_task_size/6*5)
27896
27897 static int mmap_is_legacy(void)
27898 {
27899@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
27900 return rnd << PAGE_SHIFT;
27901 }
27902
27903-static unsigned long mmap_base(void)
27904+static unsigned long mmap_base(struct mm_struct *mm)
27905 {
27906 unsigned long gap = rlimit(RLIMIT_STACK);
27907+ unsigned long pax_task_size = TASK_SIZE;
27908+
27909+#ifdef CONFIG_PAX_SEGMEXEC
27910+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27911+ pax_task_size = SEGMEXEC_TASK_SIZE;
27912+#endif
27913
27914 if (gap < MIN_GAP)
27915 gap = MIN_GAP;
27916 else if (gap > MAX_GAP)
27917 gap = MAX_GAP;
27918
27919- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
27920+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
27921 }
27922
27923 /*
27924 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
27925 * does, but not when emulating X86_32
27926 */
27927-static unsigned long mmap_legacy_base(void)
27928+static unsigned long mmap_legacy_base(struct mm_struct *mm)
27929 {
27930- if (mmap_is_ia32())
27931+ if (mmap_is_ia32()) {
27932+
27933+#ifdef CONFIG_PAX_SEGMEXEC
27934+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27935+ return SEGMEXEC_TASK_UNMAPPED_BASE;
27936+ else
27937+#endif
27938+
27939 return TASK_UNMAPPED_BASE;
27940- else
27941+ } else
27942 return TASK_UNMAPPED_BASE + mmap_rnd();
27943 }
27944
27945@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
27946 void arch_pick_mmap_layout(struct mm_struct *mm)
27947 {
27948 if (mmap_is_legacy()) {
27949- mm->mmap_base = mmap_legacy_base();
27950+ mm->mmap_base = mmap_legacy_base(mm);
27951+
27952+#ifdef CONFIG_PAX_RANDMMAP
27953+ if (mm->pax_flags & MF_PAX_RANDMMAP)
27954+ mm->mmap_base += mm->delta_mmap;
27955+#endif
27956+
27957 mm->get_unmapped_area = arch_get_unmapped_area;
27958 mm->unmap_area = arch_unmap_area;
27959 } else {
27960- mm->mmap_base = mmap_base();
27961+ mm->mmap_base = mmap_base(mm);
27962+
27963+#ifdef CONFIG_PAX_RANDMMAP
27964+ if (mm->pax_flags & MF_PAX_RANDMMAP)
27965+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
27966+#endif
27967+
27968 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
27969 mm->unmap_area = arch_unmap_area_topdown;
27970 }
27971diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
27972index dc0b727..f612039 100644
27973--- a/arch/x86/mm/mmio-mod.c
27974+++ b/arch/x86/mm/mmio-mod.c
27975@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
27976 break;
27977 default:
27978 {
27979- unsigned char *ip = (unsigned char *)instptr;
27980+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
27981 my_trace->opcode = MMIO_UNKNOWN_OP;
27982 my_trace->width = 0;
27983 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
27984@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
27985 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
27986 void __iomem *addr)
27987 {
27988- static atomic_t next_id;
27989+ static atomic_unchecked_t next_id;
27990 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
27991 /* These are page-unaligned. */
27992 struct mmiotrace_map map = {
27993@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
27994 .private = trace
27995 },
27996 .phys = offset,
27997- .id = atomic_inc_return(&next_id)
27998+ .id = atomic_inc_return_unchecked(&next_id)
27999 };
28000 map.map_id = trace->id;
28001
28002@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
28003 ioremap_trace_core(offset, size, addr);
28004 }
28005
28006-static void iounmap_trace_core(volatile void __iomem *addr)
28007+static void iounmap_trace_core(const volatile void __iomem *addr)
28008 {
28009 struct mmiotrace_map map = {
28010 .phys = 0,
28011@@ -328,7 +328,7 @@ not_enabled:
28012 }
28013 }
28014
28015-void mmiotrace_iounmap(volatile void __iomem *addr)
28016+void mmiotrace_iounmap(const volatile void __iomem *addr)
28017 {
28018 might_sleep();
28019 if (is_enabled()) /* recheck and proper locking in *_core() */
28020diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
28021index b008656..773eac2 100644
28022--- a/arch/x86/mm/pageattr-test.c
28023+++ b/arch/x86/mm/pageattr-test.c
28024@@ -36,7 +36,7 @@ enum {
28025
28026 static int pte_testbit(pte_t pte)
28027 {
28028- return pte_flags(pte) & _PAGE_UNUSED1;
28029+ return pte_flags(pte) & _PAGE_CPA_TEST;
28030 }
28031
28032 struct split_state {
28033diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
28034index a718e0d..77419bc 100644
28035--- a/arch/x86/mm/pageattr.c
28036+++ b/arch/x86/mm/pageattr.c
28037@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28038 */
28039 #ifdef CONFIG_PCI_BIOS
28040 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
28041- pgprot_val(forbidden) |= _PAGE_NX;
28042+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28043 #endif
28044
28045 /*
28046@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28047 * Does not cover __inittext since that is gone later on. On
28048 * 64bit we do not enforce !NX on the low mapping
28049 */
28050- if (within(address, (unsigned long)_text, (unsigned long)_etext))
28051- pgprot_val(forbidden) |= _PAGE_NX;
28052+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
28053+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28054
28055+#ifdef CONFIG_DEBUG_RODATA
28056 /*
28057 * The .rodata section needs to be read-only. Using the pfn
28058 * catches all aliases.
28059@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28060 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
28061 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
28062 pgprot_val(forbidden) |= _PAGE_RW;
28063+#endif
28064
28065 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
28066 /*
28067@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28068 }
28069 #endif
28070
28071+#ifdef CONFIG_PAX_KERNEXEC
28072+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
28073+ pgprot_val(forbidden) |= _PAGE_RW;
28074+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28075+ }
28076+#endif
28077+
28078 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
28079
28080 return prot;
28081@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
28082 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
28083 {
28084 /* change init_mm */
28085+ pax_open_kernel();
28086 set_pte_atomic(kpte, pte);
28087+
28088 #ifdef CONFIG_X86_32
28089 if (!SHARED_KERNEL_PMD) {
28090+
28091+#ifdef CONFIG_PAX_PER_CPU_PGD
28092+ unsigned long cpu;
28093+#else
28094 struct page *page;
28095+#endif
28096
28097+#ifdef CONFIG_PAX_PER_CPU_PGD
28098+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
28099+ pgd_t *pgd = get_cpu_pgd(cpu);
28100+#else
28101 list_for_each_entry(page, &pgd_list, lru) {
28102- pgd_t *pgd;
28103+ pgd_t *pgd = (pgd_t *)page_address(page);
28104+#endif
28105+
28106 pud_t *pud;
28107 pmd_t *pmd;
28108
28109- pgd = (pgd_t *)page_address(page) + pgd_index(address);
28110+ pgd += pgd_index(address);
28111 pud = pud_offset(pgd, address);
28112 pmd = pmd_offset(pud, address);
28113 set_pte_atomic((pte_t *)pmd, pte);
28114 }
28115 }
28116 #endif
28117+ pax_close_kernel();
28118 }
28119
28120 static int
28121diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
28122index 0eb572e..92f5c1e 100644
28123--- a/arch/x86/mm/pat.c
28124+++ b/arch/x86/mm/pat.c
28125@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
28126
28127 if (!entry) {
28128 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
28129- current->comm, current->pid, start, end - 1);
28130+ current->comm, task_pid_nr(current), start, end - 1);
28131 return -EINVAL;
28132 }
28133
28134@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28135
28136 while (cursor < to) {
28137 if (!devmem_is_allowed(pfn)) {
28138- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
28139- current->comm, from, to - 1);
28140+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
28141+ current->comm, from, to - 1, cursor);
28142 return 0;
28143 }
28144 cursor += PAGE_SIZE;
28145@@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
28146 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
28147 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
28148 "for [mem %#010Lx-%#010Lx]\n",
28149- current->comm, current->pid,
28150+ current->comm, task_pid_nr(current),
28151 cattr_name(flags),
28152 base, (unsigned long long)(base + size-1));
28153 return -EINVAL;
28154@@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
28155 flags = lookup_memtype(paddr);
28156 if (want_flags != flags) {
28157 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
28158- current->comm, current->pid,
28159+ current->comm, task_pid_nr(current),
28160 cattr_name(want_flags),
28161 (unsigned long long)paddr,
28162 (unsigned long long)(paddr + size - 1),
28163@@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
28164 free_memtype(paddr, paddr + size);
28165 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
28166 " for [mem %#010Lx-%#010Lx], got %s\n",
28167- current->comm, current->pid,
28168+ current->comm, task_pid_nr(current),
28169 cattr_name(want_flags),
28170 (unsigned long long)paddr,
28171 (unsigned long long)(paddr + size - 1),
28172diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
28173index 9f0614d..92ae64a 100644
28174--- a/arch/x86/mm/pf_in.c
28175+++ b/arch/x86/mm/pf_in.c
28176@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
28177 int i;
28178 enum reason_type rv = OTHERS;
28179
28180- p = (unsigned char *)ins_addr;
28181+ p = (unsigned char *)ktla_ktva(ins_addr);
28182 p += skip_prefix(p, &prf);
28183 p += get_opcode(p, &opcode);
28184
28185@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
28186 struct prefix_bits prf;
28187 int i;
28188
28189- p = (unsigned char *)ins_addr;
28190+ p = (unsigned char *)ktla_ktva(ins_addr);
28191 p += skip_prefix(p, &prf);
28192 p += get_opcode(p, &opcode);
28193
28194@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
28195 struct prefix_bits prf;
28196 int i;
28197
28198- p = (unsigned char *)ins_addr;
28199+ p = (unsigned char *)ktla_ktva(ins_addr);
28200 p += skip_prefix(p, &prf);
28201 p += get_opcode(p, &opcode);
28202
28203@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
28204 struct prefix_bits prf;
28205 int i;
28206
28207- p = (unsigned char *)ins_addr;
28208+ p = (unsigned char *)ktla_ktva(ins_addr);
28209 p += skip_prefix(p, &prf);
28210 p += get_opcode(p, &opcode);
28211 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
28212@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
28213 struct prefix_bits prf;
28214 int i;
28215
28216- p = (unsigned char *)ins_addr;
28217+ p = (unsigned char *)ktla_ktva(ins_addr);
28218 p += skip_prefix(p, &prf);
28219 p += get_opcode(p, &opcode);
28220 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
28221diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
28222index e27fbf8..8b56dc9 100644
28223--- a/arch/x86/mm/pgtable.c
28224+++ b/arch/x86/mm/pgtable.c
28225@@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
28226 list_del(&page->lru);
28227 }
28228
28229-#define UNSHARED_PTRS_PER_PGD \
28230- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
28231+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28232+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
28233
28234+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
28235+{
28236+ unsigned int count = USER_PGD_PTRS;
28237
28238+ while (count--)
28239+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
28240+}
28241+#endif
28242+
28243+#ifdef CONFIG_PAX_PER_CPU_PGD
28244+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
28245+{
28246+ unsigned int count = USER_PGD_PTRS;
28247+
28248+ while (count--) {
28249+ pgd_t pgd;
28250+
28251+#ifdef CONFIG_X86_64
28252+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
28253+#else
28254+ pgd = *src++;
28255+#endif
28256+
28257+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28258+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
28259+#endif
28260+
28261+ *dst++ = pgd;
28262+ }
28263+
28264+}
28265+#endif
28266+
28267+#ifdef CONFIG_X86_64
28268+#define pxd_t pud_t
28269+#define pyd_t pgd_t
28270+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
28271+#define pxd_free(mm, pud) pud_free((mm), (pud))
28272+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
28273+#define pyd_offset(mm, address) pgd_offset((mm), (address))
28274+#define PYD_SIZE PGDIR_SIZE
28275+#else
28276+#define pxd_t pmd_t
28277+#define pyd_t pud_t
28278+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
28279+#define pxd_free(mm, pud) pmd_free((mm), (pud))
28280+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
28281+#define pyd_offset(mm, address) pud_offset((mm), (address))
28282+#define PYD_SIZE PUD_SIZE
28283+#endif
28284+
28285+#ifdef CONFIG_PAX_PER_CPU_PGD
28286+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
28287+static inline void pgd_dtor(pgd_t *pgd) {}
28288+#else
28289 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
28290 {
28291 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
28292@@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
28293 pgd_list_del(pgd);
28294 spin_unlock(&pgd_lock);
28295 }
28296+#endif
28297
28298 /*
28299 * List of all pgd's needed for non-PAE so it can invalidate entries
28300@@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
28301 * -- nyc
28302 */
28303
28304-#ifdef CONFIG_X86_PAE
28305+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
28306 /*
28307 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
28308 * updating the top-level pagetable entries to guarantee the
28309@@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
28310 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
28311 * and initialize the kernel pmds here.
28312 */
28313-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
28314+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
28315
28316 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
28317 {
28318@@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
28319 */
28320 flush_tlb_mm(mm);
28321 }
28322+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
28323+#define PREALLOCATED_PXDS USER_PGD_PTRS
28324 #else /* !CONFIG_X86_PAE */
28325
28326 /* No need to prepopulate any pagetable entries in non-PAE modes. */
28327-#define PREALLOCATED_PMDS 0
28328+#define PREALLOCATED_PXDS 0
28329
28330 #endif /* CONFIG_X86_PAE */
28331
28332-static void free_pmds(pmd_t *pmds[])
28333+static void free_pxds(pxd_t *pxds[])
28334 {
28335 int i;
28336
28337- for(i = 0; i < PREALLOCATED_PMDS; i++)
28338- if (pmds[i])
28339- free_page((unsigned long)pmds[i]);
28340+ for(i = 0; i < PREALLOCATED_PXDS; i++)
28341+ if (pxds[i])
28342+ free_page((unsigned long)pxds[i]);
28343 }
28344
28345-static int preallocate_pmds(pmd_t *pmds[])
28346+static int preallocate_pxds(pxd_t *pxds[])
28347 {
28348 int i;
28349 bool failed = false;
28350
28351- for(i = 0; i < PREALLOCATED_PMDS; i++) {
28352- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
28353- if (pmd == NULL)
28354+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
28355+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
28356+ if (pxd == NULL)
28357 failed = true;
28358- pmds[i] = pmd;
28359+ pxds[i] = pxd;
28360 }
28361
28362 if (failed) {
28363- free_pmds(pmds);
28364+ free_pxds(pxds);
28365 return -ENOMEM;
28366 }
28367
28368@@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
28369 * preallocate which never got a corresponding vma will need to be
28370 * freed manually.
28371 */
28372-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
28373+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
28374 {
28375 int i;
28376
28377- for(i = 0; i < PREALLOCATED_PMDS; i++) {
28378+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
28379 pgd_t pgd = pgdp[i];
28380
28381 if (pgd_val(pgd) != 0) {
28382- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
28383+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
28384
28385- pgdp[i] = native_make_pgd(0);
28386+ set_pgd(pgdp + i, native_make_pgd(0));
28387
28388- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
28389- pmd_free(mm, pmd);
28390+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
28391+ pxd_free(mm, pxd);
28392 }
28393 }
28394 }
28395
28396-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
28397+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
28398 {
28399- pud_t *pud;
28400+ pyd_t *pyd;
28401 unsigned long addr;
28402 int i;
28403
28404- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
28405+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
28406 return;
28407
28408- pud = pud_offset(pgd, 0);
28409+#ifdef CONFIG_X86_64
28410+ pyd = pyd_offset(mm, 0L);
28411+#else
28412+ pyd = pyd_offset(pgd, 0L);
28413+#endif
28414
28415- for (addr = i = 0; i < PREALLOCATED_PMDS;
28416- i++, pud++, addr += PUD_SIZE) {
28417- pmd_t *pmd = pmds[i];
28418+ for (addr = i = 0; i < PREALLOCATED_PXDS;
28419+ i++, pyd++, addr += PYD_SIZE) {
28420+ pxd_t *pxd = pxds[i];
28421
28422 if (i >= KERNEL_PGD_BOUNDARY)
28423- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
28424- sizeof(pmd_t) * PTRS_PER_PMD);
28425+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
28426+ sizeof(pxd_t) * PTRS_PER_PMD);
28427
28428- pud_populate(mm, pud, pmd);
28429+ pyd_populate(mm, pyd, pxd);
28430 }
28431 }
28432
28433 pgd_t *pgd_alloc(struct mm_struct *mm)
28434 {
28435 pgd_t *pgd;
28436- pmd_t *pmds[PREALLOCATED_PMDS];
28437+ pxd_t *pxds[PREALLOCATED_PXDS];
28438
28439 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
28440
28441@@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
28442
28443 mm->pgd = pgd;
28444
28445- if (preallocate_pmds(pmds) != 0)
28446+ if (preallocate_pxds(pxds) != 0)
28447 goto out_free_pgd;
28448
28449 if (paravirt_pgd_alloc(mm) != 0)
28450- goto out_free_pmds;
28451+ goto out_free_pxds;
28452
28453 /*
28454 * Make sure that pre-populating the pmds is atomic with
28455@@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
28456 spin_lock(&pgd_lock);
28457
28458 pgd_ctor(mm, pgd);
28459- pgd_prepopulate_pmd(mm, pgd, pmds);
28460+ pgd_prepopulate_pxd(mm, pgd, pxds);
28461
28462 spin_unlock(&pgd_lock);
28463
28464 return pgd;
28465
28466-out_free_pmds:
28467- free_pmds(pmds);
28468+out_free_pxds:
28469+ free_pxds(pxds);
28470 out_free_pgd:
28471 free_page((unsigned long)pgd);
28472 out:
28473@@ -295,7 +356,7 @@ out:
28474
28475 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
28476 {
28477- pgd_mop_up_pmds(mm, pgd);
28478+ pgd_mop_up_pxds(mm, pgd);
28479 pgd_dtor(pgd);
28480 paravirt_pgd_free(mm, pgd);
28481 free_page((unsigned long)pgd);
28482diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
28483index a69bcb8..19068ab 100644
28484--- a/arch/x86/mm/pgtable_32.c
28485+++ b/arch/x86/mm/pgtable_32.c
28486@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
28487 return;
28488 }
28489 pte = pte_offset_kernel(pmd, vaddr);
28490+
28491+ pax_open_kernel();
28492 if (pte_val(pteval))
28493 set_pte_at(&init_mm, vaddr, pte, pteval);
28494 else
28495 pte_clear(&init_mm, vaddr, pte);
28496+ pax_close_kernel();
28497
28498 /*
28499 * It's enough to flush this one mapping.
28500diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
28501index 410531d..0f16030 100644
28502--- a/arch/x86/mm/setup_nx.c
28503+++ b/arch/x86/mm/setup_nx.c
28504@@ -5,8 +5,10 @@
28505 #include <asm/pgtable.h>
28506 #include <asm/proto.h>
28507
28508+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
28509 static int disable_nx __cpuinitdata;
28510
28511+#ifndef CONFIG_PAX_PAGEEXEC
28512 /*
28513 * noexec = on|off
28514 *
28515@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
28516 return 0;
28517 }
28518 early_param("noexec", noexec_setup);
28519+#endif
28520+
28521+#endif
28522
28523 void __cpuinit x86_configure_nx(void)
28524 {
28525+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
28526 if (cpu_has_nx && !disable_nx)
28527 __supported_pte_mask |= _PAGE_NX;
28528 else
28529+#endif
28530 __supported_pte_mask &= ~_PAGE_NX;
28531 }
28532
28533diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
28534index 13a6b29..c2fff23 100644
28535--- a/arch/x86/mm/tlb.c
28536+++ b/arch/x86/mm/tlb.c
28537@@ -48,7 +48,11 @@ void leave_mm(int cpu)
28538 BUG();
28539 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
28540 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
28541+
28542+#ifndef CONFIG_PAX_PER_CPU_PGD
28543 load_cr3(swapper_pg_dir);
28544+#endif
28545+
28546 }
28547 }
28548 EXPORT_SYMBOL_GPL(leave_mm);
28549diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
28550index 877b9a1..a8ecf42 100644
28551--- a/arch/x86/net/bpf_jit.S
28552+++ b/arch/x86/net/bpf_jit.S
28553@@ -9,6 +9,7 @@
28554 */
28555 #include <linux/linkage.h>
28556 #include <asm/dwarf2.h>
28557+#include <asm/alternative-asm.h>
28558
28559 /*
28560 * Calling convention :
28561@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
28562 jle bpf_slow_path_word
28563 mov (SKBDATA,%rsi),%eax
28564 bswap %eax /* ntohl() */
28565+ pax_force_retaddr
28566 ret
28567
28568 sk_load_half:
28569@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
28570 jle bpf_slow_path_half
28571 movzwl (SKBDATA,%rsi),%eax
28572 rol $8,%ax # ntohs()
28573+ pax_force_retaddr
28574 ret
28575
28576 sk_load_byte:
28577@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
28578 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
28579 jle bpf_slow_path_byte
28580 movzbl (SKBDATA,%rsi),%eax
28581+ pax_force_retaddr
28582 ret
28583
28584 /**
28585@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
28586 movzbl (SKBDATA,%rsi),%ebx
28587 and $15,%bl
28588 shl $2,%bl
28589+ pax_force_retaddr
28590 ret
28591
28592 /* rsi contains offset and can be scratched */
28593@@ -109,6 +114,7 @@ bpf_slow_path_word:
28594 js bpf_error
28595 mov -12(%rbp),%eax
28596 bswap %eax
28597+ pax_force_retaddr
28598 ret
28599
28600 bpf_slow_path_half:
28601@@ -117,12 +123,14 @@ bpf_slow_path_half:
28602 mov -12(%rbp),%ax
28603 rol $8,%ax
28604 movzwl %ax,%eax
28605+ pax_force_retaddr
28606 ret
28607
28608 bpf_slow_path_byte:
28609 bpf_slow_path_common(1)
28610 js bpf_error
28611 movzbl -12(%rbp),%eax
28612+ pax_force_retaddr
28613 ret
28614
28615 bpf_slow_path_byte_msh:
28616@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
28617 and $15,%al
28618 shl $2,%al
28619 xchg %eax,%ebx
28620+ pax_force_retaddr
28621 ret
28622
28623 #define sk_negative_common(SIZE) \
28624@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
28625 sk_negative_common(4)
28626 mov (%rax), %eax
28627 bswap %eax
28628+ pax_force_retaddr
28629 ret
28630
28631 bpf_slow_path_half_neg:
28632@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
28633 mov (%rax),%ax
28634 rol $8,%ax
28635 movzwl %ax,%eax
28636+ pax_force_retaddr
28637 ret
28638
28639 bpf_slow_path_byte_neg:
28640@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
28641 .globl sk_load_byte_negative_offset
28642 sk_negative_common(1)
28643 movzbl (%rax), %eax
28644+ pax_force_retaddr
28645 ret
28646
28647 bpf_slow_path_byte_msh_neg:
28648@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
28649 and $15,%al
28650 shl $2,%al
28651 xchg %eax,%ebx
28652+ pax_force_retaddr
28653 ret
28654
28655 bpf_error:
28656@@ -197,4 +210,5 @@ bpf_error:
28657 xor %eax,%eax
28658 mov -8(%rbp),%rbx
28659 leaveq
28660+ pax_force_retaddr
28661 ret
28662diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
28663index d11a470..3f9adff3 100644
28664--- a/arch/x86/net/bpf_jit_comp.c
28665+++ b/arch/x86/net/bpf_jit_comp.c
28666@@ -12,6 +12,7 @@
28667 #include <linux/netdevice.h>
28668 #include <linux/filter.h>
28669 #include <linux/if_vlan.h>
28670+#include <linux/random.h>
28671
28672 /*
28673 * Conventions :
28674@@ -49,13 +50,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
28675 return ptr + len;
28676 }
28677
28678+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28679+#define MAX_INSTR_CODE_SIZE 96
28680+#else
28681+#define MAX_INSTR_CODE_SIZE 64
28682+#endif
28683+
28684 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
28685
28686 #define EMIT1(b1) EMIT(b1, 1)
28687 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
28688 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
28689 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
28690+
28691+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28692+/* original constant will appear in ecx */
28693+#define DILUTE_CONST_SEQUENCE(_off, _key) \
28694+do { \
28695+ /* mov ecx, randkey */ \
28696+ EMIT1(0xb9); \
28697+ EMIT(_key, 4); \
28698+ /* xor ecx, randkey ^ off */ \
28699+ EMIT2(0x81, 0xf1); \
28700+ EMIT((_key) ^ (_off), 4); \
28701+} while (0)
28702+
28703+#define EMIT1_off32(b1, _off) \
28704+do { \
28705+ switch (b1) { \
28706+ case 0x05: /* add eax, imm32 */ \
28707+ case 0x2d: /* sub eax, imm32 */ \
28708+ case 0x25: /* and eax, imm32 */ \
28709+ case 0x0d: /* or eax, imm32 */ \
28710+ case 0xb8: /* mov eax, imm32 */ \
28711+ case 0x3d: /* cmp eax, imm32 */ \
28712+ case 0xa9: /* test eax, imm32 */ \
28713+ DILUTE_CONST_SEQUENCE(_off, randkey); \
28714+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
28715+ break; \
28716+ case 0xbb: /* mov ebx, imm32 */ \
28717+ DILUTE_CONST_SEQUENCE(_off, randkey); \
28718+ /* mov ebx, ecx */ \
28719+ EMIT2(0x89, 0xcb); \
28720+ break; \
28721+ case 0xbe: /* mov esi, imm32 */ \
28722+ DILUTE_CONST_SEQUENCE(_off, randkey); \
28723+ /* mov esi, ecx */ \
28724+ EMIT2(0x89, 0xce); \
28725+ break; \
28726+ case 0xe9: /* jmp rel imm32 */ \
28727+ EMIT1(b1); \
28728+ EMIT(_off, 4); \
28729+ /* prevent fall-through, we're not called if off = 0 */ \
28730+ EMIT(0xcccccccc, 4); \
28731+ EMIT(0xcccccccc, 4); \
28732+ break; \
28733+ default: \
28734+ EMIT1(b1); \
28735+ EMIT(_off, 4); \
28736+ } \
28737+} while (0)
28738+
28739+#define EMIT2_off32(b1, b2, _off) \
28740+do { \
28741+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
28742+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
28743+ EMIT(randkey, 4); \
28744+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
28745+ EMIT((_off) - randkey, 4); \
28746+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
28747+ DILUTE_CONST_SEQUENCE(_off, randkey); \
28748+ /* imul eax, ecx */ \
28749+ EMIT3(0x0f, 0xaf, 0xc1); \
28750+ } else { \
28751+ EMIT2(b1, b2); \
28752+ EMIT(_off, 4); \
28753+ } \
28754+} while (0)
28755+#else
28756 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
28757+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
28758+#endif
28759
28760 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
28761 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
28762@@ -90,6 +165,24 @@ do { \
28763 #define X86_JBE 0x76
28764 #define X86_JA 0x77
28765
28766+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28767+#define APPEND_FLOW_VERIFY() \
28768+do { \
28769+ /* mov ecx, randkey */ \
28770+ EMIT1(0xb9); \
28771+ EMIT(randkey, 4); \
28772+ /* cmp ecx, randkey */ \
28773+ EMIT2(0x81, 0xf9); \
28774+ EMIT(randkey, 4); \
28775+ /* jz after 8 int 3s */ \
28776+ EMIT2(0x74, 0x08); \
28777+ EMIT(0xcccccccc, 4); \
28778+ EMIT(0xcccccccc, 4); \
28779+} while (0)
28780+#else
28781+#define APPEND_FLOW_VERIFY() do { } while (0)
28782+#endif
28783+
28784 #define EMIT_COND_JMP(op, offset) \
28785 do { \
28786 if (is_near(offset)) \
28787@@ -97,6 +190,7 @@ do { \
28788 else { \
28789 EMIT2(0x0f, op + 0x10); \
28790 EMIT(offset, 4); /* jxx .+off32 */ \
28791+ APPEND_FLOW_VERIFY(); \
28792 } \
28793 } while (0)
28794
28795@@ -121,12 +215,17 @@ static inline void bpf_flush_icache(void *start, void *end)
28796 set_fs(old_fs);
28797 }
28798
28799+struct bpf_jit_work {
28800+ struct work_struct work;
28801+ void *image;
28802+};
28803+
28804 #define CHOOSE_LOAD_FUNC(K, func) \
28805 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
28806
28807 void bpf_jit_compile(struct sk_filter *fp)
28808 {
28809- u8 temp[64];
28810+ u8 temp[MAX_INSTR_CODE_SIZE];
28811 u8 *prog;
28812 unsigned int proglen, oldproglen = 0;
28813 int ilen, i;
28814@@ -139,6 +238,9 @@ void bpf_jit_compile(struct sk_filter *fp)
28815 unsigned int *addrs;
28816 const struct sock_filter *filter = fp->insns;
28817 int flen = fp->len;
28818+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28819+ unsigned int randkey;
28820+#endif
28821
28822 if (!bpf_jit_enable)
28823 return;
28824@@ -147,11 +249,19 @@ void bpf_jit_compile(struct sk_filter *fp)
28825 if (addrs == NULL)
28826 return;
28827
28828+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
28829+ if (!fp->work)
28830+ goto out;
28831+
28832+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28833+ randkey = get_random_int();
28834+#endif
28835+
28836 /* Before first pass, make a rough estimation of addrs[]
28837- * each bpf instruction is translated to less than 64 bytes
28838+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
28839 */
28840 for (proglen = 0, i = 0; i < flen; i++) {
28841- proglen += 64;
28842+ proglen += MAX_INSTR_CODE_SIZE;
28843 addrs[i] = proglen;
28844 }
28845 cleanup_addr = proglen; /* epilogue address */
28846@@ -261,10 +371,8 @@ void bpf_jit_compile(struct sk_filter *fp)
28847 case BPF_S_ALU_MUL_K: /* A *= K */
28848 if (is_imm8(K))
28849 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
28850- else {
28851- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
28852- EMIT(K, 4);
28853- }
28854+ else
28855+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
28856 break;
28857 case BPF_S_ALU_DIV_X: /* A /= X; */
28858 seen |= SEEN_XREG;
28859@@ -304,13 +412,23 @@ void bpf_jit_compile(struct sk_filter *fp)
28860 break;
28861 case BPF_S_ALU_MOD_K: /* A %= K; */
28862 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
28863+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28864+ DILUTE_CONST_SEQUENCE(K, randkey);
28865+#else
28866 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
28867+#endif
28868 EMIT2(0xf7, 0xf1); /* div %ecx */
28869 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
28870 break;
28871 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
28872+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28873+ DILUTE_CONST_SEQUENCE(K, randkey);
28874+ // imul rax, rcx
28875+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
28876+#else
28877 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
28878 EMIT(K, 4);
28879+#endif
28880 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
28881 break;
28882 case BPF_S_ALU_AND_X:
28883@@ -564,8 +682,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
28884 if (is_imm8(K)) {
28885 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
28886 } else {
28887- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
28888- EMIT(K, 4);
28889+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
28890 }
28891 } else {
28892 EMIT2(0x89,0xde); /* mov %ebx,%esi */
28893@@ -648,17 +765,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
28894 break;
28895 default:
28896 /* hmm, too complex filter, give up with jit compiler */
28897- goto out;
28898+ goto error;
28899 }
28900 ilen = prog - temp;
28901 if (image) {
28902 if (unlikely(proglen + ilen > oldproglen)) {
28903 pr_err("bpb_jit_compile fatal error\n");
28904- kfree(addrs);
28905- module_free(NULL, image);
28906- return;
28907+ module_free_exec(NULL, image);
28908+ goto error;
28909 }
28910+ pax_open_kernel();
28911 memcpy(image + proglen, temp, ilen);
28912+ pax_close_kernel();
28913 }
28914 proglen += ilen;
28915 addrs[i] = proglen;
28916@@ -679,11 +797,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
28917 break;
28918 }
28919 if (proglen == oldproglen) {
28920- image = module_alloc(max_t(unsigned int,
28921- proglen,
28922- sizeof(struct work_struct)));
28923+ image = module_alloc_exec(proglen);
28924 if (!image)
28925- goto out;
28926+ goto error;
28927 }
28928 oldproglen = proglen;
28929 }
28930@@ -699,7 +815,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
28931 bpf_flush_icache(image, image + proglen);
28932
28933 fp->bpf_func = (void *)image;
28934- }
28935+ } else
28936+error:
28937+ kfree(fp->work);
28938+
28939 out:
28940 kfree(addrs);
28941 return;
28942@@ -707,18 +826,20 @@ out:
28943
28944 static void jit_free_defer(struct work_struct *arg)
28945 {
28946- module_free(NULL, arg);
28947+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
28948+ kfree(arg);
28949 }
28950
28951 /* run from softirq, we must use a work_struct to call
28952- * module_free() from process context
28953+ * module_free_exec() from process context
28954 */
28955 void bpf_jit_free(struct sk_filter *fp)
28956 {
28957 if (fp->bpf_func != sk_run_filter) {
28958- struct work_struct *work = (struct work_struct *)fp->bpf_func;
28959+ struct work_struct *work = &fp->work->work;
28960
28961 INIT_WORK(work, jit_free_defer);
28962+ fp->work->image = fp->bpf_func;
28963 schedule_work(work);
28964 }
28965 }
28966diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
28967index d6aa6e8..266395a 100644
28968--- a/arch/x86/oprofile/backtrace.c
28969+++ b/arch/x86/oprofile/backtrace.c
28970@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
28971 struct stack_frame_ia32 *fp;
28972 unsigned long bytes;
28973
28974- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
28975+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
28976 if (bytes != sizeof(bufhead))
28977 return NULL;
28978
28979- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
28980+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
28981
28982 oprofile_add_trace(bufhead[0].return_address);
28983
28984@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
28985 struct stack_frame bufhead[2];
28986 unsigned long bytes;
28987
28988- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
28989+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
28990 if (bytes != sizeof(bufhead))
28991 return NULL;
28992
28993@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
28994 {
28995 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
28996
28997- if (!user_mode_vm(regs)) {
28998+ if (!user_mode(regs)) {
28999 unsigned long stack = kernel_stack_pointer(regs);
29000 if (depth)
29001 dump_trace(NULL, regs, (unsigned long *)stack, 0,
29002diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c
29003index e9e6ed5..e47ae67 100644
29004--- a/arch/x86/pci/amd_bus.c
29005+++ b/arch/x86/pci/amd_bus.c
29006@@ -337,7 +337,7 @@ static int __cpuinit amd_cpu_notify(struct notifier_block *self,
29007 return NOTIFY_OK;
29008 }
29009
29010-static struct notifier_block __cpuinitdata amd_cpu_notifier = {
29011+static struct notifier_block amd_cpu_notifier = {
29012 .notifier_call = amd_cpu_notify,
29013 };
29014
29015diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
29016index 6eb18c4..20d83de 100644
29017--- a/arch/x86/pci/mrst.c
29018+++ b/arch/x86/pci/mrst.c
29019@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
29020 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
29021 pci_mmcfg_late_init();
29022 pcibios_enable_irq = mrst_pci_irq_enable;
29023- pci_root_ops = pci_mrst_ops;
29024+ pax_open_kernel();
29025+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
29026+ pax_close_kernel();
29027 pci_soc_mode = 1;
29028 /* Continue with standard init */
29029 return 1;
29030diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
29031index c77b24a..c979855 100644
29032--- a/arch/x86/pci/pcbios.c
29033+++ b/arch/x86/pci/pcbios.c
29034@@ -79,7 +79,7 @@ union bios32 {
29035 static struct {
29036 unsigned long address;
29037 unsigned short segment;
29038-} bios32_indirect = { 0, __KERNEL_CS };
29039+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
29040
29041 /*
29042 * Returns the entry point for the given service, NULL on error
29043@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
29044 unsigned long length; /* %ecx */
29045 unsigned long entry; /* %edx */
29046 unsigned long flags;
29047+ struct desc_struct d, *gdt;
29048
29049 local_irq_save(flags);
29050- __asm__("lcall *(%%edi); cld"
29051+
29052+ gdt = get_cpu_gdt_table(smp_processor_id());
29053+
29054+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
29055+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
29056+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
29057+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
29058+
29059+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
29060 : "=a" (return_code),
29061 "=b" (address),
29062 "=c" (length),
29063 "=d" (entry)
29064 : "0" (service),
29065 "1" (0),
29066- "D" (&bios32_indirect));
29067+ "D" (&bios32_indirect),
29068+ "r"(__PCIBIOS_DS)
29069+ : "memory");
29070+
29071+ pax_open_kernel();
29072+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
29073+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
29074+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
29075+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
29076+ pax_close_kernel();
29077+
29078 local_irq_restore(flags);
29079
29080 switch (return_code) {
29081- case 0:
29082- return address + entry;
29083- case 0x80: /* Not present */
29084- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
29085- return 0;
29086- default: /* Shouldn't happen */
29087- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
29088- service, return_code);
29089+ case 0: {
29090+ int cpu;
29091+ unsigned char flags;
29092+
29093+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
29094+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
29095+ printk(KERN_WARNING "bios32_service: not valid\n");
29096 return 0;
29097+ }
29098+ address = address + PAGE_OFFSET;
29099+ length += 16UL; /* some BIOSs underreport this... */
29100+ flags = 4;
29101+ if (length >= 64*1024*1024) {
29102+ length >>= PAGE_SHIFT;
29103+ flags |= 8;
29104+ }
29105+
29106+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
29107+ gdt = get_cpu_gdt_table(cpu);
29108+ pack_descriptor(&d, address, length, 0x9b, flags);
29109+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
29110+ pack_descriptor(&d, address, length, 0x93, flags);
29111+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
29112+ }
29113+ return entry;
29114+ }
29115+ case 0x80: /* Not present */
29116+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
29117+ return 0;
29118+ default: /* Shouldn't happen */
29119+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
29120+ service, return_code);
29121+ return 0;
29122 }
29123 }
29124
29125 static struct {
29126 unsigned long address;
29127 unsigned short segment;
29128-} pci_indirect = { 0, __KERNEL_CS };
29129+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
29130
29131-static int pci_bios_present;
29132+static int pci_bios_present __read_only;
29133
29134 static int check_pcibios(void)
29135 {
29136@@ -131,11 +174,13 @@ static int check_pcibios(void)
29137 unsigned long flags, pcibios_entry;
29138
29139 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
29140- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
29141+ pci_indirect.address = pcibios_entry;
29142
29143 local_irq_save(flags);
29144- __asm__(
29145- "lcall *(%%edi); cld\n\t"
29146+ __asm__("movw %w6, %%ds\n\t"
29147+ "lcall *%%ss:(%%edi); cld\n\t"
29148+ "push %%ss\n\t"
29149+ "pop %%ds\n\t"
29150 "jc 1f\n\t"
29151 "xor %%ah, %%ah\n"
29152 "1:"
29153@@ -144,7 +189,8 @@ static int check_pcibios(void)
29154 "=b" (ebx),
29155 "=c" (ecx)
29156 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
29157- "D" (&pci_indirect)
29158+ "D" (&pci_indirect),
29159+ "r" (__PCIBIOS_DS)
29160 : "memory");
29161 local_irq_restore(flags);
29162
29163@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29164
29165 switch (len) {
29166 case 1:
29167- __asm__("lcall *(%%esi); cld\n\t"
29168+ __asm__("movw %w6, %%ds\n\t"
29169+ "lcall *%%ss:(%%esi); cld\n\t"
29170+ "push %%ss\n\t"
29171+ "pop %%ds\n\t"
29172 "jc 1f\n\t"
29173 "xor %%ah, %%ah\n"
29174 "1:"
29175@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29176 : "1" (PCIBIOS_READ_CONFIG_BYTE),
29177 "b" (bx),
29178 "D" ((long)reg),
29179- "S" (&pci_indirect));
29180+ "S" (&pci_indirect),
29181+ "r" (__PCIBIOS_DS));
29182 /*
29183 * Zero-extend the result beyond 8 bits, do not trust the
29184 * BIOS having done it:
29185@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29186 *value &= 0xff;
29187 break;
29188 case 2:
29189- __asm__("lcall *(%%esi); cld\n\t"
29190+ __asm__("movw %w6, %%ds\n\t"
29191+ "lcall *%%ss:(%%esi); cld\n\t"
29192+ "push %%ss\n\t"
29193+ "pop %%ds\n\t"
29194 "jc 1f\n\t"
29195 "xor %%ah, %%ah\n"
29196 "1:"
29197@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29198 : "1" (PCIBIOS_READ_CONFIG_WORD),
29199 "b" (bx),
29200 "D" ((long)reg),
29201- "S" (&pci_indirect));
29202+ "S" (&pci_indirect),
29203+ "r" (__PCIBIOS_DS));
29204 /*
29205 * Zero-extend the result beyond 16 bits, do not trust the
29206 * BIOS having done it:
29207@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29208 *value &= 0xffff;
29209 break;
29210 case 4:
29211- __asm__("lcall *(%%esi); cld\n\t"
29212+ __asm__("movw %w6, %%ds\n\t"
29213+ "lcall *%%ss:(%%esi); cld\n\t"
29214+ "push %%ss\n\t"
29215+ "pop %%ds\n\t"
29216 "jc 1f\n\t"
29217 "xor %%ah, %%ah\n"
29218 "1:"
29219@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29220 : "1" (PCIBIOS_READ_CONFIG_DWORD),
29221 "b" (bx),
29222 "D" ((long)reg),
29223- "S" (&pci_indirect));
29224+ "S" (&pci_indirect),
29225+ "r" (__PCIBIOS_DS));
29226 break;
29227 }
29228
29229@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29230
29231 switch (len) {
29232 case 1:
29233- __asm__("lcall *(%%esi); cld\n\t"
29234+ __asm__("movw %w6, %%ds\n\t"
29235+ "lcall *%%ss:(%%esi); cld\n\t"
29236+ "push %%ss\n\t"
29237+ "pop %%ds\n\t"
29238 "jc 1f\n\t"
29239 "xor %%ah, %%ah\n"
29240 "1:"
29241@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29242 "c" (value),
29243 "b" (bx),
29244 "D" ((long)reg),
29245- "S" (&pci_indirect));
29246+ "S" (&pci_indirect),
29247+ "r" (__PCIBIOS_DS));
29248 break;
29249 case 2:
29250- __asm__("lcall *(%%esi); cld\n\t"
29251+ __asm__("movw %w6, %%ds\n\t"
29252+ "lcall *%%ss:(%%esi); cld\n\t"
29253+ "push %%ss\n\t"
29254+ "pop %%ds\n\t"
29255 "jc 1f\n\t"
29256 "xor %%ah, %%ah\n"
29257 "1:"
29258@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29259 "c" (value),
29260 "b" (bx),
29261 "D" ((long)reg),
29262- "S" (&pci_indirect));
29263+ "S" (&pci_indirect),
29264+ "r" (__PCIBIOS_DS));
29265 break;
29266 case 4:
29267- __asm__("lcall *(%%esi); cld\n\t"
29268+ __asm__("movw %w6, %%ds\n\t"
29269+ "lcall *%%ss:(%%esi); cld\n\t"
29270+ "push %%ss\n\t"
29271+ "pop %%ds\n\t"
29272 "jc 1f\n\t"
29273 "xor %%ah, %%ah\n"
29274 "1:"
29275@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29276 "c" (value),
29277 "b" (bx),
29278 "D" ((long)reg),
29279- "S" (&pci_indirect));
29280+ "S" (&pci_indirect),
29281+ "r" (__PCIBIOS_DS));
29282 break;
29283 }
29284
29285@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
29286
29287 DBG("PCI: Fetching IRQ routing table... ");
29288 __asm__("push %%es\n\t"
29289+ "movw %w8, %%ds\n\t"
29290 "push %%ds\n\t"
29291 "pop %%es\n\t"
29292- "lcall *(%%esi); cld\n\t"
29293+ "lcall *%%ss:(%%esi); cld\n\t"
29294 "pop %%es\n\t"
29295+ "push %%ss\n\t"
29296+ "pop %%ds\n"
29297 "jc 1f\n\t"
29298 "xor %%ah, %%ah\n"
29299 "1:"
29300@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
29301 "1" (0),
29302 "D" ((long) &opt),
29303 "S" (&pci_indirect),
29304- "m" (opt)
29305+ "m" (opt),
29306+ "r" (__PCIBIOS_DS)
29307 : "memory");
29308 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
29309 if (ret & 0xff00)
29310@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
29311 {
29312 int ret;
29313
29314- __asm__("lcall *(%%esi); cld\n\t"
29315+ __asm__("movw %w5, %%ds\n\t"
29316+ "lcall *%%ss:(%%esi); cld\n\t"
29317+ "push %%ss\n\t"
29318+ "pop %%ds\n"
29319 "jc 1f\n\t"
29320 "xor %%ah, %%ah\n"
29321 "1:"
29322@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
29323 : "0" (PCIBIOS_SET_PCI_HW_INT),
29324 "b" ((dev->bus->number << 8) | dev->devfn),
29325 "c" ((irq << 8) | (pin + 10)),
29326- "S" (&pci_indirect));
29327+ "S" (&pci_indirect),
29328+ "r" (__PCIBIOS_DS));
29329 return !(ret & 0xff00);
29330 }
29331 EXPORT_SYMBOL(pcibios_set_irq_routing);
29332diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
29333index 40e4469..1ab536e 100644
29334--- a/arch/x86/platform/efi/efi_32.c
29335+++ b/arch/x86/platform/efi/efi_32.c
29336@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
29337 {
29338 struct desc_ptr gdt_descr;
29339
29340+#ifdef CONFIG_PAX_KERNEXEC
29341+ struct desc_struct d;
29342+#endif
29343+
29344 local_irq_save(efi_rt_eflags);
29345
29346 load_cr3(initial_page_table);
29347 __flush_tlb_all();
29348
29349+#ifdef CONFIG_PAX_KERNEXEC
29350+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
29351+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
29352+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
29353+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
29354+#endif
29355+
29356 gdt_descr.address = __pa(get_cpu_gdt_table(0));
29357 gdt_descr.size = GDT_SIZE - 1;
29358 load_gdt(&gdt_descr);
29359@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
29360 {
29361 struct desc_ptr gdt_descr;
29362
29363+#ifdef CONFIG_PAX_KERNEXEC
29364+ struct desc_struct d;
29365+
29366+ memset(&d, 0, sizeof d);
29367+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
29368+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
29369+#endif
29370+
29371 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
29372 gdt_descr.size = GDT_SIZE - 1;
29373 load_gdt(&gdt_descr);
29374diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
29375index fbe66e6..eae5e38 100644
29376--- a/arch/x86/platform/efi/efi_stub_32.S
29377+++ b/arch/x86/platform/efi/efi_stub_32.S
29378@@ -6,7 +6,9 @@
29379 */
29380
29381 #include <linux/linkage.h>
29382+#include <linux/init.h>
29383 #include <asm/page_types.h>
29384+#include <asm/segment.h>
29385
29386 /*
29387 * efi_call_phys(void *, ...) is a function with variable parameters.
29388@@ -20,7 +22,7 @@
29389 * service functions will comply with gcc calling convention, too.
29390 */
29391
29392-.text
29393+__INIT
29394 ENTRY(efi_call_phys)
29395 /*
29396 * 0. The function can only be called in Linux kernel. So CS has been
29397@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
29398 * The mapping of lower virtual memory has been created in prelog and
29399 * epilog.
29400 */
29401- movl $1f, %edx
29402- subl $__PAGE_OFFSET, %edx
29403- jmp *%edx
29404+#ifdef CONFIG_PAX_KERNEXEC
29405+ movl $(__KERNEXEC_EFI_DS), %edx
29406+ mov %edx, %ds
29407+ mov %edx, %es
29408+ mov %edx, %ss
29409+ addl $2f,(1f)
29410+ ljmp *(1f)
29411+
29412+__INITDATA
29413+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
29414+.previous
29415+
29416+2:
29417+ subl $2b,(1b)
29418+#else
29419+ jmp 1f-__PAGE_OFFSET
29420 1:
29421+#endif
29422
29423 /*
29424 * 2. Now on the top of stack is the return
29425@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
29426 * parameter 2, ..., param n. To make things easy, we save the return
29427 * address of efi_call_phys in a global variable.
29428 */
29429- popl %edx
29430- movl %edx, saved_return_addr
29431- /* get the function pointer into ECX*/
29432- popl %ecx
29433- movl %ecx, efi_rt_function_ptr
29434- movl $2f, %edx
29435- subl $__PAGE_OFFSET, %edx
29436- pushl %edx
29437+ popl (saved_return_addr)
29438+ popl (efi_rt_function_ptr)
29439
29440 /*
29441 * 3. Clear PG bit in %CR0.
29442@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
29443 /*
29444 * 5. Call the physical function.
29445 */
29446- jmp *%ecx
29447+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
29448
29449-2:
29450 /*
29451 * 6. After EFI runtime service returns, control will return to
29452 * following instruction. We'd better readjust stack pointer first.
29453@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
29454 movl %cr0, %edx
29455 orl $0x80000000, %edx
29456 movl %edx, %cr0
29457- jmp 1f
29458-1:
29459+
29460 /*
29461 * 8. Now restore the virtual mode from flat mode by
29462 * adding EIP with PAGE_OFFSET.
29463 */
29464- movl $1f, %edx
29465- jmp *%edx
29466+#ifdef CONFIG_PAX_KERNEXEC
29467+ movl $(__KERNEL_DS), %edx
29468+ mov %edx, %ds
29469+ mov %edx, %es
29470+ mov %edx, %ss
29471+ ljmp $(__KERNEL_CS),$1f
29472+#else
29473+ jmp 1f+__PAGE_OFFSET
29474+#endif
29475 1:
29476
29477 /*
29478 * 9. Balance the stack. And because EAX contain the return value,
29479 * we'd better not clobber it.
29480 */
29481- leal efi_rt_function_ptr, %edx
29482- movl (%edx), %ecx
29483- pushl %ecx
29484+ pushl (efi_rt_function_ptr)
29485
29486 /*
29487- * 10. Push the saved return address onto the stack and return.
29488+ * 10. Return to the saved return address.
29489 */
29490- leal saved_return_addr, %edx
29491- movl (%edx), %ecx
29492- pushl %ecx
29493- ret
29494+ jmpl *(saved_return_addr)
29495 ENDPROC(efi_call_phys)
29496 .previous
29497
29498-.data
29499+__INITDATA
29500 saved_return_addr:
29501 .long 0
29502 efi_rt_function_ptr:
29503diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
29504index 4c07cca..2c8427d 100644
29505--- a/arch/x86/platform/efi/efi_stub_64.S
29506+++ b/arch/x86/platform/efi/efi_stub_64.S
29507@@ -7,6 +7,7 @@
29508 */
29509
29510 #include <linux/linkage.h>
29511+#include <asm/alternative-asm.h>
29512
29513 #define SAVE_XMM \
29514 mov %rsp, %rax; \
29515@@ -40,6 +41,7 @@ ENTRY(efi_call0)
29516 call *%rdi
29517 addq $32, %rsp
29518 RESTORE_XMM
29519+ pax_force_retaddr 0, 1
29520 ret
29521 ENDPROC(efi_call0)
29522
29523@@ -50,6 +52,7 @@ ENTRY(efi_call1)
29524 call *%rdi
29525 addq $32, %rsp
29526 RESTORE_XMM
29527+ pax_force_retaddr 0, 1
29528 ret
29529 ENDPROC(efi_call1)
29530
29531@@ -60,6 +63,7 @@ ENTRY(efi_call2)
29532 call *%rdi
29533 addq $32, %rsp
29534 RESTORE_XMM
29535+ pax_force_retaddr 0, 1
29536 ret
29537 ENDPROC(efi_call2)
29538
29539@@ -71,6 +75,7 @@ ENTRY(efi_call3)
29540 call *%rdi
29541 addq $32, %rsp
29542 RESTORE_XMM
29543+ pax_force_retaddr 0, 1
29544 ret
29545 ENDPROC(efi_call3)
29546
29547@@ -83,6 +88,7 @@ ENTRY(efi_call4)
29548 call *%rdi
29549 addq $32, %rsp
29550 RESTORE_XMM
29551+ pax_force_retaddr 0, 1
29552 ret
29553 ENDPROC(efi_call4)
29554
29555@@ -96,6 +102,7 @@ ENTRY(efi_call5)
29556 call *%rdi
29557 addq $48, %rsp
29558 RESTORE_XMM
29559+ pax_force_retaddr 0, 1
29560 ret
29561 ENDPROC(efi_call5)
29562
29563@@ -112,5 +119,6 @@ ENTRY(efi_call6)
29564 call *%rdi
29565 addq $48, %rsp
29566 RESTORE_XMM
29567+ pax_force_retaddr 0, 1
29568 ret
29569 ENDPROC(efi_call6)
29570diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
29571index e31bcd8..f12dc46 100644
29572--- a/arch/x86/platform/mrst/mrst.c
29573+++ b/arch/x86/platform/mrst/mrst.c
29574@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
29575 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
29576 int sfi_mrtc_num;
29577
29578-static void mrst_power_off(void)
29579+static __noreturn void mrst_power_off(void)
29580 {
29581+ BUG();
29582 }
29583
29584-static void mrst_reboot(void)
29585+static __noreturn void mrst_reboot(void)
29586 {
29587 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
29588+ BUG();
29589 }
29590
29591 /* parse all the mtimer info to a static mtimer array */
29592diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
29593index d6ee929..3637cb5 100644
29594--- a/arch/x86/platform/olpc/olpc_dt.c
29595+++ b/arch/x86/platform/olpc/olpc_dt.c
29596@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
29597 return res;
29598 }
29599
29600-static struct of_pdt_ops prom_olpc_ops __initdata = {
29601+static struct of_pdt_ops prom_olpc_ops __initconst = {
29602 .nextprop = olpc_dt_nextprop,
29603 .getproplen = olpc_dt_getproplen,
29604 .getproperty = olpc_dt_getproperty,
29605diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
29606index 120cee1..b2db75a 100644
29607--- a/arch/x86/power/cpu.c
29608+++ b/arch/x86/power/cpu.c
29609@@ -133,7 +133,7 @@ static void do_fpu_end(void)
29610 static void fix_processor_context(void)
29611 {
29612 int cpu = smp_processor_id();
29613- struct tss_struct *t = &per_cpu(init_tss, cpu);
29614+ struct tss_struct *t = init_tss + cpu;
29615
29616 set_tss_desc(cpu, t); /*
29617 * This just modifies memory; should not be
29618@@ -143,8 +143,6 @@ static void fix_processor_context(void)
29619 */
29620
29621 #ifdef CONFIG_X86_64
29622- get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
29623-
29624 syscall_init(); /* This sets MSR_*STAR and related */
29625 #endif
29626 load_TR_desc(); /* This does ltr */
29627diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
29628index cbca565..bae7133 100644
29629--- a/arch/x86/realmode/init.c
29630+++ b/arch/x86/realmode/init.c
29631@@ -62,7 +62,13 @@ void __init setup_real_mode(void)
29632 __va(real_mode_header->trampoline_header);
29633
29634 #ifdef CONFIG_X86_32
29635- trampoline_header->start = __pa(startup_32_smp);
29636+ trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
29637+
29638+#ifdef CONFIG_PAX_KERNEXEC
29639+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
29640+#endif
29641+
29642+ trampoline_header->boot_cs = __BOOT_CS;
29643 trampoline_header->gdt_limit = __BOOT_DS + 7;
29644 trampoline_header->gdt_base = __pa(boot_gdt);
29645 #else
29646diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
29647index 8869287..d577672 100644
29648--- a/arch/x86/realmode/rm/Makefile
29649+++ b/arch/x86/realmode/rm/Makefile
29650@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
29651 $(call cc-option, -fno-unit-at-a-time)) \
29652 $(call cc-option, -fno-stack-protector) \
29653 $(call cc-option, -mpreferred-stack-boundary=2)
29654+ifdef CONSTIFY_PLUGIN
29655+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
29656+endif
29657 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
29658 GCOV_PROFILE := n
29659diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
29660index a28221d..93c40f1 100644
29661--- a/arch/x86/realmode/rm/header.S
29662+++ b/arch/x86/realmode/rm/header.S
29663@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
29664 #endif
29665 /* APM/BIOS reboot */
29666 .long pa_machine_real_restart_asm
29667-#ifdef CONFIG_X86_64
29668+#ifdef CONFIG_X86_32
29669+ .long __KERNEL_CS
29670+#else
29671 .long __KERNEL32_CS
29672 #endif
29673 END(real_mode_header)
29674diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
29675index c1b2791..f9e31c7 100644
29676--- a/arch/x86/realmode/rm/trampoline_32.S
29677+++ b/arch/x86/realmode/rm/trampoline_32.S
29678@@ -25,6 +25,12 @@
29679 #include <asm/page_types.h>
29680 #include "realmode.h"
29681
29682+#ifdef CONFIG_PAX_KERNEXEC
29683+#define ta(X) (X)
29684+#else
29685+#define ta(X) (pa_ ## X)
29686+#endif
29687+
29688 .text
29689 .code16
29690
29691@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
29692
29693 cli # We should be safe anyway
29694
29695- movl tr_start, %eax # where we need to go
29696-
29697 movl $0xA5A5A5A5, trampoline_status
29698 # write marker for master knows we're running
29699
29700@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
29701 movw $1, %dx # protected mode (PE) bit
29702 lmsw %dx # into protected mode
29703
29704- ljmpl $__BOOT_CS, $pa_startup_32
29705+ ljmpl *(trampoline_header)
29706
29707 .section ".text32","ax"
29708 .code32
29709@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
29710 .balign 8
29711 GLOBAL(trampoline_header)
29712 tr_start: .space 4
29713- tr_gdt_pad: .space 2
29714+ tr_boot_cs: .space 2
29715 tr_gdt: .space 6
29716 END(trampoline_header)
29717
29718diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
29719index bb360dc..3e5945f 100644
29720--- a/arch/x86/realmode/rm/trampoline_64.S
29721+++ b/arch/x86/realmode/rm/trampoline_64.S
29722@@ -107,7 +107,7 @@ ENTRY(startup_32)
29723 wrmsr
29724
29725 # Enable paging and in turn activate Long Mode
29726- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
29727+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
29728 movl %eax, %cr0
29729
29730 /*
29731diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
29732index 79d67bd..c7e1b90 100644
29733--- a/arch/x86/tools/relocs.c
29734+++ b/arch/x86/tools/relocs.c
29735@@ -12,10 +12,13 @@
29736 #include <regex.h>
29737 #include <tools/le_byteshift.h>
29738
29739+#include "../../../include/generated/autoconf.h"
29740+
29741 static void die(char *fmt, ...);
29742
29743 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
29744 static Elf32_Ehdr ehdr;
29745+static Elf32_Phdr *phdr;
29746 static unsigned long reloc_count, reloc_idx;
29747 static unsigned long *relocs;
29748 static unsigned long reloc16_count, reloc16_idx;
29749@@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
29750 }
29751 }
29752
29753+static void read_phdrs(FILE *fp)
29754+{
29755+ unsigned int i;
29756+
29757+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
29758+ if (!phdr) {
29759+ die("Unable to allocate %d program headers\n",
29760+ ehdr.e_phnum);
29761+ }
29762+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
29763+ die("Seek to %d failed: %s\n",
29764+ ehdr.e_phoff, strerror(errno));
29765+ }
29766+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
29767+ die("Cannot read ELF program headers: %s\n",
29768+ strerror(errno));
29769+ }
29770+ for(i = 0; i < ehdr.e_phnum; i++) {
29771+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
29772+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
29773+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
29774+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
29775+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
29776+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
29777+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
29778+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
29779+ }
29780+
29781+}
29782+
29783 static void read_shdrs(FILE *fp)
29784 {
29785- int i;
29786+ unsigned int i;
29787 Elf32_Shdr shdr;
29788
29789 secs = calloc(ehdr.e_shnum, sizeof(struct section));
29790@@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
29791
29792 static void read_strtabs(FILE *fp)
29793 {
29794- int i;
29795+ unsigned int i;
29796 for (i = 0; i < ehdr.e_shnum; i++) {
29797 struct section *sec = &secs[i];
29798 if (sec->shdr.sh_type != SHT_STRTAB) {
29799@@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
29800
29801 static void read_symtabs(FILE *fp)
29802 {
29803- int i,j;
29804+ unsigned int i,j;
29805 for (i = 0; i < ehdr.e_shnum; i++) {
29806 struct section *sec = &secs[i];
29807 if (sec->shdr.sh_type != SHT_SYMTAB) {
29808@@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
29809 }
29810
29811
29812-static void read_relocs(FILE *fp)
29813+static void read_relocs(FILE *fp, int use_real_mode)
29814 {
29815- int i,j;
29816+ unsigned int i,j;
29817+ uint32_t base;
29818+
29819 for (i = 0; i < ehdr.e_shnum; i++) {
29820 struct section *sec = &secs[i];
29821 if (sec->shdr.sh_type != SHT_REL) {
29822@@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
29823 die("Cannot read symbol table: %s\n",
29824 strerror(errno));
29825 }
29826+ base = 0;
29827+
29828+#ifdef CONFIG_X86_32
29829+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
29830+ if (phdr[j].p_type != PT_LOAD )
29831+ continue;
29832+ 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)
29833+ continue;
29834+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
29835+ break;
29836+ }
29837+#endif
29838+
29839 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
29840 Elf32_Rel *rel = &sec->reltab[j];
29841- rel->r_offset = elf32_to_cpu(rel->r_offset);
29842+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
29843 rel->r_info = elf32_to_cpu(rel->r_info);
29844 }
29845 }
29846@@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
29847
29848 static void print_absolute_symbols(void)
29849 {
29850- int i;
29851+ unsigned int i;
29852 printf("Absolute symbols\n");
29853 printf(" Num: Value Size Type Bind Visibility Name\n");
29854 for (i = 0; i < ehdr.e_shnum; i++) {
29855 struct section *sec = &secs[i];
29856 char *sym_strtab;
29857- int j;
29858+ unsigned int j;
29859
29860 if (sec->shdr.sh_type != SHT_SYMTAB) {
29861 continue;
29862@@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
29863
29864 static void print_absolute_relocs(void)
29865 {
29866- int i, printed = 0;
29867+ unsigned int i, printed = 0;
29868
29869 for (i = 0; i < ehdr.e_shnum; i++) {
29870 struct section *sec = &secs[i];
29871 struct section *sec_applies, *sec_symtab;
29872 char *sym_strtab;
29873 Elf32_Sym *sh_symtab;
29874- int j;
29875+ unsigned int j;
29876 if (sec->shdr.sh_type != SHT_REL) {
29877 continue;
29878 }
29879@@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
29880 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
29881 int use_real_mode)
29882 {
29883- int i;
29884+ unsigned int i;
29885 /* Walk through the relocations */
29886 for (i = 0; i < ehdr.e_shnum; i++) {
29887 char *sym_strtab;
29888 Elf32_Sym *sh_symtab;
29889 struct section *sec_applies, *sec_symtab;
29890- int j;
29891+ unsigned int j;
29892 struct section *sec = &secs[i];
29893
29894 if (sec->shdr.sh_type != SHT_REL) {
29895@@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
29896 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
29897 r_type = ELF32_R_TYPE(rel->r_info);
29898
29899+ if (!use_real_mode) {
29900+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
29901+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
29902+ continue;
29903+
29904+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
29905+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
29906+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
29907+ continue;
29908+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
29909+ continue;
29910+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
29911+ continue;
29912+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
29913+ continue;
29914+#endif
29915+ }
29916+
29917 shn_abs = sym->st_shndx == SHN_ABS;
29918
29919 switch (r_type) {
29920@@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
29921
29922 static void emit_relocs(int as_text, int use_real_mode)
29923 {
29924- int i;
29925+ unsigned int i;
29926 /* Count how many relocations I have and allocate space for them. */
29927 reloc_count = 0;
29928 walk_relocs(count_reloc, use_real_mode);
29929@@ -808,10 +874,11 @@ int main(int argc, char **argv)
29930 fname, strerror(errno));
29931 }
29932 read_ehdr(fp);
29933+ read_phdrs(fp);
29934 read_shdrs(fp);
29935 read_strtabs(fp);
29936 read_symtabs(fp);
29937- read_relocs(fp);
29938+ read_relocs(fp, use_real_mode);
29939 if (show_absolute_syms) {
29940 print_absolute_symbols();
29941 goto out;
29942diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
29943index fd14be1..e3c79c0 100644
29944--- a/arch/x86/vdso/Makefile
29945+++ b/arch/x86/vdso/Makefile
29946@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
29947 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
29948 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
29949
29950-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
29951+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
29952 GCOV_PROFILE := n
29953
29954 #
29955diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
29956index 0faad64..39ef157 100644
29957--- a/arch/x86/vdso/vdso32-setup.c
29958+++ b/arch/x86/vdso/vdso32-setup.c
29959@@ -25,6 +25,7 @@
29960 #include <asm/tlbflush.h>
29961 #include <asm/vdso.h>
29962 #include <asm/proto.h>
29963+#include <asm/mman.h>
29964
29965 enum {
29966 VDSO_DISABLED = 0,
29967@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
29968 void enable_sep_cpu(void)
29969 {
29970 int cpu = get_cpu();
29971- struct tss_struct *tss = &per_cpu(init_tss, cpu);
29972+ struct tss_struct *tss = init_tss + cpu;
29973
29974 if (!boot_cpu_has(X86_FEATURE_SEP)) {
29975 put_cpu();
29976@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
29977 gate_vma.vm_start = FIXADDR_USER_START;
29978 gate_vma.vm_end = FIXADDR_USER_END;
29979 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
29980- gate_vma.vm_page_prot = __P101;
29981+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
29982
29983 return 0;
29984 }
29985@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
29986 if (compat)
29987 addr = VDSO_HIGH_BASE;
29988 else {
29989- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
29990+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
29991 if (IS_ERR_VALUE(addr)) {
29992 ret = addr;
29993 goto up_fail;
29994 }
29995 }
29996
29997- current->mm->context.vdso = (void *)addr;
29998+ current->mm->context.vdso = addr;
29999
30000 if (compat_uses_vma || !compat) {
30001 /*
30002@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
30003 }
30004
30005 current_thread_info()->sysenter_return =
30006- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
30007+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
30008
30009 up_fail:
30010 if (ret)
30011- current->mm->context.vdso = NULL;
30012+ current->mm->context.vdso = 0;
30013
30014 up_write(&mm->mmap_sem);
30015
30016@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
30017
30018 const char *arch_vma_name(struct vm_area_struct *vma)
30019 {
30020- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
30021+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
30022 return "[vdso]";
30023+
30024+#ifdef CONFIG_PAX_SEGMEXEC
30025+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
30026+ return "[vdso]";
30027+#endif
30028+
30029 return NULL;
30030 }
30031
30032@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
30033 * Check to see if the corresponding task was created in compat vdso
30034 * mode.
30035 */
30036- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
30037+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
30038 return &gate_vma;
30039 return NULL;
30040 }
30041diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
30042index 431e875..cbb23f3 100644
30043--- a/arch/x86/vdso/vma.c
30044+++ b/arch/x86/vdso/vma.c
30045@@ -16,8 +16,6 @@
30046 #include <asm/vdso.h>
30047 #include <asm/page.h>
30048
30049-unsigned int __read_mostly vdso_enabled = 1;
30050-
30051 extern char vdso_start[], vdso_end[];
30052 extern unsigned short vdso_sync_cpuid;
30053
30054@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
30055 * unaligned here as a result of stack start randomization.
30056 */
30057 addr = PAGE_ALIGN(addr);
30058- addr = align_vdso_addr(addr);
30059
30060 return addr;
30061 }
30062@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
30063 unsigned size)
30064 {
30065 struct mm_struct *mm = current->mm;
30066- unsigned long addr;
30067+ unsigned long addr = 0;
30068 int ret;
30069
30070- if (!vdso_enabled)
30071- return 0;
30072-
30073 down_write(&mm->mmap_sem);
30074+
30075+#ifdef CONFIG_PAX_RANDMMAP
30076+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
30077+#endif
30078+
30079 addr = vdso_addr(mm->start_stack, size);
30080+ addr = align_vdso_addr(addr);
30081 addr = get_unmapped_area(NULL, addr, size, 0, 0);
30082 if (IS_ERR_VALUE(addr)) {
30083 ret = addr;
30084 goto up_fail;
30085 }
30086
30087- current->mm->context.vdso = (void *)addr;
30088+ mm->context.vdso = addr;
30089
30090 ret = install_special_mapping(mm, addr, size,
30091 VM_READ|VM_EXEC|
30092 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
30093 pages);
30094- if (ret) {
30095- current->mm->context.vdso = NULL;
30096- goto up_fail;
30097- }
30098+ if (ret)
30099+ mm->context.vdso = 0;
30100
30101 up_fail:
30102 up_write(&mm->mmap_sem);
30103@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
30104 vdsox32_size);
30105 }
30106 #endif
30107-
30108-static __init int vdso_setup(char *s)
30109-{
30110- vdso_enabled = simple_strtoul(s, NULL, 0);
30111- return 0;
30112-}
30113-__setup("vdso=", vdso_setup);
30114diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
30115index e014092..c76ab69 100644
30116--- a/arch/x86/xen/enlighten.c
30117+++ b/arch/x86/xen/enlighten.c
30118@@ -99,8 +99,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
30119
30120 struct shared_info xen_dummy_shared_info;
30121
30122-void *xen_initial_gdt;
30123-
30124 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
30125 __read_mostly int xen_have_vector_callback;
30126 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
30127@@ -495,8 +493,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
30128 {
30129 unsigned long va = dtr->address;
30130 unsigned int size = dtr->size + 1;
30131- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
30132- unsigned long frames[pages];
30133+ unsigned long frames[65536 / PAGE_SIZE];
30134 int f;
30135
30136 /*
30137@@ -544,8 +541,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
30138 {
30139 unsigned long va = dtr->address;
30140 unsigned int size = dtr->size + 1;
30141- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
30142- unsigned long frames[pages];
30143+ unsigned long frames[65536 / PAGE_SIZE];
30144 int f;
30145
30146 /*
30147@@ -938,7 +934,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
30148 return 0;
30149 }
30150
30151-static void set_xen_basic_apic_ops(void)
30152+static void __init set_xen_basic_apic_ops(void)
30153 {
30154 apic->read = xen_apic_read;
30155 apic->write = xen_apic_write;
30156@@ -1244,30 +1240,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
30157 #endif
30158 };
30159
30160-static void xen_reboot(int reason)
30161+static __noreturn void xen_reboot(int reason)
30162 {
30163 struct sched_shutdown r = { .reason = reason };
30164
30165- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
30166- BUG();
30167+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
30168+ BUG();
30169 }
30170
30171-static void xen_restart(char *msg)
30172+static __noreturn void xen_restart(char *msg)
30173 {
30174 xen_reboot(SHUTDOWN_reboot);
30175 }
30176
30177-static void xen_emergency_restart(void)
30178+static __noreturn void xen_emergency_restart(void)
30179 {
30180 xen_reboot(SHUTDOWN_reboot);
30181 }
30182
30183-static void xen_machine_halt(void)
30184+static __noreturn void xen_machine_halt(void)
30185 {
30186 xen_reboot(SHUTDOWN_poweroff);
30187 }
30188
30189-static void xen_machine_power_off(void)
30190+static __noreturn void xen_machine_power_off(void)
30191 {
30192 if (pm_power_off)
30193 pm_power_off();
30194@@ -1369,7 +1365,17 @@ asmlinkage void __init xen_start_kernel(void)
30195 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
30196
30197 /* Work out if we support NX */
30198- x86_configure_nx();
30199+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
30200+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
30201+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
30202+ unsigned l, h;
30203+
30204+ __supported_pte_mask |= _PAGE_NX;
30205+ rdmsr(MSR_EFER, l, h);
30206+ l |= EFER_NX;
30207+ wrmsr(MSR_EFER, l, h);
30208+ }
30209+#endif
30210
30211 xen_setup_features();
30212
30213@@ -1398,14 +1404,7 @@ asmlinkage void __init xen_start_kernel(void)
30214 pv_mmu_ops.ptep_modify_prot_commit = xen_ptep_modify_prot_commit;
30215 }
30216
30217- machine_ops = xen_machine_ops;
30218-
30219- /*
30220- * The only reliable way to retain the initial address of the
30221- * percpu gdt_page is to remember it here, so we can go and
30222- * mark it RW later, when the initial percpu area is freed.
30223- */
30224- xen_initial_gdt = &per_cpu(gdt_page, 0);
30225+ memcpy((void *)&machine_ops, &xen_machine_ops, sizeof machine_ops);
30226
30227 xen_smp_init();
30228
30229@@ -1590,7 +1589,7 @@ static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self,
30230 return NOTIFY_OK;
30231 }
30232
30233-static struct notifier_block xen_hvm_cpu_notifier __cpuinitdata = {
30234+static struct notifier_block xen_hvm_cpu_notifier = {
30235 .notifier_call = xen_hvm_cpu_notify,
30236 };
30237
30238diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
30239index 01de35c..0bda07b 100644
30240--- a/arch/x86/xen/mmu.c
30241+++ b/arch/x86/xen/mmu.c
30242@@ -1881,6 +1881,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
30243 /* L3_k[510] -> level2_kernel_pgt
30244 * L3_i[511] -> level2_fixmap_pgt */
30245 convert_pfn_mfn(level3_kernel_pgt);
30246+ convert_pfn_mfn(level3_vmalloc_start_pgt);
30247+ convert_pfn_mfn(level3_vmalloc_end_pgt);
30248+ convert_pfn_mfn(level3_vmemmap_pgt);
30249
30250 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
30251 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
30252@@ -1910,8 +1913,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
30253 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
30254 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
30255 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
30256+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
30257+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
30258+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
30259 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
30260 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
30261+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
30262 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
30263 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
30264
30265@@ -2097,6 +2104,7 @@ static void __init xen_post_allocator_init(void)
30266 pv_mmu_ops.set_pud = xen_set_pud;
30267 #if PAGETABLE_LEVELS == 4
30268 pv_mmu_ops.set_pgd = xen_set_pgd;
30269+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
30270 #endif
30271
30272 /* This will work as long as patching hasn't happened yet
30273@@ -2178,6 +2186,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
30274 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
30275 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
30276 .set_pgd = xen_set_pgd_hyper,
30277+ .set_pgd_batched = xen_set_pgd_hyper,
30278
30279 .alloc_pud = xen_alloc_pmd_init,
30280 .release_pud = xen_release_pmd_init,
30281diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
30282index 34bc4ce..c34aa24 100644
30283--- a/arch/x86/xen/smp.c
30284+++ b/arch/x86/xen/smp.c
30285@@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
30286 {
30287 BUG_ON(smp_processor_id() != 0);
30288 native_smp_prepare_boot_cpu();
30289-
30290- /* We've switched to the "real" per-cpu gdt, so make sure the
30291- old memory can be recycled */
30292- make_lowmem_page_readwrite(xen_initial_gdt);
30293-
30294 xen_filter_cpu_maps();
30295 xen_setup_vcpu_info_placement();
30296 }
30297@@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
30298 gdt = get_cpu_gdt_table(cpu);
30299
30300 ctxt->flags = VGCF_IN_KERNEL;
30301- ctxt->user_regs.ds = __USER_DS;
30302- ctxt->user_regs.es = __USER_DS;
30303+ ctxt->user_regs.ds = __KERNEL_DS;
30304+ ctxt->user_regs.es = __KERNEL_DS;
30305 ctxt->user_regs.ss = __KERNEL_DS;
30306 #ifdef CONFIG_X86_32
30307 ctxt->user_regs.fs = __KERNEL_PERCPU;
30308- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
30309+ savesegment(gs, ctxt->user_regs.gs);
30310 #else
30311 ctxt->gs_base_kernel = per_cpu_offset(cpu);
30312 #endif
30313@@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
30314 int rc;
30315
30316 per_cpu(current_task, cpu) = idle;
30317+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
30318 #ifdef CONFIG_X86_32
30319 irq_ctx_init(cpu);
30320 #else
30321 clear_tsk_thread_flag(idle, TIF_FORK);
30322- per_cpu(kernel_stack, cpu) =
30323- (unsigned long)task_stack_page(idle) -
30324- KERNEL_STACK_OFFSET + THREAD_SIZE;
30325+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
30326 #endif
30327 xen_setup_runstate_info(cpu);
30328 xen_setup_timer(cpu);
30329@@ -630,7 +624,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
30330
30331 void __init xen_smp_init(void)
30332 {
30333- smp_ops = xen_smp_ops;
30334+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
30335 xen_fill_possible_map();
30336 xen_init_spinlocks();
30337 }
30338diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
30339index 33ca6e4..0ded929 100644
30340--- a/arch/x86/xen/xen-asm_32.S
30341+++ b/arch/x86/xen/xen-asm_32.S
30342@@ -84,14 +84,14 @@ ENTRY(xen_iret)
30343 ESP_OFFSET=4 # bytes pushed onto stack
30344
30345 /*
30346- * Store vcpu_info pointer for easy access. Do it this way to
30347- * avoid having to reload %fs
30348+ * Store vcpu_info pointer for easy access.
30349 */
30350 #ifdef CONFIG_SMP
30351- GET_THREAD_INFO(%eax)
30352- movl %ss:TI_cpu(%eax), %eax
30353- movl %ss:__per_cpu_offset(,%eax,4), %eax
30354- mov %ss:xen_vcpu(%eax), %eax
30355+ push %fs
30356+ mov $(__KERNEL_PERCPU), %eax
30357+ mov %eax, %fs
30358+ mov PER_CPU_VAR(xen_vcpu), %eax
30359+ pop %fs
30360 #else
30361 movl %ss:xen_vcpu, %eax
30362 #endif
30363diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
30364index 7faed58..ba4427c 100644
30365--- a/arch/x86/xen/xen-head.S
30366+++ b/arch/x86/xen/xen-head.S
30367@@ -19,6 +19,17 @@ ENTRY(startup_xen)
30368 #ifdef CONFIG_X86_32
30369 mov %esi,xen_start_info
30370 mov $init_thread_union+THREAD_SIZE,%esp
30371+#ifdef CONFIG_SMP
30372+ movl $cpu_gdt_table,%edi
30373+ movl $__per_cpu_load,%eax
30374+ movw %ax,__KERNEL_PERCPU + 2(%edi)
30375+ rorl $16,%eax
30376+ movb %al,__KERNEL_PERCPU + 4(%edi)
30377+ movb %ah,__KERNEL_PERCPU + 7(%edi)
30378+ movl $__per_cpu_end - 1,%eax
30379+ subl $__per_cpu_start,%eax
30380+ movw %ax,__KERNEL_PERCPU + 0(%edi)
30381+#endif
30382 #else
30383 mov %rsi,xen_start_info
30384 mov $init_thread_union+THREAD_SIZE,%rsp
30385diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
30386index a95b417..b6dbd0b 100644
30387--- a/arch/x86/xen/xen-ops.h
30388+++ b/arch/x86/xen/xen-ops.h
30389@@ -10,8 +10,6 @@
30390 extern const char xen_hypervisor_callback[];
30391 extern const char xen_failsafe_callback[];
30392
30393-extern void *xen_initial_gdt;
30394-
30395 struct trap_info;
30396 void xen_copy_trap_info(struct trap_info *traps);
30397
30398diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
30399index 525bd3d..ef888b1 100644
30400--- a/arch/xtensa/variants/dc232b/include/variant/core.h
30401+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
30402@@ -119,9 +119,9 @@
30403 ----------------------------------------------------------------------*/
30404
30405 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
30406-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
30407 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
30408 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
30409+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
30410
30411 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
30412 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
30413diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
30414index 2f33760..835e50a 100644
30415--- a/arch/xtensa/variants/fsf/include/variant/core.h
30416+++ b/arch/xtensa/variants/fsf/include/variant/core.h
30417@@ -11,6 +11,7 @@
30418 #ifndef _XTENSA_CORE_H
30419 #define _XTENSA_CORE_H
30420
30421+#include <linux/const.h>
30422
30423 /****************************************************************************
30424 Parameters Useful for Any Code, USER or PRIVILEGED
30425@@ -112,9 +113,9 @@
30426 ----------------------------------------------------------------------*/
30427
30428 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
30429-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
30430 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
30431 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
30432+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
30433
30434 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
30435 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
30436diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
30437index af00795..2bb8105 100644
30438--- a/arch/xtensa/variants/s6000/include/variant/core.h
30439+++ b/arch/xtensa/variants/s6000/include/variant/core.h
30440@@ -11,6 +11,7 @@
30441 #ifndef _XTENSA_CORE_CONFIGURATION_H
30442 #define _XTENSA_CORE_CONFIGURATION_H
30443
30444+#include <linux/const.h>
30445
30446 /****************************************************************************
30447 Parameters Useful for Any Code, USER or PRIVILEGED
30448@@ -118,9 +119,9 @@
30449 ----------------------------------------------------------------------*/
30450
30451 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
30452-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
30453 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
30454 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
30455+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
30456
30457 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
30458 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
30459diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
30460index 58916af..eb9dbcf6 100644
30461--- a/block/blk-iopoll.c
30462+++ b/block/blk-iopoll.c
30463@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
30464 }
30465 EXPORT_SYMBOL(blk_iopoll_complete);
30466
30467-static void blk_iopoll_softirq(struct softirq_action *h)
30468+static void blk_iopoll_softirq(void)
30469 {
30470 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
30471 int rearm = 0, budget = blk_iopoll_budget;
30472@@ -209,7 +209,7 @@ static int __cpuinit blk_iopoll_cpu_notify(struct notifier_block *self,
30473 return NOTIFY_OK;
30474 }
30475
30476-static struct notifier_block __cpuinitdata blk_iopoll_cpu_notifier = {
30477+static struct notifier_block blk_iopoll_cpu_notifier = {
30478 .notifier_call = blk_iopoll_cpu_notify,
30479 };
30480
30481diff --git a/block/blk-map.c b/block/blk-map.c
30482index 623e1cd..ca1e109 100644
30483--- a/block/blk-map.c
30484+++ b/block/blk-map.c
30485@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
30486 if (!len || !kbuf)
30487 return -EINVAL;
30488
30489- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
30490+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
30491 if (do_copy)
30492 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
30493 else
30494diff --git a/block/blk-softirq.c b/block/blk-softirq.c
30495index 467c8de..f3628c5 100644
30496--- a/block/blk-softirq.c
30497+++ b/block/blk-softirq.c
30498@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
30499 * Softirq action handler - move entries to local list and loop over them
30500 * while passing them to the queue registered handler.
30501 */
30502-static void blk_done_softirq(struct softirq_action *h)
30503+static void blk_done_softirq(void)
30504 {
30505 struct list_head *cpu_list, local_list;
30506
30507@@ -98,7 +98,7 @@ static int __cpuinit blk_cpu_notify(struct notifier_block *self,
30508 return NOTIFY_OK;
30509 }
30510
30511-static struct notifier_block __cpuinitdata blk_cpu_notifier = {
30512+static struct notifier_block blk_cpu_notifier = {
30513 .notifier_call = blk_cpu_notify,
30514 };
30515
30516diff --git a/block/bsg.c b/block/bsg.c
30517index ff64ae3..593560c 100644
30518--- a/block/bsg.c
30519+++ b/block/bsg.c
30520@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
30521 struct sg_io_v4 *hdr, struct bsg_device *bd,
30522 fmode_t has_write_perm)
30523 {
30524+ unsigned char tmpcmd[sizeof(rq->__cmd)];
30525+ unsigned char *cmdptr;
30526+
30527 if (hdr->request_len > BLK_MAX_CDB) {
30528 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
30529 if (!rq->cmd)
30530 return -ENOMEM;
30531- }
30532+ cmdptr = rq->cmd;
30533+ } else
30534+ cmdptr = tmpcmd;
30535
30536- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
30537+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
30538 hdr->request_len))
30539 return -EFAULT;
30540
30541+ if (cmdptr != rq->cmd)
30542+ memcpy(rq->cmd, cmdptr, hdr->request_len);
30543+
30544 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
30545 if (blk_verify_command(rq->cmd, has_write_perm))
30546 return -EPERM;
30547diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
30548index 7c668c8..db3521c 100644
30549--- a/block/compat_ioctl.c
30550+++ b/block/compat_ioctl.c
30551@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
30552 err |= __get_user(f->spec1, &uf->spec1);
30553 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
30554 err |= __get_user(name, &uf->name);
30555- f->name = compat_ptr(name);
30556+ f->name = (void __force_kernel *)compat_ptr(name);
30557 if (err) {
30558 err = -EFAULT;
30559 goto out;
30560diff --git a/block/partitions/efi.c b/block/partitions/efi.c
30561index b62fb88..bdab4c4 100644
30562--- a/block/partitions/efi.c
30563+++ b/block/partitions/efi.c
30564@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
30565 if (!gpt)
30566 return NULL;
30567
30568+ if (!le32_to_cpu(gpt->num_partition_entries))
30569+ return NULL;
30570+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
30571+ if (!pte)
30572+ return NULL;
30573+
30574 count = le32_to_cpu(gpt->num_partition_entries) *
30575 le32_to_cpu(gpt->sizeof_partition_entry);
30576- if (!count)
30577- return NULL;
30578- pte = kzalloc(count, GFP_KERNEL);
30579- if (!pte)
30580- return NULL;
30581-
30582 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
30583 (u8 *) pte,
30584 count) < count) {
30585diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
30586index 9a87daa..fb17486 100644
30587--- a/block/scsi_ioctl.c
30588+++ b/block/scsi_ioctl.c
30589@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
30590 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
30591 struct sg_io_hdr *hdr, fmode_t mode)
30592 {
30593- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
30594+ unsigned char tmpcmd[sizeof(rq->__cmd)];
30595+ unsigned char *cmdptr;
30596+
30597+ if (rq->cmd != rq->__cmd)
30598+ cmdptr = rq->cmd;
30599+ else
30600+ cmdptr = tmpcmd;
30601+
30602+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
30603 return -EFAULT;
30604+
30605+ if (cmdptr != rq->cmd)
30606+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
30607+
30608 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
30609 return -EPERM;
30610
30611@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
30612 int err;
30613 unsigned int in_len, out_len, bytes, opcode, cmdlen;
30614 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
30615+ unsigned char tmpcmd[sizeof(rq->__cmd)];
30616+ unsigned char *cmdptr;
30617
30618 if (!sic)
30619 return -EINVAL;
30620@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
30621 */
30622 err = -EFAULT;
30623 rq->cmd_len = cmdlen;
30624- if (copy_from_user(rq->cmd, sic->data, cmdlen))
30625+
30626+ if (rq->cmd != rq->__cmd)
30627+ cmdptr = rq->cmd;
30628+ else
30629+ cmdptr = tmpcmd;
30630+
30631+ if (copy_from_user(cmdptr, sic->data, cmdlen))
30632 goto error;
30633
30634+ if (rq->cmd != cmdptr)
30635+ memcpy(rq->cmd, cmdptr, cmdlen);
30636+
30637 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
30638 goto error;
30639
30640diff --git a/crypto/ablkcipher.c b/crypto/ablkcipher.c
30641index 533de95..7d4a8d2 100644
30642--- a/crypto/ablkcipher.c
30643+++ b/crypto/ablkcipher.c
30644@@ -388,9 +388,9 @@ static int crypto_ablkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
30645 {
30646 struct crypto_report_blkcipher rblkcipher;
30647
30648- snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "ablkcipher");
30649- snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s",
30650- alg->cra_ablkcipher.geniv ?: "<default>");
30651+ strncpy(rblkcipher.type, "ablkcipher", sizeof(rblkcipher.type));
30652+ strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "<default>",
30653+ sizeof(rblkcipher.geniv));
30654
30655 rblkcipher.blocksize = alg->cra_blocksize;
30656 rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize;
30657@@ -469,9 +469,9 @@ static int crypto_givcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
30658 {
30659 struct crypto_report_blkcipher rblkcipher;
30660
30661- snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "givcipher");
30662- snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s",
30663- alg->cra_ablkcipher.geniv ?: "<built-in>");
30664+ strncpy(rblkcipher.type, "givcipher", sizeof(rblkcipher.type));
30665+ strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "<built-in>",
30666+ sizeof(rblkcipher.geniv));
30667
30668 rblkcipher.blocksize = alg->cra_blocksize;
30669 rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize;
30670diff --git a/crypto/aead.c b/crypto/aead.c
30671index 0b8121e..27bc487 100644
30672--- a/crypto/aead.c
30673+++ b/crypto/aead.c
30674@@ -117,9 +117,8 @@ static int crypto_aead_report(struct sk_buff *skb, struct crypto_alg *alg)
30675 struct crypto_report_aead raead;
30676 struct aead_alg *aead = &alg->cra_aead;
30677
30678- snprintf(raead.type, CRYPTO_MAX_ALG_NAME, "%s", "aead");
30679- snprintf(raead.geniv, CRYPTO_MAX_ALG_NAME, "%s",
30680- aead->geniv ?: "<built-in>");
30681+ strncpy(raead.type, "aead", sizeof(raead.type));
30682+ strncpy(raead.geniv, aead->geniv ?: "<built-in>", sizeof(raead.geniv));
30683
30684 raead.blocksize = alg->cra_blocksize;
30685 raead.maxauthsize = aead->maxauthsize;
30686@@ -203,8 +202,8 @@ static int crypto_nivaead_report(struct sk_buff *skb, struct crypto_alg *alg)
30687 struct crypto_report_aead raead;
30688 struct aead_alg *aead = &alg->cra_aead;
30689
30690- snprintf(raead.type, CRYPTO_MAX_ALG_NAME, "%s", "nivaead");
30691- snprintf(raead.geniv, CRYPTO_MAX_ALG_NAME, "%s", aead->geniv);
30692+ strncpy(raead.type, "nivaead", sizeof(raead.type));
30693+ strncpy(raead.geniv, aead->geniv, sizeof(raead.geniv));
30694
30695 raead.blocksize = alg->cra_blocksize;
30696 raead.maxauthsize = aead->maxauthsize;
30697diff --git a/crypto/ahash.c b/crypto/ahash.c
30698index 3887856..793a27f 100644
30699--- a/crypto/ahash.c
30700+++ b/crypto/ahash.c
30701@@ -404,7 +404,7 @@ static int crypto_ahash_report(struct sk_buff *skb, struct crypto_alg *alg)
30702 {
30703 struct crypto_report_hash rhash;
30704
30705- snprintf(rhash.type, CRYPTO_MAX_ALG_NAME, "%s", "ahash");
30706+ strncpy(rhash.type, "ahash", sizeof(rhash.type));
30707
30708 rhash.blocksize = alg->cra_blocksize;
30709 rhash.digestsize = __crypto_hash_alg_common(alg)->digestsize;
30710diff --git a/crypto/blkcipher.c b/crypto/blkcipher.c
30711index a8d85a1..c44e014 100644
30712--- a/crypto/blkcipher.c
30713+++ b/crypto/blkcipher.c
30714@@ -499,9 +499,9 @@ static int crypto_blkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
30715 {
30716 struct crypto_report_blkcipher rblkcipher;
30717
30718- snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "blkcipher");
30719- snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s",
30720- alg->cra_blkcipher.geniv ?: "<default>");
30721+ strncpy(rblkcipher.type, "blkcipher", sizeof(rblkcipher.type));
30722+ strncpy(rblkcipher.geniv, alg->cra_blkcipher.geniv ?: "<default>",
30723+ sizeof(rblkcipher.geniv));
30724
30725 rblkcipher.blocksize = alg->cra_blocksize;
30726 rblkcipher.min_keysize = alg->cra_blkcipher.min_keysize;
30727diff --git a/crypto/cryptd.c b/crypto/cryptd.c
30728index 7bdd61b..afec999 100644
30729--- a/crypto/cryptd.c
30730+++ b/crypto/cryptd.c
30731@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
30732
30733 struct cryptd_blkcipher_request_ctx {
30734 crypto_completion_t complete;
30735-};
30736+} __no_const;
30737
30738 struct cryptd_hash_ctx {
30739 struct crypto_shash *child;
30740@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
30741
30742 struct cryptd_aead_request_ctx {
30743 crypto_completion_t complete;
30744-};
30745+} __no_const;
30746
30747 static void cryptd_queue_worker(struct work_struct *work);
30748
30749diff --git a/crypto/crypto_user.c b/crypto/crypto_user.c
30750index 35d700a..dfd511f 100644
30751--- a/crypto/crypto_user.c
30752+++ b/crypto/crypto_user.c
30753@@ -30,6 +30,8 @@
30754
30755 #include "internal.h"
30756
30757+#define null_terminated(x) (strnlen(x, sizeof(x)) < sizeof(x))
30758+
30759 static DEFINE_MUTEX(crypto_cfg_mutex);
30760
30761 /* The crypto netlink socket */
30762@@ -75,7 +77,7 @@ static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg)
30763 {
30764 struct crypto_report_cipher rcipher;
30765
30766- snprintf(rcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "cipher");
30767+ strncpy(rcipher.type, "cipher", sizeof(rcipher.type));
30768
30769 rcipher.blocksize = alg->cra_blocksize;
30770 rcipher.min_keysize = alg->cra_cipher.cia_min_keysize;
30771@@ -94,8 +96,7 @@ static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg)
30772 {
30773 struct crypto_report_comp rcomp;
30774
30775- snprintf(rcomp.type, CRYPTO_MAX_ALG_NAME, "%s", "compression");
30776-
30777+ strncpy(rcomp.type, "compression", sizeof(rcomp.type));
30778 if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
30779 sizeof(struct crypto_report_comp), &rcomp))
30780 goto nla_put_failure;
30781@@ -108,12 +109,14 @@ nla_put_failure:
30782 static int crypto_report_one(struct crypto_alg *alg,
30783 struct crypto_user_alg *ualg, struct sk_buff *skb)
30784 {
30785- memcpy(&ualg->cru_name, &alg->cra_name, sizeof(ualg->cru_name));
30786- memcpy(&ualg->cru_driver_name, &alg->cra_driver_name,
30787- sizeof(ualg->cru_driver_name));
30788- memcpy(&ualg->cru_module_name, module_name(alg->cra_module),
30789- CRYPTO_MAX_ALG_NAME);
30790+ strncpy(ualg->cru_name, alg->cra_name, sizeof(ualg->cru_name));
30791+ strncpy(ualg->cru_driver_name, alg->cra_driver_name,
30792+ sizeof(ualg->cru_driver_name));
30793+ strncpy(ualg->cru_module_name, module_name(alg->cra_module),
30794+ sizeof(ualg->cru_module_name));
30795
30796+ ualg->cru_type = 0;
30797+ ualg->cru_mask = 0;
30798 ualg->cru_flags = alg->cra_flags;
30799 ualg->cru_refcnt = atomic_read(&alg->cra_refcnt);
30800
30801@@ -122,8 +125,7 @@ static int crypto_report_one(struct crypto_alg *alg,
30802 if (alg->cra_flags & CRYPTO_ALG_LARVAL) {
30803 struct crypto_report_larval rl;
30804
30805- snprintf(rl.type, CRYPTO_MAX_ALG_NAME, "%s", "larval");
30806-
30807+ strncpy(rl.type, "larval", sizeof(rl.type));
30808 if (nla_put(skb, CRYPTOCFGA_REPORT_LARVAL,
30809 sizeof(struct crypto_report_larval), &rl))
30810 goto nla_put_failure;
30811@@ -196,7 +198,10 @@ static int crypto_report(struct sk_buff *in_skb, struct nlmsghdr *in_nlh,
30812 struct crypto_dump_info info;
30813 int err;
30814
30815- if (!p->cru_driver_name)
30816+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
30817+ return -EINVAL;
30818+
30819+ if (!p->cru_driver_name[0])
30820 return -EINVAL;
30821
30822 alg = crypto_alg_match(p, 1);
30823@@ -260,6 +265,9 @@ static int crypto_update_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
30824 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
30825 LIST_HEAD(list);
30826
30827+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
30828+ return -EINVAL;
30829+
30830 if (priority && !strlen(p->cru_driver_name))
30831 return -EINVAL;
30832
30833@@ -287,6 +295,9 @@ static int crypto_del_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
30834 struct crypto_alg *alg;
30835 struct crypto_user_alg *p = nlmsg_data(nlh);
30836
30837+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
30838+ return -EINVAL;
30839+
30840 alg = crypto_alg_match(p, 1);
30841 if (!alg)
30842 return -ENOENT;
30843@@ -368,6 +379,9 @@ static int crypto_add_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
30844 struct crypto_user_alg *p = nlmsg_data(nlh);
30845 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
30846
30847+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
30848+ return -EINVAL;
30849+
30850 if (strlen(p->cru_driver_name))
30851 exact = 1;
30852
30853diff --git a/crypto/pcompress.c b/crypto/pcompress.c
30854index 04e083f..7140fe7 100644
30855--- a/crypto/pcompress.c
30856+++ b/crypto/pcompress.c
30857@@ -53,8 +53,7 @@ static int crypto_pcomp_report(struct sk_buff *skb, struct crypto_alg *alg)
30858 {
30859 struct crypto_report_comp rpcomp;
30860
30861- snprintf(rpcomp.type, CRYPTO_MAX_ALG_NAME, "%s", "pcomp");
30862-
30863+ strncpy(rpcomp.type, "pcomp", sizeof(rpcomp.type));
30864 if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
30865 sizeof(struct crypto_report_comp), &rpcomp))
30866 goto nla_put_failure;
30867diff --git a/crypto/rng.c b/crypto/rng.c
30868index f3b7894..e0a25c2 100644
30869--- a/crypto/rng.c
30870+++ b/crypto/rng.c
30871@@ -65,7 +65,7 @@ static int crypto_rng_report(struct sk_buff *skb, struct crypto_alg *alg)
30872 {
30873 struct crypto_report_rng rrng;
30874
30875- snprintf(rrng.type, CRYPTO_MAX_ALG_NAME, "%s", "rng");
30876+ strncpy(rrng.type, "rng", sizeof(rrng.type));
30877
30878 rrng.seedsize = alg->cra_rng.seedsize;
30879
30880diff --git a/crypto/shash.c b/crypto/shash.c
30881index f426330f..929058a 100644
30882--- a/crypto/shash.c
30883+++ b/crypto/shash.c
30884@@ -530,7 +530,8 @@ static int crypto_shash_report(struct sk_buff *skb, struct crypto_alg *alg)
30885 struct crypto_report_hash rhash;
30886 struct shash_alg *salg = __crypto_shash_alg(alg);
30887
30888- snprintf(rhash.type, CRYPTO_MAX_ALG_NAME, "%s", "shash");
30889+ strncpy(rhash.type, "shash", sizeof(rhash.type));
30890+
30891 rhash.blocksize = alg->cra_blocksize;
30892 rhash.digestsize = salg->digestsize;
30893
30894diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
30895index e6defd8..c26a225 100644
30896--- a/drivers/acpi/apei/cper.c
30897+++ b/drivers/acpi/apei/cper.c
30898@@ -38,12 +38,12 @@
30899 */
30900 u64 cper_next_record_id(void)
30901 {
30902- static atomic64_t seq;
30903+ static atomic64_unchecked_t seq;
30904
30905- if (!atomic64_read(&seq))
30906- atomic64_set(&seq, ((u64)get_seconds()) << 32);
30907+ if (!atomic64_read_unchecked(&seq))
30908+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
30909
30910- return atomic64_inc_return(&seq);
30911+ return atomic64_inc_return_unchecked(&seq);
30912 }
30913 EXPORT_SYMBOL_GPL(cper_next_record_id);
30914
30915diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
30916index 7586544..636a2f0 100644
30917--- a/drivers/acpi/ec_sys.c
30918+++ b/drivers/acpi/ec_sys.c
30919@@ -12,6 +12,7 @@
30920 #include <linux/acpi.h>
30921 #include <linux/debugfs.h>
30922 #include <linux/module.h>
30923+#include <linux/uaccess.h>
30924 #include "internal.h"
30925
30926 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
30927@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
30928 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
30929 */
30930 unsigned int size = EC_SPACE_SIZE;
30931- u8 *data = (u8 *) buf;
30932+ u8 data;
30933 loff_t init_off = *off;
30934 int err = 0;
30935
30936@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
30937 size = count;
30938
30939 while (size) {
30940- err = ec_read(*off, &data[*off - init_off]);
30941+ err = ec_read(*off, &data);
30942 if (err)
30943 return err;
30944+ if (put_user(data, &buf[*off - init_off]))
30945+ return -EFAULT;
30946 *off += 1;
30947 size--;
30948 }
30949@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
30950
30951 unsigned int size = count;
30952 loff_t init_off = *off;
30953- u8 *data = (u8 *) buf;
30954 int err = 0;
30955
30956 if (*off >= EC_SPACE_SIZE)
30957@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
30958 }
30959
30960 while (size) {
30961- u8 byte_write = data[*off - init_off];
30962+ u8 byte_write;
30963+ if (get_user(byte_write, &buf[*off - init_off]))
30964+ return -EFAULT;
30965 err = ec_write(*off, byte_write);
30966 if (err)
30967 return err;
30968diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
30969index e83311b..142b5cc 100644
30970--- a/drivers/acpi/processor_driver.c
30971+++ b/drivers/acpi/processor_driver.c
30972@@ -558,7 +558,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
30973 return 0;
30974 #endif
30975
30976- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
30977+ BUG_ON(pr->id >= nr_cpu_ids);
30978
30979 /*
30980 * Buggy BIOS check
30981diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
30982index 46cd3f4..0871ad0 100644
30983--- a/drivers/ata/libata-core.c
30984+++ b/drivers/ata/libata-core.c
30985@@ -4780,7 +4780,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
30986 struct ata_port *ap;
30987 unsigned int tag;
30988
30989- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30990+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30991 ap = qc->ap;
30992
30993 qc->flags = 0;
30994@@ -4796,7 +4796,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
30995 struct ata_port *ap;
30996 struct ata_link *link;
30997
30998- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30999+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31000 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
31001 ap = qc->ap;
31002 link = qc->dev->link;
31003@@ -5892,6 +5892,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
31004 return;
31005
31006 spin_lock(&lock);
31007+ pax_open_kernel();
31008
31009 for (cur = ops->inherits; cur; cur = cur->inherits) {
31010 void **inherit = (void **)cur;
31011@@ -5905,8 +5906,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
31012 if (IS_ERR(*pp))
31013 *pp = NULL;
31014
31015- ops->inherits = NULL;
31016+ *(struct ata_port_operations **)&ops->inherits = NULL;
31017
31018+ pax_close_kernel();
31019 spin_unlock(&lock);
31020 }
31021
31022diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
31023index 405022d..fb70e53 100644
31024--- a/drivers/ata/pata_arasan_cf.c
31025+++ b/drivers/ata/pata_arasan_cf.c
31026@@ -864,7 +864,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
31027 /* Handle platform specific quirks */
31028 if (pdata->quirk) {
31029 if (pdata->quirk & CF_BROKEN_PIO) {
31030- ap->ops->set_piomode = NULL;
31031+ pax_open_kernel();
31032+ *(void **)&ap->ops->set_piomode = NULL;
31033+ pax_close_kernel();
31034 ap->pio_mask = 0;
31035 }
31036 if (pdata->quirk & CF_BROKEN_MWDMA)
31037diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
31038index f9b983a..887b9d8 100644
31039--- a/drivers/atm/adummy.c
31040+++ b/drivers/atm/adummy.c
31041@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
31042 vcc->pop(vcc, skb);
31043 else
31044 dev_kfree_skb_any(skb);
31045- atomic_inc(&vcc->stats->tx);
31046+ atomic_inc_unchecked(&vcc->stats->tx);
31047
31048 return 0;
31049 }
31050diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
31051index 77a7480..05cde58 100644
31052--- a/drivers/atm/ambassador.c
31053+++ b/drivers/atm/ambassador.c
31054@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
31055 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
31056
31057 // VC layer stats
31058- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31059+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31060
31061 // free the descriptor
31062 kfree (tx_descr);
31063@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
31064 dump_skb ("<<<", vc, skb);
31065
31066 // VC layer stats
31067- atomic_inc(&atm_vcc->stats->rx);
31068+ atomic_inc_unchecked(&atm_vcc->stats->rx);
31069 __net_timestamp(skb);
31070 // end of our responsibility
31071 atm_vcc->push (atm_vcc, skb);
31072@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
31073 } else {
31074 PRINTK (KERN_INFO, "dropped over-size frame");
31075 // should we count this?
31076- atomic_inc(&atm_vcc->stats->rx_drop);
31077+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31078 }
31079
31080 } else {
31081@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
31082 }
31083
31084 if (check_area (skb->data, skb->len)) {
31085- atomic_inc(&atm_vcc->stats->tx_err);
31086+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
31087 return -ENOMEM; // ?
31088 }
31089
31090diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
31091index b22d71c..d6e1049 100644
31092--- a/drivers/atm/atmtcp.c
31093+++ b/drivers/atm/atmtcp.c
31094@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31095 if (vcc->pop) vcc->pop(vcc,skb);
31096 else dev_kfree_skb(skb);
31097 if (dev_data) return 0;
31098- atomic_inc(&vcc->stats->tx_err);
31099+ atomic_inc_unchecked(&vcc->stats->tx_err);
31100 return -ENOLINK;
31101 }
31102 size = skb->len+sizeof(struct atmtcp_hdr);
31103@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31104 if (!new_skb) {
31105 if (vcc->pop) vcc->pop(vcc,skb);
31106 else dev_kfree_skb(skb);
31107- atomic_inc(&vcc->stats->tx_err);
31108+ atomic_inc_unchecked(&vcc->stats->tx_err);
31109 return -ENOBUFS;
31110 }
31111 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
31112@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31113 if (vcc->pop) vcc->pop(vcc,skb);
31114 else dev_kfree_skb(skb);
31115 out_vcc->push(out_vcc,new_skb);
31116- atomic_inc(&vcc->stats->tx);
31117- atomic_inc(&out_vcc->stats->rx);
31118+ atomic_inc_unchecked(&vcc->stats->tx);
31119+ atomic_inc_unchecked(&out_vcc->stats->rx);
31120 return 0;
31121 }
31122
31123@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
31124 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
31125 read_unlock(&vcc_sklist_lock);
31126 if (!out_vcc) {
31127- atomic_inc(&vcc->stats->tx_err);
31128+ atomic_inc_unchecked(&vcc->stats->tx_err);
31129 goto done;
31130 }
31131 skb_pull(skb,sizeof(struct atmtcp_hdr));
31132@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
31133 __net_timestamp(new_skb);
31134 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
31135 out_vcc->push(out_vcc,new_skb);
31136- atomic_inc(&vcc->stats->tx);
31137- atomic_inc(&out_vcc->stats->rx);
31138+ atomic_inc_unchecked(&vcc->stats->tx);
31139+ atomic_inc_unchecked(&out_vcc->stats->rx);
31140 done:
31141 if (vcc->pop) vcc->pop(vcc,skb);
31142 else dev_kfree_skb(skb);
31143diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
31144index c1eb6fa..4c71be9 100644
31145--- a/drivers/atm/eni.c
31146+++ b/drivers/atm/eni.c
31147@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
31148 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
31149 vcc->dev->number);
31150 length = 0;
31151- atomic_inc(&vcc->stats->rx_err);
31152+ atomic_inc_unchecked(&vcc->stats->rx_err);
31153 }
31154 else {
31155 length = ATM_CELL_SIZE-1; /* no HEC */
31156@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
31157 size);
31158 }
31159 eff = length = 0;
31160- atomic_inc(&vcc->stats->rx_err);
31161+ atomic_inc_unchecked(&vcc->stats->rx_err);
31162 }
31163 else {
31164 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
31165@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
31166 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
31167 vcc->dev->number,vcc->vci,length,size << 2,descr);
31168 length = eff = 0;
31169- atomic_inc(&vcc->stats->rx_err);
31170+ atomic_inc_unchecked(&vcc->stats->rx_err);
31171 }
31172 }
31173 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
31174@@ -767,7 +767,7 @@ rx_dequeued++;
31175 vcc->push(vcc,skb);
31176 pushed++;
31177 }
31178- atomic_inc(&vcc->stats->rx);
31179+ atomic_inc_unchecked(&vcc->stats->rx);
31180 }
31181 wake_up(&eni_dev->rx_wait);
31182 }
31183@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
31184 PCI_DMA_TODEVICE);
31185 if (vcc->pop) vcc->pop(vcc,skb);
31186 else dev_kfree_skb_irq(skb);
31187- atomic_inc(&vcc->stats->tx);
31188+ atomic_inc_unchecked(&vcc->stats->tx);
31189 wake_up(&eni_dev->tx_wait);
31190 dma_complete++;
31191 }
31192diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
31193index b41c948..a002b17 100644
31194--- a/drivers/atm/firestream.c
31195+++ b/drivers/atm/firestream.c
31196@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
31197 }
31198 }
31199
31200- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31201+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31202
31203 fs_dprintk (FS_DEBUG_TXMEM, "i");
31204 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
31205@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
31206 #endif
31207 skb_put (skb, qe->p1 & 0xffff);
31208 ATM_SKB(skb)->vcc = atm_vcc;
31209- atomic_inc(&atm_vcc->stats->rx);
31210+ atomic_inc_unchecked(&atm_vcc->stats->rx);
31211 __net_timestamp(skb);
31212 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
31213 atm_vcc->push (atm_vcc, skb);
31214@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
31215 kfree (pe);
31216 }
31217 if (atm_vcc)
31218- atomic_inc(&atm_vcc->stats->rx_drop);
31219+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31220 break;
31221 case 0x1f: /* Reassembly abort: no buffers. */
31222 /* Silently increment error counter. */
31223 if (atm_vcc)
31224- atomic_inc(&atm_vcc->stats->rx_drop);
31225+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31226 break;
31227 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
31228 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
31229diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
31230index 204814e..cede831 100644
31231--- a/drivers/atm/fore200e.c
31232+++ b/drivers/atm/fore200e.c
31233@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
31234 #endif
31235 /* check error condition */
31236 if (*entry->status & STATUS_ERROR)
31237- atomic_inc(&vcc->stats->tx_err);
31238+ atomic_inc_unchecked(&vcc->stats->tx_err);
31239 else
31240- atomic_inc(&vcc->stats->tx);
31241+ atomic_inc_unchecked(&vcc->stats->tx);
31242 }
31243 }
31244
31245@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
31246 if (skb == NULL) {
31247 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
31248
31249- atomic_inc(&vcc->stats->rx_drop);
31250+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31251 return -ENOMEM;
31252 }
31253
31254@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
31255
31256 dev_kfree_skb_any(skb);
31257
31258- atomic_inc(&vcc->stats->rx_drop);
31259+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31260 return -ENOMEM;
31261 }
31262
31263 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
31264
31265 vcc->push(vcc, skb);
31266- atomic_inc(&vcc->stats->rx);
31267+ atomic_inc_unchecked(&vcc->stats->rx);
31268
31269 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
31270
31271@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
31272 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
31273 fore200e->atm_dev->number,
31274 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
31275- atomic_inc(&vcc->stats->rx_err);
31276+ atomic_inc_unchecked(&vcc->stats->rx_err);
31277 }
31278 }
31279
31280@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
31281 goto retry_here;
31282 }
31283
31284- atomic_inc(&vcc->stats->tx_err);
31285+ atomic_inc_unchecked(&vcc->stats->tx_err);
31286
31287 fore200e->tx_sat++;
31288 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
31289diff --git a/drivers/atm/he.c b/drivers/atm/he.c
31290index 72b6960..cf9167a 100644
31291--- a/drivers/atm/he.c
31292+++ b/drivers/atm/he.c
31293@@ -1699,7 +1699,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
31294
31295 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
31296 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
31297- atomic_inc(&vcc->stats->rx_drop);
31298+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31299 goto return_host_buffers;
31300 }
31301
31302@@ -1726,7 +1726,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
31303 RBRQ_LEN_ERR(he_dev->rbrq_head)
31304 ? "LEN_ERR" : "",
31305 vcc->vpi, vcc->vci);
31306- atomic_inc(&vcc->stats->rx_err);
31307+ atomic_inc_unchecked(&vcc->stats->rx_err);
31308 goto return_host_buffers;
31309 }
31310
31311@@ -1778,7 +1778,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
31312 vcc->push(vcc, skb);
31313 spin_lock(&he_dev->global_lock);
31314
31315- atomic_inc(&vcc->stats->rx);
31316+ atomic_inc_unchecked(&vcc->stats->rx);
31317
31318 return_host_buffers:
31319 ++pdus_assembled;
31320@@ -2104,7 +2104,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
31321 tpd->vcc->pop(tpd->vcc, tpd->skb);
31322 else
31323 dev_kfree_skb_any(tpd->skb);
31324- atomic_inc(&tpd->vcc->stats->tx_err);
31325+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
31326 }
31327 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
31328 return;
31329@@ -2516,7 +2516,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31330 vcc->pop(vcc, skb);
31331 else
31332 dev_kfree_skb_any(skb);
31333- atomic_inc(&vcc->stats->tx_err);
31334+ atomic_inc_unchecked(&vcc->stats->tx_err);
31335 return -EINVAL;
31336 }
31337
31338@@ -2527,7 +2527,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31339 vcc->pop(vcc, skb);
31340 else
31341 dev_kfree_skb_any(skb);
31342- atomic_inc(&vcc->stats->tx_err);
31343+ atomic_inc_unchecked(&vcc->stats->tx_err);
31344 return -EINVAL;
31345 }
31346 #endif
31347@@ -2539,7 +2539,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31348 vcc->pop(vcc, skb);
31349 else
31350 dev_kfree_skb_any(skb);
31351- atomic_inc(&vcc->stats->tx_err);
31352+ atomic_inc_unchecked(&vcc->stats->tx_err);
31353 spin_unlock_irqrestore(&he_dev->global_lock, flags);
31354 return -ENOMEM;
31355 }
31356@@ -2581,7 +2581,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31357 vcc->pop(vcc, skb);
31358 else
31359 dev_kfree_skb_any(skb);
31360- atomic_inc(&vcc->stats->tx_err);
31361+ atomic_inc_unchecked(&vcc->stats->tx_err);
31362 spin_unlock_irqrestore(&he_dev->global_lock, flags);
31363 return -ENOMEM;
31364 }
31365@@ -2612,7 +2612,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31366 __enqueue_tpd(he_dev, tpd, cid);
31367 spin_unlock_irqrestore(&he_dev->global_lock, flags);
31368
31369- atomic_inc(&vcc->stats->tx);
31370+ atomic_inc_unchecked(&vcc->stats->tx);
31371
31372 return 0;
31373 }
31374diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
31375index 1dc0519..1aadaf7 100644
31376--- a/drivers/atm/horizon.c
31377+++ b/drivers/atm/horizon.c
31378@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
31379 {
31380 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
31381 // VC layer stats
31382- atomic_inc(&vcc->stats->rx);
31383+ atomic_inc_unchecked(&vcc->stats->rx);
31384 __net_timestamp(skb);
31385 // end of our responsibility
31386 vcc->push (vcc, skb);
31387@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
31388 dev->tx_iovec = NULL;
31389
31390 // VC layer stats
31391- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31392+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31393
31394 // free the skb
31395 hrz_kfree_skb (skb);
31396diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
31397index 272f009..a18ba55 100644
31398--- a/drivers/atm/idt77252.c
31399+++ b/drivers/atm/idt77252.c
31400@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
31401 else
31402 dev_kfree_skb(skb);
31403
31404- atomic_inc(&vcc->stats->tx);
31405+ atomic_inc_unchecked(&vcc->stats->tx);
31406 }
31407
31408 atomic_dec(&scq->used);
31409@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31410 if ((sb = dev_alloc_skb(64)) == NULL) {
31411 printk("%s: Can't allocate buffers for aal0.\n",
31412 card->name);
31413- atomic_add(i, &vcc->stats->rx_drop);
31414+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
31415 break;
31416 }
31417 if (!atm_charge(vcc, sb->truesize)) {
31418 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
31419 card->name);
31420- atomic_add(i - 1, &vcc->stats->rx_drop);
31421+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
31422 dev_kfree_skb(sb);
31423 break;
31424 }
31425@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31426 ATM_SKB(sb)->vcc = vcc;
31427 __net_timestamp(sb);
31428 vcc->push(vcc, sb);
31429- atomic_inc(&vcc->stats->rx);
31430+ atomic_inc_unchecked(&vcc->stats->rx);
31431
31432 cell += ATM_CELL_PAYLOAD;
31433 }
31434@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31435 "(CDC: %08x)\n",
31436 card->name, len, rpp->len, readl(SAR_REG_CDC));
31437 recycle_rx_pool_skb(card, rpp);
31438- atomic_inc(&vcc->stats->rx_err);
31439+ atomic_inc_unchecked(&vcc->stats->rx_err);
31440 return;
31441 }
31442 if (stat & SAR_RSQE_CRC) {
31443 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
31444 recycle_rx_pool_skb(card, rpp);
31445- atomic_inc(&vcc->stats->rx_err);
31446+ atomic_inc_unchecked(&vcc->stats->rx_err);
31447 return;
31448 }
31449 if (skb_queue_len(&rpp->queue) > 1) {
31450@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31451 RXPRINTK("%s: Can't alloc RX skb.\n",
31452 card->name);
31453 recycle_rx_pool_skb(card, rpp);
31454- atomic_inc(&vcc->stats->rx_err);
31455+ atomic_inc_unchecked(&vcc->stats->rx_err);
31456 return;
31457 }
31458 if (!atm_charge(vcc, skb->truesize)) {
31459@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31460 __net_timestamp(skb);
31461
31462 vcc->push(vcc, skb);
31463- atomic_inc(&vcc->stats->rx);
31464+ atomic_inc_unchecked(&vcc->stats->rx);
31465
31466 return;
31467 }
31468@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31469 __net_timestamp(skb);
31470
31471 vcc->push(vcc, skb);
31472- atomic_inc(&vcc->stats->rx);
31473+ atomic_inc_unchecked(&vcc->stats->rx);
31474
31475 if (skb->truesize > SAR_FB_SIZE_3)
31476 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
31477@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
31478 if (vcc->qos.aal != ATM_AAL0) {
31479 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
31480 card->name, vpi, vci);
31481- atomic_inc(&vcc->stats->rx_drop);
31482+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31483 goto drop;
31484 }
31485
31486 if ((sb = dev_alloc_skb(64)) == NULL) {
31487 printk("%s: Can't allocate buffers for AAL0.\n",
31488 card->name);
31489- atomic_inc(&vcc->stats->rx_err);
31490+ atomic_inc_unchecked(&vcc->stats->rx_err);
31491 goto drop;
31492 }
31493
31494@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
31495 ATM_SKB(sb)->vcc = vcc;
31496 __net_timestamp(sb);
31497 vcc->push(vcc, sb);
31498- atomic_inc(&vcc->stats->rx);
31499+ atomic_inc_unchecked(&vcc->stats->rx);
31500
31501 drop:
31502 skb_pull(queue, 64);
31503@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
31504
31505 if (vc == NULL) {
31506 printk("%s: NULL connection in send().\n", card->name);
31507- atomic_inc(&vcc->stats->tx_err);
31508+ atomic_inc_unchecked(&vcc->stats->tx_err);
31509 dev_kfree_skb(skb);
31510 return -EINVAL;
31511 }
31512 if (!test_bit(VCF_TX, &vc->flags)) {
31513 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
31514- atomic_inc(&vcc->stats->tx_err);
31515+ atomic_inc_unchecked(&vcc->stats->tx_err);
31516 dev_kfree_skb(skb);
31517 return -EINVAL;
31518 }
31519@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
31520 break;
31521 default:
31522 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
31523- atomic_inc(&vcc->stats->tx_err);
31524+ atomic_inc_unchecked(&vcc->stats->tx_err);
31525 dev_kfree_skb(skb);
31526 return -EINVAL;
31527 }
31528
31529 if (skb_shinfo(skb)->nr_frags != 0) {
31530 printk("%s: No scatter-gather yet.\n", card->name);
31531- atomic_inc(&vcc->stats->tx_err);
31532+ atomic_inc_unchecked(&vcc->stats->tx_err);
31533 dev_kfree_skb(skb);
31534 return -EINVAL;
31535 }
31536@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
31537
31538 err = queue_skb(card, vc, skb, oam);
31539 if (err) {
31540- atomic_inc(&vcc->stats->tx_err);
31541+ atomic_inc_unchecked(&vcc->stats->tx_err);
31542 dev_kfree_skb(skb);
31543 return err;
31544 }
31545@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
31546 skb = dev_alloc_skb(64);
31547 if (!skb) {
31548 printk("%s: Out of memory in send_oam().\n", card->name);
31549- atomic_inc(&vcc->stats->tx_err);
31550+ atomic_inc_unchecked(&vcc->stats->tx_err);
31551 return -ENOMEM;
31552 }
31553 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
31554diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
31555index 4217f29..88f547a 100644
31556--- a/drivers/atm/iphase.c
31557+++ b/drivers/atm/iphase.c
31558@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
31559 status = (u_short) (buf_desc_ptr->desc_mode);
31560 if (status & (RX_CER | RX_PTE | RX_OFL))
31561 {
31562- atomic_inc(&vcc->stats->rx_err);
31563+ atomic_inc_unchecked(&vcc->stats->rx_err);
31564 IF_ERR(printk("IA: bad packet, dropping it");)
31565 if (status & RX_CER) {
31566 IF_ERR(printk(" cause: packet CRC error\n");)
31567@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
31568 len = dma_addr - buf_addr;
31569 if (len > iadev->rx_buf_sz) {
31570 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
31571- atomic_inc(&vcc->stats->rx_err);
31572+ atomic_inc_unchecked(&vcc->stats->rx_err);
31573 goto out_free_desc;
31574 }
31575
31576@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
31577 ia_vcc = INPH_IA_VCC(vcc);
31578 if (ia_vcc == NULL)
31579 {
31580- atomic_inc(&vcc->stats->rx_err);
31581+ atomic_inc_unchecked(&vcc->stats->rx_err);
31582 atm_return(vcc, skb->truesize);
31583 dev_kfree_skb_any(skb);
31584 goto INCR_DLE;
31585@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
31586 if ((length > iadev->rx_buf_sz) || (length >
31587 (skb->len - sizeof(struct cpcs_trailer))))
31588 {
31589- atomic_inc(&vcc->stats->rx_err);
31590+ atomic_inc_unchecked(&vcc->stats->rx_err);
31591 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
31592 length, skb->len);)
31593 atm_return(vcc, skb->truesize);
31594@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
31595
31596 IF_RX(printk("rx_dle_intr: skb push");)
31597 vcc->push(vcc,skb);
31598- atomic_inc(&vcc->stats->rx);
31599+ atomic_inc_unchecked(&vcc->stats->rx);
31600 iadev->rx_pkt_cnt++;
31601 }
31602 INCR_DLE:
31603@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
31604 {
31605 struct k_sonet_stats *stats;
31606 stats = &PRIV(_ia_dev[board])->sonet_stats;
31607- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
31608- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
31609- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
31610- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
31611- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
31612- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
31613- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
31614- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
31615- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
31616+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
31617+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
31618+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
31619+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
31620+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
31621+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
31622+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
31623+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
31624+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
31625 }
31626 ia_cmds.status = 0;
31627 break;
31628@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
31629 if ((desc == 0) || (desc > iadev->num_tx_desc))
31630 {
31631 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
31632- atomic_inc(&vcc->stats->tx);
31633+ atomic_inc_unchecked(&vcc->stats->tx);
31634 if (vcc->pop)
31635 vcc->pop(vcc, skb);
31636 else
31637@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
31638 ATM_DESC(skb) = vcc->vci;
31639 skb_queue_tail(&iadev->tx_dma_q, skb);
31640
31641- atomic_inc(&vcc->stats->tx);
31642+ atomic_inc_unchecked(&vcc->stats->tx);
31643 iadev->tx_pkt_cnt++;
31644 /* Increment transaction counter */
31645 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
31646
31647 #if 0
31648 /* add flow control logic */
31649- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
31650+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
31651 if (iavcc->vc_desc_cnt > 10) {
31652 vcc->tx_quota = vcc->tx_quota * 3 / 4;
31653 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
31654diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
31655index fa7d701..1e404c7 100644
31656--- a/drivers/atm/lanai.c
31657+++ b/drivers/atm/lanai.c
31658@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
31659 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
31660 lanai_endtx(lanai, lvcc);
31661 lanai_free_skb(lvcc->tx.atmvcc, skb);
31662- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
31663+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
31664 }
31665
31666 /* Try to fill the buffer - don't call unless there is backlog */
31667@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
31668 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
31669 __net_timestamp(skb);
31670 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
31671- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
31672+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
31673 out:
31674 lvcc->rx.buf.ptr = end;
31675 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
31676@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
31677 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
31678 "vcc %d\n", lanai->number, (unsigned int) s, vci);
31679 lanai->stats.service_rxnotaal5++;
31680- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
31681+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
31682 return 0;
31683 }
31684 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
31685@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
31686 int bytes;
31687 read_unlock(&vcc_sklist_lock);
31688 DPRINTK("got trashed rx pdu on vci %d\n", vci);
31689- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
31690+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
31691 lvcc->stats.x.aal5.service_trash++;
31692 bytes = (SERVICE_GET_END(s) * 16) -
31693 (((unsigned long) lvcc->rx.buf.ptr) -
31694@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
31695 }
31696 if (s & SERVICE_STREAM) {
31697 read_unlock(&vcc_sklist_lock);
31698- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
31699+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
31700 lvcc->stats.x.aal5.service_stream++;
31701 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
31702 "PDU on VCI %d!\n", lanai->number, vci);
31703@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
31704 return 0;
31705 }
31706 DPRINTK("got rx crc error on vci %d\n", vci);
31707- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
31708+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
31709 lvcc->stats.x.aal5.service_rxcrc++;
31710 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
31711 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
31712diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
31713index ed1d2b7..8cffc1f 100644
31714--- a/drivers/atm/nicstar.c
31715+++ b/drivers/atm/nicstar.c
31716@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
31717 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
31718 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
31719 card->index);
31720- atomic_inc(&vcc->stats->tx_err);
31721+ atomic_inc_unchecked(&vcc->stats->tx_err);
31722 dev_kfree_skb_any(skb);
31723 return -EINVAL;
31724 }
31725@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
31726 if (!vc->tx) {
31727 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
31728 card->index);
31729- atomic_inc(&vcc->stats->tx_err);
31730+ atomic_inc_unchecked(&vcc->stats->tx_err);
31731 dev_kfree_skb_any(skb);
31732 return -EINVAL;
31733 }
31734@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
31735 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
31736 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
31737 card->index);
31738- atomic_inc(&vcc->stats->tx_err);
31739+ atomic_inc_unchecked(&vcc->stats->tx_err);
31740 dev_kfree_skb_any(skb);
31741 return -EINVAL;
31742 }
31743
31744 if (skb_shinfo(skb)->nr_frags != 0) {
31745 printk("nicstar%d: No scatter-gather yet.\n", card->index);
31746- atomic_inc(&vcc->stats->tx_err);
31747+ atomic_inc_unchecked(&vcc->stats->tx_err);
31748 dev_kfree_skb_any(skb);
31749 return -EINVAL;
31750 }
31751@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
31752 }
31753
31754 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
31755- atomic_inc(&vcc->stats->tx_err);
31756+ atomic_inc_unchecked(&vcc->stats->tx_err);
31757 dev_kfree_skb_any(skb);
31758 return -EIO;
31759 }
31760- atomic_inc(&vcc->stats->tx);
31761+ atomic_inc_unchecked(&vcc->stats->tx);
31762
31763 return 0;
31764 }
31765@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31766 printk
31767 ("nicstar%d: Can't allocate buffers for aal0.\n",
31768 card->index);
31769- atomic_add(i, &vcc->stats->rx_drop);
31770+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
31771 break;
31772 }
31773 if (!atm_charge(vcc, sb->truesize)) {
31774 RXPRINTK
31775 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
31776 card->index);
31777- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
31778+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
31779 dev_kfree_skb_any(sb);
31780 break;
31781 }
31782@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31783 ATM_SKB(sb)->vcc = vcc;
31784 __net_timestamp(sb);
31785 vcc->push(vcc, sb);
31786- atomic_inc(&vcc->stats->rx);
31787+ atomic_inc_unchecked(&vcc->stats->rx);
31788 cell += ATM_CELL_PAYLOAD;
31789 }
31790
31791@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31792 if (iovb == NULL) {
31793 printk("nicstar%d: Out of iovec buffers.\n",
31794 card->index);
31795- atomic_inc(&vcc->stats->rx_drop);
31796+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31797 recycle_rx_buf(card, skb);
31798 return;
31799 }
31800@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31801 small or large buffer itself. */
31802 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
31803 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
31804- atomic_inc(&vcc->stats->rx_err);
31805+ atomic_inc_unchecked(&vcc->stats->rx_err);
31806 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
31807 NS_MAX_IOVECS);
31808 NS_PRV_IOVCNT(iovb) = 0;
31809@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31810 ("nicstar%d: Expected a small buffer, and this is not one.\n",
31811 card->index);
31812 which_list(card, skb);
31813- atomic_inc(&vcc->stats->rx_err);
31814+ atomic_inc_unchecked(&vcc->stats->rx_err);
31815 recycle_rx_buf(card, skb);
31816 vc->rx_iov = NULL;
31817 recycle_iov_buf(card, iovb);
31818@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31819 ("nicstar%d: Expected a large buffer, and this is not one.\n",
31820 card->index);
31821 which_list(card, skb);
31822- atomic_inc(&vcc->stats->rx_err);
31823+ atomic_inc_unchecked(&vcc->stats->rx_err);
31824 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
31825 NS_PRV_IOVCNT(iovb));
31826 vc->rx_iov = NULL;
31827@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31828 printk(" - PDU size mismatch.\n");
31829 else
31830 printk(".\n");
31831- atomic_inc(&vcc->stats->rx_err);
31832+ atomic_inc_unchecked(&vcc->stats->rx_err);
31833 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
31834 NS_PRV_IOVCNT(iovb));
31835 vc->rx_iov = NULL;
31836@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31837 /* skb points to a small buffer */
31838 if (!atm_charge(vcc, skb->truesize)) {
31839 push_rxbufs(card, skb);
31840- atomic_inc(&vcc->stats->rx_drop);
31841+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31842 } else {
31843 skb_put(skb, len);
31844 dequeue_sm_buf(card, skb);
31845@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31846 ATM_SKB(skb)->vcc = vcc;
31847 __net_timestamp(skb);
31848 vcc->push(vcc, skb);
31849- atomic_inc(&vcc->stats->rx);
31850+ atomic_inc_unchecked(&vcc->stats->rx);
31851 }
31852 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
31853 struct sk_buff *sb;
31854@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31855 if (len <= NS_SMBUFSIZE) {
31856 if (!atm_charge(vcc, sb->truesize)) {
31857 push_rxbufs(card, sb);
31858- atomic_inc(&vcc->stats->rx_drop);
31859+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31860 } else {
31861 skb_put(sb, len);
31862 dequeue_sm_buf(card, sb);
31863@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31864 ATM_SKB(sb)->vcc = vcc;
31865 __net_timestamp(sb);
31866 vcc->push(vcc, sb);
31867- atomic_inc(&vcc->stats->rx);
31868+ atomic_inc_unchecked(&vcc->stats->rx);
31869 }
31870
31871 push_rxbufs(card, skb);
31872@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31873
31874 if (!atm_charge(vcc, skb->truesize)) {
31875 push_rxbufs(card, skb);
31876- atomic_inc(&vcc->stats->rx_drop);
31877+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31878 } else {
31879 dequeue_lg_buf(card, skb);
31880 #ifdef NS_USE_DESTRUCTORS
31881@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31882 ATM_SKB(skb)->vcc = vcc;
31883 __net_timestamp(skb);
31884 vcc->push(vcc, skb);
31885- atomic_inc(&vcc->stats->rx);
31886+ atomic_inc_unchecked(&vcc->stats->rx);
31887 }
31888
31889 push_rxbufs(card, sb);
31890@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31891 printk
31892 ("nicstar%d: Out of huge buffers.\n",
31893 card->index);
31894- atomic_inc(&vcc->stats->rx_drop);
31895+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31896 recycle_iovec_rx_bufs(card,
31897 (struct iovec *)
31898 iovb->data,
31899@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31900 card->hbpool.count++;
31901 } else
31902 dev_kfree_skb_any(hb);
31903- atomic_inc(&vcc->stats->rx_drop);
31904+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31905 } else {
31906 /* Copy the small buffer to the huge buffer */
31907 sb = (struct sk_buff *)iov->iov_base;
31908@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31909 #endif /* NS_USE_DESTRUCTORS */
31910 __net_timestamp(hb);
31911 vcc->push(vcc, hb);
31912- atomic_inc(&vcc->stats->rx);
31913+ atomic_inc_unchecked(&vcc->stats->rx);
31914 }
31915 }
31916
31917diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
31918index 0474a89..06ea4a1 100644
31919--- a/drivers/atm/solos-pci.c
31920+++ b/drivers/atm/solos-pci.c
31921@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
31922 }
31923 atm_charge(vcc, skb->truesize);
31924 vcc->push(vcc, skb);
31925- atomic_inc(&vcc->stats->rx);
31926+ atomic_inc_unchecked(&vcc->stats->rx);
31927 break;
31928
31929 case PKT_STATUS:
31930@@ -1117,7 +1117,7 @@ static uint32_t fpga_tx(struct solos_card *card)
31931 vcc = SKB_CB(oldskb)->vcc;
31932
31933 if (vcc) {
31934- atomic_inc(&vcc->stats->tx);
31935+ atomic_inc_unchecked(&vcc->stats->tx);
31936 solos_pop(vcc, oldskb);
31937 } else {
31938 dev_kfree_skb_irq(oldskb);
31939diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
31940index 0215934..ce9f5b1 100644
31941--- a/drivers/atm/suni.c
31942+++ b/drivers/atm/suni.c
31943@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
31944
31945
31946 #define ADD_LIMITED(s,v) \
31947- atomic_add((v),&stats->s); \
31948- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
31949+ atomic_add_unchecked((v),&stats->s); \
31950+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
31951
31952
31953 static void suni_hz(unsigned long from_timer)
31954diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
31955index 5120a96..e2572bd 100644
31956--- a/drivers/atm/uPD98402.c
31957+++ b/drivers/atm/uPD98402.c
31958@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
31959 struct sonet_stats tmp;
31960 int error = 0;
31961
31962- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
31963+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
31964 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
31965 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
31966 if (zero && !error) {
31967@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
31968
31969
31970 #define ADD_LIMITED(s,v) \
31971- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
31972- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
31973- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
31974+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
31975+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
31976+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
31977
31978
31979 static void stat_event(struct atm_dev *dev)
31980@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
31981 if (reason & uPD98402_INT_PFM) stat_event(dev);
31982 if (reason & uPD98402_INT_PCO) {
31983 (void) GET(PCOCR); /* clear interrupt cause */
31984- atomic_add(GET(HECCT),
31985+ atomic_add_unchecked(GET(HECCT),
31986 &PRIV(dev)->sonet_stats.uncorr_hcs);
31987 }
31988 if ((reason & uPD98402_INT_RFO) &&
31989@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
31990 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
31991 uPD98402_INT_LOS),PIMR); /* enable them */
31992 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
31993- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
31994- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
31995- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
31996+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
31997+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
31998+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
31999 return 0;
32000 }
32001
32002diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
32003index 969c3c2..9b72956 100644
32004--- a/drivers/atm/zatm.c
32005+++ b/drivers/atm/zatm.c
32006@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
32007 }
32008 if (!size) {
32009 dev_kfree_skb_irq(skb);
32010- if (vcc) atomic_inc(&vcc->stats->rx_err);
32011+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
32012 continue;
32013 }
32014 if (!atm_charge(vcc,skb->truesize)) {
32015@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
32016 skb->len = size;
32017 ATM_SKB(skb)->vcc = vcc;
32018 vcc->push(vcc,skb);
32019- atomic_inc(&vcc->stats->rx);
32020+ atomic_inc_unchecked(&vcc->stats->rx);
32021 }
32022 zout(pos & 0xffff,MTA(mbx));
32023 #if 0 /* probably a stupid idea */
32024@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
32025 skb_queue_head(&zatm_vcc->backlog,skb);
32026 break;
32027 }
32028- atomic_inc(&vcc->stats->tx);
32029+ atomic_inc_unchecked(&vcc->stats->tx);
32030 wake_up(&zatm_vcc->tx_wait);
32031 }
32032
32033diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
32034index 17cf7ca..7e553e1 100644
32035--- a/drivers/base/devtmpfs.c
32036+++ b/drivers/base/devtmpfs.c
32037@@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
32038 if (!thread)
32039 return 0;
32040
32041- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
32042+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
32043 if (err)
32044 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
32045 else
32046diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
32047index e6ee5e8..98ad7fc 100644
32048--- a/drivers/base/power/wakeup.c
32049+++ b/drivers/base/power/wakeup.c
32050@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
32051 * They need to be modified together atomically, so it's better to use one
32052 * atomic variable to hold them both.
32053 */
32054-static atomic_t combined_event_count = ATOMIC_INIT(0);
32055+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
32056
32057 #define IN_PROGRESS_BITS (sizeof(int) * 4)
32058 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
32059
32060 static void split_counters(unsigned int *cnt, unsigned int *inpr)
32061 {
32062- unsigned int comb = atomic_read(&combined_event_count);
32063+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
32064
32065 *cnt = (comb >> IN_PROGRESS_BITS);
32066 *inpr = comb & MAX_IN_PROGRESS;
32067@@ -389,7 +389,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
32068 ws->start_prevent_time = ws->last_time;
32069
32070 /* Increment the counter of events in progress. */
32071- cec = atomic_inc_return(&combined_event_count);
32072+ cec = atomic_inc_return_unchecked(&combined_event_count);
32073
32074 trace_wakeup_source_activate(ws->name, cec);
32075 }
32076@@ -515,7 +515,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
32077 * Increment the counter of registered wakeup events and decrement the
32078 * couter of wakeup events in progress simultaneously.
32079 */
32080- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
32081+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
32082 trace_wakeup_source_deactivate(ws->name, cec);
32083
32084 split_counters(&cnt, &inpr);
32085diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
32086index ade58bc..867143d 100644
32087--- a/drivers/block/cciss.c
32088+++ b/drivers/block/cciss.c
32089@@ -1196,6 +1196,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
32090 int err;
32091 u32 cp;
32092
32093+ memset(&arg64, 0, sizeof(arg64));
32094+
32095 err = 0;
32096 err |=
32097 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
32098@@ -3005,7 +3007,7 @@ static void start_io(ctlr_info_t *h)
32099 while (!list_empty(&h->reqQ)) {
32100 c = list_entry(h->reqQ.next, CommandList_struct, list);
32101 /* can't do anything if fifo is full */
32102- if ((h->access.fifo_full(h))) {
32103+ if ((h->access->fifo_full(h))) {
32104 dev_warn(&h->pdev->dev, "fifo full\n");
32105 break;
32106 }
32107@@ -3015,7 +3017,7 @@ static void start_io(ctlr_info_t *h)
32108 h->Qdepth--;
32109
32110 /* Tell the controller execute command */
32111- h->access.submit_command(h, c);
32112+ h->access->submit_command(h, c);
32113
32114 /* Put job onto the completed Q */
32115 addQ(&h->cmpQ, c);
32116@@ -3441,17 +3443,17 @@ startio:
32117
32118 static inline unsigned long get_next_completion(ctlr_info_t *h)
32119 {
32120- return h->access.command_completed(h);
32121+ return h->access->command_completed(h);
32122 }
32123
32124 static inline int interrupt_pending(ctlr_info_t *h)
32125 {
32126- return h->access.intr_pending(h);
32127+ return h->access->intr_pending(h);
32128 }
32129
32130 static inline long interrupt_not_for_us(ctlr_info_t *h)
32131 {
32132- return ((h->access.intr_pending(h) == 0) ||
32133+ return ((h->access->intr_pending(h) == 0) ||
32134 (h->interrupts_enabled == 0));
32135 }
32136
32137@@ -3484,7 +3486,7 @@ static inline u32 next_command(ctlr_info_t *h)
32138 u32 a;
32139
32140 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
32141- return h->access.command_completed(h);
32142+ return h->access->command_completed(h);
32143
32144 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
32145 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
32146@@ -4041,7 +4043,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
32147 trans_support & CFGTBL_Trans_use_short_tags);
32148
32149 /* Change the access methods to the performant access methods */
32150- h->access = SA5_performant_access;
32151+ h->access = &SA5_performant_access;
32152 h->transMethod = CFGTBL_Trans_Performant;
32153
32154 return;
32155@@ -4310,7 +4312,7 @@ static int cciss_pci_init(ctlr_info_t *h)
32156 if (prod_index < 0)
32157 return -ENODEV;
32158 h->product_name = products[prod_index].product_name;
32159- h->access = *(products[prod_index].access);
32160+ h->access = products[prod_index].access;
32161
32162 if (cciss_board_disabled(h)) {
32163 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
32164@@ -5032,7 +5034,7 @@ reinit_after_soft_reset:
32165 }
32166
32167 /* make sure the board interrupts are off */
32168- h->access.set_intr_mask(h, CCISS_INTR_OFF);
32169+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
32170 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
32171 if (rc)
32172 goto clean2;
32173@@ -5082,7 +5084,7 @@ reinit_after_soft_reset:
32174 * fake ones to scoop up any residual completions.
32175 */
32176 spin_lock_irqsave(&h->lock, flags);
32177- h->access.set_intr_mask(h, CCISS_INTR_OFF);
32178+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
32179 spin_unlock_irqrestore(&h->lock, flags);
32180 free_irq(h->intr[h->intr_mode], h);
32181 rc = cciss_request_irq(h, cciss_msix_discard_completions,
32182@@ -5102,9 +5104,9 @@ reinit_after_soft_reset:
32183 dev_info(&h->pdev->dev, "Board READY.\n");
32184 dev_info(&h->pdev->dev,
32185 "Waiting for stale completions to drain.\n");
32186- h->access.set_intr_mask(h, CCISS_INTR_ON);
32187+ h->access->set_intr_mask(h, CCISS_INTR_ON);
32188 msleep(10000);
32189- h->access.set_intr_mask(h, CCISS_INTR_OFF);
32190+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
32191
32192 rc = controller_reset_failed(h->cfgtable);
32193 if (rc)
32194@@ -5127,7 +5129,7 @@ reinit_after_soft_reset:
32195 cciss_scsi_setup(h);
32196
32197 /* Turn the interrupts on so we can service requests */
32198- h->access.set_intr_mask(h, CCISS_INTR_ON);
32199+ h->access->set_intr_mask(h, CCISS_INTR_ON);
32200
32201 /* Get the firmware version */
32202 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
32203@@ -5199,7 +5201,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
32204 kfree(flush_buf);
32205 if (return_code != IO_OK)
32206 dev_warn(&h->pdev->dev, "Error flushing cache\n");
32207- h->access.set_intr_mask(h, CCISS_INTR_OFF);
32208+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
32209 free_irq(h->intr[h->intr_mode], h);
32210 }
32211
32212diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
32213index 7fda30e..eb5dfe0 100644
32214--- a/drivers/block/cciss.h
32215+++ b/drivers/block/cciss.h
32216@@ -101,7 +101,7 @@ struct ctlr_info
32217 /* information about each logical volume */
32218 drive_info_struct *drv[CISS_MAX_LUN];
32219
32220- struct access_method access;
32221+ struct access_method *access;
32222
32223 /* queue and queue Info */
32224 struct list_head reqQ;
32225diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
32226index 3f08713..56a586a 100644
32227--- a/drivers/block/cpqarray.c
32228+++ b/drivers/block/cpqarray.c
32229@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
32230 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
32231 goto Enomem4;
32232 }
32233- hba[i]->access.set_intr_mask(hba[i], 0);
32234+ hba[i]->access->set_intr_mask(hba[i], 0);
32235 if (request_irq(hba[i]->intr, do_ida_intr,
32236 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
32237 {
32238@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
32239 add_timer(&hba[i]->timer);
32240
32241 /* Enable IRQ now that spinlock and rate limit timer are set up */
32242- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
32243+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
32244
32245 for(j=0; j<NWD; j++) {
32246 struct gendisk *disk = ida_gendisk[i][j];
32247@@ -694,7 +694,7 @@ DBGINFO(
32248 for(i=0; i<NR_PRODUCTS; i++) {
32249 if (board_id == products[i].board_id) {
32250 c->product_name = products[i].product_name;
32251- c->access = *(products[i].access);
32252+ c->access = products[i].access;
32253 break;
32254 }
32255 }
32256@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
32257 hba[ctlr]->intr = intr;
32258 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
32259 hba[ctlr]->product_name = products[j].product_name;
32260- hba[ctlr]->access = *(products[j].access);
32261+ hba[ctlr]->access = products[j].access;
32262 hba[ctlr]->ctlr = ctlr;
32263 hba[ctlr]->board_id = board_id;
32264 hba[ctlr]->pci_dev = NULL; /* not PCI */
32265@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
32266
32267 while((c = h->reqQ) != NULL) {
32268 /* Can't do anything if we're busy */
32269- if (h->access.fifo_full(h) == 0)
32270+ if (h->access->fifo_full(h) == 0)
32271 return;
32272
32273 /* Get the first entry from the request Q */
32274@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
32275 h->Qdepth--;
32276
32277 /* Tell the controller to do our bidding */
32278- h->access.submit_command(h, c);
32279+ h->access->submit_command(h, c);
32280
32281 /* Get onto the completion Q */
32282 addQ(&h->cmpQ, c);
32283@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
32284 unsigned long flags;
32285 __u32 a,a1;
32286
32287- istat = h->access.intr_pending(h);
32288+ istat = h->access->intr_pending(h);
32289 /* Is this interrupt for us? */
32290 if (istat == 0)
32291 return IRQ_NONE;
32292@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
32293 */
32294 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
32295 if (istat & FIFO_NOT_EMPTY) {
32296- while((a = h->access.command_completed(h))) {
32297+ while((a = h->access->command_completed(h))) {
32298 a1 = a; a &= ~3;
32299 if ((c = h->cmpQ) == NULL)
32300 {
32301@@ -1449,11 +1449,11 @@ static int sendcmd(
32302 /*
32303 * Disable interrupt
32304 */
32305- info_p->access.set_intr_mask(info_p, 0);
32306+ info_p->access->set_intr_mask(info_p, 0);
32307 /* Make sure there is room in the command FIFO */
32308 /* Actually it should be completely empty at this time. */
32309 for (i = 200000; i > 0; i--) {
32310- temp = info_p->access.fifo_full(info_p);
32311+ temp = info_p->access->fifo_full(info_p);
32312 if (temp != 0) {
32313 break;
32314 }
32315@@ -1466,7 +1466,7 @@ DBG(
32316 /*
32317 * Send the cmd
32318 */
32319- info_p->access.submit_command(info_p, c);
32320+ info_p->access->submit_command(info_p, c);
32321 complete = pollcomplete(ctlr);
32322
32323 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
32324@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
32325 * we check the new geometry. Then turn interrupts back on when
32326 * we're done.
32327 */
32328- host->access.set_intr_mask(host, 0);
32329+ host->access->set_intr_mask(host, 0);
32330 getgeometry(ctlr);
32331- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
32332+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
32333
32334 for(i=0; i<NWD; i++) {
32335 struct gendisk *disk = ida_gendisk[ctlr][i];
32336@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
32337 /* Wait (up to 2 seconds) for a command to complete */
32338
32339 for (i = 200000; i > 0; i--) {
32340- done = hba[ctlr]->access.command_completed(hba[ctlr]);
32341+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
32342 if (done == 0) {
32343 udelay(10); /* a short fixed delay */
32344 } else
32345diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
32346index be73e9d..7fbf140 100644
32347--- a/drivers/block/cpqarray.h
32348+++ b/drivers/block/cpqarray.h
32349@@ -99,7 +99,7 @@ struct ctlr_info {
32350 drv_info_t drv[NWD];
32351 struct proc_dir_entry *proc;
32352
32353- struct access_method access;
32354+ struct access_method *access;
32355
32356 cmdlist_t *reqQ;
32357 cmdlist_t *cmpQ;
32358diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
32359index 6b51afa..17e1191 100644
32360--- a/drivers/block/drbd/drbd_int.h
32361+++ b/drivers/block/drbd/drbd_int.h
32362@@ -582,7 +582,7 @@ struct drbd_epoch {
32363 struct drbd_tconn *tconn;
32364 struct list_head list;
32365 unsigned int barrier_nr;
32366- atomic_t epoch_size; /* increased on every request added. */
32367+ atomic_unchecked_t epoch_size; /* increased on every request added. */
32368 atomic_t active; /* increased on every req. added, and dec on every finished. */
32369 unsigned long flags;
32370 };
32371@@ -1011,7 +1011,7 @@ struct drbd_conf {
32372 int al_tr_cycle;
32373 int al_tr_pos; /* position of the next transaction in the journal */
32374 wait_queue_head_t seq_wait;
32375- atomic_t packet_seq;
32376+ atomic_unchecked_t packet_seq;
32377 unsigned int peer_seq;
32378 spinlock_t peer_seq_lock;
32379 unsigned int minor;
32380@@ -1527,7 +1527,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
32381 char __user *uoptval;
32382 int err;
32383
32384- uoptval = (char __user __force *)optval;
32385+ uoptval = (char __force_user *)optval;
32386
32387 set_fs(KERNEL_DS);
32388 if (level == SOL_SOCKET)
32389diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
32390index 8c13eeb..217adee 100644
32391--- a/drivers/block/drbd/drbd_main.c
32392+++ b/drivers/block/drbd/drbd_main.c
32393@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
32394 p->sector = sector;
32395 p->block_id = block_id;
32396 p->blksize = blksize;
32397- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
32398+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
32399 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
32400 }
32401
32402@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
32403 return -EIO;
32404 p->sector = cpu_to_be64(req->i.sector);
32405 p->block_id = (unsigned long)req;
32406- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
32407+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
32408 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
32409 if (mdev->state.conn >= C_SYNC_SOURCE &&
32410 mdev->state.conn <= C_PAUSED_SYNC_T)
32411@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
32412 {
32413 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
32414
32415- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
32416- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
32417+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
32418+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
32419 kfree(tconn->current_epoch);
32420
32421 idr_destroy(&tconn->volumes);
32422diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
32423index a9eccfc..68e4533 100644
32424--- a/drivers/block/drbd/drbd_receiver.c
32425+++ b/drivers/block/drbd/drbd_receiver.c
32426@@ -833,7 +833,7 @@ int drbd_connected(struct drbd_conf *mdev)
32427 {
32428 int err;
32429
32430- atomic_set(&mdev->packet_seq, 0);
32431+ atomic_set_unchecked(&mdev->packet_seq, 0);
32432 mdev->peer_seq = 0;
32433
32434 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
32435@@ -1191,7 +1191,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
32436 do {
32437 next_epoch = NULL;
32438
32439- epoch_size = atomic_read(&epoch->epoch_size);
32440+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
32441
32442 switch (ev & ~EV_CLEANUP) {
32443 case EV_PUT:
32444@@ -1231,7 +1231,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
32445 rv = FE_DESTROYED;
32446 } else {
32447 epoch->flags = 0;
32448- atomic_set(&epoch->epoch_size, 0);
32449+ atomic_set_unchecked(&epoch->epoch_size, 0);
32450 /* atomic_set(&epoch->active, 0); is already zero */
32451 if (rv == FE_STILL_LIVE)
32452 rv = FE_RECYCLED;
32453@@ -1449,7 +1449,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
32454 conn_wait_active_ee_empty(tconn);
32455 drbd_flush(tconn);
32456
32457- if (atomic_read(&tconn->current_epoch->epoch_size)) {
32458+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
32459 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
32460 if (epoch)
32461 break;
32462@@ -1462,11 +1462,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
32463 }
32464
32465 epoch->flags = 0;
32466- atomic_set(&epoch->epoch_size, 0);
32467+ atomic_set_unchecked(&epoch->epoch_size, 0);
32468 atomic_set(&epoch->active, 0);
32469
32470 spin_lock(&tconn->epoch_lock);
32471- if (atomic_read(&tconn->current_epoch->epoch_size)) {
32472+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
32473 list_add(&epoch->list, &tconn->current_epoch->list);
32474 tconn->current_epoch = epoch;
32475 tconn->epochs++;
32476@@ -2170,7 +2170,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
32477
32478 err = wait_for_and_update_peer_seq(mdev, peer_seq);
32479 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
32480- atomic_inc(&tconn->current_epoch->epoch_size);
32481+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
32482 err2 = drbd_drain_block(mdev, pi->size);
32483 if (!err)
32484 err = err2;
32485@@ -2204,7 +2204,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
32486
32487 spin_lock(&tconn->epoch_lock);
32488 peer_req->epoch = tconn->current_epoch;
32489- atomic_inc(&peer_req->epoch->epoch_size);
32490+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
32491 atomic_inc(&peer_req->epoch->active);
32492 spin_unlock(&tconn->epoch_lock);
32493
32494@@ -4466,7 +4466,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
32495 if (!list_empty(&tconn->current_epoch->list))
32496 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
32497 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
32498- atomic_set(&tconn->current_epoch->epoch_size, 0);
32499+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
32500 tconn->send.seen_any_write_yet = false;
32501
32502 conn_info(tconn, "Connection closed\n");
32503diff --git a/drivers/block/loop.c b/drivers/block/loop.c
32504index ae12512..37fa397 100644
32505--- a/drivers/block/loop.c
32506+++ b/drivers/block/loop.c
32507@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
32508 mm_segment_t old_fs = get_fs();
32509
32510 set_fs(get_ds());
32511- bw = file->f_op->write(file, buf, len, &pos);
32512+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
32513 set_fs(old_fs);
32514 if (likely(bw == len))
32515 return 0;
32516diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
32517index d620b44..587561e 100644
32518--- a/drivers/cdrom/cdrom.c
32519+++ b/drivers/cdrom/cdrom.c
32520@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
32521 ENSURE(reset, CDC_RESET);
32522 ENSURE(generic_packet, CDC_GENERIC_PACKET);
32523 cdi->mc_flags = 0;
32524- cdo->n_minors = 0;
32525 cdi->options = CDO_USE_FFLAGS;
32526
32527 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
32528@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
32529 else
32530 cdi->cdda_method = CDDA_OLD;
32531
32532- if (!cdo->generic_packet)
32533- cdo->generic_packet = cdrom_dummy_generic_packet;
32534+ if (!cdo->generic_packet) {
32535+ pax_open_kernel();
32536+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
32537+ pax_close_kernel();
32538+ }
32539
32540 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
32541 mutex_lock(&cdrom_mutex);
32542@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
32543 if (cdi->exit)
32544 cdi->exit(cdi);
32545
32546- cdi->ops->n_minors--;
32547 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
32548 }
32549
32550diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
32551index d59cdcb..11afddf 100644
32552--- a/drivers/cdrom/gdrom.c
32553+++ b/drivers/cdrom/gdrom.c
32554@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
32555 .audio_ioctl = gdrom_audio_ioctl,
32556 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
32557 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
32558- .n_minors = 1,
32559 };
32560
32561 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
32562diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
32563index 72bedad..8181ce1 100644
32564--- a/drivers/char/Kconfig
32565+++ b/drivers/char/Kconfig
32566@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
32567
32568 config DEVKMEM
32569 bool "/dev/kmem virtual device support"
32570- default y
32571+ default n
32572+ depends on !GRKERNSEC_KMEM
32573 help
32574 Say Y here if you want to support the /dev/kmem device. The
32575 /dev/kmem device is rarely used, but can be used for certain
32576@@ -581,6 +582,7 @@ config DEVPORT
32577 bool
32578 depends on !M68K
32579 depends on ISA || PCI
32580+ depends on !GRKERNSEC_KMEM
32581 default y
32582
32583 source "drivers/s390/char/Kconfig"
32584diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
32585index 2e04433..22afc64 100644
32586--- a/drivers/char/agp/frontend.c
32587+++ b/drivers/char/agp/frontend.c
32588@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
32589 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
32590 return -EFAULT;
32591
32592- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
32593+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
32594 return -EFAULT;
32595
32596 client = agp_find_client_by_pid(reserve.pid);
32597diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
32598index 21cb980..f15107c 100644
32599--- a/drivers/char/genrtc.c
32600+++ b/drivers/char/genrtc.c
32601@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
32602 switch (cmd) {
32603
32604 case RTC_PLL_GET:
32605+ memset(&pll, 0, sizeof(pll));
32606 if (get_rtc_pll(&pll))
32607 return -EINVAL;
32608 else
32609diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
32610index fe6d4be..89f32100 100644
32611--- a/drivers/char/hpet.c
32612+++ b/drivers/char/hpet.c
32613@@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
32614 }
32615
32616 static int
32617-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
32618+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
32619 struct hpet_info *info)
32620 {
32621 struct hpet_timer __iomem *timer;
32622diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
32623index 053201b0..8335cce 100644
32624--- a/drivers/char/ipmi/ipmi_msghandler.c
32625+++ b/drivers/char/ipmi/ipmi_msghandler.c
32626@@ -420,7 +420,7 @@ struct ipmi_smi {
32627 struct proc_dir_entry *proc_dir;
32628 char proc_dir_name[10];
32629
32630- atomic_t stats[IPMI_NUM_STATS];
32631+ atomic_unchecked_t stats[IPMI_NUM_STATS];
32632
32633 /*
32634 * run_to_completion duplicate of smb_info, smi_info
32635@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
32636
32637
32638 #define ipmi_inc_stat(intf, stat) \
32639- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
32640+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
32641 #define ipmi_get_stat(intf, stat) \
32642- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
32643+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
32644
32645 static int is_lan_addr(struct ipmi_addr *addr)
32646 {
32647@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
32648 INIT_LIST_HEAD(&intf->cmd_rcvrs);
32649 init_waitqueue_head(&intf->waitq);
32650 for (i = 0; i < IPMI_NUM_STATS; i++)
32651- atomic_set(&intf->stats[i], 0);
32652+ atomic_set_unchecked(&intf->stats[i], 0);
32653
32654 intf->proc_dir = NULL;
32655
32656diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
32657index 1c7fdcd..4899100 100644
32658--- a/drivers/char/ipmi/ipmi_si_intf.c
32659+++ b/drivers/char/ipmi/ipmi_si_intf.c
32660@@ -275,7 +275,7 @@ struct smi_info {
32661 unsigned char slave_addr;
32662
32663 /* Counters and things for the proc filesystem. */
32664- atomic_t stats[SI_NUM_STATS];
32665+ atomic_unchecked_t stats[SI_NUM_STATS];
32666
32667 struct task_struct *thread;
32668
32669@@ -284,9 +284,9 @@ struct smi_info {
32670 };
32671
32672 #define smi_inc_stat(smi, stat) \
32673- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
32674+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
32675 #define smi_get_stat(smi, stat) \
32676- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
32677+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
32678
32679 #define SI_MAX_PARMS 4
32680
32681@@ -3225,7 +3225,7 @@ static int try_smi_init(struct smi_info *new_smi)
32682 atomic_set(&new_smi->req_events, 0);
32683 new_smi->run_to_completion = 0;
32684 for (i = 0; i < SI_NUM_STATS; i++)
32685- atomic_set(&new_smi->stats[i], 0);
32686+ atomic_set_unchecked(&new_smi->stats[i], 0);
32687
32688 new_smi->interrupt_disabled = 1;
32689 atomic_set(&new_smi->stop_operation, 0);
32690diff --git a/drivers/char/mem.c b/drivers/char/mem.c
32691index c6fa3bc..4ca3e42 100644
32692--- a/drivers/char/mem.c
32693+++ b/drivers/char/mem.c
32694@@ -18,6 +18,7 @@
32695 #include <linux/raw.h>
32696 #include <linux/tty.h>
32697 #include <linux/capability.h>
32698+#include <linux/security.h>
32699 #include <linux/ptrace.h>
32700 #include <linux/device.h>
32701 #include <linux/highmem.h>
32702@@ -37,6 +38,10 @@
32703
32704 #define DEVPORT_MINOR 4
32705
32706+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
32707+extern const struct file_operations grsec_fops;
32708+#endif
32709+
32710 static inline unsigned long size_inside_page(unsigned long start,
32711 unsigned long size)
32712 {
32713@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
32714
32715 while (cursor < to) {
32716 if (!devmem_is_allowed(pfn)) {
32717+#ifdef CONFIG_GRKERNSEC_KMEM
32718+ gr_handle_mem_readwrite(from, to);
32719+#else
32720 printk(KERN_INFO
32721 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
32722 current->comm, from, to);
32723+#endif
32724 return 0;
32725 }
32726 cursor += PAGE_SIZE;
32727@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
32728 }
32729 return 1;
32730 }
32731+#elif defined(CONFIG_GRKERNSEC_KMEM)
32732+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
32733+{
32734+ return 0;
32735+}
32736 #else
32737 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
32738 {
32739@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
32740
32741 while (count > 0) {
32742 unsigned long remaining;
32743+ char *temp;
32744
32745 sz = size_inside_page(p, count);
32746
32747@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
32748 if (!ptr)
32749 return -EFAULT;
32750
32751- remaining = copy_to_user(buf, ptr, sz);
32752+#ifdef CONFIG_PAX_USERCOPY
32753+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
32754+ if (!temp) {
32755+ unxlate_dev_mem_ptr(p, ptr);
32756+ return -ENOMEM;
32757+ }
32758+ memcpy(temp, ptr, sz);
32759+#else
32760+ temp = ptr;
32761+#endif
32762+
32763+ remaining = copy_to_user(buf, temp, sz);
32764+
32765+#ifdef CONFIG_PAX_USERCOPY
32766+ kfree(temp);
32767+#endif
32768+
32769 unxlate_dev_mem_ptr(p, ptr);
32770 if (remaining)
32771 return -EFAULT;
32772@@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
32773 size_t count, loff_t *ppos)
32774 {
32775 unsigned long p = *ppos;
32776- ssize_t low_count, read, sz;
32777+ ssize_t low_count, read, sz, err = 0;
32778 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
32779- int err = 0;
32780
32781 read = 0;
32782 if (p < (unsigned long) high_memory) {
32783@@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
32784 }
32785 #endif
32786 while (low_count > 0) {
32787+ char *temp;
32788+
32789 sz = size_inside_page(p, low_count);
32790
32791 /*
32792@@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
32793 */
32794 kbuf = xlate_dev_kmem_ptr((char *)p);
32795
32796- if (copy_to_user(buf, kbuf, sz))
32797+#ifdef CONFIG_PAX_USERCOPY
32798+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
32799+ if (!temp)
32800+ return -ENOMEM;
32801+ memcpy(temp, kbuf, sz);
32802+#else
32803+ temp = kbuf;
32804+#endif
32805+
32806+ err = copy_to_user(buf, temp, sz);
32807+
32808+#ifdef CONFIG_PAX_USERCOPY
32809+ kfree(temp);
32810+#endif
32811+
32812+ if (err)
32813 return -EFAULT;
32814 buf += sz;
32815 p += sz;
32816@@ -833,6 +880,9 @@ static const struct memdev {
32817 #ifdef CONFIG_CRASH_DUMP
32818 [12] = { "oldmem", 0, &oldmem_fops, NULL },
32819 #endif
32820+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
32821+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
32822+#endif
32823 };
32824
32825 static int memory_open(struct inode *inode, struct file *filp)
32826diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
32827index 9df78e2..01ba9ae 100644
32828--- a/drivers/char/nvram.c
32829+++ b/drivers/char/nvram.c
32830@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
32831
32832 spin_unlock_irq(&rtc_lock);
32833
32834- if (copy_to_user(buf, contents, tmp - contents))
32835+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
32836 return -EFAULT;
32837
32838 *ppos = i;
32839diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
32840index b66eaa0..2619d1b 100644
32841--- a/drivers/char/pcmcia/synclink_cs.c
32842+++ b/drivers/char/pcmcia/synclink_cs.c
32843@@ -2348,9 +2348,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
32844
32845 if (debug_level >= DEBUG_LEVEL_INFO)
32846 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
32847- __FILE__,__LINE__, info->device_name, port->count);
32848+ __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
32849
32850- WARN_ON(!port->count);
32851+ WARN_ON(!atomic_read(&port->count));
32852
32853 if (tty_port_close_start(port, tty, filp) == 0)
32854 goto cleanup;
32855@@ -2368,7 +2368,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
32856 cleanup:
32857 if (debug_level >= DEBUG_LEVEL_INFO)
32858 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
32859- tty->driver->name, port->count);
32860+ tty->driver->name, atomic_read(&port->count));
32861 }
32862
32863 /* Wait until the transmitter is empty.
32864@@ -2510,7 +2510,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
32865
32866 if (debug_level >= DEBUG_LEVEL_INFO)
32867 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
32868- __FILE__,__LINE__,tty->driver->name, port->count);
32869+ __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
32870
32871 /* If port is closing, signal caller to try again */
32872 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
32873@@ -2530,11 +2530,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
32874 goto cleanup;
32875 }
32876 spin_lock(&port->lock);
32877- port->count++;
32878+ atomic_inc(&port->count);
32879 spin_unlock(&port->lock);
32880 spin_unlock_irqrestore(&info->netlock, flags);
32881
32882- if (port->count == 1) {
32883+ if (atomic_read(&port->count) == 1) {
32884 /* 1st open on this device, init hardware */
32885 retval = startup(info, tty);
32886 if (retval < 0)
32887@@ -3889,7 +3889,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
32888 unsigned short new_crctype;
32889
32890 /* return error if TTY interface open */
32891- if (info->port.count)
32892+ if (atomic_read(&info->port.count))
32893 return -EBUSY;
32894
32895 switch (encoding)
32896@@ -3992,7 +3992,7 @@ static int hdlcdev_open(struct net_device *dev)
32897
32898 /* arbitrate between network and tty opens */
32899 spin_lock_irqsave(&info->netlock, flags);
32900- if (info->port.count != 0 || info->netcount != 0) {
32901+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
32902 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
32903 spin_unlock_irqrestore(&info->netlock, flags);
32904 return -EBUSY;
32905@@ -4081,7 +4081,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
32906 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
32907
32908 /* return error if TTY interface open */
32909- if (info->port.count)
32910+ if (atomic_read(&info->port.count))
32911 return -EBUSY;
32912
32913 if (cmd != SIOCWANDEV)
32914diff --git a/drivers/char/random.c b/drivers/char/random.c
32915index 85e81ec..bce8b97 100644
32916--- a/drivers/char/random.c
32917+++ b/drivers/char/random.c
32918@@ -272,8 +272,13 @@
32919 /*
32920 * Configuration information
32921 */
32922+#ifdef CONFIG_GRKERNSEC_RANDNET
32923+#define INPUT_POOL_WORDS 512
32924+#define OUTPUT_POOL_WORDS 128
32925+#else
32926 #define INPUT_POOL_WORDS 128
32927 #define OUTPUT_POOL_WORDS 32
32928+#endif
32929 #define SEC_XFER_SIZE 512
32930 #define EXTRACT_SIZE 10
32931
32932@@ -313,10 +318,17 @@ static struct poolinfo {
32933 int poolwords;
32934 int tap1, tap2, tap3, tap4, tap5;
32935 } poolinfo_table[] = {
32936+#ifdef CONFIG_GRKERNSEC_RANDNET
32937+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
32938+ { 512, 411, 308, 208, 104, 1 },
32939+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
32940+ { 128, 103, 76, 51, 25, 1 },
32941+#else
32942 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
32943 { 128, 103, 76, 51, 25, 1 },
32944 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
32945 { 32, 26, 20, 14, 7, 1 },
32946+#endif
32947 #if 0
32948 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
32949 { 2048, 1638, 1231, 819, 411, 1 },
32950@@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
32951 input_rotate += i ? 7 : 14;
32952 }
32953
32954- ACCESS_ONCE(r->input_rotate) = input_rotate;
32955- ACCESS_ONCE(r->add_ptr) = i;
32956+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
32957+ ACCESS_ONCE_RW(r->add_ptr) = i;
32958 smp_wmb();
32959
32960 if (out)
32961@@ -1020,7 +1032,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
32962
32963 extract_buf(r, tmp);
32964 i = min_t(int, nbytes, EXTRACT_SIZE);
32965- if (copy_to_user(buf, tmp, i)) {
32966+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
32967 ret = -EFAULT;
32968 break;
32969 }
32970@@ -1356,7 +1368,7 @@ EXPORT_SYMBOL(generate_random_uuid);
32971 #include <linux/sysctl.h>
32972
32973 static int min_read_thresh = 8, min_write_thresh;
32974-static int max_read_thresh = INPUT_POOL_WORDS * 32;
32975+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
32976 static int max_write_thresh = INPUT_POOL_WORDS * 32;
32977 static char sysctl_bootid[16];
32978
32979diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
32980index d780295..b29f3a8 100644
32981--- a/drivers/char/sonypi.c
32982+++ b/drivers/char/sonypi.c
32983@@ -54,6 +54,7 @@
32984
32985 #include <asm/uaccess.h>
32986 #include <asm/io.h>
32987+#include <asm/local.h>
32988
32989 #include <linux/sonypi.h>
32990
32991@@ -490,7 +491,7 @@ static struct sonypi_device {
32992 spinlock_t fifo_lock;
32993 wait_queue_head_t fifo_proc_list;
32994 struct fasync_struct *fifo_async;
32995- int open_count;
32996+ local_t open_count;
32997 int model;
32998 struct input_dev *input_jog_dev;
32999 struct input_dev *input_key_dev;
33000@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
33001 static int sonypi_misc_release(struct inode *inode, struct file *file)
33002 {
33003 mutex_lock(&sonypi_device.lock);
33004- sonypi_device.open_count--;
33005+ local_dec(&sonypi_device.open_count);
33006 mutex_unlock(&sonypi_device.lock);
33007 return 0;
33008 }
33009@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
33010 {
33011 mutex_lock(&sonypi_device.lock);
33012 /* Flush input queue on first open */
33013- if (!sonypi_device.open_count)
33014+ if (!local_read(&sonypi_device.open_count))
33015 kfifo_reset(&sonypi_device.fifo);
33016- sonypi_device.open_count++;
33017+ local_inc(&sonypi_device.open_count);
33018 mutex_unlock(&sonypi_device.lock);
33019
33020 return 0;
33021diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
33022index 93211df..c7805f7 100644
33023--- a/drivers/char/tpm/tpm.c
33024+++ b/drivers/char/tpm/tpm.c
33025@@ -410,7 +410,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
33026 chip->vendor.req_complete_val)
33027 goto out_recv;
33028
33029- if ((status == chip->vendor.req_canceled)) {
33030+ if (status == chip->vendor.req_canceled) {
33031 dev_err(chip->dev, "Operation Canceled\n");
33032 rc = -ECANCELED;
33033 goto out;
33034diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
33035index 56051d0..11cf3b7 100644
33036--- a/drivers/char/tpm/tpm_acpi.c
33037+++ b/drivers/char/tpm/tpm_acpi.c
33038@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
33039 virt = acpi_os_map_memory(start, len);
33040 if (!virt) {
33041 kfree(log->bios_event_log);
33042+ log->bios_event_log = NULL;
33043 printk("%s: ERROR - Unable to map memory\n", __func__);
33044 return -EIO;
33045 }
33046
33047- memcpy_fromio(log->bios_event_log, virt, len);
33048+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
33049
33050 acpi_os_unmap_memory(virt, len);
33051 return 0;
33052diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
33053index 84ddc55..1d32f1e 100644
33054--- a/drivers/char/tpm/tpm_eventlog.c
33055+++ b/drivers/char/tpm/tpm_eventlog.c
33056@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
33057 event = addr;
33058
33059 if ((event->event_type == 0 && event->event_size == 0) ||
33060- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
33061+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
33062 return NULL;
33063
33064 return addr;
33065@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
33066 return NULL;
33067
33068 if ((event->event_type == 0 && event->event_size == 0) ||
33069- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
33070+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
33071 return NULL;
33072
33073 (*pos)++;
33074@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
33075 int i;
33076
33077 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
33078- seq_putc(m, data[i]);
33079+ if (!seq_putc(m, data[i]))
33080+ return -EFAULT;
33081
33082 return 0;
33083 }
33084diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
33085index ee4dbea..69c817b 100644
33086--- a/drivers/char/virtio_console.c
33087+++ b/drivers/char/virtio_console.c
33088@@ -681,7 +681,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
33089 if (to_user) {
33090 ssize_t ret;
33091
33092- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
33093+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
33094 if (ret)
33095 return -EFAULT;
33096 } else {
33097@@ -780,7 +780,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
33098 if (!port_has_data(port) && !port->host_connected)
33099 return 0;
33100
33101- return fill_readbuf(port, ubuf, count, true);
33102+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
33103 }
33104
33105 static int wait_port_writable(struct port *port, bool nonblock)
33106diff --git a/drivers/clocksource/arm_generic.c b/drivers/clocksource/arm_generic.c
33107index 8ae1a61..9c00613 100644
33108--- a/drivers/clocksource/arm_generic.c
33109+++ b/drivers/clocksource/arm_generic.c
33110@@ -181,7 +181,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
33111 return NOTIFY_OK;
33112 }
33113
33114-static struct notifier_block __cpuinitdata arch_timer_cpu_nb = {
33115+static struct notifier_block arch_timer_cpu_nb = {
33116 .notifier_call = arch_timer_cpu_notify,
33117 };
33118
33119diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
33120index 1f93dbd..edf95ff 100644
33121--- a/drivers/cpufreq/cpufreq.c
33122+++ b/drivers/cpufreq/cpufreq.c
33123@@ -1843,7 +1843,7 @@ static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb,
33124 return NOTIFY_OK;
33125 }
33126
33127-static struct notifier_block __refdata cpufreq_cpu_notifier = {
33128+static struct notifier_block cpufreq_cpu_notifier = {
33129 .notifier_call = cpufreq_cpu_callback,
33130 };
33131
33132diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
33133index 9d7732b..0b1a793 100644
33134--- a/drivers/cpufreq/cpufreq_stats.c
33135+++ b/drivers/cpufreq/cpufreq_stats.c
33136@@ -340,7 +340,7 @@ static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
33137 }
33138
33139 /* priority=1 so this will get called before cpufreq_remove_dev */
33140-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
33141+static struct notifier_block cpufreq_stat_cpu_notifier = {
33142 .notifier_call = cpufreq_stat_cpu_callback,
33143 .priority = 1,
33144 };
33145diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
33146index 3315e4b..fc38316 100644
33147--- a/drivers/dma/sh/shdma.c
33148+++ b/drivers/dma/sh/shdma.c
33149@@ -476,7 +476,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
33150 return ret;
33151 }
33152
33153-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
33154+static struct notifier_block sh_dmae_nmi_notifier = {
33155 .notifier_call = sh_dmae_nmi_handler,
33156
33157 /* Run before NMI debug handler and KGDB */
33158diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
33159index 0056c4d..725934f 100644
33160--- a/drivers/edac/edac_pci_sysfs.c
33161+++ b/drivers/edac/edac_pci_sysfs.c
33162@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
33163 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
33164 static int edac_pci_poll_msec = 1000; /* one second workq period */
33165
33166-static atomic_t pci_parity_count = ATOMIC_INIT(0);
33167-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
33168+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
33169+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
33170
33171 static struct kobject *edac_pci_top_main_kobj;
33172 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
33173@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33174 edac_printk(KERN_CRIT, EDAC_PCI,
33175 "Signaled System Error on %s\n",
33176 pci_name(dev));
33177- atomic_inc(&pci_nonparity_count);
33178+ atomic_inc_unchecked(&pci_nonparity_count);
33179 }
33180
33181 if (status & (PCI_STATUS_PARITY)) {
33182@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33183 "Master Data Parity Error on %s\n",
33184 pci_name(dev));
33185
33186- atomic_inc(&pci_parity_count);
33187+ atomic_inc_unchecked(&pci_parity_count);
33188 }
33189
33190 if (status & (PCI_STATUS_DETECTED_PARITY)) {
33191@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33192 "Detected Parity Error on %s\n",
33193 pci_name(dev));
33194
33195- atomic_inc(&pci_parity_count);
33196+ atomic_inc_unchecked(&pci_parity_count);
33197 }
33198 }
33199
33200@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33201 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
33202 "Signaled System Error on %s\n",
33203 pci_name(dev));
33204- atomic_inc(&pci_nonparity_count);
33205+ atomic_inc_unchecked(&pci_nonparity_count);
33206 }
33207
33208 if (status & (PCI_STATUS_PARITY)) {
33209@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33210 "Master Data Parity Error on "
33211 "%s\n", pci_name(dev));
33212
33213- atomic_inc(&pci_parity_count);
33214+ atomic_inc_unchecked(&pci_parity_count);
33215 }
33216
33217 if (status & (PCI_STATUS_DETECTED_PARITY)) {
33218@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33219 "Detected Parity Error on %s\n",
33220 pci_name(dev));
33221
33222- atomic_inc(&pci_parity_count);
33223+ atomic_inc_unchecked(&pci_parity_count);
33224 }
33225 }
33226 }
33227@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
33228 if (!check_pci_errors)
33229 return;
33230
33231- before_count = atomic_read(&pci_parity_count);
33232+ before_count = atomic_read_unchecked(&pci_parity_count);
33233
33234 /* scan all PCI devices looking for a Parity Error on devices and
33235 * bridges.
33236@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
33237 /* Only if operator has selected panic on PCI Error */
33238 if (edac_pci_get_panic_on_pe()) {
33239 /* If the count is different 'after' from 'before' */
33240- if (before_count != atomic_read(&pci_parity_count))
33241+ if (before_count != atomic_read_unchecked(&pci_parity_count))
33242 panic("EDAC: PCI Parity Error");
33243 }
33244 }
33245diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
33246index 6796799..99e8377 100644
33247--- a/drivers/edac/mce_amd.h
33248+++ b/drivers/edac/mce_amd.h
33249@@ -78,7 +78,7 @@ extern const char * const ii_msgs[];
33250 struct amd_decoder_ops {
33251 bool (*mc0_mce)(u16, u8);
33252 bool (*mc1_mce)(u16, u8);
33253-};
33254+} __no_const;
33255
33256 void amd_report_gart_errors(bool);
33257 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
33258diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
33259index 57ea7f4..789e3c3 100644
33260--- a/drivers/firewire/core-card.c
33261+++ b/drivers/firewire/core-card.c
33262@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
33263
33264 void fw_core_remove_card(struct fw_card *card)
33265 {
33266- struct fw_card_driver dummy_driver = dummy_driver_template;
33267+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
33268
33269 card->driver->update_phy_reg(card, 4,
33270 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
33271diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
33272index f8d2287..5aaf4db 100644
33273--- a/drivers/firewire/core-cdev.c
33274+++ b/drivers/firewire/core-cdev.c
33275@@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
33276 int ret;
33277
33278 if ((request->channels == 0 && request->bandwidth == 0) ||
33279- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
33280- request->bandwidth < 0)
33281+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
33282 return -EINVAL;
33283
33284 r = kmalloc(sizeof(*r), GFP_KERNEL);
33285diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
33286index 28a94c7..58da63a 100644
33287--- a/drivers/firewire/core-transaction.c
33288+++ b/drivers/firewire/core-transaction.c
33289@@ -38,6 +38,7 @@
33290 #include <linux/timer.h>
33291 #include <linux/types.h>
33292 #include <linux/workqueue.h>
33293+#include <linux/sched.h>
33294
33295 #include <asm/byteorder.h>
33296
33297diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
33298index 515a42c..5ecf3ba 100644
33299--- a/drivers/firewire/core.h
33300+++ b/drivers/firewire/core.h
33301@@ -111,6 +111,7 @@ struct fw_card_driver {
33302
33303 int (*stop_iso)(struct fw_iso_context *ctx);
33304 };
33305+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
33306
33307 void fw_card_initialize(struct fw_card *card,
33308 const struct fw_card_driver *driver, struct device *device);
33309diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
33310index 982f1f5..d21e5da 100644
33311--- a/drivers/firmware/dmi_scan.c
33312+++ b/drivers/firmware/dmi_scan.c
33313@@ -491,11 +491,6 @@ void __init dmi_scan_machine(void)
33314 }
33315 }
33316 else {
33317- /*
33318- * no iounmap() for that ioremap(); it would be a no-op, but
33319- * it's so early in setup that sucker gets confused into doing
33320- * what it shouldn't if we actually call it.
33321- */
33322 p = dmi_ioremap(0xF0000, 0x10000);
33323 if (p == NULL)
33324 goto error;
33325@@ -770,7 +765,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
33326 if (buf == NULL)
33327 return -1;
33328
33329- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
33330+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
33331
33332 iounmap(buf);
33333 return 0;
33334diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
33335index f5596db..9355ce6 100644
33336--- a/drivers/firmware/efivars.c
33337+++ b/drivers/firmware/efivars.c
33338@@ -132,7 +132,7 @@ struct efivar_attribute {
33339 };
33340
33341 static struct efivars __efivars;
33342-static struct efivar_operations ops;
33343+static efivar_operations_no_const ops __read_only;
33344
33345 #define PSTORE_EFI_ATTRIBUTES \
33346 (EFI_VARIABLE_NON_VOLATILE | \
33347diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
33348index 9902732..64b62dd 100644
33349--- a/drivers/gpio/gpio-vr41xx.c
33350+++ b/drivers/gpio/gpio-vr41xx.c
33351@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
33352 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
33353 maskl, pendl, maskh, pendh);
33354
33355- atomic_inc(&irq_err_count);
33356+ atomic_inc_unchecked(&irq_err_count);
33357
33358 return -EINVAL;
33359 }
33360diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
33361index 7b2d378..cc947ea 100644
33362--- a/drivers/gpu/drm/drm_crtc_helper.c
33363+++ b/drivers/gpu/drm/drm_crtc_helper.c
33364@@ -319,7 +319,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
33365 struct drm_crtc *tmp;
33366 int crtc_mask = 1;
33367
33368- WARN(!crtc, "checking null crtc?\n");
33369+ BUG_ON(!crtc);
33370
33371 dev = crtc->dev;
33372
33373diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
33374index be174ca..0bcbb71 100644
33375--- a/drivers/gpu/drm/drm_drv.c
33376+++ b/drivers/gpu/drm/drm_drv.c
33377@@ -307,7 +307,7 @@ module_exit(drm_core_exit);
33378 /**
33379 * Copy and IOCTL return string to user space
33380 */
33381-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
33382+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
33383 {
33384 int len;
33385
33386@@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
33387 return -ENODEV;
33388
33389 atomic_inc(&dev->ioctl_count);
33390- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
33391+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
33392 ++file_priv->ioctl_count;
33393
33394 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
33395diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
33396index 133b413..fd68225 100644
33397--- a/drivers/gpu/drm/drm_fops.c
33398+++ b/drivers/gpu/drm/drm_fops.c
33399@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
33400 }
33401
33402 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
33403- atomic_set(&dev->counts[i], 0);
33404+ atomic_set_unchecked(&dev->counts[i], 0);
33405
33406 dev->sigdata.lock = NULL;
33407
33408@@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
33409 if (drm_device_is_unplugged(dev))
33410 return -ENODEV;
33411
33412- if (!dev->open_count++)
33413+ if (local_inc_return(&dev->open_count) == 1)
33414 need_setup = 1;
33415 mutex_lock(&dev->struct_mutex);
33416 old_mapping = dev->dev_mapping;
33417@@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
33418 retcode = drm_open_helper(inode, filp, dev);
33419 if (retcode)
33420 goto err_undo;
33421- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
33422+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
33423 if (need_setup) {
33424 retcode = drm_setup(dev);
33425 if (retcode)
33426@@ -164,7 +164,7 @@ err_undo:
33427 iput(container_of(dev->dev_mapping, struct inode, i_data));
33428 dev->dev_mapping = old_mapping;
33429 mutex_unlock(&dev->struct_mutex);
33430- dev->open_count--;
33431+ local_dec(&dev->open_count);
33432 return retcode;
33433 }
33434 EXPORT_SYMBOL(drm_open);
33435@@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
33436
33437 mutex_lock(&drm_global_mutex);
33438
33439- DRM_DEBUG("open_count = %d\n", dev->open_count);
33440+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
33441
33442 if (dev->driver->preclose)
33443 dev->driver->preclose(dev, file_priv);
33444@@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
33445 * Begin inline drm_release
33446 */
33447
33448- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
33449+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
33450 task_pid_nr(current),
33451 (long)old_encode_dev(file_priv->minor->device),
33452- dev->open_count);
33453+ local_read(&dev->open_count));
33454
33455 /* Release any auth tokens that might point to this file_priv,
33456 (do that under the drm_global_mutex) */
33457@@ -547,8 +547,8 @@ int drm_release(struct inode *inode, struct file *filp)
33458 * End inline drm_release
33459 */
33460
33461- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
33462- if (!--dev->open_count) {
33463+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
33464+ if (local_dec_and_test(&dev->open_count)) {
33465 if (atomic_read(&dev->ioctl_count)) {
33466 DRM_ERROR("Device busy: %d\n",
33467 atomic_read(&dev->ioctl_count));
33468diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
33469index f731116..629842c 100644
33470--- a/drivers/gpu/drm/drm_global.c
33471+++ b/drivers/gpu/drm/drm_global.c
33472@@ -36,7 +36,7 @@
33473 struct drm_global_item {
33474 struct mutex mutex;
33475 void *object;
33476- int refcount;
33477+ atomic_t refcount;
33478 };
33479
33480 static struct drm_global_item glob[DRM_GLOBAL_NUM];
33481@@ -49,7 +49,7 @@ void drm_global_init(void)
33482 struct drm_global_item *item = &glob[i];
33483 mutex_init(&item->mutex);
33484 item->object = NULL;
33485- item->refcount = 0;
33486+ atomic_set(&item->refcount, 0);
33487 }
33488 }
33489
33490@@ -59,7 +59,7 @@ void drm_global_release(void)
33491 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
33492 struct drm_global_item *item = &glob[i];
33493 BUG_ON(item->object != NULL);
33494- BUG_ON(item->refcount != 0);
33495+ BUG_ON(atomic_read(&item->refcount) != 0);
33496 }
33497 }
33498
33499@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
33500 void *object;
33501
33502 mutex_lock(&item->mutex);
33503- if (item->refcount == 0) {
33504+ if (atomic_read(&item->refcount) == 0) {
33505 item->object = kzalloc(ref->size, GFP_KERNEL);
33506 if (unlikely(item->object == NULL)) {
33507 ret = -ENOMEM;
33508@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
33509 goto out_err;
33510
33511 }
33512- ++item->refcount;
33513+ atomic_inc(&item->refcount);
33514 ref->object = item->object;
33515 object = item->object;
33516 mutex_unlock(&item->mutex);
33517@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
33518 struct drm_global_item *item = &glob[ref->global_type];
33519
33520 mutex_lock(&item->mutex);
33521- BUG_ON(item->refcount == 0);
33522+ BUG_ON(atomic_read(&item->refcount) == 0);
33523 BUG_ON(ref->object != item->object);
33524- if (--item->refcount == 0) {
33525+ if (atomic_dec_and_test(&item->refcount)) {
33526 ref->release(ref);
33527 item->object = NULL;
33528 }
33529diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
33530index d4b20ce..77a8d41 100644
33531--- a/drivers/gpu/drm/drm_info.c
33532+++ b/drivers/gpu/drm/drm_info.c
33533@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
33534 struct drm_local_map *map;
33535 struct drm_map_list *r_list;
33536
33537- /* Hardcoded from _DRM_FRAME_BUFFER,
33538- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
33539- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
33540- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
33541+ static const char * const types[] = {
33542+ [_DRM_FRAME_BUFFER] = "FB",
33543+ [_DRM_REGISTERS] = "REG",
33544+ [_DRM_SHM] = "SHM",
33545+ [_DRM_AGP] = "AGP",
33546+ [_DRM_SCATTER_GATHER] = "SG",
33547+ [_DRM_CONSISTENT] = "PCI",
33548+ [_DRM_GEM] = "GEM" };
33549 const char *type;
33550 int i;
33551
33552@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
33553 map = r_list->map;
33554 if (!map)
33555 continue;
33556- if (map->type < 0 || map->type > 5)
33557+ if (map->type >= ARRAY_SIZE(types))
33558 type = "??";
33559 else
33560 type = types[map->type];
33561@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
33562 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
33563 vma->vm_flags & VM_LOCKED ? 'l' : '-',
33564 vma->vm_flags & VM_IO ? 'i' : '-',
33565+#ifdef CONFIG_GRKERNSEC_HIDESYM
33566+ 0);
33567+#else
33568 vma->vm_pgoff);
33569+#endif
33570
33571 #if defined(__i386__)
33572 pgprot = pgprot_val(vma->vm_page_prot);
33573diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
33574index 2f4c434..764794b 100644
33575--- a/drivers/gpu/drm/drm_ioc32.c
33576+++ b/drivers/gpu/drm/drm_ioc32.c
33577@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
33578 request = compat_alloc_user_space(nbytes);
33579 if (!access_ok(VERIFY_WRITE, request, nbytes))
33580 return -EFAULT;
33581- list = (struct drm_buf_desc *) (request + 1);
33582+ list = (struct drm_buf_desc __user *) (request + 1);
33583
33584 if (__put_user(count, &request->count)
33585 || __put_user(list, &request->list))
33586@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
33587 request = compat_alloc_user_space(nbytes);
33588 if (!access_ok(VERIFY_WRITE, request, nbytes))
33589 return -EFAULT;
33590- list = (struct drm_buf_pub *) (request + 1);
33591+ list = (struct drm_buf_pub __user *) (request + 1);
33592
33593 if (__put_user(count, &request->count)
33594 || __put_user(list, &request->list))
33595diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
33596index e77bd8b..1571b85 100644
33597--- a/drivers/gpu/drm/drm_ioctl.c
33598+++ b/drivers/gpu/drm/drm_ioctl.c
33599@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
33600 stats->data[i].value =
33601 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
33602 else
33603- stats->data[i].value = atomic_read(&dev->counts[i]);
33604+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
33605 stats->data[i].type = dev->types[i];
33606 }
33607
33608diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
33609index d752c96..fe08455 100644
33610--- a/drivers/gpu/drm/drm_lock.c
33611+++ b/drivers/gpu/drm/drm_lock.c
33612@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
33613 if (drm_lock_take(&master->lock, lock->context)) {
33614 master->lock.file_priv = file_priv;
33615 master->lock.lock_time = jiffies;
33616- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
33617+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
33618 break; /* Got lock */
33619 }
33620
33621@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
33622 return -EINVAL;
33623 }
33624
33625- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
33626+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
33627
33628 if (drm_lock_free(&master->lock, lock->context)) {
33629 /* FIXME: Should really bail out here. */
33630diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
33631index 200e104..59facda 100644
33632--- a/drivers/gpu/drm/drm_stub.c
33633+++ b/drivers/gpu/drm/drm_stub.c
33634@@ -516,7 +516,7 @@ void drm_unplug_dev(struct drm_device *dev)
33635
33636 drm_device_set_unplugged(dev);
33637
33638- if (dev->open_count == 0) {
33639+ if (local_read(&dev->open_count) == 0) {
33640 drm_put_dev(dev);
33641 }
33642 mutex_unlock(&drm_global_mutex);
33643diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
33644index 004ecdf..db1f6e0 100644
33645--- a/drivers/gpu/drm/i810/i810_dma.c
33646+++ b/drivers/gpu/drm/i810/i810_dma.c
33647@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
33648 dma->buflist[vertex->idx],
33649 vertex->discard, vertex->used);
33650
33651- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
33652- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
33653+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
33654+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
33655 sarea_priv->last_enqueue = dev_priv->counter - 1;
33656 sarea_priv->last_dispatch = (int)hw_status[5];
33657
33658@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
33659 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
33660 mc->last_render);
33661
33662- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
33663- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
33664+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
33665+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
33666 sarea_priv->last_enqueue = dev_priv->counter - 1;
33667 sarea_priv->last_dispatch = (int)hw_status[5];
33668
33669diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
33670index 6e0acad..93c8289 100644
33671--- a/drivers/gpu/drm/i810/i810_drv.h
33672+++ b/drivers/gpu/drm/i810/i810_drv.h
33673@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
33674 int page_flipping;
33675
33676 wait_queue_head_t irq_queue;
33677- atomic_t irq_received;
33678- atomic_t irq_emitted;
33679+ atomic_unchecked_t irq_received;
33680+ atomic_unchecked_t irq_emitted;
33681
33682 int front_offset;
33683 } drm_i810_private_t;
33684diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
33685index 9d4a2c2..32a119f 100644
33686--- a/drivers/gpu/drm/i915/i915_debugfs.c
33687+++ b/drivers/gpu/drm/i915/i915_debugfs.c
33688@@ -496,7 +496,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
33689 I915_READ(GTIMR));
33690 }
33691 seq_printf(m, "Interrupts received: %d\n",
33692- atomic_read(&dev_priv->irq_received));
33693+ atomic_read_unchecked(&dev_priv->irq_received));
33694 for_each_ring(ring, dev_priv, i) {
33695 if (IS_GEN6(dev) || IS_GEN7(dev)) {
33696 seq_printf(m,
33697diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
33698index 99daa89..84ebd44 100644
33699--- a/drivers/gpu/drm/i915/i915_dma.c
33700+++ b/drivers/gpu/drm/i915/i915_dma.c
33701@@ -1253,7 +1253,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
33702 bool can_switch;
33703
33704 spin_lock(&dev->count_lock);
33705- can_switch = (dev->open_count == 0);
33706+ can_switch = (local_read(&dev->open_count) == 0);
33707 spin_unlock(&dev->count_lock);
33708 return can_switch;
33709 }
33710diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
33711index 12ab3bd..b3bed3b 100644
33712--- a/drivers/gpu/drm/i915/i915_drv.h
33713+++ b/drivers/gpu/drm/i915/i915_drv.h
33714@@ -656,7 +656,7 @@ typedef struct drm_i915_private {
33715 drm_dma_handle_t *status_page_dmah;
33716 struct resource mch_res;
33717
33718- atomic_t irq_received;
33719+ atomic_unchecked_t irq_received;
33720
33721 /* protects the irq masks */
33722 spinlock_t irq_lock;
33723@@ -1102,7 +1102,7 @@ struct drm_i915_gem_object {
33724 * will be page flipped away on the next vblank. When it
33725 * reaches 0, dev_priv->pending_flip_queue will be woken up.
33726 */
33727- atomic_t pending_flip;
33728+ atomic_unchecked_t pending_flip;
33729 };
33730 #define to_gem_object(obj) (&((struct drm_i915_gem_object *)(obj))->base)
33731
33732@@ -1633,7 +1633,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
33733 struct drm_i915_private *dev_priv, unsigned port);
33734 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
33735 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
33736-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
33737+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
33738 {
33739 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
33740 }
33741diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
33742index 26d08bb..fccb984 100644
33743--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
33744+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
33745@@ -672,7 +672,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
33746 i915_gem_clflush_object(obj);
33747
33748 if (obj->base.pending_write_domain)
33749- flips |= atomic_read(&obj->pending_flip);
33750+ flips |= atomic_read_unchecked(&obj->pending_flip);
33751
33752 flush_domains |= obj->base.write_domain;
33753 }
33754@@ -703,9 +703,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
33755
33756 static int
33757 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
33758- int count)
33759+ unsigned int count)
33760 {
33761- int i;
33762+ unsigned int i;
33763
33764 for (i = 0; i < count; i++) {
33765 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
33766diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
33767index fe84338..a863190 100644
33768--- a/drivers/gpu/drm/i915/i915_irq.c
33769+++ b/drivers/gpu/drm/i915/i915_irq.c
33770@@ -535,7 +535,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
33771 u32 pipe_stats[I915_MAX_PIPES];
33772 bool blc_event;
33773
33774- atomic_inc(&dev_priv->irq_received);
33775+ atomic_inc_unchecked(&dev_priv->irq_received);
33776
33777 while (true) {
33778 iir = I915_READ(VLV_IIR);
33779@@ -688,7 +688,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
33780 irqreturn_t ret = IRQ_NONE;
33781 int i;
33782
33783- atomic_inc(&dev_priv->irq_received);
33784+ atomic_inc_unchecked(&dev_priv->irq_received);
33785
33786 /* disable master interrupt before clearing iir */
33787 de_ier = I915_READ(DEIER);
33788@@ -760,7 +760,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
33789 int ret = IRQ_NONE;
33790 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
33791
33792- atomic_inc(&dev_priv->irq_received);
33793+ atomic_inc_unchecked(&dev_priv->irq_received);
33794
33795 /* disable master interrupt before clearing iir */
33796 de_ier = I915_READ(DEIER);
33797@@ -1787,7 +1787,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
33798 {
33799 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33800
33801- atomic_set(&dev_priv->irq_received, 0);
33802+ atomic_set_unchecked(&dev_priv->irq_received, 0);
33803
33804 I915_WRITE(HWSTAM, 0xeffe);
33805
33806@@ -1813,7 +1813,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
33807 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33808 int pipe;
33809
33810- atomic_set(&dev_priv->irq_received, 0);
33811+ atomic_set_unchecked(&dev_priv->irq_received, 0);
33812
33813 /* VLV magic */
33814 I915_WRITE(VLV_IMR, 0);
33815@@ -2108,7 +2108,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
33816 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33817 int pipe;
33818
33819- atomic_set(&dev_priv->irq_received, 0);
33820+ atomic_set_unchecked(&dev_priv->irq_received, 0);
33821
33822 for_each_pipe(pipe)
33823 I915_WRITE(PIPESTAT(pipe), 0);
33824@@ -2159,7 +2159,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
33825 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
33826 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
33827
33828- atomic_inc(&dev_priv->irq_received);
33829+ atomic_inc_unchecked(&dev_priv->irq_received);
33830
33831 iir = I915_READ16(IIR);
33832 if (iir == 0)
33833@@ -2244,7 +2244,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
33834 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33835 int pipe;
33836
33837- atomic_set(&dev_priv->irq_received, 0);
33838+ atomic_set_unchecked(&dev_priv->irq_received, 0);
33839
33840 if (I915_HAS_HOTPLUG(dev)) {
33841 I915_WRITE(PORT_HOTPLUG_EN, 0);
33842@@ -2339,7 +2339,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
33843 };
33844 int pipe, ret = IRQ_NONE;
33845
33846- atomic_inc(&dev_priv->irq_received);
33847+ atomic_inc_unchecked(&dev_priv->irq_received);
33848
33849 iir = I915_READ(IIR);
33850 do {
33851@@ -2465,7 +2465,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
33852 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33853 int pipe;
33854
33855- atomic_set(&dev_priv->irq_received, 0);
33856+ atomic_set_unchecked(&dev_priv->irq_received, 0);
33857
33858 I915_WRITE(PORT_HOTPLUG_EN, 0);
33859 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
33860@@ -2572,7 +2572,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
33861 int irq_received;
33862 int ret = IRQ_NONE, pipe;
33863
33864- atomic_inc(&dev_priv->irq_received);
33865+ atomic_inc_unchecked(&dev_priv->irq_received);
33866
33867 iir = I915_READ(IIR);
33868
33869diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
33870index da1ad9c..10d368b 100644
33871--- a/drivers/gpu/drm/i915/intel_display.c
33872+++ b/drivers/gpu/drm/i915/intel_display.c
33873@@ -2244,7 +2244,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
33874
33875 wait_event(dev_priv->pending_flip_queue,
33876 atomic_read(&dev_priv->mm.wedged) ||
33877- atomic_read(&obj->pending_flip) == 0);
33878+ atomic_read_unchecked(&obj->pending_flip) == 0);
33879
33880 /* Big Hammer, we also need to ensure that any pending
33881 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
33882@@ -7109,8 +7109,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
33883
33884 obj = work->old_fb_obj;
33885
33886- atomic_clear_mask(1 << intel_crtc->plane,
33887- &obj->pending_flip.counter);
33888+ atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
33889 wake_up(&dev_priv->pending_flip_queue);
33890
33891 queue_work(dev_priv->wq, &work->work);
33892@@ -7477,7 +7476,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
33893 /* Block clients from rendering to the new back buffer until
33894 * the flip occurs and the object is no longer visible.
33895 */
33896- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33897+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33898 atomic_inc(&intel_crtc->unpin_work_count);
33899
33900 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
33901@@ -7494,7 +7493,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
33902
33903 cleanup_pending:
33904 atomic_dec(&intel_crtc->unpin_work_count);
33905- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33906+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33907 drm_gem_object_unreference(&work->old_fb_obj->base);
33908 drm_gem_object_unreference(&obj->base);
33909 mutex_unlock(&dev->struct_mutex);
33910diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
33911index 54558a0..2d97005 100644
33912--- a/drivers/gpu/drm/mga/mga_drv.h
33913+++ b/drivers/gpu/drm/mga/mga_drv.h
33914@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
33915 u32 clear_cmd;
33916 u32 maccess;
33917
33918- atomic_t vbl_received; /**< Number of vblanks received. */
33919+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
33920 wait_queue_head_t fence_queue;
33921- atomic_t last_fence_retired;
33922+ atomic_unchecked_t last_fence_retired;
33923 u32 next_fence_to_post;
33924
33925 unsigned int fb_cpp;
33926diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
33927index 598c281..60d590e 100644
33928--- a/drivers/gpu/drm/mga/mga_irq.c
33929+++ b/drivers/gpu/drm/mga/mga_irq.c
33930@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
33931 if (crtc != 0)
33932 return 0;
33933
33934- return atomic_read(&dev_priv->vbl_received);
33935+ return atomic_read_unchecked(&dev_priv->vbl_received);
33936 }
33937
33938
33939@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
33940 /* VBLANK interrupt */
33941 if (status & MGA_VLINEPEN) {
33942 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
33943- atomic_inc(&dev_priv->vbl_received);
33944+ atomic_inc_unchecked(&dev_priv->vbl_received);
33945 drm_handle_vblank(dev, 0);
33946 handled = 1;
33947 }
33948@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
33949 if ((prim_start & ~0x03) != (prim_end & ~0x03))
33950 MGA_WRITE(MGA_PRIMEND, prim_end);
33951
33952- atomic_inc(&dev_priv->last_fence_retired);
33953+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
33954 DRM_WAKEUP(&dev_priv->fence_queue);
33955 handled = 1;
33956 }
33957@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
33958 * using fences.
33959 */
33960 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
33961- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
33962+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
33963 - *sequence) <= (1 << 23)));
33964
33965 *sequence = cur_fence;
33966diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
33967index 865eddf..62c4cc3 100644
33968--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
33969+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
33970@@ -1015,7 +1015,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
33971 struct bit_table {
33972 const char id;
33973 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
33974-};
33975+} __no_const;
33976
33977 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
33978
33979diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
33980index aa89eb9..d45d38b 100644
33981--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
33982+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
33983@@ -80,7 +80,7 @@ struct nouveau_drm {
33984 struct drm_global_reference mem_global_ref;
33985 struct ttm_bo_global_ref bo_global_ref;
33986 struct ttm_bo_device bdev;
33987- atomic_t validate_sequence;
33988+ atomic_unchecked_t validate_sequence;
33989 int (*move)(struct nouveau_channel *,
33990 struct ttm_buffer_object *,
33991 struct ttm_mem_reg *, struct ttm_mem_reg *);
33992diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
33993index cdb83ac..27f0a16 100644
33994--- a/drivers/gpu/drm/nouveau/nouveau_fence.h
33995+++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
33996@@ -43,7 +43,7 @@ struct nouveau_fence_priv {
33997 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
33998 struct nouveau_channel *);
33999 u32 (*read)(struct nouveau_channel *);
34000-};
34001+} __no_const;
34002
34003 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
34004
34005diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
34006index 8bf695c..9fbc90a 100644
34007--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
34008+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
34009@@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
34010 int trycnt = 0;
34011 int ret, i;
34012
34013- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
34014+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
34015 retry:
34016 if (++trycnt > 100000) {
34017 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
34018diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
34019index 25d3495..d81aaf6 100644
34020--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
34021+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
34022@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
34023 bool can_switch;
34024
34025 spin_lock(&dev->count_lock);
34026- can_switch = (dev->open_count == 0);
34027+ can_switch = (local_read(&dev->open_count) == 0);
34028 spin_unlock(&dev->count_lock);
34029 return can_switch;
34030 }
34031diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
34032index d4660cf..70dbe65 100644
34033--- a/drivers/gpu/drm/r128/r128_cce.c
34034+++ b/drivers/gpu/drm/r128/r128_cce.c
34035@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
34036
34037 /* GH: Simple idle check.
34038 */
34039- atomic_set(&dev_priv->idle_count, 0);
34040+ atomic_set_unchecked(&dev_priv->idle_count, 0);
34041
34042 /* We don't support anything other than bus-mastering ring mode,
34043 * but the ring can be in either AGP or PCI space for the ring
34044diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
34045index 930c71b..499aded 100644
34046--- a/drivers/gpu/drm/r128/r128_drv.h
34047+++ b/drivers/gpu/drm/r128/r128_drv.h
34048@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
34049 int is_pci;
34050 unsigned long cce_buffers_offset;
34051
34052- atomic_t idle_count;
34053+ atomic_unchecked_t idle_count;
34054
34055 int page_flipping;
34056 int current_page;
34057 u32 crtc_offset;
34058 u32 crtc_offset_cntl;
34059
34060- atomic_t vbl_received;
34061+ atomic_unchecked_t vbl_received;
34062
34063 u32 color_fmt;
34064 unsigned int front_offset;
34065diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
34066index 2ea4f09..d391371 100644
34067--- a/drivers/gpu/drm/r128/r128_irq.c
34068+++ b/drivers/gpu/drm/r128/r128_irq.c
34069@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
34070 if (crtc != 0)
34071 return 0;
34072
34073- return atomic_read(&dev_priv->vbl_received);
34074+ return atomic_read_unchecked(&dev_priv->vbl_received);
34075 }
34076
34077 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
34078@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
34079 /* VBLANK interrupt */
34080 if (status & R128_CRTC_VBLANK_INT) {
34081 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
34082- atomic_inc(&dev_priv->vbl_received);
34083+ atomic_inc_unchecked(&dev_priv->vbl_received);
34084 drm_handle_vblank(dev, 0);
34085 return IRQ_HANDLED;
34086 }
34087diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
34088index 19bb7e6..de7e2a2 100644
34089--- a/drivers/gpu/drm/r128/r128_state.c
34090+++ b/drivers/gpu/drm/r128/r128_state.c
34091@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
34092
34093 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
34094 {
34095- if (atomic_read(&dev_priv->idle_count) == 0)
34096+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
34097 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
34098 else
34099- atomic_set(&dev_priv->idle_count, 0);
34100+ atomic_set_unchecked(&dev_priv->idle_count, 0);
34101 }
34102
34103 #endif
34104diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
34105index 5a82b6b..9e69c73 100644
34106--- a/drivers/gpu/drm/radeon/mkregtable.c
34107+++ b/drivers/gpu/drm/radeon/mkregtable.c
34108@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
34109 regex_t mask_rex;
34110 regmatch_t match[4];
34111 char buf[1024];
34112- size_t end;
34113+ long end;
34114 int len;
34115 int done = 0;
34116 int r;
34117 unsigned o;
34118 struct offset *offset;
34119 char last_reg_s[10];
34120- int last_reg;
34121+ unsigned long last_reg;
34122
34123 if (regcomp
34124 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
34125diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
34126index 0d6562b..a154330 100644
34127--- a/drivers/gpu/drm/radeon/radeon_device.c
34128+++ b/drivers/gpu/drm/radeon/radeon_device.c
34129@@ -969,7 +969,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
34130 bool can_switch;
34131
34132 spin_lock(&dev->count_lock);
34133- can_switch = (dev->open_count == 0);
34134+ can_switch = (local_read(&dev->open_count) == 0);
34135 spin_unlock(&dev->count_lock);
34136 return can_switch;
34137 }
34138diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
34139index e7fdf16..f4f6490 100644
34140--- a/drivers/gpu/drm/radeon/radeon_drv.h
34141+++ b/drivers/gpu/drm/radeon/radeon_drv.h
34142@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
34143
34144 /* SW interrupt */
34145 wait_queue_head_t swi_queue;
34146- atomic_t swi_emitted;
34147+ atomic_unchecked_t swi_emitted;
34148 int vblank_crtc;
34149 uint32_t irq_enable_reg;
34150 uint32_t r500_disp_irq_reg;
34151diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
34152index c180df8..cd80dd2d 100644
34153--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
34154+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
34155@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
34156 request = compat_alloc_user_space(sizeof(*request));
34157 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
34158 || __put_user(req32.param, &request->param)
34159- || __put_user((void __user *)(unsigned long)req32.value,
34160+ || __put_user((unsigned long)req32.value,
34161 &request->value))
34162 return -EFAULT;
34163
34164diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
34165index e771033..a0bc6b3 100644
34166--- a/drivers/gpu/drm/radeon/radeon_irq.c
34167+++ b/drivers/gpu/drm/radeon/radeon_irq.c
34168@@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
34169 unsigned int ret;
34170 RING_LOCALS;
34171
34172- atomic_inc(&dev_priv->swi_emitted);
34173- ret = atomic_read(&dev_priv->swi_emitted);
34174+ atomic_inc_unchecked(&dev_priv->swi_emitted);
34175+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
34176
34177 BEGIN_RING(4);
34178 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
34179@@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
34180 drm_radeon_private_t *dev_priv =
34181 (drm_radeon_private_t *) dev->dev_private;
34182
34183- atomic_set(&dev_priv->swi_emitted, 0);
34184+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
34185 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
34186
34187 dev->max_vblank_count = 0x001fffff;
34188diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
34189index 8e9057b..af6dacb 100644
34190--- a/drivers/gpu/drm/radeon/radeon_state.c
34191+++ b/drivers/gpu/drm/radeon/radeon_state.c
34192@@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
34193 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
34194 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
34195
34196- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
34197+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
34198 sarea_priv->nbox * sizeof(depth_boxes[0])))
34199 return -EFAULT;
34200
34201@@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
34202 {
34203 drm_radeon_private_t *dev_priv = dev->dev_private;
34204 drm_radeon_getparam_t *param = data;
34205- int value;
34206+ int value = 0;
34207
34208 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
34209
34210diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
34211index 93f760e..33d9839 100644
34212--- a/drivers/gpu/drm/radeon/radeon_ttm.c
34213+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
34214@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
34215 man->size = size >> PAGE_SHIFT;
34216 }
34217
34218-static struct vm_operations_struct radeon_ttm_vm_ops;
34219+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
34220 static const struct vm_operations_struct *ttm_vm_ops = NULL;
34221
34222 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
34223@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
34224 }
34225 if (unlikely(ttm_vm_ops == NULL)) {
34226 ttm_vm_ops = vma->vm_ops;
34227+ pax_open_kernel();
34228 radeon_ttm_vm_ops = *ttm_vm_ops;
34229 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
34230+ pax_close_kernel();
34231 }
34232 vma->vm_ops = &radeon_ttm_vm_ops;
34233 return 0;
34234diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
34235index 5706d2a..17aedaa 100644
34236--- a/drivers/gpu/drm/radeon/rs690.c
34237+++ b/drivers/gpu/drm/radeon/rs690.c
34238@@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
34239 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
34240 rdev->pm.sideport_bandwidth.full)
34241 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
34242- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
34243+ read_delay_latency.full = dfixed_const(800 * 1000);
34244 read_delay_latency.full = dfixed_div(read_delay_latency,
34245 rdev->pm.igp_sideport_mclk);
34246+ a.full = dfixed_const(370);
34247+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
34248 } else {
34249 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
34250 rdev->pm.k8_bandwidth.full)
34251diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
34252index bd2a3b4..122d9ad 100644
34253--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
34254+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
34255@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
34256 static int ttm_pool_mm_shrink(struct shrinker *shrink,
34257 struct shrink_control *sc)
34258 {
34259- static atomic_t start_pool = ATOMIC_INIT(0);
34260+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
34261 unsigned i;
34262- unsigned pool_offset = atomic_add_return(1, &start_pool);
34263+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
34264 struct ttm_page_pool *pool;
34265 int shrink_pages = sc->nr_to_scan;
34266
34267diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
34268index 893a650..6190d3b 100644
34269--- a/drivers/gpu/drm/via/via_drv.h
34270+++ b/drivers/gpu/drm/via/via_drv.h
34271@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
34272 typedef uint32_t maskarray_t[5];
34273
34274 typedef struct drm_via_irq {
34275- atomic_t irq_received;
34276+ atomic_unchecked_t irq_received;
34277 uint32_t pending_mask;
34278 uint32_t enable_mask;
34279 wait_queue_head_t irq_queue;
34280@@ -75,7 +75,7 @@ typedef struct drm_via_private {
34281 struct timeval last_vblank;
34282 int last_vblank_valid;
34283 unsigned usec_per_vblank;
34284- atomic_t vbl_received;
34285+ atomic_unchecked_t vbl_received;
34286 drm_via_state_t hc_state;
34287 char pci_buf[VIA_PCI_BUF_SIZE];
34288 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
34289diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
34290index ac98964..5dbf512 100644
34291--- a/drivers/gpu/drm/via/via_irq.c
34292+++ b/drivers/gpu/drm/via/via_irq.c
34293@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
34294 if (crtc != 0)
34295 return 0;
34296
34297- return atomic_read(&dev_priv->vbl_received);
34298+ return atomic_read_unchecked(&dev_priv->vbl_received);
34299 }
34300
34301 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
34302@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
34303
34304 status = VIA_READ(VIA_REG_INTERRUPT);
34305 if (status & VIA_IRQ_VBLANK_PENDING) {
34306- atomic_inc(&dev_priv->vbl_received);
34307- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
34308+ atomic_inc_unchecked(&dev_priv->vbl_received);
34309+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
34310 do_gettimeofday(&cur_vblank);
34311 if (dev_priv->last_vblank_valid) {
34312 dev_priv->usec_per_vblank =
34313@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
34314 dev_priv->last_vblank = cur_vblank;
34315 dev_priv->last_vblank_valid = 1;
34316 }
34317- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
34318+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
34319 DRM_DEBUG("US per vblank is: %u\n",
34320 dev_priv->usec_per_vblank);
34321 }
34322@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
34323
34324 for (i = 0; i < dev_priv->num_irqs; ++i) {
34325 if (status & cur_irq->pending_mask) {
34326- atomic_inc(&cur_irq->irq_received);
34327+ atomic_inc_unchecked(&cur_irq->irq_received);
34328 DRM_WAKEUP(&cur_irq->irq_queue);
34329 handled = 1;
34330 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
34331@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
34332 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
34333 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
34334 masks[irq][4]));
34335- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
34336+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
34337 } else {
34338 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
34339 (((cur_irq_sequence =
34340- atomic_read(&cur_irq->irq_received)) -
34341+ atomic_read_unchecked(&cur_irq->irq_received)) -
34342 *sequence) <= (1 << 23)));
34343 }
34344 *sequence = cur_irq_sequence;
34345@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
34346 }
34347
34348 for (i = 0; i < dev_priv->num_irqs; ++i) {
34349- atomic_set(&cur_irq->irq_received, 0);
34350+ atomic_set_unchecked(&cur_irq->irq_received, 0);
34351 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
34352 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
34353 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
34354@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
34355 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
34356 case VIA_IRQ_RELATIVE:
34357 irqwait->request.sequence +=
34358- atomic_read(&cur_irq->irq_received);
34359+ atomic_read_unchecked(&cur_irq->irq_received);
34360 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
34361 case VIA_IRQ_ABSOLUTE:
34362 break;
34363diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
34364index 13aeda7..4a952d1 100644
34365--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
34366+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
34367@@ -290,7 +290,7 @@ struct vmw_private {
34368 * Fencing and IRQs.
34369 */
34370
34371- atomic_t marker_seq;
34372+ atomic_unchecked_t marker_seq;
34373 wait_queue_head_t fence_queue;
34374 wait_queue_head_t fifo_queue;
34375 int fence_queue_waiters; /* Protected by hw_mutex */
34376diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
34377index 3eb1486..0a47ee9 100644
34378--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
34379+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
34380@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
34381 (unsigned int) min,
34382 (unsigned int) fifo->capabilities);
34383
34384- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
34385+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
34386 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
34387 vmw_marker_queue_init(&fifo->marker_queue);
34388 return vmw_fifo_send_fence(dev_priv, &dummy);
34389@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
34390 if (reserveable)
34391 iowrite32(bytes, fifo_mem +
34392 SVGA_FIFO_RESERVED);
34393- return fifo_mem + (next_cmd >> 2);
34394+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
34395 } else {
34396 need_bounce = true;
34397 }
34398@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
34399
34400 fm = vmw_fifo_reserve(dev_priv, bytes);
34401 if (unlikely(fm == NULL)) {
34402- *seqno = atomic_read(&dev_priv->marker_seq);
34403+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
34404 ret = -ENOMEM;
34405 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
34406 false, 3*HZ);
34407@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
34408 }
34409
34410 do {
34411- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
34412+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
34413 } while (*seqno == 0);
34414
34415 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
34416diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
34417index 4640adb..e1384ed 100644
34418--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
34419+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
34420@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
34421 * emitted. Then the fence is stale and signaled.
34422 */
34423
34424- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
34425+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
34426 > VMW_FENCE_WRAP);
34427
34428 return ret;
34429@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
34430
34431 if (fifo_idle)
34432 down_read(&fifo_state->rwsem);
34433- signal_seq = atomic_read(&dev_priv->marker_seq);
34434+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
34435 ret = 0;
34436
34437 for (;;) {
34438diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
34439index 8a8725c..afed796 100644
34440--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
34441+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
34442@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
34443 while (!vmw_lag_lt(queue, us)) {
34444 spin_lock(&queue->lock);
34445 if (list_empty(&queue->head))
34446- seqno = atomic_read(&dev_priv->marker_seq);
34447+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
34448 else {
34449 marker = list_first_entry(&queue->head,
34450 struct vmw_marker, head);
34451diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
34452index eb2ee11..6cc50ab 100644
34453--- a/drivers/hid/hid-core.c
34454+++ b/drivers/hid/hid-core.c
34455@@ -2240,7 +2240,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
34456
34457 int hid_add_device(struct hid_device *hdev)
34458 {
34459- static atomic_t id = ATOMIC_INIT(0);
34460+ static atomic_unchecked_t id = ATOMIC_INIT(0);
34461 int ret;
34462
34463 if (WARN_ON(hdev->status & HID_STAT_ADDED))
34464@@ -2274,7 +2274,7 @@ int hid_add_device(struct hid_device *hdev)
34465 /* XXX hack, any other cleaner solution after the driver core
34466 * is converted to allow more than 20 bytes as the device name? */
34467 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
34468- hdev->vendor, hdev->product, atomic_inc_return(&id));
34469+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
34470
34471 hid_debug_register(hdev, dev_name(&hdev->dev));
34472 ret = device_add(&hdev->dev);
34473diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
34474index eec3291..8ed706b 100644
34475--- a/drivers/hid/hid-wiimote-debug.c
34476+++ b/drivers/hid/hid-wiimote-debug.c
34477@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
34478 else if (size == 0)
34479 return -EIO;
34480
34481- if (copy_to_user(u, buf, size))
34482+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
34483 return -EFAULT;
34484
34485 *off += size;
34486diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
34487index 773a2f2..7ce08bc 100644
34488--- a/drivers/hv/channel.c
34489+++ b/drivers/hv/channel.c
34490@@ -394,8 +394,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
34491 int ret = 0;
34492 int t;
34493
34494- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
34495- atomic_inc(&vmbus_connection.next_gpadl_handle);
34496+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
34497+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
34498
34499 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
34500 if (ret)
34501diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
34502index 3648f8f..30ef30d 100644
34503--- a/drivers/hv/hv.c
34504+++ b/drivers/hv/hv.c
34505@@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
34506 u64 output_address = (output) ? virt_to_phys(output) : 0;
34507 u32 output_address_hi = output_address >> 32;
34508 u32 output_address_lo = output_address & 0xFFFFFFFF;
34509- void *hypercall_page = hv_context.hypercall_page;
34510+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
34511
34512 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
34513 "=a"(hv_status_lo) : "d" (control_hi),
34514diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
34515index d8d1fad..b91caf7 100644
34516--- a/drivers/hv/hyperv_vmbus.h
34517+++ b/drivers/hv/hyperv_vmbus.h
34518@@ -594,7 +594,7 @@ enum vmbus_connect_state {
34519 struct vmbus_connection {
34520 enum vmbus_connect_state conn_state;
34521
34522- atomic_t next_gpadl_handle;
34523+ atomic_unchecked_t next_gpadl_handle;
34524
34525 /*
34526 * Represents channel interrupts. Each bit position represents a
34527diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
34528index 8e1a9ec..4687821 100644
34529--- a/drivers/hv/vmbus_drv.c
34530+++ b/drivers/hv/vmbus_drv.c
34531@@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
34532 {
34533 int ret = 0;
34534
34535- static atomic_t device_num = ATOMIC_INIT(0);
34536+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
34537
34538 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
34539- atomic_inc_return(&device_num));
34540+ atomic_inc_return_unchecked(&device_num));
34541
34542 child_device_obj->device.bus = &hv_bus;
34543 child_device_obj->device.parent = &hv_acpi_dev->dev;
34544diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
34545index d64923d..72591e8 100644
34546--- a/drivers/hwmon/coretemp.c
34547+++ b/drivers/hwmon/coretemp.c
34548@@ -790,7 +790,7 @@ static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb,
34549 return NOTIFY_OK;
34550 }
34551
34552-static struct notifier_block coretemp_cpu_notifier __refdata = {
34553+static struct notifier_block coretemp_cpu_notifier = {
34554 .notifier_call = coretemp_cpu_callback,
34555 };
34556
34557diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
34558index 1c85d39..55ed3cf 100644
34559--- a/drivers/hwmon/sht15.c
34560+++ b/drivers/hwmon/sht15.c
34561@@ -169,7 +169,7 @@ struct sht15_data {
34562 int supply_uV;
34563 bool supply_uV_valid;
34564 struct work_struct update_supply_work;
34565- atomic_t interrupt_handled;
34566+ atomic_unchecked_t interrupt_handled;
34567 };
34568
34569 /**
34570@@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
34571 return ret;
34572
34573 gpio_direction_input(data->pdata->gpio_data);
34574- atomic_set(&data->interrupt_handled, 0);
34575+ atomic_set_unchecked(&data->interrupt_handled, 0);
34576
34577 enable_irq(gpio_to_irq(data->pdata->gpio_data));
34578 if (gpio_get_value(data->pdata->gpio_data) == 0) {
34579 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
34580 /* Only relevant if the interrupt hasn't occurred. */
34581- if (!atomic_read(&data->interrupt_handled))
34582+ if (!atomic_read_unchecked(&data->interrupt_handled))
34583 schedule_work(&data->read_work);
34584 }
34585 ret = wait_event_timeout(data->wait_queue,
34586@@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
34587
34588 /* First disable the interrupt */
34589 disable_irq_nosync(irq);
34590- atomic_inc(&data->interrupt_handled);
34591+ atomic_inc_unchecked(&data->interrupt_handled);
34592 /* Then schedule a reading work struct */
34593 if (data->state != SHT15_READING_NOTHING)
34594 schedule_work(&data->read_work);
34595@@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
34596 * If not, then start the interrupt again - care here as could
34597 * have gone low in meantime so verify it hasn't!
34598 */
34599- atomic_set(&data->interrupt_handled, 0);
34600+ atomic_set_unchecked(&data->interrupt_handled, 0);
34601 enable_irq(gpio_to_irq(data->pdata->gpio_data));
34602 /* If still not occurred or another handler was scheduled */
34603 if (gpio_get_value(data->pdata->gpio_data)
34604- || atomic_read(&data->interrupt_handled))
34605+ || atomic_read_unchecked(&data->interrupt_handled))
34606 return;
34607 }
34608
34609diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
34610index 76f157b..9c0db1b 100644
34611--- a/drivers/hwmon/via-cputemp.c
34612+++ b/drivers/hwmon/via-cputemp.c
34613@@ -296,7 +296,7 @@ static int __cpuinit via_cputemp_cpu_callback(struct notifier_block *nfb,
34614 return NOTIFY_OK;
34615 }
34616
34617-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
34618+static struct notifier_block via_cputemp_cpu_notifier = {
34619 .notifier_call = via_cputemp_cpu_callback,
34620 };
34621
34622diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
34623index 378fcb5..5e91fa8 100644
34624--- a/drivers/i2c/busses/i2c-amd756-s4882.c
34625+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
34626@@ -43,7 +43,7 @@
34627 extern struct i2c_adapter amd756_smbus;
34628
34629 static struct i2c_adapter *s4882_adapter;
34630-static struct i2c_algorithm *s4882_algo;
34631+static i2c_algorithm_no_const *s4882_algo;
34632
34633 /* Wrapper access functions for multiplexed SMBus */
34634 static DEFINE_MUTEX(amd756_lock);
34635diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
34636index 29015eb..af2d8e9 100644
34637--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
34638+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
34639@@ -41,7 +41,7 @@
34640 extern struct i2c_adapter *nforce2_smbus;
34641
34642 static struct i2c_adapter *s4985_adapter;
34643-static struct i2c_algorithm *s4985_algo;
34644+static i2c_algorithm_no_const *s4985_algo;
34645
34646 /* Wrapper access functions for multiplexed SMBus */
34647 static DEFINE_MUTEX(nforce2_lock);
34648diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
34649index 8126824..55a2798 100644
34650--- a/drivers/ide/ide-cd.c
34651+++ b/drivers/ide/ide-cd.c
34652@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
34653 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
34654 if ((unsigned long)buf & alignment
34655 || blk_rq_bytes(rq) & q->dma_pad_mask
34656- || object_is_on_stack(buf))
34657+ || object_starts_on_stack(buf))
34658 drive->dma = 0;
34659 }
34660 }
34661diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
34662index 394fea2..c833880 100644
34663--- a/drivers/infiniband/core/cm.c
34664+++ b/drivers/infiniband/core/cm.c
34665@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
34666
34667 struct cm_counter_group {
34668 struct kobject obj;
34669- atomic_long_t counter[CM_ATTR_COUNT];
34670+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
34671 };
34672
34673 struct cm_counter_attribute {
34674@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
34675 struct ib_mad_send_buf *msg = NULL;
34676 int ret;
34677
34678- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34679+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34680 counter[CM_REQ_COUNTER]);
34681
34682 /* Quick state check to discard duplicate REQs. */
34683@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
34684 if (!cm_id_priv)
34685 return;
34686
34687- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34688+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34689 counter[CM_REP_COUNTER]);
34690 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
34691 if (ret)
34692@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
34693 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
34694 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
34695 spin_unlock_irq(&cm_id_priv->lock);
34696- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34697+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34698 counter[CM_RTU_COUNTER]);
34699 goto out;
34700 }
34701@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
34702 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
34703 dreq_msg->local_comm_id);
34704 if (!cm_id_priv) {
34705- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34706+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34707 counter[CM_DREQ_COUNTER]);
34708 cm_issue_drep(work->port, work->mad_recv_wc);
34709 return -EINVAL;
34710@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
34711 case IB_CM_MRA_REP_RCVD:
34712 break;
34713 case IB_CM_TIMEWAIT:
34714- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34715+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34716 counter[CM_DREQ_COUNTER]);
34717 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
34718 goto unlock;
34719@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
34720 cm_free_msg(msg);
34721 goto deref;
34722 case IB_CM_DREQ_RCVD:
34723- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34724+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34725 counter[CM_DREQ_COUNTER]);
34726 goto unlock;
34727 default:
34728@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
34729 ib_modify_mad(cm_id_priv->av.port->mad_agent,
34730 cm_id_priv->msg, timeout)) {
34731 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
34732- atomic_long_inc(&work->port->
34733+ atomic_long_inc_unchecked(&work->port->
34734 counter_group[CM_RECV_DUPLICATES].
34735 counter[CM_MRA_COUNTER]);
34736 goto out;
34737@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
34738 break;
34739 case IB_CM_MRA_REQ_RCVD:
34740 case IB_CM_MRA_REP_RCVD:
34741- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34742+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34743 counter[CM_MRA_COUNTER]);
34744 /* fall through */
34745 default:
34746@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
34747 case IB_CM_LAP_IDLE:
34748 break;
34749 case IB_CM_MRA_LAP_SENT:
34750- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34751+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34752 counter[CM_LAP_COUNTER]);
34753 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
34754 goto unlock;
34755@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
34756 cm_free_msg(msg);
34757 goto deref;
34758 case IB_CM_LAP_RCVD:
34759- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34760+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34761 counter[CM_LAP_COUNTER]);
34762 goto unlock;
34763 default:
34764@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
34765 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
34766 if (cur_cm_id_priv) {
34767 spin_unlock_irq(&cm.lock);
34768- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34769+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34770 counter[CM_SIDR_REQ_COUNTER]);
34771 goto out; /* Duplicate message. */
34772 }
34773@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
34774 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
34775 msg->retries = 1;
34776
34777- atomic_long_add(1 + msg->retries,
34778+ atomic_long_add_unchecked(1 + msg->retries,
34779 &port->counter_group[CM_XMIT].counter[attr_index]);
34780 if (msg->retries)
34781- atomic_long_add(msg->retries,
34782+ atomic_long_add_unchecked(msg->retries,
34783 &port->counter_group[CM_XMIT_RETRIES].
34784 counter[attr_index]);
34785
34786@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
34787 }
34788
34789 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
34790- atomic_long_inc(&port->counter_group[CM_RECV].
34791+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
34792 counter[attr_id - CM_ATTR_ID_OFFSET]);
34793
34794 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
34795@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
34796 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
34797
34798 return sprintf(buf, "%ld\n",
34799- atomic_long_read(&group->counter[cm_attr->index]));
34800+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
34801 }
34802
34803 static const struct sysfs_ops cm_counter_ops = {
34804diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
34805index 176c8f9..2627b62 100644
34806--- a/drivers/infiniband/core/fmr_pool.c
34807+++ b/drivers/infiniband/core/fmr_pool.c
34808@@ -98,8 +98,8 @@ struct ib_fmr_pool {
34809
34810 struct task_struct *thread;
34811
34812- atomic_t req_ser;
34813- atomic_t flush_ser;
34814+ atomic_unchecked_t req_ser;
34815+ atomic_unchecked_t flush_ser;
34816
34817 wait_queue_head_t force_wait;
34818 };
34819@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
34820 struct ib_fmr_pool *pool = pool_ptr;
34821
34822 do {
34823- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
34824+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
34825 ib_fmr_batch_release(pool);
34826
34827- atomic_inc(&pool->flush_ser);
34828+ atomic_inc_unchecked(&pool->flush_ser);
34829 wake_up_interruptible(&pool->force_wait);
34830
34831 if (pool->flush_function)
34832@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
34833 }
34834
34835 set_current_state(TASK_INTERRUPTIBLE);
34836- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
34837+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
34838 !kthread_should_stop())
34839 schedule();
34840 __set_current_state(TASK_RUNNING);
34841@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
34842 pool->dirty_watermark = params->dirty_watermark;
34843 pool->dirty_len = 0;
34844 spin_lock_init(&pool->pool_lock);
34845- atomic_set(&pool->req_ser, 0);
34846- atomic_set(&pool->flush_ser, 0);
34847+ atomic_set_unchecked(&pool->req_ser, 0);
34848+ atomic_set_unchecked(&pool->flush_ser, 0);
34849 init_waitqueue_head(&pool->force_wait);
34850
34851 pool->thread = kthread_run(ib_fmr_cleanup_thread,
34852@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
34853 }
34854 spin_unlock_irq(&pool->pool_lock);
34855
34856- serial = atomic_inc_return(&pool->req_ser);
34857+ serial = atomic_inc_return_unchecked(&pool->req_ser);
34858 wake_up_process(pool->thread);
34859
34860 if (wait_event_interruptible(pool->force_wait,
34861- atomic_read(&pool->flush_ser) - serial >= 0))
34862+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
34863 return -EINTR;
34864
34865 return 0;
34866@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
34867 } else {
34868 list_add_tail(&fmr->list, &pool->dirty_list);
34869 if (++pool->dirty_len >= pool->dirty_watermark) {
34870- atomic_inc(&pool->req_ser);
34871+ atomic_inc_unchecked(&pool->req_ser);
34872 wake_up_process(pool->thread);
34873 }
34874 }
34875diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
34876index afd8179..598063f 100644
34877--- a/drivers/infiniband/hw/cxgb4/mem.c
34878+++ b/drivers/infiniband/hw/cxgb4/mem.c
34879@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
34880 int err;
34881 struct fw_ri_tpte tpt;
34882 u32 stag_idx;
34883- static atomic_t key;
34884+ static atomic_unchecked_t key;
34885
34886 if (c4iw_fatal_error(rdev))
34887 return -EIO;
34888@@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
34889 if (rdev->stats.stag.cur > rdev->stats.stag.max)
34890 rdev->stats.stag.max = rdev->stats.stag.cur;
34891 mutex_unlock(&rdev->stats.lock);
34892- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
34893+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
34894 }
34895 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
34896 __func__, stag_state, type, pdid, stag_idx);
34897diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
34898index 79b3dbc..96e5fcc 100644
34899--- a/drivers/infiniband/hw/ipath/ipath_rc.c
34900+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
34901@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
34902 struct ib_atomic_eth *ateth;
34903 struct ipath_ack_entry *e;
34904 u64 vaddr;
34905- atomic64_t *maddr;
34906+ atomic64_unchecked_t *maddr;
34907 u64 sdata;
34908 u32 rkey;
34909 u8 next;
34910@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
34911 IB_ACCESS_REMOTE_ATOMIC)))
34912 goto nack_acc_unlck;
34913 /* Perform atomic OP and save result. */
34914- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
34915+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
34916 sdata = be64_to_cpu(ateth->swap_data);
34917 e = &qp->s_ack_queue[qp->r_head_ack_queue];
34918 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
34919- (u64) atomic64_add_return(sdata, maddr) - sdata :
34920+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
34921 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
34922 be64_to_cpu(ateth->compare_data),
34923 sdata);
34924diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
34925index 1f95bba..9530f87 100644
34926--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
34927+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
34928@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
34929 unsigned long flags;
34930 struct ib_wc wc;
34931 u64 sdata;
34932- atomic64_t *maddr;
34933+ atomic64_unchecked_t *maddr;
34934 enum ib_wc_status send_status;
34935
34936 /*
34937@@ -382,11 +382,11 @@ again:
34938 IB_ACCESS_REMOTE_ATOMIC)))
34939 goto acc_err;
34940 /* Perform atomic OP and save result. */
34941- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
34942+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
34943 sdata = wqe->wr.wr.atomic.compare_add;
34944 *(u64 *) sqp->s_sge.sge.vaddr =
34945 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
34946- (u64) atomic64_add_return(sdata, maddr) - sdata :
34947+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
34948 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
34949 sdata, wqe->wr.wr.atomic.swap);
34950 goto send_comp;
34951diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
34952index 5b152a3..c1f3e83 100644
34953--- a/drivers/infiniband/hw/nes/nes.c
34954+++ b/drivers/infiniband/hw/nes/nes.c
34955@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
34956 LIST_HEAD(nes_adapter_list);
34957 static LIST_HEAD(nes_dev_list);
34958
34959-atomic_t qps_destroyed;
34960+atomic_unchecked_t qps_destroyed;
34961
34962 static unsigned int ee_flsh_adapter;
34963 static unsigned int sysfs_nonidx_addr;
34964@@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
34965 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
34966 struct nes_adapter *nesadapter = nesdev->nesadapter;
34967
34968- atomic_inc(&qps_destroyed);
34969+ atomic_inc_unchecked(&qps_destroyed);
34970
34971 /* Free the control structures */
34972
34973diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
34974index 33cc589..3bd6538 100644
34975--- a/drivers/infiniband/hw/nes/nes.h
34976+++ b/drivers/infiniband/hw/nes/nes.h
34977@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
34978 extern unsigned int wqm_quanta;
34979 extern struct list_head nes_adapter_list;
34980
34981-extern atomic_t cm_connects;
34982-extern atomic_t cm_accepts;
34983-extern atomic_t cm_disconnects;
34984-extern atomic_t cm_closes;
34985-extern atomic_t cm_connecteds;
34986-extern atomic_t cm_connect_reqs;
34987-extern atomic_t cm_rejects;
34988-extern atomic_t mod_qp_timouts;
34989-extern atomic_t qps_created;
34990-extern atomic_t qps_destroyed;
34991-extern atomic_t sw_qps_destroyed;
34992+extern atomic_unchecked_t cm_connects;
34993+extern atomic_unchecked_t cm_accepts;
34994+extern atomic_unchecked_t cm_disconnects;
34995+extern atomic_unchecked_t cm_closes;
34996+extern atomic_unchecked_t cm_connecteds;
34997+extern atomic_unchecked_t cm_connect_reqs;
34998+extern atomic_unchecked_t cm_rejects;
34999+extern atomic_unchecked_t mod_qp_timouts;
35000+extern atomic_unchecked_t qps_created;
35001+extern atomic_unchecked_t qps_destroyed;
35002+extern atomic_unchecked_t sw_qps_destroyed;
35003 extern u32 mh_detected;
35004 extern u32 mh_pauses_sent;
35005 extern u32 cm_packets_sent;
35006@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
35007 extern u32 cm_packets_received;
35008 extern u32 cm_packets_dropped;
35009 extern u32 cm_packets_retrans;
35010-extern atomic_t cm_listens_created;
35011-extern atomic_t cm_listens_destroyed;
35012+extern atomic_unchecked_t cm_listens_created;
35013+extern atomic_unchecked_t cm_listens_destroyed;
35014 extern u32 cm_backlog_drops;
35015-extern atomic_t cm_loopbacks;
35016-extern atomic_t cm_nodes_created;
35017-extern atomic_t cm_nodes_destroyed;
35018-extern atomic_t cm_accel_dropped_pkts;
35019-extern atomic_t cm_resets_recvd;
35020-extern atomic_t pau_qps_created;
35021-extern atomic_t pau_qps_destroyed;
35022+extern atomic_unchecked_t cm_loopbacks;
35023+extern atomic_unchecked_t cm_nodes_created;
35024+extern atomic_unchecked_t cm_nodes_destroyed;
35025+extern atomic_unchecked_t cm_accel_dropped_pkts;
35026+extern atomic_unchecked_t cm_resets_recvd;
35027+extern atomic_unchecked_t pau_qps_created;
35028+extern atomic_unchecked_t pau_qps_destroyed;
35029
35030 extern u32 int_mod_timer_init;
35031 extern u32 int_mod_cq_depth_256;
35032diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
35033index 22ea67e..dcbe3bc 100644
35034--- a/drivers/infiniband/hw/nes/nes_cm.c
35035+++ b/drivers/infiniband/hw/nes/nes_cm.c
35036@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
35037 u32 cm_packets_retrans;
35038 u32 cm_packets_created;
35039 u32 cm_packets_received;
35040-atomic_t cm_listens_created;
35041-atomic_t cm_listens_destroyed;
35042+atomic_unchecked_t cm_listens_created;
35043+atomic_unchecked_t cm_listens_destroyed;
35044 u32 cm_backlog_drops;
35045-atomic_t cm_loopbacks;
35046-atomic_t cm_nodes_created;
35047-atomic_t cm_nodes_destroyed;
35048-atomic_t cm_accel_dropped_pkts;
35049-atomic_t cm_resets_recvd;
35050+atomic_unchecked_t cm_loopbacks;
35051+atomic_unchecked_t cm_nodes_created;
35052+atomic_unchecked_t cm_nodes_destroyed;
35053+atomic_unchecked_t cm_accel_dropped_pkts;
35054+atomic_unchecked_t cm_resets_recvd;
35055
35056 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
35057 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
35058@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
35059
35060 static struct nes_cm_core *g_cm_core;
35061
35062-atomic_t cm_connects;
35063-atomic_t cm_accepts;
35064-atomic_t cm_disconnects;
35065-atomic_t cm_closes;
35066-atomic_t cm_connecteds;
35067-atomic_t cm_connect_reqs;
35068-atomic_t cm_rejects;
35069+atomic_unchecked_t cm_connects;
35070+atomic_unchecked_t cm_accepts;
35071+atomic_unchecked_t cm_disconnects;
35072+atomic_unchecked_t cm_closes;
35073+atomic_unchecked_t cm_connecteds;
35074+atomic_unchecked_t cm_connect_reqs;
35075+atomic_unchecked_t cm_rejects;
35076
35077 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
35078 {
35079@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
35080 kfree(listener);
35081 listener = NULL;
35082 ret = 0;
35083- atomic_inc(&cm_listens_destroyed);
35084+ atomic_inc_unchecked(&cm_listens_destroyed);
35085 } else {
35086 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
35087 }
35088@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
35089 cm_node->rem_mac);
35090
35091 add_hte_node(cm_core, cm_node);
35092- atomic_inc(&cm_nodes_created);
35093+ atomic_inc_unchecked(&cm_nodes_created);
35094
35095 return cm_node;
35096 }
35097@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
35098 }
35099
35100 atomic_dec(&cm_core->node_cnt);
35101- atomic_inc(&cm_nodes_destroyed);
35102+ atomic_inc_unchecked(&cm_nodes_destroyed);
35103 nesqp = cm_node->nesqp;
35104 if (nesqp) {
35105 nesqp->cm_node = NULL;
35106@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
35107
35108 static void drop_packet(struct sk_buff *skb)
35109 {
35110- atomic_inc(&cm_accel_dropped_pkts);
35111+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
35112 dev_kfree_skb_any(skb);
35113 }
35114
35115@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
35116 {
35117
35118 int reset = 0; /* whether to send reset in case of err.. */
35119- atomic_inc(&cm_resets_recvd);
35120+ atomic_inc_unchecked(&cm_resets_recvd);
35121 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
35122 " refcnt=%d\n", cm_node, cm_node->state,
35123 atomic_read(&cm_node->ref_count));
35124@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
35125 rem_ref_cm_node(cm_node->cm_core, cm_node);
35126 return NULL;
35127 }
35128- atomic_inc(&cm_loopbacks);
35129+ atomic_inc_unchecked(&cm_loopbacks);
35130 loopbackremotenode->loopbackpartner = cm_node;
35131 loopbackremotenode->tcp_cntxt.rcv_wscale =
35132 NES_CM_DEFAULT_RCV_WND_SCALE;
35133@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
35134 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
35135 else {
35136 rem_ref_cm_node(cm_core, cm_node);
35137- atomic_inc(&cm_accel_dropped_pkts);
35138+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
35139 dev_kfree_skb_any(skb);
35140 }
35141 break;
35142@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
35143
35144 if ((cm_id) && (cm_id->event_handler)) {
35145 if (issue_disconn) {
35146- atomic_inc(&cm_disconnects);
35147+ atomic_inc_unchecked(&cm_disconnects);
35148 cm_event.event = IW_CM_EVENT_DISCONNECT;
35149 cm_event.status = disconn_status;
35150 cm_event.local_addr = cm_id->local_addr;
35151@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
35152 }
35153
35154 if (issue_close) {
35155- atomic_inc(&cm_closes);
35156+ atomic_inc_unchecked(&cm_closes);
35157 nes_disconnect(nesqp, 1);
35158
35159 cm_id->provider_data = nesqp;
35160@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
35161
35162 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
35163 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
35164- atomic_inc(&cm_accepts);
35165+ atomic_inc_unchecked(&cm_accepts);
35166
35167 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
35168 netdev_refcnt_read(nesvnic->netdev));
35169@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
35170 struct nes_cm_core *cm_core;
35171 u8 *start_buff;
35172
35173- atomic_inc(&cm_rejects);
35174+ atomic_inc_unchecked(&cm_rejects);
35175 cm_node = (struct nes_cm_node *)cm_id->provider_data;
35176 loopback = cm_node->loopbackpartner;
35177 cm_core = cm_node->cm_core;
35178@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
35179 ntohl(cm_id->local_addr.sin_addr.s_addr),
35180 ntohs(cm_id->local_addr.sin_port));
35181
35182- atomic_inc(&cm_connects);
35183+ atomic_inc_unchecked(&cm_connects);
35184 nesqp->active_conn = 1;
35185
35186 /* cache the cm_id in the qp */
35187@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
35188 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
35189 return err;
35190 }
35191- atomic_inc(&cm_listens_created);
35192+ atomic_inc_unchecked(&cm_listens_created);
35193 }
35194
35195 cm_id->add_ref(cm_id);
35196@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
35197
35198 if (nesqp->destroyed)
35199 return;
35200- atomic_inc(&cm_connecteds);
35201+ atomic_inc_unchecked(&cm_connecteds);
35202 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
35203 " local port 0x%04X. jiffies = %lu.\n",
35204 nesqp->hwqp.qp_id,
35205@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
35206
35207 cm_id->add_ref(cm_id);
35208 ret = cm_id->event_handler(cm_id, &cm_event);
35209- atomic_inc(&cm_closes);
35210+ atomic_inc_unchecked(&cm_closes);
35211 cm_event.event = IW_CM_EVENT_CLOSE;
35212 cm_event.status = 0;
35213 cm_event.provider_data = cm_id->provider_data;
35214@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
35215 return;
35216 cm_id = cm_node->cm_id;
35217
35218- atomic_inc(&cm_connect_reqs);
35219+ atomic_inc_unchecked(&cm_connect_reqs);
35220 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
35221 cm_node, cm_id, jiffies);
35222
35223@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
35224 return;
35225 cm_id = cm_node->cm_id;
35226
35227- atomic_inc(&cm_connect_reqs);
35228+ atomic_inc_unchecked(&cm_connect_reqs);
35229 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
35230 cm_node, cm_id, jiffies);
35231
35232diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
35233index 4166452..fc952c3 100644
35234--- a/drivers/infiniband/hw/nes/nes_mgt.c
35235+++ b/drivers/infiniband/hw/nes/nes_mgt.c
35236@@ -40,8 +40,8 @@
35237 #include "nes.h"
35238 #include "nes_mgt.h"
35239
35240-atomic_t pau_qps_created;
35241-atomic_t pau_qps_destroyed;
35242+atomic_unchecked_t pau_qps_created;
35243+atomic_unchecked_t pau_qps_destroyed;
35244
35245 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
35246 {
35247@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
35248 {
35249 struct sk_buff *skb;
35250 unsigned long flags;
35251- atomic_inc(&pau_qps_destroyed);
35252+ atomic_inc_unchecked(&pau_qps_destroyed);
35253
35254 /* Free packets that have not yet been forwarded */
35255 /* Lock is acquired by skb_dequeue when removing the skb */
35256@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
35257 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
35258 skb_queue_head_init(&nesqp->pau_list);
35259 spin_lock_init(&nesqp->pau_lock);
35260- atomic_inc(&pau_qps_created);
35261+ atomic_inc_unchecked(&pau_qps_created);
35262 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
35263 }
35264
35265diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
35266index 9542e16..a008c40 100644
35267--- a/drivers/infiniband/hw/nes/nes_nic.c
35268+++ b/drivers/infiniband/hw/nes/nes_nic.c
35269@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
35270 target_stat_values[++index] = mh_detected;
35271 target_stat_values[++index] = mh_pauses_sent;
35272 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
35273- target_stat_values[++index] = atomic_read(&cm_connects);
35274- target_stat_values[++index] = atomic_read(&cm_accepts);
35275- target_stat_values[++index] = atomic_read(&cm_disconnects);
35276- target_stat_values[++index] = atomic_read(&cm_connecteds);
35277- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
35278- target_stat_values[++index] = atomic_read(&cm_rejects);
35279- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
35280- target_stat_values[++index] = atomic_read(&qps_created);
35281- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
35282- target_stat_values[++index] = atomic_read(&qps_destroyed);
35283- target_stat_values[++index] = atomic_read(&cm_closes);
35284+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
35285+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
35286+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
35287+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
35288+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
35289+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
35290+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
35291+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
35292+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
35293+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
35294+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
35295 target_stat_values[++index] = cm_packets_sent;
35296 target_stat_values[++index] = cm_packets_bounced;
35297 target_stat_values[++index] = cm_packets_created;
35298 target_stat_values[++index] = cm_packets_received;
35299 target_stat_values[++index] = cm_packets_dropped;
35300 target_stat_values[++index] = cm_packets_retrans;
35301- target_stat_values[++index] = atomic_read(&cm_listens_created);
35302- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
35303+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
35304+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
35305 target_stat_values[++index] = cm_backlog_drops;
35306- target_stat_values[++index] = atomic_read(&cm_loopbacks);
35307- target_stat_values[++index] = atomic_read(&cm_nodes_created);
35308- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
35309- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
35310- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
35311+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
35312+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
35313+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
35314+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
35315+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
35316 target_stat_values[++index] = nesadapter->free_4kpbl;
35317 target_stat_values[++index] = nesadapter->free_256pbl;
35318 target_stat_values[++index] = int_mod_timer_init;
35319 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
35320 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
35321 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
35322- target_stat_values[++index] = atomic_read(&pau_qps_created);
35323- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
35324+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
35325+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
35326 }
35327
35328 /**
35329diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
35330index 07e4fba..685f041 100644
35331--- a/drivers/infiniband/hw/nes/nes_verbs.c
35332+++ b/drivers/infiniband/hw/nes/nes_verbs.c
35333@@ -46,9 +46,9 @@
35334
35335 #include <rdma/ib_umem.h>
35336
35337-atomic_t mod_qp_timouts;
35338-atomic_t qps_created;
35339-atomic_t sw_qps_destroyed;
35340+atomic_unchecked_t mod_qp_timouts;
35341+atomic_unchecked_t qps_created;
35342+atomic_unchecked_t sw_qps_destroyed;
35343
35344 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
35345
35346@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
35347 if (init_attr->create_flags)
35348 return ERR_PTR(-EINVAL);
35349
35350- atomic_inc(&qps_created);
35351+ atomic_inc_unchecked(&qps_created);
35352 switch (init_attr->qp_type) {
35353 case IB_QPT_RC:
35354 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
35355@@ -1462,7 +1462,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
35356 struct iw_cm_event cm_event;
35357 int ret = 0;
35358
35359- atomic_inc(&sw_qps_destroyed);
35360+ atomic_inc_unchecked(&sw_qps_destroyed);
35361 nesqp->destroyed = 1;
35362
35363 /* Blow away the connection if it exists. */
35364diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
35365index 4d11575..3e890e5 100644
35366--- a/drivers/infiniband/hw/qib/qib.h
35367+++ b/drivers/infiniband/hw/qib/qib.h
35368@@ -51,6 +51,7 @@
35369 #include <linux/completion.h>
35370 #include <linux/kref.h>
35371 #include <linux/sched.h>
35372+#include <linux/slab.h>
35373
35374 #include "qib_common.h"
35375 #include "qib_verbs.h"
35376diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
35377index da739d9..da1c7f4 100644
35378--- a/drivers/input/gameport/gameport.c
35379+++ b/drivers/input/gameport/gameport.c
35380@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
35381 */
35382 static void gameport_init_port(struct gameport *gameport)
35383 {
35384- static atomic_t gameport_no = ATOMIC_INIT(0);
35385+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
35386
35387 __module_get(THIS_MODULE);
35388
35389 mutex_init(&gameport->drv_mutex);
35390 device_initialize(&gameport->dev);
35391 dev_set_name(&gameport->dev, "gameport%lu",
35392- (unsigned long)atomic_inc_return(&gameport_no) - 1);
35393+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
35394 gameport->dev.bus = &gameport_bus;
35395 gameport->dev.release = gameport_release_port;
35396 if (gameport->parent)
35397diff --git a/drivers/input/input.c b/drivers/input/input.c
35398index c044699..174d71a 100644
35399--- a/drivers/input/input.c
35400+++ b/drivers/input/input.c
35401@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
35402 */
35403 int input_register_device(struct input_dev *dev)
35404 {
35405- static atomic_t input_no = ATOMIC_INIT(0);
35406+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
35407 struct input_devres *devres = NULL;
35408 struct input_handler *handler;
35409 unsigned int packet_size;
35410@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
35411 dev->setkeycode = input_default_setkeycode;
35412
35413 dev_set_name(&dev->dev, "input%ld",
35414- (unsigned long) atomic_inc_return(&input_no) - 1);
35415+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
35416
35417 error = device_add(&dev->dev);
35418 if (error)
35419diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
35420index 04c69af..5f92d00 100644
35421--- a/drivers/input/joystick/sidewinder.c
35422+++ b/drivers/input/joystick/sidewinder.c
35423@@ -30,6 +30,7 @@
35424 #include <linux/kernel.h>
35425 #include <linux/module.h>
35426 #include <linux/slab.h>
35427+#include <linux/sched.h>
35428 #include <linux/init.h>
35429 #include <linux/input.h>
35430 #include <linux/gameport.h>
35431diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
35432index d6cbfe9..6225402 100644
35433--- a/drivers/input/joystick/xpad.c
35434+++ b/drivers/input/joystick/xpad.c
35435@@ -735,7 +735,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
35436
35437 static int xpad_led_probe(struct usb_xpad *xpad)
35438 {
35439- static atomic_t led_seq = ATOMIC_INIT(0);
35440+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
35441 long led_no;
35442 struct xpad_led *led;
35443 struct led_classdev *led_cdev;
35444@@ -748,7 +748,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
35445 if (!led)
35446 return -ENOMEM;
35447
35448- led_no = (long)atomic_inc_return(&led_seq) - 1;
35449+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
35450
35451 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
35452 led->xpad = xpad;
35453diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
35454index 4c842c3..590b0bf 100644
35455--- a/drivers/input/mousedev.c
35456+++ b/drivers/input/mousedev.c
35457@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
35458
35459 spin_unlock_irq(&client->packet_lock);
35460
35461- if (copy_to_user(buffer, data, count))
35462+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
35463 return -EFAULT;
35464
35465 return count;
35466diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
35467index 25fc597..558bf3b 100644
35468--- a/drivers/input/serio/serio.c
35469+++ b/drivers/input/serio/serio.c
35470@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
35471 */
35472 static void serio_init_port(struct serio *serio)
35473 {
35474- static atomic_t serio_no = ATOMIC_INIT(0);
35475+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
35476
35477 __module_get(THIS_MODULE);
35478
35479@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
35480 mutex_init(&serio->drv_mutex);
35481 device_initialize(&serio->dev);
35482 dev_set_name(&serio->dev, "serio%ld",
35483- (long)atomic_inc_return(&serio_no) - 1);
35484+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
35485 serio->dev.bus = &serio_bus;
35486 serio->dev.release = serio_release_port;
35487 serio->dev.groups = serio_device_attr_groups;
35488diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
35489index 89562a8..218999b 100644
35490--- a/drivers/isdn/capi/capi.c
35491+++ b/drivers/isdn/capi/capi.c
35492@@ -81,8 +81,8 @@ struct capiminor {
35493
35494 struct capi20_appl *ap;
35495 u32 ncci;
35496- atomic_t datahandle;
35497- atomic_t msgid;
35498+ atomic_unchecked_t datahandle;
35499+ atomic_unchecked_t msgid;
35500
35501 struct tty_port port;
35502 int ttyinstop;
35503@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
35504 capimsg_setu16(s, 2, mp->ap->applid);
35505 capimsg_setu8 (s, 4, CAPI_DATA_B3);
35506 capimsg_setu8 (s, 5, CAPI_RESP);
35507- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
35508+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
35509 capimsg_setu32(s, 8, mp->ncci);
35510 capimsg_setu16(s, 12, datahandle);
35511 }
35512@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
35513 mp->outbytes -= len;
35514 spin_unlock_bh(&mp->outlock);
35515
35516- datahandle = atomic_inc_return(&mp->datahandle);
35517+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
35518 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
35519 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
35520 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
35521 capimsg_setu16(skb->data, 2, mp->ap->applid);
35522 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
35523 capimsg_setu8 (skb->data, 5, CAPI_REQ);
35524- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
35525+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
35526 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
35527 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
35528 capimsg_setu16(skb->data, 16, len); /* Data length */
35529diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
35530index 67abf3f..076b3a6 100644
35531--- a/drivers/isdn/gigaset/interface.c
35532+++ b/drivers/isdn/gigaset/interface.c
35533@@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
35534 }
35535 tty->driver_data = cs;
35536
35537- ++cs->port.count;
35538+ atomic_inc(&cs->port.count);
35539
35540- if (cs->port.count == 1) {
35541+ if (atomic_read(&cs->port.count) == 1) {
35542 tty_port_tty_set(&cs->port, tty);
35543 tty->low_latency = 1;
35544 }
35545@@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
35546
35547 if (!cs->connected)
35548 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
35549- else if (!cs->port.count)
35550+ else if (!atomic_read(&cs->port.count))
35551 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35552- else if (!--cs->port.count)
35553+ else if (!atomic_dec_return(&cs->port.count))
35554 tty_port_tty_set(&cs->port, NULL);
35555
35556 mutex_unlock(&cs->mutex);
35557diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
35558index 821f7ac..28d4030 100644
35559--- a/drivers/isdn/hardware/avm/b1.c
35560+++ b/drivers/isdn/hardware/avm/b1.c
35561@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
35562 }
35563 if (left) {
35564 if (t4file->user) {
35565- if (copy_from_user(buf, dp, left))
35566+ if (left > sizeof buf || copy_from_user(buf, dp, left))
35567 return -EFAULT;
35568 } else {
35569 memcpy(buf, dp, left);
35570@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
35571 }
35572 if (left) {
35573 if (config->user) {
35574- if (copy_from_user(buf, dp, left))
35575+ if (left > sizeof buf || copy_from_user(buf, dp, left))
35576 return -EFAULT;
35577 } else {
35578 memcpy(buf, dp, left);
35579diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
35580index e09dc8a..15e2efb 100644
35581--- a/drivers/isdn/i4l/isdn_tty.c
35582+++ b/drivers/isdn/i4l/isdn_tty.c
35583@@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
35584
35585 #ifdef ISDN_DEBUG_MODEM_OPEN
35586 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
35587- port->count);
35588+ atomic_read(&port->count));
35589 #endif
35590- port->count++;
35591+ atomic_inc(&port->count);
35592 port->tty = tty;
35593 /*
35594 * Start up serial port
35595@@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
35596 #endif
35597 return;
35598 }
35599- if ((tty->count == 1) && (port->count != 1)) {
35600+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
35601 /*
35602 * Uh, oh. tty->count is 1, which means that the tty
35603 * structure will be freed. Info->count should always
35604@@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
35605 * serial port won't be shutdown.
35606 */
35607 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
35608- "info->count is %d\n", port->count);
35609- port->count = 1;
35610+ "info->count is %d\n", atomic_read(&port->count));
35611+ atomic_set(&port->count, 1);
35612 }
35613- if (--port->count < 0) {
35614+ if (atomic_dec_return(&port->count) < 0) {
35615 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
35616- info->line, port->count);
35617- port->count = 0;
35618+ info->line, atomic_read(&port->count));
35619+ atomic_set(&port->count, 0);
35620 }
35621- if (port->count) {
35622+ if (atomic_read(&port->count)) {
35623 #ifdef ISDN_DEBUG_MODEM_OPEN
35624 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
35625 #endif
35626@@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
35627 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
35628 return;
35629 isdn_tty_shutdown(info);
35630- port->count = 0;
35631+ atomic_set(&port->count, 0);
35632 port->flags &= ~ASYNC_NORMAL_ACTIVE;
35633 port->tty = NULL;
35634 wake_up_interruptible(&port->open_wait);
35635@@ -1975,7 +1975,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
35636 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
35637 modem_info *info = &dev->mdm.info[i];
35638
35639- if (info->port.count == 0)
35640+ if (atomic_read(&info->port.count) == 0)
35641 continue;
35642 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
35643 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
35644diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
35645index e74df7c..03a03ba 100644
35646--- a/drivers/isdn/icn/icn.c
35647+++ b/drivers/isdn/icn/icn.c
35648@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
35649 if (count > len)
35650 count = len;
35651 if (user) {
35652- if (copy_from_user(msg, buf, count))
35653+ if (count > sizeof msg || copy_from_user(msg, buf, count))
35654 return -EFAULT;
35655 } else
35656 memcpy(msg, buf, count);
35657diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
35658index a5ebc00..982886f 100644
35659--- a/drivers/lguest/core.c
35660+++ b/drivers/lguest/core.c
35661@@ -92,9 +92,17 @@ static __init int map_switcher(void)
35662 * it's worked so far. The end address needs +1 because __get_vm_area
35663 * allocates an extra guard page, so we need space for that.
35664 */
35665+
35666+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
35667+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
35668+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
35669+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
35670+#else
35671 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
35672 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
35673 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
35674+#endif
35675+
35676 if (!switcher_vma) {
35677 err = -ENOMEM;
35678 printk("lguest: could not map switcher pages high\n");
35679@@ -119,7 +127,7 @@ static __init int map_switcher(void)
35680 * Now the Switcher is mapped at the right address, we can't fail!
35681 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
35682 */
35683- memcpy(switcher_vma->addr, start_switcher_text,
35684+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
35685 end_switcher_text - start_switcher_text);
35686
35687 printk(KERN_INFO "lguest: mapped switcher at %p\n",
35688diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
35689index 4af12e1..0e89afe 100644
35690--- a/drivers/lguest/x86/core.c
35691+++ b/drivers/lguest/x86/core.c
35692@@ -59,7 +59,7 @@ static struct {
35693 /* Offset from where switcher.S was compiled to where we've copied it */
35694 static unsigned long switcher_offset(void)
35695 {
35696- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
35697+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
35698 }
35699
35700 /* This cpu's struct lguest_pages. */
35701@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
35702 * These copies are pretty cheap, so we do them unconditionally: */
35703 /* Save the current Host top-level page directory.
35704 */
35705+
35706+#ifdef CONFIG_PAX_PER_CPU_PGD
35707+ pages->state.host_cr3 = read_cr3();
35708+#else
35709 pages->state.host_cr3 = __pa(current->mm->pgd);
35710+#endif
35711+
35712 /*
35713 * Set up the Guest's page tables to see this CPU's pages (and no
35714 * other CPU's pages).
35715@@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
35716 * compiled-in switcher code and the high-mapped copy we just made.
35717 */
35718 for (i = 0; i < IDT_ENTRIES; i++)
35719- default_idt_entries[i] += switcher_offset();
35720+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
35721
35722 /*
35723 * Set up the Switcher's per-cpu areas.
35724@@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
35725 * it will be undisturbed when we switch. To change %cs and jump we
35726 * need this structure to feed to Intel's "lcall" instruction.
35727 */
35728- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
35729+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
35730 lguest_entry.segment = LGUEST_CS;
35731
35732 /*
35733diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
35734index 40634b0..4f5855e 100644
35735--- a/drivers/lguest/x86/switcher_32.S
35736+++ b/drivers/lguest/x86/switcher_32.S
35737@@ -87,6 +87,7 @@
35738 #include <asm/page.h>
35739 #include <asm/segment.h>
35740 #include <asm/lguest.h>
35741+#include <asm/processor-flags.h>
35742
35743 // We mark the start of the code to copy
35744 // It's placed in .text tho it's never run here
35745@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
35746 // Changes type when we load it: damn Intel!
35747 // For after we switch over our page tables
35748 // That entry will be read-only: we'd crash.
35749+
35750+#ifdef CONFIG_PAX_KERNEXEC
35751+ mov %cr0, %edx
35752+ xor $X86_CR0_WP, %edx
35753+ mov %edx, %cr0
35754+#endif
35755+
35756 movl $(GDT_ENTRY_TSS*8), %edx
35757 ltr %dx
35758
35759@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
35760 // Let's clear it again for our return.
35761 // The GDT descriptor of the Host
35762 // Points to the table after two "size" bytes
35763- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
35764+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
35765 // Clear "used" from type field (byte 5, bit 2)
35766- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
35767+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
35768+
35769+#ifdef CONFIG_PAX_KERNEXEC
35770+ mov %cr0, %eax
35771+ xor $X86_CR0_WP, %eax
35772+ mov %eax, %cr0
35773+#endif
35774
35775 // Once our page table's switched, the Guest is live!
35776 // The Host fades as we run this final step.
35777@@ -295,13 +309,12 @@ deliver_to_host:
35778 // I consulted gcc, and it gave
35779 // These instructions, which I gladly credit:
35780 leal (%edx,%ebx,8), %eax
35781- movzwl (%eax),%edx
35782- movl 4(%eax), %eax
35783- xorw %ax, %ax
35784- orl %eax, %edx
35785+ movl 4(%eax), %edx
35786+ movw (%eax), %dx
35787 // Now the address of the handler's in %edx
35788 // We call it now: its "iret" drops us home.
35789- jmp *%edx
35790+ ljmp $__KERNEL_CS, $1f
35791+1: jmp *%edx
35792
35793 // Every interrupt can come to us here
35794 // But we must truly tell each apart.
35795diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
35796index 7155945..4bcc562 100644
35797--- a/drivers/md/bitmap.c
35798+++ b/drivers/md/bitmap.c
35799@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
35800 chunk_kb ? "KB" : "B");
35801 if (bitmap->storage.file) {
35802 seq_printf(seq, ", file: ");
35803- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
35804+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
35805 }
35806
35807 seq_printf(seq, "\n");
35808diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
35809index 0666b5d..ed82cb4 100644
35810--- a/drivers/md/dm-ioctl.c
35811+++ b/drivers/md/dm-ioctl.c
35812@@ -1628,7 +1628,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
35813 cmd == DM_LIST_VERSIONS_CMD)
35814 return 0;
35815
35816- if ((cmd == DM_DEV_CREATE_CMD)) {
35817+ if (cmd == DM_DEV_CREATE_CMD) {
35818 if (!*param->name) {
35819 DMWARN("name not supplied when creating device");
35820 return -EINVAL;
35821diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
35822index fa51918..c26253c 100644
35823--- a/drivers/md/dm-raid1.c
35824+++ b/drivers/md/dm-raid1.c
35825@@ -40,7 +40,7 @@ enum dm_raid1_error {
35826
35827 struct mirror {
35828 struct mirror_set *ms;
35829- atomic_t error_count;
35830+ atomic_unchecked_t error_count;
35831 unsigned long error_type;
35832 struct dm_dev *dev;
35833 sector_t offset;
35834@@ -183,7 +183,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
35835 struct mirror *m;
35836
35837 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
35838- if (!atomic_read(&m->error_count))
35839+ if (!atomic_read_unchecked(&m->error_count))
35840 return m;
35841
35842 return NULL;
35843@@ -215,7 +215,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
35844 * simple way to tell if a device has encountered
35845 * errors.
35846 */
35847- atomic_inc(&m->error_count);
35848+ atomic_inc_unchecked(&m->error_count);
35849
35850 if (test_and_set_bit(error_type, &m->error_type))
35851 return;
35852@@ -406,7 +406,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
35853 struct mirror *m = get_default_mirror(ms);
35854
35855 do {
35856- if (likely(!atomic_read(&m->error_count)))
35857+ if (likely(!atomic_read_unchecked(&m->error_count)))
35858 return m;
35859
35860 if (m-- == ms->mirror)
35861@@ -420,7 +420,7 @@ static int default_ok(struct mirror *m)
35862 {
35863 struct mirror *default_mirror = get_default_mirror(m->ms);
35864
35865- return !atomic_read(&default_mirror->error_count);
35866+ return !atomic_read_unchecked(&default_mirror->error_count);
35867 }
35868
35869 static int mirror_available(struct mirror_set *ms, struct bio *bio)
35870@@ -557,7 +557,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
35871 */
35872 if (likely(region_in_sync(ms, region, 1)))
35873 m = choose_mirror(ms, bio->bi_sector);
35874- else if (m && atomic_read(&m->error_count))
35875+ else if (m && atomic_read_unchecked(&m->error_count))
35876 m = NULL;
35877
35878 if (likely(m))
35879@@ -924,7 +924,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
35880 }
35881
35882 ms->mirror[mirror].ms = ms;
35883- atomic_set(&(ms->mirror[mirror].error_count), 0);
35884+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
35885 ms->mirror[mirror].error_type = 0;
35886 ms->mirror[mirror].offset = offset;
35887
35888@@ -1337,7 +1337,7 @@ static void mirror_resume(struct dm_target *ti)
35889 */
35890 static char device_status_char(struct mirror *m)
35891 {
35892- if (!atomic_read(&(m->error_count)))
35893+ if (!atomic_read_unchecked(&(m->error_count)))
35894 return 'A';
35895
35896 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
35897diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
35898index c89cde8..9d184cf 100644
35899--- a/drivers/md/dm-stripe.c
35900+++ b/drivers/md/dm-stripe.c
35901@@ -20,7 +20,7 @@ struct stripe {
35902 struct dm_dev *dev;
35903 sector_t physical_start;
35904
35905- atomic_t error_count;
35906+ atomic_unchecked_t error_count;
35907 };
35908
35909 struct stripe_c {
35910@@ -184,7 +184,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
35911 kfree(sc);
35912 return r;
35913 }
35914- atomic_set(&(sc->stripe[i].error_count), 0);
35915+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
35916 }
35917
35918 ti->private = sc;
35919@@ -325,7 +325,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
35920 DMEMIT("%d ", sc->stripes);
35921 for (i = 0; i < sc->stripes; i++) {
35922 DMEMIT("%s ", sc->stripe[i].dev->name);
35923- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
35924+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
35925 'D' : 'A';
35926 }
35927 buffer[i] = '\0';
35928@@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
35929 */
35930 for (i = 0; i < sc->stripes; i++)
35931 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
35932- atomic_inc(&(sc->stripe[i].error_count));
35933- if (atomic_read(&(sc->stripe[i].error_count)) <
35934+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
35935+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
35936 DM_IO_ERROR_THRESHOLD)
35937 schedule_work(&sc->trigger_event);
35938 }
35939diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
35940index daf25d0..d74f49f 100644
35941--- a/drivers/md/dm-table.c
35942+++ b/drivers/md/dm-table.c
35943@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
35944 if (!dev_size)
35945 return 0;
35946
35947- if ((start >= dev_size) || (start + len > dev_size)) {
35948+ if ((start >= dev_size) || (len > dev_size - start)) {
35949 DMWARN("%s: %s too small for target: "
35950 "start=%llu, len=%llu, dev_size=%llu",
35951 dm_device_name(ti->table->md), bdevname(bdev, b),
35952diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
35953index 4d6e853..a234157 100644
35954--- a/drivers/md/dm-thin-metadata.c
35955+++ b/drivers/md/dm-thin-metadata.c
35956@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
35957 {
35958 pmd->info.tm = pmd->tm;
35959 pmd->info.levels = 2;
35960- pmd->info.value_type.context = pmd->data_sm;
35961+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
35962 pmd->info.value_type.size = sizeof(__le64);
35963 pmd->info.value_type.inc = data_block_inc;
35964 pmd->info.value_type.dec = data_block_dec;
35965@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
35966
35967 pmd->bl_info.tm = pmd->tm;
35968 pmd->bl_info.levels = 1;
35969- pmd->bl_info.value_type.context = pmd->data_sm;
35970+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
35971 pmd->bl_info.value_type.size = sizeof(__le64);
35972 pmd->bl_info.value_type.inc = data_block_inc;
35973 pmd->bl_info.value_type.dec = data_block_dec;
35974diff --git a/drivers/md/dm.c b/drivers/md/dm.c
35975index 314a0e2..1376406 100644
35976--- a/drivers/md/dm.c
35977+++ b/drivers/md/dm.c
35978@@ -170,9 +170,9 @@ struct mapped_device {
35979 /*
35980 * Event handling.
35981 */
35982- atomic_t event_nr;
35983+ atomic_unchecked_t event_nr;
35984 wait_queue_head_t eventq;
35985- atomic_t uevent_seq;
35986+ atomic_unchecked_t uevent_seq;
35987 struct list_head uevent_list;
35988 spinlock_t uevent_lock; /* Protect access to uevent_list */
35989
35990@@ -1872,8 +1872,8 @@ static struct mapped_device *alloc_dev(int minor)
35991 rwlock_init(&md->map_lock);
35992 atomic_set(&md->holders, 1);
35993 atomic_set(&md->open_count, 0);
35994- atomic_set(&md->event_nr, 0);
35995- atomic_set(&md->uevent_seq, 0);
35996+ atomic_set_unchecked(&md->event_nr, 0);
35997+ atomic_set_unchecked(&md->uevent_seq, 0);
35998 INIT_LIST_HEAD(&md->uevent_list);
35999 spin_lock_init(&md->uevent_lock);
36000
36001@@ -2014,7 +2014,7 @@ static void event_callback(void *context)
36002
36003 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
36004
36005- atomic_inc(&md->event_nr);
36006+ atomic_inc_unchecked(&md->event_nr);
36007 wake_up(&md->eventq);
36008 }
36009
36010@@ -2669,18 +2669,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
36011
36012 uint32_t dm_next_uevent_seq(struct mapped_device *md)
36013 {
36014- return atomic_add_return(1, &md->uevent_seq);
36015+ return atomic_add_return_unchecked(1, &md->uevent_seq);
36016 }
36017
36018 uint32_t dm_get_event_nr(struct mapped_device *md)
36019 {
36020- return atomic_read(&md->event_nr);
36021+ return atomic_read_unchecked(&md->event_nr);
36022 }
36023
36024 int dm_wait_event(struct mapped_device *md, int event_nr)
36025 {
36026 return wait_event_interruptible(md->eventq,
36027- (event_nr != atomic_read(&md->event_nr)));
36028+ (event_nr != atomic_read_unchecked(&md->event_nr)));
36029 }
36030
36031 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
36032diff --git a/drivers/md/md.c b/drivers/md/md.c
36033index 3db3d1b..9487468 100644
36034--- a/drivers/md/md.c
36035+++ b/drivers/md/md.c
36036@@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
36037 * start build, activate spare
36038 */
36039 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
36040-static atomic_t md_event_count;
36041+static atomic_unchecked_t md_event_count;
36042 void md_new_event(struct mddev *mddev)
36043 {
36044- atomic_inc(&md_event_count);
36045+ atomic_inc_unchecked(&md_event_count);
36046 wake_up(&md_event_waiters);
36047 }
36048 EXPORT_SYMBOL_GPL(md_new_event);
36049@@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
36050 */
36051 static void md_new_event_inintr(struct mddev *mddev)
36052 {
36053- atomic_inc(&md_event_count);
36054+ atomic_inc_unchecked(&md_event_count);
36055 wake_up(&md_event_waiters);
36056 }
36057
36058@@ -1503,7 +1503,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
36059 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
36060 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
36061 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
36062- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
36063+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
36064
36065 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
36066 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
36067@@ -1747,7 +1747,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
36068 else
36069 sb->resync_offset = cpu_to_le64(0);
36070
36071- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
36072+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
36073
36074 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
36075 sb->size = cpu_to_le64(mddev->dev_sectors);
36076@@ -2747,7 +2747,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
36077 static ssize_t
36078 errors_show(struct md_rdev *rdev, char *page)
36079 {
36080- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
36081+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
36082 }
36083
36084 static ssize_t
36085@@ -2756,7 +2756,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
36086 char *e;
36087 unsigned long n = simple_strtoul(buf, &e, 10);
36088 if (*buf && (*e == 0 || *e == '\n')) {
36089- atomic_set(&rdev->corrected_errors, n);
36090+ atomic_set_unchecked(&rdev->corrected_errors, n);
36091 return len;
36092 }
36093 return -EINVAL;
36094@@ -3203,8 +3203,8 @@ int md_rdev_init(struct md_rdev *rdev)
36095 rdev->sb_loaded = 0;
36096 rdev->bb_page = NULL;
36097 atomic_set(&rdev->nr_pending, 0);
36098- atomic_set(&rdev->read_errors, 0);
36099- atomic_set(&rdev->corrected_errors, 0);
36100+ atomic_set_unchecked(&rdev->read_errors, 0);
36101+ atomic_set_unchecked(&rdev->corrected_errors, 0);
36102
36103 INIT_LIST_HEAD(&rdev->same_set);
36104 init_waitqueue_head(&rdev->blocked_wait);
36105@@ -6980,7 +6980,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
36106
36107 spin_unlock(&pers_lock);
36108 seq_printf(seq, "\n");
36109- seq->poll_event = atomic_read(&md_event_count);
36110+ seq->poll_event = atomic_read_unchecked(&md_event_count);
36111 return 0;
36112 }
36113 if (v == (void*)2) {
36114@@ -7083,7 +7083,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
36115 return error;
36116
36117 seq = file->private_data;
36118- seq->poll_event = atomic_read(&md_event_count);
36119+ seq->poll_event = atomic_read_unchecked(&md_event_count);
36120 return error;
36121 }
36122
36123@@ -7097,7 +7097,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
36124 /* always allow read */
36125 mask = POLLIN | POLLRDNORM;
36126
36127- if (seq->poll_event != atomic_read(&md_event_count))
36128+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
36129 mask |= POLLERR | POLLPRI;
36130 return mask;
36131 }
36132@@ -7141,7 +7141,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
36133 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
36134 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
36135 (int)part_stat_read(&disk->part0, sectors[1]) -
36136- atomic_read(&disk->sync_io);
36137+ atomic_read_unchecked(&disk->sync_io);
36138 /* sync IO will cause sync_io to increase before the disk_stats
36139 * as sync_io is counted when a request starts, and
36140 * disk_stats is counted when it completes.
36141diff --git a/drivers/md/md.h b/drivers/md/md.h
36142index eca59c3..7c42285 100644
36143--- a/drivers/md/md.h
36144+++ b/drivers/md/md.h
36145@@ -94,13 +94,13 @@ struct md_rdev {
36146 * only maintained for arrays that
36147 * support hot removal
36148 */
36149- atomic_t read_errors; /* number of consecutive read errors that
36150+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
36151 * we have tried to ignore.
36152 */
36153 struct timespec last_read_error; /* monotonic time since our
36154 * last read error
36155 */
36156- atomic_t corrected_errors; /* number of corrected read errors,
36157+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
36158 * for reporting to userspace and storing
36159 * in superblock.
36160 */
36161@@ -434,7 +434,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
36162
36163 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
36164 {
36165- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
36166+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
36167 }
36168
36169 struct md_personality
36170diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
36171index 1cbfc6b..56e1dbb 100644
36172--- a/drivers/md/persistent-data/dm-space-map.h
36173+++ b/drivers/md/persistent-data/dm-space-map.h
36174@@ -60,6 +60,7 @@ struct dm_space_map {
36175 int (*root_size)(struct dm_space_map *sm, size_t *result);
36176 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
36177 };
36178+typedef struct dm_space_map __no_const dm_space_map_no_const;
36179
36180 /*----------------------------------------------------------------*/
36181
36182diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
36183index d5bddfc..b079b4b 100644
36184--- a/drivers/md/raid1.c
36185+++ b/drivers/md/raid1.c
36186@@ -1818,7 +1818,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
36187 if (r1_sync_page_io(rdev, sect, s,
36188 bio->bi_io_vec[idx].bv_page,
36189 READ) != 0)
36190- atomic_add(s, &rdev->corrected_errors);
36191+ atomic_add_unchecked(s, &rdev->corrected_errors);
36192 }
36193 sectors -= s;
36194 sect += s;
36195@@ -2040,7 +2040,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
36196 test_bit(In_sync, &rdev->flags)) {
36197 if (r1_sync_page_io(rdev, sect, s,
36198 conf->tmppage, READ)) {
36199- atomic_add(s, &rdev->corrected_errors);
36200+ atomic_add_unchecked(s, &rdev->corrected_errors);
36201 printk(KERN_INFO
36202 "md/raid1:%s: read error corrected "
36203 "(%d sectors at %llu on %s)\n",
36204diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
36205index 64d4824..8b9ea57 100644
36206--- a/drivers/md/raid10.c
36207+++ b/drivers/md/raid10.c
36208@@ -1877,7 +1877,7 @@ static void end_sync_read(struct bio *bio, int error)
36209 /* The write handler will notice the lack of
36210 * R10BIO_Uptodate and record any errors etc
36211 */
36212- atomic_add(r10_bio->sectors,
36213+ atomic_add_unchecked(r10_bio->sectors,
36214 &conf->mirrors[d].rdev->corrected_errors);
36215
36216 /* for reconstruct, we always reschedule after a read.
36217@@ -2226,7 +2226,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
36218 {
36219 struct timespec cur_time_mon;
36220 unsigned long hours_since_last;
36221- unsigned int read_errors = atomic_read(&rdev->read_errors);
36222+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
36223
36224 ktime_get_ts(&cur_time_mon);
36225
36226@@ -2248,9 +2248,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
36227 * overflowing the shift of read_errors by hours_since_last.
36228 */
36229 if (hours_since_last >= 8 * sizeof(read_errors))
36230- atomic_set(&rdev->read_errors, 0);
36231+ atomic_set_unchecked(&rdev->read_errors, 0);
36232 else
36233- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
36234+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
36235 }
36236
36237 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
36238@@ -2304,8 +2304,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
36239 return;
36240
36241 check_decay_read_errors(mddev, rdev);
36242- atomic_inc(&rdev->read_errors);
36243- if (atomic_read(&rdev->read_errors) > max_read_errors) {
36244+ atomic_inc_unchecked(&rdev->read_errors);
36245+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
36246 char b[BDEVNAME_SIZE];
36247 bdevname(rdev->bdev, b);
36248
36249@@ -2313,7 +2313,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
36250 "md/raid10:%s: %s: Raid device exceeded "
36251 "read_error threshold [cur %d:max %d]\n",
36252 mdname(mddev), b,
36253- atomic_read(&rdev->read_errors), max_read_errors);
36254+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
36255 printk(KERN_NOTICE
36256 "md/raid10:%s: %s: Failing raid device\n",
36257 mdname(mddev), b);
36258@@ -2468,7 +2468,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
36259 sect +
36260 choose_data_offset(r10_bio, rdev)),
36261 bdevname(rdev->bdev, b));
36262- atomic_add(s, &rdev->corrected_errors);
36263+ atomic_add_unchecked(s, &rdev->corrected_errors);
36264 }
36265
36266 rdev_dec_pending(rdev, mddev);
36267diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
36268index 19d77a0..56051b92 100644
36269--- a/drivers/md/raid5.c
36270+++ b/drivers/md/raid5.c
36271@@ -1797,21 +1797,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
36272 mdname(conf->mddev), STRIPE_SECTORS,
36273 (unsigned long long)s,
36274 bdevname(rdev->bdev, b));
36275- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
36276+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
36277 clear_bit(R5_ReadError, &sh->dev[i].flags);
36278 clear_bit(R5_ReWrite, &sh->dev[i].flags);
36279 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
36280 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
36281
36282- if (atomic_read(&rdev->read_errors))
36283- atomic_set(&rdev->read_errors, 0);
36284+ if (atomic_read_unchecked(&rdev->read_errors))
36285+ atomic_set_unchecked(&rdev->read_errors, 0);
36286 } else {
36287 const char *bdn = bdevname(rdev->bdev, b);
36288 int retry = 0;
36289 int set_bad = 0;
36290
36291 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
36292- atomic_inc(&rdev->read_errors);
36293+ atomic_inc_unchecked(&rdev->read_errors);
36294 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
36295 printk_ratelimited(
36296 KERN_WARNING
36297@@ -1839,7 +1839,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
36298 mdname(conf->mddev),
36299 (unsigned long long)s,
36300 bdn);
36301- } else if (atomic_read(&rdev->read_errors)
36302+ } else if (atomic_read_unchecked(&rdev->read_errors)
36303 > conf->max_nr_stripes)
36304 printk(KERN_WARNING
36305 "md/raid:%s: Too many read errors, failing device %s.\n",
36306diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
36307index d33101a..6b13069 100644
36308--- a/drivers/media/dvb-core/dvbdev.c
36309+++ b/drivers/media/dvb-core/dvbdev.c
36310@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
36311 const struct dvb_device *template, void *priv, int type)
36312 {
36313 struct dvb_device *dvbdev;
36314- struct file_operations *dvbdevfops;
36315+ file_operations_no_const *dvbdevfops;
36316 struct device *clsdev;
36317 int minor;
36318 int id;
36319diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
36320index 404f63a..4796533 100644
36321--- a/drivers/media/dvb-frontends/dib3000.h
36322+++ b/drivers/media/dvb-frontends/dib3000.h
36323@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
36324 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
36325 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
36326 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
36327-};
36328+} __no_const;
36329
36330 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
36331 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
36332diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
36333index 35cc526..9d90d83 100644
36334--- a/drivers/media/platform/omap/omap_vout.c
36335+++ b/drivers/media/platform/omap/omap_vout.c
36336@@ -63,7 +63,6 @@ enum omap_vout_channels {
36337 OMAP_VIDEO2,
36338 };
36339
36340-static struct videobuf_queue_ops video_vbq_ops;
36341 /* Variables configurable through module params*/
36342 static u32 video1_numbuffers = 3;
36343 static u32 video2_numbuffers = 3;
36344@@ -1010,6 +1009,12 @@ static int omap_vout_open(struct file *file)
36345 {
36346 struct videobuf_queue *q;
36347 struct omap_vout_device *vout = NULL;
36348+ static struct videobuf_queue_ops video_vbq_ops = {
36349+ .buf_setup = omap_vout_buffer_setup,
36350+ .buf_prepare = omap_vout_buffer_prepare,
36351+ .buf_release = omap_vout_buffer_release,
36352+ .buf_queue = omap_vout_buffer_queue,
36353+ };
36354
36355 vout = video_drvdata(file);
36356 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
36357@@ -1027,10 +1032,6 @@ static int omap_vout_open(struct file *file)
36358 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
36359
36360 q = &vout->vbq;
36361- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
36362- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
36363- video_vbq_ops.buf_release = omap_vout_buffer_release;
36364- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
36365 spin_lock_init(&vout->vbq_lock);
36366
36367 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
36368diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
36369index b671e20..34088b7 100644
36370--- a/drivers/media/platform/s5p-tv/mixer.h
36371+++ b/drivers/media/platform/s5p-tv/mixer.h
36372@@ -155,7 +155,7 @@ struct mxr_layer {
36373 /** layer index (unique identifier) */
36374 int idx;
36375 /** callbacks for layer methods */
36376- struct mxr_layer_ops ops;
36377+ struct mxr_layer_ops *ops;
36378 /** format array */
36379 const struct mxr_format **fmt_array;
36380 /** size of format array */
36381diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
36382index b93a21f..2535195 100644
36383--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
36384+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
36385@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
36386 {
36387 struct mxr_layer *layer;
36388 int ret;
36389- struct mxr_layer_ops ops = {
36390+ static struct mxr_layer_ops ops = {
36391 .release = mxr_graph_layer_release,
36392 .buffer_set = mxr_graph_buffer_set,
36393 .stream_set = mxr_graph_stream_set,
36394diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
36395index 3b1670a..595c939 100644
36396--- a/drivers/media/platform/s5p-tv/mixer_reg.c
36397+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
36398@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
36399 layer->update_buf = next;
36400 }
36401
36402- layer->ops.buffer_set(layer, layer->update_buf);
36403+ layer->ops->buffer_set(layer, layer->update_buf);
36404
36405 if (done && done != layer->shadow_buf)
36406 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
36407diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
36408index 1f3b743..e839271 100644
36409--- a/drivers/media/platform/s5p-tv/mixer_video.c
36410+++ b/drivers/media/platform/s5p-tv/mixer_video.c
36411@@ -208,7 +208,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
36412 layer->geo.src.height = layer->geo.src.full_height;
36413
36414 mxr_geometry_dump(mdev, &layer->geo);
36415- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
36416+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
36417 mxr_geometry_dump(mdev, &layer->geo);
36418 }
36419
36420@@ -226,7 +226,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
36421 layer->geo.dst.full_width = mbus_fmt.width;
36422 layer->geo.dst.full_height = mbus_fmt.height;
36423 layer->geo.dst.field = mbus_fmt.field;
36424- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
36425+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
36426
36427 mxr_geometry_dump(mdev, &layer->geo);
36428 }
36429@@ -332,7 +332,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
36430 /* set source size to highest accepted value */
36431 geo->src.full_width = max(geo->dst.full_width, pix->width);
36432 geo->src.full_height = max(geo->dst.full_height, pix->height);
36433- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
36434+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
36435 mxr_geometry_dump(mdev, &layer->geo);
36436 /* set cropping to total visible screen */
36437 geo->src.width = pix->width;
36438@@ -340,12 +340,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
36439 geo->src.x_offset = 0;
36440 geo->src.y_offset = 0;
36441 /* assure consistency of geometry */
36442- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
36443+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
36444 mxr_geometry_dump(mdev, &layer->geo);
36445 /* set full size to lowest possible value */
36446 geo->src.full_width = 0;
36447 geo->src.full_height = 0;
36448- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
36449+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
36450 mxr_geometry_dump(mdev, &layer->geo);
36451
36452 /* returning results */
36453@@ -472,7 +472,7 @@ static int mxr_s_selection(struct file *file, void *fh,
36454 target->width = s->r.width;
36455 target->height = s->r.height;
36456
36457- layer->ops.fix_geometry(layer, stage, s->flags);
36458+ layer->ops->fix_geometry(layer, stage, s->flags);
36459
36460 /* retrieve update selection rectangle */
36461 res.left = target->x_offset;
36462@@ -937,13 +937,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
36463 mxr_output_get(mdev);
36464
36465 mxr_layer_update_output(layer);
36466- layer->ops.format_set(layer);
36467+ layer->ops->format_set(layer);
36468 /* enabling layer in hardware */
36469 spin_lock_irqsave(&layer->enq_slock, flags);
36470 layer->state = MXR_LAYER_STREAMING;
36471 spin_unlock_irqrestore(&layer->enq_slock, flags);
36472
36473- layer->ops.stream_set(layer, MXR_ENABLE);
36474+ layer->ops->stream_set(layer, MXR_ENABLE);
36475 mxr_streamer_get(mdev);
36476
36477 return 0;
36478@@ -1013,7 +1013,7 @@ static int stop_streaming(struct vb2_queue *vq)
36479 spin_unlock_irqrestore(&layer->enq_slock, flags);
36480
36481 /* disabling layer in hardware */
36482- layer->ops.stream_set(layer, MXR_DISABLE);
36483+ layer->ops->stream_set(layer, MXR_DISABLE);
36484 /* remove one streamer */
36485 mxr_streamer_put(mdev);
36486 /* allow changes in output configuration */
36487@@ -1052,8 +1052,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
36488
36489 void mxr_layer_release(struct mxr_layer *layer)
36490 {
36491- if (layer->ops.release)
36492- layer->ops.release(layer);
36493+ if (layer->ops->release)
36494+ layer->ops->release(layer);
36495 }
36496
36497 void mxr_base_layer_release(struct mxr_layer *layer)
36498@@ -1079,7 +1079,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
36499
36500 layer->mdev = mdev;
36501 layer->idx = idx;
36502- layer->ops = *ops;
36503+ layer->ops = ops;
36504
36505 spin_lock_init(&layer->enq_slock);
36506 INIT_LIST_HEAD(&layer->enq_list);
36507diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
36508index 3d13a63..da31bf1 100644
36509--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
36510+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
36511@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
36512 {
36513 struct mxr_layer *layer;
36514 int ret;
36515- struct mxr_layer_ops ops = {
36516+ static struct mxr_layer_ops ops = {
36517 .release = mxr_vp_layer_release,
36518 .buffer_set = mxr_vp_buffer_set,
36519 .stream_set = mxr_vp_stream_set,
36520diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
36521index 643d80a..56bb96b 100644
36522--- a/drivers/media/radio/radio-cadet.c
36523+++ b/drivers/media/radio/radio-cadet.c
36524@@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
36525 unsigned char readbuf[RDS_BUFFER];
36526 int i = 0;
36527
36528+ if (count > RDS_BUFFER)
36529+ return -EFAULT;
36530 mutex_lock(&dev->lock);
36531 if (dev->rdsstat == 0)
36532 cadet_start_rds(dev);
36533@@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
36534 while (i < count && dev->rdsin != dev->rdsout)
36535 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
36536
36537- if (i && copy_to_user(data, readbuf, i))
36538+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
36539 i = -EFAULT;
36540 unlock:
36541 mutex_unlock(&dev->lock);
36542diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
36543index 3940bb0..fb3952a 100644
36544--- a/drivers/media/usb/dvb-usb/cxusb.c
36545+++ b/drivers/media/usb/dvb-usb/cxusb.c
36546@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
36547
36548 struct dib0700_adapter_state {
36549 int (*set_param_save) (struct dvb_frontend *);
36550-};
36551+} __no_const;
36552
36553 static int dib7070_set_param_override(struct dvb_frontend *fe)
36554 {
36555diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
36556index 9382895..ac8093c 100644
36557--- a/drivers/media/usb/dvb-usb/dw2102.c
36558+++ b/drivers/media/usb/dvb-usb/dw2102.c
36559@@ -95,7 +95,7 @@ struct su3000_state {
36560
36561 struct s6x0_state {
36562 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
36563-};
36564+} __no_const;
36565
36566 /* debug */
36567 static int dvb_usb_dw2102_debug;
36568diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
36569index fb69baa..cf7ad22 100644
36570--- a/drivers/message/fusion/mptbase.c
36571+++ b/drivers/message/fusion/mptbase.c
36572@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
36573 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
36574 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
36575
36576+#ifdef CONFIG_GRKERNSEC_HIDESYM
36577+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
36578+#else
36579 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
36580 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
36581+#endif
36582+
36583 /*
36584 * Rounding UP to nearest 4-kB boundary here...
36585 */
36586diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
36587index fa43c39..daeb158 100644
36588--- a/drivers/message/fusion/mptsas.c
36589+++ b/drivers/message/fusion/mptsas.c
36590@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
36591 return 0;
36592 }
36593
36594+static inline void
36595+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
36596+{
36597+ if (phy_info->port_details) {
36598+ phy_info->port_details->rphy = rphy;
36599+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
36600+ ioc->name, rphy));
36601+ }
36602+
36603+ if (rphy) {
36604+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
36605+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
36606+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
36607+ ioc->name, rphy, rphy->dev.release));
36608+ }
36609+}
36610+
36611 /* no mutex */
36612 static void
36613 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
36614@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
36615 return NULL;
36616 }
36617
36618-static inline void
36619-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
36620-{
36621- if (phy_info->port_details) {
36622- phy_info->port_details->rphy = rphy;
36623- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
36624- ioc->name, rphy));
36625- }
36626-
36627- if (rphy) {
36628- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
36629- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
36630- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
36631- ioc->name, rphy, rphy->dev.release));
36632- }
36633-}
36634-
36635 static inline struct sas_port *
36636 mptsas_get_port(struct mptsas_phyinfo *phy_info)
36637 {
36638diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
36639index 164afa7..b6b2e74 100644
36640--- a/drivers/message/fusion/mptscsih.c
36641+++ b/drivers/message/fusion/mptscsih.c
36642@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
36643
36644 h = shost_priv(SChost);
36645
36646- if (h) {
36647- if (h->info_kbuf == NULL)
36648- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
36649- return h->info_kbuf;
36650- h->info_kbuf[0] = '\0';
36651+ if (!h)
36652+ return NULL;
36653
36654- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
36655- h->info_kbuf[size-1] = '\0';
36656- }
36657+ if (h->info_kbuf == NULL)
36658+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
36659+ return h->info_kbuf;
36660+ h->info_kbuf[0] = '\0';
36661+
36662+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
36663+ h->info_kbuf[size-1] = '\0';
36664
36665 return h->info_kbuf;
36666 }
36667diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
36668index 8001aa6..b137580 100644
36669--- a/drivers/message/i2o/i2o_proc.c
36670+++ b/drivers/message/i2o/i2o_proc.c
36671@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
36672 "Array Controller Device"
36673 };
36674
36675-static char *chtostr(char *tmp, u8 *chars, int n)
36676-{
36677- tmp[0] = 0;
36678- return strncat(tmp, (char *)chars, n);
36679-}
36680-
36681 static int i2o_report_query_status(struct seq_file *seq, int block_status,
36682 char *group)
36683 {
36684@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
36685 } *result;
36686
36687 i2o_exec_execute_ddm_table ddm_table;
36688- char tmp[28 + 1];
36689
36690 result = kmalloc(sizeof(*result), GFP_KERNEL);
36691 if (!result)
36692@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
36693
36694 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
36695 seq_printf(seq, "%-#8x", ddm_table.module_id);
36696- seq_printf(seq, "%-29s",
36697- chtostr(tmp, ddm_table.module_name_version, 28));
36698+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
36699 seq_printf(seq, "%9d ", ddm_table.data_size);
36700 seq_printf(seq, "%8d", ddm_table.code_size);
36701
36702@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
36703
36704 i2o_driver_result_table *result;
36705 i2o_driver_store_table *dst;
36706- char tmp[28 + 1];
36707
36708 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
36709 if (result == NULL)
36710@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
36711
36712 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
36713 seq_printf(seq, "%-#8x", dst->module_id);
36714- seq_printf(seq, "%-29s",
36715- chtostr(tmp, dst->module_name_version, 28));
36716- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
36717+ seq_printf(seq, "%-.28s", dst->module_name_version);
36718+ seq_printf(seq, "%-.8s", dst->date);
36719 seq_printf(seq, "%8d ", dst->module_size);
36720 seq_printf(seq, "%8d ", dst->mpb_size);
36721 seq_printf(seq, "0x%04x", dst->module_flags);
36722@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
36723 // == (allow) 512d bytes (max)
36724 static u16 *work16 = (u16 *) work32;
36725 int token;
36726- char tmp[16 + 1];
36727
36728 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
36729
36730@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
36731 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
36732 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
36733 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
36734- seq_printf(seq, "Vendor info : %s\n",
36735- chtostr(tmp, (u8 *) (work32 + 2), 16));
36736- seq_printf(seq, "Product info : %s\n",
36737- chtostr(tmp, (u8 *) (work32 + 6), 16));
36738- seq_printf(seq, "Description : %s\n",
36739- chtostr(tmp, (u8 *) (work32 + 10), 16));
36740- seq_printf(seq, "Product rev. : %s\n",
36741- chtostr(tmp, (u8 *) (work32 + 14), 8));
36742+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
36743+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
36744+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
36745+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
36746
36747 seq_printf(seq, "Serial number : ");
36748 print_serial_number(seq, (u8 *) (work32 + 16),
36749@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
36750 u8 pad[256]; // allow up to 256 byte (max) serial number
36751 } result;
36752
36753- char tmp[24 + 1];
36754-
36755 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
36756
36757 if (token < 0) {
36758@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
36759 }
36760
36761 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
36762- seq_printf(seq, "Module name : %s\n",
36763- chtostr(tmp, result.module_name, 24));
36764- seq_printf(seq, "Module revision : %s\n",
36765- chtostr(tmp, result.module_rev, 8));
36766+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
36767+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
36768
36769 seq_printf(seq, "Serial number : ");
36770 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
36771@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
36772 u8 instance_number[4];
36773 } result;
36774
36775- char tmp[64 + 1];
36776-
36777 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
36778
36779 if (token < 0) {
36780@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
36781 return 0;
36782 }
36783
36784- seq_printf(seq, "Device name : %s\n",
36785- chtostr(tmp, result.device_name, 64));
36786- seq_printf(seq, "Service name : %s\n",
36787- chtostr(tmp, result.service_name, 64));
36788- seq_printf(seq, "Physical name : %s\n",
36789- chtostr(tmp, result.physical_location, 64));
36790- seq_printf(seq, "Instance number : %s\n",
36791- chtostr(tmp, result.instance_number, 4));
36792+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
36793+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
36794+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
36795+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
36796
36797 return 0;
36798 }
36799diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
36800index a8c08f3..155fe3d 100644
36801--- a/drivers/message/i2o/iop.c
36802+++ b/drivers/message/i2o/iop.c
36803@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
36804
36805 spin_lock_irqsave(&c->context_list_lock, flags);
36806
36807- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
36808- atomic_inc(&c->context_list_counter);
36809+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
36810+ atomic_inc_unchecked(&c->context_list_counter);
36811
36812- entry->context = atomic_read(&c->context_list_counter);
36813+ entry->context = atomic_read_unchecked(&c->context_list_counter);
36814
36815 list_add(&entry->list, &c->context_list);
36816
36817@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
36818
36819 #if BITS_PER_LONG == 64
36820 spin_lock_init(&c->context_list_lock);
36821- atomic_set(&c->context_list_counter, 0);
36822+ atomic_set_unchecked(&c->context_list_counter, 0);
36823 INIT_LIST_HEAD(&c->context_list);
36824 #endif
36825
36826diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
36827index 45ece11..8efa218 100644
36828--- a/drivers/mfd/janz-cmodio.c
36829+++ b/drivers/mfd/janz-cmodio.c
36830@@ -13,6 +13,7 @@
36831
36832 #include <linux/kernel.h>
36833 #include <linux/module.h>
36834+#include <linux/slab.h>
36835 #include <linux/init.h>
36836 #include <linux/pci.h>
36837 #include <linux/interrupt.h>
36838diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
36839index 3aa9a96..59cf685 100644
36840--- a/drivers/misc/kgdbts.c
36841+++ b/drivers/misc/kgdbts.c
36842@@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
36843 char before[BREAK_INSTR_SIZE];
36844 char after[BREAK_INSTR_SIZE];
36845
36846- probe_kernel_read(before, (char *)kgdbts_break_test,
36847+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
36848 BREAK_INSTR_SIZE);
36849 init_simple_test();
36850 ts.tst = plant_and_detach_test;
36851@@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
36852 /* Activate test with initial breakpoint */
36853 if (!is_early)
36854 kgdb_breakpoint();
36855- probe_kernel_read(after, (char *)kgdbts_break_test,
36856+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
36857 BREAK_INSTR_SIZE);
36858 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
36859 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
36860diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
36861index 4a87e5c..76bdf5c 100644
36862--- a/drivers/misc/lis3lv02d/lis3lv02d.c
36863+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
36864@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
36865 * the lid is closed. This leads to interrupts as soon as a little move
36866 * is done.
36867 */
36868- atomic_inc(&lis3->count);
36869+ atomic_inc_unchecked(&lis3->count);
36870
36871 wake_up_interruptible(&lis3->misc_wait);
36872 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
36873@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
36874 if (lis3->pm_dev)
36875 pm_runtime_get_sync(lis3->pm_dev);
36876
36877- atomic_set(&lis3->count, 0);
36878+ atomic_set_unchecked(&lis3->count, 0);
36879 return 0;
36880 }
36881
36882@@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
36883 add_wait_queue(&lis3->misc_wait, &wait);
36884 while (true) {
36885 set_current_state(TASK_INTERRUPTIBLE);
36886- data = atomic_xchg(&lis3->count, 0);
36887+ data = atomic_xchg_unchecked(&lis3->count, 0);
36888 if (data)
36889 break;
36890
36891@@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
36892 struct lis3lv02d, miscdev);
36893
36894 poll_wait(file, &lis3->misc_wait, wait);
36895- if (atomic_read(&lis3->count))
36896+ if (atomic_read_unchecked(&lis3->count))
36897 return POLLIN | POLLRDNORM;
36898 return 0;
36899 }
36900diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
36901index c439c82..1f20f57 100644
36902--- a/drivers/misc/lis3lv02d/lis3lv02d.h
36903+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
36904@@ -297,7 +297,7 @@ struct lis3lv02d {
36905 struct input_polled_dev *idev; /* input device */
36906 struct platform_device *pdev; /* platform device */
36907 struct regulator_bulk_data regulators[2];
36908- atomic_t count; /* interrupt count after last read */
36909+ atomic_unchecked_t count; /* interrupt count after last read */
36910 union axis_conversion ac; /* hw -> logical axis */
36911 int mapped_btns[3];
36912
36913diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
36914index 2f30bad..c4c13d0 100644
36915--- a/drivers/misc/sgi-gru/gruhandles.c
36916+++ b/drivers/misc/sgi-gru/gruhandles.c
36917@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
36918 unsigned long nsec;
36919
36920 nsec = CLKS2NSEC(clks);
36921- atomic_long_inc(&mcs_op_statistics[op].count);
36922- atomic_long_add(nsec, &mcs_op_statistics[op].total);
36923+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
36924+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
36925 if (mcs_op_statistics[op].max < nsec)
36926 mcs_op_statistics[op].max = nsec;
36927 }
36928diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
36929index 950dbe9..eeef0f8 100644
36930--- a/drivers/misc/sgi-gru/gruprocfs.c
36931+++ b/drivers/misc/sgi-gru/gruprocfs.c
36932@@ -32,9 +32,9 @@
36933
36934 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
36935
36936-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
36937+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
36938 {
36939- unsigned long val = atomic_long_read(v);
36940+ unsigned long val = atomic_long_read_unchecked(v);
36941
36942 seq_printf(s, "%16lu %s\n", val, id);
36943 }
36944@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
36945
36946 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
36947 for (op = 0; op < mcsop_last; op++) {
36948- count = atomic_long_read(&mcs_op_statistics[op].count);
36949- total = atomic_long_read(&mcs_op_statistics[op].total);
36950+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
36951+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
36952 max = mcs_op_statistics[op].max;
36953 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
36954 count ? total / count : 0, max);
36955diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
36956index 5c3ce24..4915ccb 100644
36957--- a/drivers/misc/sgi-gru/grutables.h
36958+++ b/drivers/misc/sgi-gru/grutables.h
36959@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
36960 * GRU statistics.
36961 */
36962 struct gru_stats_s {
36963- atomic_long_t vdata_alloc;
36964- atomic_long_t vdata_free;
36965- atomic_long_t gts_alloc;
36966- atomic_long_t gts_free;
36967- atomic_long_t gms_alloc;
36968- atomic_long_t gms_free;
36969- atomic_long_t gts_double_allocate;
36970- atomic_long_t assign_context;
36971- atomic_long_t assign_context_failed;
36972- atomic_long_t free_context;
36973- atomic_long_t load_user_context;
36974- atomic_long_t load_kernel_context;
36975- atomic_long_t lock_kernel_context;
36976- atomic_long_t unlock_kernel_context;
36977- atomic_long_t steal_user_context;
36978- atomic_long_t steal_kernel_context;
36979- atomic_long_t steal_context_failed;
36980- atomic_long_t nopfn;
36981- atomic_long_t asid_new;
36982- atomic_long_t asid_next;
36983- atomic_long_t asid_wrap;
36984- atomic_long_t asid_reuse;
36985- atomic_long_t intr;
36986- atomic_long_t intr_cbr;
36987- atomic_long_t intr_tfh;
36988- atomic_long_t intr_spurious;
36989- atomic_long_t intr_mm_lock_failed;
36990- atomic_long_t call_os;
36991- atomic_long_t call_os_wait_queue;
36992- atomic_long_t user_flush_tlb;
36993- atomic_long_t user_unload_context;
36994- atomic_long_t user_exception;
36995- atomic_long_t set_context_option;
36996- atomic_long_t check_context_retarget_intr;
36997- atomic_long_t check_context_unload;
36998- atomic_long_t tlb_dropin;
36999- atomic_long_t tlb_preload_page;
37000- atomic_long_t tlb_dropin_fail_no_asid;
37001- atomic_long_t tlb_dropin_fail_upm;
37002- atomic_long_t tlb_dropin_fail_invalid;
37003- atomic_long_t tlb_dropin_fail_range_active;
37004- atomic_long_t tlb_dropin_fail_idle;
37005- atomic_long_t tlb_dropin_fail_fmm;
37006- atomic_long_t tlb_dropin_fail_no_exception;
37007- atomic_long_t tfh_stale_on_fault;
37008- atomic_long_t mmu_invalidate_range;
37009- atomic_long_t mmu_invalidate_page;
37010- atomic_long_t flush_tlb;
37011- atomic_long_t flush_tlb_gru;
37012- atomic_long_t flush_tlb_gru_tgh;
37013- atomic_long_t flush_tlb_gru_zero_asid;
37014+ atomic_long_unchecked_t vdata_alloc;
37015+ atomic_long_unchecked_t vdata_free;
37016+ atomic_long_unchecked_t gts_alloc;
37017+ atomic_long_unchecked_t gts_free;
37018+ atomic_long_unchecked_t gms_alloc;
37019+ atomic_long_unchecked_t gms_free;
37020+ atomic_long_unchecked_t gts_double_allocate;
37021+ atomic_long_unchecked_t assign_context;
37022+ atomic_long_unchecked_t assign_context_failed;
37023+ atomic_long_unchecked_t free_context;
37024+ atomic_long_unchecked_t load_user_context;
37025+ atomic_long_unchecked_t load_kernel_context;
37026+ atomic_long_unchecked_t lock_kernel_context;
37027+ atomic_long_unchecked_t unlock_kernel_context;
37028+ atomic_long_unchecked_t steal_user_context;
37029+ atomic_long_unchecked_t steal_kernel_context;
37030+ atomic_long_unchecked_t steal_context_failed;
37031+ atomic_long_unchecked_t nopfn;
37032+ atomic_long_unchecked_t asid_new;
37033+ atomic_long_unchecked_t asid_next;
37034+ atomic_long_unchecked_t asid_wrap;
37035+ atomic_long_unchecked_t asid_reuse;
37036+ atomic_long_unchecked_t intr;
37037+ atomic_long_unchecked_t intr_cbr;
37038+ atomic_long_unchecked_t intr_tfh;
37039+ atomic_long_unchecked_t intr_spurious;
37040+ atomic_long_unchecked_t intr_mm_lock_failed;
37041+ atomic_long_unchecked_t call_os;
37042+ atomic_long_unchecked_t call_os_wait_queue;
37043+ atomic_long_unchecked_t user_flush_tlb;
37044+ atomic_long_unchecked_t user_unload_context;
37045+ atomic_long_unchecked_t user_exception;
37046+ atomic_long_unchecked_t set_context_option;
37047+ atomic_long_unchecked_t check_context_retarget_intr;
37048+ atomic_long_unchecked_t check_context_unload;
37049+ atomic_long_unchecked_t tlb_dropin;
37050+ atomic_long_unchecked_t tlb_preload_page;
37051+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
37052+ atomic_long_unchecked_t tlb_dropin_fail_upm;
37053+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
37054+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
37055+ atomic_long_unchecked_t tlb_dropin_fail_idle;
37056+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
37057+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
37058+ atomic_long_unchecked_t tfh_stale_on_fault;
37059+ atomic_long_unchecked_t mmu_invalidate_range;
37060+ atomic_long_unchecked_t mmu_invalidate_page;
37061+ atomic_long_unchecked_t flush_tlb;
37062+ atomic_long_unchecked_t flush_tlb_gru;
37063+ atomic_long_unchecked_t flush_tlb_gru_tgh;
37064+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
37065
37066- atomic_long_t copy_gpa;
37067- atomic_long_t read_gpa;
37068+ atomic_long_unchecked_t copy_gpa;
37069+ atomic_long_unchecked_t read_gpa;
37070
37071- atomic_long_t mesq_receive;
37072- atomic_long_t mesq_receive_none;
37073- atomic_long_t mesq_send;
37074- atomic_long_t mesq_send_failed;
37075- atomic_long_t mesq_noop;
37076- atomic_long_t mesq_send_unexpected_error;
37077- atomic_long_t mesq_send_lb_overflow;
37078- atomic_long_t mesq_send_qlimit_reached;
37079- atomic_long_t mesq_send_amo_nacked;
37080- atomic_long_t mesq_send_put_nacked;
37081- atomic_long_t mesq_page_overflow;
37082- atomic_long_t mesq_qf_locked;
37083- atomic_long_t mesq_qf_noop_not_full;
37084- atomic_long_t mesq_qf_switch_head_failed;
37085- atomic_long_t mesq_qf_unexpected_error;
37086- atomic_long_t mesq_noop_unexpected_error;
37087- atomic_long_t mesq_noop_lb_overflow;
37088- atomic_long_t mesq_noop_qlimit_reached;
37089- atomic_long_t mesq_noop_amo_nacked;
37090- atomic_long_t mesq_noop_put_nacked;
37091- atomic_long_t mesq_noop_page_overflow;
37092+ atomic_long_unchecked_t mesq_receive;
37093+ atomic_long_unchecked_t mesq_receive_none;
37094+ atomic_long_unchecked_t mesq_send;
37095+ atomic_long_unchecked_t mesq_send_failed;
37096+ atomic_long_unchecked_t mesq_noop;
37097+ atomic_long_unchecked_t mesq_send_unexpected_error;
37098+ atomic_long_unchecked_t mesq_send_lb_overflow;
37099+ atomic_long_unchecked_t mesq_send_qlimit_reached;
37100+ atomic_long_unchecked_t mesq_send_amo_nacked;
37101+ atomic_long_unchecked_t mesq_send_put_nacked;
37102+ atomic_long_unchecked_t mesq_page_overflow;
37103+ atomic_long_unchecked_t mesq_qf_locked;
37104+ atomic_long_unchecked_t mesq_qf_noop_not_full;
37105+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
37106+ atomic_long_unchecked_t mesq_qf_unexpected_error;
37107+ atomic_long_unchecked_t mesq_noop_unexpected_error;
37108+ atomic_long_unchecked_t mesq_noop_lb_overflow;
37109+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
37110+ atomic_long_unchecked_t mesq_noop_amo_nacked;
37111+ atomic_long_unchecked_t mesq_noop_put_nacked;
37112+ atomic_long_unchecked_t mesq_noop_page_overflow;
37113
37114 };
37115
37116@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
37117 tghop_invalidate, mcsop_last};
37118
37119 struct mcs_op_statistic {
37120- atomic_long_t count;
37121- atomic_long_t total;
37122+ atomic_long_unchecked_t count;
37123+ atomic_long_unchecked_t total;
37124 unsigned long max;
37125 };
37126
37127@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
37128
37129 #define STAT(id) do { \
37130 if (gru_options & OPT_STATS) \
37131- atomic_long_inc(&gru_stats.id); \
37132+ atomic_long_inc_unchecked(&gru_stats.id); \
37133 } while (0)
37134
37135 #ifdef CONFIG_SGI_GRU_DEBUG
37136diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
37137index c862cd4..0d176fe 100644
37138--- a/drivers/misc/sgi-xp/xp.h
37139+++ b/drivers/misc/sgi-xp/xp.h
37140@@ -288,7 +288,7 @@ struct xpc_interface {
37141 xpc_notify_func, void *);
37142 void (*received) (short, int, void *);
37143 enum xp_retval (*partid_to_nasids) (short, void *);
37144-};
37145+} __no_const;
37146
37147 extern struct xpc_interface xpc_interface;
37148
37149diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
37150index b94d5f7..7f494c5 100644
37151--- a/drivers/misc/sgi-xp/xpc.h
37152+++ b/drivers/misc/sgi-xp/xpc.h
37153@@ -835,6 +835,7 @@ struct xpc_arch_operations {
37154 void (*received_payload) (struct xpc_channel *, void *);
37155 void (*notify_senders_of_disconnect) (struct xpc_channel *);
37156 };
37157+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
37158
37159 /* struct xpc_partition act_state values (for XPC HB) */
37160
37161@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
37162 /* found in xpc_main.c */
37163 extern struct device *xpc_part;
37164 extern struct device *xpc_chan;
37165-extern struct xpc_arch_operations xpc_arch_ops;
37166+extern xpc_arch_operations_no_const xpc_arch_ops;
37167 extern int xpc_disengage_timelimit;
37168 extern int xpc_disengage_timedout;
37169 extern int xpc_activate_IRQ_rcvd;
37170diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
37171index d971817..33bdca5 100644
37172--- a/drivers/misc/sgi-xp/xpc_main.c
37173+++ b/drivers/misc/sgi-xp/xpc_main.c
37174@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
37175 .notifier_call = xpc_system_die,
37176 };
37177
37178-struct xpc_arch_operations xpc_arch_ops;
37179+xpc_arch_operations_no_const xpc_arch_ops;
37180
37181 /*
37182 * Timer function to enforce the timelimit on the partition disengage.
37183@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
37184
37185 if (((die_args->trapnr == X86_TRAP_MF) ||
37186 (die_args->trapnr == X86_TRAP_XF)) &&
37187- !user_mode_vm(die_args->regs))
37188+ !user_mode(die_args->regs))
37189 xpc_die_deactivate();
37190
37191 break;
37192diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
37193index 6d8f701..35b6369 100644
37194--- a/drivers/mmc/core/mmc_ops.c
37195+++ b/drivers/mmc/core/mmc_ops.c
37196@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
37197 void *data_buf;
37198 int is_on_stack;
37199
37200- is_on_stack = object_is_on_stack(buf);
37201+ is_on_stack = object_starts_on_stack(buf);
37202 if (is_on_stack) {
37203 /*
37204 * dma onto stack is unsafe/nonportable, but callers to this
37205diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
37206index 53b8fd9..615b462 100644
37207--- a/drivers/mmc/host/dw_mmc.h
37208+++ b/drivers/mmc/host/dw_mmc.h
37209@@ -205,5 +205,5 @@ struct dw_mci_drv_data {
37210 int (*parse_dt)(struct dw_mci *host);
37211 int (*setup_bus)(struct dw_mci *host,
37212 struct device_node *slot_np, u8 bus_width);
37213-};
37214+} __do_const;
37215 #endif /* _DW_MMC_H_ */
37216diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
37217index 82a8de1..3c56ccb 100644
37218--- a/drivers/mmc/host/sdhci-s3c.c
37219+++ b/drivers/mmc/host/sdhci-s3c.c
37220@@ -721,9 +721,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
37221 * we can use overriding functions instead of default.
37222 */
37223 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
37224- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
37225- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
37226- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
37227+ pax_open_kernel();
37228+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
37229+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
37230+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
37231+ pax_close_kernel();
37232 }
37233
37234 /* It supports additional host capabilities if needed */
37235diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
37236index a4eb8b5..8c0628f 100644
37237--- a/drivers/mtd/devices/doc2000.c
37238+++ b/drivers/mtd/devices/doc2000.c
37239@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
37240
37241 /* The ECC will not be calculated correctly if less than 512 is written */
37242 /* DBB-
37243- if (len != 0x200 && eccbuf)
37244+ if (len != 0x200)
37245 printk(KERN_WARNING
37246 "ECC needs a full sector write (adr: %lx size %lx)\n",
37247 (long) to, (long) len);
37248diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
37249index 0c8bb6b..6f35deb 100644
37250--- a/drivers/mtd/nand/denali.c
37251+++ b/drivers/mtd/nand/denali.c
37252@@ -24,6 +24,7 @@
37253 #include <linux/slab.h>
37254 #include <linux/mtd/mtd.h>
37255 #include <linux/module.h>
37256+#include <linux/slab.h>
37257
37258 #include "denali.h"
37259
37260diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
37261index 51b9d6a..52af9a7 100644
37262--- a/drivers/mtd/nftlmount.c
37263+++ b/drivers/mtd/nftlmount.c
37264@@ -24,6 +24,7 @@
37265 #include <asm/errno.h>
37266 #include <linux/delay.h>
37267 #include <linux/slab.h>
37268+#include <linux/sched.h>
37269 #include <linux/mtd/mtd.h>
37270 #include <linux/mtd/nand.h>
37271 #include <linux/mtd/nftl.h>
37272diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
37273index 70dba5d..11a0919 100644
37274--- a/drivers/net/ethernet/8390/ax88796.c
37275+++ b/drivers/net/ethernet/8390/ax88796.c
37276@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
37277 if (ax->plat->reg_offsets)
37278 ei_local->reg_offset = ax->plat->reg_offsets;
37279 else {
37280+ resource_size_t _mem_size = mem_size;
37281+ do_div(_mem_size, 0x18);
37282 ei_local->reg_offset = ax->reg_offsets;
37283 for (ret = 0; ret < 0x18; ret++)
37284- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
37285+ ax->reg_offsets[ret] = _mem_size * ret;
37286 }
37287
37288 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
37289diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
37290index 0991534..8098e92 100644
37291--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
37292+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
37293@@ -1094,7 +1094,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
37294 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
37295 {
37296 /* RX_MODE controlling object */
37297- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
37298+ bnx2x_init_rx_mode_obj(bp);
37299
37300 /* multicast configuration controlling object */
37301 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
37302diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
37303index 09b625e..15b16fe 100644
37304--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
37305+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
37306@@ -2375,15 +2375,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
37307 return rc;
37308 }
37309
37310-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
37311- struct bnx2x_rx_mode_obj *o)
37312+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
37313 {
37314 if (CHIP_IS_E1x(bp)) {
37315- o->wait_comp = bnx2x_empty_rx_mode_wait;
37316- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
37317+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
37318+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
37319 } else {
37320- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
37321- o->config_rx_mode = bnx2x_set_rx_mode_e2;
37322+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
37323+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
37324 }
37325 }
37326
37327diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
37328index adbd91b..58ec94a 100644
37329--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
37330+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
37331@@ -1293,8 +1293,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
37332
37333 /********************* RX MODE ****************/
37334
37335-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
37336- struct bnx2x_rx_mode_obj *o);
37337+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
37338
37339 /**
37340 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
37341diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
37342index d330e81..ce1fb9a 100644
37343--- a/drivers/net/ethernet/broadcom/tg3.h
37344+++ b/drivers/net/ethernet/broadcom/tg3.h
37345@@ -146,6 +146,7 @@
37346 #define CHIPREV_ID_5750_A0 0x4000
37347 #define CHIPREV_ID_5750_A1 0x4001
37348 #define CHIPREV_ID_5750_A3 0x4003
37349+#define CHIPREV_ID_5750_C1 0x4201
37350 #define CHIPREV_ID_5750_C2 0x4202
37351 #define CHIPREV_ID_5752_A0_HW 0x5000
37352 #define CHIPREV_ID_5752_A0 0x6000
37353diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
37354index 8cffcdf..aadf043 100644
37355--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
37356+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
37357@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
37358 */
37359 struct l2t_skb_cb {
37360 arp_failure_handler_func arp_failure_handler;
37361-};
37362+} __no_const;
37363
37364 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
37365
37366diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
37367index 4c83003..2a2a5b9 100644
37368--- a/drivers/net/ethernet/dec/tulip/de4x5.c
37369+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
37370@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
37371 for (i=0; i<ETH_ALEN; i++) {
37372 tmp.addr[i] = dev->dev_addr[i];
37373 }
37374- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
37375+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
37376 break;
37377
37378 case DE4X5_SET_HWADDR: /* Set the hardware address */
37379@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
37380 spin_lock_irqsave(&lp->lock, flags);
37381 memcpy(&statbuf, &lp->pktStats, ioc->len);
37382 spin_unlock_irqrestore(&lp->lock, flags);
37383- if (copy_to_user(ioc->data, &statbuf, ioc->len))
37384+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
37385 return -EFAULT;
37386 break;
37387 }
37388diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
37389index 4d6f3c5..6169e60 100644
37390--- a/drivers/net/ethernet/emulex/benet/be_main.c
37391+++ b/drivers/net/ethernet/emulex/benet/be_main.c
37392@@ -455,7 +455,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
37393
37394 if (wrapped)
37395 newacc += 65536;
37396- ACCESS_ONCE(*acc) = newacc;
37397+ ACCESS_ONCE_RW(*acc) = newacc;
37398 }
37399
37400 void be_parse_stats(struct be_adapter *adapter)
37401diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
37402index 74d749e..eefb1bd 100644
37403--- a/drivers/net/ethernet/faraday/ftgmac100.c
37404+++ b/drivers/net/ethernet/faraday/ftgmac100.c
37405@@ -31,6 +31,8 @@
37406 #include <linux/netdevice.h>
37407 #include <linux/phy.h>
37408 #include <linux/platform_device.h>
37409+#include <linux/interrupt.h>
37410+#include <linux/irqreturn.h>
37411 #include <net/ip.h>
37412
37413 #include "ftgmac100.h"
37414diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
37415index b901a01..1ff32ee 100644
37416--- a/drivers/net/ethernet/faraday/ftmac100.c
37417+++ b/drivers/net/ethernet/faraday/ftmac100.c
37418@@ -31,6 +31,8 @@
37419 #include <linux/module.h>
37420 #include <linux/netdevice.h>
37421 #include <linux/platform_device.h>
37422+#include <linux/interrupt.h>
37423+#include <linux/irqreturn.h>
37424
37425 #include "ftmac100.h"
37426
37427diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
37428index bb9256a..56d8752 100644
37429--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
37430+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
37431@@ -806,7 +806,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
37432 }
37433
37434 /* update the base incval used to calculate frequency adjustment */
37435- ACCESS_ONCE(adapter->base_incval) = incval;
37436+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
37437 smp_mb();
37438
37439 /* need lock to prevent incorrect read while modifying cyclecounter */
37440diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
37441index fbe5363..266b4e3 100644
37442--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
37443+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
37444@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
37445 struct __vxge_hw_fifo *fifo;
37446 struct vxge_hw_fifo_config *config;
37447 u32 txdl_size, txdl_per_memblock;
37448- struct vxge_hw_mempool_cbs fifo_mp_callback;
37449+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
37450+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
37451+ };
37452+
37453 struct __vxge_hw_virtualpath *vpath;
37454
37455 if ((vp == NULL) || (attr == NULL)) {
37456@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
37457 goto exit;
37458 }
37459
37460- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
37461-
37462 fifo->mempool =
37463 __vxge_hw_mempool_create(vpath->hldev,
37464 fifo->config->memblock_size,
37465diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
37466index 998974f..ecd26db 100644
37467--- a/drivers/net/ethernet/realtek/r8169.c
37468+++ b/drivers/net/ethernet/realtek/r8169.c
37469@@ -741,22 +741,22 @@ struct rtl8169_private {
37470 struct mdio_ops {
37471 void (*write)(struct rtl8169_private *, int, int);
37472 int (*read)(struct rtl8169_private *, int);
37473- } mdio_ops;
37474+ } __no_const mdio_ops;
37475
37476 struct pll_power_ops {
37477 void (*down)(struct rtl8169_private *);
37478 void (*up)(struct rtl8169_private *);
37479- } pll_power_ops;
37480+ } __no_const pll_power_ops;
37481
37482 struct jumbo_ops {
37483 void (*enable)(struct rtl8169_private *);
37484 void (*disable)(struct rtl8169_private *);
37485- } jumbo_ops;
37486+ } __no_const jumbo_ops;
37487
37488 struct csi_ops {
37489 void (*write)(struct rtl8169_private *, int, int);
37490 u32 (*read)(struct rtl8169_private *, int);
37491- } csi_ops;
37492+ } __no_const csi_ops;
37493
37494 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
37495 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
37496diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
37497index 0767043f..08c2553 100644
37498--- a/drivers/net/ethernet/sfc/ptp.c
37499+++ b/drivers/net/ethernet/sfc/ptp.c
37500@@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
37501 (u32)((u64)ptp->start.dma_addr >> 32));
37502
37503 /* Clear flag that signals MC ready */
37504- ACCESS_ONCE(*start) = 0;
37505+ ACCESS_ONCE_RW(*start) = 0;
37506 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
37507 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
37508
37509diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
37510index 0c74a70..3bc6f68 100644
37511--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
37512+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
37513@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
37514
37515 writel(value, ioaddr + MMC_CNTRL);
37516
37517- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
37518- MMC_CNTRL, value);
37519+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
37520+// MMC_CNTRL, value);
37521 }
37522
37523 /* To mask all all interrupts.*/
37524diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
37525index e6fe0d8..2b7d752 100644
37526--- a/drivers/net/hyperv/hyperv_net.h
37527+++ b/drivers/net/hyperv/hyperv_net.h
37528@@ -101,7 +101,7 @@ struct rndis_device {
37529
37530 enum rndis_device_state state;
37531 bool link_state;
37532- atomic_t new_req_id;
37533+ atomic_unchecked_t new_req_id;
37534
37535 spinlock_t request_lock;
37536 struct list_head req_list;
37537diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
37538index 2b657d4..9903bc0 100644
37539--- a/drivers/net/hyperv/rndis_filter.c
37540+++ b/drivers/net/hyperv/rndis_filter.c
37541@@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
37542 * template
37543 */
37544 set = &rndis_msg->msg.set_req;
37545- set->req_id = atomic_inc_return(&dev->new_req_id);
37546+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
37547
37548 /* Add to the request list */
37549 spin_lock_irqsave(&dev->request_lock, flags);
37550@@ -758,7 +758,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
37551
37552 /* Setup the rndis set */
37553 halt = &request->request_msg.msg.halt_req;
37554- halt->req_id = atomic_inc_return(&dev->new_req_id);
37555+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
37556
37557 /* Ignore return since this msg is optional. */
37558 rndis_filter_send_request(dev, request);
37559diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
37560index 1e9cb0b..7839125 100644
37561--- a/drivers/net/ieee802154/fakehard.c
37562+++ b/drivers/net/ieee802154/fakehard.c
37563@@ -386,7 +386,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
37564 phy->transmit_power = 0xbf;
37565
37566 dev->netdev_ops = &fake_ops;
37567- dev->ml_priv = &fake_mlme;
37568+ dev->ml_priv = (void *)&fake_mlme;
37569
37570 priv = netdev_priv(dev);
37571 priv->phy = phy;
37572diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
37573index d3fb97d..e229d3e 100644
37574--- a/drivers/net/macvlan.c
37575+++ b/drivers/net/macvlan.c
37576@@ -913,7 +913,7 @@ static int macvlan_device_event(struct notifier_block *unused,
37577 return NOTIFY_DONE;
37578 }
37579
37580-static struct notifier_block macvlan_notifier_block __read_mostly = {
37581+static struct notifier_block macvlan_notifier_block = {
37582 .notifier_call = macvlan_device_event,
37583 };
37584
37585diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
37586index 0f0f9ce..0ca5819 100644
37587--- a/drivers/net/macvtap.c
37588+++ b/drivers/net/macvtap.c
37589@@ -1100,7 +1100,7 @@ static int macvtap_device_event(struct notifier_block *unused,
37590 return NOTIFY_DONE;
37591 }
37592
37593-static struct notifier_block macvtap_notifier_block __read_mostly = {
37594+static struct notifier_block macvtap_notifier_block = {
37595 .notifier_call = macvtap_device_event,
37596 };
37597
37598diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
37599index daec9b0..6428fcb 100644
37600--- a/drivers/net/phy/mdio-bitbang.c
37601+++ b/drivers/net/phy/mdio-bitbang.c
37602@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
37603 struct mdiobb_ctrl *ctrl = bus->priv;
37604
37605 module_put(ctrl->ops->owner);
37606+ mdiobus_unregister(bus);
37607 mdiobus_free(bus);
37608 }
37609 EXPORT_SYMBOL(free_mdio_bitbang);
37610diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
37611index 0b2706a..ba1430d 100644
37612--- a/drivers/net/ppp/ppp_generic.c
37613+++ b/drivers/net/ppp/ppp_generic.c
37614@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37615 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
37616 struct ppp_stats stats;
37617 struct ppp_comp_stats cstats;
37618- char *vers;
37619
37620 switch (cmd) {
37621 case SIOCGPPPSTATS:
37622@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37623 break;
37624
37625 case SIOCGPPPVER:
37626- vers = PPP_VERSION;
37627- if (copy_to_user(addr, vers, strlen(vers) + 1))
37628+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
37629 break;
37630 err = 0;
37631 break;
37632diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
37633index ad86660..9fd0884 100644
37634--- a/drivers/net/team/team.c
37635+++ b/drivers/net/team/team.c
37636@@ -2601,7 +2601,7 @@ static int team_device_event(struct notifier_block *unused,
37637 return NOTIFY_DONE;
37638 }
37639
37640-static struct notifier_block team_notifier_block __read_mostly = {
37641+static struct notifier_block team_notifier_block = {
37642 .notifier_call = team_device_event,
37643 };
37644
37645diff --git a/drivers/net/tun.c b/drivers/net/tun.c
37646index 2917a86..edd463f 100644
37647--- a/drivers/net/tun.c
37648+++ b/drivers/net/tun.c
37649@@ -1836,7 +1836,7 @@ unlock:
37650 }
37651
37652 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
37653- unsigned long arg, int ifreq_len)
37654+ unsigned long arg, size_t ifreq_len)
37655 {
37656 struct tun_file *tfile = file->private_data;
37657 struct tun_struct *tun;
37658@@ -1848,6 +1848,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
37659 int vnet_hdr_sz;
37660 int ret;
37661
37662+ if (ifreq_len > sizeof ifr)
37663+ return -EFAULT;
37664+
37665 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
37666 if (copy_from_user(&ifr, argp, ifreq_len))
37667 return -EFAULT;
37668diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
37669index cd8ccb2..cff5144 100644
37670--- a/drivers/net/usb/hso.c
37671+++ b/drivers/net/usb/hso.c
37672@@ -71,7 +71,7 @@
37673 #include <asm/byteorder.h>
37674 #include <linux/serial_core.h>
37675 #include <linux/serial.h>
37676-
37677+#include <asm/local.h>
37678
37679 #define MOD_AUTHOR "Option Wireless"
37680 #define MOD_DESCRIPTION "USB High Speed Option driver"
37681@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
37682 struct urb *urb;
37683
37684 urb = serial->rx_urb[0];
37685- if (serial->port.count > 0) {
37686+ if (atomic_read(&serial->port.count) > 0) {
37687 count = put_rxbuf_data(urb, serial);
37688 if (count == -1)
37689 return;
37690@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
37691 DUMP1(urb->transfer_buffer, urb->actual_length);
37692
37693 /* Anyone listening? */
37694- if (serial->port.count == 0)
37695+ if (atomic_read(&serial->port.count) == 0)
37696 return;
37697
37698 if (status == 0) {
37699@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
37700 tty_port_tty_set(&serial->port, tty);
37701
37702 /* check for port already opened, if not set the termios */
37703- serial->port.count++;
37704- if (serial->port.count == 1) {
37705+ if (atomic_inc_return(&serial->port.count) == 1) {
37706 serial->rx_state = RX_IDLE;
37707 /* Force default termio settings */
37708 _hso_serial_set_termios(tty, NULL);
37709@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
37710 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
37711 if (result) {
37712 hso_stop_serial_device(serial->parent);
37713- serial->port.count--;
37714+ atomic_dec(&serial->port.count);
37715 kref_put(&serial->parent->ref, hso_serial_ref_free);
37716 }
37717 } else {
37718@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
37719
37720 /* reset the rts and dtr */
37721 /* do the actual close */
37722- serial->port.count--;
37723+ atomic_dec(&serial->port.count);
37724
37725- if (serial->port.count <= 0) {
37726- serial->port.count = 0;
37727+ if (atomic_read(&serial->port.count) <= 0) {
37728+ atomic_set(&serial->port.count, 0);
37729 tty_port_tty_set(&serial->port, NULL);
37730 if (!usb_gone)
37731 hso_stop_serial_device(serial->parent);
37732@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
37733
37734 /* the actual setup */
37735 spin_lock_irqsave(&serial->serial_lock, flags);
37736- if (serial->port.count)
37737+ if (atomic_read(&serial->port.count))
37738 _hso_serial_set_termios(tty, old);
37739 else
37740 tty->termios = *old;
37741@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
37742 D1("Pending read interrupt on port %d\n", i);
37743 spin_lock(&serial->serial_lock);
37744 if (serial->rx_state == RX_IDLE &&
37745- serial->port.count > 0) {
37746+ atomic_read(&serial->port.count) > 0) {
37747 /* Setup and send a ctrl req read on
37748 * port i */
37749 if (!serial->rx_urb_filled[0]) {
37750@@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
37751 /* Start all serial ports */
37752 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
37753 if (serial_table[i] && (serial_table[i]->interface == iface)) {
37754- if (dev2ser(serial_table[i])->port.count) {
37755+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
37756 result =
37757 hso_start_serial_device(serial_table[i], GFP_NOIO);
37758 hso_kick_transmit(dev2ser(serial_table[i]));
37759diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
37760index 8d78253..bebbb68 100644
37761--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
37762+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
37763@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37764 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
37765 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
37766
37767- ACCESS_ONCE(ads->ds_link) = i->link;
37768- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
37769+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
37770+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
37771
37772 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
37773 ctl6 = SM(i->keytype, AR_EncrType);
37774@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37775
37776 if ((i->is_first || i->is_last) &&
37777 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
37778- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
37779+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
37780 | set11nTries(i->rates, 1)
37781 | set11nTries(i->rates, 2)
37782 | set11nTries(i->rates, 3)
37783 | (i->dur_update ? AR_DurUpdateEna : 0)
37784 | SM(0, AR_BurstDur);
37785
37786- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
37787+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
37788 | set11nRate(i->rates, 1)
37789 | set11nRate(i->rates, 2)
37790 | set11nRate(i->rates, 3);
37791 } else {
37792- ACCESS_ONCE(ads->ds_ctl2) = 0;
37793- ACCESS_ONCE(ads->ds_ctl3) = 0;
37794+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
37795+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
37796 }
37797
37798 if (!i->is_first) {
37799- ACCESS_ONCE(ads->ds_ctl0) = 0;
37800- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
37801- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
37802+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
37803+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
37804+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
37805 return;
37806 }
37807
37808@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37809 break;
37810 }
37811
37812- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
37813+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
37814 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
37815 | SM(i->txpower, AR_XmitPower)
37816 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
37817@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37818 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
37819 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
37820
37821- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
37822- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
37823+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
37824+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
37825
37826 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
37827 return;
37828
37829- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
37830+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
37831 | set11nPktDurRTSCTS(i->rates, 1);
37832
37833- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
37834+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
37835 | set11nPktDurRTSCTS(i->rates, 3);
37836
37837- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
37838+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
37839 | set11nRateFlags(i->rates, 1)
37840 | set11nRateFlags(i->rates, 2)
37841 | set11nRateFlags(i->rates, 3)
37842diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
37843index 301bf72..3f5654f 100644
37844--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
37845+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
37846@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37847 (i->qcu << AR_TxQcuNum_S) | desc_len;
37848
37849 checksum += val;
37850- ACCESS_ONCE(ads->info) = val;
37851+ ACCESS_ONCE_RW(ads->info) = val;
37852
37853 checksum += i->link;
37854- ACCESS_ONCE(ads->link) = i->link;
37855+ ACCESS_ONCE_RW(ads->link) = i->link;
37856
37857 checksum += i->buf_addr[0];
37858- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
37859+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
37860 checksum += i->buf_addr[1];
37861- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
37862+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
37863 checksum += i->buf_addr[2];
37864- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
37865+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
37866 checksum += i->buf_addr[3];
37867- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
37868+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
37869
37870 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
37871- ACCESS_ONCE(ads->ctl3) = val;
37872+ ACCESS_ONCE_RW(ads->ctl3) = val;
37873 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
37874- ACCESS_ONCE(ads->ctl5) = val;
37875+ ACCESS_ONCE_RW(ads->ctl5) = val;
37876 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
37877- ACCESS_ONCE(ads->ctl7) = val;
37878+ ACCESS_ONCE_RW(ads->ctl7) = val;
37879 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
37880- ACCESS_ONCE(ads->ctl9) = val;
37881+ ACCESS_ONCE_RW(ads->ctl9) = val;
37882
37883 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
37884- ACCESS_ONCE(ads->ctl10) = checksum;
37885+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
37886
37887 if (i->is_first || i->is_last) {
37888- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
37889+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
37890 | set11nTries(i->rates, 1)
37891 | set11nTries(i->rates, 2)
37892 | set11nTries(i->rates, 3)
37893 | (i->dur_update ? AR_DurUpdateEna : 0)
37894 | SM(0, AR_BurstDur);
37895
37896- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
37897+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
37898 | set11nRate(i->rates, 1)
37899 | set11nRate(i->rates, 2)
37900 | set11nRate(i->rates, 3);
37901 } else {
37902- ACCESS_ONCE(ads->ctl13) = 0;
37903- ACCESS_ONCE(ads->ctl14) = 0;
37904+ ACCESS_ONCE_RW(ads->ctl13) = 0;
37905+ ACCESS_ONCE_RW(ads->ctl14) = 0;
37906 }
37907
37908 ads->ctl20 = 0;
37909@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37910
37911 ctl17 = SM(i->keytype, AR_EncrType);
37912 if (!i->is_first) {
37913- ACCESS_ONCE(ads->ctl11) = 0;
37914- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
37915- ACCESS_ONCE(ads->ctl15) = 0;
37916- ACCESS_ONCE(ads->ctl16) = 0;
37917- ACCESS_ONCE(ads->ctl17) = ctl17;
37918- ACCESS_ONCE(ads->ctl18) = 0;
37919- ACCESS_ONCE(ads->ctl19) = 0;
37920+ ACCESS_ONCE_RW(ads->ctl11) = 0;
37921+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
37922+ ACCESS_ONCE_RW(ads->ctl15) = 0;
37923+ ACCESS_ONCE_RW(ads->ctl16) = 0;
37924+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
37925+ ACCESS_ONCE_RW(ads->ctl18) = 0;
37926+ ACCESS_ONCE_RW(ads->ctl19) = 0;
37927 return;
37928 }
37929
37930- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
37931+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
37932 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
37933 | SM(i->txpower, AR_XmitPower)
37934 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
37935@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37936 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
37937 ctl12 |= SM(val, AR_PAPRDChainMask);
37938
37939- ACCESS_ONCE(ads->ctl12) = ctl12;
37940- ACCESS_ONCE(ads->ctl17) = ctl17;
37941+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
37942+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
37943
37944- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
37945+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
37946 | set11nPktDurRTSCTS(i->rates, 1);
37947
37948- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
37949+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
37950 | set11nPktDurRTSCTS(i->rates, 3);
37951
37952- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
37953+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
37954 | set11nRateFlags(i->rates, 1)
37955 | set11nRateFlags(i->rates, 2)
37956 | set11nRateFlags(i->rates, 3)
37957 | SM(i->rtscts_rate, AR_RTSCTSRate);
37958
37959- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
37960+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
37961 }
37962
37963 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
37964diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
37965index 9d26fc5..60d9f14 100644
37966--- a/drivers/net/wireless/ath/ath9k/hw.h
37967+++ b/drivers/net/wireless/ath/ath9k/hw.h
37968@@ -658,7 +658,7 @@ struct ath_hw_private_ops {
37969
37970 /* ANI */
37971 void (*ani_cache_ini_regs)(struct ath_hw *ah);
37972-};
37973+} __no_const;
37974
37975 /**
37976 * struct ath_hw_ops - callbacks used by hardware code and driver code
37977@@ -688,7 +688,7 @@ struct ath_hw_ops {
37978 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
37979 struct ath_hw_antcomb_conf *antconf);
37980 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
37981-};
37982+} __no_const;
37983
37984 struct ath_nf_limits {
37985 s16 max;
37986diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
37987index 3726cd6..b655808 100644
37988--- a/drivers/net/wireless/iwlegacy/3945-mac.c
37989+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
37990@@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
37991 */
37992 if (il3945_mod_params.disable_hw_scan) {
37993 D_INFO("Disabling hw_scan\n");
37994- il3945_mac_ops.hw_scan = NULL;
37995+ pax_open_kernel();
37996+ *(void **)&il3945_mac_ops.hw_scan = NULL;
37997+ pax_close_kernel();
37998 }
37999
38000 D_INFO("*** LOAD DRIVER ***\n");
38001diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
38002index 5b9533e..7733880 100644
38003--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
38004+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
38005@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
38006 {
38007 struct iwl_priv *priv = file->private_data;
38008 char buf[64];
38009- int buf_size;
38010+ size_t buf_size;
38011 u32 offset, len;
38012
38013 memset(buf, 0, sizeof(buf));
38014@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
38015 struct iwl_priv *priv = file->private_data;
38016
38017 char buf[8];
38018- int buf_size;
38019+ size_t buf_size;
38020 u32 reset_flag;
38021
38022 memset(buf, 0, sizeof(buf));
38023@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
38024 {
38025 struct iwl_priv *priv = file->private_data;
38026 char buf[8];
38027- int buf_size;
38028+ size_t buf_size;
38029 int ht40;
38030
38031 memset(buf, 0, sizeof(buf));
38032@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
38033 {
38034 struct iwl_priv *priv = file->private_data;
38035 char buf[8];
38036- int buf_size;
38037+ size_t buf_size;
38038 int value;
38039
38040 memset(buf, 0, sizeof(buf));
38041@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
38042 {
38043 struct iwl_priv *priv = file->private_data;
38044 char buf[8];
38045- int buf_size;
38046+ size_t buf_size;
38047 int clear;
38048
38049 memset(buf, 0, sizeof(buf));
38050@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
38051 {
38052 struct iwl_priv *priv = file->private_data;
38053 char buf[8];
38054- int buf_size;
38055+ size_t buf_size;
38056 int trace;
38057
38058 memset(buf, 0, sizeof(buf));
38059@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
38060 {
38061 struct iwl_priv *priv = file->private_data;
38062 char buf[8];
38063- int buf_size;
38064+ size_t buf_size;
38065 int missed;
38066
38067 memset(buf, 0, sizeof(buf));
38068@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
38069
38070 struct iwl_priv *priv = file->private_data;
38071 char buf[8];
38072- int buf_size;
38073+ size_t buf_size;
38074 int plcp;
38075
38076 memset(buf, 0, sizeof(buf));
38077@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
38078
38079 struct iwl_priv *priv = file->private_data;
38080 char buf[8];
38081- int buf_size;
38082+ size_t buf_size;
38083 int flush;
38084
38085 memset(buf, 0, sizeof(buf));
38086@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
38087
38088 struct iwl_priv *priv = file->private_data;
38089 char buf[8];
38090- int buf_size;
38091+ size_t buf_size;
38092 int rts;
38093
38094 if (!priv->cfg->ht_params)
38095@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
38096 {
38097 struct iwl_priv *priv = file->private_data;
38098 char buf[8];
38099- int buf_size;
38100+ size_t buf_size;
38101
38102 memset(buf, 0, sizeof(buf));
38103 buf_size = min(count, sizeof(buf) - 1);
38104@@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
38105 struct iwl_priv *priv = file->private_data;
38106 u32 event_log_flag;
38107 char buf[8];
38108- int buf_size;
38109+ size_t buf_size;
38110
38111 /* check that the interface is up */
38112 if (!iwl_is_ready(priv))
38113@@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
38114 struct iwl_priv *priv = file->private_data;
38115 char buf[8];
38116 u32 calib_disabled;
38117- int buf_size;
38118+ size_t buf_size;
38119
38120 memset(buf, 0, sizeof(buf));
38121 buf_size = min(count, sizeof(buf) - 1);
38122diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
38123index 35708b9..31f7754 100644
38124--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
38125+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
38126@@ -1100,7 +1100,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
38127 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
38128
38129 char buf[8];
38130- int buf_size;
38131+ size_t buf_size;
38132 u32 reset_flag;
38133
38134 memset(buf, 0, sizeof(buf));
38135@@ -1121,7 +1121,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
38136 {
38137 struct iwl_trans *trans = file->private_data;
38138 char buf[8];
38139- int buf_size;
38140+ size_t buf_size;
38141 int csr;
38142
38143 memset(buf, 0, sizeof(buf));
38144diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
38145index ff90855..e46d223 100644
38146--- a/drivers/net/wireless/mac80211_hwsim.c
38147+++ b/drivers/net/wireless/mac80211_hwsim.c
38148@@ -2062,25 +2062,19 @@ static int __init init_mac80211_hwsim(void)
38149
38150 if (channels > 1) {
38151 hwsim_if_comb.num_different_channels = channels;
38152- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
38153- mac80211_hwsim_ops.cancel_hw_scan =
38154- mac80211_hwsim_cancel_hw_scan;
38155- mac80211_hwsim_ops.sw_scan_start = NULL;
38156- mac80211_hwsim_ops.sw_scan_complete = NULL;
38157- mac80211_hwsim_ops.remain_on_channel =
38158- mac80211_hwsim_roc;
38159- mac80211_hwsim_ops.cancel_remain_on_channel =
38160- mac80211_hwsim_croc;
38161- mac80211_hwsim_ops.add_chanctx =
38162- mac80211_hwsim_add_chanctx;
38163- mac80211_hwsim_ops.remove_chanctx =
38164- mac80211_hwsim_remove_chanctx;
38165- mac80211_hwsim_ops.change_chanctx =
38166- mac80211_hwsim_change_chanctx;
38167- mac80211_hwsim_ops.assign_vif_chanctx =
38168- mac80211_hwsim_assign_vif_chanctx;
38169- mac80211_hwsim_ops.unassign_vif_chanctx =
38170- mac80211_hwsim_unassign_vif_chanctx;
38171+ pax_open_kernel();
38172+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
38173+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
38174+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
38175+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
38176+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
38177+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
38178+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
38179+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
38180+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
38181+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
38182+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
38183+ pax_close_kernel();
38184 }
38185
38186 spin_lock_init(&hwsim_radio_lock);
38187diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
38188index abe1d03..fb02c22 100644
38189--- a/drivers/net/wireless/rndis_wlan.c
38190+++ b/drivers/net/wireless/rndis_wlan.c
38191@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
38192
38193 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
38194
38195- if (rts_threshold < 0 || rts_threshold > 2347)
38196+ if (rts_threshold > 2347)
38197 rts_threshold = 2347;
38198
38199 tmp = cpu_to_le32(rts_threshold);
38200diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
38201index 0751b35..246ba3e 100644
38202--- a/drivers/net/wireless/rt2x00/rt2x00.h
38203+++ b/drivers/net/wireless/rt2x00/rt2x00.h
38204@@ -398,7 +398,7 @@ struct rt2x00_intf {
38205 * for hardware which doesn't support hardware
38206 * sequence counting.
38207 */
38208- atomic_t seqno;
38209+ atomic_unchecked_t seqno;
38210 };
38211
38212 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
38213diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
38214index e488b94..14b6a0c 100644
38215--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
38216+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
38217@@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
38218 * sequence counter given by mac80211.
38219 */
38220 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
38221- seqno = atomic_add_return(0x10, &intf->seqno);
38222+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
38223 else
38224- seqno = atomic_read(&intf->seqno);
38225+ seqno = atomic_read_unchecked(&intf->seqno);
38226
38227 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
38228 hdr->seq_ctrl |= cpu_to_le16(seqno);
38229diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
38230index e57ee48..541cf6c 100644
38231--- a/drivers/net/wireless/ti/wl1251/sdio.c
38232+++ b/drivers/net/wireless/ti/wl1251/sdio.c
38233@@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
38234
38235 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
38236
38237- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
38238- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
38239+ pax_open_kernel();
38240+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
38241+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
38242+ pax_close_kernel();
38243
38244 wl1251_info("using dedicated interrupt line");
38245 } else {
38246- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
38247- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
38248+ pax_open_kernel();
38249+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
38250+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
38251+ pax_close_kernel();
38252
38253 wl1251_info("using SDIO interrupt");
38254 }
38255diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
38256index e5f5f8f..fdf15b7 100644
38257--- a/drivers/net/wireless/ti/wl12xx/main.c
38258+++ b/drivers/net/wireless/ti/wl12xx/main.c
38259@@ -644,7 +644,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
38260 sizeof(wl->conf.mem));
38261
38262 /* read data preparation is only needed by wl127x */
38263- wl->ops->prepare_read = wl127x_prepare_read;
38264+ pax_open_kernel();
38265+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
38266+ pax_close_kernel();
38267
38268 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
38269 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
38270@@ -665,7 +667,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
38271 sizeof(wl->conf.mem));
38272
38273 /* read data preparation is only needed by wl127x */
38274- wl->ops->prepare_read = wl127x_prepare_read;
38275+ pax_open_kernel();
38276+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
38277+ pax_close_kernel();
38278
38279 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
38280 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
38281diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
38282index 8d8c1f8..e754844 100644
38283--- a/drivers/net/wireless/ti/wl18xx/main.c
38284+++ b/drivers/net/wireless/ti/wl18xx/main.c
38285@@ -1489,8 +1489,10 @@ static int wl18xx_setup(struct wl1271 *wl)
38286 }
38287
38288 if (!checksum_param) {
38289- wl18xx_ops.set_rx_csum = NULL;
38290- wl18xx_ops.init_vif = NULL;
38291+ pax_open_kernel();
38292+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
38293+ *(void **)&wl18xx_ops.init_vif = NULL;
38294+ pax_close_kernel();
38295 }
38296
38297 /* Enable 11a Band only if we have 5G antennas */
38298diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
38299index d93b2b6..ae50401 100644
38300--- a/drivers/oprofile/buffer_sync.c
38301+++ b/drivers/oprofile/buffer_sync.c
38302@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
38303 if (cookie == NO_COOKIE)
38304 offset = pc;
38305 if (cookie == INVALID_COOKIE) {
38306- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
38307+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
38308 offset = pc;
38309 }
38310 if (cookie != last_cookie) {
38311@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
38312 /* add userspace sample */
38313
38314 if (!mm) {
38315- atomic_inc(&oprofile_stats.sample_lost_no_mm);
38316+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
38317 return 0;
38318 }
38319
38320 cookie = lookup_dcookie(mm, s->eip, &offset);
38321
38322 if (cookie == INVALID_COOKIE) {
38323- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
38324+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
38325 return 0;
38326 }
38327
38328@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
38329 /* ignore backtraces if failed to add a sample */
38330 if (state == sb_bt_start) {
38331 state = sb_bt_ignore;
38332- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
38333+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
38334 }
38335 }
38336 release_mm(mm);
38337diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
38338index c0cc4e7..44d4e54 100644
38339--- a/drivers/oprofile/event_buffer.c
38340+++ b/drivers/oprofile/event_buffer.c
38341@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
38342 }
38343
38344 if (buffer_pos == buffer_size) {
38345- atomic_inc(&oprofile_stats.event_lost_overflow);
38346+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
38347 return;
38348 }
38349
38350diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
38351index ed2c3ec..deda85a 100644
38352--- a/drivers/oprofile/oprof.c
38353+++ b/drivers/oprofile/oprof.c
38354@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
38355 if (oprofile_ops.switch_events())
38356 return;
38357
38358- atomic_inc(&oprofile_stats.multiplex_counter);
38359+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
38360 start_switch_worker();
38361 }
38362
38363diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
38364index 917d28e..d62d981 100644
38365--- a/drivers/oprofile/oprofile_stats.c
38366+++ b/drivers/oprofile/oprofile_stats.c
38367@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
38368 cpu_buf->sample_invalid_eip = 0;
38369 }
38370
38371- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
38372- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
38373- atomic_set(&oprofile_stats.event_lost_overflow, 0);
38374- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
38375- atomic_set(&oprofile_stats.multiplex_counter, 0);
38376+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
38377+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
38378+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
38379+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
38380+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
38381 }
38382
38383
38384diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
38385index 38b6fc0..b5cbfce 100644
38386--- a/drivers/oprofile/oprofile_stats.h
38387+++ b/drivers/oprofile/oprofile_stats.h
38388@@ -13,11 +13,11 @@
38389 #include <linux/atomic.h>
38390
38391 struct oprofile_stat_struct {
38392- atomic_t sample_lost_no_mm;
38393- atomic_t sample_lost_no_mapping;
38394- atomic_t bt_lost_no_mapping;
38395- atomic_t event_lost_overflow;
38396- atomic_t multiplex_counter;
38397+ atomic_unchecked_t sample_lost_no_mm;
38398+ atomic_unchecked_t sample_lost_no_mapping;
38399+ atomic_unchecked_t bt_lost_no_mapping;
38400+ atomic_unchecked_t event_lost_overflow;
38401+ atomic_unchecked_t multiplex_counter;
38402 };
38403
38404 extern struct oprofile_stat_struct oprofile_stats;
38405diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
38406index 849357c..b83c1e0 100644
38407--- a/drivers/oprofile/oprofilefs.c
38408+++ b/drivers/oprofile/oprofilefs.c
38409@@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
38410
38411
38412 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
38413- char const *name, atomic_t *val)
38414+ char const *name, atomic_unchecked_t *val)
38415 {
38416 return __oprofilefs_create_file(sb, root, name,
38417 &atomic_ro_fops, 0444, val);
38418diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
38419index 93404f7..4a313d8 100644
38420--- a/drivers/oprofile/timer_int.c
38421+++ b/drivers/oprofile/timer_int.c
38422@@ -93,7 +93,7 @@ static int __cpuinit oprofile_cpu_notify(struct notifier_block *self,
38423 return NOTIFY_OK;
38424 }
38425
38426-static struct notifier_block __refdata oprofile_cpu_notifier = {
38427+static struct notifier_block oprofile_cpu_notifier = {
38428 .notifier_call = oprofile_cpu_notify,
38429 };
38430
38431diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
38432index 3f56bc0..707d642 100644
38433--- a/drivers/parport/procfs.c
38434+++ b/drivers/parport/procfs.c
38435@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
38436
38437 *ppos += len;
38438
38439- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
38440+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
38441 }
38442
38443 #ifdef CONFIG_PARPORT_1284
38444@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
38445
38446 *ppos += len;
38447
38448- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
38449+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
38450 }
38451 #endif /* IEEE1284.3 support. */
38452
38453diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
38454index a6a71c4..c91097b 100644
38455--- a/drivers/pci/hotplug/cpcihp_generic.c
38456+++ b/drivers/pci/hotplug/cpcihp_generic.c
38457@@ -73,7 +73,6 @@ static u16 port;
38458 static unsigned int enum_bit;
38459 static u8 enum_mask;
38460
38461-static struct cpci_hp_controller_ops generic_hpc_ops;
38462 static struct cpci_hp_controller generic_hpc;
38463
38464 static int __init validate_parameters(void)
38465@@ -139,6 +138,10 @@ static int query_enum(void)
38466 return ((value & enum_mask) == enum_mask);
38467 }
38468
38469+static struct cpci_hp_controller_ops generic_hpc_ops = {
38470+ .query_enum = query_enum,
38471+};
38472+
38473 static int __init cpcihp_generic_init(void)
38474 {
38475 int status;
38476@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
38477 pci_dev_put(dev);
38478
38479 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
38480- generic_hpc_ops.query_enum = query_enum;
38481 generic_hpc.ops = &generic_hpc_ops;
38482
38483 status = cpci_hp_register_controller(&generic_hpc);
38484diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
38485index 449b4bb..257e2e8 100644
38486--- a/drivers/pci/hotplug/cpcihp_zt5550.c
38487+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
38488@@ -59,7 +59,6 @@
38489 /* local variables */
38490 static bool debug;
38491 static bool poll;
38492-static struct cpci_hp_controller_ops zt5550_hpc_ops;
38493 static struct cpci_hp_controller zt5550_hpc;
38494
38495 /* Primary cPCI bus bridge device */
38496@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
38497 return 0;
38498 }
38499
38500+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
38501+ .query_enum = zt5550_hc_query_enum,
38502+};
38503+
38504 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
38505 {
38506 int status;
38507@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
38508 dbg("returned from zt5550_hc_config");
38509
38510 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
38511- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
38512 zt5550_hpc.ops = &zt5550_hpc_ops;
38513 if(!poll) {
38514 zt5550_hpc.irq = hc_dev->irq;
38515 zt5550_hpc.irq_flags = IRQF_SHARED;
38516 zt5550_hpc.dev_id = hc_dev;
38517
38518- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
38519- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
38520- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
38521+ pax_open_kernel();
38522+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
38523+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
38524+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
38525+ pax_open_kernel();
38526 } else {
38527 info("using ENUM# polling mode");
38528 }
38529diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
38530index 76ba8a1..20ca857 100644
38531--- a/drivers/pci/hotplug/cpqphp_nvram.c
38532+++ b/drivers/pci/hotplug/cpqphp_nvram.c
38533@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
38534
38535 void compaq_nvram_init (void __iomem *rom_start)
38536 {
38537+
38538+#ifndef CONFIG_PAX_KERNEXEC
38539 if (rom_start) {
38540 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
38541 }
38542+#endif
38543+
38544 dbg("int15 entry = %p\n", compaq_int15_entry_point);
38545
38546 /* initialize our int15 lock */
38547diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
38548index 8474b6a..ee81993 100644
38549--- a/drivers/pci/pcie/aspm.c
38550+++ b/drivers/pci/pcie/aspm.c
38551@@ -27,9 +27,9 @@
38552 #define MODULE_PARAM_PREFIX "pcie_aspm."
38553
38554 /* Note: those are not register definitions */
38555-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
38556-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
38557-#define ASPM_STATE_L1 (4) /* L1 state */
38558+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
38559+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
38560+#define ASPM_STATE_L1 (4U) /* L1 state */
38561 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
38562 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
38563
38564diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
38565index 6186f03..1a78714 100644
38566--- a/drivers/pci/probe.c
38567+++ b/drivers/pci/probe.c
38568@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
38569 struct pci_bus_region region;
38570 bool bar_too_big = false, bar_disabled = false;
38571
38572- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
38573+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
38574
38575 /* No printks while decoding is disabled! */
38576 if (!dev->mmio_always_on) {
38577diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
38578index 9b8505c..f00870a 100644
38579--- a/drivers/pci/proc.c
38580+++ b/drivers/pci/proc.c
38581@@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
38582 static int __init pci_proc_init(void)
38583 {
38584 struct pci_dev *dev = NULL;
38585+
38586+#ifdef CONFIG_GRKERNSEC_PROC_ADD
38587+#ifdef CONFIG_GRKERNSEC_PROC_USER
38588+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
38589+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
38590+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
38591+#endif
38592+#else
38593 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
38594+#endif
38595 proc_create("devices", 0, proc_bus_pci_dir,
38596 &proc_bus_pci_dev_operations);
38597 proc_initialized = 1;
38598diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
38599index f946ca7..f25c833 100644
38600--- a/drivers/platform/x86/thinkpad_acpi.c
38601+++ b/drivers/platform/x86/thinkpad_acpi.c
38602@@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
38603 return 0;
38604 }
38605
38606-void static hotkey_mask_warn_incomplete_mask(void)
38607+static void hotkey_mask_warn_incomplete_mask(void)
38608 {
38609 /* log only what the user can fix... */
38610 const u32 wantedmask = hotkey_driver_mask &
38611@@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
38612 }
38613 }
38614
38615-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38616- struct tp_nvram_state *newn,
38617- const u32 event_mask)
38618-{
38619-
38620 #define TPACPI_COMPARE_KEY(__scancode, __member) \
38621 do { \
38622 if ((event_mask & (1 << __scancode)) && \
38623@@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38624 tpacpi_hotkey_send_key(__scancode); \
38625 } while (0)
38626
38627- void issue_volchange(const unsigned int oldvol,
38628- const unsigned int newvol)
38629- {
38630- unsigned int i = oldvol;
38631+static void issue_volchange(const unsigned int oldvol,
38632+ const unsigned int newvol,
38633+ const u32 event_mask)
38634+{
38635+ unsigned int i = oldvol;
38636
38637- while (i > newvol) {
38638- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
38639- i--;
38640- }
38641- while (i < newvol) {
38642- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
38643- i++;
38644- }
38645+ while (i > newvol) {
38646+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
38647+ i--;
38648 }
38649+ while (i < newvol) {
38650+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
38651+ i++;
38652+ }
38653+}
38654
38655- void issue_brightnesschange(const unsigned int oldbrt,
38656- const unsigned int newbrt)
38657- {
38658- unsigned int i = oldbrt;
38659+static void issue_brightnesschange(const unsigned int oldbrt,
38660+ const unsigned int newbrt,
38661+ const u32 event_mask)
38662+{
38663+ unsigned int i = oldbrt;
38664
38665- while (i > newbrt) {
38666- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
38667- i--;
38668- }
38669- while (i < newbrt) {
38670- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
38671- i++;
38672- }
38673+ while (i > newbrt) {
38674+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
38675+ i--;
38676+ }
38677+ while (i < newbrt) {
38678+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
38679+ i++;
38680 }
38681+}
38682
38683+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38684+ struct tp_nvram_state *newn,
38685+ const u32 event_mask)
38686+{
38687 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
38688 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
38689 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
38690@@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38691 oldn->volume_level != newn->volume_level) {
38692 /* recently muted, or repeated mute keypress, or
38693 * multiple presses ending in mute */
38694- issue_volchange(oldn->volume_level, newn->volume_level);
38695+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
38696 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
38697 }
38698 } else {
38699@@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38700 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
38701 }
38702 if (oldn->volume_level != newn->volume_level) {
38703- issue_volchange(oldn->volume_level, newn->volume_level);
38704+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
38705 } else if (oldn->volume_toggle != newn->volume_toggle) {
38706 /* repeated vol up/down keypress at end of scale ? */
38707 if (newn->volume_level == 0)
38708@@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38709 /* handle brightness */
38710 if (oldn->brightness_level != newn->brightness_level) {
38711 issue_brightnesschange(oldn->brightness_level,
38712- newn->brightness_level);
38713+ newn->brightness_level,
38714+ event_mask);
38715 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
38716 /* repeated key presses that didn't change state */
38717 if (newn->brightness_level == 0)
38718@@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38719 && !tp_features.bright_unkfw)
38720 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
38721 }
38722+}
38723
38724 #undef TPACPI_COMPARE_KEY
38725 #undef TPACPI_MAY_SEND_KEY
38726-}
38727
38728 /*
38729 * Polling driver
38730diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
38731index 769d265..a3a05ca 100644
38732--- a/drivers/pnp/pnpbios/bioscalls.c
38733+++ b/drivers/pnp/pnpbios/bioscalls.c
38734@@ -58,7 +58,7 @@ do { \
38735 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
38736 } while(0)
38737
38738-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
38739+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
38740 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
38741
38742 /*
38743@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
38744
38745 cpu = get_cpu();
38746 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
38747+
38748+ pax_open_kernel();
38749 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
38750+ pax_close_kernel();
38751
38752 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
38753 spin_lock_irqsave(&pnp_bios_lock, flags);
38754@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
38755 :"memory");
38756 spin_unlock_irqrestore(&pnp_bios_lock, flags);
38757
38758+ pax_open_kernel();
38759 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
38760+ pax_close_kernel();
38761+
38762 put_cpu();
38763
38764 /* If we get here and this is set then the PnP BIOS faulted on us. */
38765@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
38766 return status;
38767 }
38768
38769-void pnpbios_calls_init(union pnp_bios_install_struct *header)
38770+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
38771 {
38772 int i;
38773
38774@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
38775 pnp_bios_callpoint.offset = header->fields.pm16offset;
38776 pnp_bios_callpoint.segment = PNP_CS16;
38777
38778+ pax_open_kernel();
38779+
38780 for_each_possible_cpu(i) {
38781 struct desc_struct *gdt = get_cpu_gdt_table(i);
38782 if (!gdt)
38783@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
38784 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
38785 (unsigned long)__va(header->fields.pm16dseg));
38786 }
38787+
38788+ pax_close_kernel();
38789 }
38790diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
38791index 3e6db1c..1fbbdae 100644
38792--- a/drivers/pnp/resource.c
38793+++ b/drivers/pnp/resource.c
38794@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
38795 return 1;
38796
38797 /* check if the resource is valid */
38798- if (*irq < 0 || *irq > 15)
38799+ if (*irq > 15)
38800 return 0;
38801
38802 /* check if the resource is reserved */
38803@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
38804 return 1;
38805
38806 /* check if the resource is valid */
38807- if (*dma < 0 || *dma == 4 || *dma > 7)
38808+ if (*dma == 4 || *dma > 7)
38809 return 0;
38810
38811 /* check if the resource is reserved */
38812diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
38813index 7df7c5f..bd48c47 100644
38814--- a/drivers/power/pda_power.c
38815+++ b/drivers/power/pda_power.c
38816@@ -37,7 +37,11 @@ static int polling;
38817
38818 #ifdef CONFIG_USB_OTG_UTILS
38819 static struct usb_phy *transceiver;
38820-static struct notifier_block otg_nb;
38821+static int otg_handle_notification(struct notifier_block *nb,
38822+ unsigned long event, void *unused);
38823+static struct notifier_block otg_nb = {
38824+ .notifier_call = otg_handle_notification
38825+};
38826 #endif
38827
38828 static struct regulator *ac_draw;
38829@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
38830
38831 #ifdef CONFIG_USB_OTG_UTILS
38832 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
38833- otg_nb.notifier_call = otg_handle_notification;
38834 ret = usb_register_notifier(transceiver, &otg_nb);
38835 if (ret) {
38836 dev_err(dev, "failure to register otg notifier\n");
38837diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
38838index 4d7c635..9860196 100644
38839--- a/drivers/regulator/max8660.c
38840+++ b/drivers/regulator/max8660.c
38841@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
38842 max8660->shadow_regs[MAX8660_OVER1] = 5;
38843 } else {
38844 /* Otherwise devices can be toggled via software */
38845- max8660_dcdc_ops.enable = max8660_dcdc_enable;
38846- max8660_dcdc_ops.disable = max8660_dcdc_disable;
38847+ pax_open_kernel();
38848+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
38849+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
38850+ pax_close_kernel();
38851 }
38852
38853 /*
38854diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
38855index 9a8ea91..c483dd9 100644
38856--- a/drivers/regulator/max8973-regulator.c
38857+++ b/drivers/regulator/max8973-regulator.c
38858@@ -401,9 +401,11 @@ static int max8973_probe(struct i2c_client *client,
38859 if (!pdata->enable_ext_control) {
38860 max->desc.enable_reg = MAX8973_VOUT;
38861 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
38862- max8973_dcdc_ops.enable = regulator_enable_regmap;
38863- max8973_dcdc_ops.disable = regulator_disable_regmap;
38864- max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
38865+ pax_open_kernel();
38866+ *(void **)&max8973_dcdc_ops.enable = regulator_enable_regmap;
38867+ *(void **)&max8973_dcdc_ops.disable = regulator_disable_regmap;
38868+ *(void **)&max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
38869+ pax_close_kernel();
38870 }
38871
38872 max->enable_external_control = pdata->enable_ext_control;
38873diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
38874index 0d84b1f..c2da6ac 100644
38875--- a/drivers/regulator/mc13892-regulator.c
38876+++ b/drivers/regulator/mc13892-regulator.c
38877@@ -540,10 +540,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
38878 }
38879 mc13xxx_unlock(mc13892);
38880
38881- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
38882+ pax_open_kernel();
38883+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
38884 = mc13892_vcam_set_mode;
38885- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
38886+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
38887 = mc13892_vcam_get_mode;
38888+ pax_close_kernel();
38889
38890 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
38891 ARRAY_SIZE(mc13892_regulators));
38892diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
38893index 9a86b4b..3a383dc 100644
38894--- a/drivers/rtc/rtc-dev.c
38895+++ b/drivers/rtc/rtc-dev.c
38896@@ -14,6 +14,7 @@
38897 #include <linux/module.h>
38898 #include <linux/rtc.h>
38899 #include <linux/sched.h>
38900+#include <linux/grsecurity.h>
38901 #include "rtc-core.h"
38902
38903 static dev_t rtc_devt;
38904@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
38905 if (copy_from_user(&tm, uarg, sizeof(tm)))
38906 return -EFAULT;
38907
38908+ gr_log_timechange();
38909+
38910 return rtc_set_time(rtc, &tm);
38911
38912 case RTC_PIE_ON:
38913diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
38914index 4ad7e36..d004679 100644
38915--- a/drivers/scsi/bfa/bfa.h
38916+++ b/drivers/scsi/bfa/bfa.h
38917@@ -196,7 +196,7 @@ struct bfa_hwif_s {
38918 u32 *end);
38919 int cpe_vec_q0;
38920 int rme_vec_q0;
38921-};
38922+} __no_const;
38923 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
38924
38925 struct bfa_faa_cbfn_s {
38926diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
38927index e693af6..2e525b6 100644
38928--- a/drivers/scsi/bfa/bfa_fcpim.h
38929+++ b/drivers/scsi/bfa/bfa_fcpim.h
38930@@ -36,7 +36,7 @@ struct bfa_iotag_s {
38931
38932 struct bfa_itn_s {
38933 bfa_isr_func_t isr;
38934-};
38935+} __no_const;
38936
38937 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
38938 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
38939diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
38940index 23a90e7..9cf04ee 100644
38941--- a/drivers/scsi/bfa/bfa_ioc.h
38942+++ b/drivers/scsi/bfa/bfa_ioc.h
38943@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
38944 bfa_ioc_disable_cbfn_t disable_cbfn;
38945 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
38946 bfa_ioc_reset_cbfn_t reset_cbfn;
38947-};
38948+} __no_const;
38949
38950 /*
38951 * IOC event notification mechanism.
38952@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
38953 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
38954 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
38955 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
38956-};
38957+} __no_const;
38958
38959 /*
38960 * Queue element to wait for room in request queue. FIFO order is
38961diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
38962index 593085a..47aa999 100644
38963--- a/drivers/scsi/hosts.c
38964+++ b/drivers/scsi/hosts.c
38965@@ -42,7 +42,7 @@
38966 #include "scsi_logging.h"
38967
38968
38969-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
38970+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
38971
38972
38973 static void scsi_host_cls_release(struct device *dev)
38974@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
38975 * subtract one because we increment first then return, but we need to
38976 * know what the next host number was before increment
38977 */
38978- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
38979+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
38980 shost->dma_channel = 0xff;
38981
38982 /* These three are default values which can be overridden */
38983diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
38984index 4f33806..afd6f60 100644
38985--- a/drivers/scsi/hpsa.c
38986+++ b/drivers/scsi/hpsa.c
38987@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
38988 unsigned long flags;
38989
38990 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
38991- return h->access.command_completed(h, q);
38992+ return h->access->command_completed(h, q);
38993
38994 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
38995 a = rq->head[rq->current_entry];
38996@@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
38997 while (!list_empty(&h->reqQ)) {
38998 c = list_entry(h->reqQ.next, struct CommandList, list);
38999 /* can't do anything if fifo is full */
39000- if ((h->access.fifo_full(h))) {
39001+ if ((h->access->fifo_full(h))) {
39002 dev_warn(&h->pdev->dev, "fifo full\n");
39003 break;
39004 }
39005@@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
39006
39007 /* Tell the controller execute command */
39008 spin_unlock_irqrestore(&h->lock, flags);
39009- h->access.submit_command(h, c);
39010+ h->access->submit_command(h, c);
39011 spin_lock_irqsave(&h->lock, flags);
39012 }
39013 spin_unlock_irqrestore(&h->lock, flags);
39014@@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
39015
39016 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
39017 {
39018- return h->access.command_completed(h, q);
39019+ return h->access->command_completed(h, q);
39020 }
39021
39022 static inline bool interrupt_pending(struct ctlr_info *h)
39023 {
39024- return h->access.intr_pending(h);
39025+ return h->access->intr_pending(h);
39026 }
39027
39028 static inline long interrupt_not_for_us(struct ctlr_info *h)
39029 {
39030- return (h->access.intr_pending(h) == 0) ||
39031+ return (h->access->intr_pending(h) == 0) ||
39032 (h->interrupts_enabled == 0);
39033 }
39034
39035@@ -4316,7 +4316,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
39036 if (prod_index < 0)
39037 return -ENODEV;
39038 h->product_name = products[prod_index].product_name;
39039- h->access = *(products[prod_index].access);
39040+ h->access = products[prod_index].access;
39041
39042 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
39043 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
39044@@ -4598,7 +4598,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
39045
39046 assert_spin_locked(&lockup_detector_lock);
39047 remove_ctlr_from_lockup_detector_list(h);
39048- h->access.set_intr_mask(h, HPSA_INTR_OFF);
39049+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
39050 spin_lock_irqsave(&h->lock, flags);
39051 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
39052 spin_unlock_irqrestore(&h->lock, flags);
39053@@ -4775,7 +4775,7 @@ reinit_after_soft_reset:
39054 }
39055
39056 /* make sure the board interrupts are off */
39057- h->access.set_intr_mask(h, HPSA_INTR_OFF);
39058+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
39059
39060 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
39061 goto clean2;
39062@@ -4809,7 +4809,7 @@ reinit_after_soft_reset:
39063 * fake ones to scoop up any residual completions.
39064 */
39065 spin_lock_irqsave(&h->lock, flags);
39066- h->access.set_intr_mask(h, HPSA_INTR_OFF);
39067+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
39068 spin_unlock_irqrestore(&h->lock, flags);
39069 free_irqs(h);
39070 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
39071@@ -4828,9 +4828,9 @@ reinit_after_soft_reset:
39072 dev_info(&h->pdev->dev, "Board READY.\n");
39073 dev_info(&h->pdev->dev,
39074 "Waiting for stale completions to drain.\n");
39075- h->access.set_intr_mask(h, HPSA_INTR_ON);
39076+ h->access->set_intr_mask(h, HPSA_INTR_ON);
39077 msleep(10000);
39078- h->access.set_intr_mask(h, HPSA_INTR_OFF);
39079+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
39080
39081 rc = controller_reset_failed(h->cfgtable);
39082 if (rc)
39083@@ -4851,7 +4851,7 @@ reinit_after_soft_reset:
39084 }
39085
39086 /* Turn the interrupts on so we can service requests */
39087- h->access.set_intr_mask(h, HPSA_INTR_ON);
39088+ h->access->set_intr_mask(h, HPSA_INTR_ON);
39089
39090 hpsa_hba_inquiry(h);
39091 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
39092@@ -4903,7 +4903,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
39093 * To write all data in the battery backed cache to disks
39094 */
39095 hpsa_flush_cache(h);
39096- h->access.set_intr_mask(h, HPSA_INTR_OFF);
39097+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
39098 hpsa_free_irqs_and_disable_msix(h);
39099 }
39100
39101@@ -5071,7 +5071,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
39102 return;
39103 }
39104 /* Change the access methods to the performant access methods */
39105- h->access = SA5_performant_access;
39106+ h->access = &SA5_performant_access;
39107 h->transMethod = CFGTBL_Trans_Performant;
39108 }
39109
39110diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
39111index 9816479..c5d4e97 100644
39112--- a/drivers/scsi/hpsa.h
39113+++ b/drivers/scsi/hpsa.h
39114@@ -79,7 +79,7 @@ struct ctlr_info {
39115 unsigned int msix_vector;
39116 unsigned int msi_vector;
39117 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
39118- struct access_method access;
39119+ struct access_method *access;
39120
39121 /* queue and queue Info */
39122 struct list_head reqQ;
39123diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
39124index c772d8d..35c362c 100644
39125--- a/drivers/scsi/libfc/fc_exch.c
39126+++ b/drivers/scsi/libfc/fc_exch.c
39127@@ -100,12 +100,12 @@ struct fc_exch_mgr {
39128 u16 pool_max_index;
39129
39130 struct {
39131- atomic_t no_free_exch;
39132- atomic_t no_free_exch_xid;
39133- atomic_t xid_not_found;
39134- atomic_t xid_busy;
39135- atomic_t seq_not_found;
39136- atomic_t non_bls_resp;
39137+ atomic_unchecked_t no_free_exch;
39138+ atomic_unchecked_t no_free_exch_xid;
39139+ atomic_unchecked_t xid_not_found;
39140+ atomic_unchecked_t xid_busy;
39141+ atomic_unchecked_t seq_not_found;
39142+ atomic_unchecked_t non_bls_resp;
39143 } stats;
39144 };
39145
39146@@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
39147 /* allocate memory for exchange */
39148 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
39149 if (!ep) {
39150- atomic_inc(&mp->stats.no_free_exch);
39151+ atomic_inc_unchecked(&mp->stats.no_free_exch);
39152 goto out;
39153 }
39154 memset(ep, 0, sizeof(*ep));
39155@@ -786,7 +786,7 @@ out:
39156 return ep;
39157 err:
39158 spin_unlock_bh(&pool->lock);
39159- atomic_inc(&mp->stats.no_free_exch_xid);
39160+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
39161 mempool_free(ep, mp->ep_pool);
39162 return NULL;
39163 }
39164@@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
39165 xid = ntohs(fh->fh_ox_id); /* we originated exch */
39166 ep = fc_exch_find(mp, xid);
39167 if (!ep) {
39168- atomic_inc(&mp->stats.xid_not_found);
39169+ atomic_inc_unchecked(&mp->stats.xid_not_found);
39170 reject = FC_RJT_OX_ID;
39171 goto out;
39172 }
39173@@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
39174 ep = fc_exch_find(mp, xid);
39175 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
39176 if (ep) {
39177- atomic_inc(&mp->stats.xid_busy);
39178+ atomic_inc_unchecked(&mp->stats.xid_busy);
39179 reject = FC_RJT_RX_ID;
39180 goto rel;
39181 }
39182@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
39183 }
39184 xid = ep->xid; /* get our XID */
39185 } else if (!ep) {
39186- atomic_inc(&mp->stats.xid_not_found);
39187+ atomic_inc_unchecked(&mp->stats.xid_not_found);
39188 reject = FC_RJT_RX_ID; /* XID not found */
39189 goto out;
39190 }
39191@@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
39192 } else {
39193 sp = &ep->seq;
39194 if (sp->id != fh->fh_seq_id) {
39195- atomic_inc(&mp->stats.seq_not_found);
39196+ atomic_inc_unchecked(&mp->stats.seq_not_found);
39197 if (f_ctl & FC_FC_END_SEQ) {
39198 /*
39199 * Update sequence_id based on incoming last
39200@@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
39201
39202 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
39203 if (!ep) {
39204- atomic_inc(&mp->stats.xid_not_found);
39205+ atomic_inc_unchecked(&mp->stats.xid_not_found);
39206 goto out;
39207 }
39208 if (ep->esb_stat & ESB_ST_COMPLETE) {
39209- atomic_inc(&mp->stats.xid_not_found);
39210+ atomic_inc_unchecked(&mp->stats.xid_not_found);
39211 goto rel;
39212 }
39213 if (ep->rxid == FC_XID_UNKNOWN)
39214 ep->rxid = ntohs(fh->fh_rx_id);
39215 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
39216- atomic_inc(&mp->stats.xid_not_found);
39217+ atomic_inc_unchecked(&mp->stats.xid_not_found);
39218 goto rel;
39219 }
39220 if (ep->did != ntoh24(fh->fh_s_id) &&
39221 ep->did != FC_FID_FLOGI) {
39222- atomic_inc(&mp->stats.xid_not_found);
39223+ atomic_inc_unchecked(&mp->stats.xid_not_found);
39224 goto rel;
39225 }
39226 sof = fr_sof(fp);
39227@@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
39228 sp->ssb_stat |= SSB_ST_RESP;
39229 sp->id = fh->fh_seq_id;
39230 } else if (sp->id != fh->fh_seq_id) {
39231- atomic_inc(&mp->stats.seq_not_found);
39232+ atomic_inc_unchecked(&mp->stats.seq_not_found);
39233 goto rel;
39234 }
39235
39236@@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
39237 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
39238
39239 if (!sp)
39240- atomic_inc(&mp->stats.xid_not_found);
39241+ atomic_inc_unchecked(&mp->stats.xid_not_found);
39242 else
39243- atomic_inc(&mp->stats.non_bls_resp);
39244+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
39245
39246 fc_frame_free(fp);
39247 }
39248@@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
39249
39250 list_for_each_entry(ema, &lport->ema_list, ema_list) {
39251 mp = ema->mp;
39252- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
39253+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
39254 st->fc_no_free_exch_xid +=
39255- atomic_read(&mp->stats.no_free_exch_xid);
39256- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
39257- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
39258- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
39259- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
39260+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
39261+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
39262+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
39263+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
39264+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
39265 }
39266 }
39267 EXPORT_SYMBOL(fc_exch_update_stats);
39268diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
39269index bdb81cd..d3c7c2c 100644
39270--- a/drivers/scsi/libsas/sas_ata.c
39271+++ b/drivers/scsi/libsas/sas_ata.c
39272@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
39273 .postreset = ata_std_postreset,
39274 .error_handler = ata_std_error_handler,
39275 .post_internal_cmd = sas_ata_post_internal,
39276- .qc_defer = ata_std_qc_defer,
39277+ .qc_defer = ata_std_qc_defer,
39278 .qc_prep = ata_noop_qc_prep,
39279 .qc_issue = sas_ata_qc_issue,
39280 .qc_fill_rtf = sas_ata_qc_fill_rtf,
39281diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
39282index df4c13a..a51e90c 100644
39283--- a/drivers/scsi/lpfc/lpfc.h
39284+++ b/drivers/scsi/lpfc/lpfc.h
39285@@ -424,7 +424,7 @@ struct lpfc_vport {
39286 struct dentry *debug_nodelist;
39287 struct dentry *vport_debugfs_root;
39288 struct lpfc_debugfs_trc *disc_trc;
39289- atomic_t disc_trc_cnt;
39290+ atomic_unchecked_t disc_trc_cnt;
39291 #endif
39292 uint8_t stat_data_enabled;
39293 uint8_t stat_data_blocked;
39294@@ -842,8 +842,8 @@ struct lpfc_hba {
39295 struct timer_list fabric_block_timer;
39296 unsigned long bit_flags;
39297 #define FABRIC_COMANDS_BLOCKED 0
39298- atomic_t num_rsrc_err;
39299- atomic_t num_cmd_success;
39300+ atomic_unchecked_t num_rsrc_err;
39301+ atomic_unchecked_t num_cmd_success;
39302 unsigned long last_rsrc_error_time;
39303 unsigned long last_ramp_down_time;
39304 unsigned long last_ramp_up_time;
39305@@ -879,7 +879,7 @@ struct lpfc_hba {
39306
39307 struct dentry *debug_slow_ring_trc;
39308 struct lpfc_debugfs_trc *slow_ring_trc;
39309- atomic_t slow_ring_trc_cnt;
39310+ atomic_unchecked_t slow_ring_trc_cnt;
39311 /* iDiag debugfs sub-directory */
39312 struct dentry *idiag_root;
39313 struct dentry *idiag_pci_cfg;
39314diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
39315index f63f5ff..de29189 100644
39316--- a/drivers/scsi/lpfc/lpfc_debugfs.c
39317+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
39318@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
39319
39320 #include <linux/debugfs.h>
39321
39322-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
39323+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
39324 static unsigned long lpfc_debugfs_start_time = 0L;
39325
39326 /* iDiag */
39327@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
39328 lpfc_debugfs_enable = 0;
39329
39330 len = 0;
39331- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
39332+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
39333 (lpfc_debugfs_max_disc_trc - 1);
39334 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
39335 dtp = vport->disc_trc + i;
39336@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
39337 lpfc_debugfs_enable = 0;
39338
39339 len = 0;
39340- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
39341+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
39342 (lpfc_debugfs_max_slow_ring_trc - 1);
39343 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
39344 dtp = phba->slow_ring_trc + i;
39345@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
39346 !vport || !vport->disc_trc)
39347 return;
39348
39349- index = atomic_inc_return(&vport->disc_trc_cnt) &
39350+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
39351 (lpfc_debugfs_max_disc_trc - 1);
39352 dtp = vport->disc_trc + index;
39353 dtp->fmt = fmt;
39354 dtp->data1 = data1;
39355 dtp->data2 = data2;
39356 dtp->data3 = data3;
39357- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
39358+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
39359 dtp->jif = jiffies;
39360 #endif
39361 return;
39362@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
39363 !phba || !phba->slow_ring_trc)
39364 return;
39365
39366- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
39367+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
39368 (lpfc_debugfs_max_slow_ring_trc - 1);
39369 dtp = phba->slow_ring_trc + index;
39370 dtp->fmt = fmt;
39371 dtp->data1 = data1;
39372 dtp->data2 = data2;
39373 dtp->data3 = data3;
39374- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
39375+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
39376 dtp->jif = jiffies;
39377 #endif
39378 return;
39379@@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
39380 "slow_ring buffer\n");
39381 goto debug_failed;
39382 }
39383- atomic_set(&phba->slow_ring_trc_cnt, 0);
39384+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
39385 memset(phba->slow_ring_trc, 0,
39386 (sizeof(struct lpfc_debugfs_trc) *
39387 lpfc_debugfs_max_slow_ring_trc));
39388@@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
39389 "buffer\n");
39390 goto debug_failed;
39391 }
39392- atomic_set(&vport->disc_trc_cnt, 0);
39393+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
39394
39395 snprintf(name, sizeof(name), "discovery_trace");
39396 vport->debug_disc_trc =
39397diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
39398index 89ad558..76956c4 100644
39399--- a/drivers/scsi/lpfc/lpfc_init.c
39400+++ b/drivers/scsi/lpfc/lpfc_init.c
39401@@ -10618,8 +10618,10 @@ lpfc_init(void)
39402 "misc_register returned with status %d", error);
39403
39404 if (lpfc_enable_npiv) {
39405- lpfc_transport_functions.vport_create = lpfc_vport_create;
39406- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
39407+ pax_open_kernel();
39408+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
39409+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
39410+ pax_close_kernel();
39411 }
39412 lpfc_transport_template =
39413 fc_attach_transport(&lpfc_transport_functions);
39414diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
39415index 60e5a17..ff7a793 100644
39416--- a/drivers/scsi/lpfc/lpfc_scsi.c
39417+++ b/drivers/scsi/lpfc/lpfc_scsi.c
39418@@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
39419 uint32_t evt_posted;
39420
39421 spin_lock_irqsave(&phba->hbalock, flags);
39422- atomic_inc(&phba->num_rsrc_err);
39423+ atomic_inc_unchecked(&phba->num_rsrc_err);
39424 phba->last_rsrc_error_time = jiffies;
39425
39426 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
39427@@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
39428 unsigned long flags;
39429 struct lpfc_hba *phba = vport->phba;
39430 uint32_t evt_posted;
39431- atomic_inc(&phba->num_cmd_success);
39432+ atomic_inc_unchecked(&phba->num_cmd_success);
39433
39434 if (vport->cfg_lun_queue_depth <= queue_depth)
39435 return;
39436@@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
39437 unsigned long num_rsrc_err, num_cmd_success;
39438 int i;
39439
39440- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
39441- num_cmd_success = atomic_read(&phba->num_cmd_success);
39442+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
39443+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
39444
39445 /*
39446 * The error and success command counters are global per
39447@@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
39448 }
39449 }
39450 lpfc_destroy_vport_work_array(phba, vports);
39451- atomic_set(&phba->num_rsrc_err, 0);
39452- atomic_set(&phba->num_cmd_success, 0);
39453+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
39454+ atomic_set_unchecked(&phba->num_cmd_success, 0);
39455 }
39456
39457 /**
39458@@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
39459 }
39460 }
39461 lpfc_destroy_vport_work_array(phba, vports);
39462- atomic_set(&phba->num_rsrc_err, 0);
39463- atomic_set(&phba->num_cmd_success, 0);
39464+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
39465+ atomic_set_unchecked(&phba->num_cmd_success, 0);
39466 }
39467
39468 /**
39469diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
39470index b46f5e9..c4c4ccb 100644
39471--- a/drivers/scsi/pmcraid.c
39472+++ b/drivers/scsi/pmcraid.c
39473@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
39474 res->scsi_dev = scsi_dev;
39475 scsi_dev->hostdata = res;
39476 res->change_detected = 0;
39477- atomic_set(&res->read_failures, 0);
39478- atomic_set(&res->write_failures, 0);
39479+ atomic_set_unchecked(&res->read_failures, 0);
39480+ atomic_set_unchecked(&res->write_failures, 0);
39481 rc = 0;
39482 }
39483 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
39484@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
39485
39486 /* If this was a SCSI read/write command keep count of errors */
39487 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
39488- atomic_inc(&res->read_failures);
39489+ atomic_inc_unchecked(&res->read_failures);
39490 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
39491- atomic_inc(&res->write_failures);
39492+ atomic_inc_unchecked(&res->write_failures);
39493
39494 if (!RES_IS_GSCSI(res->cfg_entry) &&
39495 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
39496@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
39497 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
39498 * hrrq_id assigned here in queuecommand
39499 */
39500- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
39501+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
39502 pinstance->num_hrrq;
39503 cmd->cmd_done = pmcraid_io_done;
39504
39505@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
39506 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
39507 * hrrq_id assigned here in queuecommand
39508 */
39509- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
39510+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
39511 pinstance->num_hrrq;
39512
39513 if (request_size) {
39514@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
39515
39516 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
39517 /* add resources only after host is added into system */
39518- if (!atomic_read(&pinstance->expose_resources))
39519+ if (!atomic_read_unchecked(&pinstance->expose_resources))
39520 return;
39521
39522 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
39523@@ -5324,8 +5324,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
39524 init_waitqueue_head(&pinstance->reset_wait_q);
39525
39526 atomic_set(&pinstance->outstanding_cmds, 0);
39527- atomic_set(&pinstance->last_message_id, 0);
39528- atomic_set(&pinstance->expose_resources, 0);
39529+ atomic_set_unchecked(&pinstance->last_message_id, 0);
39530+ atomic_set_unchecked(&pinstance->expose_resources, 0);
39531
39532 INIT_LIST_HEAD(&pinstance->free_res_q);
39533 INIT_LIST_HEAD(&pinstance->used_res_q);
39534@@ -6038,7 +6038,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
39535 /* Schedule worker thread to handle CCN and take care of adding and
39536 * removing devices to OS
39537 */
39538- atomic_set(&pinstance->expose_resources, 1);
39539+ atomic_set_unchecked(&pinstance->expose_resources, 1);
39540 schedule_work(&pinstance->worker_q);
39541 return rc;
39542
39543diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
39544index e1d150f..6c6df44 100644
39545--- a/drivers/scsi/pmcraid.h
39546+++ b/drivers/scsi/pmcraid.h
39547@@ -748,7 +748,7 @@ struct pmcraid_instance {
39548 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
39549
39550 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
39551- atomic_t last_message_id;
39552+ atomic_unchecked_t last_message_id;
39553
39554 /* configuration table */
39555 struct pmcraid_config_table *cfg_table;
39556@@ -777,7 +777,7 @@ struct pmcraid_instance {
39557 atomic_t outstanding_cmds;
39558
39559 /* should add/delete resources to mid-layer now ?*/
39560- atomic_t expose_resources;
39561+ atomic_unchecked_t expose_resources;
39562
39563
39564
39565@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
39566 struct pmcraid_config_table_entry_ext cfg_entry_ext;
39567 };
39568 struct scsi_device *scsi_dev; /* Link scsi_device structure */
39569- atomic_t read_failures; /* count of failed READ commands */
39570- atomic_t write_failures; /* count of failed WRITE commands */
39571+ atomic_unchecked_t read_failures; /* count of failed READ commands */
39572+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
39573
39574 /* To indicate add/delete/modify during CCN */
39575 u8 change_detected;
39576diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
39577index 83d7984..a27d947 100644
39578--- a/drivers/scsi/qla2xxx/qla_attr.c
39579+++ b/drivers/scsi/qla2xxx/qla_attr.c
39580@@ -1969,7 +1969,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
39581 return 0;
39582 }
39583
39584-struct fc_function_template qla2xxx_transport_functions = {
39585+fc_function_template_no_const qla2xxx_transport_functions = {
39586
39587 .show_host_node_name = 1,
39588 .show_host_port_name = 1,
39589@@ -2016,7 +2016,7 @@ struct fc_function_template qla2xxx_transport_functions = {
39590 .bsg_timeout = qla24xx_bsg_timeout,
39591 };
39592
39593-struct fc_function_template qla2xxx_transport_vport_functions = {
39594+fc_function_template_no_const qla2xxx_transport_vport_functions = {
39595
39596 .show_host_node_name = 1,
39597 .show_host_port_name = 1,
39598diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
39599index 2411d1a..4673766 100644
39600--- a/drivers/scsi/qla2xxx/qla_gbl.h
39601+++ b/drivers/scsi/qla2xxx/qla_gbl.h
39602@@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
39603 struct device_attribute;
39604 extern struct device_attribute *qla2x00_host_attrs[];
39605 struct fc_function_template;
39606-extern struct fc_function_template qla2xxx_transport_functions;
39607-extern struct fc_function_template qla2xxx_transport_vport_functions;
39608+extern fc_function_template_no_const qla2xxx_transport_functions;
39609+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
39610 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
39611 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
39612 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
39613diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
39614index 10d23f8..a7d5d4c 100644
39615--- a/drivers/scsi/qla2xxx/qla_os.c
39616+++ b/drivers/scsi/qla2xxx/qla_os.c
39617@@ -1472,8 +1472,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
39618 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
39619 /* Ok, a 64bit DMA mask is applicable. */
39620 ha->flags.enable_64bit_addressing = 1;
39621- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
39622- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
39623+ pax_open_kernel();
39624+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
39625+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
39626+ pax_close_kernel();
39627 return;
39628 }
39629 }
39630diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
39631index 329d553..f20d31d 100644
39632--- a/drivers/scsi/qla4xxx/ql4_def.h
39633+++ b/drivers/scsi/qla4xxx/ql4_def.h
39634@@ -273,7 +273,7 @@ struct ddb_entry {
39635 * (4000 only) */
39636 atomic_t relogin_timer; /* Max Time to wait for
39637 * relogin to complete */
39638- atomic_t relogin_retry_count; /* Num of times relogin has been
39639+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
39640 * retried */
39641 uint32_t default_time2wait; /* Default Min time between
39642 * relogins (+aens) */
39643diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
39644index 4cec123..7c1329f 100644
39645--- a/drivers/scsi/qla4xxx/ql4_os.c
39646+++ b/drivers/scsi/qla4xxx/ql4_os.c
39647@@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
39648 */
39649 if (!iscsi_is_session_online(cls_sess)) {
39650 /* Reset retry relogin timer */
39651- atomic_inc(&ddb_entry->relogin_retry_count);
39652+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
39653 DEBUG2(ql4_printk(KERN_INFO, ha,
39654 "%s: index[%d] relogin timed out-retrying"
39655 " relogin (%d), retry (%d)\n", __func__,
39656 ddb_entry->fw_ddb_index,
39657- atomic_read(&ddb_entry->relogin_retry_count),
39658+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
39659 ddb_entry->default_time2wait + 4));
39660 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
39661 atomic_set(&ddb_entry->retry_relogin_timer,
39662@@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
39663
39664 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
39665 atomic_set(&ddb_entry->relogin_timer, 0);
39666- atomic_set(&ddb_entry->relogin_retry_count, 0);
39667+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
39668 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
39669 ddb_entry->default_relogin_timeout =
39670 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
39671diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
39672index 2c0d0ec..4e8681a 100644
39673--- a/drivers/scsi/scsi.c
39674+++ b/drivers/scsi/scsi.c
39675@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
39676 unsigned long timeout;
39677 int rtn = 0;
39678
39679- atomic_inc(&cmd->device->iorequest_cnt);
39680+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
39681
39682 /* check if the device is still usable */
39683 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
39684diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
39685index f1bf5af..f67e943 100644
39686--- a/drivers/scsi/scsi_lib.c
39687+++ b/drivers/scsi/scsi_lib.c
39688@@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
39689 shost = sdev->host;
39690 scsi_init_cmd_errh(cmd);
39691 cmd->result = DID_NO_CONNECT << 16;
39692- atomic_inc(&cmd->device->iorequest_cnt);
39693+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
39694
39695 /*
39696 * SCSI request completion path will do scsi_device_unbusy(),
39697@@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
39698
39699 INIT_LIST_HEAD(&cmd->eh_entry);
39700
39701- atomic_inc(&cmd->device->iodone_cnt);
39702+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
39703 if (cmd->result)
39704- atomic_inc(&cmd->device->ioerr_cnt);
39705+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
39706
39707 disposition = scsi_decide_disposition(cmd);
39708 if (disposition != SUCCESS &&
39709diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
39710index 931a7d9..0c2a754 100644
39711--- a/drivers/scsi/scsi_sysfs.c
39712+++ b/drivers/scsi/scsi_sysfs.c
39713@@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
39714 char *buf) \
39715 { \
39716 struct scsi_device *sdev = to_scsi_device(dev); \
39717- unsigned long long count = atomic_read(&sdev->field); \
39718+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
39719 return snprintf(buf, 20, "0x%llx\n", count); \
39720 } \
39721 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
39722diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
39723index 84a1fdf..693b0d6 100644
39724--- a/drivers/scsi/scsi_tgt_lib.c
39725+++ b/drivers/scsi/scsi_tgt_lib.c
39726@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
39727 int err;
39728
39729 dprintk("%lx %u\n", uaddr, len);
39730- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
39731+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
39732 if (err) {
39733 /*
39734 * TODO: need to fixup sg_tablesize, max_segment_size,
39735diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
39736index e894ca7..de9d7660 100644
39737--- a/drivers/scsi/scsi_transport_fc.c
39738+++ b/drivers/scsi/scsi_transport_fc.c
39739@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
39740 * Netlink Infrastructure
39741 */
39742
39743-static atomic_t fc_event_seq;
39744+static atomic_unchecked_t fc_event_seq;
39745
39746 /**
39747 * fc_get_event_number - Obtain the next sequential FC event number
39748@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
39749 u32
39750 fc_get_event_number(void)
39751 {
39752- return atomic_add_return(1, &fc_event_seq);
39753+ return atomic_add_return_unchecked(1, &fc_event_seq);
39754 }
39755 EXPORT_SYMBOL(fc_get_event_number);
39756
39757@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
39758 {
39759 int error;
39760
39761- atomic_set(&fc_event_seq, 0);
39762+ atomic_set_unchecked(&fc_event_seq, 0);
39763
39764 error = transport_class_register(&fc_host_class);
39765 if (error)
39766@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
39767 char *cp;
39768
39769 *val = simple_strtoul(buf, &cp, 0);
39770- if ((*cp && (*cp != '\n')) || (*val < 0))
39771+ if (*cp && (*cp != '\n'))
39772 return -EINVAL;
39773 /*
39774 * Check for overflow; dev_loss_tmo is u32
39775diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
39776index 31969f2..2b348f0 100644
39777--- a/drivers/scsi/scsi_transport_iscsi.c
39778+++ b/drivers/scsi/scsi_transport_iscsi.c
39779@@ -79,7 +79,7 @@ struct iscsi_internal {
39780 struct transport_container session_cont;
39781 };
39782
39783-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
39784+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
39785 static struct workqueue_struct *iscsi_eh_timer_workq;
39786
39787 static DEFINE_IDA(iscsi_sess_ida);
39788@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
39789 int err;
39790
39791 ihost = shost->shost_data;
39792- session->sid = atomic_add_return(1, &iscsi_session_nr);
39793+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
39794
39795 if (target_id == ISCSI_MAX_TARGET) {
39796 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
39797@@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
39798 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
39799 ISCSI_TRANSPORT_VERSION);
39800
39801- atomic_set(&iscsi_session_nr, 0);
39802+ atomic_set_unchecked(&iscsi_session_nr, 0);
39803
39804 err = class_register(&iscsi_transport_class);
39805 if (err)
39806diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
39807index f379c7f..e8fc69c 100644
39808--- a/drivers/scsi/scsi_transport_srp.c
39809+++ b/drivers/scsi/scsi_transport_srp.c
39810@@ -33,7 +33,7 @@
39811 #include "scsi_transport_srp_internal.h"
39812
39813 struct srp_host_attrs {
39814- atomic_t next_port_id;
39815+ atomic_unchecked_t next_port_id;
39816 };
39817 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
39818
39819@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
39820 struct Scsi_Host *shost = dev_to_shost(dev);
39821 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
39822
39823- atomic_set(&srp_host->next_port_id, 0);
39824+ atomic_set_unchecked(&srp_host->next_port_id, 0);
39825 return 0;
39826 }
39827
39828@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
39829 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
39830 rport->roles = ids->roles;
39831
39832- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
39833+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
39834 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
39835
39836 transport_setup_device(&rport->dev);
39837diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
39838index 7992635..609faf8 100644
39839--- a/drivers/scsi/sd.c
39840+++ b/drivers/scsi/sd.c
39841@@ -2909,7 +2909,7 @@ static int sd_probe(struct device *dev)
39842 sdkp->disk = gd;
39843 sdkp->index = index;
39844 atomic_set(&sdkp->openers, 0);
39845- atomic_set(&sdkp->device->ioerr_cnt, 0);
39846+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
39847
39848 if (!sdp->request_queue->rq_timeout) {
39849 if (sdp->type != TYPE_MOD)
39850diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
39851index be2c9a6..275525c 100644
39852--- a/drivers/scsi/sg.c
39853+++ b/drivers/scsi/sg.c
39854@@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
39855 sdp->disk->disk_name,
39856 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
39857 NULL,
39858- (char *)arg);
39859+ (char __user *)arg);
39860 case BLKTRACESTART:
39861 return blk_trace_startstop(sdp->device->request_queue, 1);
39862 case BLKTRACESTOP:
39863diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
39864index 19ee901..6e8c2ef 100644
39865--- a/drivers/spi/spi.c
39866+++ b/drivers/spi/spi.c
39867@@ -1616,7 +1616,7 @@ int spi_bus_unlock(struct spi_master *master)
39868 EXPORT_SYMBOL_GPL(spi_bus_unlock);
39869
39870 /* portable code must never pass more than 32 bytes */
39871-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
39872+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
39873
39874 static u8 *buf;
39875
39876diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
39877index 34afc16..ffe44dd 100644
39878--- a/drivers/staging/octeon/ethernet-rx.c
39879+++ b/drivers/staging/octeon/ethernet-rx.c
39880@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
39881 /* Increment RX stats for virtual ports */
39882 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
39883 #ifdef CONFIG_64BIT
39884- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
39885- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
39886+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
39887+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
39888 #else
39889- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
39890- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
39891+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
39892+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
39893 #endif
39894 }
39895 netif_receive_skb(skb);
39896@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
39897 dev->name);
39898 */
39899 #ifdef CONFIG_64BIT
39900- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
39901+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
39902 #else
39903- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
39904+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
39905 #endif
39906 dev_kfree_skb_irq(skb);
39907 }
39908diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
39909index ef32dc1..a159d68 100644
39910--- a/drivers/staging/octeon/ethernet.c
39911+++ b/drivers/staging/octeon/ethernet.c
39912@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
39913 * since the RX tasklet also increments it.
39914 */
39915 #ifdef CONFIG_64BIT
39916- atomic64_add(rx_status.dropped_packets,
39917- (atomic64_t *)&priv->stats.rx_dropped);
39918+ atomic64_add_unchecked(rx_status.dropped_packets,
39919+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
39920 #else
39921- atomic_add(rx_status.dropped_packets,
39922- (atomic_t *)&priv->stats.rx_dropped);
39923+ atomic_add_unchecked(rx_status.dropped_packets,
39924+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
39925 #endif
39926 }
39927
39928diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
39929index a2b7e03..aaf3630 100644
39930--- a/drivers/staging/ramster/tmem.c
39931+++ b/drivers/staging/ramster/tmem.c
39932@@ -50,25 +50,25 @@
39933 * A tmem host implementation must use this function to register callbacks
39934 * for memory allocation.
39935 */
39936-static struct tmem_hostops tmem_hostops;
39937+static struct tmem_hostops *tmem_hostops;
39938
39939 static void tmem_objnode_tree_init(void);
39940
39941 void tmem_register_hostops(struct tmem_hostops *m)
39942 {
39943 tmem_objnode_tree_init();
39944- tmem_hostops = *m;
39945+ tmem_hostops = m;
39946 }
39947
39948 /*
39949 * A tmem host implementation must use this function to register
39950 * callbacks for a page-accessible memory (PAM) implementation.
39951 */
39952-static struct tmem_pamops tmem_pamops;
39953+static struct tmem_pamops *tmem_pamops;
39954
39955 void tmem_register_pamops(struct tmem_pamops *m)
39956 {
39957- tmem_pamops = *m;
39958+ tmem_pamops = m;
39959 }
39960
39961 /*
39962@@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
39963 obj->pampd_count = 0;
39964 #ifdef CONFIG_RAMSTER
39965 if (tmem_pamops.new_obj != NULL)
39966- (*tmem_pamops.new_obj)(obj);
39967+ (tmem_pamops->new_obj)(obj);
39968 #endif
39969 SET_SENTINEL(obj, OBJ);
39970
39971@@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
39972 rbnode = rb_next(rbnode);
39973 tmem_pampd_destroy_all_in_obj(obj, true);
39974 tmem_obj_free(obj, hb);
39975- (*tmem_hostops.obj_free)(obj, pool);
39976+ (tmem_hostops->obj_free)(obj, pool);
39977 }
39978 spin_unlock(&hb->lock);
39979 }
39980@@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
39981 ASSERT_SENTINEL(obj, OBJ);
39982 BUG_ON(obj->pool == NULL);
39983 ASSERT_SENTINEL(obj->pool, POOL);
39984- objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
39985+ objnode = (tmem_hostops->objnode_alloc)(obj->pool);
39986 if (unlikely(objnode == NULL))
39987 goto out;
39988 objnode->obj = obj;
39989@@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
39990 ASSERT_SENTINEL(pool, POOL);
39991 objnode->obj->objnode_count--;
39992 objnode->obj = NULL;
39993- (*tmem_hostops.objnode_free)(objnode, pool);
39994+ (tmem_hostops->objnode_free)(objnode, pool);
39995 }
39996
39997 /*
39998@@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
39999 void *old_pampd = *(void **)slot;
40000 *(void **)slot = new_pampd;
40001 if (!no_free)
40002- (*tmem_pamops.free)(old_pampd, obj->pool,
40003+ (tmem_pamops->free)(old_pampd, obj->pool,
40004 NULL, 0, false);
40005 ret = new_pampd;
40006 }
40007@@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
40008 if (objnode->slots[i]) {
40009 if (ht == 1) {
40010 obj->pampd_count--;
40011- (*tmem_pamops.free)(objnode->slots[i],
40012+ (tmem_pamops->free)(objnode->slots[i],
40013 obj->pool, NULL, 0, true);
40014 objnode->slots[i] = NULL;
40015 continue;
40016@@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
40017 return;
40018 if (obj->objnode_tree_height == 0) {
40019 obj->pampd_count--;
40020- (*tmem_pamops.free)(obj->objnode_tree_root,
40021+ (tmem_pamops->free)(obj->objnode_tree_root,
40022 obj->pool, NULL, 0, true);
40023 } else {
40024 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
40025@@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
40026 obj->objnode_tree_root = NULL;
40027 #ifdef CONFIG_RAMSTER
40028 if (tmem_pamops.free_obj != NULL)
40029- (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
40030+ (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
40031 #endif
40032 }
40033
40034@@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
40035 /* if found, is a dup put, flush the old one */
40036 pampd_del = tmem_pampd_delete_from_obj(obj, index);
40037 BUG_ON(pampd_del != pampd);
40038- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
40039+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
40040 if (obj->pampd_count == 0) {
40041 objnew = obj;
40042 objfound = NULL;
40043@@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
40044 pampd = NULL;
40045 }
40046 } else {
40047- obj = objnew = (*tmem_hostops.obj_alloc)(pool);
40048+ obj = objnew = (tmem_hostops->obj_alloc)(pool);
40049 if (unlikely(obj == NULL)) {
40050 ret = -ENOMEM;
40051 goto out;
40052@@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
40053 if (unlikely(ret == -ENOMEM))
40054 /* may have partially built objnode tree ("stump") */
40055 goto delete_and_free;
40056- (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
40057+ (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
40058 goto out;
40059
40060 delete_and_free:
40061 (void)tmem_pampd_delete_from_obj(obj, index);
40062 if (pampd)
40063- (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
40064+ (tmem_pamops->free)(pampd, pool, NULL, 0, true);
40065 if (objnew) {
40066 tmem_obj_free(objnew, hb);
40067- (*tmem_hostops.obj_free)(objnew, pool);
40068+ (tmem_hostops->obj_free)(objnew, pool);
40069 }
40070 out:
40071 spin_unlock(&hb->lock);
40072@@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
40073 if (pampd != NULL) {
40074 BUG_ON(obj == NULL);
40075 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
40076- (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
40077+ (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
40078 } else if (delete) {
40079 BUG_ON(obj == NULL);
40080 (void)tmem_pampd_delete_from_obj(obj, index);
40081@@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
40082 int ret = 0;
40083
40084 if (!is_ephemeral(pool))
40085- new_pampd = (*tmem_pamops.repatriate_preload)(
40086+ new_pampd = (tmem_pamops->repatriate_preload)(
40087 old_pampd, pool, oidp, index, &intransit);
40088 if (intransit)
40089 ret = -EAGAIN;
40090@@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
40091 /* must release the hb->lock else repatriate can't sleep */
40092 spin_unlock(&hb->lock);
40093 if (!intransit)
40094- ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
40095+ ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
40096 oidp, index, free, data);
40097 if (ret == -EAGAIN) {
40098 /* rare I think, but should cond_resched()??? */
40099@@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
40100 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
40101 /* if we bug here, pamops wasn't properly set up for ramster */
40102 BUG_ON(tmem_pamops.replace_in_obj == NULL);
40103- ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
40104+ ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
40105 out:
40106 spin_unlock(&hb->lock);
40107 return ret;
40108@@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
40109 if (free) {
40110 if (obj->pampd_count == 0) {
40111 tmem_obj_free(obj, hb);
40112- (*tmem_hostops.obj_free)(obj, pool);
40113+ (tmem_hostops->obj_free)(obj, pool);
40114 obj = NULL;
40115 }
40116 }
40117 if (free)
40118- ret = (*tmem_pamops.get_data_and_free)(
40119+ ret = (tmem_pamops->get_data_and_free)(
40120 data, sizep, raw, pampd, pool, oidp, index);
40121 else
40122- ret = (*tmem_pamops.get_data)(
40123+ ret = (tmem_pamops->get_data)(
40124 data, sizep, raw, pampd, pool, oidp, index);
40125 if (ret < 0)
40126 goto out;
40127@@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
40128 pampd = tmem_pampd_delete_from_obj(obj, index);
40129 if (pampd == NULL)
40130 goto out;
40131- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
40132+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
40133 if (obj->pampd_count == 0) {
40134 tmem_obj_free(obj, hb);
40135- (*tmem_hostops.obj_free)(obj, pool);
40136+ (tmem_hostops->obj_free)(obj, pool);
40137 }
40138 ret = 0;
40139
40140@@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
40141 goto out;
40142 tmem_pampd_destroy_all_in_obj(obj, false);
40143 tmem_obj_free(obj, hb);
40144- (*tmem_hostops.obj_free)(obj, pool);
40145+ (tmem_hostops->obj_free)(obj, pool);
40146 ret = 0;
40147
40148 out:
40149diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
40150index dc23395..cf7e9b1 100644
40151--- a/drivers/staging/rtl8712/rtl871x_io.h
40152+++ b/drivers/staging/rtl8712/rtl871x_io.h
40153@@ -108,7 +108,7 @@ struct _io_ops {
40154 u8 *pmem);
40155 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
40156 u8 *pmem);
40157-};
40158+} __no_const;
40159
40160 struct io_req {
40161 struct list_head list;
40162diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
40163index 1f5088b..0e59820 100644
40164--- a/drivers/staging/sbe-2t3e3/netdev.c
40165+++ b/drivers/staging/sbe-2t3e3/netdev.c
40166@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40167 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
40168
40169 if (rlen)
40170- if (copy_to_user(data, &resp, rlen))
40171+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
40172 return -EFAULT;
40173
40174 return 0;
40175diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
40176index 5dddc4d..34fcb2f 100644
40177--- a/drivers/staging/usbip/vhci.h
40178+++ b/drivers/staging/usbip/vhci.h
40179@@ -83,7 +83,7 @@ struct vhci_hcd {
40180 unsigned resuming:1;
40181 unsigned long re_timeout;
40182
40183- atomic_t seqnum;
40184+ atomic_unchecked_t seqnum;
40185
40186 /*
40187 * NOTE:
40188diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
40189index c3aa219..bf8b3de 100644
40190--- a/drivers/staging/usbip/vhci_hcd.c
40191+++ b/drivers/staging/usbip/vhci_hcd.c
40192@@ -451,7 +451,7 @@ static void vhci_tx_urb(struct urb *urb)
40193 return;
40194 }
40195
40196- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
40197+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
40198 if (priv->seqnum == 0xffff)
40199 dev_info(&urb->dev->dev, "seqnum max\n");
40200
40201@@ -703,7 +703,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
40202 return -ENOMEM;
40203 }
40204
40205- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
40206+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
40207 if (unlink->seqnum == 0xffff)
40208 pr_info("seqnum max\n");
40209
40210@@ -907,7 +907,7 @@ static int vhci_start(struct usb_hcd *hcd)
40211 vdev->rhport = rhport;
40212 }
40213
40214- atomic_set(&vhci->seqnum, 0);
40215+ atomic_set_unchecked(&vhci->seqnum, 0);
40216 spin_lock_init(&vhci->lock);
40217
40218 hcd->power_budget = 0; /* no limit */
40219diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
40220index ba5f1c0..11d8122 100644
40221--- a/drivers/staging/usbip/vhci_rx.c
40222+++ b/drivers/staging/usbip/vhci_rx.c
40223@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
40224 if (!urb) {
40225 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
40226 pr_info("max seqnum %d\n",
40227- atomic_read(&the_controller->seqnum));
40228+ atomic_read_unchecked(&the_controller->seqnum));
40229 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
40230 return;
40231 }
40232diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
40233index 5f13890..36a044b 100644
40234--- a/drivers/staging/vt6655/hostap.c
40235+++ b/drivers/staging/vt6655/hostap.c
40236@@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
40237 *
40238 */
40239
40240+static net_device_ops_no_const apdev_netdev_ops;
40241+
40242 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
40243 {
40244 PSDevice apdev_priv;
40245 struct net_device *dev = pDevice->dev;
40246 int ret;
40247- const struct net_device_ops apdev_netdev_ops = {
40248- .ndo_start_xmit = pDevice->tx_80211,
40249- };
40250
40251 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
40252
40253@@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
40254 *apdev_priv = *pDevice;
40255 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
40256
40257+ /* only half broken now */
40258+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
40259 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
40260
40261 pDevice->apdev->type = ARPHRD_IEEE80211;
40262diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
40263index 26a7d0e..897b083 100644
40264--- a/drivers/staging/vt6656/hostap.c
40265+++ b/drivers/staging/vt6656/hostap.c
40266@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
40267 *
40268 */
40269
40270+static net_device_ops_no_const apdev_netdev_ops;
40271+
40272 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
40273 {
40274 PSDevice apdev_priv;
40275 struct net_device *dev = pDevice->dev;
40276 int ret;
40277- const struct net_device_ops apdev_netdev_ops = {
40278- .ndo_start_xmit = pDevice->tx_80211,
40279- };
40280
40281 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
40282
40283@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
40284 *apdev_priv = *pDevice;
40285 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
40286
40287+ /* only half broken now */
40288+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
40289 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
40290
40291 pDevice->apdev->type = ARPHRD_IEEE80211;
40292diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
40293index 56c8e60..1920c63 100644
40294--- a/drivers/staging/zcache/tmem.c
40295+++ b/drivers/staging/zcache/tmem.c
40296@@ -39,7 +39,7 @@
40297 * A tmem host implementation must use this function to register callbacks
40298 * for memory allocation.
40299 */
40300-static struct tmem_hostops tmem_hostops;
40301+static tmem_hostops_no_const tmem_hostops;
40302
40303 static void tmem_objnode_tree_init(void);
40304
40305@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
40306 * A tmem host implementation must use this function to register
40307 * callbacks for a page-accessible memory (PAM) implementation
40308 */
40309-static struct tmem_pamops tmem_pamops;
40310+static tmem_pamops_no_const tmem_pamops;
40311
40312 void tmem_register_pamops(struct tmem_pamops *m)
40313 {
40314diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
40315index 0d4aa82..f7832d4 100644
40316--- a/drivers/staging/zcache/tmem.h
40317+++ b/drivers/staging/zcache/tmem.h
40318@@ -180,6 +180,7 @@ struct tmem_pamops {
40319 void (*new_obj)(struct tmem_obj *);
40320 int (*replace_in_obj)(void *, struct tmem_obj *);
40321 };
40322+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
40323 extern void tmem_register_pamops(struct tmem_pamops *m);
40324
40325 /* memory allocation methods provided by the host implementation */
40326@@ -189,6 +190,7 @@ struct tmem_hostops {
40327 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
40328 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
40329 };
40330+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
40331 extern void tmem_register_hostops(struct tmem_hostops *m);
40332
40333 /* core tmem accessor functions */
40334diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
40335index f2aa754..11337b1 100644
40336--- a/drivers/target/target_core_device.c
40337+++ b/drivers/target/target_core_device.c
40338@@ -1375,7 +1375,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
40339 spin_lock_init(&dev->se_port_lock);
40340 spin_lock_init(&dev->se_tmr_lock);
40341 spin_lock_init(&dev->qf_cmd_lock);
40342- atomic_set(&dev->dev_ordered_id, 0);
40343+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
40344 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
40345 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
40346 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
40347diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
40348index bd587b7..173daf3 100644
40349--- a/drivers/target/target_core_transport.c
40350+++ b/drivers/target/target_core_transport.c
40351@@ -1077,7 +1077,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
40352 * Used to determine when ORDERED commands should go from
40353 * Dormant to Active status.
40354 */
40355- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
40356+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
40357 smp_mb__after_atomic_inc();
40358 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
40359 cmd->se_ordered_id, cmd->sam_task_attr,
40360diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
40361index b09c8d1f..c4225c0 100644
40362--- a/drivers/tty/cyclades.c
40363+++ b/drivers/tty/cyclades.c
40364@@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
40365 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
40366 info->port.count);
40367 #endif
40368- info->port.count++;
40369+ atomic_inc(&info->port.count);
40370 #ifdef CY_DEBUG_COUNT
40371 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
40372- current->pid, info->port.count);
40373+ current->pid, atomic_read(&info->port.count));
40374 #endif
40375
40376 /*
40377@@ -3991,7 +3991,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
40378 for (j = 0; j < cy_card[i].nports; j++) {
40379 info = &cy_card[i].ports[j];
40380
40381- if (info->port.count) {
40382+ if (atomic_read(&info->port.count)) {
40383 /* XXX is the ldisc num worth this? */
40384 struct tty_struct *tty;
40385 struct tty_ldisc *ld;
40386diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
40387index 13ee53b..418d164 100644
40388--- a/drivers/tty/hvc/hvc_console.c
40389+++ b/drivers/tty/hvc/hvc_console.c
40390@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
40391
40392 spin_lock_irqsave(&hp->port.lock, flags);
40393 /* Check and then increment for fast path open. */
40394- if (hp->port.count++ > 0) {
40395+ if (atomic_inc_return(&hp->port.count) > 1) {
40396 spin_unlock_irqrestore(&hp->port.lock, flags);
40397 hvc_kick();
40398 return 0;
40399@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
40400
40401 spin_lock_irqsave(&hp->port.lock, flags);
40402
40403- if (--hp->port.count == 0) {
40404+ if (atomic_dec_return(&hp->port.count) == 0) {
40405 spin_unlock_irqrestore(&hp->port.lock, flags);
40406 /* We are done with the tty pointer now. */
40407 tty_port_tty_set(&hp->port, NULL);
40408@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
40409 */
40410 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
40411 } else {
40412- if (hp->port.count < 0)
40413+ if (atomic_read(&hp->port.count) < 0)
40414 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
40415- hp->vtermno, hp->port.count);
40416+ hp->vtermno, atomic_read(&hp->port.count));
40417 spin_unlock_irqrestore(&hp->port.lock, flags);
40418 }
40419 }
40420@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
40421 * open->hangup case this can be called after the final close so prevent
40422 * that from happening for now.
40423 */
40424- if (hp->port.count <= 0) {
40425+ if (atomic_read(&hp->port.count) <= 0) {
40426 spin_unlock_irqrestore(&hp->port.lock, flags);
40427 return;
40428 }
40429
40430- hp->port.count = 0;
40431+ atomic_set(&hp->port.count, 0);
40432 spin_unlock_irqrestore(&hp->port.lock, flags);
40433 tty_port_tty_set(&hp->port, NULL);
40434
40435@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
40436 return -EPIPE;
40437
40438 /* FIXME what's this (unprotected) check for? */
40439- if (hp->port.count <= 0)
40440+ if (atomic_read(&hp->port.count) <= 0)
40441 return -EIO;
40442
40443 spin_lock_irqsave(&hp->lock, flags);
40444diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
40445index 8776357..b2d4afd 100644
40446--- a/drivers/tty/hvc/hvcs.c
40447+++ b/drivers/tty/hvc/hvcs.c
40448@@ -83,6 +83,7 @@
40449 #include <asm/hvcserver.h>
40450 #include <asm/uaccess.h>
40451 #include <asm/vio.h>
40452+#include <asm/local.h>
40453
40454 /*
40455 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
40456@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
40457
40458 spin_lock_irqsave(&hvcsd->lock, flags);
40459
40460- if (hvcsd->port.count > 0) {
40461+ if (atomic_read(&hvcsd->port.count) > 0) {
40462 spin_unlock_irqrestore(&hvcsd->lock, flags);
40463 printk(KERN_INFO "HVCS: vterm state unchanged. "
40464 "The hvcs device node is still in use.\n");
40465@@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
40466 }
40467 }
40468
40469- hvcsd->port.count = 0;
40470+ atomic_set(&hvcsd->port.count, 0);
40471 hvcsd->port.tty = tty;
40472 tty->driver_data = hvcsd;
40473
40474@@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
40475 unsigned long flags;
40476
40477 spin_lock_irqsave(&hvcsd->lock, flags);
40478- hvcsd->port.count++;
40479+ atomic_inc(&hvcsd->port.count);
40480 hvcsd->todo_mask |= HVCS_SCHED_READ;
40481 spin_unlock_irqrestore(&hvcsd->lock, flags);
40482
40483@@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
40484 hvcsd = tty->driver_data;
40485
40486 spin_lock_irqsave(&hvcsd->lock, flags);
40487- if (--hvcsd->port.count == 0) {
40488+ if (atomic_dec_and_test(&hvcsd->port.count)) {
40489
40490 vio_disable_interrupts(hvcsd->vdev);
40491
40492@@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
40493
40494 free_irq(irq, hvcsd);
40495 return;
40496- } else if (hvcsd->port.count < 0) {
40497+ } else if (atomic_read(&hvcsd->port.count) < 0) {
40498 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
40499 " is missmanaged.\n",
40500- hvcsd->vdev->unit_address, hvcsd->port.count);
40501+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
40502 }
40503
40504 spin_unlock_irqrestore(&hvcsd->lock, flags);
40505@@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
40506
40507 spin_lock_irqsave(&hvcsd->lock, flags);
40508 /* Preserve this so that we know how many kref refs to put */
40509- temp_open_count = hvcsd->port.count;
40510+ temp_open_count = atomic_read(&hvcsd->port.count);
40511
40512 /*
40513 * Don't kref put inside the spinlock because the destruction
40514@@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
40515 tty->driver_data = NULL;
40516 hvcsd->port.tty = NULL;
40517
40518- hvcsd->port.count = 0;
40519+ atomic_set(&hvcsd->port.count, 0);
40520
40521 /* This will drop any buffered data on the floor which is OK in a hangup
40522 * scenario. */
40523@@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
40524 * the middle of a write operation? This is a crummy place to do this
40525 * but we want to keep it all in the spinlock.
40526 */
40527- if (hvcsd->port.count <= 0) {
40528+ if (atomic_read(&hvcsd->port.count) <= 0) {
40529 spin_unlock_irqrestore(&hvcsd->lock, flags);
40530 return -ENODEV;
40531 }
40532@@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
40533 {
40534 struct hvcs_struct *hvcsd = tty->driver_data;
40535
40536- if (!hvcsd || hvcsd->port.count <= 0)
40537+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
40538 return 0;
40539
40540 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
40541diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
40542index 2cde13d..645d78f 100644
40543--- a/drivers/tty/ipwireless/tty.c
40544+++ b/drivers/tty/ipwireless/tty.c
40545@@ -29,6 +29,7 @@
40546 #include <linux/tty_driver.h>
40547 #include <linux/tty_flip.h>
40548 #include <linux/uaccess.h>
40549+#include <asm/local.h>
40550
40551 #include "tty.h"
40552 #include "network.h"
40553@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
40554 mutex_unlock(&tty->ipw_tty_mutex);
40555 return -ENODEV;
40556 }
40557- if (tty->port.count == 0)
40558+ if (atomic_read(&tty->port.count) == 0)
40559 tty->tx_bytes_queued = 0;
40560
40561- tty->port.count++;
40562+ atomic_inc(&tty->port.count);
40563
40564 tty->port.tty = linux_tty;
40565 linux_tty->driver_data = tty;
40566@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
40567
40568 static void do_ipw_close(struct ipw_tty *tty)
40569 {
40570- tty->port.count--;
40571-
40572- if (tty->port.count == 0) {
40573+ if (atomic_dec_return(&tty->port.count) == 0) {
40574 struct tty_struct *linux_tty = tty->port.tty;
40575
40576 if (linux_tty != NULL) {
40577@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
40578 return;
40579
40580 mutex_lock(&tty->ipw_tty_mutex);
40581- if (tty->port.count == 0) {
40582+ if (atomic_read(&tty->port.count) == 0) {
40583 mutex_unlock(&tty->ipw_tty_mutex);
40584 return;
40585 }
40586@@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
40587 return;
40588 }
40589
40590- if (!tty->port.count) {
40591+ if (!atomic_read(&tty->port.count)) {
40592 mutex_unlock(&tty->ipw_tty_mutex);
40593 return;
40594 }
40595@@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
40596 return -ENODEV;
40597
40598 mutex_lock(&tty->ipw_tty_mutex);
40599- if (!tty->port.count) {
40600+ if (!atomic_read(&tty->port.count)) {
40601 mutex_unlock(&tty->ipw_tty_mutex);
40602 return -EINVAL;
40603 }
40604@@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
40605 if (!tty)
40606 return -ENODEV;
40607
40608- if (!tty->port.count)
40609+ if (!atomic_read(&tty->port.count))
40610 return -EINVAL;
40611
40612 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
40613@@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
40614 if (!tty)
40615 return 0;
40616
40617- if (!tty->port.count)
40618+ if (!atomic_read(&tty->port.count))
40619 return 0;
40620
40621 return tty->tx_bytes_queued;
40622@@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
40623 if (!tty)
40624 return -ENODEV;
40625
40626- if (!tty->port.count)
40627+ if (!atomic_read(&tty->port.count))
40628 return -EINVAL;
40629
40630 return get_control_lines(tty);
40631@@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
40632 if (!tty)
40633 return -ENODEV;
40634
40635- if (!tty->port.count)
40636+ if (!atomic_read(&tty->port.count))
40637 return -EINVAL;
40638
40639 return set_control_lines(tty, set, clear);
40640@@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
40641 if (!tty)
40642 return -ENODEV;
40643
40644- if (!tty->port.count)
40645+ if (!atomic_read(&tty->port.count))
40646 return -EINVAL;
40647
40648 /* FIXME: Exactly how is the tty object locked here .. */
40649@@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
40650 * are gone */
40651 mutex_lock(&ttyj->ipw_tty_mutex);
40652 }
40653- while (ttyj->port.count)
40654+ while (atomic_read(&ttyj->port.count))
40655 do_ipw_close(ttyj);
40656 ipwireless_disassociate_network_ttys(network,
40657 ttyj->channel_idx);
40658diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
40659index f9d2850..b006f04 100644
40660--- a/drivers/tty/moxa.c
40661+++ b/drivers/tty/moxa.c
40662@@ -1193,7 +1193,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
40663 }
40664
40665 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
40666- ch->port.count++;
40667+ atomic_inc(&ch->port.count);
40668 tty->driver_data = ch;
40669 tty_port_tty_set(&ch->port, tty);
40670 mutex_lock(&ch->port.mutex);
40671diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
40672index dcc0430..040bef9 100644
40673--- a/drivers/tty/n_gsm.c
40674+++ b/drivers/tty/n_gsm.c
40675@@ -1636,7 +1636,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
40676 spin_lock_init(&dlci->lock);
40677 mutex_init(&dlci->mutex);
40678 dlci->fifo = &dlci->_fifo;
40679- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
40680+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
40681 kfree(dlci);
40682 return NULL;
40683 }
40684@@ -2924,7 +2924,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
40685 struct gsm_dlci *dlci = tty->driver_data;
40686 struct tty_port *port = &dlci->port;
40687
40688- port->count++;
40689+ atomic_inc(&port->count);
40690 dlci_get(dlci);
40691 dlci_get(dlci->gsm->dlci[0]);
40692 mux_get(dlci->gsm);
40693diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
40694index 19083ef..6e34e97 100644
40695--- a/drivers/tty/n_tty.c
40696+++ b/drivers/tty/n_tty.c
40697@@ -2196,6 +2196,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
40698 {
40699 *ops = tty_ldisc_N_TTY;
40700 ops->owner = NULL;
40701- ops->refcount = ops->flags = 0;
40702+ atomic_set(&ops->refcount, 0);
40703+ ops->flags = 0;
40704 }
40705 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
40706diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
40707index 79ff3a5..1fe9399 100644
40708--- a/drivers/tty/pty.c
40709+++ b/drivers/tty/pty.c
40710@@ -791,8 +791,10 @@ static void __init unix98_pty_init(void)
40711 panic("Couldn't register Unix98 pts driver");
40712
40713 /* Now create the /dev/ptmx special device */
40714+ pax_open_kernel();
40715 tty_default_fops(&ptmx_fops);
40716- ptmx_fops.open = ptmx_open;
40717+ *(void **)&ptmx_fops.open = ptmx_open;
40718+ pax_close_kernel();
40719
40720 cdev_init(&ptmx_cdev, &ptmx_fops);
40721 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
40722diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
40723index e42009a..566a036 100644
40724--- a/drivers/tty/rocket.c
40725+++ b/drivers/tty/rocket.c
40726@@ -925,7 +925,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
40727 tty->driver_data = info;
40728 tty_port_tty_set(port, tty);
40729
40730- if (port->count++ == 0) {
40731+ if (atomic_inc_return(&port->count) == 1) {
40732 atomic_inc(&rp_num_ports_open);
40733
40734 #ifdef ROCKET_DEBUG_OPEN
40735@@ -934,7 +934,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
40736 #endif
40737 }
40738 #ifdef ROCKET_DEBUG_OPEN
40739- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
40740+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
40741 #endif
40742
40743 /*
40744@@ -1529,7 +1529,7 @@ static void rp_hangup(struct tty_struct *tty)
40745 spin_unlock_irqrestore(&info->port.lock, flags);
40746 return;
40747 }
40748- if (info->port.count)
40749+ if (atomic_read(&info->port.count))
40750 atomic_dec(&rp_num_ports_open);
40751 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
40752 spin_unlock_irqrestore(&info->port.lock, flags);
40753diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
40754index 1002054..dd644a8 100644
40755--- a/drivers/tty/serial/kgdboc.c
40756+++ b/drivers/tty/serial/kgdboc.c
40757@@ -24,8 +24,9 @@
40758 #define MAX_CONFIG_LEN 40
40759
40760 static struct kgdb_io kgdboc_io_ops;
40761+static struct kgdb_io kgdboc_io_ops_console;
40762
40763-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
40764+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
40765 static int configured = -1;
40766
40767 static char config[MAX_CONFIG_LEN];
40768@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
40769 kgdboc_unregister_kbd();
40770 if (configured == 1)
40771 kgdb_unregister_io_module(&kgdboc_io_ops);
40772+ else if (configured == 2)
40773+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
40774 }
40775
40776 static int configure_kgdboc(void)
40777@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
40778 int err;
40779 char *cptr = config;
40780 struct console *cons;
40781+ int is_console = 0;
40782
40783 err = kgdboc_option_setup(config);
40784 if (err || !strlen(config) || isspace(config[0]))
40785 goto noconfig;
40786
40787 err = -ENODEV;
40788- kgdboc_io_ops.is_console = 0;
40789 kgdb_tty_driver = NULL;
40790
40791 kgdboc_use_kms = 0;
40792@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
40793 int idx;
40794 if (cons->device && cons->device(cons, &idx) == p &&
40795 idx == tty_line) {
40796- kgdboc_io_ops.is_console = 1;
40797+ is_console = 1;
40798 break;
40799 }
40800 cons = cons->next;
40801@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
40802 kgdb_tty_line = tty_line;
40803
40804 do_register:
40805- err = kgdb_register_io_module(&kgdboc_io_ops);
40806+ if (is_console) {
40807+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
40808+ configured = 2;
40809+ } else {
40810+ err = kgdb_register_io_module(&kgdboc_io_ops);
40811+ configured = 1;
40812+ }
40813 if (err)
40814 goto noconfig;
40815
40816@@ -205,8 +214,6 @@ do_register:
40817 if (err)
40818 goto nmi_con_failed;
40819
40820- configured = 1;
40821-
40822 return 0;
40823
40824 nmi_con_failed:
40825@@ -223,7 +230,7 @@ noconfig:
40826 static int __init init_kgdboc(void)
40827 {
40828 /* Already configured? */
40829- if (configured == 1)
40830+ if (configured >= 1)
40831 return 0;
40832
40833 return configure_kgdboc();
40834@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
40835 if (config[len - 1] == '\n')
40836 config[len - 1] = '\0';
40837
40838- if (configured == 1)
40839+ if (configured >= 1)
40840 cleanup_kgdboc();
40841
40842 /* Go and configure with the new params. */
40843@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
40844 .post_exception = kgdboc_post_exp_handler,
40845 };
40846
40847+static struct kgdb_io kgdboc_io_ops_console = {
40848+ .name = "kgdboc",
40849+ .read_char = kgdboc_get_char,
40850+ .write_char = kgdboc_put_char,
40851+ .pre_exception = kgdboc_pre_exp_handler,
40852+ .post_exception = kgdboc_post_exp_handler,
40853+ .is_console = 1
40854+};
40855+
40856 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
40857 /* This is only available if kgdboc is a built in for early debugging */
40858 static int __init kgdboc_early_init(char *opt)
40859diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
40860index e514b3a..c73d614 100644
40861--- a/drivers/tty/serial/samsung.c
40862+++ b/drivers/tty/serial/samsung.c
40863@@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
40864 }
40865 }
40866
40867+static int s3c64xx_serial_startup(struct uart_port *port);
40868 static int s3c24xx_serial_startup(struct uart_port *port)
40869 {
40870 struct s3c24xx_uart_port *ourport = to_ourport(port);
40871 int ret;
40872
40873+ /* Startup sequence is different for s3c64xx and higher SoC's */
40874+ if (s3c24xx_serial_has_interrupt_mask(port))
40875+ return s3c64xx_serial_startup(port);
40876+
40877 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
40878 port->mapbase, port->membase);
40879
40880@@ -1122,10 +1127,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
40881 /* setup info for port */
40882 port->dev = &platdev->dev;
40883
40884- /* Startup sequence is different for s3c64xx and higher SoC's */
40885- if (s3c24xx_serial_has_interrupt_mask(port))
40886- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
40887-
40888 port->uartclk = 1;
40889
40890 if (cfg->uart_flags & UPF_CONS_FLOW) {
40891diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
40892index 2c7230a..2104f16 100644
40893--- a/drivers/tty/serial/serial_core.c
40894+++ b/drivers/tty/serial/serial_core.c
40895@@ -1455,7 +1455,7 @@ static void uart_hangup(struct tty_struct *tty)
40896 uart_flush_buffer(tty);
40897 uart_shutdown(tty, state);
40898 spin_lock_irqsave(&port->lock, flags);
40899- port->count = 0;
40900+ atomic_set(&port->count, 0);
40901 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
40902 spin_unlock_irqrestore(&port->lock, flags);
40903 tty_port_tty_set(port, NULL);
40904@@ -1551,7 +1551,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
40905 goto end;
40906 }
40907
40908- port->count++;
40909+ atomic_inc(&port->count);
40910 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
40911 retval = -ENXIO;
40912 goto err_dec_count;
40913@@ -1578,7 +1578,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
40914 /*
40915 * Make sure the device is in D0 state.
40916 */
40917- if (port->count == 1)
40918+ if (atomic_read(&port->count) == 1)
40919 uart_change_pm(state, 0);
40920
40921 /*
40922@@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
40923 end:
40924 return retval;
40925 err_dec_count:
40926- port->count--;
40927+ atomic_inc(&port->count);
40928 mutex_unlock(&port->mutex);
40929 goto end;
40930 }
40931diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
40932index 9e071f6..f30ae69 100644
40933--- a/drivers/tty/synclink.c
40934+++ b/drivers/tty/synclink.c
40935@@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
40936
40937 if (debug_level >= DEBUG_LEVEL_INFO)
40938 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
40939- __FILE__,__LINE__, info->device_name, info->port.count);
40940+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
40941
40942 if (tty_port_close_start(&info->port, tty, filp) == 0)
40943 goto cleanup;
40944@@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
40945 cleanup:
40946 if (debug_level >= DEBUG_LEVEL_INFO)
40947 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
40948- tty->driver->name, info->port.count);
40949+ tty->driver->name, atomic_read(&info->port.count));
40950
40951 } /* end of mgsl_close() */
40952
40953@@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
40954
40955 mgsl_flush_buffer(tty);
40956 shutdown(info);
40957-
40958- info->port.count = 0;
40959+
40960+ atomic_set(&info->port.count, 0);
40961 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
40962 info->port.tty = NULL;
40963
40964@@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
40965
40966 if (debug_level >= DEBUG_LEVEL_INFO)
40967 printk("%s(%d):block_til_ready before block on %s count=%d\n",
40968- __FILE__,__LINE__, tty->driver->name, port->count );
40969+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40970
40971 spin_lock_irqsave(&info->irq_spinlock, flags);
40972 if (!tty_hung_up_p(filp)) {
40973 extra_count = true;
40974- port->count--;
40975+ atomic_dec(&port->count);
40976 }
40977 spin_unlock_irqrestore(&info->irq_spinlock, flags);
40978 port->blocked_open++;
40979@@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
40980
40981 if (debug_level >= DEBUG_LEVEL_INFO)
40982 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
40983- __FILE__,__LINE__, tty->driver->name, port->count );
40984+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40985
40986 tty_unlock(tty);
40987 schedule();
40988@@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
40989
40990 /* FIXME: Racy on hangup during close wait */
40991 if (extra_count)
40992- port->count++;
40993+ atomic_inc(&port->count);
40994 port->blocked_open--;
40995
40996 if (debug_level >= DEBUG_LEVEL_INFO)
40997 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
40998- __FILE__,__LINE__, tty->driver->name, port->count );
40999+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
41000
41001 if (!retval)
41002 port->flags |= ASYNC_NORMAL_ACTIVE;
41003@@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
41004
41005 if (debug_level >= DEBUG_LEVEL_INFO)
41006 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
41007- __FILE__,__LINE__,tty->driver->name, info->port.count);
41008+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
41009
41010 /* If port is closing, signal caller to try again */
41011 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
41012@@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
41013 spin_unlock_irqrestore(&info->netlock, flags);
41014 goto cleanup;
41015 }
41016- info->port.count++;
41017+ atomic_inc(&info->port.count);
41018 spin_unlock_irqrestore(&info->netlock, flags);
41019
41020- if (info->port.count == 1) {
41021+ if (atomic_read(&info->port.count) == 1) {
41022 /* 1st open on this device, init hardware */
41023 retval = startup(info);
41024 if (retval < 0)
41025@@ -3451,8 +3451,8 @@ cleanup:
41026 if (retval) {
41027 if (tty->count == 1)
41028 info->port.tty = NULL; /* tty layer will release tty struct */
41029- if(info->port.count)
41030- info->port.count--;
41031+ if (atomic_read(&info->port.count))
41032+ atomic_dec(&info->port.count);
41033 }
41034
41035 return retval;
41036@@ -7662,7 +7662,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
41037 unsigned short new_crctype;
41038
41039 /* return error if TTY interface open */
41040- if (info->port.count)
41041+ if (atomic_read(&info->port.count))
41042 return -EBUSY;
41043
41044 switch (encoding)
41045@@ -7757,7 +7757,7 @@ static int hdlcdev_open(struct net_device *dev)
41046
41047 /* arbitrate between network and tty opens */
41048 spin_lock_irqsave(&info->netlock, flags);
41049- if (info->port.count != 0 || info->netcount != 0) {
41050+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
41051 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
41052 spin_unlock_irqrestore(&info->netlock, flags);
41053 return -EBUSY;
41054@@ -7843,7 +7843,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
41055 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
41056
41057 /* return error if TTY interface open */
41058- if (info->port.count)
41059+ if (atomic_read(&info->port.count))
41060 return -EBUSY;
41061
41062 if (cmd != SIOCWANDEV)
41063diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
41064index aba1e59..877ac33 100644
41065--- a/drivers/tty/synclink_gt.c
41066+++ b/drivers/tty/synclink_gt.c
41067@@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
41068 tty->driver_data = info;
41069 info->port.tty = tty;
41070
41071- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
41072+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
41073
41074 /* If port is closing, signal caller to try again */
41075 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
41076@@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
41077 mutex_unlock(&info->port.mutex);
41078 goto cleanup;
41079 }
41080- info->port.count++;
41081+ atomic_inc(&info->port.count);
41082 spin_unlock_irqrestore(&info->netlock, flags);
41083
41084- if (info->port.count == 1) {
41085+ if (atomic_read(&info->port.count) == 1) {
41086 /* 1st open on this device, init hardware */
41087 retval = startup(info);
41088 if (retval < 0) {
41089@@ -716,8 +716,8 @@ cleanup:
41090 if (retval) {
41091 if (tty->count == 1)
41092 info->port.tty = NULL; /* tty layer will release tty struct */
41093- if(info->port.count)
41094- info->port.count--;
41095+ if(atomic_read(&info->port.count))
41096+ atomic_dec(&info->port.count);
41097 }
41098
41099 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
41100@@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
41101
41102 if (sanity_check(info, tty->name, "close"))
41103 return;
41104- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
41105+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
41106
41107 if (tty_port_close_start(&info->port, tty, filp) == 0)
41108 goto cleanup;
41109@@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
41110 tty_port_close_end(&info->port, tty);
41111 info->port.tty = NULL;
41112 cleanup:
41113- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
41114+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
41115 }
41116
41117 static void hangup(struct tty_struct *tty)
41118@@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
41119 shutdown(info);
41120
41121 spin_lock_irqsave(&info->port.lock, flags);
41122- info->port.count = 0;
41123+ atomic_set(&info->port.count, 0);
41124 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
41125 info->port.tty = NULL;
41126 spin_unlock_irqrestore(&info->port.lock, flags);
41127@@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
41128 unsigned short new_crctype;
41129
41130 /* return error if TTY interface open */
41131- if (info->port.count)
41132+ if (atomic_read(&info->port.count))
41133 return -EBUSY;
41134
41135 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
41136@@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
41137
41138 /* arbitrate between network and tty opens */
41139 spin_lock_irqsave(&info->netlock, flags);
41140- if (info->port.count != 0 || info->netcount != 0) {
41141+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
41142 DBGINFO(("%s hdlc_open busy\n", dev->name));
41143 spin_unlock_irqrestore(&info->netlock, flags);
41144 return -EBUSY;
41145@@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
41146 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
41147
41148 /* return error if TTY interface open */
41149- if (info->port.count)
41150+ if (atomic_read(&info->port.count))
41151 return -EBUSY;
41152
41153 if (cmd != SIOCWANDEV)
41154@@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
41155 if (port == NULL)
41156 continue;
41157 spin_lock(&port->lock);
41158- if ((port->port.count || port->netcount) &&
41159+ if ((atomic_read(&port->port.count) || port->netcount) &&
41160 port->pending_bh && !port->bh_running &&
41161 !port->bh_requested) {
41162 DBGISR(("%s bh queued\n", port->device_name));
41163@@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
41164 spin_lock_irqsave(&info->lock, flags);
41165 if (!tty_hung_up_p(filp)) {
41166 extra_count = true;
41167- port->count--;
41168+ atomic_dec(&port->count);
41169 }
41170 spin_unlock_irqrestore(&info->lock, flags);
41171 port->blocked_open++;
41172@@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
41173 remove_wait_queue(&port->open_wait, &wait);
41174
41175 if (extra_count)
41176- port->count++;
41177+ atomic_inc(&port->count);
41178 port->blocked_open--;
41179
41180 if (!retval)
41181diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
41182index fd43fb6..34704ad 100644
41183--- a/drivers/tty/synclinkmp.c
41184+++ b/drivers/tty/synclinkmp.c
41185@@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
41186
41187 if (debug_level >= DEBUG_LEVEL_INFO)
41188 printk("%s(%d):%s open(), old ref count = %d\n",
41189- __FILE__,__LINE__,tty->driver->name, info->port.count);
41190+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
41191
41192 /* If port is closing, signal caller to try again */
41193 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
41194@@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
41195 spin_unlock_irqrestore(&info->netlock, flags);
41196 goto cleanup;
41197 }
41198- info->port.count++;
41199+ atomic_inc(&info->port.count);
41200 spin_unlock_irqrestore(&info->netlock, flags);
41201
41202- if (info->port.count == 1) {
41203+ if (atomic_read(&info->port.count) == 1) {
41204 /* 1st open on this device, init hardware */
41205 retval = startup(info);
41206 if (retval < 0)
41207@@ -797,8 +797,8 @@ cleanup:
41208 if (retval) {
41209 if (tty->count == 1)
41210 info->port.tty = NULL; /* tty layer will release tty struct */
41211- if(info->port.count)
41212- info->port.count--;
41213+ if(atomic_read(&info->port.count))
41214+ atomic_dec(&info->port.count);
41215 }
41216
41217 return retval;
41218@@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
41219
41220 if (debug_level >= DEBUG_LEVEL_INFO)
41221 printk("%s(%d):%s close() entry, count=%d\n",
41222- __FILE__,__LINE__, info->device_name, info->port.count);
41223+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
41224
41225 if (tty_port_close_start(&info->port, tty, filp) == 0)
41226 goto cleanup;
41227@@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
41228 cleanup:
41229 if (debug_level >= DEBUG_LEVEL_INFO)
41230 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
41231- tty->driver->name, info->port.count);
41232+ tty->driver->name, atomic_read(&info->port.count));
41233 }
41234
41235 /* Called by tty_hangup() when a hangup is signaled.
41236@@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
41237 shutdown(info);
41238
41239 spin_lock_irqsave(&info->port.lock, flags);
41240- info->port.count = 0;
41241+ atomic_set(&info->port.count, 0);
41242 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
41243 info->port.tty = NULL;
41244 spin_unlock_irqrestore(&info->port.lock, flags);
41245@@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
41246 unsigned short new_crctype;
41247
41248 /* return error if TTY interface open */
41249- if (info->port.count)
41250+ if (atomic_read(&info->port.count))
41251 return -EBUSY;
41252
41253 switch (encoding)
41254@@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
41255
41256 /* arbitrate between network and tty opens */
41257 spin_lock_irqsave(&info->netlock, flags);
41258- if (info->port.count != 0 || info->netcount != 0) {
41259+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
41260 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
41261 spin_unlock_irqrestore(&info->netlock, flags);
41262 return -EBUSY;
41263@@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
41264 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
41265
41266 /* return error if TTY interface open */
41267- if (info->port.count)
41268+ if (atomic_read(&info->port.count))
41269 return -EBUSY;
41270
41271 if (cmd != SIOCWANDEV)
41272@@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
41273 * do not request bottom half processing if the
41274 * device is not open in a normal mode.
41275 */
41276- if ( port && (port->port.count || port->netcount) &&
41277+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
41278 port->pending_bh && !port->bh_running &&
41279 !port->bh_requested ) {
41280 if ( debug_level >= DEBUG_LEVEL_ISR )
41281@@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
41282
41283 if (debug_level >= DEBUG_LEVEL_INFO)
41284 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
41285- __FILE__,__LINE__, tty->driver->name, port->count );
41286+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
41287
41288 spin_lock_irqsave(&info->lock, flags);
41289 if (!tty_hung_up_p(filp)) {
41290 extra_count = true;
41291- port->count--;
41292+ atomic_dec(&port->count);
41293 }
41294 spin_unlock_irqrestore(&info->lock, flags);
41295 port->blocked_open++;
41296@@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
41297
41298 if (debug_level >= DEBUG_LEVEL_INFO)
41299 printk("%s(%d):%s block_til_ready() count=%d\n",
41300- __FILE__,__LINE__, tty->driver->name, port->count );
41301+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
41302
41303 tty_unlock(tty);
41304 schedule();
41305@@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
41306 remove_wait_queue(&port->open_wait, &wait);
41307
41308 if (extra_count)
41309- port->count++;
41310+ atomic_inc(&port->count);
41311 port->blocked_open--;
41312
41313 if (debug_level >= DEBUG_LEVEL_INFO)
41314 printk("%s(%d):%s block_til_ready() after, count=%d\n",
41315- __FILE__,__LINE__, tty->driver->name, port->count );
41316+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
41317
41318 if (!retval)
41319 port->flags |= ASYNC_NORMAL_ACTIVE;
41320diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
41321index b3c4a25..723916f 100644
41322--- a/drivers/tty/sysrq.c
41323+++ b/drivers/tty/sysrq.c
41324@@ -867,7 +867,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
41325 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
41326 size_t count, loff_t *ppos)
41327 {
41328- if (count) {
41329+ if (count && capable(CAP_SYS_ADMIN)) {
41330 char c;
41331
41332 if (get_user(c, buf))
41333diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
41334index da9fde8..c07975f 100644
41335--- a/drivers/tty/tty_io.c
41336+++ b/drivers/tty/tty_io.c
41337@@ -3391,7 +3391,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
41338
41339 void tty_default_fops(struct file_operations *fops)
41340 {
41341- *fops = tty_fops;
41342+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
41343 }
41344
41345 /*
41346diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
41347index c578229..45aa9ee 100644
41348--- a/drivers/tty/tty_ldisc.c
41349+++ b/drivers/tty/tty_ldisc.c
41350@@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
41351 if (atomic_dec_and_test(&ld->users)) {
41352 struct tty_ldisc_ops *ldo = ld->ops;
41353
41354- ldo->refcount--;
41355+ atomic_dec(&ldo->refcount);
41356 module_put(ldo->owner);
41357 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
41358
41359@@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
41360 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
41361 tty_ldiscs[disc] = new_ldisc;
41362 new_ldisc->num = disc;
41363- new_ldisc->refcount = 0;
41364+ atomic_set(&new_ldisc->refcount, 0);
41365 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
41366
41367 return ret;
41368@@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
41369 return -EINVAL;
41370
41371 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
41372- if (tty_ldiscs[disc]->refcount)
41373+ if (atomic_read(&tty_ldiscs[disc]->refcount))
41374 ret = -EBUSY;
41375 else
41376 tty_ldiscs[disc] = NULL;
41377@@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
41378 if (ldops) {
41379 ret = ERR_PTR(-EAGAIN);
41380 if (try_module_get(ldops->owner)) {
41381- ldops->refcount++;
41382+ atomic_inc(&ldops->refcount);
41383 ret = ldops;
41384 }
41385 }
41386@@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
41387 unsigned long flags;
41388
41389 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
41390- ldops->refcount--;
41391+ atomic_dec(&ldops->refcount);
41392 module_put(ldops->owner);
41393 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
41394 }
41395diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
41396index b7ff59d..7c6105e 100644
41397--- a/drivers/tty/tty_port.c
41398+++ b/drivers/tty/tty_port.c
41399@@ -218,7 +218,7 @@ void tty_port_hangup(struct tty_port *port)
41400 unsigned long flags;
41401
41402 spin_lock_irqsave(&port->lock, flags);
41403- port->count = 0;
41404+ atomic_set(&port->count, 0);
41405 port->flags &= ~ASYNC_NORMAL_ACTIVE;
41406 if (port->tty) {
41407 set_bit(TTY_IO_ERROR, &port->tty->flags);
41408@@ -344,7 +344,7 @@ int tty_port_block_til_ready(struct tty_port *port,
41409 /* The port lock protects the port counts */
41410 spin_lock_irqsave(&port->lock, flags);
41411 if (!tty_hung_up_p(filp))
41412- port->count--;
41413+ atomic_dec(&port->count);
41414 port->blocked_open++;
41415 spin_unlock_irqrestore(&port->lock, flags);
41416
41417@@ -386,7 +386,7 @@ int tty_port_block_til_ready(struct tty_port *port,
41418 we must not mess that up further */
41419 spin_lock_irqsave(&port->lock, flags);
41420 if (!tty_hung_up_p(filp))
41421- port->count++;
41422+ atomic_inc(&port->count);
41423 port->blocked_open--;
41424 if (retval == 0)
41425 port->flags |= ASYNC_NORMAL_ACTIVE;
41426@@ -406,19 +406,19 @@ int tty_port_close_start(struct tty_port *port,
41427 return 0;
41428 }
41429
41430- if (tty->count == 1 && port->count != 1) {
41431+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
41432 printk(KERN_WARNING
41433 "tty_port_close_start: tty->count = 1 port count = %d.\n",
41434- port->count);
41435- port->count = 1;
41436+ atomic_read(&port->count));
41437+ atomic_set(&port->count, 1);
41438 }
41439- if (--port->count < 0) {
41440+ if (atomic_dec_return(&port->count) < 0) {
41441 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
41442- port->count);
41443- port->count = 0;
41444+ atomic_read(&port->count));
41445+ atomic_set(&port->count, 0);
41446 }
41447
41448- if (port->count) {
41449+ if (atomic_read(&port->count)) {
41450 spin_unlock_irqrestore(&port->lock, flags);
41451 if (port->ops->drop)
41452 port->ops->drop(port);
41453@@ -516,7 +516,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
41454 {
41455 spin_lock_irq(&port->lock);
41456 if (!tty_hung_up_p(filp))
41457- ++port->count;
41458+ atomic_inc(&port->count);
41459 spin_unlock_irq(&port->lock);
41460 tty_port_tty_set(port, tty);
41461
41462diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
41463index 681765b..d3ccdf2 100644
41464--- a/drivers/tty/vt/keyboard.c
41465+++ b/drivers/tty/vt/keyboard.c
41466@@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
41467 kbd->kbdmode == VC_OFF) &&
41468 value != KVAL(K_SAK))
41469 return; /* SAK is allowed even in raw mode */
41470+
41471+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
41472+ {
41473+ void *func = fn_handler[value];
41474+ if (func == fn_show_state || func == fn_show_ptregs ||
41475+ func == fn_show_mem)
41476+ return;
41477+ }
41478+#endif
41479+
41480 fn_handler[value](vc);
41481 }
41482
41483@@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
41484 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
41485 return -EFAULT;
41486
41487- if (!capable(CAP_SYS_TTY_CONFIG))
41488- perm = 0;
41489-
41490 switch (cmd) {
41491 case KDGKBENT:
41492 /* Ensure another thread doesn't free it under us */
41493@@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
41494 spin_unlock_irqrestore(&kbd_event_lock, flags);
41495 return put_user(val, &user_kbe->kb_value);
41496 case KDSKBENT:
41497+ if (!capable(CAP_SYS_TTY_CONFIG))
41498+ perm = 0;
41499+
41500 if (!perm)
41501 return -EPERM;
41502 if (!i && v == K_NOSUCHMAP) {
41503@@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
41504 int i, j, k;
41505 int ret;
41506
41507- if (!capable(CAP_SYS_TTY_CONFIG))
41508- perm = 0;
41509-
41510 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
41511 if (!kbs) {
41512 ret = -ENOMEM;
41513@@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
41514 kfree(kbs);
41515 return ((p && *p) ? -EOVERFLOW : 0);
41516 case KDSKBSENT:
41517+ if (!capable(CAP_SYS_TTY_CONFIG))
41518+ perm = 0;
41519+
41520 if (!perm) {
41521 ret = -EPERM;
41522 goto reterr;
41523diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
41524index 5110f36..8dc0a74 100644
41525--- a/drivers/uio/uio.c
41526+++ b/drivers/uio/uio.c
41527@@ -25,6 +25,7 @@
41528 #include <linux/kobject.h>
41529 #include <linux/cdev.h>
41530 #include <linux/uio_driver.h>
41531+#include <asm/local.h>
41532
41533 #define UIO_MAX_DEVICES (1U << MINORBITS)
41534
41535@@ -32,10 +33,10 @@ struct uio_device {
41536 struct module *owner;
41537 struct device *dev;
41538 int minor;
41539- atomic_t event;
41540+ atomic_unchecked_t event;
41541 struct fasync_struct *async_queue;
41542 wait_queue_head_t wait;
41543- int vma_count;
41544+ local_t vma_count;
41545 struct uio_info *info;
41546 struct kobject *map_dir;
41547 struct kobject *portio_dir;
41548@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
41549 struct device_attribute *attr, char *buf)
41550 {
41551 struct uio_device *idev = dev_get_drvdata(dev);
41552- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
41553+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
41554 }
41555
41556 static struct device_attribute uio_class_attributes[] = {
41557@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
41558 {
41559 struct uio_device *idev = info->uio_dev;
41560
41561- atomic_inc(&idev->event);
41562+ atomic_inc_unchecked(&idev->event);
41563 wake_up_interruptible(&idev->wait);
41564 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
41565 }
41566@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
41567 }
41568
41569 listener->dev = idev;
41570- listener->event_count = atomic_read(&idev->event);
41571+ listener->event_count = atomic_read_unchecked(&idev->event);
41572 filep->private_data = listener;
41573
41574 if (idev->info->open) {
41575@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
41576 return -EIO;
41577
41578 poll_wait(filep, &idev->wait, wait);
41579- if (listener->event_count != atomic_read(&idev->event))
41580+ if (listener->event_count != atomic_read_unchecked(&idev->event))
41581 return POLLIN | POLLRDNORM;
41582 return 0;
41583 }
41584@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
41585 do {
41586 set_current_state(TASK_INTERRUPTIBLE);
41587
41588- event_count = atomic_read(&idev->event);
41589+ event_count = atomic_read_unchecked(&idev->event);
41590 if (event_count != listener->event_count) {
41591 if (copy_to_user(buf, &event_count, count))
41592 retval = -EFAULT;
41593@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
41594 static void uio_vma_open(struct vm_area_struct *vma)
41595 {
41596 struct uio_device *idev = vma->vm_private_data;
41597- idev->vma_count++;
41598+ local_inc(&idev->vma_count);
41599 }
41600
41601 static void uio_vma_close(struct vm_area_struct *vma)
41602 {
41603 struct uio_device *idev = vma->vm_private_data;
41604- idev->vma_count--;
41605+ local_dec(&idev->vma_count);
41606 }
41607
41608 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41609@@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
41610 idev->owner = owner;
41611 idev->info = info;
41612 init_waitqueue_head(&idev->wait);
41613- atomic_set(&idev->event, 0);
41614+ atomic_set_unchecked(&idev->event, 0);
41615
41616 ret = uio_get_minor(idev);
41617 if (ret)
41618diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
41619index b7eb86a..36d28af 100644
41620--- a/drivers/usb/atm/cxacru.c
41621+++ b/drivers/usb/atm/cxacru.c
41622@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
41623 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
41624 if (ret < 2)
41625 return -EINVAL;
41626- if (index < 0 || index > 0x7f)
41627+ if (index > 0x7f)
41628 return -EINVAL;
41629 pos += tmp;
41630
41631diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
41632index 35f10bf..6a38a0b 100644
41633--- a/drivers/usb/atm/usbatm.c
41634+++ b/drivers/usb/atm/usbatm.c
41635@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41636 if (printk_ratelimit())
41637 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
41638 __func__, vpi, vci);
41639- atomic_inc(&vcc->stats->rx_err);
41640+ atomic_inc_unchecked(&vcc->stats->rx_err);
41641 return;
41642 }
41643
41644@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41645 if (length > ATM_MAX_AAL5_PDU) {
41646 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
41647 __func__, length, vcc);
41648- atomic_inc(&vcc->stats->rx_err);
41649+ atomic_inc_unchecked(&vcc->stats->rx_err);
41650 goto out;
41651 }
41652
41653@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41654 if (sarb->len < pdu_length) {
41655 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
41656 __func__, pdu_length, sarb->len, vcc);
41657- atomic_inc(&vcc->stats->rx_err);
41658+ atomic_inc_unchecked(&vcc->stats->rx_err);
41659 goto out;
41660 }
41661
41662 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
41663 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
41664 __func__, vcc);
41665- atomic_inc(&vcc->stats->rx_err);
41666+ atomic_inc_unchecked(&vcc->stats->rx_err);
41667 goto out;
41668 }
41669
41670@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41671 if (printk_ratelimit())
41672 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
41673 __func__, length);
41674- atomic_inc(&vcc->stats->rx_drop);
41675+ atomic_inc_unchecked(&vcc->stats->rx_drop);
41676 goto out;
41677 }
41678
41679@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41680
41681 vcc->push(vcc, skb);
41682
41683- atomic_inc(&vcc->stats->rx);
41684+ atomic_inc_unchecked(&vcc->stats->rx);
41685 out:
41686 skb_trim(sarb, 0);
41687 }
41688@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
41689 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
41690
41691 usbatm_pop(vcc, skb);
41692- atomic_inc(&vcc->stats->tx);
41693+ atomic_inc_unchecked(&vcc->stats->tx);
41694
41695 skb = skb_dequeue(&instance->sndqueue);
41696 }
41697@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
41698 if (!left--)
41699 return sprintf(page,
41700 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
41701- atomic_read(&atm_dev->stats.aal5.tx),
41702- atomic_read(&atm_dev->stats.aal5.tx_err),
41703- atomic_read(&atm_dev->stats.aal5.rx),
41704- atomic_read(&atm_dev->stats.aal5.rx_err),
41705- atomic_read(&atm_dev->stats.aal5.rx_drop));
41706+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
41707+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
41708+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
41709+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
41710+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
41711
41712 if (!left--) {
41713 if (instance->disconnected)
41714diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
41715index cbacea9..246cccd 100644
41716--- a/drivers/usb/core/devices.c
41717+++ b/drivers/usb/core/devices.c
41718@@ -126,7 +126,7 @@ static const char format_endpt[] =
41719 * time it gets called.
41720 */
41721 static struct device_connect_event {
41722- atomic_t count;
41723+ atomic_unchecked_t count;
41724 wait_queue_head_t wait;
41725 } device_event = {
41726 .count = ATOMIC_INIT(1),
41727@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
41728
41729 void usbfs_conn_disc_event(void)
41730 {
41731- atomic_add(2, &device_event.count);
41732+ atomic_add_unchecked(2, &device_event.count);
41733 wake_up(&device_event.wait);
41734 }
41735
41736@@ -645,7 +645,7 @@ static unsigned int usb_device_poll(struct file *file,
41737
41738 poll_wait(file, &device_event.wait, wait);
41739
41740- event_count = atomic_read(&device_event.count);
41741+ event_count = atomic_read_unchecked(&device_event.count);
41742 if (file->f_version != event_count) {
41743 file->f_version = event_count;
41744 return POLLIN | POLLRDNORM;
41745diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
41746index 8e64adf..9a33a3c 100644
41747--- a/drivers/usb/core/hcd.c
41748+++ b/drivers/usb/core/hcd.c
41749@@ -1522,7 +1522,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
41750 */
41751 usb_get_urb(urb);
41752 atomic_inc(&urb->use_count);
41753- atomic_inc(&urb->dev->urbnum);
41754+ atomic_inc_unchecked(&urb->dev->urbnum);
41755 usbmon_urb_submit(&hcd->self, urb);
41756
41757 /* NOTE requirements on root-hub callers (usbfs and the hub
41758@@ -1549,7 +1549,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
41759 urb->hcpriv = NULL;
41760 INIT_LIST_HEAD(&urb->urb_list);
41761 atomic_dec(&urb->use_count);
41762- atomic_dec(&urb->dev->urbnum);
41763+ atomic_dec_unchecked(&urb->dev->urbnum);
41764 if (atomic_read(&urb->reject))
41765 wake_up(&usb_kill_urb_queue);
41766 usb_put_urb(urb);
41767diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
41768index 818e4a0..0fc9589 100644
41769--- a/drivers/usb/core/sysfs.c
41770+++ b/drivers/usb/core/sysfs.c
41771@@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
41772 struct usb_device *udev;
41773
41774 udev = to_usb_device(dev);
41775- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
41776+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
41777 }
41778 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
41779
41780diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
41781index f81b925..78d22ec 100644
41782--- a/drivers/usb/core/usb.c
41783+++ b/drivers/usb/core/usb.c
41784@@ -388,7 +388,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
41785 set_dev_node(&dev->dev, dev_to_node(bus->controller));
41786 dev->state = USB_STATE_ATTACHED;
41787 dev->lpm_disable_count = 1;
41788- atomic_set(&dev->urbnum, 0);
41789+ atomic_set_unchecked(&dev->urbnum, 0);
41790
41791 INIT_LIST_HEAD(&dev->ep0.urb_list);
41792 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
41793diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
41794index 5e29dde..eca992f 100644
41795--- a/drivers/usb/early/ehci-dbgp.c
41796+++ b/drivers/usb/early/ehci-dbgp.c
41797@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
41798
41799 #ifdef CONFIG_KGDB
41800 static struct kgdb_io kgdbdbgp_io_ops;
41801-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
41802+static struct kgdb_io kgdbdbgp_io_ops_console;
41803+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
41804 #else
41805 #define dbgp_kgdb_mode (0)
41806 #endif
41807@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
41808 .write_char = kgdbdbgp_write_char,
41809 };
41810
41811+static struct kgdb_io kgdbdbgp_io_ops_console = {
41812+ .name = "kgdbdbgp",
41813+ .read_char = kgdbdbgp_read_char,
41814+ .write_char = kgdbdbgp_write_char,
41815+ .is_console = 1
41816+};
41817+
41818 static int kgdbdbgp_wait_time;
41819
41820 static int __init kgdbdbgp_parse_config(char *str)
41821@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
41822 ptr++;
41823 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
41824 }
41825- kgdb_register_io_module(&kgdbdbgp_io_ops);
41826- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
41827+ if (early_dbgp_console.index != -1)
41828+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
41829+ else
41830+ kgdb_register_io_module(&kgdbdbgp_io_ops);
41831
41832 return 0;
41833 }
41834diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
41835index 598dcc1..032dd4f 100644
41836--- a/drivers/usb/gadget/u_serial.c
41837+++ b/drivers/usb/gadget/u_serial.c
41838@@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
41839 spin_lock_irq(&port->port_lock);
41840
41841 /* already open? Great. */
41842- if (port->port.count) {
41843+ if (atomic_read(&port->port.count)) {
41844 status = 0;
41845- port->port.count++;
41846+ atomic_inc(&port->port.count);
41847
41848 /* currently opening/closing? wait ... */
41849 } else if (port->openclose) {
41850@@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
41851 tty->driver_data = port;
41852 port->port.tty = tty;
41853
41854- port->port.count = 1;
41855+ atomic_set(&port->port.count, 1);
41856 port->openclose = false;
41857
41858 /* if connected, start the I/O stream */
41859@@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
41860
41861 spin_lock_irq(&port->port_lock);
41862
41863- if (port->port.count != 1) {
41864- if (port->port.count == 0)
41865+ if (atomic_read(&port->port.count) != 1) {
41866+ if (atomic_read(&port->port.count) == 0)
41867 WARN_ON(1);
41868 else
41869- --port->port.count;
41870+ atomic_dec(&port->port.count);
41871 goto exit;
41872 }
41873
41874@@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
41875 * and sleep if necessary
41876 */
41877 port->openclose = true;
41878- port->port.count = 0;
41879+ atomic_set(&port->port.count, 0);
41880
41881 gser = port->port_usb;
41882 if (gser && gser->disconnect)
41883@@ -1159,7 +1159,7 @@ static int gs_closed(struct gs_port *port)
41884 int cond;
41885
41886 spin_lock_irq(&port->port_lock);
41887- cond = (port->port.count == 0) && !port->openclose;
41888+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
41889 spin_unlock_irq(&port->port_lock);
41890 return cond;
41891 }
41892@@ -1273,7 +1273,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
41893 /* if it's already open, start I/O ... and notify the serial
41894 * protocol about open/close status (connect/disconnect).
41895 */
41896- if (port->port.count) {
41897+ if (atomic_read(&port->port.count)) {
41898 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
41899 gs_start_io(port);
41900 if (gser->connect)
41901@@ -1320,7 +1320,7 @@ void gserial_disconnect(struct gserial *gser)
41902
41903 port->port_usb = NULL;
41904 gser->ioport = NULL;
41905- if (port->port.count > 0 || port->openclose) {
41906+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
41907 wake_up_interruptible(&port->drain_wait);
41908 if (port->port.tty)
41909 tty_hangup(port->port.tty);
41910@@ -1336,7 +1336,7 @@ void gserial_disconnect(struct gserial *gser)
41911
41912 /* finally, free any unused/unusable I/O buffers */
41913 spin_lock_irqsave(&port->port_lock, flags);
41914- if (port->port.count == 0 && !port->openclose)
41915+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
41916 gs_buf_free(&port->port_write_buf);
41917 gs_free_requests(gser->out, &port->read_pool, NULL);
41918 gs_free_requests(gser->out, &port->read_queue, NULL);
41919diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
41920index 5f3bcd3..bfca43f 100644
41921--- a/drivers/usb/serial/console.c
41922+++ b/drivers/usb/serial/console.c
41923@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
41924
41925 info->port = port;
41926
41927- ++port->port.count;
41928+ atomic_inc(&port->port.count);
41929 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
41930 if (serial->type->set_termios) {
41931 /*
41932@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
41933 }
41934 /* Now that any required fake tty operations are completed restore
41935 * the tty port count */
41936- --port->port.count;
41937+ atomic_dec(&port->port.count);
41938 /* The console is special in terms of closing the device so
41939 * indicate this port is now acting as a system console. */
41940 port->port.console = 1;
41941@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
41942 free_tty:
41943 kfree(tty);
41944 reset_open_count:
41945- port->port.count = 0;
41946+ atomic_set(&port->port.count, 0);
41947 usb_autopm_put_interface(serial->interface);
41948 error_get_interface:
41949 usb_serial_put(serial);
41950diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
41951index d6bea3e..60b250e 100644
41952--- a/drivers/usb/wusbcore/wa-hc.h
41953+++ b/drivers/usb/wusbcore/wa-hc.h
41954@@ -192,7 +192,7 @@ struct wahc {
41955 struct list_head xfer_delayed_list;
41956 spinlock_t xfer_list_lock;
41957 struct work_struct xfer_work;
41958- atomic_t xfer_id_count;
41959+ atomic_unchecked_t xfer_id_count;
41960 };
41961
41962
41963@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
41964 INIT_LIST_HEAD(&wa->xfer_delayed_list);
41965 spin_lock_init(&wa->xfer_list_lock);
41966 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
41967- atomic_set(&wa->xfer_id_count, 1);
41968+ atomic_set_unchecked(&wa->xfer_id_count, 1);
41969 }
41970
41971 /**
41972diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
41973index 57c01ab..8a05959 100644
41974--- a/drivers/usb/wusbcore/wa-xfer.c
41975+++ b/drivers/usb/wusbcore/wa-xfer.c
41976@@ -296,7 +296,7 @@ out:
41977 */
41978 static void wa_xfer_id_init(struct wa_xfer *xfer)
41979 {
41980- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
41981+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
41982 }
41983
41984 /*
41985diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
41986index 8c55011..eed4ae1a 100644
41987--- a/drivers/video/aty/aty128fb.c
41988+++ b/drivers/video/aty/aty128fb.c
41989@@ -149,7 +149,7 @@ enum {
41990 };
41991
41992 /* Must match above enum */
41993-static char * const r128_family[] = {
41994+static const char * const r128_family[] = {
41995 "AGP",
41996 "PCI",
41997 "PRO AGP",
41998diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
41999index 5c3960d..15cf8fc 100644
42000--- a/drivers/video/fbcmap.c
42001+++ b/drivers/video/fbcmap.c
42002@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
42003 rc = -ENODEV;
42004 goto out;
42005 }
42006- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
42007- !info->fbops->fb_setcmap)) {
42008+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
42009 rc = -EINVAL;
42010 goto out1;
42011 }
42012diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
42013index 3ff0105..7589d98 100644
42014--- a/drivers/video/fbmem.c
42015+++ b/drivers/video/fbmem.c
42016@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
42017 image->dx += image->width + 8;
42018 }
42019 } else if (rotate == FB_ROTATE_UD) {
42020- for (x = 0; x < num && image->dx >= 0; x++) {
42021+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
42022 info->fbops->fb_imageblit(info, image);
42023 image->dx -= image->width + 8;
42024 }
42025@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
42026 image->dy += image->height + 8;
42027 }
42028 } else if (rotate == FB_ROTATE_CCW) {
42029- for (x = 0; x < num && image->dy >= 0; x++) {
42030+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
42031 info->fbops->fb_imageblit(info, image);
42032 image->dy -= image->height + 8;
42033 }
42034@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
42035 return -EFAULT;
42036 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
42037 return -EINVAL;
42038- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
42039+ if (con2fb.framebuffer >= FB_MAX)
42040 return -EINVAL;
42041 if (!registered_fb[con2fb.framebuffer])
42042 request_module("fb%d", con2fb.framebuffer);
42043diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
42044index 7672d2e..b56437f 100644
42045--- a/drivers/video/i810/i810_accel.c
42046+++ b/drivers/video/i810/i810_accel.c
42047@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
42048 }
42049 }
42050 printk("ringbuffer lockup!!!\n");
42051+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
42052 i810_report_error(mmio);
42053 par->dev_flags |= LOCKUP;
42054 info->pixmap.scan_align = 1;
42055diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
42056index 3c14e43..eafa544 100644
42057--- a/drivers/video/logo/logo_linux_clut224.ppm
42058+++ b/drivers/video/logo/logo_linux_clut224.ppm
42059@@ -1,1604 +1,1123 @@
42060 P3
42061-# Standard 224-color Linux logo
42062 80 80
42063 255
42064- 0 0 0 0 0 0 0 0 0 0 0 0
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- 6 6 6 6 6 6 10 10 10 10 10 10
42074- 10 10 10 6 6 6 6 6 6 6 6 6
42075- 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 10 10 10 14 14 14
42093- 22 22 22 26 26 26 30 30 30 34 34 34
42094- 30 30 30 30 30 30 26 26 26 18 18 18
42095- 14 14 14 10 10 10 6 6 6 0 0 0
42096- 0 0 0 0 0 0 0 0 0 0 0 0
42097- 0 0 0 0 0 0 0 0 0 0 0 0
42098- 0 0 0 0 0 0 0 0 0 0 0 0
42099- 0 0 0 0 0 0 0 0 0 0 0 0
42100- 0 0 0 0 0 0 0 0 0 0 0 0
42101- 0 0 0 0 0 0 0 0 0 0 0 0
42102- 0 0 0 0 0 0 0 0 0 0 0 0
42103- 0 0 0 0 0 0 0 0 0 0 0 0
42104- 0 0 0 0 0 0 0 0 0 0 0 0
42105- 0 0 0 0 0 1 0 0 1 0 0 0
42106- 0 0 0 0 0 0 0 0 0 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- 6 6 6 14 14 14 26 26 26 42 42 42
42113- 54 54 54 66 66 66 78 78 78 78 78 78
42114- 78 78 78 74 74 74 66 66 66 54 54 54
42115- 42 42 42 26 26 26 18 18 18 10 10 10
42116- 6 6 6 0 0 0 0 0 0 0 0 0
42117- 0 0 0 0 0 0 0 0 0 0 0 0
42118- 0 0 0 0 0 0 0 0 0 0 0 0
42119- 0 0 0 0 0 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 1 0 0 0 0 0 0 0 0 0
42126- 0 0 0 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 10 10 10
42132- 22 22 22 42 42 42 66 66 66 86 86 86
42133- 66 66 66 38 38 38 38 38 38 22 22 22
42134- 26 26 26 34 34 34 54 54 54 66 66 66
42135- 86 86 86 70 70 70 46 46 46 26 26 26
42136- 14 14 14 6 6 6 0 0 0 0 0 0
42137- 0 0 0 0 0 0 0 0 0 0 0 0
42138- 0 0 0 0 0 0 0 0 0 0 0 0
42139- 0 0 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 1 0 0 1 0 0 1 0 0 0
42146- 0 0 0 0 0 0 0 0 0 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 10 10 10 26 26 26
42152- 50 50 50 82 82 82 58 58 58 6 6 6
42153- 2 2 6 2 2 6 2 2 6 2 2 6
42154- 2 2 6 2 2 6 2 2 6 2 2 6
42155- 6 6 6 54 54 54 86 86 86 66 66 66
42156- 38 38 38 18 18 18 6 6 6 0 0 0
42157- 0 0 0 0 0 0 0 0 0 0 0 0
42158- 0 0 0 0 0 0 0 0 0 0 0 0
42159- 0 0 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 6 6 6 22 22 22 50 50 50
42172- 78 78 78 34 34 34 2 2 6 2 2 6
42173- 2 2 6 2 2 6 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 6 6 6 70 70 70
42176- 78 78 78 46 46 46 22 22 22 6 6 6
42177- 0 0 0 0 0 0 0 0 0 0 0 0
42178- 0 0 0 0 0 0 0 0 0 0 0 0
42179- 0 0 0 0 0 0 0 0 0 0 0 0
42180- 0 0 0 0 0 0 0 0 0 0 0 0
42181- 0 0 0 0 0 0 0 0 0 0 0 0
42182- 0 0 0 0 0 0 0 0 0 0 0 0
42183- 0 0 0 0 0 0 0 0 0 0 0 0
42184- 0 0 0 0 0 0 0 0 0 0 0 0
42185- 0 0 1 0 0 1 0 0 1 0 0 0
42186- 0 0 0 0 0 0 0 0 0 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- 6 6 6 18 18 18 42 42 42 82 82 82
42192- 26 26 26 2 2 6 2 2 6 2 2 6
42193- 2 2 6 2 2 6 2 2 6 2 2 6
42194- 2 2 6 2 2 6 2 2 6 14 14 14
42195- 46 46 46 34 34 34 6 6 6 2 2 6
42196- 42 42 42 78 78 78 42 42 42 18 18 18
42197- 6 6 6 0 0 0 0 0 0 0 0 0
42198- 0 0 0 0 0 0 0 0 0 0 0 0
42199- 0 0 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 1 0 0 0 0 0 1 0 0 0
42206- 0 0 0 0 0 0 0 0 0 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- 10 10 10 30 30 30 66 66 66 58 58 58
42212- 2 2 6 2 2 6 2 2 6 2 2 6
42213- 2 2 6 2 2 6 2 2 6 2 2 6
42214- 2 2 6 2 2 6 2 2 6 26 26 26
42215- 86 86 86 101 101 101 46 46 46 10 10 10
42216- 2 2 6 58 58 58 70 70 70 34 34 34
42217- 10 10 10 0 0 0 0 0 0 0 0 0
42218- 0 0 0 0 0 0 0 0 0 0 0 0
42219- 0 0 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 1 0 0 1 0 0 1 0 0 0
42226- 0 0 0 0 0 0 0 0 0 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- 14 14 14 42 42 42 86 86 86 10 10 10
42232- 2 2 6 2 2 6 2 2 6 2 2 6
42233- 2 2 6 2 2 6 2 2 6 2 2 6
42234- 2 2 6 2 2 6 2 2 6 30 30 30
42235- 94 94 94 94 94 94 58 58 58 26 26 26
42236- 2 2 6 6 6 6 78 78 78 54 54 54
42237- 22 22 22 6 6 6 0 0 0 0 0 0
42238- 0 0 0 0 0 0 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 6 6 6
42251- 22 22 22 62 62 62 62 62 62 2 2 6
42252- 2 2 6 2 2 6 2 2 6 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 26 26 26
42255- 54 54 54 38 38 38 18 18 18 10 10 10
42256- 2 2 6 2 2 6 34 34 34 82 82 82
42257- 38 38 38 14 14 14 0 0 0 0 0 0
42258- 0 0 0 0 0 0 0 0 0 0 0 0
42259- 0 0 0 0 0 0 0 0 0 0 0 0
42260- 0 0 0 0 0 0 0 0 0 0 0 0
42261- 0 0 0 0 0 0 0 0 0 0 0 0
42262- 0 0 0 0 0 0 0 0 0 0 0 0
42263- 0 0 0 0 0 0 0 0 0 0 0 0
42264- 0 0 0 0 0 0 0 0 0 0 0 0
42265- 0 0 0 0 0 1 0 0 1 0 0 0
42266- 0 0 0 0 0 0 0 0 0 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 6 6 6
42271- 30 30 30 78 78 78 30 30 30 2 2 6
42272- 2 2 6 2 2 6 2 2 6 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 10 10 10
42275- 10 10 10 2 2 6 2 2 6 2 2 6
42276- 2 2 6 2 2 6 2 2 6 78 78 78
42277- 50 50 50 18 18 18 6 6 6 0 0 0
42278- 0 0 0 0 0 0 0 0 0 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 1 0 0 0 0 0 0 0 0 0
42286- 0 0 0 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 10 10 10
42291- 38 38 38 86 86 86 14 14 14 2 2 6
42292- 2 2 6 2 2 6 2 2 6 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 54 54 54
42297- 66 66 66 26 26 26 6 6 6 0 0 0
42298- 0 0 0 0 0 0 0 0 0 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 1 0 0 1 0 0 0
42306- 0 0 0 0 0 0 0 0 0 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 14 14 14
42311- 42 42 42 82 82 82 2 2 6 2 2 6
42312- 2 2 6 6 6 6 10 10 10 2 2 6
42313- 2 2 6 2 2 6 2 2 6 2 2 6
42314- 2 2 6 2 2 6 2 2 6 6 6 6
42315- 14 14 14 10 10 10 2 2 6 2 2 6
42316- 2 2 6 2 2 6 2 2 6 18 18 18
42317- 82 82 82 34 34 34 10 10 10 0 0 0
42318- 0 0 0 0 0 0 0 0 0 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 1 0 0 0 0 0 0 0 0 0
42326- 0 0 0 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 14 14 14
42331- 46 46 46 86 86 86 2 2 6 2 2 6
42332- 6 6 6 6 6 6 22 22 22 34 34 34
42333- 6 6 6 2 2 6 2 2 6 2 2 6
42334- 2 2 6 2 2 6 18 18 18 34 34 34
42335- 10 10 10 50 50 50 22 22 22 2 2 6
42336- 2 2 6 2 2 6 2 2 6 10 10 10
42337- 86 86 86 42 42 42 14 14 14 0 0 0
42338- 0 0 0 0 0 0 0 0 0 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 1 0 0 1 0 0 1 0 0 0
42346- 0 0 0 0 0 0 0 0 0 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 14 14 14
42351- 46 46 46 86 86 86 2 2 6 2 2 6
42352- 38 38 38 116 116 116 94 94 94 22 22 22
42353- 22 22 22 2 2 6 2 2 6 2 2 6
42354- 14 14 14 86 86 86 138 138 138 162 162 162
42355-154 154 154 38 38 38 26 26 26 6 6 6
42356- 2 2 6 2 2 6 2 2 6 2 2 6
42357- 86 86 86 46 46 46 14 14 14 0 0 0
42358- 0 0 0 0 0 0 0 0 0 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 14 14 14
42371- 46 46 46 86 86 86 2 2 6 14 14 14
42372-134 134 134 198 198 198 195 195 195 116 116 116
42373- 10 10 10 2 2 6 2 2 6 6 6 6
42374-101 98 89 187 187 187 210 210 210 218 218 218
42375-214 214 214 134 134 134 14 14 14 6 6 6
42376- 2 2 6 2 2 6 2 2 6 2 2 6
42377- 86 86 86 50 50 50 18 18 18 6 6 6
42378- 0 0 0 0 0 0 0 0 0 0 0 0
42379- 0 0 0 0 0 0 0 0 0 0 0 0
42380- 0 0 0 0 0 0 0 0 0 0 0 0
42381- 0 0 0 0 0 0 0 0 0 0 0 0
42382- 0 0 0 0 0 0 0 0 0 0 0 0
42383- 0 0 0 0 0 0 0 0 0 0 0 0
42384- 0 0 0 0 0 0 0 0 1 0 0 0
42385- 0 0 1 0 0 1 0 0 1 0 0 0
42386- 0 0 0 0 0 0 0 0 0 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 14 14 14
42391- 46 46 46 86 86 86 2 2 6 54 54 54
42392-218 218 218 195 195 195 226 226 226 246 246 246
42393- 58 58 58 2 2 6 2 2 6 30 30 30
42394-210 210 210 253 253 253 174 174 174 123 123 123
42395-221 221 221 234 234 234 74 74 74 2 2 6
42396- 2 2 6 2 2 6 2 2 6 2 2 6
42397- 70 70 70 58 58 58 22 22 22 6 6 6
42398- 0 0 0 0 0 0 0 0 0 0 0 0
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 14 14 14
42411- 46 46 46 82 82 82 2 2 6 106 106 106
42412-170 170 170 26 26 26 86 86 86 226 226 226
42413-123 123 123 10 10 10 14 14 14 46 46 46
42414-231 231 231 190 190 190 6 6 6 70 70 70
42415- 90 90 90 238 238 238 158 158 158 2 2 6
42416- 2 2 6 2 2 6 2 2 6 2 2 6
42417- 70 70 70 58 58 58 22 22 22 6 6 6
42418- 0 0 0 0 0 0 0 0 0 0 0 0
42419- 0 0 0 0 0 0 0 0 0 0 0 0
42420- 0 0 0 0 0 0 0 0 0 0 0 0
42421- 0 0 0 0 0 0 0 0 0 0 0 0
42422- 0 0 0 0 0 0 0 0 0 0 0 0
42423- 0 0 0 0 0 0 0 0 0 0 0 0
42424- 0 0 0 0 0 0 0 0 1 0 0 0
42425- 0 0 1 0 0 1 0 0 1 0 0 0
42426- 0 0 0 0 0 0 0 0 0 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 14 14 14
42431- 42 42 42 86 86 86 6 6 6 116 116 116
42432-106 106 106 6 6 6 70 70 70 149 149 149
42433-128 128 128 18 18 18 38 38 38 54 54 54
42434-221 221 221 106 106 106 2 2 6 14 14 14
42435- 46 46 46 190 190 190 198 198 198 2 2 6
42436- 2 2 6 2 2 6 2 2 6 2 2 6
42437- 74 74 74 62 62 62 22 22 22 6 6 6
42438- 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 0
42445- 0 0 1 0 0 0 0 0 1 0 0 0
42446- 0 0 0 0 0 0 0 0 0 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 14 14 14
42451- 42 42 42 94 94 94 14 14 14 101 101 101
42452-128 128 128 2 2 6 18 18 18 116 116 116
42453-118 98 46 121 92 8 121 92 8 98 78 10
42454-162 162 162 106 106 106 2 2 6 2 2 6
42455- 2 2 6 195 195 195 195 195 195 6 6 6
42456- 2 2 6 2 2 6 2 2 6 2 2 6
42457- 74 74 74 62 62 62 22 22 22 6 6 6
42458- 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 1
42465- 0 0 1 0 0 0 0 0 1 0 0 0
42466- 0 0 0 0 0 0 0 0 0 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 10 10 10
42471- 38 38 38 90 90 90 14 14 14 58 58 58
42472-210 210 210 26 26 26 54 38 6 154 114 10
42473-226 170 11 236 186 11 225 175 15 184 144 12
42474-215 174 15 175 146 61 37 26 9 2 2 6
42475- 70 70 70 246 246 246 138 138 138 2 2 6
42476- 2 2 6 2 2 6 2 2 6 2 2 6
42477- 70 70 70 66 66 66 26 26 26 6 6 6
42478- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
42491- 38 38 38 86 86 86 14 14 14 10 10 10
42492-195 195 195 188 164 115 192 133 9 225 175 15
42493-239 182 13 234 190 10 232 195 16 232 200 30
42494-245 207 45 241 208 19 232 195 16 184 144 12
42495-218 194 134 211 206 186 42 42 42 2 2 6
42496- 2 2 6 2 2 6 2 2 6 2 2 6
42497- 50 50 50 74 74 74 30 30 30 6 6 6
42498- 0 0 0 0 0 0 0 0 0 0 0 0
42499- 0 0 0 0 0 0 0 0 0 0 0 0
42500- 0 0 0 0 0 0 0 0 0 0 0 0
42501- 0 0 0 0 0 0 0 0 0 0 0 0
42502- 0 0 0 0 0 0 0 0 0 0 0 0
42503- 0 0 0 0 0 0 0 0 0 0 0 0
42504- 0 0 0 0 0 0 0 0 0 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 10 10 10
42511- 34 34 34 86 86 86 14 14 14 2 2 6
42512-121 87 25 192 133 9 219 162 10 239 182 13
42513-236 186 11 232 195 16 241 208 19 244 214 54
42514-246 218 60 246 218 38 246 215 20 241 208 19
42515-241 208 19 226 184 13 121 87 25 2 2 6
42516- 2 2 6 2 2 6 2 2 6 2 2 6
42517- 50 50 50 82 82 82 34 34 34 10 10 10
42518- 0 0 0 0 0 0 0 0 0 0 0 0
42519- 0 0 0 0 0 0 0 0 0 0 0 0
42520- 0 0 0 0 0 0 0 0 0 0 0 0
42521- 0 0 0 0 0 0 0 0 0 0 0 0
42522- 0 0 0 0 0 0 0 0 0 0 0 0
42523- 0 0 0 0 0 0 0 0 0 0 0 0
42524- 0 0 0 0 0 0 0 0 0 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 10 10 10
42531- 34 34 34 82 82 82 30 30 30 61 42 6
42532-180 123 7 206 145 10 230 174 11 239 182 13
42533-234 190 10 238 202 15 241 208 19 246 218 74
42534-246 218 38 246 215 20 246 215 20 246 215 20
42535-226 184 13 215 174 15 184 144 12 6 6 6
42536- 2 2 6 2 2 6 2 2 6 2 2 6
42537- 26 26 26 94 94 94 42 42 42 14 14 14
42538- 0 0 0 0 0 0 0 0 0 0 0 0
42539- 0 0 0 0 0 0 0 0 0 0 0 0
42540- 0 0 0 0 0 0 0 0 0 0 0 0
42541- 0 0 0 0 0 0 0 0 0 0 0 0
42542- 0 0 0 0 0 0 0 0 0 0 0 0
42543- 0 0 0 0 0 0 0 0 0 0 0 0
42544- 0 0 0 0 0 0 0 0 0 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 10 10 10
42551- 30 30 30 78 78 78 50 50 50 104 69 6
42552-192 133 9 216 158 10 236 178 12 236 186 11
42553-232 195 16 241 208 19 244 214 54 245 215 43
42554-246 215 20 246 215 20 241 208 19 198 155 10
42555-200 144 11 216 158 10 156 118 10 2 2 6
42556- 2 2 6 2 2 6 2 2 6 2 2 6
42557- 6 6 6 90 90 90 54 54 54 18 18 18
42558- 6 6 6 0 0 0 0 0 0 0 0 0
42559- 0 0 0 0 0 0 0 0 0 0 0 0
42560- 0 0 0 0 0 0 0 0 0 0 0 0
42561- 0 0 0 0 0 0 0 0 0 0 0 0
42562- 0 0 0 0 0 0 0 0 0 0 0 0
42563- 0 0 0 0 0 0 0 0 0 0 0 0
42564- 0 0 0 0 0 0 0 0 0 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 10 10 10
42571- 30 30 30 78 78 78 46 46 46 22 22 22
42572-137 92 6 210 162 10 239 182 13 238 190 10
42573-238 202 15 241 208 19 246 215 20 246 215 20
42574-241 208 19 203 166 17 185 133 11 210 150 10
42575-216 158 10 210 150 10 102 78 10 2 2 6
42576- 6 6 6 54 54 54 14 14 14 2 2 6
42577- 2 2 6 62 62 62 74 74 74 30 30 30
42578- 10 10 10 0 0 0 0 0 0 0 0 0
42579- 0 0 0 0 0 0 0 0 0 0 0 0
42580- 0 0 0 0 0 0 0 0 0 0 0 0
42581- 0 0 0 0 0 0 0 0 0 0 0 0
42582- 0 0 0 0 0 0 0 0 0 0 0 0
42583- 0 0 0 0 0 0 0 0 0 0 0 0
42584- 0 0 0 0 0 0 0 0 0 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 10 10 10
42591- 34 34 34 78 78 78 50 50 50 6 6 6
42592- 94 70 30 139 102 15 190 146 13 226 184 13
42593-232 200 30 232 195 16 215 174 15 190 146 13
42594-168 122 10 192 133 9 210 150 10 213 154 11
42595-202 150 34 182 157 106 101 98 89 2 2 6
42596- 2 2 6 78 78 78 116 116 116 58 58 58
42597- 2 2 6 22 22 22 90 90 90 46 46 46
42598- 18 18 18 6 6 6 0 0 0 0 0 0
42599- 0 0 0 0 0 0 0 0 0 0 0 0
42600- 0 0 0 0 0 0 0 0 0 0 0 0
42601- 0 0 0 0 0 0 0 0 0 0 0 0
42602- 0 0 0 0 0 0 0 0 0 0 0 0
42603- 0 0 0 0 0 0 0 0 0 0 0 0
42604- 0 0 0 0 0 0 0 0 0 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 10 10 10
42611- 38 38 38 86 86 86 50 50 50 6 6 6
42612-128 128 128 174 154 114 156 107 11 168 122 10
42613-198 155 10 184 144 12 197 138 11 200 144 11
42614-206 145 10 206 145 10 197 138 11 188 164 115
42615-195 195 195 198 198 198 174 174 174 14 14 14
42616- 2 2 6 22 22 22 116 116 116 116 116 116
42617- 22 22 22 2 2 6 74 74 74 70 70 70
42618- 30 30 30 10 10 10 0 0 0 0 0 0
42619- 0 0 0 0 0 0 0 0 0 0 0 0
42620- 0 0 0 0 0 0 0 0 0 0 0 0
42621- 0 0 0 0 0 0 0 0 0 0 0 0
42622- 0 0 0 0 0 0 0 0 0 0 0 0
42623- 0 0 0 0 0 0 0 0 0 0 0 0
42624- 0 0 0 0 0 0 0 0 0 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 6 6 6 18 18 18
42631- 50 50 50 101 101 101 26 26 26 10 10 10
42632-138 138 138 190 190 190 174 154 114 156 107 11
42633-197 138 11 200 144 11 197 138 11 192 133 9
42634-180 123 7 190 142 34 190 178 144 187 187 187
42635-202 202 202 221 221 221 214 214 214 66 66 66
42636- 2 2 6 2 2 6 50 50 50 62 62 62
42637- 6 6 6 2 2 6 10 10 10 90 90 90
42638- 50 50 50 18 18 18 6 6 6 0 0 0
42639- 0 0 0 0 0 0 0 0 0 0 0 0
42640- 0 0 0 0 0 0 0 0 0 0 0 0
42641- 0 0 0 0 0 0 0 0 0 0 0 0
42642- 0 0 0 0 0 0 0 0 0 0 0 0
42643- 0 0 0 0 0 0 0 0 0 0 0 0
42644- 0 0 0 0 0 0 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 10 10 10 34 34 34
42651- 74 74 74 74 74 74 2 2 6 6 6 6
42652-144 144 144 198 198 198 190 190 190 178 166 146
42653-154 121 60 156 107 11 156 107 11 168 124 44
42654-174 154 114 187 187 187 190 190 190 210 210 210
42655-246 246 246 253 253 253 253 253 253 182 182 182
42656- 6 6 6 2 2 6 2 2 6 2 2 6
42657- 2 2 6 2 2 6 2 2 6 62 62 62
42658- 74 74 74 34 34 34 14 14 14 0 0 0
42659- 0 0 0 0 0 0 0 0 0 0 0 0
42660- 0 0 0 0 0 0 0 0 0 0 0 0
42661- 0 0 0 0 0 0 0 0 0 0 0 0
42662- 0 0 0 0 0 0 0 0 0 0 0 0
42663- 0 0 0 0 0 0 0 0 0 0 0 0
42664- 0 0 0 0 0 0 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 10 10 10 22 22 22 54 54 54
42671- 94 94 94 18 18 18 2 2 6 46 46 46
42672-234 234 234 221 221 221 190 190 190 190 190 190
42673-190 190 190 187 187 187 187 187 187 190 190 190
42674-190 190 190 195 195 195 214 214 214 242 242 242
42675-253 253 253 253 253 253 253 253 253 253 253 253
42676- 82 82 82 2 2 6 2 2 6 2 2 6
42677- 2 2 6 2 2 6 2 2 6 14 14 14
42678- 86 86 86 54 54 54 22 22 22 6 6 6
42679- 0 0 0 0 0 0 0 0 0 0 0 0
42680- 0 0 0 0 0 0 0 0 0 0 0 0
42681- 0 0 0 0 0 0 0 0 0 0 0 0
42682- 0 0 0 0 0 0 0 0 0 0 0 0
42683- 0 0 0 0 0 0 0 0 0 0 0 0
42684- 0 0 0 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- 6 6 6 18 18 18 46 46 46 90 90 90
42691- 46 46 46 18 18 18 6 6 6 182 182 182
42692-253 253 253 246 246 246 206 206 206 190 190 190
42693-190 190 190 190 190 190 190 190 190 190 190 190
42694-206 206 206 231 231 231 250 250 250 253 253 253
42695-253 253 253 253 253 253 253 253 253 253 253 253
42696-202 202 202 14 14 14 2 2 6 2 2 6
42697- 2 2 6 2 2 6 2 2 6 2 2 6
42698- 42 42 42 86 86 86 42 42 42 18 18 18
42699- 6 6 6 0 0 0 0 0 0 0 0 0
42700- 0 0 0 0 0 0 0 0 0 0 0 0
42701- 0 0 0 0 0 0 0 0 0 0 0 0
42702- 0 0 0 0 0 0 0 0 0 0 0 0
42703- 0 0 0 0 0 0 0 0 0 0 0 0
42704- 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 6 6 6
42710- 14 14 14 38 38 38 74 74 74 66 66 66
42711- 2 2 6 6 6 6 90 90 90 250 250 250
42712-253 253 253 253 253 253 238 238 238 198 198 198
42713-190 190 190 190 190 190 195 195 195 221 221 221
42714-246 246 246 253 253 253 253 253 253 253 253 253
42715-253 253 253 253 253 253 253 253 253 253 253 253
42716-253 253 253 82 82 82 2 2 6 2 2 6
42717- 2 2 6 2 2 6 2 2 6 2 2 6
42718- 2 2 6 78 78 78 70 70 70 34 34 34
42719- 14 14 14 6 6 6 0 0 0 0 0 0
42720- 0 0 0 0 0 0 0 0 0 0 0 0
42721- 0 0 0 0 0 0 0 0 0 0 0 0
42722- 0 0 0 0 0 0 0 0 0 0 0 0
42723- 0 0 0 0 0 0 0 0 0 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 14 14 14
42730- 34 34 34 66 66 66 78 78 78 6 6 6
42731- 2 2 6 18 18 18 218 218 218 253 253 253
42732-253 253 253 253 253 253 253 253 253 246 246 246
42733-226 226 226 231 231 231 246 246 246 253 253 253
42734-253 253 253 253 253 253 253 253 253 253 253 253
42735-253 253 253 253 253 253 253 253 253 253 253 253
42736-253 253 253 178 178 178 2 2 6 2 2 6
42737- 2 2 6 2 2 6 2 2 6 2 2 6
42738- 2 2 6 18 18 18 90 90 90 62 62 62
42739- 30 30 30 10 10 10 0 0 0 0 0 0
42740- 0 0 0 0 0 0 0 0 0 0 0 0
42741- 0 0 0 0 0 0 0 0 0 0 0 0
42742- 0 0 0 0 0 0 0 0 0 0 0 0
42743- 0 0 0 0 0 0 0 0 0 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 10 10 10 26 26 26
42750- 58 58 58 90 90 90 18 18 18 2 2 6
42751- 2 2 6 110 110 110 253 253 253 253 253 253
42752-253 253 253 253 253 253 253 253 253 253 253 253
42753-250 250 250 253 253 253 253 253 253 253 253 253
42754-253 253 253 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 231 231 231 18 18 18 2 2 6
42757- 2 2 6 2 2 6 2 2 6 2 2 6
42758- 2 2 6 2 2 6 18 18 18 94 94 94
42759- 54 54 54 26 26 26 10 10 10 0 0 0
42760- 0 0 0 0 0 0 0 0 0 0 0 0
42761- 0 0 0 0 0 0 0 0 0 0 0 0
42762- 0 0 0 0 0 0 0 0 0 0 0 0
42763- 0 0 0 0 0 0 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 6 6 6 22 22 22 50 50 50
42770- 90 90 90 26 26 26 2 2 6 2 2 6
42771- 14 14 14 195 195 195 250 250 250 253 253 253
42772-253 253 253 253 253 253 253 253 253 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-250 250 250 242 242 242 54 54 54 2 2 6
42777- 2 2 6 2 2 6 2 2 6 2 2 6
42778- 2 2 6 2 2 6 2 2 6 38 38 38
42779- 86 86 86 50 50 50 22 22 22 6 6 6
42780- 0 0 0 0 0 0 0 0 0 0 0 0
42781- 0 0 0 0 0 0 0 0 0 0 0 0
42782- 0 0 0 0 0 0 0 0 0 0 0 0
42783- 0 0 0 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- 6 6 6 14 14 14 38 38 38 82 82 82
42790- 34 34 34 2 2 6 2 2 6 2 2 6
42791- 42 42 42 195 195 195 246 246 246 253 253 253
42792-253 253 253 253 253 253 253 253 253 250 250 250
42793-242 242 242 242 242 242 250 250 250 253 253 253
42794-253 253 253 253 253 253 253 253 253 253 253 253
42795-253 253 253 250 250 250 246 246 246 238 238 238
42796-226 226 226 231 231 231 101 101 101 6 6 6
42797- 2 2 6 2 2 6 2 2 6 2 2 6
42798- 2 2 6 2 2 6 2 2 6 2 2 6
42799- 38 38 38 82 82 82 42 42 42 14 14 14
42800- 6 6 6 0 0 0 0 0 0 0 0 0
42801- 0 0 0 0 0 0 0 0 0 0 0 0
42802- 0 0 0 0 0 0 0 0 0 0 0 0
42803- 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- 10 10 10 26 26 26 62 62 62 66 66 66
42810- 2 2 6 2 2 6 2 2 6 6 6 6
42811- 70 70 70 170 170 170 206 206 206 234 234 234
42812-246 246 246 250 250 250 250 250 250 238 238 238
42813-226 226 226 231 231 231 238 238 238 250 250 250
42814-250 250 250 250 250 250 246 246 246 231 231 231
42815-214 214 214 206 206 206 202 202 202 202 202 202
42816-198 198 198 202 202 202 182 182 182 18 18 18
42817- 2 2 6 2 2 6 2 2 6 2 2 6
42818- 2 2 6 2 2 6 2 2 6 2 2 6
42819- 2 2 6 62 62 62 66 66 66 30 30 30
42820- 10 10 10 0 0 0 0 0 0 0 0 0
42821- 0 0 0 0 0 0 0 0 0 0 0 0
42822- 0 0 0 0 0 0 0 0 0 0 0 0
42823- 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- 14 14 14 42 42 42 82 82 82 18 18 18
42830- 2 2 6 2 2 6 2 2 6 10 10 10
42831- 94 94 94 182 182 182 218 218 218 242 242 242
42832-250 250 250 253 253 253 253 253 253 250 250 250
42833-234 234 234 253 253 253 253 253 253 253 253 253
42834-253 253 253 253 253 253 253 253 253 246 246 246
42835-238 238 238 226 226 226 210 210 210 202 202 202
42836-195 195 195 195 195 195 210 210 210 158 158 158
42837- 6 6 6 14 14 14 50 50 50 14 14 14
42838- 2 2 6 2 2 6 2 2 6 2 2 6
42839- 2 2 6 6 6 6 86 86 86 46 46 46
42840- 18 18 18 6 6 6 0 0 0 0 0 0
42841- 0 0 0 0 0 0 0 0 0 0 0 0
42842- 0 0 0 0 0 0 0 0 0 0 0 0
42843- 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 6 6 6
42849- 22 22 22 54 54 54 70 70 70 2 2 6
42850- 2 2 6 10 10 10 2 2 6 22 22 22
42851-166 166 166 231 231 231 250 250 250 253 253 253
42852-253 253 253 253 253 253 253 253 253 250 250 250
42853-242 242 242 253 253 253 253 253 253 253 253 253
42854-253 253 253 253 253 253 253 253 253 253 253 253
42855-253 253 253 253 253 253 253 253 253 246 246 246
42856-231 231 231 206 206 206 198 198 198 226 226 226
42857- 94 94 94 2 2 6 6 6 6 38 38 38
42858- 30 30 30 2 2 6 2 2 6 2 2 6
42859- 2 2 6 2 2 6 62 62 62 66 66 66
42860- 26 26 26 10 10 10 0 0 0 0 0 0
42861- 0 0 0 0 0 0 0 0 0 0 0 0
42862- 0 0 0 0 0 0 0 0 0 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 10 10 10
42869- 30 30 30 74 74 74 50 50 50 2 2 6
42870- 26 26 26 26 26 26 2 2 6 106 106 106
42871-238 238 238 253 253 253 253 253 253 253 253 253
42872-253 253 253 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 246 246 246 218 218 218 202 202 202
42877-210 210 210 14 14 14 2 2 6 2 2 6
42878- 30 30 30 22 22 22 2 2 6 2 2 6
42879- 2 2 6 2 2 6 18 18 18 86 86 86
42880- 42 42 42 14 14 14 0 0 0 0 0 0
42881- 0 0 0 0 0 0 0 0 0 0 0 0
42882- 0 0 0 0 0 0 0 0 0 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 14 14 14
42889- 42 42 42 90 90 90 22 22 22 2 2 6
42890- 42 42 42 2 2 6 18 18 18 218 218 218
42891-253 253 253 253 253 253 253 253 253 253 253 253
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 250 250 250 221 221 221
42897-218 218 218 101 101 101 2 2 6 14 14 14
42898- 18 18 18 38 38 38 10 10 10 2 2 6
42899- 2 2 6 2 2 6 2 2 6 78 78 78
42900- 58 58 58 22 22 22 6 6 6 0 0 0
42901- 0 0 0 0 0 0 0 0 0 0 0 0
42902- 0 0 0 0 0 0 0 0 0 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 6 6 6 18 18 18
42909- 54 54 54 82 82 82 2 2 6 26 26 26
42910- 22 22 22 2 2 6 123 123 123 253 253 253
42911-253 253 253 253 253 253 253 253 253 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 250 250 250
42917-238 238 238 198 198 198 6 6 6 38 38 38
42918- 58 58 58 26 26 26 38 38 38 2 2 6
42919- 2 2 6 2 2 6 2 2 6 46 46 46
42920- 78 78 78 30 30 30 10 10 10 0 0 0
42921- 0 0 0 0 0 0 0 0 0 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 10 10 10 30 30 30
42929- 74 74 74 58 58 58 2 2 6 42 42 42
42930- 2 2 6 22 22 22 231 231 231 253 253 253
42931-253 253 253 253 253 253 253 253 253 253 253 253
42932-253 253 253 253 253 253 253 253 253 250 250 250
42933-253 253 253 253 253 253 253 253 253 253 253 253
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 246 246 246 46 46 46 38 38 38
42938- 42 42 42 14 14 14 38 38 38 14 14 14
42939- 2 2 6 2 2 6 2 2 6 6 6 6
42940- 86 86 86 46 46 46 14 14 14 0 0 0
42941- 0 0 0 0 0 0 0 0 0 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 6 6 6 14 14 14 42 42 42
42949- 90 90 90 18 18 18 18 18 18 26 26 26
42950- 2 2 6 116 116 116 253 253 253 253 253 253
42951-253 253 253 253 253 253 253 253 253 253 253 253
42952-253 253 253 253 253 253 250 250 250 238 238 238
42953-253 253 253 253 253 253 253 253 253 253 253 253
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 94 94 94 6 6 6
42958- 2 2 6 2 2 6 10 10 10 34 34 34
42959- 2 2 6 2 2 6 2 2 6 2 2 6
42960- 74 74 74 58 58 58 22 22 22 6 6 6
42961- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10 26 26 26 66 66 66
42969- 82 82 82 2 2 6 38 38 38 6 6 6
42970- 14 14 14 210 210 210 253 253 253 253 253 253
42971-253 253 253 253 253 253 253 253 253 253 253 253
42972-253 253 253 253 253 253 246 246 246 242 242 242
42973-253 253 253 253 253 253 253 253 253 253 253 253
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 144 144 144 2 2 6
42978- 2 2 6 2 2 6 2 2 6 46 46 46
42979- 2 2 6 2 2 6 2 2 6 2 2 6
42980- 42 42 42 74 74 74 30 30 30 10 10 10
42981- 0 0 0 0 0 0 0 0 0 0 0 0
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- 6 6 6 14 14 14 42 42 42 90 90 90
42989- 26 26 26 6 6 6 42 42 42 2 2 6
42990- 74 74 74 250 250 250 253 253 253 253 253 253
42991-253 253 253 253 253 253 253 253 253 253 253 253
42992-253 253 253 253 253 253 242 242 242 242 242 242
42993-253 253 253 253 253 253 253 253 253 253 253 253
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 182 182 182 2 2 6
42998- 2 2 6 2 2 6 2 2 6 46 46 46
42999- 2 2 6 2 2 6 2 2 6 2 2 6
43000- 10 10 10 86 86 86 38 38 38 10 10 10
43001- 0 0 0 0 0 0 0 0 0 0 0 0
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- 10 10 10 26 26 26 66 66 66 82 82 82
43009- 2 2 6 22 22 22 18 18 18 2 2 6
43010-149 149 149 253 253 253 253 253 253 253 253 253
43011-253 253 253 253 253 253 253 253 253 253 253 253
43012-253 253 253 253 253 253 234 234 234 242 242 242
43013-253 253 253 253 253 253 253 253 253 253 253 253
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 206 206 206 2 2 6
43018- 2 2 6 2 2 6 2 2 6 38 38 38
43019- 2 2 6 2 2 6 2 2 6 2 2 6
43020- 6 6 6 86 86 86 46 46 46 14 14 14
43021- 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6
43028- 18 18 18 46 46 46 86 86 86 18 18 18
43029- 2 2 6 34 34 34 10 10 10 6 6 6
43030-210 210 210 253 253 253 253 253 253 253 253 253
43031-253 253 253 253 253 253 253 253 253 253 253 253
43032-253 253 253 253 253 253 234 234 234 242 242 242
43033-253 253 253 253 253 253 253 253 253 253 253 253
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 221 221 221 6 6 6
43038- 2 2 6 2 2 6 6 6 6 30 30 30
43039- 2 2 6 2 2 6 2 2 6 2 2 6
43040- 2 2 6 82 82 82 54 54 54 18 18 18
43041- 6 6 6 0 0 0 0 0 0 0 0 0
43042- 0 0 0 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 10 10 10
43048- 26 26 26 66 66 66 62 62 62 2 2 6
43049- 2 2 6 38 38 38 10 10 10 26 26 26
43050-238 238 238 253 253 253 253 253 253 253 253 253
43051-253 253 253 253 253 253 253 253 253 253 253 253
43052-253 253 253 253 253 253 231 231 231 238 238 238
43053-253 253 253 253 253 253 253 253 253 253 253 253
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 231 231 231 6 6 6
43058- 2 2 6 2 2 6 10 10 10 30 30 30
43059- 2 2 6 2 2 6 2 2 6 2 2 6
43060- 2 2 6 66 66 66 58 58 58 22 22 22
43061- 6 6 6 0 0 0 0 0 0 0 0 0
43062- 0 0 0 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 10 10 10
43068- 38 38 38 78 78 78 6 6 6 2 2 6
43069- 2 2 6 46 46 46 14 14 14 42 42 42
43070-246 246 246 253 253 253 253 253 253 253 253 253
43071-253 253 253 253 253 253 253 253 253 253 253 253
43072-253 253 253 253 253 253 231 231 231 242 242 242
43073-253 253 253 253 253 253 253 253 253 253 253 253
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 234 234 234 10 10 10
43078- 2 2 6 2 2 6 22 22 22 14 14 14
43079- 2 2 6 2 2 6 2 2 6 2 2 6
43080- 2 2 6 66 66 66 62 62 62 22 22 22
43081- 6 6 6 0 0 0 0 0 0 0 0 0
43082- 0 0 0 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 6 6 6 18 18 18
43088- 50 50 50 74 74 74 2 2 6 2 2 6
43089- 14 14 14 70 70 70 34 34 34 62 62 62
43090-250 250 250 253 253 253 253 253 253 253 253 253
43091-253 253 253 253 253 253 253 253 253 253 253 253
43092-253 253 253 253 253 253 231 231 231 246 246 246
43093-253 253 253 253 253 253 253 253 253 253 253 253
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 234 234 234 14 14 14
43098- 2 2 6 2 2 6 30 30 30 2 2 6
43099- 2 2 6 2 2 6 2 2 6 2 2 6
43100- 2 2 6 66 66 66 62 62 62 22 22 22
43101- 6 6 6 0 0 0 0 0 0 0 0 0
43102- 0 0 0 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 6 6 6 18 18 18
43108- 54 54 54 62 62 62 2 2 6 2 2 6
43109- 2 2 6 30 30 30 46 46 46 70 70 70
43110-250 250 250 253 253 253 253 253 253 253 253 253
43111-253 253 253 253 253 253 253 253 253 253 253 253
43112-253 253 253 253 253 253 231 231 231 246 246 246
43113-253 253 253 253 253 253 253 253 253 253 253 253
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 226 226 226 10 10 10
43118- 2 2 6 6 6 6 30 30 30 2 2 6
43119- 2 2 6 2 2 6 2 2 6 2 2 6
43120- 2 2 6 66 66 66 58 58 58 22 22 22
43121- 6 6 6 0 0 0 0 0 0 0 0 0
43122- 0 0 0 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 6 6 6 22 22 22
43128- 58 58 58 62 62 62 2 2 6 2 2 6
43129- 2 2 6 2 2 6 30 30 30 78 78 78
43130-250 250 250 253 253 253 253 253 253 253 253 253
43131-253 253 253 253 253 253 253 253 253 253 253 253
43132-253 253 253 253 253 253 231 231 231 246 246 246
43133-253 253 253 253 253 253 253 253 253 253 253 253
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 206 206 206 2 2 6
43138- 22 22 22 34 34 34 18 14 6 22 22 22
43139- 26 26 26 18 18 18 6 6 6 2 2 6
43140- 2 2 6 82 82 82 54 54 54 18 18 18
43141- 6 6 6 0 0 0 0 0 0 0 0 0
43142- 0 0 0 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 6 6 6 26 26 26
43148- 62 62 62 106 106 106 74 54 14 185 133 11
43149-210 162 10 121 92 8 6 6 6 62 62 62
43150-238 238 238 253 253 253 253 253 253 253 253 253
43151-253 253 253 253 253 253 253 253 253 253 253 253
43152-253 253 253 253 253 253 231 231 231 246 246 246
43153-253 253 253 253 253 253 253 253 253 253 253 253
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 158 158 158 18 18 18
43158- 14 14 14 2 2 6 2 2 6 2 2 6
43159- 6 6 6 18 18 18 66 66 66 38 38 38
43160- 6 6 6 94 94 94 50 50 50 18 18 18
43161- 6 6 6 0 0 0 0 0 0 0 0 0
43162- 0 0 0 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 6 6 6
43167- 10 10 10 10 10 10 18 18 18 38 38 38
43168- 78 78 78 142 134 106 216 158 10 242 186 14
43169-246 190 14 246 190 14 156 118 10 10 10 10
43170- 90 90 90 238 238 238 253 253 253 253 253 253
43171-253 253 253 253 253 253 253 253 253 253 253 253
43172-253 253 253 253 253 253 231 231 231 250 250 250
43173-253 253 253 253 253 253 253 253 253 253 253 253
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 246 230 190
43177-238 204 91 238 204 91 181 142 44 37 26 9
43178- 2 2 6 2 2 6 2 2 6 2 2 6
43179- 2 2 6 2 2 6 38 38 38 46 46 46
43180- 26 26 26 106 106 106 54 54 54 18 18 18
43181- 6 6 6 0 0 0 0 0 0 0 0 0
43182- 0 0 0 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 6 6 6 14 14 14 22 22 22
43187- 30 30 30 38 38 38 50 50 50 70 70 70
43188-106 106 106 190 142 34 226 170 11 242 186 14
43189-246 190 14 246 190 14 246 190 14 154 114 10
43190- 6 6 6 74 74 74 226 226 226 253 253 253
43191-253 253 253 253 253 253 253 253 253 253 253 253
43192-253 253 253 253 253 253 231 231 231 250 250 250
43193-253 253 253 253 253 253 253 253 253 253 253 253
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 228 184 62
43197-241 196 14 241 208 19 232 195 16 38 30 10
43198- 2 2 6 2 2 6 2 2 6 2 2 6
43199- 2 2 6 6 6 6 30 30 30 26 26 26
43200-203 166 17 154 142 90 66 66 66 26 26 26
43201- 6 6 6 0 0 0 0 0 0 0 0 0
43202- 0 0 0 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- 6 6 6 18 18 18 38 38 38 58 58 58
43207- 78 78 78 86 86 86 101 101 101 123 123 123
43208-175 146 61 210 150 10 234 174 13 246 186 14
43209-246 190 14 246 190 14 246 190 14 238 190 10
43210-102 78 10 2 2 6 46 46 46 198 198 198
43211-253 253 253 253 253 253 253 253 253 253 253 253
43212-253 253 253 253 253 253 234 234 234 242 242 242
43213-253 253 253 253 253 253 253 253 253 253 253 253
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 224 178 62
43217-242 186 14 241 196 14 210 166 10 22 18 6
43218- 2 2 6 2 2 6 2 2 6 2 2 6
43219- 2 2 6 2 2 6 6 6 6 121 92 8
43220-238 202 15 232 195 16 82 82 82 34 34 34
43221- 10 10 10 0 0 0 0 0 0 0 0 0
43222- 0 0 0 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- 14 14 14 38 38 38 70 70 70 154 122 46
43227-190 142 34 200 144 11 197 138 11 197 138 11
43228-213 154 11 226 170 11 242 186 14 246 190 14
43229-246 190 14 246 190 14 246 190 14 246 190 14
43230-225 175 15 46 32 6 2 2 6 22 22 22
43231-158 158 158 250 250 250 253 253 253 253 253 253
43232-253 253 253 253 253 253 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 250 250 250 242 242 242 224 178 62
43237-239 182 13 236 186 11 213 154 11 46 32 6
43238- 2 2 6 2 2 6 2 2 6 2 2 6
43239- 2 2 6 2 2 6 61 42 6 225 175 15
43240-238 190 10 236 186 11 112 100 78 42 42 42
43241- 14 14 14 0 0 0 0 0 0 0 0 0
43242- 0 0 0 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 6 6 6
43246- 22 22 22 54 54 54 154 122 46 213 154 11
43247-226 170 11 230 174 11 226 170 11 226 170 11
43248-236 178 12 242 186 14 246 190 14 246 190 14
43249-246 190 14 246 190 14 246 190 14 246 190 14
43250-241 196 14 184 144 12 10 10 10 2 2 6
43251- 6 6 6 116 116 116 242 242 242 253 253 253
43252-253 253 253 253 253 253 253 253 253 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 231 231 231 198 198 198 214 170 54
43257-236 178 12 236 178 12 210 150 10 137 92 6
43258- 18 14 6 2 2 6 2 2 6 2 2 6
43259- 6 6 6 70 47 6 200 144 11 236 178 12
43260-239 182 13 239 182 13 124 112 88 58 58 58
43261- 22 22 22 6 6 6 0 0 0 0 0 0
43262- 0 0 0 0 0 0 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 10 10 10
43266- 30 30 30 70 70 70 180 133 36 226 170 11
43267-239 182 13 242 186 14 242 186 14 246 186 14
43268-246 190 14 246 190 14 246 190 14 246 190 14
43269-246 190 14 246 190 14 246 190 14 246 190 14
43270-246 190 14 232 195 16 98 70 6 2 2 6
43271- 2 2 6 2 2 6 66 66 66 221 221 221
43272-253 253 253 253 253 253 253 253 253 253 253 253
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 206 206 206 198 198 198 214 166 58
43277-230 174 11 230 174 11 216 158 10 192 133 9
43278-163 110 8 116 81 8 102 78 10 116 81 8
43279-167 114 7 197 138 11 226 170 11 239 182 13
43280-242 186 14 242 186 14 162 146 94 78 78 78
43281- 34 34 34 14 14 14 6 6 6 0 0 0
43282- 0 0 0 0 0 0 0 0 0 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 6 6 6
43286- 30 30 30 78 78 78 190 142 34 226 170 11
43287-239 182 13 246 190 14 246 190 14 246 190 14
43288-246 190 14 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 241 196 14 203 166 17 22 18 6
43291- 2 2 6 2 2 6 2 2 6 38 38 38
43292-218 218 218 253 253 253 253 253 253 253 253 253
43293-253 253 253 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-250 250 250 206 206 206 198 198 198 202 162 69
43297-226 170 11 236 178 12 224 166 10 210 150 10
43298-200 144 11 197 138 11 192 133 9 197 138 11
43299-210 150 10 226 170 11 242 186 14 246 190 14
43300-246 190 14 246 186 14 225 175 15 124 112 88
43301- 62 62 62 30 30 30 14 14 14 6 6 6
43302- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
43306- 30 30 30 78 78 78 174 135 50 224 166 10
43307-239 182 13 246 190 14 246 190 14 246 190 14
43308-246 190 14 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 241 196 14 139 102 15
43311- 2 2 6 2 2 6 2 2 6 2 2 6
43312- 78 78 78 250 250 250 253 253 253 253 253 253
43313-253 253 253 253 253 253 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-250 250 250 214 214 214 198 198 198 190 150 46
43317-219 162 10 236 178 12 234 174 13 224 166 10
43318-216 158 10 213 154 11 213 154 11 216 158 10
43319-226 170 11 239 182 13 246 190 14 246 190 14
43320-246 190 14 246 190 14 242 186 14 206 162 42
43321-101 101 101 58 58 58 30 30 30 14 14 14
43322- 6 6 6 0 0 0 0 0 0 0 0 0
43323- 0 0 0 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 10 10 10
43326- 30 30 30 74 74 74 174 135 50 216 158 10
43327-236 178 12 246 190 14 246 190 14 246 190 14
43328-246 190 14 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 241 196 14 226 184 13
43331- 61 42 6 2 2 6 2 2 6 2 2 6
43332- 22 22 22 238 238 238 253 253 253 253 253 253
43333-253 253 253 253 253 253 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 226 226 226 187 187 187 180 133 36
43337-216 158 10 236 178 12 239 182 13 236 178 12
43338-230 174 11 226 170 11 226 170 11 230 174 11
43339-236 178 12 242 186 14 246 190 14 246 190 14
43340-246 190 14 246 190 14 246 186 14 239 182 13
43341-206 162 42 106 106 106 66 66 66 34 34 34
43342- 14 14 14 6 6 6 0 0 0 0 0 0
43343- 0 0 0 0 0 0 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 6 6 6
43346- 26 26 26 70 70 70 163 133 67 213 154 11
43347-236 178 12 246 190 14 246 190 14 246 190 14
43348-246 190 14 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 241 196 14
43351-190 146 13 18 14 6 2 2 6 2 2 6
43352- 46 46 46 246 246 246 253 253 253 253 253 253
43353-253 253 253 253 253 253 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 221 221 221 86 86 86 156 107 11
43357-216 158 10 236 178 12 242 186 14 246 186 14
43358-242 186 14 239 182 13 239 182 13 242 186 14
43359-242 186 14 246 186 14 246 190 14 246 190 14
43360-246 190 14 246 190 14 246 190 14 246 190 14
43361-242 186 14 225 175 15 142 122 72 66 66 66
43362- 30 30 30 10 10 10 0 0 0 0 0 0
43363- 0 0 0 0 0 0 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 6 6 6
43366- 26 26 26 70 70 70 163 133 67 210 150 10
43367-236 178 12 246 190 14 246 190 14 246 190 14
43368-246 190 14 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-232 195 16 121 92 8 34 34 34 106 106 106
43372-221 221 221 253 253 253 253 253 253 253 253 253
43373-253 253 253 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-242 242 242 82 82 82 18 14 6 163 110 8
43377-216 158 10 236 178 12 242 186 14 246 190 14
43378-246 190 14 246 190 14 246 190 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 242 186 14 163 133 67
43382- 46 46 46 18 18 18 6 6 6 0 0 0
43383- 0 0 0 0 0 0 0 0 0 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 10 10 10
43386- 30 30 30 78 78 78 163 133 67 210 150 10
43387-236 178 12 246 186 14 246 190 14 246 190 14
43388-246 190 14 246 190 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-241 196 14 215 174 15 190 178 144 253 253 253
43392-253 253 253 253 253 253 253 253 253 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 218 218 218
43396- 58 58 58 2 2 6 22 18 6 167 114 7
43397-216 158 10 236 178 12 246 186 14 246 190 14
43398-246 190 14 246 190 14 246 190 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 186 14 242 186 14 190 150 46
43402- 54 54 54 22 22 22 6 6 6 0 0 0
43403- 0 0 0 0 0 0 0 0 0 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 14 14 14
43406- 38 38 38 86 86 86 180 133 36 213 154 11
43407-236 178 12 246 186 14 246 190 14 246 190 14
43408-246 190 14 246 190 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 232 195 16 190 146 13 214 214 214
43412-253 253 253 253 253 253 253 253 253 253 253 253
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 250 250 250 170 170 170 26 26 26
43416- 2 2 6 2 2 6 37 26 9 163 110 8
43417-219 162 10 239 182 13 246 186 14 246 190 14
43418-246 190 14 246 190 14 246 190 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 186 14 236 178 12 224 166 10 142 122 72
43422- 46 46 46 18 18 18 6 6 6 0 0 0
43423- 0 0 0 0 0 0 0 0 0 0 0 0
43424- 0 0 0 0 0 0 0 0 0 0 0 0
43425- 0 0 0 0 0 0 6 6 6 18 18 18
43426- 50 50 50 109 106 95 192 133 9 224 166 10
43427-242 186 14 246 190 14 246 190 14 246 190 14
43428-246 190 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-242 186 14 226 184 13 210 162 10 142 110 46
43432-226 226 226 253 253 253 253 253 253 253 253 253
43433-253 253 253 253 253 253 253 253 253 253 253 253
43434-253 253 253 253 253 253 253 253 253 253 253 253
43435-198 198 198 66 66 66 2 2 6 2 2 6
43436- 2 2 6 2 2 6 50 34 6 156 107 11
43437-219 162 10 239 182 13 246 186 14 246 190 14
43438-246 190 14 246 190 14 246 190 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 242 186 14
43441-234 174 13 213 154 11 154 122 46 66 66 66
43442- 30 30 30 10 10 10 0 0 0 0 0 0
43443- 0 0 0 0 0 0 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 6 6 6 22 22 22
43446- 58 58 58 154 121 60 206 145 10 234 174 13
43447-242 186 14 246 186 14 246 190 14 246 190 14
43448-246 190 14 246 190 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 186 14 236 178 12 210 162 10 163 110 8
43452- 61 42 6 138 138 138 218 218 218 250 250 250
43453-253 253 253 253 253 253 253 253 253 250 250 250
43454-242 242 242 210 210 210 144 144 144 66 66 66
43455- 6 6 6 2 2 6 2 2 6 2 2 6
43456- 2 2 6 2 2 6 61 42 6 163 110 8
43457-216 158 10 236 178 12 246 190 14 246 190 14
43458-246 190 14 246 190 14 246 190 14 246 190 14
43459-246 190 14 246 190 14 246 190 14 246 190 14
43460-246 190 14 239 182 13 230 174 11 216 158 10
43461-190 142 34 124 112 88 70 70 70 38 38 38
43462- 18 18 18 6 6 6 0 0 0 0 0 0
43463- 0 0 0 0 0 0 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 6 6 6 22 22 22
43466- 62 62 62 168 124 44 206 145 10 224 166 10
43467-236 178 12 239 182 13 242 186 14 242 186 14
43468-246 186 14 246 190 14 246 190 14 246 190 14
43469-246 190 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 236 178 12 216 158 10 175 118 6
43472- 80 54 7 2 2 6 6 6 6 30 30 30
43473- 54 54 54 62 62 62 50 50 50 38 38 38
43474- 14 14 14 2 2 6 2 2 6 2 2 6
43475- 2 2 6 2 2 6 2 2 6 2 2 6
43476- 2 2 6 6 6 6 80 54 7 167 114 7
43477-213 154 11 236 178 12 246 190 14 246 190 14
43478-246 190 14 246 190 14 246 190 14 246 190 14
43479-246 190 14 242 186 14 239 182 13 239 182 13
43480-230 174 11 210 150 10 174 135 50 124 112 88
43481- 82 82 82 54 54 54 34 34 34 18 18 18
43482- 6 6 6 0 0 0 0 0 0 0 0 0
43483- 0 0 0 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 6 6 6 18 18 18
43486- 50 50 50 158 118 36 192 133 9 200 144 11
43487-216 158 10 219 162 10 224 166 10 226 170 11
43488-230 174 11 236 178 12 239 182 13 239 182 13
43489-242 186 14 246 186 14 246 190 14 246 190 14
43490-246 190 14 246 190 14 246 190 14 246 190 14
43491-246 186 14 230 174 11 210 150 10 163 110 8
43492-104 69 6 10 10 10 2 2 6 2 2 6
43493- 2 2 6 2 2 6 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 6 6 6 91 60 6 167 114 7
43497-206 145 10 230 174 11 242 186 14 246 190 14
43498-246 190 14 246 190 14 246 186 14 242 186 14
43499-239 182 13 230 174 11 224 166 10 213 154 11
43500-180 133 36 124 112 88 86 86 86 58 58 58
43501- 38 38 38 22 22 22 10 10 10 6 6 6
43502- 0 0 0 0 0 0 0 0 0 0 0 0
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 14 14 14
43506- 34 34 34 70 70 70 138 110 50 158 118 36
43507-167 114 7 180 123 7 192 133 9 197 138 11
43508-200 144 11 206 145 10 213 154 11 219 162 10
43509-224 166 10 230 174 11 239 182 13 242 186 14
43510-246 186 14 246 186 14 246 186 14 246 186 14
43511-239 182 13 216 158 10 185 133 11 152 99 6
43512-104 69 6 18 14 6 2 2 6 2 2 6
43513- 2 2 6 2 2 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 6 6 6 80 54 7 152 99 6
43517-192 133 9 219 162 10 236 178 12 239 182 13
43518-246 186 14 242 186 14 239 182 13 236 178 12
43519-224 166 10 206 145 10 192 133 9 154 121 60
43520- 94 94 94 62 62 62 42 42 42 22 22 22
43521- 14 14 14 6 6 6 0 0 0 0 0 0
43522- 0 0 0 0 0 0 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 6 6 6
43526- 18 18 18 34 34 34 58 58 58 78 78 78
43527-101 98 89 124 112 88 142 110 46 156 107 11
43528-163 110 8 167 114 7 175 118 6 180 123 7
43529-185 133 11 197 138 11 210 150 10 219 162 10
43530-226 170 11 236 178 12 236 178 12 234 174 13
43531-219 162 10 197 138 11 163 110 8 130 83 6
43532- 91 60 6 10 10 10 2 2 6 2 2 6
43533- 18 18 18 38 38 38 38 38 38 38 38 38
43534- 38 38 38 38 38 38 38 38 38 38 38 38
43535- 38 38 38 38 38 38 26 26 26 2 2 6
43536- 2 2 6 6 6 6 70 47 6 137 92 6
43537-175 118 6 200 144 11 219 162 10 230 174 11
43538-234 174 13 230 174 11 219 162 10 210 150 10
43539-192 133 9 163 110 8 124 112 88 82 82 82
43540- 50 50 50 30 30 30 14 14 14 6 6 6
43541- 0 0 0 0 0 0 0 0 0 0 0 0
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- 6 6 6 14 14 14 22 22 22 34 34 34
43547- 42 42 42 58 58 58 74 74 74 86 86 86
43548-101 98 89 122 102 70 130 98 46 121 87 25
43549-137 92 6 152 99 6 163 110 8 180 123 7
43550-185 133 11 197 138 11 206 145 10 200 144 11
43551-180 123 7 156 107 11 130 83 6 104 69 6
43552- 50 34 6 54 54 54 110 110 110 101 98 89
43553- 86 86 86 82 82 82 78 78 78 78 78 78
43554- 78 78 78 78 78 78 78 78 78 78 78 78
43555- 78 78 78 82 82 82 86 86 86 94 94 94
43556-106 106 106 101 101 101 86 66 34 124 80 6
43557-156 107 11 180 123 7 192 133 9 200 144 11
43558-206 145 10 200 144 11 192 133 9 175 118 6
43559-139 102 15 109 106 95 70 70 70 42 42 42
43560- 22 22 22 10 10 10 0 0 0 0 0 0
43561- 0 0 0 0 0 0 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 6 6 6 10 10 10
43567- 14 14 14 22 22 22 30 30 30 38 38 38
43568- 50 50 50 62 62 62 74 74 74 90 90 90
43569-101 98 89 112 100 78 121 87 25 124 80 6
43570-137 92 6 152 99 6 152 99 6 152 99 6
43571-138 86 6 124 80 6 98 70 6 86 66 30
43572-101 98 89 82 82 82 58 58 58 46 46 46
43573- 38 38 38 34 34 34 34 34 34 34 34 34
43574- 34 34 34 34 34 34 34 34 34 34 34 34
43575- 34 34 34 34 34 34 38 38 38 42 42 42
43576- 54 54 54 82 82 82 94 86 76 91 60 6
43577-134 86 6 156 107 11 167 114 7 175 118 6
43578-175 118 6 167 114 7 152 99 6 121 87 25
43579-101 98 89 62 62 62 34 34 34 18 18 18
43580- 6 6 6 0 0 0 0 0 0 0 0 0
43581- 0 0 0 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 6 6 6 6 6 6 10 10 10
43588- 18 18 18 22 22 22 30 30 30 42 42 42
43589- 50 50 50 66 66 66 86 86 86 101 98 89
43590-106 86 58 98 70 6 104 69 6 104 69 6
43591-104 69 6 91 60 6 82 62 34 90 90 90
43592- 62 62 62 38 38 38 22 22 22 14 14 14
43593- 10 10 10 10 10 10 10 10 10 10 10 10
43594- 10 10 10 10 10 10 6 6 6 10 10 10
43595- 10 10 10 10 10 10 10 10 10 14 14 14
43596- 22 22 22 42 42 42 70 70 70 89 81 66
43597- 80 54 7 104 69 6 124 80 6 137 92 6
43598-134 86 6 116 81 8 100 82 52 86 86 86
43599- 58 58 58 30 30 30 14 14 14 6 6 6
43600- 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 10 10 10 14 14 14
43609- 18 18 18 26 26 26 38 38 38 54 54 54
43610- 70 70 70 86 86 86 94 86 76 89 81 66
43611- 89 81 66 86 86 86 74 74 74 50 50 50
43612- 30 30 30 14 14 14 6 6 6 0 0 0
43613- 0 0 0 0 0 0 0 0 0 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- 6 6 6 18 18 18 34 34 34 58 58 58
43617- 82 82 82 89 81 66 89 81 66 89 81 66
43618- 94 86 66 94 86 76 74 74 74 50 50 50
43619- 26 26 26 14 14 14 6 6 6 0 0 0
43620- 0 0 0 0 0 0 0 0 0 0 0 0
43621- 0 0 0 0 0 0 0 0 0 0 0 0
43622- 0 0 0 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- 6 6 6 6 6 6 14 14 14 18 18 18
43630- 30 30 30 38 38 38 46 46 46 54 54 54
43631- 50 50 50 42 42 42 30 30 30 18 18 18
43632- 10 10 10 0 0 0 0 0 0 0 0 0
43633- 0 0 0 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 6 6 6 14 14 14 26 26 26
43637- 38 38 38 50 50 50 58 58 58 58 58 58
43638- 54 54 54 42 42 42 30 30 30 18 18 18
43639- 10 10 10 0 0 0 0 0 0 0 0 0
43640- 0 0 0 0 0 0 0 0 0 0 0 0
43641- 0 0 0 0 0 0 0 0 0 0 0 0
43642- 0 0 0 0 0 0 0 0 0 0 0 0
43643- 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 6 6 6
43650- 6 6 6 10 10 10 14 14 14 18 18 18
43651- 18 18 18 14 14 14 10 10 10 6 6 6
43652- 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6
43657- 14 14 14 18 18 18 22 22 22 22 22 22
43658- 18 18 18 14 14 14 10 10 10 6 6 6
43659- 0 0 0 0 0 0 0 0 0 0 0 0
43660- 0 0 0 0 0 0 0 0 0 0 0 0
43661- 0 0 0 0 0 0 0 0 0 0 0 0
43662- 0 0 0 0 0 0 0 0 0 0 0 0
43663- 0 0 0 0 0 0 0 0 0 0 0 0
43664+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
43678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43683+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43684+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43685+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43691+4 4 4 4 4 4
43692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43699+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43705+4 4 4 4 4 4
43706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43713+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43716+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43719+4 4 4 4 4 4
43720+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43727+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43730+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43733+4 4 4 4 4 4
43734+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43735+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43741+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43744+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43747+4 4 4 4 4 4
43748+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43752+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
43753+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
43754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43755+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43757+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
43758+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
43759+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
43760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43761+4 4 4 4 4 4
43762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43766+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
43767+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
43768+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43771+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
43772+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
43773+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
43774+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43775+4 4 4 4 4 4
43776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43780+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
43781+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
43782+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
43783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43785+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
43786+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
43787+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
43788+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
43789+4 4 4 4 4 4
43790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43793+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
43794+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
43795+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
43796+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
43797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43798+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
43799+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
43800+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
43801+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
43802+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
43803+4 4 4 4 4 4
43804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43806+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43807+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
43808+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
43809+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
43810+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
43811+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43812+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
43813+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
43814+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
43815+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
43816+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
43817+4 4 4 4 4 4
43818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43820+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43821+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
43822+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
43823+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
43824+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
43825+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
43826+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
43827+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
43828+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
43829+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
43830+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
43831+4 4 4 4 4 4
43832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43834+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
43835+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
43836+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
43837+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
43838+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
43839+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
43840+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
43841+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
43842+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
43843+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
43844+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
43845+4 4 4 4 4 4
43846+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43848+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
43849+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
43850+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
43851+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
43852+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
43853+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
43854+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
43855+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
43856+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
43857+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
43858+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
43859+4 4 4 4 4 4
43860+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43862+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
43863+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
43864+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
43865+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
43866+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
43867+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
43868+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
43869+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
43870+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
43871+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
43872+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
43873+4 4 4 4 4 4
43874+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43875+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43876+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
43877+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
43878+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
43879+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
43880+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
43881+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
43882+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
43883+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
43884+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
43885+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
43886+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
43887+4 4 4 4 4 4
43888+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43889+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
43890+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
43891+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
43892+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
43893+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
43894+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
43895+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
43896+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
43897+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
43898+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
43899+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
43900+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
43901+4 4 4 4 4 4
43902+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43903+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
43904+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
43905+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
43906+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
43907+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
43908+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
43909+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
43910+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
43911+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
43912+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
43913+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
43914+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
43915+0 0 0 4 4 4
43916+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
43917+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
43918+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
43919+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
43920+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
43921+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
43922+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
43923+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
43924+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
43925+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
43926+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
43927+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
43928+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
43929+2 0 0 0 0 0
43930+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
43931+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
43932+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
43933+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
43934+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
43935+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
43936+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
43937+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
43938+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
43939+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
43940+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
43941+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
43942+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
43943+37 38 37 0 0 0
43944+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
43945+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
43946+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
43947+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
43948+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
43949+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
43950+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
43951+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
43952+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
43953+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
43954+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
43955+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
43956+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
43957+85 115 134 4 0 0
43958+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
43959+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
43960+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
43961+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
43962+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
43963+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
43964+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
43965+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
43966+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
43967+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
43968+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
43969+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
43970+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
43971+60 73 81 4 0 0
43972+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
43973+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
43974+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
43975+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
43976+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
43977+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
43978+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
43979+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
43980+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
43981+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
43982+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
43983+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
43984+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
43985+16 19 21 4 0 0
43986+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
43987+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
43988+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
43989+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
43990+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
43991+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
43992+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
43993+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
43994+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
43995+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
43996+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
43997+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
43998+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
43999+4 0 0 4 3 3
44000+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
44001+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
44002+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
44003+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
44004+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
44005+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
44006+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
44007+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
44008+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
44009+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
44010+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
44011+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
44012+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
44013+3 2 2 4 4 4
44014+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
44015+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
44016+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
44017+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
44018+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
44019+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
44020+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
44021+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
44022+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
44023+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
44024+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
44025+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
44026+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
44027+4 4 4 4 4 4
44028+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
44029+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
44030+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
44031+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
44032+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
44033+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
44034+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
44035+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
44036+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
44037+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
44038+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
44039+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
44040+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
44041+4 4 4 4 4 4
44042+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
44043+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
44044+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
44045+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
44046+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
44047+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
44048+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
44049+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
44050+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
44051+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
44052+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
44053+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
44054+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
44055+5 5 5 5 5 5
44056+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
44057+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
44058+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
44059+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
44060+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
44061+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44062+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
44063+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
44064+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
44065+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
44066+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
44067+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
44068+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
44069+5 5 5 4 4 4
44070+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
44071+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
44072+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
44073+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
44074+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
44075+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
44076+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
44077+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
44078+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
44079+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
44080+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
44081+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
44082+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44083+4 4 4 4 4 4
44084+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
44085+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
44086+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
44087+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
44088+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
44089+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44090+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44091+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
44092+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
44093+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
44094+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
44095+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
44096+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44097+4 4 4 4 4 4
44098+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
44099+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
44100+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
44101+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
44102+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
44103+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
44104+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
44105+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
44106+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
44107+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
44108+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
44109+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44110+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44111+4 4 4 4 4 4
44112+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
44113+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
44114+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
44115+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
44116+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
44117+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44118+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44119+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
44120+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
44121+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
44122+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
44123+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44124+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44125+4 4 4 4 4 4
44126+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
44127+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
44128+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
44129+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
44130+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
44131+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
44132+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
44133+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
44134+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
44135+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
44136+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44137+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44138+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44139+4 4 4 4 4 4
44140+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
44141+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
44142+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
44143+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
44144+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
44145+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
44146+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
44147+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
44148+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
44149+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
44150+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
44151+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44152+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44153+4 4 4 4 4 4
44154+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
44155+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
44156+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
44157+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
44158+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
44159+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
44160+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
44161+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
44162+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
44163+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
44164+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
44165+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44166+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44167+4 4 4 4 4 4
44168+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
44169+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
44170+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
44171+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
44172+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
44173+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
44174+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
44175+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
44176+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
44177+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
44178+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44179+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44180+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44181+4 4 4 4 4 4
44182+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
44183+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
44184+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
44185+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
44186+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44187+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
44188+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
44189+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
44190+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
44191+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
44192+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44193+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44194+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44195+4 4 4 4 4 4
44196+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
44197+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
44198+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
44199+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
44200+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44201+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
44202+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
44203+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
44204+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
44205+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
44206+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44207+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44208+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44209+4 4 4 4 4 4
44210+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
44211+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
44212+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
44213+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
44214+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44215+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
44216+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
44217+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
44218+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
44219+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44220+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44221+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44222+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44223+4 4 4 4 4 4
44224+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
44225+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
44226+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
44227+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
44228+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
44229+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
44230+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
44231+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
44232+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
44233+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44234+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44235+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44236+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44237+4 4 4 4 4 4
44238+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
44239+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
44240+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
44241+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
44242+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44243+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
44244+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
44245+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
44246+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
44247+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44248+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44249+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44250+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44251+4 4 4 4 4 4
44252+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
44253+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
44254+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
44255+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
44256+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
44257+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
44258+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
44259+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
44260+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
44261+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44262+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44263+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44264+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44265+4 4 4 4 4 4
44266+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
44267+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
44268+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
44269+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
44270+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
44271+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
44272+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
44273+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
44274+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
44275+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44276+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44277+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44278+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44279+4 4 4 4 4 4
44280+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
44281+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
44282+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
44283+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
44284+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
44285+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
44286+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
44287+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
44288+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
44289+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44290+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44291+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44292+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44293+4 4 4 4 4 4
44294+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
44295+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
44296+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
44297+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
44298+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
44299+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
44300+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
44301+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
44302+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
44303+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44304+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44305+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44306+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44307+4 4 4 4 4 4
44308+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
44309+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
44310+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
44311+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
44312+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
44313+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
44314+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
44315+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
44316+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
44317+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44318+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44319+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44320+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44321+4 4 4 4 4 4
44322+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
44323+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
44324+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
44325+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
44326+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
44327+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
44328+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
44329+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
44330+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
44331+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44332+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44333+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44334+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44335+4 4 4 4 4 4
44336+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
44337+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
44338+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
44339+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
44340+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
44341+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
44342+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44343+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
44344+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
44345+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44346+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44347+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44348+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44349+4 4 4 4 4 4
44350+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
44351+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
44352+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
44353+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
44354+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
44355+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
44356+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44357+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
44358+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
44359+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44360+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44361+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44362+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44363+4 4 4 4 4 4
44364+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
44365+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
44366+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
44367+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
44368+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
44369+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
44370+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
44371+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
44372+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
44373+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44374+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44375+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44376+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44377+4 4 4 4 4 4
44378+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
44379+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
44380+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
44381+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
44382+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
44383+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
44384+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
44385+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
44386+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
44387+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44388+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44389+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44390+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44391+4 4 4 4 4 4
44392+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
44393+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
44394+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
44395+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
44396+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
44397+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
44398+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
44399+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
44400+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
44401+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44402+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44403+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44404+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44405+4 4 4 4 4 4
44406+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
44407+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
44408+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
44409+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
44410+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
44411+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
44412+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
44413+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
44414+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
44415+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44416+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44417+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44418+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44419+4 4 4 4 4 4
44420+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
44421+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
44422+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
44423+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
44424+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
44425+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
44426+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
44427+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
44428+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
44429+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
44430+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44431+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44432+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44433+4 4 4 4 4 4
44434+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
44435+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
44436+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
44437+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
44438+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
44439+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
44440+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
44441+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
44442+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
44443+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
44444+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44445+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44446+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44447+4 4 4 4 4 4
44448+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
44449+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
44450+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
44451+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
44452+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
44453+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
44454+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44455+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
44456+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
44457+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
44458+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
44459+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44460+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44461+4 4 4 4 4 4
44462+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
44463+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
44464+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
44465+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
44466+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
44467+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
44468+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
44469+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
44470+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
44471+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
44472+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44473+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44474+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44475+4 4 4 4 4 4
44476+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
44477+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
44478+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
44479+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
44480+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
44481+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
44482+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
44483+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
44484+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
44485+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
44486+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44487+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44488+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44489+4 4 4 4 4 4
44490+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
44491+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
44492+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
44493+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
44494+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
44495+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
44496+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
44497+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
44498+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
44499+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
44500+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44501+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44502+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44503+4 4 4 4 4 4
44504+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
44505+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
44506+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
44507+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
44508+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
44509+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
44510+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
44511+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
44512+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
44513+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
44514+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44515+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44516+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44517+4 4 4 4 4 4
44518+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
44519+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
44520+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
44521+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
44522+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
44523+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
44524+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
44525+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
44526+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
44527+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
44528+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44529+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44530+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44531+4 4 4 4 4 4
44532+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
44533+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
44534+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
44535+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
44536+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
44537+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
44538+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
44539+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
44540+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
44541+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44542+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44543+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44544+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44545+4 4 4 4 4 4
44546+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
44547+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
44548+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
44549+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
44550+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
44551+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
44552+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
44553+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
44554+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
44555+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44556+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44557+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44558+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44559+4 4 4 4 4 4
44560+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
44561+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
44562+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
44563+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
44564+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
44565+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
44566+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
44567+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
44568+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44569+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44570+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44571+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44572+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44573+4 4 4 4 4 4
44574+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
44575+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
44576+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
44577+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
44578+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
44579+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
44580+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
44581+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
44582+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44583+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44584+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44585+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44586+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44587+4 4 4 4 4 4
44588+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
44589+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
44590+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
44591+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
44592+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
44593+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
44594+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
44595+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
44596+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44597+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44598+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44599+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44600+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44601+4 4 4 4 4 4
44602+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
44603+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
44604+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
44605+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
44606+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
44607+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
44608+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
44609+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
44610+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44611+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44612+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44613+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44614+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44615+4 4 4 4 4 4
44616+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44617+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
44618+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
44619+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
44620+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
44621+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
44622+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
44623+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
44624+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44625+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44626+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44627+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44628+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44629+4 4 4 4 4 4
44630+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44631+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
44632+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
44633+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
44634+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
44635+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
44636+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
44637+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
44638+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44639+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44640+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44641+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44642+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44643+4 4 4 4 4 4
44644+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44645+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44646+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
44647+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
44648+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
44649+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
44650+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
44651+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
44652+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44653+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44654+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44655+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44656+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44657+4 4 4 4 4 4
44658+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44660+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
44661+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
44662+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
44663+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
44664+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
44665+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44666+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44668+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44669+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44670+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44671+4 4 4 4 4 4
44672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44675+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
44676+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
44677+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
44678+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
44679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44683+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44684+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44685+4 4 4 4 4 4
44686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44689+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
44690+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
44691+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
44692+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
44693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44699+4 4 4 4 4 4
44700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44703+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
44704+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
44705+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
44706+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
44707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44713+4 4 4 4 4 4
44714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44716+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
44718+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
44719+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
44720+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44727+4 4 4 4 4 4
44728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44730+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44732+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
44733+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
44734+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
44735+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44741+4 4 4 4 4 4
44742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44744+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44746+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
44747+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
44748+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44755+4 4 4 4 4 4
44756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44758+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44760+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
44761+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
44762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44766+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44769+4 4 4 4 4 4
44770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44772+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44774+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
44775+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
44776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44783+4 4 4 4 4 4
44784diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
44785index 86d449e..af6a7f7 100644
44786--- a/drivers/video/udlfb.c
44787+++ b/drivers/video/udlfb.c
44788@@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
44789 dlfb_urb_completion(urb);
44790
44791 error:
44792- atomic_add(bytes_sent, &dev->bytes_sent);
44793- atomic_add(bytes_identical, &dev->bytes_identical);
44794- atomic_add(width*height*2, &dev->bytes_rendered);
44795+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
44796+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
44797+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
44798 end_cycles = get_cycles();
44799- atomic_add(((unsigned int) ((end_cycles - start_cycles)
44800+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
44801 >> 10)), /* Kcycles */
44802 &dev->cpu_kcycles_used);
44803
44804@@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
44805 dlfb_urb_completion(urb);
44806
44807 error:
44808- atomic_add(bytes_sent, &dev->bytes_sent);
44809- atomic_add(bytes_identical, &dev->bytes_identical);
44810- atomic_add(bytes_rendered, &dev->bytes_rendered);
44811+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
44812+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
44813+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
44814 end_cycles = get_cycles();
44815- atomic_add(((unsigned int) ((end_cycles - start_cycles)
44816+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
44817 >> 10)), /* Kcycles */
44818 &dev->cpu_kcycles_used);
44819 }
44820@@ -1372,7 +1372,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
44821 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44822 struct dlfb_data *dev = fb_info->par;
44823 return snprintf(buf, PAGE_SIZE, "%u\n",
44824- atomic_read(&dev->bytes_rendered));
44825+ atomic_read_unchecked(&dev->bytes_rendered));
44826 }
44827
44828 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
44829@@ -1380,7 +1380,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
44830 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44831 struct dlfb_data *dev = fb_info->par;
44832 return snprintf(buf, PAGE_SIZE, "%u\n",
44833- atomic_read(&dev->bytes_identical));
44834+ atomic_read_unchecked(&dev->bytes_identical));
44835 }
44836
44837 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
44838@@ -1388,7 +1388,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
44839 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44840 struct dlfb_data *dev = fb_info->par;
44841 return snprintf(buf, PAGE_SIZE, "%u\n",
44842- atomic_read(&dev->bytes_sent));
44843+ atomic_read_unchecked(&dev->bytes_sent));
44844 }
44845
44846 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
44847@@ -1396,7 +1396,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
44848 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44849 struct dlfb_data *dev = fb_info->par;
44850 return snprintf(buf, PAGE_SIZE, "%u\n",
44851- atomic_read(&dev->cpu_kcycles_used));
44852+ atomic_read_unchecked(&dev->cpu_kcycles_used));
44853 }
44854
44855 static ssize_t edid_show(
44856@@ -1456,10 +1456,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
44857 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44858 struct dlfb_data *dev = fb_info->par;
44859
44860- atomic_set(&dev->bytes_rendered, 0);
44861- atomic_set(&dev->bytes_identical, 0);
44862- atomic_set(&dev->bytes_sent, 0);
44863- atomic_set(&dev->cpu_kcycles_used, 0);
44864+ atomic_set_unchecked(&dev->bytes_rendered, 0);
44865+ atomic_set_unchecked(&dev->bytes_identical, 0);
44866+ atomic_set_unchecked(&dev->bytes_sent, 0);
44867+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
44868
44869 return count;
44870 }
44871diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
44872index b75db01..5631c6d 100644
44873--- a/drivers/video/uvesafb.c
44874+++ b/drivers/video/uvesafb.c
44875@@ -19,6 +19,7 @@
44876 #include <linux/io.h>
44877 #include <linux/mutex.h>
44878 #include <linux/slab.h>
44879+#include <linux/moduleloader.h>
44880 #include <video/edid.h>
44881 #include <video/uvesafb.h>
44882 #ifdef CONFIG_X86
44883@@ -569,10 +570,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
44884 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
44885 par->pmi_setpal = par->ypan = 0;
44886 } else {
44887+
44888+#ifdef CONFIG_PAX_KERNEXEC
44889+#ifdef CONFIG_MODULES
44890+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
44891+#endif
44892+ if (!par->pmi_code) {
44893+ par->pmi_setpal = par->ypan = 0;
44894+ return 0;
44895+ }
44896+#endif
44897+
44898 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
44899 + task->t.regs.edi);
44900+
44901+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44902+ pax_open_kernel();
44903+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
44904+ pax_close_kernel();
44905+
44906+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
44907+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
44908+#else
44909 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
44910 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
44911+#endif
44912+
44913 printk(KERN_INFO "uvesafb: protected mode interface info at "
44914 "%04x:%04x\n",
44915 (u16)task->t.regs.es, (u16)task->t.regs.edi);
44916@@ -817,13 +840,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
44917 par->ypan = ypan;
44918
44919 if (par->pmi_setpal || par->ypan) {
44920+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
44921 if (__supported_pte_mask & _PAGE_NX) {
44922 par->pmi_setpal = par->ypan = 0;
44923 printk(KERN_WARNING "uvesafb: NX protection is actively."
44924 "We have better not to use the PMI.\n");
44925- } else {
44926+ } else
44927+#endif
44928 uvesafb_vbe_getpmi(task, par);
44929- }
44930 }
44931 #else
44932 /* The protected mode interface is not available on non-x86. */
44933@@ -1836,6 +1860,11 @@ out:
44934 if (par->vbe_modes)
44935 kfree(par->vbe_modes);
44936
44937+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44938+ if (par->pmi_code)
44939+ module_free_exec(NULL, par->pmi_code);
44940+#endif
44941+
44942 framebuffer_release(info);
44943 return err;
44944 }
44945@@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
44946 kfree(par->vbe_state_orig);
44947 if (par->vbe_state_saved)
44948 kfree(par->vbe_state_saved);
44949+
44950+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44951+ if (par->pmi_code)
44952+ module_free_exec(NULL, par->pmi_code);
44953+#endif
44954+
44955 }
44956
44957 framebuffer_release(info);
44958diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
44959index 501b340..86bd4cf 100644
44960--- a/drivers/video/vesafb.c
44961+++ b/drivers/video/vesafb.c
44962@@ -9,6 +9,7 @@
44963 */
44964
44965 #include <linux/module.h>
44966+#include <linux/moduleloader.h>
44967 #include <linux/kernel.h>
44968 #include <linux/errno.h>
44969 #include <linux/string.h>
44970@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
44971 static int vram_total __initdata; /* Set total amount of memory */
44972 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
44973 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
44974-static void (*pmi_start)(void) __read_mostly;
44975-static void (*pmi_pal) (void) __read_mostly;
44976+static void (*pmi_start)(void) __read_only;
44977+static void (*pmi_pal) (void) __read_only;
44978 static int depth __read_mostly;
44979 static int vga_compat __read_mostly;
44980 /* --------------------------------------------------------------------- */
44981@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
44982 unsigned int size_vmode;
44983 unsigned int size_remap;
44984 unsigned int size_total;
44985+ void *pmi_code = NULL;
44986
44987 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
44988 return -ENODEV;
44989@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
44990 size_remap = size_total;
44991 vesafb_fix.smem_len = size_remap;
44992
44993-#ifndef __i386__
44994- screen_info.vesapm_seg = 0;
44995-#endif
44996-
44997 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
44998 printk(KERN_WARNING
44999 "vesafb: cannot reserve video memory at 0x%lx\n",
45000@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
45001 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
45002 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
45003
45004+#ifdef __i386__
45005+
45006+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45007+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
45008+ if (!pmi_code)
45009+#elif !defined(CONFIG_PAX_KERNEXEC)
45010+ if (0)
45011+#endif
45012+
45013+#endif
45014+ screen_info.vesapm_seg = 0;
45015+
45016 if (screen_info.vesapm_seg) {
45017- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
45018- screen_info.vesapm_seg,screen_info.vesapm_off);
45019+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
45020+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
45021 }
45022
45023 if (screen_info.vesapm_seg < 0xc000)
45024@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
45025
45026 if (ypan || pmi_setpal) {
45027 unsigned short *pmi_base;
45028+
45029 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
45030- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
45031- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
45032+
45033+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45034+ pax_open_kernel();
45035+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
45036+#else
45037+ pmi_code = pmi_base;
45038+#endif
45039+
45040+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
45041+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
45042+
45043+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45044+ pmi_start = ktva_ktla(pmi_start);
45045+ pmi_pal = ktva_ktla(pmi_pal);
45046+ pax_close_kernel();
45047+#endif
45048+
45049 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
45050 if (pmi_base[3]) {
45051 printk(KERN_INFO "vesafb: pmi: ports = ");
45052@@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
45053 info->node, info->fix.id);
45054 return 0;
45055 err:
45056+
45057+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45058+ module_free_exec(NULL, pmi_code);
45059+#endif
45060+
45061 if (info->screen_base)
45062 iounmap(info->screen_base);
45063 framebuffer_release(info);
45064diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
45065index 88714ae..16c2e11 100644
45066--- a/drivers/video/via/via_clock.h
45067+++ b/drivers/video/via/via_clock.h
45068@@ -56,7 +56,7 @@ struct via_clock {
45069
45070 void (*set_engine_pll_state)(u8 state);
45071 void (*set_engine_pll)(struct via_pll_config config);
45072-};
45073+} __no_const;
45074
45075
45076 static inline u32 get_pll_internal_frequency(u32 ref_freq,
45077diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
45078index fef20db..d28b1ab 100644
45079--- a/drivers/xen/xenfs/xenstored.c
45080+++ b/drivers/xen/xenfs/xenstored.c
45081@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
45082 static int xsd_kva_open(struct inode *inode, struct file *file)
45083 {
45084 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
45085+#ifdef CONFIG_GRKERNSEC_HIDESYM
45086+ NULL);
45087+#else
45088 xen_store_interface);
45089+#endif
45090+
45091 if (!file->private_data)
45092 return -ENOMEM;
45093 return 0;
45094diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
45095index 890bed5..17ae73e 100644
45096--- a/fs/9p/vfs_inode.c
45097+++ b/fs/9p/vfs_inode.c
45098@@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
45099 void
45100 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
45101 {
45102- char *s = nd_get_link(nd);
45103+ const char *s = nd_get_link(nd);
45104
45105 p9_debug(P9_DEBUG_VFS, " %s %s\n",
45106 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
45107diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
45108index 0efd152..b5802ad 100644
45109--- a/fs/Kconfig.binfmt
45110+++ b/fs/Kconfig.binfmt
45111@@ -89,7 +89,7 @@ config HAVE_AOUT
45112
45113 config BINFMT_AOUT
45114 tristate "Kernel support for a.out and ECOFF binaries"
45115- depends on HAVE_AOUT
45116+ depends on HAVE_AOUT && BROKEN
45117 ---help---
45118 A.out (Assembler.OUTput) is a set of formats for libraries and
45119 executables used in the earliest versions of UNIX. Linux used
45120diff --git a/fs/aio.c b/fs/aio.c
45121index 71f613c..9d01f1f 100644
45122--- a/fs/aio.c
45123+++ b/fs/aio.c
45124@@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
45125 size += sizeof(struct io_event) * nr_events;
45126 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
45127
45128- if (nr_pages < 0)
45129+ if (nr_pages <= 0)
45130 return -EINVAL;
45131
45132 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
45133@@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
45134 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
45135 {
45136 ssize_t ret;
45137+ struct iovec iovstack;
45138
45139 #ifdef CONFIG_COMPAT
45140 if (compat)
45141 ret = compat_rw_copy_check_uvector(type,
45142 (struct compat_iovec __user *)kiocb->ki_buf,
45143- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
45144+ kiocb->ki_nbytes, 1, &iovstack,
45145 &kiocb->ki_iovec);
45146 else
45147 #endif
45148 ret = rw_copy_check_uvector(type,
45149 (struct iovec __user *)kiocb->ki_buf,
45150- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
45151+ kiocb->ki_nbytes, 1, &iovstack,
45152 &kiocb->ki_iovec);
45153 if (ret < 0)
45154 goto out;
45155@@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
45156 if (ret < 0)
45157 goto out;
45158
45159+ if (kiocb->ki_iovec == &iovstack) {
45160+ kiocb->ki_inline_vec = iovstack;
45161+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
45162+ }
45163 kiocb->ki_nr_segs = kiocb->ki_nbytes;
45164 kiocb->ki_cur_seg = 0;
45165 /* ki_nbytes/left now reflect bytes instead of segs */
45166diff --git a/fs/attr.c b/fs/attr.c
45167index 1449adb..a2038c2 100644
45168--- a/fs/attr.c
45169+++ b/fs/attr.c
45170@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
45171 unsigned long limit;
45172
45173 limit = rlimit(RLIMIT_FSIZE);
45174+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
45175 if (limit != RLIM_INFINITY && offset > limit)
45176 goto out_sig;
45177 if (offset > inode->i_sb->s_maxbytes)
45178diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
45179index 03bc1d3..6205356 100644
45180--- a/fs/autofs4/waitq.c
45181+++ b/fs/autofs4/waitq.c
45182@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
45183 {
45184 unsigned long sigpipe, flags;
45185 mm_segment_t fs;
45186- const char *data = (const char *)addr;
45187+ const char __user *data = (const char __force_user *)addr;
45188 ssize_t wr = 0;
45189
45190 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
45191@@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
45192 return 1;
45193 }
45194
45195+#ifdef CONFIG_GRKERNSEC_HIDESYM
45196+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
45197+#endif
45198+
45199 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
45200 enum autofs_notify notify)
45201 {
45202@@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
45203
45204 /* If this is a direct mount request create a dummy name */
45205 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
45206+#ifdef CONFIG_GRKERNSEC_HIDESYM
45207+ /* this name does get written to userland via autofs4_write() */
45208+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
45209+#else
45210 qstr.len = sprintf(name, "%p", dentry);
45211+#endif
45212 else {
45213 qstr.len = autofs4_getpath(sbi, dentry, &name);
45214 if (!qstr.len) {
45215diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
45216index 2b3bda8..6a2d4be 100644
45217--- a/fs/befs/linuxvfs.c
45218+++ b/fs/befs/linuxvfs.c
45219@@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
45220 {
45221 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
45222 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
45223- char *link = nd_get_link(nd);
45224+ const char *link = nd_get_link(nd);
45225 if (!IS_ERR(link))
45226 kfree(link);
45227 }
45228diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
45229index 6043567..16a9239 100644
45230--- a/fs/binfmt_aout.c
45231+++ b/fs/binfmt_aout.c
45232@@ -16,6 +16,7 @@
45233 #include <linux/string.h>
45234 #include <linux/fs.h>
45235 #include <linux/file.h>
45236+#include <linux/security.h>
45237 #include <linux/stat.h>
45238 #include <linux/fcntl.h>
45239 #include <linux/ptrace.h>
45240@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
45241 #endif
45242 # define START_STACK(u) ((void __user *)u.start_stack)
45243
45244+ memset(&dump, 0, sizeof(dump));
45245+
45246 fs = get_fs();
45247 set_fs(KERNEL_DS);
45248 has_dumped = 1;
45249@@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
45250
45251 /* If the size of the dump file exceeds the rlimit, then see what would happen
45252 if we wrote the stack, but not the data area. */
45253+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
45254 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
45255 dump.u_dsize = 0;
45256
45257 /* Make sure we have enough room to write the stack and data areas. */
45258+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
45259 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
45260 dump.u_ssize = 0;
45261
45262@@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
45263 rlim = rlimit(RLIMIT_DATA);
45264 if (rlim >= RLIM_INFINITY)
45265 rlim = ~0;
45266+
45267+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
45268 if (ex.a_data + ex.a_bss > rlim)
45269 return -ENOMEM;
45270
45271@@ -268,6 +275,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
45272
45273 install_exec_creds(bprm);
45274
45275+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45276+ current->mm->pax_flags = 0UL;
45277+#endif
45278+
45279+#ifdef CONFIG_PAX_PAGEEXEC
45280+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
45281+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
45282+
45283+#ifdef CONFIG_PAX_EMUTRAMP
45284+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
45285+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
45286+#endif
45287+
45288+#ifdef CONFIG_PAX_MPROTECT
45289+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
45290+ current->mm->pax_flags |= MF_PAX_MPROTECT;
45291+#endif
45292+
45293+ }
45294+#endif
45295+
45296 if (N_MAGIC(ex) == OMAGIC) {
45297 unsigned long text_addr, map_size;
45298 loff_t pos;
45299@@ -333,7 +361,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
45300 }
45301
45302 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
45303- PROT_READ | PROT_WRITE | PROT_EXEC,
45304+ PROT_READ | PROT_WRITE,
45305 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
45306 fd_offset + ex.a_text);
45307 if (error != N_DATADDR(ex)) {
45308diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
45309index 0c42cdb..f4be023 100644
45310--- a/fs/binfmt_elf.c
45311+++ b/fs/binfmt_elf.c
45312@@ -33,6 +33,7 @@
45313 #include <linux/elf.h>
45314 #include <linux/utsname.h>
45315 #include <linux/coredump.h>
45316+#include <linux/xattr.h>
45317 #include <asm/uaccess.h>
45318 #include <asm/param.h>
45319 #include <asm/page.h>
45320@@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
45321 #define elf_core_dump NULL
45322 #endif
45323
45324+#ifdef CONFIG_PAX_MPROTECT
45325+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
45326+#endif
45327+
45328 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
45329 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
45330 #else
45331@@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
45332 .load_binary = load_elf_binary,
45333 .load_shlib = load_elf_library,
45334 .core_dump = elf_core_dump,
45335+
45336+#ifdef CONFIG_PAX_MPROTECT
45337+ .handle_mprotect= elf_handle_mprotect,
45338+#endif
45339+
45340 .min_coredump = ELF_EXEC_PAGESIZE,
45341 };
45342
45343@@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
45344
45345 static int set_brk(unsigned long start, unsigned long end)
45346 {
45347+ unsigned long e = end;
45348+
45349 start = ELF_PAGEALIGN(start);
45350 end = ELF_PAGEALIGN(end);
45351 if (end > start) {
45352@@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
45353 if (BAD_ADDR(addr))
45354 return addr;
45355 }
45356- current->mm->start_brk = current->mm->brk = end;
45357+ current->mm->start_brk = current->mm->brk = e;
45358 return 0;
45359 }
45360
45361@@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
45362 elf_addr_t __user *u_rand_bytes;
45363 const char *k_platform = ELF_PLATFORM;
45364 const char *k_base_platform = ELF_BASE_PLATFORM;
45365- unsigned char k_rand_bytes[16];
45366+ u32 k_rand_bytes[4];
45367 int items;
45368 elf_addr_t *elf_info;
45369 int ei_index = 0;
45370 const struct cred *cred = current_cred();
45371 struct vm_area_struct *vma;
45372+ unsigned long saved_auxv[AT_VECTOR_SIZE];
45373
45374 /*
45375 * In some cases (e.g. Hyper-Threading), we want to avoid L1
45376@@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
45377 * Generate 16 random bytes for userspace PRNG seeding.
45378 */
45379 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
45380- u_rand_bytes = (elf_addr_t __user *)
45381- STACK_ALLOC(p, sizeof(k_rand_bytes));
45382+ srandom32(k_rand_bytes[0] ^ random32());
45383+ srandom32(k_rand_bytes[1] ^ random32());
45384+ srandom32(k_rand_bytes[2] ^ random32());
45385+ srandom32(k_rand_bytes[3] ^ random32());
45386+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
45387+ u_rand_bytes = (elf_addr_t __user *) p;
45388 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
45389 return -EFAULT;
45390
45391@@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
45392 return -EFAULT;
45393 current->mm->env_end = p;
45394
45395+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
45396+
45397 /* Put the elf_info on the stack in the right place. */
45398 sp = (elf_addr_t __user *)envp + 1;
45399- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
45400+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
45401 return -EFAULT;
45402 return 0;
45403 }
45404@@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
45405 an ELF header */
45406
45407 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
45408- struct file *interpreter, unsigned long *interp_map_addr,
45409- unsigned long no_base)
45410+ struct file *interpreter, unsigned long no_base)
45411 {
45412 struct elf_phdr *elf_phdata;
45413 struct elf_phdr *eppnt;
45414- unsigned long load_addr = 0;
45415+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
45416 int load_addr_set = 0;
45417 unsigned long last_bss = 0, elf_bss = 0;
45418- unsigned long error = ~0UL;
45419+ unsigned long error = -EINVAL;
45420 unsigned long total_size;
45421 int retval, i, size;
45422
45423@@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
45424 goto out_close;
45425 }
45426
45427+#ifdef CONFIG_PAX_SEGMEXEC
45428+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
45429+ pax_task_size = SEGMEXEC_TASK_SIZE;
45430+#endif
45431+
45432 eppnt = elf_phdata;
45433 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
45434 if (eppnt->p_type == PT_LOAD) {
45435@@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
45436 map_addr = elf_map(interpreter, load_addr + vaddr,
45437 eppnt, elf_prot, elf_type, total_size);
45438 total_size = 0;
45439- if (!*interp_map_addr)
45440- *interp_map_addr = map_addr;
45441 error = map_addr;
45442 if (BAD_ADDR(map_addr))
45443 goto out_close;
45444@@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
45445 k = load_addr + eppnt->p_vaddr;
45446 if (BAD_ADDR(k) ||
45447 eppnt->p_filesz > eppnt->p_memsz ||
45448- eppnt->p_memsz > TASK_SIZE ||
45449- TASK_SIZE - eppnt->p_memsz < k) {
45450+ eppnt->p_memsz > pax_task_size ||
45451+ pax_task_size - eppnt->p_memsz < k) {
45452 error = -ENOMEM;
45453 goto out_close;
45454 }
45455@@ -530,6 +551,315 @@ out:
45456 return error;
45457 }
45458
45459+#ifdef CONFIG_PAX_PT_PAX_FLAGS
45460+#ifdef CONFIG_PAX_SOFTMODE
45461+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
45462+{
45463+ unsigned long pax_flags = 0UL;
45464+
45465+#ifdef CONFIG_PAX_PAGEEXEC
45466+ if (elf_phdata->p_flags & PF_PAGEEXEC)
45467+ pax_flags |= MF_PAX_PAGEEXEC;
45468+#endif
45469+
45470+#ifdef CONFIG_PAX_SEGMEXEC
45471+ if (elf_phdata->p_flags & PF_SEGMEXEC)
45472+ pax_flags |= MF_PAX_SEGMEXEC;
45473+#endif
45474+
45475+#ifdef CONFIG_PAX_EMUTRAMP
45476+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
45477+ pax_flags |= MF_PAX_EMUTRAMP;
45478+#endif
45479+
45480+#ifdef CONFIG_PAX_MPROTECT
45481+ if (elf_phdata->p_flags & PF_MPROTECT)
45482+ pax_flags |= MF_PAX_MPROTECT;
45483+#endif
45484+
45485+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
45486+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
45487+ pax_flags |= MF_PAX_RANDMMAP;
45488+#endif
45489+
45490+ return pax_flags;
45491+}
45492+#endif
45493+
45494+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
45495+{
45496+ unsigned long pax_flags = 0UL;
45497+
45498+#ifdef CONFIG_PAX_PAGEEXEC
45499+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
45500+ pax_flags |= MF_PAX_PAGEEXEC;
45501+#endif
45502+
45503+#ifdef CONFIG_PAX_SEGMEXEC
45504+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
45505+ pax_flags |= MF_PAX_SEGMEXEC;
45506+#endif
45507+
45508+#ifdef CONFIG_PAX_EMUTRAMP
45509+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
45510+ pax_flags |= MF_PAX_EMUTRAMP;
45511+#endif
45512+
45513+#ifdef CONFIG_PAX_MPROTECT
45514+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
45515+ pax_flags |= MF_PAX_MPROTECT;
45516+#endif
45517+
45518+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
45519+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
45520+ pax_flags |= MF_PAX_RANDMMAP;
45521+#endif
45522+
45523+ return pax_flags;
45524+}
45525+#endif
45526+
45527+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
45528+#ifdef CONFIG_PAX_SOFTMODE
45529+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
45530+{
45531+ unsigned long pax_flags = 0UL;
45532+
45533+#ifdef CONFIG_PAX_PAGEEXEC
45534+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
45535+ pax_flags |= MF_PAX_PAGEEXEC;
45536+#endif
45537+
45538+#ifdef CONFIG_PAX_SEGMEXEC
45539+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
45540+ pax_flags |= MF_PAX_SEGMEXEC;
45541+#endif
45542+
45543+#ifdef CONFIG_PAX_EMUTRAMP
45544+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
45545+ pax_flags |= MF_PAX_EMUTRAMP;
45546+#endif
45547+
45548+#ifdef CONFIG_PAX_MPROTECT
45549+ if (pax_flags_softmode & MF_PAX_MPROTECT)
45550+ pax_flags |= MF_PAX_MPROTECT;
45551+#endif
45552+
45553+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
45554+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
45555+ pax_flags |= MF_PAX_RANDMMAP;
45556+#endif
45557+
45558+ return pax_flags;
45559+}
45560+#endif
45561+
45562+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
45563+{
45564+ unsigned long pax_flags = 0UL;
45565+
45566+#ifdef CONFIG_PAX_PAGEEXEC
45567+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
45568+ pax_flags |= MF_PAX_PAGEEXEC;
45569+#endif
45570+
45571+#ifdef CONFIG_PAX_SEGMEXEC
45572+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
45573+ pax_flags |= MF_PAX_SEGMEXEC;
45574+#endif
45575+
45576+#ifdef CONFIG_PAX_EMUTRAMP
45577+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
45578+ pax_flags |= MF_PAX_EMUTRAMP;
45579+#endif
45580+
45581+#ifdef CONFIG_PAX_MPROTECT
45582+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
45583+ pax_flags |= MF_PAX_MPROTECT;
45584+#endif
45585+
45586+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
45587+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
45588+ pax_flags |= MF_PAX_RANDMMAP;
45589+#endif
45590+
45591+ return pax_flags;
45592+}
45593+#endif
45594+
45595+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45596+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
45597+{
45598+ unsigned long pax_flags = 0UL;
45599+
45600+#ifdef CONFIG_PAX_EI_PAX
45601+
45602+#ifdef CONFIG_PAX_PAGEEXEC
45603+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
45604+ pax_flags |= MF_PAX_PAGEEXEC;
45605+#endif
45606+
45607+#ifdef CONFIG_PAX_SEGMEXEC
45608+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
45609+ pax_flags |= MF_PAX_SEGMEXEC;
45610+#endif
45611+
45612+#ifdef CONFIG_PAX_EMUTRAMP
45613+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
45614+ pax_flags |= MF_PAX_EMUTRAMP;
45615+#endif
45616+
45617+#ifdef CONFIG_PAX_MPROTECT
45618+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
45619+ pax_flags |= MF_PAX_MPROTECT;
45620+#endif
45621+
45622+#ifdef CONFIG_PAX_ASLR
45623+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
45624+ pax_flags |= MF_PAX_RANDMMAP;
45625+#endif
45626+
45627+#else
45628+
45629+#ifdef CONFIG_PAX_PAGEEXEC
45630+ pax_flags |= MF_PAX_PAGEEXEC;
45631+#endif
45632+
45633+#ifdef CONFIG_PAX_SEGMEXEC
45634+ pax_flags |= MF_PAX_SEGMEXEC;
45635+#endif
45636+
45637+#ifdef CONFIG_PAX_MPROTECT
45638+ pax_flags |= MF_PAX_MPROTECT;
45639+#endif
45640+
45641+#ifdef CONFIG_PAX_RANDMMAP
45642+ if (randomize_va_space)
45643+ pax_flags |= MF_PAX_RANDMMAP;
45644+#endif
45645+
45646+#endif
45647+
45648+ return pax_flags;
45649+}
45650+
45651+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
45652+{
45653+
45654+#ifdef CONFIG_PAX_PT_PAX_FLAGS
45655+ unsigned long i;
45656+
45657+ for (i = 0UL; i < elf_ex->e_phnum; i++)
45658+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
45659+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
45660+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
45661+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
45662+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
45663+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
45664+ return ~0UL;
45665+
45666+#ifdef CONFIG_PAX_SOFTMODE
45667+ if (pax_softmode)
45668+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
45669+ else
45670+#endif
45671+
45672+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
45673+ break;
45674+ }
45675+#endif
45676+
45677+ return ~0UL;
45678+}
45679+
45680+static unsigned long pax_parse_xattr_pax(struct file * const file)
45681+{
45682+
45683+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
45684+ ssize_t xattr_size, i;
45685+ unsigned char xattr_value[5];
45686+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
45687+
45688+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
45689+ if (xattr_size <= 0 || xattr_size > 5)
45690+ return ~0UL;
45691+
45692+ for (i = 0; i < xattr_size; i++)
45693+ switch (xattr_value[i]) {
45694+ default:
45695+ return ~0UL;
45696+
45697+#define parse_flag(option1, option2, flag) \
45698+ case option1: \
45699+ if (pax_flags_hardmode & MF_PAX_##flag) \
45700+ return ~0UL; \
45701+ pax_flags_hardmode |= MF_PAX_##flag; \
45702+ break; \
45703+ case option2: \
45704+ if (pax_flags_softmode & MF_PAX_##flag) \
45705+ return ~0UL; \
45706+ pax_flags_softmode |= MF_PAX_##flag; \
45707+ break;
45708+
45709+ parse_flag('p', 'P', PAGEEXEC);
45710+ parse_flag('e', 'E', EMUTRAMP);
45711+ parse_flag('m', 'M', MPROTECT);
45712+ parse_flag('r', 'R', RANDMMAP);
45713+ parse_flag('s', 'S', SEGMEXEC);
45714+
45715+#undef parse_flag
45716+ }
45717+
45718+ if (pax_flags_hardmode & pax_flags_softmode)
45719+ return ~0UL;
45720+
45721+#ifdef CONFIG_PAX_SOFTMODE
45722+ if (pax_softmode)
45723+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
45724+ else
45725+#endif
45726+
45727+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
45728+#else
45729+ return ~0UL;
45730+#endif
45731+
45732+}
45733+
45734+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
45735+{
45736+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
45737+
45738+ pax_flags = pax_parse_ei_pax(elf_ex);
45739+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
45740+ xattr_pax_flags = pax_parse_xattr_pax(file);
45741+
45742+ if (pt_pax_flags == ~0UL)
45743+ pt_pax_flags = xattr_pax_flags;
45744+ else if (xattr_pax_flags == ~0UL)
45745+ xattr_pax_flags = pt_pax_flags;
45746+ if (pt_pax_flags != xattr_pax_flags)
45747+ return -EINVAL;
45748+ if (pt_pax_flags != ~0UL)
45749+ pax_flags = pt_pax_flags;
45750+
45751+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
45752+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45753+ if ((__supported_pte_mask & _PAGE_NX))
45754+ pax_flags &= ~MF_PAX_SEGMEXEC;
45755+ else
45756+ pax_flags &= ~MF_PAX_PAGEEXEC;
45757+ }
45758+#endif
45759+
45760+ if (0 > pax_check_flags(&pax_flags))
45761+ return -EINVAL;
45762+
45763+ current->mm->pax_flags = pax_flags;
45764+ return 0;
45765+}
45766+#endif
45767+
45768 /*
45769 * These are the functions used to load ELF style executables and shared
45770 * libraries. There is no binary dependent code anywhere else.
45771@@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
45772 {
45773 unsigned int random_variable = 0;
45774
45775+#ifdef CONFIG_PAX_RANDUSTACK
45776+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
45777+ return stack_top - current->mm->delta_stack;
45778+#endif
45779+
45780 if ((current->flags & PF_RANDOMIZE) &&
45781 !(current->personality & ADDR_NO_RANDOMIZE)) {
45782 random_variable = get_random_int() & STACK_RND_MASK;
45783@@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
45784 unsigned long load_addr = 0, load_bias = 0;
45785 int load_addr_set = 0;
45786 char * elf_interpreter = NULL;
45787- unsigned long error;
45788+ unsigned long error = 0;
45789 struct elf_phdr *elf_ppnt, *elf_phdata;
45790 unsigned long elf_bss, elf_brk;
45791 int retval, i;
45792@@ -574,12 +909,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
45793 unsigned long start_code, end_code, start_data, end_data;
45794 unsigned long reloc_func_desc __maybe_unused = 0;
45795 int executable_stack = EXSTACK_DEFAULT;
45796- unsigned long def_flags = 0;
45797 struct pt_regs *regs = current_pt_regs();
45798 struct {
45799 struct elfhdr elf_ex;
45800 struct elfhdr interp_elf_ex;
45801 } *loc;
45802+ unsigned long pax_task_size = TASK_SIZE;
45803
45804 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
45805 if (!loc) {
45806@@ -715,11 +1050,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
45807 goto out_free_dentry;
45808
45809 /* OK, This is the point of no return */
45810- current->mm->def_flags = def_flags;
45811+
45812+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45813+ current->mm->pax_flags = 0UL;
45814+#endif
45815+
45816+#ifdef CONFIG_PAX_DLRESOLVE
45817+ current->mm->call_dl_resolve = 0UL;
45818+#endif
45819+
45820+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
45821+ current->mm->call_syscall = 0UL;
45822+#endif
45823+
45824+#ifdef CONFIG_PAX_ASLR
45825+ current->mm->delta_mmap = 0UL;
45826+ current->mm->delta_stack = 0UL;
45827+#endif
45828+
45829+ current->mm->def_flags = 0;
45830+
45831+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45832+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
45833+ send_sig(SIGKILL, current, 0);
45834+ goto out_free_dentry;
45835+ }
45836+#endif
45837+
45838+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
45839+ pax_set_initial_flags(bprm);
45840+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
45841+ if (pax_set_initial_flags_func)
45842+ (pax_set_initial_flags_func)(bprm);
45843+#endif
45844+
45845+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
45846+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
45847+ current->mm->context.user_cs_limit = PAGE_SIZE;
45848+ current->mm->def_flags |= VM_PAGEEXEC;
45849+ }
45850+#endif
45851+
45852+#ifdef CONFIG_PAX_SEGMEXEC
45853+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
45854+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
45855+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
45856+ pax_task_size = SEGMEXEC_TASK_SIZE;
45857+ current->mm->def_flags |= VM_NOHUGEPAGE;
45858+ }
45859+#endif
45860+
45861+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
45862+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45863+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
45864+ put_cpu();
45865+ }
45866+#endif
45867
45868 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
45869 may depend on the personality. */
45870 SET_PERSONALITY(loc->elf_ex);
45871+
45872+#ifdef CONFIG_PAX_ASLR
45873+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
45874+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
45875+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
45876+ }
45877+#endif
45878+
45879+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45880+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45881+ executable_stack = EXSTACK_DISABLE_X;
45882+ current->personality &= ~READ_IMPLIES_EXEC;
45883+ } else
45884+#endif
45885+
45886 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
45887 current->personality |= READ_IMPLIES_EXEC;
45888
45889@@ -810,6 +1215,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
45890 #else
45891 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
45892 #endif
45893+
45894+#ifdef CONFIG_PAX_RANDMMAP
45895+ /* PaX: randomize base address at the default exe base if requested */
45896+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
45897+#ifdef CONFIG_SPARC64
45898+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
45899+#else
45900+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
45901+#endif
45902+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
45903+ elf_flags |= MAP_FIXED;
45904+ }
45905+#endif
45906+
45907 }
45908
45909 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
45910@@ -842,9 +1261,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
45911 * allowed task size. Note that p_filesz must always be
45912 * <= p_memsz so it is only necessary to check p_memsz.
45913 */
45914- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
45915- elf_ppnt->p_memsz > TASK_SIZE ||
45916- TASK_SIZE - elf_ppnt->p_memsz < k) {
45917+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
45918+ elf_ppnt->p_memsz > pax_task_size ||
45919+ pax_task_size - elf_ppnt->p_memsz < k) {
45920 /* set_brk can never work. Avoid overflows. */
45921 send_sig(SIGKILL, current, 0);
45922 retval = -EINVAL;
45923@@ -883,17 +1302,44 @@ static int load_elf_binary(struct linux_binprm *bprm)
45924 goto out_free_dentry;
45925 }
45926 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
45927- send_sig(SIGSEGV, current, 0);
45928- retval = -EFAULT; /* Nobody gets to see this, but.. */
45929- goto out_free_dentry;
45930+ /*
45931+ * This bss-zeroing can fail if the ELF
45932+ * file specifies odd protections. So
45933+ * we don't check the return value
45934+ */
45935 }
45936
45937+#ifdef CONFIG_PAX_RANDMMAP
45938+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
45939+ unsigned long start, size;
45940+
45941+ start = ELF_PAGEALIGN(elf_brk);
45942+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
45943+ down_read(&current->mm->mmap_sem);
45944+ retval = -ENOMEM;
45945+ if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
45946+ unsigned long prot = PROT_NONE;
45947+
45948+ up_read(&current->mm->mmap_sem);
45949+ current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
45950+// if (current->personality & ADDR_NO_RANDOMIZE)
45951+// prot = PROT_READ;
45952+ start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
45953+ retval = IS_ERR_VALUE(start) ? start : 0;
45954+ } else
45955+ up_read(&current->mm->mmap_sem);
45956+ if (retval == 0)
45957+ retval = set_brk(start + size, start + size + PAGE_SIZE);
45958+ if (retval < 0) {
45959+ send_sig(SIGKILL, current, 0);
45960+ goto out_free_dentry;
45961+ }
45962+ }
45963+#endif
45964+
45965 if (elf_interpreter) {
45966- unsigned long interp_map_addr = 0;
45967-
45968 elf_entry = load_elf_interp(&loc->interp_elf_ex,
45969 interpreter,
45970- &interp_map_addr,
45971 load_bias);
45972 if (!IS_ERR((void *)elf_entry)) {
45973 /*
45974@@ -1115,7 +1561,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
45975 * Decide what to dump of a segment, part, all or none.
45976 */
45977 static unsigned long vma_dump_size(struct vm_area_struct *vma,
45978- unsigned long mm_flags)
45979+ unsigned long mm_flags, long signr)
45980 {
45981 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
45982
45983@@ -1152,7 +1598,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
45984 if (vma->vm_file == NULL)
45985 return 0;
45986
45987- if (FILTER(MAPPED_PRIVATE))
45988+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
45989 goto whole;
45990
45991 /*
45992@@ -1374,9 +1820,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
45993 {
45994 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
45995 int i = 0;
45996- do
45997+ do {
45998 i += 2;
45999- while (auxv[i - 2] != AT_NULL);
46000+ } while (auxv[i - 2] != AT_NULL);
46001 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
46002 }
46003
46004@@ -2006,14 +2452,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
46005 }
46006
46007 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
46008- unsigned long mm_flags)
46009+ struct coredump_params *cprm)
46010 {
46011 struct vm_area_struct *vma;
46012 size_t size = 0;
46013
46014 for (vma = first_vma(current, gate_vma); vma != NULL;
46015 vma = next_vma(vma, gate_vma))
46016- size += vma_dump_size(vma, mm_flags);
46017+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
46018 return size;
46019 }
46020
46021@@ -2107,7 +2553,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46022
46023 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
46024
46025- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
46026+ offset += elf_core_vma_data_size(gate_vma, cprm);
46027 offset += elf_core_extra_data_size();
46028 e_shoff = offset;
46029
46030@@ -2121,10 +2567,12 @@ static int elf_core_dump(struct coredump_params *cprm)
46031 offset = dataoff;
46032
46033 size += sizeof(*elf);
46034+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
46035 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
46036 goto end_coredump;
46037
46038 size += sizeof(*phdr4note);
46039+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
46040 if (size > cprm->limit
46041 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
46042 goto end_coredump;
46043@@ -2138,7 +2586,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46044 phdr.p_offset = offset;
46045 phdr.p_vaddr = vma->vm_start;
46046 phdr.p_paddr = 0;
46047- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
46048+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
46049 phdr.p_memsz = vma->vm_end - vma->vm_start;
46050 offset += phdr.p_filesz;
46051 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
46052@@ -2149,6 +2597,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46053 phdr.p_align = ELF_EXEC_PAGESIZE;
46054
46055 size += sizeof(phdr);
46056+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
46057 if (size > cprm->limit
46058 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
46059 goto end_coredump;
46060@@ -2173,7 +2622,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46061 unsigned long addr;
46062 unsigned long end;
46063
46064- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
46065+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
46066
46067 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
46068 struct page *page;
46069@@ -2182,6 +2631,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46070 page = get_dump_page(addr);
46071 if (page) {
46072 void *kaddr = kmap(page);
46073+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
46074 stop = ((size += PAGE_SIZE) > cprm->limit) ||
46075 !dump_write(cprm->file, kaddr,
46076 PAGE_SIZE);
46077@@ -2199,6 +2649,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46078
46079 if (e_phnum == PN_XNUM) {
46080 size += sizeof(*shdr4extnum);
46081+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
46082 if (size > cprm->limit
46083 || !dump_write(cprm->file, shdr4extnum,
46084 sizeof(*shdr4extnum)))
46085@@ -2219,6 +2670,97 @@ out:
46086
46087 #endif /* CONFIG_ELF_CORE */
46088
46089+#ifdef CONFIG_PAX_MPROTECT
46090+/* PaX: non-PIC ELF libraries need relocations on their executable segments
46091+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
46092+ * we'll remove VM_MAYWRITE for good on RELRO segments.
46093+ *
46094+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
46095+ * basis because we want to allow the common case and not the special ones.
46096+ */
46097+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
46098+{
46099+ struct elfhdr elf_h;
46100+ struct elf_phdr elf_p;
46101+ unsigned long i;
46102+ unsigned long oldflags;
46103+ bool is_textrel_rw, is_textrel_rx, is_relro;
46104+
46105+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
46106+ return;
46107+
46108+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
46109+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
46110+
46111+#ifdef CONFIG_PAX_ELFRELOCS
46112+ /* possible TEXTREL */
46113+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
46114+ 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);
46115+#else
46116+ is_textrel_rw = false;
46117+ is_textrel_rx = false;
46118+#endif
46119+
46120+ /* possible RELRO */
46121+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
46122+
46123+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
46124+ return;
46125+
46126+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
46127+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
46128+
46129+#ifdef CONFIG_PAX_ETEXECRELOCS
46130+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
46131+#else
46132+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
46133+#endif
46134+
46135+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
46136+ !elf_check_arch(&elf_h) ||
46137+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
46138+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
46139+ return;
46140+
46141+ for (i = 0UL; i < elf_h.e_phnum; i++) {
46142+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
46143+ return;
46144+ switch (elf_p.p_type) {
46145+ case PT_DYNAMIC:
46146+ if (!is_textrel_rw && !is_textrel_rx)
46147+ continue;
46148+ i = 0UL;
46149+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
46150+ elf_dyn dyn;
46151+
46152+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
46153+ return;
46154+ if (dyn.d_tag == DT_NULL)
46155+ return;
46156+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
46157+ gr_log_textrel(vma);
46158+ if (is_textrel_rw)
46159+ vma->vm_flags |= VM_MAYWRITE;
46160+ else
46161+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
46162+ vma->vm_flags &= ~VM_MAYWRITE;
46163+ return;
46164+ }
46165+ i++;
46166+ }
46167+ return;
46168+
46169+ case PT_GNU_RELRO:
46170+ if (!is_relro)
46171+ continue;
46172+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
46173+ vma->vm_flags &= ~VM_MAYWRITE;
46174+ return;
46175+ }
46176+ }
46177+}
46178+#endif
46179+
46180 static int __init init_elf_binfmt(void)
46181 {
46182 register_binfmt(&elf_format);
46183diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
46184index b563719..3868998 100644
46185--- a/fs/binfmt_flat.c
46186+++ b/fs/binfmt_flat.c
46187@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
46188 realdatastart = (unsigned long) -ENOMEM;
46189 printk("Unable to allocate RAM for process data, errno %d\n",
46190 (int)-realdatastart);
46191+ down_write(&current->mm->mmap_sem);
46192 vm_munmap(textpos, text_len);
46193+ up_write(&current->mm->mmap_sem);
46194 ret = realdatastart;
46195 goto err;
46196 }
46197@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
46198 }
46199 if (IS_ERR_VALUE(result)) {
46200 printk("Unable to read data+bss, errno %d\n", (int)-result);
46201+ down_write(&current->mm->mmap_sem);
46202 vm_munmap(textpos, text_len);
46203 vm_munmap(realdatastart, len);
46204+ up_write(&current->mm->mmap_sem);
46205 ret = result;
46206 goto err;
46207 }
46208@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
46209 }
46210 if (IS_ERR_VALUE(result)) {
46211 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
46212+ down_write(&current->mm->mmap_sem);
46213 vm_munmap(textpos, text_len + data_len + extra +
46214 MAX_SHARED_LIBS * sizeof(unsigned long));
46215+ up_write(&current->mm->mmap_sem);
46216 ret = result;
46217 goto err;
46218 }
46219diff --git a/fs/bio.c b/fs/bio.c
46220index b96fc6c..431d628 100644
46221--- a/fs/bio.c
46222+++ b/fs/bio.c
46223@@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
46224 /*
46225 * Overflow, abort
46226 */
46227- if (end < start)
46228+ if (end < start || end - start > INT_MAX - nr_pages)
46229 return ERR_PTR(-EINVAL);
46230
46231 nr_pages += end - start;
46232@@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
46233 /*
46234 * Overflow, abort
46235 */
46236- if (end < start)
46237+ if (end < start || end - start > INT_MAX - nr_pages)
46238 return ERR_PTR(-EINVAL);
46239
46240 nr_pages += end - start;
46241@@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
46242 const int read = bio_data_dir(bio) == READ;
46243 struct bio_map_data *bmd = bio->bi_private;
46244 int i;
46245- char *p = bmd->sgvecs[0].iov_base;
46246+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
46247
46248 __bio_for_each_segment(bvec, bio, i, 0) {
46249 char *addr = page_address(bvec->bv_page);
46250diff --git a/fs/block_dev.c b/fs/block_dev.c
46251index 172f849..6efbf24 100644
46252--- a/fs/block_dev.c
46253+++ b/fs/block_dev.c
46254@@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
46255 else if (bdev->bd_contains == bdev)
46256 return true; /* is a whole device which isn't held */
46257
46258- else if (whole->bd_holder == bd_may_claim)
46259+ else if (whole->bd_holder == (void *)bd_may_claim)
46260 return true; /* is a partition of a device that is being partitioned */
46261 else if (whole->bd_holder != NULL)
46262 return false; /* is a partition of a held device */
46263diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
46264index eea5da7..88fead70 100644
46265--- a/fs/btrfs/ctree.c
46266+++ b/fs/btrfs/ctree.c
46267@@ -1033,9 +1033,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
46268 free_extent_buffer(buf);
46269 add_root_to_dirty_list(root);
46270 } else {
46271- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
46272- parent_start = parent->start;
46273- else
46274+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
46275+ if (parent)
46276+ parent_start = parent->start;
46277+ else
46278+ parent_start = 0;
46279+ } else
46280 parent_start = 0;
46281
46282 WARN_ON(trans->transid != btrfs_header_generation(parent));
46283diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
46284index cc93b23..f3c42bf 100644
46285--- a/fs/btrfs/inode.c
46286+++ b/fs/btrfs/inode.c
46287@@ -7296,7 +7296,7 @@ fail:
46288 return -ENOMEM;
46289 }
46290
46291-static int btrfs_getattr(struct vfsmount *mnt,
46292+int btrfs_getattr(struct vfsmount *mnt,
46293 struct dentry *dentry, struct kstat *stat)
46294 {
46295 struct inode *inode = dentry->d_inode;
46296@@ -7310,6 +7310,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
46297 return 0;
46298 }
46299
46300+EXPORT_SYMBOL(btrfs_getattr);
46301+
46302+dev_t get_btrfs_dev_from_inode(struct inode *inode)
46303+{
46304+ return BTRFS_I(inode)->root->anon_dev;
46305+}
46306+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
46307+
46308 /*
46309 * If a file is moved, it will inherit the cow and compression flags of the new
46310 * directory.
46311diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
46312index 338f259..b657640 100644
46313--- a/fs/btrfs/ioctl.c
46314+++ b/fs/btrfs/ioctl.c
46315@@ -3033,9 +3033,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
46316 for (i = 0; i < num_types; i++) {
46317 struct btrfs_space_info *tmp;
46318
46319+ /* Don't copy in more than we allocated */
46320 if (!slot_count)
46321 break;
46322
46323+ slot_count--;
46324+
46325 info = NULL;
46326 rcu_read_lock();
46327 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
46328@@ -3057,10 +3060,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
46329 memcpy(dest, &space, sizeof(space));
46330 dest++;
46331 space_args.total_spaces++;
46332- slot_count--;
46333 }
46334- if (!slot_count)
46335- break;
46336 }
46337 up_read(&info->groups_sem);
46338 }
46339diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
46340index 300e09a..9fe4539 100644
46341--- a/fs/btrfs/relocation.c
46342+++ b/fs/btrfs/relocation.c
46343@@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
46344 }
46345 spin_unlock(&rc->reloc_root_tree.lock);
46346
46347- BUG_ON((struct btrfs_root *)node->data != root);
46348+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
46349
46350 if (!del) {
46351 spin_lock(&rc->reloc_root_tree.lock);
46352diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
46353index d8982e9..29a85fa 100644
46354--- a/fs/btrfs/super.c
46355+++ b/fs/btrfs/super.c
46356@@ -267,7 +267,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
46357 function, line, errstr);
46358 return;
46359 }
46360- ACCESS_ONCE(trans->transaction->aborted) = errno;
46361+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
46362 __btrfs_std_error(root->fs_info, function, line, errno, NULL);
46363 }
46364 /*
46365diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
46366index 622f469..e8d2d55 100644
46367--- a/fs/cachefiles/bind.c
46368+++ b/fs/cachefiles/bind.c
46369@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
46370 args);
46371
46372 /* start by checking things over */
46373- ASSERT(cache->fstop_percent >= 0 &&
46374- cache->fstop_percent < cache->fcull_percent &&
46375+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
46376 cache->fcull_percent < cache->frun_percent &&
46377 cache->frun_percent < 100);
46378
46379- ASSERT(cache->bstop_percent >= 0 &&
46380- cache->bstop_percent < cache->bcull_percent &&
46381+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
46382 cache->bcull_percent < cache->brun_percent &&
46383 cache->brun_percent < 100);
46384
46385diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
46386index 0a1467b..6a53245 100644
46387--- a/fs/cachefiles/daemon.c
46388+++ b/fs/cachefiles/daemon.c
46389@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
46390 if (n > buflen)
46391 return -EMSGSIZE;
46392
46393- if (copy_to_user(_buffer, buffer, n) != 0)
46394+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
46395 return -EFAULT;
46396
46397 return n;
46398@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
46399 if (test_bit(CACHEFILES_DEAD, &cache->flags))
46400 return -EIO;
46401
46402- if (datalen < 0 || datalen > PAGE_SIZE - 1)
46403+ if (datalen > PAGE_SIZE - 1)
46404 return -EOPNOTSUPP;
46405
46406 /* drag the command string into the kernel so we can parse it */
46407@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
46408 if (args[0] != '%' || args[1] != '\0')
46409 return -EINVAL;
46410
46411- if (fstop < 0 || fstop >= cache->fcull_percent)
46412+ if (fstop >= cache->fcull_percent)
46413 return cachefiles_daemon_range_error(cache, args);
46414
46415 cache->fstop_percent = fstop;
46416@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
46417 if (args[0] != '%' || args[1] != '\0')
46418 return -EINVAL;
46419
46420- if (bstop < 0 || bstop >= cache->bcull_percent)
46421+ if (bstop >= cache->bcull_percent)
46422 return cachefiles_daemon_range_error(cache, args);
46423
46424 cache->bstop_percent = bstop;
46425diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
46426index 4938251..7e01445 100644
46427--- a/fs/cachefiles/internal.h
46428+++ b/fs/cachefiles/internal.h
46429@@ -59,7 +59,7 @@ struct cachefiles_cache {
46430 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
46431 struct rb_root active_nodes; /* active nodes (can't be culled) */
46432 rwlock_t active_lock; /* lock for active_nodes */
46433- atomic_t gravecounter; /* graveyard uniquifier */
46434+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
46435 unsigned frun_percent; /* when to stop culling (% files) */
46436 unsigned fcull_percent; /* when to start culling (% files) */
46437 unsigned fstop_percent; /* when to stop allocating (% files) */
46438@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
46439 * proc.c
46440 */
46441 #ifdef CONFIG_CACHEFILES_HISTOGRAM
46442-extern atomic_t cachefiles_lookup_histogram[HZ];
46443-extern atomic_t cachefiles_mkdir_histogram[HZ];
46444-extern atomic_t cachefiles_create_histogram[HZ];
46445+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
46446+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
46447+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
46448
46449 extern int __init cachefiles_proc_init(void);
46450 extern void cachefiles_proc_cleanup(void);
46451 static inline
46452-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
46453+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
46454 {
46455 unsigned long jif = jiffies - start_jif;
46456 if (jif >= HZ)
46457 jif = HZ - 1;
46458- atomic_inc(&histogram[jif]);
46459+ atomic_inc_unchecked(&histogram[jif]);
46460 }
46461
46462 #else
46463diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
46464index 8c01c5fc..15f982e 100644
46465--- a/fs/cachefiles/namei.c
46466+++ b/fs/cachefiles/namei.c
46467@@ -317,7 +317,7 @@ try_again:
46468 /* first step is to make up a grave dentry in the graveyard */
46469 sprintf(nbuffer, "%08x%08x",
46470 (uint32_t) get_seconds(),
46471- (uint32_t) atomic_inc_return(&cache->gravecounter));
46472+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
46473
46474 /* do the multiway lock magic */
46475 trap = lock_rename(cache->graveyard, dir);
46476diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
46477index eccd339..4c1d995 100644
46478--- a/fs/cachefiles/proc.c
46479+++ b/fs/cachefiles/proc.c
46480@@ -14,9 +14,9 @@
46481 #include <linux/seq_file.h>
46482 #include "internal.h"
46483
46484-atomic_t cachefiles_lookup_histogram[HZ];
46485-atomic_t cachefiles_mkdir_histogram[HZ];
46486-atomic_t cachefiles_create_histogram[HZ];
46487+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
46488+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
46489+atomic_unchecked_t cachefiles_create_histogram[HZ];
46490
46491 /*
46492 * display the latency histogram
46493@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
46494 return 0;
46495 default:
46496 index = (unsigned long) v - 3;
46497- x = atomic_read(&cachefiles_lookup_histogram[index]);
46498- y = atomic_read(&cachefiles_mkdir_histogram[index]);
46499- z = atomic_read(&cachefiles_create_histogram[index]);
46500+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
46501+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
46502+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
46503 if (x == 0 && y == 0 && z == 0)
46504 return 0;
46505
46506diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
46507index 4809922..aab2c39 100644
46508--- a/fs/cachefiles/rdwr.c
46509+++ b/fs/cachefiles/rdwr.c
46510@@ -965,7 +965,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
46511 old_fs = get_fs();
46512 set_fs(KERNEL_DS);
46513 ret = file->f_op->write(
46514- file, (const void __user *) data, len, &pos);
46515+ file, (const void __force_user *) data, len, &pos);
46516 set_fs(old_fs);
46517 kunmap(page);
46518 if (ret != len)
46519diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
46520index 8c1aabe..bbf856a 100644
46521--- a/fs/ceph/dir.c
46522+++ b/fs/ceph/dir.c
46523@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
46524 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
46525 struct ceph_mds_client *mdsc = fsc->mdsc;
46526 unsigned frag = fpos_frag(filp->f_pos);
46527- int off = fpos_off(filp->f_pos);
46528+ unsigned int off = fpos_off(filp->f_pos);
46529 int err;
46530 u32 ftype;
46531 struct ceph_mds_reply_info_parsed *rinfo;
46532diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
46533index d9ea6ed..1e6c8ac 100644
46534--- a/fs/cifs/cifs_debug.c
46535+++ b/fs/cifs/cifs_debug.c
46536@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
46537
46538 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
46539 #ifdef CONFIG_CIFS_STATS2
46540- atomic_set(&totBufAllocCount, 0);
46541- atomic_set(&totSmBufAllocCount, 0);
46542+ atomic_set_unchecked(&totBufAllocCount, 0);
46543+ atomic_set_unchecked(&totSmBufAllocCount, 0);
46544 #endif /* CONFIG_CIFS_STATS2 */
46545 spin_lock(&cifs_tcp_ses_lock);
46546 list_for_each(tmp1, &cifs_tcp_ses_list) {
46547@@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
46548 tcon = list_entry(tmp3,
46549 struct cifs_tcon,
46550 tcon_list);
46551- atomic_set(&tcon->num_smbs_sent, 0);
46552+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
46553 if (server->ops->clear_stats)
46554 server->ops->clear_stats(tcon);
46555 }
46556@@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
46557 smBufAllocCount.counter, cifs_min_small);
46558 #ifdef CONFIG_CIFS_STATS2
46559 seq_printf(m, "Total Large %d Small %d Allocations\n",
46560- atomic_read(&totBufAllocCount),
46561- atomic_read(&totSmBufAllocCount));
46562+ atomic_read_unchecked(&totBufAllocCount),
46563+ atomic_read_unchecked(&totSmBufAllocCount));
46564 #endif /* CONFIG_CIFS_STATS2 */
46565
46566 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
46567@@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
46568 if (tcon->need_reconnect)
46569 seq_puts(m, "\tDISCONNECTED ");
46570 seq_printf(m, "\nSMBs: %d",
46571- atomic_read(&tcon->num_smbs_sent));
46572+ atomic_read_unchecked(&tcon->num_smbs_sent));
46573 if (server->ops->print_stats)
46574 server->ops->print_stats(m, tcon);
46575 }
46576diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
46577index de7f916..6cb22a9 100644
46578--- a/fs/cifs/cifsfs.c
46579+++ b/fs/cifs/cifsfs.c
46580@@ -997,7 +997,7 @@ cifs_init_request_bufs(void)
46581 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
46582 cifs_req_cachep = kmem_cache_create("cifs_request",
46583 CIFSMaxBufSize + max_hdr_size, 0,
46584- SLAB_HWCACHE_ALIGN, NULL);
46585+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
46586 if (cifs_req_cachep == NULL)
46587 return -ENOMEM;
46588
46589@@ -1024,7 +1024,7 @@ cifs_init_request_bufs(void)
46590 efficient to alloc 1 per page off the slab compared to 17K (5page)
46591 alloc of large cifs buffers even when page debugging is on */
46592 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
46593- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
46594+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
46595 NULL);
46596 if (cifs_sm_req_cachep == NULL) {
46597 mempool_destroy(cifs_req_poolp);
46598@@ -1109,8 +1109,8 @@ init_cifs(void)
46599 atomic_set(&bufAllocCount, 0);
46600 atomic_set(&smBufAllocCount, 0);
46601 #ifdef CONFIG_CIFS_STATS2
46602- atomic_set(&totBufAllocCount, 0);
46603- atomic_set(&totSmBufAllocCount, 0);
46604+ atomic_set_unchecked(&totBufAllocCount, 0);
46605+ atomic_set_unchecked(&totSmBufAllocCount, 0);
46606 #endif /* CONFIG_CIFS_STATS2 */
46607
46608 atomic_set(&midCount, 0);
46609diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
46610index e6899ce..d6b2920 100644
46611--- a/fs/cifs/cifsglob.h
46612+++ b/fs/cifs/cifsglob.h
46613@@ -751,35 +751,35 @@ struct cifs_tcon {
46614 __u16 Flags; /* optional support bits */
46615 enum statusEnum tidStatus;
46616 #ifdef CONFIG_CIFS_STATS
46617- atomic_t num_smbs_sent;
46618+ atomic_unchecked_t num_smbs_sent;
46619 union {
46620 struct {
46621- atomic_t num_writes;
46622- atomic_t num_reads;
46623- atomic_t num_flushes;
46624- atomic_t num_oplock_brks;
46625- atomic_t num_opens;
46626- atomic_t num_closes;
46627- atomic_t num_deletes;
46628- atomic_t num_mkdirs;
46629- atomic_t num_posixopens;
46630- atomic_t num_posixmkdirs;
46631- atomic_t num_rmdirs;
46632- atomic_t num_renames;
46633- atomic_t num_t2renames;
46634- atomic_t num_ffirst;
46635- atomic_t num_fnext;
46636- atomic_t num_fclose;
46637- atomic_t num_hardlinks;
46638- atomic_t num_symlinks;
46639- atomic_t num_locks;
46640- atomic_t num_acl_get;
46641- atomic_t num_acl_set;
46642+ atomic_unchecked_t num_writes;
46643+ atomic_unchecked_t num_reads;
46644+ atomic_unchecked_t num_flushes;
46645+ atomic_unchecked_t num_oplock_brks;
46646+ atomic_unchecked_t num_opens;
46647+ atomic_unchecked_t num_closes;
46648+ atomic_unchecked_t num_deletes;
46649+ atomic_unchecked_t num_mkdirs;
46650+ atomic_unchecked_t num_posixopens;
46651+ atomic_unchecked_t num_posixmkdirs;
46652+ atomic_unchecked_t num_rmdirs;
46653+ atomic_unchecked_t num_renames;
46654+ atomic_unchecked_t num_t2renames;
46655+ atomic_unchecked_t num_ffirst;
46656+ atomic_unchecked_t num_fnext;
46657+ atomic_unchecked_t num_fclose;
46658+ atomic_unchecked_t num_hardlinks;
46659+ atomic_unchecked_t num_symlinks;
46660+ atomic_unchecked_t num_locks;
46661+ atomic_unchecked_t num_acl_get;
46662+ atomic_unchecked_t num_acl_set;
46663 } cifs_stats;
46664 #ifdef CONFIG_CIFS_SMB2
46665 struct {
46666- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
46667- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
46668+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
46669+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
46670 } smb2_stats;
46671 #endif /* CONFIG_CIFS_SMB2 */
46672 } stats;
46673@@ -1080,7 +1080,7 @@ convert_delimiter(char *path, char delim)
46674 }
46675
46676 #ifdef CONFIG_CIFS_STATS
46677-#define cifs_stats_inc atomic_inc
46678+#define cifs_stats_inc atomic_inc_unchecked
46679
46680 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
46681 unsigned int bytes)
46682@@ -1445,8 +1445,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
46683 /* Various Debug counters */
46684 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
46685 #ifdef CONFIG_CIFS_STATS2
46686-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
46687-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
46688+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
46689+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
46690 #endif
46691 GLOBAL_EXTERN atomic_t smBufAllocCount;
46692 GLOBAL_EXTERN atomic_t midCount;
46693diff --git a/fs/cifs/link.c b/fs/cifs/link.c
46694index 51dc2fb..1e12a33 100644
46695--- a/fs/cifs/link.c
46696+++ b/fs/cifs/link.c
46697@@ -616,7 +616,7 @@ symlink_exit:
46698
46699 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
46700 {
46701- char *p = nd_get_link(nd);
46702+ const char *p = nd_get_link(nd);
46703 if (!IS_ERR(p))
46704 kfree(p);
46705 }
46706diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
46707index 3a00c0d..42d901c 100644
46708--- a/fs/cifs/misc.c
46709+++ b/fs/cifs/misc.c
46710@@ -169,7 +169,7 @@ cifs_buf_get(void)
46711 memset(ret_buf, 0, buf_size + 3);
46712 atomic_inc(&bufAllocCount);
46713 #ifdef CONFIG_CIFS_STATS2
46714- atomic_inc(&totBufAllocCount);
46715+ atomic_inc_unchecked(&totBufAllocCount);
46716 #endif /* CONFIG_CIFS_STATS2 */
46717 }
46718
46719@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
46720 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
46721 atomic_inc(&smBufAllocCount);
46722 #ifdef CONFIG_CIFS_STATS2
46723- atomic_inc(&totSmBufAllocCount);
46724+ atomic_inc_unchecked(&totSmBufAllocCount);
46725 #endif /* CONFIG_CIFS_STATS2 */
46726
46727 }
46728diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
46729index 47bc5a8..10decbe 100644
46730--- a/fs/cifs/smb1ops.c
46731+++ b/fs/cifs/smb1ops.c
46732@@ -586,27 +586,27 @@ static void
46733 cifs_clear_stats(struct cifs_tcon *tcon)
46734 {
46735 #ifdef CONFIG_CIFS_STATS
46736- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
46737- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
46738- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
46739- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
46740- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
46741- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
46742- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
46743- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
46744- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
46745- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
46746- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
46747- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
46748- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
46749- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
46750- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
46751- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
46752- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
46753- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
46754- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
46755- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
46756- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
46757+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
46758+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
46759+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
46760+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
46761+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
46762+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
46763+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
46764+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
46765+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
46766+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
46767+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
46768+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
46769+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
46770+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
46771+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
46772+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
46773+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
46774+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
46775+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
46776+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
46777+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
46778 #endif
46779 }
46780
46781@@ -615,36 +615,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
46782 {
46783 #ifdef CONFIG_CIFS_STATS
46784 seq_printf(m, " Oplocks breaks: %d",
46785- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
46786+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
46787 seq_printf(m, "\nReads: %d Bytes: %llu",
46788- atomic_read(&tcon->stats.cifs_stats.num_reads),
46789+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
46790 (long long)(tcon->bytes_read));
46791 seq_printf(m, "\nWrites: %d Bytes: %llu",
46792- atomic_read(&tcon->stats.cifs_stats.num_writes),
46793+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
46794 (long long)(tcon->bytes_written));
46795 seq_printf(m, "\nFlushes: %d",
46796- atomic_read(&tcon->stats.cifs_stats.num_flushes));
46797+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
46798 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
46799- atomic_read(&tcon->stats.cifs_stats.num_locks),
46800- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
46801- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
46802+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
46803+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
46804+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
46805 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
46806- atomic_read(&tcon->stats.cifs_stats.num_opens),
46807- atomic_read(&tcon->stats.cifs_stats.num_closes),
46808- atomic_read(&tcon->stats.cifs_stats.num_deletes));
46809+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
46810+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
46811+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
46812 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
46813- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
46814- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
46815+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
46816+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
46817 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
46818- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
46819- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
46820+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
46821+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
46822 seq_printf(m, "\nRenames: %d T2 Renames %d",
46823- atomic_read(&tcon->stats.cifs_stats.num_renames),
46824- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
46825+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
46826+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
46827 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
46828- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
46829- atomic_read(&tcon->stats.cifs_stats.num_fnext),
46830- atomic_read(&tcon->stats.cifs_stats.num_fclose));
46831+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
46832+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
46833+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
46834 #endif
46835 }
46836
46837diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
46838index c9c7aa7..065056a 100644
46839--- a/fs/cifs/smb2ops.c
46840+++ b/fs/cifs/smb2ops.c
46841@@ -274,8 +274,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
46842 #ifdef CONFIG_CIFS_STATS
46843 int i;
46844 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
46845- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
46846- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
46847+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
46848+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
46849 }
46850 #endif
46851 }
46852@@ -284,66 +284,66 @@ static void
46853 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
46854 {
46855 #ifdef CONFIG_CIFS_STATS
46856- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
46857- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
46858+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
46859+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
46860 seq_printf(m, "\nNegotiates: %d sent %d failed",
46861- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
46862- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
46863+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
46864+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
46865 seq_printf(m, "\nSessionSetups: %d sent %d failed",
46866- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
46867- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
46868+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
46869+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
46870 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
46871 seq_printf(m, "\nLogoffs: %d sent %d failed",
46872- atomic_read(&sent[SMB2_LOGOFF_HE]),
46873- atomic_read(&failed[SMB2_LOGOFF_HE]));
46874+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
46875+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
46876 seq_printf(m, "\nTreeConnects: %d sent %d failed",
46877- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
46878- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
46879+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
46880+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
46881 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
46882- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
46883- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
46884+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
46885+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
46886 seq_printf(m, "\nCreates: %d sent %d failed",
46887- atomic_read(&sent[SMB2_CREATE_HE]),
46888- atomic_read(&failed[SMB2_CREATE_HE]));
46889+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
46890+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
46891 seq_printf(m, "\nCloses: %d sent %d failed",
46892- atomic_read(&sent[SMB2_CLOSE_HE]),
46893- atomic_read(&failed[SMB2_CLOSE_HE]));
46894+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
46895+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
46896 seq_printf(m, "\nFlushes: %d sent %d failed",
46897- atomic_read(&sent[SMB2_FLUSH_HE]),
46898- atomic_read(&failed[SMB2_FLUSH_HE]));
46899+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
46900+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
46901 seq_printf(m, "\nReads: %d sent %d failed",
46902- atomic_read(&sent[SMB2_READ_HE]),
46903- atomic_read(&failed[SMB2_READ_HE]));
46904+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
46905+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
46906 seq_printf(m, "\nWrites: %d sent %d failed",
46907- atomic_read(&sent[SMB2_WRITE_HE]),
46908- atomic_read(&failed[SMB2_WRITE_HE]));
46909+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
46910+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
46911 seq_printf(m, "\nLocks: %d sent %d failed",
46912- atomic_read(&sent[SMB2_LOCK_HE]),
46913- atomic_read(&failed[SMB2_LOCK_HE]));
46914+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
46915+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
46916 seq_printf(m, "\nIOCTLs: %d sent %d failed",
46917- atomic_read(&sent[SMB2_IOCTL_HE]),
46918- atomic_read(&failed[SMB2_IOCTL_HE]));
46919+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
46920+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
46921 seq_printf(m, "\nCancels: %d sent %d failed",
46922- atomic_read(&sent[SMB2_CANCEL_HE]),
46923- atomic_read(&failed[SMB2_CANCEL_HE]));
46924+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
46925+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
46926 seq_printf(m, "\nEchos: %d sent %d failed",
46927- atomic_read(&sent[SMB2_ECHO_HE]),
46928- atomic_read(&failed[SMB2_ECHO_HE]));
46929+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
46930+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
46931 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
46932- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
46933- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
46934+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
46935+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
46936 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
46937- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
46938- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
46939+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
46940+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
46941 seq_printf(m, "\nQueryInfos: %d sent %d failed",
46942- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
46943- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
46944+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
46945+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
46946 seq_printf(m, "\nSetInfos: %d sent %d failed",
46947- atomic_read(&sent[SMB2_SET_INFO_HE]),
46948- atomic_read(&failed[SMB2_SET_INFO_HE]));
46949+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
46950+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
46951 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
46952- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
46953- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
46954+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
46955+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
46956 #endif
46957 }
46958
46959diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
46960index 41d9d07..dbb4772 100644
46961--- a/fs/cifs/smb2pdu.c
46962+++ b/fs/cifs/smb2pdu.c
46963@@ -1761,8 +1761,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
46964 default:
46965 cERROR(1, "info level %u isn't supported",
46966 srch_inf->info_level);
46967- rc = -EINVAL;
46968- goto qdir_exit;
46969+ return -EINVAL;
46970 }
46971
46972 req->FileIndex = cpu_to_le32(index);
46973diff --git a/fs/coda/cache.c b/fs/coda/cache.c
46974index 958ae0e..505c9d0 100644
46975--- a/fs/coda/cache.c
46976+++ b/fs/coda/cache.c
46977@@ -24,7 +24,7 @@
46978 #include "coda_linux.h"
46979 #include "coda_cache.h"
46980
46981-static atomic_t permission_epoch = ATOMIC_INIT(0);
46982+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
46983
46984 /* replace or extend an acl cache hit */
46985 void coda_cache_enter(struct inode *inode, int mask)
46986@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
46987 struct coda_inode_info *cii = ITOC(inode);
46988
46989 spin_lock(&cii->c_lock);
46990- cii->c_cached_epoch = atomic_read(&permission_epoch);
46991+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
46992 if (cii->c_uid != current_fsuid()) {
46993 cii->c_uid = current_fsuid();
46994 cii->c_cached_perm = mask;
46995@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
46996 {
46997 struct coda_inode_info *cii = ITOC(inode);
46998 spin_lock(&cii->c_lock);
46999- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
47000+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
47001 spin_unlock(&cii->c_lock);
47002 }
47003
47004 /* remove all acl caches */
47005 void coda_cache_clear_all(struct super_block *sb)
47006 {
47007- atomic_inc(&permission_epoch);
47008+ atomic_inc_unchecked(&permission_epoch);
47009 }
47010
47011
47012@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
47013 spin_lock(&cii->c_lock);
47014 hit = (mask & cii->c_cached_perm) == mask &&
47015 cii->c_uid == current_fsuid() &&
47016- cii->c_cached_epoch == atomic_read(&permission_epoch);
47017+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
47018 spin_unlock(&cii->c_lock);
47019
47020 return hit;
47021diff --git a/fs/compat.c b/fs/compat.c
47022index 015e1e1..5ce8e54 100644
47023--- a/fs/compat.c
47024+++ b/fs/compat.c
47025@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
47026
47027 set_fs(KERNEL_DS);
47028 /* The __user pointer cast is valid because of the set_fs() */
47029- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
47030+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
47031 set_fs(oldfs);
47032 /* truncating is ok because it's a user address */
47033 if (!ret)
47034@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
47035 goto out;
47036
47037 ret = -EINVAL;
47038- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
47039+ if (nr_segs > UIO_MAXIOV)
47040 goto out;
47041 if (nr_segs > fast_segs) {
47042 ret = -ENOMEM;
47043@@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
47044
47045 struct compat_readdir_callback {
47046 struct compat_old_linux_dirent __user *dirent;
47047+ struct file * file;
47048 int result;
47049 };
47050
47051@@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
47052 buf->result = -EOVERFLOW;
47053 return -EOVERFLOW;
47054 }
47055+
47056+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47057+ return 0;
47058+
47059 buf->result++;
47060 dirent = buf->dirent;
47061 if (!access_ok(VERIFY_WRITE, dirent,
47062@@ -878,6 +883,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
47063
47064 buf.result = 0;
47065 buf.dirent = dirent;
47066+ buf.file = f.file;
47067
47068 error = vfs_readdir(f.file, compat_fillonedir, &buf);
47069 if (buf.result)
47070@@ -897,6 +903,7 @@ struct compat_linux_dirent {
47071 struct compat_getdents_callback {
47072 struct compat_linux_dirent __user *current_dir;
47073 struct compat_linux_dirent __user *previous;
47074+ struct file * file;
47075 int count;
47076 int error;
47077 };
47078@@ -918,6 +925,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
47079 buf->error = -EOVERFLOW;
47080 return -EOVERFLOW;
47081 }
47082+
47083+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47084+ return 0;
47085+
47086 dirent = buf->previous;
47087 if (dirent) {
47088 if (__put_user(offset, &dirent->d_off))
47089@@ -963,6 +974,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
47090 buf.previous = NULL;
47091 buf.count = count;
47092 buf.error = 0;
47093+ buf.file = f.file;
47094
47095 error = vfs_readdir(f.file, compat_filldir, &buf);
47096 if (error >= 0)
47097@@ -983,6 +995,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
47098 struct compat_getdents_callback64 {
47099 struct linux_dirent64 __user *current_dir;
47100 struct linux_dirent64 __user *previous;
47101+ struct file * file;
47102 int count;
47103 int error;
47104 };
47105@@ -999,6 +1012,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
47106 buf->error = -EINVAL; /* only used if we fail.. */
47107 if (reclen > buf->count)
47108 return -EINVAL;
47109+
47110+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47111+ return 0;
47112+
47113 dirent = buf->previous;
47114
47115 if (dirent) {
47116@@ -1048,13 +1065,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
47117 buf.previous = NULL;
47118 buf.count = count;
47119 buf.error = 0;
47120+ buf.file = f.file;
47121
47122 error = vfs_readdir(f.file, compat_filldir64, &buf);
47123 if (error >= 0)
47124 error = buf.error;
47125 lastdirent = buf.previous;
47126 if (lastdirent) {
47127- typeof(lastdirent->d_off) d_off = f.file->f_pos;
47128+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
47129 if (__put_user_unaligned(d_off, &lastdirent->d_off))
47130 error = -EFAULT;
47131 else
47132diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
47133index a81147e..20bf2b5 100644
47134--- a/fs/compat_binfmt_elf.c
47135+++ b/fs/compat_binfmt_elf.c
47136@@ -30,11 +30,13 @@
47137 #undef elf_phdr
47138 #undef elf_shdr
47139 #undef elf_note
47140+#undef elf_dyn
47141 #undef elf_addr_t
47142 #define elfhdr elf32_hdr
47143 #define elf_phdr elf32_phdr
47144 #define elf_shdr elf32_shdr
47145 #define elf_note elf32_note
47146+#define elf_dyn Elf32_Dyn
47147 #define elf_addr_t Elf32_Addr
47148
47149 /*
47150diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
47151index e2f57a0..3c78771 100644
47152--- a/fs/compat_ioctl.c
47153+++ b/fs/compat_ioctl.c
47154@@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
47155 return -EFAULT;
47156 if (__get_user(udata, &ss32->iomem_base))
47157 return -EFAULT;
47158- ss.iomem_base = compat_ptr(udata);
47159+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
47160 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
47161 __get_user(ss.port_high, &ss32->port_high))
47162 return -EFAULT;
47163@@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
47164 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
47165 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
47166 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
47167- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
47168+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
47169 return -EFAULT;
47170
47171 return ioctl_preallocate(file, p);
47172@@ -1620,8 +1620,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
47173 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
47174 {
47175 unsigned int a, b;
47176- a = *(unsigned int *)p;
47177- b = *(unsigned int *)q;
47178+ a = *(const unsigned int *)p;
47179+ b = *(const unsigned int *)q;
47180 if (a > b)
47181 return 1;
47182 if (a < b)
47183diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
47184index 712b10f..6b54d7b 100644
47185--- a/fs/configfs/dir.c
47186+++ b/fs/configfs/dir.c
47187@@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
47188 }
47189 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
47190 struct configfs_dirent *next;
47191- const char * name;
47192+ const unsigned char * name;
47193+ char d_name[sizeof(next->s_dentry->d_iname)];
47194 int len;
47195 struct inode *inode = NULL;
47196
47197@@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
47198 continue;
47199
47200 name = configfs_get_name(next);
47201- len = strlen(name);
47202+ if (next->s_dentry && name == next->s_dentry->d_iname) {
47203+ len = next->s_dentry->d_name.len;
47204+ memcpy(d_name, name, len);
47205+ name = d_name;
47206+ } else
47207+ len = strlen(name);
47208
47209 /*
47210 * We'll have a dentry and an inode for
47211diff --git a/fs/coredump.c b/fs/coredump.c
47212index 1774932..5812106 100644
47213--- a/fs/coredump.c
47214+++ b/fs/coredump.c
47215@@ -52,7 +52,7 @@ struct core_name {
47216 char *corename;
47217 int used, size;
47218 };
47219-static atomic_t call_count = ATOMIC_INIT(1);
47220+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
47221
47222 /* The maximal length of core_pattern is also specified in sysctl.c */
47223
47224@@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
47225 {
47226 char *old_corename = cn->corename;
47227
47228- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
47229+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
47230 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
47231
47232 if (!cn->corename) {
47233@@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
47234 int pid_in_pattern = 0;
47235 int err = 0;
47236
47237- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
47238+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
47239 cn->corename = kmalloc(cn->size, GFP_KERNEL);
47240 cn->used = 0;
47241
47242@@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
47243 pipe = file->f_path.dentry->d_inode->i_pipe;
47244
47245 pipe_lock(pipe);
47246- pipe->readers++;
47247- pipe->writers--;
47248+ atomic_inc(&pipe->readers);
47249+ atomic_dec(&pipe->writers);
47250
47251- while ((pipe->readers > 1) && (!signal_pending(current))) {
47252+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
47253 wake_up_interruptible_sync(&pipe->wait);
47254 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
47255 pipe_wait(pipe);
47256 }
47257
47258- pipe->readers--;
47259- pipe->writers++;
47260+ atomic_dec(&pipe->readers);
47261+ atomic_inc(&pipe->writers);
47262 pipe_unlock(pipe);
47263
47264 }
47265@@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo)
47266 int ispipe;
47267 struct files_struct *displaced;
47268 bool need_nonrelative = false;
47269- static atomic_t core_dump_count = ATOMIC_INIT(0);
47270+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
47271+ long signr = siginfo->si_signo;
47272 struct coredump_params cprm = {
47273 .siginfo = siginfo,
47274 .regs = signal_pt_regs(),
47275@@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo)
47276 .mm_flags = mm->flags,
47277 };
47278
47279- audit_core_dumps(siginfo->si_signo);
47280+ audit_core_dumps(signr);
47281+
47282+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
47283+ gr_handle_brute_attach(cprm.mm_flags);
47284
47285 binfmt = mm->binfmt;
47286 if (!binfmt || !binfmt->core_dump)
47287@@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo)
47288 need_nonrelative = true;
47289 }
47290
47291- retval = coredump_wait(siginfo->si_signo, &core_state);
47292+ retval = coredump_wait(signr, &core_state);
47293 if (retval < 0)
47294 goto fail_creds;
47295
47296@@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo)
47297 }
47298 cprm.limit = RLIM_INFINITY;
47299
47300- dump_count = atomic_inc_return(&core_dump_count);
47301+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
47302 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
47303 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
47304 task_tgid_vnr(current), current->comm);
47305@@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo)
47306 } else {
47307 struct inode *inode;
47308
47309+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
47310+
47311 if (cprm.limit < binfmt->min_coredump)
47312 goto fail_unlock;
47313
47314@@ -640,7 +646,7 @@ close_fail:
47315 filp_close(cprm.file, NULL);
47316 fail_dropcount:
47317 if (ispipe)
47318- atomic_dec(&core_dump_count);
47319+ atomic_dec_unchecked(&core_dump_count);
47320 fail_unlock:
47321 kfree(cn.corename);
47322 fail_corename:
47323@@ -659,7 +665,7 @@ fail:
47324 */
47325 int dump_write(struct file *file, const void *addr, int nr)
47326 {
47327- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
47328+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
47329 }
47330 EXPORT_SYMBOL(dump_write);
47331
47332diff --git a/fs/dcache.c b/fs/dcache.c
47333index 19153a0..428c2f5 100644
47334--- a/fs/dcache.c
47335+++ b/fs/dcache.c
47336@@ -3133,7 +3133,7 @@ void __init vfs_caches_init(unsigned long mempages)
47337 mempages -= reserve;
47338
47339 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
47340- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
47341+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
47342
47343 dcache_init();
47344 inode_init();
47345diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
47346index a5f12b7..4ee8a6f 100644
47347--- a/fs/debugfs/inode.c
47348+++ b/fs/debugfs/inode.c
47349@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
47350 */
47351 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
47352 {
47353+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
47354+ return __create_file(name, S_IFDIR | S_IRWXU,
47355+#else
47356 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
47357+#endif
47358 parent, NULL, NULL);
47359 }
47360 EXPORT_SYMBOL_GPL(debugfs_create_dir);
47361diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
47362index cc7709e..7e7211f 100644
47363--- a/fs/ecryptfs/inode.c
47364+++ b/fs/ecryptfs/inode.c
47365@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
47366 old_fs = get_fs();
47367 set_fs(get_ds());
47368 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
47369- (char __user *)lower_buf,
47370+ (char __force_user *)lower_buf,
47371 PATH_MAX);
47372 set_fs(old_fs);
47373 if (rc < 0)
47374@@ -706,7 +706,7 @@ out:
47375 static void
47376 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
47377 {
47378- char *buf = nd_get_link(nd);
47379+ const char *buf = nd_get_link(nd);
47380 if (!IS_ERR(buf)) {
47381 /* Free the char* */
47382 kfree(buf);
47383diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
47384index 412e6ed..4292d22 100644
47385--- a/fs/ecryptfs/miscdev.c
47386+++ b/fs/ecryptfs/miscdev.c
47387@@ -315,7 +315,7 @@ check_list:
47388 goto out_unlock_msg_ctx;
47389 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
47390 if (msg_ctx->msg) {
47391- if (copy_to_user(&buf[i], packet_length, packet_length_size))
47392+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
47393 goto out_unlock_msg_ctx;
47394 i += packet_length_size;
47395 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
47396diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
47397index b2a34a1..162fa69 100644
47398--- a/fs/ecryptfs/read_write.c
47399+++ b/fs/ecryptfs/read_write.c
47400@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
47401 return -EIO;
47402 fs_save = get_fs();
47403 set_fs(get_ds());
47404- rc = vfs_write(lower_file, data, size, &offset);
47405+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
47406 set_fs(fs_save);
47407 mark_inode_dirty_sync(ecryptfs_inode);
47408 return rc;
47409@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
47410 return -EIO;
47411 fs_save = get_fs();
47412 set_fs(get_ds());
47413- rc = vfs_read(lower_file, data, size, &offset);
47414+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
47415 set_fs(fs_save);
47416 return rc;
47417 }
47418diff --git a/fs/exec.c b/fs/exec.c
47419index 20df02c..1dff97d 100644
47420--- a/fs/exec.c
47421+++ b/fs/exec.c
47422@@ -55,6 +55,17 @@
47423 #include <linux/pipe_fs_i.h>
47424 #include <linux/oom.h>
47425 #include <linux/compat.h>
47426+#include <linux/random.h>
47427+#include <linux/seq_file.h>
47428+#include <linux/coredump.h>
47429+#include <linux/mman.h>
47430+
47431+#ifdef CONFIG_PAX_REFCOUNT
47432+#include <linux/kallsyms.h>
47433+#include <linux/kdebug.h>
47434+#endif
47435+
47436+#include <trace/events/fs.h>
47437
47438 #include <asm/uaccess.h>
47439 #include <asm/mmu_context.h>
47440@@ -66,6 +77,18 @@
47441
47442 #include <trace/events/sched.h>
47443
47444+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
47445+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
47446+{
47447+ 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");
47448+}
47449+#endif
47450+
47451+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
47452+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
47453+EXPORT_SYMBOL(pax_set_initial_flags_func);
47454+#endif
47455+
47456 int suid_dumpable = 0;
47457
47458 static LIST_HEAD(formats);
47459@@ -180,18 +203,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
47460 int write)
47461 {
47462 struct page *page;
47463- int ret;
47464
47465-#ifdef CONFIG_STACK_GROWSUP
47466- if (write) {
47467- ret = expand_downwards(bprm->vma, pos);
47468- if (ret < 0)
47469- return NULL;
47470- }
47471-#endif
47472- ret = get_user_pages(current, bprm->mm, pos,
47473- 1, write, 1, &page, NULL);
47474- if (ret <= 0)
47475+ if (0 > expand_downwards(bprm->vma, pos))
47476+ return NULL;
47477+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
47478 return NULL;
47479
47480 if (write) {
47481@@ -207,6 +222,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
47482 if (size <= ARG_MAX)
47483 return page;
47484
47485+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47486+ // only allow 512KB for argv+env on suid/sgid binaries
47487+ // to prevent easy ASLR exhaustion
47488+ if (((bprm->cred->euid != current_euid()) ||
47489+ (bprm->cred->egid != current_egid())) &&
47490+ (size > (512 * 1024))) {
47491+ put_page(page);
47492+ return NULL;
47493+ }
47494+#endif
47495+
47496 /*
47497 * Limit to 1/4-th the stack size for the argv+env strings.
47498 * This ensures that:
47499@@ -266,6 +292,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
47500 vma->vm_end = STACK_TOP_MAX;
47501 vma->vm_start = vma->vm_end - PAGE_SIZE;
47502 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
47503+
47504+#ifdef CONFIG_PAX_SEGMEXEC
47505+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
47506+#endif
47507+
47508 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
47509 INIT_LIST_HEAD(&vma->anon_vma_chain);
47510
47511@@ -276,6 +307,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
47512 mm->stack_vm = mm->total_vm = 1;
47513 up_write(&mm->mmap_sem);
47514 bprm->p = vma->vm_end - sizeof(void *);
47515+
47516+#ifdef CONFIG_PAX_RANDUSTACK
47517+ if (randomize_va_space)
47518+ bprm->p ^= random32() & ~PAGE_MASK;
47519+#endif
47520+
47521 return 0;
47522 err:
47523 up_write(&mm->mmap_sem);
47524@@ -384,19 +421,7 @@ err:
47525 return err;
47526 }
47527
47528-struct user_arg_ptr {
47529-#ifdef CONFIG_COMPAT
47530- bool is_compat;
47531-#endif
47532- union {
47533- const char __user *const __user *native;
47534-#ifdef CONFIG_COMPAT
47535- const compat_uptr_t __user *compat;
47536-#endif
47537- } ptr;
47538-};
47539-
47540-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
47541+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
47542 {
47543 const char __user *native;
47544
47545@@ -405,14 +430,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
47546 compat_uptr_t compat;
47547
47548 if (get_user(compat, argv.ptr.compat + nr))
47549- return ERR_PTR(-EFAULT);
47550+ return (const char __force_user *)ERR_PTR(-EFAULT);
47551
47552 return compat_ptr(compat);
47553 }
47554 #endif
47555
47556 if (get_user(native, argv.ptr.native + nr))
47557- return ERR_PTR(-EFAULT);
47558+ return (const char __force_user *)ERR_PTR(-EFAULT);
47559
47560 return native;
47561 }
47562@@ -431,7 +456,7 @@ static int count(struct user_arg_ptr argv, int max)
47563 if (!p)
47564 break;
47565
47566- if (IS_ERR(p))
47567+ if (IS_ERR((const char __force_kernel *)p))
47568 return -EFAULT;
47569
47570 if (i >= max)
47571@@ -466,7 +491,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
47572
47573 ret = -EFAULT;
47574 str = get_user_arg_ptr(argv, argc);
47575- if (IS_ERR(str))
47576+ if (IS_ERR((const char __force_kernel *)str))
47577 goto out;
47578
47579 len = strnlen_user(str, MAX_ARG_STRLEN);
47580@@ -548,7 +573,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
47581 int r;
47582 mm_segment_t oldfs = get_fs();
47583 struct user_arg_ptr argv = {
47584- .ptr.native = (const char __user *const __user *)__argv,
47585+ .ptr.native = (const char __force_user *const __force_user *)__argv,
47586 };
47587
47588 set_fs(KERNEL_DS);
47589@@ -583,7 +608,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
47590 unsigned long new_end = old_end - shift;
47591 struct mmu_gather tlb;
47592
47593- BUG_ON(new_start > new_end);
47594+ if (new_start >= new_end || new_start < mmap_min_addr)
47595+ return -ENOMEM;
47596
47597 /*
47598 * ensure there are no vmas between where we want to go
47599@@ -592,6 +618,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
47600 if (vma != find_vma(mm, new_start))
47601 return -EFAULT;
47602
47603+#ifdef CONFIG_PAX_SEGMEXEC
47604+ BUG_ON(pax_find_mirror_vma(vma));
47605+#endif
47606+
47607 /*
47608 * cover the whole range: [new_start, old_end)
47609 */
47610@@ -672,10 +702,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
47611 stack_top = arch_align_stack(stack_top);
47612 stack_top = PAGE_ALIGN(stack_top);
47613
47614- if (unlikely(stack_top < mmap_min_addr) ||
47615- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
47616- return -ENOMEM;
47617-
47618 stack_shift = vma->vm_end - stack_top;
47619
47620 bprm->p -= stack_shift;
47621@@ -687,8 +713,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
47622 bprm->exec -= stack_shift;
47623
47624 down_write(&mm->mmap_sem);
47625+
47626+ /* Move stack pages down in memory. */
47627+ if (stack_shift) {
47628+ ret = shift_arg_pages(vma, stack_shift);
47629+ if (ret)
47630+ goto out_unlock;
47631+ }
47632+
47633 vm_flags = VM_STACK_FLAGS;
47634
47635+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
47636+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
47637+ vm_flags &= ~VM_EXEC;
47638+
47639+#ifdef CONFIG_PAX_MPROTECT
47640+ if (mm->pax_flags & MF_PAX_MPROTECT)
47641+ vm_flags &= ~VM_MAYEXEC;
47642+#endif
47643+
47644+ }
47645+#endif
47646+
47647 /*
47648 * Adjust stack execute permissions; explicitly enable for
47649 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
47650@@ -707,13 +753,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
47651 goto out_unlock;
47652 BUG_ON(prev != vma);
47653
47654- /* Move stack pages down in memory. */
47655- if (stack_shift) {
47656- ret = shift_arg_pages(vma, stack_shift);
47657- if (ret)
47658- goto out_unlock;
47659- }
47660-
47661 /* mprotect_fixup is overkill to remove the temporary stack flags */
47662 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
47663
47664@@ -737,6 +776,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
47665 #endif
47666 current->mm->start_stack = bprm->p;
47667 ret = expand_stack(vma, stack_base);
47668+
47669+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_ASLR)
47670+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
47671+ unsigned long size, flags, vm_flags;
47672+
47673+ size = STACK_TOP - vma->vm_end;
47674+ flags = MAP_FIXED | MAP_PRIVATE;
47675+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
47676+
47677+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, flags, vm_flags, 0);
47678+
47679+#ifdef CONFIG_X86
47680+ if (!ret) {
47681+ size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
47682+ ret = 0 != mmap_region(NULL, 0, size, flags, vm_flags, 0);
47683+ }
47684+#endif
47685+
47686+ }
47687+#endif
47688+
47689 if (ret)
47690 ret = -EFAULT;
47691
47692@@ -772,6 +832,8 @@ struct file *open_exec(const char *name)
47693
47694 fsnotify_open(file);
47695
47696+ trace_open_exec(name);
47697+
47698 err = deny_write_access(file);
47699 if (err)
47700 goto exit;
47701@@ -795,7 +857,7 @@ int kernel_read(struct file *file, loff_t offset,
47702 old_fs = get_fs();
47703 set_fs(get_ds());
47704 /* The cast to a user pointer is valid due to the set_fs() */
47705- result = vfs_read(file, (void __user *)addr, count, &pos);
47706+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
47707 set_fs(old_fs);
47708 return result;
47709 }
47710@@ -1247,7 +1309,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
47711 }
47712 rcu_read_unlock();
47713
47714- if (p->fs->users > n_fs) {
47715+ if (atomic_read(&p->fs->users) > n_fs) {
47716 bprm->unsafe |= LSM_UNSAFE_SHARE;
47717 } else {
47718 res = -EAGAIN;
47719@@ -1447,6 +1509,28 @@ int search_binary_handler(struct linux_binprm *bprm)
47720
47721 EXPORT_SYMBOL(search_binary_handler);
47722
47723+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47724+static DEFINE_PER_CPU(u64, exec_counter);
47725+static int __init init_exec_counters(void)
47726+{
47727+ unsigned int cpu;
47728+
47729+ for_each_possible_cpu(cpu) {
47730+ per_cpu(exec_counter, cpu) = (u64)cpu;
47731+ }
47732+
47733+ return 0;
47734+}
47735+early_initcall(init_exec_counters);
47736+static inline void increment_exec_counter(void)
47737+{
47738+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
47739+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
47740+}
47741+#else
47742+static inline void increment_exec_counter(void) {}
47743+#endif
47744+
47745 /*
47746 * sys_execve() executes a new program.
47747 */
47748@@ -1454,6 +1538,11 @@ static int do_execve_common(const char *filename,
47749 struct user_arg_ptr argv,
47750 struct user_arg_ptr envp)
47751 {
47752+#ifdef CONFIG_GRKERNSEC
47753+ struct file *old_exec_file;
47754+ struct acl_subject_label *old_acl;
47755+ struct rlimit old_rlim[RLIM_NLIMITS];
47756+#endif
47757 struct linux_binprm *bprm;
47758 struct file *file;
47759 struct files_struct *displaced;
47760@@ -1461,6 +1550,8 @@ static int do_execve_common(const char *filename,
47761 int retval;
47762 const struct cred *cred = current_cred();
47763
47764+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
47765+
47766 /*
47767 * We move the actual failure in case of RLIMIT_NPROC excess from
47768 * set*uid() to execve() because too many poorly written programs
47769@@ -1501,12 +1592,27 @@ static int do_execve_common(const char *filename,
47770 if (IS_ERR(file))
47771 goto out_unmark;
47772
47773+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
47774+ retval = -EPERM;
47775+ goto out_file;
47776+ }
47777+
47778 sched_exec();
47779
47780 bprm->file = file;
47781 bprm->filename = filename;
47782 bprm->interp = filename;
47783
47784+ if (gr_process_user_ban()) {
47785+ retval = -EPERM;
47786+ goto out_file;
47787+ }
47788+
47789+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
47790+ retval = -EACCES;
47791+ goto out_file;
47792+ }
47793+
47794 retval = bprm_mm_init(bprm);
47795 if (retval)
47796 goto out_file;
47797@@ -1523,24 +1629,65 @@ static int do_execve_common(const char *filename,
47798 if (retval < 0)
47799 goto out;
47800
47801+#ifdef CONFIG_GRKERNSEC
47802+ old_acl = current->acl;
47803+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
47804+ old_exec_file = current->exec_file;
47805+ get_file(file);
47806+ current->exec_file = file;
47807+#endif
47808+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47809+ /* limit suid stack to 8MB
47810+ * we saved the old limits above and will restore them if this exec fails
47811+ */
47812+ if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
47813+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
47814+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
47815+#endif
47816+
47817+ if (!gr_tpe_allow(file)) {
47818+ retval = -EACCES;
47819+ goto out_fail;
47820+ }
47821+
47822+ if (gr_check_crash_exec(file)) {
47823+ retval = -EACCES;
47824+ goto out_fail;
47825+ }
47826+
47827+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
47828+ bprm->unsafe);
47829+ if (retval < 0)
47830+ goto out_fail;
47831+
47832 retval = copy_strings_kernel(1, &bprm->filename, bprm);
47833 if (retval < 0)
47834- goto out;
47835+ goto out_fail;
47836
47837 bprm->exec = bprm->p;
47838 retval = copy_strings(bprm->envc, envp, bprm);
47839 if (retval < 0)
47840- goto out;
47841+ goto out_fail;
47842
47843 retval = copy_strings(bprm->argc, argv, bprm);
47844 if (retval < 0)
47845- goto out;
47846+ goto out_fail;
47847+
47848+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
47849+
47850+ gr_handle_exec_args(bprm, argv);
47851
47852 retval = search_binary_handler(bprm);
47853 if (retval < 0)
47854- goto out;
47855+ goto out_fail;
47856+#ifdef CONFIG_GRKERNSEC
47857+ if (old_exec_file)
47858+ fput(old_exec_file);
47859+#endif
47860
47861 /* execve succeeded */
47862+
47863+ increment_exec_counter();
47864 current->fs->in_exec = 0;
47865 current->in_execve = 0;
47866 acct_update_integrals(current);
47867@@ -1549,6 +1696,14 @@ static int do_execve_common(const char *filename,
47868 put_files_struct(displaced);
47869 return retval;
47870
47871+out_fail:
47872+#ifdef CONFIG_GRKERNSEC
47873+ current->acl = old_acl;
47874+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
47875+ fput(current->exec_file);
47876+ current->exec_file = old_exec_file;
47877+#endif
47878+
47879 out:
47880 if (bprm->mm) {
47881 acct_arg_size(bprm, 0);
47882@@ -1697,3 +1852,253 @@ asmlinkage long compat_sys_execve(const char __user * filename,
47883 return error;
47884 }
47885 #endif
47886+
47887+int pax_check_flags(unsigned long *flags)
47888+{
47889+ int retval = 0;
47890+
47891+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
47892+ if (*flags & MF_PAX_SEGMEXEC)
47893+ {
47894+ *flags &= ~MF_PAX_SEGMEXEC;
47895+ retval = -EINVAL;
47896+ }
47897+#endif
47898+
47899+ if ((*flags & MF_PAX_PAGEEXEC)
47900+
47901+#ifdef CONFIG_PAX_PAGEEXEC
47902+ && (*flags & MF_PAX_SEGMEXEC)
47903+#endif
47904+
47905+ )
47906+ {
47907+ *flags &= ~MF_PAX_PAGEEXEC;
47908+ retval = -EINVAL;
47909+ }
47910+
47911+ if ((*flags & MF_PAX_MPROTECT)
47912+
47913+#ifdef CONFIG_PAX_MPROTECT
47914+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
47915+#endif
47916+
47917+ )
47918+ {
47919+ *flags &= ~MF_PAX_MPROTECT;
47920+ retval = -EINVAL;
47921+ }
47922+
47923+ if ((*flags & MF_PAX_EMUTRAMP)
47924+
47925+#ifdef CONFIG_PAX_EMUTRAMP
47926+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
47927+#endif
47928+
47929+ )
47930+ {
47931+ *flags &= ~MF_PAX_EMUTRAMP;
47932+ retval = -EINVAL;
47933+ }
47934+
47935+ return retval;
47936+}
47937+
47938+EXPORT_SYMBOL(pax_check_flags);
47939+
47940+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
47941+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
47942+{
47943+ struct task_struct *tsk = current;
47944+ struct mm_struct *mm = current->mm;
47945+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
47946+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
47947+ char *path_exec = NULL;
47948+ char *path_fault = NULL;
47949+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
47950+ siginfo_t info = { };
47951+
47952+ if (buffer_exec && buffer_fault) {
47953+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
47954+
47955+ down_read(&mm->mmap_sem);
47956+ vma = mm->mmap;
47957+ while (vma && (!vma_exec || !vma_fault)) {
47958+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
47959+ vma_exec = vma;
47960+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
47961+ vma_fault = vma;
47962+ vma = vma->vm_next;
47963+ }
47964+ if (vma_exec) {
47965+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
47966+ if (IS_ERR(path_exec))
47967+ path_exec = "<path too long>";
47968+ else {
47969+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
47970+ if (path_exec) {
47971+ *path_exec = 0;
47972+ path_exec = buffer_exec;
47973+ } else
47974+ path_exec = "<path too long>";
47975+ }
47976+ }
47977+ if (vma_fault) {
47978+ start = vma_fault->vm_start;
47979+ end = vma_fault->vm_end;
47980+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
47981+ if (vma_fault->vm_file) {
47982+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
47983+ if (IS_ERR(path_fault))
47984+ path_fault = "<path too long>";
47985+ else {
47986+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
47987+ if (path_fault) {
47988+ *path_fault = 0;
47989+ path_fault = buffer_fault;
47990+ } else
47991+ path_fault = "<path too long>";
47992+ }
47993+ } else
47994+ path_fault = "<anonymous mapping>";
47995+ }
47996+ up_read(&mm->mmap_sem);
47997+ }
47998+ if (tsk->signal->curr_ip)
47999+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
48000+ else
48001+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
48002+ 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),
48003+ from_kuid(&init_user_ns, task_uid(tsk)), from_kuid(&init_user_ns, task_euid(tsk)), pc, sp);
48004+ free_page((unsigned long)buffer_exec);
48005+ free_page((unsigned long)buffer_fault);
48006+ pax_report_insns(regs, pc, sp);
48007+ info.si_signo = SIGKILL;
48008+ info.si_errno = 0;
48009+ info.si_code = SI_KERNEL;
48010+ info.si_pid = 0;
48011+ info.si_uid = 0;
48012+ do_coredump(&info);
48013+}
48014+#endif
48015+
48016+#ifdef CONFIG_PAX_REFCOUNT
48017+void pax_report_refcount_overflow(struct pt_regs *regs)
48018+{
48019+ if (current->signal->curr_ip)
48020+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
48021+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
48022+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
48023+ else
48024+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
48025+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
48026+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
48027+ show_regs(regs);
48028+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
48029+}
48030+#endif
48031+
48032+#ifdef CONFIG_PAX_USERCOPY
48033+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
48034+static noinline int check_stack_object(const void *obj, unsigned long len)
48035+{
48036+ const void * const stack = task_stack_page(current);
48037+ const void * const stackend = stack + THREAD_SIZE;
48038+
48039+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
48040+ const void *frame = NULL;
48041+ const void *oldframe;
48042+#endif
48043+
48044+ if (obj + len < obj)
48045+ return -1;
48046+
48047+ if (obj + len <= stack || stackend <= obj)
48048+ return 0;
48049+
48050+ if (obj < stack || stackend < obj + len)
48051+ return -1;
48052+
48053+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
48054+ oldframe = __builtin_frame_address(1);
48055+ if (oldframe)
48056+ frame = __builtin_frame_address(2);
48057+ /*
48058+ low ----------------------------------------------> high
48059+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
48060+ ^----------------^
48061+ allow copies only within here
48062+ */
48063+ while (stack <= frame && frame < stackend) {
48064+ /* if obj + len extends past the last frame, this
48065+ check won't pass and the next frame will be 0,
48066+ causing us to bail out and correctly report
48067+ the copy as invalid
48068+ */
48069+ if (obj + len <= frame)
48070+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
48071+ oldframe = frame;
48072+ frame = *(const void * const *)frame;
48073+ }
48074+ return -1;
48075+#else
48076+ return 1;
48077+#endif
48078+}
48079+
48080+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
48081+{
48082+ if (current->signal->curr_ip)
48083+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
48084+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
48085+ else
48086+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
48087+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
48088+ dump_stack();
48089+ gr_handle_kernel_exploit();
48090+ do_group_exit(SIGKILL);
48091+}
48092+#endif
48093+
48094+void __check_object_size(const void *ptr, unsigned long n, bool to)
48095+{
48096+
48097+#ifdef CONFIG_PAX_USERCOPY
48098+ const char *type;
48099+
48100+ if (!n)
48101+ return;
48102+
48103+ type = check_heap_object(ptr, n);
48104+ if (!type) {
48105+ if (check_stack_object(ptr, n) != -1)
48106+ return;
48107+ type = "<process stack>";
48108+ }
48109+
48110+ pax_report_usercopy(ptr, n, to, type);
48111+#endif
48112+
48113+}
48114+EXPORT_SYMBOL(__check_object_size);
48115+
48116+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
48117+void pax_track_stack(void)
48118+{
48119+ unsigned long sp = (unsigned long)&sp;
48120+ if (sp < current_thread_info()->lowest_stack &&
48121+ sp > (unsigned long)task_stack_page(current))
48122+ current_thread_info()->lowest_stack = sp;
48123+}
48124+EXPORT_SYMBOL(pax_track_stack);
48125+#endif
48126+
48127+#ifdef CONFIG_PAX_SIZE_OVERFLOW
48128+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
48129+{
48130+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
48131+ dump_stack();
48132+ do_group_exit(SIGKILL);
48133+}
48134+EXPORT_SYMBOL(report_size_overflow);
48135+#endif
48136diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
48137index 2616d0e..2ffdec9 100644
48138--- a/fs/ext2/balloc.c
48139+++ b/fs/ext2/balloc.c
48140@@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
48141
48142 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
48143 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
48144- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
48145+ if (free_blocks < root_blocks + 1 &&
48146 !uid_eq(sbi->s_resuid, current_fsuid()) &&
48147 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
48148- !in_group_p (sbi->s_resgid))) {
48149+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
48150 return 0;
48151 }
48152 return 1;
48153diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
48154index 22548f5..41521d8 100644
48155--- a/fs/ext3/balloc.c
48156+++ b/fs/ext3/balloc.c
48157@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
48158
48159 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
48160 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
48161- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
48162+ if (free_blocks < root_blocks + 1 &&
48163 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
48164 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
48165- !in_group_p (sbi->s_resgid))) {
48166+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
48167 return 0;
48168 }
48169 return 1;
48170diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
48171index cf18217..8f6b9c3 100644
48172--- a/fs/ext4/balloc.c
48173+++ b/fs/ext4/balloc.c
48174@@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
48175 /* Hm, nope. Are (enough) root reserved clusters available? */
48176 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
48177 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
48178- capable(CAP_SYS_RESOURCE) ||
48179- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
48180+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
48181+ capable_nolog(CAP_SYS_RESOURCE)) {
48182
48183 if (free_clusters >= (nclusters + dirty_clusters))
48184 return 1;
48185diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
48186index 8462eb3..4a71af6 100644
48187--- a/fs/ext4/ext4.h
48188+++ b/fs/ext4/ext4.h
48189@@ -1265,19 +1265,19 @@ struct ext4_sb_info {
48190 unsigned long s_mb_last_start;
48191
48192 /* stats for buddy allocator */
48193- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
48194- atomic_t s_bal_success; /* we found long enough chunks */
48195- atomic_t s_bal_allocated; /* in blocks */
48196- atomic_t s_bal_ex_scanned; /* total extents scanned */
48197- atomic_t s_bal_goals; /* goal hits */
48198- atomic_t s_bal_breaks; /* too long searches */
48199- atomic_t s_bal_2orders; /* 2^order hits */
48200+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
48201+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
48202+ atomic_unchecked_t s_bal_allocated; /* in blocks */
48203+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
48204+ atomic_unchecked_t s_bal_goals; /* goal hits */
48205+ atomic_unchecked_t s_bal_breaks; /* too long searches */
48206+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
48207 spinlock_t s_bal_lock;
48208 unsigned long s_mb_buddies_generated;
48209 unsigned long long s_mb_generation_time;
48210- atomic_t s_mb_lost_chunks;
48211- atomic_t s_mb_preallocated;
48212- atomic_t s_mb_discarded;
48213+ atomic_unchecked_t s_mb_lost_chunks;
48214+ atomic_unchecked_t s_mb_preallocated;
48215+ atomic_unchecked_t s_mb_discarded;
48216 atomic_t s_lock_busy;
48217
48218 /* locality groups */
48219diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
48220index 1bf6fe7..1a5bdef 100644
48221--- a/fs/ext4/mballoc.c
48222+++ b/fs/ext4/mballoc.c
48223@@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
48224 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
48225
48226 if (EXT4_SB(sb)->s_mb_stats)
48227- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
48228+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
48229
48230 break;
48231 }
48232@@ -2044,7 +2044,7 @@ repeat:
48233 ac->ac_status = AC_STATUS_CONTINUE;
48234 ac->ac_flags |= EXT4_MB_HINT_FIRST;
48235 cr = 3;
48236- atomic_inc(&sbi->s_mb_lost_chunks);
48237+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
48238 goto repeat;
48239 }
48240 }
48241@@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
48242 if (sbi->s_mb_stats) {
48243 ext4_msg(sb, KERN_INFO,
48244 "mballoc: %u blocks %u reqs (%u success)",
48245- atomic_read(&sbi->s_bal_allocated),
48246- atomic_read(&sbi->s_bal_reqs),
48247- atomic_read(&sbi->s_bal_success));
48248+ atomic_read_unchecked(&sbi->s_bal_allocated),
48249+ atomic_read_unchecked(&sbi->s_bal_reqs),
48250+ atomic_read_unchecked(&sbi->s_bal_success));
48251 ext4_msg(sb, KERN_INFO,
48252 "mballoc: %u extents scanned, %u goal hits, "
48253 "%u 2^N hits, %u breaks, %u lost",
48254- atomic_read(&sbi->s_bal_ex_scanned),
48255- atomic_read(&sbi->s_bal_goals),
48256- atomic_read(&sbi->s_bal_2orders),
48257- atomic_read(&sbi->s_bal_breaks),
48258- atomic_read(&sbi->s_mb_lost_chunks));
48259+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
48260+ atomic_read_unchecked(&sbi->s_bal_goals),
48261+ atomic_read_unchecked(&sbi->s_bal_2orders),
48262+ atomic_read_unchecked(&sbi->s_bal_breaks),
48263+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
48264 ext4_msg(sb, KERN_INFO,
48265 "mballoc: %lu generated and it took %Lu",
48266 sbi->s_mb_buddies_generated,
48267 sbi->s_mb_generation_time);
48268 ext4_msg(sb, KERN_INFO,
48269 "mballoc: %u preallocated, %u discarded",
48270- atomic_read(&sbi->s_mb_preallocated),
48271- atomic_read(&sbi->s_mb_discarded));
48272+ atomic_read_unchecked(&sbi->s_mb_preallocated),
48273+ atomic_read_unchecked(&sbi->s_mb_discarded));
48274 }
48275
48276 free_percpu(sbi->s_locality_groups);
48277@@ -3060,16 +3060,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
48278 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
48279
48280 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
48281- atomic_inc(&sbi->s_bal_reqs);
48282- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
48283+ atomic_inc_unchecked(&sbi->s_bal_reqs);
48284+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
48285 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
48286- atomic_inc(&sbi->s_bal_success);
48287- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
48288+ atomic_inc_unchecked(&sbi->s_bal_success);
48289+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
48290 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
48291 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
48292- atomic_inc(&sbi->s_bal_goals);
48293+ atomic_inc_unchecked(&sbi->s_bal_goals);
48294 if (ac->ac_found > sbi->s_mb_max_to_scan)
48295- atomic_inc(&sbi->s_bal_breaks);
48296+ atomic_inc_unchecked(&sbi->s_bal_breaks);
48297 }
48298
48299 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
48300@@ -3469,7 +3469,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
48301 trace_ext4_mb_new_inode_pa(ac, pa);
48302
48303 ext4_mb_use_inode_pa(ac, pa);
48304- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
48305+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
48306
48307 ei = EXT4_I(ac->ac_inode);
48308 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
48309@@ -3529,7 +3529,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
48310 trace_ext4_mb_new_group_pa(ac, pa);
48311
48312 ext4_mb_use_group_pa(ac, pa);
48313- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
48314+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
48315
48316 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
48317 lg = ac->ac_lg;
48318@@ -3618,7 +3618,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
48319 * from the bitmap and continue.
48320 */
48321 }
48322- atomic_add(free, &sbi->s_mb_discarded);
48323+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
48324
48325 return err;
48326 }
48327@@ -3636,7 +3636,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
48328 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
48329 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
48330 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
48331- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
48332+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
48333 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
48334
48335 return 0;
48336diff --git a/fs/fcntl.c b/fs/fcntl.c
48337index 71a600a..20d87b1 100644
48338--- a/fs/fcntl.c
48339+++ b/fs/fcntl.c
48340@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
48341 if (err)
48342 return err;
48343
48344+ if (gr_handle_chroot_fowner(pid, type))
48345+ return -ENOENT;
48346+ if (gr_check_protected_task_fowner(pid, type))
48347+ return -EACCES;
48348+
48349 f_modown(filp, pid, type, force);
48350 return 0;
48351 }
48352diff --git a/fs/fhandle.c b/fs/fhandle.c
48353index 999ff5c..41f4109 100644
48354--- a/fs/fhandle.c
48355+++ b/fs/fhandle.c
48356@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
48357 } else
48358 retval = 0;
48359 /* copy the mount id */
48360- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
48361- sizeof(*mnt_id)) ||
48362+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
48363 copy_to_user(ufh, handle,
48364 sizeof(struct file_handle) + handle_bytes))
48365 retval = -EFAULT;
48366diff --git a/fs/fifo.c b/fs/fifo.c
48367index cf6f434..3d7942c 100644
48368--- a/fs/fifo.c
48369+++ b/fs/fifo.c
48370@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
48371 */
48372 filp->f_op = &read_pipefifo_fops;
48373 pipe->r_counter++;
48374- if (pipe->readers++ == 0)
48375+ if (atomic_inc_return(&pipe->readers) == 1)
48376 wake_up_partner(inode);
48377
48378- if (!pipe->writers) {
48379+ if (!atomic_read(&pipe->writers)) {
48380 if ((filp->f_flags & O_NONBLOCK)) {
48381 /* suppress POLLHUP until we have
48382 * seen a writer */
48383@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
48384 * errno=ENXIO when there is no process reading the FIFO.
48385 */
48386 ret = -ENXIO;
48387- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
48388+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
48389 goto err;
48390
48391 filp->f_op = &write_pipefifo_fops;
48392 pipe->w_counter++;
48393- if (!pipe->writers++)
48394+ if (atomic_inc_return(&pipe->writers) == 1)
48395 wake_up_partner(inode);
48396
48397- if (!pipe->readers) {
48398+ if (!atomic_read(&pipe->readers)) {
48399 if (wait_for_partner(inode, &pipe->r_counter))
48400 goto err_wr;
48401 }
48402@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
48403 */
48404 filp->f_op = &rdwr_pipefifo_fops;
48405
48406- pipe->readers++;
48407- pipe->writers++;
48408+ atomic_inc(&pipe->readers);
48409+ atomic_inc(&pipe->writers);
48410 pipe->r_counter++;
48411 pipe->w_counter++;
48412- if (pipe->readers == 1 || pipe->writers == 1)
48413+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
48414 wake_up_partner(inode);
48415 break;
48416
48417@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
48418 return 0;
48419
48420 err_rd:
48421- if (!--pipe->readers)
48422+ if (atomic_dec_and_test(&pipe->readers))
48423 wake_up_interruptible(&pipe->wait);
48424 ret = -ERESTARTSYS;
48425 goto err;
48426
48427 err_wr:
48428- if (!--pipe->writers)
48429+ if (atomic_dec_and_test(&pipe->writers))
48430 wake_up_interruptible(&pipe->wait);
48431 ret = -ERESTARTSYS;
48432 goto err;
48433
48434 err:
48435- if (!pipe->readers && !pipe->writers)
48436+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
48437 free_pipe_info(inode);
48438
48439 err_nocleanup:
48440diff --git a/fs/file.c b/fs/file.c
48441index 2b3570b..c57924b 100644
48442--- a/fs/file.c
48443+++ b/fs/file.c
48444@@ -16,6 +16,7 @@
48445 #include <linux/slab.h>
48446 #include <linux/vmalloc.h>
48447 #include <linux/file.h>
48448+#include <linux/security.h>
48449 #include <linux/fdtable.h>
48450 #include <linux/bitops.h>
48451 #include <linux/interrupt.h>
48452@@ -892,6 +893,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
48453 if (!file)
48454 return __close_fd(files, fd);
48455
48456+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
48457 if (fd >= rlimit(RLIMIT_NOFILE))
48458 return -EBADF;
48459
48460@@ -918,6 +920,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
48461 if (unlikely(oldfd == newfd))
48462 return -EINVAL;
48463
48464+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
48465 if (newfd >= rlimit(RLIMIT_NOFILE))
48466 return -EBADF;
48467
48468@@ -973,6 +976,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
48469 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
48470 {
48471 int err;
48472+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
48473 if (from >= rlimit(RLIMIT_NOFILE))
48474 return -EINVAL;
48475 err = alloc_fd(from, flags);
48476diff --git a/fs/filesystems.c b/fs/filesystems.c
48477index da165f6..3671bdb 100644
48478--- a/fs/filesystems.c
48479+++ b/fs/filesystems.c
48480@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
48481 int len = dot ? dot - name : strlen(name);
48482
48483 fs = __get_fs_type(name, len);
48484+
48485+#ifdef CONFIG_GRKERNSEC_MODHARDEN
48486+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
48487+#else
48488 if (!fs && (request_module("%.*s", len, name) == 0))
48489+#endif
48490 fs = __get_fs_type(name, len);
48491
48492 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
48493diff --git a/fs/fs_struct.c b/fs/fs_struct.c
48494index fe6ca58..65318cf 100644
48495--- a/fs/fs_struct.c
48496+++ b/fs/fs_struct.c
48497@@ -4,6 +4,7 @@
48498 #include <linux/path.h>
48499 #include <linux/slab.h>
48500 #include <linux/fs_struct.h>
48501+#include <linux/grsecurity.h>
48502 #include "internal.h"
48503
48504 /*
48505@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
48506 write_seqcount_begin(&fs->seq);
48507 old_root = fs->root;
48508 fs->root = *path;
48509+ gr_set_chroot_entries(current, path);
48510 write_seqcount_end(&fs->seq);
48511 spin_unlock(&fs->lock);
48512 if (old_root.dentry)
48513@@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
48514 return 1;
48515 }
48516
48517+static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
48518+{
48519+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
48520+ return 0;
48521+ *p = *new;
48522+
48523+ /* This function is only called from pivot_root(). Leave our
48524+ gr_chroot_dentry and is_chrooted flags as-is, so that a
48525+ pivoted root isn't treated as a chroot
48526+ */
48527+ //gr_set_chroot_entries(task, new);
48528+
48529+ return 1;
48530+}
48531+
48532 void chroot_fs_refs(struct path *old_root, struct path *new_root)
48533 {
48534 struct task_struct *g, *p;
48535@@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
48536 int hits = 0;
48537 spin_lock(&fs->lock);
48538 write_seqcount_begin(&fs->seq);
48539- hits += replace_path(&fs->root, old_root, new_root);
48540+ hits += replace_root_path(p, &fs->root, old_root, new_root);
48541 hits += replace_path(&fs->pwd, old_root, new_root);
48542 write_seqcount_end(&fs->seq);
48543 while (hits--) {
48544@@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
48545 task_lock(tsk);
48546 spin_lock(&fs->lock);
48547 tsk->fs = NULL;
48548- kill = !--fs->users;
48549+ gr_clear_chroot_entries(tsk);
48550+ kill = !atomic_dec_return(&fs->users);
48551 spin_unlock(&fs->lock);
48552 task_unlock(tsk);
48553 if (kill)
48554@@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
48555 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
48556 /* We don't need to lock fs - think why ;-) */
48557 if (fs) {
48558- fs->users = 1;
48559+ atomic_set(&fs->users, 1);
48560 fs->in_exec = 0;
48561 spin_lock_init(&fs->lock);
48562 seqcount_init(&fs->seq);
48563@@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
48564 spin_lock(&old->lock);
48565 fs->root = old->root;
48566 path_get(&fs->root);
48567+ /* instead of calling gr_set_chroot_entries here,
48568+ we call it from every caller of this function
48569+ */
48570 fs->pwd = old->pwd;
48571 path_get(&fs->pwd);
48572 spin_unlock(&old->lock);
48573@@ -139,8 +160,9 @@ int unshare_fs_struct(void)
48574
48575 task_lock(current);
48576 spin_lock(&fs->lock);
48577- kill = !--fs->users;
48578+ kill = !atomic_dec_return(&fs->users);
48579 current->fs = new_fs;
48580+ gr_set_chroot_entries(current, &new_fs->root);
48581 spin_unlock(&fs->lock);
48582 task_unlock(current);
48583
48584@@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
48585
48586 int current_umask(void)
48587 {
48588- return current->fs->umask;
48589+ return current->fs->umask | gr_acl_umask();
48590 }
48591 EXPORT_SYMBOL(current_umask);
48592
48593 /* to be mentioned only in INIT_TASK */
48594 struct fs_struct init_fs = {
48595- .users = 1,
48596+ .users = ATOMIC_INIT(1),
48597 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
48598 .seq = SEQCNT_ZERO,
48599 .umask = 0022,
48600diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
48601index 8dcb114..b1072e2 100644
48602--- a/fs/fscache/cookie.c
48603+++ b/fs/fscache/cookie.c
48604@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
48605 parent ? (char *) parent->def->name : "<no-parent>",
48606 def->name, netfs_data);
48607
48608- fscache_stat(&fscache_n_acquires);
48609+ fscache_stat_unchecked(&fscache_n_acquires);
48610
48611 /* if there's no parent cookie, then we don't create one here either */
48612 if (!parent) {
48613- fscache_stat(&fscache_n_acquires_null);
48614+ fscache_stat_unchecked(&fscache_n_acquires_null);
48615 _leave(" [no parent]");
48616 return NULL;
48617 }
48618@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
48619 /* allocate and initialise a cookie */
48620 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
48621 if (!cookie) {
48622- fscache_stat(&fscache_n_acquires_oom);
48623+ fscache_stat_unchecked(&fscache_n_acquires_oom);
48624 _leave(" [ENOMEM]");
48625 return NULL;
48626 }
48627@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
48628
48629 switch (cookie->def->type) {
48630 case FSCACHE_COOKIE_TYPE_INDEX:
48631- fscache_stat(&fscache_n_cookie_index);
48632+ fscache_stat_unchecked(&fscache_n_cookie_index);
48633 break;
48634 case FSCACHE_COOKIE_TYPE_DATAFILE:
48635- fscache_stat(&fscache_n_cookie_data);
48636+ fscache_stat_unchecked(&fscache_n_cookie_data);
48637 break;
48638 default:
48639- fscache_stat(&fscache_n_cookie_special);
48640+ fscache_stat_unchecked(&fscache_n_cookie_special);
48641 break;
48642 }
48643
48644@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
48645 if (fscache_acquire_non_index_cookie(cookie) < 0) {
48646 atomic_dec(&parent->n_children);
48647 __fscache_cookie_put(cookie);
48648- fscache_stat(&fscache_n_acquires_nobufs);
48649+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
48650 _leave(" = NULL");
48651 return NULL;
48652 }
48653 }
48654
48655- fscache_stat(&fscache_n_acquires_ok);
48656+ fscache_stat_unchecked(&fscache_n_acquires_ok);
48657 _leave(" = %p", cookie);
48658 return cookie;
48659 }
48660@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
48661 cache = fscache_select_cache_for_object(cookie->parent);
48662 if (!cache) {
48663 up_read(&fscache_addremove_sem);
48664- fscache_stat(&fscache_n_acquires_no_cache);
48665+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
48666 _leave(" = -ENOMEDIUM [no cache]");
48667 return -ENOMEDIUM;
48668 }
48669@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
48670 object = cache->ops->alloc_object(cache, cookie);
48671 fscache_stat_d(&fscache_n_cop_alloc_object);
48672 if (IS_ERR(object)) {
48673- fscache_stat(&fscache_n_object_no_alloc);
48674+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
48675 ret = PTR_ERR(object);
48676 goto error;
48677 }
48678
48679- fscache_stat(&fscache_n_object_alloc);
48680+ fscache_stat_unchecked(&fscache_n_object_alloc);
48681
48682 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
48683
48684@@ -378,7 +378,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
48685
48686 _enter("{%s}", cookie->def->name);
48687
48688- fscache_stat(&fscache_n_invalidates);
48689+ fscache_stat_unchecked(&fscache_n_invalidates);
48690
48691 /* Only permit invalidation of data files. Invalidating an index will
48692 * require the caller to release all its attachments to the tree rooted
48693@@ -437,10 +437,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
48694 struct fscache_object *object;
48695 struct hlist_node *_p;
48696
48697- fscache_stat(&fscache_n_updates);
48698+ fscache_stat_unchecked(&fscache_n_updates);
48699
48700 if (!cookie) {
48701- fscache_stat(&fscache_n_updates_null);
48702+ fscache_stat_unchecked(&fscache_n_updates_null);
48703 _leave(" [no cookie]");
48704 return;
48705 }
48706@@ -474,12 +474,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
48707 struct fscache_object *object;
48708 unsigned long event;
48709
48710- fscache_stat(&fscache_n_relinquishes);
48711+ fscache_stat_unchecked(&fscache_n_relinquishes);
48712 if (retire)
48713- fscache_stat(&fscache_n_relinquishes_retire);
48714+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
48715
48716 if (!cookie) {
48717- fscache_stat(&fscache_n_relinquishes_null);
48718+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
48719 _leave(" [no cookie]");
48720 return;
48721 }
48722@@ -495,7 +495,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
48723
48724 /* wait for the cookie to finish being instantiated (or to fail) */
48725 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
48726- fscache_stat(&fscache_n_relinquishes_waitcrt);
48727+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
48728 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
48729 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
48730 }
48731diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
48732index ee38fef..0a326d4 100644
48733--- a/fs/fscache/internal.h
48734+++ b/fs/fscache/internal.h
48735@@ -148,101 +148,101 @@ extern void fscache_proc_cleanup(void);
48736 * stats.c
48737 */
48738 #ifdef CONFIG_FSCACHE_STATS
48739-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
48740-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
48741+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
48742+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
48743
48744-extern atomic_t fscache_n_op_pend;
48745-extern atomic_t fscache_n_op_run;
48746-extern atomic_t fscache_n_op_enqueue;
48747-extern atomic_t fscache_n_op_deferred_release;
48748-extern atomic_t fscache_n_op_release;
48749-extern atomic_t fscache_n_op_gc;
48750-extern atomic_t fscache_n_op_cancelled;
48751-extern atomic_t fscache_n_op_rejected;
48752+extern atomic_unchecked_t fscache_n_op_pend;
48753+extern atomic_unchecked_t fscache_n_op_run;
48754+extern atomic_unchecked_t fscache_n_op_enqueue;
48755+extern atomic_unchecked_t fscache_n_op_deferred_release;
48756+extern atomic_unchecked_t fscache_n_op_release;
48757+extern atomic_unchecked_t fscache_n_op_gc;
48758+extern atomic_unchecked_t fscache_n_op_cancelled;
48759+extern atomic_unchecked_t fscache_n_op_rejected;
48760
48761-extern atomic_t fscache_n_attr_changed;
48762-extern atomic_t fscache_n_attr_changed_ok;
48763-extern atomic_t fscache_n_attr_changed_nobufs;
48764-extern atomic_t fscache_n_attr_changed_nomem;
48765-extern atomic_t fscache_n_attr_changed_calls;
48766+extern atomic_unchecked_t fscache_n_attr_changed;
48767+extern atomic_unchecked_t fscache_n_attr_changed_ok;
48768+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
48769+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
48770+extern atomic_unchecked_t fscache_n_attr_changed_calls;
48771
48772-extern atomic_t fscache_n_allocs;
48773-extern atomic_t fscache_n_allocs_ok;
48774-extern atomic_t fscache_n_allocs_wait;
48775-extern atomic_t fscache_n_allocs_nobufs;
48776-extern atomic_t fscache_n_allocs_intr;
48777-extern atomic_t fscache_n_allocs_object_dead;
48778-extern atomic_t fscache_n_alloc_ops;
48779-extern atomic_t fscache_n_alloc_op_waits;
48780+extern atomic_unchecked_t fscache_n_allocs;
48781+extern atomic_unchecked_t fscache_n_allocs_ok;
48782+extern atomic_unchecked_t fscache_n_allocs_wait;
48783+extern atomic_unchecked_t fscache_n_allocs_nobufs;
48784+extern atomic_unchecked_t fscache_n_allocs_intr;
48785+extern atomic_unchecked_t fscache_n_allocs_object_dead;
48786+extern atomic_unchecked_t fscache_n_alloc_ops;
48787+extern atomic_unchecked_t fscache_n_alloc_op_waits;
48788
48789-extern atomic_t fscache_n_retrievals;
48790-extern atomic_t fscache_n_retrievals_ok;
48791-extern atomic_t fscache_n_retrievals_wait;
48792-extern atomic_t fscache_n_retrievals_nodata;
48793-extern atomic_t fscache_n_retrievals_nobufs;
48794-extern atomic_t fscache_n_retrievals_intr;
48795-extern atomic_t fscache_n_retrievals_nomem;
48796-extern atomic_t fscache_n_retrievals_object_dead;
48797-extern atomic_t fscache_n_retrieval_ops;
48798-extern atomic_t fscache_n_retrieval_op_waits;
48799+extern atomic_unchecked_t fscache_n_retrievals;
48800+extern atomic_unchecked_t fscache_n_retrievals_ok;
48801+extern atomic_unchecked_t fscache_n_retrievals_wait;
48802+extern atomic_unchecked_t fscache_n_retrievals_nodata;
48803+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
48804+extern atomic_unchecked_t fscache_n_retrievals_intr;
48805+extern atomic_unchecked_t fscache_n_retrievals_nomem;
48806+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
48807+extern atomic_unchecked_t fscache_n_retrieval_ops;
48808+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
48809
48810-extern atomic_t fscache_n_stores;
48811-extern atomic_t fscache_n_stores_ok;
48812-extern atomic_t fscache_n_stores_again;
48813-extern atomic_t fscache_n_stores_nobufs;
48814-extern atomic_t fscache_n_stores_oom;
48815-extern atomic_t fscache_n_store_ops;
48816-extern atomic_t fscache_n_store_calls;
48817-extern atomic_t fscache_n_store_pages;
48818-extern atomic_t fscache_n_store_radix_deletes;
48819-extern atomic_t fscache_n_store_pages_over_limit;
48820+extern atomic_unchecked_t fscache_n_stores;
48821+extern atomic_unchecked_t fscache_n_stores_ok;
48822+extern atomic_unchecked_t fscache_n_stores_again;
48823+extern atomic_unchecked_t fscache_n_stores_nobufs;
48824+extern atomic_unchecked_t fscache_n_stores_oom;
48825+extern atomic_unchecked_t fscache_n_store_ops;
48826+extern atomic_unchecked_t fscache_n_store_calls;
48827+extern atomic_unchecked_t fscache_n_store_pages;
48828+extern atomic_unchecked_t fscache_n_store_radix_deletes;
48829+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
48830
48831-extern atomic_t fscache_n_store_vmscan_not_storing;
48832-extern atomic_t fscache_n_store_vmscan_gone;
48833-extern atomic_t fscache_n_store_vmscan_busy;
48834-extern atomic_t fscache_n_store_vmscan_cancelled;
48835-extern atomic_t fscache_n_store_vmscan_wait;
48836+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
48837+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
48838+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
48839+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
48840+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
48841
48842-extern atomic_t fscache_n_marks;
48843-extern atomic_t fscache_n_uncaches;
48844+extern atomic_unchecked_t fscache_n_marks;
48845+extern atomic_unchecked_t fscache_n_uncaches;
48846
48847-extern atomic_t fscache_n_acquires;
48848-extern atomic_t fscache_n_acquires_null;
48849-extern atomic_t fscache_n_acquires_no_cache;
48850-extern atomic_t fscache_n_acquires_ok;
48851-extern atomic_t fscache_n_acquires_nobufs;
48852-extern atomic_t fscache_n_acquires_oom;
48853+extern atomic_unchecked_t fscache_n_acquires;
48854+extern atomic_unchecked_t fscache_n_acquires_null;
48855+extern atomic_unchecked_t fscache_n_acquires_no_cache;
48856+extern atomic_unchecked_t fscache_n_acquires_ok;
48857+extern atomic_unchecked_t fscache_n_acquires_nobufs;
48858+extern atomic_unchecked_t fscache_n_acquires_oom;
48859
48860-extern atomic_t fscache_n_invalidates;
48861-extern atomic_t fscache_n_invalidates_run;
48862+extern atomic_unchecked_t fscache_n_invalidates;
48863+extern atomic_unchecked_t fscache_n_invalidates_run;
48864
48865-extern atomic_t fscache_n_updates;
48866-extern atomic_t fscache_n_updates_null;
48867-extern atomic_t fscache_n_updates_run;
48868+extern atomic_unchecked_t fscache_n_updates;
48869+extern atomic_unchecked_t fscache_n_updates_null;
48870+extern atomic_unchecked_t fscache_n_updates_run;
48871
48872-extern atomic_t fscache_n_relinquishes;
48873-extern atomic_t fscache_n_relinquishes_null;
48874-extern atomic_t fscache_n_relinquishes_waitcrt;
48875-extern atomic_t fscache_n_relinquishes_retire;
48876+extern atomic_unchecked_t fscache_n_relinquishes;
48877+extern atomic_unchecked_t fscache_n_relinquishes_null;
48878+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
48879+extern atomic_unchecked_t fscache_n_relinquishes_retire;
48880
48881-extern atomic_t fscache_n_cookie_index;
48882-extern atomic_t fscache_n_cookie_data;
48883-extern atomic_t fscache_n_cookie_special;
48884+extern atomic_unchecked_t fscache_n_cookie_index;
48885+extern atomic_unchecked_t fscache_n_cookie_data;
48886+extern atomic_unchecked_t fscache_n_cookie_special;
48887
48888-extern atomic_t fscache_n_object_alloc;
48889-extern atomic_t fscache_n_object_no_alloc;
48890-extern atomic_t fscache_n_object_lookups;
48891-extern atomic_t fscache_n_object_lookups_negative;
48892-extern atomic_t fscache_n_object_lookups_positive;
48893-extern atomic_t fscache_n_object_lookups_timed_out;
48894-extern atomic_t fscache_n_object_created;
48895-extern atomic_t fscache_n_object_avail;
48896-extern atomic_t fscache_n_object_dead;
48897+extern atomic_unchecked_t fscache_n_object_alloc;
48898+extern atomic_unchecked_t fscache_n_object_no_alloc;
48899+extern atomic_unchecked_t fscache_n_object_lookups;
48900+extern atomic_unchecked_t fscache_n_object_lookups_negative;
48901+extern atomic_unchecked_t fscache_n_object_lookups_positive;
48902+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
48903+extern atomic_unchecked_t fscache_n_object_created;
48904+extern atomic_unchecked_t fscache_n_object_avail;
48905+extern atomic_unchecked_t fscache_n_object_dead;
48906
48907-extern atomic_t fscache_n_checkaux_none;
48908-extern atomic_t fscache_n_checkaux_okay;
48909-extern atomic_t fscache_n_checkaux_update;
48910-extern atomic_t fscache_n_checkaux_obsolete;
48911+extern atomic_unchecked_t fscache_n_checkaux_none;
48912+extern atomic_unchecked_t fscache_n_checkaux_okay;
48913+extern atomic_unchecked_t fscache_n_checkaux_update;
48914+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
48915
48916 extern atomic_t fscache_n_cop_alloc_object;
48917 extern atomic_t fscache_n_cop_lookup_object;
48918@@ -267,6 +267,11 @@ static inline void fscache_stat(atomic_t *stat)
48919 atomic_inc(stat);
48920 }
48921
48922+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
48923+{
48924+ atomic_inc_unchecked(stat);
48925+}
48926+
48927 static inline void fscache_stat_d(atomic_t *stat)
48928 {
48929 atomic_dec(stat);
48930@@ -279,6 +284,7 @@ extern const struct file_operations fscache_stats_fops;
48931
48932 #define __fscache_stat(stat) (NULL)
48933 #define fscache_stat(stat) do {} while (0)
48934+#define fscache_stat_unchecked(stat) do {} while (0)
48935 #define fscache_stat_d(stat) do {} while (0)
48936 #endif
48937
48938diff --git a/fs/fscache/object.c b/fs/fscache/object.c
48939index 50d41c1..10ee117 100644
48940--- a/fs/fscache/object.c
48941+++ b/fs/fscache/object.c
48942@@ -143,7 +143,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48943 /* Invalidate an object on disk */
48944 case FSCACHE_OBJECT_INVALIDATING:
48945 clear_bit(FSCACHE_OBJECT_EV_INVALIDATE, &object->events);
48946- fscache_stat(&fscache_n_invalidates_run);
48947+ fscache_stat_unchecked(&fscache_n_invalidates_run);
48948 fscache_stat(&fscache_n_cop_invalidate_object);
48949 fscache_invalidate_object(object);
48950 fscache_stat_d(&fscache_n_cop_invalidate_object);
48951@@ -153,7 +153,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48952 /* update the object metadata on disk */
48953 case FSCACHE_OBJECT_UPDATING:
48954 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
48955- fscache_stat(&fscache_n_updates_run);
48956+ fscache_stat_unchecked(&fscache_n_updates_run);
48957 fscache_stat(&fscache_n_cop_update_object);
48958 object->cache->ops->update_object(object);
48959 fscache_stat_d(&fscache_n_cop_update_object);
48960@@ -242,7 +242,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48961 spin_lock(&object->lock);
48962 object->state = FSCACHE_OBJECT_DEAD;
48963 spin_unlock(&object->lock);
48964- fscache_stat(&fscache_n_object_dead);
48965+ fscache_stat_unchecked(&fscache_n_object_dead);
48966 goto terminal_transit;
48967
48968 /* handle the parent cache of this object being withdrawn from
48969@@ -257,7 +257,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48970 spin_lock(&object->lock);
48971 object->state = FSCACHE_OBJECT_DEAD;
48972 spin_unlock(&object->lock);
48973- fscache_stat(&fscache_n_object_dead);
48974+ fscache_stat_unchecked(&fscache_n_object_dead);
48975 goto terminal_transit;
48976
48977 /* complain about the object being woken up once it is
48978@@ -495,7 +495,7 @@ static void fscache_lookup_object(struct fscache_object *object)
48979 parent->cookie->def->name, cookie->def->name,
48980 object->cache->tag->name);
48981
48982- fscache_stat(&fscache_n_object_lookups);
48983+ fscache_stat_unchecked(&fscache_n_object_lookups);
48984 fscache_stat(&fscache_n_cop_lookup_object);
48985 ret = object->cache->ops->lookup_object(object);
48986 fscache_stat_d(&fscache_n_cop_lookup_object);
48987@@ -506,7 +506,7 @@ static void fscache_lookup_object(struct fscache_object *object)
48988 if (ret == -ETIMEDOUT) {
48989 /* probably stuck behind another object, so move this one to
48990 * the back of the queue */
48991- fscache_stat(&fscache_n_object_lookups_timed_out);
48992+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
48993 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
48994 }
48995
48996@@ -529,7 +529,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
48997
48998 spin_lock(&object->lock);
48999 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
49000- fscache_stat(&fscache_n_object_lookups_negative);
49001+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
49002
49003 /* transit here to allow write requests to begin stacking up
49004 * and read requests to begin returning ENODATA */
49005@@ -575,7 +575,7 @@ void fscache_obtained_object(struct fscache_object *object)
49006 * result, in which case there may be data available */
49007 spin_lock(&object->lock);
49008 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
49009- fscache_stat(&fscache_n_object_lookups_positive);
49010+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
49011
49012 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
49013
49014@@ -589,7 +589,7 @@ void fscache_obtained_object(struct fscache_object *object)
49015 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
49016 } else {
49017 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
49018- fscache_stat(&fscache_n_object_created);
49019+ fscache_stat_unchecked(&fscache_n_object_created);
49020
49021 object->state = FSCACHE_OBJECT_AVAILABLE;
49022 spin_unlock(&object->lock);
49023@@ -634,7 +634,7 @@ static void fscache_object_available(struct fscache_object *object)
49024 fscache_enqueue_dependents(object);
49025
49026 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
49027- fscache_stat(&fscache_n_object_avail);
49028+ fscache_stat_unchecked(&fscache_n_object_avail);
49029
49030 _leave("");
49031 }
49032@@ -894,7 +894,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
49033 enum fscache_checkaux result;
49034
49035 if (!object->cookie->def->check_aux) {
49036- fscache_stat(&fscache_n_checkaux_none);
49037+ fscache_stat_unchecked(&fscache_n_checkaux_none);
49038 return FSCACHE_CHECKAUX_OKAY;
49039 }
49040
49041@@ -903,17 +903,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
49042 switch (result) {
49043 /* entry okay as is */
49044 case FSCACHE_CHECKAUX_OKAY:
49045- fscache_stat(&fscache_n_checkaux_okay);
49046+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
49047 break;
49048
49049 /* entry requires update */
49050 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
49051- fscache_stat(&fscache_n_checkaux_update);
49052+ fscache_stat_unchecked(&fscache_n_checkaux_update);
49053 break;
49054
49055 /* entry requires deletion */
49056 case FSCACHE_CHECKAUX_OBSOLETE:
49057- fscache_stat(&fscache_n_checkaux_obsolete);
49058+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
49059 break;
49060
49061 default:
49062diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
49063index 762a9ec..2023284 100644
49064--- a/fs/fscache/operation.c
49065+++ b/fs/fscache/operation.c
49066@@ -17,7 +17,7 @@
49067 #include <linux/slab.h>
49068 #include "internal.h"
49069
49070-atomic_t fscache_op_debug_id;
49071+atomic_unchecked_t fscache_op_debug_id;
49072 EXPORT_SYMBOL(fscache_op_debug_id);
49073
49074 /**
49075@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
49076 ASSERTCMP(atomic_read(&op->usage), >, 0);
49077 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
49078
49079- fscache_stat(&fscache_n_op_enqueue);
49080+ fscache_stat_unchecked(&fscache_n_op_enqueue);
49081 switch (op->flags & FSCACHE_OP_TYPE) {
49082 case FSCACHE_OP_ASYNC:
49083 _debug("queue async");
49084@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
49085 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
49086 if (op->processor)
49087 fscache_enqueue_operation(op);
49088- fscache_stat(&fscache_n_op_run);
49089+ fscache_stat_unchecked(&fscache_n_op_run);
49090 }
49091
49092 /*
49093@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
49094 if (object->n_in_progress > 0) {
49095 atomic_inc(&op->usage);
49096 list_add_tail(&op->pend_link, &object->pending_ops);
49097- fscache_stat(&fscache_n_op_pend);
49098+ fscache_stat_unchecked(&fscache_n_op_pend);
49099 } else if (!list_empty(&object->pending_ops)) {
49100 atomic_inc(&op->usage);
49101 list_add_tail(&op->pend_link, &object->pending_ops);
49102- fscache_stat(&fscache_n_op_pend);
49103+ fscache_stat_unchecked(&fscache_n_op_pend);
49104 fscache_start_operations(object);
49105 } else {
49106 ASSERTCMP(object->n_in_progress, ==, 0);
49107@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
49108 object->n_exclusive++; /* reads and writes must wait */
49109 atomic_inc(&op->usage);
49110 list_add_tail(&op->pend_link, &object->pending_ops);
49111- fscache_stat(&fscache_n_op_pend);
49112+ fscache_stat_unchecked(&fscache_n_op_pend);
49113 ret = 0;
49114 } else {
49115 /* If we're in any other state, there must have been an I/O
49116@@ -215,11 +215,11 @@ int fscache_submit_op(struct fscache_object *object,
49117 if (object->n_exclusive > 0) {
49118 atomic_inc(&op->usage);
49119 list_add_tail(&op->pend_link, &object->pending_ops);
49120- fscache_stat(&fscache_n_op_pend);
49121+ fscache_stat_unchecked(&fscache_n_op_pend);
49122 } else if (!list_empty(&object->pending_ops)) {
49123 atomic_inc(&op->usage);
49124 list_add_tail(&op->pend_link, &object->pending_ops);
49125- fscache_stat(&fscache_n_op_pend);
49126+ fscache_stat_unchecked(&fscache_n_op_pend);
49127 fscache_start_operations(object);
49128 } else {
49129 ASSERTCMP(object->n_exclusive, ==, 0);
49130@@ -231,12 +231,12 @@ int fscache_submit_op(struct fscache_object *object,
49131 object->n_ops++;
49132 atomic_inc(&op->usage);
49133 list_add_tail(&op->pend_link, &object->pending_ops);
49134- fscache_stat(&fscache_n_op_pend);
49135+ fscache_stat_unchecked(&fscache_n_op_pend);
49136 ret = 0;
49137 } else if (object->state == FSCACHE_OBJECT_DYING ||
49138 object->state == FSCACHE_OBJECT_LC_DYING ||
49139 object->state == FSCACHE_OBJECT_WITHDRAWING) {
49140- fscache_stat(&fscache_n_op_rejected);
49141+ fscache_stat_unchecked(&fscache_n_op_rejected);
49142 op->state = FSCACHE_OP_ST_CANCELLED;
49143 ret = -ENOBUFS;
49144 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
49145@@ -315,7 +315,7 @@ int fscache_cancel_op(struct fscache_operation *op,
49146 ret = -EBUSY;
49147 if (op->state == FSCACHE_OP_ST_PENDING) {
49148 ASSERT(!list_empty(&op->pend_link));
49149- fscache_stat(&fscache_n_op_cancelled);
49150+ fscache_stat_unchecked(&fscache_n_op_cancelled);
49151 list_del_init(&op->pend_link);
49152 if (do_cancel)
49153 do_cancel(op);
49154@@ -347,7 +347,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
49155 while (!list_empty(&object->pending_ops)) {
49156 op = list_entry(object->pending_ops.next,
49157 struct fscache_operation, pend_link);
49158- fscache_stat(&fscache_n_op_cancelled);
49159+ fscache_stat_unchecked(&fscache_n_op_cancelled);
49160 list_del_init(&op->pend_link);
49161
49162 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
49163@@ -419,7 +419,7 @@ void fscache_put_operation(struct fscache_operation *op)
49164 op->state, ==, FSCACHE_OP_ST_CANCELLED);
49165 op->state = FSCACHE_OP_ST_DEAD;
49166
49167- fscache_stat(&fscache_n_op_release);
49168+ fscache_stat_unchecked(&fscache_n_op_release);
49169
49170 if (op->release) {
49171 op->release(op);
49172@@ -442,7 +442,7 @@ void fscache_put_operation(struct fscache_operation *op)
49173 * lock, and defer it otherwise */
49174 if (!spin_trylock(&object->lock)) {
49175 _debug("defer put");
49176- fscache_stat(&fscache_n_op_deferred_release);
49177+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
49178
49179 cache = object->cache;
49180 spin_lock(&cache->op_gc_list_lock);
49181@@ -495,7 +495,7 @@ void fscache_operation_gc(struct work_struct *work)
49182
49183 _debug("GC DEFERRED REL OBJ%x OP%x",
49184 object->debug_id, op->debug_id);
49185- fscache_stat(&fscache_n_op_gc);
49186+ fscache_stat_unchecked(&fscache_n_op_gc);
49187
49188 ASSERTCMP(atomic_read(&op->usage), ==, 0);
49189 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
49190diff --git a/fs/fscache/page.c b/fs/fscache/page.c
49191index ff000e5..c44ec6d 100644
49192--- a/fs/fscache/page.c
49193+++ b/fs/fscache/page.c
49194@@ -61,7 +61,7 @@ try_again:
49195 val = radix_tree_lookup(&cookie->stores, page->index);
49196 if (!val) {
49197 rcu_read_unlock();
49198- fscache_stat(&fscache_n_store_vmscan_not_storing);
49199+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
49200 __fscache_uncache_page(cookie, page);
49201 return true;
49202 }
49203@@ -91,11 +91,11 @@ try_again:
49204 spin_unlock(&cookie->stores_lock);
49205
49206 if (xpage) {
49207- fscache_stat(&fscache_n_store_vmscan_cancelled);
49208- fscache_stat(&fscache_n_store_radix_deletes);
49209+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
49210+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
49211 ASSERTCMP(xpage, ==, page);
49212 } else {
49213- fscache_stat(&fscache_n_store_vmscan_gone);
49214+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
49215 }
49216
49217 wake_up_bit(&cookie->flags, 0);
49218@@ -110,11 +110,11 @@ page_busy:
49219 * sleeping on memory allocation, so we may need to impose a timeout
49220 * too. */
49221 if (!(gfp & __GFP_WAIT)) {
49222- fscache_stat(&fscache_n_store_vmscan_busy);
49223+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
49224 return false;
49225 }
49226
49227- fscache_stat(&fscache_n_store_vmscan_wait);
49228+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
49229 __fscache_wait_on_page_write(cookie, page);
49230 gfp &= ~__GFP_WAIT;
49231 goto try_again;
49232@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
49233 FSCACHE_COOKIE_STORING_TAG);
49234 if (!radix_tree_tag_get(&cookie->stores, page->index,
49235 FSCACHE_COOKIE_PENDING_TAG)) {
49236- fscache_stat(&fscache_n_store_radix_deletes);
49237+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
49238 xpage = radix_tree_delete(&cookie->stores, page->index);
49239 }
49240 spin_unlock(&cookie->stores_lock);
49241@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
49242
49243 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
49244
49245- fscache_stat(&fscache_n_attr_changed_calls);
49246+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
49247
49248 if (fscache_object_is_active(object)) {
49249 fscache_stat(&fscache_n_cop_attr_changed);
49250@@ -187,11 +187,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
49251
49252 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
49253
49254- fscache_stat(&fscache_n_attr_changed);
49255+ fscache_stat_unchecked(&fscache_n_attr_changed);
49256
49257 op = kzalloc(sizeof(*op), GFP_KERNEL);
49258 if (!op) {
49259- fscache_stat(&fscache_n_attr_changed_nomem);
49260+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
49261 _leave(" = -ENOMEM");
49262 return -ENOMEM;
49263 }
49264@@ -209,7 +209,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
49265 if (fscache_submit_exclusive_op(object, op) < 0)
49266 goto nobufs;
49267 spin_unlock(&cookie->lock);
49268- fscache_stat(&fscache_n_attr_changed_ok);
49269+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
49270 fscache_put_operation(op);
49271 _leave(" = 0");
49272 return 0;
49273@@ -217,7 +217,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
49274 nobufs:
49275 spin_unlock(&cookie->lock);
49276 kfree(op);
49277- fscache_stat(&fscache_n_attr_changed_nobufs);
49278+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
49279 _leave(" = %d", -ENOBUFS);
49280 return -ENOBUFS;
49281 }
49282@@ -255,7 +255,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
49283 /* allocate a retrieval operation and attempt to submit it */
49284 op = kzalloc(sizeof(*op), GFP_NOIO);
49285 if (!op) {
49286- fscache_stat(&fscache_n_retrievals_nomem);
49287+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
49288 return NULL;
49289 }
49290
49291@@ -283,13 +283,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
49292 return 0;
49293 }
49294
49295- fscache_stat(&fscache_n_retrievals_wait);
49296+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
49297
49298 jif = jiffies;
49299 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
49300 fscache_wait_bit_interruptible,
49301 TASK_INTERRUPTIBLE) != 0) {
49302- fscache_stat(&fscache_n_retrievals_intr);
49303+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
49304 _leave(" = -ERESTARTSYS");
49305 return -ERESTARTSYS;
49306 }
49307@@ -318,8 +318,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
49308 */
49309 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
49310 struct fscache_retrieval *op,
49311- atomic_t *stat_op_waits,
49312- atomic_t *stat_object_dead)
49313+ atomic_unchecked_t *stat_op_waits,
49314+ atomic_unchecked_t *stat_object_dead)
49315 {
49316 int ret;
49317
49318@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
49319 goto check_if_dead;
49320
49321 _debug(">>> WT");
49322- fscache_stat(stat_op_waits);
49323+ fscache_stat_unchecked(stat_op_waits);
49324 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
49325 fscache_wait_bit_interruptible,
49326 TASK_INTERRUPTIBLE) != 0) {
49327@@ -344,14 +344,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
49328
49329 check_if_dead:
49330 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
49331- fscache_stat(stat_object_dead);
49332+ fscache_stat_unchecked(stat_object_dead);
49333 _leave(" = -ENOBUFS [cancelled]");
49334 return -ENOBUFS;
49335 }
49336 if (unlikely(fscache_object_is_dead(object))) {
49337 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
49338 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
49339- fscache_stat(stat_object_dead);
49340+ fscache_stat_unchecked(stat_object_dead);
49341 return -ENOBUFS;
49342 }
49343 return 0;
49344@@ -378,7 +378,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
49345
49346 _enter("%p,%p,,,", cookie, page);
49347
49348- fscache_stat(&fscache_n_retrievals);
49349+ fscache_stat_unchecked(&fscache_n_retrievals);
49350
49351 if (hlist_empty(&cookie->backing_objects))
49352 goto nobufs;
49353@@ -417,7 +417,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
49354 goto nobufs_unlock_dec;
49355 spin_unlock(&cookie->lock);
49356
49357- fscache_stat(&fscache_n_retrieval_ops);
49358+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
49359
49360 /* pin the netfs read context in case we need to do the actual netfs
49361 * read because we've encountered a cache read failure */
49362@@ -447,15 +447,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
49363
49364 error:
49365 if (ret == -ENOMEM)
49366- fscache_stat(&fscache_n_retrievals_nomem);
49367+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
49368 else if (ret == -ERESTARTSYS)
49369- fscache_stat(&fscache_n_retrievals_intr);
49370+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
49371 else if (ret == -ENODATA)
49372- fscache_stat(&fscache_n_retrievals_nodata);
49373+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
49374 else if (ret < 0)
49375- fscache_stat(&fscache_n_retrievals_nobufs);
49376+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49377 else
49378- fscache_stat(&fscache_n_retrievals_ok);
49379+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
49380
49381 fscache_put_retrieval(op);
49382 _leave(" = %d", ret);
49383@@ -467,7 +467,7 @@ nobufs_unlock:
49384 spin_unlock(&cookie->lock);
49385 kfree(op);
49386 nobufs:
49387- fscache_stat(&fscache_n_retrievals_nobufs);
49388+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49389 _leave(" = -ENOBUFS");
49390 return -ENOBUFS;
49391 }
49392@@ -505,7 +505,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
49393
49394 _enter("%p,,%d,,,", cookie, *nr_pages);
49395
49396- fscache_stat(&fscache_n_retrievals);
49397+ fscache_stat_unchecked(&fscache_n_retrievals);
49398
49399 if (hlist_empty(&cookie->backing_objects))
49400 goto nobufs;
49401@@ -541,7 +541,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
49402 goto nobufs_unlock_dec;
49403 spin_unlock(&cookie->lock);
49404
49405- fscache_stat(&fscache_n_retrieval_ops);
49406+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
49407
49408 /* pin the netfs read context in case we need to do the actual netfs
49409 * read because we've encountered a cache read failure */
49410@@ -571,15 +571,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
49411
49412 error:
49413 if (ret == -ENOMEM)
49414- fscache_stat(&fscache_n_retrievals_nomem);
49415+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
49416 else if (ret == -ERESTARTSYS)
49417- fscache_stat(&fscache_n_retrievals_intr);
49418+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
49419 else if (ret == -ENODATA)
49420- fscache_stat(&fscache_n_retrievals_nodata);
49421+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
49422 else if (ret < 0)
49423- fscache_stat(&fscache_n_retrievals_nobufs);
49424+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49425 else
49426- fscache_stat(&fscache_n_retrievals_ok);
49427+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
49428
49429 fscache_put_retrieval(op);
49430 _leave(" = %d", ret);
49431@@ -591,7 +591,7 @@ nobufs_unlock:
49432 spin_unlock(&cookie->lock);
49433 kfree(op);
49434 nobufs:
49435- fscache_stat(&fscache_n_retrievals_nobufs);
49436+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49437 _leave(" = -ENOBUFS");
49438 return -ENOBUFS;
49439 }
49440@@ -615,7 +615,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
49441
49442 _enter("%p,%p,,,", cookie, page);
49443
49444- fscache_stat(&fscache_n_allocs);
49445+ fscache_stat_unchecked(&fscache_n_allocs);
49446
49447 if (hlist_empty(&cookie->backing_objects))
49448 goto nobufs;
49449@@ -647,7 +647,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
49450 goto nobufs_unlock;
49451 spin_unlock(&cookie->lock);
49452
49453- fscache_stat(&fscache_n_alloc_ops);
49454+ fscache_stat_unchecked(&fscache_n_alloc_ops);
49455
49456 ret = fscache_wait_for_retrieval_activation(
49457 object, op,
49458@@ -663,11 +663,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
49459
49460 error:
49461 if (ret == -ERESTARTSYS)
49462- fscache_stat(&fscache_n_allocs_intr);
49463+ fscache_stat_unchecked(&fscache_n_allocs_intr);
49464 else if (ret < 0)
49465- fscache_stat(&fscache_n_allocs_nobufs);
49466+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
49467 else
49468- fscache_stat(&fscache_n_allocs_ok);
49469+ fscache_stat_unchecked(&fscache_n_allocs_ok);
49470
49471 fscache_put_retrieval(op);
49472 _leave(" = %d", ret);
49473@@ -677,7 +677,7 @@ nobufs_unlock:
49474 spin_unlock(&cookie->lock);
49475 kfree(op);
49476 nobufs:
49477- fscache_stat(&fscache_n_allocs_nobufs);
49478+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
49479 _leave(" = -ENOBUFS");
49480 return -ENOBUFS;
49481 }
49482@@ -736,7 +736,7 @@ static void fscache_write_op(struct fscache_operation *_op)
49483
49484 spin_lock(&cookie->stores_lock);
49485
49486- fscache_stat(&fscache_n_store_calls);
49487+ fscache_stat_unchecked(&fscache_n_store_calls);
49488
49489 /* find a page to store */
49490 page = NULL;
49491@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
49492 page = results[0];
49493 _debug("gang %d [%lx]", n, page->index);
49494 if (page->index > op->store_limit) {
49495- fscache_stat(&fscache_n_store_pages_over_limit);
49496+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
49497 goto superseded;
49498 }
49499
49500@@ -759,7 +759,7 @@ static void fscache_write_op(struct fscache_operation *_op)
49501 spin_unlock(&cookie->stores_lock);
49502 spin_unlock(&object->lock);
49503
49504- fscache_stat(&fscache_n_store_pages);
49505+ fscache_stat_unchecked(&fscache_n_store_pages);
49506 fscache_stat(&fscache_n_cop_write_page);
49507 ret = object->cache->ops->write_page(op, page);
49508 fscache_stat_d(&fscache_n_cop_write_page);
49509@@ -860,7 +860,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49510 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
49511 ASSERT(PageFsCache(page));
49512
49513- fscache_stat(&fscache_n_stores);
49514+ fscache_stat_unchecked(&fscache_n_stores);
49515
49516 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
49517 _leave(" = -ENOBUFS [invalidating]");
49518@@ -916,7 +916,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49519 spin_unlock(&cookie->stores_lock);
49520 spin_unlock(&object->lock);
49521
49522- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
49523+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
49524 op->store_limit = object->store_limit;
49525
49526 if (fscache_submit_op(object, &op->op) < 0)
49527@@ -924,8 +924,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49528
49529 spin_unlock(&cookie->lock);
49530 radix_tree_preload_end();
49531- fscache_stat(&fscache_n_store_ops);
49532- fscache_stat(&fscache_n_stores_ok);
49533+ fscache_stat_unchecked(&fscache_n_store_ops);
49534+ fscache_stat_unchecked(&fscache_n_stores_ok);
49535
49536 /* the work queue now carries its own ref on the object */
49537 fscache_put_operation(&op->op);
49538@@ -933,14 +933,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49539 return 0;
49540
49541 already_queued:
49542- fscache_stat(&fscache_n_stores_again);
49543+ fscache_stat_unchecked(&fscache_n_stores_again);
49544 already_pending:
49545 spin_unlock(&cookie->stores_lock);
49546 spin_unlock(&object->lock);
49547 spin_unlock(&cookie->lock);
49548 radix_tree_preload_end();
49549 kfree(op);
49550- fscache_stat(&fscache_n_stores_ok);
49551+ fscache_stat_unchecked(&fscache_n_stores_ok);
49552 _leave(" = 0");
49553 return 0;
49554
49555@@ -959,14 +959,14 @@ nobufs:
49556 spin_unlock(&cookie->lock);
49557 radix_tree_preload_end();
49558 kfree(op);
49559- fscache_stat(&fscache_n_stores_nobufs);
49560+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
49561 _leave(" = -ENOBUFS");
49562 return -ENOBUFS;
49563
49564 nomem_free:
49565 kfree(op);
49566 nomem:
49567- fscache_stat(&fscache_n_stores_oom);
49568+ fscache_stat_unchecked(&fscache_n_stores_oom);
49569 _leave(" = -ENOMEM");
49570 return -ENOMEM;
49571 }
49572@@ -984,7 +984,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
49573 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
49574 ASSERTCMP(page, !=, NULL);
49575
49576- fscache_stat(&fscache_n_uncaches);
49577+ fscache_stat_unchecked(&fscache_n_uncaches);
49578
49579 /* cache withdrawal may beat us to it */
49580 if (!PageFsCache(page))
49581@@ -1035,7 +1035,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
49582 struct fscache_cookie *cookie = op->op.object->cookie;
49583
49584 #ifdef CONFIG_FSCACHE_STATS
49585- atomic_inc(&fscache_n_marks);
49586+ atomic_inc_unchecked(&fscache_n_marks);
49587 #endif
49588
49589 _debug("- mark %p{%lx}", page, page->index);
49590diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
49591index 8179e8b..5072cc7 100644
49592--- a/fs/fscache/stats.c
49593+++ b/fs/fscache/stats.c
49594@@ -18,99 +18,99 @@
49595 /*
49596 * operation counters
49597 */
49598-atomic_t fscache_n_op_pend;
49599-atomic_t fscache_n_op_run;
49600-atomic_t fscache_n_op_enqueue;
49601-atomic_t fscache_n_op_requeue;
49602-atomic_t fscache_n_op_deferred_release;
49603-atomic_t fscache_n_op_release;
49604-atomic_t fscache_n_op_gc;
49605-atomic_t fscache_n_op_cancelled;
49606-atomic_t fscache_n_op_rejected;
49607+atomic_unchecked_t fscache_n_op_pend;
49608+atomic_unchecked_t fscache_n_op_run;
49609+atomic_unchecked_t fscache_n_op_enqueue;
49610+atomic_unchecked_t fscache_n_op_requeue;
49611+atomic_unchecked_t fscache_n_op_deferred_release;
49612+atomic_unchecked_t fscache_n_op_release;
49613+atomic_unchecked_t fscache_n_op_gc;
49614+atomic_unchecked_t fscache_n_op_cancelled;
49615+atomic_unchecked_t fscache_n_op_rejected;
49616
49617-atomic_t fscache_n_attr_changed;
49618-atomic_t fscache_n_attr_changed_ok;
49619-atomic_t fscache_n_attr_changed_nobufs;
49620-atomic_t fscache_n_attr_changed_nomem;
49621-atomic_t fscache_n_attr_changed_calls;
49622+atomic_unchecked_t fscache_n_attr_changed;
49623+atomic_unchecked_t fscache_n_attr_changed_ok;
49624+atomic_unchecked_t fscache_n_attr_changed_nobufs;
49625+atomic_unchecked_t fscache_n_attr_changed_nomem;
49626+atomic_unchecked_t fscache_n_attr_changed_calls;
49627
49628-atomic_t fscache_n_allocs;
49629-atomic_t fscache_n_allocs_ok;
49630-atomic_t fscache_n_allocs_wait;
49631-atomic_t fscache_n_allocs_nobufs;
49632-atomic_t fscache_n_allocs_intr;
49633-atomic_t fscache_n_allocs_object_dead;
49634-atomic_t fscache_n_alloc_ops;
49635-atomic_t fscache_n_alloc_op_waits;
49636+atomic_unchecked_t fscache_n_allocs;
49637+atomic_unchecked_t fscache_n_allocs_ok;
49638+atomic_unchecked_t fscache_n_allocs_wait;
49639+atomic_unchecked_t fscache_n_allocs_nobufs;
49640+atomic_unchecked_t fscache_n_allocs_intr;
49641+atomic_unchecked_t fscache_n_allocs_object_dead;
49642+atomic_unchecked_t fscache_n_alloc_ops;
49643+atomic_unchecked_t fscache_n_alloc_op_waits;
49644
49645-atomic_t fscache_n_retrievals;
49646-atomic_t fscache_n_retrievals_ok;
49647-atomic_t fscache_n_retrievals_wait;
49648-atomic_t fscache_n_retrievals_nodata;
49649-atomic_t fscache_n_retrievals_nobufs;
49650-atomic_t fscache_n_retrievals_intr;
49651-atomic_t fscache_n_retrievals_nomem;
49652-atomic_t fscache_n_retrievals_object_dead;
49653-atomic_t fscache_n_retrieval_ops;
49654-atomic_t fscache_n_retrieval_op_waits;
49655+atomic_unchecked_t fscache_n_retrievals;
49656+atomic_unchecked_t fscache_n_retrievals_ok;
49657+atomic_unchecked_t fscache_n_retrievals_wait;
49658+atomic_unchecked_t fscache_n_retrievals_nodata;
49659+atomic_unchecked_t fscache_n_retrievals_nobufs;
49660+atomic_unchecked_t fscache_n_retrievals_intr;
49661+atomic_unchecked_t fscache_n_retrievals_nomem;
49662+atomic_unchecked_t fscache_n_retrievals_object_dead;
49663+atomic_unchecked_t fscache_n_retrieval_ops;
49664+atomic_unchecked_t fscache_n_retrieval_op_waits;
49665
49666-atomic_t fscache_n_stores;
49667-atomic_t fscache_n_stores_ok;
49668-atomic_t fscache_n_stores_again;
49669-atomic_t fscache_n_stores_nobufs;
49670-atomic_t fscache_n_stores_oom;
49671-atomic_t fscache_n_store_ops;
49672-atomic_t fscache_n_store_calls;
49673-atomic_t fscache_n_store_pages;
49674-atomic_t fscache_n_store_radix_deletes;
49675-atomic_t fscache_n_store_pages_over_limit;
49676+atomic_unchecked_t fscache_n_stores;
49677+atomic_unchecked_t fscache_n_stores_ok;
49678+atomic_unchecked_t fscache_n_stores_again;
49679+atomic_unchecked_t fscache_n_stores_nobufs;
49680+atomic_unchecked_t fscache_n_stores_oom;
49681+atomic_unchecked_t fscache_n_store_ops;
49682+atomic_unchecked_t fscache_n_store_calls;
49683+atomic_unchecked_t fscache_n_store_pages;
49684+atomic_unchecked_t fscache_n_store_radix_deletes;
49685+atomic_unchecked_t fscache_n_store_pages_over_limit;
49686
49687-atomic_t fscache_n_store_vmscan_not_storing;
49688-atomic_t fscache_n_store_vmscan_gone;
49689-atomic_t fscache_n_store_vmscan_busy;
49690-atomic_t fscache_n_store_vmscan_cancelled;
49691-atomic_t fscache_n_store_vmscan_wait;
49692+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
49693+atomic_unchecked_t fscache_n_store_vmscan_gone;
49694+atomic_unchecked_t fscache_n_store_vmscan_busy;
49695+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
49696+atomic_unchecked_t fscache_n_store_vmscan_wait;
49697
49698-atomic_t fscache_n_marks;
49699-atomic_t fscache_n_uncaches;
49700+atomic_unchecked_t fscache_n_marks;
49701+atomic_unchecked_t fscache_n_uncaches;
49702
49703-atomic_t fscache_n_acquires;
49704-atomic_t fscache_n_acquires_null;
49705-atomic_t fscache_n_acquires_no_cache;
49706-atomic_t fscache_n_acquires_ok;
49707-atomic_t fscache_n_acquires_nobufs;
49708-atomic_t fscache_n_acquires_oom;
49709+atomic_unchecked_t fscache_n_acquires;
49710+atomic_unchecked_t fscache_n_acquires_null;
49711+atomic_unchecked_t fscache_n_acquires_no_cache;
49712+atomic_unchecked_t fscache_n_acquires_ok;
49713+atomic_unchecked_t fscache_n_acquires_nobufs;
49714+atomic_unchecked_t fscache_n_acquires_oom;
49715
49716-atomic_t fscache_n_invalidates;
49717-atomic_t fscache_n_invalidates_run;
49718+atomic_unchecked_t fscache_n_invalidates;
49719+atomic_unchecked_t fscache_n_invalidates_run;
49720
49721-atomic_t fscache_n_updates;
49722-atomic_t fscache_n_updates_null;
49723-atomic_t fscache_n_updates_run;
49724+atomic_unchecked_t fscache_n_updates;
49725+atomic_unchecked_t fscache_n_updates_null;
49726+atomic_unchecked_t fscache_n_updates_run;
49727
49728-atomic_t fscache_n_relinquishes;
49729-atomic_t fscache_n_relinquishes_null;
49730-atomic_t fscache_n_relinquishes_waitcrt;
49731-atomic_t fscache_n_relinquishes_retire;
49732+atomic_unchecked_t fscache_n_relinquishes;
49733+atomic_unchecked_t fscache_n_relinquishes_null;
49734+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
49735+atomic_unchecked_t fscache_n_relinquishes_retire;
49736
49737-atomic_t fscache_n_cookie_index;
49738-atomic_t fscache_n_cookie_data;
49739-atomic_t fscache_n_cookie_special;
49740+atomic_unchecked_t fscache_n_cookie_index;
49741+atomic_unchecked_t fscache_n_cookie_data;
49742+atomic_unchecked_t fscache_n_cookie_special;
49743
49744-atomic_t fscache_n_object_alloc;
49745-atomic_t fscache_n_object_no_alloc;
49746-atomic_t fscache_n_object_lookups;
49747-atomic_t fscache_n_object_lookups_negative;
49748-atomic_t fscache_n_object_lookups_positive;
49749-atomic_t fscache_n_object_lookups_timed_out;
49750-atomic_t fscache_n_object_created;
49751-atomic_t fscache_n_object_avail;
49752-atomic_t fscache_n_object_dead;
49753+atomic_unchecked_t fscache_n_object_alloc;
49754+atomic_unchecked_t fscache_n_object_no_alloc;
49755+atomic_unchecked_t fscache_n_object_lookups;
49756+atomic_unchecked_t fscache_n_object_lookups_negative;
49757+atomic_unchecked_t fscache_n_object_lookups_positive;
49758+atomic_unchecked_t fscache_n_object_lookups_timed_out;
49759+atomic_unchecked_t fscache_n_object_created;
49760+atomic_unchecked_t fscache_n_object_avail;
49761+atomic_unchecked_t fscache_n_object_dead;
49762
49763-atomic_t fscache_n_checkaux_none;
49764-atomic_t fscache_n_checkaux_okay;
49765-atomic_t fscache_n_checkaux_update;
49766-atomic_t fscache_n_checkaux_obsolete;
49767+atomic_unchecked_t fscache_n_checkaux_none;
49768+atomic_unchecked_t fscache_n_checkaux_okay;
49769+atomic_unchecked_t fscache_n_checkaux_update;
49770+atomic_unchecked_t fscache_n_checkaux_obsolete;
49771
49772 atomic_t fscache_n_cop_alloc_object;
49773 atomic_t fscache_n_cop_lookup_object;
49774@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
49775 seq_puts(m, "FS-Cache statistics\n");
49776
49777 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
49778- atomic_read(&fscache_n_cookie_index),
49779- atomic_read(&fscache_n_cookie_data),
49780- atomic_read(&fscache_n_cookie_special));
49781+ atomic_read_unchecked(&fscache_n_cookie_index),
49782+ atomic_read_unchecked(&fscache_n_cookie_data),
49783+ atomic_read_unchecked(&fscache_n_cookie_special));
49784
49785 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
49786- atomic_read(&fscache_n_object_alloc),
49787- atomic_read(&fscache_n_object_no_alloc),
49788- atomic_read(&fscache_n_object_avail),
49789- atomic_read(&fscache_n_object_dead));
49790+ atomic_read_unchecked(&fscache_n_object_alloc),
49791+ atomic_read_unchecked(&fscache_n_object_no_alloc),
49792+ atomic_read_unchecked(&fscache_n_object_avail),
49793+ atomic_read_unchecked(&fscache_n_object_dead));
49794 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
49795- atomic_read(&fscache_n_checkaux_none),
49796- atomic_read(&fscache_n_checkaux_okay),
49797- atomic_read(&fscache_n_checkaux_update),
49798- atomic_read(&fscache_n_checkaux_obsolete));
49799+ atomic_read_unchecked(&fscache_n_checkaux_none),
49800+ atomic_read_unchecked(&fscache_n_checkaux_okay),
49801+ atomic_read_unchecked(&fscache_n_checkaux_update),
49802+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
49803
49804 seq_printf(m, "Pages : mrk=%u unc=%u\n",
49805- atomic_read(&fscache_n_marks),
49806- atomic_read(&fscache_n_uncaches));
49807+ atomic_read_unchecked(&fscache_n_marks),
49808+ atomic_read_unchecked(&fscache_n_uncaches));
49809
49810 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
49811 " oom=%u\n",
49812- atomic_read(&fscache_n_acquires),
49813- atomic_read(&fscache_n_acquires_null),
49814- atomic_read(&fscache_n_acquires_no_cache),
49815- atomic_read(&fscache_n_acquires_ok),
49816- atomic_read(&fscache_n_acquires_nobufs),
49817- atomic_read(&fscache_n_acquires_oom));
49818+ atomic_read_unchecked(&fscache_n_acquires),
49819+ atomic_read_unchecked(&fscache_n_acquires_null),
49820+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
49821+ atomic_read_unchecked(&fscache_n_acquires_ok),
49822+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
49823+ atomic_read_unchecked(&fscache_n_acquires_oom));
49824
49825 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
49826- atomic_read(&fscache_n_object_lookups),
49827- atomic_read(&fscache_n_object_lookups_negative),
49828- atomic_read(&fscache_n_object_lookups_positive),
49829- atomic_read(&fscache_n_object_created),
49830- atomic_read(&fscache_n_object_lookups_timed_out));
49831+ atomic_read_unchecked(&fscache_n_object_lookups),
49832+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
49833+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
49834+ atomic_read_unchecked(&fscache_n_object_created),
49835+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
49836
49837 seq_printf(m, "Invals : n=%u run=%u\n",
49838- atomic_read(&fscache_n_invalidates),
49839- atomic_read(&fscache_n_invalidates_run));
49840+ atomic_read_unchecked(&fscache_n_invalidates),
49841+ atomic_read_unchecked(&fscache_n_invalidates_run));
49842
49843 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
49844- atomic_read(&fscache_n_updates),
49845- atomic_read(&fscache_n_updates_null),
49846- atomic_read(&fscache_n_updates_run));
49847+ atomic_read_unchecked(&fscache_n_updates),
49848+ atomic_read_unchecked(&fscache_n_updates_null),
49849+ atomic_read_unchecked(&fscache_n_updates_run));
49850
49851 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
49852- atomic_read(&fscache_n_relinquishes),
49853- atomic_read(&fscache_n_relinquishes_null),
49854- atomic_read(&fscache_n_relinquishes_waitcrt),
49855- atomic_read(&fscache_n_relinquishes_retire));
49856+ atomic_read_unchecked(&fscache_n_relinquishes),
49857+ atomic_read_unchecked(&fscache_n_relinquishes_null),
49858+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
49859+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
49860
49861 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
49862- atomic_read(&fscache_n_attr_changed),
49863- atomic_read(&fscache_n_attr_changed_ok),
49864- atomic_read(&fscache_n_attr_changed_nobufs),
49865- atomic_read(&fscache_n_attr_changed_nomem),
49866- atomic_read(&fscache_n_attr_changed_calls));
49867+ atomic_read_unchecked(&fscache_n_attr_changed),
49868+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
49869+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
49870+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
49871+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
49872
49873 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
49874- atomic_read(&fscache_n_allocs),
49875- atomic_read(&fscache_n_allocs_ok),
49876- atomic_read(&fscache_n_allocs_wait),
49877- atomic_read(&fscache_n_allocs_nobufs),
49878- atomic_read(&fscache_n_allocs_intr));
49879+ atomic_read_unchecked(&fscache_n_allocs),
49880+ atomic_read_unchecked(&fscache_n_allocs_ok),
49881+ atomic_read_unchecked(&fscache_n_allocs_wait),
49882+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
49883+ atomic_read_unchecked(&fscache_n_allocs_intr));
49884 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
49885- atomic_read(&fscache_n_alloc_ops),
49886- atomic_read(&fscache_n_alloc_op_waits),
49887- atomic_read(&fscache_n_allocs_object_dead));
49888+ atomic_read_unchecked(&fscache_n_alloc_ops),
49889+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
49890+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
49891
49892 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
49893 " int=%u oom=%u\n",
49894- atomic_read(&fscache_n_retrievals),
49895- atomic_read(&fscache_n_retrievals_ok),
49896- atomic_read(&fscache_n_retrievals_wait),
49897- atomic_read(&fscache_n_retrievals_nodata),
49898- atomic_read(&fscache_n_retrievals_nobufs),
49899- atomic_read(&fscache_n_retrievals_intr),
49900- atomic_read(&fscache_n_retrievals_nomem));
49901+ atomic_read_unchecked(&fscache_n_retrievals),
49902+ atomic_read_unchecked(&fscache_n_retrievals_ok),
49903+ atomic_read_unchecked(&fscache_n_retrievals_wait),
49904+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
49905+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
49906+ atomic_read_unchecked(&fscache_n_retrievals_intr),
49907+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
49908 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
49909- atomic_read(&fscache_n_retrieval_ops),
49910- atomic_read(&fscache_n_retrieval_op_waits),
49911- atomic_read(&fscache_n_retrievals_object_dead));
49912+ atomic_read_unchecked(&fscache_n_retrieval_ops),
49913+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
49914+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
49915
49916 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
49917- atomic_read(&fscache_n_stores),
49918- atomic_read(&fscache_n_stores_ok),
49919- atomic_read(&fscache_n_stores_again),
49920- atomic_read(&fscache_n_stores_nobufs),
49921- atomic_read(&fscache_n_stores_oom));
49922+ atomic_read_unchecked(&fscache_n_stores),
49923+ atomic_read_unchecked(&fscache_n_stores_ok),
49924+ atomic_read_unchecked(&fscache_n_stores_again),
49925+ atomic_read_unchecked(&fscache_n_stores_nobufs),
49926+ atomic_read_unchecked(&fscache_n_stores_oom));
49927 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
49928- atomic_read(&fscache_n_store_ops),
49929- atomic_read(&fscache_n_store_calls),
49930- atomic_read(&fscache_n_store_pages),
49931- atomic_read(&fscache_n_store_radix_deletes),
49932- atomic_read(&fscache_n_store_pages_over_limit));
49933+ atomic_read_unchecked(&fscache_n_store_ops),
49934+ atomic_read_unchecked(&fscache_n_store_calls),
49935+ atomic_read_unchecked(&fscache_n_store_pages),
49936+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
49937+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
49938
49939 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
49940- atomic_read(&fscache_n_store_vmscan_not_storing),
49941- atomic_read(&fscache_n_store_vmscan_gone),
49942- atomic_read(&fscache_n_store_vmscan_busy),
49943- atomic_read(&fscache_n_store_vmscan_cancelled),
49944- atomic_read(&fscache_n_store_vmscan_wait));
49945+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
49946+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
49947+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
49948+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
49949+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
49950
49951 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
49952- atomic_read(&fscache_n_op_pend),
49953- atomic_read(&fscache_n_op_run),
49954- atomic_read(&fscache_n_op_enqueue),
49955- atomic_read(&fscache_n_op_cancelled),
49956- atomic_read(&fscache_n_op_rejected));
49957+ atomic_read_unchecked(&fscache_n_op_pend),
49958+ atomic_read_unchecked(&fscache_n_op_run),
49959+ atomic_read_unchecked(&fscache_n_op_enqueue),
49960+ atomic_read_unchecked(&fscache_n_op_cancelled),
49961+ atomic_read_unchecked(&fscache_n_op_rejected));
49962 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
49963- atomic_read(&fscache_n_op_deferred_release),
49964- atomic_read(&fscache_n_op_release),
49965- atomic_read(&fscache_n_op_gc));
49966+ atomic_read_unchecked(&fscache_n_op_deferred_release),
49967+ atomic_read_unchecked(&fscache_n_op_release),
49968+ atomic_read_unchecked(&fscache_n_op_gc));
49969
49970 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
49971 atomic_read(&fscache_n_cop_alloc_object),
49972diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
49973index e397b67..b0d8709 100644
49974--- a/fs/fuse/cuse.c
49975+++ b/fs/fuse/cuse.c
49976@@ -593,10 +593,12 @@ static int __init cuse_init(void)
49977 INIT_LIST_HEAD(&cuse_conntbl[i]);
49978
49979 /* inherit and extend fuse_dev_operations */
49980- cuse_channel_fops = fuse_dev_operations;
49981- cuse_channel_fops.owner = THIS_MODULE;
49982- cuse_channel_fops.open = cuse_channel_open;
49983- cuse_channel_fops.release = cuse_channel_release;
49984+ pax_open_kernel();
49985+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
49986+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
49987+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
49988+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
49989+ pax_close_kernel();
49990
49991 cuse_class = class_create(THIS_MODULE, "cuse");
49992 if (IS_ERR(cuse_class))
49993diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
49994index e83351a..41e3c9c 100644
49995--- a/fs/fuse/dev.c
49996+++ b/fs/fuse/dev.c
49997@@ -1236,7 +1236,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
49998 ret = 0;
49999 pipe_lock(pipe);
50000
50001- if (!pipe->readers) {
50002+ if (!atomic_read(&pipe->readers)) {
50003 send_sig(SIGPIPE, current, 0);
50004 if (!ret)
50005 ret = -EPIPE;
50006diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
50007index b7c09f9..3eff736 100644
50008--- a/fs/fuse/dir.c
50009+++ b/fs/fuse/dir.c
50010@@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
50011 return link;
50012 }
50013
50014-static void free_link(char *link)
50015+static void free_link(const char *link)
50016 {
50017 if (!IS_ERR(link))
50018 free_page((unsigned long) link);
50019diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
50020index 2b6f569..fcb4d1f 100644
50021--- a/fs/gfs2/inode.c
50022+++ b/fs/gfs2/inode.c
50023@@ -1499,7 +1499,7 @@ out:
50024
50025 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
50026 {
50027- char *s = nd_get_link(nd);
50028+ const char *s = nd_get_link(nd);
50029 if (!IS_ERR(s))
50030 kfree(s);
50031 }
50032diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
50033index 78bde32..767e906 100644
50034--- a/fs/hugetlbfs/inode.c
50035+++ b/fs/hugetlbfs/inode.c
50036@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
50037 struct mm_struct *mm = current->mm;
50038 struct vm_area_struct *vma;
50039 struct hstate *h = hstate_file(file);
50040+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
50041 struct vm_unmapped_area_info info;
50042
50043 if (len & ~huge_page_mask(h))
50044@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
50045 return addr;
50046 }
50047
50048+#ifdef CONFIG_PAX_RANDMMAP
50049+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
50050+#endif
50051+
50052 if (addr) {
50053 addr = ALIGN(addr, huge_page_size(h));
50054 vma = find_vma(mm, addr);
50055- if (TASK_SIZE - len >= addr &&
50056- (!vma || addr + len <= vma->vm_start))
50057+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
50058 return addr;
50059 }
50060
50061 info.flags = 0;
50062 info.length = len;
50063 info.low_limit = TASK_UNMAPPED_BASE;
50064+
50065+#ifdef CONFIG_PAX_RANDMMAP
50066+ if (mm->pax_flags & MF_PAX_RANDMMAP)
50067+ info.low_limit += mm->delta_mmap;
50068+#endif
50069+
50070 info.high_limit = TASK_SIZE;
50071 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
50072 info.align_offset = 0;
50073@@ -897,7 +907,7 @@ static struct file_system_type hugetlbfs_fs_type = {
50074 .kill_sb = kill_litter_super,
50075 };
50076
50077-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
50078+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
50079
50080 static int can_do_hugetlb_shm(void)
50081 {
50082diff --git a/fs/inode.c b/fs/inode.c
50083index 14084b7..29af1d9 100644
50084--- a/fs/inode.c
50085+++ b/fs/inode.c
50086@@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
50087
50088 #ifdef CONFIG_SMP
50089 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
50090- static atomic_t shared_last_ino;
50091- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
50092+ static atomic_unchecked_t shared_last_ino;
50093+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
50094
50095 res = next - LAST_INO_BATCH;
50096 }
50097diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
50098index 4a6cf28..d3a29d3 100644
50099--- a/fs/jffs2/erase.c
50100+++ b/fs/jffs2/erase.c
50101@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
50102 struct jffs2_unknown_node marker = {
50103 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
50104 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
50105- .totlen = cpu_to_je32(c->cleanmarker_size)
50106+ .totlen = cpu_to_je32(c->cleanmarker_size),
50107+ .hdr_crc = cpu_to_je32(0)
50108 };
50109
50110 jffs2_prealloc_raw_node_refs(c, jeb, 1);
50111diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
50112index a6597d6..41b30ec 100644
50113--- a/fs/jffs2/wbuf.c
50114+++ b/fs/jffs2/wbuf.c
50115@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
50116 {
50117 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
50118 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
50119- .totlen = constant_cpu_to_je32(8)
50120+ .totlen = constant_cpu_to_je32(8),
50121+ .hdr_crc = constant_cpu_to_je32(0)
50122 };
50123
50124 /*
50125diff --git a/fs/jfs/super.c b/fs/jfs/super.c
50126index 1a543be..d803c40 100644
50127--- a/fs/jfs/super.c
50128+++ b/fs/jfs/super.c
50129@@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
50130
50131 jfs_inode_cachep =
50132 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
50133- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
50134+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
50135 init_once);
50136 if (jfs_inode_cachep == NULL)
50137 return -ENOMEM;
50138diff --git a/fs/libfs.c b/fs/libfs.c
50139index 916da8c..1588998 100644
50140--- a/fs/libfs.c
50141+++ b/fs/libfs.c
50142@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
50143
50144 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
50145 struct dentry *next;
50146+ char d_name[sizeof(next->d_iname)];
50147+ const unsigned char *name;
50148+
50149 next = list_entry(p, struct dentry, d_u.d_child);
50150 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
50151 if (!simple_positive(next)) {
50152@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
50153
50154 spin_unlock(&next->d_lock);
50155 spin_unlock(&dentry->d_lock);
50156- if (filldir(dirent, next->d_name.name,
50157+ name = next->d_name.name;
50158+ if (name == next->d_iname) {
50159+ memcpy(d_name, name, next->d_name.len);
50160+ name = d_name;
50161+ }
50162+ if (filldir(dirent, name,
50163 next->d_name.len, filp->f_pos,
50164 next->d_inode->i_ino,
50165 dt_type(next->d_inode)) < 0)
50166diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
50167index 54f9e6c..9ed908c 100644
50168--- a/fs/lockd/clntproc.c
50169+++ b/fs/lockd/clntproc.c
50170@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
50171 /*
50172 * Cookie counter for NLM requests
50173 */
50174-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
50175+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
50176
50177 void nlmclnt_next_cookie(struct nlm_cookie *c)
50178 {
50179- u32 cookie = atomic_inc_return(&nlm_cookie);
50180+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
50181
50182 memcpy(c->data, &cookie, 4);
50183 c->len=4;
50184diff --git a/fs/locks.c b/fs/locks.c
50185index a94e331..060bce3 100644
50186--- a/fs/locks.c
50187+++ b/fs/locks.c
50188@@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
50189 return;
50190
50191 if (filp->f_op && filp->f_op->flock) {
50192- struct file_lock fl = {
50193+ struct file_lock flock = {
50194 .fl_pid = current->tgid,
50195 .fl_file = filp,
50196 .fl_flags = FL_FLOCK,
50197 .fl_type = F_UNLCK,
50198 .fl_end = OFFSET_MAX,
50199 };
50200- filp->f_op->flock(filp, F_SETLKW, &fl);
50201- if (fl.fl_ops && fl.fl_ops->fl_release_private)
50202- fl.fl_ops->fl_release_private(&fl);
50203+ filp->f_op->flock(filp, F_SETLKW, &flock);
50204+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
50205+ flock.fl_ops->fl_release_private(&flock);
50206 }
50207
50208 lock_flocks();
50209diff --git a/fs/namei.c b/fs/namei.c
50210index 43a97ee..ff3f601 100644
50211--- a/fs/namei.c
50212+++ b/fs/namei.c
50213@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
50214 if (ret != -EACCES)
50215 return ret;
50216
50217+#ifdef CONFIG_GRKERNSEC
50218+ /* we'll block if we have to log due to a denied capability use */
50219+ if (mask & MAY_NOT_BLOCK)
50220+ return -ECHILD;
50221+#endif
50222+
50223 if (S_ISDIR(inode->i_mode)) {
50224 /* DACs are overridable for directories */
50225- if (inode_capable(inode, CAP_DAC_OVERRIDE))
50226- return 0;
50227 if (!(mask & MAY_WRITE))
50228- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
50229+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
50230+ inode_capable(inode, CAP_DAC_READ_SEARCH))
50231 return 0;
50232+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
50233+ return 0;
50234 return -EACCES;
50235 }
50236 /*
50237+ * Searching includes executable on directories, else just read.
50238+ */
50239+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
50240+ if (mask == MAY_READ)
50241+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
50242+ inode_capable(inode, CAP_DAC_READ_SEARCH))
50243+ return 0;
50244+
50245+ /*
50246 * Read/write DACs are always overridable.
50247 * Executable DACs are overridable when there is
50248 * at least one exec bit set.
50249@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
50250 if (inode_capable(inode, CAP_DAC_OVERRIDE))
50251 return 0;
50252
50253- /*
50254- * Searching includes executable on directories, else just read.
50255- */
50256- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
50257- if (mask == MAY_READ)
50258- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
50259- return 0;
50260-
50261 return -EACCES;
50262 }
50263
50264@@ -826,7 +834,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
50265 {
50266 struct dentry *dentry = link->dentry;
50267 int error;
50268- char *s;
50269+ const char *s;
50270
50271 BUG_ON(nd->flags & LOOKUP_RCU);
50272
50273@@ -847,6 +855,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
50274 if (error)
50275 goto out_put_nd_path;
50276
50277+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
50278+ dentry->d_inode, dentry, nd->path.mnt)) {
50279+ error = -EACCES;
50280+ goto out_put_nd_path;
50281+ }
50282+
50283 nd->last_type = LAST_BIND;
50284 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
50285 error = PTR_ERR(*p);
50286@@ -1596,6 +1610,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
50287 break;
50288 res = walk_component(nd, path, &nd->last,
50289 nd->last_type, LOOKUP_FOLLOW);
50290+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
50291+ res = -EACCES;
50292 put_link(nd, &link, cookie);
50293 } while (res > 0);
50294
50295@@ -1694,7 +1710,7 @@ EXPORT_SYMBOL(full_name_hash);
50296 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
50297 {
50298 unsigned long a, b, adata, bdata, mask, hash, len;
50299- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
50300+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
50301
50302 hash = a = 0;
50303 len = -sizeof(unsigned long);
50304@@ -1979,6 +1995,8 @@ static int path_lookupat(int dfd, const char *name,
50305 if (err)
50306 break;
50307 err = lookup_last(nd, &path);
50308+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
50309+ err = -EACCES;
50310 put_link(nd, &link, cookie);
50311 }
50312 }
50313@@ -1986,6 +2004,21 @@ static int path_lookupat(int dfd, const char *name,
50314 if (!err)
50315 err = complete_walk(nd);
50316
50317+ if (!(nd->flags & LOOKUP_PARENT)) {
50318+#ifdef CONFIG_GRKERNSEC
50319+ if (flags & LOOKUP_RCU) {
50320+ if (!err)
50321+ path_put(&nd->path);
50322+ err = -ECHILD;
50323+ } else
50324+#endif
50325+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
50326+ if (!err)
50327+ path_put(&nd->path);
50328+ err = -ENOENT;
50329+ }
50330+ }
50331+
50332 if (!err && nd->flags & LOOKUP_DIRECTORY) {
50333 if (!nd->inode->i_op->lookup) {
50334 path_put(&nd->path);
50335@@ -2013,8 +2046,17 @@ static int filename_lookup(int dfd, struct filename *name,
50336 retval = path_lookupat(dfd, name->name,
50337 flags | LOOKUP_REVAL, nd);
50338
50339- if (likely(!retval))
50340+ if (likely(!retval)) {
50341+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
50342+#ifdef CONFIG_GRKERNSEC
50343+ if (flags & LOOKUP_RCU)
50344+ return -ECHILD;
50345+#endif
50346+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
50347+ return -ENOENT;
50348+ }
50349 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
50350+ }
50351 return retval;
50352 }
50353
50354@@ -2392,6 +2434,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
50355 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
50356 return -EPERM;
50357
50358+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
50359+ return -EPERM;
50360+ if (gr_handle_rawio(inode))
50361+ return -EPERM;
50362+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
50363+ return -EACCES;
50364+
50365 return 0;
50366 }
50367
50368@@ -2613,7 +2662,7 @@ looked_up:
50369 * cleared otherwise prior to returning.
50370 */
50371 static int lookup_open(struct nameidata *nd, struct path *path,
50372- struct file *file,
50373+ struct path *link, struct file *file,
50374 const struct open_flags *op,
50375 bool got_write, int *opened)
50376 {
50377@@ -2648,6 +2697,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
50378 /* Negative dentry, just create the file */
50379 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
50380 umode_t mode = op->mode;
50381+
50382+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
50383+ error = -EACCES;
50384+ goto out_dput;
50385+ }
50386+
50387+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
50388+ error = -EACCES;
50389+ goto out_dput;
50390+ }
50391+
50392 if (!IS_POSIXACL(dir->d_inode))
50393 mode &= ~current_umask();
50394 /*
50395@@ -2669,6 +2729,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
50396 nd->flags & LOOKUP_EXCL);
50397 if (error)
50398 goto out_dput;
50399+ else
50400+ gr_handle_create(dentry, nd->path.mnt);
50401 }
50402 out_no_open:
50403 path->dentry = dentry;
50404@@ -2683,7 +2745,7 @@ out_dput:
50405 /*
50406 * Handle the last step of open()
50407 */
50408-static int do_last(struct nameidata *nd, struct path *path,
50409+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
50410 struct file *file, const struct open_flags *op,
50411 int *opened, struct filename *name)
50412 {
50413@@ -2712,16 +2774,44 @@ static int do_last(struct nameidata *nd, struct path *path,
50414 error = complete_walk(nd);
50415 if (error)
50416 return error;
50417+#ifdef CONFIG_GRKERNSEC
50418+ if (nd->flags & LOOKUP_RCU) {
50419+ error = -ECHILD;
50420+ goto out;
50421+ }
50422+#endif
50423+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
50424+ error = -ENOENT;
50425+ goto out;
50426+ }
50427 audit_inode(name, nd->path.dentry, 0);
50428 if (open_flag & O_CREAT) {
50429 error = -EISDIR;
50430 goto out;
50431 }
50432+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
50433+ error = -EACCES;
50434+ goto out;
50435+ }
50436 goto finish_open;
50437 case LAST_BIND:
50438 error = complete_walk(nd);
50439 if (error)
50440 return error;
50441+#ifdef CONFIG_GRKERNSEC
50442+ if (nd->flags & LOOKUP_RCU) {
50443+ error = -ECHILD;
50444+ goto out;
50445+ }
50446+#endif
50447+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
50448+ error = -ENOENT;
50449+ goto out;
50450+ }
50451+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
50452+ error = -EACCES;
50453+ goto out;
50454+ }
50455 audit_inode(name, dir, 0);
50456 goto finish_open;
50457 }
50458@@ -2770,7 +2860,7 @@ retry_lookup:
50459 */
50460 }
50461 mutex_lock(&dir->d_inode->i_mutex);
50462- error = lookup_open(nd, path, file, op, got_write, opened);
50463+ error = lookup_open(nd, path, link, file, op, got_write, opened);
50464 mutex_unlock(&dir->d_inode->i_mutex);
50465
50466 if (error <= 0) {
50467@@ -2794,11 +2884,28 @@ retry_lookup:
50468 goto finish_open_created;
50469 }
50470
50471+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
50472+ error = -ENOENT;
50473+ goto exit_dput;
50474+ }
50475+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
50476+ error = -EACCES;
50477+ goto exit_dput;
50478+ }
50479+
50480 /*
50481 * create/update audit record if it already exists.
50482 */
50483- if (path->dentry->d_inode)
50484+ if (path->dentry->d_inode) {
50485+ /* only check if O_CREAT is specified, all other checks need to go
50486+ into may_open */
50487+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
50488+ error = -EACCES;
50489+ goto exit_dput;
50490+ }
50491+
50492 audit_inode(name, path->dentry, 0);
50493+ }
50494
50495 /*
50496 * If atomic_open() acquired write access it is dropped now due to
50497@@ -2839,6 +2946,11 @@ finish_lookup:
50498 }
50499 }
50500 BUG_ON(inode != path->dentry->d_inode);
50501+ /* if we're resolving a symlink to another symlink */
50502+ if (link && gr_handle_symlink_owner(link, inode)) {
50503+ error = -EACCES;
50504+ goto out;
50505+ }
50506 return 1;
50507 }
50508
50509@@ -2848,7 +2960,6 @@ finish_lookup:
50510 save_parent.dentry = nd->path.dentry;
50511 save_parent.mnt = mntget(path->mnt);
50512 nd->path.dentry = path->dentry;
50513-
50514 }
50515 nd->inode = inode;
50516 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
50517@@ -2857,6 +2968,22 @@ finish_lookup:
50518 path_put(&save_parent);
50519 return error;
50520 }
50521+
50522+#ifdef CONFIG_GRKERNSEC
50523+ if (nd->flags & LOOKUP_RCU) {
50524+ error = -ECHILD;
50525+ goto out;
50526+ }
50527+#endif
50528+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
50529+ error = -ENOENT;
50530+ goto out;
50531+ }
50532+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
50533+ error = -EACCES;
50534+ goto out;
50535+ }
50536+
50537 error = -EISDIR;
50538 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
50539 goto out;
50540@@ -2955,7 +3082,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
50541 if (unlikely(error))
50542 goto out;
50543
50544- error = do_last(nd, &path, file, op, &opened, pathname);
50545+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
50546 while (unlikely(error > 0)) { /* trailing symlink */
50547 struct path link = path;
50548 void *cookie;
50549@@ -2973,7 +3100,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
50550 error = follow_link(&link, nd, &cookie);
50551 if (unlikely(error))
50552 break;
50553- error = do_last(nd, &path, file, op, &opened, pathname);
50554+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
50555 put_link(nd, &link, cookie);
50556 }
50557 out:
50558@@ -3073,8 +3200,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
50559 goto unlock;
50560
50561 error = -EEXIST;
50562- if (dentry->d_inode)
50563+ if (dentry->d_inode) {
50564+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
50565+ error = -ENOENT;
50566+ }
50567 goto fail;
50568+ }
50569 /*
50570 * Special case - lookup gave negative, but... we had foo/bar/
50571 * From the vfs_mknod() POV we just have a negative dentry -
50572@@ -3126,6 +3257,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
50573 }
50574 EXPORT_SYMBOL(user_path_create);
50575
50576+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, int is_dir)
50577+{
50578+ struct filename *tmp = getname(pathname);
50579+ struct dentry *res;
50580+ if (IS_ERR(tmp))
50581+ return ERR_CAST(tmp);
50582+ res = kern_path_create(dfd, tmp->name, path, is_dir);
50583+ if (IS_ERR(res))
50584+ putname(tmp);
50585+ else
50586+ *to = tmp;
50587+ return res;
50588+}
50589+
50590 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
50591 {
50592 int error = may_create(dir, dentry);
50593@@ -3188,6 +3333,17 @@ retry:
50594
50595 if (!IS_POSIXACL(path.dentry->d_inode))
50596 mode &= ~current_umask();
50597+
50598+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
50599+ error = -EPERM;
50600+ goto out;
50601+ }
50602+
50603+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
50604+ error = -EACCES;
50605+ goto out;
50606+ }
50607+
50608 error = security_path_mknod(&path, dentry, mode, dev);
50609 if (error)
50610 goto out;
50611@@ -3204,6 +3360,8 @@ retry:
50612 break;
50613 }
50614 out:
50615+ if (!error)
50616+ gr_handle_create(dentry, path.mnt);
50617 done_path_create(&path, dentry);
50618 if (retry_estale(error, lookup_flags)) {
50619 lookup_flags |= LOOKUP_REVAL;
50620@@ -3256,9 +3414,16 @@ retry:
50621
50622 if (!IS_POSIXACL(path.dentry->d_inode))
50623 mode &= ~current_umask();
50624+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
50625+ error = -EACCES;
50626+ goto out;
50627+ }
50628 error = security_path_mkdir(&path, dentry, mode);
50629 if (!error)
50630 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
50631+ if (!error)
50632+ gr_handle_create(dentry, path.mnt);
50633+out:
50634 done_path_create(&path, dentry);
50635 if (retry_estale(error, lookup_flags)) {
50636 lookup_flags |= LOOKUP_REVAL;
50637@@ -3339,6 +3504,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
50638 struct filename *name;
50639 struct dentry *dentry;
50640 struct nameidata nd;
50641+ ino_t saved_ino = 0;
50642+ dev_t saved_dev = 0;
50643 unsigned int lookup_flags = 0;
50644 retry:
50645 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
50646@@ -3371,10 +3538,21 @@ retry:
50647 error = -ENOENT;
50648 goto exit3;
50649 }
50650+
50651+ saved_ino = dentry->d_inode->i_ino;
50652+ saved_dev = gr_get_dev_from_dentry(dentry);
50653+
50654+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
50655+ error = -EACCES;
50656+ goto exit3;
50657+ }
50658+
50659 error = security_path_rmdir(&nd.path, dentry);
50660 if (error)
50661 goto exit3;
50662 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
50663+ if (!error && (saved_dev || saved_ino))
50664+ gr_handle_delete(saved_ino, saved_dev);
50665 exit3:
50666 dput(dentry);
50667 exit2:
50668@@ -3440,6 +3618,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
50669 struct dentry *dentry;
50670 struct nameidata nd;
50671 struct inode *inode = NULL;
50672+ ino_t saved_ino = 0;
50673+ dev_t saved_dev = 0;
50674 unsigned int lookup_flags = 0;
50675 retry:
50676 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
50677@@ -3466,10 +3646,22 @@ retry:
50678 if (!inode)
50679 goto slashes;
50680 ihold(inode);
50681+
50682+ if (inode->i_nlink <= 1) {
50683+ saved_ino = inode->i_ino;
50684+ saved_dev = gr_get_dev_from_dentry(dentry);
50685+ }
50686+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
50687+ error = -EACCES;
50688+ goto exit2;
50689+ }
50690+
50691 error = security_path_unlink(&nd.path, dentry);
50692 if (error)
50693 goto exit2;
50694 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
50695+ if (!error && (saved_ino || saved_dev))
50696+ gr_handle_delete(saved_ino, saved_dev);
50697 exit2:
50698 dput(dentry);
50699 }
50700@@ -3547,9 +3739,17 @@ retry:
50701 if (IS_ERR(dentry))
50702 goto out_putname;
50703
50704+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
50705+ error = -EACCES;
50706+ goto out;
50707+ }
50708+
50709 error = security_path_symlink(&path, dentry, from->name);
50710 if (!error)
50711 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
50712+ if (!error)
50713+ gr_handle_create(dentry, path.mnt);
50714+out:
50715 done_path_create(&path, dentry);
50716 if (retry_estale(error, lookup_flags)) {
50717 lookup_flags |= LOOKUP_REVAL;
50718@@ -3623,6 +3823,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
50719 {
50720 struct dentry *new_dentry;
50721 struct path old_path, new_path;
50722+ struct filename *to = NULL;
50723 int how = 0;
50724 int error;
50725
50726@@ -3646,7 +3847,7 @@ retry:
50727 if (error)
50728 return error;
50729
50730- new_dentry = user_path_create(newdfd, newname, &new_path,
50731+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
50732 (how & LOOKUP_REVAL));
50733 error = PTR_ERR(new_dentry);
50734 if (IS_ERR(new_dentry))
50735@@ -3658,11 +3859,28 @@ retry:
50736 error = may_linkat(&old_path);
50737 if (unlikely(error))
50738 goto out_dput;
50739+
50740+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
50741+ old_path.dentry->d_inode,
50742+ old_path.dentry->d_inode->i_mode, to)) {
50743+ error = -EACCES;
50744+ goto out_dput;
50745+ }
50746+
50747+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
50748+ old_path.dentry, old_path.mnt, to)) {
50749+ error = -EACCES;
50750+ goto out_dput;
50751+ }
50752+
50753 error = security_path_link(old_path.dentry, &new_path, new_dentry);
50754 if (error)
50755 goto out_dput;
50756 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
50757+ if (!error)
50758+ gr_handle_create(new_dentry, new_path.mnt);
50759 out_dput:
50760+ putname(to);
50761 done_path_create(&new_path, new_dentry);
50762 if (retry_estale(error, how)) {
50763 how |= LOOKUP_REVAL;
50764@@ -3908,12 +4126,21 @@ retry:
50765 if (new_dentry == trap)
50766 goto exit5;
50767
50768+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
50769+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
50770+ to);
50771+ if (error)
50772+ goto exit5;
50773+
50774 error = security_path_rename(&oldnd.path, old_dentry,
50775 &newnd.path, new_dentry);
50776 if (error)
50777 goto exit5;
50778 error = vfs_rename(old_dir->d_inode, old_dentry,
50779 new_dir->d_inode, new_dentry);
50780+ if (!error)
50781+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
50782+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
50783 exit5:
50784 dput(new_dentry);
50785 exit4:
50786@@ -3945,6 +4172,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
50787
50788 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
50789 {
50790+ char tmpbuf[64];
50791+ const char *newlink;
50792 int len;
50793
50794 len = PTR_ERR(link);
50795@@ -3954,7 +4183,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
50796 len = strlen(link);
50797 if (len > (unsigned) buflen)
50798 len = buflen;
50799- if (copy_to_user(buffer, link, len))
50800+
50801+ if (len < sizeof(tmpbuf)) {
50802+ memcpy(tmpbuf, link, len);
50803+ newlink = tmpbuf;
50804+ } else
50805+ newlink = link;
50806+
50807+ if (copy_to_user(buffer, newlink, len))
50808 len = -EFAULT;
50809 out:
50810 return len;
50811diff --git a/fs/namespace.c b/fs/namespace.c
50812index 55605c5..22e9a03 100644
50813--- a/fs/namespace.c
50814+++ b/fs/namespace.c
50815@@ -1215,6 +1215,9 @@ static int do_umount(struct mount *mnt, int flags)
50816 if (!(sb->s_flags & MS_RDONLY))
50817 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
50818 up_write(&sb->s_umount);
50819+
50820+ gr_log_remount(mnt->mnt_devname, retval);
50821+
50822 return retval;
50823 }
50824
50825@@ -1234,6 +1237,9 @@ static int do_umount(struct mount *mnt, int flags)
50826 br_write_unlock(&vfsmount_lock);
50827 up_write(&namespace_sem);
50828 release_mounts(&umount_list);
50829+
50830+ gr_log_unmount(mnt->mnt_devname, retval);
50831+
50832 return retval;
50833 }
50834
50835@@ -2282,6 +2288,16 @@ long do_mount(const char *dev_name, const char *dir_name,
50836 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
50837 MS_STRICTATIME);
50838
50839+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
50840+ retval = -EPERM;
50841+ goto dput_out;
50842+ }
50843+
50844+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
50845+ retval = -EPERM;
50846+ goto dput_out;
50847+ }
50848+
50849 if (flags & MS_REMOUNT)
50850 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
50851 data_page);
50852@@ -2296,6 +2312,9 @@ long do_mount(const char *dev_name, const char *dir_name,
50853 dev_name, data_page);
50854 dput_out:
50855 path_put(&path);
50856+
50857+ gr_log_mount(dev_name, dir_name, retval);
50858+
50859 return retval;
50860 }
50861
50862@@ -2582,6 +2601,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
50863 if (error)
50864 goto out2;
50865
50866+ if (gr_handle_chroot_pivot()) {
50867+ error = -EPERM;
50868+ goto out2;
50869+ }
50870+
50871 get_fs_root(current->fs, &root);
50872 error = lock_mount(&old);
50873 if (error)
50874@@ -2785,7 +2809,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
50875 !nsown_capable(CAP_SYS_ADMIN))
50876 return -EPERM;
50877
50878- if (fs->users != 1)
50879+ if (atomic_read(&fs->users) != 1)
50880 return -EINVAL;
50881
50882 get_mnt_ns(mnt_ns);
50883diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
50884index ebeb94c..ff35337 100644
50885--- a/fs/nfs/inode.c
50886+++ b/fs/nfs/inode.c
50887@@ -1042,16 +1042,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
50888 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
50889 }
50890
50891-static atomic_long_t nfs_attr_generation_counter;
50892+static atomic_long_unchecked_t nfs_attr_generation_counter;
50893
50894 static unsigned long nfs_read_attr_generation_counter(void)
50895 {
50896- return atomic_long_read(&nfs_attr_generation_counter);
50897+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
50898 }
50899
50900 unsigned long nfs_inc_attr_generation_counter(void)
50901 {
50902- return atomic_long_inc_return(&nfs_attr_generation_counter);
50903+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
50904 }
50905
50906 void nfs_fattr_init(struct nfs_fattr *fattr)
50907diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
50908index d586117..143d568 100644
50909--- a/fs/nfsd/vfs.c
50910+++ b/fs/nfsd/vfs.c
50911@@ -939,7 +939,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
50912 } else {
50913 oldfs = get_fs();
50914 set_fs(KERNEL_DS);
50915- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
50916+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
50917 set_fs(oldfs);
50918 }
50919
50920@@ -1025,7 +1025,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
50921
50922 /* Write the data. */
50923 oldfs = get_fs(); set_fs(KERNEL_DS);
50924- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
50925+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
50926 set_fs(oldfs);
50927 if (host_err < 0)
50928 goto out_nfserr;
50929@@ -1571,7 +1571,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
50930 */
50931
50932 oldfs = get_fs(); set_fs(KERNEL_DS);
50933- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
50934+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
50935 set_fs(oldfs);
50936
50937 if (host_err < 0)
50938diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
50939index 9ff4a5e..deb1f0f 100644
50940--- a/fs/notify/fanotify/fanotify_user.c
50941+++ b/fs/notify/fanotify/fanotify_user.c
50942@@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
50943
50944 fd = fanotify_event_metadata.fd;
50945 ret = -EFAULT;
50946- if (copy_to_user(buf, &fanotify_event_metadata,
50947- fanotify_event_metadata.event_len))
50948+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
50949+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
50950 goto out_close_fd;
50951
50952 ret = prepare_for_access_response(group, event, fd);
50953diff --git a/fs/notify/notification.c b/fs/notify/notification.c
50954index 7b51b05..5ea5ef6 100644
50955--- a/fs/notify/notification.c
50956+++ b/fs/notify/notification.c
50957@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
50958 * get set to 0 so it will never get 'freed'
50959 */
50960 static struct fsnotify_event *q_overflow_event;
50961-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
50962+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
50963
50964 /**
50965 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
50966@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
50967 */
50968 u32 fsnotify_get_cookie(void)
50969 {
50970- return atomic_inc_return(&fsnotify_sync_cookie);
50971+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
50972 }
50973 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
50974
50975diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
50976index 99e3610..02c1068 100644
50977--- a/fs/ntfs/dir.c
50978+++ b/fs/ntfs/dir.c
50979@@ -1329,7 +1329,7 @@ find_next_index_buffer:
50980 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
50981 ~(s64)(ndir->itype.index.block_size - 1)));
50982 /* Bounds checks. */
50983- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
50984+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
50985 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
50986 "inode 0x%lx or driver bug.", vdir->i_ino);
50987 goto err_out;
50988diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
50989index 5b2d4f0..c6de396 100644
50990--- a/fs/ntfs/file.c
50991+++ b/fs/ntfs/file.c
50992@@ -2242,6 +2242,6 @@ const struct inode_operations ntfs_file_inode_ops = {
50993 #endif /* NTFS_RW */
50994 };
50995
50996-const struct file_operations ntfs_empty_file_ops = {};
50997+const struct file_operations ntfs_empty_file_ops __read_only;
50998
50999-const struct inode_operations ntfs_empty_inode_ops = {};
51000+const struct inode_operations ntfs_empty_inode_ops __read_only;
51001diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
51002index a9f78c7..ed8a381 100644
51003--- a/fs/ocfs2/localalloc.c
51004+++ b/fs/ocfs2/localalloc.c
51005@@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
51006 goto bail;
51007 }
51008
51009- atomic_inc(&osb->alloc_stats.moves);
51010+ atomic_inc_unchecked(&osb->alloc_stats.moves);
51011
51012 bail:
51013 if (handle)
51014diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
51015index d355e6e..578d905 100644
51016--- a/fs/ocfs2/ocfs2.h
51017+++ b/fs/ocfs2/ocfs2.h
51018@@ -235,11 +235,11 @@ enum ocfs2_vol_state
51019
51020 struct ocfs2_alloc_stats
51021 {
51022- atomic_t moves;
51023- atomic_t local_data;
51024- atomic_t bitmap_data;
51025- atomic_t bg_allocs;
51026- atomic_t bg_extends;
51027+ atomic_unchecked_t moves;
51028+ atomic_unchecked_t local_data;
51029+ atomic_unchecked_t bitmap_data;
51030+ atomic_unchecked_t bg_allocs;
51031+ atomic_unchecked_t bg_extends;
51032 };
51033
51034 enum ocfs2_local_alloc_state
51035diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
51036index f169da4..9112253 100644
51037--- a/fs/ocfs2/suballoc.c
51038+++ b/fs/ocfs2/suballoc.c
51039@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
51040 mlog_errno(status);
51041 goto bail;
51042 }
51043- atomic_inc(&osb->alloc_stats.bg_extends);
51044+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
51045
51046 /* You should never ask for this much metadata */
51047 BUG_ON(bits_wanted >
51048@@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
51049 mlog_errno(status);
51050 goto bail;
51051 }
51052- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51053+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51054
51055 *suballoc_loc = res.sr_bg_blkno;
51056 *suballoc_bit_start = res.sr_bit_offset;
51057@@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
51058 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
51059 res->sr_bits);
51060
51061- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51062+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51063
51064 BUG_ON(res->sr_bits != 1);
51065
51066@@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
51067 mlog_errno(status);
51068 goto bail;
51069 }
51070- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51071+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51072
51073 BUG_ON(res.sr_bits != 1);
51074
51075@@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
51076 cluster_start,
51077 num_clusters);
51078 if (!status)
51079- atomic_inc(&osb->alloc_stats.local_data);
51080+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
51081 } else {
51082 if (min_clusters > (osb->bitmap_cpg - 1)) {
51083 /* The only paths asking for contiguousness
51084@@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
51085 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
51086 res.sr_bg_blkno,
51087 res.sr_bit_offset);
51088- atomic_inc(&osb->alloc_stats.bitmap_data);
51089+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
51090 *num_clusters = res.sr_bits;
51091 }
51092 }
51093diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
51094index 0e91ec2..f4b3fc6 100644
51095--- a/fs/ocfs2/super.c
51096+++ b/fs/ocfs2/super.c
51097@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
51098 "%10s => GlobalAllocs: %d LocalAllocs: %d "
51099 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
51100 "Stats",
51101- atomic_read(&osb->alloc_stats.bitmap_data),
51102- atomic_read(&osb->alloc_stats.local_data),
51103- atomic_read(&osb->alloc_stats.bg_allocs),
51104- atomic_read(&osb->alloc_stats.moves),
51105- atomic_read(&osb->alloc_stats.bg_extends));
51106+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
51107+ atomic_read_unchecked(&osb->alloc_stats.local_data),
51108+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
51109+ atomic_read_unchecked(&osb->alloc_stats.moves),
51110+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
51111
51112 out += snprintf(buf + out, len - out,
51113 "%10s => State: %u Descriptor: %llu Size: %u bits "
51114@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
51115 spin_lock_init(&osb->osb_xattr_lock);
51116 ocfs2_init_steal_slots(osb);
51117
51118- atomic_set(&osb->alloc_stats.moves, 0);
51119- atomic_set(&osb->alloc_stats.local_data, 0);
51120- atomic_set(&osb->alloc_stats.bitmap_data, 0);
51121- atomic_set(&osb->alloc_stats.bg_allocs, 0);
51122- atomic_set(&osb->alloc_stats.bg_extends, 0);
51123+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
51124+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
51125+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
51126+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
51127+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
51128
51129 /* Copy the blockcheck stats from the superblock probe */
51130 osb->osb_ecc_stats = *stats;
51131diff --git a/fs/open.c b/fs/open.c
51132index 9b33c0c..2ffcca2 100644
51133--- a/fs/open.c
51134+++ b/fs/open.c
51135@@ -31,6 +31,8 @@
51136 #include <linux/ima.h>
51137 #include <linux/dnotify.h>
51138
51139+#define CREATE_TRACE_POINTS
51140+#include <trace/events/fs.h>
51141 #include "internal.h"
51142
51143 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
51144@@ -101,6 +103,8 @@ long vfs_truncate(struct path *path, loff_t length)
51145 error = locks_verify_truncate(inode, NULL, length);
51146 if (!error)
51147 error = security_path_truncate(path);
51148+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
51149+ error = -EACCES;
51150 if (!error)
51151 error = do_truncate(path->dentry, length, 0, NULL);
51152
51153@@ -178,6 +182,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
51154 error = locks_verify_truncate(inode, f.file, length);
51155 if (!error)
51156 error = security_path_truncate(&f.file->f_path);
51157+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
51158+ error = -EACCES;
51159 if (!error)
51160 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
51161 sb_end_write(inode->i_sb);
51162@@ -373,6 +379,9 @@ retry:
51163 if (__mnt_is_readonly(path.mnt))
51164 res = -EROFS;
51165
51166+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
51167+ res = -EACCES;
51168+
51169 out_path_release:
51170 path_put(&path);
51171 if (retry_estale(res, lookup_flags)) {
51172@@ -404,6 +413,8 @@ retry:
51173 if (error)
51174 goto dput_and_out;
51175
51176+ gr_log_chdir(path.dentry, path.mnt);
51177+
51178 set_fs_pwd(current->fs, &path);
51179
51180 dput_and_out:
51181@@ -433,6 +444,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
51182 goto out_putf;
51183
51184 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
51185+
51186+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
51187+ error = -EPERM;
51188+
51189+ if (!error)
51190+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
51191+
51192 if (!error)
51193 set_fs_pwd(current->fs, &f.file->f_path);
51194 out_putf:
51195@@ -462,7 +480,13 @@ retry:
51196 if (error)
51197 goto dput_and_out;
51198
51199+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
51200+ goto dput_and_out;
51201+
51202 set_fs_root(current->fs, &path);
51203+
51204+ gr_handle_chroot_chdir(&path);
51205+
51206 error = 0;
51207 dput_and_out:
51208 path_put(&path);
51209@@ -484,6 +508,16 @@ static int chmod_common(struct path *path, umode_t mode)
51210 if (error)
51211 return error;
51212 mutex_lock(&inode->i_mutex);
51213+
51214+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
51215+ error = -EACCES;
51216+ goto out_unlock;
51217+ }
51218+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
51219+ error = -EACCES;
51220+ goto out_unlock;
51221+ }
51222+
51223 error = security_path_chmod(path, mode);
51224 if (error)
51225 goto out_unlock;
51226@@ -544,6 +578,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
51227 uid = make_kuid(current_user_ns(), user);
51228 gid = make_kgid(current_user_ns(), group);
51229
51230+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
51231+ return -EACCES;
51232+
51233 newattrs.ia_valid = ATTR_CTIME;
51234 if (user != (uid_t) -1) {
51235 if (!uid_valid(uid))
51236@@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
51237 } else {
51238 fsnotify_open(f);
51239 fd_install(fd, f);
51240+ trace_do_sys_open(tmp->name, flags, mode);
51241 }
51242 }
51243 putname(tmp);
51244diff --git a/fs/pipe.c b/fs/pipe.c
51245index bd3479d..fb92c4d 100644
51246--- a/fs/pipe.c
51247+++ b/fs/pipe.c
51248@@ -438,9 +438,9 @@ redo:
51249 }
51250 if (bufs) /* More to do? */
51251 continue;
51252- if (!pipe->writers)
51253+ if (!atomic_read(&pipe->writers))
51254 break;
51255- if (!pipe->waiting_writers) {
51256+ if (!atomic_read(&pipe->waiting_writers)) {
51257 /* syscall merging: Usually we must not sleep
51258 * if O_NONBLOCK is set, or if we got some data.
51259 * But if a writer sleeps in kernel space, then
51260@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
51261 mutex_lock(&inode->i_mutex);
51262 pipe = inode->i_pipe;
51263
51264- if (!pipe->readers) {
51265+ if (!atomic_read(&pipe->readers)) {
51266 send_sig(SIGPIPE, current, 0);
51267 ret = -EPIPE;
51268 goto out;
51269@@ -553,7 +553,7 @@ redo1:
51270 for (;;) {
51271 int bufs;
51272
51273- if (!pipe->readers) {
51274+ if (!atomic_read(&pipe->readers)) {
51275 send_sig(SIGPIPE, current, 0);
51276 if (!ret)
51277 ret = -EPIPE;
51278@@ -644,9 +644,9 @@ redo2:
51279 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
51280 do_wakeup = 0;
51281 }
51282- pipe->waiting_writers++;
51283+ atomic_inc(&pipe->waiting_writers);
51284 pipe_wait(pipe);
51285- pipe->waiting_writers--;
51286+ atomic_dec(&pipe->waiting_writers);
51287 }
51288 out:
51289 mutex_unlock(&inode->i_mutex);
51290@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
51291 mask = 0;
51292 if (filp->f_mode & FMODE_READ) {
51293 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
51294- if (!pipe->writers && filp->f_version != pipe->w_counter)
51295+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
51296 mask |= POLLHUP;
51297 }
51298
51299@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
51300 * Most Unices do not set POLLERR for FIFOs but on Linux they
51301 * behave exactly like pipes for poll().
51302 */
51303- if (!pipe->readers)
51304+ if (!atomic_read(&pipe->readers))
51305 mask |= POLLERR;
51306 }
51307
51308@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
51309
51310 mutex_lock(&inode->i_mutex);
51311 pipe = inode->i_pipe;
51312- pipe->readers -= decr;
51313- pipe->writers -= decw;
51314+ atomic_sub(decr, &pipe->readers);
51315+ atomic_sub(decw, &pipe->writers);
51316
51317- if (!pipe->readers && !pipe->writers) {
51318+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
51319 free_pipe_info(inode);
51320 } else {
51321 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
51322@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
51323
51324 if (inode->i_pipe) {
51325 ret = 0;
51326- inode->i_pipe->readers++;
51327+ atomic_inc(&inode->i_pipe->readers);
51328 }
51329
51330 mutex_unlock(&inode->i_mutex);
51331@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
51332
51333 if (inode->i_pipe) {
51334 ret = 0;
51335- inode->i_pipe->writers++;
51336+ atomic_inc(&inode->i_pipe->writers);
51337 }
51338
51339 mutex_unlock(&inode->i_mutex);
51340@@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
51341 if (inode->i_pipe) {
51342 ret = 0;
51343 if (filp->f_mode & FMODE_READ)
51344- inode->i_pipe->readers++;
51345+ atomic_inc(&inode->i_pipe->readers);
51346 if (filp->f_mode & FMODE_WRITE)
51347- inode->i_pipe->writers++;
51348+ atomic_inc(&inode->i_pipe->writers);
51349 }
51350
51351 mutex_unlock(&inode->i_mutex);
51352@@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
51353 inode->i_pipe = NULL;
51354 }
51355
51356-static struct vfsmount *pipe_mnt __read_mostly;
51357+struct vfsmount *pipe_mnt __read_mostly;
51358
51359 /*
51360 * pipefs_dname() is called from d_path().
51361@@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
51362 goto fail_iput;
51363 inode->i_pipe = pipe;
51364
51365- pipe->readers = pipe->writers = 1;
51366+ atomic_set(&pipe->readers, 1);
51367+ atomic_set(&pipe->writers, 1);
51368 inode->i_fop = &rdwr_pipefifo_fops;
51369
51370 /*
51371diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
51372index 15af622..0e9f4467 100644
51373--- a/fs/proc/Kconfig
51374+++ b/fs/proc/Kconfig
51375@@ -30,12 +30,12 @@ config PROC_FS
51376
51377 config PROC_KCORE
51378 bool "/proc/kcore support" if !ARM
51379- depends on PROC_FS && MMU
51380+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
51381
51382 config PROC_VMCORE
51383 bool "/proc/vmcore support"
51384- depends on PROC_FS && CRASH_DUMP
51385- default y
51386+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
51387+ default n
51388 help
51389 Exports the dump image of crashed kernel in ELF format.
51390
51391@@ -59,8 +59,8 @@ config PROC_SYSCTL
51392 limited in memory.
51393
51394 config PROC_PAGE_MONITOR
51395- default y
51396- depends on PROC_FS && MMU
51397+ default n
51398+ depends on PROC_FS && MMU && !GRKERNSEC
51399 bool "Enable /proc page monitoring" if EXPERT
51400 help
51401 Various /proc files exist to monitor process memory utilization:
51402diff --git a/fs/proc/array.c b/fs/proc/array.c
51403index 6a91e6f..e54dbc14 100644
51404--- a/fs/proc/array.c
51405+++ b/fs/proc/array.c
51406@@ -60,6 +60,7 @@
51407 #include <linux/tty.h>
51408 #include <linux/string.h>
51409 #include <linux/mman.h>
51410+#include <linux/grsecurity.h>
51411 #include <linux/proc_fs.h>
51412 #include <linux/ioport.h>
51413 #include <linux/uaccess.h>
51414@@ -362,6 +363,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
51415 seq_putc(m, '\n');
51416 }
51417
51418+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
51419+static inline void task_pax(struct seq_file *m, struct task_struct *p)
51420+{
51421+ if (p->mm)
51422+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
51423+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
51424+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
51425+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
51426+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
51427+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
51428+ else
51429+ seq_printf(m, "PaX:\t-----\n");
51430+}
51431+#endif
51432+
51433 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
51434 struct pid *pid, struct task_struct *task)
51435 {
51436@@ -380,9 +396,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
51437 task_cpus_allowed(m, task);
51438 cpuset_task_status_allowed(m, task);
51439 task_context_switch_counts(m, task);
51440+
51441+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
51442+ task_pax(m, task);
51443+#endif
51444+
51445+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
51446+ task_grsec_rbac(m, task);
51447+#endif
51448+
51449 return 0;
51450 }
51451
51452+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51453+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
51454+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
51455+ _mm->pax_flags & MF_PAX_SEGMEXEC))
51456+#endif
51457+
51458 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51459 struct pid *pid, struct task_struct *task, int whole)
51460 {
51461@@ -404,6 +435,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51462 char tcomm[sizeof(task->comm)];
51463 unsigned long flags;
51464
51465+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51466+ if (current->exec_id != m->exec_id) {
51467+ gr_log_badprocpid("stat");
51468+ return 0;
51469+ }
51470+#endif
51471+
51472 state = *get_task_state(task);
51473 vsize = eip = esp = 0;
51474 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
51475@@ -475,6 +513,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51476 gtime = task->gtime;
51477 }
51478
51479+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51480+ if (PAX_RAND_FLAGS(mm)) {
51481+ eip = 0;
51482+ esp = 0;
51483+ wchan = 0;
51484+ }
51485+#endif
51486+#ifdef CONFIG_GRKERNSEC_HIDESYM
51487+ wchan = 0;
51488+ eip =0;
51489+ esp =0;
51490+#endif
51491+
51492 /* scale priority and nice values from timeslices to -20..20 */
51493 /* to make it look like a "normal" Unix priority/nice value */
51494 priority = task_prio(task);
51495@@ -511,9 +562,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51496 seq_put_decimal_ull(m, ' ', vsize);
51497 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
51498 seq_put_decimal_ull(m, ' ', rsslim);
51499+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51500+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
51501+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
51502+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
51503+#else
51504 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
51505 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
51506 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
51507+#endif
51508 seq_put_decimal_ull(m, ' ', esp);
51509 seq_put_decimal_ull(m, ' ', eip);
51510 /* The signal information here is obsolete.
51511@@ -535,7 +592,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51512 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
51513 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
51514
51515- if (mm && permitted) {
51516+ if (mm && permitted
51517+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51518+ && !PAX_RAND_FLAGS(mm)
51519+#endif
51520+ ) {
51521 seq_put_decimal_ull(m, ' ', mm->start_data);
51522 seq_put_decimal_ull(m, ' ', mm->end_data);
51523 seq_put_decimal_ull(m, ' ', mm->start_brk);
51524@@ -573,8 +634,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
51525 struct pid *pid, struct task_struct *task)
51526 {
51527 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
51528- struct mm_struct *mm = get_task_mm(task);
51529+ struct mm_struct *mm;
51530
51531+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51532+ if (current->exec_id != m->exec_id) {
51533+ gr_log_badprocpid("statm");
51534+ return 0;
51535+ }
51536+#endif
51537+ mm = get_task_mm(task);
51538 if (mm) {
51539 size = task_statm(mm, &shared, &text, &data, &resident);
51540 mmput(mm);
51541@@ -597,6 +665,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
51542 return 0;
51543 }
51544
51545+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
51546+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
51547+{
51548+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
51549+}
51550+#endif
51551+
51552 #ifdef CONFIG_CHECKPOINT_RESTORE
51553 static struct pid *
51554 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
51555diff --git a/fs/proc/base.c b/fs/proc/base.c
51556index 9b43ff77..3d6a99f 100644
51557--- a/fs/proc/base.c
51558+++ b/fs/proc/base.c
51559@@ -111,6 +111,14 @@ struct pid_entry {
51560 union proc_op op;
51561 };
51562
51563+struct getdents_callback {
51564+ struct linux_dirent __user * current_dir;
51565+ struct linux_dirent __user * previous;
51566+ struct file * file;
51567+ int count;
51568+ int error;
51569+};
51570+
51571 #define NOD(NAME, MODE, IOP, FOP, OP) { \
51572 .name = (NAME), \
51573 .len = sizeof(NAME) - 1, \
51574@@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
51575 if (!mm->arg_end)
51576 goto out_mm; /* Shh! No looking before we're done */
51577
51578+ if (gr_acl_handle_procpidmem(task))
51579+ goto out_mm;
51580+
51581 len = mm->arg_end - mm->arg_start;
51582
51583 if (len > PAGE_SIZE)
51584@@ -235,12 +246,28 @@ out:
51585 return res;
51586 }
51587
51588+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51589+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
51590+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
51591+ _mm->pax_flags & MF_PAX_SEGMEXEC))
51592+#endif
51593+
51594 static int proc_pid_auxv(struct task_struct *task, char *buffer)
51595 {
51596 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
51597 int res = PTR_ERR(mm);
51598 if (mm && !IS_ERR(mm)) {
51599 unsigned int nwords = 0;
51600+
51601+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51602+ /* allow if we're currently ptracing this task */
51603+ if (PAX_RAND_FLAGS(mm) &&
51604+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
51605+ mmput(mm);
51606+ return 0;
51607+ }
51608+#endif
51609+
51610 do {
51611 nwords += 2;
51612 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
51613@@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
51614 }
51615
51616
51617-#ifdef CONFIG_KALLSYMS
51618+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51619 /*
51620 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
51621 * Returns the resolved symbol. If that fails, simply return the address.
51622@@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
51623 mutex_unlock(&task->signal->cred_guard_mutex);
51624 }
51625
51626-#ifdef CONFIG_STACKTRACE
51627+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51628
51629 #define MAX_STACK_TRACE_DEPTH 64
51630
51631@@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
51632 return count;
51633 }
51634
51635-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
51636+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51637 static int proc_pid_syscall(struct task_struct *task, char *buffer)
51638 {
51639 long nr;
51640@@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
51641 /************************************************************************/
51642
51643 /* permission checks */
51644-static int proc_fd_access_allowed(struct inode *inode)
51645+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
51646 {
51647 struct task_struct *task;
51648 int allowed = 0;
51649@@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
51650 */
51651 task = get_proc_task(inode);
51652 if (task) {
51653- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
51654+ if (log)
51655+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
51656+ else
51657+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
51658 put_task_struct(task);
51659 }
51660 return allowed;
51661@@ -555,10 +585,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
51662 struct task_struct *task,
51663 int hide_pid_min)
51664 {
51665+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51666+ return false;
51667+
51668+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51669+ rcu_read_lock();
51670+ {
51671+ const struct cred *tmpcred = current_cred();
51672+ const struct cred *cred = __task_cred(task);
51673+
51674+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
51675+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51676+ || in_group_p(grsec_proc_gid)
51677+#endif
51678+ ) {
51679+ rcu_read_unlock();
51680+ return true;
51681+ }
51682+ }
51683+ rcu_read_unlock();
51684+
51685+ if (!pid->hide_pid)
51686+ return false;
51687+#endif
51688+
51689 if (pid->hide_pid < hide_pid_min)
51690 return true;
51691 if (in_group_p(pid->pid_gid))
51692 return true;
51693+
51694 return ptrace_may_access(task, PTRACE_MODE_READ);
51695 }
51696
51697@@ -576,7 +631,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
51698 put_task_struct(task);
51699
51700 if (!has_perms) {
51701+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51702+ {
51703+#else
51704 if (pid->hide_pid == 2) {
51705+#endif
51706 /*
51707 * Let's make getdents(), stat(), and open()
51708 * consistent with each other. If a process
51709@@ -674,6 +733,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
51710 if (!task)
51711 return -ESRCH;
51712
51713+ if (gr_acl_handle_procpidmem(task)) {
51714+ put_task_struct(task);
51715+ return -EPERM;
51716+ }
51717+
51718 mm = mm_access(task, mode);
51719 put_task_struct(task);
51720
51721@@ -689,6 +753,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
51722
51723 file->private_data = mm;
51724
51725+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51726+ file->f_version = current->exec_id;
51727+#endif
51728+
51729 return 0;
51730 }
51731
51732@@ -710,6 +778,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
51733 ssize_t copied;
51734 char *page;
51735
51736+#ifdef CONFIG_GRKERNSEC
51737+ if (write)
51738+ return -EPERM;
51739+#endif
51740+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51741+ if (file->f_version != current->exec_id) {
51742+ gr_log_badprocpid("mem");
51743+ return 0;
51744+ }
51745+#endif
51746+
51747 if (!mm)
51748 return 0;
51749
51750@@ -814,6 +893,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
51751 if (!mm)
51752 return 0;
51753
51754+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51755+ if (file->f_version != current->exec_id) {
51756+ gr_log_badprocpid("environ");
51757+ return 0;
51758+ }
51759+#endif
51760+
51761 page = (char *)__get_free_page(GFP_TEMPORARY);
51762 if (!page)
51763 return -ENOMEM;
51764@@ -1429,7 +1515,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
51765 int error = -EACCES;
51766
51767 /* Are we allowed to snoop on the tasks file descriptors? */
51768- if (!proc_fd_access_allowed(inode))
51769+ if (!proc_fd_access_allowed(inode, 0))
51770 goto out;
51771
51772 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
51773@@ -1473,8 +1559,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
51774 struct path path;
51775
51776 /* Are we allowed to snoop on the tasks file descriptors? */
51777- if (!proc_fd_access_allowed(inode))
51778- goto out;
51779+ /* logging this is needed for learning on chromium to work properly,
51780+ but we don't want to flood the logs from 'ps' which does a readlink
51781+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
51782+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
51783+ */
51784+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
51785+ if (!proc_fd_access_allowed(inode,0))
51786+ goto out;
51787+ } else {
51788+ if (!proc_fd_access_allowed(inode,1))
51789+ goto out;
51790+ }
51791
51792 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
51793 if (error)
51794@@ -1524,7 +1620,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
51795 rcu_read_lock();
51796 cred = __task_cred(task);
51797 inode->i_uid = cred->euid;
51798+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51799+ inode->i_gid = grsec_proc_gid;
51800+#else
51801 inode->i_gid = cred->egid;
51802+#endif
51803 rcu_read_unlock();
51804 }
51805 security_task_to_inode(task, inode);
51806@@ -1560,10 +1660,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
51807 return -ENOENT;
51808 }
51809 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
51810+#ifdef CONFIG_GRKERNSEC_PROC_USER
51811+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
51812+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51813+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
51814+#endif
51815 task_dumpable(task)) {
51816 cred = __task_cred(task);
51817 stat->uid = cred->euid;
51818+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51819+ stat->gid = grsec_proc_gid;
51820+#else
51821 stat->gid = cred->egid;
51822+#endif
51823 }
51824 }
51825 rcu_read_unlock();
51826@@ -1601,11 +1710,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
51827
51828 if (task) {
51829 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
51830+#ifdef CONFIG_GRKERNSEC_PROC_USER
51831+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
51832+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51833+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
51834+#endif
51835 task_dumpable(task)) {
51836 rcu_read_lock();
51837 cred = __task_cred(task);
51838 inode->i_uid = cred->euid;
51839+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51840+ inode->i_gid = grsec_proc_gid;
51841+#else
51842 inode->i_gid = cred->egid;
51843+#endif
51844 rcu_read_unlock();
51845 } else {
51846 inode->i_uid = GLOBAL_ROOT_UID;
51847@@ -2058,6 +2176,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
51848 if (!task)
51849 goto out_no_task;
51850
51851+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51852+ goto out;
51853+
51854 /*
51855 * Yes, it does not scale. And it should not. Don't add
51856 * new entries into /proc/<tgid>/ without very good reasons.
51857@@ -2102,6 +2223,9 @@ static int proc_pident_readdir(struct file *filp,
51858 if (!task)
51859 goto out_no_task;
51860
51861+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51862+ goto out;
51863+
51864 ret = 0;
51865 i = filp->f_pos;
51866 switch (i) {
51867@@ -2515,7 +2639,7 @@ static const struct pid_entry tgid_base_stuff[] = {
51868 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
51869 #endif
51870 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
51871-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
51872+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51873 INF("syscall", S_IRUGO, proc_pid_syscall),
51874 #endif
51875 INF("cmdline", S_IRUGO, proc_pid_cmdline),
51876@@ -2540,10 +2664,10 @@ static const struct pid_entry tgid_base_stuff[] = {
51877 #ifdef CONFIG_SECURITY
51878 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
51879 #endif
51880-#ifdef CONFIG_KALLSYMS
51881+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51882 INF("wchan", S_IRUGO, proc_pid_wchan),
51883 #endif
51884-#ifdef CONFIG_STACKTRACE
51885+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51886 ONE("stack", S_IRUGO, proc_pid_stack),
51887 #endif
51888 #ifdef CONFIG_SCHEDSTATS
51889@@ -2577,6 +2701,9 @@ static const struct pid_entry tgid_base_stuff[] = {
51890 #ifdef CONFIG_HARDWALL
51891 INF("hardwall", S_IRUGO, proc_pid_hardwall),
51892 #endif
51893+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
51894+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
51895+#endif
51896 #ifdef CONFIG_USER_NS
51897 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
51898 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
51899@@ -2705,7 +2832,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
51900 if (!inode)
51901 goto out;
51902
51903+#ifdef CONFIG_GRKERNSEC_PROC_USER
51904+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
51905+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51906+ inode->i_gid = grsec_proc_gid;
51907+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
51908+#else
51909 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
51910+#endif
51911 inode->i_op = &proc_tgid_base_inode_operations;
51912 inode->i_fop = &proc_tgid_base_operations;
51913 inode->i_flags|=S_IMMUTABLE;
51914@@ -2743,7 +2877,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
51915 if (!task)
51916 goto out;
51917
51918+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51919+ goto out_put_task;
51920+
51921 result = proc_pid_instantiate(dir, dentry, task, NULL);
51922+out_put_task:
51923 put_task_struct(task);
51924 out:
51925 return result;
51926@@ -2806,6 +2944,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
51927 static int fake_filldir(void *buf, const char *name, int namelen,
51928 loff_t offset, u64 ino, unsigned d_type)
51929 {
51930+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
51931+ __buf->error = -EINVAL;
51932 return 0;
51933 }
51934
51935@@ -2857,7 +2997,7 @@ static const struct pid_entry tid_base_stuff[] = {
51936 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
51937 #endif
51938 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
51939-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
51940+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51941 INF("syscall", S_IRUGO, proc_pid_syscall),
51942 #endif
51943 INF("cmdline", S_IRUGO, proc_pid_cmdline),
51944@@ -2884,10 +3024,10 @@ static const struct pid_entry tid_base_stuff[] = {
51945 #ifdef CONFIG_SECURITY
51946 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
51947 #endif
51948-#ifdef CONFIG_KALLSYMS
51949+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51950 INF("wchan", S_IRUGO, proc_pid_wchan),
51951 #endif
51952-#ifdef CONFIG_STACKTRACE
51953+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51954 ONE("stack", S_IRUGO, proc_pid_stack),
51955 #endif
51956 #ifdef CONFIG_SCHEDSTATS
51957diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
51958index 82676e3..5f8518a 100644
51959--- a/fs/proc/cmdline.c
51960+++ b/fs/proc/cmdline.c
51961@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
51962
51963 static int __init proc_cmdline_init(void)
51964 {
51965+#ifdef CONFIG_GRKERNSEC_PROC_ADD
51966+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
51967+#else
51968 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
51969+#endif
51970 return 0;
51971 }
51972 module_init(proc_cmdline_init);
51973diff --git a/fs/proc/devices.c b/fs/proc/devices.c
51974index b143471..bb105e5 100644
51975--- a/fs/proc/devices.c
51976+++ b/fs/proc/devices.c
51977@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
51978
51979 static int __init proc_devices_init(void)
51980 {
51981+#ifdef CONFIG_GRKERNSEC_PROC_ADD
51982+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
51983+#else
51984 proc_create("devices", 0, NULL, &proc_devinfo_operations);
51985+#endif
51986 return 0;
51987 }
51988 module_init(proc_devices_init);
51989diff --git a/fs/proc/fd.c b/fs/proc/fd.c
51990index d7a4a28..0201742 100644
51991--- a/fs/proc/fd.c
51992+++ b/fs/proc/fd.c
51993@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
51994 if (!task)
51995 return -ENOENT;
51996
51997- files = get_files_struct(task);
51998+ if (!gr_acl_handle_procpidmem(task))
51999+ files = get_files_struct(task);
52000 put_task_struct(task);
52001
52002 if (files) {
52003@@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
52004 */
52005 int proc_fd_permission(struct inode *inode, int mask)
52006 {
52007+ struct task_struct *task;
52008 int rv = generic_permission(inode, mask);
52009- if (rv == 0)
52010- return 0;
52011+
52012 if (task_pid(current) == proc_pid(inode))
52013 rv = 0;
52014+
52015+ task = get_proc_task(inode);
52016+ if (task == NULL)
52017+ return rv;
52018+
52019+ if (gr_acl_handle_procpidmem(task))
52020+ rv = -EACCES;
52021+
52022+ put_task_struct(task);
52023+
52024 return rv;
52025 }
52026
52027diff --git a/fs/proc/inode.c b/fs/proc/inode.c
52028index 439ae688..c21ac36 100644
52029--- a/fs/proc/inode.c
52030+++ b/fs/proc/inode.c
52031@@ -21,11 +21,17 @@
52032 #include <linux/seq_file.h>
52033 #include <linux/slab.h>
52034 #include <linux/mount.h>
52035+#include <linux/grsecurity.h>
52036
52037 #include <asm/uaccess.h>
52038
52039 #include "internal.h"
52040
52041+#ifdef CONFIG_PROC_SYSCTL
52042+extern const struct inode_operations proc_sys_inode_operations;
52043+extern const struct inode_operations proc_sys_dir_operations;
52044+#endif
52045+
52046 static void proc_evict_inode(struct inode *inode)
52047 {
52048 struct proc_dir_entry *de;
52049@@ -53,6 +59,13 @@ static void proc_evict_inode(struct inode *inode)
52050 ns = PROC_I(inode)->ns;
52051 if (ns_ops && ns)
52052 ns_ops->put(ns);
52053+
52054+#ifdef CONFIG_PROC_SYSCTL
52055+ if (inode->i_op == &proc_sys_inode_operations ||
52056+ inode->i_op == &proc_sys_dir_operations)
52057+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
52058+#endif
52059+
52060 }
52061
52062 static struct kmem_cache * proc_inode_cachep;
52063@@ -457,7 +470,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
52064 if (de->mode) {
52065 inode->i_mode = de->mode;
52066 inode->i_uid = de->uid;
52067+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52068+ inode->i_gid = grsec_proc_gid;
52069+#else
52070 inode->i_gid = de->gid;
52071+#endif
52072 }
52073 if (de->size)
52074 inode->i_size = de->size;
52075diff --git a/fs/proc/internal.h b/fs/proc/internal.h
52076index 252544c..04395b9 100644
52077--- a/fs/proc/internal.h
52078+++ b/fs/proc/internal.h
52079@@ -55,6 +55,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
52080 struct pid *pid, struct task_struct *task);
52081 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
52082 struct pid *pid, struct task_struct *task);
52083+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
52084+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
52085+#endif
52086 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
52087
52088 extern const struct file_operations proc_tid_children_operations;
52089diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
52090index e96d4f1..8b116ed 100644
52091--- a/fs/proc/kcore.c
52092+++ b/fs/proc/kcore.c
52093@@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
52094 * the addresses in the elf_phdr on our list.
52095 */
52096 start = kc_offset_to_vaddr(*fpos - elf_buflen);
52097- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
52098+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
52099+ if (tsz > buflen)
52100 tsz = buflen;
52101-
52102+
52103 while (buflen) {
52104 struct kcore_list *m;
52105
52106@@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
52107 kfree(elf_buf);
52108 } else {
52109 if (kern_addr_valid(start)) {
52110- unsigned long n;
52111+ char *elf_buf;
52112+ mm_segment_t oldfs;
52113
52114- n = copy_to_user(buffer, (char *)start, tsz);
52115- /*
52116- * We cannot distinguish between fault on source
52117- * and fault on destination. When this happens
52118- * we clear too and hope it will trigger the
52119- * EFAULT again.
52120- */
52121- if (n) {
52122- if (clear_user(buffer + tsz - n,
52123- n))
52124+ elf_buf = kmalloc(tsz, GFP_KERNEL);
52125+ if (!elf_buf)
52126+ return -ENOMEM;
52127+ oldfs = get_fs();
52128+ set_fs(KERNEL_DS);
52129+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
52130+ set_fs(oldfs);
52131+ if (copy_to_user(buffer, elf_buf, tsz)) {
52132+ kfree(elf_buf);
52133 return -EFAULT;
52134+ }
52135 }
52136+ set_fs(oldfs);
52137+ kfree(elf_buf);
52138 } else {
52139 if (clear_user(buffer, tsz))
52140 return -EFAULT;
52141@@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
52142
52143 static int open_kcore(struct inode *inode, struct file *filp)
52144 {
52145+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
52146+ return -EPERM;
52147+#endif
52148 if (!capable(CAP_SYS_RAWIO))
52149 return -EPERM;
52150 if (kcore_need_update)
52151diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
52152index 80e4645..53e5fcf 100644
52153--- a/fs/proc/meminfo.c
52154+++ b/fs/proc/meminfo.c
52155@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
52156 vmi.used >> 10,
52157 vmi.largest_chunk >> 10
52158 #ifdef CONFIG_MEMORY_FAILURE
52159- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
52160+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
52161 #endif
52162 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
52163 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
52164diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
52165index b1822dd..df622cb 100644
52166--- a/fs/proc/nommu.c
52167+++ b/fs/proc/nommu.c
52168@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
52169 if (len < 1)
52170 len = 1;
52171 seq_printf(m, "%*c", len, ' ');
52172- seq_path(m, &file->f_path, "");
52173+ seq_path(m, &file->f_path, "\n\\");
52174 }
52175
52176 seq_putc(m, '\n');
52177diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
52178index fe72cd0..cb9b67d 100644
52179--- a/fs/proc/proc_net.c
52180+++ b/fs/proc/proc_net.c
52181@@ -23,6 +23,7 @@
52182 #include <linux/nsproxy.h>
52183 #include <net/net_namespace.h>
52184 #include <linux/seq_file.h>
52185+#include <linux/grsecurity.h>
52186
52187 #include "internal.h"
52188
52189@@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
52190 struct task_struct *task;
52191 struct nsproxy *ns;
52192 struct net *net = NULL;
52193+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52194+ const struct cred *cred = current_cred();
52195+#endif
52196+
52197+#ifdef CONFIG_GRKERNSEC_PROC_USER
52198+ if (cred->fsuid)
52199+ return net;
52200+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52201+ if (cred->fsuid && !in_group_p(grsec_proc_gid))
52202+ return net;
52203+#endif
52204
52205 rcu_read_lock();
52206 task = pid_task(proc_pid(dir), PIDTYPE_PID);
52207diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
52208index 1827d88..9a60b01 100644
52209--- a/fs/proc/proc_sysctl.c
52210+++ b/fs/proc/proc_sysctl.c
52211@@ -12,11 +12,15 @@
52212 #include <linux/module.h>
52213 #include "internal.h"
52214
52215+extern int gr_handle_chroot_sysctl(const int op);
52216+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
52217+ const int op);
52218+
52219 static const struct dentry_operations proc_sys_dentry_operations;
52220 static const struct file_operations proc_sys_file_operations;
52221-static const struct inode_operations proc_sys_inode_operations;
52222+const struct inode_operations proc_sys_inode_operations;
52223 static const struct file_operations proc_sys_dir_file_operations;
52224-static const struct inode_operations proc_sys_dir_operations;
52225+const struct inode_operations proc_sys_dir_operations;
52226
52227 void proc_sys_poll_notify(struct ctl_table_poll *poll)
52228 {
52229@@ -466,6 +470,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
52230
52231 err = NULL;
52232 d_set_d_op(dentry, &proc_sys_dentry_operations);
52233+
52234+ gr_handle_proc_create(dentry, inode);
52235+
52236 d_add(dentry, inode);
52237
52238 out:
52239@@ -481,6 +488,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
52240 struct inode *inode = filp->f_path.dentry->d_inode;
52241 struct ctl_table_header *head = grab_header(inode);
52242 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
52243+ int op = write ? MAY_WRITE : MAY_READ;
52244 ssize_t error;
52245 size_t res;
52246
52247@@ -492,7 +500,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
52248 * and won't be until we finish.
52249 */
52250 error = -EPERM;
52251- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
52252+ if (sysctl_perm(head, table, op))
52253 goto out;
52254
52255 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
52256@@ -500,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
52257 if (!table->proc_handler)
52258 goto out;
52259
52260+#ifdef CONFIG_GRKERNSEC
52261+ error = -EPERM;
52262+ if (gr_handle_chroot_sysctl(op))
52263+ goto out;
52264+ dget(filp->f_path.dentry);
52265+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
52266+ dput(filp->f_path.dentry);
52267+ goto out;
52268+ }
52269+ dput(filp->f_path.dentry);
52270+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
52271+ goto out;
52272+ if (write && !capable(CAP_SYS_ADMIN))
52273+ goto out;
52274+#endif
52275+
52276 /* careful: calling conventions are nasty here */
52277 res = count;
52278 error = table->proc_handler(table, write, buf, &res, ppos);
52279@@ -597,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
52280 return -ENOMEM;
52281 } else {
52282 d_set_d_op(child, &proc_sys_dentry_operations);
52283+
52284+ gr_handle_proc_create(child, inode);
52285+
52286 d_add(child, inode);
52287 }
52288 } else {
52289@@ -640,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
52290 if ((*pos)++ < file->f_pos)
52291 return 0;
52292
52293+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
52294+ return 0;
52295+
52296 if (unlikely(S_ISLNK(table->mode)))
52297 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
52298 else
52299@@ -750,6 +780,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
52300 if (IS_ERR(head))
52301 return PTR_ERR(head);
52302
52303+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
52304+ return -ENOENT;
52305+
52306 generic_fillattr(inode, stat);
52307 if (table)
52308 stat->mode = (stat->mode & S_IFMT) | table->mode;
52309@@ -772,13 +805,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
52310 .llseek = generic_file_llseek,
52311 };
52312
52313-static const struct inode_operations proc_sys_inode_operations = {
52314+const struct inode_operations proc_sys_inode_operations = {
52315 .permission = proc_sys_permission,
52316 .setattr = proc_sys_setattr,
52317 .getattr = proc_sys_getattr,
52318 };
52319
52320-static const struct inode_operations proc_sys_dir_operations = {
52321+const struct inode_operations proc_sys_dir_operations = {
52322 .lookup = proc_sys_lookup,
52323 .permission = proc_sys_permission,
52324 .setattr = proc_sys_setattr,
52325diff --git a/fs/proc/root.c b/fs/proc/root.c
52326index c6e9fac..a740964 100644
52327--- a/fs/proc/root.c
52328+++ b/fs/proc/root.c
52329@@ -176,7 +176,15 @@ void __init proc_root_init(void)
52330 #ifdef CONFIG_PROC_DEVICETREE
52331 proc_device_tree_init();
52332 #endif
52333+#ifdef CONFIG_GRKERNSEC_PROC_ADD
52334+#ifdef CONFIG_GRKERNSEC_PROC_USER
52335+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
52336+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52337+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
52338+#endif
52339+#else
52340 proc_mkdir("bus", NULL);
52341+#endif
52342 proc_sys_init();
52343 }
52344
52345diff --git a/fs/proc/self.c b/fs/proc/self.c
52346index aa5cc3b..c91a5d0 100644
52347--- a/fs/proc/self.c
52348+++ b/fs/proc/self.c
52349@@ -37,7 +37,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
52350 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
52351 void *cookie)
52352 {
52353- char *s = nd_get_link(nd);
52354+ const char *s = nd_get_link(nd);
52355 if (!IS_ERR(s))
52356 kfree(s);
52357 }
52358diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
52359index ca5ce7f..02c1cf0 100644
52360--- a/fs/proc/task_mmu.c
52361+++ b/fs/proc/task_mmu.c
52362@@ -11,12 +11,19 @@
52363 #include <linux/rmap.h>
52364 #include <linux/swap.h>
52365 #include <linux/swapops.h>
52366+#include <linux/grsecurity.h>
52367
52368 #include <asm/elf.h>
52369 #include <asm/uaccess.h>
52370 #include <asm/tlbflush.h>
52371 #include "internal.h"
52372
52373+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52374+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
52375+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
52376+ _mm->pax_flags & MF_PAX_SEGMEXEC))
52377+#endif
52378+
52379 void task_mem(struct seq_file *m, struct mm_struct *mm)
52380 {
52381 unsigned long data, text, lib, swap;
52382@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
52383 "VmExe:\t%8lu kB\n"
52384 "VmLib:\t%8lu kB\n"
52385 "VmPTE:\t%8lu kB\n"
52386- "VmSwap:\t%8lu kB\n",
52387- hiwater_vm << (PAGE_SHIFT-10),
52388+ "VmSwap:\t%8lu kB\n"
52389+
52390+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
52391+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
52392+#endif
52393+
52394+ ,hiwater_vm << (PAGE_SHIFT-10),
52395 total_vm << (PAGE_SHIFT-10),
52396 mm->locked_vm << (PAGE_SHIFT-10),
52397 mm->pinned_vm << (PAGE_SHIFT-10),
52398@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
52399 data << (PAGE_SHIFT-10),
52400 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
52401 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
52402- swap << (PAGE_SHIFT-10));
52403+ swap << (PAGE_SHIFT-10)
52404+
52405+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
52406+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52407+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
52408+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
52409+#else
52410+ , mm->context.user_cs_base
52411+ , mm->context.user_cs_limit
52412+#endif
52413+#endif
52414+
52415+ );
52416 }
52417
52418 unsigned long task_vsize(struct mm_struct *mm)
52419@@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
52420 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
52421 }
52422
52423- /* We don't show the stack guard page in /proc/maps */
52424+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52425+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
52426+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
52427+#else
52428 start = vma->vm_start;
52429- if (stack_guard_page_start(vma, start))
52430- start += PAGE_SIZE;
52431 end = vma->vm_end;
52432- if (stack_guard_page_end(vma, end))
52433- end -= PAGE_SIZE;
52434+#endif
52435
52436 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
52437 start,
52438@@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
52439 flags & VM_WRITE ? 'w' : '-',
52440 flags & VM_EXEC ? 'x' : '-',
52441 flags & VM_MAYSHARE ? 's' : 'p',
52442+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52443+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
52444+#else
52445 pgoff,
52446+#endif
52447 MAJOR(dev), MINOR(dev), ino, &len);
52448
52449 /*
52450@@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
52451 */
52452 if (file) {
52453 pad_len_spaces(m, len);
52454- seq_path(m, &file->f_path, "\n");
52455+ seq_path(m, &file->f_path, "\n\\");
52456 goto done;
52457 }
52458
52459@@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
52460 * Thread stack in /proc/PID/task/TID/maps or
52461 * the main process stack.
52462 */
52463- if (!is_pid || (vma->vm_start <= mm->start_stack &&
52464- vma->vm_end >= mm->start_stack)) {
52465+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
52466+ (vma->vm_start <= mm->start_stack &&
52467+ vma->vm_end >= mm->start_stack)) {
52468 name = "[stack]";
52469 } else {
52470 /* Thread stack in /proc/PID/maps */
52471@@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
52472 struct proc_maps_private *priv = m->private;
52473 struct task_struct *task = priv->task;
52474
52475+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52476+ if (current->exec_id != m->exec_id) {
52477+ gr_log_badprocpid("maps");
52478+ return 0;
52479+ }
52480+#endif
52481+
52482 show_map_vma(m, vma, is_pid);
52483
52484 if (m->count < m->size) /* vma is copied successfully */
52485@@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
52486 .private = &mss,
52487 };
52488
52489+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52490+ if (current->exec_id != m->exec_id) {
52491+ gr_log_badprocpid("smaps");
52492+ return 0;
52493+ }
52494+#endif
52495 memset(&mss, 0, sizeof mss);
52496- mss.vma = vma;
52497- /* mmap_sem is held in m_start */
52498- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
52499- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
52500-
52501+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52502+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
52503+#endif
52504+ mss.vma = vma;
52505+ /* mmap_sem is held in m_start */
52506+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
52507+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
52508+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52509+ }
52510+#endif
52511 show_map_vma(m, vma, is_pid);
52512
52513 seq_printf(m,
52514@@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
52515 "KernelPageSize: %8lu kB\n"
52516 "MMUPageSize: %8lu kB\n"
52517 "Locked: %8lu kB\n",
52518+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52519+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
52520+#else
52521 (vma->vm_end - vma->vm_start) >> 10,
52522+#endif
52523 mss.resident >> 10,
52524 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
52525 mss.shared_clean >> 10,
52526@@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
52527 int n;
52528 char buffer[50];
52529
52530+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52531+ if (current->exec_id != m->exec_id) {
52532+ gr_log_badprocpid("numa_maps");
52533+ return 0;
52534+ }
52535+#endif
52536+
52537 if (!mm)
52538 return 0;
52539
52540@@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
52541 mpol_to_str(buffer, sizeof(buffer), pol);
52542 mpol_cond_put(pol);
52543
52544+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52545+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
52546+#else
52547 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
52548+#endif
52549
52550 if (file) {
52551 seq_printf(m, " file=");
52552- seq_path(m, &file->f_path, "\n\t= ");
52553+ seq_path(m, &file->f_path, "\n\t\\= ");
52554 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
52555 seq_printf(m, " heap");
52556 } else {
52557diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
52558index 1ccfa53..0848f95 100644
52559--- a/fs/proc/task_nommu.c
52560+++ b/fs/proc/task_nommu.c
52561@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
52562 else
52563 bytes += kobjsize(mm);
52564
52565- if (current->fs && current->fs->users > 1)
52566+ if (current->fs && atomic_read(&current->fs->users) > 1)
52567 sbytes += kobjsize(current->fs);
52568 else
52569 bytes += kobjsize(current->fs);
52570@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
52571
52572 if (file) {
52573 pad_len_spaces(m, len);
52574- seq_path(m, &file->f_path, "");
52575+ seq_path(m, &file->f_path, "\n\\");
52576 } else if (mm) {
52577 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
52578
52579diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
52580index 16e8abb..2dcf914 100644
52581--- a/fs/quota/netlink.c
52582+++ b/fs/quota/netlink.c
52583@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
52584 void quota_send_warning(struct kqid qid, dev_t dev,
52585 const char warntype)
52586 {
52587- static atomic_t seq;
52588+ static atomic_unchecked_t seq;
52589 struct sk_buff *skb;
52590 void *msg_head;
52591 int ret;
52592@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
52593 "VFS: Not enough memory to send quota warning.\n");
52594 return;
52595 }
52596- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
52597+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
52598 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
52599 if (!msg_head) {
52600 printk(KERN_ERR
52601diff --git a/fs/readdir.c b/fs/readdir.c
52602index 5e69ef5..e5d9099 100644
52603--- a/fs/readdir.c
52604+++ b/fs/readdir.c
52605@@ -17,6 +17,7 @@
52606 #include <linux/security.h>
52607 #include <linux/syscalls.h>
52608 #include <linux/unistd.h>
52609+#include <linux/namei.h>
52610
52611 #include <asm/uaccess.h>
52612
52613@@ -67,6 +68,7 @@ struct old_linux_dirent {
52614
52615 struct readdir_callback {
52616 struct old_linux_dirent __user * dirent;
52617+ struct file * file;
52618 int result;
52619 };
52620
52621@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
52622 buf->result = -EOVERFLOW;
52623 return -EOVERFLOW;
52624 }
52625+
52626+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
52627+ return 0;
52628+
52629 buf->result++;
52630 dirent = buf->dirent;
52631 if (!access_ok(VERIFY_WRITE, dirent,
52632@@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
52633
52634 buf.result = 0;
52635 buf.dirent = dirent;
52636+ buf.file = f.file;
52637
52638 error = vfs_readdir(f.file, fillonedir, &buf);
52639 if (buf.result)
52640@@ -139,6 +146,7 @@ struct linux_dirent {
52641 struct getdents_callback {
52642 struct linux_dirent __user * current_dir;
52643 struct linux_dirent __user * previous;
52644+ struct file * file;
52645 int count;
52646 int error;
52647 };
52648@@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
52649 buf->error = -EOVERFLOW;
52650 return -EOVERFLOW;
52651 }
52652+
52653+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
52654+ return 0;
52655+
52656 dirent = buf->previous;
52657 if (dirent) {
52658 if (__put_user(offset, &dirent->d_off))
52659@@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
52660 buf.previous = NULL;
52661 buf.count = count;
52662 buf.error = 0;
52663+ buf.file = f.file;
52664
52665 error = vfs_readdir(f.file, filldir, &buf);
52666 if (error >= 0)
52667@@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
52668 struct getdents_callback64 {
52669 struct linux_dirent64 __user * current_dir;
52670 struct linux_dirent64 __user * previous;
52671+ struct file *file;
52672 int count;
52673 int error;
52674 };
52675@@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
52676 buf->error = -EINVAL; /* only used if we fail.. */
52677 if (reclen > buf->count)
52678 return -EINVAL;
52679+
52680+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
52681+ return 0;
52682+
52683 dirent = buf->previous;
52684 if (dirent) {
52685 if (__put_user(offset, &dirent->d_off))
52686@@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
52687
52688 buf.current_dir = dirent;
52689 buf.previous = NULL;
52690+ buf.file = f.file;
52691 buf.count = count;
52692 buf.error = 0;
52693
52694@@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
52695 error = buf.error;
52696 lastdirent = buf.previous;
52697 if (lastdirent) {
52698- typeof(lastdirent->d_off) d_off = f.file->f_pos;
52699+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
52700 if (__put_user(d_off, &lastdirent->d_off))
52701 error = -EFAULT;
52702 else
52703diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
52704index 2b7882b..1c5ef48 100644
52705--- a/fs/reiserfs/do_balan.c
52706+++ b/fs/reiserfs/do_balan.c
52707@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
52708 return;
52709 }
52710
52711- atomic_inc(&(fs_generation(tb->tb_sb)));
52712+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
52713 do_balance_starts(tb);
52714
52715 /* balance leaf returns 0 except if combining L R and S into
52716diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
52717index e60e870..f40ac16 100644
52718--- a/fs/reiserfs/procfs.c
52719+++ b/fs/reiserfs/procfs.c
52720@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
52721 "SMALL_TAILS " : "NO_TAILS ",
52722 replay_only(sb) ? "REPLAY_ONLY " : "",
52723 convert_reiserfs(sb) ? "CONV " : "",
52724- atomic_read(&r->s_generation_counter),
52725+ atomic_read_unchecked(&r->s_generation_counter),
52726 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
52727 SF(s_do_balance), SF(s_unneeded_left_neighbor),
52728 SF(s_good_search_by_key_reada), SF(s_bmaps),
52729diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
52730index 157e474..65a6114 100644
52731--- a/fs/reiserfs/reiserfs.h
52732+++ b/fs/reiserfs/reiserfs.h
52733@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
52734 /* Comment? -Hans */
52735 wait_queue_head_t s_wait;
52736 /* To be obsoleted soon by per buffer seals.. -Hans */
52737- atomic_t s_generation_counter; // increased by one every time the
52738+ atomic_unchecked_t s_generation_counter; // increased by one every time the
52739 // tree gets re-balanced
52740 unsigned long s_properties; /* File system properties. Currently holds
52741 on-disk FS format */
52742@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
52743 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
52744
52745 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
52746-#define get_generation(s) atomic_read (&fs_generation(s))
52747+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
52748 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
52749 #define __fs_changed(gen,s) (gen != get_generation (s))
52750 #define fs_changed(gen,s) \
52751diff --git a/fs/select.c b/fs/select.c
52752index 2ef72d9..f213b17 100644
52753--- a/fs/select.c
52754+++ b/fs/select.c
52755@@ -20,6 +20,7 @@
52756 #include <linux/export.h>
52757 #include <linux/slab.h>
52758 #include <linux/poll.h>
52759+#include <linux/security.h>
52760 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
52761 #include <linux/file.h>
52762 #include <linux/fdtable.h>
52763@@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
52764 struct poll_list *walk = head;
52765 unsigned long todo = nfds;
52766
52767+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
52768 if (nfds > rlimit(RLIMIT_NOFILE))
52769 return -EINVAL;
52770
52771diff --git a/fs/seq_file.c b/fs/seq_file.c
52772index f2bc3df..239d4f6 100644
52773--- a/fs/seq_file.c
52774+++ b/fs/seq_file.c
52775@@ -10,6 +10,7 @@
52776 #include <linux/seq_file.h>
52777 #include <linux/slab.h>
52778 #include <linux/cred.h>
52779+#include <linux/sched.h>
52780
52781 #include <asm/uaccess.h>
52782 #include <asm/page.h>
52783@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
52784 #ifdef CONFIG_USER_NS
52785 p->user_ns = file->f_cred->user_ns;
52786 #endif
52787+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52788+ p->exec_id = current->exec_id;
52789+#endif
52790
52791 /*
52792 * Wrappers around seq_open(e.g. swaps_open) need to be
52793@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
52794 return 0;
52795 }
52796 if (!m->buf) {
52797- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
52798+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
52799 if (!m->buf)
52800 return -ENOMEM;
52801 }
52802@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
52803 Eoverflow:
52804 m->op->stop(m, p);
52805 kfree(m->buf);
52806- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
52807+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
52808 return !m->buf ? -ENOMEM : -EAGAIN;
52809 }
52810
52811@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
52812
52813 /* grab buffer if we didn't have one */
52814 if (!m->buf) {
52815- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
52816+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
52817 if (!m->buf)
52818 goto Enomem;
52819 }
52820@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
52821 goto Fill;
52822 m->op->stop(m, p);
52823 kfree(m->buf);
52824- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
52825+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
52826 if (!m->buf)
52827 goto Enomem;
52828 m->count = 0;
52829@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
52830 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
52831 void *data)
52832 {
52833- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
52834+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
52835 int res = -ENOMEM;
52836
52837 if (op) {
52838diff --git a/fs/splice.c b/fs/splice.c
52839index 6909d89..5b2e8f9 100644
52840--- a/fs/splice.c
52841+++ b/fs/splice.c
52842@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
52843 pipe_lock(pipe);
52844
52845 for (;;) {
52846- if (!pipe->readers) {
52847+ if (!atomic_read(&pipe->readers)) {
52848 send_sig(SIGPIPE, current, 0);
52849 if (!ret)
52850 ret = -EPIPE;
52851@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
52852 do_wakeup = 0;
52853 }
52854
52855- pipe->waiting_writers++;
52856+ atomic_inc(&pipe->waiting_writers);
52857 pipe_wait(pipe);
52858- pipe->waiting_writers--;
52859+ atomic_dec(&pipe->waiting_writers);
52860 }
52861
52862 pipe_unlock(pipe);
52863@@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
52864 old_fs = get_fs();
52865 set_fs(get_ds());
52866 /* The cast to a user pointer is valid due to the set_fs() */
52867- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
52868+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
52869 set_fs(old_fs);
52870
52871 return res;
52872@@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
52873 old_fs = get_fs();
52874 set_fs(get_ds());
52875 /* The cast to a user pointer is valid due to the set_fs() */
52876- res = vfs_write(file, (const char __user *)buf, count, &pos);
52877+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
52878 set_fs(old_fs);
52879
52880 return res;
52881@@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
52882 goto err;
52883
52884 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
52885- vec[i].iov_base = (void __user *) page_address(page);
52886+ vec[i].iov_base = (void __force_user *) page_address(page);
52887 vec[i].iov_len = this_len;
52888 spd.pages[i] = page;
52889 spd.nr_pages++;
52890@@ -851,10 +851,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
52891 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
52892 {
52893 while (!pipe->nrbufs) {
52894- if (!pipe->writers)
52895+ if (!atomic_read(&pipe->writers))
52896 return 0;
52897
52898- if (!pipe->waiting_writers && sd->num_spliced)
52899+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
52900 return 0;
52901
52902 if (sd->flags & SPLICE_F_NONBLOCK)
52903@@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
52904 * out of the pipe right after the splice_to_pipe(). So set
52905 * PIPE_READERS appropriately.
52906 */
52907- pipe->readers = 1;
52908+ atomic_set(&pipe->readers, 1);
52909
52910 current->splice_pipe = pipe;
52911 }
52912@@ -1738,9 +1738,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
52913 ret = -ERESTARTSYS;
52914 break;
52915 }
52916- if (!pipe->writers)
52917+ if (!atomic_read(&pipe->writers))
52918 break;
52919- if (!pipe->waiting_writers) {
52920+ if (!atomic_read(&pipe->waiting_writers)) {
52921 if (flags & SPLICE_F_NONBLOCK) {
52922 ret = -EAGAIN;
52923 break;
52924@@ -1772,7 +1772,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
52925 pipe_lock(pipe);
52926
52927 while (pipe->nrbufs >= pipe->buffers) {
52928- if (!pipe->readers) {
52929+ if (!atomic_read(&pipe->readers)) {
52930 send_sig(SIGPIPE, current, 0);
52931 ret = -EPIPE;
52932 break;
52933@@ -1785,9 +1785,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
52934 ret = -ERESTARTSYS;
52935 break;
52936 }
52937- pipe->waiting_writers++;
52938+ atomic_inc(&pipe->waiting_writers);
52939 pipe_wait(pipe);
52940- pipe->waiting_writers--;
52941+ atomic_dec(&pipe->waiting_writers);
52942 }
52943
52944 pipe_unlock(pipe);
52945@@ -1823,14 +1823,14 @@ retry:
52946 pipe_double_lock(ipipe, opipe);
52947
52948 do {
52949- if (!opipe->readers) {
52950+ if (!atomic_read(&opipe->readers)) {
52951 send_sig(SIGPIPE, current, 0);
52952 if (!ret)
52953 ret = -EPIPE;
52954 break;
52955 }
52956
52957- if (!ipipe->nrbufs && !ipipe->writers)
52958+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
52959 break;
52960
52961 /*
52962@@ -1927,7 +1927,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
52963 pipe_double_lock(ipipe, opipe);
52964
52965 do {
52966- if (!opipe->readers) {
52967+ if (!atomic_read(&opipe->readers)) {
52968 send_sig(SIGPIPE, current, 0);
52969 if (!ret)
52970 ret = -EPIPE;
52971@@ -1972,7 +1972,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
52972 * return EAGAIN if we have the potential of some data in the
52973 * future, otherwise just return 0
52974 */
52975- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
52976+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
52977 ret = -EAGAIN;
52978
52979 pipe_unlock(ipipe);
52980diff --git a/fs/stat.c b/fs/stat.c
52981index 14f4545..9b7f55b 100644
52982--- a/fs/stat.c
52983+++ b/fs/stat.c
52984@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
52985 stat->gid = inode->i_gid;
52986 stat->rdev = inode->i_rdev;
52987 stat->size = i_size_read(inode);
52988- stat->atime = inode->i_atime;
52989- stat->mtime = inode->i_mtime;
52990+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
52991+ stat->atime = inode->i_ctime;
52992+ stat->mtime = inode->i_ctime;
52993+ } else {
52994+ stat->atime = inode->i_atime;
52995+ stat->mtime = inode->i_mtime;
52996+ }
52997 stat->ctime = inode->i_ctime;
52998 stat->blksize = (1 << inode->i_blkbits);
52999 stat->blocks = inode->i_blocks;
53000@@ -46,8 +51,14 @@ int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
53001 if (retval)
53002 return retval;
53003
53004- if (inode->i_op->getattr)
53005- return inode->i_op->getattr(mnt, dentry, stat);
53006+ if (inode->i_op->getattr) {
53007+ retval = inode->i_op->getattr(mnt, dentry, stat);
53008+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
53009+ stat->atime = stat->ctime;
53010+ stat->mtime = stat->ctime;
53011+ }
53012+ return retval;
53013+ }
53014
53015 generic_fillattr(inode, stat);
53016 return 0;
53017diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
53018index 2fbdff6..5530a61 100644
53019--- a/fs/sysfs/dir.c
53020+++ b/fs/sysfs/dir.c
53021@@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
53022 struct sysfs_dirent *sd;
53023 int rc;
53024
53025+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
53026+ const char *parent_name = parent_sd->s_name;
53027+
53028+ mode = S_IFDIR | S_IRWXU;
53029+
53030+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
53031+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
53032+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
53033+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
53034+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
53035+#endif
53036+
53037 /* allocate */
53038 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
53039 if (!sd)
53040diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
53041index 602f56d..6853db8 100644
53042--- a/fs/sysfs/file.c
53043+++ b/fs/sysfs/file.c
53044@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
53045
53046 struct sysfs_open_dirent {
53047 atomic_t refcnt;
53048- atomic_t event;
53049+ atomic_unchecked_t event;
53050 wait_queue_head_t poll;
53051 struct list_head buffers; /* goes through sysfs_buffer.list */
53052 };
53053@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
53054 if (!sysfs_get_active(attr_sd))
53055 return -ENODEV;
53056
53057- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
53058+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
53059 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
53060
53061 sysfs_put_active(attr_sd);
53062@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
53063 return -ENOMEM;
53064
53065 atomic_set(&new_od->refcnt, 0);
53066- atomic_set(&new_od->event, 1);
53067+ atomic_set_unchecked(&new_od->event, 1);
53068 init_waitqueue_head(&new_od->poll);
53069 INIT_LIST_HEAD(&new_od->buffers);
53070 goto retry;
53071@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
53072
53073 sysfs_put_active(attr_sd);
53074
53075- if (buffer->event != atomic_read(&od->event))
53076+ if (buffer->event != atomic_read_unchecked(&od->event))
53077 goto trigger;
53078
53079 return DEFAULT_POLLMASK;
53080@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
53081
53082 od = sd->s_attr.open;
53083 if (od) {
53084- atomic_inc(&od->event);
53085+ atomic_inc_unchecked(&od->event);
53086 wake_up_interruptible(&od->poll);
53087 }
53088
53089diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
53090index 3c9eb56..9dea5be 100644
53091--- a/fs/sysfs/symlink.c
53092+++ b/fs/sysfs/symlink.c
53093@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
53094
53095 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
53096 {
53097- char *page = nd_get_link(nd);
53098+ const char *page = nd_get_link(nd);
53099 if (!IS_ERR(page))
53100 free_page((unsigned long)page);
53101 }
53102diff --git a/fs/udf/misc.c b/fs/udf/misc.c
53103index c175b4d..8f36a16 100644
53104--- a/fs/udf/misc.c
53105+++ b/fs/udf/misc.c
53106@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
53107
53108 u8 udf_tag_checksum(const struct tag *t)
53109 {
53110- u8 *data = (u8 *)t;
53111+ const u8 *data = (const u8 *)t;
53112 u8 checksum = 0;
53113 int i;
53114 for (i = 0; i < sizeof(struct tag); ++i)
53115diff --git a/fs/utimes.c b/fs/utimes.c
53116index f4fb7ec..3fe03c0 100644
53117--- a/fs/utimes.c
53118+++ b/fs/utimes.c
53119@@ -1,6 +1,7 @@
53120 #include <linux/compiler.h>
53121 #include <linux/file.h>
53122 #include <linux/fs.h>
53123+#include <linux/security.h>
53124 #include <linux/linkage.h>
53125 #include <linux/mount.h>
53126 #include <linux/namei.h>
53127@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
53128 goto mnt_drop_write_and_out;
53129 }
53130 }
53131+
53132+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
53133+ error = -EACCES;
53134+ goto mnt_drop_write_and_out;
53135+ }
53136+
53137 mutex_lock(&inode->i_mutex);
53138 error = notify_change(path->dentry, &newattrs);
53139 mutex_unlock(&inode->i_mutex);
53140diff --git a/fs/xattr.c b/fs/xattr.c
53141index 3377dff..4feded6 100644
53142--- a/fs/xattr.c
53143+++ b/fs/xattr.c
53144@@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
53145 * Extended attribute SET operations
53146 */
53147 static long
53148-setxattr(struct dentry *d, const char __user *name, const void __user *value,
53149+setxattr(struct path *path, const char __user *name, const void __user *value,
53150 size_t size, int flags)
53151 {
53152 int error;
53153@@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
53154 posix_acl_fix_xattr_from_user(kvalue, size);
53155 }
53156
53157- error = vfs_setxattr(d, kname, kvalue, size, flags);
53158+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
53159+ error = -EACCES;
53160+ goto out;
53161+ }
53162+
53163+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
53164 out:
53165 if (vvalue)
53166 vfree(vvalue);
53167@@ -377,7 +382,7 @@ retry:
53168 return error;
53169 error = mnt_want_write(path.mnt);
53170 if (!error) {
53171- error = setxattr(path.dentry, name, value, size, flags);
53172+ error = setxattr(&path, name, value, size, flags);
53173 mnt_drop_write(path.mnt);
53174 }
53175 path_put(&path);
53176@@ -401,7 +406,7 @@ retry:
53177 return error;
53178 error = mnt_want_write(path.mnt);
53179 if (!error) {
53180- error = setxattr(path.dentry, name, value, size, flags);
53181+ error = setxattr(&path, name, value, size, flags);
53182 mnt_drop_write(path.mnt);
53183 }
53184 path_put(&path);
53185@@ -416,16 +421,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
53186 const void __user *,value, size_t, size, int, flags)
53187 {
53188 struct fd f = fdget(fd);
53189- struct dentry *dentry;
53190 int error = -EBADF;
53191
53192 if (!f.file)
53193 return error;
53194- dentry = f.file->f_path.dentry;
53195- audit_inode(NULL, dentry, 0);
53196+ audit_inode(NULL, f.file->f_path.dentry, 0);
53197 error = mnt_want_write_file(f.file);
53198 if (!error) {
53199- error = setxattr(dentry, name, value, size, flags);
53200+ error = setxattr(&f.file->f_path, name, value, size, flags);
53201 mnt_drop_write_file(f.file);
53202 }
53203 fdput(f);
53204diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
53205index 9fbea87..6b19972 100644
53206--- a/fs/xattr_acl.c
53207+++ b/fs/xattr_acl.c
53208@@ -76,8 +76,8 @@ struct posix_acl *
53209 posix_acl_from_xattr(struct user_namespace *user_ns,
53210 const void *value, size_t size)
53211 {
53212- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
53213- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
53214+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
53215+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
53216 int count;
53217 struct posix_acl *acl;
53218 struct posix_acl_entry *acl_e;
53219diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
53220index cdb2d33..704ce7f 100644
53221--- a/fs/xfs/xfs_bmap.c
53222+++ b/fs/xfs/xfs_bmap.c
53223@@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
53224 int nmap,
53225 int ret_nmap);
53226 #else
53227-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
53228+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
53229 #endif /* DEBUG */
53230
53231 STATIC int
53232diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
53233index 1b9fc3e..e1bdde0 100644
53234--- a/fs/xfs/xfs_dir2_sf.c
53235+++ b/fs/xfs/xfs_dir2_sf.c
53236@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
53237 }
53238
53239 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
53240- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
53241+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
53242+ char name[sfep->namelen];
53243+ memcpy(name, sfep->name, sfep->namelen);
53244+ if (filldir(dirent, name, sfep->namelen,
53245+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
53246+ *offset = off & 0x7fffffff;
53247+ return 0;
53248+ }
53249+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
53250 off & 0x7fffffff, ino, DT_UNKNOWN)) {
53251 *offset = off & 0x7fffffff;
53252 return 0;
53253diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
53254index c1c3ef8..0952438 100644
53255--- a/fs/xfs/xfs_ioctl.c
53256+++ b/fs/xfs/xfs_ioctl.c
53257@@ -127,7 +127,7 @@ xfs_find_handle(
53258 }
53259
53260 error = -EFAULT;
53261- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
53262+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
53263 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
53264 goto out_put;
53265
53266diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
53267index d82efaa..0904a8e 100644
53268--- a/fs/xfs/xfs_iops.c
53269+++ b/fs/xfs/xfs_iops.c
53270@@ -395,7 +395,7 @@ xfs_vn_put_link(
53271 struct nameidata *nd,
53272 void *p)
53273 {
53274- char *s = nd_get_link(nd);
53275+ const char *s = nd_get_link(nd);
53276
53277 if (!IS_ERR(s))
53278 kfree(s);
53279diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
53280new file mode 100644
53281index 0000000..92247e4
53282--- /dev/null
53283+++ b/grsecurity/Kconfig
53284@@ -0,0 +1,1021 @@
53285+#
53286+# grecurity configuration
53287+#
53288+menu "Memory Protections"
53289+depends on GRKERNSEC
53290+
53291+config GRKERNSEC_KMEM
53292+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
53293+ default y if GRKERNSEC_CONFIG_AUTO
53294+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
53295+ help
53296+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
53297+ be written to or read from to modify or leak the contents of the running
53298+ kernel. /dev/port will also not be allowed to be opened and support
53299+ for /dev/cpu/*/msr will be removed. If you have module
53300+ support disabled, enabling this will close up five ways that are
53301+ currently used to insert malicious code into the running kernel.
53302+
53303+ Even with all these features enabled, we still highly recommend that
53304+ you use the RBAC system, as it is still possible for an attacker to
53305+ modify the running kernel through privileged I/O granted by ioperm/iopl.
53306+
53307+ If you are not using XFree86, you may be able to stop this additional
53308+ case by enabling the 'Disable privileged I/O' option. Though nothing
53309+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
53310+ but only to video memory, which is the only writing we allow in this
53311+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
53312+ not be allowed to mprotect it with PROT_WRITE later.
53313+ Enabling this feature will prevent the "cpupower" and "powertop" tools
53314+ from working.
53315+
53316+ It is highly recommended that you say Y here if you meet all the
53317+ conditions above.
53318+
53319+config GRKERNSEC_VM86
53320+ bool "Restrict VM86 mode"
53321+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
53322+ depends on X86_32
53323+
53324+ help
53325+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
53326+ make use of a special execution mode on 32bit x86 processors called
53327+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
53328+ video cards and will still work with this option enabled. The purpose
53329+ of the option is to prevent exploitation of emulation errors in
53330+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
53331+ Nearly all users should be able to enable this option.
53332+
53333+config GRKERNSEC_IO
53334+ bool "Disable privileged I/O"
53335+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
53336+ depends on X86
53337+ select RTC_CLASS
53338+ select RTC_INTF_DEV
53339+ select RTC_DRV_CMOS
53340+
53341+ help
53342+ If you say Y here, all ioperm and iopl calls will return an error.
53343+ Ioperm and iopl can be used to modify the running kernel.
53344+ Unfortunately, some programs need this access to operate properly,
53345+ the most notable of which are XFree86 and hwclock. hwclock can be
53346+ remedied by having RTC support in the kernel, so real-time
53347+ clock support is enabled if this option is enabled, to ensure
53348+ that hwclock operates correctly. XFree86 still will not
53349+ operate correctly with this option enabled, so DO NOT CHOOSE Y
53350+ IF YOU USE XFree86. If you use XFree86 and you still want to
53351+ protect your kernel against modification, use the RBAC system.
53352+
53353+config GRKERNSEC_JIT_HARDEN
53354+ bool "Harden BPF JIT against spray attacks"
53355+ default y if GRKERNSEC_CONFIG_AUTO
53356+ depends on BPF_JIT
53357+ help
53358+ If you say Y here, the native code generated by the kernel's Berkeley
53359+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
53360+ attacks that attempt to fit attacker-beneficial instructions in
53361+ 32bit immediate fields of JIT-generated native instructions. The
53362+ attacker will generally aim to cause an unintended instruction sequence
53363+ of JIT-generated native code to execute by jumping into the middle of
53364+ a generated instruction. This feature effectively randomizes the 32bit
53365+ immediate constants present in the generated code to thwart such attacks.
53366+
53367+ If you're using KERNEXEC, it's recommended that you enable this option
53368+ to supplement the hardening of the kernel.
53369+
53370+config GRKERNSEC_RAND_THREADSTACK
53371+ bool "Insert random gaps between thread stacks"
53372+ default y if GRKERNSEC_CONFIG_AUTO
53373+ depends on PAX_RANDMMAP && !PPC
53374+ help
53375+ If you say Y here, a random-sized gap will be enforced between allocated
53376+ thread stacks. Glibc's NPTL and other threading libraries that
53377+ pass MAP_STACK to the kernel for thread stack allocation are supported.
53378+ The implementation currently provides 8 bits of entropy for the gap.
53379+
53380+ Many distributions do not compile threaded remote services with the
53381+ -fstack-check argument to GCC, causing the variable-sized stack-based
53382+ allocator, alloca(), to not probe the stack on allocation. This
53383+ permits an unbounded alloca() to skip over any guard page and potentially
53384+ modify another thread's stack reliably. An enforced random gap
53385+ reduces the reliability of such an attack and increases the chance
53386+ that such a read/write to another thread's stack instead lands in
53387+ an unmapped area, causing a crash and triggering grsecurity's
53388+ anti-bruteforcing logic.
53389+
53390+config GRKERNSEC_PROC_MEMMAP
53391+ bool "Harden ASLR against information leaks and entropy reduction"
53392+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
53393+ depends on PAX_NOEXEC || PAX_ASLR
53394+ help
53395+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
53396+ give no information about the addresses of its mappings if
53397+ PaX features that rely on random addresses are enabled on the task.
53398+ In addition to sanitizing this information and disabling other
53399+ dangerous sources of information, this option causes reads of sensitive
53400+ /proc/<pid> entries where the file descriptor was opened in a different
53401+ task than the one performing the read. Such attempts are logged.
53402+ This option also limits argv/env strings for suid/sgid binaries
53403+ to 512KB to prevent a complete exhaustion of the stack entropy provided
53404+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
53405+ binaries to prevent alternative mmap layouts from being abused.
53406+
53407+ If you use PaX it is essential that you say Y here as it closes up
53408+ several holes that make full ASLR useless locally.
53409+
53410+config GRKERNSEC_BRUTE
53411+ bool "Deter exploit bruteforcing"
53412+ default y if GRKERNSEC_CONFIG_AUTO
53413+ help
53414+ If you say Y here, attempts to bruteforce exploits against forking
53415+ daemons such as apache or sshd, as well as against suid/sgid binaries
53416+ will be deterred. When a child of a forking daemon is killed by PaX
53417+ or crashes due to an illegal instruction or other suspicious signal,
53418+ the parent process will be delayed 30 seconds upon every subsequent
53419+ fork until the administrator is able to assess the situation and
53420+ restart the daemon.
53421+ In the suid/sgid case, the attempt is logged, the user has all their
53422+ processes terminated, and they are prevented from executing any further
53423+ processes for 15 minutes.
53424+ It is recommended that you also enable signal logging in the auditing
53425+ section so that logs are generated when a process triggers a suspicious
53426+ signal.
53427+ If the sysctl option is enabled, a sysctl option with name
53428+ "deter_bruteforce" is created.
53429+
53430+
53431+config GRKERNSEC_MODHARDEN
53432+ bool "Harden module auto-loading"
53433+ default y if GRKERNSEC_CONFIG_AUTO
53434+ depends on MODULES
53435+ help
53436+ If you say Y here, module auto-loading in response to use of some
53437+ feature implemented by an unloaded module will be restricted to
53438+ root users. Enabling this option helps defend against attacks
53439+ by unprivileged users who abuse the auto-loading behavior to
53440+ cause a vulnerable module to load that is then exploited.
53441+
53442+ If this option prevents a legitimate use of auto-loading for a
53443+ non-root user, the administrator can execute modprobe manually
53444+ with the exact name of the module mentioned in the alert log.
53445+ Alternatively, the administrator can add the module to the list
53446+ of modules loaded at boot by modifying init scripts.
53447+
53448+ Modification of init scripts will most likely be needed on
53449+ Ubuntu servers with encrypted home directory support enabled,
53450+ as the first non-root user logging in will cause the ecb(aes),
53451+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
53452+
53453+config GRKERNSEC_HIDESYM
53454+ bool "Hide kernel symbols"
53455+ default y if GRKERNSEC_CONFIG_AUTO
53456+ select PAX_USERCOPY_SLABS
53457+ help
53458+ If you say Y here, getting information on loaded modules, and
53459+ displaying all kernel symbols through a syscall will be restricted
53460+ to users with CAP_SYS_MODULE. For software compatibility reasons,
53461+ /proc/kallsyms will be restricted to the root user. The RBAC
53462+ system can hide that entry even from root.
53463+
53464+ This option also prevents leaking of kernel addresses through
53465+ several /proc entries.
53466+
53467+ Note that this option is only effective provided the following
53468+ conditions are met:
53469+ 1) The kernel using grsecurity is not precompiled by some distribution
53470+ 2) You have also enabled GRKERNSEC_DMESG
53471+ 3) You are using the RBAC system and hiding other files such as your
53472+ kernel image and System.map. Alternatively, enabling this option
53473+ causes the permissions on /boot, /lib/modules, and the kernel
53474+ source directory to change at compile time to prevent
53475+ reading by non-root users.
53476+ If the above conditions are met, this option will aid in providing a
53477+ useful protection against local kernel exploitation of overflows
53478+ and arbitrary read/write vulnerabilities.
53479+
53480+config GRKERNSEC_KERN_LOCKOUT
53481+ bool "Active kernel exploit response"
53482+ default y if GRKERNSEC_CONFIG_AUTO
53483+ depends on X86 || ARM || PPC || SPARC
53484+ help
53485+ If you say Y here, when a PaX alert is triggered due to suspicious
53486+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
53487+ or an OOPS occurs due to bad memory accesses, instead of just
53488+ terminating the offending process (and potentially allowing
53489+ a subsequent exploit from the same user), we will take one of two
53490+ actions:
53491+ If the user was root, we will panic the system
53492+ If the user was non-root, we will log the attempt, terminate
53493+ all processes owned by the user, then prevent them from creating
53494+ any new processes until the system is restarted
53495+ This deters repeated kernel exploitation/bruteforcing attempts
53496+ and is useful for later forensics.
53497+
53498+endmenu
53499+menu "Role Based Access Control Options"
53500+depends on GRKERNSEC
53501+
53502+config GRKERNSEC_RBAC_DEBUG
53503+ bool
53504+
53505+config GRKERNSEC_NO_RBAC
53506+ bool "Disable RBAC system"
53507+ help
53508+ If you say Y here, the /dev/grsec device will be removed from the kernel,
53509+ preventing the RBAC system from being enabled. You should only say Y
53510+ here if you have no intention of using the RBAC system, so as to prevent
53511+ an attacker with root access from misusing the RBAC system to hide files
53512+ and processes when loadable module support and /dev/[k]mem have been
53513+ locked down.
53514+
53515+config GRKERNSEC_ACL_HIDEKERN
53516+ bool "Hide kernel processes"
53517+ help
53518+ If you say Y here, all kernel threads will be hidden to all
53519+ processes but those whose subject has the "view hidden processes"
53520+ flag.
53521+
53522+config GRKERNSEC_ACL_MAXTRIES
53523+ int "Maximum tries before password lockout"
53524+ default 3
53525+ help
53526+ This option enforces the maximum number of times a user can attempt
53527+ to authorize themselves with the grsecurity RBAC system before being
53528+ denied the ability to attempt authorization again for a specified time.
53529+ The lower the number, the harder it will be to brute-force a password.
53530+
53531+config GRKERNSEC_ACL_TIMEOUT
53532+ int "Time to wait after max password tries, in seconds"
53533+ default 30
53534+ help
53535+ This option specifies the time the user must wait after attempting to
53536+ authorize to the RBAC system with the maximum number of invalid
53537+ passwords. The higher the number, the harder it will be to brute-force
53538+ a password.
53539+
53540+endmenu
53541+menu "Filesystem Protections"
53542+depends on GRKERNSEC
53543+
53544+config GRKERNSEC_PROC
53545+ bool "Proc restrictions"
53546+ default y if GRKERNSEC_CONFIG_AUTO
53547+ help
53548+ If you say Y here, the permissions of the /proc filesystem
53549+ will be altered to enhance system security and privacy. You MUST
53550+ choose either a user only restriction or a user and group restriction.
53551+ Depending upon the option you choose, you can either restrict users to
53552+ see only the processes they themselves run, or choose a group that can
53553+ view all processes and files normally restricted to root if you choose
53554+ the "restrict to user only" option. NOTE: If you're running identd or
53555+ ntpd as a non-root user, you will have to run it as the group you
53556+ specify here.
53557+
53558+config GRKERNSEC_PROC_USER
53559+ bool "Restrict /proc to user only"
53560+ depends on GRKERNSEC_PROC
53561+ help
53562+ If you say Y here, non-root users will only be able to view their own
53563+ processes, and restricts them from viewing network-related information,
53564+ and viewing kernel symbol and module information.
53565+
53566+config GRKERNSEC_PROC_USERGROUP
53567+ bool "Allow special group"
53568+ default y if GRKERNSEC_CONFIG_AUTO
53569+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
53570+ help
53571+ If you say Y here, you will be able to select a group that will be
53572+ able to view all processes and network-related information. If you've
53573+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
53574+ remain hidden. This option is useful if you want to run identd as
53575+ a non-root user. The group you select may also be chosen at boot time
53576+ via "grsec_proc_gid=" on the kernel commandline.
53577+
53578+config GRKERNSEC_PROC_GID
53579+ int "GID for special group"
53580+ depends on GRKERNSEC_PROC_USERGROUP
53581+ default 1001
53582+
53583+config GRKERNSEC_PROC_ADD
53584+ bool "Additional restrictions"
53585+ default y if GRKERNSEC_CONFIG_AUTO
53586+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
53587+ help
53588+ If you say Y here, additional restrictions will be placed on
53589+ /proc that keep normal users from viewing device information and
53590+ slabinfo information that could be useful for exploits.
53591+
53592+config GRKERNSEC_LINK
53593+ bool "Linking restrictions"
53594+ default y if GRKERNSEC_CONFIG_AUTO
53595+ help
53596+ If you say Y here, /tmp race exploits will be prevented, since users
53597+ will no longer be able to follow symlinks owned by other users in
53598+ world-writable +t directories (e.g. /tmp), unless the owner of the
53599+ symlink is the owner of the directory. users will also not be
53600+ able to hardlink to files they do not own. If the sysctl option is
53601+ enabled, a sysctl option with name "linking_restrictions" is created.
53602+
53603+config GRKERNSEC_SYMLINKOWN
53604+ bool "Kernel-enforced SymlinksIfOwnerMatch"
53605+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
53606+ help
53607+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
53608+ that prevents it from being used as a security feature. As Apache
53609+ verifies the symlink by performing a stat() against the target of
53610+ the symlink before it is followed, an attacker can setup a symlink
53611+ to point to a same-owned file, then replace the symlink with one
53612+ that targets another user's file just after Apache "validates" the
53613+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
53614+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
53615+ will be in place for the group you specify. If the sysctl option
53616+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
53617+ created.
53618+
53619+config GRKERNSEC_SYMLINKOWN_GID
53620+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
53621+ depends on GRKERNSEC_SYMLINKOWN
53622+ default 1006
53623+ help
53624+ Setting this GID determines what group kernel-enforced
53625+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
53626+ is enabled, a sysctl option with name "symlinkown_gid" is created.
53627+
53628+config GRKERNSEC_FIFO
53629+ bool "FIFO restrictions"
53630+ default y if GRKERNSEC_CONFIG_AUTO
53631+ help
53632+ If you say Y here, users will not be able to write to FIFOs they don't
53633+ own in world-writable +t directories (e.g. /tmp), unless the owner of
53634+ the FIFO is the same owner of the directory it's held in. If the sysctl
53635+ option is enabled, a sysctl option with name "fifo_restrictions" is
53636+ created.
53637+
53638+config GRKERNSEC_SYSFS_RESTRICT
53639+ bool "Sysfs/debugfs restriction"
53640+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
53641+ depends on SYSFS
53642+ help
53643+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
53644+ any filesystem normally mounted under it (e.g. debugfs) will be
53645+ mostly accessible only by root. These filesystems generally provide access
53646+ to hardware and debug information that isn't appropriate for unprivileged
53647+ users of the system. Sysfs and debugfs have also become a large source
53648+ of new vulnerabilities, ranging from infoleaks to local compromise.
53649+ There has been very little oversight with an eye toward security involved
53650+ in adding new exporters of information to these filesystems, so their
53651+ use is discouraged.
53652+ For reasons of compatibility, a few directories have been whitelisted
53653+ for access by non-root users:
53654+ /sys/fs/selinux
53655+ /sys/fs/fuse
53656+ /sys/devices/system/cpu
53657+
53658+config GRKERNSEC_ROFS
53659+ bool "Runtime read-only mount protection"
53660+ help
53661+ If you say Y here, a sysctl option with name "romount_protect" will
53662+ be created. By setting this option to 1 at runtime, filesystems
53663+ will be protected in the following ways:
53664+ * No new writable mounts will be allowed
53665+ * Existing read-only mounts won't be able to be remounted read/write
53666+ * Write operations will be denied on all block devices
53667+ This option acts independently of grsec_lock: once it is set to 1,
53668+ it cannot be turned off. Therefore, please be mindful of the resulting
53669+ behavior if this option is enabled in an init script on a read-only
53670+ filesystem. This feature is mainly intended for secure embedded systems.
53671+
53672+config GRKERNSEC_DEVICE_SIDECHANNEL
53673+ bool "Eliminate stat/notify-based device sidechannels"
53674+ default y if GRKERNSEC_CONFIG_AUTO
53675+ help
53676+ If you say Y here, timing analyses on block or character
53677+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
53678+ will be thwarted for unprivileged users. If a process without
53679+ CAP_MKNOD stats such a device, the last access and last modify times
53680+ will match the device's create time. No access or modify events
53681+ will be triggered through inotify/dnotify/fanotify for such devices.
53682+ This feature will prevent attacks that may at a minimum
53683+ allow an attacker to determine the administrator's password length.
53684+
53685+config GRKERNSEC_CHROOT
53686+ bool "Chroot jail restrictions"
53687+ default y if GRKERNSEC_CONFIG_AUTO
53688+ help
53689+ If you say Y here, you will be able to choose several options that will
53690+ make breaking out of a chrooted jail much more difficult. If you
53691+ encounter no software incompatibilities with the following options, it
53692+ is recommended that you enable each one.
53693+
53694+config GRKERNSEC_CHROOT_MOUNT
53695+ bool "Deny mounts"
53696+ default y if GRKERNSEC_CONFIG_AUTO
53697+ depends on GRKERNSEC_CHROOT
53698+ help
53699+ If you say Y here, processes inside a chroot will not be able to
53700+ mount or remount filesystems. If the sysctl option is enabled, a
53701+ sysctl option with name "chroot_deny_mount" is created.
53702+
53703+config GRKERNSEC_CHROOT_DOUBLE
53704+ bool "Deny double-chroots"
53705+ default y if GRKERNSEC_CONFIG_AUTO
53706+ depends on GRKERNSEC_CHROOT
53707+ help
53708+ If you say Y here, processes inside a chroot will not be able to chroot
53709+ again outside the chroot. This is a widely used method of breaking
53710+ out of a chroot jail and should not be allowed. If the sysctl
53711+ option is enabled, a sysctl option with name
53712+ "chroot_deny_chroot" is created.
53713+
53714+config GRKERNSEC_CHROOT_PIVOT
53715+ bool "Deny pivot_root in chroot"
53716+ default y if GRKERNSEC_CONFIG_AUTO
53717+ depends on GRKERNSEC_CHROOT
53718+ help
53719+ If you say Y here, processes inside a chroot will not be able to use
53720+ a function called pivot_root() that was introduced in Linux 2.3.41. It
53721+ works similar to chroot in that it changes the root filesystem. This
53722+ function could be misused in a chrooted process to attempt to break out
53723+ of the chroot, and therefore should not be allowed. If the sysctl
53724+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
53725+ created.
53726+
53727+config GRKERNSEC_CHROOT_CHDIR
53728+ bool "Enforce chdir(\"/\") on all chroots"
53729+ default y if GRKERNSEC_CONFIG_AUTO
53730+ depends on GRKERNSEC_CHROOT
53731+ help
53732+ If you say Y here, the current working directory of all newly-chrooted
53733+ applications will be set to the the root directory of the chroot.
53734+ The man page on chroot(2) states:
53735+ Note that this call does not change the current working
53736+ directory, so that `.' can be outside the tree rooted at
53737+ `/'. In particular, the super-user can escape from a
53738+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
53739+
53740+ It is recommended that you say Y here, since it's not known to break
53741+ any software. If the sysctl option is enabled, a sysctl option with
53742+ name "chroot_enforce_chdir" is created.
53743+
53744+config GRKERNSEC_CHROOT_CHMOD
53745+ bool "Deny (f)chmod +s"
53746+ default y if GRKERNSEC_CONFIG_AUTO
53747+ depends on GRKERNSEC_CHROOT
53748+ help
53749+ If you say Y here, processes inside a chroot will not be able to chmod
53750+ or fchmod files to make them have suid or sgid bits. This protects
53751+ against another published method of breaking a chroot. If the sysctl
53752+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
53753+ created.
53754+
53755+config GRKERNSEC_CHROOT_FCHDIR
53756+ bool "Deny fchdir out of chroot"
53757+ default y if GRKERNSEC_CONFIG_AUTO
53758+ depends on GRKERNSEC_CHROOT
53759+ help
53760+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
53761+ to a file descriptor of the chrooting process that points to a directory
53762+ outside the filesystem will be stopped. If the sysctl option
53763+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
53764+
53765+config GRKERNSEC_CHROOT_MKNOD
53766+ bool "Deny mknod"
53767+ default y if GRKERNSEC_CONFIG_AUTO
53768+ depends on GRKERNSEC_CHROOT
53769+ help
53770+ If you say Y here, processes inside a chroot will not be allowed to
53771+ mknod. The problem with using mknod inside a chroot is that it
53772+ would allow an attacker to create a device entry that is the same
53773+ as one on the physical root of your system, which could range from
53774+ anything from the console device to a device for your harddrive (which
53775+ they could then use to wipe the drive or steal data). It is recommended
53776+ that you say Y here, unless you run into software incompatibilities.
53777+ If the sysctl option is enabled, a sysctl option with name
53778+ "chroot_deny_mknod" is created.
53779+
53780+config GRKERNSEC_CHROOT_SHMAT
53781+ bool "Deny shmat() out of chroot"
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 able to attach
53786+ to shared memory segments that were created outside of the chroot jail.
53787+ It is recommended that you say Y here. If the sysctl option is enabled,
53788+ a sysctl option with name "chroot_deny_shmat" is created.
53789+
53790+config GRKERNSEC_CHROOT_UNIX
53791+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
53792+ default y if GRKERNSEC_CONFIG_AUTO
53793+ depends on GRKERNSEC_CHROOT
53794+ help
53795+ If you say Y here, processes inside a chroot will not be able to
53796+ connect to abstract (meaning not belonging to a filesystem) Unix
53797+ domain sockets that were bound outside of a chroot. It is recommended
53798+ that you say Y here. If the sysctl option is enabled, a sysctl option
53799+ with name "chroot_deny_unix" is created.
53800+
53801+config GRKERNSEC_CHROOT_FINDTASK
53802+ bool "Protect outside processes"
53803+ default y if GRKERNSEC_CONFIG_AUTO
53804+ depends on GRKERNSEC_CHROOT
53805+ help
53806+ If you say Y here, processes inside a chroot will not be able to
53807+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
53808+ getsid, or view any process outside of the chroot. If the sysctl
53809+ option is enabled, a sysctl option with name "chroot_findtask" is
53810+ created.
53811+
53812+config GRKERNSEC_CHROOT_NICE
53813+ bool "Restrict priority changes"
53814+ default y if GRKERNSEC_CONFIG_AUTO
53815+ depends on GRKERNSEC_CHROOT
53816+ help
53817+ If you say Y here, processes inside a chroot will not be able to raise
53818+ the priority of processes in the chroot, or alter the priority of
53819+ processes outside the chroot. This provides more security than simply
53820+ removing CAP_SYS_NICE from the process' capability set. If the
53821+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
53822+ is created.
53823+
53824+config GRKERNSEC_CHROOT_SYSCTL
53825+ bool "Deny sysctl writes"
53826+ default y if GRKERNSEC_CONFIG_AUTO
53827+ depends on GRKERNSEC_CHROOT
53828+ help
53829+ If you say Y here, an attacker in a chroot will not be able to
53830+ write to sysctl entries, either by sysctl(2) or through a /proc
53831+ interface. It is strongly recommended that you say Y here. If the
53832+ sysctl option is enabled, a sysctl option with name
53833+ "chroot_deny_sysctl" is created.
53834+
53835+config GRKERNSEC_CHROOT_CAPS
53836+ bool "Capability restrictions"
53837+ default y if GRKERNSEC_CONFIG_AUTO
53838+ depends on GRKERNSEC_CHROOT
53839+ help
53840+ If you say Y here, the capabilities on all processes within a
53841+ chroot jail will be lowered to stop module insertion, raw i/o,
53842+ system and net admin tasks, rebooting the system, modifying immutable
53843+ files, modifying IPC owned by another, and changing the system time.
53844+ This is left an option because it can break some apps. Disable this
53845+ if your chrooted apps are having problems performing those kinds of
53846+ tasks. If the sysctl option is enabled, a sysctl option with
53847+ name "chroot_caps" is created.
53848+
53849+endmenu
53850+menu "Kernel Auditing"
53851+depends on GRKERNSEC
53852+
53853+config GRKERNSEC_AUDIT_GROUP
53854+ bool "Single group for auditing"
53855+ help
53856+ If you say Y here, the exec and chdir logging features will only operate
53857+ on a group you specify. This option is recommended if you only want to
53858+ watch certain users instead of having a large amount of logs from the
53859+ entire system. If the sysctl option is enabled, a sysctl option with
53860+ name "audit_group" is created.
53861+
53862+config GRKERNSEC_AUDIT_GID
53863+ int "GID for auditing"
53864+ depends on GRKERNSEC_AUDIT_GROUP
53865+ default 1007
53866+
53867+config GRKERNSEC_EXECLOG
53868+ bool "Exec logging"
53869+ help
53870+ If you say Y here, all execve() calls will be logged (since the
53871+ other exec*() calls are frontends to execve(), all execution
53872+ will be logged). Useful for shell-servers that like to keep track
53873+ of their users. If the sysctl option is enabled, a sysctl option with
53874+ name "exec_logging" is created.
53875+ WARNING: This option when enabled will produce a LOT of logs, especially
53876+ on an active system.
53877+
53878+config GRKERNSEC_RESLOG
53879+ bool "Resource logging"
53880+ default y if GRKERNSEC_CONFIG_AUTO
53881+ help
53882+ If you say Y here, all attempts to overstep resource limits will
53883+ be logged with the resource name, the requested size, and the current
53884+ limit. It is highly recommended that you say Y here. If the sysctl
53885+ option is enabled, a sysctl option with name "resource_logging" is
53886+ created. If the RBAC system is enabled, the sysctl value is ignored.
53887+
53888+config GRKERNSEC_CHROOT_EXECLOG
53889+ bool "Log execs within chroot"
53890+ help
53891+ If you say Y here, all executions inside a chroot jail will be logged
53892+ to syslog. This can cause a large amount of logs if certain
53893+ applications (eg. djb's daemontools) are installed on the system, and
53894+ is therefore left as an option. If the sysctl option is enabled, a
53895+ sysctl option with name "chroot_execlog" is created.
53896+
53897+config GRKERNSEC_AUDIT_PTRACE
53898+ bool "Ptrace logging"
53899+ help
53900+ If you say Y here, all attempts to attach to a process via ptrace
53901+ will be logged. If the sysctl option is enabled, a sysctl option
53902+ with name "audit_ptrace" is created.
53903+
53904+config GRKERNSEC_AUDIT_CHDIR
53905+ bool "Chdir logging"
53906+ help
53907+ If you say Y here, all chdir() calls will be logged. If the sysctl
53908+ option is enabled, a sysctl option with name "audit_chdir" is created.
53909+
53910+config GRKERNSEC_AUDIT_MOUNT
53911+ bool "(Un)Mount logging"
53912+ help
53913+ If you say Y here, all mounts and unmounts will be logged. If the
53914+ sysctl option is enabled, a sysctl option with name "audit_mount" is
53915+ created.
53916+
53917+config GRKERNSEC_SIGNAL
53918+ bool "Signal logging"
53919+ default y if GRKERNSEC_CONFIG_AUTO
53920+ help
53921+ If you say Y here, certain important signals will be logged, such as
53922+ SIGSEGV, which will as a result inform you of when a error in a program
53923+ occurred, which in some cases could mean a possible exploit attempt.
53924+ If the sysctl option is enabled, a sysctl option with name
53925+ "signal_logging" is created.
53926+
53927+config GRKERNSEC_FORKFAIL
53928+ bool "Fork failure logging"
53929+ help
53930+ If you say Y here, all failed fork() attempts will be logged.
53931+ This could suggest a fork bomb, or someone attempting to overstep
53932+ their process limit. If the sysctl option is enabled, a sysctl option
53933+ with name "forkfail_logging" is created.
53934+
53935+config GRKERNSEC_TIME
53936+ bool "Time change logging"
53937+ default y if GRKERNSEC_CONFIG_AUTO
53938+ help
53939+ If you say Y here, any changes of the system clock will be logged.
53940+ If the sysctl option is enabled, a sysctl option with name
53941+ "timechange_logging" is created.
53942+
53943+config GRKERNSEC_PROC_IPADDR
53944+ bool "/proc/<pid>/ipaddr support"
53945+ default y if GRKERNSEC_CONFIG_AUTO
53946+ help
53947+ If you say Y here, a new entry will be added to each /proc/<pid>
53948+ directory that contains the IP address of the person using the task.
53949+ The IP is carried across local TCP and AF_UNIX stream sockets.
53950+ This information can be useful for IDS/IPSes to perform remote response
53951+ to a local attack. The entry is readable by only the owner of the
53952+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
53953+ the RBAC system), and thus does not create privacy concerns.
53954+
53955+config GRKERNSEC_RWXMAP_LOG
53956+ bool 'Denied RWX mmap/mprotect logging'
53957+ default y if GRKERNSEC_CONFIG_AUTO
53958+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
53959+ help
53960+ If you say Y here, calls to mmap() and mprotect() with explicit
53961+ usage of PROT_WRITE and PROT_EXEC together will be logged when
53962+ denied by the PAX_MPROTECT feature. If the sysctl option is
53963+ enabled, a sysctl option with name "rwxmap_logging" is created.
53964+
53965+config GRKERNSEC_AUDIT_TEXTREL
53966+ bool 'ELF text relocations logging (READ HELP)'
53967+ depends on PAX_MPROTECT
53968+ help
53969+ If you say Y here, text relocations will be logged with the filename
53970+ of the offending library or binary. The purpose of the feature is
53971+ to help Linux distribution developers get rid of libraries and
53972+ binaries that need text relocations which hinder the future progress
53973+ of PaX. Only Linux distribution developers should say Y here, and
53974+ never on a production machine, as this option creates an information
53975+ leak that could aid an attacker in defeating the randomization of
53976+ a single memory region. If the sysctl option is enabled, a sysctl
53977+ option with name "audit_textrel" is created.
53978+
53979+endmenu
53980+
53981+menu "Executable Protections"
53982+depends on GRKERNSEC
53983+
53984+config GRKERNSEC_DMESG
53985+ bool "Dmesg(8) restriction"
53986+ default y if GRKERNSEC_CONFIG_AUTO
53987+ help
53988+ If you say Y here, non-root users will not be able to use dmesg(8)
53989+ to view the contents of the kernel's circular log buffer.
53990+ The kernel's log buffer often contains kernel addresses and other
53991+ identifying information useful to an attacker in fingerprinting a
53992+ system for a targeted exploit.
53993+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
53994+ created.
53995+
53996+config GRKERNSEC_HARDEN_PTRACE
53997+ bool "Deter ptrace-based process snooping"
53998+ default y if GRKERNSEC_CONFIG_AUTO
53999+ help
54000+ If you say Y here, TTY sniffers and other malicious monitoring
54001+ programs implemented through ptrace will be defeated. If you
54002+ have been using the RBAC system, this option has already been
54003+ enabled for several years for all users, with the ability to make
54004+ fine-grained exceptions.
54005+
54006+ This option only affects the ability of non-root users to ptrace
54007+ processes that are not a descendent of the ptracing process.
54008+ This means that strace ./binary and gdb ./binary will still work,
54009+ but attaching to arbitrary processes will not. If the sysctl
54010+ option is enabled, a sysctl option with name "harden_ptrace" is
54011+ created.
54012+
54013+config GRKERNSEC_PTRACE_READEXEC
54014+ bool "Require read access to ptrace sensitive binaries"
54015+ default y if GRKERNSEC_CONFIG_AUTO
54016+ help
54017+ If you say Y here, unprivileged users will not be able to ptrace unreadable
54018+ binaries. This option is useful in environments that
54019+ remove the read bits (e.g. file mode 4711) from suid binaries to
54020+ prevent infoleaking of their contents. This option adds
54021+ consistency to the use of that file mode, as the binary could normally
54022+ be read out when run without privileges while ptracing.
54023+
54024+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
54025+ is created.
54026+
54027+config GRKERNSEC_SETXID
54028+ bool "Enforce consistent multithreaded privileges"
54029+ default y if GRKERNSEC_CONFIG_AUTO
54030+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
54031+ help
54032+ If you say Y here, a change from a root uid to a non-root uid
54033+ in a multithreaded application will cause the resulting uids,
54034+ gids, supplementary groups, and capabilities in that thread
54035+ to be propagated to the other threads of the process. In most
54036+ cases this is unnecessary, as glibc will emulate this behavior
54037+ on behalf of the application. Other libcs do not act in the
54038+ same way, allowing the other threads of the process to continue
54039+ running with root privileges. If the sysctl option is enabled,
54040+ a sysctl option with name "consistent_setxid" is created.
54041+
54042+config GRKERNSEC_TPE
54043+ bool "Trusted Path Execution (TPE)"
54044+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
54045+ help
54046+ If you say Y here, you will be able to choose a gid to add to the
54047+ supplementary groups of users you want to mark as "untrusted."
54048+ These users will not be able to execute any files that are not in
54049+ root-owned directories writable only by root. If the sysctl option
54050+ is enabled, a sysctl option with name "tpe" is created.
54051+
54052+config GRKERNSEC_TPE_ALL
54053+ bool "Partially restrict all non-root users"
54054+ depends on GRKERNSEC_TPE
54055+ help
54056+ If you say Y here, all non-root users will be covered under
54057+ a weaker TPE restriction. This is separate from, and in addition to,
54058+ the main TPE options that you have selected elsewhere. Thus, if a
54059+ "trusted" GID is chosen, this restriction applies to even that GID.
54060+ Under this restriction, all non-root users will only be allowed to
54061+ execute files in directories they own that are not group or
54062+ world-writable, or in directories owned by root and writable only by
54063+ root. If the sysctl option is enabled, a sysctl option with name
54064+ "tpe_restrict_all" is created.
54065+
54066+config GRKERNSEC_TPE_INVERT
54067+ bool "Invert GID option"
54068+ depends on GRKERNSEC_TPE
54069+ help
54070+ If you say Y here, the group you specify in the TPE configuration will
54071+ decide what group TPE restrictions will be *disabled* for. This
54072+ option is useful if you want TPE restrictions to be applied to most
54073+ users on the system. If the sysctl option is enabled, a sysctl option
54074+ with name "tpe_invert" is created. Unlike other sysctl options, this
54075+ entry will default to on for backward-compatibility.
54076+
54077+config GRKERNSEC_TPE_GID
54078+ int
54079+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
54080+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
54081+
54082+config GRKERNSEC_TPE_UNTRUSTED_GID
54083+ int "GID for TPE-untrusted users"
54084+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
54085+ default 1005
54086+ help
54087+ Setting this GID determines what group TPE restrictions will be
54088+ *enabled* for. If the sysctl option is enabled, a sysctl option
54089+ with name "tpe_gid" is created.
54090+
54091+config GRKERNSEC_TPE_TRUSTED_GID
54092+ int "GID for TPE-trusted users"
54093+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
54094+ default 1005
54095+ help
54096+ Setting this GID determines what group TPE restrictions will be
54097+ *disabled* for. If the sysctl option is enabled, a sysctl option
54098+ with name "tpe_gid" is created.
54099+
54100+endmenu
54101+menu "Network Protections"
54102+depends on GRKERNSEC
54103+
54104+config GRKERNSEC_RANDNET
54105+ bool "Larger entropy pools"
54106+ default y if GRKERNSEC_CONFIG_AUTO
54107+ help
54108+ If you say Y here, the entropy pools used for many features of Linux
54109+ and grsecurity will be doubled in size. Since several grsecurity
54110+ features use additional randomness, it is recommended that you say Y
54111+ here. Saying Y here has a similar effect as modifying
54112+ /proc/sys/kernel/random/poolsize.
54113+
54114+config GRKERNSEC_BLACKHOLE
54115+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
54116+ default y if GRKERNSEC_CONFIG_AUTO
54117+ depends on NET
54118+ help
54119+ If you say Y here, neither TCP resets nor ICMP
54120+ destination-unreachable packets will be sent in response to packets
54121+ sent to ports for which no associated listening process exists.
54122+ This feature supports both IPV4 and IPV6 and exempts the
54123+ loopback interface from blackholing. Enabling this feature
54124+ makes a host more resilient to DoS attacks and reduces network
54125+ visibility against scanners.
54126+
54127+ The blackhole feature as-implemented is equivalent to the FreeBSD
54128+ blackhole feature, as it prevents RST responses to all packets, not
54129+ just SYNs. Under most application behavior this causes no
54130+ problems, but applications (like haproxy) may not close certain
54131+ connections in a way that cleanly terminates them on the remote
54132+ end, leaving the remote host in LAST_ACK state. Because of this
54133+ side-effect and to prevent intentional LAST_ACK DoSes, this
54134+ feature also adds automatic mitigation against such attacks.
54135+ The mitigation drastically reduces the amount of time a socket
54136+ can spend in LAST_ACK state. If you're using haproxy and not
54137+ all servers it connects to have this option enabled, consider
54138+ disabling this feature on the haproxy host.
54139+
54140+ If the sysctl option is enabled, two sysctl options with names
54141+ "ip_blackhole" and "lastack_retries" will be created.
54142+ While "ip_blackhole" takes the standard zero/non-zero on/off
54143+ toggle, "lastack_retries" uses the same kinds of values as
54144+ "tcp_retries1" and "tcp_retries2". The default value of 4
54145+ prevents a socket from lasting more than 45 seconds in LAST_ACK
54146+ state.
54147+
54148+config GRKERNSEC_NO_SIMULT_CONNECT
54149+ bool "Disable TCP Simultaneous Connect"
54150+ default y if GRKERNSEC_CONFIG_AUTO
54151+ depends on NET
54152+ help
54153+ If you say Y here, a feature by Willy Tarreau will be enabled that
54154+ removes a weakness in Linux's strict implementation of TCP that
54155+ allows two clients to connect to each other without either entering
54156+ a listening state. The weakness allows an attacker to easily prevent
54157+ a client from connecting to a known server provided the source port
54158+ for the connection is guessed correctly.
54159+
54160+ As the weakness could be used to prevent an antivirus or IPS from
54161+ fetching updates, or prevent an SSL gateway from fetching a CRL,
54162+ it should be eliminated by enabling this option. Though Linux is
54163+ one of few operating systems supporting simultaneous connect, it
54164+ has no legitimate use in practice and is rarely supported by firewalls.
54165+
54166+config GRKERNSEC_SOCKET
54167+ bool "Socket restrictions"
54168+ depends on NET
54169+ help
54170+ If you say Y here, you will be able to choose from several options.
54171+ If you assign a GID on your system and add it to the supplementary
54172+ groups of users you want to restrict socket access to, this patch
54173+ will perform up to three things, based on the option(s) you choose.
54174+
54175+config GRKERNSEC_SOCKET_ALL
54176+ bool "Deny any sockets to group"
54177+ depends on GRKERNSEC_SOCKET
54178+ help
54179+ If you say Y here, you will be able to choose a GID of whose users will
54180+ be unable to connect to other hosts from your machine or run server
54181+ applications from your machine. If the sysctl option is enabled, a
54182+ sysctl option with name "socket_all" is created.
54183+
54184+config GRKERNSEC_SOCKET_ALL_GID
54185+ int "GID to deny all sockets for"
54186+ depends on GRKERNSEC_SOCKET_ALL
54187+ default 1004
54188+ help
54189+ Here you can choose the GID to disable socket access for. Remember to
54190+ add the users you want socket access disabled for to the GID
54191+ specified here. If the sysctl option is enabled, a sysctl option
54192+ with name "socket_all_gid" is created.
54193+
54194+config GRKERNSEC_SOCKET_CLIENT
54195+ bool "Deny client sockets to group"
54196+ depends on GRKERNSEC_SOCKET
54197+ help
54198+ If you say Y here, you will be able to choose a GID of whose users will
54199+ be unable to connect to other hosts from your machine, but will be
54200+ able to run servers. If this option is enabled, all users in the group
54201+ you specify will have to use passive mode when initiating ftp transfers
54202+ from the shell on your machine. If the sysctl option is enabled, a
54203+ sysctl option with name "socket_client" is created.
54204+
54205+config GRKERNSEC_SOCKET_CLIENT_GID
54206+ int "GID to deny client sockets for"
54207+ depends on GRKERNSEC_SOCKET_CLIENT
54208+ default 1003
54209+ help
54210+ Here you can choose the GID to disable client socket access for.
54211+ Remember to add the users you want client socket access disabled for to
54212+ the GID specified here. If the sysctl option is enabled, a sysctl
54213+ option with name "socket_client_gid" is created.
54214+
54215+config GRKERNSEC_SOCKET_SERVER
54216+ bool "Deny server sockets to group"
54217+ depends on GRKERNSEC_SOCKET
54218+ help
54219+ If you say Y here, you will be able to choose a GID of whose users will
54220+ be unable to run server applications from your machine. If the sysctl
54221+ option is enabled, a sysctl option with name "socket_server" is created.
54222+
54223+config GRKERNSEC_SOCKET_SERVER_GID
54224+ int "GID to deny server sockets for"
54225+ depends on GRKERNSEC_SOCKET_SERVER
54226+ default 1002
54227+ help
54228+ Here you can choose the GID to disable server socket access for.
54229+ Remember to add the users you want server socket access disabled for to
54230+ the GID specified here. If the sysctl option is enabled, a sysctl
54231+ option with name "socket_server_gid" is created.
54232+
54233+endmenu
54234+menu "Sysctl Support"
54235+depends on GRKERNSEC && SYSCTL
54236+
54237+config GRKERNSEC_SYSCTL
54238+ bool "Sysctl support"
54239+ default y if GRKERNSEC_CONFIG_AUTO
54240+ help
54241+ If you say Y here, you will be able to change the options that
54242+ grsecurity runs with at bootup, without having to recompile your
54243+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
54244+ to enable (1) or disable (0) various features. All the sysctl entries
54245+ are mutable until the "grsec_lock" entry is set to a non-zero value.
54246+ All features enabled in the kernel configuration are disabled at boot
54247+ if you do not say Y to the "Turn on features by default" option.
54248+ All options should be set at startup, and the grsec_lock entry should
54249+ be set to a non-zero value after all the options are set.
54250+ *THIS IS EXTREMELY IMPORTANT*
54251+
54252+config GRKERNSEC_SYSCTL_DISTRO
54253+ bool "Extra sysctl support for distro makers (READ HELP)"
54254+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
54255+ help
54256+ If you say Y here, additional sysctl options will be created
54257+ for features that affect processes running as root. Therefore,
54258+ it is critical when using this option that the grsec_lock entry be
54259+ enabled after boot. Only distros with prebuilt kernel packages
54260+ with this option enabled that can ensure grsec_lock is enabled
54261+ after boot should use this option.
54262+ *Failure to set grsec_lock after boot makes all grsec features
54263+ this option covers useless*
54264+
54265+ Currently this option creates the following sysctl entries:
54266+ "Disable Privileged I/O": "disable_priv_io"
54267+
54268+config GRKERNSEC_SYSCTL_ON
54269+ bool "Turn on features by default"
54270+ default y if GRKERNSEC_CONFIG_AUTO
54271+ depends on GRKERNSEC_SYSCTL
54272+ help
54273+ If you say Y here, instead of having all features enabled in the
54274+ kernel configuration disabled at boot time, the features will be
54275+ enabled at boot time. It is recommended you say Y here unless
54276+ there is some reason you would want all sysctl-tunable features to
54277+ be disabled by default. As mentioned elsewhere, it is important
54278+ to enable the grsec_lock entry once you have finished modifying
54279+ the sysctl entries.
54280+
54281+endmenu
54282+menu "Logging Options"
54283+depends on GRKERNSEC
54284+
54285+config GRKERNSEC_FLOODTIME
54286+ int "Seconds in between log messages (minimum)"
54287+ default 10
54288+ help
54289+ This option allows you to enforce the number of seconds between
54290+ grsecurity log messages. The default should be suitable for most
54291+ people, however, if you choose to change it, choose a value small enough
54292+ to allow informative logs to be produced, but large enough to
54293+ prevent flooding.
54294+
54295+config GRKERNSEC_FLOODBURST
54296+ int "Number of messages in a burst (maximum)"
54297+ default 6
54298+ help
54299+ This option allows you to choose the maximum number of messages allowed
54300+ within the flood time interval you chose in a separate option. The
54301+ default should be suitable for most people, however if you find that
54302+ many of your logs are being interpreted as flooding, you may want to
54303+ raise this value.
54304+
54305+endmenu
54306diff --git a/grsecurity/Makefile b/grsecurity/Makefile
54307new file mode 100644
54308index 0000000..1b9afa9
54309--- /dev/null
54310+++ b/grsecurity/Makefile
54311@@ -0,0 +1,38 @@
54312+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
54313+# during 2001-2009 it has been completely redesigned by Brad Spengler
54314+# into an RBAC system
54315+#
54316+# All code in this directory and various hooks inserted throughout the kernel
54317+# are copyright Brad Spengler - Open Source Security, Inc., and released
54318+# under the GPL v2 or higher
54319+
54320+KBUILD_CFLAGS += -Werror
54321+
54322+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
54323+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
54324+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
54325+
54326+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
54327+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
54328+ gracl_learn.o grsec_log.o
54329+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
54330+
54331+ifdef CONFIG_NET
54332+obj-y += grsec_sock.o
54333+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
54334+endif
54335+
54336+ifndef CONFIG_GRKERNSEC
54337+obj-y += grsec_disabled.o
54338+endif
54339+
54340+ifdef CONFIG_GRKERNSEC_HIDESYM
54341+extra-y := grsec_hidesym.o
54342+$(obj)/grsec_hidesym.o:
54343+ @-chmod -f 500 /boot
54344+ @-chmod -f 500 /lib/modules
54345+ @-chmod -f 500 /lib64/modules
54346+ @-chmod -f 500 /lib32/modules
54347+ @-chmod -f 700 .
54348+ @echo ' grsec: protected kernel image paths'
54349+endif
54350diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
54351new file mode 100644
54352index 0000000..69e1320
54353--- /dev/null
54354+++ b/grsecurity/gracl.c
54355@@ -0,0 +1,4019 @@
54356+#include <linux/kernel.h>
54357+#include <linux/module.h>
54358+#include <linux/sched.h>
54359+#include <linux/mm.h>
54360+#include <linux/file.h>
54361+#include <linux/fs.h>
54362+#include <linux/namei.h>
54363+#include <linux/mount.h>
54364+#include <linux/tty.h>
54365+#include <linux/proc_fs.h>
54366+#include <linux/lglock.h>
54367+#include <linux/slab.h>
54368+#include <linux/vmalloc.h>
54369+#include <linux/types.h>
54370+#include <linux/sysctl.h>
54371+#include <linux/netdevice.h>
54372+#include <linux/ptrace.h>
54373+#include <linux/gracl.h>
54374+#include <linux/gralloc.h>
54375+#include <linux/security.h>
54376+#include <linux/grinternal.h>
54377+#include <linux/pid_namespace.h>
54378+#include <linux/stop_machine.h>
54379+#include <linux/fdtable.h>
54380+#include <linux/percpu.h>
54381+#include <linux/lglock.h>
54382+#include <linux/hugetlb.h>
54383+#include "../fs/mount.h"
54384+
54385+#include <asm/uaccess.h>
54386+#include <asm/errno.h>
54387+#include <asm/mman.h>
54388+
54389+extern struct lglock vfsmount_lock;
54390+
54391+static struct acl_role_db acl_role_set;
54392+static struct name_db name_set;
54393+static struct inodev_db inodev_set;
54394+
54395+/* for keeping track of userspace pointers used for subjects, so we
54396+ can share references in the kernel as well
54397+*/
54398+
54399+static struct path real_root;
54400+
54401+static struct acl_subj_map_db subj_map_set;
54402+
54403+static struct acl_role_label *default_role;
54404+
54405+static struct acl_role_label *role_list;
54406+
54407+static u16 acl_sp_role_value;
54408+
54409+extern char *gr_shared_page[4];
54410+static DEFINE_MUTEX(gr_dev_mutex);
54411+DEFINE_RWLOCK(gr_inode_lock);
54412+
54413+struct gr_arg *gr_usermode;
54414+
54415+static unsigned int gr_status __read_only = GR_STATUS_INIT;
54416+
54417+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
54418+extern void gr_clear_learn_entries(void);
54419+
54420+unsigned char *gr_system_salt;
54421+unsigned char *gr_system_sum;
54422+
54423+static struct sprole_pw **acl_special_roles = NULL;
54424+static __u16 num_sprole_pws = 0;
54425+
54426+static struct acl_role_label *kernel_role = NULL;
54427+
54428+static unsigned int gr_auth_attempts = 0;
54429+static unsigned long gr_auth_expires = 0UL;
54430+
54431+#ifdef CONFIG_NET
54432+extern struct vfsmount *sock_mnt;
54433+#endif
54434+
54435+extern struct vfsmount *pipe_mnt;
54436+extern struct vfsmount *shm_mnt;
54437+
54438+#ifdef CONFIG_HUGETLBFS
54439+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
54440+#endif
54441+
54442+static struct acl_object_label *fakefs_obj_rw;
54443+static struct acl_object_label *fakefs_obj_rwx;
54444+
54445+extern int gr_init_uidset(void);
54446+extern void gr_free_uidset(void);
54447+extern void gr_remove_uid(uid_t uid);
54448+extern int gr_find_uid(uid_t uid);
54449+
54450+__inline__ int
54451+gr_acl_is_enabled(void)
54452+{
54453+ return (gr_status & GR_READY);
54454+}
54455+
54456+#ifdef CONFIG_BTRFS_FS
54457+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
54458+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
54459+#endif
54460+
54461+static inline dev_t __get_dev(const struct dentry *dentry)
54462+{
54463+#ifdef CONFIG_BTRFS_FS
54464+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
54465+ return get_btrfs_dev_from_inode(dentry->d_inode);
54466+ else
54467+#endif
54468+ return dentry->d_inode->i_sb->s_dev;
54469+}
54470+
54471+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
54472+{
54473+ return __get_dev(dentry);
54474+}
54475+
54476+static char gr_task_roletype_to_char(struct task_struct *task)
54477+{
54478+ switch (task->role->roletype &
54479+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
54480+ GR_ROLE_SPECIAL)) {
54481+ case GR_ROLE_DEFAULT:
54482+ return 'D';
54483+ case GR_ROLE_USER:
54484+ return 'U';
54485+ case GR_ROLE_GROUP:
54486+ return 'G';
54487+ case GR_ROLE_SPECIAL:
54488+ return 'S';
54489+ }
54490+
54491+ return 'X';
54492+}
54493+
54494+char gr_roletype_to_char(void)
54495+{
54496+ return gr_task_roletype_to_char(current);
54497+}
54498+
54499+__inline__ int
54500+gr_acl_tpe_check(void)
54501+{
54502+ if (unlikely(!(gr_status & GR_READY)))
54503+ return 0;
54504+ if (current->role->roletype & GR_ROLE_TPE)
54505+ return 1;
54506+ else
54507+ return 0;
54508+}
54509+
54510+int
54511+gr_handle_rawio(const struct inode *inode)
54512+{
54513+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
54514+ if (inode && S_ISBLK(inode->i_mode) &&
54515+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
54516+ !capable(CAP_SYS_RAWIO))
54517+ return 1;
54518+#endif
54519+ return 0;
54520+}
54521+
54522+static int
54523+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
54524+{
54525+ if (likely(lena != lenb))
54526+ return 0;
54527+
54528+ return !memcmp(a, b, lena);
54529+}
54530+
54531+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
54532+{
54533+ *buflen -= namelen;
54534+ if (*buflen < 0)
54535+ return -ENAMETOOLONG;
54536+ *buffer -= namelen;
54537+ memcpy(*buffer, str, namelen);
54538+ return 0;
54539+}
54540+
54541+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
54542+{
54543+ return prepend(buffer, buflen, name->name, name->len);
54544+}
54545+
54546+static int prepend_path(const struct path *path, struct path *root,
54547+ char **buffer, int *buflen)
54548+{
54549+ struct dentry *dentry = path->dentry;
54550+ struct vfsmount *vfsmnt = path->mnt;
54551+ struct mount *mnt = real_mount(vfsmnt);
54552+ bool slash = false;
54553+ int error = 0;
54554+
54555+ while (dentry != root->dentry || vfsmnt != root->mnt) {
54556+ struct dentry * parent;
54557+
54558+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
54559+ /* Global root? */
54560+ if (!mnt_has_parent(mnt)) {
54561+ goto out;
54562+ }
54563+ dentry = mnt->mnt_mountpoint;
54564+ mnt = mnt->mnt_parent;
54565+ vfsmnt = &mnt->mnt;
54566+ continue;
54567+ }
54568+ parent = dentry->d_parent;
54569+ prefetch(parent);
54570+ spin_lock(&dentry->d_lock);
54571+ error = prepend_name(buffer, buflen, &dentry->d_name);
54572+ spin_unlock(&dentry->d_lock);
54573+ if (!error)
54574+ error = prepend(buffer, buflen, "/", 1);
54575+ if (error)
54576+ break;
54577+
54578+ slash = true;
54579+ dentry = parent;
54580+ }
54581+
54582+out:
54583+ if (!error && !slash)
54584+ error = prepend(buffer, buflen, "/", 1);
54585+
54586+ return error;
54587+}
54588+
54589+/* this must be called with vfsmount_lock and rename_lock held */
54590+
54591+static char *__our_d_path(const struct path *path, struct path *root,
54592+ char *buf, int buflen)
54593+{
54594+ char *res = buf + buflen;
54595+ int error;
54596+
54597+ prepend(&res, &buflen, "\0", 1);
54598+ error = prepend_path(path, root, &res, &buflen);
54599+ if (error)
54600+ return ERR_PTR(error);
54601+
54602+ return res;
54603+}
54604+
54605+static char *
54606+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
54607+{
54608+ char *retval;
54609+
54610+ retval = __our_d_path(path, root, buf, buflen);
54611+ if (unlikely(IS_ERR(retval)))
54612+ retval = strcpy(buf, "<path too long>");
54613+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
54614+ retval[1] = '\0';
54615+
54616+ return retval;
54617+}
54618+
54619+static char *
54620+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
54621+ char *buf, int buflen)
54622+{
54623+ struct path path;
54624+ char *res;
54625+
54626+ path.dentry = (struct dentry *)dentry;
54627+ path.mnt = (struct vfsmount *)vfsmnt;
54628+
54629+ /* we can use real_root.dentry, real_root.mnt, because this is only called
54630+ by the RBAC system */
54631+ res = gen_full_path(&path, &real_root, buf, buflen);
54632+
54633+ return res;
54634+}
54635+
54636+static char *
54637+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
54638+ char *buf, int buflen)
54639+{
54640+ char *res;
54641+ struct path path;
54642+ struct path root;
54643+ struct task_struct *reaper = init_pid_ns.child_reaper;
54644+
54645+ path.dentry = (struct dentry *)dentry;
54646+ path.mnt = (struct vfsmount *)vfsmnt;
54647+
54648+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
54649+ get_fs_root(reaper->fs, &root);
54650+
54651+ write_seqlock(&rename_lock);
54652+ br_read_lock(&vfsmount_lock);
54653+ res = gen_full_path(&path, &root, buf, buflen);
54654+ br_read_unlock(&vfsmount_lock);
54655+ write_sequnlock(&rename_lock);
54656+
54657+ path_put(&root);
54658+ return res;
54659+}
54660+
54661+static char *
54662+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
54663+{
54664+ char *ret;
54665+ write_seqlock(&rename_lock);
54666+ br_read_lock(&vfsmount_lock);
54667+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
54668+ PAGE_SIZE);
54669+ br_read_unlock(&vfsmount_lock);
54670+ write_sequnlock(&rename_lock);
54671+ return ret;
54672+}
54673+
54674+static char *
54675+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
54676+{
54677+ char *ret;
54678+ char *buf;
54679+ int buflen;
54680+
54681+ write_seqlock(&rename_lock);
54682+ br_read_lock(&vfsmount_lock);
54683+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
54684+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
54685+ buflen = (int)(ret - buf);
54686+ if (buflen >= 5)
54687+ prepend(&ret, &buflen, "/proc", 5);
54688+ else
54689+ ret = strcpy(buf, "<path too long>");
54690+ br_read_unlock(&vfsmount_lock);
54691+ write_sequnlock(&rename_lock);
54692+ return ret;
54693+}
54694+
54695+char *
54696+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
54697+{
54698+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
54699+ PAGE_SIZE);
54700+}
54701+
54702+char *
54703+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
54704+{
54705+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
54706+ PAGE_SIZE);
54707+}
54708+
54709+char *
54710+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
54711+{
54712+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
54713+ PAGE_SIZE);
54714+}
54715+
54716+char *
54717+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
54718+{
54719+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
54720+ PAGE_SIZE);
54721+}
54722+
54723+char *
54724+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
54725+{
54726+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
54727+ PAGE_SIZE);
54728+}
54729+
54730+__inline__ __u32
54731+to_gr_audit(const __u32 reqmode)
54732+{
54733+ /* masks off auditable permission flags, then shifts them to create
54734+ auditing flags, and adds the special case of append auditing if
54735+ we're requesting write */
54736+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
54737+}
54738+
54739+struct acl_subject_label *
54740+lookup_subject_map(const struct acl_subject_label *userp)
54741+{
54742+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
54743+ struct subject_map *match;
54744+
54745+ match = subj_map_set.s_hash[index];
54746+
54747+ while (match && match->user != userp)
54748+ match = match->next;
54749+
54750+ if (match != NULL)
54751+ return match->kernel;
54752+ else
54753+ return NULL;
54754+}
54755+
54756+static void
54757+insert_subj_map_entry(struct subject_map *subjmap)
54758+{
54759+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
54760+ struct subject_map **curr;
54761+
54762+ subjmap->prev = NULL;
54763+
54764+ curr = &subj_map_set.s_hash[index];
54765+ if (*curr != NULL)
54766+ (*curr)->prev = subjmap;
54767+
54768+ subjmap->next = *curr;
54769+ *curr = subjmap;
54770+
54771+ return;
54772+}
54773+
54774+static struct acl_role_label *
54775+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
54776+ const gid_t gid)
54777+{
54778+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
54779+ struct acl_role_label *match;
54780+ struct role_allowed_ip *ipp;
54781+ unsigned int x;
54782+ u32 curr_ip = task->signal->curr_ip;
54783+
54784+ task->signal->saved_ip = curr_ip;
54785+
54786+ match = acl_role_set.r_hash[index];
54787+
54788+ while (match) {
54789+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
54790+ for (x = 0; x < match->domain_child_num; x++) {
54791+ if (match->domain_children[x] == uid)
54792+ goto found;
54793+ }
54794+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
54795+ break;
54796+ match = match->next;
54797+ }
54798+found:
54799+ if (match == NULL) {
54800+ try_group:
54801+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
54802+ match = acl_role_set.r_hash[index];
54803+
54804+ while (match) {
54805+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
54806+ for (x = 0; x < match->domain_child_num; x++) {
54807+ if (match->domain_children[x] == gid)
54808+ goto found2;
54809+ }
54810+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
54811+ break;
54812+ match = match->next;
54813+ }
54814+found2:
54815+ if (match == NULL)
54816+ match = default_role;
54817+ if (match->allowed_ips == NULL)
54818+ return match;
54819+ else {
54820+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
54821+ if (likely
54822+ ((ntohl(curr_ip) & ipp->netmask) ==
54823+ (ntohl(ipp->addr) & ipp->netmask)))
54824+ return match;
54825+ }
54826+ match = default_role;
54827+ }
54828+ } else if (match->allowed_ips == NULL) {
54829+ return match;
54830+ } else {
54831+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
54832+ if (likely
54833+ ((ntohl(curr_ip) & ipp->netmask) ==
54834+ (ntohl(ipp->addr) & ipp->netmask)))
54835+ return match;
54836+ }
54837+ goto try_group;
54838+ }
54839+
54840+ return match;
54841+}
54842+
54843+struct acl_subject_label *
54844+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
54845+ const struct acl_role_label *role)
54846+{
54847+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
54848+ struct acl_subject_label *match;
54849+
54850+ match = role->subj_hash[index];
54851+
54852+ while (match && (match->inode != ino || match->device != dev ||
54853+ (match->mode & GR_DELETED))) {
54854+ match = match->next;
54855+ }
54856+
54857+ if (match && !(match->mode & GR_DELETED))
54858+ return match;
54859+ else
54860+ return NULL;
54861+}
54862+
54863+struct acl_subject_label *
54864+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
54865+ const struct acl_role_label *role)
54866+{
54867+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
54868+ struct acl_subject_label *match;
54869+
54870+ match = role->subj_hash[index];
54871+
54872+ while (match && (match->inode != ino || match->device != dev ||
54873+ !(match->mode & GR_DELETED))) {
54874+ match = match->next;
54875+ }
54876+
54877+ if (match && (match->mode & GR_DELETED))
54878+ return match;
54879+ else
54880+ return NULL;
54881+}
54882+
54883+static struct acl_object_label *
54884+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
54885+ const struct acl_subject_label *subj)
54886+{
54887+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
54888+ struct acl_object_label *match;
54889+
54890+ match = subj->obj_hash[index];
54891+
54892+ while (match && (match->inode != ino || match->device != dev ||
54893+ (match->mode & GR_DELETED))) {
54894+ match = match->next;
54895+ }
54896+
54897+ if (match && !(match->mode & GR_DELETED))
54898+ return match;
54899+ else
54900+ return NULL;
54901+}
54902+
54903+static struct acl_object_label *
54904+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
54905+ const struct acl_subject_label *subj)
54906+{
54907+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
54908+ struct acl_object_label *match;
54909+
54910+ match = subj->obj_hash[index];
54911+
54912+ while (match && (match->inode != ino || match->device != dev ||
54913+ !(match->mode & GR_DELETED))) {
54914+ match = match->next;
54915+ }
54916+
54917+ if (match && (match->mode & GR_DELETED))
54918+ return match;
54919+
54920+ match = subj->obj_hash[index];
54921+
54922+ while (match && (match->inode != ino || match->device != dev ||
54923+ (match->mode & GR_DELETED))) {
54924+ match = match->next;
54925+ }
54926+
54927+ if (match && !(match->mode & GR_DELETED))
54928+ return match;
54929+ else
54930+ return NULL;
54931+}
54932+
54933+static struct name_entry *
54934+lookup_name_entry(const char *name)
54935+{
54936+ unsigned int len = strlen(name);
54937+ unsigned int key = full_name_hash(name, len);
54938+ unsigned int index = key % name_set.n_size;
54939+ struct name_entry *match;
54940+
54941+ match = name_set.n_hash[index];
54942+
54943+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
54944+ match = match->next;
54945+
54946+ return match;
54947+}
54948+
54949+static struct name_entry *
54950+lookup_name_entry_create(const char *name)
54951+{
54952+ unsigned int len = strlen(name);
54953+ unsigned int key = full_name_hash(name, len);
54954+ unsigned int index = key % name_set.n_size;
54955+ struct name_entry *match;
54956+
54957+ match = name_set.n_hash[index];
54958+
54959+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
54960+ !match->deleted))
54961+ match = match->next;
54962+
54963+ if (match && match->deleted)
54964+ return match;
54965+
54966+ match = name_set.n_hash[index];
54967+
54968+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
54969+ match->deleted))
54970+ match = match->next;
54971+
54972+ if (match && !match->deleted)
54973+ return match;
54974+ else
54975+ return NULL;
54976+}
54977+
54978+static struct inodev_entry *
54979+lookup_inodev_entry(const ino_t ino, const dev_t dev)
54980+{
54981+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
54982+ struct inodev_entry *match;
54983+
54984+ match = inodev_set.i_hash[index];
54985+
54986+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
54987+ match = match->next;
54988+
54989+ return match;
54990+}
54991+
54992+static void
54993+insert_inodev_entry(struct inodev_entry *entry)
54994+{
54995+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
54996+ inodev_set.i_size);
54997+ struct inodev_entry **curr;
54998+
54999+ entry->prev = NULL;
55000+
55001+ curr = &inodev_set.i_hash[index];
55002+ if (*curr != NULL)
55003+ (*curr)->prev = entry;
55004+
55005+ entry->next = *curr;
55006+ *curr = entry;
55007+
55008+ return;
55009+}
55010+
55011+static void
55012+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
55013+{
55014+ unsigned int index =
55015+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
55016+ struct acl_role_label **curr;
55017+ struct acl_role_label *tmp, *tmp2;
55018+
55019+ curr = &acl_role_set.r_hash[index];
55020+
55021+ /* simple case, slot is empty, just set it to our role */
55022+ if (*curr == NULL) {
55023+ *curr = role;
55024+ } else {
55025+ /* example:
55026+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
55027+ 2 -> 3
55028+ */
55029+ /* first check to see if we can already be reached via this slot */
55030+ tmp = *curr;
55031+ while (tmp && tmp != role)
55032+ tmp = tmp->next;
55033+ if (tmp == role) {
55034+ /* we don't need to add ourselves to this slot's chain */
55035+ return;
55036+ }
55037+ /* we need to add ourselves to this chain, two cases */
55038+ if (role->next == NULL) {
55039+ /* simple case, append the current chain to our role */
55040+ role->next = *curr;
55041+ *curr = role;
55042+ } else {
55043+ /* 1 -> 2 -> 3 -> 4
55044+ 2 -> 3 -> 4
55045+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
55046+ */
55047+ /* trickier case: walk our role's chain until we find
55048+ the role for the start of the current slot's chain */
55049+ tmp = role;
55050+ tmp2 = *curr;
55051+ while (tmp->next && tmp->next != tmp2)
55052+ tmp = tmp->next;
55053+ if (tmp->next == tmp2) {
55054+ /* from example above, we found 3, so just
55055+ replace this slot's chain with ours */
55056+ *curr = role;
55057+ } else {
55058+ /* we didn't find a subset of our role's chain
55059+ in the current slot's chain, so append their
55060+ chain to ours, and set us as the first role in
55061+ the slot's chain
55062+
55063+ we could fold this case with the case above,
55064+ but making it explicit for clarity
55065+ */
55066+ tmp->next = tmp2;
55067+ *curr = role;
55068+ }
55069+ }
55070+ }
55071+
55072+ return;
55073+}
55074+
55075+static void
55076+insert_acl_role_label(struct acl_role_label *role)
55077+{
55078+ int i;
55079+
55080+ if (role_list == NULL) {
55081+ role_list = role;
55082+ role->prev = NULL;
55083+ } else {
55084+ role->prev = role_list;
55085+ role_list = role;
55086+ }
55087+
55088+ /* used for hash chains */
55089+ role->next = NULL;
55090+
55091+ if (role->roletype & GR_ROLE_DOMAIN) {
55092+ for (i = 0; i < role->domain_child_num; i++)
55093+ __insert_acl_role_label(role, role->domain_children[i]);
55094+ } else
55095+ __insert_acl_role_label(role, role->uidgid);
55096+}
55097+
55098+static int
55099+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
55100+{
55101+ struct name_entry **curr, *nentry;
55102+ struct inodev_entry *ientry;
55103+ unsigned int len = strlen(name);
55104+ unsigned int key = full_name_hash(name, len);
55105+ unsigned int index = key % name_set.n_size;
55106+
55107+ curr = &name_set.n_hash[index];
55108+
55109+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
55110+ curr = &((*curr)->next);
55111+
55112+ if (*curr != NULL)
55113+ return 1;
55114+
55115+ nentry = acl_alloc(sizeof (struct name_entry));
55116+ if (nentry == NULL)
55117+ return 0;
55118+ ientry = acl_alloc(sizeof (struct inodev_entry));
55119+ if (ientry == NULL)
55120+ return 0;
55121+ ientry->nentry = nentry;
55122+
55123+ nentry->key = key;
55124+ nentry->name = name;
55125+ nentry->inode = inode;
55126+ nentry->device = device;
55127+ nentry->len = len;
55128+ nentry->deleted = deleted;
55129+
55130+ nentry->prev = NULL;
55131+ curr = &name_set.n_hash[index];
55132+ if (*curr != NULL)
55133+ (*curr)->prev = nentry;
55134+ nentry->next = *curr;
55135+ *curr = nentry;
55136+
55137+ /* insert us into the table searchable by inode/dev */
55138+ insert_inodev_entry(ientry);
55139+
55140+ return 1;
55141+}
55142+
55143+static void
55144+insert_acl_obj_label(struct acl_object_label *obj,
55145+ struct acl_subject_label *subj)
55146+{
55147+ unsigned int index =
55148+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
55149+ struct acl_object_label **curr;
55150+
55151+
55152+ obj->prev = NULL;
55153+
55154+ curr = &subj->obj_hash[index];
55155+ if (*curr != NULL)
55156+ (*curr)->prev = obj;
55157+
55158+ obj->next = *curr;
55159+ *curr = obj;
55160+
55161+ return;
55162+}
55163+
55164+static void
55165+insert_acl_subj_label(struct acl_subject_label *obj,
55166+ struct acl_role_label *role)
55167+{
55168+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
55169+ struct acl_subject_label **curr;
55170+
55171+ obj->prev = NULL;
55172+
55173+ curr = &role->subj_hash[index];
55174+ if (*curr != NULL)
55175+ (*curr)->prev = obj;
55176+
55177+ obj->next = *curr;
55178+ *curr = obj;
55179+
55180+ return;
55181+}
55182+
55183+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
55184+
55185+static void *
55186+create_table(__u32 * len, int elementsize)
55187+{
55188+ unsigned int table_sizes[] = {
55189+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
55190+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
55191+ 4194301, 8388593, 16777213, 33554393, 67108859
55192+ };
55193+ void *newtable = NULL;
55194+ unsigned int pwr = 0;
55195+
55196+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
55197+ table_sizes[pwr] <= *len)
55198+ pwr++;
55199+
55200+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
55201+ return newtable;
55202+
55203+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
55204+ newtable =
55205+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
55206+ else
55207+ newtable = vmalloc(table_sizes[pwr] * elementsize);
55208+
55209+ *len = table_sizes[pwr];
55210+
55211+ return newtable;
55212+}
55213+
55214+static int
55215+init_variables(const struct gr_arg *arg)
55216+{
55217+ struct task_struct *reaper = init_pid_ns.child_reaper;
55218+ unsigned int stacksize;
55219+
55220+ subj_map_set.s_size = arg->role_db.num_subjects;
55221+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
55222+ name_set.n_size = arg->role_db.num_objects;
55223+ inodev_set.i_size = arg->role_db.num_objects;
55224+
55225+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
55226+ !name_set.n_size || !inodev_set.i_size)
55227+ return 1;
55228+
55229+ if (!gr_init_uidset())
55230+ return 1;
55231+
55232+ /* set up the stack that holds allocation info */
55233+
55234+ stacksize = arg->role_db.num_pointers + 5;
55235+
55236+ if (!acl_alloc_stack_init(stacksize))
55237+ return 1;
55238+
55239+ /* grab reference for the real root dentry and vfsmount */
55240+ get_fs_root(reaper->fs, &real_root);
55241+
55242+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55243+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
55244+#endif
55245+
55246+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
55247+ if (fakefs_obj_rw == NULL)
55248+ return 1;
55249+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
55250+
55251+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
55252+ if (fakefs_obj_rwx == NULL)
55253+ return 1;
55254+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
55255+
55256+ subj_map_set.s_hash =
55257+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
55258+ acl_role_set.r_hash =
55259+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
55260+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
55261+ inodev_set.i_hash =
55262+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
55263+
55264+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
55265+ !name_set.n_hash || !inodev_set.i_hash)
55266+ return 1;
55267+
55268+ memset(subj_map_set.s_hash, 0,
55269+ sizeof(struct subject_map *) * subj_map_set.s_size);
55270+ memset(acl_role_set.r_hash, 0,
55271+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
55272+ memset(name_set.n_hash, 0,
55273+ sizeof (struct name_entry *) * name_set.n_size);
55274+ memset(inodev_set.i_hash, 0,
55275+ sizeof (struct inodev_entry *) * inodev_set.i_size);
55276+
55277+ return 0;
55278+}
55279+
55280+/* free information not needed after startup
55281+ currently contains user->kernel pointer mappings for subjects
55282+*/
55283+
55284+static void
55285+free_init_variables(void)
55286+{
55287+ __u32 i;
55288+
55289+ if (subj_map_set.s_hash) {
55290+ for (i = 0; i < subj_map_set.s_size; i++) {
55291+ if (subj_map_set.s_hash[i]) {
55292+ kfree(subj_map_set.s_hash[i]);
55293+ subj_map_set.s_hash[i] = NULL;
55294+ }
55295+ }
55296+
55297+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
55298+ PAGE_SIZE)
55299+ kfree(subj_map_set.s_hash);
55300+ else
55301+ vfree(subj_map_set.s_hash);
55302+ }
55303+
55304+ return;
55305+}
55306+
55307+static void
55308+free_variables(void)
55309+{
55310+ struct acl_subject_label *s;
55311+ struct acl_role_label *r;
55312+ struct task_struct *task, *task2;
55313+ unsigned int x;
55314+
55315+ gr_clear_learn_entries();
55316+
55317+ read_lock(&tasklist_lock);
55318+ do_each_thread(task2, task) {
55319+ task->acl_sp_role = 0;
55320+ task->acl_role_id = 0;
55321+ task->acl = NULL;
55322+ task->role = NULL;
55323+ } while_each_thread(task2, task);
55324+ read_unlock(&tasklist_lock);
55325+
55326+ /* release the reference to the real root dentry and vfsmount */
55327+ path_put(&real_root);
55328+ memset(&real_root, 0, sizeof(real_root));
55329+
55330+ /* free all object hash tables */
55331+
55332+ FOR_EACH_ROLE_START(r)
55333+ if (r->subj_hash == NULL)
55334+ goto next_role;
55335+ FOR_EACH_SUBJECT_START(r, s, x)
55336+ if (s->obj_hash == NULL)
55337+ break;
55338+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
55339+ kfree(s->obj_hash);
55340+ else
55341+ vfree(s->obj_hash);
55342+ FOR_EACH_SUBJECT_END(s, x)
55343+ FOR_EACH_NESTED_SUBJECT_START(r, s)
55344+ if (s->obj_hash == NULL)
55345+ break;
55346+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
55347+ kfree(s->obj_hash);
55348+ else
55349+ vfree(s->obj_hash);
55350+ FOR_EACH_NESTED_SUBJECT_END(s)
55351+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
55352+ kfree(r->subj_hash);
55353+ else
55354+ vfree(r->subj_hash);
55355+ r->subj_hash = NULL;
55356+next_role:
55357+ FOR_EACH_ROLE_END(r)
55358+
55359+ acl_free_all();
55360+
55361+ if (acl_role_set.r_hash) {
55362+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
55363+ PAGE_SIZE)
55364+ kfree(acl_role_set.r_hash);
55365+ else
55366+ vfree(acl_role_set.r_hash);
55367+ }
55368+ if (name_set.n_hash) {
55369+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
55370+ PAGE_SIZE)
55371+ kfree(name_set.n_hash);
55372+ else
55373+ vfree(name_set.n_hash);
55374+ }
55375+
55376+ if (inodev_set.i_hash) {
55377+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
55378+ PAGE_SIZE)
55379+ kfree(inodev_set.i_hash);
55380+ else
55381+ vfree(inodev_set.i_hash);
55382+ }
55383+
55384+ gr_free_uidset();
55385+
55386+ memset(&name_set, 0, sizeof (struct name_db));
55387+ memset(&inodev_set, 0, sizeof (struct inodev_db));
55388+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
55389+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
55390+
55391+ default_role = NULL;
55392+ kernel_role = NULL;
55393+ role_list = NULL;
55394+
55395+ return;
55396+}
55397+
55398+static __u32
55399+count_user_objs(struct acl_object_label *userp)
55400+{
55401+ struct acl_object_label o_tmp;
55402+ __u32 num = 0;
55403+
55404+ while (userp) {
55405+ if (copy_from_user(&o_tmp, userp,
55406+ sizeof (struct acl_object_label)))
55407+ break;
55408+
55409+ userp = o_tmp.prev;
55410+ num++;
55411+ }
55412+
55413+ return num;
55414+}
55415+
55416+static struct acl_subject_label *
55417+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
55418+
55419+static int
55420+copy_user_glob(struct acl_object_label *obj)
55421+{
55422+ struct acl_object_label *g_tmp, **guser;
55423+ unsigned int len;
55424+ char *tmp;
55425+
55426+ if (obj->globbed == NULL)
55427+ return 0;
55428+
55429+ guser = &obj->globbed;
55430+ while (*guser) {
55431+ g_tmp = (struct acl_object_label *)
55432+ acl_alloc(sizeof (struct acl_object_label));
55433+ if (g_tmp == NULL)
55434+ return -ENOMEM;
55435+
55436+ if (copy_from_user(g_tmp, *guser,
55437+ sizeof (struct acl_object_label)))
55438+ return -EFAULT;
55439+
55440+ len = strnlen_user(g_tmp->filename, PATH_MAX);
55441+
55442+ if (!len || len >= PATH_MAX)
55443+ return -EINVAL;
55444+
55445+ if ((tmp = (char *) acl_alloc(len)) == NULL)
55446+ return -ENOMEM;
55447+
55448+ if (copy_from_user(tmp, g_tmp->filename, len))
55449+ return -EFAULT;
55450+ tmp[len-1] = '\0';
55451+ g_tmp->filename = tmp;
55452+
55453+ *guser = g_tmp;
55454+ guser = &(g_tmp->next);
55455+ }
55456+
55457+ return 0;
55458+}
55459+
55460+static int
55461+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
55462+ struct acl_role_label *role)
55463+{
55464+ struct acl_object_label *o_tmp;
55465+ unsigned int len;
55466+ int ret;
55467+ char *tmp;
55468+
55469+ while (userp) {
55470+ if ((o_tmp = (struct acl_object_label *)
55471+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
55472+ return -ENOMEM;
55473+
55474+ if (copy_from_user(o_tmp, userp,
55475+ sizeof (struct acl_object_label)))
55476+ return -EFAULT;
55477+
55478+ userp = o_tmp->prev;
55479+
55480+ len = strnlen_user(o_tmp->filename, PATH_MAX);
55481+
55482+ if (!len || len >= PATH_MAX)
55483+ return -EINVAL;
55484+
55485+ if ((tmp = (char *) acl_alloc(len)) == NULL)
55486+ return -ENOMEM;
55487+
55488+ if (copy_from_user(tmp, o_tmp->filename, len))
55489+ return -EFAULT;
55490+ tmp[len-1] = '\0';
55491+ o_tmp->filename = tmp;
55492+
55493+ insert_acl_obj_label(o_tmp, subj);
55494+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
55495+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
55496+ return -ENOMEM;
55497+
55498+ ret = copy_user_glob(o_tmp);
55499+ if (ret)
55500+ return ret;
55501+
55502+ if (o_tmp->nested) {
55503+ int already_copied;
55504+
55505+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
55506+ if (IS_ERR(o_tmp->nested))
55507+ return PTR_ERR(o_tmp->nested);
55508+
55509+ /* insert into nested subject list if we haven't copied this one yet
55510+ to prevent duplicate entries */
55511+ if (!already_copied) {
55512+ o_tmp->nested->next = role->hash->first;
55513+ role->hash->first = o_tmp->nested;
55514+ }
55515+ }
55516+ }
55517+
55518+ return 0;
55519+}
55520+
55521+static __u32
55522+count_user_subjs(struct acl_subject_label *userp)
55523+{
55524+ struct acl_subject_label s_tmp;
55525+ __u32 num = 0;
55526+
55527+ while (userp) {
55528+ if (copy_from_user(&s_tmp, userp,
55529+ sizeof (struct acl_subject_label)))
55530+ break;
55531+
55532+ userp = s_tmp.prev;
55533+ }
55534+
55535+ return num;
55536+}
55537+
55538+static int
55539+copy_user_allowedips(struct acl_role_label *rolep)
55540+{
55541+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
55542+
55543+ ruserip = rolep->allowed_ips;
55544+
55545+ while (ruserip) {
55546+ rlast = rtmp;
55547+
55548+ if ((rtmp = (struct role_allowed_ip *)
55549+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
55550+ return -ENOMEM;
55551+
55552+ if (copy_from_user(rtmp, ruserip,
55553+ sizeof (struct role_allowed_ip)))
55554+ return -EFAULT;
55555+
55556+ ruserip = rtmp->prev;
55557+
55558+ if (!rlast) {
55559+ rtmp->prev = NULL;
55560+ rolep->allowed_ips = rtmp;
55561+ } else {
55562+ rlast->next = rtmp;
55563+ rtmp->prev = rlast;
55564+ }
55565+
55566+ if (!ruserip)
55567+ rtmp->next = NULL;
55568+ }
55569+
55570+ return 0;
55571+}
55572+
55573+static int
55574+copy_user_transitions(struct acl_role_label *rolep)
55575+{
55576+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
55577+
55578+ unsigned int len;
55579+ char *tmp;
55580+
55581+ rusertp = rolep->transitions;
55582+
55583+ while (rusertp) {
55584+ rlast = rtmp;
55585+
55586+ if ((rtmp = (struct role_transition *)
55587+ acl_alloc(sizeof (struct role_transition))) == NULL)
55588+ return -ENOMEM;
55589+
55590+ if (copy_from_user(rtmp, rusertp,
55591+ sizeof (struct role_transition)))
55592+ return -EFAULT;
55593+
55594+ rusertp = rtmp->prev;
55595+
55596+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
55597+
55598+ if (!len || len >= GR_SPROLE_LEN)
55599+ return -EINVAL;
55600+
55601+ if ((tmp = (char *) acl_alloc(len)) == NULL)
55602+ return -ENOMEM;
55603+
55604+ if (copy_from_user(tmp, rtmp->rolename, len))
55605+ return -EFAULT;
55606+ tmp[len-1] = '\0';
55607+ rtmp->rolename = tmp;
55608+
55609+ if (!rlast) {
55610+ rtmp->prev = NULL;
55611+ rolep->transitions = rtmp;
55612+ } else {
55613+ rlast->next = rtmp;
55614+ rtmp->prev = rlast;
55615+ }
55616+
55617+ if (!rusertp)
55618+ rtmp->next = NULL;
55619+ }
55620+
55621+ return 0;
55622+}
55623+
55624+static struct acl_subject_label *
55625+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
55626+{
55627+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
55628+ unsigned int len;
55629+ char *tmp;
55630+ __u32 num_objs;
55631+ struct acl_ip_label **i_tmp, *i_utmp2;
55632+ struct gr_hash_struct ghash;
55633+ struct subject_map *subjmap;
55634+ unsigned int i_num;
55635+ int err;
55636+
55637+ if (already_copied != NULL)
55638+ *already_copied = 0;
55639+
55640+ s_tmp = lookup_subject_map(userp);
55641+
55642+ /* we've already copied this subject into the kernel, just return
55643+ the reference to it, and don't copy it over again
55644+ */
55645+ if (s_tmp) {
55646+ if (already_copied != NULL)
55647+ *already_copied = 1;
55648+ return(s_tmp);
55649+ }
55650+
55651+ if ((s_tmp = (struct acl_subject_label *)
55652+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
55653+ return ERR_PTR(-ENOMEM);
55654+
55655+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
55656+ if (subjmap == NULL)
55657+ return ERR_PTR(-ENOMEM);
55658+
55659+ subjmap->user = userp;
55660+ subjmap->kernel = s_tmp;
55661+ insert_subj_map_entry(subjmap);
55662+
55663+ if (copy_from_user(s_tmp, userp,
55664+ sizeof (struct acl_subject_label)))
55665+ return ERR_PTR(-EFAULT);
55666+
55667+ len = strnlen_user(s_tmp->filename, PATH_MAX);
55668+
55669+ if (!len || len >= PATH_MAX)
55670+ return ERR_PTR(-EINVAL);
55671+
55672+ if ((tmp = (char *) acl_alloc(len)) == NULL)
55673+ return ERR_PTR(-ENOMEM);
55674+
55675+ if (copy_from_user(tmp, s_tmp->filename, len))
55676+ return ERR_PTR(-EFAULT);
55677+ tmp[len-1] = '\0';
55678+ s_tmp->filename = tmp;
55679+
55680+ if (!strcmp(s_tmp->filename, "/"))
55681+ role->root_label = s_tmp;
55682+
55683+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
55684+ return ERR_PTR(-EFAULT);
55685+
55686+ /* copy user and group transition tables */
55687+
55688+ if (s_tmp->user_trans_num) {
55689+ uid_t *uidlist;
55690+
55691+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
55692+ if (uidlist == NULL)
55693+ return ERR_PTR(-ENOMEM);
55694+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
55695+ return ERR_PTR(-EFAULT);
55696+
55697+ s_tmp->user_transitions = uidlist;
55698+ }
55699+
55700+ if (s_tmp->group_trans_num) {
55701+ gid_t *gidlist;
55702+
55703+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
55704+ if (gidlist == NULL)
55705+ return ERR_PTR(-ENOMEM);
55706+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
55707+ return ERR_PTR(-EFAULT);
55708+
55709+ s_tmp->group_transitions = gidlist;
55710+ }
55711+
55712+ /* set up object hash table */
55713+ num_objs = count_user_objs(ghash.first);
55714+
55715+ s_tmp->obj_hash_size = num_objs;
55716+ s_tmp->obj_hash =
55717+ (struct acl_object_label **)
55718+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
55719+
55720+ if (!s_tmp->obj_hash)
55721+ return ERR_PTR(-ENOMEM);
55722+
55723+ memset(s_tmp->obj_hash, 0,
55724+ s_tmp->obj_hash_size *
55725+ sizeof (struct acl_object_label *));
55726+
55727+ /* add in objects */
55728+ err = copy_user_objs(ghash.first, s_tmp, role);
55729+
55730+ if (err)
55731+ return ERR_PTR(err);
55732+
55733+ /* set pointer for parent subject */
55734+ if (s_tmp->parent_subject) {
55735+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
55736+
55737+ if (IS_ERR(s_tmp2))
55738+ return s_tmp2;
55739+
55740+ s_tmp->parent_subject = s_tmp2;
55741+ }
55742+
55743+ /* add in ip acls */
55744+
55745+ if (!s_tmp->ip_num) {
55746+ s_tmp->ips = NULL;
55747+ goto insert;
55748+ }
55749+
55750+ i_tmp =
55751+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
55752+ sizeof (struct acl_ip_label *));
55753+
55754+ if (!i_tmp)
55755+ return ERR_PTR(-ENOMEM);
55756+
55757+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
55758+ *(i_tmp + i_num) =
55759+ (struct acl_ip_label *)
55760+ acl_alloc(sizeof (struct acl_ip_label));
55761+ if (!*(i_tmp + i_num))
55762+ return ERR_PTR(-ENOMEM);
55763+
55764+ if (copy_from_user
55765+ (&i_utmp2, s_tmp->ips + i_num,
55766+ sizeof (struct acl_ip_label *)))
55767+ return ERR_PTR(-EFAULT);
55768+
55769+ if (copy_from_user
55770+ (*(i_tmp + i_num), i_utmp2,
55771+ sizeof (struct acl_ip_label)))
55772+ return ERR_PTR(-EFAULT);
55773+
55774+ if ((*(i_tmp + i_num))->iface == NULL)
55775+ continue;
55776+
55777+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
55778+ if (!len || len >= IFNAMSIZ)
55779+ return ERR_PTR(-EINVAL);
55780+ tmp = acl_alloc(len);
55781+ if (tmp == NULL)
55782+ return ERR_PTR(-ENOMEM);
55783+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
55784+ return ERR_PTR(-EFAULT);
55785+ (*(i_tmp + i_num))->iface = tmp;
55786+ }
55787+
55788+ s_tmp->ips = i_tmp;
55789+
55790+insert:
55791+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
55792+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
55793+ return ERR_PTR(-ENOMEM);
55794+
55795+ return s_tmp;
55796+}
55797+
55798+static int
55799+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
55800+{
55801+ struct acl_subject_label s_pre;
55802+ struct acl_subject_label * ret;
55803+ int err;
55804+
55805+ while (userp) {
55806+ if (copy_from_user(&s_pre, userp,
55807+ sizeof (struct acl_subject_label)))
55808+ return -EFAULT;
55809+
55810+ ret = do_copy_user_subj(userp, role, NULL);
55811+
55812+ err = PTR_ERR(ret);
55813+ if (IS_ERR(ret))
55814+ return err;
55815+
55816+ insert_acl_subj_label(ret, role);
55817+
55818+ userp = s_pre.prev;
55819+ }
55820+
55821+ return 0;
55822+}
55823+
55824+static int
55825+copy_user_acl(struct gr_arg *arg)
55826+{
55827+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
55828+ struct acl_subject_label *subj_list;
55829+ struct sprole_pw *sptmp;
55830+ struct gr_hash_struct *ghash;
55831+ uid_t *domainlist;
55832+ unsigned int r_num;
55833+ unsigned int len;
55834+ char *tmp;
55835+ int err = 0;
55836+ __u16 i;
55837+ __u32 num_subjs;
55838+
55839+ /* we need a default and kernel role */
55840+ if (arg->role_db.num_roles < 2)
55841+ return -EINVAL;
55842+
55843+ /* copy special role authentication info from userspace */
55844+
55845+ num_sprole_pws = arg->num_sprole_pws;
55846+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
55847+
55848+ if (!acl_special_roles && num_sprole_pws)
55849+ return -ENOMEM;
55850+
55851+ for (i = 0; i < num_sprole_pws; i++) {
55852+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
55853+ if (!sptmp)
55854+ return -ENOMEM;
55855+ if (copy_from_user(sptmp, arg->sprole_pws + i,
55856+ sizeof (struct sprole_pw)))
55857+ return -EFAULT;
55858+
55859+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
55860+
55861+ if (!len || len >= GR_SPROLE_LEN)
55862+ return -EINVAL;
55863+
55864+ if ((tmp = (char *) acl_alloc(len)) == NULL)
55865+ return -ENOMEM;
55866+
55867+ if (copy_from_user(tmp, sptmp->rolename, len))
55868+ return -EFAULT;
55869+
55870+ tmp[len-1] = '\0';
55871+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55872+ printk(KERN_ALERT "Copying special role %s\n", tmp);
55873+#endif
55874+ sptmp->rolename = tmp;
55875+ acl_special_roles[i] = sptmp;
55876+ }
55877+
55878+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
55879+
55880+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
55881+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
55882+
55883+ if (!r_tmp)
55884+ return -ENOMEM;
55885+
55886+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
55887+ sizeof (struct acl_role_label *)))
55888+ return -EFAULT;
55889+
55890+ if (copy_from_user(r_tmp, r_utmp2,
55891+ sizeof (struct acl_role_label)))
55892+ return -EFAULT;
55893+
55894+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
55895+
55896+ if (!len || len >= PATH_MAX)
55897+ return -EINVAL;
55898+
55899+ if ((tmp = (char *) acl_alloc(len)) == NULL)
55900+ return -ENOMEM;
55901+
55902+ if (copy_from_user(tmp, r_tmp->rolename, len))
55903+ return -EFAULT;
55904+
55905+ tmp[len-1] = '\0';
55906+ r_tmp->rolename = tmp;
55907+
55908+ if (!strcmp(r_tmp->rolename, "default")
55909+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
55910+ default_role = r_tmp;
55911+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
55912+ kernel_role = r_tmp;
55913+ }
55914+
55915+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
55916+ return -ENOMEM;
55917+
55918+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
55919+ return -EFAULT;
55920+
55921+ r_tmp->hash = ghash;
55922+
55923+ num_subjs = count_user_subjs(r_tmp->hash->first);
55924+
55925+ r_tmp->subj_hash_size = num_subjs;
55926+ r_tmp->subj_hash =
55927+ (struct acl_subject_label **)
55928+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
55929+
55930+ if (!r_tmp->subj_hash)
55931+ return -ENOMEM;
55932+
55933+ err = copy_user_allowedips(r_tmp);
55934+ if (err)
55935+ return err;
55936+
55937+ /* copy domain info */
55938+ if (r_tmp->domain_children != NULL) {
55939+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
55940+ if (domainlist == NULL)
55941+ return -ENOMEM;
55942+
55943+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
55944+ return -EFAULT;
55945+
55946+ r_tmp->domain_children = domainlist;
55947+ }
55948+
55949+ err = copy_user_transitions(r_tmp);
55950+ if (err)
55951+ return err;
55952+
55953+ memset(r_tmp->subj_hash, 0,
55954+ r_tmp->subj_hash_size *
55955+ sizeof (struct acl_subject_label *));
55956+
55957+ /* acquire the list of subjects, then NULL out
55958+ the list prior to parsing the subjects for this role,
55959+ as during this parsing the list is replaced with a list
55960+ of *nested* subjects for the role
55961+ */
55962+ subj_list = r_tmp->hash->first;
55963+
55964+ /* set nested subject list to null */
55965+ r_tmp->hash->first = NULL;
55966+
55967+ err = copy_user_subjs(subj_list, r_tmp);
55968+
55969+ if (err)
55970+ return err;
55971+
55972+ insert_acl_role_label(r_tmp);
55973+ }
55974+
55975+ if (default_role == NULL || kernel_role == NULL)
55976+ return -EINVAL;
55977+
55978+ return err;
55979+}
55980+
55981+static int
55982+gracl_init(struct gr_arg *args)
55983+{
55984+ int error = 0;
55985+
55986+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
55987+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
55988+
55989+ if (init_variables(args)) {
55990+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
55991+ error = -ENOMEM;
55992+ free_variables();
55993+ goto out;
55994+ }
55995+
55996+ error = copy_user_acl(args);
55997+ free_init_variables();
55998+ if (error) {
55999+ free_variables();
56000+ goto out;
56001+ }
56002+
56003+ if ((error = gr_set_acls(0))) {
56004+ free_variables();
56005+ goto out;
56006+ }
56007+
56008+ pax_open_kernel();
56009+ gr_status |= GR_READY;
56010+ pax_close_kernel();
56011+
56012+ out:
56013+ return error;
56014+}
56015+
56016+/* derived from glibc fnmatch() 0: match, 1: no match*/
56017+
56018+static int
56019+glob_match(const char *p, const char *n)
56020+{
56021+ char c;
56022+
56023+ while ((c = *p++) != '\0') {
56024+ switch (c) {
56025+ case '?':
56026+ if (*n == '\0')
56027+ return 1;
56028+ else if (*n == '/')
56029+ return 1;
56030+ break;
56031+ case '\\':
56032+ if (*n != c)
56033+ return 1;
56034+ break;
56035+ case '*':
56036+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
56037+ if (*n == '/')
56038+ return 1;
56039+ else if (c == '?') {
56040+ if (*n == '\0')
56041+ return 1;
56042+ else
56043+ ++n;
56044+ }
56045+ }
56046+ if (c == '\0') {
56047+ return 0;
56048+ } else {
56049+ const char *endp;
56050+
56051+ if ((endp = strchr(n, '/')) == NULL)
56052+ endp = n + strlen(n);
56053+
56054+ if (c == '[') {
56055+ for (--p; n < endp; ++n)
56056+ if (!glob_match(p, n))
56057+ return 0;
56058+ } else if (c == '/') {
56059+ while (*n != '\0' && *n != '/')
56060+ ++n;
56061+ if (*n == '/' && !glob_match(p, n + 1))
56062+ return 0;
56063+ } else {
56064+ for (--p; n < endp; ++n)
56065+ if (*n == c && !glob_match(p, n))
56066+ return 0;
56067+ }
56068+
56069+ return 1;
56070+ }
56071+ case '[':
56072+ {
56073+ int not;
56074+ char cold;
56075+
56076+ if (*n == '\0' || *n == '/')
56077+ return 1;
56078+
56079+ not = (*p == '!' || *p == '^');
56080+ if (not)
56081+ ++p;
56082+
56083+ c = *p++;
56084+ for (;;) {
56085+ unsigned char fn = (unsigned char)*n;
56086+
56087+ if (c == '\0')
56088+ return 1;
56089+ else {
56090+ if (c == fn)
56091+ goto matched;
56092+ cold = c;
56093+ c = *p++;
56094+
56095+ if (c == '-' && *p != ']') {
56096+ unsigned char cend = *p++;
56097+
56098+ if (cend == '\0')
56099+ return 1;
56100+
56101+ if (cold <= fn && fn <= cend)
56102+ goto matched;
56103+
56104+ c = *p++;
56105+ }
56106+ }
56107+
56108+ if (c == ']')
56109+ break;
56110+ }
56111+ if (!not)
56112+ return 1;
56113+ break;
56114+ matched:
56115+ while (c != ']') {
56116+ if (c == '\0')
56117+ return 1;
56118+
56119+ c = *p++;
56120+ }
56121+ if (not)
56122+ return 1;
56123+ }
56124+ break;
56125+ default:
56126+ if (c != *n)
56127+ return 1;
56128+ }
56129+
56130+ ++n;
56131+ }
56132+
56133+ if (*n == '\0')
56134+ return 0;
56135+
56136+ if (*n == '/')
56137+ return 0;
56138+
56139+ return 1;
56140+}
56141+
56142+static struct acl_object_label *
56143+chk_glob_label(struct acl_object_label *globbed,
56144+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
56145+{
56146+ struct acl_object_label *tmp;
56147+
56148+ if (*path == NULL)
56149+ *path = gr_to_filename_nolock(dentry, mnt);
56150+
56151+ tmp = globbed;
56152+
56153+ while (tmp) {
56154+ if (!glob_match(tmp->filename, *path))
56155+ return tmp;
56156+ tmp = tmp->next;
56157+ }
56158+
56159+ return NULL;
56160+}
56161+
56162+static struct acl_object_label *
56163+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
56164+ const ino_t curr_ino, const dev_t curr_dev,
56165+ const struct acl_subject_label *subj, char **path, const int checkglob)
56166+{
56167+ struct acl_subject_label *tmpsubj;
56168+ struct acl_object_label *retval;
56169+ struct acl_object_label *retval2;
56170+
56171+ tmpsubj = (struct acl_subject_label *) subj;
56172+ read_lock(&gr_inode_lock);
56173+ do {
56174+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
56175+ if (retval) {
56176+ if (checkglob && retval->globbed) {
56177+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
56178+ if (retval2)
56179+ retval = retval2;
56180+ }
56181+ break;
56182+ }
56183+ } while ((tmpsubj = tmpsubj->parent_subject));
56184+ read_unlock(&gr_inode_lock);
56185+
56186+ return retval;
56187+}
56188+
56189+static __inline__ struct acl_object_label *
56190+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
56191+ struct dentry *curr_dentry,
56192+ const struct acl_subject_label *subj, char **path, const int checkglob)
56193+{
56194+ int newglob = checkglob;
56195+ ino_t inode;
56196+ dev_t device;
56197+
56198+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
56199+ as we don't want a / * rule to match instead of the / object
56200+ don't do this for create lookups that call this function though, since they're looking up
56201+ on the parent and thus need globbing checks on all paths
56202+ */
56203+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
56204+ newglob = GR_NO_GLOB;
56205+
56206+ spin_lock(&curr_dentry->d_lock);
56207+ inode = curr_dentry->d_inode->i_ino;
56208+ device = __get_dev(curr_dentry);
56209+ spin_unlock(&curr_dentry->d_lock);
56210+
56211+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
56212+}
56213+
56214+#ifdef CONFIG_HUGETLBFS
56215+static inline bool
56216+is_hugetlbfs_mnt(const struct vfsmount *mnt)
56217+{
56218+ int i;
56219+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
56220+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
56221+ return true;
56222+ }
56223+
56224+ return false;
56225+}
56226+#endif
56227+
56228+static struct acl_object_label *
56229+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56230+ const struct acl_subject_label *subj, char *path, const int checkglob)
56231+{
56232+ struct dentry *dentry = (struct dentry *) l_dentry;
56233+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
56234+ struct mount *real_mnt = real_mount(mnt);
56235+ struct acl_object_label *retval;
56236+ struct dentry *parent;
56237+
56238+ write_seqlock(&rename_lock);
56239+ br_read_lock(&vfsmount_lock);
56240+
56241+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
56242+#ifdef CONFIG_NET
56243+ mnt == sock_mnt ||
56244+#endif
56245+#ifdef CONFIG_HUGETLBFS
56246+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
56247+#endif
56248+ /* ignore Eric Biederman */
56249+ IS_PRIVATE(l_dentry->d_inode))) {
56250+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
56251+ goto out;
56252+ }
56253+
56254+ for (;;) {
56255+ if (dentry == real_root.dentry && mnt == real_root.mnt)
56256+ break;
56257+
56258+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
56259+ if (!mnt_has_parent(real_mnt))
56260+ break;
56261+
56262+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
56263+ if (retval != NULL)
56264+ goto out;
56265+
56266+ dentry = real_mnt->mnt_mountpoint;
56267+ real_mnt = real_mnt->mnt_parent;
56268+ mnt = &real_mnt->mnt;
56269+ continue;
56270+ }
56271+
56272+ parent = dentry->d_parent;
56273+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
56274+ if (retval != NULL)
56275+ goto out;
56276+
56277+ dentry = parent;
56278+ }
56279+
56280+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
56281+
56282+ /* real_root is pinned so we don't have to hold a reference */
56283+ if (retval == NULL)
56284+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
56285+out:
56286+ br_read_unlock(&vfsmount_lock);
56287+ write_sequnlock(&rename_lock);
56288+
56289+ BUG_ON(retval == NULL);
56290+
56291+ return retval;
56292+}
56293+
56294+static __inline__ struct acl_object_label *
56295+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56296+ const struct acl_subject_label *subj)
56297+{
56298+ char *path = NULL;
56299+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
56300+}
56301+
56302+static __inline__ struct acl_object_label *
56303+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56304+ const struct acl_subject_label *subj)
56305+{
56306+ char *path = NULL;
56307+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
56308+}
56309+
56310+static __inline__ struct acl_object_label *
56311+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56312+ const struct acl_subject_label *subj, char *path)
56313+{
56314+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
56315+}
56316+
56317+static struct acl_subject_label *
56318+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56319+ const struct acl_role_label *role)
56320+{
56321+ struct dentry *dentry = (struct dentry *) l_dentry;
56322+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
56323+ struct mount *real_mnt = real_mount(mnt);
56324+ struct acl_subject_label *retval;
56325+ struct dentry *parent;
56326+
56327+ write_seqlock(&rename_lock);
56328+ br_read_lock(&vfsmount_lock);
56329+
56330+ for (;;) {
56331+ if (dentry == real_root.dentry && mnt == real_root.mnt)
56332+ break;
56333+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
56334+ if (!mnt_has_parent(real_mnt))
56335+ break;
56336+
56337+ spin_lock(&dentry->d_lock);
56338+ read_lock(&gr_inode_lock);
56339+ retval =
56340+ lookup_acl_subj_label(dentry->d_inode->i_ino,
56341+ __get_dev(dentry), role);
56342+ read_unlock(&gr_inode_lock);
56343+ spin_unlock(&dentry->d_lock);
56344+ if (retval != NULL)
56345+ goto out;
56346+
56347+ dentry = real_mnt->mnt_mountpoint;
56348+ real_mnt = real_mnt->mnt_parent;
56349+ mnt = &real_mnt->mnt;
56350+ continue;
56351+ }
56352+
56353+ spin_lock(&dentry->d_lock);
56354+ read_lock(&gr_inode_lock);
56355+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
56356+ __get_dev(dentry), role);
56357+ read_unlock(&gr_inode_lock);
56358+ parent = dentry->d_parent;
56359+ spin_unlock(&dentry->d_lock);
56360+
56361+ if (retval != NULL)
56362+ goto out;
56363+
56364+ dentry = parent;
56365+ }
56366+
56367+ spin_lock(&dentry->d_lock);
56368+ read_lock(&gr_inode_lock);
56369+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
56370+ __get_dev(dentry), role);
56371+ read_unlock(&gr_inode_lock);
56372+ spin_unlock(&dentry->d_lock);
56373+
56374+ if (unlikely(retval == NULL)) {
56375+ /* real_root is pinned, we don't need to hold a reference */
56376+ read_lock(&gr_inode_lock);
56377+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
56378+ __get_dev(real_root.dentry), role);
56379+ read_unlock(&gr_inode_lock);
56380+ }
56381+out:
56382+ br_read_unlock(&vfsmount_lock);
56383+ write_sequnlock(&rename_lock);
56384+
56385+ BUG_ON(retval == NULL);
56386+
56387+ return retval;
56388+}
56389+
56390+static void
56391+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
56392+{
56393+ struct task_struct *task = current;
56394+ const struct cred *cred = current_cred();
56395+
56396+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
56397+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
56398+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
56399+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
56400+
56401+ return;
56402+}
56403+
56404+static void
56405+gr_log_learn_id_change(const char type, const unsigned int real,
56406+ const unsigned int effective, const unsigned int fs)
56407+{
56408+ struct task_struct *task = current;
56409+ const struct cred *cred = current_cred();
56410+
56411+ security_learn(GR_ID_LEARN_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+ type, real, effective, fs, &task->signal->saved_ip);
56415+
56416+ return;
56417+}
56418+
56419+__u32
56420+gr_search_file(const struct dentry * dentry, const __u32 mode,
56421+ const struct vfsmount * mnt)
56422+{
56423+ __u32 retval = mode;
56424+ struct acl_subject_label *curracl;
56425+ struct acl_object_label *currobj;
56426+
56427+ if (unlikely(!(gr_status & GR_READY)))
56428+ return (mode & ~GR_AUDITS);
56429+
56430+ curracl = current->acl;
56431+
56432+ currobj = chk_obj_label(dentry, mnt, curracl);
56433+ retval = currobj->mode & mode;
56434+
56435+ /* if we're opening a specified transfer file for writing
56436+ (e.g. /dev/initctl), then transfer our role to init
56437+ */
56438+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
56439+ current->role->roletype & GR_ROLE_PERSIST)) {
56440+ struct task_struct *task = init_pid_ns.child_reaper;
56441+
56442+ if (task->role != current->role) {
56443+ task->acl_sp_role = 0;
56444+ task->acl_role_id = current->acl_role_id;
56445+ task->role = current->role;
56446+ rcu_read_lock();
56447+ read_lock(&grsec_exec_file_lock);
56448+ gr_apply_subject_to_task(task);
56449+ read_unlock(&grsec_exec_file_lock);
56450+ rcu_read_unlock();
56451+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
56452+ }
56453+ }
56454+
56455+ if (unlikely
56456+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
56457+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
56458+ __u32 new_mode = mode;
56459+
56460+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
56461+
56462+ retval = new_mode;
56463+
56464+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
56465+ new_mode |= GR_INHERIT;
56466+
56467+ if (!(mode & GR_NOLEARN))
56468+ gr_log_learn(dentry, mnt, new_mode);
56469+ }
56470+
56471+ return retval;
56472+}
56473+
56474+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
56475+ const struct dentry *parent,
56476+ const struct vfsmount *mnt)
56477+{
56478+ struct name_entry *match;
56479+ struct acl_object_label *matchpo;
56480+ struct acl_subject_label *curracl;
56481+ char *path;
56482+
56483+ if (unlikely(!(gr_status & GR_READY)))
56484+ return NULL;
56485+
56486+ preempt_disable();
56487+ path = gr_to_filename_rbac(new_dentry, mnt);
56488+ match = lookup_name_entry_create(path);
56489+
56490+ curracl = current->acl;
56491+
56492+ if (match) {
56493+ read_lock(&gr_inode_lock);
56494+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
56495+ read_unlock(&gr_inode_lock);
56496+
56497+ if (matchpo) {
56498+ preempt_enable();
56499+ return matchpo;
56500+ }
56501+ }
56502+
56503+ // lookup parent
56504+
56505+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
56506+
56507+ preempt_enable();
56508+ return matchpo;
56509+}
56510+
56511+__u32
56512+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
56513+ const struct vfsmount * mnt, const __u32 mode)
56514+{
56515+ struct acl_object_label *matchpo;
56516+ __u32 retval;
56517+
56518+ if (unlikely(!(gr_status & GR_READY)))
56519+ return (mode & ~GR_AUDITS);
56520+
56521+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
56522+
56523+ retval = matchpo->mode & mode;
56524+
56525+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
56526+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
56527+ __u32 new_mode = mode;
56528+
56529+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
56530+
56531+ gr_log_learn(new_dentry, mnt, new_mode);
56532+ return new_mode;
56533+ }
56534+
56535+ return retval;
56536+}
56537+
56538+__u32
56539+gr_check_link(const struct dentry * new_dentry,
56540+ const struct dentry * parent_dentry,
56541+ const struct vfsmount * parent_mnt,
56542+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
56543+{
56544+ struct acl_object_label *obj;
56545+ __u32 oldmode, newmode;
56546+ __u32 needmode;
56547+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
56548+ GR_DELETE | GR_INHERIT;
56549+
56550+ if (unlikely(!(gr_status & GR_READY)))
56551+ return (GR_CREATE | GR_LINK);
56552+
56553+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
56554+ oldmode = obj->mode;
56555+
56556+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
56557+ newmode = obj->mode;
56558+
56559+ needmode = newmode & checkmodes;
56560+
56561+ // old name for hardlink must have at least the permissions of the new name
56562+ if ((oldmode & needmode) != needmode)
56563+ goto bad;
56564+
56565+ // if old name had restrictions/auditing, make sure the new name does as well
56566+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
56567+
56568+ // don't allow hardlinking of suid/sgid/fcapped files without permission
56569+ if (is_privileged_binary(old_dentry))
56570+ needmode |= GR_SETID;
56571+
56572+ if ((newmode & needmode) != needmode)
56573+ goto bad;
56574+
56575+ // enforce minimum permissions
56576+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
56577+ return newmode;
56578+bad:
56579+ needmode = oldmode;
56580+ if (is_privileged_binary(old_dentry))
56581+ needmode |= GR_SETID;
56582+
56583+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
56584+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
56585+ return (GR_CREATE | GR_LINK);
56586+ } else if (newmode & GR_SUPPRESS)
56587+ return GR_SUPPRESS;
56588+ else
56589+ return 0;
56590+}
56591+
56592+int
56593+gr_check_hidden_task(const struct task_struct *task)
56594+{
56595+ if (unlikely(!(gr_status & GR_READY)))
56596+ return 0;
56597+
56598+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
56599+ return 1;
56600+
56601+ return 0;
56602+}
56603+
56604+int
56605+gr_check_protected_task(const struct task_struct *task)
56606+{
56607+ if (unlikely(!(gr_status & GR_READY) || !task))
56608+ return 0;
56609+
56610+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
56611+ task->acl != current->acl)
56612+ return 1;
56613+
56614+ return 0;
56615+}
56616+
56617+int
56618+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
56619+{
56620+ struct task_struct *p;
56621+ int ret = 0;
56622+
56623+ if (unlikely(!(gr_status & GR_READY) || !pid))
56624+ return ret;
56625+
56626+ read_lock(&tasklist_lock);
56627+ do_each_pid_task(pid, type, p) {
56628+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
56629+ p->acl != current->acl) {
56630+ ret = 1;
56631+ goto out;
56632+ }
56633+ } while_each_pid_task(pid, type, p);
56634+out:
56635+ read_unlock(&tasklist_lock);
56636+
56637+ return ret;
56638+}
56639+
56640+void
56641+gr_copy_label(struct task_struct *tsk)
56642+{
56643+ tsk->signal->used_accept = 0;
56644+ tsk->acl_sp_role = 0;
56645+ tsk->acl_role_id = current->acl_role_id;
56646+ tsk->acl = current->acl;
56647+ tsk->role = current->role;
56648+ tsk->signal->curr_ip = current->signal->curr_ip;
56649+ tsk->signal->saved_ip = current->signal->saved_ip;
56650+ if (current->exec_file)
56651+ get_file(current->exec_file);
56652+ tsk->exec_file = current->exec_file;
56653+ tsk->is_writable = current->is_writable;
56654+ if (unlikely(current->signal->used_accept)) {
56655+ current->signal->curr_ip = 0;
56656+ current->signal->saved_ip = 0;
56657+ }
56658+
56659+ return;
56660+}
56661+
56662+static void
56663+gr_set_proc_res(struct task_struct *task)
56664+{
56665+ struct acl_subject_label *proc;
56666+ unsigned short i;
56667+
56668+ proc = task->acl;
56669+
56670+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
56671+ return;
56672+
56673+ for (i = 0; i < RLIM_NLIMITS; i++) {
56674+ if (!(proc->resmask & (1 << i)))
56675+ continue;
56676+
56677+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
56678+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
56679+ }
56680+
56681+ return;
56682+}
56683+
56684+extern int __gr_process_user_ban(struct user_struct *user);
56685+
56686+int
56687+gr_check_user_change(int real, int effective, int fs)
56688+{
56689+ unsigned int i;
56690+ __u16 num;
56691+ uid_t *uidlist;
56692+ int curuid;
56693+ int realok = 0;
56694+ int effectiveok = 0;
56695+ int fsok = 0;
56696+
56697+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
56698+ struct user_struct *user;
56699+
56700+ if (real == -1)
56701+ goto skipit;
56702+
56703+ user = find_user(real);
56704+ if (user == NULL)
56705+ goto skipit;
56706+
56707+ if (__gr_process_user_ban(user)) {
56708+ /* for find_user */
56709+ free_uid(user);
56710+ return 1;
56711+ }
56712+
56713+ /* for find_user */
56714+ free_uid(user);
56715+
56716+skipit:
56717+#endif
56718+
56719+ if (unlikely(!(gr_status & GR_READY)))
56720+ return 0;
56721+
56722+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
56723+ gr_log_learn_id_change('u', real, effective, fs);
56724+
56725+ num = current->acl->user_trans_num;
56726+ uidlist = current->acl->user_transitions;
56727+
56728+ if (uidlist == NULL)
56729+ return 0;
56730+
56731+ if (real == -1)
56732+ realok = 1;
56733+ if (effective == -1)
56734+ effectiveok = 1;
56735+ if (fs == -1)
56736+ fsok = 1;
56737+
56738+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
56739+ for (i = 0; i < num; i++) {
56740+ curuid = (int)uidlist[i];
56741+ if (real == curuid)
56742+ realok = 1;
56743+ if (effective == curuid)
56744+ effectiveok = 1;
56745+ if (fs == curuid)
56746+ fsok = 1;
56747+ }
56748+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
56749+ for (i = 0; i < num; i++) {
56750+ curuid = (int)uidlist[i];
56751+ if (real == curuid)
56752+ break;
56753+ if (effective == curuid)
56754+ break;
56755+ if (fs == curuid)
56756+ break;
56757+ }
56758+ /* not in deny list */
56759+ if (i == num) {
56760+ realok = 1;
56761+ effectiveok = 1;
56762+ fsok = 1;
56763+ }
56764+ }
56765+
56766+ if (realok && effectiveok && fsok)
56767+ return 0;
56768+ else {
56769+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
56770+ return 1;
56771+ }
56772+}
56773+
56774+int
56775+gr_check_group_change(int real, int effective, int fs)
56776+{
56777+ unsigned int i;
56778+ __u16 num;
56779+ gid_t *gidlist;
56780+ int curgid;
56781+ int realok = 0;
56782+ int effectiveok = 0;
56783+ int fsok = 0;
56784+
56785+ if (unlikely(!(gr_status & GR_READY)))
56786+ return 0;
56787+
56788+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
56789+ gr_log_learn_id_change('g', real, effective, fs);
56790+
56791+ num = current->acl->group_trans_num;
56792+ gidlist = current->acl->group_transitions;
56793+
56794+ if (gidlist == NULL)
56795+ return 0;
56796+
56797+ if (real == -1)
56798+ realok = 1;
56799+ if (effective == -1)
56800+ effectiveok = 1;
56801+ if (fs == -1)
56802+ fsok = 1;
56803+
56804+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
56805+ for (i = 0; i < num; i++) {
56806+ curgid = (int)gidlist[i];
56807+ if (real == curgid)
56808+ realok = 1;
56809+ if (effective == curgid)
56810+ effectiveok = 1;
56811+ if (fs == curgid)
56812+ fsok = 1;
56813+ }
56814+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
56815+ for (i = 0; i < num; i++) {
56816+ curgid = (int)gidlist[i];
56817+ if (real == curgid)
56818+ break;
56819+ if (effective == curgid)
56820+ break;
56821+ if (fs == curgid)
56822+ break;
56823+ }
56824+ /* not in deny list */
56825+ if (i == num) {
56826+ realok = 1;
56827+ effectiveok = 1;
56828+ fsok = 1;
56829+ }
56830+ }
56831+
56832+ if (realok && effectiveok && fsok)
56833+ return 0;
56834+ else {
56835+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
56836+ return 1;
56837+ }
56838+}
56839+
56840+extern int gr_acl_is_capable(const int cap);
56841+
56842+void
56843+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
56844+{
56845+ struct acl_role_label *role = task->role;
56846+ struct acl_subject_label *subj = NULL;
56847+ struct acl_object_label *obj;
56848+ struct file *filp;
56849+
56850+ if (unlikely(!(gr_status & GR_READY)))
56851+ return;
56852+
56853+ filp = task->exec_file;
56854+
56855+ /* kernel process, we'll give them the kernel role */
56856+ if (unlikely(!filp)) {
56857+ task->role = kernel_role;
56858+ task->acl = kernel_role->root_label;
56859+ return;
56860+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
56861+ role = lookup_acl_role_label(task, uid, gid);
56862+
56863+ /* don't change the role if we're not a privileged process */
56864+ if (role && task->role != role &&
56865+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
56866+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
56867+ return;
56868+
56869+ /* perform subject lookup in possibly new role
56870+ we can use this result below in the case where role == task->role
56871+ */
56872+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
56873+
56874+ /* if we changed uid/gid, but result in the same role
56875+ and are using inheritance, don't lose the inherited subject
56876+ if current subject is other than what normal lookup
56877+ would result in, we arrived via inheritance, don't
56878+ lose subject
56879+ */
56880+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
56881+ (subj == task->acl)))
56882+ task->acl = subj;
56883+
56884+ task->role = role;
56885+
56886+ task->is_writable = 0;
56887+
56888+ /* ignore additional mmap checks for processes that are writable
56889+ by the default ACL */
56890+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
56891+ if (unlikely(obj->mode & GR_WRITE))
56892+ task->is_writable = 1;
56893+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
56894+ if (unlikely(obj->mode & GR_WRITE))
56895+ task->is_writable = 1;
56896+
56897+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56898+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
56899+#endif
56900+
56901+ gr_set_proc_res(task);
56902+
56903+ return;
56904+}
56905+
56906+int
56907+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
56908+ const int unsafe_flags)
56909+{
56910+ struct task_struct *task = current;
56911+ struct acl_subject_label *newacl;
56912+ struct acl_object_label *obj;
56913+ __u32 retmode;
56914+
56915+ if (unlikely(!(gr_status & GR_READY)))
56916+ return 0;
56917+
56918+ newacl = chk_subj_label(dentry, mnt, task->role);
56919+
56920+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
56921+ did an exec
56922+ */
56923+ rcu_read_lock();
56924+ read_lock(&tasklist_lock);
56925+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
56926+ (task->parent->acl->mode & GR_POVERRIDE))) {
56927+ read_unlock(&tasklist_lock);
56928+ rcu_read_unlock();
56929+ goto skip_check;
56930+ }
56931+ read_unlock(&tasklist_lock);
56932+ rcu_read_unlock();
56933+
56934+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
56935+ !(task->role->roletype & GR_ROLE_GOD) &&
56936+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
56937+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
56938+ if (unsafe_flags & LSM_UNSAFE_SHARE)
56939+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
56940+ else
56941+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
56942+ return -EACCES;
56943+ }
56944+
56945+skip_check:
56946+
56947+ obj = chk_obj_label(dentry, mnt, task->acl);
56948+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
56949+
56950+ if (!(task->acl->mode & GR_INHERITLEARN) &&
56951+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
56952+ if (obj->nested)
56953+ task->acl = obj->nested;
56954+ else
56955+ task->acl = newacl;
56956+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
56957+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
56958+
56959+ task->is_writable = 0;
56960+
56961+ /* ignore additional mmap checks for processes that are writable
56962+ by the default ACL */
56963+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
56964+ if (unlikely(obj->mode & GR_WRITE))
56965+ task->is_writable = 1;
56966+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
56967+ if (unlikely(obj->mode & GR_WRITE))
56968+ task->is_writable = 1;
56969+
56970+ gr_set_proc_res(task);
56971+
56972+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56973+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
56974+#endif
56975+ return 0;
56976+}
56977+
56978+/* always called with valid inodev ptr */
56979+static void
56980+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
56981+{
56982+ struct acl_object_label *matchpo;
56983+ struct acl_subject_label *matchps;
56984+ struct acl_subject_label *subj;
56985+ struct acl_role_label *role;
56986+ unsigned int x;
56987+
56988+ FOR_EACH_ROLE_START(role)
56989+ FOR_EACH_SUBJECT_START(role, subj, x)
56990+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
56991+ matchpo->mode |= GR_DELETED;
56992+ FOR_EACH_SUBJECT_END(subj,x)
56993+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
56994+ /* nested subjects aren't in the role's subj_hash table */
56995+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
56996+ matchpo->mode |= GR_DELETED;
56997+ FOR_EACH_NESTED_SUBJECT_END(subj)
56998+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
56999+ matchps->mode |= GR_DELETED;
57000+ FOR_EACH_ROLE_END(role)
57001+
57002+ inodev->nentry->deleted = 1;
57003+
57004+ return;
57005+}
57006+
57007+void
57008+gr_handle_delete(const ino_t ino, const dev_t dev)
57009+{
57010+ struct inodev_entry *inodev;
57011+
57012+ if (unlikely(!(gr_status & GR_READY)))
57013+ return;
57014+
57015+ write_lock(&gr_inode_lock);
57016+ inodev = lookup_inodev_entry(ino, dev);
57017+ if (inodev != NULL)
57018+ do_handle_delete(inodev, ino, dev);
57019+ write_unlock(&gr_inode_lock);
57020+
57021+ return;
57022+}
57023+
57024+static void
57025+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
57026+ const ino_t newinode, const dev_t newdevice,
57027+ struct acl_subject_label *subj)
57028+{
57029+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
57030+ struct acl_object_label *match;
57031+
57032+ match = subj->obj_hash[index];
57033+
57034+ while (match && (match->inode != oldinode ||
57035+ match->device != olddevice ||
57036+ !(match->mode & GR_DELETED)))
57037+ match = match->next;
57038+
57039+ if (match && (match->inode == oldinode)
57040+ && (match->device == olddevice)
57041+ && (match->mode & GR_DELETED)) {
57042+ if (match->prev == NULL) {
57043+ subj->obj_hash[index] = match->next;
57044+ if (match->next != NULL)
57045+ match->next->prev = NULL;
57046+ } else {
57047+ match->prev->next = match->next;
57048+ if (match->next != NULL)
57049+ match->next->prev = match->prev;
57050+ }
57051+ match->prev = NULL;
57052+ match->next = NULL;
57053+ match->inode = newinode;
57054+ match->device = newdevice;
57055+ match->mode &= ~GR_DELETED;
57056+
57057+ insert_acl_obj_label(match, subj);
57058+ }
57059+
57060+ return;
57061+}
57062+
57063+static void
57064+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
57065+ const ino_t newinode, const dev_t newdevice,
57066+ struct acl_role_label *role)
57067+{
57068+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
57069+ struct acl_subject_label *match;
57070+
57071+ match = role->subj_hash[index];
57072+
57073+ while (match && (match->inode != oldinode ||
57074+ match->device != olddevice ||
57075+ !(match->mode & GR_DELETED)))
57076+ match = match->next;
57077+
57078+ if (match && (match->inode == oldinode)
57079+ && (match->device == olddevice)
57080+ && (match->mode & GR_DELETED)) {
57081+ if (match->prev == NULL) {
57082+ role->subj_hash[index] = match->next;
57083+ if (match->next != NULL)
57084+ match->next->prev = NULL;
57085+ } else {
57086+ match->prev->next = match->next;
57087+ if (match->next != NULL)
57088+ match->next->prev = match->prev;
57089+ }
57090+ match->prev = NULL;
57091+ match->next = NULL;
57092+ match->inode = newinode;
57093+ match->device = newdevice;
57094+ match->mode &= ~GR_DELETED;
57095+
57096+ insert_acl_subj_label(match, role);
57097+ }
57098+
57099+ return;
57100+}
57101+
57102+static void
57103+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
57104+ const ino_t newinode, const dev_t newdevice)
57105+{
57106+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
57107+ struct inodev_entry *match;
57108+
57109+ match = inodev_set.i_hash[index];
57110+
57111+ while (match && (match->nentry->inode != oldinode ||
57112+ match->nentry->device != olddevice || !match->nentry->deleted))
57113+ match = match->next;
57114+
57115+ if (match && (match->nentry->inode == oldinode)
57116+ && (match->nentry->device == olddevice) &&
57117+ match->nentry->deleted) {
57118+ if (match->prev == NULL) {
57119+ inodev_set.i_hash[index] = match->next;
57120+ if (match->next != NULL)
57121+ match->next->prev = NULL;
57122+ } else {
57123+ match->prev->next = match->next;
57124+ if (match->next != NULL)
57125+ match->next->prev = match->prev;
57126+ }
57127+ match->prev = NULL;
57128+ match->next = NULL;
57129+ match->nentry->inode = newinode;
57130+ match->nentry->device = newdevice;
57131+ match->nentry->deleted = 0;
57132+
57133+ insert_inodev_entry(match);
57134+ }
57135+
57136+ return;
57137+}
57138+
57139+static void
57140+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
57141+{
57142+ struct acl_subject_label *subj;
57143+ struct acl_role_label *role;
57144+ unsigned int x;
57145+
57146+ FOR_EACH_ROLE_START(role)
57147+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
57148+
57149+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
57150+ if ((subj->inode == ino) && (subj->device == dev)) {
57151+ subj->inode = ino;
57152+ subj->device = dev;
57153+ }
57154+ /* nested subjects aren't in the role's subj_hash table */
57155+ update_acl_obj_label(matchn->inode, matchn->device,
57156+ ino, dev, subj);
57157+ FOR_EACH_NESTED_SUBJECT_END(subj)
57158+ FOR_EACH_SUBJECT_START(role, subj, x)
57159+ update_acl_obj_label(matchn->inode, matchn->device,
57160+ ino, dev, subj);
57161+ FOR_EACH_SUBJECT_END(subj,x)
57162+ FOR_EACH_ROLE_END(role)
57163+
57164+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
57165+
57166+ return;
57167+}
57168+
57169+static void
57170+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
57171+ const struct vfsmount *mnt)
57172+{
57173+ ino_t ino = dentry->d_inode->i_ino;
57174+ dev_t dev = __get_dev(dentry);
57175+
57176+ __do_handle_create(matchn, ino, dev);
57177+
57178+ return;
57179+}
57180+
57181+void
57182+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57183+{
57184+ struct name_entry *matchn;
57185+
57186+ if (unlikely(!(gr_status & GR_READY)))
57187+ return;
57188+
57189+ preempt_disable();
57190+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
57191+
57192+ if (unlikely((unsigned long)matchn)) {
57193+ write_lock(&gr_inode_lock);
57194+ do_handle_create(matchn, dentry, mnt);
57195+ write_unlock(&gr_inode_lock);
57196+ }
57197+ preempt_enable();
57198+
57199+ return;
57200+}
57201+
57202+void
57203+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57204+{
57205+ struct name_entry *matchn;
57206+
57207+ if (unlikely(!(gr_status & GR_READY)))
57208+ return;
57209+
57210+ preempt_disable();
57211+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
57212+
57213+ if (unlikely((unsigned long)matchn)) {
57214+ write_lock(&gr_inode_lock);
57215+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
57216+ write_unlock(&gr_inode_lock);
57217+ }
57218+ preempt_enable();
57219+
57220+ return;
57221+}
57222+
57223+void
57224+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57225+ struct dentry *old_dentry,
57226+ struct dentry *new_dentry,
57227+ struct vfsmount *mnt, const __u8 replace)
57228+{
57229+ struct name_entry *matchn;
57230+ struct inodev_entry *inodev;
57231+ struct inode *inode = new_dentry->d_inode;
57232+ ino_t old_ino = old_dentry->d_inode->i_ino;
57233+ dev_t old_dev = __get_dev(old_dentry);
57234+
57235+ /* vfs_rename swaps the name and parent link for old_dentry and
57236+ new_dentry
57237+ at this point, old_dentry has the new name, parent link, and inode
57238+ for the renamed file
57239+ if a file is being replaced by a rename, new_dentry has the inode
57240+ and name for the replaced file
57241+ */
57242+
57243+ if (unlikely(!(gr_status & GR_READY)))
57244+ return;
57245+
57246+ preempt_disable();
57247+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
57248+
57249+ /* we wouldn't have to check d_inode if it weren't for
57250+ NFS silly-renaming
57251+ */
57252+
57253+ write_lock(&gr_inode_lock);
57254+ if (unlikely(replace && inode)) {
57255+ ino_t new_ino = inode->i_ino;
57256+ dev_t new_dev = __get_dev(new_dentry);
57257+
57258+ inodev = lookup_inodev_entry(new_ino, new_dev);
57259+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
57260+ do_handle_delete(inodev, new_ino, new_dev);
57261+ }
57262+
57263+ inodev = lookup_inodev_entry(old_ino, old_dev);
57264+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
57265+ do_handle_delete(inodev, old_ino, old_dev);
57266+
57267+ if (unlikely((unsigned long)matchn))
57268+ do_handle_create(matchn, old_dentry, mnt);
57269+
57270+ write_unlock(&gr_inode_lock);
57271+ preempt_enable();
57272+
57273+ return;
57274+}
57275+
57276+static int
57277+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
57278+ unsigned char **sum)
57279+{
57280+ struct acl_role_label *r;
57281+ struct role_allowed_ip *ipp;
57282+ struct role_transition *trans;
57283+ unsigned int i;
57284+ int found = 0;
57285+ u32 curr_ip = current->signal->curr_ip;
57286+
57287+ current->signal->saved_ip = curr_ip;
57288+
57289+ /* check transition table */
57290+
57291+ for (trans = current->role->transitions; trans; trans = trans->next) {
57292+ if (!strcmp(rolename, trans->rolename)) {
57293+ found = 1;
57294+ break;
57295+ }
57296+ }
57297+
57298+ if (!found)
57299+ return 0;
57300+
57301+ /* handle special roles that do not require authentication
57302+ and check ip */
57303+
57304+ FOR_EACH_ROLE_START(r)
57305+ if (!strcmp(rolename, r->rolename) &&
57306+ (r->roletype & GR_ROLE_SPECIAL)) {
57307+ found = 0;
57308+ if (r->allowed_ips != NULL) {
57309+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
57310+ if ((ntohl(curr_ip) & ipp->netmask) ==
57311+ (ntohl(ipp->addr) & ipp->netmask))
57312+ found = 1;
57313+ }
57314+ } else
57315+ found = 2;
57316+ if (!found)
57317+ return 0;
57318+
57319+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
57320+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
57321+ *salt = NULL;
57322+ *sum = NULL;
57323+ return 1;
57324+ }
57325+ }
57326+ FOR_EACH_ROLE_END(r)
57327+
57328+ for (i = 0; i < num_sprole_pws; i++) {
57329+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
57330+ *salt = acl_special_roles[i]->salt;
57331+ *sum = acl_special_roles[i]->sum;
57332+ return 1;
57333+ }
57334+ }
57335+
57336+ return 0;
57337+}
57338+
57339+static void
57340+assign_special_role(char *rolename)
57341+{
57342+ struct acl_object_label *obj;
57343+ struct acl_role_label *r;
57344+ struct acl_role_label *assigned = NULL;
57345+ struct task_struct *tsk;
57346+ struct file *filp;
57347+
57348+ FOR_EACH_ROLE_START(r)
57349+ if (!strcmp(rolename, r->rolename) &&
57350+ (r->roletype & GR_ROLE_SPECIAL)) {
57351+ assigned = r;
57352+ break;
57353+ }
57354+ FOR_EACH_ROLE_END(r)
57355+
57356+ if (!assigned)
57357+ return;
57358+
57359+ read_lock(&tasklist_lock);
57360+ read_lock(&grsec_exec_file_lock);
57361+
57362+ tsk = current->real_parent;
57363+ if (tsk == NULL)
57364+ goto out_unlock;
57365+
57366+ filp = tsk->exec_file;
57367+ if (filp == NULL)
57368+ goto out_unlock;
57369+
57370+ tsk->is_writable = 0;
57371+
57372+ tsk->acl_sp_role = 1;
57373+ tsk->acl_role_id = ++acl_sp_role_value;
57374+ tsk->role = assigned;
57375+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
57376+
57377+ /* ignore additional mmap checks for processes that are writable
57378+ by the default ACL */
57379+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
57380+ if (unlikely(obj->mode & GR_WRITE))
57381+ tsk->is_writable = 1;
57382+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
57383+ if (unlikely(obj->mode & GR_WRITE))
57384+ tsk->is_writable = 1;
57385+
57386+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57387+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
57388+#endif
57389+
57390+out_unlock:
57391+ read_unlock(&grsec_exec_file_lock);
57392+ read_unlock(&tasklist_lock);
57393+ return;
57394+}
57395+
57396+int gr_check_secure_terminal(struct task_struct *task)
57397+{
57398+ struct task_struct *p, *p2, *p3;
57399+ struct files_struct *files;
57400+ struct fdtable *fdt;
57401+ struct file *our_file = NULL, *file;
57402+ int i;
57403+
57404+ if (task->signal->tty == NULL)
57405+ return 1;
57406+
57407+ files = get_files_struct(task);
57408+ if (files != NULL) {
57409+ rcu_read_lock();
57410+ fdt = files_fdtable(files);
57411+ for (i=0; i < fdt->max_fds; i++) {
57412+ file = fcheck_files(files, i);
57413+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
57414+ get_file(file);
57415+ our_file = file;
57416+ }
57417+ }
57418+ rcu_read_unlock();
57419+ put_files_struct(files);
57420+ }
57421+
57422+ if (our_file == NULL)
57423+ return 1;
57424+
57425+ read_lock(&tasklist_lock);
57426+ do_each_thread(p2, p) {
57427+ files = get_files_struct(p);
57428+ if (files == NULL ||
57429+ (p->signal && p->signal->tty == task->signal->tty)) {
57430+ if (files != NULL)
57431+ put_files_struct(files);
57432+ continue;
57433+ }
57434+ rcu_read_lock();
57435+ fdt = files_fdtable(files);
57436+ for (i=0; i < fdt->max_fds; i++) {
57437+ file = fcheck_files(files, i);
57438+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
57439+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
57440+ p3 = task;
57441+ while (p3->pid > 0) {
57442+ if (p3 == p)
57443+ break;
57444+ p3 = p3->real_parent;
57445+ }
57446+ if (p3 == p)
57447+ break;
57448+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
57449+ gr_handle_alertkill(p);
57450+ rcu_read_unlock();
57451+ put_files_struct(files);
57452+ read_unlock(&tasklist_lock);
57453+ fput(our_file);
57454+ return 0;
57455+ }
57456+ }
57457+ rcu_read_unlock();
57458+ put_files_struct(files);
57459+ } while_each_thread(p2, p);
57460+ read_unlock(&tasklist_lock);
57461+
57462+ fput(our_file);
57463+ return 1;
57464+}
57465+
57466+static int gr_rbac_disable(void *unused)
57467+{
57468+ pax_open_kernel();
57469+ gr_status &= ~GR_READY;
57470+ pax_close_kernel();
57471+
57472+ return 0;
57473+}
57474+
57475+ssize_t
57476+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
57477+{
57478+ struct gr_arg_wrapper uwrap;
57479+ unsigned char *sprole_salt = NULL;
57480+ unsigned char *sprole_sum = NULL;
57481+ int error = sizeof (struct gr_arg_wrapper);
57482+ int error2 = 0;
57483+
57484+ mutex_lock(&gr_dev_mutex);
57485+
57486+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
57487+ error = -EPERM;
57488+ goto out;
57489+ }
57490+
57491+ if (count != sizeof (struct gr_arg_wrapper)) {
57492+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
57493+ error = -EINVAL;
57494+ goto out;
57495+ }
57496+
57497+
57498+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
57499+ gr_auth_expires = 0;
57500+ gr_auth_attempts = 0;
57501+ }
57502+
57503+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
57504+ error = -EFAULT;
57505+ goto out;
57506+ }
57507+
57508+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
57509+ error = -EINVAL;
57510+ goto out;
57511+ }
57512+
57513+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
57514+ error = -EFAULT;
57515+ goto out;
57516+ }
57517+
57518+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
57519+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
57520+ time_after(gr_auth_expires, get_seconds())) {
57521+ error = -EBUSY;
57522+ goto out;
57523+ }
57524+
57525+ /* if non-root trying to do anything other than use a special role,
57526+ do not attempt authentication, do not count towards authentication
57527+ locking
57528+ */
57529+
57530+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
57531+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
57532+ !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
57533+ error = -EPERM;
57534+ goto out;
57535+ }
57536+
57537+ /* ensure pw and special role name are null terminated */
57538+
57539+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
57540+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
57541+
57542+ /* Okay.
57543+ * We have our enough of the argument structure..(we have yet
57544+ * to copy_from_user the tables themselves) . Copy the tables
57545+ * only if we need them, i.e. for loading operations. */
57546+
57547+ switch (gr_usermode->mode) {
57548+ case GR_STATUS:
57549+ if (gr_status & GR_READY) {
57550+ error = 1;
57551+ if (!gr_check_secure_terminal(current))
57552+ error = 3;
57553+ } else
57554+ error = 2;
57555+ goto out;
57556+ case GR_SHUTDOWN:
57557+ if ((gr_status & GR_READY)
57558+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
57559+ stop_machine(gr_rbac_disable, NULL, NULL);
57560+ free_variables();
57561+ memset(gr_usermode, 0, sizeof (struct gr_arg));
57562+ memset(gr_system_salt, 0, GR_SALT_LEN);
57563+ memset(gr_system_sum, 0, GR_SHA_LEN);
57564+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
57565+ } else if (gr_status & GR_READY) {
57566+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
57567+ error = -EPERM;
57568+ } else {
57569+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
57570+ error = -EAGAIN;
57571+ }
57572+ break;
57573+ case GR_ENABLE:
57574+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
57575+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
57576+ else {
57577+ if (gr_status & GR_READY)
57578+ error = -EAGAIN;
57579+ else
57580+ error = error2;
57581+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
57582+ }
57583+ break;
57584+ case GR_RELOAD:
57585+ if (!(gr_status & GR_READY)) {
57586+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
57587+ error = -EAGAIN;
57588+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
57589+ stop_machine(gr_rbac_disable, NULL, NULL);
57590+ free_variables();
57591+ error2 = gracl_init(gr_usermode);
57592+ if (!error2)
57593+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
57594+ else {
57595+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
57596+ error = error2;
57597+ }
57598+ } else {
57599+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
57600+ error = -EPERM;
57601+ }
57602+ break;
57603+ case GR_SEGVMOD:
57604+ if (unlikely(!(gr_status & GR_READY))) {
57605+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
57606+ error = -EAGAIN;
57607+ break;
57608+ }
57609+
57610+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
57611+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
57612+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
57613+ struct acl_subject_label *segvacl;
57614+ segvacl =
57615+ lookup_acl_subj_label(gr_usermode->segv_inode,
57616+ gr_usermode->segv_device,
57617+ current->role);
57618+ if (segvacl) {
57619+ segvacl->crashes = 0;
57620+ segvacl->expires = 0;
57621+ }
57622+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
57623+ gr_remove_uid(gr_usermode->segv_uid);
57624+ }
57625+ } else {
57626+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
57627+ error = -EPERM;
57628+ }
57629+ break;
57630+ case GR_SPROLE:
57631+ case GR_SPROLEPAM:
57632+ if (unlikely(!(gr_status & GR_READY))) {
57633+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
57634+ error = -EAGAIN;
57635+ break;
57636+ }
57637+
57638+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
57639+ current->role->expires = 0;
57640+ current->role->auth_attempts = 0;
57641+ }
57642+
57643+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
57644+ time_after(current->role->expires, get_seconds())) {
57645+ error = -EBUSY;
57646+ goto out;
57647+ }
57648+
57649+ if (lookup_special_role_auth
57650+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
57651+ && ((!sprole_salt && !sprole_sum)
57652+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
57653+ char *p = "";
57654+ assign_special_role(gr_usermode->sp_role);
57655+ read_lock(&tasklist_lock);
57656+ if (current->real_parent)
57657+ p = current->real_parent->role->rolename;
57658+ read_unlock(&tasklist_lock);
57659+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
57660+ p, acl_sp_role_value);
57661+ } else {
57662+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
57663+ error = -EPERM;
57664+ if(!(current->role->auth_attempts++))
57665+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
57666+
57667+ goto out;
57668+ }
57669+ break;
57670+ case GR_UNSPROLE:
57671+ if (unlikely(!(gr_status & GR_READY))) {
57672+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
57673+ error = -EAGAIN;
57674+ break;
57675+ }
57676+
57677+ if (current->role->roletype & GR_ROLE_SPECIAL) {
57678+ char *p = "";
57679+ int i = 0;
57680+
57681+ read_lock(&tasklist_lock);
57682+ if (current->real_parent) {
57683+ p = current->real_parent->role->rolename;
57684+ i = current->real_parent->acl_role_id;
57685+ }
57686+ read_unlock(&tasklist_lock);
57687+
57688+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
57689+ gr_set_acls(1);
57690+ } else {
57691+ error = -EPERM;
57692+ goto out;
57693+ }
57694+ break;
57695+ default:
57696+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
57697+ error = -EINVAL;
57698+ break;
57699+ }
57700+
57701+ if (error != -EPERM)
57702+ goto out;
57703+
57704+ if(!(gr_auth_attempts++))
57705+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
57706+
57707+ out:
57708+ mutex_unlock(&gr_dev_mutex);
57709+ return error;
57710+}
57711+
57712+/* must be called with
57713+ rcu_read_lock();
57714+ read_lock(&tasklist_lock);
57715+ read_lock(&grsec_exec_file_lock);
57716+*/
57717+int gr_apply_subject_to_task(struct task_struct *task)
57718+{
57719+ struct acl_object_label *obj;
57720+ char *tmpname;
57721+ struct acl_subject_label *tmpsubj;
57722+ struct file *filp;
57723+ struct name_entry *nmatch;
57724+
57725+ filp = task->exec_file;
57726+ if (filp == NULL)
57727+ return 0;
57728+
57729+ /* the following is to apply the correct subject
57730+ on binaries running when the RBAC system
57731+ is enabled, when the binaries have been
57732+ replaced or deleted since their execution
57733+ -----
57734+ when the RBAC system starts, the inode/dev
57735+ from exec_file will be one the RBAC system
57736+ is unaware of. It only knows the inode/dev
57737+ of the present file on disk, or the absence
57738+ of it.
57739+ */
57740+ preempt_disable();
57741+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
57742+
57743+ nmatch = lookup_name_entry(tmpname);
57744+ preempt_enable();
57745+ tmpsubj = NULL;
57746+ if (nmatch) {
57747+ if (nmatch->deleted)
57748+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
57749+ else
57750+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
57751+ if (tmpsubj != NULL)
57752+ task->acl = tmpsubj;
57753+ }
57754+ if (tmpsubj == NULL)
57755+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
57756+ task->role);
57757+ if (task->acl) {
57758+ task->is_writable = 0;
57759+ /* ignore additional mmap checks for processes that are writable
57760+ by the default ACL */
57761+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
57762+ if (unlikely(obj->mode & GR_WRITE))
57763+ task->is_writable = 1;
57764+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
57765+ if (unlikely(obj->mode & GR_WRITE))
57766+ task->is_writable = 1;
57767+
57768+ gr_set_proc_res(task);
57769+
57770+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57771+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
57772+#endif
57773+ } else {
57774+ return 1;
57775+ }
57776+
57777+ return 0;
57778+}
57779+
57780+int
57781+gr_set_acls(const int type)
57782+{
57783+ struct task_struct *task, *task2;
57784+ struct acl_role_label *role = current->role;
57785+ __u16 acl_role_id = current->acl_role_id;
57786+ const struct cred *cred;
57787+ int ret;
57788+
57789+ rcu_read_lock();
57790+ read_lock(&tasklist_lock);
57791+ read_lock(&grsec_exec_file_lock);
57792+ do_each_thread(task2, task) {
57793+ /* check to see if we're called from the exit handler,
57794+ if so, only replace ACLs that have inherited the admin
57795+ ACL */
57796+
57797+ if (type && (task->role != role ||
57798+ task->acl_role_id != acl_role_id))
57799+ continue;
57800+
57801+ task->acl_role_id = 0;
57802+ task->acl_sp_role = 0;
57803+
57804+ if (task->exec_file) {
57805+ cred = __task_cred(task);
57806+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
57807+ ret = gr_apply_subject_to_task(task);
57808+ if (ret) {
57809+ read_unlock(&grsec_exec_file_lock);
57810+ read_unlock(&tasklist_lock);
57811+ rcu_read_unlock();
57812+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
57813+ return ret;
57814+ }
57815+ } else {
57816+ // it's a kernel process
57817+ task->role = kernel_role;
57818+ task->acl = kernel_role->root_label;
57819+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
57820+ task->acl->mode &= ~GR_PROCFIND;
57821+#endif
57822+ }
57823+ } while_each_thread(task2, task);
57824+ read_unlock(&grsec_exec_file_lock);
57825+ read_unlock(&tasklist_lock);
57826+ rcu_read_unlock();
57827+
57828+ return 0;
57829+}
57830+
57831+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
57832+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
57833+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
57834+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
57835+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
57836+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
57837+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
57838+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
57839+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
57840+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
57841+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
57842+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
57843+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
57844+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
57845+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
57846+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
57847+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
57848+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
57849+};
57850+
57851+void
57852+gr_learn_resource(const struct task_struct *task,
57853+ const int res, const unsigned long wanted, const int gt)
57854+{
57855+ struct acl_subject_label *acl;
57856+ const struct cred *cred;
57857+
57858+ if (unlikely((gr_status & GR_READY) &&
57859+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
57860+ goto skip_reslog;
57861+
57862+ gr_log_resource(task, res, wanted, gt);
57863+skip_reslog:
57864+
57865+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
57866+ return;
57867+
57868+ acl = task->acl;
57869+
57870+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
57871+ !(acl->resmask & (1 << (unsigned short) res))))
57872+ return;
57873+
57874+ if (wanted >= acl->res[res].rlim_cur) {
57875+ unsigned long res_add;
57876+
57877+ res_add = wanted + res_learn_bumps[res];
57878+
57879+ acl->res[res].rlim_cur = res_add;
57880+
57881+ if (wanted > acl->res[res].rlim_max)
57882+ acl->res[res].rlim_max = res_add;
57883+
57884+ /* only log the subject filename, since resource logging is supported for
57885+ single-subject learning only */
57886+ rcu_read_lock();
57887+ cred = __task_cred(task);
57888+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
57889+ task->role->roletype, cred->uid, cred->gid, acl->filename,
57890+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
57891+ "", (unsigned long) res, &task->signal->saved_ip);
57892+ rcu_read_unlock();
57893+ }
57894+
57895+ return;
57896+}
57897+EXPORT_SYMBOL(gr_learn_resource);
57898+#endif
57899+
57900+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
57901+void
57902+pax_set_initial_flags(struct linux_binprm *bprm)
57903+{
57904+ struct task_struct *task = current;
57905+ struct acl_subject_label *proc;
57906+ unsigned long flags;
57907+
57908+ if (unlikely(!(gr_status & GR_READY)))
57909+ return;
57910+
57911+ flags = pax_get_flags(task);
57912+
57913+ proc = task->acl;
57914+
57915+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
57916+ flags &= ~MF_PAX_PAGEEXEC;
57917+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
57918+ flags &= ~MF_PAX_SEGMEXEC;
57919+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
57920+ flags &= ~MF_PAX_RANDMMAP;
57921+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
57922+ flags &= ~MF_PAX_EMUTRAMP;
57923+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
57924+ flags &= ~MF_PAX_MPROTECT;
57925+
57926+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
57927+ flags |= MF_PAX_PAGEEXEC;
57928+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
57929+ flags |= MF_PAX_SEGMEXEC;
57930+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
57931+ flags |= MF_PAX_RANDMMAP;
57932+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
57933+ flags |= MF_PAX_EMUTRAMP;
57934+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
57935+ flags |= MF_PAX_MPROTECT;
57936+
57937+ pax_set_flags(task, flags);
57938+
57939+ return;
57940+}
57941+#endif
57942+
57943+int
57944+gr_handle_proc_ptrace(struct task_struct *task)
57945+{
57946+ struct file *filp;
57947+ struct task_struct *tmp = task;
57948+ struct task_struct *curtemp = current;
57949+ __u32 retmode;
57950+
57951+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
57952+ if (unlikely(!(gr_status & GR_READY)))
57953+ return 0;
57954+#endif
57955+
57956+ read_lock(&tasklist_lock);
57957+ read_lock(&grsec_exec_file_lock);
57958+ filp = task->exec_file;
57959+
57960+ while (tmp->pid > 0) {
57961+ if (tmp == curtemp)
57962+ break;
57963+ tmp = tmp->real_parent;
57964+ }
57965+
57966+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
57967+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
57968+ read_unlock(&grsec_exec_file_lock);
57969+ read_unlock(&tasklist_lock);
57970+ return 1;
57971+ }
57972+
57973+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57974+ if (!(gr_status & GR_READY)) {
57975+ read_unlock(&grsec_exec_file_lock);
57976+ read_unlock(&tasklist_lock);
57977+ return 0;
57978+ }
57979+#endif
57980+
57981+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
57982+ read_unlock(&grsec_exec_file_lock);
57983+ read_unlock(&tasklist_lock);
57984+
57985+ if (retmode & GR_NOPTRACE)
57986+ return 1;
57987+
57988+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
57989+ && (current->acl != task->acl || (current->acl != current->role->root_label
57990+ && current->pid != task->pid)))
57991+ return 1;
57992+
57993+ return 0;
57994+}
57995+
57996+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
57997+{
57998+ if (unlikely(!(gr_status & GR_READY)))
57999+ return;
58000+
58001+ if (!(current->role->roletype & GR_ROLE_GOD))
58002+ return;
58003+
58004+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
58005+ p->role->rolename, gr_task_roletype_to_char(p),
58006+ p->acl->filename);
58007+}
58008+
58009+int
58010+gr_handle_ptrace(struct task_struct *task, const long request)
58011+{
58012+ struct task_struct *tmp = task;
58013+ struct task_struct *curtemp = current;
58014+ __u32 retmode;
58015+
58016+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
58017+ if (unlikely(!(gr_status & GR_READY)))
58018+ return 0;
58019+#endif
58020+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
58021+ read_lock(&tasklist_lock);
58022+ while (tmp->pid > 0) {
58023+ if (tmp == curtemp)
58024+ break;
58025+ tmp = tmp->real_parent;
58026+ }
58027+
58028+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
58029+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
58030+ read_unlock(&tasklist_lock);
58031+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
58032+ return 1;
58033+ }
58034+ read_unlock(&tasklist_lock);
58035+ }
58036+
58037+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58038+ if (!(gr_status & GR_READY))
58039+ return 0;
58040+#endif
58041+
58042+ read_lock(&grsec_exec_file_lock);
58043+ if (unlikely(!task->exec_file)) {
58044+ read_unlock(&grsec_exec_file_lock);
58045+ return 0;
58046+ }
58047+
58048+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
58049+ read_unlock(&grsec_exec_file_lock);
58050+
58051+ if (retmode & GR_NOPTRACE) {
58052+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
58053+ return 1;
58054+ }
58055+
58056+ if (retmode & GR_PTRACERD) {
58057+ switch (request) {
58058+ case PTRACE_SEIZE:
58059+ case PTRACE_POKETEXT:
58060+ case PTRACE_POKEDATA:
58061+ case PTRACE_POKEUSR:
58062+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
58063+ case PTRACE_SETREGS:
58064+ case PTRACE_SETFPREGS:
58065+#endif
58066+#ifdef CONFIG_X86
58067+ case PTRACE_SETFPXREGS:
58068+#endif
58069+#ifdef CONFIG_ALTIVEC
58070+ case PTRACE_SETVRREGS:
58071+#endif
58072+ return 1;
58073+ default:
58074+ return 0;
58075+ }
58076+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
58077+ !(current->role->roletype & GR_ROLE_GOD) &&
58078+ (current->acl != task->acl)) {
58079+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
58080+ return 1;
58081+ }
58082+
58083+ return 0;
58084+}
58085+
58086+static int is_writable_mmap(const struct file *filp)
58087+{
58088+ struct task_struct *task = current;
58089+ struct acl_object_label *obj, *obj2;
58090+
58091+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
58092+ !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))) {
58093+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
58094+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
58095+ task->role->root_label);
58096+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
58097+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
58098+ return 1;
58099+ }
58100+ }
58101+ return 0;
58102+}
58103+
58104+int
58105+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
58106+{
58107+ __u32 mode;
58108+
58109+ if (unlikely(!file || !(prot & PROT_EXEC)))
58110+ return 1;
58111+
58112+ if (is_writable_mmap(file))
58113+ return 0;
58114+
58115+ mode =
58116+ gr_search_file(file->f_path.dentry,
58117+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
58118+ file->f_path.mnt);
58119+
58120+ if (!gr_tpe_allow(file))
58121+ return 0;
58122+
58123+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
58124+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
58125+ return 0;
58126+ } else if (unlikely(!(mode & GR_EXEC))) {
58127+ return 0;
58128+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
58129+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
58130+ return 1;
58131+ }
58132+
58133+ return 1;
58134+}
58135+
58136+int
58137+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
58138+{
58139+ __u32 mode;
58140+
58141+ if (unlikely(!file || !(prot & PROT_EXEC)))
58142+ return 1;
58143+
58144+ if (is_writable_mmap(file))
58145+ return 0;
58146+
58147+ mode =
58148+ gr_search_file(file->f_path.dentry,
58149+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
58150+ file->f_path.mnt);
58151+
58152+ if (!gr_tpe_allow(file))
58153+ return 0;
58154+
58155+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
58156+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
58157+ return 0;
58158+ } else if (unlikely(!(mode & GR_EXEC))) {
58159+ return 0;
58160+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
58161+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
58162+ return 1;
58163+ }
58164+
58165+ return 1;
58166+}
58167+
58168+void
58169+gr_acl_handle_psacct(struct task_struct *task, const long code)
58170+{
58171+ unsigned long runtime;
58172+ unsigned long cputime;
58173+ unsigned int wday, cday;
58174+ __u8 whr, chr;
58175+ __u8 wmin, cmin;
58176+ __u8 wsec, csec;
58177+ struct timespec timeval;
58178+
58179+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
58180+ !(task->acl->mode & GR_PROCACCT)))
58181+ return;
58182+
58183+ do_posix_clock_monotonic_gettime(&timeval);
58184+ runtime = timeval.tv_sec - task->start_time.tv_sec;
58185+ wday = runtime / (3600 * 24);
58186+ runtime -= wday * (3600 * 24);
58187+ whr = runtime / 3600;
58188+ runtime -= whr * 3600;
58189+ wmin = runtime / 60;
58190+ runtime -= wmin * 60;
58191+ wsec = runtime;
58192+
58193+ cputime = (task->utime + task->stime) / HZ;
58194+ cday = cputime / (3600 * 24);
58195+ cputime -= cday * (3600 * 24);
58196+ chr = cputime / 3600;
58197+ cputime -= chr * 3600;
58198+ cmin = cputime / 60;
58199+ cputime -= cmin * 60;
58200+ csec = cputime;
58201+
58202+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
58203+
58204+ return;
58205+}
58206+
58207+void gr_set_kernel_label(struct task_struct *task)
58208+{
58209+ if (gr_status & GR_READY) {
58210+ task->role = kernel_role;
58211+ task->acl = kernel_role->root_label;
58212+ }
58213+ return;
58214+}
58215+
58216+#ifdef CONFIG_TASKSTATS
58217+int gr_is_taskstats_denied(int pid)
58218+{
58219+ struct task_struct *task;
58220+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
58221+ const struct cred *cred;
58222+#endif
58223+ int ret = 0;
58224+
58225+ /* restrict taskstats viewing to un-chrooted root users
58226+ who have the 'view' subject flag if the RBAC system is enabled
58227+ */
58228+
58229+ rcu_read_lock();
58230+ read_lock(&tasklist_lock);
58231+ task = find_task_by_vpid(pid);
58232+ if (task) {
58233+#ifdef CONFIG_GRKERNSEC_CHROOT
58234+ if (proc_is_chrooted(task))
58235+ ret = -EACCES;
58236+#endif
58237+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
58238+ cred = __task_cred(task);
58239+#ifdef CONFIG_GRKERNSEC_PROC_USER
58240+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
58241+ ret = -EACCES;
58242+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
58243+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
58244+ ret = -EACCES;
58245+#endif
58246+#endif
58247+ if (gr_status & GR_READY) {
58248+ if (!(task->acl->mode & GR_VIEW))
58249+ ret = -EACCES;
58250+ }
58251+ } else
58252+ ret = -ENOENT;
58253+
58254+ read_unlock(&tasklist_lock);
58255+ rcu_read_unlock();
58256+
58257+ return ret;
58258+}
58259+#endif
58260+
58261+/* AUXV entries are filled via a descendant of search_binary_handler
58262+ after we've already applied the subject for the target
58263+*/
58264+int gr_acl_enable_at_secure(void)
58265+{
58266+ if (unlikely(!(gr_status & GR_READY)))
58267+ return 0;
58268+
58269+ if (current->acl->mode & GR_ATSECURE)
58270+ return 1;
58271+
58272+ return 0;
58273+}
58274+
58275+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
58276+{
58277+ struct task_struct *task = current;
58278+ struct dentry *dentry = file->f_path.dentry;
58279+ struct vfsmount *mnt = file->f_path.mnt;
58280+ struct acl_object_label *obj, *tmp;
58281+ struct acl_subject_label *subj;
58282+ unsigned int bufsize;
58283+ int is_not_root;
58284+ char *path;
58285+ dev_t dev = __get_dev(dentry);
58286+
58287+ if (unlikely(!(gr_status & GR_READY)))
58288+ return 1;
58289+
58290+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
58291+ return 1;
58292+
58293+ /* ignore Eric Biederman */
58294+ if (IS_PRIVATE(dentry->d_inode))
58295+ return 1;
58296+
58297+ subj = task->acl;
58298+ read_lock(&gr_inode_lock);
58299+ do {
58300+ obj = lookup_acl_obj_label(ino, dev, subj);
58301+ if (obj != NULL) {
58302+ read_unlock(&gr_inode_lock);
58303+ return (obj->mode & GR_FIND) ? 1 : 0;
58304+ }
58305+ } while ((subj = subj->parent_subject));
58306+ read_unlock(&gr_inode_lock);
58307+
58308+ /* this is purely an optimization since we're looking for an object
58309+ for the directory we're doing a readdir on
58310+ if it's possible for any globbed object to match the entry we're
58311+ filling into the directory, then the object we find here will be
58312+ an anchor point with attached globbed objects
58313+ */
58314+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
58315+ if (obj->globbed == NULL)
58316+ return (obj->mode & GR_FIND) ? 1 : 0;
58317+
58318+ is_not_root = ((obj->filename[0] == '/') &&
58319+ (obj->filename[1] == '\0')) ? 0 : 1;
58320+ bufsize = PAGE_SIZE - namelen - is_not_root;
58321+
58322+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
58323+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
58324+ return 1;
58325+
58326+ preempt_disable();
58327+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
58328+ bufsize);
58329+
58330+ bufsize = strlen(path);
58331+
58332+ /* if base is "/", don't append an additional slash */
58333+ if (is_not_root)
58334+ *(path + bufsize) = '/';
58335+ memcpy(path + bufsize + is_not_root, name, namelen);
58336+ *(path + bufsize + namelen + is_not_root) = '\0';
58337+
58338+ tmp = obj->globbed;
58339+ while (tmp) {
58340+ if (!glob_match(tmp->filename, path)) {
58341+ preempt_enable();
58342+ return (tmp->mode & GR_FIND) ? 1 : 0;
58343+ }
58344+ tmp = tmp->next;
58345+ }
58346+ preempt_enable();
58347+ return (obj->mode & GR_FIND) ? 1 : 0;
58348+}
58349+
58350+void gr_put_exec_file(struct task_struct *task)
58351+{
58352+ struct file *filp;
58353+
58354+ write_lock(&grsec_exec_file_lock);
58355+ filp = task->exec_file;
58356+ task->exec_file = NULL;
58357+ write_unlock(&grsec_exec_file_lock);
58358+
58359+ if (filp)
58360+ fput(filp);
58361+
58362+ return;
58363+}
58364+
58365+
58366+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
58367+EXPORT_SYMBOL(gr_acl_is_enabled);
58368+#endif
58369+EXPORT_SYMBOL(gr_set_kernel_label);
58370+#ifdef CONFIG_SECURITY
58371+EXPORT_SYMBOL(gr_check_user_change);
58372+EXPORT_SYMBOL(gr_check_group_change);
58373+#endif
58374+
58375diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
58376new file mode 100644
58377index 0000000..34fefda
58378--- /dev/null
58379+++ b/grsecurity/gracl_alloc.c
58380@@ -0,0 +1,105 @@
58381+#include <linux/kernel.h>
58382+#include <linux/mm.h>
58383+#include <linux/slab.h>
58384+#include <linux/vmalloc.h>
58385+#include <linux/gracl.h>
58386+#include <linux/grsecurity.h>
58387+
58388+static unsigned long alloc_stack_next = 1;
58389+static unsigned long alloc_stack_size = 1;
58390+static void **alloc_stack;
58391+
58392+static __inline__ int
58393+alloc_pop(void)
58394+{
58395+ if (alloc_stack_next == 1)
58396+ return 0;
58397+
58398+ kfree(alloc_stack[alloc_stack_next - 2]);
58399+
58400+ alloc_stack_next--;
58401+
58402+ return 1;
58403+}
58404+
58405+static __inline__ int
58406+alloc_push(void *buf)
58407+{
58408+ if (alloc_stack_next >= alloc_stack_size)
58409+ return 1;
58410+
58411+ alloc_stack[alloc_stack_next - 1] = buf;
58412+
58413+ alloc_stack_next++;
58414+
58415+ return 0;
58416+}
58417+
58418+void *
58419+acl_alloc(unsigned long len)
58420+{
58421+ void *ret = NULL;
58422+
58423+ if (!len || len > PAGE_SIZE)
58424+ goto out;
58425+
58426+ ret = kmalloc(len, GFP_KERNEL);
58427+
58428+ if (ret) {
58429+ if (alloc_push(ret)) {
58430+ kfree(ret);
58431+ ret = NULL;
58432+ }
58433+ }
58434+
58435+out:
58436+ return ret;
58437+}
58438+
58439+void *
58440+acl_alloc_num(unsigned long num, unsigned long len)
58441+{
58442+ if (!len || (num > (PAGE_SIZE / len)))
58443+ return NULL;
58444+
58445+ return acl_alloc(num * len);
58446+}
58447+
58448+void
58449+acl_free_all(void)
58450+{
58451+ if (gr_acl_is_enabled() || !alloc_stack)
58452+ return;
58453+
58454+ while (alloc_pop()) ;
58455+
58456+ if (alloc_stack) {
58457+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
58458+ kfree(alloc_stack);
58459+ else
58460+ vfree(alloc_stack);
58461+ }
58462+
58463+ alloc_stack = NULL;
58464+ alloc_stack_size = 1;
58465+ alloc_stack_next = 1;
58466+
58467+ return;
58468+}
58469+
58470+int
58471+acl_alloc_stack_init(unsigned long size)
58472+{
58473+ if ((size * sizeof (void *)) <= PAGE_SIZE)
58474+ alloc_stack =
58475+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
58476+ else
58477+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
58478+
58479+ alloc_stack_size = size;
58480+
58481+ if (!alloc_stack)
58482+ return 0;
58483+ else
58484+ return 1;
58485+}
58486diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
58487new file mode 100644
58488index 0000000..6d21049
58489--- /dev/null
58490+++ b/grsecurity/gracl_cap.c
58491@@ -0,0 +1,110 @@
58492+#include <linux/kernel.h>
58493+#include <linux/module.h>
58494+#include <linux/sched.h>
58495+#include <linux/gracl.h>
58496+#include <linux/grsecurity.h>
58497+#include <linux/grinternal.h>
58498+
58499+extern const char *captab_log[];
58500+extern int captab_log_entries;
58501+
58502+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58503+{
58504+ struct acl_subject_label *curracl;
58505+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
58506+ kernel_cap_t cap_audit = __cap_empty_set;
58507+
58508+ if (!gr_acl_is_enabled())
58509+ return 1;
58510+
58511+ curracl = task->acl;
58512+
58513+ cap_drop = curracl->cap_lower;
58514+ cap_mask = curracl->cap_mask;
58515+ cap_audit = curracl->cap_invert_audit;
58516+
58517+ while ((curracl = curracl->parent_subject)) {
58518+ /* if the cap isn't specified in the current computed mask but is specified in the
58519+ current level subject, and is lowered in the current level subject, then add
58520+ it to the set of dropped capabilities
58521+ otherwise, add the current level subject's mask to the current computed mask
58522+ */
58523+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
58524+ cap_raise(cap_mask, cap);
58525+ if (cap_raised(curracl->cap_lower, cap))
58526+ cap_raise(cap_drop, cap);
58527+ if (cap_raised(curracl->cap_invert_audit, cap))
58528+ cap_raise(cap_audit, cap);
58529+ }
58530+ }
58531+
58532+ if (!cap_raised(cap_drop, cap)) {
58533+ if (cap_raised(cap_audit, cap))
58534+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
58535+ return 1;
58536+ }
58537+
58538+ curracl = task->acl;
58539+
58540+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
58541+ && cap_raised(cred->cap_effective, cap)) {
58542+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
58543+ task->role->roletype, cred->uid,
58544+ cred->gid, task->exec_file ?
58545+ gr_to_filename(task->exec_file->f_path.dentry,
58546+ task->exec_file->f_path.mnt) : curracl->filename,
58547+ curracl->filename, 0UL,
58548+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
58549+ return 1;
58550+ }
58551+
58552+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
58553+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
58554+
58555+ return 0;
58556+}
58557+
58558+int
58559+gr_acl_is_capable(const int cap)
58560+{
58561+ return gr_task_acl_is_capable(current, current_cred(), cap);
58562+}
58563+
58564+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
58565+{
58566+ struct acl_subject_label *curracl;
58567+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
58568+
58569+ if (!gr_acl_is_enabled())
58570+ return 1;
58571+
58572+ curracl = task->acl;
58573+
58574+ cap_drop = curracl->cap_lower;
58575+ cap_mask = curracl->cap_mask;
58576+
58577+ while ((curracl = curracl->parent_subject)) {
58578+ /* if the cap isn't specified in the current computed mask but is specified in the
58579+ current level subject, and is lowered in the current level subject, then add
58580+ it to the set of dropped capabilities
58581+ otherwise, add the current level subject's mask to the current computed mask
58582+ */
58583+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
58584+ cap_raise(cap_mask, cap);
58585+ if (cap_raised(curracl->cap_lower, cap))
58586+ cap_raise(cap_drop, cap);
58587+ }
58588+ }
58589+
58590+ if (!cap_raised(cap_drop, cap))
58591+ return 1;
58592+
58593+ return 0;
58594+}
58595+
58596+int
58597+gr_acl_is_capable_nolog(const int cap)
58598+{
58599+ return gr_task_acl_is_capable_nolog(current, cap);
58600+}
58601+
58602diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
58603new file mode 100644
58604index 0000000..a340c17
58605--- /dev/null
58606+++ b/grsecurity/gracl_fs.c
58607@@ -0,0 +1,431 @@
58608+#include <linux/kernel.h>
58609+#include <linux/sched.h>
58610+#include <linux/types.h>
58611+#include <linux/fs.h>
58612+#include <linux/file.h>
58613+#include <linux/stat.h>
58614+#include <linux/grsecurity.h>
58615+#include <linux/grinternal.h>
58616+#include <linux/gracl.h>
58617+
58618+umode_t
58619+gr_acl_umask(void)
58620+{
58621+ if (unlikely(!gr_acl_is_enabled()))
58622+ return 0;
58623+
58624+ return current->role->umask;
58625+}
58626+
58627+__u32
58628+gr_acl_handle_hidden_file(const struct dentry * dentry,
58629+ const struct vfsmount * mnt)
58630+{
58631+ __u32 mode;
58632+
58633+ if (unlikely(!dentry->d_inode))
58634+ return GR_FIND;
58635+
58636+ mode =
58637+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
58638+
58639+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
58640+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
58641+ return mode;
58642+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
58643+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
58644+ return 0;
58645+ } else if (unlikely(!(mode & GR_FIND)))
58646+ return 0;
58647+
58648+ return GR_FIND;
58649+}
58650+
58651+__u32
58652+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
58653+ int acc_mode)
58654+{
58655+ __u32 reqmode = GR_FIND;
58656+ __u32 mode;
58657+
58658+ if (unlikely(!dentry->d_inode))
58659+ return reqmode;
58660+
58661+ if (acc_mode & MAY_APPEND)
58662+ reqmode |= GR_APPEND;
58663+ else if (acc_mode & MAY_WRITE)
58664+ reqmode |= GR_WRITE;
58665+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
58666+ reqmode |= GR_READ;
58667+
58668+ mode =
58669+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
58670+ mnt);
58671+
58672+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
58673+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
58674+ reqmode & GR_READ ? " reading" : "",
58675+ reqmode & GR_WRITE ? " writing" : reqmode &
58676+ GR_APPEND ? " appending" : "");
58677+ return reqmode;
58678+ } else
58679+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
58680+ {
58681+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
58682+ reqmode & GR_READ ? " reading" : "",
58683+ reqmode & GR_WRITE ? " writing" : reqmode &
58684+ GR_APPEND ? " appending" : "");
58685+ return 0;
58686+ } else if (unlikely((mode & reqmode) != reqmode))
58687+ return 0;
58688+
58689+ return reqmode;
58690+}
58691+
58692+__u32
58693+gr_acl_handle_creat(const struct dentry * dentry,
58694+ const struct dentry * p_dentry,
58695+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
58696+ const int imode)
58697+{
58698+ __u32 reqmode = GR_WRITE | GR_CREATE;
58699+ __u32 mode;
58700+
58701+ if (acc_mode & MAY_APPEND)
58702+ reqmode |= GR_APPEND;
58703+ // if a directory was required or the directory already exists, then
58704+ // don't count this open as a read
58705+ if ((acc_mode & MAY_READ) &&
58706+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
58707+ reqmode |= GR_READ;
58708+ if ((open_flags & O_CREAT) &&
58709+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
58710+ reqmode |= GR_SETID;
58711+
58712+ mode =
58713+ gr_check_create(dentry, p_dentry, p_mnt,
58714+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
58715+
58716+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
58717+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
58718+ reqmode & GR_READ ? " reading" : "",
58719+ reqmode & GR_WRITE ? " writing" : reqmode &
58720+ GR_APPEND ? " appending" : "");
58721+ return reqmode;
58722+ } else
58723+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
58724+ {
58725+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
58726+ reqmode & GR_READ ? " reading" : "",
58727+ reqmode & GR_WRITE ? " writing" : reqmode &
58728+ GR_APPEND ? " appending" : "");
58729+ return 0;
58730+ } else if (unlikely((mode & reqmode) != reqmode))
58731+ return 0;
58732+
58733+ return reqmode;
58734+}
58735+
58736+__u32
58737+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
58738+ const int fmode)
58739+{
58740+ __u32 mode, reqmode = GR_FIND;
58741+
58742+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
58743+ reqmode |= GR_EXEC;
58744+ if (fmode & S_IWOTH)
58745+ reqmode |= GR_WRITE;
58746+ if (fmode & S_IROTH)
58747+ reqmode |= GR_READ;
58748+
58749+ mode =
58750+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
58751+ mnt);
58752+
58753+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
58754+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
58755+ reqmode & GR_READ ? " reading" : "",
58756+ reqmode & GR_WRITE ? " writing" : "",
58757+ reqmode & GR_EXEC ? " executing" : "");
58758+ return reqmode;
58759+ } else
58760+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
58761+ {
58762+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
58763+ reqmode & GR_READ ? " reading" : "",
58764+ reqmode & GR_WRITE ? " writing" : "",
58765+ reqmode & GR_EXEC ? " executing" : "");
58766+ return 0;
58767+ } else if (unlikely((mode & reqmode) != reqmode))
58768+ return 0;
58769+
58770+ return reqmode;
58771+}
58772+
58773+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
58774+{
58775+ __u32 mode;
58776+
58777+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
58778+
58779+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
58780+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
58781+ return mode;
58782+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
58783+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
58784+ return 0;
58785+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
58786+ return 0;
58787+
58788+ return (reqmode);
58789+}
58790+
58791+__u32
58792+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
58793+{
58794+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
58795+}
58796+
58797+__u32
58798+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
58799+{
58800+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
58801+}
58802+
58803+__u32
58804+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
58805+{
58806+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
58807+}
58808+
58809+__u32
58810+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
58811+{
58812+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
58813+}
58814+
58815+__u32
58816+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
58817+ umode_t *modeptr)
58818+{
58819+ umode_t mode;
58820+
58821+ *modeptr &= ~gr_acl_umask();
58822+ mode = *modeptr;
58823+
58824+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
58825+ return 1;
58826+
58827+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
58828+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
58829+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
58830+ GR_CHMOD_ACL_MSG);
58831+ } else {
58832+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
58833+ }
58834+}
58835+
58836+__u32
58837+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
58838+{
58839+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
58840+}
58841+
58842+__u32
58843+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
58844+{
58845+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
58846+}
58847+
58848+__u32
58849+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
58850+{
58851+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
58852+}
58853+
58854+__u32
58855+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
58856+{
58857+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
58858+ GR_UNIXCONNECT_ACL_MSG);
58859+}
58860+
58861+/* hardlinks require at minimum create and link permission,
58862+ any additional privilege required is based on the
58863+ privilege of the file being linked to
58864+*/
58865+__u32
58866+gr_acl_handle_link(const struct dentry * new_dentry,
58867+ const struct dentry * parent_dentry,
58868+ const struct vfsmount * parent_mnt,
58869+ const struct dentry * old_dentry,
58870+ const struct vfsmount * old_mnt, const struct filename *to)
58871+{
58872+ __u32 mode;
58873+ __u32 needmode = GR_CREATE | GR_LINK;
58874+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
58875+
58876+ mode =
58877+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
58878+ old_mnt);
58879+
58880+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
58881+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
58882+ return mode;
58883+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
58884+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
58885+ return 0;
58886+ } else if (unlikely((mode & needmode) != needmode))
58887+ return 0;
58888+
58889+ return 1;
58890+}
58891+
58892+__u32
58893+gr_acl_handle_symlink(const struct dentry * new_dentry,
58894+ const struct dentry * parent_dentry,
58895+ const struct vfsmount * parent_mnt, const struct filename *from)
58896+{
58897+ __u32 needmode = GR_WRITE | GR_CREATE;
58898+ __u32 mode;
58899+
58900+ mode =
58901+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
58902+ GR_CREATE | GR_AUDIT_CREATE |
58903+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
58904+
58905+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
58906+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
58907+ return mode;
58908+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
58909+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
58910+ return 0;
58911+ } else if (unlikely((mode & needmode) != needmode))
58912+ return 0;
58913+
58914+ return (GR_WRITE | GR_CREATE);
58915+}
58916+
58917+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)
58918+{
58919+ __u32 mode;
58920+
58921+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
58922+
58923+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
58924+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
58925+ return mode;
58926+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
58927+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
58928+ return 0;
58929+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
58930+ return 0;
58931+
58932+ return (reqmode);
58933+}
58934+
58935+__u32
58936+gr_acl_handle_mknod(const struct dentry * new_dentry,
58937+ const struct dentry * parent_dentry,
58938+ const struct vfsmount * parent_mnt,
58939+ const int mode)
58940+{
58941+ __u32 reqmode = GR_WRITE | GR_CREATE;
58942+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
58943+ reqmode |= GR_SETID;
58944+
58945+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
58946+ reqmode, GR_MKNOD_ACL_MSG);
58947+}
58948+
58949+__u32
58950+gr_acl_handle_mkdir(const struct dentry *new_dentry,
58951+ const struct dentry *parent_dentry,
58952+ const struct vfsmount *parent_mnt)
58953+{
58954+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
58955+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
58956+}
58957+
58958+#define RENAME_CHECK_SUCCESS(old, new) \
58959+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
58960+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
58961+
58962+int
58963+gr_acl_handle_rename(struct dentry *new_dentry,
58964+ struct dentry *parent_dentry,
58965+ const struct vfsmount *parent_mnt,
58966+ struct dentry *old_dentry,
58967+ struct inode *old_parent_inode,
58968+ struct vfsmount *old_mnt, const struct filename *newname)
58969+{
58970+ __u32 comp1, comp2;
58971+ int error = 0;
58972+
58973+ if (unlikely(!gr_acl_is_enabled()))
58974+ return 0;
58975+
58976+ if (!new_dentry->d_inode) {
58977+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
58978+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
58979+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
58980+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
58981+ GR_DELETE | GR_AUDIT_DELETE |
58982+ GR_AUDIT_READ | GR_AUDIT_WRITE |
58983+ GR_SUPPRESS, old_mnt);
58984+ } else {
58985+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
58986+ GR_CREATE | GR_DELETE |
58987+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
58988+ GR_AUDIT_READ | GR_AUDIT_WRITE |
58989+ GR_SUPPRESS, parent_mnt);
58990+ comp2 =
58991+ gr_search_file(old_dentry,
58992+ GR_READ | GR_WRITE | GR_AUDIT_READ |
58993+ GR_DELETE | GR_AUDIT_DELETE |
58994+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
58995+ }
58996+
58997+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
58998+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
58999+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
59000+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
59001+ && !(comp2 & GR_SUPPRESS)) {
59002+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
59003+ error = -EACCES;
59004+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
59005+ error = -EACCES;
59006+
59007+ return error;
59008+}
59009+
59010+void
59011+gr_acl_handle_exit(void)
59012+{
59013+ u16 id;
59014+ char *rolename;
59015+
59016+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
59017+ !(current->role->roletype & GR_ROLE_PERSIST))) {
59018+ id = current->acl_role_id;
59019+ rolename = current->role->rolename;
59020+ gr_set_acls(1);
59021+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
59022+ }
59023+
59024+ gr_put_exec_file(current);
59025+ return;
59026+}
59027+
59028+int
59029+gr_acl_handle_procpidmem(const struct task_struct *task)
59030+{
59031+ if (unlikely(!gr_acl_is_enabled()))
59032+ return 0;
59033+
59034+ if (task != current && task->acl->mode & GR_PROTPROCFD)
59035+ return -EACCES;
59036+
59037+ return 0;
59038+}
59039diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
59040new file mode 100644
59041index 0000000..58800a7
59042--- /dev/null
59043+++ b/grsecurity/gracl_ip.c
59044@@ -0,0 +1,384 @@
59045+#include <linux/kernel.h>
59046+#include <asm/uaccess.h>
59047+#include <asm/errno.h>
59048+#include <net/sock.h>
59049+#include <linux/file.h>
59050+#include <linux/fs.h>
59051+#include <linux/net.h>
59052+#include <linux/in.h>
59053+#include <linux/skbuff.h>
59054+#include <linux/ip.h>
59055+#include <linux/udp.h>
59056+#include <linux/types.h>
59057+#include <linux/sched.h>
59058+#include <linux/netdevice.h>
59059+#include <linux/inetdevice.h>
59060+#include <linux/gracl.h>
59061+#include <linux/grsecurity.h>
59062+#include <linux/grinternal.h>
59063+
59064+#define GR_BIND 0x01
59065+#define GR_CONNECT 0x02
59066+#define GR_INVERT 0x04
59067+#define GR_BINDOVERRIDE 0x08
59068+#define GR_CONNECTOVERRIDE 0x10
59069+#define GR_SOCK_FAMILY 0x20
59070+
59071+static const char * gr_protocols[IPPROTO_MAX] = {
59072+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
59073+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
59074+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
59075+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
59076+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
59077+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
59078+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
59079+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
59080+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
59081+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
59082+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
59083+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
59084+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
59085+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
59086+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
59087+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
59088+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
59089+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
59090+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
59091+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
59092+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
59093+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
59094+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
59095+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
59096+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
59097+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
59098+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
59099+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
59100+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
59101+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
59102+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
59103+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
59104+ };
59105+
59106+static const char * gr_socktypes[SOCK_MAX] = {
59107+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
59108+ "unknown:7", "unknown:8", "unknown:9", "packet"
59109+ };
59110+
59111+static const char * gr_sockfamilies[AF_MAX+1] = {
59112+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
59113+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
59114+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
59115+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
59116+ };
59117+
59118+const char *
59119+gr_proto_to_name(unsigned char proto)
59120+{
59121+ return gr_protocols[proto];
59122+}
59123+
59124+const char *
59125+gr_socktype_to_name(unsigned char type)
59126+{
59127+ return gr_socktypes[type];
59128+}
59129+
59130+const char *
59131+gr_sockfamily_to_name(unsigned char family)
59132+{
59133+ return gr_sockfamilies[family];
59134+}
59135+
59136+int
59137+gr_search_socket(const int domain, const int type, const int protocol)
59138+{
59139+ struct acl_subject_label *curr;
59140+ const struct cred *cred = current_cred();
59141+
59142+ if (unlikely(!gr_acl_is_enabled()))
59143+ goto exit;
59144+
59145+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
59146+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
59147+ goto exit; // let the kernel handle it
59148+
59149+ curr = current->acl;
59150+
59151+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
59152+ /* the family is allowed, if this is PF_INET allow it only if
59153+ the extra sock type/protocol checks pass */
59154+ if (domain == PF_INET)
59155+ goto inet_check;
59156+ goto exit;
59157+ } else {
59158+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
59159+ __u32 fakeip = 0;
59160+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
59161+ current->role->roletype, cred->uid,
59162+ cred->gid, current->exec_file ?
59163+ gr_to_filename(current->exec_file->f_path.dentry,
59164+ current->exec_file->f_path.mnt) :
59165+ curr->filename, curr->filename,
59166+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
59167+ &current->signal->saved_ip);
59168+ goto exit;
59169+ }
59170+ goto exit_fail;
59171+ }
59172+
59173+inet_check:
59174+ /* the rest of this checking is for IPv4 only */
59175+ if (!curr->ips)
59176+ goto exit;
59177+
59178+ if ((curr->ip_type & (1 << type)) &&
59179+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
59180+ goto exit;
59181+
59182+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
59183+ /* we don't place acls on raw sockets , and sometimes
59184+ dgram/ip sockets are opened for ioctl and not
59185+ bind/connect, so we'll fake a bind learn log */
59186+ if (type == SOCK_RAW || type == SOCK_PACKET) {
59187+ __u32 fakeip = 0;
59188+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
59189+ current->role->roletype, cred->uid,
59190+ cred->gid, current->exec_file ?
59191+ gr_to_filename(current->exec_file->f_path.dentry,
59192+ current->exec_file->f_path.mnt) :
59193+ curr->filename, curr->filename,
59194+ &fakeip, 0, type,
59195+ protocol, GR_CONNECT, &current->signal->saved_ip);
59196+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
59197+ __u32 fakeip = 0;
59198+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
59199+ current->role->roletype, cred->uid,
59200+ cred->gid, current->exec_file ?
59201+ gr_to_filename(current->exec_file->f_path.dentry,
59202+ current->exec_file->f_path.mnt) :
59203+ curr->filename, curr->filename,
59204+ &fakeip, 0, type,
59205+ protocol, GR_BIND, &current->signal->saved_ip);
59206+ }
59207+ /* we'll log when they use connect or bind */
59208+ goto exit;
59209+ }
59210+
59211+exit_fail:
59212+ if (domain == PF_INET)
59213+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
59214+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
59215+ else
59216+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
59217+ gr_socktype_to_name(type), protocol);
59218+
59219+ return 0;
59220+exit:
59221+ return 1;
59222+}
59223+
59224+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)
59225+{
59226+ if ((ip->mode & mode) &&
59227+ (ip_port >= ip->low) &&
59228+ (ip_port <= ip->high) &&
59229+ ((ntohl(ip_addr) & our_netmask) ==
59230+ (ntohl(our_addr) & our_netmask))
59231+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
59232+ && (ip->type & (1 << type))) {
59233+ if (ip->mode & GR_INVERT)
59234+ return 2; // specifically denied
59235+ else
59236+ return 1; // allowed
59237+ }
59238+
59239+ return 0; // not specifically allowed, may continue parsing
59240+}
59241+
59242+static int
59243+gr_search_connectbind(const int full_mode, struct sock *sk,
59244+ struct sockaddr_in *addr, const int type)
59245+{
59246+ char iface[IFNAMSIZ] = {0};
59247+ struct acl_subject_label *curr;
59248+ struct acl_ip_label *ip;
59249+ struct inet_sock *isk;
59250+ struct net_device *dev;
59251+ struct in_device *idev;
59252+ unsigned long i;
59253+ int ret;
59254+ int mode = full_mode & (GR_BIND | GR_CONNECT);
59255+ __u32 ip_addr = 0;
59256+ __u32 our_addr;
59257+ __u32 our_netmask;
59258+ char *p;
59259+ __u16 ip_port = 0;
59260+ const struct cred *cred = current_cred();
59261+
59262+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
59263+ return 0;
59264+
59265+ curr = current->acl;
59266+ isk = inet_sk(sk);
59267+
59268+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
59269+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
59270+ addr->sin_addr.s_addr = curr->inaddr_any_override;
59271+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
59272+ struct sockaddr_in saddr;
59273+ int err;
59274+
59275+ saddr.sin_family = AF_INET;
59276+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
59277+ saddr.sin_port = isk->inet_sport;
59278+
59279+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
59280+ if (err)
59281+ return err;
59282+
59283+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
59284+ if (err)
59285+ return err;
59286+ }
59287+
59288+ if (!curr->ips)
59289+ return 0;
59290+
59291+ ip_addr = addr->sin_addr.s_addr;
59292+ ip_port = ntohs(addr->sin_port);
59293+
59294+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
59295+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
59296+ current->role->roletype, cred->uid,
59297+ cred->gid, current->exec_file ?
59298+ gr_to_filename(current->exec_file->f_path.dentry,
59299+ current->exec_file->f_path.mnt) :
59300+ curr->filename, curr->filename,
59301+ &ip_addr, ip_port, type,
59302+ sk->sk_protocol, mode, &current->signal->saved_ip);
59303+ return 0;
59304+ }
59305+
59306+ for (i = 0; i < curr->ip_num; i++) {
59307+ ip = *(curr->ips + i);
59308+ if (ip->iface != NULL) {
59309+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
59310+ p = strchr(iface, ':');
59311+ if (p != NULL)
59312+ *p = '\0';
59313+ dev = dev_get_by_name(sock_net(sk), iface);
59314+ if (dev == NULL)
59315+ continue;
59316+ idev = in_dev_get(dev);
59317+ if (idev == NULL) {
59318+ dev_put(dev);
59319+ continue;
59320+ }
59321+ rcu_read_lock();
59322+ for_ifa(idev) {
59323+ if (!strcmp(ip->iface, ifa->ifa_label)) {
59324+ our_addr = ifa->ifa_address;
59325+ our_netmask = 0xffffffff;
59326+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
59327+ if (ret == 1) {
59328+ rcu_read_unlock();
59329+ in_dev_put(idev);
59330+ dev_put(dev);
59331+ return 0;
59332+ } else if (ret == 2) {
59333+ rcu_read_unlock();
59334+ in_dev_put(idev);
59335+ dev_put(dev);
59336+ goto denied;
59337+ }
59338+ }
59339+ } endfor_ifa(idev);
59340+ rcu_read_unlock();
59341+ in_dev_put(idev);
59342+ dev_put(dev);
59343+ } else {
59344+ our_addr = ip->addr;
59345+ our_netmask = ip->netmask;
59346+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
59347+ if (ret == 1)
59348+ return 0;
59349+ else if (ret == 2)
59350+ goto denied;
59351+ }
59352+ }
59353+
59354+denied:
59355+ if (mode == GR_BIND)
59356+ 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));
59357+ else if (mode == GR_CONNECT)
59358+ 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));
59359+
59360+ return -EACCES;
59361+}
59362+
59363+int
59364+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
59365+{
59366+ /* always allow disconnection of dgram sockets with connect */
59367+ if (addr->sin_family == AF_UNSPEC)
59368+ return 0;
59369+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
59370+}
59371+
59372+int
59373+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
59374+{
59375+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
59376+}
59377+
59378+int gr_search_listen(struct socket *sock)
59379+{
59380+ struct sock *sk = sock->sk;
59381+ struct sockaddr_in addr;
59382+
59383+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
59384+ addr.sin_port = inet_sk(sk)->inet_sport;
59385+
59386+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
59387+}
59388+
59389+int gr_search_accept(struct socket *sock)
59390+{
59391+ struct sock *sk = sock->sk;
59392+ struct sockaddr_in addr;
59393+
59394+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
59395+ addr.sin_port = inet_sk(sk)->inet_sport;
59396+
59397+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
59398+}
59399+
59400+int
59401+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
59402+{
59403+ if (addr)
59404+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
59405+ else {
59406+ struct sockaddr_in sin;
59407+ const struct inet_sock *inet = inet_sk(sk);
59408+
59409+ sin.sin_addr.s_addr = inet->inet_daddr;
59410+ sin.sin_port = inet->inet_dport;
59411+
59412+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
59413+ }
59414+}
59415+
59416+int
59417+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
59418+{
59419+ struct sockaddr_in sin;
59420+
59421+ if (unlikely(skb->len < sizeof (struct udphdr)))
59422+ return 0; // skip this packet
59423+
59424+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
59425+ sin.sin_port = udp_hdr(skb)->source;
59426+
59427+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
59428+}
59429diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
59430new file mode 100644
59431index 0000000..25f54ef
59432--- /dev/null
59433+++ b/grsecurity/gracl_learn.c
59434@@ -0,0 +1,207 @@
59435+#include <linux/kernel.h>
59436+#include <linux/mm.h>
59437+#include <linux/sched.h>
59438+#include <linux/poll.h>
59439+#include <linux/string.h>
59440+#include <linux/file.h>
59441+#include <linux/types.h>
59442+#include <linux/vmalloc.h>
59443+#include <linux/grinternal.h>
59444+
59445+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
59446+ size_t count, loff_t *ppos);
59447+extern int gr_acl_is_enabled(void);
59448+
59449+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
59450+static int gr_learn_attached;
59451+
59452+/* use a 512k buffer */
59453+#define LEARN_BUFFER_SIZE (512 * 1024)
59454+
59455+static DEFINE_SPINLOCK(gr_learn_lock);
59456+static DEFINE_MUTEX(gr_learn_user_mutex);
59457+
59458+/* we need to maintain two buffers, so that the kernel context of grlearn
59459+ uses a semaphore around the userspace copying, and the other kernel contexts
59460+ use a spinlock when copying into the buffer, since they cannot sleep
59461+*/
59462+static char *learn_buffer;
59463+static char *learn_buffer_user;
59464+static int learn_buffer_len;
59465+static int learn_buffer_user_len;
59466+
59467+static ssize_t
59468+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
59469+{
59470+ DECLARE_WAITQUEUE(wait, current);
59471+ ssize_t retval = 0;
59472+
59473+ add_wait_queue(&learn_wait, &wait);
59474+ set_current_state(TASK_INTERRUPTIBLE);
59475+ do {
59476+ mutex_lock(&gr_learn_user_mutex);
59477+ spin_lock(&gr_learn_lock);
59478+ if (learn_buffer_len)
59479+ break;
59480+ spin_unlock(&gr_learn_lock);
59481+ mutex_unlock(&gr_learn_user_mutex);
59482+ if (file->f_flags & O_NONBLOCK) {
59483+ retval = -EAGAIN;
59484+ goto out;
59485+ }
59486+ if (signal_pending(current)) {
59487+ retval = -ERESTARTSYS;
59488+ goto out;
59489+ }
59490+
59491+ schedule();
59492+ } while (1);
59493+
59494+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
59495+ learn_buffer_user_len = learn_buffer_len;
59496+ retval = learn_buffer_len;
59497+ learn_buffer_len = 0;
59498+
59499+ spin_unlock(&gr_learn_lock);
59500+
59501+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
59502+ retval = -EFAULT;
59503+
59504+ mutex_unlock(&gr_learn_user_mutex);
59505+out:
59506+ set_current_state(TASK_RUNNING);
59507+ remove_wait_queue(&learn_wait, &wait);
59508+ return retval;
59509+}
59510+
59511+static unsigned int
59512+poll_learn(struct file * file, poll_table * wait)
59513+{
59514+ poll_wait(file, &learn_wait, wait);
59515+
59516+ if (learn_buffer_len)
59517+ return (POLLIN | POLLRDNORM);
59518+
59519+ return 0;
59520+}
59521+
59522+void
59523+gr_clear_learn_entries(void)
59524+{
59525+ char *tmp;
59526+
59527+ mutex_lock(&gr_learn_user_mutex);
59528+ spin_lock(&gr_learn_lock);
59529+ tmp = learn_buffer;
59530+ learn_buffer = NULL;
59531+ spin_unlock(&gr_learn_lock);
59532+ if (tmp)
59533+ vfree(tmp);
59534+ if (learn_buffer_user != NULL) {
59535+ vfree(learn_buffer_user);
59536+ learn_buffer_user = NULL;
59537+ }
59538+ learn_buffer_len = 0;
59539+ mutex_unlock(&gr_learn_user_mutex);
59540+
59541+ return;
59542+}
59543+
59544+void
59545+gr_add_learn_entry(const char *fmt, ...)
59546+{
59547+ va_list args;
59548+ unsigned int len;
59549+
59550+ if (!gr_learn_attached)
59551+ return;
59552+
59553+ spin_lock(&gr_learn_lock);
59554+
59555+ /* leave a gap at the end so we know when it's "full" but don't have to
59556+ compute the exact length of the string we're trying to append
59557+ */
59558+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
59559+ spin_unlock(&gr_learn_lock);
59560+ wake_up_interruptible(&learn_wait);
59561+ return;
59562+ }
59563+ if (learn_buffer == NULL) {
59564+ spin_unlock(&gr_learn_lock);
59565+ return;
59566+ }
59567+
59568+ va_start(args, fmt);
59569+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
59570+ va_end(args);
59571+
59572+ learn_buffer_len += len + 1;
59573+
59574+ spin_unlock(&gr_learn_lock);
59575+ wake_up_interruptible(&learn_wait);
59576+
59577+ return;
59578+}
59579+
59580+static int
59581+open_learn(struct inode *inode, struct file *file)
59582+{
59583+ if (file->f_mode & FMODE_READ && gr_learn_attached)
59584+ return -EBUSY;
59585+ if (file->f_mode & FMODE_READ) {
59586+ int retval = 0;
59587+ mutex_lock(&gr_learn_user_mutex);
59588+ if (learn_buffer == NULL)
59589+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
59590+ if (learn_buffer_user == NULL)
59591+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
59592+ if (learn_buffer == NULL) {
59593+ retval = -ENOMEM;
59594+ goto out_error;
59595+ }
59596+ if (learn_buffer_user == NULL) {
59597+ retval = -ENOMEM;
59598+ goto out_error;
59599+ }
59600+ learn_buffer_len = 0;
59601+ learn_buffer_user_len = 0;
59602+ gr_learn_attached = 1;
59603+out_error:
59604+ mutex_unlock(&gr_learn_user_mutex);
59605+ return retval;
59606+ }
59607+ return 0;
59608+}
59609+
59610+static int
59611+close_learn(struct inode *inode, struct file *file)
59612+{
59613+ if (file->f_mode & FMODE_READ) {
59614+ char *tmp = NULL;
59615+ mutex_lock(&gr_learn_user_mutex);
59616+ spin_lock(&gr_learn_lock);
59617+ tmp = learn_buffer;
59618+ learn_buffer = NULL;
59619+ spin_unlock(&gr_learn_lock);
59620+ if (tmp)
59621+ vfree(tmp);
59622+ if (learn_buffer_user != NULL) {
59623+ vfree(learn_buffer_user);
59624+ learn_buffer_user = NULL;
59625+ }
59626+ learn_buffer_len = 0;
59627+ learn_buffer_user_len = 0;
59628+ gr_learn_attached = 0;
59629+ mutex_unlock(&gr_learn_user_mutex);
59630+ }
59631+
59632+ return 0;
59633+}
59634+
59635+const struct file_operations grsec_fops = {
59636+ .read = read_learn,
59637+ .write = write_grsec_handler,
59638+ .open = open_learn,
59639+ .release = close_learn,
59640+ .poll = poll_learn,
59641+};
59642diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
59643new file mode 100644
59644index 0000000..39645c9
59645--- /dev/null
59646+++ b/grsecurity/gracl_res.c
59647@@ -0,0 +1,68 @@
59648+#include <linux/kernel.h>
59649+#include <linux/sched.h>
59650+#include <linux/gracl.h>
59651+#include <linux/grinternal.h>
59652+
59653+static const char *restab_log[] = {
59654+ [RLIMIT_CPU] = "RLIMIT_CPU",
59655+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
59656+ [RLIMIT_DATA] = "RLIMIT_DATA",
59657+ [RLIMIT_STACK] = "RLIMIT_STACK",
59658+ [RLIMIT_CORE] = "RLIMIT_CORE",
59659+ [RLIMIT_RSS] = "RLIMIT_RSS",
59660+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
59661+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
59662+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
59663+ [RLIMIT_AS] = "RLIMIT_AS",
59664+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
59665+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
59666+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
59667+ [RLIMIT_NICE] = "RLIMIT_NICE",
59668+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
59669+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
59670+ [GR_CRASH_RES] = "RLIMIT_CRASH"
59671+};
59672+
59673+void
59674+gr_log_resource(const struct task_struct *task,
59675+ const int res, const unsigned long wanted, const int gt)
59676+{
59677+ const struct cred *cred;
59678+ unsigned long rlim;
59679+
59680+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
59681+ return;
59682+
59683+ // not yet supported resource
59684+ if (unlikely(!restab_log[res]))
59685+ return;
59686+
59687+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
59688+ rlim = task_rlimit_max(task, res);
59689+ else
59690+ rlim = task_rlimit(task, res);
59691+
59692+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
59693+ return;
59694+
59695+ rcu_read_lock();
59696+ cred = __task_cred(task);
59697+
59698+ if (res == RLIMIT_NPROC &&
59699+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
59700+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
59701+ goto out_rcu_unlock;
59702+ else if (res == RLIMIT_MEMLOCK &&
59703+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
59704+ goto out_rcu_unlock;
59705+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
59706+ goto out_rcu_unlock;
59707+ rcu_read_unlock();
59708+
59709+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
59710+
59711+ return;
59712+out_rcu_unlock:
59713+ rcu_read_unlock();
59714+ return;
59715+}
59716diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
59717new file mode 100644
59718index 0000000..25197e9
59719--- /dev/null
59720+++ b/grsecurity/gracl_segv.c
59721@@ -0,0 +1,299 @@
59722+#include <linux/kernel.h>
59723+#include <linux/mm.h>
59724+#include <asm/uaccess.h>
59725+#include <asm/errno.h>
59726+#include <asm/mman.h>
59727+#include <net/sock.h>
59728+#include <linux/file.h>
59729+#include <linux/fs.h>
59730+#include <linux/net.h>
59731+#include <linux/in.h>
59732+#include <linux/slab.h>
59733+#include <linux/types.h>
59734+#include <linux/sched.h>
59735+#include <linux/timer.h>
59736+#include <linux/gracl.h>
59737+#include <linux/grsecurity.h>
59738+#include <linux/grinternal.h>
59739+
59740+static struct crash_uid *uid_set;
59741+static unsigned short uid_used;
59742+static DEFINE_SPINLOCK(gr_uid_lock);
59743+extern rwlock_t gr_inode_lock;
59744+extern struct acl_subject_label *
59745+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
59746+ struct acl_role_label *role);
59747+
59748+#ifdef CONFIG_BTRFS_FS
59749+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
59750+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
59751+#endif
59752+
59753+static inline dev_t __get_dev(const struct dentry *dentry)
59754+{
59755+#ifdef CONFIG_BTRFS_FS
59756+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
59757+ return get_btrfs_dev_from_inode(dentry->d_inode);
59758+ else
59759+#endif
59760+ return dentry->d_inode->i_sb->s_dev;
59761+}
59762+
59763+int
59764+gr_init_uidset(void)
59765+{
59766+ uid_set =
59767+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
59768+ uid_used = 0;
59769+
59770+ return uid_set ? 1 : 0;
59771+}
59772+
59773+void
59774+gr_free_uidset(void)
59775+{
59776+ if (uid_set)
59777+ kfree(uid_set);
59778+
59779+ return;
59780+}
59781+
59782+int
59783+gr_find_uid(const uid_t uid)
59784+{
59785+ struct crash_uid *tmp = uid_set;
59786+ uid_t buid;
59787+ int low = 0, high = uid_used - 1, mid;
59788+
59789+ while (high >= low) {
59790+ mid = (low + high) >> 1;
59791+ buid = tmp[mid].uid;
59792+ if (buid == uid)
59793+ return mid;
59794+ if (buid > uid)
59795+ high = mid - 1;
59796+ if (buid < uid)
59797+ low = mid + 1;
59798+ }
59799+
59800+ return -1;
59801+}
59802+
59803+static __inline__ void
59804+gr_insertsort(void)
59805+{
59806+ unsigned short i, j;
59807+ struct crash_uid index;
59808+
59809+ for (i = 1; i < uid_used; i++) {
59810+ index = uid_set[i];
59811+ j = i;
59812+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
59813+ uid_set[j] = uid_set[j - 1];
59814+ j--;
59815+ }
59816+ uid_set[j] = index;
59817+ }
59818+
59819+ return;
59820+}
59821+
59822+static __inline__ void
59823+gr_insert_uid(const uid_t uid, const unsigned long expires)
59824+{
59825+ int loc;
59826+
59827+ if (uid_used == GR_UIDTABLE_MAX)
59828+ return;
59829+
59830+ loc = gr_find_uid(uid);
59831+
59832+ if (loc >= 0) {
59833+ uid_set[loc].expires = expires;
59834+ return;
59835+ }
59836+
59837+ uid_set[uid_used].uid = uid;
59838+ uid_set[uid_used].expires = expires;
59839+ uid_used++;
59840+
59841+ gr_insertsort();
59842+
59843+ return;
59844+}
59845+
59846+void
59847+gr_remove_uid(const unsigned short loc)
59848+{
59849+ unsigned short i;
59850+
59851+ for (i = loc + 1; i < uid_used; i++)
59852+ uid_set[i - 1] = uid_set[i];
59853+
59854+ uid_used--;
59855+
59856+ return;
59857+}
59858+
59859+int
59860+gr_check_crash_uid(const uid_t uid)
59861+{
59862+ int loc;
59863+ int ret = 0;
59864+
59865+ if (unlikely(!gr_acl_is_enabled()))
59866+ return 0;
59867+
59868+ spin_lock(&gr_uid_lock);
59869+ loc = gr_find_uid(uid);
59870+
59871+ if (loc < 0)
59872+ goto out_unlock;
59873+
59874+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
59875+ gr_remove_uid(loc);
59876+ else
59877+ ret = 1;
59878+
59879+out_unlock:
59880+ spin_unlock(&gr_uid_lock);
59881+ return ret;
59882+}
59883+
59884+static __inline__ int
59885+proc_is_setxid(const struct cred *cred)
59886+{
59887+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
59888+ !uid_eq(cred->uid, cred->fsuid))
59889+ return 1;
59890+ if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
59891+ !uid_eq(cred->gid, cred->fsgid))
59892+ return 1;
59893+
59894+ return 0;
59895+}
59896+
59897+extern int gr_fake_force_sig(int sig, struct task_struct *t);
59898+
59899+void
59900+gr_handle_crash(struct task_struct *task, const int sig)
59901+{
59902+ struct acl_subject_label *curr;
59903+ struct task_struct *tsk, *tsk2;
59904+ const struct cred *cred;
59905+ const struct cred *cred2;
59906+
59907+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
59908+ return;
59909+
59910+ if (unlikely(!gr_acl_is_enabled()))
59911+ return;
59912+
59913+ curr = task->acl;
59914+
59915+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
59916+ return;
59917+
59918+ if (time_before_eq(curr->expires, get_seconds())) {
59919+ curr->expires = 0;
59920+ curr->crashes = 0;
59921+ }
59922+
59923+ curr->crashes++;
59924+
59925+ if (!curr->expires)
59926+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
59927+
59928+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
59929+ time_after(curr->expires, get_seconds())) {
59930+ rcu_read_lock();
59931+ cred = __task_cred(task);
59932+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
59933+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
59934+ spin_lock(&gr_uid_lock);
59935+ gr_insert_uid(cred->uid, curr->expires);
59936+ spin_unlock(&gr_uid_lock);
59937+ curr->expires = 0;
59938+ curr->crashes = 0;
59939+ read_lock(&tasklist_lock);
59940+ do_each_thread(tsk2, tsk) {
59941+ cred2 = __task_cred(tsk);
59942+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
59943+ gr_fake_force_sig(SIGKILL, tsk);
59944+ } while_each_thread(tsk2, tsk);
59945+ read_unlock(&tasklist_lock);
59946+ } else {
59947+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
59948+ read_lock(&tasklist_lock);
59949+ read_lock(&grsec_exec_file_lock);
59950+ do_each_thread(tsk2, tsk) {
59951+ if (likely(tsk != task)) {
59952+ // if this thread has the same subject as the one that triggered
59953+ // RES_CRASH and it's the same binary, kill it
59954+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
59955+ gr_fake_force_sig(SIGKILL, tsk);
59956+ }
59957+ } while_each_thread(tsk2, tsk);
59958+ read_unlock(&grsec_exec_file_lock);
59959+ read_unlock(&tasklist_lock);
59960+ }
59961+ rcu_read_unlock();
59962+ }
59963+
59964+ return;
59965+}
59966+
59967+int
59968+gr_check_crash_exec(const struct file *filp)
59969+{
59970+ struct acl_subject_label *curr;
59971+
59972+ if (unlikely(!gr_acl_is_enabled()))
59973+ return 0;
59974+
59975+ read_lock(&gr_inode_lock);
59976+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
59977+ __get_dev(filp->f_path.dentry),
59978+ current->role);
59979+ read_unlock(&gr_inode_lock);
59980+
59981+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
59982+ (!curr->crashes && !curr->expires))
59983+ return 0;
59984+
59985+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
59986+ time_after(curr->expires, get_seconds()))
59987+ return 1;
59988+ else if (time_before_eq(curr->expires, get_seconds())) {
59989+ curr->crashes = 0;
59990+ curr->expires = 0;
59991+ }
59992+
59993+ return 0;
59994+}
59995+
59996+void
59997+gr_handle_alertkill(struct task_struct *task)
59998+{
59999+ struct acl_subject_label *curracl;
60000+ __u32 curr_ip;
60001+ struct task_struct *p, *p2;
60002+
60003+ if (unlikely(!gr_acl_is_enabled()))
60004+ return;
60005+
60006+ curracl = task->acl;
60007+ curr_ip = task->signal->curr_ip;
60008+
60009+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
60010+ read_lock(&tasklist_lock);
60011+ do_each_thread(p2, p) {
60012+ if (p->signal->curr_ip == curr_ip)
60013+ gr_fake_force_sig(SIGKILL, p);
60014+ } while_each_thread(p2, p);
60015+ read_unlock(&tasklist_lock);
60016+ } else if (curracl->mode & GR_KILLPROC)
60017+ gr_fake_force_sig(SIGKILL, task);
60018+
60019+ return;
60020+}
60021diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
60022new file mode 100644
60023index 0000000..9d83a69
60024--- /dev/null
60025+++ b/grsecurity/gracl_shm.c
60026@@ -0,0 +1,40 @@
60027+#include <linux/kernel.h>
60028+#include <linux/mm.h>
60029+#include <linux/sched.h>
60030+#include <linux/file.h>
60031+#include <linux/ipc.h>
60032+#include <linux/gracl.h>
60033+#include <linux/grsecurity.h>
60034+#include <linux/grinternal.h>
60035+
60036+int
60037+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
60038+ const time_t shm_createtime, const uid_t cuid, const int shmid)
60039+{
60040+ struct task_struct *task;
60041+
60042+ if (!gr_acl_is_enabled())
60043+ return 1;
60044+
60045+ rcu_read_lock();
60046+ read_lock(&tasklist_lock);
60047+
60048+ task = find_task_by_vpid(shm_cprid);
60049+
60050+ if (unlikely(!task))
60051+ task = find_task_by_vpid(shm_lapid);
60052+
60053+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
60054+ (task->pid == shm_lapid)) &&
60055+ (task->acl->mode & GR_PROTSHM) &&
60056+ (task->acl != current->acl))) {
60057+ read_unlock(&tasklist_lock);
60058+ rcu_read_unlock();
60059+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
60060+ return 0;
60061+ }
60062+ read_unlock(&tasklist_lock);
60063+ rcu_read_unlock();
60064+
60065+ return 1;
60066+}
60067diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
60068new file mode 100644
60069index 0000000..bc0be01
60070--- /dev/null
60071+++ b/grsecurity/grsec_chdir.c
60072@@ -0,0 +1,19 @@
60073+#include <linux/kernel.h>
60074+#include <linux/sched.h>
60075+#include <linux/fs.h>
60076+#include <linux/file.h>
60077+#include <linux/grsecurity.h>
60078+#include <linux/grinternal.h>
60079+
60080+void
60081+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
60082+{
60083+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60084+ if ((grsec_enable_chdir && grsec_enable_group &&
60085+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
60086+ !grsec_enable_group)) {
60087+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
60088+ }
60089+#endif
60090+ return;
60091+}
60092diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
60093new file mode 100644
60094index 0000000..70fe0ae
60095--- /dev/null
60096+++ b/grsecurity/grsec_chroot.c
60097@@ -0,0 +1,357 @@
60098+#include <linux/kernel.h>
60099+#include <linux/module.h>
60100+#include <linux/sched.h>
60101+#include <linux/file.h>
60102+#include <linux/fs.h>
60103+#include <linux/mount.h>
60104+#include <linux/types.h>
60105+#include "../fs/mount.h"
60106+#include <linux/grsecurity.h>
60107+#include <linux/grinternal.h>
60108+
60109+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
60110+{
60111+#ifdef CONFIG_GRKERNSEC
60112+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
60113+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
60114+ task->gr_is_chrooted = 1;
60115+ else
60116+ task->gr_is_chrooted = 0;
60117+
60118+ task->gr_chroot_dentry = path->dentry;
60119+#endif
60120+ return;
60121+}
60122+
60123+void gr_clear_chroot_entries(struct task_struct *task)
60124+{
60125+#ifdef CONFIG_GRKERNSEC
60126+ task->gr_is_chrooted = 0;
60127+ task->gr_chroot_dentry = NULL;
60128+#endif
60129+ return;
60130+}
60131+
60132+int
60133+gr_handle_chroot_unix(const pid_t pid)
60134+{
60135+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
60136+ struct task_struct *p;
60137+
60138+ if (unlikely(!grsec_enable_chroot_unix))
60139+ return 1;
60140+
60141+ if (likely(!proc_is_chrooted(current)))
60142+ return 1;
60143+
60144+ rcu_read_lock();
60145+ read_lock(&tasklist_lock);
60146+ p = find_task_by_vpid_unrestricted(pid);
60147+ if (unlikely(p && !have_same_root(current, p))) {
60148+ read_unlock(&tasklist_lock);
60149+ rcu_read_unlock();
60150+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
60151+ return 0;
60152+ }
60153+ read_unlock(&tasklist_lock);
60154+ rcu_read_unlock();
60155+#endif
60156+ return 1;
60157+}
60158+
60159+int
60160+gr_handle_chroot_nice(void)
60161+{
60162+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60163+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
60164+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
60165+ return -EPERM;
60166+ }
60167+#endif
60168+ return 0;
60169+}
60170+
60171+int
60172+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
60173+{
60174+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60175+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
60176+ && proc_is_chrooted(current)) {
60177+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
60178+ return -EACCES;
60179+ }
60180+#endif
60181+ return 0;
60182+}
60183+
60184+int
60185+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
60186+{
60187+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60188+ struct task_struct *p;
60189+ int ret = 0;
60190+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
60191+ return ret;
60192+
60193+ read_lock(&tasklist_lock);
60194+ do_each_pid_task(pid, type, p) {
60195+ if (!have_same_root(current, p)) {
60196+ ret = 1;
60197+ goto out;
60198+ }
60199+ } while_each_pid_task(pid, type, p);
60200+out:
60201+ read_unlock(&tasklist_lock);
60202+ return ret;
60203+#endif
60204+ return 0;
60205+}
60206+
60207+int
60208+gr_pid_is_chrooted(struct task_struct *p)
60209+{
60210+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60211+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
60212+ return 0;
60213+
60214+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
60215+ !have_same_root(current, p)) {
60216+ return 1;
60217+ }
60218+#endif
60219+ return 0;
60220+}
60221+
60222+EXPORT_SYMBOL(gr_pid_is_chrooted);
60223+
60224+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
60225+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
60226+{
60227+ struct path path, currentroot;
60228+ int ret = 0;
60229+
60230+ path.dentry = (struct dentry *)u_dentry;
60231+ path.mnt = (struct vfsmount *)u_mnt;
60232+ get_fs_root(current->fs, &currentroot);
60233+ if (path_is_under(&path, &currentroot))
60234+ ret = 1;
60235+ path_put(&currentroot);
60236+
60237+ return ret;
60238+}
60239+#endif
60240+
60241+int
60242+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
60243+{
60244+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60245+ if (!grsec_enable_chroot_fchdir)
60246+ return 1;
60247+
60248+ if (!proc_is_chrooted(current))
60249+ return 1;
60250+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
60251+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
60252+ return 0;
60253+ }
60254+#endif
60255+ return 1;
60256+}
60257+
60258+int
60259+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
60260+ const time_t shm_createtime)
60261+{
60262+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
60263+ struct task_struct *p;
60264+ time_t starttime;
60265+
60266+ if (unlikely(!grsec_enable_chroot_shmat))
60267+ return 1;
60268+
60269+ if (likely(!proc_is_chrooted(current)))
60270+ return 1;
60271+
60272+ rcu_read_lock();
60273+ read_lock(&tasklist_lock);
60274+
60275+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
60276+ starttime = p->start_time.tv_sec;
60277+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
60278+ if (have_same_root(current, p)) {
60279+ goto allow;
60280+ } else {
60281+ read_unlock(&tasklist_lock);
60282+ rcu_read_unlock();
60283+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
60284+ return 0;
60285+ }
60286+ }
60287+ /* creator exited, pid reuse, fall through to next check */
60288+ }
60289+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
60290+ if (unlikely(!have_same_root(current, p))) {
60291+ read_unlock(&tasklist_lock);
60292+ rcu_read_unlock();
60293+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
60294+ return 0;
60295+ }
60296+ }
60297+
60298+allow:
60299+ read_unlock(&tasklist_lock);
60300+ rcu_read_unlock();
60301+#endif
60302+ return 1;
60303+}
60304+
60305+void
60306+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
60307+{
60308+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60309+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
60310+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
60311+#endif
60312+ return;
60313+}
60314+
60315+int
60316+gr_handle_chroot_mknod(const struct dentry *dentry,
60317+ const struct vfsmount *mnt, const int mode)
60318+{
60319+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60320+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
60321+ proc_is_chrooted(current)) {
60322+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
60323+ return -EPERM;
60324+ }
60325+#endif
60326+ return 0;
60327+}
60328+
60329+int
60330+gr_handle_chroot_mount(const struct dentry *dentry,
60331+ const struct vfsmount *mnt, const char *dev_name)
60332+{
60333+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
60334+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
60335+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
60336+ return -EPERM;
60337+ }
60338+#endif
60339+ return 0;
60340+}
60341+
60342+int
60343+gr_handle_chroot_pivot(void)
60344+{
60345+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60346+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
60347+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
60348+ return -EPERM;
60349+ }
60350+#endif
60351+ return 0;
60352+}
60353+
60354+int
60355+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
60356+{
60357+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60358+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
60359+ !gr_is_outside_chroot(dentry, mnt)) {
60360+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
60361+ return -EPERM;
60362+ }
60363+#endif
60364+ return 0;
60365+}
60366+
60367+extern const char *captab_log[];
60368+extern int captab_log_entries;
60369+
60370+int
60371+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
60372+{
60373+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60374+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
60375+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
60376+ if (cap_raised(chroot_caps, cap)) {
60377+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
60378+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
60379+ }
60380+ return 0;
60381+ }
60382+ }
60383+#endif
60384+ return 1;
60385+}
60386+
60387+int
60388+gr_chroot_is_capable(const int cap)
60389+{
60390+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60391+ return gr_task_chroot_is_capable(current, current_cred(), cap);
60392+#endif
60393+ return 1;
60394+}
60395+
60396+int
60397+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
60398+{
60399+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60400+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
60401+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
60402+ if (cap_raised(chroot_caps, cap)) {
60403+ return 0;
60404+ }
60405+ }
60406+#endif
60407+ return 1;
60408+}
60409+
60410+int
60411+gr_chroot_is_capable_nolog(const int cap)
60412+{
60413+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60414+ return gr_task_chroot_is_capable_nolog(current, cap);
60415+#endif
60416+ return 1;
60417+}
60418+
60419+int
60420+gr_handle_chroot_sysctl(const int op)
60421+{
60422+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60423+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
60424+ proc_is_chrooted(current))
60425+ return -EACCES;
60426+#endif
60427+ return 0;
60428+}
60429+
60430+void
60431+gr_handle_chroot_chdir(struct path *path)
60432+{
60433+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60434+ if (grsec_enable_chroot_chdir)
60435+ set_fs_pwd(current->fs, path);
60436+#endif
60437+ return;
60438+}
60439+
60440+int
60441+gr_handle_chroot_chmod(const struct dentry *dentry,
60442+ const struct vfsmount *mnt, const int mode)
60443+{
60444+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60445+ /* allow chmod +s on directories, but not files */
60446+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
60447+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
60448+ proc_is_chrooted(current)) {
60449+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
60450+ return -EPERM;
60451+ }
60452+#endif
60453+ return 0;
60454+}
60455diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
60456new file mode 100644
60457index 0000000..e6796b3
60458--- /dev/null
60459+++ b/grsecurity/grsec_disabled.c
60460@@ -0,0 +1,434 @@
60461+#include <linux/kernel.h>
60462+#include <linux/module.h>
60463+#include <linux/sched.h>
60464+#include <linux/file.h>
60465+#include <linux/fs.h>
60466+#include <linux/kdev_t.h>
60467+#include <linux/net.h>
60468+#include <linux/in.h>
60469+#include <linux/ip.h>
60470+#include <linux/skbuff.h>
60471+#include <linux/sysctl.h>
60472+
60473+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
60474+void
60475+pax_set_initial_flags(struct linux_binprm *bprm)
60476+{
60477+ return;
60478+}
60479+#endif
60480+
60481+#ifdef CONFIG_SYSCTL
60482+__u32
60483+gr_handle_sysctl(const struct ctl_table * table, const int op)
60484+{
60485+ return 0;
60486+}
60487+#endif
60488+
60489+#ifdef CONFIG_TASKSTATS
60490+int gr_is_taskstats_denied(int pid)
60491+{
60492+ return 0;
60493+}
60494+#endif
60495+
60496+int
60497+gr_acl_is_enabled(void)
60498+{
60499+ return 0;
60500+}
60501+
60502+void
60503+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
60504+{
60505+ return;
60506+}
60507+
60508+int
60509+gr_handle_rawio(const struct inode *inode)
60510+{
60511+ return 0;
60512+}
60513+
60514+void
60515+gr_acl_handle_psacct(struct task_struct *task, const long code)
60516+{
60517+ return;
60518+}
60519+
60520+int
60521+gr_handle_ptrace(struct task_struct *task, const long request)
60522+{
60523+ return 0;
60524+}
60525+
60526+int
60527+gr_handle_proc_ptrace(struct task_struct *task)
60528+{
60529+ return 0;
60530+}
60531+
60532+int
60533+gr_set_acls(const int type)
60534+{
60535+ return 0;
60536+}
60537+
60538+int
60539+gr_check_hidden_task(const struct task_struct *tsk)
60540+{
60541+ return 0;
60542+}
60543+
60544+int
60545+gr_check_protected_task(const struct task_struct *task)
60546+{
60547+ return 0;
60548+}
60549+
60550+int
60551+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
60552+{
60553+ return 0;
60554+}
60555+
60556+void
60557+gr_copy_label(struct task_struct *tsk)
60558+{
60559+ return;
60560+}
60561+
60562+void
60563+gr_set_pax_flags(struct task_struct *task)
60564+{
60565+ return;
60566+}
60567+
60568+int
60569+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
60570+ const int unsafe_share)
60571+{
60572+ return 0;
60573+}
60574+
60575+void
60576+gr_handle_delete(const ino_t ino, const dev_t dev)
60577+{
60578+ return;
60579+}
60580+
60581+void
60582+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
60583+{
60584+ return;
60585+}
60586+
60587+void
60588+gr_handle_crash(struct task_struct *task, const int sig)
60589+{
60590+ return;
60591+}
60592+
60593+int
60594+gr_check_crash_exec(const struct file *filp)
60595+{
60596+ return 0;
60597+}
60598+
60599+int
60600+gr_check_crash_uid(const uid_t uid)
60601+{
60602+ return 0;
60603+}
60604+
60605+void
60606+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
60607+ struct dentry *old_dentry,
60608+ struct dentry *new_dentry,
60609+ struct vfsmount *mnt, const __u8 replace)
60610+{
60611+ return;
60612+}
60613+
60614+int
60615+gr_search_socket(const int family, const int type, const int protocol)
60616+{
60617+ return 1;
60618+}
60619+
60620+int
60621+gr_search_connectbind(const int mode, const struct socket *sock,
60622+ const struct sockaddr_in *addr)
60623+{
60624+ return 0;
60625+}
60626+
60627+void
60628+gr_handle_alertkill(struct task_struct *task)
60629+{
60630+ return;
60631+}
60632+
60633+__u32
60634+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
60635+{
60636+ return 1;
60637+}
60638+
60639+__u32
60640+gr_acl_handle_hidden_file(const struct dentry * dentry,
60641+ const struct vfsmount * mnt)
60642+{
60643+ return 1;
60644+}
60645+
60646+__u32
60647+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
60648+ int acc_mode)
60649+{
60650+ return 1;
60651+}
60652+
60653+__u32
60654+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
60655+{
60656+ return 1;
60657+}
60658+
60659+__u32
60660+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
60661+{
60662+ return 1;
60663+}
60664+
60665+int
60666+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
60667+ unsigned int *vm_flags)
60668+{
60669+ return 1;
60670+}
60671+
60672+__u32
60673+gr_acl_handle_truncate(const struct dentry * dentry,
60674+ const struct vfsmount * mnt)
60675+{
60676+ return 1;
60677+}
60678+
60679+__u32
60680+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
60681+{
60682+ return 1;
60683+}
60684+
60685+__u32
60686+gr_acl_handle_access(const struct dentry * dentry,
60687+ const struct vfsmount * mnt, const int fmode)
60688+{
60689+ return 1;
60690+}
60691+
60692+__u32
60693+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
60694+ umode_t *mode)
60695+{
60696+ return 1;
60697+}
60698+
60699+__u32
60700+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
60701+{
60702+ return 1;
60703+}
60704+
60705+__u32
60706+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
60707+{
60708+ return 1;
60709+}
60710+
60711+void
60712+grsecurity_init(void)
60713+{
60714+ return;
60715+}
60716+
60717+umode_t gr_acl_umask(void)
60718+{
60719+ return 0;
60720+}
60721+
60722+__u32
60723+gr_acl_handle_mknod(const struct dentry * new_dentry,
60724+ const struct dentry * parent_dentry,
60725+ const struct vfsmount * parent_mnt,
60726+ const int mode)
60727+{
60728+ return 1;
60729+}
60730+
60731+__u32
60732+gr_acl_handle_mkdir(const struct dentry * new_dentry,
60733+ const struct dentry * parent_dentry,
60734+ const struct vfsmount * parent_mnt)
60735+{
60736+ return 1;
60737+}
60738+
60739+__u32
60740+gr_acl_handle_symlink(const struct dentry * new_dentry,
60741+ const struct dentry * parent_dentry,
60742+ const struct vfsmount * parent_mnt, const struct filename *from)
60743+{
60744+ return 1;
60745+}
60746+
60747+__u32
60748+gr_acl_handle_link(const struct dentry * new_dentry,
60749+ const struct dentry * parent_dentry,
60750+ const struct vfsmount * parent_mnt,
60751+ const struct dentry * old_dentry,
60752+ const struct vfsmount * old_mnt, const struct filename *to)
60753+{
60754+ return 1;
60755+}
60756+
60757+int
60758+gr_acl_handle_rename(const struct dentry *new_dentry,
60759+ const struct dentry *parent_dentry,
60760+ const struct vfsmount *parent_mnt,
60761+ const struct dentry *old_dentry,
60762+ const struct inode *old_parent_inode,
60763+ const struct vfsmount *old_mnt, const struct filename *newname)
60764+{
60765+ return 0;
60766+}
60767+
60768+int
60769+gr_acl_handle_filldir(const struct file *file, const char *name,
60770+ const int namelen, const ino_t ino)
60771+{
60772+ return 1;
60773+}
60774+
60775+int
60776+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
60777+ const time_t shm_createtime, const uid_t cuid, const int shmid)
60778+{
60779+ return 1;
60780+}
60781+
60782+int
60783+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
60784+{
60785+ return 0;
60786+}
60787+
60788+int
60789+gr_search_accept(const struct socket *sock)
60790+{
60791+ return 0;
60792+}
60793+
60794+int
60795+gr_search_listen(const struct socket *sock)
60796+{
60797+ return 0;
60798+}
60799+
60800+int
60801+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
60802+{
60803+ return 0;
60804+}
60805+
60806+__u32
60807+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
60808+{
60809+ return 1;
60810+}
60811+
60812+__u32
60813+gr_acl_handle_creat(const struct dentry * dentry,
60814+ const struct dentry * p_dentry,
60815+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
60816+ const int imode)
60817+{
60818+ return 1;
60819+}
60820+
60821+void
60822+gr_acl_handle_exit(void)
60823+{
60824+ return;
60825+}
60826+
60827+int
60828+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
60829+{
60830+ return 1;
60831+}
60832+
60833+void
60834+gr_set_role_label(const uid_t uid, const gid_t gid)
60835+{
60836+ return;
60837+}
60838+
60839+int
60840+gr_acl_handle_procpidmem(const struct task_struct *task)
60841+{
60842+ return 0;
60843+}
60844+
60845+int
60846+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
60847+{
60848+ return 0;
60849+}
60850+
60851+int
60852+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
60853+{
60854+ return 0;
60855+}
60856+
60857+void
60858+gr_set_kernel_label(struct task_struct *task)
60859+{
60860+ return;
60861+}
60862+
60863+int
60864+gr_check_user_change(int real, int effective, int fs)
60865+{
60866+ return 0;
60867+}
60868+
60869+int
60870+gr_check_group_change(int real, int effective, int fs)
60871+{
60872+ return 0;
60873+}
60874+
60875+int gr_acl_enable_at_secure(void)
60876+{
60877+ return 0;
60878+}
60879+
60880+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
60881+{
60882+ return dentry->d_inode->i_sb->s_dev;
60883+}
60884+
60885+void gr_put_exec_file(struct task_struct *task)
60886+{
60887+ return;
60888+}
60889+
60890+EXPORT_SYMBOL(gr_set_kernel_label);
60891+#ifdef CONFIG_SECURITY
60892+EXPORT_SYMBOL(gr_check_user_change);
60893+EXPORT_SYMBOL(gr_check_group_change);
60894+#endif
60895diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
60896new file mode 100644
60897index 0000000..abfa971
60898--- /dev/null
60899+++ b/grsecurity/grsec_exec.c
60900@@ -0,0 +1,174 @@
60901+#include <linux/kernel.h>
60902+#include <linux/sched.h>
60903+#include <linux/file.h>
60904+#include <linux/binfmts.h>
60905+#include <linux/fs.h>
60906+#include <linux/types.h>
60907+#include <linux/grdefs.h>
60908+#include <linux/grsecurity.h>
60909+#include <linux/grinternal.h>
60910+#include <linux/capability.h>
60911+#include <linux/module.h>
60912+
60913+#include <asm/uaccess.h>
60914+
60915+#ifdef CONFIG_GRKERNSEC_EXECLOG
60916+static char gr_exec_arg_buf[132];
60917+static DEFINE_MUTEX(gr_exec_arg_mutex);
60918+#endif
60919+
60920+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
60921+
60922+void
60923+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
60924+{
60925+#ifdef CONFIG_GRKERNSEC_EXECLOG
60926+ char *grarg = gr_exec_arg_buf;
60927+ unsigned int i, x, execlen = 0;
60928+ char c;
60929+
60930+ if (!((grsec_enable_execlog && grsec_enable_group &&
60931+ in_group_p(grsec_audit_gid))
60932+ || (grsec_enable_execlog && !grsec_enable_group)))
60933+ return;
60934+
60935+ mutex_lock(&gr_exec_arg_mutex);
60936+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
60937+
60938+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
60939+ const char __user *p;
60940+ unsigned int len;
60941+
60942+ p = get_user_arg_ptr(argv, i);
60943+ if (IS_ERR(p))
60944+ goto log;
60945+
60946+ len = strnlen_user(p, 128 - execlen);
60947+ if (len > 128 - execlen)
60948+ len = 128 - execlen;
60949+ else if (len > 0)
60950+ len--;
60951+ if (copy_from_user(grarg + execlen, p, len))
60952+ goto log;
60953+
60954+ /* rewrite unprintable characters */
60955+ for (x = 0; x < len; x++) {
60956+ c = *(grarg + execlen + x);
60957+ if (c < 32 || c > 126)
60958+ *(grarg + execlen + x) = ' ';
60959+ }
60960+
60961+ execlen += len;
60962+ *(grarg + execlen) = ' ';
60963+ *(grarg + execlen + 1) = '\0';
60964+ execlen++;
60965+ }
60966+
60967+ log:
60968+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
60969+ bprm->file->f_path.mnt, grarg);
60970+ mutex_unlock(&gr_exec_arg_mutex);
60971+#endif
60972+ return;
60973+}
60974+
60975+#ifdef CONFIG_GRKERNSEC
60976+extern int gr_acl_is_capable(const int cap);
60977+extern int gr_acl_is_capable_nolog(const int cap);
60978+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
60979+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
60980+extern int gr_chroot_is_capable(const int cap);
60981+extern int gr_chroot_is_capable_nolog(const int cap);
60982+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
60983+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
60984+#endif
60985+
60986+const char *captab_log[] = {
60987+ "CAP_CHOWN",
60988+ "CAP_DAC_OVERRIDE",
60989+ "CAP_DAC_READ_SEARCH",
60990+ "CAP_FOWNER",
60991+ "CAP_FSETID",
60992+ "CAP_KILL",
60993+ "CAP_SETGID",
60994+ "CAP_SETUID",
60995+ "CAP_SETPCAP",
60996+ "CAP_LINUX_IMMUTABLE",
60997+ "CAP_NET_BIND_SERVICE",
60998+ "CAP_NET_BROADCAST",
60999+ "CAP_NET_ADMIN",
61000+ "CAP_NET_RAW",
61001+ "CAP_IPC_LOCK",
61002+ "CAP_IPC_OWNER",
61003+ "CAP_SYS_MODULE",
61004+ "CAP_SYS_RAWIO",
61005+ "CAP_SYS_CHROOT",
61006+ "CAP_SYS_PTRACE",
61007+ "CAP_SYS_PACCT",
61008+ "CAP_SYS_ADMIN",
61009+ "CAP_SYS_BOOT",
61010+ "CAP_SYS_NICE",
61011+ "CAP_SYS_RESOURCE",
61012+ "CAP_SYS_TIME",
61013+ "CAP_SYS_TTY_CONFIG",
61014+ "CAP_MKNOD",
61015+ "CAP_LEASE",
61016+ "CAP_AUDIT_WRITE",
61017+ "CAP_AUDIT_CONTROL",
61018+ "CAP_SETFCAP",
61019+ "CAP_MAC_OVERRIDE",
61020+ "CAP_MAC_ADMIN",
61021+ "CAP_SYSLOG",
61022+ "CAP_WAKE_ALARM"
61023+};
61024+
61025+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
61026+
61027+int gr_is_capable(const int cap)
61028+{
61029+#ifdef CONFIG_GRKERNSEC
61030+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
61031+ return 1;
61032+ return 0;
61033+#else
61034+ return 1;
61035+#endif
61036+}
61037+
61038+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
61039+{
61040+#ifdef CONFIG_GRKERNSEC
61041+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
61042+ return 1;
61043+ return 0;
61044+#else
61045+ return 1;
61046+#endif
61047+}
61048+
61049+int gr_is_capable_nolog(const int cap)
61050+{
61051+#ifdef CONFIG_GRKERNSEC
61052+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
61053+ return 1;
61054+ return 0;
61055+#else
61056+ return 1;
61057+#endif
61058+}
61059+
61060+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
61061+{
61062+#ifdef CONFIG_GRKERNSEC
61063+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
61064+ return 1;
61065+ return 0;
61066+#else
61067+ return 1;
61068+#endif
61069+}
61070+
61071+EXPORT_SYMBOL(gr_is_capable);
61072+EXPORT_SYMBOL(gr_is_capable_nolog);
61073+EXPORT_SYMBOL(gr_task_is_capable);
61074+EXPORT_SYMBOL(gr_task_is_capable_nolog);
61075diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
61076new file mode 100644
61077index 0000000..d3ee748
61078--- /dev/null
61079+++ b/grsecurity/grsec_fifo.c
61080@@ -0,0 +1,24 @@
61081+#include <linux/kernel.h>
61082+#include <linux/sched.h>
61083+#include <linux/fs.h>
61084+#include <linux/file.h>
61085+#include <linux/grinternal.h>
61086+
61087+int
61088+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
61089+ const struct dentry *dir, const int flag, const int acc_mode)
61090+{
61091+#ifdef CONFIG_GRKERNSEC_FIFO
61092+ const struct cred *cred = current_cred();
61093+
61094+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
61095+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
61096+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
61097+ (cred->fsuid != dentry->d_inode->i_uid)) {
61098+ if (!inode_permission(dentry->d_inode, acc_mode))
61099+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
61100+ return -EACCES;
61101+ }
61102+#endif
61103+ return 0;
61104+}
61105diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
61106new file mode 100644
61107index 0000000..8ca18bf
61108--- /dev/null
61109+++ b/grsecurity/grsec_fork.c
61110@@ -0,0 +1,23 @@
61111+#include <linux/kernel.h>
61112+#include <linux/sched.h>
61113+#include <linux/grsecurity.h>
61114+#include <linux/grinternal.h>
61115+#include <linux/errno.h>
61116+
61117+void
61118+gr_log_forkfail(const int retval)
61119+{
61120+#ifdef CONFIG_GRKERNSEC_FORKFAIL
61121+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
61122+ switch (retval) {
61123+ case -EAGAIN:
61124+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
61125+ break;
61126+ case -ENOMEM:
61127+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
61128+ break;
61129+ }
61130+ }
61131+#endif
61132+ return;
61133+}
61134diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
61135new file mode 100644
61136index 0000000..05a6015
61137--- /dev/null
61138+++ b/grsecurity/grsec_init.c
61139@@ -0,0 +1,283 @@
61140+#include <linux/kernel.h>
61141+#include <linux/sched.h>
61142+#include <linux/mm.h>
61143+#include <linux/gracl.h>
61144+#include <linux/slab.h>
61145+#include <linux/vmalloc.h>
61146+#include <linux/percpu.h>
61147+#include <linux/module.h>
61148+
61149+int grsec_enable_ptrace_readexec;
61150+int grsec_enable_setxid;
61151+int grsec_enable_symlinkown;
61152+int grsec_symlinkown_gid;
61153+int grsec_enable_brute;
61154+int grsec_enable_link;
61155+int grsec_enable_dmesg;
61156+int grsec_enable_harden_ptrace;
61157+int grsec_enable_fifo;
61158+int grsec_enable_execlog;
61159+int grsec_enable_signal;
61160+int grsec_enable_forkfail;
61161+int grsec_enable_audit_ptrace;
61162+int grsec_enable_time;
61163+int grsec_enable_audit_textrel;
61164+int grsec_enable_group;
61165+int grsec_audit_gid;
61166+int grsec_enable_chdir;
61167+int grsec_enable_mount;
61168+int grsec_enable_rofs;
61169+int grsec_enable_chroot_findtask;
61170+int grsec_enable_chroot_mount;
61171+int grsec_enable_chroot_shmat;
61172+int grsec_enable_chroot_fchdir;
61173+int grsec_enable_chroot_double;
61174+int grsec_enable_chroot_pivot;
61175+int grsec_enable_chroot_chdir;
61176+int grsec_enable_chroot_chmod;
61177+int grsec_enable_chroot_mknod;
61178+int grsec_enable_chroot_nice;
61179+int grsec_enable_chroot_execlog;
61180+int grsec_enable_chroot_caps;
61181+int grsec_enable_chroot_sysctl;
61182+int grsec_enable_chroot_unix;
61183+int grsec_enable_tpe;
61184+int grsec_tpe_gid;
61185+int grsec_enable_blackhole;
61186+#ifdef CONFIG_IPV6_MODULE
61187+EXPORT_SYMBOL(grsec_enable_blackhole);
61188+#endif
61189+int grsec_lastack_retries;
61190+int grsec_enable_tpe_all;
61191+int grsec_enable_tpe_invert;
61192+int grsec_enable_socket_all;
61193+int grsec_socket_all_gid;
61194+int grsec_enable_socket_client;
61195+int grsec_socket_client_gid;
61196+int grsec_enable_socket_server;
61197+int grsec_socket_server_gid;
61198+int grsec_resource_logging;
61199+int grsec_disable_privio;
61200+int grsec_enable_log_rwxmaps;
61201+int grsec_lock;
61202+
61203+DEFINE_SPINLOCK(grsec_alert_lock);
61204+unsigned long grsec_alert_wtime = 0;
61205+unsigned long grsec_alert_fyet = 0;
61206+
61207+DEFINE_SPINLOCK(grsec_audit_lock);
61208+
61209+DEFINE_RWLOCK(grsec_exec_file_lock);
61210+
61211+char *gr_shared_page[4];
61212+
61213+char *gr_alert_log_fmt;
61214+char *gr_audit_log_fmt;
61215+char *gr_alert_log_buf;
61216+char *gr_audit_log_buf;
61217+
61218+extern struct gr_arg *gr_usermode;
61219+extern unsigned char *gr_system_salt;
61220+extern unsigned char *gr_system_sum;
61221+
61222+void __init
61223+grsecurity_init(void)
61224+{
61225+ int j;
61226+ /* create the per-cpu shared pages */
61227+
61228+#ifdef CONFIG_X86
61229+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
61230+#endif
61231+
61232+ for (j = 0; j < 4; j++) {
61233+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
61234+ if (gr_shared_page[j] == NULL) {
61235+ panic("Unable to allocate grsecurity shared page");
61236+ return;
61237+ }
61238+ }
61239+
61240+ /* allocate log buffers */
61241+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
61242+ if (!gr_alert_log_fmt) {
61243+ panic("Unable to allocate grsecurity alert log format buffer");
61244+ return;
61245+ }
61246+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
61247+ if (!gr_audit_log_fmt) {
61248+ panic("Unable to allocate grsecurity audit log format buffer");
61249+ return;
61250+ }
61251+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
61252+ if (!gr_alert_log_buf) {
61253+ panic("Unable to allocate grsecurity alert log buffer");
61254+ return;
61255+ }
61256+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
61257+ if (!gr_audit_log_buf) {
61258+ panic("Unable to allocate grsecurity audit log buffer");
61259+ return;
61260+ }
61261+
61262+ /* allocate memory for authentication structure */
61263+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
61264+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
61265+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
61266+
61267+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
61268+ panic("Unable to allocate grsecurity authentication structure");
61269+ return;
61270+ }
61271+
61272+
61273+#ifdef CONFIG_GRKERNSEC_IO
61274+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
61275+ grsec_disable_privio = 1;
61276+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
61277+ grsec_disable_privio = 1;
61278+#else
61279+ grsec_disable_privio = 0;
61280+#endif
61281+#endif
61282+
61283+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
61284+ /* for backward compatibility, tpe_invert always defaults to on if
61285+ enabled in the kernel
61286+ */
61287+ grsec_enable_tpe_invert = 1;
61288+#endif
61289+
61290+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
61291+#ifndef CONFIG_GRKERNSEC_SYSCTL
61292+ grsec_lock = 1;
61293+#endif
61294+
61295+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
61296+ grsec_enable_audit_textrel = 1;
61297+#endif
61298+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61299+ grsec_enable_log_rwxmaps = 1;
61300+#endif
61301+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
61302+ grsec_enable_group = 1;
61303+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
61304+#endif
61305+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
61306+ grsec_enable_ptrace_readexec = 1;
61307+#endif
61308+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
61309+ grsec_enable_chdir = 1;
61310+#endif
61311+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61312+ grsec_enable_harden_ptrace = 1;
61313+#endif
61314+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61315+ grsec_enable_mount = 1;
61316+#endif
61317+#ifdef CONFIG_GRKERNSEC_LINK
61318+ grsec_enable_link = 1;
61319+#endif
61320+#ifdef CONFIG_GRKERNSEC_BRUTE
61321+ grsec_enable_brute = 1;
61322+#endif
61323+#ifdef CONFIG_GRKERNSEC_DMESG
61324+ grsec_enable_dmesg = 1;
61325+#endif
61326+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
61327+ grsec_enable_blackhole = 1;
61328+ grsec_lastack_retries = 4;
61329+#endif
61330+#ifdef CONFIG_GRKERNSEC_FIFO
61331+ grsec_enable_fifo = 1;
61332+#endif
61333+#ifdef CONFIG_GRKERNSEC_EXECLOG
61334+ grsec_enable_execlog = 1;
61335+#endif
61336+#ifdef CONFIG_GRKERNSEC_SETXID
61337+ grsec_enable_setxid = 1;
61338+#endif
61339+#ifdef CONFIG_GRKERNSEC_SIGNAL
61340+ grsec_enable_signal = 1;
61341+#endif
61342+#ifdef CONFIG_GRKERNSEC_FORKFAIL
61343+ grsec_enable_forkfail = 1;
61344+#endif
61345+#ifdef CONFIG_GRKERNSEC_TIME
61346+ grsec_enable_time = 1;
61347+#endif
61348+#ifdef CONFIG_GRKERNSEC_RESLOG
61349+ grsec_resource_logging = 1;
61350+#endif
61351+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61352+ grsec_enable_chroot_findtask = 1;
61353+#endif
61354+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
61355+ grsec_enable_chroot_unix = 1;
61356+#endif
61357+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
61358+ grsec_enable_chroot_mount = 1;
61359+#endif
61360+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
61361+ grsec_enable_chroot_fchdir = 1;
61362+#endif
61363+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
61364+ grsec_enable_chroot_shmat = 1;
61365+#endif
61366+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
61367+ grsec_enable_audit_ptrace = 1;
61368+#endif
61369+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
61370+ grsec_enable_chroot_double = 1;
61371+#endif
61372+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
61373+ grsec_enable_chroot_pivot = 1;
61374+#endif
61375+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
61376+ grsec_enable_chroot_chdir = 1;
61377+#endif
61378+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
61379+ grsec_enable_chroot_chmod = 1;
61380+#endif
61381+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
61382+ grsec_enable_chroot_mknod = 1;
61383+#endif
61384+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
61385+ grsec_enable_chroot_nice = 1;
61386+#endif
61387+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
61388+ grsec_enable_chroot_execlog = 1;
61389+#endif
61390+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
61391+ grsec_enable_chroot_caps = 1;
61392+#endif
61393+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
61394+ grsec_enable_chroot_sysctl = 1;
61395+#endif
61396+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
61397+ grsec_enable_symlinkown = 1;
61398+ grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
61399+#endif
61400+#ifdef CONFIG_GRKERNSEC_TPE
61401+ grsec_enable_tpe = 1;
61402+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
61403+#ifdef CONFIG_GRKERNSEC_TPE_ALL
61404+ grsec_enable_tpe_all = 1;
61405+#endif
61406+#endif
61407+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
61408+ grsec_enable_socket_all = 1;
61409+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
61410+#endif
61411+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
61412+ grsec_enable_socket_client = 1;
61413+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
61414+#endif
61415+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61416+ grsec_enable_socket_server = 1;
61417+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
61418+#endif
61419+#endif
61420+
61421+ return;
61422+}
61423diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
61424new file mode 100644
61425index 0000000..6095407
61426--- /dev/null
61427+++ b/grsecurity/grsec_link.c
61428@@ -0,0 +1,58 @@
61429+#include <linux/kernel.h>
61430+#include <linux/sched.h>
61431+#include <linux/fs.h>
61432+#include <linux/file.h>
61433+#include <linux/grinternal.h>
61434+
61435+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
61436+{
61437+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
61438+ const struct inode *link_inode = link->dentry->d_inode;
61439+
61440+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
61441+ /* ignore root-owned links, e.g. /proc/self */
61442+ !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
61443+ !uid_eq(link_inode->i_uid, target->i_uid)) {
61444+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
61445+ return 1;
61446+ }
61447+#endif
61448+ return 0;
61449+}
61450+
61451+int
61452+gr_handle_follow_link(const struct inode *parent,
61453+ const struct inode *inode,
61454+ const struct dentry *dentry, const struct vfsmount *mnt)
61455+{
61456+#ifdef CONFIG_GRKERNSEC_LINK
61457+ const struct cred *cred = current_cred();
61458+
61459+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
61460+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
61461+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
61462+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
61463+ return -EACCES;
61464+ }
61465+#endif
61466+ return 0;
61467+}
61468+
61469+int
61470+gr_handle_hardlink(const struct dentry *dentry,
61471+ const struct vfsmount *mnt,
61472+ struct inode *inode, const int mode, const struct filename *to)
61473+{
61474+#ifdef CONFIG_GRKERNSEC_LINK
61475+ const struct cred *cred = current_cred();
61476+
61477+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
61478+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
61479+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
61480+ !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
61481+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
61482+ return -EPERM;
61483+ }
61484+#endif
61485+ return 0;
61486+}
61487diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
61488new file mode 100644
61489index 0000000..7bd6c2b
61490--- /dev/null
61491+++ b/grsecurity/grsec_log.c
61492@@ -0,0 +1,329 @@
61493+#include <linux/kernel.h>
61494+#include <linux/sched.h>
61495+#include <linux/file.h>
61496+#include <linux/tty.h>
61497+#include <linux/fs.h>
61498+#include <linux/grinternal.h>
61499+
61500+#ifdef CONFIG_TREE_PREEMPT_RCU
61501+#define DISABLE_PREEMPT() preempt_disable()
61502+#define ENABLE_PREEMPT() preempt_enable()
61503+#else
61504+#define DISABLE_PREEMPT()
61505+#define ENABLE_PREEMPT()
61506+#endif
61507+
61508+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
61509+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
61510+
61511+#define BEGIN_LOCKS(x) \
61512+ DISABLE_PREEMPT(); \
61513+ rcu_read_lock(); \
61514+ read_lock(&tasklist_lock); \
61515+ read_lock(&grsec_exec_file_lock); \
61516+ if (x != GR_DO_AUDIT) \
61517+ spin_lock(&grsec_alert_lock); \
61518+ else \
61519+ spin_lock(&grsec_audit_lock)
61520+
61521+#define END_LOCKS(x) \
61522+ if (x != GR_DO_AUDIT) \
61523+ spin_unlock(&grsec_alert_lock); \
61524+ else \
61525+ spin_unlock(&grsec_audit_lock); \
61526+ read_unlock(&grsec_exec_file_lock); \
61527+ read_unlock(&tasklist_lock); \
61528+ rcu_read_unlock(); \
61529+ ENABLE_PREEMPT(); \
61530+ if (x == GR_DONT_AUDIT) \
61531+ gr_handle_alertkill(current)
61532+
61533+enum {
61534+ FLOODING,
61535+ NO_FLOODING
61536+};
61537+
61538+extern char *gr_alert_log_fmt;
61539+extern char *gr_audit_log_fmt;
61540+extern char *gr_alert_log_buf;
61541+extern char *gr_audit_log_buf;
61542+
61543+static int gr_log_start(int audit)
61544+{
61545+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
61546+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
61547+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
61548+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
61549+ unsigned long curr_secs = get_seconds();
61550+
61551+ if (audit == GR_DO_AUDIT)
61552+ goto set_fmt;
61553+
61554+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
61555+ grsec_alert_wtime = curr_secs;
61556+ grsec_alert_fyet = 0;
61557+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
61558+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
61559+ grsec_alert_fyet++;
61560+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
61561+ grsec_alert_wtime = curr_secs;
61562+ grsec_alert_fyet++;
61563+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
61564+ return FLOODING;
61565+ }
61566+ else return FLOODING;
61567+
61568+set_fmt:
61569+#endif
61570+ memset(buf, 0, PAGE_SIZE);
61571+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
61572+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
61573+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
61574+ } else if (current->signal->curr_ip) {
61575+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
61576+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
61577+ } else if (gr_acl_is_enabled()) {
61578+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
61579+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
61580+ } else {
61581+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
61582+ strcpy(buf, fmt);
61583+ }
61584+
61585+ return NO_FLOODING;
61586+}
61587+
61588+static void gr_log_middle(int audit, const char *msg, va_list ap)
61589+ __attribute__ ((format (printf, 2, 0)));
61590+
61591+static void gr_log_middle(int audit, const char *msg, va_list ap)
61592+{
61593+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
61594+ unsigned int len = strlen(buf);
61595+
61596+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
61597+
61598+ return;
61599+}
61600+
61601+static void gr_log_middle_varargs(int audit, const char *msg, ...)
61602+ __attribute__ ((format (printf, 2, 3)));
61603+
61604+static void gr_log_middle_varargs(int audit, const char *msg, ...)
61605+{
61606+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
61607+ unsigned int len = strlen(buf);
61608+ va_list ap;
61609+
61610+ va_start(ap, msg);
61611+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
61612+ va_end(ap);
61613+
61614+ return;
61615+}
61616+
61617+static void gr_log_end(int audit, int append_default)
61618+{
61619+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
61620+ if (append_default) {
61621+ struct task_struct *task = current;
61622+ struct task_struct *parent = task->real_parent;
61623+ const struct cred *cred = __task_cred(task);
61624+ const struct cred *pcred = __task_cred(parent);
61625+ unsigned int len = strlen(buf);
61626+
61627+ 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));
61628+ }
61629+
61630+ printk("%s\n", buf);
61631+
61632+ return;
61633+}
61634+
61635+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
61636+{
61637+ int logtype;
61638+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
61639+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
61640+ void *voidptr = NULL;
61641+ int num1 = 0, num2 = 0;
61642+ unsigned long ulong1 = 0, ulong2 = 0;
61643+ struct dentry *dentry = NULL;
61644+ struct vfsmount *mnt = NULL;
61645+ struct file *file = NULL;
61646+ struct task_struct *task = NULL;
61647+ const struct cred *cred, *pcred;
61648+ va_list ap;
61649+
61650+ BEGIN_LOCKS(audit);
61651+ logtype = gr_log_start(audit);
61652+ if (logtype == FLOODING) {
61653+ END_LOCKS(audit);
61654+ return;
61655+ }
61656+ va_start(ap, argtypes);
61657+ switch (argtypes) {
61658+ case GR_TTYSNIFF:
61659+ task = va_arg(ap, struct task_struct *);
61660+ 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));
61661+ break;
61662+ case GR_SYSCTL_HIDDEN:
61663+ str1 = va_arg(ap, char *);
61664+ gr_log_middle_varargs(audit, msg, result, str1);
61665+ break;
61666+ case GR_RBAC:
61667+ dentry = va_arg(ap, struct dentry *);
61668+ mnt = va_arg(ap, struct vfsmount *);
61669+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
61670+ break;
61671+ case GR_RBAC_STR:
61672+ dentry = va_arg(ap, struct dentry *);
61673+ mnt = va_arg(ap, struct vfsmount *);
61674+ str1 = va_arg(ap, char *);
61675+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
61676+ break;
61677+ case GR_STR_RBAC:
61678+ str1 = va_arg(ap, char *);
61679+ dentry = va_arg(ap, struct dentry *);
61680+ mnt = va_arg(ap, struct vfsmount *);
61681+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
61682+ break;
61683+ case GR_RBAC_MODE2:
61684+ dentry = va_arg(ap, struct dentry *);
61685+ mnt = va_arg(ap, struct vfsmount *);
61686+ str1 = va_arg(ap, char *);
61687+ str2 = va_arg(ap, char *);
61688+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
61689+ break;
61690+ case GR_RBAC_MODE3:
61691+ dentry = va_arg(ap, struct dentry *);
61692+ mnt = va_arg(ap, struct vfsmount *);
61693+ str1 = va_arg(ap, char *);
61694+ str2 = va_arg(ap, char *);
61695+ str3 = va_arg(ap, char *);
61696+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
61697+ break;
61698+ case GR_FILENAME:
61699+ dentry = va_arg(ap, struct dentry *);
61700+ mnt = va_arg(ap, struct vfsmount *);
61701+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
61702+ break;
61703+ case GR_STR_FILENAME:
61704+ str1 = va_arg(ap, char *);
61705+ dentry = va_arg(ap, struct dentry *);
61706+ mnt = va_arg(ap, struct vfsmount *);
61707+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
61708+ break;
61709+ case GR_FILENAME_STR:
61710+ dentry = va_arg(ap, struct dentry *);
61711+ mnt = va_arg(ap, struct vfsmount *);
61712+ str1 = va_arg(ap, char *);
61713+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
61714+ break;
61715+ case GR_FILENAME_TWO_INT:
61716+ dentry = va_arg(ap, struct dentry *);
61717+ mnt = va_arg(ap, struct vfsmount *);
61718+ num1 = va_arg(ap, int);
61719+ num2 = va_arg(ap, int);
61720+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
61721+ break;
61722+ case GR_FILENAME_TWO_INT_STR:
61723+ dentry = va_arg(ap, struct dentry *);
61724+ mnt = va_arg(ap, struct vfsmount *);
61725+ num1 = va_arg(ap, int);
61726+ num2 = va_arg(ap, int);
61727+ str1 = va_arg(ap, char *);
61728+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
61729+ break;
61730+ case GR_TEXTREL:
61731+ file = va_arg(ap, struct file *);
61732+ ulong1 = va_arg(ap, unsigned long);
61733+ ulong2 = va_arg(ap, unsigned long);
61734+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
61735+ break;
61736+ case GR_PTRACE:
61737+ task = va_arg(ap, struct task_struct *);
61738+ 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));
61739+ break;
61740+ case GR_RESOURCE:
61741+ task = va_arg(ap, struct task_struct *);
61742+ cred = __task_cred(task);
61743+ pcred = __task_cred(task->real_parent);
61744+ ulong1 = va_arg(ap, unsigned long);
61745+ str1 = va_arg(ap, char *);
61746+ ulong2 = va_arg(ap, unsigned long);
61747+ 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));
61748+ break;
61749+ case GR_CAP:
61750+ task = va_arg(ap, struct task_struct *);
61751+ cred = __task_cred(task);
61752+ pcred = __task_cred(task->real_parent);
61753+ str1 = va_arg(ap, char *);
61754+ 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));
61755+ break;
61756+ case GR_SIG:
61757+ str1 = va_arg(ap, char *);
61758+ voidptr = va_arg(ap, void *);
61759+ gr_log_middle_varargs(audit, msg, str1, voidptr);
61760+ break;
61761+ case GR_SIG2:
61762+ task = va_arg(ap, struct task_struct *);
61763+ cred = __task_cred(task);
61764+ pcred = __task_cred(task->real_parent);
61765+ num1 = va_arg(ap, int);
61766+ 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));
61767+ break;
61768+ case GR_CRASH1:
61769+ task = va_arg(ap, struct task_struct *);
61770+ cred = __task_cred(task);
61771+ pcred = __task_cred(task->real_parent);
61772+ ulong1 = va_arg(ap, unsigned long);
61773+ 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);
61774+ break;
61775+ case GR_CRASH2:
61776+ task = va_arg(ap, struct task_struct *);
61777+ cred = __task_cred(task);
61778+ pcred = __task_cred(task->real_parent);
61779+ ulong1 = va_arg(ap, unsigned long);
61780+ 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);
61781+ break;
61782+ case GR_RWXMAP:
61783+ file = va_arg(ap, struct file *);
61784+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
61785+ break;
61786+ case GR_PSACCT:
61787+ {
61788+ unsigned int wday, cday;
61789+ __u8 whr, chr;
61790+ __u8 wmin, cmin;
61791+ __u8 wsec, csec;
61792+ char cur_tty[64] = { 0 };
61793+ char parent_tty[64] = { 0 };
61794+
61795+ task = va_arg(ap, struct task_struct *);
61796+ wday = va_arg(ap, unsigned int);
61797+ cday = va_arg(ap, unsigned int);
61798+ whr = va_arg(ap, int);
61799+ chr = va_arg(ap, int);
61800+ wmin = va_arg(ap, int);
61801+ cmin = va_arg(ap, int);
61802+ wsec = va_arg(ap, int);
61803+ csec = va_arg(ap, int);
61804+ ulong1 = va_arg(ap, unsigned long);
61805+ cred = __task_cred(task);
61806+ pcred = __task_cred(task->real_parent);
61807+
61808+ 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));
61809+ }
61810+ break;
61811+ default:
61812+ gr_log_middle(audit, msg, ap);
61813+ }
61814+ va_end(ap);
61815+ // these don't need DEFAULTSECARGS printed on the end
61816+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
61817+ gr_log_end(audit, 0);
61818+ else
61819+ gr_log_end(audit, 1);
61820+ END_LOCKS(audit);
61821+}
61822diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
61823new file mode 100644
61824index 0000000..f536303
61825--- /dev/null
61826+++ b/grsecurity/grsec_mem.c
61827@@ -0,0 +1,40 @@
61828+#include <linux/kernel.h>
61829+#include <linux/sched.h>
61830+#include <linux/mm.h>
61831+#include <linux/mman.h>
61832+#include <linux/grinternal.h>
61833+
61834+void
61835+gr_handle_ioperm(void)
61836+{
61837+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
61838+ return;
61839+}
61840+
61841+void
61842+gr_handle_iopl(void)
61843+{
61844+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
61845+ return;
61846+}
61847+
61848+void
61849+gr_handle_mem_readwrite(u64 from, u64 to)
61850+{
61851+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
61852+ return;
61853+}
61854+
61855+void
61856+gr_handle_vm86(void)
61857+{
61858+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
61859+ return;
61860+}
61861+
61862+void
61863+gr_log_badprocpid(const char *entry)
61864+{
61865+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
61866+ return;
61867+}
61868diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
61869new file mode 100644
61870index 0000000..2131422
61871--- /dev/null
61872+++ b/grsecurity/grsec_mount.c
61873@@ -0,0 +1,62 @@
61874+#include <linux/kernel.h>
61875+#include <linux/sched.h>
61876+#include <linux/mount.h>
61877+#include <linux/grsecurity.h>
61878+#include <linux/grinternal.h>
61879+
61880+void
61881+gr_log_remount(const char *devname, const int retval)
61882+{
61883+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61884+ if (grsec_enable_mount && (retval >= 0))
61885+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
61886+#endif
61887+ return;
61888+}
61889+
61890+void
61891+gr_log_unmount(const char *devname, const int retval)
61892+{
61893+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61894+ if (grsec_enable_mount && (retval >= 0))
61895+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
61896+#endif
61897+ return;
61898+}
61899+
61900+void
61901+gr_log_mount(const char *from, const char *to, const int retval)
61902+{
61903+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61904+ if (grsec_enable_mount && (retval >= 0))
61905+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
61906+#endif
61907+ return;
61908+}
61909+
61910+int
61911+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
61912+{
61913+#ifdef CONFIG_GRKERNSEC_ROFS
61914+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
61915+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
61916+ return -EPERM;
61917+ } else
61918+ return 0;
61919+#endif
61920+ return 0;
61921+}
61922+
61923+int
61924+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
61925+{
61926+#ifdef CONFIG_GRKERNSEC_ROFS
61927+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
61928+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
61929+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
61930+ return -EPERM;
61931+ } else
61932+ return 0;
61933+#endif
61934+ return 0;
61935+}
61936diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
61937new file mode 100644
61938index 0000000..a3b12a0
61939--- /dev/null
61940+++ b/grsecurity/grsec_pax.c
61941@@ -0,0 +1,36 @@
61942+#include <linux/kernel.h>
61943+#include <linux/sched.h>
61944+#include <linux/mm.h>
61945+#include <linux/file.h>
61946+#include <linux/grinternal.h>
61947+#include <linux/grsecurity.h>
61948+
61949+void
61950+gr_log_textrel(struct vm_area_struct * vma)
61951+{
61952+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
61953+ if (grsec_enable_audit_textrel)
61954+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
61955+#endif
61956+ return;
61957+}
61958+
61959+void
61960+gr_log_rwxmmap(struct file *file)
61961+{
61962+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61963+ if (grsec_enable_log_rwxmaps)
61964+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
61965+#endif
61966+ return;
61967+}
61968+
61969+void
61970+gr_log_rwxmprotect(struct file *file)
61971+{
61972+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61973+ if (grsec_enable_log_rwxmaps)
61974+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
61975+#endif
61976+ return;
61977+}
61978diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
61979new file mode 100644
61980index 0000000..f7f29aa
61981--- /dev/null
61982+++ b/grsecurity/grsec_ptrace.c
61983@@ -0,0 +1,30 @@
61984+#include <linux/kernel.h>
61985+#include <linux/sched.h>
61986+#include <linux/grinternal.h>
61987+#include <linux/security.h>
61988+
61989+void
61990+gr_audit_ptrace(struct task_struct *task)
61991+{
61992+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
61993+ if (grsec_enable_audit_ptrace)
61994+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
61995+#endif
61996+ return;
61997+}
61998+
61999+int
62000+gr_ptrace_readexec(struct file *file, int unsafe_flags)
62001+{
62002+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
62003+ const struct dentry *dentry = file->f_path.dentry;
62004+ const struct vfsmount *mnt = file->f_path.mnt;
62005+
62006+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
62007+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
62008+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
62009+ return -EACCES;
62010+ }
62011+#endif
62012+ return 0;
62013+}
62014diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
62015new file mode 100644
62016index 0000000..5c00416
62017--- /dev/null
62018+++ b/grsecurity/grsec_sig.c
62019@@ -0,0 +1,222 @@
62020+#include <linux/kernel.h>
62021+#include <linux/sched.h>
62022+#include <linux/delay.h>
62023+#include <linux/grsecurity.h>
62024+#include <linux/grinternal.h>
62025+#include <linux/hardirq.h>
62026+
62027+char *signames[] = {
62028+ [SIGSEGV] = "Segmentation fault",
62029+ [SIGILL] = "Illegal instruction",
62030+ [SIGABRT] = "Abort",
62031+ [SIGBUS] = "Invalid alignment/Bus error"
62032+};
62033+
62034+void
62035+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
62036+{
62037+#ifdef CONFIG_GRKERNSEC_SIGNAL
62038+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
62039+ (sig == SIGABRT) || (sig == SIGBUS))) {
62040+ if (t->pid == current->pid) {
62041+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
62042+ } else {
62043+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
62044+ }
62045+ }
62046+#endif
62047+ return;
62048+}
62049+
62050+int
62051+gr_handle_signal(const struct task_struct *p, const int sig)
62052+{
62053+#ifdef CONFIG_GRKERNSEC
62054+ /* ignore the 0 signal for protected task checks */
62055+ if (current->pid > 1 && sig && gr_check_protected_task(p)) {
62056+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
62057+ return -EPERM;
62058+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
62059+ return -EPERM;
62060+ }
62061+#endif
62062+ return 0;
62063+}
62064+
62065+#ifdef CONFIG_GRKERNSEC
62066+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
62067+
62068+int gr_fake_force_sig(int sig, struct task_struct *t)
62069+{
62070+ unsigned long int flags;
62071+ int ret, blocked, ignored;
62072+ struct k_sigaction *action;
62073+
62074+ spin_lock_irqsave(&t->sighand->siglock, flags);
62075+ action = &t->sighand->action[sig-1];
62076+ ignored = action->sa.sa_handler == SIG_IGN;
62077+ blocked = sigismember(&t->blocked, sig);
62078+ if (blocked || ignored) {
62079+ action->sa.sa_handler = SIG_DFL;
62080+ if (blocked) {
62081+ sigdelset(&t->blocked, sig);
62082+ recalc_sigpending_and_wake(t);
62083+ }
62084+ }
62085+ if (action->sa.sa_handler == SIG_DFL)
62086+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
62087+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
62088+
62089+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
62090+
62091+ return ret;
62092+}
62093+#endif
62094+
62095+#ifdef CONFIG_GRKERNSEC_BRUTE
62096+#define GR_USER_BAN_TIME (15 * 60)
62097+#define GR_DAEMON_BRUTE_TIME (30 * 60)
62098+
62099+static int __get_dumpable(unsigned long mm_flags)
62100+{
62101+ int ret;
62102+
62103+ ret = mm_flags & MMF_DUMPABLE_MASK;
62104+ return (ret >= 2) ? 2 : ret;
62105+}
62106+#endif
62107+
62108+void gr_handle_brute_attach(unsigned long mm_flags)
62109+{
62110+#ifdef CONFIG_GRKERNSEC_BRUTE
62111+ struct task_struct *p = current;
62112+ kuid_t uid = GLOBAL_ROOT_UID;
62113+ int daemon = 0;
62114+
62115+ if (!grsec_enable_brute)
62116+ return;
62117+
62118+ rcu_read_lock();
62119+ read_lock(&tasklist_lock);
62120+ read_lock(&grsec_exec_file_lock);
62121+ if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
62122+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
62123+ p->real_parent->brute = 1;
62124+ daemon = 1;
62125+ } else {
62126+ const struct cred *cred = __task_cred(p), *cred2;
62127+ struct task_struct *tsk, *tsk2;
62128+
62129+ if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
62130+ struct user_struct *user;
62131+
62132+ uid = cred->uid;
62133+
62134+ /* this is put upon execution past expiration */
62135+ user = find_user(uid);
62136+ if (user == NULL)
62137+ goto unlock;
62138+ user->banned = 1;
62139+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
62140+ if (user->ban_expires == ~0UL)
62141+ user->ban_expires--;
62142+
62143+ do_each_thread(tsk2, tsk) {
62144+ cred2 = __task_cred(tsk);
62145+ if (tsk != p && uid_eq(cred2->uid, uid))
62146+ gr_fake_force_sig(SIGKILL, tsk);
62147+ } while_each_thread(tsk2, tsk);
62148+ }
62149+ }
62150+unlock:
62151+ read_unlock(&grsec_exec_file_lock);
62152+ read_unlock(&tasklist_lock);
62153+ rcu_read_unlock();
62154+
62155+ if (!uid_eq(uid, GLOBAL_ROOT_UID))
62156+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
62157+ from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
62158+ else if (daemon)
62159+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
62160+
62161+#endif
62162+ return;
62163+}
62164+
62165+void gr_handle_brute_check(void)
62166+{
62167+#ifdef CONFIG_GRKERNSEC_BRUTE
62168+ struct task_struct *p = current;
62169+
62170+ if (unlikely(p->brute)) {
62171+ if (!grsec_enable_brute)
62172+ p->brute = 0;
62173+ else if (time_before(get_seconds(), p->brute_expires))
62174+ msleep(30 * 1000);
62175+ }
62176+#endif
62177+ return;
62178+}
62179+
62180+void gr_handle_kernel_exploit(void)
62181+{
62182+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
62183+ const struct cred *cred;
62184+ struct task_struct *tsk, *tsk2;
62185+ struct user_struct *user;
62186+ kuid_t uid;
62187+
62188+ if (in_irq() || in_serving_softirq() || in_nmi())
62189+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
62190+
62191+ uid = current_uid();
62192+
62193+ if (uid_eq(uid, GLOBAL_ROOT_UID))
62194+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
62195+ else {
62196+ /* kill all the processes of this user, hold a reference
62197+ to their creds struct, and prevent them from creating
62198+ another process until system reset
62199+ */
62200+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
62201+ from_kuid_munged(&init_user_ns, uid));
62202+ /* we intentionally leak this ref */
62203+ user = get_uid(current->cred->user);
62204+ if (user) {
62205+ user->banned = 1;
62206+ user->ban_expires = ~0UL;
62207+ }
62208+
62209+ read_lock(&tasklist_lock);
62210+ do_each_thread(tsk2, tsk) {
62211+ cred = __task_cred(tsk);
62212+ if (uid_eq(cred->uid, uid))
62213+ gr_fake_force_sig(SIGKILL, tsk);
62214+ } while_each_thread(tsk2, tsk);
62215+ read_unlock(&tasklist_lock);
62216+ }
62217+#endif
62218+}
62219+
62220+int __gr_process_user_ban(struct user_struct *user)
62221+{
62222+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
62223+ if (unlikely(user->banned)) {
62224+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
62225+ user->banned = 0;
62226+ user->ban_expires = 0;
62227+ free_uid(user);
62228+ } else
62229+ return -EPERM;
62230+ }
62231+#endif
62232+ return 0;
62233+}
62234+
62235+int gr_process_user_ban(void)
62236+{
62237+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
62238+ return __gr_process_user_ban(current->cred->user);
62239+#endif
62240+ return 0;
62241+}
62242diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
62243new file mode 100644
62244index 0000000..4030d57
62245--- /dev/null
62246+++ b/grsecurity/grsec_sock.c
62247@@ -0,0 +1,244 @@
62248+#include <linux/kernel.h>
62249+#include <linux/module.h>
62250+#include <linux/sched.h>
62251+#include <linux/file.h>
62252+#include <linux/net.h>
62253+#include <linux/in.h>
62254+#include <linux/ip.h>
62255+#include <net/sock.h>
62256+#include <net/inet_sock.h>
62257+#include <linux/grsecurity.h>
62258+#include <linux/grinternal.h>
62259+#include <linux/gracl.h>
62260+
62261+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
62262+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
62263+
62264+EXPORT_SYMBOL(gr_search_udp_recvmsg);
62265+EXPORT_SYMBOL(gr_search_udp_sendmsg);
62266+
62267+#ifdef CONFIG_UNIX_MODULE
62268+EXPORT_SYMBOL(gr_acl_handle_unix);
62269+EXPORT_SYMBOL(gr_acl_handle_mknod);
62270+EXPORT_SYMBOL(gr_handle_chroot_unix);
62271+EXPORT_SYMBOL(gr_handle_create);
62272+#endif
62273+
62274+#ifdef CONFIG_GRKERNSEC
62275+#define gr_conn_table_size 32749
62276+struct conn_table_entry {
62277+ struct conn_table_entry *next;
62278+ struct signal_struct *sig;
62279+};
62280+
62281+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
62282+DEFINE_SPINLOCK(gr_conn_table_lock);
62283+
62284+extern const char * gr_socktype_to_name(unsigned char type);
62285+extern const char * gr_proto_to_name(unsigned char proto);
62286+extern const char * gr_sockfamily_to_name(unsigned char family);
62287+
62288+static __inline__ int
62289+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
62290+{
62291+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
62292+}
62293+
62294+static __inline__ int
62295+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
62296+ __u16 sport, __u16 dport)
62297+{
62298+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
62299+ sig->gr_sport == sport && sig->gr_dport == dport))
62300+ return 1;
62301+ else
62302+ return 0;
62303+}
62304+
62305+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
62306+{
62307+ struct conn_table_entry **match;
62308+ unsigned int index;
62309+
62310+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
62311+ sig->gr_sport, sig->gr_dport,
62312+ gr_conn_table_size);
62313+
62314+ newent->sig = sig;
62315+
62316+ match = &gr_conn_table[index];
62317+ newent->next = *match;
62318+ *match = newent;
62319+
62320+ return;
62321+}
62322+
62323+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
62324+{
62325+ struct conn_table_entry *match, *last = NULL;
62326+ unsigned int index;
62327+
62328+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
62329+ sig->gr_sport, sig->gr_dport,
62330+ gr_conn_table_size);
62331+
62332+ match = gr_conn_table[index];
62333+ while (match && !conn_match(match->sig,
62334+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
62335+ sig->gr_dport)) {
62336+ last = match;
62337+ match = match->next;
62338+ }
62339+
62340+ if (match) {
62341+ if (last)
62342+ last->next = match->next;
62343+ else
62344+ gr_conn_table[index] = NULL;
62345+ kfree(match);
62346+ }
62347+
62348+ return;
62349+}
62350+
62351+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
62352+ __u16 sport, __u16 dport)
62353+{
62354+ struct conn_table_entry *match;
62355+ unsigned int index;
62356+
62357+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
62358+
62359+ match = gr_conn_table[index];
62360+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
62361+ match = match->next;
62362+
62363+ if (match)
62364+ return match->sig;
62365+ else
62366+ return NULL;
62367+}
62368+
62369+#endif
62370+
62371+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
62372+{
62373+#ifdef CONFIG_GRKERNSEC
62374+ struct signal_struct *sig = task->signal;
62375+ struct conn_table_entry *newent;
62376+
62377+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
62378+ if (newent == NULL)
62379+ return;
62380+ /* no bh lock needed since we are called with bh disabled */
62381+ spin_lock(&gr_conn_table_lock);
62382+ gr_del_task_from_ip_table_nolock(sig);
62383+ sig->gr_saddr = inet->inet_rcv_saddr;
62384+ sig->gr_daddr = inet->inet_daddr;
62385+ sig->gr_sport = inet->inet_sport;
62386+ sig->gr_dport = inet->inet_dport;
62387+ gr_add_to_task_ip_table_nolock(sig, newent);
62388+ spin_unlock(&gr_conn_table_lock);
62389+#endif
62390+ return;
62391+}
62392+
62393+void gr_del_task_from_ip_table(struct task_struct *task)
62394+{
62395+#ifdef CONFIG_GRKERNSEC
62396+ spin_lock_bh(&gr_conn_table_lock);
62397+ gr_del_task_from_ip_table_nolock(task->signal);
62398+ spin_unlock_bh(&gr_conn_table_lock);
62399+#endif
62400+ return;
62401+}
62402+
62403+void
62404+gr_attach_curr_ip(const struct sock *sk)
62405+{
62406+#ifdef CONFIG_GRKERNSEC
62407+ struct signal_struct *p, *set;
62408+ const struct inet_sock *inet = inet_sk(sk);
62409+
62410+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
62411+ return;
62412+
62413+ set = current->signal;
62414+
62415+ spin_lock_bh(&gr_conn_table_lock);
62416+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
62417+ inet->inet_dport, inet->inet_sport);
62418+ if (unlikely(p != NULL)) {
62419+ set->curr_ip = p->curr_ip;
62420+ set->used_accept = 1;
62421+ gr_del_task_from_ip_table_nolock(p);
62422+ spin_unlock_bh(&gr_conn_table_lock);
62423+ return;
62424+ }
62425+ spin_unlock_bh(&gr_conn_table_lock);
62426+
62427+ set->curr_ip = inet->inet_daddr;
62428+ set->used_accept = 1;
62429+#endif
62430+ return;
62431+}
62432+
62433+int
62434+gr_handle_sock_all(const int family, const int type, const int protocol)
62435+{
62436+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
62437+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
62438+ (family != AF_UNIX)) {
62439+ if (family == AF_INET)
62440+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
62441+ else
62442+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
62443+ return -EACCES;
62444+ }
62445+#endif
62446+ return 0;
62447+}
62448+
62449+int
62450+gr_handle_sock_server(const struct sockaddr *sck)
62451+{
62452+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
62453+ if (grsec_enable_socket_server &&
62454+ in_group_p(grsec_socket_server_gid) &&
62455+ sck && (sck->sa_family != AF_UNIX) &&
62456+ (sck->sa_family != AF_LOCAL)) {
62457+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
62458+ return -EACCES;
62459+ }
62460+#endif
62461+ return 0;
62462+}
62463+
62464+int
62465+gr_handle_sock_server_other(const struct sock *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->sk_family != AF_UNIX) &&
62471+ (sck->sk_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_client(const struct sockaddr *sck)
62481+{
62482+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
62483+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
62484+ sck && (sck->sa_family != AF_UNIX) &&
62485+ (sck->sa_family != AF_LOCAL)) {
62486+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
62487+ return -EACCES;
62488+ }
62489+#endif
62490+ return 0;
62491+}
62492diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
62493new file mode 100644
62494index 0000000..f55ef0f
62495--- /dev/null
62496+++ b/grsecurity/grsec_sysctl.c
62497@@ -0,0 +1,469 @@
62498+#include <linux/kernel.h>
62499+#include <linux/sched.h>
62500+#include <linux/sysctl.h>
62501+#include <linux/grsecurity.h>
62502+#include <linux/grinternal.h>
62503+
62504+int
62505+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
62506+{
62507+#ifdef CONFIG_GRKERNSEC_SYSCTL
62508+ if (dirname == NULL || name == NULL)
62509+ return 0;
62510+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
62511+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
62512+ return -EACCES;
62513+ }
62514+#endif
62515+ return 0;
62516+}
62517+
62518+#ifdef CONFIG_GRKERNSEC_ROFS
62519+static int __maybe_unused one = 1;
62520+#endif
62521+
62522+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
62523+struct ctl_table grsecurity_table[] = {
62524+#ifdef CONFIG_GRKERNSEC_SYSCTL
62525+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
62526+#ifdef CONFIG_GRKERNSEC_IO
62527+ {
62528+ .procname = "disable_priv_io",
62529+ .data = &grsec_disable_privio,
62530+ .maxlen = sizeof(int),
62531+ .mode = 0600,
62532+ .proc_handler = &proc_dointvec,
62533+ },
62534+#endif
62535+#endif
62536+#ifdef CONFIG_GRKERNSEC_LINK
62537+ {
62538+ .procname = "linking_restrictions",
62539+ .data = &grsec_enable_link,
62540+ .maxlen = sizeof(int),
62541+ .mode = 0600,
62542+ .proc_handler = &proc_dointvec,
62543+ },
62544+#endif
62545+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
62546+ {
62547+ .procname = "enforce_symlinksifowner",
62548+ .data = &grsec_enable_symlinkown,
62549+ .maxlen = sizeof(int),
62550+ .mode = 0600,
62551+ .proc_handler = &proc_dointvec,
62552+ },
62553+ {
62554+ .procname = "symlinkown_gid",
62555+ .data = &grsec_symlinkown_gid,
62556+ .maxlen = sizeof(int),
62557+ .mode = 0600,
62558+ .proc_handler = &proc_dointvec,
62559+ },
62560+#endif
62561+#ifdef CONFIG_GRKERNSEC_BRUTE
62562+ {
62563+ .procname = "deter_bruteforce",
62564+ .data = &grsec_enable_brute,
62565+ .maxlen = sizeof(int),
62566+ .mode = 0600,
62567+ .proc_handler = &proc_dointvec,
62568+ },
62569+#endif
62570+#ifdef CONFIG_GRKERNSEC_FIFO
62571+ {
62572+ .procname = "fifo_restrictions",
62573+ .data = &grsec_enable_fifo,
62574+ .maxlen = sizeof(int),
62575+ .mode = 0600,
62576+ .proc_handler = &proc_dointvec,
62577+ },
62578+#endif
62579+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
62580+ {
62581+ .procname = "ptrace_readexec",
62582+ .data = &grsec_enable_ptrace_readexec,
62583+ .maxlen = sizeof(int),
62584+ .mode = 0600,
62585+ .proc_handler = &proc_dointvec,
62586+ },
62587+#endif
62588+#ifdef CONFIG_GRKERNSEC_SETXID
62589+ {
62590+ .procname = "consistent_setxid",
62591+ .data = &grsec_enable_setxid,
62592+ .maxlen = sizeof(int),
62593+ .mode = 0600,
62594+ .proc_handler = &proc_dointvec,
62595+ },
62596+#endif
62597+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
62598+ {
62599+ .procname = "ip_blackhole",
62600+ .data = &grsec_enable_blackhole,
62601+ .maxlen = sizeof(int),
62602+ .mode = 0600,
62603+ .proc_handler = &proc_dointvec,
62604+ },
62605+ {
62606+ .procname = "lastack_retries",
62607+ .data = &grsec_lastack_retries,
62608+ .maxlen = sizeof(int),
62609+ .mode = 0600,
62610+ .proc_handler = &proc_dointvec,
62611+ },
62612+#endif
62613+#ifdef CONFIG_GRKERNSEC_EXECLOG
62614+ {
62615+ .procname = "exec_logging",
62616+ .data = &grsec_enable_execlog,
62617+ .maxlen = sizeof(int),
62618+ .mode = 0600,
62619+ .proc_handler = &proc_dointvec,
62620+ },
62621+#endif
62622+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
62623+ {
62624+ .procname = "rwxmap_logging",
62625+ .data = &grsec_enable_log_rwxmaps,
62626+ .maxlen = sizeof(int),
62627+ .mode = 0600,
62628+ .proc_handler = &proc_dointvec,
62629+ },
62630+#endif
62631+#ifdef CONFIG_GRKERNSEC_SIGNAL
62632+ {
62633+ .procname = "signal_logging",
62634+ .data = &grsec_enable_signal,
62635+ .maxlen = sizeof(int),
62636+ .mode = 0600,
62637+ .proc_handler = &proc_dointvec,
62638+ },
62639+#endif
62640+#ifdef CONFIG_GRKERNSEC_FORKFAIL
62641+ {
62642+ .procname = "forkfail_logging",
62643+ .data = &grsec_enable_forkfail,
62644+ .maxlen = sizeof(int),
62645+ .mode = 0600,
62646+ .proc_handler = &proc_dointvec,
62647+ },
62648+#endif
62649+#ifdef CONFIG_GRKERNSEC_TIME
62650+ {
62651+ .procname = "timechange_logging",
62652+ .data = &grsec_enable_time,
62653+ .maxlen = sizeof(int),
62654+ .mode = 0600,
62655+ .proc_handler = &proc_dointvec,
62656+ },
62657+#endif
62658+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
62659+ {
62660+ .procname = "chroot_deny_shmat",
62661+ .data = &grsec_enable_chroot_shmat,
62662+ .maxlen = sizeof(int),
62663+ .mode = 0600,
62664+ .proc_handler = &proc_dointvec,
62665+ },
62666+#endif
62667+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
62668+ {
62669+ .procname = "chroot_deny_unix",
62670+ .data = &grsec_enable_chroot_unix,
62671+ .maxlen = sizeof(int),
62672+ .mode = 0600,
62673+ .proc_handler = &proc_dointvec,
62674+ },
62675+#endif
62676+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
62677+ {
62678+ .procname = "chroot_deny_mount",
62679+ .data = &grsec_enable_chroot_mount,
62680+ .maxlen = sizeof(int),
62681+ .mode = 0600,
62682+ .proc_handler = &proc_dointvec,
62683+ },
62684+#endif
62685+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
62686+ {
62687+ .procname = "chroot_deny_fchdir",
62688+ .data = &grsec_enable_chroot_fchdir,
62689+ .maxlen = sizeof(int),
62690+ .mode = 0600,
62691+ .proc_handler = &proc_dointvec,
62692+ },
62693+#endif
62694+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
62695+ {
62696+ .procname = "chroot_deny_chroot",
62697+ .data = &grsec_enable_chroot_double,
62698+ .maxlen = sizeof(int),
62699+ .mode = 0600,
62700+ .proc_handler = &proc_dointvec,
62701+ },
62702+#endif
62703+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
62704+ {
62705+ .procname = "chroot_deny_pivot",
62706+ .data = &grsec_enable_chroot_pivot,
62707+ .maxlen = sizeof(int),
62708+ .mode = 0600,
62709+ .proc_handler = &proc_dointvec,
62710+ },
62711+#endif
62712+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
62713+ {
62714+ .procname = "chroot_enforce_chdir",
62715+ .data = &grsec_enable_chroot_chdir,
62716+ .maxlen = sizeof(int),
62717+ .mode = 0600,
62718+ .proc_handler = &proc_dointvec,
62719+ },
62720+#endif
62721+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
62722+ {
62723+ .procname = "chroot_deny_chmod",
62724+ .data = &grsec_enable_chroot_chmod,
62725+ .maxlen = sizeof(int),
62726+ .mode = 0600,
62727+ .proc_handler = &proc_dointvec,
62728+ },
62729+#endif
62730+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
62731+ {
62732+ .procname = "chroot_deny_mknod",
62733+ .data = &grsec_enable_chroot_mknod,
62734+ .maxlen = sizeof(int),
62735+ .mode = 0600,
62736+ .proc_handler = &proc_dointvec,
62737+ },
62738+#endif
62739+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
62740+ {
62741+ .procname = "chroot_restrict_nice",
62742+ .data = &grsec_enable_chroot_nice,
62743+ .maxlen = sizeof(int),
62744+ .mode = 0600,
62745+ .proc_handler = &proc_dointvec,
62746+ },
62747+#endif
62748+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
62749+ {
62750+ .procname = "chroot_execlog",
62751+ .data = &grsec_enable_chroot_execlog,
62752+ .maxlen = sizeof(int),
62753+ .mode = 0600,
62754+ .proc_handler = &proc_dointvec,
62755+ },
62756+#endif
62757+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62758+ {
62759+ .procname = "chroot_caps",
62760+ .data = &grsec_enable_chroot_caps,
62761+ .maxlen = sizeof(int),
62762+ .mode = 0600,
62763+ .proc_handler = &proc_dointvec,
62764+ },
62765+#endif
62766+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
62767+ {
62768+ .procname = "chroot_deny_sysctl",
62769+ .data = &grsec_enable_chroot_sysctl,
62770+ .maxlen = sizeof(int),
62771+ .mode = 0600,
62772+ .proc_handler = &proc_dointvec,
62773+ },
62774+#endif
62775+#ifdef CONFIG_GRKERNSEC_TPE
62776+ {
62777+ .procname = "tpe",
62778+ .data = &grsec_enable_tpe,
62779+ .maxlen = sizeof(int),
62780+ .mode = 0600,
62781+ .proc_handler = &proc_dointvec,
62782+ },
62783+ {
62784+ .procname = "tpe_gid",
62785+ .data = &grsec_tpe_gid,
62786+ .maxlen = sizeof(int),
62787+ .mode = 0600,
62788+ .proc_handler = &proc_dointvec,
62789+ },
62790+#endif
62791+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
62792+ {
62793+ .procname = "tpe_invert",
62794+ .data = &grsec_enable_tpe_invert,
62795+ .maxlen = sizeof(int),
62796+ .mode = 0600,
62797+ .proc_handler = &proc_dointvec,
62798+ },
62799+#endif
62800+#ifdef CONFIG_GRKERNSEC_TPE_ALL
62801+ {
62802+ .procname = "tpe_restrict_all",
62803+ .data = &grsec_enable_tpe_all,
62804+ .maxlen = sizeof(int),
62805+ .mode = 0600,
62806+ .proc_handler = &proc_dointvec,
62807+ },
62808+#endif
62809+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
62810+ {
62811+ .procname = "socket_all",
62812+ .data = &grsec_enable_socket_all,
62813+ .maxlen = sizeof(int),
62814+ .mode = 0600,
62815+ .proc_handler = &proc_dointvec,
62816+ },
62817+ {
62818+ .procname = "socket_all_gid",
62819+ .data = &grsec_socket_all_gid,
62820+ .maxlen = sizeof(int),
62821+ .mode = 0600,
62822+ .proc_handler = &proc_dointvec,
62823+ },
62824+#endif
62825+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
62826+ {
62827+ .procname = "socket_client",
62828+ .data = &grsec_enable_socket_client,
62829+ .maxlen = sizeof(int),
62830+ .mode = 0600,
62831+ .proc_handler = &proc_dointvec,
62832+ },
62833+ {
62834+ .procname = "socket_client_gid",
62835+ .data = &grsec_socket_client_gid,
62836+ .maxlen = sizeof(int),
62837+ .mode = 0600,
62838+ .proc_handler = &proc_dointvec,
62839+ },
62840+#endif
62841+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
62842+ {
62843+ .procname = "socket_server",
62844+ .data = &grsec_enable_socket_server,
62845+ .maxlen = sizeof(int),
62846+ .mode = 0600,
62847+ .proc_handler = &proc_dointvec,
62848+ },
62849+ {
62850+ .procname = "socket_server_gid",
62851+ .data = &grsec_socket_server_gid,
62852+ .maxlen = sizeof(int),
62853+ .mode = 0600,
62854+ .proc_handler = &proc_dointvec,
62855+ },
62856+#endif
62857+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
62858+ {
62859+ .procname = "audit_group",
62860+ .data = &grsec_enable_group,
62861+ .maxlen = sizeof(int),
62862+ .mode = 0600,
62863+ .proc_handler = &proc_dointvec,
62864+ },
62865+ {
62866+ .procname = "audit_gid",
62867+ .data = &grsec_audit_gid,
62868+ .maxlen = sizeof(int),
62869+ .mode = 0600,
62870+ .proc_handler = &proc_dointvec,
62871+ },
62872+#endif
62873+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
62874+ {
62875+ .procname = "audit_chdir",
62876+ .data = &grsec_enable_chdir,
62877+ .maxlen = sizeof(int),
62878+ .mode = 0600,
62879+ .proc_handler = &proc_dointvec,
62880+ },
62881+#endif
62882+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
62883+ {
62884+ .procname = "audit_mount",
62885+ .data = &grsec_enable_mount,
62886+ .maxlen = sizeof(int),
62887+ .mode = 0600,
62888+ .proc_handler = &proc_dointvec,
62889+ },
62890+#endif
62891+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
62892+ {
62893+ .procname = "audit_textrel",
62894+ .data = &grsec_enable_audit_textrel,
62895+ .maxlen = sizeof(int),
62896+ .mode = 0600,
62897+ .proc_handler = &proc_dointvec,
62898+ },
62899+#endif
62900+#ifdef CONFIG_GRKERNSEC_DMESG
62901+ {
62902+ .procname = "dmesg",
62903+ .data = &grsec_enable_dmesg,
62904+ .maxlen = sizeof(int),
62905+ .mode = 0600,
62906+ .proc_handler = &proc_dointvec,
62907+ },
62908+#endif
62909+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62910+ {
62911+ .procname = "chroot_findtask",
62912+ .data = &grsec_enable_chroot_findtask,
62913+ .maxlen = sizeof(int),
62914+ .mode = 0600,
62915+ .proc_handler = &proc_dointvec,
62916+ },
62917+#endif
62918+#ifdef CONFIG_GRKERNSEC_RESLOG
62919+ {
62920+ .procname = "resource_logging",
62921+ .data = &grsec_resource_logging,
62922+ .maxlen = sizeof(int),
62923+ .mode = 0600,
62924+ .proc_handler = &proc_dointvec,
62925+ },
62926+#endif
62927+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
62928+ {
62929+ .procname = "audit_ptrace",
62930+ .data = &grsec_enable_audit_ptrace,
62931+ .maxlen = sizeof(int),
62932+ .mode = 0600,
62933+ .proc_handler = &proc_dointvec,
62934+ },
62935+#endif
62936+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
62937+ {
62938+ .procname = "harden_ptrace",
62939+ .data = &grsec_enable_harden_ptrace,
62940+ .maxlen = sizeof(int),
62941+ .mode = 0600,
62942+ .proc_handler = &proc_dointvec,
62943+ },
62944+#endif
62945+ {
62946+ .procname = "grsec_lock",
62947+ .data = &grsec_lock,
62948+ .maxlen = sizeof(int),
62949+ .mode = 0600,
62950+ .proc_handler = &proc_dointvec,
62951+ },
62952+#endif
62953+#ifdef CONFIG_GRKERNSEC_ROFS
62954+ {
62955+ .procname = "romount_protect",
62956+ .data = &grsec_enable_rofs,
62957+ .maxlen = sizeof(int),
62958+ .mode = 0600,
62959+ .proc_handler = &proc_dointvec_minmax,
62960+ .extra1 = &one,
62961+ .extra2 = &one,
62962+ },
62963+#endif
62964+ { }
62965+};
62966+#endif
62967diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
62968new file mode 100644
62969index 0000000..0dc13c3
62970--- /dev/null
62971+++ b/grsecurity/grsec_time.c
62972@@ -0,0 +1,16 @@
62973+#include <linux/kernel.h>
62974+#include <linux/sched.h>
62975+#include <linux/grinternal.h>
62976+#include <linux/module.h>
62977+
62978+void
62979+gr_log_timechange(void)
62980+{
62981+#ifdef CONFIG_GRKERNSEC_TIME
62982+ if (grsec_enable_time)
62983+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
62984+#endif
62985+ return;
62986+}
62987+
62988+EXPORT_SYMBOL(gr_log_timechange);
62989diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
62990new file mode 100644
62991index 0000000..07e0dc0
62992--- /dev/null
62993+++ b/grsecurity/grsec_tpe.c
62994@@ -0,0 +1,73 @@
62995+#include <linux/kernel.h>
62996+#include <linux/sched.h>
62997+#include <linux/file.h>
62998+#include <linux/fs.h>
62999+#include <linux/grinternal.h>
63000+
63001+extern int gr_acl_tpe_check(void);
63002+
63003+int
63004+gr_tpe_allow(const struct file *file)
63005+{
63006+#ifdef CONFIG_GRKERNSEC
63007+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
63008+ const struct cred *cred = current_cred();
63009+ char *msg = NULL;
63010+ char *msg2 = NULL;
63011+
63012+ // never restrict root
63013+ if (!cred->uid)
63014+ return 1;
63015+
63016+ if (grsec_enable_tpe) {
63017+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
63018+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
63019+ msg = "not being in trusted group";
63020+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
63021+ msg = "being in untrusted group";
63022+#else
63023+ if (in_group_p(grsec_tpe_gid))
63024+ msg = "being in untrusted group";
63025+#endif
63026+ }
63027+ if (!msg && gr_acl_tpe_check())
63028+ msg = "being in untrusted role";
63029+
63030+ // not in any affected group/role
63031+ if (!msg)
63032+ goto next_check;
63033+
63034+ if (inode->i_uid)
63035+ msg2 = "file in non-root-owned directory";
63036+ else if (inode->i_mode & S_IWOTH)
63037+ msg2 = "file in world-writable directory";
63038+ else if (inode->i_mode & S_IWGRP)
63039+ msg2 = "file in group-writable directory";
63040+
63041+ if (msg && msg2) {
63042+ char fullmsg[70] = {0};
63043+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
63044+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
63045+ return 0;
63046+ }
63047+ msg = NULL;
63048+next_check:
63049+#ifdef CONFIG_GRKERNSEC_TPE_ALL
63050+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
63051+ return 1;
63052+
63053+ if (inode->i_uid && (inode->i_uid != cred->uid))
63054+ msg = "directory not owned by user";
63055+ else if (inode->i_mode & S_IWOTH)
63056+ msg = "file in world-writable directory";
63057+ else if (inode->i_mode & S_IWGRP)
63058+ msg = "file in group-writable directory";
63059+
63060+ if (msg) {
63061+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
63062+ return 0;
63063+ }
63064+#endif
63065+#endif
63066+ return 1;
63067+}
63068diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
63069new file mode 100644
63070index 0000000..9f7b1ac
63071--- /dev/null
63072+++ b/grsecurity/grsum.c
63073@@ -0,0 +1,61 @@
63074+#include <linux/err.h>
63075+#include <linux/kernel.h>
63076+#include <linux/sched.h>
63077+#include <linux/mm.h>
63078+#include <linux/scatterlist.h>
63079+#include <linux/crypto.h>
63080+#include <linux/gracl.h>
63081+
63082+
63083+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
63084+#error "crypto and sha256 must be built into the kernel"
63085+#endif
63086+
63087+int
63088+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
63089+{
63090+ char *p;
63091+ struct crypto_hash *tfm;
63092+ struct hash_desc desc;
63093+ struct scatterlist sg;
63094+ unsigned char temp_sum[GR_SHA_LEN];
63095+ volatile int retval = 0;
63096+ volatile int dummy = 0;
63097+ unsigned int i;
63098+
63099+ sg_init_table(&sg, 1);
63100+
63101+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
63102+ if (IS_ERR(tfm)) {
63103+ /* should never happen, since sha256 should be built in */
63104+ return 1;
63105+ }
63106+
63107+ desc.tfm = tfm;
63108+ desc.flags = 0;
63109+
63110+ crypto_hash_init(&desc);
63111+
63112+ p = salt;
63113+ sg_set_buf(&sg, p, GR_SALT_LEN);
63114+ crypto_hash_update(&desc, &sg, sg.length);
63115+
63116+ p = entry->pw;
63117+ sg_set_buf(&sg, p, strlen(p));
63118+
63119+ crypto_hash_update(&desc, &sg, sg.length);
63120+
63121+ crypto_hash_final(&desc, temp_sum);
63122+
63123+ memset(entry->pw, 0, GR_PW_LEN);
63124+
63125+ for (i = 0; i < GR_SHA_LEN; i++)
63126+ if (sum[i] != temp_sum[i])
63127+ retval = 1;
63128+ else
63129+ dummy = 1; // waste a cycle
63130+
63131+ crypto_free_hash(tfm);
63132+
63133+ return retval;
63134+}
63135diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
63136index 77ff547..181834f 100644
63137--- a/include/asm-generic/4level-fixup.h
63138+++ b/include/asm-generic/4level-fixup.h
63139@@ -13,8 +13,10 @@
63140 #define pmd_alloc(mm, pud, address) \
63141 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
63142 NULL: pmd_offset(pud, address))
63143+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
63144
63145 #define pud_alloc(mm, pgd, address) (pgd)
63146+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
63147 #define pud_offset(pgd, start) (pgd)
63148 #define pud_none(pud) 0
63149 #define pud_bad(pud) 0
63150diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
63151index b7babf0..04ad282 100644
63152--- a/include/asm-generic/atomic-long.h
63153+++ b/include/asm-generic/atomic-long.h
63154@@ -22,6 +22,12 @@
63155
63156 typedef atomic64_t atomic_long_t;
63157
63158+#ifdef CONFIG_PAX_REFCOUNT
63159+typedef atomic64_unchecked_t atomic_long_unchecked_t;
63160+#else
63161+typedef atomic64_t atomic_long_unchecked_t;
63162+#endif
63163+
63164 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
63165
63166 static inline long atomic_long_read(atomic_long_t *l)
63167@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
63168 return (long)atomic64_read(v);
63169 }
63170
63171+#ifdef CONFIG_PAX_REFCOUNT
63172+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
63173+{
63174+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63175+
63176+ return (long)atomic64_read_unchecked(v);
63177+}
63178+#endif
63179+
63180 static inline void atomic_long_set(atomic_long_t *l, long i)
63181 {
63182 atomic64_t *v = (atomic64_t *)l;
63183@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
63184 atomic64_set(v, i);
63185 }
63186
63187+#ifdef CONFIG_PAX_REFCOUNT
63188+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
63189+{
63190+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63191+
63192+ atomic64_set_unchecked(v, i);
63193+}
63194+#endif
63195+
63196 static inline void atomic_long_inc(atomic_long_t *l)
63197 {
63198 atomic64_t *v = (atomic64_t *)l;
63199@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
63200 atomic64_inc(v);
63201 }
63202
63203+#ifdef CONFIG_PAX_REFCOUNT
63204+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
63205+{
63206+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63207+
63208+ atomic64_inc_unchecked(v);
63209+}
63210+#endif
63211+
63212 static inline void atomic_long_dec(atomic_long_t *l)
63213 {
63214 atomic64_t *v = (atomic64_t *)l;
63215@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
63216 atomic64_dec(v);
63217 }
63218
63219+#ifdef CONFIG_PAX_REFCOUNT
63220+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
63221+{
63222+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63223+
63224+ atomic64_dec_unchecked(v);
63225+}
63226+#endif
63227+
63228 static inline void atomic_long_add(long i, atomic_long_t *l)
63229 {
63230 atomic64_t *v = (atomic64_t *)l;
63231@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
63232 atomic64_add(i, v);
63233 }
63234
63235+#ifdef CONFIG_PAX_REFCOUNT
63236+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
63237+{
63238+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63239+
63240+ atomic64_add_unchecked(i, v);
63241+}
63242+#endif
63243+
63244 static inline void atomic_long_sub(long i, atomic_long_t *l)
63245 {
63246 atomic64_t *v = (atomic64_t *)l;
63247@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
63248 atomic64_sub(i, v);
63249 }
63250
63251+#ifdef CONFIG_PAX_REFCOUNT
63252+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
63253+{
63254+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63255+
63256+ atomic64_sub_unchecked(i, v);
63257+}
63258+#endif
63259+
63260 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
63261 {
63262 atomic64_t *v = (atomic64_t *)l;
63263@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
63264 return (long)atomic64_add_return(i, v);
63265 }
63266
63267+#ifdef CONFIG_PAX_REFCOUNT
63268+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
63269+{
63270+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63271+
63272+ return (long)atomic64_add_return_unchecked(i, v);
63273+}
63274+#endif
63275+
63276 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
63277 {
63278 atomic64_t *v = (atomic64_t *)l;
63279@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
63280 return (long)atomic64_inc_return(v);
63281 }
63282
63283+#ifdef CONFIG_PAX_REFCOUNT
63284+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
63285+{
63286+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63287+
63288+ return (long)atomic64_inc_return_unchecked(v);
63289+}
63290+#endif
63291+
63292 static inline long atomic_long_dec_return(atomic_long_t *l)
63293 {
63294 atomic64_t *v = (atomic64_t *)l;
63295@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
63296
63297 typedef atomic_t atomic_long_t;
63298
63299+#ifdef CONFIG_PAX_REFCOUNT
63300+typedef atomic_unchecked_t atomic_long_unchecked_t;
63301+#else
63302+typedef atomic_t atomic_long_unchecked_t;
63303+#endif
63304+
63305 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
63306 static inline long atomic_long_read(atomic_long_t *l)
63307 {
63308@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
63309 return (long)atomic_read(v);
63310 }
63311
63312+#ifdef CONFIG_PAX_REFCOUNT
63313+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
63314+{
63315+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63316+
63317+ return (long)atomic_read_unchecked(v);
63318+}
63319+#endif
63320+
63321 static inline void atomic_long_set(atomic_long_t *l, long i)
63322 {
63323 atomic_t *v = (atomic_t *)l;
63324@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
63325 atomic_set(v, i);
63326 }
63327
63328+#ifdef CONFIG_PAX_REFCOUNT
63329+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
63330+{
63331+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63332+
63333+ atomic_set_unchecked(v, i);
63334+}
63335+#endif
63336+
63337 static inline void atomic_long_inc(atomic_long_t *l)
63338 {
63339 atomic_t *v = (atomic_t *)l;
63340@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
63341 atomic_inc(v);
63342 }
63343
63344+#ifdef CONFIG_PAX_REFCOUNT
63345+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
63346+{
63347+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63348+
63349+ atomic_inc_unchecked(v);
63350+}
63351+#endif
63352+
63353 static inline void atomic_long_dec(atomic_long_t *l)
63354 {
63355 atomic_t *v = (atomic_t *)l;
63356@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
63357 atomic_dec(v);
63358 }
63359
63360+#ifdef CONFIG_PAX_REFCOUNT
63361+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
63362+{
63363+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63364+
63365+ atomic_dec_unchecked(v);
63366+}
63367+#endif
63368+
63369 static inline void atomic_long_add(long i, atomic_long_t *l)
63370 {
63371 atomic_t *v = (atomic_t *)l;
63372@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
63373 atomic_add(i, v);
63374 }
63375
63376+#ifdef CONFIG_PAX_REFCOUNT
63377+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
63378+{
63379+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63380+
63381+ atomic_add_unchecked(i, v);
63382+}
63383+#endif
63384+
63385 static inline void atomic_long_sub(long i, atomic_long_t *l)
63386 {
63387 atomic_t *v = (atomic_t *)l;
63388@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
63389 atomic_sub(i, v);
63390 }
63391
63392+#ifdef CONFIG_PAX_REFCOUNT
63393+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
63394+{
63395+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63396+
63397+ atomic_sub_unchecked(i, v);
63398+}
63399+#endif
63400+
63401 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
63402 {
63403 atomic_t *v = (atomic_t *)l;
63404@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
63405 return (long)atomic_add_return(i, v);
63406 }
63407
63408+#ifdef CONFIG_PAX_REFCOUNT
63409+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
63410+{
63411+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63412+
63413+ return (long)atomic_add_return_unchecked(i, v);
63414+}
63415+
63416+#endif
63417+
63418 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
63419 {
63420 atomic_t *v = (atomic_t *)l;
63421@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
63422 return (long)atomic_inc_return(v);
63423 }
63424
63425+#ifdef CONFIG_PAX_REFCOUNT
63426+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
63427+{
63428+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63429+
63430+ return (long)atomic_inc_return_unchecked(v);
63431+}
63432+#endif
63433+
63434 static inline long atomic_long_dec_return(atomic_long_t *l)
63435 {
63436 atomic_t *v = (atomic_t *)l;
63437@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
63438
63439 #endif /* BITS_PER_LONG == 64 */
63440
63441+#ifdef CONFIG_PAX_REFCOUNT
63442+static inline void pax_refcount_needs_these_functions(void)
63443+{
63444+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
63445+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
63446+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
63447+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
63448+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
63449+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
63450+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
63451+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
63452+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
63453+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
63454+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
63455+#ifdef CONFIG_X86
63456+ atomic_clear_mask_unchecked(0, NULL);
63457+ atomic_set_mask_unchecked(0, NULL);
63458+#endif
63459+
63460+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
63461+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
63462+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
63463+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
63464+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
63465+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
63466+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
63467+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
63468+}
63469+#else
63470+#define atomic_read_unchecked(v) atomic_read(v)
63471+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
63472+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
63473+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
63474+#define atomic_inc_unchecked(v) atomic_inc(v)
63475+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
63476+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
63477+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
63478+#define atomic_dec_unchecked(v) atomic_dec(v)
63479+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
63480+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
63481+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
63482+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
63483+
63484+#define atomic_long_read_unchecked(v) atomic_long_read(v)
63485+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
63486+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
63487+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
63488+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
63489+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
63490+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
63491+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
63492+#endif
63493+
63494 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
63495diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
63496index 1ced641..c896ee8 100644
63497--- a/include/asm-generic/atomic.h
63498+++ b/include/asm-generic/atomic.h
63499@@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
63500 * Atomically clears the bits set in @mask from @v
63501 */
63502 #ifndef atomic_clear_mask
63503-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
63504+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
63505 {
63506 unsigned long flags;
63507
63508diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
63509index b18ce4f..2ee2843 100644
63510--- a/include/asm-generic/atomic64.h
63511+++ b/include/asm-generic/atomic64.h
63512@@ -16,6 +16,8 @@ typedef struct {
63513 long long counter;
63514 } atomic64_t;
63515
63516+typedef atomic64_t atomic64_unchecked_t;
63517+
63518 #define ATOMIC64_INIT(i) { (i) }
63519
63520 extern long long atomic64_read(const atomic64_t *v);
63521@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
63522 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
63523 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
63524
63525+#define atomic64_read_unchecked(v) atomic64_read(v)
63526+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
63527+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
63528+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
63529+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
63530+#define atomic64_inc_unchecked(v) atomic64_inc(v)
63531+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
63532+#define atomic64_dec_unchecked(v) atomic64_dec(v)
63533+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
63534+
63535 #endif /* _ASM_GENERIC_ATOMIC64_H */
63536diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
63537index 1bfcfe5..e04c5c9 100644
63538--- a/include/asm-generic/cache.h
63539+++ b/include/asm-generic/cache.h
63540@@ -6,7 +6,7 @@
63541 * cache lines need to provide their own cache.h.
63542 */
63543
63544-#define L1_CACHE_SHIFT 5
63545-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
63546+#define L1_CACHE_SHIFT 5UL
63547+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
63548
63549 #endif /* __ASM_GENERIC_CACHE_H */
63550diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
63551index 0d68a1e..b74a761 100644
63552--- a/include/asm-generic/emergency-restart.h
63553+++ b/include/asm-generic/emergency-restart.h
63554@@ -1,7 +1,7 @@
63555 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
63556 #define _ASM_GENERIC_EMERGENCY_RESTART_H
63557
63558-static inline void machine_emergency_restart(void)
63559+static inline __noreturn void machine_emergency_restart(void)
63560 {
63561 machine_restart(NULL);
63562 }
63563diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
63564index 90f99c7..00ce236 100644
63565--- a/include/asm-generic/kmap_types.h
63566+++ b/include/asm-generic/kmap_types.h
63567@@ -2,9 +2,9 @@
63568 #define _ASM_GENERIC_KMAP_TYPES_H
63569
63570 #ifdef __WITH_KM_FENCE
63571-# define KM_TYPE_NR 41
63572+# define KM_TYPE_NR 42
63573 #else
63574-# define KM_TYPE_NR 20
63575+# define KM_TYPE_NR 21
63576 #endif
63577
63578 #endif
63579diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
63580index 9ceb03b..62b0b8f 100644
63581--- a/include/asm-generic/local.h
63582+++ b/include/asm-generic/local.h
63583@@ -23,24 +23,37 @@ typedef struct
63584 atomic_long_t a;
63585 } local_t;
63586
63587+typedef struct {
63588+ atomic_long_unchecked_t a;
63589+} local_unchecked_t;
63590+
63591 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
63592
63593 #define local_read(l) atomic_long_read(&(l)->a)
63594+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
63595 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
63596+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
63597 #define local_inc(l) atomic_long_inc(&(l)->a)
63598+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
63599 #define local_dec(l) atomic_long_dec(&(l)->a)
63600+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
63601 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
63602+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
63603 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
63604+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
63605
63606 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
63607 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
63608 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
63609 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
63610 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
63611+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
63612 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
63613 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
63614+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
63615
63616 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
63617+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
63618 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
63619 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
63620 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
63621diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
63622index 725612b..9cc513a 100644
63623--- a/include/asm-generic/pgtable-nopmd.h
63624+++ b/include/asm-generic/pgtable-nopmd.h
63625@@ -1,14 +1,19 @@
63626 #ifndef _PGTABLE_NOPMD_H
63627 #define _PGTABLE_NOPMD_H
63628
63629-#ifndef __ASSEMBLY__
63630-
63631 #include <asm-generic/pgtable-nopud.h>
63632
63633-struct mm_struct;
63634-
63635 #define __PAGETABLE_PMD_FOLDED
63636
63637+#define PMD_SHIFT PUD_SHIFT
63638+#define PTRS_PER_PMD 1
63639+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
63640+#define PMD_MASK (~(PMD_SIZE-1))
63641+
63642+#ifndef __ASSEMBLY__
63643+
63644+struct mm_struct;
63645+
63646 /*
63647 * Having the pmd type consist of a pud gets the size right, and allows
63648 * us to conceptually access the pud entry that this pmd is folded into
63649@@ -16,11 +21,6 @@ struct mm_struct;
63650 */
63651 typedef struct { pud_t pud; } pmd_t;
63652
63653-#define PMD_SHIFT PUD_SHIFT
63654-#define PTRS_PER_PMD 1
63655-#define PMD_SIZE (1UL << PMD_SHIFT)
63656-#define PMD_MASK (~(PMD_SIZE-1))
63657-
63658 /*
63659 * The "pud_xxx()" functions here are trivial for a folded two-level
63660 * setup: the pmd is never bad, and a pmd always exists (as it's folded
63661diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
63662index 810431d..0ec4804f 100644
63663--- a/include/asm-generic/pgtable-nopud.h
63664+++ b/include/asm-generic/pgtable-nopud.h
63665@@ -1,10 +1,15 @@
63666 #ifndef _PGTABLE_NOPUD_H
63667 #define _PGTABLE_NOPUD_H
63668
63669-#ifndef __ASSEMBLY__
63670-
63671 #define __PAGETABLE_PUD_FOLDED
63672
63673+#define PUD_SHIFT PGDIR_SHIFT
63674+#define PTRS_PER_PUD 1
63675+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
63676+#define PUD_MASK (~(PUD_SIZE-1))
63677+
63678+#ifndef __ASSEMBLY__
63679+
63680 /*
63681 * Having the pud type consist of a pgd gets the size right, and allows
63682 * us to conceptually access the pgd entry that this pud is folded into
63683@@ -12,11 +17,6 @@
63684 */
63685 typedef struct { pgd_t pgd; } pud_t;
63686
63687-#define PUD_SHIFT PGDIR_SHIFT
63688-#define PTRS_PER_PUD 1
63689-#define PUD_SIZE (1UL << PUD_SHIFT)
63690-#define PUD_MASK (~(PUD_SIZE-1))
63691-
63692 /*
63693 * The "pgd_xxx()" functions here are trivial for a folded two-level
63694 * setup: the pud is never bad, and a pud always exists (as it's folded
63695@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
63696 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
63697
63698 #define pgd_populate(mm, pgd, pud) do { } while (0)
63699+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
63700 /*
63701 * (puds are folded into pgds so this doesn't get actually called,
63702 * but the define is needed for a generic inline function.)
63703diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
63704index 5cf680a..4b74d62 100644
63705--- a/include/asm-generic/pgtable.h
63706+++ b/include/asm-generic/pgtable.h
63707@@ -688,6 +688,14 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
63708 }
63709 #endif /* CONFIG_NUMA_BALANCING */
63710
63711+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
63712+static inline unsigned long pax_open_kernel(void) { return 0; }
63713+#endif
63714+
63715+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
63716+static inline unsigned long pax_close_kernel(void) { return 0; }
63717+#endif
63718+
63719 #endif /* CONFIG_MMU */
63720
63721 #endif /* !__ASSEMBLY__ */
63722diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
63723index d1ea7ce..b1ebf2a 100644
63724--- a/include/asm-generic/vmlinux.lds.h
63725+++ b/include/asm-generic/vmlinux.lds.h
63726@@ -218,6 +218,7 @@
63727 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
63728 VMLINUX_SYMBOL(__start_rodata) = .; \
63729 *(.rodata) *(.rodata.*) \
63730+ *(.data..read_only) \
63731 *(__vermagic) /* Kernel version magic */ \
63732 . = ALIGN(8); \
63733 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
63734@@ -725,17 +726,18 @@
63735 * section in the linker script will go there too. @phdr should have
63736 * a leading colon.
63737 *
63738- * Note that this macros defines __per_cpu_load as an absolute symbol.
63739+ * Note that this macros defines per_cpu_load as an absolute symbol.
63740 * If there is no need to put the percpu section at a predetermined
63741 * address, use PERCPU_SECTION.
63742 */
63743 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
63744- VMLINUX_SYMBOL(__per_cpu_load) = .; \
63745- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
63746+ per_cpu_load = .; \
63747+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
63748 - LOAD_OFFSET) { \
63749+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
63750 PERCPU_INPUT(cacheline) \
63751 } phdr \
63752- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
63753+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
63754
63755 /**
63756 * PERCPU_SECTION - define output section for percpu area, simple version
63757diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
63758index 418d270..bfd2794 100644
63759--- a/include/crypto/algapi.h
63760+++ b/include/crypto/algapi.h
63761@@ -34,7 +34,7 @@ struct crypto_type {
63762 unsigned int maskclear;
63763 unsigned int maskset;
63764 unsigned int tfmsize;
63765-};
63766+} __do_const;
63767
63768 struct crypto_instance {
63769 struct crypto_alg alg;
63770diff --git a/include/drm/drmP.h b/include/drm/drmP.h
63771index fad21c9..3fff955 100644
63772--- a/include/drm/drmP.h
63773+++ b/include/drm/drmP.h
63774@@ -72,6 +72,7 @@
63775 #include <linux/workqueue.h>
63776 #include <linux/poll.h>
63777 #include <asm/pgalloc.h>
63778+#include <asm/local.h>
63779 #include <drm/drm.h>
63780 #include <drm/drm_sarea.h>
63781
63782@@ -1068,7 +1069,7 @@ struct drm_device {
63783
63784 /** \name Usage Counters */
63785 /*@{ */
63786- int open_count; /**< Outstanding files open */
63787+ local_t open_count; /**< Outstanding files open */
63788 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
63789 atomic_t vma_count; /**< Outstanding vma areas open */
63790 int buf_use; /**< Buffers in use -- cannot alloc */
63791@@ -1079,7 +1080,7 @@ struct drm_device {
63792 /*@{ */
63793 unsigned long counters;
63794 enum drm_stat_type types[15];
63795- atomic_t counts[15];
63796+ atomic_unchecked_t counts[15];
63797 /*@} */
63798
63799 struct list_head filelist;
63800diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
63801index f43d556..94d9343 100644
63802--- a/include/drm/drm_crtc_helper.h
63803+++ b/include/drm/drm_crtc_helper.h
63804@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
63805 struct drm_connector *connector);
63806 /* disable encoder when not in use - more explicit than dpms off */
63807 void (*disable)(struct drm_encoder *encoder);
63808-};
63809+} __no_const;
63810
63811 /**
63812 * drm_connector_helper_funcs - helper operations for connectors
63813diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
63814index 72dcbe8..8db58d7 100644
63815--- a/include/drm/ttm/ttm_memory.h
63816+++ b/include/drm/ttm/ttm_memory.h
63817@@ -48,7 +48,7 @@
63818
63819 struct ttm_mem_shrink {
63820 int (*do_shrink) (struct ttm_mem_shrink *);
63821-};
63822+} __no_const;
63823
63824 /**
63825 * struct ttm_mem_global - Global memory accounting structure.
63826diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
63827index c1da539..4db35ec 100644
63828--- a/include/linux/atmdev.h
63829+++ b/include/linux/atmdev.h
63830@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
63831 #endif
63832
63833 struct k_atm_aal_stats {
63834-#define __HANDLE_ITEM(i) atomic_t i
63835+#define __HANDLE_ITEM(i) atomic_unchecked_t i
63836 __AAL_STAT_ITEMS
63837 #undef __HANDLE_ITEM
63838 };
63839diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
63840index 0530b98..b127a9e 100644
63841--- a/include/linux/binfmts.h
63842+++ b/include/linux/binfmts.h
63843@@ -73,6 +73,7 @@ struct linux_binfmt {
63844 int (*load_binary)(struct linux_binprm *);
63845 int (*load_shlib)(struct file *);
63846 int (*core_dump)(struct coredump_params *cprm);
63847+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
63848 unsigned long min_coredump; /* minimal dump size */
63849 };
63850
63851diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
63852index f94bc83..62b9cfe 100644
63853--- a/include/linux/blkdev.h
63854+++ b/include/linux/blkdev.h
63855@@ -1498,7 +1498,7 @@ struct block_device_operations {
63856 /* this callback is with swap_lock and sometimes page table lock held */
63857 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
63858 struct module *owner;
63859-};
63860+} __do_const;
63861
63862 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
63863 unsigned long);
63864diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
63865index 7c2e030..b72475d 100644
63866--- a/include/linux/blktrace_api.h
63867+++ b/include/linux/blktrace_api.h
63868@@ -23,7 +23,7 @@ struct blk_trace {
63869 struct dentry *dir;
63870 struct dentry *dropped_file;
63871 struct dentry *msg_file;
63872- atomic_t dropped;
63873+ atomic_unchecked_t dropped;
63874 };
63875
63876 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
63877diff --git a/include/linux/cache.h b/include/linux/cache.h
63878index 4c57065..4307975 100644
63879--- a/include/linux/cache.h
63880+++ b/include/linux/cache.h
63881@@ -16,6 +16,10 @@
63882 #define __read_mostly
63883 #endif
63884
63885+#ifndef __read_only
63886+#define __read_only __read_mostly
63887+#endif
63888+
63889 #ifndef ____cacheline_aligned
63890 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
63891 #endif
63892diff --git a/include/linux/capability.h b/include/linux/capability.h
63893index 98503b7..cc36d18 100644
63894--- a/include/linux/capability.h
63895+++ b/include/linux/capability.h
63896@@ -211,8 +211,13 @@ extern bool capable(int cap);
63897 extern bool ns_capable(struct user_namespace *ns, int cap);
63898 extern bool nsown_capable(int cap);
63899 extern bool inode_capable(const struct inode *inode, int cap);
63900+extern bool capable_nolog(int cap);
63901+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
63902+extern bool inode_capable_nolog(const struct inode *inode, int cap);
63903
63904 /* audit system wants to get cap info from files as well */
63905 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
63906
63907+extern int is_privileged_binary(const struct dentry *dentry);
63908+
63909 #endif /* !_LINUX_CAPABILITY_H */
63910diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
63911index 8609d57..86e4d79 100644
63912--- a/include/linux/cdrom.h
63913+++ b/include/linux/cdrom.h
63914@@ -87,7 +87,6 @@ struct cdrom_device_ops {
63915
63916 /* driver specifications */
63917 const int capability; /* capability flags */
63918- int n_minors; /* number of active minor devices */
63919 /* handle uniform packets for scsi type devices (scsi,atapi) */
63920 int (*generic_packet) (struct cdrom_device_info *,
63921 struct packet_command *);
63922diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
63923index 42e55de..1cd0e66 100644
63924--- a/include/linux/cleancache.h
63925+++ b/include/linux/cleancache.h
63926@@ -31,7 +31,7 @@ struct cleancache_ops {
63927 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
63928 void (*invalidate_inode)(int, struct cleancache_filekey);
63929 void (*invalidate_fs)(int);
63930-};
63931+} __no_const;
63932
63933 extern struct cleancache_ops
63934 cleancache_register_ops(struct cleancache_ops *ops);
63935diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
63936index 662fd1b..e801992 100644
63937--- a/include/linux/compiler-gcc4.h
63938+++ b/include/linux/compiler-gcc4.h
63939@@ -34,6 +34,21 @@
63940 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
63941
63942 #if __GNUC_MINOR__ >= 5
63943+
63944+#ifdef CONSTIFY_PLUGIN
63945+#define __no_const __attribute__((no_const))
63946+#define __do_const __attribute__((do_const))
63947+#endif
63948+
63949+#ifdef SIZE_OVERFLOW_PLUGIN
63950+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
63951+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
63952+#endif
63953+
63954+#ifdef LATENT_ENTROPY_PLUGIN
63955+#define __latent_entropy __attribute__((latent_entropy))
63956+#endif
63957+
63958 /*
63959 * Mark a position in code as unreachable. This can be used to
63960 * suppress control flow warnings after asm blocks that transfer
63961@@ -49,6 +64,11 @@
63962 #define __noclone __attribute__((__noclone__))
63963
63964 #endif
63965+
63966+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
63967+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
63968+#define __bos0(ptr) __bos((ptr), 0)
63969+#define __bos1(ptr) __bos((ptr), 1)
63970 #endif
63971
63972 #if __GNUC_MINOR__ >= 6
63973diff --git a/include/linux/compiler.h b/include/linux/compiler.h
63974index dd852b7..72924c0 100644
63975--- a/include/linux/compiler.h
63976+++ b/include/linux/compiler.h
63977@@ -5,11 +5,14 @@
63978
63979 #ifdef __CHECKER__
63980 # define __user __attribute__((noderef, address_space(1)))
63981+# define __force_user __force __user
63982 # define __kernel __attribute__((address_space(0)))
63983+# define __force_kernel __force __kernel
63984 # define __safe __attribute__((safe))
63985 # define __force __attribute__((force))
63986 # define __nocast __attribute__((nocast))
63987 # define __iomem __attribute__((noderef, address_space(2)))
63988+# define __force_iomem __force __iomem
63989 # define __must_hold(x) __attribute__((context(x,1,1)))
63990 # define __acquires(x) __attribute__((context(x,0,1)))
63991 # define __releases(x) __attribute__((context(x,1,0)))
63992@@ -17,20 +20,48 @@
63993 # define __release(x) __context__(x,-1)
63994 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
63995 # define __percpu __attribute__((noderef, address_space(3)))
63996+# define __force_percpu __force __percpu
63997 #ifdef CONFIG_SPARSE_RCU_POINTER
63998 # define __rcu __attribute__((noderef, address_space(4)))
63999+# define __force_rcu __force __rcu
64000 #else
64001 # define __rcu
64002+# define __force_rcu
64003 #endif
64004 extern void __chk_user_ptr(const volatile void __user *);
64005 extern void __chk_io_ptr(const volatile void __iomem *);
64006+#elif defined(CHECKER_PLUGIN)
64007+//# define __user
64008+//# define __force_user
64009+//# define __kernel
64010+//# define __force_kernel
64011+# define __safe
64012+# define __force
64013+# define __nocast
64014+# define __iomem
64015+# define __force_iomem
64016+# define __chk_user_ptr(x) (void)0
64017+# define __chk_io_ptr(x) (void)0
64018+# define __builtin_warning(x, y...) (1)
64019+# define __acquires(x)
64020+# define __releases(x)
64021+# define __acquire(x) (void)0
64022+# define __release(x) (void)0
64023+# define __cond_lock(x,c) (c)
64024+# define __percpu
64025+# define __force_percpu
64026+# define __rcu
64027+# define __force_rcu
64028 #else
64029 # define __user
64030+# define __force_user
64031 # define __kernel
64032+# define __force_kernel
64033 # define __safe
64034 # define __force
64035 # define __nocast
64036 # define __iomem
64037+# define __force_iomem
64038 # define __chk_user_ptr(x) (void)0
64039 # define __chk_io_ptr(x) (void)0
64040 # define __builtin_warning(x, y...) (1)
64041@@ -41,7 +72,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
64042 # define __release(x) (void)0
64043 # define __cond_lock(x,c) (c)
64044 # define __percpu
64045+# define __force_percpu
64046 # define __rcu
64047+# define __force_rcu
64048 #endif
64049
64050 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
64051@@ -275,6 +308,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
64052 # define __attribute_const__ /* unimplemented */
64053 #endif
64054
64055+#ifndef __no_const
64056+# define __no_const
64057+#endif
64058+
64059+#ifndef __do_const
64060+# define __do_const
64061+#endif
64062+
64063+#ifndef __size_overflow
64064+# define __size_overflow(...)
64065+#endif
64066+
64067+#ifndef __intentional_overflow
64068+# define __intentional_overflow(...)
64069+#endif
64070+
64071+#ifndef __latent_entropy
64072+# define __latent_entropy
64073+#endif
64074+
64075 /*
64076 * Tell gcc if a function is cold. The compiler will assume any path
64077 * directly leading to the call is unlikely.
64078@@ -284,6 +337,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
64079 #define __cold
64080 #endif
64081
64082+#ifndef __alloc_size
64083+#define __alloc_size(...)
64084+#endif
64085+
64086+#ifndef __bos
64087+#define __bos(ptr, arg)
64088+#endif
64089+
64090+#ifndef __bos0
64091+#define __bos0(ptr)
64092+#endif
64093+
64094+#ifndef __bos1
64095+#define __bos1(ptr)
64096+#endif
64097+
64098 /* Simple shorthand for a section definition */
64099 #ifndef __section
64100 # define __section(S) __attribute__ ((__section__(#S)))
64101@@ -323,6 +392,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
64102 * use is to mediate communication between process-level code and irq/NMI
64103 * handlers, all running on the same CPU.
64104 */
64105-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
64106+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
64107+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
64108
64109 #endif /* __LINUX_COMPILER_H */
64110diff --git a/include/linux/cpu.h b/include/linux/cpu.h
64111index ce7a074..01ab8ac 100644
64112--- a/include/linux/cpu.h
64113+++ b/include/linux/cpu.h
64114@@ -115,7 +115,7 @@ enum {
64115 /* Need to know about CPUs going up/down? */
64116 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
64117 #define cpu_notifier(fn, pri) { \
64118- static struct notifier_block fn##_nb __cpuinitdata = \
64119+ static struct notifier_block fn##_nb = \
64120 { .notifier_call = fn, .priority = pri }; \
64121 register_cpu_notifier(&fn##_nb); \
64122 }
64123diff --git a/include/linux/cred.h b/include/linux/cred.h
64124index 04421e8..6bce4ef 100644
64125--- a/include/linux/cred.h
64126+++ b/include/linux/cred.h
64127@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
64128 static inline void validate_process_creds(void)
64129 {
64130 }
64131+static inline void validate_task_creds(struct task_struct *task)
64132+{
64133+}
64134 #endif
64135
64136 /**
64137diff --git a/include/linux/crypto.h b/include/linux/crypto.h
64138index b92eadf..b4ecdc1 100644
64139--- a/include/linux/crypto.h
64140+++ b/include/linux/crypto.h
64141@@ -373,7 +373,7 @@ struct cipher_tfm {
64142 const u8 *key, unsigned int keylen);
64143 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
64144 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
64145-};
64146+} __no_const;
64147
64148 struct hash_tfm {
64149 int (*init)(struct hash_desc *desc);
64150@@ -394,13 +394,13 @@ struct compress_tfm {
64151 int (*cot_decompress)(struct crypto_tfm *tfm,
64152 const u8 *src, unsigned int slen,
64153 u8 *dst, unsigned int *dlen);
64154-};
64155+} __no_const;
64156
64157 struct rng_tfm {
64158 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
64159 unsigned int dlen);
64160 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
64161-};
64162+} __no_const;
64163
64164 #define crt_ablkcipher crt_u.ablkcipher
64165 #define crt_aead crt_u.aead
64166diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
64167index 7925bf0..d5143d2 100644
64168--- a/include/linux/decompress/mm.h
64169+++ b/include/linux/decompress/mm.h
64170@@ -77,7 +77,7 @@ static void free(void *where)
64171 * warnings when not needed (indeed large_malloc / large_free are not
64172 * needed by inflate */
64173
64174-#define malloc(a) kmalloc(a, GFP_KERNEL)
64175+#define malloc(a) kmalloc((a), GFP_KERNEL)
64176 #define free(a) kfree(a)
64177
64178 #define large_malloc(a) vmalloc(a)
64179diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
64180index 94af418..b1ca7a2 100644
64181--- a/include/linux/dma-mapping.h
64182+++ b/include/linux/dma-mapping.h
64183@@ -54,7 +54,7 @@ struct dma_map_ops {
64184 u64 (*get_required_mask)(struct device *dev);
64185 #endif
64186 int is_phys;
64187-};
64188+} __do_const;
64189
64190 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
64191
64192diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
64193index d3201e4..8281e63 100644
64194--- a/include/linux/dmaengine.h
64195+++ b/include/linux/dmaengine.h
64196@@ -1018,9 +1018,9 @@ struct dma_pinned_list {
64197 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
64198 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
64199
64200-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
64201+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
64202 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
64203-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
64204+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
64205 struct dma_pinned_list *pinned_list, struct page *page,
64206 unsigned int offset, size_t len);
64207
64208diff --git a/include/linux/efi.h b/include/linux/efi.h
64209index 7a9498a..155713d 100644
64210--- a/include/linux/efi.h
64211+++ b/include/linux/efi.h
64212@@ -733,6 +733,7 @@ struct efivar_operations {
64213 efi_set_variable_t *set_variable;
64214 efi_query_variable_info_t *query_variable_info;
64215 };
64216+typedef struct efivar_operations __no_const efivar_operations_no_const;
64217
64218 struct efivars {
64219 /*
64220diff --git a/include/linux/elf.h b/include/linux/elf.h
64221index 8c9048e..16a4665 100644
64222--- a/include/linux/elf.h
64223+++ b/include/linux/elf.h
64224@@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
64225 #define elf_note elf32_note
64226 #define elf_addr_t Elf32_Off
64227 #define Elf_Half Elf32_Half
64228+#define elf_dyn Elf32_Dyn
64229
64230 #else
64231
64232@@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
64233 #define elf_note elf64_note
64234 #define elf_addr_t Elf64_Off
64235 #define Elf_Half Elf64_Half
64236+#define elf_dyn Elf64_Dyn
64237
64238 #endif
64239
64240diff --git a/include/linux/filter.h b/include/linux/filter.h
64241index c45eabc..baa0be5 100644
64242--- a/include/linux/filter.h
64243+++ b/include/linux/filter.h
64244@@ -20,6 +20,7 @@ struct compat_sock_fprog {
64245
64246 struct sk_buff;
64247 struct sock;
64248+struct bpf_jit_work;
64249
64250 struct sk_filter
64251 {
64252@@ -27,6 +28,9 @@ struct sk_filter
64253 unsigned int len; /* Number of filter blocks */
64254 unsigned int (*bpf_func)(const struct sk_buff *skb,
64255 const struct sock_filter *filter);
64256+#ifdef CONFIG_BPF_JIT
64257+ struct bpf_jit_work *work;
64258+#endif
64259 struct rcu_head rcu;
64260 struct sock_filter insns[0];
64261 };
64262diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
64263index 3044254..9767f41 100644
64264--- a/include/linux/frontswap.h
64265+++ b/include/linux/frontswap.h
64266@@ -11,7 +11,7 @@ struct frontswap_ops {
64267 int (*load)(unsigned, pgoff_t, struct page *);
64268 void (*invalidate_page)(unsigned, pgoff_t);
64269 void (*invalidate_area)(unsigned);
64270-};
64271+} __no_const;
64272
64273 extern bool frontswap_enabled;
64274 extern struct frontswap_ops
64275diff --git a/include/linux/fs.h b/include/linux/fs.h
64276index 7617ee0..b575199 100644
64277--- a/include/linux/fs.h
64278+++ b/include/linux/fs.h
64279@@ -1541,7 +1541,8 @@ struct file_operations {
64280 long (*fallocate)(struct file *file, int mode, loff_t offset,
64281 loff_t len);
64282 int (*show_fdinfo)(struct seq_file *m, struct file *f);
64283-};
64284+} __do_const;
64285+typedef struct file_operations __no_const file_operations_no_const;
64286
64287 struct inode_operations {
64288 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
64289@@ -2665,4 +2666,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
64290 inode->i_flags |= S_NOSEC;
64291 }
64292
64293+static inline bool is_sidechannel_device(const struct inode *inode)
64294+{
64295+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
64296+ umode_t mode = inode->i_mode;
64297+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
64298+#else
64299+ return false;
64300+#endif
64301+}
64302+
64303 #endif /* _LINUX_FS_H */
64304diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
64305index d0ae3a8..0244b34 100644
64306--- a/include/linux/fs_struct.h
64307+++ b/include/linux/fs_struct.h
64308@@ -6,7 +6,7 @@
64309 #include <linux/seqlock.h>
64310
64311 struct fs_struct {
64312- int users;
64313+ atomic_t users;
64314 spinlock_t lock;
64315 seqcount_t seq;
64316 int umask;
64317diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
64318index 5dfa0aa..6acf322 100644
64319--- a/include/linux/fscache-cache.h
64320+++ b/include/linux/fscache-cache.h
64321@@ -112,7 +112,7 @@ struct fscache_operation {
64322 fscache_operation_release_t release;
64323 };
64324
64325-extern atomic_t fscache_op_debug_id;
64326+extern atomic_unchecked_t fscache_op_debug_id;
64327 extern void fscache_op_work_func(struct work_struct *work);
64328
64329 extern void fscache_enqueue_operation(struct fscache_operation *);
64330@@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
64331 INIT_WORK(&op->work, fscache_op_work_func);
64332 atomic_set(&op->usage, 1);
64333 op->state = FSCACHE_OP_ST_INITIALISED;
64334- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
64335+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
64336 op->processor = processor;
64337 op->release = release;
64338 INIT_LIST_HEAD(&op->pend_link);
64339diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
64340index 0fbfb46..508eb0d 100644
64341--- a/include/linux/fsnotify.h
64342+++ b/include/linux/fsnotify.h
64343@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
64344 struct inode *inode = path->dentry->d_inode;
64345 __u32 mask = FS_ACCESS;
64346
64347+ if (is_sidechannel_device(inode))
64348+ return;
64349+
64350 if (S_ISDIR(inode->i_mode))
64351 mask |= FS_ISDIR;
64352
64353@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
64354 struct inode *inode = path->dentry->d_inode;
64355 __u32 mask = FS_MODIFY;
64356
64357+ if (is_sidechannel_device(inode))
64358+ return;
64359+
64360 if (S_ISDIR(inode->i_mode))
64361 mask |= FS_ISDIR;
64362
64363@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
64364 */
64365 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
64366 {
64367- return kstrdup(name, GFP_KERNEL);
64368+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
64369 }
64370
64371 /*
64372diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
64373index a3d4895..ddd2a50 100644
64374--- a/include/linux/ftrace_event.h
64375+++ b/include/linux/ftrace_event.h
64376@@ -272,7 +272,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
64377 extern int trace_add_event_call(struct ftrace_event_call *call);
64378 extern void trace_remove_event_call(struct ftrace_event_call *call);
64379
64380-#define is_signed_type(type) (((type)(-1)) < 0)
64381+#define is_signed_type(type) (((type)(-1)) < (type)1)
64382
64383 int trace_set_clr_event(const char *system, const char *event, int set);
64384
64385diff --git a/include/linux/genhd.h b/include/linux/genhd.h
64386index 79b8bba..86b539e 100644
64387--- a/include/linux/genhd.h
64388+++ b/include/linux/genhd.h
64389@@ -194,7 +194,7 @@ struct gendisk {
64390 struct kobject *slave_dir;
64391
64392 struct timer_rand_state *random;
64393- atomic_t sync_io; /* RAID */
64394+ atomic_unchecked_t sync_io; /* RAID */
64395 struct disk_events *ev;
64396 #ifdef CONFIG_BLK_DEV_INTEGRITY
64397 struct blk_integrity *integrity;
64398diff --git a/include/linux/gfp.h b/include/linux/gfp.h
64399index 0f615eb..5c3832f 100644
64400--- a/include/linux/gfp.h
64401+++ b/include/linux/gfp.h
64402@@ -35,6 +35,13 @@ struct vm_area_struct;
64403 #define ___GFP_NO_KSWAPD 0x400000u
64404 #define ___GFP_OTHER_NODE 0x800000u
64405 #define ___GFP_WRITE 0x1000000u
64406+
64407+#ifdef CONFIG_PAX_USERCOPY_SLABS
64408+#define ___GFP_USERCOPY 0x2000000u
64409+#else
64410+#define ___GFP_USERCOPY 0
64411+#endif
64412+
64413 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
64414
64415 /*
64416@@ -92,6 +99,7 @@ struct vm_area_struct;
64417 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
64418 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
64419 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
64420+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
64421
64422 /*
64423 * This may seem redundant, but it's a way of annotating false positives vs.
64424@@ -99,7 +107,7 @@ struct vm_area_struct;
64425 */
64426 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
64427
64428-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
64429+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
64430 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
64431
64432 /* This equals 0, but use constants in case they ever change */
64433@@ -153,6 +161,8 @@ struct vm_area_struct;
64434 /* 4GB DMA on some platforms */
64435 #define GFP_DMA32 __GFP_DMA32
64436
64437+#define GFP_USERCOPY __GFP_USERCOPY
64438+
64439 /* Convert GFP flags to their corresponding migrate type */
64440 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
64441 {
64442diff --git a/include/linux/gracl.h b/include/linux/gracl.h
64443new file mode 100644
64444index 0000000..ebe6d72
64445--- /dev/null
64446+++ b/include/linux/gracl.h
64447@@ -0,0 +1,319 @@
64448+#ifndef GR_ACL_H
64449+#define GR_ACL_H
64450+
64451+#include <linux/grdefs.h>
64452+#include <linux/resource.h>
64453+#include <linux/capability.h>
64454+#include <linux/dcache.h>
64455+#include <asm/resource.h>
64456+
64457+/* Major status information */
64458+
64459+#define GR_VERSION "grsecurity 2.9.1"
64460+#define GRSECURITY_VERSION 0x2901
64461+
64462+enum {
64463+ GR_SHUTDOWN = 0,
64464+ GR_ENABLE = 1,
64465+ GR_SPROLE = 2,
64466+ GR_RELOAD = 3,
64467+ GR_SEGVMOD = 4,
64468+ GR_STATUS = 5,
64469+ GR_UNSPROLE = 6,
64470+ GR_PASSSET = 7,
64471+ GR_SPROLEPAM = 8,
64472+};
64473+
64474+/* Password setup definitions
64475+ * kernel/grhash.c */
64476+enum {
64477+ GR_PW_LEN = 128,
64478+ GR_SALT_LEN = 16,
64479+ GR_SHA_LEN = 32,
64480+};
64481+
64482+enum {
64483+ GR_SPROLE_LEN = 64,
64484+};
64485+
64486+enum {
64487+ GR_NO_GLOB = 0,
64488+ GR_REG_GLOB,
64489+ GR_CREATE_GLOB
64490+};
64491+
64492+#define GR_NLIMITS 32
64493+
64494+/* Begin Data Structures */
64495+
64496+struct sprole_pw {
64497+ unsigned char *rolename;
64498+ unsigned char salt[GR_SALT_LEN];
64499+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
64500+};
64501+
64502+struct name_entry {
64503+ __u32 key;
64504+ ino_t inode;
64505+ dev_t device;
64506+ char *name;
64507+ __u16 len;
64508+ __u8 deleted;
64509+ struct name_entry *prev;
64510+ struct name_entry *next;
64511+};
64512+
64513+struct inodev_entry {
64514+ struct name_entry *nentry;
64515+ struct inodev_entry *prev;
64516+ struct inodev_entry *next;
64517+};
64518+
64519+struct acl_role_db {
64520+ struct acl_role_label **r_hash;
64521+ __u32 r_size;
64522+};
64523+
64524+struct inodev_db {
64525+ struct inodev_entry **i_hash;
64526+ __u32 i_size;
64527+};
64528+
64529+struct name_db {
64530+ struct name_entry **n_hash;
64531+ __u32 n_size;
64532+};
64533+
64534+struct crash_uid {
64535+ uid_t uid;
64536+ unsigned long expires;
64537+};
64538+
64539+struct gr_hash_struct {
64540+ void **table;
64541+ void **nametable;
64542+ void *first;
64543+ __u32 table_size;
64544+ __u32 used_size;
64545+ int type;
64546+};
64547+
64548+/* Userspace Grsecurity ACL data structures */
64549+
64550+struct acl_subject_label {
64551+ char *filename;
64552+ ino_t inode;
64553+ dev_t device;
64554+ __u32 mode;
64555+ kernel_cap_t cap_mask;
64556+ kernel_cap_t cap_lower;
64557+ kernel_cap_t cap_invert_audit;
64558+
64559+ struct rlimit res[GR_NLIMITS];
64560+ __u32 resmask;
64561+
64562+ __u8 user_trans_type;
64563+ __u8 group_trans_type;
64564+ uid_t *user_transitions;
64565+ gid_t *group_transitions;
64566+ __u16 user_trans_num;
64567+ __u16 group_trans_num;
64568+
64569+ __u32 sock_families[2];
64570+ __u32 ip_proto[8];
64571+ __u32 ip_type;
64572+ struct acl_ip_label **ips;
64573+ __u32 ip_num;
64574+ __u32 inaddr_any_override;
64575+
64576+ __u32 crashes;
64577+ unsigned long expires;
64578+
64579+ struct acl_subject_label *parent_subject;
64580+ struct gr_hash_struct *hash;
64581+ struct acl_subject_label *prev;
64582+ struct acl_subject_label *next;
64583+
64584+ struct acl_object_label **obj_hash;
64585+ __u32 obj_hash_size;
64586+ __u16 pax_flags;
64587+};
64588+
64589+struct role_allowed_ip {
64590+ __u32 addr;
64591+ __u32 netmask;
64592+
64593+ struct role_allowed_ip *prev;
64594+ struct role_allowed_ip *next;
64595+};
64596+
64597+struct role_transition {
64598+ char *rolename;
64599+
64600+ struct role_transition *prev;
64601+ struct role_transition *next;
64602+};
64603+
64604+struct acl_role_label {
64605+ char *rolename;
64606+ uid_t uidgid;
64607+ __u16 roletype;
64608+
64609+ __u16 auth_attempts;
64610+ unsigned long expires;
64611+
64612+ struct acl_subject_label *root_label;
64613+ struct gr_hash_struct *hash;
64614+
64615+ struct acl_role_label *prev;
64616+ struct acl_role_label *next;
64617+
64618+ struct role_transition *transitions;
64619+ struct role_allowed_ip *allowed_ips;
64620+ uid_t *domain_children;
64621+ __u16 domain_child_num;
64622+
64623+ umode_t umask;
64624+
64625+ struct acl_subject_label **subj_hash;
64626+ __u32 subj_hash_size;
64627+};
64628+
64629+struct user_acl_role_db {
64630+ struct acl_role_label **r_table;
64631+ __u32 num_pointers; /* Number of allocations to track */
64632+ __u32 num_roles; /* Number of roles */
64633+ __u32 num_domain_children; /* Number of domain children */
64634+ __u32 num_subjects; /* Number of subjects */
64635+ __u32 num_objects; /* Number of objects */
64636+};
64637+
64638+struct acl_object_label {
64639+ char *filename;
64640+ ino_t inode;
64641+ dev_t device;
64642+ __u32 mode;
64643+
64644+ struct acl_subject_label *nested;
64645+ struct acl_object_label *globbed;
64646+
64647+ /* next two structures not used */
64648+
64649+ struct acl_object_label *prev;
64650+ struct acl_object_label *next;
64651+};
64652+
64653+struct acl_ip_label {
64654+ char *iface;
64655+ __u32 addr;
64656+ __u32 netmask;
64657+ __u16 low, high;
64658+ __u8 mode;
64659+ __u32 type;
64660+ __u32 proto[8];
64661+
64662+ /* next two structures not used */
64663+
64664+ struct acl_ip_label *prev;
64665+ struct acl_ip_label *next;
64666+};
64667+
64668+struct gr_arg {
64669+ struct user_acl_role_db role_db;
64670+ unsigned char pw[GR_PW_LEN];
64671+ unsigned char salt[GR_SALT_LEN];
64672+ unsigned char sum[GR_SHA_LEN];
64673+ unsigned char sp_role[GR_SPROLE_LEN];
64674+ struct sprole_pw *sprole_pws;
64675+ dev_t segv_device;
64676+ ino_t segv_inode;
64677+ uid_t segv_uid;
64678+ __u16 num_sprole_pws;
64679+ __u16 mode;
64680+};
64681+
64682+struct gr_arg_wrapper {
64683+ struct gr_arg *arg;
64684+ __u32 version;
64685+ __u32 size;
64686+};
64687+
64688+struct subject_map {
64689+ struct acl_subject_label *user;
64690+ struct acl_subject_label *kernel;
64691+ struct subject_map *prev;
64692+ struct subject_map *next;
64693+};
64694+
64695+struct acl_subj_map_db {
64696+ struct subject_map **s_hash;
64697+ __u32 s_size;
64698+};
64699+
64700+/* End Data Structures Section */
64701+
64702+/* Hash functions generated by empirical testing by Brad Spengler
64703+ Makes good use of the low bits of the inode. Generally 0-1 times
64704+ in loop for successful match. 0-3 for unsuccessful match.
64705+ Shift/add algorithm with modulus of table size and an XOR*/
64706+
64707+static __inline__ unsigned int
64708+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
64709+{
64710+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
64711+}
64712+
64713+ static __inline__ unsigned int
64714+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
64715+{
64716+ return ((const unsigned long)userp % sz);
64717+}
64718+
64719+static __inline__ unsigned int
64720+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
64721+{
64722+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
64723+}
64724+
64725+static __inline__ unsigned int
64726+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
64727+{
64728+ return full_name_hash((const unsigned char *)name, len) % sz;
64729+}
64730+
64731+#define FOR_EACH_ROLE_START(role) \
64732+ role = role_list; \
64733+ while (role) {
64734+
64735+#define FOR_EACH_ROLE_END(role) \
64736+ role = role->prev; \
64737+ }
64738+
64739+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
64740+ subj = NULL; \
64741+ iter = 0; \
64742+ while (iter < role->subj_hash_size) { \
64743+ if (subj == NULL) \
64744+ subj = role->subj_hash[iter]; \
64745+ if (subj == NULL) { \
64746+ iter++; \
64747+ continue; \
64748+ }
64749+
64750+#define FOR_EACH_SUBJECT_END(subj,iter) \
64751+ subj = subj->next; \
64752+ if (subj == NULL) \
64753+ iter++; \
64754+ }
64755+
64756+
64757+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
64758+ subj = role->hash->first; \
64759+ while (subj != NULL) {
64760+
64761+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
64762+ subj = subj->next; \
64763+ }
64764+
64765+#endif
64766+
64767diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
64768new file mode 100644
64769index 0000000..323ecf2
64770--- /dev/null
64771+++ b/include/linux/gralloc.h
64772@@ -0,0 +1,9 @@
64773+#ifndef __GRALLOC_H
64774+#define __GRALLOC_H
64775+
64776+void acl_free_all(void);
64777+int acl_alloc_stack_init(unsigned long size);
64778+void *acl_alloc(unsigned long len);
64779+void *acl_alloc_num(unsigned long num, unsigned long len);
64780+
64781+#endif
64782diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
64783new file mode 100644
64784index 0000000..be66033
64785--- /dev/null
64786+++ b/include/linux/grdefs.h
64787@@ -0,0 +1,140 @@
64788+#ifndef GRDEFS_H
64789+#define GRDEFS_H
64790+
64791+/* Begin grsecurity status declarations */
64792+
64793+enum {
64794+ GR_READY = 0x01,
64795+ GR_STATUS_INIT = 0x00 // disabled state
64796+};
64797+
64798+/* Begin ACL declarations */
64799+
64800+/* Role flags */
64801+
64802+enum {
64803+ GR_ROLE_USER = 0x0001,
64804+ GR_ROLE_GROUP = 0x0002,
64805+ GR_ROLE_DEFAULT = 0x0004,
64806+ GR_ROLE_SPECIAL = 0x0008,
64807+ GR_ROLE_AUTH = 0x0010,
64808+ GR_ROLE_NOPW = 0x0020,
64809+ GR_ROLE_GOD = 0x0040,
64810+ GR_ROLE_LEARN = 0x0080,
64811+ GR_ROLE_TPE = 0x0100,
64812+ GR_ROLE_DOMAIN = 0x0200,
64813+ GR_ROLE_PAM = 0x0400,
64814+ GR_ROLE_PERSIST = 0x0800
64815+};
64816+
64817+/* ACL Subject and Object mode flags */
64818+enum {
64819+ GR_DELETED = 0x80000000
64820+};
64821+
64822+/* ACL Object-only mode flags */
64823+enum {
64824+ GR_READ = 0x00000001,
64825+ GR_APPEND = 0x00000002,
64826+ GR_WRITE = 0x00000004,
64827+ GR_EXEC = 0x00000008,
64828+ GR_FIND = 0x00000010,
64829+ GR_INHERIT = 0x00000020,
64830+ GR_SETID = 0x00000040,
64831+ GR_CREATE = 0x00000080,
64832+ GR_DELETE = 0x00000100,
64833+ GR_LINK = 0x00000200,
64834+ GR_AUDIT_READ = 0x00000400,
64835+ GR_AUDIT_APPEND = 0x00000800,
64836+ GR_AUDIT_WRITE = 0x00001000,
64837+ GR_AUDIT_EXEC = 0x00002000,
64838+ GR_AUDIT_FIND = 0x00004000,
64839+ GR_AUDIT_INHERIT= 0x00008000,
64840+ GR_AUDIT_SETID = 0x00010000,
64841+ GR_AUDIT_CREATE = 0x00020000,
64842+ GR_AUDIT_DELETE = 0x00040000,
64843+ GR_AUDIT_LINK = 0x00080000,
64844+ GR_PTRACERD = 0x00100000,
64845+ GR_NOPTRACE = 0x00200000,
64846+ GR_SUPPRESS = 0x00400000,
64847+ GR_NOLEARN = 0x00800000,
64848+ GR_INIT_TRANSFER= 0x01000000
64849+};
64850+
64851+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
64852+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
64853+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
64854+
64855+/* ACL subject-only mode flags */
64856+enum {
64857+ GR_KILL = 0x00000001,
64858+ GR_VIEW = 0x00000002,
64859+ GR_PROTECTED = 0x00000004,
64860+ GR_LEARN = 0x00000008,
64861+ GR_OVERRIDE = 0x00000010,
64862+ /* just a placeholder, this mode is only used in userspace */
64863+ GR_DUMMY = 0x00000020,
64864+ GR_PROTSHM = 0x00000040,
64865+ GR_KILLPROC = 0x00000080,
64866+ GR_KILLIPPROC = 0x00000100,
64867+ /* just a placeholder, this mode is only used in userspace */
64868+ GR_NOTROJAN = 0x00000200,
64869+ GR_PROTPROCFD = 0x00000400,
64870+ GR_PROCACCT = 0x00000800,
64871+ GR_RELAXPTRACE = 0x00001000,
64872+ //GR_NESTED = 0x00002000,
64873+ GR_INHERITLEARN = 0x00004000,
64874+ GR_PROCFIND = 0x00008000,
64875+ GR_POVERRIDE = 0x00010000,
64876+ GR_KERNELAUTH = 0x00020000,
64877+ GR_ATSECURE = 0x00040000,
64878+ GR_SHMEXEC = 0x00080000
64879+};
64880+
64881+enum {
64882+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
64883+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
64884+ GR_PAX_ENABLE_MPROTECT = 0x0004,
64885+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
64886+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
64887+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
64888+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
64889+ GR_PAX_DISABLE_MPROTECT = 0x0400,
64890+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
64891+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
64892+};
64893+
64894+enum {
64895+ GR_ID_USER = 0x01,
64896+ GR_ID_GROUP = 0x02,
64897+};
64898+
64899+enum {
64900+ GR_ID_ALLOW = 0x01,
64901+ GR_ID_DENY = 0x02,
64902+};
64903+
64904+#define GR_CRASH_RES 31
64905+#define GR_UIDTABLE_MAX 500
64906+
64907+/* begin resource learning section */
64908+enum {
64909+ GR_RLIM_CPU_BUMP = 60,
64910+ GR_RLIM_FSIZE_BUMP = 50000,
64911+ GR_RLIM_DATA_BUMP = 10000,
64912+ GR_RLIM_STACK_BUMP = 1000,
64913+ GR_RLIM_CORE_BUMP = 10000,
64914+ GR_RLIM_RSS_BUMP = 500000,
64915+ GR_RLIM_NPROC_BUMP = 1,
64916+ GR_RLIM_NOFILE_BUMP = 5,
64917+ GR_RLIM_MEMLOCK_BUMP = 50000,
64918+ GR_RLIM_AS_BUMP = 500000,
64919+ GR_RLIM_LOCKS_BUMP = 2,
64920+ GR_RLIM_SIGPENDING_BUMP = 5,
64921+ GR_RLIM_MSGQUEUE_BUMP = 10000,
64922+ GR_RLIM_NICE_BUMP = 1,
64923+ GR_RLIM_RTPRIO_BUMP = 1,
64924+ GR_RLIM_RTTIME_BUMP = 1000000
64925+};
64926+
64927+#endif
64928diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
64929new file mode 100644
64930index 0000000..baa6e96
64931--- /dev/null
64932+++ b/include/linux/grinternal.h
64933@@ -0,0 +1,215 @@
64934+#ifndef __GRINTERNAL_H
64935+#define __GRINTERNAL_H
64936+
64937+#ifdef CONFIG_GRKERNSEC
64938+
64939+#include <linux/fs.h>
64940+#include <linux/mnt_namespace.h>
64941+#include <linux/nsproxy.h>
64942+#include <linux/gracl.h>
64943+#include <linux/grdefs.h>
64944+#include <linux/grmsg.h>
64945+
64946+void gr_add_learn_entry(const char *fmt, ...)
64947+ __attribute__ ((format (printf, 1, 2)));
64948+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
64949+ const struct vfsmount *mnt);
64950+__u32 gr_check_create(const struct dentry *new_dentry,
64951+ const struct dentry *parent,
64952+ const struct vfsmount *mnt, const __u32 mode);
64953+int gr_check_protected_task(const struct task_struct *task);
64954+__u32 to_gr_audit(const __u32 reqmode);
64955+int gr_set_acls(const int type);
64956+int gr_apply_subject_to_task(struct task_struct *task);
64957+int gr_acl_is_enabled(void);
64958+char gr_roletype_to_char(void);
64959+
64960+void gr_handle_alertkill(struct task_struct *task);
64961+char *gr_to_filename(const struct dentry *dentry,
64962+ const struct vfsmount *mnt);
64963+char *gr_to_filename1(const struct dentry *dentry,
64964+ const struct vfsmount *mnt);
64965+char *gr_to_filename2(const struct dentry *dentry,
64966+ const struct vfsmount *mnt);
64967+char *gr_to_filename3(const struct dentry *dentry,
64968+ const struct vfsmount *mnt);
64969+
64970+extern int grsec_enable_ptrace_readexec;
64971+extern int grsec_enable_harden_ptrace;
64972+extern int grsec_enable_link;
64973+extern int grsec_enable_fifo;
64974+extern int grsec_enable_execve;
64975+extern int grsec_enable_shm;
64976+extern int grsec_enable_execlog;
64977+extern int grsec_enable_signal;
64978+extern int grsec_enable_audit_ptrace;
64979+extern int grsec_enable_forkfail;
64980+extern int grsec_enable_time;
64981+extern int grsec_enable_rofs;
64982+extern int grsec_enable_chroot_shmat;
64983+extern int grsec_enable_chroot_mount;
64984+extern int grsec_enable_chroot_double;
64985+extern int grsec_enable_chroot_pivot;
64986+extern int grsec_enable_chroot_chdir;
64987+extern int grsec_enable_chroot_chmod;
64988+extern int grsec_enable_chroot_mknod;
64989+extern int grsec_enable_chroot_fchdir;
64990+extern int grsec_enable_chroot_nice;
64991+extern int grsec_enable_chroot_execlog;
64992+extern int grsec_enable_chroot_caps;
64993+extern int grsec_enable_chroot_sysctl;
64994+extern int grsec_enable_chroot_unix;
64995+extern int grsec_enable_symlinkown;
64996+extern int grsec_symlinkown_gid;
64997+extern int grsec_enable_tpe;
64998+extern int grsec_tpe_gid;
64999+extern int grsec_enable_tpe_all;
65000+extern int grsec_enable_tpe_invert;
65001+extern int grsec_enable_socket_all;
65002+extern int grsec_socket_all_gid;
65003+extern int grsec_enable_socket_client;
65004+extern int grsec_socket_client_gid;
65005+extern int grsec_enable_socket_server;
65006+extern int grsec_socket_server_gid;
65007+extern int grsec_audit_gid;
65008+extern int grsec_enable_group;
65009+extern int grsec_enable_audit_textrel;
65010+extern int grsec_enable_log_rwxmaps;
65011+extern int grsec_enable_mount;
65012+extern int grsec_enable_chdir;
65013+extern int grsec_resource_logging;
65014+extern int grsec_enable_blackhole;
65015+extern int grsec_lastack_retries;
65016+extern int grsec_enable_brute;
65017+extern int grsec_lock;
65018+
65019+extern spinlock_t grsec_alert_lock;
65020+extern unsigned long grsec_alert_wtime;
65021+extern unsigned long grsec_alert_fyet;
65022+
65023+extern spinlock_t grsec_audit_lock;
65024+
65025+extern rwlock_t grsec_exec_file_lock;
65026+
65027+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
65028+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
65029+ (tsk)->exec_file->f_vfsmnt) : "/")
65030+
65031+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
65032+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
65033+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
65034+
65035+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
65036+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
65037+ (tsk)->exec_file->f_vfsmnt) : "/")
65038+
65039+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
65040+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
65041+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
65042+
65043+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
65044+
65045+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
65046+
65047+#define GR_CHROOT_CAPS {{ \
65048+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
65049+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
65050+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
65051+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
65052+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
65053+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
65054+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
65055+
65056+#define security_learn(normal_msg,args...) \
65057+({ \
65058+ read_lock(&grsec_exec_file_lock); \
65059+ gr_add_learn_entry(normal_msg "\n", ## args); \
65060+ read_unlock(&grsec_exec_file_lock); \
65061+})
65062+
65063+enum {
65064+ GR_DO_AUDIT,
65065+ GR_DONT_AUDIT,
65066+ /* used for non-audit messages that we shouldn't kill the task on */
65067+ GR_DONT_AUDIT_GOOD
65068+};
65069+
65070+enum {
65071+ GR_TTYSNIFF,
65072+ GR_RBAC,
65073+ GR_RBAC_STR,
65074+ GR_STR_RBAC,
65075+ GR_RBAC_MODE2,
65076+ GR_RBAC_MODE3,
65077+ GR_FILENAME,
65078+ GR_SYSCTL_HIDDEN,
65079+ GR_NOARGS,
65080+ GR_ONE_INT,
65081+ GR_ONE_INT_TWO_STR,
65082+ GR_ONE_STR,
65083+ GR_STR_INT,
65084+ GR_TWO_STR_INT,
65085+ GR_TWO_INT,
65086+ GR_TWO_U64,
65087+ GR_THREE_INT,
65088+ GR_FIVE_INT_TWO_STR,
65089+ GR_TWO_STR,
65090+ GR_THREE_STR,
65091+ GR_FOUR_STR,
65092+ GR_STR_FILENAME,
65093+ GR_FILENAME_STR,
65094+ GR_FILENAME_TWO_INT,
65095+ GR_FILENAME_TWO_INT_STR,
65096+ GR_TEXTREL,
65097+ GR_PTRACE,
65098+ GR_RESOURCE,
65099+ GR_CAP,
65100+ GR_SIG,
65101+ GR_SIG2,
65102+ GR_CRASH1,
65103+ GR_CRASH2,
65104+ GR_PSACCT,
65105+ GR_RWXMAP
65106+};
65107+
65108+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
65109+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
65110+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
65111+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
65112+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
65113+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
65114+#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)
65115+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
65116+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
65117+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
65118+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
65119+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
65120+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
65121+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
65122+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
65123+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
65124+#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)
65125+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
65126+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
65127+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
65128+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
65129+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
65130+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
65131+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
65132+#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)
65133+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
65134+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
65135+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
65136+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
65137+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
65138+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
65139+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
65140+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
65141+#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)
65142+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
65143+
65144+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
65145+
65146+#endif
65147+
65148+#endif
65149diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
65150new file mode 100644
65151index 0000000..2bd4c8d
65152--- /dev/null
65153+++ b/include/linux/grmsg.h
65154@@ -0,0 +1,111 @@
65155+#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"
65156+#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"
65157+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
65158+#define GR_STOPMOD_MSG "denied modification of module state by "
65159+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
65160+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
65161+#define GR_IOPERM_MSG "denied use of ioperm() by "
65162+#define GR_IOPL_MSG "denied use of iopl() by "
65163+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
65164+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
65165+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
65166+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
65167+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
65168+#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"
65169+#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"
65170+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
65171+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
65172+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
65173+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
65174+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
65175+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
65176+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
65177+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
65178+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
65179+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
65180+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
65181+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
65182+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
65183+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
65184+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
65185+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
65186+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
65187+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
65188+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
65189+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
65190+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
65191+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
65192+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
65193+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
65194+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
65195+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
65196+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
65197+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
65198+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
65199+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
65200+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
65201+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
65202+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
65203+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
65204+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
65205+#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"
65206+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
65207+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
65208+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
65209+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
65210+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
65211+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
65212+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
65213+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
65214+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
65215+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
65216+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
65217+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
65218+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
65219+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
65220+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
65221+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
65222+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
65223+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
65224+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
65225+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
65226+#define GR_FAILFORK_MSG "failed fork with errno %s by "
65227+#define GR_NICE_CHROOT_MSG "denied priority change by "
65228+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
65229+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
65230+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
65231+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
65232+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
65233+#define GR_TIME_MSG "time set by "
65234+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
65235+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
65236+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
65237+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
65238+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
65239+#define GR_BIND_MSG "denied bind() by "
65240+#define GR_CONNECT_MSG "denied connect() by "
65241+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
65242+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
65243+#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"
65244+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
65245+#define GR_CAP_ACL_MSG "use of %s denied for "
65246+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
65247+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
65248+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
65249+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
65250+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
65251+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
65252+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
65253+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
65254+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
65255+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
65256+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
65257+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
65258+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
65259+#define GR_VM86_MSG "denied use of vm86 by "
65260+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
65261+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
65262+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
65263+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
65264+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
65265+#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 "
65266diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
65267new file mode 100644
65268index 0000000..c5e5913
65269--- /dev/null
65270+++ b/include/linux/grsecurity.h
65271@@ -0,0 +1,257 @@
65272+#ifndef GR_SECURITY_H
65273+#define GR_SECURITY_H
65274+#include <linux/fs.h>
65275+#include <linux/fs_struct.h>
65276+#include <linux/binfmts.h>
65277+#include <linux/gracl.h>
65278+
65279+/* notify of brain-dead configs */
65280+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65281+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
65282+#endif
65283+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
65284+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
65285+#endif
65286+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
65287+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
65288+#endif
65289+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
65290+#error "CONFIG_PAX enabled, but no PaX options are enabled."
65291+#endif
65292+
65293+#include <linux/compat.h>
65294+
65295+struct user_arg_ptr {
65296+#ifdef CONFIG_COMPAT
65297+ bool is_compat;
65298+#endif
65299+ union {
65300+ const char __user *const __user *native;
65301+#ifdef CONFIG_COMPAT
65302+ const compat_uptr_t __user *compat;
65303+#endif
65304+ } ptr;
65305+};
65306+
65307+void gr_handle_brute_attach(unsigned long mm_flags);
65308+void gr_handle_brute_check(void);
65309+void gr_handle_kernel_exploit(void);
65310+int gr_process_user_ban(void);
65311+
65312+char gr_roletype_to_char(void);
65313+
65314+int gr_acl_enable_at_secure(void);
65315+
65316+int gr_check_user_change(int real, int effective, int fs);
65317+int gr_check_group_change(int real, int effective, int fs);
65318+
65319+void gr_del_task_from_ip_table(struct task_struct *p);
65320+
65321+int gr_pid_is_chrooted(struct task_struct *p);
65322+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
65323+int gr_handle_chroot_nice(void);
65324+int gr_handle_chroot_sysctl(const int op);
65325+int gr_handle_chroot_setpriority(struct task_struct *p,
65326+ const int niceval);
65327+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
65328+int gr_handle_chroot_chroot(const struct dentry *dentry,
65329+ const struct vfsmount *mnt);
65330+void gr_handle_chroot_chdir(struct path *path);
65331+int gr_handle_chroot_chmod(const struct dentry *dentry,
65332+ const struct vfsmount *mnt, const int mode);
65333+int gr_handle_chroot_mknod(const struct dentry *dentry,
65334+ const struct vfsmount *mnt, const int mode);
65335+int gr_handle_chroot_mount(const struct dentry *dentry,
65336+ const struct vfsmount *mnt,
65337+ const char *dev_name);
65338+int gr_handle_chroot_pivot(void);
65339+int gr_handle_chroot_unix(const pid_t pid);
65340+
65341+int gr_handle_rawio(const struct inode *inode);
65342+
65343+void gr_handle_ioperm(void);
65344+void gr_handle_iopl(void);
65345+
65346+umode_t gr_acl_umask(void);
65347+
65348+int gr_tpe_allow(const struct file *file);
65349+
65350+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
65351+void gr_clear_chroot_entries(struct task_struct *task);
65352+
65353+void gr_log_forkfail(const int retval);
65354+void gr_log_timechange(void);
65355+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
65356+void gr_log_chdir(const struct dentry *dentry,
65357+ const struct vfsmount *mnt);
65358+void gr_log_chroot_exec(const struct dentry *dentry,
65359+ const struct vfsmount *mnt);
65360+void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
65361+void gr_log_remount(const char *devname, const int retval);
65362+void gr_log_unmount(const char *devname, const int retval);
65363+void gr_log_mount(const char *from, const char *to, const int retval);
65364+void gr_log_textrel(struct vm_area_struct *vma);
65365+void gr_log_rwxmmap(struct file *file);
65366+void gr_log_rwxmprotect(struct file *file);
65367+
65368+int gr_handle_follow_link(const struct inode *parent,
65369+ const struct inode *inode,
65370+ const struct dentry *dentry,
65371+ const struct vfsmount *mnt);
65372+int gr_handle_fifo(const struct dentry *dentry,
65373+ const struct vfsmount *mnt,
65374+ const struct dentry *dir, const int flag,
65375+ const int acc_mode);
65376+int gr_handle_hardlink(const struct dentry *dentry,
65377+ const struct vfsmount *mnt,
65378+ struct inode *inode,
65379+ const int mode, const struct filename *to);
65380+
65381+int gr_is_capable(const int cap);
65382+int gr_is_capable_nolog(const int cap);
65383+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
65384+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
65385+
65386+void gr_copy_label(struct task_struct *tsk);
65387+void gr_handle_crash(struct task_struct *task, const int sig);
65388+int gr_handle_signal(const struct task_struct *p, const int sig);
65389+int gr_check_crash_uid(const uid_t uid);
65390+int gr_check_protected_task(const struct task_struct *task);
65391+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
65392+int gr_acl_handle_mmap(const struct file *file,
65393+ const unsigned long prot);
65394+int gr_acl_handle_mprotect(const struct file *file,
65395+ const unsigned long prot);
65396+int gr_check_hidden_task(const struct task_struct *tsk);
65397+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
65398+ const struct vfsmount *mnt);
65399+__u32 gr_acl_handle_utime(const struct dentry *dentry,
65400+ const struct vfsmount *mnt);
65401+__u32 gr_acl_handle_access(const struct dentry *dentry,
65402+ const struct vfsmount *mnt, const int fmode);
65403+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
65404+ const struct vfsmount *mnt, umode_t *mode);
65405+__u32 gr_acl_handle_chown(const struct dentry *dentry,
65406+ const struct vfsmount *mnt);
65407+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
65408+ const struct vfsmount *mnt);
65409+int gr_handle_ptrace(struct task_struct *task, const long request);
65410+int gr_handle_proc_ptrace(struct task_struct *task);
65411+__u32 gr_acl_handle_execve(const struct dentry *dentry,
65412+ const struct vfsmount *mnt);
65413+int gr_check_crash_exec(const struct file *filp);
65414+int gr_acl_is_enabled(void);
65415+void gr_set_kernel_label(struct task_struct *task);
65416+void gr_set_role_label(struct task_struct *task, const uid_t uid,
65417+ const gid_t gid);
65418+int gr_set_proc_label(const struct dentry *dentry,
65419+ const struct vfsmount *mnt,
65420+ const int unsafe_flags);
65421+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
65422+ const struct vfsmount *mnt);
65423+__u32 gr_acl_handle_open(const struct dentry *dentry,
65424+ const struct vfsmount *mnt, int acc_mode);
65425+__u32 gr_acl_handle_creat(const struct dentry *dentry,
65426+ const struct dentry *p_dentry,
65427+ const struct vfsmount *p_mnt,
65428+ int open_flags, int acc_mode, const int imode);
65429+void gr_handle_create(const struct dentry *dentry,
65430+ const struct vfsmount *mnt);
65431+void gr_handle_proc_create(const struct dentry *dentry,
65432+ const struct inode *inode);
65433+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
65434+ const struct dentry *parent_dentry,
65435+ const struct vfsmount *parent_mnt,
65436+ const int mode);
65437+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
65438+ const struct dentry *parent_dentry,
65439+ const struct vfsmount *parent_mnt);
65440+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
65441+ const struct vfsmount *mnt);
65442+void gr_handle_delete(const ino_t ino, const dev_t dev);
65443+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
65444+ const struct vfsmount *mnt);
65445+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
65446+ const struct dentry *parent_dentry,
65447+ const struct vfsmount *parent_mnt,
65448+ const struct filename *from);
65449+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
65450+ const struct dentry *parent_dentry,
65451+ const struct vfsmount *parent_mnt,
65452+ const struct dentry *old_dentry,
65453+ const struct vfsmount *old_mnt, const struct filename *to);
65454+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
65455+int gr_acl_handle_rename(struct dentry *new_dentry,
65456+ struct dentry *parent_dentry,
65457+ const struct vfsmount *parent_mnt,
65458+ struct dentry *old_dentry,
65459+ struct inode *old_parent_inode,
65460+ struct vfsmount *old_mnt, const struct filename *newname);
65461+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
65462+ struct dentry *old_dentry,
65463+ struct dentry *new_dentry,
65464+ struct vfsmount *mnt, const __u8 replace);
65465+__u32 gr_check_link(const struct dentry *new_dentry,
65466+ const struct dentry *parent_dentry,
65467+ const struct vfsmount *parent_mnt,
65468+ const struct dentry *old_dentry,
65469+ const struct vfsmount *old_mnt);
65470+int gr_acl_handle_filldir(const struct file *file, const char *name,
65471+ const unsigned int namelen, const ino_t ino);
65472+
65473+__u32 gr_acl_handle_unix(const struct dentry *dentry,
65474+ const struct vfsmount *mnt);
65475+void gr_acl_handle_exit(void);
65476+void gr_acl_handle_psacct(struct task_struct *task, const long code);
65477+int gr_acl_handle_procpidmem(const struct task_struct *task);
65478+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
65479+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
65480+void gr_audit_ptrace(struct task_struct *task);
65481+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
65482+void gr_put_exec_file(struct task_struct *task);
65483+
65484+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
65485+
65486+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
65487+extern void gr_learn_resource(const struct task_struct *task, const int res,
65488+ const unsigned long wanted, const int gt);
65489+#else
65490+static inline void gr_learn_resource(const struct task_struct *task, const int res,
65491+ const unsigned long wanted, const int gt)
65492+{
65493+}
65494+#endif
65495+
65496+#ifdef CONFIG_GRKERNSEC_RESLOG
65497+extern void gr_log_resource(const struct task_struct *task, const int res,
65498+ const unsigned long wanted, const int gt);
65499+#else
65500+static inline void gr_log_resource(const struct task_struct *task, const int res,
65501+ const unsigned long wanted, const int gt)
65502+{
65503+}
65504+#endif
65505+
65506+#ifdef CONFIG_GRKERNSEC
65507+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
65508+void gr_handle_vm86(void);
65509+void gr_handle_mem_readwrite(u64 from, u64 to);
65510+
65511+void gr_log_badprocpid(const char *entry);
65512+
65513+extern int grsec_enable_dmesg;
65514+extern int grsec_disable_privio;
65515+
65516+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
65517+extern int grsec_proc_gid;
65518+#endif
65519+
65520+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
65521+extern int grsec_enable_chroot_findtask;
65522+#endif
65523+#ifdef CONFIG_GRKERNSEC_SETXID
65524+extern int grsec_enable_setxid;
65525+#endif
65526+#endif
65527+
65528+#endif
65529diff --git a/include/linux/grsock.h b/include/linux/grsock.h
65530new file mode 100644
65531index 0000000..e7ffaaf
65532--- /dev/null
65533+++ b/include/linux/grsock.h
65534@@ -0,0 +1,19 @@
65535+#ifndef __GRSOCK_H
65536+#define __GRSOCK_H
65537+
65538+extern void gr_attach_curr_ip(const struct sock *sk);
65539+extern int gr_handle_sock_all(const int family, const int type,
65540+ const int protocol);
65541+extern int gr_handle_sock_server(const struct sockaddr *sck);
65542+extern int gr_handle_sock_server_other(const struct sock *sck);
65543+extern int gr_handle_sock_client(const struct sockaddr *sck);
65544+extern int gr_search_connect(struct socket * sock,
65545+ struct sockaddr_in * addr);
65546+extern int gr_search_bind(struct socket * sock,
65547+ struct sockaddr_in * addr);
65548+extern int gr_search_listen(struct socket * sock);
65549+extern int gr_search_accept(struct socket * sock);
65550+extern int gr_search_socket(const int domain, const int type,
65551+ const int protocol);
65552+
65553+#endif
65554diff --git a/include/linux/highmem.h b/include/linux/highmem.h
65555index ef788b5..ac41b7b 100644
65556--- a/include/linux/highmem.h
65557+++ b/include/linux/highmem.h
65558@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
65559 kunmap_atomic(kaddr);
65560 }
65561
65562+static inline void sanitize_highpage(struct page *page)
65563+{
65564+ void *kaddr;
65565+ unsigned long flags;
65566+
65567+ local_irq_save(flags);
65568+ kaddr = kmap_atomic(page);
65569+ clear_page(kaddr);
65570+ kunmap_atomic(kaddr);
65571+ local_irq_restore(flags);
65572+}
65573+
65574 static inline void zero_user_segments(struct page *page,
65575 unsigned start1, unsigned end1,
65576 unsigned start2, unsigned end2)
65577diff --git a/include/linux/i2c.h b/include/linux/i2c.h
65578index d0c4db7..61b3577 100644
65579--- a/include/linux/i2c.h
65580+++ b/include/linux/i2c.h
65581@@ -369,6 +369,7 @@ struct i2c_algorithm {
65582 /* To determine what the adapter supports */
65583 u32 (*functionality) (struct i2c_adapter *);
65584 };
65585+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
65586
65587 /*
65588 * i2c_adapter is the structure used to identify a physical i2c bus along
65589diff --git a/include/linux/i2o.h b/include/linux/i2o.h
65590index d23c3c2..eb63c81 100644
65591--- a/include/linux/i2o.h
65592+++ b/include/linux/i2o.h
65593@@ -565,7 +565,7 @@ struct i2o_controller {
65594 struct i2o_device *exec; /* Executive */
65595 #if BITS_PER_LONG == 64
65596 spinlock_t context_list_lock; /* lock for context_list */
65597- atomic_t context_list_counter; /* needed for unique contexts */
65598+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
65599 struct list_head context_list; /* list of context id's
65600 and pointers */
65601 #endif
65602diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
65603index aff7ad8..3942bbd 100644
65604--- a/include/linux/if_pppox.h
65605+++ b/include/linux/if_pppox.h
65606@@ -76,7 +76,7 @@ struct pppox_proto {
65607 int (*ioctl)(struct socket *sock, unsigned int cmd,
65608 unsigned long arg);
65609 struct module *owner;
65610-};
65611+} __do_const;
65612
65613 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
65614 extern void unregister_pppox_proto(int proto_num);
65615diff --git a/include/linux/init.h b/include/linux/init.h
65616index 10ed4f4..8e8490d 100644
65617--- a/include/linux/init.h
65618+++ b/include/linux/init.h
65619@@ -39,9 +39,36 @@
65620 * Also note, that this data cannot be "const".
65621 */
65622
65623+#ifdef MODULE
65624+#define add_init_latent_entropy
65625+#define add_devinit_latent_entropy
65626+#define add_cpuinit_latent_entropy
65627+#define add_meminit_latent_entropy
65628+#else
65629+#define add_init_latent_entropy __latent_entropy
65630+
65631+#ifdef CONFIG_HOTPLUG
65632+#define add_devinit_latent_entropy
65633+#else
65634+#define add_devinit_latent_entropy __latent_entropy
65635+#endif
65636+
65637+#ifdef CONFIG_HOTPLUG_CPU
65638+#define add_cpuinit_latent_entropy
65639+#else
65640+#define add_cpuinit_latent_entropy __latent_entropy
65641+#endif
65642+
65643+#ifdef CONFIG_MEMORY_HOTPLUG
65644+#define add_meminit_latent_entropy
65645+#else
65646+#define add_meminit_latent_entropy __latent_entropy
65647+#endif
65648+#endif
65649+
65650 /* These are for everybody (although not all archs will actually
65651 discard it in modules) */
65652-#define __init __section(.init.text) __cold notrace
65653+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
65654 #define __initdata __section(.init.data)
65655 #define __initconst __constsection(.init.rodata)
65656 #define __exitdata __section(.exit.data)
65657@@ -94,7 +121,7 @@
65658 #define __exit __section(.exit.text) __exitused __cold notrace
65659
65660 /* Used for HOTPLUG_CPU */
65661-#define __cpuinit __section(.cpuinit.text) __cold notrace
65662+#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
65663 #define __cpuinitdata __section(.cpuinit.data)
65664 #define __cpuinitconst __constsection(.cpuinit.rodata)
65665 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
65666@@ -102,7 +129,7 @@
65667 #define __cpuexitconst __constsection(.cpuexit.rodata)
65668
65669 /* Used for MEMORY_HOTPLUG */
65670-#define __meminit __section(.meminit.text) __cold notrace
65671+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
65672 #define __meminitdata __section(.meminit.data)
65673 #define __meminitconst __constsection(.meminit.rodata)
65674 #define __memexit __section(.memexit.text) __exitused __cold notrace
65675diff --git a/include/linux/init_task.h b/include/linux/init_task.h
65676index 6d087c5..401cab8 100644
65677--- a/include/linux/init_task.h
65678+++ b/include/linux/init_task.h
65679@@ -143,6 +143,12 @@ extern struct task_group root_task_group;
65680
65681 #define INIT_TASK_COMM "swapper"
65682
65683+#ifdef CONFIG_X86
65684+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
65685+#else
65686+#define INIT_TASK_THREAD_INFO
65687+#endif
65688+
65689 /*
65690 * INIT_TASK is used to set up the first task table, touch at
65691 * your own risk!. Base=0, limit=0x1fffff (=2MB)
65692@@ -182,6 +188,7 @@ extern struct task_group root_task_group;
65693 RCU_POINTER_INITIALIZER(cred, &init_cred), \
65694 .comm = INIT_TASK_COMM, \
65695 .thread = INIT_THREAD, \
65696+ INIT_TASK_THREAD_INFO \
65697 .fs = &init_fs, \
65698 .files = &init_files, \
65699 .signal = &init_signals, \
65700diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
65701index 5fa5afe..ac55b25 100644
65702--- a/include/linux/interrupt.h
65703+++ b/include/linux/interrupt.h
65704@@ -430,7 +430,7 @@ enum
65705 /* map softirq index to softirq name. update 'softirq_to_name' in
65706 * kernel/softirq.c when adding a new softirq.
65707 */
65708-extern char *softirq_to_name[NR_SOFTIRQS];
65709+extern const char * const softirq_to_name[NR_SOFTIRQS];
65710
65711 /* softirq mask and active fields moved to irq_cpustat_t in
65712 * asm/hardirq.h to get better cache usage. KAO
65713@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
65714
65715 struct softirq_action
65716 {
65717- void (*action)(struct softirq_action *);
65718-};
65719+ void (*action)(void);
65720+} __no_const;
65721
65722 asmlinkage void do_softirq(void);
65723 asmlinkage void __do_softirq(void);
65724-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
65725+extern void open_softirq(int nr, void (*action)(void));
65726 extern void softirq_init(void);
65727 extern void __raise_softirq_irqoff(unsigned int nr);
65728
65729diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
65730index 6883e19..06992b1 100644
65731--- a/include/linux/kallsyms.h
65732+++ b/include/linux/kallsyms.h
65733@@ -15,7 +15,8 @@
65734
65735 struct module;
65736
65737-#ifdef CONFIG_KALLSYMS
65738+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
65739+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65740 /* Lookup the address for a symbol. Returns 0 if not found. */
65741 unsigned long kallsyms_lookup_name(const char *name);
65742
65743@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
65744 /* Stupid that this does nothing, but I didn't create this mess. */
65745 #define __print_symbol(fmt, addr)
65746 #endif /*CONFIG_KALLSYMS*/
65747+#else /* when included by kallsyms.c, vsnprintf.c, or
65748+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
65749+extern void __print_symbol(const char *fmt, unsigned long address);
65750+extern int sprint_backtrace(char *buffer, unsigned long address);
65751+extern int sprint_symbol(char *buffer, unsigned long address);
65752+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
65753+const char *kallsyms_lookup(unsigned long addr,
65754+ unsigned long *symbolsize,
65755+ unsigned long *offset,
65756+ char **modname, char *namebuf);
65757+#endif
65758
65759 /* This macro allows us to keep printk typechecking */
65760 static __printf(1, 2)
65761diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
65762index 4dff0c6..1ca9b72 100644
65763--- a/include/linux/kgdb.h
65764+++ b/include/linux/kgdb.h
65765@@ -53,7 +53,7 @@ extern int kgdb_connected;
65766 extern int kgdb_io_module_registered;
65767
65768 extern atomic_t kgdb_setting_breakpoint;
65769-extern atomic_t kgdb_cpu_doing_single_step;
65770+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
65771
65772 extern struct task_struct *kgdb_usethread;
65773 extern struct task_struct *kgdb_contthread;
65774@@ -255,7 +255,7 @@ struct kgdb_arch {
65775 void (*correct_hw_break)(void);
65776
65777 void (*enable_nmi)(bool on);
65778-};
65779+} __do_const;
65780
65781 /**
65782 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
65783@@ -280,7 +280,7 @@ struct kgdb_io {
65784 void (*pre_exception) (void);
65785 void (*post_exception) (void);
65786 int is_console;
65787-};
65788+} __do_const;
65789
65790 extern struct kgdb_arch arch_kgdb_ops;
65791
65792diff --git a/include/linux/kmod.h b/include/linux/kmod.h
65793index 5398d58..5883a34 100644
65794--- a/include/linux/kmod.h
65795+++ b/include/linux/kmod.h
65796@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
65797 * usually useless though. */
65798 extern __printf(2, 3)
65799 int __request_module(bool wait, const char *name, ...);
65800+extern __printf(3, 4)
65801+int ___request_module(bool wait, char *param_name, const char *name, ...);
65802 #define request_module(mod...) __request_module(true, mod)
65803 #define request_module_nowait(mod...) __request_module(false, mod)
65804 #define try_then_request_module(x, mod...) \
65805diff --git a/include/linux/kobject.h b/include/linux/kobject.h
65806index 939b112..90b7f44 100644
65807--- a/include/linux/kobject.h
65808+++ b/include/linux/kobject.h
65809@@ -111,7 +111,7 @@ struct kobj_type {
65810 struct attribute **default_attrs;
65811 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
65812 const void *(*namespace)(struct kobject *kobj);
65813-};
65814+} __do_const;
65815
65816 struct kobj_uevent_env {
65817 char *envp[UEVENT_NUM_ENVP];
65818diff --git a/include/linux/kref.h b/include/linux/kref.h
65819index 4972e6e..de4d19b 100644
65820--- a/include/linux/kref.h
65821+++ b/include/linux/kref.h
65822@@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
65823 static inline int kref_sub(struct kref *kref, unsigned int count,
65824 void (*release)(struct kref *kref))
65825 {
65826- WARN_ON(release == NULL);
65827+ BUG_ON(release == NULL);
65828
65829 if (atomic_sub_and_test((int) count, &kref->refcount)) {
65830 release(kref);
65831diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
65832index 2c497ab..afe32f5 100644
65833--- a/include/linux/kvm_host.h
65834+++ b/include/linux/kvm_host.h
65835@@ -418,7 +418,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
65836 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
65837 void vcpu_put(struct kvm_vcpu *vcpu);
65838
65839-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
65840+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
65841 struct module *module);
65842 void kvm_exit(void);
65843
65844@@ -574,7 +574,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
65845 struct kvm_guest_debug *dbg);
65846 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
65847
65848-int kvm_arch_init(void *opaque);
65849+int kvm_arch_init(const void *opaque);
65850 void kvm_arch_exit(void);
65851
65852 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
65853diff --git a/include/linux/libata.h b/include/linux/libata.h
65854index 649e5f8..ead5194 100644
65855--- a/include/linux/libata.h
65856+++ b/include/linux/libata.h
65857@@ -915,7 +915,7 @@ struct ata_port_operations {
65858 * fields must be pointers.
65859 */
65860 const struct ata_port_operations *inherits;
65861-};
65862+} __do_const;
65863
65864 struct ata_port_info {
65865 unsigned long flags;
65866diff --git a/include/linux/list.h b/include/linux/list.h
65867index cc6d2aa..71febca 100644
65868--- a/include/linux/list.h
65869+++ b/include/linux/list.h
65870@@ -112,6 +112,9 @@ extern void __list_del_entry(struct list_head *entry);
65871 extern void list_del(struct list_head *entry);
65872 #endif
65873
65874+extern void pax_list_add_tail(struct list_head *new, struct list_head *head);
65875+extern void pax_list_del(struct list_head *entry);
65876+
65877 /**
65878 * list_replace - replace old entry by new one
65879 * @old : the element to be replaced
65880diff --git a/include/linux/mm.h b/include/linux/mm.h
65881index 66e2f7c..ea88001 100644
65882--- a/include/linux/mm.h
65883+++ b/include/linux/mm.h
65884@@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
65885 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
65886 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
65887 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
65888+
65889+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
65890+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
65891+#endif
65892+
65893 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
65894
65895 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
65896@@ -231,6 +236,7 @@ struct vm_operations_struct {
65897 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
65898 unsigned long size, pgoff_t pgoff);
65899 };
65900+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
65901
65902 struct mmu_gather;
65903 struct inode;
65904@@ -1068,34 +1074,6 @@ int set_page_dirty(struct page *page);
65905 int set_page_dirty_lock(struct page *page);
65906 int clear_page_dirty_for_io(struct page *page);
65907
65908-/* Is the vma a continuation of the stack vma above it? */
65909-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
65910-{
65911- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
65912-}
65913-
65914-static inline int stack_guard_page_start(struct vm_area_struct *vma,
65915- unsigned long addr)
65916-{
65917- return (vma->vm_flags & VM_GROWSDOWN) &&
65918- (vma->vm_start == addr) &&
65919- !vma_growsdown(vma->vm_prev, addr);
65920-}
65921-
65922-/* Is the vma a continuation of the stack vma below it? */
65923-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
65924-{
65925- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
65926-}
65927-
65928-static inline int stack_guard_page_end(struct vm_area_struct *vma,
65929- unsigned long addr)
65930-{
65931- return (vma->vm_flags & VM_GROWSUP) &&
65932- (vma->vm_end == addr) &&
65933- !vma_growsup(vma->vm_next, addr);
65934-}
65935-
65936 extern pid_t
65937 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
65938
65939@@ -1198,6 +1176,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
65940 }
65941 #endif
65942
65943+#ifdef CONFIG_MMU
65944+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
65945+#else
65946+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
65947+{
65948+ return __pgprot(0);
65949+}
65950+#endif
65951+
65952 int vma_wants_writenotify(struct vm_area_struct *vma);
65953
65954 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
65955@@ -1216,8 +1203,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
65956 {
65957 return 0;
65958 }
65959+
65960+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
65961+ unsigned long address)
65962+{
65963+ return 0;
65964+}
65965 #else
65966 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
65967+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
65968 #endif
65969
65970 #ifdef __PAGETABLE_PMD_FOLDED
65971@@ -1226,8 +1220,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
65972 {
65973 return 0;
65974 }
65975+
65976+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
65977+ unsigned long address)
65978+{
65979+ return 0;
65980+}
65981 #else
65982 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
65983+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
65984 #endif
65985
65986 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
65987@@ -1245,11 +1246,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
65988 NULL: pud_offset(pgd, address);
65989 }
65990
65991+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
65992+{
65993+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
65994+ NULL: pud_offset(pgd, address);
65995+}
65996+
65997 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
65998 {
65999 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
66000 NULL: pmd_offset(pud, address);
66001 }
66002+
66003+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
66004+{
66005+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
66006+ NULL: pmd_offset(pud, address);
66007+}
66008 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
66009
66010 #if USE_SPLIT_PTLOCKS
66011@@ -1479,6 +1492,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
66012 unsigned long, unsigned long,
66013 unsigned long, unsigned long);
66014 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
66015+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
66016
66017 /* These take the mm semaphore themselves */
66018 extern unsigned long vm_brk(unsigned long, unsigned long);
66019@@ -1573,6 +1587,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
66020 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
66021 struct vm_area_struct **pprev);
66022
66023+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
66024+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
66025+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
66026+
66027 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
66028 NULL if none. Assume start_addr < end_addr. */
66029 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
66030@@ -1601,15 +1619,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
66031 return vma;
66032 }
66033
66034-#ifdef CONFIG_MMU
66035-pgprot_t vm_get_page_prot(unsigned long vm_flags);
66036-#else
66037-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
66038-{
66039- return __pgprot(0);
66040-}
66041-#endif
66042-
66043 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
66044 unsigned long change_prot_numa(struct vm_area_struct *vma,
66045 unsigned long start, unsigned long end);
66046@@ -1721,7 +1730,7 @@ extern int unpoison_memory(unsigned long pfn);
66047 extern int sysctl_memory_failure_early_kill;
66048 extern int sysctl_memory_failure_recovery;
66049 extern void shake_page(struct page *p, int access);
66050-extern atomic_long_t mce_bad_pages;
66051+extern atomic_long_unchecked_t mce_bad_pages;
66052 extern int soft_offline_page(struct page *page, int flags);
66053
66054 extern void dump_page(struct page *page);
66055@@ -1752,5 +1761,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
66056 static inline bool page_is_guard(struct page *page) { return false; }
66057 #endif /* CONFIG_DEBUG_PAGEALLOC */
66058
66059+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
66060+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
66061+#else
66062+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
66063+#endif
66064+
66065 #endif /* __KERNEL__ */
66066 #endif /* _LINUX_MM_H */
66067diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
66068index f8f5162..6276a36 100644
66069--- a/include/linux/mm_types.h
66070+++ b/include/linux/mm_types.h
66071@@ -288,6 +288,8 @@ struct vm_area_struct {
66072 #ifdef CONFIG_NUMA
66073 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
66074 #endif
66075+
66076+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
66077 };
66078
66079 struct core_thread {
66080@@ -362,7 +364,7 @@ struct mm_struct {
66081 unsigned long def_flags;
66082 unsigned long nr_ptes; /* Page table pages */
66083 unsigned long start_code, end_code, start_data, end_data;
66084- unsigned long start_brk, brk, start_stack;
66085+ unsigned long brk_gap, start_brk, brk, start_stack;
66086 unsigned long arg_start, arg_end, env_start, env_end;
66087
66088 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
66089@@ -436,6 +438,24 @@ struct mm_struct {
66090 int first_nid;
66091 #endif
66092 struct uprobes_state uprobes_state;
66093+
66094+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
66095+ unsigned long pax_flags;
66096+#endif
66097+
66098+#ifdef CONFIG_PAX_DLRESOLVE
66099+ unsigned long call_dl_resolve;
66100+#endif
66101+
66102+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
66103+ unsigned long call_syscall;
66104+#endif
66105+
66106+#ifdef CONFIG_PAX_ASLR
66107+ unsigned long delta_mmap; /* randomized offset */
66108+ unsigned long delta_stack; /* randomized offset */
66109+#endif
66110+
66111 };
66112
66113 /* first nid will either be a valid NID or one of these values */
66114diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
66115index c5d5278..f0b68c8 100644
66116--- a/include/linux/mmiotrace.h
66117+++ b/include/linux/mmiotrace.h
66118@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
66119 /* Called from ioremap.c */
66120 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
66121 void __iomem *addr);
66122-extern void mmiotrace_iounmap(volatile void __iomem *addr);
66123+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
66124
66125 /* For anyone to insert markers. Remember trailing newline. */
66126 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
66127@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
66128 {
66129 }
66130
66131-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
66132+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
66133 {
66134 }
66135
66136diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
66137index 73b64a3..6562925 100644
66138--- a/include/linux/mmzone.h
66139+++ b/include/linux/mmzone.h
66140@@ -412,7 +412,7 @@ struct zone {
66141 unsigned long flags; /* zone flags, see below */
66142
66143 /* Zone statistics */
66144- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66145+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66146
66147 /*
66148 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
66149diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
66150index fed3def..7cc3f93 100644
66151--- a/include/linux/mod_devicetable.h
66152+++ b/include/linux/mod_devicetable.h
66153@@ -12,7 +12,7 @@
66154 typedef unsigned long kernel_ulong_t;
66155 #endif
66156
66157-#define PCI_ANY_ID (~0)
66158+#define PCI_ANY_ID ((__u16)~0)
66159
66160 struct pci_device_id {
66161 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
66162@@ -139,7 +139,7 @@ struct usb_device_id {
66163 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
66164 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
66165
66166-#define HID_ANY_ID (~0)
66167+#define HID_ANY_ID (~0U)
66168 #define HID_BUS_ANY 0xffff
66169 #define HID_GROUP_ANY 0x0000
66170
66171diff --git a/include/linux/module.h b/include/linux/module.h
66172index 1375ee3..d631af0 100644
66173--- a/include/linux/module.h
66174+++ b/include/linux/module.h
66175@@ -17,9 +17,11 @@
66176 #include <linux/moduleparam.h>
66177 #include <linux/tracepoint.h>
66178 #include <linux/export.h>
66179+#include <linux/fs.h>
66180
66181 #include <linux/percpu.h>
66182 #include <asm/module.h>
66183+#include <asm/pgtable.h>
66184
66185 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
66186 #define MODULE_SIG_STRING "~Module signature appended~\n"
66187@@ -281,19 +283,16 @@ struct module
66188 int (*init)(void);
66189
66190 /* If this is non-NULL, vfree after init() returns */
66191- void *module_init;
66192+ void *module_init_rx, *module_init_rw;
66193
66194 /* Here is the actual code + data, vfree'd on unload. */
66195- void *module_core;
66196+ void *module_core_rx, *module_core_rw;
66197
66198 /* Here are the sizes of the init and core sections */
66199- unsigned int init_size, core_size;
66200+ unsigned int init_size_rw, core_size_rw;
66201
66202 /* The size of the executable code in each section. */
66203- unsigned int init_text_size, core_text_size;
66204-
66205- /* Size of RO sections of the module (text+rodata) */
66206- unsigned int init_ro_size, core_ro_size;
66207+ unsigned int init_size_rx, core_size_rx;
66208
66209 /* Arch-specific module values */
66210 struct mod_arch_specific arch;
66211@@ -349,6 +348,10 @@ struct module
66212 #ifdef CONFIG_EVENT_TRACING
66213 struct ftrace_event_call **trace_events;
66214 unsigned int num_trace_events;
66215+ struct file_operations trace_id;
66216+ struct file_operations trace_enable;
66217+ struct file_operations trace_format;
66218+ struct file_operations trace_filter;
66219 #endif
66220 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
66221 unsigned int num_ftrace_callsites;
66222@@ -396,16 +399,46 @@ bool is_module_address(unsigned long addr);
66223 bool is_module_percpu_address(unsigned long addr);
66224 bool is_module_text_address(unsigned long addr);
66225
66226+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
66227+{
66228+
66229+#ifdef CONFIG_PAX_KERNEXEC
66230+ if (ktla_ktva(addr) >= (unsigned long)start &&
66231+ ktla_ktva(addr) < (unsigned long)start + size)
66232+ return 1;
66233+#endif
66234+
66235+ return ((void *)addr >= start && (void *)addr < start + size);
66236+}
66237+
66238+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
66239+{
66240+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
66241+}
66242+
66243+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
66244+{
66245+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
66246+}
66247+
66248+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
66249+{
66250+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
66251+}
66252+
66253+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
66254+{
66255+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
66256+}
66257+
66258 static inline int within_module_core(unsigned long addr, struct module *mod)
66259 {
66260- return (unsigned long)mod->module_core <= addr &&
66261- addr < (unsigned long)mod->module_core + mod->core_size;
66262+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
66263 }
66264
66265 static inline int within_module_init(unsigned long addr, struct module *mod)
66266 {
66267- return (unsigned long)mod->module_init <= addr &&
66268- addr < (unsigned long)mod->module_init + mod->init_size;
66269+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
66270 }
66271
66272 /* Search for module by name: must hold module_mutex. */
66273diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
66274index 560ca53..5ee8d73 100644
66275--- a/include/linux/moduleloader.h
66276+++ b/include/linux/moduleloader.h
66277@@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
66278
66279 /* Allocator used for allocating struct module, core sections and init
66280 sections. Returns NULL on failure. */
66281-void *module_alloc(unsigned long size);
66282+void *module_alloc(unsigned long size) __size_overflow(1);
66283+
66284+#ifdef CONFIG_PAX_KERNEXEC
66285+void *module_alloc_exec(unsigned long size) __size_overflow(1);
66286+#else
66287+#define module_alloc_exec(x) module_alloc(x)
66288+#endif
66289
66290 /* Free memory returned from module_alloc. */
66291 void module_free(struct module *mod, void *module_region);
66292
66293+#ifdef CONFIG_PAX_KERNEXEC
66294+void module_free_exec(struct module *mod, void *module_region);
66295+#else
66296+#define module_free_exec(x, y) module_free((x), (y))
66297+#endif
66298+
66299 /*
66300 * Apply the given relocation to the (simplified) ELF. Return -error
66301 * or 0.
66302@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
66303 unsigned int relsec,
66304 struct module *me)
66305 {
66306+#ifdef CONFIG_MODULES
66307 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
66308+#endif
66309 return -ENOEXEC;
66310 }
66311 #endif
66312@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
66313 unsigned int relsec,
66314 struct module *me)
66315 {
66316+#ifdef CONFIG_MODULES
66317 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
66318+#endif
66319 return -ENOEXEC;
66320 }
66321 #endif
66322diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
66323index 137b419..fe663ec 100644
66324--- a/include/linux/moduleparam.h
66325+++ b/include/linux/moduleparam.h
66326@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
66327 * @len is usually just sizeof(string).
66328 */
66329 #define module_param_string(name, string, len, perm) \
66330- static const struct kparam_string __param_string_##name \
66331+ static const struct kparam_string __param_string_##name __used \
66332 = { len, string }; \
66333 __module_param_call(MODULE_PARAM_PREFIX, name, \
66334 &param_ops_string, \
66335@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
66336 */
66337 #define module_param_array_named(name, array, type, nump, perm) \
66338 param_check_##type(name, &(array)[0]); \
66339- static const struct kparam_array __param_arr_##name \
66340+ static const struct kparam_array __param_arr_##name __used \
66341 = { .max = ARRAY_SIZE(array), .num = nump, \
66342 .ops = &param_ops_##type, \
66343 .elemsize = sizeof(array[0]), .elem = array }; \
66344diff --git a/include/linux/namei.h b/include/linux/namei.h
66345index 5a5ff57..5ae5070 100644
66346--- a/include/linux/namei.h
66347+++ b/include/linux/namei.h
66348@@ -19,7 +19,7 @@ struct nameidata {
66349 unsigned seq;
66350 int last_type;
66351 unsigned depth;
66352- char *saved_names[MAX_NESTED_LINKS + 1];
66353+ const char *saved_names[MAX_NESTED_LINKS + 1];
66354 };
66355
66356 /*
66357@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
66358
66359 extern void nd_jump_link(struct nameidata *nd, struct path *path);
66360
66361-static inline void nd_set_link(struct nameidata *nd, char *path)
66362+static inline void nd_set_link(struct nameidata *nd, const char *path)
66363 {
66364 nd->saved_names[nd->depth] = path;
66365 }
66366
66367-static inline char *nd_get_link(struct nameidata *nd)
66368+static inline const char *nd_get_link(const struct nameidata *nd)
66369 {
66370 return nd->saved_names[nd->depth];
66371 }
66372diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
66373index 9ef07d0..130a5d9 100644
66374--- a/include/linux/netdevice.h
66375+++ b/include/linux/netdevice.h
66376@@ -1012,6 +1012,7 @@ struct net_device_ops {
66377 u32 pid, u32 seq,
66378 struct net_device *dev);
66379 };
66380+typedef struct net_device_ops __no_const net_device_ops_no_const;
66381
66382 /*
66383 * The DEVICE structure.
66384@@ -1078,7 +1079,7 @@ struct net_device {
66385 int iflink;
66386
66387 struct net_device_stats stats;
66388- atomic_long_t rx_dropped; /* dropped packets by core network
66389+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
66390 * Do not use this in drivers.
66391 */
66392
66393diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
66394index 7958e84..ed74d7a 100644
66395--- a/include/linux/netfilter/ipset/ip_set.h
66396+++ b/include/linux/netfilter/ipset/ip_set.h
66397@@ -98,7 +98,7 @@ struct ip_set_type_variant {
66398 /* Return true if "b" set is the same as "a"
66399 * according to the create set parameters */
66400 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
66401-};
66402+} __do_const;
66403
66404 /* The core set type structure */
66405 struct ip_set_type {
66406diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
66407index 4966dde..7d8ce06 100644
66408--- a/include/linux/netfilter/nfnetlink.h
66409+++ b/include/linux/netfilter/nfnetlink.h
66410@@ -16,7 +16,7 @@ struct nfnl_callback {
66411 const struct nlattr * const cda[]);
66412 const struct nla_policy *policy; /* netlink attribute policy */
66413 const u_int16_t attr_count; /* number of nlattr's */
66414-};
66415+} __do_const;
66416
66417 struct nfnetlink_subsystem {
66418 const char *name;
66419diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
66420new file mode 100644
66421index 0000000..33f4af8
66422--- /dev/null
66423+++ b/include/linux/netfilter/xt_gradm.h
66424@@ -0,0 +1,9 @@
66425+#ifndef _LINUX_NETFILTER_XT_GRADM_H
66426+#define _LINUX_NETFILTER_XT_GRADM_H 1
66427+
66428+struct xt_gradm_mtinfo {
66429+ __u16 flags;
66430+ __u16 invflags;
66431+};
66432+
66433+#endif
66434diff --git a/include/linux/notifier.h b/include/linux/notifier.h
66435index d65746e..62e72c2 100644
66436--- a/include/linux/notifier.h
66437+++ b/include/linux/notifier.h
66438@@ -51,7 +51,8 @@ struct notifier_block {
66439 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
66440 struct notifier_block __rcu *next;
66441 int priority;
66442-};
66443+} __do_const;
66444+typedef struct notifier_block __no_const notifier_block_no_const;
66445
66446 struct atomic_notifier_head {
66447 spinlock_t lock;
66448diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
66449index a4c5624..79d6d88 100644
66450--- a/include/linux/oprofile.h
66451+++ b/include/linux/oprofile.h
66452@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
66453 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
66454 char const * name, ulong * val);
66455
66456-/** Create a file for read-only access to an atomic_t. */
66457+/** Create a file for read-only access to an atomic_unchecked_t. */
66458 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
66459- char const * name, atomic_t * val);
66460+ char const * name, atomic_unchecked_t * val);
66461
66462 /** create a directory */
66463 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
66464diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
66465index 6bfb2faa..e5bc5e5 100644
66466--- a/include/linux/perf_event.h
66467+++ b/include/linux/perf_event.h
66468@@ -328,8 +328,8 @@ struct perf_event {
66469
66470 enum perf_event_active_state state;
66471 unsigned int attach_state;
66472- local64_t count;
66473- atomic64_t child_count;
66474+ local64_t count; /* PaX: fix it one day */
66475+ atomic64_unchecked_t child_count;
66476
66477 /*
66478 * These are the total time in nanoseconds that the event
66479@@ -380,8 +380,8 @@ struct perf_event {
66480 * These accumulate total time (in nanoseconds) that children
66481 * events have been enabled and running, respectively.
66482 */
66483- atomic64_t child_total_time_enabled;
66484- atomic64_t child_total_time_running;
66485+ atomic64_unchecked_t child_total_time_enabled;
66486+ atomic64_unchecked_t child_total_time_running;
66487
66488 /*
66489 * Protect attach/detach and child_list:
66490@@ -801,7 +801,7 @@ static inline void perf_event_task_tick(void) { }
66491 */
66492 #define perf_cpu_notifier(fn) \
66493 do { \
66494- static struct notifier_block fn##_nb __cpuinitdata = \
66495+ static struct notifier_block fn##_nb = \
66496 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
66497 unsigned long cpu = smp_processor_id(); \
66498 unsigned long flags; \
66499diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
66500index ad1a427..6419649 100644
66501--- a/include/linux/pipe_fs_i.h
66502+++ b/include/linux/pipe_fs_i.h
66503@@ -45,9 +45,9 @@ struct pipe_buffer {
66504 struct pipe_inode_info {
66505 wait_queue_head_t wait;
66506 unsigned int nrbufs, curbuf, buffers;
66507- unsigned int readers;
66508- unsigned int writers;
66509- unsigned int waiting_writers;
66510+ atomic_t readers;
66511+ atomic_t writers;
66512+ atomic_t waiting_writers;
66513 unsigned int r_counter;
66514 unsigned int w_counter;
66515 struct page *tmp_page;
66516diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
66517index 5f28cae..3d23723 100644
66518--- a/include/linux/platform_data/usb-ehci-s5p.h
66519+++ b/include/linux/platform_data/usb-ehci-s5p.h
66520@@ -14,7 +14,7 @@
66521 struct s5p_ehci_platdata {
66522 int (*phy_init)(struct platform_device *pdev, int type);
66523 int (*phy_exit)(struct platform_device *pdev, int type);
66524-};
66525+} __no_const;
66526
66527 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
66528
66529diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
66530index f271860..6b3bec5 100644
66531--- a/include/linux/pm_runtime.h
66532+++ b/include/linux/pm_runtime.h
66533@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
66534
66535 static inline void pm_runtime_mark_last_busy(struct device *dev)
66536 {
66537- ACCESS_ONCE(dev->power.last_busy) = jiffies;
66538+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
66539 }
66540
66541 #else /* !CONFIG_PM_RUNTIME */
66542diff --git a/include/linux/poison.h b/include/linux/poison.h
66543index 2110a81..13a11bb 100644
66544--- a/include/linux/poison.h
66545+++ b/include/linux/poison.h
66546@@ -19,8 +19,8 @@
66547 * under normal circumstances, used to verify that nobody uses
66548 * non-initialized list entries.
66549 */
66550-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
66551-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
66552+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
66553+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
66554
66555 /********** include/linux/timer.h **********/
66556 /*
66557diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
66558index c0f44c2..1572583 100644
66559--- a/include/linux/power/smartreflex.h
66560+++ b/include/linux/power/smartreflex.h
66561@@ -238,7 +238,7 @@ struct omap_sr_class_data {
66562 int (*notify)(struct omap_sr *sr, u32 status);
66563 u8 notify_flags;
66564 u8 class_type;
66565-};
66566+} __do_const;
66567
66568 /**
66569 * struct omap_sr_nvalue_table - Smartreflex n-target value info
66570diff --git a/include/linux/printk.h b/include/linux/printk.h
66571index 9afc01e..92c32e8 100644
66572--- a/include/linux/printk.h
66573+++ b/include/linux/printk.h
66574@@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
66575 extern int printk_needs_cpu(int cpu);
66576 extern void printk_tick(void);
66577
66578+extern int kptr_restrict;
66579+
66580 #ifdef CONFIG_PRINTK
66581 asmlinkage __printf(5, 0)
66582 int vprintk_emit(int facility, int level,
66583@@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
66584
66585 extern int printk_delay_msec;
66586 extern int dmesg_restrict;
66587-extern int kptr_restrict;
66588
66589 void log_buf_kexec_setup(void);
66590 void __init setup_log_buf(int early);
66591diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
66592index 32676b3..8f7a182 100644
66593--- a/include/linux/proc_fs.h
66594+++ b/include/linux/proc_fs.h
66595@@ -159,6 +159,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
66596 return proc_create_data(name, mode, parent, proc_fops, NULL);
66597 }
66598
66599+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
66600+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
66601+{
66602+#ifdef CONFIG_GRKERNSEC_PROC_USER
66603+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
66604+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66605+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
66606+#else
66607+ return proc_create_data(name, mode, parent, proc_fops, NULL);
66608+#endif
66609+}
66610+
66611 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
66612 umode_t mode, struct proc_dir_entry *base,
66613 read_proc_t *read_proc, void * data)
66614diff --git a/include/linux/random.h b/include/linux/random.h
66615index d984608..d6f0042 100644
66616--- a/include/linux/random.h
66617+++ b/include/linux/random.h
66618@@ -39,6 +39,11 @@ void prandom_seed(u32 seed);
66619 u32 prandom_u32_state(struct rnd_state *);
66620 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
66621
66622+static inline unsigned long pax_get_random_long(void)
66623+{
66624+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
66625+}
66626+
66627 /*
66628 * Handle minimum values for seeds
66629 */
66630diff --git a/include/linux/reboot.h b/include/linux/reboot.h
66631index 23b3630..e1bc12b 100644
66632--- a/include/linux/reboot.h
66633+++ b/include/linux/reboot.h
66634@@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
66635 * Architecture-specific implementations of sys_reboot commands.
66636 */
66637
66638-extern void machine_restart(char *cmd);
66639-extern void machine_halt(void);
66640-extern void machine_power_off(void);
66641+extern void machine_restart(char *cmd) __noreturn;
66642+extern void machine_halt(void) __noreturn;
66643+extern void machine_power_off(void) __noreturn;
66644
66645 extern void machine_shutdown(void);
66646 struct pt_regs;
66647@@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
66648 */
66649
66650 extern void kernel_restart_prepare(char *cmd);
66651-extern void kernel_restart(char *cmd);
66652-extern void kernel_halt(void);
66653-extern void kernel_power_off(void);
66654+extern void kernel_restart(char *cmd) __noreturn;
66655+extern void kernel_halt(void) __noreturn;
66656+extern void kernel_power_off(void) __noreturn;
66657
66658 extern int C_A_D; /* for sysctl */
66659 void ctrl_alt_del(void);
66660@@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
66661 * Emergency restart, callable from an interrupt handler.
66662 */
66663
66664-extern void emergency_restart(void);
66665+extern void emergency_restart(void) __noreturn;
66666 #include <asm/emergency-restart.h>
66667
66668 #endif /* _LINUX_REBOOT_H */
66669diff --git a/include/linux/regset.h b/include/linux/regset.h
66670index 8e0c9fe..ac4d221 100644
66671--- a/include/linux/regset.h
66672+++ b/include/linux/regset.h
66673@@ -161,7 +161,8 @@ struct user_regset {
66674 unsigned int align;
66675 unsigned int bias;
66676 unsigned int core_note_type;
66677-};
66678+} __do_const;
66679+typedef struct user_regset __no_const user_regset_no_const;
66680
66681 /**
66682 * struct user_regset_view - available regsets
66683diff --git a/include/linux/relay.h b/include/linux/relay.h
66684index 91cacc3..b55ff74 100644
66685--- a/include/linux/relay.h
66686+++ b/include/linux/relay.h
66687@@ -160,7 +160,7 @@ struct rchan_callbacks
66688 * The callback should return 0 if successful, negative if not.
66689 */
66690 int (*remove_buf_file)(struct dentry *dentry);
66691-};
66692+} __no_const;
66693
66694 /*
66695 * CONFIG_RELAY kernel API, kernel/relay.c
66696diff --git a/include/linux/rio.h b/include/linux/rio.h
66697index a3e7842..d973ca6 100644
66698--- a/include/linux/rio.h
66699+++ b/include/linux/rio.h
66700@@ -339,7 +339,7 @@ struct rio_ops {
66701 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
66702 u64 rstart, u32 size, u32 flags);
66703 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
66704-};
66705+} __no_const;
66706
66707 #define RIO_RESOURCE_MEM 0x00000100
66708 #define RIO_RESOURCE_DOORBELL 0x00000200
66709diff --git a/include/linux/rmap.h b/include/linux/rmap.h
66710index c20635c..2f5def4 100644
66711--- a/include/linux/rmap.h
66712+++ b/include/linux/rmap.h
66713@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
66714 void anon_vma_init(void); /* create anon_vma_cachep */
66715 int anon_vma_prepare(struct vm_area_struct *);
66716 void unlink_anon_vmas(struct vm_area_struct *);
66717-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
66718-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
66719+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
66720+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
66721
66722 static inline void anon_vma_merge(struct vm_area_struct *vma,
66723 struct vm_area_struct *next)
66724diff --git a/include/linux/sched.h b/include/linux/sched.h
66725index d211247..d64a165 100644
66726--- a/include/linux/sched.h
66727+++ b/include/linux/sched.h
66728@@ -61,6 +61,7 @@ struct bio_list;
66729 struct fs_struct;
66730 struct perf_event_context;
66731 struct blk_plug;
66732+struct linux_binprm;
66733
66734 /*
66735 * List of flags we want to share for kernel threads,
66736@@ -354,10 +355,23 @@ struct user_namespace;
66737 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
66738
66739 extern int sysctl_max_map_count;
66740+extern unsigned long sysctl_heap_stack_gap;
66741
66742 #include <linux/aio.h>
66743
66744 #ifdef CONFIG_MMU
66745+
66746+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
66747+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
66748+#else
66749+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
66750+{
66751+ return 0;
66752+}
66753+#endif
66754+
66755+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
66756+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
66757 extern void arch_pick_mmap_layout(struct mm_struct *mm);
66758 extern unsigned long
66759 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
66760@@ -639,6 +653,17 @@ struct signal_struct {
66761 #ifdef CONFIG_TASKSTATS
66762 struct taskstats *stats;
66763 #endif
66764+
66765+#ifdef CONFIG_GRKERNSEC
66766+ u32 curr_ip;
66767+ u32 saved_ip;
66768+ u32 gr_saddr;
66769+ u32 gr_daddr;
66770+ u16 gr_sport;
66771+ u16 gr_dport;
66772+ u8 used_accept:1;
66773+#endif
66774+
66775 #ifdef CONFIG_AUDIT
66776 unsigned audit_tty;
66777 struct tty_audit_buf *tty_audit_buf;
66778@@ -717,6 +742,11 @@ struct user_struct {
66779 struct key *session_keyring; /* UID's default session keyring */
66780 #endif
66781
66782+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
66783+ unsigned int banned;
66784+ unsigned long ban_expires;
66785+#endif
66786+
66787 /* Hash table maintenance information */
66788 struct hlist_node uidhash_node;
66789 kuid_t uid;
66790@@ -1360,8 +1390,8 @@ struct task_struct {
66791 struct list_head thread_group;
66792
66793 struct completion *vfork_done; /* for vfork() */
66794- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
66795- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
66796+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
66797+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
66798
66799 cputime_t utime, stime, utimescaled, stimescaled;
66800 cputime_t gtime;
66801@@ -1377,11 +1407,6 @@ struct task_struct {
66802 struct task_cputime cputime_expires;
66803 struct list_head cpu_timers[3];
66804
66805-/* process credentials */
66806- const struct cred __rcu *real_cred; /* objective and real subjective task
66807- * credentials (COW) */
66808- const struct cred __rcu *cred; /* effective (overridable) subjective task
66809- * credentials (COW) */
66810 char comm[TASK_COMM_LEN]; /* executable name excluding path
66811 - access with [gs]et_task_comm (which lock
66812 it with task_lock())
66813@@ -1398,6 +1423,10 @@ struct task_struct {
66814 #endif
66815 /* CPU-specific state of this task */
66816 struct thread_struct thread;
66817+/* thread_info moved to task_struct */
66818+#ifdef CONFIG_X86
66819+ struct thread_info tinfo;
66820+#endif
66821 /* filesystem information */
66822 struct fs_struct *fs;
66823 /* open file information */
66824@@ -1471,6 +1500,10 @@ struct task_struct {
66825 gfp_t lockdep_reclaim_gfp;
66826 #endif
66827
66828+/* process credentials */
66829+ const struct cred __rcu *real_cred; /* objective and real subjective task
66830+ * credentials (COW) */
66831+
66832 /* journalling filesystem info */
66833 void *journal_info;
66834
66835@@ -1509,6 +1542,10 @@ struct task_struct {
66836 /* cg_list protected by css_set_lock and tsk->alloc_lock */
66837 struct list_head cg_list;
66838 #endif
66839+
66840+ const struct cred __rcu *cred; /* effective (overridable) subjective task
66841+ * credentials (COW) */
66842+
66843 #ifdef CONFIG_FUTEX
66844 struct robust_list_head __user *robust_list;
66845 #ifdef CONFIG_COMPAT
66846@@ -1605,8 +1642,74 @@ struct task_struct {
66847 #ifdef CONFIG_UPROBES
66848 struct uprobe_task *utask;
66849 #endif
66850+
66851+#ifdef CONFIG_GRKERNSEC
66852+ /* grsecurity */
66853+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66854+ u64 exec_id;
66855+#endif
66856+#ifdef CONFIG_GRKERNSEC_SETXID
66857+ const struct cred *delayed_cred;
66858+#endif
66859+ struct dentry *gr_chroot_dentry;
66860+ struct acl_subject_label *acl;
66861+ struct acl_role_label *role;
66862+ struct file *exec_file;
66863+ unsigned long brute_expires;
66864+ u16 acl_role_id;
66865+ /* is this the task that authenticated to the special role */
66866+ u8 acl_sp_role;
66867+ u8 is_writable;
66868+ u8 brute;
66869+ u8 gr_is_chrooted;
66870+#endif
66871+
66872 };
66873
66874+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
66875+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
66876+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
66877+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
66878+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
66879+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
66880+
66881+#ifdef CONFIG_PAX_SOFTMODE
66882+extern int pax_softmode;
66883+#endif
66884+
66885+extern int pax_check_flags(unsigned long *);
66886+
66887+/* if tsk != current then task_lock must be held on it */
66888+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
66889+static inline unsigned long pax_get_flags(struct task_struct *tsk)
66890+{
66891+ if (likely(tsk->mm))
66892+ return tsk->mm->pax_flags;
66893+ else
66894+ return 0UL;
66895+}
66896+
66897+/* if tsk != current then task_lock must be held on it */
66898+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
66899+{
66900+ if (likely(tsk->mm)) {
66901+ tsk->mm->pax_flags = flags;
66902+ return 0;
66903+ }
66904+ return -EINVAL;
66905+}
66906+#endif
66907+
66908+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
66909+extern void pax_set_initial_flags(struct linux_binprm *bprm);
66910+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
66911+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
66912+#endif
66913+
66914+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
66915+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
66916+extern void pax_report_refcount_overflow(struct pt_regs *regs);
66917+
66918 /* Future-safe accessor for struct task_struct's cpus_allowed. */
66919 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
66920
66921@@ -2155,7 +2258,9 @@ void yield(void);
66922 extern struct exec_domain default_exec_domain;
66923
66924 union thread_union {
66925+#ifndef CONFIG_X86
66926 struct thread_info thread_info;
66927+#endif
66928 unsigned long stack[THREAD_SIZE/sizeof(long)];
66929 };
66930
66931@@ -2188,6 +2293,7 @@ extern struct pid_namespace init_pid_ns;
66932 */
66933
66934 extern struct task_struct *find_task_by_vpid(pid_t nr);
66935+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
66936 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
66937 struct pid_namespace *ns);
66938
66939@@ -2344,7 +2450,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
66940 extern void exit_itimers(struct signal_struct *);
66941 extern void flush_itimer_signals(void);
66942
66943-extern void do_group_exit(int);
66944+extern __noreturn void do_group_exit(int);
66945
66946 extern int allow_signal(int);
66947 extern int disallow_signal(int);
66948@@ -2545,9 +2651,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
66949
66950 #endif
66951
66952-static inline int object_is_on_stack(void *obj)
66953+static inline int object_starts_on_stack(void *obj)
66954 {
66955- void *stack = task_stack_page(current);
66956+ const void *stack = task_stack_page(current);
66957
66958 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
66959 }
66960diff --git a/include/linux/security.h b/include/linux/security.h
66961index eee7478..290f7ba 100644
66962--- a/include/linux/security.h
66963+++ b/include/linux/security.h
66964@@ -26,6 +26,7 @@
66965 #include <linux/capability.h>
66966 #include <linux/slab.h>
66967 #include <linux/err.h>
66968+#include <linux/grsecurity.h>
66969
66970 struct linux_binprm;
66971 struct cred;
66972diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
66973index 68a04a3..866e6a1 100644
66974--- a/include/linux/seq_file.h
66975+++ b/include/linux/seq_file.h
66976@@ -26,6 +26,9 @@ struct seq_file {
66977 struct mutex lock;
66978 const struct seq_operations *op;
66979 int poll_event;
66980+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66981+ u64 exec_id;
66982+#endif
66983 #ifdef CONFIG_USER_NS
66984 struct user_namespace *user_ns;
66985 #endif
66986@@ -38,6 +41,7 @@ struct seq_operations {
66987 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
66988 int (*show) (struct seq_file *m, void *v);
66989 };
66990+typedef struct seq_operations __no_const seq_operations_no_const;
66991
66992 #define SEQ_SKIP 1
66993
66994diff --git a/include/linux/shm.h b/include/linux/shm.h
66995index 429c199..4d42e38 100644
66996--- a/include/linux/shm.h
66997+++ b/include/linux/shm.h
66998@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
66999
67000 /* The task created the shm object. NULL if the task is dead. */
67001 struct task_struct *shm_creator;
67002+#ifdef CONFIG_GRKERNSEC
67003+ time_t shm_createtime;
67004+ pid_t shm_lapid;
67005+#endif
67006 };
67007
67008 /* shm_mode upper byte flags */
67009diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
67010index 320e976..fd52553 100644
67011--- a/include/linux/skbuff.h
67012+++ b/include/linux/skbuff.h
67013@@ -590,7 +590,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
67014 extern struct sk_buff *__alloc_skb(unsigned int size,
67015 gfp_t priority, int flags, int node);
67016 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
67017-static inline struct sk_buff *alloc_skb(unsigned int size,
67018+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
67019 gfp_t priority)
67020 {
67021 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
67022@@ -700,7 +700,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
67023 */
67024 static inline int skb_queue_empty(const struct sk_buff_head *list)
67025 {
67026- return list->next == (struct sk_buff *)list;
67027+ return list->next == (const struct sk_buff *)list;
67028 }
67029
67030 /**
67031@@ -713,7 +713,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
67032 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
67033 const struct sk_buff *skb)
67034 {
67035- return skb->next == (struct sk_buff *)list;
67036+ return skb->next == (const struct sk_buff *)list;
67037 }
67038
67039 /**
67040@@ -726,7 +726,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
67041 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
67042 const struct sk_buff *skb)
67043 {
67044- return skb->prev == (struct sk_buff *)list;
67045+ return skb->prev == (const struct sk_buff *)list;
67046 }
67047
67048 /**
67049@@ -1722,7 +1722,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
67050 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
67051 */
67052 #ifndef NET_SKB_PAD
67053-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
67054+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
67055 #endif
67056
67057 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
67058@@ -2300,7 +2300,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
67059 int noblock, int *err);
67060 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
67061 struct poll_table_struct *wait);
67062-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
67063+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
67064 int offset, struct iovec *to,
67065 int size);
67066 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
67067diff --git a/include/linux/slab.h b/include/linux/slab.h
67068index 5d168d7..720bff3 100644
67069--- a/include/linux/slab.h
67070+++ b/include/linux/slab.h
67071@@ -12,13 +12,20 @@
67072 #include <linux/gfp.h>
67073 #include <linux/types.h>
67074 #include <linux/workqueue.h>
67075-
67076+#include <linux/err.h>
67077
67078 /*
67079 * Flags to pass to kmem_cache_create().
67080 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
67081 */
67082 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
67083+
67084+#ifdef CONFIG_PAX_USERCOPY_SLABS
67085+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
67086+#else
67087+#define SLAB_USERCOPY 0x00000000UL
67088+#endif
67089+
67090 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
67091 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
67092 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
67093@@ -89,10 +96,13 @@
67094 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
67095 * Both make kfree a no-op.
67096 */
67097-#define ZERO_SIZE_PTR ((void *)16)
67098+#define ZERO_SIZE_PTR \
67099+({ \
67100+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
67101+ (void *)(-MAX_ERRNO-1L); \
67102+})
67103
67104-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
67105- (unsigned long)ZERO_SIZE_PTR)
67106+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
67107
67108 /*
67109 * Common fields provided in kmem_cache by all slab allocators
67110@@ -112,7 +122,7 @@ struct kmem_cache {
67111 unsigned int align; /* Alignment as calculated */
67112 unsigned long flags; /* Active flags on the slab */
67113 const char *name; /* Slab name for sysfs */
67114- int refcount; /* Use counter */
67115+ atomic_t refcount; /* Use counter */
67116 void (*ctor)(void *); /* Called on object slot creation */
67117 struct list_head list; /* List of all slab caches on the system */
67118 };
67119@@ -232,6 +242,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
67120 void kfree(const void *);
67121 void kzfree(const void *);
67122 size_t ksize(const void *);
67123+const char *check_heap_object(const void *ptr, unsigned long n);
67124+bool is_usercopy_object(const void *ptr);
67125
67126 /*
67127 * Allocator specific definitions. These are mainly used to establish optimized
67128@@ -311,6 +323,7 @@ size_t ksize(const void *);
67129 * for general use, and so are not documented here. For a full list of
67130 * potential flags, always refer to linux/gfp.h.
67131 */
67132+
67133 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
67134 {
67135 if (size != 0 && n > SIZE_MAX / size)
67136@@ -370,7 +383,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
67137 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
67138 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
67139 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
67140-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
67141+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
67142 #define kmalloc_track_caller(size, flags) \
67143 __kmalloc_track_caller(size, flags, _RET_IP_)
67144 #else
67145@@ -390,7 +403,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
67146 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
67147 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
67148 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
67149-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
67150+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
67151 #define kmalloc_node_track_caller(size, flags, node) \
67152 __kmalloc_node_track_caller(size, flags, node, \
67153 _RET_IP_)
67154diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
67155index 8bb6e0e..8eb0dbe 100644
67156--- a/include/linux/slab_def.h
67157+++ b/include/linux/slab_def.h
67158@@ -52,7 +52,7 @@ struct kmem_cache {
67159 /* 4) cache creation/removal */
67160 const char *name;
67161 struct list_head list;
67162- int refcount;
67163+ atomic_t refcount;
67164 int object_size;
67165 int align;
67166
67167@@ -68,10 +68,10 @@ struct kmem_cache {
67168 unsigned long node_allocs;
67169 unsigned long node_frees;
67170 unsigned long node_overflow;
67171- atomic_t allochit;
67172- atomic_t allocmiss;
67173- atomic_t freehit;
67174- atomic_t freemiss;
67175+ atomic_unchecked_t allochit;
67176+ atomic_unchecked_t allocmiss;
67177+ atomic_unchecked_t freehit;
67178+ atomic_unchecked_t freemiss;
67179
67180 /*
67181 * If debugging is enabled, then the allocator can add additional
67182@@ -111,11 +111,16 @@ struct cache_sizes {
67183 #ifdef CONFIG_ZONE_DMA
67184 struct kmem_cache *cs_dmacachep;
67185 #endif
67186+
67187+#ifdef CONFIG_PAX_USERCOPY_SLABS
67188+ struct kmem_cache *cs_usercopycachep;
67189+#endif
67190+
67191 };
67192 extern struct cache_sizes malloc_sizes[];
67193
67194 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
67195-void *__kmalloc(size_t size, gfp_t flags);
67196+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
67197
67198 #ifdef CONFIG_TRACING
67199 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
67200@@ -152,6 +157,13 @@ found:
67201 cachep = malloc_sizes[i].cs_dmacachep;
67202 else
67203 #endif
67204+
67205+#ifdef CONFIG_PAX_USERCOPY_SLABS
67206+ if (flags & GFP_USERCOPY)
67207+ cachep = malloc_sizes[i].cs_usercopycachep;
67208+ else
67209+#endif
67210+
67211 cachep = malloc_sizes[i].cs_cachep;
67212
67213 ret = kmem_cache_alloc_trace(cachep, flags, size);
67214@@ -162,7 +174,7 @@ found:
67215 }
67216
67217 #ifdef CONFIG_NUMA
67218-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
67219+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
67220 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
67221
67222 #ifdef CONFIG_TRACING
67223@@ -205,6 +217,13 @@ found:
67224 cachep = malloc_sizes[i].cs_dmacachep;
67225 else
67226 #endif
67227+
67228+#ifdef CONFIG_PAX_USERCOPY_SLABS
67229+ if (flags & GFP_USERCOPY)
67230+ cachep = malloc_sizes[i].cs_usercopycachep;
67231+ else
67232+#endif
67233+
67234 cachep = malloc_sizes[i].cs_cachep;
67235
67236 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
67237diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
67238index f28e14a..7831211 100644
67239--- a/include/linux/slob_def.h
67240+++ b/include/linux/slob_def.h
67241@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
67242 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
67243 }
67244
67245-void *__kmalloc_node(size_t size, gfp_t flags, int node);
67246+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
67247
67248 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
67249 {
67250@@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
67251 return __kmalloc_node(size, flags, NUMA_NO_NODE);
67252 }
67253
67254-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
67255+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
67256 {
67257 return kmalloc(size, flags);
67258 }
67259diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
67260index 9db4825..ed42fb5 100644
67261--- a/include/linux/slub_def.h
67262+++ b/include/linux/slub_def.h
67263@@ -91,7 +91,7 @@ struct kmem_cache {
67264 struct kmem_cache_order_objects max;
67265 struct kmem_cache_order_objects min;
67266 gfp_t allocflags; /* gfp flags to use on each alloc */
67267- int refcount; /* Refcount for slab cache destroy */
67268+ atomic_t refcount; /* Refcount for slab cache destroy */
67269 void (*ctor)(void *);
67270 int inuse; /* Offset to metadata */
67271 int align; /* Alignment */
67272@@ -156,7 +156,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
67273 * Sorry that the following has to be that ugly but some versions of GCC
67274 * have trouble with constant propagation and loops.
67275 */
67276-static __always_inline int kmalloc_index(size_t size)
67277+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
67278 {
67279 if (!size)
67280 return 0;
67281@@ -221,7 +221,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
67282 }
67283
67284 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
67285-void *__kmalloc(size_t size, gfp_t flags);
67286+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
67287
67288 static __always_inline void *
67289 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
67290@@ -265,7 +265,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
67291 }
67292 #endif
67293
67294-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
67295+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
67296 {
67297 unsigned int order = get_order(size);
67298 return kmalloc_order_trace(size, flags, order);
67299@@ -290,7 +290,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
67300 }
67301
67302 #ifdef CONFIG_NUMA
67303-void *__kmalloc_node(size_t size, gfp_t flags, int node);
67304+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
67305 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
67306
67307 #ifdef CONFIG_TRACING
67308diff --git a/include/linux/sonet.h b/include/linux/sonet.h
67309index 680f9a3..f13aeb0 100644
67310--- a/include/linux/sonet.h
67311+++ b/include/linux/sonet.h
67312@@ -7,7 +7,7 @@
67313 #include <uapi/linux/sonet.h>
67314
67315 struct k_sonet_stats {
67316-#define __HANDLE_ITEM(i) atomic_t i
67317+#define __HANDLE_ITEM(i) atomic_unchecked_t i
67318 __SONET_ITEMS
67319 #undef __HANDLE_ITEM
67320 };
67321diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
67322index 34206b8..f019e06 100644
67323--- a/include/linux/sunrpc/clnt.h
67324+++ b/include/linux/sunrpc/clnt.h
67325@@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
67326 {
67327 switch (sap->sa_family) {
67328 case AF_INET:
67329- return ntohs(((struct sockaddr_in *)sap)->sin_port);
67330+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
67331 case AF_INET6:
67332- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
67333+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
67334 }
67335 return 0;
67336 }
67337@@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
67338 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
67339 const struct sockaddr *src)
67340 {
67341- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
67342+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
67343 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
67344
67345 dsin->sin_family = ssin->sin_family;
67346@@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
67347 if (sa->sa_family != AF_INET6)
67348 return 0;
67349
67350- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
67351+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
67352 }
67353
67354 #endif /* __KERNEL__ */
67355diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
67356index 0b8e3e6..33e0a01 100644
67357--- a/include/linux/sunrpc/svc_rdma.h
67358+++ b/include/linux/sunrpc/svc_rdma.h
67359@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
67360 extern unsigned int svcrdma_max_requests;
67361 extern unsigned int svcrdma_max_req_size;
67362
67363-extern atomic_t rdma_stat_recv;
67364-extern atomic_t rdma_stat_read;
67365-extern atomic_t rdma_stat_write;
67366-extern atomic_t rdma_stat_sq_starve;
67367-extern atomic_t rdma_stat_rq_starve;
67368-extern atomic_t rdma_stat_rq_poll;
67369-extern atomic_t rdma_stat_rq_prod;
67370-extern atomic_t rdma_stat_sq_poll;
67371-extern atomic_t rdma_stat_sq_prod;
67372+extern atomic_unchecked_t rdma_stat_recv;
67373+extern atomic_unchecked_t rdma_stat_read;
67374+extern atomic_unchecked_t rdma_stat_write;
67375+extern atomic_unchecked_t rdma_stat_sq_starve;
67376+extern atomic_unchecked_t rdma_stat_rq_starve;
67377+extern atomic_unchecked_t rdma_stat_rq_poll;
67378+extern atomic_unchecked_t rdma_stat_rq_prod;
67379+extern atomic_unchecked_t rdma_stat_sq_poll;
67380+extern atomic_unchecked_t rdma_stat_sq_prod;
67381
67382 #define RPCRDMA_VERSION 1
67383
67384diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
67385index 14a8ff2..21fe4c7 100644
67386--- a/include/linux/sysctl.h
67387+++ b/include/linux/sysctl.h
67388@@ -41,6 +41,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
67389
67390 extern int proc_dostring(struct ctl_table *, int,
67391 void __user *, size_t *, loff_t *);
67392+extern int proc_dostring_modpriv(struct ctl_table *, int,
67393+ void __user *, size_t *, loff_t *);
67394 extern int proc_dointvec(struct ctl_table *, int,
67395 void __user *, size_t *, loff_t *);
67396 extern int proc_dointvec_minmax(struct ctl_table *, int,
67397diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
67398index 7faf933..eb6f5e3 100644
67399--- a/include/linux/sysrq.h
67400+++ b/include/linux/sysrq.h
67401@@ -36,7 +36,7 @@ struct sysrq_key_op {
67402 char *help_msg;
67403 char *action_msg;
67404 int enable_mask;
67405-};
67406+} __do_const;
67407
67408 #ifdef CONFIG_MAGIC_SYSRQ
67409
67410diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
67411index e7e0473..39b7b52 100644
67412--- a/include/linux/thread_info.h
67413+++ b/include/linux/thread_info.h
67414@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
67415 #error "no set_restore_sigmask() provided and default one won't work"
67416 #endif
67417
67418+extern void __check_object_size(const void *ptr, unsigned long n, bool to);
67419+static inline void check_object_size(const void *ptr, unsigned long n, bool to)
67420+{
67421+#ifndef CONFIG_PAX_USERCOPY_DEBUG
67422+ if (!__builtin_constant_p(n))
67423+#endif
67424+ __check_object_size(ptr, n, to);
67425+}
67426+
67427 #endif /* __KERNEL__ */
67428
67429 #endif /* _LINUX_THREAD_INFO_H */
67430diff --git a/include/linux/tty.h b/include/linux/tty.h
67431index 8db1b56..c16a040 100644
67432--- a/include/linux/tty.h
67433+++ b/include/linux/tty.h
67434@@ -194,7 +194,7 @@ struct tty_port {
67435 const struct tty_port_operations *ops; /* Port operations */
67436 spinlock_t lock; /* Lock protecting tty field */
67437 int blocked_open; /* Waiting to open */
67438- int count; /* Usage count */
67439+ atomic_t count; /* Usage count */
67440 wait_queue_head_t open_wait; /* Open waiters */
67441 wait_queue_head_t close_wait; /* Close waiters */
67442 wait_queue_head_t delta_msr_wait; /* Modem status change */
67443@@ -490,7 +490,7 @@ extern int tty_port_open(struct tty_port *port,
67444 struct tty_struct *tty, struct file *filp);
67445 static inline int tty_port_users(struct tty_port *port)
67446 {
67447- return port->count + port->blocked_open;
67448+ return atomic_read(&port->count) + port->blocked_open;
67449 }
67450
67451 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
67452diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
67453index dd976cf..e272742 100644
67454--- a/include/linux/tty_driver.h
67455+++ b/include/linux/tty_driver.h
67456@@ -284,7 +284,7 @@ struct tty_operations {
67457 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
67458 #endif
67459 const struct file_operations *proc_fops;
67460-};
67461+} __do_const;
67462
67463 struct tty_driver {
67464 int magic; /* magic number for this structure */
67465diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
67466index fb79dd8d..07d4773 100644
67467--- a/include/linux/tty_ldisc.h
67468+++ b/include/linux/tty_ldisc.h
67469@@ -149,7 +149,7 @@ struct tty_ldisc_ops {
67470
67471 struct module *owner;
67472
67473- int refcount;
67474+ atomic_t refcount;
67475 };
67476
67477 struct tty_ldisc {
67478diff --git a/include/linux/types.h b/include/linux/types.h
67479index 4d118ba..c3ee9bf 100644
67480--- a/include/linux/types.h
67481+++ b/include/linux/types.h
67482@@ -176,10 +176,26 @@ typedef struct {
67483 int counter;
67484 } atomic_t;
67485
67486+#ifdef CONFIG_PAX_REFCOUNT
67487+typedef struct {
67488+ int counter;
67489+} atomic_unchecked_t;
67490+#else
67491+typedef atomic_t atomic_unchecked_t;
67492+#endif
67493+
67494 #ifdef CONFIG_64BIT
67495 typedef struct {
67496 long counter;
67497 } atomic64_t;
67498+
67499+#ifdef CONFIG_PAX_REFCOUNT
67500+typedef struct {
67501+ long counter;
67502+} atomic64_unchecked_t;
67503+#else
67504+typedef atomic64_t atomic64_unchecked_t;
67505+#endif
67506 #endif
67507
67508 struct list_head {
67509diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
67510index 5ca0951..ab496a5 100644
67511--- a/include/linux/uaccess.h
67512+++ b/include/linux/uaccess.h
67513@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
67514 long ret; \
67515 mm_segment_t old_fs = get_fs(); \
67516 \
67517- set_fs(KERNEL_DS); \
67518 pagefault_disable(); \
67519- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
67520- pagefault_enable(); \
67521+ set_fs(KERNEL_DS); \
67522+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
67523 set_fs(old_fs); \
67524+ pagefault_enable(); \
67525 ret; \
67526 })
67527
67528diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
67529index 99c1b4d..bb94261 100644
67530--- a/include/linux/unaligned/access_ok.h
67531+++ b/include/linux/unaligned/access_ok.h
67532@@ -6,32 +6,32 @@
67533
67534 static inline u16 get_unaligned_le16(const void *p)
67535 {
67536- return le16_to_cpup((__le16 *)p);
67537+ return le16_to_cpup((const __le16 *)p);
67538 }
67539
67540 static inline u32 get_unaligned_le32(const void *p)
67541 {
67542- return le32_to_cpup((__le32 *)p);
67543+ return le32_to_cpup((const __le32 *)p);
67544 }
67545
67546 static inline u64 get_unaligned_le64(const void *p)
67547 {
67548- return le64_to_cpup((__le64 *)p);
67549+ return le64_to_cpup((const __le64 *)p);
67550 }
67551
67552 static inline u16 get_unaligned_be16(const void *p)
67553 {
67554- return be16_to_cpup((__be16 *)p);
67555+ return be16_to_cpup((const __be16 *)p);
67556 }
67557
67558 static inline u32 get_unaligned_be32(const void *p)
67559 {
67560- return be32_to_cpup((__be32 *)p);
67561+ return be32_to_cpup((const __be32 *)p);
67562 }
67563
67564 static inline u64 get_unaligned_be64(const void *p)
67565 {
67566- return be64_to_cpup((__be64 *)p);
67567+ return be64_to_cpup((const __be64 *)p);
67568 }
67569
67570 static inline void put_unaligned_le16(u16 val, void *p)
67571diff --git a/include/linux/usb.h b/include/linux/usb.h
67572index 4d22d0f..ac43c2f 100644
67573--- a/include/linux/usb.h
67574+++ b/include/linux/usb.h
67575@@ -554,7 +554,7 @@ struct usb_device {
67576 int maxchild;
67577
67578 u32 quirks;
67579- atomic_t urbnum;
67580+ atomic_unchecked_t urbnum;
67581
67582 unsigned long active_duration;
67583
67584diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
67585index c5d36c6..108f4f9 100644
67586--- a/include/linux/usb/renesas_usbhs.h
67587+++ b/include/linux/usb/renesas_usbhs.h
67588@@ -39,7 +39,7 @@ enum {
67589 */
67590 struct renesas_usbhs_driver_callback {
67591 int (*notify_hotplug)(struct platform_device *pdev);
67592-};
67593+} __no_const;
67594
67595 /*
67596 * callback functions for platform
67597diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
67598index 6f8fbcf..8259001 100644
67599--- a/include/linux/vermagic.h
67600+++ b/include/linux/vermagic.h
67601@@ -25,9 +25,35 @@
67602 #define MODULE_ARCH_VERMAGIC ""
67603 #endif
67604
67605+#ifdef CONFIG_PAX_REFCOUNT
67606+#define MODULE_PAX_REFCOUNT "REFCOUNT "
67607+#else
67608+#define MODULE_PAX_REFCOUNT ""
67609+#endif
67610+
67611+#ifdef CONSTIFY_PLUGIN
67612+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
67613+#else
67614+#define MODULE_CONSTIFY_PLUGIN ""
67615+#endif
67616+
67617+#ifdef STACKLEAK_PLUGIN
67618+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
67619+#else
67620+#define MODULE_STACKLEAK_PLUGIN ""
67621+#endif
67622+
67623+#ifdef CONFIG_GRKERNSEC
67624+#define MODULE_GRSEC "GRSEC "
67625+#else
67626+#define MODULE_GRSEC ""
67627+#endif
67628+
67629 #define VERMAGIC_STRING \
67630 UTS_RELEASE " " \
67631 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
67632 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
67633- MODULE_ARCH_VERMAGIC
67634+ MODULE_ARCH_VERMAGIC \
67635+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
67636+ MODULE_GRSEC
67637
67638diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
67639index 6071e91..ca6a489 100644
67640--- a/include/linux/vmalloc.h
67641+++ b/include/linux/vmalloc.h
67642@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
67643 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
67644 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
67645 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
67646+
67647+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
67648+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
67649+#endif
67650+
67651 /* bits [20..32] reserved for arch specific ioremap internals */
67652
67653 /*
67654@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
67655 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
67656 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
67657 unsigned long start, unsigned long end, gfp_t gfp_mask,
67658- pgprot_t prot, int node, const void *caller);
67659+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
67660 extern void vfree(const void *addr);
67661
67662 extern void *vmap(struct page **pages, unsigned int count,
67663@@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
67664 extern void free_vm_area(struct vm_struct *area);
67665
67666 /* for /dev/kmem */
67667-extern long vread(char *buf, char *addr, unsigned long count);
67668-extern long vwrite(char *buf, char *addr, unsigned long count);
67669+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
67670+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
67671
67672 /*
67673 * Internals. Dont't use..
67674diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
67675index a13291f..af51fa3 100644
67676--- a/include/linux/vmstat.h
67677+++ b/include/linux/vmstat.h
67678@@ -95,18 +95,18 @@ static inline void vm_events_fold_cpu(int cpu)
67679 /*
67680 * Zone based page accounting with per cpu differentials.
67681 */
67682-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
67683+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
67684
67685 static inline void zone_page_state_add(long x, struct zone *zone,
67686 enum zone_stat_item item)
67687 {
67688- atomic_long_add(x, &zone->vm_stat[item]);
67689- atomic_long_add(x, &vm_stat[item]);
67690+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
67691+ atomic_long_add_unchecked(x, &vm_stat[item]);
67692 }
67693
67694 static inline unsigned long global_page_state(enum zone_stat_item item)
67695 {
67696- long x = atomic_long_read(&vm_stat[item]);
67697+ long x = atomic_long_read_unchecked(&vm_stat[item]);
67698 #ifdef CONFIG_SMP
67699 if (x < 0)
67700 x = 0;
67701@@ -117,7 +117,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
67702 static inline unsigned long zone_page_state(struct zone *zone,
67703 enum zone_stat_item item)
67704 {
67705- long x = atomic_long_read(&zone->vm_stat[item]);
67706+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
67707 #ifdef CONFIG_SMP
67708 if (x < 0)
67709 x = 0;
67710@@ -134,7 +134,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
67711 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
67712 enum zone_stat_item item)
67713 {
67714- long x = atomic_long_read(&zone->vm_stat[item]);
67715+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
67716
67717 #ifdef CONFIG_SMP
67718 int cpu;
67719@@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
67720
67721 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
67722 {
67723- atomic_long_inc(&zone->vm_stat[item]);
67724- atomic_long_inc(&vm_stat[item]);
67725+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
67726+ atomic_long_inc_unchecked(&vm_stat[item]);
67727 }
67728
67729 static inline void __inc_zone_page_state(struct page *page,
67730@@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
67731
67732 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
67733 {
67734- atomic_long_dec(&zone->vm_stat[item]);
67735- atomic_long_dec(&vm_stat[item]);
67736+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
67737+ atomic_long_dec_unchecked(&vm_stat[item]);
67738 }
67739
67740 static inline void __dec_zone_page_state(struct page *page,
67741diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
67742index 95d1c91..6798cca 100644
67743--- a/include/media/v4l2-dev.h
67744+++ b/include/media/v4l2-dev.h
67745@@ -76,7 +76,7 @@ struct v4l2_file_operations {
67746 int (*mmap) (struct file *, struct vm_area_struct *);
67747 int (*open) (struct file *);
67748 int (*release) (struct file *);
67749-};
67750+} __do_const;
67751
67752 /*
67753 * Newer version of video_device, handled by videodev2.c
67754diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
67755index 4118ad1..cb7e25f 100644
67756--- a/include/media/v4l2-ioctl.h
67757+++ b/include/media/v4l2-ioctl.h
67758@@ -284,7 +284,6 @@ struct v4l2_ioctl_ops {
67759 bool valid_prio, int cmd, void *arg);
67760 };
67761
67762-
67763 /* v4l debugging and diagnostics */
67764
67765 /* Debug bitmask flags to be used on V4L2 */
67766diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
67767index 9e5425b..8136ffc 100644
67768--- a/include/net/caif/cfctrl.h
67769+++ b/include/net/caif/cfctrl.h
67770@@ -52,7 +52,7 @@ struct cfctrl_rsp {
67771 void (*radioset_rsp)(void);
67772 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
67773 struct cflayer *client_layer);
67774-};
67775+} __no_const;
67776
67777 /* Link Setup Parameters for CAIF-Links. */
67778 struct cfctrl_link_param {
67779@@ -101,8 +101,8 @@ struct cfctrl_request_info {
67780 struct cfctrl {
67781 struct cfsrvl serv;
67782 struct cfctrl_rsp res;
67783- atomic_t req_seq_no;
67784- atomic_t rsp_seq_no;
67785+ atomic_unchecked_t req_seq_no;
67786+ atomic_unchecked_t rsp_seq_no;
67787 struct list_head list;
67788 /* Protects from simultaneous access to first_req list */
67789 spinlock_t info_list_lock;
67790diff --git a/include/net/flow.h b/include/net/flow.h
67791index 628e11b..4c475df 100644
67792--- a/include/net/flow.h
67793+++ b/include/net/flow.h
67794@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
67795
67796 extern void flow_cache_flush(void);
67797 extern void flow_cache_flush_deferred(void);
67798-extern atomic_t flow_cache_genid;
67799+extern atomic_unchecked_t flow_cache_genid;
67800
67801 #endif
67802diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
67803index e5062c9..48a9a4b 100644
67804--- a/include/net/gro_cells.h
67805+++ b/include/net/gro_cells.h
67806@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
67807 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
67808
67809 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
67810- atomic_long_inc(&dev->rx_dropped);
67811+ atomic_long_inc_unchecked(&dev->rx_dropped);
67812 kfree_skb(skb);
67813 return;
67814 }
67815@@ -73,8 +73,8 @@ static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *de
67816 int i;
67817
67818 gcells->gro_cells_mask = roundup_pow_of_two(netif_get_num_default_rss_queues()) - 1;
67819- gcells->cells = kcalloc(sizeof(struct gro_cell),
67820- gcells->gro_cells_mask + 1,
67821+ gcells->cells = kcalloc(gcells->gro_cells_mask + 1,
67822+ sizeof(struct gro_cell),
67823 GFP_KERNEL);
67824 if (!gcells->cells)
67825 return -ENOMEM;
67826diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
67827index 1832927..ce39aea 100644
67828--- a/include/net/inet_connection_sock.h
67829+++ b/include/net/inet_connection_sock.h
67830@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
67831 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
67832 int (*bind_conflict)(const struct sock *sk,
67833 const struct inet_bind_bucket *tb, bool relax);
67834-};
67835+} __do_const;
67836
67837 /** inet_connection_sock - INET connection oriented sock
67838 *
67839diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
67840index 53f464d..ba76aaa 100644
67841--- a/include/net/inetpeer.h
67842+++ b/include/net/inetpeer.h
67843@@ -47,8 +47,8 @@ struct inet_peer {
67844 */
67845 union {
67846 struct {
67847- atomic_t rid; /* Frag reception counter */
67848- atomic_t ip_id_count; /* IP ID for the next packet */
67849+ atomic_unchecked_t rid; /* Frag reception counter */
67850+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
67851 };
67852 struct rcu_head rcu;
67853 struct inet_peer *gc_next;
67854@@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
67855 more++;
67856 inet_peer_refcheck(p);
67857 do {
67858- old = atomic_read(&p->ip_id_count);
67859+ old = atomic_read_unchecked(&p->ip_id_count);
67860 new = old + more;
67861 if (!new)
67862 new = 1;
67863- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
67864+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
67865 return new;
67866 }
67867
67868diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
67869index 9497be1..5a4fafe 100644
67870--- a/include/net/ip_fib.h
67871+++ b/include/net/ip_fib.h
67872@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
67873
67874 #define FIB_RES_SADDR(net, res) \
67875 ((FIB_RES_NH(res).nh_saddr_genid == \
67876- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
67877+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
67878 FIB_RES_NH(res).nh_saddr : \
67879 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
67880 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
67881diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
67882index 68c69d5..2ee192b 100644
67883--- a/include/net/ip_vs.h
67884+++ b/include/net/ip_vs.h
67885@@ -599,7 +599,7 @@ struct ip_vs_conn {
67886 struct ip_vs_conn *control; /* Master control connection */
67887 atomic_t n_control; /* Number of controlled ones */
67888 struct ip_vs_dest *dest; /* real server */
67889- atomic_t in_pkts; /* incoming packet counter */
67890+ atomic_unchecked_t in_pkts; /* incoming packet counter */
67891
67892 /* packet transmitter for different forwarding methods. If it
67893 mangles the packet, it must return NF_DROP or better NF_STOLEN,
67894@@ -737,7 +737,7 @@ struct ip_vs_dest {
67895 __be16 port; /* port number of the server */
67896 union nf_inet_addr addr; /* IP address of the server */
67897 volatile unsigned int flags; /* dest status flags */
67898- atomic_t conn_flags; /* flags to copy to conn */
67899+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
67900 atomic_t weight; /* server weight */
67901
67902 atomic_t refcnt; /* reference counter */
67903diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
67904index 80ffde3..968b0f4 100644
67905--- a/include/net/irda/ircomm_tty.h
67906+++ b/include/net/irda/ircomm_tty.h
67907@@ -35,6 +35,7 @@
67908 #include <linux/termios.h>
67909 #include <linux/timer.h>
67910 #include <linux/tty.h> /* struct tty_struct */
67911+#include <asm/local.h>
67912
67913 #include <net/irda/irias_object.h>
67914 #include <net/irda/ircomm_core.h>
67915diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
67916index cc7c197..9f2da2a 100644
67917--- a/include/net/iucv/af_iucv.h
67918+++ b/include/net/iucv/af_iucv.h
67919@@ -141,7 +141,7 @@ struct iucv_sock {
67920 struct iucv_sock_list {
67921 struct hlist_head head;
67922 rwlock_t lock;
67923- atomic_t autobind_name;
67924+ atomic_unchecked_t autobind_name;
67925 };
67926
67927 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
67928diff --git a/include/net/neighbour.h b/include/net/neighbour.h
67929index 0dab173..1b76af0 100644
67930--- a/include/net/neighbour.h
67931+++ b/include/net/neighbour.h
67932@@ -123,7 +123,7 @@ struct neigh_ops {
67933 void (*error_report)(struct neighbour *, struct sk_buff *);
67934 int (*output)(struct neighbour *, struct sk_buff *);
67935 int (*connected_output)(struct neighbour *, struct sk_buff *);
67936-};
67937+} __do_const;
67938
67939 struct pneigh_entry {
67940 struct pneigh_entry *next;
67941diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
67942index de644bc..666aed3 100644
67943--- a/include/net/net_namespace.h
67944+++ b/include/net/net_namespace.h
67945@@ -115,7 +115,7 @@ struct net {
67946 #endif
67947 struct netns_ipvs *ipvs;
67948 struct sock *diag_nlsk;
67949- atomic_t rt_genid;
67950+ atomic_unchecked_t rt_genid;
67951 };
67952
67953 /*
67954@@ -330,12 +330,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
67955
67956 static inline int rt_genid(struct net *net)
67957 {
67958- return atomic_read(&net->rt_genid);
67959+ return atomic_read_unchecked(&net->rt_genid);
67960 }
67961
67962 static inline void rt_genid_bump(struct net *net)
67963 {
67964- atomic_inc(&net->rt_genid);
67965+ atomic_inc_unchecked(&net->rt_genid);
67966 }
67967
67968 #endif /* __NET_NET_NAMESPACE_H */
67969diff --git a/include/net/netdma.h b/include/net/netdma.h
67970index 8ba8ce2..99b7fff 100644
67971--- a/include/net/netdma.h
67972+++ b/include/net/netdma.h
67973@@ -24,7 +24,7 @@
67974 #include <linux/dmaengine.h>
67975 #include <linux/skbuff.h>
67976
67977-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
67978+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
67979 struct sk_buff *skb, int offset, struct iovec *to,
67980 size_t len, struct dma_pinned_list *pinned_list);
67981
67982diff --git a/include/net/netlink.h b/include/net/netlink.h
67983index 9690b0f..87aded7 100644
67984--- a/include/net/netlink.h
67985+++ b/include/net/netlink.h
67986@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
67987 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
67988 {
67989 if (mark)
67990- skb_trim(skb, (unsigned char *) mark - skb->data);
67991+ skb_trim(skb, (const unsigned char *) mark - skb->data);
67992 }
67993
67994 /**
67995diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
67996index 2ae2b83..dbdc85e 100644
67997--- a/include/net/netns/ipv4.h
67998+++ b/include/net/netns/ipv4.h
67999@@ -64,7 +64,7 @@ struct netns_ipv4 {
68000 kgid_t sysctl_ping_group_range[2];
68001 long sysctl_tcp_mem[3];
68002
68003- atomic_t dev_addr_genid;
68004+ atomic_unchecked_t dev_addr_genid;
68005
68006 #ifdef CONFIG_IP_MROUTE
68007 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
68008diff --git a/include/net/protocol.h b/include/net/protocol.h
68009index 047c047..b9dad15 100644
68010--- a/include/net/protocol.h
68011+++ b/include/net/protocol.h
68012@@ -44,7 +44,7 @@ struct net_protocol {
68013 void (*err_handler)(struct sk_buff *skb, u32 info);
68014 unsigned int no_policy:1,
68015 netns_ok:1;
68016-};
68017+} __do_const;
68018
68019 #if IS_ENABLED(CONFIG_IPV6)
68020 struct inet6_protocol {
68021@@ -57,7 +57,7 @@ struct inet6_protocol {
68022 u8 type, u8 code, int offset,
68023 __be32 info);
68024 unsigned int flags; /* INET6_PROTO_xxx */
68025-};
68026+} __do_const;
68027
68028 #define INET6_PROTO_NOPOLICY 0x1
68029 #define INET6_PROTO_FINAL 0x2
68030diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
68031index 7fdf298..197e9f7 100644
68032--- a/include/net/sctp/sctp.h
68033+++ b/include/net/sctp/sctp.h
68034@@ -330,9 +330,9 @@ do { \
68035
68036 #else /* SCTP_DEBUG */
68037
68038-#define SCTP_DEBUG_PRINTK(whatever...)
68039-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
68040-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
68041+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
68042+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
68043+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
68044 #define SCTP_ENABLE_DEBUG
68045 #define SCTP_DISABLE_DEBUG
68046 #define SCTP_ASSERT(expr, str, func)
68047diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
68048index fdeb85a..0c554d5 100644
68049--- a/include/net/sctp/structs.h
68050+++ b/include/net/sctp/structs.h
68051@@ -497,7 +497,7 @@ struct sctp_af {
68052 int sockaddr_len;
68053 sa_family_t sa_family;
68054 struct list_head list;
68055-};
68056+} __do_const;
68057
68058 struct sctp_af *sctp_get_af_specific(sa_family_t);
68059 int sctp_register_af(struct sctp_af *);
68060@@ -517,7 +517,7 @@ struct sctp_pf {
68061 struct sctp_association *asoc);
68062 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
68063 struct sctp_af *af;
68064-};
68065+} __do_const;
68066
68067
68068 /* Structure to track chunk fragments that have been acked, but peer
68069diff --git a/include/net/sock.h b/include/net/sock.h
68070index 182ca99..b7dc290 100644
68071--- a/include/net/sock.h
68072+++ b/include/net/sock.h
68073@@ -322,7 +322,7 @@ struct sock {
68074 #ifdef CONFIG_RPS
68075 __u32 sk_rxhash;
68076 #endif
68077- atomic_t sk_drops;
68078+ atomic_unchecked_t sk_drops;
68079 int sk_rcvbuf;
68080
68081 struct sk_filter __rcu *sk_filter;
68082@@ -1781,7 +1781,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
68083 }
68084
68085 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
68086- char __user *from, char *to,
68087+ char __user *from, unsigned char *to,
68088 int copy, int offset)
68089 {
68090 if (skb->ip_summed == CHECKSUM_NONE) {
68091@@ -2040,7 +2040,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
68092 }
68093 }
68094
68095-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
68096+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
68097
68098 /**
68099 * sk_page_frag - return an appropriate page_frag
68100diff --git a/include/net/tcp.h b/include/net/tcp.h
68101index aed42c7..43890c6 100644
68102--- a/include/net/tcp.h
68103+++ b/include/net/tcp.h
68104@@ -530,7 +530,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
68105 extern void tcp_xmit_retransmit_queue(struct sock *);
68106 extern void tcp_simple_retransmit(struct sock *);
68107 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
68108-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
68109+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
68110
68111 extern void tcp_send_probe0(struct sock *);
68112 extern void tcp_send_partial(struct sock *);
68113@@ -701,8 +701,8 @@ struct tcp_skb_cb {
68114 struct inet6_skb_parm h6;
68115 #endif
68116 } header; /* For incoming frames */
68117- __u32 seq; /* Starting sequence number */
68118- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
68119+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
68120+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
68121 __u32 when; /* used to compute rtt's */
68122 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
68123
68124@@ -716,7 +716,7 @@ struct tcp_skb_cb {
68125
68126 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
68127 /* 1 byte hole */
68128- __u32 ack_seq; /* Sequence number ACK'd */
68129+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
68130 };
68131
68132 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
68133diff --git a/include/net/xfrm.h b/include/net/xfrm.h
68134index 63445ed..74ef61d 100644
68135--- a/include/net/xfrm.h
68136+++ b/include/net/xfrm.h
68137@@ -423,7 +423,7 @@ struct xfrm_mode {
68138 struct module *owner;
68139 unsigned int encap;
68140 int flags;
68141-};
68142+} __do_const;
68143
68144 /* Flags for xfrm_mode. */
68145 enum {
68146@@ -514,7 +514,7 @@ struct xfrm_policy {
68147 struct timer_list timer;
68148
68149 struct flow_cache_object flo;
68150- atomic_t genid;
68151+ atomic_unchecked_t genid;
68152 u32 priority;
68153 u32 index;
68154 struct xfrm_mark mark;
68155diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
68156index 1a046b1..ee0bef0 100644
68157--- a/include/rdma/iw_cm.h
68158+++ b/include/rdma/iw_cm.h
68159@@ -122,7 +122,7 @@ struct iw_cm_verbs {
68160 int backlog);
68161
68162 int (*destroy_listen)(struct iw_cm_id *cm_id);
68163-};
68164+} __no_const;
68165
68166 /**
68167 * iw_create_cm_id - Create an IW CM identifier.
68168diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
68169index 399162b..b337f1a 100644
68170--- a/include/scsi/libfc.h
68171+++ b/include/scsi/libfc.h
68172@@ -762,6 +762,7 @@ struct libfc_function_template {
68173 */
68174 void (*disc_stop_final) (struct fc_lport *);
68175 };
68176+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
68177
68178 /**
68179 * struct fc_disc - Discovery context
68180@@ -866,7 +867,7 @@ struct fc_lport {
68181 struct fc_vport *vport;
68182
68183 /* Operational Information */
68184- struct libfc_function_template tt;
68185+ libfc_function_template_no_const tt;
68186 u8 link_up;
68187 u8 qfull;
68188 enum fc_lport_state state;
68189diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
68190index e65c62e..aa2e5a2 100644
68191--- a/include/scsi/scsi_device.h
68192+++ b/include/scsi/scsi_device.h
68193@@ -170,9 +170,9 @@ struct scsi_device {
68194 unsigned int max_device_blocked; /* what device_blocked counts down from */
68195 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
68196
68197- atomic_t iorequest_cnt;
68198- atomic_t iodone_cnt;
68199- atomic_t ioerr_cnt;
68200+ atomic_unchecked_t iorequest_cnt;
68201+ atomic_unchecked_t iodone_cnt;
68202+ atomic_unchecked_t ioerr_cnt;
68203
68204 struct device sdev_gendev,
68205 sdev_dev;
68206diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
68207index b797e8f..8e2c3aa 100644
68208--- a/include/scsi/scsi_transport_fc.h
68209+++ b/include/scsi/scsi_transport_fc.h
68210@@ -751,7 +751,8 @@ struct fc_function_template {
68211 unsigned long show_host_system_hostname:1;
68212
68213 unsigned long disable_target_scan:1;
68214-};
68215+} __do_const;
68216+typedef struct fc_function_template __no_const fc_function_template_no_const;
68217
68218
68219 /**
68220diff --git a/include/sound/soc.h b/include/sound/soc.h
68221index bc56738..a4be132 100644
68222--- a/include/sound/soc.h
68223+++ b/include/sound/soc.h
68224@@ -771,7 +771,7 @@ struct snd_soc_codec_driver {
68225 /* probe ordering - for components with runtime dependencies */
68226 int probe_order;
68227 int remove_order;
68228-};
68229+} __do_const;
68230
68231 /* SoC platform interface */
68232 struct snd_soc_platform_driver {
68233@@ -817,7 +817,7 @@ struct snd_soc_platform_driver {
68234 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
68235 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
68236 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
68237-};
68238+} __do_const;
68239
68240 struct snd_soc_platform {
68241 const char *name;
68242diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
68243index 663e34a..91b306a 100644
68244--- a/include/target/target_core_base.h
68245+++ b/include/target/target_core_base.h
68246@@ -654,7 +654,7 @@ struct se_device {
68247 spinlock_t stats_lock;
68248 /* Active commands on this virtual SE device */
68249 atomic_t simple_cmds;
68250- atomic_t dev_ordered_id;
68251+ atomic_unchecked_t dev_ordered_id;
68252 atomic_t dev_ordered_sync;
68253 atomic_t dev_qf_count;
68254 int export_count;
68255diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
68256new file mode 100644
68257index 0000000..fb634b7
68258--- /dev/null
68259+++ b/include/trace/events/fs.h
68260@@ -0,0 +1,53 @@
68261+#undef TRACE_SYSTEM
68262+#define TRACE_SYSTEM fs
68263+
68264+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
68265+#define _TRACE_FS_H
68266+
68267+#include <linux/fs.h>
68268+#include <linux/tracepoint.h>
68269+
68270+TRACE_EVENT(do_sys_open,
68271+
68272+ TP_PROTO(const char *filename, int flags, int mode),
68273+
68274+ TP_ARGS(filename, flags, mode),
68275+
68276+ TP_STRUCT__entry(
68277+ __string( filename, filename )
68278+ __field( int, flags )
68279+ __field( int, mode )
68280+ ),
68281+
68282+ TP_fast_assign(
68283+ __assign_str(filename, filename);
68284+ __entry->flags = flags;
68285+ __entry->mode = mode;
68286+ ),
68287+
68288+ TP_printk("\"%s\" %x %o",
68289+ __get_str(filename), __entry->flags, __entry->mode)
68290+);
68291+
68292+TRACE_EVENT(open_exec,
68293+
68294+ TP_PROTO(const char *filename),
68295+
68296+ TP_ARGS(filename),
68297+
68298+ TP_STRUCT__entry(
68299+ __string( filename, filename )
68300+ ),
68301+
68302+ TP_fast_assign(
68303+ __assign_str(filename, filename);
68304+ ),
68305+
68306+ TP_printk("\"%s\"",
68307+ __get_str(filename))
68308+);
68309+
68310+#endif /* _TRACE_FS_H */
68311+
68312+/* This part must be outside protection */
68313+#include <trace/define_trace.h>
68314diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
68315index 1c09820..7f5ec79 100644
68316--- a/include/trace/events/irq.h
68317+++ b/include/trace/events/irq.h
68318@@ -36,7 +36,7 @@ struct softirq_action;
68319 */
68320 TRACE_EVENT(irq_handler_entry,
68321
68322- TP_PROTO(int irq, struct irqaction *action),
68323+ TP_PROTO(int irq, const struct irqaction *action),
68324
68325 TP_ARGS(irq, action),
68326
68327@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
68328 */
68329 TRACE_EVENT(irq_handler_exit,
68330
68331- TP_PROTO(int irq, struct irqaction *action, int ret),
68332+ TP_PROTO(int irq, const struct irqaction *action, int ret),
68333
68334 TP_ARGS(irq, action, ret),
68335
68336diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
68337index 7caf44c..23c6f27 100644
68338--- a/include/uapi/linux/a.out.h
68339+++ b/include/uapi/linux/a.out.h
68340@@ -39,6 +39,14 @@ enum machine_type {
68341 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
68342 };
68343
68344+/* Constants for the N_FLAGS field */
68345+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
68346+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
68347+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
68348+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
68349+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
68350+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
68351+
68352 #if !defined (N_MAGIC)
68353 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
68354 #endif
68355diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
68356index d876736..b36014e 100644
68357--- a/include/uapi/linux/byteorder/little_endian.h
68358+++ b/include/uapi/linux/byteorder/little_endian.h
68359@@ -42,51 +42,51 @@
68360
68361 static inline __le64 __cpu_to_le64p(const __u64 *p)
68362 {
68363- return (__force __le64)*p;
68364+ return (__force const __le64)*p;
68365 }
68366 static inline __u64 __le64_to_cpup(const __le64 *p)
68367 {
68368- return (__force __u64)*p;
68369+ return (__force const __u64)*p;
68370 }
68371 static inline __le32 __cpu_to_le32p(const __u32 *p)
68372 {
68373- return (__force __le32)*p;
68374+ return (__force const __le32)*p;
68375 }
68376 static inline __u32 __le32_to_cpup(const __le32 *p)
68377 {
68378- return (__force __u32)*p;
68379+ return (__force const __u32)*p;
68380 }
68381 static inline __le16 __cpu_to_le16p(const __u16 *p)
68382 {
68383- return (__force __le16)*p;
68384+ return (__force const __le16)*p;
68385 }
68386 static inline __u16 __le16_to_cpup(const __le16 *p)
68387 {
68388- return (__force __u16)*p;
68389+ return (__force const __u16)*p;
68390 }
68391 static inline __be64 __cpu_to_be64p(const __u64 *p)
68392 {
68393- return (__force __be64)__swab64p(p);
68394+ return (__force const __be64)__swab64p(p);
68395 }
68396 static inline __u64 __be64_to_cpup(const __be64 *p)
68397 {
68398- return __swab64p((__u64 *)p);
68399+ return __swab64p((const __u64 *)p);
68400 }
68401 static inline __be32 __cpu_to_be32p(const __u32 *p)
68402 {
68403- return (__force __be32)__swab32p(p);
68404+ return (__force const __be32)__swab32p(p);
68405 }
68406 static inline __u32 __be32_to_cpup(const __be32 *p)
68407 {
68408- return __swab32p((__u32 *)p);
68409+ return __swab32p((const __u32 *)p);
68410 }
68411 static inline __be16 __cpu_to_be16p(const __u16 *p)
68412 {
68413- return (__force __be16)__swab16p(p);
68414+ return (__force const __be16)__swab16p(p);
68415 }
68416 static inline __u16 __be16_to_cpup(const __be16 *p)
68417 {
68418- return __swab16p((__u16 *)p);
68419+ return __swab16p((const __u16 *)p);
68420 }
68421 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
68422 #define __le64_to_cpus(x) do { (void)(x); } while (0)
68423diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
68424index 126a817..d522bd1 100644
68425--- a/include/uapi/linux/elf.h
68426+++ b/include/uapi/linux/elf.h
68427@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
68428 #define PT_GNU_EH_FRAME 0x6474e550
68429
68430 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
68431+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
68432+
68433+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
68434+
68435+/* Constants for the e_flags field */
68436+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
68437+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
68438+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
68439+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
68440+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
68441+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
68442
68443 /*
68444 * Extended Numbering
68445@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
68446 #define DT_DEBUG 21
68447 #define DT_TEXTREL 22
68448 #define DT_JMPREL 23
68449+#define DT_FLAGS 30
68450+ #define DF_TEXTREL 0x00000004
68451 #define DT_ENCODING 32
68452 #define OLD_DT_LOOS 0x60000000
68453 #define DT_LOOS 0x6000000d
68454@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
68455 #define PF_W 0x2
68456 #define PF_X 0x1
68457
68458+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
68459+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
68460+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
68461+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
68462+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
68463+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
68464+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
68465+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
68466+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
68467+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
68468+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
68469+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
68470+
68471 typedef struct elf32_phdr{
68472 Elf32_Word p_type;
68473 Elf32_Off p_offset;
68474@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
68475 #define EI_OSABI 7
68476 #define EI_PAD 8
68477
68478+#define EI_PAX 14
68479+
68480 #define ELFMAG0 0x7f /* EI_MAG */
68481 #define ELFMAG1 'E'
68482 #define ELFMAG2 'L'
68483diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
68484index aa169c4..6a2771d 100644
68485--- a/include/uapi/linux/personality.h
68486+++ b/include/uapi/linux/personality.h
68487@@ -30,6 +30,7 @@ enum {
68488 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
68489 ADDR_NO_RANDOMIZE | \
68490 ADDR_COMPAT_LAYOUT | \
68491+ ADDR_LIMIT_3GB | \
68492 MMAP_PAGE_ZERO)
68493
68494 /*
68495diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
68496index 7530e74..e714828 100644
68497--- a/include/uapi/linux/screen_info.h
68498+++ b/include/uapi/linux/screen_info.h
68499@@ -43,7 +43,8 @@ struct screen_info {
68500 __u16 pages; /* 0x32 */
68501 __u16 vesa_attributes; /* 0x34 */
68502 __u32 capabilities; /* 0x36 */
68503- __u8 _reserved[6]; /* 0x3a */
68504+ __u16 vesapm_size; /* 0x3a */
68505+ __u8 _reserved[4]; /* 0x3c */
68506 } __attribute__((packed));
68507
68508 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
68509diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
68510index 6d67213..8dab561 100644
68511--- a/include/uapi/linux/sysctl.h
68512+++ b/include/uapi/linux/sysctl.h
68513@@ -155,7 +155,11 @@ enum
68514 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
68515 };
68516
68517-
68518+#ifdef CONFIG_PAX_SOFTMODE
68519+enum {
68520+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
68521+};
68522+#endif
68523
68524 /* CTL_VM names: */
68525 enum
68526diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
68527index 26607bd..588b65f 100644
68528--- a/include/uapi/linux/xattr.h
68529+++ b/include/uapi/linux/xattr.h
68530@@ -60,5 +60,9 @@
68531 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
68532 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
68533
68534+/* User namespace */
68535+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
68536+#define XATTR_PAX_FLAGS_SUFFIX "flags"
68537+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
68538
68539 #endif /* _UAPI_LINUX_XATTR_H */
68540diff --git a/include/video/udlfb.h b/include/video/udlfb.h
68541index f9466fa..f4e2b81 100644
68542--- a/include/video/udlfb.h
68543+++ b/include/video/udlfb.h
68544@@ -53,10 +53,10 @@ struct dlfb_data {
68545 u32 pseudo_palette[256];
68546 int blank_mode; /*one of FB_BLANK_ */
68547 /* blit-only rendering path metrics, exposed through sysfs */
68548- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
68549- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
68550- atomic_t bytes_sent; /* to usb, after compression including overhead */
68551- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
68552+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
68553+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
68554+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
68555+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
68556 };
68557
68558 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
68559diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
68560index 0993a22..32ba2fe 100644
68561--- a/include/video/uvesafb.h
68562+++ b/include/video/uvesafb.h
68563@@ -177,6 +177,7 @@ struct uvesafb_par {
68564 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
68565 u8 pmi_setpal; /* PMI for palette changes */
68566 u16 *pmi_base; /* protected mode interface location */
68567+ u8 *pmi_code; /* protected mode code location */
68568 void *pmi_start;
68569 void *pmi_pal;
68570 u8 *vbe_state_orig; /*
68571diff --git a/init/Kconfig b/init/Kconfig
68572index be8b7f5..b13cb62 100644
68573--- a/init/Kconfig
68574+++ b/init/Kconfig
68575@@ -990,6 +990,7 @@ endif # CGROUPS
68576
68577 config CHECKPOINT_RESTORE
68578 bool "Checkpoint/restore support" if EXPERT
68579+ depends on !GRKERNSEC
68580 default n
68581 help
68582 Enables additional kernel features in a sake of checkpoint/restore.
68583@@ -1079,6 +1080,8 @@ config UIDGID_CONVERTED
68584 depends on OCFS2_FS = n
68585 depends on XFS_FS = n
68586
68587+ depends on GRKERNSEC = n
68588+
68589 config UIDGID_STRICT_TYPE_CHECKS
68590 bool "Require conversions between uid/gids and their internal representation"
68591 depends on UIDGID_CONVERTED
68592@@ -1468,7 +1471,7 @@ config SLUB_DEBUG
68593
68594 config COMPAT_BRK
68595 bool "Disable heap randomization"
68596- default y
68597+ default n
68598 help
68599 Randomizing heap placement makes heap exploits harder, but it
68600 also breaks ancient binaries (including anything libc5 based).
68601@@ -1711,7 +1714,7 @@ config INIT_ALL_POSSIBLE
68602 config STOP_MACHINE
68603 bool
68604 default y
68605- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
68606+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
68607 help
68608 Need stop_machine() primitive.
68609
68610diff --git a/init/Makefile b/init/Makefile
68611index 7bc47ee..6da2dc7 100644
68612--- a/init/Makefile
68613+++ b/init/Makefile
68614@@ -2,6 +2,9 @@
68615 # Makefile for the linux kernel.
68616 #
68617
68618+ccflags-y := $(GCC_PLUGINS_CFLAGS)
68619+asflags-y := $(GCC_PLUGINS_AFLAGS)
68620+
68621 obj-y := main.o version.o mounts.o
68622 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
68623 obj-y += noinitramfs.o
68624diff --git a/init/do_mounts.c b/init/do_mounts.c
68625index 1d1b634..a1c810f 100644
68626--- a/init/do_mounts.c
68627+++ b/init/do_mounts.c
68628@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
68629 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
68630 {
68631 struct super_block *s;
68632- int err = sys_mount(name, "/root", fs, flags, data);
68633+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
68634 if (err)
68635 return err;
68636
68637- sys_chdir("/root");
68638+ sys_chdir((const char __force_user *)"/root");
68639 s = current->fs->pwd.dentry->d_sb;
68640 ROOT_DEV = s->s_dev;
68641 printk(KERN_INFO
68642@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
68643 va_start(args, fmt);
68644 vsprintf(buf, fmt, args);
68645 va_end(args);
68646- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
68647+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
68648 if (fd >= 0) {
68649 sys_ioctl(fd, FDEJECT, 0);
68650 sys_close(fd);
68651 }
68652 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
68653- fd = sys_open("/dev/console", O_RDWR, 0);
68654+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
68655 if (fd >= 0) {
68656 sys_ioctl(fd, TCGETS, (long)&termios);
68657 termios.c_lflag &= ~ICANON;
68658 sys_ioctl(fd, TCSETSF, (long)&termios);
68659- sys_read(fd, &c, 1);
68660+ sys_read(fd, (char __user *)&c, 1);
68661 termios.c_lflag |= ICANON;
68662 sys_ioctl(fd, TCSETSF, (long)&termios);
68663 sys_close(fd);
68664@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
68665 mount_root();
68666 out:
68667 devtmpfs_mount("dev");
68668- sys_mount(".", "/", NULL, MS_MOVE, NULL);
68669- sys_chroot(".");
68670+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
68671+ sys_chroot((const char __force_user *)".");
68672 }
68673diff --git a/init/do_mounts.h b/init/do_mounts.h
68674index f5b978a..69dbfe8 100644
68675--- a/init/do_mounts.h
68676+++ b/init/do_mounts.h
68677@@ -15,15 +15,15 @@ extern int root_mountflags;
68678
68679 static inline int create_dev(char *name, dev_t dev)
68680 {
68681- sys_unlink(name);
68682- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
68683+ sys_unlink((char __force_user *)name);
68684+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
68685 }
68686
68687 #if BITS_PER_LONG == 32
68688 static inline u32 bstat(char *name)
68689 {
68690 struct stat64 stat;
68691- if (sys_stat64(name, &stat) != 0)
68692+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
68693 return 0;
68694 if (!S_ISBLK(stat.st_mode))
68695 return 0;
68696@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
68697 static inline u32 bstat(char *name)
68698 {
68699 struct stat stat;
68700- if (sys_newstat(name, &stat) != 0)
68701+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
68702 return 0;
68703 if (!S_ISBLK(stat.st_mode))
68704 return 0;
68705diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
68706index f9acf71..1e19144 100644
68707--- a/init/do_mounts_initrd.c
68708+++ b/init/do_mounts_initrd.c
68709@@ -58,8 +58,8 @@ static void __init handle_initrd(void)
68710 create_dev("/dev/root.old", Root_RAM0);
68711 /* mount initrd on rootfs' /root */
68712 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
68713- sys_mkdir("/old", 0700);
68714- sys_chdir("/old");
68715+ sys_mkdir((const char __force_user *)"/old", 0700);
68716+ sys_chdir((const char __force_user *)"/old");
68717
68718 /*
68719 * In case that a resume from disk is carried out by linuxrc or one of
68720@@ -73,31 +73,31 @@ static void __init handle_initrd(void)
68721 current->flags &= ~PF_FREEZER_SKIP;
68722
68723 /* move initrd to rootfs' /old */
68724- sys_mount("..", ".", NULL, MS_MOVE, NULL);
68725+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
68726 /* switch root and cwd back to / of rootfs */
68727- sys_chroot("..");
68728+ sys_chroot((const char __force_user *)"..");
68729
68730 if (new_decode_dev(real_root_dev) == Root_RAM0) {
68731- sys_chdir("/old");
68732+ sys_chdir((const char __force_user *)"/old");
68733 return;
68734 }
68735
68736- sys_chdir("/");
68737+ sys_chdir((const char __force_user *)"/");
68738 ROOT_DEV = new_decode_dev(real_root_dev);
68739 mount_root();
68740
68741 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
68742- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
68743+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
68744 if (!error)
68745 printk("okay\n");
68746 else {
68747- int fd = sys_open("/dev/root.old", O_RDWR, 0);
68748+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
68749 if (error == -ENOENT)
68750 printk("/initrd does not exist. Ignored.\n");
68751 else
68752 printk("failed\n");
68753 printk(KERN_NOTICE "Unmounting old root\n");
68754- sys_umount("/old", MNT_DETACH);
68755+ sys_umount((char __force_user *)"/old", MNT_DETACH);
68756 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
68757 if (fd < 0) {
68758 error = fd;
68759@@ -120,11 +120,11 @@ int __init initrd_load(void)
68760 * mounted in the normal path.
68761 */
68762 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
68763- sys_unlink("/initrd.image");
68764+ sys_unlink((const char __force_user *)"/initrd.image");
68765 handle_initrd();
68766 return 1;
68767 }
68768 }
68769- sys_unlink("/initrd.image");
68770+ sys_unlink((const char __force_user *)"/initrd.image");
68771 return 0;
68772 }
68773diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
68774index 8cb6db5..d729f50 100644
68775--- a/init/do_mounts_md.c
68776+++ b/init/do_mounts_md.c
68777@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
68778 partitioned ? "_d" : "", minor,
68779 md_setup_args[ent].device_names);
68780
68781- fd = sys_open(name, 0, 0);
68782+ fd = sys_open((char __force_user *)name, 0, 0);
68783 if (fd < 0) {
68784 printk(KERN_ERR "md: open failed - cannot start "
68785 "array %s\n", name);
68786@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
68787 * array without it
68788 */
68789 sys_close(fd);
68790- fd = sys_open(name, 0, 0);
68791+ fd = sys_open((char __force_user *)name, 0, 0);
68792 sys_ioctl(fd, BLKRRPART, 0);
68793 }
68794 sys_close(fd);
68795@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
68796
68797 wait_for_device_probe();
68798
68799- fd = sys_open("/dev/md0", 0, 0);
68800+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
68801 if (fd >= 0) {
68802 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
68803 sys_close(fd);
68804diff --git a/init/init_task.c b/init/init_task.c
68805index 8b2f399..f0797c9 100644
68806--- a/init/init_task.c
68807+++ b/init/init_task.c
68808@@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
68809 * Initial thread structure. Alignment of this is handled by a special
68810 * linker map entry.
68811 */
68812+#ifdef CONFIG_X86
68813+union thread_union init_thread_union __init_task_data;
68814+#else
68815 union thread_union init_thread_union __init_task_data =
68816 { INIT_THREAD_INFO(init_task) };
68817+#endif
68818diff --git a/init/initramfs.c b/init/initramfs.c
68819index 84c6bf1..8899338 100644
68820--- a/init/initramfs.c
68821+++ b/init/initramfs.c
68822@@ -84,7 +84,7 @@ static void __init free_hash(void)
68823 }
68824 }
68825
68826-static long __init do_utime(char *filename, time_t mtime)
68827+static long __init do_utime(char __force_user *filename, time_t mtime)
68828 {
68829 struct timespec t[2];
68830
68831@@ -119,7 +119,7 @@ static void __init dir_utime(void)
68832 struct dir_entry *de, *tmp;
68833 list_for_each_entry_safe(de, tmp, &dir_list, list) {
68834 list_del(&de->list);
68835- do_utime(de->name, de->mtime);
68836+ do_utime((char __force_user *)de->name, de->mtime);
68837 kfree(de->name);
68838 kfree(de);
68839 }
68840@@ -281,7 +281,7 @@ static int __init maybe_link(void)
68841 if (nlink >= 2) {
68842 char *old = find_link(major, minor, ino, mode, collected);
68843 if (old)
68844- return (sys_link(old, collected) < 0) ? -1 : 1;
68845+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
68846 }
68847 return 0;
68848 }
68849@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
68850 {
68851 struct stat st;
68852
68853- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
68854+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
68855 if (S_ISDIR(st.st_mode))
68856- sys_rmdir(path);
68857+ sys_rmdir((char __force_user *)path);
68858 else
68859- sys_unlink(path);
68860+ sys_unlink((char __force_user *)path);
68861 }
68862 }
68863
68864@@ -315,7 +315,7 @@ static int __init do_name(void)
68865 int openflags = O_WRONLY|O_CREAT;
68866 if (ml != 1)
68867 openflags |= O_TRUNC;
68868- wfd = sys_open(collected, openflags, mode);
68869+ wfd = sys_open((char __force_user *)collected, openflags, mode);
68870
68871 if (wfd >= 0) {
68872 sys_fchown(wfd, uid, gid);
68873@@ -327,17 +327,17 @@ static int __init do_name(void)
68874 }
68875 }
68876 } else if (S_ISDIR(mode)) {
68877- sys_mkdir(collected, mode);
68878- sys_chown(collected, uid, gid);
68879- sys_chmod(collected, mode);
68880+ sys_mkdir((char __force_user *)collected, mode);
68881+ sys_chown((char __force_user *)collected, uid, gid);
68882+ sys_chmod((char __force_user *)collected, mode);
68883 dir_add(collected, mtime);
68884 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
68885 S_ISFIFO(mode) || S_ISSOCK(mode)) {
68886 if (maybe_link() == 0) {
68887- sys_mknod(collected, mode, rdev);
68888- sys_chown(collected, uid, gid);
68889- sys_chmod(collected, mode);
68890- do_utime(collected, mtime);
68891+ sys_mknod((char __force_user *)collected, mode, rdev);
68892+ sys_chown((char __force_user *)collected, uid, gid);
68893+ sys_chmod((char __force_user *)collected, mode);
68894+ do_utime((char __force_user *)collected, mtime);
68895 }
68896 }
68897 return 0;
68898@@ -346,15 +346,15 @@ static int __init do_name(void)
68899 static int __init do_copy(void)
68900 {
68901 if (count >= body_len) {
68902- sys_write(wfd, victim, body_len);
68903+ sys_write(wfd, (char __force_user *)victim, body_len);
68904 sys_close(wfd);
68905- do_utime(vcollected, mtime);
68906+ do_utime((char __force_user *)vcollected, mtime);
68907 kfree(vcollected);
68908 eat(body_len);
68909 state = SkipIt;
68910 return 0;
68911 } else {
68912- sys_write(wfd, victim, count);
68913+ sys_write(wfd, (char __force_user *)victim, count);
68914 body_len -= count;
68915 eat(count);
68916 return 1;
68917@@ -365,9 +365,9 @@ static int __init do_symlink(void)
68918 {
68919 collected[N_ALIGN(name_len) + body_len] = '\0';
68920 clean_path(collected, 0);
68921- sys_symlink(collected + N_ALIGN(name_len), collected);
68922- sys_lchown(collected, uid, gid);
68923- do_utime(collected, mtime);
68924+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
68925+ sys_lchown((char __force_user *)collected, uid, gid);
68926+ do_utime((char __force_user *)collected, mtime);
68927 state = SkipIt;
68928 next_state = Reset;
68929 return 0;
68930diff --git a/init/main.c b/init/main.c
68931index cee4b5c..47f445e 100644
68932--- a/init/main.c
68933+++ b/init/main.c
68934@@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
68935 extern void tc_init(void);
68936 #endif
68937
68938+extern void grsecurity_init(void);
68939+
68940 /*
68941 * Debug helper: via this flag we know that we are in 'early bootup code'
68942 * where only the boot processor is running with IRQ disabled. This means
68943@@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
68944
68945 __setup("reset_devices", set_reset_devices);
68946
68947+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
68948+int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
68949+static int __init setup_grsec_proc_gid(char *str)
68950+{
68951+ grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
68952+ return 1;
68953+}
68954+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
68955+#endif
68956+
68957+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
68958+extern char pax_enter_kernel_user[];
68959+extern char pax_exit_kernel_user[];
68960+extern pgdval_t clone_pgd_mask;
68961+#endif
68962+
68963+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
68964+static int __init setup_pax_nouderef(char *str)
68965+{
68966+#ifdef CONFIG_X86_32
68967+ unsigned int cpu;
68968+ struct desc_struct *gdt;
68969+
68970+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
68971+ gdt = get_cpu_gdt_table(cpu);
68972+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
68973+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
68974+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
68975+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
68976+ }
68977+ loadsegment(ds, __KERNEL_DS);
68978+ loadsegment(es, __KERNEL_DS);
68979+ loadsegment(ss, __KERNEL_DS);
68980+#else
68981+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
68982+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
68983+ clone_pgd_mask = ~(pgdval_t)0UL;
68984+#endif
68985+
68986+ return 0;
68987+}
68988+early_param("pax_nouderef", setup_pax_nouderef);
68989+#endif
68990+
68991+#ifdef CONFIG_PAX_SOFTMODE
68992+int pax_softmode;
68993+
68994+static int __init setup_pax_softmode(char *str)
68995+{
68996+ get_option(&str, &pax_softmode);
68997+ return 1;
68998+}
68999+__setup("pax_softmode=", setup_pax_softmode);
69000+#endif
69001+
69002 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
69003 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
69004 static const char *panic_later, *panic_param;
69005@@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
69006 {
69007 int count = preempt_count();
69008 int ret;
69009+ const char *msg1 = "", *msg2 = "";
69010
69011 if (initcall_debug)
69012 ret = do_one_initcall_debug(fn);
69013@@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
69014 sprintf(msgbuf, "error code %d ", ret);
69015
69016 if (preempt_count() != count) {
69017- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
69018+ msg1 = " preemption imbalance";
69019 preempt_count() = count;
69020 }
69021 if (irqs_disabled()) {
69022- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
69023+ msg2 = " disabled interrupts";
69024 local_irq_enable();
69025 }
69026- if (msgbuf[0]) {
69027- printk("initcall %pF returned with %s\n", fn, msgbuf);
69028+ if (msgbuf[0] || *msg1 || *msg2) {
69029+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
69030 }
69031
69032 return ret;
69033@@ -743,6 +801,10 @@ static char *initcall_level_names[] __initdata = {
69034 "late",
69035 };
69036
69037+#ifdef CONFIG_PAX_LATENT_ENTROPY
69038+u64 latent_entropy;
69039+#endif
69040+
69041 static void __init do_initcall_level(int level)
69042 {
69043 extern const struct kernel_param __start___param[], __stop___param[];
69044@@ -755,8 +817,14 @@ static void __init do_initcall_level(int level)
69045 level, level,
69046 &repair_env_string);
69047
69048- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
69049+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
69050 do_one_initcall(*fn);
69051+
69052+#ifdef CONFIG_PAX_LATENT_ENTROPY
69053+ add_device_randomness(&latent_entropy, sizeof(latent_entropy));
69054+#endif
69055+
69056+ }
69057 }
69058
69059 static void __init do_initcalls(void)
69060@@ -790,8 +858,14 @@ static void __init do_pre_smp_initcalls(void)
69061 {
69062 initcall_t *fn;
69063
69064- for (fn = __initcall_start; fn < __initcall0_start; fn++)
69065+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
69066 do_one_initcall(*fn);
69067+
69068+#ifdef CONFIG_PAX_LATENT_ENTROPY
69069+ add_device_randomness(&latent_entropy, sizeof(latent_entropy));
69070+#endif
69071+
69072+ }
69073 }
69074
69075 static int run_init_process(const char *init_filename)
69076@@ -877,7 +951,7 @@ static noinline void __init kernel_init_freeable(void)
69077 do_basic_setup();
69078
69079 /* Open the /dev/console on the rootfs, this should never fail */
69080- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
69081+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
69082 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
69083
69084 (void) sys_dup(0);
69085@@ -890,11 +964,13 @@ static noinline void __init kernel_init_freeable(void)
69086 if (!ramdisk_execute_command)
69087 ramdisk_execute_command = "/init";
69088
69089- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
69090+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
69091 ramdisk_execute_command = NULL;
69092 prepare_namespace();
69093 }
69094
69095+ grsecurity_init();
69096+
69097 /*
69098 * Ok, we have completed the initial bootup, and
69099 * we're essentially up and running. Get rid of the
69100diff --git a/ipc/mqueue.c b/ipc/mqueue.c
69101index 71a3ca1..cc330ee 100644
69102--- a/ipc/mqueue.c
69103+++ b/ipc/mqueue.c
69104@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
69105 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
69106 info->attr.mq_msgsize);
69107
69108+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
69109 spin_lock(&mq_lock);
69110 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
69111 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
69112diff --git a/ipc/msg.c b/ipc/msg.c
69113index 950572f..266c15f 100644
69114--- a/ipc/msg.c
69115+++ b/ipc/msg.c
69116@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
69117 return security_msg_queue_associate(msq, msgflg);
69118 }
69119
69120+static struct ipc_ops msg_ops = {
69121+ .getnew = newque,
69122+ .associate = msg_security,
69123+ .more_checks = NULL
69124+};
69125+
69126 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
69127 {
69128 struct ipc_namespace *ns;
69129- struct ipc_ops msg_ops;
69130 struct ipc_params msg_params;
69131
69132 ns = current->nsproxy->ipc_ns;
69133
69134- msg_ops.getnew = newque;
69135- msg_ops.associate = msg_security;
69136- msg_ops.more_checks = NULL;
69137-
69138 msg_params.key = key;
69139 msg_params.flg = msgflg;
69140
69141diff --git a/ipc/sem.c b/ipc/sem.c
69142index 58d31f1..cce7a55 100644
69143--- a/ipc/sem.c
69144+++ b/ipc/sem.c
69145@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
69146 return 0;
69147 }
69148
69149+static struct ipc_ops sem_ops = {
69150+ .getnew = newary,
69151+ .associate = sem_security,
69152+ .more_checks = sem_more_checks
69153+};
69154+
69155 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
69156 {
69157 struct ipc_namespace *ns;
69158- struct ipc_ops sem_ops;
69159 struct ipc_params sem_params;
69160
69161 ns = current->nsproxy->ipc_ns;
69162@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
69163 if (nsems < 0 || nsems > ns->sc_semmsl)
69164 return -EINVAL;
69165
69166- sem_ops.getnew = newary;
69167- sem_ops.associate = sem_security;
69168- sem_ops.more_checks = sem_more_checks;
69169-
69170 sem_params.key = key;
69171 sem_params.flg = semflg;
69172 sem_params.u.nsems = nsems;
69173diff --git a/ipc/shm.c b/ipc/shm.c
69174index 4fa6d8f..38dfd0c 100644
69175--- a/ipc/shm.c
69176+++ b/ipc/shm.c
69177@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
69178 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
69179 #endif
69180
69181+#ifdef CONFIG_GRKERNSEC
69182+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
69183+ const time_t shm_createtime, const uid_t cuid,
69184+ const int shmid);
69185+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
69186+ const time_t shm_createtime);
69187+#endif
69188+
69189 void shm_init_ns(struct ipc_namespace *ns)
69190 {
69191 ns->shm_ctlmax = SHMMAX;
69192@@ -521,6 +529,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
69193 shp->shm_lprid = 0;
69194 shp->shm_atim = shp->shm_dtim = 0;
69195 shp->shm_ctim = get_seconds();
69196+#ifdef CONFIG_GRKERNSEC
69197+ {
69198+ struct timespec timeval;
69199+ do_posix_clock_monotonic_gettime(&timeval);
69200+
69201+ shp->shm_createtime = timeval.tv_sec;
69202+ }
69203+#endif
69204 shp->shm_segsz = size;
69205 shp->shm_nattch = 0;
69206 shp->shm_file = file;
69207@@ -572,18 +588,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
69208 return 0;
69209 }
69210
69211+static struct ipc_ops shm_ops = {
69212+ .getnew = newseg,
69213+ .associate = shm_security,
69214+ .more_checks = shm_more_checks
69215+};
69216+
69217 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
69218 {
69219 struct ipc_namespace *ns;
69220- struct ipc_ops shm_ops;
69221 struct ipc_params shm_params;
69222
69223 ns = current->nsproxy->ipc_ns;
69224
69225- shm_ops.getnew = newseg;
69226- shm_ops.associate = shm_security;
69227- shm_ops.more_checks = shm_more_checks;
69228-
69229 shm_params.key = key;
69230 shm_params.flg = shmflg;
69231 shm_params.u.size = size;
69232@@ -1004,6 +1021,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
69233 f_mode = FMODE_READ | FMODE_WRITE;
69234 }
69235 if (shmflg & SHM_EXEC) {
69236+
69237+#ifdef CONFIG_PAX_MPROTECT
69238+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
69239+ goto out;
69240+#endif
69241+
69242 prot |= PROT_EXEC;
69243 acc_mode |= S_IXUGO;
69244 }
69245@@ -1027,9 +1050,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
69246 if (err)
69247 goto out_unlock;
69248
69249+#ifdef CONFIG_GRKERNSEC
69250+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
69251+ shp->shm_perm.cuid, shmid) ||
69252+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
69253+ err = -EACCES;
69254+ goto out_unlock;
69255+ }
69256+#endif
69257+
69258 path = shp->shm_file->f_path;
69259 path_get(&path);
69260 shp->shm_nattch++;
69261+#ifdef CONFIG_GRKERNSEC
69262+ shp->shm_lapid = current->pid;
69263+#endif
69264 size = i_size_read(path.dentry->d_inode);
69265 shm_unlock(shp);
69266
69267diff --git a/kernel/acct.c b/kernel/acct.c
69268index 051e071..15e0920 100644
69269--- a/kernel/acct.c
69270+++ b/kernel/acct.c
69271@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
69272 */
69273 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
69274 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
69275- file->f_op->write(file, (char *)&ac,
69276+ file->f_op->write(file, (char __force_user *)&ac,
69277 sizeof(acct_t), &file->f_pos);
69278 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
69279 set_fs(fs);
69280diff --git a/kernel/audit.c b/kernel/audit.c
69281index d596e53..dbef3c3 100644
69282--- a/kernel/audit.c
69283+++ b/kernel/audit.c
69284@@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
69285 3) suppressed due to audit_rate_limit
69286 4) suppressed due to audit_backlog_limit
69287 */
69288-static atomic_t audit_lost = ATOMIC_INIT(0);
69289+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
69290
69291 /* The netlink socket. */
69292 static struct sock *audit_sock;
69293@@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
69294 unsigned long now;
69295 int print;
69296
69297- atomic_inc(&audit_lost);
69298+ atomic_inc_unchecked(&audit_lost);
69299
69300 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
69301
69302@@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
69303 printk(KERN_WARNING
69304 "audit: audit_lost=%d audit_rate_limit=%d "
69305 "audit_backlog_limit=%d\n",
69306- atomic_read(&audit_lost),
69307+ atomic_read_unchecked(&audit_lost),
69308 audit_rate_limit,
69309 audit_backlog_limit);
69310 audit_panic(message);
69311@@ -681,7 +681,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
69312 status_set.pid = audit_pid;
69313 status_set.rate_limit = audit_rate_limit;
69314 status_set.backlog_limit = audit_backlog_limit;
69315- status_set.lost = atomic_read(&audit_lost);
69316+ status_set.lost = atomic_read_unchecked(&audit_lost);
69317 status_set.backlog = skb_queue_len(&audit_skb_queue);
69318 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
69319 &status_set, sizeof(status_set));
69320diff --git a/kernel/auditsc.c b/kernel/auditsc.c
69321index a371f85..da826c1 100644
69322--- a/kernel/auditsc.c
69323+++ b/kernel/auditsc.c
69324@@ -2292,7 +2292,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
69325 }
69326
69327 /* global counter which is incremented every time something logs in */
69328-static atomic_t session_id = ATOMIC_INIT(0);
69329+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
69330
69331 /**
69332 * audit_set_loginuid - set current task's audit_context loginuid
69333@@ -2316,7 +2316,7 @@ int audit_set_loginuid(kuid_t loginuid)
69334 return -EPERM;
69335 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
69336
69337- sessionid = atomic_inc_return(&session_id);
69338+ sessionid = atomic_inc_return_unchecked(&session_id);
69339 if (context && context->in_syscall) {
69340 struct audit_buffer *ab;
69341
69342diff --git a/kernel/capability.c b/kernel/capability.c
69343index 493d972..f87dfbd 100644
69344--- a/kernel/capability.c
69345+++ b/kernel/capability.c
69346@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
69347 * before modification is attempted and the application
69348 * fails.
69349 */
69350+ if (tocopy > ARRAY_SIZE(kdata))
69351+ return -EFAULT;
69352+
69353 if (copy_to_user(dataptr, kdata, tocopy
69354 * sizeof(struct __user_cap_data_struct))) {
69355 return -EFAULT;
69356@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
69357 int ret;
69358
69359 rcu_read_lock();
69360- ret = security_capable(__task_cred(t), ns, cap);
69361+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
69362+ gr_task_is_capable(t, __task_cred(t), cap);
69363 rcu_read_unlock();
69364
69365- return (ret == 0);
69366+ return ret;
69367 }
69368
69369 /**
69370@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
69371 int ret;
69372
69373 rcu_read_lock();
69374- ret = security_capable_noaudit(__task_cred(t), ns, cap);
69375+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
69376 rcu_read_unlock();
69377
69378- return (ret == 0);
69379+ return ret;
69380 }
69381
69382 /**
69383@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
69384 BUG();
69385 }
69386
69387- if (security_capable(current_cred(), ns, cap) == 0) {
69388+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
69389 current->flags |= PF_SUPERPRIV;
69390 return true;
69391 }
69392@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
69393 }
69394 EXPORT_SYMBOL(ns_capable);
69395
69396+bool ns_capable_nolog(struct user_namespace *ns, int cap)
69397+{
69398+ if (unlikely(!cap_valid(cap))) {
69399+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
69400+ BUG();
69401+ }
69402+
69403+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
69404+ current->flags |= PF_SUPERPRIV;
69405+ return true;
69406+ }
69407+ return false;
69408+}
69409+EXPORT_SYMBOL(ns_capable_nolog);
69410+
69411 /**
69412 * capable - Determine if the current task has a superior capability in effect
69413 * @cap: The capability to be tested for
69414@@ -408,6 +427,12 @@ bool capable(int cap)
69415 }
69416 EXPORT_SYMBOL(capable);
69417
69418+bool capable_nolog(int cap)
69419+{
69420+ return ns_capable_nolog(&init_user_ns, cap);
69421+}
69422+EXPORT_SYMBOL(capable_nolog);
69423+
69424 /**
69425 * nsown_capable - Check superior capability to one's own user_ns
69426 * @cap: The capability in question
69427@@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
69428
69429 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
69430 }
69431+
69432+bool inode_capable_nolog(const struct inode *inode, int cap)
69433+{
69434+ struct user_namespace *ns = current_user_ns();
69435+
69436+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
69437+}
69438diff --git a/kernel/cgroup.c b/kernel/cgroup.c
69439index 4855892..30d23b4 100644
69440--- a/kernel/cgroup.c
69441+++ b/kernel/cgroup.c
69442@@ -5535,7 +5535,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
69443 struct css_set *cg = link->cg;
69444 struct task_struct *task;
69445 int count = 0;
69446- seq_printf(seq, "css_set %p\n", cg);
69447+ seq_printf(seq, "css_set %pK\n", cg);
69448 list_for_each_entry(task, &cg->tasks, cg_list) {
69449 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
69450 seq_puts(seq, " ...\n");
69451diff --git a/kernel/compat.c b/kernel/compat.c
69452index 36700e9..73d770c 100644
69453--- a/kernel/compat.c
69454+++ b/kernel/compat.c
69455@@ -13,6 +13,7 @@
69456
69457 #include <linux/linkage.h>
69458 #include <linux/compat.h>
69459+#include <linux/module.h>
69460 #include <linux/errno.h>
69461 #include <linux/time.h>
69462 #include <linux/signal.h>
69463@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
69464 mm_segment_t oldfs;
69465 long ret;
69466
69467- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
69468+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
69469 oldfs = get_fs();
69470 set_fs(KERNEL_DS);
69471 ret = hrtimer_nanosleep_restart(restart);
69472@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
69473 oldfs = get_fs();
69474 set_fs(KERNEL_DS);
69475 ret = hrtimer_nanosleep(&tu,
69476- rmtp ? (struct timespec __user *)&rmt : NULL,
69477+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
69478 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
69479 set_fs(oldfs);
69480
69481@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
69482 mm_segment_t old_fs = get_fs();
69483
69484 set_fs(KERNEL_DS);
69485- ret = sys_sigpending((old_sigset_t __user *) &s);
69486+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
69487 set_fs(old_fs);
69488 if (ret == 0)
69489 ret = put_user(s, set);
69490@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
69491 mm_segment_t old_fs = get_fs();
69492
69493 set_fs(KERNEL_DS);
69494- ret = sys_old_getrlimit(resource, &r);
69495+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
69496 set_fs(old_fs);
69497
69498 if (!ret) {
69499@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
69500 mm_segment_t old_fs = get_fs();
69501
69502 set_fs(KERNEL_DS);
69503- ret = sys_getrusage(who, (struct rusage __user *) &r);
69504+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
69505 set_fs(old_fs);
69506
69507 if (ret)
69508@@ -552,8 +553,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
69509 set_fs (KERNEL_DS);
69510 ret = sys_wait4(pid,
69511 (stat_addr ?
69512- (unsigned int __user *) &status : NULL),
69513- options, (struct rusage __user *) &r);
69514+ (unsigned int __force_user *) &status : NULL),
69515+ options, (struct rusage __force_user *) &r);
69516 set_fs (old_fs);
69517
69518 if (ret > 0) {
69519@@ -579,8 +580,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
69520 memset(&info, 0, sizeof(info));
69521
69522 set_fs(KERNEL_DS);
69523- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
69524- uru ? (struct rusage __user *)&ru : NULL);
69525+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
69526+ uru ? (struct rusage __force_user *)&ru : NULL);
69527 set_fs(old_fs);
69528
69529 if ((ret < 0) || (info.si_signo == 0))
69530@@ -714,8 +715,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
69531 oldfs = get_fs();
69532 set_fs(KERNEL_DS);
69533 err = sys_timer_settime(timer_id, flags,
69534- (struct itimerspec __user *) &newts,
69535- (struct itimerspec __user *) &oldts);
69536+ (struct itimerspec __force_user *) &newts,
69537+ (struct itimerspec __force_user *) &oldts);
69538 set_fs(oldfs);
69539 if (!err && old && put_compat_itimerspec(old, &oldts))
69540 return -EFAULT;
69541@@ -732,7 +733,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
69542 oldfs = get_fs();
69543 set_fs(KERNEL_DS);
69544 err = sys_timer_gettime(timer_id,
69545- (struct itimerspec __user *) &ts);
69546+ (struct itimerspec __force_user *) &ts);
69547 set_fs(oldfs);
69548 if (!err && put_compat_itimerspec(setting, &ts))
69549 return -EFAULT;
69550@@ -751,7 +752,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
69551 oldfs = get_fs();
69552 set_fs(KERNEL_DS);
69553 err = sys_clock_settime(which_clock,
69554- (struct timespec __user *) &ts);
69555+ (struct timespec __force_user *) &ts);
69556 set_fs(oldfs);
69557 return err;
69558 }
69559@@ -766,7 +767,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
69560 oldfs = get_fs();
69561 set_fs(KERNEL_DS);
69562 err = sys_clock_gettime(which_clock,
69563- (struct timespec __user *) &ts);
69564+ (struct timespec __force_user *) &ts);
69565 set_fs(oldfs);
69566 if (!err && put_compat_timespec(&ts, tp))
69567 return -EFAULT;
69568@@ -786,7 +787,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
69569
69570 oldfs = get_fs();
69571 set_fs(KERNEL_DS);
69572- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
69573+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
69574 set_fs(oldfs);
69575
69576 err = compat_put_timex(utp, &txc);
69577@@ -806,7 +807,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
69578 oldfs = get_fs();
69579 set_fs(KERNEL_DS);
69580 err = sys_clock_getres(which_clock,
69581- (struct timespec __user *) &ts);
69582+ (struct timespec __force_user *) &ts);
69583 set_fs(oldfs);
69584 if (!err && tp && put_compat_timespec(&ts, tp))
69585 return -EFAULT;
69586@@ -818,9 +819,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
69587 long err;
69588 mm_segment_t oldfs;
69589 struct timespec tu;
69590- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
69591+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
69592
69593- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
69594+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
69595 oldfs = get_fs();
69596 set_fs(KERNEL_DS);
69597 err = clock_nanosleep_restart(restart);
69598@@ -852,8 +853,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
69599 oldfs = get_fs();
69600 set_fs(KERNEL_DS);
69601 err = sys_clock_nanosleep(which_clock, flags,
69602- (struct timespec __user *) &in,
69603- (struct timespec __user *) &out);
69604+ (struct timespec __force_user *) &in,
69605+ (struct timespec __force_user *) &out);
69606 set_fs(oldfs);
69607
69608 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
69609diff --git a/kernel/configs.c b/kernel/configs.c
69610index 42e8fa0..9e7406b 100644
69611--- a/kernel/configs.c
69612+++ b/kernel/configs.c
69613@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
69614 struct proc_dir_entry *entry;
69615
69616 /* create the current config file */
69617+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
69618+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
69619+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
69620+ &ikconfig_file_ops);
69621+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69622+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
69623+ &ikconfig_file_ops);
69624+#endif
69625+#else
69626 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
69627 &ikconfig_file_ops);
69628+#endif
69629+
69630 if (!entry)
69631 return -ENOMEM;
69632
69633diff --git a/kernel/cred.c b/kernel/cred.c
69634index e0573a4..eefe488 100644
69635--- a/kernel/cred.c
69636+++ b/kernel/cred.c
69637@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
69638 validate_creds(cred);
69639 alter_cred_subscribers(cred, -1);
69640 put_cred(cred);
69641+
69642+#ifdef CONFIG_GRKERNSEC_SETXID
69643+ cred = (struct cred *) tsk->delayed_cred;
69644+ if (cred != NULL) {
69645+ tsk->delayed_cred = NULL;
69646+ validate_creds(cred);
69647+ alter_cred_subscribers(cred, -1);
69648+ put_cred(cred);
69649+ }
69650+#endif
69651 }
69652
69653 /**
69654@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
69655 * Always returns 0 thus allowing this function to be tail-called at the end
69656 * of, say, sys_setgid().
69657 */
69658-int commit_creds(struct cred *new)
69659+static int __commit_creds(struct cred *new)
69660 {
69661 struct task_struct *task = current;
69662 const struct cred *old = task->real_cred;
69663@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
69664
69665 get_cred(new); /* we will require a ref for the subj creds too */
69666
69667+ gr_set_role_label(task, new->uid, new->gid);
69668+
69669 /* dumpability changes */
69670 if (!uid_eq(old->euid, new->euid) ||
69671 !gid_eq(old->egid, new->egid) ||
69672@@ -479,6 +491,101 @@ int commit_creds(struct cred *new)
69673 put_cred(old);
69674 return 0;
69675 }
69676+#ifdef CONFIG_GRKERNSEC_SETXID
69677+extern int set_user(struct cred *new);
69678+
69679+void gr_delayed_cred_worker(void)
69680+{
69681+ const struct cred *new = current->delayed_cred;
69682+ struct cred *ncred;
69683+
69684+ current->delayed_cred = NULL;
69685+
69686+ if (current_uid() && new != NULL) {
69687+ // from doing get_cred on it when queueing this
69688+ put_cred(new);
69689+ return;
69690+ } else if (new == NULL)
69691+ return;
69692+
69693+ ncred = prepare_creds();
69694+ if (!ncred)
69695+ goto die;
69696+ // uids
69697+ ncred->uid = new->uid;
69698+ ncred->euid = new->euid;
69699+ ncred->suid = new->suid;
69700+ ncred->fsuid = new->fsuid;
69701+ // gids
69702+ ncred->gid = new->gid;
69703+ ncred->egid = new->egid;
69704+ ncred->sgid = new->sgid;
69705+ ncred->fsgid = new->fsgid;
69706+ // groups
69707+ if (set_groups(ncred, new->group_info) < 0) {
69708+ abort_creds(ncred);
69709+ goto die;
69710+ }
69711+ // caps
69712+ ncred->securebits = new->securebits;
69713+ ncred->cap_inheritable = new->cap_inheritable;
69714+ ncred->cap_permitted = new->cap_permitted;
69715+ ncred->cap_effective = new->cap_effective;
69716+ ncred->cap_bset = new->cap_bset;
69717+
69718+ if (set_user(ncred)) {
69719+ abort_creds(ncred);
69720+ goto die;
69721+ }
69722+
69723+ // from doing get_cred on it when queueing this
69724+ put_cred(new);
69725+
69726+ __commit_creds(ncred);
69727+ return;
69728+die:
69729+ // from doing get_cred on it when queueing this
69730+ put_cred(new);
69731+ do_group_exit(SIGKILL);
69732+}
69733+#endif
69734+
69735+int commit_creds(struct cred *new)
69736+{
69737+#ifdef CONFIG_GRKERNSEC_SETXID
69738+ int ret;
69739+ int schedule_it = 0;
69740+ struct task_struct *t;
69741+
69742+ /* we won't get called with tasklist_lock held for writing
69743+ and interrupts disabled as the cred struct in that case is
69744+ init_cred
69745+ */
69746+ if (grsec_enable_setxid && !current_is_single_threaded() &&
69747+ !current_uid() && new->uid) {
69748+ schedule_it = 1;
69749+ }
69750+ ret = __commit_creds(new);
69751+ if (schedule_it) {
69752+ rcu_read_lock();
69753+ read_lock(&tasklist_lock);
69754+ for (t = next_thread(current); t != current;
69755+ t = next_thread(t)) {
69756+ if (t->delayed_cred == NULL) {
69757+ t->delayed_cred = get_cred(new);
69758+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
69759+ set_tsk_need_resched(t);
69760+ }
69761+ }
69762+ read_unlock(&tasklist_lock);
69763+ rcu_read_unlock();
69764+ }
69765+ return ret;
69766+#else
69767+ return __commit_creds(new);
69768+#endif
69769+}
69770+
69771 EXPORT_SYMBOL(commit_creds);
69772
69773 /**
69774diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
69775index 9a61738..c5c8f3a 100644
69776--- a/kernel/debug/debug_core.c
69777+++ b/kernel/debug/debug_core.c
69778@@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
69779 */
69780 static atomic_t masters_in_kgdb;
69781 static atomic_t slaves_in_kgdb;
69782-static atomic_t kgdb_break_tasklet_var;
69783+static atomic_unchecked_t kgdb_break_tasklet_var;
69784 atomic_t kgdb_setting_breakpoint;
69785
69786 struct task_struct *kgdb_usethread;
69787@@ -132,7 +132,7 @@ int kgdb_single_step;
69788 static pid_t kgdb_sstep_pid;
69789
69790 /* to keep track of the CPU which is doing the single stepping*/
69791-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
69792+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
69793
69794 /*
69795 * If you are debugging a problem where roundup (the collection of
69796@@ -540,7 +540,7 @@ return_normal:
69797 * kernel will only try for the value of sstep_tries before
69798 * giving up and continuing on.
69799 */
69800- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
69801+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
69802 (kgdb_info[cpu].task &&
69803 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
69804 atomic_set(&kgdb_active, -1);
69805@@ -634,8 +634,8 @@ cpu_master_loop:
69806 }
69807
69808 kgdb_restore:
69809- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
69810- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
69811+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
69812+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
69813 if (kgdb_info[sstep_cpu].task)
69814 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
69815 else
69816@@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
69817 static void kgdb_tasklet_bpt(unsigned long ing)
69818 {
69819 kgdb_breakpoint();
69820- atomic_set(&kgdb_break_tasklet_var, 0);
69821+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
69822 }
69823
69824 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
69825
69826 void kgdb_schedule_breakpoint(void)
69827 {
69828- if (atomic_read(&kgdb_break_tasklet_var) ||
69829+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
69830 atomic_read(&kgdb_active) != -1 ||
69831 atomic_read(&kgdb_setting_breakpoint))
69832 return;
69833- atomic_inc(&kgdb_break_tasklet_var);
69834+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
69835 tasklet_schedule(&kgdb_tasklet_breakpoint);
69836 }
69837 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
69838diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
69839index 8875254..7cf4928 100644
69840--- a/kernel/debug/kdb/kdb_main.c
69841+++ b/kernel/debug/kdb/kdb_main.c
69842@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
69843 continue;
69844
69845 kdb_printf("%-20s%8u 0x%p ", mod->name,
69846- mod->core_size, (void *)mod);
69847+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
69848 #ifdef CONFIG_MODULE_UNLOAD
69849 kdb_printf("%4ld ", module_refcount(mod));
69850 #endif
69851@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
69852 kdb_printf(" (Loading)");
69853 else
69854 kdb_printf(" (Live)");
69855- kdb_printf(" 0x%p", mod->module_core);
69856+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
69857
69858 #ifdef CONFIG_MODULE_UNLOAD
69859 {
69860diff --git a/kernel/events/core.c b/kernel/events/core.c
69861index 7b6646a..3cb1135 100644
69862--- a/kernel/events/core.c
69863+++ b/kernel/events/core.c
69864@@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
69865 return 0;
69866 }
69867
69868-static atomic64_t perf_event_id;
69869+static atomic64_unchecked_t perf_event_id;
69870
69871 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
69872 enum event_type_t event_type);
69873@@ -2677,7 +2677,7 @@ static void __perf_event_read(void *info)
69874
69875 static inline u64 perf_event_count(struct perf_event *event)
69876 {
69877- return local64_read(&event->count) + atomic64_read(&event->child_count);
69878+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
69879 }
69880
69881 static u64 perf_event_read(struct perf_event *event)
69882@@ -3007,9 +3007,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
69883 mutex_lock(&event->child_mutex);
69884 total += perf_event_read(event);
69885 *enabled += event->total_time_enabled +
69886- atomic64_read(&event->child_total_time_enabled);
69887+ atomic64_read_unchecked(&event->child_total_time_enabled);
69888 *running += event->total_time_running +
69889- atomic64_read(&event->child_total_time_running);
69890+ atomic64_read_unchecked(&event->child_total_time_running);
69891
69892 list_for_each_entry(child, &event->child_list, child_list) {
69893 total += perf_event_read(child);
69894@@ -3412,10 +3412,10 @@ void perf_event_update_userpage(struct perf_event *event)
69895 userpg->offset -= local64_read(&event->hw.prev_count);
69896
69897 userpg->time_enabled = enabled +
69898- atomic64_read(&event->child_total_time_enabled);
69899+ atomic64_read_unchecked(&event->child_total_time_enabled);
69900
69901 userpg->time_running = running +
69902- atomic64_read(&event->child_total_time_running);
69903+ atomic64_read_unchecked(&event->child_total_time_running);
69904
69905 arch_perf_update_userpage(userpg, now);
69906
69907@@ -3974,11 +3974,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
69908 values[n++] = perf_event_count(event);
69909 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
69910 values[n++] = enabled +
69911- atomic64_read(&event->child_total_time_enabled);
69912+ atomic64_read_unchecked(&event->child_total_time_enabled);
69913 }
69914 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
69915 values[n++] = running +
69916- atomic64_read(&event->child_total_time_running);
69917+ atomic64_read_unchecked(&event->child_total_time_running);
69918 }
69919 if (read_format & PERF_FORMAT_ID)
69920 values[n++] = primary_event_id(event);
69921@@ -4721,12 +4721,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
69922 * need to add enough zero bytes after the string to handle
69923 * the 64bit alignment we do later.
69924 */
69925- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
69926+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
69927 if (!buf) {
69928 name = strncpy(tmp, "//enomem", sizeof(tmp));
69929 goto got_name;
69930 }
69931- name = d_path(&file->f_path, buf, PATH_MAX);
69932+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
69933 if (IS_ERR(name)) {
69934 name = strncpy(tmp, "//toolong", sizeof(tmp));
69935 goto got_name;
69936@@ -6165,7 +6165,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
69937 event->parent = parent_event;
69938
69939 event->ns = get_pid_ns(task_active_pid_ns(current));
69940- event->id = atomic64_inc_return(&perf_event_id);
69941+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
69942
69943 event->state = PERF_EVENT_STATE_INACTIVE;
69944
69945@@ -6790,10 +6790,10 @@ static void sync_child_event(struct perf_event *child_event,
69946 /*
69947 * Add back the child's count to the parent's count:
69948 */
69949- atomic64_add(child_val, &parent_event->child_count);
69950- atomic64_add(child_event->total_time_enabled,
69951+ atomic64_add_unchecked(child_val, &parent_event->child_count);
69952+ atomic64_add_unchecked(child_event->total_time_enabled,
69953 &parent_event->child_total_time_enabled);
69954- atomic64_add(child_event->total_time_running,
69955+ atomic64_add_unchecked(child_event->total_time_running,
69956 &parent_event->child_total_time_running);
69957
69958 /*
69959diff --git a/kernel/exit.c b/kernel/exit.c
69960index b4df219..f13c02d 100644
69961--- a/kernel/exit.c
69962+++ b/kernel/exit.c
69963@@ -170,6 +170,10 @@ void release_task(struct task_struct * p)
69964 struct task_struct *leader;
69965 int zap_leader;
69966 repeat:
69967+#ifdef CONFIG_NET
69968+ gr_del_task_from_ip_table(p);
69969+#endif
69970+
69971 /* don't need to get the RCU readlock here - the process is dead and
69972 * can't be modifying its own credentials. But shut RCU-lockdep up */
69973 rcu_read_lock();
69974@@ -338,7 +342,7 @@ int allow_signal(int sig)
69975 * know it'll be handled, so that they don't get converted to
69976 * SIGKILL or just silently dropped.
69977 */
69978- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
69979+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
69980 recalc_sigpending();
69981 spin_unlock_irq(&current->sighand->siglock);
69982 return 0;
69983@@ -708,6 +712,8 @@ void do_exit(long code)
69984 struct task_struct *tsk = current;
69985 int group_dead;
69986
69987+ set_fs(USER_DS);
69988+
69989 profile_task_exit(tsk);
69990
69991 WARN_ON(blk_needs_flush_plug(tsk));
69992@@ -724,7 +730,6 @@ void do_exit(long code)
69993 * mm_release()->clear_child_tid() from writing to a user-controlled
69994 * kernel address.
69995 */
69996- set_fs(USER_DS);
69997
69998 ptrace_event(PTRACE_EVENT_EXIT, code);
69999
70000@@ -783,6 +788,9 @@ void do_exit(long code)
70001 tsk->exit_code = code;
70002 taskstats_exit(tsk, group_dead);
70003
70004+ gr_acl_handle_psacct(tsk, code);
70005+ gr_acl_handle_exit();
70006+
70007 exit_mm(tsk);
70008
70009 if (group_dead)
70010@@ -903,7 +911,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
70011 * Take down every thread in the group. This is called by fatal signals
70012 * as well as by sys_exit_group (below).
70013 */
70014-void
70015+__noreturn void
70016 do_group_exit(int exit_code)
70017 {
70018 struct signal_struct *sig = current->signal;
70019diff --git a/kernel/fork.c b/kernel/fork.c
70020index c535f33..1d768f9 100644
70021--- a/kernel/fork.c
70022+++ b/kernel/fork.c
70023@@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
70024 *stackend = STACK_END_MAGIC; /* for overflow detection */
70025
70026 #ifdef CONFIG_CC_STACKPROTECTOR
70027- tsk->stack_canary = get_random_int();
70028+ tsk->stack_canary = pax_get_random_long();
70029 #endif
70030
70031 /*
70032@@ -344,13 +344,81 @@ free_tsk:
70033 }
70034
70035 #ifdef CONFIG_MMU
70036+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
70037+{
70038+ struct vm_area_struct *tmp;
70039+ unsigned long charge;
70040+ struct mempolicy *pol;
70041+ struct file *file;
70042+
70043+ charge = 0;
70044+ if (mpnt->vm_flags & VM_ACCOUNT) {
70045+ unsigned long len = vma_pages(mpnt);
70046+
70047+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
70048+ goto fail_nomem;
70049+ charge = len;
70050+ }
70051+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
70052+ if (!tmp)
70053+ goto fail_nomem;
70054+ *tmp = *mpnt;
70055+ tmp->vm_mm = mm;
70056+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
70057+ pol = mpol_dup(vma_policy(mpnt));
70058+ if (IS_ERR(pol))
70059+ goto fail_nomem_policy;
70060+ vma_set_policy(tmp, pol);
70061+ if (anon_vma_fork(tmp, mpnt))
70062+ goto fail_nomem_anon_vma_fork;
70063+ tmp->vm_flags &= ~VM_LOCKED;
70064+ tmp->vm_next = tmp->vm_prev = NULL;
70065+ tmp->vm_mirror = NULL;
70066+ file = tmp->vm_file;
70067+ if (file) {
70068+ struct inode *inode = file->f_path.dentry->d_inode;
70069+ struct address_space *mapping = file->f_mapping;
70070+
70071+ get_file(file);
70072+ if (tmp->vm_flags & VM_DENYWRITE)
70073+ atomic_dec(&inode->i_writecount);
70074+ mutex_lock(&mapping->i_mmap_mutex);
70075+ if (tmp->vm_flags & VM_SHARED)
70076+ mapping->i_mmap_writable++;
70077+ flush_dcache_mmap_lock(mapping);
70078+ /* insert tmp into the share list, just after mpnt */
70079+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
70080+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
70081+ else
70082+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
70083+ flush_dcache_mmap_unlock(mapping);
70084+ mutex_unlock(&mapping->i_mmap_mutex);
70085+ }
70086+
70087+ /*
70088+ * Clear hugetlb-related page reserves for children. This only
70089+ * affects MAP_PRIVATE mappings. Faults generated by the child
70090+ * are not guaranteed to succeed, even if read-only
70091+ */
70092+ if (is_vm_hugetlb_page(tmp))
70093+ reset_vma_resv_huge_pages(tmp);
70094+
70095+ return tmp;
70096+
70097+fail_nomem_anon_vma_fork:
70098+ mpol_put(pol);
70099+fail_nomem_policy:
70100+ kmem_cache_free(vm_area_cachep, tmp);
70101+fail_nomem:
70102+ vm_unacct_memory(charge);
70103+ return NULL;
70104+}
70105+
70106 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70107 {
70108 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
70109 struct rb_node **rb_link, *rb_parent;
70110 int retval;
70111- unsigned long charge;
70112- struct mempolicy *pol;
70113
70114 uprobe_start_dup_mmap();
70115 down_write(&oldmm->mmap_sem);
70116@@ -364,8 +432,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70117 mm->locked_vm = 0;
70118 mm->mmap = NULL;
70119 mm->mmap_cache = NULL;
70120- mm->free_area_cache = oldmm->mmap_base;
70121- mm->cached_hole_size = ~0UL;
70122+ mm->free_area_cache = oldmm->free_area_cache;
70123+ mm->cached_hole_size = oldmm->cached_hole_size;
70124 mm->map_count = 0;
70125 cpumask_clear(mm_cpumask(mm));
70126 mm->mm_rb = RB_ROOT;
70127@@ -381,57 +449,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70128
70129 prev = NULL;
70130 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
70131- struct file *file;
70132-
70133 if (mpnt->vm_flags & VM_DONTCOPY) {
70134 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
70135 -vma_pages(mpnt));
70136 continue;
70137 }
70138- charge = 0;
70139- if (mpnt->vm_flags & VM_ACCOUNT) {
70140- unsigned long len = vma_pages(mpnt);
70141-
70142- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
70143- goto fail_nomem;
70144- charge = len;
70145- }
70146- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
70147- if (!tmp)
70148- goto fail_nomem;
70149- *tmp = *mpnt;
70150- INIT_LIST_HEAD(&tmp->anon_vma_chain);
70151- pol = mpol_dup(vma_policy(mpnt));
70152- retval = PTR_ERR(pol);
70153- if (IS_ERR(pol))
70154- goto fail_nomem_policy;
70155- vma_set_policy(tmp, pol);
70156- tmp->vm_mm = mm;
70157- if (anon_vma_fork(tmp, mpnt))
70158- goto fail_nomem_anon_vma_fork;
70159- tmp->vm_flags &= ~VM_LOCKED;
70160- tmp->vm_next = tmp->vm_prev = NULL;
70161- file = tmp->vm_file;
70162- if (file) {
70163- struct inode *inode = file->f_path.dentry->d_inode;
70164- struct address_space *mapping = file->f_mapping;
70165-
70166- get_file(file);
70167- if (tmp->vm_flags & VM_DENYWRITE)
70168- atomic_dec(&inode->i_writecount);
70169- mutex_lock(&mapping->i_mmap_mutex);
70170- if (tmp->vm_flags & VM_SHARED)
70171- mapping->i_mmap_writable++;
70172- flush_dcache_mmap_lock(mapping);
70173- /* insert tmp into the share list, just after mpnt */
70174- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
70175- vma_nonlinear_insert(tmp,
70176- &mapping->i_mmap_nonlinear);
70177- else
70178- vma_interval_tree_insert_after(tmp, mpnt,
70179- &mapping->i_mmap);
70180- flush_dcache_mmap_unlock(mapping);
70181- mutex_unlock(&mapping->i_mmap_mutex);
70182+ tmp = dup_vma(mm, oldmm, mpnt);
70183+ if (!tmp) {
70184+ retval = -ENOMEM;
70185+ goto out;
70186 }
70187
70188 /*
70189@@ -463,6 +489,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70190 if (retval)
70191 goto out;
70192 }
70193+
70194+#ifdef CONFIG_PAX_SEGMEXEC
70195+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
70196+ struct vm_area_struct *mpnt_m;
70197+
70198+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
70199+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
70200+
70201+ if (!mpnt->vm_mirror)
70202+ continue;
70203+
70204+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
70205+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
70206+ mpnt->vm_mirror = mpnt_m;
70207+ } else {
70208+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
70209+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
70210+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
70211+ mpnt->vm_mirror->vm_mirror = mpnt;
70212+ }
70213+ }
70214+ BUG_ON(mpnt_m);
70215+ }
70216+#endif
70217+
70218 /* a new mm has just been created */
70219 arch_dup_mmap(oldmm, mm);
70220 retval = 0;
70221@@ -472,14 +523,6 @@ out:
70222 up_write(&oldmm->mmap_sem);
70223 uprobe_end_dup_mmap();
70224 return retval;
70225-fail_nomem_anon_vma_fork:
70226- mpol_put(pol);
70227-fail_nomem_policy:
70228- kmem_cache_free(vm_area_cachep, tmp);
70229-fail_nomem:
70230- retval = -ENOMEM;
70231- vm_unacct_memory(charge);
70232- goto out;
70233 }
70234
70235 static inline int mm_alloc_pgd(struct mm_struct *mm)
70236@@ -694,8 +737,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
70237 return ERR_PTR(err);
70238
70239 mm = get_task_mm(task);
70240- if (mm && mm != current->mm &&
70241- !ptrace_may_access(task, mode)) {
70242+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
70243+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
70244 mmput(mm);
70245 mm = ERR_PTR(-EACCES);
70246 }
70247@@ -917,13 +960,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
70248 spin_unlock(&fs->lock);
70249 return -EAGAIN;
70250 }
70251- fs->users++;
70252+ atomic_inc(&fs->users);
70253 spin_unlock(&fs->lock);
70254 return 0;
70255 }
70256 tsk->fs = copy_fs_struct(fs);
70257 if (!tsk->fs)
70258 return -ENOMEM;
70259+ /* Carry through gr_chroot_dentry and is_chrooted instead
70260+ of recomputing it here. Already copied when the task struct
70261+ is duplicated. This allows pivot_root to not be treated as
70262+ a chroot
70263+ */
70264+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
70265+
70266 return 0;
70267 }
70268
70269@@ -1193,6 +1243,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
70270 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
70271 #endif
70272 retval = -EAGAIN;
70273+
70274+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
70275+
70276 if (atomic_read(&p->real_cred->user->processes) >=
70277 task_rlimit(p, RLIMIT_NPROC)) {
70278 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
70279@@ -1432,6 +1485,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
70280 goto bad_fork_free_pid;
70281 }
70282
70283+ /* synchronizes with gr_set_acls()
70284+ we need to call this past the point of no return for fork()
70285+ */
70286+ gr_copy_label(p);
70287+
70288 if (clone_flags & CLONE_THREAD) {
70289 current->signal->nr_threads++;
70290 atomic_inc(&current->signal->live);
70291@@ -1515,6 +1573,8 @@ bad_fork_cleanup_count:
70292 bad_fork_free:
70293 free_task(p);
70294 fork_out:
70295+ gr_log_forkfail(retval);
70296+
70297 return ERR_PTR(retval);
70298 }
70299
70300@@ -1565,6 +1625,23 @@ long do_fork(unsigned long clone_flags,
70301 return -EINVAL;
70302 }
70303
70304+#ifdef CONFIG_GRKERNSEC
70305+ if (clone_flags & CLONE_NEWUSER) {
70306+ /*
70307+ * This doesn't really inspire confidence:
70308+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
70309+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
70310+ * Increases kernel attack surface in areas developers
70311+ * previously cared little about ("low importance due
70312+ * to requiring "root" capability")
70313+ * To be removed when this code receives *proper* review
70314+ */
70315+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
70316+ !capable(CAP_SETGID))
70317+ return -EPERM;
70318+ }
70319+#endif
70320+
70321 /*
70322 * Determine whether and which event to report to ptracer. When
70323 * called from kernel_thread or CLONE_UNTRACED is explicitly
70324@@ -1599,6 +1676,8 @@ long do_fork(unsigned long clone_flags,
70325 if (clone_flags & CLONE_PARENT_SETTID)
70326 put_user(nr, parent_tidptr);
70327
70328+ gr_handle_brute_check();
70329+
70330 if (clone_flags & CLONE_VFORK) {
70331 p->vfork_done = &vfork;
70332 init_completion(&vfork);
70333@@ -1752,7 +1831,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
70334 return 0;
70335
70336 /* don't need lock here; in the worst case we'll do useless copy */
70337- if (fs->users == 1)
70338+ if (atomic_read(&fs->users) == 1)
70339 return 0;
70340
70341 *new_fsp = copy_fs_struct(fs);
70342@@ -1866,7 +1945,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
70343 fs = current->fs;
70344 spin_lock(&fs->lock);
70345 current->fs = new_fs;
70346- if (--fs->users)
70347+ gr_set_chroot_entries(current, &current->fs->root);
70348+ if (atomic_dec_return(&fs->users))
70349 new_fs = NULL;
70350 else
70351 new_fs = fs;
70352diff --git a/kernel/futex.c b/kernel/futex.c
70353index 19eb089..b8c65ea 100644
70354--- a/kernel/futex.c
70355+++ b/kernel/futex.c
70356@@ -54,6 +54,7 @@
70357 #include <linux/mount.h>
70358 #include <linux/pagemap.h>
70359 #include <linux/syscalls.h>
70360+#include <linux/ptrace.h>
70361 #include <linux/signal.h>
70362 #include <linux/export.h>
70363 #include <linux/magic.h>
70364@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
70365 struct page *page, *page_head;
70366 int err, ro = 0;
70367
70368+#ifdef CONFIG_PAX_SEGMEXEC
70369+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
70370+ return -EFAULT;
70371+#endif
70372+
70373 /*
70374 * The futex address must be "naturally" aligned.
70375 */
70376@@ -2733,6 +2739,7 @@ static int __init futex_init(void)
70377 {
70378 u32 curval;
70379 int i;
70380+ mm_segment_t oldfs;
70381
70382 /*
70383 * This will fail and we want it. Some arch implementations do
70384@@ -2744,8 +2751,11 @@ static int __init futex_init(void)
70385 * implementation, the non-functional ones will return
70386 * -ENOSYS.
70387 */
70388+ oldfs = get_fs();
70389+ set_fs(USER_DS);
70390 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
70391 futex_cmpxchg_enabled = 1;
70392+ set_fs(oldfs);
70393
70394 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
70395 plist_head_init(&futex_queues[i].chain);
70396diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
70397index 9b22d03..6295b62 100644
70398--- a/kernel/gcov/base.c
70399+++ b/kernel/gcov/base.c
70400@@ -102,11 +102,6 @@ void gcov_enable_events(void)
70401 }
70402
70403 #ifdef CONFIG_MODULES
70404-static inline int within(void *addr, void *start, unsigned long size)
70405-{
70406- return ((addr >= start) && (addr < start + size));
70407-}
70408-
70409 /* Update list and generate events when modules are unloaded. */
70410 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
70411 void *data)
70412@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
70413 prev = NULL;
70414 /* Remove entries located in module from linked list. */
70415 for (info = gcov_info_head; info; info = info->next) {
70416- if (within(info, mod->module_core, mod->core_size)) {
70417+ if (within_module_core_rw((unsigned long)info, mod)) {
70418 if (prev)
70419 prev->next = info->next;
70420 else
70421diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
70422index 6db7a5e..0d600bd 100644
70423--- a/kernel/hrtimer.c
70424+++ b/kernel/hrtimer.c
70425@@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
70426 local_irq_restore(flags);
70427 }
70428
70429-static void run_hrtimer_softirq(struct softirq_action *h)
70430+static void run_hrtimer_softirq(void)
70431 {
70432 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
70433
70434@@ -1751,7 +1751,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
70435 return NOTIFY_OK;
70436 }
70437
70438-static struct notifier_block __cpuinitdata hrtimers_nb = {
70439+static struct notifier_block hrtimers_nb = {
70440 .notifier_call = hrtimer_cpu_notify,
70441 };
70442
70443diff --git a/kernel/jump_label.c b/kernel/jump_label.c
70444index 60f48fa..7f3a770 100644
70445--- a/kernel/jump_label.c
70446+++ b/kernel/jump_label.c
70447@@ -13,6 +13,7 @@
70448 #include <linux/sort.h>
70449 #include <linux/err.h>
70450 #include <linux/static_key.h>
70451+#include <linux/mm.h>
70452
70453 #ifdef HAVE_JUMP_LABEL
70454
70455@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
70456
70457 size = (((unsigned long)stop - (unsigned long)start)
70458 / sizeof(struct jump_entry));
70459+ pax_open_kernel();
70460 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
70461+ pax_close_kernel();
70462 }
70463
70464 static void jump_label_update(struct static_key *key, int enable);
70465@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
70466 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
70467 struct jump_entry *iter;
70468
70469+ pax_open_kernel();
70470 for (iter = iter_start; iter < iter_stop; iter++) {
70471 if (within_module_init(iter->code, mod))
70472 iter->code = 0;
70473 }
70474+ pax_close_kernel();
70475 }
70476
70477 static int
70478diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
70479index 2169fee..45c017a 100644
70480--- a/kernel/kallsyms.c
70481+++ b/kernel/kallsyms.c
70482@@ -11,6 +11,9 @@
70483 * Changed the compression method from stem compression to "table lookup"
70484 * compression (see scripts/kallsyms.c for a more complete description)
70485 */
70486+#ifdef CONFIG_GRKERNSEC_HIDESYM
70487+#define __INCLUDED_BY_HIDESYM 1
70488+#endif
70489 #include <linux/kallsyms.h>
70490 #include <linux/module.h>
70491 #include <linux/init.h>
70492@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
70493
70494 static inline int is_kernel_inittext(unsigned long addr)
70495 {
70496+ if (system_state != SYSTEM_BOOTING)
70497+ return 0;
70498+
70499 if (addr >= (unsigned long)_sinittext
70500 && addr <= (unsigned long)_einittext)
70501 return 1;
70502 return 0;
70503 }
70504
70505+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
70506+#ifdef CONFIG_MODULES
70507+static inline int is_module_text(unsigned long addr)
70508+{
70509+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
70510+ return 1;
70511+
70512+ addr = ktla_ktva(addr);
70513+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
70514+}
70515+#else
70516+static inline int is_module_text(unsigned long addr)
70517+{
70518+ return 0;
70519+}
70520+#endif
70521+#endif
70522+
70523 static inline int is_kernel_text(unsigned long addr)
70524 {
70525 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
70526@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
70527
70528 static inline int is_kernel(unsigned long addr)
70529 {
70530+
70531+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
70532+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
70533+ return 1;
70534+
70535+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
70536+#else
70537 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
70538+#endif
70539+
70540 return 1;
70541 return in_gate_area_no_mm(addr);
70542 }
70543
70544 static int is_ksym_addr(unsigned long addr)
70545 {
70546+
70547+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
70548+ if (is_module_text(addr))
70549+ return 0;
70550+#endif
70551+
70552 if (all_var)
70553 return is_kernel(addr);
70554
70555@@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
70556
70557 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
70558 {
70559- iter->name[0] = '\0';
70560 iter->nameoff = get_symbol_offset(new_pos);
70561 iter->pos = new_pos;
70562 }
70563@@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
70564 {
70565 struct kallsym_iter *iter = m->private;
70566
70567+#ifdef CONFIG_GRKERNSEC_HIDESYM
70568+ if (current_uid())
70569+ return 0;
70570+#endif
70571+
70572 /* Some debugging symbols have no name. Ignore them. */
70573 if (!iter->name[0])
70574 return 0;
70575@@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
70576 */
70577 type = iter->exported ? toupper(iter->type) :
70578 tolower(iter->type);
70579+
70580 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
70581 type, iter->name, iter->module_name);
70582 } else
70583@@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
70584 struct kallsym_iter *iter;
70585 int ret;
70586
70587- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
70588+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
70589 if (!iter)
70590 return -ENOMEM;
70591 reset_iter(iter, 0);
70592diff --git a/kernel/kcmp.c b/kernel/kcmp.c
70593index e30ac0f..3528cac 100644
70594--- a/kernel/kcmp.c
70595+++ b/kernel/kcmp.c
70596@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
70597 struct task_struct *task1, *task2;
70598 int ret;
70599
70600+#ifdef CONFIG_GRKERNSEC
70601+ return -ENOSYS;
70602+#endif
70603+
70604 rcu_read_lock();
70605
70606 /*
70607diff --git a/kernel/kexec.c b/kernel/kexec.c
70608index 5e4bd78..00c5b91 100644
70609--- a/kernel/kexec.c
70610+++ b/kernel/kexec.c
70611@@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
70612 unsigned long flags)
70613 {
70614 struct compat_kexec_segment in;
70615- struct kexec_segment out, __user *ksegments;
70616+ struct kexec_segment out;
70617+ struct kexec_segment __user *ksegments;
70618 unsigned long i, result;
70619
70620 /* Don't allow clients that don't understand the native
70621diff --git a/kernel/kmod.c b/kernel/kmod.c
70622index 0023a87..3fe3781 100644
70623--- a/kernel/kmod.c
70624+++ b/kernel/kmod.c
70625@@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
70626 kfree(info->argv);
70627 }
70628
70629-static int call_modprobe(char *module_name, int wait)
70630+static int call_modprobe(char *module_name, char *module_param, int wait)
70631 {
70632 static char *envp[] = {
70633 "HOME=/",
70634@@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
70635 NULL
70636 };
70637
70638- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
70639+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
70640 if (!argv)
70641 goto out;
70642
70643@@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
70644 argv[1] = "-q";
70645 argv[2] = "--";
70646 argv[3] = module_name; /* check free_modprobe_argv() */
70647- argv[4] = NULL;
70648+ argv[4] = module_param;
70649+ argv[5] = NULL;
70650
70651 return call_usermodehelper_fns(modprobe_path, argv, envp,
70652 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
70653@@ -120,9 +121,8 @@ out:
70654 * If module auto-loading support is disabled then this function
70655 * becomes a no-operation.
70656 */
70657-int __request_module(bool wait, const char *fmt, ...)
70658+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
70659 {
70660- va_list args;
70661 char module_name[MODULE_NAME_LEN];
70662 unsigned int max_modprobes;
70663 int ret;
70664@@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
70665 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
70666 static int kmod_loop_msg;
70667
70668- va_start(args, fmt);
70669- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
70670- va_end(args);
70671+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
70672 if (ret >= MODULE_NAME_LEN)
70673 return -ENAMETOOLONG;
70674
70675@@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
70676 if (ret)
70677 return ret;
70678
70679+#ifdef CONFIG_GRKERNSEC_MODHARDEN
70680+ if (!current_uid()) {
70681+ /* hack to workaround consolekit/udisks stupidity */
70682+ read_lock(&tasklist_lock);
70683+ if (!strcmp(current->comm, "mount") &&
70684+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
70685+ read_unlock(&tasklist_lock);
70686+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
70687+ return -EPERM;
70688+ }
70689+ read_unlock(&tasklist_lock);
70690+ }
70691+#endif
70692+
70693 /* If modprobe needs a service that is in a module, we get a recursive
70694 * loop. Limit the number of running kmod threads to max_threads/2 or
70695 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
70696@@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
70697
70698 trace_module_request(module_name, wait, _RET_IP_);
70699
70700- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
70701+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
70702
70703 atomic_dec(&kmod_concurrent);
70704 return ret;
70705 }
70706+
70707+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
70708+{
70709+ va_list args;
70710+ int ret;
70711+
70712+ va_start(args, fmt);
70713+ ret = ____request_module(wait, module_param, fmt, args);
70714+ va_end(args);
70715+
70716+ return ret;
70717+}
70718+
70719+int __request_module(bool wait, const char *fmt, ...)
70720+{
70721+ va_list args;
70722+ int ret;
70723+
70724+#ifdef CONFIG_GRKERNSEC_MODHARDEN
70725+ if (current_uid()) {
70726+ char module_param[MODULE_NAME_LEN];
70727+
70728+ memset(module_param, 0, sizeof(module_param));
70729+
70730+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
70731+
70732+ va_start(args, fmt);
70733+ ret = ____request_module(wait, module_param, fmt, args);
70734+ va_end(args);
70735+
70736+ return ret;
70737+ }
70738+#endif
70739+
70740+ va_start(args, fmt);
70741+ ret = ____request_module(wait, NULL, fmt, args);
70742+ va_end(args);
70743+
70744+ return ret;
70745+}
70746+
70747 EXPORT_SYMBOL(__request_module);
70748 #endif /* CONFIG_MODULES */
70749
70750@@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
70751 *
70752 * Thus the __user pointer cast is valid here.
70753 */
70754- sys_wait4(pid, (int __user *)&ret, 0, NULL);
70755+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
70756
70757 /*
70758 * If ret is 0, either ____call_usermodehelper failed and the
70759diff --git a/kernel/kprobes.c b/kernel/kprobes.c
70760index 098f396..fe85ff1 100644
70761--- a/kernel/kprobes.c
70762+++ b/kernel/kprobes.c
70763@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
70764 * kernel image and loaded module images reside. This is required
70765 * so x86_64 can correctly handle the %rip-relative fixups.
70766 */
70767- kip->insns = module_alloc(PAGE_SIZE);
70768+ kip->insns = module_alloc_exec(PAGE_SIZE);
70769 if (!kip->insns) {
70770 kfree(kip);
70771 return NULL;
70772@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
70773 */
70774 if (!list_is_singular(&kip->list)) {
70775 list_del(&kip->list);
70776- module_free(NULL, kip->insns);
70777+ module_free_exec(NULL, kip->insns);
70778 kfree(kip);
70779 }
70780 return 1;
70781@@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
70782 {
70783 int i, err = 0;
70784 unsigned long offset = 0, size = 0;
70785- char *modname, namebuf[128];
70786+ char *modname, namebuf[KSYM_NAME_LEN];
70787 const char *symbol_name;
70788 void *addr;
70789 struct kprobe_blackpoint *kb;
70790@@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
70791 kprobe_type = "k";
70792
70793 if (sym)
70794- seq_printf(pi, "%p %s %s+0x%x %s ",
70795+ seq_printf(pi, "%pK %s %s+0x%x %s ",
70796 p->addr, kprobe_type, sym, offset,
70797 (modname ? modname : " "));
70798 else
70799- seq_printf(pi, "%p %s %p ",
70800+ seq_printf(pi, "%pK %s %pK ",
70801 p->addr, kprobe_type, p->addr);
70802
70803 if (!pp)
70804@@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
70805 const char *sym = NULL;
70806 unsigned int i = *(loff_t *) v;
70807 unsigned long offset = 0;
70808- char *modname, namebuf[128];
70809+ char *modname, namebuf[KSYM_NAME_LEN];
70810
70811 head = &kprobe_table[i];
70812 preempt_disable();
70813diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
70814index 6ada93c..55baf4d 100644
70815--- a/kernel/ksysfs.c
70816+++ b/kernel/ksysfs.c
70817@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
70818 {
70819 if (count+1 > UEVENT_HELPER_PATH_LEN)
70820 return -ENOENT;
70821+ if (!capable(CAP_SYS_ADMIN))
70822+ return -EPERM;
70823 memcpy(uevent_helper, buf, count);
70824 uevent_helper[count] = '\0';
70825 if (count && uevent_helper[count-1] == '\n')
70826diff --git a/kernel/lockdep.c b/kernel/lockdep.c
70827index 7981e5b..7f2105c 100644
70828--- a/kernel/lockdep.c
70829+++ b/kernel/lockdep.c
70830@@ -590,6 +590,10 @@ static int static_obj(void *obj)
70831 end = (unsigned long) &_end,
70832 addr = (unsigned long) obj;
70833
70834+#ifdef CONFIG_PAX_KERNEXEC
70835+ start = ktla_ktva(start);
70836+#endif
70837+
70838 /*
70839 * static variable?
70840 */
70841@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
70842 if (!static_obj(lock->key)) {
70843 debug_locks_off();
70844 printk("INFO: trying to register non-static key.\n");
70845+ printk("lock:%pS key:%pS.\n", lock, lock->key);
70846 printk("the code is fine but needs lockdep annotation.\n");
70847 printk("turning off the locking correctness validator.\n");
70848 dump_stack();
70849@@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
70850 if (!class)
70851 return 0;
70852 }
70853- atomic_inc((atomic_t *)&class->ops);
70854+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
70855 if (very_verbose(class)) {
70856 printk("\nacquire class [%p] %s", class->key, class->name);
70857 if (class->name_version > 1)
70858diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
70859index b2c71c5..7b88d63 100644
70860--- a/kernel/lockdep_proc.c
70861+++ b/kernel/lockdep_proc.c
70862@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
70863 return 0;
70864 }
70865
70866- seq_printf(m, "%p", class->key);
70867+ seq_printf(m, "%pK", class->key);
70868 #ifdef CONFIG_DEBUG_LOCKDEP
70869 seq_printf(m, " OPS:%8ld", class->ops);
70870 #endif
70871@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
70872
70873 list_for_each_entry(entry, &class->locks_after, entry) {
70874 if (entry->distance == 1) {
70875- seq_printf(m, " -> [%p] ", entry->class->key);
70876+ seq_printf(m, " -> [%pK] ", entry->class->key);
70877 print_name(m, entry->class);
70878 seq_puts(m, "\n");
70879 }
70880@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
70881 if (!class->key)
70882 continue;
70883
70884- seq_printf(m, "[%p] ", class->key);
70885+ seq_printf(m, "[%pK] ", class->key);
70886 print_name(m, class);
70887 seq_puts(m, "\n");
70888 }
70889@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
70890 if (!i)
70891 seq_line(m, '-', 40-namelen, namelen);
70892
70893- snprintf(ip, sizeof(ip), "[<%p>]",
70894+ snprintf(ip, sizeof(ip), "[<%pK>]",
70895 (void *)class->contention_point[i]);
70896 seq_printf(m, "%40s %14lu %29s %pS\n",
70897 name, stats->contention_point[i],
70898@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
70899 if (!i)
70900 seq_line(m, '-', 40-namelen, namelen);
70901
70902- snprintf(ip, sizeof(ip), "[<%p>]",
70903+ snprintf(ip, sizeof(ip), "[<%pK>]",
70904 (void *)class->contending_point[i]);
70905 seq_printf(m, "%40s %14lu %29s %pS\n",
70906 name, stats->contending_point[i],
70907diff --git a/kernel/module.c b/kernel/module.c
70908index eab0827..75ede66 100644
70909--- a/kernel/module.c
70910+++ b/kernel/module.c
70911@@ -61,6 +61,7 @@
70912 #include <linux/pfn.h>
70913 #include <linux/bsearch.h>
70914 #include <linux/fips.h>
70915+#include <linux/grsecurity.h>
70916 #include <uapi/linux/module.h>
70917 #include "module-internal.h"
70918
70919@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
70920
70921 /* Bounds of module allocation, for speeding __module_address.
70922 * Protected by module_mutex. */
70923-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
70924+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
70925+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
70926
70927 int register_module_notifier(struct notifier_block * nb)
70928 {
70929@@ -322,7 +324,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
70930 return true;
70931
70932 list_for_each_entry_rcu(mod, &modules, list) {
70933- struct symsearch arr[] = {
70934+ struct symsearch modarr[] = {
70935 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
70936 NOT_GPL_ONLY, false },
70937 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
70938@@ -347,7 +349,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
70939 if (mod->state == MODULE_STATE_UNFORMED)
70940 continue;
70941
70942- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
70943+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
70944 return true;
70945 }
70946 return false;
70947@@ -484,7 +486,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
70948 static int percpu_modalloc(struct module *mod,
70949 unsigned long size, unsigned long align)
70950 {
70951- if (align > PAGE_SIZE) {
70952+ if (align-1 >= PAGE_SIZE) {
70953 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
70954 mod->name, align, PAGE_SIZE);
70955 align = PAGE_SIZE;
70956@@ -1088,7 +1090,7 @@ struct module_attribute module_uevent =
70957 static ssize_t show_coresize(struct module_attribute *mattr,
70958 struct module_kobject *mk, char *buffer)
70959 {
70960- return sprintf(buffer, "%u\n", mk->mod->core_size);
70961+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
70962 }
70963
70964 static struct module_attribute modinfo_coresize =
70965@@ -1097,7 +1099,7 @@ static struct module_attribute modinfo_coresize =
70966 static ssize_t show_initsize(struct module_attribute *mattr,
70967 struct module_kobject *mk, char *buffer)
70968 {
70969- return sprintf(buffer, "%u\n", mk->mod->init_size);
70970+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
70971 }
70972
70973 static struct module_attribute modinfo_initsize =
70974@@ -1311,7 +1313,7 @@ resolve_symbol_wait(struct module *mod,
70975 */
70976 #ifdef CONFIG_SYSFS
70977
70978-#ifdef CONFIG_KALLSYMS
70979+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
70980 static inline bool sect_empty(const Elf_Shdr *sect)
70981 {
70982 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
70983@@ -1777,21 +1779,21 @@ static void set_section_ro_nx(void *base,
70984
70985 static void unset_module_core_ro_nx(struct module *mod)
70986 {
70987- set_page_attributes(mod->module_core + mod->core_text_size,
70988- mod->module_core + mod->core_size,
70989+ set_page_attributes(mod->module_core_rw,
70990+ mod->module_core_rw + mod->core_size_rw,
70991 set_memory_x);
70992- set_page_attributes(mod->module_core,
70993- mod->module_core + mod->core_ro_size,
70994+ set_page_attributes(mod->module_core_rx,
70995+ mod->module_core_rx + mod->core_size_rx,
70996 set_memory_rw);
70997 }
70998
70999 static void unset_module_init_ro_nx(struct module *mod)
71000 {
71001- set_page_attributes(mod->module_init + mod->init_text_size,
71002- mod->module_init + mod->init_size,
71003+ set_page_attributes(mod->module_init_rw,
71004+ mod->module_init_rw + mod->init_size_rw,
71005 set_memory_x);
71006- set_page_attributes(mod->module_init,
71007- mod->module_init + mod->init_ro_size,
71008+ set_page_attributes(mod->module_init_rx,
71009+ mod->module_init_rx + mod->init_size_rx,
71010 set_memory_rw);
71011 }
71012
71013@@ -1804,14 +1806,14 @@ void set_all_modules_text_rw(void)
71014 list_for_each_entry_rcu(mod, &modules, list) {
71015 if (mod->state == MODULE_STATE_UNFORMED)
71016 continue;
71017- if ((mod->module_core) && (mod->core_text_size)) {
71018- set_page_attributes(mod->module_core,
71019- mod->module_core + mod->core_text_size,
71020+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
71021+ set_page_attributes(mod->module_core_rx,
71022+ mod->module_core_rx + mod->core_size_rx,
71023 set_memory_rw);
71024 }
71025- if ((mod->module_init) && (mod->init_text_size)) {
71026- set_page_attributes(mod->module_init,
71027- mod->module_init + mod->init_text_size,
71028+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
71029+ set_page_attributes(mod->module_init_rx,
71030+ mod->module_init_rx + mod->init_size_rx,
71031 set_memory_rw);
71032 }
71033 }
71034@@ -1827,14 +1829,14 @@ void set_all_modules_text_ro(void)
71035 list_for_each_entry_rcu(mod, &modules, list) {
71036 if (mod->state == MODULE_STATE_UNFORMED)
71037 continue;
71038- if ((mod->module_core) && (mod->core_text_size)) {
71039- set_page_attributes(mod->module_core,
71040- mod->module_core + mod->core_text_size,
71041+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
71042+ set_page_attributes(mod->module_core_rx,
71043+ mod->module_core_rx + mod->core_size_rx,
71044 set_memory_ro);
71045 }
71046- if ((mod->module_init) && (mod->init_text_size)) {
71047- set_page_attributes(mod->module_init,
71048- mod->module_init + mod->init_text_size,
71049+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
71050+ set_page_attributes(mod->module_init_rx,
71051+ mod->module_init_rx + mod->init_size_rx,
71052 set_memory_ro);
71053 }
71054 }
71055@@ -1880,16 +1882,19 @@ static void free_module(struct module *mod)
71056
71057 /* This may be NULL, but that's OK */
71058 unset_module_init_ro_nx(mod);
71059- module_free(mod, mod->module_init);
71060+ module_free(mod, mod->module_init_rw);
71061+ module_free_exec(mod, mod->module_init_rx);
71062 kfree(mod->args);
71063 percpu_modfree(mod);
71064
71065 /* Free lock-classes: */
71066- lockdep_free_key_range(mod->module_core, mod->core_size);
71067+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
71068+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
71069
71070 /* Finally, free the core (containing the module structure) */
71071 unset_module_core_ro_nx(mod);
71072- module_free(mod, mod->module_core);
71073+ module_free_exec(mod, mod->module_core_rx);
71074+ module_free(mod, mod->module_core_rw);
71075
71076 #ifdef CONFIG_MPU
71077 update_protections(current->mm);
71078@@ -1959,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
71079 int ret = 0;
71080 const struct kernel_symbol *ksym;
71081
71082+#ifdef CONFIG_GRKERNSEC_MODHARDEN
71083+ int is_fs_load = 0;
71084+ int register_filesystem_found = 0;
71085+ char *p;
71086+
71087+ p = strstr(mod->args, "grsec_modharden_fs");
71088+ if (p) {
71089+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
71090+ /* copy \0 as well */
71091+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
71092+ is_fs_load = 1;
71093+ }
71094+#endif
71095+
71096 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
71097 const char *name = info->strtab + sym[i].st_name;
71098
71099+#ifdef CONFIG_GRKERNSEC_MODHARDEN
71100+ /* it's a real shame this will never get ripped and copied
71101+ upstream! ;(
71102+ */
71103+ if (is_fs_load && !strcmp(name, "register_filesystem"))
71104+ register_filesystem_found = 1;
71105+#endif
71106+
71107 switch (sym[i].st_shndx) {
71108 case SHN_COMMON:
71109 /* We compiled with -fno-common. These are not
71110@@ -1982,7 +2009,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
71111 ksym = resolve_symbol_wait(mod, info, name);
71112 /* Ok if resolved. */
71113 if (ksym && !IS_ERR(ksym)) {
71114+ pax_open_kernel();
71115 sym[i].st_value = ksym->value;
71116+ pax_close_kernel();
71117 break;
71118 }
71119
71120@@ -2001,11 +2030,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
71121 secbase = (unsigned long)mod_percpu(mod);
71122 else
71123 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
71124+ pax_open_kernel();
71125 sym[i].st_value += secbase;
71126+ pax_close_kernel();
71127 break;
71128 }
71129 }
71130
71131+#ifdef CONFIG_GRKERNSEC_MODHARDEN
71132+ if (is_fs_load && !register_filesystem_found) {
71133+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
71134+ ret = -EPERM;
71135+ }
71136+#endif
71137+
71138 return ret;
71139 }
71140
71141@@ -2089,22 +2127,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
71142 || s->sh_entsize != ~0UL
71143 || strstarts(sname, ".init"))
71144 continue;
71145- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
71146+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
71147+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
71148+ else
71149+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
71150 pr_debug("\t%s\n", sname);
71151 }
71152- switch (m) {
71153- case 0: /* executable */
71154- mod->core_size = debug_align(mod->core_size);
71155- mod->core_text_size = mod->core_size;
71156- break;
71157- case 1: /* RO: text and ro-data */
71158- mod->core_size = debug_align(mod->core_size);
71159- mod->core_ro_size = mod->core_size;
71160- break;
71161- case 3: /* whole core */
71162- mod->core_size = debug_align(mod->core_size);
71163- break;
71164- }
71165 }
71166
71167 pr_debug("Init section allocation order:\n");
71168@@ -2118,23 +2146,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
71169 || s->sh_entsize != ~0UL
71170 || !strstarts(sname, ".init"))
71171 continue;
71172- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
71173- | INIT_OFFSET_MASK);
71174+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
71175+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
71176+ else
71177+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
71178+ s->sh_entsize |= INIT_OFFSET_MASK;
71179 pr_debug("\t%s\n", sname);
71180 }
71181- switch (m) {
71182- case 0: /* executable */
71183- mod->init_size = debug_align(mod->init_size);
71184- mod->init_text_size = mod->init_size;
71185- break;
71186- case 1: /* RO: text and ro-data */
71187- mod->init_size = debug_align(mod->init_size);
71188- mod->init_ro_size = mod->init_size;
71189- break;
71190- case 3: /* whole init */
71191- mod->init_size = debug_align(mod->init_size);
71192- break;
71193- }
71194 }
71195 }
71196
71197@@ -2306,7 +2324,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
71198
71199 /* Put symbol section at end of init part of module. */
71200 symsect->sh_flags |= SHF_ALLOC;
71201- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
71202+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
71203 info->index.sym) | INIT_OFFSET_MASK;
71204 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
71205
71206@@ -2323,13 +2341,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
71207 }
71208
71209 /* Append room for core symbols at end of core part. */
71210- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
71211- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
71212- mod->core_size += strtab_size;
71213+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
71214+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
71215+ mod->core_size_rx += strtab_size;
71216
71217 /* Put string table section at end of init part of module. */
71218 strsect->sh_flags |= SHF_ALLOC;
71219- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
71220+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
71221 info->index.str) | INIT_OFFSET_MASK;
71222 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
71223 }
71224@@ -2347,12 +2365,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
71225 /* Make sure we get permanent strtab: don't use info->strtab. */
71226 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
71227
71228+ pax_open_kernel();
71229+
71230 /* Set types up while we still have access to sections. */
71231 for (i = 0; i < mod->num_symtab; i++)
71232 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
71233
71234- mod->core_symtab = dst = mod->module_core + info->symoffs;
71235- mod->core_strtab = s = mod->module_core + info->stroffs;
71236+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
71237+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
71238 src = mod->symtab;
71239 for (ndst = i = 0; i < mod->num_symtab; i++) {
71240 if (i == 0 ||
71241@@ -2364,6 +2384,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
71242 }
71243 }
71244 mod->core_num_syms = ndst;
71245+
71246+ pax_close_kernel();
71247 }
71248 #else
71249 static inline void layout_symtab(struct module *mod, struct load_info *info)
71250@@ -2397,17 +2419,33 @@ void * __weak module_alloc(unsigned long size)
71251 return vmalloc_exec(size);
71252 }
71253
71254-static void *module_alloc_update_bounds(unsigned long size)
71255+static void *module_alloc_update_bounds_rw(unsigned long size)
71256 {
71257 void *ret = module_alloc(size);
71258
71259 if (ret) {
71260 mutex_lock(&module_mutex);
71261 /* Update module bounds. */
71262- if ((unsigned long)ret < module_addr_min)
71263- module_addr_min = (unsigned long)ret;
71264- if ((unsigned long)ret + size > module_addr_max)
71265- module_addr_max = (unsigned long)ret + size;
71266+ if ((unsigned long)ret < module_addr_min_rw)
71267+ module_addr_min_rw = (unsigned long)ret;
71268+ if ((unsigned long)ret + size > module_addr_max_rw)
71269+ module_addr_max_rw = (unsigned long)ret + size;
71270+ mutex_unlock(&module_mutex);
71271+ }
71272+ return ret;
71273+}
71274+
71275+static void *module_alloc_update_bounds_rx(unsigned long size)
71276+{
71277+ void *ret = module_alloc_exec(size);
71278+
71279+ if (ret) {
71280+ mutex_lock(&module_mutex);
71281+ /* Update module bounds. */
71282+ if ((unsigned long)ret < module_addr_min_rx)
71283+ module_addr_min_rx = (unsigned long)ret;
71284+ if ((unsigned long)ret + size > module_addr_max_rx)
71285+ module_addr_max_rx = (unsigned long)ret + size;
71286 mutex_unlock(&module_mutex);
71287 }
71288 return ret;
71289@@ -2683,8 +2721,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
71290 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
71291 {
71292 const char *modmagic = get_modinfo(info, "vermagic");
71293+ const char *license = get_modinfo(info, "license");
71294 int err;
71295
71296+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
71297+ if (!license || !license_is_gpl_compatible(license))
71298+ return -ENOEXEC;
71299+#endif
71300+
71301 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
71302 modmagic = NULL;
71303
71304@@ -2710,7 +2754,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
71305 }
71306
71307 /* Set up license info based on the info section */
71308- set_license(mod, get_modinfo(info, "license"));
71309+ set_license(mod, license);
71310
71311 return 0;
71312 }
71313@@ -2804,7 +2848,7 @@ static int move_module(struct module *mod, struct load_info *info)
71314 void *ptr;
71315
71316 /* Do the allocs. */
71317- ptr = module_alloc_update_bounds(mod->core_size);
71318+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
71319 /*
71320 * The pointer to this block is stored in the module structure
71321 * which is inside the block. Just mark it as not being a
71322@@ -2814,11 +2858,11 @@ static int move_module(struct module *mod, struct load_info *info)
71323 if (!ptr)
71324 return -ENOMEM;
71325
71326- memset(ptr, 0, mod->core_size);
71327- mod->module_core = ptr;
71328+ memset(ptr, 0, mod->core_size_rw);
71329+ mod->module_core_rw = ptr;
71330
71331- if (mod->init_size) {
71332- ptr = module_alloc_update_bounds(mod->init_size);
71333+ if (mod->init_size_rw) {
71334+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
71335 /*
71336 * The pointer to this block is stored in the module structure
71337 * which is inside the block. This block doesn't need to be
71338@@ -2827,13 +2871,45 @@ static int move_module(struct module *mod, struct load_info *info)
71339 */
71340 kmemleak_ignore(ptr);
71341 if (!ptr) {
71342- module_free(mod, mod->module_core);
71343+ module_free(mod, mod->module_core_rw);
71344 return -ENOMEM;
71345 }
71346- memset(ptr, 0, mod->init_size);
71347- mod->module_init = ptr;
71348+ memset(ptr, 0, mod->init_size_rw);
71349+ mod->module_init_rw = ptr;
71350 } else
71351- mod->module_init = NULL;
71352+ mod->module_init_rw = NULL;
71353+
71354+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
71355+ kmemleak_not_leak(ptr);
71356+ if (!ptr) {
71357+ if (mod->module_init_rw)
71358+ module_free(mod, mod->module_init_rw);
71359+ module_free(mod, mod->module_core_rw);
71360+ return -ENOMEM;
71361+ }
71362+
71363+ pax_open_kernel();
71364+ memset(ptr, 0, mod->core_size_rx);
71365+ pax_close_kernel();
71366+ mod->module_core_rx = ptr;
71367+
71368+ if (mod->init_size_rx) {
71369+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
71370+ kmemleak_ignore(ptr);
71371+ if (!ptr && mod->init_size_rx) {
71372+ module_free_exec(mod, mod->module_core_rx);
71373+ if (mod->module_init_rw)
71374+ module_free(mod, mod->module_init_rw);
71375+ module_free(mod, mod->module_core_rw);
71376+ return -ENOMEM;
71377+ }
71378+
71379+ pax_open_kernel();
71380+ memset(ptr, 0, mod->init_size_rx);
71381+ pax_close_kernel();
71382+ mod->module_init_rx = ptr;
71383+ } else
71384+ mod->module_init_rx = NULL;
71385
71386 /* Transfer each section which specifies SHF_ALLOC */
71387 pr_debug("final section addresses:\n");
71388@@ -2844,16 +2920,45 @@ static int move_module(struct module *mod, struct load_info *info)
71389 if (!(shdr->sh_flags & SHF_ALLOC))
71390 continue;
71391
71392- if (shdr->sh_entsize & INIT_OFFSET_MASK)
71393- dest = mod->module_init
71394- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
71395- else
71396- dest = mod->module_core + shdr->sh_entsize;
71397+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
71398+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
71399+ dest = mod->module_init_rw
71400+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
71401+ else
71402+ dest = mod->module_init_rx
71403+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
71404+ } else {
71405+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
71406+ dest = mod->module_core_rw + shdr->sh_entsize;
71407+ else
71408+ dest = mod->module_core_rx + shdr->sh_entsize;
71409+ }
71410+
71411+ if (shdr->sh_type != SHT_NOBITS) {
71412+
71413+#ifdef CONFIG_PAX_KERNEXEC
71414+#ifdef CONFIG_X86_64
71415+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
71416+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
71417+#endif
71418+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
71419+ pax_open_kernel();
71420+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
71421+ pax_close_kernel();
71422+ } else
71423+#endif
71424
71425- if (shdr->sh_type != SHT_NOBITS)
71426 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
71427+ }
71428 /* Update sh_addr to point to copy in image. */
71429- shdr->sh_addr = (unsigned long)dest;
71430+
71431+#ifdef CONFIG_PAX_KERNEXEC
71432+ if (shdr->sh_flags & SHF_EXECINSTR)
71433+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
71434+ else
71435+#endif
71436+
71437+ shdr->sh_addr = (unsigned long)dest;
71438 pr_debug("\t0x%lx %s\n",
71439 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
71440 }
71441@@ -2908,12 +3013,12 @@ static void flush_module_icache(const struct module *mod)
71442 * Do it before processing of module parameters, so the module
71443 * can provide parameter accessor functions of its own.
71444 */
71445- if (mod->module_init)
71446- flush_icache_range((unsigned long)mod->module_init,
71447- (unsigned long)mod->module_init
71448- + mod->init_size);
71449- flush_icache_range((unsigned long)mod->module_core,
71450- (unsigned long)mod->module_core + mod->core_size);
71451+ if (mod->module_init_rx)
71452+ flush_icache_range((unsigned long)mod->module_init_rx,
71453+ (unsigned long)mod->module_init_rx
71454+ + mod->init_size_rx);
71455+ flush_icache_range((unsigned long)mod->module_core_rx,
71456+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
71457
71458 set_fs(old_fs);
71459 }
71460@@ -2983,8 +3088,10 @@ out:
71461 static void module_deallocate(struct module *mod, struct load_info *info)
71462 {
71463 percpu_modfree(mod);
71464- module_free(mod, mod->module_init);
71465- module_free(mod, mod->module_core);
71466+ module_free_exec(mod, mod->module_init_rx);
71467+ module_free_exec(mod, mod->module_core_rx);
71468+ module_free(mod, mod->module_init_rw);
71469+ module_free(mod, mod->module_core_rw);
71470 }
71471
71472 int __weak module_finalize(const Elf_Ehdr *hdr,
71473@@ -2997,7 +3104,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
71474 static int post_relocation(struct module *mod, const struct load_info *info)
71475 {
71476 /* Sort exception table now relocations are done. */
71477+ pax_open_kernel();
71478 sort_extable(mod->extable, mod->extable + mod->num_exentries);
71479+ pax_close_kernel();
71480
71481 /* Copy relocated percpu area over. */
71482 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
71483@@ -3051,16 +3160,16 @@ static int do_init_module(struct module *mod)
71484 MODULE_STATE_COMING, mod);
71485
71486 /* Set RO and NX regions for core */
71487- set_section_ro_nx(mod->module_core,
71488- mod->core_text_size,
71489- mod->core_ro_size,
71490- mod->core_size);
71491+ set_section_ro_nx(mod->module_core_rx,
71492+ mod->core_size_rx,
71493+ mod->core_size_rx,
71494+ mod->core_size_rx);
71495
71496 /* Set RO and NX regions for init */
71497- set_section_ro_nx(mod->module_init,
71498- mod->init_text_size,
71499- mod->init_ro_size,
71500- mod->init_size);
71501+ set_section_ro_nx(mod->module_init_rx,
71502+ mod->init_size_rx,
71503+ mod->init_size_rx,
71504+ mod->init_size_rx);
71505
71506 do_mod_ctors(mod);
71507 /* Start the module */
71508@@ -3122,11 +3231,12 @@ static int do_init_module(struct module *mod)
71509 mod->strtab = mod->core_strtab;
71510 #endif
71511 unset_module_init_ro_nx(mod);
71512- module_free(mod, mod->module_init);
71513- mod->module_init = NULL;
71514- mod->init_size = 0;
71515- mod->init_ro_size = 0;
71516- mod->init_text_size = 0;
71517+ module_free(mod, mod->module_init_rw);
71518+ module_free_exec(mod, mod->module_init_rx);
71519+ mod->module_init_rw = NULL;
71520+ mod->module_init_rx = NULL;
71521+ mod->init_size_rw = 0;
71522+ mod->init_size_rx = 0;
71523 mutex_unlock(&module_mutex);
71524 wake_up_all(&module_wq);
71525
71526@@ -3209,9 +3319,38 @@ again:
71527 if (err)
71528 goto free_unload;
71529
71530+ /* Now copy in args */
71531+ mod->args = strndup_user(uargs, ~0UL >> 1);
71532+ if (IS_ERR(mod->args)) {
71533+ err = PTR_ERR(mod->args);
71534+ goto free_unload;
71535+ }
71536+
71537 /* Set up MODINFO_ATTR fields */
71538 setup_modinfo(mod, info);
71539
71540+#ifdef CONFIG_GRKERNSEC_MODHARDEN
71541+ {
71542+ char *p, *p2;
71543+
71544+ if (strstr(mod->args, "grsec_modharden_netdev")) {
71545+ 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);
71546+ err = -EPERM;
71547+ goto free_modinfo;
71548+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
71549+ p += sizeof("grsec_modharden_normal") - 1;
71550+ p2 = strstr(p, "_");
71551+ if (p2) {
71552+ *p2 = '\0';
71553+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
71554+ *p2 = '_';
71555+ }
71556+ err = -EPERM;
71557+ goto free_modinfo;
71558+ }
71559+ }
71560+#endif
71561+
71562 /* Fix up syms, so that st_value is a pointer to location. */
71563 err = simplify_symbols(mod, info);
71564 if (err < 0)
71565@@ -3227,13 +3366,6 @@ again:
71566
71567 flush_module_icache(mod);
71568
71569- /* Now copy in args */
71570- mod->args = strndup_user(uargs, ~0UL >> 1);
71571- if (IS_ERR(mod->args)) {
71572- err = PTR_ERR(mod->args);
71573- goto free_arch_cleanup;
71574- }
71575-
71576 dynamic_debug_setup(info->debug, info->num_debug);
71577
71578 mutex_lock(&module_mutex);
71579@@ -3278,11 +3410,10 @@ again:
71580 mutex_unlock(&module_mutex);
71581 dynamic_debug_remove(info->debug);
71582 synchronize_sched();
71583- kfree(mod->args);
71584- free_arch_cleanup:
71585 module_arch_cleanup(mod);
71586 free_modinfo:
71587 free_modinfo(mod);
71588+ kfree(mod->args);
71589 free_unload:
71590 module_unload_free(mod);
71591 unlink_mod:
71592@@ -3365,10 +3496,16 @@ static const char *get_ksymbol(struct module *mod,
71593 unsigned long nextval;
71594
71595 /* At worse, next value is at end of module */
71596- if (within_module_init(addr, mod))
71597- nextval = (unsigned long)mod->module_init+mod->init_text_size;
71598+ if (within_module_init_rx(addr, mod))
71599+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
71600+ else if (within_module_init_rw(addr, mod))
71601+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
71602+ else if (within_module_core_rx(addr, mod))
71603+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
71604+ else if (within_module_core_rw(addr, mod))
71605+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
71606 else
71607- nextval = (unsigned long)mod->module_core+mod->core_text_size;
71608+ return NULL;
71609
71610 /* Scan for closest preceding symbol, and next symbol. (ELF
71611 starts real symbols at 1). */
71612@@ -3621,7 +3758,7 @@ static int m_show(struct seq_file *m, void *p)
71613 return 0;
71614
71615 seq_printf(m, "%s %u",
71616- mod->name, mod->init_size + mod->core_size);
71617+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
71618 print_unload_info(m, mod);
71619
71620 /* Informative for users. */
71621@@ -3630,7 +3767,7 @@ static int m_show(struct seq_file *m, void *p)
71622 mod->state == MODULE_STATE_COMING ? "Loading":
71623 "Live");
71624 /* Used by oprofile and other similar tools. */
71625- seq_printf(m, " 0x%pK", mod->module_core);
71626+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
71627
71628 /* Taints info */
71629 if (mod->taints)
71630@@ -3666,7 +3803,17 @@ static const struct file_operations proc_modules_operations = {
71631
71632 static int __init proc_modules_init(void)
71633 {
71634+#ifndef CONFIG_GRKERNSEC_HIDESYM
71635+#ifdef CONFIG_GRKERNSEC_PROC_USER
71636+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
71637+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71638+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
71639+#else
71640 proc_create("modules", 0, NULL, &proc_modules_operations);
71641+#endif
71642+#else
71643+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
71644+#endif
71645 return 0;
71646 }
71647 module_init(proc_modules_init);
71648@@ -3727,14 +3874,14 @@ struct module *__module_address(unsigned long addr)
71649 {
71650 struct module *mod;
71651
71652- if (addr < module_addr_min || addr > module_addr_max)
71653+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
71654+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
71655 return NULL;
71656
71657 list_for_each_entry_rcu(mod, &modules, list) {
71658 if (mod->state == MODULE_STATE_UNFORMED)
71659 continue;
71660- if (within_module_core(addr, mod)
71661- || within_module_init(addr, mod))
71662+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
71663 return mod;
71664 }
71665 return NULL;
71666@@ -3769,11 +3916,20 @@ bool is_module_text_address(unsigned long addr)
71667 */
71668 struct module *__module_text_address(unsigned long addr)
71669 {
71670- struct module *mod = __module_address(addr);
71671+ struct module *mod;
71672+
71673+#ifdef CONFIG_X86_32
71674+ addr = ktla_ktva(addr);
71675+#endif
71676+
71677+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
71678+ return NULL;
71679+
71680+ mod = __module_address(addr);
71681+
71682 if (mod) {
71683 /* Make sure it's within the text section. */
71684- if (!within(addr, mod->module_init, mod->init_text_size)
71685- && !within(addr, mod->module_core, mod->core_text_size))
71686+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
71687 mod = NULL;
71688 }
71689 return mod;
71690diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
71691index 7e3443f..b2a1e6b 100644
71692--- a/kernel/mutex-debug.c
71693+++ b/kernel/mutex-debug.c
71694@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
71695 }
71696
71697 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
71698- struct thread_info *ti)
71699+ struct task_struct *task)
71700 {
71701 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
71702
71703 /* Mark the current thread as blocked on the lock: */
71704- ti->task->blocked_on = waiter;
71705+ task->blocked_on = waiter;
71706 }
71707
71708 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
71709- struct thread_info *ti)
71710+ struct task_struct *task)
71711 {
71712 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
71713- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
71714- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
71715- ti->task->blocked_on = NULL;
71716+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
71717+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
71718+ task->blocked_on = NULL;
71719
71720 list_del_init(&waiter->list);
71721 waiter->task = NULL;
71722diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
71723index 0799fd3..d06ae3b 100644
71724--- a/kernel/mutex-debug.h
71725+++ b/kernel/mutex-debug.h
71726@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
71727 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
71728 extern void debug_mutex_add_waiter(struct mutex *lock,
71729 struct mutex_waiter *waiter,
71730- struct thread_info *ti);
71731+ struct task_struct *task);
71732 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
71733- struct thread_info *ti);
71734+ struct task_struct *task);
71735 extern void debug_mutex_unlock(struct mutex *lock);
71736 extern void debug_mutex_init(struct mutex *lock, const char *name,
71737 struct lock_class_key *key);
71738diff --git a/kernel/mutex.c b/kernel/mutex.c
71739index a307cc9..27fd2e9 100644
71740--- a/kernel/mutex.c
71741+++ b/kernel/mutex.c
71742@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
71743 spin_lock_mutex(&lock->wait_lock, flags);
71744
71745 debug_mutex_lock_common(lock, &waiter);
71746- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
71747+ debug_mutex_add_waiter(lock, &waiter, task);
71748
71749 /* add waiting tasks to the end of the waitqueue (FIFO): */
71750 list_add_tail(&waiter.list, &lock->wait_list);
71751@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
71752 * TASK_UNINTERRUPTIBLE case.)
71753 */
71754 if (unlikely(signal_pending_state(state, task))) {
71755- mutex_remove_waiter(lock, &waiter,
71756- task_thread_info(task));
71757+ mutex_remove_waiter(lock, &waiter, task);
71758 mutex_release(&lock->dep_map, 1, ip);
71759 spin_unlock_mutex(&lock->wait_lock, flags);
71760
71761@@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
71762 done:
71763 lock_acquired(&lock->dep_map, ip);
71764 /* got the lock - rejoice! */
71765- mutex_remove_waiter(lock, &waiter, current_thread_info());
71766+ mutex_remove_waiter(lock, &waiter, task);
71767 mutex_set_owner(lock);
71768
71769 /* set it to 0 if there are no waiters left: */
71770diff --git a/kernel/notifier.c b/kernel/notifier.c
71771index 2d5cc4c..d9ea600 100644
71772--- a/kernel/notifier.c
71773+++ b/kernel/notifier.c
71774@@ -5,6 +5,7 @@
71775 #include <linux/rcupdate.h>
71776 #include <linux/vmalloc.h>
71777 #include <linux/reboot.h>
71778+#include <linux/mm.h>
71779
71780 /*
71781 * Notifier list for kernel code which wants to be called
71782@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
71783 while ((*nl) != NULL) {
71784 if (n->priority > (*nl)->priority)
71785 break;
71786- nl = &((*nl)->next);
71787+ nl = (struct notifier_block **)&((*nl)->next);
71788 }
71789- n->next = *nl;
71790+ pax_open_kernel();
71791+ *(const void **)&n->next = *nl;
71792 rcu_assign_pointer(*nl, n);
71793+ pax_close_kernel();
71794 return 0;
71795 }
71796
71797@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
71798 return 0;
71799 if (n->priority > (*nl)->priority)
71800 break;
71801- nl = &((*nl)->next);
71802+ nl = (struct notifier_block **)&((*nl)->next);
71803 }
71804- n->next = *nl;
71805+ pax_open_kernel();
71806+ *(const void **)&n->next = *nl;
71807 rcu_assign_pointer(*nl, n);
71808+ pax_close_kernel();
71809 return 0;
71810 }
71811
71812@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
71813 {
71814 while ((*nl) != NULL) {
71815 if ((*nl) == n) {
71816+ pax_open_kernel();
71817 rcu_assign_pointer(*nl, n->next);
71818+ pax_close_kernel();
71819 return 0;
71820 }
71821- nl = &((*nl)->next);
71822+ nl = (struct notifier_block **)&((*nl)->next);
71823 }
71824 return -ENOENT;
71825 }
71826diff --git a/kernel/panic.c b/kernel/panic.c
71827index e1b2822..5edc1d9 100644
71828--- a/kernel/panic.c
71829+++ b/kernel/panic.c
71830@@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
71831 const char *board;
71832
71833 printk(KERN_WARNING "------------[ cut here ]------------\n");
71834- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
71835+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
71836 board = dmi_get_system_info(DMI_PRODUCT_NAME);
71837 if (board)
71838 printk(KERN_WARNING "Hardware name: %s\n", board);
71839@@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
71840 */
71841 void __stack_chk_fail(void)
71842 {
71843- panic("stack-protector: Kernel stack is corrupted in: %p\n",
71844+ dump_stack();
71845+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
71846 __builtin_return_address(0));
71847 }
71848 EXPORT_SYMBOL(__stack_chk_fail);
71849diff --git a/kernel/pid.c b/kernel/pid.c
71850index f2c6a68..4922d97 100644
71851--- a/kernel/pid.c
71852+++ b/kernel/pid.c
71853@@ -33,6 +33,7 @@
71854 #include <linux/rculist.h>
71855 #include <linux/bootmem.h>
71856 #include <linux/hash.h>
71857+#include <linux/security.h>
71858 #include <linux/pid_namespace.h>
71859 #include <linux/init_task.h>
71860 #include <linux/syscalls.h>
71861@@ -46,7 +47,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
71862
71863 int pid_max = PID_MAX_DEFAULT;
71864
71865-#define RESERVED_PIDS 300
71866+#define RESERVED_PIDS 500
71867
71868 int pid_max_min = RESERVED_PIDS + 1;
71869 int pid_max_max = PID_MAX_LIMIT;
71870@@ -441,10 +442,18 @@ EXPORT_SYMBOL(pid_task);
71871 */
71872 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
71873 {
71874+ struct task_struct *task;
71875+
71876 rcu_lockdep_assert(rcu_read_lock_held(),
71877 "find_task_by_pid_ns() needs rcu_read_lock()"
71878 " protection");
71879- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
71880+
71881+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
71882+
71883+ if (gr_pid_is_chrooted(task))
71884+ return NULL;
71885+
71886+ return task;
71887 }
71888
71889 struct task_struct *find_task_by_vpid(pid_t vnr)
71890@@ -452,6 +461,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
71891 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
71892 }
71893
71894+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
71895+{
71896+ rcu_lockdep_assert(rcu_read_lock_held(),
71897+ "find_task_by_pid_ns() needs rcu_read_lock()"
71898+ " protection");
71899+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
71900+}
71901+
71902 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
71903 {
71904 struct pid *pid;
71905diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
71906index a278cad..bff5bd3 100644
71907--- a/kernel/posix-cpu-timers.c
71908+++ b/kernel/posix-cpu-timers.c
71909@@ -1557,14 +1557,14 @@ struct k_clock clock_posix_cpu = {
71910
71911 static __init int init_posix_cpu_timers(void)
71912 {
71913- struct k_clock process = {
71914+ static struct k_clock process = {
71915 .clock_getres = process_cpu_clock_getres,
71916 .clock_get = process_cpu_clock_get,
71917 .timer_create = process_cpu_timer_create,
71918 .nsleep = process_cpu_nsleep,
71919 .nsleep_restart = process_cpu_nsleep_restart,
71920 };
71921- struct k_clock thread = {
71922+ static struct k_clock thread = {
71923 .clock_getres = thread_cpu_clock_getres,
71924 .clock_get = thread_cpu_clock_get,
71925 .timer_create = thread_cpu_timer_create,
71926diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
71927index 69185ae..cc2847a 100644
71928--- a/kernel/posix-timers.c
71929+++ b/kernel/posix-timers.c
71930@@ -43,6 +43,7 @@
71931 #include <linux/idr.h>
71932 #include <linux/posix-clock.h>
71933 #include <linux/posix-timers.h>
71934+#include <linux/grsecurity.h>
71935 #include <linux/syscalls.h>
71936 #include <linux/wait.h>
71937 #include <linux/workqueue.h>
71938@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
71939 * which we beg off on and pass to do_sys_settimeofday().
71940 */
71941
71942-static struct k_clock posix_clocks[MAX_CLOCKS];
71943+static struct k_clock *posix_clocks[MAX_CLOCKS];
71944
71945 /*
71946 * These ones are defined below.
71947@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
71948 */
71949 static __init int init_posix_timers(void)
71950 {
71951- struct k_clock clock_realtime = {
71952+ static struct k_clock clock_realtime = {
71953 .clock_getres = hrtimer_get_res,
71954 .clock_get = posix_clock_realtime_get,
71955 .clock_set = posix_clock_realtime_set,
71956@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
71957 .timer_get = common_timer_get,
71958 .timer_del = common_timer_del,
71959 };
71960- struct k_clock clock_monotonic = {
71961+ static struct k_clock clock_monotonic = {
71962 .clock_getres = hrtimer_get_res,
71963 .clock_get = posix_ktime_get_ts,
71964 .nsleep = common_nsleep,
71965@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
71966 .timer_get = common_timer_get,
71967 .timer_del = common_timer_del,
71968 };
71969- struct k_clock clock_monotonic_raw = {
71970+ static struct k_clock clock_monotonic_raw = {
71971 .clock_getres = hrtimer_get_res,
71972 .clock_get = posix_get_monotonic_raw,
71973 };
71974- struct k_clock clock_realtime_coarse = {
71975+ static struct k_clock clock_realtime_coarse = {
71976 .clock_getres = posix_get_coarse_res,
71977 .clock_get = posix_get_realtime_coarse,
71978 };
71979- struct k_clock clock_monotonic_coarse = {
71980+ static struct k_clock clock_monotonic_coarse = {
71981 .clock_getres = posix_get_coarse_res,
71982 .clock_get = posix_get_monotonic_coarse,
71983 };
71984- struct k_clock clock_boottime = {
71985+ static struct k_clock clock_boottime = {
71986 .clock_getres = hrtimer_get_res,
71987 .clock_get = posix_get_boottime,
71988 .nsleep = common_nsleep,
71989@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
71990 return;
71991 }
71992
71993- posix_clocks[clock_id] = *new_clock;
71994+ posix_clocks[clock_id] = new_clock;
71995 }
71996 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
71997
71998@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
71999 return (id & CLOCKFD_MASK) == CLOCKFD ?
72000 &clock_posix_dynamic : &clock_posix_cpu;
72001
72002- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
72003+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
72004 return NULL;
72005- return &posix_clocks[id];
72006+ return posix_clocks[id];
72007 }
72008
72009 static int common_timer_create(struct k_itimer *new_timer)
72010@@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
72011 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
72012 return -EFAULT;
72013
72014+ /* only the CLOCK_REALTIME clock can be set, all other clocks
72015+ have their clock_set fptr set to a nosettime dummy function
72016+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
72017+ call common_clock_set, which calls do_sys_settimeofday, which
72018+ we hook
72019+ */
72020+
72021 return kc->clock_set(which_clock, &new_tp);
72022 }
72023
72024diff --git a/kernel/power/process.c b/kernel/power/process.c
72025index d5a258b..4271191 100644
72026--- a/kernel/power/process.c
72027+++ b/kernel/power/process.c
72028@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
72029 u64 elapsed_csecs64;
72030 unsigned int elapsed_csecs;
72031 bool wakeup = false;
72032+ bool timedout = false;
72033
72034 do_gettimeofday(&start);
72035
72036@@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
72037
72038 while (true) {
72039 todo = 0;
72040+ if (time_after(jiffies, end_time))
72041+ timedout = true;
72042 read_lock(&tasklist_lock);
72043 do_each_thread(g, p) {
72044 if (p == current || !freeze_task(p))
72045 continue;
72046
72047- if (!freezer_should_skip(p))
72048+ if (!freezer_should_skip(p)) {
72049 todo++;
72050+ if (timedout) {
72051+ printk(KERN_ERR "Task refusing to freeze:\n");
72052+ sched_show_task(p);
72053+ }
72054+ }
72055 } while_each_thread(g, p);
72056 read_unlock(&tasklist_lock);
72057
72058@@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
72059 todo += wq_busy;
72060 }
72061
72062- if (!todo || time_after(jiffies, end_time))
72063+ if (!todo || timedout)
72064 break;
72065
72066 if (pm_wakeup_pending()) {
72067diff --git a/kernel/printk.c b/kernel/printk.c
72068index 267ce78..952f8a8 100644
72069--- a/kernel/printk.c
72070+++ b/kernel/printk.c
72071@@ -834,6 +834,11 @@ static int check_syslog_permissions(int type, bool from_file)
72072 if (from_file && type != SYSLOG_ACTION_OPEN)
72073 return 0;
72074
72075+#ifdef CONFIG_GRKERNSEC_DMESG
72076+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
72077+ return -EPERM;
72078+#endif
72079+
72080 if (syslog_action_restricted(type)) {
72081 if (capable(CAP_SYSLOG))
72082 return 0;
72083diff --git a/kernel/profile.c b/kernel/profile.c
72084index 1f39181..86093471 100644
72085--- a/kernel/profile.c
72086+++ b/kernel/profile.c
72087@@ -40,7 +40,7 @@ struct profile_hit {
72088 /* Oprofile timer tick hook */
72089 static int (*timer_hook)(struct pt_regs *) __read_mostly;
72090
72091-static atomic_t *prof_buffer;
72092+static atomic_unchecked_t *prof_buffer;
72093 static unsigned long prof_len, prof_shift;
72094
72095 int prof_on __read_mostly;
72096@@ -282,7 +282,7 @@ static void profile_flip_buffers(void)
72097 hits[i].pc = 0;
72098 continue;
72099 }
72100- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
72101+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
72102 hits[i].hits = hits[i].pc = 0;
72103 }
72104 }
72105@@ -343,9 +343,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
72106 * Add the current hit(s) and flush the write-queue out
72107 * to the global buffer:
72108 */
72109- atomic_add(nr_hits, &prof_buffer[pc]);
72110+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
72111 for (i = 0; i < NR_PROFILE_HIT; ++i) {
72112- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
72113+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
72114 hits[i].pc = hits[i].hits = 0;
72115 }
72116 out:
72117@@ -420,7 +420,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
72118 {
72119 unsigned long pc;
72120 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
72121- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
72122+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
72123 }
72124 #endif /* !CONFIG_SMP */
72125
72126@@ -518,7 +518,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
72127 return -EFAULT;
72128 buf++; p++; count--; read++;
72129 }
72130- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
72131+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
72132 if (copy_to_user(buf, (void *)pnt, count))
72133 return -EFAULT;
72134 read += count;
72135@@ -549,7 +549,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
72136 }
72137 #endif
72138 profile_discard_flip_buffers();
72139- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
72140+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
72141 return count;
72142 }
72143
72144diff --git a/kernel/ptrace.c b/kernel/ptrace.c
72145index 6cbeaae..363c48a 100644
72146--- a/kernel/ptrace.c
72147+++ b/kernel/ptrace.c
72148@@ -324,7 +324,7 @@ static int ptrace_attach(struct task_struct *task, long request,
72149 if (seize)
72150 flags |= PT_SEIZED;
72151 rcu_read_lock();
72152- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
72153+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
72154 flags |= PT_PTRACE_CAP;
72155 rcu_read_unlock();
72156 task->ptrace = flags;
72157@@ -535,7 +535,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
72158 break;
72159 return -EIO;
72160 }
72161- if (copy_to_user(dst, buf, retval))
72162+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
72163 return -EFAULT;
72164 copied += retval;
72165 src += retval;
72166@@ -720,7 +720,7 @@ int ptrace_request(struct task_struct *child, long request,
72167 bool seized = child->ptrace & PT_SEIZED;
72168 int ret = -EIO;
72169 siginfo_t siginfo, *si;
72170- void __user *datavp = (void __user *) data;
72171+ void __user *datavp = (__force void __user *) data;
72172 unsigned long __user *datalp = datavp;
72173 unsigned long flags;
72174
72175@@ -922,14 +922,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
72176 goto out;
72177 }
72178
72179+ if (gr_handle_ptrace(child, request)) {
72180+ ret = -EPERM;
72181+ goto out_put_task_struct;
72182+ }
72183+
72184 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
72185 ret = ptrace_attach(child, request, addr, data);
72186 /*
72187 * Some architectures need to do book-keeping after
72188 * a ptrace attach.
72189 */
72190- if (!ret)
72191+ if (!ret) {
72192 arch_ptrace_attach(child);
72193+ gr_audit_ptrace(child);
72194+ }
72195 goto out_put_task_struct;
72196 }
72197
72198@@ -957,7 +964,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
72199 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
72200 if (copied != sizeof(tmp))
72201 return -EIO;
72202- return put_user(tmp, (unsigned long __user *)data);
72203+ return put_user(tmp, (__force unsigned long __user *)data);
72204 }
72205
72206 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
72207@@ -1067,14 +1074,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
72208 goto out;
72209 }
72210
72211+ if (gr_handle_ptrace(child, request)) {
72212+ ret = -EPERM;
72213+ goto out_put_task_struct;
72214+ }
72215+
72216 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
72217 ret = ptrace_attach(child, request, addr, data);
72218 /*
72219 * Some architectures need to do book-keeping after
72220 * a ptrace attach.
72221 */
72222- if (!ret)
72223+ if (!ret) {
72224 arch_ptrace_attach(child);
72225+ gr_audit_ptrace(child);
72226+ }
72227 goto out_put_task_struct;
72228 }
72229
72230diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
72231index e7dce58..ad0d7b7 100644
72232--- a/kernel/rcutiny.c
72233+++ b/kernel/rcutiny.c
72234@@ -46,7 +46,7 @@
72235 struct rcu_ctrlblk;
72236 static void invoke_rcu_callbacks(void);
72237 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
72238-static void rcu_process_callbacks(struct softirq_action *unused);
72239+static void rcu_process_callbacks(void);
72240 static void __call_rcu(struct rcu_head *head,
72241 void (*func)(struct rcu_head *rcu),
72242 struct rcu_ctrlblk *rcp);
72243@@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
72244 rcu_is_callbacks_kthread()));
72245 }
72246
72247-static void rcu_process_callbacks(struct softirq_action *unused)
72248+static void rcu_process_callbacks(void)
72249 {
72250 __rcu_process_callbacks(&rcu_sched_ctrlblk);
72251 __rcu_process_callbacks(&rcu_bh_ctrlblk);
72252diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
72253index f85016a..91cb03b 100644
72254--- a/kernel/rcutiny_plugin.h
72255+++ b/kernel/rcutiny_plugin.h
72256@@ -896,7 +896,7 @@ static int rcu_kthread(void *arg)
72257 have_rcu_kthread_work = morework;
72258 local_irq_restore(flags);
72259 if (work)
72260- rcu_process_callbacks(NULL);
72261+ rcu_process_callbacks();
72262 schedule_timeout_interruptible(1); /* Leave CPU for others. */
72263 }
72264
72265diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
72266index 31dea01..ad91ffb 100644
72267--- a/kernel/rcutorture.c
72268+++ b/kernel/rcutorture.c
72269@@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
72270 { 0 };
72271 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
72272 { 0 };
72273-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
72274-static atomic_t n_rcu_torture_alloc;
72275-static atomic_t n_rcu_torture_alloc_fail;
72276-static atomic_t n_rcu_torture_free;
72277-static atomic_t n_rcu_torture_mberror;
72278-static atomic_t n_rcu_torture_error;
72279+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
72280+static atomic_unchecked_t n_rcu_torture_alloc;
72281+static atomic_unchecked_t n_rcu_torture_alloc_fail;
72282+static atomic_unchecked_t n_rcu_torture_free;
72283+static atomic_unchecked_t n_rcu_torture_mberror;
72284+static atomic_unchecked_t n_rcu_torture_error;
72285 static long n_rcu_torture_barrier_error;
72286 static long n_rcu_torture_boost_ktrerror;
72287 static long n_rcu_torture_boost_rterror;
72288@@ -272,11 +272,11 @@ rcu_torture_alloc(void)
72289
72290 spin_lock_bh(&rcu_torture_lock);
72291 if (list_empty(&rcu_torture_freelist)) {
72292- atomic_inc(&n_rcu_torture_alloc_fail);
72293+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
72294 spin_unlock_bh(&rcu_torture_lock);
72295 return NULL;
72296 }
72297- atomic_inc(&n_rcu_torture_alloc);
72298+ atomic_inc_unchecked(&n_rcu_torture_alloc);
72299 p = rcu_torture_freelist.next;
72300 list_del_init(p);
72301 spin_unlock_bh(&rcu_torture_lock);
72302@@ -289,7 +289,7 @@ rcu_torture_alloc(void)
72303 static void
72304 rcu_torture_free(struct rcu_torture *p)
72305 {
72306- atomic_inc(&n_rcu_torture_free);
72307+ atomic_inc_unchecked(&n_rcu_torture_free);
72308 spin_lock_bh(&rcu_torture_lock);
72309 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
72310 spin_unlock_bh(&rcu_torture_lock);
72311@@ -409,7 +409,7 @@ rcu_torture_cb(struct rcu_head *p)
72312 i = rp->rtort_pipe_count;
72313 if (i > RCU_TORTURE_PIPE_LEN)
72314 i = RCU_TORTURE_PIPE_LEN;
72315- atomic_inc(&rcu_torture_wcount[i]);
72316+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
72317 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
72318 rp->rtort_mbtest = 0;
72319 rcu_torture_free(rp);
72320@@ -457,7 +457,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
72321 i = rp->rtort_pipe_count;
72322 if (i > RCU_TORTURE_PIPE_LEN)
72323 i = RCU_TORTURE_PIPE_LEN;
72324- atomic_inc(&rcu_torture_wcount[i]);
72325+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
72326 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
72327 rp->rtort_mbtest = 0;
72328 list_del(&rp->rtort_free);
72329@@ -975,7 +975,7 @@ rcu_torture_writer(void *arg)
72330 i = old_rp->rtort_pipe_count;
72331 if (i > RCU_TORTURE_PIPE_LEN)
72332 i = RCU_TORTURE_PIPE_LEN;
72333- atomic_inc(&rcu_torture_wcount[i]);
72334+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
72335 old_rp->rtort_pipe_count++;
72336 cur_ops->deferred_free(old_rp);
72337 }
72338@@ -1060,7 +1060,7 @@ static void rcu_torture_timer(unsigned long unused)
72339 }
72340 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
72341 if (p->rtort_mbtest == 0)
72342- atomic_inc(&n_rcu_torture_mberror);
72343+ atomic_inc_unchecked(&n_rcu_torture_mberror);
72344 spin_lock(&rand_lock);
72345 cur_ops->read_delay(&rand);
72346 n_rcu_torture_timers++;
72347@@ -1124,7 +1124,7 @@ rcu_torture_reader(void *arg)
72348 }
72349 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
72350 if (p->rtort_mbtest == 0)
72351- atomic_inc(&n_rcu_torture_mberror);
72352+ atomic_inc_unchecked(&n_rcu_torture_mberror);
72353 cur_ops->read_delay(&rand);
72354 preempt_disable();
72355 pipe_count = p->rtort_pipe_count;
72356@@ -1183,11 +1183,11 @@ rcu_torture_printk(char *page)
72357 rcu_torture_current,
72358 rcu_torture_current_version,
72359 list_empty(&rcu_torture_freelist),
72360- atomic_read(&n_rcu_torture_alloc),
72361- atomic_read(&n_rcu_torture_alloc_fail),
72362- atomic_read(&n_rcu_torture_free));
72363+ atomic_read_unchecked(&n_rcu_torture_alloc),
72364+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
72365+ atomic_read_unchecked(&n_rcu_torture_free));
72366 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
72367- atomic_read(&n_rcu_torture_mberror),
72368+ atomic_read_unchecked(&n_rcu_torture_mberror),
72369 n_rcu_torture_boost_ktrerror,
72370 n_rcu_torture_boost_rterror);
72371 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
72372@@ -1206,14 +1206,14 @@ rcu_torture_printk(char *page)
72373 n_barrier_attempts,
72374 n_rcu_torture_barrier_error);
72375 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
72376- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
72377+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
72378 n_rcu_torture_barrier_error != 0 ||
72379 n_rcu_torture_boost_ktrerror != 0 ||
72380 n_rcu_torture_boost_rterror != 0 ||
72381 n_rcu_torture_boost_failure != 0 ||
72382 i > 1) {
72383 cnt += sprintf(&page[cnt], "!!! ");
72384- atomic_inc(&n_rcu_torture_error);
72385+ atomic_inc_unchecked(&n_rcu_torture_error);
72386 WARN_ON_ONCE(1);
72387 }
72388 cnt += sprintf(&page[cnt], "Reader Pipe: ");
72389@@ -1227,7 +1227,7 @@ rcu_torture_printk(char *page)
72390 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
72391 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
72392 cnt += sprintf(&page[cnt], " %d",
72393- atomic_read(&rcu_torture_wcount[i]));
72394+ atomic_read_unchecked(&rcu_torture_wcount[i]));
72395 }
72396 cnt += sprintf(&page[cnt], "\n");
72397 if (cur_ops->stats)
72398@@ -1920,7 +1920,7 @@ rcu_torture_cleanup(void)
72399
72400 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
72401
72402- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
72403+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
72404 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
72405 else if (n_online_successes != n_online_attempts ||
72406 n_offline_successes != n_offline_attempts)
72407@@ -1989,18 +1989,18 @@ rcu_torture_init(void)
72408
72409 rcu_torture_current = NULL;
72410 rcu_torture_current_version = 0;
72411- atomic_set(&n_rcu_torture_alloc, 0);
72412- atomic_set(&n_rcu_torture_alloc_fail, 0);
72413- atomic_set(&n_rcu_torture_free, 0);
72414- atomic_set(&n_rcu_torture_mberror, 0);
72415- atomic_set(&n_rcu_torture_error, 0);
72416+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
72417+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
72418+ atomic_set_unchecked(&n_rcu_torture_free, 0);
72419+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
72420+ atomic_set_unchecked(&n_rcu_torture_error, 0);
72421 n_rcu_torture_barrier_error = 0;
72422 n_rcu_torture_boost_ktrerror = 0;
72423 n_rcu_torture_boost_rterror = 0;
72424 n_rcu_torture_boost_failure = 0;
72425 n_rcu_torture_boosts = 0;
72426 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
72427- atomic_set(&rcu_torture_wcount[i], 0);
72428+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
72429 for_each_possible_cpu(cpu) {
72430 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
72431 per_cpu(rcu_torture_count, cpu)[i] = 0;
72432diff --git a/kernel/rcutree.c b/kernel/rcutree.c
72433index e441b77..dd54f17 100644
72434--- a/kernel/rcutree.c
72435+++ b/kernel/rcutree.c
72436@@ -349,9 +349,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
72437 rcu_prepare_for_idle(smp_processor_id());
72438 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
72439 smp_mb__before_atomic_inc(); /* See above. */
72440- atomic_inc(&rdtp->dynticks);
72441+ atomic_inc_unchecked(&rdtp->dynticks);
72442 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
72443- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
72444+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
72445
72446 /*
72447 * It is illegal to enter an extended quiescent state while
72448@@ -487,10 +487,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
72449 int user)
72450 {
72451 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
72452- atomic_inc(&rdtp->dynticks);
72453+ atomic_inc_unchecked(&rdtp->dynticks);
72454 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
72455 smp_mb__after_atomic_inc(); /* See above. */
72456- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
72457+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
72458 rcu_cleanup_after_idle(smp_processor_id());
72459 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
72460 if (!user && !is_idle_task(current)) {
72461@@ -629,14 +629,14 @@ void rcu_nmi_enter(void)
72462 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
72463
72464 if (rdtp->dynticks_nmi_nesting == 0 &&
72465- (atomic_read(&rdtp->dynticks) & 0x1))
72466+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
72467 return;
72468 rdtp->dynticks_nmi_nesting++;
72469 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
72470- atomic_inc(&rdtp->dynticks);
72471+ atomic_inc_unchecked(&rdtp->dynticks);
72472 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
72473 smp_mb__after_atomic_inc(); /* See above. */
72474- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
72475+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
72476 }
72477
72478 /**
72479@@ -655,9 +655,9 @@ void rcu_nmi_exit(void)
72480 return;
72481 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
72482 smp_mb__before_atomic_inc(); /* See above. */
72483- atomic_inc(&rdtp->dynticks);
72484+ atomic_inc_unchecked(&rdtp->dynticks);
72485 smp_mb__after_atomic_inc(); /* Force delay to next write. */
72486- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
72487+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
72488 }
72489
72490 /**
72491@@ -671,7 +671,7 @@ int rcu_is_cpu_idle(void)
72492 int ret;
72493
72494 preempt_disable();
72495- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
72496+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
72497 preempt_enable();
72498 return ret;
72499 }
72500@@ -739,7 +739,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
72501 */
72502 static int dyntick_save_progress_counter(struct rcu_data *rdp)
72503 {
72504- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
72505+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
72506 return (rdp->dynticks_snap & 0x1) == 0;
72507 }
72508
72509@@ -754,7 +754,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
72510 unsigned int curr;
72511 unsigned int snap;
72512
72513- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
72514+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
72515 snap = (unsigned int)rdp->dynticks_snap;
72516
72517 /*
72518@@ -802,10 +802,10 @@ static int jiffies_till_stall_check(void)
72519 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
72520 */
72521 if (till_stall_check < 3) {
72522- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
72523+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
72524 till_stall_check = 3;
72525 } else if (till_stall_check > 300) {
72526- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
72527+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
72528 till_stall_check = 300;
72529 }
72530 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
72531@@ -1592,7 +1592,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
72532 rsp->qlen += rdp->qlen;
72533 rdp->n_cbs_orphaned += rdp->qlen;
72534 rdp->qlen_lazy = 0;
72535- ACCESS_ONCE(rdp->qlen) = 0;
72536+ ACCESS_ONCE_RW(rdp->qlen) = 0;
72537 }
72538
72539 /*
72540@@ -1838,7 +1838,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
72541 }
72542 smp_mb(); /* List handling before counting for rcu_barrier(). */
72543 rdp->qlen_lazy -= count_lazy;
72544- ACCESS_ONCE(rdp->qlen) -= count;
72545+ ACCESS_ONCE_RW(rdp->qlen) -= count;
72546 rdp->n_cbs_invoked += count;
72547
72548 /* Reinstate batch limit if we have worked down the excess. */
72549@@ -2031,7 +2031,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
72550 /*
72551 * Do RCU core processing for the current CPU.
72552 */
72553-static void rcu_process_callbacks(struct softirq_action *unused)
72554+static void rcu_process_callbacks(void)
72555 {
72556 struct rcu_state *rsp;
72557
72558@@ -2154,7 +2154,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
72559 local_irq_restore(flags);
72560 return;
72561 }
72562- ACCESS_ONCE(rdp->qlen)++;
72563+ ACCESS_ONCE_RW(rdp->qlen)++;
72564 if (lazy)
72565 rdp->qlen_lazy++;
72566 else
72567@@ -2363,11 +2363,11 @@ void synchronize_sched_expedited(void)
72568 * counter wrap on a 32-bit system. Quite a few more CPUs would of
72569 * course be required on a 64-bit system.
72570 */
72571- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
72572+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
72573 (ulong)atomic_long_read(&rsp->expedited_done) +
72574 ULONG_MAX / 8)) {
72575 synchronize_sched();
72576- atomic_long_inc(&rsp->expedited_wrap);
72577+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
72578 return;
72579 }
72580
72581@@ -2375,7 +2375,7 @@ void synchronize_sched_expedited(void)
72582 * Take a ticket. Note that atomic_inc_return() implies a
72583 * full memory barrier.
72584 */
72585- snap = atomic_long_inc_return(&rsp->expedited_start);
72586+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
72587 firstsnap = snap;
72588 get_online_cpus();
72589 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
72590@@ -2388,14 +2388,14 @@ void synchronize_sched_expedited(void)
72591 synchronize_sched_expedited_cpu_stop,
72592 NULL) == -EAGAIN) {
72593 put_online_cpus();
72594- atomic_long_inc(&rsp->expedited_tryfail);
72595+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
72596
72597 /* Check to see if someone else did our work for us. */
72598 s = atomic_long_read(&rsp->expedited_done);
72599 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
72600 /* ensure test happens before caller kfree */
72601 smp_mb__before_atomic_inc(); /* ^^^ */
72602- atomic_long_inc(&rsp->expedited_workdone1);
72603+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
72604 return;
72605 }
72606
72607@@ -2404,7 +2404,7 @@ void synchronize_sched_expedited(void)
72608 udelay(trycount * num_online_cpus());
72609 } else {
72610 wait_rcu_gp(call_rcu_sched);
72611- atomic_long_inc(&rsp->expedited_normal);
72612+ atomic_long_inc_unchecked(&rsp->expedited_normal);
72613 return;
72614 }
72615
72616@@ -2413,7 +2413,7 @@ void synchronize_sched_expedited(void)
72617 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
72618 /* ensure test happens before caller kfree */
72619 smp_mb__before_atomic_inc(); /* ^^^ */
72620- atomic_long_inc(&rsp->expedited_workdone2);
72621+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
72622 return;
72623 }
72624
72625@@ -2425,10 +2425,10 @@ void synchronize_sched_expedited(void)
72626 * period works for us.
72627 */
72628 get_online_cpus();
72629- snap = atomic_long_read(&rsp->expedited_start);
72630+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
72631 smp_mb(); /* ensure read is before try_stop_cpus(). */
72632 }
72633- atomic_long_inc(&rsp->expedited_stoppedcpus);
72634+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
72635
72636 /*
72637 * Everyone up to our most recent fetch is covered by our grace
72638@@ -2437,16 +2437,16 @@ void synchronize_sched_expedited(void)
72639 * than we did already did their update.
72640 */
72641 do {
72642- atomic_long_inc(&rsp->expedited_done_tries);
72643+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
72644 s = atomic_long_read(&rsp->expedited_done);
72645 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
72646 /* ensure test happens before caller kfree */
72647 smp_mb__before_atomic_inc(); /* ^^^ */
72648- atomic_long_inc(&rsp->expedited_done_lost);
72649+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
72650 break;
72651 }
72652 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
72653- atomic_long_inc(&rsp->expedited_done_exit);
72654+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
72655
72656 put_online_cpus();
72657 }
72658@@ -2620,7 +2620,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
72659 * ACCESS_ONCE() to prevent the compiler from speculating
72660 * the increment to precede the early-exit check.
72661 */
72662- ACCESS_ONCE(rsp->n_barrier_done)++;
72663+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
72664 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
72665 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
72666 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
72667@@ -2670,7 +2670,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
72668
72669 /* Increment ->n_barrier_done to prevent duplicate work. */
72670 smp_mb(); /* Keep increment after above mechanism. */
72671- ACCESS_ONCE(rsp->n_barrier_done)++;
72672+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
72673 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
72674 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
72675 smp_mb(); /* Keep increment before caller's subsequent code. */
72676@@ -2715,10 +2715,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
72677 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
72678 init_callback_list(rdp);
72679 rdp->qlen_lazy = 0;
72680- ACCESS_ONCE(rdp->qlen) = 0;
72681+ ACCESS_ONCE_RW(rdp->qlen) = 0;
72682 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
72683 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
72684- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
72685+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
72686 #ifdef CONFIG_RCU_USER_QS
72687 WARN_ON_ONCE(rdp->dynticks->in_user);
72688 #endif
72689@@ -2754,8 +2754,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
72690 rdp->blimit = blimit;
72691 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
72692 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
72693- atomic_set(&rdp->dynticks->dynticks,
72694- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
72695+ atomic_set_unchecked(&rdp->dynticks->dynticks,
72696+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
72697 rcu_prepare_for_idle_init(cpu);
72698 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
72699
72700diff --git a/kernel/rcutree.h b/kernel/rcutree.h
72701index 4b69291..704c92e 100644
72702--- a/kernel/rcutree.h
72703+++ b/kernel/rcutree.h
72704@@ -86,7 +86,7 @@ struct rcu_dynticks {
72705 long long dynticks_nesting; /* Track irq/process nesting level. */
72706 /* Process level is worth LLONG_MAX/2. */
72707 int dynticks_nmi_nesting; /* Track NMI nesting level. */
72708- atomic_t dynticks; /* Even value for idle, else odd. */
72709+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
72710 #ifdef CONFIG_RCU_FAST_NO_HZ
72711 int dyntick_drain; /* Prepare-for-idle state variable. */
72712 unsigned long dyntick_holdoff;
72713@@ -423,17 +423,17 @@ struct rcu_state {
72714 /* _rcu_barrier(). */
72715 /* End of fields guarded by barrier_mutex. */
72716
72717- atomic_long_t expedited_start; /* Starting ticket. */
72718- atomic_long_t expedited_done; /* Done ticket. */
72719- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
72720- atomic_long_t expedited_tryfail; /* # acquisition failures. */
72721- atomic_long_t expedited_workdone1; /* # done by others #1. */
72722- atomic_long_t expedited_workdone2; /* # done by others #2. */
72723- atomic_long_t expedited_normal; /* # fallbacks to normal. */
72724- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
72725- atomic_long_t expedited_done_tries; /* # tries to update _done. */
72726- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
72727- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
72728+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
72729+ atomic_long_t expedited_done; /* Done ticket. */
72730+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
72731+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
72732+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
72733+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
72734+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
72735+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
72736+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
72737+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
72738+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
72739
72740 unsigned long jiffies_force_qs; /* Time at which to invoke */
72741 /* force_quiescent_state(). */
72742diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
72743index c1cc7e1..5043e0e 100644
72744--- a/kernel/rcutree_plugin.h
72745+++ b/kernel/rcutree_plugin.h
72746@@ -892,7 +892,7 @@ void synchronize_rcu_expedited(void)
72747
72748 /* Clean up and exit. */
72749 smp_mb(); /* ensure expedited GP seen before counter increment. */
72750- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
72751+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
72752 unlock_mb_ret:
72753 mutex_unlock(&sync_rcu_preempt_exp_mutex);
72754 mb_ret:
72755@@ -2072,7 +2072,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
72756 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
72757 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
72758 cpu, ticks_value, ticks_title,
72759- atomic_read(&rdtp->dynticks) & 0xfff,
72760+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
72761 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
72762 fast_no_hz);
72763 }
72764@@ -2192,7 +2192,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
72765
72766 /* Enqueue the callback on the nocb list and update counts. */
72767 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
72768- ACCESS_ONCE(*old_rhpp) = rhp;
72769+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
72770 atomic_long_add(rhcount, &rdp->nocb_q_count);
72771 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
72772
72773@@ -2384,12 +2384,12 @@ static int rcu_nocb_kthread(void *arg)
72774 * Extract queued callbacks, update counts, and wait
72775 * for a grace period to elapse.
72776 */
72777- ACCESS_ONCE(rdp->nocb_head) = NULL;
72778+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
72779 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
72780 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
72781 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
72782- ACCESS_ONCE(rdp->nocb_p_count) += c;
72783- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
72784+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
72785+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
72786 wait_rcu_gp(rdp->rsp->call_remote);
72787
72788 /* Each pass through the following loop invokes a callback. */
72789@@ -2411,8 +2411,8 @@ static int rcu_nocb_kthread(void *arg)
72790 list = next;
72791 }
72792 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
72793- ACCESS_ONCE(rdp->nocb_p_count) -= c;
72794- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
72795+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
72796+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
72797 rdp->n_nocbs_invoked += c;
72798 }
72799 return 0;
72800@@ -2438,7 +2438,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
72801 rdp = per_cpu_ptr(rsp->rda, cpu);
72802 t = kthread_run(rcu_nocb_kthread, rdp, "rcuo%d", cpu);
72803 BUG_ON(IS_ERR(t));
72804- ACCESS_ONCE(rdp->nocb_kthread) = t;
72805+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
72806 }
72807 }
72808
72809diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
72810index 0d095dc..1985b19 100644
72811--- a/kernel/rcutree_trace.c
72812+++ b/kernel/rcutree_trace.c
72813@@ -123,7 +123,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
72814 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
72815 rdp->passed_quiesce, rdp->qs_pending);
72816 seq_printf(m, " dt=%d/%llx/%d df=%lu",
72817- atomic_read(&rdp->dynticks->dynticks),
72818+ atomic_read_unchecked(&rdp->dynticks->dynticks),
72819 rdp->dynticks->dynticks_nesting,
72820 rdp->dynticks->dynticks_nmi_nesting,
72821 rdp->dynticks_fqs);
72822@@ -184,17 +184,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
72823 struct rcu_state *rsp = (struct rcu_state *)m->private;
72824
72825 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",
72826- atomic_long_read(&rsp->expedited_start),
72827+ atomic_long_read_unchecked(&rsp->expedited_start),
72828 atomic_long_read(&rsp->expedited_done),
72829- atomic_long_read(&rsp->expedited_wrap),
72830- atomic_long_read(&rsp->expedited_tryfail),
72831- atomic_long_read(&rsp->expedited_workdone1),
72832- atomic_long_read(&rsp->expedited_workdone2),
72833- atomic_long_read(&rsp->expedited_normal),
72834- atomic_long_read(&rsp->expedited_stoppedcpus),
72835- atomic_long_read(&rsp->expedited_done_tries),
72836- atomic_long_read(&rsp->expedited_done_lost),
72837- atomic_long_read(&rsp->expedited_done_exit));
72838+ atomic_long_read_unchecked(&rsp->expedited_wrap),
72839+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
72840+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
72841+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
72842+ atomic_long_read_unchecked(&rsp->expedited_normal),
72843+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
72844+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
72845+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
72846+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
72847 return 0;
72848 }
72849
72850diff --git a/kernel/resource.c b/kernel/resource.c
72851index 73f35d4..4684fc4 100644
72852--- a/kernel/resource.c
72853+++ b/kernel/resource.c
72854@@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
72855
72856 static int __init ioresources_init(void)
72857 {
72858+#ifdef CONFIG_GRKERNSEC_PROC_ADD
72859+#ifdef CONFIG_GRKERNSEC_PROC_USER
72860+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
72861+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
72862+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72863+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
72864+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
72865+#endif
72866+#else
72867 proc_create("ioports", 0, NULL, &proc_ioports_operations);
72868 proc_create("iomem", 0, NULL, &proc_iomem_operations);
72869+#endif
72870 return 0;
72871 }
72872 __initcall(ioresources_init);
72873diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
72874index 98ec494..4241d6d 100644
72875--- a/kernel/rtmutex-tester.c
72876+++ b/kernel/rtmutex-tester.c
72877@@ -20,7 +20,7 @@
72878 #define MAX_RT_TEST_MUTEXES 8
72879
72880 static spinlock_t rttest_lock;
72881-static atomic_t rttest_event;
72882+static atomic_unchecked_t rttest_event;
72883
72884 struct test_thread_data {
72885 int opcode;
72886@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72887
72888 case RTTEST_LOCKCONT:
72889 td->mutexes[td->opdata] = 1;
72890- td->event = atomic_add_return(1, &rttest_event);
72891+ td->event = atomic_add_return_unchecked(1, &rttest_event);
72892 return 0;
72893
72894 case RTTEST_RESET:
72895@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72896 return 0;
72897
72898 case RTTEST_RESETEVENT:
72899- atomic_set(&rttest_event, 0);
72900+ atomic_set_unchecked(&rttest_event, 0);
72901 return 0;
72902
72903 default:
72904@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72905 return ret;
72906
72907 td->mutexes[id] = 1;
72908- td->event = atomic_add_return(1, &rttest_event);
72909+ td->event = atomic_add_return_unchecked(1, &rttest_event);
72910 rt_mutex_lock(&mutexes[id]);
72911- td->event = atomic_add_return(1, &rttest_event);
72912+ td->event = atomic_add_return_unchecked(1, &rttest_event);
72913 td->mutexes[id] = 4;
72914 return 0;
72915
72916@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72917 return ret;
72918
72919 td->mutexes[id] = 1;
72920- td->event = atomic_add_return(1, &rttest_event);
72921+ td->event = atomic_add_return_unchecked(1, &rttest_event);
72922 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
72923- td->event = atomic_add_return(1, &rttest_event);
72924+ td->event = atomic_add_return_unchecked(1, &rttest_event);
72925 td->mutexes[id] = ret ? 0 : 4;
72926 return ret ? -EINTR : 0;
72927
72928@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72929 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
72930 return ret;
72931
72932- td->event = atomic_add_return(1, &rttest_event);
72933+ td->event = atomic_add_return_unchecked(1, &rttest_event);
72934 rt_mutex_unlock(&mutexes[id]);
72935- td->event = atomic_add_return(1, &rttest_event);
72936+ td->event = atomic_add_return_unchecked(1, &rttest_event);
72937 td->mutexes[id] = 0;
72938 return 0;
72939
72940@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
72941 break;
72942
72943 td->mutexes[dat] = 2;
72944- td->event = atomic_add_return(1, &rttest_event);
72945+ td->event = atomic_add_return_unchecked(1, &rttest_event);
72946 break;
72947
72948 default:
72949@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
72950 return;
72951
72952 td->mutexes[dat] = 3;
72953- td->event = atomic_add_return(1, &rttest_event);
72954+ td->event = atomic_add_return_unchecked(1, &rttest_event);
72955 break;
72956
72957 case RTTEST_LOCKNOWAIT:
72958@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
72959 return;
72960
72961 td->mutexes[dat] = 1;
72962- td->event = atomic_add_return(1, &rttest_event);
72963+ td->event = atomic_add_return_unchecked(1, &rttest_event);
72964 return;
72965
72966 default:
72967diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
72968index 0984a21..939f183 100644
72969--- a/kernel/sched/auto_group.c
72970+++ b/kernel/sched/auto_group.c
72971@@ -11,7 +11,7 @@
72972
72973 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
72974 static struct autogroup autogroup_default;
72975-static atomic_t autogroup_seq_nr;
72976+static atomic_unchecked_t autogroup_seq_nr;
72977
72978 void __init autogroup_init(struct task_struct *init_task)
72979 {
72980@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
72981
72982 kref_init(&ag->kref);
72983 init_rwsem(&ag->lock);
72984- ag->id = atomic_inc_return(&autogroup_seq_nr);
72985+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
72986 ag->tg = tg;
72987 #ifdef CONFIG_RT_GROUP_SCHED
72988 /*
72989diff --git a/kernel/sched/core.c b/kernel/sched/core.c
72990index 26058d0..06f15dd 100644
72991--- a/kernel/sched/core.c
72992+++ b/kernel/sched/core.c
72993@@ -3631,6 +3631,8 @@ int can_nice(const struct task_struct *p, const int nice)
72994 /* convert nice value [19,-20] to rlimit style value [1,40] */
72995 int nice_rlim = 20 - nice;
72996
72997+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
72998+
72999 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
73000 capable(CAP_SYS_NICE));
73001 }
73002@@ -3664,7 +3666,8 @@ SYSCALL_DEFINE1(nice, int, increment)
73003 if (nice > 19)
73004 nice = 19;
73005
73006- if (increment < 0 && !can_nice(current, nice))
73007+ if (increment < 0 && (!can_nice(current, nice) ||
73008+ gr_handle_chroot_nice()))
73009 return -EPERM;
73010
73011 retval = security_task_setnice(current, nice);
73012@@ -3818,6 +3821,7 @@ recheck:
73013 unsigned long rlim_rtprio =
73014 task_rlimit(p, RLIMIT_RTPRIO);
73015
73016+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
73017 /* can't set/change the rt policy */
73018 if (policy != p->policy && !rlim_rtprio)
73019 return -EPERM;
73020@@ -5162,7 +5166,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
73021 * happens before everything else. This has to be lower priority than
73022 * the notifier in the perf_event subsystem, though.
73023 */
73024-static struct notifier_block __cpuinitdata migration_notifier = {
73025+static struct notifier_block migration_notifier = {
73026 .notifier_call = migration_call,
73027 .priority = CPU_PRI_MIGRATION,
73028 };
73029diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
73030index 81fa536..80fa821 100644
73031--- a/kernel/sched/fair.c
73032+++ b/kernel/sched/fair.c
73033@@ -830,7 +830,7 @@ void task_numa_fault(int node, int pages, bool migrated)
73034
73035 static void reset_ptenuma_scan(struct task_struct *p)
73036 {
73037- ACCESS_ONCE(p->mm->numa_scan_seq)++;
73038+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
73039 p->mm->numa_scan_offset = 0;
73040 }
73041
73042@@ -5663,7 +5663,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
73043 * run_rebalance_domains is triggered when needed from the scheduler tick.
73044 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
73045 */
73046-static void run_rebalance_domains(struct softirq_action *h)
73047+static void run_rebalance_domains(void)
73048 {
73049 int this_cpu = smp_processor_id();
73050 struct rq *this_rq = cpu_rq(this_cpu);
73051diff --git a/kernel/signal.c b/kernel/signal.c
73052index 3d09cf6..a67d2c6 100644
73053--- a/kernel/signal.c
73054+++ b/kernel/signal.c
73055@@ -50,12 +50,12 @@ static struct kmem_cache *sigqueue_cachep;
73056
73057 int print_fatal_signals __read_mostly;
73058
73059-static void __user *sig_handler(struct task_struct *t, int sig)
73060+static __sighandler_t sig_handler(struct task_struct *t, int sig)
73061 {
73062 return t->sighand->action[sig - 1].sa.sa_handler;
73063 }
73064
73065-static int sig_handler_ignored(void __user *handler, int sig)
73066+static int sig_handler_ignored(__sighandler_t handler, int sig)
73067 {
73068 /* Is it explicitly or implicitly ignored? */
73069 return handler == SIG_IGN ||
73070@@ -64,7 +64,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
73071
73072 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
73073 {
73074- void __user *handler;
73075+ __sighandler_t handler;
73076
73077 handler = sig_handler(t, sig);
73078
73079@@ -368,6 +368,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
73080 atomic_inc(&user->sigpending);
73081 rcu_read_unlock();
73082
73083+ if (!override_rlimit)
73084+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
73085+
73086 if (override_rlimit ||
73087 atomic_read(&user->sigpending) <=
73088 task_rlimit(t, RLIMIT_SIGPENDING)) {
73089@@ -492,7 +495,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
73090
73091 int unhandled_signal(struct task_struct *tsk, int sig)
73092 {
73093- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
73094+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
73095 if (is_global_init(tsk))
73096 return 1;
73097 if (handler != SIG_IGN && handler != SIG_DFL)
73098@@ -812,6 +815,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
73099 }
73100 }
73101
73102+ /* allow glibc communication via tgkill to other threads in our
73103+ thread group */
73104+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
73105+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
73106+ && gr_handle_signal(t, sig))
73107+ return -EPERM;
73108+
73109 return security_task_kill(t, info, sig, 0);
73110 }
73111
73112@@ -1194,7 +1204,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
73113 return send_signal(sig, info, p, 1);
73114 }
73115
73116-static int
73117+int
73118 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
73119 {
73120 return send_signal(sig, info, t, 0);
73121@@ -1231,6 +1241,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
73122 unsigned long int flags;
73123 int ret, blocked, ignored;
73124 struct k_sigaction *action;
73125+ int is_unhandled = 0;
73126
73127 spin_lock_irqsave(&t->sighand->siglock, flags);
73128 action = &t->sighand->action[sig-1];
73129@@ -1245,9 +1256,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
73130 }
73131 if (action->sa.sa_handler == SIG_DFL)
73132 t->signal->flags &= ~SIGNAL_UNKILLABLE;
73133+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
73134+ is_unhandled = 1;
73135 ret = specific_send_sig_info(sig, info, t);
73136 spin_unlock_irqrestore(&t->sighand->siglock, flags);
73137
73138+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
73139+ normal operation */
73140+ if (is_unhandled) {
73141+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
73142+ gr_handle_crash(t, sig);
73143+ }
73144+
73145 return ret;
73146 }
73147
73148@@ -1314,8 +1334,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
73149 ret = check_kill_permission(sig, info, p);
73150 rcu_read_unlock();
73151
73152- if (!ret && sig)
73153+ if (!ret && sig) {
73154 ret = do_send_sig_info(sig, info, p, true);
73155+ if (!ret)
73156+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
73157+ }
73158
73159 return ret;
73160 }
73161@@ -2852,7 +2875,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
73162 int error = -ESRCH;
73163
73164 rcu_read_lock();
73165- p = find_task_by_vpid(pid);
73166+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73167+ /* allow glibc communication via tgkill to other threads in our
73168+ thread group */
73169+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
73170+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
73171+ p = find_task_by_vpid_unrestricted(pid);
73172+ else
73173+#endif
73174+ p = find_task_by_vpid(pid);
73175 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
73176 error = check_kill_permission(sig, info, p);
73177 /*
73178@@ -3135,8 +3166,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
73179 }
73180 seg = get_fs();
73181 set_fs(KERNEL_DS);
73182- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
73183- (stack_t __force __user *) &uoss,
73184+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
73185+ (stack_t __force_user *) &uoss,
73186 compat_user_stack_pointer());
73187 set_fs(seg);
73188 if (ret >= 0 && uoss_ptr) {
73189diff --git a/kernel/smp.c b/kernel/smp.c
73190index 69f38bd..77bbf12 100644
73191--- a/kernel/smp.c
73192+++ b/kernel/smp.c
73193@@ -77,7 +77,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
73194 return NOTIFY_OK;
73195 }
73196
73197-static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
73198+static struct notifier_block hotplug_cfd_notifier = {
73199 .notifier_call = hotplug_cfd,
73200 };
73201
73202diff --git a/kernel/softirq.c b/kernel/softirq.c
73203index ed567ba..dc61b61 100644
73204--- a/kernel/softirq.c
73205+++ b/kernel/softirq.c
73206@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
73207 EXPORT_SYMBOL(irq_stat);
73208 #endif
73209
73210-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
73211+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
73212
73213 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
73214
73215-char *softirq_to_name[NR_SOFTIRQS] = {
73216+const char * const softirq_to_name[NR_SOFTIRQS] = {
73217 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
73218 "TASKLET", "SCHED", "HRTIMER", "RCU"
73219 };
73220@@ -244,7 +244,7 @@ restart:
73221 kstat_incr_softirqs_this_cpu(vec_nr);
73222
73223 trace_softirq_entry(vec_nr);
73224- h->action(h);
73225+ h->action();
73226 trace_softirq_exit(vec_nr);
73227 if (unlikely(prev_count != preempt_count())) {
73228 printk(KERN_ERR "huh, entered softirq %u %s %p"
73229@@ -391,7 +391,7 @@ void __raise_softirq_irqoff(unsigned int nr)
73230 or_softirq_pending(1UL << nr);
73231 }
73232
73233-void open_softirq(int nr, void (*action)(struct softirq_action *))
73234+void __init open_softirq(int nr, void (*action)(void))
73235 {
73236 softirq_vec[nr].action = action;
73237 }
73238@@ -447,7 +447,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
73239
73240 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
73241
73242-static void tasklet_action(struct softirq_action *a)
73243+static void tasklet_action(void)
73244 {
73245 struct tasklet_struct *list;
73246
73247@@ -482,7 +482,7 @@ static void tasklet_action(struct softirq_action *a)
73248 }
73249 }
73250
73251-static void tasklet_hi_action(struct softirq_action *a)
73252+static void tasklet_hi_action(void)
73253 {
73254 struct tasklet_struct *list;
73255
73256@@ -718,7 +718,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
73257 return NOTIFY_OK;
73258 }
73259
73260-static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
73261+static struct notifier_block remote_softirq_cpu_notifier = {
73262 .notifier_call = remote_softirq_cpu_notify,
73263 };
73264
73265@@ -835,7 +835,7 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
73266 return NOTIFY_OK;
73267 }
73268
73269-static struct notifier_block __cpuinitdata cpu_nfb = {
73270+static struct notifier_block cpu_nfb = {
73271 .notifier_call = cpu_callback
73272 };
73273
73274diff --git a/kernel/srcu.c b/kernel/srcu.c
73275index 2b85982..d52ab26 100644
73276--- a/kernel/srcu.c
73277+++ b/kernel/srcu.c
73278@@ -305,9 +305,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
73279 preempt_disable();
73280 idx = rcu_dereference_index_check(sp->completed,
73281 rcu_read_lock_sched_held()) & 0x1;
73282- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
73283+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
73284 smp_mb(); /* B */ /* Avoid leaking the critical section. */
73285- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
73286+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
73287 preempt_enable();
73288 return idx;
73289 }
73290@@ -323,7 +323,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
73291 {
73292 preempt_disable();
73293 smp_mb(); /* C */ /* Avoid leaking the critical section. */
73294- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
73295+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
73296 preempt_enable();
73297 }
73298 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
73299diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
73300index 2f194e9..2c05ea9 100644
73301--- a/kernel/stop_machine.c
73302+++ b/kernel/stop_machine.c
73303@@ -362,7 +362,7 @@ static int __cpuinit cpu_stop_cpu_callback(struct notifier_block *nfb,
73304 * cpu notifiers. It currently shares the same priority as sched
73305 * migration_notifier.
73306 */
73307-static struct notifier_block __cpuinitdata cpu_stop_cpu_notifier = {
73308+static struct notifier_block cpu_stop_cpu_notifier = {
73309 .notifier_call = cpu_stop_cpu_callback,
73310 .priority = 10,
73311 };
73312diff --git a/kernel/sys.c b/kernel/sys.c
73313index 265b376..b0cd50d 100644
73314--- a/kernel/sys.c
73315+++ b/kernel/sys.c
73316@@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
73317 error = -EACCES;
73318 goto out;
73319 }
73320+
73321+ if (gr_handle_chroot_setpriority(p, niceval)) {
73322+ error = -EACCES;
73323+ goto out;
73324+ }
73325+
73326 no_nice = security_task_setnice(p, niceval);
73327 if (no_nice) {
73328 error = no_nice;
73329@@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
73330 goto error;
73331 }
73332
73333+ if (gr_check_group_change(new->gid, new->egid, -1))
73334+ goto error;
73335+
73336 if (rgid != (gid_t) -1 ||
73337 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
73338 new->sgid = new->egid;
73339@@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
73340 old = current_cred();
73341
73342 retval = -EPERM;
73343+
73344+ if (gr_check_group_change(kgid, kgid, kgid))
73345+ goto error;
73346+
73347 if (nsown_capable(CAP_SETGID))
73348 new->gid = new->egid = new->sgid = new->fsgid = kgid;
73349 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
73350@@ -647,7 +660,7 @@ error:
73351 /*
73352 * change the user struct in a credentials set to match the new UID
73353 */
73354-static int set_user(struct cred *new)
73355+int set_user(struct cred *new)
73356 {
73357 struct user_struct *new_user;
73358
73359@@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
73360 goto error;
73361 }
73362
73363+ if (gr_check_user_change(new->uid, new->euid, -1))
73364+ goto error;
73365+
73366 if (!uid_eq(new->uid, old->uid)) {
73367 retval = set_user(new);
73368 if (retval < 0)
73369@@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
73370 old = current_cred();
73371
73372 retval = -EPERM;
73373+
73374+ if (gr_check_crash_uid(kuid))
73375+ goto error;
73376+ if (gr_check_user_change(kuid, kuid, kuid))
73377+ goto error;
73378+
73379 if (nsown_capable(CAP_SETUID)) {
73380 new->suid = new->uid = kuid;
73381 if (!uid_eq(kuid, old->uid)) {
73382@@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
73383 goto error;
73384 }
73385
73386+ if (gr_check_user_change(kruid, keuid, -1))
73387+ goto error;
73388+
73389 if (ruid != (uid_t) -1) {
73390 new->uid = kruid;
73391 if (!uid_eq(kruid, old->uid)) {
73392@@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
73393 goto error;
73394 }
73395
73396+ if (gr_check_group_change(krgid, kegid, -1))
73397+ goto error;
73398+
73399 if (rgid != (gid_t) -1)
73400 new->gid = krgid;
73401 if (egid != (gid_t) -1)
73402@@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
73403 if (!uid_valid(kuid))
73404 return old_fsuid;
73405
73406+ if (gr_check_user_change(-1, -1, kuid))
73407+ goto error;
73408+
73409 new = prepare_creds();
73410 if (!new)
73411 return old_fsuid;
73412@@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
73413 }
73414 }
73415
73416+error:
73417 abort_creds(new);
73418 return old_fsuid;
73419
73420@@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
73421 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
73422 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
73423 nsown_capable(CAP_SETGID)) {
73424+ if (gr_check_group_change(-1, -1, kgid))
73425+ goto error;
73426+
73427 if (!gid_eq(kgid, old->fsgid)) {
73428 new->fsgid = kgid;
73429 goto change_okay;
73430 }
73431 }
73432
73433+error:
73434 abort_creds(new);
73435 return old_fsgid;
73436
73437@@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
73438 return -EFAULT;
73439
73440 down_read(&uts_sem);
73441- error = __copy_to_user(&name->sysname, &utsname()->sysname,
73442+ error = __copy_to_user(name->sysname, &utsname()->sysname,
73443 __OLD_UTS_LEN);
73444 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
73445- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
73446+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
73447 __OLD_UTS_LEN);
73448 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
73449- error |= __copy_to_user(&name->release, &utsname()->release,
73450+ error |= __copy_to_user(name->release, &utsname()->release,
73451 __OLD_UTS_LEN);
73452 error |= __put_user(0, name->release + __OLD_UTS_LEN);
73453- error |= __copy_to_user(&name->version, &utsname()->version,
73454+ error |= __copy_to_user(name->version, &utsname()->version,
73455 __OLD_UTS_LEN);
73456 error |= __put_user(0, name->version + __OLD_UTS_LEN);
73457- error |= __copy_to_user(&name->machine, &utsname()->machine,
73458+ error |= __copy_to_user(name->machine, &utsname()->machine,
73459 __OLD_UTS_LEN);
73460 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
73461 up_read(&uts_sem);
73462@@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
73463 error = get_dumpable(me->mm);
73464 break;
73465 case PR_SET_DUMPABLE:
73466- if (arg2 < 0 || arg2 > 1) {
73467+ if (arg2 > 1) {
73468 error = -EINVAL;
73469 break;
73470 }
73471diff --git a/kernel/sysctl.c b/kernel/sysctl.c
73472index c88878d..99d321b 100644
73473--- a/kernel/sysctl.c
73474+++ b/kernel/sysctl.c
73475@@ -92,7 +92,6 @@
73476
73477
73478 #if defined(CONFIG_SYSCTL)
73479-
73480 /* External variables not in a header file. */
73481 extern int sysctl_overcommit_memory;
73482 extern int sysctl_overcommit_ratio;
73483@@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
73484 void __user *buffer, size_t *lenp, loff_t *ppos);
73485 #endif
73486
73487-#ifdef CONFIG_PRINTK
73488 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
73489 void __user *buffer, size_t *lenp, loff_t *ppos);
73490-#endif
73491
73492 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
73493 void __user *buffer, size_t *lenp, loff_t *ppos);
73494@@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
73495
73496 #endif
73497
73498+extern struct ctl_table grsecurity_table[];
73499+
73500 static struct ctl_table kern_table[];
73501 static struct ctl_table vm_table[];
73502 static struct ctl_table fs_table[];
73503@@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
73504 int sysctl_legacy_va_layout;
73505 #endif
73506
73507+#ifdef CONFIG_PAX_SOFTMODE
73508+static ctl_table pax_table[] = {
73509+ {
73510+ .procname = "softmode",
73511+ .data = &pax_softmode,
73512+ .maxlen = sizeof(unsigned int),
73513+ .mode = 0600,
73514+ .proc_handler = &proc_dointvec,
73515+ },
73516+
73517+ { }
73518+};
73519+#endif
73520+
73521 /* The default sysctl tables: */
73522
73523 static struct ctl_table sysctl_base_table[] = {
73524@@ -268,6 +281,22 @@ static int max_extfrag_threshold = 1000;
73525 #endif
73526
73527 static struct ctl_table kern_table[] = {
73528+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
73529+ {
73530+ .procname = "grsecurity",
73531+ .mode = 0500,
73532+ .child = grsecurity_table,
73533+ },
73534+#endif
73535+
73536+#ifdef CONFIG_PAX_SOFTMODE
73537+ {
73538+ .procname = "pax",
73539+ .mode = 0500,
73540+ .child = pax_table,
73541+ },
73542+#endif
73543+
73544 {
73545 .procname = "sched_child_runs_first",
73546 .data = &sysctl_sched_child_runs_first,
73547@@ -593,7 +622,7 @@ static struct ctl_table kern_table[] = {
73548 .data = &modprobe_path,
73549 .maxlen = KMOD_PATH_LEN,
73550 .mode = 0644,
73551- .proc_handler = proc_dostring,
73552+ .proc_handler = proc_dostring_modpriv,
73553 },
73554 {
73555 .procname = "modules_disabled",
73556@@ -760,16 +789,20 @@ static struct ctl_table kern_table[] = {
73557 .extra1 = &zero,
73558 .extra2 = &one,
73559 },
73560+#endif
73561 {
73562 .procname = "kptr_restrict",
73563 .data = &kptr_restrict,
73564 .maxlen = sizeof(int),
73565 .mode = 0644,
73566 .proc_handler = proc_dointvec_minmax_sysadmin,
73567+#ifdef CONFIG_GRKERNSEC_HIDESYM
73568+ .extra1 = &two,
73569+#else
73570 .extra1 = &zero,
73571+#endif
73572 .extra2 = &two,
73573 },
73574-#endif
73575 {
73576 .procname = "ngroups_max",
73577 .data = &ngroups_max,
73578@@ -1266,6 +1299,13 @@ static struct ctl_table vm_table[] = {
73579 .proc_handler = proc_dointvec_minmax,
73580 .extra1 = &zero,
73581 },
73582+ {
73583+ .procname = "heap_stack_gap",
73584+ .data = &sysctl_heap_stack_gap,
73585+ .maxlen = sizeof(sysctl_heap_stack_gap),
73586+ .mode = 0644,
73587+ .proc_handler = proc_doulongvec_minmax,
73588+ },
73589 #else
73590 {
73591 .procname = "nr_trim_pages",
73592@@ -1716,6 +1756,16 @@ int proc_dostring(struct ctl_table *table, int write,
73593 buffer, lenp, ppos);
73594 }
73595
73596+int proc_dostring_modpriv(struct ctl_table *table, int write,
73597+ void __user *buffer, size_t *lenp, loff_t *ppos)
73598+{
73599+ if (write && !capable(CAP_SYS_MODULE))
73600+ return -EPERM;
73601+
73602+ return _proc_do_string(table->data, table->maxlen, write,
73603+ buffer, lenp, ppos);
73604+}
73605+
73606 static size_t proc_skip_spaces(char **buf)
73607 {
73608 size_t ret;
73609@@ -1821,6 +1871,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
73610 len = strlen(tmp);
73611 if (len > *size)
73612 len = *size;
73613+ if (len > sizeof(tmp))
73614+ len = sizeof(tmp);
73615 if (copy_to_user(*buf, tmp, len))
73616 return -EFAULT;
73617 *size -= len;
73618@@ -2013,7 +2065,6 @@ static int proc_taint(struct ctl_table *table, int write,
73619 return err;
73620 }
73621
73622-#ifdef CONFIG_PRINTK
73623 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
73624 void __user *buffer, size_t *lenp, loff_t *ppos)
73625 {
73626@@ -2022,7 +2073,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
73627
73628 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
73629 }
73630-#endif
73631
73632 struct do_proc_dointvec_minmax_conv_param {
73633 int *min;
73634@@ -2169,8 +2219,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
73635 *i = val;
73636 } else {
73637 val = convdiv * (*i) / convmul;
73638- if (!first)
73639+ if (!first) {
73640 err = proc_put_char(&buffer, &left, '\t');
73641+ if (err)
73642+ break;
73643+ }
73644 err = proc_put_long(&buffer, &left, val, false);
73645 if (err)
73646 break;
73647@@ -2562,6 +2615,12 @@ int proc_dostring(struct ctl_table *table, int write,
73648 return -ENOSYS;
73649 }
73650
73651+int proc_dostring_modpriv(struct ctl_table *table, int write,
73652+ void __user *buffer, size_t *lenp, loff_t *ppos)
73653+{
73654+ return -ENOSYS;
73655+}
73656+
73657 int proc_dointvec(struct ctl_table *table, int write,
73658 void __user *buffer, size_t *lenp, loff_t *ppos)
73659 {
73660@@ -2618,5 +2677,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
73661 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
73662 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
73663 EXPORT_SYMBOL(proc_dostring);
73664+EXPORT_SYMBOL(proc_dostring_modpriv);
73665 EXPORT_SYMBOL(proc_doulongvec_minmax);
73666 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
73667diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
73668index 5a63844..25dfc5c 100644
73669--- a/kernel/sysctl_binary.c
73670+++ b/kernel/sysctl_binary.c
73671@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
73672 int i;
73673
73674 set_fs(KERNEL_DS);
73675- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
73676+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
73677 set_fs(old_fs);
73678 if (result < 0)
73679 goto out_kfree;
73680@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
73681 }
73682
73683 set_fs(KERNEL_DS);
73684- result = vfs_write(file, buffer, str - buffer, &pos);
73685+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
73686 set_fs(old_fs);
73687 if (result < 0)
73688 goto out_kfree;
73689@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
73690 int i;
73691
73692 set_fs(KERNEL_DS);
73693- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
73694+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
73695 set_fs(old_fs);
73696 if (result < 0)
73697 goto out_kfree;
73698@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
73699 }
73700
73701 set_fs(KERNEL_DS);
73702- result = vfs_write(file, buffer, str - buffer, &pos);
73703+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
73704 set_fs(old_fs);
73705 if (result < 0)
73706 goto out_kfree;
73707@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
73708 int i;
73709
73710 set_fs(KERNEL_DS);
73711- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
73712+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
73713 set_fs(old_fs);
73714 if (result < 0)
73715 goto out;
73716@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
73717 __le16 dnaddr;
73718
73719 set_fs(KERNEL_DS);
73720- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
73721+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
73722 set_fs(old_fs);
73723 if (result < 0)
73724 goto out;
73725@@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
73726 le16_to_cpu(dnaddr) & 0x3ff);
73727
73728 set_fs(KERNEL_DS);
73729- result = vfs_write(file, buf, len, &pos);
73730+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
73731 set_fs(old_fs);
73732 if (result < 0)
73733 goto out;
73734diff --git a/kernel/taskstats.c b/kernel/taskstats.c
73735index 145bb4d..b2aa969 100644
73736--- a/kernel/taskstats.c
73737+++ b/kernel/taskstats.c
73738@@ -28,9 +28,12 @@
73739 #include <linux/fs.h>
73740 #include <linux/file.h>
73741 #include <linux/pid_namespace.h>
73742+#include <linux/grsecurity.h>
73743 #include <net/genetlink.h>
73744 #include <linux/atomic.h>
73745
73746+extern int gr_is_taskstats_denied(int pid);
73747+
73748 /*
73749 * Maximum length of a cpumask that can be specified in
73750 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
73751@@ -570,6 +573,9 @@ err:
73752
73753 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
73754 {
73755+ if (gr_is_taskstats_denied(current->pid))
73756+ return -EACCES;
73757+
73758 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
73759 return cmd_attr_register_cpumask(info);
73760 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
73761diff --git a/kernel/time.c b/kernel/time.c
73762index d226c6a..c7c0960 100644
73763--- a/kernel/time.c
73764+++ b/kernel/time.c
73765@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
73766 return error;
73767
73768 if (tz) {
73769+ /* we log in do_settimeofday called below, so don't log twice
73770+ */
73771+ if (!tv)
73772+ gr_log_timechange();
73773+
73774 sys_tz = *tz;
73775 update_vsyscall_tz();
73776 if (firsttime) {
73777diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
73778index f11d83b..d016d91 100644
73779--- a/kernel/time/alarmtimer.c
73780+++ b/kernel/time/alarmtimer.c
73781@@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
73782 struct platform_device *pdev;
73783 int error = 0;
73784 int i;
73785- struct k_clock alarm_clock = {
73786+ static struct k_clock alarm_clock = {
73787 .clock_getres = alarm_clock_getres,
73788 .clock_get = alarm_clock_get,
73789 .timer_create = alarm_timer_create,
73790diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
73791index f113755..ec24223 100644
73792--- a/kernel/time/tick-broadcast.c
73793+++ b/kernel/time/tick-broadcast.c
73794@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
73795 * then clear the broadcast bit.
73796 */
73797 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
73798- int cpu = smp_processor_id();
73799+ cpu = smp_processor_id();
73800
73801 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
73802 tick_broadcast_clear_oneshot(cpu);
73803diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
73804index cbc6acb..3a77191 100644
73805--- a/kernel/time/timekeeping.c
73806+++ b/kernel/time/timekeeping.c
73807@@ -15,6 +15,7 @@
73808 #include <linux/init.h>
73809 #include <linux/mm.h>
73810 #include <linux/sched.h>
73811+#include <linux/grsecurity.h>
73812 #include <linux/syscore_ops.h>
73813 #include <linux/clocksource.h>
73814 #include <linux/jiffies.h>
73815@@ -412,6 +413,8 @@ int do_settimeofday(const struct timespec *tv)
73816 if (!timespec_valid_strict(tv))
73817 return -EINVAL;
73818
73819+ gr_log_timechange();
73820+
73821 write_seqlock_irqsave(&tk->lock, flags);
73822
73823 timekeeping_forward_now(tk);
73824diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
73825index af5a7e9..715611a 100644
73826--- a/kernel/time/timer_list.c
73827+++ b/kernel/time/timer_list.c
73828@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
73829
73830 static void print_name_offset(struct seq_file *m, void *sym)
73831 {
73832+#ifdef CONFIG_GRKERNSEC_HIDESYM
73833+ SEQ_printf(m, "<%p>", NULL);
73834+#else
73835 char symname[KSYM_NAME_LEN];
73836
73837 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
73838 SEQ_printf(m, "<%pK>", sym);
73839 else
73840 SEQ_printf(m, "%s", symname);
73841+#endif
73842 }
73843
73844 static void
73845@@ -112,7 +116,11 @@ next_one:
73846 static void
73847 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
73848 {
73849+#ifdef CONFIG_GRKERNSEC_HIDESYM
73850+ SEQ_printf(m, " .base: %p\n", NULL);
73851+#else
73852 SEQ_printf(m, " .base: %pK\n", base);
73853+#endif
73854 SEQ_printf(m, " .index: %d\n",
73855 base->index);
73856 SEQ_printf(m, " .resolution: %Lu nsecs\n",
73857@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
73858 {
73859 struct proc_dir_entry *pe;
73860
73861+#ifdef CONFIG_GRKERNSEC_PROC_ADD
73862+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
73863+#else
73864 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
73865+#endif
73866 if (!pe)
73867 return -ENOMEM;
73868 return 0;
73869diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
73870index 0b537f2..40d6c20 100644
73871--- a/kernel/time/timer_stats.c
73872+++ b/kernel/time/timer_stats.c
73873@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
73874 static unsigned long nr_entries;
73875 static struct entry entries[MAX_ENTRIES];
73876
73877-static atomic_t overflow_count;
73878+static atomic_unchecked_t overflow_count;
73879
73880 /*
73881 * The entries are in a hash-table, for fast lookup:
73882@@ -140,7 +140,7 @@ static void reset_entries(void)
73883 nr_entries = 0;
73884 memset(entries, 0, sizeof(entries));
73885 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
73886- atomic_set(&overflow_count, 0);
73887+ atomic_set_unchecked(&overflow_count, 0);
73888 }
73889
73890 static struct entry *alloc_entry(void)
73891@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
73892 if (likely(entry))
73893 entry->count++;
73894 else
73895- atomic_inc(&overflow_count);
73896+ atomic_inc_unchecked(&overflow_count);
73897
73898 out_unlock:
73899 raw_spin_unlock_irqrestore(lock, flags);
73900@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
73901
73902 static void print_name_offset(struct seq_file *m, unsigned long addr)
73903 {
73904+#ifdef CONFIG_GRKERNSEC_HIDESYM
73905+ seq_printf(m, "<%p>", NULL);
73906+#else
73907 char symname[KSYM_NAME_LEN];
73908
73909 if (lookup_symbol_name(addr, symname) < 0)
73910- seq_printf(m, "<%p>", (void *)addr);
73911+ seq_printf(m, "<%pK>", (void *)addr);
73912 else
73913 seq_printf(m, "%s", symname);
73914+#endif
73915 }
73916
73917 static int tstats_show(struct seq_file *m, void *v)
73918@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
73919
73920 seq_puts(m, "Timer Stats Version: v0.2\n");
73921 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
73922- if (atomic_read(&overflow_count))
73923+ if (atomic_read_unchecked(&overflow_count))
73924 seq_printf(m, "Overflow: %d entries\n",
73925- atomic_read(&overflow_count));
73926+ atomic_read_unchecked(&overflow_count));
73927
73928 for (i = 0; i < nr_entries; i++) {
73929 entry = entries + i;
73930@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
73931 {
73932 struct proc_dir_entry *pe;
73933
73934+#ifdef CONFIG_GRKERNSEC_PROC_ADD
73935+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
73936+#else
73937 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
73938+#endif
73939 if (!pe)
73940 return -ENOMEM;
73941 return 0;
73942diff --git a/kernel/timer.c b/kernel/timer.c
73943index 367d008..1ee9ed9 100644
73944--- a/kernel/timer.c
73945+++ b/kernel/timer.c
73946@@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
73947 /*
73948 * This function runs timers and the timer-tq in bottom half context.
73949 */
73950-static void run_timer_softirq(struct softirq_action *h)
73951+static void run_timer_softirq(void)
73952 {
73953 struct tvec_base *base = __this_cpu_read(tvec_bases);
73954
73955@@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
73956 return NOTIFY_OK;
73957 }
73958
73959-static struct notifier_block __cpuinitdata timers_nb = {
73960+static struct notifier_block timers_nb = {
73961 .notifier_call = timer_cpu_notify,
73962 };
73963
73964diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
73965index c0bd030..62a1927 100644
73966--- a/kernel/trace/blktrace.c
73967+++ b/kernel/trace/blktrace.c
73968@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
73969 struct blk_trace *bt = filp->private_data;
73970 char buf[16];
73971
73972- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
73973+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
73974
73975 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
73976 }
73977@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
73978 return 1;
73979
73980 bt = buf->chan->private_data;
73981- atomic_inc(&bt->dropped);
73982+ atomic_inc_unchecked(&bt->dropped);
73983 return 0;
73984 }
73985
73986@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
73987
73988 bt->dir = dir;
73989 bt->dev = dev;
73990- atomic_set(&bt->dropped, 0);
73991+ atomic_set_unchecked(&bt->dropped, 0);
73992
73993 ret = -EIO;
73994 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
73995diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
73996index 41473b4..325fcfc 100644
73997--- a/kernel/trace/ftrace.c
73998+++ b/kernel/trace/ftrace.c
73999@@ -1874,12 +1874,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
74000 if (unlikely(ftrace_disabled))
74001 return 0;
74002
74003+ ret = ftrace_arch_code_modify_prepare();
74004+ FTRACE_WARN_ON(ret);
74005+ if (ret)
74006+ return 0;
74007+
74008 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
74009+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
74010 if (ret) {
74011 ftrace_bug(ret, ip);
74012- return 0;
74013 }
74014- return 1;
74015+ return ret ? 0 : 1;
74016 }
74017
74018 /*
74019@@ -2965,7 +2970,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
74020
74021 int
74022 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
74023- void *data)
74024+ void *data)
74025 {
74026 struct ftrace_func_probe *entry;
74027 struct ftrace_page *pg;
74028@@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
74029 if (!count)
74030 return 0;
74031
74032+ pax_open_kernel();
74033 sort(start, count, sizeof(*start),
74034 ftrace_cmp_ips, ftrace_swap_ips);
74035+ pax_close_kernel();
74036
74037 start_pg = ftrace_allocate_pages(count);
74038 if (!start_pg)
74039@@ -4541,8 +4548,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
74040 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
74041
74042 static int ftrace_graph_active;
74043-static struct notifier_block ftrace_suspend_notifier;
74044-
74045 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
74046 {
74047 return 0;
74048@@ -4686,6 +4691,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
74049 return NOTIFY_DONE;
74050 }
74051
74052+static struct notifier_block ftrace_suspend_notifier = {
74053+ .notifier_call = ftrace_suspend_notifier_call
74054+};
74055+
74056 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
74057 trace_func_graph_ent_t entryfunc)
74058 {
74059@@ -4699,7 +4708,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
74060 goto out;
74061 }
74062
74063- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
74064 register_pm_notifier(&ftrace_suspend_notifier);
74065
74066 ftrace_graph_active++;
74067diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
74068index ce8514f..8233573 100644
74069--- a/kernel/trace/ring_buffer.c
74070+++ b/kernel/trace/ring_buffer.c
74071@@ -346,9 +346,9 @@ struct buffer_data_page {
74072 */
74073 struct buffer_page {
74074 struct list_head list; /* list of buffer pages */
74075- local_t write; /* index for next write */
74076+ local_unchecked_t write; /* index for next write */
74077 unsigned read; /* index for next read */
74078- local_t entries; /* entries on this page */
74079+ local_unchecked_t entries; /* entries on this page */
74080 unsigned long real_end; /* real end of data */
74081 struct buffer_data_page *page; /* Actual data page */
74082 };
74083@@ -461,8 +461,8 @@ struct ring_buffer_per_cpu {
74084 unsigned long last_overrun;
74085 local_t entries_bytes;
74086 local_t entries;
74087- local_t overrun;
74088- local_t commit_overrun;
74089+ local_unchecked_t overrun;
74090+ local_unchecked_t commit_overrun;
74091 local_t dropped_events;
74092 local_t committing;
74093 local_t commits;
74094@@ -861,8 +861,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
74095 *
74096 * We add a counter to the write field to denote this.
74097 */
74098- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
74099- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
74100+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
74101+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
74102
74103 /*
74104 * Just make sure we have seen our old_write and synchronize
74105@@ -890,8 +890,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
74106 * cmpxchg to only update if an interrupt did not already
74107 * do it for us. If the cmpxchg fails, we don't care.
74108 */
74109- (void)local_cmpxchg(&next_page->write, old_write, val);
74110- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
74111+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
74112+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
74113
74114 /*
74115 * No need to worry about races with clearing out the commit.
74116@@ -1250,12 +1250,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
74117
74118 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
74119 {
74120- return local_read(&bpage->entries) & RB_WRITE_MASK;
74121+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
74122 }
74123
74124 static inline unsigned long rb_page_write(struct buffer_page *bpage)
74125 {
74126- return local_read(&bpage->write) & RB_WRITE_MASK;
74127+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
74128 }
74129
74130 static int
74131@@ -1350,7 +1350,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
74132 * bytes consumed in ring buffer from here.
74133 * Increment overrun to account for the lost events.
74134 */
74135- local_add(page_entries, &cpu_buffer->overrun);
74136+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
74137 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
74138 }
74139
74140@@ -1906,7 +1906,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
74141 * it is our responsibility to update
74142 * the counters.
74143 */
74144- local_add(entries, &cpu_buffer->overrun);
74145+ local_add_unchecked(entries, &cpu_buffer->overrun);
74146 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
74147
74148 /*
74149@@ -2056,7 +2056,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
74150 if (tail == BUF_PAGE_SIZE)
74151 tail_page->real_end = 0;
74152
74153- local_sub(length, &tail_page->write);
74154+ local_sub_unchecked(length, &tail_page->write);
74155 return;
74156 }
74157
74158@@ -2091,7 +2091,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
74159 rb_event_set_padding(event);
74160
74161 /* Set the write back to the previous setting */
74162- local_sub(length, &tail_page->write);
74163+ local_sub_unchecked(length, &tail_page->write);
74164 return;
74165 }
74166
74167@@ -2103,7 +2103,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
74168
74169 /* Set write to end of buffer */
74170 length = (tail + length) - BUF_PAGE_SIZE;
74171- local_sub(length, &tail_page->write);
74172+ local_sub_unchecked(length, &tail_page->write);
74173 }
74174
74175 /*
74176@@ -2129,7 +2129,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
74177 * about it.
74178 */
74179 if (unlikely(next_page == commit_page)) {
74180- local_inc(&cpu_buffer->commit_overrun);
74181+ local_inc_unchecked(&cpu_buffer->commit_overrun);
74182 goto out_reset;
74183 }
74184
74185@@ -2185,7 +2185,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
74186 cpu_buffer->tail_page) &&
74187 (cpu_buffer->commit_page ==
74188 cpu_buffer->reader_page))) {
74189- local_inc(&cpu_buffer->commit_overrun);
74190+ local_inc_unchecked(&cpu_buffer->commit_overrun);
74191 goto out_reset;
74192 }
74193 }
74194@@ -2233,7 +2233,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
74195 length += RB_LEN_TIME_EXTEND;
74196
74197 tail_page = cpu_buffer->tail_page;
74198- write = local_add_return(length, &tail_page->write);
74199+ write = local_add_return_unchecked(length, &tail_page->write);
74200
74201 /* set write to only the index of the write */
74202 write &= RB_WRITE_MASK;
74203@@ -2250,7 +2250,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
74204 kmemcheck_annotate_bitfield(event, bitfield);
74205 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
74206
74207- local_inc(&tail_page->entries);
74208+ local_inc_unchecked(&tail_page->entries);
74209
74210 /*
74211 * If this is the first commit on the page, then update
74212@@ -2283,7 +2283,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
74213
74214 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
74215 unsigned long write_mask =
74216- local_read(&bpage->write) & ~RB_WRITE_MASK;
74217+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
74218 unsigned long event_length = rb_event_length(event);
74219 /*
74220 * This is on the tail page. It is possible that
74221@@ -2293,7 +2293,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
74222 */
74223 old_index += write_mask;
74224 new_index += write_mask;
74225- index = local_cmpxchg(&bpage->write, old_index, new_index);
74226+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
74227 if (index == old_index) {
74228 /* update counters */
74229 local_sub(event_length, &cpu_buffer->entries_bytes);
74230@@ -2632,7 +2632,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
74231
74232 /* Do the likely case first */
74233 if (likely(bpage->page == (void *)addr)) {
74234- local_dec(&bpage->entries);
74235+ local_dec_unchecked(&bpage->entries);
74236 return;
74237 }
74238
74239@@ -2644,7 +2644,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
74240 start = bpage;
74241 do {
74242 if (bpage->page == (void *)addr) {
74243- local_dec(&bpage->entries);
74244+ local_dec_unchecked(&bpage->entries);
74245 return;
74246 }
74247 rb_inc_page(cpu_buffer, &bpage);
74248@@ -2926,7 +2926,7 @@ static inline unsigned long
74249 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
74250 {
74251 return local_read(&cpu_buffer->entries) -
74252- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
74253+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
74254 }
74255
74256 /**
74257@@ -3015,7 +3015,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
74258 return 0;
74259
74260 cpu_buffer = buffer->buffers[cpu];
74261- ret = local_read(&cpu_buffer->overrun);
74262+ ret = local_read_unchecked(&cpu_buffer->overrun);
74263
74264 return ret;
74265 }
74266@@ -3038,7 +3038,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
74267 return 0;
74268
74269 cpu_buffer = buffer->buffers[cpu];
74270- ret = local_read(&cpu_buffer->commit_overrun);
74271+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
74272
74273 return ret;
74274 }
74275@@ -3105,7 +3105,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
74276 /* if you care about this being correct, lock the buffer */
74277 for_each_buffer_cpu(buffer, cpu) {
74278 cpu_buffer = buffer->buffers[cpu];
74279- overruns += local_read(&cpu_buffer->overrun);
74280+ overruns += local_read_unchecked(&cpu_buffer->overrun);
74281 }
74282
74283 return overruns;
74284@@ -3281,8 +3281,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
74285 /*
74286 * Reset the reader page to size zero.
74287 */
74288- local_set(&cpu_buffer->reader_page->write, 0);
74289- local_set(&cpu_buffer->reader_page->entries, 0);
74290+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
74291+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
74292 local_set(&cpu_buffer->reader_page->page->commit, 0);
74293 cpu_buffer->reader_page->real_end = 0;
74294
74295@@ -3316,7 +3316,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
74296 * want to compare with the last_overrun.
74297 */
74298 smp_mb();
74299- overwrite = local_read(&(cpu_buffer->overrun));
74300+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
74301
74302 /*
74303 * Here's the tricky part.
74304@@ -3886,8 +3886,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
74305
74306 cpu_buffer->head_page
74307 = list_entry(cpu_buffer->pages, struct buffer_page, list);
74308- local_set(&cpu_buffer->head_page->write, 0);
74309- local_set(&cpu_buffer->head_page->entries, 0);
74310+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
74311+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
74312 local_set(&cpu_buffer->head_page->page->commit, 0);
74313
74314 cpu_buffer->head_page->read = 0;
74315@@ -3897,14 +3897,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
74316
74317 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
74318 INIT_LIST_HEAD(&cpu_buffer->new_pages);
74319- local_set(&cpu_buffer->reader_page->write, 0);
74320- local_set(&cpu_buffer->reader_page->entries, 0);
74321+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
74322+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
74323 local_set(&cpu_buffer->reader_page->page->commit, 0);
74324 cpu_buffer->reader_page->read = 0;
74325
74326 local_set(&cpu_buffer->entries_bytes, 0);
74327- local_set(&cpu_buffer->overrun, 0);
74328- local_set(&cpu_buffer->commit_overrun, 0);
74329+ local_set_unchecked(&cpu_buffer->overrun, 0);
74330+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
74331 local_set(&cpu_buffer->dropped_events, 0);
74332 local_set(&cpu_buffer->entries, 0);
74333 local_set(&cpu_buffer->committing, 0);
74334@@ -4308,8 +4308,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
74335 rb_init_page(bpage);
74336 bpage = reader->page;
74337 reader->page = *data_page;
74338- local_set(&reader->write, 0);
74339- local_set(&reader->entries, 0);
74340+ local_set_unchecked(&reader->write, 0);
74341+ local_set_unchecked(&reader->entries, 0);
74342 reader->read = 0;
74343 *data_page = bpage;
74344
74345diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
74346index 3c13e46..883d039 100644
74347--- a/kernel/trace/trace.c
74348+++ b/kernel/trace/trace.c
74349@@ -4465,10 +4465,9 @@ static const struct file_operations tracing_dyn_info_fops = {
74350 };
74351 #endif
74352
74353-static struct dentry *d_tracer;
74354-
74355 struct dentry *tracing_init_dentry(void)
74356 {
74357+ static struct dentry *d_tracer;
74358 static int once;
74359
74360 if (d_tracer)
74361@@ -4488,10 +4487,9 @@ struct dentry *tracing_init_dentry(void)
74362 return d_tracer;
74363 }
74364
74365-static struct dentry *d_percpu;
74366-
74367 struct dentry *tracing_dentry_percpu(void)
74368 {
74369+ static struct dentry *d_percpu;
74370 static int once;
74371 struct dentry *d_tracer;
74372
74373diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
74374index 880073d..42db7c3 100644
74375--- a/kernel/trace/trace_events.c
74376+++ b/kernel/trace/trace_events.c
74377@@ -1330,10 +1330,6 @@ static LIST_HEAD(ftrace_module_file_list);
74378 struct ftrace_module_file_ops {
74379 struct list_head list;
74380 struct module *mod;
74381- struct file_operations id;
74382- struct file_operations enable;
74383- struct file_operations format;
74384- struct file_operations filter;
74385 };
74386
74387 static struct ftrace_module_file_ops *
74388@@ -1354,17 +1350,12 @@ trace_create_file_ops(struct module *mod)
74389
74390 file_ops->mod = mod;
74391
74392- file_ops->id = ftrace_event_id_fops;
74393- file_ops->id.owner = mod;
74394-
74395- file_ops->enable = ftrace_enable_fops;
74396- file_ops->enable.owner = mod;
74397-
74398- file_ops->filter = ftrace_event_filter_fops;
74399- file_ops->filter.owner = mod;
74400-
74401- file_ops->format = ftrace_event_format_fops;
74402- file_ops->format.owner = mod;
74403+ pax_open_kernel();
74404+ mod->trace_id.owner = mod;
74405+ mod->trace_enable.owner = mod;
74406+ mod->trace_filter.owner = mod;
74407+ mod->trace_format.owner = mod;
74408+ pax_close_kernel();
74409
74410 list_add(&file_ops->list, &ftrace_module_file_list);
74411
74412@@ -1388,8 +1379,8 @@ static void trace_module_add_events(struct module *mod)
74413
74414 for_each_event(call, start, end) {
74415 __trace_add_event_call(*call, mod,
74416- &file_ops->id, &file_ops->enable,
74417- &file_ops->filter, &file_ops->format);
74418+ &mod->trace_id, &mod->trace_enable,
74419+ &mod->trace_filter, &mod->trace_format);
74420 }
74421 }
74422
74423diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
74424index fd3c8aa..5f324a6 100644
74425--- a/kernel/trace/trace_mmiotrace.c
74426+++ b/kernel/trace/trace_mmiotrace.c
74427@@ -24,7 +24,7 @@ struct header_iter {
74428 static struct trace_array *mmio_trace_array;
74429 static bool overrun_detected;
74430 static unsigned long prev_overruns;
74431-static atomic_t dropped_count;
74432+static atomic_unchecked_t dropped_count;
74433
74434 static void mmio_reset_data(struct trace_array *tr)
74435 {
74436@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
74437
74438 static unsigned long count_overruns(struct trace_iterator *iter)
74439 {
74440- unsigned long cnt = atomic_xchg(&dropped_count, 0);
74441+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
74442 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
74443
74444 if (over > prev_overruns)
74445@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
74446 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
74447 sizeof(*entry), 0, pc);
74448 if (!event) {
74449- atomic_inc(&dropped_count);
74450+ atomic_inc_unchecked(&dropped_count);
74451 return;
74452 }
74453 entry = ring_buffer_event_data(event);
74454@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
74455 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
74456 sizeof(*entry), 0, pc);
74457 if (!event) {
74458- atomic_inc(&dropped_count);
74459+ atomic_inc_unchecked(&dropped_count);
74460 return;
74461 }
74462 entry = ring_buffer_event_data(event);
74463diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
74464index 194d796..76edb8f 100644
74465--- a/kernel/trace/trace_output.c
74466+++ b/kernel/trace/trace_output.c
74467@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
74468
74469 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
74470 if (!IS_ERR(p)) {
74471- p = mangle_path(s->buffer + s->len, p, "\n");
74472+ p = mangle_path(s->buffer + s->len, p, "\n\\");
74473 if (p) {
74474 s->len = p - s->buffer;
74475 return 1;
74476@@ -852,14 +852,16 @@ int register_ftrace_event(struct trace_event *event)
74477 goto out;
74478 }
74479
74480+ pax_open_kernel();
74481 if (event->funcs->trace == NULL)
74482- event->funcs->trace = trace_nop_print;
74483+ *(void **)&event->funcs->trace = trace_nop_print;
74484 if (event->funcs->raw == NULL)
74485- event->funcs->raw = trace_nop_print;
74486+ *(void **)&event->funcs->raw = trace_nop_print;
74487 if (event->funcs->hex == NULL)
74488- event->funcs->hex = trace_nop_print;
74489+ *(void **)&event->funcs->hex = trace_nop_print;
74490 if (event->funcs->binary == NULL)
74491- event->funcs->binary = trace_nop_print;
74492+ *(void **)&event->funcs->binary = trace_nop_print;
74493+ pax_close_kernel();
74494
74495 key = event->type & (EVENT_HASHSIZE - 1);
74496
74497diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
74498index 42ca822..cdcacc6 100644
74499--- a/kernel/trace/trace_stack.c
74500+++ b/kernel/trace/trace_stack.c
74501@@ -52,7 +52,7 @@ static inline void check_stack(void)
74502 return;
74503
74504 /* we do not handle interrupt stacks yet */
74505- if (!object_is_on_stack(&this_size))
74506+ if (!object_starts_on_stack(&this_size))
74507 return;
74508
74509 local_irq_save(flags);
74510diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
74511index 67604e5..3ebb003 100644
74512--- a/lib/Kconfig.debug
74513+++ b/lib/Kconfig.debug
74514@@ -1278,6 +1278,7 @@ config LATENCYTOP
74515 depends on DEBUG_KERNEL
74516 depends on STACKTRACE_SUPPORT
74517 depends on PROC_FS
74518+ depends on !GRKERNSEC_HIDESYM
74519 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
74520 select KALLSYMS
74521 select KALLSYMS_ALL
74522@@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
74523
74524 config PROVIDE_OHCI1394_DMA_INIT
74525 bool "Remote debugging over FireWire early on boot"
74526- depends on PCI && X86
74527+ depends on PCI && X86 && !GRKERNSEC
74528 help
74529 If you want to debug problems which hang or crash the kernel early
74530 on boot and the crashing machine has a FireWire port, you can use
74531@@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
74532
74533 config FIREWIRE_OHCI_REMOTE_DMA
74534 bool "Remote debugging over FireWire with firewire-ohci"
74535- depends on FIREWIRE_OHCI
74536+ depends on FIREWIRE_OHCI && !GRKERNSEC
74537 help
74538 This option lets you use the FireWire bus for remote debugging
74539 with help of the firewire-ohci driver. It enables unfiltered
74540diff --git a/lib/Makefile b/lib/Makefile
74541index 02ed6c0..bd243da 100644
74542--- a/lib/Makefile
74543+++ b/lib/Makefile
74544@@ -47,7 +47,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
74545
74546 obj-$(CONFIG_BTREE) += btree.o
74547 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
74548-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
74549+obj-y += list_debug.o
74550 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
74551
74552 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
74553diff --git a/lib/bitmap.c b/lib/bitmap.c
74554index 06f7e4f..f3cf2b0 100644
74555--- a/lib/bitmap.c
74556+++ b/lib/bitmap.c
74557@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
74558 {
74559 int c, old_c, totaldigits, ndigits, nchunks, nbits;
74560 u32 chunk;
74561- const char __user __force *ubuf = (const char __user __force *)buf;
74562+ const char __user *ubuf = (const char __force_user *)buf;
74563
74564 bitmap_zero(maskp, nmaskbits);
74565
74566@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
74567 {
74568 if (!access_ok(VERIFY_READ, ubuf, ulen))
74569 return -EFAULT;
74570- return __bitmap_parse((const char __force *)ubuf,
74571+ return __bitmap_parse((const char __force_kernel *)ubuf,
74572 ulen, 1, maskp, nmaskbits);
74573
74574 }
74575@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
74576 {
74577 unsigned a, b;
74578 int c, old_c, totaldigits;
74579- const char __user __force *ubuf = (const char __user __force *)buf;
74580+ const char __user *ubuf = (const char __force_user *)buf;
74581 int exp_digit, in_range;
74582
74583 totaldigits = c = 0;
74584@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
74585 {
74586 if (!access_ok(VERIFY_READ, ubuf, ulen))
74587 return -EFAULT;
74588- return __bitmap_parselist((const char __force *)ubuf,
74589+ return __bitmap_parselist((const char __force_kernel *)ubuf,
74590 ulen, 1, maskp, nmaskbits);
74591 }
74592 EXPORT_SYMBOL(bitmap_parselist_user);
74593diff --git a/lib/bug.c b/lib/bug.c
74594index d0cdf14..4d07bd2 100644
74595--- a/lib/bug.c
74596+++ b/lib/bug.c
74597@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
74598 return BUG_TRAP_TYPE_NONE;
74599
74600 bug = find_bug(bugaddr);
74601+ if (!bug)
74602+ return BUG_TRAP_TYPE_NONE;
74603
74604 file = NULL;
74605 line = 0;
74606diff --git a/lib/debugobjects.c b/lib/debugobjects.c
74607index d11808c..dc2d6f8 100644
74608--- a/lib/debugobjects.c
74609+++ b/lib/debugobjects.c
74610@@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
74611 if (limit > 4)
74612 return;
74613
74614- is_on_stack = object_is_on_stack(addr);
74615+ is_on_stack = object_starts_on_stack(addr);
74616 if (is_on_stack == onstack)
74617 return;
74618
74619diff --git a/lib/devres.c b/lib/devres.c
74620index 80b9c76..9e32279 100644
74621--- a/lib/devres.c
74622+++ b/lib/devres.c
74623@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
74624 void devm_iounmap(struct device *dev, void __iomem *addr)
74625 {
74626 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
74627- (void *)addr));
74628+ (void __force *)addr));
74629 iounmap(addr);
74630 }
74631 EXPORT_SYMBOL(devm_iounmap);
74632@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
74633 {
74634 ioport_unmap(addr);
74635 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
74636- devm_ioport_map_match, (void *)addr));
74637+ devm_ioport_map_match, (void __force *)addr));
74638 }
74639 EXPORT_SYMBOL(devm_ioport_unmap);
74640
74641diff --git a/lib/dma-debug.c b/lib/dma-debug.c
74642index 5e396ac..58d5de1 100644
74643--- a/lib/dma-debug.c
74644+++ b/lib/dma-debug.c
74645@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
74646
74647 void dma_debug_add_bus(struct bus_type *bus)
74648 {
74649- struct notifier_block *nb;
74650+ notifier_block_no_const *nb;
74651
74652 if (global_disable)
74653 return;
74654@@ -942,7 +942,7 @@ out:
74655
74656 static void check_for_stack(struct device *dev, void *addr)
74657 {
74658- if (object_is_on_stack(addr))
74659+ if (object_starts_on_stack(addr))
74660 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
74661 "stack [addr=%p]\n", addr);
74662 }
74663diff --git a/lib/inflate.c b/lib/inflate.c
74664index 013a761..c28f3fc 100644
74665--- a/lib/inflate.c
74666+++ b/lib/inflate.c
74667@@ -269,7 +269,7 @@ static void free(void *where)
74668 malloc_ptr = free_mem_ptr;
74669 }
74670 #else
74671-#define malloc(a) kmalloc(a, GFP_KERNEL)
74672+#define malloc(a) kmalloc((a), GFP_KERNEL)
74673 #define free(a) kfree(a)
74674 #endif
74675
74676diff --git a/lib/ioremap.c b/lib/ioremap.c
74677index 0c9216c..863bd89 100644
74678--- a/lib/ioremap.c
74679+++ b/lib/ioremap.c
74680@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
74681 unsigned long next;
74682
74683 phys_addr -= addr;
74684- pmd = pmd_alloc(&init_mm, pud, addr);
74685+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
74686 if (!pmd)
74687 return -ENOMEM;
74688 do {
74689@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
74690 unsigned long next;
74691
74692 phys_addr -= addr;
74693- pud = pud_alloc(&init_mm, pgd, addr);
74694+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
74695 if (!pud)
74696 return -ENOMEM;
74697 do {
74698diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
74699index bd2bea9..6b3c95e 100644
74700--- a/lib/is_single_threaded.c
74701+++ b/lib/is_single_threaded.c
74702@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
74703 struct task_struct *p, *t;
74704 bool ret;
74705
74706+ if (!mm)
74707+ return true;
74708+
74709 if (atomic_read(&task->signal->live) != 1)
74710 return false;
74711
74712diff --git a/lib/list_debug.c b/lib/list_debug.c
74713index c24c2f7..3fc5da0 100644
74714--- a/lib/list_debug.c
74715+++ b/lib/list_debug.c
74716@@ -11,7 +11,9 @@
74717 #include <linux/bug.h>
74718 #include <linux/kernel.h>
74719 #include <linux/rculist.h>
74720+#include <linux/mm.h>
74721
74722+#ifdef CONFIG_DEBUG_LIST
74723 /*
74724 * Insert a new entry between two known consecutive entries.
74725 *
74726@@ -19,21 +21,32 @@
74727 * the prev/next entries already!
74728 */
74729
74730-void __list_add(struct list_head *new,
74731- struct list_head *prev,
74732- struct list_head *next)
74733+static bool __list_add_debug(struct list_head *new,
74734+ struct list_head *prev,
74735+ struct list_head *next)
74736 {
74737- WARN(next->prev != prev,
74738+ if (WARN(next->prev != prev,
74739 "list_add corruption. next->prev should be "
74740 "prev (%p), but was %p. (next=%p).\n",
74741- prev, next->prev, next);
74742- WARN(prev->next != next,
74743+ prev, next->prev, next) ||
74744+ WARN(prev->next != next,
74745 "list_add corruption. prev->next should be "
74746 "next (%p), but was %p. (prev=%p).\n",
74747- next, prev->next, prev);
74748- WARN(new == prev || new == next,
74749+ next, prev->next, prev) ||
74750+ WARN(new == prev || new == next,
74751 "list_add double add: new=%p, prev=%p, next=%p.\n",
74752- new, prev, next);
74753+ new, prev, next))
74754+ return false;
74755+ return true;
74756+}
74757+
74758+void __list_add(struct list_head *new,
74759+ struct list_head *prev,
74760+ struct list_head *next)
74761+{
74762+ if (!__list_add_debug(new, prev, next))
74763+ return;
74764+
74765 next->prev = new;
74766 new->next = next;
74767 new->prev = prev;
74768@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
74769 }
74770 EXPORT_SYMBOL(__list_add);
74771
74772-void __list_del_entry(struct list_head *entry)
74773+static bool __list_del_entry_debug(struct list_head *entry)
74774 {
74775 struct list_head *prev, *next;
74776
74777@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
74778 WARN(next->prev != entry,
74779 "list_del corruption. next->prev should be %p, "
74780 "but was %p\n", entry, next->prev))
74781+ return false;
74782+ return true;
74783+}
74784+
74785+void __list_del_entry(struct list_head *entry)
74786+{
74787+ if (!__list_del_entry_debug(entry))
74788 return;
74789
74790- __list_del(prev, next);
74791+ __list_del(entry->prev, entry->next);
74792 }
74793 EXPORT_SYMBOL(__list_del_entry);
74794
74795@@ -86,15 +106,54 @@ EXPORT_SYMBOL(list_del);
74796 void __list_add_rcu(struct list_head *new,
74797 struct list_head *prev, struct list_head *next)
74798 {
74799- WARN(next->prev != prev,
74800+ if (WARN(next->prev != prev,
74801 "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
74802- prev, next->prev, next);
74803- WARN(prev->next != next,
74804+ prev, next->prev, next) ||
74805+ WARN(prev->next != next,
74806 "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
74807- next, prev->next, prev);
74808+ next, prev->next, prev))
74809+ return;
74810+
74811 new->next = next;
74812 new->prev = prev;
74813 rcu_assign_pointer(list_next_rcu(prev), new);
74814 next->prev = new;
74815 }
74816 EXPORT_SYMBOL(__list_add_rcu);
74817+#endif
74818+
74819+void pax_list_add_tail(struct list_head *new, struct list_head *head)
74820+{
74821+ struct list_head *prev, *next;
74822+
74823+ prev = head->prev;
74824+ next = head;
74825+
74826+#ifdef CONFIG_DEBUG_LIST
74827+ if (!__list_add_debug(new, prev, next))
74828+ return;
74829+#endif
74830+
74831+ pax_open_kernel();
74832+ next->prev = new;
74833+ new->next = next;
74834+ new->prev = prev;
74835+ prev->next = new;
74836+ pax_close_kernel();
74837+}
74838+EXPORT_SYMBOL(pax_list_add_tail);
74839+
74840+void pax_list_del(struct list_head *entry)
74841+{
74842+#ifdef CONFIG_DEBUG_LIST
74843+ if (!__list_del_entry_debug(entry))
74844+ return;
74845+#endif
74846+
74847+ pax_open_kernel();
74848+ __list_del(entry->prev, entry->next);
74849+ entry->next = LIST_POISON1;
74850+ entry->prev = LIST_POISON2;
74851+ pax_close_kernel();
74852+}
74853+EXPORT_SYMBOL(pax_list_del);
74854diff --git a/lib/radix-tree.c b/lib/radix-tree.c
74855index e796429..6e38f9f 100644
74856--- a/lib/radix-tree.c
74857+++ b/lib/radix-tree.c
74858@@ -92,7 +92,7 @@ struct radix_tree_preload {
74859 int nr;
74860 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
74861 };
74862-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
74863+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
74864
74865 static inline void *ptr_to_indirect(void *ptr)
74866 {
74867diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
74868index bb2b201..46abaf9 100644
74869--- a/lib/strncpy_from_user.c
74870+++ b/lib/strncpy_from_user.c
74871@@ -21,7 +21,7 @@
74872 */
74873 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
74874 {
74875- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
74876+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
74877 long res = 0;
74878
74879 /*
74880diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
74881index a28df52..3d55877 100644
74882--- a/lib/strnlen_user.c
74883+++ b/lib/strnlen_user.c
74884@@ -26,7 +26,7 @@
74885 */
74886 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
74887 {
74888- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
74889+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
74890 long align, res = 0;
74891 unsigned long c;
74892
74893diff --git a/lib/vsprintf.c b/lib/vsprintf.c
74894index fab33a9..3b5fe68 100644
74895--- a/lib/vsprintf.c
74896+++ b/lib/vsprintf.c
74897@@ -16,6 +16,9 @@
74898 * - scnprintf and vscnprintf
74899 */
74900
74901+#ifdef CONFIG_GRKERNSEC_HIDESYM
74902+#define __INCLUDED_BY_HIDESYM 1
74903+#endif
74904 #include <stdarg.h>
74905 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
74906 #include <linux/types.h>
74907@@ -541,7 +544,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
74908 char sym[KSYM_SYMBOL_LEN];
74909 if (ext == 'B')
74910 sprint_backtrace(sym, value);
74911- else if (ext != 'f' && ext != 's')
74912+ else if (ext != 'f' && ext != 's' && ext != 'a')
74913 sprint_symbol(sym, value);
74914 else
74915 sprint_symbol_no_offset(sym, value);
74916@@ -974,7 +977,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
74917 return number(buf, end, *(const netdev_features_t *)addr, spec);
74918 }
74919
74920+#ifdef CONFIG_GRKERNSEC_HIDESYM
74921+int kptr_restrict __read_mostly = 2;
74922+#else
74923 int kptr_restrict __read_mostly;
74924+#endif
74925
74926 /*
74927 * Show a '%p' thing. A kernel extension is that the '%p' is followed
74928@@ -988,6 +995,8 @@ int kptr_restrict __read_mostly;
74929 * - 'S' For symbolic direct pointers with offset
74930 * - 's' For symbolic direct pointers without offset
74931 * - 'B' For backtraced symbolic direct pointers with offset
74932+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
74933+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
74934 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
74935 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
74936 * - 'M' For a 6-byte MAC address, it prints the address in the
74937@@ -1043,12 +1052,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
74938
74939 if (!ptr && *fmt != 'K') {
74940 /*
74941- * Print (null) with the same width as a pointer so it makes
74942+ * Print (nil) with the same width as a pointer so it makes
74943 * tabular output look nice.
74944 */
74945 if (spec.field_width == -1)
74946 spec.field_width = default_width;
74947- return string(buf, end, "(null)", spec);
74948+ return string(buf, end, "(nil)", spec);
74949 }
74950
74951 switch (*fmt) {
74952@@ -1058,6 +1067,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
74953 /* Fallthrough */
74954 case 'S':
74955 case 's':
74956+#ifdef CONFIG_GRKERNSEC_HIDESYM
74957+ break;
74958+#else
74959+ return symbol_string(buf, end, ptr, spec, *fmt);
74960+#endif
74961+ case 'A':
74962+ case 'a':
74963 case 'B':
74964 return symbol_string(buf, end, ptr, spec, *fmt);
74965 case 'R':
74966@@ -1098,6 +1114,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
74967 va_end(va);
74968 return buf;
74969 }
74970+ case 'P':
74971+ break;
74972 case 'K':
74973 /*
74974 * %pK cannot be used in IRQ context because its test
74975@@ -1121,6 +1139,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
74976 }
74977 break;
74978 }
74979+
74980+#ifdef CONFIG_GRKERNSEC_HIDESYM
74981+ /* 'P' = approved pointers to copy to userland,
74982+ as in the /proc/kallsyms case, as we make it display nothing
74983+ for non-root users, and the real contents for root users
74984+ Also ignore 'K' pointers, since we force their NULLing for non-root users
74985+ above
74986+ */
74987+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
74988+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
74989+ dump_stack();
74990+ ptr = NULL;
74991+ }
74992+#endif
74993+
74994 spec.flags |= SMALL;
74995 if (spec.field_width == -1) {
74996 spec.field_width = default_width;
74997@@ -1842,11 +1875,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
74998 typeof(type) value; \
74999 if (sizeof(type) == 8) { \
75000 args = PTR_ALIGN(args, sizeof(u32)); \
75001- *(u32 *)&value = *(u32 *)args; \
75002- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
75003+ *(u32 *)&value = *(const u32 *)args; \
75004+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
75005 } else { \
75006 args = PTR_ALIGN(args, sizeof(type)); \
75007- value = *(typeof(type) *)args; \
75008+ value = *(const typeof(type) *)args; \
75009 } \
75010 args += sizeof(type); \
75011 value; \
75012@@ -1909,7 +1942,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
75013 case FORMAT_TYPE_STR: {
75014 const char *str_arg = args;
75015 args += strlen(str_arg) + 1;
75016- str = string(str, end, (char *)str_arg, spec);
75017+ str = string(str, end, str_arg, spec);
75018 break;
75019 }
75020
75021diff --git a/localversion-grsec b/localversion-grsec
75022new file mode 100644
75023index 0000000..7cd6065
75024--- /dev/null
75025+++ b/localversion-grsec
75026@@ -0,0 +1 @@
75027+-grsec
75028diff --git a/mm/Kconfig b/mm/Kconfig
75029index 278e3ab..87c384d 100644
75030--- a/mm/Kconfig
75031+++ b/mm/Kconfig
75032@@ -286,10 +286,10 @@ config KSM
75033 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
75034
75035 config DEFAULT_MMAP_MIN_ADDR
75036- int "Low address space to protect from user allocation"
75037+ int "Low address space to protect from user allocation"
75038 depends on MMU
75039- default 4096
75040- help
75041+ default 65536
75042+ help
75043 This is the portion of low virtual memory which should be protected
75044 from userspace allocation. Keeping a user from writing to low pages
75045 can help reduce the impact of kernel NULL pointer bugs.
75046@@ -320,7 +320,7 @@ config MEMORY_FAILURE
75047
75048 config HWPOISON_INJECT
75049 tristate "HWPoison pages injector"
75050- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
75051+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
75052 select PROC_PAGE_MONITOR
75053
75054 config NOMMU_INITIAL_TRIM_EXCESS
75055diff --git a/mm/filemap.c b/mm/filemap.c
75056index 83efee7..3f99381 100644
75057--- a/mm/filemap.c
75058+++ b/mm/filemap.c
75059@@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
75060 struct address_space *mapping = file->f_mapping;
75061
75062 if (!mapping->a_ops->readpage)
75063- return -ENOEXEC;
75064+ return -ENODEV;
75065 file_accessed(file);
75066 vma->vm_ops = &generic_file_vm_ops;
75067 return 0;
75068@@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
75069 *pos = i_size_read(inode);
75070
75071 if (limit != RLIM_INFINITY) {
75072+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
75073 if (*pos >= limit) {
75074 send_sig(SIGXFSZ, current, 0);
75075 return -EFBIG;
75076diff --git a/mm/fremap.c b/mm/fremap.c
75077index a0aaf0e..20325c3 100644
75078--- a/mm/fremap.c
75079+++ b/mm/fremap.c
75080@@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
75081 retry:
75082 vma = find_vma(mm, start);
75083
75084+#ifdef CONFIG_PAX_SEGMEXEC
75085+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
75086+ goto out;
75087+#endif
75088+
75089 /*
75090 * Make sure the vma is shared, that it supports prefaulting,
75091 * and that the remapped range is valid and fully within
75092diff --git a/mm/highmem.c b/mm/highmem.c
75093index b32b70c..e512eb0 100644
75094--- a/mm/highmem.c
75095+++ b/mm/highmem.c
75096@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
75097 * So no dangers, even with speculative execution.
75098 */
75099 page = pte_page(pkmap_page_table[i]);
75100+ pax_open_kernel();
75101 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
75102-
75103+ pax_close_kernel();
75104 set_page_address(page, NULL);
75105 need_flush = 1;
75106 }
75107@@ -198,9 +199,11 @@ start:
75108 }
75109 }
75110 vaddr = PKMAP_ADDR(last_pkmap_nr);
75111+
75112+ pax_open_kernel();
75113 set_pte_at(&init_mm, vaddr,
75114 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
75115-
75116+ pax_close_kernel();
75117 pkmap_count[last_pkmap_nr] = 1;
75118 set_page_address(page, (void *)vaddr);
75119
75120diff --git a/mm/hugetlb.c b/mm/hugetlb.c
75121index 546db81..01d5c53 100644
75122--- a/mm/hugetlb.c
75123+++ b/mm/hugetlb.c
75124@@ -2511,6 +2511,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
75125 return 1;
75126 }
75127
75128+#ifdef CONFIG_PAX_SEGMEXEC
75129+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
75130+{
75131+ struct mm_struct *mm = vma->vm_mm;
75132+ struct vm_area_struct *vma_m;
75133+ unsigned long address_m;
75134+ pte_t *ptep_m;
75135+
75136+ vma_m = pax_find_mirror_vma(vma);
75137+ if (!vma_m)
75138+ return;
75139+
75140+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75141+ address_m = address + SEGMEXEC_TASK_SIZE;
75142+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
75143+ get_page(page_m);
75144+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
75145+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
75146+}
75147+#endif
75148+
75149 /*
75150 * Hugetlb_cow() should be called with page lock of the original hugepage held.
75151 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
75152@@ -2629,6 +2650,11 @@ retry_avoidcopy:
75153 make_huge_pte(vma, new_page, 1));
75154 page_remove_rmap(old_page);
75155 hugepage_add_new_anon_rmap(new_page, vma, address);
75156+
75157+#ifdef CONFIG_PAX_SEGMEXEC
75158+ pax_mirror_huge_pte(vma, address, new_page);
75159+#endif
75160+
75161 /* Make the old page be freed below */
75162 new_page = old_page;
75163 }
75164@@ -2788,6 +2814,10 @@ retry:
75165 && (vma->vm_flags & VM_SHARED)));
75166 set_huge_pte_at(mm, address, ptep, new_pte);
75167
75168+#ifdef CONFIG_PAX_SEGMEXEC
75169+ pax_mirror_huge_pte(vma, address, page);
75170+#endif
75171+
75172 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
75173 /* Optimization, do the COW without a second fault */
75174 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
75175@@ -2817,6 +2847,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75176 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
75177 struct hstate *h = hstate_vma(vma);
75178
75179+#ifdef CONFIG_PAX_SEGMEXEC
75180+ struct vm_area_struct *vma_m;
75181+#endif
75182+
75183 address &= huge_page_mask(h);
75184
75185 ptep = huge_pte_offset(mm, address);
75186@@ -2830,6 +2864,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75187 VM_FAULT_SET_HINDEX(hstate_index(h));
75188 }
75189
75190+#ifdef CONFIG_PAX_SEGMEXEC
75191+ vma_m = pax_find_mirror_vma(vma);
75192+ if (vma_m) {
75193+ unsigned long address_m;
75194+
75195+ if (vma->vm_start > vma_m->vm_start) {
75196+ address_m = address;
75197+ address -= SEGMEXEC_TASK_SIZE;
75198+ vma = vma_m;
75199+ h = hstate_vma(vma);
75200+ } else
75201+ address_m = address + SEGMEXEC_TASK_SIZE;
75202+
75203+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
75204+ return VM_FAULT_OOM;
75205+ address_m &= HPAGE_MASK;
75206+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
75207+ }
75208+#endif
75209+
75210 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
75211 if (!ptep)
75212 return VM_FAULT_OOM;
75213diff --git a/mm/internal.h b/mm/internal.h
75214index 9ba2110..eaf0674 100644
75215--- a/mm/internal.h
75216+++ b/mm/internal.h
75217@@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
75218 * in mm/page_alloc.c
75219 */
75220 extern void __free_pages_bootmem(struct page *page, unsigned int order);
75221+extern void free_compound_page(struct page *page);
75222 extern void prep_compound_page(struct page *page, unsigned long order);
75223 #ifdef CONFIG_MEMORY_FAILURE
75224 extern bool is_free_buddy_page(struct page *page);
75225diff --git a/mm/kmemleak.c b/mm/kmemleak.c
75226index 752a705..6c3102e 100644
75227--- a/mm/kmemleak.c
75228+++ b/mm/kmemleak.c
75229@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
75230
75231 for (i = 0; i < object->trace_len; i++) {
75232 void *ptr = (void *)object->trace[i];
75233- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
75234+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
75235 }
75236 }
75237
75238@@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
75239 return -ENOMEM;
75240 }
75241
75242- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
75243+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
75244 &kmemleak_fops);
75245 if (!dentry)
75246 pr_warning("Failed to create the debugfs kmemleak file\n");
75247diff --git a/mm/maccess.c b/mm/maccess.c
75248index d53adf9..03a24bf 100644
75249--- a/mm/maccess.c
75250+++ b/mm/maccess.c
75251@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
75252 set_fs(KERNEL_DS);
75253 pagefault_disable();
75254 ret = __copy_from_user_inatomic(dst,
75255- (__force const void __user *)src, size);
75256+ (const void __force_user *)src, size);
75257 pagefault_enable();
75258 set_fs(old_fs);
75259
75260@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
75261
75262 set_fs(KERNEL_DS);
75263 pagefault_disable();
75264- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
75265+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
75266 pagefault_enable();
75267 set_fs(old_fs);
75268
75269diff --git a/mm/madvise.c b/mm/madvise.c
75270index 03dfa5c..b032917 100644
75271--- a/mm/madvise.c
75272+++ b/mm/madvise.c
75273@@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
75274 pgoff_t pgoff;
75275 unsigned long new_flags = vma->vm_flags;
75276
75277+#ifdef CONFIG_PAX_SEGMEXEC
75278+ struct vm_area_struct *vma_m;
75279+#endif
75280+
75281 switch (behavior) {
75282 case MADV_NORMAL:
75283 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
75284@@ -123,6 +127,13 @@ success:
75285 /*
75286 * vm_flags is protected by the mmap_sem held in write mode.
75287 */
75288+
75289+#ifdef CONFIG_PAX_SEGMEXEC
75290+ vma_m = pax_find_mirror_vma(vma);
75291+ if (vma_m)
75292+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
75293+#endif
75294+
75295 vma->vm_flags = new_flags;
75296
75297 out:
75298@@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
75299 struct vm_area_struct ** prev,
75300 unsigned long start, unsigned long end)
75301 {
75302+
75303+#ifdef CONFIG_PAX_SEGMEXEC
75304+ struct vm_area_struct *vma_m;
75305+#endif
75306+
75307 *prev = vma;
75308 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
75309 return -EINVAL;
75310@@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
75311 zap_page_range(vma, start, end - start, &details);
75312 } else
75313 zap_page_range(vma, start, end - start, NULL);
75314+
75315+#ifdef CONFIG_PAX_SEGMEXEC
75316+ vma_m = pax_find_mirror_vma(vma);
75317+ if (vma_m) {
75318+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
75319+ struct zap_details details = {
75320+ .nonlinear_vma = vma_m,
75321+ .last_index = ULONG_MAX,
75322+ };
75323+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
75324+ } else
75325+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
75326+ }
75327+#endif
75328+
75329 return 0;
75330 }
75331
75332@@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
75333 if (end < start)
75334 goto out;
75335
75336+#ifdef CONFIG_PAX_SEGMEXEC
75337+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
75338+ if (end > SEGMEXEC_TASK_SIZE)
75339+ goto out;
75340+ } else
75341+#endif
75342+
75343+ if (end > TASK_SIZE)
75344+ goto out;
75345+
75346 error = 0;
75347 if (end == start)
75348 goto out;
75349diff --git a/mm/memory-failure.c b/mm/memory-failure.c
75350index c6e4dd3..fdb2ca6 100644
75351--- a/mm/memory-failure.c
75352+++ b/mm/memory-failure.c
75353@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
75354
75355 int sysctl_memory_failure_recovery __read_mostly = 1;
75356
75357-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
75358+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
75359
75360 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
75361
75362@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
75363 pfn, t->comm, t->pid);
75364 si.si_signo = SIGBUS;
75365 si.si_errno = 0;
75366- si.si_addr = (void *)addr;
75367+ si.si_addr = (void __user *)addr;
75368 #ifdef __ARCH_SI_TRAPNO
75369 si.si_trapno = trapno;
75370 #endif
75371@@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
75372 }
75373
75374 nr_pages = 1 << compound_trans_order(hpage);
75375- atomic_long_add(nr_pages, &mce_bad_pages);
75376+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
75377
75378 /*
75379 * We need/can do nothing about count=0 pages.
75380@@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
75381 if (!PageHWPoison(hpage)
75382 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
75383 || (p != hpage && TestSetPageHWPoison(hpage))) {
75384- atomic_long_sub(nr_pages, &mce_bad_pages);
75385+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
75386 return 0;
75387 }
75388 set_page_hwpoison_huge_page(hpage);
75389@@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
75390 }
75391 if (hwpoison_filter(p)) {
75392 if (TestClearPageHWPoison(p))
75393- atomic_long_sub(nr_pages, &mce_bad_pages);
75394+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
75395 unlock_page(hpage);
75396 put_page(hpage);
75397 return 0;
75398@@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
75399 return 0;
75400 }
75401 if (TestClearPageHWPoison(p))
75402- atomic_long_sub(nr_pages, &mce_bad_pages);
75403+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
75404 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
75405 return 0;
75406 }
75407@@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
75408 */
75409 if (TestClearPageHWPoison(page)) {
75410 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
75411- atomic_long_sub(nr_pages, &mce_bad_pages);
75412+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
75413 freeit = 1;
75414 if (PageHuge(page))
75415 clear_page_hwpoison_huge_page(page);
75416@@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
75417 }
75418 done:
75419 if (!PageHWPoison(hpage))
75420- atomic_long_add(1 << compound_trans_order(hpage),
75421+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
75422 &mce_bad_pages);
75423 set_page_hwpoison_huge_page(hpage);
75424 dequeue_hwpoisoned_huge_page(hpage);
75425@@ -1583,7 +1583,7 @@ int soft_offline_page(struct page *page, int flags)
75426 return ret;
75427
75428 done:
75429- atomic_long_add(1, &mce_bad_pages);
75430+ atomic_long_add_unchecked(1, &mce_bad_pages);
75431 SetPageHWPoison(page);
75432 /* keep elevated page count for bad page */
75433 return ret;
75434diff --git a/mm/memory.c b/mm/memory.c
75435index bb1369f..efb96b5 100644
75436--- a/mm/memory.c
75437+++ b/mm/memory.c
75438@@ -433,6 +433,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
75439 free_pte_range(tlb, pmd, addr);
75440 } while (pmd++, addr = next, addr != end);
75441
75442+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
75443 start &= PUD_MASK;
75444 if (start < floor)
75445 return;
75446@@ -447,6 +448,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
75447 pmd = pmd_offset(pud, start);
75448 pud_clear(pud);
75449 pmd_free_tlb(tlb, pmd, start);
75450+#endif
75451+
75452 }
75453
75454 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
75455@@ -466,6 +469,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
75456 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
75457 } while (pud++, addr = next, addr != end);
75458
75459+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
75460 start &= PGDIR_MASK;
75461 if (start < floor)
75462 return;
75463@@ -480,6 +484,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
75464 pud = pud_offset(pgd, start);
75465 pgd_clear(pgd);
75466 pud_free_tlb(tlb, pud, start);
75467+#endif
75468+
75469 }
75470
75471 /*
75472@@ -1618,12 +1624,6 @@ no_page_table:
75473 return page;
75474 }
75475
75476-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
75477-{
75478- return stack_guard_page_start(vma, addr) ||
75479- stack_guard_page_end(vma, addr+PAGE_SIZE);
75480-}
75481-
75482 /**
75483 * __get_user_pages() - pin user pages in memory
75484 * @tsk: task_struct of target task
75485@@ -1709,10 +1709,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75486
75487 i = 0;
75488
75489- do {
75490+ while (nr_pages) {
75491 struct vm_area_struct *vma;
75492
75493- vma = find_extend_vma(mm, start);
75494+ vma = find_vma(mm, start);
75495 if (!vma && in_gate_area(mm, start)) {
75496 unsigned long pg = start & PAGE_MASK;
75497 pgd_t *pgd;
75498@@ -1760,7 +1760,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75499 goto next_page;
75500 }
75501
75502- if (!vma ||
75503+ if (!vma || start < vma->vm_start ||
75504 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
75505 !(vm_flags & vma->vm_flags))
75506 return i ? : -EFAULT;
75507@@ -1787,11 +1787,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75508 int ret;
75509 unsigned int fault_flags = 0;
75510
75511- /* For mlock, just skip the stack guard page. */
75512- if (foll_flags & FOLL_MLOCK) {
75513- if (stack_guard_page(vma, start))
75514- goto next_page;
75515- }
75516 if (foll_flags & FOLL_WRITE)
75517 fault_flags |= FAULT_FLAG_WRITE;
75518 if (nonblocking)
75519@@ -1865,7 +1860,7 @@ next_page:
75520 start += PAGE_SIZE;
75521 nr_pages--;
75522 } while (nr_pages && start < vma->vm_end);
75523- } while (nr_pages);
75524+ }
75525 return i;
75526 }
75527 EXPORT_SYMBOL(__get_user_pages);
75528@@ -2072,6 +2067,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
75529 page_add_file_rmap(page);
75530 set_pte_at(mm, addr, pte, mk_pte(page, prot));
75531
75532+#ifdef CONFIG_PAX_SEGMEXEC
75533+ pax_mirror_file_pte(vma, addr, page, ptl);
75534+#endif
75535+
75536 retval = 0;
75537 pte_unmap_unlock(pte, ptl);
75538 return retval;
75539@@ -2116,9 +2115,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
75540 if (!page_count(page))
75541 return -EINVAL;
75542 if (!(vma->vm_flags & VM_MIXEDMAP)) {
75543+
75544+#ifdef CONFIG_PAX_SEGMEXEC
75545+ struct vm_area_struct *vma_m;
75546+#endif
75547+
75548 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
75549 BUG_ON(vma->vm_flags & VM_PFNMAP);
75550 vma->vm_flags |= VM_MIXEDMAP;
75551+
75552+#ifdef CONFIG_PAX_SEGMEXEC
75553+ vma_m = pax_find_mirror_vma(vma);
75554+ if (vma_m)
75555+ vma_m->vm_flags |= VM_MIXEDMAP;
75556+#endif
75557+
75558 }
75559 return insert_page(vma, addr, page, vma->vm_page_prot);
75560 }
75561@@ -2201,6 +2212,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
75562 unsigned long pfn)
75563 {
75564 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
75565+ BUG_ON(vma->vm_mirror);
75566
75567 if (addr < vma->vm_start || addr >= vma->vm_end)
75568 return -EFAULT;
75569@@ -2401,7 +2413,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
75570
75571 BUG_ON(pud_huge(*pud));
75572
75573- pmd = pmd_alloc(mm, pud, addr);
75574+ pmd = (mm == &init_mm) ?
75575+ pmd_alloc_kernel(mm, pud, addr) :
75576+ pmd_alloc(mm, pud, addr);
75577 if (!pmd)
75578 return -ENOMEM;
75579 do {
75580@@ -2421,7 +2435,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
75581 unsigned long next;
75582 int err;
75583
75584- pud = pud_alloc(mm, pgd, addr);
75585+ pud = (mm == &init_mm) ?
75586+ pud_alloc_kernel(mm, pgd, addr) :
75587+ pud_alloc(mm, pgd, addr);
75588 if (!pud)
75589 return -ENOMEM;
75590 do {
75591@@ -2509,6 +2525,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
75592 copy_user_highpage(dst, src, va, vma);
75593 }
75594
75595+#ifdef CONFIG_PAX_SEGMEXEC
75596+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
75597+{
75598+ struct mm_struct *mm = vma->vm_mm;
75599+ spinlock_t *ptl;
75600+ pte_t *pte, entry;
75601+
75602+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
75603+ entry = *pte;
75604+ if (!pte_present(entry)) {
75605+ if (!pte_none(entry)) {
75606+ BUG_ON(pte_file(entry));
75607+ free_swap_and_cache(pte_to_swp_entry(entry));
75608+ pte_clear_not_present_full(mm, address, pte, 0);
75609+ }
75610+ } else {
75611+ struct page *page;
75612+
75613+ flush_cache_page(vma, address, pte_pfn(entry));
75614+ entry = ptep_clear_flush(vma, address, pte);
75615+ BUG_ON(pte_dirty(entry));
75616+ page = vm_normal_page(vma, address, entry);
75617+ if (page) {
75618+ update_hiwater_rss(mm);
75619+ if (PageAnon(page))
75620+ dec_mm_counter_fast(mm, MM_ANONPAGES);
75621+ else
75622+ dec_mm_counter_fast(mm, MM_FILEPAGES);
75623+ page_remove_rmap(page);
75624+ page_cache_release(page);
75625+ }
75626+ }
75627+ pte_unmap_unlock(pte, ptl);
75628+}
75629+
75630+/* PaX: if vma is mirrored, synchronize the mirror's PTE
75631+ *
75632+ * the ptl of the lower mapped page is held on entry and is not released on exit
75633+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
75634+ */
75635+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
75636+{
75637+ struct mm_struct *mm = vma->vm_mm;
75638+ unsigned long address_m;
75639+ spinlock_t *ptl_m;
75640+ struct vm_area_struct *vma_m;
75641+ pmd_t *pmd_m;
75642+ pte_t *pte_m, entry_m;
75643+
75644+ BUG_ON(!page_m || !PageAnon(page_m));
75645+
75646+ vma_m = pax_find_mirror_vma(vma);
75647+ if (!vma_m)
75648+ return;
75649+
75650+ BUG_ON(!PageLocked(page_m));
75651+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75652+ address_m = address + SEGMEXEC_TASK_SIZE;
75653+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
75654+ pte_m = pte_offset_map(pmd_m, address_m);
75655+ ptl_m = pte_lockptr(mm, pmd_m);
75656+ if (ptl != ptl_m) {
75657+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
75658+ if (!pte_none(*pte_m))
75659+ goto out;
75660+ }
75661+
75662+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
75663+ page_cache_get(page_m);
75664+ page_add_anon_rmap(page_m, vma_m, address_m);
75665+ inc_mm_counter_fast(mm, MM_ANONPAGES);
75666+ set_pte_at(mm, address_m, pte_m, entry_m);
75667+ update_mmu_cache(vma_m, address_m, entry_m);
75668+out:
75669+ if (ptl != ptl_m)
75670+ spin_unlock(ptl_m);
75671+ pte_unmap(pte_m);
75672+ unlock_page(page_m);
75673+}
75674+
75675+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
75676+{
75677+ struct mm_struct *mm = vma->vm_mm;
75678+ unsigned long address_m;
75679+ spinlock_t *ptl_m;
75680+ struct vm_area_struct *vma_m;
75681+ pmd_t *pmd_m;
75682+ pte_t *pte_m, entry_m;
75683+
75684+ BUG_ON(!page_m || PageAnon(page_m));
75685+
75686+ vma_m = pax_find_mirror_vma(vma);
75687+ if (!vma_m)
75688+ return;
75689+
75690+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75691+ address_m = address + SEGMEXEC_TASK_SIZE;
75692+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
75693+ pte_m = pte_offset_map(pmd_m, address_m);
75694+ ptl_m = pte_lockptr(mm, pmd_m);
75695+ if (ptl != ptl_m) {
75696+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
75697+ if (!pte_none(*pte_m))
75698+ goto out;
75699+ }
75700+
75701+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
75702+ page_cache_get(page_m);
75703+ page_add_file_rmap(page_m);
75704+ inc_mm_counter_fast(mm, MM_FILEPAGES);
75705+ set_pte_at(mm, address_m, pte_m, entry_m);
75706+ update_mmu_cache(vma_m, address_m, entry_m);
75707+out:
75708+ if (ptl != ptl_m)
75709+ spin_unlock(ptl_m);
75710+ pte_unmap(pte_m);
75711+}
75712+
75713+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
75714+{
75715+ struct mm_struct *mm = vma->vm_mm;
75716+ unsigned long address_m;
75717+ spinlock_t *ptl_m;
75718+ struct vm_area_struct *vma_m;
75719+ pmd_t *pmd_m;
75720+ pte_t *pte_m, entry_m;
75721+
75722+ vma_m = pax_find_mirror_vma(vma);
75723+ if (!vma_m)
75724+ return;
75725+
75726+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75727+ address_m = address + SEGMEXEC_TASK_SIZE;
75728+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
75729+ pte_m = pte_offset_map(pmd_m, address_m);
75730+ ptl_m = pte_lockptr(mm, pmd_m);
75731+ if (ptl != ptl_m) {
75732+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
75733+ if (!pte_none(*pte_m))
75734+ goto out;
75735+ }
75736+
75737+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
75738+ set_pte_at(mm, address_m, pte_m, entry_m);
75739+out:
75740+ if (ptl != ptl_m)
75741+ spin_unlock(ptl_m);
75742+ pte_unmap(pte_m);
75743+}
75744+
75745+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
75746+{
75747+ struct page *page_m;
75748+ pte_t entry;
75749+
75750+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
75751+ goto out;
75752+
75753+ entry = *pte;
75754+ page_m = vm_normal_page(vma, address, entry);
75755+ if (!page_m)
75756+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
75757+ else if (PageAnon(page_m)) {
75758+ if (pax_find_mirror_vma(vma)) {
75759+ pte_unmap_unlock(pte, ptl);
75760+ lock_page(page_m);
75761+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
75762+ if (pte_same(entry, *pte))
75763+ pax_mirror_anon_pte(vma, address, page_m, ptl);
75764+ else
75765+ unlock_page(page_m);
75766+ }
75767+ } else
75768+ pax_mirror_file_pte(vma, address, page_m, ptl);
75769+
75770+out:
75771+ pte_unmap_unlock(pte, ptl);
75772+}
75773+#endif
75774+
75775 /*
75776 * This routine handles present pages, when users try to write
75777 * to a shared page. It is done by copying the page to a new address
75778@@ -2725,6 +2921,12 @@ gotten:
75779 */
75780 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
75781 if (likely(pte_same(*page_table, orig_pte))) {
75782+
75783+#ifdef CONFIG_PAX_SEGMEXEC
75784+ if (pax_find_mirror_vma(vma))
75785+ BUG_ON(!trylock_page(new_page));
75786+#endif
75787+
75788 if (old_page) {
75789 if (!PageAnon(old_page)) {
75790 dec_mm_counter_fast(mm, MM_FILEPAGES);
75791@@ -2776,6 +2978,10 @@ gotten:
75792 page_remove_rmap(old_page);
75793 }
75794
75795+#ifdef CONFIG_PAX_SEGMEXEC
75796+ pax_mirror_anon_pte(vma, address, new_page, ptl);
75797+#endif
75798+
75799 /* Free the old page.. */
75800 new_page = old_page;
75801 ret |= VM_FAULT_WRITE;
75802@@ -3051,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
75803 swap_free(entry);
75804 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
75805 try_to_free_swap(page);
75806+
75807+#ifdef CONFIG_PAX_SEGMEXEC
75808+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
75809+#endif
75810+
75811 unlock_page(page);
75812 if (swapcache) {
75813 /*
75814@@ -3074,6 +3285,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
75815
75816 /* No need to invalidate - it was non-present before */
75817 update_mmu_cache(vma, address, page_table);
75818+
75819+#ifdef CONFIG_PAX_SEGMEXEC
75820+ pax_mirror_anon_pte(vma, address, page, ptl);
75821+#endif
75822+
75823 unlock:
75824 pte_unmap_unlock(page_table, ptl);
75825 out:
75826@@ -3093,40 +3309,6 @@ out_release:
75827 }
75828
75829 /*
75830- * This is like a special single-page "expand_{down|up}wards()",
75831- * except we must first make sure that 'address{-|+}PAGE_SIZE'
75832- * doesn't hit another vma.
75833- */
75834-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
75835-{
75836- address &= PAGE_MASK;
75837- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
75838- struct vm_area_struct *prev = vma->vm_prev;
75839-
75840- /*
75841- * Is there a mapping abutting this one below?
75842- *
75843- * That's only ok if it's the same stack mapping
75844- * that has gotten split..
75845- */
75846- if (prev && prev->vm_end == address)
75847- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
75848-
75849- expand_downwards(vma, address - PAGE_SIZE);
75850- }
75851- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
75852- struct vm_area_struct *next = vma->vm_next;
75853-
75854- /* As VM_GROWSDOWN but s/below/above/ */
75855- if (next && next->vm_start == address + PAGE_SIZE)
75856- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
75857-
75858- expand_upwards(vma, address + PAGE_SIZE);
75859- }
75860- return 0;
75861-}
75862-
75863-/*
75864 * We enter with non-exclusive mmap_sem (to exclude vma changes,
75865 * but allow concurrent faults), and pte mapped but not yet locked.
75866 * We return with mmap_sem still held, but pte unmapped and unlocked.
75867@@ -3135,27 +3317,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
75868 unsigned long address, pte_t *page_table, pmd_t *pmd,
75869 unsigned int flags)
75870 {
75871- struct page *page;
75872+ struct page *page = NULL;
75873 spinlock_t *ptl;
75874 pte_t entry;
75875
75876- pte_unmap(page_table);
75877-
75878- /* Check if we need to add a guard page to the stack */
75879- if (check_stack_guard_page(vma, address) < 0)
75880- return VM_FAULT_SIGBUS;
75881-
75882- /* Use the zero-page for reads */
75883 if (!(flags & FAULT_FLAG_WRITE)) {
75884 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
75885 vma->vm_page_prot));
75886- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
75887+ ptl = pte_lockptr(mm, pmd);
75888+ spin_lock(ptl);
75889 if (!pte_none(*page_table))
75890 goto unlock;
75891 goto setpte;
75892 }
75893
75894 /* Allocate our own private page. */
75895+ pte_unmap(page_table);
75896+
75897 if (unlikely(anon_vma_prepare(vma)))
75898 goto oom;
75899 page = alloc_zeroed_user_highpage_movable(vma, address);
75900@@ -3174,6 +3352,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
75901 if (!pte_none(*page_table))
75902 goto release;
75903
75904+#ifdef CONFIG_PAX_SEGMEXEC
75905+ if (pax_find_mirror_vma(vma))
75906+ BUG_ON(!trylock_page(page));
75907+#endif
75908+
75909 inc_mm_counter_fast(mm, MM_ANONPAGES);
75910 page_add_new_anon_rmap(page, vma, address);
75911 setpte:
75912@@ -3181,6 +3364,12 @@ setpte:
75913
75914 /* No need to invalidate - it was non-present before */
75915 update_mmu_cache(vma, address, page_table);
75916+
75917+#ifdef CONFIG_PAX_SEGMEXEC
75918+ if (page)
75919+ pax_mirror_anon_pte(vma, address, page, ptl);
75920+#endif
75921+
75922 unlock:
75923 pte_unmap_unlock(page_table, ptl);
75924 return 0;
75925@@ -3324,6 +3513,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75926 */
75927 /* Only go through if we didn't race with anybody else... */
75928 if (likely(pte_same(*page_table, orig_pte))) {
75929+
75930+#ifdef CONFIG_PAX_SEGMEXEC
75931+ if (anon && pax_find_mirror_vma(vma))
75932+ BUG_ON(!trylock_page(page));
75933+#endif
75934+
75935 flush_icache_page(vma, page);
75936 entry = mk_pte(page, vma->vm_page_prot);
75937 if (flags & FAULT_FLAG_WRITE)
75938@@ -3343,6 +3538,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75939
75940 /* no need to invalidate: a not-present page won't be cached */
75941 update_mmu_cache(vma, address, page_table);
75942+
75943+#ifdef CONFIG_PAX_SEGMEXEC
75944+ if (anon)
75945+ pax_mirror_anon_pte(vma, address, page, ptl);
75946+ else
75947+ pax_mirror_file_pte(vma, address, page, ptl);
75948+#endif
75949+
75950 } else {
75951 if (cow_page)
75952 mem_cgroup_uncharge_page(cow_page);
75953@@ -3664,6 +3867,12 @@ int handle_pte_fault(struct mm_struct *mm,
75954 if (flags & FAULT_FLAG_WRITE)
75955 flush_tlb_fix_spurious_fault(vma, address);
75956 }
75957+
75958+#ifdef CONFIG_PAX_SEGMEXEC
75959+ pax_mirror_pte(vma, address, pte, pmd, ptl);
75960+ return 0;
75961+#endif
75962+
75963 unlock:
75964 pte_unmap_unlock(pte, ptl);
75965 return 0;
75966@@ -3680,6 +3889,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75967 pmd_t *pmd;
75968 pte_t *pte;
75969
75970+#ifdef CONFIG_PAX_SEGMEXEC
75971+ struct vm_area_struct *vma_m;
75972+#endif
75973+
75974 __set_current_state(TASK_RUNNING);
75975
75976 count_vm_event(PGFAULT);
75977@@ -3691,6 +3904,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75978 if (unlikely(is_vm_hugetlb_page(vma)))
75979 return hugetlb_fault(mm, vma, address, flags);
75980
75981+#ifdef CONFIG_PAX_SEGMEXEC
75982+ vma_m = pax_find_mirror_vma(vma);
75983+ if (vma_m) {
75984+ unsigned long address_m;
75985+ pgd_t *pgd_m;
75986+ pud_t *pud_m;
75987+ pmd_t *pmd_m;
75988+
75989+ if (vma->vm_start > vma_m->vm_start) {
75990+ address_m = address;
75991+ address -= SEGMEXEC_TASK_SIZE;
75992+ vma = vma_m;
75993+ } else
75994+ address_m = address + SEGMEXEC_TASK_SIZE;
75995+
75996+ pgd_m = pgd_offset(mm, address_m);
75997+ pud_m = pud_alloc(mm, pgd_m, address_m);
75998+ if (!pud_m)
75999+ return VM_FAULT_OOM;
76000+ pmd_m = pmd_alloc(mm, pud_m, address_m);
76001+ if (!pmd_m)
76002+ return VM_FAULT_OOM;
76003+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
76004+ return VM_FAULT_OOM;
76005+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
76006+ }
76007+#endif
76008+
76009 retry:
76010 pgd = pgd_offset(mm, address);
76011 pud = pud_alloc(mm, pgd, address);
76012@@ -3789,6 +4030,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
76013 spin_unlock(&mm->page_table_lock);
76014 return 0;
76015 }
76016+
76017+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
76018+{
76019+ pud_t *new = pud_alloc_one(mm, address);
76020+ if (!new)
76021+ return -ENOMEM;
76022+
76023+ smp_wmb(); /* See comment in __pte_alloc */
76024+
76025+ spin_lock(&mm->page_table_lock);
76026+ if (pgd_present(*pgd)) /* Another has populated it */
76027+ pud_free(mm, new);
76028+ else
76029+ pgd_populate_kernel(mm, pgd, new);
76030+ spin_unlock(&mm->page_table_lock);
76031+ return 0;
76032+}
76033 #endif /* __PAGETABLE_PUD_FOLDED */
76034
76035 #ifndef __PAGETABLE_PMD_FOLDED
76036@@ -3819,6 +4077,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
76037 spin_unlock(&mm->page_table_lock);
76038 return 0;
76039 }
76040+
76041+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
76042+{
76043+ pmd_t *new = pmd_alloc_one(mm, address);
76044+ if (!new)
76045+ return -ENOMEM;
76046+
76047+ smp_wmb(); /* See comment in __pte_alloc */
76048+
76049+ spin_lock(&mm->page_table_lock);
76050+#ifndef __ARCH_HAS_4LEVEL_HACK
76051+ if (pud_present(*pud)) /* Another has populated it */
76052+ pmd_free(mm, new);
76053+ else
76054+ pud_populate_kernel(mm, pud, new);
76055+#else
76056+ if (pgd_present(*pud)) /* Another has populated it */
76057+ pmd_free(mm, new);
76058+ else
76059+ pgd_populate_kernel(mm, pud, new);
76060+#endif /* __ARCH_HAS_4LEVEL_HACK */
76061+ spin_unlock(&mm->page_table_lock);
76062+ return 0;
76063+}
76064 #endif /* __PAGETABLE_PMD_FOLDED */
76065
76066 int make_pages_present(unsigned long addr, unsigned long end)
76067@@ -3856,7 +4138,7 @@ static int __init gate_vma_init(void)
76068 gate_vma.vm_start = FIXADDR_USER_START;
76069 gate_vma.vm_end = FIXADDR_USER_END;
76070 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
76071- gate_vma.vm_page_prot = __P101;
76072+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
76073
76074 return 0;
76075 }
76076diff --git a/mm/mempolicy.c b/mm/mempolicy.c
76077index e2df1c1..1e31d57 100644
76078--- a/mm/mempolicy.c
76079+++ b/mm/mempolicy.c
76080@@ -721,6 +721,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
76081 unsigned long vmstart;
76082 unsigned long vmend;
76083
76084+#ifdef CONFIG_PAX_SEGMEXEC
76085+ struct vm_area_struct *vma_m;
76086+#endif
76087+
76088 vma = find_vma(mm, start);
76089 if (!vma || vma->vm_start > start)
76090 return -EFAULT;
76091@@ -757,9 +761,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
76092 if (err)
76093 goto out;
76094 }
76095+
76096 err = vma_replace_policy(vma, new_pol);
76097 if (err)
76098 goto out;
76099+
76100+#ifdef CONFIG_PAX_SEGMEXEC
76101+ vma_m = pax_find_mirror_vma(vma);
76102+ if (vma_m) {
76103+ err = vma_replace_policy(vma_m, new_pol);
76104+ if (err)
76105+ goto out;
76106+ }
76107+#endif
76108+
76109 }
76110
76111 out:
76112@@ -1216,6 +1231,17 @@ static long do_mbind(unsigned long start, unsigned long len,
76113
76114 if (end < start)
76115 return -EINVAL;
76116+
76117+#ifdef CONFIG_PAX_SEGMEXEC
76118+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
76119+ if (end > SEGMEXEC_TASK_SIZE)
76120+ return -EINVAL;
76121+ } else
76122+#endif
76123+
76124+ if (end > TASK_SIZE)
76125+ return -EINVAL;
76126+
76127 if (end == start)
76128 return 0;
76129
76130@@ -1445,8 +1471,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
76131 */
76132 tcred = __task_cred(task);
76133 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
76134- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
76135- !capable(CAP_SYS_NICE)) {
76136+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
76137 rcu_read_unlock();
76138 err = -EPERM;
76139 goto out_put;
76140@@ -1477,6 +1502,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
76141 goto out;
76142 }
76143
76144+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76145+ if (mm != current->mm &&
76146+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
76147+ mmput(mm);
76148+ err = -EPERM;
76149+ goto out;
76150+ }
76151+#endif
76152+
76153 err = do_migrate_pages(mm, old, new,
76154 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
76155
76156diff --git a/mm/migrate.c b/mm/migrate.c
76157index 2fd8b4a..d70358f 100644
76158--- a/mm/migrate.c
76159+++ b/mm/migrate.c
76160@@ -1401,8 +1401,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
76161 */
76162 tcred = __task_cred(task);
76163 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
76164- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
76165- !capable(CAP_SYS_NICE)) {
76166+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
76167 rcu_read_unlock();
76168 err = -EPERM;
76169 goto out;
76170diff --git a/mm/mlock.c b/mm/mlock.c
76171index c9bd528..da8d069 100644
76172--- a/mm/mlock.c
76173+++ b/mm/mlock.c
76174@@ -13,6 +13,7 @@
76175 #include <linux/pagemap.h>
76176 #include <linux/mempolicy.h>
76177 #include <linux/syscalls.h>
76178+#include <linux/security.h>
76179 #include <linux/sched.h>
76180 #include <linux/export.h>
76181 #include <linux/rmap.h>
76182@@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
76183 {
76184 unsigned long nstart, end, tmp;
76185 struct vm_area_struct * vma, * prev;
76186- int error;
76187+ int error = 0;
76188
76189 VM_BUG_ON(start & ~PAGE_MASK);
76190 VM_BUG_ON(len != PAGE_ALIGN(len));
76191@@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
76192 return -EINVAL;
76193 if (end == start)
76194 return 0;
76195+ if (end > TASK_SIZE)
76196+ return -EINVAL;
76197+
76198 vma = find_vma(current->mm, start);
76199 if (!vma || vma->vm_start > start)
76200 return -ENOMEM;
76201@@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
76202 for (nstart = start ; ; ) {
76203 vm_flags_t newflags;
76204
76205+#ifdef CONFIG_PAX_SEGMEXEC
76206+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
76207+ break;
76208+#endif
76209+
76210 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
76211
76212 newflags = vma->vm_flags | VM_LOCKED;
76213@@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
76214 lock_limit >>= PAGE_SHIFT;
76215
76216 /* check against resource limits */
76217+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
76218 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
76219 error = do_mlock(start, len, 1);
76220 up_write(&current->mm->mmap_sem);
76221@@ -528,6 +538,12 @@ static int do_mlockall(int flags)
76222 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
76223 vm_flags_t newflags;
76224
76225+#ifdef CONFIG_PAX_SEGMEXEC
76226+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
76227+ break;
76228+#endif
76229+
76230+ BUG_ON(vma->vm_end > TASK_SIZE);
76231 newflags = vma->vm_flags | VM_LOCKED;
76232 if (!(flags & MCL_CURRENT))
76233 newflags &= ~VM_LOCKED;
76234@@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
76235 lock_limit >>= PAGE_SHIFT;
76236
76237 ret = -ENOMEM;
76238+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
76239 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
76240 capable(CAP_IPC_LOCK))
76241 ret = do_mlockall(flags);
76242diff --git a/mm/mmap.c b/mm/mmap.c
76243index d1e4124..32a6988 100644
76244--- a/mm/mmap.c
76245+++ b/mm/mmap.c
76246@@ -32,6 +32,7 @@
76247 #include <linux/khugepaged.h>
76248 #include <linux/uprobes.h>
76249 #include <linux/rbtree_augmented.h>
76250+#include <linux/random.h>
76251
76252 #include <asm/uaccess.h>
76253 #include <asm/cacheflush.h>
76254@@ -48,6 +49,16 @@
76255 #define arch_rebalance_pgtables(addr, len) (addr)
76256 #endif
76257
76258+static inline void verify_mm_writelocked(struct mm_struct *mm)
76259+{
76260+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
76261+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
76262+ up_read(&mm->mmap_sem);
76263+ BUG();
76264+ }
76265+#endif
76266+}
76267+
76268 static void unmap_region(struct mm_struct *mm,
76269 struct vm_area_struct *vma, struct vm_area_struct *prev,
76270 unsigned long start, unsigned long end);
76271@@ -67,22 +78,32 @@ static void unmap_region(struct mm_struct *mm,
76272 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
76273 *
76274 */
76275-pgprot_t protection_map[16] = {
76276+pgprot_t protection_map[16] __read_only = {
76277 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
76278 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
76279 };
76280
76281-pgprot_t vm_get_page_prot(unsigned long vm_flags)
76282+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
76283 {
76284- return __pgprot(pgprot_val(protection_map[vm_flags &
76285+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
76286 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
76287 pgprot_val(arch_vm_get_page_prot(vm_flags)));
76288+
76289+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76290+ if (!(__supported_pte_mask & _PAGE_NX) &&
76291+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
76292+ (vm_flags & (VM_READ | VM_WRITE)))
76293+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
76294+#endif
76295+
76296+ return prot;
76297 }
76298 EXPORT_SYMBOL(vm_get_page_prot);
76299
76300 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
76301 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
76302 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
76303+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
76304 /*
76305 * Make sure vm_committed_as in one cacheline and not cacheline shared with
76306 * other variables. It can be updated by several CPUs frequently.
76307@@ -238,6 +259,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
76308 struct vm_area_struct *next = vma->vm_next;
76309
76310 might_sleep();
76311+ BUG_ON(vma->vm_mirror);
76312 if (vma->vm_ops && vma->vm_ops->close)
76313 vma->vm_ops->close(vma);
76314 if (vma->vm_file)
76315@@ -281,6 +303,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
76316 * not page aligned -Ram Gupta
76317 */
76318 rlim = rlimit(RLIMIT_DATA);
76319+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
76320 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
76321 (mm->end_data - mm->start_data) > rlim)
76322 goto out;
76323@@ -888,6 +911,12 @@ static int
76324 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
76325 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
76326 {
76327+
76328+#ifdef CONFIG_PAX_SEGMEXEC
76329+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
76330+ return 0;
76331+#endif
76332+
76333 if (is_mergeable_vma(vma, file, vm_flags) &&
76334 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
76335 if (vma->vm_pgoff == vm_pgoff)
76336@@ -907,6 +936,12 @@ static int
76337 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
76338 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
76339 {
76340+
76341+#ifdef CONFIG_PAX_SEGMEXEC
76342+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
76343+ return 0;
76344+#endif
76345+
76346 if (is_mergeable_vma(vma, file, vm_flags) &&
76347 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
76348 pgoff_t vm_pglen;
76349@@ -949,13 +984,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
76350 struct vm_area_struct *vma_merge(struct mm_struct *mm,
76351 struct vm_area_struct *prev, unsigned long addr,
76352 unsigned long end, unsigned long vm_flags,
76353- struct anon_vma *anon_vma, struct file *file,
76354+ struct anon_vma *anon_vma, struct file *file,
76355 pgoff_t pgoff, struct mempolicy *policy)
76356 {
76357 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
76358 struct vm_area_struct *area, *next;
76359 int err;
76360
76361+#ifdef CONFIG_PAX_SEGMEXEC
76362+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
76363+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
76364+
76365+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
76366+#endif
76367+
76368 /*
76369 * We later require that vma->vm_flags == vm_flags,
76370 * so this tests vma->vm_flags & VM_SPECIAL, too.
76371@@ -971,6 +1013,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
76372 if (next && next->vm_end == end) /* cases 6, 7, 8 */
76373 next = next->vm_next;
76374
76375+#ifdef CONFIG_PAX_SEGMEXEC
76376+ if (prev)
76377+ prev_m = pax_find_mirror_vma(prev);
76378+ if (area)
76379+ area_m = pax_find_mirror_vma(area);
76380+ if (next)
76381+ next_m = pax_find_mirror_vma(next);
76382+#endif
76383+
76384 /*
76385 * Can it merge with the predecessor?
76386 */
76387@@ -990,9 +1041,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
76388 /* cases 1, 6 */
76389 err = vma_adjust(prev, prev->vm_start,
76390 next->vm_end, prev->vm_pgoff, NULL);
76391- } else /* cases 2, 5, 7 */
76392+
76393+#ifdef CONFIG_PAX_SEGMEXEC
76394+ if (!err && prev_m)
76395+ err = vma_adjust(prev_m, prev_m->vm_start,
76396+ next_m->vm_end, prev_m->vm_pgoff, NULL);
76397+#endif
76398+
76399+ } else { /* cases 2, 5, 7 */
76400 err = vma_adjust(prev, prev->vm_start,
76401 end, prev->vm_pgoff, NULL);
76402+
76403+#ifdef CONFIG_PAX_SEGMEXEC
76404+ if (!err && prev_m)
76405+ err = vma_adjust(prev_m, prev_m->vm_start,
76406+ end_m, prev_m->vm_pgoff, NULL);
76407+#endif
76408+
76409+ }
76410 if (err)
76411 return NULL;
76412 khugepaged_enter_vma_merge(prev);
76413@@ -1006,12 +1072,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
76414 mpol_equal(policy, vma_policy(next)) &&
76415 can_vma_merge_before(next, vm_flags,
76416 anon_vma, file, pgoff+pglen)) {
76417- if (prev && addr < prev->vm_end) /* case 4 */
76418+ if (prev && addr < prev->vm_end) { /* case 4 */
76419 err = vma_adjust(prev, prev->vm_start,
76420 addr, prev->vm_pgoff, NULL);
76421- else /* cases 3, 8 */
76422+
76423+#ifdef CONFIG_PAX_SEGMEXEC
76424+ if (!err && prev_m)
76425+ err = vma_adjust(prev_m, prev_m->vm_start,
76426+ addr_m, prev_m->vm_pgoff, NULL);
76427+#endif
76428+
76429+ } else { /* cases 3, 8 */
76430 err = vma_adjust(area, addr, next->vm_end,
76431 next->vm_pgoff - pglen, NULL);
76432+
76433+#ifdef CONFIG_PAX_SEGMEXEC
76434+ if (!err && area_m)
76435+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
76436+ next_m->vm_pgoff - pglen, NULL);
76437+#endif
76438+
76439+ }
76440 if (err)
76441 return NULL;
76442 khugepaged_enter_vma_merge(area);
76443@@ -1120,16 +1201,13 @@ none:
76444 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
76445 struct file *file, long pages)
76446 {
76447- const unsigned long stack_flags
76448- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
76449-
76450 mm->total_vm += pages;
76451
76452 if (file) {
76453 mm->shared_vm += pages;
76454 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
76455 mm->exec_vm += pages;
76456- } else if (flags & stack_flags)
76457+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
76458 mm->stack_vm += pages;
76459 }
76460 #endif /* CONFIG_PROC_FS */
76461@@ -1165,7 +1243,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76462 * (the exception is when the underlying filesystem is noexec
76463 * mounted, in which case we dont add PROT_EXEC.)
76464 */
76465- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
76466+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
76467 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
76468 prot |= PROT_EXEC;
76469
76470@@ -1191,7 +1269,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76471 /* Obtain the address to map to. we verify (or select) it and ensure
76472 * that it represents a valid section of the address space.
76473 */
76474- addr = get_unmapped_area(file, addr, len, pgoff, flags);
76475+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
76476 if (addr & ~PAGE_MASK)
76477 return addr;
76478
76479@@ -1202,6 +1280,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76480 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
76481 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
76482
76483+#ifdef CONFIG_PAX_MPROTECT
76484+ if (mm->pax_flags & MF_PAX_MPROTECT) {
76485+#ifndef CONFIG_PAX_MPROTECT_COMPAT
76486+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
76487+ gr_log_rwxmmap(file);
76488+
76489+#ifdef CONFIG_PAX_EMUPLT
76490+ vm_flags &= ~VM_EXEC;
76491+#else
76492+ return -EPERM;
76493+#endif
76494+
76495+ }
76496+
76497+ if (!(vm_flags & VM_EXEC))
76498+ vm_flags &= ~VM_MAYEXEC;
76499+#else
76500+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
76501+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
76502+#endif
76503+ else
76504+ vm_flags &= ~VM_MAYWRITE;
76505+ }
76506+#endif
76507+
76508+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76509+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
76510+ vm_flags &= ~VM_PAGEEXEC;
76511+#endif
76512+
76513 if (flags & MAP_LOCKED)
76514 if (!can_do_mlock())
76515 return -EPERM;
76516@@ -1213,6 +1321,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76517 locked += mm->locked_vm;
76518 lock_limit = rlimit(RLIMIT_MEMLOCK);
76519 lock_limit >>= PAGE_SHIFT;
76520+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
76521 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
76522 return -EAGAIN;
76523 }
76524@@ -1279,6 +1388,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76525 }
76526 }
76527
76528+ if (!gr_acl_handle_mmap(file, prot))
76529+ return -EACCES;
76530+
76531 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
76532 }
76533
76534@@ -1356,7 +1468,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
76535 vm_flags_t vm_flags = vma->vm_flags;
76536
76537 /* If it was private or non-writable, the write bit is already clear */
76538- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
76539+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
76540 return 0;
76541
76542 /* The backer wishes to know when pages are first written to? */
76543@@ -1405,13 +1517,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
76544 unsigned long charged = 0;
76545 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
76546
76547+#ifdef CONFIG_PAX_SEGMEXEC
76548+ struct vm_area_struct *vma_m = NULL;
76549+#endif
76550+
76551+ /*
76552+ * mm->mmap_sem is required to protect against another thread
76553+ * changing the mappings in case we sleep.
76554+ */
76555+ verify_mm_writelocked(mm);
76556+
76557 /* Clear old maps */
76558 error = -ENOMEM;
76559-munmap_back:
76560 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
76561 if (do_munmap(mm, addr, len))
76562 return -ENOMEM;
76563- goto munmap_back;
76564+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
76565 }
76566
76567 /* Check against address space limit. */
76568@@ -1460,6 +1581,16 @@ munmap_back:
76569 goto unacct_error;
76570 }
76571
76572+#ifdef CONFIG_PAX_SEGMEXEC
76573+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
76574+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76575+ if (!vma_m) {
76576+ error = -ENOMEM;
76577+ goto free_vma;
76578+ }
76579+ }
76580+#endif
76581+
76582 vma->vm_mm = mm;
76583 vma->vm_start = addr;
76584 vma->vm_end = addr + len;
76585@@ -1484,6 +1615,13 @@ munmap_back:
76586 if (error)
76587 goto unmap_and_free_vma;
76588
76589+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76590+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
76591+ vma->vm_flags |= VM_PAGEEXEC;
76592+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
76593+ }
76594+#endif
76595+
76596 /* Can addr have changed??
76597 *
76598 * Answer: Yes, several device drivers can do it in their
76599@@ -1522,6 +1660,11 @@ munmap_back:
76600 vma_link(mm, vma, prev, rb_link, rb_parent);
76601 file = vma->vm_file;
76602
76603+#ifdef CONFIG_PAX_SEGMEXEC
76604+ if (vma_m)
76605+ BUG_ON(pax_mirror_vma(vma_m, vma));
76606+#endif
76607+
76608 /* Once vma denies write, undo our temporary denial count */
76609 if (correct_wcount)
76610 atomic_inc(&inode->i_writecount);
76611@@ -1529,6 +1672,7 @@ out:
76612 perf_event_mmap(vma);
76613
76614 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
76615+ track_exec_limit(mm, addr, addr + len, vm_flags);
76616 if (vm_flags & VM_LOCKED) {
76617 if (!mlock_vma_pages_range(vma, addr, addr + len))
76618 mm->locked_vm += (len >> PAGE_SHIFT);
76619@@ -1550,6 +1694,12 @@ unmap_and_free_vma:
76620 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
76621 charged = 0;
76622 free_vma:
76623+
76624+#ifdef CONFIG_PAX_SEGMEXEC
76625+ if (vma_m)
76626+ kmem_cache_free(vm_area_cachep, vma_m);
76627+#endif
76628+
76629 kmem_cache_free(vm_area_cachep, vma);
76630 unacct_error:
76631 if (charged)
76632@@ -1557,6 +1707,62 @@ unacct_error:
76633 return error;
76634 }
76635
76636+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
76637+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
76638+{
76639+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
76640+ return (random32() & 0xFF) << PAGE_SHIFT;
76641+
76642+ return 0;
76643+}
76644+#endif
76645+
76646+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
76647+{
76648+ if (!vma) {
76649+#ifdef CONFIG_STACK_GROWSUP
76650+ if (addr > sysctl_heap_stack_gap)
76651+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
76652+ else
76653+ vma = find_vma(current->mm, 0);
76654+ if (vma && (vma->vm_flags & VM_GROWSUP))
76655+ return false;
76656+#endif
76657+ return true;
76658+ }
76659+
76660+ if (addr + len > vma->vm_start)
76661+ return false;
76662+
76663+ if (vma->vm_flags & VM_GROWSDOWN)
76664+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
76665+#ifdef CONFIG_STACK_GROWSUP
76666+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
76667+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
76668+#endif
76669+ else if (offset)
76670+ return offset <= vma->vm_start - addr - len;
76671+
76672+ return true;
76673+}
76674+
76675+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
76676+{
76677+ if (vma->vm_start < len)
76678+ return -ENOMEM;
76679+
76680+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
76681+ if (offset <= vma->vm_start - len)
76682+ return vma->vm_start - len - offset;
76683+ else
76684+ return -ENOMEM;
76685+ }
76686+
76687+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
76688+ return vma->vm_start - len - sysctl_heap_stack_gap;
76689+ return -ENOMEM;
76690+}
76691+
76692 unsigned long unmapped_area(struct vm_unmapped_area_info *info)
76693 {
76694 /*
76695@@ -1776,6 +1982,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
76696 struct mm_struct *mm = current->mm;
76697 struct vm_area_struct *vma;
76698 struct vm_unmapped_area_info info;
76699+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
76700
76701 if (len > TASK_SIZE)
76702 return -ENOMEM;
76703@@ -1783,17 +1990,26 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
76704 if (flags & MAP_FIXED)
76705 return addr;
76706
76707+#ifdef CONFIG_PAX_RANDMMAP
76708+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
76709+#endif
76710+
76711 if (addr) {
76712 addr = PAGE_ALIGN(addr);
76713 vma = find_vma(mm, addr);
76714- if (TASK_SIZE - len >= addr &&
76715- (!vma || addr + len <= vma->vm_start))
76716+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
76717 return addr;
76718 }
76719
76720 info.flags = 0;
76721 info.length = len;
76722 info.low_limit = TASK_UNMAPPED_BASE;
76723+
76724+#ifdef CONFIG_PAX_RANDMMAP
76725+ if (mm->pax_flags & MF_PAX_RANDMMAP)
76726+ info.low_limit += mm->delta_mmap;
76727+#endif
76728+
76729 info.high_limit = TASK_SIZE;
76730 info.align_mask = 0;
76731 return vm_unmapped_area(&info);
76732@@ -1802,10 +2018,16 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
76733
76734 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
76735 {
76736+
76737+#ifdef CONFIG_PAX_SEGMEXEC
76738+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
76739+ return;
76740+#endif
76741+
76742 /*
76743 * Is this a new hole at the lowest possible address?
76744 */
76745- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
76746+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
76747 mm->free_area_cache = addr;
76748 }
76749
76750@@ -1823,6 +2045,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
76751 struct mm_struct *mm = current->mm;
76752 unsigned long addr = addr0;
76753 struct vm_unmapped_area_info info;
76754+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
76755
76756 /* requested length too big for entire address space */
76757 if (len > TASK_SIZE)
76758@@ -1831,12 +2054,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
76759 if (flags & MAP_FIXED)
76760 return addr;
76761
76762+#ifdef CONFIG_PAX_RANDMMAP
76763+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
76764+#endif
76765+
76766 /* requesting a specific address */
76767 if (addr) {
76768 addr = PAGE_ALIGN(addr);
76769 vma = find_vma(mm, addr);
76770- if (TASK_SIZE - len >= addr &&
76771- (!vma || addr + len <= vma->vm_start))
76772+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
76773 return addr;
76774 }
76775
76776@@ -1857,6 +2083,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
76777 VM_BUG_ON(addr != -ENOMEM);
76778 info.flags = 0;
76779 info.low_limit = TASK_UNMAPPED_BASE;
76780+
76781+#ifdef CONFIG_PAX_RANDMMAP
76782+ if (mm->pax_flags & MF_PAX_RANDMMAP)
76783+ info.low_limit += mm->delta_mmap;
76784+#endif
76785+
76786 info.high_limit = TASK_SIZE;
76787 addr = vm_unmapped_area(&info);
76788 }
76789@@ -1867,6 +2099,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
76790
76791 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
76792 {
76793+
76794+#ifdef CONFIG_PAX_SEGMEXEC
76795+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
76796+ return;
76797+#endif
76798+
76799 /*
76800 * Is this a new hole at the highest possible address?
76801 */
76802@@ -1874,8 +2112,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
76803 mm->free_area_cache = addr;
76804
76805 /* dont allow allocations above current base */
76806- if (mm->free_area_cache > mm->mmap_base)
76807+ if (mm->free_area_cache > mm->mmap_base) {
76808 mm->free_area_cache = mm->mmap_base;
76809+ mm->cached_hole_size = ~0UL;
76810+ }
76811 }
76812
76813 unsigned long
76814@@ -1974,6 +2214,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
76815 return vma;
76816 }
76817
76818+#ifdef CONFIG_PAX_SEGMEXEC
76819+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
76820+{
76821+ struct vm_area_struct *vma_m;
76822+
76823+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
76824+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
76825+ BUG_ON(vma->vm_mirror);
76826+ return NULL;
76827+ }
76828+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
76829+ vma_m = vma->vm_mirror;
76830+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
76831+ BUG_ON(vma->vm_file != vma_m->vm_file);
76832+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
76833+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
76834+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
76835+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
76836+ return vma_m;
76837+}
76838+#endif
76839+
76840 /*
76841 * Verify that the stack growth is acceptable and
76842 * update accounting. This is shared with both the
76843@@ -1990,6 +2252,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
76844 return -ENOMEM;
76845
76846 /* Stack limit test */
76847+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
76848 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
76849 return -ENOMEM;
76850
76851@@ -2000,6 +2263,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
76852 locked = mm->locked_vm + grow;
76853 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
76854 limit >>= PAGE_SHIFT;
76855+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
76856 if (locked > limit && !capable(CAP_IPC_LOCK))
76857 return -ENOMEM;
76858 }
76859@@ -2029,37 +2293,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
76860 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
76861 * vma is the last one with address > vma->vm_end. Have to extend vma.
76862 */
76863+#ifndef CONFIG_IA64
76864+static
76865+#endif
76866 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
76867 {
76868 int error;
76869+ bool locknext;
76870
76871 if (!(vma->vm_flags & VM_GROWSUP))
76872 return -EFAULT;
76873
76874+ /* Also guard against wrapping around to address 0. */
76875+ if (address < PAGE_ALIGN(address+1))
76876+ address = PAGE_ALIGN(address+1);
76877+ else
76878+ return -ENOMEM;
76879+
76880 /*
76881 * We must make sure the anon_vma is allocated
76882 * so that the anon_vma locking is not a noop.
76883 */
76884 if (unlikely(anon_vma_prepare(vma)))
76885 return -ENOMEM;
76886+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
76887+ if (locknext && anon_vma_prepare(vma->vm_next))
76888+ return -ENOMEM;
76889 vma_lock_anon_vma(vma);
76890+ if (locknext)
76891+ vma_lock_anon_vma(vma->vm_next);
76892
76893 /*
76894 * vma->vm_start/vm_end cannot change under us because the caller
76895 * is required to hold the mmap_sem in read mode. We need the
76896- * anon_vma lock to serialize against concurrent expand_stacks.
76897- * Also guard against wrapping around to address 0.
76898+ * anon_vma locks to serialize against concurrent expand_stacks
76899+ * and expand_upwards.
76900 */
76901- if (address < PAGE_ALIGN(address+4))
76902- address = PAGE_ALIGN(address+4);
76903- else {
76904- vma_unlock_anon_vma(vma);
76905- return -ENOMEM;
76906- }
76907 error = 0;
76908
76909 /* Somebody else might have raced and expanded it already */
76910- if (address > vma->vm_end) {
76911+ 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)
76912+ error = -ENOMEM;
76913+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
76914 unsigned long size, grow;
76915
76916 size = address - vma->vm_start;
76917@@ -2094,6 +2369,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
76918 }
76919 }
76920 }
76921+ if (locknext)
76922+ vma_unlock_anon_vma(vma->vm_next);
76923 vma_unlock_anon_vma(vma);
76924 khugepaged_enter_vma_merge(vma);
76925 validate_mm(vma->vm_mm);
76926@@ -2108,6 +2385,8 @@ int expand_downwards(struct vm_area_struct *vma,
76927 unsigned long address)
76928 {
76929 int error;
76930+ bool lockprev = false;
76931+ struct vm_area_struct *prev;
76932
76933 /*
76934 * We must make sure the anon_vma is allocated
76935@@ -2121,6 +2400,15 @@ int expand_downwards(struct vm_area_struct *vma,
76936 if (error)
76937 return error;
76938
76939+ prev = vma->vm_prev;
76940+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
76941+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
76942+#endif
76943+ if (lockprev && anon_vma_prepare(prev))
76944+ return -ENOMEM;
76945+ if (lockprev)
76946+ vma_lock_anon_vma(prev);
76947+
76948 vma_lock_anon_vma(vma);
76949
76950 /*
76951@@ -2130,9 +2418,17 @@ int expand_downwards(struct vm_area_struct *vma,
76952 */
76953
76954 /* Somebody else might have raced and expanded it already */
76955- if (address < vma->vm_start) {
76956+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
76957+ error = -ENOMEM;
76958+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
76959 unsigned long size, grow;
76960
76961+#ifdef CONFIG_PAX_SEGMEXEC
76962+ struct vm_area_struct *vma_m;
76963+
76964+ vma_m = pax_find_mirror_vma(vma);
76965+#endif
76966+
76967 size = vma->vm_end - address;
76968 grow = (vma->vm_start - address) >> PAGE_SHIFT;
76969
76970@@ -2157,6 +2453,18 @@ int expand_downwards(struct vm_area_struct *vma,
76971 vma->vm_pgoff -= grow;
76972 anon_vma_interval_tree_post_update_vma(vma);
76973 vma_gap_update(vma);
76974+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
76975+
76976+#ifdef CONFIG_PAX_SEGMEXEC
76977+ if (vma_m) {
76978+ anon_vma_interval_tree_pre_update_vma(vma_m);
76979+ vma_m->vm_start -= grow << PAGE_SHIFT;
76980+ vma_m->vm_pgoff -= grow;
76981+ anon_vma_interval_tree_post_update_vma(vma_m);
76982+ vma_gap_update(vma_m);
76983+ }
76984+#endif
76985+
76986 spin_unlock(&vma->vm_mm->page_table_lock);
76987
76988 perf_event_mmap(vma);
76989@@ -2236,6 +2544,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
76990 do {
76991 long nrpages = vma_pages(vma);
76992
76993+#ifdef CONFIG_PAX_SEGMEXEC
76994+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
76995+ vma = remove_vma(vma);
76996+ continue;
76997+ }
76998+#endif
76999+
77000 if (vma->vm_flags & VM_ACCOUNT)
77001 nr_accounted += nrpages;
77002 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
77003@@ -2281,6 +2596,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
77004 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
77005 vma->vm_prev = NULL;
77006 do {
77007+
77008+#ifdef CONFIG_PAX_SEGMEXEC
77009+ if (vma->vm_mirror) {
77010+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
77011+ vma->vm_mirror->vm_mirror = NULL;
77012+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
77013+ vma->vm_mirror = NULL;
77014+ }
77015+#endif
77016+
77017 vma_rb_erase(vma, &mm->mm_rb);
77018 mm->map_count--;
77019 tail_vma = vma;
77020@@ -2312,14 +2637,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77021 struct vm_area_struct *new;
77022 int err = -ENOMEM;
77023
77024+#ifdef CONFIG_PAX_SEGMEXEC
77025+ struct vm_area_struct *vma_m, *new_m = NULL;
77026+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
77027+#endif
77028+
77029 if (is_vm_hugetlb_page(vma) && (addr &
77030 ~(huge_page_mask(hstate_vma(vma)))))
77031 return -EINVAL;
77032
77033+#ifdef CONFIG_PAX_SEGMEXEC
77034+ vma_m = pax_find_mirror_vma(vma);
77035+#endif
77036+
77037 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
77038 if (!new)
77039 goto out_err;
77040
77041+#ifdef CONFIG_PAX_SEGMEXEC
77042+ if (vma_m) {
77043+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
77044+ if (!new_m) {
77045+ kmem_cache_free(vm_area_cachep, new);
77046+ goto out_err;
77047+ }
77048+ }
77049+#endif
77050+
77051 /* most fields are the same, copy all, and then fixup */
77052 *new = *vma;
77053
77054@@ -2332,6 +2676,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77055 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
77056 }
77057
77058+#ifdef CONFIG_PAX_SEGMEXEC
77059+ if (vma_m) {
77060+ *new_m = *vma_m;
77061+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
77062+ new_m->vm_mirror = new;
77063+ new->vm_mirror = new_m;
77064+
77065+ if (new_below)
77066+ new_m->vm_end = addr_m;
77067+ else {
77068+ new_m->vm_start = addr_m;
77069+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
77070+ }
77071+ }
77072+#endif
77073+
77074 pol = mpol_dup(vma_policy(vma));
77075 if (IS_ERR(pol)) {
77076 err = PTR_ERR(pol);
77077@@ -2354,6 +2714,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77078 else
77079 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
77080
77081+#ifdef CONFIG_PAX_SEGMEXEC
77082+ if (!err && vma_m) {
77083+ if (anon_vma_clone(new_m, vma_m))
77084+ goto out_free_mpol;
77085+
77086+ mpol_get(pol);
77087+ vma_set_policy(new_m, pol);
77088+
77089+ if (new_m->vm_file)
77090+ get_file(new_m->vm_file);
77091+
77092+ if (new_m->vm_ops && new_m->vm_ops->open)
77093+ new_m->vm_ops->open(new_m);
77094+
77095+ if (new_below)
77096+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
77097+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
77098+ else
77099+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
77100+
77101+ if (err) {
77102+ if (new_m->vm_ops && new_m->vm_ops->close)
77103+ new_m->vm_ops->close(new_m);
77104+ if (new_m->vm_file)
77105+ fput(new_m->vm_file);
77106+ mpol_put(pol);
77107+ }
77108+ }
77109+#endif
77110+
77111 /* Success. */
77112 if (!err)
77113 return 0;
77114@@ -2363,10 +2753,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77115 new->vm_ops->close(new);
77116 if (new->vm_file)
77117 fput(new->vm_file);
77118- unlink_anon_vmas(new);
77119 out_free_mpol:
77120 mpol_put(pol);
77121 out_free_vma:
77122+
77123+#ifdef CONFIG_PAX_SEGMEXEC
77124+ if (new_m) {
77125+ unlink_anon_vmas(new_m);
77126+ kmem_cache_free(vm_area_cachep, new_m);
77127+ }
77128+#endif
77129+
77130+ unlink_anon_vmas(new);
77131 kmem_cache_free(vm_area_cachep, new);
77132 out_err:
77133 return err;
77134@@ -2379,6 +2777,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77135 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
77136 unsigned long addr, int new_below)
77137 {
77138+
77139+#ifdef CONFIG_PAX_SEGMEXEC
77140+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
77141+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
77142+ if (mm->map_count >= sysctl_max_map_count-1)
77143+ return -ENOMEM;
77144+ } else
77145+#endif
77146+
77147 if (mm->map_count >= sysctl_max_map_count)
77148 return -ENOMEM;
77149
77150@@ -2390,11 +2797,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
77151 * work. This now handles partial unmappings.
77152 * Jeremy Fitzhardinge <jeremy@goop.org>
77153 */
77154+#ifdef CONFIG_PAX_SEGMEXEC
77155 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77156 {
77157+ int ret = __do_munmap(mm, start, len);
77158+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
77159+ return ret;
77160+
77161+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
77162+}
77163+
77164+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77165+#else
77166+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77167+#endif
77168+{
77169 unsigned long end;
77170 struct vm_area_struct *vma, *prev, *last;
77171
77172+ /*
77173+ * mm->mmap_sem is required to protect against another thread
77174+ * changing the mappings in case we sleep.
77175+ */
77176+ verify_mm_writelocked(mm);
77177+
77178 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
77179 return -EINVAL;
77180
77181@@ -2469,6 +2895,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77182 /* Fix up all other VM information */
77183 remove_vma_list(mm, vma);
77184
77185+ track_exec_limit(mm, start, end, 0UL);
77186+
77187 return 0;
77188 }
77189
77190@@ -2477,6 +2905,13 @@ int vm_munmap(unsigned long start, size_t len)
77191 int ret;
77192 struct mm_struct *mm = current->mm;
77193
77194+
77195+#ifdef CONFIG_PAX_SEGMEXEC
77196+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
77197+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
77198+ return -EINVAL;
77199+#endif
77200+
77201 down_write(&mm->mmap_sem);
77202 ret = do_munmap(mm, start, len);
77203 up_write(&mm->mmap_sem);
77204@@ -2490,16 +2925,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
77205 return vm_munmap(addr, len);
77206 }
77207
77208-static inline void verify_mm_writelocked(struct mm_struct *mm)
77209-{
77210-#ifdef CONFIG_DEBUG_VM
77211- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
77212- WARN_ON(1);
77213- up_read(&mm->mmap_sem);
77214- }
77215-#endif
77216-}
77217-
77218 /*
77219 * this is really a simplified "do_mmap". it only handles
77220 * anonymous maps. eventually we may be able to do some
77221@@ -2513,6 +2938,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77222 struct rb_node ** rb_link, * rb_parent;
77223 pgoff_t pgoff = addr >> PAGE_SHIFT;
77224 int error;
77225+ unsigned long charged;
77226
77227 len = PAGE_ALIGN(len);
77228 if (!len)
77229@@ -2520,16 +2946,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77230
77231 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
77232
77233+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
77234+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
77235+ flags &= ~VM_EXEC;
77236+
77237+#ifdef CONFIG_PAX_MPROTECT
77238+ if (mm->pax_flags & MF_PAX_MPROTECT)
77239+ flags &= ~VM_MAYEXEC;
77240+#endif
77241+
77242+ }
77243+#endif
77244+
77245 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
77246 if (error & ~PAGE_MASK)
77247 return error;
77248
77249+ charged = len >> PAGE_SHIFT;
77250+
77251 /*
77252 * mlock MCL_FUTURE?
77253 */
77254 if (mm->def_flags & VM_LOCKED) {
77255 unsigned long locked, lock_limit;
77256- locked = len >> PAGE_SHIFT;
77257+ locked = charged;
77258 locked += mm->locked_vm;
77259 lock_limit = rlimit(RLIMIT_MEMLOCK);
77260 lock_limit >>= PAGE_SHIFT;
77261@@ -2546,21 +2986,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77262 /*
77263 * Clear old maps. this also does some error checking for us
77264 */
77265- munmap_back:
77266 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
77267 if (do_munmap(mm, addr, len))
77268 return -ENOMEM;
77269- goto munmap_back;
77270+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
77271 }
77272
77273 /* Check against address space limits *after* clearing old maps... */
77274- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
77275+ if (!may_expand_vm(mm, charged))
77276 return -ENOMEM;
77277
77278 if (mm->map_count > sysctl_max_map_count)
77279 return -ENOMEM;
77280
77281- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
77282+ if (security_vm_enough_memory_mm(mm, charged))
77283 return -ENOMEM;
77284
77285 /* Can we just expand an old private anonymous mapping? */
77286@@ -2574,7 +3013,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77287 */
77288 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77289 if (!vma) {
77290- vm_unacct_memory(len >> PAGE_SHIFT);
77291+ vm_unacct_memory(charged);
77292 return -ENOMEM;
77293 }
77294
77295@@ -2588,11 +3027,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77296 vma_link(mm, vma, prev, rb_link, rb_parent);
77297 out:
77298 perf_event_mmap(vma);
77299- mm->total_vm += len >> PAGE_SHIFT;
77300+ mm->total_vm += charged;
77301 if (flags & VM_LOCKED) {
77302 if (!mlock_vma_pages_range(vma, addr, addr + len))
77303- mm->locked_vm += (len >> PAGE_SHIFT);
77304+ mm->locked_vm += charged;
77305 }
77306+ track_exec_limit(mm, addr, addr + len, flags);
77307 return addr;
77308 }
77309
77310@@ -2650,6 +3090,7 @@ void exit_mmap(struct mm_struct *mm)
77311 while (vma) {
77312 if (vma->vm_flags & VM_ACCOUNT)
77313 nr_accounted += vma_pages(vma);
77314+ vma->vm_mirror = NULL;
77315 vma = remove_vma(vma);
77316 }
77317 vm_unacct_memory(nr_accounted);
77318@@ -2666,6 +3107,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
77319 struct vm_area_struct *prev;
77320 struct rb_node **rb_link, *rb_parent;
77321
77322+#ifdef CONFIG_PAX_SEGMEXEC
77323+ struct vm_area_struct *vma_m = NULL;
77324+#endif
77325+
77326+ if (security_mmap_addr(vma->vm_start))
77327+ return -EPERM;
77328+
77329 /*
77330 * The vm_pgoff of a purely anonymous vma should be irrelevant
77331 * until its first write fault, when page's anon_vma and index
77332@@ -2689,7 +3137,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
77333 security_vm_enough_memory_mm(mm, vma_pages(vma)))
77334 return -ENOMEM;
77335
77336+#ifdef CONFIG_PAX_SEGMEXEC
77337+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
77338+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77339+ if (!vma_m)
77340+ return -ENOMEM;
77341+ }
77342+#endif
77343+
77344 vma_link(mm, vma, prev, rb_link, rb_parent);
77345+
77346+#ifdef CONFIG_PAX_SEGMEXEC
77347+ if (vma_m)
77348+ BUG_ON(pax_mirror_vma(vma_m, vma));
77349+#endif
77350+
77351 return 0;
77352 }
77353
77354@@ -2709,6 +3171,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
77355 struct mempolicy *pol;
77356 bool faulted_in_anon_vma = true;
77357
77358+ BUG_ON(vma->vm_mirror);
77359+
77360 /*
77361 * If anonymous vma has not yet been faulted, update new pgoff
77362 * to match new location, to increase its chance of merging.
77363@@ -2775,6 +3239,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
77364 return NULL;
77365 }
77366
77367+#ifdef CONFIG_PAX_SEGMEXEC
77368+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
77369+{
77370+ struct vm_area_struct *prev_m;
77371+ struct rb_node **rb_link_m, *rb_parent_m;
77372+ struct mempolicy *pol_m;
77373+
77374+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
77375+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
77376+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
77377+ *vma_m = *vma;
77378+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
77379+ if (anon_vma_clone(vma_m, vma))
77380+ return -ENOMEM;
77381+ pol_m = vma_policy(vma_m);
77382+ mpol_get(pol_m);
77383+ vma_set_policy(vma_m, pol_m);
77384+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
77385+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
77386+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
77387+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
77388+ if (vma_m->vm_file)
77389+ get_file(vma_m->vm_file);
77390+ if (vma_m->vm_ops && vma_m->vm_ops->open)
77391+ vma_m->vm_ops->open(vma_m);
77392+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
77393+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
77394+ vma_m->vm_mirror = vma;
77395+ vma->vm_mirror = vma_m;
77396+ return 0;
77397+}
77398+#endif
77399+
77400 /*
77401 * Return true if the calling process may expand its vm space by the passed
77402 * number of pages
77403@@ -2786,6 +3283,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
77404
77405 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
77406
77407+#ifdef CONFIG_PAX_RANDMMAP
77408+ if (mm->pax_flags & MF_PAX_RANDMMAP)
77409+ cur -= mm->brk_gap;
77410+#endif
77411+
77412+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
77413 if (cur + npages > lim)
77414 return 0;
77415 return 1;
77416@@ -2856,6 +3359,22 @@ int install_special_mapping(struct mm_struct *mm,
77417 vma->vm_start = addr;
77418 vma->vm_end = addr + len;
77419
77420+#ifdef CONFIG_PAX_MPROTECT
77421+ if (mm->pax_flags & MF_PAX_MPROTECT) {
77422+#ifndef CONFIG_PAX_MPROTECT_COMPAT
77423+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
77424+ return -EPERM;
77425+ if (!(vm_flags & VM_EXEC))
77426+ vm_flags &= ~VM_MAYEXEC;
77427+#else
77428+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
77429+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
77430+#endif
77431+ else
77432+ vm_flags &= ~VM_MAYWRITE;
77433+ }
77434+#endif
77435+
77436 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
77437 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
77438
77439diff --git a/mm/mprotect.c b/mm/mprotect.c
77440index 94722a4..9837984 100644
77441--- a/mm/mprotect.c
77442+++ b/mm/mprotect.c
77443@@ -23,10 +23,17 @@
77444 #include <linux/mmu_notifier.h>
77445 #include <linux/migrate.h>
77446 #include <linux/perf_event.h>
77447+
77448+#ifdef CONFIG_PAX_MPROTECT
77449+#include <linux/elf.h>
77450+#include <linux/binfmts.h>
77451+#endif
77452+
77453 #include <asm/uaccess.h>
77454 #include <asm/pgtable.h>
77455 #include <asm/cacheflush.h>
77456 #include <asm/tlbflush.h>
77457+#include <asm/mmu_context.h>
77458
77459 #ifndef pgprot_modify
77460 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
77461@@ -233,6 +240,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
77462 return pages;
77463 }
77464
77465+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
77466+/* called while holding the mmap semaphor for writing except stack expansion */
77467+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
77468+{
77469+ unsigned long oldlimit, newlimit = 0UL;
77470+
77471+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
77472+ return;
77473+
77474+ spin_lock(&mm->page_table_lock);
77475+ oldlimit = mm->context.user_cs_limit;
77476+ if ((prot & VM_EXEC) && oldlimit < end)
77477+ /* USER_CS limit moved up */
77478+ newlimit = end;
77479+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
77480+ /* USER_CS limit moved down */
77481+ newlimit = start;
77482+
77483+ if (newlimit) {
77484+ mm->context.user_cs_limit = newlimit;
77485+
77486+#ifdef CONFIG_SMP
77487+ wmb();
77488+ cpus_clear(mm->context.cpu_user_cs_mask);
77489+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
77490+#endif
77491+
77492+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
77493+ }
77494+ spin_unlock(&mm->page_table_lock);
77495+ if (newlimit == end) {
77496+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
77497+
77498+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
77499+ if (is_vm_hugetlb_page(vma))
77500+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
77501+ else
77502+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
77503+ }
77504+}
77505+#endif
77506+
77507 int
77508 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
77509 unsigned long start, unsigned long end, unsigned long newflags)
77510@@ -245,11 +294,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
77511 int error;
77512 int dirty_accountable = 0;
77513
77514+#ifdef CONFIG_PAX_SEGMEXEC
77515+ struct vm_area_struct *vma_m = NULL;
77516+ unsigned long start_m, end_m;
77517+
77518+ start_m = start + SEGMEXEC_TASK_SIZE;
77519+ end_m = end + SEGMEXEC_TASK_SIZE;
77520+#endif
77521+
77522 if (newflags == oldflags) {
77523 *pprev = vma;
77524 return 0;
77525 }
77526
77527+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
77528+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
77529+
77530+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
77531+ return -ENOMEM;
77532+
77533+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
77534+ return -ENOMEM;
77535+ }
77536+
77537 /*
77538 * If we make a private mapping writable we increase our commit;
77539 * but (without finer accounting) cannot reduce our commit if we
77540@@ -266,6 +333,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
77541 }
77542 }
77543
77544+#ifdef CONFIG_PAX_SEGMEXEC
77545+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
77546+ if (start != vma->vm_start) {
77547+ error = split_vma(mm, vma, start, 1);
77548+ if (error)
77549+ goto fail;
77550+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
77551+ *pprev = (*pprev)->vm_next;
77552+ }
77553+
77554+ if (end != vma->vm_end) {
77555+ error = split_vma(mm, vma, end, 0);
77556+ if (error)
77557+ goto fail;
77558+ }
77559+
77560+ if (pax_find_mirror_vma(vma)) {
77561+ error = __do_munmap(mm, start_m, end_m - start_m);
77562+ if (error)
77563+ goto fail;
77564+ } else {
77565+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77566+ if (!vma_m) {
77567+ error = -ENOMEM;
77568+ goto fail;
77569+ }
77570+ vma->vm_flags = newflags;
77571+ error = pax_mirror_vma(vma_m, vma);
77572+ if (error) {
77573+ vma->vm_flags = oldflags;
77574+ goto fail;
77575+ }
77576+ }
77577+ }
77578+#endif
77579+
77580 /*
77581 * First try to merge with previous and/or next vma.
77582 */
77583@@ -296,9 +399,21 @@ success:
77584 * vm_flags and vm_page_prot are protected by the mmap_sem
77585 * held in write mode.
77586 */
77587+
77588+#ifdef CONFIG_PAX_SEGMEXEC
77589+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
77590+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
77591+#endif
77592+
77593 vma->vm_flags = newflags;
77594+
77595+#ifdef CONFIG_PAX_MPROTECT
77596+ if (mm->binfmt && mm->binfmt->handle_mprotect)
77597+ mm->binfmt->handle_mprotect(vma, newflags);
77598+#endif
77599+
77600 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
77601- vm_get_page_prot(newflags));
77602+ vm_get_page_prot(vma->vm_flags));
77603
77604 if (vma_wants_writenotify(vma)) {
77605 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
77606@@ -337,6 +452,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77607 end = start + len;
77608 if (end <= start)
77609 return -ENOMEM;
77610+
77611+#ifdef CONFIG_PAX_SEGMEXEC
77612+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
77613+ if (end > SEGMEXEC_TASK_SIZE)
77614+ return -EINVAL;
77615+ } else
77616+#endif
77617+
77618+ if (end > TASK_SIZE)
77619+ return -EINVAL;
77620+
77621 if (!arch_validate_prot(prot))
77622 return -EINVAL;
77623
77624@@ -344,7 +470,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77625 /*
77626 * Does the application expect PROT_READ to imply PROT_EXEC:
77627 */
77628- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
77629+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
77630 prot |= PROT_EXEC;
77631
77632 vm_flags = calc_vm_prot_bits(prot);
77633@@ -376,6 +502,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77634 if (start > vma->vm_start)
77635 prev = vma;
77636
77637+#ifdef CONFIG_PAX_MPROTECT
77638+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
77639+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
77640+#endif
77641+
77642 for (nstart = start ; ; ) {
77643 unsigned long newflags;
77644
77645@@ -386,6 +517,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77646
77647 /* newflags >> 4 shift VM_MAY% in place of VM_% */
77648 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
77649+ if (prot & (PROT_WRITE | PROT_EXEC))
77650+ gr_log_rwxmprotect(vma->vm_file);
77651+
77652+ error = -EACCES;
77653+ goto out;
77654+ }
77655+
77656+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
77657 error = -EACCES;
77658 goto out;
77659 }
77660@@ -400,6 +539,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77661 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
77662 if (error)
77663 goto out;
77664+
77665+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
77666+
77667 nstart = tmp;
77668
77669 if (nstart < prev->vm_end)
77670diff --git a/mm/mremap.c b/mm/mremap.c
77671index e1031e1..1f2a0a1 100644
77672--- a/mm/mremap.c
77673+++ b/mm/mremap.c
77674@@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
77675 continue;
77676 pte = ptep_get_and_clear(mm, old_addr, old_pte);
77677 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
77678+
77679+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
77680+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
77681+ pte = pte_exprotect(pte);
77682+#endif
77683+
77684 set_pte_at(mm, new_addr, new_pte, pte);
77685 }
77686
77687@@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
77688 if (is_vm_hugetlb_page(vma))
77689 goto Einval;
77690
77691+#ifdef CONFIG_PAX_SEGMEXEC
77692+ if (pax_find_mirror_vma(vma))
77693+ goto Einval;
77694+#endif
77695+
77696 /* We can't remap across vm area boundaries */
77697 if (old_len > vma->vm_end - addr)
77698 goto Efault;
77699@@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
77700 unsigned long ret = -EINVAL;
77701 unsigned long charged = 0;
77702 unsigned long map_flags;
77703+ unsigned long pax_task_size = TASK_SIZE;
77704
77705 if (new_addr & ~PAGE_MASK)
77706 goto out;
77707
77708- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
77709+#ifdef CONFIG_PAX_SEGMEXEC
77710+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
77711+ pax_task_size = SEGMEXEC_TASK_SIZE;
77712+#endif
77713+
77714+ pax_task_size -= PAGE_SIZE;
77715+
77716+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
77717 goto out;
77718
77719 /* Check if the location we're moving into overlaps the
77720 * old location at all, and fail if it does.
77721 */
77722- if ((new_addr <= addr) && (new_addr+new_len) > addr)
77723- goto out;
77724-
77725- if ((addr <= new_addr) && (addr+old_len) > new_addr)
77726+ if (addr + old_len > new_addr && new_addr + new_len > addr)
77727 goto out;
77728
77729 ret = do_munmap(mm, new_addr, new_len);
77730@@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
77731 struct vm_area_struct *vma;
77732 unsigned long ret = -EINVAL;
77733 unsigned long charged = 0;
77734+ unsigned long pax_task_size = TASK_SIZE;
77735
77736 down_write(&current->mm->mmap_sem);
77737
77738@@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
77739 if (!new_len)
77740 goto out;
77741
77742+#ifdef CONFIG_PAX_SEGMEXEC
77743+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
77744+ pax_task_size = SEGMEXEC_TASK_SIZE;
77745+#endif
77746+
77747+ pax_task_size -= PAGE_SIZE;
77748+
77749+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
77750+ old_len > pax_task_size || addr > pax_task_size-old_len)
77751+ goto out;
77752+
77753 if (flags & MREMAP_FIXED) {
77754 if (flags & MREMAP_MAYMOVE)
77755 ret = mremap_to(addr, old_len, new_addr, new_len);
77756@@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
77757 addr + new_len);
77758 }
77759 ret = addr;
77760+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
77761 goto out;
77762 }
77763 }
77764@@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
77765 goto out;
77766 }
77767
77768+ map_flags = vma->vm_flags;
77769 ret = move_vma(vma, addr, old_len, new_len, new_addr);
77770+ if (!(ret & ~PAGE_MASK)) {
77771+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
77772+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
77773+ }
77774 }
77775 out:
77776 if (ret & ~PAGE_MASK)
77777diff --git a/mm/nommu.c b/mm/nommu.c
77778index 79c3cac..4d357e0 100644
77779--- a/mm/nommu.c
77780+++ b/mm/nommu.c
77781@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
77782 int sysctl_overcommit_ratio = 50; /* default is 50% */
77783 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
77784 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
77785-int heap_stack_gap = 0;
77786
77787 atomic_long_t mmap_pages_allocated;
77788
77789@@ -839,15 +838,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
77790 EXPORT_SYMBOL(find_vma);
77791
77792 /*
77793- * find a VMA
77794- * - we don't extend stack VMAs under NOMMU conditions
77795- */
77796-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
77797-{
77798- return find_vma(mm, addr);
77799-}
77800-
77801-/*
77802 * expand a stack to a given address
77803 * - not supported under NOMMU conditions
77804 */
77805@@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
77806
77807 /* most fields are the same, copy all, and then fixup */
77808 *new = *vma;
77809+ INIT_LIST_HEAD(&new->anon_vma_chain);
77810 *region = *vma->vm_region;
77811 new->vm_region = region;
77812
77813diff --git a/mm/page-writeback.c b/mm/page-writeback.c
77814index 0713bfb..e3774e0 100644
77815--- a/mm/page-writeback.c
77816+++ b/mm/page-writeback.c
77817@@ -1630,7 +1630,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
77818 }
77819 }
77820
77821-static struct notifier_block __cpuinitdata ratelimit_nb = {
77822+static struct notifier_block ratelimit_nb = {
77823 .notifier_call = ratelimit_handler,
77824 .next = NULL,
77825 };
77826diff --git a/mm/page_alloc.c b/mm/page_alloc.c
77827index 6a83cd3..bc2dcb6 100644
77828--- a/mm/page_alloc.c
77829+++ b/mm/page_alloc.c
77830@@ -338,7 +338,7 @@ out:
77831 * This usage means that zero-order pages may not be compound.
77832 */
77833
77834-static void free_compound_page(struct page *page)
77835+void free_compound_page(struct page *page)
77836 {
77837 __free_pages_ok(page, compound_order(page));
77838 }
77839@@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
77840 int i;
77841 int bad = 0;
77842
77843+#ifdef CONFIG_PAX_MEMORY_SANITIZE
77844+ unsigned long index = 1UL << order;
77845+#endif
77846+
77847 trace_mm_page_free(page, order);
77848 kmemcheck_free_shadow(page, order);
77849
77850@@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
77851 debug_check_no_obj_freed(page_address(page),
77852 PAGE_SIZE << order);
77853 }
77854+
77855+#ifdef CONFIG_PAX_MEMORY_SANITIZE
77856+ for (; index; --index)
77857+ sanitize_highpage(page + index - 1);
77858+#endif
77859+
77860 arch_free_page(page, order);
77861 kernel_map_pages(page, 1 << order, 0);
77862
77863@@ -861,8 +871,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
77864 arch_alloc_page(page, order);
77865 kernel_map_pages(page, 1 << order, 1);
77866
77867+#ifndef CONFIG_PAX_MEMORY_SANITIZE
77868 if (gfp_flags & __GFP_ZERO)
77869 prep_zero_page(page, order, gfp_flags);
77870+#endif
77871
77872 if (order && (gfp_flags & __GFP_COMP))
77873 prep_compound_page(page, order);
77874@@ -3752,7 +3764,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
77875 unsigned long pfn;
77876
77877 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
77878+#ifdef CONFIG_X86_32
77879+ /* boot failures in VMware 8 on 32bit vanilla since
77880+ this change */
77881+ if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
77882+#else
77883 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
77884+#endif
77885 return 1;
77886 }
77887 return 0;
77888diff --git a/mm/percpu.c b/mm/percpu.c
77889index 8c8e08f..73a5cda 100644
77890--- a/mm/percpu.c
77891+++ b/mm/percpu.c
77892@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
77893 static unsigned int pcpu_high_unit_cpu __read_mostly;
77894
77895 /* the address of the first chunk which starts with the kernel static area */
77896-void *pcpu_base_addr __read_mostly;
77897+void *pcpu_base_addr __read_only;
77898 EXPORT_SYMBOL_GPL(pcpu_base_addr);
77899
77900 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
77901diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
77902index 926b466..b23df53 100644
77903--- a/mm/process_vm_access.c
77904+++ b/mm/process_vm_access.c
77905@@ -13,6 +13,7 @@
77906 #include <linux/uio.h>
77907 #include <linux/sched.h>
77908 #include <linux/highmem.h>
77909+#include <linux/security.h>
77910 #include <linux/ptrace.h>
77911 #include <linux/slab.h>
77912 #include <linux/syscalls.h>
77913@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
77914 size_t iov_l_curr_offset = 0;
77915 ssize_t iov_len;
77916
77917+ return -ENOSYS; // PaX: until properly audited
77918+
77919 /*
77920 * Work out how many pages of struct pages we're going to need
77921 * when eventually calling get_user_pages
77922 */
77923 for (i = 0; i < riovcnt; i++) {
77924 iov_len = rvec[i].iov_len;
77925- if (iov_len > 0) {
77926- nr_pages_iov = ((unsigned long)rvec[i].iov_base
77927- + iov_len)
77928- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
77929- / PAGE_SIZE + 1;
77930- nr_pages = max(nr_pages, nr_pages_iov);
77931- }
77932+ if (iov_len <= 0)
77933+ continue;
77934+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
77935+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
77936+ nr_pages = max(nr_pages, nr_pages_iov);
77937 }
77938
77939 if (nr_pages == 0)
77940@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
77941 goto free_proc_pages;
77942 }
77943
77944+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
77945+ rc = -EPERM;
77946+ goto put_task_struct;
77947+ }
77948+
77949 mm = mm_access(task, PTRACE_MODE_ATTACH);
77950 if (!mm || IS_ERR(mm)) {
77951 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
77952diff --git a/mm/rmap.c b/mm/rmap.c
77953index 2c78f8c..9e9c624 100644
77954--- a/mm/rmap.c
77955+++ b/mm/rmap.c
77956@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
77957 struct anon_vma *anon_vma = vma->anon_vma;
77958 struct anon_vma_chain *avc;
77959
77960+#ifdef CONFIG_PAX_SEGMEXEC
77961+ struct anon_vma_chain *avc_m = NULL;
77962+#endif
77963+
77964 might_sleep();
77965 if (unlikely(!anon_vma)) {
77966 struct mm_struct *mm = vma->vm_mm;
77967@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
77968 if (!avc)
77969 goto out_enomem;
77970
77971+#ifdef CONFIG_PAX_SEGMEXEC
77972+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
77973+ if (!avc_m)
77974+ goto out_enomem_free_avc;
77975+#endif
77976+
77977 anon_vma = find_mergeable_anon_vma(vma);
77978 allocated = NULL;
77979 if (!anon_vma) {
77980@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
77981 /* page_table_lock to protect against threads */
77982 spin_lock(&mm->page_table_lock);
77983 if (likely(!vma->anon_vma)) {
77984+
77985+#ifdef CONFIG_PAX_SEGMEXEC
77986+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
77987+
77988+ if (vma_m) {
77989+ BUG_ON(vma_m->anon_vma);
77990+ vma_m->anon_vma = anon_vma;
77991+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
77992+ avc_m = NULL;
77993+ }
77994+#endif
77995+
77996 vma->anon_vma = anon_vma;
77997 anon_vma_chain_link(vma, avc, anon_vma);
77998 allocated = NULL;
77999@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
78000
78001 if (unlikely(allocated))
78002 put_anon_vma(allocated);
78003+
78004+#ifdef CONFIG_PAX_SEGMEXEC
78005+ if (unlikely(avc_m))
78006+ anon_vma_chain_free(avc_m);
78007+#endif
78008+
78009 if (unlikely(avc))
78010 anon_vma_chain_free(avc);
78011 }
78012 return 0;
78013
78014 out_enomem_free_avc:
78015+
78016+#ifdef CONFIG_PAX_SEGMEXEC
78017+ if (avc_m)
78018+ anon_vma_chain_free(avc_m);
78019+#endif
78020+
78021 anon_vma_chain_free(avc);
78022 out_enomem:
78023 return -ENOMEM;
78024@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
78025 * Attach the anon_vmas from src to dst.
78026 * Returns 0 on success, -ENOMEM on failure.
78027 */
78028-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
78029+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
78030 {
78031 struct anon_vma_chain *avc, *pavc;
78032 struct anon_vma *root = NULL;
78033@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
78034 * the corresponding VMA in the parent process is attached to.
78035 * Returns 0 on success, non-zero on failure.
78036 */
78037-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
78038+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
78039 {
78040 struct anon_vma_chain *avc;
78041 struct anon_vma *anon_vma;
78042diff --git a/mm/shmem.c b/mm/shmem.c
78043index 5dd56f6..7c51725 100644
78044--- a/mm/shmem.c
78045+++ b/mm/shmem.c
78046@@ -31,7 +31,7 @@
78047 #include <linux/export.h>
78048 #include <linux/swap.h>
78049
78050-static struct vfsmount *shm_mnt;
78051+struct vfsmount *shm_mnt;
78052
78053 #ifdef CONFIG_SHMEM
78054 /*
78055@@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
78056 #define BOGO_DIRENT_SIZE 20
78057
78058 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
78059-#define SHORT_SYMLINK_LEN 128
78060+#define SHORT_SYMLINK_LEN 64
78061
78062 /*
78063 * shmem_fallocate and shmem_writepage communicate via inode->i_private
78064@@ -2202,6 +2202,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
78065 static int shmem_xattr_validate(const char *name)
78066 {
78067 struct { const char *prefix; size_t len; } arr[] = {
78068+
78069+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
78070+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
78071+#endif
78072+
78073 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
78074 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
78075 };
78076@@ -2257,6 +2262,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
78077 if (err)
78078 return err;
78079
78080+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
78081+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
78082+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
78083+ return -EOPNOTSUPP;
78084+ if (size > 8)
78085+ return -EINVAL;
78086+ }
78087+#endif
78088+
78089 return simple_xattr_set(&info->xattrs, name, value, size, flags);
78090 }
78091
78092@@ -2556,8 +2570,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
78093 int err = -ENOMEM;
78094
78095 /* Round up to L1_CACHE_BYTES to resist false sharing */
78096- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
78097- L1_CACHE_BYTES), GFP_KERNEL);
78098+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
78099 if (!sbinfo)
78100 return -ENOMEM;
78101
78102diff --git a/mm/slab.c b/mm/slab.c
78103index e7667a3..b62c169 100644
78104--- a/mm/slab.c
78105+++ b/mm/slab.c
78106@@ -306,7 +306,7 @@ struct kmem_list3 {
78107 * Need this for bootstrapping a per node allocator.
78108 */
78109 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
78110-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
78111+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
78112 #define CACHE_CACHE 0
78113 #define SIZE_AC MAX_NUMNODES
78114 #define SIZE_L3 (2 * MAX_NUMNODES)
78115@@ -407,10 +407,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
78116 if ((x)->max_freeable < i) \
78117 (x)->max_freeable = i; \
78118 } while (0)
78119-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
78120-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
78121-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
78122-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
78123+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
78124+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
78125+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
78126+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
78127 #else
78128 #define STATS_INC_ACTIVE(x) do { } while (0)
78129 #define STATS_DEC_ACTIVE(x) do { } while (0)
78130@@ -518,7 +518,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
78131 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
78132 */
78133 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
78134- const struct slab *slab, void *obj)
78135+ const struct slab *slab, const void *obj)
78136 {
78137 u32 offset = (obj - slab->s_mem);
78138 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
78139@@ -539,12 +539,13 @@ EXPORT_SYMBOL(malloc_sizes);
78140 struct cache_names {
78141 char *name;
78142 char *name_dma;
78143+ char *name_usercopy;
78144 };
78145
78146 static struct cache_names __initdata cache_names[] = {
78147-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
78148+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
78149 #include <linux/kmalloc_sizes.h>
78150- {NULL,}
78151+ {NULL}
78152 #undef CACHE
78153 };
78154
78155@@ -729,6 +730,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
78156 if (unlikely(gfpflags & GFP_DMA))
78157 return csizep->cs_dmacachep;
78158 #endif
78159+
78160+#ifdef CONFIG_PAX_USERCOPY_SLABS
78161+ if (unlikely(gfpflags & GFP_USERCOPY))
78162+ return csizep->cs_usercopycachep;
78163+#endif
78164+
78165 return csizep->cs_cachep;
78166 }
78167
78168@@ -1482,7 +1489,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
78169 return notifier_from_errno(err);
78170 }
78171
78172-static struct notifier_block __cpuinitdata cpucache_notifier = {
78173+static struct notifier_block cpucache_notifier = {
78174 &cpuup_callback, NULL, 0
78175 };
78176
78177@@ -1667,12 +1674,12 @@ void __init kmem_cache_init(void)
78178 */
78179
78180 sizes[INDEX_AC].cs_cachep = create_kmalloc_cache(names[INDEX_AC].name,
78181- sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS);
78182+ sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
78183
78184 if (INDEX_AC != INDEX_L3)
78185 sizes[INDEX_L3].cs_cachep =
78186 create_kmalloc_cache(names[INDEX_L3].name,
78187- sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS);
78188+ sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
78189
78190 slab_early_init = 0;
78191
78192@@ -1686,13 +1693,20 @@ void __init kmem_cache_init(void)
78193 */
78194 if (!sizes->cs_cachep)
78195 sizes->cs_cachep = create_kmalloc_cache(names->name,
78196- sizes->cs_size, ARCH_KMALLOC_FLAGS);
78197+ sizes->cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
78198
78199 #ifdef CONFIG_ZONE_DMA
78200 sizes->cs_dmacachep = create_kmalloc_cache(
78201 names->name_dma, sizes->cs_size,
78202 SLAB_CACHE_DMA|ARCH_KMALLOC_FLAGS);
78203 #endif
78204+
78205+#ifdef CONFIG_PAX_USERCOPY_SLABS
78206+ sizes->cs_usercopycachep = create_kmalloc_cache(
78207+ names->name_usercopy, sizes->cs_size,
78208+ ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
78209+#endif
78210+
78211 sizes++;
78212 names++;
78213 }
78214@@ -4365,10 +4379,10 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
78215 }
78216 /* cpu stats */
78217 {
78218- unsigned long allochit = atomic_read(&cachep->allochit);
78219- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
78220- unsigned long freehit = atomic_read(&cachep->freehit);
78221- unsigned long freemiss = atomic_read(&cachep->freemiss);
78222+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
78223+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
78224+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
78225+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
78226
78227 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
78228 allochit, allocmiss, freehit, freemiss);
78229@@ -4600,13 +4614,71 @@ static const struct file_operations proc_slabstats_operations = {
78230 static int __init slab_proc_init(void)
78231 {
78232 #ifdef CONFIG_DEBUG_SLAB_LEAK
78233- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
78234+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
78235 #endif
78236 return 0;
78237 }
78238 module_init(slab_proc_init);
78239 #endif
78240
78241+bool is_usercopy_object(const void *ptr)
78242+{
78243+ struct page *page;
78244+ struct kmem_cache *cachep;
78245+
78246+ if (ZERO_OR_NULL_PTR(ptr))
78247+ return false;
78248+
78249+ if (!slab_is_available())
78250+ return false;
78251+
78252+ if (!virt_addr_valid(ptr))
78253+ return false;
78254+
78255+ page = virt_to_head_page(ptr);
78256+
78257+ if (!PageSlab(page))
78258+ return false;
78259+
78260+ cachep = page->slab_cache;
78261+ return cachep->flags & SLAB_USERCOPY;
78262+}
78263+
78264+#ifdef CONFIG_PAX_USERCOPY
78265+const char *check_heap_object(const void *ptr, unsigned long n)
78266+{
78267+ struct page *page;
78268+ struct kmem_cache *cachep;
78269+ struct slab *slabp;
78270+ unsigned int objnr;
78271+ unsigned long offset;
78272+
78273+ if (ZERO_OR_NULL_PTR(ptr))
78274+ return "<null>";
78275+
78276+ if (!virt_addr_valid(ptr))
78277+ return NULL;
78278+
78279+ page = virt_to_head_page(ptr);
78280+
78281+ if (!PageSlab(page))
78282+ return NULL;
78283+
78284+ cachep = page->slab_cache;
78285+ if (!(cachep->flags & SLAB_USERCOPY))
78286+ return cachep->name;
78287+
78288+ slabp = page->slab_page;
78289+ objnr = obj_to_index(cachep, slabp, ptr);
78290+ BUG_ON(objnr >= cachep->num);
78291+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
78292+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
78293+ return NULL;
78294+
78295+ return cachep->name;
78296+}
78297+#endif
78298+
78299 /**
78300 * ksize - get the actual amount of memory allocated for a given object
78301 * @objp: Pointer to the object
78302diff --git a/mm/slab.h b/mm/slab.h
78303index 34a98d6..73633d1 100644
78304--- a/mm/slab.h
78305+++ b/mm/slab.h
78306@@ -58,7 +58,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
78307
78308 /* Legal flag mask for kmem_cache_create(), for various configurations */
78309 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
78310- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
78311+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | SLAB_USERCOPY)
78312
78313 #if defined(CONFIG_DEBUG_SLAB)
78314 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
78315@@ -220,6 +220,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
78316 return s;
78317
78318 page = virt_to_head_page(x);
78319+
78320+ BUG_ON(!PageSlab(page));
78321+
78322 cachep = page->slab_cache;
78323 if (slab_equal_or_root(cachep, s))
78324 return cachep;
78325diff --git a/mm/slab_common.c b/mm/slab_common.c
78326index 3f3cd97..e050794 100644
78327--- a/mm/slab_common.c
78328+++ b/mm/slab_common.c
78329@@ -209,7 +209,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
78330
78331 err = __kmem_cache_create(s, flags);
78332 if (!err) {
78333- s->refcount = 1;
78334+ atomic_set(&s->refcount, 1);
78335 list_add(&s->list, &slab_caches);
78336 memcg_cache_list_add(memcg, s);
78337 } else {
78338@@ -255,8 +255,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
78339
78340 get_online_cpus();
78341 mutex_lock(&slab_mutex);
78342- s->refcount--;
78343- if (!s->refcount) {
78344+ if (atomic_dec_and_test(&s->refcount)) {
78345 list_del(&s->list);
78346
78347 if (!__kmem_cache_shutdown(s)) {
78348@@ -302,7 +301,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
78349 panic("Creation of kmalloc slab %s size=%zd failed. Reason %d\n",
78350 name, size, err);
78351
78352- s->refcount = -1; /* Exempt from merging for now */
78353+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
78354 }
78355
78356 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
78357@@ -315,7 +314,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
78358
78359 create_boot_cache(s, name, size, flags);
78360 list_add(&s->list, &slab_caches);
78361- s->refcount = 1;
78362+ atomic_set(&s->refcount, 1);
78363 return s;
78364 }
78365
78366diff --git a/mm/slob.c b/mm/slob.c
78367index a99fdf7..f5b6577 100644
78368--- a/mm/slob.c
78369+++ b/mm/slob.c
78370@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
78371 /*
78372 * Return the size of a slob block.
78373 */
78374-static slobidx_t slob_units(slob_t *s)
78375+static slobidx_t slob_units(const slob_t *s)
78376 {
78377 if (s->units > 0)
78378 return s->units;
78379@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
78380 /*
78381 * Return the next free slob block pointer after this one.
78382 */
78383-static slob_t *slob_next(slob_t *s)
78384+static slob_t *slob_next(const slob_t *s)
78385 {
78386 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
78387 slobidx_t next;
78388@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
78389 /*
78390 * Returns true if s is the last free block in its page.
78391 */
78392-static int slob_last(slob_t *s)
78393+static int slob_last(const slob_t *s)
78394 {
78395 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
78396 }
78397
78398-static void *slob_new_pages(gfp_t gfp, int order, int node)
78399+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
78400 {
78401- void *page;
78402+ struct page *page;
78403
78404 #ifdef CONFIG_NUMA
78405 if (node != NUMA_NO_NODE)
78406@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
78407 if (!page)
78408 return NULL;
78409
78410- return page_address(page);
78411+ __SetPageSlab(page);
78412+ return page;
78413 }
78414
78415-static void slob_free_pages(void *b, int order)
78416+static void slob_free_pages(struct page *sp, int order)
78417 {
78418 if (current->reclaim_state)
78419 current->reclaim_state->reclaimed_slab += 1 << order;
78420- free_pages((unsigned long)b, order);
78421+ __ClearPageSlab(sp);
78422+ reset_page_mapcount(sp);
78423+ sp->private = 0;
78424+ __free_pages(sp, order);
78425 }
78426
78427 /*
78428@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
78429
78430 /* Not enough space: must allocate a new page */
78431 if (!b) {
78432- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
78433- if (!b)
78434+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
78435+ if (!sp)
78436 return NULL;
78437- sp = virt_to_page(b);
78438- __SetPageSlab(sp);
78439+ b = page_address(sp);
78440
78441 spin_lock_irqsave(&slob_lock, flags);
78442 sp->units = SLOB_UNITS(PAGE_SIZE);
78443 sp->freelist = b;
78444+ sp->private = 0;
78445 INIT_LIST_HEAD(&sp->list);
78446 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
78447 set_slob_page_free(sp, slob_list);
78448@@ -359,9 +363,7 @@ static void slob_free(void *block, int size)
78449 if (slob_page_free(sp))
78450 clear_slob_page_free(sp);
78451 spin_unlock_irqrestore(&slob_lock, flags);
78452- __ClearPageSlab(sp);
78453- reset_page_mapcount(sp);
78454- slob_free_pages(b, 0);
78455+ slob_free_pages(sp, 0);
78456 return;
78457 }
78458
78459@@ -424,11 +426,10 @@ out:
78460 */
78461
78462 static __always_inline void *
78463-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
78464+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
78465 {
78466- unsigned int *m;
78467- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78468- void *ret;
78469+ slob_t *m;
78470+ void *ret = NULL;
78471
78472 gfp &= gfp_allowed_mask;
78473
78474@@ -442,23 +443,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
78475
78476 if (!m)
78477 return NULL;
78478- *m = size;
78479+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
78480+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
78481+ m[0].units = size;
78482+ m[1].units = align;
78483 ret = (void *)m + align;
78484
78485 trace_kmalloc_node(caller, ret,
78486 size, size + align, gfp, node);
78487 } else {
78488 unsigned int order = get_order(size);
78489+ struct page *page;
78490
78491 if (likely(order))
78492 gfp |= __GFP_COMP;
78493- ret = slob_new_pages(gfp, order, node);
78494+ page = slob_new_pages(gfp, order, node);
78495+ if (page) {
78496+ ret = page_address(page);
78497+ page->private = size;
78498+ }
78499
78500 trace_kmalloc_node(caller, ret,
78501 size, PAGE_SIZE << order, gfp, node);
78502 }
78503
78504- kmemleak_alloc(ret, size, 1, gfp);
78505+ return ret;
78506+}
78507+
78508+static __always_inline void *
78509+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
78510+{
78511+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78512+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
78513+
78514+ if (!ZERO_OR_NULL_PTR(ret))
78515+ kmemleak_alloc(ret, size, 1, gfp);
78516 return ret;
78517 }
78518
78519@@ -494,33 +513,110 @@ void kfree(const void *block)
78520 kmemleak_free(block);
78521
78522 sp = virt_to_page(block);
78523- if (PageSlab(sp)) {
78524+ VM_BUG_ON(!PageSlab(sp));
78525+ if (!sp->private) {
78526 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78527- unsigned int *m = (unsigned int *)(block - align);
78528- slob_free(m, *m + align);
78529- } else
78530+ slob_t *m = (slob_t *)(block - align);
78531+ slob_free(m, m[0].units + align);
78532+ } else {
78533+ __ClearPageSlab(sp);
78534+ reset_page_mapcount(sp);
78535+ sp->private = 0;
78536 __free_pages(sp, compound_order(sp));
78537+ }
78538 }
78539 EXPORT_SYMBOL(kfree);
78540
78541+bool is_usercopy_object(const void *ptr)
78542+{
78543+ if (!slab_is_available())
78544+ return false;
78545+
78546+ // PAX: TODO
78547+
78548+ return false;
78549+}
78550+
78551+#ifdef CONFIG_PAX_USERCOPY
78552+const char *check_heap_object(const void *ptr, unsigned long n)
78553+{
78554+ struct page *page;
78555+ const slob_t *free;
78556+ const void *base;
78557+ unsigned long flags;
78558+
78559+ if (ZERO_OR_NULL_PTR(ptr))
78560+ return "<null>";
78561+
78562+ if (!virt_addr_valid(ptr))
78563+ return NULL;
78564+
78565+ page = virt_to_head_page(ptr);
78566+ if (!PageSlab(page))
78567+ return NULL;
78568+
78569+ if (page->private) {
78570+ base = page;
78571+ if (base <= ptr && n <= page->private - (ptr - base))
78572+ return NULL;
78573+ return "<slob>";
78574+ }
78575+
78576+ /* some tricky double walking to find the chunk */
78577+ spin_lock_irqsave(&slob_lock, flags);
78578+ base = (void *)((unsigned long)ptr & PAGE_MASK);
78579+ free = page->freelist;
78580+
78581+ while (!slob_last(free) && (void *)free <= ptr) {
78582+ base = free + slob_units(free);
78583+ free = slob_next(free);
78584+ }
78585+
78586+ while (base < (void *)free) {
78587+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
78588+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
78589+ int offset;
78590+
78591+ if (ptr < base + align)
78592+ break;
78593+
78594+ offset = ptr - base - align;
78595+ if (offset >= m) {
78596+ base += size;
78597+ continue;
78598+ }
78599+
78600+ if (n > m - offset)
78601+ break;
78602+
78603+ spin_unlock_irqrestore(&slob_lock, flags);
78604+ return NULL;
78605+ }
78606+
78607+ spin_unlock_irqrestore(&slob_lock, flags);
78608+ return "<slob>";
78609+}
78610+#endif
78611+
78612 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
78613 size_t ksize(const void *block)
78614 {
78615 struct page *sp;
78616 int align;
78617- unsigned int *m;
78618+ slob_t *m;
78619
78620 BUG_ON(!block);
78621 if (unlikely(block == ZERO_SIZE_PTR))
78622 return 0;
78623
78624 sp = virt_to_page(block);
78625- if (unlikely(!PageSlab(sp)))
78626- return PAGE_SIZE << compound_order(sp);
78627+ VM_BUG_ON(!PageSlab(sp));
78628+ if (sp->private)
78629+ return sp->private;
78630
78631 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78632- m = (unsigned int *)(block - align);
78633- return SLOB_UNITS(*m) * SLOB_UNIT;
78634+ m = (slob_t *)(block - align);
78635+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
78636 }
78637 EXPORT_SYMBOL(ksize);
78638
78639@@ -536,23 +632,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
78640
78641 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
78642 {
78643- void *b;
78644+ void *b = NULL;
78645
78646 flags &= gfp_allowed_mask;
78647
78648 lockdep_trace_alloc(flags);
78649
78650+#ifdef CONFIG_PAX_USERCOPY_SLABS
78651+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
78652+#else
78653 if (c->size < PAGE_SIZE) {
78654 b = slob_alloc(c->size, flags, c->align, node);
78655 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
78656 SLOB_UNITS(c->size) * SLOB_UNIT,
78657 flags, node);
78658 } else {
78659- b = slob_new_pages(flags, get_order(c->size), node);
78660+ struct page *sp;
78661+
78662+ sp = slob_new_pages(flags, get_order(c->size), node);
78663+ if (sp) {
78664+ b = page_address(sp);
78665+ sp->private = c->size;
78666+ }
78667 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
78668 PAGE_SIZE << get_order(c->size),
78669 flags, node);
78670 }
78671+#endif
78672
78673 if (c->ctor)
78674 c->ctor(b);
78675@@ -564,10 +670,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
78676
78677 static void __kmem_cache_free(void *b, int size)
78678 {
78679- if (size < PAGE_SIZE)
78680+ struct page *sp;
78681+
78682+ sp = virt_to_page(b);
78683+ BUG_ON(!PageSlab(sp));
78684+ if (!sp->private)
78685 slob_free(b, size);
78686 else
78687- slob_free_pages(b, get_order(size));
78688+ slob_free_pages(sp, get_order(size));
78689 }
78690
78691 static void kmem_rcu_free(struct rcu_head *head)
78692@@ -580,17 +690,31 @@ static void kmem_rcu_free(struct rcu_head *head)
78693
78694 void kmem_cache_free(struct kmem_cache *c, void *b)
78695 {
78696+ int size = c->size;
78697+
78698+#ifdef CONFIG_PAX_USERCOPY_SLABS
78699+ if (size + c->align < PAGE_SIZE) {
78700+ size += c->align;
78701+ b -= c->align;
78702+ }
78703+#endif
78704+
78705 kmemleak_free_recursive(b, c->flags);
78706 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
78707 struct slob_rcu *slob_rcu;
78708- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
78709- slob_rcu->size = c->size;
78710+ slob_rcu = b + (size - sizeof(struct slob_rcu));
78711+ slob_rcu->size = size;
78712 call_rcu(&slob_rcu->head, kmem_rcu_free);
78713 } else {
78714- __kmem_cache_free(b, c->size);
78715+ __kmem_cache_free(b, size);
78716 }
78717
78718+#ifdef CONFIG_PAX_USERCOPY_SLABS
78719+ trace_kfree(_RET_IP_, b);
78720+#else
78721 trace_kmem_cache_free(_RET_IP_, b);
78722+#endif
78723+
78724 }
78725 EXPORT_SYMBOL(kmem_cache_free);
78726
78727diff --git a/mm/slub.c b/mm/slub.c
78728index ba2ca53..00b1f4e 100644
78729--- a/mm/slub.c
78730+++ b/mm/slub.c
78731@@ -197,7 +197,7 @@ struct track {
78732
78733 enum track_item { TRACK_ALLOC, TRACK_FREE };
78734
78735-#ifdef CONFIG_SYSFS
78736+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78737 static int sysfs_slab_add(struct kmem_cache *);
78738 static int sysfs_slab_alias(struct kmem_cache *, const char *);
78739 static void sysfs_slab_remove(struct kmem_cache *);
78740@@ -518,7 +518,7 @@ static void print_track(const char *s, struct track *t)
78741 if (!t->addr)
78742 return;
78743
78744- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
78745+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
78746 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
78747 #ifdef CONFIG_STACKTRACE
78748 {
78749@@ -2653,7 +2653,7 @@ static int slub_min_objects;
78750 * Merge control. If this is set then no merging of slab caches will occur.
78751 * (Could be removed. This was introduced to pacify the merge skeptics.)
78752 */
78753-static int slub_nomerge;
78754+static int slub_nomerge = 1;
78755
78756 /*
78757 * Calculate the order of allocation given an slab object size.
78758@@ -3181,6 +3181,10 @@ EXPORT_SYMBOL(kmalloc_caches);
78759 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
78760 #endif
78761
78762+#ifdef CONFIG_PAX_USERCOPY_SLABS
78763+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
78764+#endif
78765+
78766 static int __init setup_slub_min_order(char *str)
78767 {
78768 get_option(&str, &slub_min_order);
78769@@ -3272,6 +3276,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
78770 return kmalloc_dma_caches[index];
78771
78772 #endif
78773+
78774+#ifdef CONFIG_PAX_USERCOPY_SLABS
78775+ if (flags & SLAB_USERCOPY)
78776+ return kmalloc_usercopy_caches[index];
78777+
78778+#endif
78779+
78780 return kmalloc_caches[index];
78781 }
78782
78783@@ -3340,6 +3351,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
78784 EXPORT_SYMBOL(__kmalloc_node);
78785 #endif
78786
78787+bool is_usercopy_object(const void *ptr)
78788+{
78789+ struct page *page;
78790+ struct kmem_cache *s;
78791+
78792+ if (ZERO_OR_NULL_PTR(ptr))
78793+ return false;
78794+
78795+ if (!slab_is_available())
78796+ return false;
78797+
78798+ if (!virt_addr_valid(ptr))
78799+ return false;
78800+
78801+ page = virt_to_head_page(ptr);
78802+
78803+ if (!PageSlab(page))
78804+ return false;
78805+
78806+ s = page->slab_cache;
78807+ return s->flags & SLAB_USERCOPY;
78808+}
78809+
78810+#ifdef CONFIG_PAX_USERCOPY
78811+const char *check_heap_object(const void *ptr, unsigned long n)
78812+{
78813+ struct page *page;
78814+ struct kmem_cache *s;
78815+ unsigned long offset;
78816+
78817+ if (ZERO_OR_NULL_PTR(ptr))
78818+ return "<null>";
78819+
78820+ if (!virt_addr_valid(ptr))
78821+ return NULL;
78822+
78823+ page = virt_to_head_page(ptr);
78824+
78825+ if (!PageSlab(page))
78826+ return NULL;
78827+
78828+ s = page->slab_cache;
78829+ if (!(s->flags & SLAB_USERCOPY))
78830+ return s->name;
78831+
78832+ offset = (ptr - page_address(page)) % s->size;
78833+ if (offset <= s->object_size && n <= s->object_size - offset)
78834+ return NULL;
78835+
78836+ return s->name;
78837+}
78838+#endif
78839+
78840 size_t ksize(const void *object)
78841 {
78842 struct page *page;
78843@@ -3712,17 +3776,17 @@ void __init kmem_cache_init(void)
78844
78845 /* Caches that are not of the two-to-the-power-of size */
78846 if (KMALLOC_MIN_SIZE <= 32) {
78847- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
78848+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
78849 caches++;
78850 }
78851
78852 if (KMALLOC_MIN_SIZE <= 64) {
78853- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
78854+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
78855 caches++;
78856 }
78857
78858 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
78859- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
78860+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
78861 caches++;
78862 }
78863
78864@@ -3764,6 +3828,22 @@ void __init kmem_cache_init(void)
78865 }
78866 }
78867 #endif
78868+
78869+#ifdef CONFIG_PAX_USERCOPY_SLABS
78870+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
78871+ struct kmem_cache *s = kmalloc_caches[i];
78872+
78873+ if (s && s->size) {
78874+ char *name = kasprintf(GFP_NOWAIT,
78875+ "usercopy-kmalloc-%d", s->object_size);
78876+
78877+ BUG_ON(!name);
78878+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
78879+ s->object_size, SLAB_USERCOPY);
78880+ }
78881+ }
78882+#endif
78883+
78884 printk(KERN_INFO
78885 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
78886 " CPUs=%d, Nodes=%d\n",
78887@@ -3790,7 +3870,7 @@ static int slab_unmergeable(struct kmem_cache *s)
78888 /*
78889 * We may have set a slab to be unmergeable during bootstrap.
78890 */
78891- if (s->refcount < 0)
78892+ if (atomic_read(&s->refcount) < 0)
78893 return 1;
78894
78895 return 0;
78896@@ -3848,7 +3928,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
78897
78898 s = find_mergeable(memcg, size, align, flags, name, ctor);
78899 if (s) {
78900- s->refcount++;
78901+ atomic_inc(&s->refcount);
78902 /*
78903 * Adjust the object sizes so that we clear
78904 * the complete object on kzalloc.
78905@@ -3857,7 +3937,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
78906 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
78907
78908 if (sysfs_slab_alias(s, name)) {
78909- s->refcount--;
78910+ atomic_dec(&s->refcount);
78911 s = NULL;
78912 }
78913 }
78914@@ -3919,7 +3999,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
78915 return NOTIFY_OK;
78916 }
78917
78918-static struct notifier_block __cpuinitdata slab_notifier = {
78919+static struct notifier_block slab_notifier = {
78920 .notifier_call = slab_cpuup_callback
78921 };
78922
78923@@ -3977,7 +4057,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
78924 }
78925 #endif
78926
78927-#ifdef CONFIG_SYSFS
78928+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78929 static int count_inuse(struct page *page)
78930 {
78931 return page->inuse;
78932@@ -4364,12 +4444,12 @@ static void resiliency_test(void)
78933 validate_slab_cache(kmalloc_caches[9]);
78934 }
78935 #else
78936-#ifdef CONFIG_SYSFS
78937+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78938 static void resiliency_test(void) {};
78939 #endif
78940 #endif
78941
78942-#ifdef CONFIG_SYSFS
78943+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78944 enum slab_stat_type {
78945 SL_ALL, /* All slabs */
78946 SL_PARTIAL, /* Only partially allocated slabs */
78947@@ -4613,7 +4693,7 @@ SLAB_ATTR_RO(ctor);
78948
78949 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
78950 {
78951- return sprintf(buf, "%d\n", s->refcount - 1);
78952+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
78953 }
78954 SLAB_ATTR_RO(aliases);
78955
78956@@ -5266,6 +5346,7 @@ static char *create_unique_id(struct kmem_cache *s)
78957 return name;
78958 }
78959
78960+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78961 static int sysfs_slab_add(struct kmem_cache *s)
78962 {
78963 int err;
78964@@ -5323,6 +5404,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
78965 kobject_del(&s->kobj);
78966 kobject_put(&s->kobj);
78967 }
78968+#endif
78969
78970 /*
78971 * Need to buffer aliases during bootup until sysfs becomes
78972@@ -5336,6 +5418,7 @@ struct saved_alias {
78973
78974 static struct saved_alias *alias_list;
78975
78976+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78977 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
78978 {
78979 struct saved_alias *al;
78980@@ -5358,6 +5441,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
78981 alias_list = al;
78982 return 0;
78983 }
78984+#endif
78985
78986 static int __init slab_sysfs_init(void)
78987 {
78988diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
78989index 1b7e22a..3fcd4f3 100644
78990--- a/mm/sparse-vmemmap.c
78991+++ b/mm/sparse-vmemmap.c
78992@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
78993 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
78994 if (!p)
78995 return NULL;
78996- pud_populate(&init_mm, pud, p);
78997+ pud_populate_kernel(&init_mm, pud, p);
78998 }
78999 return pud;
79000 }
79001@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
79002 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
79003 if (!p)
79004 return NULL;
79005- pgd_populate(&init_mm, pgd, p);
79006+ pgd_populate_kernel(&init_mm, pgd, p);
79007 }
79008 return pgd;
79009 }
79010diff --git a/mm/sparse.c b/mm/sparse.c
79011index 6b5fb76..db0c190 100644
79012--- a/mm/sparse.c
79013+++ b/mm/sparse.c
79014@@ -782,7 +782,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
79015
79016 for (i = 0; i < PAGES_PER_SECTION; i++) {
79017 if (PageHWPoison(&memmap[i])) {
79018- atomic_long_sub(1, &mce_bad_pages);
79019+ atomic_long_sub_unchecked(1, &mce_bad_pages);
79020 ClearPageHWPoison(&memmap[i]);
79021 }
79022 }
79023diff --git a/mm/swap.c b/mm/swap.c
79024index 6310dc2..3662b3f 100644
79025--- a/mm/swap.c
79026+++ b/mm/swap.c
79027@@ -30,6 +30,7 @@
79028 #include <linux/backing-dev.h>
79029 #include <linux/memcontrol.h>
79030 #include <linux/gfp.h>
79031+#include <linux/hugetlb.h>
79032
79033 #include "internal.h"
79034
79035@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
79036
79037 __page_cache_release(page);
79038 dtor = get_compound_page_dtor(page);
79039+ if (!PageHuge(page))
79040+ BUG_ON(dtor != free_compound_page);
79041 (*dtor)(page);
79042 }
79043
79044diff --git a/mm/swapfile.c b/mm/swapfile.c
79045index e97a0e5..b50e796 100644
79046--- a/mm/swapfile.c
79047+++ b/mm/swapfile.c
79048@@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
79049
79050 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
79051 /* Activity counter to indicate that a swapon or swapoff has occurred */
79052-static atomic_t proc_poll_event = ATOMIC_INIT(0);
79053+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
79054
79055 static inline unsigned char swap_count(unsigned char ent)
79056 {
79057@@ -1608,7 +1608,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
79058 }
79059 filp_close(swap_file, NULL);
79060 err = 0;
79061- atomic_inc(&proc_poll_event);
79062+ atomic_inc_unchecked(&proc_poll_event);
79063 wake_up_interruptible(&proc_poll_wait);
79064
79065 out_dput:
79066@@ -1625,8 +1625,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
79067
79068 poll_wait(file, &proc_poll_wait, wait);
79069
79070- if (seq->poll_event != atomic_read(&proc_poll_event)) {
79071- seq->poll_event = atomic_read(&proc_poll_event);
79072+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
79073+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
79074 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
79075 }
79076
79077@@ -1724,7 +1724,7 @@ static int swaps_open(struct inode *inode, struct file *file)
79078 return ret;
79079
79080 seq = file->private_data;
79081- seq->poll_event = atomic_read(&proc_poll_event);
79082+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
79083 return 0;
79084 }
79085
79086@@ -2066,7 +2066,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
79087 (frontswap_map) ? "FS" : "");
79088
79089 mutex_unlock(&swapon_mutex);
79090- atomic_inc(&proc_poll_event);
79091+ atomic_inc_unchecked(&proc_poll_event);
79092 wake_up_interruptible(&proc_poll_wait);
79093
79094 if (S_ISREG(inode->i_mode))
79095diff --git a/mm/util.c b/mm/util.c
79096index c55e26b..3f913a9 100644
79097--- a/mm/util.c
79098+++ b/mm/util.c
79099@@ -292,6 +292,12 @@ done:
79100 void arch_pick_mmap_layout(struct mm_struct *mm)
79101 {
79102 mm->mmap_base = TASK_UNMAPPED_BASE;
79103+
79104+#ifdef CONFIG_PAX_RANDMMAP
79105+ if (mm->pax_flags & MF_PAX_RANDMMAP)
79106+ mm->mmap_base += mm->delta_mmap;
79107+#endif
79108+
79109 mm->get_unmapped_area = arch_get_unmapped_area;
79110 mm->unmap_area = arch_unmap_area;
79111 }
79112diff --git a/mm/vmalloc.c b/mm/vmalloc.c
79113index 5123a16..f234a48 100644
79114--- a/mm/vmalloc.c
79115+++ b/mm/vmalloc.c
79116@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
79117
79118 pte = pte_offset_kernel(pmd, addr);
79119 do {
79120- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
79121- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
79122+
79123+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79124+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
79125+ BUG_ON(!pte_exec(*pte));
79126+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
79127+ continue;
79128+ }
79129+#endif
79130+
79131+ {
79132+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
79133+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
79134+ }
79135 } while (pte++, addr += PAGE_SIZE, addr != end);
79136 }
79137
79138@@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
79139 pte = pte_alloc_kernel(pmd, addr);
79140 if (!pte)
79141 return -ENOMEM;
79142+
79143+ pax_open_kernel();
79144 do {
79145 struct page *page = pages[*nr];
79146
79147- if (WARN_ON(!pte_none(*pte)))
79148+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79149+ if (pgprot_val(prot) & _PAGE_NX)
79150+#endif
79151+
79152+ if (!pte_none(*pte)) {
79153+ pax_close_kernel();
79154+ WARN_ON(1);
79155 return -EBUSY;
79156- if (WARN_ON(!page))
79157+ }
79158+ if (!page) {
79159+ pax_close_kernel();
79160+ WARN_ON(1);
79161 return -ENOMEM;
79162+ }
79163 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
79164 (*nr)++;
79165 } while (pte++, addr += PAGE_SIZE, addr != end);
79166+ pax_close_kernel();
79167 return 0;
79168 }
79169
79170@@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
79171 pmd_t *pmd;
79172 unsigned long next;
79173
79174- pmd = pmd_alloc(&init_mm, pud, addr);
79175+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
79176 if (!pmd)
79177 return -ENOMEM;
79178 do {
79179@@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
79180 pud_t *pud;
79181 unsigned long next;
79182
79183- pud = pud_alloc(&init_mm, pgd, addr);
79184+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
79185 if (!pud)
79186 return -ENOMEM;
79187 do {
79188@@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
79189 * and fall back on vmalloc() if that fails. Others
79190 * just put it in the vmalloc space.
79191 */
79192-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
79193+#ifdef CONFIG_MODULES
79194+#ifdef MODULES_VADDR
79195 unsigned long addr = (unsigned long)x;
79196 if (addr >= MODULES_VADDR && addr < MODULES_END)
79197 return 1;
79198 #endif
79199+
79200+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79201+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
79202+ return 1;
79203+#endif
79204+
79205+#endif
79206+
79207 return is_vmalloc_addr(x);
79208 }
79209
79210@@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
79211
79212 if (!pgd_none(*pgd)) {
79213 pud_t *pud = pud_offset(pgd, addr);
79214+#ifdef CONFIG_X86
79215+ if (!pud_large(*pud))
79216+#endif
79217 if (!pud_none(*pud)) {
79218 pmd_t *pmd = pmd_offset(pud, addr);
79219+#ifdef CONFIG_X86
79220+ if (!pmd_large(*pmd))
79221+#endif
79222 if (!pmd_none(*pmd)) {
79223 pte_t *ptep, pte;
79224
79225@@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
79226 * Allocate a region of KVA of the specified size and alignment, within the
79227 * vstart and vend.
79228 */
79229-static struct vmap_area *alloc_vmap_area(unsigned long size,
79230+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
79231 unsigned long align,
79232 unsigned long vstart, unsigned long vend,
79233 int node, gfp_t gfp_mask)
79234@@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
79235 struct vm_struct *area;
79236
79237 BUG_ON(in_interrupt());
79238+
79239+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79240+ if (flags & VM_KERNEXEC) {
79241+ if (start != VMALLOC_START || end != VMALLOC_END)
79242+ return NULL;
79243+ start = (unsigned long)MODULES_EXEC_VADDR;
79244+ end = (unsigned long)MODULES_EXEC_END;
79245+ }
79246+#endif
79247+
79248 if (flags & VM_IOREMAP) {
79249 int bit = fls(size);
79250
79251@@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
79252 if (count > totalram_pages)
79253 return NULL;
79254
79255+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79256+ if (!(pgprot_val(prot) & _PAGE_NX))
79257+ flags |= VM_KERNEXEC;
79258+#endif
79259+
79260 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
79261 __builtin_return_address(0));
79262 if (!area)
79263@@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
79264 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
79265 goto fail;
79266
79267+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79268+ if (!(pgprot_val(prot) & _PAGE_NX))
79269+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
79270+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
79271+ else
79272+#endif
79273+
79274 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
79275 start, end, node, gfp_mask, caller);
79276 if (!area)
79277@@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
79278 * For tight control over page level allocator and protection flags
79279 * use __vmalloc() instead.
79280 */
79281-
79282 void *vmalloc_exec(unsigned long size)
79283 {
79284- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
79285+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
79286 -1, __builtin_return_address(0));
79287 }
79288
79289@@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
79290 unsigned long uaddr = vma->vm_start;
79291 unsigned long usize = vma->vm_end - vma->vm_start;
79292
79293+ BUG_ON(vma->vm_mirror);
79294+
79295 if ((PAGE_SIZE-1) & (unsigned long)addr)
79296 return -EINVAL;
79297
79298@@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
79299 v->addr, v->addr + v->size, v->size);
79300
79301 if (v->caller)
79302+#ifdef CONFIG_GRKERNSEC_HIDESYM
79303+ seq_printf(m, " %pK", v->caller);
79304+#else
79305 seq_printf(m, " %pS", v->caller);
79306+#endif
79307
79308 if (v->nr_pages)
79309 seq_printf(m, " pages=%d", v->nr_pages);
79310diff --git a/mm/vmstat.c b/mm/vmstat.c
79311index 9800306..76b4b27 100644
79312--- a/mm/vmstat.c
79313+++ b/mm/vmstat.c
79314@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
79315 *
79316 * vm_stat contains the global counters
79317 */
79318-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
79319+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
79320 EXPORT_SYMBOL(vm_stat);
79321
79322 #ifdef CONFIG_SMP
79323@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
79324 v = p->vm_stat_diff[i];
79325 p->vm_stat_diff[i] = 0;
79326 local_irq_restore(flags);
79327- atomic_long_add(v, &zone->vm_stat[i]);
79328+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
79329 global_diff[i] += v;
79330 #ifdef CONFIG_NUMA
79331 /* 3 seconds idle till flush */
79332@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
79333
79334 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
79335 if (global_diff[i])
79336- atomic_long_add(global_diff[i], &vm_stat[i]);
79337+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
79338 }
79339
79340 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
79341@@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
79342 if (pset->vm_stat_diff[i]) {
79343 int v = pset->vm_stat_diff[i];
79344 pset->vm_stat_diff[i] = 0;
79345- atomic_long_add(v, &zone->vm_stat[i]);
79346- atomic_long_add(v, &vm_stat[i]);
79347+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
79348+ atomic_long_add_unchecked(v, &vm_stat[i]);
79349 }
79350 }
79351 #endif
79352@@ -1223,7 +1223,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
79353 return NOTIFY_OK;
79354 }
79355
79356-static struct notifier_block __cpuinitdata vmstat_notifier =
79357+static struct notifier_block vmstat_notifier =
79358 { &vmstat_cpuup_callback, NULL, 0 };
79359 #endif
79360
79361@@ -1238,10 +1238,20 @@ static int __init setup_vmstat(void)
79362 start_cpu_timer(cpu);
79363 #endif
79364 #ifdef CONFIG_PROC_FS
79365- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
79366- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
79367- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
79368- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
79369+ {
79370+ mode_t gr_mode = S_IRUGO;
79371+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79372+ gr_mode = S_IRUSR;
79373+#endif
79374+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
79375+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
79376+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79377+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
79378+#else
79379+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
79380+#endif
79381+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
79382+ }
79383 #endif
79384 return 0;
79385 }
79386diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
79387index a292e80..785ee68 100644
79388--- a/net/8021q/vlan.c
79389+++ b/net/8021q/vlan.c
79390@@ -485,7 +485,7 @@ out:
79391 return NOTIFY_DONE;
79392 }
79393
79394-static struct notifier_block vlan_notifier_block __read_mostly = {
79395+static struct notifier_block vlan_notifier_block = {
79396 .notifier_call = vlan_device_event,
79397 };
79398
79399@@ -560,8 +560,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
79400 err = -EPERM;
79401 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
79402 break;
79403- if ((args.u.name_type >= 0) &&
79404- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
79405+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
79406 struct vlan_net *vn;
79407
79408 vn = net_generic(net, vlan_net_id);
79409diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
79410index 02efb25..41541a9 100644
79411--- a/net/9p/trans_fd.c
79412+++ b/net/9p/trans_fd.c
79413@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
79414 oldfs = get_fs();
79415 set_fs(get_ds());
79416 /* The cast to a user pointer is valid due to the set_fs() */
79417- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
79418+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
79419 set_fs(oldfs);
79420
79421 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
79422diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
79423index 876fbe8..8bbea9f 100644
79424--- a/net/atm/atm_misc.c
79425+++ b/net/atm/atm_misc.c
79426@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
79427 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
79428 return 1;
79429 atm_return(vcc, truesize);
79430- atomic_inc(&vcc->stats->rx_drop);
79431+ atomic_inc_unchecked(&vcc->stats->rx_drop);
79432 return 0;
79433 }
79434 EXPORT_SYMBOL(atm_charge);
79435@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
79436 }
79437 }
79438 atm_return(vcc, guess);
79439- atomic_inc(&vcc->stats->rx_drop);
79440+ atomic_inc_unchecked(&vcc->stats->rx_drop);
79441 return NULL;
79442 }
79443 EXPORT_SYMBOL(atm_alloc_charge);
79444@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
79445
79446 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
79447 {
79448-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
79449+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
79450 __SONET_ITEMS
79451 #undef __HANDLE_ITEM
79452 }
79453@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
79454
79455 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
79456 {
79457-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
79458+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
79459 __SONET_ITEMS
79460 #undef __HANDLE_ITEM
79461 }
79462diff --git a/net/atm/lec.h b/net/atm/lec.h
79463index a86aff9..3a0d6f6 100644
79464--- a/net/atm/lec.h
79465+++ b/net/atm/lec.h
79466@@ -48,7 +48,7 @@ struct lane2_ops {
79467 const u8 *tlvs, u32 sizeoftlvs);
79468 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
79469 const u8 *tlvs, u32 sizeoftlvs);
79470-};
79471+} __no_const;
79472
79473 /*
79474 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
79475diff --git a/net/atm/proc.c b/net/atm/proc.c
79476index 0d020de..011c7bb 100644
79477--- a/net/atm/proc.c
79478+++ b/net/atm/proc.c
79479@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
79480 const struct k_atm_aal_stats *stats)
79481 {
79482 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
79483- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
79484- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
79485- atomic_read(&stats->rx_drop));
79486+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
79487+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
79488+ atomic_read_unchecked(&stats->rx_drop));
79489 }
79490
79491 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
79492diff --git a/net/atm/resources.c b/net/atm/resources.c
79493index 0447d5d..3cf4728 100644
79494--- a/net/atm/resources.c
79495+++ b/net/atm/resources.c
79496@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
79497 static void copy_aal_stats(struct k_atm_aal_stats *from,
79498 struct atm_aal_stats *to)
79499 {
79500-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
79501+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
79502 __AAL_STAT_ITEMS
79503 #undef __HANDLE_ITEM
79504 }
79505@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
79506 static void subtract_aal_stats(struct k_atm_aal_stats *from,
79507 struct atm_aal_stats *to)
79508 {
79509-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
79510+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
79511 __AAL_STAT_ITEMS
79512 #undef __HANDLE_ITEM
79513 }
79514diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
79515index 7d02ebd..4d4cc01 100644
79516--- a/net/batman-adv/bat_iv_ogm.c
79517+++ b/net/batman-adv/bat_iv_ogm.c
79518@@ -63,7 +63,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
79519
79520 /* randomize initial seqno to avoid collision */
79521 get_random_bytes(&random_seqno, sizeof(random_seqno));
79522- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
79523+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
79524
79525 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
79526 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
79527@@ -615,9 +615,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
79528 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
79529
79530 /* change sequence number to network order */
79531- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
79532+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
79533 batadv_ogm_packet->seqno = htonl(seqno);
79534- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
79535+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
79536
79537 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
79538 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
79539@@ -1022,7 +1022,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
79540 return;
79541
79542 /* could be changed by schedule_own_packet() */
79543- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
79544+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
79545
79546 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
79547 has_directlink_flag = 1;
79548diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
79549index f1d37cd..4190879 100644
79550--- a/net/batman-adv/hard-interface.c
79551+++ b/net/batman-adv/hard-interface.c
79552@@ -370,7 +370,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
79553 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
79554 dev_add_pack(&hard_iface->batman_adv_ptype);
79555
79556- atomic_set(&hard_iface->frag_seqno, 1);
79557+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
79558 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
79559 hard_iface->net_dev->name);
79560
79561@@ -493,7 +493,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
79562 /* This can't be called via a bat_priv callback because
79563 * we have no bat_priv yet.
79564 */
79565- atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
79566+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
79567 hard_iface->bat_iv.ogm_buff = NULL;
79568
79569 return hard_iface;
79570diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
79571index 6b548fd..fc32c8d 100644
79572--- a/net/batman-adv/soft-interface.c
79573+++ b/net/batman-adv/soft-interface.c
79574@@ -252,7 +252,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
79575 primary_if->net_dev->dev_addr, ETH_ALEN);
79576
79577 /* set broadcast sequence number */
79578- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
79579+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
79580 bcast_packet->seqno = htonl(seqno);
79581
79582 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
79583@@ -497,7 +497,7 @@ struct net_device *batadv_softif_create(const char *name)
79584 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
79585
79586 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
79587- atomic_set(&bat_priv->bcast_seqno, 1);
79588+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
79589 atomic_set(&bat_priv->tt.vn, 0);
79590 atomic_set(&bat_priv->tt.local_changes, 0);
79591 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
79592diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
79593index ae9ac9a..11e0fe7 100644
79594--- a/net/batman-adv/types.h
79595+++ b/net/batman-adv/types.h
79596@@ -48,7 +48,7 @@
79597 struct batadv_hard_iface_bat_iv {
79598 unsigned char *ogm_buff;
79599 int ogm_buff_len;
79600- atomic_t ogm_seqno;
79601+ atomic_unchecked_t ogm_seqno;
79602 };
79603
79604 struct batadv_hard_iface {
79605@@ -56,7 +56,7 @@ struct batadv_hard_iface {
79606 int16_t if_num;
79607 char if_status;
79608 struct net_device *net_dev;
79609- atomic_t frag_seqno;
79610+ atomic_unchecked_t frag_seqno;
79611 struct kobject *hardif_obj;
79612 atomic_t refcount;
79613 struct packet_type batman_adv_ptype;
79614@@ -284,7 +284,7 @@ struct batadv_priv {
79615 atomic_t orig_interval; /* uint */
79616 atomic_t hop_penalty; /* uint */
79617 atomic_t log_level; /* uint */
79618- atomic_t bcast_seqno;
79619+ atomic_unchecked_t bcast_seqno;
79620 atomic_t bcast_queue_left;
79621 atomic_t batman_queue_left;
79622 char num_ifaces;
79623diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
79624index 10aff49..ea8e021 100644
79625--- a/net/batman-adv/unicast.c
79626+++ b/net/batman-adv/unicast.c
79627@@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
79628 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
79629 frag2->flags = large_tail;
79630
79631- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
79632+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
79633 frag1->seqno = htons(seqno - 1);
79634 frag2->seqno = htons(seqno);
79635
79636diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
79637index 07f0739..3c42e34 100644
79638--- a/net/bluetooth/hci_sock.c
79639+++ b/net/bluetooth/hci_sock.c
79640@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
79641 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
79642 }
79643
79644- len = min_t(unsigned int, len, sizeof(uf));
79645+ len = min((size_t)len, sizeof(uf));
79646 if (copy_from_user(&uf, optval, len)) {
79647 err = -EFAULT;
79648 break;
79649diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
79650index 22e6583..426e2f3 100644
79651--- a/net/bluetooth/l2cap_core.c
79652+++ b/net/bluetooth/l2cap_core.c
79653@@ -3400,8 +3400,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
79654 break;
79655
79656 case L2CAP_CONF_RFC:
79657- if (olen == sizeof(rfc))
79658- memcpy(&rfc, (void *)val, olen);
79659+ if (olen != sizeof(rfc))
79660+ break;
79661+
79662+ memcpy(&rfc, (void *)val, olen);
79663
79664 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
79665 rfc.mode != chan->mode)
79666diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
79667index 1bcfb84..dad9f98 100644
79668--- a/net/bluetooth/l2cap_sock.c
79669+++ b/net/bluetooth/l2cap_sock.c
79670@@ -479,7 +479,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
79671 struct sock *sk = sock->sk;
79672 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
79673 struct l2cap_options opts;
79674- int len, err = 0;
79675+ int err = 0;
79676+ size_t len = optlen;
79677 u32 opt;
79678
79679 BT_DBG("sk %p", sk);
79680@@ -501,7 +502,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
79681 opts.max_tx = chan->max_tx;
79682 opts.txwin_size = chan->tx_win;
79683
79684- len = min_t(unsigned int, sizeof(opts), optlen);
79685+ len = min(sizeof(opts), len);
79686 if (copy_from_user((char *) &opts, optval, len)) {
79687 err = -EFAULT;
79688 break;
79689@@ -581,7 +582,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
79690 struct bt_security sec;
79691 struct bt_power pwr;
79692 struct l2cap_conn *conn;
79693- int len, err = 0;
79694+ int err = 0;
79695+ size_t len = optlen;
79696 u32 opt;
79697
79698 BT_DBG("sk %p", sk);
79699@@ -604,7 +606,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
79700
79701 sec.level = BT_SECURITY_LOW;
79702
79703- len = min_t(unsigned int, sizeof(sec), optlen);
79704+ len = min(sizeof(sec), len);
79705 if (copy_from_user((char *) &sec, optval, len)) {
79706 err = -EFAULT;
79707 break;
79708@@ -701,7 +703,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
79709
79710 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
79711
79712- len = min_t(unsigned int, sizeof(pwr), optlen);
79713+ len = min(sizeof(pwr), len);
79714 if (copy_from_user((char *) &pwr, optval, len)) {
79715 err = -EFAULT;
79716 break;
79717diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
79718index ce3f665..2c7d08f 100644
79719--- a/net/bluetooth/rfcomm/sock.c
79720+++ b/net/bluetooth/rfcomm/sock.c
79721@@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
79722 struct sock *sk = sock->sk;
79723 struct bt_security sec;
79724 int err = 0;
79725- size_t len;
79726+ size_t len = optlen;
79727 u32 opt;
79728
79729 BT_DBG("sk %p", sk);
79730@@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
79731
79732 sec.level = BT_SECURITY_LOW;
79733
79734- len = min_t(unsigned int, sizeof(sec), optlen);
79735+ len = min(sizeof(sec), len);
79736 if (copy_from_user((char *) &sec, optval, len)) {
79737 err = -EFAULT;
79738 break;
79739diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
79740index bd6fd0f..6492cba 100644
79741--- a/net/bluetooth/rfcomm/tty.c
79742+++ b/net/bluetooth/rfcomm/tty.c
79743@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
79744 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
79745
79746 spin_lock_irqsave(&dev->port.lock, flags);
79747- if (dev->port.count > 0) {
79748+ if (atomic_read(&dev->port.count) > 0) {
79749 spin_unlock_irqrestore(&dev->port.lock, flags);
79750 return;
79751 }
79752@@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
79753 return -ENODEV;
79754
79755 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
79756- dev->channel, dev->port.count);
79757+ dev->channel, atomic_read(&dev->port.count));
79758
79759 spin_lock_irqsave(&dev->port.lock, flags);
79760- if (++dev->port.count > 1) {
79761+ if (atomic_inc_return(&dev->port.count) > 1) {
79762 spin_unlock_irqrestore(&dev->port.lock, flags);
79763 return 0;
79764 }
79765@@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
79766 return;
79767
79768 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
79769- dev->port.count);
79770+ atomic_read(&dev->port.count));
79771
79772 spin_lock_irqsave(&dev->port.lock, flags);
79773- if (!--dev->port.count) {
79774+ if (!atomic_dec_return(&dev->port.count)) {
79775 spin_unlock_irqrestore(&dev->port.lock, flags);
79776 if (dev->tty_dev->parent)
79777 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
79778diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
79779index 5fe2ff3..121d696 100644
79780--- a/net/bridge/netfilter/ebtables.c
79781+++ b/net/bridge/netfilter/ebtables.c
79782@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79783 tmp.valid_hooks = t->table->valid_hooks;
79784 }
79785 mutex_unlock(&ebt_mutex);
79786- if (copy_to_user(user, &tmp, *len) != 0){
79787+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
79788 BUGPRINT("c2u Didn't work\n");
79789 ret = -EFAULT;
79790 break;
79791@@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
79792 goto out;
79793 tmp.valid_hooks = t->valid_hooks;
79794
79795- if (copy_to_user(user, &tmp, *len) != 0) {
79796+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
79797 ret = -EFAULT;
79798 break;
79799 }
79800@@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
79801 tmp.entries_size = t->table->entries_size;
79802 tmp.valid_hooks = t->table->valid_hooks;
79803
79804- if (copy_to_user(user, &tmp, *len) != 0) {
79805+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
79806 ret = -EFAULT;
79807 break;
79808 }
79809diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
79810index a376ec1..1fbd6be 100644
79811--- a/net/caif/cfctrl.c
79812+++ b/net/caif/cfctrl.c
79813@@ -10,6 +10,7 @@
79814 #include <linux/spinlock.h>
79815 #include <linux/slab.h>
79816 #include <linux/pkt_sched.h>
79817+#include <linux/sched.h>
79818 #include <net/caif/caif_layer.h>
79819 #include <net/caif/cfpkt.h>
79820 #include <net/caif/cfctrl.h>
79821@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
79822 memset(&dev_info, 0, sizeof(dev_info));
79823 dev_info.id = 0xff;
79824 cfsrvl_init(&this->serv, 0, &dev_info, false);
79825- atomic_set(&this->req_seq_no, 1);
79826- atomic_set(&this->rsp_seq_no, 1);
79827+ atomic_set_unchecked(&this->req_seq_no, 1);
79828+ atomic_set_unchecked(&this->rsp_seq_no, 1);
79829 this->serv.layer.receive = cfctrl_recv;
79830 sprintf(this->serv.layer.name, "ctrl");
79831 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
79832@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
79833 struct cfctrl_request_info *req)
79834 {
79835 spin_lock_bh(&ctrl->info_list_lock);
79836- atomic_inc(&ctrl->req_seq_no);
79837- req->sequence_no = atomic_read(&ctrl->req_seq_no);
79838+ atomic_inc_unchecked(&ctrl->req_seq_no);
79839+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
79840 list_add_tail(&req->list, &ctrl->list);
79841 spin_unlock_bh(&ctrl->info_list_lock);
79842 }
79843@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
79844 if (p != first)
79845 pr_warn("Requests are not received in order\n");
79846
79847- atomic_set(&ctrl->rsp_seq_no,
79848+ atomic_set_unchecked(&ctrl->rsp_seq_no,
79849 p->sequence_no);
79850 list_del(&p->list);
79851 goto out;
79852diff --git a/net/can/af_can.c b/net/can/af_can.c
79853index ddac1ee..3ee0a78 100644
79854--- a/net/can/af_can.c
79855+++ b/net/can/af_can.c
79856@@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
79857 };
79858
79859 /* notifier block for netdevice event */
79860-static struct notifier_block can_netdev_notifier __read_mostly = {
79861+static struct notifier_block can_netdev_notifier = {
79862 .notifier_call = can_notifier,
79863 };
79864
79865diff --git a/net/can/gw.c b/net/can/gw.c
79866index 574dda78e..3d2b3da 100644
79867--- a/net/can/gw.c
79868+++ b/net/can/gw.c
79869@@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
79870 MODULE_ALIAS("can-gw");
79871
79872 static HLIST_HEAD(cgw_list);
79873-static struct notifier_block notifier;
79874
79875 static struct kmem_cache *cgw_cache __read_mostly;
79876
79877@@ -893,6 +892,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
79878 return err;
79879 }
79880
79881+static struct notifier_block notifier = {
79882+ .notifier_call = cgw_notifier
79883+};
79884+
79885 static __init int cgw_module_init(void)
79886 {
79887 printk(banner);
79888@@ -904,7 +907,6 @@ static __init int cgw_module_init(void)
79889 return -ENOMEM;
79890
79891 /* set notifier */
79892- notifier.notifier_call = cgw_notifier;
79893 register_netdevice_notifier(&notifier);
79894
79895 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
79896diff --git a/net/compat.c b/net/compat.c
79897index 79ae884..17c5c09 100644
79898--- a/net/compat.c
79899+++ b/net/compat.c
79900@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
79901 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
79902 __get_user(kmsg->msg_flags, &umsg->msg_flags))
79903 return -EFAULT;
79904- kmsg->msg_name = compat_ptr(tmp1);
79905- kmsg->msg_iov = compat_ptr(tmp2);
79906- kmsg->msg_control = compat_ptr(tmp3);
79907+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
79908+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
79909+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
79910 return 0;
79911 }
79912
79913@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
79914
79915 if (kern_msg->msg_namelen) {
79916 if (mode == VERIFY_READ) {
79917- int err = move_addr_to_kernel(kern_msg->msg_name,
79918+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
79919 kern_msg->msg_namelen,
79920 kern_address);
79921 if (err < 0)
79922@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
79923 kern_msg->msg_name = NULL;
79924
79925 tot_len = iov_from_user_compat_to_kern(kern_iov,
79926- (struct compat_iovec __user *)kern_msg->msg_iov,
79927+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
79928 kern_msg->msg_iovlen);
79929 if (tot_len >= 0)
79930 kern_msg->msg_iov = kern_iov;
79931@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
79932
79933 #define CMSG_COMPAT_FIRSTHDR(msg) \
79934 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
79935- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
79936+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
79937 (struct compat_cmsghdr __user *)NULL)
79938
79939 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
79940 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
79941 (ucmlen) <= (unsigned long) \
79942 ((mhdr)->msg_controllen - \
79943- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
79944+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
79945
79946 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
79947 struct compat_cmsghdr __user *cmsg, int cmsg_len)
79948 {
79949 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
79950- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
79951+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
79952 msg->msg_controllen)
79953 return NULL;
79954 return (struct compat_cmsghdr __user *)ptr;
79955@@ -219,7 +219,7 @@ Efault:
79956
79957 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
79958 {
79959- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
79960+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
79961 struct compat_cmsghdr cmhdr;
79962 struct compat_timeval ctv;
79963 struct compat_timespec cts[3];
79964@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
79965
79966 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
79967 {
79968- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
79969+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
79970 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
79971 int fdnum = scm->fp->count;
79972 struct file **fp = scm->fp->fp;
79973@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
79974 return -EFAULT;
79975 old_fs = get_fs();
79976 set_fs(KERNEL_DS);
79977- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
79978+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
79979 set_fs(old_fs);
79980
79981 return err;
79982@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
79983 len = sizeof(ktime);
79984 old_fs = get_fs();
79985 set_fs(KERNEL_DS);
79986- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
79987+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
79988 set_fs(old_fs);
79989
79990 if (!err) {
79991@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
79992 case MCAST_JOIN_GROUP:
79993 case MCAST_LEAVE_GROUP:
79994 {
79995- struct compat_group_req __user *gr32 = (void *)optval;
79996+ struct compat_group_req __user *gr32 = (void __user *)optval;
79997 struct group_req __user *kgr =
79998 compat_alloc_user_space(sizeof(struct group_req));
79999 u32 interface;
80000@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
80001 case MCAST_BLOCK_SOURCE:
80002 case MCAST_UNBLOCK_SOURCE:
80003 {
80004- struct compat_group_source_req __user *gsr32 = (void *)optval;
80005+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
80006 struct group_source_req __user *kgsr = compat_alloc_user_space(
80007 sizeof(struct group_source_req));
80008 u32 interface;
80009@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
80010 }
80011 case MCAST_MSFILTER:
80012 {
80013- struct compat_group_filter __user *gf32 = (void *)optval;
80014+ struct compat_group_filter __user *gf32 = (void __user *)optval;
80015 struct group_filter __user *kgf;
80016 u32 interface, fmode, numsrc;
80017
80018@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
80019 char __user *optval, int __user *optlen,
80020 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
80021 {
80022- struct compat_group_filter __user *gf32 = (void *)optval;
80023+ struct compat_group_filter __user *gf32 = (void __user *)optval;
80024 struct group_filter __user *kgf;
80025 int __user *koptlen;
80026 u32 interface, fmode, numsrc;
80027@@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
80028
80029 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
80030 return -EINVAL;
80031- if (copy_from_user(a, args, nas[call]))
80032+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
80033 return -EFAULT;
80034 a0 = a[0];
80035 a1 = a[1];
80036diff --git a/net/core/datagram.c b/net/core/datagram.c
80037index 368f9c3..f82d4a3 100644
80038--- a/net/core/datagram.c
80039+++ b/net/core/datagram.c
80040@@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
80041 }
80042
80043 kfree_skb(skb);
80044- atomic_inc(&sk->sk_drops);
80045+ atomic_inc_unchecked(&sk->sk_drops);
80046 sk_mem_reclaim_partial(sk);
80047
80048 return err;
80049diff --git a/net/core/dev.c b/net/core/dev.c
80050index f64e439..8f959e6 100644
80051--- a/net/core/dev.c
80052+++ b/net/core/dev.c
80053@@ -1250,9 +1250,13 @@ void dev_load(struct net *net, const char *name)
80054 if (no_module && capable(CAP_NET_ADMIN))
80055 no_module = request_module("netdev-%s", name);
80056 if (no_module && capable(CAP_SYS_MODULE)) {
80057+#ifdef CONFIG_GRKERNSEC_MODHARDEN
80058+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
80059+#else
80060 if (!request_module("%s", name))
80061 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
80062 name);
80063+#endif
80064 }
80065 }
80066 EXPORT_SYMBOL(dev_load);
80067@@ -1715,7 +1719,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
80068 {
80069 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
80070 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
80071- atomic_long_inc(&dev->rx_dropped);
80072+ atomic_long_inc_unchecked(&dev->rx_dropped);
80073 kfree_skb(skb);
80074 return NET_RX_DROP;
80075 }
80076@@ -1725,7 +1729,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
80077 nf_reset(skb);
80078
80079 if (unlikely(!is_skb_forwardable(dev, skb))) {
80080- atomic_long_inc(&dev->rx_dropped);
80081+ atomic_long_inc_unchecked(&dev->rx_dropped);
80082 kfree_skb(skb);
80083 return NET_RX_DROP;
80084 }
80085@@ -2180,7 +2184,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
80086
80087 struct dev_gso_cb {
80088 void (*destructor)(struct sk_buff *skb);
80089-};
80090+} __no_const;
80091
80092 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
80093
80094@@ -3053,7 +3057,7 @@ enqueue:
80095
80096 local_irq_restore(flags);
80097
80098- atomic_long_inc(&skb->dev->rx_dropped);
80099+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
80100 kfree_skb(skb);
80101 return NET_RX_DROP;
80102 }
80103@@ -3125,7 +3129,7 @@ int netif_rx_ni(struct sk_buff *skb)
80104 }
80105 EXPORT_SYMBOL(netif_rx_ni);
80106
80107-static void net_tx_action(struct softirq_action *h)
80108+static void net_tx_action(void)
80109 {
80110 struct softnet_data *sd = &__get_cpu_var(softnet_data);
80111
80112@@ -3456,7 +3460,7 @@ ncls:
80113 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
80114 } else {
80115 drop:
80116- atomic_long_inc(&skb->dev->rx_dropped);
80117+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
80118 kfree_skb(skb);
80119 /* Jamal, now you will not able to escape explaining
80120 * me how you were going to use this. :-)
80121@@ -4039,7 +4043,7 @@ void netif_napi_del(struct napi_struct *napi)
80122 }
80123 EXPORT_SYMBOL(netif_napi_del);
80124
80125-static void net_rx_action(struct softirq_action *h)
80126+static void net_rx_action(void)
80127 {
80128 struct softnet_data *sd = &__get_cpu_var(softnet_data);
80129 unsigned long time_limit = jiffies + 2;
80130@@ -4523,8 +4527,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
80131 else
80132 seq_printf(seq, "%04x", ntohs(pt->type));
80133
80134+#ifdef CONFIG_GRKERNSEC_HIDESYM
80135+ seq_printf(seq, " %-8s %p\n",
80136+ pt->dev ? pt->dev->name : "", NULL);
80137+#else
80138 seq_printf(seq, " %-8s %pF\n",
80139 pt->dev ? pt->dev->name : "", pt->func);
80140+#endif
80141 }
80142
80143 return 0;
80144@@ -6096,7 +6105,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
80145 } else {
80146 netdev_stats_to_stats64(storage, &dev->stats);
80147 }
80148- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
80149+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
80150 return storage;
80151 }
80152 EXPORT_SYMBOL(dev_get_stats);
80153diff --git a/net/core/flow.c b/net/core/flow.c
80154index b0901ee..7d3c2ca 100644
80155--- a/net/core/flow.c
80156+++ b/net/core/flow.c
80157@@ -61,7 +61,7 @@ struct flow_cache {
80158 struct timer_list rnd_timer;
80159 };
80160
80161-atomic_t flow_cache_genid = ATOMIC_INIT(0);
80162+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
80163 EXPORT_SYMBOL(flow_cache_genid);
80164 static struct flow_cache flow_cache_global;
80165 static struct kmem_cache *flow_cachep __read_mostly;
80166@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
80167
80168 static int flow_entry_valid(struct flow_cache_entry *fle)
80169 {
80170- if (atomic_read(&flow_cache_genid) != fle->genid)
80171+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
80172 return 0;
80173 if (fle->object && !fle->object->ops->check(fle->object))
80174 return 0;
80175@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
80176 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
80177 fcp->hash_count++;
80178 }
80179- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
80180+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
80181 flo = fle->object;
80182 if (!flo)
80183 goto ret_object;
80184@@ -280,7 +280,7 @@ nocache:
80185 }
80186 flo = resolver(net, key, family, dir, flo, ctx);
80187 if (fle) {
80188- fle->genid = atomic_read(&flow_cache_genid);
80189+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
80190 if (!IS_ERR(flo))
80191 fle->object = flo;
80192 else
80193diff --git a/net/core/iovec.c b/net/core/iovec.c
80194index 7e7aeb0..2a998cb 100644
80195--- a/net/core/iovec.c
80196+++ b/net/core/iovec.c
80197@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
80198 if (m->msg_namelen) {
80199 if (mode == VERIFY_READ) {
80200 void __user *namep;
80201- namep = (void __user __force *) m->msg_name;
80202+ namep = (void __force_user *) m->msg_name;
80203 err = move_addr_to_kernel(namep, m->msg_namelen,
80204 address);
80205 if (err < 0)
80206@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
80207 }
80208
80209 size = m->msg_iovlen * sizeof(struct iovec);
80210- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
80211+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
80212 return -EFAULT;
80213
80214 m->msg_iov = iov;
80215diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
80216index 1868625..5f4de62 100644
80217--- a/net/core/rtnetlink.c
80218+++ b/net/core/rtnetlink.c
80219@@ -58,7 +58,7 @@ struct rtnl_link {
80220 rtnl_doit_func doit;
80221 rtnl_dumpit_func dumpit;
80222 rtnl_calcit_func calcit;
80223-};
80224+} __no_const;
80225
80226 static DEFINE_MUTEX(rtnl_mutex);
80227
80228diff --git a/net/core/scm.c b/net/core/scm.c
80229index 905dcc6..14ee2d6 100644
80230--- a/net/core/scm.c
80231+++ b/net/core/scm.c
80232@@ -224,7 +224,7 @@ EXPORT_SYMBOL(__scm_send);
80233 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
80234 {
80235 struct cmsghdr __user *cm
80236- = (__force struct cmsghdr __user *)msg->msg_control;
80237+ = (struct cmsghdr __force_user *)msg->msg_control;
80238 struct cmsghdr cmhdr;
80239 int cmlen = CMSG_LEN(len);
80240 int err;
80241@@ -247,7 +247,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
80242 err = -EFAULT;
80243 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
80244 goto out;
80245- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
80246+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
80247 goto out;
80248 cmlen = CMSG_SPACE(len);
80249 if (msg->msg_controllen < cmlen)
80250@@ -263,7 +263,7 @@ EXPORT_SYMBOL(put_cmsg);
80251 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
80252 {
80253 struct cmsghdr __user *cm
80254- = (__force struct cmsghdr __user*)msg->msg_control;
80255+ = (struct cmsghdr __force_user *)msg->msg_control;
80256
80257 int fdmax = 0;
80258 int fdnum = scm->fp->count;
80259@@ -283,7 +283,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
80260 if (fdnum < fdmax)
80261 fdmax = fdnum;
80262
80263- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
80264+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
80265 i++, cmfptr++)
80266 {
80267 struct socket *sock;
80268diff --git a/net/core/sock.c b/net/core/sock.c
80269index bc131d4..029e378 100644
80270--- a/net/core/sock.c
80271+++ b/net/core/sock.c
80272@@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80273 struct sk_buff_head *list = &sk->sk_receive_queue;
80274
80275 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
80276- atomic_inc(&sk->sk_drops);
80277+ atomic_inc_unchecked(&sk->sk_drops);
80278 trace_sock_rcvqueue_full(sk, skb);
80279 return -ENOMEM;
80280 }
80281@@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80282 return err;
80283
80284 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
80285- atomic_inc(&sk->sk_drops);
80286+ atomic_inc_unchecked(&sk->sk_drops);
80287 return -ENOBUFS;
80288 }
80289
80290@@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80291 skb_dst_force(skb);
80292
80293 spin_lock_irqsave(&list->lock, flags);
80294- skb->dropcount = atomic_read(&sk->sk_drops);
80295+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
80296 __skb_queue_tail(list, skb);
80297 spin_unlock_irqrestore(&list->lock, flags);
80298
80299@@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
80300 skb->dev = NULL;
80301
80302 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
80303- atomic_inc(&sk->sk_drops);
80304+ atomic_inc_unchecked(&sk->sk_drops);
80305 goto discard_and_relse;
80306 }
80307 if (nested)
80308@@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
80309 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
80310 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
80311 bh_unlock_sock(sk);
80312- atomic_inc(&sk->sk_drops);
80313+ atomic_inc_unchecked(&sk->sk_drops);
80314 goto discard_and_relse;
80315 }
80316
80317@@ -930,12 +930,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
80318 struct timeval tm;
80319 } v;
80320
80321- int lv = sizeof(int);
80322- int len;
80323+ unsigned int lv = sizeof(int);
80324+ unsigned int len;
80325
80326 if (get_user(len, optlen))
80327 return -EFAULT;
80328- if (len < 0)
80329+ if (len > INT_MAX)
80330 return -EINVAL;
80331
80332 memset(&v, 0, sizeof(v));
80333@@ -1083,11 +1083,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
80334
80335 case SO_PEERNAME:
80336 {
80337- char address[128];
80338+ char address[_K_SS_MAXSIZE];
80339
80340 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
80341 return -ENOTCONN;
80342- if (lv < len)
80343+ if (lv < len || sizeof address < len)
80344 return -EINVAL;
80345 if (copy_to_user(optval, address, len))
80346 return -EFAULT;
80347@@ -1146,7 +1146,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
80348
80349 if (len > lv)
80350 len = lv;
80351- if (copy_to_user(optval, &v, len))
80352+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
80353 return -EFAULT;
80354 lenout:
80355 if (put_user(len, optlen))
80356@@ -2276,7 +2276,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
80357 */
80358 smp_wmb();
80359 atomic_set(&sk->sk_refcnt, 1);
80360- atomic_set(&sk->sk_drops, 0);
80361+ atomic_set_unchecked(&sk->sk_drops, 0);
80362 }
80363 EXPORT_SYMBOL(sock_init_data);
80364
80365diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
80366index 602cd63..05c6c60 100644
80367--- a/net/core/sock_diag.c
80368+++ b/net/core/sock_diag.c
80369@@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
80370
80371 int sock_diag_check_cookie(void *sk, __u32 *cookie)
80372 {
80373+#ifndef CONFIG_GRKERNSEC_HIDESYM
80374 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
80375 cookie[1] != INET_DIAG_NOCOOKIE) &&
80376 ((u32)(unsigned long)sk != cookie[0] ||
80377 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
80378 return -ESTALE;
80379 else
80380+#endif
80381 return 0;
80382 }
80383 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
80384
80385 void sock_diag_save_cookie(void *sk, __u32 *cookie)
80386 {
80387+#ifdef CONFIG_GRKERNSEC_HIDESYM
80388+ cookie[0] = 0;
80389+ cookie[1] = 0;
80390+#else
80391 cookie[0] = (u32)(unsigned long)sk;
80392 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
80393+#endif
80394 }
80395 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
80396
80397diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
80398index a55eecc..dd8428c 100644
80399--- a/net/decnet/sysctl_net_decnet.c
80400+++ b/net/decnet/sysctl_net_decnet.c
80401@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
80402
80403 if (len > *lenp) len = *lenp;
80404
80405- if (copy_to_user(buffer, addr, len))
80406+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
80407 return -EFAULT;
80408
80409 *lenp = len;
80410@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
80411
80412 if (len > *lenp) len = *lenp;
80413
80414- if (copy_to_user(buffer, devname, len))
80415+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
80416 return -EFAULT;
80417
80418 *lenp = len;
80419diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
80420index a69b4e4..dbccba5 100644
80421--- a/net/ipv4/ah4.c
80422+++ b/net/ipv4/ah4.c
80423@@ -421,7 +421,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
80424 return;
80425
80426 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
80427- atomic_inc(&flow_cache_genid);
80428+ atomic_inc_unchecked(&flow_cache_genid);
80429 rt_genid_bump(net);
80430
80431 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
80432diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
80433index 3b4f0cd..8cb864c 100644
80434--- a/net/ipv4/esp4.c
80435+++ b/net/ipv4/esp4.c
80436@@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
80437 return;
80438
80439 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
80440- atomic_inc(&flow_cache_genid);
80441+ atomic_inc_unchecked(&flow_cache_genid);
80442 rt_genid_bump(net);
80443
80444 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
80445diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
80446index 5cd75e2..f57ef39 100644
80447--- a/net/ipv4/fib_frontend.c
80448+++ b/net/ipv4/fib_frontend.c
80449@@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
80450 #ifdef CONFIG_IP_ROUTE_MULTIPATH
80451 fib_sync_up(dev);
80452 #endif
80453- atomic_inc(&net->ipv4.dev_addr_genid);
80454+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
80455 rt_cache_flush(dev_net(dev));
80456 break;
80457 case NETDEV_DOWN:
80458 fib_del_ifaddr(ifa, NULL);
80459- atomic_inc(&net->ipv4.dev_addr_genid);
80460+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
80461 if (ifa->ifa_dev->ifa_list == NULL) {
80462 /* Last address was deleted from this interface.
80463 * Disable IP.
80464@@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
80465 #ifdef CONFIG_IP_ROUTE_MULTIPATH
80466 fib_sync_up(dev);
80467 #endif
80468- atomic_inc(&net->ipv4.dev_addr_genid);
80469+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
80470 rt_cache_flush(net);
80471 break;
80472 case NETDEV_DOWN:
80473diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
80474index 4797a80..2bd54e9 100644
80475--- a/net/ipv4/fib_semantics.c
80476+++ b/net/ipv4/fib_semantics.c
80477@@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
80478 nh->nh_saddr = inet_select_addr(nh->nh_dev,
80479 nh->nh_gw,
80480 nh->nh_parent->fib_scope);
80481- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
80482+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
80483
80484 return nh->nh_saddr;
80485 }
80486diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
80487index fa3ae81..0dbe6b8 100644
80488--- a/net/ipv4/inet_hashtables.c
80489+++ b/net/ipv4/inet_hashtables.c
80490@@ -18,12 +18,15 @@
80491 #include <linux/sched.h>
80492 #include <linux/slab.h>
80493 #include <linux/wait.h>
80494+#include <linux/security.h>
80495
80496 #include <net/inet_connection_sock.h>
80497 #include <net/inet_hashtables.h>
80498 #include <net/secure_seq.h>
80499 #include <net/ip.h>
80500
80501+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
80502+
80503 /*
80504 * Allocate and initialize a new local port bind bucket.
80505 * The bindhash mutex for snum's hash chain must be held here.
80506@@ -540,6 +543,8 @@ ok:
80507 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
80508 spin_unlock(&head->lock);
80509
80510+ gr_update_task_in_ip_table(current, inet_sk(sk));
80511+
80512 if (tw) {
80513 inet_twsk_deschedule(tw, death_row);
80514 while (twrefcnt) {
80515diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
80516index 000e3d2..5472da3 100644
80517--- a/net/ipv4/inetpeer.c
80518+++ b/net/ipv4/inetpeer.c
80519@@ -503,8 +503,8 @@ relookup:
80520 if (p) {
80521 p->daddr = *daddr;
80522 atomic_set(&p->refcnt, 1);
80523- atomic_set(&p->rid, 0);
80524- atomic_set(&p->ip_id_count,
80525+ atomic_set_unchecked(&p->rid, 0);
80526+ atomic_set_unchecked(&p->ip_id_count,
80527 (daddr->family == AF_INET) ?
80528 secure_ip_id(daddr->addr.a4) :
80529 secure_ipv6_id(daddr->addr.a6));
80530diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
80531index eb9d63a..50babc1 100644
80532--- a/net/ipv4/ip_fragment.c
80533+++ b/net/ipv4/ip_fragment.c
80534@@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
80535 return 0;
80536
80537 start = qp->rid;
80538- end = atomic_inc_return(&peer->rid);
80539+ end = atomic_inc_return_unchecked(&peer->rid);
80540 qp->rid = end;
80541
80542 rc = qp->q.fragments && (end - start) > max;
80543diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
80544index d9c4f11..02b82db 100644
80545--- a/net/ipv4/ip_sockglue.c
80546+++ b/net/ipv4/ip_sockglue.c
80547@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
80548 len = min_t(unsigned int, len, opt->optlen);
80549 if (put_user(len, optlen))
80550 return -EFAULT;
80551- if (copy_to_user(optval, opt->__data, len))
80552+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
80553+ copy_to_user(optval, opt->__data, len))
80554 return -EFAULT;
80555 return 0;
80556 }
80557@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
80558 if (sk->sk_type != SOCK_STREAM)
80559 return -ENOPROTOOPT;
80560
80561- msg.msg_control = optval;
80562+ msg.msg_control = (void __force_kernel *)optval;
80563 msg.msg_controllen = len;
80564 msg.msg_flags = flags;
80565
80566diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
80567index 9a46dae..5f793a0 100644
80568--- a/net/ipv4/ipcomp.c
80569+++ b/net/ipv4/ipcomp.c
80570@@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
80571 return;
80572
80573 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
80574- atomic_inc(&flow_cache_genid);
80575+ atomic_inc_unchecked(&flow_cache_genid);
80576 rt_genid_bump(net);
80577
80578 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
80579diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
80580index a2e50ae..e152b7c 100644
80581--- a/net/ipv4/ipconfig.c
80582+++ b/net/ipv4/ipconfig.c
80583@@ -323,7 +323,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
80584
80585 mm_segment_t oldfs = get_fs();
80586 set_fs(get_ds());
80587- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
80588+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
80589 set_fs(oldfs);
80590 return res;
80591 }
80592@@ -334,7 +334,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
80593
80594 mm_segment_t oldfs = get_fs();
80595 set_fs(get_ds());
80596- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
80597+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
80598 set_fs(oldfs);
80599 return res;
80600 }
80601@@ -345,7 +345,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
80602
80603 mm_segment_t oldfs = get_fs();
80604 set_fs(get_ds());
80605- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
80606+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
80607 set_fs(oldfs);
80608 return res;
80609 }
80610diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
80611index 3ea4127..849297b 100644
80612--- a/net/ipv4/netfilter/arp_tables.c
80613+++ b/net/ipv4/netfilter/arp_tables.c
80614@@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
80615 #endif
80616
80617 static int get_info(struct net *net, void __user *user,
80618- const int *len, int compat)
80619+ int len, int compat)
80620 {
80621 char name[XT_TABLE_MAXNAMELEN];
80622 struct xt_table *t;
80623 int ret;
80624
80625- if (*len != sizeof(struct arpt_getinfo)) {
80626- duprintf("length %u != %Zu\n", *len,
80627+ if (len != sizeof(struct arpt_getinfo)) {
80628+ duprintf("length %u != %Zu\n", len,
80629 sizeof(struct arpt_getinfo));
80630 return -EINVAL;
80631 }
80632@@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
80633 info.size = private->size;
80634 strcpy(info.name, name);
80635
80636- if (copy_to_user(user, &info, *len) != 0)
80637+ if (copy_to_user(user, &info, len) != 0)
80638 ret = -EFAULT;
80639 else
80640 ret = 0;
80641@@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
80642
80643 switch (cmd) {
80644 case ARPT_SO_GET_INFO:
80645- ret = get_info(sock_net(sk), user, len, 1);
80646+ ret = get_info(sock_net(sk), user, *len, 1);
80647 break;
80648 case ARPT_SO_GET_ENTRIES:
80649 ret = compat_get_entries(sock_net(sk), user, len);
80650@@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
80651
80652 switch (cmd) {
80653 case ARPT_SO_GET_INFO:
80654- ret = get_info(sock_net(sk), user, len, 0);
80655+ ret = get_info(sock_net(sk), user, *len, 0);
80656 break;
80657
80658 case ARPT_SO_GET_ENTRIES:
80659diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
80660index 17c5e06..1b91206 100644
80661--- a/net/ipv4/netfilter/ip_tables.c
80662+++ b/net/ipv4/netfilter/ip_tables.c
80663@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
80664 #endif
80665
80666 static int get_info(struct net *net, void __user *user,
80667- const int *len, int compat)
80668+ int len, int compat)
80669 {
80670 char name[XT_TABLE_MAXNAMELEN];
80671 struct xt_table *t;
80672 int ret;
80673
80674- if (*len != sizeof(struct ipt_getinfo)) {
80675- duprintf("length %u != %zu\n", *len,
80676+ if (len != sizeof(struct ipt_getinfo)) {
80677+ duprintf("length %u != %zu\n", len,
80678 sizeof(struct ipt_getinfo));
80679 return -EINVAL;
80680 }
80681@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
80682 info.size = private->size;
80683 strcpy(info.name, name);
80684
80685- if (copy_to_user(user, &info, *len) != 0)
80686+ if (copy_to_user(user, &info, len) != 0)
80687 ret = -EFAULT;
80688 else
80689 ret = 0;
80690@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
80691
80692 switch (cmd) {
80693 case IPT_SO_GET_INFO:
80694- ret = get_info(sock_net(sk), user, len, 1);
80695+ ret = get_info(sock_net(sk), user, *len, 1);
80696 break;
80697 case IPT_SO_GET_ENTRIES:
80698 ret = compat_get_entries(sock_net(sk), user, len);
80699@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
80700
80701 switch (cmd) {
80702 case IPT_SO_GET_INFO:
80703- ret = get_info(sock_net(sk), user, len, 0);
80704+ ret = get_info(sock_net(sk), user, *len, 0);
80705 break;
80706
80707 case IPT_SO_GET_ENTRIES:
80708diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
80709index 6f9c072..38ea6c6 100644
80710--- a/net/ipv4/ping.c
80711+++ b/net/ipv4/ping.c
80712@@ -844,7 +844,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
80713 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
80714 0, sock_i_ino(sp),
80715 atomic_read(&sp->sk_refcnt), sp,
80716- atomic_read(&sp->sk_drops), len);
80717+ atomic_read_unchecked(&sp->sk_drops), len);
80718 }
80719
80720 static int ping_seq_show(struct seq_file *seq, void *v)
80721diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
80722index 6f08991..55867ad 100644
80723--- a/net/ipv4/raw.c
80724+++ b/net/ipv4/raw.c
80725@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
80726 int raw_rcv(struct sock *sk, struct sk_buff *skb)
80727 {
80728 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
80729- atomic_inc(&sk->sk_drops);
80730+ atomic_inc_unchecked(&sk->sk_drops);
80731 kfree_skb(skb);
80732 return NET_RX_DROP;
80733 }
80734@@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
80735
80736 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
80737 {
80738+ struct icmp_filter filter;
80739+
80740 if (optlen > sizeof(struct icmp_filter))
80741 optlen = sizeof(struct icmp_filter);
80742- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
80743+ if (copy_from_user(&filter, optval, optlen))
80744 return -EFAULT;
80745+ raw_sk(sk)->filter = filter;
80746 return 0;
80747 }
80748
80749 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
80750 {
80751 int len, ret = -EFAULT;
80752+ struct icmp_filter filter;
80753
80754 if (get_user(len, optlen))
80755 goto out;
80756@@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
80757 if (len > sizeof(struct icmp_filter))
80758 len = sizeof(struct icmp_filter);
80759 ret = -EFAULT;
80760- if (put_user(len, optlen) ||
80761- copy_to_user(optval, &raw_sk(sk)->filter, len))
80762+ filter = raw_sk(sk)->filter;
80763+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
80764 goto out;
80765 ret = 0;
80766 out: return ret;
80767@@ -998,7 +1002,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
80768 0, 0L, 0,
80769 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
80770 0, sock_i_ino(sp),
80771- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
80772+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
80773 }
80774
80775 static int raw_seq_show(struct seq_file *seq, void *v)
80776diff --git a/net/ipv4/route.c b/net/ipv4/route.c
80777index a0fcc47..5949bba1 100644
80778--- a/net/ipv4/route.c
80779+++ b/net/ipv4/route.c
80780@@ -2602,7 +2602,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
80781
80782 static __net_init int rt_genid_init(struct net *net)
80783 {
80784- atomic_set(&net->rt_genid, 0);
80785+ atomic_set_unchecked(&net->rt_genid, 0);
80786 get_random_bytes(&net->ipv4.dev_addr_genid,
80787 sizeof(net->ipv4.dev_addr_genid));
80788 return 0;
80789diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
80790index ad70a96..50cb55b 100644
80791--- a/net/ipv4/tcp_input.c
80792+++ b/net/ipv4/tcp_input.c
80793@@ -4733,7 +4733,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
80794 * simplifies code)
80795 */
80796 static void
80797-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
80798+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
80799 struct sk_buff *head, struct sk_buff *tail,
80800 u32 start, u32 end)
80801 {
80802@@ -5850,6 +5850,7 @@ discard:
80803 tcp_paws_reject(&tp->rx_opt, 0))
80804 goto discard_and_undo;
80805
80806+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
80807 if (th->syn) {
80808 /* We see SYN without ACK. It is attempt of
80809 * simultaneous connect with crossed SYNs.
80810@@ -5900,6 +5901,7 @@ discard:
80811 goto discard;
80812 #endif
80813 }
80814+#endif
80815 /* "fifth, if neither of the SYN or RST bits is set then
80816 * drop the segment and return."
80817 */
80818@@ -5944,7 +5946,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
80819 goto discard;
80820
80821 if (th->syn) {
80822- if (th->fin)
80823+ if (th->fin || th->urg || th->psh)
80824 goto discard;
80825 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
80826 return 1;
80827diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
80828index eadb693..e8f7251 100644
80829--- a/net/ipv4/tcp_ipv4.c
80830+++ b/net/ipv4/tcp_ipv4.c
80831@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
80832 EXPORT_SYMBOL(sysctl_tcp_low_latency);
80833
80834
80835+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80836+extern int grsec_enable_blackhole;
80837+#endif
80838+
80839 #ifdef CONFIG_TCP_MD5SIG
80840 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
80841 __be32 daddr, __be32 saddr, const struct tcphdr *th);
80842@@ -1895,6 +1899,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
80843 return 0;
80844
80845 reset:
80846+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80847+ if (!grsec_enable_blackhole)
80848+#endif
80849 tcp_v4_send_reset(rsk, skb);
80850 discard:
80851 kfree_skb(skb);
80852@@ -1994,12 +2001,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
80853 TCP_SKB_CB(skb)->sacked = 0;
80854
80855 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
80856- if (!sk)
80857+ if (!sk) {
80858+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80859+ ret = 1;
80860+#endif
80861 goto no_tcp_socket;
80862-
80863+ }
80864 process:
80865- if (sk->sk_state == TCP_TIME_WAIT)
80866+ if (sk->sk_state == TCP_TIME_WAIT) {
80867+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80868+ ret = 2;
80869+#endif
80870 goto do_time_wait;
80871+ }
80872
80873 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
80874 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
80875@@ -2050,6 +2064,10 @@ no_tcp_socket:
80876 bad_packet:
80877 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
80878 } else {
80879+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80880+ if (!grsec_enable_blackhole || (ret == 1 &&
80881+ (skb->dev->flags & IFF_LOOPBACK)))
80882+#endif
80883 tcp_v4_send_reset(NULL, skb);
80884 }
80885
80886diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
80887index f35f2df..ccb5ca6 100644
80888--- a/net/ipv4/tcp_minisocks.c
80889+++ b/net/ipv4/tcp_minisocks.c
80890@@ -27,6 +27,10 @@
80891 #include <net/inet_common.h>
80892 #include <net/xfrm.h>
80893
80894+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80895+extern int grsec_enable_blackhole;
80896+#endif
80897+
80898 int sysctl_tcp_syncookies __read_mostly = 1;
80899 EXPORT_SYMBOL(sysctl_tcp_syncookies);
80900
80901@@ -742,7 +746,10 @@ embryonic_reset:
80902 * avoid becoming vulnerable to outside attack aiming at
80903 * resetting legit local connections.
80904 */
80905- req->rsk_ops->send_reset(sk, skb);
80906+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80907+ if (!grsec_enable_blackhole)
80908+#endif
80909+ req->rsk_ops->send_reset(sk, skb);
80910 } else if (fastopen) { /* received a valid RST pkt */
80911 reqsk_fastopen_remove(sk, req, true);
80912 tcp_reset(sk);
80913diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
80914index 4526fe6..1a34e43 100644
80915--- a/net/ipv4/tcp_probe.c
80916+++ b/net/ipv4/tcp_probe.c
80917@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
80918 if (cnt + width >= len)
80919 break;
80920
80921- if (copy_to_user(buf + cnt, tbuf, width))
80922+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
80923 return -EFAULT;
80924 cnt += width;
80925 }
80926diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
80927index b78aac3..e18230b 100644
80928--- a/net/ipv4/tcp_timer.c
80929+++ b/net/ipv4/tcp_timer.c
80930@@ -22,6 +22,10 @@
80931 #include <linux/gfp.h>
80932 #include <net/tcp.h>
80933
80934+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80935+extern int grsec_lastack_retries;
80936+#endif
80937+
80938 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
80939 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
80940 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
80941@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
80942 }
80943 }
80944
80945+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80946+ if ((sk->sk_state == TCP_LAST_ACK) &&
80947+ (grsec_lastack_retries > 0) &&
80948+ (grsec_lastack_retries < retry_until))
80949+ retry_until = grsec_lastack_retries;
80950+#endif
80951+
80952 if (retransmits_timed_out(sk, retry_until,
80953 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
80954 /* Has it gone just too far? */
80955diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
80956index 1f4d405..3524677 100644
80957--- a/net/ipv4/udp.c
80958+++ b/net/ipv4/udp.c
80959@@ -87,6 +87,7 @@
80960 #include <linux/types.h>
80961 #include <linux/fcntl.h>
80962 #include <linux/module.h>
80963+#include <linux/security.h>
80964 #include <linux/socket.h>
80965 #include <linux/sockios.h>
80966 #include <linux/igmp.h>
80967@@ -111,6 +112,10 @@
80968 #include <trace/events/skb.h>
80969 #include "udp_impl.h"
80970
80971+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80972+extern int grsec_enable_blackhole;
80973+#endif
80974+
80975 struct udp_table udp_table __read_mostly;
80976 EXPORT_SYMBOL(udp_table);
80977
80978@@ -569,6 +574,9 @@ found:
80979 return s;
80980 }
80981
80982+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
80983+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
80984+
80985 /*
80986 * This routine is called by the ICMP module when it gets some
80987 * sort of error condition. If err < 0 then the socket should
80988@@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
80989 dport = usin->sin_port;
80990 if (dport == 0)
80991 return -EINVAL;
80992+
80993+ err = gr_search_udp_sendmsg(sk, usin);
80994+ if (err)
80995+ return err;
80996 } else {
80997 if (sk->sk_state != TCP_ESTABLISHED)
80998 return -EDESTADDRREQ;
80999+
81000+ err = gr_search_udp_sendmsg(sk, NULL);
81001+ if (err)
81002+ return err;
81003+
81004 daddr = inet->inet_daddr;
81005 dport = inet->inet_dport;
81006 /* Open fast path for connected socket.
81007@@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
81008 udp_lib_checksum_complete(skb)) {
81009 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
81010 IS_UDPLITE(sk));
81011- atomic_inc(&sk->sk_drops);
81012+ atomic_inc_unchecked(&sk->sk_drops);
81013 __skb_unlink(skb, rcvq);
81014 __skb_queue_tail(&list_kill, skb);
81015 }
81016@@ -1194,6 +1211,10 @@ try_again:
81017 if (!skb)
81018 goto out;
81019
81020+ err = gr_search_udp_recvmsg(sk, skb);
81021+ if (err)
81022+ goto out_free;
81023+
81024 ulen = skb->len - sizeof(struct udphdr);
81025 copied = len;
81026 if (copied > ulen)
81027@@ -1227,7 +1248,7 @@ try_again:
81028 if (unlikely(err)) {
81029 trace_kfree_skb(skb, udp_recvmsg);
81030 if (!peeked) {
81031- atomic_inc(&sk->sk_drops);
81032+ atomic_inc_unchecked(&sk->sk_drops);
81033 UDP_INC_STATS_USER(sock_net(sk),
81034 UDP_MIB_INERRORS, is_udplite);
81035 }
81036@@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
81037
81038 drop:
81039 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
81040- atomic_inc(&sk->sk_drops);
81041+ atomic_inc_unchecked(&sk->sk_drops);
81042 kfree_skb(skb);
81043 return -1;
81044 }
81045@@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
81046 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
81047
81048 if (!skb1) {
81049- atomic_inc(&sk->sk_drops);
81050+ atomic_inc_unchecked(&sk->sk_drops);
81051 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
81052 IS_UDPLITE(sk));
81053 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
81054@@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
81055 goto csum_error;
81056
81057 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
81058+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81059+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
81060+#endif
81061 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
81062
81063 /*
81064@@ -2120,7 +2144,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
81065 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
81066 0, sock_i_ino(sp),
81067 atomic_read(&sp->sk_refcnt), sp,
81068- atomic_read(&sp->sk_drops), len);
81069+ atomic_read_unchecked(&sp->sk_drops), len);
81070 }
81071
81072 int udp4_seq_show(struct seq_file *seq, void *v)
81073diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
81074index 1b5d8cb..2e8c2d9 100644
81075--- a/net/ipv6/addrconf.c
81076+++ b/net/ipv6/addrconf.c
81077@@ -2272,7 +2272,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
81078 p.iph.ihl = 5;
81079 p.iph.protocol = IPPROTO_IPV6;
81080 p.iph.ttl = 64;
81081- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
81082+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
81083
81084 if (ops->ndo_do_ioctl) {
81085 mm_segment_t oldfs = get_fs();
81086diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
81087index 131dd09..7647ada 100644
81088--- a/net/ipv6/ip6_gre.c
81089+++ b/net/ipv6/ip6_gre.c
81090@@ -1337,7 +1337,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
81091 }
81092
81093
81094-static struct inet6_protocol ip6gre_protocol __read_mostly = {
81095+static struct inet6_protocol ip6gre_protocol = {
81096 .handler = ip6gre_rcv,
81097 .err_handler = ip6gre_err,
81098 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
81099diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
81100index d1e2e8e..51c19ae 100644
81101--- a/net/ipv6/ipv6_sockglue.c
81102+++ b/net/ipv6/ipv6_sockglue.c
81103@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
81104 if (sk->sk_type != SOCK_STREAM)
81105 return -ENOPROTOOPT;
81106
81107- msg.msg_control = optval;
81108+ msg.msg_control = (void __force_kernel *)optval;
81109 msg.msg_controllen = len;
81110 msg.msg_flags = flags;
81111
81112diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
81113index 125a90d..2a11f36 100644
81114--- a/net/ipv6/netfilter/ip6_tables.c
81115+++ b/net/ipv6/netfilter/ip6_tables.c
81116@@ -1076,14 +1076,14 @@ static int compat_table_info(const struct xt_table_info *info,
81117 #endif
81118
81119 static int get_info(struct net *net, void __user *user,
81120- const int *len, int compat)
81121+ int len, int compat)
81122 {
81123 char name[XT_TABLE_MAXNAMELEN];
81124 struct xt_table *t;
81125 int ret;
81126
81127- if (*len != sizeof(struct ip6t_getinfo)) {
81128- duprintf("length %u != %zu\n", *len,
81129+ if (len != sizeof(struct ip6t_getinfo)) {
81130+ duprintf("length %u != %zu\n", len,
81131 sizeof(struct ip6t_getinfo));
81132 return -EINVAL;
81133 }
81134@@ -1120,7 +1120,7 @@ static int get_info(struct net *net, void __user *user,
81135 info.size = private->size;
81136 strcpy(info.name, name);
81137
81138- if (copy_to_user(user, &info, *len) != 0)
81139+ if (copy_to_user(user, &info, len) != 0)
81140 ret = -EFAULT;
81141 else
81142 ret = 0;
81143@@ -1974,7 +1974,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
81144
81145 switch (cmd) {
81146 case IP6T_SO_GET_INFO:
81147- ret = get_info(sock_net(sk), user, len, 1);
81148+ ret = get_info(sock_net(sk), user, *len, 1);
81149 break;
81150 case IP6T_SO_GET_ENTRIES:
81151 ret = compat_get_entries(sock_net(sk), user, len);
81152@@ -2021,7 +2021,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
81153
81154 switch (cmd) {
81155 case IP6T_SO_GET_INFO:
81156- ret = get_info(sock_net(sk), user, len, 0);
81157+ ret = get_info(sock_net(sk), user, *len, 0);
81158 break;
81159
81160 case IP6T_SO_GET_ENTRIES:
81161diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
81162index 70fa814..d70c28c 100644
81163--- a/net/ipv6/raw.c
81164+++ b/net/ipv6/raw.c
81165@@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
81166 {
81167 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
81168 skb_checksum_complete(skb)) {
81169- atomic_inc(&sk->sk_drops);
81170+ atomic_inc_unchecked(&sk->sk_drops);
81171 kfree_skb(skb);
81172 return NET_RX_DROP;
81173 }
81174@@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
81175 struct raw6_sock *rp = raw6_sk(sk);
81176
81177 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
81178- atomic_inc(&sk->sk_drops);
81179+ atomic_inc_unchecked(&sk->sk_drops);
81180 kfree_skb(skb);
81181 return NET_RX_DROP;
81182 }
81183@@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
81184
81185 if (inet->hdrincl) {
81186 if (skb_checksum_complete(skb)) {
81187- atomic_inc(&sk->sk_drops);
81188+ atomic_inc_unchecked(&sk->sk_drops);
81189 kfree_skb(skb);
81190 return NET_RX_DROP;
81191 }
81192@@ -604,7 +604,7 @@ out:
81193 return err;
81194 }
81195
81196-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
81197+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
81198 struct flowi6 *fl6, struct dst_entry **dstp,
81199 unsigned int flags)
81200 {
81201@@ -916,12 +916,15 @@ do_confirm:
81202 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
81203 char __user *optval, int optlen)
81204 {
81205+ struct icmp6_filter filter;
81206+
81207 switch (optname) {
81208 case ICMPV6_FILTER:
81209 if (optlen > sizeof(struct icmp6_filter))
81210 optlen = sizeof(struct icmp6_filter);
81211- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
81212+ if (copy_from_user(&filter, optval, optlen))
81213 return -EFAULT;
81214+ raw6_sk(sk)->filter = filter;
81215 return 0;
81216 default:
81217 return -ENOPROTOOPT;
81218@@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
81219 char __user *optval, int __user *optlen)
81220 {
81221 int len;
81222+ struct icmp6_filter filter;
81223
81224 switch (optname) {
81225 case ICMPV6_FILTER:
81226@@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
81227 len = sizeof(struct icmp6_filter);
81228 if (put_user(len, optlen))
81229 return -EFAULT;
81230- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
81231+ filter = raw6_sk(sk)->filter;
81232+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
81233 return -EFAULT;
81234 return 0;
81235 default:
81236@@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
81237 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
81238 0,
81239 sock_i_ino(sp),
81240- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
81241+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
81242 }
81243
81244 static int raw6_seq_show(struct seq_file *seq, void *v)
81245diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
81246index 4f435371..5de9da7 100644
81247--- a/net/ipv6/tcp_ipv6.c
81248+++ b/net/ipv6/tcp_ipv6.c
81249@@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
81250 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
81251 }
81252
81253+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81254+extern int grsec_enable_blackhole;
81255+#endif
81256+
81257 static void tcp_v6_hash(struct sock *sk)
81258 {
81259 if (sk->sk_state != TCP_CLOSE) {
81260@@ -1433,6 +1437,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
81261 return 0;
81262
81263 reset:
81264+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81265+ if (!grsec_enable_blackhole)
81266+#endif
81267 tcp_v6_send_reset(sk, skb);
81268 discard:
81269 if (opt_skb)
81270@@ -1514,12 +1521,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
81271 TCP_SKB_CB(skb)->sacked = 0;
81272
81273 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
81274- if (!sk)
81275+ if (!sk) {
81276+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81277+ ret = 1;
81278+#endif
81279 goto no_tcp_socket;
81280+ }
81281
81282 process:
81283- if (sk->sk_state == TCP_TIME_WAIT)
81284+ if (sk->sk_state == TCP_TIME_WAIT) {
81285+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81286+ ret = 2;
81287+#endif
81288 goto do_time_wait;
81289+ }
81290
81291 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
81292 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
81293@@ -1568,6 +1583,10 @@ no_tcp_socket:
81294 bad_packet:
81295 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
81296 } else {
81297+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81298+ if (!grsec_enable_blackhole || (ret == 1 &&
81299+ (skb->dev->flags & IFF_LOOPBACK)))
81300+#endif
81301 tcp_v6_send_reset(NULL, skb);
81302 }
81303
81304diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
81305index fb08329..2d6919e 100644
81306--- a/net/ipv6/udp.c
81307+++ b/net/ipv6/udp.c
81308@@ -51,6 +51,10 @@
81309 #include <trace/events/skb.h>
81310 #include "udp_impl.h"
81311
81312+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81313+extern int grsec_enable_blackhole;
81314+#endif
81315+
81316 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
81317 {
81318 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
81319@@ -395,7 +399,7 @@ try_again:
81320 if (unlikely(err)) {
81321 trace_kfree_skb(skb, udpv6_recvmsg);
81322 if (!peeked) {
81323- atomic_inc(&sk->sk_drops);
81324+ atomic_inc_unchecked(&sk->sk_drops);
81325 if (is_udp4)
81326 UDP_INC_STATS_USER(sock_net(sk),
81327 UDP_MIB_INERRORS,
81328@@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
81329 return rc;
81330 drop:
81331 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
81332- atomic_inc(&sk->sk_drops);
81333+ atomic_inc_unchecked(&sk->sk_drops);
81334 kfree_skb(skb);
81335 return -1;
81336 }
81337@@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
81338 if (likely(skb1 == NULL))
81339 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
81340 if (!skb1) {
81341- atomic_inc(&sk->sk_drops);
81342+ atomic_inc_unchecked(&sk->sk_drops);
81343 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
81344 IS_UDPLITE(sk));
81345 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
81346@@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
81347 goto discard;
81348
81349 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
81350+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81351+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
81352+#endif
81353 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
81354
81355 kfree_skb(skb);
81356@@ -1379,7 +1386,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
81357 0,
81358 sock_i_ino(sp),
81359 atomic_read(&sp->sk_refcnt), sp,
81360- atomic_read(&sp->sk_drops));
81361+ atomic_read_unchecked(&sp->sk_drops));
81362 }
81363
81364 int udp6_seq_show(struct seq_file *seq, void *v)
81365diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
81366index a68c88c..d55b0c5 100644
81367--- a/net/irda/ircomm/ircomm_tty.c
81368+++ b/net/irda/ircomm/ircomm_tty.c
81369@@ -312,12 +312,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
81370 add_wait_queue(&port->open_wait, &wait);
81371
81372 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
81373- __FILE__, __LINE__, tty->driver->name, port->count);
81374+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
81375
81376 spin_lock_irqsave(&port->lock, flags);
81377 if (!tty_hung_up_p(filp)) {
81378 extra_count = 1;
81379- port->count--;
81380+ atomic_dec(&port->count);
81381 }
81382 spin_unlock_irqrestore(&port->lock, flags);
81383 port->blocked_open++;
81384@@ -353,7 +353,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
81385 }
81386
81387 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
81388- __FILE__, __LINE__, tty->driver->name, port->count);
81389+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
81390
81391 schedule();
81392 }
81393@@ -364,13 +364,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
81394 if (extra_count) {
81395 /* ++ is not atomic, so this should be protected - Jean II */
81396 spin_lock_irqsave(&port->lock, flags);
81397- port->count++;
81398+ atomic_inc(&port->count);
81399 spin_unlock_irqrestore(&port->lock, flags);
81400 }
81401 port->blocked_open--;
81402
81403 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
81404- __FILE__, __LINE__, tty->driver->name, port->count);
81405+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
81406
81407 if (!retval)
81408 port->flags |= ASYNC_NORMAL_ACTIVE;
81409@@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
81410
81411 /* ++ is not atomic, so this should be protected - Jean II */
81412 spin_lock_irqsave(&self->port.lock, flags);
81413- self->port.count++;
81414+ atomic_inc(&self->port.count);
81415 spin_unlock_irqrestore(&self->port.lock, flags);
81416 tty_port_tty_set(&self->port, tty);
81417
81418 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
81419- self->line, self->port.count);
81420+ self->line, atomic_read(&self->port.count));
81421
81422 /* Not really used by us, but lets do it anyway */
81423 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
81424@@ -986,7 +986,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
81425 tty_kref_put(port->tty);
81426 }
81427 port->tty = NULL;
81428- port->count = 0;
81429+ atomic_set(&port->count, 0);
81430 spin_unlock_irqrestore(&port->lock, flags);
81431
81432 wake_up_interruptible(&port->open_wait);
81433@@ -1343,7 +1343,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
81434 seq_putc(m, '\n');
81435
81436 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
81437- seq_printf(m, "Open count: %d\n", self->port.count);
81438+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
81439 seq_printf(m, "Max data size: %d\n", self->max_data_size);
81440 seq_printf(m, "Max header size: %d\n", self->max_header_size);
81441
81442diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
81443index cd6f7a9..e63fe89 100644
81444--- a/net/iucv/af_iucv.c
81445+++ b/net/iucv/af_iucv.c
81446@@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
81447
81448 write_lock_bh(&iucv_sk_list.lock);
81449
81450- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
81451+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
81452 while (__iucv_get_sock_by_name(name)) {
81453 sprintf(name, "%08x",
81454- atomic_inc_return(&iucv_sk_list.autobind_name));
81455+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
81456 }
81457
81458 write_unlock_bh(&iucv_sk_list.lock);
81459diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
81460index df08250..02021fe 100644
81461--- a/net/iucv/iucv.c
81462+++ b/net/iucv/iucv.c
81463@@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
81464 return NOTIFY_OK;
81465 }
81466
81467-static struct notifier_block __refdata iucv_cpu_notifier = {
81468+static struct notifier_block iucv_cpu_notifier = {
81469 .notifier_call = iucv_cpu_notify,
81470 };
81471
81472diff --git a/net/key/af_key.c b/net/key/af_key.c
81473index 5b426a6..970032b 100644
81474--- a/net/key/af_key.c
81475+++ b/net/key/af_key.c
81476@@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
81477 static u32 get_acqseq(void)
81478 {
81479 u32 res;
81480- static atomic_t acqseq;
81481+ static atomic_unchecked_t acqseq;
81482
81483 do {
81484- res = atomic_inc_return(&acqseq);
81485+ res = atomic_inc_return_unchecked(&acqseq);
81486 } while (!res);
81487 return res;
81488 }
81489diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
81490index 0479c64..d031db6 100644
81491--- a/net/mac80211/cfg.c
81492+++ b/net/mac80211/cfg.c
81493@@ -790,7 +790,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
81494 ret = ieee80211_vif_use_channel(sdata, chandef,
81495 IEEE80211_CHANCTX_EXCLUSIVE);
81496 }
81497- } else if (local->open_count == local->monitors) {
81498+ } else if (local_read(&local->open_count) == local->monitors) {
81499 local->_oper_channel = chandef->chan;
81500 local->_oper_channel_type = cfg80211_get_chandef_type(chandef);
81501 ieee80211_hw_config(local, 0);
81502@@ -2716,7 +2716,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
81503 else
81504 local->probe_req_reg--;
81505
81506- if (!local->open_count)
81507+ if (!local_read(&local->open_count))
81508 break;
81509
81510 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
81511diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
81512index 2ed065c..948177f 100644
81513--- a/net/mac80211/ieee80211_i.h
81514+++ b/net/mac80211/ieee80211_i.h
81515@@ -28,6 +28,7 @@
81516 #include <net/ieee80211_radiotap.h>
81517 #include <net/cfg80211.h>
81518 #include <net/mac80211.h>
81519+#include <asm/local.h>
81520 #include "key.h"
81521 #include "sta_info.h"
81522 #include "debug.h"
81523@@ -909,7 +910,7 @@ struct ieee80211_local {
81524 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
81525 spinlock_t queue_stop_reason_lock;
81526
81527- int open_count;
81528+ local_t open_count;
81529 int monitors, cooked_mntrs;
81530 /* number of interfaces with corresponding FIF_ flags */
81531 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
81532diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
81533index 8be854e..ad72a69 100644
81534--- a/net/mac80211/iface.c
81535+++ b/net/mac80211/iface.c
81536@@ -546,7 +546,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
81537 break;
81538 }
81539
81540- if (local->open_count == 0) {
81541+ if (local_read(&local->open_count) == 0) {
81542 res = drv_start(local);
81543 if (res)
81544 goto err_del_bss;
81545@@ -591,7 +591,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
81546 break;
81547 }
81548
81549- if (local->monitors == 0 && local->open_count == 0) {
81550+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
81551 res = ieee80211_add_virtual_monitor(local);
81552 if (res)
81553 goto err_stop;
81554@@ -699,7 +699,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
81555 mutex_unlock(&local->mtx);
81556
81557 if (coming_up)
81558- local->open_count++;
81559+ local_inc(&local->open_count);
81560
81561 if (hw_reconf_flags)
81562 ieee80211_hw_config(local, hw_reconf_flags);
81563@@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
81564 err_del_interface:
81565 drv_remove_interface(local, sdata);
81566 err_stop:
81567- if (!local->open_count)
81568+ if (!local_read(&local->open_count))
81569 drv_stop(local);
81570 err_del_bss:
81571 sdata->bss = NULL;
81572@@ -827,7 +827,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
81573 }
81574
81575 if (going_down)
81576- local->open_count--;
81577+ local_dec(&local->open_count);
81578
81579 switch (sdata->vif.type) {
81580 case NL80211_IFTYPE_AP_VLAN:
81581@@ -884,7 +884,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
81582
81583 ieee80211_recalc_ps(local, -1);
81584
81585- if (local->open_count == 0) {
81586+ if (local_read(&local->open_count) == 0) {
81587 if (local->ops->napi_poll)
81588 napi_disable(&local->napi);
81589 ieee80211_clear_tx_pending(local);
81590@@ -910,7 +910,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
81591 }
81592 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
81593
81594- if (local->monitors == local->open_count && local->monitors > 0)
81595+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
81596 ieee80211_add_virtual_monitor(local);
81597 }
81598
81599diff --git a/net/mac80211/main.c b/net/mac80211/main.c
81600index 1b087ff..bf600e9 100644
81601--- a/net/mac80211/main.c
81602+++ b/net/mac80211/main.c
81603@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
81604 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
81605 IEEE80211_CONF_CHANGE_POWER);
81606
81607- if (changed && local->open_count) {
81608+ if (changed && local_read(&local->open_count)) {
81609 ret = drv_config(local, changed);
81610 /*
81611 * Goal:
81612diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
81613index 79a48f3..5e185c9 100644
81614--- a/net/mac80211/pm.c
81615+++ b/net/mac80211/pm.c
81616@@ -35,7 +35,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
81617 struct sta_info *sta;
81618 struct ieee80211_chanctx *ctx;
81619
81620- if (!local->open_count)
81621+ if (!local_read(&local->open_count))
81622 goto suspend;
81623
81624 ieee80211_scan_cancel(local);
81625@@ -73,7 +73,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
81626 cancel_work_sync(&local->dynamic_ps_enable_work);
81627 del_timer_sync(&local->dynamic_ps_timer);
81628
81629- local->wowlan = wowlan && local->open_count;
81630+ local->wowlan = wowlan && local_read(&local->open_count);
81631 if (local->wowlan) {
81632 int err = drv_suspend(local, wowlan);
81633 if (err < 0) {
81634@@ -187,7 +187,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
81635 mutex_unlock(&local->chanctx_mtx);
81636
81637 /* stop hardware - this must stop RX */
81638- if (local->open_count)
81639+ if (local_read(&local->open_count))
81640 ieee80211_stop_device(local);
81641
81642 suspend:
81643diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
81644index dd88381..eef4dd6 100644
81645--- a/net/mac80211/rate.c
81646+++ b/net/mac80211/rate.c
81647@@ -493,7 +493,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
81648
81649 ASSERT_RTNL();
81650
81651- if (local->open_count)
81652+ if (local_read(&local->open_count))
81653 return -EBUSY;
81654
81655 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
81656diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
81657index c97a065..ff61928 100644
81658--- a/net/mac80211/rc80211_pid_debugfs.c
81659+++ b/net/mac80211/rc80211_pid_debugfs.c
81660@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
81661
81662 spin_unlock_irqrestore(&events->lock, status);
81663
81664- if (copy_to_user(buf, pb, p))
81665+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
81666 return -EFAULT;
81667
81668 return p;
81669diff --git a/net/mac80211/util.c b/net/mac80211/util.c
81670index f11e8c5..08d0013 100644
81671--- a/net/mac80211/util.c
81672+++ b/net/mac80211/util.c
81673@@ -1380,7 +1380,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
81674 }
81675 #endif
81676 /* everything else happens only if HW was up & running */
81677- if (!local->open_count)
81678+ if (!local_read(&local->open_count))
81679 goto wake_up;
81680
81681 /*
81682diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
81683index 49e96df..63a51c3 100644
81684--- a/net/netfilter/Kconfig
81685+++ b/net/netfilter/Kconfig
81686@@ -936,6 +936,16 @@ config NETFILTER_XT_MATCH_ESP
81687
81688 To compile it as a module, choose M here. If unsure, say N.
81689
81690+config NETFILTER_XT_MATCH_GRADM
81691+ tristate '"gradm" match support'
81692+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
81693+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
81694+ ---help---
81695+ The gradm match allows to match on grsecurity RBAC being enabled.
81696+ It is useful when iptables rules are applied early on bootup to
81697+ prevent connections to the machine (except from a trusted host)
81698+ while the RBAC system is disabled.
81699+
81700 config NETFILTER_XT_MATCH_HASHLIMIT
81701 tristate '"hashlimit" match support'
81702 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
81703diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
81704index 3259697..54d5393 100644
81705--- a/net/netfilter/Makefile
81706+++ b/net/netfilter/Makefile
81707@@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
81708 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
81709 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
81710 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
81711+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
81712 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
81713 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
81714 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
81715diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
81716index 30e764a..c3b6a9d 100644
81717--- a/net/netfilter/ipvs/ip_vs_conn.c
81718+++ b/net/netfilter/ipvs/ip_vs_conn.c
81719@@ -554,7 +554,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
81720 /* Increase the refcnt counter of the dest */
81721 atomic_inc(&dest->refcnt);
81722
81723- conn_flags = atomic_read(&dest->conn_flags);
81724+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
81725 if (cp->protocol != IPPROTO_UDP)
81726 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
81727 flags = cp->flags;
81728@@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
81729 atomic_set(&cp->refcnt, 1);
81730
81731 atomic_set(&cp->n_control, 0);
81732- atomic_set(&cp->in_pkts, 0);
81733+ atomic_set_unchecked(&cp->in_pkts, 0);
81734
81735 atomic_inc(&ipvs->conn_count);
81736 if (flags & IP_VS_CONN_F_NO_CPORT)
81737@@ -1180,7 +1180,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
81738
81739 /* Don't drop the entry if its number of incoming packets is not
81740 located in [0, 8] */
81741- i = atomic_read(&cp->in_pkts);
81742+ i = atomic_read_unchecked(&cp->in_pkts);
81743 if (i > 8 || i < 0) return 0;
81744
81745 if (!todrop_rate[i]) return 0;
81746diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
81747index 47edf5a..235b07d 100644
81748--- a/net/netfilter/ipvs/ip_vs_core.c
81749+++ b/net/netfilter/ipvs/ip_vs_core.c
81750@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
81751 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
81752 /* do not touch skb anymore */
81753
81754- atomic_inc(&cp->in_pkts);
81755+ atomic_inc_unchecked(&cp->in_pkts);
81756 ip_vs_conn_put(cp);
81757 return ret;
81758 }
81759@@ -1691,7 +1691,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
81760 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
81761 pkts = sysctl_sync_threshold(ipvs);
81762 else
81763- pkts = atomic_add_return(1, &cp->in_pkts);
81764+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
81765
81766 if (ipvs->sync_state & IP_VS_STATE_MASTER)
81767 ip_vs_sync_conn(net, cp, pkts);
81768diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
81769index ec664cb..cd576ab 100644
81770--- a/net/netfilter/ipvs/ip_vs_ctl.c
81771+++ b/net/netfilter/ipvs/ip_vs_ctl.c
81772@@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
81773 ip_vs_rs_hash(ipvs, dest);
81774 write_unlock_bh(&ipvs->rs_lock);
81775 }
81776- atomic_set(&dest->conn_flags, conn_flags);
81777+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
81778
81779 /* bind the service */
81780 if (!dest->svc) {
81781@@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
81782 " %-7s %-6d %-10d %-10d\n",
81783 &dest->addr.in6,
81784 ntohs(dest->port),
81785- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
81786+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
81787 atomic_read(&dest->weight),
81788 atomic_read(&dest->activeconns),
81789 atomic_read(&dest->inactconns));
81790@@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
81791 "%-7s %-6d %-10d %-10d\n",
81792 ntohl(dest->addr.ip),
81793 ntohs(dest->port),
81794- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
81795+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
81796 atomic_read(&dest->weight),
81797 atomic_read(&dest->activeconns),
81798 atomic_read(&dest->inactconns));
81799@@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
81800
81801 entry.addr = dest->addr.ip;
81802 entry.port = dest->port;
81803- entry.conn_flags = atomic_read(&dest->conn_flags);
81804+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
81805 entry.weight = atomic_read(&dest->weight);
81806 entry.u_threshold = dest->u_threshold;
81807 entry.l_threshold = dest->l_threshold;
81808@@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
81809 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
81810 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
81811 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
81812- (atomic_read(&dest->conn_flags) &
81813+ (atomic_read_unchecked(&dest->conn_flags) &
81814 IP_VS_CONN_F_FWD_MASK)) ||
81815 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
81816 atomic_read(&dest->weight)) ||
81817diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
81818index 44fd10c..2a163b3 100644
81819--- a/net/netfilter/ipvs/ip_vs_sync.c
81820+++ b/net/netfilter/ipvs/ip_vs_sync.c
81821@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
81822 cp = cp->control;
81823 if (cp) {
81824 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
81825- pkts = atomic_add_return(1, &cp->in_pkts);
81826+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
81827 else
81828 pkts = sysctl_sync_threshold(ipvs);
81829 ip_vs_sync_conn(net, cp->control, pkts);
81830@@ -758,7 +758,7 @@ control:
81831 if (!cp)
81832 return;
81833 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
81834- pkts = atomic_add_return(1, &cp->in_pkts);
81835+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
81836 else
81837 pkts = sysctl_sync_threshold(ipvs);
81838 goto sloop;
81839@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
81840
81841 if (opt)
81842 memcpy(&cp->in_seq, opt, sizeof(*opt));
81843- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
81844+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
81845 cp->state = state;
81846 cp->old_state = cp->state;
81847 /*
81848diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
81849index ee6b7a9..f9a89f6 100644
81850--- a/net/netfilter/ipvs/ip_vs_xmit.c
81851+++ b/net/netfilter/ipvs/ip_vs_xmit.c
81852@@ -1210,7 +1210,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
81853 else
81854 rc = NF_ACCEPT;
81855 /* do not touch skb anymore */
81856- atomic_inc(&cp->in_pkts);
81857+ atomic_inc_unchecked(&cp->in_pkts);
81858 goto out;
81859 }
81860
81861@@ -1332,7 +1332,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
81862 else
81863 rc = NF_ACCEPT;
81864 /* do not touch skb anymore */
81865- atomic_inc(&cp->in_pkts);
81866+ atomic_inc_unchecked(&cp->in_pkts);
81867 goto out;
81868 }
81869
81870diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
81871index e4a0c4f..c263f28 100644
81872--- a/net/netfilter/nf_conntrack_core.c
81873+++ b/net/netfilter/nf_conntrack_core.c
81874@@ -1529,6 +1529,10 @@ err_extend:
81875 #define DYING_NULLS_VAL ((1<<30)+1)
81876 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
81877
81878+#ifdef CONFIG_GRKERNSEC_HIDESYM
81879+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
81880+#endif
81881+
81882 static int nf_conntrack_init_net(struct net *net)
81883 {
81884 int ret;
81885@@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
81886 goto err_stat;
81887 }
81888
81889+#ifdef CONFIG_GRKERNSEC_HIDESYM
81890+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
81891+#else
81892 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
81893+#endif
81894 if (!net->ct.slabname) {
81895 ret = -ENOMEM;
81896 goto err_slabname;
81897diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
81898index 92fd8ec..3f6ea4b 100644
81899--- a/net/netfilter/nfnetlink_log.c
81900+++ b/net/netfilter/nfnetlink_log.c
81901@@ -72,7 +72,7 @@ struct nfulnl_instance {
81902 };
81903
81904 static DEFINE_SPINLOCK(instances_lock);
81905-static atomic_t global_seq;
81906+static atomic_unchecked_t global_seq;
81907
81908 #define INSTANCE_BUCKETS 16
81909 static struct hlist_head instance_table[INSTANCE_BUCKETS];
81910@@ -537,7 +537,7 @@ __build_packet_message(struct nfulnl_instance *inst,
81911 /* global sequence number */
81912 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
81913 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
81914- htonl(atomic_inc_return(&global_seq))))
81915+ htonl(atomic_inc_return_unchecked(&global_seq))))
81916 goto nla_put_failure;
81917
81918 if (data_len) {
81919diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
81920new file mode 100644
81921index 0000000..c566332
81922--- /dev/null
81923+++ b/net/netfilter/xt_gradm.c
81924@@ -0,0 +1,51 @@
81925+/*
81926+ * gradm match for netfilter
81927