]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.8.1-201303012255.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.8.1-201303012255.patch
CommitLineData
6109fa7a
PK
1diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2index b89a739..dba90c5 100644
3--- a/Documentation/dontdiff
4+++ b/Documentation/dontdiff
5@@ -2,9 +2,11 @@
6 *.aux
7 *.bin
8 *.bz2
9+*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13+*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17@@ -14,6 +16,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21+*.gmo
22 *.grep
23 *.grp
24 *.gz
25@@ -48,14 +51,17 @@
26 *.tab.h
27 *.tex
28 *.ver
29+*.vim
30 *.xml
31 *.xz
32 *_MODULES
33+*_reg_safe.h
34 *_vga16.c
35 *~
36 \#*#
37 *.9
38-.*
39+.[^g]*
40+.gen*
41 .*.d
42 .mm
43 53c700_d.h
44@@ -69,6 +75,7 @@ Image
45 Module.markers
46 Module.symvers
47 PENDING
48+PERF*
49 SCCS
50 System.map*
51 TAGS
52@@ -80,6 +87,7 @@ aic7*seq.h*
53 aicasm
54 aicdb.h*
55 altivec*.c
56+ashldi3.S
57 asm-offsets.h
58 asm_offsets.h
59 autoconf.h*
60@@ -92,19 +100,24 @@ bounds.h
61 bsetup
62 btfixupprep
63 build
64+builtin-policy.h
65 bvmlinux
66 bzImage*
67 capability_names.h
68 capflags.c
69 classlist.h*
70+clut_vga16.c
71+common-cmds.h
72 comp*.log
73 compile.h*
74 conf
75 config
76 config-*
77 config_data.h*
78+config.c
79 config.mak
80 config.mak.autogen
81+config.tmp
82 conmakehash
83 consolemap_deftbl.c*
84 cpustr.h
85@@ -115,9 +128,11 @@ devlist.h*
86 dnotify_test
87 docproc
88 dslm
89+dtc-lexer.lex.c
90 elf2ecoff
91 elfconfig.h*
92 evergreen_reg_safe.h
93+exception_policy.conf
94 fixdep
95 flask.h
96 fore200e_mkfirm
97@@ -125,12 +140,15 @@ fore200e_pca_fw.c*
98 gconf
99 gconf.glade.h
100 gen-devlist
101+gen-kdb_cmds.c
102 gen_crc32table
103 gen_init_cpio
104 generated
105 genheaders
106 genksyms
107 *_gray256.c
108+hash
109+hid-example
110 hpet_example
111 hugepage-mmap
112 hugepage-shm
113@@ -145,14 +163,14 @@ int32.c
114 int4.c
115 int8.c
116 kallsyms
117-kconfig
118+kern_constants.h
119 keywords.c
120 ksym.c*
121 ksym.h*
122 kxgettext
123 lex.c
124 lex.*.c
125-linux
126+lib1funcs.S
127 logo_*.c
128 logo_*_clut224.c
129 logo_*_mono.c
130@@ -162,14 +180,15 @@ mach-types.h
131 machtypes.h
132 map
133 map_hugetlb
134-media
135 mconf
136+mdp
137 miboot*
138 mk_elfconfig
139 mkboot
140 mkbugboot
141 mkcpustr
142 mkdep
143+mkpiggy
144 mkprep
145 mkregtable
146 mktables
147@@ -185,6 +204,8 @@ oui.c*
148 page-types
149 parse.c
150 parse.h
151+parse-events*
152+pasyms.h
153 patches*
154 pca200e.bin
155 pca200e_ecd.bin2
156@@ -194,6 +215,7 @@ perf-archive
157 piggyback
158 piggy.gzip
159 piggy.S
160+pmu-*
161 pnmtologo
162 ppc_defs.h*
163 pss_boot.h
164@@ -203,7 +225,10 @@ r200_reg_safe.h
165 r300_reg_safe.h
166 r420_reg_safe.h
167 r600_reg_safe.h
168+realmode.lds
169+realmode.relocs
170 recordmcount
171+regdb.c
172 relocs
173 rlim_names.h
174 rn50_reg_safe.h
175@@ -213,8 +238,11 @@ series
176 setup
177 setup.bin
178 setup.elf
179+size_overflow_hash.h
180 sImage
181+slabinfo
182 sm_tbl*
183+sortextable
184 split-include
185 syscalltab.h
186 tables.c
187@@ -224,6 +252,7 @@ tftpboot.img
188 timeconst.h
189 times.h*
190 trix_boot.h
191+user_constants.h
192 utsrelease.h*
193 vdso-syms.lds
194 vdso.lds
195@@ -235,13 +264,17 @@ vdso32.lds
196 vdso32.so.dbg
197 vdso64.lds
198 vdso64.so.dbg
199+vdsox32.lds
200+vdsox32-syms.lds
201 version.h*
202 vmImage
203 vmlinux
204 vmlinux-*
205 vmlinux.aout
206 vmlinux.bin.all
207+vmlinux.bin.bz2
208 vmlinux.lds
209+vmlinux.relocs
210 vmlinuz
211 voffset.h
212 vsyscall.lds
213@@ -249,9 +282,11 @@ vsyscall_32.lds
214 wanxlfw.inc
215 uImage
216 unifdef
217+utsrelease.h
218 wakeup.bin
219 wakeup.elf
220 wakeup.lds
221 zImage*
222 zconf.hash.c
223+zconf.lex.c
224 zoffset.h
225diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
226index 6c72381..2fe9ae4 100644
227--- a/Documentation/kernel-parameters.txt
228+++ b/Documentation/kernel-parameters.txt
229@@ -917,6 +917,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
230 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
231 Default: 1024
232
233+ grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
234+ ignore grsecurity's /proc restrictions
235+
236+
237 hashdist= [KNL,NUMA] Large hashes allocated during boot
238 are distributed across NUMA nodes. Defaults on
239 for 64-bit NUMA, off otherwise.
240@@ -2116,6 +2120,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
241 the specified number of seconds. This is to be used if
242 your oopses keep scrolling off the screen.
243
244+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
245+ virtualization environments that don't cope well with the
246+ expand down segment used by UDEREF on X86-32 or the frequent
247+ page table updates on X86-64.
248+
249+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
250+
251 pcbit= [HW,ISDN]
252
253 pcd. [PARIDE]
254diff --git a/Makefile b/Makefile
255index 746c856..c014cfa 100644
256--- a/Makefile
257+++ b/Makefile
258@@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
259
260 HOSTCC = gcc
261 HOSTCXX = g++
262-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
263-HOSTCXXFLAGS = -O2
264+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
265+HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
266+HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
267
268 # Decide whether to build built-in, modular, or both.
269 # Normally, just do built-in.
270@@ -414,8 +415,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
271 # Rules shared between *config targets and build targets
272
273 # Basic helpers built in scripts/
274-PHONY += scripts_basic
275-scripts_basic:
276+PHONY += scripts_basic gcc-plugins
277+scripts_basic: gcc-plugins
278 $(Q)$(MAKE) $(build)=scripts/basic
279 $(Q)rm -f .tmp_quiet_recordmcount
280
281@@ -575,6 +576,64 @@ else
282 KBUILD_CFLAGS += -O2
283 endif
284
285+ifndef DISABLE_PAX_PLUGINS
286+ifeq ($(call cc-ifversion, -ge, 0408, y), y)
287+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
288+else
289+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
290+endif
291+ifneq ($(PLUGINCC),)
292+ifndef DISABLE_PAX_CONSTIFY_PLUGIN
293+ifndef CONFIG_UML
294+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
295+endif
296+endif
297+ifdef CONFIG_PAX_MEMORY_STACKLEAK
298+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
299+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
300+endif
301+ifdef CONFIG_KALLOCSTAT_PLUGIN
302+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
303+endif
304+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
305+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
306+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
307+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
308+endif
309+ifdef CONFIG_CHECKER_PLUGIN
310+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
311+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
312+endif
313+endif
314+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
315+ifdef CONFIG_PAX_SIZE_OVERFLOW
316+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
317+endif
318+ifdef CONFIG_PAX_LATENT_ENTROPY
319+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
320+endif
321+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
322+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
323+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS)
324+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
325+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
326+ifeq ($(KBUILD_EXTMOD),)
327+gcc-plugins:
328+ $(Q)$(MAKE) $(build)=tools/gcc
329+else
330+gcc-plugins: ;
331+endif
332+else
333+gcc-plugins:
334+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
335+ $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
336+else
337+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
338+endif
339+ $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
340+endif
341+endif
342+
343 include $(srctree)/arch/$(SRCARCH)/Makefile
344
345 ifdef CONFIG_READABLE_ASM
346@@ -731,7 +790,7 @@ export mod_sign_cmd
347
348
349 ifeq ($(KBUILD_EXTMOD),)
350-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
351+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
352
353 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
354 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
355@@ -778,6 +837,8 @@ endif
356
357 # The actual objects are generated when descending,
358 # make sure no implicit rule kicks in
359+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
360+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
361 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
362
363 # Handle descending into subdirectories listed in $(vmlinux-dirs)
364@@ -787,7 +848,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
365 # Error messages still appears in the original language
366
367 PHONY += $(vmlinux-dirs)
368-$(vmlinux-dirs): prepare scripts
369+$(vmlinux-dirs): gcc-plugins prepare scripts
370 $(Q)$(MAKE) $(build)=$@
371
372 # Store (new) KERNELRELASE string in include/config/kernel.release
373@@ -831,6 +892,7 @@ prepare0: archprepare FORCE
374 $(Q)$(MAKE) $(build)=.
375
376 # All the preparing..
377+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
378 prepare: prepare0
379
380 # Generate some files
381@@ -938,6 +1000,8 @@ all: modules
382 # using awk while concatenating to the final file.
383
384 PHONY += modules
385+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
386+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
387 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
388 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
389 @$(kecho) ' Building modules, stage 2.';
390@@ -953,7 +1017,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
391
392 # Target to prepare building external modules
393 PHONY += modules_prepare
394-modules_prepare: prepare scripts
395+modules_prepare: gcc-plugins prepare scripts
396
397 # Target to install modules
398 PHONY += modules_install
399@@ -1019,7 +1083,7 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
400 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
401 signing_key.priv signing_key.x509 x509.genkey \
402 extra_certificates signing_key.x509.keyid \
403- signing_key.x509.signer
404+ signing_key.x509.signer tools/gcc/size_overflow_hash.h
405
406 # clean - Delete most, but leave enough to build external modules
407 #
408@@ -1059,6 +1123,7 @@ distclean: mrproper
409 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
410 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
411 -o -name '.*.rej' \
412+ -o -name '.*.rej' -o -name '*.so' \
413 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
414 -type f -print | xargs rm -f
415
416@@ -1219,6 +1284,8 @@ PHONY += $(module-dirs) modules
417 $(module-dirs): crmodverdir $(objtree)/Module.symvers
418 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
419
420+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
421+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
422 modules: $(module-dirs)
423 @$(kecho) ' Building modules, stage 2.';
424 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
425@@ -1355,17 +1422,21 @@ else
426 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
427 endif
428
429-%.s: %.c prepare scripts FORCE
430+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
431+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
432+%.s: %.c gcc-plugins prepare scripts FORCE
433 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
434 %.i: %.c prepare scripts FORCE
435 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
436-%.o: %.c prepare scripts FORCE
437+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
438+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
439+%.o: %.c gcc-plugins prepare scripts FORCE
440 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
441 %.lst: %.c prepare scripts FORCE
442 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
443-%.s: %.S prepare scripts FORCE
444+%.s: %.S gcc-plugins prepare scripts FORCE
445 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
446-%.o: %.S prepare scripts FORCE
447+%.o: %.S gcc-plugins prepare scripts FORCE
448 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
449 %.symtypes: %.c prepare scripts FORCE
450 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
451@@ -1375,11 +1446,15 @@ endif
452 $(cmd_crmodverdir)
453 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
454 $(build)=$(build-dir)
455-%/: prepare scripts FORCE
456+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
457+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
458+%/: gcc-plugins prepare scripts FORCE
459 $(cmd_crmodverdir)
460 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
461 $(build)=$(build-dir)
462-%.ko: prepare scripts FORCE
463+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
464+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
465+%.ko: gcc-plugins prepare scripts FORCE
466 $(cmd_crmodverdir)
467 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
468 $(build)=$(build-dir) $(@:.ko=.o)
469diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
470index c2cbe4f..f7264b4 100644
471--- a/arch/alpha/include/asm/atomic.h
472+++ b/arch/alpha/include/asm/atomic.h
473@@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
474 #define atomic_dec(v) atomic_sub(1,(v))
475 #define atomic64_dec(v) atomic64_sub(1,(v))
476
477+#define atomic64_read_unchecked(v) atomic64_read(v)
478+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
479+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
480+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
481+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
482+#define atomic64_inc_unchecked(v) atomic64_inc(v)
483+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
484+#define atomic64_dec_unchecked(v) atomic64_dec(v)
485+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
486+
487 #define smp_mb__before_atomic_dec() smp_mb()
488 #define smp_mb__after_atomic_dec() smp_mb()
489 #define smp_mb__before_atomic_inc() smp_mb()
490diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
491index ad368a9..fbe0f25 100644
492--- a/arch/alpha/include/asm/cache.h
493+++ b/arch/alpha/include/asm/cache.h
494@@ -4,19 +4,19 @@
495 #ifndef __ARCH_ALPHA_CACHE_H
496 #define __ARCH_ALPHA_CACHE_H
497
498+#include <linux/const.h>
499
500 /* Bytes per L1 (data) cache line. */
501 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
502-# define L1_CACHE_BYTES 64
503 # define L1_CACHE_SHIFT 6
504 #else
505 /* Both EV4 and EV5 are write-through, read-allocate,
506 direct-mapped, physical.
507 */
508-# define L1_CACHE_BYTES 32
509 # define L1_CACHE_SHIFT 5
510 #endif
511
512+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
513 #define SMP_CACHE_BYTES L1_CACHE_BYTES
514
515 #endif
516diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
517index 968d999..d36b2df 100644
518--- a/arch/alpha/include/asm/elf.h
519+++ b/arch/alpha/include/asm/elf.h
520@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
521
522 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
523
524+#ifdef CONFIG_PAX_ASLR
525+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
526+
527+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
528+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
529+#endif
530+
531 /* $0 is set by ld.so to a pointer to a function which might be
532 registered using atexit. This provides a mean for the dynamic
533 linker to call DT_FINI functions for shared libraries that have
534diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
535index bc2a0da..8ad11ee 100644
536--- a/arch/alpha/include/asm/pgalloc.h
537+++ b/arch/alpha/include/asm/pgalloc.h
538@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
539 pgd_set(pgd, pmd);
540 }
541
542+static inline void
543+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
544+{
545+ pgd_populate(mm, pgd, pmd);
546+}
547+
548 extern pgd_t *pgd_alloc(struct mm_struct *mm);
549
550 static inline void
551diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
552index 81a4342..348b927 100644
553--- a/arch/alpha/include/asm/pgtable.h
554+++ b/arch/alpha/include/asm/pgtable.h
555@@ -102,6 +102,17 @@ struct vm_area_struct;
556 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
557 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
558 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
559+
560+#ifdef CONFIG_PAX_PAGEEXEC
561+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
562+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
563+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
564+#else
565+# define PAGE_SHARED_NOEXEC PAGE_SHARED
566+# define PAGE_COPY_NOEXEC PAGE_COPY
567+# define PAGE_READONLY_NOEXEC PAGE_READONLY
568+#endif
569+
570 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
571
572 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
573diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
574index 2fd00b7..cfd5069 100644
575--- a/arch/alpha/kernel/module.c
576+++ b/arch/alpha/kernel/module.c
577@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
578
579 /* The small sections were sorted to the end of the segment.
580 The following should definitely cover them. */
581- gp = (u64)me->module_core + me->core_size - 0x8000;
582+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
583 got = sechdrs[me->arch.gotsecindex].sh_addr;
584
585 for (i = 0; i < n; i++) {
586diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
587index 14db93e..47bed62 100644
588--- a/arch/alpha/kernel/osf_sys.c
589+++ b/arch/alpha/kernel/osf_sys.c
590@@ -1295,16 +1295,16 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
591 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
592
593 static unsigned long
594-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
595- unsigned long limit)
596+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
597+ unsigned long limit, unsigned long flags)
598 {
599 struct vm_area_struct *vma = find_vma(current->mm, addr);
600-
601+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
602 while (1) {
603 /* At this point: (!vma || addr < vma->vm_end). */
604 if (limit - len < addr)
605 return -ENOMEM;
606- if (!vma || addr + len <= vma->vm_start)
607+ if (check_heap_stack_gap(vma, addr, len, offset))
608 return addr;
609 addr = vma->vm_end;
610 vma = vma->vm_next;
611@@ -1340,20 +1340,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
612 merely specific addresses, but regions of memory -- perhaps
613 this feature should be incorporated into all ports? */
614
615+#ifdef CONFIG_PAX_RANDMMAP
616+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
617+#endif
618+
619 if (addr) {
620- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
621+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
622 if (addr != (unsigned long) -ENOMEM)
623 return addr;
624 }
625
626 /* Next, try allocating at TASK_UNMAPPED_BASE. */
627- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
628- len, limit);
629+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
630+
631 if (addr != (unsigned long) -ENOMEM)
632 return addr;
633
634 /* Finally, try allocating in low memory. */
635- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
636+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
637
638 return addr;
639 }
640diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
641index 0c4132d..88f0d53 100644
642--- a/arch/alpha/mm/fault.c
643+++ b/arch/alpha/mm/fault.c
644@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
645 __reload_thread(pcb);
646 }
647
648+#ifdef CONFIG_PAX_PAGEEXEC
649+/*
650+ * PaX: decide what to do with offenders (regs->pc = fault address)
651+ *
652+ * returns 1 when task should be killed
653+ * 2 when patched PLT trampoline was detected
654+ * 3 when unpatched PLT trampoline was detected
655+ */
656+static int pax_handle_fetch_fault(struct pt_regs *regs)
657+{
658+
659+#ifdef CONFIG_PAX_EMUPLT
660+ int err;
661+
662+ do { /* PaX: patched PLT emulation #1 */
663+ unsigned int ldah, ldq, jmp;
664+
665+ err = get_user(ldah, (unsigned int *)regs->pc);
666+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
667+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
668+
669+ if (err)
670+ break;
671+
672+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
673+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
674+ jmp == 0x6BFB0000U)
675+ {
676+ unsigned long r27, addr;
677+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
678+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
679+
680+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
681+ err = get_user(r27, (unsigned long *)addr);
682+ if (err)
683+ break;
684+
685+ regs->r27 = r27;
686+ regs->pc = r27;
687+ return 2;
688+ }
689+ } while (0);
690+
691+ do { /* PaX: patched PLT emulation #2 */
692+ unsigned int ldah, lda, br;
693+
694+ err = get_user(ldah, (unsigned int *)regs->pc);
695+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
696+ err |= get_user(br, (unsigned int *)(regs->pc+8));
697+
698+ if (err)
699+ break;
700+
701+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
702+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
703+ (br & 0xFFE00000U) == 0xC3E00000U)
704+ {
705+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
706+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
707+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
708+
709+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
710+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
711+ return 2;
712+ }
713+ } while (0);
714+
715+ do { /* PaX: unpatched PLT emulation */
716+ unsigned int br;
717+
718+ err = get_user(br, (unsigned int *)regs->pc);
719+
720+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
721+ unsigned int br2, ldq, nop, jmp;
722+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
723+
724+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
725+ err = get_user(br2, (unsigned int *)addr);
726+ err |= get_user(ldq, (unsigned int *)(addr+4));
727+ err |= get_user(nop, (unsigned int *)(addr+8));
728+ err |= get_user(jmp, (unsigned int *)(addr+12));
729+ err |= get_user(resolver, (unsigned long *)(addr+16));
730+
731+ if (err)
732+ break;
733+
734+ if (br2 == 0xC3600000U &&
735+ ldq == 0xA77B000CU &&
736+ nop == 0x47FF041FU &&
737+ jmp == 0x6B7B0000U)
738+ {
739+ regs->r28 = regs->pc+4;
740+ regs->r27 = addr+16;
741+ regs->pc = resolver;
742+ return 3;
743+ }
744+ }
745+ } while (0);
746+#endif
747+
748+ return 1;
749+}
750+
751+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
752+{
753+ unsigned long i;
754+
755+ printk(KERN_ERR "PAX: bytes at PC: ");
756+ for (i = 0; i < 5; i++) {
757+ unsigned int c;
758+ if (get_user(c, (unsigned int *)pc+i))
759+ printk(KERN_CONT "???????? ");
760+ else
761+ printk(KERN_CONT "%08x ", c);
762+ }
763+ printk("\n");
764+}
765+#endif
766
767 /*
768 * This routine handles page faults. It determines the address,
769@@ -133,8 +251,29 @@ retry:
770 good_area:
771 si_code = SEGV_ACCERR;
772 if (cause < 0) {
773- if (!(vma->vm_flags & VM_EXEC))
774+ if (!(vma->vm_flags & VM_EXEC)) {
775+
776+#ifdef CONFIG_PAX_PAGEEXEC
777+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
778+ goto bad_area;
779+
780+ up_read(&mm->mmap_sem);
781+ switch (pax_handle_fetch_fault(regs)) {
782+
783+#ifdef CONFIG_PAX_EMUPLT
784+ case 2:
785+ case 3:
786+ return;
787+#endif
788+
789+ }
790+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
791+ do_group_exit(SIGKILL);
792+#else
793 goto bad_area;
794+#endif
795+
796+ }
797 } else if (!cause) {
798 /* Allow reads even for write-only mappings */
799 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
800diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
801index 67874b8..0e40765 100644
802--- a/arch/arm/Kconfig
803+++ b/arch/arm/Kconfig
804@@ -1813,7 +1813,7 @@ config ALIGNMENT_TRAP
805
806 config UACCESS_WITH_MEMCPY
807 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
808- depends on MMU
809+ depends on MMU && !PAX_MEMORY_UDEREF
810 default y if CPU_FEROCEON
811 help
812 Implement faster copy_to_user and clear_user methods for CPU
813diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
814index c79f61f..9ac0642 100644
815--- a/arch/arm/include/asm/atomic.h
816+++ b/arch/arm/include/asm/atomic.h
817@@ -17,17 +17,35 @@
818 #include <asm/barrier.h>
819 #include <asm/cmpxchg.h>
820
821+#ifdef CONFIG_GENERIC_ATOMIC64
822+#include <asm-generic/atomic64.h>
823+#endif
824+
825 #define ATOMIC_INIT(i) { (i) }
826
827 #ifdef __KERNEL__
828
829+#define _ASM_EXTABLE(from, to) \
830+" .pushsection __ex_table,\"a\"\n"\
831+" .align 3\n" \
832+" .long " #from ", " #to"\n" \
833+" .popsection"
834+
835 /*
836 * On ARM, ordinary assignment (str instruction) doesn't clear the local
837 * strex/ldrex monitor on some implementations. The reason we can use it for
838 * atomic_set() is the clrex or dummy strex done on every exception return.
839 */
840 #define atomic_read(v) (*(volatile int *)&(v)->counter)
841+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
842+{
843+ return v->counter;
844+}
845 #define atomic_set(v,i) (((v)->counter) = (i))
846+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
847+{
848+ v->counter = i;
849+}
850
851 #if __LINUX_ARM_ARCH__ >= 6
852
853@@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
854 int result;
855
856 __asm__ __volatile__("@ atomic_add\n"
857+"1: ldrex %1, [%3]\n"
858+" adds %0, %1, %4\n"
859+
860+#ifdef CONFIG_PAX_REFCOUNT
861+" bvc 3f\n"
862+"2: bkpt 0xf103\n"
863+"3:\n"
864+#endif
865+
866+" strex %1, %0, [%3]\n"
867+" teq %1, #0\n"
868+" bne 1b"
869+
870+#ifdef CONFIG_PAX_REFCOUNT
871+"\n4:\n"
872+ _ASM_EXTABLE(2b, 4b)
873+#endif
874+
875+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
876+ : "r" (&v->counter), "Ir" (i)
877+ : "cc");
878+}
879+
880+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
881+{
882+ unsigned long tmp;
883+ int result;
884+
885+ __asm__ __volatile__("@ atomic_add_unchecked\n"
886 "1: ldrex %0, [%3]\n"
887 " add %0, %0, %4\n"
888 " strex %1, %0, [%3]\n"
889@@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
890 smp_mb();
891
892 __asm__ __volatile__("@ atomic_add_return\n"
893+"1: ldrex %1, [%3]\n"
894+" adds %0, %1, %4\n"
895+
896+#ifdef CONFIG_PAX_REFCOUNT
897+" bvc 3f\n"
898+" mov %0, %1\n"
899+"2: bkpt 0xf103\n"
900+"3:\n"
901+#endif
902+
903+" strex %1, %0, [%3]\n"
904+" teq %1, #0\n"
905+" bne 1b"
906+
907+#ifdef CONFIG_PAX_REFCOUNT
908+"\n4:\n"
909+ _ASM_EXTABLE(2b, 4b)
910+#endif
911+
912+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
913+ : "r" (&v->counter), "Ir" (i)
914+ : "cc");
915+
916+ smp_mb();
917+
918+ return result;
919+}
920+
921+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
922+{
923+ unsigned long tmp;
924+ int result;
925+
926+ smp_mb();
927+
928+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
929 "1: ldrex %0, [%3]\n"
930 " add %0, %0, %4\n"
931 " strex %1, %0, [%3]\n"
932@@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
933 int result;
934
935 __asm__ __volatile__("@ atomic_sub\n"
936+"1: ldrex %1, [%3]\n"
937+" subs %0, %1, %4\n"
938+
939+#ifdef CONFIG_PAX_REFCOUNT
940+" bvc 3f\n"
941+"2: bkpt 0xf103\n"
942+"3:\n"
943+#endif
944+
945+" strex %1, %0, [%3]\n"
946+" teq %1, #0\n"
947+" bne 1b"
948+
949+#ifdef CONFIG_PAX_REFCOUNT
950+"\n4:\n"
951+ _ASM_EXTABLE(2b, 4b)
952+#endif
953+
954+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
955+ : "r" (&v->counter), "Ir" (i)
956+ : "cc");
957+}
958+
959+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
960+{
961+ unsigned long tmp;
962+ int result;
963+
964+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
965 "1: ldrex %0, [%3]\n"
966 " sub %0, %0, %4\n"
967 " strex %1, %0, [%3]\n"
968@@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
969 smp_mb();
970
971 __asm__ __volatile__("@ atomic_sub_return\n"
972-"1: ldrex %0, [%3]\n"
973-" sub %0, %0, %4\n"
974+"1: ldrex %1, [%3]\n"
975+" subs %0, %1, %4\n"
976+
977+#ifdef CONFIG_PAX_REFCOUNT
978+" bvc 3f\n"
979+" mov %0, %1\n"
980+"2: bkpt 0xf103\n"
981+"3:\n"
982+#endif
983+
984 " strex %1, %0, [%3]\n"
985 " teq %1, #0\n"
986 " bne 1b"
987+
988+#ifdef CONFIG_PAX_REFCOUNT
989+"\n4:\n"
990+ _ASM_EXTABLE(2b, 4b)
991+#endif
992+
993 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
994 : "r" (&v->counter), "Ir" (i)
995 : "cc");
996@@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
997 return oldval;
998 }
999
1000+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1001+{
1002+ unsigned long oldval, res;
1003+
1004+ smp_mb();
1005+
1006+ do {
1007+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1008+ "ldrex %1, [%3]\n"
1009+ "mov %0, #0\n"
1010+ "teq %1, %4\n"
1011+ "strexeq %0, %5, [%3]\n"
1012+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1013+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1014+ : "cc");
1015+ } while (res);
1016+
1017+ smp_mb();
1018+
1019+ return oldval;
1020+}
1021+
1022 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1023 {
1024 unsigned long tmp, tmp2;
1025@@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1026
1027 return val;
1028 }
1029+
1030+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1031+{
1032+ return atomic_add_return(i, v);
1033+}
1034+
1035 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1036+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1037+{
1038+ (void) atomic_add_return(i, v);
1039+}
1040
1041 static inline int atomic_sub_return(int i, atomic_t *v)
1042 {
1043@@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1044 return val;
1045 }
1046 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1047+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1048+{
1049+ (void) atomic_sub_return(i, v);
1050+}
1051
1052 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1053 {
1054@@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1055 return ret;
1056 }
1057
1058+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1059+{
1060+ return atomic_cmpxchg(v, old, new);
1061+}
1062+
1063 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1064 {
1065 unsigned long flags;
1066@@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1067 #endif /* __LINUX_ARM_ARCH__ */
1068
1069 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1070+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1071+{
1072+ return xchg(&v->counter, new);
1073+}
1074
1075 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1076 {
1077@@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1078 }
1079
1080 #define atomic_inc(v) atomic_add(1, v)
1081+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1082+{
1083+ atomic_add_unchecked(1, v);
1084+}
1085 #define atomic_dec(v) atomic_sub(1, v)
1086+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1087+{
1088+ atomic_sub_unchecked(1, v);
1089+}
1090
1091 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1092+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1093+{
1094+ return atomic_add_return_unchecked(1, v) == 0;
1095+}
1096 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1097 #define atomic_inc_return(v) (atomic_add_return(1, v))
1098+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1099+{
1100+ return atomic_add_return_unchecked(1, v);
1101+}
1102 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1103 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1104
1105@@ -241,6 +428,14 @@ typedef struct {
1106 u64 __aligned(8) counter;
1107 } atomic64_t;
1108
1109+#ifdef CONFIG_PAX_REFCOUNT
1110+typedef struct {
1111+ u64 __aligned(8) counter;
1112+} atomic64_unchecked_t;
1113+#else
1114+typedef atomic64_t atomic64_unchecked_t;
1115+#endif
1116+
1117 #define ATOMIC64_INIT(i) { (i) }
1118
1119 static inline u64 atomic64_read(const atomic64_t *v)
1120@@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1121 return result;
1122 }
1123
1124+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1125+{
1126+ u64 result;
1127+
1128+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1129+" ldrexd %0, %H0, [%1]"
1130+ : "=&r" (result)
1131+ : "r" (&v->counter), "Qo" (v->counter)
1132+ );
1133+
1134+ return result;
1135+}
1136+
1137 static inline void atomic64_set(atomic64_t *v, u64 i)
1138 {
1139 u64 tmp;
1140@@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1141 : "cc");
1142 }
1143
1144+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1145+{
1146+ u64 tmp;
1147+
1148+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1149+"1: ldrexd %0, %H0, [%2]\n"
1150+" strexd %0, %3, %H3, [%2]\n"
1151+" teq %0, #0\n"
1152+" bne 1b"
1153+ : "=&r" (tmp), "=Qo" (v->counter)
1154+ : "r" (&v->counter), "r" (i)
1155+ : "cc");
1156+}
1157+
1158 static inline void atomic64_add(u64 i, atomic64_t *v)
1159 {
1160 u64 result;
1161@@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1162 __asm__ __volatile__("@ atomic64_add\n"
1163 "1: ldrexd %0, %H0, [%3]\n"
1164 " adds %0, %0, %4\n"
1165+" adcs %H0, %H0, %H4\n"
1166+
1167+#ifdef CONFIG_PAX_REFCOUNT
1168+" bvc 3f\n"
1169+"2: bkpt 0xf103\n"
1170+"3:\n"
1171+#endif
1172+
1173+" strexd %1, %0, %H0, [%3]\n"
1174+" teq %1, #0\n"
1175+" bne 1b"
1176+
1177+#ifdef CONFIG_PAX_REFCOUNT
1178+"\n4:\n"
1179+ _ASM_EXTABLE(2b, 4b)
1180+#endif
1181+
1182+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1183+ : "r" (&v->counter), "r" (i)
1184+ : "cc");
1185+}
1186+
1187+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1188+{
1189+ u64 result;
1190+ unsigned long tmp;
1191+
1192+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1193+"1: ldrexd %0, %H0, [%3]\n"
1194+" adds %0, %0, %4\n"
1195 " adc %H0, %H0, %H4\n"
1196 " strexd %1, %0, %H0, [%3]\n"
1197 " teq %1, #0\n"
1198@@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1199
1200 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1201 {
1202- u64 result;
1203- unsigned long tmp;
1204+ u64 result, tmp;
1205
1206 smp_mb();
1207
1208 __asm__ __volatile__("@ atomic64_add_return\n"
1209+"1: ldrexd %1, %H1, [%3]\n"
1210+" adds %0, %1, %4\n"
1211+" adcs %H0, %H1, %H4\n"
1212+
1213+#ifdef CONFIG_PAX_REFCOUNT
1214+" bvc 3f\n"
1215+" mov %0, %1\n"
1216+" mov %H0, %H1\n"
1217+"2: bkpt 0xf103\n"
1218+"3:\n"
1219+#endif
1220+
1221+" strexd %1, %0, %H0, [%3]\n"
1222+" teq %1, #0\n"
1223+" bne 1b"
1224+
1225+#ifdef CONFIG_PAX_REFCOUNT
1226+"\n4:\n"
1227+ _ASM_EXTABLE(2b, 4b)
1228+#endif
1229+
1230+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1231+ : "r" (&v->counter), "r" (i)
1232+ : "cc");
1233+
1234+ smp_mb();
1235+
1236+ return result;
1237+}
1238+
1239+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1240+{
1241+ u64 result;
1242+ unsigned long tmp;
1243+
1244+ smp_mb();
1245+
1246+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1247 "1: ldrexd %0, %H0, [%3]\n"
1248 " adds %0, %0, %4\n"
1249 " adc %H0, %H0, %H4\n"
1250@@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1251 __asm__ __volatile__("@ atomic64_sub\n"
1252 "1: ldrexd %0, %H0, [%3]\n"
1253 " subs %0, %0, %4\n"
1254+" sbcs %H0, %H0, %H4\n"
1255+
1256+#ifdef CONFIG_PAX_REFCOUNT
1257+" bvc 3f\n"
1258+"2: bkpt 0xf103\n"
1259+"3:\n"
1260+#endif
1261+
1262+" strexd %1, %0, %H0, [%3]\n"
1263+" teq %1, #0\n"
1264+" bne 1b"
1265+
1266+#ifdef CONFIG_PAX_REFCOUNT
1267+"\n4:\n"
1268+ _ASM_EXTABLE(2b, 4b)
1269+#endif
1270+
1271+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1272+ : "r" (&v->counter), "r" (i)
1273+ : "cc");
1274+}
1275+
1276+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1277+{
1278+ u64 result;
1279+ unsigned long tmp;
1280+
1281+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1282+"1: ldrexd %0, %H0, [%3]\n"
1283+" subs %0, %0, %4\n"
1284 " sbc %H0, %H0, %H4\n"
1285 " strexd %1, %0, %H0, [%3]\n"
1286 " teq %1, #0\n"
1287@@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1288
1289 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1290 {
1291- u64 result;
1292- unsigned long tmp;
1293+ u64 result, tmp;
1294
1295 smp_mb();
1296
1297 __asm__ __volatile__("@ atomic64_sub_return\n"
1298-"1: ldrexd %0, %H0, [%3]\n"
1299-" subs %0, %0, %4\n"
1300-" sbc %H0, %H0, %H4\n"
1301+"1: ldrexd %1, %H1, [%3]\n"
1302+" subs %0, %1, %4\n"
1303+" sbcs %H0, %H1, %H4\n"
1304+
1305+#ifdef CONFIG_PAX_REFCOUNT
1306+" bvc 3f\n"
1307+" mov %0, %1\n"
1308+" mov %H0, %H1\n"
1309+"2: bkpt 0xf103\n"
1310+"3:\n"
1311+#endif
1312+
1313 " strexd %1, %0, %H0, [%3]\n"
1314 " teq %1, #0\n"
1315 " bne 1b"
1316+
1317+#ifdef CONFIG_PAX_REFCOUNT
1318+"\n4:\n"
1319+ _ASM_EXTABLE(2b, 4b)
1320+#endif
1321+
1322 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1323 : "r" (&v->counter), "r" (i)
1324 : "cc");
1325@@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1326 return oldval;
1327 }
1328
1329+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1330+{
1331+ u64 oldval;
1332+ unsigned long res;
1333+
1334+ smp_mb();
1335+
1336+ do {
1337+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1338+ "ldrexd %1, %H1, [%3]\n"
1339+ "mov %0, #0\n"
1340+ "teq %1, %4\n"
1341+ "teqeq %H1, %H4\n"
1342+ "strexdeq %0, %5, %H5, [%3]"
1343+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1344+ : "r" (&ptr->counter), "r" (old), "r" (new)
1345+ : "cc");
1346+ } while (res);
1347+
1348+ smp_mb();
1349+
1350+ return oldval;
1351+}
1352+
1353 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1354 {
1355 u64 result;
1356@@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1357
1358 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1359 {
1360- u64 result;
1361- unsigned long tmp;
1362+ u64 result, tmp;
1363
1364 smp_mb();
1365
1366 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1367-"1: ldrexd %0, %H0, [%3]\n"
1368-" subs %0, %0, #1\n"
1369-" sbc %H0, %H0, #0\n"
1370+"1: ldrexd %1, %H1, [%3]\n"
1371+" subs %0, %1, #1\n"
1372+" sbcs %H0, %H1, #0\n"
1373+
1374+#ifdef CONFIG_PAX_REFCOUNT
1375+" bvc 3f\n"
1376+" mov %0, %1\n"
1377+" mov %H0, %H1\n"
1378+"2: bkpt 0xf103\n"
1379+"3:\n"
1380+#endif
1381+
1382 " teq %H0, #0\n"
1383-" bmi 2f\n"
1384+" bmi 4f\n"
1385 " strexd %1, %0, %H0, [%3]\n"
1386 " teq %1, #0\n"
1387 " bne 1b\n"
1388-"2:"
1389+"4:\n"
1390+
1391+#ifdef CONFIG_PAX_REFCOUNT
1392+ _ASM_EXTABLE(2b, 4b)
1393+#endif
1394+
1395 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1396 : "r" (&v->counter)
1397 : "cc");
1398@@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1399 " teq %0, %5\n"
1400 " teqeq %H0, %H5\n"
1401 " moveq %1, #0\n"
1402-" beq 2f\n"
1403+" beq 4f\n"
1404 " adds %0, %0, %6\n"
1405-" adc %H0, %H0, %H6\n"
1406+" adcs %H0, %H0, %H6\n"
1407+
1408+#ifdef CONFIG_PAX_REFCOUNT
1409+" bvc 3f\n"
1410+"2: bkpt 0xf103\n"
1411+"3:\n"
1412+#endif
1413+
1414 " strexd %2, %0, %H0, [%4]\n"
1415 " teq %2, #0\n"
1416 " bne 1b\n"
1417-"2:"
1418+"4:\n"
1419+
1420+#ifdef CONFIG_PAX_REFCOUNT
1421+ _ASM_EXTABLE(2b, 4b)
1422+#endif
1423+
1424 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1425 : "r" (&v->counter), "r" (u), "r" (a)
1426 : "cc");
1427@@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1428
1429 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1430 #define atomic64_inc(v) atomic64_add(1LL, (v))
1431+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1432 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1433+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1434 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1435 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1436 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1437+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1438 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1439 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1440 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1441diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1442index 75fe66b..ba3dee4 100644
1443--- a/arch/arm/include/asm/cache.h
1444+++ b/arch/arm/include/asm/cache.h
1445@@ -4,8 +4,10 @@
1446 #ifndef __ASMARM_CACHE_H
1447 #define __ASMARM_CACHE_H
1448
1449+#include <linux/const.h>
1450+
1451 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1452-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1453+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1454
1455 /*
1456 * Memory returned by kmalloc() may be used for DMA, so we must make
1457@@ -24,5 +26,6 @@
1458 #endif
1459
1460 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1461+#define __read_only __attribute__ ((__section__(".data..read_only")))
1462
1463 #endif
1464diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1465index e1489c5..d418304 100644
1466--- a/arch/arm/include/asm/cacheflush.h
1467+++ b/arch/arm/include/asm/cacheflush.h
1468@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1469 void (*dma_unmap_area)(const void *, size_t, int);
1470
1471 void (*dma_flush_range)(const void *, const void *);
1472-};
1473+} __no_const;
1474
1475 /*
1476 * Select the calling method
1477diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1478index 6dcc164..b14d917 100644
1479--- a/arch/arm/include/asm/checksum.h
1480+++ b/arch/arm/include/asm/checksum.h
1481@@ -37,7 +37,19 @@ __wsum
1482 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1483
1484 __wsum
1485-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1486+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1487+
1488+static inline __wsum
1489+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1490+{
1491+ __wsum ret;
1492+ pax_open_userland();
1493+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1494+ pax_close_userland();
1495+ return ret;
1496+}
1497+
1498+
1499
1500 /*
1501 * Fold a partial checksum without adding pseudo headers
1502diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1503index 7eb18c1..e38b6d2 100644
1504--- a/arch/arm/include/asm/cmpxchg.h
1505+++ b/arch/arm/include/asm/cmpxchg.h
1506@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1507
1508 #define xchg(ptr,x) \
1509 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1510+#define xchg_unchecked(ptr,x) \
1511+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1512
1513 #include <asm-generic/cmpxchg-local.h>
1514
1515diff --git a/arch/arm/include/asm/delay.h b/arch/arm/include/asm/delay.h
1516index ab98fdd..6b19938 100644
1517--- a/arch/arm/include/asm/delay.h
1518+++ b/arch/arm/include/asm/delay.h
1519@@ -24,9 +24,9 @@ extern struct arm_delay_ops {
1520 void (*delay)(unsigned long);
1521 void (*const_udelay)(unsigned long);
1522 void (*udelay)(unsigned long);
1523-} arm_delay_ops;
1524+} *arm_delay_ops;
1525
1526-#define __delay(n) arm_delay_ops.delay(n)
1527+#define __delay(n) arm_delay_ops->delay(n)
1528
1529 /*
1530 * This function intentionally does not exist; if you see references to
1531@@ -47,8 +47,8 @@ extern void __bad_udelay(void);
1532 * first constant multiplications gets optimized away if the delay is
1533 * a constant)
1534 */
1535-#define __udelay(n) arm_delay_ops.udelay(n)
1536-#define __const_udelay(n) arm_delay_ops.const_udelay(n)
1537+#define __udelay(n) arm_delay_ops->udelay(n)
1538+#define __const_udelay(n) arm_delay_ops->const_udelay(n)
1539
1540 #define udelay(n) \
1541 (__builtin_constant_p(n) ? \
1542diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1543index 6ddbe44..758b5f2 100644
1544--- a/arch/arm/include/asm/domain.h
1545+++ b/arch/arm/include/asm/domain.h
1546@@ -48,18 +48,37 @@
1547 * Domain types
1548 */
1549 #define DOMAIN_NOACCESS 0
1550-#define DOMAIN_CLIENT 1
1551 #ifdef CONFIG_CPU_USE_DOMAINS
1552+#define DOMAIN_USERCLIENT 1
1553+#define DOMAIN_KERNELCLIENT 1
1554 #define DOMAIN_MANAGER 3
1555+#define DOMAIN_VECTORS DOMAIN_USER
1556 #else
1557+
1558+#ifdef CONFIG_PAX_KERNEXEC
1559 #define DOMAIN_MANAGER 1
1560+#define DOMAIN_KERNEXEC 3
1561+#else
1562+#define DOMAIN_MANAGER 1
1563+#endif
1564+
1565+#ifdef CONFIG_PAX_MEMORY_UDEREF
1566+#define DOMAIN_USERCLIENT 0
1567+#define DOMAIN_UDEREF 1
1568+#define DOMAIN_VECTORS DOMAIN_KERNEL
1569+#else
1570+#define DOMAIN_USERCLIENT 1
1571+#define DOMAIN_VECTORS DOMAIN_USER
1572+#endif
1573+#define DOMAIN_KERNELCLIENT 1
1574+
1575 #endif
1576
1577 #define domain_val(dom,type) ((type) << (2*(dom)))
1578
1579 #ifndef __ASSEMBLY__
1580
1581-#ifdef CONFIG_CPU_USE_DOMAINS
1582+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1583 static inline void set_domain(unsigned val)
1584 {
1585 asm volatile(
1586@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1587 isb();
1588 }
1589
1590-#define modify_domain(dom,type) \
1591- do { \
1592- struct thread_info *thread = current_thread_info(); \
1593- unsigned int domain = thread->cpu_domain; \
1594- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1595- thread->cpu_domain = domain | domain_val(dom, type); \
1596- set_domain(thread->cpu_domain); \
1597- } while (0)
1598-
1599+extern void modify_domain(unsigned int dom, unsigned int type);
1600 #else
1601 static inline void set_domain(unsigned val) { }
1602 static inline void modify_domain(unsigned dom, unsigned type) { }
1603diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1604index 38050b1..9d90e8b 100644
1605--- a/arch/arm/include/asm/elf.h
1606+++ b/arch/arm/include/asm/elf.h
1607@@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1608 the loader. We need to make sure that it is out of the way of the program
1609 that it will "exec", and that there is sufficient room for the brk. */
1610
1611-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1612+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1613+
1614+#ifdef CONFIG_PAX_ASLR
1615+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1616+
1617+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1618+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1619+#endif
1620
1621 /* When the program starts, a1 contains a pointer to a function to be
1622 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1623@@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1624 extern void elf_set_personality(const struct elf32_hdr *);
1625 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1626
1627-struct mm_struct;
1628-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1629-#define arch_randomize_brk arch_randomize_brk
1630-
1631 #endif
1632diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1633index de53547..52b9a28 100644
1634--- a/arch/arm/include/asm/fncpy.h
1635+++ b/arch/arm/include/asm/fncpy.h
1636@@ -81,7 +81,9 @@
1637 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1638 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1639 \
1640+ pax_open_kernel(); \
1641 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1642+ pax_close_kernel(); \
1643 flush_icache_range((unsigned long)(dest_buf), \
1644 (unsigned long)(dest_buf) + (size)); \
1645 \
1646diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1647index e42cf59..7b94b8f 100644
1648--- a/arch/arm/include/asm/futex.h
1649+++ b/arch/arm/include/asm/futex.h
1650@@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1651 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1652 return -EFAULT;
1653
1654+ pax_open_userland();
1655+
1656 smp_mb();
1657 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1658 "1: ldrex %1, [%4]\n"
1659@@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1660 : "cc", "memory");
1661 smp_mb();
1662
1663+ pax_close_userland();
1664+
1665 *uval = val;
1666 return ret;
1667 }
1668@@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1669 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1670 return -EFAULT;
1671
1672+ pax_open_userland();
1673+
1674 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1675 "1: " TUSER(ldr) " %1, [%4]\n"
1676 " teq %1, %2\n"
1677@@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1678 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1679 : "cc", "memory");
1680
1681+ pax_close_userland();
1682+
1683 *uval = val;
1684 return ret;
1685 }
1686@@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1687 return -EFAULT;
1688
1689 pagefault_disable(); /* implies preempt_disable() */
1690+ pax_open_userland();
1691
1692 switch (op) {
1693 case FUTEX_OP_SET:
1694@@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1695 ret = -ENOSYS;
1696 }
1697
1698+ pax_close_userland();
1699 pagefault_enable(); /* subsumes preempt_enable() */
1700
1701 if (!ret) {
1702diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1703index 83eb2f7..ed77159 100644
1704--- a/arch/arm/include/asm/kmap_types.h
1705+++ b/arch/arm/include/asm/kmap_types.h
1706@@ -4,6 +4,6 @@
1707 /*
1708 * This is the "bare minimum". AIO seems to require this.
1709 */
1710-#define KM_TYPE_NR 16
1711+#define KM_TYPE_NR 17
1712
1713 #endif
1714diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1715index 9e614a1..3302cca 100644
1716--- a/arch/arm/include/asm/mach/dma.h
1717+++ b/arch/arm/include/asm/mach/dma.h
1718@@ -22,7 +22,7 @@ struct dma_ops {
1719 int (*residue)(unsigned int, dma_t *); /* optional */
1720 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1721 const char *type;
1722-};
1723+} __do_const;
1724
1725 struct dma_struct {
1726 void *addr; /* single DMA address */
1727diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1728index 2fe141f..192dc01 100644
1729--- a/arch/arm/include/asm/mach/map.h
1730+++ b/arch/arm/include/asm/mach/map.h
1731@@ -27,13 +27,16 @@ struct map_desc {
1732 #define MT_MINICLEAN 6
1733 #define MT_LOW_VECTORS 7
1734 #define MT_HIGH_VECTORS 8
1735-#define MT_MEMORY 9
1736+#define MT_MEMORY_RWX 9
1737 #define MT_ROM 10
1738-#define MT_MEMORY_NONCACHED 11
1739+#define MT_MEMORY_NONCACHED_RX 11
1740 #define MT_MEMORY_DTCM 12
1741 #define MT_MEMORY_ITCM 13
1742 #define MT_MEMORY_SO 14
1743 #define MT_MEMORY_DMA_READY 15
1744+#define MT_MEMORY_RW 16
1745+#define MT_MEMORY_RX 17
1746+#define MT_MEMORY_NONCACHED_RW 18
1747
1748 #ifdef CONFIG_MMU
1749 extern void iotable_init(struct map_desc *, int);
1750diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1751index 53426c6..c7baff3 100644
1752--- a/arch/arm/include/asm/outercache.h
1753+++ b/arch/arm/include/asm/outercache.h
1754@@ -35,7 +35,7 @@ struct outer_cache_fns {
1755 #endif
1756 void (*set_debug)(unsigned long);
1757 void (*resume)(void);
1758-};
1759+} __no_const;
1760
1761 #ifdef CONFIG_OUTER_CACHE
1762
1763diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1764index 812a494..71fc0b6 100644
1765--- a/arch/arm/include/asm/page.h
1766+++ b/arch/arm/include/asm/page.h
1767@@ -114,7 +114,7 @@ struct cpu_user_fns {
1768 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1769 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1770 unsigned long vaddr, struct vm_area_struct *vma);
1771-};
1772+} __no_const;
1773
1774 #ifdef MULTI_USER
1775 extern struct cpu_user_fns cpu_user;
1776diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1777index 943504f..c37a730 100644
1778--- a/arch/arm/include/asm/pgalloc.h
1779+++ b/arch/arm/include/asm/pgalloc.h
1780@@ -17,6 +17,7 @@
1781 #include <asm/processor.h>
1782 #include <asm/cacheflush.h>
1783 #include <asm/tlbflush.h>
1784+#include <asm/system_info.h>
1785
1786 #define check_pgt_cache() do { } while (0)
1787
1788@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1789 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1790 }
1791
1792+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1793+{
1794+ pud_populate(mm, pud, pmd);
1795+}
1796+
1797 #else /* !CONFIG_ARM_LPAE */
1798
1799 /*
1800@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1801 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1802 #define pmd_free(mm, pmd) do { } while (0)
1803 #define pud_populate(mm,pmd,pte) BUG()
1804+#define pud_populate_kernel(mm,pmd,pte) BUG()
1805
1806 #endif /* CONFIG_ARM_LPAE */
1807
1808@@ -126,6 +133,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1809 __free_page(pte);
1810 }
1811
1812+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1813+{
1814+#ifdef CONFIG_ARM_LPAE
1815+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1816+#else
1817+ if (addr & SECTION_SIZE)
1818+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1819+ else
1820+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1821+#endif
1822+ flush_pmd_entry(pmdp);
1823+}
1824+
1825 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1826 pmdval_t prot)
1827 {
1828@@ -155,7 +175,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1829 static inline void
1830 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1831 {
1832- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1833+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1834 }
1835 #define pmd_pgtable(pmd) pmd_page(pmd)
1836
1837diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1838index 5cfba15..f415e1a 100644
1839--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1840+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1841@@ -20,12 +20,15 @@
1842 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1843 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1844 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1845+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1846 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1847 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1848 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1849+
1850 /*
1851 * - section
1852 */
1853+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1854 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1855 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1856 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1857@@ -37,6 +40,7 @@
1858 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1859 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1860 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1861+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1862
1863 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1864 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1865@@ -66,6 +70,7 @@
1866 * - extended small page/tiny page
1867 */
1868 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1869+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1870 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1871 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1872 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1873diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1874index f97ee02..07f1be5 100644
1875--- a/arch/arm/include/asm/pgtable-2level.h
1876+++ b/arch/arm/include/asm/pgtable-2level.h
1877@@ -125,6 +125,7 @@
1878 #define L_PTE_XN (_AT(pteval_t, 1) << 9)
1879 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1880 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1881+#define L_PTE_PXN (_AT(pteval_t, 1) << 12) /* v7*/
1882
1883 /*
1884 * These are the memory types, defined to be compatible with
1885diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1886index d795282..a43ea90 100644
1887--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1888+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1889@@ -32,15 +32,18 @@
1890 #define PMD_TYPE_SECT (_AT(pmdval_t, 1) << 0)
1891 #define PMD_BIT4 (_AT(pmdval_t, 0))
1892 #define PMD_DOMAIN(x) (_AT(pmdval_t, 0))
1893+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 59) /* PXNTable */
1894
1895 /*
1896 * - section
1897 */
1898 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1899 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1900+#define PMD_SECT_RDONLY (_AT(pmdval_t, 1) << 7)
1901 #define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
1902 #define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
1903 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 11)
1904+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 53)
1905 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 54)
1906 #define PMD_SECT_AP_WRITE (_AT(pmdval_t, 0))
1907 #define PMD_SECT_AP_READ (_AT(pmdval_t, 0))
1908@@ -66,6 +69,7 @@
1909 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1910 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1911 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1912+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1913 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1914
1915 /*
1916diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1917index a3f3792..7b932a6 100644
1918--- a/arch/arm/include/asm/pgtable-3level.h
1919+++ b/arch/arm/include/asm/pgtable-3level.h
1920@@ -74,6 +74,7 @@
1921 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1922 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1923 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1924+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1925 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1926 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1927 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1928@@ -82,6 +83,7 @@
1929 /*
1930 * To be used in assembly code with the upper page attributes.
1931 */
1932+#define L_PTE_PXN_HIGH (1 << (53 - 32))
1933 #define L_PTE_XN_HIGH (1 << (54 - 32))
1934 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1935
1936diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1937index 9c82f988..514705a 100644
1938--- a/arch/arm/include/asm/pgtable.h
1939+++ b/arch/arm/include/asm/pgtable.h
1940@@ -30,6 +30,9 @@
1941 #include <asm/pgtable-2level.h>
1942 #endif
1943
1944+#define ktla_ktva(addr) (addr)
1945+#define ktva_ktla(addr) (addr)
1946+
1947 /*
1948 * Just any arbitrary offset to the start of the vmalloc VM area: the
1949 * current 8MB value just means that there will be a 8MB "hole" after the
1950@@ -45,6 +48,9 @@
1951 #define LIBRARY_TEXT_START 0x0c000000
1952
1953 #ifndef __ASSEMBLY__
1954+extern pteval_t __supported_pte_mask;
1955+extern pmdval_t __supported_pmd_mask;
1956+
1957 extern void __pte_error(const char *file, int line, pte_t);
1958 extern void __pmd_error(const char *file, int line, pmd_t);
1959 extern void __pgd_error(const char *file, int line, pgd_t);
1960@@ -53,6 +59,50 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1961 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1962 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1963
1964+#define __HAVE_ARCH_PAX_OPEN_KERNEL
1965+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
1966+
1967+#ifdef CONFIG_PAX_KERNEXEC
1968+#include <asm/domain.h>
1969+#include <linux/thread_info.h>
1970+#include <linux/preempt.h>
1971+#endif
1972+
1973+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1974+static inline int test_domain(int domain, int domaintype)
1975+{
1976+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
1977+}
1978+#endif
1979+
1980+#ifdef CONFIG_PAX_KERNEXEC
1981+static inline unsigned long pax_open_kernel(void) {
1982+#ifdef CONFIG_ARM_LPAE
1983+ /* TODO */
1984+#else
1985+ preempt_disable();
1986+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
1987+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
1988+#endif
1989+ return 0;
1990+}
1991+
1992+static inline unsigned long pax_close_kernel(void) {
1993+#ifdef CONFIG_ARM_LPAE
1994+ /* TODO */
1995+#else
1996+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
1997+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
1998+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
1999+ preempt_enable_no_resched();
2000+#endif
2001+ return 0;
2002+}
2003+#else
2004+static inline unsigned long pax_open_kernel(void) { return 0; }
2005+static inline unsigned long pax_close_kernel(void) { return 0; }
2006+#endif
2007+
2008 /*
2009 * This is the lowest virtual address we can permit any user space
2010 * mapping to be mapped at. This is particularly important for
2011@@ -63,8 +113,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2012 /*
2013 * The pgprot_* and protection_map entries will be fixed up in runtime
2014 * to include the cachable and bufferable bits based on memory policy,
2015- * as well as any architecture dependent bits like global/ASID and SMP
2016- * shared mapping bits.
2017+ * as well as any architecture dependent bits like global/ASID, PXN,
2018+ * and SMP shared mapping bits.
2019 */
2020 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2021
2022@@ -240,7 +290,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2023
2024 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2025 {
2026- const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER | L_PTE_NONE;
2027+ const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER | L_PTE_NONE | __supported_pte_mask;
2028 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2029 return pte;
2030 }
2031diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2032index f3628fb..a0672dd 100644
2033--- a/arch/arm/include/asm/proc-fns.h
2034+++ b/arch/arm/include/asm/proc-fns.h
2035@@ -75,7 +75,7 @@ extern struct processor {
2036 unsigned int suspend_size;
2037 void (*do_suspend)(void *);
2038 void (*do_resume)(void *);
2039-} processor;
2040+} __do_const processor;
2041
2042 #ifndef MULTI_CPU
2043 extern void cpu_proc_init(void);
2044diff --git a/arch/arm/include/asm/processor.h b/arch/arm/include/asm/processor.h
2045index 06e7d50..8a8e251 100644
2046--- a/arch/arm/include/asm/processor.h
2047+++ b/arch/arm/include/asm/processor.h
2048@@ -65,9 +65,8 @@ struct thread_struct {
2049 regs->ARM_cpsr |= PSR_ENDSTATE; \
2050 regs->ARM_pc = pc & ~1; /* pc */ \
2051 regs->ARM_sp = sp; /* sp */ \
2052- regs->ARM_r2 = stack[2]; /* r2 (envp) */ \
2053- regs->ARM_r1 = stack[1]; /* r1 (argv) */ \
2054- regs->ARM_r0 = stack[0]; /* r0 (argc) */ \
2055+ /* r2 (envp), r1 (argv), r0 (argc) */ \
2056+ (void)copy_from_user(&regs->ARM_r0, (const char __user *)stack, 3 * sizeof(unsigned long)); \
2057 nommu_start_thread(regs); \
2058 })
2059
2060diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2061index d3a22be..3a69ad5 100644
2062--- a/arch/arm/include/asm/smp.h
2063+++ b/arch/arm/include/asm/smp.h
2064@@ -107,7 +107,7 @@ struct smp_operations {
2065 int (*cpu_disable)(unsigned int cpu);
2066 #endif
2067 #endif
2068-};
2069+} __no_const;
2070
2071 /*
2072 * set platform specific SMP operations
2073diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2074index cddda1f..ff357f7 100644
2075--- a/arch/arm/include/asm/thread_info.h
2076+++ b/arch/arm/include/asm/thread_info.h
2077@@ -77,9 +77,9 @@ struct thread_info {
2078 .flags = 0, \
2079 .preempt_count = INIT_PREEMPT_COUNT, \
2080 .addr_limit = KERNEL_DS, \
2081- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2082- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2083- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2084+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2085+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2086+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2087 .restart_block = { \
2088 .fn = do_no_restart_syscall, \
2089 }, \
2090@@ -152,6 +152,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2091 #define TIF_SYSCALL_AUDIT 9
2092 #define TIF_SYSCALL_TRACEPOINT 10
2093 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2094+
2095+/* within 8 bits of TIF_SYSCALL_TRACE
2096+ * to meet flexible second operand requirements
2097+ */
2098+#define TIF_GRSEC_SETXID 12
2099+
2100 #define TIF_USING_IWMMXT 17
2101 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2102 #define TIF_RESTORE_SIGMASK 20
2103@@ -165,10 +171,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2104 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2105 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2106 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2107+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2108
2109 /* Checks for any syscall work in entry-common.S */
2110 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2111- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2112+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2113
2114 /*
2115 * Change these and you break ASM code in entry-common.S
2116diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2117index 7e1f760..752fcb7 100644
2118--- a/arch/arm/include/asm/uaccess.h
2119+++ b/arch/arm/include/asm/uaccess.h
2120@@ -18,6 +18,7 @@
2121 #include <asm/domain.h>
2122 #include <asm/unified.h>
2123 #include <asm/compiler.h>
2124+#include <asm/pgtable.h>
2125
2126 #define VERIFY_READ 0
2127 #define VERIFY_WRITE 1
2128@@ -60,10 +61,34 @@ extern int __put_user_bad(void);
2129 #define USER_DS TASK_SIZE
2130 #define get_fs() (current_thread_info()->addr_limit)
2131
2132+static inline void pax_open_userland(void)
2133+{
2134+
2135+#ifdef CONFIG_PAX_MEMORY_UDEREF
2136+ if (get_fs() == USER_DS) {
2137+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2138+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2139+ }
2140+#endif
2141+
2142+}
2143+
2144+static inline void pax_close_userland(void)
2145+{
2146+
2147+#ifdef CONFIG_PAX_MEMORY_UDEREF
2148+ if (get_fs() == USER_DS) {
2149+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2150+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2151+ }
2152+#endif
2153+
2154+}
2155+
2156 static inline void set_fs(mm_segment_t fs)
2157 {
2158 current_thread_info()->addr_limit = fs;
2159- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2160+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2161 }
2162
2163 #define segment_eq(a,b) ((a) == (b))
2164@@ -143,8 +168,12 @@ extern int __get_user_4(void *);
2165
2166 #define get_user(x,p) \
2167 ({ \
2168+ int __e; \
2169 might_fault(); \
2170- __get_user_check(x,p); \
2171+ pax_open_userland(); \
2172+ __e = __get_user_check(x,p); \
2173+ pax_close_userland(); \
2174+ __e; \
2175 })
2176
2177 extern int __put_user_1(void *, unsigned int);
2178@@ -188,8 +217,12 @@ extern int __put_user_8(void *, unsigned long long);
2179
2180 #define put_user(x,p) \
2181 ({ \
2182+ int __e; \
2183 might_fault(); \
2184- __put_user_check(x,p); \
2185+ pax_open_userland(); \
2186+ __e = __put_user_check(x,p); \
2187+ pax_close_userland(); \
2188+ __e; \
2189 })
2190
2191 #else /* CONFIG_MMU */
2192@@ -230,13 +263,17 @@ static inline void set_fs(mm_segment_t fs)
2193 #define __get_user(x,ptr) \
2194 ({ \
2195 long __gu_err = 0; \
2196+ pax_open_userland(); \
2197 __get_user_err((x),(ptr),__gu_err); \
2198+ pax_close_userland(); \
2199 __gu_err; \
2200 })
2201
2202 #define __get_user_error(x,ptr,err) \
2203 ({ \
2204+ pax_open_userland(); \
2205 __get_user_err((x),(ptr),err); \
2206+ pax_close_userland(); \
2207 (void) 0; \
2208 })
2209
2210@@ -312,13 +349,17 @@ do { \
2211 #define __put_user(x,ptr) \
2212 ({ \
2213 long __pu_err = 0; \
2214+ pax_open_userland(); \
2215 __put_user_err((x),(ptr),__pu_err); \
2216+ pax_close_userland(); \
2217 __pu_err; \
2218 })
2219
2220 #define __put_user_error(x,ptr,err) \
2221 ({ \
2222+ pax_open_userland(); \
2223 __put_user_err((x),(ptr),err); \
2224+ pax_close_userland(); \
2225 (void) 0; \
2226 })
2227
2228@@ -418,11 +459,44 @@ do { \
2229
2230
2231 #ifdef CONFIG_MMU
2232-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2233-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2234+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2235+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2236+
2237+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2238+{
2239+ unsigned long ret;
2240+
2241+ check_object_size(to, n, false);
2242+ pax_open_userland();
2243+ ret = ___copy_from_user(to, from, n);
2244+ pax_close_userland();
2245+ return ret;
2246+}
2247+
2248+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2249+{
2250+ unsigned long ret;
2251+
2252+ check_object_size(from, n, true);
2253+ pax_open_userland();
2254+ ret = ___copy_to_user(to, from, n);
2255+ pax_close_userland();
2256+ return ret;
2257+}
2258+
2259 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2260-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2261+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2262 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2263+
2264+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2265+{
2266+ unsigned long ret;
2267+ pax_open_userland();
2268+ ret = ___clear_user(addr, n);
2269+ pax_close_userland();
2270+ return ret;
2271+}
2272+
2273 #else
2274 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2275 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2276@@ -431,6 +505,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2277
2278 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2279 {
2280+ if ((long)n < 0)
2281+ return n;
2282+
2283 if (access_ok(VERIFY_READ, from, n))
2284 n = __copy_from_user(to, from, n);
2285 else /* security hole - plug it */
2286@@ -440,6 +517,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2287
2288 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2289 {
2290+ if ((long)n < 0)
2291+ return n;
2292+
2293 if (access_ok(VERIFY_WRITE, to, n))
2294 n = __copy_to_user(to, from, n);
2295 return n;
2296diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2297index 96ee092..37f1844 100644
2298--- a/arch/arm/include/uapi/asm/ptrace.h
2299+++ b/arch/arm/include/uapi/asm/ptrace.h
2300@@ -73,7 +73,7 @@
2301 * ARMv7 groups of PSR bits
2302 */
2303 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2304-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2305+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2306 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2307 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2308
2309diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2310index 60d3b73..9168db0 100644
2311--- a/arch/arm/kernel/armksyms.c
2312+++ b/arch/arm/kernel/armksyms.c
2313@@ -89,8 +89,8 @@ EXPORT_SYMBOL(__memzero);
2314 #ifdef CONFIG_MMU
2315 EXPORT_SYMBOL(copy_page);
2316
2317-EXPORT_SYMBOL(__copy_from_user);
2318-EXPORT_SYMBOL(__copy_to_user);
2319+EXPORT_SYMBOL(___copy_from_user);
2320+EXPORT_SYMBOL(___copy_to_user);
2321 EXPORT_SYMBOL(__clear_user);
2322
2323 EXPORT_SYMBOL(__get_user_1);
2324diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2325index 0f82098..3dbd3ee 100644
2326--- a/arch/arm/kernel/entry-armv.S
2327+++ b/arch/arm/kernel/entry-armv.S
2328@@ -47,6 +47,87 @@
2329 9997:
2330 .endm
2331
2332+ .macro pax_enter_kernel
2333+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2334+ @ make aligned space for saved DACR
2335+ sub sp, sp, #8
2336+ @ save regs
2337+ stmdb sp!, {r1, r2}
2338+ @ read DACR from cpu_domain into r1
2339+ mov r2, sp
2340+ @ assume 8K pages, since we have to split the immediate in two
2341+ bic r2, r2, #(0x1fc0)
2342+ bic r2, r2, #(0x3f)
2343+ ldr r1, [r2, #TI_CPU_DOMAIN]
2344+ @ store old DACR on stack
2345+ str r1, [sp, #8]
2346+#ifdef CONFIG_PAX_KERNEXEC
2347+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2348+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2349+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2350+#endif
2351+#ifdef CONFIG_PAX_MEMORY_UDEREF
2352+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2353+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2354+#endif
2355+ @ write r1 to current_thread_info()->cpu_domain
2356+ str r1, [r2, #TI_CPU_DOMAIN]
2357+ @ write r1 to DACR
2358+ mcr p15, 0, r1, c3, c0, 0
2359+ @ instruction sync
2360+ instr_sync
2361+ @ restore regs
2362+ ldmia sp!, {r1, r2}
2363+#endif
2364+ .endm
2365+
2366+ .macro pax_open_userland
2367+#ifdef CONFIG_PAX_MEMORY_UDEREF
2368+ @ save regs
2369+ stmdb sp!, {r0, r1}
2370+ @ read DACR from cpu_domain into r1
2371+ mov r0, sp
2372+ @ assume 8K pages, since we have to split the immediate in two
2373+ bic r0, r0, #(0x1fc0)
2374+ bic r0, r0, #(0x3f)
2375+ ldr r1, [r0, #TI_CPU_DOMAIN]
2376+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2377+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2378+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2379+ @ write r1 to current_thread_info()->cpu_domain
2380+ str r1, [r0, #TI_CPU_DOMAIN]
2381+ @ write r1 to DACR
2382+ mcr p15, 0, r1, c3, c0, 0
2383+ @ instruction sync
2384+ instr_sync
2385+ @ restore regs
2386+ ldmia sp!, {r0, r1}
2387+#endif
2388+ .endm
2389+
2390+ .macro pax_close_userland
2391+#ifdef CONFIG_PAX_MEMORY_UDEREF
2392+ @ save regs
2393+ stmdb sp!, {r0, r1}
2394+ @ read DACR from cpu_domain into r1
2395+ mov r0, sp
2396+ @ assume 8K pages, since we have to split the immediate in two
2397+ bic r0, r0, #(0x1fc0)
2398+ bic r0, r0, #(0x3f)
2399+ ldr r1, [r0, #TI_CPU_DOMAIN]
2400+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2401+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2402+ @ write r1 to current_thread_info()->cpu_domain
2403+ str r1, [r0, #TI_CPU_DOMAIN]
2404+ @ write r1 to DACR
2405+ mcr p15, 0, r1, c3, c0, 0
2406+ @ instruction sync
2407+ instr_sync
2408+ @ restore regs
2409+ ldmia sp!, {r0, r1}
2410+#endif
2411+ .endm
2412+
2413 .macro pabt_helper
2414 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2415 #ifdef MULTI_PABORT
2416@@ -89,11 +170,15 @@
2417 * Invalid mode handlers
2418 */
2419 .macro inv_entry, reason
2420+
2421+ pax_enter_kernel
2422+
2423 sub sp, sp, #S_FRAME_SIZE
2424 ARM( stmib sp, {r1 - lr} )
2425 THUMB( stmia sp, {r0 - r12} )
2426 THUMB( str sp, [sp, #S_SP] )
2427 THUMB( str lr, [sp, #S_LR] )
2428+
2429 mov r1, #\reason
2430 .endm
2431
2432@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2433 .macro svc_entry, stack_hole=0
2434 UNWIND(.fnstart )
2435 UNWIND(.save {r0 - pc} )
2436+
2437+ pax_enter_kernel
2438+
2439 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2440+
2441 #ifdef CONFIG_THUMB2_KERNEL
2442 SPFIX( str r0, [sp] ) @ temporarily saved
2443 SPFIX( mov r0, sp )
2444@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2445 ldmia r0, {r3 - r5}
2446 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2447 mov r6, #-1 @ "" "" "" ""
2448+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2449+ @ offset sp by 8 as done in pax_enter_kernel
2450+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2451+#else
2452 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2453+#endif
2454 SPFIX( addeq r2, r2, #4 )
2455 str r3, [sp, #-4]! @ save the "real" r0 copied
2456 @ from the exception stack
2457@@ -359,6 +453,9 @@ ENDPROC(__pabt_svc)
2458 .macro usr_entry
2459 UNWIND(.fnstart )
2460 UNWIND(.cantunwind ) @ don't unwind the user space
2461+
2462+ pax_enter_kernel_user
2463+
2464 sub sp, sp, #S_FRAME_SIZE
2465 ARM( stmib sp, {r1 - r12} )
2466 THUMB( stmia sp, {r0 - r12} )
2467@@ -456,7 +553,9 @@ __und_usr:
2468 tst r3, #PSR_T_BIT @ Thumb mode?
2469 bne __und_usr_thumb
2470 sub r4, r2, #4 @ ARM instr at LR - 4
2471+ pax_open_userland
2472 1: ldrt r0, [r4]
2473+ pax_close_userland
2474 #ifdef CONFIG_CPU_ENDIAN_BE8
2475 rev r0, r0 @ little endian instruction
2476 #endif
2477@@ -491,10 +590,14 @@ __und_usr_thumb:
2478 */
2479 .arch armv6t2
2480 #endif
2481+ pax_open_userland
2482 2: ldrht r5, [r4]
2483+ pax_close_userland
2484 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2485 blo __und_usr_fault_16 @ 16bit undefined instruction
2486+ pax_open_userland
2487 3: ldrht r0, [r2]
2488+ pax_close_userland
2489 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2490 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2491 orr r0, r0, r5, lsl #16
2492@@ -733,7 +836,7 @@ ENTRY(__switch_to)
2493 THUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stack
2494 THUMB( str sp, [ip], #4 )
2495 THUMB( str lr, [ip], #4 )
2496-#ifdef CONFIG_CPU_USE_DOMAINS
2497+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC)
2498 ldr r6, [r2, #TI_CPU_DOMAIN]
2499 #endif
2500 set_tls r3, r4, r5
2501@@ -742,7 +845,7 @@ ENTRY(__switch_to)
2502 ldr r8, =__stack_chk_guard
2503 ldr r7, [r7, #TSK_STACK_CANARY]
2504 #endif
2505-#ifdef CONFIG_CPU_USE_DOMAINS
2506+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC)
2507 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2508 #endif
2509 mov r5, r0
2510diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2511index a6c301e..908821b 100644
2512--- a/arch/arm/kernel/entry-common.S
2513+++ b/arch/arm/kernel/entry-common.S
2514@@ -10,18 +10,46 @@
2515
2516 #include <asm/unistd.h>
2517 #include <asm/ftrace.h>
2518+#include <asm/domain.h>
2519 #include <asm/unwind.h>
2520
2521+#include "entry-header.S"
2522+
2523 #ifdef CONFIG_NEED_RET_TO_USER
2524 #include <mach/entry-macro.S>
2525 #else
2526 .macro arch_ret_to_user, tmp1, tmp2
2527+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2528+ @ save regs
2529+ stmdb sp!, {r1, r2}
2530+ @ read DACR from cpu_domain into r1
2531+ mov r2, sp
2532+ @ assume 8K pages, since we have to split the immediate in two
2533+ bic r2, r2, #(0x1fc0)
2534+ bic r2, r2, #(0x3f)
2535+ ldr r1, [r2, #TI_CPU_DOMAIN]
2536+#ifdef CONFIG_PAX_KERNEXEC
2537+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2538+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2539+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2540+#endif
2541+#ifdef CONFIG_PAX_MEMORY_UDEREF
2542+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2543+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2544+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2545+#endif
2546+ @ write r1 to current_thread_info()->cpu_domain
2547+ str r1, [r2, #TI_CPU_DOMAIN]
2548+ @ write r1 to DACR
2549+ mcr p15, 0, r1, c3, c0, 0
2550+ @ instruction sync
2551+ instr_sync
2552+ @ restore regs
2553+ ldmia sp!, {r1, r2}
2554+#endif
2555 .endm
2556 #endif
2557
2558-#include "entry-header.S"
2559-
2560-
2561 .align 5
2562 /*
2563 * This is the fast syscall return path. We do as little as
2564@@ -339,6 +367,7 @@ ENDPROC(ftrace_stub)
2565
2566 .align 5
2567 ENTRY(vector_swi)
2568+
2569 sub sp, sp, #S_FRAME_SIZE
2570 stmia sp, {r0 - r12} @ Calling r0 - r12
2571 ARM( add r8, sp, #S_PC )
2572@@ -388,6 +417,12 @@ ENTRY(vector_swi)
2573 ldr scno, [lr, #-4] @ get SWI instruction
2574 #endif
2575
2576+ /*
2577+ * do this here to avoid a performance hit of wrapping the code above
2578+ * that directly dereferences userland to parse the SWI instruction
2579+ */
2580+ pax_enter_kernel_user
2581+
2582 #ifdef CONFIG_ALIGNMENT_TRAP
2583 ldr ip, __cr_alignment
2584 ldr ip, [ip]
2585diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2586index 9a8531e..812e287 100644
2587--- a/arch/arm/kernel/entry-header.S
2588+++ b/arch/arm/kernel/entry-header.S
2589@@ -73,9 +73,66 @@
2590 msr cpsr_c, \rtemp @ switch back to the SVC mode
2591 .endm
2592
2593+ .macro pax_enter_kernel_user
2594+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2595+ @ save regs
2596+ stmdb sp!, {r0, r1}
2597+ @ read DACR from cpu_domain into r1
2598+ mov r0, sp
2599+ @ assume 8K pages, since we have to split the immediate in two
2600+ bic r0, r0, #(0x1fc0)
2601+ bic r0, r0, #(0x3f)
2602+ ldr r1, [r0, #TI_CPU_DOMAIN]
2603+#ifdef CONFIG_PAX_MEMORY_UDEREF
2604+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2605+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2606+#endif
2607+#ifdef CONFIG_PAX_KERNEXEC
2608+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2609+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2610+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2611+#endif
2612+ @ write r1 to current_thread_info()->cpu_domain
2613+ str r1, [r0, #TI_CPU_DOMAIN]
2614+ @ write r1 to DACR
2615+ mcr p15, 0, r1, c3, c0, 0
2616+ @ instruction sync
2617+ instr_sync
2618+ @ restore regs
2619+ ldmia sp!, {r0, r1}
2620+#endif
2621+ .endm
2622+
2623+ .macro pax_exit_kernel
2624+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2625+ @ save regs
2626+ stmdb sp!, {r0, r1}
2627+ @ read old DACR from stack into r1
2628+ ldr r1, [sp, #(8 + S_SP)]
2629+ sub r1, r1, #8
2630+ ldr r1, [r1]
2631+
2632+ @ write r1 to current_thread_info()->cpu_domain
2633+ mov r0, sp
2634+ @ assume 8K pages, since we have to split the immediate in two
2635+ bic r0, r0, #(0x1fc0)
2636+ bic r0, r0, #(0x3f)
2637+ str r1, [r0, #TI_CPU_DOMAIN]
2638+ @ write r1 to DACR
2639+ mcr p15, 0, r1, c3, c0, 0
2640+ @ instruction sync
2641+ instr_sync
2642+ @ restore regs
2643+ ldmia sp!, {r0, r1}
2644+#endif
2645+ .endm
2646+
2647 #ifndef CONFIG_THUMB2_KERNEL
2648 .macro svc_exit, rpsr
2649 msr spsr_cxsf, \rpsr
2650+
2651+ pax_exit_kernel
2652+
2653 #if defined(CONFIG_CPU_V6)
2654 ldr r0, [sp]
2655 strex r1, r2, [sp] @ clear the exclusive monitor
2656@@ -121,6 +178,9 @@
2657 .endm
2658 #else /* CONFIG_THUMB2_KERNEL */
2659 .macro svc_exit, rpsr
2660+
2661+ pax_exit_kernel
2662+
2663 ldr lr, [sp, #S_SP] @ top of the stack
2664 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2665 clrex @ clear the exclusive monitor
2666diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2667index 2adda11..7fbe958 100644
2668--- a/arch/arm/kernel/fiq.c
2669+++ b/arch/arm/kernel/fiq.c
2670@@ -82,7 +82,9 @@ void set_fiq_handler(void *start, unsigned int length)
2671 #if defined(CONFIG_CPU_USE_DOMAINS)
2672 memcpy((void *)0xffff001c, start, length);
2673 #else
2674+ pax_open_kernel();
2675 memcpy(vectors_page + 0x1c, start, length);
2676+ pax_close_kernel();
2677 #endif
2678 flush_icache_range(0xffff001c, 0xffff001c + length);
2679 if (!vectors_high())
2680diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2681index 486a15a..2d6880e 100644
2682--- a/arch/arm/kernel/head.S
2683+++ b/arch/arm/kernel/head.S
2684@@ -52,7 +52,9 @@
2685 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2686
2687 .macro pgtbl, rd, phys
2688- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2689+ mov \rd, #TEXT_OFFSET
2690+ sub \rd, #PG_DIR_SIZE
2691+ add \rd, \rd, \phys
2692 .endm
2693
2694 /*
2695@@ -416,7 +418,7 @@ __enable_mmu:
2696 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2697 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2698 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2699- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2700+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2701 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2702 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2703 #endif
2704diff --git a/arch/arm/kernel/hw_breakpoint.c b/arch/arm/kernel/hw_breakpoint.c
2705index 5ff2e77..556d030 100644
2706--- a/arch/arm/kernel/hw_breakpoint.c
2707+++ b/arch/arm/kernel/hw_breakpoint.c
2708@@ -1011,7 +1011,7 @@ static int __cpuinit dbg_reset_notify(struct notifier_block *self,
2709 return NOTIFY_OK;
2710 }
2711
2712-static struct notifier_block __cpuinitdata dbg_reset_nb = {
2713+static struct notifier_block dbg_reset_nb = {
2714 .notifier_call = dbg_reset_notify,
2715 };
2716
2717diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2718index 1e9be5d..03edbc2 100644
2719--- a/arch/arm/kernel/module.c
2720+++ b/arch/arm/kernel/module.c
2721@@ -37,12 +37,37 @@
2722 #endif
2723
2724 #ifdef CONFIG_MMU
2725-void *module_alloc(unsigned long size)
2726+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2727 {
2728+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2729+ return NULL;
2730 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2731- GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2732+ GFP_KERNEL, prot, -1,
2733 __builtin_return_address(0));
2734 }
2735+
2736+void *module_alloc(unsigned long size)
2737+{
2738+
2739+#ifdef CONFIG_PAX_KERNEXEC
2740+ return __module_alloc(size, PAGE_KERNEL);
2741+#else
2742+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2743+#endif
2744+
2745+}
2746+
2747+#ifdef CONFIG_PAX_KERNEXEC
2748+void module_free_exec(struct module *mod, void *module_region)
2749+{
2750+ module_free(mod, module_region);
2751+}
2752+
2753+void *module_alloc_exec(unsigned long size)
2754+{
2755+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2756+}
2757+#endif
2758 #endif
2759
2760 int
2761diff --git a/arch/arm/kernel/perf_event_cpu.c b/arch/arm/kernel/perf_event_cpu.c
2762index 5f66206..dce492f 100644
2763--- a/arch/arm/kernel/perf_event_cpu.c
2764+++ b/arch/arm/kernel/perf_event_cpu.c
2765@@ -171,7 +171,7 @@ static int __cpuinit cpu_pmu_notify(struct notifier_block *b,
2766 return NOTIFY_OK;
2767 }
2768
2769-static struct notifier_block __cpuinitdata cpu_pmu_hotplug_notifier = {
2770+static struct notifier_block cpu_pmu_hotplug_notifier = {
2771 .notifier_call = cpu_pmu_notify,
2772 };
2773
2774diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2775index c6dec5f..f853532 100644
2776--- a/arch/arm/kernel/process.c
2777+++ b/arch/arm/kernel/process.c
2778@@ -28,7 +28,6 @@
2779 #include <linux/tick.h>
2780 #include <linux/utsname.h>
2781 #include <linux/uaccess.h>
2782-#include <linux/random.h>
2783 #include <linux/hw_breakpoint.h>
2784 #include <linux/cpuidle.h>
2785 #include <linux/leds.h>
2786@@ -256,9 +255,10 @@ void machine_power_off(void)
2787 machine_shutdown();
2788 if (pm_power_off)
2789 pm_power_off();
2790+ BUG();
2791 }
2792
2793-void machine_restart(char *cmd)
2794+__noreturn void machine_restart(char *cmd)
2795 {
2796 machine_shutdown();
2797
2798@@ -283,8 +283,8 @@ void __show_regs(struct pt_regs *regs)
2799 init_utsname()->release,
2800 (int)strcspn(init_utsname()->version, " "),
2801 init_utsname()->version);
2802- print_symbol("PC is at %s\n", instruction_pointer(regs));
2803- print_symbol("LR is at %s\n", regs->ARM_lr);
2804+ printk("PC is at %pA\n", instruction_pointer(regs));
2805+ printk("LR is at %pA\n", regs->ARM_lr);
2806 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2807 "sp : %08lx ip : %08lx fp : %08lx\n",
2808 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2809@@ -452,12 +452,6 @@ unsigned long get_wchan(struct task_struct *p)
2810 return 0;
2811 }
2812
2813-unsigned long arch_randomize_brk(struct mm_struct *mm)
2814-{
2815- unsigned long range_end = mm->brk + 0x02000000;
2816- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2817-}
2818-
2819 #ifdef CONFIG_MMU
2820 /*
2821 * The vectors page is always readable from user space for the
2822diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2823index 03deeff..741ce88 100644
2824--- a/arch/arm/kernel/ptrace.c
2825+++ b/arch/arm/kernel/ptrace.c
2826@@ -937,10 +937,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2827 return current_thread_info()->syscall;
2828 }
2829
2830+#ifdef CONFIG_GRKERNSEC_SETXID
2831+extern void gr_delayed_cred_worker(void);
2832+#endif
2833+
2834 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2835 {
2836 current_thread_info()->syscall = scno;
2837
2838+#ifdef CONFIG_GRKERNSEC_SETXID
2839+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2840+ gr_delayed_cred_worker();
2841+#endif
2842+
2843 /* Do the secure computing check first; failures should be fast. */
2844 if (secure_computing(scno) == -1)
2845 return -1;
2846diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2847index 3f6cbb2..6d856f5 100644
2848--- a/arch/arm/kernel/setup.c
2849+++ b/arch/arm/kernel/setup.c
2850@@ -97,21 +97,23 @@ EXPORT_SYMBOL(system_serial_high);
2851 unsigned int elf_hwcap __read_mostly;
2852 EXPORT_SYMBOL(elf_hwcap);
2853
2854+pteval_t __supported_pte_mask __read_only;
2855+pmdval_t __supported_pmd_mask __read_only;
2856
2857 #ifdef MULTI_CPU
2858-struct processor processor __read_mostly;
2859+struct processor processor;
2860 #endif
2861 #ifdef MULTI_TLB
2862-struct cpu_tlb_fns cpu_tlb __read_mostly;
2863+struct cpu_tlb_fns cpu_tlb __read_only;
2864 #endif
2865 #ifdef MULTI_USER
2866-struct cpu_user_fns cpu_user __read_mostly;
2867+struct cpu_user_fns cpu_user __read_only;
2868 #endif
2869 #ifdef MULTI_CACHE
2870-struct cpu_cache_fns cpu_cache __read_mostly;
2871+struct cpu_cache_fns cpu_cache __read_only;
2872 #endif
2873 #ifdef CONFIG_OUTER_CACHE
2874-struct outer_cache_fns outer_cache __read_mostly;
2875+struct outer_cache_fns outer_cache __read_only;
2876 EXPORT_SYMBOL(outer_cache);
2877 #endif
2878
2879@@ -236,9 +238,13 @@ static int __get_cpu_architecture(void)
2880 asm("mrc p15, 0, %0, c0, c1, 4"
2881 : "=r" (mmfr0));
2882 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2883- (mmfr0 & 0x000000f0) >= 0x00000030)
2884+ (mmfr0 & 0x000000f0) >= 0x00000030) {
2885 cpu_arch = CPU_ARCH_ARMv7;
2886- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2887+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2888+ __supported_pte_mask |= L_PTE_PXN;
2889+ __supported_pmd_mask |= PMD_PXNTABLE;
2890+ }
2891+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2892 (mmfr0 & 0x000000f0) == 0x00000020)
2893 cpu_arch = CPU_ARCH_ARMv6;
2894 else
2895@@ -462,7 +468,7 @@ static void __init setup_processor(void)
2896 __cpu_architecture = __get_cpu_architecture();
2897
2898 #ifdef MULTI_CPU
2899- processor = *list->proc;
2900+ memcpy((void *)&processor, list->proc, sizeof processor);
2901 #endif
2902 #ifdef MULTI_TLB
2903 cpu_tlb = *list->tlb;
2904diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
2905index 84f4cbf..672f5b8 100644
2906--- a/arch/arm/kernel/smp.c
2907+++ b/arch/arm/kernel/smp.c
2908@@ -70,7 +70,7 @@ enum ipi_msg_type {
2909
2910 static DECLARE_COMPLETION(cpu_running);
2911
2912-static struct smp_operations smp_ops;
2913+static struct smp_operations smp_ops __read_only;
2914
2915 void __init smp_set_ops(struct smp_operations *ops)
2916 {
2917diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
2918index b0179b8..b7b16c7 100644
2919--- a/arch/arm/kernel/traps.c
2920+++ b/arch/arm/kernel/traps.c
2921@@ -57,7 +57,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
2922 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
2923 {
2924 #ifdef CONFIG_KALLSYMS
2925- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
2926+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
2927 #else
2928 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
2929 #endif
2930@@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
2931 static int die_owner = -1;
2932 static unsigned int die_nest_count;
2933
2934+extern void gr_handle_kernel_exploit(void);
2935+
2936 static unsigned long oops_begin(void)
2937 {
2938 int cpu;
2939@@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
2940 panic("Fatal exception in interrupt");
2941 if (panic_on_oops)
2942 panic("Fatal exception");
2943+
2944+ gr_handle_kernel_exploit();
2945+
2946 if (signr)
2947 do_exit(signr);
2948 }
2949@@ -601,7 +606,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
2950 * The user helper at 0xffff0fe0 must be used instead.
2951 * (see entry-armv.S for details)
2952 */
2953+ pax_open_kernel();
2954 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
2955+ pax_close_kernel();
2956 }
2957 return 0;
2958
2959@@ -849,5 +856,9 @@ void __init early_trap_init(void *vectors_base)
2960 sigreturn_codes, sizeof(sigreturn_codes));
2961
2962 flush_icache_range(vectors, vectors + PAGE_SIZE);
2963- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
2964+
2965+#ifndef CONFIG_PAX_MEMORY_UDEREF
2966+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
2967+#endif
2968+
2969 }
2970diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
2971index 11c1785..c67d54c 100644
2972--- a/arch/arm/kernel/vmlinux.lds.S
2973+++ b/arch/arm/kernel/vmlinux.lds.S
2974@@ -8,7 +8,11 @@
2975 #include <asm/thread_info.h>
2976 #include <asm/memory.h>
2977 #include <asm/page.h>
2978-
2979+
2980+#ifdef CONFIG_PAX_KERNEXEC
2981+#include <asm/pgtable.h>
2982+#endif
2983+
2984 #define PROC_INFO \
2985 . = ALIGN(4); \
2986 VMLINUX_SYMBOL(__proc_info_begin) = .; \
2987@@ -90,6 +94,11 @@ SECTIONS
2988 _text = .;
2989 HEAD_TEXT
2990 }
2991+
2992+#ifdef CONFIG_PAX_KERNEXEC
2993+ . = ALIGN(1<<SECTION_SHIFT);
2994+#endif
2995+
2996 .text : { /* Real text segment */
2997 _stext = .; /* Text and read-only data */
2998 __exception_text_start = .;
2999@@ -144,6 +153,10 @@ SECTIONS
3000
3001 _etext = .; /* End of text and rodata section */
3002
3003+#ifdef CONFIG_PAX_KERNEXEC
3004+ . = ALIGN(1<<SECTION_SHIFT);
3005+#endif
3006+
3007 #ifndef CONFIG_XIP_KERNEL
3008 . = ALIGN(PAGE_SIZE);
3009 __init_begin = .;
3010@@ -203,6 +216,11 @@ SECTIONS
3011 . = PAGE_OFFSET + TEXT_OFFSET;
3012 #else
3013 __init_end = .;
3014+
3015+#ifdef CONFIG_PAX_KERNEXEC
3016+ . = ALIGN(1<<SECTION_SHIFT);
3017+#endif
3018+
3019 . = ALIGN(THREAD_SIZE);
3020 __data_loc = .;
3021 #endif
3022diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3023index 14a0d98..7771a7d 100644
3024--- a/arch/arm/lib/clear_user.S
3025+++ b/arch/arm/lib/clear_user.S
3026@@ -12,14 +12,14 @@
3027
3028 .text
3029
3030-/* Prototype: int __clear_user(void *addr, size_t sz)
3031+/* Prototype: int ___clear_user(void *addr, size_t sz)
3032 * Purpose : clear some user memory
3033 * Params : addr - user memory address to clear
3034 * : sz - number of bytes to clear
3035 * Returns : number of bytes NOT cleared
3036 */
3037 ENTRY(__clear_user_std)
3038-WEAK(__clear_user)
3039+WEAK(___clear_user)
3040 stmfd sp!, {r1, lr}
3041 mov r2, #0
3042 cmp r1, #4
3043@@ -44,7 +44,7 @@ WEAK(__clear_user)
3044 USER( strnebt r2, [r0])
3045 mov r0, #0
3046 ldmfd sp!, {r1, pc}
3047-ENDPROC(__clear_user)
3048+ENDPROC(___clear_user)
3049 ENDPROC(__clear_user_std)
3050
3051 .pushsection .fixup,"ax"
3052diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3053index 66a477a..bee61d3 100644
3054--- a/arch/arm/lib/copy_from_user.S
3055+++ b/arch/arm/lib/copy_from_user.S
3056@@ -16,7 +16,7 @@
3057 /*
3058 * Prototype:
3059 *
3060- * size_t __copy_from_user(void *to, const void *from, size_t n)
3061+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3062 *
3063 * Purpose:
3064 *
3065@@ -84,11 +84,11 @@
3066
3067 .text
3068
3069-ENTRY(__copy_from_user)
3070+ENTRY(___copy_from_user)
3071
3072 #include "copy_template.S"
3073
3074-ENDPROC(__copy_from_user)
3075+ENDPROC(___copy_from_user)
3076
3077 .pushsection .fixup,"ax"
3078 .align 0
3079diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3080index 6ee2f67..d1cce76 100644
3081--- a/arch/arm/lib/copy_page.S
3082+++ b/arch/arm/lib/copy_page.S
3083@@ -10,6 +10,7 @@
3084 * ASM optimised string functions
3085 */
3086 #include <linux/linkage.h>
3087+#include <linux/const.h>
3088 #include <asm/assembler.h>
3089 #include <asm/asm-offsets.h>
3090 #include <asm/cache.h>
3091diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3092index d066df6..df28194 100644
3093--- a/arch/arm/lib/copy_to_user.S
3094+++ b/arch/arm/lib/copy_to_user.S
3095@@ -16,7 +16,7 @@
3096 /*
3097 * Prototype:
3098 *
3099- * size_t __copy_to_user(void *to, const void *from, size_t n)
3100+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3101 *
3102 * Purpose:
3103 *
3104@@ -88,11 +88,11 @@
3105 .text
3106
3107 ENTRY(__copy_to_user_std)
3108-WEAK(__copy_to_user)
3109+WEAK(___copy_to_user)
3110
3111 #include "copy_template.S"
3112
3113-ENDPROC(__copy_to_user)
3114+ENDPROC(___copy_to_user)
3115 ENDPROC(__copy_to_user_std)
3116
3117 .pushsection .fixup,"ax"
3118diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3119index 7d08b43..f7ca7ea 100644
3120--- a/arch/arm/lib/csumpartialcopyuser.S
3121+++ b/arch/arm/lib/csumpartialcopyuser.S
3122@@ -57,8 +57,8 @@
3123 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3124 */
3125
3126-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3127-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3128+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3129+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3130
3131 #include "csumpartialcopygeneric.S"
3132
3133diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3134index 0dc5385..45833ef 100644
3135--- a/arch/arm/lib/delay.c
3136+++ b/arch/arm/lib/delay.c
3137@@ -28,12 +28,14 @@
3138 /*
3139 * Default to the loop-based delay implementation.
3140 */
3141-struct arm_delay_ops arm_delay_ops = {
3142+static struct arm_delay_ops arm_loop_delay_ops = {
3143 .delay = __loop_delay,
3144 .const_udelay = __loop_const_udelay,
3145 .udelay = __loop_udelay,
3146 };
3147
3148+struct arm_delay_ops *arm_delay_ops __read_only = &arm_loop_delay_ops;
3149+
3150 static const struct delay_timer *delay_timer;
3151 static bool delay_calibrated;
3152
3153@@ -67,6 +69,12 @@ static void __timer_udelay(unsigned long usecs)
3154 __timer_const_udelay(usecs * UDELAY_MULT);
3155 }
3156
3157+static struct arm_delay_ops arm_timer_delay_ops = {
3158+ .delay = __timer_delay,
3159+ .const_udelay = __timer_const_udelay,
3160+ .udelay = __timer_udelay,
3161+};
3162+
3163 void __init register_current_timer_delay(const struct delay_timer *timer)
3164 {
3165 if (!delay_calibrated) {
3166@@ -74,9 +82,7 @@ void __init register_current_timer_delay(const struct delay_timer *timer)
3167 delay_timer = timer;
3168 lpj_fine = timer->freq / HZ;
3169 loops_per_jiffy = lpj_fine;
3170- arm_delay_ops.delay = __timer_delay;
3171- arm_delay_ops.const_udelay = __timer_const_udelay;
3172- arm_delay_ops.udelay = __timer_udelay;
3173+ arm_delay_ops = &arm_timer_delay_ops;
3174 delay_calibrated = true;
3175 } else {
3176 pr_info("Ignoring duplicate/late registration of read_current_timer delay\n");
3177diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3178index 025f742..8432b08 100644
3179--- a/arch/arm/lib/uaccess_with_memcpy.c
3180+++ b/arch/arm/lib/uaccess_with_memcpy.c
3181@@ -104,7 +104,7 @@ out:
3182 }
3183
3184 unsigned long
3185-__copy_to_user(void __user *to, const void *from, unsigned long n)
3186+___copy_to_user(void __user *to, const void *from, unsigned long n)
3187 {
3188 /*
3189 * This test is stubbed out of the main function above to keep
3190diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3191index bac21a5..b67ef8e 100644
3192--- a/arch/arm/mach-kirkwood/common.c
3193+++ b/arch/arm/mach-kirkwood/common.c
3194@@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3195 clk_gate_ops.disable(hw);
3196 }
3197
3198-static struct clk_ops clk_gate_fn_ops;
3199+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3200+{
3201+ return clk_gate_ops.is_enabled(hw);
3202+}
3203+
3204+static struct clk_ops clk_gate_fn_ops = {
3205+ .enable = clk_gate_fn_enable,
3206+ .disable = clk_gate_fn_disable,
3207+ .is_enabled = clk_gate_fn_is_enabled,
3208+};
3209
3210 static struct clk __init *clk_register_gate_fn(struct device *dev,
3211 const char *name,
3212@@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3213 gate_fn->fn_en = fn_en;
3214 gate_fn->fn_dis = fn_dis;
3215
3216- /* ops is the gate ops, but with our enable/disable functions */
3217- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3218- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3219- clk_gate_fn_ops = clk_gate_ops;
3220- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3221- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3222- }
3223-
3224 clk = clk_register(dev, &gate_fn->gate.hw);
3225
3226 if (IS_ERR(clk))
3227diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3228index 0abb30f..54064da 100644
3229--- a/arch/arm/mach-omap2/board-n8x0.c
3230+++ b/arch/arm/mach-omap2/board-n8x0.c
3231@@ -631,7 +631,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3232 }
3233 #endif
3234
3235-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3236+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3237 .late_init = n8x0_menelaus_late_init,
3238 };
3239
3240diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3241index 5d3b4f4..ddba3c0 100644
3242--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3243+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3244@@ -340,7 +340,7 @@ static int __cpuinit irq_cpu_hotplug_notify(struct notifier_block *self,
3245 return NOTIFY_OK;
3246 }
3247
3248-static struct notifier_block __refdata irq_hotplug_notifier = {
3249+static struct notifier_block irq_hotplug_notifier = {
3250 .notifier_call = irq_cpu_hotplug_notify,
3251 };
3252
3253diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3254index 4653efb..8c60bf7 100644
3255--- a/arch/arm/mach-omap2/omap_hwmod.c
3256+++ b/arch/arm/mach-omap2/omap_hwmod.c
3257@@ -189,10 +189,10 @@ struct omap_hwmod_soc_ops {
3258 int (*init_clkdm)(struct omap_hwmod *oh);
3259 void (*update_context_lost)(struct omap_hwmod *oh);
3260 int (*get_context_lost)(struct omap_hwmod *oh);
3261-};
3262+} __no_const;
3263
3264 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3265-static struct omap_hwmod_soc_ops soc_ops;
3266+static struct omap_hwmod_soc_ops soc_ops __read_only;
3267
3268 /* omap_hwmod_list contains all registered struct omap_hwmods */
3269 static LIST_HEAD(omap_hwmod_list);
3270diff --git a/arch/arm/mach-ux500/include/mach/setup.h b/arch/arm/mach-ux500/include/mach/setup.h
3271index 6be4c4d..32ac32a 100644
3272--- a/arch/arm/mach-ux500/include/mach/setup.h
3273+++ b/arch/arm/mach-ux500/include/mach/setup.h
3274@@ -38,13 +38,6 @@ extern struct sys_timer ux500_timer;
3275 .type = MT_DEVICE, \
3276 }
3277
3278-#define __MEM_DEV_DESC(x, sz) { \
3279- .virtual = IO_ADDRESS(x), \
3280- .pfn = __phys_to_pfn(x), \
3281- .length = sz, \
3282- .type = MT_MEMORY, \
3283-}
3284-
3285 extern struct smp_operations ux500_smp_ops;
3286 extern void ux500_cpu_die(unsigned int cpu);
3287
3288diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3289index 3fd629d..8b1aca9 100644
3290--- a/arch/arm/mm/Kconfig
3291+++ b/arch/arm/mm/Kconfig
3292@@ -425,7 +425,7 @@ config CPU_32v5
3293
3294 config CPU_32v6
3295 bool
3296- select CPU_USE_DOMAINS if CPU_V6 && MMU
3297+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC
3298 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3299
3300 config CPU_32v6K
3301@@ -577,6 +577,7 @@ config CPU_CP15_MPU
3302
3303 config CPU_USE_DOMAINS
3304 bool
3305+ depends on !ARM_LPAE && !PAX_KERNEXEC
3306 help
3307 This option enables or disables the use of domain switching
3308 via the set_fs() function.
3309diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3310index 5dbf13f..6393f55 100644
3311--- a/arch/arm/mm/fault.c
3312+++ b/arch/arm/mm/fault.c
3313@@ -25,6 +25,7 @@
3314 #include <asm/system_misc.h>
3315 #include <asm/system_info.h>
3316 #include <asm/tlbflush.h>
3317+#include <asm/sections.h>
3318
3319 #include "fault.h"
3320
3321@@ -138,6 +139,20 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3322 if (fixup_exception(regs))
3323 return;
3324
3325+#ifdef CONFIG_PAX_KERNEXEC
3326+ if ((fsr & FSR_WRITE) &&
3327+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3328+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3329+ {
3330+ if (current->signal->curr_ip)
3331+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3332+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
3333+ else
3334+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3335+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
3336+ }
3337+#endif
3338+
3339 /*
3340 * No handler, we'll have to terminate things with extreme prejudice.
3341 */
3342@@ -174,6 +189,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3343 }
3344 #endif
3345
3346+#ifdef CONFIG_PAX_PAGEEXEC
3347+ if (fsr & FSR_LNX_PF) {
3348+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3349+ do_group_exit(SIGKILL);
3350+ }
3351+#endif
3352+
3353 tsk->thread.address = addr;
3354 tsk->thread.error_code = fsr;
3355 tsk->thread.trap_no = 14;
3356@@ -398,6 +420,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3357 }
3358 #endif /* CONFIG_MMU */
3359
3360+#ifdef CONFIG_PAX_PAGEEXEC
3361+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3362+{
3363+ long i;
3364+
3365+ printk(KERN_ERR "PAX: bytes at PC: ");
3366+ for (i = 0; i < 20; i++) {
3367+ unsigned char c;
3368+ if (get_user(c, (__force unsigned char __user *)pc+i))
3369+ printk(KERN_CONT "?? ");
3370+ else
3371+ printk(KERN_CONT "%02x ", c);
3372+ }
3373+ printk("\n");
3374+
3375+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3376+ for (i = -1; i < 20; i++) {
3377+ unsigned long c;
3378+ if (get_user(c, (__force unsigned long __user *)sp+i))
3379+ printk(KERN_CONT "???????? ");
3380+ else
3381+ printk(KERN_CONT "%08lx ", c);
3382+ }
3383+ printk("\n");
3384+}
3385+#endif
3386+
3387 /*
3388 * First Level Translation Fault Handler
3389 *
3390@@ -543,9 +592,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3391 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3392 struct siginfo info;
3393
3394+#ifdef CONFIG_PAX_MEMORY_UDEREF
3395+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3396+ if (current->signal->curr_ip)
3397+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3398+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()), addr);
3399+ else
3400+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3401+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()), addr);
3402+ goto die;
3403+ }
3404+#endif
3405+
3406 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3407 return;
3408
3409+die:
3410 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3411 inf->name, fsr, addr);
3412
3413@@ -575,9 +637,38 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3414 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3415 struct siginfo info;
3416
3417+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3418+ if (!user_mode(regs) && (is_domain_fault(ifsr) || is_xn_fault(ifsr))) {
3419+ if (current->signal->curr_ip)
3420+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3421+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()),
3422+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3423+ else
3424+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3425+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()),
3426+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3427+ goto die;
3428+ }
3429+#endif
3430+
3431+#ifdef CONFIG_PAX_REFCOUNT
3432+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3433+ unsigned int bkpt;
3434+
3435+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
3436+ current->thread.error_code = ifsr;
3437+ current->thread.trap_no = 0;
3438+ pax_report_refcount_overflow(regs);
3439+ fixup_exception(regs);
3440+ return;
3441+ }
3442+ }
3443+#endif
3444+
3445 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
3446 return;
3447
3448+die:
3449 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
3450 inf->name, ifsr, addr);
3451
3452diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
3453index cf08bdf..772656c 100644
3454--- a/arch/arm/mm/fault.h
3455+++ b/arch/arm/mm/fault.h
3456@@ -3,6 +3,7 @@
3457
3458 /*
3459 * Fault status register encodings. We steal bit 31 for our own purposes.
3460+ * Set when the FSR value is from an instruction fault.
3461 */
3462 #define FSR_LNX_PF (1 << 31)
3463 #define FSR_WRITE (1 << 11)
3464@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
3465 }
3466 #endif
3467
3468+/* valid for LPAE and !LPAE */
3469+static inline int is_xn_fault(unsigned int fsr)
3470+{
3471+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
3472+}
3473+
3474+static inline int is_domain_fault(unsigned int fsr)
3475+{
3476+ return ((fsr_fs(fsr) & 0xD) == 0x9);
3477+}
3478+
3479 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
3480 unsigned long search_exception_table(unsigned long addr);
3481
3482diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
3483index ad722f1..763fdd3 100644
3484--- a/arch/arm/mm/init.c
3485+++ b/arch/arm/mm/init.c
3486@@ -30,6 +30,8 @@
3487 #include <asm/setup.h>
3488 #include <asm/tlb.h>
3489 #include <asm/fixmap.h>
3490+#include <asm/system_info.h>
3491+#include <asm/cp15.h>
3492
3493 #include <asm/mach/arch.h>
3494 #include <asm/mach/map.h>
3495@@ -736,7 +738,46 @@ void free_initmem(void)
3496 {
3497 #ifdef CONFIG_HAVE_TCM
3498 extern char __tcm_start, __tcm_end;
3499+#endif
3500
3501+#ifdef CONFIG_PAX_KERNEXEC
3502+ unsigned long addr;
3503+ pgd_t *pgd;
3504+ pud_t *pud;
3505+ pmd_t *pmd;
3506+ int cpu_arch = cpu_architecture();
3507+ unsigned int cr = get_cr();
3508+
3509+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
3510+ /* make pages tables, etc before .text NX */
3511+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
3512+ pgd = pgd_offset_k(addr);
3513+ pud = pud_offset(pgd, addr);
3514+ pmd = pmd_offset(pud, addr);
3515+ __section_update(pmd, addr, PMD_SECT_XN);
3516+ }
3517+ /* make init NX */
3518+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
3519+ pgd = pgd_offset_k(addr);
3520+ pud = pud_offset(pgd, addr);
3521+ pmd = pmd_offset(pud, addr);
3522+ __section_update(pmd, addr, PMD_SECT_XN);
3523+ }
3524+ /* make kernel code/rodata RX */
3525+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
3526+ pgd = pgd_offset_k(addr);
3527+ pud = pud_offset(pgd, addr);
3528+ pmd = pmd_offset(pud, addr);
3529+#ifdef CONFIG_ARM_LPAE
3530+ __section_update(pmd, addr, PMD_SECT_RDONLY);
3531+#else
3532+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
3533+#endif
3534+ }
3535+ }
3536+#endif
3537+
3538+#ifdef CONFIG_HAVE_TCM
3539 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
3540 totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)),
3541 __phys_to_pfn(__pa(&__tcm_end)),
3542diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
3543index 88fd86c..7a224ce 100644
3544--- a/arch/arm/mm/ioremap.c
3545+++ b/arch/arm/mm/ioremap.c
3546@@ -335,9 +335,9 @@ __arm_ioremap_exec(unsigned long phys_addr, size_t size, bool cached)
3547 unsigned int mtype;
3548
3549 if (cached)
3550- mtype = MT_MEMORY;
3551+ mtype = MT_MEMORY_RX;
3552 else
3553- mtype = MT_MEMORY_NONCACHED;
3554+ mtype = MT_MEMORY_NONCACHED_RX;
3555
3556 return __arm_ioremap_caller(phys_addr, size, mtype,
3557 __builtin_return_address(0));
3558diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
3559index 10062ce..aa96dd7 100644
3560--- a/arch/arm/mm/mmap.c
3561+++ b/arch/arm/mm/mmap.c
3562@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3563 struct vm_area_struct *vma;
3564 int do_align = 0;
3565 int aliasing = cache_is_vipt_aliasing();
3566+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3567 struct vm_unmapped_area_info info;
3568
3569 /*
3570@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3571 if (len > TASK_SIZE)
3572 return -ENOMEM;
3573
3574+#ifdef CONFIG_PAX_RANDMMAP
3575+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3576+#endif
3577+
3578 if (addr) {
3579 if (do_align)
3580 addr = COLOUR_ALIGN(addr, pgoff);
3581@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3582 addr = PAGE_ALIGN(addr);
3583
3584 vma = find_vma(mm, addr);
3585- if (TASK_SIZE - len >= addr &&
3586- (!vma || addr + len <= vma->vm_start))
3587+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3588 return addr;
3589 }
3590
3591@@ -112,6 +116,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3592 unsigned long addr = addr0;
3593 int do_align = 0;
3594 int aliasing = cache_is_vipt_aliasing();
3595+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3596 struct vm_unmapped_area_info info;
3597
3598 /*
3599@@ -132,6 +137,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3600 return addr;
3601 }
3602
3603+#ifdef CONFIG_PAX_RANDMMAP
3604+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3605+#endif
3606+
3607 /* requesting a specific address */
3608 if (addr) {
3609 if (do_align)
3610@@ -139,8 +148,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3611 else
3612 addr = PAGE_ALIGN(addr);
3613 vma = find_vma(mm, addr);
3614- if (TASK_SIZE - len >= addr &&
3615- (!vma || addr + len <= vma->vm_start))
3616+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3617 return addr;
3618 }
3619
3620@@ -162,6 +170,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3621 VM_BUG_ON(addr != -ENOMEM);
3622 info.flags = 0;
3623 info.low_limit = mm->mmap_base;
3624+
3625+#ifdef CONFIG_PAX_RANDMMAP
3626+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3627+ info.low_limit += mm->delta_mmap;
3628+#endif
3629+
3630 info.high_limit = TASK_SIZE;
3631 addr = vm_unmapped_area(&info);
3632 }
3633@@ -173,6 +187,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3634 {
3635 unsigned long random_factor = 0UL;
3636
3637+#ifdef CONFIG_PAX_RANDMMAP
3638+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3639+#endif
3640+
3641 /* 8 bits of randomness in 20 address space bits */
3642 if ((current->flags & PF_RANDOMIZE) &&
3643 !(current->personality & ADDR_NO_RANDOMIZE))
3644@@ -180,10 +198,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3645
3646 if (mmap_is_legacy()) {
3647 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
3648+
3649+#ifdef CONFIG_PAX_RANDMMAP
3650+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3651+ mm->mmap_base += mm->delta_mmap;
3652+#endif
3653+
3654 mm->get_unmapped_area = arch_get_unmapped_area;
3655 mm->unmap_area = arch_unmap_area;
3656 } else {
3657 mm->mmap_base = mmap_base(random_factor);
3658+
3659+#ifdef CONFIG_PAX_RANDMMAP
3660+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3661+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3662+#endif
3663+
3664 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3665 mm->unmap_area = arch_unmap_area_topdown;
3666 }
3667diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
3668index ce328c7..f82bebb 100644
3669--- a/arch/arm/mm/mmu.c
3670+++ b/arch/arm/mm/mmu.c
3671@@ -35,6 +35,23 @@
3672
3673 #include "mm.h"
3674
3675+
3676+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3677+void modify_domain(unsigned int dom, unsigned int type)
3678+{
3679+ struct thread_info *thread = current_thread_info();
3680+ unsigned int domain = thread->cpu_domain;
3681+ /*
3682+ * DOMAIN_MANAGER might be defined to some other value,
3683+ * use the arch-defined constant
3684+ */
3685+ domain &= ~domain_val(dom, 3);
3686+ thread->cpu_domain = domain | domain_val(dom, type);
3687+ set_domain(thread->cpu_domain);
3688+}
3689+EXPORT_SYMBOL(modify_domain);
3690+#endif
3691+
3692 /*
3693 * empty_zero_page is a special page that is used for
3694 * zero-initialized data and COW.
3695@@ -195,10 +212,18 @@ void adjust_cr(unsigned long mask, unsigned long set)
3696 }
3697 #endif
3698
3699-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
3700+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
3701 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
3702
3703-static struct mem_type mem_types[] = {
3704+#ifdef CONFIG_PAX_KERNEXEC
3705+#define L_PTE_KERNEXEC L_PTE_RDONLY
3706+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
3707+#else
3708+#define L_PTE_KERNEXEC L_PTE_DIRTY
3709+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
3710+#endif
3711+
3712+static struct mem_type mem_types[] __read_only = {
3713 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
3714 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
3715 L_PTE_SHARED,
3716@@ -227,16 +252,16 @@ static struct mem_type mem_types[] = {
3717 [MT_UNCACHED] = {
3718 .prot_pte = PROT_PTE_DEVICE,
3719 .prot_l1 = PMD_TYPE_TABLE,
3720- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3721+ .prot_sect = PROT_SECT_DEVICE,
3722 .domain = DOMAIN_IO,
3723 },
3724 [MT_CACHECLEAN] = {
3725- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3726+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
3727 .domain = DOMAIN_KERNEL,
3728 },
3729 #ifndef CONFIG_ARM_LPAE
3730 [MT_MINICLEAN] = {
3731- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
3732+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
3733 .domain = DOMAIN_KERNEL,
3734 },
3735 #endif
3736@@ -244,36 +269,54 @@ static struct mem_type mem_types[] = {
3737 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3738 L_PTE_RDONLY,
3739 .prot_l1 = PMD_TYPE_TABLE,
3740- .domain = DOMAIN_USER,
3741+ .domain = DOMAIN_VECTORS,
3742 },
3743 [MT_HIGH_VECTORS] = {
3744 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3745 L_PTE_USER | L_PTE_RDONLY,
3746 .prot_l1 = PMD_TYPE_TABLE,
3747- .domain = DOMAIN_USER,
3748+ .domain = DOMAIN_VECTORS,
3749 },
3750- [MT_MEMORY] = {
3751+ [MT_MEMORY_RWX] = {
3752 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
3753 .prot_l1 = PMD_TYPE_TABLE,
3754 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
3755 .domain = DOMAIN_KERNEL,
3756 },
3757+ [MT_MEMORY_RW] = {
3758+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
3759+ .prot_l1 = PMD_TYPE_TABLE,
3760+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
3761+ .domain = DOMAIN_KERNEL,
3762+ },
3763+ [MT_MEMORY_RX] = {
3764+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
3765+ .prot_l1 = PMD_TYPE_TABLE,
3766+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
3767+ .domain = DOMAIN_KERNEL,
3768+ },
3769 [MT_ROM] = {
3770- .prot_sect = PMD_TYPE_SECT,
3771+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
3772 .domain = DOMAIN_KERNEL,
3773 },
3774- [MT_MEMORY_NONCACHED] = {
3775+ [MT_MEMORY_NONCACHED_RW] = {
3776 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3777 L_PTE_MT_BUFFERABLE,
3778 .prot_l1 = PMD_TYPE_TABLE,
3779 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
3780 .domain = DOMAIN_KERNEL,
3781 },
3782+ [MT_MEMORY_NONCACHED_RX] = {
3783+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
3784+ L_PTE_MT_BUFFERABLE,
3785+ .prot_l1 = PMD_TYPE_TABLE,
3786+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
3787+ .domain = DOMAIN_KERNEL,
3788+ },
3789 [MT_MEMORY_DTCM] = {
3790- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3791- L_PTE_XN,
3792+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
3793 .prot_l1 = PMD_TYPE_TABLE,
3794- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3795+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
3796 .domain = DOMAIN_KERNEL,
3797 },
3798 [MT_MEMORY_ITCM] = {
3799@@ -283,10 +326,10 @@ static struct mem_type mem_types[] = {
3800 },
3801 [MT_MEMORY_SO] = {
3802 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3803- L_PTE_MT_UNCACHED | L_PTE_XN,
3804+ L_PTE_MT_UNCACHED,
3805 .prot_l1 = PMD_TYPE_TABLE,
3806 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
3807- PMD_SECT_UNCACHED | PMD_SECT_XN,
3808+ PMD_SECT_UNCACHED,
3809 .domain = DOMAIN_KERNEL,
3810 },
3811 [MT_MEMORY_DMA_READY] = {
3812@@ -371,9 +414,35 @@ static void __init build_mem_type_table(void)
3813 * to prevent speculative instruction fetches.
3814 */
3815 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
3816+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
3817 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
3818+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
3819 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
3820+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
3821 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
3822+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
3823+
3824+ /* Mark other regions on ARMv6+ as execute-never */
3825+
3826+#ifdef CONFIG_PAX_KERNEXEC
3827+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
3828+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
3829+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
3830+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
3831+#ifndef CONFIG_ARM_LPAE
3832+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
3833+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
3834+#endif
3835+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
3836+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
3837+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
3838+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
3839+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
3840+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
3841+#endif
3842+
3843+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
3844+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
3845 }
3846 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
3847 /*
3848@@ -432,6 +501,9 @@ static void __init build_mem_type_table(void)
3849 * from SVC mode and no access from userspace.
3850 */
3851 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
3852+#ifdef CONFIG_PAX_KERNEXEC
3853+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
3854+#endif
3855 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
3856 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
3857 #endif
3858@@ -448,11 +520,17 @@ static void __init build_mem_type_table(void)
3859 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
3860 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
3861 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
3862- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
3863- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
3864+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
3865+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
3866+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
3867+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
3868+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
3869+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
3870 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
3871- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
3872- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
3873+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
3874+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
3875+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
3876+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
3877 }
3878 }
3879
3880@@ -463,15 +541,20 @@ static void __init build_mem_type_table(void)
3881 if (cpu_arch >= CPU_ARCH_ARMv6) {
3882 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
3883 /* Non-cacheable Normal is XCB = 001 */
3884- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
3885+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
3886+ PMD_SECT_BUFFERED;
3887+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
3888 PMD_SECT_BUFFERED;
3889 } else {
3890 /* For both ARMv6 and non-TEX-remapping ARMv7 */
3891- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
3892+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
3893+ PMD_SECT_TEX(1);
3894+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
3895 PMD_SECT_TEX(1);
3896 }
3897 } else {
3898- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
3899+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
3900+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
3901 }
3902
3903 #ifdef CONFIG_ARM_LPAE
3904@@ -487,6 +570,8 @@ static void __init build_mem_type_table(void)
3905 vecs_pgprot |= PTE_EXT_AF;
3906 #endif
3907
3908+ user_pgprot |= __supported_pte_mask;
3909+
3910 for (i = 0; i < 16; i++) {
3911 pteval_t v = pgprot_val(protection_map[i]);
3912 protection_map[i] = __pgprot(v | user_pgprot);
3913@@ -501,10 +586,15 @@ static void __init build_mem_type_table(void)
3914
3915 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
3916 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
3917- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
3918- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
3919+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
3920+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
3921+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
3922+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
3923+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
3924+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
3925 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
3926- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
3927+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
3928+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
3929 mem_types[MT_ROM].prot_sect |= cp->pmd;
3930
3931 switch (cp->pmd) {
3932@@ -1105,18 +1195,15 @@ void __init arm_mm_memblock_reserve(void)
3933 * called function. This means you can't use any function or debugging
3934 * method which may touch any device, otherwise the kernel _will_ crash.
3935 */
3936+
3937+static char vectors[PAGE_SIZE] __read_only __aligned(PAGE_SIZE);
3938+
3939 static void __init devicemaps_init(struct machine_desc *mdesc)
3940 {
3941 struct map_desc map;
3942 unsigned long addr;
3943- void *vectors;
3944
3945- /*
3946- * Allocate the vector page early.
3947- */
3948- vectors = early_alloc(PAGE_SIZE);
3949-
3950- early_trap_init(vectors);
3951+ early_trap_init(&vectors);
3952
3953 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
3954 pmd_clear(pmd_off_k(addr));
3955@@ -1156,7 +1243,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
3956 * location (0xffff0000). If we aren't using high-vectors, also
3957 * create a mapping at the low-vectors virtual address.
3958 */
3959- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
3960+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
3961 map.virtual = 0xffff0000;
3962 map.length = PAGE_SIZE;
3963 map.type = MT_HIGH_VECTORS;
3964@@ -1214,8 +1301,39 @@ static void __init map_lowmem(void)
3965 map.pfn = __phys_to_pfn(start);
3966 map.virtual = __phys_to_virt(start);
3967 map.length = end - start;
3968- map.type = MT_MEMORY;
3969
3970+#ifdef CONFIG_PAX_KERNEXEC
3971+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
3972+ struct map_desc kernel;
3973+ struct map_desc initmap;
3974+
3975+ /* when freeing initmem we will make this RW */
3976+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
3977+ initmap.virtual = (unsigned long)__init_begin;
3978+ initmap.length = _sdata - __init_begin;
3979+ initmap.type = MT_MEMORY_RWX;
3980+ create_mapping(&initmap);
3981+
3982+ /* when freeing initmem we will make this RX */
3983+ kernel.pfn = __phys_to_pfn(__pa(_stext));
3984+ kernel.virtual = (unsigned long)_stext;
3985+ kernel.length = __init_begin - _stext;
3986+ kernel.type = MT_MEMORY_RWX;
3987+ create_mapping(&kernel);
3988+
3989+ if (map.virtual < (unsigned long)_stext) {
3990+ map.length = (unsigned long)_stext - map.virtual;
3991+ map.type = MT_MEMORY_RWX;
3992+ create_mapping(&map);
3993+ }
3994+
3995+ map.pfn = __phys_to_pfn(__pa(_sdata));
3996+ map.virtual = (unsigned long)_sdata;
3997+ map.length = end - __pa(_sdata);
3998+ }
3999+#endif
4000+
4001+ map.type = MT_MEMORY_RW;
4002 create_mapping(&map);
4003 }
4004 }
4005diff --git a/arch/arm/mm/proc-v7-2level.S b/arch/arm/mm/proc-v7-2level.S
4006index 6d98c13..3cfb174 100644
4007--- a/arch/arm/mm/proc-v7-2level.S
4008+++ b/arch/arm/mm/proc-v7-2level.S
4009@@ -99,6 +99,9 @@ ENTRY(cpu_v7_set_pte_ext)
4010 tst r1, #L_PTE_XN
4011 orrne r3, r3, #PTE_EXT_XN
4012
4013+ tst r1, #L_PTE_PXN
4014+ orrne r3, r3, #PTE_EXT_PXN
4015+
4016 tst r1, #L_PTE_YOUNG
4017 tstne r1, #L_PTE_VALID
4018 #ifndef CONFIG_CPU_USE_DOMAINS
4019diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4020index a5bc92d..0bb4730 100644
4021--- a/arch/arm/plat-omap/sram.c
4022+++ b/arch/arm/plat-omap/sram.c
4023@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4024 * Looks like we need to preserve some bootloader code at the
4025 * beginning of SRAM for jumping to flash for reboot to work...
4026 */
4027+ pax_open_kernel();
4028 memset_io(omap_sram_base + omap_sram_skip, 0,
4029 omap_sram_size - omap_sram_skip);
4030+ pax_close_kernel();
4031 }
4032diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
4033index b76c065..b6e766b 100644
4034--- a/arch/arm/plat-orion/include/plat/addr-map.h
4035+++ b/arch/arm/plat-orion/include/plat/addr-map.h
4036@@ -27,7 +27,7 @@ struct orion_addr_map_cfg {
4037 value in bridge_virt_base */
4038 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
4039 const int win);
4040-};
4041+} __no_const;
4042
4043 /*
4044 * Information needed to setup one address mapping.
4045diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4046index f5144cd..71f6d1f 100644
4047--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4048+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4049@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4050 int (*started)(unsigned ch);
4051 int (*flush)(unsigned ch);
4052 int (*stop)(unsigned ch);
4053-};
4054+} __no_const;
4055
4056 extern void *samsung_dmadev_get_ops(void);
4057 extern void *s3c_dma_get_ops(void);
4058diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
4059index 0c3ba9f..95722b3 100644
4060--- a/arch/arm64/kernel/debug-monitors.c
4061+++ b/arch/arm64/kernel/debug-monitors.c
4062@@ -151,7 +151,7 @@ static int __cpuinit os_lock_notify(struct notifier_block *self,
4063 return NOTIFY_OK;
4064 }
4065
4066-static struct notifier_block __cpuinitdata os_lock_nb = {
4067+static struct notifier_block os_lock_nb = {
4068 .notifier_call = os_lock_notify,
4069 };
4070
4071diff --git a/arch/arm64/kernel/hw_breakpoint.c b/arch/arm64/kernel/hw_breakpoint.c
4072index 5ab825c..96aaec8 100644
4073--- a/arch/arm64/kernel/hw_breakpoint.c
4074+++ b/arch/arm64/kernel/hw_breakpoint.c
4075@@ -831,7 +831,7 @@ static int __cpuinit hw_breakpoint_reset_notify(struct notifier_block *self,
4076 return NOTIFY_OK;
4077 }
4078
4079-static struct notifier_block __cpuinitdata hw_breakpoint_reset_nb = {
4080+static struct notifier_block hw_breakpoint_reset_nb = {
4081 .notifier_call = hw_breakpoint_reset_notify,
4082 };
4083
4084diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4085index c3a58a1..78fbf54 100644
4086--- a/arch/avr32/include/asm/cache.h
4087+++ b/arch/avr32/include/asm/cache.h
4088@@ -1,8 +1,10 @@
4089 #ifndef __ASM_AVR32_CACHE_H
4090 #define __ASM_AVR32_CACHE_H
4091
4092+#include <linux/const.h>
4093+
4094 #define L1_CACHE_SHIFT 5
4095-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4096+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4097
4098 /*
4099 * Memory returned by kmalloc() may be used for DMA, so we must make
4100diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4101index e2c3287..6c4f98c 100644
4102--- a/arch/avr32/include/asm/elf.h
4103+++ b/arch/avr32/include/asm/elf.h
4104@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4105 the loader. We need to make sure that it is out of the way of the program
4106 that it will "exec", and that there is sufficient room for the brk. */
4107
4108-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4109+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4110
4111+#ifdef CONFIG_PAX_ASLR
4112+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4113+
4114+#define PAX_DELTA_MMAP_LEN 15
4115+#define PAX_DELTA_STACK_LEN 15
4116+#endif
4117
4118 /* This yields a mask that user programs can use to figure out what
4119 instruction set this CPU supports. This could be done in user space,
4120diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4121index 479330b..53717a8 100644
4122--- a/arch/avr32/include/asm/kmap_types.h
4123+++ b/arch/avr32/include/asm/kmap_types.h
4124@@ -2,9 +2,9 @@
4125 #define __ASM_AVR32_KMAP_TYPES_H
4126
4127 #ifdef CONFIG_DEBUG_HIGHMEM
4128-# define KM_TYPE_NR 29
4129+# define KM_TYPE_NR 30
4130 #else
4131-# define KM_TYPE_NR 14
4132+# define KM_TYPE_NR 15
4133 #endif
4134
4135 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4136diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4137index b2f2d2d..d1c85cb 100644
4138--- a/arch/avr32/mm/fault.c
4139+++ b/arch/avr32/mm/fault.c
4140@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4141
4142 int exception_trace = 1;
4143
4144+#ifdef CONFIG_PAX_PAGEEXEC
4145+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4146+{
4147+ unsigned long i;
4148+
4149+ printk(KERN_ERR "PAX: bytes at PC: ");
4150+ for (i = 0; i < 20; i++) {
4151+ unsigned char c;
4152+ if (get_user(c, (unsigned char *)pc+i))
4153+ printk(KERN_CONT "???????? ");
4154+ else
4155+ printk(KERN_CONT "%02x ", c);
4156+ }
4157+ printk("\n");
4158+}
4159+#endif
4160+
4161 /*
4162 * This routine handles page faults. It determines the address and the
4163 * problem, and then passes it off to one of the appropriate routines.
4164@@ -174,6 +191,16 @@ bad_area:
4165 up_read(&mm->mmap_sem);
4166
4167 if (user_mode(regs)) {
4168+
4169+#ifdef CONFIG_PAX_PAGEEXEC
4170+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4171+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4172+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4173+ do_group_exit(SIGKILL);
4174+ }
4175+ }
4176+#endif
4177+
4178 if (exception_trace && printk_ratelimit())
4179 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4180 "sp %08lx ecr %lu\n",
4181diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4182index 568885a..f8008df 100644
4183--- a/arch/blackfin/include/asm/cache.h
4184+++ b/arch/blackfin/include/asm/cache.h
4185@@ -7,6 +7,7 @@
4186 #ifndef __ARCH_BLACKFIN_CACHE_H
4187 #define __ARCH_BLACKFIN_CACHE_H
4188
4189+#include <linux/const.h>
4190 #include <linux/linkage.h> /* for asmlinkage */
4191
4192 /*
4193@@ -14,7 +15,7 @@
4194 * Blackfin loads 32 bytes for cache
4195 */
4196 #define L1_CACHE_SHIFT 5
4197-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4198+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4199 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4200
4201 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4202diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4203index aea2718..3639a60 100644
4204--- a/arch/cris/include/arch-v10/arch/cache.h
4205+++ b/arch/cris/include/arch-v10/arch/cache.h
4206@@ -1,8 +1,9 @@
4207 #ifndef _ASM_ARCH_CACHE_H
4208 #define _ASM_ARCH_CACHE_H
4209
4210+#include <linux/const.h>
4211 /* Etrax 100LX have 32-byte cache-lines. */
4212-#define L1_CACHE_BYTES 32
4213 #define L1_CACHE_SHIFT 5
4214+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4215
4216 #endif /* _ASM_ARCH_CACHE_H */
4217diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4218index 7caf25d..ee65ac5 100644
4219--- a/arch/cris/include/arch-v32/arch/cache.h
4220+++ b/arch/cris/include/arch-v32/arch/cache.h
4221@@ -1,11 +1,12 @@
4222 #ifndef _ASM_CRIS_ARCH_CACHE_H
4223 #define _ASM_CRIS_ARCH_CACHE_H
4224
4225+#include <linux/const.h>
4226 #include <arch/hwregs/dma.h>
4227
4228 /* A cache-line is 32 bytes. */
4229-#define L1_CACHE_BYTES 32
4230 #define L1_CACHE_SHIFT 5
4231+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4232
4233 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4234
4235diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4236index b86329d..6709906 100644
4237--- a/arch/frv/include/asm/atomic.h
4238+++ b/arch/frv/include/asm/atomic.h
4239@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4240 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4241 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4242
4243+#define atomic64_read_unchecked(v) atomic64_read(v)
4244+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4245+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4246+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4247+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4248+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4249+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4250+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4251+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4252+
4253 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4254 {
4255 int c, old;
4256diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4257index 2797163..c2a401d 100644
4258--- a/arch/frv/include/asm/cache.h
4259+++ b/arch/frv/include/asm/cache.h
4260@@ -12,10 +12,11 @@
4261 #ifndef __ASM_CACHE_H
4262 #define __ASM_CACHE_H
4263
4264+#include <linux/const.h>
4265
4266 /* bytes per L1 cache line */
4267 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4268-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4269+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4270
4271 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4272 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4273diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4274index 43901f2..0d8b865 100644
4275--- a/arch/frv/include/asm/kmap_types.h
4276+++ b/arch/frv/include/asm/kmap_types.h
4277@@ -2,6 +2,6 @@
4278 #ifndef _ASM_KMAP_TYPES_H
4279 #define _ASM_KMAP_TYPES_H
4280
4281-#define KM_TYPE_NR 17
4282+#define KM_TYPE_NR 18
4283
4284 #endif
4285diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4286index 385fd30..3aaf4fe 100644
4287--- a/arch/frv/mm/elf-fdpic.c
4288+++ b/arch/frv/mm/elf-fdpic.c
4289@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4290 {
4291 struct vm_area_struct *vma;
4292 unsigned long limit;
4293+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4294
4295 if (len > TASK_SIZE)
4296 return -ENOMEM;
4297@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4298 if (addr) {
4299 addr = PAGE_ALIGN(addr);
4300 vma = find_vma(current->mm, addr);
4301- if (TASK_SIZE - len >= addr &&
4302- (!vma || addr + len <= vma->vm_start))
4303+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4304 goto success;
4305 }
4306
4307@@ -89,7 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4308 for (; vma; vma = vma->vm_next) {
4309 if (addr > limit)
4310 break;
4311- if (addr + len <= vma->vm_start)
4312+ if (check_heap_stack_gap(vma, addr, len, offset))
4313 goto success;
4314 addr = vma->vm_end;
4315 }
4316@@ -104,7 +104,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4317 for (; vma; vma = vma->vm_next) {
4318 if (addr > limit)
4319 break;
4320- if (addr + len <= vma->vm_start)
4321+ if (check_heap_stack_gap(vma, addr, len, offset))
4322 goto success;
4323 addr = vma->vm_end;
4324 }
4325diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4326index f4ca594..adc72fd6 100644
4327--- a/arch/hexagon/include/asm/cache.h
4328+++ b/arch/hexagon/include/asm/cache.h
4329@@ -21,9 +21,11 @@
4330 #ifndef __ASM_CACHE_H
4331 #define __ASM_CACHE_H
4332
4333+#include <linux/const.h>
4334+
4335 /* Bytes per L1 cache line */
4336-#define L1_CACHE_SHIFT (5)
4337-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4338+#define L1_CACHE_SHIFT 5
4339+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4340
4341 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4342 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4343diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4344index 6e6fe18..a6ae668 100644
4345--- a/arch/ia64/include/asm/atomic.h
4346+++ b/arch/ia64/include/asm/atomic.h
4347@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4348 #define atomic64_inc(v) atomic64_add(1, (v))
4349 #define atomic64_dec(v) atomic64_sub(1, (v))
4350
4351+#define atomic64_read_unchecked(v) atomic64_read(v)
4352+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4353+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4354+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4355+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4356+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4357+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4358+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4359+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4360+
4361 /* Atomic operations are already serializing */
4362 #define smp_mb__before_atomic_dec() barrier()
4363 #define smp_mb__after_atomic_dec() barrier()
4364diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4365index 988254a..e1ee885 100644
4366--- a/arch/ia64/include/asm/cache.h
4367+++ b/arch/ia64/include/asm/cache.h
4368@@ -1,6 +1,7 @@
4369 #ifndef _ASM_IA64_CACHE_H
4370 #define _ASM_IA64_CACHE_H
4371
4372+#include <linux/const.h>
4373
4374 /*
4375 * Copyright (C) 1998-2000 Hewlett-Packard Co
4376@@ -9,7 +10,7 @@
4377
4378 /* Bytes per L1 (data) cache line. */
4379 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4380-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4381+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4382
4383 #ifdef CONFIG_SMP
4384 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4385diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4386index b5298eb..67c6e62 100644
4387--- a/arch/ia64/include/asm/elf.h
4388+++ b/arch/ia64/include/asm/elf.h
4389@@ -42,6 +42,13 @@
4390 */
4391 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4392
4393+#ifdef CONFIG_PAX_ASLR
4394+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4395+
4396+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4397+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4398+#endif
4399+
4400 #define PT_IA_64_UNWIND 0x70000001
4401
4402 /* IA-64 relocations: */
4403diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4404index 96a8d92..617a1cf 100644
4405--- a/arch/ia64/include/asm/pgalloc.h
4406+++ b/arch/ia64/include/asm/pgalloc.h
4407@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4408 pgd_val(*pgd_entry) = __pa(pud);
4409 }
4410
4411+static inline void
4412+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4413+{
4414+ pgd_populate(mm, pgd_entry, pud);
4415+}
4416+
4417 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4418 {
4419 return quicklist_alloc(0, GFP_KERNEL, NULL);
4420@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4421 pud_val(*pud_entry) = __pa(pmd);
4422 }
4423
4424+static inline void
4425+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4426+{
4427+ pud_populate(mm, pud_entry, pmd);
4428+}
4429+
4430 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4431 {
4432 return quicklist_alloc(0, GFP_KERNEL, NULL);
4433diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4434index 815810c..d60bd4c 100644
4435--- a/arch/ia64/include/asm/pgtable.h
4436+++ b/arch/ia64/include/asm/pgtable.h
4437@@ -12,7 +12,7 @@
4438 * David Mosberger-Tang <davidm@hpl.hp.com>
4439 */
4440
4441-
4442+#include <linux/const.h>
4443 #include <asm/mman.h>
4444 #include <asm/page.h>
4445 #include <asm/processor.h>
4446@@ -142,6 +142,17 @@
4447 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4448 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4449 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4450+
4451+#ifdef CONFIG_PAX_PAGEEXEC
4452+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4453+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4454+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4455+#else
4456+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4457+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4458+# define PAGE_COPY_NOEXEC PAGE_COPY
4459+#endif
4460+
4461 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4462 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4463 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4464diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4465index 54ff557..70c88b7 100644
4466--- a/arch/ia64/include/asm/spinlock.h
4467+++ b/arch/ia64/include/asm/spinlock.h
4468@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4469 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4470
4471 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4472- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4473+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4474 }
4475
4476 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4477diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4478index 449c8c0..50cdf87 100644
4479--- a/arch/ia64/include/asm/uaccess.h
4480+++ b/arch/ia64/include/asm/uaccess.h
4481@@ -42,6 +42,8 @@
4482 #include <asm/pgtable.h>
4483 #include <asm/io.h>
4484
4485+extern void check_object_size(const void *ptr, unsigned long n, bool to);
4486+
4487 /*
4488 * For historical reasons, the following macros are grossly misnamed:
4489 */
4490@@ -240,12 +242,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4491 static inline unsigned long
4492 __copy_to_user (void __user *to, const void *from, unsigned long count)
4493 {
4494+ if (count > INT_MAX)
4495+ return count;
4496+
4497+ if (!__builtin_constant_p(count))
4498+ check_object_size(from, count, true);
4499+
4500 return __copy_user(to, (__force void __user *) from, count);
4501 }
4502
4503 static inline unsigned long
4504 __copy_from_user (void *to, const void __user *from, unsigned long count)
4505 {
4506+ if (count > INT_MAX)
4507+ return count;
4508+
4509+ if (!__builtin_constant_p(count))
4510+ check_object_size(to, count, false);
4511+
4512 return __copy_user((__force void __user *) to, from, count);
4513 }
4514
4515@@ -255,10 +269,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4516 ({ \
4517 void __user *__cu_to = (to); \
4518 const void *__cu_from = (from); \
4519- long __cu_len = (n); \
4520+ unsigned long __cu_len = (n); \
4521 \
4522- if (__access_ok(__cu_to, __cu_len, get_fs())) \
4523+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
4524+ if (!__builtin_constant_p(n)) \
4525+ check_object_size(__cu_from, __cu_len, true); \
4526 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
4527+ } \
4528 __cu_len; \
4529 })
4530
4531@@ -266,11 +283,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4532 ({ \
4533 void *__cu_to = (to); \
4534 const void __user *__cu_from = (from); \
4535- long __cu_len = (n); \
4536+ unsigned long __cu_len = (n); \
4537 \
4538 __chk_user_ptr(__cu_from); \
4539- if (__access_ok(__cu_from, __cu_len, get_fs())) \
4540+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
4541+ if (!__builtin_constant_p(n)) \
4542+ check_object_size(__cu_to, __cu_len, false); \
4543 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
4544+ } \
4545 __cu_len; \
4546 })
4547
4548diff --git a/arch/ia64/kernel/err_inject.c b/arch/ia64/kernel/err_inject.c
4549index 2d67317..07d8bfa 100644
4550--- a/arch/ia64/kernel/err_inject.c
4551+++ b/arch/ia64/kernel/err_inject.c
4552@@ -256,7 +256,7 @@ static int __cpuinit err_inject_cpu_callback(struct notifier_block *nfb,
4553 return NOTIFY_OK;
4554 }
4555
4556-static struct notifier_block __cpuinitdata err_inject_cpu_notifier =
4557+static struct notifier_block err_inject_cpu_notifier =
4558 {
4559 .notifier_call = err_inject_cpu_callback,
4560 };
4561diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
4562index 65bf9cd..794f06b 100644
4563--- a/arch/ia64/kernel/mca.c
4564+++ b/arch/ia64/kernel/mca.c
4565@@ -1922,7 +1922,7 @@ static int __cpuinit mca_cpu_callback(struct notifier_block *nfb,
4566 return NOTIFY_OK;
4567 }
4568
4569-static struct notifier_block mca_cpu_notifier __cpuinitdata = {
4570+static struct notifier_block mca_cpu_notifier = {
4571 .notifier_call = mca_cpu_callback
4572 };
4573
4574diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
4575index 24603be..948052d 100644
4576--- a/arch/ia64/kernel/module.c
4577+++ b/arch/ia64/kernel/module.c
4578@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
4579 void
4580 module_free (struct module *mod, void *module_region)
4581 {
4582- if (mod && mod->arch.init_unw_table &&
4583- module_region == mod->module_init) {
4584+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
4585 unw_remove_unwind_table(mod->arch.init_unw_table);
4586 mod->arch.init_unw_table = NULL;
4587 }
4588@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
4589 }
4590
4591 static inline int
4592+in_init_rx (const struct module *mod, uint64_t addr)
4593+{
4594+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
4595+}
4596+
4597+static inline int
4598+in_init_rw (const struct module *mod, uint64_t addr)
4599+{
4600+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
4601+}
4602+
4603+static inline int
4604 in_init (const struct module *mod, uint64_t addr)
4605 {
4606- return addr - (uint64_t) mod->module_init < mod->init_size;
4607+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
4608+}
4609+
4610+static inline int
4611+in_core_rx (const struct module *mod, uint64_t addr)
4612+{
4613+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
4614+}
4615+
4616+static inline int
4617+in_core_rw (const struct module *mod, uint64_t addr)
4618+{
4619+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
4620 }
4621
4622 static inline int
4623 in_core (const struct module *mod, uint64_t addr)
4624 {
4625- return addr - (uint64_t) mod->module_core < mod->core_size;
4626+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
4627 }
4628
4629 static inline int
4630@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
4631 break;
4632
4633 case RV_BDREL:
4634- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
4635+ if (in_init_rx(mod, val))
4636+ val -= (uint64_t) mod->module_init_rx;
4637+ else if (in_init_rw(mod, val))
4638+ val -= (uint64_t) mod->module_init_rw;
4639+ else if (in_core_rx(mod, val))
4640+ val -= (uint64_t) mod->module_core_rx;
4641+ else if (in_core_rw(mod, val))
4642+ val -= (uint64_t) mod->module_core_rw;
4643 break;
4644
4645 case RV_LTV:
4646@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
4647 * addresses have been selected...
4648 */
4649 uint64_t gp;
4650- if (mod->core_size > MAX_LTOFF)
4651+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
4652 /*
4653 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
4654 * at the end of the module.
4655 */
4656- gp = mod->core_size - MAX_LTOFF / 2;
4657+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
4658 else
4659- gp = mod->core_size / 2;
4660- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
4661+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
4662+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
4663 mod->arch.gp = gp;
4664 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
4665 }
4666diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
4667index 77597e5..6f28f3f 100644
4668--- a/arch/ia64/kernel/palinfo.c
4669+++ b/arch/ia64/kernel/palinfo.c
4670@@ -1045,7 +1045,7 @@ static int __cpuinit palinfo_cpu_callback(struct notifier_block *nfb,
4671 return NOTIFY_OK;
4672 }
4673
4674-static struct notifier_block __refdata palinfo_cpu_notifier =
4675+static struct notifier_block palinfo_cpu_notifier =
4676 {
4677 .notifier_call = palinfo_cpu_callback,
4678 .priority = 0,
4679diff --git a/arch/ia64/kernel/salinfo.c b/arch/ia64/kernel/salinfo.c
4680index 79802e5..1a89ec5 100644
4681--- a/arch/ia64/kernel/salinfo.c
4682+++ b/arch/ia64/kernel/salinfo.c
4683@@ -616,7 +616,7 @@ salinfo_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu
4684 return NOTIFY_OK;
4685 }
4686
4687-static struct notifier_block salinfo_cpu_notifier __cpuinitdata =
4688+static struct notifier_block salinfo_cpu_notifier =
4689 {
4690 .notifier_call = salinfo_cpu_callback,
4691 .priority = 0,
4692diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
4693index d9439ef..d0cac6b 100644
4694--- a/arch/ia64/kernel/sys_ia64.c
4695+++ b/arch/ia64/kernel/sys_ia64.c
4696@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4697 unsigned long start_addr, align_mask = PAGE_SIZE - 1;
4698 struct mm_struct *mm = current->mm;
4699 struct vm_area_struct *vma;
4700+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4701
4702 if (len > RGN_MAP_LIMIT)
4703 return -ENOMEM;
4704@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4705 if (REGION_NUMBER(addr) == RGN_HPAGE)
4706 addr = 0;
4707 #endif
4708+
4709+#ifdef CONFIG_PAX_RANDMMAP
4710+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4711+ addr = mm->free_area_cache;
4712+ else
4713+#endif
4714+
4715 if (!addr)
4716 addr = mm->free_area_cache;
4717
4718@@ -61,14 +69,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4719 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
4720 /* At this point: (!vma || addr < vma->vm_end). */
4721 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
4722- if (start_addr != TASK_UNMAPPED_BASE) {
4723+ if (start_addr != mm->mmap_base) {
4724 /* Start a new search --- just in case we missed some holes. */
4725- addr = TASK_UNMAPPED_BASE;
4726+ addr = mm->mmap_base;
4727 goto full_search;
4728 }
4729 return -ENOMEM;
4730 }
4731- if (!vma || addr + len <= vma->vm_start) {
4732+ if (check_heap_stack_gap(vma, addr, len, offset)) {
4733 /* Remember the address where we stopped this search: */
4734 mm->free_area_cache = addr + len;
4735 return addr;
4736diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
4737index dc00b2c..cce53c2 100644
4738--- a/arch/ia64/kernel/topology.c
4739+++ b/arch/ia64/kernel/topology.c
4740@@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
4741 return NOTIFY_OK;
4742 }
4743
4744-static struct notifier_block __cpuinitdata cache_cpu_notifier =
4745+static struct notifier_block cache_cpu_notifier =
4746 {
4747 .notifier_call = cache_cpu_callback
4748 };
4749diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
4750index 0ccb28f..8992469 100644
4751--- a/arch/ia64/kernel/vmlinux.lds.S
4752+++ b/arch/ia64/kernel/vmlinux.lds.S
4753@@ -198,7 +198,7 @@ SECTIONS {
4754 /* Per-cpu data: */
4755 . = ALIGN(PERCPU_PAGE_SIZE);
4756 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
4757- __phys_per_cpu_start = __per_cpu_load;
4758+ __phys_per_cpu_start = per_cpu_load;
4759 /*
4760 * ensure percpu data fits
4761 * into percpu page size
4762diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
4763index 6cf0341..d352594 100644
4764--- a/arch/ia64/mm/fault.c
4765+++ b/arch/ia64/mm/fault.c
4766@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
4767 return pte_present(pte);
4768 }
4769
4770+#ifdef CONFIG_PAX_PAGEEXEC
4771+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4772+{
4773+ unsigned long i;
4774+
4775+ printk(KERN_ERR "PAX: bytes at PC: ");
4776+ for (i = 0; i < 8; i++) {
4777+ unsigned int c;
4778+ if (get_user(c, (unsigned int *)pc+i))
4779+ printk(KERN_CONT "???????? ");
4780+ else
4781+ printk(KERN_CONT "%08x ", c);
4782+ }
4783+ printk("\n");
4784+}
4785+#endif
4786+
4787 # define VM_READ_BIT 0
4788 # define VM_WRITE_BIT 1
4789 # define VM_EXEC_BIT 2
4790@@ -149,8 +166,21 @@ retry:
4791 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
4792 goto bad_area;
4793
4794- if ((vma->vm_flags & mask) != mask)
4795+ if ((vma->vm_flags & mask) != mask) {
4796+
4797+#ifdef CONFIG_PAX_PAGEEXEC
4798+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
4799+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
4800+ goto bad_area;
4801+
4802+ up_read(&mm->mmap_sem);
4803+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
4804+ do_group_exit(SIGKILL);
4805+ }
4806+#endif
4807+
4808 goto bad_area;
4809+ }
4810
4811 /*
4812 * If for any reason at all we couldn't handle the fault, make
4813diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
4814index 5ca674b..127c3cb 100644
4815--- a/arch/ia64/mm/hugetlbpage.c
4816+++ b/arch/ia64/mm/hugetlbpage.c
4817@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
4818 unsigned long pgoff, unsigned long flags)
4819 {
4820 struct vm_area_struct *vmm;
4821+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
4822
4823 if (len > RGN_MAP_LIMIT)
4824 return -ENOMEM;
4825@@ -171,7 +172,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
4826 /* At this point: (!vmm || addr < vmm->vm_end). */
4827 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
4828 return -ENOMEM;
4829- if (!vmm || (addr + len) <= vmm->vm_start)
4830+ if (check_heap_stack_gap(vmm, addr, len, offset))
4831 return addr;
4832 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
4833 }
4834diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
4835index b755ea9..b9a969e 100644
4836--- a/arch/ia64/mm/init.c
4837+++ b/arch/ia64/mm/init.c
4838@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
4839 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
4840 vma->vm_end = vma->vm_start + PAGE_SIZE;
4841 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
4842+
4843+#ifdef CONFIG_PAX_PAGEEXEC
4844+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
4845+ vma->vm_flags &= ~VM_EXEC;
4846+
4847+#ifdef CONFIG_PAX_MPROTECT
4848+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
4849+ vma->vm_flags &= ~VM_MAYEXEC;
4850+#endif
4851+
4852+ }
4853+#endif
4854+
4855 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
4856 down_write(&current->mm->mmap_sem);
4857 if (insert_vm_struct(current->mm, vma)) {
4858diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
4859index 40b3ee9..8c2c112 100644
4860--- a/arch/m32r/include/asm/cache.h
4861+++ b/arch/m32r/include/asm/cache.h
4862@@ -1,8 +1,10 @@
4863 #ifndef _ASM_M32R_CACHE_H
4864 #define _ASM_M32R_CACHE_H
4865
4866+#include <linux/const.h>
4867+
4868 /* L1 cache line size */
4869 #define L1_CACHE_SHIFT 4
4870-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4871+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4872
4873 #endif /* _ASM_M32R_CACHE_H */
4874diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
4875index 82abd15..d95ae5d 100644
4876--- a/arch/m32r/lib/usercopy.c
4877+++ b/arch/m32r/lib/usercopy.c
4878@@ -14,6 +14,9 @@
4879 unsigned long
4880 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
4881 {
4882+ if ((long)n < 0)
4883+ return n;
4884+
4885 prefetch(from);
4886 if (access_ok(VERIFY_WRITE, to, n))
4887 __copy_user(to,from,n);
4888@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
4889 unsigned long
4890 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
4891 {
4892+ if ((long)n < 0)
4893+ return n;
4894+
4895 prefetchw(to);
4896 if (access_ok(VERIFY_READ, from, n))
4897 __copy_user_zeroing(to,from,n);
4898diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
4899index 0395c51..5f26031 100644
4900--- a/arch/m68k/include/asm/cache.h
4901+++ b/arch/m68k/include/asm/cache.h
4902@@ -4,9 +4,11 @@
4903 #ifndef __ARCH_M68K_CACHE_H
4904 #define __ARCH_M68K_CACHE_H
4905
4906+#include <linux/const.h>
4907+
4908 /* bytes per L1 cache line */
4909 #define L1_CACHE_SHIFT 4
4910-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
4911+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4912
4913 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4914
4915diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
4916index 4efe96a..60e8699 100644
4917--- a/arch/microblaze/include/asm/cache.h
4918+++ b/arch/microblaze/include/asm/cache.h
4919@@ -13,11 +13,12 @@
4920 #ifndef _ASM_MICROBLAZE_CACHE_H
4921 #define _ASM_MICROBLAZE_CACHE_H
4922
4923+#include <linux/const.h>
4924 #include <asm/registers.h>
4925
4926 #define L1_CACHE_SHIFT 5
4927 /* word-granular cache in microblaze */
4928-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4929+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4930
4931 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4932
4933diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
4934index 01cc6ba..bcb7a5d 100644
4935--- a/arch/mips/include/asm/atomic.h
4936+++ b/arch/mips/include/asm/atomic.h
4937@@ -21,6 +21,10 @@
4938 #include <asm/cmpxchg.h>
4939 #include <asm/war.h>
4940
4941+#ifdef CONFIG_GENERIC_ATOMIC64
4942+#include <asm-generic/atomic64.h>
4943+#endif
4944+
4945 #define ATOMIC_INIT(i) { (i) }
4946
4947 /*
4948@@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
4949 */
4950 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
4951
4952+#define atomic64_read_unchecked(v) atomic64_read(v)
4953+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4954+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4955+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4956+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4957+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4958+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4959+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4960+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4961+
4962 #endif /* CONFIG_64BIT */
4963
4964 /*
4965diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
4966index b4db69f..8f3b093 100644
4967--- a/arch/mips/include/asm/cache.h
4968+++ b/arch/mips/include/asm/cache.h
4969@@ -9,10 +9,11 @@
4970 #ifndef _ASM_CACHE_H
4971 #define _ASM_CACHE_H
4972
4973+#include <linux/const.h>
4974 #include <kmalloc.h>
4975
4976 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
4977-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4978+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4979
4980 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4981 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4982diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
4983index 455c0ac..ad65fbe 100644
4984--- a/arch/mips/include/asm/elf.h
4985+++ b/arch/mips/include/asm/elf.h
4986@@ -372,13 +372,16 @@ extern const char *__elf_platform;
4987 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4988 #endif
4989
4990+#ifdef CONFIG_PAX_ASLR
4991+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
4992+
4993+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
4994+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
4995+#endif
4996+
4997 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4998 struct linux_binprm;
4999 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
5000 int uses_interp);
5001
5002-struct mm_struct;
5003-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5004-#define arch_randomize_brk arch_randomize_brk
5005-
5006 #endif /* _ASM_ELF_H */
5007diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
5008index c1f6afa..38cc6e9 100644
5009--- a/arch/mips/include/asm/exec.h
5010+++ b/arch/mips/include/asm/exec.h
5011@@ -12,6 +12,6 @@
5012 #ifndef _ASM_EXEC_H
5013 #define _ASM_EXEC_H
5014
5015-extern unsigned long arch_align_stack(unsigned long sp);
5016+#define arch_align_stack(x) ((x) & ~0xfUL)
5017
5018 #endif /* _ASM_EXEC_H */
5019diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
5020index dbaec94..6a14935 100644
5021--- a/arch/mips/include/asm/page.h
5022+++ b/arch/mips/include/asm/page.h
5023@@ -96,7 +96,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
5024 #ifdef CONFIG_CPU_MIPS32
5025 typedef struct { unsigned long pte_low, pte_high; } pte_t;
5026 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
5027- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
5028+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
5029 #else
5030 typedef struct { unsigned long long pte; } pte_t;
5031 #define pte_val(x) ((x).pte)
5032diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
5033index 881d18b..cea38bc 100644
5034--- a/arch/mips/include/asm/pgalloc.h
5035+++ b/arch/mips/include/asm/pgalloc.h
5036@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5037 {
5038 set_pud(pud, __pud((unsigned long)pmd));
5039 }
5040+
5041+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5042+{
5043+ pud_populate(mm, pud, pmd);
5044+}
5045 #endif
5046
5047 /*
5048diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
5049index b2050b9..d71bb1b 100644
5050--- a/arch/mips/include/asm/thread_info.h
5051+++ b/arch/mips/include/asm/thread_info.h
5052@@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
5053 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
5054 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
5055 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
5056+/* li takes a 32bit immediate */
5057+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
5058 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
5059
5060 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
5061@@ -126,15 +128,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
5062 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
5063 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
5064 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
5065+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5066+
5067+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5068
5069 /* work to do in syscall_trace_leave() */
5070-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
5071+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5072
5073 /* work to do on interrupt/exception return */
5074 #define _TIF_WORK_MASK \
5075 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
5076 /* work to do on any return to u-space */
5077-#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
5078+#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
5079
5080 #endif /* __KERNEL__ */
5081
5082diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
5083index 9fdd8bc..4bd7f1a 100644
5084--- a/arch/mips/kernel/binfmt_elfn32.c
5085+++ b/arch/mips/kernel/binfmt_elfn32.c
5086@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5087 #undef ELF_ET_DYN_BASE
5088 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5089
5090+#ifdef CONFIG_PAX_ASLR
5091+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5092+
5093+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5094+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5095+#endif
5096+
5097 #include <asm/processor.h>
5098 #include <linux/module.h>
5099 #include <linux/elfcore.h>
5100diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
5101index ff44823..97f8906 100644
5102--- a/arch/mips/kernel/binfmt_elfo32.c
5103+++ b/arch/mips/kernel/binfmt_elfo32.c
5104@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5105 #undef ELF_ET_DYN_BASE
5106 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5107
5108+#ifdef CONFIG_PAX_ASLR
5109+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5110+
5111+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5112+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5113+#endif
5114+
5115 #include <asm/processor.h>
5116
5117 /*
5118diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
5119index a11c6f9..be5e164 100644
5120--- a/arch/mips/kernel/process.c
5121+++ b/arch/mips/kernel/process.c
5122@@ -460,15 +460,3 @@ unsigned long get_wchan(struct task_struct *task)
5123 out:
5124 return pc;
5125 }
5126-
5127-/*
5128- * Don't forget that the stack pointer must be aligned on a 8 bytes
5129- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
5130- */
5131-unsigned long arch_align_stack(unsigned long sp)
5132-{
5133- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5134- sp -= get_random_int() & ~PAGE_MASK;
5135-
5136- return sp & ALMASK;
5137-}
5138diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
5139index 4812c6d..2069554 100644
5140--- a/arch/mips/kernel/ptrace.c
5141+++ b/arch/mips/kernel/ptrace.c
5142@@ -528,6 +528,10 @@ static inline int audit_arch(void)
5143 return arch;
5144 }
5145
5146+#ifdef CONFIG_GRKERNSEC_SETXID
5147+extern void gr_delayed_cred_worker(void);
5148+#endif
5149+
5150 /*
5151 * Notification of system call entry/exit
5152 * - triggered by current->work.syscall_trace
5153@@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
5154 /* do the secure computing check first */
5155 secure_computing_strict(regs->regs[2]);
5156
5157+#ifdef CONFIG_GRKERNSEC_SETXID
5158+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5159+ gr_delayed_cred_worker();
5160+#endif
5161+
5162 if (!(current->ptrace & PT_PTRACED))
5163 goto out;
5164
5165diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
5166index d20a4bc..7096ae5 100644
5167--- a/arch/mips/kernel/scall32-o32.S
5168+++ b/arch/mips/kernel/scall32-o32.S
5169@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5170
5171 stack_done:
5172 lw t0, TI_FLAGS($28) # syscall tracing enabled?
5173- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5174+ li t1, _TIF_SYSCALL_WORK
5175 and t0, t1
5176 bnez t0, syscall_trace_entry # -> yes
5177
5178diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
5179index b64f642..0fe6eab 100644
5180--- a/arch/mips/kernel/scall64-64.S
5181+++ b/arch/mips/kernel/scall64-64.S
5182@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
5183
5184 sd a3, PT_R26(sp) # save a3 for syscall restarting
5185
5186- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5187+ li t1, _TIF_SYSCALL_WORK
5188 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5189 and t0, t1, t0
5190 bnez t0, syscall_trace_entry
5191diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
5192index c29ac19..c592d05 100644
5193--- a/arch/mips/kernel/scall64-n32.S
5194+++ b/arch/mips/kernel/scall64-n32.S
5195@@ -47,7 +47,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
5196
5197 sd a3, PT_R26(sp) # save a3 for syscall restarting
5198
5199- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5200+ li t1, _TIF_SYSCALL_WORK
5201 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5202 and t0, t1, t0
5203 bnez t0, n32_syscall_trace_entry
5204diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
5205index cf3e75e..72e93fe 100644
5206--- a/arch/mips/kernel/scall64-o32.S
5207+++ b/arch/mips/kernel/scall64-o32.S
5208@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5209 PTR 4b, bad_stack
5210 .previous
5211
5212- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5213+ li t1, _TIF_SYSCALL_WORK
5214 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5215 and t0, t1, t0
5216 bnez t0, trace_a_syscall
5217diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
5218index ddcec1e..c7f983e 100644
5219--- a/arch/mips/mm/fault.c
5220+++ b/arch/mips/mm/fault.c
5221@@ -27,6 +27,23 @@
5222 #include <asm/highmem.h> /* For VMALLOC_END */
5223 #include <linux/kdebug.h>
5224
5225+#ifdef CONFIG_PAX_PAGEEXEC
5226+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5227+{
5228+ unsigned long i;
5229+
5230+ printk(KERN_ERR "PAX: bytes at PC: ");
5231+ for (i = 0; i < 5; i++) {
5232+ unsigned int c;
5233+ if (get_user(c, (unsigned int *)pc+i))
5234+ printk(KERN_CONT "???????? ");
5235+ else
5236+ printk(KERN_CONT "%08x ", c);
5237+ }
5238+ printk("\n");
5239+}
5240+#endif
5241+
5242 /*
5243 * This routine handles page faults. It determines the address,
5244 * and the problem, and then passes it off to one of the appropriate
5245diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
5246index 7e5fe27..479a219 100644
5247--- a/arch/mips/mm/mmap.c
5248+++ b/arch/mips/mm/mmap.c
5249@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5250 struct vm_area_struct *vma;
5251 unsigned long addr = addr0;
5252 int do_color_align;
5253+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5254 struct vm_unmapped_area_info info;
5255
5256 if (unlikely(len > TASK_SIZE))
5257@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5258 do_color_align = 1;
5259
5260 /* requesting a specific address */
5261+
5262+#ifdef CONFIG_PAX_RANDMMAP
5263+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
5264+#endif
5265+
5266 if (addr) {
5267 if (do_color_align)
5268 addr = COLOUR_ALIGN(addr, pgoff);
5269@@ -91,8 +97,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5270 addr = PAGE_ALIGN(addr);
5271
5272 vma = find_vma(mm, addr);
5273- if (TASK_SIZE - len >= addr &&
5274- (!vma || addr + len <= vma->vm_start))
5275+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
5276 return addr;
5277 }
5278
5279@@ -146,6 +151,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5280 {
5281 unsigned long random_factor = 0UL;
5282
5283+#ifdef CONFIG_PAX_RANDMMAP
5284+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5285+#endif
5286+
5287 if (current->flags & PF_RANDOMIZE) {
5288 random_factor = get_random_int();
5289 random_factor = random_factor << PAGE_SHIFT;
5290@@ -157,42 +166,27 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5291
5292 if (mmap_is_legacy()) {
5293 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5294+
5295+#ifdef CONFIG_PAX_RANDMMAP
5296+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5297+ mm->mmap_base += mm->delta_mmap;
5298+#endif
5299+
5300 mm->get_unmapped_area = arch_get_unmapped_area;
5301 mm->unmap_area = arch_unmap_area;
5302 } else {
5303 mm->mmap_base = mmap_base(random_factor);
5304+
5305+#ifdef CONFIG_PAX_RANDMMAP
5306+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5307+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5308+#endif
5309+
5310 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5311 mm->unmap_area = arch_unmap_area_topdown;
5312 }
5313 }
5314
5315-static inline unsigned long brk_rnd(void)
5316-{
5317- unsigned long rnd = get_random_int();
5318-
5319- rnd = rnd << PAGE_SHIFT;
5320- /* 8MB for 32bit, 256MB for 64bit */
5321- if (TASK_IS_32BIT_ADDR)
5322- rnd = rnd & 0x7ffffful;
5323- else
5324- rnd = rnd & 0xffffffful;
5325-
5326- return rnd;
5327-}
5328-
5329-unsigned long arch_randomize_brk(struct mm_struct *mm)
5330-{
5331- unsigned long base = mm->brk;
5332- unsigned long ret;
5333-
5334- ret = PAGE_ALIGN(base + brk_rnd());
5335-
5336- if (ret < mm->brk)
5337- return mm->brk;
5338-
5339- return ret;
5340-}
5341-
5342 int __virt_addr_valid(const volatile void *kaddr)
5343 {
5344 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
5345diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5346index 967d144..db12197 100644
5347--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
5348+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5349@@ -11,12 +11,14 @@
5350 #ifndef _ASM_PROC_CACHE_H
5351 #define _ASM_PROC_CACHE_H
5352
5353+#include <linux/const.h>
5354+
5355 /* L1 cache */
5356
5357 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5358 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
5359-#define L1_CACHE_BYTES 16 /* bytes per entry */
5360 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
5361+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5362 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
5363
5364 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5365diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5366index bcb5df2..84fabd2 100644
5367--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5368+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5369@@ -16,13 +16,15 @@
5370 #ifndef _ASM_PROC_CACHE_H
5371 #define _ASM_PROC_CACHE_H
5372
5373+#include <linux/const.h>
5374+
5375 /*
5376 * L1 cache
5377 */
5378 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5379 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
5380-#define L1_CACHE_BYTES 32 /* bytes per entry */
5381 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
5382+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5383 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
5384
5385 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5386diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
5387index 4ce7a01..449202a 100644
5388--- a/arch/openrisc/include/asm/cache.h
5389+++ b/arch/openrisc/include/asm/cache.h
5390@@ -19,11 +19,13 @@
5391 #ifndef __ASM_OPENRISC_CACHE_H
5392 #define __ASM_OPENRISC_CACHE_H
5393
5394+#include <linux/const.h>
5395+
5396 /* FIXME: How can we replace these with values from the CPU...
5397 * they shouldn't be hard-coded!
5398 */
5399
5400-#define L1_CACHE_BYTES 16
5401 #define L1_CACHE_SHIFT 4
5402+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5403
5404 #endif /* __ASM_OPENRISC_CACHE_H */
5405diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
5406index af9cf30..2aae9b2 100644
5407--- a/arch/parisc/include/asm/atomic.h
5408+++ b/arch/parisc/include/asm/atomic.h
5409@@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5410
5411 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5412
5413+#define atomic64_read_unchecked(v) atomic64_read(v)
5414+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5415+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5416+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5417+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5418+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5419+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5420+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5421+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5422+
5423 #endif /* !CONFIG_64BIT */
5424
5425
5426diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
5427index 47f11c7..3420df2 100644
5428--- a/arch/parisc/include/asm/cache.h
5429+++ b/arch/parisc/include/asm/cache.h
5430@@ -5,6 +5,7 @@
5431 #ifndef __ARCH_PARISC_CACHE_H
5432 #define __ARCH_PARISC_CACHE_H
5433
5434+#include <linux/const.h>
5435
5436 /*
5437 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
5438@@ -15,13 +16,13 @@
5439 * just ruin performance.
5440 */
5441 #ifdef CONFIG_PA20
5442-#define L1_CACHE_BYTES 64
5443 #define L1_CACHE_SHIFT 6
5444 #else
5445-#define L1_CACHE_BYTES 32
5446 #define L1_CACHE_SHIFT 5
5447 #endif
5448
5449+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5450+
5451 #ifndef __ASSEMBLY__
5452
5453 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5454diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
5455index 19f6cb1..6c78cf2 100644
5456--- a/arch/parisc/include/asm/elf.h
5457+++ b/arch/parisc/include/asm/elf.h
5458@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
5459
5460 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
5461
5462+#ifdef CONFIG_PAX_ASLR
5463+#define PAX_ELF_ET_DYN_BASE 0x10000UL
5464+
5465+#define PAX_DELTA_MMAP_LEN 16
5466+#define PAX_DELTA_STACK_LEN 16
5467+#endif
5468+
5469 /* This yields a mask that user programs can use to figure out what
5470 instruction set this CPU supports. This could be done in user space,
5471 but it's not easy, and we've already done it here. */
5472diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
5473index fc987a1..6e068ef 100644
5474--- a/arch/parisc/include/asm/pgalloc.h
5475+++ b/arch/parisc/include/asm/pgalloc.h
5476@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5477 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
5478 }
5479
5480+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5481+{
5482+ pgd_populate(mm, pgd, pmd);
5483+}
5484+
5485 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
5486 {
5487 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
5488@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
5489 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
5490 #define pmd_free(mm, x) do { } while (0)
5491 #define pgd_populate(mm, pmd, pte) BUG()
5492+#define pgd_populate_kernel(mm, pmd, pte) BUG()
5493
5494 #endif
5495
5496diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
5497index 7df49fa..38b62bf 100644
5498--- a/arch/parisc/include/asm/pgtable.h
5499+++ b/arch/parisc/include/asm/pgtable.h
5500@@ -218,6 +218,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
5501 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
5502 #define PAGE_COPY PAGE_EXECREAD
5503 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
5504+
5505+#ifdef CONFIG_PAX_PAGEEXEC
5506+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
5507+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5508+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5509+#else
5510+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5511+# define PAGE_COPY_NOEXEC PAGE_COPY
5512+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5513+#endif
5514+
5515 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
5516 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
5517 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
5518diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
5519index 4ba2c93..f5e3974 100644
5520--- a/arch/parisc/include/asm/uaccess.h
5521+++ b/arch/parisc/include/asm/uaccess.h
5522@@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
5523 const void __user *from,
5524 unsigned long n)
5525 {
5526- int sz = __compiletime_object_size(to);
5527+ size_t sz = __compiletime_object_size(to);
5528 int ret = -EFAULT;
5529
5530- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
5531+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
5532 ret = __copy_from_user(to, from, n);
5533 else
5534 copy_from_user_overflow();
5535diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
5536index 2a625fb..9908930 100644
5537--- a/arch/parisc/kernel/module.c
5538+++ b/arch/parisc/kernel/module.c
5539@@ -98,16 +98,38 @@
5540
5541 /* three functions to determine where in the module core
5542 * or init pieces the location is */
5543+static inline int in_init_rx(struct module *me, void *loc)
5544+{
5545+ return (loc >= me->module_init_rx &&
5546+ loc < (me->module_init_rx + me->init_size_rx));
5547+}
5548+
5549+static inline int in_init_rw(struct module *me, void *loc)
5550+{
5551+ return (loc >= me->module_init_rw &&
5552+ loc < (me->module_init_rw + me->init_size_rw));
5553+}
5554+
5555 static inline int in_init(struct module *me, void *loc)
5556 {
5557- return (loc >= me->module_init &&
5558- loc <= (me->module_init + me->init_size));
5559+ return in_init_rx(me, loc) || in_init_rw(me, loc);
5560+}
5561+
5562+static inline int in_core_rx(struct module *me, void *loc)
5563+{
5564+ return (loc >= me->module_core_rx &&
5565+ loc < (me->module_core_rx + me->core_size_rx));
5566+}
5567+
5568+static inline int in_core_rw(struct module *me, void *loc)
5569+{
5570+ return (loc >= me->module_core_rw &&
5571+ loc < (me->module_core_rw + me->core_size_rw));
5572 }
5573
5574 static inline int in_core(struct module *me, void *loc)
5575 {
5576- return (loc >= me->module_core &&
5577- loc <= (me->module_core + me->core_size));
5578+ return in_core_rx(me, loc) || in_core_rw(me, loc);
5579 }
5580
5581 static inline int in_local(struct module *me, void *loc)
5582@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
5583 }
5584
5585 /* align things a bit */
5586- me->core_size = ALIGN(me->core_size, 16);
5587- me->arch.got_offset = me->core_size;
5588- me->core_size += gots * sizeof(struct got_entry);
5589+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
5590+ me->arch.got_offset = me->core_size_rw;
5591+ me->core_size_rw += gots * sizeof(struct got_entry);
5592
5593- me->core_size = ALIGN(me->core_size, 16);
5594- me->arch.fdesc_offset = me->core_size;
5595- me->core_size += fdescs * sizeof(Elf_Fdesc);
5596+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
5597+ me->arch.fdesc_offset = me->core_size_rw;
5598+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
5599
5600 me->arch.got_max = gots;
5601 me->arch.fdesc_max = fdescs;
5602@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5603
5604 BUG_ON(value == 0);
5605
5606- got = me->module_core + me->arch.got_offset;
5607+ got = me->module_core_rw + me->arch.got_offset;
5608 for (i = 0; got[i].addr; i++)
5609 if (got[i].addr == value)
5610 goto out;
5611@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5612 #ifdef CONFIG_64BIT
5613 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5614 {
5615- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
5616+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
5617
5618 if (!value) {
5619 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
5620@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5621
5622 /* Create new one */
5623 fdesc->addr = value;
5624- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5625+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5626 return (Elf_Addr)fdesc;
5627 }
5628 #endif /* CONFIG_64BIT */
5629@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
5630
5631 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
5632 end = table + sechdrs[me->arch.unwind_section].sh_size;
5633- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5634+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5635
5636 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
5637 me->arch.unwind_section, table, end, gp);
5638diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
5639index f76c108..92bad82 100644
5640--- a/arch/parisc/kernel/sys_parisc.c
5641+++ b/arch/parisc/kernel/sys_parisc.c
5642@@ -33,9 +33,11 @@
5643 #include <linux/utsname.h>
5644 #include <linux/personality.h>
5645
5646-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5647+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
5648+ unsigned long flags)
5649 {
5650 struct vm_area_struct *vma;
5651+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5652
5653 addr = PAGE_ALIGN(addr);
5654
5655@@ -43,7 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5656 /* At this point: (!vma || addr < vma->vm_end). */
5657 if (TASK_SIZE - len < addr)
5658 return -ENOMEM;
5659- if (!vma || addr + len <= vma->vm_start)
5660+ if (check_heap_stack_gap(vma, addr, len, offset))
5661 return addr;
5662 addr = vma->vm_end;
5663 }
5664@@ -67,11 +69,12 @@ static int get_offset(struct address_space *mapping)
5665 return offset & 0x3FF000;
5666 }
5667
5668-static unsigned long get_shared_area(struct address_space *mapping,
5669- unsigned long addr, unsigned long len, unsigned long pgoff)
5670+static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
5671+ unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
5672 {
5673 struct vm_area_struct *vma;
5674 int offset = mapping ? get_offset(mapping) : 0;
5675+ unsigned long rand_offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5676
5677 offset = (offset + (pgoff << PAGE_SHIFT)) & 0x3FF000;
5678
5679@@ -81,7 +84,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
5680 /* At this point: (!vma || addr < vma->vm_end). */
5681 if (TASK_SIZE - len < addr)
5682 return -ENOMEM;
5683- if (!vma || addr + len <= vma->vm_start)
5684+ if (check_heap_stack_gap(vma, addr, len, rand_offset))
5685 return addr;
5686 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
5687 if (addr < vma->vm_end) /* handle wraparound */
5688@@ -100,14 +103,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5689 if (flags & MAP_FIXED)
5690 return addr;
5691 if (!addr)
5692- addr = TASK_UNMAPPED_BASE;
5693+ addr = current->mm->mmap_base;
5694
5695 if (filp) {
5696- addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
5697+ addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
5698 } else if(flags & MAP_SHARED) {
5699- addr = get_shared_area(NULL, addr, len, pgoff);
5700+ addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
5701 } else {
5702- addr = get_unshared_area(addr, len);
5703+ addr = get_unshared_area(filp, addr, len, flags);
5704 }
5705 return addr;
5706 }
5707diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
5708index 45ba99f..8e22c33 100644
5709--- a/arch/parisc/kernel/traps.c
5710+++ b/arch/parisc/kernel/traps.c
5711@@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
5712
5713 down_read(&current->mm->mmap_sem);
5714 vma = find_vma(current->mm,regs->iaoq[0]);
5715- if (vma && (regs->iaoq[0] >= vma->vm_start)
5716- && (vma->vm_flags & VM_EXEC)) {
5717-
5718+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
5719 fault_address = regs->iaoq[0];
5720 fault_space = regs->iasq[0];
5721
5722diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
5723index 18162ce..94de376 100644
5724--- a/arch/parisc/mm/fault.c
5725+++ b/arch/parisc/mm/fault.c
5726@@ -15,6 +15,7 @@
5727 #include <linux/sched.h>
5728 #include <linux/interrupt.h>
5729 #include <linux/module.h>
5730+#include <linux/unistd.h>
5731
5732 #include <asm/uaccess.h>
5733 #include <asm/traps.h>
5734@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
5735 static unsigned long
5736 parisc_acctyp(unsigned long code, unsigned int inst)
5737 {
5738- if (code == 6 || code == 16)
5739+ if (code == 6 || code == 7 || code == 16)
5740 return VM_EXEC;
5741
5742 switch (inst & 0xf0000000) {
5743@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
5744 }
5745 #endif
5746
5747+#ifdef CONFIG_PAX_PAGEEXEC
5748+/*
5749+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
5750+ *
5751+ * returns 1 when task should be killed
5752+ * 2 when rt_sigreturn trampoline was detected
5753+ * 3 when unpatched PLT trampoline was detected
5754+ */
5755+static int pax_handle_fetch_fault(struct pt_regs *regs)
5756+{
5757+
5758+#ifdef CONFIG_PAX_EMUPLT
5759+ int err;
5760+
5761+ do { /* PaX: unpatched PLT emulation */
5762+ unsigned int bl, depwi;
5763+
5764+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
5765+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
5766+
5767+ if (err)
5768+ break;
5769+
5770+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
5771+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
5772+
5773+ err = get_user(ldw, (unsigned int *)addr);
5774+ err |= get_user(bv, (unsigned int *)(addr+4));
5775+ err |= get_user(ldw2, (unsigned int *)(addr+8));
5776+
5777+ if (err)
5778+ break;
5779+
5780+ if (ldw == 0x0E801096U &&
5781+ bv == 0xEAC0C000U &&
5782+ ldw2 == 0x0E881095U)
5783+ {
5784+ unsigned int resolver, map;
5785+
5786+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
5787+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
5788+ if (err)
5789+ break;
5790+
5791+ regs->gr[20] = instruction_pointer(regs)+8;
5792+ regs->gr[21] = map;
5793+ regs->gr[22] = resolver;
5794+ regs->iaoq[0] = resolver | 3UL;
5795+ regs->iaoq[1] = regs->iaoq[0] + 4;
5796+ return 3;
5797+ }
5798+ }
5799+ } while (0);
5800+#endif
5801+
5802+#ifdef CONFIG_PAX_EMUTRAMP
5803+
5804+#ifndef CONFIG_PAX_EMUSIGRT
5805+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
5806+ return 1;
5807+#endif
5808+
5809+ do { /* PaX: rt_sigreturn emulation */
5810+ unsigned int ldi1, ldi2, bel, nop;
5811+
5812+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
5813+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
5814+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
5815+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
5816+
5817+ if (err)
5818+ break;
5819+
5820+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
5821+ ldi2 == 0x3414015AU &&
5822+ bel == 0xE4008200U &&
5823+ nop == 0x08000240U)
5824+ {
5825+ regs->gr[25] = (ldi1 & 2) >> 1;
5826+ regs->gr[20] = __NR_rt_sigreturn;
5827+ regs->gr[31] = regs->iaoq[1] + 16;
5828+ regs->sr[0] = regs->iasq[1];
5829+ regs->iaoq[0] = 0x100UL;
5830+ regs->iaoq[1] = regs->iaoq[0] + 4;
5831+ regs->iasq[0] = regs->sr[2];
5832+ regs->iasq[1] = regs->sr[2];
5833+ return 2;
5834+ }
5835+ } while (0);
5836+#endif
5837+
5838+ return 1;
5839+}
5840+
5841+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5842+{
5843+ unsigned long i;
5844+
5845+ printk(KERN_ERR "PAX: bytes at PC: ");
5846+ for (i = 0; i < 5; i++) {
5847+ unsigned int c;
5848+ if (get_user(c, (unsigned int *)pc+i))
5849+ printk(KERN_CONT "???????? ");
5850+ else
5851+ printk(KERN_CONT "%08x ", c);
5852+ }
5853+ printk("\n");
5854+}
5855+#endif
5856+
5857 int fixup_exception(struct pt_regs *regs)
5858 {
5859 const struct exception_table_entry *fix;
5860@@ -192,8 +303,33 @@ good_area:
5861
5862 acc_type = parisc_acctyp(code,regs->iir);
5863
5864- if ((vma->vm_flags & acc_type) != acc_type)
5865+ if ((vma->vm_flags & acc_type) != acc_type) {
5866+
5867+#ifdef CONFIG_PAX_PAGEEXEC
5868+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
5869+ (address & ~3UL) == instruction_pointer(regs))
5870+ {
5871+ up_read(&mm->mmap_sem);
5872+ switch (pax_handle_fetch_fault(regs)) {
5873+
5874+#ifdef CONFIG_PAX_EMUPLT
5875+ case 3:
5876+ return;
5877+#endif
5878+
5879+#ifdef CONFIG_PAX_EMUTRAMP
5880+ case 2:
5881+ return;
5882+#endif
5883+
5884+ }
5885+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
5886+ do_group_exit(SIGKILL);
5887+ }
5888+#endif
5889+
5890 goto bad_area;
5891+ }
5892
5893 /*
5894 * If for any reason at all we couldn't handle the fault, make
5895diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
5896index e3b1d41..8e81edf 100644
5897--- a/arch/powerpc/include/asm/atomic.h
5898+++ b/arch/powerpc/include/asm/atomic.h
5899@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
5900 return t1;
5901 }
5902
5903+#define atomic64_read_unchecked(v) atomic64_read(v)
5904+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5905+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5906+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5907+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5908+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5909+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5910+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5911+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5912+
5913 #endif /* __powerpc64__ */
5914
5915 #endif /* __KERNEL__ */
5916diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
5917index 9e495c9..b6878e5 100644
5918--- a/arch/powerpc/include/asm/cache.h
5919+++ b/arch/powerpc/include/asm/cache.h
5920@@ -3,6 +3,7 @@
5921
5922 #ifdef __KERNEL__
5923
5924+#include <linux/const.h>
5925
5926 /* bytes per L1 cache line */
5927 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
5928@@ -22,7 +23,7 @@
5929 #define L1_CACHE_SHIFT 7
5930 #endif
5931
5932-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5933+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5934
5935 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5936
5937diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
5938index 6abf0a1..459d0f1 100644
5939--- a/arch/powerpc/include/asm/elf.h
5940+++ b/arch/powerpc/include/asm/elf.h
5941@@ -28,8 +28,19 @@
5942 the loader. We need to make sure that it is out of the way of the program
5943 that it will "exec", and that there is sufficient room for the brk. */
5944
5945-extern unsigned long randomize_et_dyn(unsigned long base);
5946-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
5947+#define ELF_ET_DYN_BASE (0x20000000)
5948+
5949+#ifdef CONFIG_PAX_ASLR
5950+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
5951+
5952+#ifdef __powerpc64__
5953+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
5954+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
5955+#else
5956+#define PAX_DELTA_MMAP_LEN 15
5957+#define PAX_DELTA_STACK_LEN 15
5958+#endif
5959+#endif
5960
5961 /*
5962 * Our registers are always unsigned longs, whether we're a 32 bit
5963@@ -124,10 +135,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
5964 (0x7ff >> (PAGE_SHIFT - 12)) : \
5965 (0x3ffff >> (PAGE_SHIFT - 12)))
5966
5967-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5968-#define arch_randomize_brk arch_randomize_brk
5969-
5970-
5971 #ifdef CONFIG_SPU_BASE
5972 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
5973 #define NT_SPU 1
5974diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
5975index 8196e9c..d83a9f3 100644
5976--- a/arch/powerpc/include/asm/exec.h
5977+++ b/arch/powerpc/include/asm/exec.h
5978@@ -4,6 +4,6 @@
5979 #ifndef _ASM_POWERPC_EXEC_H
5980 #define _ASM_POWERPC_EXEC_H
5981
5982-extern unsigned long arch_align_stack(unsigned long sp);
5983+#define arch_align_stack(x) ((x) & ~0xfUL)
5984
5985 #endif /* _ASM_POWERPC_EXEC_H */
5986diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
5987index 5acabbd..7ea14fa 100644
5988--- a/arch/powerpc/include/asm/kmap_types.h
5989+++ b/arch/powerpc/include/asm/kmap_types.h
5990@@ -10,7 +10,7 @@
5991 * 2 of the License, or (at your option) any later version.
5992 */
5993
5994-#define KM_TYPE_NR 16
5995+#define KM_TYPE_NR 17
5996
5997 #endif /* __KERNEL__ */
5998 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
5999diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
6000index 8565c25..2865190 100644
6001--- a/arch/powerpc/include/asm/mman.h
6002+++ b/arch/powerpc/include/asm/mman.h
6003@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
6004 }
6005 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
6006
6007-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
6008+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
6009 {
6010 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
6011 }
6012diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
6013index f072e97..b436dee 100644
6014--- a/arch/powerpc/include/asm/page.h
6015+++ b/arch/powerpc/include/asm/page.h
6016@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
6017 * and needs to be executable. This means the whole heap ends
6018 * up being executable.
6019 */
6020-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6021- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6022+#define VM_DATA_DEFAULT_FLAGS32 \
6023+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6024+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6025
6026 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6027 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6028@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
6029 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
6030 #endif
6031
6032+#define ktla_ktva(addr) (addr)
6033+#define ktva_ktla(addr) (addr)
6034+
6035 /*
6036 * Use the top bit of the higher-level page table entries to indicate whether
6037 * the entries we point to contain hugepages. This works because we know that
6038diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
6039index cd915d6..c10cee8 100644
6040--- a/arch/powerpc/include/asm/page_64.h
6041+++ b/arch/powerpc/include/asm/page_64.h
6042@@ -154,15 +154,18 @@ do { \
6043 * stack by default, so in the absence of a PT_GNU_STACK program header
6044 * we turn execute permission off.
6045 */
6046-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6047- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6048+#define VM_STACK_DEFAULT_FLAGS32 \
6049+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6050+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6051
6052 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6053 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6054
6055+#ifndef CONFIG_PAX_PAGEEXEC
6056 #define VM_STACK_DEFAULT_FLAGS \
6057 (is_32bit_task() ? \
6058 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
6059+#endif
6060
6061 #include <asm-generic/getorder.h>
6062
6063diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
6064index 292725c..f87ae14 100644
6065--- a/arch/powerpc/include/asm/pgalloc-64.h
6066+++ b/arch/powerpc/include/asm/pgalloc-64.h
6067@@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6068 #ifndef CONFIG_PPC_64K_PAGES
6069
6070 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
6071+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
6072
6073 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
6074 {
6075@@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6076 pud_set(pud, (unsigned long)pmd);
6077 }
6078
6079+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6080+{
6081+ pud_populate(mm, pud, pmd);
6082+}
6083+
6084 #define pmd_populate(mm, pmd, pte_page) \
6085 pmd_populate_kernel(mm, pmd, page_address(pte_page))
6086 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
6087@@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6088 #else /* CONFIG_PPC_64K_PAGES */
6089
6090 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
6091+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
6092
6093 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
6094 pte_t *pte)
6095diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
6096index a9cbd3b..3b67efa 100644
6097--- a/arch/powerpc/include/asm/pgtable.h
6098+++ b/arch/powerpc/include/asm/pgtable.h
6099@@ -2,6 +2,7 @@
6100 #define _ASM_POWERPC_PGTABLE_H
6101 #ifdef __KERNEL__
6102
6103+#include <linux/const.h>
6104 #ifndef __ASSEMBLY__
6105 #include <asm/processor.h> /* For TASK_SIZE */
6106 #include <asm/mmu.h>
6107diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
6108index 4aad413..85d86bf 100644
6109--- a/arch/powerpc/include/asm/pte-hash32.h
6110+++ b/arch/powerpc/include/asm/pte-hash32.h
6111@@ -21,6 +21,7 @@
6112 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
6113 #define _PAGE_USER 0x004 /* usermode access allowed */
6114 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
6115+#define _PAGE_EXEC _PAGE_GUARDED
6116 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
6117 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
6118 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
6119diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
6120index 3d5c9dc..62f8414 100644
6121--- a/arch/powerpc/include/asm/reg.h
6122+++ b/arch/powerpc/include/asm/reg.h
6123@@ -215,6 +215,7 @@
6124 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
6125 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
6126 #define DSISR_NOHPTE 0x40000000 /* no translation found */
6127+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
6128 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
6129 #define DSISR_ISSTORE 0x02000000 /* access was a store */
6130 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
6131diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
6132index 406b7b9..af63426 100644
6133--- a/arch/powerpc/include/asm/thread_info.h
6134+++ b/arch/powerpc/include/asm/thread_info.h
6135@@ -97,7 +97,6 @@ static inline struct thread_info *current_thread_info(void)
6136 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
6137 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
6138 #define TIF_SINGLESTEP 8 /* singlestepping active */
6139-#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
6140 #define TIF_SECCOMP 10 /* secure computing */
6141 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
6142 #define TIF_NOERROR 12 /* Force successful syscall return */
6143@@ -106,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6144 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
6145 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
6146 for stack store? */
6147+#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
6148+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
6149+#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
6150
6151 /* as above, but as bit values */
6152 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6153@@ -124,8 +126,10 @@ static inline struct thread_info *current_thread_info(void)
6154 #define _TIF_UPROBE (1<<TIF_UPROBE)
6155 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6156 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
6157+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6158 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
6159- _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
6160+ _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
6161+ _TIF_GRSEC_SETXID)
6162
6163 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
6164 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
6165diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
6166index 4db4959..335e00c 100644
6167--- a/arch/powerpc/include/asm/uaccess.h
6168+++ b/arch/powerpc/include/asm/uaccess.h
6169@@ -13,6 +13,8 @@
6170 #define VERIFY_READ 0
6171 #define VERIFY_WRITE 1
6172
6173+extern void check_object_size(const void *ptr, unsigned long n, bool to);
6174+
6175 /*
6176 * The fs value determines whether argument validity checking should be
6177 * performed or not. If get_fs() == USER_DS, checking is performed, with
6178@@ -318,52 +320,6 @@ do { \
6179 extern unsigned long __copy_tofrom_user(void __user *to,
6180 const void __user *from, unsigned long size);
6181
6182-#ifndef __powerpc64__
6183-
6184-static inline unsigned long copy_from_user(void *to,
6185- const void __user *from, unsigned long n)
6186-{
6187- unsigned long over;
6188-
6189- if (access_ok(VERIFY_READ, from, n))
6190- return __copy_tofrom_user((__force void __user *)to, from, n);
6191- if ((unsigned long)from < TASK_SIZE) {
6192- over = (unsigned long)from + n - TASK_SIZE;
6193- return __copy_tofrom_user((__force void __user *)to, from,
6194- n - over) + over;
6195- }
6196- return n;
6197-}
6198-
6199-static inline unsigned long copy_to_user(void __user *to,
6200- const void *from, unsigned long n)
6201-{
6202- unsigned long over;
6203-
6204- if (access_ok(VERIFY_WRITE, to, n))
6205- return __copy_tofrom_user(to, (__force void __user *)from, n);
6206- if ((unsigned long)to < TASK_SIZE) {
6207- over = (unsigned long)to + n - TASK_SIZE;
6208- return __copy_tofrom_user(to, (__force void __user *)from,
6209- n - over) + over;
6210- }
6211- return n;
6212-}
6213-
6214-#else /* __powerpc64__ */
6215-
6216-#define __copy_in_user(to, from, size) \
6217- __copy_tofrom_user((to), (from), (size))
6218-
6219-extern unsigned long copy_from_user(void *to, const void __user *from,
6220- unsigned long n);
6221-extern unsigned long copy_to_user(void __user *to, const void *from,
6222- unsigned long n);
6223-extern unsigned long copy_in_user(void __user *to, const void __user *from,
6224- unsigned long n);
6225-
6226-#endif /* __powerpc64__ */
6227-
6228 static inline unsigned long __copy_from_user_inatomic(void *to,
6229 const void __user *from, unsigned long n)
6230 {
6231@@ -387,6 +343,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
6232 if (ret == 0)
6233 return 0;
6234 }
6235+
6236+ if (!__builtin_constant_p(n))
6237+ check_object_size(to, n, false);
6238+
6239 return __copy_tofrom_user((__force void __user *)to, from, n);
6240 }
6241
6242@@ -413,6 +373,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
6243 if (ret == 0)
6244 return 0;
6245 }
6246+
6247+ if (!__builtin_constant_p(n))
6248+ check_object_size(from, n, true);
6249+
6250 return __copy_tofrom_user(to, (__force const void __user *)from, n);
6251 }
6252
6253@@ -430,6 +394,92 @@ static inline unsigned long __copy_to_user(void __user *to,
6254 return __copy_to_user_inatomic(to, from, size);
6255 }
6256
6257+#ifndef __powerpc64__
6258+
6259+static inline unsigned long __must_check copy_from_user(void *to,
6260+ const void __user *from, unsigned long n)
6261+{
6262+ unsigned long over;
6263+
6264+ if ((long)n < 0)
6265+ return n;
6266+
6267+ if (access_ok(VERIFY_READ, from, n)) {
6268+ if (!__builtin_constant_p(n))
6269+ check_object_size(to, n, false);
6270+ return __copy_tofrom_user((__force void __user *)to, from, n);
6271+ }
6272+ if ((unsigned long)from < TASK_SIZE) {
6273+ over = (unsigned long)from + n - TASK_SIZE;
6274+ if (!__builtin_constant_p(n - over))
6275+ check_object_size(to, n - over, false);
6276+ return __copy_tofrom_user((__force void __user *)to, from,
6277+ n - over) + over;
6278+ }
6279+ return n;
6280+}
6281+
6282+static inline unsigned long __must_check copy_to_user(void __user *to,
6283+ const void *from, unsigned long n)
6284+{
6285+ unsigned long over;
6286+
6287+ if ((long)n < 0)
6288+ return n;
6289+
6290+ if (access_ok(VERIFY_WRITE, to, n)) {
6291+ if (!__builtin_constant_p(n))
6292+ check_object_size(from, n, true);
6293+ return __copy_tofrom_user(to, (__force void __user *)from, n);
6294+ }
6295+ if ((unsigned long)to < TASK_SIZE) {
6296+ over = (unsigned long)to + n - TASK_SIZE;
6297+ if (!__builtin_constant_p(n))
6298+ check_object_size(from, n - over, true);
6299+ return __copy_tofrom_user(to, (__force void __user *)from,
6300+ n - over) + over;
6301+ }
6302+ return n;
6303+}
6304+
6305+#else /* __powerpc64__ */
6306+
6307+#define __copy_in_user(to, from, size) \
6308+ __copy_tofrom_user((to), (from), (size))
6309+
6310+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
6311+{
6312+ if ((long)n < 0 || n > INT_MAX)
6313+ return n;
6314+
6315+ if (!__builtin_constant_p(n))
6316+ check_object_size(to, n, false);
6317+
6318+ if (likely(access_ok(VERIFY_READ, from, n)))
6319+ n = __copy_from_user(to, from, n);
6320+ else
6321+ memset(to, 0, n);
6322+ return n;
6323+}
6324+
6325+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
6326+{
6327+ if ((long)n < 0 || n > INT_MAX)
6328+ return n;
6329+
6330+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
6331+ if (!__builtin_constant_p(n))
6332+ check_object_size(from, n, true);
6333+ n = __copy_to_user(to, from, n);
6334+ }
6335+ return n;
6336+}
6337+
6338+extern unsigned long copy_in_user(void __user *to, const void __user *from,
6339+ unsigned long n);
6340+
6341+#endif /* __powerpc64__ */
6342+
6343 extern unsigned long __clear_user(void __user *addr, unsigned long size);
6344
6345 static inline unsigned long clear_user(void __user *addr, unsigned long size)
6346diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
6347index 4684e33..acc4d19e 100644
6348--- a/arch/powerpc/kernel/exceptions-64e.S
6349+++ b/arch/powerpc/kernel/exceptions-64e.S
6350@@ -715,6 +715,7 @@ storage_fault_common:
6351 std r14,_DAR(r1)
6352 std r15,_DSISR(r1)
6353 addi r3,r1,STACK_FRAME_OVERHEAD
6354+ bl .save_nvgprs
6355 mr r4,r14
6356 mr r5,r15
6357 ld r14,PACA_EXGEN+EX_R14(r13)
6358@@ -723,8 +724,7 @@ storage_fault_common:
6359 cmpdi r3,0
6360 bne- 1f
6361 b .ret_from_except_lite
6362-1: bl .save_nvgprs
6363- mr r5,r3
6364+1: mr r5,r3
6365 addi r3,r1,STACK_FRAME_OVERHEAD
6366 ld r4,_DAR(r1)
6367 bl .bad_page_fault
6368diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
6369index 4665e82..080ea99 100644
6370--- a/arch/powerpc/kernel/exceptions-64s.S
6371+++ b/arch/powerpc/kernel/exceptions-64s.S
6372@@ -1206,10 +1206,10 @@ handle_page_fault:
6373 11: ld r4,_DAR(r1)
6374 ld r5,_DSISR(r1)
6375 addi r3,r1,STACK_FRAME_OVERHEAD
6376+ bl .save_nvgprs
6377 bl .do_page_fault
6378 cmpdi r3,0
6379 beq+ 12f
6380- bl .save_nvgprs
6381 mr r5,r3
6382 addi r3,r1,STACK_FRAME_OVERHEAD
6383 lwz r4,_DAR(r1)
6384diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
6385index 2e3200c..72095ce 100644
6386--- a/arch/powerpc/kernel/module_32.c
6387+++ b/arch/powerpc/kernel/module_32.c
6388@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
6389 me->arch.core_plt_section = i;
6390 }
6391 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
6392- printk("Module doesn't contain .plt or .init.plt sections.\n");
6393+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
6394 return -ENOEXEC;
6395 }
6396
6397@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
6398
6399 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
6400 /* Init, or core PLT? */
6401- if (location >= mod->module_core
6402- && location < mod->module_core + mod->core_size)
6403+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
6404+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
6405 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
6406- else
6407+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
6408+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
6409 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
6410+ else {
6411+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
6412+ return ~0UL;
6413+ }
6414
6415 /* Find this entry, or if that fails, the next avail. entry */
6416 while (entry->jump[0]) {
6417diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
6418index 8143067..21ae55b 100644
6419--- a/arch/powerpc/kernel/process.c
6420+++ b/arch/powerpc/kernel/process.c
6421@@ -680,8 +680,8 @@ void show_regs(struct pt_regs * regs)
6422 * Lookup NIP late so we have the best change of getting the
6423 * above info out without failing
6424 */
6425- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
6426- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
6427+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
6428+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
6429 #endif
6430 show_stack(current, (unsigned long *) regs->gpr[1]);
6431 if (!user_mode(regs))
6432@@ -1129,10 +1129,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6433 newsp = stack[0];
6434 ip = stack[STACK_FRAME_LR_SAVE];
6435 if (!firstframe || ip != lr) {
6436- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
6437+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
6438 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6439 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
6440- printk(" (%pS)",
6441+ printk(" (%pA)",
6442 (void *)current->ret_stack[curr_frame].ret);
6443 curr_frame--;
6444 }
6445@@ -1152,7 +1152,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6446 struct pt_regs *regs = (struct pt_regs *)
6447 (sp + STACK_FRAME_OVERHEAD);
6448 lr = regs->link;
6449- printk("--- Exception: %lx at %pS\n LR = %pS\n",
6450+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
6451 regs->trap, (void *)regs->nip, (void *)lr);
6452 firstframe = 1;
6453 }
6454@@ -1194,58 +1194,3 @@ void __ppc64_runlatch_off(void)
6455 mtspr(SPRN_CTRLT, ctrl);
6456 }
6457 #endif /* CONFIG_PPC64 */
6458-
6459-unsigned long arch_align_stack(unsigned long sp)
6460-{
6461- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6462- sp -= get_random_int() & ~PAGE_MASK;
6463- return sp & ~0xf;
6464-}
6465-
6466-static inline unsigned long brk_rnd(void)
6467-{
6468- unsigned long rnd = 0;
6469-
6470- /* 8MB for 32bit, 1GB for 64bit */
6471- if (is_32bit_task())
6472- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
6473- else
6474- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
6475-
6476- return rnd << PAGE_SHIFT;
6477-}
6478-
6479-unsigned long arch_randomize_brk(struct mm_struct *mm)
6480-{
6481- unsigned long base = mm->brk;
6482- unsigned long ret;
6483-
6484-#ifdef CONFIG_PPC_STD_MMU_64
6485- /*
6486- * If we are using 1TB segments and we are allowed to randomise
6487- * the heap, we can put it above 1TB so it is backed by a 1TB
6488- * segment. Otherwise the heap will be in the bottom 1TB
6489- * which always uses 256MB segments and this may result in a
6490- * performance penalty.
6491- */
6492- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
6493- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
6494-#endif
6495-
6496- ret = PAGE_ALIGN(base + brk_rnd());
6497-
6498- if (ret < mm->brk)
6499- return mm->brk;
6500-
6501- return ret;
6502-}
6503-
6504-unsigned long randomize_et_dyn(unsigned long base)
6505-{
6506- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
6507-
6508- if (ret < base)
6509- return base;
6510-
6511- return ret;
6512-}
6513diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
6514index c497000..8fde506 100644
6515--- a/arch/powerpc/kernel/ptrace.c
6516+++ b/arch/powerpc/kernel/ptrace.c
6517@@ -1737,6 +1737,10 @@ long arch_ptrace(struct task_struct *child, long request,
6518 return ret;
6519 }
6520
6521+#ifdef CONFIG_GRKERNSEC_SETXID
6522+extern void gr_delayed_cred_worker(void);
6523+#endif
6524+
6525 /*
6526 * We must return the syscall number to actually look up in the table.
6527 * This can be -1L to skip running any syscall at all.
6528@@ -1747,6 +1751,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
6529
6530 secure_computing_strict(regs->gpr[0]);
6531
6532+#ifdef CONFIG_GRKERNSEC_SETXID
6533+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6534+ gr_delayed_cred_worker();
6535+#endif
6536+
6537 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
6538 tracehook_report_syscall_entry(regs))
6539 /*
6540@@ -1781,6 +1790,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
6541 {
6542 int step;
6543
6544+#ifdef CONFIG_GRKERNSEC_SETXID
6545+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6546+ gr_delayed_cred_worker();
6547+#endif
6548+
6549 audit_syscall_exit(regs);
6550
6551 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6552diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
6553index 804e323..79181c1 100644
6554--- a/arch/powerpc/kernel/signal_32.c
6555+++ b/arch/powerpc/kernel/signal_32.c
6556@@ -851,7 +851,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
6557 /* Save user registers on the stack */
6558 frame = &rt_sf->uc.uc_mcontext;
6559 addr = frame;
6560- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
6561+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6562 if (save_user_regs(regs, frame, 0, 1))
6563 goto badframe;
6564 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
6565diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
6566index 1ca045d..139c3f7 100644
6567--- a/arch/powerpc/kernel/signal_64.c
6568+++ b/arch/powerpc/kernel/signal_64.c
6569@@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
6570 current->thread.fpscr.val = 0;
6571
6572 /* Set up to return from userspace. */
6573- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
6574+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6575 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
6576 } else {
6577 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
6578diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
6579index 3ce1f86..c30e629 100644
6580--- a/arch/powerpc/kernel/sysfs.c
6581+++ b/arch/powerpc/kernel/sysfs.c
6582@@ -522,7 +522,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
6583 return NOTIFY_OK;
6584 }
6585
6586-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
6587+static struct notifier_block sysfs_cpu_nb = {
6588 .notifier_call = sysfs_cpu_notify,
6589 };
6590
6591diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
6592index 3251840..3f7c77a 100644
6593--- a/arch/powerpc/kernel/traps.c
6594+++ b/arch/powerpc/kernel/traps.c
6595@@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
6596 return flags;
6597 }
6598
6599+extern void gr_handle_kernel_exploit(void);
6600+
6601 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6602 int signr)
6603 {
6604@@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6605 panic("Fatal exception in interrupt");
6606 if (panic_on_oops)
6607 panic("Fatal exception");
6608+
6609+ gr_handle_kernel_exploit();
6610+
6611 do_exit(signr);
6612 }
6613
6614diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
6615index 1b2076f..835e4be 100644
6616--- a/arch/powerpc/kernel/vdso.c
6617+++ b/arch/powerpc/kernel/vdso.c
6618@@ -34,6 +34,7 @@
6619 #include <asm/firmware.h>
6620 #include <asm/vdso.h>
6621 #include <asm/vdso_datapage.h>
6622+#include <asm/mman.h>
6623
6624 #include "setup.h"
6625
6626@@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6627 vdso_base = VDSO32_MBASE;
6628 #endif
6629
6630- current->mm->context.vdso_base = 0;
6631+ current->mm->context.vdso_base = ~0UL;
6632
6633 /* vDSO has a problem and was disabled, just don't "enable" it for the
6634 * process
6635@@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6636 vdso_base = get_unmapped_area(NULL, vdso_base,
6637 (vdso_pages << PAGE_SHIFT) +
6638 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
6639- 0, 0);
6640+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
6641 if (IS_ERR_VALUE(vdso_base)) {
6642 rc = vdso_base;
6643 goto fail_mmapsem;
6644diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
6645index 5eea6f3..5d10396 100644
6646--- a/arch/powerpc/lib/usercopy_64.c
6647+++ b/arch/powerpc/lib/usercopy_64.c
6648@@ -9,22 +9,6 @@
6649 #include <linux/module.h>
6650 #include <asm/uaccess.h>
6651
6652-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
6653-{
6654- if (likely(access_ok(VERIFY_READ, from, n)))
6655- n = __copy_from_user(to, from, n);
6656- else
6657- memset(to, 0, n);
6658- return n;
6659-}
6660-
6661-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
6662-{
6663- if (likely(access_ok(VERIFY_WRITE, to, n)))
6664- n = __copy_to_user(to, from, n);
6665- return n;
6666-}
6667-
6668 unsigned long copy_in_user(void __user *to, const void __user *from,
6669 unsigned long n)
6670 {
6671@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
6672 return n;
6673 }
6674
6675-EXPORT_SYMBOL(copy_from_user);
6676-EXPORT_SYMBOL(copy_to_user);
6677 EXPORT_SYMBOL(copy_in_user);
6678
6679diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
6680index 3a8489a..6a63b3b 100644
6681--- a/arch/powerpc/mm/fault.c
6682+++ b/arch/powerpc/mm/fault.c
6683@@ -32,6 +32,10 @@
6684 #include <linux/perf_event.h>
6685 #include <linux/magic.h>
6686 #include <linux/ratelimit.h>
6687+#include <linux/slab.h>
6688+#include <linux/pagemap.h>
6689+#include <linux/compiler.h>
6690+#include <linux/unistd.h>
6691
6692 #include <asm/firmware.h>
6693 #include <asm/page.h>
6694@@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
6695 }
6696 #endif
6697
6698+#ifdef CONFIG_PAX_PAGEEXEC
6699+/*
6700+ * PaX: decide what to do with offenders (regs->nip = fault address)
6701+ *
6702+ * returns 1 when task should be killed
6703+ */
6704+static int pax_handle_fetch_fault(struct pt_regs *regs)
6705+{
6706+ return 1;
6707+}
6708+
6709+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6710+{
6711+ unsigned long i;
6712+
6713+ printk(KERN_ERR "PAX: bytes at PC: ");
6714+ for (i = 0; i < 5; i++) {
6715+ unsigned int c;
6716+ if (get_user(c, (unsigned int __user *)pc+i))
6717+ printk(KERN_CONT "???????? ");
6718+ else
6719+ printk(KERN_CONT "%08x ", c);
6720+ }
6721+ printk("\n");
6722+}
6723+#endif
6724+
6725 /*
6726 * Check whether the instruction at regs->nip is a store using
6727 * an update addressing form which will update r1.
6728@@ -213,7 +244,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
6729 * indicate errors in DSISR but can validly be set in SRR1.
6730 */
6731 if (trap == 0x400)
6732- error_code &= 0x48200000;
6733+ error_code &= 0x58200000;
6734 else
6735 is_write = error_code & DSISR_ISSTORE;
6736 #else
6737@@ -364,7 +395,7 @@ good_area:
6738 * "undefined". Of those that can be set, this is the only
6739 * one which seems bad.
6740 */
6741- if (error_code & 0x10000000)
6742+ if (error_code & DSISR_GUARDED)
6743 /* Guarded storage error. */
6744 goto bad_area;
6745 #endif /* CONFIG_8xx */
6746@@ -379,7 +410,7 @@ good_area:
6747 * processors use the same I/D cache coherency mechanism
6748 * as embedded.
6749 */
6750- if (error_code & DSISR_PROTFAULT)
6751+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
6752 goto bad_area;
6753 #endif /* CONFIG_PPC_STD_MMU */
6754
6755@@ -462,6 +493,23 @@ bad_area:
6756 bad_area_nosemaphore:
6757 /* User mode accesses cause a SIGSEGV */
6758 if (user_mode(regs)) {
6759+
6760+#ifdef CONFIG_PAX_PAGEEXEC
6761+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
6762+#ifdef CONFIG_PPC_STD_MMU
6763+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
6764+#else
6765+ if (is_exec && regs->nip == address) {
6766+#endif
6767+ switch (pax_handle_fetch_fault(regs)) {
6768+ }
6769+
6770+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
6771+ do_group_exit(SIGKILL);
6772+ }
6773+ }
6774+#endif
6775+
6776 _exception(SIGSEGV, regs, code, address);
6777 return 0;
6778 }
6779diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
6780index 67a42ed..cd463e0 100644
6781--- a/arch/powerpc/mm/mmap_64.c
6782+++ b/arch/powerpc/mm/mmap_64.c
6783@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
6784 {
6785 unsigned long rnd = 0;
6786
6787+#ifdef CONFIG_PAX_RANDMMAP
6788+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6789+#endif
6790+
6791 if (current->flags & PF_RANDOMIZE) {
6792 /* 8MB for 32bit, 1GB for 64bit */
6793 if (is_32bit_task())
6794@@ -91,10 +95,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6795 */
6796 if (mmap_is_legacy()) {
6797 mm->mmap_base = TASK_UNMAPPED_BASE;
6798+
6799+#ifdef CONFIG_PAX_RANDMMAP
6800+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6801+ mm->mmap_base += mm->delta_mmap;
6802+#endif
6803+
6804 mm->get_unmapped_area = arch_get_unmapped_area;
6805 mm->unmap_area = arch_unmap_area;
6806 } else {
6807 mm->mmap_base = mmap_base();
6808+
6809+#ifdef CONFIG_PAX_RANDMMAP
6810+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6811+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6812+#endif
6813+
6814 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6815 mm->unmap_area = arch_unmap_area_topdown;
6816 }
6817diff --git a/arch/powerpc/mm/mmu_context_nohash.c b/arch/powerpc/mm/mmu_context_nohash.c
6818index e779642..e5bb889 100644
6819--- a/arch/powerpc/mm/mmu_context_nohash.c
6820+++ b/arch/powerpc/mm/mmu_context_nohash.c
6821@@ -363,7 +363,7 @@ static int __cpuinit mmu_context_cpu_notify(struct notifier_block *self,
6822 return NOTIFY_OK;
6823 }
6824
6825-static struct notifier_block __cpuinitdata mmu_context_cpu_nb = {
6826+static struct notifier_block mmu_context_cpu_nb = {
6827 .notifier_call = mmu_context_cpu_notify,
6828 };
6829
6830diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
6831index bba87ca..c346a33 100644
6832--- a/arch/powerpc/mm/numa.c
6833+++ b/arch/powerpc/mm/numa.c
6834@@ -932,7 +932,7 @@ static void __init *careful_zallocation(int nid, unsigned long size,
6835 return ret;
6836 }
6837
6838-static struct notifier_block __cpuinitdata ppc64_numa_nb = {
6839+static struct notifier_block ppc64_numa_nb = {
6840 .notifier_call = cpu_numa_callback,
6841 .priority = 1 /* Must run before sched domains notifier. */
6842 };
6843diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
6844index cf9dada..241529f 100644
6845--- a/arch/powerpc/mm/slice.c
6846+++ b/arch/powerpc/mm/slice.c
6847@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
6848 if ((mm->task_size - len) < addr)
6849 return 0;
6850 vma = find_vma(mm, addr);
6851- return (!vma || (addr + len) <= vma->vm_start);
6852+ return check_heap_stack_gap(vma, addr, len, 0);
6853 }
6854
6855 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
6856@@ -272,7 +272,7 @@ full_search:
6857 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
6858 continue;
6859 }
6860- if (!vma || addr + len <= vma->vm_start) {
6861+ if (check_heap_stack_gap(vma, addr, len, 0)) {
6862 /*
6863 * Remember the place where we stopped the search:
6864 */
6865@@ -329,10 +329,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
6866 }
6867 }
6868
6869- addr = mm->mmap_base;
6870- while (addr > len) {
6871+ if (mm->mmap_base < len)
6872+ addr = -ENOMEM;
6873+ else
6874+ addr = mm->mmap_base - len;
6875+
6876+ while (!IS_ERR_VALUE(addr)) {
6877 /* Go down by chunk size */
6878- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
6879+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
6880
6881 /* Check for hit with different page size */
6882 mask = slice_range_to_mask(addr, len);
6883@@ -352,7 +356,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
6884 * return with success:
6885 */
6886 vma = find_vma(mm, addr);
6887- if (!vma || (addr + len) <= vma->vm_start) {
6888+ if (check_heap_stack_gap(vma, addr, len, 0)) {
6889 /* remember the address as a hint for next time */
6890 if (use_cache)
6891 mm->free_area_cache = addr;
6892@@ -364,7 +368,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
6893 mm->cached_hole_size = vma->vm_start - addr;
6894
6895 /* try just below the current vma->vm_start */
6896- addr = vma->vm_start;
6897+ addr = skip_heap_stack_gap(vma, len, 0);
6898 }
6899
6900 /*
6901@@ -442,6 +446,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
6902 if (fixed && addr > (mm->task_size - len))
6903 return -EINVAL;
6904
6905+#ifdef CONFIG_PAX_RANDMMAP
6906+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
6907+ addr = 0;
6908+#endif
6909+
6910 /* If hint, make sure it matches our alignment restrictions */
6911 if (!fixed && addr) {
6912 addr = _ALIGN_UP(addr, 1ul << pshift);
6913diff --git a/arch/powerpc/platforms/powermac/smp.c b/arch/powerpc/platforms/powermac/smp.c
6914index bdb738a..49c9f95 100644
6915--- a/arch/powerpc/platforms/powermac/smp.c
6916+++ b/arch/powerpc/platforms/powermac/smp.c
6917@@ -885,7 +885,7 @@ static int smp_core99_cpu_notify(struct notifier_block *self,
6918 return NOTIFY_OK;
6919 }
6920
6921-static struct notifier_block __cpuinitdata smp_core99_cpu_nb = {
6922+static struct notifier_block smp_core99_cpu_nb = {
6923 .notifier_call = smp_core99_cpu_notify,
6924 };
6925 #endif /* CONFIG_HOTPLUG_CPU */
6926diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
6927index c797832..ce575c8 100644
6928--- a/arch/s390/include/asm/atomic.h
6929+++ b/arch/s390/include/asm/atomic.h
6930@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
6931 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
6932 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
6933
6934+#define atomic64_read_unchecked(v) atomic64_read(v)
6935+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6936+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6937+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6938+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6939+#define atomic64_inc_unchecked(v) atomic64_inc(v)
6940+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6941+#define atomic64_dec_unchecked(v) atomic64_dec(v)
6942+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6943+
6944 #define smp_mb__before_atomic_dec() smp_mb()
6945 #define smp_mb__after_atomic_dec() smp_mb()
6946 #define smp_mb__before_atomic_inc() smp_mb()
6947diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
6948index 4d7ccac..d03d0ad 100644
6949--- a/arch/s390/include/asm/cache.h
6950+++ b/arch/s390/include/asm/cache.h
6951@@ -9,8 +9,10 @@
6952 #ifndef __ARCH_S390_CACHE_H
6953 #define __ARCH_S390_CACHE_H
6954
6955-#define L1_CACHE_BYTES 256
6956+#include <linux/const.h>
6957+
6958 #define L1_CACHE_SHIFT 8
6959+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6960 #define NET_SKB_PAD 32
6961
6962 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
6963diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
6964index 178ff96..8c93bd1 100644
6965--- a/arch/s390/include/asm/elf.h
6966+++ b/arch/s390/include/asm/elf.h
6967@@ -160,8 +160,14 @@ extern unsigned int vdso_enabled;
6968 the loader. We need to make sure that it is out of the way of the program
6969 that it will "exec", and that there is sufficient room for the brk. */
6970
6971-extern unsigned long randomize_et_dyn(unsigned long base);
6972-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
6973+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
6974+
6975+#ifdef CONFIG_PAX_ASLR
6976+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
6977+
6978+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
6979+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
6980+#endif
6981
6982 /* This yields a mask that user programs can use to figure out what
6983 instruction set this CPU supports. */
6984@@ -210,9 +216,6 @@ struct linux_binprm;
6985 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6986 int arch_setup_additional_pages(struct linux_binprm *, int);
6987
6988-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6989-#define arch_randomize_brk arch_randomize_brk
6990-
6991 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
6992
6993 #endif
6994diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
6995index c4a93d6..4d2a9b4 100644
6996--- a/arch/s390/include/asm/exec.h
6997+++ b/arch/s390/include/asm/exec.h
6998@@ -7,6 +7,6 @@
6999 #ifndef __ASM_EXEC_H
7000 #define __ASM_EXEC_H
7001
7002-extern unsigned long arch_align_stack(unsigned long sp);
7003+#define arch_align_stack(x) ((x) & ~0xfUL)
7004
7005 #endif /* __ASM_EXEC_H */
7006diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
7007index 34268df..ea97318 100644
7008--- a/arch/s390/include/asm/uaccess.h
7009+++ b/arch/s390/include/asm/uaccess.h
7010@@ -252,6 +252,10 @@ static inline unsigned long __must_check
7011 copy_to_user(void __user *to, const void *from, unsigned long n)
7012 {
7013 might_fault();
7014+
7015+ if ((long)n < 0)
7016+ return n;
7017+
7018 if (access_ok(VERIFY_WRITE, to, n))
7019 n = __copy_to_user(to, from, n);
7020 return n;
7021@@ -277,6 +281,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
7022 static inline unsigned long __must_check
7023 __copy_from_user(void *to, const void __user *from, unsigned long n)
7024 {
7025+ if ((long)n < 0)
7026+ return n;
7027+
7028 if (__builtin_constant_p(n) && (n <= 256))
7029 return uaccess.copy_from_user_small(n, from, to);
7030 else
7031@@ -308,10 +315,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
7032 static inline unsigned long __must_check
7033 copy_from_user(void *to, const void __user *from, unsigned long n)
7034 {
7035- unsigned int sz = __compiletime_object_size(to);
7036+ size_t sz = __compiletime_object_size(to);
7037
7038 might_fault();
7039- if (unlikely(sz != -1 && sz < n)) {
7040+
7041+ if ((long)n < 0)
7042+ return n;
7043+
7044+ if (unlikely(sz != (size_t)-1 && sz < n)) {
7045 copy_from_user_overflow();
7046 return n;
7047 }
7048diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
7049index 4610dea..cf0af21 100644
7050--- a/arch/s390/kernel/module.c
7051+++ b/arch/s390/kernel/module.c
7052@@ -171,11 +171,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
7053
7054 /* Increase core size by size of got & plt and set start
7055 offsets for got and plt. */
7056- me->core_size = ALIGN(me->core_size, 4);
7057- me->arch.got_offset = me->core_size;
7058- me->core_size += me->arch.got_size;
7059- me->arch.plt_offset = me->core_size;
7060- me->core_size += me->arch.plt_size;
7061+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
7062+ me->arch.got_offset = me->core_size_rw;
7063+ me->core_size_rw += me->arch.got_size;
7064+ me->arch.plt_offset = me->core_size_rx;
7065+ me->core_size_rx += me->arch.plt_size;
7066 return 0;
7067 }
7068
7069@@ -252,7 +252,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7070 if (info->got_initialized == 0) {
7071 Elf_Addr *gotent;
7072
7073- gotent = me->module_core + me->arch.got_offset +
7074+ gotent = me->module_core_rw + me->arch.got_offset +
7075 info->got_offset;
7076 *gotent = val;
7077 info->got_initialized = 1;
7078@@ -276,7 +276,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7079 else if (r_type == R_390_GOTENT ||
7080 r_type == R_390_GOTPLTENT)
7081 *(unsigned int *) loc =
7082- (val + (Elf_Addr) me->module_core - loc) >> 1;
7083+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
7084 else if (r_type == R_390_GOT64 ||
7085 r_type == R_390_GOTPLT64)
7086 *(unsigned long *) loc = val;
7087@@ -290,7 +290,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7088 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
7089 if (info->plt_initialized == 0) {
7090 unsigned int *ip;
7091- ip = me->module_core + me->arch.plt_offset +
7092+ ip = me->module_core_rx + me->arch.plt_offset +
7093 info->plt_offset;
7094 #ifndef CONFIG_64BIT
7095 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
7096@@ -315,7 +315,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7097 val - loc + 0xffffUL < 0x1ffffeUL) ||
7098 (r_type == R_390_PLT32DBL &&
7099 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
7100- val = (Elf_Addr) me->module_core +
7101+ val = (Elf_Addr) me->module_core_rx +
7102 me->arch.plt_offset +
7103 info->plt_offset;
7104 val += rela->r_addend - loc;
7105@@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7106 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
7107 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
7108 val = val + rela->r_addend -
7109- ((Elf_Addr) me->module_core + me->arch.got_offset);
7110+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
7111 if (r_type == R_390_GOTOFF16)
7112 *(unsigned short *) loc = val;
7113 else if (r_type == R_390_GOTOFF32)
7114@@ -347,7 +347,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7115 break;
7116 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
7117 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
7118- val = (Elf_Addr) me->module_core + me->arch.got_offset +
7119+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
7120 rela->r_addend - loc;
7121 if (r_type == R_390_GOTPC)
7122 *(unsigned int *) loc = val;
7123diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
7124index 536d645..4a5bd9e 100644
7125--- a/arch/s390/kernel/process.c
7126+++ b/arch/s390/kernel/process.c
7127@@ -250,39 +250,3 @@ unsigned long get_wchan(struct task_struct *p)
7128 }
7129 return 0;
7130 }
7131-
7132-unsigned long arch_align_stack(unsigned long sp)
7133-{
7134- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7135- sp -= get_random_int() & ~PAGE_MASK;
7136- return sp & ~0xf;
7137-}
7138-
7139-static inline unsigned long brk_rnd(void)
7140-{
7141- /* 8MB for 32bit, 1GB for 64bit */
7142- if (is_32bit_task())
7143- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
7144- else
7145- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
7146-}
7147-
7148-unsigned long arch_randomize_brk(struct mm_struct *mm)
7149-{
7150- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
7151-
7152- if (ret < mm->brk)
7153- return mm->brk;
7154- return ret;
7155-}
7156-
7157-unsigned long randomize_et_dyn(unsigned long base)
7158-{
7159- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
7160-
7161- if (!(current->flags & PF_RANDOMIZE))
7162- return base;
7163- if (ret < base)
7164- return base;
7165- return ret;
7166-}
7167diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
7168index c59a5ef..3fae59c 100644
7169--- a/arch/s390/mm/mmap.c
7170+++ b/arch/s390/mm/mmap.c
7171@@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7172 */
7173 if (mmap_is_legacy()) {
7174 mm->mmap_base = TASK_UNMAPPED_BASE;
7175+
7176+#ifdef CONFIG_PAX_RANDMMAP
7177+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7178+ mm->mmap_base += mm->delta_mmap;
7179+#endif
7180+
7181 mm->get_unmapped_area = arch_get_unmapped_area;
7182 mm->unmap_area = arch_unmap_area;
7183 } else {
7184 mm->mmap_base = mmap_base();
7185+
7186+#ifdef CONFIG_PAX_RANDMMAP
7187+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7188+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7189+#endif
7190+
7191 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7192 mm->unmap_area = arch_unmap_area_topdown;
7193 }
7194@@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7195 */
7196 if (mmap_is_legacy()) {
7197 mm->mmap_base = TASK_UNMAPPED_BASE;
7198+
7199+#ifdef CONFIG_PAX_RANDMMAP
7200+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7201+ mm->mmap_base += mm->delta_mmap;
7202+#endif
7203+
7204 mm->get_unmapped_area = s390_get_unmapped_area;
7205 mm->unmap_area = arch_unmap_area;
7206 } else {
7207 mm->mmap_base = mmap_base();
7208+
7209+#ifdef CONFIG_PAX_RANDMMAP
7210+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7211+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7212+#endif
7213+
7214 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
7215 mm->unmap_area = arch_unmap_area_topdown;
7216 }
7217diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
7218index ae3d59f..f65f075 100644
7219--- a/arch/score/include/asm/cache.h
7220+++ b/arch/score/include/asm/cache.h
7221@@ -1,7 +1,9 @@
7222 #ifndef _ASM_SCORE_CACHE_H
7223 #define _ASM_SCORE_CACHE_H
7224
7225+#include <linux/const.h>
7226+
7227 #define L1_CACHE_SHIFT 4
7228-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7229+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7230
7231 #endif /* _ASM_SCORE_CACHE_H */
7232diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
7233index f9f3cd5..58ff438 100644
7234--- a/arch/score/include/asm/exec.h
7235+++ b/arch/score/include/asm/exec.h
7236@@ -1,6 +1,6 @@
7237 #ifndef _ASM_SCORE_EXEC_H
7238 #define _ASM_SCORE_EXEC_H
7239
7240-extern unsigned long arch_align_stack(unsigned long sp);
7241+#define arch_align_stack(x) (x)
7242
7243 #endif /* _ASM_SCORE_EXEC_H */
7244diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
7245index 7956846..5f37677 100644
7246--- a/arch/score/kernel/process.c
7247+++ b/arch/score/kernel/process.c
7248@@ -134,8 +134,3 @@ unsigned long get_wchan(struct task_struct *task)
7249
7250 return task_pt_regs(task)->cp0_epc;
7251 }
7252-
7253-unsigned long arch_align_stack(unsigned long sp)
7254-{
7255- return sp;
7256-}
7257diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
7258index ef9e555..331bd29 100644
7259--- a/arch/sh/include/asm/cache.h
7260+++ b/arch/sh/include/asm/cache.h
7261@@ -9,10 +9,11 @@
7262 #define __ASM_SH_CACHE_H
7263 #ifdef __KERNEL__
7264
7265+#include <linux/const.h>
7266 #include <linux/init.h>
7267 #include <cpu/cache.h>
7268
7269-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7270+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7271
7272 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7273
7274diff --git a/arch/sh/kernel/cpu/sh4a/smp-shx3.c b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7275index 03f2b55..b027032 100644
7276--- a/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7277+++ b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7278@@ -143,7 +143,7 @@ shx3_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
7279 return NOTIFY_OK;
7280 }
7281
7282-static struct notifier_block __cpuinitdata shx3_cpu_notifier = {
7283+static struct notifier_block shx3_cpu_notifier = {
7284 .notifier_call = shx3_cpu_callback,
7285 };
7286
7287diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
7288index 6777177..cb5e44f 100644
7289--- a/arch/sh/mm/mmap.c
7290+++ b/arch/sh/mm/mmap.c
7291@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7292 struct mm_struct *mm = current->mm;
7293 struct vm_area_struct *vma;
7294 int do_colour_align;
7295+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7296 struct vm_unmapped_area_info info;
7297
7298 if (flags & MAP_FIXED) {
7299@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7300 if (filp || (flags & MAP_SHARED))
7301 do_colour_align = 1;
7302
7303+#ifdef CONFIG_PAX_RANDMMAP
7304+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7305+#endif
7306+
7307 if (addr) {
7308 if (do_colour_align)
7309 addr = COLOUR_ALIGN(addr, pgoff);
7310@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7311 addr = PAGE_ALIGN(addr);
7312
7313 vma = find_vma(mm, addr);
7314- if (TASK_SIZE - len >= addr &&
7315- (!vma || addr + len <= vma->vm_start))
7316+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7317 return addr;
7318 }
7319
7320 info.flags = 0;
7321 info.length = len;
7322- info.low_limit = TASK_UNMAPPED_BASE;
7323+ info.low_limit = mm->mmap_base;
7324 info.high_limit = TASK_SIZE;
7325 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
7326 info.align_offset = pgoff << PAGE_SHIFT;
7327@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7328 struct mm_struct *mm = current->mm;
7329 unsigned long addr = addr0;
7330 int do_colour_align;
7331+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7332 struct vm_unmapped_area_info info;
7333
7334 if (flags & MAP_FIXED) {
7335@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7336 if (filp || (flags & MAP_SHARED))
7337 do_colour_align = 1;
7338
7339+#ifdef CONFIG_PAX_RANDMMAP
7340+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7341+#endif
7342+
7343 /* requesting a specific address */
7344 if (addr) {
7345 if (do_colour_align)
7346@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7347 addr = PAGE_ALIGN(addr);
7348
7349 vma = find_vma(mm, addr);
7350- if (TASK_SIZE - len >= addr &&
7351- (!vma || addr + len <= vma->vm_start))
7352+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7353 return addr;
7354 }
7355
7356@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7357 VM_BUG_ON(addr != -ENOMEM);
7358 info.flags = 0;
7359 info.low_limit = TASK_UNMAPPED_BASE;
7360+
7361+#ifdef CONFIG_PAX_RANDMMAP
7362+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7363+ info.low_limit += mm->delta_mmap;
7364+#endif
7365+
7366 info.high_limit = TASK_SIZE;
7367 addr = vm_unmapped_area(&info);
7368 }
7369diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
7370index be56a24..443328f 100644
7371--- a/arch/sparc/include/asm/atomic_64.h
7372+++ b/arch/sparc/include/asm/atomic_64.h
7373@@ -14,18 +14,40 @@
7374 #define ATOMIC64_INIT(i) { (i) }
7375
7376 #define atomic_read(v) (*(volatile int *)&(v)->counter)
7377+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
7378+{
7379+ return v->counter;
7380+}
7381 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
7382+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
7383+{
7384+ return v->counter;
7385+}
7386
7387 #define atomic_set(v, i) (((v)->counter) = i)
7388+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7389+{
7390+ v->counter = i;
7391+}
7392 #define atomic64_set(v, i) (((v)->counter) = i)
7393+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
7394+{
7395+ v->counter = i;
7396+}
7397
7398 extern void atomic_add(int, atomic_t *);
7399+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
7400 extern void atomic64_add(long, atomic64_t *);
7401+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
7402 extern void atomic_sub(int, atomic_t *);
7403+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
7404 extern void atomic64_sub(long, atomic64_t *);
7405+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
7406
7407 extern int atomic_add_ret(int, atomic_t *);
7408+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
7409 extern long atomic64_add_ret(long, atomic64_t *);
7410+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
7411 extern int atomic_sub_ret(int, atomic_t *);
7412 extern long atomic64_sub_ret(long, atomic64_t *);
7413
7414@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7415 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
7416
7417 #define atomic_inc_return(v) atomic_add_ret(1, v)
7418+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7419+{
7420+ return atomic_add_ret_unchecked(1, v);
7421+}
7422 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
7423+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
7424+{
7425+ return atomic64_add_ret_unchecked(1, v);
7426+}
7427
7428 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
7429 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
7430
7431 #define atomic_add_return(i, v) atomic_add_ret(i, v)
7432+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
7433+{
7434+ return atomic_add_ret_unchecked(i, v);
7435+}
7436 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
7437+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
7438+{
7439+ return atomic64_add_ret_unchecked(i, v);
7440+}
7441
7442 /*
7443 * atomic_inc_and_test - increment and test
7444@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7445 * other cases.
7446 */
7447 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
7448+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7449+{
7450+ return atomic_inc_return_unchecked(v) == 0;
7451+}
7452 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
7453
7454 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
7455@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7456 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
7457
7458 #define atomic_inc(v) atomic_add(1, v)
7459+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7460+{
7461+ atomic_add_unchecked(1, v);
7462+}
7463 #define atomic64_inc(v) atomic64_add(1, v)
7464+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
7465+{
7466+ atomic64_add_unchecked(1, v);
7467+}
7468
7469 #define atomic_dec(v) atomic_sub(1, v)
7470+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
7471+{
7472+ atomic_sub_unchecked(1, v);
7473+}
7474 #define atomic64_dec(v) atomic64_sub(1, v)
7475+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
7476+{
7477+ atomic64_sub_unchecked(1, v);
7478+}
7479
7480 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
7481 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
7482
7483 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
7484+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7485+{
7486+ return cmpxchg(&v->counter, old, new);
7487+}
7488 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
7489+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7490+{
7491+ return xchg(&v->counter, new);
7492+}
7493
7494 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7495 {
7496- int c, old;
7497+ int c, old, new;
7498 c = atomic_read(v);
7499 for (;;) {
7500- if (unlikely(c == (u)))
7501+ if (unlikely(c == u))
7502 break;
7503- old = atomic_cmpxchg((v), c, c + (a));
7504+
7505+ asm volatile("addcc %2, %0, %0\n"
7506+
7507+#ifdef CONFIG_PAX_REFCOUNT
7508+ "tvs %%icc, 6\n"
7509+#endif
7510+
7511+ : "=r" (new)
7512+ : "0" (c), "ir" (a)
7513+ : "cc");
7514+
7515+ old = atomic_cmpxchg(v, c, new);
7516 if (likely(old == c))
7517 break;
7518 c = old;
7519@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7520 #define atomic64_cmpxchg(v, o, n) \
7521 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
7522 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
7523+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
7524+{
7525+ return xchg(&v->counter, new);
7526+}
7527
7528 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7529 {
7530- long c, old;
7531+ long c, old, new;
7532 c = atomic64_read(v);
7533 for (;;) {
7534- if (unlikely(c == (u)))
7535+ if (unlikely(c == u))
7536 break;
7537- old = atomic64_cmpxchg((v), c, c + (a));
7538+
7539+ asm volatile("addcc %2, %0, %0\n"
7540+
7541+#ifdef CONFIG_PAX_REFCOUNT
7542+ "tvs %%xcc, 6\n"
7543+#endif
7544+
7545+ : "=r" (new)
7546+ : "0" (c), "ir" (a)
7547+ : "cc");
7548+
7549+ old = atomic64_cmpxchg(v, c, new);
7550 if (likely(old == c))
7551 break;
7552 c = old;
7553 }
7554- return c != (u);
7555+ return c != u;
7556 }
7557
7558 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7559diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
7560index 5bb6991..5c2132e 100644
7561--- a/arch/sparc/include/asm/cache.h
7562+++ b/arch/sparc/include/asm/cache.h
7563@@ -7,10 +7,12 @@
7564 #ifndef _SPARC_CACHE_H
7565 #define _SPARC_CACHE_H
7566
7567+#include <linux/const.h>
7568+
7569 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
7570
7571 #define L1_CACHE_SHIFT 5
7572-#define L1_CACHE_BYTES 32
7573+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7574
7575 #ifdef CONFIG_SPARC32
7576 #define SMP_CACHE_BYTES_SHIFT 5
7577diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
7578index ac74a2c..a9e58af 100644
7579--- a/arch/sparc/include/asm/elf_32.h
7580+++ b/arch/sparc/include/asm/elf_32.h
7581@@ -114,6 +114,13 @@ typedef struct {
7582
7583 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
7584
7585+#ifdef CONFIG_PAX_ASLR
7586+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7587+
7588+#define PAX_DELTA_MMAP_LEN 16
7589+#define PAX_DELTA_STACK_LEN 16
7590+#endif
7591+
7592 /* This yields a mask that user programs can use to figure out what
7593 instruction set this cpu supports. This can NOT be done in userspace
7594 on Sparc. */
7595diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
7596index 370ca1e..d4f4a98 100644
7597--- a/arch/sparc/include/asm/elf_64.h
7598+++ b/arch/sparc/include/asm/elf_64.h
7599@@ -189,6 +189,13 @@ typedef struct {
7600 #define ELF_ET_DYN_BASE 0x0000010000000000UL
7601 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
7602
7603+#ifdef CONFIG_PAX_ASLR
7604+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
7605+
7606+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
7607+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
7608+#endif
7609+
7610 extern unsigned long sparc64_elf_hwcap;
7611 #define ELF_HWCAP sparc64_elf_hwcap
7612
7613diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
7614index 9b1c36d..209298b 100644
7615--- a/arch/sparc/include/asm/pgalloc_32.h
7616+++ b/arch/sparc/include/asm/pgalloc_32.h
7617@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
7618 }
7619
7620 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
7621+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
7622
7623 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
7624 unsigned long address)
7625diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
7626index bcfe063..b333142 100644
7627--- a/arch/sparc/include/asm/pgalloc_64.h
7628+++ b/arch/sparc/include/asm/pgalloc_64.h
7629@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7630 }
7631
7632 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
7633+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
7634
7635 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
7636 {
7637diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
7638index 6fc1348..390c50a 100644
7639--- a/arch/sparc/include/asm/pgtable_32.h
7640+++ b/arch/sparc/include/asm/pgtable_32.h
7641@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
7642 #define PAGE_SHARED SRMMU_PAGE_SHARED
7643 #define PAGE_COPY SRMMU_PAGE_COPY
7644 #define PAGE_READONLY SRMMU_PAGE_RDONLY
7645+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
7646+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
7647+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
7648 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
7649
7650 /* Top-level page directory - dummy used by init-mm.
7651@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
7652
7653 /* xwr */
7654 #define __P000 PAGE_NONE
7655-#define __P001 PAGE_READONLY
7656-#define __P010 PAGE_COPY
7657-#define __P011 PAGE_COPY
7658+#define __P001 PAGE_READONLY_NOEXEC
7659+#define __P010 PAGE_COPY_NOEXEC
7660+#define __P011 PAGE_COPY_NOEXEC
7661 #define __P100 PAGE_READONLY
7662 #define __P101 PAGE_READONLY
7663 #define __P110 PAGE_COPY
7664 #define __P111 PAGE_COPY
7665
7666 #define __S000 PAGE_NONE
7667-#define __S001 PAGE_READONLY
7668-#define __S010 PAGE_SHARED
7669-#define __S011 PAGE_SHARED
7670+#define __S001 PAGE_READONLY_NOEXEC
7671+#define __S010 PAGE_SHARED_NOEXEC
7672+#define __S011 PAGE_SHARED_NOEXEC
7673 #define __S100 PAGE_READONLY
7674 #define __S101 PAGE_READONLY
7675 #define __S110 PAGE_SHARED
7676diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
7677index 79da178..c2eede8 100644
7678--- a/arch/sparc/include/asm/pgtsrmmu.h
7679+++ b/arch/sparc/include/asm/pgtsrmmu.h
7680@@ -115,6 +115,11 @@
7681 SRMMU_EXEC | SRMMU_REF)
7682 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
7683 SRMMU_EXEC | SRMMU_REF)
7684+
7685+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
7686+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7687+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7688+
7689 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
7690 SRMMU_DIRTY | SRMMU_REF)
7691
7692diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
7693index 9689176..63c18ea 100644
7694--- a/arch/sparc/include/asm/spinlock_64.h
7695+++ b/arch/sparc/include/asm/spinlock_64.h
7696@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
7697
7698 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
7699
7700-static void inline arch_read_lock(arch_rwlock_t *lock)
7701+static inline void arch_read_lock(arch_rwlock_t *lock)
7702 {
7703 unsigned long tmp1, tmp2;
7704
7705 __asm__ __volatile__ (
7706 "1: ldsw [%2], %0\n"
7707 " brlz,pn %0, 2f\n"
7708-"4: add %0, 1, %1\n"
7709+"4: addcc %0, 1, %1\n"
7710+
7711+#ifdef CONFIG_PAX_REFCOUNT
7712+" tvs %%icc, 6\n"
7713+#endif
7714+
7715 " cas [%2], %0, %1\n"
7716 " cmp %0, %1\n"
7717 " bne,pn %%icc, 1b\n"
7718@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
7719 " .previous"
7720 : "=&r" (tmp1), "=&r" (tmp2)
7721 : "r" (lock)
7722- : "memory");
7723+ : "memory", "cc");
7724 }
7725
7726-static int inline arch_read_trylock(arch_rwlock_t *lock)
7727+static inline int arch_read_trylock(arch_rwlock_t *lock)
7728 {
7729 int tmp1, tmp2;
7730
7731@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
7732 "1: ldsw [%2], %0\n"
7733 " brlz,a,pn %0, 2f\n"
7734 " mov 0, %0\n"
7735-" add %0, 1, %1\n"
7736+" addcc %0, 1, %1\n"
7737+
7738+#ifdef CONFIG_PAX_REFCOUNT
7739+" tvs %%icc, 6\n"
7740+#endif
7741+
7742 " cas [%2], %0, %1\n"
7743 " cmp %0, %1\n"
7744 " bne,pn %%icc, 1b\n"
7745@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
7746 return tmp1;
7747 }
7748
7749-static void inline arch_read_unlock(arch_rwlock_t *lock)
7750+static inline void arch_read_unlock(arch_rwlock_t *lock)
7751 {
7752 unsigned long tmp1, tmp2;
7753
7754 __asm__ __volatile__(
7755 "1: lduw [%2], %0\n"
7756-" sub %0, 1, %1\n"
7757+" subcc %0, 1, %1\n"
7758+
7759+#ifdef CONFIG_PAX_REFCOUNT
7760+" tvs %%icc, 6\n"
7761+#endif
7762+
7763 " cas [%2], %0, %1\n"
7764 " cmp %0, %1\n"
7765 " bne,pn %%xcc, 1b\n"
7766@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
7767 : "memory");
7768 }
7769
7770-static void inline arch_write_lock(arch_rwlock_t *lock)
7771+static inline void arch_write_lock(arch_rwlock_t *lock)
7772 {
7773 unsigned long mask, tmp1, tmp2;
7774
7775@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
7776 : "memory");
7777 }
7778
7779-static void inline arch_write_unlock(arch_rwlock_t *lock)
7780+static inline void arch_write_unlock(arch_rwlock_t *lock)
7781 {
7782 __asm__ __volatile__(
7783 " stw %%g0, [%0]"
7784@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
7785 : "memory");
7786 }
7787
7788-static int inline arch_write_trylock(arch_rwlock_t *lock)
7789+static inline int arch_write_trylock(arch_rwlock_t *lock)
7790 {
7791 unsigned long mask, tmp1, tmp2, result;
7792
7793diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
7794index 25849ae..924c54b 100644
7795--- a/arch/sparc/include/asm/thread_info_32.h
7796+++ b/arch/sparc/include/asm/thread_info_32.h
7797@@ -49,6 +49,8 @@ struct thread_info {
7798 unsigned long w_saved;
7799
7800 struct restart_block restart_block;
7801+
7802+ unsigned long lowest_stack;
7803 };
7804
7805 /*
7806diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
7807index 269bd92..e46a9b8 100644
7808--- a/arch/sparc/include/asm/thread_info_64.h
7809+++ b/arch/sparc/include/asm/thread_info_64.h
7810@@ -63,6 +63,8 @@ struct thread_info {
7811 struct pt_regs *kern_una_regs;
7812 unsigned int kern_una_insn;
7813
7814+ unsigned long lowest_stack;
7815+
7816 unsigned long fpregs[0] __attribute__ ((aligned(64)));
7817 };
7818
7819@@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
7820 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
7821 /* flag bit 6 is available */
7822 #define TIF_32BIT 7 /* 32-bit binary */
7823-/* flag bit 8 is available */
7824+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
7825 #define TIF_SECCOMP 9 /* secure computing */
7826 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
7827 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
7828+
7829 /* NOTE: Thread flags >= 12 should be ones we have no interest
7830 * in using in assembly, else we can't use the mask as
7831 * an immediate value in instructions such as andcc.
7832@@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
7833 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
7834 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
7835 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
7836+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
7837
7838 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
7839 _TIF_DO_NOTIFY_RESUME_MASK | \
7840 _TIF_NEED_RESCHED)
7841 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
7842
7843+#define _TIF_WORK_SYSCALL \
7844+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
7845+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
7846+
7847+
7848 /*
7849 * Thread-synchronous status.
7850 *
7851diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
7852index 0167d26..9acd8ed 100644
7853--- a/arch/sparc/include/asm/uaccess.h
7854+++ b/arch/sparc/include/asm/uaccess.h
7855@@ -1,5 +1,13 @@
7856 #ifndef ___ASM_SPARC_UACCESS_H
7857 #define ___ASM_SPARC_UACCESS_H
7858+
7859+#ifdef __KERNEL__
7860+#ifndef __ASSEMBLY__
7861+#include <linux/types.h>
7862+extern void check_object_size(const void *ptr, unsigned long n, bool to);
7863+#endif
7864+#endif
7865+
7866 #if defined(__sparc__) && defined(__arch64__)
7867 #include <asm/uaccess_64.h>
7868 #else
7869diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
7870index 53a28dd..50c38c3 100644
7871--- a/arch/sparc/include/asm/uaccess_32.h
7872+++ b/arch/sparc/include/asm/uaccess_32.h
7873@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
7874
7875 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
7876 {
7877- if (n && __access_ok((unsigned long) to, n))
7878+ if ((long)n < 0)
7879+ return n;
7880+
7881+ if (n && __access_ok((unsigned long) to, n)) {
7882+ if (!__builtin_constant_p(n))
7883+ check_object_size(from, n, true);
7884 return __copy_user(to, (__force void __user *) from, n);
7885- else
7886+ } else
7887 return n;
7888 }
7889
7890 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
7891 {
7892+ if ((long)n < 0)
7893+ return n;
7894+
7895+ if (!__builtin_constant_p(n))
7896+ check_object_size(from, n, true);
7897+
7898 return __copy_user(to, (__force void __user *) from, n);
7899 }
7900
7901 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
7902 {
7903- if (n && __access_ok((unsigned long) from, n))
7904+ if ((long)n < 0)
7905+ return n;
7906+
7907+ if (n && __access_ok((unsigned long) from, n)) {
7908+ if (!__builtin_constant_p(n))
7909+ check_object_size(to, n, false);
7910 return __copy_user((__force void __user *) to, from, n);
7911- else
7912+ } else
7913 return n;
7914 }
7915
7916 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
7917 {
7918+ if ((long)n < 0)
7919+ return n;
7920+
7921 return __copy_user((__force void __user *) to, from, n);
7922 }
7923
7924diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
7925index e562d3c..191f176 100644
7926--- a/arch/sparc/include/asm/uaccess_64.h
7927+++ b/arch/sparc/include/asm/uaccess_64.h
7928@@ -10,6 +10,7 @@
7929 #include <linux/compiler.h>
7930 #include <linux/string.h>
7931 #include <linux/thread_info.h>
7932+#include <linux/kernel.h>
7933 #include <asm/asi.h>
7934 #include <asm/spitfire.h>
7935 #include <asm-generic/uaccess-unaligned.h>
7936@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
7937 static inline unsigned long __must_check
7938 copy_from_user(void *to, const void __user *from, unsigned long size)
7939 {
7940- unsigned long ret = ___copy_from_user(to, from, size);
7941+ unsigned long ret;
7942
7943+ if ((long)size < 0 || size > INT_MAX)
7944+ return size;
7945+
7946+ if (!__builtin_constant_p(size))
7947+ check_object_size(to, size, false);
7948+
7949+ ret = ___copy_from_user(to, from, size);
7950 if (unlikely(ret))
7951 ret = copy_from_user_fixup(to, from, size);
7952
7953@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
7954 static inline unsigned long __must_check
7955 copy_to_user(void __user *to, const void *from, unsigned long size)
7956 {
7957- unsigned long ret = ___copy_to_user(to, from, size);
7958+ unsigned long ret;
7959
7960+ if ((long)size < 0 || size > INT_MAX)
7961+ return size;
7962+
7963+ if (!__builtin_constant_p(size))
7964+ check_object_size(from, size, true);
7965+
7966+ ret = ___copy_to_user(to, from, size);
7967 if (unlikely(ret))
7968 ret = copy_to_user_fixup(to, from, size);
7969 return ret;
7970diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
7971index 6cf591b..b49e65a 100644
7972--- a/arch/sparc/kernel/Makefile
7973+++ b/arch/sparc/kernel/Makefile
7974@@ -3,7 +3,7 @@
7975 #
7976
7977 asflags-y := -ansi
7978-ccflags-y := -Werror
7979+#ccflags-y := -Werror
7980
7981 extra-y := head_$(BITS).o
7982
7983diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
7984index be8e862..5b50b12 100644
7985--- a/arch/sparc/kernel/process_32.c
7986+++ b/arch/sparc/kernel/process_32.c
7987@@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
7988
7989 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
7990 r->psr, r->pc, r->npc, r->y, print_tainted());
7991- printk("PC: <%pS>\n", (void *) r->pc);
7992+ printk("PC: <%pA>\n", (void *) r->pc);
7993 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
7994 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
7995 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
7996 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
7997 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
7998 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
7999- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
8000+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
8001
8002 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8003 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
8004@@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8005 rw = (struct reg_window32 *) fp;
8006 pc = rw->ins[7];
8007 printk("[%08lx : ", pc);
8008- printk("%pS ] ", (void *) pc);
8009+ printk("%pA ] ", (void *) pc);
8010 fp = rw->ins[6];
8011 } while (++count < 16);
8012 printk("\n");
8013diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
8014index cdb80b2..5ca141d 100644
8015--- a/arch/sparc/kernel/process_64.c
8016+++ b/arch/sparc/kernel/process_64.c
8017@@ -181,14 +181,14 @@ static void show_regwindow(struct pt_regs *regs)
8018 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
8019 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
8020 if (regs->tstate & TSTATE_PRIV)
8021- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
8022+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
8023 }
8024
8025 void show_regs(struct pt_regs *regs)
8026 {
8027 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
8028 regs->tpc, regs->tnpc, regs->y, print_tainted());
8029- printk("TPC: <%pS>\n", (void *) regs->tpc);
8030+ printk("TPC: <%pA>\n", (void *) regs->tpc);
8031 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
8032 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
8033 regs->u_regs[3]);
8034@@ -201,7 +201,7 @@ void show_regs(struct pt_regs *regs)
8035 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
8036 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
8037 regs->u_regs[15]);
8038- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
8039+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
8040 show_regwindow(regs);
8041 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
8042 }
8043@@ -290,7 +290,7 @@ void arch_trigger_all_cpu_backtrace(void)
8044 ((tp && tp->task) ? tp->task->pid : -1));
8045
8046 if (gp->tstate & TSTATE_PRIV) {
8047- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
8048+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
8049 (void *) gp->tpc,
8050 (void *) gp->o7,
8051 (void *) gp->i7,
8052diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
8053index 7ff45e4..a58f271 100644
8054--- a/arch/sparc/kernel/ptrace_64.c
8055+++ b/arch/sparc/kernel/ptrace_64.c
8056@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
8057 return ret;
8058 }
8059
8060+#ifdef CONFIG_GRKERNSEC_SETXID
8061+extern void gr_delayed_cred_worker(void);
8062+#endif
8063+
8064 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8065 {
8066 int ret = 0;
8067@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8068 /* do the secure computing check first */
8069 secure_computing_strict(regs->u_regs[UREG_G1]);
8070
8071+#ifdef CONFIG_GRKERNSEC_SETXID
8072+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8073+ gr_delayed_cred_worker();
8074+#endif
8075+
8076 if (test_thread_flag(TIF_SYSCALL_TRACE))
8077 ret = tracehook_report_syscall_entry(regs);
8078
8079@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8080
8081 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
8082 {
8083+#ifdef CONFIG_GRKERNSEC_SETXID
8084+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8085+ gr_delayed_cred_worker();
8086+#endif
8087+
8088 audit_syscall_exit(regs);
8089
8090 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8091diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
8092index 2da0bdc..79128d2 100644
8093--- a/arch/sparc/kernel/sys_sparc_32.c
8094+++ b/arch/sparc/kernel/sys_sparc_32.c
8095@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8096 if (len > TASK_SIZE - PAGE_SIZE)
8097 return -ENOMEM;
8098 if (!addr)
8099- addr = TASK_UNMAPPED_BASE;
8100+ addr = current->mm->mmap_base;
8101
8102 info.flags = 0;
8103 info.length = len;
8104diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
8105index 708bc29..f0129cb 100644
8106--- a/arch/sparc/kernel/sys_sparc_64.c
8107+++ b/arch/sparc/kernel/sys_sparc_64.c
8108@@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8109 struct vm_area_struct * vma;
8110 unsigned long task_size = TASK_SIZE;
8111 int do_color_align;
8112+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8113 struct vm_unmapped_area_info info;
8114
8115 if (flags & MAP_FIXED) {
8116 /* We do not accept a shared mapping if it would violate
8117 * cache aliasing constraints.
8118 */
8119- if ((flags & MAP_SHARED) &&
8120+ if ((filp || (flags & MAP_SHARED)) &&
8121 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8122 return -EINVAL;
8123 return addr;
8124@@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8125 if (filp || (flags & MAP_SHARED))
8126 do_color_align = 1;
8127
8128+#ifdef CONFIG_PAX_RANDMMAP
8129+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8130+#endif
8131+
8132 if (addr) {
8133 if (do_color_align)
8134 addr = COLOR_ALIGN(addr, pgoff);
8135@@ -118,14 +123,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8136 addr = PAGE_ALIGN(addr);
8137
8138 vma = find_vma(mm, addr);
8139- if (task_size - len >= addr &&
8140- (!vma || addr + len <= vma->vm_start))
8141+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8142 return addr;
8143 }
8144
8145 info.flags = 0;
8146 info.length = len;
8147- info.low_limit = TASK_UNMAPPED_BASE;
8148+ info.low_limit = mm->mmap_base;
8149 info.high_limit = min(task_size, VA_EXCLUDE_START);
8150 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
8151 info.align_offset = pgoff << PAGE_SHIFT;
8152@@ -134,6 +138,12 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8153 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
8154 VM_BUG_ON(addr != -ENOMEM);
8155 info.low_limit = VA_EXCLUDE_END;
8156+
8157+#ifdef CONFIG_PAX_RANDMMAP
8158+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8159+ info.low_limit += mm->delta_mmap;
8160+#endif
8161+
8162 info.high_limit = task_size;
8163 addr = vm_unmapped_area(&info);
8164 }
8165@@ -151,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8166 unsigned long task_size = STACK_TOP32;
8167 unsigned long addr = addr0;
8168 int do_color_align;
8169+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8170 struct vm_unmapped_area_info info;
8171
8172 /* This should only ever run for 32-bit processes. */
8173@@ -160,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8174 /* We do not accept a shared mapping if it would violate
8175 * cache aliasing constraints.
8176 */
8177- if ((flags & MAP_SHARED) &&
8178+ if ((filp || (flags & MAP_SHARED)) &&
8179 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8180 return -EINVAL;
8181 return addr;
8182@@ -173,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8183 if (filp || (flags & MAP_SHARED))
8184 do_color_align = 1;
8185
8186+#ifdef CONFIG_PAX_RANDMMAP
8187+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8188+#endif
8189+
8190 /* requesting a specific address */
8191 if (addr) {
8192 if (do_color_align)
8193@@ -181,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8194 addr = PAGE_ALIGN(addr);
8195
8196 vma = find_vma(mm, addr);
8197- if (task_size - len >= addr &&
8198- (!vma || addr + len <= vma->vm_start))
8199+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8200 return addr;
8201 }
8202
8203@@ -204,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8204 VM_BUG_ON(addr != -ENOMEM);
8205 info.flags = 0;
8206 info.low_limit = TASK_UNMAPPED_BASE;
8207+
8208+#ifdef CONFIG_PAX_RANDMMAP
8209+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8210+ info.low_limit += mm->delta_mmap;
8211+#endif
8212+
8213 info.high_limit = STACK_TOP32;
8214 addr = vm_unmapped_area(&info);
8215 }
8216@@ -264,6 +284,10 @@ static unsigned long mmap_rnd(void)
8217 {
8218 unsigned long rnd = 0UL;
8219
8220+#ifdef CONFIG_PAX_RANDMMAP
8221+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8222+#endif
8223+
8224 if (current->flags & PF_RANDOMIZE) {
8225 unsigned long val = get_random_int();
8226 if (test_thread_flag(TIF_32BIT))
8227@@ -289,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8228 gap == RLIM_INFINITY ||
8229 sysctl_legacy_va_layout) {
8230 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
8231+
8232+#ifdef CONFIG_PAX_RANDMMAP
8233+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8234+ mm->mmap_base += mm->delta_mmap;
8235+#endif
8236+
8237 mm->get_unmapped_area = arch_get_unmapped_area;
8238 mm->unmap_area = arch_unmap_area;
8239 } else {
8240@@ -301,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8241 gap = (task_size / 6 * 5);
8242
8243 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
8244+
8245+#ifdef CONFIG_PAX_RANDMMAP
8246+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8247+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8248+#endif
8249+
8250 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8251 mm->unmap_area = arch_unmap_area_topdown;
8252 }
8253diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
8254index e0fed77..604a7e5 100644
8255--- a/arch/sparc/kernel/syscalls.S
8256+++ b/arch/sparc/kernel/syscalls.S
8257@@ -58,7 +58,7 @@ sys32_rt_sigreturn:
8258 #endif
8259 .align 32
8260 1: ldx [%g6 + TI_FLAGS], %l5
8261- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8262+ andcc %l5, _TIF_WORK_SYSCALL, %g0
8263 be,pt %icc, rtrap
8264 nop
8265 call syscall_trace_leave
8266@@ -190,7 +190,7 @@ linux_sparc_syscall32:
8267
8268 srl %i5, 0, %o5 ! IEU1
8269 srl %i2, 0, %o2 ! IEU0 Group
8270- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8271+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8272 bne,pn %icc, linux_syscall_trace32 ! CTI
8273 mov %i0, %l5 ! IEU1
8274 call %l7 ! CTI Group brk forced
8275@@ -213,7 +213,7 @@ linux_sparc_syscall:
8276
8277 mov %i3, %o3 ! IEU1
8278 mov %i4, %o4 ! IEU0 Group
8279- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8280+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8281 bne,pn %icc, linux_syscall_trace ! CTI Group
8282 mov %i0, %l5 ! IEU0
8283 2: call %l7 ! CTI Group brk forced
8284@@ -229,7 +229,7 @@ ret_sys_call:
8285
8286 cmp %o0, -ERESTART_RESTARTBLOCK
8287 bgeu,pn %xcc, 1f
8288- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8289+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8290 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
8291
8292 2:
8293diff --git a/arch/sparc/kernel/sysfs.c b/arch/sparc/kernel/sysfs.c
8294index 654e8aa..45f431b 100644
8295--- a/arch/sparc/kernel/sysfs.c
8296+++ b/arch/sparc/kernel/sysfs.c
8297@@ -266,7 +266,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
8298 return NOTIFY_OK;
8299 }
8300
8301-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
8302+static struct notifier_block sysfs_cpu_nb = {
8303 .notifier_call = sysfs_cpu_notify,
8304 };
8305
8306diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
8307index a5785ea..405c5f7 100644
8308--- a/arch/sparc/kernel/traps_32.c
8309+++ b/arch/sparc/kernel/traps_32.c
8310@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
8311 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
8312 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
8313
8314+extern void gr_handle_kernel_exploit(void);
8315+
8316 void die_if_kernel(char *str, struct pt_regs *regs)
8317 {
8318 static int die_counter;
8319@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8320 count++ < 30 &&
8321 (((unsigned long) rw) >= PAGE_OFFSET) &&
8322 !(((unsigned long) rw) & 0x7)) {
8323- printk("Caller[%08lx]: %pS\n", rw->ins[7],
8324+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
8325 (void *) rw->ins[7]);
8326 rw = (struct reg_window32 *)rw->ins[6];
8327 }
8328 }
8329 printk("Instruction DUMP:");
8330 instruction_dump ((unsigned long *) regs->pc);
8331- if(regs->psr & PSR_PS)
8332+ if(regs->psr & PSR_PS) {
8333+ gr_handle_kernel_exploit();
8334 do_exit(SIGKILL);
8335+ }
8336 do_exit(SIGSEGV);
8337 }
8338
8339diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
8340index e7ecf15..6520e65 100644
8341--- a/arch/sparc/kernel/traps_64.c
8342+++ b/arch/sparc/kernel/traps_64.c
8343@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
8344 i + 1,
8345 p->trapstack[i].tstate, p->trapstack[i].tpc,
8346 p->trapstack[i].tnpc, p->trapstack[i].tt);
8347- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
8348+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
8349 }
8350 }
8351
8352@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
8353
8354 lvl -= 0x100;
8355 if (regs->tstate & TSTATE_PRIV) {
8356+
8357+#ifdef CONFIG_PAX_REFCOUNT
8358+ if (lvl == 6)
8359+ pax_report_refcount_overflow(regs);
8360+#endif
8361+
8362 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
8363 die_if_kernel(buffer, regs);
8364 }
8365@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
8366 void bad_trap_tl1(struct pt_regs *regs, long lvl)
8367 {
8368 char buffer[32];
8369-
8370+
8371 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
8372 0, lvl, SIGTRAP) == NOTIFY_STOP)
8373 return;
8374
8375+#ifdef CONFIG_PAX_REFCOUNT
8376+ if (lvl == 6)
8377+ pax_report_refcount_overflow(regs);
8378+#endif
8379+
8380 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
8381
8382 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
8383@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
8384 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
8385 printk("%s" "ERROR(%d): ",
8386 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
8387- printk("TPC<%pS>\n", (void *) regs->tpc);
8388+ printk("TPC<%pA>\n", (void *) regs->tpc);
8389 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
8390 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
8391 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
8392@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8393 smp_processor_id(),
8394 (type & 0x1) ? 'I' : 'D',
8395 regs->tpc);
8396- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
8397+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
8398 panic("Irrecoverable Cheetah+ parity error.");
8399 }
8400
8401@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8402 smp_processor_id(),
8403 (type & 0x1) ? 'I' : 'D',
8404 regs->tpc);
8405- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
8406+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
8407 }
8408
8409 struct sun4v_error_entry {
8410@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
8411
8412 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
8413 regs->tpc, tl);
8414- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
8415+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
8416 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8417- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
8418+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
8419 (void *) regs->u_regs[UREG_I7]);
8420 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
8421 "pte[%lx] error[%lx]\n",
8422@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
8423
8424 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
8425 regs->tpc, tl);
8426- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
8427+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
8428 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8429- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
8430+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
8431 (void *) regs->u_regs[UREG_I7]);
8432 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
8433 "pte[%lx] error[%lx]\n",
8434@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8435 fp = (unsigned long)sf->fp + STACK_BIAS;
8436 }
8437
8438- printk(" [%016lx] %pS\n", pc, (void *) pc);
8439+ printk(" [%016lx] %pA\n", pc, (void *) pc);
8440 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8441 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
8442 int index = tsk->curr_ret_stack;
8443 if (tsk->ret_stack && index >= graph) {
8444 pc = tsk->ret_stack[index - graph].ret;
8445- printk(" [%016lx] %pS\n", pc, (void *) pc);
8446+ printk(" [%016lx] %pA\n", pc, (void *) pc);
8447 graph++;
8448 }
8449 }
8450@@ -2367,6 +2378,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
8451 return (struct reg_window *) (fp + STACK_BIAS);
8452 }
8453
8454+extern void gr_handle_kernel_exploit(void);
8455+
8456 void die_if_kernel(char *str, struct pt_regs *regs)
8457 {
8458 static int die_counter;
8459@@ -2395,7 +2408,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8460 while (rw &&
8461 count++ < 30 &&
8462 kstack_valid(tp, (unsigned long) rw)) {
8463- printk("Caller[%016lx]: %pS\n", rw->ins[7],
8464+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
8465 (void *) rw->ins[7]);
8466
8467 rw = kernel_stack_up(rw);
8468@@ -2408,8 +2421,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8469 }
8470 user_instruction_dump ((unsigned int __user *) regs->tpc);
8471 }
8472- if (regs->tstate & TSTATE_PRIV)
8473+ if (regs->tstate & TSTATE_PRIV) {
8474+ gr_handle_kernel_exploit();
8475 do_exit(SIGKILL);
8476+ }
8477 do_exit(SIGSEGV);
8478 }
8479 EXPORT_SYMBOL(die_if_kernel);
8480diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
8481index 8201c25e..072a2a7 100644
8482--- a/arch/sparc/kernel/unaligned_64.c
8483+++ b/arch/sparc/kernel/unaligned_64.c
8484@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
8485 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
8486
8487 if (__ratelimit(&ratelimit)) {
8488- printk("Kernel unaligned access at TPC[%lx] %pS\n",
8489+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
8490 regs->tpc, (void *) regs->tpc);
8491 }
8492 }
8493diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
8494index 8410065f2..4fd4ca22 100644
8495--- a/arch/sparc/lib/Makefile
8496+++ b/arch/sparc/lib/Makefile
8497@@ -2,7 +2,7 @@
8498 #
8499
8500 asflags-y := -ansi -DST_DIV0=0x02
8501-ccflags-y := -Werror
8502+#ccflags-y := -Werror
8503
8504 lib-$(CONFIG_SPARC32) += ashrdi3.o
8505 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
8506diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
8507index 85c233d..68500e0 100644
8508--- a/arch/sparc/lib/atomic_64.S
8509+++ b/arch/sparc/lib/atomic_64.S
8510@@ -17,7 +17,12 @@
8511 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8512 BACKOFF_SETUP(%o2)
8513 1: lduw [%o1], %g1
8514- add %g1, %o0, %g7
8515+ addcc %g1, %o0, %g7
8516+
8517+#ifdef CONFIG_PAX_REFCOUNT
8518+ tvs %icc, 6
8519+#endif
8520+
8521 cas [%o1], %g1, %g7
8522 cmp %g1, %g7
8523 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8524@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8525 2: BACKOFF_SPIN(%o2, %o3, 1b)
8526 ENDPROC(atomic_add)
8527
8528+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8529+ BACKOFF_SETUP(%o2)
8530+1: lduw [%o1], %g1
8531+ add %g1, %o0, %g7
8532+ cas [%o1], %g1, %g7
8533+ cmp %g1, %g7
8534+ bne,pn %icc, 2f
8535+ nop
8536+ retl
8537+ nop
8538+2: BACKOFF_SPIN(%o2, %o3, 1b)
8539+ENDPROC(atomic_add_unchecked)
8540+
8541 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8542 BACKOFF_SETUP(%o2)
8543 1: lduw [%o1], %g1
8544- sub %g1, %o0, %g7
8545+ subcc %g1, %o0, %g7
8546+
8547+#ifdef CONFIG_PAX_REFCOUNT
8548+ tvs %icc, 6
8549+#endif
8550+
8551 cas [%o1], %g1, %g7
8552 cmp %g1, %g7
8553 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8554@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8555 2: BACKOFF_SPIN(%o2, %o3, 1b)
8556 ENDPROC(atomic_sub)
8557
8558+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8559+ BACKOFF_SETUP(%o2)
8560+1: lduw [%o1], %g1
8561+ sub %g1, %o0, %g7
8562+ cas [%o1], %g1, %g7
8563+ cmp %g1, %g7
8564+ bne,pn %icc, 2f
8565+ nop
8566+ retl
8567+ nop
8568+2: BACKOFF_SPIN(%o2, %o3, 1b)
8569+ENDPROC(atomic_sub_unchecked)
8570+
8571 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8572 BACKOFF_SETUP(%o2)
8573 1: lduw [%o1], %g1
8574- add %g1, %o0, %g7
8575+ addcc %g1, %o0, %g7
8576+
8577+#ifdef CONFIG_PAX_REFCOUNT
8578+ tvs %icc, 6
8579+#endif
8580+
8581 cas [%o1], %g1, %g7
8582 cmp %g1, %g7
8583 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8584@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8585 2: BACKOFF_SPIN(%o2, %o3, 1b)
8586 ENDPROC(atomic_add_ret)
8587
8588+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8589+ BACKOFF_SETUP(%o2)
8590+1: lduw [%o1], %g1
8591+ addcc %g1, %o0, %g7
8592+ cas [%o1], %g1, %g7
8593+ cmp %g1, %g7
8594+ bne,pn %icc, 2f
8595+ add %g7, %o0, %g7
8596+ sra %g7, 0, %o0
8597+ retl
8598+ nop
8599+2: BACKOFF_SPIN(%o2, %o3, 1b)
8600+ENDPROC(atomic_add_ret_unchecked)
8601+
8602 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
8603 BACKOFF_SETUP(%o2)
8604 1: lduw [%o1], %g1
8605- sub %g1, %o0, %g7
8606+ subcc %g1, %o0, %g7
8607+
8608+#ifdef CONFIG_PAX_REFCOUNT
8609+ tvs %icc, 6
8610+#endif
8611+
8612 cas [%o1], %g1, %g7
8613 cmp %g1, %g7
8614 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8615@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
8616 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8617 BACKOFF_SETUP(%o2)
8618 1: ldx [%o1], %g1
8619- add %g1, %o0, %g7
8620+ addcc %g1, %o0, %g7
8621+
8622+#ifdef CONFIG_PAX_REFCOUNT
8623+ tvs %xcc, 6
8624+#endif
8625+
8626 casx [%o1], %g1, %g7
8627 cmp %g1, %g7
8628 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8629@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8630 2: BACKOFF_SPIN(%o2, %o3, 1b)
8631 ENDPROC(atomic64_add)
8632
8633+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8634+ BACKOFF_SETUP(%o2)
8635+1: ldx [%o1], %g1
8636+ addcc %g1, %o0, %g7
8637+ casx [%o1], %g1, %g7
8638+ cmp %g1, %g7
8639+ bne,pn %xcc, 2f
8640+ nop
8641+ retl
8642+ nop
8643+2: BACKOFF_SPIN(%o2, %o3, 1b)
8644+ENDPROC(atomic64_add_unchecked)
8645+
8646 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8647 BACKOFF_SETUP(%o2)
8648 1: ldx [%o1], %g1
8649- sub %g1, %o0, %g7
8650+ subcc %g1, %o0, %g7
8651+
8652+#ifdef CONFIG_PAX_REFCOUNT
8653+ tvs %xcc, 6
8654+#endif
8655+
8656 casx [%o1], %g1, %g7
8657 cmp %g1, %g7
8658 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8659@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8660 2: BACKOFF_SPIN(%o2, %o3, 1b)
8661 ENDPROC(atomic64_sub)
8662
8663+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8664+ BACKOFF_SETUP(%o2)
8665+1: ldx [%o1], %g1
8666+ subcc %g1, %o0, %g7
8667+ casx [%o1], %g1, %g7
8668+ cmp %g1, %g7
8669+ bne,pn %xcc, 2f
8670+ nop
8671+ retl
8672+ nop
8673+2: BACKOFF_SPIN(%o2, %o3, 1b)
8674+ENDPROC(atomic64_sub_unchecked)
8675+
8676 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8677 BACKOFF_SETUP(%o2)
8678 1: ldx [%o1], %g1
8679- add %g1, %o0, %g7
8680+ addcc %g1, %o0, %g7
8681+
8682+#ifdef CONFIG_PAX_REFCOUNT
8683+ tvs %xcc, 6
8684+#endif
8685+
8686 casx [%o1], %g1, %g7
8687 cmp %g1, %g7
8688 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8689@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8690 2: BACKOFF_SPIN(%o2, %o3, 1b)
8691 ENDPROC(atomic64_add_ret)
8692
8693+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8694+ BACKOFF_SETUP(%o2)
8695+1: ldx [%o1], %g1
8696+ addcc %g1, %o0, %g7
8697+ casx [%o1], %g1, %g7
8698+ cmp %g1, %g7
8699+ bne,pn %xcc, 2f
8700+ add %g7, %o0, %g7
8701+ mov %g7, %o0
8702+ retl
8703+ nop
8704+2: BACKOFF_SPIN(%o2, %o3, 1b)
8705+ENDPROC(atomic64_add_ret_unchecked)
8706+
8707 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
8708 BACKOFF_SETUP(%o2)
8709 1: ldx [%o1], %g1
8710- sub %g1, %o0, %g7
8711+ subcc %g1, %o0, %g7
8712+
8713+#ifdef CONFIG_PAX_REFCOUNT
8714+ tvs %xcc, 6
8715+#endif
8716+
8717 casx [%o1], %g1, %g7
8718 cmp %g1, %g7
8719 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8720diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
8721index 0c4e35e..745d3e4 100644
8722--- a/arch/sparc/lib/ksyms.c
8723+++ b/arch/sparc/lib/ksyms.c
8724@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
8725
8726 /* Atomic counter implementation. */
8727 EXPORT_SYMBOL(atomic_add);
8728+EXPORT_SYMBOL(atomic_add_unchecked);
8729 EXPORT_SYMBOL(atomic_add_ret);
8730+EXPORT_SYMBOL(atomic_add_ret_unchecked);
8731 EXPORT_SYMBOL(atomic_sub);
8732+EXPORT_SYMBOL(atomic_sub_unchecked);
8733 EXPORT_SYMBOL(atomic_sub_ret);
8734 EXPORT_SYMBOL(atomic64_add);
8735+EXPORT_SYMBOL(atomic64_add_unchecked);
8736 EXPORT_SYMBOL(atomic64_add_ret);
8737+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
8738 EXPORT_SYMBOL(atomic64_sub);
8739+EXPORT_SYMBOL(atomic64_sub_unchecked);
8740 EXPORT_SYMBOL(atomic64_sub_ret);
8741 EXPORT_SYMBOL(atomic64_dec_if_positive);
8742
8743diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
8744index 30c3ecc..736f015 100644
8745--- a/arch/sparc/mm/Makefile
8746+++ b/arch/sparc/mm/Makefile
8747@@ -2,7 +2,7 @@
8748 #
8749
8750 asflags-y := -ansi
8751-ccflags-y := -Werror
8752+#ccflags-y := -Werror
8753
8754 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
8755 obj-y += fault_$(BITS).o
8756diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
8757index e98bfda..ea8d221 100644
8758--- a/arch/sparc/mm/fault_32.c
8759+++ b/arch/sparc/mm/fault_32.c
8760@@ -21,6 +21,9 @@
8761 #include <linux/perf_event.h>
8762 #include <linux/interrupt.h>
8763 #include <linux/kdebug.h>
8764+#include <linux/slab.h>
8765+#include <linux/pagemap.h>
8766+#include <linux/compiler.h>
8767
8768 #include <asm/page.h>
8769 #include <asm/pgtable.h>
8770@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
8771 return safe_compute_effective_address(regs, insn);
8772 }
8773
8774+#ifdef CONFIG_PAX_PAGEEXEC
8775+#ifdef CONFIG_PAX_DLRESOLVE
8776+static void pax_emuplt_close(struct vm_area_struct *vma)
8777+{
8778+ vma->vm_mm->call_dl_resolve = 0UL;
8779+}
8780+
8781+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8782+{
8783+ unsigned int *kaddr;
8784+
8785+ vmf->page = alloc_page(GFP_HIGHUSER);
8786+ if (!vmf->page)
8787+ return VM_FAULT_OOM;
8788+
8789+ kaddr = kmap(vmf->page);
8790+ memset(kaddr, 0, PAGE_SIZE);
8791+ kaddr[0] = 0x9DE3BFA8U; /* save */
8792+ flush_dcache_page(vmf->page);
8793+ kunmap(vmf->page);
8794+ return VM_FAULT_MAJOR;
8795+}
8796+
8797+static const struct vm_operations_struct pax_vm_ops = {
8798+ .close = pax_emuplt_close,
8799+ .fault = pax_emuplt_fault
8800+};
8801+
8802+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
8803+{
8804+ int ret;
8805+
8806+ INIT_LIST_HEAD(&vma->anon_vma_chain);
8807+ vma->vm_mm = current->mm;
8808+ vma->vm_start = addr;
8809+ vma->vm_end = addr + PAGE_SIZE;
8810+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
8811+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
8812+ vma->vm_ops = &pax_vm_ops;
8813+
8814+ ret = insert_vm_struct(current->mm, vma);
8815+ if (ret)
8816+ return ret;
8817+
8818+ ++current->mm->total_vm;
8819+ return 0;
8820+}
8821+#endif
8822+
8823+/*
8824+ * PaX: decide what to do with offenders (regs->pc = fault address)
8825+ *
8826+ * returns 1 when task should be killed
8827+ * 2 when patched PLT trampoline was detected
8828+ * 3 when unpatched PLT trampoline was detected
8829+ */
8830+static int pax_handle_fetch_fault(struct pt_regs *regs)
8831+{
8832+
8833+#ifdef CONFIG_PAX_EMUPLT
8834+ int err;
8835+
8836+ do { /* PaX: patched PLT emulation #1 */
8837+ unsigned int sethi1, sethi2, jmpl;
8838+
8839+ err = get_user(sethi1, (unsigned int *)regs->pc);
8840+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
8841+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
8842+
8843+ if (err)
8844+ break;
8845+
8846+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
8847+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
8848+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
8849+ {
8850+ unsigned int addr;
8851+
8852+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
8853+ addr = regs->u_regs[UREG_G1];
8854+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
8855+ regs->pc = addr;
8856+ regs->npc = addr+4;
8857+ return 2;
8858+ }
8859+ } while (0);
8860+
8861+ do { /* PaX: patched PLT emulation #2 */
8862+ unsigned int ba;
8863+
8864+ err = get_user(ba, (unsigned int *)regs->pc);
8865+
8866+ if (err)
8867+ break;
8868+
8869+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
8870+ unsigned int addr;
8871+
8872+ if ((ba & 0xFFC00000U) == 0x30800000U)
8873+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
8874+ else
8875+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
8876+ regs->pc = addr;
8877+ regs->npc = addr+4;
8878+ return 2;
8879+ }
8880+ } while (0);
8881+
8882+ do { /* PaX: patched PLT emulation #3 */
8883+ unsigned int sethi, bajmpl, nop;
8884+
8885+ err = get_user(sethi, (unsigned int *)regs->pc);
8886+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
8887+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
8888+
8889+ if (err)
8890+ break;
8891+
8892+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
8893+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
8894+ nop == 0x01000000U)
8895+ {
8896+ unsigned int addr;
8897+
8898+ addr = (sethi & 0x003FFFFFU) << 10;
8899+ regs->u_regs[UREG_G1] = addr;
8900+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
8901+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
8902+ else
8903+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
8904+ regs->pc = addr;
8905+ regs->npc = addr+4;
8906+ return 2;
8907+ }
8908+ } while (0);
8909+
8910+ do { /* PaX: unpatched PLT emulation step 1 */
8911+ unsigned int sethi, ba, nop;
8912+
8913+ err = get_user(sethi, (unsigned int *)regs->pc);
8914+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
8915+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
8916+
8917+ if (err)
8918+ break;
8919+
8920+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
8921+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
8922+ nop == 0x01000000U)
8923+ {
8924+ unsigned int addr, save, call;
8925+
8926+ if ((ba & 0xFFC00000U) == 0x30800000U)
8927+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
8928+ else
8929+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
8930+
8931+ err = get_user(save, (unsigned int *)addr);
8932+ err |= get_user(call, (unsigned int *)(addr+4));
8933+ err |= get_user(nop, (unsigned int *)(addr+8));
8934+ if (err)
8935+ break;
8936+
8937+#ifdef CONFIG_PAX_DLRESOLVE
8938+ if (save == 0x9DE3BFA8U &&
8939+ (call & 0xC0000000U) == 0x40000000U &&
8940+ nop == 0x01000000U)
8941+ {
8942+ struct vm_area_struct *vma;
8943+ unsigned long call_dl_resolve;
8944+
8945+ down_read(&current->mm->mmap_sem);
8946+ call_dl_resolve = current->mm->call_dl_resolve;
8947+ up_read(&current->mm->mmap_sem);
8948+ if (likely(call_dl_resolve))
8949+ goto emulate;
8950+
8951+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
8952+
8953+ down_write(&current->mm->mmap_sem);
8954+ if (current->mm->call_dl_resolve) {
8955+ call_dl_resolve = current->mm->call_dl_resolve;
8956+ up_write(&current->mm->mmap_sem);
8957+ if (vma)
8958+ kmem_cache_free(vm_area_cachep, vma);
8959+ goto emulate;
8960+ }
8961+
8962+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
8963+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
8964+ up_write(&current->mm->mmap_sem);
8965+ if (vma)
8966+ kmem_cache_free(vm_area_cachep, vma);
8967+ return 1;
8968+ }
8969+
8970+ if (pax_insert_vma(vma, call_dl_resolve)) {
8971+ up_write(&current->mm->mmap_sem);
8972+ kmem_cache_free(vm_area_cachep, vma);
8973+ return 1;
8974+ }
8975+
8976+ current->mm->call_dl_resolve = call_dl_resolve;
8977+ up_write(&current->mm->mmap_sem);
8978+
8979+emulate:
8980+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8981+ regs->pc = call_dl_resolve;
8982+ regs->npc = addr+4;
8983+ return 3;
8984+ }
8985+#endif
8986+
8987+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
8988+ if ((save & 0xFFC00000U) == 0x05000000U &&
8989+ (call & 0xFFFFE000U) == 0x85C0A000U &&
8990+ nop == 0x01000000U)
8991+ {
8992+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8993+ regs->u_regs[UREG_G2] = addr + 4;
8994+ addr = (save & 0x003FFFFFU) << 10;
8995+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
8996+ regs->pc = addr;
8997+ regs->npc = addr+4;
8998+ return 3;
8999+ }
9000+ }
9001+ } while (0);
9002+
9003+ do { /* PaX: unpatched PLT emulation step 2 */
9004+ unsigned int save, call, nop;
9005+
9006+ err = get_user(save, (unsigned int *)(regs->pc-4));
9007+ err |= get_user(call, (unsigned int *)regs->pc);
9008+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
9009+ if (err)
9010+ break;
9011+
9012+ if (save == 0x9DE3BFA8U &&
9013+ (call & 0xC0000000U) == 0x40000000U &&
9014+ nop == 0x01000000U)
9015+ {
9016+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
9017+
9018+ regs->u_regs[UREG_RETPC] = regs->pc;
9019+ regs->pc = dl_resolve;
9020+ regs->npc = dl_resolve+4;
9021+ return 3;
9022+ }
9023+ } while (0);
9024+#endif
9025+
9026+ return 1;
9027+}
9028+
9029+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9030+{
9031+ unsigned long i;
9032+
9033+ printk(KERN_ERR "PAX: bytes at PC: ");
9034+ for (i = 0; i < 8; i++) {
9035+ unsigned int c;
9036+ if (get_user(c, (unsigned int *)pc+i))
9037+ printk(KERN_CONT "???????? ");
9038+ else
9039+ printk(KERN_CONT "%08x ", c);
9040+ }
9041+ printk("\n");
9042+}
9043+#endif
9044+
9045 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
9046 int text_fault)
9047 {
9048@@ -230,6 +504,24 @@ good_area:
9049 if (!(vma->vm_flags & VM_WRITE))
9050 goto bad_area;
9051 } else {
9052+
9053+#ifdef CONFIG_PAX_PAGEEXEC
9054+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
9055+ up_read(&mm->mmap_sem);
9056+ switch (pax_handle_fetch_fault(regs)) {
9057+
9058+#ifdef CONFIG_PAX_EMUPLT
9059+ case 2:
9060+ case 3:
9061+ return;
9062+#endif
9063+
9064+ }
9065+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
9066+ do_group_exit(SIGKILL);
9067+ }
9068+#endif
9069+
9070 /* Allow reads even for write-only mappings */
9071 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
9072 goto bad_area;
9073diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
9074index 5062ff3..e0b75f3 100644
9075--- a/arch/sparc/mm/fault_64.c
9076+++ b/arch/sparc/mm/fault_64.c
9077@@ -21,6 +21,9 @@
9078 #include <linux/kprobes.h>
9079 #include <linux/kdebug.h>
9080 #include <linux/percpu.h>
9081+#include <linux/slab.h>
9082+#include <linux/pagemap.h>
9083+#include <linux/compiler.h>
9084
9085 #include <asm/page.h>
9086 #include <asm/pgtable.h>
9087@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
9088 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
9089 regs->tpc);
9090 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
9091- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
9092+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
9093 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
9094 dump_stack();
9095 unhandled_fault(regs->tpc, current, regs);
9096@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
9097 show_regs(regs);
9098 }
9099
9100+#ifdef CONFIG_PAX_PAGEEXEC
9101+#ifdef CONFIG_PAX_DLRESOLVE
9102+static void pax_emuplt_close(struct vm_area_struct *vma)
9103+{
9104+ vma->vm_mm->call_dl_resolve = 0UL;
9105+}
9106+
9107+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9108+{
9109+ unsigned int *kaddr;
9110+
9111+ vmf->page = alloc_page(GFP_HIGHUSER);
9112+ if (!vmf->page)
9113+ return VM_FAULT_OOM;
9114+
9115+ kaddr = kmap(vmf->page);
9116+ memset(kaddr, 0, PAGE_SIZE);
9117+ kaddr[0] = 0x9DE3BFA8U; /* save */
9118+ flush_dcache_page(vmf->page);
9119+ kunmap(vmf->page);
9120+ return VM_FAULT_MAJOR;
9121+}
9122+
9123+static const struct vm_operations_struct pax_vm_ops = {
9124+ .close = pax_emuplt_close,
9125+ .fault = pax_emuplt_fault
9126+};
9127+
9128+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9129+{
9130+ int ret;
9131+
9132+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9133+ vma->vm_mm = current->mm;
9134+ vma->vm_start = addr;
9135+ vma->vm_end = addr + PAGE_SIZE;
9136+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9137+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9138+ vma->vm_ops = &pax_vm_ops;
9139+
9140+ ret = insert_vm_struct(current->mm, vma);
9141+ if (ret)
9142+ return ret;
9143+
9144+ ++current->mm->total_vm;
9145+ return 0;
9146+}
9147+#endif
9148+
9149+/*
9150+ * PaX: decide what to do with offenders (regs->tpc = fault address)
9151+ *
9152+ * returns 1 when task should be killed
9153+ * 2 when patched PLT trampoline was detected
9154+ * 3 when unpatched PLT trampoline was detected
9155+ */
9156+static int pax_handle_fetch_fault(struct pt_regs *regs)
9157+{
9158+
9159+#ifdef CONFIG_PAX_EMUPLT
9160+ int err;
9161+
9162+ do { /* PaX: patched PLT emulation #1 */
9163+ unsigned int sethi1, sethi2, jmpl;
9164+
9165+ err = get_user(sethi1, (unsigned int *)regs->tpc);
9166+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
9167+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
9168+
9169+ if (err)
9170+ break;
9171+
9172+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9173+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9174+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9175+ {
9176+ unsigned long addr;
9177+
9178+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9179+ addr = regs->u_regs[UREG_G1];
9180+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9181+
9182+ if (test_thread_flag(TIF_32BIT))
9183+ addr &= 0xFFFFFFFFUL;
9184+
9185+ regs->tpc = addr;
9186+ regs->tnpc = addr+4;
9187+ return 2;
9188+ }
9189+ } while (0);
9190+
9191+ do { /* PaX: patched PLT emulation #2 */
9192+ unsigned int ba;
9193+
9194+ err = get_user(ba, (unsigned int *)regs->tpc);
9195+
9196+ if (err)
9197+ break;
9198+
9199+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9200+ unsigned long addr;
9201+
9202+ if ((ba & 0xFFC00000U) == 0x30800000U)
9203+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9204+ else
9205+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9206+
9207+ if (test_thread_flag(TIF_32BIT))
9208+ addr &= 0xFFFFFFFFUL;
9209+
9210+ regs->tpc = addr;
9211+ regs->tnpc = addr+4;
9212+ return 2;
9213+ }
9214+ } while (0);
9215+
9216+ do { /* PaX: patched PLT emulation #3 */
9217+ unsigned int sethi, bajmpl, nop;
9218+
9219+ err = get_user(sethi, (unsigned int *)regs->tpc);
9220+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
9221+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9222+
9223+ if (err)
9224+ break;
9225+
9226+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9227+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9228+ nop == 0x01000000U)
9229+ {
9230+ unsigned long addr;
9231+
9232+ addr = (sethi & 0x003FFFFFU) << 10;
9233+ regs->u_regs[UREG_G1] = addr;
9234+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9235+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9236+ else
9237+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9238+
9239+ if (test_thread_flag(TIF_32BIT))
9240+ addr &= 0xFFFFFFFFUL;
9241+
9242+ regs->tpc = addr;
9243+ regs->tnpc = addr+4;
9244+ return 2;
9245+ }
9246+ } while (0);
9247+
9248+ do { /* PaX: patched PLT emulation #4 */
9249+ unsigned int sethi, mov1, call, mov2;
9250+
9251+ err = get_user(sethi, (unsigned int *)regs->tpc);
9252+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
9253+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
9254+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
9255+
9256+ if (err)
9257+ break;
9258+
9259+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9260+ mov1 == 0x8210000FU &&
9261+ (call & 0xC0000000U) == 0x40000000U &&
9262+ mov2 == 0x9E100001U)
9263+ {
9264+ unsigned long addr;
9265+
9266+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
9267+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9268+
9269+ if (test_thread_flag(TIF_32BIT))
9270+ addr &= 0xFFFFFFFFUL;
9271+
9272+ regs->tpc = addr;
9273+ regs->tnpc = addr+4;
9274+ return 2;
9275+ }
9276+ } while (0);
9277+
9278+ do { /* PaX: patched PLT emulation #5 */
9279+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
9280+
9281+ err = get_user(sethi, (unsigned int *)regs->tpc);
9282+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9283+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9284+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
9285+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
9286+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
9287+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
9288+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
9289+
9290+ if (err)
9291+ break;
9292+
9293+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9294+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
9295+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9296+ (or1 & 0xFFFFE000U) == 0x82106000U &&
9297+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
9298+ sllx == 0x83287020U &&
9299+ jmpl == 0x81C04005U &&
9300+ nop == 0x01000000U)
9301+ {
9302+ unsigned long addr;
9303+
9304+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9305+ regs->u_regs[UREG_G1] <<= 32;
9306+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9307+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9308+ regs->tpc = addr;
9309+ regs->tnpc = addr+4;
9310+ return 2;
9311+ }
9312+ } while (0);
9313+
9314+ do { /* PaX: patched PLT emulation #6 */
9315+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
9316+
9317+ err = get_user(sethi, (unsigned int *)regs->tpc);
9318+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9319+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9320+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
9321+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
9322+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
9323+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
9324+
9325+ if (err)
9326+ break;
9327+
9328+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9329+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
9330+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9331+ sllx == 0x83287020U &&
9332+ (or & 0xFFFFE000U) == 0x8A116000U &&
9333+ jmpl == 0x81C04005U &&
9334+ nop == 0x01000000U)
9335+ {
9336+ unsigned long addr;
9337+
9338+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
9339+ regs->u_regs[UREG_G1] <<= 32;
9340+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
9341+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9342+ regs->tpc = addr;
9343+ regs->tnpc = addr+4;
9344+ return 2;
9345+ }
9346+ } while (0);
9347+
9348+ do { /* PaX: unpatched PLT emulation step 1 */
9349+ unsigned int sethi, ba, nop;
9350+
9351+ err = get_user(sethi, (unsigned int *)regs->tpc);
9352+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9353+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9354+
9355+ if (err)
9356+ break;
9357+
9358+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9359+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9360+ nop == 0x01000000U)
9361+ {
9362+ unsigned long addr;
9363+ unsigned int save, call;
9364+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
9365+
9366+ if ((ba & 0xFFC00000U) == 0x30800000U)
9367+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9368+ else
9369+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9370+
9371+ if (test_thread_flag(TIF_32BIT))
9372+ addr &= 0xFFFFFFFFUL;
9373+
9374+ err = get_user(save, (unsigned int *)addr);
9375+ err |= get_user(call, (unsigned int *)(addr+4));
9376+ err |= get_user(nop, (unsigned int *)(addr+8));
9377+ if (err)
9378+ break;
9379+
9380+#ifdef CONFIG_PAX_DLRESOLVE
9381+ if (save == 0x9DE3BFA8U &&
9382+ (call & 0xC0000000U) == 0x40000000U &&
9383+ nop == 0x01000000U)
9384+ {
9385+ struct vm_area_struct *vma;
9386+ unsigned long call_dl_resolve;
9387+
9388+ down_read(&current->mm->mmap_sem);
9389+ call_dl_resolve = current->mm->call_dl_resolve;
9390+ up_read(&current->mm->mmap_sem);
9391+ if (likely(call_dl_resolve))
9392+ goto emulate;
9393+
9394+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9395+
9396+ down_write(&current->mm->mmap_sem);
9397+ if (current->mm->call_dl_resolve) {
9398+ call_dl_resolve = current->mm->call_dl_resolve;
9399+ up_write(&current->mm->mmap_sem);
9400+ if (vma)
9401+ kmem_cache_free(vm_area_cachep, vma);
9402+ goto emulate;
9403+ }
9404+
9405+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9406+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9407+ up_write(&current->mm->mmap_sem);
9408+ if (vma)
9409+ kmem_cache_free(vm_area_cachep, vma);
9410+ return 1;
9411+ }
9412+
9413+ if (pax_insert_vma(vma, call_dl_resolve)) {
9414+ up_write(&current->mm->mmap_sem);
9415+ kmem_cache_free(vm_area_cachep, vma);
9416+ return 1;
9417+ }
9418+
9419+ current->mm->call_dl_resolve = call_dl_resolve;
9420+ up_write(&current->mm->mmap_sem);
9421+
9422+emulate:
9423+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9424+ regs->tpc = call_dl_resolve;
9425+ regs->tnpc = addr+4;
9426+ return 3;
9427+ }
9428+#endif
9429+
9430+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9431+ if ((save & 0xFFC00000U) == 0x05000000U &&
9432+ (call & 0xFFFFE000U) == 0x85C0A000U &&
9433+ nop == 0x01000000U)
9434+ {
9435+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9436+ regs->u_regs[UREG_G2] = addr + 4;
9437+ addr = (save & 0x003FFFFFU) << 10;
9438+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9439+
9440+ if (test_thread_flag(TIF_32BIT))
9441+ addr &= 0xFFFFFFFFUL;
9442+
9443+ regs->tpc = addr;
9444+ regs->tnpc = addr+4;
9445+ return 3;
9446+ }
9447+
9448+ /* PaX: 64-bit PLT stub */
9449+ err = get_user(sethi1, (unsigned int *)addr);
9450+ err |= get_user(sethi2, (unsigned int *)(addr+4));
9451+ err |= get_user(or1, (unsigned int *)(addr+8));
9452+ err |= get_user(or2, (unsigned int *)(addr+12));
9453+ err |= get_user(sllx, (unsigned int *)(addr+16));
9454+ err |= get_user(add, (unsigned int *)(addr+20));
9455+ err |= get_user(jmpl, (unsigned int *)(addr+24));
9456+ err |= get_user(nop, (unsigned int *)(addr+28));
9457+ if (err)
9458+ break;
9459+
9460+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
9461+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9462+ (or1 & 0xFFFFE000U) == 0x88112000U &&
9463+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
9464+ sllx == 0x89293020U &&
9465+ add == 0x8A010005U &&
9466+ jmpl == 0x89C14000U &&
9467+ nop == 0x01000000U)
9468+ {
9469+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9470+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9471+ regs->u_regs[UREG_G4] <<= 32;
9472+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9473+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
9474+ regs->u_regs[UREG_G4] = addr + 24;
9475+ addr = regs->u_regs[UREG_G5];
9476+ regs->tpc = addr;
9477+ regs->tnpc = addr+4;
9478+ return 3;
9479+ }
9480+ }
9481+ } while (0);
9482+
9483+#ifdef CONFIG_PAX_DLRESOLVE
9484+ do { /* PaX: unpatched PLT emulation step 2 */
9485+ unsigned int save, call, nop;
9486+
9487+ err = get_user(save, (unsigned int *)(regs->tpc-4));
9488+ err |= get_user(call, (unsigned int *)regs->tpc);
9489+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
9490+ if (err)
9491+ break;
9492+
9493+ if (save == 0x9DE3BFA8U &&
9494+ (call & 0xC0000000U) == 0x40000000U &&
9495+ nop == 0x01000000U)
9496+ {
9497+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9498+
9499+ if (test_thread_flag(TIF_32BIT))
9500+ dl_resolve &= 0xFFFFFFFFUL;
9501+
9502+ regs->u_regs[UREG_RETPC] = regs->tpc;
9503+ regs->tpc = dl_resolve;
9504+ regs->tnpc = dl_resolve+4;
9505+ return 3;
9506+ }
9507+ } while (0);
9508+#endif
9509+
9510+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
9511+ unsigned int sethi, ba, nop;
9512+
9513+ err = get_user(sethi, (unsigned int *)regs->tpc);
9514+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9515+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9516+
9517+ if (err)
9518+ break;
9519+
9520+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9521+ (ba & 0xFFF00000U) == 0x30600000U &&
9522+ nop == 0x01000000U)
9523+ {
9524+ unsigned long addr;
9525+
9526+ addr = (sethi & 0x003FFFFFU) << 10;
9527+ regs->u_regs[UREG_G1] = addr;
9528+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9529+
9530+ if (test_thread_flag(TIF_32BIT))
9531+ addr &= 0xFFFFFFFFUL;
9532+
9533+ regs->tpc = addr;
9534+ regs->tnpc = addr+4;
9535+ return 2;
9536+ }
9537+ } while (0);
9538+
9539+#endif
9540+
9541+ return 1;
9542+}
9543+
9544+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9545+{
9546+ unsigned long i;
9547+
9548+ printk(KERN_ERR "PAX: bytes at PC: ");
9549+ for (i = 0; i < 8; i++) {
9550+ unsigned int c;
9551+ if (get_user(c, (unsigned int *)pc+i))
9552+ printk(KERN_CONT "???????? ");
9553+ else
9554+ printk(KERN_CONT "%08x ", c);
9555+ }
9556+ printk("\n");
9557+}
9558+#endif
9559+
9560 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
9561 {
9562 struct mm_struct *mm = current->mm;
9563@@ -341,6 +804,29 @@ retry:
9564 if (!vma)
9565 goto bad_area;
9566
9567+#ifdef CONFIG_PAX_PAGEEXEC
9568+ /* PaX: detect ITLB misses on non-exec pages */
9569+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
9570+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
9571+ {
9572+ if (address != regs->tpc)
9573+ goto good_area;
9574+
9575+ up_read(&mm->mmap_sem);
9576+ switch (pax_handle_fetch_fault(regs)) {
9577+
9578+#ifdef CONFIG_PAX_EMUPLT
9579+ case 2:
9580+ case 3:
9581+ return;
9582+#endif
9583+
9584+ }
9585+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
9586+ do_group_exit(SIGKILL);
9587+ }
9588+#endif
9589+
9590 /* Pure DTLB misses do not tell us whether the fault causing
9591 * load/store/atomic was a write or not, it only says that there
9592 * was no match. So in such a case we (carefully) read the
9593diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
9594index d2b5944..bd813f2 100644
9595--- a/arch/sparc/mm/hugetlbpage.c
9596+++ b/arch/sparc/mm/hugetlbpage.c
9597@@ -38,7 +38,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9598
9599 info.flags = 0;
9600 info.length = len;
9601- info.low_limit = TASK_UNMAPPED_BASE;
9602+ info.low_limit = mm->mmap_base;
9603 info.high_limit = min(task_size, VA_EXCLUDE_START);
9604 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
9605 info.align_offset = 0;
9606@@ -47,6 +47,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9607 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9608 VM_BUG_ON(addr != -ENOMEM);
9609 info.low_limit = VA_EXCLUDE_END;
9610+
9611+#ifdef CONFIG_PAX_RANDMMAP
9612+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9613+ info.low_limit += mm->delta_mmap;
9614+#endif
9615+
9616 info.high_limit = task_size;
9617 addr = vm_unmapped_area(&info);
9618 }
9619@@ -85,6 +91,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9620 VM_BUG_ON(addr != -ENOMEM);
9621 info.flags = 0;
9622 info.low_limit = TASK_UNMAPPED_BASE;
9623+
9624+#ifdef CONFIG_PAX_RANDMMAP
9625+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9626+ info.low_limit += mm->delta_mmap;
9627+#endif
9628+
9629 info.high_limit = STACK_TOP32;
9630 addr = vm_unmapped_area(&info);
9631 }
9632@@ -99,6 +111,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9633 struct mm_struct *mm = current->mm;
9634 struct vm_area_struct *vma;
9635 unsigned long task_size = TASK_SIZE;
9636+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
9637
9638 if (test_thread_flag(TIF_32BIT))
9639 task_size = STACK_TOP32;
9640@@ -114,11 +127,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9641 return addr;
9642 }
9643
9644+#ifdef CONFIG_PAX_RANDMMAP
9645+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9646+#endif
9647+
9648 if (addr) {
9649 addr = ALIGN(addr, HPAGE_SIZE);
9650 vma = find_vma(mm, addr);
9651- if (task_size - len >= addr &&
9652- (!vma || addr + len <= vma->vm_start))
9653+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9654 return addr;
9655 }
9656 if (mm->get_unmapped_area == arch_get_unmapped_area)
9657diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
9658index f4500c6..889656c 100644
9659--- a/arch/tile/include/asm/atomic_64.h
9660+++ b/arch/tile/include/asm/atomic_64.h
9661@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9662
9663 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9664
9665+#define atomic64_read_unchecked(v) atomic64_read(v)
9666+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9667+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9668+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9669+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9670+#define atomic64_inc_unchecked(v) atomic64_inc(v)
9671+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9672+#define atomic64_dec_unchecked(v) atomic64_dec(v)
9673+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9674+
9675 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
9676 #define smp_mb__before_atomic_dec() smp_mb()
9677 #define smp_mb__after_atomic_dec() smp_mb()
9678diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
9679index a9a5299..0fce79e 100644
9680--- a/arch/tile/include/asm/cache.h
9681+++ b/arch/tile/include/asm/cache.h
9682@@ -15,11 +15,12 @@
9683 #ifndef _ASM_TILE_CACHE_H
9684 #define _ASM_TILE_CACHE_H
9685
9686+#include <linux/const.h>
9687 #include <arch/chip.h>
9688
9689 /* bytes per L1 data cache line */
9690 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
9691-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9692+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9693
9694 /* bytes per L2 cache line */
9695 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
9696diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
9697index 9ab078a..d6635c2 100644
9698--- a/arch/tile/include/asm/uaccess.h
9699+++ b/arch/tile/include/asm/uaccess.h
9700@@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
9701 const void __user *from,
9702 unsigned long n)
9703 {
9704- int sz = __compiletime_object_size(to);
9705+ size_t sz = __compiletime_object_size(to);
9706
9707- if (likely(sz == -1 || sz >= n))
9708+ if (likely(sz == (size_t)-1 || sz >= n))
9709 n = _copy_from_user(to, from, n);
9710 else
9711 copy_from_user_overflow();
9712diff --git a/arch/um/Makefile b/arch/um/Makefile
9713index 133f7de..1d6f2f1 100644
9714--- a/arch/um/Makefile
9715+++ b/arch/um/Makefile
9716@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
9717 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
9718 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
9719
9720+ifdef CONSTIFY_PLUGIN
9721+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
9722+endif
9723+
9724 #This will adjust *FLAGS accordingly to the platform.
9725 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
9726
9727diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
9728index 19e1bdd..3665b77 100644
9729--- a/arch/um/include/asm/cache.h
9730+++ b/arch/um/include/asm/cache.h
9731@@ -1,6 +1,7 @@
9732 #ifndef __UM_CACHE_H
9733 #define __UM_CACHE_H
9734
9735+#include <linux/const.h>
9736
9737 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
9738 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
9739@@ -12,6 +13,6 @@
9740 # define L1_CACHE_SHIFT 5
9741 #endif
9742
9743-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9744+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9745
9746 #endif
9747diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
9748index 2e0a6b1..a64d0f5 100644
9749--- a/arch/um/include/asm/kmap_types.h
9750+++ b/arch/um/include/asm/kmap_types.h
9751@@ -8,6 +8,6 @@
9752
9753 /* No more #include "asm/arch/kmap_types.h" ! */
9754
9755-#define KM_TYPE_NR 14
9756+#define KM_TYPE_NR 15
9757
9758 #endif
9759diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
9760index 5ff53d9..5850cdf 100644
9761--- a/arch/um/include/asm/page.h
9762+++ b/arch/um/include/asm/page.h
9763@@ -14,6 +14,9 @@
9764 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
9765 #define PAGE_MASK (~(PAGE_SIZE-1))
9766
9767+#define ktla_ktva(addr) (addr)
9768+#define ktva_ktla(addr) (addr)
9769+
9770 #ifndef __ASSEMBLY__
9771
9772 struct page;
9773diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
9774index 0032f92..cd151e0 100644
9775--- a/arch/um/include/asm/pgtable-3level.h
9776+++ b/arch/um/include/asm/pgtable-3level.h
9777@@ -58,6 +58,7 @@
9778 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
9779 #define pud_populate(mm, pud, pmd) \
9780 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
9781+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
9782
9783 #ifdef CONFIG_64BIT
9784 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
9785diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
9786index b462b13..e7a19aa 100644
9787--- a/arch/um/kernel/process.c
9788+++ b/arch/um/kernel/process.c
9789@@ -386,22 +386,6 @@ int singlestepping(void * t)
9790 return 2;
9791 }
9792
9793-/*
9794- * Only x86 and x86_64 have an arch_align_stack().
9795- * All other arches have "#define arch_align_stack(x) (x)"
9796- * in their asm/system.h
9797- * As this is included in UML from asm-um/system-generic.h,
9798- * we can use it to behave as the subarch does.
9799- */
9800-#ifndef arch_align_stack
9801-unsigned long arch_align_stack(unsigned long sp)
9802-{
9803- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9804- sp -= get_random_int() % 8192;
9805- return sp & ~0xf;
9806-}
9807-#endif
9808-
9809 unsigned long get_wchan(struct task_struct *p)
9810 {
9811 unsigned long stack_page, sp, ip;
9812diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
9813index ad8f795..2c7eec6 100644
9814--- a/arch/unicore32/include/asm/cache.h
9815+++ b/arch/unicore32/include/asm/cache.h
9816@@ -12,8 +12,10 @@
9817 #ifndef __UNICORE_CACHE_H__
9818 #define __UNICORE_CACHE_H__
9819
9820-#define L1_CACHE_SHIFT (5)
9821-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9822+#include <linux/const.h>
9823+
9824+#define L1_CACHE_SHIFT 5
9825+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9826
9827 /*
9828 * Memory returned by kmalloc() may be used for DMA, so we must make
9829diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
9830index 0694d09..b58b3aa 100644
9831--- a/arch/x86/Kconfig
9832+++ b/arch/x86/Kconfig
9833@@ -238,7 +238,7 @@ config X86_HT
9834
9835 config X86_32_LAZY_GS
9836 def_bool y
9837- depends on X86_32 && !CC_STACKPROTECTOR
9838+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
9839
9840 config ARCH_HWEIGHT_CFLAGS
9841 string
9842@@ -1031,6 +1031,7 @@ config MICROCODE_OLD_INTERFACE
9843
9844 config X86_MSR
9845 tristate "/dev/cpu/*/msr - Model-specific register support"
9846+ depends on !GRKERNSEC_KMEM
9847 ---help---
9848 This device gives privileged processes access to the x86
9849 Model-Specific Registers (MSRs). It is a character device with
9850@@ -1054,7 +1055,7 @@ choice
9851
9852 config NOHIGHMEM
9853 bool "off"
9854- depends on !X86_NUMAQ
9855+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
9856 ---help---
9857 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
9858 However, the address space of 32-bit x86 processors is only 4
9859@@ -1091,7 +1092,7 @@ config NOHIGHMEM
9860
9861 config HIGHMEM4G
9862 bool "4GB"
9863- depends on !X86_NUMAQ
9864+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
9865 ---help---
9866 Select this if you have a 32-bit processor and between 1 and 4
9867 gigabytes of physical RAM.
9868@@ -1145,7 +1146,7 @@ config PAGE_OFFSET
9869 hex
9870 default 0xB0000000 if VMSPLIT_3G_OPT
9871 default 0x80000000 if VMSPLIT_2G
9872- default 0x78000000 if VMSPLIT_2G_OPT
9873+ default 0x70000000 if VMSPLIT_2G_OPT
9874 default 0x40000000 if VMSPLIT_1G
9875 default 0xC0000000
9876 depends on X86_32
9877@@ -1542,6 +1543,7 @@ config SECCOMP
9878
9879 config CC_STACKPROTECTOR
9880 bool "Enable -fstack-protector buffer overflow detection"
9881+ depends on X86_64 || !PAX_MEMORY_UDEREF
9882 ---help---
9883 This option turns on the -fstack-protector GCC feature. This
9884 feature puts, at the beginning of functions, a canary value on
9885@@ -1599,6 +1601,7 @@ config KEXEC_JUMP
9886 config PHYSICAL_START
9887 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
9888 default "0x1000000"
9889+ range 0x400000 0x40000000
9890 ---help---
9891 This gives the physical address where the kernel is loaded.
9892
9893@@ -1662,6 +1665,7 @@ config X86_NEED_RELOCS
9894 config PHYSICAL_ALIGN
9895 hex "Alignment value to which kernel should be aligned" if X86_32
9896 default "0x1000000"
9897+ range 0x400000 0x1000000 if PAX_KERNEXEC
9898 range 0x2000 0x1000000
9899 ---help---
9900 This value puts the alignment restrictions on physical address
9901@@ -1737,9 +1741,10 @@ config DEBUG_HOTPLUG_CPU0
9902 If unsure, say N.
9903
9904 config COMPAT_VDSO
9905- def_bool y
9906+ def_bool n
9907 prompt "Compat VDSO support"
9908 depends on X86_32 || IA32_EMULATION
9909+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
9910 ---help---
9911 Map the 32-bit VDSO to the predictable old-style address too.
9912
9913diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
9914index c026cca..14657ae 100644
9915--- a/arch/x86/Kconfig.cpu
9916+++ b/arch/x86/Kconfig.cpu
9917@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
9918
9919 config X86_F00F_BUG
9920 def_bool y
9921- depends on M586MMX || M586TSC || M586 || M486
9922+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
9923
9924 config X86_INVD_BUG
9925 def_bool y
9926@@ -327,7 +327,7 @@ config X86_INVD_BUG
9927
9928 config X86_ALIGNMENT_16
9929 def_bool y
9930- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
9931+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
9932
9933 config X86_INTEL_USERCOPY
9934 def_bool y
9935@@ -373,7 +373,7 @@ config X86_CMPXCHG64
9936 # generates cmov.
9937 config X86_CMOV
9938 def_bool y
9939- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
9940+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
9941
9942 config X86_MINIMUM_CPU_FAMILY
9943 int
9944diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
9945index b322f12..652d0d9 100644
9946--- a/arch/x86/Kconfig.debug
9947+++ b/arch/x86/Kconfig.debug
9948@@ -84,7 +84,7 @@ config X86_PTDUMP
9949 config DEBUG_RODATA
9950 bool "Write protect kernel read-only data structures"
9951 default y
9952- depends on DEBUG_KERNEL
9953+ depends on DEBUG_KERNEL && BROKEN
9954 ---help---
9955 Mark the kernel read-only data as write-protected in the pagetables,
9956 in order to catch accidental (and incorrect) writes to such const
9957@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
9958
9959 config DEBUG_SET_MODULE_RONX
9960 bool "Set loadable kernel module data as NX and text as RO"
9961- depends on MODULES
9962+ depends on MODULES && BROKEN
9963 ---help---
9964 This option helps catch unintended modifications to loadable
9965 kernel module's text and read-only data. It also prevents execution
9966@@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
9967
9968 config DEBUG_STRICT_USER_COPY_CHECKS
9969 bool "Strict copy size checks"
9970- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
9971+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
9972 ---help---
9973 Enabling this option turns a certain set of sanity checks for user
9974 copy operations into compile time failures.
9975diff --git a/arch/x86/Makefile b/arch/x86/Makefile
9976index e71fc42..7829607 100644
9977--- a/arch/x86/Makefile
9978+++ b/arch/x86/Makefile
9979@@ -50,6 +50,7 @@ else
9980 UTS_MACHINE := x86_64
9981 CHECKFLAGS += -D__x86_64__ -m64
9982
9983+ biarch := $(call cc-option,-m64)
9984 KBUILD_AFLAGS += -m64
9985 KBUILD_CFLAGS += -m64
9986
9987@@ -230,3 +231,12 @@ define archhelp
9988 echo ' FDARGS="..." arguments for the booted kernel'
9989 echo ' FDINITRD=file initrd for the booted kernel'
9990 endef
9991+
9992+define OLD_LD
9993+
9994+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
9995+*** Please upgrade your binutils to 2.18 or newer
9996+endef
9997+
9998+archprepare:
9999+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
10000diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
10001index 379814b..add62ce 100644
10002--- a/arch/x86/boot/Makefile
10003+++ b/arch/x86/boot/Makefile
10004@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
10005 $(call cc-option, -fno-stack-protector) \
10006 $(call cc-option, -mpreferred-stack-boundary=2)
10007 KBUILD_CFLAGS += $(call cc-option, -m32)
10008+ifdef CONSTIFY_PLUGIN
10009+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10010+endif
10011 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10012 GCOV_PROFILE := n
10013
10014diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
10015index 878e4b9..20537ab 100644
10016--- a/arch/x86/boot/bitops.h
10017+++ b/arch/x86/boot/bitops.h
10018@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10019 u8 v;
10020 const u32 *p = (const u32 *)addr;
10021
10022- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10023+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10024 return v;
10025 }
10026
10027@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10028
10029 static inline void set_bit(int nr, void *addr)
10030 {
10031- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10032+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10033 }
10034
10035 #endif /* BOOT_BITOPS_H */
10036diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
10037index 18997e5..83d9c67 100644
10038--- a/arch/x86/boot/boot.h
10039+++ b/arch/x86/boot/boot.h
10040@@ -85,7 +85,7 @@ static inline void io_delay(void)
10041 static inline u16 ds(void)
10042 {
10043 u16 seg;
10044- asm("movw %%ds,%0" : "=rm" (seg));
10045+ asm volatile("movw %%ds,%0" : "=rm" (seg));
10046 return seg;
10047 }
10048
10049@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
10050 static inline int memcmp(const void *s1, const void *s2, size_t len)
10051 {
10052 u8 diff;
10053- asm("repe; cmpsb; setnz %0"
10054+ asm volatile("repe; cmpsb; setnz %0"
10055 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
10056 return diff;
10057 }
10058diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
10059index 8a84501..b2d165f 100644
10060--- a/arch/x86/boot/compressed/Makefile
10061+++ b/arch/x86/boot/compressed/Makefile
10062@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
10063 KBUILD_CFLAGS += $(cflags-y)
10064 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
10065 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
10066+ifdef CONSTIFY_PLUGIN
10067+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10068+endif
10069
10070 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10071 GCOV_PROFILE := n
10072diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
10073index f8fa411..c570c53 100644
10074--- a/arch/x86/boot/compressed/eboot.c
10075+++ b/arch/x86/boot/compressed/eboot.c
10076@@ -145,7 +145,6 @@ again:
10077 *addr = max_addr;
10078 }
10079
10080-free_pool:
10081 efi_call_phys1(sys_table->boottime->free_pool, map);
10082
10083 fail:
10084@@ -209,7 +208,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
10085 if (i == map_size / desc_size)
10086 status = EFI_NOT_FOUND;
10087
10088-free_pool:
10089 efi_call_phys1(sys_table->boottime->free_pool, map);
10090 fail:
10091 return status;
10092diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
10093index 1e3184f..0d11e2e 100644
10094--- a/arch/x86/boot/compressed/head_32.S
10095+++ b/arch/x86/boot/compressed/head_32.S
10096@@ -118,7 +118,7 @@ preferred_addr:
10097 notl %eax
10098 andl %eax, %ebx
10099 #else
10100- movl $LOAD_PHYSICAL_ADDR, %ebx
10101+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10102 #endif
10103
10104 /* Target address to relocate to for decompression */
10105@@ -204,7 +204,7 @@ relocated:
10106 * and where it was actually loaded.
10107 */
10108 movl %ebp, %ebx
10109- subl $LOAD_PHYSICAL_ADDR, %ebx
10110+ subl $____LOAD_PHYSICAL_ADDR, %ebx
10111 jz 2f /* Nothing to be done if loaded at compiled addr. */
10112 /*
10113 * Process relocations.
10114@@ -212,8 +212,7 @@ relocated:
10115
10116 1: subl $4, %edi
10117 movl (%edi), %ecx
10118- testl %ecx, %ecx
10119- jz 2f
10120+ jecxz 2f
10121 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
10122 jmp 1b
10123 2:
10124diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
10125index f5d1aaa..cce11dc 100644
10126--- a/arch/x86/boot/compressed/head_64.S
10127+++ b/arch/x86/boot/compressed/head_64.S
10128@@ -91,7 +91,7 @@ ENTRY(startup_32)
10129 notl %eax
10130 andl %eax, %ebx
10131 #else
10132- movl $LOAD_PHYSICAL_ADDR, %ebx
10133+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10134 #endif
10135
10136 /* Target address to relocate to for decompression */
10137@@ -273,7 +273,7 @@ preferred_addr:
10138 notq %rax
10139 andq %rax, %rbp
10140 #else
10141- movq $LOAD_PHYSICAL_ADDR, %rbp
10142+ movq $____LOAD_PHYSICAL_ADDR, %rbp
10143 #endif
10144
10145 /* Target address to relocate to for decompression */
10146diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
10147index 88f7ff6..ed695dd 100644
10148--- a/arch/x86/boot/compressed/misc.c
10149+++ b/arch/x86/boot/compressed/misc.c
10150@@ -303,7 +303,7 @@ static void parse_elf(void *output)
10151 case PT_LOAD:
10152 #ifdef CONFIG_RELOCATABLE
10153 dest = output;
10154- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
10155+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
10156 #else
10157 dest = (void *)(phdr->p_paddr);
10158 #endif
10159@@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
10160 error("Destination address too large");
10161 #endif
10162 #ifndef CONFIG_RELOCATABLE
10163- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
10164+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
10165 error("Wrong destination address");
10166 #endif
10167
10168diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
10169index 4d3ff03..e4972ff 100644
10170--- a/arch/x86/boot/cpucheck.c
10171+++ b/arch/x86/boot/cpucheck.c
10172@@ -74,7 +74,7 @@ static int has_fpu(void)
10173 u16 fcw = -1, fsw = -1;
10174 u32 cr0;
10175
10176- asm("movl %%cr0,%0" : "=r" (cr0));
10177+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
10178 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
10179 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
10180 asm volatile("movl %0,%%cr0" : : "r" (cr0));
10181@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
10182 {
10183 u32 f0, f1;
10184
10185- asm("pushfl ; "
10186+ asm volatile("pushfl ; "
10187 "pushfl ; "
10188 "popl %0 ; "
10189 "movl %0,%1 ; "
10190@@ -115,7 +115,7 @@ static void get_flags(void)
10191 set_bit(X86_FEATURE_FPU, cpu.flags);
10192
10193 if (has_eflag(X86_EFLAGS_ID)) {
10194- asm("cpuid"
10195+ asm volatile("cpuid"
10196 : "=a" (max_intel_level),
10197 "=b" (cpu_vendor[0]),
10198 "=d" (cpu_vendor[1]),
10199@@ -124,7 +124,7 @@ static void get_flags(void)
10200
10201 if (max_intel_level >= 0x00000001 &&
10202 max_intel_level <= 0x0000ffff) {
10203- asm("cpuid"
10204+ asm volatile("cpuid"
10205 : "=a" (tfms),
10206 "=c" (cpu.flags[4]),
10207 "=d" (cpu.flags[0])
10208@@ -136,7 +136,7 @@ static void get_flags(void)
10209 cpu.model += ((tfms >> 16) & 0xf) << 4;
10210 }
10211
10212- asm("cpuid"
10213+ asm volatile("cpuid"
10214 : "=a" (max_amd_level)
10215 : "a" (0x80000000)
10216 : "ebx", "ecx", "edx");
10217@@ -144,7 +144,7 @@ static void get_flags(void)
10218 if (max_amd_level >= 0x80000001 &&
10219 max_amd_level <= 0x8000ffff) {
10220 u32 eax = 0x80000001;
10221- asm("cpuid"
10222+ asm volatile("cpuid"
10223 : "+a" (eax),
10224 "=c" (cpu.flags[6]),
10225 "=d" (cpu.flags[1])
10226@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10227 u32 ecx = MSR_K7_HWCR;
10228 u32 eax, edx;
10229
10230- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10231+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10232 eax &= ~(1 << 15);
10233- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10234+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10235
10236 get_flags(); /* Make sure it really did something */
10237 err = check_flags();
10238@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10239 u32 ecx = MSR_VIA_FCR;
10240 u32 eax, edx;
10241
10242- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10243+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10244 eax |= (1<<1)|(1<<7);
10245- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10246+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10247
10248 set_bit(X86_FEATURE_CX8, cpu.flags);
10249 err = check_flags();
10250@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10251 u32 eax, edx;
10252 u32 level = 1;
10253
10254- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10255- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10256- asm("cpuid"
10257+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10258+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10259+ asm volatile("cpuid"
10260 : "+a" (level), "=d" (cpu.flags[0])
10261 : : "ecx", "ebx");
10262- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10263+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10264
10265 err = check_flags();
10266 }
10267diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
10268index 944ce59..87ee37a 100644
10269--- a/arch/x86/boot/header.S
10270+++ b/arch/x86/boot/header.S
10271@@ -401,10 +401,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
10272 # single linked list of
10273 # struct setup_data
10274
10275-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
10276+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
10277
10278 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
10279+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
10280+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
10281+#else
10282 #define VO_INIT_SIZE (VO__end - VO__text)
10283+#endif
10284 #if ZO_INIT_SIZE > VO_INIT_SIZE
10285 #define INIT_SIZE ZO_INIT_SIZE
10286 #else
10287diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
10288index db75d07..8e6d0af 100644
10289--- a/arch/x86/boot/memory.c
10290+++ b/arch/x86/boot/memory.c
10291@@ -19,7 +19,7 @@
10292
10293 static int detect_memory_e820(void)
10294 {
10295- int count = 0;
10296+ unsigned int count = 0;
10297 struct biosregs ireg, oreg;
10298 struct e820entry *desc = boot_params.e820_map;
10299 static struct e820entry buf; /* static so it is zeroed */
10300diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
10301index 11e8c6e..fdbb1ed 100644
10302--- a/arch/x86/boot/video-vesa.c
10303+++ b/arch/x86/boot/video-vesa.c
10304@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
10305
10306 boot_params.screen_info.vesapm_seg = oreg.es;
10307 boot_params.screen_info.vesapm_off = oreg.di;
10308+ boot_params.screen_info.vesapm_size = oreg.cx;
10309 }
10310
10311 /*
10312diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
10313index 43eda28..5ab5fdb 100644
10314--- a/arch/x86/boot/video.c
10315+++ b/arch/x86/boot/video.c
10316@@ -96,7 +96,7 @@ static void store_mode_params(void)
10317 static unsigned int get_entry(void)
10318 {
10319 char entry_buf[4];
10320- int i, len = 0;
10321+ unsigned int i, len = 0;
10322 int key;
10323 unsigned int v;
10324
10325diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
10326index 5b577d5..3c1fed4 100644
10327--- a/arch/x86/crypto/aes-x86_64-asm_64.S
10328+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
10329@@ -8,6 +8,8 @@
10330 * including this sentence is retained in full.
10331 */
10332
10333+#include <asm/alternative-asm.h>
10334+
10335 .extern crypto_ft_tab
10336 .extern crypto_it_tab
10337 .extern crypto_fl_tab
10338@@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
10339 je B192; \
10340 leaq 32(r9),r9;
10341
10342+#define ret pax_force_retaddr 0, 1; ret
10343+
10344 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
10345 movq r1,r2; \
10346 movq r3,r4; \
10347diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
10348index 3470624..201259d 100644
10349--- a/arch/x86/crypto/aesni-intel_asm.S
10350+++ b/arch/x86/crypto/aesni-intel_asm.S
10351@@ -31,6 +31,7 @@
10352
10353 #include <linux/linkage.h>
10354 #include <asm/inst.h>
10355+#include <asm/alternative-asm.h>
10356
10357 #ifdef __x86_64__
10358 .data
10359@@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
10360 pop %r14
10361 pop %r13
10362 pop %r12
10363+ pax_force_retaddr 0, 1
10364 ret
10365+ENDPROC(aesni_gcm_dec)
10366
10367
10368 /*****************************************************************************
10369@@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
10370 pop %r14
10371 pop %r13
10372 pop %r12
10373+ pax_force_retaddr 0, 1
10374 ret
10375+ENDPROC(aesni_gcm_enc)
10376
10377 #endif
10378
10379@@ -1714,6 +1719,7 @@ _key_expansion_256a:
10380 pxor %xmm1, %xmm0
10381 movaps %xmm0, (TKEYP)
10382 add $0x10, TKEYP
10383+ pax_force_retaddr_bts
10384 ret
10385
10386 .align 4
10387@@ -1738,6 +1744,7 @@ _key_expansion_192a:
10388 shufps $0b01001110, %xmm2, %xmm1
10389 movaps %xmm1, 0x10(TKEYP)
10390 add $0x20, TKEYP
10391+ pax_force_retaddr_bts
10392 ret
10393
10394 .align 4
10395@@ -1757,6 +1764,7 @@ _key_expansion_192b:
10396
10397 movaps %xmm0, (TKEYP)
10398 add $0x10, TKEYP
10399+ pax_force_retaddr_bts
10400 ret
10401
10402 .align 4
10403@@ -1769,6 +1777,7 @@ _key_expansion_256b:
10404 pxor %xmm1, %xmm2
10405 movaps %xmm2, (TKEYP)
10406 add $0x10, TKEYP
10407+ pax_force_retaddr_bts
10408 ret
10409
10410 /*
10411@@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
10412 #ifndef __x86_64__
10413 popl KEYP
10414 #endif
10415+ pax_force_retaddr 0, 1
10416 ret
10417+ENDPROC(aesni_set_key)
10418
10419 /*
10420 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
10421@@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
10422 popl KLEN
10423 popl KEYP
10424 #endif
10425+ pax_force_retaddr 0, 1
10426 ret
10427+ENDPROC(aesni_enc)
10428
10429 /*
10430 * _aesni_enc1: internal ABI
10431@@ -1959,6 +1972,7 @@ _aesni_enc1:
10432 AESENC KEY STATE
10433 movaps 0x70(TKEYP), KEY
10434 AESENCLAST KEY STATE
10435+ pax_force_retaddr_bts
10436 ret
10437
10438 /*
10439@@ -2067,6 +2081,7 @@ _aesni_enc4:
10440 AESENCLAST KEY STATE2
10441 AESENCLAST KEY STATE3
10442 AESENCLAST KEY STATE4
10443+ pax_force_retaddr_bts
10444 ret
10445
10446 /*
10447@@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
10448 popl KLEN
10449 popl KEYP
10450 #endif
10451+ pax_force_retaddr 0, 1
10452 ret
10453+ENDPROC(aesni_dec)
10454
10455 /*
10456 * _aesni_dec1: internal ABI
10457@@ -2146,6 +2163,7 @@ _aesni_dec1:
10458 AESDEC KEY STATE
10459 movaps 0x70(TKEYP), KEY
10460 AESDECLAST KEY STATE
10461+ pax_force_retaddr_bts
10462 ret
10463
10464 /*
10465@@ -2254,6 +2272,7 @@ _aesni_dec4:
10466 AESDECLAST KEY STATE2
10467 AESDECLAST KEY STATE3
10468 AESDECLAST KEY STATE4
10469+ pax_force_retaddr_bts
10470 ret
10471
10472 /*
10473@@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
10474 popl KEYP
10475 popl LEN
10476 #endif
10477+ pax_force_retaddr 0, 1
10478 ret
10479+ENDPROC(aesni_ecb_enc)
10480
10481 /*
10482 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10483@@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
10484 popl KEYP
10485 popl LEN
10486 #endif
10487+ pax_force_retaddr 0, 1
10488 ret
10489+ENDPROC(aesni_ecb_dec)
10490
10491 /*
10492 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10493@@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
10494 popl LEN
10495 popl IVP
10496 #endif
10497+ pax_force_retaddr 0, 1
10498 ret
10499+ENDPROC(aesni_cbc_enc)
10500
10501 /*
10502 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10503@@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
10504 popl LEN
10505 popl IVP
10506 #endif
10507+ pax_force_retaddr 0, 1
10508 ret
10509+ENDPROC(aesni_cbc_dec)
10510
10511 #ifdef __x86_64__
10512 .align 16
10513@@ -2526,6 +2553,7 @@ _aesni_inc_init:
10514 mov $1, TCTR_LOW
10515 MOVQ_R64_XMM TCTR_LOW INC
10516 MOVQ_R64_XMM CTR TCTR_LOW
10517+ pax_force_retaddr_bts
10518 ret
10519
10520 /*
10521@@ -2554,6 +2582,7 @@ _aesni_inc:
10522 .Linc_low:
10523 movaps CTR, IV
10524 PSHUFB_XMM BSWAP_MASK IV
10525+ pax_force_retaddr_bts
10526 ret
10527
10528 /*
10529@@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
10530 .Lctr_enc_ret:
10531 movups IV, (IVP)
10532 .Lctr_enc_just_ret:
10533+ pax_force_retaddr 0, 1
10534 ret
10535+ENDPROC(aesni_ctr_enc)
10536 #endif
10537diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10538index 391d245..67f35c2 100644
10539--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
10540+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10541@@ -20,6 +20,8 @@
10542 *
10543 */
10544
10545+#include <asm/alternative-asm.h>
10546+
10547 .file "blowfish-x86_64-asm.S"
10548 .text
10549
10550@@ -151,9 +153,11 @@ __blowfish_enc_blk:
10551 jnz __enc_xor;
10552
10553 write_block();
10554+ pax_force_retaddr 0, 1
10555 ret;
10556 __enc_xor:
10557 xor_block();
10558+ pax_force_retaddr 0, 1
10559 ret;
10560
10561 .align 8
10562@@ -188,6 +192,7 @@ blowfish_dec_blk:
10563
10564 movq %r11, %rbp;
10565
10566+ pax_force_retaddr 0, 1
10567 ret;
10568
10569 /**********************************************************************
10570@@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
10571
10572 popq %rbx;
10573 popq %rbp;
10574+ pax_force_retaddr 0, 1
10575 ret;
10576
10577 __enc_xor4:
10578@@ -349,6 +355,7 @@ __enc_xor4:
10579
10580 popq %rbx;
10581 popq %rbp;
10582+ pax_force_retaddr 0, 1
10583 ret;
10584
10585 .align 8
10586@@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
10587 popq %rbx;
10588 popq %rbp;
10589
10590+ pax_force_retaddr 0, 1
10591 ret;
10592
10593diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
10594index 0b33743..7a56206 100644
10595--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
10596+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
10597@@ -20,6 +20,8 @@
10598 *
10599 */
10600
10601+#include <asm/alternative-asm.h>
10602+
10603 .file "camellia-x86_64-asm_64.S"
10604 .text
10605
10606@@ -229,12 +231,14 @@ __enc_done:
10607 enc_outunpack(mov, RT1);
10608
10609 movq RRBP, %rbp;
10610+ pax_force_retaddr 0, 1
10611 ret;
10612
10613 __enc_xor:
10614 enc_outunpack(xor, RT1);
10615
10616 movq RRBP, %rbp;
10617+ pax_force_retaddr 0, 1
10618 ret;
10619
10620 .global camellia_dec_blk;
10621@@ -275,6 +279,7 @@ __dec_rounds16:
10622 dec_outunpack();
10623
10624 movq RRBP, %rbp;
10625+ pax_force_retaddr 0, 1
10626 ret;
10627
10628 /**********************************************************************
10629@@ -468,6 +473,7 @@ __enc2_done:
10630
10631 movq RRBP, %rbp;
10632 popq %rbx;
10633+ pax_force_retaddr 0, 1
10634 ret;
10635
10636 __enc2_xor:
10637@@ -475,6 +481,7 @@ __enc2_xor:
10638
10639 movq RRBP, %rbp;
10640 popq %rbx;
10641+ pax_force_retaddr 0, 1
10642 ret;
10643
10644 .global camellia_dec_blk_2way;
10645@@ -517,4 +524,5 @@ __dec2_rounds16:
10646
10647 movq RRBP, %rbp;
10648 movq RXOR, %rbx;
10649+ pax_force_retaddr 0, 1
10650 ret;
10651diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10652index 15b00ac..2071784 100644
10653--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10654+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10655@@ -23,6 +23,8 @@
10656 *
10657 */
10658
10659+#include <asm/alternative-asm.h>
10660+
10661 .file "cast5-avx-x86_64-asm_64.S"
10662
10663 .extern cast_s1
10664@@ -281,6 +283,7 @@ __skip_enc:
10665 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
10666 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
10667
10668+ pax_force_retaddr 0, 1
10669 ret;
10670
10671 .align 16
10672@@ -353,6 +356,7 @@ __dec_tail:
10673 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
10674 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
10675
10676+ pax_force_retaddr 0, 1
10677 ret;
10678
10679 __skip_dec:
10680@@ -392,6 +396,7 @@ cast5_ecb_enc_16way:
10681 vmovdqu RR4, (6*4*4)(%r11);
10682 vmovdqu RL4, (7*4*4)(%r11);
10683
10684+ pax_force_retaddr
10685 ret;
10686
10687 .align 16
10688@@ -427,6 +432,7 @@ cast5_ecb_dec_16way:
10689 vmovdqu RR4, (6*4*4)(%r11);
10690 vmovdqu RL4, (7*4*4)(%r11);
10691
10692+ pax_force_retaddr
10693 ret;
10694
10695 .align 16
10696@@ -479,6 +485,7 @@ cast5_cbc_dec_16way:
10697
10698 popq %r12;
10699
10700+ pax_force_retaddr
10701 ret;
10702
10703 .align 16
10704@@ -555,4 +562,5 @@ cast5_ctr_16way:
10705
10706 popq %r12;
10707
10708+ pax_force_retaddr
10709 ret;
10710diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
10711index 2569d0d..637c289 100644
10712--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
10713+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
10714@@ -23,6 +23,8 @@
10715 *
10716 */
10717
10718+#include <asm/alternative-asm.h>
10719+
10720 #include "glue_helper-asm-avx.S"
10721
10722 .file "cast6-avx-x86_64-asm_64.S"
10723@@ -294,6 +296,7 @@ __cast6_enc_blk8:
10724 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
10725 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
10726
10727+ pax_force_retaddr 0, 1
10728 ret;
10729
10730 .align 8
10731@@ -340,6 +343,7 @@ __cast6_dec_blk8:
10732 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
10733 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
10734
10735+ pax_force_retaddr 0, 1
10736 ret;
10737
10738 .align 8
10739@@ -361,6 +365,7 @@ cast6_ecb_enc_8way:
10740
10741 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10742
10743+ pax_force_retaddr
10744 ret;
10745
10746 .align 8
10747@@ -382,6 +387,7 @@ cast6_ecb_dec_8way:
10748
10749 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10750
10751+ pax_force_retaddr
10752 ret;
10753
10754 .align 8
10755@@ -408,6 +414,7 @@ cast6_cbc_dec_8way:
10756
10757 popq %r12;
10758
10759+ pax_force_retaddr
10760 ret;
10761
10762 .align 8
10763@@ -436,4 +443,5 @@ cast6_ctr_8way:
10764
10765 popq %r12;
10766
10767+ pax_force_retaddr
10768 ret;
10769diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
10770index 6214a9b..1f4fc9a 100644
10771--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
10772+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
10773@@ -1,3 +1,5 @@
10774+#include <asm/alternative-asm.h>
10775+
10776 # enter ECRYPT_encrypt_bytes
10777 .text
10778 .p2align 5
10779@@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
10780 add %r11,%rsp
10781 mov %rdi,%rax
10782 mov %rsi,%rdx
10783+ pax_force_retaddr 0, 1
10784 ret
10785 # bytesatleast65:
10786 ._bytesatleast65:
10787@@ -891,6 +894,7 @@ ECRYPT_keysetup:
10788 add %r11,%rsp
10789 mov %rdi,%rax
10790 mov %rsi,%rdx
10791+ pax_force_retaddr
10792 ret
10793 # enter ECRYPT_ivsetup
10794 .text
10795@@ -917,4 +921,5 @@ ECRYPT_ivsetup:
10796 add %r11,%rsp
10797 mov %rdi,%rax
10798 mov %rsi,%rdx
10799+ pax_force_retaddr
10800 ret
10801diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
10802index 02b0e9f..cf4cf5c 100644
10803--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
10804+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
10805@@ -24,6 +24,8 @@
10806 *
10807 */
10808
10809+#include <asm/alternative-asm.h>
10810+
10811 #include "glue_helper-asm-avx.S"
10812
10813 .file "serpent-avx-x86_64-asm_64.S"
10814@@ -618,6 +620,7 @@ __serpent_enc_blk8_avx:
10815 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
10816 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
10817
10818+ pax_force_retaddr
10819 ret;
10820
10821 .align 8
10822@@ -673,6 +676,7 @@ __serpent_dec_blk8_avx:
10823 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
10824 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
10825
10826+ pax_force_retaddr
10827 ret;
10828
10829 .align 8
10830@@ -692,6 +696,7 @@ serpent_ecb_enc_8way_avx:
10831
10832 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10833
10834+ pax_force_retaddr
10835 ret;
10836
10837 .align 8
10838@@ -711,6 +716,7 @@ serpent_ecb_dec_8way_avx:
10839
10840 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
10841
10842+ pax_force_retaddr
10843 ret;
10844
10845 .align 8
10846@@ -730,6 +736,7 @@ serpent_cbc_dec_8way_avx:
10847
10848 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
10849
10850+ pax_force_retaddr
10851 ret;
10852
10853 .align 8
10854@@ -751,4 +758,5 @@ serpent_ctr_8way_avx:
10855
10856 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10857
10858+ pax_force_retaddr
10859 ret;
10860diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
10861index 3ee1ff0..cbc568b 100644
10862--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
10863+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
10864@@ -24,6 +24,8 @@
10865 *
10866 */
10867
10868+#include <asm/alternative-asm.h>
10869+
10870 .file "serpent-sse2-x86_64-asm_64.S"
10871 .text
10872
10873@@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
10874 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
10875 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
10876
10877+ pax_force_retaddr
10878 ret;
10879
10880 __enc_xor8:
10881 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
10882 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
10883
10884+ pax_force_retaddr
10885 ret;
10886
10887 .align 8
10888@@ -755,4 +759,5 @@ serpent_dec_blk_8way:
10889 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
10890 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
10891
10892+ pax_force_retaddr
10893 ret;
10894diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
10895index 49d6987..df66bd4 100644
10896--- a/arch/x86/crypto/sha1_ssse3_asm.S
10897+++ b/arch/x86/crypto/sha1_ssse3_asm.S
10898@@ -28,6 +28,8 @@
10899 * (at your option) any later version.
10900 */
10901
10902+#include <asm/alternative-asm.h>
10903+
10904 #define CTX %rdi // arg1
10905 #define BUF %rsi // arg2
10906 #define CNT %rdx // arg3
10907@@ -104,6 +106,7 @@
10908 pop %r12
10909 pop %rbp
10910 pop %rbx
10911+ pax_force_retaddr 0, 1
10912 ret
10913
10914 .size \name, .-\name
10915diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
10916index ebac16b..8092eb9 100644
10917--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
10918+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
10919@@ -23,6 +23,8 @@
10920 *
10921 */
10922
10923+#include <asm/alternative-asm.h>
10924+
10925 #include "glue_helper-asm-avx.S"
10926
10927 .file "twofish-avx-x86_64-asm_64.S"
10928@@ -283,6 +285,7 @@ __twofish_enc_blk8:
10929 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
10930 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
10931
10932+ pax_force_retaddr 0, 1
10933 ret;
10934
10935 .align 8
10936@@ -324,6 +327,7 @@ __twofish_dec_blk8:
10937 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
10938 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
10939
10940+ pax_force_retaddr 0, 1
10941 ret;
10942
10943 .align 8
10944@@ -345,6 +349,7 @@ twofish_ecb_enc_8way:
10945
10946 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
10947
10948+ pax_force_retaddr 0, 1
10949 ret;
10950
10951 .align 8
10952@@ -366,6 +371,7 @@ twofish_ecb_dec_8way:
10953
10954 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10955
10956+ pax_force_retaddr 0, 1
10957 ret;
10958
10959 .align 8
10960@@ -392,6 +398,7 @@ twofish_cbc_dec_8way:
10961
10962 popq %r12;
10963
10964+ pax_force_retaddr 0, 1
10965 ret;
10966
10967 .align 8
10968@@ -420,4 +427,5 @@ twofish_ctr_8way:
10969
10970 popq %r12;
10971
10972+ pax_force_retaddr 0, 1
10973 ret;
10974diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
10975index 5b012a2..36d5364 100644
10976--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
10977+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
10978@@ -20,6 +20,8 @@
10979 *
10980 */
10981
10982+#include <asm/alternative-asm.h>
10983+
10984 .file "twofish-x86_64-asm-3way.S"
10985 .text
10986
10987@@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
10988 popq %r13;
10989 popq %r14;
10990 popq %r15;
10991+ pax_force_retaddr 0, 1
10992 ret;
10993
10994 __enc_xor3:
10995@@ -271,6 +274,7 @@ __enc_xor3:
10996 popq %r13;
10997 popq %r14;
10998 popq %r15;
10999+ pax_force_retaddr 0, 1
11000 ret;
11001
11002 .global twofish_dec_blk_3way
11003@@ -312,5 +316,6 @@ twofish_dec_blk_3way:
11004 popq %r13;
11005 popq %r14;
11006 popq %r15;
11007+ pax_force_retaddr 0, 1
11008 ret;
11009
11010diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
11011index 7bcf3fc..f53832f 100644
11012--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
11013+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
11014@@ -21,6 +21,7 @@
11015 .text
11016
11017 #include <asm/asm-offsets.h>
11018+#include <asm/alternative-asm.h>
11019
11020 #define a_offset 0
11021 #define b_offset 4
11022@@ -268,6 +269,7 @@ twofish_enc_blk:
11023
11024 popq R1
11025 movq $1,%rax
11026+ pax_force_retaddr 0, 1
11027 ret
11028
11029 twofish_dec_blk:
11030@@ -319,4 +321,5 @@ twofish_dec_blk:
11031
11032 popq R1
11033 movq $1,%rax
11034+ pax_force_retaddr 0, 1
11035 ret
11036diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
11037index a703af1..f5b9c36 100644
11038--- a/arch/x86/ia32/ia32_aout.c
11039+++ b/arch/x86/ia32/ia32_aout.c
11040@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
11041 unsigned long dump_start, dump_size;
11042 struct user32 dump;
11043
11044+ memset(&dump, 0, sizeof(dump));
11045+
11046 fs = get_fs();
11047 set_fs(KERNEL_DS);
11048 has_dumped = 1;
11049diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
11050index a1daf4a..f8c4537 100644
11051--- a/arch/x86/ia32/ia32_signal.c
11052+++ b/arch/x86/ia32/ia32_signal.c
11053@@ -348,7 +348,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
11054 sp -= frame_size;
11055 /* Align the stack pointer according to the i386 ABI,
11056 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
11057- sp = ((sp + 4) & -16ul) - 4;
11058+ sp = ((sp - 12) & -16ul) - 4;
11059 return (void __user *) sp;
11060 }
11061
11062@@ -406,7 +406,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
11063 * These are actually not used anymore, but left because some
11064 * gdb versions depend on them as a marker.
11065 */
11066- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11067+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11068 } put_user_catch(err);
11069
11070 if (err)
11071@@ -448,7 +448,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
11072 0xb8,
11073 __NR_ia32_rt_sigreturn,
11074 0x80cd,
11075- 0,
11076+ 0
11077 };
11078
11079 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
11080@@ -471,16 +471,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
11081
11082 if (ka->sa.sa_flags & SA_RESTORER)
11083 restorer = ka->sa.sa_restorer;
11084+ else if (current->mm->context.vdso)
11085+ /* Return stub is in 32bit vsyscall page */
11086+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
11087 else
11088- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
11089- rt_sigreturn);
11090+ restorer = &frame->retcode;
11091 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
11092
11093 /*
11094 * Not actually used anymore, but left because some gdb
11095 * versions need it.
11096 */
11097- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11098+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11099 } put_user_catch(err);
11100
11101 err |= copy_siginfo_to_user32(&frame->info, info);
11102diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
11103index 142c4ce..19b683f 100644
11104--- a/arch/x86/ia32/ia32entry.S
11105+++ b/arch/x86/ia32/ia32entry.S
11106@@ -15,8 +15,10 @@
11107 #include <asm/irqflags.h>
11108 #include <asm/asm.h>
11109 #include <asm/smap.h>
11110+#include <asm/pgtable.h>
11111 #include <linux/linkage.h>
11112 #include <linux/err.h>
11113+#include <asm/alternative-asm.h>
11114
11115 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
11116 #include <linux/elf-em.h>
11117@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
11118 ENDPROC(native_irq_enable_sysexit)
11119 #endif
11120
11121+ .macro pax_enter_kernel_user
11122+ pax_set_fptr_mask
11123+#ifdef CONFIG_PAX_MEMORY_UDEREF
11124+ call pax_enter_kernel_user
11125+#endif
11126+ .endm
11127+
11128+ .macro pax_exit_kernel_user
11129+#ifdef CONFIG_PAX_MEMORY_UDEREF
11130+ call pax_exit_kernel_user
11131+#endif
11132+#ifdef CONFIG_PAX_RANDKSTACK
11133+ pushq %rax
11134+ pushq %r11
11135+ call pax_randomize_kstack
11136+ popq %r11
11137+ popq %rax
11138+#endif
11139+ .endm
11140+
11141+.macro pax_erase_kstack
11142+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
11143+ call pax_erase_kstack
11144+#endif
11145+.endm
11146+
11147 /*
11148 * 32bit SYSENTER instruction entry.
11149 *
11150@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
11151 CFI_REGISTER rsp,rbp
11152 SWAPGS_UNSAFE_STACK
11153 movq PER_CPU_VAR(kernel_stack), %rsp
11154- addq $(KERNEL_STACK_OFFSET),%rsp
11155- /*
11156- * No need to follow this irqs on/off section: the syscall
11157- * disabled irqs, here we enable it straight after entry:
11158- */
11159- ENABLE_INTERRUPTS(CLBR_NONE)
11160 movl %ebp,%ebp /* zero extension */
11161 pushq_cfi $__USER32_DS
11162 /*CFI_REL_OFFSET ss,0*/
11163@@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
11164 CFI_REL_OFFSET rsp,0
11165 pushfq_cfi
11166 /*CFI_REL_OFFSET rflags,0*/
11167- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
11168- CFI_REGISTER rip,r10
11169+ orl $X86_EFLAGS_IF,(%rsp)
11170+ GET_THREAD_INFO(%r11)
11171+ movl TI_sysenter_return(%r11), %r11d
11172+ CFI_REGISTER rip,r11
11173 pushq_cfi $__USER32_CS
11174 /*CFI_REL_OFFSET cs,0*/
11175 movl %eax, %eax
11176- pushq_cfi %r10
11177+ pushq_cfi %r11
11178 CFI_REL_OFFSET rip,0
11179 pushq_cfi %rax
11180 cld
11181 SAVE_ARGS 0,1,0
11182+ pax_enter_kernel_user
11183+
11184+#ifdef CONFIG_PAX_RANDKSTACK
11185+ pax_erase_kstack
11186+#endif
11187+
11188+ /*
11189+ * No need to follow this irqs on/off section: the syscall
11190+ * disabled irqs, here we enable it straight after entry:
11191+ */
11192+ ENABLE_INTERRUPTS(CLBR_NONE)
11193 /* no need to do an access_ok check here because rbp has been
11194 32bit zero extended */
11195+
11196+#ifdef CONFIG_PAX_MEMORY_UDEREF
11197+ mov $PAX_USER_SHADOW_BASE,%r11
11198+ add %r11,%rbp
11199+#endif
11200+
11201 ASM_STAC
11202 1: movl (%rbp),%ebp
11203 _ASM_EXTABLE(1b,ia32_badarg)
11204 ASM_CLAC
11205- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11206- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11207+ GET_THREAD_INFO(%r11)
11208+ orl $TS_COMPAT,TI_status(%r11)
11209+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11210 CFI_REMEMBER_STATE
11211 jnz sysenter_tracesys
11212 cmpq $(IA32_NR_syscalls-1),%rax
11213@@ -162,12 +204,15 @@ sysenter_do_call:
11214 sysenter_dispatch:
11215 call *ia32_sys_call_table(,%rax,8)
11216 movq %rax,RAX-ARGOFFSET(%rsp)
11217+ GET_THREAD_INFO(%r11)
11218 DISABLE_INTERRUPTS(CLBR_NONE)
11219 TRACE_IRQS_OFF
11220- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11221+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11222 jnz sysexit_audit
11223 sysexit_from_sys_call:
11224- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11225+ pax_exit_kernel_user
11226+ pax_erase_kstack
11227+ andl $~TS_COMPAT,TI_status(%r11)
11228 /* clear IF, that popfq doesn't enable interrupts early */
11229 andl $~0x200,EFLAGS-R11(%rsp)
11230 movl RIP-R11(%rsp),%edx /* User %eip */
11231@@ -193,6 +238,9 @@ sysexit_from_sys_call:
11232 movl %eax,%esi /* 2nd arg: syscall number */
11233 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
11234 call __audit_syscall_entry
11235+
11236+ pax_erase_kstack
11237+
11238 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
11239 cmpq $(IA32_NR_syscalls-1),%rax
11240 ja ia32_badsys
11241@@ -204,7 +252,7 @@ sysexit_from_sys_call:
11242 .endm
11243
11244 .macro auditsys_exit exit
11245- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11246+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11247 jnz ia32_ret_from_sys_call
11248 TRACE_IRQS_ON
11249 ENABLE_INTERRUPTS(CLBR_NONE)
11250@@ -215,11 +263,12 @@ sysexit_from_sys_call:
11251 1: setbe %al /* 1 if error, 0 if not */
11252 movzbl %al,%edi /* zero-extend that into %edi */
11253 call __audit_syscall_exit
11254+ GET_THREAD_INFO(%r11)
11255 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
11256 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
11257 DISABLE_INTERRUPTS(CLBR_NONE)
11258 TRACE_IRQS_OFF
11259- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11260+ testl %edi,TI_flags(%r11)
11261 jz \exit
11262 CLEAR_RREGS -ARGOFFSET
11263 jmp int_with_check
11264@@ -237,7 +286,7 @@ sysexit_audit:
11265
11266 sysenter_tracesys:
11267 #ifdef CONFIG_AUDITSYSCALL
11268- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11269+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11270 jz sysenter_auditsys
11271 #endif
11272 SAVE_REST
11273@@ -249,6 +298,9 @@ sysenter_tracesys:
11274 RESTORE_REST
11275 cmpq $(IA32_NR_syscalls-1),%rax
11276 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
11277+
11278+ pax_erase_kstack
11279+
11280 jmp sysenter_do_call
11281 CFI_ENDPROC
11282 ENDPROC(ia32_sysenter_target)
11283@@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
11284 ENTRY(ia32_cstar_target)
11285 CFI_STARTPROC32 simple
11286 CFI_SIGNAL_FRAME
11287- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
11288+ CFI_DEF_CFA rsp,0
11289 CFI_REGISTER rip,rcx
11290 /*CFI_REGISTER rflags,r11*/
11291 SWAPGS_UNSAFE_STACK
11292 movl %esp,%r8d
11293 CFI_REGISTER rsp,r8
11294 movq PER_CPU_VAR(kernel_stack),%rsp
11295+ SAVE_ARGS 8*6,0,0
11296+ pax_enter_kernel_user
11297+
11298+#ifdef CONFIG_PAX_RANDKSTACK
11299+ pax_erase_kstack
11300+#endif
11301+
11302 /*
11303 * No need to follow this irqs on/off section: the syscall
11304 * disabled irqs and here we enable it straight after entry:
11305 */
11306 ENABLE_INTERRUPTS(CLBR_NONE)
11307- SAVE_ARGS 8,0,0
11308 movl %eax,%eax /* zero extension */
11309 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
11310 movq %rcx,RIP-ARGOFFSET(%rsp)
11311@@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
11312 /* no need to do an access_ok check here because r8 has been
11313 32bit zero extended */
11314 /* hardware stack frame is complete now */
11315+
11316+#ifdef CONFIG_PAX_MEMORY_UDEREF
11317+ mov $PAX_USER_SHADOW_BASE,%r11
11318+ add %r11,%r8
11319+#endif
11320+
11321 ASM_STAC
11322 1: movl (%r8),%r9d
11323 _ASM_EXTABLE(1b,ia32_badarg)
11324 ASM_CLAC
11325- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11326- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11327+ GET_THREAD_INFO(%r11)
11328+ orl $TS_COMPAT,TI_status(%r11)
11329+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11330 CFI_REMEMBER_STATE
11331 jnz cstar_tracesys
11332 cmpq $IA32_NR_syscalls-1,%rax
11333@@ -319,12 +384,15 @@ cstar_do_call:
11334 cstar_dispatch:
11335 call *ia32_sys_call_table(,%rax,8)
11336 movq %rax,RAX-ARGOFFSET(%rsp)
11337+ GET_THREAD_INFO(%r11)
11338 DISABLE_INTERRUPTS(CLBR_NONE)
11339 TRACE_IRQS_OFF
11340- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11341+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11342 jnz sysretl_audit
11343 sysretl_from_sys_call:
11344- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11345+ pax_exit_kernel_user
11346+ pax_erase_kstack
11347+ andl $~TS_COMPAT,TI_status(%r11)
11348 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
11349 movl RIP-ARGOFFSET(%rsp),%ecx
11350 CFI_REGISTER rip,rcx
11351@@ -352,7 +420,7 @@ sysretl_audit:
11352
11353 cstar_tracesys:
11354 #ifdef CONFIG_AUDITSYSCALL
11355- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11356+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11357 jz cstar_auditsys
11358 #endif
11359 xchgl %r9d,%ebp
11360@@ -366,6 +434,9 @@ cstar_tracesys:
11361 xchgl %ebp,%r9d
11362 cmpq $(IA32_NR_syscalls-1),%rax
11363 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
11364+
11365+ pax_erase_kstack
11366+
11367 jmp cstar_do_call
11368 END(ia32_cstar_target)
11369
11370@@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
11371 CFI_REL_OFFSET rip,RIP-RIP
11372 PARAVIRT_ADJUST_EXCEPTION_FRAME
11373 SWAPGS
11374- /*
11375- * No need to follow this irqs on/off section: the syscall
11376- * disabled irqs and here we enable it straight after entry:
11377- */
11378- ENABLE_INTERRUPTS(CLBR_NONE)
11379 movl %eax,%eax
11380 pushq_cfi %rax
11381 cld
11382 /* note the registers are not zero extended to the sf.
11383 this could be a problem. */
11384 SAVE_ARGS 0,1,0
11385- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11386- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11387+ pax_enter_kernel_user
11388+
11389+#ifdef CONFIG_PAX_RANDKSTACK
11390+ pax_erase_kstack
11391+#endif
11392+
11393+ /*
11394+ * No need to follow this irqs on/off section: the syscall
11395+ * disabled irqs and here we enable it straight after entry:
11396+ */
11397+ ENABLE_INTERRUPTS(CLBR_NONE)
11398+ GET_THREAD_INFO(%r11)
11399+ orl $TS_COMPAT,TI_status(%r11)
11400+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11401 jnz ia32_tracesys
11402 cmpq $(IA32_NR_syscalls-1),%rax
11403 ja ia32_badsys
11404@@ -442,6 +520,9 @@ ia32_tracesys:
11405 RESTORE_REST
11406 cmpq $(IA32_NR_syscalls-1),%rax
11407 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
11408+
11409+ pax_erase_kstack
11410+
11411 jmp ia32_do_call
11412 END(ia32_syscall)
11413
11414diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
11415index d0b689b..34be51d 100644
11416--- a/arch/x86/ia32/sys_ia32.c
11417+++ b/arch/x86/ia32/sys_ia32.c
11418@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
11419 */
11420 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
11421 {
11422- typeof(ubuf->st_uid) uid = 0;
11423- typeof(ubuf->st_gid) gid = 0;
11424+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
11425+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
11426 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
11427 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
11428 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
11429@@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
11430 mm_segment_t old_fs = get_fs();
11431
11432 set_fs(KERNEL_DS);
11433- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
11434+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
11435 set_fs(old_fs);
11436 if (put_compat_timespec(&t, interval))
11437 return -EFAULT;
11438@@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
11439 mm_segment_t old_fs = get_fs();
11440
11441 set_fs(KERNEL_DS);
11442- ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
11443+ ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
11444 set_fs(old_fs);
11445 if (!ret) {
11446 switch (_NSIG_WORDS) {
11447@@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
11448 if (copy_siginfo_from_user32(&info, uinfo))
11449 return -EFAULT;
11450 set_fs(KERNEL_DS);
11451- ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
11452+ ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
11453 set_fs(old_fs);
11454 return ret;
11455 }
11456@@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
11457 return -EFAULT;
11458
11459 set_fs(KERNEL_DS);
11460- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
11461+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
11462 count);
11463 set_fs(old_fs);
11464
11465diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
11466index 372231c..a5aa1a1 100644
11467--- a/arch/x86/include/asm/alternative-asm.h
11468+++ b/arch/x86/include/asm/alternative-asm.h
11469@@ -18,6 +18,45 @@
11470 .endm
11471 #endif
11472
11473+#ifdef KERNEXEC_PLUGIN
11474+ .macro pax_force_retaddr_bts rip=0
11475+ btsq $63,\rip(%rsp)
11476+ .endm
11477+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11478+ .macro pax_force_retaddr rip=0, reload=0
11479+ btsq $63,\rip(%rsp)
11480+ .endm
11481+ .macro pax_force_fptr ptr
11482+ btsq $63,\ptr
11483+ .endm
11484+ .macro pax_set_fptr_mask
11485+ .endm
11486+#endif
11487+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
11488+ .macro pax_force_retaddr rip=0, reload=0
11489+ .if \reload
11490+ pax_set_fptr_mask
11491+ .endif
11492+ orq %r10,\rip(%rsp)
11493+ .endm
11494+ .macro pax_force_fptr ptr
11495+ orq %r10,\ptr
11496+ .endm
11497+ .macro pax_set_fptr_mask
11498+ movabs $0x8000000000000000,%r10
11499+ .endm
11500+#endif
11501+#else
11502+ .macro pax_force_retaddr rip=0, reload=0
11503+ .endm
11504+ .macro pax_force_fptr ptr
11505+ .endm
11506+ .macro pax_force_retaddr_bts rip=0
11507+ .endm
11508+ .macro pax_set_fptr_mask
11509+ .endm
11510+#endif
11511+
11512 .macro altinstruction_entry orig alt feature orig_len alt_len
11513 .long \orig - .
11514 .long \alt - .
11515diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
11516index 58ed6d9..f1cbe58 100644
11517--- a/arch/x86/include/asm/alternative.h
11518+++ b/arch/x86/include/asm/alternative.h
11519@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11520 ".pushsection .discard,\"aw\",@progbits\n" \
11521 DISCARD_ENTRY(1) \
11522 ".popsection\n" \
11523- ".pushsection .altinstr_replacement, \"ax\"\n" \
11524+ ".pushsection .altinstr_replacement, \"a\"\n" \
11525 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
11526 ".popsection"
11527
11528@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11529 DISCARD_ENTRY(1) \
11530 DISCARD_ENTRY(2) \
11531 ".popsection\n" \
11532- ".pushsection .altinstr_replacement, \"ax\"\n" \
11533+ ".pushsection .altinstr_replacement, \"a\"\n" \
11534 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
11535 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
11536 ".popsection"
11537diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
11538index 3388034..050f0b9 100644
11539--- a/arch/x86/include/asm/apic.h
11540+++ b/arch/x86/include/asm/apic.h
11541@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
11542
11543 #ifdef CONFIG_X86_LOCAL_APIC
11544
11545-extern unsigned int apic_verbosity;
11546+extern int apic_verbosity;
11547 extern int local_apic_timer_c2_ok;
11548
11549 extern int disable_apic;
11550diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
11551index 20370c6..a2eb9b0 100644
11552--- a/arch/x86/include/asm/apm.h
11553+++ b/arch/x86/include/asm/apm.h
11554@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
11555 __asm__ __volatile__(APM_DO_ZERO_SEGS
11556 "pushl %%edi\n\t"
11557 "pushl %%ebp\n\t"
11558- "lcall *%%cs:apm_bios_entry\n\t"
11559+ "lcall *%%ss:apm_bios_entry\n\t"
11560 "setc %%al\n\t"
11561 "popl %%ebp\n\t"
11562 "popl %%edi\n\t"
11563@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
11564 __asm__ __volatile__(APM_DO_ZERO_SEGS
11565 "pushl %%edi\n\t"
11566 "pushl %%ebp\n\t"
11567- "lcall *%%cs:apm_bios_entry\n\t"
11568+ "lcall *%%ss:apm_bios_entry\n\t"
11569 "setc %%bl\n\t"
11570 "popl %%ebp\n\t"
11571 "popl %%edi\n\t"
11572diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
11573index 722aa3b..3a0bb27 100644
11574--- a/arch/x86/include/asm/atomic.h
11575+++ b/arch/x86/include/asm/atomic.h
11576@@ -22,7 +22,18 @@
11577 */
11578 static inline int atomic_read(const atomic_t *v)
11579 {
11580- return (*(volatile int *)&(v)->counter);
11581+ return (*(volatile const int *)&(v)->counter);
11582+}
11583+
11584+/**
11585+ * atomic_read_unchecked - read atomic variable
11586+ * @v: pointer of type atomic_unchecked_t
11587+ *
11588+ * Atomically reads the value of @v.
11589+ */
11590+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
11591+{
11592+ return (*(volatile const int *)&(v)->counter);
11593 }
11594
11595 /**
11596@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
11597 }
11598
11599 /**
11600+ * atomic_set_unchecked - set atomic variable
11601+ * @v: pointer of type atomic_unchecked_t
11602+ * @i: required value
11603+ *
11604+ * Atomically sets the value of @v to @i.
11605+ */
11606+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
11607+{
11608+ v->counter = i;
11609+}
11610+
11611+/**
11612 * atomic_add - add integer to atomic variable
11613 * @i: integer value to add
11614 * @v: pointer of type atomic_t
11615@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
11616 */
11617 static inline void atomic_add(int i, atomic_t *v)
11618 {
11619- asm volatile(LOCK_PREFIX "addl %1,%0"
11620+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
11621+
11622+#ifdef CONFIG_PAX_REFCOUNT
11623+ "jno 0f\n"
11624+ LOCK_PREFIX "subl %1,%0\n"
11625+ "int $4\n0:\n"
11626+ _ASM_EXTABLE(0b, 0b)
11627+#endif
11628+
11629+ : "+m" (v->counter)
11630+ : "ir" (i));
11631+}
11632+
11633+/**
11634+ * atomic_add_unchecked - add integer to atomic variable
11635+ * @i: integer value to add
11636+ * @v: pointer of type atomic_unchecked_t
11637+ *
11638+ * Atomically adds @i to @v.
11639+ */
11640+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
11641+{
11642+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
11643 : "+m" (v->counter)
11644 : "ir" (i));
11645 }
11646@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
11647 */
11648 static inline void atomic_sub(int i, atomic_t *v)
11649 {
11650- asm volatile(LOCK_PREFIX "subl %1,%0"
11651+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
11652+
11653+#ifdef CONFIG_PAX_REFCOUNT
11654+ "jno 0f\n"
11655+ LOCK_PREFIX "addl %1,%0\n"
11656+ "int $4\n0:\n"
11657+ _ASM_EXTABLE(0b, 0b)
11658+#endif
11659+
11660+ : "+m" (v->counter)
11661+ : "ir" (i));
11662+}
11663+
11664+/**
11665+ * atomic_sub_unchecked - subtract integer from atomic variable
11666+ * @i: integer value to subtract
11667+ * @v: pointer of type atomic_unchecked_t
11668+ *
11669+ * Atomically subtracts @i from @v.
11670+ */
11671+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
11672+{
11673+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
11674 : "+m" (v->counter)
11675 : "ir" (i));
11676 }
11677@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
11678 {
11679 unsigned char c;
11680
11681- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
11682+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
11683+
11684+#ifdef CONFIG_PAX_REFCOUNT
11685+ "jno 0f\n"
11686+ LOCK_PREFIX "addl %2,%0\n"
11687+ "int $4\n0:\n"
11688+ _ASM_EXTABLE(0b, 0b)
11689+#endif
11690+
11691+ "sete %1\n"
11692 : "+m" (v->counter), "=qm" (c)
11693 : "ir" (i) : "memory");
11694 return c;
11695@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
11696 */
11697 static inline void atomic_inc(atomic_t *v)
11698 {
11699- asm volatile(LOCK_PREFIX "incl %0"
11700+ asm volatile(LOCK_PREFIX "incl %0\n"
11701+
11702+#ifdef CONFIG_PAX_REFCOUNT
11703+ "jno 0f\n"
11704+ LOCK_PREFIX "decl %0\n"
11705+ "int $4\n0:\n"
11706+ _ASM_EXTABLE(0b, 0b)
11707+#endif
11708+
11709+ : "+m" (v->counter));
11710+}
11711+
11712+/**
11713+ * atomic_inc_unchecked - increment atomic variable
11714+ * @v: pointer of type atomic_unchecked_t
11715+ *
11716+ * Atomically increments @v by 1.
11717+ */
11718+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
11719+{
11720+ asm volatile(LOCK_PREFIX "incl %0\n"
11721 : "+m" (v->counter));
11722 }
11723
11724@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
11725 */
11726 static inline void atomic_dec(atomic_t *v)
11727 {
11728- asm volatile(LOCK_PREFIX "decl %0"
11729+ asm volatile(LOCK_PREFIX "decl %0\n"
11730+
11731+#ifdef CONFIG_PAX_REFCOUNT
11732+ "jno 0f\n"
11733+ LOCK_PREFIX "incl %0\n"
11734+ "int $4\n0:\n"
11735+ _ASM_EXTABLE(0b, 0b)
11736+#endif
11737+
11738+ : "+m" (v->counter));
11739+}
11740+
11741+/**
11742+ * atomic_dec_unchecked - decrement atomic variable
11743+ * @v: pointer of type atomic_unchecked_t
11744+ *
11745+ * Atomically decrements @v by 1.
11746+ */
11747+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
11748+{
11749+ asm volatile(LOCK_PREFIX "decl %0\n"
11750 : "+m" (v->counter));
11751 }
11752
11753@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
11754 {
11755 unsigned char c;
11756
11757- asm volatile(LOCK_PREFIX "decl %0; sete %1"
11758+ asm volatile(LOCK_PREFIX "decl %0\n"
11759+
11760+#ifdef CONFIG_PAX_REFCOUNT
11761+ "jno 0f\n"
11762+ LOCK_PREFIX "incl %0\n"
11763+ "int $4\n0:\n"
11764+ _ASM_EXTABLE(0b, 0b)
11765+#endif
11766+
11767+ "sete %1\n"
11768 : "+m" (v->counter), "=qm" (c)
11769 : : "memory");
11770 return c != 0;
11771@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
11772 {
11773 unsigned char c;
11774
11775- asm volatile(LOCK_PREFIX "incl %0; sete %1"
11776+ asm volatile(LOCK_PREFIX "incl %0\n"
11777+
11778+#ifdef CONFIG_PAX_REFCOUNT
11779+ "jno 0f\n"
11780+ LOCK_PREFIX "decl %0\n"
11781+ "int $4\n0:\n"
11782+ _ASM_EXTABLE(0b, 0b)
11783+#endif
11784+
11785+ "sete %1\n"
11786+ : "+m" (v->counter), "=qm" (c)
11787+ : : "memory");
11788+ return c != 0;
11789+}
11790+
11791+/**
11792+ * atomic_inc_and_test_unchecked - increment and test
11793+ * @v: pointer of type atomic_unchecked_t
11794+ *
11795+ * Atomically increments @v by 1
11796+ * and returns true if the result is zero, or false for all
11797+ * other cases.
11798+ */
11799+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
11800+{
11801+ unsigned char c;
11802+
11803+ asm volatile(LOCK_PREFIX "incl %0\n"
11804+ "sete %1\n"
11805 : "+m" (v->counter), "=qm" (c)
11806 : : "memory");
11807 return c != 0;
11808@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
11809 {
11810 unsigned char c;
11811
11812- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
11813+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
11814+
11815+#ifdef CONFIG_PAX_REFCOUNT
11816+ "jno 0f\n"
11817+ LOCK_PREFIX "subl %2,%0\n"
11818+ "int $4\n0:\n"
11819+ _ASM_EXTABLE(0b, 0b)
11820+#endif
11821+
11822+ "sets %1\n"
11823 : "+m" (v->counter), "=qm" (c)
11824 : "ir" (i) : "memory");
11825 return c;
11826@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
11827 */
11828 static inline int atomic_add_return(int i, atomic_t *v)
11829 {
11830+ return i + xadd_check_overflow(&v->counter, i);
11831+}
11832+
11833+/**
11834+ * atomic_add_return_unchecked - add integer and return
11835+ * @i: integer value to add
11836+ * @v: pointer of type atomic_unchecked_t
11837+ *
11838+ * Atomically adds @i to @v and returns @i + @v
11839+ */
11840+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
11841+{
11842 return i + xadd(&v->counter, i);
11843 }
11844
11845@@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
11846 }
11847
11848 #define atomic_inc_return(v) (atomic_add_return(1, v))
11849+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
11850+{
11851+ return atomic_add_return_unchecked(1, v);
11852+}
11853 #define atomic_dec_return(v) (atomic_sub_return(1, v))
11854
11855 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
11856@@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
11857 return cmpxchg(&v->counter, old, new);
11858 }
11859
11860+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
11861+{
11862+ return cmpxchg(&v->counter, old, new);
11863+}
11864+
11865 static inline int atomic_xchg(atomic_t *v, int new)
11866 {
11867 return xchg(&v->counter, new);
11868 }
11869
11870+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
11871+{
11872+ return xchg(&v->counter, new);
11873+}
11874+
11875 /**
11876 * __atomic_add_unless - add unless the number is already a given value
11877 * @v: pointer of type atomic_t
11878@@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
11879 */
11880 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
11881 {
11882- int c, old;
11883+ int c, old, new;
11884 c = atomic_read(v);
11885 for (;;) {
11886- if (unlikely(c == (u)))
11887+ if (unlikely(c == u))
11888 break;
11889- old = atomic_cmpxchg((v), c, c + (a));
11890+
11891+ asm volatile("addl %2,%0\n"
11892+
11893+#ifdef CONFIG_PAX_REFCOUNT
11894+ "jno 0f\n"
11895+ "subl %2,%0\n"
11896+ "int $4\n0:\n"
11897+ _ASM_EXTABLE(0b, 0b)
11898+#endif
11899+
11900+ : "=r" (new)
11901+ : "0" (c), "ir" (a));
11902+
11903+ old = atomic_cmpxchg(v, c, new);
11904 if (likely(old == c))
11905 break;
11906 c = old;
11907@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
11908 }
11909
11910 /**
11911+ * atomic_inc_not_zero_hint - increment if not null
11912+ * @v: pointer of type atomic_t
11913+ * @hint: probable value of the atomic before the increment
11914+ *
11915+ * This version of atomic_inc_not_zero() gives a hint of probable
11916+ * value of the atomic. This helps processor to not read the memory
11917+ * before doing the atomic read/modify/write cycle, lowering
11918+ * number of bus transactions on some arches.
11919+ *
11920+ * Returns: 0 if increment was not done, 1 otherwise.
11921+ */
11922+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
11923+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
11924+{
11925+ int val, c = hint, new;
11926+
11927+ /* sanity test, should be removed by compiler if hint is a constant */
11928+ if (!hint)
11929+ return __atomic_add_unless(v, 1, 0);
11930+
11931+ do {
11932+ asm volatile("incl %0\n"
11933+
11934+#ifdef CONFIG_PAX_REFCOUNT
11935+ "jno 0f\n"
11936+ "decl %0\n"
11937+ "int $4\n0:\n"
11938+ _ASM_EXTABLE(0b, 0b)
11939+#endif
11940+
11941+ : "=r" (new)
11942+ : "0" (c));
11943+
11944+ val = atomic_cmpxchg(v, c, new);
11945+ if (val == c)
11946+ return 1;
11947+ c = val;
11948+ } while (c);
11949+
11950+ return 0;
11951+}
11952+
11953+/**
11954 * atomic_inc_short - increment of a short integer
11955 * @v: pointer to type int
11956 *
11957@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
11958 #endif
11959
11960 /* These are x86-specific, used by some header files */
11961-#define atomic_clear_mask(mask, addr) \
11962- asm volatile(LOCK_PREFIX "andl %0,%1" \
11963- : : "r" (~(mask)), "m" (*(addr)) : "memory")
11964+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
11965+{
11966+ asm volatile(LOCK_PREFIX "andl %1,%0"
11967+ : "+m" (v->counter)
11968+ : "r" (~(mask))
11969+ : "memory");
11970+}
11971
11972-#define atomic_set_mask(mask, addr) \
11973- asm volatile(LOCK_PREFIX "orl %0,%1" \
11974- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
11975- : "memory")
11976+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
11977+{
11978+ asm volatile(LOCK_PREFIX "andl %1,%0"
11979+ : "+m" (v->counter)
11980+ : "r" (~(mask))
11981+ : "memory");
11982+}
11983+
11984+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
11985+{
11986+ asm volatile(LOCK_PREFIX "orl %1,%0"
11987+ : "+m" (v->counter)
11988+ : "r" (mask)
11989+ : "memory");
11990+}
11991+
11992+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
11993+{
11994+ asm volatile(LOCK_PREFIX "orl %1,%0"
11995+ : "+m" (v->counter)
11996+ : "r" (mask)
11997+ : "memory");
11998+}
11999
12000 /* Atomic operations are already serializing on x86 */
12001 #define smp_mb__before_atomic_dec() barrier()
12002diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
12003index b154de7..aadebd8 100644
12004--- a/arch/x86/include/asm/atomic64_32.h
12005+++ b/arch/x86/include/asm/atomic64_32.h
12006@@ -12,6 +12,14 @@ typedef struct {
12007 u64 __aligned(8) counter;
12008 } atomic64_t;
12009
12010+#ifdef CONFIG_PAX_REFCOUNT
12011+typedef struct {
12012+ u64 __aligned(8) counter;
12013+} atomic64_unchecked_t;
12014+#else
12015+typedef atomic64_t atomic64_unchecked_t;
12016+#endif
12017+
12018 #define ATOMIC64_INIT(val) { (val) }
12019
12020 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
12021@@ -37,21 +45,31 @@ typedef struct {
12022 ATOMIC64_DECL_ONE(sym##_386)
12023
12024 ATOMIC64_DECL_ONE(add_386);
12025+ATOMIC64_DECL_ONE(add_unchecked_386);
12026 ATOMIC64_DECL_ONE(sub_386);
12027+ATOMIC64_DECL_ONE(sub_unchecked_386);
12028 ATOMIC64_DECL_ONE(inc_386);
12029+ATOMIC64_DECL_ONE(inc_unchecked_386);
12030 ATOMIC64_DECL_ONE(dec_386);
12031+ATOMIC64_DECL_ONE(dec_unchecked_386);
12032 #endif
12033
12034 #define alternative_atomic64(f, out, in...) \
12035 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
12036
12037 ATOMIC64_DECL(read);
12038+ATOMIC64_DECL(read_unchecked);
12039 ATOMIC64_DECL(set);
12040+ATOMIC64_DECL(set_unchecked);
12041 ATOMIC64_DECL(xchg);
12042 ATOMIC64_DECL(add_return);
12043+ATOMIC64_DECL(add_return_unchecked);
12044 ATOMIC64_DECL(sub_return);
12045+ATOMIC64_DECL(sub_return_unchecked);
12046 ATOMIC64_DECL(inc_return);
12047+ATOMIC64_DECL(inc_return_unchecked);
12048 ATOMIC64_DECL(dec_return);
12049+ATOMIC64_DECL(dec_return_unchecked);
12050 ATOMIC64_DECL(dec_if_positive);
12051 ATOMIC64_DECL(inc_not_zero);
12052 ATOMIC64_DECL(add_unless);
12053@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
12054 }
12055
12056 /**
12057+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
12058+ * @p: pointer to type atomic64_unchecked_t
12059+ * @o: expected value
12060+ * @n: new value
12061+ *
12062+ * Atomically sets @v to @n if it was equal to @o and returns
12063+ * the old value.
12064+ */
12065+
12066+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
12067+{
12068+ return cmpxchg64(&v->counter, o, n);
12069+}
12070+
12071+/**
12072 * atomic64_xchg - xchg atomic64 variable
12073 * @v: pointer to type atomic64_t
12074 * @n: value to assign
12075@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
12076 }
12077
12078 /**
12079+ * atomic64_set_unchecked - set atomic64 variable
12080+ * @v: pointer to type atomic64_unchecked_t
12081+ * @n: value to assign
12082+ *
12083+ * Atomically sets the value of @v to @n.
12084+ */
12085+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
12086+{
12087+ unsigned high = (unsigned)(i >> 32);
12088+ unsigned low = (unsigned)i;
12089+ alternative_atomic64(set, /* no output */,
12090+ "S" (v), "b" (low), "c" (high)
12091+ : "eax", "edx", "memory");
12092+}
12093+
12094+/**
12095 * atomic64_read - read atomic64 variable
12096 * @v: pointer to type atomic64_t
12097 *
12098@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
12099 }
12100
12101 /**
12102+ * atomic64_read_unchecked - read atomic64 variable
12103+ * @v: pointer to type atomic64_unchecked_t
12104+ *
12105+ * Atomically reads the value of @v and returns it.
12106+ */
12107+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
12108+{
12109+ long long r;
12110+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
12111+ return r;
12112+ }
12113+
12114+/**
12115 * atomic64_add_return - add and return
12116 * @i: integer value to add
12117 * @v: pointer to type atomic64_t
12118@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
12119 return i;
12120 }
12121
12122+/**
12123+ * atomic64_add_return_unchecked - add and return
12124+ * @i: integer value to add
12125+ * @v: pointer to type atomic64_unchecked_t
12126+ *
12127+ * Atomically adds @i to @v and returns @i + *@v
12128+ */
12129+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
12130+{
12131+ alternative_atomic64(add_return_unchecked,
12132+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12133+ ASM_NO_INPUT_CLOBBER("memory"));
12134+ return i;
12135+}
12136+
12137 /*
12138 * Other variants with different arithmetic operators:
12139 */
12140@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
12141 return a;
12142 }
12143
12144+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12145+{
12146+ long long a;
12147+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
12148+ "S" (v) : "memory", "ecx");
12149+ return a;
12150+}
12151+
12152 static inline long long atomic64_dec_return(atomic64_t *v)
12153 {
12154 long long a;
12155@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
12156 }
12157
12158 /**
12159+ * atomic64_add_unchecked - add integer to atomic64 variable
12160+ * @i: integer value to add
12161+ * @v: pointer to type atomic64_unchecked_t
12162+ *
12163+ * Atomically adds @i to @v.
12164+ */
12165+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
12166+{
12167+ __alternative_atomic64(add_unchecked, add_return_unchecked,
12168+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12169+ ASM_NO_INPUT_CLOBBER("memory"));
12170+ return i;
12171+}
12172+
12173+/**
12174 * atomic64_sub - subtract the atomic64 variable
12175 * @i: integer value to subtract
12176 * @v: pointer to type atomic64_t
12177diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
12178index 0e1cbfc..5623683 100644
12179--- a/arch/x86/include/asm/atomic64_64.h
12180+++ b/arch/x86/include/asm/atomic64_64.h
12181@@ -18,7 +18,19 @@
12182 */
12183 static inline long atomic64_read(const atomic64_t *v)
12184 {
12185- return (*(volatile long *)&(v)->counter);
12186+ return (*(volatile const long *)&(v)->counter);
12187+}
12188+
12189+/**
12190+ * atomic64_read_unchecked - read atomic64 variable
12191+ * @v: pointer of type atomic64_unchecked_t
12192+ *
12193+ * Atomically reads the value of @v.
12194+ * Doesn't imply a read memory barrier.
12195+ */
12196+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
12197+{
12198+ return (*(volatile const long *)&(v)->counter);
12199 }
12200
12201 /**
12202@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
12203 }
12204
12205 /**
12206+ * atomic64_set_unchecked - set atomic64 variable
12207+ * @v: pointer to type atomic64_unchecked_t
12208+ * @i: required value
12209+ *
12210+ * Atomically sets the value of @v to @i.
12211+ */
12212+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
12213+{
12214+ v->counter = i;
12215+}
12216+
12217+/**
12218 * atomic64_add - add integer to atomic64 variable
12219 * @i: integer value to add
12220 * @v: pointer to type atomic64_t
12221@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
12222 */
12223 static inline void atomic64_add(long i, atomic64_t *v)
12224 {
12225+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
12226+
12227+#ifdef CONFIG_PAX_REFCOUNT
12228+ "jno 0f\n"
12229+ LOCK_PREFIX "subq %1,%0\n"
12230+ "int $4\n0:\n"
12231+ _ASM_EXTABLE(0b, 0b)
12232+#endif
12233+
12234+ : "=m" (v->counter)
12235+ : "er" (i), "m" (v->counter));
12236+}
12237+
12238+/**
12239+ * atomic64_add_unchecked - add integer to atomic64 variable
12240+ * @i: integer value to add
12241+ * @v: pointer to type atomic64_unchecked_t
12242+ *
12243+ * Atomically adds @i to @v.
12244+ */
12245+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
12246+{
12247 asm volatile(LOCK_PREFIX "addq %1,%0"
12248 : "=m" (v->counter)
12249 : "er" (i), "m" (v->counter));
12250@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
12251 */
12252 static inline void atomic64_sub(long i, atomic64_t *v)
12253 {
12254- asm volatile(LOCK_PREFIX "subq %1,%0"
12255+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
12256+
12257+#ifdef CONFIG_PAX_REFCOUNT
12258+ "jno 0f\n"
12259+ LOCK_PREFIX "addq %1,%0\n"
12260+ "int $4\n0:\n"
12261+ _ASM_EXTABLE(0b, 0b)
12262+#endif
12263+
12264+ : "=m" (v->counter)
12265+ : "er" (i), "m" (v->counter));
12266+}
12267+
12268+/**
12269+ * atomic64_sub_unchecked - subtract the atomic64 variable
12270+ * @i: integer value to subtract
12271+ * @v: pointer to type atomic64_unchecked_t
12272+ *
12273+ * Atomically subtracts @i from @v.
12274+ */
12275+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
12276+{
12277+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
12278 : "=m" (v->counter)
12279 : "er" (i), "m" (v->counter));
12280 }
12281@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12282 {
12283 unsigned char c;
12284
12285- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
12286+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
12287+
12288+#ifdef CONFIG_PAX_REFCOUNT
12289+ "jno 0f\n"
12290+ LOCK_PREFIX "addq %2,%0\n"
12291+ "int $4\n0:\n"
12292+ _ASM_EXTABLE(0b, 0b)
12293+#endif
12294+
12295+ "sete %1\n"
12296 : "=m" (v->counter), "=qm" (c)
12297 : "er" (i), "m" (v->counter) : "memory");
12298 return c;
12299@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12300 */
12301 static inline void atomic64_inc(atomic64_t *v)
12302 {
12303+ asm volatile(LOCK_PREFIX "incq %0\n"
12304+
12305+#ifdef CONFIG_PAX_REFCOUNT
12306+ "jno 0f\n"
12307+ LOCK_PREFIX "decq %0\n"
12308+ "int $4\n0:\n"
12309+ _ASM_EXTABLE(0b, 0b)
12310+#endif
12311+
12312+ : "=m" (v->counter)
12313+ : "m" (v->counter));
12314+}
12315+
12316+/**
12317+ * atomic64_inc_unchecked - increment atomic64 variable
12318+ * @v: pointer to type atomic64_unchecked_t
12319+ *
12320+ * Atomically increments @v by 1.
12321+ */
12322+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
12323+{
12324 asm volatile(LOCK_PREFIX "incq %0"
12325 : "=m" (v->counter)
12326 : "m" (v->counter));
12327@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
12328 */
12329 static inline void atomic64_dec(atomic64_t *v)
12330 {
12331- asm volatile(LOCK_PREFIX "decq %0"
12332+ asm volatile(LOCK_PREFIX "decq %0\n"
12333+
12334+#ifdef CONFIG_PAX_REFCOUNT
12335+ "jno 0f\n"
12336+ LOCK_PREFIX "incq %0\n"
12337+ "int $4\n0:\n"
12338+ _ASM_EXTABLE(0b, 0b)
12339+#endif
12340+
12341+ : "=m" (v->counter)
12342+ : "m" (v->counter));
12343+}
12344+
12345+/**
12346+ * atomic64_dec_unchecked - decrement atomic64 variable
12347+ * @v: pointer to type atomic64_t
12348+ *
12349+ * Atomically decrements @v by 1.
12350+ */
12351+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
12352+{
12353+ asm volatile(LOCK_PREFIX "decq %0\n"
12354 : "=m" (v->counter)
12355 : "m" (v->counter));
12356 }
12357@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
12358 {
12359 unsigned char c;
12360
12361- asm volatile(LOCK_PREFIX "decq %0; sete %1"
12362+ asm volatile(LOCK_PREFIX "decq %0\n"
12363+
12364+#ifdef CONFIG_PAX_REFCOUNT
12365+ "jno 0f\n"
12366+ LOCK_PREFIX "incq %0\n"
12367+ "int $4\n0:\n"
12368+ _ASM_EXTABLE(0b, 0b)
12369+#endif
12370+
12371+ "sete %1\n"
12372 : "=m" (v->counter), "=qm" (c)
12373 : "m" (v->counter) : "memory");
12374 return c != 0;
12375@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
12376 {
12377 unsigned char c;
12378
12379- asm volatile(LOCK_PREFIX "incq %0; sete %1"
12380+ asm volatile(LOCK_PREFIX "incq %0\n"
12381+
12382+#ifdef CONFIG_PAX_REFCOUNT
12383+ "jno 0f\n"
12384+ LOCK_PREFIX "decq %0\n"
12385+ "int $4\n0:\n"
12386+ _ASM_EXTABLE(0b, 0b)
12387+#endif
12388+
12389+ "sete %1\n"
12390 : "=m" (v->counter), "=qm" (c)
12391 : "m" (v->counter) : "memory");
12392 return c != 0;
12393@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12394 {
12395 unsigned char c;
12396
12397- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
12398+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
12399+
12400+#ifdef CONFIG_PAX_REFCOUNT
12401+ "jno 0f\n"
12402+ LOCK_PREFIX "subq %2,%0\n"
12403+ "int $4\n0:\n"
12404+ _ASM_EXTABLE(0b, 0b)
12405+#endif
12406+
12407+ "sets %1\n"
12408 : "=m" (v->counter), "=qm" (c)
12409 : "er" (i), "m" (v->counter) : "memory");
12410 return c;
12411@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12412 */
12413 static inline long atomic64_add_return(long i, atomic64_t *v)
12414 {
12415+ return i + xadd_check_overflow(&v->counter, i);
12416+}
12417+
12418+/**
12419+ * atomic64_add_return_unchecked - add and return
12420+ * @i: integer value to add
12421+ * @v: pointer to type atomic64_unchecked_t
12422+ *
12423+ * Atomically adds @i to @v and returns @i + @v
12424+ */
12425+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
12426+{
12427 return i + xadd(&v->counter, i);
12428 }
12429
12430@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
12431 }
12432
12433 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
12434+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12435+{
12436+ return atomic64_add_return_unchecked(1, v);
12437+}
12438 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
12439
12440 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12441@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12442 return cmpxchg(&v->counter, old, new);
12443 }
12444
12445+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
12446+{
12447+ return cmpxchg(&v->counter, old, new);
12448+}
12449+
12450 static inline long atomic64_xchg(atomic64_t *v, long new)
12451 {
12452 return xchg(&v->counter, new);
12453@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
12454 */
12455 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
12456 {
12457- long c, old;
12458+ long c, old, new;
12459 c = atomic64_read(v);
12460 for (;;) {
12461- if (unlikely(c == (u)))
12462+ if (unlikely(c == u))
12463 break;
12464- old = atomic64_cmpxchg((v), c, c + (a));
12465+
12466+ asm volatile("add %2,%0\n"
12467+
12468+#ifdef CONFIG_PAX_REFCOUNT
12469+ "jno 0f\n"
12470+ "sub %2,%0\n"
12471+ "int $4\n0:\n"
12472+ _ASM_EXTABLE(0b, 0b)
12473+#endif
12474+
12475+ : "=r" (new)
12476+ : "0" (c), "ir" (a));
12477+
12478+ old = atomic64_cmpxchg(v, c, new);
12479 if (likely(old == c))
12480 break;
12481 c = old;
12482 }
12483- return c != (u);
12484+ return c != u;
12485 }
12486
12487 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12488diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
12489index 6dfd019..0c6699f 100644
12490--- a/arch/x86/include/asm/bitops.h
12491+++ b/arch/x86/include/asm/bitops.h
12492@@ -40,7 +40,7 @@
12493 * a mask operation on a byte.
12494 */
12495 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
12496-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
12497+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
12498 #define CONST_MASK(nr) (1 << ((nr) & 7))
12499
12500 /**
12501diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
12502index 4fa687a..60f2d39 100644
12503--- a/arch/x86/include/asm/boot.h
12504+++ b/arch/x86/include/asm/boot.h
12505@@ -6,10 +6,15 @@
12506 #include <uapi/asm/boot.h>
12507
12508 /* Physical address where kernel should be loaded. */
12509-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12510+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12511 + (CONFIG_PHYSICAL_ALIGN - 1)) \
12512 & ~(CONFIG_PHYSICAL_ALIGN - 1))
12513
12514+#ifndef __ASSEMBLY__
12515+extern unsigned char __LOAD_PHYSICAL_ADDR[];
12516+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
12517+#endif
12518+
12519 /* Minimum kernel alignment, as a power of two */
12520 #ifdef CONFIG_X86_64
12521 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
12522diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
12523index 48f99f1..d78ebf9 100644
12524--- a/arch/x86/include/asm/cache.h
12525+++ b/arch/x86/include/asm/cache.h
12526@@ -5,12 +5,13 @@
12527
12528 /* L1 cache line size */
12529 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12530-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12531+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12532
12533 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
12534+#define __read_only __attribute__((__section__(".data..read_only")))
12535
12536 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
12537-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
12538+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
12539
12540 #ifdef CONFIG_X86_VSMP
12541 #ifdef CONFIG_SMP
12542diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
12543index 9863ee3..4a1f8e1 100644
12544--- a/arch/x86/include/asm/cacheflush.h
12545+++ b/arch/x86/include/asm/cacheflush.h
12546@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
12547 unsigned long pg_flags = pg->flags & _PGMT_MASK;
12548
12549 if (pg_flags == _PGMT_DEFAULT)
12550- return -1;
12551+ return ~0UL;
12552 else if (pg_flags == _PGMT_WC)
12553 return _PAGE_CACHE_WC;
12554 else if (pg_flags == _PGMT_UC_MINUS)
12555diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
12556index 46fc474..b02b0f9 100644
12557--- a/arch/x86/include/asm/checksum_32.h
12558+++ b/arch/x86/include/asm/checksum_32.h
12559@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
12560 int len, __wsum sum,
12561 int *src_err_ptr, int *dst_err_ptr);
12562
12563+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
12564+ int len, __wsum sum,
12565+ int *src_err_ptr, int *dst_err_ptr);
12566+
12567+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
12568+ int len, __wsum sum,
12569+ int *src_err_ptr, int *dst_err_ptr);
12570+
12571 /*
12572 * Note: when you get a NULL pointer exception here this means someone
12573 * passed in an incorrect kernel address to one of these functions.
12574@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
12575 int *err_ptr)
12576 {
12577 might_sleep();
12578- return csum_partial_copy_generic((__force void *)src, dst,
12579+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
12580 len, sum, err_ptr, NULL);
12581 }
12582
12583@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
12584 {
12585 might_sleep();
12586 if (access_ok(VERIFY_WRITE, dst, len))
12587- return csum_partial_copy_generic(src, (__force void *)dst,
12588+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
12589 len, sum, NULL, err_ptr);
12590
12591 if (len)
12592diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
12593index 8d871ea..c1a0dc9 100644
12594--- a/arch/x86/include/asm/cmpxchg.h
12595+++ b/arch/x86/include/asm/cmpxchg.h
12596@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
12597 __compiletime_error("Bad argument size for cmpxchg");
12598 extern void __xadd_wrong_size(void)
12599 __compiletime_error("Bad argument size for xadd");
12600+extern void __xadd_check_overflow_wrong_size(void)
12601+ __compiletime_error("Bad argument size for xadd_check_overflow");
12602 extern void __add_wrong_size(void)
12603 __compiletime_error("Bad argument size for add");
12604+extern void __add_check_overflow_wrong_size(void)
12605+ __compiletime_error("Bad argument size for add_check_overflow");
12606
12607 /*
12608 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
12609@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
12610 __ret; \
12611 })
12612
12613+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
12614+ ({ \
12615+ __typeof__ (*(ptr)) __ret = (arg); \
12616+ switch (sizeof(*(ptr))) { \
12617+ case __X86_CASE_L: \
12618+ asm volatile (lock #op "l %0, %1\n" \
12619+ "jno 0f\n" \
12620+ "mov %0,%1\n" \
12621+ "int $4\n0:\n" \
12622+ _ASM_EXTABLE(0b, 0b) \
12623+ : "+r" (__ret), "+m" (*(ptr)) \
12624+ : : "memory", "cc"); \
12625+ break; \
12626+ case __X86_CASE_Q: \
12627+ asm volatile (lock #op "q %q0, %1\n" \
12628+ "jno 0f\n" \
12629+ "mov %0,%1\n" \
12630+ "int $4\n0:\n" \
12631+ _ASM_EXTABLE(0b, 0b) \
12632+ : "+r" (__ret), "+m" (*(ptr)) \
12633+ : : "memory", "cc"); \
12634+ break; \
12635+ default: \
12636+ __ ## op ## _check_overflow_wrong_size(); \
12637+ } \
12638+ __ret; \
12639+ })
12640+
12641 /*
12642 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
12643 * Since this is generally used to protect other memory information, we
12644@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
12645 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
12646 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
12647
12648+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
12649+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
12650+
12651 #define __add(ptr, inc, lock) \
12652 ({ \
12653 __typeof__ (*(ptr)) __ret = (inc); \
12654diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
12655index 2d9075e..b75a844 100644
12656--- a/arch/x86/include/asm/cpufeature.h
12657+++ b/arch/x86/include/asm/cpufeature.h
12658@@ -206,7 +206,7 @@
12659 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
12660 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
12661 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
12662-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
12663+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
12664 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
12665 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
12666 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
12667@@ -375,7 +375,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
12668 ".section .discard,\"aw\",@progbits\n"
12669 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
12670 ".previous\n"
12671- ".section .altinstr_replacement,\"ax\"\n"
12672+ ".section .altinstr_replacement,\"a\"\n"
12673 "3: movb $1,%0\n"
12674 "4:\n"
12675 ".previous\n"
12676diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
12677index 8bf1c06..f723dfd 100644
12678--- a/arch/x86/include/asm/desc.h
12679+++ b/arch/x86/include/asm/desc.h
12680@@ -4,6 +4,7 @@
12681 #include <asm/desc_defs.h>
12682 #include <asm/ldt.h>
12683 #include <asm/mmu.h>
12684+#include <asm/pgtable.h>
12685
12686 #include <linux/smp.h>
12687 #include <linux/percpu.h>
12688@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
12689
12690 desc->type = (info->read_exec_only ^ 1) << 1;
12691 desc->type |= info->contents << 2;
12692+ desc->type |= info->seg_not_present ^ 1;
12693
12694 desc->s = 1;
12695 desc->dpl = 0x3;
12696@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
12697 }
12698
12699 extern struct desc_ptr idt_descr;
12700-extern gate_desc idt_table[];
12701 extern struct desc_ptr nmi_idt_descr;
12702-extern gate_desc nmi_idt_table[];
12703-
12704-struct gdt_page {
12705- struct desc_struct gdt[GDT_ENTRIES];
12706-} __attribute__((aligned(PAGE_SIZE)));
12707-
12708-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
12709+extern gate_desc idt_table[256];
12710+extern gate_desc nmi_idt_table[256];
12711
12712+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
12713 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
12714 {
12715- return per_cpu(gdt_page, cpu).gdt;
12716+ return cpu_gdt_table[cpu];
12717 }
12718
12719 #ifdef CONFIG_X86_64
12720@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
12721 unsigned long base, unsigned dpl, unsigned flags,
12722 unsigned short seg)
12723 {
12724- gate->a = (seg << 16) | (base & 0xffff);
12725- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
12726+ gate->gate.offset_low = base;
12727+ gate->gate.seg = seg;
12728+ gate->gate.reserved = 0;
12729+ gate->gate.type = type;
12730+ gate->gate.s = 0;
12731+ gate->gate.dpl = dpl;
12732+ gate->gate.p = 1;
12733+ gate->gate.offset_high = base >> 16;
12734 }
12735
12736 #endif
12737@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
12738
12739 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
12740 {
12741+ pax_open_kernel();
12742 memcpy(&idt[entry], gate, sizeof(*gate));
12743+ pax_close_kernel();
12744 }
12745
12746 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
12747 {
12748+ pax_open_kernel();
12749 memcpy(&ldt[entry], desc, 8);
12750+ pax_close_kernel();
12751 }
12752
12753 static inline void
12754@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
12755 default: size = sizeof(*gdt); break;
12756 }
12757
12758+ pax_open_kernel();
12759 memcpy(&gdt[entry], desc, size);
12760+ pax_close_kernel();
12761 }
12762
12763 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
12764@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
12765
12766 static inline void native_load_tr_desc(void)
12767 {
12768+ pax_open_kernel();
12769 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
12770+ pax_close_kernel();
12771 }
12772
12773 static inline void native_load_gdt(const struct desc_ptr *dtr)
12774@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
12775 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
12776 unsigned int i;
12777
12778+ pax_open_kernel();
12779 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
12780 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
12781+ pax_close_kernel();
12782 }
12783
12784 #define _LDT_empty(info) \
12785@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
12786 }
12787
12788 #ifdef CONFIG_X86_64
12789-static inline void set_nmi_gate(int gate, void *addr)
12790+static inline void set_nmi_gate(int gate, const void *addr)
12791 {
12792 gate_desc s;
12793
12794@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
12795 }
12796 #endif
12797
12798-static inline void _set_gate(int gate, unsigned type, void *addr,
12799+static inline void _set_gate(int gate, unsigned type, const void *addr,
12800 unsigned dpl, unsigned ist, unsigned seg)
12801 {
12802 gate_desc s;
12803@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
12804 * Pentium F0 0F bugfix can have resulted in the mapped
12805 * IDT being write-protected.
12806 */
12807-static inline void set_intr_gate(unsigned int n, void *addr)
12808+static inline void set_intr_gate(unsigned int n, const void *addr)
12809 {
12810 BUG_ON((unsigned)n > 0xFF);
12811 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
12812@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
12813 /*
12814 * This routine sets up an interrupt gate at directory privilege level 3.
12815 */
12816-static inline void set_system_intr_gate(unsigned int n, void *addr)
12817+static inline void set_system_intr_gate(unsigned int n, const void *addr)
12818 {
12819 BUG_ON((unsigned)n > 0xFF);
12820 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
12821 }
12822
12823-static inline void set_system_trap_gate(unsigned int n, void *addr)
12824+static inline void set_system_trap_gate(unsigned int n, const void *addr)
12825 {
12826 BUG_ON((unsigned)n > 0xFF);
12827 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
12828 }
12829
12830-static inline void set_trap_gate(unsigned int n, void *addr)
12831+static inline void set_trap_gate(unsigned int n, const void *addr)
12832 {
12833 BUG_ON((unsigned)n > 0xFF);
12834 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
12835@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
12836 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
12837 {
12838 BUG_ON((unsigned)n > 0xFF);
12839- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
12840+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
12841 }
12842
12843-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
12844+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
12845 {
12846 BUG_ON((unsigned)n > 0xFF);
12847 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
12848 }
12849
12850-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
12851+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
12852 {
12853 BUG_ON((unsigned)n > 0xFF);
12854 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
12855 }
12856
12857+#ifdef CONFIG_X86_32
12858+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
12859+{
12860+ struct desc_struct d;
12861+
12862+ if (likely(limit))
12863+ limit = (limit - 1UL) >> PAGE_SHIFT;
12864+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
12865+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
12866+}
12867+#endif
12868+
12869 #endif /* _ASM_X86_DESC_H */
12870diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
12871index 278441f..b95a174 100644
12872--- a/arch/x86/include/asm/desc_defs.h
12873+++ b/arch/x86/include/asm/desc_defs.h
12874@@ -31,6 +31,12 @@ struct desc_struct {
12875 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
12876 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
12877 };
12878+ struct {
12879+ u16 offset_low;
12880+ u16 seg;
12881+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
12882+ unsigned offset_high: 16;
12883+ } gate;
12884 };
12885 } __attribute__((packed));
12886
12887diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
12888index 9c999c1..3860cb8 100644
12889--- a/arch/x86/include/asm/elf.h
12890+++ b/arch/x86/include/asm/elf.h
12891@@ -243,7 +243,25 @@ extern int force_personality32;
12892 the loader. We need to make sure that it is out of the way of the program
12893 that it will "exec", and that there is sufficient room for the brk. */
12894
12895+#ifdef CONFIG_PAX_SEGMEXEC
12896+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
12897+#else
12898 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
12899+#endif
12900+
12901+#ifdef CONFIG_PAX_ASLR
12902+#ifdef CONFIG_X86_32
12903+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
12904+
12905+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
12906+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
12907+#else
12908+#define PAX_ELF_ET_DYN_BASE 0x400000UL
12909+
12910+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
12911+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
12912+#endif
12913+#endif
12914
12915 /* This yields a mask that user programs can use to figure out what
12916 instruction set this CPU supports. This could be done in user space,
12917@@ -296,16 +314,12 @@ do { \
12918
12919 #define ARCH_DLINFO \
12920 do { \
12921- if (vdso_enabled) \
12922- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
12923- (unsigned long)current->mm->context.vdso); \
12924+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
12925 } while (0)
12926
12927 #define ARCH_DLINFO_X32 \
12928 do { \
12929- if (vdso_enabled) \
12930- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
12931- (unsigned long)current->mm->context.vdso); \
12932+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
12933 } while (0)
12934
12935 #define AT_SYSINFO 32
12936@@ -320,7 +334,7 @@ else \
12937
12938 #endif /* !CONFIG_X86_32 */
12939
12940-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
12941+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
12942
12943 #define VDSO_ENTRY \
12944 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
12945@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
12946 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
12947 #define compat_arch_setup_additional_pages syscall32_setup_pages
12948
12949-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
12950-#define arch_randomize_brk arch_randomize_brk
12951-
12952 /*
12953 * True on X86_32 or when emulating IA32 on X86_64
12954 */
12955diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
12956index 75ce3f4..882e801 100644
12957--- a/arch/x86/include/asm/emergency-restart.h
12958+++ b/arch/x86/include/asm/emergency-restart.h
12959@@ -13,6 +13,6 @@ enum reboot_type {
12960
12961 extern enum reboot_type reboot_type;
12962
12963-extern void machine_emergency_restart(void);
12964+extern void machine_emergency_restart(void) __noreturn;
12965
12966 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
12967diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
12968index 41ab26e..a88c9e6 100644
12969--- a/arch/x86/include/asm/fpu-internal.h
12970+++ b/arch/x86/include/asm/fpu-internal.h
12971@@ -126,7 +126,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
12972 ({ \
12973 int err; \
12974 asm volatile(ASM_STAC "\n" \
12975- "1:" #insn "\n\t" \
12976+ "1:" \
12977+ __copyuser_seg \
12978+ #insn "\n\t" \
12979 "2: " ASM_CLAC "\n" \
12980 ".section .fixup,\"ax\"\n" \
12981 "3: movl $-1,%[err]\n" \
12982@@ -299,7 +301,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
12983 "emms\n\t" /* clear stack tags */
12984 "fildl %P[addr]", /* set F?P to defined value */
12985 X86_FEATURE_FXSAVE_LEAK,
12986- [addr] "m" (tsk->thread.fpu.has_fpu));
12987+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
12988
12989 return fpu_restore_checking(&tsk->thread.fpu);
12990 }
12991diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
12992index be27ba1..8f13ff9 100644
12993--- a/arch/x86/include/asm/futex.h
12994+++ b/arch/x86/include/asm/futex.h
12995@@ -12,6 +12,7 @@
12996 #include <asm/smap.h>
12997
12998 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
12999+ typecheck(u32 __user *, uaddr); \
13000 asm volatile("\t" ASM_STAC "\n" \
13001 "1:\t" insn "\n" \
13002 "2:\t" ASM_CLAC "\n" \
13003@@ -20,15 +21,16 @@
13004 "\tjmp\t2b\n" \
13005 "\t.previous\n" \
13006 _ASM_EXTABLE(1b, 3b) \
13007- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
13008+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
13009 : "i" (-EFAULT), "0" (oparg), "1" (0))
13010
13011 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
13012+ typecheck(u32 __user *, uaddr); \
13013 asm volatile("\t" ASM_STAC "\n" \
13014 "1:\tmovl %2, %0\n" \
13015 "\tmovl\t%0, %3\n" \
13016 "\t" insn "\n" \
13017- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
13018+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
13019 "\tjnz\t1b\n" \
13020 "3:\t" ASM_CLAC "\n" \
13021 "\t.section .fixup,\"ax\"\n" \
13022@@ -38,7 +40,7 @@
13023 _ASM_EXTABLE(1b, 4b) \
13024 _ASM_EXTABLE(2b, 4b) \
13025 : "=&a" (oldval), "=&r" (ret), \
13026- "+m" (*uaddr), "=&r" (tem) \
13027+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
13028 : "r" (oparg), "i" (-EFAULT), "1" (0))
13029
13030 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13031@@ -59,10 +61,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13032
13033 switch (op) {
13034 case FUTEX_OP_SET:
13035- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
13036+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
13037 break;
13038 case FUTEX_OP_ADD:
13039- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
13040+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
13041 uaddr, oparg);
13042 break;
13043 case FUTEX_OP_OR:
13044@@ -116,14 +118,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
13045 return -EFAULT;
13046
13047 asm volatile("\t" ASM_STAC "\n"
13048- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
13049+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
13050 "2:\t" ASM_CLAC "\n"
13051 "\t.section .fixup, \"ax\"\n"
13052 "3:\tmov %3, %0\n"
13053 "\tjmp 2b\n"
13054 "\t.previous\n"
13055 _ASM_EXTABLE(1b, 3b)
13056- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
13057+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
13058 : "i" (-EFAULT), "r" (newval), "1" (oldval)
13059 : "memory"
13060 );
13061diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
13062index eb92a6e..b98b2f4 100644
13063--- a/arch/x86/include/asm/hw_irq.h
13064+++ b/arch/x86/include/asm/hw_irq.h
13065@@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
13066 extern void enable_IO_APIC(void);
13067
13068 /* Statistics */
13069-extern atomic_t irq_err_count;
13070-extern atomic_t irq_mis_count;
13071+extern atomic_unchecked_t irq_err_count;
13072+extern atomic_unchecked_t irq_mis_count;
13073
13074 /* EISA */
13075 extern void eisa_set_level_irq(unsigned int irq);
13076diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
13077index d8e8eef..15b1179 100644
13078--- a/arch/x86/include/asm/io.h
13079+++ b/arch/x86/include/asm/io.h
13080@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
13081 return ioremap_nocache(offset, size);
13082 }
13083
13084-extern void iounmap(volatile void __iomem *addr);
13085+extern void iounmap(const volatile void __iomem *addr);
13086
13087 extern void set_iounmap_nonlazy(void);
13088
13089@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
13090
13091 #include <linux/vmalloc.h>
13092
13093+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
13094+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
13095+{
13096+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13097+}
13098+
13099+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
13100+{
13101+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13102+}
13103+
13104 /*
13105 * Convert a virtual cached pointer to an uncached pointer
13106 */
13107diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
13108index bba3cf8..06bc8da 100644
13109--- a/arch/x86/include/asm/irqflags.h
13110+++ b/arch/x86/include/asm/irqflags.h
13111@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
13112 sti; \
13113 sysexit
13114
13115+#define GET_CR0_INTO_RDI mov %cr0, %rdi
13116+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
13117+#define GET_CR3_INTO_RDI mov %cr3, %rdi
13118+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
13119+
13120 #else
13121 #define INTERRUPT_RETURN iret
13122 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
13123diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
13124index d3ddd17..c9fb0cc 100644
13125--- a/arch/x86/include/asm/kprobes.h
13126+++ b/arch/x86/include/asm/kprobes.h
13127@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
13128 #define RELATIVEJUMP_SIZE 5
13129 #define RELATIVECALL_OPCODE 0xe8
13130 #define RELATIVE_ADDR_SIZE 4
13131-#define MAX_STACK_SIZE 64
13132-#define MIN_STACK_SIZE(ADDR) \
13133- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
13134- THREAD_SIZE - (unsigned long)(ADDR))) \
13135- ? (MAX_STACK_SIZE) \
13136- : (((unsigned long)current_thread_info()) + \
13137- THREAD_SIZE - (unsigned long)(ADDR)))
13138+#define MAX_STACK_SIZE 64UL
13139+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
13140
13141 #define flush_insn_slot(p) do { } while (0)
13142
13143diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
13144index 2d89e39..baee879 100644
13145--- a/arch/x86/include/asm/local.h
13146+++ b/arch/x86/include/asm/local.h
13147@@ -10,33 +10,97 @@ typedef struct {
13148 atomic_long_t a;
13149 } local_t;
13150
13151+typedef struct {
13152+ atomic_long_unchecked_t a;
13153+} local_unchecked_t;
13154+
13155 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
13156
13157 #define local_read(l) atomic_long_read(&(l)->a)
13158+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
13159 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
13160+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
13161
13162 static inline void local_inc(local_t *l)
13163 {
13164- asm volatile(_ASM_INC "%0"
13165+ asm volatile(_ASM_INC "%0\n"
13166+
13167+#ifdef CONFIG_PAX_REFCOUNT
13168+ "jno 0f\n"
13169+ _ASM_DEC "%0\n"
13170+ "int $4\n0:\n"
13171+ _ASM_EXTABLE(0b, 0b)
13172+#endif
13173+
13174+ : "+m" (l->a.counter));
13175+}
13176+
13177+static inline void local_inc_unchecked(local_unchecked_t *l)
13178+{
13179+ asm volatile(_ASM_INC "%0\n"
13180 : "+m" (l->a.counter));
13181 }
13182
13183 static inline void local_dec(local_t *l)
13184 {
13185- asm volatile(_ASM_DEC "%0"
13186+ asm volatile(_ASM_DEC "%0\n"
13187+
13188+#ifdef CONFIG_PAX_REFCOUNT
13189+ "jno 0f\n"
13190+ _ASM_INC "%0\n"
13191+ "int $4\n0:\n"
13192+ _ASM_EXTABLE(0b, 0b)
13193+#endif
13194+
13195+ : "+m" (l->a.counter));
13196+}
13197+
13198+static inline void local_dec_unchecked(local_unchecked_t *l)
13199+{
13200+ asm volatile(_ASM_DEC "%0\n"
13201 : "+m" (l->a.counter));
13202 }
13203
13204 static inline void local_add(long i, local_t *l)
13205 {
13206- asm volatile(_ASM_ADD "%1,%0"
13207+ asm volatile(_ASM_ADD "%1,%0\n"
13208+
13209+#ifdef CONFIG_PAX_REFCOUNT
13210+ "jno 0f\n"
13211+ _ASM_SUB "%1,%0\n"
13212+ "int $4\n0:\n"
13213+ _ASM_EXTABLE(0b, 0b)
13214+#endif
13215+
13216+ : "+m" (l->a.counter)
13217+ : "ir" (i));
13218+}
13219+
13220+static inline void local_add_unchecked(long i, local_unchecked_t *l)
13221+{
13222+ asm volatile(_ASM_ADD "%1,%0\n"
13223 : "+m" (l->a.counter)
13224 : "ir" (i));
13225 }
13226
13227 static inline void local_sub(long i, local_t *l)
13228 {
13229- asm volatile(_ASM_SUB "%1,%0"
13230+ asm volatile(_ASM_SUB "%1,%0\n"
13231+
13232+#ifdef CONFIG_PAX_REFCOUNT
13233+ "jno 0f\n"
13234+ _ASM_ADD "%1,%0\n"
13235+ "int $4\n0:\n"
13236+ _ASM_EXTABLE(0b, 0b)
13237+#endif
13238+
13239+ : "+m" (l->a.counter)
13240+ : "ir" (i));
13241+}
13242+
13243+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
13244+{
13245+ asm volatile(_ASM_SUB "%1,%0\n"
13246 : "+m" (l->a.counter)
13247 : "ir" (i));
13248 }
13249@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
13250 {
13251 unsigned char c;
13252
13253- asm volatile(_ASM_SUB "%2,%0; sete %1"
13254+ asm volatile(_ASM_SUB "%2,%0\n"
13255+
13256+#ifdef CONFIG_PAX_REFCOUNT
13257+ "jno 0f\n"
13258+ _ASM_ADD "%2,%0\n"
13259+ "int $4\n0:\n"
13260+ _ASM_EXTABLE(0b, 0b)
13261+#endif
13262+
13263+ "sete %1\n"
13264 : "+m" (l->a.counter), "=qm" (c)
13265 : "ir" (i) : "memory");
13266 return c;
13267@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
13268 {
13269 unsigned char c;
13270
13271- asm volatile(_ASM_DEC "%0; sete %1"
13272+ asm volatile(_ASM_DEC "%0\n"
13273+
13274+#ifdef CONFIG_PAX_REFCOUNT
13275+ "jno 0f\n"
13276+ _ASM_INC "%0\n"
13277+ "int $4\n0:\n"
13278+ _ASM_EXTABLE(0b, 0b)
13279+#endif
13280+
13281+ "sete %1\n"
13282 : "+m" (l->a.counter), "=qm" (c)
13283 : : "memory");
13284 return c != 0;
13285@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
13286 {
13287 unsigned char c;
13288
13289- asm volatile(_ASM_INC "%0; sete %1"
13290+ asm volatile(_ASM_INC "%0\n"
13291+
13292+#ifdef CONFIG_PAX_REFCOUNT
13293+ "jno 0f\n"
13294+ _ASM_DEC "%0\n"
13295+ "int $4\n0:\n"
13296+ _ASM_EXTABLE(0b, 0b)
13297+#endif
13298+
13299+ "sete %1\n"
13300 : "+m" (l->a.counter), "=qm" (c)
13301 : : "memory");
13302 return c != 0;
13303@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
13304 {
13305 unsigned char c;
13306
13307- asm volatile(_ASM_ADD "%2,%0; sets %1"
13308+ asm volatile(_ASM_ADD "%2,%0\n"
13309+
13310+#ifdef CONFIG_PAX_REFCOUNT
13311+ "jno 0f\n"
13312+ _ASM_SUB "%2,%0\n"
13313+ "int $4\n0:\n"
13314+ _ASM_EXTABLE(0b, 0b)
13315+#endif
13316+
13317+ "sets %1\n"
13318 : "+m" (l->a.counter), "=qm" (c)
13319 : "ir" (i) : "memory");
13320 return c;
13321@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
13322 static inline long local_add_return(long i, local_t *l)
13323 {
13324 long __i = i;
13325+ asm volatile(_ASM_XADD "%0, %1\n"
13326+
13327+#ifdef CONFIG_PAX_REFCOUNT
13328+ "jno 0f\n"
13329+ _ASM_MOV "%0,%1\n"
13330+ "int $4\n0:\n"
13331+ _ASM_EXTABLE(0b, 0b)
13332+#endif
13333+
13334+ : "+r" (i), "+m" (l->a.counter)
13335+ : : "memory");
13336+ return i + __i;
13337+}
13338+
13339+/**
13340+ * local_add_return_unchecked - add and return
13341+ * @i: integer value to add
13342+ * @l: pointer to type local_unchecked_t
13343+ *
13344+ * Atomically adds @i to @l and returns @i + @l
13345+ */
13346+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
13347+{
13348+ long __i = i;
13349 asm volatile(_ASM_XADD "%0, %1;"
13350 : "+r" (i), "+m" (l->a.counter)
13351 : : "memory");
13352@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
13353
13354 #define local_cmpxchg(l, o, n) \
13355 (cmpxchg_local(&((l)->a.counter), (o), (n)))
13356+#define local_cmpxchg_unchecked(l, o, n) \
13357+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
13358 /* Always has a lock prefix */
13359 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
13360
13361diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
13362new file mode 100644
13363index 0000000..2bfd3ba
13364--- /dev/null
13365+++ b/arch/x86/include/asm/mman.h
13366@@ -0,0 +1,15 @@
13367+#ifndef _X86_MMAN_H
13368+#define _X86_MMAN_H
13369+
13370+#include <uapi/asm/mman.h>
13371+
13372+#ifdef __KERNEL__
13373+#ifndef __ASSEMBLY__
13374+#ifdef CONFIG_X86_32
13375+#define arch_mmap_check i386_mmap_check
13376+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
13377+#endif
13378+#endif
13379+#endif
13380+
13381+#endif /* X86_MMAN_H */
13382diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
13383index 5f55e69..e20bfb1 100644
13384--- a/arch/x86/include/asm/mmu.h
13385+++ b/arch/x86/include/asm/mmu.h
13386@@ -9,7 +9,7 @@
13387 * we put the segment information here.
13388 */
13389 typedef struct {
13390- void *ldt;
13391+ struct desc_struct *ldt;
13392 int size;
13393
13394 #ifdef CONFIG_X86_64
13395@@ -18,7 +18,19 @@ typedef struct {
13396 #endif
13397
13398 struct mutex lock;
13399- void *vdso;
13400+ unsigned long vdso;
13401+
13402+#ifdef CONFIG_X86_32
13403+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
13404+ unsigned long user_cs_base;
13405+ unsigned long user_cs_limit;
13406+
13407+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13408+ cpumask_t cpu_user_cs_mask;
13409+#endif
13410+
13411+#endif
13412+#endif
13413 } mm_context_t;
13414
13415 #ifdef CONFIG_SMP
13416diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
13417index cdbf367..adb37ac 100644
13418--- a/arch/x86/include/asm/mmu_context.h
13419+++ b/arch/x86/include/asm/mmu_context.h
13420@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
13421
13422 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
13423 {
13424+
13425+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13426+ unsigned int i;
13427+ pgd_t *pgd;
13428+
13429+ pax_open_kernel();
13430+ pgd = get_cpu_pgd(smp_processor_id());
13431+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
13432+ set_pgd_batched(pgd+i, native_make_pgd(0));
13433+ pax_close_kernel();
13434+#endif
13435+
13436 #ifdef CONFIG_SMP
13437 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
13438 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
13439@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13440 struct task_struct *tsk)
13441 {
13442 unsigned cpu = smp_processor_id();
13443+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13444+ int tlbstate = TLBSTATE_OK;
13445+#endif
13446
13447 if (likely(prev != next)) {
13448 #ifdef CONFIG_SMP
13449+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13450+ tlbstate = this_cpu_read(cpu_tlbstate.state);
13451+#endif
13452 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13453 this_cpu_write(cpu_tlbstate.active_mm, next);
13454 #endif
13455 cpumask_set_cpu(cpu, mm_cpumask(next));
13456
13457 /* Re-load page tables */
13458+#ifdef CONFIG_PAX_PER_CPU_PGD
13459+ pax_open_kernel();
13460+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13461+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13462+ pax_close_kernel();
13463+ load_cr3(get_cpu_pgd(cpu));
13464+#else
13465 load_cr3(next->pgd);
13466+#endif
13467
13468 /* stop flush ipis for the previous mm */
13469 cpumask_clear_cpu(cpu, mm_cpumask(prev));
13470@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13471 */
13472 if (unlikely(prev->context.ldt != next->context.ldt))
13473 load_LDT_nolock(&next->context);
13474- }
13475+
13476+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13477+ if (!(__supported_pte_mask & _PAGE_NX)) {
13478+ smp_mb__before_clear_bit();
13479+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
13480+ smp_mb__after_clear_bit();
13481+ cpu_set(cpu, next->context.cpu_user_cs_mask);
13482+ }
13483+#endif
13484+
13485+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13486+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
13487+ prev->context.user_cs_limit != next->context.user_cs_limit))
13488+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13489 #ifdef CONFIG_SMP
13490+ else if (unlikely(tlbstate != TLBSTATE_OK))
13491+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13492+#endif
13493+#endif
13494+
13495+ }
13496 else {
13497+
13498+#ifdef CONFIG_PAX_PER_CPU_PGD
13499+ pax_open_kernel();
13500+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13501+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13502+ pax_close_kernel();
13503+ load_cr3(get_cpu_pgd(cpu));
13504+#endif
13505+
13506+#ifdef CONFIG_SMP
13507 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13508 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
13509
13510@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13511 * tlb flush IPI delivery. We must reload CR3
13512 * to make sure to use no freed page tables.
13513 */
13514+
13515+#ifndef CONFIG_PAX_PER_CPU_PGD
13516 load_cr3(next->pgd);
13517+#endif
13518+
13519 load_LDT_nolock(&next->context);
13520+
13521+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
13522+ if (!(__supported_pte_mask & _PAGE_NX))
13523+ cpu_set(cpu, next->context.cpu_user_cs_mask);
13524+#endif
13525+
13526+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13527+#ifdef CONFIG_PAX_PAGEEXEC
13528+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
13529+#endif
13530+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13531+#endif
13532+
13533 }
13534+#endif
13535 }
13536-#endif
13537 }
13538
13539 #define activate_mm(prev, next) \
13540diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
13541index e3b7819..b257c64 100644
13542--- a/arch/x86/include/asm/module.h
13543+++ b/arch/x86/include/asm/module.h
13544@@ -5,6 +5,7 @@
13545
13546 #ifdef CONFIG_X86_64
13547 /* X86_64 does not define MODULE_PROC_FAMILY */
13548+#define MODULE_PROC_FAMILY ""
13549 #elif defined CONFIG_M486
13550 #define MODULE_PROC_FAMILY "486 "
13551 #elif defined CONFIG_M586
13552@@ -57,8 +58,20 @@
13553 #error unknown processor family
13554 #endif
13555
13556-#ifdef CONFIG_X86_32
13557-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
13558+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
13559+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
13560+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
13561+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
13562+#else
13563+#define MODULE_PAX_KERNEXEC ""
13564 #endif
13565
13566+#ifdef CONFIG_PAX_MEMORY_UDEREF
13567+#define MODULE_PAX_UDEREF "UDEREF "
13568+#else
13569+#define MODULE_PAX_UDEREF ""
13570+#endif
13571+
13572+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
13573+
13574 #endif /* _ASM_X86_MODULE_H */
13575diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
13576index 320f7bb..e89f8f8 100644
13577--- a/arch/x86/include/asm/page_64_types.h
13578+++ b/arch/x86/include/asm/page_64_types.h
13579@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
13580
13581 /* duplicated to the one in bootmem.h */
13582 extern unsigned long max_pfn;
13583-extern unsigned long phys_base;
13584+extern const unsigned long phys_base;
13585
13586 extern unsigned long __phys_addr(unsigned long);
13587 #define __phys_reloc_hide(x) (x)
13588diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
13589index 5edd174..9cf5821 100644
13590--- a/arch/x86/include/asm/paravirt.h
13591+++ b/arch/x86/include/asm/paravirt.h
13592@@ -630,6 +630,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
13593 val);
13594 }
13595
13596+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
13597+{
13598+ pgdval_t val = native_pgd_val(pgd);
13599+
13600+ if (sizeof(pgdval_t) > sizeof(long))
13601+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
13602+ val, (u64)val >> 32);
13603+ else
13604+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
13605+ val);
13606+}
13607+
13608 static inline void pgd_clear(pgd_t *pgdp)
13609 {
13610 set_pgd(pgdp, __pgd(0));
13611@@ -711,6 +723,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
13612 pv_mmu_ops.set_fixmap(idx, phys, flags);
13613 }
13614
13615+#ifdef CONFIG_PAX_KERNEXEC
13616+static inline unsigned long pax_open_kernel(void)
13617+{
13618+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
13619+}
13620+
13621+static inline unsigned long pax_close_kernel(void)
13622+{
13623+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
13624+}
13625+#else
13626+static inline unsigned long pax_open_kernel(void) { return 0; }
13627+static inline unsigned long pax_close_kernel(void) { return 0; }
13628+#endif
13629+
13630 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
13631
13632 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
13633@@ -927,7 +954,7 @@ extern void default_banner(void);
13634
13635 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
13636 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
13637-#define PARA_INDIRECT(addr) *%cs:addr
13638+#define PARA_INDIRECT(addr) *%ss:addr
13639 #endif
13640
13641 #define INTERRUPT_RETURN \
13642@@ -1002,6 +1029,21 @@ extern void default_banner(void);
13643 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
13644 CLBR_NONE, \
13645 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
13646+
13647+#define GET_CR0_INTO_RDI \
13648+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
13649+ mov %rax,%rdi
13650+
13651+#define SET_RDI_INTO_CR0 \
13652+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
13653+
13654+#define GET_CR3_INTO_RDI \
13655+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
13656+ mov %rax,%rdi
13657+
13658+#define SET_RDI_INTO_CR3 \
13659+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
13660+
13661 #endif /* CONFIG_X86_32 */
13662
13663 #endif /* __ASSEMBLY__ */
13664diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
13665index 142236e..5446ffbc 100644
13666--- a/arch/x86/include/asm/paravirt_types.h
13667+++ b/arch/x86/include/asm/paravirt_types.h
13668@@ -84,7 +84,7 @@ struct pv_init_ops {
13669 */
13670 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
13671 unsigned long addr, unsigned len);
13672-};
13673+} __no_const;
13674
13675
13676 struct pv_lazy_ops {
13677@@ -97,7 +97,7 @@ struct pv_time_ops {
13678 unsigned long long (*sched_clock)(void);
13679 unsigned long long (*steal_clock)(int cpu);
13680 unsigned long (*get_tsc_khz)(void);
13681-};
13682+} __no_const;
13683
13684 struct pv_cpu_ops {
13685 /* hooks for various privileged instructions */
13686@@ -191,7 +191,7 @@ struct pv_cpu_ops {
13687
13688 void (*start_context_switch)(struct task_struct *prev);
13689 void (*end_context_switch)(struct task_struct *next);
13690-};
13691+} __no_const;
13692
13693 struct pv_irq_ops {
13694 /*
13695@@ -222,7 +222,7 @@ struct pv_apic_ops {
13696 unsigned long start_eip,
13697 unsigned long start_esp);
13698 #endif
13699-};
13700+} __no_const;
13701
13702 struct pv_mmu_ops {
13703 unsigned long (*read_cr2)(void);
13704@@ -312,6 +312,7 @@ struct pv_mmu_ops {
13705 struct paravirt_callee_save make_pud;
13706
13707 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
13708+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
13709 #endif /* PAGETABLE_LEVELS == 4 */
13710 #endif /* PAGETABLE_LEVELS >= 3 */
13711
13712@@ -323,6 +324,12 @@ struct pv_mmu_ops {
13713 an mfn. We can tell which is which from the index. */
13714 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
13715 phys_addr_t phys, pgprot_t flags);
13716+
13717+#ifdef CONFIG_PAX_KERNEXEC
13718+ unsigned long (*pax_open_kernel)(void);
13719+ unsigned long (*pax_close_kernel)(void);
13720+#endif
13721+
13722 };
13723
13724 struct arch_spinlock;
13725@@ -333,7 +340,7 @@ struct pv_lock_ops {
13726 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
13727 int (*spin_trylock)(struct arch_spinlock *lock);
13728 void (*spin_unlock)(struct arch_spinlock *lock);
13729-};
13730+} __no_const;
13731
13732 /* This contains all the paravirt structures: we get a convenient
13733 * number for each function using the offset which we use to indicate
13734diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
13735index b4389a4..7024269 100644
13736--- a/arch/x86/include/asm/pgalloc.h
13737+++ b/arch/x86/include/asm/pgalloc.h
13738@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
13739 pmd_t *pmd, pte_t *pte)
13740 {
13741 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
13742+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
13743+}
13744+
13745+static inline void pmd_populate_user(struct mm_struct *mm,
13746+ pmd_t *pmd, pte_t *pte)
13747+{
13748+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
13749 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
13750 }
13751
13752@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
13753
13754 #ifdef CONFIG_X86_PAE
13755 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
13756+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
13757+{
13758+ pud_populate(mm, pudp, pmd);
13759+}
13760 #else /* !CONFIG_X86_PAE */
13761 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
13762 {
13763 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
13764 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
13765 }
13766+
13767+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
13768+{
13769+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
13770+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
13771+}
13772 #endif /* CONFIG_X86_PAE */
13773
13774 #if PAGETABLE_LEVELS > 3
13775@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
13776 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
13777 }
13778
13779+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
13780+{
13781+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
13782+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
13783+}
13784+
13785 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
13786 {
13787 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
13788diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
13789index f2b489c..4f7e2e5 100644
13790--- a/arch/x86/include/asm/pgtable-2level.h
13791+++ b/arch/x86/include/asm/pgtable-2level.h
13792@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
13793
13794 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
13795 {
13796+ pax_open_kernel();
13797 *pmdp = pmd;
13798+ pax_close_kernel();
13799 }
13800
13801 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
13802diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
13803index 4cc9f2b..5fd9226 100644
13804--- a/arch/x86/include/asm/pgtable-3level.h
13805+++ b/arch/x86/include/asm/pgtable-3level.h
13806@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
13807
13808 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
13809 {
13810+ pax_open_kernel();
13811 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
13812+ pax_close_kernel();
13813 }
13814
13815 static inline void native_set_pud(pud_t *pudp, pud_t pud)
13816 {
13817+ pax_open_kernel();
13818 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
13819+ pax_close_kernel();
13820 }
13821
13822 /*
13823diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
13824index 1c1a955..50f828c 100644
13825--- a/arch/x86/include/asm/pgtable.h
13826+++ b/arch/x86/include/asm/pgtable.h
13827@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
13828
13829 #ifndef __PAGETABLE_PUD_FOLDED
13830 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
13831+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
13832 #define pgd_clear(pgd) native_pgd_clear(pgd)
13833 #endif
13834
13835@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
13836
13837 #define arch_end_context_switch(prev) do {} while(0)
13838
13839+#define pax_open_kernel() native_pax_open_kernel()
13840+#define pax_close_kernel() native_pax_close_kernel()
13841 #endif /* CONFIG_PARAVIRT */
13842
13843+#define __HAVE_ARCH_PAX_OPEN_KERNEL
13844+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
13845+
13846+#ifdef CONFIG_PAX_KERNEXEC
13847+static inline unsigned long native_pax_open_kernel(void)
13848+{
13849+ unsigned long cr0;
13850+
13851+ preempt_disable();
13852+ barrier();
13853+ cr0 = read_cr0() ^ X86_CR0_WP;
13854+ BUG_ON(cr0 & X86_CR0_WP);
13855+ write_cr0(cr0);
13856+ return cr0 ^ X86_CR0_WP;
13857+}
13858+
13859+static inline unsigned long native_pax_close_kernel(void)
13860+{
13861+ unsigned long cr0;
13862+
13863+ cr0 = read_cr0() ^ X86_CR0_WP;
13864+ BUG_ON(!(cr0 & X86_CR0_WP));
13865+ write_cr0(cr0);
13866+ barrier();
13867+ preempt_enable_no_resched();
13868+ return cr0 ^ X86_CR0_WP;
13869+}
13870+#else
13871+static inline unsigned long native_pax_open_kernel(void) { return 0; }
13872+static inline unsigned long native_pax_close_kernel(void) { return 0; }
13873+#endif
13874+
13875 /*
13876 * The following only work if pte_present() is true.
13877 * Undefined behaviour if not..
13878 */
13879+static inline int pte_user(pte_t pte)
13880+{
13881+ return pte_val(pte) & _PAGE_USER;
13882+}
13883+
13884 static inline int pte_dirty(pte_t pte)
13885 {
13886 return pte_flags(pte) & _PAGE_DIRTY;
13887@@ -200,9 +240,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
13888 return pte_clear_flags(pte, _PAGE_RW);
13889 }
13890
13891+static inline pte_t pte_mkread(pte_t pte)
13892+{
13893+ return __pte(pte_val(pte) | _PAGE_USER);
13894+}
13895+
13896 static inline pte_t pte_mkexec(pte_t pte)
13897 {
13898- return pte_clear_flags(pte, _PAGE_NX);
13899+#ifdef CONFIG_X86_PAE
13900+ if (__supported_pte_mask & _PAGE_NX)
13901+ return pte_clear_flags(pte, _PAGE_NX);
13902+ else
13903+#endif
13904+ return pte_set_flags(pte, _PAGE_USER);
13905+}
13906+
13907+static inline pte_t pte_exprotect(pte_t pte)
13908+{
13909+#ifdef CONFIG_X86_PAE
13910+ if (__supported_pte_mask & _PAGE_NX)
13911+ return pte_set_flags(pte, _PAGE_NX);
13912+ else
13913+#endif
13914+ return pte_clear_flags(pte, _PAGE_USER);
13915 }
13916
13917 static inline pte_t pte_mkdirty(pte_t pte)
13918@@ -394,6 +454,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
13919 #endif
13920
13921 #ifndef __ASSEMBLY__
13922+
13923+#ifdef CONFIG_PAX_PER_CPU_PGD
13924+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
13925+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
13926+{
13927+ return cpu_pgd[cpu];
13928+}
13929+#endif
13930+
13931 #include <linux/mm_types.h>
13932
13933 static inline int pte_none(pte_t pte)
13934@@ -583,7 +652,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
13935
13936 static inline int pgd_bad(pgd_t pgd)
13937 {
13938- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
13939+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
13940 }
13941
13942 static inline int pgd_none(pgd_t pgd)
13943@@ -606,7 +675,12 @@ static inline int pgd_none(pgd_t pgd)
13944 * pgd_offset() returns a (pgd_t *)
13945 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
13946 */
13947-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
13948+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
13949+
13950+#ifdef CONFIG_PAX_PER_CPU_PGD
13951+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
13952+#endif
13953+
13954 /*
13955 * a shortcut which implies the use of the kernel's pgd, instead
13956 * of a process's
13957@@ -617,6 +691,20 @@ static inline int pgd_none(pgd_t pgd)
13958 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
13959 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
13960
13961+#ifdef CONFIG_X86_32
13962+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
13963+#else
13964+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
13965+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
13966+
13967+#ifdef CONFIG_PAX_MEMORY_UDEREF
13968+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
13969+#else
13970+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
13971+#endif
13972+
13973+#endif
13974+
13975 #ifndef __ASSEMBLY__
13976
13977 extern int direct_gbpages;
13978@@ -781,11 +869,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
13979 * dst and src can be on the same page, but the range must not overlap,
13980 * and must not cross a page boundary.
13981 */
13982-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
13983+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
13984 {
13985- memcpy(dst, src, count * sizeof(pgd_t));
13986+ pax_open_kernel();
13987+ while (count--)
13988+ *dst++ = *src++;
13989+ pax_close_kernel();
13990 }
13991
13992+#ifdef CONFIG_PAX_PER_CPU_PGD
13993+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
13994+#endif
13995+
13996+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13997+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
13998+#else
13999+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
14000+#endif
14001
14002 #include <asm-generic/pgtable.h>
14003 #endif /* __ASSEMBLY__ */
14004diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
14005index 8faa215..a8a17ea 100644
14006--- a/arch/x86/include/asm/pgtable_32.h
14007+++ b/arch/x86/include/asm/pgtable_32.h
14008@@ -25,9 +25,6 @@
14009 struct mm_struct;
14010 struct vm_area_struct;
14011
14012-extern pgd_t swapper_pg_dir[1024];
14013-extern pgd_t initial_page_table[1024];
14014-
14015 static inline void pgtable_cache_init(void) { }
14016 static inline void check_pgt_cache(void) { }
14017 void paging_init(void);
14018@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14019 # include <asm/pgtable-2level.h>
14020 #endif
14021
14022+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
14023+extern pgd_t initial_page_table[PTRS_PER_PGD];
14024+#ifdef CONFIG_X86_PAE
14025+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
14026+#endif
14027+
14028 #if defined(CONFIG_HIGHPTE)
14029 #define pte_offset_map(dir, address) \
14030 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
14031@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14032 /* Clear a kernel PTE and flush it from the TLB */
14033 #define kpte_clear_flush(ptep, vaddr) \
14034 do { \
14035+ pax_open_kernel(); \
14036 pte_clear(&init_mm, (vaddr), (ptep)); \
14037+ pax_close_kernel(); \
14038 __flush_tlb_one((vaddr)); \
14039 } while (0)
14040
14041@@ -75,6 +80,9 @@ do { \
14042
14043 #endif /* !__ASSEMBLY__ */
14044
14045+#define HAVE_ARCH_UNMAPPED_AREA
14046+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
14047+
14048 /*
14049 * kern_addr_valid() is (1) for FLATMEM and (0) for
14050 * SPARSEMEM and DISCONTIGMEM
14051diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
14052index ed5903b..c7fe163 100644
14053--- a/arch/x86/include/asm/pgtable_32_types.h
14054+++ b/arch/x86/include/asm/pgtable_32_types.h
14055@@ -8,7 +8,7 @@
14056 */
14057 #ifdef CONFIG_X86_PAE
14058 # include <asm/pgtable-3level_types.h>
14059-# define PMD_SIZE (1UL << PMD_SHIFT)
14060+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
14061 # define PMD_MASK (~(PMD_SIZE - 1))
14062 #else
14063 # include <asm/pgtable-2level_types.h>
14064@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
14065 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
14066 #endif
14067
14068+#ifdef CONFIG_PAX_KERNEXEC
14069+#ifndef __ASSEMBLY__
14070+extern unsigned char MODULES_EXEC_VADDR[];
14071+extern unsigned char MODULES_EXEC_END[];
14072+#endif
14073+#include <asm/boot.h>
14074+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
14075+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
14076+#else
14077+#define ktla_ktva(addr) (addr)
14078+#define ktva_ktla(addr) (addr)
14079+#endif
14080+
14081 #define MODULES_VADDR VMALLOC_START
14082 #define MODULES_END VMALLOC_END
14083 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
14084diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
14085index 47356f9..deb94a2 100644
14086--- a/arch/x86/include/asm/pgtable_64.h
14087+++ b/arch/x86/include/asm/pgtable_64.h
14088@@ -16,10 +16,14 @@
14089
14090 extern pud_t level3_kernel_pgt[512];
14091 extern pud_t level3_ident_pgt[512];
14092+extern pud_t level3_vmalloc_start_pgt[512];
14093+extern pud_t level3_vmalloc_end_pgt[512];
14094+extern pud_t level3_vmemmap_pgt[512];
14095+extern pud_t level2_vmemmap_pgt[512];
14096 extern pmd_t level2_kernel_pgt[512];
14097 extern pmd_t level2_fixmap_pgt[512];
14098-extern pmd_t level2_ident_pgt[512];
14099-extern pgd_t init_level4_pgt[];
14100+extern pmd_t level2_ident_pgt[512*2];
14101+extern pgd_t init_level4_pgt[512];
14102
14103 #define swapper_pg_dir init_level4_pgt
14104
14105@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14106
14107 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14108 {
14109+ pax_open_kernel();
14110 *pmdp = pmd;
14111+ pax_close_kernel();
14112 }
14113
14114 static inline void native_pmd_clear(pmd_t *pmd)
14115@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
14116
14117 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14118 {
14119+ pax_open_kernel();
14120 *pudp = pud;
14121+ pax_close_kernel();
14122 }
14123
14124 static inline void native_pud_clear(pud_t *pud)
14125@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
14126
14127 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
14128 {
14129+ pax_open_kernel();
14130+ *pgdp = pgd;
14131+ pax_close_kernel();
14132+}
14133+
14134+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14135+{
14136 *pgdp = pgd;
14137 }
14138
14139diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
14140index 766ea16..5b96cb3 100644
14141--- a/arch/x86/include/asm/pgtable_64_types.h
14142+++ b/arch/x86/include/asm/pgtable_64_types.h
14143@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
14144 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
14145 #define MODULES_END _AC(0xffffffffff000000, UL)
14146 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
14147+#define MODULES_EXEC_VADDR MODULES_VADDR
14148+#define MODULES_EXEC_END MODULES_END
14149+
14150+#define ktla_ktva(addr) (addr)
14151+#define ktva_ktla(addr) (addr)
14152
14153 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
14154diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
14155index 3c32db8..1ddccf5 100644
14156--- a/arch/x86/include/asm/pgtable_types.h
14157+++ b/arch/x86/include/asm/pgtable_types.h
14158@@ -16,13 +16,12 @@
14159 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
14160 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
14161 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
14162-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
14163+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
14164 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
14165 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
14166 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
14167-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
14168-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
14169-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
14170+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
14171+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
14172 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
14173
14174 /* If _PAGE_BIT_PRESENT is clear, we use these: */
14175@@ -40,7 +39,6 @@
14176 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
14177 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
14178 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
14179-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
14180 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
14181 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
14182 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
14183@@ -57,8 +55,10 @@
14184
14185 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
14186 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
14187-#else
14188+#elif defined(CONFIG_KMEMCHECK)
14189 #define _PAGE_NX (_AT(pteval_t, 0))
14190+#else
14191+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
14192 #endif
14193
14194 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
14195@@ -116,6 +116,9 @@
14196 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
14197 _PAGE_ACCESSED)
14198
14199+#define PAGE_READONLY_NOEXEC PAGE_READONLY
14200+#define PAGE_SHARED_NOEXEC PAGE_SHARED
14201+
14202 #define __PAGE_KERNEL_EXEC \
14203 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
14204 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
14205@@ -126,7 +129,7 @@
14206 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
14207 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
14208 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
14209-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
14210+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
14211 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
14212 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
14213 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
14214@@ -188,8 +191,8 @@
14215 * bits are combined, this will alow user to access the high address mapped
14216 * VDSO in the presence of CONFIG_COMPAT_VDSO
14217 */
14218-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
14219-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
14220+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14221+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14222 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
14223 #endif
14224
14225@@ -227,7 +230,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
14226 {
14227 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
14228 }
14229+#endif
14230
14231+#if PAGETABLE_LEVELS == 3
14232+#include <asm-generic/pgtable-nopud.h>
14233+#endif
14234+
14235+#if PAGETABLE_LEVELS == 2
14236+#include <asm-generic/pgtable-nopmd.h>
14237+#endif
14238+
14239+#ifndef __ASSEMBLY__
14240 #if PAGETABLE_LEVELS > 3
14241 typedef struct { pudval_t pud; } pud_t;
14242
14243@@ -241,8 +254,6 @@ static inline pudval_t native_pud_val(pud_t pud)
14244 return pud.pud;
14245 }
14246 #else
14247-#include <asm-generic/pgtable-nopud.h>
14248-
14249 static inline pudval_t native_pud_val(pud_t pud)
14250 {
14251 return native_pgd_val(pud.pgd);
14252@@ -262,8 +273,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
14253 return pmd.pmd;
14254 }
14255 #else
14256-#include <asm-generic/pgtable-nopmd.h>
14257-
14258 static inline pmdval_t native_pmd_val(pmd_t pmd)
14259 {
14260 return native_pgd_val(pmd.pud.pgd);
14261@@ -303,7 +312,6 @@ typedef struct page *pgtable_t;
14262
14263 extern pteval_t __supported_pte_mask;
14264 extern void set_nx(void);
14265-extern int nx_enabled;
14266
14267 #define pgprot_writecombine pgprot_writecombine
14268 extern pgprot_t pgprot_writecombine(pgprot_t prot);
14269diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
14270index 888184b..a07ac89 100644
14271--- a/arch/x86/include/asm/processor.h
14272+++ b/arch/x86/include/asm/processor.h
14273@@ -287,7 +287,7 @@ struct tss_struct {
14274
14275 } ____cacheline_aligned;
14276
14277-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
14278+extern struct tss_struct init_tss[NR_CPUS];
14279
14280 /*
14281 * Save the original ist values for checking stack pointers during debugging
14282@@ -827,11 +827,18 @@ static inline void spin_lock_prefetch(const void *x)
14283 */
14284 #define TASK_SIZE PAGE_OFFSET
14285 #define TASK_SIZE_MAX TASK_SIZE
14286+
14287+#ifdef CONFIG_PAX_SEGMEXEC
14288+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
14289+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
14290+#else
14291 #define STACK_TOP TASK_SIZE
14292-#define STACK_TOP_MAX STACK_TOP
14293+#endif
14294+
14295+#define STACK_TOP_MAX TASK_SIZE
14296
14297 #define INIT_THREAD { \
14298- .sp0 = sizeof(init_stack) + (long)&init_stack, \
14299+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14300 .vm86_info = NULL, \
14301 .sysenter_cs = __KERNEL_CS, \
14302 .io_bitmap_ptr = NULL, \
14303@@ -845,7 +852,7 @@ static inline void spin_lock_prefetch(const void *x)
14304 */
14305 #define INIT_TSS { \
14306 .x86_tss = { \
14307- .sp0 = sizeof(init_stack) + (long)&init_stack, \
14308+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14309 .ss0 = __KERNEL_DS, \
14310 .ss1 = __KERNEL_CS, \
14311 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
14312@@ -856,11 +863,7 @@ static inline void spin_lock_prefetch(const void *x)
14313 extern unsigned long thread_saved_pc(struct task_struct *tsk);
14314
14315 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
14316-#define KSTK_TOP(info) \
14317-({ \
14318- unsigned long *__ptr = (unsigned long *)(info); \
14319- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
14320-})
14321+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
14322
14323 /*
14324 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
14325@@ -875,7 +878,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14326 #define task_pt_regs(task) \
14327 ({ \
14328 struct pt_regs *__regs__; \
14329- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
14330+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
14331 __regs__ - 1; \
14332 })
14333
14334@@ -885,13 +888,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14335 /*
14336 * User space process size. 47bits minus one guard page.
14337 */
14338-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
14339+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
14340
14341 /* This decides where the kernel will search for a free chunk of vm
14342 * space during mmap's.
14343 */
14344 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
14345- 0xc0000000 : 0xFFFFe000)
14346+ 0xc0000000 : 0xFFFFf000)
14347
14348 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
14349 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
14350@@ -902,11 +905,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14351 #define STACK_TOP_MAX TASK_SIZE_MAX
14352
14353 #define INIT_THREAD { \
14354- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14355+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14356 }
14357
14358 #define INIT_TSS { \
14359- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14360+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14361 }
14362
14363 /*
14364@@ -934,6 +937,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
14365 */
14366 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
14367
14368+#ifdef CONFIG_PAX_SEGMEXEC
14369+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
14370+#endif
14371+
14372 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
14373
14374 /* Get/set a process' ability to use the timestamp counter instruction */
14375@@ -994,12 +1001,12 @@ extern bool cpu_has_amd_erratum(const int *);
14376 #define cpu_has_amd_erratum(x) (false)
14377 #endif /* CONFIG_CPU_SUP_AMD */
14378
14379-extern unsigned long arch_align_stack(unsigned long sp);
14380+#define arch_align_stack(x) ((x) & ~0xfUL)
14381 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
14382
14383 void default_idle(void);
14384 bool set_pm_idle_to_default(void);
14385
14386-void stop_this_cpu(void *dummy);
14387+void stop_this_cpu(void *dummy) __noreturn;
14388
14389 #endif /* _ASM_X86_PROCESSOR_H */
14390diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
14391index 942a086..6c26446 100644
14392--- a/arch/x86/include/asm/ptrace.h
14393+++ b/arch/x86/include/asm/ptrace.h
14394@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
14395 }
14396
14397 /*
14398- * user_mode_vm(regs) determines whether a register set came from user mode.
14399+ * user_mode(regs) determines whether a register set came from user mode.
14400 * This is true if V8086 mode was enabled OR if the register set was from
14401 * protected mode with RPL-3 CS value. This tricky test checks that with
14402 * one comparison. Many places in the kernel can bypass this full check
14403- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
14404+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
14405+ * be used.
14406 */
14407-static inline int user_mode(struct pt_regs *regs)
14408+static inline int user_mode_novm(struct pt_regs *regs)
14409 {
14410 #ifdef CONFIG_X86_32
14411 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
14412 #else
14413- return !!(regs->cs & 3);
14414+ return !!(regs->cs & SEGMENT_RPL_MASK);
14415 #endif
14416 }
14417
14418-static inline int user_mode_vm(struct pt_regs *regs)
14419+static inline int user_mode(struct pt_regs *regs)
14420 {
14421 #ifdef CONFIG_X86_32
14422 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
14423 USER_RPL;
14424 #else
14425- return user_mode(regs);
14426+ return user_mode_novm(regs);
14427 #endif
14428 }
14429
14430@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
14431 #ifdef CONFIG_X86_64
14432 static inline bool user_64bit_mode(struct pt_regs *regs)
14433 {
14434+ unsigned long cs = regs->cs & 0xffff;
14435 #ifndef CONFIG_PARAVIRT
14436 /*
14437 * On non-paravirt systems, this is the only long mode CPL 3
14438 * selector. We do not allow long mode selectors in the LDT.
14439 */
14440- return regs->cs == __USER_CS;
14441+ return cs == __USER_CS;
14442 #else
14443 /* Headers are too twisted for this to go in paravirt.h. */
14444- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
14445+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
14446 #endif
14447 }
14448
14449@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
14450 * Traps from the kernel do not save sp and ss.
14451 * Use the helper function to retrieve sp.
14452 */
14453- if (offset == offsetof(struct pt_regs, sp) &&
14454- regs->cs == __KERNEL_CS)
14455- return kernel_stack_pointer(regs);
14456+ if (offset == offsetof(struct pt_regs, sp)) {
14457+ unsigned long cs = regs->cs & 0xffff;
14458+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
14459+ return kernel_stack_pointer(regs);
14460+ }
14461 #endif
14462 return *(unsigned long *)((unsigned long)regs + offset);
14463 }
14464diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
14465index fe1ec5b..dc5c3fe 100644
14466--- a/arch/x86/include/asm/realmode.h
14467+++ b/arch/x86/include/asm/realmode.h
14468@@ -22,16 +22,14 @@ struct real_mode_header {
14469 #endif
14470 /* APM/BIOS reboot */
14471 u32 machine_real_restart_asm;
14472-#ifdef CONFIG_X86_64
14473 u32 machine_real_restart_seg;
14474-#endif
14475 };
14476
14477 /* This must match data at trampoline_32/64.S */
14478 struct trampoline_header {
14479 #ifdef CONFIG_X86_32
14480 u32 start;
14481- u16 gdt_pad;
14482+ u16 boot_cs;
14483 u16 gdt_limit;
14484 u32 gdt_base;
14485 #else
14486diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
14487index a82c4f1..ac45053 100644
14488--- a/arch/x86/include/asm/reboot.h
14489+++ b/arch/x86/include/asm/reboot.h
14490@@ -6,13 +6,13 @@
14491 struct pt_regs;
14492
14493 struct machine_ops {
14494- void (*restart)(char *cmd);
14495- void (*halt)(void);
14496- void (*power_off)(void);
14497+ void (* __noreturn restart)(char *cmd);
14498+ void (* __noreturn halt)(void);
14499+ void (* __noreturn power_off)(void);
14500 void (*shutdown)(void);
14501 void (*crash_shutdown)(struct pt_regs *);
14502- void (*emergency_restart)(void);
14503-};
14504+ void (* __noreturn emergency_restart)(void);
14505+} __no_const;
14506
14507 extern struct machine_ops machine_ops;
14508
14509diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
14510index 2dbe4a7..ce1db00 100644
14511--- a/arch/x86/include/asm/rwsem.h
14512+++ b/arch/x86/include/asm/rwsem.h
14513@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
14514 {
14515 asm volatile("# beginning down_read\n\t"
14516 LOCK_PREFIX _ASM_INC "(%1)\n\t"
14517+
14518+#ifdef CONFIG_PAX_REFCOUNT
14519+ "jno 0f\n"
14520+ LOCK_PREFIX _ASM_DEC "(%1)\n"
14521+ "int $4\n0:\n"
14522+ _ASM_EXTABLE(0b, 0b)
14523+#endif
14524+
14525 /* adds 0x00000001 */
14526 " jns 1f\n"
14527 " call call_rwsem_down_read_failed\n"
14528@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
14529 "1:\n\t"
14530 " mov %1,%2\n\t"
14531 " add %3,%2\n\t"
14532+
14533+#ifdef CONFIG_PAX_REFCOUNT
14534+ "jno 0f\n"
14535+ "sub %3,%2\n"
14536+ "int $4\n0:\n"
14537+ _ASM_EXTABLE(0b, 0b)
14538+#endif
14539+
14540 " jle 2f\n\t"
14541 LOCK_PREFIX " cmpxchg %2,%0\n\t"
14542 " jnz 1b\n\t"
14543@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
14544 long tmp;
14545 asm volatile("# beginning down_write\n\t"
14546 LOCK_PREFIX " xadd %1,(%2)\n\t"
14547+
14548+#ifdef CONFIG_PAX_REFCOUNT
14549+ "jno 0f\n"
14550+ "mov %1,(%2)\n"
14551+ "int $4\n0:\n"
14552+ _ASM_EXTABLE(0b, 0b)
14553+#endif
14554+
14555 /* adds 0xffff0001, returns the old value */
14556 " test %1,%1\n\t"
14557 /* was the count 0 before? */
14558@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
14559 long tmp;
14560 asm volatile("# beginning __up_read\n\t"
14561 LOCK_PREFIX " xadd %1,(%2)\n\t"
14562+
14563+#ifdef CONFIG_PAX_REFCOUNT
14564+ "jno 0f\n"
14565+ "mov %1,(%2)\n"
14566+ "int $4\n0:\n"
14567+ _ASM_EXTABLE(0b, 0b)
14568+#endif
14569+
14570 /* subtracts 1, returns the old value */
14571 " jns 1f\n\t"
14572 " call call_rwsem_wake\n" /* expects old value in %edx */
14573@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
14574 long tmp;
14575 asm volatile("# beginning __up_write\n\t"
14576 LOCK_PREFIX " xadd %1,(%2)\n\t"
14577+
14578+#ifdef CONFIG_PAX_REFCOUNT
14579+ "jno 0f\n"
14580+ "mov %1,(%2)\n"
14581+ "int $4\n0:\n"
14582+ _ASM_EXTABLE(0b, 0b)
14583+#endif
14584+
14585 /* subtracts 0xffff0001, returns the old value */
14586 " jns 1f\n\t"
14587 " call call_rwsem_wake\n" /* expects old value in %edx */
14588@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
14589 {
14590 asm volatile("# beginning __downgrade_write\n\t"
14591 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
14592+
14593+#ifdef CONFIG_PAX_REFCOUNT
14594+ "jno 0f\n"
14595+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
14596+ "int $4\n0:\n"
14597+ _ASM_EXTABLE(0b, 0b)
14598+#endif
14599+
14600 /*
14601 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
14602 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
14603@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
14604 */
14605 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
14606 {
14607- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
14608+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
14609+
14610+#ifdef CONFIG_PAX_REFCOUNT
14611+ "jno 0f\n"
14612+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
14613+ "int $4\n0:\n"
14614+ _ASM_EXTABLE(0b, 0b)
14615+#endif
14616+
14617 : "+m" (sem->count)
14618 : "er" (delta));
14619 }
14620@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
14621 */
14622 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
14623 {
14624- return delta + xadd(&sem->count, delta);
14625+ return delta + xadd_check_overflow(&sem->count, delta);
14626 }
14627
14628 #endif /* __KERNEL__ */
14629diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
14630index c48a950..c6d7468 100644
14631--- a/arch/x86/include/asm/segment.h
14632+++ b/arch/x86/include/asm/segment.h
14633@@ -64,10 +64,15 @@
14634 * 26 - ESPFIX small SS
14635 * 27 - per-cpu [ offset to per-cpu data area ]
14636 * 28 - stack_canary-20 [ for stack protector ]
14637- * 29 - unused
14638- * 30 - unused
14639+ * 29 - PCI BIOS CS
14640+ * 30 - PCI BIOS DS
14641 * 31 - TSS for double fault handler
14642 */
14643+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
14644+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
14645+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
14646+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
14647+
14648 #define GDT_ENTRY_TLS_MIN 6
14649 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
14650
14651@@ -79,6 +84,8 @@
14652
14653 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
14654
14655+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
14656+
14657 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
14658
14659 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
14660@@ -104,6 +111,12 @@
14661 #define __KERNEL_STACK_CANARY 0
14662 #endif
14663
14664+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
14665+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
14666+
14667+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
14668+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
14669+
14670 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
14671
14672 /*
14673@@ -141,7 +154,7 @@
14674 */
14675
14676 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
14677-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
14678+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
14679
14680
14681 #else
14682@@ -165,6 +178,8 @@
14683 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
14684 #define __USER32_DS __USER_DS
14685
14686+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
14687+
14688 #define GDT_ENTRY_TSS 8 /* needs two entries */
14689 #define GDT_ENTRY_LDT 10 /* needs two entries */
14690 #define GDT_ENTRY_TLS_MIN 12
14691@@ -185,6 +200,7 @@
14692 #endif
14693
14694 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
14695+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
14696 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
14697 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
14698 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
14699@@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
14700 {
14701 unsigned long __limit;
14702 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
14703- return __limit + 1;
14704+ return __limit;
14705 }
14706
14707 #endif /* !__ASSEMBLY__ */
14708diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
14709index b073aae..39f9bdd 100644
14710--- a/arch/x86/include/asm/smp.h
14711+++ b/arch/x86/include/asm/smp.h
14712@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
14713 /* cpus sharing the last level cache: */
14714 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
14715 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
14716-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
14717+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
14718
14719 static inline struct cpumask *cpu_sibling_mask(int cpu)
14720 {
14721@@ -79,7 +79,7 @@ struct smp_ops {
14722
14723 void (*send_call_func_ipi)(const struct cpumask *mask);
14724 void (*send_call_func_single_ipi)(int cpu);
14725-};
14726+} __no_const;
14727
14728 /* Globals due to paravirt */
14729 extern void set_cpu_sibling_map(int cpu);
14730@@ -191,14 +191,8 @@ extern unsigned disabled_cpus __cpuinitdata;
14731 extern int safe_smp_processor_id(void);
14732
14733 #elif defined(CONFIG_X86_64_SMP)
14734-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
14735-
14736-#define stack_smp_processor_id() \
14737-({ \
14738- struct thread_info *ti; \
14739- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
14740- ti->cpu; \
14741-})
14742+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
14743+#define stack_smp_processor_id() raw_smp_processor_id()
14744 #define safe_smp_processor_id() smp_processor_id()
14745
14746 #endif
14747diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
14748index 33692ea..350a534 100644
14749--- a/arch/x86/include/asm/spinlock.h
14750+++ b/arch/x86/include/asm/spinlock.h
14751@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
14752 static inline void arch_read_lock(arch_rwlock_t *rw)
14753 {
14754 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
14755+
14756+#ifdef CONFIG_PAX_REFCOUNT
14757+ "jno 0f\n"
14758+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
14759+ "int $4\n0:\n"
14760+ _ASM_EXTABLE(0b, 0b)
14761+#endif
14762+
14763 "jns 1f\n"
14764 "call __read_lock_failed\n\t"
14765 "1:\n"
14766@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
14767 static inline void arch_write_lock(arch_rwlock_t *rw)
14768 {
14769 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
14770+
14771+#ifdef CONFIG_PAX_REFCOUNT
14772+ "jno 0f\n"
14773+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
14774+ "int $4\n0:\n"
14775+ _ASM_EXTABLE(0b, 0b)
14776+#endif
14777+
14778 "jz 1f\n"
14779 "call __write_lock_failed\n\t"
14780 "1:\n"
14781@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
14782
14783 static inline void arch_read_unlock(arch_rwlock_t *rw)
14784 {
14785- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
14786+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
14787+
14788+#ifdef CONFIG_PAX_REFCOUNT
14789+ "jno 0f\n"
14790+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
14791+ "int $4\n0:\n"
14792+ _ASM_EXTABLE(0b, 0b)
14793+#endif
14794+
14795 :"+m" (rw->lock) : : "memory");
14796 }
14797
14798 static inline void arch_write_unlock(arch_rwlock_t *rw)
14799 {
14800- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
14801+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
14802+
14803+#ifdef CONFIG_PAX_REFCOUNT
14804+ "jno 0f\n"
14805+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
14806+ "int $4\n0:\n"
14807+ _ASM_EXTABLE(0b, 0b)
14808+#endif
14809+
14810 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
14811 }
14812
14813diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
14814index 6a99859..03cb807 100644
14815--- a/arch/x86/include/asm/stackprotector.h
14816+++ b/arch/x86/include/asm/stackprotector.h
14817@@ -47,7 +47,7 @@
14818 * head_32 for boot CPU and setup_per_cpu_areas() for others.
14819 */
14820 #define GDT_STACK_CANARY_INIT \
14821- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
14822+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
14823
14824 /*
14825 * Initialize the stackprotector canary value.
14826@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
14827
14828 static inline void load_stack_canary_segment(void)
14829 {
14830-#ifdef CONFIG_X86_32
14831+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
14832 asm volatile ("mov %0, %%gs" : : "r" (0));
14833 #endif
14834 }
14835diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
14836index 70bbe39..4ae2bd4 100644
14837--- a/arch/x86/include/asm/stacktrace.h
14838+++ b/arch/x86/include/asm/stacktrace.h
14839@@ -11,28 +11,20 @@
14840
14841 extern int kstack_depth_to_print;
14842
14843-struct thread_info;
14844+struct task_struct;
14845 struct stacktrace_ops;
14846
14847-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
14848- unsigned long *stack,
14849- unsigned long bp,
14850- const struct stacktrace_ops *ops,
14851- void *data,
14852- unsigned long *end,
14853- int *graph);
14854+typedef unsigned long walk_stack_t(struct task_struct *task,
14855+ void *stack_start,
14856+ unsigned long *stack,
14857+ unsigned long bp,
14858+ const struct stacktrace_ops *ops,
14859+ void *data,
14860+ unsigned long *end,
14861+ int *graph);
14862
14863-extern unsigned long
14864-print_context_stack(struct thread_info *tinfo,
14865- unsigned long *stack, unsigned long bp,
14866- const struct stacktrace_ops *ops, void *data,
14867- unsigned long *end, int *graph);
14868-
14869-extern unsigned long
14870-print_context_stack_bp(struct thread_info *tinfo,
14871- unsigned long *stack, unsigned long bp,
14872- const struct stacktrace_ops *ops, void *data,
14873- unsigned long *end, int *graph);
14874+extern walk_stack_t print_context_stack;
14875+extern walk_stack_t print_context_stack_bp;
14876
14877 /* Generic stack tracer with callbacks */
14878
14879@@ -40,7 +32,7 @@ struct stacktrace_ops {
14880 void (*address)(void *data, unsigned long address, int reliable);
14881 /* On negative return stop dumping */
14882 int (*stack)(void *data, char *name);
14883- walk_stack_t walk_stack;
14884+ walk_stack_t *walk_stack;
14885 };
14886
14887 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
14888diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
14889index 4ec45b3..a4f0a8a 100644
14890--- a/arch/x86/include/asm/switch_to.h
14891+++ b/arch/x86/include/asm/switch_to.h
14892@@ -108,7 +108,7 @@ do { \
14893 "call __switch_to\n\t" \
14894 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
14895 __switch_canary \
14896- "movq %P[thread_info](%%rsi),%%r8\n\t" \
14897+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
14898 "movq %%rax,%%rdi\n\t" \
14899 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
14900 "jnz ret_from_fork\n\t" \
14901@@ -119,7 +119,7 @@ do { \
14902 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
14903 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
14904 [_tif_fork] "i" (_TIF_FORK), \
14905- [thread_info] "i" (offsetof(struct task_struct, stack)), \
14906+ [thread_info] "m" (current_tinfo), \
14907 [current_task] "m" (current_task) \
14908 __switch_canary_iparam \
14909 : "memory", "cc" __EXTRA_CLOBBER)
14910diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
14911index 2d946e6..e453ec4 100644
14912--- a/arch/x86/include/asm/thread_info.h
14913+++ b/arch/x86/include/asm/thread_info.h
14914@@ -10,6 +10,7 @@
14915 #include <linux/compiler.h>
14916 #include <asm/page.h>
14917 #include <asm/types.h>
14918+#include <asm/percpu.h>
14919
14920 /*
14921 * low level task data that entry.S needs immediate access to
14922@@ -24,7 +25,6 @@ struct exec_domain;
14923 #include <linux/atomic.h>
14924
14925 struct thread_info {
14926- struct task_struct *task; /* main task structure */
14927 struct exec_domain *exec_domain; /* execution domain */
14928 __u32 flags; /* low level flags */
14929 __u32 status; /* thread synchronous flags */
14930@@ -34,19 +34,13 @@ struct thread_info {
14931 mm_segment_t addr_limit;
14932 struct restart_block restart_block;
14933 void __user *sysenter_return;
14934-#ifdef CONFIG_X86_32
14935- unsigned long previous_esp; /* ESP of the previous stack in
14936- case of nested (IRQ) stacks
14937- */
14938- __u8 supervisor_stack[0];
14939-#endif
14940+ unsigned long lowest_stack;
14941 unsigned int sig_on_uaccess_error:1;
14942 unsigned int uaccess_err:1; /* uaccess failed */
14943 };
14944
14945-#define INIT_THREAD_INFO(tsk) \
14946+#define INIT_THREAD_INFO \
14947 { \
14948- .task = &tsk, \
14949 .exec_domain = &default_exec_domain, \
14950 .flags = 0, \
14951 .cpu = 0, \
14952@@ -57,7 +51,7 @@ struct thread_info {
14953 }, \
14954 }
14955
14956-#define init_thread_info (init_thread_union.thread_info)
14957+#define init_thread_info (init_thread_union.stack)
14958 #define init_stack (init_thread_union.stack)
14959
14960 #else /* !__ASSEMBLY__ */
14961@@ -98,6 +92,7 @@ struct thread_info {
14962 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
14963 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
14964 #define TIF_X32 30 /* 32-bit native x86-64 binary */
14965+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
14966
14967 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
14968 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
14969@@ -122,17 +117,18 @@ struct thread_info {
14970 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
14971 #define _TIF_ADDR32 (1 << TIF_ADDR32)
14972 #define _TIF_X32 (1 << TIF_X32)
14973+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
14974
14975 /* work to do in syscall_trace_enter() */
14976 #define _TIF_WORK_SYSCALL_ENTRY \
14977 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
14978 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
14979- _TIF_NOHZ)
14980+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
14981
14982 /* work to do in syscall_trace_leave() */
14983 #define _TIF_WORK_SYSCALL_EXIT \
14984 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
14985- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
14986+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
14987
14988 /* work to do on interrupt/exception return */
14989 #define _TIF_WORK_MASK \
14990@@ -143,7 +139,7 @@ struct thread_info {
14991 /* work to do on any return to user space */
14992 #define _TIF_ALLWORK_MASK \
14993 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
14994- _TIF_NOHZ)
14995+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
14996
14997 /* Only used for 64 bit */
14998 #define _TIF_DO_NOTIFY_MASK \
14999@@ -159,45 +155,40 @@ struct thread_info {
15000
15001 #define PREEMPT_ACTIVE 0x10000000
15002
15003-#ifdef CONFIG_X86_32
15004-
15005-#define STACK_WARN (THREAD_SIZE/8)
15006-/*
15007- * macros/functions for gaining access to the thread information structure
15008- *
15009- * preempt_count needs to be 1 initially, until the scheduler is functional.
15010- */
15011-#ifndef __ASSEMBLY__
15012-
15013-
15014-/* how to get the current stack pointer from C */
15015-register unsigned long current_stack_pointer asm("esp") __used;
15016-
15017-/* how to get the thread information struct from C */
15018-static inline struct thread_info *current_thread_info(void)
15019-{
15020- return (struct thread_info *)
15021- (current_stack_pointer & ~(THREAD_SIZE - 1));
15022-}
15023-
15024-#else /* !__ASSEMBLY__ */
15025-
15026+#ifdef __ASSEMBLY__
15027 /* how to get the thread information struct from ASM */
15028 #define GET_THREAD_INFO(reg) \
15029- movl $-THREAD_SIZE, reg; \
15030- andl %esp, reg
15031+ mov PER_CPU_VAR(current_tinfo), reg
15032
15033 /* use this one if reg already contains %esp */
15034-#define GET_THREAD_INFO_WITH_ESP(reg) \
15035- andl $-THREAD_SIZE, reg
15036+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
15037+#else
15038+/* how to get the thread information struct from C */
15039+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
15040+
15041+static __always_inline struct thread_info *current_thread_info(void)
15042+{
15043+ return this_cpu_read_stable(current_tinfo);
15044+}
15045+#endif
15046+
15047+#ifdef CONFIG_X86_32
15048+
15049+#define STACK_WARN (THREAD_SIZE/8)
15050+/*
15051+ * macros/functions for gaining access to the thread information structure
15052+ *
15053+ * preempt_count needs to be 1 initially, until the scheduler is functional.
15054+ */
15055+#ifndef __ASSEMBLY__
15056+
15057+/* how to get the current stack pointer from C */
15058+register unsigned long current_stack_pointer asm("esp") __used;
15059
15060 #endif
15061
15062 #else /* X86_32 */
15063
15064-#include <asm/percpu.h>
15065-#define KERNEL_STACK_OFFSET (5*8)
15066-
15067 /*
15068 * macros/functions for gaining access to the thread information structure
15069 * preempt_count needs to be 1 initially, until the scheduler is functional.
15070@@ -205,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
15071 #ifndef __ASSEMBLY__
15072 DECLARE_PER_CPU(unsigned long, kernel_stack);
15073
15074-static inline struct thread_info *current_thread_info(void)
15075-{
15076- struct thread_info *ti;
15077- ti = (void *)(this_cpu_read_stable(kernel_stack) +
15078- KERNEL_STACK_OFFSET - THREAD_SIZE);
15079- return ti;
15080-}
15081-
15082-#else /* !__ASSEMBLY__ */
15083-
15084-/* how to get the thread information struct from ASM */
15085-#define GET_THREAD_INFO(reg) \
15086- movq PER_CPU_VAR(kernel_stack),reg ; \
15087- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
15088-
15089-/*
15090- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
15091- * a certain register (to be used in assembler memory operands).
15092- */
15093-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
15094-
15095+/* how to get the current stack pointer from C */
15096+register unsigned long current_stack_pointer asm("rsp") __used;
15097 #endif
15098
15099 #endif /* !X86_32 */
15100@@ -286,5 +258,12 @@ static inline bool is_ia32_task(void)
15101 extern void arch_task_cache_init(void);
15102 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
15103 extern void arch_release_task_struct(struct task_struct *tsk);
15104+
15105+#define __HAVE_THREAD_FUNCTIONS
15106+#define task_thread_info(task) (&(task)->tinfo)
15107+#define task_stack_page(task) ((task)->stack)
15108+#define setup_thread_stack(p, org) do {} while (0)
15109+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
15110+
15111 #endif
15112 #endif /* _ASM_X86_THREAD_INFO_H */
15113diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
15114index 1709801..0a60f2f 100644
15115--- a/arch/x86/include/asm/uaccess.h
15116+++ b/arch/x86/include/asm/uaccess.h
15117@@ -7,6 +7,7 @@
15118 #include <linux/compiler.h>
15119 #include <linux/thread_info.h>
15120 #include <linux/string.h>
15121+#include <linux/sched.h>
15122 #include <asm/asm.h>
15123 #include <asm/page.h>
15124 #include <asm/smap.h>
15125@@ -29,7 +30,12 @@
15126
15127 #define get_ds() (KERNEL_DS)
15128 #define get_fs() (current_thread_info()->addr_limit)
15129+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15130+void __set_fs(mm_segment_t x);
15131+void set_fs(mm_segment_t x);
15132+#else
15133 #define set_fs(x) (current_thread_info()->addr_limit = (x))
15134+#endif
15135
15136 #define segment_eq(a, b) ((a).seg == (b).seg)
15137
15138@@ -77,8 +83,33 @@
15139 * checks that the pointer is in the user space range - after calling
15140 * this function, memory access functions may still return -EFAULT.
15141 */
15142-#define access_ok(type, addr, size) \
15143- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15144+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15145+#define access_ok(type, addr, size) \
15146+({ \
15147+ long __size = size; \
15148+ unsigned long __addr = (unsigned long)addr; \
15149+ unsigned long __addr_ao = __addr & PAGE_MASK; \
15150+ unsigned long __end_ao = __addr + __size - 1; \
15151+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
15152+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
15153+ while(__addr_ao <= __end_ao) { \
15154+ char __c_ao; \
15155+ __addr_ao += PAGE_SIZE; \
15156+ if (__size > PAGE_SIZE) \
15157+ cond_resched(); \
15158+ if (__get_user(__c_ao, (char __user *)__addr)) \
15159+ break; \
15160+ if (type != VERIFY_WRITE) { \
15161+ __addr = __addr_ao; \
15162+ continue; \
15163+ } \
15164+ if (__put_user(__c_ao, (char __user *)__addr)) \
15165+ break; \
15166+ __addr = __addr_ao; \
15167+ } \
15168+ } \
15169+ __ret_ao; \
15170+})
15171
15172 /*
15173 * The exception table consists of pairs of addresses relative to the
15174@@ -189,13 +220,21 @@ extern int __get_user_bad(void);
15175 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
15176 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
15177
15178-
15179+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15180+#define __copyuser_seg "gs;"
15181+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
15182+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
15183+#else
15184+#define __copyuser_seg
15185+#define __COPYUSER_SET_ES
15186+#define __COPYUSER_RESTORE_ES
15187+#endif
15188
15189 #ifdef CONFIG_X86_32
15190 #define __put_user_asm_u64(x, addr, err, errret) \
15191 asm volatile(ASM_STAC "\n" \
15192- "1: movl %%eax,0(%2)\n" \
15193- "2: movl %%edx,4(%2)\n" \
15194+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
15195+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
15196 "3: " ASM_CLAC "\n" \
15197 ".section .fixup,\"ax\"\n" \
15198 "4: movl %3,%0\n" \
15199@@ -208,8 +247,8 @@ extern int __get_user_bad(void);
15200
15201 #define __put_user_asm_ex_u64(x, addr) \
15202 asm volatile(ASM_STAC "\n" \
15203- "1: movl %%eax,0(%1)\n" \
15204- "2: movl %%edx,4(%1)\n" \
15205+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
15206+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
15207 "3: " ASM_CLAC "\n" \
15208 _ASM_EXTABLE_EX(1b, 2b) \
15209 _ASM_EXTABLE_EX(2b, 3b) \
15210@@ -259,7 +298,7 @@ extern void __put_user_8(void);
15211 __typeof__(*(ptr)) __pu_val; \
15212 __chk_user_ptr(ptr); \
15213 might_fault(); \
15214- __pu_val = x; \
15215+ __pu_val = (x); \
15216 switch (sizeof(*(ptr))) { \
15217 case 1: \
15218 __put_user_x(1, __pu_val, ptr, __ret_pu); \
15219@@ -358,7 +397,7 @@ do { \
15220
15221 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15222 asm volatile(ASM_STAC "\n" \
15223- "1: mov"itype" %2,%"rtype"1\n" \
15224+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
15225 "2: " ASM_CLAC "\n" \
15226 ".section .fixup,\"ax\"\n" \
15227 "3: mov %3,%0\n" \
15228@@ -366,7 +405,7 @@ do { \
15229 " jmp 2b\n" \
15230 ".previous\n" \
15231 _ASM_EXTABLE(1b, 3b) \
15232- : "=r" (err), ltype(x) \
15233+ : "=r" (err), ltype (x) \
15234 : "m" (__m(addr)), "i" (errret), "0" (err))
15235
15236 #define __get_user_size_ex(x, ptr, size) \
15237@@ -391,7 +430,7 @@ do { \
15238 } while (0)
15239
15240 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
15241- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
15242+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
15243 "2:\n" \
15244 _ASM_EXTABLE_EX(1b, 2b) \
15245 : ltype(x) : "m" (__m(addr)))
15246@@ -408,13 +447,24 @@ do { \
15247 int __gu_err; \
15248 unsigned long __gu_val; \
15249 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
15250- (x) = (__force __typeof__(*(ptr)))__gu_val; \
15251+ (x) = (__typeof__(*(ptr)))__gu_val; \
15252 __gu_err; \
15253 })
15254
15255 /* FIXME: this hack is definitely wrong -AK */
15256 struct __large_struct { unsigned long buf[100]; };
15257-#define __m(x) (*(struct __large_struct __user *)(x))
15258+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15259+#define ____m(x) \
15260+({ \
15261+ unsigned long ____x = (unsigned long)(x); \
15262+ if (____x < PAX_USER_SHADOW_BASE) \
15263+ ____x += PAX_USER_SHADOW_BASE; \
15264+ (void __user *)____x; \
15265+})
15266+#else
15267+#define ____m(x) (x)
15268+#endif
15269+#define __m(x) (*(struct __large_struct __user *)____m(x))
15270
15271 /*
15272 * Tell gcc we read from memory instead of writing: this is because
15273@@ -423,7 +473,7 @@ struct __large_struct { unsigned long buf[100]; };
15274 */
15275 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15276 asm volatile(ASM_STAC "\n" \
15277- "1: mov"itype" %"rtype"1,%2\n" \
15278+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
15279 "2: " ASM_CLAC "\n" \
15280 ".section .fixup,\"ax\"\n" \
15281 "3: mov %3,%0\n" \
15282@@ -431,10 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
15283 ".previous\n" \
15284 _ASM_EXTABLE(1b, 3b) \
15285 : "=r"(err) \
15286- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
15287+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
15288
15289 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
15290- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
15291+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
15292 "2:\n" \
15293 _ASM_EXTABLE_EX(1b, 2b) \
15294 : : ltype(x), "m" (__m(addr)))
15295@@ -473,8 +523,12 @@ struct __large_struct { unsigned long buf[100]; };
15296 * On error, the variable @x is set to zero.
15297 */
15298
15299+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15300+#define __get_user(x, ptr) get_user((x), (ptr))
15301+#else
15302 #define __get_user(x, ptr) \
15303 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
15304+#endif
15305
15306 /**
15307 * __put_user: - Write a simple value into user space, with less checking.
15308@@ -496,8 +550,12 @@ struct __large_struct { unsigned long buf[100]; };
15309 * Returns zero on success, or -EFAULT on error.
15310 */
15311
15312+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15313+#define __put_user(x, ptr) put_user((x), (ptr))
15314+#else
15315 #define __put_user(x, ptr) \
15316 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
15317+#endif
15318
15319 #define __get_user_unaligned __get_user
15320 #define __put_user_unaligned __put_user
15321@@ -515,7 +573,7 @@ struct __large_struct { unsigned long buf[100]; };
15322 #define get_user_ex(x, ptr) do { \
15323 unsigned long __gue_val; \
15324 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
15325- (x) = (__force __typeof__(*(ptr)))__gue_val; \
15326+ (x) = (__typeof__(*(ptr)))__gue_val; \
15327 } while (0)
15328
15329 #define put_user_try uaccess_try
15330@@ -532,8 +590,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
15331 extern __must_check long strlen_user(const char __user *str);
15332 extern __must_check long strnlen_user(const char __user *str, long n);
15333
15334-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
15335-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
15336+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15337+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15338
15339 /*
15340 * movsl can be slow when source and dest are not both 8-byte aligned
15341diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
15342index 7f760a9..04b1c65 100644
15343--- a/arch/x86/include/asm/uaccess_32.h
15344+++ b/arch/x86/include/asm/uaccess_32.h
15345@@ -11,15 +11,15 @@
15346 #include <asm/page.h>
15347
15348 unsigned long __must_check __copy_to_user_ll
15349- (void __user *to, const void *from, unsigned long n);
15350+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
15351 unsigned long __must_check __copy_from_user_ll
15352- (void *to, const void __user *from, unsigned long n);
15353+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15354 unsigned long __must_check __copy_from_user_ll_nozero
15355- (void *to, const void __user *from, unsigned long n);
15356+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15357 unsigned long __must_check __copy_from_user_ll_nocache
15358- (void *to, const void __user *from, unsigned long n);
15359+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15360 unsigned long __must_check __copy_from_user_ll_nocache_nozero
15361- (void *to, const void __user *from, unsigned long n);
15362+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15363
15364 /**
15365 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
15366@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
15367 static __always_inline unsigned long __must_check
15368 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
15369 {
15370+ if ((long)n < 0)
15371+ return n;
15372+
15373+ check_object_size(from, n, true);
15374+
15375 if (__builtin_constant_p(n)) {
15376 unsigned long ret;
15377
15378@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
15379 __copy_to_user(void __user *to, const void *from, unsigned long n)
15380 {
15381 might_fault();
15382+
15383 return __copy_to_user_inatomic(to, from, n);
15384 }
15385
15386 static __always_inline unsigned long
15387 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
15388 {
15389+ if ((long)n < 0)
15390+ return n;
15391+
15392 /* Avoid zeroing the tail if the copy fails..
15393 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
15394 * but as the zeroing behaviour is only significant when n is not
15395@@ -137,6 +146,12 @@ static __always_inline unsigned long
15396 __copy_from_user(void *to, const void __user *from, unsigned long n)
15397 {
15398 might_fault();
15399+
15400+ if ((long)n < 0)
15401+ return n;
15402+
15403+ check_object_size(to, n, false);
15404+
15405 if (__builtin_constant_p(n)) {
15406 unsigned long ret;
15407
15408@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
15409 const void __user *from, unsigned long n)
15410 {
15411 might_fault();
15412+
15413+ if ((long)n < 0)
15414+ return n;
15415+
15416 if (__builtin_constant_p(n)) {
15417 unsigned long ret;
15418
15419@@ -181,15 +200,19 @@ static __always_inline unsigned long
15420 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
15421 unsigned long n)
15422 {
15423- return __copy_from_user_ll_nocache_nozero(to, from, n);
15424+ if ((long)n < 0)
15425+ return n;
15426+
15427+ return __copy_from_user_ll_nocache_nozero(to, from, n);
15428 }
15429
15430-unsigned long __must_check copy_to_user(void __user *to,
15431- const void *from, unsigned long n);
15432-unsigned long __must_check _copy_from_user(void *to,
15433- const void __user *from,
15434- unsigned long n);
15435-
15436+extern void copy_to_user_overflow(void)
15437+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15438+ __compiletime_error("copy_to_user() buffer size is not provably correct")
15439+#else
15440+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
15441+#endif
15442+;
15443
15444 extern void copy_from_user_overflow(void)
15445 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15446@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
15447 #endif
15448 ;
15449
15450-static inline unsigned long __must_check copy_from_user(void *to,
15451- const void __user *from,
15452- unsigned long n)
15453+/**
15454+ * copy_to_user: - Copy a block of data into user space.
15455+ * @to: Destination address, in user space.
15456+ * @from: Source address, in kernel space.
15457+ * @n: Number of bytes to copy.
15458+ *
15459+ * Context: User context only. This function may sleep.
15460+ *
15461+ * Copy data from kernel space to user space.
15462+ *
15463+ * Returns number of bytes that could not be copied.
15464+ * On success, this will be zero.
15465+ */
15466+static inline unsigned long __must_check
15467+copy_to_user(void __user *to, const void *from, unsigned long n)
15468 {
15469- int sz = __compiletime_object_size(to);
15470+ size_t sz = __compiletime_object_size(from);
15471
15472- if (likely(sz == -1 || sz >= n))
15473- n = _copy_from_user(to, from, n);
15474- else
15475+ if (unlikely(sz != (size_t)-1 && sz < n))
15476+ copy_to_user_overflow();
15477+ else if (access_ok(VERIFY_WRITE, to, n))
15478+ n = __copy_to_user(to, from, n);
15479+ return n;
15480+}
15481+
15482+/**
15483+ * copy_from_user: - Copy a block of data from user space.
15484+ * @to: Destination address, in kernel space.
15485+ * @from: Source address, in user space.
15486+ * @n: Number of bytes to copy.
15487+ *
15488+ * Context: User context only. This function may sleep.
15489+ *
15490+ * Copy data from user space to kernel space.
15491+ *
15492+ * Returns number of bytes that could not be copied.
15493+ * On success, this will be zero.
15494+ *
15495+ * If some data could not be copied, this function will pad the copied
15496+ * data to the requested size using zero bytes.
15497+ */
15498+static inline unsigned long __must_check
15499+copy_from_user(void *to, const void __user *from, unsigned long n)
15500+{
15501+ size_t sz = __compiletime_object_size(to);
15502+
15503+ check_object_size(to, n, false);
15504+
15505+ if (unlikely(sz != (size_t)-1 && sz < n))
15506 copy_from_user_overflow();
15507-
15508+ else if (access_ok(VERIFY_READ, from, n))
15509+ n = __copy_from_user(to, from, n);
15510+ else if ((long)n > 0)
15511+ memset(to, 0, n);
15512 return n;
15513 }
15514
15515diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
15516index 142810c..747941a 100644
15517--- a/arch/x86/include/asm/uaccess_64.h
15518+++ b/arch/x86/include/asm/uaccess_64.h
15519@@ -10,6 +10,9 @@
15520 #include <asm/alternative.h>
15521 #include <asm/cpufeature.h>
15522 #include <asm/page.h>
15523+#include <asm/pgtable.h>
15524+
15525+#define set_fs(x) (current_thread_info()->addr_limit = (x))
15526
15527 /*
15528 * Copy To/From Userspace
15529@@ -17,13 +20,13 @@
15530
15531 /* Handles exceptions in both to and from, but doesn't do access_ok */
15532 __must_check unsigned long
15533-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
15534+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
15535 __must_check unsigned long
15536-copy_user_generic_string(void *to, const void *from, unsigned len);
15537+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
15538 __must_check unsigned long
15539-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
15540+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
15541
15542-static __always_inline __must_check unsigned long
15543+static __always_inline __must_check __size_overflow(3) unsigned long
15544 copy_user_generic(void *to, const void *from, unsigned len)
15545 {
15546 unsigned ret;
15547@@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
15548 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
15549 "=d" (len)),
15550 "1" (to), "2" (from), "3" (len)
15551- : "memory", "rcx", "r8", "r9", "r10", "r11");
15552+ : "memory", "rcx", "r8", "r9", "r11");
15553 return ret;
15554 }
15555
15556+static __always_inline __must_check unsigned long
15557+__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
15558+static __always_inline __must_check unsigned long
15559+__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
15560 __must_check unsigned long
15561-_copy_to_user(void __user *to, const void *from, unsigned len);
15562-__must_check unsigned long
15563-_copy_from_user(void *to, const void __user *from, unsigned len);
15564-__must_check unsigned long
15565-copy_in_user(void __user *to, const void __user *from, unsigned len);
15566+copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
15567+
15568+extern void copy_to_user_overflow(void)
15569+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15570+ __compiletime_error("copy_to_user() buffer size is not provably correct")
15571+#else
15572+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
15573+#endif
15574+;
15575+
15576+extern void copy_from_user_overflow(void)
15577+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15578+ __compiletime_error("copy_from_user() buffer size is not provably correct")
15579+#else
15580+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
15581+#endif
15582+;
15583
15584 static inline unsigned long __must_check copy_from_user(void *to,
15585 const void __user *from,
15586 unsigned long n)
15587 {
15588- int sz = __compiletime_object_size(to);
15589-
15590 might_fault();
15591- if (likely(sz == -1 || sz >= n))
15592- n = _copy_from_user(to, from, n);
15593-#ifdef CONFIG_DEBUG_VM
15594- else
15595- WARN(1, "Buffer overflow detected!\n");
15596-#endif
15597+
15598+ check_object_size(to, n, false);
15599+
15600+ if (access_ok(VERIFY_READ, from, n))
15601+ n = __copy_from_user(to, from, n);
15602+ else if (n < INT_MAX)
15603+ memset(to, 0, n);
15604 return n;
15605 }
15606
15607 static __always_inline __must_check
15608-int copy_to_user(void __user *dst, const void *src, unsigned size)
15609+int copy_to_user(void __user *dst, const void *src, unsigned long size)
15610 {
15611 might_fault();
15612
15613- return _copy_to_user(dst, src, size);
15614+ if (access_ok(VERIFY_WRITE, dst, size))
15615+ size = __copy_to_user(dst, src, size);
15616+ return size;
15617 }
15618
15619 static __always_inline __must_check
15620-int __copy_from_user(void *dst, const void __user *src, unsigned size)
15621+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
15622 {
15623- int ret = 0;
15624+ size_t sz = __compiletime_object_size(dst);
15625+ unsigned ret = 0;
15626
15627 might_fault();
15628+
15629+ if (size > INT_MAX)
15630+ return size;
15631+
15632+ check_object_size(dst, size, false);
15633+
15634+#ifdef CONFIG_PAX_MEMORY_UDEREF
15635+ if (!__access_ok(VERIFY_READ, src, size))
15636+ return size;
15637+#endif
15638+
15639+ if (unlikely(sz != (size_t)-1 && sz < size)) {
15640+ copy_from_user_overflow();
15641+ return size;
15642+ }
15643+
15644 if (!__builtin_constant_p(size))
15645- return copy_user_generic(dst, (__force void *)src, size);
15646+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
15647 switch (size) {
15648- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
15649+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
15650 ret, "b", "b", "=q", 1);
15651 return ret;
15652- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
15653+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
15654 ret, "w", "w", "=r", 2);
15655 return ret;
15656- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
15657+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
15658 ret, "l", "k", "=r", 4);
15659 return ret;
15660- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
15661+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
15662 ret, "q", "", "=r", 8);
15663 return ret;
15664 case 10:
15665- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
15666+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
15667 ret, "q", "", "=r", 10);
15668 if (unlikely(ret))
15669 return ret;
15670 __get_user_asm(*(u16 *)(8 + (char *)dst),
15671- (u16 __user *)(8 + (char __user *)src),
15672+ (const u16 __user *)(8 + (const char __user *)src),
15673 ret, "w", "w", "=r", 2);
15674 return ret;
15675 case 16:
15676- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
15677+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
15678 ret, "q", "", "=r", 16);
15679 if (unlikely(ret))
15680 return ret;
15681 __get_user_asm(*(u64 *)(8 + (char *)dst),
15682- (u64 __user *)(8 + (char __user *)src),
15683+ (const u64 __user *)(8 + (const char __user *)src),
15684 ret, "q", "", "=r", 8);
15685 return ret;
15686 default:
15687- return copy_user_generic(dst, (__force void *)src, size);
15688+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
15689 }
15690 }
15691
15692 static __always_inline __must_check
15693-int __copy_to_user(void __user *dst, const void *src, unsigned size)
15694+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
15695 {
15696- int ret = 0;
15697+ size_t sz = __compiletime_object_size(src);
15698+ unsigned ret = 0;
15699
15700 might_fault();
15701+
15702+ if (size > INT_MAX)
15703+ return size;
15704+
15705+ check_object_size(src, size, true);
15706+
15707+#ifdef CONFIG_PAX_MEMORY_UDEREF
15708+ if (!__access_ok(VERIFY_WRITE, dst, size))
15709+ return size;
15710+#endif
15711+
15712+ if (unlikely(sz != (size_t)-1 && sz < size)) {
15713+ copy_to_user_overflow();
15714+ return size;
15715+ }
15716+
15717 if (!__builtin_constant_p(size))
15718- return copy_user_generic((__force void *)dst, src, size);
15719+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
15720 switch (size) {
15721- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
15722+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
15723 ret, "b", "b", "iq", 1);
15724 return ret;
15725- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
15726+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
15727 ret, "w", "w", "ir", 2);
15728 return ret;
15729- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
15730+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
15731 ret, "l", "k", "ir", 4);
15732 return ret;
15733- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
15734+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
15735 ret, "q", "", "er", 8);
15736 return ret;
15737 case 10:
15738- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
15739+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
15740 ret, "q", "", "er", 10);
15741 if (unlikely(ret))
15742 return ret;
15743 asm("":::"memory");
15744- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
15745+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
15746 ret, "w", "w", "ir", 2);
15747 return ret;
15748 case 16:
15749- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
15750+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
15751 ret, "q", "", "er", 16);
15752 if (unlikely(ret))
15753 return ret;
15754 asm("":::"memory");
15755- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
15756+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
15757 ret, "q", "", "er", 8);
15758 return ret;
15759 default:
15760- return copy_user_generic((__force void *)dst, src, size);
15761+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
15762 }
15763 }
15764
15765 static __always_inline __must_check
15766-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15767+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
15768 {
15769- int ret = 0;
15770+ unsigned ret = 0;
15771
15772 might_fault();
15773+
15774+ if (size > INT_MAX)
15775+ return size;
15776+
15777+#ifdef CONFIG_PAX_MEMORY_UDEREF
15778+ if (!__access_ok(VERIFY_READ, src, size))
15779+ return size;
15780+ if (!__access_ok(VERIFY_WRITE, dst, size))
15781+ return size;
15782+#endif
15783+
15784 if (!__builtin_constant_p(size))
15785- return copy_user_generic((__force void *)dst,
15786- (__force void *)src, size);
15787+ return copy_user_generic((__force_kernel void *)____m(dst),
15788+ (__force_kernel const void *)____m(src), size);
15789 switch (size) {
15790 case 1: {
15791 u8 tmp;
15792- __get_user_asm(tmp, (u8 __user *)src,
15793+ __get_user_asm(tmp, (const u8 __user *)src,
15794 ret, "b", "b", "=q", 1);
15795 if (likely(!ret))
15796 __put_user_asm(tmp, (u8 __user *)dst,
15797@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15798 }
15799 case 2: {
15800 u16 tmp;
15801- __get_user_asm(tmp, (u16 __user *)src,
15802+ __get_user_asm(tmp, (const u16 __user *)src,
15803 ret, "w", "w", "=r", 2);
15804 if (likely(!ret))
15805 __put_user_asm(tmp, (u16 __user *)dst,
15806@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15807
15808 case 4: {
15809 u32 tmp;
15810- __get_user_asm(tmp, (u32 __user *)src,
15811+ __get_user_asm(tmp, (const u32 __user *)src,
15812 ret, "l", "k", "=r", 4);
15813 if (likely(!ret))
15814 __put_user_asm(tmp, (u32 __user *)dst,
15815@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15816 }
15817 case 8: {
15818 u64 tmp;
15819- __get_user_asm(tmp, (u64 __user *)src,
15820+ __get_user_asm(tmp, (const u64 __user *)src,
15821 ret, "q", "", "=r", 8);
15822 if (likely(!ret))
15823 __put_user_asm(tmp, (u64 __user *)dst,
15824@@ -212,41 +277,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15825 return ret;
15826 }
15827 default:
15828- return copy_user_generic((__force void *)dst,
15829- (__force void *)src, size);
15830+ return copy_user_generic((__force_kernel void *)____m(dst),
15831+ (__force_kernel const void *)____m(src), size);
15832 }
15833 }
15834
15835 static __must_check __always_inline int
15836-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
15837+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
15838 {
15839- return copy_user_generic(dst, (__force const void *)src, size);
15840+ if (size > INT_MAX)
15841+ return size;
15842+
15843+#ifdef CONFIG_PAX_MEMORY_UDEREF
15844+ if (!__access_ok(VERIFY_READ, src, size))
15845+ return size;
15846+#endif
15847+
15848+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
15849 }
15850
15851-static __must_check __always_inline int
15852-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
15853+static __must_check __always_inline unsigned long
15854+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
15855 {
15856- return copy_user_generic((__force void *)dst, src, size);
15857+ if (size > INT_MAX)
15858+ return size;
15859+
15860+#ifdef CONFIG_PAX_MEMORY_UDEREF
15861+ if (!__access_ok(VERIFY_WRITE, dst, size))
15862+ return size;
15863+#endif
15864+
15865+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
15866 }
15867
15868-extern long __copy_user_nocache(void *dst, const void __user *src,
15869- unsigned size, int zerorest);
15870+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
15871+ unsigned long size, int zerorest) __size_overflow(3);
15872
15873-static inline int
15874-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
15875+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
15876 {
15877 might_sleep();
15878+
15879+ if (size > INT_MAX)
15880+ return size;
15881+
15882+#ifdef CONFIG_PAX_MEMORY_UDEREF
15883+ if (!__access_ok(VERIFY_READ, src, size))
15884+ return size;
15885+#endif
15886+
15887 return __copy_user_nocache(dst, src, size, 1);
15888 }
15889
15890-static inline int
15891-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
15892- unsigned size)
15893+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
15894+ unsigned long size)
15895 {
15896+ if (size > INT_MAX)
15897+ return size;
15898+
15899+#ifdef CONFIG_PAX_MEMORY_UDEREF
15900+ if (!__access_ok(VERIFY_READ, src, size))
15901+ return size;
15902+#endif
15903+
15904 return __copy_user_nocache(dst, src, size, 0);
15905 }
15906
15907-unsigned long
15908-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
15909+extern unsigned long
15910+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
15911
15912 #endif /* _ASM_X86_UACCESS_64_H */
15913diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
15914index 5b238981..77fdd78 100644
15915--- a/arch/x86/include/asm/word-at-a-time.h
15916+++ b/arch/x86/include/asm/word-at-a-time.h
15917@@ -11,7 +11,7 @@
15918 * and shift, for example.
15919 */
15920 struct word_at_a_time {
15921- const unsigned long one_bits, high_bits;
15922+ unsigned long one_bits, high_bits;
15923 };
15924
15925 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
15926diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
15927index 5769349..a3d3e2a 100644
15928--- a/arch/x86/include/asm/x86_init.h
15929+++ b/arch/x86/include/asm/x86_init.h
15930@@ -141,7 +141,7 @@ struct x86_init_ops {
15931 struct x86_init_timers timers;
15932 struct x86_init_iommu iommu;
15933 struct x86_init_pci pci;
15934-};
15935+} __no_const;
15936
15937 /**
15938 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
15939@@ -152,7 +152,7 @@ struct x86_cpuinit_ops {
15940 void (*setup_percpu_clockev)(void);
15941 void (*early_percpu_clock_init)(void);
15942 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
15943-};
15944+} __no_const;
15945
15946 /**
15947 * struct x86_platform_ops - platform specific runtime functions
15948@@ -178,7 +178,7 @@ struct x86_platform_ops {
15949 void (*save_sched_clock_state)(void);
15950 void (*restore_sched_clock_state)(void);
15951 void (*apic_post_init)(void);
15952-};
15953+} __no_const;
15954
15955 struct pci_dev;
15956
15957@@ -187,14 +187,14 @@ struct x86_msi_ops {
15958 void (*teardown_msi_irq)(unsigned int irq);
15959 void (*teardown_msi_irqs)(struct pci_dev *dev);
15960 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
15961-};
15962+} __no_const;
15963
15964 struct x86_io_apic_ops {
15965 void (*init) (void);
15966 unsigned int (*read) (unsigned int apic, unsigned int reg);
15967 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
15968 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
15969-};
15970+} __no_const;
15971
15972 extern struct x86_init_ops x86_init;
15973 extern struct x86_cpuinit_ops x86_cpuinit;
15974diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
15975index 0415cda..b43d877 100644
15976--- a/arch/x86/include/asm/xsave.h
15977+++ b/arch/x86/include/asm/xsave.h
15978@@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
15979 return -EFAULT;
15980
15981 __asm__ __volatile__(ASM_STAC "\n"
15982- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
15983+ "1:"
15984+ __copyuser_seg
15985+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
15986 "2: " ASM_CLAC "\n"
15987 ".section .fixup,\"ax\"\n"
15988 "3: movl $-1,%[err]\n"
15989@@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
15990 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
15991 {
15992 int err;
15993- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
15994+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
15995 u32 lmask = mask;
15996 u32 hmask = mask >> 32;
15997
15998 __asm__ __volatile__(ASM_STAC "\n"
15999- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16000+ "1:"
16001+ __copyuser_seg
16002+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16003 "2: " ASM_CLAC "\n"
16004 ".section .fixup,\"ax\"\n"
16005 "3: movl $-1,%[err]\n"
16006diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
16007index bbae024..e1528f9 100644
16008--- a/arch/x86/include/uapi/asm/e820.h
16009+++ b/arch/x86/include/uapi/asm/e820.h
16010@@ -63,7 +63,7 @@ struct e820map {
16011 #define ISA_START_ADDRESS 0xa0000
16012 #define ISA_END_ADDRESS 0x100000
16013
16014-#define BIOS_BEGIN 0x000a0000
16015+#define BIOS_BEGIN 0x000c0000
16016 #define BIOS_END 0x00100000
16017
16018 #define BIOS_ROM_BASE 0xffe00000
16019diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
16020index 34e923a..0c6bb6e 100644
16021--- a/arch/x86/kernel/Makefile
16022+++ b/arch/x86/kernel/Makefile
16023@@ -22,7 +22,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
16024 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
16025 obj-$(CONFIG_IRQ_WORK) += irq_work.o
16026 obj-y += probe_roms.o
16027-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
16028+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
16029 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
16030 obj-y += syscall_$(BITS).o
16031 obj-$(CONFIG_X86_64) += vsyscall_64.o
16032diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
16033index d5e0d71..6533e08 100644
16034--- a/arch/x86/kernel/acpi/sleep.c
16035+++ b/arch/x86/kernel/acpi/sleep.c
16036@@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
16037 #else /* CONFIG_64BIT */
16038 #ifdef CONFIG_SMP
16039 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
16040+
16041+ pax_open_kernel();
16042 early_gdt_descr.address =
16043 (unsigned long)get_cpu_gdt_table(smp_processor_id());
16044+ pax_close_kernel();
16045+
16046 initial_gs = per_cpu_offset(smp_processor_id());
16047 #endif
16048 initial_code = (unsigned long)wakeup_long64;
16049diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
16050index 13ab720..95d5442 100644
16051--- a/arch/x86/kernel/acpi/wakeup_32.S
16052+++ b/arch/x86/kernel/acpi/wakeup_32.S
16053@@ -30,13 +30,11 @@ wakeup_pmode_return:
16054 # and restore the stack ... but you need gdt for this to work
16055 movl saved_context_esp, %esp
16056
16057- movl %cs:saved_magic, %eax
16058- cmpl $0x12345678, %eax
16059+ cmpl $0x12345678, saved_magic
16060 jne bogus_magic
16061
16062 # jump to place where we left off
16063- movl saved_eip, %eax
16064- jmp *%eax
16065+ jmp *(saved_eip)
16066
16067 bogus_magic:
16068 jmp bogus_magic
16069diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
16070index ef5ccca..bd83949 100644
16071--- a/arch/x86/kernel/alternative.c
16072+++ b/arch/x86/kernel/alternative.c
16073@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
16074 */
16075 for (a = start; a < end; a++) {
16076 instr = (u8 *)&a->instr_offset + a->instr_offset;
16077+
16078+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16079+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16080+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
16081+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16082+#endif
16083+
16084 replacement = (u8 *)&a->repl_offset + a->repl_offset;
16085 BUG_ON(a->replacementlen > a->instrlen);
16086 BUG_ON(a->instrlen > sizeof(insnbuf));
16087@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
16088 for (poff = start; poff < end; poff++) {
16089 u8 *ptr = (u8 *)poff + *poff;
16090
16091+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16092+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16093+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16094+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16095+#endif
16096+
16097 if (!*poff || ptr < text || ptr >= text_end)
16098 continue;
16099 /* turn DS segment override prefix into lock prefix */
16100- if (*ptr == 0x3e)
16101+ if (*ktla_ktva(ptr) == 0x3e)
16102 text_poke(ptr, ((unsigned char []){0xf0}), 1);
16103 }
16104 mutex_unlock(&text_mutex);
16105@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
16106 for (poff = start; poff < end; poff++) {
16107 u8 *ptr = (u8 *)poff + *poff;
16108
16109+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16110+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16111+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16112+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16113+#endif
16114+
16115 if (!*poff || ptr < text || ptr >= text_end)
16116 continue;
16117 /* turn lock prefix into DS segment override prefix */
16118- if (*ptr == 0xf0)
16119+ if (*ktla_ktva(ptr) == 0xf0)
16120 text_poke(ptr, ((unsigned char []){0x3E}), 1);
16121 }
16122 mutex_unlock(&text_mutex);
16123@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
16124
16125 BUG_ON(p->len > MAX_PATCH_LEN);
16126 /* prep the buffer with the original instructions */
16127- memcpy(insnbuf, p->instr, p->len);
16128+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
16129 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
16130 (unsigned long)p->instr, p->len);
16131
16132@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
16133 if (!uniproc_patched || num_possible_cpus() == 1)
16134 free_init_pages("SMP alternatives",
16135 (unsigned long)__smp_locks,
16136- (unsigned long)__smp_locks_end);
16137+ PAGE_ALIGN((unsigned long)__smp_locks_end));
16138 #endif
16139
16140 apply_paravirt(__parainstructions, __parainstructions_end);
16141@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
16142 * instructions. And on the local CPU you need to be protected again NMI or MCE
16143 * handlers seeing an inconsistent instruction while you patch.
16144 */
16145-void *__init_or_module text_poke_early(void *addr, const void *opcode,
16146+void *__kprobes text_poke_early(void *addr, const void *opcode,
16147 size_t len)
16148 {
16149 unsigned long flags;
16150 local_irq_save(flags);
16151- memcpy(addr, opcode, len);
16152+
16153+ pax_open_kernel();
16154+ memcpy(ktla_ktva(addr), opcode, len);
16155 sync_core();
16156+ pax_close_kernel();
16157+
16158 local_irq_restore(flags);
16159 /* Could also do a CLFLUSH here to speed up CPU recovery; but
16160 that causes hangs on some VIA CPUs. */
16161@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
16162 */
16163 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
16164 {
16165- unsigned long flags;
16166- char *vaddr;
16167+ unsigned char *vaddr = ktla_ktva(addr);
16168 struct page *pages[2];
16169- int i;
16170+ size_t i;
16171
16172 if (!core_kernel_text((unsigned long)addr)) {
16173- pages[0] = vmalloc_to_page(addr);
16174- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
16175+ pages[0] = vmalloc_to_page(vaddr);
16176+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
16177 } else {
16178- pages[0] = virt_to_page(addr);
16179+ pages[0] = virt_to_page(vaddr);
16180 WARN_ON(!PageReserved(pages[0]));
16181- pages[1] = virt_to_page(addr + PAGE_SIZE);
16182+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
16183 }
16184 BUG_ON(!pages[0]);
16185- local_irq_save(flags);
16186- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
16187- if (pages[1])
16188- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
16189- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
16190- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
16191- clear_fixmap(FIX_TEXT_POKE0);
16192- if (pages[1])
16193- clear_fixmap(FIX_TEXT_POKE1);
16194- local_flush_tlb();
16195- sync_core();
16196- /* Could also do a CLFLUSH here to speed up CPU recovery; but
16197- that causes hangs on some VIA CPUs. */
16198+ text_poke_early(addr, opcode, len);
16199 for (i = 0; i < len; i++)
16200- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
16201- local_irq_restore(flags);
16202+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
16203 return addr;
16204 }
16205
16206diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
16207index b994cc8..812b537 100644
16208--- a/arch/x86/kernel/apic/apic.c
16209+++ b/arch/x86/kernel/apic/apic.c
16210@@ -131,7 +131,7 @@ static int __init parse_lapic(char *arg)
16211 {
16212 if (config_enabled(CONFIG_X86_32) && !arg)
16213 force_enable_local_apic = 1;
16214- else if (!strncmp(arg, "notscdeadline", 13))
16215+ else if (arg && !strncmp(arg, "notscdeadline", 13))
16216 setup_clear_cpu_cap(X86_FEATURE_TSC_DEADLINE_TIMER);
16217 return 0;
16218 }
16219@@ -189,7 +189,7 @@ int first_system_vector = 0xfe;
16220 /*
16221 * Debug level, exported for io_apic.c
16222 */
16223-unsigned int apic_verbosity;
16224+int apic_verbosity;
16225
16226 int pic_mode;
16227
16228@@ -1956,7 +1956,7 @@ void smp_error_interrupt(struct pt_regs *regs)
16229 apic_write(APIC_ESR, 0);
16230 v1 = apic_read(APIC_ESR);
16231 ack_APIC_irq();
16232- atomic_inc(&irq_err_count);
16233+ atomic_inc_unchecked(&irq_err_count);
16234
16235 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
16236 smp_processor_id(), v0 , v1);
16237diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
16238index 00c77cf..2dc6a2d 100644
16239--- a/arch/x86/kernel/apic/apic_flat_64.c
16240+++ b/arch/x86/kernel/apic/apic_flat_64.c
16241@@ -157,7 +157,7 @@ static int flat_probe(void)
16242 return 1;
16243 }
16244
16245-static struct apic apic_flat = {
16246+static struct apic apic_flat __read_only = {
16247 .name = "flat",
16248 .probe = flat_probe,
16249 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
16250@@ -271,7 +271,7 @@ static int physflat_probe(void)
16251 return 0;
16252 }
16253
16254-static struct apic apic_physflat = {
16255+static struct apic apic_physflat __read_only = {
16256
16257 .name = "physical flat",
16258 .probe = physflat_probe,
16259diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
16260index d50e364..543bee3 100644
16261--- a/arch/x86/kernel/apic/bigsmp_32.c
16262+++ b/arch/x86/kernel/apic/bigsmp_32.c
16263@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
16264 return dmi_bigsmp;
16265 }
16266
16267-static struct apic apic_bigsmp = {
16268+static struct apic apic_bigsmp __read_only = {
16269
16270 .name = "bigsmp",
16271 .probe = probe_bigsmp,
16272diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
16273index 0874799..24a836e 100644
16274--- a/arch/x86/kernel/apic/es7000_32.c
16275+++ b/arch/x86/kernel/apic/es7000_32.c
16276@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
16277 return ret && es7000_apic_is_cluster();
16278 }
16279
16280-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
16281-static struct apic __refdata apic_es7000_cluster = {
16282+static struct apic apic_es7000_cluster __read_only = {
16283
16284 .name = "es7000",
16285 .probe = probe_es7000,
16286@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
16287 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
16288 };
16289
16290-static struct apic __refdata apic_es7000 = {
16291+static struct apic __refdata apic_es7000 __read_only = {
16292
16293 .name = "es7000",
16294 .probe = probe_es7000,
16295diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
16296index b739d39..6e4f1db 100644
16297--- a/arch/x86/kernel/apic/io_apic.c
16298+++ b/arch/x86/kernel/apic/io_apic.c
16299@@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
16300 }
16301 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
16302
16303-void lock_vector_lock(void)
16304+void lock_vector_lock(void) __acquires(vector_lock)
16305 {
16306 /* Used to the online set of cpus does not change
16307 * during assign_irq_vector.
16308@@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
16309 raw_spin_lock(&vector_lock);
16310 }
16311
16312-void unlock_vector_lock(void)
16313+void unlock_vector_lock(void) __releases(vector_lock)
16314 {
16315 raw_spin_unlock(&vector_lock);
16316 }
16317@@ -2399,7 +2399,7 @@ static void ack_apic_edge(struct irq_data *data)
16318 ack_APIC_irq();
16319 }
16320
16321-atomic_t irq_mis_count;
16322+atomic_unchecked_t irq_mis_count;
16323
16324 #ifdef CONFIG_GENERIC_PENDING_IRQ
16325 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
16326@@ -2540,7 +2540,7 @@ static void ack_apic_level(struct irq_data *data)
16327 * at the cpu.
16328 */
16329 if (!(v & (1 << (i & 0x1f)))) {
16330- atomic_inc(&irq_mis_count);
16331+ atomic_inc_unchecked(&irq_mis_count);
16332
16333 eoi_ioapic_irq(irq, cfg);
16334 }
16335diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
16336index d661ee9..791fd33 100644
16337--- a/arch/x86/kernel/apic/numaq_32.c
16338+++ b/arch/x86/kernel/apic/numaq_32.c
16339@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
16340 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
16341 }
16342
16343-/* Use __refdata to keep false positive warning calm. */
16344-static struct apic __refdata apic_numaq = {
16345+static struct apic apic_numaq __read_only = {
16346
16347 .name = "NUMAQ",
16348 .probe = probe_numaq,
16349diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
16350index eb35ef9..f184a21 100644
16351--- a/arch/x86/kernel/apic/probe_32.c
16352+++ b/arch/x86/kernel/apic/probe_32.c
16353@@ -72,7 +72,7 @@ static int probe_default(void)
16354 return 1;
16355 }
16356
16357-static struct apic apic_default = {
16358+static struct apic apic_default __read_only = {
16359
16360 .name = "default",
16361 .probe = probe_default,
16362diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
16363index 77c95c0..434f8a4 100644
16364--- a/arch/x86/kernel/apic/summit_32.c
16365+++ b/arch/x86/kernel/apic/summit_32.c
16366@@ -486,7 +486,7 @@ void setup_summit(void)
16367 }
16368 #endif
16369
16370-static struct apic apic_summit = {
16371+static struct apic apic_summit __read_only = {
16372
16373 .name = "summit",
16374 .probe = probe_summit,
16375diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
16376index c88baa4..757aee1 100644
16377--- a/arch/x86/kernel/apic/x2apic_cluster.c
16378+++ b/arch/x86/kernel/apic/x2apic_cluster.c
16379@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
16380 return notifier_from_errno(err);
16381 }
16382
16383-static struct notifier_block __refdata x2apic_cpu_notifier = {
16384+static struct notifier_block x2apic_cpu_notifier = {
16385 .notifier_call = update_clusterinfo,
16386 };
16387
16388@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
16389 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
16390 }
16391
16392-static struct apic apic_x2apic_cluster = {
16393+static struct apic apic_x2apic_cluster __read_only = {
16394
16395 .name = "cluster x2apic",
16396 .probe = x2apic_cluster_probe,
16397diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
16398index 562a76d..a003c0f 100644
16399--- a/arch/x86/kernel/apic/x2apic_phys.c
16400+++ b/arch/x86/kernel/apic/x2apic_phys.c
16401@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
16402 return apic == &apic_x2apic_phys;
16403 }
16404
16405-static struct apic apic_x2apic_phys = {
16406+static struct apic apic_x2apic_phys __read_only = {
16407
16408 .name = "physical x2apic",
16409 .probe = x2apic_phys_probe,
16410diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
16411index 8cfade9..b9d04fc 100644
16412--- a/arch/x86/kernel/apic/x2apic_uv_x.c
16413+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
16414@@ -333,7 +333,7 @@ static int uv_probe(void)
16415 return apic == &apic_x2apic_uv_x;
16416 }
16417
16418-static struct apic __refdata apic_x2apic_uv_x = {
16419+static struct apic apic_x2apic_uv_x __read_only = {
16420
16421 .name = "UV large system",
16422 .probe = uv_probe,
16423diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
16424index d65464e..1035d31 100644
16425--- a/arch/x86/kernel/apm_32.c
16426+++ b/arch/x86/kernel/apm_32.c
16427@@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
16428 * This is for buggy BIOS's that refer to (real mode) segment 0x40
16429 * even though they are called in protected mode.
16430 */
16431-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
16432+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
16433 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
16434
16435 static const char driver_version[] = "1.16ac"; /* no spaces */
16436@@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
16437 BUG_ON(cpu != 0);
16438 gdt = get_cpu_gdt_table(cpu);
16439 save_desc_40 = gdt[0x40 / 8];
16440+
16441+ pax_open_kernel();
16442 gdt[0x40 / 8] = bad_bios_desc;
16443+ pax_close_kernel();
16444
16445 apm_irq_save(flags);
16446 APM_DO_SAVE_SEGS;
16447@@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
16448 &call->esi);
16449 APM_DO_RESTORE_SEGS;
16450 apm_irq_restore(flags);
16451+
16452+ pax_open_kernel();
16453 gdt[0x40 / 8] = save_desc_40;
16454+ pax_close_kernel();
16455+
16456 put_cpu();
16457
16458 return call->eax & 0xff;
16459@@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
16460 BUG_ON(cpu != 0);
16461 gdt = get_cpu_gdt_table(cpu);
16462 save_desc_40 = gdt[0x40 / 8];
16463+
16464+ pax_open_kernel();
16465 gdt[0x40 / 8] = bad_bios_desc;
16466+ pax_close_kernel();
16467
16468 apm_irq_save(flags);
16469 APM_DO_SAVE_SEGS;
16470@@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
16471 &call->eax);
16472 APM_DO_RESTORE_SEGS;
16473 apm_irq_restore(flags);
16474+
16475+ pax_open_kernel();
16476 gdt[0x40 / 8] = save_desc_40;
16477+ pax_close_kernel();
16478+
16479 put_cpu();
16480 return error;
16481 }
16482@@ -2345,12 +2359,15 @@ static int __init apm_init(void)
16483 * code to that CPU.
16484 */
16485 gdt = get_cpu_gdt_table(0);
16486+
16487+ pax_open_kernel();
16488 set_desc_base(&gdt[APM_CS >> 3],
16489 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
16490 set_desc_base(&gdt[APM_CS_16 >> 3],
16491 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
16492 set_desc_base(&gdt[APM_DS >> 3],
16493 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
16494+ pax_close_kernel();
16495
16496 proc_create("apm", 0, NULL, &apm_file_ops);
16497
16498diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
16499index 2861082..6d4718e 100644
16500--- a/arch/x86/kernel/asm-offsets.c
16501+++ b/arch/x86/kernel/asm-offsets.c
16502@@ -33,6 +33,8 @@ void common(void) {
16503 OFFSET(TI_status, thread_info, status);
16504 OFFSET(TI_addr_limit, thread_info, addr_limit);
16505 OFFSET(TI_preempt_count, thread_info, preempt_count);
16506+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
16507+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
16508
16509 BLANK();
16510 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
16511@@ -53,8 +55,26 @@ void common(void) {
16512 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
16513 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
16514 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
16515+
16516+#ifdef CONFIG_PAX_KERNEXEC
16517+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
16518 #endif
16519
16520+#ifdef CONFIG_PAX_MEMORY_UDEREF
16521+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
16522+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
16523+#ifdef CONFIG_X86_64
16524+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
16525+#endif
16526+#endif
16527+
16528+#endif
16529+
16530+ BLANK();
16531+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
16532+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
16533+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
16534+
16535 #ifdef CONFIG_XEN
16536 BLANK();
16537 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
16538diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
16539index 1b4754f..fbb4227 100644
16540--- a/arch/x86/kernel/asm-offsets_64.c
16541+++ b/arch/x86/kernel/asm-offsets_64.c
16542@@ -76,6 +76,7 @@ int main(void)
16543 BLANK();
16544 #undef ENTRY
16545
16546+ DEFINE(TSS_size, sizeof(struct tss_struct));
16547 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
16548 BLANK();
16549
16550diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
16551index a0e067d..9c7db16 100644
16552--- a/arch/x86/kernel/cpu/Makefile
16553+++ b/arch/x86/kernel/cpu/Makefile
16554@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
16555 CFLAGS_REMOVE_perf_event.o = -pg
16556 endif
16557
16558-# Make sure load_percpu_segment has no stackprotector
16559-nostackp := $(call cc-option, -fno-stack-protector)
16560-CFLAGS_common.o := $(nostackp)
16561-
16562 obj-y := intel_cacheinfo.o scattered.o topology.o
16563 obj-y += proc.o capflags.o powerflags.o common.o
16564 obj-y += vmware.o hypervisor.o mshyperv.o
16565diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
16566index 15239ff..e23e04e 100644
16567--- a/arch/x86/kernel/cpu/amd.c
16568+++ b/arch/x86/kernel/cpu/amd.c
16569@@ -733,7 +733,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
16570 unsigned int size)
16571 {
16572 /* AMD errata T13 (order #21922) */
16573- if ((c->x86 == 6)) {
16574+ if (c->x86 == 6) {
16575 /* Duron Rev A0 */
16576 if (c->x86_model == 3 && c->x86_mask == 0)
16577 size = 64;
16578diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
16579index 9c3ab43..51e6366 100644
16580--- a/arch/x86/kernel/cpu/common.c
16581+++ b/arch/x86/kernel/cpu/common.c
16582@@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
16583
16584 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
16585
16586-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
16587-#ifdef CONFIG_X86_64
16588- /*
16589- * We need valid kernel segments for data and code in long mode too
16590- * IRET will check the segment types kkeil 2000/10/28
16591- * Also sysret mandates a special GDT layout
16592- *
16593- * TLS descriptors are currently at a different place compared to i386.
16594- * Hopefully nobody expects them at a fixed place (Wine?)
16595- */
16596- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
16597- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
16598- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
16599- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
16600- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
16601- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
16602-#else
16603- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
16604- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
16605- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
16606- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
16607- /*
16608- * Segments used for calling PnP BIOS have byte granularity.
16609- * They code segments and data segments have fixed 64k limits,
16610- * the transfer segment sizes are set at run time.
16611- */
16612- /* 32-bit code */
16613- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
16614- /* 16-bit code */
16615- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
16616- /* 16-bit data */
16617- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
16618- /* 16-bit data */
16619- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
16620- /* 16-bit data */
16621- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
16622- /*
16623- * The APM segments have byte granularity and their bases
16624- * are set at run time. All have 64k limits.
16625- */
16626- /* 32-bit code */
16627- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
16628- /* 16-bit code */
16629- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
16630- /* data */
16631- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
16632-
16633- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
16634- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
16635- GDT_STACK_CANARY_INIT
16636-#endif
16637-} };
16638-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
16639-
16640 static int __init x86_xsave_setup(char *s)
16641 {
16642 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
16643@@ -389,7 +335,7 @@ void switch_to_new_gdt(int cpu)
16644 {
16645 struct desc_ptr gdt_descr;
16646
16647- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
16648+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
16649 gdt_descr.size = GDT_SIZE - 1;
16650 load_gdt(&gdt_descr);
16651 /* Reload the per-cpu base */
16652@@ -885,6 +831,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
16653 /* Filter out anything that depends on CPUID levels we don't have */
16654 filter_cpuid_features(c, true);
16655
16656+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
16657+ setup_clear_cpu_cap(X86_FEATURE_SEP);
16658+#endif
16659+
16660 /* If the model name is still unset, do table lookup. */
16661 if (!c->x86_model_id[0]) {
16662 const char *p;
16663@@ -1068,10 +1018,12 @@ static __init int setup_disablecpuid(char *arg)
16664 }
16665 __setup("clearcpuid=", setup_disablecpuid);
16666
16667+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
16668+EXPORT_PER_CPU_SYMBOL(current_tinfo);
16669+
16670 #ifdef CONFIG_X86_64
16671 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
16672-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
16673- (unsigned long) nmi_idt_table };
16674+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
16675
16676 DEFINE_PER_CPU_FIRST(union irq_stack_union,
16677 irq_stack_union) __aligned(PAGE_SIZE);
16678@@ -1085,7 +1037,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
16679 EXPORT_PER_CPU_SYMBOL(current_task);
16680
16681 DEFINE_PER_CPU(unsigned long, kernel_stack) =
16682- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
16683+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
16684 EXPORT_PER_CPU_SYMBOL(kernel_stack);
16685
16686 DEFINE_PER_CPU(char *, irq_stack_ptr) =
16687@@ -1224,7 +1176,7 @@ void __cpuinit cpu_init(void)
16688 int i;
16689
16690 cpu = stack_smp_processor_id();
16691- t = &per_cpu(init_tss, cpu);
16692+ t = init_tss + cpu;
16693 oist = &per_cpu(orig_ist, cpu);
16694
16695 #ifdef CONFIG_NUMA
16696@@ -1250,7 +1202,7 @@ void __cpuinit cpu_init(void)
16697 switch_to_new_gdt(cpu);
16698 loadsegment(fs, 0);
16699
16700- load_idt((const struct desc_ptr *)&idt_descr);
16701+ load_idt(&idt_descr);
16702
16703 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
16704 syscall_init();
16705@@ -1259,7 +1211,6 @@ void __cpuinit cpu_init(void)
16706 wrmsrl(MSR_KERNEL_GS_BASE, 0);
16707 barrier();
16708
16709- x86_configure_nx();
16710 enable_x2apic();
16711
16712 /*
16713@@ -1311,7 +1262,7 @@ void __cpuinit cpu_init(void)
16714 {
16715 int cpu = smp_processor_id();
16716 struct task_struct *curr = current;
16717- struct tss_struct *t = &per_cpu(init_tss, cpu);
16718+ struct tss_struct *t = init_tss + cpu;
16719 struct thread_struct *thread = &curr->thread;
16720
16721 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
16722diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
16723index fcaabd0..7b55a26 100644
16724--- a/arch/x86/kernel/cpu/intel.c
16725+++ b/arch/x86/kernel/cpu/intel.c
16726@@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
16727 * Update the IDT descriptor and reload the IDT so that
16728 * it uses the read-only mapped virtual address.
16729 */
16730- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
16731+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
16732 load_idt(&idt_descr);
16733 }
16734 #endif
16735diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
16736index 84c1309..39b7224 100644
16737--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
16738+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
16739@@ -1017,6 +1017,22 @@ static struct attribute *default_attrs[] = {
16740 };
16741
16742 #ifdef CONFIG_AMD_NB
16743+static struct attribute *default_attrs_amd_nb[] = {
16744+ &type.attr,
16745+ &level.attr,
16746+ &coherency_line_size.attr,
16747+ &physical_line_partition.attr,
16748+ &ways_of_associativity.attr,
16749+ &number_of_sets.attr,
16750+ &size.attr,
16751+ &shared_cpu_map.attr,
16752+ &shared_cpu_list.attr,
16753+ NULL,
16754+ NULL,
16755+ NULL,
16756+ NULL
16757+};
16758+
16759 static struct attribute ** __cpuinit amd_l3_attrs(void)
16760 {
16761 static struct attribute **attrs;
16762@@ -1027,18 +1043,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
16763
16764 n = ARRAY_SIZE(default_attrs);
16765
16766- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
16767- n += 2;
16768-
16769- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
16770- n += 1;
16771-
16772- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
16773- if (attrs == NULL)
16774- return attrs = default_attrs;
16775-
16776- for (n = 0; default_attrs[n]; n++)
16777- attrs[n] = default_attrs[n];
16778+ attrs = default_attrs_amd_nb;
16779
16780 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
16781 attrs[n++] = &cache_disable_0.attr;
16782@@ -1089,6 +1094,13 @@ static struct kobj_type ktype_cache = {
16783 .default_attrs = default_attrs,
16784 };
16785
16786+#ifdef CONFIG_AMD_NB
16787+static struct kobj_type ktype_cache_amd_nb = {
16788+ .sysfs_ops = &sysfs_ops,
16789+ .default_attrs = default_attrs_amd_nb,
16790+};
16791+#endif
16792+
16793 static struct kobj_type ktype_percpu_entry = {
16794 .sysfs_ops = &sysfs_ops,
16795 };
16796@@ -1154,20 +1166,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
16797 return retval;
16798 }
16799
16800+#ifdef CONFIG_AMD_NB
16801+ amd_l3_attrs();
16802+#endif
16803+
16804 for (i = 0; i < num_cache_leaves; i++) {
16805+ struct kobj_type *ktype;
16806+
16807 this_object = INDEX_KOBJECT_PTR(cpu, i);
16808 this_object->cpu = cpu;
16809 this_object->index = i;
16810
16811 this_leaf = CPUID4_INFO_IDX(cpu, i);
16812
16813- ktype_cache.default_attrs = default_attrs;
16814+ ktype = &ktype_cache;
16815 #ifdef CONFIG_AMD_NB
16816 if (this_leaf->base.nb)
16817- ktype_cache.default_attrs = amd_l3_attrs();
16818+ ktype = &ktype_cache_amd_nb;
16819 #endif
16820 retval = kobject_init_and_add(&(this_object->kobj),
16821- &ktype_cache,
16822+ ktype,
16823 per_cpu(ici_cache_kobject, cpu),
16824 "index%1lu", i);
16825 if (unlikely(retval)) {
16826@@ -1222,7 +1240,7 @@ static int __cpuinit cacheinfo_cpu_callback(struct notifier_block *nfb,
16827 return NOTIFY_OK;
16828 }
16829
16830-static struct notifier_block __cpuinitdata cacheinfo_cpu_notifier = {
16831+static struct notifier_block cacheinfo_cpu_notifier = {
16832 .notifier_call = cacheinfo_cpu_callback,
16833 };
16834
16835diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
16836index 80dbda8..b45ebad 100644
16837--- a/arch/x86/kernel/cpu/mcheck/mce.c
16838+++ b/arch/x86/kernel/cpu/mcheck/mce.c
16839@@ -45,6 +45,7 @@
16840 #include <asm/processor.h>
16841 #include <asm/mce.h>
16842 #include <asm/msr.h>
16843+#include <asm/local.h>
16844
16845 #include "mce-internal.h"
16846
16847@@ -246,7 +247,7 @@ static void print_mce(struct mce *m)
16848 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
16849 m->cs, m->ip);
16850
16851- if (m->cs == __KERNEL_CS)
16852+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
16853 print_symbol("{%s}", m->ip);
16854 pr_cont("\n");
16855 }
16856@@ -279,10 +280,10 @@ static void print_mce(struct mce *m)
16857
16858 #define PANIC_TIMEOUT 5 /* 5 seconds */
16859
16860-static atomic_t mce_paniced;
16861+static atomic_unchecked_t mce_paniced;
16862
16863 static int fake_panic;
16864-static atomic_t mce_fake_paniced;
16865+static atomic_unchecked_t mce_fake_paniced;
16866
16867 /* Panic in progress. Enable interrupts and wait for final IPI */
16868 static void wait_for_panic(void)
16869@@ -306,7 +307,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
16870 /*
16871 * Make sure only one CPU runs in machine check panic
16872 */
16873- if (atomic_inc_return(&mce_paniced) > 1)
16874+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
16875 wait_for_panic();
16876 barrier();
16877
16878@@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
16879 console_verbose();
16880 } else {
16881 /* Don't log too much for fake panic */
16882- if (atomic_inc_return(&mce_fake_paniced) > 1)
16883+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
16884 return;
16885 }
16886 /* First print corrected ones that are still unlogged */
16887@@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
16888 * might have been modified by someone else.
16889 */
16890 rmb();
16891- if (atomic_read(&mce_paniced))
16892+ if (atomic_read_unchecked(&mce_paniced))
16893 wait_for_panic();
16894 if (!mca_cfg.monarch_timeout)
16895 goto out;
16896@@ -1662,7 +1663,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
16897 }
16898
16899 /* Call the installed machine check handler for this CPU setup. */
16900-void (*machine_check_vector)(struct pt_regs *, long error_code) =
16901+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
16902 unexpected_machine_check;
16903
16904 /*
16905@@ -1685,7 +1686,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
16906 return;
16907 }
16908
16909+ pax_open_kernel();
16910 machine_check_vector = do_machine_check;
16911+ pax_close_kernel();
16912
16913 __mcheck_cpu_init_generic();
16914 __mcheck_cpu_init_vendor(c);
16915@@ -1699,7 +1702,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
16916 */
16917
16918 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
16919-static int mce_chrdev_open_count; /* #times opened */
16920+static local_t mce_chrdev_open_count; /* #times opened */
16921 static int mce_chrdev_open_exclu; /* already open exclusive? */
16922
16923 static int mce_chrdev_open(struct inode *inode, struct file *file)
16924@@ -1707,7 +1710,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
16925 spin_lock(&mce_chrdev_state_lock);
16926
16927 if (mce_chrdev_open_exclu ||
16928- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
16929+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
16930 spin_unlock(&mce_chrdev_state_lock);
16931
16932 return -EBUSY;
16933@@ -1715,7 +1718,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
16934
16935 if (file->f_flags & O_EXCL)
16936 mce_chrdev_open_exclu = 1;
16937- mce_chrdev_open_count++;
16938+ local_inc(&mce_chrdev_open_count);
16939
16940 spin_unlock(&mce_chrdev_state_lock);
16941
16942@@ -1726,7 +1729,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
16943 {
16944 spin_lock(&mce_chrdev_state_lock);
16945
16946- mce_chrdev_open_count--;
16947+ local_dec(&mce_chrdev_open_count);
16948 mce_chrdev_open_exclu = 0;
16949
16950 spin_unlock(&mce_chrdev_state_lock);
16951@@ -2372,7 +2375,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
16952 return NOTIFY_OK;
16953 }
16954
16955-static struct notifier_block mce_cpu_notifier __cpuinitdata = {
16956+static struct notifier_block mce_cpu_notifier = {
16957 .notifier_call = mce_cpu_callback,
16958 };
16959
16960@@ -2450,7 +2453,7 @@ struct dentry *mce_get_debugfs_dir(void)
16961 static void mce_reset(void)
16962 {
16963 cpu_missing = 0;
16964- atomic_set(&mce_fake_paniced, 0);
16965+ atomic_set_unchecked(&mce_fake_paniced, 0);
16966 atomic_set(&mce_executing, 0);
16967 atomic_set(&mce_callin, 0);
16968 atomic_set(&global_nwo, 0);
16969diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
16970index 2d5454c..51987eb 100644
16971--- a/arch/x86/kernel/cpu/mcheck/p5.c
16972+++ b/arch/x86/kernel/cpu/mcheck/p5.c
16973@@ -11,6 +11,7 @@
16974 #include <asm/processor.h>
16975 #include <asm/mce.h>
16976 #include <asm/msr.h>
16977+#include <asm/pgtable.h>
16978
16979 /* By default disabled */
16980 int mce_p5_enabled __read_mostly;
16981@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
16982 if (!cpu_has(c, X86_FEATURE_MCE))
16983 return;
16984
16985+ pax_open_kernel();
16986 machine_check_vector = pentium_machine_check;
16987+ pax_close_kernel();
16988 /* Make sure the vector pointer is visible before we enable MCEs: */
16989 wmb();
16990
16991diff --git a/arch/x86/kernel/cpu/mcheck/therm_throt.c b/arch/x86/kernel/cpu/mcheck/therm_throt.c
16992index 47a1870..8c019a7 100644
16993--- a/arch/x86/kernel/cpu/mcheck/therm_throt.c
16994+++ b/arch/x86/kernel/cpu/mcheck/therm_throt.c
16995@@ -288,7 +288,7 @@ thermal_throttle_cpu_callback(struct notifier_block *nfb,
16996 return notifier_from_errno(err);
16997 }
16998
16999-static struct notifier_block thermal_throttle_cpu_notifier __cpuinitdata =
17000+static struct notifier_block thermal_throttle_cpu_notifier =
17001 {
17002 .notifier_call = thermal_throttle_cpu_callback,
17003 };
17004diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
17005index 2d7998f..17c9de1 100644
17006--- a/arch/x86/kernel/cpu/mcheck/winchip.c
17007+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
17008@@ -10,6 +10,7 @@
17009 #include <asm/processor.h>
17010 #include <asm/mce.h>
17011 #include <asm/msr.h>
17012+#include <asm/pgtable.h>
17013
17014 /* Machine check handler for WinChip C6: */
17015 static void winchip_machine_check(struct pt_regs *regs, long error_code)
17016@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
17017 {
17018 u32 lo, hi;
17019
17020+ pax_open_kernel();
17021 machine_check_vector = winchip_machine_check;
17022+ pax_close_kernel();
17023 /* Make sure the vector pointer is visible before we enable MCEs: */
17024 wmb();
17025
17026diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
17027index 726bf96..81f0526 100644
17028--- a/arch/x86/kernel/cpu/mtrr/main.c
17029+++ b/arch/x86/kernel/cpu/mtrr/main.c
17030@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
17031 u64 size_or_mask, size_and_mask;
17032 static bool mtrr_aps_delayed_init;
17033
17034-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
17035+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
17036
17037 const struct mtrr_ops *mtrr_if;
17038
17039diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
17040index df5e41f..816c719 100644
17041--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
17042+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
17043@@ -25,7 +25,7 @@ struct mtrr_ops {
17044 int (*validate_add_page)(unsigned long base, unsigned long size,
17045 unsigned int type);
17046 int (*have_wrcomb)(void);
17047-};
17048+} __do_const;
17049
17050 extern int generic_get_free_region(unsigned long base, unsigned long size,
17051 int replace_reg);
17052diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
17053index 6774c17..a691911 100644
17054--- a/arch/x86/kernel/cpu/perf_event.c
17055+++ b/arch/x86/kernel/cpu/perf_event.c
17056@@ -1880,7 +1880,7 @@ static unsigned long get_segment_base(unsigned int segment)
17057 if (idx > GDT_ENTRIES)
17058 return 0;
17059
17060- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
17061+ desc = get_cpu_gdt_table(smp_processor_id());
17062 }
17063
17064 return get_desc_base(desc + idx);
17065@@ -1970,7 +1970,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
17066 break;
17067
17068 perf_callchain_store(entry, frame.return_address);
17069- fp = frame.next_frame;
17070+ fp = (const void __force_user *)frame.next_frame;
17071 }
17072 }
17073
17074diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
17075index 4914e94..60b06e3 100644
17076--- a/arch/x86/kernel/cpu/perf_event_intel.c
17077+++ b/arch/x86/kernel/cpu/perf_event_intel.c
17078@@ -1958,10 +1958,10 @@ __init int intel_pmu_init(void)
17079 * v2 and above have a perf capabilities MSR
17080 */
17081 if (version > 1) {
17082- u64 capabilities;
17083+ u64 capabilities = x86_pmu.intel_cap.capabilities;
17084
17085- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
17086- x86_pmu.intel_cap.capabilities = capabilities;
17087+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
17088+ x86_pmu.intel_cap.capabilities = capabilities;
17089 }
17090
17091 intel_ds_init();
17092diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17093index b43200d..62cddfe 100644
17094--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17095+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17096@@ -2826,7 +2826,7 @@ static int
17097 return NOTIFY_OK;
17098 }
17099
17100-static struct notifier_block uncore_cpu_nb __cpuinitdata = {
17101+static struct notifier_block uncore_cpu_nb = {
17102 .notifier_call = uncore_cpu_notifier,
17103 /*
17104 * to migrate uncore events, our notifier should be executed
17105diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
17106index 60c7891..9e911d3 100644
17107--- a/arch/x86/kernel/cpuid.c
17108+++ b/arch/x86/kernel/cpuid.c
17109@@ -171,7 +171,7 @@ static int __cpuinit cpuid_class_cpu_callback(struct notifier_block *nfb,
17110 return notifier_from_errno(err);
17111 }
17112
17113-static struct notifier_block __refdata cpuid_class_cpu_notifier =
17114+static struct notifier_block cpuid_class_cpu_notifier =
17115 {
17116 .notifier_call = cpuid_class_cpu_callback,
17117 };
17118diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
17119index 74467fe..18793d5 100644
17120--- a/arch/x86/kernel/crash.c
17121+++ b/arch/x86/kernel/crash.c
17122@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
17123 {
17124 #ifdef CONFIG_X86_32
17125 struct pt_regs fixed_regs;
17126-#endif
17127
17128-#ifdef CONFIG_X86_32
17129- if (!user_mode_vm(regs)) {
17130+ if (!user_mode(regs)) {
17131 crash_fixup_ss_esp(&fixed_regs, regs);
17132 regs = &fixed_regs;
17133 }
17134diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
17135index 37250fe..bf2ec74 100644
17136--- a/arch/x86/kernel/doublefault_32.c
17137+++ b/arch/x86/kernel/doublefault_32.c
17138@@ -11,7 +11,7 @@
17139
17140 #define DOUBLEFAULT_STACKSIZE (1024)
17141 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
17142-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
17143+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
17144
17145 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
17146
17147@@ -21,7 +21,7 @@ static void doublefault_fn(void)
17148 unsigned long gdt, tss;
17149
17150 store_gdt(&gdt_desc);
17151- gdt = gdt_desc.address;
17152+ gdt = (unsigned long)gdt_desc.address;
17153
17154 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
17155
17156@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
17157 /* 0x2 bit is always set */
17158 .flags = X86_EFLAGS_SF | 0x2,
17159 .sp = STACK_START,
17160- .es = __USER_DS,
17161+ .es = __KERNEL_DS,
17162 .cs = __KERNEL_CS,
17163 .ss = __KERNEL_DS,
17164- .ds = __USER_DS,
17165+ .ds = __KERNEL_DS,
17166 .fs = __KERNEL_PERCPU,
17167
17168 .__cr3 = __pa_nodebug(swapper_pg_dir),
17169diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
17170index ae42418b..787c16b 100644
17171--- a/arch/x86/kernel/dumpstack.c
17172+++ b/arch/x86/kernel/dumpstack.c
17173@@ -2,6 +2,9 @@
17174 * Copyright (C) 1991, 1992 Linus Torvalds
17175 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
17176 */
17177+#ifdef CONFIG_GRKERNSEC_HIDESYM
17178+#define __INCLUDED_BY_HIDESYM 1
17179+#endif
17180 #include <linux/kallsyms.h>
17181 #include <linux/kprobes.h>
17182 #include <linux/uaccess.h>
17183@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
17184 static void
17185 print_ftrace_graph_addr(unsigned long addr, void *data,
17186 const struct stacktrace_ops *ops,
17187- struct thread_info *tinfo, int *graph)
17188+ struct task_struct *task, int *graph)
17189 {
17190- struct task_struct *task;
17191 unsigned long ret_addr;
17192 int index;
17193
17194 if (addr != (unsigned long)return_to_handler)
17195 return;
17196
17197- task = tinfo->task;
17198 index = task->curr_ret_stack;
17199
17200 if (!task->ret_stack || index < *graph)
17201@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17202 static inline void
17203 print_ftrace_graph_addr(unsigned long addr, void *data,
17204 const struct stacktrace_ops *ops,
17205- struct thread_info *tinfo, int *graph)
17206+ struct task_struct *task, int *graph)
17207 { }
17208 #endif
17209
17210@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17211 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
17212 */
17213
17214-static inline int valid_stack_ptr(struct thread_info *tinfo,
17215- void *p, unsigned int size, void *end)
17216+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
17217 {
17218- void *t = tinfo;
17219 if (end) {
17220 if (p < end && p >= (end-THREAD_SIZE))
17221 return 1;
17222@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
17223 }
17224
17225 unsigned long
17226-print_context_stack(struct thread_info *tinfo,
17227+print_context_stack(struct task_struct *task, void *stack_start,
17228 unsigned long *stack, unsigned long bp,
17229 const struct stacktrace_ops *ops, void *data,
17230 unsigned long *end, int *graph)
17231 {
17232 struct stack_frame *frame = (struct stack_frame *)bp;
17233
17234- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
17235+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
17236 unsigned long addr;
17237
17238 addr = *stack;
17239@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
17240 } else {
17241 ops->address(data, addr, 0);
17242 }
17243- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17244+ print_ftrace_graph_addr(addr, data, ops, task, graph);
17245 }
17246 stack++;
17247 }
17248@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
17249 EXPORT_SYMBOL_GPL(print_context_stack);
17250
17251 unsigned long
17252-print_context_stack_bp(struct thread_info *tinfo,
17253+print_context_stack_bp(struct task_struct *task, void *stack_start,
17254 unsigned long *stack, unsigned long bp,
17255 const struct stacktrace_ops *ops, void *data,
17256 unsigned long *end, int *graph)
17257@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17258 struct stack_frame *frame = (struct stack_frame *)bp;
17259 unsigned long *ret_addr = &frame->return_address;
17260
17261- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
17262+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
17263 unsigned long addr = *ret_addr;
17264
17265 if (!__kernel_text_address(addr))
17266@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17267 ops->address(data, addr, 1);
17268 frame = frame->next_frame;
17269 ret_addr = &frame->return_address;
17270- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17271+ print_ftrace_graph_addr(addr, data, ops, task, graph);
17272 }
17273
17274 return (unsigned long)frame;
17275@@ -189,7 +188,7 @@ void dump_stack(void)
17276
17277 bp = stack_frame(current, NULL);
17278 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
17279- current->pid, current->comm, print_tainted(),
17280+ task_pid_nr(current), current->comm, print_tainted(),
17281 init_utsname()->release,
17282 (int)strcspn(init_utsname()->version, " "),
17283 init_utsname()->version);
17284@@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
17285 }
17286 EXPORT_SYMBOL_GPL(oops_begin);
17287
17288+extern void gr_handle_kernel_exploit(void);
17289+
17290 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17291 {
17292 if (regs && kexec_should_crash(current))
17293@@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17294 panic("Fatal exception in interrupt");
17295 if (panic_on_oops)
17296 panic("Fatal exception");
17297- do_exit(signr);
17298+
17299+ gr_handle_kernel_exploit();
17300+
17301+ do_group_exit(signr);
17302 }
17303
17304 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17305@@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17306 print_modules();
17307 show_regs(regs);
17308 #ifdef CONFIG_X86_32
17309- if (user_mode_vm(regs)) {
17310+ if (user_mode(regs)) {
17311 sp = regs->sp;
17312 ss = regs->ss & 0xffff;
17313 } else {
17314@@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
17315 unsigned long flags = oops_begin();
17316 int sig = SIGSEGV;
17317
17318- if (!user_mode_vm(regs))
17319+ if (!user_mode(regs))
17320 report_bug(regs->ip, regs);
17321
17322 if (__die(str, regs, err))
17323diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
17324index 1038a41..db2c12b 100644
17325--- a/arch/x86/kernel/dumpstack_32.c
17326+++ b/arch/x86/kernel/dumpstack_32.c
17327@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17328 bp = stack_frame(task, regs);
17329
17330 for (;;) {
17331- struct thread_info *context;
17332+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
17333
17334- context = (struct thread_info *)
17335- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
17336- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
17337+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
17338
17339- stack = (unsigned long *)context->previous_esp;
17340- if (!stack)
17341+ if (stack_start == task_stack_page(task))
17342 break;
17343+ stack = *(unsigned long **)stack_start;
17344 if (ops->stack(data, "IRQ") < 0)
17345 break;
17346 touch_nmi_watchdog();
17347@@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
17348 {
17349 int i;
17350
17351- __show_regs(regs, !user_mode_vm(regs));
17352+ __show_regs(regs, !user_mode(regs));
17353
17354 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
17355 TASK_COMM_LEN, current->comm, task_pid_nr(current),
17356@@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
17357 * When in-kernel, we also print out the stack and code at the
17358 * time of the fault..
17359 */
17360- if (!user_mode_vm(regs)) {
17361+ if (!user_mode(regs)) {
17362 unsigned int code_prologue = code_bytes * 43 / 64;
17363 unsigned int code_len = code_bytes;
17364 unsigned char c;
17365 u8 *ip;
17366+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
17367
17368 pr_emerg("Stack:\n");
17369 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
17370
17371 pr_emerg("Code:");
17372
17373- ip = (u8 *)regs->ip - code_prologue;
17374+ ip = (u8 *)regs->ip - code_prologue + cs_base;
17375 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
17376 /* try starting at IP */
17377- ip = (u8 *)regs->ip;
17378+ ip = (u8 *)regs->ip + cs_base;
17379 code_len = code_len - code_prologue + 1;
17380 }
17381 for (i = 0; i < code_len; i++, ip++) {
17382@@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
17383 pr_cont(" Bad EIP value.");
17384 break;
17385 }
17386- if (ip == (u8 *)regs->ip)
17387+ if (ip == (u8 *)regs->ip + cs_base)
17388 pr_cont(" <%02x>", c);
17389 else
17390 pr_cont(" %02x", c);
17391@@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
17392 {
17393 unsigned short ud2;
17394
17395+ ip = ktla_ktva(ip);
17396 if (ip < PAGE_OFFSET)
17397 return 0;
17398 if (probe_kernel_address((unsigned short *)ip, ud2))
17399@@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
17400
17401 return ud2 == 0x0b0f;
17402 }
17403+
17404+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17405+void pax_check_alloca(unsigned long size)
17406+{
17407+ unsigned long sp = (unsigned long)&sp, stack_left;
17408+
17409+ /* all kernel stacks are of the same size */
17410+ stack_left = sp & (THREAD_SIZE - 1);
17411+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
17412+}
17413+EXPORT_SYMBOL(pax_check_alloca);
17414+#endif
17415diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
17416index b653675..51cc8c0 100644
17417--- a/arch/x86/kernel/dumpstack_64.c
17418+++ b/arch/x86/kernel/dumpstack_64.c
17419@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17420 unsigned long *irq_stack_end =
17421 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
17422 unsigned used = 0;
17423- struct thread_info *tinfo;
17424 int graph = 0;
17425 unsigned long dummy;
17426+ void *stack_start;
17427
17428 if (!task)
17429 task = current;
17430@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17431 * current stack address. If the stacks consist of nested
17432 * exceptions
17433 */
17434- tinfo = task_thread_info(task);
17435 for (;;) {
17436 char *id;
17437 unsigned long *estack_end;
17438+
17439 estack_end = in_exception_stack(cpu, (unsigned long)stack,
17440 &used, &id);
17441
17442@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17443 if (ops->stack(data, id) < 0)
17444 break;
17445
17446- bp = ops->walk_stack(tinfo, stack, bp, ops,
17447+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
17448 data, estack_end, &graph);
17449 ops->stack(data, "<EOE>");
17450 /*
17451@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17452 * second-to-last pointer (index -2 to end) in the
17453 * exception stack:
17454 */
17455+ if ((u16)estack_end[-1] != __KERNEL_DS)
17456+ goto out;
17457 stack = (unsigned long *) estack_end[-2];
17458 continue;
17459 }
17460@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17461 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
17462 if (ops->stack(data, "IRQ") < 0)
17463 break;
17464- bp = ops->walk_stack(tinfo, stack, bp,
17465+ bp = ops->walk_stack(task, irq_stack, stack, bp,
17466 ops, data, irq_stack_end, &graph);
17467 /*
17468 * We link to the next stack (which would be
17469@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17470 /*
17471 * This handles the process stack:
17472 */
17473- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
17474+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
17475+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
17476+out:
17477 put_cpu();
17478 }
17479 EXPORT_SYMBOL(dump_trace);
17480@@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
17481 {
17482 int i;
17483 unsigned long sp;
17484- const int cpu = smp_processor_id();
17485+ const int cpu = raw_smp_processor_id();
17486 struct task_struct *cur = current;
17487
17488 sp = regs->sp;
17489@@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
17490
17491 return ud2 == 0x0b0f;
17492 }
17493+
17494+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17495+void pax_check_alloca(unsigned long size)
17496+{
17497+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
17498+ unsigned cpu, used;
17499+ char *id;
17500+
17501+ /* check the process stack first */
17502+ stack_start = (unsigned long)task_stack_page(current);
17503+ stack_end = stack_start + THREAD_SIZE;
17504+ if (likely(stack_start <= sp && sp < stack_end)) {
17505+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
17506+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
17507+ return;
17508+ }
17509+
17510+ cpu = get_cpu();
17511+
17512+ /* check the irq stacks */
17513+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
17514+ stack_start = stack_end - IRQ_STACK_SIZE;
17515+ if (stack_start <= sp && sp < stack_end) {
17516+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
17517+ put_cpu();
17518+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
17519+ return;
17520+ }
17521+
17522+ /* check the exception stacks */
17523+ used = 0;
17524+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
17525+ stack_start = stack_end - EXCEPTION_STKSZ;
17526+ if (stack_end && stack_start <= sp && sp < stack_end) {
17527+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
17528+ put_cpu();
17529+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
17530+ return;
17531+ }
17532+
17533+ put_cpu();
17534+
17535+ /* unknown stack */
17536+ BUG();
17537+}
17538+EXPORT_SYMBOL(pax_check_alloca);
17539+#endif
17540diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
17541index 9b9f18b..9fcaa04 100644
17542--- a/arch/x86/kernel/early_printk.c
17543+++ b/arch/x86/kernel/early_printk.c
17544@@ -7,6 +7,7 @@
17545 #include <linux/pci_regs.h>
17546 #include <linux/pci_ids.h>
17547 #include <linux/errno.h>
17548+#include <linux/sched.h>
17549 #include <asm/io.h>
17550 #include <asm/processor.h>
17551 #include <asm/fcntl.h>
17552diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
17553index 6ed91d9..6cc365b 100644
17554--- a/arch/x86/kernel/entry_32.S
17555+++ b/arch/x86/kernel/entry_32.S
17556@@ -177,13 +177,153 @@
17557 /*CFI_REL_OFFSET gs, PT_GS*/
17558 .endm
17559 .macro SET_KERNEL_GS reg
17560+
17561+#ifdef CONFIG_CC_STACKPROTECTOR
17562 movl $(__KERNEL_STACK_CANARY), \reg
17563+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17564+ movl $(__USER_DS), \reg
17565+#else
17566+ xorl \reg, \reg
17567+#endif
17568+
17569 movl \reg, %gs
17570 .endm
17571
17572 #endif /* CONFIG_X86_32_LAZY_GS */
17573
17574-.macro SAVE_ALL
17575+.macro pax_enter_kernel
17576+#ifdef CONFIG_PAX_KERNEXEC
17577+ call pax_enter_kernel
17578+#endif
17579+.endm
17580+
17581+.macro pax_exit_kernel
17582+#ifdef CONFIG_PAX_KERNEXEC
17583+ call pax_exit_kernel
17584+#endif
17585+.endm
17586+
17587+#ifdef CONFIG_PAX_KERNEXEC
17588+ENTRY(pax_enter_kernel)
17589+#ifdef CONFIG_PARAVIRT
17590+ pushl %eax
17591+ pushl %ecx
17592+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
17593+ mov %eax, %esi
17594+#else
17595+ mov %cr0, %esi
17596+#endif
17597+ bts $16, %esi
17598+ jnc 1f
17599+ mov %cs, %esi
17600+ cmp $__KERNEL_CS, %esi
17601+ jz 3f
17602+ ljmp $__KERNEL_CS, $3f
17603+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
17604+2:
17605+#ifdef CONFIG_PARAVIRT
17606+ mov %esi, %eax
17607+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17608+#else
17609+ mov %esi, %cr0
17610+#endif
17611+3:
17612+#ifdef CONFIG_PARAVIRT
17613+ popl %ecx
17614+ popl %eax
17615+#endif
17616+ ret
17617+ENDPROC(pax_enter_kernel)
17618+
17619+ENTRY(pax_exit_kernel)
17620+#ifdef CONFIG_PARAVIRT
17621+ pushl %eax
17622+ pushl %ecx
17623+#endif
17624+ mov %cs, %esi
17625+ cmp $__KERNEXEC_KERNEL_CS, %esi
17626+ jnz 2f
17627+#ifdef CONFIG_PARAVIRT
17628+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
17629+ mov %eax, %esi
17630+#else
17631+ mov %cr0, %esi
17632+#endif
17633+ btr $16, %esi
17634+ ljmp $__KERNEL_CS, $1f
17635+1:
17636+#ifdef CONFIG_PARAVIRT
17637+ mov %esi, %eax
17638+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
17639+#else
17640+ mov %esi, %cr0
17641+#endif
17642+2:
17643+#ifdef CONFIG_PARAVIRT
17644+ popl %ecx
17645+ popl %eax
17646+#endif
17647+ ret
17648+ENDPROC(pax_exit_kernel)
17649+#endif
17650+
17651+.macro pax_erase_kstack
17652+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17653+ call pax_erase_kstack
17654+#endif
17655+.endm
17656+
17657+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17658+/*
17659+ * ebp: thread_info
17660+ */
17661+ENTRY(pax_erase_kstack)
17662+ pushl %edi
17663+ pushl %ecx
17664+ pushl %eax
17665+
17666+ mov TI_lowest_stack(%ebp), %edi
17667+ mov $-0xBEEF, %eax
17668+ std
17669+
17670+1: mov %edi, %ecx
17671+ and $THREAD_SIZE_asm - 1, %ecx
17672+ shr $2, %ecx
17673+ repne scasl
17674+ jecxz 2f
17675+
17676+ cmp $2*16, %ecx
17677+ jc 2f
17678+
17679+ mov $2*16, %ecx
17680+ repe scasl
17681+ jecxz 2f
17682+ jne 1b
17683+
17684+2: cld
17685+ mov %esp, %ecx
17686+ sub %edi, %ecx
17687+
17688+ cmp $THREAD_SIZE_asm, %ecx
17689+ jb 3f
17690+ ud2
17691+3:
17692+
17693+ shr $2, %ecx
17694+ rep stosl
17695+
17696+ mov TI_task_thread_sp0(%ebp), %edi
17697+ sub $128, %edi
17698+ mov %edi, TI_lowest_stack(%ebp)
17699+
17700+ popl %eax
17701+ popl %ecx
17702+ popl %edi
17703+ ret
17704+ENDPROC(pax_erase_kstack)
17705+#endif
17706+
17707+.macro __SAVE_ALL _DS
17708 cld
17709 PUSH_GS
17710 pushl_cfi %fs
17711@@ -206,7 +346,7 @@
17712 CFI_REL_OFFSET ecx, 0
17713 pushl_cfi %ebx
17714 CFI_REL_OFFSET ebx, 0
17715- movl $(__USER_DS), %edx
17716+ movl $\_DS, %edx
17717 movl %edx, %ds
17718 movl %edx, %es
17719 movl $(__KERNEL_PERCPU), %edx
17720@@ -214,6 +354,15 @@
17721 SET_KERNEL_GS %edx
17722 .endm
17723
17724+.macro SAVE_ALL
17725+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
17726+ __SAVE_ALL __KERNEL_DS
17727+ pax_enter_kernel
17728+#else
17729+ __SAVE_ALL __USER_DS
17730+#endif
17731+.endm
17732+
17733 .macro RESTORE_INT_REGS
17734 popl_cfi %ebx
17735 CFI_RESTORE ebx
17736@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
17737 popfl_cfi
17738 jmp syscall_exit
17739 CFI_ENDPROC
17740-END(ret_from_fork)
17741+ENDPROC(ret_from_fork)
17742
17743 ENTRY(ret_from_kernel_thread)
17744 CFI_STARTPROC
17745@@ -344,7 +493,15 @@ ret_from_intr:
17746 andl $SEGMENT_RPL_MASK, %eax
17747 #endif
17748 cmpl $USER_RPL, %eax
17749+
17750+#ifdef CONFIG_PAX_KERNEXEC
17751+ jae resume_userspace
17752+
17753+ pax_exit_kernel
17754+ jmp resume_kernel
17755+#else
17756 jb resume_kernel # not returning to v8086 or userspace
17757+#endif
17758
17759 ENTRY(resume_userspace)
17760 LOCKDEP_SYS_EXIT
17761@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
17762 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
17763 # int/exception return?
17764 jne work_pending
17765- jmp restore_all
17766-END(ret_from_exception)
17767+ jmp restore_all_pax
17768+ENDPROC(ret_from_exception)
17769
17770 #ifdef CONFIG_PREEMPT
17771 ENTRY(resume_kernel)
17772@@ -372,7 +529,7 @@ need_resched:
17773 jz restore_all
17774 call preempt_schedule_irq
17775 jmp need_resched
17776-END(resume_kernel)
17777+ENDPROC(resume_kernel)
17778 #endif
17779 CFI_ENDPROC
17780 /*
17781@@ -406,30 +563,45 @@ sysenter_past_esp:
17782 /*CFI_REL_OFFSET cs, 0*/
17783 /*
17784 * Push current_thread_info()->sysenter_return to the stack.
17785- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
17786- * pushed above; +8 corresponds to copy_thread's esp0 setting.
17787 */
17788- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
17789+ pushl_cfi $0
17790 CFI_REL_OFFSET eip, 0
17791
17792 pushl_cfi %eax
17793 SAVE_ALL
17794+ GET_THREAD_INFO(%ebp)
17795+ movl TI_sysenter_return(%ebp),%ebp
17796+ movl %ebp,PT_EIP(%esp)
17797 ENABLE_INTERRUPTS(CLBR_NONE)
17798
17799 /*
17800 * Load the potential sixth argument from user stack.
17801 * Careful about security.
17802 */
17803+ movl PT_OLDESP(%esp),%ebp
17804+
17805+#ifdef CONFIG_PAX_MEMORY_UDEREF
17806+ mov PT_OLDSS(%esp),%ds
17807+1: movl %ds:(%ebp),%ebp
17808+ push %ss
17809+ pop %ds
17810+#else
17811 cmpl $__PAGE_OFFSET-3,%ebp
17812 jae syscall_fault
17813 ASM_STAC
17814 1: movl (%ebp),%ebp
17815 ASM_CLAC
17816+#endif
17817+
17818 movl %ebp,PT_EBP(%esp)
17819 _ASM_EXTABLE(1b,syscall_fault)
17820
17821 GET_THREAD_INFO(%ebp)
17822
17823+#ifdef CONFIG_PAX_RANDKSTACK
17824+ pax_erase_kstack
17825+#endif
17826+
17827 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
17828 jnz sysenter_audit
17829 sysenter_do_call:
17830@@ -444,12 +616,24 @@ sysenter_do_call:
17831 testl $_TIF_ALLWORK_MASK, %ecx
17832 jne sysexit_audit
17833 sysenter_exit:
17834+
17835+#ifdef CONFIG_PAX_RANDKSTACK
17836+ pushl_cfi %eax
17837+ movl %esp, %eax
17838+ call pax_randomize_kstack
17839+ popl_cfi %eax
17840+#endif
17841+
17842+ pax_erase_kstack
17843+
17844 /* if something modifies registers it must also disable sysexit */
17845 movl PT_EIP(%esp), %edx
17846 movl PT_OLDESP(%esp), %ecx
17847 xorl %ebp,%ebp
17848 TRACE_IRQS_ON
17849 1: mov PT_FS(%esp), %fs
17850+2: mov PT_DS(%esp), %ds
17851+3: mov PT_ES(%esp), %es
17852 PTGS_TO_GS
17853 ENABLE_INTERRUPTS_SYSEXIT
17854
17855@@ -466,6 +650,9 @@ sysenter_audit:
17856 movl %eax,%edx /* 2nd arg: syscall number */
17857 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
17858 call __audit_syscall_entry
17859+
17860+ pax_erase_kstack
17861+
17862 pushl_cfi %ebx
17863 movl PT_EAX(%esp),%eax /* reload syscall number */
17864 jmp sysenter_do_call
17865@@ -491,10 +678,16 @@ sysexit_audit:
17866
17867 CFI_ENDPROC
17868 .pushsection .fixup,"ax"
17869-2: movl $0,PT_FS(%esp)
17870+4: movl $0,PT_FS(%esp)
17871+ jmp 1b
17872+5: movl $0,PT_DS(%esp)
17873+ jmp 1b
17874+6: movl $0,PT_ES(%esp)
17875 jmp 1b
17876 .popsection
17877- _ASM_EXTABLE(1b,2b)
17878+ _ASM_EXTABLE(1b,4b)
17879+ _ASM_EXTABLE(2b,5b)
17880+ _ASM_EXTABLE(3b,6b)
17881 PTGS_TO_GS_EX
17882 ENDPROC(ia32_sysenter_target)
17883
17884@@ -509,6 +702,11 @@ ENTRY(system_call)
17885 pushl_cfi %eax # save orig_eax
17886 SAVE_ALL
17887 GET_THREAD_INFO(%ebp)
17888+
17889+#ifdef CONFIG_PAX_RANDKSTACK
17890+ pax_erase_kstack
17891+#endif
17892+
17893 # system call tracing in operation / emulation
17894 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
17895 jnz syscall_trace_entry
17896@@ -527,6 +725,15 @@ syscall_exit:
17897 testl $_TIF_ALLWORK_MASK, %ecx # current->work
17898 jne syscall_exit_work
17899
17900+restore_all_pax:
17901+
17902+#ifdef CONFIG_PAX_RANDKSTACK
17903+ movl %esp, %eax
17904+ call pax_randomize_kstack
17905+#endif
17906+
17907+ pax_erase_kstack
17908+
17909 restore_all:
17910 TRACE_IRQS_IRET
17911 restore_all_notrace:
17912@@ -583,14 +790,34 @@ ldt_ss:
17913 * compensating for the offset by changing to the ESPFIX segment with
17914 * a base address that matches for the difference.
17915 */
17916-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
17917+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
17918 mov %esp, %edx /* load kernel esp */
17919 mov PT_OLDESP(%esp), %eax /* load userspace esp */
17920 mov %dx, %ax /* eax: new kernel esp */
17921 sub %eax, %edx /* offset (low word is 0) */
17922+#ifdef CONFIG_SMP
17923+ movl PER_CPU_VAR(cpu_number), %ebx
17924+ shll $PAGE_SHIFT_asm, %ebx
17925+ addl $cpu_gdt_table, %ebx
17926+#else
17927+ movl $cpu_gdt_table, %ebx
17928+#endif
17929 shr $16, %edx
17930- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
17931- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
17932+
17933+#ifdef CONFIG_PAX_KERNEXEC
17934+ mov %cr0, %esi
17935+ btr $16, %esi
17936+ mov %esi, %cr0
17937+#endif
17938+
17939+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
17940+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
17941+
17942+#ifdef CONFIG_PAX_KERNEXEC
17943+ bts $16, %esi
17944+ mov %esi, %cr0
17945+#endif
17946+
17947 pushl_cfi $__ESPFIX_SS
17948 pushl_cfi %eax /* new kernel esp */
17949 /* Disable interrupts, but do not irqtrace this section: we
17950@@ -619,20 +846,18 @@ work_resched:
17951 movl TI_flags(%ebp), %ecx
17952 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
17953 # than syscall tracing?
17954- jz restore_all
17955+ jz restore_all_pax
17956 testb $_TIF_NEED_RESCHED, %cl
17957 jnz work_resched
17958
17959 work_notifysig: # deal with pending signals and
17960 # notify-resume requests
17961+ movl %esp, %eax
17962 #ifdef CONFIG_VM86
17963 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
17964- movl %esp, %eax
17965 jne work_notifysig_v86 # returning to kernel-space or
17966 # vm86-space
17967 1:
17968-#else
17969- movl %esp, %eax
17970 #endif
17971 TRACE_IRQS_ON
17972 ENABLE_INTERRUPTS(CLBR_NONE)
17973@@ -653,7 +878,7 @@ work_notifysig_v86:
17974 movl %eax, %esp
17975 jmp 1b
17976 #endif
17977-END(work_pending)
17978+ENDPROC(work_pending)
17979
17980 # perform syscall exit tracing
17981 ALIGN
17982@@ -661,11 +886,14 @@ syscall_trace_entry:
17983 movl $-ENOSYS,PT_EAX(%esp)
17984 movl %esp, %eax
17985 call syscall_trace_enter
17986+
17987+ pax_erase_kstack
17988+
17989 /* What it returned is what we'll actually use. */
17990 cmpl $(NR_syscalls), %eax
17991 jnae syscall_call
17992 jmp syscall_exit
17993-END(syscall_trace_entry)
17994+ENDPROC(syscall_trace_entry)
17995
17996 # perform syscall exit tracing
17997 ALIGN
17998@@ -678,21 +906,25 @@ syscall_exit_work:
17999 movl %esp, %eax
18000 call syscall_trace_leave
18001 jmp resume_userspace
18002-END(syscall_exit_work)
18003+ENDPROC(syscall_exit_work)
18004 CFI_ENDPROC
18005
18006 RING0_INT_FRAME # can't unwind into user space anyway
18007 syscall_fault:
18008+#ifdef CONFIG_PAX_MEMORY_UDEREF
18009+ push %ss
18010+ pop %ds
18011+#endif
18012 ASM_CLAC
18013 GET_THREAD_INFO(%ebp)
18014 movl $-EFAULT,PT_EAX(%esp)
18015 jmp resume_userspace
18016-END(syscall_fault)
18017+ENDPROC(syscall_fault)
18018
18019 syscall_badsys:
18020 movl $-ENOSYS,PT_EAX(%esp)
18021 jmp resume_userspace
18022-END(syscall_badsys)
18023+ENDPROC(syscall_badsys)
18024 CFI_ENDPROC
18025 /*
18026 * End of kprobes section
18027@@ -753,8 +985,15 @@ PTREGSCALL1(vm86old)
18028 * normal stack and adjusts ESP with the matching offset.
18029 */
18030 /* fixup the stack */
18031- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
18032- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
18033+#ifdef CONFIG_SMP
18034+ movl PER_CPU_VAR(cpu_number), %ebx
18035+ shll $PAGE_SHIFT_asm, %ebx
18036+ addl $cpu_gdt_table, %ebx
18037+#else
18038+ movl $cpu_gdt_table, %ebx
18039+#endif
18040+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
18041+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
18042 shl $16, %eax
18043 addl %esp, %eax /* the adjusted stack pointer */
18044 pushl_cfi $__KERNEL_DS
18045@@ -807,7 +1046,7 @@ vector=vector+1
18046 .endr
18047 2: jmp common_interrupt
18048 .endr
18049-END(irq_entries_start)
18050+ENDPROC(irq_entries_start)
18051
18052 .previous
18053 END(interrupt)
18054@@ -858,7 +1097,7 @@ ENTRY(coprocessor_error)
18055 pushl_cfi $do_coprocessor_error
18056 jmp error_code
18057 CFI_ENDPROC
18058-END(coprocessor_error)
18059+ENDPROC(coprocessor_error)
18060
18061 ENTRY(simd_coprocessor_error)
18062 RING0_INT_FRAME
18063@@ -880,7 +1119,7 @@ ENTRY(simd_coprocessor_error)
18064 #endif
18065 jmp error_code
18066 CFI_ENDPROC
18067-END(simd_coprocessor_error)
18068+ENDPROC(simd_coprocessor_error)
18069
18070 ENTRY(device_not_available)
18071 RING0_INT_FRAME
18072@@ -889,18 +1128,18 @@ ENTRY(device_not_available)
18073 pushl_cfi $do_device_not_available
18074 jmp error_code
18075 CFI_ENDPROC
18076-END(device_not_available)
18077+ENDPROC(device_not_available)
18078
18079 #ifdef CONFIG_PARAVIRT
18080 ENTRY(native_iret)
18081 iret
18082 _ASM_EXTABLE(native_iret, iret_exc)
18083-END(native_iret)
18084+ENDPROC(native_iret)
18085
18086 ENTRY(native_irq_enable_sysexit)
18087 sti
18088 sysexit
18089-END(native_irq_enable_sysexit)
18090+ENDPROC(native_irq_enable_sysexit)
18091 #endif
18092
18093 ENTRY(overflow)
18094@@ -910,7 +1149,7 @@ ENTRY(overflow)
18095 pushl_cfi $do_overflow
18096 jmp error_code
18097 CFI_ENDPROC
18098-END(overflow)
18099+ENDPROC(overflow)
18100
18101 ENTRY(bounds)
18102 RING0_INT_FRAME
18103@@ -919,7 +1158,7 @@ ENTRY(bounds)
18104 pushl_cfi $do_bounds
18105 jmp error_code
18106 CFI_ENDPROC
18107-END(bounds)
18108+ENDPROC(bounds)
18109
18110 ENTRY(invalid_op)
18111 RING0_INT_FRAME
18112@@ -928,7 +1167,7 @@ ENTRY(invalid_op)
18113 pushl_cfi $do_invalid_op
18114 jmp error_code
18115 CFI_ENDPROC
18116-END(invalid_op)
18117+ENDPROC(invalid_op)
18118
18119 ENTRY(coprocessor_segment_overrun)
18120 RING0_INT_FRAME
18121@@ -937,7 +1176,7 @@ ENTRY(coprocessor_segment_overrun)
18122 pushl_cfi $do_coprocessor_segment_overrun
18123 jmp error_code
18124 CFI_ENDPROC
18125-END(coprocessor_segment_overrun)
18126+ENDPROC(coprocessor_segment_overrun)
18127
18128 ENTRY(invalid_TSS)
18129 RING0_EC_FRAME
18130@@ -945,7 +1184,7 @@ ENTRY(invalid_TSS)
18131 pushl_cfi $do_invalid_TSS
18132 jmp error_code
18133 CFI_ENDPROC
18134-END(invalid_TSS)
18135+ENDPROC(invalid_TSS)
18136
18137 ENTRY(segment_not_present)
18138 RING0_EC_FRAME
18139@@ -953,7 +1192,7 @@ ENTRY(segment_not_present)
18140 pushl_cfi $do_segment_not_present
18141 jmp error_code
18142 CFI_ENDPROC
18143-END(segment_not_present)
18144+ENDPROC(segment_not_present)
18145
18146 ENTRY(stack_segment)
18147 RING0_EC_FRAME
18148@@ -961,7 +1200,7 @@ ENTRY(stack_segment)
18149 pushl_cfi $do_stack_segment
18150 jmp error_code
18151 CFI_ENDPROC
18152-END(stack_segment)
18153+ENDPROC(stack_segment)
18154
18155 ENTRY(alignment_check)
18156 RING0_EC_FRAME
18157@@ -969,7 +1208,7 @@ ENTRY(alignment_check)
18158 pushl_cfi $do_alignment_check
18159 jmp error_code
18160 CFI_ENDPROC
18161-END(alignment_check)
18162+ENDPROC(alignment_check)
18163
18164 ENTRY(divide_error)
18165 RING0_INT_FRAME
18166@@ -978,7 +1217,7 @@ ENTRY(divide_error)
18167 pushl_cfi $do_divide_error
18168 jmp error_code
18169 CFI_ENDPROC
18170-END(divide_error)
18171+ENDPROC(divide_error)
18172
18173 #ifdef CONFIG_X86_MCE
18174 ENTRY(machine_check)
18175@@ -988,7 +1227,7 @@ ENTRY(machine_check)
18176 pushl_cfi machine_check_vector
18177 jmp error_code
18178 CFI_ENDPROC
18179-END(machine_check)
18180+ENDPROC(machine_check)
18181 #endif
18182
18183 ENTRY(spurious_interrupt_bug)
18184@@ -998,7 +1237,7 @@ ENTRY(spurious_interrupt_bug)
18185 pushl_cfi $do_spurious_interrupt_bug
18186 jmp error_code
18187 CFI_ENDPROC
18188-END(spurious_interrupt_bug)
18189+ENDPROC(spurious_interrupt_bug)
18190 /*
18191 * End of kprobes section
18192 */
18193@@ -1101,7 +1340,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
18194
18195 ENTRY(mcount)
18196 ret
18197-END(mcount)
18198+ENDPROC(mcount)
18199
18200 ENTRY(ftrace_caller)
18201 cmpl $0, function_trace_stop
18202@@ -1134,7 +1373,7 @@ ftrace_graph_call:
18203 .globl ftrace_stub
18204 ftrace_stub:
18205 ret
18206-END(ftrace_caller)
18207+ENDPROC(ftrace_caller)
18208
18209 ENTRY(ftrace_regs_caller)
18210 pushf /* push flags before compare (in cs location) */
18211@@ -1235,7 +1474,7 @@ trace:
18212 popl %ecx
18213 popl %eax
18214 jmp ftrace_stub
18215-END(mcount)
18216+ENDPROC(mcount)
18217 #endif /* CONFIG_DYNAMIC_FTRACE */
18218 #endif /* CONFIG_FUNCTION_TRACER */
18219
18220@@ -1253,7 +1492,7 @@ ENTRY(ftrace_graph_caller)
18221 popl %ecx
18222 popl %eax
18223 ret
18224-END(ftrace_graph_caller)
18225+ENDPROC(ftrace_graph_caller)
18226
18227 .globl return_to_handler
18228 return_to_handler:
18229@@ -1309,15 +1548,18 @@ error_code:
18230 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
18231 REG_TO_PTGS %ecx
18232 SET_KERNEL_GS %ecx
18233- movl $(__USER_DS), %ecx
18234+ movl $(__KERNEL_DS), %ecx
18235 movl %ecx, %ds
18236 movl %ecx, %es
18237+
18238+ pax_enter_kernel
18239+
18240 TRACE_IRQS_OFF
18241 movl %esp,%eax # pt_regs pointer
18242 call *%edi
18243 jmp ret_from_exception
18244 CFI_ENDPROC
18245-END(page_fault)
18246+ENDPROC(page_fault)
18247
18248 /*
18249 * Debug traps and NMI can happen at the one SYSENTER instruction
18250@@ -1360,7 +1602,7 @@ debug_stack_correct:
18251 call do_debug
18252 jmp ret_from_exception
18253 CFI_ENDPROC
18254-END(debug)
18255+ENDPROC(debug)
18256
18257 /*
18258 * NMI is doubly nasty. It can happen _while_ we're handling
18259@@ -1398,6 +1640,9 @@ nmi_stack_correct:
18260 xorl %edx,%edx # zero error code
18261 movl %esp,%eax # pt_regs pointer
18262 call do_nmi
18263+
18264+ pax_exit_kernel
18265+
18266 jmp restore_all_notrace
18267 CFI_ENDPROC
18268
18269@@ -1434,12 +1679,15 @@ nmi_espfix_stack:
18270 FIXUP_ESPFIX_STACK # %eax == %esp
18271 xorl %edx,%edx # zero error code
18272 call do_nmi
18273+
18274+ pax_exit_kernel
18275+
18276 RESTORE_REGS
18277 lss 12+4(%esp), %esp # back to espfix stack
18278 CFI_ADJUST_CFA_OFFSET -24
18279 jmp irq_return
18280 CFI_ENDPROC
18281-END(nmi)
18282+ENDPROC(nmi)
18283
18284 ENTRY(int3)
18285 RING0_INT_FRAME
18286@@ -1452,14 +1700,14 @@ ENTRY(int3)
18287 call do_int3
18288 jmp ret_from_exception
18289 CFI_ENDPROC
18290-END(int3)
18291+ENDPROC(int3)
18292
18293 ENTRY(general_protection)
18294 RING0_EC_FRAME
18295 pushl_cfi $do_general_protection
18296 jmp error_code
18297 CFI_ENDPROC
18298-END(general_protection)
18299+ENDPROC(general_protection)
18300
18301 #ifdef CONFIG_KVM_GUEST
18302 ENTRY(async_page_fault)
18303@@ -1468,7 +1716,7 @@ ENTRY(async_page_fault)
18304 pushl_cfi $do_async_page_fault
18305 jmp error_code
18306 CFI_ENDPROC
18307-END(async_page_fault)
18308+ENDPROC(async_page_fault)
18309 #endif
18310
18311 /*
18312diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
18313index cb3c591..bc63707 100644
18314--- a/arch/x86/kernel/entry_64.S
18315+++ b/arch/x86/kernel/entry_64.S
18316@@ -59,6 +59,8 @@
18317 #include <asm/context_tracking.h>
18318 #include <asm/smap.h>
18319 #include <linux/err.h>
18320+#include <asm/pgtable.h>
18321+#include <asm/alternative-asm.h>
18322
18323 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
18324 #include <linux/elf-em.h>
18325@@ -80,8 +82,9 @@
18326 #ifdef CONFIG_DYNAMIC_FTRACE
18327
18328 ENTRY(function_hook)
18329+ pax_force_retaddr
18330 retq
18331-END(function_hook)
18332+ENDPROC(function_hook)
18333
18334 /* skip is set if stack has been adjusted */
18335 .macro ftrace_caller_setup skip=0
18336@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
18337 #endif
18338
18339 GLOBAL(ftrace_stub)
18340+ pax_force_retaddr
18341 retq
18342-END(ftrace_caller)
18343+ENDPROC(ftrace_caller)
18344
18345 ENTRY(ftrace_regs_caller)
18346 /* Save the current flags before compare (in SS location)*/
18347@@ -191,7 +195,7 @@ ftrace_restore_flags:
18348 popfq
18349 jmp ftrace_stub
18350
18351-END(ftrace_regs_caller)
18352+ENDPROC(ftrace_regs_caller)
18353
18354
18355 #else /* ! CONFIG_DYNAMIC_FTRACE */
18356@@ -212,6 +216,7 @@ ENTRY(function_hook)
18357 #endif
18358
18359 GLOBAL(ftrace_stub)
18360+ pax_force_retaddr
18361 retq
18362
18363 trace:
18364@@ -225,12 +230,13 @@ trace:
18365 #endif
18366 subq $MCOUNT_INSN_SIZE, %rdi
18367
18368+ pax_force_fptr ftrace_trace_function
18369 call *ftrace_trace_function
18370
18371 MCOUNT_RESTORE_FRAME
18372
18373 jmp ftrace_stub
18374-END(function_hook)
18375+ENDPROC(function_hook)
18376 #endif /* CONFIG_DYNAMIC_FTRACE */
18377 #endif /* CONFIG_FUNCTION_TRACER */
18378
18379@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
18380
18381 MCOUNT_RESTORE_FRAME
18382
18383+ pax_force_retaddr
18384 retq
18385-END(ftrace_graph_caller)
18386+ENDPROC(ftrace_graph_caller)
18387
18388 GLOBAL(return_to_handler)
18389 subq $24, %rsp
18390@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
18391 movq 8(%rsp), %rdx
18392 movq (%rsp), %rax
18393 addq $24, %rsp
18394+ pax_force_fptr %rdi
18395 jmp *%rdi
18396+ENDPROC(return_to_handler)
18397 #endif
18398
18399
18400@@ -284,6 +293,273 @@ ENTRY(native_usergs_sysret64)
18401 ENDPROC(native_usergs_sysret64)
18402 #endif /* CONFIG_PARAVIRT */
18403
18404+ .macro ljmpq sel, off
18405+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
18406+ .byte 0x48; ljmp *1234f(%rip)
18407+ .pushsection .rodata
18408+ .align 16
18409+ 1234: .quad \off; .word \sel
18410+ .popsection
18411+#else
18412+ pushq $\sel
18413+ pushq $\off
18414+ lretq
18415+#endif
18416+ .endm
18417+
18418+ .macro pax_enter_kernel
18419+ pax_set_fptr_mask
18420+#ifdef CONFIG_PAX_KERNEXEC
18421+ call pax_enter_kernel
18422+#endif
18423+ .endm
18424+
18425+ .macro pax_exit_kernel
18426+#ifdef CONFIG_PAX_KERNEXEC
18427+ call pax_exit_kernel
18428+#endif
18429+ .endm
18430+
18431+#ifdef CONFIG_PAX_KERNEXEC
18432+ENTRY(pax_enter_kernel)
18433+ pushq %rdi
18434+
18435+#ifdef CONFIG_PARAVIRT
18436+ PV_SAVE_REGS(CLBR_RDI)
18437+#endif
18438+
18439+ GET_CR0_INTO_RDI
18440+ bts $16,%rdi
18441+ jnc 3f
18442+ mov %cs,%edi
18443+ cmp $__KERNEL_CS,%edi
18444+ jnz 2f
18445+1:
18446+
18447+#ifdef CONFIG_PARAVIRT
18448+ PV_RESTORE_REGS(CLBR_RDI)
18449+#endif
18450+
18451+ popq %rdi
18452+ pax_force_retaddr
18453+ retq
18454+
18455+2: ljmpq __KERNEL_CS,1f
18456+3: ljmpq __KERNEXEC_KERNEL_CS,4f
18457+4: SET_RDI_INTO_CR0
18458+ jmp 1b
18459+ENDPROC(pax_enter_kernel)
18460+
18461+ENTRY(pax_exit_kernel)
18462+ pushq %rdi
18463+
18464+#ifdef CONFIG_PARAVIRT
18465+ PV_SAVE_REGS(CLBR_RDI)
18466+#endif
18467+
18468+ mov %cs,%rdi
18469+ cmp $__KERNEXEC_KERNEL_CS,%edi
18470+ jz 2f
18471+1:
18472+
18473+#ifdef CONFIG_PARAVIRT
18474+ PV_RESTORE_REGS(CLBR_RDI);
18475+#endif
18476+
18477+ popq %rdi
18478+ pax_force_retaddr
18479+ retq
18480+
18481+2: GET_CR0_INTO_RDI
18482+ btr $16,%rdi
18483+ ljmpq __KERNEL_CS,3f
18484+3: SET_RDI_INTO_CR0
18485+ jmp 1b
18486+ENDPROC(pax_exit_kernel)
18487+#endif
18488+
18489+ .macro pax_enter_kernel_user
18490+ pax_set_fptr_mask
18491+#ifdef CONFIG_PAX_MEMORY_UDEREF
18492+ call pax_enter_kernel_user
18493+#endif
18494+ .endm
18495+
18496+ .macro pax_exit_kernel_user
18497+#ifdef CONFIG_PAX_MEMORY_UDEREF
18498+ call pax_exit_kernel_user
18499+#endif
18500+#ifdef CONFIG_PAX_RANDKSTACK
18501+ pushq %rax
18502+ call pax_randomize_kstack
18503+ popq %rax
18504+#endif
18505+ .endm
18506+
18507+#ifdef CONFIG_PAX_MEMORY_UDEREF
18508+ENTRY(pax_enter_kernel_user)
18509+ pushq %rdi
18510+ pushq %rbx
18511+
18512+#ifdef CONFIG_PARAVIRT
18513+ PV_SAVE_REGS(CLBR_RDI)
18514+#endif
18515+
18516+ GET_CR3_INTO_RDI
18517+ mov %rdi,%rbx
18518+ add $__START_KERNEL_map,%rbx
18519+ sub phys_base(%rip),%rbx
18520+
18521+#ifdef CONFIG_PARAVIRT
18522+ pushq %rdi
18523+ cmpl $0, pv_info+PARAVIRT_enabled
18524+ jz 1f
18525+ i = 0
18526+ .rept USER_PGD_PTRS
18527+ mov i*8(%rbx),%rsi
18528+ mov $0,%sil
18529+ lea i*8(%rbx),%rdi
18530+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
18531+ i = i + 1
18532+ .endr
18533+ jmp 2f
18534+1:
18535+#endif
18536+
18537+ i = 0
18538+ .rept USER_PGD_PTRS
18539+ movb $0,i*8(%rbx)
18540+ i = i + 1
18541+ .endr
18542+
18543+#ifdef CONFIG_PARAVIRT
18544+2: popq %rdi
18545+#endif
18546+ SET_RDI_INTO_CR3
18547+
18548+#ifdef CONFIG_PAX_KERNEXEC
18549+ GET_CR0_INTO_RDI
18550+ bts $16,%rdi
18551+ SET_RDI_INTO_CR0
18552+#endif
18553+
18554+#ifdef CONFIG_PARAVIRT
18555+ PV_RESTORE_REGS(CLBR_RDI)
18556+#endif
18557+
18558+ popq %rbx
18559+ popq %rdi
18560+ pax_force_retaddr
18561+ retq
18562+ENDPROC(pax_enter_kernel_user)
18563+
18564+ENTRY(pax_exit_kernel_user)
18565+ push %rdi
18566+
18567+#ifdef CONFIG_PARAVIRT
18568+ pushq %rbx
18569+ PV_SAVE_REGS(CLBR_RDI)
18570+#endif
18571+
18572+#ifdef CONFIG_PAX_KERNEXEC
18573+ GET_CR0_INTO_RDI
18574+ btr $16,%rdi
18575+ SET_RDI_INTO_CR0
18576+#endif
18577+
18578+ GET_CR3_INTO_RDI
18579+ add $__START_KERNEL_map,%rdi
18580+ sub phys_base(%rip),%rdi
18581+
18582+#ifdef CONFIG_PARAVIRT
18583+ cmpl $0, pv_info+PARAVIRT_enabled
18584+ jz 1f
18585+ mov %rdi,%rbx
18586+ i = 0
18587+ .rept USER_PGD_PTRS
18588+ mov i*8(%rbx),%rsi
18589+ mov $0x67,%sil
18590+ lea i*8(%rbx),%rdi
18591+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
18592+ i = i + 1
18593+ .endr
18594+ jmp 2f
18595+1:
18596+#endif
18597+
18598+ i = 0
18599+ .rept USER_PGD_PTRS
18600+ movb $0x67,i*8(%rdi)
18601+ i = i + 1
18602+ .endr
18603+
18604+#ifdef CONFIG_PARAVIRT
18605+2: PV_RESTORE_REGS(CLBR_RDI)
18606+ popq %rbx
18607+#endif
18608+
18609+ popq %rdi
18610+ pax_force_retaddr
18611+ retq
18612+ENDPROC(pax_exit_kernel_user)
18613+#endif
18614+
18615+.macro pax_erase_kstack
18616+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18617+ call pax_erase_kstack
18618+#endif
18619+.endm
18620+
18621+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18622+ENTRY(pax_erase_kstack)
18623+ pushq %rdi
18624+ pushq %rcx
18625+ pushq %rax
18626+ pushq %r11
18627+
18628+ GET_THREAD_INFO(%r11)
18629+ mov TI_lowest_stack(%r11), %rdi
18630+ mov $-0xBEEF, %rax
18631+ std
18632+
18633+1: mov %edi, %ecx
18634+ and $THREAD_SIZE_asm - 1, %ecx
18635+ shr $3, %ecx
18636+ repne scasq
18637+ jecxz 2f
18638+
18639+ cmp $2*8, %ecx
18640+ jc 2f
18641+
18642+ mov $2*8, %ecx
18643+ repe scasq
18644+ jecxz 2f
18645+ jne 1b
18646+
18647+2: cld
18648+ mov %esp, %ecx
18649+ sub %edi, %ecx
18650+
18651+ cmp $THREAD_SIZE_asm, %rcx
18652+ jb 3f
18653+ ud2
18654+3:
18655+
18656+ shr $3, %ecx
18657+ rep stosq
18658+
18659+ mov TI_task_thread_sp0(%r11), %rdi
18660+ sub $256, %rdi
18661+ mov %rdi, TI_lowest_stack(%r11)
18662+
18663+ popq %r11
18664+ popq %rax
18665+ popq %rcx
18666+ popq %rdi
18667+ pax_force_retaddr
18668+ ret
18669+ENDPROC(pax_erase_kstack)
18670+#endif
18671
18672 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
18673 #ifdef CONFIG_TRACE_IRQFLAGS
18674@@ -375,8 +651,8 @@ ENDPROC(native_usergs_sysret64)
18675 .endm
18676
18677 .macro UNFAKE_STACK_FRAME
18678- addq $8*6, %rsp
18679- CFI_ADJUST_CFA_OFFSET -(6*8)
18680+ addq $8*6 + ARG_SKIP, %rsp
18681+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
18682 .endm
18683
18684 /*
18685@@ -463,7 +739,7 @@ ENDPROC(native_usergs_sysret64)
18686 movq %rsp, %rsi
18687
18688 leaq -RBP(%rsp),%rdi /* arg1 for handler */
18689- testl $3, CS-RBP(%rsi)
18690+ testb $3, CS-RBP(%rsi)
18691 je 1f
18692 SWAPGS
18693 /*
18694@@ -498,9 +774,10 @@ ENTRY(save_rest)
18695 movq_cfi r15, R15+16
18696 movq %r11, 8(%rsp) /* return address */
18697 FIXUP_TOP_OF_STACK %r11, 16
18698+ pax_force_retaddr
18699 ret
18700 CFI_ENDPROC
18701-END(save_rest)
18702+ENDPROC(save_rest)
18703
18704 /* save complete stack frame */
18705 .pushsection .kprobes.text, "ax"
18706@@ -529,9 +806,10 @@ ENTRY(save_paranoid)
18707 js 1f /* negative -> in kernel */
18708 SWAPGS
18709 xorl %ebx,%ebx
18710-1: ret
18711+1: pax_force_retaddr_bts
18712+ ret
18713 CFI_ENDPROC
18714-END(save_paranoid)
18715+ENDPROC(save_paranoid)
18716 .popsection
18717
18718 /*
18719@@ -553,7 +831,7 @@ ENTRY(ret_from_fork)
18720
18721 RESTORE_REST
18722
18723- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
18724+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
18725 jz 1f
18726
18727 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
18728@@ -571,7 +849,7 @@ ENTRY(ret_from_fork)
18729 RESTORE_REST
18730 jmp int_ret_from_sys_call
18731 CFI_ENDPROC
18732-END(ret_from_fork)
18733+ENDPROC(ret_from_fork)
18734
18735 /*
18736 * System call entry. Up to 6 arguments in registers are supported.
18737@@ -608,7 +886,7 @@ END(ret_from_fork)
18738 ENTRY(system_call)
18739 CFI_STARTPROC simple
18740 CFI_SIGNAL_FRAME
18741- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
18742+ CFI_DEF_CFA rsp,0
18743 CFI_REGISTER rip,rcx
18744 /*CFI_REGISTER rflags,r11*/
18745 SWAPGS_UNSAFE_STACK
18746@@ -621,16 +899,23 @@ GLOBAL(system_call_after_swapgs)
18747
18748 movq %rsp,PER_CPU_VAR(old_rsp)
18749 movq PER_CPU_VAR(kernel_stack),%rsp
18750+ SAVE_ARGS 8*6,0
18751+ pax_enter_kernel_user
18752+
18753+#ifdef CONFIG_PAX_RANDKSTACK
18754+ pax_erase_kstack
18755+#endif
18756+
18757 /*
18758 * No need to follow this irqs off/on section - it's straight
18759 * and short:
18760 */
18761 ENABLE_INTERRUPTS(CLBR_NONE)
18762- SAVE_ARGS 8,0
18763 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
18764 movq %rcx,RIP-ARGOFFSET(%rsp)
18765 CFI_REL_OFFSET rip,RIP-ARGOFFSET
18766- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
18767+ GET_THREAD_INFO(%rcx)
18768+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
18769 jnz tracesys
18770 system_call_fastpath:
18771 #if __SYSCALL_MASK == ~0
18772@@ -640,7 +925,7 @@ system_call_fastpath:
18773 cmpl $__NR_syscall_max,%eax
18774 #endif
18775 ja badsys
18776- movq %r10,%rcx
18777+ movq R10-ARGOFFSET(%rsp),%rcx
18778 call *sys_call_table(,%rax,8) # XXX: rip relative
18779 movq %rax,RAX-ARGOFFSET(%rsp)
18780 /*
18781@@ -654,10 +939,13 @@ sysret_check:
18782 LOCKDEP_SYS_EXIT
18783 DISABLE_INTERRUPTS(CLBR_NONE)
18784 TRACE_IRQS_OFF
18785- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
18786+ GET_THREAD_INFO(%rcx)
18787+ movl TI_flags(%rcx),%edx
18788 andl %edi,%edx
18789 jnz sysret_careful
18790 CFI_REMEMBER_STATE
18791+ pax_exit_kernel_user
18792+ pax_erase_kstack
18793 /*
18794 * sysretq will re-enable interrupts:
18795 */
18796@@ -709,14 +997,18 @@ badsys:
18797 * jump back to the normal fast path.
18798 */
18799 auditsys:
18800- movq %r10,%r9 /* 6th arg: 4th syscall arg */
18801+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
18802 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
18803 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
18804 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
18805 movq %rax,%rsi /* 2nd arg: syscall number */
18806 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
18807 call __audit_syscall_entry
18808+
18809+ pax_erase_kstack
18810+
18811 LOAD_ARGS 0 /* reload call-clobbered registers */
18812+ pax_set_fptr_mask
18813 jmp system_call_fastpath
18814
18815 /*
18816@@ -737,7 +1029,7 @@ sysret_audit:
18817 /* Do syscall tracing */
18818 tracesys:
18819 #ifdef CONFIG_AUDITSYSCALL
18820- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
18821+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
18822 jz auditsys
18823 #endif
18824 SAVE_REST
18825@@ -745,12 +1037,16 @@ tracesys:
18826 FIXUP_TOP_OF_STACK %rdi
18827 movq %rsp,%rdi
18828 call syscall_trace_enter
18829+
18830+ pax_erase_kstack
18831+
18832 /*
18833 * Reload arg registers from stack in case ptrace changed them.
18834 * We don't reload %rax because syscall_trace_enter() returned
18835 * the value it wants us to use in the table lookup.
18836 */
18837 LOAD_ARGS ARGOFFSET, 1
18838+ pax_set_fptr_mask
18839 RESTORE_REST
18840 #if __SYSCALL_MASK == ~0
18841 cmpq $__NR_syscall_max,%rax
18842@@ -759,7 +1055,7 @@ tracesys:
18843 cmpl $__NR_syscall_max,%eax
18844 #endif
18845 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
18846- movq %r10,%rcx /* fixup for C */
18847+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
18848 call *sys_call_table(,%rax,8)
18849 movq %rax,RAX-ARGOFFSET(%rsp)
18850 /* Use IRET because user could have changed frame */
18851@@ -780,7 +1076,9 @@ GLOBAL(int_with_check)
18852 andl %edi,%edx
18853 jnz int_careful
18854 andl $~TS_COMPAT,TI_status(%rcx)
18855- jmp retint_swapgs
18856+ pax_exit_kernel_user
18857+ pax_erase_kstack
18858+ jmp retint_swapgs_pax
18859
18860 /* Either reschedule or signal or syscall exit tracking needed. */
18861 /* First do a reschedule test. */
18862@@ -826,7 +1124,7 @@ int_restore_rest:
18863 TRACE_IRQS_OFF
18864 jmp int_with_check
18865 CFI_ENDPROC
18866-END(system_call)
18867+ENDPROC(system_call)
18868
18869 /*
18870 * Certain special system calls that need to save a complete full stack frame.
18871@@ -842,7 +1140,7 @@ ENTRY(\label)
18872 call \func
18873 jmp ptregscall_common
18874 CFI_ENDPROC
18875-END(\label)
18876+ENDPROC(\label)
18877 .endm
18878
18879 .macro FORK_LIKE func
18880@@ -856,9 +1154,10 @@ ENTRY(stub_\func)
18881 DEFAULT_FRAME 0 8 /* offset 8: return address */
18882 call sys_\func
18883 RESTORE_TOP_OF_STACK %r11, 8
18884+ pax_force_retaddr
18885 ret $REST_SKIP /* pop extended registers */
18886 CFI_ENDPROC
18887-END(stub_\func)
18888+ENDPROC(stub_\func)
18889 .endm
18890
18891 FORK_LIKE clone
18892@@ -875,9 +1174,10 @@ ENTRY(ptregscall_common)
18893 movq_cfi_restore R12+8, r12
18894 movq_cfi_restore RBP+8, rbp
18895 movq_cfi_restore RBX+8, rbx
18896+ pax_force_retaddr
18897 ret $REST_SKIP /* pop extended registers */
18898 CFI_ENDPROC
18899-END(ptregscall_common)
18900+ENDPROC(ptregscall_common)
18901
18902 ENTRY(stub_execve)
18903 CFI_STARTPROC
18904@@ -891,7 +1191,7 @@ ENTRY(stub_execve)
18905 RESTORE_REST
18906 jmp int_ret_from_sys_call
18907 CFI_ENDPROC
18908-END(stub_execve)
18909+ENDPROC(stub_execve)
18910
18911 /*
18912 * sigreturn is special because it needs to restore all registers on return.
18913@@ -909,7 +1209,7 @@ ENTRY(stub_rt_sigreturn)
18914 RESTORE_REST
18915 jmp int_ret_from_sys_call
18916 CFI_ENDPROC
18917-END(stub_rt_sigreturn)
18918+ENDPROC(stub_rt_sigreturn)
18919
18920 #ifdef CONFIG_X86_X32_ABI
18921 ENTRY(stub_x32_rt_sigreturn)
18922@@ -975,7 +1275,7 @@ vector=vector+1
18923 2: jmp common_interrupt
18924 .endr
18925 CFI_ENDPROC
18926-END(irq_entries_start)
18927+ENDPROC(irq_entries_start)
18928
18929 .previous
18930 END(interrupt)
18931@@ -995,6 +1295,16 @@ END(interrupt)
18932 subq $ORIG_RAX-RBP, %rsp
18933 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
18934 SAVE_ARGS_IRQ
18935+#ifdef CONFIG_PAX_MEMORY_UDEREF
18936+ testb $3, CS(%rdi)
18937+ jnz 1f
18938+ pax_enter_kernel
18939+ jmp 2f
18940+1: pax_enter_kernel_user
18941+2:
18942+#else
18943+ pax_enter_kernel
18944+#endif
18945 call \func
18946 .endm
18947
18948@@ -1027,7 +1337,7 @@ ret_from_intr:
18949
18950 exit_intr:
18951 GET_THREAD_INFO(%rcx)
18952- testl $3,CS-ARGOFFSET(%rsp)
18953+ testb $3,CS-ARGOFFSET(%rsp)
18954 je retint_kernel
18955
18956 /* Interrupt came from user space */
18957@@ -1049,12 +1359,16 @@ retint_swapgs: /* return to user-space */
18958 * The iretq could re-enable interrupts:
18959 */
18960 DISABLE_INTERRUPTS(CLBR_ANY)
18961+ pax_exit_kernel_user
18962+retint_swapgs_pax:
18963 TRACE_IRQS_IRETQ
18964 SWAPGS
18965 jmp restore_args
18966
18967 retint_restore_args: /* return to kernel space */
18968 DISABLE_INTERRUPTS(CLBR_ANY)
18969+ pax_exit_kernel
18970+ pax_force_retaddr (RIP-ARGOFFSET)
18971 /*
18972 * The iretq could re-enable interrupts:
18973 */
18974@@ -1137,7 +1451,7 @@ ENTRY(retint_kernel)
18975 #endif
18976
18977 CFI_ENDPROC
18978-END(common_interrupt)
18979+ENDPROC(common_interrupt)
18980 /*
18981 * End of kprobes section
18982 */
18983@@ -1155,7 +1469,7 @@ ENTRY(\sym)
18984 interrupt \do_sym
18985 jmp ret_from_intr
18986 CFI_ENDPROC
18987-END(\sym)
18988+ENDPROC(\sym)
18989 .endm
18990
18991 #ifdef CONFIG_SMP
18992@@ -1211,12 +1525,22 @@ ENTRY(\sym)
18993 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
18994 call error_entry
18995 DEFAULT_FRAME 0
18996+#ifdef CONFIG_PAX_MEMORY_UDEREF
18997+ testb $3, CS(%rsp)
18998+ jnz 1f
18999+ pax_enter_kernel
19000+ jmp 2f
19001+1: pax_enter_kernel_user
19002+2:
19003+#else
19004+ pax_enter_kernel
19005+#endif
19006 movq %rsp,%rdi /* pt_regs pointer */
19007 xorl %esi,%esi /* no error code */
19008 call \do_sym
19009 jmp error_exit /* %ebx: no swapgs flag */
19010 CFI_ENDPROC
19011-END(\sym)
19012+ENDPROC(\sym)
19013 .endm
19014
19015 .macro paranoidzeroentry sym do_sym
19016@@ -1229,15 +1553,25 @@ ENTRY(\sym)
19017 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19018 call save_paranoid
19019 TRACE_IRQS_OFF
19020+#ifdef CONFIG_PAX_MEMORY_UDEREF
19021+ testb $3, CS(%rsp)
19022+ jnz 1f
19023+ pax_enter_kernel
19024+ jmp 2f
19025+1: pax_enter_kernel_user
19026+2:
19027+#else
19028+ pax_enter_kernel
19029+#endif
19030 movq %rsp,%rdi /* pt_regs pointer */
19031 xorl %esi,%esi /* no error code */
19032 call \do_sym
19033 jmp paranoid_exit /* %ebx: no swapgs flag */
19034 CFI_ENDPROC
19035-END(\sym)
19036+ENDPROC(\sym)
19037 .endm
19038
19039-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
19040+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
19041 .macro paranoidzeroentry_ist sym do_sym ist
19042 ENTRY(\sym)
19043 INTR_FRAME
19044@@ -1248,14 +1582,30 @@ ENTRY(\sym)
19045 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19046 call save_paranoid
19047 TRACE_IRQS_OFF_DEBUG
19048+#ifdef CONFIG_PAX_MEMORY_UDEREF
19049+ testb $3, CS(%rsp)
19050+ jnz 1f
19051+ pax_enter_kernel
19052+ jmp 2f
19053+1: pax_enter_kernel_user
19054+2:
19055+#else
19056+ pax_enter_kernel
19057+#endif
19058 movq %rsp,%rdi /* pt_regs pointer */
19059 xorl %esi,%esi /* no error code */
19060+#ifdef CONFIG_SMP
19061+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
19062+ lea init_tss(%r12), %r12
19063+#else
19064+ lea init_tss(%rip), %r12
19065+#endif
19066 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19067 call \do_sym
19068 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19069 jmp paranoid_exit /* %ebx: no swapgs flag */
19070 CFI_ENDPROC
19071-END(\sym)
19072+ENDPROC(\sym)
19073 .endm
19074
19075 .macro errorentry sym do_sym
19076@@ -1267,13 +1617,23 @@ ENTRY(\sym)
19077 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19078 call error_entry
19079 DEFAULT_FRAME 0
19080+#ifdef CONFIG_PAX_MEMORY_UDEREF
19081+ testb $3, CS(%rsp)
19082+ jnz 1f
19083+ pax_enter_kernel
19084+ jmp 2f
19085+1: pax_enter_kernel_user
19086+2:
19087+#else
19088+ pax_enter_kernel
19089+#endif
19090 movq %rsp,%rdi /* pt_regs pointer */
19091 movq ORIG_RAX(%rsp),%rsi /* get error code */
19092 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19093 call \do_sym
19094 jmp error_exit /* %ebx: no swapgs flag */
19095 CFI_ENDPROC
19096-END(\sym)
19097+ENDPROC(\sym)
19098 .endm
19099
19100 /* error code is on the stack already */
19101@@ -1287,13 +1647,23 @@ ENTRY(\sym)
19102 call save_paranoid
19103 DEFAULT_FRAME 0
19104 TRACE_IRQS_OFF
19105+#ifdef CONFIG_PAX_MEMORY_UDEREF
19106+ testb $3, CS(%rsp)
19107+ jnz 1f
19108+ pax_enter_kernel
19109+ jmp 2f
19110+1: pax_enter_kernel_user
19111+2:
19112+#else
19113+ pax_enter_kernel
19114+#endif
19115 movq %rsp,%rdi /* pt_regs pointer */
19116 movq ORIG_RAX(%rsp),%rsi /* get error code */
19117 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19118 call \do_sym
19119 jmp paranoid_exit /* %ebx: no swapgs flag */
19120 CFI_ENDPROC
19121-END(\sym)
19122+ENDPROC(\sym)
19123 .endm
19124
19125 zeroentry divide_error do_divide_error
19126@@ -1323,9 +1693,10 @@ gs_change:
19127 2: mfence /* workaround */
19128 SWAPGS
19129 popfq_cfi
19130+ pax_force_retaddr
19131 ret
19132 CFI_ENDPROC
19133-END(native_load_gs_index)
19134+ENDPROC(native_load_gs_index)
19135
19136 _ASM_EXTABLE(gs_change,bad_gs)
19137 .section .fixup,"ax"
19138@@ -1353,9 +1724,10 @@ ENTRY(call_softirq)
19139 CFI_DEF_CFA_REGISTER rsp
19140 CFI_ADJUST_CFA_OFFSET -8
19141 decl PER_CPU_VAR(irq_count)
19142+ pax_force_retaddr
19143 ret
19144 CFI_ENDPROC
19145-END(call_softirq)
19146+ENDPROC(call_softirq)
19147
19148 #ifdef CONFIG_XEN
19149 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
19150@@ -1393,7 +1765,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
19151 decl PER_CPU_VAR(irq_count)
19152 jmp error_exit
19153 CFI_ENDPROC
19154-END(xen_do_hypervisor_callback)
19155+ENDPROC(xen_do_hypervisor_callback)
19156
19157 /*
19158 * Hypervisor uses this for application faults while it executes.
19159@@ -1452,7 +1824,7 @@ ENTRY(xen_failsafe_callback)
19160 SAVE_ALL
19161 jmp error_exit
19162 CFI_ENDPROC
19163-END(xen_failsafe_callback)
19164+ENDPROC(xen_failsafe_callback)
19165
19166 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
19167 xen_hvm_callback_vector xen_evtchn_do_upcall
19168@@ -1501,16 +1873,31 @@ ENTRY(paranoid_exit)
19169 TRACE_IRQS_OFF_DEBUG
19170 testl %ebx,%ebx /* swapgs needed? */
19171 jnz paranoid_restore
19172- testl $3,CS(%rsp)
19173+ testb $3,CS(%rsp)
19174 jnz paranoid_userspace
19175+#ifdef CONFIG_PAX_MEMORY_UDEREF
19176+ pax_exit_kernel
19177+ TRACE_IRQS_IRETQ 0
19178+ SWAPGS_UNSAFE_STACK
19179+ RESTORE_ALL 8
19180+ pax_force_retaddr_bts
19181+ jmp irq_return
19182+#endif
19183 paranoid_swapgs:
19184+#ifdef CONFIG_PAX_MEMORY_UDEREF
19185+ pax_exit_kernel_user
19186+#else
19187+ pax_exit_kernel
19188+#endif
19189 TRACE_IRQS_IRETQ 0
19190 SWAPGS_UNSAFE_STACK
19191 RESTORE_ALL 8
19192 jmp irq_return
19193 paranoid_restore:
19194+ pax_exit_kernel
19195 TRACE_IRQS_IRETQ_DEBUG 0
19196 RESTORE_ALL 8
19197+ pax_force_retaddr_bts
19198 jmp irq_return
19199 paranoid_userspace:
19200 GET_THREAD_INFO(%rcx)
19201@@ -1539,7 +1926,7 @@ paranoid_schedule:
19202 TRACE_IRQS_OFF
19203 jmp paranoid_userspace
19204 CFI_ENDPROC
19205-END(paranoid_exit)
19206+ENDPROC(paranoid_exit)
19207
19208 /*
19209 * Exception entry point. This expects an error code/orig_rax on the stack.
19210@@ -1566,12 +1953,13 @@ ENTRY(error_entry)
19211 movq_cfi r14, R14+8
19212 movq_cfi r15, R15+8
19213 xorl %ebx,%ebx
19214- testl $3,CS+8(%rsp)
19215+ testb $3,CS+8(%rsp)
19216 je error_kernelspace
19217 error_swapgs:
19218 SWAPGS
19219 error_sti:
19220 TRACE_IRQS_OFF
19221+ pax_force_retaddr_bts
19222 ret
19223
19224 /*
19225@@ -1598,7 +1986,7 @@ bstep_iret:
19226 movq %rcx,RIP+8(%rsp)
19227 jmp error_swapgs
19228 CFI_ENDPROC
19229-END(error_entry)
19230+ENDPROC(error_entry)
19231
19232
19233 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
19234@@ -1618,7 +2006,7 @@ ENTRY(error_exit)
19235 jnz retint_careful
19236 jmp retint_swapgs
19237 CFI_ENDPROC
19238-END(error_exit)
19239+ENDPROC(error_exit)
19240
19241 /*
19242 * Test if a given stack is an NMI stack or not.
19243@@ -1676,9 +2064,11 @@ ENTRY(nmi)
19244 * If %cs was not the kernel segment, then the NMI triggered in user
19245 * space, which means it is definitely not nested.
19246 */
19247+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
19248+ je 1f
19249 cmpl $__KERNEL_CS, 16(%rsp)
19250 jne first_nmi
19251-
19252+1:
19253 /*
19254 * Check the special variable on the stack to see if NMIs are
19255 * executing.
19256@@ -1847,6 +2237,17 @@ end_repeat_nmi:
19257 */
19258 movq %cr2, %r12
19259
19260+#ifdef CONFIG_PAX_MEMORY_UDEREF
19261+ testb $3, CS(%rsp)
19262+ jnz 1f
19263+ pax_enter_kernel
19264+ jmp 2f
19265+1: pax_enter_kernel_user
19266+2:
19267+#else
19268+ pax_enter_kernel
19269+#endif
19270+
19271 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
19272 movq %rsp,%rdi
19273 movq $-1,%rsi
19274@@ -1862,23 +2263,34 @@ end_repeat_nmi:
19275 testl %ebx,%ebx /* swapgs needed? */
19276 jnz nmi_restore
19277 nmi_swapgs:
19278+#ifdef CONFIG_PAX_MEMORY_UDEREF
19279+ pax_exit_kernel_user
19280+#else
19281+ pax_exit_kernel
19282+#endif
19283 SWAPGS_UNSAFE_STACK
19284+ RESTORE_ALL 6*8
19285+ /* Clear the NMI executing stack variable */
19286+ movq $0, 5*8(%rsp)
19287+ jmp irq_return
19288 nmi_restore:
19289+ pax_exit_kernel
19290 /* Pop the extra iret frame at once */
19291 RESTORE_ALL 6*8
19292+ pax_force_retaddr_bts
19293
19294 /* Clear the NMI executing stack variable */
19295 movq $0, 5*8(%rsp)
19296 jmp irq_return
19297 CFI_ENDPROC
19298-END(nmi)
19299+ENDPROC(nmi)
19300
19301 ENTRY(ignore_sysret)
19302 CFI_STARTPROC
19303 mov $-ENOSYS,%eax
19304 sysret
19305 CFI_ENDPROC
19306-END(ignore_sysret)
19307+ENDPROC(ignore_sysret)
19308
19309 /*
19310 * End of kprobes section
19311diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
19312index 1d41402..af9a46a 100644
19313--- a/arch/x86/kernel/ftrace.c
19314+++ b/arch/x86/kernel/ftrace.c
19315@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
19316 {
19317 unsigned char replaced[MCOUNT_INSN_SIZE];
19318
19319+ ip = ktla_ktva(ip);
19320+
19321 /*
19322 * Note: Due to modules and __init, code can
19323 * disappear and change, we need to protect against faulting
19324@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
19325 unsigned char old[MCOUNT_INSN_SIZE], *new;
19326 int ret;
19327
19328- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
19329+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
19330 new = ftrace_call_replace(ip, (unsigned long)func);
19331
19332 /* See comment above by declaration of modifying_ftrace_code */
19333@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
19334 /* Also update the regs callback function */
19335 if (!ret) {
19336 ip = (unsigned long)(&ftrace_regs_call);
19337- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
19338+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
19339 new = ftrace_call_replace(ip, (unsigned long)func);
19340 ret = ftrace_modify_code(ip, old, new);
19341 }
19342@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
19343 * kernel identity mapping to modify code.
19344 */
19345 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
19346- ip = (unsigned long)__va(__pa(ip));
19347+ ip = (unsigned long)__va(__pa(ktla_ktva(ip)));
19348
19349 return probe_kernel_write((void *)ip, val, size);
19350 }
19351@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
19352 unsigned char replaced[MCOUNT_INSN_SIZE];
19353 unsigned char brk = BREAKPOINT_INSTRUCTION;
19354
19355- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
19356+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
19357 return -EFAULT;
19358
19359 /* Make sure it is what we expect it to be */
19360@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
19361 return ret;
19362
19363 fail_update:
19364- probe_kernel_write((void *)ip, &old_code[0], 1);
19365+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
19366 goto out;
19367 }
19368
19369@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
19370 {
19371 unsigned char code[MCOUNT_INSN_SIZE];
19372
19373+ ip = ktla_ktva(ip);
19374+
19375 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
19376 return -EFAULT;
19377
19378diff --git a/arch/x86/kernel/head.c b/arch/x86/kernel/head.c
19379index 48d9d4e..992f442 100644
19380--- a/arch/x86/kernel/head.c
19381+++ b/arch/x86/kernel/head.c
19382@@ -5,8 +5,6 @@
19383 #include <asm/setup.h>
19384 #include <asm/bios_ebda.h>
19385
19386-#define BIOS_LOWMEM_KILOBYTES 0x413
19387-
19388 /*
19389 * The BIOS places the EBDA/XBDA at the top of conventional
19390 * memory, and usually decreases the reported amount of
19391@@ -16,17 +14,30 @@
19392 * chipset: reserve a page before VGA to prevent PCI prefetch
19393 * into it (errata #56). Usually the page is reserved anyways,
19394 * unless you have no PS/2 mouse plugged in.
19395+ *
19396+ * This functions is deliberately very conservative. Losing
19397+ * memory in the bottom megabyte is rarely a problem, as long
19398+ * as we have enough memory to install the trampoline. Using
19399+ * memory that is in use by the BIOS or by some DMA device
19400+ * the BIOS didn't shut down *is* a big problem.
19401 */
19402+
19403+#define BIOS_LOWMEM_KILOBYTES 0x413
19404+#define LOWMEM_CAP 0x9f000U /* Absolute maximum */
19405+#define INSANE_CUTOFF 0x20000U /* Less than this = insane */
19406+
19407 void __init reserve_ebda_region(void)
19408 {
19409 unsigned int lowmem, ebda_addr;
19410
19411- /* To determine the position of the EBDA and the */
19412- /* end of conventional memory, we need to look at */
19413- /* the BIOS data area. In a paravirtual environment */
19414- /* that area is absent. We'll just have to assume */
19415- /* that the paravirt case can handle memory setup */
19416- /* correctly, without our help. */
19417+ /*
19418+ * To determine the position of the EBDA and the
19419+ * end of conventional memory, we need to look at
19420+ * the BIOS data area. In a paravirtual environment
19421+ * that area is absent. We'll just have to assume
19422+ * that the paravirt case can handle memory setup
19423+ * correctly, without our help.
19424+ */
19425 if (paravirt_enabled())
19426 return;
19427
19428@@ -37,19 +48,23 @@ void __init reserve_ebda_region(void)
19429 /* start of EBDA area */
19430 ebda_addr = get_bios_ebda();
19431
19432- /* Fixup: bios puts an EBDA in the top 64K segment */
19433- /* of conventional memory, but does not adjust lowmem. */
19434- if ((lowmem - ebda_addr) <= 0x10000)
19435- lowmem = ebda_addr;
19436+ /*
19437+ * Note: some old Dells seem to need 4k EBDA without
19438+ * reporting so, so just consider the memory above 0x9f000
19439+ * to be off limits (bugzilla 2990).
19440+ */
19441
19442- /* Fixup: bios does not report an EBDA at all. */
19443- /* Some old Dells seem to need 4k anyhow (bugzilla 2990) */
19444- if ((ebda_addr == 0) && (lowmem >= 0x9f000))
19445- lowmem = 0x9f000;
19446+ /* If the EBDA address is below 128K, assume it is bogus */
19447+ if (ebda_addr < INSANE_CUTOFF)
19448+ ebda_addr = LOWMEM_CAP;
19449
19450- /* Paranoia: should never happen, but... */
19451- if ((lowmem == 0) || (lowmem >= 0x100000))
19452- lowmem = 0x9f000;
19453+ /* If lowmem is less than 128K, assume it is bogus */
19454+ if (lowmem < INSANE_CUTOFF)
19455+ lowmem = LOWMEM_CAP;
19456+
19457+ /* Use the lower of the lowmem and EBDA markers as the cutoff */
19458+ lowmem = min(lowmem, ebda_addr);
19459+ lowmem = min(lowmem, LOWMEM_CAP); /* Absolute cap */
19460
19461 /* reserve all memory between lowmem and the 1MB mark */
19462 memblock_reserve(lowmem, 0x100000 - lowmem);
19463diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
19464index c18f59d..9c0c9f6 100644
19465--- a/arch/x86/kernel/head32.c
19466+++ b/arch/x86/kernel/head32.c
19467@@ -18,6 +18,7 @@
19468 #include <asm/io_apic.h>
19469 #include <asm/bios_ebda.h>
19470 #include <asm/tlbflush.h>
19471+#include <asm/boot.h>
19472
19473 static void __init i386_default_early_setup(void)
19474 {
19475@@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
19476
19477 void __init i386_start_kernel(void)
19478 {
19479- memblock_reserve(__pa_symbol(&_text),
19480- __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
19481+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
19482
19483 #ifdef CONFIG_BLK_DEV_INITRD
19484 /* Reserve INITRD */
19485diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
19486index c8932c7..d56b622 100644
19487--- a/arch/x86/kernel/head_32.S
19488+++ b/arch/x86/kernel/head_32.S
19489@@ -26,6 +26,12 @@
19490 /* Physical address */
19491 #define pa(X) ((X) - __PAGE_OFFSET)
19492
19493+#ifdef CONFIG_PAX_KERNEXEC
19494+#define ta(X) (X)
19495+#else
19496+#define ta(X) ((X) - __PAGE_OFFSET)
19497+#endif
19498+
19499 /*
19500 * References to members of the new_cpu_data structure.
19501 */
19502@@ -55,11 +61,7 @@
19503 * and small than max_low_pfn, otherwise will waste some page table entries
19504 */
19505
19506-#if PTRS_PER_PMD > 1
19507-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
19508-#else
19509-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
19510-#endif
19511+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
19512
19513 /* Number of possible pages in the lowmem region */
19514 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
19515@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
19516 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
19517
19518 /*
19519+ * Real beginning of normal "text" segment
19520+ */
19521+ENTRY(stext)
19522+ENTRY(_stext)
19523+
19524+/*
19525 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
19526 * %esi points to the real-mode code as a 32-bit pointer.
19527 * CS and DS must be 4 GB flat segments, but we don't depend on
19528@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
19529 * can.
19530 */
19531 __HEAD
19532+
19533+#ifdef CONFIG_PAX_KERNEXEC
19534+ jmp startup_32
19535+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
19536+.fill PAGE_SIZE-5,1,0xcc
19537+#endif
19538+
19539 ENTRY(startup_32)
19540 movl pa(stack_start),%ecx
19541
19542@@ -106,6 +121,59 @@ ENTRY(startup_32)
19543 2:
19544 leal -__PAGE_OFFSET(%ecx),%esp
19545
19546+#ifdef CONFIG_SMP
19547+ movl $pa(cpu_gdt_table),%edi
19548+ movl $__per_cpu_load,%eax
19549+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
19550+ rorl $16,%eax
19551+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
19552+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
19553+ movl $__per_cpu_end - 1,%eax
19554+ subl $__per_cpu_start,%eax
19555+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
19556+#endif
19557+
19558+#ifdef CONFIG_PAX_MEMORY_UDEREF
19559+ movl $NR_CPUS,%ecx
19560+ movl $pa(cpu_gdt_table),%edi
19561+1:
19562+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
19563+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
19564+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
19565+ addl $PAGE_SIZE_asm,%edi
19566+ loop 1b
19567+#endif
19568+
19569+#ifdef CONFIG_PAX_KERNEXEC
19570+ movl $pa(boot_gdt),%edi
19571+ movl $__LOAD_PHYSICAL_ADDR,%eax
19572+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
19573+ rorl $16,%eax
19574+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
19575+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
19576+ rorl $16,%eax
19577+
19578+ ljmp $(__BOOT_CS),$1f
19579+1:
19580+
19581+ movl $NR_CPUS,%ecx
19582+ movl $pa(cpu_gdt_table),%edi
19583+ addl $__PAGE_OFFSET,%eax
19584+1:
19585+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
19586+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
19587+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
19588+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
19589+ rorl $16,%eax
19590+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
19591+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
19592+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
19593+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
19594+ rorl $16,%eax
19595+ addl $PAGE_SIZE_asm,%edi
19596+ loop 1b
19597+#endif
19598+
19599 /*
19600 * Clear BSS first so that there are no surprises...
19601 */
19602@@ -196,8 +264,11 @@ ENTRY(startup_32)
19603 movl %eax, pa(max_pfn_mapped)
19604
19605 /* Do early initialization of the fixmap area */
19606- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
19607- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
19608+#ifdef CONFIG_COMPAT_VDSO
19609+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
19610+#else
19611+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
19612+#endif
19613 #else /* Not PAE */
19614
19615 page_pde_offset = (__PAGE_OFFSET >> 20);
19616@@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
19617 movl %eax, pa(max_pfn_mapped)
19618
19619 /* Do early initialization of the fixmap area */
19620- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
19621- movl %eax,pa(initial_page_table+0xffc)
19622+#ifdef CONFIG_COMPAT_VDSO
19623+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
19624+#else
19625+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
19626+#endif
19627 #endif
19628
19629 #ifdef CONFIG_PARAVIRT
19630@@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
19631 cmpl $num_subarch_entries, %eax
19632 jae bad_subarch
19633
19634- movl pa(subarch_entries)(,%eax,4), %eax
19635- subl $__PAGE_OFFSET, %eax
19636- jmp *%eax
19637+ jmp *pa(subarch_entries)(,%eax,4)
19638
19639 bad_subarch:
19640 WEAK(lguest_entry)
19641@@ -256,10 +328,10 @@ WEAK(xen_entry)
19642 __INITDATA
19643
19644 subarch_entries:
19645- .long default_entry /* normal x86/PC */
19646- .long lguest_entry /* lguest hypervisor */
19647- .long xen_entry /* Xen hypervisor */
19648- .long default_entry /* Moorestown MID */
19649+ .long ta(default_entry) /* normal x86/PC */
19650+ .long ta(lguest_entry) /* lguest hypervisor */
19651+ .long ta(xen_entry) /* Xen hypervisor */
19652+ .long ta(default_entry) /* Moorestown MID */
19653 num_subarch_entries = (. - subarch_entries) / 4
19654 .previous
19655 #else
19656@@ -335,6 +407,7 @@ default_entry:
19657 movl pa(mmu_cr4_features),%eax
19658 movl %eax,%cr4
19659
19660+#ifdef CONFIG_X86_PAE
19661 testb $X86_CR4_PAE, %al # check if PAE is enabled
19662 jz 6f
19663
19664@@ -363,6 +436,9 @@ default_entry:
19665 /* Make changes effective */
19666 wrmsr
19667
19668+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
19669+#endif
19670+
19671 6:
19672
19673 /*
19674@@ -460,14 +536,20 @@ is386: movl $2,%ecx # set MP
19675 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
19676 movl %eax,%ss # after changing gdt.
19677
19678- movl $(__USER_DS),%eax # DS/ES contains default USER segment
19679+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
19680 movl %eax,%ds
19681 movl %eax,%es
19682
19683 movl $(__KERNEL_PERCPU), %eax
19684 movl %eax,%fs # set this cpu's percpu
19685
19686+#ifdef CONFIG_CC_STACKPROTECTOR
19687 movl $(__KERNEL_STACK_CANARY),%eax
19688+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
19689+ movl $(__USER_DS),%eax
19690+#else
19691+ xorl %eax,%eax
19692+#endif
19693 movl %eax,%gs
19694
19695 xorl %eax,%eax # Clear LDT
19696@@ -544,8 +626,11 @@ setup_once:
19697 * relocation. Manually set base address in stack canary
19698 * segment descriptor.
19699 */
19700- movl $gdt_page,%eax
19701+ movl $cpu_gdt_table,%eax
19702 movl $stack_canary,%ecx
19703+#ifdef CONFIG_SMP
19704+ addl $__per_cpu_load,%ecx
19705+#endif
19706 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
19707 shrl $16, %ecx
19708 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
19709@@ -576,7 +661,7 @@ ENDPROC(early_idt_handlers)
19710 /* This is global to keep gas from relaxing the jumps */
19711 ENTRY(early_idt_handler)
19712 cld
19713- cmpl $2,%ss:early_recursion_flag
19714+ cmpl $1,%ss:early_recursion_flag
19715 je hlt_loop
19716 incl %ss:early_recursion_flag
19717
19718@@ -614,8 +699,8 @@ ENTRY(early_idt_handler)
19719 pushl (20+6*4)(%esp) /* trapno */
19720 pushl $fault_msg
19721 call printk
19722-#endif
19723 call dump_stack
19724+#endif
19725 hlt_loop:
19726 hlt
19727 jmp hlt_loop
19728@@ -634,8 +719,11 @@ ENDPROC(early_idt_handler)
19729 /* This is the default interrupt "handler" :-) */
19730 ALIGN
19731 ignore_int:
19732- cld
19733 #ifdef CONFIG_PRINTK
19734+ cmpl $2,%ss:early_recursion_flag
19735+ je hlt_loop
19736+ incl %ss:early_recursion_flag
19737+ cld
19738 pushl %eax
19739 pushl %ecx
19740 pushl %edx
19741@@ -644,9 +732,6 @@ ignore_int:
19742 movl $(__KERNEL_DS),%eax
19743 movl %eax,%ds
19744 movl %eax,%es
19745- cmpl $2,early_recursion_flag
19746- je hlt_loop
19747- incl early_recursion_flag
19748 pushl 16(%esp)
19749 pushl 24(%esp)
19750 pushl 32(%esp)
19751@@ -680,29 +765,43 @@ ENTRY(setup_once_ref)
19752 /*
19753 * BSS section
19754 */
19755-__PAGE_ALIGNED_BSS
19756- .align PAGE_SIZE
19757 #ifdef CONFIG_X86_PAE
19758+.section .initial_pg_pmd,"a",@progbits
19759 initial_pg_pmd:
19760 .fill 1024*KPMDS,4,0
19761 #else
19762+.section .initial_page_table,"a",@progbits
19763 ENTRY(initial_page_table)
19764 .fill 1024,4,0
19765 #endif
19766+.section .initial_pg_fixmap,"a",@progbits
19767 initial_pg_fixmap:
19768 .fill 1024,4,0
19769+.section .empty_zero_page,"a",@progbits
19770 ENTRY(empty_zero_page)
19771 .fill 4096,1,0
19772+.section .swapper_pg_dir,"a",@progbits
19773 ENTRY(swapper_pg_dir)
19774+#ifdef CONFIG_X86_PAE
19775+ .fill 4,8,0
19776+#else
19777 .fill 1024,4,0
19778+#endif
19779+
19780+/*
19781+ * The IDT has to be page-aligned to simplify the Pentium
19782+ * F0 0F bug workaround.. We have a special link segment
19783+ * for this.
19784+ */
19785+.section .idt,"a",@progbits
19786+ENTRY(idt_table)
19787+ .fill 256,8,0
19788
19789 /*
19790 * This starts the data section.
19791 */
19792 #ifdef CONFIG_X86_PAE
19793-__PAGE_ALIGNED_DATA
19794- /* Page-aligned for the benefit of paravirt? */
19795- .align PAGE_SIZE
19796+.section .initial_page_table,"a",@progbits
19797 ENTRY(initial_page_table)
19798 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
19799 # if KPMDS == 3
19800@@ -721,12 +820,20 @@ ENTRY(initial_page_table)
19801 # error "Kernel PMDs should be 1, 2 or 3"
19802 # endif
19803 .align PAGE_SIZE /* needs to be page-sized too */
19804+
19805+#ifdef CONFIG_PAX_PER_CPU_PGD
19806+ENTRY(cpu_pgd)
19807+ .rept NR_CPUS
19808+ .fill 4,8,0
19809+ .endr
19810+#endif
19811+
19812 #endif
19813
19814 .data
19815 .balign 4
19816 ENTRY(stack_start)
19817- .long init_thread_union+THREAD_SIZE
19818+ .long init_thread_union+THREAD_SIZE-8
19819
19820 __INITRODATA
19821 int_msg:
19822@@ -754,7 +861,7 @@ fault_msg:
19823 * segment size, and 32-bit linear address value:
19824 */
19825
19826- .data
19827+.section .rodata,"a",@progbits
19828 .globl boot_gdt_descr
19829 .globl idt_descr
19830
19831@@ -763,7 +870,7 @@ fault_msg:
19832 .word 0 # 32 bit align gdt_desc.address
19833 boot_gdt_descr:
19834 .word __BOOT_DS+7
19835- .long boot_gdt - __PAGE_OFFSET
19836+ .long pa(boot_gdt)
19837
19838 .word 0 # 32-bit align idt_desc.address
19839 idt_descr:
19840@@ -774,7 +881,7 @@ idt_descr:
19841 .word 0 # 32 bit align gdt_desc.address
19842 ENTRY(early_gdt_descr)
19843 .word GDT_ENTRIES*8-1
19844- .long gdt_page /* Overwritten for secondary CPUs */
19845+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
19846
19847 /*
19848 * The boot_gdt must mirror the equivalent in setup.S and is
19849@@ -783,5 +890,65 @@ ENTRY(early_gdt_descr)
19850 .align L1_CACHE_BYTES
19851 ENTRY(boot_gdt)
19852 .fill GDT_ENTRY_BOOT_CS,8,0
19853- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
19854- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
19855+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
19856+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
19857+
19858+ .align PAGE_SIZE_asm
19859+ENTRY(cpu_gdt_table)
19860+ .rept NR_CPUS
19861+ .quad 0x0000000000000000 /* NULL descriptor */
19862+ .quad 0x0000000000000000 /* 0x0b reserved */
19863+ .quad 0x0000000000000000 /* 0x13 reserved */
19864+ .quad 0x0000000000000000 /* 0x1b reserved */
19865+
19866+#ifdef CONFIG_PAX_KERNEXEC
19867+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
19868+#else
19869+ .quad 0x0000000000000000 /* 0x20 unused */
19870+#endif
19871+
19872+ .quad 0x0000000000000000 /* 0x28 unused */
19873+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
19874+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
19875+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
19876+ .quad 0x0000000000000000 /* 0x4b reserved */
19877+ .quad 0x0000000000000000 /* 0x53 reserved */
19878+ .quad 0x0000000000000000 /* 0x5b reserved */
19879+
19880+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
19881+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
19882+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
19883+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
19884+
19885+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
19886+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
19887+
19888+ /*
19889+ * Segments used for calling PnP BIOS have byte granularity.
19890+ * The code segments and data segments have fixed 64k limits,
19891+ * the transfer segment sizes are set at run time.
19892+ */
19893+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
19894+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
19895+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
19896+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
19897+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
19898+
19899+ /*
19900+ * The APM segments have byte granularity and their bases
19901+ * are set at run time. All have 64k limits.
19902+ */
19903+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
19904+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
19905+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
19906+
19907+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
19908+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
19909+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
19910+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
19911+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
19912+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
19913+
19914+ /* Be sure this is zeroed to avoid false validations in Xen */
19915+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
19916+ .endr
19917diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
19918index 980053c..74d3b44 100644
19919--- a/arch/x86/kernel/head_64.S
19920+++ b/arch/x86/kernel/head_64.S
19921@@ -20,6 +20,8 @@
19922 #include <asm/processor-flags.h>
19923 #include <asm/percpu.h>
19924 #include <asm/nops.h>
19925+#include <asm/cpufeature.h>
19926+#include <asm/alternative-asm.h>
19927
19928 #ifdef CONFIG_PARAVIRT
19929 #include <asm/asm-offsets.h>
19930@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
19931 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
19932 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
19933 L3_START_KERNEL = pud_index(__START_KERNEL_map)
19934+L4_VMALLOC_START = pgd_index(VMALLOC_START)
19935+L3_VMALLOC_START = pud_index(VMALLOC_START)
19936+L4_VMALLOC_END = pgd_index(VMALLOC_END)
19937+L3_VMALLOC_END = pud_index(VMALLOC_END)
19938+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
19939+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
19940
19941 .text
19942 __HEAD
19943@@ -88,35 +96,23 @@ startup_64:
19944 */
19945 addq %rbp, init_level4_pgt + 0(%rip)
19946 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
19947+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
19948+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
19949+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
19950 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
19951
19952 addq %rbp, level3_ident_pgt + 0(%rip)
19953+#ifndef CONFIG_XEN
19954+ addq %rbp, level3_ident_pgt + 8(%rip)
19955+#endif
19956
19957- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
19958- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
19959+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
19960+
19961+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
19962+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
19963
19964 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
19965-
19966- /* Add an Identity mapping if I am above 1G */
19967- leaq _text(%rip), %rdi
19968- andq $PMD_PAGE_MASK, %rdi
19969-
19970- movq %rdi, %rax
19971- shrq $PUD_SHIFT, %rax
19972- andq $(PTRS_PER_PUD - 1), %rax
19973- jz ident_complete
19974-
19975- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
19976- leaq level3_ident_pgt(%rip), %rbx
19977- movq %rdx, 0(%rbx, %rax, 8)
19978-
19979- movq %rdi, %rax
19980- shrq $PMD_SHIFT, %rax
19981- andq $(PTRS_PER_PMD - 1), %rax
19982- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
19983- leaq level2_spare_pgt(%rip), %rbx
19984- movq %rdx, 0(%rbx, %rax, 8)
19985-ident_complete:
19986+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
19987
19988 /*
19989 * Fixup the kernel text+data virtual addresses. Note that
19990@@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
19991 * after the boot processor executes this code.
19992 */
19993
19994- /* Enable PAE mode and PGE */
19995- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
19996+ /* Enable PAE mode and PSE/PGE */
19997+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
19998 movq %rax, %cr4
19999
20000 /* Setup early boot stage 4 level pagetables. */
20001@@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
20002 movl $MSR_EFER, %ecx
20003 rdmsr
20004 btsl $_EFER_SCE, %eax /* Enable System Call */
20005- btl $20,%edi /* No Execute supported? */
20006+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
20007 jnc 1f
20008 btsl $_EFER_NX, %eax
20009+ leaq init_level4_pgt(%rip), %rdi
20010+#ifndef CONFIG_EFI
20011+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
20012+#endif
20013+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
20014+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
20015+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
20016+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
20017 1: wrmsr /* Make changes effective */
20018
20019 /* Setup cr0 */
20020@@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
20021 * jump. In addition we need to ensure %cs is set so we make this
20022 * a far return.
20023 */
20024+ pax_set_fptr_mask
20025 movq initial_code(%rip),%rax
20026 pushq $0 # fake return address to stop unwinder
20027 pushq $__KERNEL_CS # set correct cs
20028@@ -284,7 +289,7 @@ ENDPROC(start_cpu0)
20029 bad_address:
20030 jmp bad_address
20031
20032- .section ".init.text","ax"
20033+ __INIT
20034 .globl early_idt_handlers
20035 early_idt_handlers:
20036 # 104(%rsp) %rflags
20037@@ -343,7 +348,7 @@ ENTRY(early_idt_handler)
20038 call dump_stack
20039 #ifdef CONFIG_KALLSYMS
20040 leaq early_idt_ripmsg(%rip),%rdi
20041- movq 40(%rsp),%rsi # %rip again
20042+ movq 88(%rsp),%rsi # %rip again
20043 call __print_symbol
20044 #endif
20045 #endif /* EARLY_PRINTK */
20046@@ -363,11 +368,15 @@ ENTRY(early_idt_handler)
20047 addq $16,%rsp # drop vector number and error code
20048 decl early_recursion_flag(%rip)
20049 INTERRUPT_RETURN
20050+ .previous
20051
20052+ __INITDATA
20053 .balign 4
20054 early_recursion_flag:
20055 .long 0
20056+ .previous
20057
20058+ .section .rodata,"a",@progbits
20059 #ifdef CONFIG_EARLY_PRINTK
20060 early_idt_msg:
20061 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
20062@@ -376,6 +385,7 @@ early_idt_ripmsg:
20063 #endif /* CONFIG_EARLY_PRINTK */
20064 .previous
20065
20066+ .section .rodata,"a",@progbits
20067 #define NEXT_PAGE(name) \
20068 .balign PAGE_SIZE; \
20069 ENTRY(name)
20070@@ -388,7 +398,6 @@ ENTRY(name)
20071 i = i + 1 ; \
20072 .endr
20073
20074- .data
20075 /*
20076 * This default setting generates an ident mapping at address 0x100000
20077 * and a mapping for the kernel that precisely maps virtual address
20078@@ -399,13 +408,41 @@ NEXT_PAGE(init_level4_pgt)
20079 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20080 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
20081 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20082+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
20083+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
20084+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
20085+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
20086+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
20087+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20088 .org init_level4_pgt + L4_START_KERNEL*8, 0
20089 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
20090 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
20091
20092+#ifdef CONFIG_PAX_PER_CPU_PGD
20093+NEXT_PAGE(cpu_pgd)
20094+ .rept NR_CPUS
20095+ .fill 512,8,0
20096+ .endr
20097+#endif
20098+
20099 NEXT_PAGE(level3_ident_pgt)
20100 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20101+#ifdef CONFIG_XEN
20102 .fill 511,8,0
20103+#else
20104+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
20105+ .fill 510,8,0
20106+#endif
20107+
20108+NEXT_PAGE(level3_vmalloc_start_pgt)
20109+ .fill 512,8,0
20110+
20111+NEXT_PAGE(level3_vmalloc_end_pgt)
20112+ .fill 512,8,0
20113+
20114+NEXT_PAGE(level3_vmemmap_pgt)
20115+ .fill L3_VMEMMAP_START,8,0
20116+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20117
20118 NEXT_PAGE(level3_kernel_pgt)
20119 .fill L3_START_KERNEL,8,0
20120@@ -413,20 +450,23 @@ NEXT_PAGE(level3_kernel_pgt)
20121 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
20122 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20123
20124+NEXT_PAGE(level2_vmemmap_pgt)
20125+ .fill 512,8,0
20126+
20127 NEXT_PAGE(level2_fixmap_pgt)
20128- .fill 506,8,0
20129- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20130- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
20131- .fill 5,8,0
20132+ .fill 507,8,0
20133+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
20134+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
20135+ .fill 4,8,0
20136
20137-NEXT_PAGE(level1_fixmap_pgt)
20138+NEXT_PAGE(level1_vsyscall_pgt)
20139 .fill 512,8,0
20140
20141-NEXT_PAGE(level2_ident_pgt)
20142- /* Since I easily can, map the first 1G.
20143+ /* Since I easily can, map the first 2G.
20144 * Don't set NX because code runs from these pages.
20145 */
20146- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
20147+NEXT_PAGE(level2_ident_pgt)
20148+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
20149
20150 NEXT_PAGE(level2_kernel_pgt)
20151 /*
20152@@ -439,37 +479,59 @@ NEXT_PAGE(level2_kernel_pgt)
20153 * If you want to increase this then increase MODULES_VADDR
20154 * too.)
20155 */
20156- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
20157- KERNEL_IMAGE_SIZE/PMD_SIZE)
20158-
20159-NEXT_PAGE(level2_spare_pgt)
20160- .fill 512, 8, 0
20161+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
20162
20163 #undef PMDS
20164 #undef NEXT_PAGE
20165
20166- .data
20167+ .align PAGE_SIZE
20168+ENTRY(cpu_gdt_table)
20169+ .rept NR_CPUS
20170+ .quad 0x0000000000000000 /* NULL descriptor */
20171+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
20172+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
20173+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
20174+ .quad 0x00cffb000000ffff /* __USER32_CS */
20175+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
20176+ .quad 0x00affb000000ffff /* __USER_CS */
20177+
20178+#ifdef CONFIG_PAX_KERNEXEC
20179+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
20180+#else
20181+ .quad 0x0 /* unused */
20182+#endif
20183+
20184+ .quad 0,0 /* TSS */
20185+ .quad 0,0 /* LDT */
20186+ .quad 0,0,0 /* three TLS descriptors */
20187+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
20188+ /* asm/segment.h:GDT_ENTRIES must match this */
20189+
20190+ /* zero the remaining page */
20191+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
20192+ .endr
20193+
20194 .align 16
20195 .globl early_gdt_descr
20196 early_gdt_descr:
20197 .word GDT_ENTRIES*8-1
20198 early_gdt_descr_base:
20199- .quad INIT_PER_CPU_VAR(gdt_page)
20200+ .quad cpu_gdt_table
20201
20202 ENTRY(phys_base)
20203 /* This must match the first entry in level2_kernel_pgt */
20204 .quad 0x0000000000000000
20205
20206 #include "../../x86/xen/xen-head.S"
20207-
20208- .section .bss, "aw", @nobits
20209+
20210+ .section .rodata,"a",@progbits
20211 .align L1_CACHE_BYTES
20212 ENTRY(idt_table)
20213- .skip IDT_ENTRIES * 16
20214+ .fill 512,8,0
20215
20216 .align L1_CACHE_BYTES
20217 ENTRY(nmi_idt_table)
20218- .skip IDT_ENTRIES * 16
20219+ .fill 512,8,0
20220
20221 __PAGE_ALIGNED_BSS
20222 .align PAGE_SIZE
20223diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
20224index 9c3bd4a..e1d9b35 100644
20225--- a/arch/x86/kernel/i386_ksyms_32.c
20226+++ b/arch/x86/kernel/i386_ksyms_32.c
20227@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
20228 EXPORT_SYMBOL(cmpxchg8b_emu);
20229 #endif
20230
20231+EXPORT_SYMBOL_GPL(cpu_gdt_table);
20232+
20233 /* Networking helper routines. */
20234 EXPORT_SYMBOL(csum_partial_copy_generic);
20235+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
20236+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
20237
20238 EXPORT_SYMBOL(__get_user_1);
20239 EXPORT_SYMBOL(__get_user_2);
20240@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
20241
20242 EXPORT_SYMBOL(csum_partial);
20243 EXPORT_SYMBOL(empty_zero_page);
20244+
20245+#ifdef CONFIG_PAX_KERNEXEC
20246+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
20247+#endif
20248diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
20249index 245a71d..89d9ce4 100644
20250--- a/arch/x86/kernel/i387.c
20251+++ b/arch/x86/kernel/i387.c
20252@@ -55,7 +55,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
20253 static inline bool interrupted_user_mode(void)
20254 {
20255 struct pt_regs *regs = get_irq_regs();
20256- return regs && user_mode_vm(regs);
20257+ return regs && user_mode(regs);
20258 }
20259
20260 /*
20261diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
20262index 9a5c460..dc4374d 100644
20263--- a/arch/x86/kernel/i8259.c
20264+++ b/arch/x86/kernel/i8259.c
20265@@ -209,7 +209,7 @@ spurious_8259A_irq:
20266 "spurious 8259A interrupt: IRQ%d.\n", irq);
20267 spurious_irq_mask |= irqmask;
20268 }
20269- atomic_inc(&irq_err_count);
20270+ atomic_inc_unchecked(&irq_err_count);
20271 /*
20272 * Theoretically we do not have to handle this IRQ,
20273 * but in Linux this does not cause problems and is
20274diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
20275index 8c96897..be66bfa 100644
20276--- a/arch/x86/kernel/ioport.c
20277+++ b/arch/x86/kernel/ioport.c
20278@@ -6,6 +6,7 @@
20279 #include <linux/sched.h>
20280 #include <linux/kernel.h>
20281 #include <linux/capability.h>
20282+#include <linux/security.h>
20283 #include <linux/errno.h>
20284 #include <linux/types.h>
20285 #include <linux/ioport.h>
20286@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20287
20288 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
20289 return -EINVAL;
20290+#ifdef CONFIG_GRKERNSEC_IO
20291+ if (turn_on && grsec_disable_privio) {
20292+ gr_handle_ioperm();
20293+ return -EPERM;
20294+ }
20295+#endif
20296 if (turn_on && !capable(CAP_SYS_RAWIO))
20297 return -EPERM;
20298
20299@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20300 * because the ->io_bitmap_max value must match the bitmap
20301 * contents:
20302 */
20303- tss = &per_cpu(init_tss, get_cpu());
20304+ tss = init_tss + get_cpu();
20305
20306 if (turn_on)
20307 bitmap_clear(t->io_bitmap_ptr, from, num);
20308@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
20309 return -EINVAL;
20310 /* Trying to gain more privileges? */
20311 if (level > old) {
20312+#ifdef CONFIG_GRKERNSEC_IO
20313+ if (grsec_disable_privio) {
20314+ gr_handle_iopl();
20315+ return -EPERM;
20316+ }
20317+#endif
20318 if (!capable(CAP_SYS_RAWIO))
20319 return -EPERM;
20320 }
20321diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
20322index e4595f1..ee3bfb8 100644
20323--- a/arch/x86/kernel/irq.c
20324+++ b/arch/x86/kernel/irq.c
20325@@ -18,7 +18,7 @@
20326 #include <asm/mce.h>
20327 #include <asm/hw_irq.h>
20328
20329-atomic_t irq_err_count;
20330+atomic_unchecked_t irq_err_count;
20331
20332 /* Function pointer for generic interrupt vector handling */
20333 void (*x86_platform_ipi_callback)(void) = NULL;
20334@@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
20335 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
20336 seq_printf(p, " Machine check polls\n");
20337 #endif
20338- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
20339+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
20340 #if defined(CONFIG_X86_IO_APIC)
20341- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
20342+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
20343 #endif
20344 return 0;
20345 }
20346@@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
20347
20348 u64 arch_irq_stat(void)
20349 {
20350- u64 sum = atomic_read(&irq_err_count);
20351+ u64 sum = atomic_read_unchecked(&irq_err_count);
20352
20353 #ifdef CONFIG_X86_IO_APIC
20354- sum += atomic_read(&irq_mis_count);
20355+ sum += atomic_read_unchecked(&irq_mis_count);
20356 #endif
20357 return sum;
20358 }
20359diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
20360index 344faf8..355f60d 100644
20361--- a/arch/x86/kernel/irq_32.c
20362+++ b/arch/x86/kernel/irq_32.c
20363@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
20364 __asm__ __volatile__("andl %%esp,%0" :
20365 "=r" (sp) : "0" (THREAD_SIZE - 1));
20366
20367- return sp < (sizeof(struct thread_info) + STACK_WARN);
20368+ return sp < STACK_WARN;
20369 }
20370
20371 static void print_stack_overflow(void)
20372@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
20373 * per-CPU IRQ handling contexts (thread information and stack)
20374 */
20375 union irq_ctx {
20376- struct thread_info tinfo;
20377- u32 stack[THREAD_SIZE/sizeof(u32)];
20378+ unsigned long previous_esp;
20379+ u32 stack[THREAD_SIZE/sizeof(u32)];
20380 } __attribute__((aligned(THREAD_SIZE)));
20381
20382 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
20383@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
20384 static inline int
20385 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20386 {
20387- union irq_ctx *curctx, *irqctx;
20388+ union irq_ctx *irqctx;
20389 u32 *isp, arg1, arg2;
20390
20391- curctx = (union irq_ctx *) current_thread_info();
20392 irqctx = __this_cpu_read(hardirq_ctx);
20393
20394 /*
20395@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20396 * handler) we can't do that and just have to keep using the
20397 * current stack (which is the irq stack already after all)
20398 */
20399- if (unlikely(curctx == irqctx))
20400+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
20401 return 0;
20402
20403 /* build the stack frame on the IRQ stack */
20404- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
20405- irqctx->tinfo.task = curctx->tinfo.task;
20406- irqctx->tinfo.previous_esp = current_stack_pointer;
20407+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
20408+ irqctx->previous_esp = current_stack_pointer;
20409
20410- /* Copy the preempt_count so that the [soft]irq checks work. */
20411- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
20412+#ifdef CONFIG_PAX_MEMORY_UDEREF
20413+ __set_fs(MAKE_MM_SEG(0));
20414+#endif
20415
20416 if (unlikely(overflow))
20417 call_on_stack(print_stack_overflow, isp);
20418@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20419 : "0" (irq), "1" (desc), "2" (isp),
20420 "D" (desc->handle_irq)
20421 : "memory", "cc", "ecx");
20422+
20423+#ifdef CONFIG_PAX_MEMORY_UDEREF
20424+ __set_fs(current_thread_info()->addr_limit);
20425+#endif
20426+
20427 return 1;
20428 }
20429
20430@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20431 */
20432 void __cpuinit irq_ctx_init(int cpu)
20433 {
20434- union irq_ctx *irqctx;
20435-
20436 if (per_cpu(hardirq_ctx, cpu))
20437 return;
20438
20439- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
20440- THREADINFO_GFP,
20441- THREAD_SIZE_ORDER));
20442- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
20443- irqctx->tinfo.cpu = cpu;
20444- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
20445- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
20446-
20447- per_cpu(hardirq_ctx, cpu) = irqctx;
20448-
20449- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
20450- THREADINFO_GFP,
20451- THREAD_SIZE_ORDER));
20452- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
20453- irqctx->tinfo.cpu = cpu;
20454- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
20455-
20456- per_cpu(softirq_ctx, cpu) = irqctx;
20457+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
20458+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
20459+
20460+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
20461+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
20462
20463 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
20464 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
20465@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
20466 asmlinkage void do_softirq(void)
20467 {
20468 unsigned long flags;
20469- struct thread_info *curctx;
20470 union irq_ctx *irqctx;
20471 u32 *isp;
20472
20473@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
20474 local_irq_save(flags);
20475
20476 if (local_softirq_pending()) {
20477- curctx = current_thread_info();
20478 irqctx = __this_cpu_read(softirq_ctx);
20479- irqctx->tinfo.task = curctx->task;
20480- irqctx->tinfo.previous_esp = current_stack_pointer;
20481+ irqctx->previous_esp = current_stack_pointer;
20482
20483 /* build the stack frame on the softirq stack */
20484- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
20485+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
20486+
20487+#ifdef CONFIG_PAX_MEMORY_UDEREF
20488+ __set_fs(MAKE_MM_SEG(0));
20489+#endif
20490
20491 call_on_stack(__do_softirq, isp);
20492+
20493+#ifdef CONFIG_PAX_MEMORY_UDEREF
20494+ __set_fs(current_thread_info()->addr_limit);
20495+#endif
20496+
20497 /*
20498 * Shouldn't happen, we returned above if in_interrupt():
20499 */
20500@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
20501 if (unlikely(!desc))
20502 return false;
20503
20504- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
20505+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
20506 if (unlikely(overflow))
20507 print_stack_overflow();
20508 desc->handle_irq(irq, desc);
20509diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
20510index d04d3ec..ea4b374 100644
20511--- a/arch/x86/kernel/irq_64.c
20512+++ b/arch/x86/kernel/irq_64.c
20513@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
20514 u64 estack_top, estack_bottom;
20515 u64 curbase = (u64)task_stack_page(current);
20516
20517- if (user_mode_vm(regs))
20518+ if (user_mode(regs))
20519 return;
20520
20521 if (regs->sp >= curbase + sizeof(struct thread_info) +
20522diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
20523index dc1404b..bbc43e7 100644
20524--- a/arch/x86/kernel/kdebugfs.c
20525+++ b/arch/x86/kernel/kdebugfs.c
20526@@ -27,7 +27,7 @@ struct setup_data_node {
20527 u32 len;
20528 };
20529
20530-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
20531+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
20532 size_t count, loff_t *ppos)
20533 {
20534 struct setup_data_node *node = file->private_data;
20535diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
20536index 836f832..a8bda67 100644
20537--- a/arch/x86/kernel/kgdb.c
20538+++ b/arch/x86/kernel/kgdb.c
20539@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
20540 #ifdef CONFIG_X86_32
20541 switch (regno) {
20542 case GDB_SS:
20543- if (!user_mode_vm(regs))
20544+ if (!user_mode(regs))
20545 *(unsigned long *)mem = __KERNEL_DS;
20546 break;
20547 case GDB_SP:
20548- if (!user_mode_vm(regs))
20549+ if (!user_mode(regs))
20550 *(unsigned long *)mem = kernel_stack_pointer(regs);
20551 break;
20552 case GDB_GS:
20553@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
20554 bp->attr.bp_addr = breakinfo[breakno].addr;
20555 bp->attr.bp_len = breakinfo[breakno].len;
20556 bp->attr.bp_type = breakinfo[breakno].type;
20557- info->address = breakinfo[breakno].addr;
20558+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
20559+ info->address = ktla_ktva(breakinfo[breakno].addr);
20560+ else
20561+ info->address = breakinfo[breakno].addr;
20562 info->len = breakinfo[breakno].len;
20563 info->type = breakinfo[breakno].type;
20564 val = arch_install_hw_breakpoint(bp);
20565@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
20566 case 'k':
20567 /* clear the trace bit */
20568 linux_regs->flags &= ~X86_EFLAGS_TF;
20569- atomic_set(&kgdb_cpu_doing_single_step, -1);
20570+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
20571
20572 /* set the trace bit if we're stepping */
20573 if (remcomInBuffer[0] == 's') {
20574 linux_regs->flags |= X86_EFLAGS_TF;
20575- atomic_set(&kgdb_cpu_doing_single_step,
20576+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
20577 raw_smp_processor_id());
20578 }
20579
20580@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
20581
20582 switch (cmd) {
20583 case DIE_DEBUG:
20584- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
20585+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
20586 if (user_mode(regs))
20587 return single_step_cont(regs, args);
20588 break;
20589@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
20590 #endif /* CONFIG_DEBUG_RODATA */
20591
20592 bpt->type = BP_BREAKPOINT;
20593- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
20594+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
20595 BREAK_INSTR_SIZE);
20596 if (err)
20597 return err;
20598- err = probe_kernel_write((char *)bpt->bpt_addr,
20599+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
20600 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
20601 #ifdef CONFIG_DEBUG_RODATA
20602 if (!err)
20603@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
20604 return -EBUSY;
20605 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
20606 BREAK_INSTR_SIZE);
20607- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
20608+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
20609 if (err)
20610 return err;
20611 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
20612@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
20613 if (mutex_is_locked(&text_mutex))
20614 goto knl_write;
20615 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
20616- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
20617+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
20618 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
20619 goto knl_write;
20620 return err;
20621 knl_write:
20622 #endif /* CONFIG_DEBUG_RODATA */
20623- return probe_kernel_write((char *)bpt->bpt_addr,
20624+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
20625 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
20626 }
20627
20628diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
20629index c5e410e..ed5a7f0 100644
20630--- a/arch/x86/kernel/kprobes-opt.c
20631+++ b/arch/x86/kernel/kprobes-opt.c
20632@@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
20633 * Verify if the address gap is in 2GB range, because this uses
20634 * a relative jump.
20635 */
20636- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
20637+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
20638 if (abs(rel) > 0x7fffffff)
20639 return -ERANGE;
20640
20641@@ -353,16 +353,16 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
20642 op->optinsn.size = ret;
20643
20644 /* Copy arch-dep-instance from template */
20645- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
20646+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
20647
20648 /* Set probe information */
20649 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
20650
20651 /* Set probe function call */
20652- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
20653+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
20654
20655 /* Set returning jmp instruction at the tail of out-of-line buffer */
20656- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
20657+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
20658 (u8 *)op->kp.addr + op->optinsn.size);
20659
20660 flush_icache_range((unsigned long) buf,
20661@@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
20662 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
20663
20664 /* Backup instructions which will be replaced by jump address */
20665- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
20666+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
20667 RELATIVE_ADDR_SIZE);
20668
20669 insn_buf[0] = RELATIVEJUMP_OPCODE;
20670@@ -483,7 +483,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
20671 /* This kprobe is really able to run optimized path. */
20672 op = container_of(p, struct optimized_kprobe, kp);
20673 /* Detour through copied instructions */
20674- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
20675+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
20676 if (!reenter)
20677 reset_current_kprobe();
20678 preempt_enable_no_resched();
20679diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
20680index 57916c0..9e0b9d0 100644
20681--- a/arch/x86/kernel/kprobes.c
20682+++ b/arch/x86/kernel/kprobes.c
20683@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
20684 s32 raddr;
20685 } __attribute__((packed)) *insn;
20686
20687- insn = (struct __arch_relative_insn *)from;
20688+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
20689+
20690+ pax_open_kernel();
20691 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
20692 insn->op = op;
20693+ pax_close_kernel();
20694 }
20695
20696 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
20697@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
20698 kprobe_opcode_t opcode;
20699 kprobe_opcode_t *orig_opcodes = opcodes;
20700
20701- if (search_exception_tables((unsigned long)opcodes))
20702+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
20703 return 0; /* Page fault may occur on this address. */
20704
20705 retry:
20706@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
20707 * for the first byte, we can recover the original instruction
20708 * from it and kp->opcode.
20709 */
20710- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
20711+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
20712 buf[0] = kp->opcode;
20713- return (unsigned long)buf;
20714+ return ktva_ktla((unsigned long)buf);
20715 }
20716
20717 /*
20718@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
20719 /* Another subsystem puts a breakpoint, failed to recover */
20720 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
20721 return 0;
20722+ pax_open_kernel();
20723 memcpy(dest, insn.kaddr, insn.length);
20724+ pax_close_kernel();
20725
20726 #ifdef CONFIG_X86_64
20727 if (insn_rip_relative(&insn)) {
20728@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
20729 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
20730 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
20731 disp = (u8 *) dest + insn_offset_displacement(&insn);
20732+ pax_open_kernel();
20733 *(s32 *) disp = (s32) newdisp;
20734+ pax_close_kernel();
20735 }
20736 #endif
20737 return insn.length;
20738@@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
20739 * nor set current_kprobe, because it doesn't use single
20740 * stepping.
20741 */
20742- regs->ip = (unsigned long)p->ainsn.insn;
20743+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
20744 preempt_enable_no_resched();
20745 return;
20746 }
20747@@ -502,9 +509,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
20748 regs->flags &= ~X86_EFLAGS_IF;
20749 /* single step inline if the instruction is an int3 */
20750 if (p->opcode == BREAKPOINT_INSTRUCTION)
20751- regs->ip = (unsigned long)p->addr;
20752+ regs->ip = ktla_ktva((unsigned long)p->addr);
20753 else
20754- regs->ip = (unsigned long)p->ainsn.insn;
20755+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
20756 }
20757
20758 /*
20759@@ -600,7 +607,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
20760 setup_singlestep(p, regs, kcb, 0);
20761 return 1;
20762 }
20763- } else if (*addr != BREAKPOINT_INSTRUCTION) {
20764+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
20765 /*
20766 * The breakpoint instruction was removed right
20767 * after we hit it. Another cpu has removed
20768@@ -651,6 +658,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
20769 " movq %rax, 152(%rsp)\n"
20770 RESTORE_REGS_STRING
20771 " popfq\n"
20772+#ifdef KERNEXEC_PLUGIN
20773+ " btsq $63,(%rsp)\n"
20774+#endif
20775 #else
20776 " pushf\n"
20777 SAVE_REGS_STRING
20778@@ -788,7 +798,7 @@ static void __kprobes
20779 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
20780 {
20781 unsigned long *tos = stack_addr(regs);
20782- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
20783+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
20784 unsigned long orig_ip = (unsigned long)p->addr;
20785 kprobe_opcode_t *insn = p->ainsn.insn;
20786
20787@@ -970,7 +980,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
20788 struct die_args *args = data;
20789 int ret = NOTIFY_DONE;
20790
20791- if (args->regs && user_mode_vm(args->regs))
20792+ if (args->regs && user_mode(args->regs))
20793 return ret;
20794
20795 switch (val) {
20796diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
20797index 9c2bd8b..bb1131c 100644
20798--- a/arch/x86/kernel/kvm.c
20799+++ b/arch/x86/kernel/kvm.c
20800@@ -452,7 +452,7 @@ static int __cpuinit kvm_cpu_notify(struct notifier_block *self,
20801 return NOTIFY_OK;
20802 }
20803
20804-static struct notifier_block __cpuinitdata kvm_cpu_notifier = {
20805+static struct notifier_block kvm_cpu_notifier = {
20806 .notifier_call = kvm_cpu_notify,
20807 };
20808 #endif
20809diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
20810index ebc9873..1b9724b 100644
20811--- a/arch/x86/kernel/ldt.c
20812+++ b/arch/x86/kernel/ldt.c
20813@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
20814 if (reload) {
20815 #ifdef CONFIG_SMP
20816 preempt_disable();
20817- load_LDT(pc);
20818+ load_LDT_nolock(pc);
20819 if (!cpumask_equal(mm_cpumask(current->mm),
20820 cpumask_of(smp_processor_id())))
20821 smp_call_function(flush_ldt, current->mm, 1);
20822 preempt_enable();
20823 #else
20824- load_LDT(pc);
20825+ load_LDT_nolock(pc);
20826 #endif
20827 }
20828 if (oldsize) {
20829@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
20830 return err;
20831
20832 for (i = 0; i < old->size; i++)
20833- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
20834+ write_ldt_entry(new->ldt, i, old->ldt + i);
20835 return 0;
20836 }
20837
20838@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
20839 retval = copy_ldt(&mm->context, &old_mm->context);
20840 mutex_unlock(&old_mm->context.lock);
20841 }
20842+
20843+ if (tsk == current) {
20844+ mm->context.vdso = 0;
20845+
20846+#ifdef CONFIG_X86_32
20847+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
20848+ mm->context.user_cs_base = 0UL;
20849+ mm->context.user_cs_limit = ~0UL;
20850+
20851+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
20852+ cpus_clear(mm->context.cpu_user_cs_mask);
20853+#endif
20854+
20855+#endif
20856+#endif
20857+
20858+ }
20859+
20860 return retval;
20861 }
20862
20863@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
20864 }
20865 }
20866
20867+#ifdef CONFIG_PAX_SEGMEXEC
20868+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
20869+ error = -EINVAL;
20870+ goto out_unlock;
20871+ }
20872+#endif
20873+
20874 fill_ldt(&ldt, &ldt_info);
20875 if (oldmode)
20876 ldt.avl = 0;
20877diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
20878index 5b19e4d..6476a76 100644
20879--- a/arch/x86/kernel/machine_kexec_32.c
20880+++ b/arch/x86/kernel/machine_kexec_32.c
20881@@ -26,7 +26,7 @@
20882 #include <asm/cacheflush.h>
20883 #include <asm/debugreg.h>
20884
20885-static void set_idt(void *newidt, __u16 limit)
20886+static void set_idt(struct desc_struct *newidt, __u16 limit)
20887 {
20888 struct desc_ptr curidt;
20889
20890@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
20891 }
20892
20893
20894-static void set_gdt(void *newgdt, __u16 limit)
20895+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
20896 {
20897 struct desc_ptr curgdt;
20898
20899@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
20900 }
20901
20902 control_page = page_address(image->control_code_page);
20903- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
20904+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
20905
20906 relocate_kernel_ptr = control_page;
20907 page_list[PA_CONTROL_PAGE] = __pa(control_page);
20908diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
20909index 3a04b22..1d2eb09 100644
20910--- a/arch/x86/kernel/microcode_core.c
20911+++ b/arch/x86/kernel/microcode_core.c
20912@@ -512,7 +512,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
20913 return NOTIFY_OK;
20914 }
20915
20916-static struct notifier_block __refdata mc_cpu_notifier = {
20917+static struct notifier_block mc_cpu_notifier = {
20918 .notifier_call = mc_cpu_callback,
20919 };
20920
20921diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
20922index 3544aed..01ddc1c 100644
20923--- a/arch/x86/kernel/microcode_intel.c
20924+++ b/arch/x86/kernel/microcode_intel.c
20925@@ -431,13 +431,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
20926
20927 static int get_ucode_user(void *to, const void *from, size_t n)
20928 {
20929- return copy_from_user(to, from, n);
20930+ return copy_from_user(to, (const void __force_user *)from, n);
20931 }
20932
20933 static enum ucode_state
20934 request_microcode_user(int cpu, const void __user *buf, size_t size)
20935 {
20936- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
20937+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
20938 }
20939
20940 static void microcode_fini_cpu(int cpu)
20941diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
20942index 216a4d7..228255a 100644
20943--- a/arch/x86/kernel/module.c
20944+++ b/arch/x86/kernel/module.c
20945@@ -43,15 +43,60 @@ do { \
20946 } while (0)
20947 #endif
20948
20949-void *module_alloc(unsigned long size)
20950+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
20951 {
20952- if (PAGE_ALIGN(size) > MODULES_LEN)
20953+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
20954 return NULL;
20955 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
20956- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
20957+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
20958 -1, __builtin_return_address(0));
20959 }
20960
20961+void *module_alloc(unsigned long size)
20962+{
20963+
20964+#ifdef CONFIG_PAX_KERNEXEC
20965+ return __module_alloc(size, PAGE_KERNEL);
20966+#else
20967+ return __module_alloc(size, PAGE_KERNEL_EXEC);
20968+#endif
20969+
20970+}
20971+
20972+#ifdef CONFIG_PAX_KERNEXEC
20973+#ifdef CONFIG_X86_32
20974+void *module_alloc_exec(unsigned long size)
20975+{
20976+ struct vm_struct *area;
20977+
20978+ if (size == 0)
20979+ return NULL;
20980+
20981+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
20982+ return area ? area->addr : NULL;
20983+}
20984+EXPORT_SYMBOL(module_alloc_exec);
20985+
20986+void module_free_exec(struct module *mod, void *module_region)
20987+{
20988+ vunmap(module_region);
20989+}
20990+EXPORT_SYMBOL(module_free_exec);
20991+#else
20992+void module_free_exec(struct module *mod, void *module_region)
20993+{
20994+ module_free(mod, module_region);
20995+}
20996+EXPORT_SYMBOL(module_free_exec);
20997+
20998+void *module_alloc_exec(unsigned long size)
20999+{
21000+ return __module_alloc(size, PAGE_KERNEL_RX);
21001+}
21002+EXPORT_SYMBOL(module_alloc_exec);
21003+#endif
21004+#endif
21005+
21006 #ifdef CONFIG_X86_32
21007 int apply_relocate(Elf32_Shdr *sechdrs,
21008 const char *strtab,
21009@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21010 unsigned int i;
21011 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
21012 Elf32_Sym *sym;
21013- uint32_t *location;
21014+ uint32_t *plocation, location;
21015
21016 DEBUGP("Applying relocate section %u to %u\n",
21017 relsec, sechdrs[relsec].sh_info);
21018 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
21019 /* This is where to make the change */
21020- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
21021- + rel[i].r_offset;
21022+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
21023+ location = (uint32_t)plocation;
21024+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
21025+ plocation = ktla_ktva((void *)plocation);
21026 /* This is the symbol it is referring to. Note that all
21027 undefined symbols have been resolved. */
21028 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
21029@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21030 switch (ELF32_R_TYPE(rel[i].r_info)) {
21031 case R_386_32:
21032 /* We add the value into the location given */
21033- *location += sym->st_value;
21034+ pax_open_kernel();
21035+ *plocation += sym->st_value;
21036+ pax_close_kernel();
21037 break;
21038 case R_386_PC32:
21039 /* Add the value, subtract its position */
21040- *location += sym->st_value - (uint32_t)location;
21041+ pax_open_kernel();
21042+ *plocation += sym->st_value - location;
21043+ pax_close_kernel();
21044 break;
21045 default:
21046 pr_err("%s: Unknown relocation: %u\n",
21047@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
21048 case R_X86_64_NONE:
21049 break;
21050 case R_X86_64_64:
21051+ pax_open_kernel();
21052 *(u64 *)loc = val;
21053+ pax_close_kernel();
21054 break;
21055 case R_X86_64_32:
21056+ pax_open_kernel();
21057 *(u32 *)loc = val;
21058+ pax_close_kernel();
21059 if (val != *(u32 *)loc)
21060 goto overflow;
21061 break;
21062 case R_X86_64_32S:
21063+ pax_open_kernel();
21064 *(s32 *)loc = val;
21065+ pax_close_kernel();
21066 if ((s64)val != *(s32 *)loc)
21067 goto overflow;
21068 break;
21069 case R_X86_64_PC32:
21070 val -= (u64)loc;
21071+ pax_open_kernel();
21072 *(u32 *)loc = val;
21073+ pax_close_kernel();
21074+
21075 #if 0
21076 if ((s64)val != *(s32 *)loc)
21077 goto overflow;
21078diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
21079index 4929502..686c291 100644
21080--- a/arch/x86/kernel/msr.c
21081+++ b/arch/x86/kernel/msr.c
21082@@ -234,7 +234,7 @@ static int __cpuinit msr_class_cpu_callback(struct notifier_block *nfb,
21083 return notifier_from_errno(err);
21084 }
21085
21086-static struct notifier_block __refdata msr_class_cpu_notifier = {
21087+static struct notifier_block msr_class_cpu_notifier = {
21088 .notifier_call = msr_class_cpu_callback,
21089 };
21090
21091diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
21092index f84f5c5..e27e54b 100644
21093--- a/arch/x86/kernel/nmi.c
21094+++ b/arch/x86/kernel/nmi.c
21095@@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
21096 dotraplinkage notrace __kprobes void
21097 do_nmi(struct pt_regs *regs, long error_code)
21098 {
21099+
21100+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21101+ if (!user_mode(regs)) {
21102+ unsigned long cs = regs->cs & 0xFFFF;
21103+ unsigned long ip = ktva_ktla(regs->ip);
21104+
21105+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
21106+ regs->ip = ip;
21107+ }
21108+#endif
21109+
21110 nmi_nesting_preprocess(regs);
21111
21112 nmi_enter();
21113diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
21114index 676b8c7..870ba04 100644
21115--- a/arch/x86/kernel/paravirt-spinlocks.c
21116+++ b/arch/x86/kernel/paravirt-spinlocks.c
21117@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
21118 arch_spin_lock(lock);
21119 }
21120
21121-struct pv_lock_ops pv_lock_ops = {
21122+struct pv_lock_ops pv_lock_ops __read_only = {
21123 #ifdef CONFIG_SMP
21124 .spin_is_locked = __ticket_spin_is_locked,
21125 .spin_is_contended = __ticket_spin_is_contended,
21126diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
21127index 17fff18..5cfa0f4 100644
21128--- a/arch/x86/kernel/paravirt.c
21129+++ b/arch/x86/kernel/paravirt.c
21130@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
21131 {
21132 return x;
21133 }
21134+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21135+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
21136+#endif
21137
21138 void __init default_banner(void)
21139 {
21140@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
21141 if (opfunc == NULL)
21142 /* If there's no function, patch it with a ud2a (BUG) */
21143 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
21144- else if (opfunc == _paravirt_nop)
21145+ else if (opfunc == (void *)_paravirt_nop)
21146 /* If the operation is a nop, then nop the callsite */
21147 ret = paravirt_patch_nop();
21148
21149 /* identity functions just return their single argument */
21150- else if (opfunc == _paravirt_ident_32)
21151+ else if (opfunc == (void *)_paravirt_ident_32)
21152 ret = paravirt_patch_ident_32(insnbuf, len);
21153- else if (opfunc == _paravirt_ident_64)
21154+ else if (opfunc == (void *)_paravirt_ident_64)
21155 ret = paravirt_patch_ident_64(insnbuf, len);
21156+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21157+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
21158+ ret = paravirt_patch_ident_64(insnbuf, len);
21159+#endif
21160
21161 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
21162 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
21163@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
21164 if (insn_len > len || start == NULL)
21165 insn_len = len;
21166 else
21167- memcpy(insnbuf, start, insn_len);
21168+ memcpy(insnbuf, ktla_ktva(start), insn_len);
21169
21170 return insn_len;
21171 }
21172@@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
21173 preempt_enable();
21174 }
21175
21176-struct pv_info pv_info = {
21177+struct pv_info pv_info __read_only = {
21178 .name = "bare hardware",
21179 .paravirt_enabled = 0,
21180 .kernel_rpl = 0,
21181@@ -315,16 +322,16 @@ struct pv_info pv_info = {
21182 #endif
21183 };
21184
21185-struct pv_init_ops pv_init_ops = {
21186+struct pv_init_ops pv_init_ops __read_only = {
21187 .patch = native_patch,
21188 };
21189
21190-struct pv_time_ops pv_time_ops = {
21191+struct pv_time_ops pv_time_ops __read_only = {
21192 .sched_clock = native_sched_clock,
21193 .steal_clock = native_steal_clock,
21194 };
21195
21196-struct pv_irq_ops pv_irq_ops = {
21197+struct pv_irq_ops pv_irq_ops __read_only = {
21198 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
21199 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
21200 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
21201@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
21202 #endif
21203 };
21204
21205-struct pv_cpu_ops pv_cpu_ops = {
21206+struct pv_cpu_ops pv_cpu_ops __read_only = {
21207 .cpuid = native_cpuid,
21208 .get_debugreg = native_get_debugreg,
21209 .set_debugreg = native_set_debugreg,
21210@@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
21211 .end_context_switch = paravirt_nop,
21212 };
21213
21214-struct pv_apic_ops pv_apic_ops = {
21215+struct pv_apic_ops pv_apic_ops __read_only= {
21216 #ifdef CONFIG_X86_LOCAL_APIC
21217 .startup_ipi_hook = paravirt_nop,
21218 #endif
21219 };
21220
21221-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
21222+#ifdef CONFIG_X86_32
21223+#ifdef CONFIG_X86_PAE
21224+/* 64-bit pagetable entries */
21225+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
21226+#else
21227 /* 32-bit pagetable entries */
21228 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
21229+#endif
21230 #else
21231 /* 64-bit pagetable entries */
21232 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
21233 #endif
21234
21235-struct pv_mmu_ops pv_mmu_ops = {
21236+struct pv_mmu_ops pv_mmu_ops __read_only = {
21237
21238 .read_cr2 = native_read_cr2,
21239 .write_cr2 = native_write_cr2,
21240@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
21241 .make_pud = PTE_IDENT,
21242
21243 .set_pgd = native_set_pgd,
21244+ .set_pgd_batched = native_set_pgd_batched,
21245 #endif
21246 #endif /* PAGETABLE_LEVELS >= 3 */
21247
21248@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
21249 },
21250
21251 .set_fixmap = native_set_fixmap,
21252+
21253+#ifdef CONFIG_PAX_KERNEXEC
21254+ .pax_open_kernel = native_pax_open_kernel,
21255+ .pax_close_kernel = native_pax_close_kernel,
21256+#endif
21257+
21258 };
21259
21260 EXPORT_SYMBOL_GPL(pv_time_ops);
21261diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
21262index 35ccf75..7a15747 100644
21263--- a/arch/x86/kernel/pci-iommu_table.c
21264+++ b/arch/x86/kernel/pci-iommu_table.c
21265@@ -2,7 +2,7 @@
21266 #include <asm/iommu_table.h>
21267 #include <linux/string.h>
21268 #include <linux/kallsyms.h>
21269-
21270+#include <linux/sched.h>
21271
21272 #define DEBUG 1
21273
21274diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
21275index 2ed787f..f70c9f6 100644
21276--- a/arch/x86/kernel/process.c
21277+++ b/arch/x86/kernel/process.c
21278@@ -36,7 +36,8 @@
21279 * section. Since TSS's are completely CPU-local, we want them
21280 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
21281 */
21282-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
21283+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
21284+EXPORT_SYMBOL(init_tss);
21285
21286 #ifdef CONFIG_X86_64
21287 static DEFINE_PER_CPU(unsigned char, is_idle);
21288@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
21289 task_xstate_cachep =
21290 kmem_cache_create("task_xstate", xstate_size,
21291 __alignof__(union thread_xstate),
21292- SLAB_PANIC | SLAB_NOTRACK, NULL);
21293+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
21294 }
21295
21296 /*
21297@@ -105,7 +106,7 @@ void exit_thread(void)
21298 unsigned long *bp = t->io_bitmap_ptr;
21299
21300 if (bp) {
21301- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
21302+ struct tss_struct *tss = init_tss + get_cpu();
21303
21304 t->io_bitmap_ptr = NULL;
21305 clear_thread_flag(TIF_IO_BITMAP);
21306@@ -136,7 +137,7 @@ void show_regs_common(void)
21307 board = dmi_get_system_info(DMI_BOARD_NAME);
21308
21309 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
21310- current->pid, current->comm, print_tainted(),
21311+ task_pid_nr(current), current->comm, print_tainted(),
21312 init_utsname()->release,
21313 (int)strcspn(init_utsname()->version, " "),
21314 init_utsname()->version,
21315@@ -149,6 +150,9 @@ void flush_thread(void)
21316 {
21317 struct task_struct *tsk = current;
21318
21319+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
21320+ loadsegment(gs, 0);
21321+#endif
21322 flush_ptrace_hw_breakpoint(tsk);
21323 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
21324 drop_init_fpu(tsk);
21325@@ -301,7 +305,7 @@ static void __exit_idle(void)
21326 void exit_idle(void)
21327 {
21328 /* idle loop has pid 0 */
21329- if (current->pid)
21330+ if (task_pid_nr(current))
21331 return;
21332 __exit_idle();
21333 }
21334@@ -404,7 +408,7 @@ bool set_pm_idle_to_default(void)
21335
21336 return ret;
21337 }
21338-void stop_this_cpu(void *dummy)
21339+__noreturn void stop_this_cpu(void *dummy)
21340 {
21341 local_irq_disable();
21342 /*
21343@@ -632,16 +636,37 @@ static int __init idle_setup(char *str)
21344 }
21345 early_param("idle", idle_setup);
21346
21347-unsigned long arch_align_stack(unsigned long sp)
21348+#ifdef CONFIG_PAX_RANDKSTACK
21349+void pax_randomize_kstack(struct pt_regs *regs)
21350 {
21351- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
21352- sp -= get_random_int() % 8192;
21353- return sp & ~0xf;
21354-}
21355+ struct thread_struct *thread = &current->thread;
21356+ unsigned long time;
21357
21358-unsigned long arch_randomize_brk(struct mm_struct *mm)
21359-{
21360- unsigned long range_end = mm->brk + 0x02000000;
21361- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
21362-}
21363+ if (!randomize_va_space)
21364+ return;
21365+
21366+ if (v8086_mode(regs))
21367+ return;
21368
21369+ rdtscl(time);
21370+
21371+ /* P4 seems to return a 0 LSB, ignore it */
21372+#ifdef CONFIG_MPENTIUM4
21373+ time &= 0x3EUL;
21374+ time <<= 2;
21375+#elif defined(CONFIG_X86_64)
21376+ time &= 0xFUL;
21377+ time <<= 4;
21378+#else
21379+ time &= 0x1FUL;
21380+ time <<= 3;
21381+#endif
21382+
21383+ thread->sp0 ^= time;
21384+ load_sp0(init_tss + smp_processor_id(), thread);
21385+
21386+#ifdef CONFIG_X86_64
21387+ this_cpu_write(kernel_stack, thread->sp0);
21388+#endif
21389+}
21390+#endif
21391diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
21392index b5a8905..d9cacac 100644
21393--- a/arch/x86/kernel/process_32.c
21394+++ b/arch/x86/kernel/process_32.c
21395@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
21396 unsigned long thread_saved_pc(struct task_struct *tsk)
21397 {
21398 return ((unsigned long *)tsk->thread.sp)[3];
21399+//XXX return tsk->thread.eip;
21400 }
21401
21402 void __show_regs(struct pt_regs *regs, int all)
21403@@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
21404 unsigned long sp;
21405 unsigned short ss, gs;
21406
21407- if (user_mode_vm(regs)) {
21408+ if (user_mode(regs)) {
21409 sp = regs->sp;
21410 ss = regs->ss & 0xffff;
21411- gs = get_user_gs(regs);
21412 } else {
21413 sp = kernel_stack_pointer(regs);
21414 savesegment(ss, ss);
21415- savesegment(gs, gs);
21416 }
21417+ gs = get_user_gs(regs);
21418
21419 show_regs_common();
21420
21421 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
21422 (u16)regs->cs, regs->ip, regs->flags,
21423- smp_processor_id());
21424+ raw_smp_processor_id());
21425 print_symbol("EIP is at %s\n", regs->ip);
21426
21427 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
21428@@ -130,20 +130,21 @@ void release_thread(struct task_struct *dead_task)
21429 int copy_thread(unsigned long clone_flags, unsigned long sp,
21430 unsigned long arg, struct task_struct *p)
21431 {
21432- struct pt_regs *childregs = task_pt_regs(p);
21433+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
21434 struct task_struct *tsk;
21435 int err;
21436
21437 p->thread.sp = (unsigned long) childregs;
21438 p->thread.sp0 = (unsigned long) (childregs+1);
21439+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
21440
21441 if (unlikely(p->flags & PF_KTHREAD)) {
21442 /* kernel thread */
21443 memset(childregs, 0, sizeof(struct pt_regs));
21444 p->thread.ip = (unsigned long) ret_from_kernel_thread;
21445- task_user_gs(p) = __KERNEL_STACK_CANARY;
21446- childregs->ds = __USER_DS;
21447- childregs->es = __USER_DS;
21448+ savesegment(gs, childregs->gs);
21449+ childregs->ds = __KERNEL_DS;
21450+ childregs->es = __KERNEL_DS;
21451 childregs->fs = __KERNEL_PERCPU;
21452 childregs->bx = sp; /* function */
21453 childregs->bp = arg;
21454@@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21455 struct thread_struct *prev = &prev_p->thread,
21456 *next = &next_p->thread;
21457 int cpu = smp_processor_id();
21458- struct tss_struct *tss = &per_cpu(init_tss, cpu);
21459+ struct tss_struct *tss = init_tss + cpu;
21460 fpu_switch_t fpu;
21461
21462 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
21463@@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21464 */
21465 lazy_save_gs(prev->gs);
21466
21467+#ifdef CONFIG_PAX_MEMORY_UDEREF
21468+ __set_fs(task_thread_info(next_p)->addr_limit);
21469+#endif
21470+
21471 /*
21472 * Load the per-thread Thread-Local Storage descriptor.
21473 */
21474@@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21475 */
21476 arch_end_context_switch(next_p);
21477
21478+ this_cpu_write(current_task, next_p);
21479+ this_cpu_write(current_tinfo, &next_p->tinfo);
21480+
21481 /*
21482 * Restore %gs if needed (which is common)
21483 */
21484@@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21485
21486 switch_fpu_finish(next_p, fpu);
21487
21488- this_cpu_write(current_task, next_p);
21489-
21490 return prev_p;
21491 }
21492
21493@@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
21494 } while (count++ < 16);
21495 return 0;
21496 }
21497-
21498diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
21499index 6e68a61..955a9a5 100644
21500--- a/arch/x86/kernel/process_64.c
21501+++ b/arch/x86/kernel/process_64.c
21502@@ -152,10 +152,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
21503 struct pt_regs *childregs;
21504 struct task_struct *me = current;
21505
21506- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
21507+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
21508 childregs = task_pt_regs(p);
21509 p->thread.sp = (unsigned long) childregs;
21510 p->thread.usersp = me->thread.usersp;
21511+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
21512 set_tsk_thread_flag(p, TIF_FORK);
21513 p->fpu_counter = 0;
21514 p->thread.io_bitmap_ptr = NULL;
21515@@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21516 struct thread_struct *prev = &prev_p->thread;
21517 struct thread_struct *next = &next_p->thread;
21518 int cpu = smp_processor_id();
21519- struct tss_struct *tss = &per_cpu(init_tss, cpu);
21520+ struct tss_struct *tss = init_tss + cpu;
21521 unsigned fsindex, gsindex;
21522 fpu_switch_t fpu;
21523
21524@@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21525 prev->usersp = this_cpu_read(old_rsp);
21526 this_cpu_write(old_rsp, next->usersp);
21527 this_cpu_write(current_task, next_p);
21528+ this_cpu_write(current_tinfo, &next_p->tinfo);
21529
21530- this_cpu_write(kernel_stack,
21531- (unsigned long)task_stack_page(next_p) +
21532- THREAD_SIZE - KERNEL_STACK_OFFSET);
21533+ this_cpu_write(kernel_stack, next->sp0);
21534
21535 /*
21536 * Now maybe reload the debug registers and handle I/O bitmaps
21537@@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
21538 if (!p || p == current || p->state == TASK_RUNNING)
21539 return 0;
21540 stack = (unsigned long)task_stack_page(p);
21541- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
21542+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
21543 return 0;
21544 fp = *(u64 *)(p->thread.sp);
21545 do {
21546- if (fp < (unsigned long)stack ||
21547- fp >= (unsigned long)stack+THREAD_SIZE)
21548+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
21549 return 0;
21550 ip = *(u64 *)(fp+8);
21551 if (!in_sched_functions(ip))
21552diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
21553index b629bbe..0fa615a 100644
21554--- a/arch/x86/kernel/ptrace.c
21555+++ b/arch/x86/kernel/ptrace.c
21556@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
21557 {
21558 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
21559 unsigned long sp = (unsigned long)&regs->sp;
21560- struct thread_info *tinfo;
21561
21562- if (context == (sp & ~(THREAD_SIZE - 1)))
21563+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
21564 return sp;
21565
21566- tinfo = (struct thread_info *)context;
21567- if (tinfo->previous_esp)
21568- return tinfo->previous_esp;
21569+ sp = *(unsigned long *)context;
21570+ if (sp)
21571+ return sp;
21572
21573 return (unsigned long)regs;
21574 }
21575@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
21576 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
21577 {
21578 int i;
21579- int dr7 = 0;
21580+ unsigned long dr7 = 0;
21581 struct arch_hw_breakpoint *info;
21582
21583 for (i = 0; i < HBP_NUM; i++) {
21584@@ -856,7 +855,7 @@ long arch_ptrace(struct task_struct *child, long request,
21585 unsigned long addr, unsigned long data)
21586 {
21587 int ret;
21588- unsigned long __user *datap = (unsigned long __user *)data;
21589+ unsigned long __user *datap = (__force unsigned long __user *)data;
21590
21591 switch (request) {
21592 /* read the word at location addr in the USER area. */
21593@@ -941,14 +940,14 @@ long arch_ptrace(struct task_struct *child, long request,
21594 if ((int) addr < 0)
21595 return -EIO;
21596 ret = do_get_thread_area(child, addr,
21597- (struct user_desc __user *)data);
21598+ (__force struct user_desc __user *) data);
21599 break;
21600
21601 case PTRACE_SET_THREAD_AREA:
21602 if ((int) addr < 0)
21603 return -EIO;
21604 ret = do_set_thread_area(child, addr,
21605- (struct user_desc __user *)data, 0);
21606+ (__force struct user_desc __user *) data, 0);
21607 break;
21608 #endif
21609
21610@@ -1326,7 +1325,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
21611
21612 #ifdef CONFIG_X86_64
21613
21614-static struct user_regset x86_64_regsets[] __read_mostly = {
21615+static user_regset_no_const x86_64_regsets[] __read_only = {
21616 [REGSET_GENERAL] = {
21617 .core_note_type = NT_PRSTATUS,
21618 .n = sizeof(struct user_regs_struct) / sizeof(long),
21619@@ -1367,7 +1366,7 @@ static const struct user_regset_view user_x86_64_view = {
21620 #endif /* CONFIG_X86_64 */
21621
21622 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
21623-static struct user_regset x86_32_regsets[] __read_mostly = {
21624+static user_regset_no_const x86_32_regsets[] __read_only = {
21625 [REGSET_GENERAL] = {
21626 .core_note_type = NT_PRSTATUS,
21627 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
21628@@ -1420,7 +1419,7 @@ static const struct user_regset_view user_x86_32_view = {
21629 */
21630 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
21631
21632-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
21633+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
21634 {
21635 #ifdef CONFIG_X86_64
21636 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
21637@@ -1455,7 +1454,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
21638 memset(info, 0, sizeof(*info));
21639 info->si_signo = SIGTRAP;
21640 info->si_code = si_code;
21641- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
21642+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
21643 }
21644
21645 void user_single_step_siginfo(struct task_struct *tsk,
21646@@ -1484,6 +1483,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
21647 # define IS_IA32 0
21648 #endif
21649
21650+#ifdef CONFIG_GRKERNSEC_SETXID
21651+extern void gr_delayed_cred_worker(void);
21652+#endif
21653+
21654 /*
21655 * We must return the syscall number to actually look up in the table.
21656 * This can be -1L to skip running any syscall at all.
21657@@ -1494,6 +1497,11 @@ long syscall_trace_enter(struct pt_regs *regs)
21658
21659 user_exit();
21660
21661+#ifdef CONFIG_GRKERNSEC_SETXID
21662+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
21663+ gr_delayed_cred_worker();
21664+#endif
21665+
21666 /*
21667 * If we stepped into a sysenter/syscall insn, it trapped in
21668 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
21669@@ -1549,6 +1557,11 @@ void syscall_trace_leave(struct pt_regs *regs)
21670 */
21671 user_exit();
21672
21673+#ifdef CONFIG_GRKERNSEC_SETXID
21674+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
21675+ gr_delayed_cred_worker();
21676+#endif
21677+
21678 audit_syscall_exit(regs);
21679
21680 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
21681diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
21682index 85c3959..76b89f9 100644
21683--- a/arch/x86/kernel/pvclock.c
21684+++ b/arch/x86/kernel/pvclock.c
21685@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
21686 return pv_tsc_khz;
21687 }
21688
21689-static atomic64_t last_value = ATOMIC64_INIT(0);
21690+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
21691
21692 void pvclock_resume(void)
21693 {
21694- atomic64_set(&last_value, 0);
21695+ atomic64_set_unchecked(&last_value, 0);
21696 }
21697
21698 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
21699@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
21700 * updating at the same time, and one of them could be slightly behind,
21701 * making the assumption that last_value always go forward fail to hold.
21702 */
21703- last = atomic64_read(&last_value);
21704+ last = atomic64_read_unchecked(&last_value);
21705 do {
21706 if (ret < last)
21707 return last;
21708- last = atomic64_cmpxchg(&last_value, last, ret);
21709+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
21710 } while (unlikely(last != ret));
21711
21712 return ret;
21713diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
21714index 76fa1e9..abf09ea 100644
21715--- a/arch/x86/kernel/reboot.c
21716+++ b/arch/x86/kernel/reboot.c
21717@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
21718 EXPORT_SYMBOL(pm_power_off);
21719
21720 static const struct desc_ptr no_idt = {};
21721-static int reboot_mode;
21722+static unsigned short reboot_mode;
21723 enum reboot_type reboot_type = BOOT_ACPI;
21724 int reboot_force;
21725
21726@@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
21727
21728 void __noreturn machine_real_restart(unsigned int type)
21729 {
21730+
21731+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21732+ struct desc_struct *gdt;
21733+#endif
21734+
21735 local_irq_disable();
21736
21737 /*
21738@@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
21739
21740 /* Jump to the identity-mapped low memory code */
21741 #ifdef CONFIG_X86_32
21742- asm volatile("jmpl *%0" : :
21743+
21744+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21745+ gdt = get_cpu_gdt_table(smp_processor_id());
21746+ pax_open_kernel();
21747+#ifdef CONFIG_PAX_MEMORY_UDEREF
21748+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
21749+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
21750+ loadsegment(ds, __KERNEL_DS);
21751+ loadsegment(es, __KERNEL_DS);
21752+ loadsegment(ss, __KERNEL_DS);
21753+#endif
21754+#ifdef CONFIG_PAX_KERNEXEC
21755+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
21756+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
21757+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
21758+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
21759+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
21760+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
21761+#endif
21762+ pax_close_kernel();
21763+#endif
21764+
21765+ asm volatile("ljmpl *%0" : :
21766 "rm" (real_mode_header->machine_real_restart_asm),
21767 "a" (type));
21768 #else
21769@@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
21770 * try to force a triple fault and then cycle between hitting the keyboard
21771 * controller and doing that
21772 */
21773-static void native_machine_emergency_restart(void)
21774+static void __noreturn native_machine_emergency_restart(void)
21775 {
21776 int i;
21777 int attempt = 0;
21778@@ -654,13 +681,13 @@ void native_machine_shutdown(void)
21779 #endif
21780 }
21781
21782-static void __machine_emergency_restart(int emergency)
21783+static void __noreturn __machine_emergency_restart(int emergency)
21784 {
21785 reboot_emergency = emergency;
21786 machine_ops.emergency_restart();
21787 }
21788
21789-static void native_machine_restart(char *__unused)
21790+static void __noreturn native_machine_restart(char *__unused)
21791 {
21792 pr_notice("machine restart\n");
21793
21794@@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
21795 __machine_emergency_restart(0);
21796 }
21797
21798-static void native_machine_halt(void)
21799+static void __noreturn native_machine_halt(void)
21800 {
21801 /* Stop other cpus and apics */
21802 machine_shutdown();
21803@@ -679,7 +706,7 @@ static void native_machine_halt(void)
21804 stop_this_cpu(NULL);
21805 }
21806
21807-static void native_machine_power_off(void)
21808+static void __noreturn native_machine_power_off(void)
21809 {
21810 if (pm_power_off) {
21811 if (!reboot_force)
21812@@ -688,9 +715,10 @@ static void native_machine_power_off(void)
21813 }
21814 /* A fallback in case there is no PM info available */
21815 tboot_shutdown(TB_SHUTDOWN_HALT);
21816+ unreachable();
21817 }
21818
21819-struct machine_ops machine_ops = {
21820+struct machine_ops machine_ops __read_only = {
21821 .power_off = native_machine_power_off,
21822 .shutdown = native_machine_shutdown,
21823 .emergency_restart = native_machine_emergency_restart,
21824diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
21825index 7a6f3b3..bed145d7 100644
21826--- a/arch/x86/kernel/relocate_kernel_64.S
21827+++ b/arch/x86/kernel/relocate_kernel_64.S
21828@@ -11,6 +11,7 @@
21829 #include <asm/kexec.h>
21830 #include <asm/processor-flags.h>
21831 #include <asm/pgtable_types.h>
21832+#include <asm/alternative-asm.h>
21833
21834 /*
21835 * Must be relocatable PIC code callable as a C function
21836@@ -160,13 +161,14 @@ identity_mapped:
21837 xorq %rbp, %rbp
21838 xorq %r8, %r8
21839 xorq %r9, %r9
21840- xorq %r10, %r9
21841+ xorq %r10, %r10
21842 xorq %r11, %r11
21843 xorq %r12, %r12
21844 xorq %r13, %r13
21845 xorq %r14, %r14
21846 xorq %r15, %r15
21847
21848+ pax_force_retaddr 0, 1
21849 ret
21850
21851 1:
21852diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
21853index 8b24289..d37b58b 100644
21854--- a/arch/x86/kernel/setup.c
21855+++ b/arch/x86/kernel/setup.c
21856@@ -437,7 +437,7 @@ static void __init parse_setup_data(void)
21857
21858 switch (data->type) {
21859 case SETUP_E820_EXT:
21860- parse_e820_ext(data);
21861+ parse_e820_ext((struct setup_data __force_kernel *)data);
21862 break;
21863 case SETUP_DTB:
21864 add_dtb(pa_data);
21865@@ -706,7 +706,7 @@ static void __init trim_bios_range(void)
21866 * area (640->1Mb) as ram even though it is not.
21867 * take them out.
21868 */
21869- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
21870+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
21871
21872 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
21873 }
21874@@ -830,14 +830,14 @@ void __init setup_arch(char **cmdline_p)
21875
21876 if (!boot_params.hdr.root_flags)
21877 root_mountflags &= ~MS_RDONLY;
21878- init_mm.start_code = (unsigned long) _text;
21879- init_mm.end_code = (unsigned long) _etext;
21880+ init_mm.start_code = ktla_ktva((unsigned long) _text);
21881+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
21882 init_mm.end_data = (unsigned long) _edata;
21883 init_mm.brk = _brk_end;
21884
21885- code_resource.start = virt_to_phys(_text);
21886- code_resource.end = virt_to_phys(_etext)-1;
21887- data_resource.start = virt_to_phys(_etext);
21888+ code_resource.start = virt_to_phys(ktla_ktva(_text));
21889+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
21890+ data_resource.start = virt_to_phys(_sdata);
21891 data_resource.end = virt_to_phys(_edata)-1;
21892 bss_resource.start = virt_to_phys(&__bss_start);
21893 bss_resource.end = virt_to_phys(&__bss_stop)-1;
21894diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
21895index 5cdff03..5810740 100644
21896--- a/arch/x86/kernel/setup_percpu.c
21897+++ b/arch/x86/kernel/setup_percpu.c
21898@@ -21,19 +21,17 @@
21899 #include <asm/cpu.h>
21900 #include <asm/stackprotector.h>
21901
21902-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
21903+#ifdef CONFIG_SMP
21904+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
21905 EXPORT_PER_CPU_SYMBOL(cpu_number);
21906+#endif
21907
21908-#ifdef CONFIG_X86_64
21909 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
21910-#else
21911-#define BOOT_PERCPU_OFFSET 0
21912-#endif
21913
21914 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
21915 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
21916
21917-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
21918+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
21919 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
21920 };
21921 EXPORT_SYMBOL(__per_cpu_offset);
21922@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
21923 {
21924 #ifdef CONFIG_X86_32
21925 struct desc_struct gdt;
21926+ unsigned long base = per_cpu_offset(cpu);
21927
21928- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
21929- 0x2 | DESCTYPE_S, 0x8);
21930- gdt.s = 1;
21931+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
21932+ 0x83 | DESCTYPE_S, 0xC);
21933 write_gdt_entry(get_cpu_gdt_table(cpu),
21934 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
21935 #endif
21936@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
21937 /* alrighty, percpu areas up and running */
21938 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
21939 for_each_possible_cpu(cpu) {
21940+#ifdef CONFIG_CC_STACKPROTECTOR
21941+#ifdef CONFIG_X86_32
21942+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
21943+#endif
21944+#endif
21945 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
21946 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
21947 per_cpu(cpu_number, cpu) = cpu;
21948@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
21949 */
21950 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
21951 #endif
21952+#ifdef CONFIG_CC_STACKPROTECTOR
21953+#ifdef CONFIG_X86_32
21954+ if (!cpu)
21955+ per_cpu(stack_canary.canary, cpu) = canary;
21956+#endif
21957+#endif
21958 /*
21959 * Up to this point, the boot CPU has been using .init.data
21960 * area. Reload any changed state for the boot CPU.
21961diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
21962index d6bf1f3..3ffce5a 100644
21963--- a/arch/x86/kernel/signal.c
21964+++ b/arch/x86/kernel/signal.c
21965@@ -196,7 +196,7 @@ static unsigned long align_sigframe(unsigned long sp)
21966 * Align the stack pointer according to the i386 ABI,
21967 * i.e. so that on function entry ((sp + 4) & 15) == 0.
21968 */
21969- sp = ((sp + 4) & -16ul) - 4;
21970+ sp = ((sp - 12) & -16ul) - 4;
21971 #else /* !CONFIG_X86_32 */
21972 sp = round_down(sp, 16) - 8;
21973 #endif
21974@@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
21975 }
21976
21977 if (current->mm->context.vdso)
21978- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
21979+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
21980 else
21981- restorer = &frame->retcode;
21982+ restorer = (void __user *)&frame->retcode;
21983 if (ka->sa.sa_flags & SA_RESTORER)
21984 restorer = ka->sa.sa_restorer;
21985
21986@@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
21987 * reasons and because gdb uses it as a signature to notice
21988 * signal handler stack frames.
21989 */
21990- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
21991+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
21992
21993 if (err)
21994 return -EFAULT;
21995@@ -367,7 +367,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
21996 err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
21997
21998 /* Set up to return from userspace. */
21999- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22000+ if (current->mm->context.vdso)
22001+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22002+ else
22003+ restorer = (void __user *)&frame->retcode;
22004 if (ka->sa.sa_flags & SA_RESTORER)
22005 restorer = ka->sa.sa_restorer;
22006 put_user_ex(restorer, &frame->pretcode);
22007@@ -379,7 +382,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
22008 * reasons and because gdb uses it as a signature to notice
22009 * signal handler stack frames.
22010 */
22011- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
22012+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
22013 } put_user_catch(err);
22014
22015 err |= copy_siginfo_to_user(&frame->info, info);
22016diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
22017index 48d2b7d..90d328a 100644
22018--- a/arch/x86/kernel/smp.c
22019+++ b/arch/x86/kernel/smp.c
22020@@ -285,7 +285,7 @@ static int __init nonmi_ipi_setup(char *str)
22021
22022 __setup("nonmi_ipi", nonmi_ipi_setup);
22023
22024-struct smp_ops smp_ops = {
22025+struct smp_ops smp_ops __read_only = {
22026 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
22027 .smp_prepare_cpus = native_smp_prepare_cpus,
22028 .smp_cpus_done = native_smp_cpus_done,
22029diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
22030index ed0fe38..87fc692 100644
22031--- a/arch/x86/kernel/smpboot.c
22032+++ b/arch/x86/kernel/smpboot.c
22033@@ -748,6 +748,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
22034 idle->thread.sp = (unsigned long) (((struct pt_regs *)
22035 (THREAD_SIZE + task_stack_page(idle))) - 1);
22036 per_cpu(current_task, cpu) = idle;
22037+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
22038
22039 #ifdef CONFIG_X86_32
22040 /* Stack for startup_32 can be just as for start_secondary onwards */
22041@@ -755,11 +756,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
22042 #else
22043 clear_tsk_thread_flag(idle, TIF_FORK);
22044 initial_gs = per_cpu_offset(cpu);
22045- per_cpu(kernel_stack, cpu) =
22046- (unsigned long)task_stack_page(idle) -
22047- KERNEL_STACK_OFFSET + THREAD_SIZE;
22048+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
22049 #endif
22050+
22051+ pax_open_kernel();
22052 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
22053+ pax_close_kernel();
22054+
22055 initial_code = (unsigned long)start_secondary;
22056 stack_start = idle->thread.sp;
22057
22058@@ -908,6 +911,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
22059 /* the FPU context is blank, nobody can own it */
22060 __cpu_disable_lazy_restore(cpu);
22061
22062+#ifdef CONFIG_PAX_PER_CPU_PGD
22063+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
22064+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22065+ KERNEL_PGD_PTRS);
22066+#endif
22067+
22068+ /* the FPU context is blank, nobody can own it */
22069+ __cpu_disable_lazy_restore(cpu);
22070+
22071 err = do_boot_cpu(apicid, cpu, tidle);
22072 if (err) {
22073 pr_debug("do_boot_cpu failed %d\n", err);
22074diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
22075index 9b4d51d..5d28b58 100644
22076--- a/arch/x86/kernel/step.c
22077+++ b/arch/x86/kernel/step.c
22078@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22079 struct desc_struct *desc;
22080 unsigned long base;
22081
22082- seg &= ~7UL;
22083+ seg >>= 3;
22084
22085 mutex_lock(&child->mm->context.lock);
22086- if (unlikely((seg >> 3) >= child->mm->context.size))
22087+ if (unlikely(seg >= child->mm->context.size))
22088 addr = -1L; /* bogus selector, access would fault */
22089 else {
22090 desc = child->mm->context.ldt + seg;
22091@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22092 addr += base;
22093 }
22094 mutex_unlock(&child->mm->context.lock);
22095- }
22096+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
22097+ addr = ktla_ktva(addr);
22098
22099 return addr;
22100 }
22101@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
22102 unsigned char opcode[15];
22103 unsigned long addr = convert_ip_to_linear(child, regs);
22104
22105+ if (addr == -EINVAL)
22106+ return 0;
22107+
22108 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
22109 for (i = 0; i < copied; i++) {
22110 switch (opcode[i]) {
22111diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
22112new file mode 100644
22113index 0000000..26bb1af
22114--- /dev/null
22115+++ b/arch/x86/kernel/sys_i386_32.c
22116@@ -0,0 +1,249 @@
22117+/*
22118+ * This file contains various random system calls that
22119+ * have a non-standard calling sequence on the Linux/i386
22120+ * platform.
22121+ */
22122+
22123+#include <linux/errno.h>
22124+#include <linux/sched.h>
22125+#include <linux/mm.h>
22126+#include <linux/fs.h>
22127+#include <linux/smp.h>
22128+#include <linux/sem.h>
22129+#include <linux/msg.h>
22130+#include <linux/shm.h>
22131+#include <linux/stat.h>
22132+#include <linux/syscalls.h>
22133+#include <linux/mman.h>
22134+#include <linux/file.h>
22135+#include <linux/utsname.h>
22136+#include <linux/ipc.h>
22137+
22138+#include <linux/uaccess.h>
22139+#include <linux/unistd.h>
22140+
22141+#include <asm/syscalls.h>
22142+
22143+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
22144+{
22145+ unsigned long pax_task_size = TASK_SIZE;
22146+
22147+#ifdef CONFIG_PAX_SEGMEXEC
22148+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
22149+ pax_task_size = SEGMEXEC_TASK_SIZE;
22150+#endif
22151+
22152+ if (len > pax_task_size || addr > pax_task_size - len)
22153+ return -EINVAL;
22154+
22155+ return 0;
22156+}
22157+
22158+unsigned long
22159+arch_get_unmapped_area(struct file *filp, unsigned long addr,
22160+ unsigned long len, unsigned long pgoff, unsigned long flags)
22161+{
22162+ struct mm_struct *mm = current->mm;
22163+ struct vm_area_struct *vma;
22164+ unsigned long start_addr, pax_task_size = TASK_SIZE;
22165+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22166+
22167+#ifdef CONFIG_PAX_SEGMEXEC
22168+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22169+ pax_task_size = SEGMEXEC_TASK_SIZE;
22170+#endif
22171+
22172+ pax_task_size -= PAGE_SIZE;
22173+
22174+ if (len > pax_task_size)
22175+ return -ENOMEM;
22176+
22177+ if (flags & MAP_FIXED)
22178+ return addr;
22179+
22180+#ifdef CONFIG_PAX_RANDMMAP
22181+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22182+#endif
22183+
22184+ if (addr) {
22185+ addr = PAGE_ALIGN(addr);
22186+ if (pax_task_size - len >= addr) {
22187+ vma = find_vma(mm, addr);
22188+ if (check_heap_stack_gap(vma, addr, len, offset))
22189+ return addr;
22190+ }
22191+ }
22192+ if (len > mm->cached_hole_size) {
22193+ start_addr = addr = mm->free_area_cache;
22194+ } else {
22195+ start_addr = addr = mm->mmap_base;
22196+ mm->cached_hole_size = 0;
22197+ }
22198+
22199+#ifdef CONFIG_PAX_PAGEEXEC
22200+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
22201+ start_addr = 0x00110000UL;
22202+
22203+#ifdef CONFIG_PAX_RANDMMAP
22204+ if (mm->pax_flags & MF_PAX_RANDMMAP)
22205+ start_addr += mm->delta_mmap & 0x03FFF000UL;
22206+#endif
22207+
22208+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
22209+ start_addr = addr = mm->mmap_base;
22210+ else
22211+ addr = start_addr;
22212+ }
22213+#endif
22214+
22215+full_search:
22216+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
22217+ /* At this point: (!vma || addr < vma->vm_end). */
22218+ if (pax_task_size - len < addr) {
22219+ /*
22220+ * Start a new search - just in case we missed
22221+ * some holes.
22222+ */
22223+ if (start_addr != mm->mmap_base) {
22224+ start_addr = addr = mm->mmap_base;
22225+ mm->cached_hole_size = 0;
22226+ goto full_search;
22227+ }
22228+ return -ENOMEM;
22229+ }
22230+ if (check_heap_stack_gap(vma, addr, len, offset))
22231+ break;
22232+ if (addr + mm->cached_hole_size < vma->vm_start)
22233+ mm->cached_hole_size = vma->vm_start - addr;
22234+ addr = vma->vm_end;
22235+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
22236+ start_addr = addr = mm->mmap_base;
22237+ mm->cached_hole_size = 0;
22238+ goto full_search;
22239+ }
22240+ }
22241+
22242+ /*
22243+ * Remember the place where we stopped the search:
22244+ */
22245+ mm->free_area_cache = addr + len;
22246+ return addr;
22247+}
22248+
22249+unsigned long
22250+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
22251+ const unsigned long len, const unsigned long pgoff,
22252+ const unsigned long flags)
22253+{
22254+ struct vm_area_struct *vma;
22255+ struct mm_struct *mm = current->mm;
22256+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
22257+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22258+
22259+#ifdef CONFIG_PAX_SEGMEXEC
22260+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22261+ pax_task_size = SEGMEXEC_TASK_SIZE;
22262+#endif
22263+
22264+ pax_task_size -= PAGE_SIZE;
22265+
22266+ /* requested length too big for entire address space */
22267+ if (len > pax_task_size)
22268+ return -ENOMEM;
22269+
22270+ if (flags & MAP_FIXED)
22271+ return addr;
22272+
22273+#ifdef CONFIG_PAX_PAGEEXEC
22274+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
22275+ goto bottomup;
22276+#endif
22277+
22278+#ifdef CONFIG_PAX_RANDMMAP
22279+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22280+#endif
22281+
22282+ /* requesting a specific address */
22283+ if (addr) {
22284+ addr = PAGE_ALIGN(addr);
22285+ if (pax_task_size - len >= addr) {
22286+ vma = find_vma(mm, addr);
22287+ if (check_heap_stack_gap(vma, addr, len, offset))
22288+ return addr;
22289+ }
22290+ }
22291+
22292+ /* check if free_area_cache is useful for us */
22293+ if (len <= mm->cached_hole_size) {
22294+ mm->cached_hole_size = 0;
22295+ mm->free_area_cache = mm->mmap_base;
22296+ }
22297+
22298+ /* either no address requested or can't fit in requested address hole */
22299+ addr = mm->free_area_cache;
22300+
22301+ /* make sure it can fit in the remaining address space */
22302+ if (addr > len) {
22303+ vma = find_vma(mm, addr-len);
22304+ if (check_heap_stack_gap(vma, addr - len, len, offset))
22305+ /* remember the address as a hint for next time */
22306+ return (mm->free_area_cache = addr-len);
22307+ }
22308+
22309+ if (mm->mmap_base < len)
22310+ goto bottomup;
22311+
22312+ addr = mm->mmap_base-len;
22313+
22314+ do {
22315+ /*
22316+ * Lookup failure means no vma is above this address,
22317+ * else if new region fits below vma->vm_start,
22318+ * return with success:
22319+ */
22320+ vma = find_vma(mm, addr);
22321+ if (check_heap_stack_gap(vma, addr, len, offset))
22322+ /* remember the address as a hint for next time */
22323+ return (mm->free_area_cache = addr);
22324+
22325+ /* remember the largest hole we saw so far */
22326+ if (addr + mm->cached_hole_size < vma->vm_start)
22327+ mm->cached_hole_size = vma->vm_start - addr;
22328+
22329+ /* try just below the current vma->vm_start */
22330+ addr = skip_heap_stack_gap(vma, len, offset);
22331+ } while (!IS_ERR_VALUE(addr));
22332+
22333+bottomup:
22334+ /*
22335+ * A failed mmap() very likely causes application failure,
22336+ * so fall back to the bottom-up function here. This scenario
22337+ * can happen with large stack limits and large mmap()
22338+ * allocations.
22339+ */
22340+
22341+#ifdef CONFIG_PAX_SEGMEXEC
22342+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22343+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
22344+ else
22345+#endif
22346+
22347+ mm->mmap_base = TASK_UNMAPPED_BASE;
22348+
22349+#ifdef CONFIG_PAX_RANDMMAP
22350+ if (mm->pax_flags & MF_PAX_RANDMMAP)
22351+ mm->mmap_base += mm->delta_mmap;
22352+#endif
22353+
22354+ mm->free_area_cache = mm->mmap_base;
22355+ mm->cached_hole_size = ~0UL;
22356+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
22357+ /*
22358+ * Restore the topdown base:
22359+ */
22360+ mm->mmap_base = base;
22361+ mm->free_area_cache = base;
22362+ mm->cached_hole_size = ~0UL;
22363+
22364+ return addr;
22365+}
22366diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
22367index 97ef74b..57a1882 100644
22368--- a/arch/x86/kernel/sys_x86_64.c
22369+++ b/arch/x86/kernel/sys_x86_64.c
22370@@ -81,8 +81,8 @@ out:
22371 return error;
22372 }
22373
22374-static void find_start_end(unsigned long flags, unsigned long *begin,
22375- unsigned long *end)
22376+static void find_start_end(struct mm_struct *mm, unsigned long flags,
22377+ unsigned long *begin, unsigned long *end)
22378 {
22379 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
22380 unsigned long new_begin;
22381@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
22382 *begin = new_begin;
22383 }
22384 } else {
22385- *begin = TASK_UNMAPPED_BASE;
22386+ *begin = mm->mmap_base;
22387 *end = TASK_SIZE;
22388 }
22389 }
22390@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
22391 struct vm_area_struct *vma;
22392 struct vm_unmapped_area_info info;
22393 unsigned long begin, end;
22394+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22395
22396 if (flags & MAP_FIXED)
22397 return addr;
22398
22399- find_start_end(flags, &begin, &end);
22400+ find_start_end(mm, flags, &begin, &end);
22401
22402 if (len > end)
22403 return -ENOMEM;
22404
22405+#ifdef CONFIG_PAX_RANDMMAP
22406+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22407+#endif
22408+
22409 if (addr) {
22410 addr = PAGE_ALIGN(addr);
22411 vma = find_vma(mm, addr);
22412- if (end - len >= addr &&
22413- (!vma || addr + len <= vma->vm_start))
22414+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
22415 return addr;
22416 }
22417
22418@@ -161,6 +165,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
22419 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
22420 goto bottomup;
22421
22422+#ifdef CONFIG_PAX_RANDMMAP
22423+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22424+#endif
22425+
22426 /* requesting a specific address */
22427 if (addr) {
22428 addr = PAGE_ALIGN(addr);
22429diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
22430index f84fe00..f41d9f1 100644
22431--- a/arch/x86/kernel/tboot.c
22432+++ b/arch/x86/kernel/tboot.c
22433@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
22434
22435 void tboot_shutdown(u32 shutdown_type)
22436 {
22437- void (*shutdown)(void);
22438+ void (* __noreturn shutdown)(void);
22439
22440 if (!tboot_enabled())
22441 return;
22442@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
22443
22444 switch_to_tboot_pt();
22445
22446- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
22447+ shutdown = (void *)tboot->shutdown_entry;
22448 shutdown();
22449
22450 /* should not reach here */
22451@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
22452 return 0;
22453 }
22454
22455-static atomic_t ap_wfs_count;
22456+static atomic_unchecked_t ap_wfs_count;
22457
22458 static int tboot_wait_for_aps(int num_aps)
22459 {
22460@@ -324,16 +324,16 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
22461 {
22462 switch (action) {
22463 case CPU_DYING:
22464- atomic_inc(&ap_wfs_count);
22465+ atomic_inc_unchecked(&ap_wfs_count);
22466 if (num_online_cpus() == 1)
22467- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
22468+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
22469 return NOTIFY_BAD;
22470 break;
22471 }
22472 return NOTIFY_OK;
22473 }
22474
22475-static struct notifier_block tboot_cpu_notifier __cpuinitdata =
22476+static struct notifier_block tboot_cpu_notifier =
22477 {
22478 .notifier_call = tboot_cpu_callback,
22479 };
22480@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
22481
22482 tboot_create_trampoline();
22483
22484- atomic_set(&ap_wfs_count, 0);
22485+ atomic_set_unchecked(&ap_wfs_count, 0);
22486 register_hotcpu_notifier(&tboot_cpu_notifier);
22487
22488 acpi_os_set_prepare_sleep(&tboot_sleep);
22489diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
22490index 24d3c91..d06b473 100644
22491--- a/arch/x86/kernel/time.c
22492+++ b/arch/x86/kernel/time.c
22493@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
22494 {
22495 unsigned long pc = instruction_pointer(regs);
22496
22497- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
22498+ if (!user_mode(regs) && in_lock_functions(pc)) {
22499 #ifdef CONFIG_FRAME_POINTER
22500- return *(unsigned long *)(regs->bp + sizeof(long));
22501+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
22502 #else
22503 unsigned long *sp =
22504 (unsigned long *)kernel_stack_pointer(regs);
22505@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
22506 * or above a saved flags. Eflags has bits 22-31 zero,
22507 * kernel addresses don't.
22508 */
22509+
22510+#ifdef CONFIG_PAX_KERNEXEC
22511+ return ktla_ktva(sp[0]);
22512+#else
22513 if (sp[0] >> 22)
22514 return sp[0];
22515 if (sp[1] >> 22)
22516 return sp[1];
22517 #endif
22518+
22519+#endif
22520 }
22521 return pc;
22522 }
22523diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
22524index 9d9d2f9..cad418a 100644
22525--- a/arch/x86/kernel/tls.c
22526+++ b/arch/x86/kernel/tls.c
22527@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
22528 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
22529 return -EINVAL;
22530
22531+#ifdef CONFIG_PAX_SEGMEXEC
22532+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
22533+ return -EINVAL;
22534+#endif
22535+
22536 set_tls_desc(p, idx, &info, 1);
22537
22538 return 0;
22539@@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
22540
22541 if (kbuf)
22542 info = kbuf;
22543- else if (__copy_from_user(infobuf, ubuf, count))
22544+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
22545 return -EFAULT;
22546 else
22547 info = infobuf;
22548diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
22549index ecffca1..95c4d13 100644
22550--- a/arch/x86/kernel/traps.c
22551+++ b/arch/x86/kernel/traps.c
22552@@ -68,12 +68,6 @@
22553 #include <asm/setup.h>
22554
22555 asmlinkage int system_call(void);
22556-
22557-/*
22558- * The IDT has to be page-aligned to simplify the Pentium
22559- * F0 0F bug workaround.
22560- */
22561-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
22562 #endif
22563
22564 DECLARE_BITMAP(used_vectors, NR_VECTORS);
22565@@ -106,11 +100,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
22566 }
22567
22568 static int __kprobes
22569-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
22570+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
22571 struct pt_regs *regs, long error_code)
22572 {
22573 #ifdef CONFIG_X86_32
22574- if (regs->flags & X86_VM_MASK) {
22575+ if (v8086_mode(regs)) {
22576 /*
22577 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
22578 * On nmi (interrupt 2), do_trap should not be called.
22579@@ -123,12 +117,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
22580 return -1;
22581 }
22582 #endif
22583- if (!user_mode(regs)) {
22584+ if (!user_mode_novm(regs)) {
22585 if (!fixup_exception(regs)) {
22586 tsk->thread.error_code = error_code;
22587 tsk->thread.trap_nr = trapnr;
22588+
22589+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22590+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
22591+ str = "PAX: suspicious stack segment fault";
22592+#endif
22593+
22594 die(str, regs, error_code);
22595 }
22596+
22597+#ifdef CONFIG_PAX_REFCOUNT
22598+ if (trapnr == 4)
22599+ pax_report_refcount_overflow(regs);
22600+#endif
22601+
22602 return 0;
22603 }
22604
22605@@ -136,7 +142,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
22606 }
22607
22608 static void __kprobes
22609-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
22610+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
22611 long error_code, siginfo_t *info)
22612 {
22613 struct task_struct *tsk = current;
22614@@ -160,7 +166,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
22615 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
22616 printk_ratelimit()) {
22617 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
22618- tsk->comm, tsk->pid, str,
22619+ tsk->comm, task_pid_nr(tsk), str,
22620 regs->ip, regs->sp, error_code);
22621 print_vma_addr(" in ", regs->ip);
22622 pr_cont("\n");
22623@@ -266,7 +272,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
22624 conditional_sti(regs);
22625
22626 #ifdef CONFIG_X86_32
22627- if (regs->flags & X86_VM_MASK) {
22628+ if (v8086_mode(regs)) {
22629 local_irq_enable();
22630 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
22631 goto exit;
22632@@ -274,18 +280,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
22633 #endif
22634
22635 tsk = current;
22636- if (!user_mode(regs)) {
22637+ if (!user_mode_novm(regs)) {
22638 if (fixup_exception(regs))
22639 goto exit;
22640
22641 tsk->thread.error_code = error_code;
22642 tsk->thread.trap_nr = X86_TRAP_GP;
22643 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
22644- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
22645+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
22646+
22647+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22648+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
22649+ die("PAX: suspicious general protection fault", regs, error_code);
22650+ else
22651+#endif
22652+
22653 die("general protection fault", regs, error_code);
22654+ }
22655 goto exit;
22656 }
22657
22658+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
22659+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
22660+ struct mm_struct *mm = tsk->mm;
22661+ unsigned long limit;
22662+
22663+ down_write(&mm->mmap_sem);
22664+ limit = mm->context.user_cs_limit;
22665+ if (limit < TASK_SIZE) {
22666+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
22667+ up_write(&mm->mmap_sem);
22668+ return;
22669+ }
22670+ up_write(&mm->mmap_sem);
22671+ }
22672+#endif
22673+
22674 tsk->thread.error_code = error_code;
22675 tsk->thread.trap_nr = X86_TRAP_GP;
22676
22677@@ -440,7 +470,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
22678 /* It's safe to allow irq's after DR6 has been saved */
22679 preempt_conditional_sti(regs);
22680
22681- if (regs->flags & X86_VM_MASK) {
22682+ if (v8086_mode(regs)) {
22683 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
22684 X86_TRAP_DB);
22685 preempt_conditional_cli(regs);
22686@@ -455,7 +485,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
22687 * We already checked v86 mode above, so we can check for kernel mode
22688 * by just checking the CPL of CS.
22689 */
22690- if ((dr6 & DR_STEP) && !user_mode(regs)) {
22691+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
22692 tsk->thread.debugreg6 &= ~DR_STEP;
22693 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
22694 regs->flags &= ~X86_EFLAGS_TF;
22695@@ -487,7 +517,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
22696 return;
22697 conditional_sti(regs);
22698
22699- if (!user_mode_vm(regs))
22700+ if (!user_mode(regs))
22701 {
22702 if (!fixup_exception(regs)) {
22703 task->thread.error_code = error_code;
22704diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
22705index c71025b..b117501 100644
22706--- a/arch/x86/kernel/uprobes.c
22707+++ b/arch/x86/kernel/uprobes.c
22708@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
22709 int ret = NOTIFY_DONE;
22710
22711 /* We are only interested in userspace traps */
22712- if (regs && !user_mode_vm(regs))
22713+ if (regs && !user_mode(regs))
22714 return NOTIFY_DONE;
22715
22716 switch (val) {
22717diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
22718index b9242ba..50c5edd 100644
22719--- a/arch/x86/kernel/verify_cpu.S
22720+++ b/arch/x86/kernel/verify_cpu.S
22721@@ -20,6 +20,7 @@
22722 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
22723 * arch/x86/kernel/trampoline_64.S: secondary processor verification
22724 * arch/x86/kernel/head_32.S: processor startup
22725+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
22726 *
22727 * verify_cpu, returns the status of longmode and SSE in register %eax.
22728 * 0: Success 1: Failure
22729diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
22730index 1dfe69c..a3df6f6 100644
22731--- a/arch/x86/kernel/vm86_32.c
22732+++ b/arch/x86/kernel/vm86_32.c
22733@@ -43,6 +43,7 @@
22734 #include <linux/ptrace.h>
22735 #include <linux/audit.h>
22736 #include <linux/stddef.h>
22737+#include <linux/grsecurity.h>
22738
22739 #include <asm/uaccess.h>
22740 #include <asm/io.h>
22741@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
22742 do_exit(SIGSEGV);
22743 }
22744
22745- tss = &per_cpu(init_tss, get_cpu());
22746+ tss = init_tss + get_cpu();
22747 current->thread.sp0 = current->thread.saved_sp0;
22748 current->thread.sysenter_cs = __KERNEL_CS;
22749 load_sp0(tss, &current->thread);
22750@@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
22751 struct task_struct *tsk;
22752 int tmp, ret = -EPERM;
22753
22754+#ifdef CONFIG_GRKERNSEC_VM86
22755+ if (!capable(CAP_SYS_RAWIO)) {
22756+ gr_handle_vm86();
22757+ goto out;
22758+ }
22759+#endif
22760+
22761 tsk = current;
22762 if (tsk->thread.saved_sp0)
22763 goto out;
22764@@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
22765 int tmp, ret;
22766 struct vm86plus_struct __user *v86;
22767
22768+#ifdef CONFIG_GRKERNSEC_VM86
22769+ if (!capable(CAP_SYS_RAWIO)) {
22770+ gr_handle_vm86();
22771+ ret = -EPERM;
22772+ goto out;
22773+ }
22774+#endif
22775+
22776 tsk = current;
22777 switch (cmd) {
22778 case VM86_REQUEST_IRQ:
22779@@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
22780 tsk->thread.saved_fs = info->regs32->fs;
22781 tsk->thread.saved_gs = get_user_gs(info->regs32);
22782
22783- tss = &per_cpu(init_tss, get_cpu());
22784+ tss = init_tss + get_cpu();
22785 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
22786 if (cpu_has_sep)
22787 tsk->thread.sysenter_cs = 0;
22788@@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
22789 goto cannot_handle;
22790 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
22791 goto cannot_handle;
22792- intr_ptr = (unsigned long __user *) (i << 2);
22793+ intr_ptr = (__force unsigned long __user *) (i << 2);
22794 if (get_user(segoffs, intr_ptr))
22795 goto cannot_handle;
22796 if ((segoffs >> 16) == BIOSSEG)
22797diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
22798index 22a1530..8fbaaad 100644
22799--- a/arch/x86/kernel/vmlinux.lds.S
22800+++ b/arch/x86/kernel/vmlinux.lds.S
22801@@ -26,6 +26,13 @@
22802 #include <asm/page_types.h>
22803 #include <asm/cache.h>
22804 #include <asm/boot.h>
22805+#include <asm/segment.h>
22806+
22807+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22808+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
22809+#else
22810+#define __KERNEL_TEXT_OFFSET 0
22811+#endif
22812
22813 #undef i386 /* in case the preprocessor is a 32bit one */
22814
22815@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
22816
22817 PHDRS {
22818 text PT_LOAD FLAGS(5); /* R_E */
22819+#ifdef CONFIG_X86_32
22820+ module PT_LOAD FLAGS(5); /* R_E */
22821+#endif
22822+#ifdef CONFIG_XEN
22823+ rodata PT_LOAD FLAGS(5); /* R_E */
22824+#else
22825+ rodata PT_LOAD FLAGS(4); /* R__ */
22826+#endif
22827 data PT_LOAD FLAGS(6); /* RW_ */
22828-#ifdef CONFIG_X86_64
22829+ init.begin PT_LOAD FLAGS(6); /* RW_ */
22830 #ifdef CONFIG_SMP
22831 percpu PT_LOAD FLAGS(6); /* RW_ */
22832 #endif
22833+ text.init PT_LOAD FLAGS(5); /* R_E */
22834+ text.exit PT_LOAD FLAGS(5); /* R_E */
22835 init PT_LOAD FLAGS(7); /* RWE */
22836-#endif
22837 note PT_NOTE FLAGS(0); /* ___ */
22838 }
22839
22840 SECTIONS
22841 {
22842 #ifdef CONFIG_X86_32
22843- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
22844- phys_startup_32 = startup_32 - LOAD_OFFSET;
22845+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
22846 #else
22847- . = __START_KERNEL;
22848- phys_startup_64 = startup_64 - LOAD_OFFSET;
22849+ . = __START_KERNEL;
22850 #endif
22851
22852 /* Text and read-only data */
22853- .text : AT(ADDR(.text) - LOAD_OFFSET) {
22854- _text = .;
22855+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
22856 /* bootstrapping code */
22857+#ifdef CONFIG_X86_32
22858+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
22859+#else
22860+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
22861+#endif
22862+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
22863+ _text = .;
22864 HEAD_TEXT
22865 #ifdef CONFIG_X86_32
22866 . = ALIGN(PAGE_SIZE);
22867@@ -108,13 +128,48 @@ SECTIONS
22868 IRQENTRY_TEXT
22869 *(.fixup)
22870 *(.gnu.warning)
22871- /* End of text section */
22872- _etext = .;
22873 } :text = 0x9090
22874
22875- NOTES :text :note
22876+ . += __KERNEL_TEXT_OFFSET;
22877
22878- EXCEPTION_TABLE(16) :text = 0x9090
22879+#ifdef CONFIG_X86_32
22880+ . = ALIGN(PAGE_SIZE);
22881+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
22882+
22883+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
22884+ MODULES_EXEC_VADDR = .;
22885+ BYTE(0)
22886+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
22887+ . = ALIGN(HPAGE_SIZE) - 1;
22888+ MODULES_EXEC_END = .;
22889+#endif
22890+
22891+ } :module
22892+#endif
22893+
22894+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
22895+ /* End of text section */
22896+ BYTE(0)
22897+ _etext = . - __KERNEL_TEXT_OFFSET;
22898+ }
22899+
22900+#ifdef CONFIG_X86_32
22901+ . = ALIGN(PAGE_SIZE);
22902+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
22903+ *(.idt)
22904+ . = ALIGN(PAGE_SIZE);
22905+ *(.empty_zero_page)
22906+ *(.initial_pg_fixmap)
22907+ *(.initial_pg_pmd)
22908+ *(.initial_page_table)
22909+ *(.swapper_pg_dir)
22910+ } :rodata
22911+#endif
22912+
22913+ . = ALIGN(PAGE_SIZE);
22914+ NOTES :rodata :note
22915+
22916+ EXCEPTION_TABLE(16) :rodata
22917
22918 #if defined(CONFIG_DEBUG_RODATA)
22919 /* .text should occupy whole number of pages */
22920@@ -126,16 +181,20 @@ SECTIONS
22921
22922 /* Data */
22923 .data : AT(ADDR(.data) - LOAD_OFFSET) {
22924+
22925+#ifdef CONFIG_PAX_KERNEXEC
22926+ . = ALIGN(HPAGE_SIZE);
22927+#else
22928+ . = ALIGN(PAGE_SIZE);
22929+#endif
22930+
22931 /* Start of data section */
22932 _sdata = .;
22933
22934 /* init_task */
22935 INIT_TASK_DATA(THREAD_SIZE)
22936
22937-#ifdef CONFIG_X86_32
22938- /* 32 bit has nosave before _edata */
22939 NOSAVE_DATA
22940-#endif
22941
22942 PAGE_ALIGNED_DATA(PAGE_SIZE)
22943
22944@@ -176,12 +235,19 @@ SECTIONS
22945 #endif /* CONFIG_X86_64 */
22946
22947 /* Init code and data - will be freed after init */
22948- . = ALIGN(PAGE_SIZE);
22949 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
22950+ BYTE(0)
22951+
22952+#ifdef CONFIG_PAX_KERNEXEC
22953+ . = ALIGN(HPAGE_SIZE);
22954+#else
22955+ . = ALIGN(PAGE_SIZE);
22956+#endif
22957+
22958 __init_begin = .; /* paired with __init_end */
22959- }
22960+ } :init.begin
22961
22962-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
22963+#ifdef CONFIG_SMP
22964 /*
22965 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
22966 * output PHDR, so the next output section - .init.text - should
22967@@ -190,12 +256,27 @@ SECTIONS
22968 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
22969 #endif
22970
22971- INIT_TEXT_SECTION(PAGE_SIZE)
22972-#ifdef CONFIG_X86_64
22973- :init
22974-#endif
22975+ . = ALIGN(PAGE_SIZE);
22976+ init_begin = .;
22977+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
22978+ VMLINUX_SYMBOL(_sinittext) = .;
22979+ INIT_TEXT
22980+ VMLINUX_SYMBOL(_einittext) = .;
22981+ . = ALIGN(PAGE_SIZE);
22982+ } :text.init
22983
22984- INIT_DATA_SECTION(16)
22985+ /*
22986+ * .exit.text is discard at runtime, not link time, to deal with
22987+ * references from .altinstructions and .eh_frame
22988+ */
22989+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
22990+ EXIT_TEXT
22991+ . = ALIGN(16);
22992+ } :text.exit
22993+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
22994+
22995+ . = ALIGN(PAGE_SIZE);
22996+ INIT_DATA_SECTION(16) :init
22997
22998 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
22999 __x86_cpu_dev_start = .;
23000@@ -257,19 +338,12 @@ SECTIONS
23001 }
23002
23003 . = ALIGN(8);
23004- /*
23005- * .exit.text is discard at runtime, not link time, to deal with
23006- * references from .altinstructions and .eh_frame
23007- */
23008- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
23009- EXIT_TEXT
23010- }
23011
23012 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
23013 EXIT_DATA
23014 }
23015
23016-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
23017+#ifndef CONFIG_SMP
23018 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
23019 #endif
23020
23021@@ -288,16 +362,10 @@ SECTIONS
23022 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
23023 __smp_locks = .;
23024 *(.smp_locks)
23025- . = ALIGN(PAGE_SIZE);
23026 __smp_locks_end = .;
23027+ . = ALIGN(PAGE_SIZE);
23028 }
23029
23030-#ifdef CONFIG_X86_64
23031- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
23032- NOSAVE_DATA
23033- }
23034-#endif
23035-
23036 /* BSS */
23037 . = ALIGN(PAGE_SIZE);
23038 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
23039@@ -313,6 +381,7 @@ SECTIONS
23040 __brk_base = .;
23041 . += 64 * 1024; /* 64k alignment slop space */
23042 *(.brk_reservation) /* areas brk users have reserved */
23043+ . = ALIGN(HPAGE_SIZE);
23044 __brk_limit = .;
23045 }
23046
23047@@ -339,13 +408,12 @@ SECTIONS
23048 * for the boot processor.
23049 */
23050 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
23051-INIT_PER_CPU(gdt_page);
23052 INIT_PER_CPU(irq_stack_union);
23053
23054 /*
23055 * Build-time check on the image size:
23056 */
23057-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
23058+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
23059 "kernel image bigger than KERNEL_IMAGE_SIZE");
23060
23061 #ifdef CONFIG_SMP
23062diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
23063index 9a907a6..f83f921 100644
23064--- a/arch/x86/kernel/vsyscall_64.c
23065+++ b/arch/x86/kernel/vsyscall_64.c
23066@@ -56,15 +56,13 @@
23067 DEFINE_VVAR(int, vgetcpu_mode);
23068 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
23069
23070-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
23071+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
23072
23073 static int __init vsyscall_setup(char *str)
23074 {
23075 if (str) {
23076 if (!strcmp("emulate", str))
23077 vsyscall_mode = EMULATE;
23078- else if (!strcmp("native", str))
23079- vsyscall_mode = NATIVE;
23080 else if (!strcmp("none", str))
23081 vsyscall_mode = NONE;
23082 else
23083@@ -323,8 +321,7 @@ do_ret:
23084 return true;
23085
23086 sigsegv:
23087- force_sig(SIGSEGV, current);
23088- return true;
23089+ do_group_exit(SIGKILL);
23090 }
23091
23092 /*
23093@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
23094 extern char __vvar_page;
23095 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
23096
23097- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
23098- vsyscall_mode == NATIVE
23099- ? PAGE_KERNEL_VSYSCALL
23100- : PAGE_KERNEL_VVAR);
23101+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
23102 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
23103 (unsigned long)VSYSCALL_START);
23104
23105diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
23106index 1330dd1..d220b99 100644
23107--- a/arch/x86/kernel/x8664_ksyms_64.c
23108+++ b/arch/x86/kernel/x8664_ksyms_64.c
23109@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
23110 EXPORT_SYMBOL(copy_user_generic_unrolled);
23111 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
23112 EXPORT_SYMBOL(__copy_user_nocache);
23113-EXPORT_SYMBOL(_copy_from_user);
23114-EXPORT_SYMBOL(_copy_to_user);
23115
23116 EXPORT_SYMBOL(copy_page);
23117 EXPORT_SYMBOL(clear_page);
23118diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
23119index 7a3d075..6cb373d 100644
23120--- a/arch/x86/kernel/x86_init.c
23121+++ b/arch/x86/kernel/x86_init.c
23122@@ -88,7 +88,7 @@ struct x86_init_ops x86_init __initdata = {
23123 },
23124 };
23125
23126-struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23127+struct x86_cpuinit_ops x86_cpuinit __cpuinitconst = {
23128 .early_percpu_clock_init = x86_init_noop,
23129 .setup_percpu_clockev = setup_secondary_APIC_clock,
23130 };
23131@@ -96,7 +96,7 @@ struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23132 static void default_nmi_init(void) { };
23133 static int default_i8042_detect(void) { return 1; };
23134
23135-struct x86_platform_ops x86_platform = {
23136+struct x86_platform_ops x86_platform __read_only = {
23137 .calibrate_tsc = native_calibrate_tsc,
23138 .get_wallclock = mach_get_cmos_time,
23139 .set_wallclock = mach_set_rtc_mmss,
23140@@ -110,14 +110,14 @@ struct x86_platform_ops x86_platform = {
23141 };
23142
23143 EXPORT_SYMBOL_GPL(x86_platform);
23144-struct x86_msi_ops x86_msi = {
23145+struct x86_msi_ops x86_msi __read_only = {
23146 .setup_msi_irqs = native_setup_msi_irqs,
23147 .teardown_msi_irq = native_teardown_msi_irq,
23148 .teardown_msi_irqs = default_teardown_msi_irqs,
23149 .restore_msi_irqs = default_restore_msi_irqs,
23150 };
23151
23152-struct x86_io_apic_ops x86_io_apic_ops = {
23153+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
23154 .init = native_io_apic_init_mappings,
23155 .read = native_io_apic_read,
23156 .write = native_io_apic_write,
23157diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
23158index ada87a3..afea76d 100644
23159--- a/arch/x86/kernel/xsave.c
23160+++ b/arch/x86/kernel/xsave.c
23161@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
23162 {
23163 int err;
23164
23165+ buf = (struct xsave_struct __user *)____m(buf);
23166 if (use_xsave())
23167 err = xsave_user(buf);
23168 else if (use_fxsr())
23169@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
23170 */
23171 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
23172 {
23173+ buf = (void __user *)____m(buf);
23174 if (use_xsave()) {
23175 if ((unsigned long)buf % 64 || fx_only) {
23176 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
23177diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
23178index a20ecb5..d0e2194 100644
23179--- a/arch/x86/kvm/cpuid.c
23180+++ b/arch/x86/kvm/cpuid.c
23181@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
23182 struct kvm_cpuid2 *cpuid,
23183 struct kvm_cpuid_entry2 __user *entries)
23184 {
23185- int r;
23186+ int r, i;
23187
23188 r = -E2BIG;
23189 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
23190 goto out;
23191 r = -EFAULT;
23192- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
23193- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23194+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23195 goto out;
23196+ for (i = 0; i < cpuid->nent; ++i) {
23197+ struct kvm_cpuid_entry2 cpuid_entry;
23198+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
23199+ goto out;
23200+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
23201+ }
23202 vcpu->arch.cpuid_nent = cpuid->nent;
23203 kvm_apic_set_version(vcpu);
23204 kvm_x86_ops->cpuid_update(vcpu);
23205@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
23206 struct kvm_cpuid2 *cpuid,
23207 struct kvm_cpuid_entry2 __user *entries)
23208 {
23209- int r;
23210+ int r, i;
23211
23212 r = -E2BIG;
23213 if (cpuid->nent < vcpu->arch.cpuid_nent)
23214 goto out;
23215 r = -EFAULT;
23216- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
23217- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
23218+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
23219 goto out;
23220+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
23221+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
23222+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
23223+ goto out;
23224+ }
23225 return 0;
23226
23227 out:
23228diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
23229index a27e763..54bfe43 100644
23230--- a/arch/x86/kvm/emulate.c
23231+++ b/arch/x86/kvm/emulate.c
23232@@ -292,6 +292,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23233
23234 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
23235 do { \
23236+ unsigned long _tmp; \
23237 __asm__ __volatile__ ( \
23238 _PRE_EFLAGS("0", "4", "2") \
23239 _op _suffix " %"_x"3,%1; " \
23240@@ -306,8 +307,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23241 /* Raw emulation: instruction has two explicit operands. */
23242 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
23243 do { \
23244- unsigned long _tmp; \
23245- \
23246 switch ((ctxt)->dst.bytes) { \
23247 case 2: \
23248 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
23249@@ -323,7 +322,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23250
23251 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
23252 do { \
23253- unsigned long _tmp; \
23254 switch ((ctxt)->dst.bytes) { \
23255 case 1: \
23256 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
23257diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
23258index 9392f52..0e56d77 100644
23259--- a/arch/x86/kvm/lapic.c
23260+++ b/arch/x86/kvm/lapic.c
23261@@ -55,7 +55,7 @@
23262 #define APIC_BUS_CYCLE_NS 1
23263
23264 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
23265-#define apic_debug(fmt, arg...)
23266+#define apic_debug(fmt, arg...) do {} while (0)
23267
23268 #define APIC_LVT_NUM 6
23269 /* 14 is the version for Xeon and Pentium 8.4.8*/
23270diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
23271index 891eb6d..e027900 100644
23272--- a/arch/x86/kvm/paging_tmpl.h
23273+++ b/arch/x86/kvm/paging_tmpl.h
23274@@ -208,7 +208,7 @@ retry_walk:
23275 if (unlikely(kvm_is_error_hva(host_addr)))
23276 goto error;
23277
23278- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
23279+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
23280 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
23281 goto error;
23282 walker->ptep_user[walker->level - 1] = ptep_user;
23283diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
23284index d29d3cd..ec9d522 100644
23285--- a/arch/x86/kvm/svm.c
23286+++ b/arch/x86/kvm/svm.c
23287@@ -3507,7 +3507,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
23288 int cpu = raw_smp_processor_id();
23289
23290 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
23291+
23292+ pax_open_kernel();
23293 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
23294+ pax_close_kernel();
23295+
23296 load_TR_desc();
23297 }
23298
23299@@ -3881,6 +3885,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
23300 #endif
23301 #endif
23302
23303+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
23304+ __set_fs(current_thread_info()->addr_limit);
23305+#endif
23306+
23307 reload_tss(vcpu);
23308
23309 local_irq_disable();
23310diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
23311index 9120ae1..238abc0 100644
23312--- a/arch/x86/kvm/vmx.c
23313+++ b/arch/x86/kvm/vmx.c
23314@@ -1370,7 +1370,11 @@ static void reload_tss(void)
23315 struct desc_struct *descs;
23316
23317 descs = (void *)gdt->address;
23318+
23319+ pax_open_kernel();
23320 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
23321+ pax_close_kernel();
23322+
23323 load_TR_desc();
23324 }
23325
23326@@ -1594,6 +1598,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
23327 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
23328 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
23329
23330+#ifdef CONFIG_PAX_PER_CPU_PGD
23331+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
23332+#endif
23333+
23334 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
23335 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
23336 vmx->loaded_vmcs->cpu = cpu;
23337@@ -2738,8 +2746,11 @@ static __init int hardware_setup(void)
23338 if (!cpu_has_vmx_flexpriority())
23339 flexpriority_enabled = 0;
23340
23341- if (!cpu_has_vmx_tpr_shadow())
23342- kvm_x86_ops->update_cr8_intercept = NULL;
23343+ if (!cpu_has_vmx_tpr_shadow()) {
23344+ pax_open_kernel();
23345+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
23346+ pax_close_kernel();
23347+ }
23348
23349 if (enable_ept && !cpu_has_vmx_ept_2m_page())
23350 kvm_disable_largepages();
23351@@ -3782,7 +3793,10 @@ static void vmx_set_constant_host_state(void)
23352
23353 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
23354 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
23355+
23356+#ifndef CONFIG_PAX_PER_CPU_PGD
23357 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
23358+#endif
23359
23360 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
23361 #ifdef CONFIG_X86_64
23362@@ -3803,7 +3817,7 @@ static void vmx_set_constant_host_state(void)
23363 native_store_idt(&dt);
23364 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
23365
23366- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
23367+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
23368
23369 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
23370 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
23371@@ -6355,6 +6369,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23372 "jmp 2f \n\t"
23373 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
23374 "2: "
23375+
23376+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23377+ "ljmp %[cs],$3f\n\t"
23378+ "3: "
23379+#endif
23380+
23381 /* Save guest registers, load host registers, keep flags */
23382 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
23383 "pop %0 \n\t"
23384@@ -6407,6 +6427,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23385 #endif
23386 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
23387 [wordsize]"i"(sizeof(ulong))
23388+
23389+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23390+ ,[cs]"i"(__KERNEL_CS)
23391+#endif
23392+
23393 : "cc", "memory"
23394 #ifdef CONFIG_X86_64
23395 , "rax", "rbx", "rdi", "rsi"
23396@@ -6420,7 +6445,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23397 if (debugctlmsr)
23398 update_debugctlmsr(debugctlmsr);
23399
23400-#ifndef CONFIG_X86_64
23401+#ifdef CONFIG_X86_32
23402 /*
23403 * The sysexit path does not restore ds/es, so we must set them to
23404 * a reasonable value ourselves.
23405@@ -6429,8 +6454,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23406 * may be executed in interrupt context, which saves and restore segments
23407 * around it, nullifying its effect.
23408 */
23409- loadsegment(ds, __USER_DS);
23410- loadsegment(es, __USER_DS);
23411+ loadsegment(ds, __KERNEL_DS);
23412+ loadsegment(es, __KERNEL_DS);
23413+ loadsegment(ss, __KERNEL_DS);
23414+
23415+#ifdef CONFIG_PAX_KERNEXEC
23416+ loadsegment(fs, __KERNEL_PERCPU);
23417+#endif
23418+
23419+#ifdef CONFIG_PAX_MEMORY_UDEREF
23420+ __set_fs(current_thread_info()->addr_limit);
23421+#endif
23422+
23423 #endif
23424
23425 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
23426diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
23427index c243b81..9eb193f 100644
23428--- a/arch/x86/kvm/x86.c
23429+++ b/arch/x86/kvm/x86.c
23430@@ -1692,8 +1692,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
23431 {
23432 struct kvm *kvm = vcpu->kvm;
23433 int lm = is_long_mode(vcpu);
23434- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
23435- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
23436+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
23437+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
23438 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
23439 : kvm->arch.xen_hvm_config.blob_size_32;
23440 u32 page_num = data & ~PAGE_MASK;
23441@@ -2571,6 +2571,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
23442 if (n < msr_list.nmsrs)
23443 goto out;
23444 r = -EFAULT;
23445+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
23446+ goto out;
23447 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
23448 num_msrs_to_save * sizeof(u32)))
23449 goto out;
23450@@ -2700,7 +2702,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
23451 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
23452 struct kvm_interrupt *irq)
23453 {
23454- if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
23455+ if (irq->irq >= KVM_NR_INTERRUPTS)
23456 return -EINVAL;
23457 if (irqchip_in_kernel(vcpu->kvm))
23458 return -ENXIO;
23459@@ -5213,7 +5215,7 @@ static struct notifier_block pvclock_gtod_notifier = {
23460 };
23461 #endif
23462
23463-int kvm_arch_init(void *opaque)
23464+int kvm_arch_init(const void *opaque)
23465 {
23466 int r;
23467 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
23468diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
23469index df4176c..23ce092 100644
23470--- a/arch/x86/lguest/boot.c
23471+++ b/arch/x86/lguest/boot.c
23472@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
23473 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
23474 * Launcher to reboot us.
23475 */
23476-static void lguest_restart(char *reason)
23477+static __noreturn void lguest_restart(char *reason)
23478 {
23479 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
23480+ BUG();
23481 }
23482
23483 /*G:050
23484diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
23485index 00933d5..3a64af9 100644
23486--- a/arch/x86/lib/atomic64_386_32.S
23487+++ b/arch/x86/lib/atomic64_386_32.S
23488@@ -48,6 +48,10 @@ BEGIN(read)
23489 movl (v), %eax
23490 movl 4(v), %edx
23491 RET_ENDP
23492+BEGIN(read_unchecked)
23493+ movl (v), %eax
23494+ movl 4(v), %edx
23495+RET_ENDP
23496 #undef v
23497
23498 #define v %esi
23499@@ -55,6 +59,10 @@ BEGIN(set)
23500 movl %ebx, (v)
23501 movl %ecx, 4(v)
23502 RET_ENDP
23503+BEGIN(set_unchecked)
23504+ movl %ebx, (v)
23505+ movl %ecx, 4(v)
23506+RET_ENDP
23507 #undef v
23508
23509 #define v %esi
23510@@ -70,6 +78,20 @@ RET_ENDP
23511 BEGIN(add)
23512 addl %eax, (v)
23513 adcl %edx, 4(v)
23514+
23515+#ifdef CONFIG_PAX_REFCOUNT
23516+ jno 0f
23517+ subl %eax, (v)
23518+ sbbl %edx, 4(v)
23519+ int $4
23520+0:
23521+ _ASM_EXTABLE(0b, 0b)
23522+#endif
23523+
23524+RET_ENDP
23525+BEGIN(add_unchecked)
23526+ addl %eax, (v)
23527+ adcl %edx, 4(v)
23528 RET_ENDP
23529 #undef v
23530
23531@@ -77,6 +99,24 @@ RET_ENDP
23532 BEGIN(add_return)
23533 addl (v), %eax
23534 adcl 4(v), %edx
23535+
23536+#ifdef CONFIG_PAX_REFCOUNT
23537+ into
23538+1234:
23539+ _ASM_EXTABLE(1234b, 2f)
23540+#endif
23541+
23542+ movl %eax, (v)
23543+ movl %edx, 4(v)
23544+
23545+#ifdef CONFIG_PAX_REFCOUNT
23546+2:
23547+#endif
23548+
23549+RET_ENDP
23550+BEGIN(add_return_unchecked)
23551+ addl (v), %eax
23552+ adcl 4(v), %edx
23553 movl %eax, (v)
23554 movl %edx, 4(v)
23555 RET_ENDP
23556@@ -86,6 +126,20 @@ RET_ENDP
23557 BEGIN(sub)
23558 subl %eax, (v)
23559 sbbl %edx, 4(v)
23560+
23561+#ifdef CONFIG_PAX_REFCOUNT
23562+ jno 0f
23563+ addl %eax, (v)
23564+ adcl %edx, 4(v)
23565+ int $4
23566+0:
23567+ _ASM_EXTABLE(0b, 0b)
23568+#endif
23569+
23570+RET_ENDP
23571+BEGIN(sub_unchecked)
23572+ subl %eax, (v)
23573+ sbbl %edx, 4(v)
23574 RET_ENDP
23575 #undef v
23576
23577@@ -96,6 +150,27 @@ BEGIN(sub_return)
23578 sbbl $0, %edx
23579 addl (v), %eax
23580 adcl 4(v), %edx
23581+
23582+#ifdef CONFIG_PAX_REFCOUNT
23583+ into
23584+1234:
23585+ _ASM_EXTABLE(1234b, 2f)
23586+#endif
23587+
23588+ movl %eax, (v)
23589+ movl %edx, 4(v)
23590+
23591+#ifdef CONFIG_PAX_REFCOUNT
23592+2:
23593+#endif
23594+
23595+RET_ENDP
23596+BEGIN(sub_return_unchecked)
23597+ negl %edx
23598+ negl %eax
23599+ sbbl $0, %edx
23600+ addl (v), %eax
23601+ adcl 4(v), %edx
23602 movl %eax, (v)
23603 movl %edx, 4(v)
23604 RET_ENDP
23605@@ -105,6 +180,20 @@ RET_ENDP
23606 BEGIN(inc)
23607 addl $1, (v)
23608 adcl $0, 4(v)
23609+
23610+#ifdef CONFIG_PAX_REFCOUNT
23611+ jno 0f
23612+ subl $1, (v)
23613+ sbbl $0, 4(v)
23614+ int $4
23615+0:
23616+ _ASM_EXTABLE(0b, 0b)
23617+#endif
23618+
23619+RET_ENDP
23620+BEGIN(inc_unchecked)
23621+ addl $1, (v)
23622+ adcl $0, 4(v)
23623 RET_ENDP
23624 #undef v
23625
23626@@ -114,6 +203,26 @@ BEGIN(inc_return)
23627 movl 4(v), %edx
23628 addl $1, %eax
23629 adcl $0, %edx
23630+
23631+#ifdef CONFIG_PAX_REFCOUNT
23632+ into
23633+1234:
23634+ _ASM_EXTABLE(1234b, 2f)
23635+#endif
23636+
23637+ movl %eax, (v)
23638+ movl %edx, 4(v)
23639+
23640+#ifdef CONFIG_PAX_REFCOUNT
23641+2:
23642+#endif
23643+
23644+RET_ENDP
23645+BEGIN(inc_return_unchecked)
23646+ movl (v), %eax
23647+ movl 4(v), %edx
23648+ addl $1, %eax
23649+ adcl $0, %edx
23650 movl %eax, (v)
23651 movl %edx, 4(v)
23652 RET_ENDP
23653@@ -123,6 +232,20 @@ RET_ENDP
23654 BEGIN(dec)
23655 subl $1, (v)
23656 sbbl $0, 4(v)
23657+
23658+#ifdef CONFIG_PAX_REFCOUNT
23659+ jno 0f
23660+ addl $1, (v)
23661+ adcl $0, 4(v)
23662+ int $4
23663+0:
23664+ _ASM_EXTABLE(0b, 0b)
23665+#endif
23666+
23667+RET_ENDP
23668+BEGIN(dec_unchecked)
23669+ subl $1, (v)
23670+ sbbl $0, 4(v)
23671 RET_ENDP
23672 #undef v
23673
23674@@ -132,6 +255,26 @@ BEGIN(dec_return)
23675 movl 4(v), %edx
23676 subl $1, %eax
23677 sbbl $0, %edx
23678+
23679+#ifdef CONFIG_PAX_REFCOUNT
23680+ into
23681+1234:
23682+ _ASM_EXTABLE(1234b, 2f)
23683+#endif
23684+
23685+ movl %eax, (v)
23686+ movl %edx, 4(v)
23687+
23688+#ifdef CONFIG_PAX_REFCOUNT
23689+2:
23690+#endif
23691+
23692+RET_ENDP
23693+BEGIN(dec_return_unchecked)
23694+ movl (v), %eax
23695+ movl 4(v), %edx
23696+ subl $1, %eax
23697+ sbbl $0, %edx
23698 movl %eax, (v)
23699 movl %edx, 4(v)
23700 RET_ENDP
23701@@ -143,6 +286,13 @@ BEGIN(add_unless)
23702 adcl %edx, %edi
23703 addl (v), %eax
23704 adcl 4(v), %edx
23705+
23706+#ifdef CONFIG_PAX_REFCOUNT
23707+ into
23708+1234:
23709+ _ASM_EXTABLE(1234b, 2f)
23710+#endif
23711+
23712 cmpl %eax, %ecx
23713 je 3f
23714 1:
23715@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
23716 1:
23717 addl $1, %eax
23718 adcl $0, %edx
23719+
23720+#ifdef CONFIG_PAX_REFCOUNT
23721+ into
23722+1234:
23723+ _ASM_EXTABLE(1234b, 2f)
23724+#endif
23725+
23726 movl %eax, (v)
23727 movl %edx, 4(v)
23728 movl $1, %eax
23729@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
23730 movl 4(v), %edx
23731 subl $1, %eax
23732 sbbl $0, %edx
23733+
23734+#ifdef CONFIG_PAX_REFCOUNT
23735+ into
23736+1234:
23737+ _ASM_EXTABLE(1234b, 1f)
23738+#endif
23739+
23740 js 1f
23741 movl %eax, (v)
23742 movl %edx, 4(v)
23743diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
23744index f5cc9eb..51fa319 100644
23745--- a/arch/x86/lib/atomic64_cx8_32.S
23746+++ b/arch/x86/lib/atomic64_cx8_32.S
23747@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
23748 CFI_STARTPROC
23749
23750 read64 %ecx
23751+ pax_force_retaddr
23752 ret
23753 CFI_ENDPROC
23754 ENDPROC(atomic64_read_cx8)
23755
23756+ENTRY(atomic64_read_unchecked_cx8)
23757+ CFI_STARTPROC
23758+
23759+ read64 %ecx
23760+ pax_force_retaddr
23761+ ret
23762+ CFI_ENDPROC
23763+ENDPROC(atomic64_read_unchecked_cx8)
23764+
23765 ENTRY(atomic64_set_cx8)
23766 CFI_STARTPROC
23767
23768@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
23769 cmpxchg8b (%esi)
23770 jne 1b
23771
23772+ pax_force_retaddr
23773 ret
23774 CFI_ENDPROC
23775 ENDPROC(atomic64_set_cx8)
23776
23777+ENTRY(atomic64_set_unchecked_cx8)
23778+ CFI_STARTPROC
23779+
23780+1:
23781+/* we don't need LOCK_PREFIX since aligned 64-bit writes
23782+ * are atomic on 586 and newer */
23783+ cmpxchg8b (%esi)
23784+ jne 1b
23785+
23786+ pax_force_retaddr
23787+ ret
23788+ CFI_ENDPROC
23789+ENDPROC(atomic64_set_unchecked_cx8)
23790+
23791 ENTRY(atomic64_xchg_cx8)
23792 CFI_STARTPROC
23793
23794@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
23795 cmpxchg8b (%esi)
23796 jne 1b
23797
23798+ pax_force_retaddr
23799 ret
23800 CFI_ENDPROC
23801 ENDPROC(atomic64_xchg_cx8)
23802
23803-.macro addsub_return func ins insc
23804-ENTRY(atomic64_\func\()_return_cx8)
23805+.macro addsub_return func ins insc unchecked=""
23806+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
23807 CFI_STARTPROC
23808 SAVE ebp
23809 SAVE ebx
23810@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
23811 movl %edx, %ecx
23812 \ins\()l %esi, %ebx
23813 \insc\()l %edi, %ecx
23814+
23815+.ifb \unchecked
23816+#ifdef CONFIG_PAX_REFCOUNT
23817+ into
23818+2:
23819+ _ASM_EXTABLE(2b, 3f)
23820+#endif
23821+.endif
23822+
23823 LOCK_PREFIX
23824 cmpxchg8b (%ebp)
23825 jne 1b
23826-
23827-10:
23828 movl %ebx, %eax
23829 movl %ecx, %edx
23830+
23831+.ifb \unchecked
23832+#ifdef CONFIG_PAX_REFCOUNT
23833+3:
23834+#endif
23835+.endif
23836+
23837 RESTORE edi
23838 RESTORE esi
23839 RESTORE ebx
23840 RESTORE ebp
23841+ pax_force_retaddr
23842 ret
23843 CFI_ENDPROC
23844-ENDPROC(atomic64_\func\()_return_cx8)
23845+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
23846 .endm
23847
23848 addsub_return add add adc
23849 addsub_return sub sub sbb
23850+addsub_return add add adc _unchecked
23851+addsub_return sub sub sbb _unchecked
23852
23853-.macro incdec_return func ins insc
23854-ENTRY(atomic64_\func\()_return_cx8)
23855+.macro incdec_return func ins insc unchecked=""
23856+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
23857 CFI_STARTPROC
23858 SAVE ebx
23859
23860@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
23861 movl %edx, %ecx
23862 \ins\()l $1, %ebx
23863 \insc\()l $0, %ecx
23864+
23865+.ifb \unchecked
23866+#ifdef CONFIG_PAX_REFCOUNT
23867+ into
23868+2:
23869+ _ASM_EXTABLE(2b, 3f)
23870+#endif
23871+.endif
23872+
23873 LOCK_PREFIX
23874 cmpxchg8b (%esi)
23875 jne 1b
23876
23877-10:
23878 movl %ebx, %eax
23879 movl %ecx, %edx
23880+
23881+.ifb \unchecked
23882+#ifdef CONFIG_PAX_REFCOUNT
23883+3:
23884+#endif
23885+.endif
23886+
23887 RESTORE ebx
23888+ pax_force_retaddr
23889 ret
23890 CFI_ENDPROC
23891-ENDPROC(atomic64_\func\()_return_cx8)
23892+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
23893 .endm
23894
23895 incdec_return inc add adc
23896 incdec_return dec sub sbb
23897+incdec_return inc add adc _unchecked
23898+incdec_return dec sub sbb _unchecked
23899
23900 ENTRY(atomic64_dec_if_positive_cx8)
23901 CFI_STARTPROC
23902@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
23903 movl %edx, %ecx
23904 subl $1, %ebx
23905 sbb $0, %ecx
23906+
23907+#ifdef CONFIG_PAX_REFCOUNT
23908+ into
23909+1234:
23910+ _ASM_EXTABLE(1234b, 2f)
23911+#endif
23912+
23913 js 2f
23914 LOCK_PREFIX
23915 cmpxchg8b (%esi)
23916@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
23917 movl %ebx, %eax
23918 movl %ecx, %edx
23919 RESTORE ebx
23920+ pax_force_retaddr
23921 ret
23922 CFI_ENDPROC
23923 ENDPROC(atomic64_dec_if_positive_cx8)
23924@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
23925 movl %edx, %ecx
23926 addl %ebp, %ebx
23927 adcl %edi, %ecx
23928+
23929+#ifdef CONFIG_PAX_REFCOUNT
23930+ into
23931+1234:
23932+ _ASM_EXTABLE(1234b, 3f)
23933+#endif
23934+
23935 LOCK_PREFIX
23936 cmpxchg8b (%esi)
23937 jne 1b
23938@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
23939 CFI_ADJUST_CFA_OFFSET -8
23940 RESTORE ebx
23941 RESTORE ebp
23942+ pax_force_retaddr
23943 ret
23944 4:
23945 cmpl %edx, 4(%esp)
23946@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
23947 xorl %ecx, %ecx
23948 addl $1, %ebx
23949 adcl %edx, %ecx
23950+
23951+#ifdef CONFIG_PAX_REFCOUNT
23952+ into
23953+1234:
23954+ _ASM_EXTABLE(1234b, 3f)
23955+#endif
23956+
23957 LOCK_PREFIX
23958 cmpxchg8b (%esi)
23959 jne 1b
23960@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
23961 movl $1, %eax
23962 3:
23963 RESTORE ebx
23964+ pax_force_retaddr
23965 ret
23966 CFI_ENDPROC
23967 ENDPROC(atomic64_inc_not_zero_cx8)
23968diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
23969index 2af5df3..62b1a5a 100644
23970--- a/arch/x86/lib/checksum_32.S
23971+++ b/arch/x86/lib/checksum_32.S
23972@@ -29,7 +29,8 @@
23973 #include <asm/dwarf2.h>
23974 #include <asm/errno.h>
23975 #include <asm/asm.h>
23976-
23977+#include <asm/segment.h>
23978+
23979 /*
23980 * computes a partial checksum, e.g. for TCP/UDP fragments
23981 */
23982@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
23983
23984 #define ARGBASE 16
23985 #define FP 12
23986-
23987-ENTRY(csum_partial_copy_generic)
23988+
23989+ENTRY(csum_partial_copy_generic_to_user)
23990 CFI_STARTPROC
23991+
23992+#ifdef CONFIG_PAX_MEMORY_UDEREF
23993+ pushl_cfi %gs
23994+ popl_cfi %es
23995+ jmp csum_partial_copy_generic
23996+#endif
23997+
23998+ENTRY(csum_partial_copy_generic_from_user)
23999+
24000+#ifdef CONFIG_PAX_MEMORY_UDEREF
24001+ pushl_cfi %gs
24002+ popl_cfi %ds
24003+#endif
24004+
24005+ENTRY(csum_partial_copy_generic)
24006 subl $4,%esp
24007 CFI_ADJUST_CFA_OFFSET 4
24008 pushl_cfi %edi
24009@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
24010 jmp 4f
24011 SRC(1: movw (%esi), %bx )
24012 addl $2, %esi
24013-DST( movw %bx, (%edi) )
24014+DST( movw %bx, %es:(%edi) )
24015 addl $2, %edi
24016 addw %bx, %ax
24017 adcl $0, %eax
24018@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
24019 SRC(1: movl (%esi), %ebx )
24020 SRC( movl 4(%esi), %edx )
24021 adcl %ebx, %eax
24022-DST( movl %ebx, (%edi) )
24023+DST( movl %ebx, %es:(%edi) )
24024 adcl %edx, %eax
24025-DST( movl %edx, 4(%edi) )
24026+DST( movl %edx, %es:4(%edi) )
24027
24028 SRC( movl 8(%esi), %ebx )
24029 SRC( movl 12(%esi), %edx )
24030 adcl %ebx, %eax
24031-DST( movl %ebx, 8(%edi) )
24032+DST( movl %ebx, %es:8(%edi) )
24033 adcl %edx, %eax
24034-DST( movl %edx, 12(%edi) )
24035+DST( movl %edx, %es:12(%edi) )
24036
24037 SRC( movl 16(%esi), %ebx )
24038 SRC( movl 20(%esi), %edx )
24039 adcl %ebx, %eax
24040-DST( movl %ebx, 16(%edi) )
24041+DST( movl %ebx, %es:16(%edi) )
24042 adcl %edx, %eax
24043-DST( movl %edx, 20(%edi) )
24044+DST( movl %edx, %es:20(%edi) )
24045
24046 SRC( movl 24(%esi), %ebx )
24047 SRC( movl 28(%esi), %edx )
24048 adcl %ebx, %eax
24049-DST( movl %ebx, 24(%edi) )
24050+DST( movl %ebx, %es:24(%edi) )
24051 adcl %edx, %eax
24052-DST( movl %edx, 28(%edi) )
24053+DST( movl %edx, %es:28(%edi) )
24054
24055 lea 32(%esi), %esi
24056 lea 32(%edi), %edi
24057@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
24058 shrl $2, %edx # This clears CF
24059 SRC(3: movl (%esi), %ebx )
24060 adcl %ebx, %eax
24061-DST( movl %ebx, (%edi) )
24062+DST( movl %ebx, %es:(%edi) )
24063 lea 4(%esi), %esi
24064 lea 4(%edi), %edi
24065 dec %edx
24066@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
24067 jb 5f
24068 SRC( movw (%esi), %cx )
24069 leal 2(%esi), %esi
24070-DST( movw %cx, (%edi) )
24071+DST( movw %cx, %es:(%edi) )
24072 leal 2(%edi), %edi
24073 je 6f
24074 shll $16,%ecx
24075 SRC(5: movb (%esi), %cl )
24076-DST( movb %cl, (%edi) )
24077+DST( movb %cl, %es:(%edi) )
24078 6: addl %ecx, %eax
24079 adcl $0, %eax
24080 7:
24081@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
24082
24083 6001:
24084 movl ARGBASE+20(%esp), %ebx # src_err_ptr
24085- movl $-EFAULT, (%ebx)
24086+ movl $-EFAULT, %ss:(%ebx)
24087
24088 # zero the complete destination - computing the rest
24089 # is too much work
24090@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
24091
24092 6002:
24093 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24094- movl $-EFAULT,(%ebx)
24095+ movl $-EFAULT,%ss:(%ebx)
24096 jmp 5000b
24097
24098 .previous
24099
24100+ pushl_cfi %ss
24101+ popl_cfi %ds
24102+ pushl_cfi %ss
24103+ popl_cfi %es
24104 popl_cfi %ebx
24105 CFI_RESTORE ebx
24106 popl_cfi %esi
24107@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
24108 popl_cfi %ecx # equivalent to addl $4,%esp
24109 ret
24110 CFI_ENDPROC
24111-ENDPROC(csum_partial_copy_generic)
24112+ENDPROC(csum_partial_copy_generic_to_user)
24113
24114 #else
24115
24116 /* Version for PentiumII/PPro */
24117
24118 #define ROUND1(x) \
24119+ nop; nop; nop; \
24120 SRC(movl x(%esi), %ebx ) ; \
24121 addl %ebx, %eax ; \
24122- DST(movl %ebx, x(%edi) ) ;
24123+ DST(movl %ebx, %es:x(%edi)) ;
24124
24125 #define ROUND(x) \
24126+ nop; nop; nop; \
24127 SRC(movl x(%esi), %ebx ) ; \
24128 adcl %ebx, %eax ; \
24129- DST(movl %ebx, x(%edi) ) ;
24130+ DST(movl %ebx, %es:x(%edi)) ;
24131
24132 #define ARGBASE 12
24133-
24134-ENTRY(csum_partial_copy_generic)
24135+
24136+ENTRY(csum_partial_copy_generic_to_user)
24137 CFI_STARTPROC
24138+
24139+#ifdef CONFIG_PAX_MEMORY_UDEREF
24140+ pushl_cfi %gs
24141+ popl_cfi %es
24142+ jmp csum_partial_copy_generic
24143+#endif
24144+
24145+ENTRY(csum_partial_copy_generic_from_user)
24146+
24147+#ifdef CONFIG_PAX_MEMORY_UDEREF
24148+ pushl_cfi %gs
24149+ popl_cfi %ds
24150+#endif
24151+
24152+ENTRY(csum_partial_copy_generic)
24153 pushl_cfi %ebx
24154 CFI_REL_OFFSET ebx, 0
24155 pushl_cfi %edi
24156@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
24157 subl %ebx, %edi
24158 lea -1(%esi),%edx
24159 andl $-32,%edx
24160- lea 3f(%ebx,%ebx), %ebx
24161+ lea 3f(%ebx,%ebx,2), %ebx
24162 testl %esi, %esi
24163 jmp *%ebx
24164 1: addl $64,%esi
24165@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
24166 jb 5f
24167 SRC( movw (%esi), %dx )
24168 leal 2(%esi), %esi
24169-DST( movw %dx, (%edi) )
24170+DST( movw %dx, %es:(%edi) )
24171 leal 2(%edi), %edi
24172 je 6f
24173 shll $16,%edx
24174 5:
24175 SRC( movb (%esi), %dl )
24176-DST( movb %dl, (%edi) )
24177+DST( movb %dl, %es:(%edi) )
24178 6: addl %edx, %eax
24179 adcl $0, %eax
24180 7:
24181 .section .fixup, "ax"
24182 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
24183- movl $-EFAULT, (%ebx)
24184+ movl $-EFAULT, %ss:(%ebx)
24185 # zero the complete destination (computing the rest is too much work)
24186 movl ARGBASE+8(%esp),%edi # dst
24187 movl ARGBASE+12(%esp),%ecx # len
24188@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
24189 rep; stosb
24190 jmp 7b
24191 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24192- movl $-EFAULT, (%ebx)
24193+ movl $-EFAULT, %ss:(%ebx)
24194 jmp 7b
24195 .previous
24196
24197+#ifdef CONFIG_PAX_MEMORY_UDEREF
24198+ pushl_cfi %ss
24199+ popl_cfi %ds
24200+ pushl_cfi %ss
24201+ popl_cfi %es
24202+#endif
24203+
24204 popl_cfi %esi
24205 CFI_RESTORE esi
24206 popl_cfi %edi
24207@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
24208 CFI_RESTORE ebx
24209 ret
24210 CFI_ENDPROC
24211-ENDPROC(csum_partial_copy_generic)
24212+ENDPROC(csum_partial_copy_generic_to_user)
24213
24214 #undef ROUND
24215 #undef ROUND1
24216diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
24217index f2145cf..cea889d 100644
24218--- a/arch/x86/lib/clear_page_64.S
24219+++ b/arch/x86/lib/clear_page_64.S
24220@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
24221 movl $4096/8,%ecx
24222 xorl %eax,%eax
24223 rep stosq
24224+ pax_force_retaddr
24225 ret
24226 CFI_ENDPROC
24227 ENDPROC(clear_page_c)
24228@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
24229 movl $4096,%ecx
24230 xorl %eax,%eax
24231 rep stosb
24232+ pax_force_retaddr
24233 ret
24234 CFI_ENDPROC
24235 ENDPROC(clear_page_c_e)
24236@@ -43,6 +45,7 @@ ENTRY(clear_page)
24237 leaq 64(%rdi),%rdi
24238 jnz .Lloop
24239 nop
24240+ pax_force_retaddr
24241 ret
24242 CFI_ENDPROC
24243 .Lclear_page_end:
24244@@ -58,7 +61,7 @@ ENDPROC(clear_page)
24245
24246 #include <asm/cpufeature.h>
24247
24248- .section .altinstr_replacement,"ax"
24249+ .section .altinstr_replacement,"a"
24250 1: .byte 0xeb /* jmp <disp8> */
24251 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
24252 2: .byte 0xeb /* jmp <disp8> */
24253diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
24254index 1e572c5..2a162cd 100644
24255--- a/arch/x86/lib/cmpxchg16b_emu.S
24256+++ b/arch/x86/lib/cmpxchg16b_emu.S
24257@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
24258
24259 popf
24260 mov $1, %al
24261+ pax_force_retaddr
24262 ret
24263
24264 not_same:
24265 popf
24266 xor %al,%al
24267+ pax_force_retaddr
24268 ret
24269
24270 CFI_ENDPROC
24271diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
24272index 176cca6..1166c50 100644
24273--- a/arch/x86/lib/copy_page_64.S
24274+++ b/arch/x86/lib/copy_page_64.S
24275@@ -9,6 +9,7 @@ copy_page_rep:
24276 CFI_STARTPROC
24277 movl $4096/8, %ecx
24278 rep movsq
24279+ pax_force_retaddr
24280 ret
24281 CFI_ENDPROC
24282 ENDPROC(copy_page_rep)
24283@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
24284
24285 ENTRY(copy_page)
24286 CFI_STARTPROC
24287- subq $2*8, %rsp
24288- CFI_ADJUST_CFA_OFFSET 2*8
24289+ subq $3*8, %rsp
24290+ CFI_ADJUST_CFA_OFFSET 3*8
24291 movq %rbx, (%rsp)
24292 CFI_REL_OFFSET rbx, 0
24293 movq %r12, 1*8(%rsp)
24294 CFI_REL_OFFSET r12, 1*8
24295+ movq %r13, 2*8(%rsp)
24296+ CFI_REL_OFFSET r13, 2*8
24297
24298 movl $(4096/64)-5, %ecx
24299 .p2align 4
24300@@ -36,7 +39,7 @@ ENTRY(copy_page)
24301 movq 0x8*2(%rsi), %rdx
24302 movq 0x8*3(%rsi), %r8
24303 movq 0x8*4(%rsi), %r9
24304- movq 0x8*5(%rsi), %r10
24305+ movq 0x8*5(%rsi), %r13
24306 movq 0x8*6(%rsi), %r11
24307 movq 0x8*7(%rsi), %r12
24308
24309@@ -47,7 +50,7 @@ ENTRY(copy_page)
24310 movq %rdx, 0x8*2(%rdi)
24311 movq %r8, 0x8*3(%rdi)
24312 movq %r9, 0x8*4(%rdi)
24313- movq %r10, 0x8*5(%rdi)
24314+ movq %r13, 0x8*5(%rdi)
24315 movq %r11, 0x8*6(%rdi)
24316 movq %r12, 0x8*7(%rdi)
24317
24318@@ -66,7 +69,7 @@ ENTRY(copy_page)
24319 movq 0x8*2(%rsi), %rdx
24320 movq 0x8*3(%rsi), %r8
24321 movq 0x8*4(%rsi), %r9
24322- movq 0x8*5(%rsi), %r10
24323+ movq 0x8*5(%rsi), %r13
24324 movq 0x8*6(%rsi), %r11
24325 movq 0x8*7(%rsi), %r12
24326
24327@@ -75,7 +78,7 @@ ENTRY(copy_page)
24328 movq %rdx, 0x8*2(%rdi)
24329 movq %r8, 0x8*3(%rdi)
24330 movq %r9, 0x8*4(%rdi)
24331- movq %r10, 0x8*5(%rdi)
24332+ movq %r13, 0x8*5(%rdi)
24333 movq %r11, 0x8*6(%rdi)
24334 movq %r12, 0x8*7(%rdi)
24335
24336@@ -87,8 +90,11 @@ ENTRY(copy_page)
24337 CFI_RESTORE rbx
24338 movq 1*8(%rsp), %r12
24339 CFI_RESTORE r12
24340- addq $2*8, %rsp
24341- CFI_ADJUST_CFA_OFFSET -2*8
24342+ movq 2*8(%rsp), %r13
24343+ CFI_RESTORE r13
24344+ addq $3*8, %rsp
24345+ CFI_ADJUST_CFA_OFFSET -3*8
24346+ pax_force_retaddr
24347 ret
24348 .Lcopy_page_end:
24349 CFI_ENDPROC
24350@@ -99,7 +105,7 @@ ENDPROC(copy_page)
24351
24352 #include <asm/cpufeature.h>
24353
24354- .section .altinstr_replacement,"ax"
24355+ .section .altinstr_replacement,"a"
24356 1: .byte 0xeb /* jmp <disp8> */
24357 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
24358 2:
24359diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
24360index a30ca15..d25fab6 100644
24361--- a/arch/x86/lib/copy_user_64.S
24362+++ b/arch/x86/lib/copy_user_64.S
24363@@ -18,6 +18,7 @@
24364 #include <asm/alternative-asm.h>
24365 #include <asm/asm.h>
24366 #include <asm/smap.h>
24367+#include <asm/pgtable.h>
24368
24369 /*
24370 * By placing feature2 after feature1 in altinstructions section, we logically
24371@@ -31,7 +32,7 @@
24372 .byte 0xe9 /* 32bit jump */
24373 .long \orig-1f /* by default jump to orig */
24374 1:
24375- .section .altinstr_replacement,"ax"
24376+ .section .altinstr_replacement,"a"
24377 2: .byte 0xe9 /* near jump with 32bit immediate */
24378 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
24379 3: .byte 0xe9 /* near jump with 32bit immediate */
24380@@ -70,47 +71,20 @@
24381 #endif
24382 .endm
24383
24384-/* Standard copy_to_user with segment limit checking */
24385-ENTRY(_copy_to_user)
24386- CFI_STARTPROC
24387- GET_THREAD_INFO(%rax)
24388- movq %rdi,%rcx
24389- addq %rdx,%rcx
24390- jc bad_to_user
24391- cmpq TI_addr_limit(%rax),%rcx
24392- ja bad_to_user
24393- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
24394- copy_user_generic_unrolled,copy_user_generic_string, \
24395- copy_user_enhanced_fast_string
24396- CFI_ENDPROC
24397-ENDPROC(_copy_to_user)
24398-
24399-/* Standard copy_from_user with segment limit checking */
24400-ENTRY(_copy_from_user)
24401- CFI_STARTPROC
24402- GET_THREAD_INFO(%rax)
24403- movq %rsi,%rcx
24404- addq %rdx,%rcx
24405- jc bad_from_user
24406- cmpq TI_addr_limit(%rax),%rcx
24407- ja bad_from_user
24408- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
24409- copy_user_generic_unrolled,copy_user_generic_string, \
24410- copy_user_enhanced_fast_string
24411- CFI_ENDPROC
24412-ENDPROC(_copy_from_user)
24413-
24414 .section .fixup,"ax"
24415 /* must zero dest */
24416 ENTRY(bad_from_user)
24417 bad_from_user:
24418 CFI_STARTPROC
24419+ testl %edx,%edx
24420+ js bad_to_user
24421 movl %edx,%ecx
24422 xorl %eax,%eax
24423 rep
24424 stosb
24425 bad_to_user:
24426 movl %edx,%eax
24427+ pax_force_retaddr
24428 ret
24429 CFI_ENDPROC
24430 ENDPROC(bad_from_user)
24431@@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
24432 jz 17f
24433 1: movq (%rsi),%r8
24434 2: movq 1*8(%rsi),%r9
24435-3: movq 2*8(%rsi),%r10
24436+3: movq 2*8(%rsi),%rax
24437 4: movq 3*8(%rsi),%r11
24438 5: movq %r8,(%rdi)
24439 6: movq %r9,1*8(%rdi)
24440-7: movq %r10,2*8(%rdi)
24441+7: movq %rax,2*8(%rdi)
24442 8: movq %r11,3*8(%rdi)
24443 9: movq 4*8(%rsi),%r8
24444 10: movq 5*8(%rsi),%r9
24445-11: movq 6*8(%rsi),%r10
24446+11: movq 6*8(%rsi),%rax
24447 12: movq 7*8(%rsi),%r11
24448 13: movq %r8,4*8(%rdi)
24449 14: movq %r9,5*8(%rdi)
24450-15: movq %r10,6*8(%rdi)
24451+15: movq %rax,6*8(%rdi)
24452 16: movq %r11,7*8(%rdi)
24453 leaq 64(%rsi),%rsi
24454 leaq 64(%rdi),%rdi
24455@@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
24456 jnz 21b
24457 23: xor %eax,%eax
24458 ASM_CLAC
24459+ pax_force_retaddr
24460 ret
24461
24462 .section .fixup,"ax"
24463@@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
24464 movsb
24465 4: xorl %eax,%eax
24466 ASM_CLAC
24467+ pax_force_retaddr
24468 ret
24469
24470 .section .fixup,"ax"
24471@@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
24472 movsb
24473 2: xorl %eax,%eax
24474 ASM_CLAC
24475+ pax_force_retaddr
24476 ret
24477
24478 .section .fixup,"ax"
24479diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
24480index 6a4f43c..f5f9e26 100644
24481--- a/arch/x86/lib/copy_user_nocache_64.S
24482+++ b/arch/x86/lib/copy_user_nocache_64.S
24483@@ -8,6 +8,7 @@
24484
24485 #include <linux/linkage.h>
24486 #include <asm/dwarf2.h>
24487+#include <asm/alternative-asm.h>
24488
24489 #define FIX_ALIGNMENT 1
24490
24491@@ -16,6 +17,7 @@
24492 #include <asm/thread_info.h>
24493 #include <asm/asm.h>
24494 #include <asm/smap.h>
24495+#include <asm/pgtable.h>
24496
24497 .macro ALIGN_DESTINATION
24498 #ifdef FIX_ALIGNMENT
24499@@ -49,6 +51,15 @@
24500 */
24501 ENTRY(__copy_user_nocache)
24502 CFI_STARTPROC
24503+
24504+#ifdef CONFIG_PAX_MEMORY_UDEREF
24505+ mov $PAX_USER_SHADOW_BASE,%rcx
24506+ cmp %rcx,%rsi
24507+ jae 1f
24508+ add %rcx,%rsi
24509+1:
24510+#endif
24511+
24512 ASM_STAC
24513 cmpl $8,%edx
24514 jb 20f /* less then 8 bytes, go to byte copy loop */
24515@@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
24516 jz 17f
24517 1: movq (%rsi),%r8
24518 2: movq 1*8(%rsi),%r9
24519-3: movq 2*8(%rsi),%r10
24520+3: movq 2*8(%rsi),%rax
24521 4: movq 3*8(%rsi),%r11
24522 5: movnti %r8,(%rdi)
24523 6: movnti %r9,1*8(%rdi)
24524-7: movnti %r10,2*8(%rdi)
24525+7: movnti %rax,2*8(%rdi)
24526 8: movnti %r11,3*8(%rdi)
24527 9: movq 4*8(%rsi),%r8
24528 10: movq 5*8(%rsi),%r9
24529-11: movq 6*8(%rsi),%r10
24530+11: movq 6*8(%rsi),%rax
24531 12: movq 7*8(%rsi),%r11
24532 13: movnti %r8,4*8(%rdi)
24533 14: movnti %r9,5*8(%rdi)
24534-15: movnti %r10,6*8(%rdi)
24535+15: movnti %rax,6*8(%rdi)
24536 16: movnti %r11,7*8(%rdi)
24537 leaq 64(%rsi),%rsi
24538 leaq 64(%rdi),%rdi
24539@@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
24540 23: xorl %eax,%eax
24541 ASM_CLAC
24542 sfence
24543+ pax_force_retaddr
24544 ret
24545
24546 .section .fixup,"ax"
24547diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
24548index 2419d5f..953ee51 100644
24549--- a/arch/x86/lib/csum-copy_64.S
24550+++ b/arch/x86/lib/csum-copy_64.S
24551@@ -9,6 +9,7 @@
24552 #include <asm/dwarf2.h>
24553 #include <asm/errno.h>
24554 #include <asm/asm.h>
24555+#include <asm/alternative-asm.h>
24556
24557 /*
24558 * Checksum copy with exception handling.
24559@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
24560 CFI_RESTORE rbp
24561 addq $7*8, %rsp
24562 CFI_ADJUST_CFA_OFFSET -7*8
24563+ pax_force_retaddr 0, 1
24564 ret
24565 CFI_RESTORE_STATE
24566
24567diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
24568index 25b7ae8..169fafc 100644
24569--- a/arch/x86/lib/csum-wrappers_64.c
24570+++ b/arch/x86/lib/csum-wrappers_64.c
24571@@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
24572 len -= 2;
24573 }
24574 }
24575- isum = csum_partial_copy_generic((__force const void *)src,
24576+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
24577 dst, len, isum, errp, NULL);
24578 if (unlikely(*errp))
24579 goto out_err;
24580@@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
24581 }
24582
24583 *errp = 0;
24584- return csum_partial_copy_generic(src, (void __force *)dst,
24585+ return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
24586 len, isum, NULL, errp);
24587 }
24588 EXPORT_SYMBOL(csum_partial_copy_to_user);
24589diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
24590index 156b9c8..b144132 100644
24591--- a/arch/x86/lib/getuser.S
24592+++ b/arch/x86/lib/getuser.S
24593@@ -34,17 +34,40 @@
24594 #include <asm/thread_info.h>
24595 #include <asm/asm.h>
24596 #include <asm/smap.h>
24597+#include <asm/segment.h>
24598+#include <asm/pgtable.h>
24599+#include <asm/alternative-asm.h>
24600+
24601+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
24602+#define __copyuser_seg gs;
24603+#else
24604+#define __copyuser_seg
24605+#endif
24606
24607 .text
24608 ENTRY(__get_user_1)
24609 CFI_STARTPROC
24610+
24611+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24612 GET_THREAD_INFO(%_ASM_DX)
24613 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24614 jae bad_get_user
24615 ASM_STAC
24616-1: movzb (%_ASM_AX),%edx
24617+
24618+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24619+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24620+ cmp %_ASM_DX,%_ASM_AX
24621+ jae 1234f
24622+ add %_ASM_DX,%_ASM_AX
24623+1234:
24624+#endif
24625+
24626+#endif
24627+
24628+1: __copyuser_seg movzb (%_ASM_AX),%edx
24629 xor %eax,%eax
24630 ASM_CLAC
24631+ pax_force_retaddr
24632 ret
24633 CFI_ENDPROC
24634 ENDPROC(__get_user_1)
24635@@ -52,14 +75,28 @@ ENDPROC(__get_user_1)
24636 ENTRY(__get_user_2)
24637 CFI_STARTPROC
24638 add $1,%_ASM_AX
24639+
24640+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24641 jc bad_get_user
24642 GET_THREAD_INFO(%_ASM_DX)
24643 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24644 jae bad_get_user
24645 ASM_STAC
24646-2: movzwl -1(%_ASM_AX),%edx
24647+
24648+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24649+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24650+ cmp %_ASM_DX,%_ASM_AX
24651+ jae 1234f
24652+ add %_ASM_DX,%_ASM_AX
24653+1234:
24654+#endif
24655+
24656+#endif
24657+
24658+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
24659 xor %eax,%eax
24660 ASM_CLAC
24661+ pax_force_retaddr
24662 ret
24663 CFI_ENDPROC
24664 ENDPROC(__get_user_2)
24665@@ -67,14 +104,28 @@ ENDPROC(__get_user_2)
24666 ENTRY(__get_user_4)
24667 CFI_STARTPROC
24668 add $3,%_ASM_AX
24669+
24670+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24671 jc bad_get_user
24672 GET_THREAD_INFO(%_ASM_DX)
24673 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24674 jae bad_get_user
24675 ASM_STAC
24676-3: mov -3(%_ASM_AX),%edx
24677+
24678+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24679+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24680+ cmp %_ASM_DX,%_ASM_AX
24681+ jae 1234f
24682+ add %_ASM_DX,%_ASM_AX
24683+1234:
24684+#endif
24685+
24686+#endif
24687+
24688+3: __copyuser_seg mov -3(%_ASM_AX),%edx
24689 xor %eax,%eax
24690 ASM_CLAC
24691+ pax_force_retaddr
24692 ret
24693 CFI_ENDPROC
24694 ENDPROC(__get_user_4)
24695@@ -87,10 +138,20 @@ ENTRY(__get_user_8)
24696 GET_THREAD_INFO(%_ASM_DX)
24697 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24698 jae bad_get_user
24699+
24700+#ifdef CONFIG_PAX_MEMORY_UDEREF
24701+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24702+ cmp %_ASM_DX,%_ASM_AX
24703+ jae 1234f
24704+ add %_ASM_DX,%_ASM_AX
24705+1234:
24706+#endif
24707+
24708 ASM_STAC
24709 4: movq -7(%_ASM_AX),%_ASM_DX
24710 xor %eax,%eax
24711 ASM_CLAC
24712+ pax_force_retaddr
24713 ret
24714 CFI_ENDPROC
24715 ENDPROC(__get_user_8)
24716@@ -101,6 +162,7 @@ bad_get_user:
24717 xor %edx,%edx
24718 mov $(-EFAULT),%_ASM_AX
24719 ASM_CLAC
24720+ pax_force_retaddr
24721 ret
24722 CFI_ENDPROC
24723 END(bad_get_user)
24724diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
24725index 54fcffe..7be149e 100644
24726--- a/arch/x86/lib/insn.c
24727+++ b/arch/x86/lib/insn.c
24728@@ -20,8 +20,10 @@
24729
24730 #ifdef __KERNEL__
24731 #include <linux/string.h>
24732+#include <asm/pgtable_types.h>
24733 #else
24734 #include <string.h>
24735+#define ktla_ktva(addr) addr
24736 #endif
24737 #include <asm/inat.h>
24738 #include <asm/insn.h>
24739@@ -53,8 +55,8 @@
24740 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
24741 {
24742 memset(insn, 0, sizeof(*insn));
24743- insn->kaddr = kaddr;
24744- insn->next_byte = kaddr;
24745+ insn->kaddr = ktla_ktva(kaddr);
24746+ insn->next_byte = ktla_ktva(kaddr);
24747 insn->x86_64 = x86_64 ? 1 : 0;
24748 insn->opnd_bytes = 4;
24749 if (x86_64)
24750diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
24751index 05a95e7..326f2fa 100644
24752--- a/arch/x86/lib/iomap_copy_64.S
24753+++ b/arch/x86/lib/iomap_copy_64.S
24754@@ -17,6 +17,7 @@
24755
24756 #include <linux/linkage.h>
24757 #include <asm/dwarf2.h>
24758+#include <asm/alternative-asm.h>
24759
24760 /*
24761 * override generic version in lib/iomap_copy.c
24762@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
24763 CFI_STARTPROC
24764 movl %edx,%ecx
24765 rep movsd
24766+ pax_force_retaddr
24767 ret
24768 CFI_ENDPROC
24769 ENDPROC(__iowrite32_copy)
24770diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
24771index 1c273be..da9cc0e 100644
24772--- a/arch/x86/lib/memcpy_64.S
24773+++ b/arch/x86/lib/memcpy_64.S
24774@@ -33,6 +33,7 @@
24775 rep movsq
24776 movl %edx, %ecx
24777 rep movsb
24778+ pax_force_retaddr
24779 ret
24780 .Lmemcpy_e:
24781 .previous
24782@@ -49,6 +50,7 @@
24783 movq %rdi, %rax
24784 movq %rdx, %rcx
24785 rep movsb
24786+ pax_force_retaddr
24787 ret
24788 .Lmemcpy_e_e:
24789 .previous
24790@@ -76,13 +78,13 @@ ENTRY(memcpy)
24791 */
24792 movq 0*8(%rsi), %r8
24793 movq 1*8(%rsi), %r9
24794- movq 2*8(%rsi), %r10
24795+ movq 2*8(%rsi), %rcx
24796 movq 3*8(%rsi), %r11
24797 leaq 4*8(%rsi), %rsi
24798
24799 movq %r8, 0*8(%rdi)
24800 movq %r9, 1*8(%rdi)
24801- movq %r10, 2*8(%rdi)
24802+ movq %rcx, 2*8(%rdi)
24803 movq %r11, 3*8(%rdi)
24804 leaq 4*8(%rdi), %rdi
24805 jae .Lcopy_forward_loop
24806@@ -105,12 +107,12 @@ ENTRY(memcpy)
24807 subq $0x20, %rdx
24808 movq -1*8(%rsi), %r8
24809 movq -2*8(%rsi), %r9
24810- movq -3*8(%rsi), %r10
24811+ movq -3*8(%rsi), %rcx
24812 movq -4*8(%rsi), %r11
24813 leaq -4*8(%rsi), %rsi
24814 movq %r8, -1*8(%rdi)
24815 movq %r9, -2*8(%rdi)
24816- movq %r10, -3*8(%rdi)
24817+ movq %rcx, -3*8(%rdi)
24818 movq %r11, -4*8(%rdi)
24819 leaq -4*8(%rdi), %rdi
24820 jae .Lcopy_backward_loop
24821@@ -130,12 +132,13 @@ ENTRY(memcpy)
24822 */
24823 movq 0*8(%rsi), %r8
24824 movq 1*8(%rsi), %r9
24825- movq -2*8(%rsi, %rdx), %r10
24826+ movq -2*8(%rsi, %rdx), %rcx
24827 movq -1*8(%rsi, %rdx), %r11
24828 movq %r8, 0*8(%rdi)
24829 movq %r9, 1*8(%rdi)
24830- movq %r10, -2*8(%rdi, %rdx)
24831+ movq %rcx, -2*8(%rdi, %rdx)
24832 movq %r11, -1*8(%rdi, %rdx)
24833+ pax_force_retaddr
24834 retq
24835 .p2align 4
24836 .Lless_16bytes:
24837@@ -148,6 +151,7 @@ ENTRY(memcpy)
24838 movq -1*8(%rsi, %rdx), %r9
24839 movq %r8, 0*8(%rdi)
24840 movq %r9, -1*8(%rdi, %rdx)
24841+ pax_force_retaddr
24842 retq
24843 .p2align 4
24844 .Lless_8bytes:
24845@@ -161,6 +165,7 @@ ENTRY(memcpy)
24846 movl -4(%rsi, %rdx), %r8d
24847 movl %ecx, (%rdi)
24848 movl %r8d, -4(%rdi, %rdx)
24849+ pax_force_retaddr
24850 retq
24851 .p2align 4
24852 .Lless_3bytes:
24853@@ -179,6 +184,7 @@ ENTRY(memcpy)
24854 movb %cl, (%rdi)
24855
24856 .Lend:
24857+ pax_force_retaddr
24858 retq
24859 CFI_ENDPROC
24860 ENDPROC(memcpy)
24861diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
24862index ee16461..c39c199 100644
24863--- a/arch/x86/lib/memmove_64.S
24864+++ b/arch/x86/lib/memmove_64.S
24865@@ -61,13 +61,13 @@ ENTRY(memmove)
24866 5:
24867 sub $0x20, %rdx
24868 movq 0*8(%rsi), %r11
24869- movq 1*8(%rsi), %r10
24870+ movq 1*8(%rsi), %rcx
24871 movq 2*8(%rsi), %r9
24872 movq 3*8(%rsi), %r8
24873 leaq 4*8(%rsi), %rsi
24874
24875 movq %r11, 0*8(%rdi)
24876- movq %r10, 1*8(%rdi)
24877+ movq %rcx, 1*8(%rdi)
24878 movq %r9, 2*8(%rdi)
24879 movq %r8, 3*8(%rdi)
24880 leaq 4*8(%rdi), %rdi
24881@@ -81,10 +81,10 @@ ENTRY(memmove)
24882 4:
24883 movq %rdx, %rcx
24884 movq -8(%rsi, %rdx), %r11
24885- lea -8(%rdi, %rdx), %r10
24886+ lea -8(%rdi, %rdx), %r9
24887 shrq $3, %rcx
24888 rep movsq
24889- movq %r11, (%r10)
24890+ movq %r11, (%r9)
24891 jmp 13f
24892 .Lmemmove_end_forward:
24893
24894@@ -95,14 +95,14 @@ ENTRY(memmove)
24895 7:
24896 movq %rdx, %rcx
24897 movq (%rsi), %r11
24898- movq %rdi, %r10
24899+ movq %rdi, %r9
24900 leaq -8(%rsi, %rdx), %rsi
24901 leaq -8(%rdi, %rdx), %rdi
24902 shrq $3, %rcx
24903 std
24904 rep movsq
24905 cld
24906- movq %r11, (%r10)
24907+ movq %r11, (%r9)
24908 jmp 13f
24909
24910 /*
24911@@ -127,13 +127,13 @@ ENTRY(memmove)
24912 8:
24913 subq $0x20, %rdx
24914 movq -1*8(%rsi), %r11
24915- movq -2*8(%rsi), %r10
24916+ movq -2*8(%rsi), %rcx
24917 movq -3*8(%rsi), %r9
24918 movq -4*8(%rsi), %r8
24919 leaq -4*8(%rsi), %rsi
24920
24921 movq %r11, -1*8(%rdi)
24922- movq %r10, -2*8(%rdi)
24923+ movq %rcx, -2*8(%rdi)
24924 movq %r9, -3*8(%rdi)
24925 movq %r8, -4*8(%rdi)
24926 leaq -4*8(%rdi), %rdi
24927@@ -151,11 +151,11 @@ ENTRY(memmove)
24928 * Move data from 16 bytes to 31 bytes.
24929 */
24930 movq 0*8(%rsi), %r11
24931- movq 1*8(%rsi), %r10
24932+ movq 1*8(%rsi), %rcx
24933 movq -2*8(%rsi, %rdx), %r9
24934 movq -1*8(%rsi, %rdx), %r8
24935 movq %r11, 0*8(%rdi)
24936- movq %r10, 1*8(%rdi)
24937+ movq %rcx, 1*8(%rdi)
24938 movq %r9, -2*8(%rdi, %rdx)
24939 movq %r8, -1*8(%rdi, %rdx)
24940 jmp 13f
24941@@ -167,9 +167,9 @@ ENTRY(memmove)
24942 * Move data from 8 bytes to 15 bytes.
24943 */
24944 movq 0*8(%rsi), %r11
24945- movq -1*8(%rsi, %rdx), %r10
24946+ movq -1*8(%rsi, %rdx), %r9
24947 movq %r11, 0*8(%rdi)
24948- movq %r10, -1*8(%rdi, %rdx)
24949+ movq %r9, -1*8(%rdi, %rdx)
24950 jmp 13f
24951 10:
24952 cmpq $4, %rdx
24953@@ -178,9 +178,9 @@ ENTRY(memmove)
24954 * Move data from 4 bytes to 7 bytes.
24955 */
24956 movl (%rsi), %r11d
24957- movl -4(%rsi, %rdx), %r10d
24958+ movl -4(%rsi, %rdx), %r9d
24959 movl %r11d, (%rdi)
24960- movl %r10d, -4(%rdi, %rdx)
24961+ movl %r9d, -4(%rdi, %rdx)
24962 jmp 13f
24963 11:
24964 cmp $2, %rdx
24965@@ -189,9 +189,9 @@ ENTRY(memmove)
24966 * Move data from 2 bytes to 3 bytes.
24967 */
24968 movw (%rsi), %r11w
24969- movw -2(%rsi, %rdx), %r10w
24970+ movw -2(%rsi, %rdx), %r9w
24971 movw %r11w, (%rdi)
24972- movw %r10w, -2(%rdi, %rdx)
24973+ movw %r9w, -2(%rdi, %rdx)
24974 jmp 13f
24975 12:
24976 cmp $1, %rdx
24977@@ -202,6 +202,7 @@ ENTRY(memmove)
24978 movb (%rsi), %r11b
24979 movb %r11b, (%rdi)
24980 13:
24981+ pax_force_retaddr
24982 retq
24983 CFI_ENDPROC
24984
24985@@ -210,6 +211,7 @@ ENTRY(memmove)
24986 /* Forward moving data. */
24987 movq %rdx, %rcx
24988 rep movsb
24989+ pax_force_retaddr
24990 retq
24991 .Lmemmove_end_forward_efs:
24992 .previous
24993diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
24994index 2dcb380..963660a 100644
24995--- a/arch/x86/lib/memset_64.S
24996+++ b/arch/x86/lib/memset_64.S
24997@@ -30,6 +30,7 @@
24998 movl %edx,%ecx
24999 rep stosb
25000 movq %r9,%rax
25001+ pax_force_retaddr
25002 ret
25003 .Lmemset_e:
25004 .previous
25005@@ -52,6 +53,7 @@
25006 movq %rdx,%rcx
25007 rep stosb
25008 movq %r9,%rax
25009+ pax_force_retaddr
25010 ret
25011 .Lmemset_e_e:
25012 .previous
25013@@ -59,7 +61,7 @@
25014 ENTRY(memset)
25015 ENTRY(__memset)
25016 CFI_STARTPROC
25017- movq %rdi,%r10
25018+ movq %rdi,%r11
25019
25020 /* expand byte value */
25021 movzbl %sil,%ecx
25022@@ -117,7 +119,8 @@ ENTRY(__memset)
25023 jnz .Lloop_1
25024
25025 .Lende:
25026- movq %r10,%rax
25027+ movq %r11,%rax
25028+ pax_force_retaddr
25029 ret
25030
25031 CFI_RESTORE_STATE
25032diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
25033index c9f2d9b..e7fd2c0 100644
25034--- a/arch/x86/lib/mmx_32.c
25035+++ b/arch/x86/lib/mmx_32.c
25036@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
25037 {
25038 void *p;
25039 int i;
25040+ unsigned long cr0;
25041
25042 if (unlikely(in_interrupt()))
25043 return __memcpy(to, from, len);
25044@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
25045 kernel_fpu_begin();
25046
25047 __asm__ __volatile__ (
25048- "1: prefetch (%0)\n" /* This set is 28 bytes */
25049- " prefetch 64(%0)\n"
25050- " prefetch 128(%0)\n"
25051- " prefetch 192(%0)\n"
25052- " prefetch 256(%0)\n"
25053+ "1: prefetch (%1)\n" /* This set is 28 bytes */
25054+ " prefetch 64(%1)\n"
25055+ " prefetch 128(%1)\n"
25056+ " prefetch 192(%1)\n"
25057+ " prefetch 256(%1)\n"
25058 "2: \n"
25059 ".section .fixup, \"ax\"\n"
25060- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25061+ "3: \n"
25062+
25063+#ifdef CONFIG_PAX_KERNEXEC
25064+ " movl %%cr0, %0\n"
25065+ " movl %0, %%eax\n"
25066+ " andl $0xFFFEFFFF, %%eax\n"
25067+ " movl %%eax, %%cr0\n"
25068+#endif
25069+
25070+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25071+
25072+#ifdef CONFIG_PAX_KERNEXEC
25073+ " movl %0, %%cr0\n"
25074+#endif
25075+
25076 " jmp 2b\n"
25077 ".previous\n"
25078 _ASM_EXTABLE(1b, 3b)
25079- : : "r" (from));
25080+ : "=&r" (cr0) : "r" (from) : "ax");
25081
25082 for ( ; i > 5; i--) {
25083 __asm__ __volatile__ (
25084- "1: prefetch 320(%0)\n"
25085- "2: movq (%0), %%mm0\n"
25086- " movq 8(%0), %%mm1\n"
25087- " movq 16(%0), %%mm2\n"
25088- " movq 24(%0), %%mm3\n"
25089- " movq %%mm0, (%1)\n"
25090- " movq %%mm1, 8(%1)\n"
25091- " movq %%mm2, 16(%1)\n"
25092- " movq %%mm3, 24(%1)\n"
25093- " movq 32(%0), %%mm0\n"
25094- " movq 40(%0), %%mm1\n"
25095- " movq 48(%0), %%mm2\n"
25096- " movq 56(%0), %%mm3\n"
25097- " movq %%mm0, 32(%1)\n"
25098- " movq %%mm1, 40(%1)\n"
25099- " movq %%mm2, 48(%1)\n"
25100- " movq %%mm3, 56(%1)\n"
25101+ "1: prefetch 320(%1)\n"
25102+ "2: movq (%1), %%mm0\n"
25103+ " movq 8(%1), %%mm1\n"
25104+ " movq 16(%1), %%mm2\n"
25105+ " movq 24(%1), %%mm3\n"
25106+ " movq %%mm0, (%2)\n"
25107+ " movq %%mm1, 8(%2)\n"
25108+ " movq %%mm2, 16(%2)\n"
25109+ " movq %%mm3, 24(%2)\n"
25110+ " movq 32(%1), %%mm0\n"
25111+ " movq 40(%1), %%mm1\n"
25112+ " movq 48(%1), %%mm2\n"
25113+ " movq 56(%1), %%mm3\n"
25114+ " movq %%mm0, 32(%2)\n"
25115+ " movq %%mm1, 40(%2)\n"
25116+ " movq %%mm2, 48(%2)\n"
25117+ " movq %%mm3, 56(%2)\n"
25118 ".section .fixup, \"ax\"\n"
25119- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25120+ "3:\n"
25121+
25122+#ifdef CONFIG_PAX_KERNEXEC
25123+ " movl %%cr0, %0\n"
25124+ " movl %0, %%eax\n"
25125+ " andl $0xFFFEFFFF, %%eax\n"
25126+ " movl %%eax, %%cr0\n"
25127+#endif
25128+
25129+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25130+
25131+#ifdef CONFIG_PAX_KERNEXEC
25132+ " movl %0, %%cr0\n"
25133+#endif
25134+
25135 " jmp 2b\n"
25136 ".previous\n"
25137 _ASM_EXTABLE(1b, 3b)
25138- : : "r" (from), "r" (to) : "memory");
25139+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25140
25141 from += 64;
25142 to += 64;
25143@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
25144 static void fast_copy_page(void *to, void *from)
25145 {
25146 int i;
25147+ unsigned long cr0;
25148
25149 kernel_fpu_begin();
25150
25151@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
25152 * but that is for later. -AV
25153 */
25154 __asm__ __volatile__(
25155- "1: prefetch (%0)\n"
25156- " prefetch 64(%0)\n"
25157- " prefetch 128(%0)\n"
25158- " prefetch 192(%0)\n"
25159- " prefetch 256(%0)\n"
25160+ "1: prefetch (%1)\n"
25161+ " prefetch 64(%1)\n"
25162+ " prefetch 128(%1)\n"
25163+ " prefetch 192(%1)\n"
25164+ " prefetch 256(%1)\n"
25165 "2: \n"
25166 ".section .fixup, \"ax\"\n"
25167- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25168+ "3: \n"
25169+
25170+#ifdef CONFIG_PAX_KERNEXEC
25171+ " movl %%cr0, %0\n"
25172+ " movl %0, %%eax\n"
25173+ " andl $0xFFFEFFFF, %%eax\n"
25174+ " movl %%eax, %%cr0\n"
25175+#endif
25176+
25177+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25178+
25179+#ifdef CONFIG_PAX_KERNEXEC
25180+ " movl %0, %%cr0\n"
25181+#endif
25182+
25183 " jmp 2b\n"
25184 ".previous\n"
25185- _ASM_EXTABLE(1b, 3b) : : "r" (from));
25186+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
25187
25188 for (i = 0; i < (4096-320)/64; i++) {
25189 __asm__ __volatile__ (
25190- "1: prefetch 320(%0)\n"
25191- "2: movq (%0), %%mm0\n"
25192- " movntq %%mm0, (%1)\n"
25193- " movq 8(%0), %%mm1\n"
25194- " movntq %%mm1, 8(%1)\n"
25195- " movq 16(%0), %%mm2\n"
25196- " movntq %%mm2, 16(%1)\n"
25197- " movq 24(%0), %%mm3\n"
25198- " movntq %%mm3, 24(%1)\n"
25199- " movq 32(%0), %%mm4\n"
25200- " movntq %%mm4, 32(%1)\n"
25201- " movq 40(%0), %%mm5\n"
25202- " movntq %%mm5, 40(%1)\n"
25203- " movq 48(%0), %%mm6\n"
25204- " movntq %%mm6, 48(%1)\n"
25205- " movq 56(%0), %%mm7\n"
25206- " movntq %%mm7, 56(%1)\n"
25207+ "1: prefetch 320(%1)\n"
25208+ "2: movq (%1), %%mm0\n"
25209+ " movntq %%mm0, (%2)\n"
25210+ " movq 8(%1), %%mm1\n"
25211+ " movntq %%mm1, 8(%2)\n"
25212+ " movq 16(%1), %%mm2\n"
25213+ " movntq %%mm2, 16(%2)\n"
25214+ " movq 24(%1), %%mm3\n"
25215+ " movntq %%mm3, 24(%2)\n"
25216+ " movq 32(%1), %%mm4\n"
25217+ " movntq %%mm4, 32(%2)\n"
25218+ " movq 40(%1), %%mm5\n"
25219+ " movntq %%mm5, 40(%2)\n"
25220+ " movq 48(%1), %%mm6\n"
25221+ " movntq %%mm6, 48(%2)\n"
25222+ " movq 56(%1), %%mm7\n"
25223+ " movntq %%mm7, 56(%2)\n"
25224 ".section .fixup, \"ax\"\n"
25225- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25226+ "3:\n"
25227+
25228+#ifdef CONFIG_PAX_KERNEXEC
25229+ " movl %%cr0, %0\n"
25230+ " movl %0, %%eax\n"
25231+ " andl $0xFFFEFFFF, %%eax\n"
25232+ " movl %%eax, %%cr0\n"
25233+#endif
25234+
25235+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25236+
25237+#ifdef CONFIG_PAX_KERNEXEC
25238+ " movl %0, %%cr0\n"
25239+#endif
25240+
25241 " jmp 2b\n"
25242 ".previous\n"
25243- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
25244+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25245
25246 from += 64;
25247 to += 64;
25248@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
25249 static void fast_copy_page(void *to, void *from)
25250 {
25251 int i;
25252+ unsigned long cr0;
25253
25254 kernel_fpu_begin();
25255
25256 __asm__ __volatile__ (
25257- "1: prefetch (%0)\n"
25258- " prefetch 64(%0)\n"
25259- " prefetch 128(%0)\n"
25260- " prefetch 192(%0)\n"
25261- " prefetch 256(%0)\n"
25262+ "1: prefetch (%1)\n"
25263+ " prefetch 64(%1)\n"
25264+ " prefetch 128(%1)\n"
25265+ " prefetch 192(%1)\n"
25266+ " prefetch 256(%1)\n"
25267 "2: \n"
25268 ".section .fixup, \"ax\"\n"
25269- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25270+ "3: \n"
25271+
25272+#ifdef CONFIG_PAX_KERNEXEC
25273+ " movl %%cr0, %0\n"
25274+ " movl %0, %%eax\n"
25275+ " andl $0xFFFEFFFF, %%eax\n"
25276+ " movl %%eax, %%cr0\n"
25277+#endif
25278+
25279+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25280+
25281+#ifdef CONFIG_PAX_KERNEXEC
25282+ " movl %0, %%cr0\n"
25283+#endif
25284+
25285 " jmp 2b\n"
25286 ".previous\n"
25287- _ASM_EXTABLE(1b, 3b) : : "r" (from));
25288+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
25289
25290 for (i = 0; i < 4096/64; i++) {
25291 __asm__ __volatile__ (
25292- "1: prefetch 320(%0)\n"
25293- "2: movq (%0), %%mm0\n"
25294- " movq 8(%0), %%mm1\n"
25295- " movq 16(%0), %%mm2\n"
25296- " movq 24(%0), %%mm3\n"
25297- " movq %%mm0, (%1)\n"
25298- " movq %%mm1, 8(%1)\n"
25299- " movq %%mm2, 16(%1)\n"
25300- " movq %%mm3, 24(%1)\n"
25301- " movq 32(%0), %%mm0\n"
25302- " movq 40(%0), %%mm1\n"
25303- " movq 48(%0), %%mm2\n"
25304- " movq 56(%0), %%mm3\n"
25305- " movq %%mm0, 32(%1)\n"
25306- " movq %%mm1, 40(%1)\n"
25307- " movq %%mm2, 48(%1)\n"
25308- " movq %%mm3, 56(%1)\n"
25309+ "1: prefetch 320(%1)\n"
25310+ "2: movq (%1), %%mm0\n"
25311+ " movq 8(%1), %%mm1\n"
25312+ " movq 16(%1), %%mm2\n"
25313+ " movq 24(%1), %%mm3\n"
25314+ " movq %%mm0, (%2)\n"
25315+ " movq %%mm1, 8(%2)\n"
25316+ " movq %%mm2, 16(%2)\n"
25317+ " movq %%mm3, 24(%2)\n"
25318+ " movq 32(%1), %%mm0\n"
25319+ " movq 40(%1), %%mm1\n"
25320+ " movq 48(%1), %%mm2\n"
25321+ " movq 56(%1), %%mm3\n"
25322+ " movq %%mm0, 32(%2)\n"
25323+ " movq %%mm1, 40(%2)\n"
25324+ " movq %%mm2, 48(%2)\n"
25325+ " movq %%mm3, 56(%2)\n"
25326 ".section .fixup, \"ax\"\n"
25327- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25328+ "3:\n"
25329+
25330+#ifdef CONFIG_PAX_KERNEXEC
25331+ " movl %%cr0, %0\n"
25332+ " movl %0, %%eax\n"
25333+ " andl $0xFFFEFFFF, %%eax\n"
25334+ " movl %%eax, %%cr0\n"
25335+#endif
25336+
25337+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25338+
25339+#ifdef CONFIG_PAX_KERNEXEC
25340+ " movl %0, %%cr0\n"
25341+#endif
25342+
25343 " jmp 2b\n"
25344 ".previous\n"
25345 _ASM_EXTABLE(1b, 3b)
25346- : : "r" (from), "r" (to) : "memory");
25347+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25348
25349 from += 64;
25350 to += 64;
25351diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
25352index f6d13ee..aca5f0b 100644
25353--- a/arch/x86/lib/msr-reg.S
25354+++ b/arch/x86/lib/msr-reg.S
25355@@ -3,6 +3,7 @@
25356 #include <asm/dwarf2.h>
25357 #include <asm/asm.h>
25358 #include <asm/msr.h>
25359+#include <asm/alternative-asm.h>
25360
25361 #ifdef CONFIG_X86_64
25362 /*
25363@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
25364 CFI_STARTPROC
25365 pushq_cfi %rbx
25366 pushq_cfi %rbp
25367- movq %rdi, %r10 /* Save pointer */
25368+ movq %rdi, %r9 /* Save pointer */
25369 xorl %r11d, %r11d /* Return value */
25370 movl (%rdi), %eax
25371 movl 4(%rdi), %ecx
25372@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
25373 movl 28(%rdi), %edi
25374 CFI_REMEMBER_STATE
25375 1: \op
25376-2: movl %eax, (%r10)
25377+2: movl %eax, (%r9)
25378 movl %r11d, %eax /* Return value */
25379- movl %ecx, 4(%r10)
25380- movl %edx, 8(%r10)
25381- movl %ebx, 12(%r10)
25382- movl %ebp, 20(%r10)
25383- movl %esi, 24(%r10)
25384- movl %edi, 28(%r10)
25385+ movl %ecx, 4(%r9)
25386+ movl %edx, 8(%r9)
25387+ movl %ebx, 12(%r9)
25388+ movl %ebp, 20(%r9)
25389+ movl %esi, 24(%r9)
25390+ movl %edi, 28(%r9)
25391 popq_cfi %rbp
25392 popq_cfi %rbx
25393+ pax_force_retaddr
25394 ret
25395 3:
25396 CFI_RESTORE_STATE
25397diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
25398index fc6ba17..04471c5 100644
25399--- a/arch/x86/lib/putuser.S
25400+++ b/arch/x86/lib/putuser.S
25401@@ -16,7 +16,9 @@
25402 #include <asm/errno.h>
25403 #include <asm/asm.h>
25404 #include <asm/smap.h>
25405-
25406+#include <asm/segment.h>
25407+#include <asm/pgtable.h>
25408+#include <asm/alternative-asm.h>
25409
25410 /*
25411 * __put_user_X
25412@@ -30,57 +32,125 @@
25413 * as they get called from within inline assembly.
25414 */
25415
25416-#define ENTER CFI_STARTPROC ; \
25417- GET_THREAD_INFO(%_ASM_BX)
25418-#define EXIT ASM_CLAC ; \
25419- ret ; \
25420+#define ENTER CFI_STARTPROC
25421+#define EXIT ASM_CLAC ; \
25422+ pax_force_retaddr ; \
25423+ ret ; \
25424 CFI_ENDPROC
25425
25426+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25427+#define _DEST %_ASM_CX,%_ASM_BX
25428+#else
25429+#define _DEST %_ASM_CX
25430+#endif
25431+
25432+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
25433+#define __copyuser_seg gs;
25434+#else
25435+#define __copyuser_seg
25436+#endif
25437+
25438 .text
25439 ENTRY(__put_user_1)
25440 ENTER
25441+
25442+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25443+ GET_THREAD_INFO(%_ASM_BX)
25444 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
25445 jae bad_put_user
25446 ASM_STAC
25447-1: movb %al,(%_ASM_CX)
25448+
25449+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25450+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25451+ cmp %_ASM_BX,%_ASM_CX
25452+ jb 1234f
25453+ xor %ebx,%ebx
25454+1234:
25455+#endif
25456+
25457+#endif
25458+
25459+1: __copyuser_seg movb %al,(_DEST)
25460 xor %eax,%eax
25461 EXIT
25462 ENDPROC(__put_user_1)
25463
25464 ENTRY(__put_user_2)
25465 ENTER
25466+
25467+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25468+ GET_THREAD_INFO(%_ASM_BX)
25469 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
25470 sub $1,%_ASM_BX
25471 cmp %_ASM_BX,%_ASM_CX
25472 jae bad_put_user
25473 ASM_STAC
25474-2: movw %ax,(%_ASM_CX)
25475+
25476+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25477+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25478+ cmp %_ASM_BX,%_ASM_CX
25479+ jb 1234f
25480+ xor %ebx,%ebx
25481+1234:
25482+#endif
25483+
25484+#endif
25485+
25486+2: __copyuser_seg movw %ax,(_DEST)
25487 xor %eax,%eax
25488 EXIT
25489 ENDPROC(__put_user_2)
25490
25491 ENTRY(__put_user_4)
25492 ENTER
25493+
25494+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25495+ GET_THREAD_INFO(%_ASM_BX)
25496 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
25497 sub $3,%_ASM_BX
25498 cmp %_ASM_BX,%_ASM_CX
25499 jae bad_put_user
25500 ASM_STAC
25501-3: movl %eax,(%_ASM_CX)
25502+
25503+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25504+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25505+ cmp %_ASM_BX,%_ASM_CX
25506+ jb 1234f
25507+ xor %ebx,%ebx
25508+1234:
25509+#endif
25510+
25511+#endif
25512+
25513+3: __copyuser_seg movl %eax,(_DEST)
25514 xor %eax,%eax
25515 EXIT
25516 ENDPROC(__put_user_4)
25517
25518 ENTRY(__put_user_8)
25519 ENTER
25520+
25521+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25522+ GET_THREAD_INFO(%_ASM_BX)
25523 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
25524 sub $7,%_ASM_BX
25525 cmp %_ASM_BX,%_ASM_CX
25526 jae bad_put_user
25527 ASM_STAC
25528-4: mov %_ASM_AX,(%_ASM_CX)
25529+
25530+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25531+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25532+ cmp %_ASM_BX,%_ASM_CX
25533+ jb 1234f
25534+ xor %ebx,%ebx
25535+1234:
25536+#endif
25537+
25538+#endif
25539+
25540+4: __copyuser_seg mov %_ASM_AX,(_DEST)
25541 #ifdef CONFIG_X86_32
25542-5: movl %edx,4(%_ASM_CX)
25543+5: __copyuser_seg movl %edx,4(_DEST)
25544 #endif
25545 xor %eax,%eax
25546 EXIT
25547diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
25548index 1cad221..de671ee 100644
25549--- a/arch/x86/lib/rwlock.S
25550+++ b/arch/x86/lib/rwlock.S
25551@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
25552 FRAME
25553 0: LOCK_PREFIX
25554 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
25555+
25556+#ifdef CONFIG_PAX_REFCOUNT
25557+ jno 1234f
25558+ LOCK_PREFIX
25559+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
25560+ int $4
25561+1234:
25562+ _ASM_EXTABLE(1234b, 1234b)
25563+#endif
25564+
25565 1: rep; nop
25566 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
25567 jne 1b
25568 LOCK_PREFIX
25569 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
25570+
25571+#ifdef CONFIG_PAX_REFCOUNT
25572+ jno 1234f
25573+ LOCK_PREFIX
25574+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
25575+ int $4
25576+1234:
25577+ _ASM_EXTABLE(1234b, 1234b)
25578+#endif
25579+
25580 jnz 0b
25581 ENDFRAME
25582+ pax_force_retaddr
25583 ret
25584 CFI_ENDPROC
25585 END(__write_lock_failed)
25586@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
25587 FRAME
25588 0: LOCK_PREFIX
25589 READ_LOCK_SIZE(inc) (%__lock_ptr)
25590+
25591+#ifdef CONFIG_PAX_REFCOUNT
25592+ jno 1234f
25593+ LOCK_PREFIX
25594+ READ_LOCK_SIZE(dec) (%__lock_ptr)
25595+ int $4
25596+1234:
25597+ _ASM_EXTABLE(1234b, 1234b)
25598+#endif
25599+
25600 1: rep; nop
25601 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
25602 js 1b
25603 LOCK_PREFIX
25604 READ_LOCK_SIZE(dec) (%__lock_ptr)
25605+
25606+#ifdef CONFIG_PAX_REFCOUNT
25607+ jno 1234f
25608+ LOCK_PREFIX
25609+ READ_LOCK_SIZE(inc) (%__lock_ptr)
25610+ int $4
25611+1234:
25612+ _ASM_EXTABLE(1234b, 1234b)
25613+#endif
25614+
25615 js 0b
25616 ENDFRAME
25617+ pax_force_retaddr
25618 ret
25619 CFI_ENDPROC
25620 END(__read_lock_failed)
25621diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
25622index 5dff5f0..cadebf4 100644
25623--- a/arch/x86/lib/rwsem.S
25624+++ b/arch/x86/lib/rwsem.S
25625@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
25626 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
25627 CFI_RESTORE __ASM_REG(dx)
25628 restore_common_regs
25629+ pax_force_retaddr
25630 ret
25631 CFI_ENDPROC
25632 ENDPROC(call_rwsem_down_read_failed)
25633@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
25634 movq %rax,%rdi
25635 call rwsem_down_write_failed
25636 restore_common_regs
25637+ pax_force_retaddr
25638 ret
25639 CFI_ENDPROC
25640 ENDPROC(call_rwsem_down_write_failed)
25641@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
25642 movq %rax,%rdi
25643 call rwsem_wake
25644 restore_common_regs
25645-1: ret
25646+1: pax_force_retaddr
25647+ ret
25648 CFI_ENDPROC
25649 ENDPROC(call_rwsem_wake)
25650
25651@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
25652 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
25653 CFI_RESTORE __ASM_REG(dx)
25654 restore_common_regs
25655+ pax_force_retaddr
25656 ret
25657 CFI_ENDPROC
25658 ENDPROC(call_rwsem_downgrade_wake)
25659diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
25660index a63efd6..ccecad8 100644
25661--- a/arch/x86/lib/thunk_64.S
25662+++ b/arch/x86/lib/thunk_64.S
25663@@ -8,6 +8,7 @@
25664 #include <linux/linkage.h>
25665 #include <asm/dwarf2.h>
25666 #include <asm/calling.h>
25667+#include <asm/alternative-asm.h>
25668
25669 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
25670 .macro THUNK name, func, put_ret_addr_in_rdi=0
25671@@ -41,5 +42,6 @@
25672 SAVE_ARGS
25673 restore:
25674 RESTORE_ARGS
25675+ pax_force_retaddr
25676 ret
25677 CFI_ENDPROC
25678diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
25679index f0312d7..9c39d63 100644
25680--- a/arch/x86/lib/usercopy_32.c
25681+++ b/arch/x86/lib/usercopy_32.c
25682@@ -42,11 +42,13 @@ do { \
25683 int __d0; \
25684 might_fault(); \
25685 __asm__ __volatile__( \
25686+ __COPYUSER_SET_ES \
25687 ASM_STAC "\n" \
25688 "0: rep; stosl\n" \
25689 " movl %2,%0\n" \
25690 "1: rep; stosb\n" \
25691 "2: " ASM_CLAC "\n" \
25692+ __COPYUSER_RESTORE_ES \
25693 ".section .fixup,\"ax\"\n" \
25694 "3: lea 0(%2,%0,4),%0\n" \
25695 " jmp 2b\n" \
25696@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
25697
25698 #ifdef CONFIG_X86_INTEL_USERCOPY
25699 static unsigned long
25700-__copy_user_intel(void __user *to, const void *from, unsigned long size)
25701+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
25702 {
25703 int d0, d1;
25704 __asm__ __volatile__(
25705@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
25706 " .align 2,0x90\n"
25707 "3: movl 0(%4), %%eax\n"
25708 "4: movl 4(%4), %%edx\n"
25709- "5: movl %%eax, 0(%3)\n"
25710- "6: movl %%edx, 4(%3)\n"
25711+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
25712+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
25713 "7: movl 8(%4), %%eax\n"
25714 "8: movl 12(%4),%%edx\n"
25715- "9: movl %%eax, 8(%3)\n"
25716- "10: movl %%edx, 12(%3)\n"
25717+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
25718+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
25719 "11: movl 16(%4), %%eax\n"
25720 "12: movl 20(%4), %%edx\n"
25721- "13: movl %%eax, 16(%3)\n"
25722- "14: movl %%edx, 20(%3)\n"
25723+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
25724+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
25725 "15: movl 24(%4), %%eax\n"
25726 "16: movl 28(%4), %%edx\n"
25727- "17: movl %%eax, 24(%3)\n"
25728- "18: movl %%edx, 28(%3)\n"
25729+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
25730+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
25731 "19: movl 32(%4), %%eax\n"
25732 "20: movl 36(%4), %%edx\n"
25733- "21: movl %%eax, 32(%3)\n"
25734- "22: movl %%edx, 36(%3)\n"
25735+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
25736+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
25737 "23: movl 40(%4), %%eax\n"
25738 "24: movl 44(%4), %%edx\n"
25739- "25: movl %%eax, 40(%3)\n"
25740- "26: movl %%edx, 44(%3)\n"
25741+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
25742+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
25743 "27: movl 48(%4), %%eax\n"
25744 "28: movl 52(%4), %%edx\n"
25745- "29: movl %%eax, 48(%3)\n"
25746- "30: movl %%edx, 52(%3)\n"
25747+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
25748+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
25749 "31: movl 56(%4), %%eax\n"
25750 "32: movl 60(%4), %%edx\n"
25751- "33: movl %%eax, 56(%3)\n"
25752- "34: movl %%edx, 60(%3)\n"
25753+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
25754+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
25755 " addl $-64, %0\n"
25756 " addl $64, %4\n"
25757 " addl $64, %3\n"
25758@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
25759 " shrl $2, %0\n"
25760 " andl $3, %%eax\n"
25761 " cld\n"
25762+ __COPYUSER_SET_ES
25763 "99: rep; movsl\n"
25764 "36: movl %%eax, %0\n"
25765 "37: rep; movsb\n"
25766 "100:\n"
25767+ __COPYUSER_RESTORE_ES
25768 ".section .fixup,\"ax\"\n"
25769 "101: lea 0(%%eax,%0,4),%0\n"
25770 " jmp 100b\n"
25771@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
25772 }
25773
25774 static unsigned long
25775+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
25776+{
25777+ int d0, d1;
25778+ __asm__ __volatile__(
25779+ " .align 2,0x90\n"
25780+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
25781+ " cmpl $67, %0\n"
25782+ " jbe 3f\n"
25783+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
25784+ " .align 2,0x90\n"
25785+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
25786+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
25787+ "5: movl %%eax, 0(%3)\n"
25788+ "6: movl %%edx, 4(%3)\n"
25789+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
25790+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
25791+ "9: movl %%eax, 8(%3)\n"
25792+ "10: movl %%edx, 12(%3)\n"
25793+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
25794+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
25795+ "13: movl %%eax, 16(%3)\n"
25796+ "14: movl %%edx, 20(%3)\n"
25797+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
25798+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
25799+ "17: movl %%eax, 24(%3)\n"
25800+ "18: movl %%edx, 28(%3)\n"
25801+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
25802+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
25803+ "21: movl %%eax, 32(%3)\n"
25804+ "22: movl %%edx, 36(%3)\n"
25805+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
25806+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
25807+ "25: movl %%eax, 40(%3)\n"
25808+ "26: movl %%edx, 44(%3)\n"
25809+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
25810+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
25811+ "29: movl %%eax, 48(%3)\n"
25812+ "30: movl %%edx, 52(%3)\n"
25813+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
25814+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
25815+ "33: movl %%eax, 56(%3)\n"
25816+ "34: movl %%edx, 60(%3)\n"
25817+ " addl $-64, %0\n"
25818+ " addl $64, %4\n"
25819+ " addl $64, %3\n"
25820+ " cmpl $63, %0\n"
25821+ " ja 1b\n"
25822+ "35: movl %0, %%eax\n"
25823+ " shrl $2, %0\n"
25824+ " andl $3, %%eax\n"
25825+ " cld\n"
25826+ "99: rep; "__copyuser_seg" movsl\n"
25827+ "36: movl %%eax, %0\n"
25828+ "37: rep; "__copyuser_seg" movsb\n"
25829+ "100:\n"
25830+ ".section .fixup,\"ax\"\n"
25831+ "101: lea 0(%%eax,%0,4),%0\n"
25832+ " jmp 100b\n"
25833+ ".previous\n"
25834+ _ASM_EXTABLE(1b,100b)
25835+ _ASM_EXTABLE(2b,100b)
25836+ _ASM_EXTABLE(3b,100b)
25837+ _ASM_EXTABLE(4b,100b)
25838+ _ASM_EXTABLE(5b,100b)
25839+ _ASM_EXTABLE(6b,100b)
25840+ _ASM_EXTABLE(7b,100b)
25841+ _ASM_EXTABLE(8b,100b)
25842+ _ASM_EXTABLE(9b,100b)
25843+ _ASM_EXTABLE(10b,100b)
25844+ _ASM_EXTABLE(11b,100b)
25845+ _ASM_EXTABLE(12b,100b)
25846+ _ASM_EXTABLE(13b,100b)
25847+ _ASM_EXTABLE(14b,100b)
25848+ _ASM_EXTABLE(15b,100b)
25849+ _ASM_EXTABLE(16b,100b)
25850+ _ASM_EXTABLE(17b,100b)
25851+ _ASM_EXTABLE(18b,100b)
25852+ _ASM_EXTABLE(19b,100b)
25853+ _ASM_EXTABLE(20b,100b)
25854+ _ASM_EXTABLE(21b,100b)
25855+ _ASM_EXTABLE(22b,100b)
25856+ _ASM_EXTABLE(23b,100b)
25857+ _ASM_EXTABLE(24b,100b)
25858+ _ASM_EXTABLE(25b,100b)
25859+ _ASM_EXTABLE(26b,100b)
25860+ _ASM_EXTABLE(27b,100b)
25861+ _ASM_EXTABLE(28b,100b)
25862+ _ASM_EXTABLE(29b,100b)
25863+ _ASM_EXTABLE(30b,100b)
25864+ _ASM_EXTABLE(31b,100b)
25865+ _ASM_EXTABLE(32b,100b)
25866+ _ASM_EXTABLE(33b,100b)
25867+ _ASM_EXTABLE(34b,100b)
25868+ _ASM_EXTABLE(35b,100b)
25869+ _ASM_EXTABLE(36b,100b)
25870+ _ASM_EXTABLE(37b,100b)
25871+ _ASM_EXTABLE(99b,101b)
25872+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
25873+ : "1"(to), "2"(from), "0"(size)
25874+ : "eax", "edx", "memory");
25875+ return size;
25876+}
25877+
25878+static unsigned long __size_overflow(3)
25879 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
25880 {
25881 int d0, d1;
25882 __asm__ __volatile__(
25883 " .align 2,0x90\n"
25884- "0: movl 32(%4), %%eax\n"
25885+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
25886 " cmpl $67, %0\n"
25887 " jbe 2f\n"
25888- "1: movl 64(%4), %%eax\n"
25889+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
25890 " .align 2,0x90\n"
25891- "2: movl 0(%4), %%eax\n"
25892- "21: movl 4(%4), %%edx\n"
25893+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
25894+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
25895 " movl %%eax, 0(%3)\n"
25896 " movl %%edx, 4(%3)\n"
25897- "3: movl 8(%4), %%eax\n"
25898- "31: movl 12(%4),%%edx\n"
25899+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
25900+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
25901 " movl %%eax, 8(%3)\n"
25902 " movl %%edx, 12(%3)\n"
25903- "4: movl 16(%4), %%eax\n"
25904- "41: movl 20(%4), %%edx\n"
25905+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
25906+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
25907 " movl %%eax, 16(%3)\n"
25908 " movl %%edx, 20(%3)\n"
25909- "10: movl 24(%4), %%eax\n"
25910- "51: movl 28(%4), %%edx\n"
25911+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
25912+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
25913 " movl %%eax, 24(%3)\n"
25914 " movl %%edx, 28(%3)\n"
25915- "11: movl 32(%4), %%eax\n"
25916- "61: movl 36(%4), %%edx\n"
25917+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
25918+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
25919 " movl %%eax, 32(%3)\n"
25920 " movl %%edx, 36(%3)\n"
25921- "12: movl 40(%4), %%eax\n"
25922- "71: movl 44(%4), %%edx\n"
25923+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
25924+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
25925 " movl %%eax, 40(%3)\n"
25926 " movl %%edx, 44(%3)\n"
25927- "13: movl 48(%4), %%eax\n"
25928- "81: movl 52(%4), %%edx\n"
25929+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
25930+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
25931 " movl %%eax, 48(%3)\n"
25932 " movl %%edx, 52(%3)\n"
25933- "14: movl 56(%4), %%eax\n"
25934- "91: movl 60(%4), %%edx\n"
25935+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
25936+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
25937 " movl %%eax, 56(%3)\n"
25938 " movl %%edx, 60(%3)\n"
25939 " addl $-64, %0\n"
25940@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
25941 " shrl $2, %0\n"
25942 " andl $3, %%eax\n"
25943 " cld\n"
25944- "6: rep; movsl\n"
25945+ "6: rep; "__copyuser_seg" movsl\n"
25946 " movl %%eax,%0\n"
25947- "7: rep; movsb\n"
25948+ "7: rep; "__copyuser_seg" movsb\n"
25949 "8:\n"
25950 ".section .fixup,\"ax\"\n"
25951 "9: lea 0(%%eax,%0,4),%0\n"
25952@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
25953 * hyoshiok@miraclelinux.com
25954 */
25955
25956-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
25957+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
25958 const void __user *from, unsigned long size)
25959 {
25960 int d0, d1;
25961
25962 __asm__ __volatile__(
25963 " .align 2,0x90\n"
25964- "0: movl 32(%4), %%eax\n"
25965+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
25966 " cmpl $67, %0\n"
25967 " jbe 2f\n"
25968- "1: movl 64(%4), %%eax\n"
25969+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
25970 " .align 2,0x90\n"
25971- "2: movl 0(%4), %%eax\n"
25972- "21: movl 4(%4), %%edx\n"
25973+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
25974+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
25975 " movnti %%eax, 0(%3)\n"
25976 " movnti %%edx, 4(%3)\n"
25977- "3: movl 8(%4), %%eax\n"
25978- "31: movl 12(%4),%%edx\n"
25979+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
25980+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
25981 " movnti %%eax, 8(%3)\n"
25982 " movnti %%edx, 12(%3)\n"
25983- "4: movl 16(%4), %%eax\n"
25984- "41: movl 20(%4), %%edx\n"
25985+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
25986+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
25987 " movnti %%eax, 16(%3)\n"
25988 " movnti %%edx, 20(%3)\n"
25989- "10: movl 24(%4), %%eax\n"
25990- "51: movl 28(%4), %%edx\n"
25991+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
25992+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
25993 " movnti %%eax, 24(%3)\n"
25994 " movnti %%edx, 28(%3)\n"
25995- "11: movl 32(%4), %%eax\n"
25996- "61: movl 36(%4), %%edx\n"
25997+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
25998+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
25999 " movnti %%eax, 32(%3)\n"
26000 " movnti %%edx, 36(%3)\n"
26001- "12: movl 40(%4), %%eax\n"
26002- "71: movl 44(%4), %%edx\n"
26003+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26004+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26005 " movnti %%eax, 40(%3)\n"
26006 " movnti %%edx, 44(%3)\n"
26007- "13: movl 48(%4), %%eax\n"
26008- "81: movl 52(%4), %%edx\n"
26009+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26010+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26011 " movnti %%eax, 48(%3)\n"
26012 " movnti %%edx, 52(%3)\n"
26013- "14: movl 56(%4), %%eax\n"
26014- "91: movl 60(%4), %%edx\n"
26015+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26016+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26017 " movnti %%eax, 56(%3)\n"
26018 " movnti %%edx, 60(%3)\n"
26019 " addl $-64, %0\n"
26020@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26021 " shrl $2, %0\n"
26022 " andl $3, %%eax\n"
26023 " cld\n"
26024- "6: rep; movsl\n"
26025+ "6: rep; "__copyuser_seg" movsl\n"
26026 " movl %%eax,%0\n"
26027- "7: rep; movsb\n"
26028+ "7: rep; "__copyuser_seg" movsb\n"
26029 "8:\n"
26030 ".section .fixup,\"ax\"\n"
26031 "9: lea 0(%%eax,%0,4),%0\n"
26032@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26033 return size;
26034 }
26035
26036-static unsigned long __copy_user_intel_nocache(void *to,
26037+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
26038 const void __user *from, unsigned long size)
26039 {
26040 int d0, d1;
26041
26042 __asm__ __volatile__(
26043 " .align 2,0x90\n"
26044- "0: movl 32(%4), %%eax\n"
26045+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26046 " cmpl $67, %0\n"
26047 " jbe 2f\n"
26048- "1: movl 64(%4), %%eax\n"
26049+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26050 " .align 2,0x90\n"
26051- "2: movl 0(%4), %%eax\n"
26052- "21: movl 4(%4), %%edx\n"
26053+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26054+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26055 " movnti %%eax, 0(%3)\n"
26056 " movnti %%edx, 4(%3)\n"
26057- "3: movl 8(%4), %%eax\n"
26058- "31: movl 12(%4),%%edx\n"
26059+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26060+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26061 " movnti %%eax, 8(%3)\n"
26062 " movnti %%edx, 12(%3)\n"
26063- "4: movl 16(%4), %%eax\n"
26064- "41: movl 20(%4), %%edx\n"
26065+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26066+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26067 " movnti %%eax, 16(%3)\n"
26068 " movnti %%edx, 20(%3)\n"
26069- "10: movl 24(%4), %%eax\n"
26070- "51: movl 28(%4), %%edx\n"
26071+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26072+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26073 " movnti %%eax, 24(%3)\n"
26074 " movnti %%edx, 28(%3)\n"
26075- "11: movl 32(%4), %%eax\n"
26076- "61: movl 36(%4), %%edx\n"
26077+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26078+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26079 " movnti %%eax, 32(%3)\n"
26080 " movnti %%edx, 36(%3)\n"
26081- "12: movl 40(%4), %%eax\n"
26082- "71: movl 44(%4), %%edx\n"
26083+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26084+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26085 " movnti %%eax, 40(%3)\n"
26086 " movnti %%edx, 44(%3)\n"
26087- "13: movl 48(%4), %%eax\n"
26088- "81: movl 52(%4), %%edx\n"
26089+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26090+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26091 " movnti %%eax, 48(%3)\n"
26092 " movnti %%edx, 52(%3)\n"
26093- "14: movl 56(%4), %%eax\n"
26094- "91: movl 60(%4), %%edx\n"
26095+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26096+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26097 " movnti %%eax, 56(%3)\n"
26098 " movnti %%edx, 60(%3)\n"
26099 " addl $-64, %0\n"
26100@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
26101 " shrl $2, %0\n"
26102 " andl $3, %%eax\n"
26103 " cld\n"
26104- "6: rep; movsl\n"
26105+ "6: rep; "__copyuser_seg" movsl\n"
26106 " movl %%eax,%0\n"
26107- "7: rep; movsb\n"
26108+ "7: rep; "__copyuser_seg" movsb\n"
26109 "8:\n"
26110 ".section .fixup,\"ax\"\n"
26111 "9: lea 0(%%eax,%0,4),%0\n"
26112@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
26113 */
26114 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
26115 unsigned long size);
26116-unsigned long __copy_user_intel(void __user *to, const void *from,
26117+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
26118+ unsigned long size);
26119+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
26120 unsigned long size);
26121 unsigned long __copy_user_zeroing_intel_nocache(void *to,
26122 const void __user *from, unsigned long size);
26123 #endif /* CONFIG_X86_INTEL_USERCOPY */
26124
26125 /* Generic arbitrary sized copy. */
26126-#define __copy_user(to, from, size) \
26127+#define __copy_user(to, from, size, prefix, set, restore) \
26128 do { \
26129 int __d0, __d1, __d2; \
26130 __asm__ __volatile__( \
26131+ set \
26132 " cmp $7,%0\n" \
26133 " jbe 1f\n" \
26134 " movl %1,%0\n" \
26135 " negl %0\n" \
26136 " andl $7,%0\n" \
26137 " subl %0,%3\n" \
26138- "4: rep; movsb\n" \
26139+ "4: rep; "prefix"movsb\n" \
26140 " movl %3,%0\n" \
26141 " shrl $2,%0\n" \
26142 " andl $3,%3\n" \
26143 " .align 2,0x90\n" \
26144- "0: rep; movsl\n" \
26145+ "0: rep; "prefix"movsl\n" \
26146 " movl %3,%0\n" \
26147- "1: rep; movsb\n" \
26148+ "1: rep; "prefix"movsb\n" \
26149 "2:\n" \
26150+ restore \
26151 ".section .fixup,\"ax\"\n" \
26152 "5: addl %3,%0\n" \
26153 " jmp 2b\n" \
26154@@ -538,14 +650,14 @@ do { \
26155 " negl %0\n" \
26156 " andl $7,%0\n" \
26157 " subl %0,%3\n" \
26158- "4: rep; movsb\n" \
26159+ "4: rep; "__copyuser_seg"movsb\n" \
26160 " movl %3,%0\n" \
26161 " shrl $2,%0\n" \
26162 " andl $3,%3\n" \
26163 " .align 2,0x90\n" \
26164- "0: rep; movsl\n" \
26165+ "0: rep; "__copyuser_seg"movsl\n" \
26166 " movl %3,%0\n" \
26167- "1: rep; movsb\n" \
26168+ "1: rep; "__copyuser_seg"movsb\n" \
26169 "2:\n" \
26170 ".section .fixup,\"ax\"\n" \
26171 "5: addl %3,%0\n" \
26172@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
26173 {
26174 stac();
26175 if (movsl_is_ok(to, from, n))
26176- __copy_user(to, from, n);
26177+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
26178 else
26179- n = __copy_user_intel(to, from, n);
26180+ n = __generic_copy_to_user_intel(to, from, n);
26181 clac();
26182 return n;
26183 }
26184@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
26185 {
26186 stac();
26187 if (movsl_is_ok(to, from, n))
26188- __copy_user(to, from, n);
26189+ __copy_user(to, from, n, __copyuser_seg, "", "");
26190 else
26191- n = __copy_user_intel((void __user *)to,
26192- (const void *)from, n);
26193+ n = __generic_copy_from_user_intel(to, from, n);
26194 clac();
26195 return n;
26196 }
26197@@ -632,66 +743,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
26198 if (n > 64 && cpu_has_xmm2)
26199 n = __copy_user_intel_nocache(to, from, n);
26200 else
26201- __copy_user(to, from, n);
26202+ __copy_user(to, from, n, __copyuser_seg, "", "");
26203 #else
26204- __copy_user(to, from, n);
26205+ __copy_user(to, from, n, __copyuser_seg, "", "");
26206 #endif
26207 clac();
26208 return n;
26209 }
26210 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
26211
26212-/**
26213- * copy_to_user: - Copy a block of data into user space.
26214- * @to: Destination address, in user space.
26215- * @from: Source address, in kernel space.
26216- * @n: Number of bytes to copy.
26217- *
26218- * Context: User context only. This function may sleep.
26219- *
26220- * Copy data from kernel space to user space.
26221- *
26222- * Returns number of bytes that could not be copied.
26223- * On success, this will be zero.
26224- */
26225-unsigned long
26226-copy_to_user(void __user *to, const void *from, unsigned long n)
26227-{
26228- if (access_ok(VERIFY_WRITE, to, n))
26229- n = __copy_to_user(to, from, n);
26230- return n;
26231-}
26232-EXPORT_SYMBOL(copy_to_user);
26233-
26234-/**
26235- * copy_from_user: - Copy a block of data from user space.
26236- * @to: Destination address, in kernel space.
26237- * @from: Source address, in user space.
26238- * @n: Number of bytes to copy.
26239- *
26240- * Context: User context only. This function may sleep.
26241- *
26242- * Copy data from user space to kernel space.
26243- *
26244- * Returns number of bytes that could not be copied.
26245- * On success, this will be zero.
26246- *
26247- * If some data could not be copied, this function will pad the copied
26248- * data to the requested size using zero bytes.
26249- */
26250-unsigned long
26251-_copy_from_user(void *to, const void __user *from, unsigned long n)
26252-{
26253- if (access_ok(VERIFY_READ, from, n))
26254- n = __copy_from_user(to, from, n);
26255- else
26256- memset(to, 0, n);
26257- return n;
26258-}
26259-EXPORT_SYMBOL(_copy_from_user);
26260-
26261 void copy_from_user_overflow(void)
26262 {
26263 WARN(1, "Buffer overflow detected!\n");
26264 }
26265 EXPORT_SYMBOL(copy_from_user_overflow);
26266+
26267+void copy_to_user_overflow(void)
26268+{
26269+ WARN(1, "Buffer overflow detected!\n");
26270+}
26271+EXPORT_SYMBOL(copy_to_user_overflow);
26272+
26273+#ifdef CONFIG_PAX_MEMORY_UDEREF
26274+void __set_fs(mm_segment_t x)
26275+{
26276+ switch (x.seg) {
26277+ case 0:
26278+ loadsegment(gs, 0);
26279+ break;
26280+ case TASK_SIZE_MAX:
26281+ loadsegment(gs, __USER_DS);
26282+ break;
26283+ case -1UL:
26284+ loadsegment(gs, __KERNEL_DS);
26285+ break;
26286+ default:
26287+ BUG();
26288+ }
26289+ return;
26290+}
26291+EXPORT_SYMBOL(__set_fs);
26292+
26293+void set_fs(mm_segment_t x)
26294+{
26295+ current_thread_info()->addr_limit = x;
26296+ __set_fs(x);
26297+}
26298+EXPORT_SYMBOL(set_fs);
26299+#endif
26300diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
26301index 05928aa..b33dea1 100644
26302--- a/arch/x86/lib/usercopy_64.c
26303+++ b/arch/x86/lib/usercopy_64.c
26304@@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
26305 _ASM_EXTABLE(0b,3b)
26306 _ASM_EXTABLE(1b,2b)
26307 : [size8] "=&c"(size), [dst] "=&D" (__d0)
26308- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
26309+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
26310 [zero] "r" (0UL), [eight] "r" (8UL));
26311 clac();
26312 return size;
26313@@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
26314 }
26315 EXPORT_SYMBOL(clear_user);
26316
26317-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
26318+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
26319 {
26320- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
26321- return copy_user_generic((__force void *)to, (__force void *)from, len);
26322- }
26323- return len;
26324+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
26325+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
26326+ return len;
26327 }
26328 EXPORT_SYMBOL(copy_in_user);
26329
26330@@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
26331 * it is not necessary to optimize tail handling.
26332 */
26333 unsigned long
26334-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
26335+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
26336 {
26337 char c;
26338 unsigned zero_len;
26339@@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
26340 clac();
26341 return len;
26342 }
26343+
26344+void copy_from_user_overflow(void)
26345+{
26346+ WARN(1, "Buffer overflow detected!\n");
26347+}
26348+EXPORT_SYMBOL(copy_from_user_overflow);
26349+
26350+void copy_to_user_overflow(void)
26351+{
26352+ WARN(1, "Buffer overflow detected!\n");
26353+}
26354+EXPORT_SYMBOL(copy_to_user_overflow);
26355diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
26356index 903ec1e..c4166b2 100644
26357--- a/arch/x86/mm/extable.c
26358+++ b/arch/x86/mm/extable.c
26359@@ -6,12 +6,24 @@
26360 static inline unsigned long
26361 ex_insn_addr(const struct exception_table_entry *x)
26362 {
26363- return (unsigned long)&x->insn + x->insn;
26364+ unsigned long reloc = 0;
26365+
26366+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26367+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26368+#endif
26369+
26370+ return (unsigned long)&x->insn + x->insn + reloc;
26371 }
26372 static inline unsigned long
26373 ex_fixup_addr(const struct exception_table_entry *x)
26374 {
26375- return (unsigned long)&x->fixup + x->fixup;
26376+ unsigned long reloc = 0;
26377+
26378+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26379+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26380+#endif
26381+
26382+ return (unsigned long)&x->fixup + x->fixup + reloc;
26383 }
26384
26385 int fixup_exception(struct pt_regs *regs)
26386@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
26387 unsigned long new_ip;
26388
26389 #ifdef CONFIG_PNPBIOS
26390- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
26391+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
26392 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
26393 extern u32 pnp_bios_is_utter_crap;
26394 pnp_bios_is_utter_crap = 1;
26395@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
26396 i += 4;
26397 p->fixup -= i;
26398 i += 4;
26399+
26400+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26401+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
26402+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26403+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26404+#endif
26405+
26406 }
26407 }
26408
26409diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
26410index fb674fd..272f369 100644
26411--- a/arch/x86/mm/fault.c
26412+++ b/arch/x86/mm/fault.c
26413@@ -13,12 +13,19 @@
26414 #include <linux/perf_event.h> /* perf_sw_event */
26415 #include <linux/hugetlb.h> /* hstate_index_to_shift */
26416 #include <linux/prefetch.h> /* prefetchw */
26417+#include <linux/unistd.h>
26418+#include <linux/compiler.h>
26419
26420 #include <asm/traps.h> /* dotraplinkage, ... */
26421 #include <asm/pgalloc.h> /* pgd_*(), ... */
26422 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
26423 #include <asm/fixmap.h> /* VSYSCALL_START */
26424 #include <asm/context_tracking.h> /* exception_enter(), ... */
26425+#include <asm/tlbflush.h>
26426+
26427+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26428+#include <asm/stacktrace.h>
26429+#endif
26430
26431 /*
26432 * Page fault error code bits:
26433@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
26434 int ret = 0;
26435
26436 /* kprobe_running() needs smp_processor_id() */
26437- if (kprobes_built_in() && !user_mode_vm(regs)) {
26438+ if (kprobes_built_in() && !user_mode(regs)) {
26439 preempt_disable();
26440 if (kprobe_running() && kprobe_fault_handler(regs, 14))
26441 ret = 1;
26442@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
26443 return !instr_lo || (instr_lo>>1) == 1;
26444 case 0x00:
26445 /* Prefetch instruction is 0x0F0D or 0x0F18 */
26446- if (probe_kernel_address(instr, opcode))
26447+ if (user_mode(regs)) {
26448+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
26449+ return 0;
26450+ } else if (probe_kernel_address(instr, opcode))
26451 return 0;
26452
26453 *prefetch = (instr_lo == 0xF) &&
26454@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
26455 while (instr < max_instr) {
26456 unsigned char opcode;
26457
26458- if (probe_kernel_address(instr, opcode))
26459+ if (user_mode(regs)) {
26460+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
26461+ break;
26462+ } else if (probe_kernel_address(instr, opcode))
26463 break;
26464
26465 instr++;
26466@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
26467 force_sig_info(si_signo, &info, tsk);
26468 }
26469
26470+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26471+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
26472+#endif
26473+
26474+#ifdef CONFIG_PAX_EMUTRAMP
26475+static int pax_handle_fetch_fault(struct pt_regs *regs);
26476+#endif
26477+
26478+#ifdef CONFIG_PAX_PAGEEXEC
26479+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
26480+{
26481+ pgd_t *pgd;
26482+ pud_t *pud;
26483+ pmd_t *pmd;
26484+
26485+ pgd = pgd_offset(mm, address);
26486+ if (!pgd_present(*pgd))
26487+ return NULL;
26488+ pud = pud_offset(pgd, address);
26489+ if (!pud_present(*pud))
26490+ return NULL;
26491+ pmd = pmd_offset(pud, address);
26492+ if (!pmd_present(*pmd))
26493+ return NULL;
26494+ return pmd;
26495+}
26496+#endif
26497+
26498 DEFINE_SPINLOCK(pgd_lock);
26499 LIST_HEAD(pgd_list);
26500
26501@@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
26502 for (address = VMALLOC_START & PMD_MASK;
26503 address >= TASK_SIZE && address < FIXADDR_TOP;
26504 address += PMD_SIZE) {
26505+
26506+#ifdef CONFIG_PAX_PER_CPU_PGD
26507+ unsigned long cpu;
26508+#else
26509 struct page *page;
26510+#endif
26511
26512 spin_lock(&pgd_lock);
26513+
26514+#ifdef CONFIG_PAX_PER_CPU_PGD
26515+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
26516+ pgd_t *pgd = get_cpu_pgd(cpu);
26517+ pmd_t *ret;
26518+#else
26519 list_for_each_entry(page, &pgd_list, lru) {
26520+ pgd_t *pgd = page_address(page);
26521 spinlock_t *pgt_lock;
26522 pmd_t *ret;
26523
26524@@ -243,8 +296,13 @@ void vmalloc_sync_all(void)
26525 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
26526
26527 spin_lock(pgt_lock);
26528- ret = vmalloc_sync_one(page_address(page), address);
26529+#endif
26530+
26531+ ret = vmalloc_sync_one(pgd, address);
26532+
26533+#ifndef CONFIG_PAX_PER_CPU_PGD
26534 spin_unlock(pgt_lock);
26535+#endif
26536
26537 if (!ret)
26538 break;
26539@@ -278,6 +336,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
26540 * an interrupt in the middle of a task switch..
26541 */
26542 pgd_paddr = read_cr3();
26543+
26544+#ifdef CONFIG_PAX_PER_CPU_PGD
26545+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
26546+#endif
26547+
26548 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
26549 if (!pmd_k)
26550 return -1;
26551@@ -373,7 +436,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
26552 * happen within a race in page table update. In the later
26553 * case just flush:
26554 */
26555+
26556+#ifdef CONFIG_PAX_PER_CPU_PGD
26557+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
26558+ pgd = pgd_offset_cpu(smp_processor_id(), address);
26559+#else
26560 pgd = pgd_offset(current->active_mm, address);
26561+#endif
26562+
26563 pgd_ref = pgd_offset_k(address);
26564 if (pgd_none(*pgd_ref))
26565 return -1;
26566@@ -541,7 +611,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
26567 static int is_errata100(struct pt_regs *regs, unsigned long address)
26568 {
26569 #ifdef CONFIG_X86_64
26570- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
26571+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
26572 return 1;
26573 #endif
26574 return 0;
26575@@ -568,7 +638,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
26576 }
26577
26578 static const char nx_warning[] = KERN_CRIT
26579-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
26580+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
26581
26582 static void
26583 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
26584@@ -577,15 +647,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
26585 if (!oops_may_print())
26586 return;
26587
26588- if (error_code & PF_INSTR) {
26589+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
26590 unsigned int level;
26591
26592 pte_t *pte = lookup_address(address, &level);
26593
26594 if (pte && pte_present(*pte) && !pte_exec(*pte))
26595- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
26596+ printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
26597 }
26598
26599+#ifdef CONFIG_PAX_KERNEXEC
26600+ if (init_mm.start_code <= address && address < init_mm.end_code) {
26601+ if (current->signal->curr_ip)
26602+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
26603+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
26604+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
26605+ else
26606+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
26607+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
26608+ }
26609+#endif
26610+
26611 printk(KERN_ALERT "BUG: unable to handle kernel ");
26612 if (address < PAGE_SIZE)
26613 printk(KERN_CONT "NULL pointer dereference");
26614@@ -748,6 +830,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
26615 return;
26616 }
26617 #endif
26618+
26619+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26620+ if (pax_is_fetch_fault(regs, error_code, address)) {
26621+
26622+#ifdef CONFIG_PAX_EMUTRAMP
26623+ switch (pax_handle_fetch_fault(regs)) {
26624+ case 2:
26625+ return;
26626+ }
26627+#endif
26628+
26629+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
26630+ do_group_exit(SIGKILL);
26631+ }
26632+#endif
26633+
26634 /* Kernel addresses are always protection faults: */
26635 if (address >= TASK_SIZE)
26636 error_code |= PF_PROT;
26637@@ -833,7 +931,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
26638 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
26639 printk(KERN_ERR
26640 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
26641- tsk->comm, tsk->pid, address);
26642+ tsk->comm, task_pid_nr(tsk), address);
26643 code = BUS_MCEERR_AR;
26644 }
26645 #endif
26646@@ -896,6 +994,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
26647 return 1;
26648 }
26649
26650+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
26651+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
26652+{
26653+ pte_t *pte;
26654+ pmd_t *pmd;
26655+ spinlock_t *ptl;
26656+ unsigned char pte_mask;
26657+
26658+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
26659+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
26660+ return 0;
26661+
26662+ /* PaX: it's our fault, let's handle it if we can */
26663+
26664+ /* PaX: take a look at read faults before acquiring any locks */
26665+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
26666+ /* instruction fetch attempt from a protected page in user mode */
26667+ up_read(&mm->mmap_sem);
26668+
26669+#ifdef CONFIG_PAX_EMUTRAMP
26670+ switch (pax_handle_fetch_fault(regs)) {
26671+ case 2:
26672+ return 1;
26673+ }
26674+#endif
26675+
26676+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
26677+ do_group_exit(SIGKILL);
26678+ }
26679+
26680+ pmd = pax_get_pmd(mm, address);
26681+ if (unlikely(!pmd))
26682+ return 0;
26683+
26684+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
26685+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
26686+ pte_unmap_unlock(pte, ptl);
26687+ return 0;
26688+ }
26689+
26690+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
26691+ /* write attempt to a protected page in user mode */
26692+ pte_unmap_unlock(pte, ptl);
26693+ return 0;
26694+ }
26695+
26696+#ifdef CONFIG_SMP
26697+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
26698+#else
26699+ if (likely(address > get_limit(regs->cs)))
26700+#endif
26701+ {
26702+ set_pte(pte, pte_mkread(*pte));
26703+ __flush_tlb_one(address);
26704+ pte_unmap_unlock(pte, ptl);
26705+ up_read(&mm->mmap_sem);
26706+ return 1;
26707+ }
26708+
26709+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
26710+
26711+ /*
26712+ * PaX: fill DTLB with user rights and retry
26713+ */
26714+ __asm__ __volatile__ (
26715+ "orb %2,(%1)\n"
26716+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
26717+/*
26718+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
26719+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
26720+ * page fault when examined during a TLB load attempt. this is true not only
26721+ * for PTEs holding a non-present entry but also present entries that will
26722+ * raise a page fault (such as those set up by PaX, or the copy-on-write
26723+ * mechanism). in effect it means that we do *not* need to flush the TLBs
26724+ * for our target pages since their PTEs are simply not in the TLBs at all.
26725+
26726+ * the best thing in omitting it is that we gain around 15-20% speed in the
26727+ * fast path of the page fault handler and can get rid of tracing since we
26728+ * can no longer flush unintended entries.
26729+ */
26730+ "invlpg (%0)\n"
26731+#endif
26732+ __copyuser_seg"testb $0,(%0)\n"
26733+ "xorb %3,(%1)\n"
26734+ :
26735+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
26736+ : "memory", "cc");
26737+ pte_unmap_unlock(pte, ptl);
26738+ up_read(&mm->mmap_sem);
26739+ return 1;
26740+}
26741+#endif
26742+
26743 /*
26744 * Handle a spurious fault caused by a stale TLB entry.
26745 *
26746@@ -968,6 +1159,9 @@ int show_unhandled_signals = 1;
26747 static inline int
26748 access_error(unsigned long error_code, struct vm_area_struct *vma)
26749 {
26750+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
26751+ return 1;
26752+
26753 if (error_code & PF_WRITE) {
26754 /* write, present and write, not present: */
26755 if (unlikely(!(vma->vm_flags & VM_WRITE)))
26756@@ -996,7 +1190,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
26757 if (error_code & PF_USER)
26758 return false;
26759
26760- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
26761+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
26762 return false;
26763
26764 return true;
26765@@ -1012,18 +1206,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
26766 {
26767 struct vm_area_struct *vma;
26768 struct task_struct *tsk;
26769- unsigned long address;
26770 struct mm_struct *mm;
26771 int fault;
26772 int write = error_code & PF_WRITE;
26773 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
26774 (write ? FAULT_FLAG_WRITE : 0);
26775
26776- tsk = current;
26777- mm = tsk->mm;
26778-
26779 /* Get the faulting address: */
26780- address = read_cr2();
26781+ unsigned long address = read_cr2();
26782+
26783+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26784+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
26785+ if (!search_exception_tables(regs->ip)) {
26786+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
26787+ bad_area_nosemaphore(regs, error_code, address);
26788+ return;
26789+ }
26790+ if (address < PAX_USER_SHADOW_BASE) {
26791+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
26792+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
26793+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
26794+ } else
26795+ address -= PAX_USER_SHADOW_BASE;
26796+ }
26797+#endif
26798+
26799+ tsk = current;
26800+ mm = tsk->mm;
26801
26802 /*
26803 * Detect and handle instructions that would cause a page fault for
26804@@ -1084,7 +1293,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
26805 * User-mode registers count as a user access even for any
26806 * potential system fault or CPU buglet:
26807 */
26808- if (user_mode_vm(regs)) {
26809+ if (user_mode(regs)) {
26810 local_irq_enable();
26811 error_code |= PF_USER;
26812 } else {
26813@@ -1146,6 +1355,11 @@ retry:
26814 might_sleep();
26815 }
26816
26817+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
26818+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
26819+ return;
26820+#endif
26821+
26822 vma = find_vma(mm, address);
26823 if (unlikely(!vma)) {
26824 bad_area(regs, error_code, address);
26825@@ -1157,18 +1371,24 @@ retry:
26826 bad_area(regs, error_code, address);
26827 return;
26828 }
26829- if (error_code & PF_USER) {
26830- /*
26831- * Accessing the stack below %sp is always a bug.
26832- * The large cushion allows instructions like enter
26833- * and pusha to work. ("enter $65535, $31" pushes
26834- * 32 pointers and then decrements %sp by 65535.)
26835- */
26836- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
26837- bad_area(regs, error_code, address);
26838- return;
26839- }
26840+ /*
26841+ * Accessing the stack below %sp is always a bug.
26842+ * The large cushion allows instructions like enter
26843+ * and pusha to work. ("enter $65535, $31" pushes
26844+ * 32 pointers and then decrements %sp by 65535.)
26845+ */
26846+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
26847+ bad_area(regs, error_code, address);
26848+ return;
26849 }
26850+
26851+#ifdef CONFIG_PAX_SEGMEXEC
26852+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
26853+ bad_area(regs, error_code, address);
26854+ return;
26855+ }
26856+#endif
26857+
26858 if (unlikely(expand_stack(vma, address))) {
26859 bad_area(regs, error_code, address);
26860 return;
26861@@ -1232,3 +1452,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
26862 __do_page_fault(regs, error_code);
26863 exception_exit(regs);
26864 }
26865+
26866+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26867+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
26868+{
26869+ struct mm_struct *mm = current->mm;
26870+ unsigned long ip = regs->ip;
26871+
26872+ if (v8086_mode(regs))
26873+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
26874+
26875+#ifdef CONFIG_PAX_PAGEEXEC
26876+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
26877+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
26878+ return true;
26879+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
26880+ return true;
26881+ return false;
26882+ }
26883+#endif
26884+
26885+#ifdef CONFIG_PAX_SEGMEXEC
26886+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
26887+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
26888+ return true;
26889+ return false;
26890+ }
26891+#endif
26892+
26893+ return false;
26894+}
26895+#endif
26896+
26897+#ifdef CONFIG_PAX_EMUTRAMP
26898+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
26899+{
26900+ int err;
26901+
26902+ do { /* PaX: libffi trampoline emulation */
26903+ unsigned char mov, jmp;
26904+ unsigned int addr1, addr2;
26905+
26906+#ifdef CONFIG_X86_64
26907+ if ((regs->ip + 9) >> 32)
26908+ break;
26909+#endif
26910+
26911+ err = get_user(mov, (unsigned char __user *)regs->ip);
26912+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
26913+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
26914+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
26915+
26916+ if (err)
26917+ break;
26918+
26919+ if (mov == 0xB8 && jmp == 0xE9) {
26920+ regs->ax = addr1;
26921+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
26922+ return 2;
26923+ }
26924+ } while (0);
26925+
26926+ do { /* PaX: gcc trampoline emulation #1 */
26927+ unsigned char mov1, mov2;
26928+ unsigned short jmp;
26929+ unsigned int addr1, addr2;
26930+
26931+#ifdef CONFIG_X86_64
26932+ if ((regs->ip + 11) >> 32)
26933+ break;
26934+#endif
26935+
26936+ err = get_user(mov1, (unsigned char __user *)regs->ip);
26937+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
26938+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
26939+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
26940+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
26941+
26942+ if (err)
26943+ break;
26944+
26945+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
26946+ regs->cx = addr1;
26947+ regs->ax = addr2;
26948+ regs->ip = addr2;
26949+ return 2;
26950+ }
26951+ } while (0);
26952+
26953+ do { /* PaX: gcc trampoline emulation #2 */
26954+ unsigned char mov, jmp;
26955+ unsigned int addr1, addr2;
26956+
26957+#ifdef CONFIG_X86_64
26958+ if ((regs->ip + 9) >> 32)
26959+ break;
26960+#endif
26961+
26962+ err = get_user(mov, (unsigned char __user *)regs->ip);
26963+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
26964+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
26965+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
26966+
26967+ if (err)
26968+ break;
26969+
26970+ if (mov == 0xB9 && jmp == 0xE9) {
26971+ regs->cx = addr1;
26972+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
26973+ return 2;
26974+ }
26975+ } while (0);
26976+
26977+ return 1; /* PaX in action */
26978+}
26979+
26980+#ifdef CONFIG_X86_64
26981+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
26982+{
26983+ int err;
26984+
26985+ do { /* PaX: libffi trampoline emulation */
26986+ unsigned short mov1, mov2, jmp1;
26987+ unsigned char stcclc, jmp2;
26988+ unsigned long addr1, addr2;
26989+
26990+ err = get_user(mov1, (unsigned short __user *)regs->ip);
26991+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
26992+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
26993+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
26994+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
26995+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
26996+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
26997+
26998+ if (err)
26999+ break;
27000+
27001+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27002+ regs->r11 = addr1;
27003+ regs->r10 = addr2;
27004+ if (stcclc == 0xF8)
27005+ regs->flags &= ~X86_EFLAGS_CF;
27006+ else
27007+ regs->flags |= X86_EFLAGS_CF;
27008+ regs->ip = addr1;
27009+ return 2;
27010+ }
27011+ } while (0);
27012+
27013+ do { /* PaX: gcc trampoline emulation #1 */
27014+ unsigned short mov1, mov2, jmp1;
27015+ unsigned char jmp2;
27016+ unsigned int addr1;
27017+ unsigned long addr2;
27018+
27019+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27020+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
27021+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
27022+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
27023+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
27024+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
27025+
27026+ if (err)
27027+ break;
27028+
27029+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27030+ regs->r11 = addr1;
27031+ regs->r10 = addr2;
27032+ regs->ip = addr1;
27033+ return 2;
27034+ }
27035+ } while (0);
27036+
27037+ do { /* PaX: gcc trampoline emulation #2 */
27038+ unsigned short mov1, mov2, jmp1;
27039+ unsigned char jmp2;
27040+ unsigned long addr1, addr2;
27041+
27042+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27043+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
27044+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
27045+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
27046+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
27047+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
27048+
27049+ if (err)
27050+ break;
27051+
27052+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27053+ regs->r11 = addr1;
27054+ regs->r10 = addr2;
27055+ regs->ip = addr1;
27056+ return 2;
27057+ }
27058+ } while (0);
27059+
27060+ return 1; /* PaX in action */
27061+}
27062+#endif
27063+
27064+/*
27065+ * PaX: decide what to do with offenders (regs->ip = fault address)
27066+ *
27067+ * returns 1 when task should be killed
27068+ * 2 when gcc trampoline was detected
27069+ */
27070+static int pax_handle_fetch_fault(struct pt_regs *regs)
27071+{
27072+ if (v8086_mode(regs))
27073+ return 1;
27074+
27075+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
27076+ return 1;
27077+
27078+#ifdef CONFIG_X86_32
27079+ return pax_handle_fetch_fault_32(regs);
27080+#else
27081+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
27082+ return pax_handle_fetch_fault_32(regs);
27083+ else
27084+ return pax_handle_fetch_fault_64(regs);
27085+#endif
27086+}
27087+#endif
27088+
27089+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27090+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
27091+{
27092+ long i;
27093+
27094+ printk(KERN_ERR "PAX: bytes at PC: ");
27095+ for (i = 0; i < 20; i++) {
27096+ unsigned char c;
27097+ if (get_user(c, (unsigned char __force_user *)pc+i))
27098+ printk(KERN_CONT "?? ");
27099+ else
27100+ printk(KERN_CONT "%02x ", c);
27101+ }
27102+ printk("\n");
27103+
27104+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
27105+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
27106+ unsigned long c;
27107+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
27108+#ifdef CONFIG_X86_32
27109+ printk(KERN_CONT "???????? ");
27110+#else
27111+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
27112+ printk(KERN_CONT "???????? ???????? ");
27113+ else
27114+ printk(KERN_CONT "???????????????? ");
27115+#endif
27116+ } else {
27117+#ifdef CONFIG_X86_64
27118+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
27119+ printk(KERN_CONT "%08x ", (unsigned int)c);
27120+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
27121+ } else
27122+#endif
27123+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
27124+ }
27125+ }
27126+ printk("\n");
27127+}
27128+#endif
27129+
27130+/**
27131+ * probe_kernel_write(): safely attempt to write to a location
27132+ * @dst: address to write to
27133+ * @src: pointer to the data that shall be written
27134+ * @size: size of the data chunk
27135+ *
27136+ * Safely write to address @dst from the buffer at @src. If a kernel fault
27137+ * happens, handle that and return -EFAULT.
27138+ */
27139+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
27140+{
27141+ long ret;
27142+ mm_segment_t old_fs = get_fs();
27143+
27144+ set_fs(KERNEL_DS);
27145+ pagefault_disable();
27146+ pax_open_kernel();
27147+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
27148+ pax_close_kernel();
27149+ pagefault_enable();
27150+ set_fs(old_fs);
27151+
27152+ return ret ? -EFAULT : 0;
27153+}
27154diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
27155index dd74e46..7d26398 100644
27156--- a/arch/x86/mm/gup.c
27157+++ b/arch/x86/mm/gup.c
27158@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
27159 addr = start;
27160 len = (unsigned long) nr_pages << PAGE_SHIFT;
27161 end = start + len;
27162- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27163+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27164 (void __user *)start, len)))
27165 return 0;
27166
27167diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
27168index 6f31ee5..8ee4164 100644
27169--- a/arch/x86/mm/highmem_32.c
27170+++ b/arch/x86/mm/highmem_32.c
27171@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
27172 idx = type + KM_TYPE_NR*smp_processor_id();
27173 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
27174 BUG_ON(!pte_none(*(kmap_pte-idx)));
27175+
27176+ pax_open_kernel();
27177 set_pte(kmap_pte-idx, mk_pte(page, prot));
27178+ pax_close_kernel();
27179+
27180 arch_flush_lazy_mmu_mode();
27181
27182 return (void *)vaddr;
27183diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
27184index ae1aa71..56316db 100644
27185--- a/arch/x86/mm/hugetlbpage.c
27186+++ b/arch/x86/mm/hugetlbpage.c
27187@@ -279,6 +279,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
27188 info.flags = 0;
27189 info.length = len;
27190 info.low_limit = TASK_UNMAPPED_BASE;
27191+
27192+#ifdef CONFIG_PAX_RANDMMAP
27193+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
27194+ info.low_limit += current->mm->delta_mmap;
27195+#endif
27196+
27197 info.high_limit = TASK_SIZE;
27198 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
27199 info.align_offset = 0;
27200@@ -311,6 +317,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
27201 VM_BUG_ON(addr != -ENOMEM);
27202 info.flags = 0;
27203 info.low_limit = TASK_UNMAPPED_BASE;
27204+
27205+#ifdef CONFIG_PAX_RANDMMAP
27206+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
27207+ info.low_limit += current->mm->delta_mmap;
27208+#endif
27209+
27210 info.high_limit = TASK_SIZE;
27211 addr = vm_unmapped_area(&info);
27212 }
27213@@ -325,10 +337,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
27214 struct hstate *h = hstate_file(file);
27215 struct mm_struct *mm = current->mm;
27216 struct vm_area_struct *vma;
27217+ unsigned long pax_task_size = TASK_SIZE;
27218+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
27219
27220 if (len & ~huge_page_mask(h))
27221 return -EINVAL;
27222- if (len > TASK_SIZE)
27223+
27224+#ifdef CONFIG_PAX_SEGMEXEC
27225+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27226+ pax_task_size = SEGMEXEC_TASK_SIZE;
27227+#endif
27228+
27229+ pax_task_size -= PAGE_SIZE;
27230+
27231+ if (len > pax_task_size)
27232 return -ENOMEM;
27233
27234 if (flags & MAP_FIXED) {
27235@@ -337,11 +359,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
27236 return addr;
27237 }
27238
27239+#ifdef CONFIG_PAX_RANDMMAP
27240+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27241+#endif
27242+
27243 if (addr) {
27244 addr = ALIGN(addr, huge_page_size(h));
27245 vma = find_vma(mm, addr);
27246- if (TASK_SIZE - len >= addr &&
27247- (!vma || addr + len <= vma->vm_start))
27248+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27249 return addr;
27250 }
27251 if (mm->get_unmapped_area == arch_get_unmapped_area)
27252diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
27253index d7aea41..0fc945b 100644
27254--- a/arch/x86/mm/init.c
27255+++ b/arch/x86/mm/init.c
27256@@ -4,6 +4,7 @@
27257 #include <linux/swap.h>
27258 #include <linux/memblock.h>
27259 #include <linux/bootmem.h> /* for max_low_pfn */
27260+#include <linux/tboot.h>
27261
27262 #include <asm/cacheflush.h>
27263 #include <asm/e820.h>
27264@@ -16,6 +17,8 @@
27265 #include <asm/tlb.h>
27266 #include <asm/proto.h>
27267 #include <asm/dma.h> /* for MAX_DMA_PFN */
27268+#include <asm/desc.h>
27269+#include <asm/bios_ebda.h>
27270
27271 unsigned long __initdata pgt_buf_start;
27272 unsigned long __meminitdata pgt_buf_end;
27273@@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
27274 {
27275 int i;
27276 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
27277- unsigned long start = 0, good_end;
27278+ unsigned long start = 0x100000, good_end;
27279 phys_addr_t base;
27280
27281 for (i = 0; i < nr_range; i++) {
27282@@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
27283 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
27284 * mmio resources as well as potential bios/acpi data regions.
27285 */
27286+
27287+#ifdef CONFIG_GRKERNSEC_KMEM
27288+static unsigned int ebda_start __read_only;
27289+static unsigned int ebda_end __read_only;
27290+#endif
27291+
27292 int devmem_is_allowed(unsigned long pagenr)
27293 {
27294- if (pagenr < 256)
27295+#ifdef CONFIG_GRKERNSEC_KMEM
27296+ /* allow BDA */
27297+ if (!pagenr)
27298 return 1;
27299+ /* allow EBDA */
27300+ if (pagenr >= ebda_start && pagenr < ebda_end)
27301+ return 1;
27302+ /* if tboot is in use, allow access to its hardcoded serial log range */
27303+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
27304+ return 1;
27305+#else
27306+ if (!pagenr)
27307+ return 1;
27308+#ifdef CONFIG_VM86
27309+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
27310+ return 1;
27311+#endif
27312+#endif
27313+
27314+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
27315+ return 1;
27316+#ifdef CONFIG_GRKERNSEC_KMEM
27317+ /* throw out everything else below 1MB */
27318+ if (pagenr <= 256)
27319+ return 0;
27320+#endif
27321 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
27322 return 0;
27323 if (!page_is_ram(pagenr))
27324@@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
27325 #endif
27326 }
27327
27328+#ifdef CONFIG_GRKERNSEC_KMEM
27329+static inline void gr_init_ebda(void)
27330+{
27331+ unsigned int ebda_addr;
27332+ unsigned int ebda_size = 0;
27333+
27334+ ebda_addr = get_bios_ebda();
27335+ if (ebda_addr) {
27336+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
27337+ ebda_size <<= 10;
27338+ }
27339+ if (ebda_addr && ebda_size) {
27340+ ebda_start = ebda_addr >> PAGE_SHIFT;
27341+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
27342+ } else {
27343+ ebda_start = 0x9f000 >> PAGE_SHIFT;
27344+ ebda_end = 0xa0000 >> PAGE_SHIFT;
27345+ }
27346+}
27347+#else
27348+static inline void gr_init_ebda(void) { }
27349+#endif
27350+
27351 void free_initmem(void)
27352 {
27353+#ifdef CONFIG_PAX_KERNEXEC
27354+#ifdef CONFIG_X86_32
27355+ /* PaX: limit KERNEL_CS to actual size */
27356+ unsigned long addr, limit;
27357+ struct desc_struct d;
27358+ int cpu;
27359+#else
27360+ pgd_t *pgd;
27361+ pud_t *pud;
27362+ pmd_t *pmd;
27363+ unsigned long addr, end;
27364+#endif
27365+#endif
27366+
27367+ gr_init_ebda();
27368+
27369+#ifdef CONFIG_PAX_KERNEXEC
27370+#ifdef CONFIG_X86_32
27371+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
27372+ limit = (limit - 1UL) >> PAGE_SHIFT;
27373+
27374+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
27375+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
27376+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
27377+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
27378+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
27379+ }
27380+
27381+ /* PaX: make KERNEL_CS read-only */
27382+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
27383+ if (!paravirt_enabled())
27384+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
27385+/*
27386+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
27387+ pgd = pgd_offset_k(addr);
27388+ pud = pud_offset(pgd, addr);
27389+ pmd = pmd_offset(pud, addr);
27390+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
27391+ }
27392+*/
27393+#ifdef CONFIG_X86_PAE
27394+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
27395+/*
27396+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
27397+ pgd = pgd_offset_k(addr);
27398+ pud = pud_offset(pgd, addr);
27399+ pmd = pmd_offset(pud, addr);
27400+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
27401+ }
27402+*/
27403+#endif
27404+
27405+#ifdef CONFIG_MODULES
27406+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
27407+#endif
27408+
27409+#else
27410+ /* PaX: make kernel code/rodata read-only, rest non-executable */
27411+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
27412+ pgd = pgd_offset_k(addr);
27413+ pud = pud_offset(pgd, addr);
27414+ pmd = pmd_offset(pud, addr);
27415+ if (!pmd_present(*pmd))
27416+ continue;
27417+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
27418+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
27419+ else
27420+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
27421+ }
27422+
27423+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
27424+ end = addr + KERNEL_IMAGE_SIZE;
27425+ for (; addr < end; addr += PMD_SIZE) {
27426+ pgd = pgd_offset_k(addr);
27427+ pud = pud_offset(pgd, addr);
27428+ pmd = pmd_offset(pud, addr);
27429+ if (!pmd_present(*pmd))
27430+ continue;
27431+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
27432+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
27433+ }
27434+#endif
27435+
27436+ flush_tlb_all();
27437+#endif
27438+
27439 free_init_pages("unused kernel memory",
27440 (unsigned long)(&__init_begin),
27441 (unsigned long)(&__init_end));
27442diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
27443index 745d66b..56bf568 100644
27444--- a/arch/x86/mm/init_32.c
27445+++ b/arch/x86/mm/init_32.c
27446@@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
27447 }
27448
27449 /*
27450- * Creates a middle page table and puts a pointer to it in the
27451- * given global directory entry. This only returns the gd entry
27452- * in non-PAE compilation mode, since the middle layer is folded.
27453- */
27454-static pmd_t * __init one_md_table_init(pgd_t *pgd)
27455-{
27456- pud_t *pud;
27457- pmd_t *pmd_table;
27458-
27459-#ifdef CONFIG_X86_PAE
27460- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
27461- if (after_bootmem)
27462- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
27463- else
27464- pmd_table = (pmd_t *)alloc_low_page();
27465- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
27466- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
27467- pud = pud_offset(pgd, 0);
27468- BUG_ON(pmd_table != pmd_offset(pud, 0));
27469-
27470- return pmd_table;
27471- }
27472-#endif
27473- pud = pud_offset(pgd, 0);
27474- pmd_table = pmd_offset(pud, 0);
27475-
27476- return pmd_table;
27477-}
27478-
27479-/*
27480 * Create a page table and place a pointer to it in a middle page
27481 * directory entry:
27482 */
27483@@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
27484 page_table = (pte_t *)alloc_low_page();
27485
27486 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
27487+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27488+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
27489+#else
27490 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
27491+#endif
27492 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
27493 }
27494
27495 return pte_offset_kernel(pmd, 0);
27496 }
27497
27498+static pmd_t * __init one_md_table_init(pgd_t *pgd)
27499+{
27500+ pud_t *pud;
27501+ pmd_t *pmd_table;
27502+
27503+ pud = pud_offset(pgd, 0);
27504+ pmd_table = pmd_offset(pud, 0);
27505+
27506+ return pmd_table;
27507+}
27508+
27509 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
27510 {
27511 int pgd_idx = pgd_index(vaddr);
27512@@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
27513 int pgd_idx, pmd_idx;
27514 unsigned long vaddr;
27515 pgd_t *pgd;
27516+ pud_t *pud;
27517 pmd_t *pmd;
27518 pte_t *pte = NULL;
27519
27520@@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
27521 pgd = pgd_base + pgd_idx;
27522
27523 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
27524- pmd = one_md_table_init(pgd);
27525- pmd = pmd + pmd_index(vaddr);
27526+ pud = pud_offset(pgd, vaddr);
27527+ pmd = pmd_offset(pud, vaddr);
27528+
27529+#ifdef CONFIG_X86_PAE
27530+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
27531+#endif
27532+
27533 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
27534 pmd++, pmd_idx++) {
27535 pte = page_table_kmap_check(one_page_table_init(pmd),
27536@@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
27537 }
27538 }
27539
27540-static inline int is_kernel_text(unsigned long addr)
27541+static inline int is_kernel_text(unsigned long start, unsigned long end)
27542 {
27543- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
27544- return 1;
27545- return 0;
27546+ if ((start > ktla_ktva((unsigned long)_etext) ||
27547+ end <= ktla_ktva((unsigned long)_stext)) &&
27548+ (start > ktla_ktva((unsigned long)_einittext) ||
27549+ end <= ktla_ktva((unsigned long)_sinittext)) &&
27550+
27551+#ifdef CONFIG_ACPI_SLEEP
27552+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
27553+#endif
27554+
27555+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
27556+ return 0;
27557+ return 1;
27558 }
27559
27560 /*
27561@@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
27562 unsigned long last_map_addr = end;
27563 unsigned long start_pfn, end_pfn;
27564 pgd_t *pgd_base = swapper_pg_dir;
27565- int pgd_idx, pmd_idx, pte_ofs;
27566+ unsigned int pgd_idx, pmd_idx, pte_ofs;
27567 unsigned long pfn;
27568 pgd_t *pgd;
27569+ pud_t *pud;
27570 pmd_t *pmd;
27571 pte_t *pte;
27572 unsigned pages_2m, pages_4k;
27573@@ -280,8 +281,13 @@ repeat:
27574 pfn = start_pfn;
27575 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
27576 pgd = pgd_base + pgd_idx;
27577- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
27578- pmd = one_md_table_init(pgd);
27579+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
27580+ pud = pud_offset(pgd, 0);
27581+ pmd = pmd_offset(pud, 0);
27582+
27583+#ifdef CONFIG_X86_PAE
27584+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
27585+#endif
27586
27587 if (pfn >= end_pfn)
27588 continue;
27589@@ -293,14 +299,13 @@ repeat:
27590 #endif
27591 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
27592 pmd++, pmd_idx++) {
27593- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
27594+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
27595
27596 /*
27597 * Map with big pages if possible, otherwise
27598 * create normal page tables:
27599 */
27600 if (use_pse) {
27601- unsigned int addr2;
27602 pgprot_t prot = PAGE_KERNEL_LARGE;
27603 /*
27604 * first pass will use the same initial
27605@@ -310,11 +315,7 @@ repeat:
27606 __pgprot(PTE_IDENT_ATTR |
27607 _PAGE_PSE);
27608
27609- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
27610- PAGE_OFFSET + PAGE_SIZE-1;
27611-
27612- if (is_kernel_text(addr) ||
27613- is_kernel_text(addr2))
27614+ if (is_kernel_text(address, address + PMD_SIZE))
27615 prot = PAGE_KERNEL_LARGE_EXEC;
27616
27617 pages_2m++;
27618@@ -331,7 +332,7 @@ repeat:
27619 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
27620 pte += pte_ofs;
27621 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
27622- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
27623+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
27624 pgprot_t prot = PAGE_KERNEL;
27625 /*
27626 * first pass will use the same initial
27627@@ -339,7 +340,7 @@ repeat:
27628 */
27629 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
27630
27631- if (is_kernel_text(addr))
27632+ if (is_kernel_text(address, address + PAGE_SIZE))
27633 prot = PAGE_KERNEL_EXEC;
27634
27635 pages_4k++;
27636@@ -465,7 +466,7 @@ void __init native_pagetable_init(void)
27637
27638 pud = pud_offset(pgd, va);
27639 pmd = pmd_offset(pud, va);
27640- if (!pmd_present(*pmd))
27641+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
27642 break;
27643
27644 pte = pte_offset_kernel(pmd, va);
27645@@ -514,12 +515,10 @@ void __init early_ioremap_page_table_range_init(void)
27646
27647 static void __init pagetable_init(void)
27648 {
27649- pgd_t *pgd_base = swapper_pg_dir;
27650-
27651- permanent_kmaps_init(pgd_base);
27652+ permanent_kmaps_init(swapper_pg_dir);
27653 }
27654
27655-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
27656+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
27657 EXPORT_SYMBOL_GPL(__supported_pte_mask);
27658
27659 /* user-defined highmem size */
27660@@ -728,6 +727,12 @@ void __init mem_init(void)
27661
27662 pci_iommu_alloc();
27663
27664+#ifdef CONFIG_PAX_PER_CPU_PGD
27665+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
27666+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27667+ KERNEL_PGD_PTRS);
27668+#endif
27669+
27670 #ifdef CONFIG_FLATMEM
27671 BUG_ON(!mem_map);
27672 #endif
27673@@ -754,7 +759,7 @@ void __init mem_init(void)
27674 reservedpages++;
27675
27676 codesize = (unsigned long) &_etext - (unsigned long) &_text;
27677- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
27678+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
27679 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
27680
27681 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
27682@@ -795,10 +800,10 @@ void __init mem_init(void)
27683 ((unsigned long)&__init_end -
27684 (unsigned long)&__init_begin) >> 10,
27685
27686- (unsigned long)&_etext, (unsigned long)&_edata,
27687- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
27688+ (unsigned long)&_sdata, (unsigned long)&_edata,
27689+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
27690
27691- (unsigned long)&_text, (unsigned long)&_etext,
27692+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
27693 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
27694
27695 /*
27696@@ -876,6 +881,7 @@ void set_kernel_text_rw(void)
27697 if (!kernel_set_to_readonly)
27698 return;
27699
27700+ start = ktla_ktva(start);
27701 pr_debug("Set kernel text: %lx - %lx for read write\n",
27702 start, start+size);
27703
27704@@ -890,6 +896,7 @@ void set_kernel_text_ro(void)
27705 if (!kernel_set_to_readonly)
27706 return;
27707
27708+ start = ktla_ktva(start);
27709 pr_debug("Set kernel text: %lx - %lx for read only\n",
27710 start, start+size);
27711
27712@@ -918,6 +925,7 @@ void mark_rodata_ro(void)
27713 unsigned long start = PFN_ALIGN(_text);
27714 unsigned long size = PFN_ALIGN(_etext) - start;
27715
27716+ start = ktla_ktva(start);
27717 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
27718 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
27719 size >> 10);
27720diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
27721index 75c9a6a..498d677 100644
27722--- a/arch/x86/mm/init_64.c
27723+++ b/arch/x86/mm/init_64.c
27724@@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
27725 * around without checking the pgd every time.
27726 */
27727
27728-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
27729+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
27730 EXPORT_SYMBOL_GPL(__supported_pte_mask);
27731
27732 int force_personality32;
27733@@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
27734
27735 for (address = start; address <= end; address += PGDIR_SIZE) {
27736 const pgd_t *pgd_ref = pgd_offset_k(address);
27737+
27738+#ifdef CONFIG_PAX_PER_CPU_PGD
27739+ unsigned long cpu;
27740+#else
27741 struct page *page;
27742+#endif
27743
27744 if (pgd_none(*pgd_ref))
27745 continue;
27746
27747 spin_lock(&pgd_lock);
27748+
27749+#ifdef CONFIG_PAX_PER_CPU_PGD
27750+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
27751+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
27752+#else
27753 list_for_each_entry(page, &pgd_list, lru) {
27754 pgd_t *pgd;
27755 spinlock_t *pgt_lock;
27756@@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
27757 /* the pgt_lock only for Xen */
27758 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
27759 spin_lock(pgt_lock);
27760+#endif
27761
27762 if (pgd_none(*pgd))
27763 set_pgd(pgd, *pgd_ref);
27764@@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
27765 BUG_ON(pgd_page_vaddr(*pgd)
27766 != pgd_page_vaddr(*pgd_ref));
27767
27768+#ifndef CONFIG_PAX_PER_CPU_PGD
27769 spin_unlock(pgt_lock);
27770+#endif
27771+
27772 }
27773 spin_unlock(&pgd_lock);
27774 }
27775@@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
27776 {
27777 if (pgd_none(*pgd)) {
27778 pud_t *pud = (pud_t *)spp_getpage();
27779- pgd_populate(&init_mm, pgd, pud);
27780+ pgd_populate_kernel(&init_mm, pgd, pud);
27781 if (pud != pud_offset(pgd, 0))
27782 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
27783 pud, pud_offset(pgd, 0));
27784@@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
27785 {
27786 if (pud_none(*pud)) {
27787 pmd_t *pmd = (pmd_t *) spp_getpage();
27788- pud_populate(&init_mm, pud, pmd);
27789+ pud_populate_kernel(&init_mm, pud, pmd);
27790 if (pmd != pmd_offset(pud, 0))
27791 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
27792 pmd, pmd_offset(pud, 0));
27793@@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
27794 pmd = fill_pmd(pud, vaddr);
27795 pte = fill_pte(pmd, vaddr);
27796
27797+ pax_open_kernel();
27798 set_pte(pte, new_pte);
27799+ pax_close_kernel();
27800
27801 /*
27802 * It's enough to flush this one mapping.
27803@@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
27804 pgd = pgd_offset_k((unsigned long)__va(phys));
27805 if (pgd_none(*pgd)) {
27806 pud = (pud_t *) spp_getpage();
27807- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
27808- _PAGE_USER));
27809+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
27810 }
27811 pud = pud_offset(pgd, (unsigned long)__va(phys));
27812 if (pud_none(*pud)) {
27813 pmd = (pmd_t *) spp_getpage();
27814- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
27815- _PAGE_USER));
27816+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
27817 }
27818 pmd = pmd_offset(pud, phys);
27819 BUG_ON(!pmd_none(*pmd));
27820@@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
27821 if (pfn >= pgt_buf_top)
27822 panic("alloc_low_page: ran out of memory");
27823
27824- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
27825+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
27826 clear_page(adr);
27827 *phys = pfn * PAGE_SIZE;
27828 return adr;
27829@@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
27830
27831 phys = __pa(virt);
27832 left = phys & (PAGE_SIZE - 1);
27833- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
27834+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
27835 adr = (void *)(((unsigned long)adr) | left);
27836
27837 return adr;
27838@@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
27839 unmap_low_page(pmd);
27840
27841 spin_lock(&init_mm.page_table_lock);
27842- pud_populate(&init_mm, pud, __va(pmd_phys));
27843+ pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
27844 spin_unlock(&init_mm.page_table_lock);
27845 }
27846 __flush_tlb_all();
27847@@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
27848 unmap_low_page(pud);
27849
27850 spin_lock(&init_mm.page_table_lock);
27851- pgd_populate(&init_mm, pgd, __va(pud_phys));
27852+ pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
27853 spin_unlock(&init_mm.page_table_lock);
27854 pgd_changed = true;
27855 }
27856@@ -693,6 +707,12 @@ void __init mem_init(void)
27857
27858 pci_iommu_alloc();
27859
27860+#ifdef CONFIG_PAX_PER_CPU_PGD
27861+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
27862+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27863+ KERNEL_PGD_PTRS);
27864+#endif
27865+
27866 /* clear_bss() already clear the empty_zero_page */
27867
27868 reservedpages = 0;
27869@@ -856,8 +876,8 @@ int kern_addr_valid(unsigned long addr)
27870 static struct vm_area_struct gate_vma = {
27871 .vm_start = VSYSCALL_START,
27872 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
27873- .vm_page_prot = PAGE_READONLY_EXEC,
27874- .vm_flags = VM_READ | VM_EXEC
27875+ .vm_page_prot = PAGE_READONLY,
27876+ .vm_flags = VM_READ
27877 };
27878
27879 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27880@@ -891,7 +911,7 @@ int in_gate_area_no_mm(unsigned long addr)
27881
27882 const char *arch_vma_name(struct vm_area_struct *vma)
27883 {
27884- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27885+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27886 return "[vdso]";
27887 if (vma == &gate_vma)
27888 return "[vsyscall]";
27889diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
27890index 7b179b4..6bd1777 100644
27891--- a/arch/x86/mm/iomap_32.c
27892+++ b/arch/x86/mm/iomap_32.c
27893@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
27894 type = kmap_atomic_idx_push();
27895 idx = type + KM_TYPE_NR * smp_processor_id();
27896 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
27897+
27898+ pax_open_kernel();
27899 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
27900+ pax_close_kernel();
27901+
27902 arch_flush_lazy_mmu_mode();
27903
27904 return (void *)vaddr;
27905diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
27906index 78fe3f1..2f9433c 100644
27907--- a/arch/x86/mm/ioremap.c
27908+++ b/arch/x86/mm/ioremap.c
27909@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
27910 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
27911 int is_ram = page_is_ram(pfn);
27912
27913- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
27914+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
27915 return NULL;
27916 WARN_ON_ONCE(is_ram);
27917 }
27918@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
27919 *
27920 * Caller must ensure there is only one unmapping for the same pointer.
27921 */
27922-void iounmap(volatile void __iomem *addr)
27923+void iounmap(const volatile void __iomem *addr)
27924 {
27925 struct vm_struct *p, *o;
27926
27927@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
27928
27929 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
27930 if (page_is_ram(start >> PAGE_SHIFT))
27931+#ifdef CONFIG_HIGHMEM
27932+ if ((start >> PAGE_SHIFT) < max_low_pfn)
27933+#endif
27934 return __va(phys);
27935
27936 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
27937@@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
27938 early_param("early_ioremap_debug", early_ioremap_debug_setup);
27939
27940 static __initdata int after_paging_init;
27941-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
27942+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
27943
27944 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
27945 {
27946@@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
27947 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
27948
27949 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
27950- memset(bm_pte, 0, sizeof(bm_pte));
27951- pmd_populate_kernel(&init_mm, pmd, bm_pte);
27952+ pmd_populate_user(&init_mm, pmd, bm_pte);
27953
27954 /*
27955 * The boot-ioremap range spans multiple pmds, for which
27956diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
27957index d87dd6d..bf3fa66 100644
27958--- a/arch/x86/mm/kmemcheck/kmemcheck.c
27959+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
27960@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
27961 * memory (e.g. tracked pages)? For now, we need this to avoid
27962 * invoking kmemcheck for PnP BIOS calls.
27963 */
27964- if (regs->flags & X86_VM_MASK)
27965+ if (v8086_mode(regs))
27966 return false;
27967- if (regs->cs != __KERNEL_CS)
27968+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
27969 return false;
27970
27971 pte = kmemcheck_pte_lookup(address);
27972diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
27973index 845df68..1d8d29f 100644
27974--- a/arch/x86/mm/mmap.c
27975+++ b/arch/x86/mm/mmap.c
27976@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
27977 * Leave an at least ~128 MB hole with possible stack randomization.
27978 */
27979 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
27980-#define MAX_GAP (TASK_SIZE/6*5)
27981+#define MAX_GAP (pax_task_size/6*5)
27982
27983 static int mmap_is_legacy(void)
27984 {
27985@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
27986 return rnd << PAGE_SHIFT;
27987 }
27988
27989-static unsigned long mmap_base(void)
27990+static unsigned long mmap_base(struct mm_struct *mm)
27991 {
27992 unsigned long gap = rlimit(RLIMIT_STACK);
27993+ unsigned long pax_task_size = TASK_SIZE;
27994+
27995+#ifdef CONFIG_PAX_SEGMEXEC
27996+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27997+ pax_task_size = SEGMEXEC_TASK_SIZE;
27998+#endif
27999
28000 if (gap < MIN_GAP)
28001 gap = MIN_GAP;
28002 else if (gap > MAX_GAP)
28003 gap = MAX_GAP;
28004
28005- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
28006+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
28007 }
28008
28009 /*
28010 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
28011 * does, but not when emulating X86_32
28012 */
28013-static unsigned long mmap_legacy_base(void)
28014+static unsigned long mmap_legacy_base(struct mm_struct *mm)
28015 {
28016- if (mmap_is_ia32())
28017+ if (mmap_is_ia32()) {
28018+
28019+#ifdef CONFIG_PAX_SEGMEXEC
28020+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28021+ return SEGMEXEC_TASK_UNMAPPED_BASE;
28022+ else
28023+#endif
28024+
28025 return TASK_UNMAPPED_BASE;
28026- else
28027+ } else
28028 return TASK_UNMAPPED_BASE + mmap_rnd();
28029 }
28030
28031@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
28032 void arch_pick_mmap_layout(struct mm_struct *mm)
28033 {
28034 if (mmap_is_legacy()) {
28035- mm->mmap_base = mmap_legacy_base();
28036+ mm->mmap_base = mmap_legacy_base(mm);
28037+
28038+#ifdef CONFIG_PAX_RANDMMAP
28039+ if (mm->pax_flags & MF_PAX_RANDMMAP)
28040+ mm->mmap_base += mm->delta_mmap;
28041+#endif
28042+
28043 mm->get_unmapped_area = arch_get_unmapped_area;
28044 mm->unmap_area = arch_unmap_area;
28045 } else {
28046- mm->mmap_base = mmap_base();
28047+ mm->mmap_base = mmap_base(mm);
28048+
28049+#ifdef CONFIG_PAX_RANDMMAP
28050+ if (mm->pax_flags & MF_PAX_RANDMMAP)
28051+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
28052+#endif
28053+
28054 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
28055 mm->unmap_area = arch_unmap_area_topdown;
28056 }
28057diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
28058index dc0b727..f612039 100644
28059--- a/arch/x86/mm/mmio-mod.c
28060+++ b/arch/x86/mm/mmio-mod.c
28061@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
28062 break;
28063 default:
28064 {
28065- unsigned char *ip = (unsigned char *)instptr;
28066+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
28067 my_trace->opcode = MMIO_UNKNOWN_OP;
28068 my_trace->width = 0;
28069 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
28070@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
28071 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
28072 void __iomem *addr)
28073 {
28074- static atomic_t next_id;
28075+ static atomic_unchecked_t next_id;
28076 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
28077 /* These are page-unaligned. */
28078 struct mmiotrace_map map = {
28079@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
28080 .private = trace
28081 },
28082 .phys = offset,
28083- .id = atomic_inc_return(&next_id)
28084+ .id = atomic_inc_return_unchecked(&next_id)
28085 };
28086 map.map_id = trace->id;
28087
28088@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
28089 ioremap_trace_core(offset, size, addr);
28090 }
28091
28092-static void iounmap_trace_core(volatile void __iomem *addr)
28093+static void iounmap_trace_core(const volatile void __iomem *addr)
28094 {
28095 struct mmiotrace_map map = {
28096 .phys = 0,
28097@@ -328,7 +328,7 @@ not_enabled:
28098 }
28099 }
28100
28101-void mmiotrace_iounmap(volatile void __iomem *addr)
28102+void mmiotrace_iounmap(const volatile void __iomem *addr)
28103 {
28104 might_sleep();
28105 if (is_enabled()) /* recheck and proper locking in *_core() */
28106diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
28107index b008656..773eac2 100644
28108--- a/arch/x86/mm/pageattr-test.c
28109+++ b/arch/x86/mm/pageattr-test.c
28110@@ -36,7 +36,7 @@ enum {
28111
28112 static int pte_testbit(pte_t pte)
28113 {
28114- return pte_flags(pte) & _PAGE_UNUSED1;
28115+ return pte_flags(pte) & _PAGE_CPA_TEST;
28116 }
28117
28118 struct split_state {
28119diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
28120index a718e0d..77419bc 100644
28121--- a/arch/x86/mm/pageattr.c
28122+++ b/arch/x86/mm/pageattr.c
28123@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28124 */
28125 #ifdef CONFIG_PCI_BIOS
28126 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
28127- pgprot_val(forbidden) |= _PAGE_NX;
28128+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28129 #endif
28130
28131 /*
28132@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28133 * Does not cover __inittext since that is gone later on. On
28134 * 64bit we do not enforce !NX on the low mapping
28135 */
28136- if (within(address, (unsigned long)_text, (unsigned long)_etext))
28137- pgprot_val(forbidden) |= _PAGE_NX;
28138+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
28139+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28140
28141+#ifdef CONFIG_DEBUG_RODATA
28142 /*
28143 * The .rodata section needs to be read-only. Using the pfn
28144 * catches all aliases.
28145@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28146 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
28147 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
28148 pgprot_val(forbidden) |= _PAGE_RW;
28149+#endif
28150
28151 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
28152 /*
28153@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28154 }
28155 #endif
28156
28157+#ifdef CONFIG_PAX_KERNEXEC
28158+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
28159+ pgprot_val(forbidden) |= _PAGE_RW;
28160+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28161+ }
28162+#endif
28163+
28164 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
28165
28166 return prot;
28167@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
28168 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
28169 {
28170 /* change init_mm */
28171+ pax_open_kernel();
28172 set_pte_atomic(kpte, pte);
28173+
28174 #ifdef CONFIG_X86_32
28175 if (!SHARED_KERNEL_PMD) {
28176+
28177+#ifdef CONFIG_PAX_PER_CPU_PGD
28178+ unsigned long cpu;
28179+#else
28180 struct page *page;
28181+#endif
28182
28183+#ifdef CONFIG_PAX_PER_CPU_PGD
28184+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
28185+ pgd_t *pgd = get_cpu_pgd(cpu);
28186+#else
28187 list_for_each_entry(page, &pgd_list, lru) {
28188- pgd_t *pgd;
28189+ pgd_t *pgd = (pgd_t *)page_address(page);
28190+#endif
28191+
28192 pud_t *pud;
28193 pmd_t *pmd;
28194
28195- pgd = (pgd_t *)page_address(page) + pgd_index(address);
28196+ pgd += pgd_index(address);
28197 pud = pud_offset(pgd, address);
28198 pmd = pmd_offset(pud, address);
28199 set_pte_atomic((pte_t *)pmd, pte);
28200 }
28201 }
28202 #endif
28203+ pax_close_kernel();
28204 }
28205
28206 static int
28207diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
28208index 0eb572e..92f5c1e 100644
28209--- a/arch/x86/mm/pat.c
28210+++ b/arch/x86/mm/pat.c
28211@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
28212
28213 if (!entry) {
28214 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
28215- current->comm, current->pid, start, end - 1);
28216+ current->comm, task_pid_nr(current), start, end - 1);
28217 return -EINVAL;
28218 }
28219
28220@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28221
28222 while (cursor < to) {
28223 if (!devmem_is_allowed(pfn)) {
28224- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
28225- current->comm, from, to - 1);
28226+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
28227+ current->comm, from, to - 1, cursor);
28228 return 0;
28229 }
28230 cursor += PAGE_SIZE;
28231@@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
28232 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
28233 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
28234 "for [mem %#010Lx-%#010Lx]\n",
28235- current->comm, current->pid,
28236+ current->comm, task_pid_nr(current),
28237 cattr_name(flags),
28238 base, (unsigned long long)(base + size-1));
28239 return -EINVAL;
28240@@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
28241 flags = lookup_memtype(paddr);
28242 if (want_flags != flags) {
28243 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
28244- current->comm, current->pid,
28245+ current->comm, task_pid_nr(current),
28246 cattr_name(want_flags),
28247 (unsigned long long)paddr,
28248 (unsigned long long)(paddr + size - 1),
28249@@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
28250 free_memtype(paddr, paddr + size);
28251 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
28252 " for [mem %#010Lx-%#010Lx], got %s\n",
28253- current->comm, current->pid,
28254+ current->comm, task_pid_nr(current),
28255 cattr_name(want_flags),
28256 (unsigned long long)paddr,
28257 (unsigned long long)(paddr + size - 1),
28258diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
28259index 9f0614d..92ae64a 100644
28260--- a/arch/x86/mm/pf_in.c
28261+++ b/arch/x86/mm/pf_in.c
28262@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
28263 int i;
28264 enum reason_type rv = OTHERS;
28265
28266- p = (unsigned char *)ins_addr;
28267+ p = (unsigned char *)ktla_ktva(ins_addr);
28268 p += skip_prefix(p, &prf);
28269 p += get_opcode(p, &opcode);
28270
28271@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
28272 struct prefix_bits prf;
28273 int i;
28274
28275- p = (unsigned char *)ins_addr;
28276+ p = (unsigned char *)ktla_ktva(ins_addr);
28277 p += skip_prefix(p, &prf);
28278 p += get_opcode(p, &opcode);
28279
28280@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
28281 struct prefix_bits prf;
28282 int i;
28283
28284- p = (unsigned char *)ins_addr;
28285+ p = (unsigned char *)ktla_ktva(ins_addr);
28286 p += skip_prefix(p, &prf);
28287 p += get_opcode(p, &opcode);
28288
28289@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
28290 struct prefix_bits prf;
28291 int i;
28292
28293- p = (unsigned char *)ins_addr;
28294+ p = (unsigned char *)ktla_ktva(ins_addr);
28295 p += skip_prefix(p, &prf);
28296 p += get_opcode(p, &opcode);
28297 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
28298@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
28299 struct prefix_bits prf;
28300 int i;
28301
28302- p = (unsigned char *)ins_addr;
28303+ p = (unsigned char *)ktla_ktva(ins_addr);
28304 p += skip_prefix(p, &prf);
28305 p += get_opcode(p, &opcode);
28306 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
28307diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
28308index e27fbf8..8b56dc9 100644
28309--- a/arch/x86/mm/pgtable.c
28310+++ b/arch/x86/mm/pgtable.c
28311@@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
28312 list_del(&page->lru);
28313 }
28314
28315-#define UNSHARED_PTRS_PER_PGD \
28316- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
28317+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28318+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
28319
28320+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
28321+{
28322+ unsigned int count = USER_PGD_PTRS;
28323
28324+ while (count--)
28325+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
28326+}
28327+#endif
28328+
28329+#ifdef CONFIG_PAX_PER_CPU_PGD
28330+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
28331+{
28332+ unsigned int count = USER_PGD_PTRS;
28333+
28334+ while (count--) {
28335+ pgd_t pgd;
28336+
28337+#ifdef CONFIG_X86_64
28338+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
28339+#else
28340+ pgd = *src++;
28341+#endif
28342+
28343+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28344+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
28345+#endif
28346+
28347+ *dst++ = pgd;
28348+ }
28349+
28350+}
28351+#endif
28352+
28353+#ifdef CONFIG_X86_64
28354+#define pxd_t pud_t
28355+#define pyd_t pgd_t
28356+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
28357+#define pxd_free(mm, pud) pud_free((mm), (pud))
28358+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
28359+#define pyd_offset(mm, address) pgd_offset((mm), (address))
28360+#define PYD_SIZE PGDIR_SIZE
28361+#else
28362+#define pxd_t pmd_t
28363+#define pyd_t pud_t
28364+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
28365+#define pxd_free(mm, pud) pmd_free((mm), (pud))
28366+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
28367+#define pyd_offset(mm, address) pud_offset((mm), (address))
28368+#define PYD_SIZE PUD_SIZE
28369+#endif
28370+
28371+#ifdef CONFIG_PAX_PER_CPU_PGD
28372+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
28373+static inline void pgd_dtor(pgd_t *pgd) {}
28374+#else
28375 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
28376 {
28377 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
28378@@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
28379 pgd_list_del(pgd);
28380 spin_unlock(&pgd_lock);
28381 }
28382+#endif
28383
28384 /*
28385 * List of all pgd's needed for non-PAE so it can invalidate entries
28386@@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
28387 * -- nyc
28388 */
28389
28390-#ifdef CONFIG_X86_PAE
28391+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
28392 /*
28393 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
28394 * updating the top-level pagetable entries to guarantee the
28395@@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
28396 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
28397 * and initialize the kernel pmds here.
28398 */
28399-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
28400+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
28401
28402 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
28403 {
28404@@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
28405 */
28406 flush_tlb_mm(mm);
28407 }
28408+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
28409+#define PREALLOCATED_PXDS USER_PGD_PTRS
28410 #else /* !CONFIG_X86_PAE */
28411
28412 /* No need to prepopulate any pagetable entries in non-PAE modes. */
28413-#define PREALLOCATED_PMDS 0
28414+#define PREALLOCATED_PXDS 0
28415
28416 #endif /* CONFIG_X86_PAE */
28417
28418-static void free_pmds(pmd_t *pmds[])
28419+static void free_pxds(pxd_t *pxds[])
28420 {
28421 int i;
28422
28423- for(i = 0; i < PREALLOCATED_PMDS; i++)
28424- if (pmds[i])
28425- free_page((unsigned long)pmds[i]);
28426+ for(i = 0; i < PREALLOCATED_PXDS; i++)
28427+ if (pxds[i])
28428+ free_page((unsigned long)pxds[i]);
28429 }
28430
28431-static int preallocate_pmds(pmd_t *pmds[])
28432+static int preallocate_pxds(pxd_t *pxds[])
28433 {
28434 int i;
28435 bool failed = false;
28436
28437- for(i = 0; i < PREALLOCATED_PMDS; i++) {
28438- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
28439- if (pmd == NULL)
28440+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
28441+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
28442+ if (pxd == NULL)
28443 failed = true;
28444- pmds[i] = pmd;
28445+ pxds[i] = pxd;
28446 }
28447
28448 if (failed) {
28449- free_pmds(pmds);
28450+ free_pxds(pxds);
28451 return -ENOMEM;
28452 }
28453
28454@@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
28455 * preallocate which never got a corresponding vma will need to be
28456 * freed manually.
28457 */
28458-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
28459+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
28460 {
28461 int i;
28462
28463- for(i = 0; i < PREALLOCATED_PMDS; i++) {
28464+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
28465 pgd_t pgd = pgdp[i];
28466
28467 if (pgd_val(pgd) != 0) {
28468- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
28469+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
28470
28471- pgdp[i] = native_make_pgd(0);
28472+ set_pgd(pgdp + i, native_make_pgd(0));
28473
28474- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
28475- pmd_free(mm, pmd);
28476+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
28477+ pxd_free(mm, pxd);
28478 }
28479 }
28480 }
28481
28482-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
28483+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
28484 {
28485- pud_t *pud;
28486+ pyd_t *pyd;
28487 unsigned long addr;
28488 int i;
28489
28490- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
28491+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
28492 return;
28493
28494- pud = pud_offset(pgd, 0);
28495+#ifdef CONFIG_X86_64
28496+ pyd = pyd_offset(mm, 0L);
28497+#else
28498+ pyd = pyd_offset(pgd, 0L);
28499+#endif
28500
28501- for (addr = i = 0; i < PREALLOCATED_PMDS;
28502- i++, pud++, addr += PUD_SIZE) {
28503- pmd_t *pmd = pmds[i];
28504+ for (addr = i = 0; i < PREALLOCATED_PXDS;
28505+ i++, pyd++, addr += PYD_SIZE) {
28506+ pxd_t *pxd = pxds[i];
28507
28508 if (i >= KERNEL_PGD_BOUNDARY)
28509- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
28510- sizeof(pmd_t) * PTRS_PER_PMD);
28511+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
28512+ sizeof(pxd_t) * PTRS_PER_PMD);
28513
28514- pud_populate(mm, pud, pmd);
28515+ pyd_populate(mm, pyd, pxd);
28516 }
28517 }
28518
28519 pgd_t *pgd_alloc(struct mm_struct *mm)
28520 {
28521 pgd_t *pgd;
28522- pmd_t *pmds[PREALLOCATED_PMDS];
28523+ pxd_t *pxds[PREALLOCATED_PXDS];
28524
28525 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
28526
28527@@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
28528
28529 mm->pgd = pgd;
28530
28531- if (preallocate_pmds(pmds) != 0)
28532+ if (preallocate_pxds(pxds) != 0)
28533 goto out_free_pgd;
28534
28535 if (paravirt_pgd_alloc(mm) != 0)
28536- goto out_free_pmds;
28537+ goto out_free_pxds;
28538
28539 /*
28540 * Make sure that pre-populating the pmds is atomic with
28541@@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
28542 spin_lock(&pgd_lock);
28543
28544 pgd_ctor(mm, pgd);
28545- pgd_prepopulate_pmd(mm, pgd, pmds);
28546+ pgd_prepopulate_pxd(mm, pgd, pxds);
28547
28548 spin_unlock(&pgd_lock);
28549
28550 return pgd;
28551
28552-out_free_pmds:
28553- free_pmds(pmds);
28554+out_free_pxds:
28555+ free_pxds(pxds);
28556 out_free_pgd:
28557 free_page((unsigned long)pgd);
28558 out:
28559@@ -295,7 +356,7 @@ out:
28560
28561 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
28562 {
28563- pgd_mop_up_pmds(mm, pgd);
28564+ pgd_mop_up_pxds(mm, pgd);
28565 pgd_dtor(pgd);
28566 paravirt_pgd_free(mm, pgd);
28567 free_page((unsigned long)pgd);
28568diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
28569index a69bcb8..19068ab 100644
28570--- a/arch/x86/mm/pgtable_32.c
28571+++ b/arch/x86/mm/pgtable_32.c
28572@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
28573 return;
28574 }
28575 pte = pte_offset_kernel(pmd, vaddr);
28576+
28577+ pax_open_kernel();
28578 if (pte_val(pteval))
28579 set_pte_at(&init_mm, vaddr, pte, pteval);
28580 else
28581 pte_clear(&init_mm, vaddr, pte);
28582+ pax_close_kernel();
28583
28584 /*
28585 * It's enough to flush this one mapping.
28586diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
28587index 410531d..0f16030 100644
28588--- a/arch/x86/mm/setup_nx.c
28589+++ b/arch/x86/mm/setup_nx.c
28590@@ -5,8 +5,10 @@
28591 #include <asm/pgtable.h>
28592 #include <asm/proto.h>
28593
28594+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
28595 static int disable_nx __cpuinitdata;
28596
28597+#ifndef CONFIG_PAX_PAGEEXEC
28598 /*
28599 * noexec = on|off
28600 *
28601@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
28602 return 0;
28603 }
28604 early_param("noexec", noexec_setup);
28605+#endif
28606+
28607+#endif
28608
28609 void __cpuinit x86_configure_nx(void)
28610 {
28611+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
28612 if (cpu_has_nx && !disable_nx)
28613 __supported_pte_mask |= _PAGE_NX;
28614 else
28615+#endif
28616 __supported_pte_mask &= ~_PAGE_NX;
28617 }
28618
28619diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
28620index 13a6b29..c2fff23 100644
28621--- a/arch/x86/mm/tlb.c
28622+++ b/arch/x86/mm/tlb.c
28623@@ -48,7 +48,11 @@ void leave_mm(int cpu)
28624 BUG();
28625 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
28626 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
28627+
28628+#ifndef CONFIG_PAX_PER_CPU_PGD
28629 load_cr3(swapper_pg_dir);
28630+#endif
28631+
28632 }
28633 }
28634 EXPORT_SYMBOL_GPL(leave_mm);
28635diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
28636index 877b9a1..a8ecf42 100644
28637--- a/arch/x86/net/bpf_jit.S
28638+++ b/arch/x86/net/bpf_jit.S
28639@@ -9,6 +9,7 @@
28640 */
28641 #include <linux/linkage.h>
28642 #include <asm/dwarf2.h>
28643+#include <asm/alternative-asm.h>
28644
28645 /*
28646 * Calling convention :
28647@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
28648 jle bpf_slow_path_word
28649 mov (SKBDATA,%rsi),%eax
28650 bswap %eax /* ntohl() */
28651+ pax_force_retaddr
28652 ret
28653
28654 sk_load_half:
28655@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
28656 jle bpf_slow_path_half
28657 movzwl (SKBDATA,%rsi),%eax
28658 rol $8,%ax # ntohs()
28659+ pax_force_retaddr
28660 ret
28661
28662 sk_load_byte:
28663@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
28664 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
28665 jle bpf_slow_path_byte
28666 movzbl (SKBDATA,%rsi),%eax
28667+ pax_force_retaddr
28668 ret
28669
28670 /**
28671@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
28672 movzbl (SKBDATA,%rsi),%ebx
28673 and $15,%bl
28674 shl $2,%bl
28675+ pax_force_retaddr
28676 ret
28677
28678 /* rsi contains offset and can be scratched */
28679@@ -109,6 +114,7 @@ bpf_slow_path_word:
28680 js bpf_error
28681 mov -12(%rbp),%eax
28682 bswap %eax
28683+ pax_force_retaddr
28684 ret
28685
28686 bpf_slow_path_half:
28687@@ -117,12 +123,14 @@ bpf_slow_path_half:
28688 mov -12(%rbp),%ax
28689 rol $8,%ax
28690 movzwl %ax,%eax
28691+ pax_force_retaddr
28692 ret
28693
28694 bpf_slow_path_byte:
28695 bpf_slow_path_common(1)
28696 js bpf_error
28697 movzbl -12(%rbp),%eax
28698+ pax_force_retaddr
28699 ret
28700
28701 bpf_slow_path_byte_msh:
28702@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
28703 and $15,%al
28704 shl $2,%al
28705 xchg %eax,%ebx
28706+ pax_force_retaddr
28707 ret
28708
28709 #define sk_negative_common(SIZE) \
28710@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
28711 sk_negative_common(4)
28712 mov (%rax), %eax
28713 bswap %eax
28714+ pax_force_retaddr
28715 ret
28716
28717 bpf_slow_path_half_neg:
28718@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
28719 mov (%rax),%ax
28720 rol $8,%ax
28721 movzwl %ax,%eax
28722+ pax_force_retaddr
28723 ret
28724
28725 bpf_slow_path_byte_neg:
28726@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
28727 .globl sk_load_byte_negative_offset
28728 sk_negative_common(1)
28729 movzbl (%rax), %eax
28730+ pax_force_retaddr
28731 ret
28732
28733 bpf_slow_path_byte_msh_neg:
28734@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
28735 and $15,%al
28736 shl $2,%al
28737 xchg %eax,%ebx
28738+ pax_force_retaddr
28739 ret
28740
28741 bpf_error:
28742@@ -197,4 +210,5 @@ bpf_error:
28743 xor %eax,%eax
28744 mov -8(%rbp),%rbx
28745 leaveq
28746+ pax_force_retaddr
28747 ret
28748diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
28749index d11a470..3f9adff3 100644
28750--- a/arch/x86/net/bpf_jit_comp.c
28751+++ b/arch/x86/net/bpf_jit_comp.c
28752@@ -12,6 +12,7 @@
28753 #include <linux/netdevice.h>
28754 #include <linux/filter.h>
28755 #include <linux/if_vlan.h>
28756+#include <linux/random.h>
28757
28758 /*
28759 * Conventions :
28760@@ -49,13 +50,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
28761 return ptr + len;
28762 }
28763
28764+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28765+#define MAX_INSTR_CODE_SIZE 96
28766+#else
28767+#define MAX_INSTR_CODE_SIZE 64
28768+#endif
28769+
28770 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
28771
28772 #define EMIT1(b1) EMIT(b1, 1)
28773 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
28774 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
28775 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
28776+
28777+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28778+/* original constant will appear in ecx */
28779+#define DILUTE_CONST_SEQUENCE(_off, _key) \
28780+do { \
28781+ /* mov ecx, randkey */ \
28782+ EMIT1(0xb9); \
28783+ EMIT(_key, 4); \
28784+ /* xor ecx, randkey ^ off */ \
28785+ EMIT2(0x81, 0xf1); \
28786+ EMIT((_key) ^ (_off), 4); \
28787+} while (0)
28788+
28789+#define EMIT1_off32(b1, _off) \
28790+do { \
28791+ switch (b1) { \
28792+ case 0x05: /* add eax, imm32 */ \
28793+ case 0x2d: /* sub eax, imm32 */ \
28794+ case 0x25: /* and eax, imm32 */ \
28795+ case 0x0d: /* or eax, imm32 */ \
28796+ case 0xb8: /* mov eax, imm32 */ \
28797+ case 0x3d: /* cmp eax, imm32 */ \
28798+ case 0xa9: /* test eax, imm32 */ \
28799+ DILUTE_CONST_SEQUENCE(_off, randkey); \
28800+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
28801+ break; \
28802+ case 0xbb: /* mov ebx, imm32 */ \
28803+ DILUTE_CONST_SEQUENCE(_off, randkey); \
28804+ /* mov ebx, ecx */ \
28805+ EMIT2(0x89, 0xcb); \
28806+ break; \
28807+ case 0xbe: /* mov esi, imm32 */ \
28808+ DILUTE_CONST_SEQUENCE(_off, randkey); \
28809+ /* mov esi, ecx */ \
28810+ EMIT2(0x89, 0xce); \
28811+ break; \
28812+ case 0xe9: /* jmp rel imm32 */ \
28813+ EMIT1(b1); \
28814+ EMIT(_off, 4); \
28815+ /* prevent fall-through, we're not called if off = 0 */ \
28816+ EMIT(0xcccccccc, 4); \
28817+ EMIT(0xcccccccc, 4); \
28818+ break; \
28819+ default: \
28820+ EMIT1(b1); \
28821+ EMIT(_off, 4); \
28822+ } \
28823+} while (0)
28824+
28825+#define EMIT2_off32(b1, b2, _off) \
28826+do { \
28827+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
28828+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
28829+ EMIT(randkey, 4); \
28830+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
28831+ EMIT((_off) - randkey, 4); \
28832+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
28833+ DILUTE_CONST_SEQUENCE(_off, randkey); \
28834+ /* imul eax, ecx */ \
28835+ EMIT3(0x0f, 0xaf, 0xc1); \
28836+ } else { \
28837+ EMIT2(b1, b2); \
28838+ EMIT(_off, 4); \
28839+ } \
28840+} while (0)
28841+#else
28842 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
28843+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
28844+#endif
28845
28846 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
28847 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
28848@@ -90,6 +165,24 @@ do { \
28849 #define X86_JBE 0x76
28850 #define X86_JA 0x77
28851
28852+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28853+#define APPEND_FLOW_VERIFY() \
28854+do { \
28855+ /* mov ecx, randkey */ \
28856+ EMIT1(0xb9); \
28857+ EMIT(randkey, 4); \
28858+ /* cmp ecx, randkey */ \
28859+ EMIT2(0x81, 0xf9); \
28860+ EMIT(randkey, 4); \
28861+ /* jz after 8 int 3s */ \
28862+ EMIT2(0x74, 0x08); \
28863+ EMIT(0xcccccccc, 4); \
28864+ EMIT(0xcccccccc, 4); \
28865+} while (0)
28866+#else
28867+#define APPEND_FLOW_VERIFY() do { } while (0)
28868+#endif
28869+
28870 #define EMIT_COND_JMP(op, offset) \
28871 do { \
28872 if (is_near(offset)) \
28873@@ -97,6 +190,7 @@ do { \
28874 else { \
28875 EMIT2(0x0f, op + 0x10); \
28876 EMIT(offset, 4); /* jxx .+off32 */ \
28877+ APPEND_FLOW_VERIFY(); \
28878 } \
28879 } while (0)
28880
28881@@ -121,12 +215,17 @@ static inline void bpf_flush_icache(void *start, void *end)
28882 set_fs(old_fs);
28883 }
28884
28885+struct bpf_jit_work {
28886+ struct work_struct work;
28887+ void *image;
28888+};
28889+
28890 #define CHOOSE_LOAD_FUNC(K, func) \
28891 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
28892
28893 void bpf_jit_compile(struct sk_filter *fp)
28894 {
28895- u8 temp[64];
28896+ u8 temp[MAX_INSTR_CODE_SIZE];
28897 u8 *prog;
28898 unsigned int proglen, oldproglen = 0;
28899 int ilen, i;
28900@@ -139,6 +238,9 @@ void bpf_jit_compile(struct sk_filter *fp)
28901 unsigned int *addrs;
28902 const struct sock_filter *filter = fp->insns;
28903 int flen = fp->len;
28904+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28905+ unsigned int randkey;
28906+#endif
28907
28908 if (!bpf_jit_enable)
28909 return;
28910@@ -147,11 +249,19 @@ void bpf_jit_compile(struct sk_filter *fp)
28911 if (addrs == NULL)
28912 return;
28913
28914+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
28915+ if (!fp->work)
28916+ goto out;
28917+
28918+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28919+ randkey = get_random_int();
28920+#endif
28921+
28922 /* Before first pass, make a rough estimation of addrs[]
28923- * each bpf instruction is translated to less than 64 bytes
28924+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
28925 */
28926 for (proglen = 0, i = 0; i < flen; i++) {
28927- proglen += 64;
28928+ proglen += MAX_INSTR_CODE_SIZE;
28929 addrs[i] = proglen;
28930 }
28931 cleanup_addr = proglen; /* epilogue address */
28932@@ -261,10 +371,8 @@ void bpf_jit_compile(struct sk_filter *fp)
28933 case BPF_S_ALU_MUL_K: /* A *= K */
28934 if (is_imm8(K))
28935 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
28936- else {
28937- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
28938- EMIT(K, 4);
28939- }
28940+ else
28941+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
28942 break;
28943 case BPF_S_ALU_DIV_X: /* A /= X; */
28944 seen |= SEEN_XREG;
28945@@ -304,13 +412,23 @@ void bpf_jit_compile(struct sk_filter *fp)
28946 break;
28947 case BPF_S_ALU_MOD_K: /* A %= K; */
28948 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
28949+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28950+ DILUTE_CONST_SEQUENCE(K, randkey);
28951+#else
28952 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
28953+#endif
28954 EMIT2(0xf7, 0xf1); /* div %ecx */
28955 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
28956 break;
28957 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
28958+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28959+ DILUTE_CONST_SEQUENCE(K, randkey);
28960+ // imul rax, rcx
28961+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
28962+#else
28963 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
28964 EMIT(K, 4);
28965+#endif
28966 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
28967 break;
28968 case BPF_S_ALU_AND_X:
28969@@ -564,8 +682,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
28970 if (is_imm8(K)) {
28971 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
28972 } else {
28973- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
28974- EMIT(K, 4);
28975+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
28976 }
28977 } else {
28978 EMIT2(0x89,0xde); /* mov %ebx,%esi */
28979@@ -648,17 +765,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
28980 break;
28981 default:
28982 /* hmm, too complex filter, give up with jit compiler */
28983- goto out;
28984+ goto error;
28985 }
28986 ilen = prog - temp;
28987 if (image) {
28988 if (unlikely(proglen + ilen > oldproglen)) {
28989 pr_err("bpb_jit_compile fatal error\n");
28990- kfree(addrs);
28991- module_free(NULL, image);
28992- return;
28993+ module_free_exec(NULL, image);
28994+ goto error;
28995 }
28996+ pax_open_kernel();
28997 memcpy(image + proglen, temp, ilen);
28998+ pax_close_kernel();
28999 }
29000 proglen += ilen;
29001 addrs[i] = proglen;
29002@@ -679,11 +797,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29003 break;
29004 }
29005 if (proglen == oldproglen) {
29006- image = module_alloc(max_t(unsigned int,
29007- proglen,
29008- sizeof(struct work_struct)));
29009+ image = module_alloc_exec(proglen);
29010 if (!image)
29011- goto out;
29012+ goto error;
29013 }
29014 oldproglen = proglen;
29015 }
29016@@ -699,7 +815,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29017 bpf_flush_icache(image, image + proglen);
29018
29019 fp->bpf_func = (void *)image;
29020- }
29021+ } else
29022+error:
29023+ kfree(fp->work);
29024+
29025 out:
29026 kfree(addrs);
29027 return;
29028@@ -707,18 +826,20 @@ out:
29029
29030 static void jit_free_defer(struct work_struct *arg)
29031 {
29032- module_free(NULL, arg);
29033+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
29034+ kfree(arg);
29035 }
29036
29037 /* run from softirq, we must use a work_struct to call
29038- * module_free() from process context
29039+ * module_free_exec() from process context
29040 */
29041 void bpf_jit_free(struct sk_filter *fp)
29042 {
29043 if (fp->bpf_func != sk_run_filter) {
29044- struct work_struct *work = (struct work_struct *)fp->bpf_func;
29045+ struct work_struct *work = &fp->work->work;
29046
29047 INIT_WORK(work, jit_free_defer);
29048+ fp->work->image = fp->bpf_func;
29049 schedule_work(work);
29050 }
29051 }
29052diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
29053index d6aa6e8..266395a 100644
29054--- a/arch/x86/oprofile/backtrace.c
29055+++ b/arch/x86/oprofile/backtrace.c
29056@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
29057 struct stack_frame_ia32 *fp;
29058 unsigned long bytes;
29059
29060- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
29061+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
29062 if (bytes != sizeof(bufhead))
29063 return NULL;
29064
29065- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
29066+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
29067
29068 oprofile_add_trace(bufhead[0].return_address);
29069
29070@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
29071 struct stack_frame bufhead[2];
29072 unsigned long bytes;
29073
29074- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
29075+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
29076 if (bytes != sizeof(bufhead))
29077 return NULL;
29078
29079@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
29080 {
29081 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
29082
29083- if (!user_mode_vm(regs)) {
29084+ if (!user_mode(regs)) {
29085 unsigned long stack = kernel_stack_pointer(regs);
29086 if (depth)
29087 dump_trace(NULL, regs, (unsigned long *)stack, 0,
29088diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c
29089index e9e6ed5..e47ae67 100644
29090--- a/arch/x86/pci/amd_bus.c
29091+++ b/arch/x86/pci/amd_bus.c
29092@@ -337,7 +337,7 @@ static int __cpuinit amd_cpu_notify(struct notifier_block *self,
29093 return NOTIFY_OK;
29094 }
29095
29096-static struct notifier_block __cpuinitdata amd_cpu_notifier = {
29097+static struct notifier_block amd_cpu_notifier = {
29098 .notifier_call = amd_cpu_notify,
29099 };
29100
29101diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
29102index 6eb18c4..20d83de 100644
29103--- a/arch/x86/pci/mrst.c
29104+++ b/arch/x86/pci/mrst.c
29105@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
29106 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
29107 pci_mmcfg_late_init();
29108 pcibios_enable_irq = mrst_pci_irq_enable;
29109- pci_root_ops = pci_mrst_ops;
29110+ pax_open_kernel();
29111+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
29112+ pax_close_kernel();
29113 pci_soc_mode = 1;
29114 /* Continue with standard init */
29115 return 1;
29116diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
29117index c77b24a..c979855 100644
29118--- a/arch/x86/pci/pcbios.c
29119+++ b/arch/x86/pci/pcbios.c
29120@@ -79,7 +79,7 @@ union bios32 {
29121 static struct {
29122 unsigned long address;
29123 unsigned short segment;
29124-} bios32_indirect = { 0, __KERNEL_CS };
29125+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
29126
29127 /*
29128 * Returns the entry point for the given service, NULL on error
29129@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
29130 unsigned long length; /* %ecx */
29131 unsigned long entry; /* %edx */
29132 unsigned long flags;
29133+ struct desc_struct d, *gdt;
29134
29135 local_irq_save(flags);
29136- __asm__("lcall *(%%edi); cld"
29137+
29138+ gdt = get_cpu_gdt_table(smp_processor_id());
29139+
29140+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
29141+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
29142+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
29143+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
29144+
29145+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
29146 : "=a" (return_code),
29147 "=b" (address),
29148 "=c" (length),
29149 "=d" (entry)
29150 : "0" (service),
29151 "1" (0),
29152- "D" (&bios32_indirect));
29153+ "D" (&bios32_indirect),
29154+ "r"(__PCIBIOS_DS)
29155+ : "memory");
29156+
29157+ pax_open_kernel();
29158+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
29159+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
29160+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
29161+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
29162+ pax_close_kernel();
29163+
29164 local_irq_restore(flags);
29165
29166 switch (return_code) {
29167- case 0:
29168- return address + entry;
29169- case 0x80: /* Not present */
29170- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
29171- return 0;
29172- default: /* Shouldn't happen */
29173- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
29174- service, return_code);
29175+ case 0: {
29176+ int cpu;
29177+ unsigned char flags;
29178+
29179+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
29180+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
29181+ printk(KERN_WARNING "bios32_service: not valid\n");
29182 return 0;
29183+ }
29184+ address = address + PAGE_OFFSET;
29185+ length += 16UL; /* some BIOSs underreport this... */
29186+ flags = 4;
29187+ if (length >= 64*1024*1024) {
29188+ length >>= PAGE_SHIFT;
29189+ flags |= 8;
29190+ }
29191+
29192+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
29193+ gdt = get_cpu_gdt_table(cpu);
29194+ pack_descriptor(&d, address, length, 0x9b, flags);
29195+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
29196+ pack_descriptor(&d, address, length, 0x93, flags);
29197+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
29198+ }
29199+ return entry;
29200+ }
29201+ case 0x80: /* Not present */
29202+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
29203+ return 0;
29204+ default: /* Shouldn't happen */
29205+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
29206+ service, return_code);
29207+ return 0;
29208 }
29209 }
29210
29211 static struct {
29212 unsigned long address;
29213 unsigned short segment;
29214-} pci_indirect = { 0, __KERNEL_CS };
29215+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
29216
29217-static int pci_bios_present;
29218+static int pci_bios_present __read_only;
29219
29220 static int check_pcibios(void)
29221 {
29222@@ -131,11 +174,13 @@ static int check_pcibios(void)
29223 unsigned long flags, pcibios_entry;
29224
29225 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
29226- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
29227+ pci_indirect.address = pcibios_entry;
29228
29229 local_irq_save(flags);
29230- __asm__(
29231- "lcall *(%%edi); cld\n\t"
29232+ __asm__("movw %w6, %%ds\n\t"
29233+ "lcall *%%ss:(%%edi); cld\n\t"
29234+ "push %%ss\n\t"
29235+ "pop %%ds\n\t"
29236 "jc 1f\n\t"
29237 "xor %%ah, %%ah\n"
29238 "1:"
29239@@ -144,7 +189,8 @@ static int check_pcibios(void)
29240 "=b" (ebx),
29241 "=c" (ecx)
29242 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
29243- "D" (&pci_indirect)
29244+ "D" (&pci_indirect),
29245+ "r" (__PCIBIOS_DS)
29246 : "memory");
29247 local_irq_restore(flags);
29248
29249@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29250
29251 switch (len) {
29252 case 1:
29253- __asm__("lcall *(%%esi); cld\n\t"
29254+ __asm__("movw %w6, %%ds\n\t"
29255+ "lcall *%%ss:(%%esi); cld\n\t"
29256+ "push %%ss\n\t"
29257+ "pop %%ds\n\t"
29258 "jc 1f\n\t"
29259 "xor %%ah, %%ah\n"
29260 "1:"
29261@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29262 : "1" (PCIBIOS_READ_CONFIG_BYTE),
29263 "b" (bx),
29264 "D" ((long)reg),
29265- "S" (&pci_indirect));
29266+ "S" (&pci_indirect),
29267+ "r" (__PCIBIOS_DS));
29268 /*
29269 * Zero-extend the result beyond 8 bits, do not trust the
29270 * BIOS having done it:
29271@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29272 *value &= 0xff;
29273 break;
29274 case 2:
29275- __asm__("lcall *(%%esi); cld\n\t"
29276+ __asm__("movw %w6, %%ds\n\t"
29277+ "lcall *%%ss:(%%esi); cld\n\t"
29278+ "push %%ss\n\t"
29279+ "pop %%ds\n\t"
29280 "jc 1f\n\t"
29281 "xor %%ah, %%ah\n"
29282 "1:"
29283@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29284 : "1" (PCIBIOS_READ_CONFIG_WORD),
29285 "b" (bx),
29286 "D" ((long)reg),
29287- "S" (&pci_indirect));
29288+ "S" (&pci_indirect),
29289+ "r" (__PCIBIOS_DS));
29290 /*
29291 * Zero-extend the result beyond 16 bits, do not trust the
29292 * BIOS having done it:
29293@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29294 *value &= 0xffff;
29295 break;
29296 case 4:
29297- __asm__("lcall *(%%esi); cld\n\t"
29298+ __asm__("movw %w6, %%ds\n\t"
29299+ "lcall *%%ss:(%%esi); cld\n\t"
29300+ "push %%ss\n\t"
29301+ "pop %%ds\n\t"
29302 "jc 1f\n\t"
29303 "xor %%ah, %%ah\n"
29304 "1:"
29305@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29306 : "1" (PCIBIOS_READ_CONFIG_DWORD),
29307 "b" (bx),
29308 "D" ((long)reg),
29309- "S" (&pci_indirect));
29310+ "S" (&pci_indirect),
29311+ "r" (__PCIBIOS_DS));
29312 break;
29313 }
29314
29315@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29316
29317 switch (len) {
29318 case 1:
29319- __asm__("lcall *(%%esi); cld\n\t"
29320+ __asm__("movw %w6, %%ds\n\t"
29321+ "lcall *%%ss:(%%esi); cld\n\t"
29322+ "push %%ss\n\t"
29323+ "pop %%ds\n\t"
29324 "jc 1f\n\t"
29325 "xor %%ah, %%ah\n"
29326 "1:"
29327@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29328 "c" (value),
29329 "b" (bx),
29330 "D" ((long)reg),
29331- "S" (&pci_indirect));
29332+ "S" (&pci_indirect),
29333+ "r" (__PCIBIOS_DS));
29334 break;
29335 case 2:
29336- __asm__("lcall *(%%esi); cld\n\t"
29337+ __asm__("movw %w6, %%ds\n\t"
29338+ "lcall *%%ss:(%%esi); cld\n\t"
29339+ "push %%ss\n\t"
29340+ "pop %%ds\n\t"
29341 "jc 1f\n\t"
29342 "xor %%ah, %%ah\n"
29343 "1:"
29344@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29345 "c" (value),
29346 "b" (bx),
29347 "D" ((long)reg),
29348- "S" (&pci_indirect));
29349+ "S" (&pci_indirect),
29350+ "r" (__PCIBIOS_DS));
29351 break;
29352 case 4:
29353- __asm__("lcall *(%%esi); cld\n\t"
29354+ __asm__("movw %w6, %%ds\n\t"
29355+ "lcall *%%ss:(%%esi); cld\n\t"
29356+ "push %%ss\n\t"
29357+ "pop %%ds\n\t"
29358 "jc 1f\n\t"
29359 "xor %%ah, %%ah\n"
29360 "1:"
29361@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29362 "c" (value),
29363 "b" (bx),
29364 "D" ((long)reg),
29365- "S" (&pci_indirect));
29366+ "S" (&pci_indirect),
29367+ "r" (__PCIBIOS_DS));
29368 break;
29369 }
29370
29371@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
29372
29373 DBG("PCI: Fetching IRQ routing table... ");
29374 __asm__("push %%es\n\t"
29375+ "movw %w8, %%ds\n\t"
29376 "push %%ds\n\t"
29377 "pop %%es\n\t"
29378- "lcall *(%%esi); cld\n\t"
29379+ "lcall *%%ss:(%%esi); cld\n\t"
29380 "pop %%es\n\t"
29381+ "push %%ss\n\t"
29382+ "pop %%ds\n"
29383 "jc 1f\n\t"
29384 "xor %%ah, %%ah\n"
29385 "1:"
29386@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
29387 "1" (0),
29388 "D" ((long) &opt),
29389 "S" (&pci_indirect),
29390- "m" (opt)
29391+ "m" (opt),
29392+ "r" (__PCIBIOS_DS)
29393 : "memory");
29394 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
29395 if (ret & 0xff00)
29396@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
29397 {
29398 int ret;
29399
29400- __asm__("lcall *(%%esi); cld\n\t"
29401+ __asm__("movw %w5, %%ds\n\t"
29402+ "lcall *%%ss:(%%esi); cld\n\t"
29403+ "push %%ss\n\t"
29404+ "pop %%ds\n"
29405 "jc 1f\n\t"
29406 "xor %%ah, %%ah\n"
29407 "1:"
29408@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
29409 : "0" (PCIBIOS_SET_PCI_HW_INT),
29410 "b" ((dev->bus->number << 8) | dev->devfn),
29411 "c" ((irq << 8) | (pin + 10)),
29412- "S" (&pci_indirect));
29413+ "S" (&pci_indirect),
29414+ "r" (__PCIBIOS_DS));
29415 return !(ret & 0xff00);
29416 }
29417 EXPORT_SYMBOL(pcibios_set_irq_routing);
29418diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
29419index 40e4469..1ab536e 100644
29420--- a/arch/x86/platform/efi/efi_32.c
29421+++ b/arch/x86/platform/efi/efi_32.c
29422@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
29423 {
29424 struct desc_ptr gdt_descr;
29425
29426+#ifdef CONFIG_PAX_KERNEXEC
29427+ struct desc_struct d;
29428+#endif
29429+
29430 local_irq_save(efi_rt_eflags);
29431
29432 load_cr3(initial_page_table);
29433 __flush_tlb_all();
29434
29435+#ifdef CONFIG_PAX_KERNEXEC
29436+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
29437+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
29438+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
29439+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
29440+#endif
29441+
29442 gdt_descr.address = __pa(get_cpu_gdt_table(0));
29443 gdt_descr.size = GDT_SIZE - 1;
29444 load_gdt(&gdt_descr);
29445@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
29446 {
29447 struct desc_ptr gdt_descr;
29448
29449+#ifdef CONFIG_PAX_KERNEXEC
29450+ struct desc_struct d;
29451+
29452+ memset(&d, 0, sizeof d);
29453+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
29454+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
29455+#endif
29456+
29457 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
29458 gdt_descr.size = GDT_SIZE - 1;
29459 load_gdt(&gdt_descr);
29460diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
29461index fbe66e6..eae5e38 100644
29462--- a/arch/x86/platform/efi/efi_stub_32.S
29463+++ b/arch/x86/platform/efi/efi_stub_32.S
29464@@ -6,7 +6,9 @@
29465 */
29466
29467 #include <linux/linkage.h>
29468+#include <linux/init.h>
29469 #include <asm/page_types.h>
29470+#include <asm/segment.h>
29471
29472 /*
29473 * efi_call_phys(void *, ...) is a function with variable parameters.
29474@@ -20,7 +22,7 @@
29475 * service functions will comply with gcc calling convention, too.
29476 */
29477
29478-.text
29479+__INIT
29480 ENTRY(efi_call_phys)
29481 /*
29482 * 0. The function can only be called in Linux kernel. So CS has been
29483@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
29484 * The mapping of lower virtual memory has been created in prelog and
29485 * epilog.
29486 */
29487- movl $1f, %edx
29488- subl $__PAGE_OFFSET, %edx
29489- jmp *%edx
29490+#ifdef CONFIG_PAX_KERNEXEC
29491+ movl $(__KERNEXEC_EFI_DS), %edx
29492+ mov %edx, %ds
29493+ mov %edx, %es
29494+ mov %edx, %ss
29495+ addl $2f,(1f)
29496+ ljmp *(1f)
29497+
29498+__INITDATA
29499+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
29500+.previous
29501+
29502+2:
29503+ subl $2b,(1b)
29504+#else
29505+ jmp 1f-__PAGE_OFFSET
29506 1:
29507+#endif
29508
29509 /*
29510 * 2. Now on the top of stack is the return
29511@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
29512 * parameter 2, ..., param n. To make things easy, we save the return
29513 * address of efi_call_phys in a global variable.
29514 */
29515- popl %edx
29516- movl %edx, saved_return_addr
29517- /* get the function pointer into ECX*/
29518- popl %ecx
29519- movl %ecx, efi_rt_function_ptr
29520- movl $2f, %edx
29521- subl $__PAGE_OFFSET, %edx
29522- pushl %edx
29523+ popl (saved_return_addr)
29524+ popl (efi_rt_function_ptr)
29525
29526 /*
29527 * 3. Clear PG bit in %CR0.
29528@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
29529 /*
29530 * 5. Call the physical function.
29531 */
29532- jmp *%ecx
29533+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
29534
29535-2:
29536 /*
29537 * 6. After EFI runtime service returns, control will return to
29538 * following instruction. We'd better readjust stack pointer first.
29539@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
29540 movl %cr0, %edx
29541 orl $0x80000000, %edx
29542 movl %edx, %cr0
29543- jmp 1f
29544-1:
29545+
29546 /*
29547 * 8. Now restore the virtual mode from flat mode by
29548 * adding EIP with PAGE_OFFSET.
29549 */
29550- movl $1f, %edx
29551- jmp *%edx
29552+#ifdef CONFIG_PAX_KERNEXEC
29553+ movl $(__KERNEL_DS), %edx
29554+ mov %edx, %ds
29555+ mov %edx, %es
29556+ mov %edx, %ss
29557+ ljmp $(__KERNEL_CS),$1f
29558+#else
29559+ jmp 1f+__PAGE_OFFSET
29560+#endif
29561 1:
29562
29563 /*
29564 * 9. Balance the stack. And because EAX contain the return value,
29565 * we'd better not clobber it.
29566 */
29567- leal efi_rt_function_ptr, %edx
29568- movl (%edx), %ecx
29569- pushl %ecx
29570+ pushl (efi_rt_function_ptr)
29571
29572 /*
29573- * 10. Push the saved return address onto the stack and return.
29574+ * 10. Return to the saved return address.
29575 */
29576- leal saved_return_addr, %edx
29577- movl (%edx), %ecx
29578- pushl %ecx
29579- ret
29580+ jmpl *(saved_return_addr)
29581 ENDPROC(efi_call_phys)
29582 .previous
29583
29584-.data
29585+__INITDATA
29586 saved_return_addr:
29587 .long 0
29588 efi_rt_function_ptr:
29589diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
29590index 4c07cca..2c8427d 100644
29591--- a/arch/x86/platform/efi/efi_stub_64.S
29592+++ b/arch/x86/platform/efi/efi_stub_64.S
29593@@ -7,6 +7,7 @@
29594 */
29595
29596 #include <linux/linkage.h>
29597+#include <asm/alternative-asm.h>
29598
29599 #define SAVE_XMM \
29600 mov %rsp, %rax; \
29601@@ -40,6 +41,7 @@ ENTRY(efi_call0)
29602 call *%rdi
29603 addq $32, %rsp
29604 RESTORE_XMM
29605+ pax_force_retaddr 0, 1
29606 ret
29607 ENDPROC(efi_call0)
29608
29609@@ -50,6 +52,7 @@ ENTRY(efi_call1)
29610 call *%rdi
29611 addq $32, %rsp
29612 RESTORE_XMM
29613+ pax_force_retaddr 0, 1
29614 ret
29615 ENDPROC(efi_call1)
29616
29617@@ -60,6 +63,7 @@ ENTRY(efi_call2)
29618 call *%rdi
29619 addq $32, %rsp
29620 RESTORE_XMM
29621+ pax_force_retaddr 0, 1
29622 ret
29623 ENDPROC(efi_call2)
29624
29625@@ -71,6 +75,7 @@ ENTRY(efi_call3)
29626 call *%rdi
29627 addq $32, %rsp
29628 RESTORE_XMM
29629+ pax_force_retaddr 0, 1
29630 ret
29631 ENDPROC(efi_call3)
29632
29633@@ -83,6 +88,7 @@ ENTRY(efi_call4)
29634 call *%rdi
29635 addq $32, %rsp
29636 RESTORE_XMM
29637+ pax_force_retaddr 0, 1
29638 ret
29639 ENDPROC(efi_call4)
29640
29641@@ -96,6 +102,7 @@ ENTRY(efi_call5)
29642 call *%rdi
29643 addq $48, %rsp
29644 RESTORE_XMM
29645+ pax_force_retaddr 0, 1
29646 ret
29647 ENDPROC(efi_call5)
29648
29649@@ -112,5 +119,6 @@ ENTRY(efi_call6)
29650 call *%rdi
29651 addq $48, %rsp
29652 RESTORE_XMM
29653+ pax_force_retaddr 0, 1
29654 ret
29655 ENDPROC(efi_call6)
29656diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
29657index e31bcd8..f12dc46 100644
29658--- a/arch/x86/platform/mrst/mrst.c
29659+++ b/arch/x86/platform/mrst/mrst.c
29660@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
29661 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
29662 int sfi_mrtc_num;
29663
29664-static void mrst_power_off(void)
29665+static __noreturn void mrst_power_off(void)
29666 {
29667+ BUG();
29668 }
29669
29670-static void mrst_reboot(void)
29671+static __noreturn void mrst_reboot(void)
29672 {
29673 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
29674+ BUG();
29675 }
29676
29677 /* parse all the mtimer info to a static mtimer array */
29678diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
29679index d6ee929..3637cb5 100644
29680--- a/arch/x86/platform/olpc/olpc_dt.c
29681+++ b/arch/x86/platform/olpc/olpc_dt.c
29682@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
29683 return res;
29684 }
29685
29686-static struct of_pdt_ops prom_olpc_ops __initdata = {
29687+static struct of_pdt_ops prom_olpc_ops __initconst = {
29688 .nextprop = olpc_dt_nextprop,
29689 .getproplen = olpc_dt_getproplen,
29690 .getproperty = olpc_dt_getproperty,
29691diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
29692index 120cee1..b2db75a 100644
29693--- a/arch/x86/power/cpu.c
29694+++ b/arch/x86/power/cpu.c
29695@@ -133,7 +133,7 @@ static void do_fpu_end(void)
29696 static void fix_processor_context(void)
29697 {
29698 int cpu = smp_processor_id();
29699- struct tss_struct *t = &per_cpu(init_tss, cpu);
29700+ struct tss_struct *t = init_tss + cpu;
29701
29702 set_tss_desc(cpu, t); /*
29703 * This just modifies memory; should not be
29704@@ -143,8 +143,6 @@ static void fix_processor_context(void)
29705 */
29706
29707 #ifdef CONFIG_X86_64
29708- get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
29709-
29710 syscall_init(); /* This sets MSR_*STAR and related */
29711 #endif
29712 load_TR_desc(); /* This does ltr */
29713diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
29714index cbca565..bae7133 100644
29715--- a/arch/x86/realmode/init.c
29716+++ b/arch/x86/realmode/init.c
29717@@ -62,7 +62,13 @@ void __init setup_real_mode(void)
29718 __va(real_mode_header->trampoline_header);
29719
29720 #ifdef CONFIG_X86_32
29721- trampoline_header->start = __pa(startup_32_smp);
29722+ trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
29723+
29724+#ifdef CONFIG_PAX_KERNEXEC
29725+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
29726+#endif
29727+
29728+ trampoline_header->boot_cs = __BOOT_CS;
29729 trampoline_header->gdt_limit = __BOOT_DS + 7;
29730 trampoline_header->gdt_base = __pa(boot_gdt);
29731 #else
29732diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
29733index 8869287..d577672 100644
29734--- a/arch/x86/realmode/rm/Makefile
29735+++ b/arch/x86/realmode/rm/Makefile
29736@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
29737 $(call cc-option, -fno-unit-at-a-time)) \
29738 $(call cc-option, -fno-stack-protector) \
29739 $(call cc-option, -mpreferred-stack-boundary=2)
29740+ifdef CONSTIFY_PLUGIN
29741+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
29742+endif
29743 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
29744 GCOV_PROFILE := n
29745diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
29746index a28221d..93c40f1 100644
29747--- a/arch/x86/realmode/rm/header.S
29748+++ b/arch/x86/realmode/rm/header.S
29749@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
29750 #endif
29751 /* APM/BIOS reboot */
29752 .long pa_machine_real_restart_asm
29753-#ifdef CONFIG_X86_64
29754+#ifdef CONFIG_X86_32
29755+ .long __KERNEL_CS
29756+#else
29757 .long __KERNEL32_CS
29758 #endif
29759 END(real_mode_header)
29760diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
29761index c1b2791..f9e31c7 100644
29762--- a/arch/x86/realmode/rm/trampoline_32.S
29763+++ b/arch/x86/realmode/rm/trampoline_32.S
29764@@ -25,6 +25,12 @@
29765 #include <asm/page_types.h>
29766 #include "realmode.h"
29767
29768+#ifdef CONFIG_PAX_KERNEXEC
29769+#define ta(X) (X)
29770+#else
29771+#define ta(X) (pa_ ## X)
29772+#endif
29773+
29774 .text
29775 .code16
29776
29777@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
29778
29779 cli # We should be safe anyway
29780
29781- movl tr_start, %eax # where we need to go
29782-
29783 movl $0xA5A5A5A5, trampoline_status
29784 # write marker for master knows we're running
29785
29786@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
29787 movw $1, %dx # protected mode (PE) bit
29788 lmsw %dx # into protected mode
29789
29790- ljmpl $__BOOT_CS, $pa_startup_32
29791+ ljmpl *(trampoline_header)
29792
29793 .section ".text32","ax"
29794 .code32
29795@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
29796 .balign 8
29797 GLOBAL(trampoline_header)
29798 tr_start: .space 4
29799- tr_gdt_pad: .space 2
29800+ tr_boot_cs: .space 2
29801 tr_gdt: .space 6
29802 END(trampoline_header)
29803
29804diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
29805index bb360dc..3e5945f 100644
29806--- a/arch/x86/realmode/rm/trampoline_64.S
29807+++ b/arch/x86/realmode/rm/trampoline_64.S
29808@@ -107,7 +107,7 @@ ENTRY(startup_32)
29809 wrmsr
29810
29811 # Enable paging and in turn activate Long Mode
29812- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
29813+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
29814 movl %eax, %cr0
29815
29816 /*
29817diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
29818index 79d67bd..c7e1b90 100644
29819--- a/arch/x86/tools/relocs.c
29820+++ b/arch/x86/tools/relocs.c
29821@@ -12,10 +12,13 @@
29822 #include <regex.h>
29823 #include <tools/le_byteshift.h>
29824
29825+#include "../../../include/generated/autoconf.h"
29826+
29827 static void die(char *fmt, ...);
29828
29829 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
29830 static Elf32_Ehdr ehdr;
29831+static Elf32_Phdr *phdr;
29832 static unsigned long reloc_count, reloc_idx;
29833 static unsigned long *relocs;
29834 static unsigned long reloc16_count, reloc16_idx;
29835@@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
29836 }
29837 }
29838
29839+static void read_phdrs(FILE *fp)
29840+{
29841+ unsigned int i;
29842+
29843+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
29844+ if (!phdr) {
29845+ die("Unable to allocate %d program headers\n",
29846+ ehdr.e_phnum);
29847+ }
29848+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
29849+ die("Seek to %d failed: %s\n",
29850+ ehdr.e_phoff, strerror(errno));
29851+ }
29852+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
29853+ die("Cannot read ELF program headers: %s\n",
29854+ strerror(errno));
29855+ }
29856+ for(i = 0; i < ehdr.e_phnum; i++) {
29857+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
29858+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
29859+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
29860+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
29861+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
29862+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
29863+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
29864+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
29865+ }
29866+
29867+}
29868+
29869 static void read_shdrs(FILE *fp)
29870 {
29871- int i;
29872+ unsigned int i;
29873 Elf32_Shdr shdr;
29874
29875 secs = calloc(ehdr.e_shnum, sizeof(struct section));
29876@@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
29877
29878 static void read_strtabs(FILE *fp)
29879 {
29880- int i;
29881+ unsigned int i;
29882 for (i = 0; i < ehdr.e_shnum; i++) {
29883 struct section *sec = &secs[i];
29884 if (sec->shdr.sh_type != SHT_STRTAB) {
29885@@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
29886
29887 static void read_symtabs(FILE *fp)
29888 {
29889- int i,j;
29890+ unsigned int i,j;
29891 for (i = 0; i < ehdr.e_shnum; i++) {
29892 struct section *sec = &secs[i];
29893 if (sec->shdr.sh_type != SHT_SYMTAB) {
29894@@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
29895 }
29896
29897
29898-static void read_relocs(FILE *fp)
29899+static void read_relocs(FILE *fp, int use_real_mode)
29900 {
29901- int i,j;
29902+ unsigned int i,j;
29903+ uint32_t base;
29904+
29905 for (i = 0; i < ehdr.e_shnum; i++) {
29906 struct section *sec = &secs[i];
29907 if (sec->shdr.sh_type != SHT_REL) {
29908@@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
29909 die("Cannot read symbol table: %s\n",
29910 strerror(errno));
29911 }
29912+ base = 0;
29913+
29914+#ifdef CONFIG_X86_32
29915+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
29916+ if (phdr[j].p_type != PT_LOAD )
29917+ continue;
29918+ 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)
29919+ continue;
29920+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
29921+ break;
29922+ }
29923+#endif
29924+
29925 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
29926 Elf32_Rel *rel = &sec->reltab[j];
29927- rel->r_offset = elf32_to_cpu(rel->r_offset);
29928+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
29929 rel->r_info = elf32_to_cpu(rel->r_info);
29930 }
29931 }
29932@@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
29933
29934 static void print_absolute_symbols(void)
29935 {
29936- int i;
29937+ unsigned int i;
29938 printf("Absolute symbols\n");
29939 printf(" Num: Value Size Type Bind Visibility Name\n");
29940 for (i = 0; i < ehdr.e_shnum; i++) {
29941 struct section *sec = &secs[i];
29942 char *sym_strtab;
29943- int j;
29944+ unsigned int j;
29945
29946 if (sec->shdr.sh_type != SHT_SYMTAB) {
29947 continue;
29948@@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
29949
29950 static void print_absolute_relocs(void)
29951 {
29952- int i, printed = 0;
29953+ unsigned int i, printed = 0;
29954
29955 for (i = 0; i < ehdr.e_shnum; i++) {
29956 struct section *sec = &secs[i];
29957 struct section *sec_applies, *sec_symtab;
29958 char *sym_strtab;
29959 Elf32_Sym *sh_symtab;
29960- int j;
29961+ unsigned int j;
29962 if (sec->shdr.sh_type != SHT_REL) {
29963 continue;
29964 }
29965@@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
29966 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
29967 int use_real_mode)
29968 {
29969- int i;
29970+ unsigned int i;
29971 /* Walk through the relocations */
29972 for (i = 0; i < ehdr.e_shnum; i++) {
29973 char *sym_strtab;
29974 Elf32_Sym *sh_symtab;
29975 struct section *sec_applies, *sec_symtab;
29976- int j;
29977+ unsigned int j;
29978 struct section *sec = &secs[i];
29979
29980 if (sec->shdr.sh_type != SHT_REL) {
29981@@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
29982 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
29983 r_type = ELF32_R_TYPE(rel->r_info);
29984
29985+ if (!use_real_mode) {
29986+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
29987+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
29988+ continue;
29989+
29990+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
29991+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
29992+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
29993+ continue;
29994+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
29995+ continue;
29996+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
29997+ continue;
29998+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
29999+ continue;
30000+#endif
30001+ }
30002+
30003 shn_abs = sym->st_shndx == SHN_ABS;
30004
30005 switch (r_type) {
30006@@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
30007
30008 static void emit_relocs(int as_text, int use_real_mode)
30009 {
30010- int i;
30011+ unsigned int i;
30012 /* Count how many relocations I have and allocate space for them. */
30013 reloc_count = 0;
30014 walk_relocs(count_reloc, use_real_mode);
30015@@ -808,10 +874,11 @@ int main(int argc, char **argv)
30016 fname, strerror(errno));
30017 }
30018 read_ehdr(fp);
30019+ read_phdrs(fp);
30020 read_shdrs(fp);
30021 read_strtabs(fp);
30022 read_symtabs(fp);
30023- read_relocs(fp);
30024+ read_relocs(fp, use_real_mode);
30025 if (show_absolute_syms) {
30026 print_absolute_symbols();
30027 goto out;
30028diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
30029index fd14be1..e3c79c0 100644
30030--- a/arch/x86/vdso/Makefile
30031+++ b/arch/x86/vdso/Makefile
30032@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
30033 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
30034 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
30035
30036-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
30037+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
30038 GCOV_PROFILE := n
30039
30040 #
30041diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
30042index 0faad64..39ef157 100644
30043--- a/arch/x86/vdso/vdso32-setup.c
30044+++ b/arch/x86/vdso/vdso32-setup.c
30045@@ -25,6 +25,7 @@
30046 #include <asm/tlbflush.h>
30047 #include <asm/vdso.h>
30048 #include <asm/proto.h>
30049+#include <asm/mman.h>
30050
30051 enum {
30052 VDSO_DISABLED = 0,
30053@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
30054 void enable_sep_cpu(void)
30055 {
30056 int cpu = get_cpu();
30057- struct tss_struct *tss = &per_cpu(init_tss, cpu);
30058+ struct tss_struct *tss = init_tss + cpu;
30059
30060 if (!boot_cpu_has(X86_FEATURE_SEP)) {
30061 put_cpu();
30062@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
30063 gate_vma.vm_start = FIXADDR_USER_START;
30064 gate_vma.vm_end = FIXADDR_USER_END;
30065 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
30066- gate_vma.vm_page_prot = __P101;
30067+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
30068
30069 return 0;
30070 }
30071@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
30072 if (compat)
30073 addr = VDSO_HIGH_BASE;
30074 else {
30075- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
30076+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
30077 if (IS_ERR_VALUE(addr)) {
30078 ret = addr;
30079 goto up_fail;
30080 }
30081 }
30082
30083- current->mm->context.vdso = (void *)addr;
30084+ current->mm->context.vdso = addr;
30085
30086 if (compat_uses_vma || !compat) {
30087 /*
30088@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
30089 }
30090
30091 current_thread_info()->sysenter_return =
30092- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
30093+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
30094
30095 up_fail:
30096 if (ret)
30097- current->mm->context.vdso = NULL;
30098+ current->mm->context.vdso = 0;
30099
30100 up_write(&mm->mmap_sem);
30101
30102@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
30103
30104 const char *arch_vma_name(struct vm_area_struct *vma)
30105 {
30106- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
30107+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
30108 return "[vdso]";
30109+
30110+#ifdef CONFIG_PAX_SEGMEXEC
30111+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
30112+ return "[vdso]";
30113+#endif
30114+
30115 return NULL;
30116 }
30117
30118@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
30119 * Check to see if the corresponding task was created in compat vdso
30120 * mode.
30121 */
30122- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
30123+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
30124 return &gate_vma;
30125 return NULL;
30126 }
30127diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
30128index 431e875..cbb23f3 100644
30129--- a/arch/x86/vdso/vma.c
30130+++ b/arch/x86/vdso/vma.c
30131@@ -16,8 +16,6 @@
30132 #include <asm/vdso.h>
30133 #include <asm/page.h>
30134
30135-unsigned int __read_mostly vdso_enabled = 1;
30136-
30137 extern char vdso_start[], vdso_end[];
30138 extern unsigned short vdso_sync_cpuid;
30139
30140@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
30141 * unaligned here as a result of stack start randomization.
30142 */
30143 addr = PAGE_ALIGN(addr);
30144- addr = align_vdso_addr(addr);
30145
30146 return addr;
30147 }
30148@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
30149 unsigned size)
30150 {
30151 struct mm_struct *mm = current->mm;
30152- unsigned long addr;
30153+ unsigned long addr = 0;
30154 int ret;
30155
30156- if (!vdso_enabled)
30157- return 0;
30158-
30159 down_write(&mm->mmap_sem);
30160+
30161+#ifdef CONFIG_PAX_RANDMMAP
30162+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
30163+#endif
30164+
30165 addr = vdso_addr(mm->start_stack, size);
30166+ addr = align_vdso_addr(addr);
30167 addr = get_unmapped_area(NULL, addr, size, 0, 0);
30168 if (IS_ERR_VALUE(addr)) {
30169 ret = addr;
30170 goto up_fail;
30171 }
30172
30173- current->mm->context.vdso = (void *)addr;
30174+ mm->context.vdso = addr;
30175
30176 ret = install_special_mapping(mm, addr, size,
30177 VM_READ|VM_EXEC|
30178 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
30179 pages);
30180- if (ret) {
30181- current->mm->context.vdso = NULL;
30182- goto up_fail;
30183- }
30184+ if (ret)
30185+ mm->context.vdso = 0;
30186
30187 up_fail:
30188 up_write(&mm->mmap_sem);
30189@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
30190 vdsox32_size);
30191 }
30192 #endif
30193-
30194-static __init int vdso_setup(char *s)
30195-{
30196- vdso_enabled = simple_strtoul(s, NULL, 0);
30197- return 0;
30198-}
30199-__setup("vdso=", vdso_setup);
30200diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
30201index e014092..c76ab69 100644
30202--- a/arch/x86/xen/enlighten.c
30203+++ b/arch/x86/xen/enlighten.c
30204@@ -99,8 +99,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
30205
30206 struct shared_info xen_dummy_shared_info;
30207
30208-void *xen_initial_gdt;
30209-
30210 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
30211 __read_mostly int xen_have_vector_callback;
30212 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
30213@@ -495,8 +493,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
30214 {
30215 unsigned long va = dtr->address;
30216 unsigned int size = dtr->size + 1;
30217- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
30218- unsigned long frames[pages];
30219+ unsigned long frames[65536 / PAGE_SIZE];
30220 int f;
30221
30222 /*
30223@@ -544,8 +541,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
30224 {
30225 unsigned long va = dtr->address;
30226 unsigned int size = dtr->size + 1;
30227- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
30228- unsigned long frames[pages];
30229+ unsigned long frames[65536 / PAGE_SIZE];
30230 int f;
30231
30232 /*
30233@@ -938,7 +934,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
30234 return 0;
30235 }
30236
30237-static void set_xen_basic_apic_ops(void)
30238+static void __init set_xen_basic_apic_ops(void)
30239 {
30240 apic->read = xen_apic_read;
30241 apic->write = xen_apic_write;
30242@@ -1244,30 +1240,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
30243 #endif
30244 };
30245
30246-static void xen_reboot(int reason)
30247+static __noreturn void xen_reboot(int reason)
30248 {
30249 struct sched_shutdown r = { .reason = reason };
30250
30251- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
30252- BUG();
30253+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
30254+ BUG();
30255 }
30256
30257-static void xen_restart(char *msg)
30258+static __noreturn void xen_restart(char *msg)
30259 {
30260 xen_reboot(SHUTDOWN_reboot);
30261 }
30262
30263-static void xen_emergency_restart(void)
30264+static __noreturn void xen_emergency_restart(void)
30265 {
30266 xen_reboot(SHUTDOWN_reboot);
30267 }
30268
30269-static void xen_machine_halt(void)
30270+static __noreturn void xen_machine_halt(void)
30271 {
30272 xen_reboot(SHUTDOWN_poweroff);
30273 }
30274
30275-static void xen_machine_power_off(void)
30276+static __noreturn void xen_machine_power_off(void)
30277 {
30278 if (pm_power_off)
30279 pm_power_off();
30280@@ -1369,7 +1365,17 @@ asmlinkage void __init xen_start_kernel(void)
30281 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
30282
30283 /* Work out if we support NX */
30284- x86_configure_nx();
30285+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
30286+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
30287+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
30288+ unsigned l, h;
30289+
30290+ __supported_pte_mask |= _PAGE_NX;
30291+ rdmsr(MSR_EFER, l, h);
30292+ l |= EFER_NX;
30293+ wrmsr(MSR_EFER, l, h);
30294+ }
30295+#endif
30296
30297 xen_setup_features();
30298
30299@@ -1398,14 +1404,7 @@ asmlinkage void __init xen_start_kernel(void)
30300 pv_mmu_ops.ptep_modify_prot_commit = xen_ptep_modify_prot_commit;
30301 }
30302
30303- machine_ops = xen_machine_ops;
30304-
30305- /*
30306- * The only reliable way to retain the initial address of the
30307- * percpu gdt_page is to remember it here, so we can go and
30308- * mark it RW later, when the initial percpu area is freed.
30309- */
30310- xen_initial_gdt = &per_cpu(gdt_page, 0);
30311+ memcpy((void *)&machine_ops, &xen_machine_ops, sizeof machine_ops);
30312
30313 xen_smp_init();
30314
30315@@ -1590,7 +1589,7 @@ static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self,
30316 return NOTIFY_OK;
30317 }
30318
30319-static struct notifier_block xen_hvm_cpu_notifier __cpuinitdata = {
30320+static struct notifier_block xen_hvm_cpu_notifier = {
30321 .notifier_call = xen_hvm_cpu_notify,
30322 };
30323
30324diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
30325index 01de35c..0bda07b 100644
30326--- a/arch/x86/xen/mmu.c
30327+++ b/arch/x86/xen/mmu.c
30328@@ -1881,6 +1881,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
30329 /* L3_k[510] -> level2_kernel_pgt
30330 * L3_i[511] -> level2_fixmap_pgt */
30331 convert_pfn_mfn(level3_kernel_pgt);
30332+ convert_pfn_mfn(level3_vmalloc_start_pgt);
30333+ convert_pfn_mfn(level3_vmalloc_end_pgt);
30334+ convert_pfn_mfn(level3_vmemmap_pgt);
30335
30336 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
30337 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
30338@@ -1910,8 +1913,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
30339 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
30340 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
30341 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
30342+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
30343+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
30344+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
30345 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
30346 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
30347+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
30348 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
30349 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
30350
30351@@ -2097,6 +2104,7 @@ static void __init xen_post_allocator_init(void)
30352 pv_mmu_ops.set_pud = xen_set_pud;
30353 #if PAGETABLE_LEVELS == 4
30354 pv_mmu_ops.set_pgd = xen_set_pgd;
30355+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
30356 #endif
30357
30358 /* This will work as long as patching hasn't happened yet
30359@@ -2178,6 +2186,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
30360 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
30361 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
30362 .set_pgd = xen_set_pgd_hyper,
30363+ .set_pgd_batched = xen_set_pgd_hyper,
30364
30365 .alloc_pud = xen_alloc_pmd_init,
30366 .release_pud = xen_release_pmd_init,
30367diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
30368index 34bc4ce..c34aa24 100644
30369--- a/arch/x86/xen/smp.c
30370+++ b/arch/x86/xen/smp.c
30371@@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
30372 {
30373 BUG_ON(smp_processor_id() != 0);
30374 native_smp_prepare_boot_cpu();
30375-
30376- /* We've switched to the "real" per-cpu gdt, so make sure the
30377- old memory can be recycled */
30378- make_lowmem_page_readwrite(xen_initial_gdt);
30379-
30380 xen_filter_cpu_maps();
30381 xen_setup_vcpu_info_placement();
30382 }
30383@@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
30384 gdt = get_cpu_gdt_table(cpu);
30385
30386 ctxt->flags = VGCF_IN_KERNEL;
30387- ctxt->user_regs.ds = __USER_DS;
30388- ctxt->user_regs.es = __USER_DS;
30389+ ctxt->user_regs.ds = __KERNEL_DS;
30390+ ctxt->user_regs.es = __KERNEL_DS;
30391 ctxt->user_regs.ss = __KERNEL_DS;
30392 #ifdef CONFIG_X86_32
30393 ctxt->user_regs.fs = __KERNEL_PERCPU;
30394- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
30395+ savesegment(gs, ctxt->user_regs.gs);
30396 #else
30397 ctxt->gs_base_kernel = per_cpu_offset(cpu);
30398 #endif
30399@@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
30400 int rc;
30401
30402 per_cpu(current_task, cpu) = idle;
30403+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
30404 #ifdef CONFIG_X86_32
30405 irq_ctx_init(cpu);
30406 #else
30407 clear_tsk_thread_flag(idle, TIF_FORK);
30408- per_cpu(kernel_stack, cpu) =
30409- (unsigned long)task_stack_page(idle) -
30410- KERNEL_STACK_OFFSET + THREAD_SIZE;
30411+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
30412 #endif
30413 xen_setup_runstate_info(cpu);
30414 xen_setup_timer(cpu);
30415@@ -630,7 +624,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
30416
30417 void __init xen_smp_init(void)
30418 {
30419- smp_ops = xen_smp_ops;
30420+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
30421 xen_fill_possible_map();
30422 xen_init_spinlocks();
30423 }
30424diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
30425index 33ca6e4..0ded929 100644
30426--- a/arch/x86/xen/xen-asm_32.S
30427+++ b/arch/x86/xen/xen-asm_32.S
30428@@ -84,14 +84,14 @@ ENTRY(xen_iret)
30429 ESP_OFFSET=4 # bytes pushed onto stack
30430
30431 /*
30432- * Store vcpu_info pointer for easy access. Do it this way to
30433- * avoid having to reload %fs
30434+ * Store vcpu_info pointer for easy access.
30435 */
30436 #ifdef CONFIG_SMP
30437- GET_THREAD_INFO(%eax)
30438- movl %ss:TI_cpu(%eax), %eax
30439- movl %ss:__per_cpu_offset(,%eax,4), %eax
30440- mov %ss:xen_vcpu(%eax), %eax
30441+ push %fs
30442+ mov $(__KERNEL_PERCPU), %eax
30443+ mov %eax, %fs
30444+ mov PER_CPU_VAR(xen_vcpu), %eax
30445+ pop %fs
30446 #else
30447 movl %ss:xen_vcpu, %eax
30448 #endif
30449diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
30450index 7faed58..ba4427c 100644
30451--- a/arch/x86/xen/xen-head.S
30452+++ b/arch/x86/xen/xen-head.S
30453@@ -19,6 +19,17 @@ ENTRY(startup_xen)
30454 #ifdef CONFIG_X86_32
30455 mov %esi,xen_start_info
30456 mov $init_thread_union+THREAD_SIZE,%esp
30457+#ifdef CONFIG_SMP
30458+ movl $cpu_gdt_table,%edi
30459+ movl $__per_cpu_load,%eax
30460+ movw %ax,__KERNEL_PERCPU + 2(%edi)
30461+ rorl $16,%eax
30462+ movb %al,__KERNEL_PERCPU + 4(%edi)
30463+ movb %ah,__KERNEL_PERCPU + 7(%edi)
30464+ movl $__per_cpu_end - 1,%eax
30465+ subl $__per_cpu_start,%eax
30466+ movw %ax,__KERNEL_PERCPU + 0(%edi)
30467+#endif
30468 #else
30469 mov %rsi,xen_start_info
30470 mov $init_thread_union+THREAD_SIZE,%rsp
30471diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
30472index a95b417..b6dbd0b 100644
30473--- a/arch/x86/xen/xen-ops.h
30474+++ b/arch/x86/xen/xen-ops.h
30475@@ -10,8 +10,6 @@
30476 extern const char xen_hypervisor_callback[];
30477 extern const char xen_failsafe_callback[];
30478
30479-extern void *xen_initial_gdt;
30480-
30481 struct trap_info;
30482 void xen_copy_trap_info(struct trap_info *traps);
30483
30484diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
30485index 525bd3d..ef888b1 100644
30486--- a/arch/xtensa/variants/dc232b/include/variant/core.h
30487+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
30488@@ -119,9 +119,9 @@
30489 ----------------------------------------------------------------------*/
30490
30491 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
30492-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
30493 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
30494 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
30495+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
30496
30497 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
30498 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
30499diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
30500index 2f33760..835e50a 100644
30501--- a/arch/xtensa/variants/fsf/include/variant/core.h
30502+++ b/arch/xtensa/variants/fsf/include/variant/core.h
30503@@ -11,6 +11,7 @@
30504 #ifndef _XTENSA_CORE_H
30505 #define _XTENSA_CORE_H
30506
30507+#include <linux/const.h>
30508
30509 /****************************************************************************
30510 Parameters Useful for Any Code, USER or PRIVILEGED
30511@@ -112,9 +113,9 @@
30512 ----------------------------------------------------------------------*/
30513
30514 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
30515-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
30516 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
30517 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
30518+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
30519
30520 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
30521 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
30522diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
30523index af00795..2bb8105 100644
30524--- a/arch/xtensa/variants/s6000/include/variant/core.h
30525+++ b/arch/xtensa/variants/s6000/include/variant/core.h
30526@@ -11,6 +11,7 @@
30527 #ifndef _XTENSA_CORE_CONFIGURATION_H
30528 #define _XTENSA_CORE_CONFIGURATION_H
30529
30530+#include <linux/const.h>
30531
30532 /****************************************************************************
30533 Parameters Useful for Any Code, USER or PRIVILEGED
30534@@ -118,9 +119,9 @@
30535 ----------------------------------------------------------------------*/
30536
30537 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
30538-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
30539 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
30540 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
30541+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
30542
30543 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
30544 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
30545diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
30546index 58916af..eb9dbcf6 100644
30547--- a/block/blk-iopoll.c
30548+++ b/block/blk-iopoll.c
30549@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
30550 }
30551 EXPORT_SYMBOL(blk_iopoll_complete);
30552
30553-static void blk_iopoll_softirq(struct softirq_action *h)
30554+static void blk_iopoll_softirq(void)
30555 {
30556 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
30557 int rearm = 0, budget = blk_iopoll_budget;
30558@@ -209,7 +209,7 @@ static int __cpuinit blk_iopoll_cpu_notify(struct notifier_block *self,
30559 return NOTIFY_OK;
30560 }
30561
30562-static struct notifier_block __cpuinitdata blk_iopoll_cpu_notifier = {
30563+static struct notifier_block blk_iopoll_cpu_notifier = {
30564 .notifier_call = blk_iopoll_cpu_notify,
30565 };
30566
30567diff --git a/block/blk-map.c b/block/blk-map.c
30568index 623e1cd..ca1e109 100644
30569--- a/block/blk-map.c
30570+++ b/block/blk-map.c
30571@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
30572 if (!len || !kbuf)
30573 return -EINVAL;
30574
30575- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
30576+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
30577 if (do_copy)
30578 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
30579 else
30580diff --git a/block/blk-softirq.c b/block/blk-softirq.c
30581index 467c8de..f3628c5 100644
30582--- a/block/blk-softirq.c
30583+++ b/block/blk-softirq.c
30584@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
30585 * Softirq action handler - move entries to local list and loop over them
30586 * while passing them to the queue registered handler.
30587 */
30588-static void blk_done_softirq(struct softirq_action *h)
30589+static void blk_done_softirq(void)
30590 {
30591 struct list_head *cpu_list, local_list;
30592
30593@@ -98,7 +98,7 @@ static int __cpuinit blk_cpu_notify(struct notifier_block *self,
30594 return NOTIFY_OK;
30595 }
30596
30597-static struct notifier_block __cpuinitdata blk_cpu_notifier = {
30598+static struct notifier_block blk_cpu_notifier = {
30599 .notifier_call = blk_cpu_notify,
30600 };
30601
30602diff --git a/block/bsg.c b/block/bsg.c
30603index ff64ae3..593560c 100644
30604--- a/block/bsg.c
30605+++ b/block/bsg.c
30606@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
30607 struct sg_io_v4 *hdr, struct bsg_device *bd,
30608 fmode_t has_write_perm)
30609 {
30610+ unsigned char tmpcmd[sizeof(rq->__cmd)];
30611+ unsigned char *cmdptr;
30612+
30613 if (hdr->request_len > BLK_MAX_CDB) {
30614 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
30615 if (!rq->cmd)
30616 return -ENOMEM;
30617- }
30618+ cmdptr = rq->cmd;
30619+ } else
30620+ cmdptr = tmpcmd;
30621
30622- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
30623+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
30624 hdr->request_len))
30625 return -EFAULT;
30626
30627+ if (cmdptr != rq->cmd)
30628+ memcpy(rq->cmd, cmdptr, hdr->request_len);
30629+
30630 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
30631 if (blk_verify_command(rq->cmd, has_write_perm))
30632 return -EPERM;
30633diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
30634index 7c668c8..db3521c 100644
30635--- a/block/compat_ioctl.c
30636+++ b/block/compat_ioctl.c
30637@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
30638 err |= __get_user(f->spec1, &uf->spec1);
30639 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
30640 err |= __get_user(name, &uf->name);
30641- f->name = compat_ptr(name);
30642+ f->name = (void __force_kernel *)compat_ptr(name);
30643 if (err) {
30644 err = -EFAULT;
30645 goto out;
30646diff --git a/block/partitions/efi.c b/block/partitions/efi.c
30647index b62fb88..bdab4c4 100644
30648--- a/block/partitions/efi.c
30649+++ b/block/partitions/efi.c
30650@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
30651 if (!gpt)
30652 return NULL;
30653
30654+ if (!le32_to_cpu(gpt->num_partition_entries))
30655+ return NULL;
30656+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
30657+ if (!pte)
30658+ return NULL;
30659+
30660 count = le32_to_cpu(gpt->num_partition_entries) *
30661 le32_to_cpu(gpt->sizeof_partition_entry);
30662- if (!count)
30663- return NULL;
30664- pte = kzalloc(count, GFP_KERNEL);
30665- if (!pte)
30666- return NULL;
30667-
30668 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
30669 (u8 *) pte,
30670 count) < count) {
30671diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
30672index 9a87daa..fb17486 100644
30673--- a/block/scsi_ioctl.c
30674+++ b/block/scsi_ioctl.c
30675@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
30676 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
30677 struct sg_io_hdr *hdr, fmode_t mode)
30678 {
30679- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
30680+ unsigned char tmpcmd[sizeof(rq->__cmd)];
30681+ unsigned char *cmdptr;
30682+
30683+ if (rq->cmd != rq->__cmd)
30684+ cmdptr = rq->cmd;
30685+ else
30686+ cmdptr = tmpcmd;
30687+
30688+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
30689 return -EFAULT;
30690+
30691+ if (cmdptr != rq->cmd)
30692+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
30693+
30694 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
30695 return -EPERM;
30696
30697@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
30698 int err;
30699 unsigned int in_len, out_len, bytes, opcode, cmdlen;
30700 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
30701+ unsigned char tmpcmd[sizeof(rq->__cmd)];
30702+ unsigned char *cmdptr;
30703
30704 if (!sic)
30705 return -EINVAL;
30706@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
30707 */
30708 err = -EFAULT;
30709 rq->cmd_len = cmdlen;
30710- if (copy_from_user(rq->cmd, sic->data, cmdlen))
30711+
30712+ if (rq->cmd != rq->__cmd)
30713+ cmdptr = rq->cmd;
30714+ else
30715+ cmdptr = tmpcmd;
30716+
30717+ if (copy_from_user(cmdptr, sic->data, cmdlen))
30718 goto error;
30719
30720+ if (rq->cmd != cmdptr)
30721+ memcpy(rq->cmd, cmdptr, cmdlen);
30722+
30723 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
30724 goto error;
30725
30726diff --git a/crypto/ablkcipher.c b/crypto/ablkcipher.c
30727index 533de95..7d4a8d2 100644
30728--- a/crypto/ablkcipher.c
30729+++ b/crypto/ablkcipher.c
30730@@ -388,9 +388,9 @@ static int crypto_ablkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
30731 {
30732 struct crypto_report_blkcipher rblkcipher;
30733
30734- snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "ablkcipher");
30735- snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s",
30736- alg->cra_ablkcipher.geniv ?: "<default>");
30737+ strncpy(rblkcipher.type, "ablkcipher", sizeof(rblkcipher.type));
30738+ strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "<default>",
30739+ sizeof(rblkcipher.geniv));
30740
30741 rblkcipher.blocksize = alg->cra_blocksize;
30742 rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize;
30743@@ -469,9 +469,9 @@ static int crypto_givcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
30744 {
30745 struct crypto_report_blkcipher rblkcipher;
30746
30747- snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "givcipher");
30748- snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s",
30749- alg->cra_ablkcipher.geniv ?: "<built-in>");
30750+ strncpy(rblkcipher.type, "givcipher", sizeof(rblkcipher.type));
30751+ strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "<built-in>",
30752+ sizeof(rblkcipher.geniv));
30753
30754 rblkcipher.blocksize = alg->cra_blocksize;
30755 rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize;
30756diff --git a/crypto/aead.c b/crypto/aead.c
30757index 0b8121e..27bc487 100644
30758--- a/crypto/aead.c
30759+++ b/crypto/aead.c
30760@@ -117,9 +117,8 @@ static int crypto_aead_report(struct sk_buff *skb, struct crypto_alg *alg)
30761 struct crypto_report_aead raead;
30762 struct aead_alg *aead = &alg->cra_aead;
30763
30764- snprintf(raead.type, CRYPTO_MAX_ALG_NAME, "%s", "aead");
30765- snprintf(raead.geniv, CRYPTO_MAX_ALG_NAME, "%s",
30766- aead->geniv ?: "<built-in>");
30767+ strncpy(raead.type, "aead", sizeof(raead.type));
30768+ strncpy(raead.geniv, aead->geniv ?: "<built-in>", sizeof(raead.geniv));
30769
30770 raead.blocksize = alg->cra_blocksize;
30771 raead.maxauthsize = aead->maxauthsize;
30772@@ -203,8 +202,8 @@ static int crypto_nivaead_report(struct sk_buff *skb, struct crypto_alg *alg)
30773 struct crypto_report_aead raead;
30774 struct aead_alg *aead = &alg->cra_aead;
30775
30776- snprintf(raead.type, CRYPTO_MAX_ALG_NAME, "%s", "nivaead");
30777- snprintf(raead.geniv, CRYPTO_MAX_ALG_NAME, "%s", aead->geniv);
30778+ strncpy(raead.type, "nivaead", sizeof(raead.type));
30779+ strncpy(raead.geniv, aead->geniv, sizeof(raead.geniv));
30780
30781 raead.blocksize = alg->cra_blocksize;
30782 raead.maxauthsize = aead->maxauthsize;
30783diff --git a/crypto/ahash.c b/crypto/ahash.c
30784index 3887856..793a27f 100644
30785--- a/crypto/ahash.c
30786+++ b/crypto/ahash.c
30787@@ -404,7 +404,7 @@ static int crypto_ahash_report(struct sk_buff *skb, struct crypto_alg *alg)
30788 {
30789 struct crypto_report_hash rhash;
30790
30791- snprintf(rhash.type, CRYPTO_MAX_ALG_NAME, "%s", "ahash");
30792+ strncpy(rhash.type, "ahash", sizeof(rhash.type));
30793
30794 rhash.blocksize = alg->cra_blocksize;
30795 rhash.digestsize = __crypto_hash_alg_common(alg)->digestsize;
30796diff --git a/crypto/blkcipher.c b/crypto/blkcipher.c
30797index a8d85a1..c44e014 100644
30798--- a/crypto/blkcipher.c
30799+++ b/crypto/blkcipher.c
30800@@ -499,9 +499,9 @@ static int crypto_blkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
30801 {
30802 struct crypto_report_blkcipher rblkcipher;
30803
30804- snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "blkcipher");
30805- snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s",
30806- alg->cra_blkcipher.geniv ?: "<default>");
30807+ strncpy(rblkcipher.type, "blkcipher", sizeof(rblkcipher.type));
30808+ strncpy(rblkcipher.geniv, alg->cra_blkcipher.geniv ?: "<default>",
30809+ sizeof(rblkcipher.geniv));
30810
30811 rblkcipher.blocksize = alg->cra_blocksize;
30812 rblkcipher.min_keysize = alg->cra_blkcipher.min_keysize;
30813diff --git a/crypto/cryptd.c b/crypto/cryptd.c
30814index 7bdd61b..afec999 100644
30815--- a/crypto/cryptd.c
30816+++ b/crypto/cryptd.c
30817@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
30818
30819 struct cryptd_blkcipher_request_ctx {
30820 crypto_completion_t complete;
30821-};
30822+} __no_const;
30823
30824 struct cryptd_hash_ctx {
30825 struct crypto_shash *child;
30826@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
30827
30828 struct cryptd_aead_request_ctx {
30829 crypto_completion_t complete;
30830-};
30831+} __no_const;
30832
30833 static void cryptd_queue_worker(struct work_struct *work);
30834
30835diff --git a/crypto/crypto_user.c b/crypto/crypto_user.c
30836index 35d700a..dfd511f 100644
30837--- a/crypto/crypto_user.c
30838+++ b/crypto/crypto_user.c
30839@@ -30,6 +30,8 @@
30840
30841 #include "internal.h"
30842
30843+#define null_terminated(x) (strnlen(x, sizeof(x)) < sizeof(x))
30844+
30845 static DEFINE_MUTEX(crypto_cfg_mutex);
30846
30847 /* The crypto netlink socket */
30848@@ -75,7 +77,7 @@ static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg)
30849 {
30850 struct crypto_report_cipher rcipher;
30851
30852- snprintf(rcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "cipher");
30853+ strncpy(rcipher.type, "cipher", sizeof(rcipher.type));
30854
30855 rcipher.blocksize = alg->cra_blocksize;
30856 rcipher.min_keysize = alg->cra_cipher.cia_min_keysize;
30857@@ -94,8 +96,7 @@ static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg)
30858 {
30859 struct crypto_report_comp rcomp;
30860
30861- snprintf(rcomp.type, CRYPTO_MAX_ALG_NAME, "%s", "compression");
30862-
30863+ strncpy(rcomp.type, "compression", sizeof(rcomp.type));
30864 if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
30865 sizeof(struct crypto_report_comp), &rcomp))
30866 goto nla_put_failure;
30867@@ -108,12 +109,14 @@ nla_put_failure:
30868 static int crypto_report_one(struct crypto_alg *alg,
30869 struct crypto_user_alg *ualg, struct sk_buff *skb)
30870 {
30871- memcpy(&ualg->cru_name, &alg->cra_name, sizeof(ualg->cru_name));
30872- memcpy(&ualg->cru_driver_name, &alg->cra_driver_name,
30873- sizeof(ualg->cru_driver_name));
30874- memcpy(&ualg->cru_module_name, module_name(alg->cra_module),
30875- CRYPTO_MAX_ALG_NAME);
30876+ strncpy(ualg->cru_name, alg->cra_name, sizeof(ualg->cru_name));
30877+ strncpy(ualg->cru_driver_name, alg->cra_driver_name,
30878+ sizeof(ualg->cru_driver_name));
30879+ strncpy(ualg->cru_module_name, module_name(alg->cra_module),
30880+ sizeof(ualg->cru_module_name));
30881
30882+ ualg->cru_type = 0;
30883+ ualg->cru_mask = 0;
30884 ualg->cru_flags = alg->cra_flags;
30885 ualg->cru_refcnt = atomic_read(&alg->cra_refcnt);
30886
30887@@ -122,8 +125,7 @@ static int crypto_report_one(struct crypto_alg *alg,
30888 if (alg->cra_flags & CRYPTO_ALG_LARVAL) {
30889 struct crypto_report_larval rl;
30890
30891- snprintf(rl.type, CRYPTO_MAX_ALG_NAME, "%s", "larval");
30892-
30893+ strncpy(rl.type, "larval", sizeof(rl.type));
30894 if (nla_put(skb, CRYPTOCFGA_REPORT_LARVAL,
30895 sizeof(struct crypto_report_larval), &rl))
30896 goto nla_put_failure;
30897@@ -196,7 +198,10 @@ static int crypto_report(struct sk_buff *in_skb, struct nlmsghdr *in_nlh,
30898 struct crypto_dump_info info;
30899 int err;
30900
30901- if (!p->cru_driver_name)
30902+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
30903+ return -EINVAL;
30904+
30905+ if (!p->cru_driver_name[0])
30906 return -EINVAL;
30907
30908 alg = crypto_alg_match(p, 1);
30909@@ -260,6 +265,9 @@ static int crypto_update_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
30910 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
30911 LIST_HEAD(list);
30912
30913+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
30914+ return -EINVAL;
30915+
30916 if (priority && !strlen(p->cru_driver_name))
30917 return -EINVAL;
30918
30919@@ -287,6 +295,9 @@ static int crypto_del_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
30920 struct crypto_alg *alg;
30921 struct crypto_user_alg *p = nlmsg_data(nlh);
30922
30923+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
30924+ return -EINVAL;
30925+
30926 alg = crypto_alg_match(p, 1);
30927 if (!alg)
30928 return -ENOENT;
30929@@ -368,6 +379,9 @@ static int crypto_add_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
30930 struct crypto_user_alg *p = nlmsg_data(nlh);
30931 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
30932
30933+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
30934+ return -EINVAL;
30935+
30936 if (strlen(p->cru_driver_name))
30937 exact = 1;
30938
30939diff --git a/crypto/pcompress.c b/crypto/pcompress.c
30940index 04e083f..7140fe7 100644
30941--- a/crypto/pcompress.c
30942+++ b/crypto/pcompress.c
30943@@ -53,8 +53,7 @@ static int crypto_pcomp_report(struct sk_buff *skb, struct crypto_alg *alg)
30944 {
30945 struct crypto_report_comp rpcomp;
30946
30947- snprintf(rpcomp.type, CRYPTO_MAX_ALG_NAME, "%s", "pcomp");
30948-
30949+ strncpy(rpcomp.type, "pcomp", sizeof(rpcomp.type));
30950 if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
30951 sizeof(struct crypto_report_comp), &rpcomp))
30952 goto nla_put_failure;
30953diff --git a/crypto/rng.c b/crypto/rng.c
30954index f3b7894..e0a25c2 100644
30955--- a/crypto/rng.c
30956+++ b/crypto/rng.c
30957@@ -65,7 +65,7 @@ static int crypto_rng_report(struct sk_buff *skb, struct crypto_alg *alg)
30958 {
30959 struct crypto_report_rng rrng;
30960
30961- snprintf(rrng.type, CRYPTO_MAX_ALG_NAME, "%s", "rng");
30962+ strncpy(rrng.type, "rng", sizeof(rrng.type));
30963
30964 rrng.seedsize = alg->cra_rng.seedsize;
30965
30966diff --git a/crypto/shash.c b/crypto/shash.c
30967index f426330f..929058a 100644
30968--- a/crypto/shash.c
30969+++ b/crypto/shash.c
30970@@ -530,7 +530,8 @@ static int crypto_shash_report(struct sk_buff *skb, struct crypto_alg *alg)
30971 struct crypto_report_hash rhash;
30972 struct shash_alg *salg = __crypto_shash_alg(alg);
30973
30974- snprintf(rhash.type, CRYPTO_MAX_ALG_NAME, "%s", "shash");
30975+ strncpy(rhash.type, "shash", sizeof(rhash.type));
30976+
30977 rhash.blocksize = alg->cra_blocksize;
30978 rhash.digestsize = salg->digestsize;
30979
30980diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
30981index e6defd8..c26a225 100644
30982--- a/drivers/acpi/apei/cper.c
30983+++ b/drivers/acpi/apei/cper.c
30984@@ -38,12 +38,12 @@
30985 */
30986 u64 cper_next_record_id(void)
30987 {
30988- static atomic64_t seq;
30989+ static atomic64_unchecked_t seq;
30990
30991- if (!atomic64_read(&seq))
30992- atomic64_set(&seq, ((u64)get_seconds()) << 32);
30993+ if (!atomic64_read_unchecked(&seq))
30994+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
30995
30996- return atomic64_inc_return(&seq);
30997+ return atomic64_inc_return_unchecked(&seq);
30998 }
30999 EXPORT_SYMBOL_GPL(cper_next_record_id);
31000
31001diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
31002index 7586544..636a2f0 100644
31003--- a/drivers/acpi/ec_sys.c
31004+++ b/drivers/acpi/ec_sys.c
31005@@ -12,6 +12,7 @@
31006 #include <linux/acpi.h>
31007 #include <linux/debugfs.h>
31008 #include <linux/module.h>
31009+#include <linux/uaccess.h>
31010 #include "internal.h"
31011
31012 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
31013@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
31014 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
31015 */
31016 unsigned int size = EC_SPACE_SIZE;
31017- u8 *data = (u8 *) buf;
31018+ u8 data;
31019 loff_t init_off = *off;
31020 int err = 0;
31021
31022@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
31023 size = count;
31024
31025 while (size) {
31026- err = ec_read(*off, &data[*off - init_off]);
31027+ err = ec_read(*off, &data);
31028 if (err)
31029 return err;
31030+ if (put_user(data, &buf[*off - init_off]))
31031+ return -EFAULT;
31032 *off += 1;
31033 size--;
31034 }
31035@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
31036
31037 unsigned int size = count;
31038 loff_t init_off = *off;
31039- u8 *data = (u8 *) buf;
31040 int err = 0;
31041
31042 if (*off >= EC_SPACE_SIZE)
31043@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
31044 }
31045
31046 while (size) {
31047- u8 byte_write = data[*off - init_off];
31048+ u8 byte_write;
31049+ if (get_user(byte_write, &buf[*off - init_off]))
31050+ return -EFAULT;
31051 err = ec_write(*off, byte_write);
31052 if (err)
31053 return err;
31054diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
31055index e83311b..142b5cc 100644
31056--- a/drivers/acpi/processor_driver.c
31057+++ b/drivers/acpi/processor_driver.c
31058@@ -558,7 +558,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
31059 return 0;
31060 #endif
31061
31062- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
31063+ BUG_ON(pr->id >= nr_cpu_ids);
31064
31065 /*
31066 * Buggy BIOS check
31067diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
31068index 46cd3f4..0871ad0 100644
31069--- a/drivers/ata/libata-core.c
31070+++ b/drivers/ata/libata-core.c
31071@@ -4780,7 +4780,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
31072 struct ata_port *ap;
31073 unsigned int tag;
31074
31075- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31076+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31077 ap = qc->ap;
31078
31079 qc->flags = 0;
31080@@ -4796,7 +4796,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
31081 struct ata_port *ap;
31082 struct ata_link *link;
31083
31084- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31085+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31086 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
31087 ap = qc->ap;
31088 link = qc->dev->link;
31089@@ -5892,6 +5892,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
31090 return;
31091
31092 spin_lock(&lock);
31093+ pax_open_kernel();
31094
31095 for (cur = ops->inherits; cur; cur = cur->inherits) {
31096 void **inherit = (void **)cur;
31097@@ -5905,8 +5906,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
31098 if (IS_ERR(*pp))
31099 *pp = NULL;
31100
31101- ops->inherits = NULL;
31102+ *(struct ata_port_operations **)&ops->inherits = NULL;
31103
31104+ pax_close_kernel();
31105 spin_unlock(&lock);
31106 }
31107
31108diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
31109index 405022d..fb70e53 100644
31110--- a/drivers/ata/pata_arasan_cf.c
31111+++ b/drivers/ata/pata_arasan_cf.c
31112@@ -864,7 +864,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
31113 /* Handle platform specific quirks */
31114 if (pdata->quirk) {
31115 if (pdata->quirk & CF_BROKEN_PIO) {
31116- ap->ops->set_piomode = NULL;
31117+ pax_open_kernel();
31118+ *(void **)&ap->ops->set_piomode = NULL;
31119+ pax_close_kernel();
31120 ap->pio_mask = 0;
31121 }
31122 if (pdata->quirk & CF_BROKEN_MWDMA)
31123diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
31124index f9b983a..887b9d8 100644
31125--- a/drivers/atm/adummy.c
31126+++ b/drivers/atm/adummy.c
31127@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
31128 vcc->pop(vcc, skb);
31129 else
31130 dev_kfree_skb_any(skb);
31131- atomic_inc(&vcc->stats->tx);
31132+ atomic_inc_unchecked(&vcc->stats->tx);
31133
31134 return 0;
31135 }
31136diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
31137index 77a7480..05cde58 100644
31138--- a/drivers/atm/ambassador.c
31139+++ b/drivers/atm/ambassador.c
31140@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
31141 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
31142
31143 // VC layer stats
31144- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31145+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31146
31147 // free the descriptor
31148 kfree (tx_descr);
31149@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
31150 dump_skb ("<<<", vc, skb);
31151
31152 // VC layer stats
31153- atomic_inc(&atm_vcc->stats->rx);
31154+ atomic_inc_unchecked(&atm_vcc->stats->rx);
31155 __net_timestamp(skb);
31156 // end of our responsibility
31157 atm_vcc->push (atm_vcc, skb);
31158@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
31159 } else {
31160 PRINTK (KERN_INFO, "dropped over-size frame");
31161 // should we count this?
31162- atomic_inc(&atm_vcc->stats->rx_drop);
31163+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31164 }
31165
31166 } else {
31167@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
31168 }
31169
31170 if (check_area (skb->data, skb->len)) {
31171- atomic_inc(&atm_vcc->stats->tx_err);
31172+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
31173 return -ENOMEM; // ?
31174 }
31175
31176diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
31177index b22d71c..d6e1049 100644
31178--- a/drivers/atm/atmtcp.c
31179+++ b/drivers/atm/atmtcp.c
31180@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31181 if (vcc->pop) vcc->pop(vcc,skb);
31182 else dev_kfree_skb(skb);
31183 if (dev_data) return 0;
31184- atomic_inc(&vcc->stats->tx_err);
31185+ atomic_inc_unchecked(&vcc->stats->tx_err);
31186 return -ENOLINK;
31187 }
31188 size = skb->len+sizeof(struct atmtcp_hdr);
31189@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31190 if (!new_skb) {
31191 if (vcc->pop) vcc->pop(vcc,skb);
31192 else dev_kfree_skb(skb);
31193- atomic_inc(&vcc->stats->tx_err);
31194+ atomic_inc_unchecked(&vcc->stats->tx_err);
31195 return -ENOBUFS;
31196 }
31197 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
31198@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31199 if (vcc->pop) vcc->pop(vcc,skb);
31200 else dev_kfree_skb(skb);
31201 out_vcc->push(out_vcc,new_skb);
31202- atomic_inc(&vcc->stats->tx);
31203- atomic_inc(&out_vcc->stats->rx);
31204+ atomic_inc_unchecked(&vcc->stats->tx);
31205+ atomic_inc_unchecked(&out_vcc->stats->rx);
31206 return 0;
31207 }
31208
31209@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
31210 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
31211 read_unlock(&vcc_sklist_lock);
31212 if (!out_vcc) {
31213- atomic_inc(&vcc->stats->tx_err);
31214+ atomic_inc_unchecked(&vcc->stats->tx_err);
31215 goto done;
31216 }
31217 skb_pull(skb,sizeof(struct atmtcp_hdr));
31218@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
31219 __net_timestamp(new_skb);
31220 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
31221 out_vcc->push(out_vcc,new_skb);
31222- atomic_inc(&vcc->stats->tx);
31223- atomic_inc(&out_vcc->stats->rx);
31224+ atomic_inc_unchecked(&vcc->stats->tx);
31225+ atomic_inc_unchecked(&out_vcc->stats->rx);
31226 done:
31227 if (vcc->pop) vcc->pop(vcc,skb);
31228 else dev_kfree_skb(skb);
31229diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
31230index c1eb6fa..4c71be9 100644
31231--- a/drivers/atm/eni.c
31232+++ b/drivers/atm/eni.c
31233@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
31234 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
31235 vcc->dev->number);
31236 length = 0;
31237- atomic_inc(&vcc->stats->rx_err);
31238+ atomic_inc_unchecked(&vcc->stats->rx_err);
31239 }
31240 else {
31241 length = ATM_CELL_SIZE-1; /* no HEC */
31242@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
31243 size);
31244 }
31245 eff = length = 0;
31246- atomic_inc(&vcc->stats->rx_err);
31247+ atomic_inc_unchecked(&vcc->stats->rx_err);
31248 }
31249 else {
31250 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
31251@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
31252 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
31253 vcc->dev->number,vcc->vci,length,size << 2,descr);
31254 length = eff = 0;
31255- atomic_inc(&vcc->stats->rx_err);
31256+ atomic_inc_unchecked(&vcc->stats->rx_err);
31257 }
31258 }
31259 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
31260@@ -767,7 +767,7 @@ rx_dequeued++;
31261 vcc->push(vcc,skb);
31262 pushed++;
31263 }
31264- atomic_inc(&vcc->stats->rx);
31265+ atomic_inc_unchecked(&vcc->stats->rx);
31266 }
31267 wake_up(&eni_dev->rx_wait);
31268 }
31269@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
31270 PCI_DMA_TODEVICE);
31271 if (vcc->pop) vcc->pop(vcc,skb);
31272 else dev_kfree_skb_irq(skb);
31273- atomic_inc(&vcc->stats->tx);
31274+ atomic_inc_unchecked(&vcc->stats->tx);
31275 wake_up(&eni_dev->tx_wait);
31276 dma_complete++;
31277 }
31278diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
31279index b41c948..a002b17 100644
31280--- a/drivers/atm/firestream.c
31281+++ b/drivers/atm/firestream.c
31282@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
31283 }
31284 }
31285
31286- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31287+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31288
31289 fs_dprintk (FS_DEBUG_TXMEM, "i");
31290 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
31291@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
31292 #endif
31293 skb_put (skb, qe->p1 & 0xffff);
31294 ATM_SKB(skb)->vcc = atm_vcc;
31295- atomic_inc(&atm_vcc->stats->rx);
31296+ atomic_inc_unchecked(&atm_vcc->stats->rx);
31297 __net_timestamp(skb);
31298 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
31299 atm_vcc->push (atm_vcc, skb);
31300@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
31301 kfree (pe);
31302 }
31303 if (atm_vcc)
31304- atomic_inc(&atm_vcc->stats->rx_drop);
31305+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31306 break;
31307 case 0x1f: /* Reassembly abort: no buffers. */
31308 /* Silently increment error counter. */
31309 if (atm_vcc)
31310- atomic_inc(&atm_vcc->stats->rx_drop);
31311+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31312 break;
31313 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
31314 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
31315diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
31316index 204814e..cede831 100644
31317--- a/drivers/atm/fore200e.c
31318+++ b/drivers/atm/fore200e.c
31319@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
31320 #endif
31321 /* check error condition */
31322 if (*entry->status & STATUS_ERROR)
31323- atomic_inc(&vcc->stats->tx_err);
31324+ atomic_inc_unchecked(&vcc->stats->tx_err);
31325 else
31326- atomic_inc(&vcc->stats->tx);
31327+ atomic_inc_unchecked(&vcc->stats->tx);
31328 }
31329 }
31330
31331@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
31332 if (skb == NULL) {
31333 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
31334
31335- atomic_inc(&vcc->stats->rx_drop);
31336+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31337 return -ENOMEM;
31338 }
31339
31340@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
31341
31342 dev_kfree_skb_any(skb);
31343
31344- atomic_inc(&vcc->stats->rx_drop);
31345+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31346 return -ENOMEM;
31347 }
31348
31349 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
31350
31351 vcc->push(vcc, skb);
31352- atomic_inc(&vcc->stats->rx);
31353+ atomic_inc_unchecked(&vcc->stats->rx);
31354
31355 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
31356
31357@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
31358 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
31359 fore200e->atm_dev->number,
31360 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
31361- atomic_inc(&vcc->stats->rx_err);
31362+ atomic_inc_unchecked(&vcc->stats->rx_err);
31363 }
31364 }
31365
31366@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
31367 goto retry_here;
31368 }
31369
31370- atomic_inc(&vcc->stats->tx_err);
31371+ atomic_inc_unchecked(&vcc->stats->tx_err);
31372
31373 fore200e->tx_sat++;
31374 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
31375diff --git a/drivers/atm/he.c b/drivers/atm/he.c
31376index 72b6960..cf9167a 100644
31377--- a/drivers/atm/he.c
31378+++ b/drivers/atm/he.c
31379@@ -1699,7 +1699,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
31380
31381 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
31382 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
31383- atomic_inc(&vcc->stats->rx_drop);
31384+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31385 goto return_host_buffers;
31386 }
31387
31388@@ -1726,7 +1726,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
31389 RBRQ_LEN_ERR(he_dev->rbrq_head)
31390 ? "LEN_ERR" : "",
31391 vcc->vpi, vcc->vci);
31392- atomic_inc(&vcc->stats->rx_err);
31393+ atomic_inc_unchecked(&vcc->stats->rx_err);
31394 goto return_host_buffers;
31395 }
31396
31397@@ -1778,7 +1778,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
31398 vcc->push(vcc, skb);
31399 spin_lock(&he_dev->global_lock);
31400
31401- atomic_inc(&vcc->stats->rx);
31402+ atomic_inc_unchecked(&vcc->stats->rx);
31403
31404 return_host_buffers:
31405 ++pdus_assembled;
31406@@ -2104,7 +2104,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
31407 tpd->vcc->pop(tpd->vcc, tpd->skb);
31408 else
31409 dev_kfree_skb_any(tpd->skb);
31410- atomic_inc(&tpd->vcc->stats->tx_err);
31411+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
31412 }
31413 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
31414 return;
31415@@ -2516,7 +2516,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31416 vcc->pop(vcc, skb);
31417 else
31418 dev_kfree_skb_any(skb);
31419- atomic_inc(&vcc->stats->tx_err);
31420+ atomic_inc_unchecked(&vcc->stats->tx_err);
31421 return -EINVAL;
31422 }
31423
31424@@ -2527,7 +2527,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31425 vcc->pop(vcc, skb);
31426 else
31427 dev_kfree_skb_any(skb);
31428- atomic_inc(&vcc->stats->tx_err);
31429+ atomic_inc_unchecked(&vcc->stats->tx_err);
31430 return -EINVAL;
31431 }
31432 #endif
31433@@ -2539,7 +2539,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31434 vcc->pop(vcc, skb);
31435 else
31436 dev_kfree_skb_any(skb);
31437- atomic_inc(&vcc->stats->tx_err);
31438+ atomic_inc_unchecked(&vcc->stats->tx_err);
31439 spin_unlock_irqrestore(&he_dev->global_lock, flags);
31440 return -ENOMEM;
31441 }
31442@@ -2581,7 +2581,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31443 vcc->pop(vcc, skb);
31444 else
31445 dev_kfree_skb_any(skb);
31446- atomic_inc(&vcc->stats->tx_err);
31447+ atomic_inc_unchecked(&vcc->stats->tx_err);
31448 spin_unlock_irqrestore(&he_dev->global_lock, flags);
31449 return -ENOMEM;
31450 }
31451@@ -2612,7 +2612,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31452 __enqueue_tpd(he_dev, tpd, cid);
31453 spin_unlock_irqrestore(&he_dev->global_lock, flags);
31454
31455- atomic_inc(&vcc->stats->tx);
31456+ atomic_inc_unchecked(&vcc->stats->tx);
31457
31458 return 0;
31459 }
31460diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
31461index 1dc0519..1aadaf7 100644
31462--- a/drivers/atm/horizon.c
31463+++ b/drivers/atm/horizon.c
31464@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
31465 {
31466 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
31467 // VC layer stats
31468- atomic_inc(&vcc->stats->rx);
31469+ atomic_inc_unchecked(&vcc->stats->rx);
31470 __net_timestamp(skb);
31471 // end of our responsibility
31472 vcc->push (vcc, skb);
31473@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
31474 dev->tx_iovec = NULL;
31475
31476 // VC layer stats
31477- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31478+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31479
31480 // free the skb
31481 hrz_kfree_skb (skb);
31482diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
31483index 272f009..a18ba55 100644
31484--- a/drivers/atm/idt77252.c
31485+++ b/drivers/atm/idt77252.c
31486@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
31487 else
31488 dev_kfree_skb(skb);
31489
31490- atomic_inc(&vcc->stats->tx);
31491+ atomic_inc_unchecked(&vcc->stats->tx);
31492 }
31493
31494 atomic_dec(&scq->used);
31495@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31496 if ((sb = dev_alloc_skb(64)) == NULL) {
31497 printk("%s: Can't allocate buffers for aal0.\n",
31498 card->name);
31499- atomic_add(i, &vcc->stats->rx_drop);
31500+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
31501 break;
31502 }
31503 if (!atm_charge(vcc, sb->truesize)) {
31504 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
31505 card->name);
31506- atomic_add(i - 1, &vcc->stats->rx_drop);
31507+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
31508 dev_kfree_skb(sb);
31509 break;
31510 }
31511@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31512 ATM_SKB(sb)->vcc = vcc;
31513 __net_timestamp(sb);
31514 vcc->push(vcc, sb);
31515- atomic_inc(&vcc->stats->rx);
31516+ atomic_inc_unchecked(&vcc->stats->rx);
31517
31518 cell += ATM_CELL_PAYLOAD;
31519 }
31520@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31521 "(CDC: %08x)\n",
31522 card->name, len, rpp->len, readl(SAR_REG_CDC));
31523 recycle_rx_pool_skb(card, rpp);
31524- atomic_inc(&vcc->stats->rx_err);
31525+ atomic_inc_unchecked(&vcc->stats->rx_err);
31526 return;
31527 }
31528 if (stat & SAR_RSQE_CRC) {
31529 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
31530 recycle_rx_pool_skb(card, rpp);
31531- atomic_inc(&vcc->stats->rx_err);
31532+ atomic_inc_unchecked(&vcc->stats->rx_err);
31533 return;
31534 }
31535 if (skb_queue_len(&rpp->queue) > 1) {
31536@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31537 RXPRINTK("%s: Can't alloc RX skb.\n",
31538 card->name);
31539 recycle_rx_pool_skb(card, rpp);
31540- atomic_inc(&vcc->stats->rx_err);
31541+ atomic_inc_unchecked(&vcc->stats->rx_err);
31542 return;
31543 }
31544 if (!atm_charge(vcc, skb->truesize)) {
31545@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31546 __net_timestamp(skb);
31547
31548 vcc->push(vcc, skb);
31549- atomic_inc(&vcc->stats->rx);
31550+ atomic_inc_unchecked(&vcc->stats->rx);
31551
31552 return;
31553 }
31554@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31555 __net_timestamp(skb);
31556
31557 vcc->push(vcc, skb);
31558- atomic_inc(&vcc->stats->rx);
31559+ atomic_inc_unchecked(&vcc->stats->rx);
31560
31561 if (skb->truesize > SAR_FB_SIZE_3)
31562 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
31563@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
31564 if (vcc->qos.aal != ATM_AAL0) {
31565 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
31566 card->name, vpi, vci);
31567- atomic_inc(&vcc->stats->rx_drop);
31568+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31569 goto drop;
31570 }
31571
31572 if ((sb = dev_alloc_skb(64)) == NULL) {
31573 printk("%s: Can't allocate buffers for AAL0.\n",
31574 card->name);
31575- atomic_inc(&vcc->stats->rx_err);
31576+ atomic_inc_unchecked(&vcc->stats->rx_err);
31577 goto drop;
31578 }
31579
31580@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
31581 ATM_SKB(sb)->vcc = vcc;
31582 __net_timestamp(sb);
31583 vcc->push(vcc, sb);
31584- atomic_inc(&vcc->stats->rx);
31585+ atomic_inc_unchecked(&vcc->stats->rx);
31586
31587 drop:
31588 skb_pull(queue, 64);
31589@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
31590
31591 if (vc == NULL) {
31592 printk("%s: NULL connection in send().\n", card->name);
31593- atomic_inc(&vcc->stats->tx_err);
31594+ atomic_inc_unchecked(&vcc->stats->tx_err);
31595 dev_kfree_skb(skb);
31596 return -EINVAL;
31597 }
31598 if (!test_bit(VCF_TX, &vc->flags)) {
31599 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
31600- atomic_inc(&vcc->stats->tx_err);
31601+ atomic_inc_unchecked(&vcc->stats->tx_err);
31602 dev_kfree_skb(skb);
31603 return -EINVAL;
31604 }
31605@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
31606 break;
31607 default:
31608 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
31609- atomic_inc(&vcc->stats->tx_err);
31610+ atomic_inc_unchecked(&vcc->stats->tx_err);
31611 dev_kfree_skb(skb);
31612 return -EINVAL;
31613 }
31614
31615 if (skb_shinfo(skb)->nr_frags != 0) {
31616 printk("%s: No scatter-gather yet.\n", card->name);
31617- atomic_inc(&vcc->stats->tx_err);
31618+ atomic_inc_unchecked(&vcc->stats->tx_err);
31619 dev_kfree_skb(skb);
31620 return -EINVAL;
31621 }
31622@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
31623
31624 err = queue_skb(card, vc, skb, oam);
31625 if (err) {
31626- atomic_inc(&vcc->stats->tx_err);
31627+ atomic_inc_unchecked(&vcc->stats->tx_err);
31628 dev_kfree_skb(skb);
31629 return err;
31630 }
31631@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
31632 skb = dev_alloc_skb(64);
31633 if (!skb) {
31634 printk("%s: Out of memory in send_oam().\n", card->name);
31635- atomic_inc(&vcc->stats->tx_err);
31636+ atomic_inc_unchecked(&vcc->stats->tx_err);
31637 return -ENOMEM;
31638 }
31639 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
31640diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
31641index 4217f29..88f547a 100644
31642--- a/drivers/atm/iphase.c
31643+++ b/drivers/atm/iphase.c
31644@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
31645 status = (u_short) (buf_desc_ptr->desc_mode);
31646 if (status & (RX_CER | RX_PTE | RX_OFL))
31647 {
31648- atomic_inc(&vcc->stats->rx_err);
31649+ atomic_inc_unchecked(&vcc->stats->rx_err);
31650 IF_ERR(printk("IA: bad packet, dropping it");)
31651 if (status & RX_CER) {
31652 IF_ERR(printk(" cause: packet CRC error\n");)
31653@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
31654 len = dma_addr - buf_addr;
31655 if (len > iadev->rx_buf_sz) {
31656 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
31657- atomic_inc(&vcc->stats->rx_err);
31658+ atomic_inc_unchecked(&vcc->stats->rx_err);
31659 goto out_free_desc;
31660 }
31661
31662@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
31663 ia_vcc = INPH_IA_VCC(vcc);
31664 if (ia_vcc == NULL)
31665 {
31666- atomic_inc(&vcc->stats->rx_err);
31667+ atomic_inc_unchecked(&vcc->stats->rx_err);
31668 atm_return(vcc, skb->truesize);
31669 dev_kfree_skb_any(skb);
31670 goto INCR_DLE;
31671@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
31672 if ((length > iadev->rx_buf_sz) || (length >
31673 (skb->len - sizeof(struct cpcs_trailer))))
31674 {
31675- atomic_inc(&vcc->stats->rx_err);
31676+ atomic_inc_unchecked(&vcc->stats->rx_err);
31677 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
31678 length, skb->len);)
31679 atm_return(vcc, skb->truesize);
31680@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
31681
31682 IF_RX(printk("rx_dle_intr: skb push");)
31683 vcc->push(vcc,skb);
31684- atomic_inc(&vcc->stats->rx);
31685+ atomic_inc_unchecked(&vcc->stats->rx);
31686 iadev->rx_pkt_cnt++;
31687 }
31688 INCR_DLE:
31689@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
31690 {
31691 struct k_sonet_stats *stats;
31692 stats = &PRIV(_ia_dev[board])->sonet_stats;
31693- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
31694- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
31695- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
31696- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
31697- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
31698- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
31699- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
31700- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
31701- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
31702+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
31703+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
31704+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
31705+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
31706+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
31707+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
31708+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
31709+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
31710+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
31711 }
31712 ia_cmds.status = 0;
31713 break;
31714@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
31715 if ((desc == 0) || (desc > iadev->num_tx_desc))
31716 {
31717 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
31718- atomic_inc(&vcc->stats->tx);
31719+ atomic_inc_unchecked(&vcc->stats->tx);
31720 if (vcc->pop)
31721 vcc->pop(vcc, skb);
31722 else
31723@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
31724 ATM_DESC(skb) = vcc->vci;
31725 skb_queue_tail(&iadev->tx_dma_q, skb);
31726
31727- atomic_inc(&vcc->stats->tx);
31728+ atomic_inc_unchecked(&vcc->stats->tx);
31729 iadev->tx_pkt_cnt++;
31730 /* Increment transaction counter */
31731 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
31732
31733 #if 0
31734 /* add flow control logic */
31735- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
31736+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
31737 if (iavcc->vc_desc_cnt > 10) {
31738 vcc->tx_quota = vcc->tx_quota * 3 / 4;
31739 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
31740diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
31741index fa7d701..1e404c7 100644
31742--- a/drivers/atm/lanai.c
31743+++ b/drivers/atm/lanai.c
31744@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
31745 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
31746 lanai_endtx(lanai, lvcc);
31747 lanai_free_skb(lvcc->tx.atmvcc, skb);
31748- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
31749+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
31750 }
31751
31752 /* Try to fill the buffer - don't call unless there is backlog */
31753@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
31754 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
31755 __net_timestamp(skb);
31756 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
31757- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
31758+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
31759 out:
31760 lvcc->rx.buf.ptr = end;
31761 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
31762@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
31763 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
31764 "vcc %d\n", lanai->number, (unsigned int) s, vci);
31765 lanai->stats.service_rxnotaal5++;
31766- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
31767+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
31768 return 0;
31769 }
31770 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
31771@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
31772 int bytes;
31773 read_unlock(&vcc_sklist_lock);
31774 DPRINTK("got trashed rx pdu on vci %d\n", vci);
31775- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
31776+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
31777 lvcc->stats.x.aal5.service_trash++;
31778 bytes = (SERVICE_GET_END(s) * 16) -
31779 (((unsigned long) lvcc->rx.buf.ptr) -
31780@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
31781 }
31782 if (s & SERVICE_STREAM) {
31783 read_unlock(&vcc_sklist_lock);
31784- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
31785+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
31786 lvcc->stats.x.aal5.service_stream++;
31787 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
31788 "PDU on VCI %d!\n", lanai->number, vci);
31789@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
31790 return 0;
31791 }
31792 DPRINTK("got rx crc error on vci %d\n", vci);
31793- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
31794+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
31795 lvcc->stats.x.aal5.service_rxcrc++;
31796 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
31797 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
31798diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
31799index ed1d2b7..8cffc1f 100644
31800--- a/drivers/atm/nicstar.c
31801+++ b/drivers/atm/nicstar.c
31802@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
31803 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
31804 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
31805 card->index);
31806- atomic_inc(&vcc->stats->tx_err);
31807+ atomic_inc_unchecked(&vcc->stats->tx_err);
31808 dev_kfree_skb_any(skb);
31809 return -EINVAL;
31810 }
31811@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
31812 if (!vc->tx) {
31813 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
31814 card->index);
31815- atomic_inc(&vcc->stats->tx_err);
31816+ atomic_inc_unchecked(&vcc->stats->tx_err);
31817 dev_kfree_skb_any(skb);
31818 return -EINVAL;
31819 }
31820@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
31821 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
31822 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
31823 card->index);
31824- atomic_inc(&vcc->stats->tx_err);
31825+ atomic_inc_unchecked(&vcc->stats->tx_err);
31826 dev_kfree_skb_any(skb);
31827 return -EINVAL;
31828 }
31829
31830 if (skb_shinfo(skb)->nr_frags != 0) {
31831 printk("nicstar%d: No scatter-gather yet.\n", card->index);
31832- atomic_inc(&vcc->stats->tx_err);
31833+ atomic_inc_unchecked(&vcc->stats->tx_err);
31834 dev_kfree_skb_any(skb);
31835 return -EINVAL;
31836 }
31837@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
31838 }
31839
31840 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
31841- atomic_inc(&vcc->stats->tx_err);
31842+ atomic_inc_unchecked(&vcc->stats->tx_err);
31843 dev_kfree_skb_any(skb);
31844 return -EIO;
31845 }
31846- atomic_inc(&vcc->stats->tx);
31847+ atomic_inc_unchecked(&vcc->stats->tx);
31848
31849 return 0;
31850 }
31851@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31852 printk
31853 ("nicstar%d: Can't allocate buffers for aal0.\n",
31854 card->index);
31855- atomic_add(i, &vcc->stats->rx_drop);
31856+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
31857 break;
31858 }
31859 if (!atm_charge(vcc, sb->truesize)) {
31860 RXPRINTK
31861 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
31862 card->index);
31863- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
31864+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
31865 dev_kfree_skb_any(sb);
31866 break;
31867 }
31868@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31869 ATM_SKB(sb)->vcc = vcc;
31870 __net_timestamp(sb);
31871 vcc->push(vcc, sb);
31872- atomic_inc(&vcc->stats->rx);
31873+ atomic_inc_unchecked(&vcc->stats->rx);
31874 cell += ATM_CELL_PAYLOAD;
31875 }
31876
31877@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31878 if (iovb == NULL) {
31879 printk("nicstar%d: Out of iovec buffers.\n",
31880 card->index);
31881- atomic_inc(&vcc->stats->rx_drop);
31882+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31883 recycle_rx_buf(card, skb);
31884 return;
31885 }
31886@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31887 small or large buffer itself. */
31888 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
31889 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
31890- atomic_inc(&vcc->stats->rx_err);
31891+ atomic_inc_unchecked(&vcc->stats->rx_err);
31892 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
31893 NS_MAX_IOVECS);
31894 NS_PRV_IOVCNT(iovb) = 0;
31895@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31896 ("nicstar%d: Expected a small buffer, and this is not one.\n",
31897 card->index);
31898 which_list(card, skb);
31899- atomic_inc(&vcc->stats->rx_err);
31900+ atomic_inc_unchecked(&vcc->stats->rx_err);
31901 recycle_rx_buf(card, skb);
31902 vc->rx_iov = NULL;
31903 recycle_iov_buf(card, iovb);
31904@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31905 ("nicstar%d: Expected a large buffer, and this is not one.\n",
31906 card->index);
31907 which_list(card, skb);
31908- atomic_inc(&vcc->stats->rx_err);
31909+ atomic_inc_unchecked(&vcc->stats->rx_err);
31910 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
31911 NS_PRV_IOVCNT(iovb));
31912 vc->rx_iov = NULL;
31913@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31914 printk(" - PDU size mismatch.\n");
31915 else
31916 printk(".\n");
31917- atomic_inc(&vcc->stats->rx_err);
31918+ atomic_inc_unchecked(&vcc->stats->rx_err);
31919 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
31920 NS_PRV_IOVCNT(iovb));
31921 vc->rx_iov = NULL;
31922@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31923 /* skb points to a small buffer */
31924 if (!atm_charge(vcc, skb->truesize)) {
31925 push_rxbufs(card, skb);
31926- atomic_inc(&vcc->stats->rx_drop);
31927+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31928 } else {
31929 skb_put(skb, len);
31930 dequeue_sm_buf(card, skb);
31931@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31932 ATM_SKB(skb)->vcc = vcc;
31933 __net_timestamp(skb);
31934 vcc->push(vcc, skb);
31935- atomic_inc(&vcc->stats->rx);
31936+ atomic_inc_unchecked(&vcc->stats->rx);
31937 }
31938 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
31939 struct sk_buff *sb;
31940@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31941 if (len <= NS_SMBUFSIZE) {
31942 if (!atm_charge(vcc, sb->truesize)) {
31943 push_rxbufs(card, sb);
31944- atomic_inc(&vcc->stats->rx_drop);
31945+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31946 } else {
31947 skb_put(sb, len);
31948 dequeue_sm_buf(card, sb);
31949@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31950 ATM_SKB(sb)->vcc = vcc;
31951 __net_timestamp(sb);
31952 vcc->push(vcc, sb);
31953- atomic_inc(&vcc->stats->rx);
31954+ atomic_inc_unchecked(&vcc->stats->rx);
31955 }
31956
31957 push_rxbufs(card, skb);
31958@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31959
31960 if (!atm_charge(vcc, skb->truesize)) {
31961 push_rxbufs(card, skb);
31962- atomic_inc(&vcc->stats->rx_drop);
31963+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31964 } else {
31965 dequeue_lg_buf(card, skb);
31966 #ifdef NS_USE_DESTRUCTORS
31967@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31968 ATM_SKB(skb)->vcc = vcc;
31969 __net_timestamp(skb);
31970 vcc->push(vcc, skb);
31971- atomic_inc(&vcc->stats->rx);
31972+ atomic_inc_unchecked(&vcc->stats->rx);
31973 }
31974
31975 push_rxbufs(card, sb);
31976@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31977 printk
31978 ("nicstar%d: Out of huge buffers.\n",
31979 card->index);
31980- atomic_inc(&vcc->stats->rx_drop);
31981+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31982 recycle_iovec_rx_bufs(card,
31983 (struct iovec *)
31984 iovb->data,
31985@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31986 card->hbpool.count++;
31987 } else
31988 dev_kfree_skb_any(hb);
31989- atomic_inc(&vcc->stats->rx_drop);
31990+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31991 } else {
31992 /* Copy the small buffer to the huge buffer */
31993 sb = (struct sk_buff *)iov->iov_base;
31994@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31995 #endif /* NS_USE_DESTRUCTORS */
31996 __net_timestamp(hb);
31997 vcc->push(vcc, hb);
31998- atomic_inc(&vcc->stats->rx);
31999+ atomic_inc_unchecked(&vcc->stats->rx);
32000 }
32001 }
32002
32003diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
32004index 0474a89..06ea4a1 100644
32005--- a/drivers/atm/solos-pci.c
32006+++ b/drivers/atm/solos-pci.c
32007@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
32008 }
32009 atm_charge(vcc, skb->truesize);
32010 vcc->push(vcc, skb);
32011- atomic_inc(&vcc->stats->rx);
32012+ atomic_inc_unchecked(&vcc->stats->rx);
32013 break;
32014
32015 case PKT_STATUS:
32016@@ -1117,7 +1117,7 @@ static uint32_t fpga_tx(struct solos_card *card)
32017 vcc = SKB_CB(oldskb)->vcc;
32018
32019 if (vcc) {
32020- atomic_inc(&vcc->stats->tx);
32021+ atomic_inc_unchecked(&vcc->stats->tx);
32022 solos_pop(vcc, oldskb);
32023 } else {
32024 dev_kfree_skb_irq(oldskb);
32025diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
32026index 0215934..ce9f5b1 100644
32027--- a/drivers/atm/suni.c
32028+++ b/drivers/atm/suni.c
32029@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
32030
32031
32032 #define ADD_LIMITED(s,v) \
32033- atomic_add((v),&stats->s); \
32034- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
32035+ atomic_add_unchecked((v),&stats->s); \
32036+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
32037
32038
32039 static void suni_hz(unsigned long from_timer)
32040diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
32041index 5120a96..e2572bd 100644
32042--- a/drivers/atm/uPD98402.c
32043+++ b/drivers/atm/uPD98402.c
32044@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
32045 struct sonet_stats tmp;
32046 int error = 0;
32047
32048- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
32049+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
32050 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
32051 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
32052 if (zero && !error) {
32053@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
32054
32055
32056 #define ADD_LIMITED(s,v) \
32057- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
32058- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
32059- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
32060+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
32061+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
32062+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
32063
32064
32065 static void stat_event(struct atm_dev *dev)
32066@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
32067 if (reason & uPD98402_INT_PFM) stat_event(dev);
32068 if (reason & uPD98402_INT_PCO) {
32069 (void) GET(PCOCR); /* clear interrupt cause */
32070- atomic_add(GET(HECCT),
32071+ atomic_add_unchecked(GET(HECCT),
32072 &PRIV(dev)->sonet_stats.uncorr_hcs);
32073 }
32074 if ((reason & uPD98402_INT_RFO) &&
32075@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
32076 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
32077 uPD98402_INT_LOS),PIMR); /* enable them */
32078 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
32079- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
32080- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
32081- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
32082+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
32083+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
32084+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
32085 return 0;
32086 }
32087
32088diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
32089index 969c3c2..9b72956 100644
32090--- a/drivers/atm/zatm.c
32091+++ b/drivers/atm/zatm.c
32092@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
32093 }
32094 if (!size) {
32095 dev_kfree_skb_irq(skb);
32096- if (vcc) atomic_inc(&vcc->stats->rx_err);
32097+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
32098 continue;
32099 }
32100 if (!atm_charge(vcc,skb->truesize)) {
32101@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
32102 skb->len = size;
32103 ATM_SKB(skb)->vcc = vcc;
32104 vcc->push(vcc,skb);
32105- atomic_inc(&vcc->stats->rx);
32106+ atomic_inc_unchecked(&vcc->stats->rx);
32107 }
32108 zout(pos & 0xffff,MTA(mbx));
32109 #if 0 /* probably a stupid idea */
32110@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
32111 skb_queue_head(&zatm_vcc->backlog,skb);
32112 break;
32113 }
32114- atomic_inc(&vcc->stats->tx);
32115+ atomic_inc_unchecked(&vcc->stats->tx);
32116 wake_up(&zatm_vcc->tx_wait);
32117 }
32118
32119diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
32120index 17cf7ca..7e553e1 100644
32121--- a/drivers/base/devtmpfs.c
32122+++ b/drivers/base/devtmpfs.c
32123@@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
32124 if (!thread)
32125 return 0;
32126
32127- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
32128+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
32129 if (err)
32130 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
32131 else
32132diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
32133index e6ee5e8..98ad7fc 100644
32134--- a/drivers/base/power/wakeup.c
32135+++ b/drivers/base/power/wakeup.c
32136@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
32137 * They need to be modified together atomically, so it's better to use one
32138 * atomic variable to hold them both.
32139 */
32140-static atomic_t combined_event_count = ATOMIC_INIT(0);
32141+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
32142
32143 #define IN_PROGRESS_BITS (sizeof(int) * 4)
32144 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
32145
32146 static void split_counters(unsigned int *cnt, unsigned int *inpr)
32147 {
32148- unsigned int comb = atomic_read(&combined_event_count);
32149+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
32150
32151 *cnt = (comb >> IN_PROGRESS_BITS);
32152 *inpr = comb & MAX_IN_PROGRESS;
32153@@ -389,7 +389,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
32154 ws->start_prevent_time = ws->last_time;
32155
32156 /* Increment the counter of events in progress. */
32157- cec = atomic_inc_return(&combined_event_count);
32158+ cec = atomic_inc_return_unchecked(&combined_event_count);
32159
32160 trace_wakeup_source_activate(ws->name, cec);
32161 }
32162@@ -515,7 +515,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
32163 * Increment the counter of registered wakeup events and decrement the
32164 * couter of wakeup events in progress simultaneously.
32165 */
32166- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
32167+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
32168 trace_wakeup_source_deactivate(ws->name, cec);
32169
32170 split_counters(&cnt, &inpr);
32171diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
32172index ade58bc..867143d 100644
32173--- a/drivers/block/cciss.c
32174+++ b/drivers/block/cciss.c
32175@@ -1196,6 +1196,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
32176 int err;
32177 u32 cp;
32178
32179+ memset(&arg64, 0, sizeof(arg64));
32180+
32181 err = 0;
32182 err |=
32183 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
32184@@ -3005,7 +3007,7 @@ static void start_io(ctlr_info_t *h)
32185 while (!list_empty(&h->reqQ)) {
32186 c = list_entry(h->reqQ.next, CommandList_struct, list);
32187 /* can't do anything if fifo is full */
32188- if ((h->access.fifo_full(h))) {
32189+ if ((h->access->fifo_full(h))) {
32190 dev_warn(&h->pdev->dev, "fifo full\n");
32191 break;
32192 }
32193@@ -3015,7 +3017,7 @@ static void start_io(ctlr_info_t *h)
32194 h->Qdepth--;
32195
32196 /* Tell the controller execute command */
32197- h->access.submit_command(h, c);
32198+ h->access->submit_command(h, c);
32199
32200 /* Put job onto the completed Q */
32201 addQ(&h->cmpQ, c);
32202@@ -3441,17 +3443,17 @@ startio:
32203
32204 static inline unsigned long get_next_completion(ctlr_info_t *h)
32205 {
32206- return h->access.command_completed(h);
32207+ return h->access->command_completed(h);
32208 }
32209
32210 static inline int interrupt_pending(ctlr_info_t *h)
32211 {
32212- return h->access.intr_pending(h);
32213+ return h->access->intr_pending(h);
32214 }
32215
32216 static inline long interrupt_not_for_us(ctlr_info_t *h)
32217 {
32218- return ((h->access.intr_pending(h) == 0) ||
32219+ return ((h->access->intr_pending(h) == 0) ||
32220 (h->interrupts_enabled == 0));
32221 }
32222
32223@@ -3484,7 +3486,7 @@ static inline u32 next_command(ctlr_info_t *h)
32224 u32 a;
32225
32226 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
32227- return h->access.command_completed(h);
32228+ return h->access->command_completed(h);
32229
32230 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
32231 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
32232@@ -4041,7 +4043,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
32233 trans_support & CFGTBL_Trans_use_short_tags);
32234
32235 /* Change the access methods to the performant access methods */
32236- h->access = SA5_performant_access;
32237+ h->access = &SA5_performant_access;
32238 h->transMethod = CFGTBL_Trans_Performant;
32239
32240 return;
32241@@ -4310,7 +4312,7 @@ static int cciss_pci_init(ctlr_info_t *h)
32242 if (prod_index < 0)
32243 return -ENODEV;
32244 h->product_name = products[prod_index].product_name;
32245- h->access = *(products[prod_index].access);
32246+ h->access = products[prod_index].access;
32247
32248 if (cciss_board_disabled(h)) {
32249 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
32250@@ -5032,7 +5034,7 @@ reinit_after_soft_reset:
32251 }
32252
32253 /* make sure the board interrupts are off */
32254- h->access.set_intr_mask(h, CCISS_INTR_OFF);
32255+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
32256 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
32257 if (rc)
32258 goto clean2;
32259@@ -5082,7 +5084,7 @@ reinit_after_soft_reset:
32260 * fake ones to scoop up any residual completions.
32261 */
32262 spin_lock_irqsave(&h->lock, flags);
32263- h->access.set_intr_mask(h, CCISS_INTR_OFF);
32264+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
32265 spin_unlock_irqrestore(&h->lock, flags);
32266 free_irq(h->intr[h->intr_mode], h);
32267 rc = cciss_request_irq(h, cciss_msix_discard_completions,
32268@@ -5102,9 +5104,9 @@ reinit_after_soft_reset:
32269 dev_info(&h->pdev->dev, "Board READY.\n");
32270 dev_info(&h->pdev->dev,
32271 "Waiting for stale completions to drain.\n");
32272- h->access.set_intr_mask(h, CCISS_INTR_ON);
32273+ h->access->set_intr_mask(h, CCISS_INTR_ON);
32274 msleep(10000);
32275- h->access.set_intr_mask(h, CCISS_INTR_OFF);
32276+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
32277
32278 rc = controller_reset_failed(h->cfgtable);
32279 if (rc)
32280@@ -5127,7 +5129,7 @@ reinit_after_soft_reset:
32281 cciss_scsi_setup(h);
32282
32283 /* Turn the interrupts on so we can service requests */
32284- h->access.set_intr_mask(h, CCISS_INTR_ON);
32285+ h->access->set_intr_mask(h, CCISS_INTR_ON);
32286
32287 /* Get the firmware version */
32288 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
32289@@ -5199,7 +5201,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
32290 kfree(flush_buf);
32291 if (return_code != IO_OK)
32292 dev_warn(&h->pdev->dev, "Error flushing cache\n");
32293- h->access.set_intr_mask(h, CCISS_INTR_OFF);
32294+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
32295 free_irq(h->intr[h->intr_mode], h);
32296 }
32297
32298diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
32299index 7fda30e..eb5dfe0 100644
32300--- a/drivers/block/cciss.h
32301+++ b/drivers/block/cciss.h
32302@@ -101,7 +101,7 @@ struct ctlr_info
32303 /* information about each logical volume */
32304 drive_info_struct *drv[CISS_MAX_LUN];
32305
32306- struct access_method access;
32307+ struct access_method *access;
32308
32309 /* queue and queue Info */
32310 struct list_head reqQ;
32311diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
32312index 3f08713..56a586a 100644
32313--- a/drivers/block/cpqarray.c
32314+++ b/drivers/block/cpqarray.c
32315@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
32316 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
32317 goto Enomem4;
32318 }
32319- hba[i]->access.set_intr_mask(hba[i], 0);
32320+ hba[i]->access->set_intr_mask(hba[i], 0);
32321 if (request_irq(hba[i]->intr, do_ida_intr,
32322 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
32323 {
32324@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
32325 add_timer(&hba[i]->timer);
32326
32327 /* Enable IRQ now that spinlock and rate limit timer are set up */
32328- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
32329+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
32330
32331 for(j=0; j<NWD; j++) {
32332 struct gendisk *disk = ida_gendisk[i][j];
32333@@ -694,7 +694,7 @@ DBGINFO(
32334 for(i=0; i<NR_PRODUCTS; i++) {
32335 if (board_id == products[i].board_id) {
32336 c->product_name = products[i].product_name;
32337- c->access = *(products[i].access);
32338+ c->access = products[i].access;
32339 break;
32340 }
32341 }
32342@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
32343 hba[ctlr]->intr = intr;
32344 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
32345 hba[ctlr]->product_name = products[j].product_name;
32346- hba[ctlr]->access = *(products[j].access);
32347+ hba[ctlr]->access = products[j].access;
32348 hba[ctlr]->ctlr = ctlr;
32349 hba[ctlr]->board_id = board_id;
32350 hba[ctlr]->pci_dev = NULL; /* not PCI */
32351@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
32352
32353 while((c = h->reqQ) != NULL) {
32354 /* Can't do anything if we're busy */
32355- if (h->access.fifo_full(h) == 0)
32356+ if (h->access->fifo_full(h) == 0)
32357 return;
32358
32359 /* Get the first entry from the request Q */
32360@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
32361 h->Qdepth--;
32362
32363 /* Tell the controller to do our bidding */
32364- h->access.submit_command(h, c);
32365+ h->access->submit_command(h, c);
32366
32367 /* Get onto the completion Q */
32368 addQ(&h->cmpQ, c);
32369@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
32370 unsigned long flags;
32371 __u32 a,a1;
32372
32373- istat = h->access.intr_pending(h);
32374+ istat = h->access->intr_pending(h);
32375 /* Is this interrupt for us? */
32376 if (istat == 0)
32377 return IRQ_NONE;
32378@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
32379 */
32380 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
32381 if (istat & FIFO_NOT_EMPTY) {
32382- while((a = h->access.command_completed(h))) {
32383+ while((a = h->access->command_completed(h))) {
32384 a1 = a; a &= ~3;
32385 if ((c = h->cmpQ) == NULL)
32386 {
32387@@ -1449,11 +1449,11 @@ static int sendcmd(
32388 /*
32389 * Disable interrupt
32390 */
32391- info_p->access.set_intr_mask(info_p, 0);
32392+ info_p->access->set_intr_mask(info_p, 0);
32393 /* Make sure there is room in the command FIFO */
32394 /* Actually it should be completely empty at this time. */
32395 for (i = 200000; i > 0; i--) {
32396- temp = info_p->access.fifo_full(info_p);
32397+ temp = info_p->access->fifo_full(info_p);
32398 if (temp != 0) {
32399 break;
32400 }
32401@@ -1466,7 +1466,7 @@ DBG(
32402 /*
32403 * Send the cmd
32404 */
32405- info_p->access.submit_command(info_p, c);
32406+ info_p->access->submit_command(info_p, c);
32407 complete = pollcomplete(ctlr);
32408
32409 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
32410@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
32411 * we check the new geometry. Then turn interrupts back on when
32412 * we're done.
32413 */
32414- host->access.set_intr_mask(host, 0);
32415+ host->access->set_intr_mask(host, 0);
32416 getgeometry(ctlr);
32417- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
32418+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
32419
32420 for(i=0; i<NWD; i++) {
32421 struct gendisk *disk = ida_gendisk[ctlr][i];
32422@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
32423 /* Wait (up to 2 seconds) for a command to complete */
32424
32425 for (i = 200000; i > 0; i--) {
32426- done = hba[ctlr]->access.command_completed(hba[ctlr]);
32427+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
32428 if (done == 0) {
32429 udelay(10); /* a short fixed delay */
32430 } else
32431diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
32432index be73e9d..7fbf140 100644
32433--- a/drivers/block/cpqarray.h
32434+++ b/drivers/block/cpqarray.h
32435@@ -99,7 +99,7 @@ struct ctlr_info {
32436 drv_info_t drv[NWD];
32437 struct proc_dir_entry *proc;
32438
32439- struct access_method access;
32440+ struct access_method *access;
32441
32442 cmdlist_t *reqQ;
32443 cmdlist_t *cmpQ;
32444diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
32445index 6b51afa..17e1191 100644
32446--- a/drivers/block/drbd/drbd_int.h
32447+++ b/drivers/block/drbd/drbd_int.h
32448@@ -582,7 +582,7 @@ struct drbd_epoch {
32449 struct drbd_tconn *tconn;
32450 struct list_head list;
32451 unsigned int barrier_nr;
32452- atomic_t epoch_size; /* increased on every request added. */
32453+ atomic_unchecked_t epoch_size; /* increased on every request added. */
32454 atomic_t active; /* increased on every req. added, and dec on every finished. */
32455 unsigned long flags;
32456 };
32457@@ -1011,7 +1011,7 @@ struct drbd_conf {
32458 int al_tr_cycle;
32459 int al_tr_pos; /* position of the next transaction in the journal */
32460 wait_queue_head_t seq_wait;
32461- atomic_t packet_seq;
32462+ atomic_unchecked_t packet_seq;
32463 unsigned int peer_seq;
32464 spinlock_t peer_seq_lock;
32465 unsigned int minor;
32466@@ -1527,7 +1527,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
32467 char __user *uoptval;
32468 int err;
32469
32470- uoptval = (char __user __force *)optval;
32471+ uoptval = (char __force_user *)optval;
32472
32473 set_fs(KERNEL_DS);
32474 if (level == SOL_SOCKET)
32475diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
32476index 8c13eeb..217adee 100644
32477--- a/drivers/block/drbd/drbd_main.c
32478+++ b/drivers/block/drbd/drbd_main.c
32479@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
32480 p->sector = sector;
32481 p->block_id = block_id;
32482 p->blksize = blksize;
32483- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
32484+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
32485 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
32486 }
32487
32488@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
32489 return -EIO;
32490 p->sector = cpu_to_be64(req->i.sector);
32491 p->block_id = (unsigned long)req;
32492- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
32493+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
32494 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
32495 if (mdev->state.conn >= C_SYNC_SOURCE &&
32496 mdev->state.conn <= C_PAUSED_SYNC_T)
32497@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
32498 {
32499 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
32500
32501- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
32502- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
32503+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
32504+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
32505 kfree(tconn->current_epoch);
32506
32507 idr_destroy(&tconn->volumes);
32508diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
32509index a9eccfc..68e4533 100644
32510--- a/drivers/block/drbd/drbd_receiver.c
32511+++ b/drivers/block/drbd/drbd_receiver.c
32512@@ -833,7 +833,7 @@ int drbd_connected(struct drbd_conf *mdev)
32513 {
32514 int err;
32515
32516- atomic_set(&mdev->packet_seq, 0);
32517+ atomic_set_unchecked(&mdev->packet_seq, 0);
32518 mdev->peer_seq = 0;
32519
32520 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
32521@@ -1191,7 +1191,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
32522 do {
32523 next_epoch = NULL;
32524
32525- epoch_size = atomic_read(&epoch->epoch_size);
32526+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
32527
32528 switch (ev & ~EV_CLEANUP) {
32529 case EV_PUT:
32530@@ -1231,7 +1231,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
32531 rv = FE_DESTROYED;
32532 } else {
32533 epoch->flags = 0;
32534- atomic_set(&epoch->epoch_size, 0);
32535+ atomic_set_unchecked(&epoch->epoch_size, 0);
32536 /* atomic_set(&epoch->active, 0); is already zero */
32537 if (rv == FE_STILL_LIVE)
32538 rv = FE_RECYCLED;
32539@@ -1449,7 +1449,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
32540 conn_wait_active_ee_empty(tconn);
32541 drbd_flush(tconn);
32542
32543- if (atomic_read(&tconn->current_epoch->epoch_size)) {
32544+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
32545 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
32546 if (epoch)
32547 break;
32548@@ -1462,11 +1462,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
32549 }
32550
32551 epoch->flags = 0;
32552- atomic_set(&epoch->epoch_size, 0);
32553+ atomic_set_unchecked(&epoch->epoch_size, 0);
32554 atomic_set(&epoch->active, 0);
32555
32556 spin_lock(&tconn->epoch_lock);
32557- if (atomic_read(&tconn->current_epoch->epoch_size)) {
32558+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
32559 list_add(&epoch->list, &tconn->current_epoch->list);
32560 tconn->current_epoch = epoch;
32561 tconn->epochs++;
32562@@ -2170,7 +2170,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
32563
32564 err = wait_for_and_update_peer_seq(mdev, peer_seq);
32565 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
32566- atomic_inc(&tconn->current_epoch->epoch_size);
32567+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
32568 err2 = drbd_drain_block(mdev, pi->size);
32569 if (!err)
32570 err = err2;
32571@@ -2204,7 +2204,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
32572
32573 spin_lock(&tconn->epoch_lock);
32574 peer_req->epoch = tconn->current_epoch;
32575- atomic_inc(&peer_req->epoch->epoch_size);
32576+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
32577 atomic_inc(&peer_req->epoch->active);
32578 spin_unlock(&tconn->epoch_lock);
32579
32580@@ -4466,7 +4466,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
32581 if (!list_empty(&tconn->current_epoch->list))
32582 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
32583 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
32584- atomic_set(&tconn->current_epoch->epoch_size, 0);
32585+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
32586 tconn->send.seen_any_write_yet = false;
32587
32588 conn_info(tconn, "Connection closed\n");
32589diff --git a/drivers/block/loop.c b/drivers/block/loop.c
32590index ae12512..37fa397 100644
32591--- a/drivers/block/loop.c
32592+++ b/drivers/block/loop.c
32593@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
32594 mm_segment_t old_fs = get_fs();
32595
32596 set_fs(get_ds());
32597- bw = file->f_op->write(file, buf, len, &pos);
32598+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
32599 set_fs(old_fs);
32600 if (likely(bw == len))
32601 return 0;
32602diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
32603index d620b44..587561e 100644
32604--- a/drivers/cdrom/cdrom.c
32605+++ b/drivers/cdrom/cdrom.c
32606@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
32607 ENSURE(reset, CDC_RESET);
32608 ENSURE(generic_packet, CDC_GENERIC_PACKET);
32609 cdi->mc_flags = 0;
32610- cdo->n_minors = 0;
32611 cdi->options = CDO_USE_FFLAGS;
32612
32613 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
32614@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
32615 else
32616 cdi->cdda_method = CDDA_OLD;
32617
32618- if (!cdo->generic_packet)
32619- cdo->generic_packet = cdrom_dummy_generic_packet;
32620+ if (!cdo->generic_packet) {
32621+ pax_open_kernel();
32622+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
32623+ pax_close_kernel();
32624+ }
32625
32626 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
32627 mutex_lock(&cdrom_mutex);
32628@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
32629 if (cdi->exit)
32630 cdi->exit(cdi);
32631
32632- cdi->ops->n_minors--;
32633 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
32634 }
32635
32636diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
32637index d59cdcb..11afddf 100644
32638--- a/drivers/cdrom/gdrom.c
32639+++ b/drivers/cdrom/gdrom.c
32640@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
32641 .audio_ioctl = gdrom_audio_ioctl,
32642 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
32643 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
32644- .n_minors = 1,
32645 };
32646
32647 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
32648diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
32649index 72bedad..8181ce1 100644
32650--- a/drivers/char/Kconfig
32651+++ b/drivers/char/Kconfig
32652@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
32653
32654 config DEVKMEM
32655 bool "/dev/kmem virtual device support"
32656- default y
32657+ default n
32658+ depends on !GRKERNSEC_KMEM
32659 help
32660 Say Y here if you want to support the /dev/kmem device. The
32661 /dev/kmem device is rarely used, but can be used for certain
32662@@ -581,6 +582,7 @@ config DEVPORT
32663 bool
32664 depends on !M68K
32665 depends on ISA || PCI
32666+ depends on !GRKERNSEC_KMEM
32667 default y
32668
32669 source "drivers/s390/char/Kconfig"
32670diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
32671index 2e04433..22afc64 100644
32672--- a/drivers/char/agp/frontend.c
32673+++ b/drivers/char/agp/frontend.c
32674@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
32675 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
32676 return -EFAULT;
32677
32678- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
32679+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
32680 return -EFAULT;
32681
32682 client = agp_find_client_by_pid(reserve.pid);
32683diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
32684index 21cb980..f15107c 100644
32685--- a/drivers/char/genrtc.c
32686+++ b/drivers/char/genrtc.c
32687@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
32688 switch (cmd) {
32689
32690 case RTC_PLL_GET:
32691+ memset(&pll, 0, sizeof(pll));
32692 if (get_rtc_pll(&pll))
32693 return -EINVAL;
32694 else
32695diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
32696index fe6d4be..89f32100 100644
32697--- a/drivers/char/hpet.c
32698+++ b/drivers/char/hpet.c
32699@@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
32700 }
32701
32702 static int
32703-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
32704+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
32705 struct hpet_info *info)
32706 {
32707 struct hpet_timer __iomem *timer;
32708diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
32709index 053201b0..8335cce 100644
32710--- a/drivers/char/ipmi/ipmi_msghandler.c
32711+++ b/drivers/char/ipmi/ipmi_msghandler.c
32712@@ -420,7 +420,7 @@ struct ipmi_smi {
32713 struct proc_dir_entry *proc_dir;
32714 char proc_dir_name[10];
32715
32716- atomic_t stats[IPMI_NUM_STATS];
32717+ atomic_unchecked_t stats[IPMI_NUM_STATS];
32718
32719 /*
32720 * run_to_completion duplicate of smb_info, smi_info
32721@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
32722
32723
32724 #define ipmi_inc_stat(intf, stat) \
32725- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
32726+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
32727 #define ipmi_get_stat(intf, stat) \
32728- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
32729+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
32730
32731 static int is_lan_addr(struct ipmi_addr *addr)
32732 {
32733@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
32734 INIT_LIST_HEAD(&intf->cmd_rcvrs);
32735 init_waitqueue_head(&intf->waitq);
32736 for (i = 0; i < IPMI_NUM_STATS; i++)
32737- atomic_set(&intf->stats[i], 0);
32738+ atomic_set_unchecked(&intf->stats[i], 0);
32739
32740 intf->proc_dir = NULL;
32741
32742diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
32743index 1c7fdcd..4899100 100644
32744--- a/drivers/char/ipmi/ipmi_si_intf.c
32745+++ b/drivers/char/ipmi/ipmi_si_intf.c
32746@@ -275,7 +275,7 @@ struct smi_info {
32747 unsigned char slave_addr;
32748
32749 /* Counters and things for the proc filesystem. */
32750- atomic_t stats[SI_NUM_STATS];
32751+ atomic_unchecked_t stats[SI_NUM_STATS];
32752
32753 struct task_struct *thread;
32754
32755@@ -284,9 +284,9 @@ struct smi_info {
32756 };
32757
32758 #define smi_inc_stat(smi, stat) \
32759- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
32760+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
32761 #define smi_get_stat(smi, stat) \
32762- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
32763+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
32764
32765 #define SI_MAX_PARMS 4
32766
32767@@ -3225,7 +3225,7 @@ static int try_smi_init(struct smi_info *new_smi)
32768 atomic_set(&new_smi->req_events, 0);
32769 new_smi->run_to_completion = 0;
32770 for (i = 0; i < SI_NUM_STATS; i++)
32771- atomic_set(&new_smi->stats[i], 0);
32772+ atomic_set_unchecked(&new_smi->stats[i], 0);
32773
32774 new_smi->interrupt_disabled = 1;
32775 atomic_set(&new_smi->stop_operation, 0);
32776diff --git a/drivers/char/mem.c b/drivers/char/mem.c
32777index c6fa3bc..4ca3e42 100644
32778--- a/drivers/char/mem.c
32779+++ b/drivers/char/mem.c
32780@@ -18,6 +18,7 @@
32781 #include <linux/raw.h>
32782 #include <linux/tty.h>
32783 #include <linux/capability.h>
32784+#include <linux/security.h>
32785 #include <linux/ptrace.h>
32786 #include <linux/device.h>
32787 #include <linux/highmem.h>
32788@@ -37,6 +38,10 @@
32789
32790 #define DEVPORT_MINOR 4
32791
32792+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
32793+extern const struct file_operations grsec_fops;
32794+#endif
32795+
32796 static inline unsigned long size_inside_page(unsigned long start,
32797 unsigned long size)
32798 {
32799@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
32800
32801 while (cursor < to) {
32802 if (!devmem_is_allowed(pfn)) {
32803+#ifdef CONFIG_GRKERNSEC_KMEM
32804+ gr_handle_mem_readwrite(from, to);
32805+#else
32806 printk(KERN_INFO
32807 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
32808 current->comm, from, to);
32809+#endif
32810 return 0;
32811 }
32812 cursor += PAGE_SIZE;
32813@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
32814 }
32815 return 1;
32816 }
32817+#elif defined(CONFIG_GRKERNSEC_KMEM)
32818+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
32819+{
32820+ return 0;
32821+}
32822 #else
32823 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
32824 {
32825@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
32826
32827 while (count > 0) {
32828 unsigned long remaining;
32829+ char *temp;
32830
32831 sz = size_inside_page(p, count);
32832
32833@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
32834 if (!ptr)
32835 return -EFAULT;
32836
32837- remaining = copy_to_user(buf, ptr, sz);
32838+#ifdef CONFIG_PAX_USERCOPY
32839+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
32840+ if (!temp) {
32841+ unxlate_dev_mem_ptr(p, ptr);
32842+ return -ENOMEM;
32843+ }
32844+ memcpy(temp, ptr, sz);
32845+#else
32846+ temp = ptr;
32847+#endif
32848+
32849+ remaining = copy_to_user(buf, temp, sz);
32850+
32851+#ifdef CONFIG_PAX_USERCOPY
32852+ kfree(temp);
32853+#endif
32854+
32855 unxlate_dev_mem_ptr(p, ptr);
32856 if (remaining)
32857 return -EFAULT;
32858@@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
32859 size_t count, loff_t *ppos)
32860 {
32861 unsigned long p = *ppos;
32862- ssize_t low_count, read, sz;
32863+ ssize_t low_count, read, sz, err = 0;
32864 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
32865- int err = 0;
32866
32867 read = 0;
32868 if (p < (unsigned long) high_memory) {
32869@@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
32870 }
32871 #endif
32872 while (low_count > 0) {
32873+ char *temp;
32874+
32875 sz = size_inside_page(p, low_count);
32876
32877 /*
32878@@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
32879 */
32880 kbuf = xlate_dev_kmem_ptr((char *)p);
32881
32882- if (copy_to_user(buf, kbuf, sz))
32883+#ifdef CONFIG_PAX_USERCOPY
32884+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
32885+ if (!temp)
32886+ return -ENOMEM;
32887+ memcpy(temp, kbuf, sz);
32888+#else
32889+ temp = kbuf;
32890+#endif
32891+
32892+ err = copy_to_user(buf, temp, sz);
32893+
32894+#ifdef CONFIG_PAX_USERCOPY
32895+ kfree(temp);
32896+#endif
32897+
32898+ if (err)
32899 return -EFAULT;
32900 buf += sz;
32901 p += sz;
32902@@ -833,6 +880,9 @@ static const struct memdev {
32903 #ifdef CONFIG_CRASH_DUMP
32904 [12] = { "oldmem", 0, &oldmem_fops, NULL },
32905 #endif
32906+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
32907+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
32908+#endif
32909 };
32910
32911 static int memory_open(struct inode *inode, struct file *filp)
32912diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
32913index 9df78e2..01ba9ae 100644
32914--- a/drivers/char/nvram.c
32915+++ b/drivers/char/nvram.c
32916@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
32917
32918 spin_unlock_irq(&rtc_lock);
32919
32920- if (copy_to_user(buf, contents, tmp - contents))
32921+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
32922 return -EFAULT;
32923
32924 *ppos = i;
32925diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
32926index b66eaa0..2619d1b 100644
32927--- a/drivers/char/pcmcia/synclink_cs.c
32928+++ b/drivers/char/pcmcia/synclink_cs.c
32929@@ -2348,9 +2348,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
32930
32931 if (debug_level >= DEBUG_LEVEL_INFO)
32932 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
32933- __FILE__,__LINE__, info->device_name, port->count);
32934+ __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
32935
32936- WARN_ON(!port->count);
32937+ WARN_ON(!atomic_read(&port->count));
32938
32939 if (tty_port_close_start(port, tty, filp) == 0)
32940 goto cleanup;
32941@@ -2368,7 +2368,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
32942 cleanup:
32943 if (debug_level >= DEBUG_LEVEL_INFO)
32944 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
32945- tty->driver->name, port->count);
32946+ tty->driver->name, atomic_read(&port->count));
32947 }
32948
32949 /* Wait until the transmitter is empty.
32950@@ -2510,7 +2510,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
32951
32952 if (debug_level >= DEBUG_LEVEL_INFO)
32953 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
32954- __FILE__,__LINE__,tty->driver->name, port->count);
32955+ __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
32956
32957 /* If port is closing, signal caller to try again */
32958 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
32959@@ -2530,11 +2530,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
32960 goto cleanup;
32961 }
32962 spin_lock(&port->lock);
32963- port->count++;
32964+ atomic_inc(&port->count);
32965 spin_unlock(&port->lock);
32966 spin_unlock_irqrestore(&info->netlock, flags);
32967
32968- if (port->count == 1) {
32969+ if (atomic_read(&port->count) == 1) {
32970 /* 1st open on this device, init hardware */
32971 retval = startup(info, tty);
32972 if (retval < 0)
32973@@ -3889,7 +3889,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
32974 unsigned short new_crctype;
32975
32976 /* return error if TTY interface open */
32977- if (info->port.count)
32978+ if (atomic_read(&info->port.count))
32979 return -EBUSY;
32980
32981 switch (encoding)
32982@@ -3992,7 +3992,7 @@ static int hdlcdev_open(struct net_device *dev)
32983
32984 /* arbitrate between network and tty opens */
32985 spin_lock_irqsave(&info->netlock, flags);
32986- if (info->port.count != 0 || info->netcount != 0) {
32987+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
32988 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
32989 spin_unlock_irqrestore(&info->netlock, flags);
32990 return -EBUSY;
32991@@ -4081,7 +4081,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
32992 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
32993
32994 /* return error if TTY interface open */
32995- if (info->port.count)
32996+ if (atomic_read(&info->port.count))
32997 return -EBUSY;
32998
32999 if (cmd != SIOCWANDEV)
33000diff --git a/drivers/char/random.c b/drivers/char/random.c
33001index 85e81ec..bce8b97 100644
33002--- a/drivers/char/random.c
33003+++ b/drivers/char/random.c
33004@@ -272,8 +272,13 @@
33005 /*
33006 * Configuration information
33007 */
33008+#ifdef CONFIG_GRKERNSEC_RANDNET
33009+#define INPUT_POOL_WORDS 512
33010+#define OUTPUT_POOL_WORDS 128
33011+#else
33012 #define INPUT_POOL_WORDS 128
33013 #define OUTPUT_POOL_WORDS 32
33014+#endif
33015 #define SEC_XFER_SIZE 512
33016 #define EXTRACT_SIZE 10
33017
33018@@ -313,10 +318,17 @@ static struct poolinfo {
33019 int poolwords;
33020 int tap1, tap2, tap3, tap4, tap5;
33021 } poolinfo_table[] = {
33022+#ifdef CONFIG_GRKERNSEC_RANDNET
33023+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
33024+ { 512, 411, 308, 208, 104, 1 },
33025+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
33026+ { 128, 103, 76, 51, 25, 1 },
33027+#else
33028 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
33029 { 128, 103, 76, 51, 25, 1 },
33030 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
33031 { 32, 26, 20, 14, 7, 1 },
33032+#endif
33033 #if 0
33034 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
33035 { 2048, 1638, 1231, 819, 411, 1 },
33036@@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
33037 input_rotate += i ? 7 : 14;
33038 }
33039
33040- ACCESS_ONCE(r->input_rotate) = input_rotate;
33041- ACCESS_ONCE(r->add_ptr) = i;
33042+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
33043+ ACCESS_ONCE_RW(r->add_ptr) = i;
33044 smp_wmb();
33045
33046 if (out)
33047@@ -1020,7 +1032,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
33048
33049 extract_buf(r, tmp);
33050 i = min_t(int, nbytes, EXTRACT_SIZE);
33051- if (copy_to_user(buf, tmp, i)) {
33052+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
33053 ret = -EFAULT;
33054 break;
33055 }
33056@@ -1356,7 +1368,7 @@ EXPORT_SYMBOL(generate_random_uuid);
33057 #include <linux/sysctl.h>
33058
33059 static int min_read_thresh = 8, min_write_thresh;
33060-static int max_read_thresh = INPUT_POOL_WORDS * 32;
33061+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
33062 static int max_write_thresh = INPUT_POOL_WORDS * 32;
33063 static char sysctl_bootid[16];
33064
33065diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
33066index d780295..b29f3a8 100644
33067--- a/drivers/char/sonypi.c
33068+++ b/drivers/char/sonypi.c
33069@@ -54,6 +54,7 @@
33070
33071 #include <asm/uaccess.h>
33072 #include <asm/io.h>
33073+#include <asm/local.h>
33074
33075 #include <linux/sonypi.h>
33076
33077@@ -490,7 +491,7 @@ static struct sonypi_device {
33078 spinlock_t fifo_lock;
33079 wait_queue_head_t fifo_proc_list;
33080 struct fasync_struct *fifo_async;
33081- int open_count;
33082+ local_t open_count;
33083 int model;
33084 struct input_dev *input_jog_dev;
33085 struct input_dev *input_key_dev;
33086@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
33087 static int sonypi_misc_release(struct inode *inode, struct file *file)
33088 {
33089 mutex_lock(&sonypi_device.lock);
33090- sonypi_device.open_count--;
33091+ local_dec(&sonypi_device.open_count);
33092 mutex_unlock(&sonypi_device.lock);
33093 return 0;
33094 }
33095@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
33096 {
33097 mutex_lock(&sonypi_device.lock);
33098 /* Flush input queue on first open */
33099- if (!sonypi_device.open_count)
33100+ if (!local_read(&sonypi_device.open_count))
33101 kfifo_reset(&sonypi_device.fifo);
33102- sonypi_device.open_count++;
33103+ local_inc(&sonypi_device.open_count);
33104 mutex_unlock(&sonypi_device.lock);
33105
33106 return 0;
33107diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
33108index 93211df..c7805f7 100644
33109--- a/drivers/char/tpm/tpm.c
33110+++ b/drivers/char/tpm/tpm.c
33111@@ -410,7 +410,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
33112 chip->vendor.req_complete_val)
33113 goto out_recv;
33114
33115- if ((status == chip->vendor.req_canceled)) {
33116+ if (status == chip->vendor.req_canceled) {
33117 dev_err(chip->dev, "Operation Canceled\n");
33118 rc = -ECANCELED;
33119 goto out;
33120diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
33121index 56051d0..11cf3b7 100644
33122--- a/drivers/char/tpm/tpm_acpi.c
33123+++ b/drivers/char/tpm/tpm_acpi.c
33124@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
33125 virt = acpi_os_map_memory(start, len);
33126 if (!virt) {
33127 kfree(log->bios_event_log);
33128+ log->bios_event_log = NULL;
33129 printk("%s: ERROR - Unable to map memory\n", __func__);
33130 return -EIO;
33131 }
33132
33133- memcpy_fromio(log->bios_event_log, virt, len);
33134+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
33135
33136 acpi_os_unmap_memory(virt, len);
33137 return 0;
33138diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
33139index 84ddc55..1d32f1e 100644
33140--- a/drivers/char/tpm/tpm_eventlog.c
33141+++ b/drivers/char/tpm/tpm_eventlog.c
33142@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
33143 event = addr;
33144
33145 if ((event->event_type == 0 && event->event_size == 0) ||
33146- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
33147+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
33148 return NULL;
33149
33150 return addr;
33151@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
33152 return NULL;
33153
33154 if ((event->event_type == 0 && event->event_size == 0) ||
33155- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
33156+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
33157 return NULL;
33158
33159 (*pos)++;
33160@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
33161 int i;
33162
33163 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
33164- seq_putc(m, data[i]);
33165+ if (!seq_putc(m, data[i]))
33166+ return -EFAULT;
33167
33168 return 0;
33169 }
33170diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
33171index ee4dbea..69c817b 100644
33172--- a/drivers/char/virtio_console.c
33173+++ b/drivers/char/virtio_console.c
33174@@ -681,7 +681,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
33175 if (to_user) {
33176 ssize_t ret;
33177
33178- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
33179+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
33180 if (ret)
33181 return -EFAULT;
33182 } else {
33183@@ -780,7 +780,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
33184 if (!port_has_data(port) && !port->host_connected)
33185 return 0;
33186
33187- return fill_readbuf(port, ubuf, count, true);
33188+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
33189 }
33190
33191 static int wait_port_writable(struct port *port, bool nonblock)
33192diff --git a/drivers/clocksource/arm_generic.c b/drivers/clocksource/arm_generic.c
33193index 8ae1a61..9c00613 100644
33194--- a/drivers/clocksource/arm_generic.c
33195+++ b/drivers/clocksource/arm_generic.c
33196@@ -181,7 +181,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
33197 return NOTIFY_OK;
33198 }
33199
33200-static struct notifier_block __cpuinitdata arch_timer_cpu_nb = {
33201+static struct notifier_block arch_timer_cpu_nb = {
33202 .notifier_call = arch_timer_cpu_notify,
33203 };
33204
33205diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
33206index 1f93dbd..edf95ff 100644
33207--- a/drivers/cpufreq/cpufreq.c
33208+++ b/drivers/cpufreq/cpufreq.c
33209@@ -1843,7 +1843,7 @@ static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb,
33210 return NOTIFY_OK;
33211 }
33212
33213-static struct notifier_block __refdata cpufreq_cpu_notifier = {
33214+static struct notifier_block cpufreq_cpu_notifier = {
33215 .notifier_call = cpufreq_cpu_callback,
33216 };
33217
33218diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
33219index 9d7732b..0b1a793 100644
33220--- a/drivers/cpufreq/cpufreq_stats.c
33221+++ b/drivers/cpufreq/cpufreq_stats.c
33222@@ -340,7 +340,7 @@ static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
33223 }
33224
33225 /* priority=1 so this will get called before cpufreq_remove_dev */
33226-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
33227+static struct notifier_block cpufreq_stat_cpu_notifier = {
33228 .notifier_call = cpufreq_stat_cpu_callback,
33229 .priority = 1,
33230 };
33231diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
33232index b70709b..1d8d02a 100644
33233--- a/drivers/dma/sh/shdma.c
33234+++ b/drivers/dma/sh/shdma.c
33235@@ -476,7 +476,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
33236 return ret;
33237 }
33238
33239-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
33240+static struct notifier_block sh_dmae_nmi_notifier = {
33241 .notifier_call = sh_dmae_nmi_handler,
33242
33243 /* Run before NMI debug handler and KGDB */
33244diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
33245index 0056c4d..725934f 100644
33246--- a/drivers/edac/edac_pci_sysfs.c
33247+++ b/drivers/edac/edac_pci_sysfs.c
33248@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
33249 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
33250 static int edac_pci_poll_msec = 1000; /* one second workq period */
33251
33252-static atomic_t pci_parity_count = ATOMIC_INIT(0);
33253-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
33254+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
33255+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
33256
33257 static struct kobject *edac_pci_top_main_kobj;
33258 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
33259@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33260 edac_printk(KERN_CRIT, EDAC_PCI,
33261 "Signaled System Error on %s\n",
33262 pci_name(dev));
33263- atomic_inc(&pci_nonparity_count);
33264+ atomic_inc_unchecked(&pci_nonparity_count);
33265 }
33266
33267 if (status & (PCI_STATUS_PARITY)) {
33268@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33269 "Master Data Parity Error on %s\n",
33270 pci_name(dev));
33271
33272- atomic_inc(&pci_parity_count);
33273+ atomic_inc_unchecked(&pci_parity_count);
33274 }
33275
33276 if (status & (PCI_STATUS_DETECTED_PARITY)) {
33277@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33278 "Detected Parity Error on %s\n",
33279 pci_name(dev));
33280
33281- atomic_inc(&pci_parity_count);
33282+ atomic_inc_unchecked(&pci_parity_count);
33283 }
33284 }
33285
33286@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33287 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
33288 "Signaled System Error on %s\n",
33289 pci_name(dev));
33290- atomic_inc(&pci_nonparity_count);
33291+ atomic_inc_unchecked(&pci_nonparity_count);
33292 }
33293
33294 if (status & (PCI_STATUS_PARITY)) {
33295@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33296 "Master Data Parity Error on "
33297 "%s\n", pci_name(dev));
33298
33299- atomic_inc(&pci_parity_count);
33300+ atomic_inc_unchecked(&pci_parity_count);
33301 }
33302
33303 if (status & (PCI_STATUS_DETECTED_PARITY)) {
33304@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33305 "Detected Parity Error on %s\n",
33306 pci_name(dev));
33307
33308- atomic_inc(&pci_parity_count);
33309+ atomic_inc_unchecked(&pci_parity_count);
33310 }
33311 }
33312 }
33313@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
33314 if (!check_pci_errors)
33315 return;
33316
33317- before_count = atomic_read(&pci_parity_count);
33318+ before_count = atomic_read_unchecked(&pci_parity_count);
33319
33320 /* scan all PCI devices looking for a Parity Error on devices and
33321 * bridges.
33322@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
33323 /* Only if operator has selected panic on PCI Error */
33324 if (edac_pci_get_panic_on_pe()) {
33325 /* If the count is different 'after' from 'before' */
33326- if (before_count != atomic_read(&pci_parity_count))
33327+ if (before_count != atomic_read_unchecked(&pci_parity_count))
33328 panic("EDAC: PCI Parity Error");
33329 }
33330 }
33331diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
33332index 6796799..99e8377 100644
33333--- a/drivers/edac/mce_amd.h
33334+++ b/drivers/edac/mce_amd.h
33335@@ -78,7 +78,7 @@ extern const char * const ii_msgs[];
33336 struct amd_decoder_ops {
33337 bool (*mc0_mce)(u16, u8);
33338 bool (*mc1_mce)(u16, u8);
33339-};
33340+} __no_const;
33341
33342 void amd_report_gart_errors(bool);
33343 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
33344diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
33345index 57ea7f4..789e3c3 100644
33346--- a/drivers/firewire/core-card.c
33347+++ b/drivers/firewire/core-card.c
33348@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
33349
33350 void fw_core_remove_card(struct fw_card *card)
33351 {
33352- struct fw_card_driver dummy_driver = dummy_driver_template;
33353+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
33354
33355 card->driver->update_phy_reg(card, 4,
33356 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
33357diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
33358index f8d2287..5aaf4db 100644
33359--- a/drivers/firewire/core-cdev.c
33360+++ b/drivers/firewire/core-cdev.c
33361@@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
33362 int ret;
33363
33364 if ((request->channels == 0 && request->bandwidth == 0) ||
33365- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
33366- request->bandwidth < 0)
33367+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
33368 return -EINVAL;
33369
33370 r = kmalloc(sizeof(*r), GFP_KERNEL);
33371diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
33372index 28a94c7..58da63a 100644
33373--- a/drivers/firewire/core-transaction.c
33374+++ b/drivers/firewire/core-transaction.c
33375@@ -38,6 +38,7 @@
33376 #include <linux/timer.h>
33377 #include <linux/types.h>
33378 #include <linux/workqueue.h>
33379+#include <linux/sched.h>
33380
33381 #include <asm/byteorder.h>
33382
33383diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
33384index 515a42c..5ecf3ba 100644
33385--- a/drivers/firewire/core.h
33386+++ b/drivers/firewire/core.h
33387@@ -111,6 +111,7 @@ struct fw_card_driver {
33388
33389 int (*stop_iso)(struct fw_iso_context *ctx);
33390 };
33391+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
33392
33393 void fw_card_initialize(struct fw_card *card,
33394 const struct fw_card_driver *driver, struct device *device);
33395diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
33396index 982f1f5..d21e5da 100644
33397--- a/drivers/firmware/dmi_scan.c
33398+++ b/drivers/firmware/dmi_scan.c
33399@@ -491,11 +491,6 @@ void __init dmi_scan_machine(void)
33400 }
33401 }
33402 else {
33403- /*
33404- * no iounmap() for that ioremap(); it would be a no-op, but
33405- * it's so early in setup that sucker gets confused into doing
33406- * what it shouldn't if we actually call it.
33407- */
33408 p = dmi_ioremap(0xF0000, 0x10000);
33409 if (p == NULL)
33410 goto error;
33411@@ -770,7 +765,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
33412 if (buf == NULL)
33413 return -1;
33414
33415- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
33416+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
33417
33418 iounmap(buf);
33419 return 0;
33420diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
33421index f5596db..9355ce6 100644
33422--- a/drivers/firmware/efivars.c
33423+++ b/drivers/firmware/efivars.c
33424@@ -132,7 +132,7 @@ struct efivar_attribute {
33425 };
33426
33427 static struct efivars __efivars;
33428-static struct efivar_operations ops;
33429+static efivar_operations_no_const ops __read_only;
33430
33431 #define PSTORE_EFI_ATTRIBUTES \
33432 (EFI_VARIABLE_NON_VOLATILE | \
33433diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
33434index 9902732..64b62dd 100644
33435--- a/drivers/gpio/gpio-vr41xx.c
33436+++ b/drivers/gpio/gpio-vr41xx.c
33437@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
33438 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
33439 maskl, pendl, maskh, pendh);
33440
33441- atomic_inc(&irq_err_count);
33442+ atomic_inc_unchecked(&irq_err_count);
33443
33444 return -EINVAL;
33445 }
33446diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
33447index 7b2d378..cc947ea 100644
33448--- a/drivers/gpu/drm/drm_crtc_helper.c
33449+++ b/drivers/gpu/drm/drm_crtc_helper.c
33450@@ -319,7 +319,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
33451 struct drm_crtc *tmp;
33452 int crtc_mask = 1;
33453
33454- WARN(!crtc, "checking null crtc?\n");
33455+ BUG_ON(!crtc);
33456
33457 dev = crtc->dev;
33458
33459diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
33460index be174ca..0bcbb71 100644
33461--- a/drivers/gpu/drm/drm_drv.c
33462+++ b/drivers/gpu/drm/drm_drv.c
33463@@ -307,7 +307,7 @@ module_exit(drm_core_exit);
33464 /**
33465 * Copy and IOCTL return string to user space
33466 */
33467-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
33468+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
33469 {
33470 int len;
33471
33472@@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
33473 return -ENODEV;
33474
33475 atomic_inc(&dev->ioctl_count);
33476- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
33477+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
33478 ++file_priv->ioctl_count;
33479
33480 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
33481diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
33482index 133b413..fd68225 100644
33483--- a/drivers/gpu/drm/drm_fops.c
33484+++ b/drivers/gpu/drm/drm_fops.c
33485@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
33486 }
33487
33488 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
33489- atomic_set(&dev->counts[i], 0);
33490+ atomic_set_unchecked(&dev->counts[i], 0);
33491
33492 dev->sigdata.lock = NULL;
33493
33494@@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
33495 if (drm_device_is_unplugged(dev))
33496 return -ENODEV;
33497
33498- if (!dev->open_count++)
33499+ if (local_inc_return(&dev->open_count) == 1)
33500 need_setup = 1;
33501 mutex_lock(&dev->struct_mutex);
33502 old_mapping = dev->dev_mapping;
33503@@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
33504 retcode = drm_open_helper(inode, filp, dev);
33505 if (retcode)
33506 goto err_undo;
33507- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
33508+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
33509 if (need_setup) {
33510 retcode = drm_setup(dev);
33511 if (retcode)
33512@@ -164,7 +164,7 @@ err_undo:
33513 iput(container_of(dev->dev_mapping, struct inode, i_data));
33514 dev->dev_mapping = old_mapping;
33515 mutex_unlock(&dev->struct_mutex);
33516- dev->open_count--;
33517+ local_dec(&dev->open_count);
33518 return retcode;
33519 }
33520 EXPORT_SYMBOL(drm_open);
33521@@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
33522
33523 mutex_lock(&drm_global_mutex);
33524
33525- DRM_DEBUG("open_count = %d\n", dev->open_count);
33526+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
33527
33528 if (dev->driver->preclose)
33529 dev->driver->preclose(dev, file_priv);
33530@@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
33531 * Begin inline drm_release
33532 */
33533
33534- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
33535+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
33536 task_pid_nr(current),
33537 (long)old_encode_dev(file_priv->minor->device),
33538- dev->open_count);
33539+ local_read(&dev->open_count));
33540
33541 /* Release any auth tokens that might point to this file_priv,
33542 (do that under the drm_global_mutex) */
33543@@ -547,8 +547,8 @@ int drm_release(struct inode *inode, struct file *filp)
33544 * End inline drm_release
33545 */
33546
33547- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
33548- if (!--dev->open_count) {
33549+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
33550+ if (local_dec_and_test(&dev->open_count)) {
33551 if (atomic_read(&dev->ioctl_count)) {
33552 DRM_ERROR("Device busy: %d\n",
33553 atomic_read(&dev->ioctl_count));
33554diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
33555index f731116..629842c 100644
33556--- a/drivers/gpu/drm/drm_global.c
33557+++ b/drivers/gpu/drm/drm_global.c
33558@@ -36,7 +36,7 @@
33559 struct drm_global_item {
33560 struct mutex mutex;
33561 void *object;
33562- int refcount;
33563+ atomic_t refcount;
33564 };
33565
33566 static struct drm_global_item glob[DRM_GLOBAL_NUM];
33567@@ -49,7 +49,7 @@ void drm_global_init(void)
33568 struct drm_global_item *item = &glob[i];
33569 mutex_init(&item->mutex);
33570 item->object = NULL;
33571- item->refcount = 0;
33572+ atomic_set(&item->refcount, 0);
33573 }
33574 }
33575
33576@@ -59,7 +59,7 @@ void drm_global_release(void)
33577 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
33578 struct drm_global_item *item = &glob[i];
33579 BUG_ON(item->object != NULL);
33580- BUG_ON(item->refcount != 0);
33581+ BUG_ON(atomic_read(&item->refcount) != 0);
33582 }
33583 }
33584
33585@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
33586 void *object;
33587
33588 mutex_lock(&item->mutex);
33589- if (item->refcount == 0) {
33590+ if (atomic_read(&item->refcount) == 0) {
33591 item->object = kzalloc(ref->size, GFP_KERNEL);
33592 if (unlikely(item->object == NULL)) {
33593 ret = -ENOMEM;
33594@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
33595 goto out_err;
33596
33597 }
33598- ++item->refcount;
33599+ atomic_inc(&item->refcount);
33600 ref->object = item->object;
33601 object = item->object;
33602 mutex_unlock(&item->mutex);
33603@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
33604 struct drm_global_item *item = &glob[ref->global_type];
33605
33606 mutex_lock(&item->mutex);
33607- BUG_ON(item->refcount == 0);
33608+ BUG_ON(atomic_read(&item->refcount) == 0);
33609 BUG_ON(ref->object != item->object);
33610- if (--item->refcount == 0) {
33611+ if (atomic_dec_and_test(&item->refcount)) {
33612 ref->release(ref);
33613 item->object = NULL;
33614 }
33615diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
33616index d4b20ce..77a8d41 100644
33617--- a/drivers/gpu/drm/drm_info.c
33618+++ b/drivers/gpu/drm/drm_info.c
33619@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
33620 struct drm_local_map *map;
33621 struct drm_map_list *r_list;
33622
33623- /* Hardcoded from _DRM_FRAME_BUFFER,
33624- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
33625- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
33626- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
33627+ static const char * const types[] = {
33628+ [_DRM_FRAME_BUFFER] = "FB",
33629+ [_DRM_REGISTERS] = "REG",
33630+ [_DRM_SHM] = "SHM",
33631+ [_DRM_AGP] = "AGP",
33632+ [_DRM_SCATTER_GATHER] = "SG",
33633+ [_DRM_CONSISTENT] = "PCI",
33634+ [_DRM_GEM] = "GEM" };
33635 const char *type;
33636 int i;
33637
33638@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
33639 map = r_list->map;
33640 if (!map)
33641 continue;
33642- if (map->type < 0 || map->type > 5)
33643+ if (map->type >= ARRAY_SIZE(types))
33644 type = "??";
33645 else
33646 type = types[map->type];
33647@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
33648 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
33649 vma->vm_flags & VM_LOCKED ? 'l' : '-',
33650 vma->vm_flags & VM_IO ? 'i' : '-',
33651+#ifdef CONFIG_GRKERNSEC_HIDESYM
33652+ 0);
33653+#else
33654 vma->vm_pgoff);
33655+#endif
33656
33657 #if defined(__i386__)
33658 pgprot = pgprot_val(vma->vm_page_prot);
33659diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
33660index 2f4c434..764794b 100644
33661--- a/drivers/gpu/drm/drm_ioc32.c
33662+++ b/drivers/gpu/drm/drm_ioc32.c
33663@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
33664 request = compat_alloc_user_space(nbytes);
33665 if (!access_ok(VERIFY_WRITE, request, nbytes))
33666 return -EFAULT;
33667- list = (struct drm_buf_desc *) (request + 1);
33668+ list = (struct drm_buf_desc __user *) (request + 1);
33669
33670 if (__put_user(count, &request->count)
33671 || __put_user(list, &request->list))
33672@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
33673 request = compat_alloc_user_space(nbytes);
33674 if (!access_ok(VERIFY_WRITE, request, nbytes))
33675 return -EFAULT;
33676- list = (struct drm_buf_pub *) (request + 1);
33677+ list = (struct drm_buf_pub __user *) (request + 1);
33678
33679 if (__put_user(count, &request->count)
33680 || __put_user(list, &request->list))
33681diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
33682index e77bd8b..1571b85 100644
33683--- a/drivers/gpu/drm/drm_ioctl.c
33684+++ b/drivers/gpu/drm/drm_ioctl.c
33685@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
33686 stats->data[i].value =
33687 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
33688 else
33689- stats->data[i].value = atomic_read(&dev->counts[i]);
33690+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
33691 stats->data[i].type = dev->types[i];
33692 }
33693
33694diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
33695index d752c96..fe08455 100644
33696--- a/drivers/gpu/drm/drm_lock.c
33697+++ b/drivers/gpu/drm/drm_lock.c
33698@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
33699 if (drm_lock_take(&master->lock, lock->context)) {
33700 master->lock.file_priv = file_priv;
33701 master->lock.lock_time = jiffies;
33702- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
33703+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
33704 break; /* Got lock */
33705 }
33706
33707@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
33708 return -EINVAL;
33709 }
33710
33711- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
33712+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
33713
33714 if (drm_lock_free(&master->lock, lock->context)) {
33715 /* FIXME: Should really bail out here. */
33716diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
33717index 200e104..59facda 100644
33718--- a/drivers/gpu/drm/drm_stub.c
33719+++ b/drivers/gpu/drm/drm_stub.c
33720@@ -516,7 +516,7 @@ void drm_unplug_dev(struct drm_device *dev)
33721
33722 drm_device_set_unplugged(dev);
33723
33724- if (dev->open_count == 0) {
33725+ if (local_read(&dev->open_count) == 0) {
33726 drm_put_dev(dev);
33727 }
33728 mutex_unlock(&drm_global_mutex);
33729diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
33730index 004ecdf..db1f6e0 100644
33731--- a/drivers/gpu/drm/i810/i810_dma.c
33732+++ b/drivers/gpu/drm/i810/i810_dma.c
33733@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
33734 dma->buflist[vertex->idx],
33735 vertex->discard, vertex->used);
33736
33737- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
33738- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
33739+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
33740+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
33741 sarea_priv->last_enqueue = dev_priv->counter - 1;
33742 sarea_priv->last_dispatch = (int)hw_status[5];
33743
33744@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
33745 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
33746 mc->last_render);
33747
33748- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
33749- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
33750+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
33751+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
33752 sarea_priv->last_enqueue = dev_priv->counter - 1;
33753 sarea_priv->last_dispatch = (int)hw_status[5];
33754
33755diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
33756index 6e0acad..93c8289 100644
33757--- a/drivers/gpu/drm/i810/i810_drv.h
33758+++ b/drivers/gpu/drm/i810/i810_drv.h
33759@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
33760 int page_flipping;
33761
33762 wait_queue_head_t irq_queue;
33763- atomic_t irq_received;
33764- atomic_t irq_emitted;
33765+ atomic_unchecked_t irq_received;
33766+ atomic_unchecked_t irq_emitted;
33767
33768 int front_offset;
33769 } drm_i810_private_t;
33770diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
33771index 8a7c48b..72effc2 100644
33772--- a/drivers/gpu/drm/i915/i915_debugfs.c
33773+++ b/drivers/gpu/drm/i915/i915_debugfs.c
33774@@ -496,7 +496,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
33775 I915_READ(GTIMR));
33776 }
33777 seq_printf(m, "Interrupts received: %d\n",
33778- atomic_read(&dev_priv->irq_received));
33779+ atomic_read_unchecked(&dev_priv->irq_received));
33780 for_each_ring(ring, dev_priv, i) {
33781 if (IS_GEN6(dev) || IS_GEN7(dev)) {
33782 seq_printf(m,
33783diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
33784index 99daa89..84ebd44 100644
33785--- a/drivers/gpu/drm/i915/i915_dma.c
33786+++ b/drivers/gpu/drm/i915/i915_dma.c
33787@@ -1253,7 +1253,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
33788 bool can_switch;
33789
33790 spin_lock(&dev->count_lock);
33791- can_switch = (dev->open_count == 0);
33792+ can_switch = (local_read(&dev->open_count) == 0);
33793 spin_unlock(&dev->count_lock);
33794 return can_switch;
33795 }
33796diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
33797index 7339a4b..445aaba 100644
33798--- a/drivers/gpu/drm/i915/i915_drv.h
33799+++ b/drivers/gpu/drm/i915/i915_drv.h
33800@@ -656,7 +656,7 @@ typedef struct drm_i915_private {
33801 drm_dma_handle_t *status_page_dmah;
33802 struct resource mch_res;
33803
33804- atomic_t irq_received;
33805+ atomic_unchecked_t irq_received;
33806
33807 /* protects the irq masks */
33808 spinlock_t irq_lock;
33809@@ -1102,7 +1102,7 @@ struct drm_i915_gem_object {
33810 * will be page flipped away on the next vblank. When it
33811 * reaches 0, dev_priv->pending_flip_queue will be woken up.
33812 */
33813- atomic_t pending_flip;
33814+ atomic_unchecked_t pending_flip;
33815 };
33816 #define to_gem_object(obj) (&((struct drm_i915_gem_object *)(obj))->base)
33817
33818@@ -1633,7 +1633,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
33819 struct drm_i915_private *dev_priv, unsigned port);
33820 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
33821 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
33822-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
33823+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
33824 {
33825 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
33826 }
33827diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
33828index 26d08bb..fccb984 100644
33829--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
33830+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
33831@@ -672,7 +672,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
33832 i915_gem_clflush_object(obj);
33833
33834 if (obj->base.pending_write_domain)
33835- flips |= atomic_read(&obj->pending_flip);
33836+ flips |= atomic_read_unchecked(&obj->pending_flip);
33837
33838 flush_domains |= obj->base.write_domain;
33839 }
33840@@ -703,9 +703,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
33841
33842 static int
33843 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
33844- int count)
33845+ unsigned int count)
33846 {
33847- int i;
33848+ unsigned int i;
33849
33850 for (i = 0; i < count; i++) {
33851 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
33852diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
33853index fe84338..a863190 100644
33854--- a/drivers/gpu/drm/i915/i915_irq.c
33855+++ b/drivers/gpu/drm/i915/i915_irq.c
33856@@ -535,7 +535,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
33857 u32 pipe_stats[I915_MAX_PIPES];
33858 bool blc_event;
33859
33860- atomic_inc(&dev_priv->irq_received);
33861+ atomic_inc_unchecked(&dev_priv->irq_received);
33862
33863 while (true) {
33864 iir = I915_READ(VLV_IIR);
33865@@ -688,7 +688,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
33866 irqreturn_t ret = IRQ_NONE;
33867 int i;
33868
33869- atomic_inc(&dev_priv->irq_received);
33870+ atomic_inc_unchecked(&dev_priv->irq_received);
33871
33872 /* disable master interrupt before clearing iir */
33873 de_ier = I915_READ(DEIER);
33874@@ -760,7 +760,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
33875 int ret = IRQ_NONE;
33876 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
33877
33878- atomic_inc(&dev_priv->irq_received);
33879+ atomic_inc_unchecked(&dev_priv->irq_received);
33880
33881 /* disable master interrupt before clearing iir */
33882 de_ier = I915_READ(DEIER);
33883@@ -1787,7 +1787,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
33884 {
33885 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33886
33887- atomic_set(&dev_priv->irq_received, 0);
33888+ atomic_set_unchecked(&dev_priv->irq_received, 0);
33889
33890 I915_WRITE(HWSTAM, 0xeffe);
33891
33892@@ -1813,7 +1813,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
33893 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33894 int pipe;
33895
33896- atomic_set(&dev_priv->irq_received, 0);
33897+ atomic_set_unchecked(&dev_priv->irq_received, 0);
33898
33899 /* VLV magic */
33900 I915_WRITE(VLV_IMR, 0);
33901@@ -2108,7 +2108,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
33902 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33903 int pipe;
33904
33905- atomic_set(&dev_priv->irq_received, 0);
33906+ atomic_set_unchecked(&dev_priv->irq_received, 0);
33907
33908 for_each_pipe(pipe)
33909 I915_WRITE(PIPESTAT(pipe), 0);
33910@@ -2159,7 +2159,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
33911 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
33912 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
33913
33914- atomic_inc(&dev_priv->irq_received);
33915+ atomic_inc_unchecked(&dev_priv->irq_received);
33916
33917 iir = I915_READ16(IIR);
33918 if (iir == 0)
33919@@ -2244,7 +2244,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
33920 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33921 int pipe;
33922
33923- atomic_set(&dev_priv->irq_received, 0);
33924+ atomic_set_unchecked(&dev_priv->irq_received, 0);
33925
33926 if (I915_HAS_HOTPLUG(dev)) {
33927 I915_WRITE(PORT_HOTPLUG_EN, 0);
33928@@ -2339,7 +2339,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
33929 };
33930 int pipe, ret = IRQ_NONE;
33931
33932- atomic_inc(&dev_priv->irq_received);
33933+ atomic_inc_unchecked(&dev_priv->irq_received);
33934
33935 iir = I915_READ(IIR);
33936 do {
33937@@ -2465,7 +2465,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
33938 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33939 int pipe;
33940
33941- atomic_set(&dev_priv->irq_received, 0);
33942+ atomic_set_unchecked(&dev_priv->irq_received, 0);
33943
33944 I915_WRITE(PORT_HOTPLUG_EN, 0);
33945 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
33946@@ -2572,7 +2572,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
33947 int irq_received;
33948 int ret = IRQ_NONE, pipe;
33949
33950- atomic_inc(&dev_priv->irq_received);
33951+ atomic_inc_unchecked(&dev_priv->irq_received);
33952
33953 iir = I915_READ(IIR);
33954
33955diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
33956index 80aa1fc..1ede041 100644
33957--- a/drivers/gpu/drm/i915/intel_display.c
33958+++ b/drivers/gpu/drm/i915/intel_display.c
33959@@ -2255,7 +2255,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
33960
33961 wait_event(dev_priv->pending_flip_queue,
33962 atomic_read(&dev_priv->mm.wedged) ||
33963- atomic_read(&obj->pending_flip) == 0);
33964+ atomic_read_unchecked(&obj->pending_flip) == 0);
33965
33966 /* Big Hammer, we also need to ensure that any pending
33967 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
33968@@ -7122,8 +7122,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
33969
33970 obj = work->old_fb_obj;
33971
33972- atomic_clear_mask(1 << intel_crtc->plane,
33973- &obj->pending_flip.counter);
33974+ atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
33975 wake_up(&dev_priv->pending_flip_queue);
33976
33977 queue_work(dev_priv->wq, &work->work);
33978@@ -7490,7 +7489,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
33979 /* Block clients from rendering to the new back buffer until
33980 * the flip occurs and the object is no longer visible.
33981 */
33982- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33983+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33984 atomic_inc(&intel_crtc->unpin_work_count);
33985
33986 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
33987@@ -7507,7 +7506,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
33988
33989 cleanup_pending:
33990 atomic_dec(&intel_crtc->unpin_work_count);
33991- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33992+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33993 drm_gem_object_unreference(&work->old_fb_obj->base);
33994 drm_gem_object_unreference(&obj->base);
33995 mutex_unlock(&dev->struct_mutex);
33996diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
33997index 54558a0..2d97005 100644
33998--- a/drivers/gpu/drm/mga/mga_drv.h
33999+++ b/drivers/gpu/drm/mga/mga_drv.h
34000@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
34001 u32 clear_cmd;
34002 u32 maccess;
34003
34004- atomic_t vbl_received; /**< Number of vblanks received. */
34005+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
34006 wait_queue_head_t fence_queue;
34007- atomic_t last_fence_retired;
34008+ atomic_unchecked_t last_fence_retired;
34009 u32 next_fence_to_post;
34010
34011 unsigned int fb_cpp;
34012diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
34013index 598c281..60d590e 100644
34014--- a/drivers/gpu/drm/mga/mga_irq.c
34015+++ b/drivers/gpu/drm/mga/mga_irq.c
34016@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
34017 if (crtc != 0)
34018 return 0;
34019
34020- return atomic_read(&dev_priv->vbl_received);
34021+ return atomic_read_unchecked(&dev_priv->vbl_received);
34022 }
34023
34024
34025@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
34026 /* VBLANK interrupt */
34027 if (status & MGA_VLINEPEN) {
34028 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
34029- atomic_inc(&dev_priv->vbl_received);
34030+ atomic_inc_unchecked(&dev_priv->vbl_received);
34031 drm_handle_vblank(dev, 0);
34032 handled = 1;
34033 }
34034@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
34035 if ((prim_start & ~0x03) != (prim_end & ~0x03))
34036 MGA_WRITE(MGA_PRIMEND, prim_end);
34037
34038- atomic_inc(&dev_priv->last_fence_retired);
34039+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
34040 DRM_WAKEUP(&dev_priv->fence_queue);
34041 handled = 1;
34042 }
34043@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
34044 * using fences.
34045 */
34046 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
34047- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
34048+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
34049 - *sequence) <= (1 << 23)));
34050
34051 *sequence = cur_fence;
34052diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
34053index 865eddf..62c4cc3 100644
34054--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
34055+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
34056@@ -1015,7 +1015,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
34057 struct bit_table {
34058 const char id;
34059 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
34060-};
34061+} __no_const;
34062
34063 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
34064
34065diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
34066index aa89eb9..d45d38b 100644
34067--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
34068+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
34069@@ -80,7 +80,7 @@ struct nouveau_drm {
34070 struct drm_global_reference mem_global_ref;
34071 struct ttm_bo_global_ref bo_global_ref;
34072 struct ttm_bo_device bdev;
34073- atomic_t validate_sequence;
34074+ atomic_unchecked_t validate_sequence;
34075 int (*move)(struct nouveau_channel *,
34076 struct ttm_buffer_object *,
34077 struct ttm_mem_reg *, struct ttm_mem_reg *);
34078diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
34079index cdb83ac..27f0a16 100644
34080--- a/drivers/gpu/drm/nouveau/nouveau_fence.h
34081+++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
34082@@ -43,7 +43,7 @@ struct nouveau_fence_priv {
34083 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
34084 struct nouveau_channel *);
34085 u32 (*read)(struct nouveau_channel *);
34086-};
34087+} __no_const;
34088
34089 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
34090
34091diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
34092index 8bf695c..9fbc90a 100644
34093--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
34094+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
34095@@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
34096 int trycnt = 0;
34097 int ret, i;
34098
34099- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
34100+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
34101 retry:
34102 if (++trycnt > 100000) {
34103 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
34104diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
34105index 25d3495..d81aaf6 100644
34106--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
34107+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
34108@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
34109 bool can_switch;
34110
34111 spin_lock(&dev->count_lock);
34112- can_switch = (dev->open_count == 0);
34113+ can_switch = (local_read(&dev->open_count) == 0);
34114 spin_unlock(&dev->count_lock);
34115 return can_switch;
34116 }
34117diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
34118index d4660cf..70dbe65 100644
34119--- a/drivers/gpu/drm/r128/r128_cce.c
34120+++ b/drivers/gpu/drm/r128/r128_cce.c
34121@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
34122
34123 /* GH: Simple idle check.
34124 */
34125- atomic_set(&dev_priv->idle_count, 0);
34126+ atomic_set_unchecked(&dev_priv->idle_count, 0);
34127
34128 /* We don't support anything other than bus-mastering ring mode,
34129 * but the ring can be in either AGP or PCI space for the ring
34130diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
34131index 930c71b..499aded 100644
34132--- a/drivers/gpu/drm/r128/r128_drv.h
34133+++ b/drivers/gpu/drm/r128/r128_drv.h
34134@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
34135 int is_pci;
34136 unsigned long cce_buffers_offset;
34137
34138- atomic_t idle_count;
34139+ atomic_unchecked_t idle_count;
34140
34141 int page_flipping;
34142 int current_page;
34143 u32 crtc_offset;
34144 u32 crtc_offset_cntl;
34145
34146- atomic_t vbl_received;
34147+ atomic_unchecked_t vbl_received;
34148
34149 u32 color_fmt;
34150 unsigned int front_offset;
34151diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
34152index 2ea4f09..d391371 100644
34153--- a/drivers/gpu/drm/r128/r128_irq.c
34154+++ b/drivers/gpu/drm/r128/r128_irq.c
34155@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
34156 if (crtc != 0)
34157 return 0;
34158
34159- return atomic_read(&dev_priv->vbl_received);
34160+ return atomic_read_unchecked(&dev_priv->vbl_received);
34161 }
34162
34163 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
34164@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
34165 /* VBLANK interrupt */
34166 if (status & R128_CRTC_VBLANK_INT) {
34167 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
34168- atomic_inc(&dev_priv->vbl_received);
34169+ atomic_inc_unchecked(&dev_priv->vbl_received);
34170 drm_handle_vblank(dev, 0);
34171 return IRQ_HANDLED;
34172 }
34173diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
34174index 19bb7e6..de7e2a2 100644
34175--- a/drivers/gpu/drm/r128/r128_state.c
34176+++ b/drivers/gpu/drm/r128/r128_state.c
34177@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
34178
34179 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
34180 {
34181- if (atomic_read(&dev_priv->idle_count) == 0)
34182+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
34183 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
34184 else
34185- atomic_set(&dev_priv->idle_count, 0);
34186+ atomic_set_unchecked(&dev_priv->idle_count, 0);
34187 }
34188
34189 #endif
34190diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
34191index 5a82b6b..9e69c73 100644
34192--- a/drivers/gpu/drm/radeon/mkregtable.c
34193+++ b/drivers/gpu/drm/radeon/mkregtable.c
34194@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
34195 regex_t mask_rex;
34196 regmatch_t match[4];
34197 char buf[1024];
34198- size_t end;
34199+ long end;
34200 int len;
34201 int done = 0;
34202 int r;
34203 unsigned o;
34204 struct offset *offset;
34205 char last_reg_s[10];
34206- int last_reg;
34207+ unsigned long last_reg;
34208
34209 if (regcomp
34210 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
34211diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
34212index 0d6562b..a154330 100644
34213--- a/drivers/gpu/drm/radeon/radeon_device.c
34214+++ b/drivers/gpu/drm/radeon/radeon_device.c
34215@@ -969,7 +969,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
34216 bool can_switch;
34217
34218 spin_lock(&dev->count_lock);
34219- can_switch = (dev->open_count == 0);
34220+ can_switch = (local_read(&dev->open_count) == 0);
34221 spin_unlock(&dev->count_lock);
34222 return can_switch;
34223 }
34224diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
34225index e7fdf16..f4f6490 100644
34226--- a/drivers/gpu/drm/radeon/radeon_drv.h
34227+++ b/drivers/gpu/drm/radeon/radeon_drv.h
34228@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
34229
34230 /* SW interrupt */
34231 wait_queue_head_t swi_queue;
34232- atomic_t swi_emitted;
34233+ atomic_unchecked_t swi_emitted;
34234 int vblank_crtc;
34235 uint32_t irq_enable_reg;
34236 uint32_t r500_disp_irq_reg;
34237diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
34238index c180df8..cd80dd2d 100644
34239--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
34240+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
34241@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
34242 request = compat_alloc_user_space(sizeof(*request));
34243 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
34244 || __put_user(req32.param, &request->param)
34245- || __put_user((void __user *)(unsigned long)req32.value,
34246+ || __put_user((unsigned long)req32.value,
34247 &request->value))
34248 return -EFAULT;
34249
34250diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
34251index e771033..a0bc6b3 100644
34252--- a/drivers/gpu/drm/radeon/radeon_irq.c
34253+++ b/drivers/gpu/drm/radeon/radeon_irq.c
34254@@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
34255 unsigned int ret;
34256 RING_LOCALS;
34257
34258- atomic_inc(&dev_priv->swi_emitted);
34259- ret = atomic_read(&dev_priv->swi_emitted);
34260+ atomic_inc_unchecked(&dev_priv->swi_emitted);
34261+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
34262
34263 BEGIN_RING(4);
34264 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
34265@@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
34266 drm_radeon_private_t *dev_priv =
34267 (drm_radeon_private_t *) dev->dev_private;
34268
34269- atomic_set(&dev_priv->swi_emitted, 0);
34270+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
34271 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
34272
34273 dev->max_vblank_count = 0x001fffff;
34274diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
34275index 8e9057b..af6dacb 100644
34276--- a/drivers/gpu/drm/radeon/radeon_state.c
34277+++ b/drivers/gpu/drm/radeon/radeon_state.c
34278@@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
34279 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
34280 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
34281
34282- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
34283+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
34284 sarea_priv->nbox * sizeof(depth_boxes[0])))
34285 return -EFAULT;
34286
34287@@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
34288 {
34289 drm_radeon_private_t *dev_priv = dev->dev_private;
34290 drm_radeon_getparam_t *param = data;
34291- int value;
34292+ int value = 0;
34293
34294 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
34295
34296diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
34297index 93f760e..33d9839 100644
34298--- a/drivers/gpu/drm/radeon/radeon_ttm.c
34299+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
34300@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
34301 man->size = size >> PAGE_SHIFT;
34302 }
34303
34304-static struct vm_operations_struct radeon_ttm_vm_ops;
34305+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
34306 static const struct vm_operations_struct *ttm_vm_ops = NULL;
34307
34308 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
34309@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
34310 }
34311 if (unlikely(ttm_vm_ops == NULL)) {
34312 ttm_vm_ops = vma->vm_ops;
34313+ pax_open_kernel();
34314 radeon_ttm_vm_ops = *ttm_vm_ops;
34315 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
34316+ pax_close_kernel();
34317 }
34318 vma->vm_ops = &radeon_ttm_vm_ops;
34319 return 0;
34320diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
34321index 5706d2a..17aedaa 100644
34322--- a/drivers/gpu/drm/radeon/rs690.c
34323+++ b/drivers/gpu/drm/radeon/rs690.c
34324@@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
34325 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
34326 rdev->pm.sideport_bandwidth.full)
34327 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
34328- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
34329+ read_delay_latency.full = dfixed_const(800 * 1000);
34330 read_delay_latency.full = dfixed_div(read_delay_latency,
34331 rdev->pm.igp_sideport_mclk);
34332+ a.full = dfixed_const(370);
34333+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
34334 } else {
34335 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
34336 rdev->pm.k8_bandwidth.full)
34337diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
34338index bd2a3b4..122d9ad 100644
34339--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
34340+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
34341@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
34342 static int ttm_pool_mm_shrink(struct shrinker *shrink,
34343 struct shrink_control *sc)
34344 {
34345- static atomic_t start_pool = ATOMIC_INIT(0);
34346+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
34347 unsigned i;
34348- unsigned pool_offset = atomic_add_return(1, &start_pool);
34349+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
34350 struct ttm_page_pool *pool;
34351 int shrink_pages = sc->nr_to_scan;
34352
34353diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
34354index 893a650..6190d3b 100644
34355--- a/drivers/gpu/drm/via/via_drv.h
34356+++ b/drivers/gpu/drm/via/via_drv.h
34357@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
34358 typedef uint32_t maskarray_t[5];
34359
34360 typedef struct drm_via_irq {
34361- atomic_t irq_received;
34362+ atomic_unchecked_t irq_received;
34363 uint32_t pending_mask;
34364 uint32_t enable_mask;
34365 wait_queue_head_t irq_queue;
34366@@ -75,7 +75,7 @@ typedef struct drm_via_private {
34367 struct timeval last_vblank;
34368 int last_vblank_valid;
34369 unsigned usec_per_vblank;
34370- atomic_t vbl_received;
34371+ atomic_unchecked_t vbl_received;
34372 drm_via_state_t hc_state;
34373 char pci_buf[VIA_PCI_BUF_SIZE];
34374 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
34375diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
34376index ac98964..5dbf512 100644
34377--- a/drivers/gpu/drm/via/via_irq.c
34378+++ b/drivers/gpu/drm/via/via_irq.c
34379@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
34380 if (crtc != 0)
34381 return 0;
34382
34383- return atomic_read(&dev_priv->vbl_received);
34384+ return atomic_read_unchecked(&dev_priv->vbl_received);
34385 }
34386
34387 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
34388@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
34389
34390 status = VIA_READ(VIA_REG_INTERRUPT);
34391 if (status & VIA_IRQ_VBLANK_PENDING) {
34392- atomic_inc(&dev_priv->vbl_received);
34393- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
34394+ atomic_inc_unchecked(&dev_priv->vbl_received);
34395+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
34396 do_gettimeofday(&cur_vblank);
34397 if (dev_priv->last_vblank_valid) {
34398 dev_priv->usec_per_vblank =
34399@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
34400 dev_priv->last_vblank = cur_vblank;
34401 dev_priv->last_vblank_valid = 1;
34402 }
34403- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
34404+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
34405 DRM_DEBUG("US per vblank is: %u\n",
34406 dev_priv->usec_per_vblank);
34407 }
34408@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
34409
34410 for (i = 0; i < dev_priv->num_irqs; ++i) {
34411 if (status & cur_irq->pending_mask) {
34412- atomic_inc(&cur_irq->irq_received);
34413+ atomic_inc_unchecked(&cur_irq->irq_received);
34414 DRM_WAKEUP(&cur_irq->irq_queue);
34415 handled = 1;
34416 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
34417@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
34418 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
34419 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
34420 masks[irq][4]));
34421- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
34422+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
34423 } else {
34424 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
34425 (((cur_irq_sequence =
34426- atomic_read(&cur_irq->irq_received)) -
34427+ atomic_read_unchecked(&cur_irq->irq_received)) -
34428 *sequence) <= (1 << 23)));
34429 }
34430 *sequence = cur_irq_sequence;
34431@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
34432 }
34433
34434 for (i = 0; i < dev_priv->num_irqs; ++i) {
34435- atomic_set(&cur_irq->irq_received, 0);
34436+ atomic_set_unchecked(&cur_irq->irq_received, 0);
34437 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
34438 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
34439 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
34440@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
34441 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
34442 case VIA_IRQ_RELATIVE:
34443 irqwait->request.sequence +=
34444- atomic_read(&cur_irq->irq_received);
34445+ atomic_read_unchecked(&cur_irq->irq_received);
34446 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
34447 case VIA_IRQ_ABSOLUTE:
34448 break;
34449diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
34450index 13aeda7..4a952d1 100644
34451--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
34452+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
34453@@ -290,7 +290,7 @@ struct vmw_private {
34454 * Fencing and IRQs.
34455 */
34456
34457- atomic_t marker_seq;
34458+ atomic_unchecked_t marker_seq;
34459 wait_queue_head_t fence_queue;
34460 wait_queue_head_t fifo_queue;
34461 int fence_queue_waiters; /* Protected by hw_mutex */
34462diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
34463index 3eb1486..0a47ee9 100644
34464--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
34465+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
34466@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
34467 (unsigned int) min,
34468 (unsigned int) fifo->capabilities);
34469
34470- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
34471+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
34472 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
34473 vmw_marker_queue_init(&fifo->marker_queue);
34474 return vmw_fifo_send_fence(dev_priv, &dummy);
34475@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
34476 if (reserveable)
34477 iowrite32(bytes, fifo_mem +
34478 SVGA_FIFO_RESERVED);
34479- return fifo_mem + (next_cmd >> 2);
34480+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
34481 } else {
34482 need_bounce = true;
34483 }
34484@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
34485
34486 fm = vmw_fifo_reserve(dev_priv, bytes);
34487 if (unlikely(fm == NULL)) {
34488- *seqno = atomic_read(&dev_priv->marker_seq);
34489+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
34490 ret = -ENOMEM;
34491 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
34492 false, 3*HZ);
34493@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
34494 }
34495
34496 do {
34497- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
34498+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
34499 } while (*seqno == 0);
34500
34501 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
34502diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
34503index 4640adb..e1384ed 100644
34504--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
34505+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
34506@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
34507 * emitted. Then the fence is stale and signaled.
34508 */
34509
34510- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
34511+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
34512 > VMW_FENCE_WRAP);
34513
34514 return ret;
34515@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
34516
34517 if (fifo_idle)
34518 down_read(&fifo_state->rwsem);
34519- signal_seq = atomic_read(&dev_priv->marker_seq);
34520+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
34521 ret = 0;
34522
34523 for (;;) {
34524diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
34525index 8a8725c..afed796 100644
34526--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
34527+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
34528@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
34529 while (!vmw_lag_lt(queue, us)) {
34530 spin_lock(&queue->lock);
34531 if (list_empty(&queue->head))
34532- seqno = atomic_read(&dev_priv->marker_seq);
34533+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
34534 else {
34535 marker = list_first_entry(&queue->head,
34536 struct vmw_marker, head);
34537diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
34538index eb2ee11..6cc50ab 100644
34539--- a/drivers/hid/hid-core.c
34540+++ b/drivers/hid/hid-core.c
34541@@ -2240,7 +2240,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
34542
34543 int hid_add_device(struct hid_device *hdev)
34544 {
34545- static atomic_t id = ATOMIC_INIT(0);
34546+ static atomic_unchecked_t id = ATOMIC_INIT(0);
34547 int ret;
34548
34549 if (WARN_ON(hdev->status & HID_STAT_ADDED))
34550@@ -2274,7 +2274,7 @@ int hid_add_device(struct hid_device *hdev)
34551 /* XXX hack, any other cleaner solution after the driver core
34552 * is converted to allow more than 20 bytes as the device name? */
34553 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
34554- hdev->vendor, hdev->product, atomic_inc_return(&id));
34555+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
34556
34557 hid_debug_register(hdev, dev_name(&hdev->dev));
34558 ret = device_add(&hdev->dev);
34559diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
34560index eec3291..8ed706b 100644
34561--- a/drivers/hid/hid-wiimote-debug.c
34562+++ b/drivers/hid/hid-wiimote-debug.c
34563@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
34564 else if (size == 0)
34565 return -EIO;
34566
34567- if (copy_to_user(u, buf, size))
34568+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
34569 return -EFAULT;
34570
34571 *off += size;
34572diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
34573index 773a2f2..7ce08bc 100644
34574--- a/drivers/hv/channel.c
34575+++ b/drivers/hv/channel.c
34576@@ -394,8 +394,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
34577 int ret = 0;
34578 int t;
34579
34580- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
34581- atomic_inc(&vmbus_connection.next_gpadl_handle);
34582+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
34583+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
34584
34585 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
34586 if (ret)
34587diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
34588index 3648f8f..30ef30d 100644
34589--- a/drivers/hv/hv.c
34590+++ b/drivers/hv/hv.c
34591@@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
34592 u64 output_address = (output) ? virt_to_phys(output) : 0;
34593 u32 output_address_hi = output_address >> 32;
34594 u32 output_address_lo = output_address & 0xFFFFFFFF;
34595- void *hypercall_page = hv_context.hypercall_page;
34596+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
34597
34598 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
34599 "=a"(hv_status_lo) : "d" (control_hi),
34600diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
34601index d8d1fad..b91caf7 100644
34602--- a/drivers/hv/hyperv_vmbus.h
34603+++ b/drivers/hv/hyperv_vmbus.h
34604@@ -594,7 +594,7 @@ enum vmbus_connect_state {
34605 struct vmbus_connection {
34606 enum vmbus_connect_state conn_state;
34607
34608- atomic_t next_gpadl_handle;
34609+ atomic_unchecked_t next_gpadl_handle;
34610
34611 /*
34612 * Represents channel interrupts. Each bit position represents a
34613diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
34614index 8e1a9ec..4687821 100644
34615--- a/drivers/hv/vmbus_drv.c
34616+++ b/drivers/hv/vmbus_drv.c
34617@@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
34618 {
34619 int ret = 0;
34620
34621- static atomic_t device_num = ATOMIC_INIT(0);
34622+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
34623
34624 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
34625- atomic_inc_return(&device_num));
34626+ atomic_inc_return_unchecked(&device_num));
34627
34628 child_device_obj->device.bus = &hv_bus;
34629 child_device_obj->device.parent = &hv_acpi_dev->dev;
34630diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
34631index d64923d..72591e8 100644
34632--- a/drivers/hwmon/coretemp.c
34633+++ b/drivers/hwmon/coretemp.c
34634@@ -790,7 +790,7 @@ static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb,
34635 return NOTIFY_OK;
34636 }
34637
34638-static struct notifier_block coretemp_cpu_notifier __refdata = {
34639+static struct notifier_block coretemp_cpu_notifier = {
34640 .notifier_call = coretemp_cpu_callback,
34641 };
34642
34643diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
34644index 1c85d39..55ed3cf 100644
34645--- a/drivers/hwmon/sht15.c
34646+++ b/drivers/hwmon/sht15.c
34647@@ -169,7 +169,7 @@ struct sht15_data {
34648 int supply_uV;
34649 bool supply_uV_valid;
34650 struct work_struct update_supply_work;
34651- atomic_t interrupt_handled;
34652+ atomic_unchecked_t interrupt_handled;
34653 };
34654
34655 /**
34656@@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
34657 return ret;
34658
34659 gpio_direction_input(data->pdata->gpio_data);
34660- atomic_set(&data->interrupt_handled, 0);
34661+ atomic_set_unchecked(&data->interrupt_handled, 0);
34662
34663 enable_irq(gpio_to_irq(data->pdata->gpio_data));
34664 if (gpio_get_value(data->pdata->gpio_data) == 0) {
34665 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
34666 /* Only relevant if the interrupt hasn't occurred. */
34667- if (!atomic_read(&data->interrupt_handled))
34668+ if (!atomic_read_unchecked(&data->interrupt_handled))
34669 schedule_work(&data->read_work);
34670 }
34671 ret = wait_event_timeout(data->wait_queue,
34672@@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
34673
34674 /* First disable the interrupt */
34675 disable_irq_nosync(irq);
34676- atomic_inc(&data->interrupt_handled);
34677+ atomic_inc_unchecked(&data->interrupt_handled);
34678 /* Then schedule a reading work struct */
34679 if (data->state != SHT15_READING_NOTHING)
34680 schedule_work(&data->read_work);
34681@@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
34682 * If not, then start the interrupt again - care here as could
34683 * have gone low in meantime so verify it hasn't!
34684 */
34685- atomic_set(&data->interrupt_handled, 0);
34686+ atomic_set_unchecked(&data->interrupt_handled, 0);
34687 enable_irq(gpio_to_irq(data->pdata->gpio_data));
34688 /* If still not occurred or another handler was scheduled */
34689 if (gpio_get_value(data->pdata->gpio_data)
34690- || atomic_read(&data->interrupt_handled))
34691+ || atomic_read_unchecked(&data->interrupt_handled))
34692 return;
34693 }
34694
34695diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
34696index 76f157b..9c0db1b 100644
34697--- a/drivers/hwmon/via-cputemp.c
34698+++ b/drivers/hwmon/via-cputemp.c
34699@@ -296,7 +296,7 @@ static int __cpuinit via_cputemp_cpu_callback(struct notifier_block *nfb,
34700 return NOTIFY_OK;
34701 }
34702
34703-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
34704+static struct notifier_block via_cputemp_cpu_notifier = {
34705 .notifier_call = via_cputemp_cpu_callback,
34706 };
34707
34708diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
34709index 378fcb5..5e91fa8 100644
34710--- a/drivers/i2c/busses/i2c-amd756-s4882.c
34711+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
34712@@ -43,7 +43,7 @@
34713 extern struct i2c_adapter amd756_smbus;
34714
34715 static struct i2c_adapter *s4882_adapter;
34716-static struct i2c_algorithm *s4882_algo;
34717+static i2c_algorithm_no_const *s4882_algo;
34718
34719 /* Wrapper access functions for multiplexed SMBus */
34720 static DEFINE_MUTEX(amd756_lock);
34721diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
34722index 29015eb..af2d8e9 100644
34723--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
34724+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
34725@@ -41,7 +41,7 @@
34726 extern struct i2c_adapter *nforce2_smbus;
34727
34728 static struct i2c_adapter *s4985_adapter;
34729-static struct i2c_algorithm *s4985_algo;
34730+static i2c_algorithm_no_const *s4985_algo;
34731
34732 /* Wrapper access functions for multiplexed SMBus */
34733 static DEFINE_MUTEX(nforce2_lock);
34734diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
34735index 8126824..55a2798 100644
34736--- a/drivers/ide/ide-cd.c
34737+++ b/drivers/ide/ide-cd.c
34738@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
34739 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
34740 if ((unsigned long)buf & alignment
34741 || blk_rq_bytes(rq) & q->dma_pad_mask
34742- || object_is_on_stack(buf))
34743+ || object_starts_on_stack(buf))
34744 drive->dma = 0;
34745 }
34746 }
34747diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
34748index 394fea2..c833880 100644
34749--- a/drivers/infiniband/core/cm.c
34750+++ b/drivers/infiniband/core/cm.c
34751@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
34752
34753 struct cm_counter_group {
34754 struct kobject obj;
34755- atomic_long_t counter[CM_ATTR_COUNT];
34756+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
34757 };
34758
34759 struct cm_counter_attribute {
34760@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
34761 struct ib_mad_send_buf *msg = NULL;
34762 int ret;
34763
34764- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34765+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34766 counter[CM_REQ_COUNTER]);
34767
34768 /* Quick state check to discard duplicate REQs. */
34769@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
34770 if (!cm_id_priv)
34771 return;
34772
34773- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34774+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34775 counter[CM_REP_COUNTER]);
34776 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
34777 if (ret)
34778@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
34779 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
34780 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
34781 spin_unlock_irq(&cm_id_priv->lock);
34782- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34783+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34784 counter[CM_RTU_COUNTER]);
34785 goto out;
34786 }
34787@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
34788 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
34789 dreq_msg->local_comm_id);
34790 if (!cm_id_priv) {
34791- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34792+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34793 counter[CM_DREQ_COUNTER]);
34794 cm_issue_drep(work->port, work->mad_recv_wc);
34795 return -EINVAL;
34796@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
34797 case IB_CM_MRA_REP_RCVD:
34798 break;
34799 case IB_CM_TIMEWAIT:
34800- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34801+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34802 counter[CM_DREQ_COUNTER]);
34803 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
34804 goto unlock;
34805@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
34806 cm_free_msg(msg);
34807 goto deref;
34808 case IB_CM_DREQ_RCVD:
34809- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34810+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34811 counter[CM_DREQ_COUNTER]);
34812 goto unlock;
34813 default:
34814@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
34815 ib_modify_mad(cm_id_priv->av.port->mad_agent,
34816 cm_id_priv->msg, timeout)) {
34817 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
34818- atomic_long_inc(&work->port->
34819+ atomic_long_inc_unchecked(&work->port->
34820 counter_group[CM_RECV_DUPLICATES].
34821 counter[CM_MRA_COUNTER]);
34822 goto out;
34823@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
34824 break;
34825 case IB_CM_MRA_REQ_RCVD:
34826 case IB_CM_MRA_REP_RCVD:
34827- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34828+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34829 counter[CM_MRA_COUNTER]);
34830 /* fall through */
34831 default:
34832@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
34833 case IB_CM_LAP_IDLE:
34834 break;
34835 case IB_CM_MRA_LAP_SENT:
34836- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34837+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34838 counter[CM_LAP_COUNTER]);
34839 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
34840 goto unlock;
34841@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
34842 cm_free_msg(msg);
34843 goto deref;
34844 case IB_CM_LAP_RCVD:
34845- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34846+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34847 counter[CM_LAP_COUNTER]);
34848 goto unlock;
34849 default:
34850@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
34851 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
34852 if (cur_cm_id_priv) {
34853 spin_unlock_irq(&cm.lock);
34854- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34855+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34856 counter[CM_SIDR_REQ_COUNTER]);
34857 goto out; /* Duplicate message. */
34858 }
34859@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
34860 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
34861 msg->retries = 1;
34862
34863- atomic_long_add(1 + msg->retries,
34864+ atomic_long_add_unchecked(1 + msg->retries,
34865 &port->counter_group[CM_XMIT].counter[attr_index]);
34866 if (msg->retries)
34867- atomic_long_add(msg->retries,
34868+ atomic_long_add_unchecked(msg->retries,
34869 &port->counter_group[CM_XMIT_RETRIES].
34870 counter[attr_index]);
34871
34872@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
34873 }
34874
34875 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
34876- atomic_long_inc(&port->counter_group[CM_RECV].
34877+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
34878 counter[attr_id - CM_ATTR_ID_OFFSET]);
34879
34880 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
34881@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
34882 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
34883
34884 return sprintf(buf, "%ld\n",
34885- atomic_long_read(&group->counter[cm_attr->index]));
34886+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
34887 }
34888
34889 static const struct sysfs_ops cm_counter_ops = {
34890diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
34891index 176c8f9..2627b62 100644
34892--- a/drivers/infiniband/core/fmr_pool.c
34893+++ b/drivers/infiniband/core/fmr_pool.c
34894@@ -98,8 +98,8 @@ struct ib_fmr_pool {
34895
34896 struct task_struct *thread;
34897
34898- atomic_t req_ser;
34899- atomic_t flush_ser;
34900+ atomic_unchecked_t req_ser;
34901+ atomic_unchecked_t flush_ser;
34902
34903 wait_queue_head_t force_wait;
34904 };
34905@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
34906 struct ib_fmr_pool *pool = pool_ptr;
34907
34908 do {
34909- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
34910+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
34911 ib_fmr_batch_release(pool);
34912
34913- atomic_inc(&pool->flush_ser);
34914+ atomic_inc_unchecked(&pool->flush_ser);
34915 wake_up_interruptible(&pool->force_wait);
34916
34917 if (pool->flush_function)
34918@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
34919 }
34920
34921 set_current_state(TASK_INTERRUPTIBLE);
34922- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
34923+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
34924 !kthread_should_stop())
34925 schedule();
34926 __set_current_state(TASK_RUNNING);
34927@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
34928 pool->dirty_watermark = params->dirty_watermark;
34929 pool->dirty_len = 0;
34930 spin_lock_init(&pool->pool_lock);
34931- atomic_set(&pool->req_ser, 0);
34932- atomic_set(&pool->flush_ser, 0);
34933+ atomic_set_unchecked(&pool->req_ser, 0);
34934+ atomic_set_unchecked(&pool->flush_ser, 0);
34935 init_waitqueue_head(&pool->force_wait);
34936
34937 pool->thread = kthread_run(ib_fmr_cleanup_thread,
34938@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
34939 }
34940 spin_unlock_irq(&pool->pool_lock);
34941
34942- serial = atomic_inc_return(&pool->req_ser);
34943+ serial = atomic_inc_return_unchecked(&pool->req_ser);
34944 wake_up_process(pool->thread);
34945
34946 if (wait_event_interruptible(pool->force_wait,
34947- atomic_read(&pool->flush_ser) - serial >= 0))
34948+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
34949 return -EINTR;
34950
34951 return 0;
34952@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
34953 } else {
34954 list_add_tail(&fmr->list, &pool->dirty_list);
34955 if (++pool->dirty_len >= pool->dirty_watermark) {
34956- atomic_inc(&pool->req_ser);
34957+ atomic_inc_unchecked(&pool->req_ser);
34958 wake_up_process(pool->thread);
34959 }
34960 }
34961diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
34962index afd8179..598063f 100644
34963--- a/drivers/infiniband/hw/cxgb4/mem.c
34964+++ b/drivers/infiniband/hw/cxgb4/mem.c
34965@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
34966 int err;
34967 struct fw_ri_tpte tpt;
34968 u32 stag_idx;
34969- static atomic_t key;
34970+ static atomic_unchecked_t key;
34971
34972 if (c4iw_fatal_error(rdev))
34973 return -EIO;
34974@@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
34975 if (rdev->stats.stag.cur > rdev->stats.stag.max)
34976 rdev->stats.stag.max = rdev->stats.stag.cur;
34977 mutex_unlock(&rdev->stats.lock);
34978- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
34979+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
34980 }
34981 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
34982 __func__, stag_state, type, pdid, stag_idx);
34983diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
34984index 79b3dbc..96e5fcc 100644
34985--- a/drivers/infiniband/hw/ipath/ipath_rc.c
34986+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
34987@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
34988 struct ib_atomic_eth *ateth;
34989 struct ipath_ack_entry *e;
34990 u64 vaddr;
34991- atomic64_t *maddr;
34992+ atomic64_unchecked_t *maddr;
34993 u64 sdata;
34994 u32 rkey;
34995 u8 next;
34996@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
34997 IB_ACCESS_REMOTE_ATOMIC)))
34998 goto nack_acc_unlck;
34999 /* Perform atomic OP and save result. */
35000- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
35001+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
35002 sdata = be64_to_cpu(ateth->swap_data);
35003 e = &qp->s_ack_queue[qp->r_head_ack_queue];
35004 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
35005- (u64) atomic64_add_return(sdata, maddr) - sdata :
35006+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
35007 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
35008 be64_to_cpu(ateth->compare_data),
35009 sdata);
35010diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
35011index 1f95bba..9530f87 100644
35012--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
35013+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
35014@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
35015 unsigned long flags;
35016 struct ib_wc wc;
35017 u64 sdata;
35018- atomic64_t *maddr;
35019+ atomic64_unchecked_t *maddr;
35020 enum ib_wc_status send_status;
35021
35022 /*
35023@@ -382,11 +382,11 @@ again:
35024 IB_ACCESS_REMOTE_ATOMIC)))
35025 goto acc_err;
35026 /* Perform atomic OP and save result. */
35027- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
35028+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
35029 sdata = wqe->wr.wr.atomic.compare_add;
35030 *(u64 *) sqp->s_sge.sge.vaddr =
35031 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
35032- (u64) atomic64_add_return(sdata, maddr) - sdata :
35033+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
35034 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
35035 sdata, wqe->wr.wr.atomic.swap);
35036 goto send_comp;
35037diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
35038index 5b152a3..c1f3e83 100644
35039--- a/drivers/infiniband/hw/nes/nes.c
35040+++ b/drivers/infiniband/hw/nes/nes.c
35041@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
35042 LIST_HEAD(nes_adapter_list);
35043 static LIST_HEAD(nes_dev_list);
35044
35045-atomic_t qps_destroyed;
35046+atomic_unchecked_t qps_destroyed;
35047
35048 static unsigned int ee_flsh_adapter;
35049 static unsigned int sysfs_nonidx_addr;
35050@@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
35051 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
35052 struct nes_adapter *nesadapter = nesdev->nesadapter;
35053
35054- atomic_inc(&qps_destroyed);
35055+ atomic_inc_unchecked(&qps_destroyed);
35056
35057 /* Free the control structures */
35058
35059diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
35060index 33cc589..3bd6538 100644
35061--- a/drivers/infiniband/hw/nes/nes.h
35062+++ b/drivers/infiniband/hw/nes/nes.h
35063@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
35064 extern unsigned int wqm_quanta;
35065 extern struct list_head nes_adapter_list;
35066
35067-extern atomic_t cm_connects;
35068-extern atomic_t cm_accepts;
35069-extern atomic_t cm_disconnects;
35070-extern atomic_t cm_closes;
35071-extern atomic_t cm_connecteds;
35072-extern atomic_t cm_connect_reqs;
35073-extern atomic_t cm_rejects;
35074-extern atomic_t mod_qp_timouts;
35075-extern atomic_t qps_created;
35076-extern atomic_t qps_destroyed;
35077-extern atomic_t sw_qps_destroyed;
35078+extern atomic_unchecked_t cm_connects;
35079+extern atomic_unchecked_t cm_accepts;
35080+extern atomic_unchecked_t cm_disconnects;
35081+extern atomic_unchecked_t cm_closes;
35082+extern atomic_unchecked_t cm_connecteds;
35083+extern atomic_unchecked_t cm_connect_reqs;
35084+extern atomic_unchecked_t cm_rejects;
35085+extern atomic_unchecked_t mod_qp_timouts;
35086+extern atomic_unchecked_t qps_created;
35087+extern atomic_unchecked_t qps_destroyed;
35088+extern atomic_unchecked_t sw_qps_destroyed;
35089 extern u32 mh_detected;
35090 extern u32 mh_pauses_sent;
35091 extern u32 cm_packets_sent;
35092@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
35093 extern u32 cm_packets_received;
35094 extern u32 cm_packets_dropped;
35095 extern u32 cm_packets_retrans;
35096-extern atomic_t cm_listens_created;
35097-extern atomic_t cm_listens_destroyed;
35098+extern atomic_unchecked_t cm_listens_created;
35099+extern atomic_unchecked_t cm_listens_destroyed;
35100 extern u32 cm_backlog_drops;
35101-extern atomic_t cm_loopbacks;
35102-extern atomic_t cm_nodes_created;
35103-extern atomic_t cm_nodes_destroyed;
35104-extern atomic_t cm_accel_dropped_pkts;
35105-extern atomic_t cm_resets_recvd;
35106-extern atomic_t pau_qps_created;
35107-extern atomic_t pau_qps_destroyed;
35108+extern atomic_unchecked_t cm_loopbacks;
35109+extern atomic_unchecked_t cm_nodes_created;
35110+extern atomic_unchecked_t cm_nodes_destroyed;
35111+extern atomic_unchecked_t cm_accel_dropped_pkts;
35112+extern atomic_unchecked_t cm_resets_recvd;
35113+extern atomic_unchecked_t pau_qps_created;
35114+extern atomic_unchecked_t pau_qps_destroyed;
35115
35116 extern u32 int_mod_timer_init;
35117 extern u32 int_mod_cq_depth_256;
35118diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
35119index 22ea67e..dcbe3bc 100644
35120--- a/drivers/infiniband/hw/nes/nes_cm.c
35121+++ b/drivers/infiniband/hw/nes/nes_cm.c
35122@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
35123 u32 cm_packets_retrans;
35124 u32 cm_packets_created;
35125 u32 cm_packets_received;
35126-atomic_t cm_listens_created;
35127-atomic_t cm_listens_destroyed;
35128+atomic_unchecked_t cm_listens_created;
35129+atomic_unchecked_t cm_listens_destroyed;
35130 u32 cm_backlog_drops;
35131-atomic_t cm_loopbacks;
35132-atomic_t cm_nodes_created;
35133-atomic_t cm_nodes_destroyed;
35134-atomic_t cm_accel_dropped_pkts;
35135-atomic_t cm_resets_recvd;
35136+atomic_unchecked_t cm_loopbacks;
35137+atomic_unchecked_t cm_nodes_created;
35138+atomic_unchecked_t cm_nodes_destroyed;
35139+atomic_unchecked_t cm_accel_dropped_pkts;
35140+atomic_unchecked_t cm_resets_recvd;
35141
35142 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
35143 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
35144@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
35145
35146 static struct nes_cm_core *g_cm_core;
35147
35148-atomic_t cm_connects;
35149-atomic_t cm_accepts;
35150-atomic_t cm_disconnects;
35151-atomic_t cm_closes;
35152-atomic_t cm_connecteds;
35153-atomic_t cm_connect_reqs;
35154-atomic_t cm_rejects;
35155+atomic_unchecked_t cm_connects;
35156+atomic_unchecked_t cm_accepts;
35157+atomic_unchecked_t cm_disconnects;
35158+atomic_unchecked_t cm_closes;
35159+atomic_unchecked_t cm_connecteds;
35160+atomic_unchecked_t cm_connect_reqs;
35161+atomic_unchecked_t cm_rejects;
35162
35163 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
35164 {
35165@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
35166 kfree(listener);
35167 listener = NULL;
35168 ret = 0;
35169- atomic_inc(&cm_listens_destroyed);
35170+ atomic_inc_unchecked(&cm_listens_destroyed);
35171 } else {
35172 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
35173 }
35174@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
35175 cm_node->rem_mac);
35176
35177 add_hte_node(cm_core, cm_node);
35178- atomic_inc(&cm_nodes_created);
35179+ atomic_inc_unchecked(&cm_nodes_created);
35180
35181 return cm_node;
35182 }
35183@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
35184 }
35185
35186 atomic_dec(&cm_core->node_cnt);
35187- atomic_inc(&cm_nodes_destroyed);
35188+ atomic_inc_unchecked(&cm_nodes_destroyed);
35189 nesqp = cm_node->nesqp;
35190 if (nesqp) {
35191 nesqp->cm_node = NULL;
35192@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
35193
35194 static void drop_packet(struct sk_buff *skb)
35195 {
35196- atomic_inc(&cm_accel_dropped_pkts);
35197+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
35198 dev_kfree_skb_any(skb);
35199 }
35200
35201@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
35202 {
35203
35204 int reset = 0; /* whether to send reset in case of err.. */
35205- atomic_inc(&cm_resets_recvd);
35206+ atomic_inc_unchecked(&cm_resets_recvd);
35207 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
35208 " refcnt=%d\n", cm_node, cm_node->state,
35209 atomic_read(&cm_node->ref_count));
35210@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
35211 rem_ref_cm_node(cm_node->cm_core, cm_node);
35212 return NULL;
35213 }
35214- atomic_inc(&cm_loopbacks);
35215+ atomic_inc_unchecked(&cm_loopbacks);
35216 loopbackremotenode->loopbackpartner = cm_node;
35217 loopbackremotenode->tcp_cntxt.rcv_wscale =
35218 NES_CM_DEFAULT_RCV_WND_SCALE;
35219@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
35220 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
35221 else {
35222 rem_ref_cm_node(cm_core, cm_node);
35223- atomic_inc(&cm_accel_dropped_pkts);
35224+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
35225 dev_kfree_skb_any(skb);
35226 }
35227 break;
35228@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
35229
35230 if ((cm_id) && (cm_id->event_handler)) {
35231 if (issue_disconn) {
35232- atomic_inc(&cm_disconnects);
35233+ atomic_inc_unchecked(&cm_disconnects);
35234 cm_event.event = IW_CM_EVENT_DISCONNECT;
35235 cm_event.status = disconn_status;
35236 cm_event.local_addr = cm_id->local_addr;
35237@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
35238 }
35239
35240 if (issue_close) {
35241- atomic_inc(&cm_closes);
35242+ atomic_inc_unchecked(&cm_closes);
35243 nes_disconnect(nesqp, 1);
35244
35245 cm_id->provider_data = nesqp;
35246@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
35247
35248 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
35249 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
35250- atomic_inc(&cm_accepts);
35251+ atomic_inc_unchecked(&cm_accepts);
35252
35253 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
35254 netdev_refcnt_read(nesvnic->netdev));
35255@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
35256 struct nes_cm_core *cm_core;
35257 u8 *start_buff;
35258
35259- atomic_inc(&cm_rejects);
35260+ atomic_inc_unchecked(&cm_rejects);
35261 cm_node = (struct nes_cm_node *)cm_id->provider_data;
35262 loopback = cm_node->loopbackpartner;
35263 cm_core = cm_node->cm_core;
35264@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
35265 ntohl(cm_id->local_addr.sin_addr.s_addr),
35266 ntohs(cm_id->local_addr.sin_port));
35267
35268- atomic_inc(&cm_connects);
35269+ atomic_inc_unchecked(&cm_connects);
35270 nesqp->active_conn = 1;
35271
35272 /* cache the cm_id in the qp */
35273@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
35274 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
35275 return err;
35276 }
35277- atomic_inc(&cm_listens_created);
35278+ atomic_inc_unchecked(&cm_listens_created);
35279 }
35280
35281 cm_id->add_ref(cm_id);
35282@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
35283
35284 if (nesqp->destroyed)
35285 return;
35286- atomic_inc(&cm_connecteds);
35287+ atomic_inc_unchecked(&cm_connecteds);
35288 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
35289 " local port 0x%04X. jiffies = %lu.\n",
35290 nesqp->hwqp.qp_id,
35291@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
35292
35293 cm_id->add_ref(cm_id);
35294 ret = cm_id->event_handler(cm_id, &cm_event);
35295- atomic_inc(&cm_closes);
35296+ atomic_inc_unchecked(&cm_closes);
35297 cm_event.event = IW_CM_EVENT_CLOSE;
35298 cm_event.status = 0;
35299 cm_event.provider_data = cm_id->provider_data;
35300@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
35301 return;
35302 cm_id = cm_node->cm_id;
35303
35304- atomic_inc(&cm_connect_reqs);
35305+ atomic_inc_unchecked(&cm_connect_reqs);
35306 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
35307 cm_node, cm_id, jiffies);
35308
35309@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
35310 return;
35311 cm_id = cm_node->cm_id;
35312
35313- atomic_inc(&cm_connect_reqs);
35314+ atomic_inc_unchecked(&cm_connect_reqs);
35315 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
35316 cm_node, cm_id, jiffies);
35317
35318diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
35319index 4166452..fc952c3 100644
35320--- a/drivers/infiniband/hw/nes/nes_mgt.c
35321+++ b/drivers/infiniband/hw/nes/nes_mgt.c
35322@@ -40,8 +40,8 @@
35323 #include "nes.h"
35324 #include "nes_mgt.h"
35325
35326-atomic_t pau_qps_created;
35327-atomic_t pau_qps_destroyed;
35328+atomic_unchecked_t pau_qps_created;
35329+atomic_unchecked_t pau_qps_destroyed;
35330
35331 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
35332 {
35333@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
35334 {
35335 struct sk_buff *skb;
35336 unsigned long flags;
35337- atomic_inc(&pau_qps_destroyed);
35338+ atomic_inc_unchecked(&pau_qps_destroyed);
35339
35340 /* Free packets that have not yet been forwarded */
35341 /* Lock is acquired by skb_dequeue when removing the skb */
35342@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
35343 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
35344 skb_queue_head_init(&nesqp->pau_list);
35345 spin_lock_init(&nesqp->pau_lock);
35346- atomic_inc(&pau_qps_created);
35347+ atomic_inc_unchecked(&pau_qps_created);
35348 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
35349 }
35350
35351diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
35352index 9542e16..a008c40 100644
35353--- a/drivers/infiniband/hw/nes/nes_nic.c
35354+++ b/drivers/infiniband/hw/nes/nes_nic.c
35355@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
35356 target_stat_values[++index] = mh_detected;
35357 target_stat_values[++index] = mh_pauses_sent;
35358 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
35359- target_stat_values[++index] = atomic_read(&cm_connects);
35360- target_stat_values[++index] = atomic_read(&cm_accepts);
35361- target_stat_values[++index] = atomic_read(&cm_disconnects);
35362- target_stat_values[++index] = atomic_read(&cm_connecteds);
35363- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
35364- target_stat_values[++index] = atomic_read(&cm_rejects);
35365- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
35366- target_stat_values[++index] = atomic_read(&qps_created);
35367- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
35368- target_stat_values[++index] = atomic_read(&qps_destroyed);
35369- target_stat_values[++index] = atomic_read(&cm_closes);
35370+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
35371+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
35372+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
35373+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
35374+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
35375+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
35376+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
35377+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
35378+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
35379+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
35380+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
35381 target_stat_values[++index] = cm_packets_sent;
35382 target_stat_values[++index] = cm_packets_bounced;
35383 target_stat_values[++index] = cm_packets_created;
35384 target_stat_values[++index] = cm_packets_received;
35385 target_stat_values[++index] = cm_packets_dropped;
35386 target_stat_values[++index] = cm_packets_retrans;
35387- target_stat_values[++index] = atomic_read(&cm_listens_created);
35388- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
35389+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
35390+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
35391 target_stat_values[++index] = cm_backlog_drops;
35392- target_stat_values[++index] = atomic_read(&cm_loopbacks);
35393- target_stat_values[++index] = atomic_read(&cm_nodes_created);
35394- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
35395- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
35396- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
35397+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
35398+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
35399+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
35400+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
35401+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
35402 target_stat_values[++index] = nesadapter->free_4kpbl;
35403 target_stat_values[++index] = nesadapter->free_256pbl;
35404 target_stat_values[++index] = int_mod_timer_init;
35405 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
35406 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
35407 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
35408- target_stat_values[++index] = atomic_read(&pau_qps_created);
35409- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
35410+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
35411+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
35412 }
35413
35414 /**
35415diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
35416index 07e4fba..685f041 100644
35417--- a/drivers/infiniband/hw/nes/nes_verbs.c
35418+++ b/drivers/infiniband/hw/nes/nes_verbs.c
35419@@ -46,9 +46,9 @@
35420
35421 #include <rdma/ib_umem.h>
35422
35423-atomic_t mod_qp_timouts;
35424-atomic_t qps_created;
35425-atomic_t sw_qps_destroyed;
35426+atomic_unchecked_t mod_qp_timouts;
35427+atomic_unchecked_t qps_created;
35428+atomic_unchecked_t sw_qps_destroyed;
35429
35430 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
35431
35432@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
35433 if (init_attr->create_flags)
35434 return ERR_PTR(-EINVAL);
35435
35436- atomic_inc(&qps_created);
35437+ atomic_inc_unchecked(&qps_created);
35438 switch (init_attr->qp_type) {
35439 case IB_QPT_RC:
35440 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
35441@@ -1462,7 +1462,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
35442 struct iw_cm_event cm_event;
35443 int ret = 0;
35444
35445- atomic_inc(&sw_qps_destroyed);
35446+ atomic_inc_unchecked(&sw_qps_destroyed);
35447 nesqp->destroyed = 1;
35448
35449 /* Blow away the connection if it exists. */
35450diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
35451index 4d11575..3e890e5 100644
35452--- a/drivers/infiniband/hw/qib/qib.h
35453+++ b/drivers/infiniband/hw/qib/qib.h
35454@@ -51,6 +51,7 @@
35455 #include <linux/completion.h>
35456 #include <linux/kref.h>
35457 #include <linux/sched.h>
35458+#include <linux/slab.h>
35459
35460 #include "qib_common.h"
35461 #include "qib_verbs.h"
35462diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
35463index da739d9..da1c7f4 100644
35464--- a/drivers/input/gameport/gameport.c
35465+++ b/drivers/input/gameport/gameport.c
35466@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
35467 */
35468 static void gameport_init_port(struct gameport *gameport)
35469 {
35470- static atomic_t gameport_no = ATOMIC_INIT(0);
35471+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
35472
35473 __module_get(THIS_MODULE);
35474
35475 mutex_init(&gameport->drv_mutex);
35476 device_initialize(&gameport->dev);
35477 dev_set_name(&gameport->dev, "gameport%lu",
35478- (unsigned long)atomic_inc_return(&gameport_no) - 1);
35479+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
35480 gameport->dev.bus = &gameport_bus;
35481 gameport->dev.release = gameport_release_port;
35482 if (gameport->parent)
35483diff --git a/drivers/input/input.c b/drivers/input/input.c
35484index c044699..174d71a 100644
35485--- a/drivers/input/input.c
35486+++ b/drivers/input/input.c
35487@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
35488 */
35489 int input_register_device(struct input_dev *dev)
35490 {
35491- static atomic_t input_no = ATOMIC_INIT(0);
35492+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
35493 struct input_devres *devres = NULL;
35494 struct input_handler *handler;
35495 unsigned int packet_size;
35496@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
35497 dev->setkeycode = input_default_setkeycode;
35498
35499 dev_set_name(&dev->dev, "input%ld",
35500- (unsigned long) atomic_inc_return(&input_no) - 1);
35501+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
35502
35503 error = device_add(&dev->dev);
35504 if (error)
35505diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
35506index 04c69af..5f92d00 100644
35507--- a/drivers/input/joystick/sidewinder.c
35508+++ b/drivers/input/joystick/sidewinder.c
35509@@ -30,6 +30,7 @@
35510 #include <linux/kernel.h>
35511 #include <linux/module.h>
35512 #include <linux/slab.h>
35513+#include <linux/sched.h>
35514 #include <linux/init.h>
35515 #include <linux/input.h>
35516 #include <linux/gameport.h>
35517diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
35518index d6cbfe9..6225402 100644
35519--- a/drivers/input/joystick/xpad.c
35520+++ b/drivers/input/joystick/xpad.c
35521@@ -735,7 +735,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
35522
35523 static int xpad_led_probe(struct usb_xpad *xpad)
35524 {
35525- static atomic_t led_seq = ATOMIC_INIT(0);
35526+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
35527 long led_no;
35528 struct xpad_led *led;
35529 struct led_classdev *led_cdev;
35530@@ -748,7 +748,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
35531 if (!led)
35532 return -ENOMEM;
35533
35534- led_no = (long)atomic_inc_return(&led_seq) - 1;
35535+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
35536
35537 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
35538 led->xpad = xpad;
35539diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
35540index 4c842c3..590b0bf 100644
35541--- a/drivers/input/mousedev.c
35542+++ b/drivers/input/mousedev.c
35543@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
35544
35545 spin_unlock_irq(&client->packet_lock);
35546
35547- if (copy_to_user(buffer, data, count))
35548+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
35549 return -EFAULT;
35550
35551 return count;
35552diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
35553index 25fc597..558bf3b 100644
35554--- a/drivers/input/serio/serio.c
35555+++ b/drivers/input/serio/serio.c
35556@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
35557 */
35558 static void serio_init_port(struct serio *serio)
35559 {
35560- static atomic_t serio_no = ATOMIC_INIT(0);
35561+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
35562
35563 __module_get(THIS_MODULE);
35564
35565@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
35566 mutex_init(&serio->drv_mutex);
35567 device_initialize(&serio->dev);
35568 dev_set_name(&serio->dev, "serio%ld",
35569- (long)atomic_inc_return(&serio_no) - 1);
35570+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
35571 serio->dev.bus = &serio_bus;
35572 serio->dev.release = serio_release_port;
35573 serio->dev.groups = serio_device_attr_groups;
35574diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
35575index 89562a8..218999b 100644
35576--- a/drivers/isdn/capi/capi.c
35577+++ b/drivers/isdn/capi/capi.c
35578@@ -81,8 +81,8 @@ struct capiminor {
35579
35580 struct capi20_appl *ap;
35581 u32 ncci;
35582- atomic_t datahandle;
35583- atomic_t msgid;
35584+ atomic_unchecked_t datahandle;
35585+ atomic_unchecked_t msgid;
35586
35587 struct tty_port port;
35588 int ttyinstop;
35589@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
35590 capimsg_setu16(s, 2, mp->ap->applid);
35591 capimsg_setu8 (s, 4, CAPI_DATA_B3);
35592 capimsg_setu8 (s, 5, CAPI_RESP);
35593- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
35594+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
35595 capimsg_setu32(s, 8, mp->ncci);
35596 capimsg_setu16(s, 12, datahandle);
35597 }
35598@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
35599 mp->outbytes -= len;
35600 spin_unlock_bh(&mp->outlock);
35601
35602- datahandle = atomic_inc_return(&mp->datahandle);
35603+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
35604 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
35605 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
35606 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
35607 capimsg_setu16(skb->data, 2, mp->ap->applid);
35608 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
35609 capimsg_setu8 (skb->data, 5, CAPI_REQ);
35610- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
35611+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
35612 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
35613 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
35614 capimsg_setu16(skb->data, 16, len); /* Data length */
35615diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
35616index 67abf3f..076b3a6 100644
35617--- a/drivers/isdn/gigaset/interface.c
35618+++ b/drivers/isdn/gigaset/interface.c
35619@@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
35620 }
35621 tty->driver_data = cs;
35622
35623- ++cs->port.count;
35624+ atomic_inc(&cs->port.count);
35625
35626- if (cs->port.count == 1) {
35627+ if (atomic_read(&cs->port.count) == 1) {
35628 tty_port_tty_set(&cs->port, tty);
35629 tty->low_latency = 1;
35630 }
35631@@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
35632
35633 if (!cs->connected)
35634 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
35635- else if (!cs->port.count)
35636+ else if (!atomic_read(&cs->port.count))
35637 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35638- else if (!--cs->port.count)
35639+ else if (!atomic_dec_return(&cs->port.count))
35640 tty_port_tty_set(&cs->port, NULL);
35641
35642 mutex_unlock(&cs->mutex);
35643diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
35644index 821f7ac..28d4030 100644
35645--- a/drivers/isdn/hardware/avm/b1.c
35646+++ b/drivers/isdn/hardware/avm/b1.c
35647@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
35648 }
35649 if (left) {
35650 if (t4file->user) {
35651- if (copy_from_user(buf, dp, left))
35652+ if (left > sizeof buf || copy_from_user(buf, dp, left))
35653 return -EFAULT;
35654 } else {
35655 memcpy(buf, dp, left);
35656@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
35657 }
35658 if (left) {
35659 if (config->user) {
35660- if (copy_from_user(buf, dp, left))
35661+ if (left > sizeof buf || copy_from_user(buf, dp, left))
35662 return -EFAULT;
35663 } else {
35664 memcpy(buf, dp, left);
35665diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
35666index e09dc8a..15e2efb 100644
35667--- a/drivers/isdn/i4l/isdn_tty.c
35668+++ b/drivers/isdn/i4l/isdn_tty.c
35669@@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
35670
35671 #ifdef ISDN_DEBUG_MODEM_OPEN
35672 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
35673- port->count);
35674+ atomic_read(&port->count));
35675 #endif
35676- port->count++;
35677+ atomic_inc(&port->count);
35678 port->tty = tty;
35679 /*
35680 * Start up serial port
35681@@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
35682 #endif
35683 return;
35684 }
35685- if ((tty->count == 1) && (port->count != 1)) {
35686+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
35687 /*
35688 * Uh, oh. tty->count is 1, which means that the tty
35689 * structure will be freed. Info->count should always
35690@@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
35691 * serial port won't be shutdown.
35692 */
35693 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
35694- "info->count is %d\n", port->count);
35695- port->count = 1;
35696+ "info->count is %d\n", atomic_read(&port->count));
35697+ atomic_set(&port->count, 1);
35698 }
35699- if (--port->count < 0) {
35700+ if (atomic_dec_return(&port->count) < 0) {
35701 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
35702- info->line, port->count);
35703- port->count = 0;
35704+ info->line, atomic_read(&port->count));
35705+ atomic_set(&port->count, 0);
35706 }
35707- if (port->count) {
35708+ if (atomic_read(&port->count)) {
35709 #ifdef ISDN_DEBUG_MODEM_OPEN
35710 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
35711 #endif
35712@@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
35713 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
35714 return;
35715 isdn_tty_shutdown(info);
35716- port->count = 0;
35717+ atomic_set(&port->count, 0);
35718 port->flags &= ~ASYNC_NORMAL_ACTIVE;
35719 port->tty = NULL;
35720 wake_up_interruptible(&port->open_wait);
35721@@ -1975,7 +1975,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
35722 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
35723 modem_info *info = &dev->mdm.info[i];
35724
35725- if (info->port.count == 0)
35726+ if (atomic_read(&info->port.count) == 0)
35727 continue;
35728 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
35729 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
35730diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
35731index e74df7c..03a03ba 100644
35732--- a/drivers/isdn/icn/icn.c
35733+++ b/drivers/isdn/icn/icn.c
35734@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
35735 if (count > len)
35736 count = len;
35737 if (user) {
35738- if (copy_from_user(msg, buf, count))
35739+ if (count > sizeof msg || copy_from_user(msg, buf, count))
35740 return -EFAULT;
35741 } else
35742 memcpy(msg, buf, count);
35743diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
35744index a5ebc00..982886f 100644
35745--- a/drivers/lguest/core.c
35746+++ b/drivers/lguest/core.c
35747@@ -92,9 +92,17 @@ static __init int map_switcher(void)
35748 * it's worked so far. The end address needs +1 because __get_vm_area
35749 * allocates an extra guard page, so we need space for that.
35750 */
35751+
35752+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
35753+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
35754+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
35755+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
35756+#else
35757 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
35758 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
35759 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
35760+#endif
35761+
35762 if (!switcher_vma) {
35763 err = -ENOMEM;
35764 printk("lguest: could not map switcher pages high\n");
35765@@ -119,7 +127,7 @@ static __init int map_switcher(void)
35766 * Now the Switcher is mapped at the right address, we can't fail!
35767 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
35768 */
35769- memcpy(switcher_vma->addr, start_switcher_text,
35770+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
35771 end_switcher_text - start_switcher_text);
35772
35773 printk(KERN_INFO "lguest: mapped switcher at %p\n",
35774diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
35775index 4af12e1..0e89afe 100644
35776--- a/drivers/lguest/x86/core.c
35777+++ b/drivers/lguest/x86/core.c
35778@@ -59,7 +59,7 @@ static struct {
35779 /* Offset from where switcher.S was compiled to where we've copied it */
35780 static unsigned long switcher_offset(void)
35781 {
35782- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
35783+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
35784 }
35785
35786 /* This cpu's struct lguest_pages. */
35787@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
35788 * These copies are pretty cheap, so we do them unconditionally: */
35789 /* Save the current Host top-level page directory.
35790 */
35791+
35792+#ifdef CONFIG_PAX_PER_CPU_PGD
35793+ pages->state.host_cr3 = read_cr3();
35794+#else
35795 pages->state.host_cr3 = __pa(current->mm->pgd);
35796+#endif
35797+
35798 /*
35799 * Set up the Guest's page tables to see this CPU's pages (and no
35800 * other CPU's pages).
35801@@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
35802 * compiled-in switcher code and the high-mapped copy we just made.
35803 */
35804 for (i = 0; i < IDT_ENTRIES; i++)
35805- default_idt_entries[i] += switcher_offset();
35806+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
35807
35808 /*
35809 * Set up the Switcher's per-cpu areas.
35810@@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
35811 * it will be undisturbed when we switch. To change %cs and jump we
35812 * need this structure to feed to Intel's "lcall" instruction.
35813 */
35814- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
35815+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
35816 lguest_entry.segment = LGUEST_CS;
35817
35818 /*
35819diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
35820index 40634b0..4f5855e 100644
35821--- a/drivers/lguest/x86/switcher_32.S
35822+++ b/drivers/lguest/x86/switcher_32.S
35823@@ -87,6 +87,7 @@
35824 #include <asm/page.h>
35825 #include <asm/segment.h>
35826 #include <asm/lguest.h>
35827+#include <asm/processor-flags.h>
35828
35829 // We mark the start of the code to copy
35830 // It's placed in .text tho it's never run here
35831@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
35832 // Changes type when we load it: damn Intel!
35833 // For after we switch over our page tables
35834 // That entry will be read-only: we'd crash.
35835+
35836+#ifdef CONFIG_PAX_KERNEXEC
35837+ mov %cr0, %edx
35838+ xor $X86_CR0_WP, %edx
35839+ mov %edx, %cr0
35840+#endif
35841+
35842 movl $(GDT_ENTRY_TSS*8), %edx
35843 ltr %dx
35844
35845@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
35846 // Let's clear it again for our return.
35847 // The GDT descriptor of the Host
35848 // Points to the table after two "size" bytes
35849- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
35850+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
35851 // Clear "used" from type field (byte 5, bit 2)
35852- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
35853+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
35854+
35855+#ifdef CONFIG_PAX_KERNEXEC
35856+ mov %cr0, %eax
35857+ xor $X86_CR0_WP, %eax
35858+ mov %eax, %cr0
35859+#endif
35860
35861 // Once our page table's switched, the Guest is live!
35862 // The Host fades as we run this final step.
35863@@ -295,13 +309,12 @@ deliver_to_host:
35864 // I consulted gcc, and it gave
35865 // These instructions, which I gladly credit:
35866 leal (%edx,%ebx,8), %eax
35867- movzwl (%eax),%edx
35868- movl 4(%eax), %eax
35869- xorw %ax, %ax
35870- orl %eax, %edx
35871+ movl 4(%eax), %edx
35872+ movw (%eax), %dx
35873 // Now the address of the handler's in %edx
35874 // We call it now: its "iret" drops us home.
35875- jmp *%edx
35876+ ljmp $__KERNEL_CS, $1f
35877+1: jmp *%edx
35878
35879 // Every interrupt can come to us here
35880 // But we must truly tell each apart.
35881diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
35882index 7155945..4bcc562 100644
35883--- a/drivers/md/bitmap.c
35884+++ b/drivers/md/bitmap.c
35885@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
35886 chunk_kb ? "KB" : "B");
35887 if (bitmap->storage.file) {
35888 seq_printf(seq, ", file: ");
35889- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
35890+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
35891 }
35892
35893 seq_printf(seq, "\n");
35894diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
35895index 0666b5d..ed82cb4 100644
35896--- a/drivers/md/dm-ioctl.c
35897+++ b/drivers/md/dm-ioctl.c
35898@@ -1628,7 +1628,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
35899 cmd == DM_LIST_VERSIONS_CMD)
35900 return 0;
35901
35902- if ((cmd == DM_DEV_CREATE_CMD)) {
35903+ if (cmd == DM_DEV_CREATE_CMD) {
35904 if (!*param->name) {
35905 DMWARN("name not supplied when creating device");
35906 return -EINVAL;
35907diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
35908index fa51918..c26253c 100644
35909--- a/drivers/md/dm-raid1.c
35910+++ b/drivers/md/dm-raid1.c
35911@@ -40,7 +40,7 @@ enum dm_raid1_error {
35912
35913 struct mirror {
35914 struct mirror_set *ms;
35915- atomic_t error_count;
35916+ atomic_unchecked_t error_count;
35917 unsigned long error_type;
35918 struct dm_dev *dev;
35919 sector_t offset;
35920@@ -183,7 +183,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
35921 struct mirror *m;
35922
35923 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
35924- if (!atomic_read(&m->error_count))
35925+ if (!atomic_read_unchecked(&m->error_count))
35926 return m;
35927
35928 return NULL;
35929@@ -215,7 +215,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
35930 * simple way to tell if a device has encountered
35931 * errors.
35932 */
35933- atomic_inc(&m->error_count);
35934+ atomic_inc_unchecked(&m->error_count);
35935
35936 if (test_and_set_bit(error_type, &m->error_type))
35937 return;
35938@@ -406,7 +406,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
35939 struct mirror *m = get_default_mirror(ms);
35940
35941 do {
35942- if (likely(!atomic_read(&m->error_count)))
35943+ if (likely(!atomic_read_unchecked(&m->error_count)))
35944 return m;
35945
35946 if (m-- == ms->mirror)
35947@@ -420,7 +420,7 @@ static int default_ok(struct mirror *m)
35948 {
35949 struct mirror *default_mirror = get_default_mirror(m->ms);
35950
35951- return !atomic_read(&default_mirror->error_count);
35952+ return !atomic_read_unchecked(&default_mirror->error_count);
35953 }
35954
35955 static int mirror_available(struct mirror_set *ms, struct bio *bio)
35956@@ -557,7 +557,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
35957 */
35958 if (likely(region_in_sync(ms, region, 1)))
35959 m = choose_mirror(ms, bio->bi_sector);
35960- else if (m && atomic_read(&m->error_count))
35961+ else if (m && atomic_read_unchecked(&m->error_count))
35962 m = NULL;
35963
35964 if (likely(m))
35965@@ -924,7 +924,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
35966 }
35967
35968 ms->mirror[mirror].ms = ms;
35969- atomic_set(&(ms->mirror[mirror].error_count), 0);
35970+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
35971 ms->mirror[mirror].error_type = 0;
35972 ms->mirror[mirror].offset = offset;
35973
35974@@ -1337,7 +1337,7 @@ static void mirror_resume(struct dm_target *ti)
35975 */
35976 static char device_status_char(struct mirror *m)
35977 {
35978- if (!atomic_read(&(m->error_count)))
35979+ if (!atomic_read_unchecked(&(m->error_count)))
35980 return 'A';
35981
35982 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
35983diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
35984index c89cde8..9d184cf 100644
35985--- a/drivers/md/dm-stripe.c
35986+++ b/drivers/md/dm-stripe.c
35987@@ -20,7 +20,7 @@ struct stripe {
35988 struct dm_dev *dev;
35989 sector_t physical_start;
35990
35991- atomic_t error_count;
35992+ atomic_unchecked_t error_count;
35993 };
35994
35995 struct stripe_c {
35996@@ -184,7 +184,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
35997 kfree(sc);
35998 return r;
35999 }
36000- atomic_set(&(sc->stripe[i].error_count), 0);
36001+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
36002 }
36003
36004 ti->private = sc;
36005@@ -325,7 +325,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
36006 DMEMIT("%d ", sc->stripes);
36007 for (i = 0; i < sc->stripes; i++) {
36008 DMEMIT("%s ", sc->stripe[i].dev->name);
36009- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
36010+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
36011 'D' : 'A';
36012 }
36013 buffer[i] = '\0';
36014@@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
36015 */
36016 for (i = 0; i < sc->stripes; i++)
36017 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
36018- atomic_inc(&(sc->stripe[i].error_count));
36019- if (atomic_read(&(sc->stripe[i].error_count)) <
36020+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
36021+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
36022 DM_IO_ERROR_THRESHOLD)
36023 schedule_work(&sc->trigger_event);
36024 }
36025diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
36026index daf25d0..d74f49f 100644
36027--- a/drivers/md/dm-table.c
36028+++ b/drivers/md/dm-table.c
36029@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
36030 if (!dev_size)
36031 return 0;
36032
36033- if ((start >= dev_size) || (start + len > dev_size)) {
36034+ if ((start >= dev_size) || (len > dev_size - start)) {
36035 DMWARN("%s: %s too small for target: "
36036 "start=%llu, len=%llu, dev_size=%llu",
36037 dm_device_name(ti->table->md), bdevname(bdev, b),
36038diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
36039index 4d6e853..a234157 100644
36040--- a/drivers/md/dm-thin-metadata.c
36041+++ b/drivers/md/dm-thin-metadata.c
36042@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
36043 {
36044 pmd->info.tm = pmd->tm;
36045 pmd->info.levels = 2;
36046- pmd->info.value_type.context = pmd->data_sm;
36047+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
36048 pmd->info.value_type.size = sizeof(__le64);
36049 pmd->info.value_type.inc = data_block_inc;
36050 pmd->info.value_type.dec = data_block_dec;
36051@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
36052
36053 pmd->bl_info.tm = pmd->tm;
36054 pmd->bl_info.levels = 1;
36055- pmd->bl_info.value_type.context = pmd->data_sm;
36056+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
36057 pmd->bl_info.value_type.size = sizeof(__le64);
36058 pmd->bl_info.value_type.inc = data_block_inc;
36059 pmd->bl_info.value_type.dec = data_block_dec;
36060diff --git a/drivers/md/dm.c b/drivers/md/dm.c
36061index 314a0e2..1376406 100644
36062--- a/drivers/md/dm.c
36063+++ b/drivers/md/dm.c
36064@@ -170,9 +170,9 @@ struct mapped_device {
36065 /*
36066 * Event handling.
36067 */
36068- atomic_t event_nr;
36069+ atomic_unchecked_t event_nr;
36070 wait_queue_head_t eventq;
36071- atomic_t uevent_seq;
36072+ atomic_unchecked_t uevent_seq;
36073 struct list_head uevent_list;
36074 spinlock_t uevent_lock; /* Protect access to uevent_list */
36075
36076@@ -1872,8 +1872,8 @@ static struct mapped_device *alloc_dev(int minor)
36077 rwlock_init(&md->map_lock);
36078 atomic_set(&md->holders, 1);
36079 atomic_set(&md->open_count, 0);
36080- atomic_set(&md->event_nr, 0);
36081- atomic_set(&md->uevent_seq, 0);
36082+ atomic_set_unchecked(&md->event_nr, 0);
36083+ atomic_set_unchecked(&md->uevent_seq, 0);
36084 INIT_LIST_HEAD(&md->uevent_list);
36085 spin_lock_init(&md->uevent_lock);
36086
36087@@ -2014,7 +2014,7 @@ static void event_callback(void *context)
36088
36089 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
36090
36091- atomic_inc(&md->event_nr);
36092+ atomic_inc_unchecked(&md->event_nr);
36093 wake_up(&md->eventq);
36094 }
36095
36096@@ -2669,18 +2669,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
36097
36098 uint32_t dm_next_uevent_seq(struct mapped_device *md)
36099 {
36100- return atomic_add_return(1, &md->uevent_seq);
36101+ return atomic_add_return_unchecked(1, &md->uevent_seq);
36102 }
36103
36104 uint32_t dm_get_event_nr(struct mapped_device *md)
36105 {
36106- return atomic_read(&md->event_nr);
36107+ return atomic_read_unchecked(&md->event_nr);
36108 }
36109
36110 int dm_wait_event(struct mapped_device *md, int event_nr)
36111 {
36112 return wait_event_interruptible(md->eventq,
36113- (event_nr != atomic_read(&md->event_nr)));
36114+ (event_nr != atomic_read_unchecked(&md->event_nr)));
36115 }
36116
36117 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
36118diff --git a/drivers/md/md.c b/drivers/md/md.c
36119index 3db3d1b..9487468 100644
36120--- a/drivers/md/md.c
36121+++ b/drivers/md/md.c
36122@@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
36123 * start build, activate spare
36124 */
36125 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
36126-static atomic_t md_event_count;
36127+static atomic_unchecked_t md_event_count;
36128 void md_new_event(struct mddev *mddev)
36129 {
36130- atomic_inc(&md_event_count);
36131+ atomic_inc_unchecked(&md_event_count);
36132 wake_up(&md_event_waiters);
36133 }
36134 EXPORT_SYMBOL_GPL(md_new_event);
36135@@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
36136 */
36137 static void md_new_event_inintr(struct mddev *mddev)
36138 {
36139- atomic_inc(&md_event_count);
36140+ atomic_inc_unchecked(&md_event_count);
36141 wake_up(&md_event_waiters);
36142 }
36143
36144@@ -1503,7 +1503,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
36145 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
36146 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
36147 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
36148- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
36149+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
36150
36151 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
36152 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
36153@@ -1747,7 +1747,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
36154 else
36155 sb->resync_offset = cpu_to_le64(0);
36156
36157- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
36158+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
36159
36160 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
36161 sb->size = cpu_to_le64(mddev->dev_sectors);
36162@@ -2747,7 +2747,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
36163 static ssize_t
36164 errors_show(struct md_rdev *rdev, char *page)
36165 {
36166- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
36167+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
36168 }
36169
36170 static ssize_t
36171@@ -2756,7 +2756,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
36172 char *e;
36173 unsigned long n = simple_strtoul(buf, &e, 10);
36174 if (*buf && (*e == 0 || *e == '\n')) {
36175- atomic_set(&rdev->corrected_errors, n);
36176+ atomic_set_unchecked(&rdev->corrected_errors, n);
36177 return len;
36178 }
36179 return -EINVAL;
36180@@ -3203,8 +3203,8 @@ int md_rdev_init(struct md_rdev *rdev)
36181 rdev->sb_loaded = 0;
36182 rdev->bb_page = NULL;
36183 atomic_set(&rdev->nr_pending, 0);
36184- atomic_set(&rdev->read_errors, 0);
36185- atomic_set(&rdev->corrected_errors, 0);
36186+ atomic_set_unchecked(&rdev->read_errors, 0);
36187+ atomic_set_unchecked(&rdev->corrected_errors, 0);
36188
36189 INIT_LIST_HEAD(&rdev->same_set);
36190 init_waitqueue_head(&rdev->blocked_wait);
36191@@ -6980,7 +6980,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
36192
36193 spin_unlock(&pers_lock);
36194 seq_printf(seq, "\n");
36195- seq->poll_event = atomic_read(&md_event_count);
36196+ seq->poll_event = atomic_read_unchecked(&md_event_count);
36197 return 0;
36198 }
36199 if (v == (void*)2) {
36200@@ -7083,7 +7083,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
36201 return error;
36202
36203 seq = file->private_data;
36204- seq->poll_event = atomic_read(&md_event_count);
36205+ seq->poll_event = atomic_read_unchecked(&md_event_count);
36206 return error;
36207 }
36208
36209@@ -7097,7 +7097,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
36210 /* always allow read */
36211 mask = POLLIN | POLLRDNORM;
36212
36213- if (seq->poll_event != atomic_read(&md_event_count))
36214+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
36215 mask |= POLLERR | POLLPRI;
36216 return mask;
36217 }
36218@@ -7141,7 +7141,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
36219 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
36220 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
36221 (int)part_stat_read(&disk->part0, sectors[1]) -
36222- atomic_read(&disk->sync_io);
36223+ atomic_read_unchecked(&disk->sync_io);
36224 /* sync IO will cause sync_io to increase before the disk_stats
36225 * as sync_io is counted when a request starts, and
36226 * disk_stats is counted when it completes.
36227diff --git a/drivers/md/md.h b/drivers/md/md.h
36228index eca59c3..7c42285 100644
36229--- a/drivers/md/md.h
36230+++ b/drivers/md/md.h
36231@@ -94,13 +94,13 @@ struct md_rdev {
36232 * only maintained for arrays that
36233 * support hot removal
36234 */
36235- atomic_t read_errors; /* number of consecutive read errors that
36236+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
36237 * we have tried to ignore.
36238 */
36239 struct timespec last_read_error; /* monotonic time since our
36240 * last read error
36241 */
36242- atomic_t corrected_errors; /* number of corrected read errors,
36243+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
36244 * for reporting to userspace and storing
36245 * in superblock.
36246 */
36247@@ -434,7 +434,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
36248
36249 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
36250 {
36251- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
36252+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
36253 }
36254
36255 struct md_personality
36256diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
36257index 1cbfc6b..56e1dbb 100644
36258--- a/drivers/md/persistent-data/dm-space-map.h
36259+++ b/drivers/md/persistent-data/dm-space-map.h
36260@@ -60,6 +60,7 @@ struct dm_space_map {
36261 int (*root_size)(struct dm_space_map *sm, size_t *result);
36262 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
36263 };
36264+typedef struct dm_space_map __no_const dm_space_map_no_const;
36265
36266 /*----------------------------------------------------------------*/
36267
36268diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
36269index d5bddfc..b079b4b 100644
36270--- a/drivers/md/raid1.c
36271+++ b/drivers/md/raid1.c
36272@@ -1818,7 +1818,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
36273 if (r1_sync_page_io(rdev, sect, s,
36274 bio->bi_io_vec[idx].bv_page,
36275 READ) != 0)
36276- atomic_add(s, &rdev->corrected_errors);
36277+ atomic_add_unchecked(s, &rdev->corrected_errors);
36278 }
36279 sectors -= s;
36280 sect += s;
36281@@ -2040,7 +2040,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
36282 test_bit(In_sync, &rdev->flags)) {
36283 if (r1_sync_page_io(rdev, sect, s,
36284 conf->tmppage, READ)) {
36285- atomic_add(s, &rdev->corrected_errors);
36286+ atomic_add_unchecked(s, &rdev->corrected_errors);
36287 printk(KERN_INFO
36288 "md/raid1:%s: read error corrected "
36289 "(%d sectors at %llu on %s)\n",
36290diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
36291index 64d4824..8b9ea57 100644
36292--- a/drivers/md/raid10.c
36293+++ b/drivers/md/raid10.c
36294@@ -1877,7 +1877,7 @@ static void end_sync_read(struct bio *bio, int error)
36295 /* The write handler will notice the lack of
36296 * R10BIO_Uptodate and record any errors etc
36297 */
36298- atomic_add(r10_bio->sectors,
36299+ atomic_add_unchecked(r10_bio->sectors,
36300 &conf->mirrors[d].rdev->corrected_errors);
36301
36302 /* for reconstruct, we always reschedule after a read.
36303@@ -2226,7 +2226,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
36304 {
36305 struct timespec cur_time_mon;
36306 unsigned long hours_since_last;
36307- unsigned int read_errors = atomic_read(&rdev->read_errors);
36308+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
36309
36310 ktime_get_ts(&cur_time_mon);
36311
36312@@ -2248,9 +2248,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
36313 * overflowing the shift of read_errors by hours_since_last.
36314 */
36315 if (hours_since_last >= 8 * sizeof(read_errors))
36316- atomic_set(&rdev->read_errors, 0);
36317+ atomic_set_unchecked(&rdev->read_errors, 0);
36318 else
36319- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
36320+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
36321 }
36322
36323 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
36324@@ -2304,8 +2304,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
36325 return;
36326
36327 check_decay_read_errors(mddev, rdev);
36328- atomic_inc(&rdev->read_errors);
36329- if (atomic_read(&rdev->read_errors) > max_read_errors) {
36330+ atomic_inc_unchecked(&rdev->read_errors);
36331+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
36332 char b[BDEVNAME_SIZE];
36333 bdevname(rdev->bdev, b);
36334
36335@@ -2313,7 +2313,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
36336 "md/raid10:%s: %s: Raid device exceeded "
36337 "read_error threshold [cur %d:max %d]\n",
36338 mdname(mddev), b,
36339- atomic_read(&rdev->read_errors), max_read_errors);
36340+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
36341 printk(KERN_NOTICE
36342 "md/raid10:%s: %s: Failing raid device\n",
36343 mdname(mddev), b);
36344@@ -2468,7 +2468,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
36345 sect +
36346 choose_data_offset(r10_bio, rdev)),
36347 bdevname(rdev->bdev, b));
36348- atomic_add(s, &rdev->corrected_errors);
36349+ atomic_add_unchecked(s, &rdev->corrected_errors);
36350 }
36351
36352 rdev_dec_pending(rdev, mddev);
36353diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
36354index 19d77a0..56051b92 100644
36355--- a/drivers/md/raid5.c
36356+++ b/drivers/md/raid5.c
36357@@ -1797,21 +1797,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
36358 mdname(conf->mddev), STRIPE_SECTORS,
36359 (unsigned long long)s,
36360 bdevname(rdev->bdev, b));
36361- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
36362+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
36363 clear_bit(R5_ReadError, &sh->dev[i].flags);
36364 clear_bit(R5_ReWrite, &sh->dev[i].flags);
36365 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
36366 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
36367
36368- if (atomic_read(&rdev->read_errors))
36369- atomic_set(&rdev->read_errors, 0);
36370+ if (atomic_read_unchecked(&rdev->read_errors))
36371+ atomic_set_unchecked(&rdev->read_errors, 0);
36372 } else {
36373 const char *bdn = bdevname(rdev->bdev, b);
36374 int retry = 0;
36375 int set_bad = 0;
36376
36377 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
36378- atomic_inc(&rdev->read_errors);
36379+ atomic_inc_unchecked(&rdev->read_errors);
36380 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
36381 printk_ratelimited(
36382 KERN_WARNING
36383@@ -1839,7 +1839,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
36384 mdname(conf->mddev),
36385 (unsigned long long)s,
36386 bdn);
36387- } else if (atomic_read(&rdev->read_errors)
36388+ } else if (atomic_read_unchecked(&rdev->read_errors)
36389 > conf->max_nr_stripes)
36390 printk(KERN_WARNING
36391 "md/raid:%s: Too many read errors, failing device %s.\n",
36392diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
36393index d33101a..6b13069 100644
36394--- a/drivers/media/dvb-core/dvbdev.c
36395+++ b/drivers/media/dvb-core/dvbdev.c
36396@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
36397 const struct dvb_device *template, void *priv, int type)
36398 {
36399 struct dvb_device *dvbdev;
36400- struct file_operations *dvbdevfops;
36401+ file_operations_no_const *dvbdevfops;
36402 struct device *clsdev;
36403 int minor;
36404 int id;
36405diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
36406index 404f63a..4796533 100644
36407--- a/drivers/media/dvb-frontends/dib3000.h
36408+++ b/drivers/media/dvb-frontends/dib3000.h
36409@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
36410 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
36411 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
36412 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
36413-};
36414+} __no_const;
36415
36416 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
36417 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
36418diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
36419index 35cc526..9d90d83 100644
36420--- a/drivers/media/platform/omap/omap_vout.c
36421+++ b/drivers/media/platform/omap/omap_vout.c
36422@@ -63,7 +63,6 @@ enum omap_vout_channels {
36423 OMAP_VIDEO2,
36424 };
36425
36426-static struct videobuf_queue_ops video_vbq_ops;
36427 /* Variables configurable through module params*/
36428 static u32 video1_numbuffers = 3;
36429 static u32 video2_numbuffers = 3;
36430@@ -1010,6 +1009,12 @@ static int omap_vout_open(struct file *file)
36431 {
36432 struct videobuf_queue *q;
36433 struct omap_vout_device *vout = NULL;
36434+ static struct videobuf_queue_ops video_vbq_ops = {
36435+ .buf_setup = omap_vout_buffer_setup,
36436+ .buf_prepare = omap_vout_buffer_prepare,
36437+ .buf_release = omap_vout_buffer_release,
36438+ .buf_queue = omap_vout_buffer_queue,
36439+ };
36440
36441 vout = video_drvdata(file);
36442 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
36443@@ -1027,10 +1032,6 @@ static int omap_vout_open(struct file *file)
36444 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
36445
36446 q = &vout->vbq;
36447- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
36448- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
36449- video_vbq_ops.buf_release = omap_vout_buffer_release;
36450- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
36451 spin_lock_init(&vout->vbq_lock);
36452
36453 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
36454diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
36455index b671e20..34088b7 100644
36456--- a/drivers/media/platform/s5p-tv/mixer.h
36457+++ b/drivers/media/platform/s5p-tv/mixer.h
36458@@ -155,7 +155,7 @@ struct mxr_layer {
36459 /** layer index (unique identifier) */
36460 int idx;
36461 /** callbacks for layer methods */
36462- struct mxr_layer_ops ops;
36463+ struct mxr_layer_ops *ops;
36464 /** format array */
36465 const struct mxr_format **fmt_array;
36466 /** size of format array */
36467diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
36468index b93a21f..2535195 100644
36469--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
36470+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
36471@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
36472 {
36473 struct mxr_layer *layer;
36474 int ret;
36475- struct mxr_layer_ops ops = {
36476+ static struct mxr_layer_ops ops = {
36477 .release = mxr_graph_layer_release,
36478 .buffer_set = mxr_graph_buffer_set,
36479 .stream_set = mxr_graph_stream_set,
36480diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
36481index 3b1670a..595c939 100644
36482--- a/drivers/media/platform/s5p-tv/mixer_reg.c
36483+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
36484@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
36485 layer->update_buf = next;
36486 }
36487
36488- layer->ops.buffer_set(layer, layer->update_buf);
36489+ layer->ops->buffer_set(layer, layer->update_buf);
36490
36491 if (done && done != layer->shadow_buf)
36492 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
36493diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
36494index 1f3b743..e839271 100644
36495--- a/drivers/media/platform/s5p-tv/mixer_video.c
36496+++ b/drivers/media/platform/s5p-tv/mixer_video.c
36497@@ -208,7 +208,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
36498 layer->geo.src.height = layer->geo.src.full_height;
36499
36500 mxr_geometry_dump(mdev, &layer->geo);
36501- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
36502+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
36503 mxr_geometry_dump(mdev, &layer->geo);
36504 }
36505
36506@@ -226,7 +226,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
36507 layer->geo.dst.full_width = mbus_fmt.width;
36508 layer->geo.dst.full_height = mbus_fmt.height;
36509 layer->geo.dst.field = mbus_fmt.field;
36510- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
36511+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
36512
36513 mxr_geometry_dump(mdev, &layer->geo);
36514 }
36515@@ -332,7 +332,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
36516 /* set source size to highest accepted value */
36517 geo->src.full_width = max(geo->dst.full_width, pix->width);
36518 geo->src.full_height = max(geo->dst.full_height, pix->height);
36519- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
36520+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
36521 mxr_geometry_dump(mdev, &layer->geo);
36522 /* set cropping to total visible screen */
36523 geo->src.width = pix->width;
36524@@ -340,12 +340,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
36525 geo->src.x_offset = 0;
36526 geo->src.y_offset = 0;
36527 /* assure consistency of geometry */
36528- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
36529+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
36530 mxr_geometry_dump(mdev, &layer->geo);
36531 /* set full size to lowest possible value */
36532 geo->src.full_width = 0;
36533 geo->src.full_height = 0;
36534- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
36535+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
36536 mxr_geometry_dump(mdev, &layer->geo);
36537
36538 /* returning results */
36539@@ -472,7 +472,7 @@ static int mxr_s_selection(struct file *file, void *fh,
36540 target->width = s->r.width;
36541 target->height = s->r.height;
36542
36543- layer->ops.fix_geometry(layer, stage, s->flags);
36544+ layer->ops->fix_geometry(layer, stage, s->flags);
36545
36546 /* retrieve update selection rectangle */
36547 res.left = target->x_offset;
36548@@ -937,13 +937,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
36549 mxr_output_get(mdev);
36550
36551 mxr_layer_update_output(layer);
36552- layer->ops.format_set(layer);
36553+ layer->ops->format_set(layer);
36554 /* enabling layer in hardware */
36555 spin_lock_irqsave(&layer->enq_slock, flags);
36556 layer->state = MXR_LAYER_STREAMING;
36557 spin_unlock_irqrestore(&layer->enq_slock, flags);
36558
36559- layer->ops.stream_set(layer, MXR_ENABLE);
36560+ layer->ops->stream_set(layer, MXR_ENABLE);
36561 mxr_streamer_get(mdev);
36562
36563 return 0;
36564@@ -1013,7 +1013,7 @@ static int stop_streaming(struct vb2_queue *vq)
36565 spin_unlock_irqrestore(&layer->enq_slock, flags);
36566
36567 /* disabling layer in hardware */
36568- layer->ops.stream_set(layer, MXR_DISABLE);
36569+ layer->ops->stream_set(layer, MXR_DISABLE);
36570 /* remove one streamer */
36571 mxr_streamer_put(mdev);
36572 /* allow changes in output configuration */
36573@@ -1052,8 +1052,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
36574
36575 void mxr_layer_release(struct mxr_layer *layer)
36576 {
36577- if (layer->ops.release)
36578- layer->ops.release(layer);
36579+ if (layer->ops->release)
36580+ layer->ops->release(layer);
36581 }
36582
36583 void mxr_base_layer_release(struct mxr_layer *layer)
36584@@ -1079,7 +1079,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
36585
36586 layer->mdev = mdev;
36587 layer->idx = idx;
36588- layer->ops = *ops;
36589+ layer->ops = ops;
36590
36591 spin_lock_init(&layer->enq_slock);
36592 INIT_LIST_HEAD(&layer->enq_list);
36593diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
36594index 3d13a63..da31bf1 100644
36595--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
36596+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
36597@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
36598 {
36599 struct mxr_layer *layer;
36600 int ret;
36601- struct mxr_layer_ops ops = {
36602+ static struct mxr_layer_ops ops = {
36603 .release = mxr_vp_layer_release,
36604 .buffer_set = mxr_vp_buffer_set,
36605 .stream_set = mxr_vp_stream_set,
36606diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
36607index 643d80a..56bb96b 100644
36608--- a/drivers/media/radio/radio-cadet.c
36609+++ b/drivers/media/radio/radio-cadet.c
36610@@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
36611 unsigned char readbuf[RDS_BUFFER];
36612 int i = 0;
36613
36614+ if (count > RDS_BUFFER)
36615+ return -EFAULT;
36616 mutex_lock(&dev->lock);
36617 if (dev->rdsstat == 0)
36618 cadet_start_rds(dev);
36619@@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
36620 while (i < count && dev->rdsin != dev->rdsout)
36621 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
36622
36623- if (i && copy_to_user(data, readbuf, i))
36624+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
36625 i = -EFAULT;
36626 unlock:
36627 mutex_unlock(&dev->lock);
36628diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
36629index 3940bb0..fb3952a 100644
36630--- a/drivers/media/usb/dvb-usb/cxusb.c
36631+++ b/drivers/media/usb/dvb-usb/cxusb.c
36632@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
36633
36634 struct dib0700_adapter_state {
36635 int (*set_param_save) (struct dvb_frontend *);
36636-};
36637+} __no_const;
36638
36639 static int dib7070_set_param_override(struct dvb_frontend *fe)
36640 {
36641diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
36642index 9382895..ac8093c 100644
36643--- a/drivers/media/usb/dvb-usb/dw2102.c
36644+++ b/drivers/media/usb/dvb-usb/dw2102.c
36645@@ -95,7 +95,7 @@ struct su3000_state {
36646
36647 struct s6x0_state {
36648 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
36649-};
36650+} __no_const;
36651
36652 /* debug */
36653 static int dvb_usb_dw2102_debug;
36654diff --git a/drivers/memstick/host/r592.c b/drivers/memstick/host/r592.c
36655index 29b2172..a7c5b31 100644
36656--- a/drivers/memstick/host/r592.c
36657+++ b/drivers/memstick/host/r592.c
36658@@ -454,7 +454,7 @@ static int r592_transfer_fifo_pio(struct r592_device *dev)
36659 /* Executes one TPC (data is read/written from small or large fifo) */
36660 static void r592_execute_tpc(struct r592_device *dev)
36661 {
36662- bool is_write = dev->req->tpc >= MS_TPC_SET_RW_REG_ADRS;
36663+ bool is_write;
36664 int len, error;
36665 u32 status, reg;
36666
36667@@ -463,6 +463,7 @@ static void r592_execute_tpc(struct r592_device *dev)
36668 return;
36669 }
36670
36671+ is_write = dev->req->tpc >= MS_TPC_SET_RW_REG_ADRS;
36672 len = dev->req->long_data ?
36673 dev->req->sg.length : dev->req->data_len;
36674
36675diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
36676index fb69baa..cf7ad22 100644
36677--- a/drivers/message/fusion/mptbase.c
36678+++ b/drivers/message/fusion/mptbase.c
36679@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
36680 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
36681 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
36682
36683+#ifdef CONFIG_GRKERNSEC_HIDESYM
36684+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
36685+#else
36686 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
36687 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
36688+#endif
36689+
36690 /*
36691 * Rounding UP to nearest 4-kB boundary here...
36692 */
36693diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
36694index fa43c39..daeb158 100644
36695--- a/drivers/message/fusion/mptsas.c
36696+++ b/drivers/message/fusion/mptsas.c
36697@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
36698 return 0;
36699 }
36700
36701+static inline void
36702+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
36703+{
36704+ if (phy_info->port_details) {
36705+ phy_info->port_details->rphy = rphy;
36706+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
36707+ ioc->name, rphy));
36708+ }
36709+
36710+ if (rphy) {
36711+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
36712+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
36713+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
36714+ ioc->name, rphy, rphy->dev.release));
36715+ }
36716+}
36717+
36718 /* no mutex */
36719 static void
36720 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
36721@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
36722 return NULL;
36723 }
36724
36725-static inline void
36726-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
36727-{
36728- if (phy_info->port_details) {
36729- phy_info->port_details->rphy = rphy;
36730- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
36731- ioc->name, rphy));
36732- }
36733-
36734- if (rphy) {
36735- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
36736- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
36737- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
36738- ioc->name, rphy, rphy->dev.release));
36739- }
36740-}
36741-
36742 static inline struct sas_port *
36743 mptsas_get_port(struct mptsas_phyinfo *phy_info)
36744 {
36745diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
36746index 164afa7..b6b2e74 100644
36747--- a/drivers/message/fusion/mptscsih.c
36748+++ b/drivers/message/fusion/mptscsih.c
36749@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
36750
36751 h = shost_priv(SChost);
36752
36753- if (h) {
36754- if (h->info_kbuf == NULL)
36755- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
36756- return h->info_kbuf;
36757- h->info_kbuf[0] = '\0';
36758+ if (!h)
36759+ return NULL;
36760
36761- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
36762- h->info_kbuf[size-1] = '\0';
36763- }
36764+ if (h->info_kbuf == NULL)
36765+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
36766+ return h->info_kbuf;
36767+ h->info_kbuf[0] = '\0';
36768+
36769+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
36770+ h->info_kbuf[size-1] = '\0';
36771
36772 return h->info_kbuf;
36773 }
36774diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
36775index 8001aa6..b137580 100644
36776--- a/drivers/message/i2o/i2o_proc.c
36777+++ b/drivers/message/i2o/i2o_proc.c
36778@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
36779 "Array Controller Device"
36780 };
36781
36782-static char *chtostr(char *tmp, u8 *chars, int n)
36783-{
36784- tmp[0] = 0;
36785- return strncat(tmp, (char *)chars, n);
36786-}
36787-
36788 static int i2o_report_query_status(struct seq_file *seq, int block_status,
36789 char *group)
36790 {
36791@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
36792 } *result;
36793
36794 i2o_exec_execute_ddm_table ddm_table;
36795- char tmp[28 + 1];
36796
36797 result = kmalloc(sizeof(*result), GFP_KERNEL);
36798 if (!result)
36799@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
36800
36801 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
36802 seq_printf(seq, "%-#8x", ddm_table.module_id);
36803- seq_printf(seq, "%-29s",
36804- chtostr(tmp, ddm_table.module_name_version, 28));
36805+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
36806 seq_printf(seq, "%9d ", ddm_table.data_size);
36807 seq_printf(seq, "%8d", ddm_table.code_size);
36808
36809@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
36810
36811 i2o_driver_result_table *result;
36812 i2o_driver_store_table *dst;
36813- char tmp[28 + 1];
36814
36815 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
36816 if (result == NULL)
36817@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
36818
36819 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
36820 seq_printf(seq, "%-#8x", dst->module_id);
36821- seq_printf(seq, "%-29s",
36822- chtostr(tmp, dst->module_name_version, 28));
36823- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
36824+ seq_printf(seq, "%-.28s", dst->module_name_version);
36825+ seq_printf(seq, "%-.8s", dst->date);
36826 seq_printf(seq, "%8d ", dst->module_size);
36827 seq_printf(seq, "%8d ", dst->mpb_size);
36828 seq_printf(seq, "0x%04x", dst->module_flags);
36829@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
36830 // == (allow) 512d bytes (max)
36831 static u16 *work16 = (u16 *) work32;
36832 int token;
36833- char tmp[16 + 1];
36834
36835 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
36836
36837@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
36838 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
36839 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
36840 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
36841- seq_printf(seq, "Vendor info : %s\n",
36842- chtostr(tmp, (u8 *) (work32 + 2), 16));
36843- seq_printf(seq, "Product info : %s\n",
36844- chtostr(tmp, (u8 *) (work32 + 6), 16));
36845- seq_printf(seq, "Description : %s\n",
36846- chtostr(tmp, (u8 *) (work32 + 10), 16));
36847- seq_printf(seq, "Product rev. : %s\n",
36848- chtostr(tmp, (u8 *) (work32 + 14), 8));
36849+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
36850+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
36851+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
36852+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
36853
36854 seq_printf(seq, "Serial number : ");
36855 print_serial_number(seq, (u8 *) (work32 + 16),
36856@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
36857 u8 pad[256]; // allow up to 256 byte (max) serial number
36858 } result;
36859
36860- char tmp[24 + 1];
36861-
36862 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
36863
36864 if (token < 0) {
36865@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
36866 }
36867
36868 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
36869- seq_printf(seq, "Module name : %s\n",
36870- chtostr(tmp, result.module_name, 24));
36871- seq_printf(seq, "Module revision : %s\n",
36872- chtostr(tmp, result.module_rev, 8));
36873+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
36874+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
36875
36876 seq_printf(seq, "Serial number : ");
36877 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
36878@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
36879 u8 instance_number[4];
36880 } result;
36881
36882- char tmp[64 + 1];
36883-
36884 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
36885
36886 if (token < 0) {
36887@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
36888 return 0;
36889 }
36890
36891- seq_printf(seq, "Device name : %s\n",
36892- chtostr(tmp, result.device_name, 64));
36893- seq_printf(seq, "Service name : %s\n",
36894- chtostr(tmp, result.service_name, 64));
36895- seq_printf(seq, "Physical name : %s\n",
36896- chtostr(tmp, result.physical_location, 64));
36897- seq_printf(seq, "Instance number : %s\n",
36898- chtostr(tmp, result.instance_number, 4));
36899+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
36900+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
36901+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
36902+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
36903
36904 return 0;
36905 }
36906diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
36907index a8c08f3..155fe3d 100644
36908--- a/drivers/message/i2o/iop.c
36909+++ b/drivers/message/i2o/iop.c
36910@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
36911
36912 spin_lock_irqsave(&c->context_list_lock, flags);
36913
36914- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
36915- atomic_inc(&c->context_list_counter);
36916+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
36917+ atomic_inc_unchecked(&c->context_list_counter);
36918
36919- entry->context = atomic_read(&c->context_list_counter);
36920+ entry->context = atomic_read_unchecked(&c->context_list_counter);
36921
36922 list_add(&entry->list, &c->context_list);
36923
36924@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
36925
36926 #if BITS_PER_LONG == 64
36927 spin_lock_init(&c->context_list_lock);
36928- atomic_set(&c->context_list_counter, 0);
36929+ atomic_set_unchecked(&c->context_list_counter, 0);
36930 INIT_LIST_HEAD(&c->context_list);
36931 #endif
36932
36933diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
36934index 45ece11..8efa218 100644
36935--- a/drivers/mfd/janz-cmodio.c
36936+++ b/drivers/mfd/janz-cmodio.c
36937@@ -13,6 +13,7 @@
36938
36939 #include <linux/kernel.h>
36940 #include <linux/module.h>
36941+#include <linux/slab.h>
36942 #include <linux/init.h>
36943 #include <linux/pci.h>
36944 #include <linux/interrupt.h>
36945diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
36946index 3aa9a96..59cf685 100644
36947--- a/drivers/misc/kgdbts.c
36948+++ b/drivers/misc/kgdbts.c
36949@@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
36950 char before[BREAK_INSTR_SIZE];
36951 char after[BREAK_INSTR_SIZE];
36952
36953- probe_kernel_read(before, (char *)kgdbts_break_test,
36954+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
36955 BREAK_INSTR_SIZE);
36956 init_simple_test();
36957 ts.tst = plant_and_detach_test;
36958@@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
36959 /* Activate test with initial breakpoint */
36960 if (!is_early)
36961 kgdb_breakpoint();
36962- probe_kernel_read(after, (char *)kgdbts_break_test,
36963+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
36964 BREAK_INSTR_SIZE);
36965 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
36966 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
36967diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
36968index 4a87e5c..76bdf5c 100644
36969--- a/drivers/misc/lis3lv02d/lis3lv02d.c
36970+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
36971@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
36972 * the lid is closed. This leads to interrupts as soon as a little move
36973 * is done.
36974 */
36975- atomic_inc(&lis3->count);
36976+ atomic_inc_unchecked(&lis3->count);
36977
36978 wake_up_interruptible(&lis3->misc_wait);
36979 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
36980@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
36981 if (lis3->pm_dev)
36982 pm_runtime_get_sync(lis3->pm_dev);
36983
36984- atomic_set(&lis3->count, 0);
36985+ atomic_set_unchecked(&lis3->count, 0);
36986 return 0;
36987 }
36988
36989@@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
36990 add_wait_queue(&lis3->misc_wait, &wait);
36991 while (true) {
36992 set_current_state(TASK_INTERRUPTIBLE);
36993- data = atomic_xchg(&lis3->count, 0);
36994+ data = atomic_xchg_unchecked(&lis3->count, 0);
36995 if (data)
36996 break;
36997
36998@@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
36999 struct lis3lv02d, miscdev);
37000
37001 poll_wait(file, &lis3->misc_wait, wait);
37002- if (atomic_read(&lis3->count))
37003+ if (atomic_read_unchecked(&lis3->count))
37004 return POLLIN | POLLRDNORM;
37005 return 0;
37006 }
37007diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
37008index c439c82..1f20f57 100644
37009--- a/drivers/misc/lis3lv02d/lis3lv02d.h
37010+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
37011@@ -297,7 +297,7 @@ struct lis3lv02d {
37012 struct input_polled_dev *idev; /* input device */
37013 struct platform_device *pdev; /* platform device */
37014 struct regulator_bulk_data regulators[2];
37015- atomic_t count; /* interrupt count after last read */
37016+ atomic_unchecked_t count; /* interrupt count after last read */
37017 union axis_conversion ac; /* hw -> logical axis */
37018 int mapped_btns[3];
37019
37020diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
37021index 2f30bad..c4c13d0 100644
37022--- a/drivers/misc/sgi-gru/gruhandles.c
37023+++ b/drivers/misc/sgi-gru/gruhandles.c
37024@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
37025 unsigned long nsec;
37026
37027 nsec = CLKS2NSEC(clks);
37028- atomic_long_inc(&mcs_op_statistics[op].count);
37029- atomic_long_add(nsec, &mcs_op_statistics[op].total);
37030+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
37031+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
37032 if (mcs_op_statistics[op].max < nsec)
37033 mcs_op_statistics[op].max = nsec;
37034 }
37035diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
37036index 950dbe9..eeef0f8 100644
37037--- a/drivers/misc/sgi-gru/gruprocfs.c
37038+++ b/drivers/misc/sgi-gru/gruprocfs.c
37039@@ -32,9 +32,9 @@
37040
37041 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
37042
37043-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
37044+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
37045 {
37046- unsigned long val = atomic_long_read(v);
37047+ unsigned long val = atomic_long_read_unchecked(v);
37048
37049 seq_printf(s, "%16lu %s\n", val, id);
37050 }
37051@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
37052
37053 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
37054 for (op = 0; op < mcsop_last; op++) {
37055- count = atomic_long_read(&mcs_op_statistics[op].count);
37056- total = atomic_long_read(&mcs_op_statistics[op].total);
37057+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
37058+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
37059 max = mcs_op_statistics[op].max;
37060 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
37061 count ? total / count : 0, max);
37062diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
37063index 5c3ce24..4915ccb 100644
37064--- a/drivers/misc/sgi-gru/grutables.h
37065+++ b/drivers/misc/sgi-gru/grutables.h
37066@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
37067 * GRU statistics.
37068 */
37069 struct gru_stats_s {
37070- atomic_long_t vdata_alloc;
37071- atomic_long_t vdata_free;
37072- atomic_long_t gts_alloc;
37073- atomic_long_t gts_free;
37074- atomic_long_t gms_alloc;
37075- atomic_long_t gms_free;
37076- atomic_long_t gts_double_allocate;
37077- atomic_long_t assign_context;
37078- atomic_long_t assign_context_failed;
37079- atomic_long_t free_context;
37080- atomic_long_t load_user_context;
37081- atomic_long_t load_kernel_context;
37082- atomic_long_t lock_kernel_context;
37083- atomic_long_t unlock_kernel_context;
37084- atomic_long_t steal_user_context;
37085- atomic_long_t steal_kernel_context;
37086- atomic_long_t steal_context_failed;
37087- atomic_long_t nopfn;
37088- atomic_long_t asid_new;
37089- atomic_long_t asid_next;
37090- atomic_long_t asid_wrap;
37091- atomic_long_t asid_reuse;
37092- atomic_long_t intr;
37093- atomic_long_t intr_cbr;
37094- atomic_long_t intr_tfh;
37095- atomic_long_t intr_spurious;
37096- atomic_long_t intr_mm_lock_failed;
37097- atomic_long_t call_os;
37098- atomic_long_t call_os_wait_queue;
37099- atomic_long_t user_flush_tlb;
37100- atomic_long_t user_unload_context;
37101- atomic_long_t user_exception;
37102- atomic_long_t set_context_option;
37103- atomic_long_t check_context_retarget_intr;
37104- atomic_long_t check_context_unload;
37105- atomic_long_t tlb_dropin;
37106- atomic_long_t tlb_preload_page;
37107- atomic_long_t tlb_dropin_fail_no_asid;
37108- atomic_long_t tlb_dropin_fail_upm;
37109- atomic_long_t tlb_dropin_fail_invalid;
37110- atomic_long_t tlb_dropin_fail_range_active;
37111- atomic_long_t tlb_dropin_fail_idle;
37112- atomic_long_t tlb_dropin_fail_fmm;
37113- atomic_long_t tlb_dropin_fail_no_exception;
37114- atomic_long_t tfh_stale_on_fault;
37115- atomic_long_t mmu_invalidate_range;
37116- atomic_long_t mmu_invalidate_page;
37117- atomic_long_t flush_tlb;
37118- atomic_long_t flush_tlb_gru;
37119- atomic_long_t flush_tlb_gru_tgh;
37120- atomic_long_t flush_tlb_gru_zero_asid;
37121+ atomic_long_unchecked_t vdata_alloc;
37122+ atomic_long_unchecked_t vdata_free;
37123+ atomic_long_unchecked_t gts_alloc;
37124+ atomic_long_unchecked_t gts_free;
37125+ atomic_long_unchecked_t gms_alloc;
37126+ atomic_long_unchecked_t gms_free;
37127+ atomic_long_unchecked_t gts_double_allocate;
37128+ atomic_long_unchecked_t assign_context;
37129+ atomic_long_unchecked_t assign_context_failed;
37130+ atomic_long_unchecked_t free_context;
37131+ atomic_long_unchecked_t load_user_context;
37132+ atomic_long_unchecked_t load_kernel_context;
37133+ atomic_long_unchecked_t lock_kernel_context;
37134+ atomic_long_unchecked_t unlock_kernel_context;
37135+ atomic_long_unchecked_t steal_user_context;
37136+ atomic_long_unchecked_t steal_kernel_context;
37137+ atomic_long_unchecked_t steal_context_failed;
37138+ atomic_long_unchecked_t nopfn;
37139+ atomic_long_unchecked_t asid_new;
37140+ atomic_long_unchecked_t asid_next;
37141+ atomic_long_unchecked_t asid_wrap;
37142+ atomic_long_unchecked_t asid_reuse;
37143+ atomic_long_unchecked_t intr;
37144+ atomic_long_unchecked_t intr_cbr;
37145+ atomic_long_unchecked_t intr_tfh;
37146+ atomic_long_unchecked_t intr_spurious;
37147+ atomic_long_unchecked_t intr_mm_lock_failed;
37148+ atomic_long_unchecked_t call_os;
37149+ atomic_long_unchecked_t call_os_wait_queue;
37150+ atomic_long_unchecked_t user_flush_tlb;
37151+ atomic_long_unchecked_t user_unload_context;
37152+ atomic_long_unchecked_t user_exception;
37153+ atomic_long_unchecked_t set_context_option;
37154+ atomic_long_unchecked_t check_context_retarget_intr;
37155+ atomic_long_unchecked_t check_context_unload;
37156+ atomic_long_unchecked_t tlb_dropin;
37157+ atomic_long_unchecked_t tlb_preload_page;
37158+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
37159+ atomic_long_unchecked_t tlb_dropin_fail_upm;
37160+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
37161+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
37162+ atomic_long_unchecked_t tlb_dropin_fail_idle;
37163+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
37164+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
37165+ atomic_long_unchecked_t tfh_stale_on_fault;
37166+ atomic_long_unchecked_t mmu_invalidate_range;
37167+ atomic_long_unchecked_t mmu_invalidate_page;
37168+ atomic_long_unchecked_t flush_tlb;
37169+ atomic_long_unchecked_t flush_tlb_gru;
37170+ atomic_long_unchecked_t flush_tlb_gru_tgh;
37171+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
37172
37173- atomic_long_t copy_gpa;
37174- atomic_long_t read_gpa;
37175+ atomic_long_unchecked_t copy_gpa;
37176+ atomic_long_unchecked_t read_gpa;
37177
37178- atomic_long_t mesq_receive;
37179- atomic_long_t mesq_receive_none;
37180- atomic_long_t mesq_send;
37181- atomic_long_t mesq_send_failed;
37182- atomic_long_t mesq_noop;
37183- atomic_long_t mesq_send_unexpected_error;
37184- atomic_long_t mesq_send_lb_overflow;
37185- atomic_long_t mesq_send_qlimit_reached;
37186- atomic_long_t mesq_send_amo_nacked;
37187- atomic_long_t mesq_send_put_nacked;
37188- atomic_long_t mesq_page_overflow;
37189- atomic_long_t mesq_qf_locked;
37190- atomic_long_t mesq_qf_noop_not_full;
37191- atomic_long_t mesq_qf_switch_head_failed;
37192- atomic_long_t mesq_qf_unexpected_error;
37193- atomic_long_t mesq_noop_unexpected_error;
37194- atomic_long_t mesq_noop_lb_overflow;
37195- atomic_long_t mesq_noop_qlimit_reached;
37196- atomic_long_t mesq_noop_amo_nacked;
37197- atomic_long_t mesq_noop_put_nacked;
37198- atomic_long_t mesq_noop_page_overflow;
37199+ atomic_long_unchecked_t mesq_receive;
37200+ atomic_long_unchecked_t mesq_receive_none;
37201+ atomic_long_unchecked_t mesq_send;
37202+ atomic_long_unchecked_t mesq_send_failed;
37203+ atomic_long_unchecked_t mesq_noop;
37204+ atomic_long_unchecked_t mesq_send_unexpected_error;
37205+ atomic_long_unchecked_t mesq_send_lb_overflow;
37206+ atomic_long_unchecked_t mesq_send_qlimit_reached;
37207+ atomic_long_unchecked_t mesq_send_amo_nacked;
37208+ atomic_long_unchecked_t mesq_send_put_nacked;
37209+ atomic_long_unchecked_t mesq_page_overflow;
37210+ atomic_long_unchecked_t mesq_qf_locked;
37211+ atomic_long_unchecked_t mesq_qf_noop_not_full;
37212+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
37213+ atomic_long_unchecked_t mesq_qf_unexpected_error;
37214+ atomic_long_unchecked_t mesq_noop_unexpected_error;
37215+ atomic_long_unchecked_t mesq_noop_lb_overflow;
37216+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
37217+ atomic_long_unchecked_t mesq_noop_amo_nacked;
37218+ atomic_long_unchecked_t mesq_noop_put_nacked;
37219+ atomic_long_unchecked_t mesq_noop_page_overflow;
37220
37221 };
37222
37223@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
37224 tghop_invalidate, mcsop_last};
37225
37226 struct mcs_op_statistic {
37227- atomic_long_t count;
37228- atomic_long_t total;
37229+ atomic_long_unchecked_t count;
37230+ atomic_long_unchecked_t total;
37231 unsigned long max;
37232 };
37233
37234@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
37235
37236 #define STAT(id) do { \
37237 if (gru_options & OPT_STATS) \
37238- atomic_long_inc(&gru_stats.id); \
37239+ atomic_long_inc_unchecked(&gru_stats.id); \
37240 } while (0)
37241
37242 #ifdef CONFIG_SGI_GRU_DEBUG
37243diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
37244index c862cd4..0d176fe 100644
37245--- a/drivers/misc/sgi-xp/xp.h
37246+++ b/drivers/misc/sgi-xp/xp.h
37247@@ -288,7 +288,7 @@ struct xpc_interface {
37248 xpc_notify_func, void *);
37249 void (*received) (short, int, void *);
37250 enum xp_retval (*partid_to_nasids) (short, void *);
37251-};
37252+} __no_const;
37253
37254 extern struct xpc_interface xpc_interface;
37255
37256diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
37257index b94d5f7..7f494c5 100644
37258--- a/drivers/misc/sgi-xp/xpc.h
37259+++ b/drivers/misc/sgi-xp/xpc.h
37260@@ -835,6 +835,7 @@ struct xpc_arch_operations {
37261 void (*received_payload) (struct xpc_channel *, void *);
37262 void (*notify_senders_of_disconnect) (struct xpc_channel *);
37263 };
37264+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
37265
37266 /* struct xpc_partition act_state values (for XPC HB) */
37267
37268@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
37269 /* found in xpc_main.c */
37270 extern struct device *xpc_part;
37271 extern struct device *xpc_chan;
37272-extern struct xpc_arch_operations xpc_arch_ops;
37273+extern xpc_arch_operations_no_const xpc_arch_ops;
37274 extern int xpc_disengage_timelimit;
37275 extern int xpc_disengage_timedout;
37276 extern int xpc_activate_IRQ_rcvd;
37277diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
37278index d971817..33bdca5 100644
37279--- a/drivers/misc/sgi-xp/xpc_main.c
37280+++ b/drivers/misc/sgi-xp/xpc_main.c
37281@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
37282 .notifier_call = xpc_system_die,
37283 };
37284
37285-struct xpc_arch_operations xpc_arch_ops;
37286+xpc_arch_operations_no_const xpc_arch_ops;
37287
37288 /*
37289 * Timer function to enforce the timelimit on the partition disengage.
37290@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
37291
37292 if (((die_args->trapnr == X86_TRAP_MF) ||
37293 (die_args->trapnr == X86_TRAP_XF)) &&
37294- !user_mode_vm(die_args->regs))
37295+ !user_mode(die_args->regs))
37296 xpc_die_deactivate();
37297
37298 break;
37299diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
37300index 6d8f701..35b6369 100644
37301--- a/drivers/mmc/core/mmc_ops.c
37302+++ b/drivers/mmc/core/mmc_ops.c
37303@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
37304 void *data_buf;
37305 int is_on_stack;
37306
37307- is_on_stack = object_is_on_stack(buf);
37308+ is_on_stack = object_starts_on_stack(buf);
37309 if (is_on_stack) {
37310 /*
37311 * dma onto stack is unsafe/nonportable, but callers to this
37312diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
37313index 53b8fd9..615b462 100644
37314--- a/drivers/mmc/host/dw_mmc.h
37315+++ b/drivers/mmc/host/dw_mmc.h
37316@@ -205,5 +205,5 @@ struct dw_mci_drv_data {
37317 int (*parse_dt)(struct dw_mci *host);
37318 int (*setup_bus)(struct dw_mci *host,
37319 struct device_node *slot_np, u8 bus_width);
37320-};
37321+} __do_const;
37322 #endif /* _DW_MMC_H_ */
37323diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
37324index 82a8de1..3c56ccb 100644
37325--- a/drivers/mmc/host/sdhci-s3c.c
37326+++ b/drivers/mmc/host/sdhci-s3c.c
37327@@ -721,9 +721,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
37328 * we can use overriding functions instead of default.
37329 */
37330 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
37331- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
37332- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
37333- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
37334+ pax_open_kernel();
37335+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
37336+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
37337+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
37338+ pax_close_kernel();
37339 }
37340
37341 /* It supports additional host capabilities if needed */
37342diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
37343index a4eb8b5..8c0628f 100644
37344--- a/drivers/mtd/devices/doc2000.c
37345+++ b/drivers/mtd/devices/doc2000.c
37346@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
37347
37348 /* The ECC will not be calculated correctly if less than 512 is written */
37349 /* DBB-
37350- if (len != 0x200 && eccbuf)
37351+ if (len != 0x200)
37352 printk(KERN_WARNING
37353 "ECC needs a full sector write (adr: %lx size %lx)\n",
37354 (long) to, (long) len);
37355diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
37356index 0c8bb6b..6f35deb 100644
37357--- a/drivers/mtd/nand/denali.c
37358+++ b/drivers/mtd/nand/denali.c
37359@@ -24,6 +24,7 @@
37360 #include <linux/slab.h>
37361 #include <linux/mtd/mtd.h>
37362 #include <linux/module.h>
37363+#include <linux/slab.h>
37364
37365 #include "denali.h"
37366
37367diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
37368index 51b9d6a..52af9a7 100644
37369--- a/drivers/mtd/nftlmount.c
37370+++ b/drivers/mtd/nftlmount.c
37371@@ -24,6 +24,7 @@
37372 #include <asm/errno.h>
37373 #include <linux/delay.h>
37374 #include <linux/slab.h>
37375+#include <linux/sched.h>
37376 #include <linux/mtd/mtd.h>
37377 #include <linux/mtd/nand.h>
37378 #include <linux/mtd/nftl.h>
37379diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
37380index 70dba5d..11a0919 100644
37381--- a/drivers/net/ethernet/8390/ax88796.c
37382+++ b/drivers/net/ethernet/8390/ax88796.c
37383@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
37384 if (ax->plat->reg_offsets)
37385 ei_local->reg_offset = ax->plat->reg_offsets;
37386 else {
37387+ resource_size_t _mem_size = mem_size;
37388+ do_div(_mem_size, 0x18);
37389 ei_local->reg_offset = ax->reg_offsets;
37390 for (ret = 0; ret < 0x18; ret++)
37391- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
37392+ ax->reg_offsets[ret] = _mem_size * ret;
37393 }
37394
37395 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
37396diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
37397index 0991534..8098e92 100644
37398--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
37399+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
37400@@ -1094,7 +1094,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
37401 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
37402 {
37403 /* RX_MODE controlling object */
37404- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
37405+ bnx2x_init_rx_mode_obj(bp);
37406
37407 /* multicast configuration controlling object */
37408 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
37409diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
37410index 09b625e..15b16fe 100644
37411--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
37412+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
37413@@ -2375,15 +2375,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
37414 return rc;
37415 }
37416
37417-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
37418- struct bnx2x_rx_mode_obj *o)
37419+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
37420 {
37421 if (CHIP_IS_E1x(bp)) {
37422- o->wait_comp = bnx2x_empty_rx_mode_wait;
37423- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
37424+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
37425+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
37426 } else {
37427- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
37428- o->config_rx_mode = bnx2x_set_rx_mode_e2;
37429+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
37430+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
37431 }
37432 }
37433
37434diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
37435index adbd91b..58ec94a 100644
37436--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
37437+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
37438@@ -1293,8 +1293,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
37439
37440 /********************* RX MODE ****************/
37441
37442-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
37443- struct bnx2x_rx_mode_obj *o);
37444+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
37445
37446 /**
37447 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
37448diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
37449index d330e81..ce1fb9a 100644
37450--- a/drivers/net/ethernet/broadcom/tg3.h
37451+++ b/drivers/net/ethernet/broadcom/tg3.h
37452@@ -146,6 +146,7 @@
37453 #define CHIPREV_ID_5750_A0 0x4000
37454 #define CHIPREV_ID_5750_A1 0x4001
37455 #define CHIPREV_ID_5750_A3 0x4003
37456+#define CHIPREV_ID_5750_C1 0x4201
37457 #define CHIPREV_ID_5750_C2 0x4202
37458 #define CHIPREV_ID_5752_A0_HW 0x5000
37459 #define CHIPREV_ID_5752_A0 0x6000
37460diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
37461index 8cffcdf..aadf043 100644
37462--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
37463+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
37464@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
37465 */
37466 struct l2t_skb_cb {
37467 arp_failure_handler_func arp_failure_handler;
37468-};
37469+} __no_const;
37470
37471 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
37472
37473diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
37474index 4c83003..2a2a5b9 100644
37475--- a/drivers/net/ethernet/dec/tulip/de4x5.c
37476+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
37477@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
37478 for (i=0; i<ETH_ALEN; i++) {
37479 tmp.addr[i] = dev->dev_addr[i];
37480 }
37481- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
37482+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
37483 break;
37484
37485 case DE4X5_SET_HWADDR: /* Set the hardware address */
37486@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
37487 spin_lock_irqsave(&lp->lock, flags);
37488 memcpy(&statbuf, &lp->pktStats, ioc->len);
37489 spin_unlock_irqrestore(&lp->lock, flags);
37490- if (copy_to_user(ioc->data, &statbuf, ioc->len))
37491+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
37492 return -EFAULT;
37493 break;
37494 }
37495diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
37496index 4d6f3c5..6169e60 100644
37497--- a/drivers/net/ethernet/emulex/benet/be_main.c
37498+++ b/drivers/net/ethernet/emulex/benet/be_main.c
37499@@ -455,7 +455,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
37500
37501 if (wrapped)
37502 newacc += 65536;
37503- ACCESS_ONCE(*acc) = newacc;
37504+ ACCESS_ONCE_RW(*acc) = newacc;
37505 }
37506
37507 void be_parse_stats(struct be_adapter *adapter)
37508diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
37509index 74d749e..eefb1bd 100644
37510--- a/drivers/net/ethernet/faraday/ftgmac100.c
37511+++ b/drivers/net/ethernet/faraday/ftgmac100.c
37512@@ -31,6 +31,8 @@
37513 #include <linux/netdevice.h>
37514 #include <linux/phy.h>
37515 #include <linux/platform_device.h>
37516+#include <linux/interrupt.h>
37517+#include <linux/irqreturn.h>
37518 #include <net/ip.h>
37519
37520 #include "ftgmac100.h"
37521diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
37522index b901a01..1ff32ee 100644
37523--- a/drivers/net/ethernet/faraday/ftmac100.c
37524+++ b/drivers/net/ethernet/faraday/ftmac100.c
37525@@ -31,6 +31,8 @@
37526 #include <linux/module.h>
37527 #include <linux/netdevice.h>
37528 #include <linux/platform_device.h>
37529+#include <linux/interrupt.h>
37530+#include <linux/irqreturn.h>
37531
37532 #include "ftmac100.h"
37533
37534diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
37535index bb9256a..56d8752 100644
37536--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
37537+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
37538@@ -806,7 +806,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
37539 }
37540
37541 /* update the base incval used to calculate frequency adjustment */
37542- ACCESS_ONCE(adapter->base_incval) = incval;
37543+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
37544 smp_mb();
37545
37546 /* need lock to prevent incorrect read while modifying cyclecounter */
37547diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
37548index fbe5363..266b4e3 100644
37549--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
37550+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
37551@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
37552 struct __vxge_hw_fifo *fifo;
37553 struct vxge_hw_fifo_config *config;
37554 u32 txdl_size, txdl_per_memblock;
37555- struct vxge_hw_mempool_cbs fifo_mp_callback;
37556+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
37557+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
37558+ };
37559+
37560 struct __vxge_hw_virtualpath *vpath;
37561
37562 if ((vp == NULL) || (attr == NULL)) {
37563@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
37564 goto exit;
37565 }
37566
37567- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
37568-
37569 fifo->mempool =
37570 __vxge_hw_mempool_create(vpath->hldev,
37571 fifo->config->memblock_size,
37572diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
37573index 998974f..ecd26db 100644
37574--- a/drivers/net/ethernet/realtek/r8169.c
37575+++ b/drivers/net/ethernet/realtek/r8169.c
37576@@ -741,22 +741,22 @@ struct rtl8169_private {
37577 struct mdio_ops {
37578 void (*write)(struct rtl8169_private *, int, int);
37579 int (*read)(struct rtl8169_private *, int);
37580- } mdio_ops;
37581+ } __no_const mdio_ops;
37582
37583 struct pll_power_ops {
37584 void (*down)(struct rtl8169_private *);
37585 void (*up)(struct rtl8169_private *);
37586- } pll_power_ops;
37587+ } __no_const pll_power_ops;
37588
37589 struct jumbo_ops {
37590 void (*enable)(struct rtl8169_private *);
37591 void (*disable)(struct rtl8169_private *);
37592- } jumbo_ops;
37593+ } __no_const jumbo_ops;
37594
37595 struct csi_ops {
37596 void (*write)(struct rtl8169_private *, int, int);
37597 u32 (*read)(struct rtl8169_private *, int);
37598- } csi_ops;
37599+ } __no_const csi_ops;
37600
37601 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
37602 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
37603diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
37604index 0767043f..08c2553 100644
37605--- a/drivers/net/ethernet/sfc/ptp.c
37606+++ b/drivers/net/ethernet/sfc/ptp.c
37607@@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
37608 (u32)((u64)ptp->start.dma_addr >> 32));
37609
37610 /* Clear flag that signals MC ready */
37611- ACCESS_ONCE(*start) = 0;
37612+ ACCESS_ONCE_RW(*start) = 0;
37613 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
37614 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
37615
37616diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
37617index 0c74a70..3bc6f68 100644
37618--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
37619+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
37620@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
37621
37622 writel(value, ioaddr + MMC_CNTRL);
37623
37624- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
37625- MMC_CNTRL, value);
37626+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
37627+// MMC_CNTRL, value);
37628 }
37629
37630 /* To mask all all interrupts.*/
37631diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
37632index e6fe0d8..2b7d752 100644
37633--- a/drivers/net/hyperv/hyperv_net.h
37634+++ b/drivers/net/hyperv/hyperv_net.h
37635@@ -101,7 +101,7 @@ struct rndis_device {
37636
37637 enum rndis_device_state state;
37638 bool link_state;
37639- atomic_t new_req_id;
37640+ atomic_unchecked_t new_req_id;
37641
37642 spinlock_t request_lock;
37643 struct list_head req_list;
37644diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
37645index 2b657d4..9903bc0 100644
37646--- a/drivers/net/hyperv/rndis_filter.c
37647+++ b/drivers/net/hyperv/rndis_filter.c
37648@@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
37649 * template
37650 */
37651 set = &rndis_msg->msg.set_req;
37652- set->req_id = atomic_inc_return(&dev->new_req_id);
37653+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
37654
37655 /* Add to the request list */
37656 spin_lock_irqsave(&dev->request_lock, flags);
37657@@ -758,7 +758,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
37658
37659 /* Setup the rndis set */
37660 halt = &request->request_msg.msg.halt_req;
37661- halt->req_id = atomic_inc_return(&dev->new_req_id);
37662+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
37663
37664 /* Ignore return since this msg is optional. */
37665 rndis_filter_send_request(dev, request);
37666diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
37667index 1e9cb0b..7839125 100644
37668--- a/drivers/net/ieee802154/fakehard.c
37669+++ b/drivers/net/ieee802154/fakehard.c
37670@@ -386,7 +386,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
37671 phy->transmit_power = 0xbf;
37672
37673 dev->netdev_ops = &fake_ops;
37674- dev->ml_priv = &fake_mlme;
37675+ dev->ml_priv = (void *)&fake_mlme;
37676
37677 priv = netdev_priv(dev);
37678 priv->phy = phy;
37679diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
37680index d3fb97d..e229d3e 100644
37681--- a/drivers/net/macvlan.c
37682+++ b/drivers/net/macvlan.c
37683@@ -913,7 +913,7 @@ static int macvlan_device_event(struct notifier_block *unused,
37684 return NOTIFY_DONE;
37685 }
37686
37687-static struct notifier_block macvlan_notifier_block __read_mostly = {
37688+static struct notifier_block macvlan_notifier_block = {
37689 .notifier_call = macvlan_device_event,
37690 };
37691
37692diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
37693index 0f0f9ce..0ca5819 100644
37694--- a/drivers/net/macvtap.c
37695+++ b/drivers/net/macvtap.c
37696@@ -1100,7 +1100,7 @@ static int macvtap_device_event(struct notifier_block *unused,
37697 return NOTIFY_DONE;
37698 }
37699
37700-static struct notifier_block macvtap_notifier_block __read_mostly = {
37701+static struct notifier_block macvtap_notifier_block = {
37702 .notifier_call = macvtap_device_event,
37703 };
37704
37705diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
37706index daec9b0..6428fcb 100644
37707--- a/drivers/net/phy/mdio-bitbang.c
37708+++ b/drivers/net/phy/mdio-bitbang.c
37709@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
37710 struct mdiobb_ctrl *ctrl = bus->priv;
37711
37712 module_put(ctrl->ops->owner);
37713+ mdiobus_unregister(bus);
37714 mdiobus_free(bus);
37715 }
37716 EXPORT_SYMBOL(free_mdio_bitbang);
37717diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
37718index 508570e..f706dc7 100644
37719--- a/drivers/net/ppp/ppp_generic.c
37720+++ b/drivers/net/ppp/ppp_generic.c
37721@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37722 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
37723 struct ppp_stats stats;
37724 struct ppp_comp_stats cstats;
37725- char *vers;
37726
37727 switch (cmd) {
37728 case SIOCGPPPSTATS:
37729@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37730 break;
37731
37732 case SIOCGPPPVER:
37733- vers = PPP_VERSION;
37734- if (copy_to_user(addr, vers, strlen(vers) + 1))
37735+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
37736 break;
37737 err = 0;
37738 break;
37739diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
37740index ad86660..9fd0884 100644
37741--- a/drivers/net/team/team.c
37742+++ b/drivers/net/team/team.c
37743@@ -2601,7 +2601,7 @@ static int team_device_event(struct notifier_block *unused,
37744 return NOTIFY_DONE;
37745 }
37746
37747-static struct notifier_block team_notifier_block __read_mostly = {
37748+static struct notifier_block team_notifier_block = {
37749 .notifier_call = team_device_event,
37750 };
37751
37752diff --git a/drivers/net/tun.c b/drivers/net/tun.c
37753index 2917a86..edd463f 100644
37754--- a/drivers/net/tun.c
37755+++ b/drivers/net/tun.c
37756@@ -1836,7 +1836,7 @@ unlock:
37757 }
37758
37759 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
37760- unsigned long arg, int ifreq_len)
37761+ unsigned long arg, size_t ifreq_len)
37762 {
37763 struct tun_file *tfile = file->private_data;
37764 struct tun_struct *tun;
37765@@ -1848,6 +1848,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
37766 int vnet_hdr_sz;
37767 int ret;
37768
37769+ if (ifreq_len > sizeof ifr)
37770+ return -EFAULT;
37771+
37772 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
37773 if (copy_from_user(&ifr, argp, ifreq_len))
37774 return -EFAULT;
37775diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
37776index cd8ccb2..cff5144 100644
37777--- a/drivers/net/usb/hso.c
37778+++ b/drivers/net/usb/hso.c
37779@@ -71,7 +71,7 @@
37780 #include <asm/byteorder.h>
37781 #include <linux/serial_core.h>
37782 #include <linux/serial.h>
37783-
37784+#include <asm/local.h>
37785
37786 #define MOD_AUTHOR "Option Wireless"
37787 #define MOD_DESCRIPTION "USB High Speed Option driver"
37788@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
37789 struct urb *urb;
37790
37791 urb = serial->rx_urb[0];
37792- if (serial->port.count > 0) {
37793+ if (atomic_read(&serial->port.count) > 0) {
37794 count = put_rxbuf_data(urb, serial);
37795 if (count == -1)
37796 return;
37797@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
37798 DUMP1(urb->transfer_buffer, urb->actual_length);
37799
37800 /* Anyone listening? */
37801- if (serial->port.count == 0)
37802+ if (atomic_read(&serial->port.count) == 0)
37803 return;
37804
37805 if (status == 0) {
37806@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
37807 tty_port_tty_set(&serial->port, tty);
37808
37809 /* check for port already opened, if not set the termios */
37810- serial->port.count++;
37811- if (serial->port.count == 1) {
37812+ if (atomic_inc_return(&serial->port.count) == 1) {
37813 serial->rx_state = RX_IDLE;
37814 /* Force default termio settings */
37815 _hso_serial_set_termios(tty, NULL);
37816@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
37817 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
37818 if (result) {
37819 hso_stop_serial_device(serial->parent);
37820- serial->port.count--;
37821+ atomic_dec(&serial->port.count);
37822 kref_put(&serial->parent->ref, hso_serial_ref_free);
37823 }
37824 } else {
37825@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
37826
37827 /* reset the rts and dtr */
37828 /* do the actual close */
37829- serial->port.count--;
37830+ atomic_dec(&serial->port.count);
37831
37832- if (serial->port.count <= 0) {
37833- serial->port.count = 0;
37834+ if (atomic_read(&serial->port.count) <= 0) {
37835+ atomic_set(&serial->port.count, 0);
37836 tty_port_tty_set(&serial->port, NULL);
37837 if (!usb_gone)
37838 hso_stop_serial_device(serial->parent);
37839@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
37840
37841 /* the actual setup */
37842 spin_lock_irqsave(&serial->serial_lock, flags);
37843- if (serial->port.count)
37844+ if (atomic_read(&serial->port.count))
37845 _hso_serial_set_termios(tty, old);
37846 else
37847 tty->termios = *old;
37848@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
37849 D1("Pending read interrupt on port %d\n", i);
37850 spin_lock(&serial->serial_lock);
37851 if (serial->rx_state == RX_IDLE &&
37852- serial->port.count > 0) {
37853+ atomic_read(&serial->port.count) > 0) {
37854 /* Setup and send a ctrl req read on
37855 * port i */
37856 if (!serial->rx_urb_filled[0]) {
37857@@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
37858 /* Start all serial ports */
37859 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
37860 if (serial_table[i] && (serial_table[i]->interface == iface)) {
37861- if (dev2ser(serial_table[i])->port.count) {
37862+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
37863 result =
37864 hso_start_serial_device(serial_table[i], GFP_NOIO);
37865 hso_kick_transmit(dev2ser(serial_table[i]));
37866diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
37867index 8d78253..bebbb68 100644
37868--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
37869+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
37870@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37871 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
37872 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
37873
37874- ACCESS_ONCE(ads->ds_link) = i->link;
37875- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
37876+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
37877+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
37878
37879 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
37880 ctl6 = SM(i->keytype, AR_EncrType);
37881@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37882
37883 if ((i->is_first || i->is_last) &&
37884 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
37885- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
37886+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
37887 | set11nTries(i->rates, 1)
37888 | set11nTries(i->rates, 2)
37889 | set11nTries(i->rates, 3)
37890 | (i->dur_update ? AR_DurUpdateEna : 0)
37891 | SM(0, AR_BurstDur);
37892
37893- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
37894+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
37895 | set11nRate(i->rates, 1)
37896 | set11nRate(i->rates, 2)
37897 | set11nRate(i->rates, 3);
37898 } else {
37899- ACCESS_ONCE(ads->ds_ctl2) = 0;
37900- ACCESS_ONCE(ads->ds_ctl3) = 0;
37901+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
37902+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
37903 }
37904
37905 if (!i->is_first) {
37906- ACCESS_ONCE(ads->ds_ctl0) = 0;
37907- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
37908- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
37909+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
37910+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
37911+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
37912 return;
37913 }
37914
37915@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37916 break;
37917 }
37918
37919- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
37920+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
37921 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
37922 | SM(i->txpower, AR_XmitPower)
37923 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
37924@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37925 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
37926 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
37927
37928- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
37929- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
37930+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
37931+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
37932
37933 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
37934 return;
37935
37936- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
37937+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
37938 | set11nPktDurRTSCTS(i->rates, 1);
37939
37940- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
37941+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
37942 | set11nPktDurRTSCTS(i->rates, 3);
37943
37944- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
37945+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
37946 | set11nRateFlags(i->rates, 1)
37947 | set11nRateFlags(i->rates, 2)
37948 | set11nRateFlags(i->rates, 3)
37949diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
37950index 301bf72..3f5654f 100644
37951--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
37952+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
37953@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37954 (i->qcu << AR_TxQcuNum_S) | desc_len;
37955
37956 checksum += val;
37957- ACCESS_ONCE(ads->info) = val;
37958+ ACCESS_ONCE_RW(ads->info) = val;
37959
37960 checksum += i->link;
37961- ACCESS_ONCE(ads->link) = i->link;
37962+ ACCESS_ONCE_RW(ads->link) = i->link;
37963
37964 checksum += i->buf_addr[0];
37965- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
37966+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
37967 checksum += i->buf_addr[1];
37968- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
37969+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
37970 checksum += i->buf_addr[2];
37971- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
37972+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
37973 checksum += i->buf_addr[3];
37974- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
37975+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
37976
37977 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
37978- ACCESS_ONCE(ads->ctl3) = val;
37979+ ACCESS_ONCE_RW(ads->ctl3) = val;
37980 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
37981- ACCESS_ONCE(ads->ctl5) = val;
37982+ ACCESS_ONCE_RW(ads->ctl5) = val;
37983 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
37984- ACCESS_ONCE(ads->ctl7) = val;
37985+ ACCESS_ONCE_RW(ads->ctl7) = val;
37986 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
37987- ACCESS_ONCE(ads->ctl9) = val;
37988+ ACCESS_ONCE_RW(ads->ctl9) = val;
37989
37990 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
37991- ACCESS_ONCE(ads->ctl10) = checksum;
37992+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
37993
37994 if (i->is_first || i->is_last) {
37995- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
37996+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
37997 | set11nTries(i->rates, 1)
37998 | set11nTries(i->rates, 2)
37999 | set11nTries(i->rates, 3)
38000 | (i->dur_update ? AR_DurUpdateEna : 0)
38001 | SM(0, AR_BurstDur);
38002
38003- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
38004+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
38005 | set11nRate(i->rates, 1)
38006 | set11nRate(i->rates, 2)
38007 | set11nRate(i->rates, 3);
38008 } else {
38009- ACCESS_ONCE(ads->ctl13) = 0;
38010- ACCESS_ONCE(ads->ctl14) = 0;
38011+ ACCESS_ONCE_RW(ads->ctl13) = 0;
38012+ ACCESS_ONCE_RW(ads->ctl14) = 0;
38013 }
38014
38015 ads->ctl20 = 0;
38016@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
38017
38018 ctl17 = SM(i->keytype, AR_EncrType);
38019 if (!i->is_first) {
38020- ACCESS_ONCE(ads->ctl11) = 0;
38021- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
38022- ACCESS_ONCE(ads->ctl15) = 0;
38023- ACCESS_ONCE(ads->ctl16) = 0;
38024- ACCESS_ONCE(ads->ctl17) = ctl17;
38025- ACCESS_ONCE(ads->ctl18) = 0;
38026- ACCESS_ONCE(ads->ctl19) = 0;
38027+ ACCESS_ONCE_RW(ads->ctl11) = 0;
38028+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
38029+ ACCESS_ONCE_RW(ads->ctl15) = 0;
38030+ ACCESS_ONCE_RW(ads->ctl16) = 0;
38031+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
38032+ ACCESS_ONCE_RW(ads->ctl18) = 0;
38033+ ACCESS_ONCE_RW(ads->ctl19) = 0;
38034 return;
38035 }
38036
38037- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
38038+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
38039 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
38040 | SM(i->txpower, AR_XmitPower)
38041 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
38042@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
38043 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
38044 ctl12 |= SM(val, AR_PAPRDChainMask);
38045
38046- ACCESS_ONCE(ads->ctl12) = ctl12;
38047- ACCESS_ONCE(ads->ctl17) = ctl17;
38048+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
38049+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
38050
38051- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
38052+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
38053 | set11nPktDurRTSCTS(i->rates, 1);
38054
38055- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
38056+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
38057 | set11nPktDurRTSCTS(i->rates, 3);
38058
38059- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
38060+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
38061 | set11nRateFlags(i->rates, 1)
38062 | set11nRateFlags(i->rates, 2)
38063 | set11nRateFlags(i->rates, 3)
38064 | SM(i->rtscts_rate, AR_RTSCTSRate);
38065
38066- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
38067+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
38068 }
38069
38070 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
38071diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
38072index 9d26fc5..60d9f14 100644
38073--- a/drivers/net/wireless/ath/ath9k/hw.h
38074+++ b/drivers/net/wireless/ath/ath9k/hw.h
38075@@ -658,7 +658,7 @@ struct ath_hw_private_ops {
38076
38077 /* ANI */
38078 void (*ani_cache_ini_regs)(struct ath_hw *ah);
38079-};
38080+} __no_const;
38081
38082 /**
38083 * struct ath_hw_ops - callbacks used by hardware code and driver code
38084@@ -688,7 +688,7 @@ struct ath_hw_ops {
38085 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
38086 struct ath_hw_antcomb_conf *antconf);
38087 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
38088-};
38089+} __no_const;
38090
38091 struct ath_nf_limits {
38092 s16 max;
38093diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
38094index 3726cd6..b655808 100644
38095--- a/drivers/net/wireless/iwlegacy/3945-mac.c
38096+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
38097@@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
38098 */
38099 if (il3945_mod_params.disable_hw_scan) {
38100 D_INFO("Disabling hw_scan\n");
38101- il3945_mac_ops.hw_scan = NULL;
38102+ pax_open_kernel();
38103+ *(void **)&il3945_mac_ops.hw_scan = NULL;
38104+ pax_close_kernel();
38105 }
38106
38107 D_INFO("*** LOAD DRIVER ***\n");
38108diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
38109index 5b9533e..7733880 100644
38110--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
38111+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
38112@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
38113 {
38114 struct iwl_priv *priv = file->private_data;
38115 char buf[64];
38116- int buf_size;
38117+ size_t buf_size;
38118 u32 offset, len;
38119
38120 memset(buf, 0, sizeof(buf));
38121@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
38122 struct iwl_priv *priv = file->private_data;
38123
38124 char buf[8];
38125- int buf_size;
38126+ size_t buf_size;
38127 u32 reset_flag;
38128
38129 memset(buf, 0, sizeof(buf));
38130@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
38131 {
38132 struct iwl_priv *priv = file->private_data;
38133 char buf[8];
38134- int buf_size;
38135+ size_t buf_size;
38136 int ht40;
38137
38138 memset(buf, 0, sizeof(buf));
38139@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
38140 {
38141 struct iwl_priv *priv = file->private_data;
38142 char buf[8];
38143- int buf_size;
38144+ size_t buf_size;
38145 int value;
38146
38147 memset(buf, 0, sizeof(buf));
38148@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
38149 {
38150 struct iwl_priv *priv = file->private_data;
38151 char buf[8];
38152- int buf_size;
38153+ size_t buf_size;
38154 int clear;
38155
38156 memset(buf, 0, sizeof(buf));
38157@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
38158 {
38159 struct iwl_priv *priv = file->private_data;
38160 char buf[8];
38161- int buf_size;
38162+ size_t buf_size;
38163 int trace;
38164
38165 memset(buf, 0, sizeof(buf));
38166@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
38167 {
38168 struct iwl_priv *priv = file->private_data;
38169 char buf[8];
38170- int buf_size;
38171+ size_t buf_size;
38172 int missed;
38173
38174 memset(buf, 0, sizeof(buf));
38175@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
38176
38177 struct iwl_priv *priv = file->private_data;
38178 char buf[8];
38179- int buf_size;
38180+ size_t buf_size;
38181 int plcp;
38182
38183 memset(buf, 0, sizeof(buf));
38184@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
38185
38186 struct iwl_priv *priv = file->private_data;
38187 char buf[8];
38188- int buf_size;
38189+ size_t buf_size;
38190 int flush;
38191
38192 memset(buf, 0, sizeof(buf));
38193@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
38194
38195 struct iwl_priv *priv = file->private_data;
38196 char buf[8];
38197- int buf_size;
38198+ size_t buf_size;
38199 int rts;
38200
38201 if (!priv->cfg->ht_params)
38202@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
38203 {
38204 struct iwl_priv *priv = file->private_data;
38205 char buf[8];
38206- int buf_size;
38207+ size_t buf_size;
38208
38209 memset(buf, 0, sizeof(buf));
38210 buf_size = min(count, sizeof(buf) - 1);
38211@@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
38212 struct iwl_priv *priv = file->private_data;
38213 u32 event_log_flag;
38214 char buf[8];
38215- int buf_size;
38216+ size_t buf_size;
38217
38218 /* check that the interface is up */
38219 if (!iwl_is_ready(priv))
38220@@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
38221 struct iwl_priv *priv = file->private_data;
38222 char buf[8];
38223 u32 calib_disabled;
38224- int buf_size;
38225+ size_t buf_size;
38226
38227 memset(buf, 0, sizeof(buf));
38228 buf_size = min(count, sizeof(buf) - 1);
38229diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
38230index 35708b9..31f7754 100644
38231--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
38232+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
38233@@ -1100,7 +1100,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
38234 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
38235
38236 char buf[8];
38237- int buf_size;
38238+ size_t buf_size;
38239 u32 reset_flag;
38240
38241 memset(buf, 0, sizeof(buf));
38242@@ -1121,7 +1121,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
38243 {
38244 struct iwl_trans *trans = file->private_data;
38245 char buf[8];
38246- int buf_size;
38247+ size_t buf_size;
38248 int csr;
38249
38250 memset(buf, 0, sizeof(buf));
38251diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
38252index ff90855..e46d223 100644
38253--- a/drivers/net/wireless/mac80211_hwsim.c
38254+++ b/drivers/net/wireless/mac80211_hwsim.c
38255@@ -2062,25 +2062,19 @@ static int __init init_mac80211_hwsim(void)
38256
38257 if (channels > 1) {
38258 hwsim_if_comb.num_different_channels = channels;
38259- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
38260- mac80211_hwsim_ops.cancel_hw_scan =
38261- mac80211_hwsim_cancel_hw_scan;
38262- mac80211_hwsim_ops.sw_scan_start = NULL;
38263- mac80211_hwsim_ops.sw_scan_complete = NULL;
38264- mac80211_hwsim_ops.remain_on_channel =
38265- mac80211_hwsim_roc;
38266- mac80211_hwsim_ops.cancel_remain_on_channel =
38267- mac80211_hwsim_croc;
38268- mac80211_hwsim_ops.add_chanctx =
38269- mac80211_hwsim_add_chanctx;
38270- mac80211_hwsim_ops.remove_chanctx =
38271- mac80211_hwsim_remove_chanctx;
38272- mac80211_hwsim_ops.change_chanctx =
38273- mac80211_hwsim_change_chanctx;
38274- mac80211_hwsim_ops.assign_vif_chanctx =
38275- mac80211_hwsim_assign_vif_chanctx;
38276- mac80211_hwsim_ops.unassign_vif_chanctx =
38277- mac80211_hwsim_unassign_vif_chanctx;
38278+ pax_open_kernel();
38279+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
38280+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
38281+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
38282+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
38283+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
38284+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
38285+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
38286+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
38287+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
38288+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
38289+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
38290+ pax_close_kernel();
38291 }
38292
38293 spin_lock_init(&hwsim_radio_lock);
38294diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
38295index abe1d03..fb02c22 100644
38296--- a/drivers/net/wireless/rndis_wlan.c
38297+++ b/drivers/net/wireless/rndis_wlan.c
38298@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
38299
38300 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
38301
38302- if (rts_threshold < 0 || rts_threshold > 2347)
38303+ if (rts_threshold > 2347)
38304 rts_threshold = 2347;
38305
38306 tmp = cpu_to_le32(rts_threshold);
38307diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
38308index 0751b35..246ba3e 100644
38309--- a/drivers/net/wireless/rt2x00/rt2x00.h
38310+++ b/drivers/net/wireless/rt2x00/rt2x00.h
38311@@ -398,7 +398,7 @@ struct rt2x00_intf {
38312 * for hardware which doesn't support hardware
38313 * sequence counting.
38314 */
38315- atomic_t seqno;
38316+ atomic_unchecked_t seqno;
38317 };
38318
38319 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
38320diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
38321index e488b94..14b6a0c 100644
38322--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
38323+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
38324@@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
38325 * sequence counter given by mac80211.
38326 */
38327 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
38328- seqno = atomic_add_return(0x10, &intf->seqno);
38329+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
38330 else
38331- seqno = atomic_read(&intf->seqno);
38332+ seqno = atomic_read_unchecked(&intf->seqno);
38333
38334 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
38335 hdr->seq_ctrl |= cpu_to_le16(seqno);
38336diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
38337index e57ee48..541cf6c 100644
38338--- a/drivers/net/wireless/ti/wl1251/sdio.c
38339+++ b/drivers/net/wireless/ti/wl1251/sdio.c
38340@@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
38341
38342 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
38343
38344- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
38345- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
38346+ pax_open_kernel();
38347+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
38348+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
38349+ pax_close_kernel();
38350
38351 wl1251_info("using dedicated interrupt line");
38352 } else {
38353- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
38354- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
38355+ pax_open_kernel();
38356+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
38357+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
38358+ pax_close_kernel();
38359
38360 wl1251_info("using SDIO interrupt");
38361 }
38362diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
38363index e5f5f8f..fdf15b7 100644
38364--- a/drivers/net/wireless/ti/wl12xx/main.c
38365+++ b/drivers/net/wireless/ti/wl12xx/main.c
38366@@ -644,7 +644,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
38367 sizeof(wl->conf.mem));
38368
38369 /* read data preparation is only needed by wl127x */
38370- wl->ops->prepare_read = wl127x_prepare_read;
38371+ pax_open_kernel();
38372+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
38373+ pax_close_kernel();
38374
38375 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
38376 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
38377@@ -665,7 +667,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
38378 sizeof(wl->conf.mem));
38379
38380 /* read data preparation is only needed by wl127x */
38381- wl->ops->prepare_read = wl127x_prepare_read;
38382+ pax_open_kernel();
38383+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
38384+ pax_close_kernel();
38385
38386 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
38387 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
38388diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
38389index 8d8c1f8..e754844 100644
38390--- a/drivers/net/wireless/ti/wl18xx/main.c
38391+++ b/drivers/net/wireless/ti/wl18xx/main.c
38392@@ -1489,8 +1489,10 @@ static int wl18xx_setup(struct wl1271 *wl)
38393 }
38394
38395 if (!checksum_param) {
38396- wl18xx_ops.set_rx_csum = NULL;
38397- wl18xx_ops.init_vif = NULL;
38398+ pax_open_kernel();
38399+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
38400+ *(void **)&wl18xx_ops.init_vif = NULL;
38401+ pax_close_kernel();
38402 }
38403
38404 /* Enable 11a Band only if we have 5G antennas */
38405diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
38406index d93b2b6..ae50401 100644
38407--- a/drivers/oprofile/buffer_sync.c
38408+++ b/drivers/oprofile/buffer_sync.c
38409@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
38410 if (cookie == NO_COOKIE)
38411 offset = pc;
38412 if (cookie == INVALID_COOKIE) {
38413- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
38414+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
38415 offset = pc;
38416 }
38417 if (cookie != last_cookie) {
38418@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
38419 /* add userspace sample */
38420
38421 if (!mm) {
38422- atomic_inc(&oprofile_stats.sample_lost_no_mm);
38423+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
38424 return 0;
38425 }
38426
38427 cookie = lookup_dcookie(mm, s->eip, &offset);
38428
38429 if (cookie == INVALID_COOKIE) {
38430- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
38431+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
38432 return 0;
38433 }
38434
38435@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
38436 /* ignore backtraces if failed to add a sample */
38437 if (state == sb_bt_start) {
38438 state = sb_bt_ignore;
38439- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
38440+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
38441 }
38442 }
38443 release_mm(mm);
38444diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
38445index c0cc4e7..44d4e54 100644
38446--- a/drivers/oprofile/event_buffer.c
38447+++ b/drivers/oprofile/event_buffer.c
38448@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
38449 }
38450
38451 if (buffer_pos == buffer_size) {
38452- atomic_inc(&oprofile_stats.event_lost_overflow);
38453+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
38454 return;
38455 }
38456
38457diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
38458index ed2c3ec..deda85a 100644
38459--- a/drivers/oprofile/oprof.c
38460+++ b/drivers/oprofile/oprof.c
38461@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
38462 if (oprofile_ops.switch_events())
38463 return;
38464
38465- atomic_inc(&oprofile_stats.multiplex_counter);
38466+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
38467 start_switch_worker();
38468 }
38469
38470diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
38471index 917d28e..d62d981 100644
38472--- a/drivers/oprofile/oprofile_stats.c
38473+++ b/drivers/oprofile/oprofile_stats.c
38474@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
38475 cpu_buf->sample_invalid_eip = 0;
38476 }
38477
38478- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
38479- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
38480- atomic_set(&oprofile_stats.event_lost_overflow, 0);
38481- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
38482- atomic_set(&oprofile_stats.multiplex_counter, 0);
38483+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
38484+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
38485+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
38486+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
38487+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
38488 }
38489
38490
38491diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
38492index 38b6fc0..b5cbfce 100644
38493--- a/drivers/oprofile/oprofile_stats.h
38494+++ b/drivers/oprofile/oprofile_stats.h
38495@@ -13,11 +13,11 @@
38496 #include <linux/atomic.h>
38497
38498 struct oprofile_stat_struct {
38499- atomic_t sample_lost_no_mm;
38500- atomic_t sample_lost_no_mapping;
38501- atomic_t bt_lost_no_mapping;
38502- atomic_t event_lost_overflow;
38503- atomic_t multiplex_counter;
38504+ atomic_unchecked_t sample_lost_no_mm;
38505+ atomic_unchecked_t sample_lost_no_mapping;
38506+ atomic_unchecked_t bt_lost_no_mapping;
38507+ atomic_unchecked_t event_lost_overflow;
38508+ atomic_unchecked_t multiplex_counter;
38509 };
38510
38511 extern struct oprofile_stat_struct oprofile_stats;
38512diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
38513index 849357c..b83c1e0 100644
38514--- a/drivers/oprofile/oprofilefs.c
38515+++ b/drivers/oprofile/oprofilefs.c
38516@@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
38517
38518
38519 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
38520- char const *name, atomic_t *val)
38521+ char const *name, atomic_unchecked_t *val)
38522 {
38523 return __oprofilefs_create_file(sb, root, name,
38524 &atomic_ro_fops, 0444, val);
38525diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
38526index 93404f7..4a313d8 100644
38527--- a/drivers/oprofile/timer_int.c
38528+++ b/drivers/oprofile/timer_int.c
38529@@ -93,7 +93,7 @@ static int __cpuinit oprofile_cpu_notify(struct notifier_block *self,
38530 return NOTIFY_OK;
38531 }
38532
38533-static struct notifier_block __refdata oprofile_cpu_notifier = {
38534+static struct notifier_block oprofile_cpu_notifier = {
38535 .notifier_call = oprofile_cpu_notify,
38536 };
38537
38538diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
38539index 3f56bc0..707d642 100644
38540--- a/drivers/parport/procfs.c
38541+++ b/drivers/parport/procfs.c
38542@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
38543
38544 *ppos += len;
38545
38546- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
38547+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
38548 }
38549
38550 #ifdef CONFIG_PARPORT_1284
38551@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
38552
38553 *ppos += len;
38554
38555- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
38556+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
38557 }
38558 #endif /* IEEE1284.3 support. */
38559
38560diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
38561index a6a71c4..c91097b 100644
38562--- a/drivers/pci/hotplug/cpcihp_generic.c
38563+++ b/drivers/pci/hotplug/cpcihp_generic.c
38564@@ -73,7 +73,6 @@ static u16 port;
38565 static unsigned int enum_bit;
38566 static u8 enum_mask;
38567
38568-static struct cpci_hp_controller_ops generic_hpc_ops;
38569 static struct cpci_hp_controller generic_hpc;
38570
38571 static int __init validate_parameters(void)
38572@@ -139,6 +138,10 @@ static int query_enum(void)
38573 return ((value & enum_mask) == enum_mask);
38574 }
38575
38576+static struct cpci_hp_controller_ops generic_hpc_ops = {
38577+ .query_enum = query_enum,
38578+};
38579+
38580 static int __init cpcihp_generic_init(void)
38581 {
38582 int status;
38583@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
38584 pci_dev_put(dev);
38585
38586 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
38587- generic_hpc_ops.query_enum = query_enum;
38588 generic_hpc.ops = &generic_hpc_ops;
38589
38590 status = cpci_hp_register_controller(&generic_hpc);
38591diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
38592index 449b4bb..257e2e8 100644
38593--- a/drivers/pci/hotplug/cpcihp_zt5550.c
38594+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
38595@@ -59,7 +59,6 @@
38596 /* local variables */
38597 static bool debug;
38598 static bool poll;
38599-static struct cpci_hp_controller_ops zt5550_hpc_ops;
38600 static struct cpci_hp_controller zt5550_hpc;
38601
38602 /* Primary cPCI bus bridge device */
38603@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
38604 return 0;
38605 }
38606
38607+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
38608+ .query_enum = zt5550_hc_query_enum,
38609+};
38610+
38611 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
38612 {
38613 int status;
38614@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
38615 dbg("returned from zt5550_hc_config");
38616
38617 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
38618- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
38619 zt5550_hpc.ops = &zt5550_hpc_ops;
38620 if(!poll) {
38621 zt5550_hpc.irq = hc_dev->irq;
38622 zt5550_hpc.irq_flags = IRQF_SHARED;
38623 zt5550_hpc.dev_id = hc_dev;
38624
38625- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
38626- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
38627- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
38628+ pax_open_kernel();
38629+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
38630+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
38631+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
38632+ pax_open_kernel();
38633 } else {
38634 info("using ENUM# polling mode");
38635 }
38636diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
38637index 76ba8a1..20ca857 100644
38638--- a/drivers/pci/hotplug/cpqphp_nvram.c
38639+++ b/drivers/pci/hotplug/cpqphp_nvram.c
38640@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
38641
38642 void compaq_nvram_init (void __iomem *rom_start)
38643 {
38644+
38645+#ifndef CONFIG_PAX_KERNEXEC
38646 if (rom_start) {
38647 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
38648 }
38649+#endif
38650+
38651 dbg("int15 entry = %p\n", compaq_int15_entry_point);
38652
38653 /* initialize our int15 lock */
38654diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
38655index 8474b6a..ee81993 100644
38656--- a/drivers/pci/pcie/aspm.c
38657+++ b/drivers/pci/pcie/aspm.c
38658@@ -27,9 +27,9 @@
38659 #define MODULE_PARAM_PREFIX "pcie_aspm."
38660
38661 /* Note: those are not register definitions */
38662-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
38663-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
38664-#define ASPM_STATE_L1 (4) /* L1 state */
38665+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
38666+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
38667+#define ASPM_STATE_L1 (4U) /* L1 state */
38668 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
38669 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
38670
38671diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
38672index 6186f03..1a78714 100644
38673--- a/drivers/pci/probe.c
38674+++ b/drivers/pci/probe.c
38675@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
38676 struct pci_bus_region region;
38677 bool bar_too_big = false, bar_disabled = false;
38678
38679- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
38680+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
38681
38682 /* No printks while decoding is disabled! */
38683 if (!dev->mmio_always_on) {
38684diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
38685index 9b8505c..f00870a 100644
38686--- a/drivers/pci/proc.c
38687+++ b/drivers/pci/proc.c
38688@@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
38689 static int __init pci_proc_init(void)
38690 {
38691 struct pci_dev *dev = NULL;
38692+
38693+#ifdef CONFIG_GRKERNSEC_PROC_ADD
38694+#ifdef CONFIG_GRKERNSEC_PROC_USER
38695+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
38696+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
38697+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
38698+#endif
38699+#else
38700 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
38701+#endif
38702 proc_create("devices", 0, proc_bus_pci_dir,
38703 &proc_bus_pci_dev_operations);
38704 proc_initialized = 1;
38705diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
38706index f946ca7..f25c833 100644
38707--- a/drivers/platform/x86/thinkpad_acpi.c
38708+++ b/drivers/platform/x86/thinkpad_acpi.c
38709@@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
38710 return 0;
38711 }
38712
38713-void static hotkey_mask_warn_incomplete_mask(void)
38714+static void hotkey_mask_warn_incomplete_mask(void)
38715 {
38716 /* log only what the user can fix... */
38717 const u32 wantedmask = hotkey_driver_mask &
38718@@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
38719 }
38720 }
38721
38722-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38723- struct tp_nvram_state *newn,
38724- const u32 event_mask)
38725-{
38726-
38727 #define TPACPI_COMPARE_KEY(__scancode, __member) \
38728 do { \
38729 if ((event_mask & (1 << __scancode)) && \
38730@@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38731 tpacpi_hotkey_send_key(__scancode); \
38732 } while (0)
38733
38734- void issue_volchange(const unsigned int oldvol,
38735- const unsigned int newvol)
38736- {
38737- unsigned int i = oldvol;
38738+static void issue_volchange(const unsigned int oldvol,
38739+ const unsigned int newvol,
38740+ const u32 event_mask)
38741+{
38742+ unsigned int i = oldvol;
38743
38744- while (i > newvol) {
38745- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
38746- i--;
38747- }
38748- while (i < newvol) {
38749- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
38750- i++;
38751- }
38752+ while (i > newvol) {
38753+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
38754+ i--;
38755 }
38756+ while (i < newvol) {
38757+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
38758+ i++;
38759+ }
38760+}
38761
38762- void issue_brightnesschange(const unsigned int oldbrt,
38763- const unsigned int newbrt)
38764- {
38765- unsigned int i = oldbrt;
38766+static void issue_brightnesschange(const unsigned int oldbrt,
38767+ const unsigned int newbrt,
38768+ const u32 event_mask)
38769+{
38770+ unsigned int i = oldbrt;
38771
38772- while (i > newbrt) {
38773- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
38774- i--;
38775- }
38776- while (i < newbrt) {
38777- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
38778- i++;
38779- }
38780+ while (i > newbrt) {
38781+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
38782+ i--;
38783+ }
38784+ while (i < newbrt) {
38785+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
38786+ i++;
38787 }
38788+}
38789
38790+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38791+ struct tp_nvram_state *newn,
38792+ const u32 event_mask)
38793+{
38794 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
38795 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
38796 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
38797@@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38798 oldn->volume_level != newn->volume_level) {
38799 /* recently muted, or repeated mute keypress, or
38800 * multiple presses ending in mute */
38801- issue_volchange(oldn->volume_level, newn->volume_level);
38802+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
38803 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
38804 }
38805 } else {
38806@@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38807 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
38808 }
38809 if (oldn->volume_level != newn->volume_level) {
38810- issue_volchange(oldn->volume_level, newn->volume_level);
38811+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
38812 } else if (oldn->volume_toggle != newn->volume_toggle) {
38813 /* repeated vol up/down keypress at end of scale ? */
38814 if (newn->volume_level == 0)
38815@@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38816 /* handle brightness */
38817 if (oldn->brightness_level != newn->brightness_level) {
38818 issue_brightnesschange(oldn->brightness_level,
38819- newn->brightness_level);
38820+ newn->brightness_level,
38821+ event_mask);
38822 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
38823 /* repeated key presses that didn't change state */
38824 if (newn->brightness_level == 0)
38825@@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38826 && !tp_features.bright_unkfw)
38827 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
38828 }
38829+}
38830
38831 #undef TPACPI_COMPARE_KEY
38832 #undef TPACPI_MAY_SEND_KEY
38833-}
38834
38835 /*
38836 * Polling driver
38837diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
38838index 769d265..a3a05ca 100644
38839--- a/drivers/pnp/pnpbios/bioscalls.c
38840+++ b/drivers/pnp/pnpbios/bioscalls.c
38841@@ -58,7 +58,7 @@ do { \
38842 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
38843 } while(0)
38844
38845-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
38846+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
38847 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
38848
38849 /*
38850@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
38851
38852 cpu = get_cpu();
38853 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
38854+
38855+ pax_open_kernel();
38856 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
38857+ pax_close_kernel();
38858
38859 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
38860 spin_lock_irqsave(&pnp_bios_lock, flags);
38861@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
38862 :"memory");
38863 spin_unlock_irqrestore(&pnp_bios_lock, flags);
38864
38865+ pax_open_kernel();
38866 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
38867+ pax_close_kernel();
38868+
38869 put_cpu();
38870
38871 /* If we get here and this is set then the PnP BIOS faulted on us. */
38872@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
38873 return status;
38874 }
38875
38876-void pnpbios_calls_init(union pnp_bios_install_struct *header)
38877+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
38878 {
38879 int i;
38880
38881@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
38882 pnp_bios_callpoint.offset = header->fields.pm16offset;
38883 pnp_bios_callpoint.segment = PNP_CS16;
38884
38885+ pax_open_kernel();
38886+
38887 for_each_possible_cpu(i) {
38888 struct desc_struct *gdt = get_cpu_gdt_table(i);
38889 if (!gdt)
38890@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
38891 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
38892 (unsigned long)__va(header->fields.pm16dseg));
38893 }
38894+
38895+ pax_close_kernel();
38896 }
38897diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
38898index 3e6db1c..1fbbdae 100644
38899--- a/drivers/pnp/resource.c
38900+++ b/drivers/pnp/resource.c
38901@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
38902 return 1;
38903
38904 /* check if the resource is valid */
38905- if (*irq < 0 || *irq > 15)
38906+ if (*irq > 15)
38907 return 0;
38908
38909 /* check if the resource is reserved */
38910@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
38911 return 1;
38912
38913 /* check if the resource is valid */
38914- if (*dma < 0 || *dma == 4 || *dma > 7)
38915+ if (*dma == 4 || *dma > 7)
38916 return 0;
38917
38918 /* check if the resource is reserved */
38919diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
38920index 7df7c5f..bd48c47 100644
38921--- a/drivers/power/pda_power.c
38922+++ b/drivers/power/pda_power.c
38923@@ -37,7 +37,11 @@ static int polling;
38924
38925 #ifdef CONFIG_USB_OTG_UTILS
38926 static struct usb_phy *transceiver;
38927-static struct notifier_block otg_nb;
38928+static int otg_handle_notification(struct notifier_block *nb,
38929+ unsigned long event, void *unused);
38930+static struct notifier_block otg_nb = {
38931+ .notifier_call = otg_handle_notification
38932+};
38933 #endif
38934
38935 static struct regulator *ac_draw;
38936@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
38937
38938 #ifdef CONFIG_USB_OTG_UTILS
38939 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
38940- otg_nb.notifier_call = otg_handle_notification;
38941 ret = usb_register_notifier(transceiver, &otg_nb);
38942 if (ret) {
38943 dev_err(dev, "failure to register otg notifier\n");
38944diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
38945index 4d7c635..9860196 100644
38946--- a/drivers/regulator/max8660.c
38947+++ b/drivers/regulator/max8660.c
38948@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
38949 max8660->shadow_regs[MAX8660_OVER1] = 5;
38950 } else {
38951 /* Otherwise devices can be toggled via software */
38952- max8660_dcdc_ops.enable = max8660_dcdc_enable;
38953- max8660_dcdc_ops.disable = max8660_dcdc_disable;
38954+ pax_open_kernel();
38955+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
38956+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
38957+ pax_close_kernel();
38958 }
38959
38960 /*
38961diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
38962index 9a8ea91..c483dd9 100644
38963--- a/drivers/regulator/max8973-regulator.c
38964+++ b/drivers/regulator/max8973-regulator.c
38965@@ -401,9 +401,11 @@ static int max8973_probe(struct i2c_client *client,
38966 if (!pdata->enable_ext_control) {
38967 max->desc.enable_reg = MAX8973_VOUT;
38968 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
38969- max8973_dcdc_ops.enable = regulator_enable_regmap;
38970- max8973_dcdc_ops.disable = regulator_disable_regmap;
38971- max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
38972+ pax_open_kernel();
38973+ *(void **)&max8973_dcdc_ops.enable = regulator_enable_regmap;
38974+ *(void **)&max8973_dcdc_ops.disable = regulator_disable_regmap;
38975+ *(void **)&max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
38976+ pax_close_kernel();
38977 }
38978
38979 max->enable_external_control = pdata->enable_ext_control;
38980diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
38981index 0d84b1f..c2da6ac 100644
38982--- a/drivers/regulator/mc13892-regulator.c
38983+++ b/drivers/regulator/mc13892-regulator.c
38984@@ -540,10 +540,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
38985 }
38986 mc13xxx_unlock(mc13892);
38987
38988- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
38989+ pax_open_kernel();
38990+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
38991 = mc13892_vcam_set_mode;
38992- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
38993+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
38994 = mc13892_vcam_get_mode;
38995+ pax_close_kernel();
38996
38997 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
38998 ARRAY_SIZE(mc13892_regulators));
38999diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
39000index 9a86b4b..3a383dc 100644
39001--- a/drivers/rtc/rtc-dev.c
39002+++ b/drivers/rtc/rtc-dev.c
39003@@ -14,6 +14,7 @@
39004 #include <linux/module.h>
39005 #include <linux/rtc.h>
39006 #include <linux/sched.h>
39007+#include <linux/grsecurity.h>
39008 #include "rtc-core.h"
39009
39010 static dev_t rtc_devt;
39011@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
39012 if (copy_from_user(&tm, uarg, sizeof(tm)))
39013 return -EFAULT;
39014
39015+ gr_log_timechange();
39016+
39017 return rtc_set_time(rtc, &tm);
39018
39019 case RTC_PIE_ON:
39020diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
39021index 4ad7e36..d004679 100644
39022--- a/drivers/scsi/bfa/bfa.h
39023+++ b/drivers/scsi/bfa/bfa.h
39024@@ -196,7 +196,7 @@ struct bfa_hwif_s {
39025 u32 *end);
39026 int cpe_vec_q0;
39027 int rme_vec_q0;
39028-};
39029+} __no_const;
39030 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
39031
39032 struct bfa_faa_cbfn_s {
39033diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
39034index e693af6..2e525b6 100644
39035--- a/drivers/scsi/bfa/bfa_fcpim.h
39036+++ b/drivers/scsi/bfa/bfa_fcpim.h
39037@@ -36,7 +36,7 @@ struct bfa_iotag_s {
39038
39039 struct bfa_itn_s {
39040 bfa_isr_func_t isr;
39041-};
39042+} __no_const;
39043
39044 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
39045 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
39046diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
39047index 23a90e7..9cf04ee 100644
39048--- a/drivers/scsi/bfa/bfa_ioc.h
39049+++ b/drivers/scsi/bfa/bfa_ioc.h
39050@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
39051 bfa_ioc_disable_cbfn_t disable_cbfn;
39052 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
39053 bfa_ioc_reset_cbfn_t reset_cbfn;
39054-};
39055+} __no_const;
39056
39057 /*
39058 * IOC event notification mechanism.
39059@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
39060 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
39061 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
39062 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
39063-};
39064+} __no_const;
39065
39066 /*
39067 * Queue element to wait for room in request queue. FIFO order is
39068diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
39069index 593085a..47aa999 100644
39070--- a/drivers/scsi/hosts.c
39071+++ b/drivers/scsi/hosts.c
39072@@ -42,7 +42,7 @@
39073 #include "scsi_logging.h"
39074
39075
39076-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
39077+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
39078
39079
39080 static void scsi_host_cls_release(struct device *dev)
39081@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
39082 * subtract one because we increment first then return, but we need to
39083 * know what the next host number was before increment
39084 */
39085- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
39086+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
39087 shost->dma_channel = 0xff;
39088
39089 /* These three are default values which can be overridden */
39090diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
39091index 4f33806..afd6f60 100644
39092--- a/drivers/scsi/hpsa.c
39093+++ b/drivers/scsi/hpsa.c
39094@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
39095 unsigned long flags;
39096
39097 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
39098- return h->access.command_completed(h, q);
39099+ return h->access->command_completed(h, q);
39100
39101 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
39102 a = rq->head[rq->current_entry];
39103@@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
39104 while (!list_empty(&h->reqQ)) {
39105 c = list_entry(h->reqQ.next, struct CommandList, list);
39106 /* can't do anything if fifo is full */
39107- if ((h->access.fifo_full(h))) {
39108+ if ((h->access->fifo_full(h))) {
39109 dev_warn(&h->pdev->dev, "fifo full\n");
39110 break;
39111 }
39112@@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
39113
39114 /* Tell the controller execute command */
39115 spin_unlock_irqrestore(&h->lock, flags);
39116- h->access.submit_command(h, c);
39117+ h->access->submit_command(h, c);
39118 spin_lock_irqsave(&h->lock, flags);
39119 }
39120 spin_unlock_irqrestore(&h->lock, flags);
39121@@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
39122
39123 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
39124 {
39125- return h->access.command_completed(h, q);
39126+ return h->access->command_completed(h, q);
39127 }
39128
39129 static inline bool interrupt_pending(struct ctlr_info *h)
39130 {
39131- return h->access.intr_pending(h);
39132+ return h->access->intr_pending(h);
39133 }
39134
39135 static inline long interrupt_not_for_us(struct ctlr_info *h)
39136 {
39137- return (h->access.intr_pending(h) == 0) ||
39138+ return (h->access->intr_pending(h) == 0) ||
39139 (h->interrupts_enabled == 0);
39140 }
39141
39142@@ -4316,7 +4316,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
39143 if (prod_index < 0)
39144 return -ENODEV;
39145 h->product_name = products[prod_index].product_name;
39146- h->access = *(products[prod_index].access);
39147+ h->access = products[prod_index].access;
39148
39149 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
39150 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
39151@@ -4598,7 +4598,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
39152
39153 assert_spin_locked(&lockup_detector_lock);
39154 remove_ctlr_from_lockup_detector_list(h);
39155- h->access.set_intr_mask(h, HPSA_INTR_OFF);
39156+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
39157 spin_lock_irqsave(&h->lock, flags);
39158 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
39159 spin_unlock_irqrestore(&h->lock, flags);
39160@@ -4775,7 +4775,7 @@ reinit_after_soft_reset:
39161 }
39162
39163 /* make sure the board interrupts are off */
39164- h->access.set_intr_mask(h, HPSA_INTR_OFF);
39165+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
39166
39167 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
39168 goto clean2;
39169@@ -4809,7 +4809,7 @@ reinit_after_soft_reset:
39170 * fake ones to scoop up any residual completions.
39171 */
39172 spin_lock_irqsave(&h->lock, flags);
39173- h->access.set_intr_mask(h, HPSA_INTR_OFF);
39174+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
39175 spin_unlock_irqrestore(&h->lock, flags);
39176 free_irqs(h);
39177 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
39178@@ -4828,9 +4828,9 @@ reinit_after_soft_reset:
39179 dev_info(&h->pdev->dev, "Board READY.\n");
39180 dev_info(&h->pdev->dev,
39181 "Waiting for stale completions to drain.\n");
39182- h->access.set_intr_mask(h, HPSA_INTR_ON);
39183+ h->access->set_intr_mask(h, HPSA_INTR_ON);
39184 msleep(10000);
39185- h->access.set_intr_mask(h, HPSA_INTR_OFF);
39186+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
39187
39188 rc = controller_reset_failed(h->cfgtable);
39189 if (rc)
39190@@ -4851,7 +4851,7 @@ reinit_after_soft_reset:
39191 }
39192
39193 /* Turn the interrupts on so we can service requests */
39194- h->access.set_intr_mask(h, HPSA_INTR_ON);
39195+ h->access->set_intr_mask(h, HPSA_INTR_ON);
39196
39197 hpsa_hba_inquiry(h);
39198 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
39199@@ -4903,7 +4903,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
39200 * To write all data in the battery backed cache to disks
39201 */
39202 hpsa_flush_cache(h);
39203- h->access.set_intr_mask(h, HPSA_INTR_OFF);
39204+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
39205 hpsa_free_irqs_and_disable_msix(h);
39206 }
39207
39208@@ -5071,7 +5071,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
39209 return;
39210 }
39211 /* Change the access methods to the performant access methods */
39212- h->access = SA5_performant_access;
39213+ h->access = &SA5_performant_access;
39214 h->transMethod = CFGTBL_Trans_Performant;
39215 }
39216
39217diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
39218index 9816479..c5d4e97 100644
39219--- a/drivers/scsi/hpsa.h
39220+++ b/drivers/scsi/hpsa.h
39221@@ -79,7 +79,7 @@ struct ctlr_info {
39222 unsigned int msix_vector;
39223 unsigned int msi_vector;
39224 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
39225- struct access_method access;
39226+ struct access_method *access;
39227
39228 /* queue and queue Info */
39229 struct list_head reqQ;
39230diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
39231index c772d8d..35c362c 100644
39232--- a/drivers/scsi/libfc/fc_exch.c
39233+++ b/drivers/scsi/libfc/fc_exch.c
39234@@ -100,12 +100,12 @@ struct fc_exch_mgr {
39235 u16 pool_max_index;
39236
39237 struct {
39238- atomic_t no_free_exch;
39239- atomic_t no_free_exch_xid;
39240- atomic_t xid_not_found;
39241- atomic_t xid_busy;
39242- atomic_t seq_not_found;
39243- atomic_t non_bls_resp;
39244+ atomic_unchecked_t no_free_exch;
39245+ atomic_unchecked_t no_free_exch_xid;
39246+ atomic_unchecked_t xid_not_found;
39247+ atomic_unchecked_t xid_busy;
39248+ atomic_unchecked_t seq_not_found;
39249+ atomic_unchecked_t non_bls_resp;
39250 } stats;
39251 };
39252
39253@@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
39254 /* allocate memory for exchange */
39255 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
39256 if (!ep) {
39257- atomic_inc(&mp->stats.no_free_exch);
39258+ atomic_inc_unchecked(&mp->stats.no_free_exch);
39259 goto out;
39260 }
39261 memset(ep, 0, sizeof(*ep));
39262@@ -786,7 +786,7 @@ out:
39263 return ep;
39264 err:
39265 spin_unlock_bh(&pool->lock);
39266- atomic_inc(&mp->stats.no_free_exch_xid);
39267+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
39268 mempool_free(ep, mp->ep_pool);
39269 return NULL;
39270 }
39271@@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
39272 xid = ntohs(fh->fh_ox_id); /* we originated exch */
39273 ep = fc_exch_find(mp, xid);
39274 if (!ep) {
39275- atomic_inc(&mp->stats.xid_not_found);
39276+ atomic_inc_unchecked(&mp->stats.xid_not_found);
39277 reject = FC_RJT_OX_ID;
39278 goto out;
39279 }
39280@@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
39281 ep = fc_exch_find(mp, xid);
39282 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
39283 if (ep) {
39284- atomic_inc(&mp->stats.xid_busy);
39285+ atomic_inc_unchecked(&mp->stats.xid_busy);
39286 reject = FC_RJT_RX_ID;
39287 goto rel;
39288 }
39289@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
39290 }
39291 xid = ep->xid; /* get our XID */
39292 } else if (!ep) {
39293- atomic_inc(&mp->stats.xid_not_found);
39294+ atomic_inc_unchecked(&mp->stats.xid_not_found);
39295 reject = FC_RJT_RX_ID; /* XID not found */
39296 goto out;
39297 }
39298@@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
39299 } else {
39300 sp = &ep->seq;
39301 if (sp->id != fh->fh_seq_id) {
39302- atomic_inc(&mp->stats.seq_not_found);
39303+ atomic_inc_unchecked(&mp->stats.seq_not_found);
39304 if (f_ctl & FC_FC_END_SEQ) {
39305 /*
39306 * Update sequence_id based on incoming last
39307@@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
39308
39309 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
39310 if (!ep) {
39311- atomic_inc(&mp->stats.xid_not_found);
39312+ atomic_inc_unchecked(&mp->stats.xid_not_found);
39313 goto out;
39314 }
39315 if (ep->esb_stat & ESB_ST_COMPLETE) {
39316- atomic_inc(&mp->stats.xid_not_found);
39317+ atomic_inc_unchecked(&mp->stats.xid_not_found);
39318 goto rel;
39319 }
39320 if (ep->rxid == FC_XID_UNKNOWN)
39321 ep->rxid = ntohs(fh->fh_rx_id);
39322 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
39323- atomic_inc(&mp->stats.xid_not_found);
39324+ atomic_inc_unchecked(&mp->stats.xid_not_found);
39325 goto rel;
39326 }
39327 if (ep->did != ntoh24(fh->fh_s_id) &&
39328 ep->did != FC_FID_FLOGI) {
39329- atomic_inc(&mp->stats.xid_not_found);
39330+ atomic_inc_unchecked(&mp->stats.xid_not_found);
39331 goto rel;
39332 }
39333 sof = fr_sof(fp);
39334@@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
39335 sp->ssb_stat |= SSB_ST_RESP;
39336 sp->id = fh->fh_seq_id;
39337 } else if (sp->id != fh->fh_seq_id) {
39338- atomic_inc(&mp->stats.seq_not_found);
39339+ atomic_inc_unchecked(&mp->stats.seq_not_found);
39340 goto rel;
39341 }
39342
39343@@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
39344 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
39345
39346 if (!sp)
39347- atomic_inc(&mp->stats.xid_not_found);
39348+ atomic_inc_unchecked(&mp->stats.xid_not_found);
39349 else
39350- atomic_inc(&mp->stats.non_bls_resp);
39351+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
39352
39353 fc_frame_free(fp);
39354 }
39355@@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
39356
39357 list_for_each_entry(ema, &lport->ema_list, ema_list) {
39358 mp = ema->mp;
39359- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
39360+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
39361 st->fc_no_free_exch_xid +=
39362- atomic_read(&mp->stats.no_free_exch_xid);
39363- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
39364- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
39365- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
39366- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
39367+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
39368+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
39369+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
39370+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
39371+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
39372 }
39373 }
39374 EXPORT_SYMBOL(fc_exch_update_stats);
39375diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
39376index bdb81cd..d3c7c2c 100644
39377--- a/drivers/scsi/libsas/sas_ata.c
39378+++ b/drivers/scsi/libsas/sas_ata.c
39379@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
39380 .postreset = ata_std_postreset,
39381 .error_handler = ata_std_error_handler,
39382 .post_internal_cmd = sas_ata_post_internal,
39383- .qc_defer = ata_std_qc_defer,
39384+ .qc_defer = ata_std_qc_defer,
39385 .qc_prep = ata_noop_qc_prep,
39386 .qc_issue = sas_ata_qc_issue,
39387 .qc_fill_rtf = sas_ata_qc_fill_rtf,
39388diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
39389index df4c13a..a51e90c 100644
39390--- a/drivers/scsi/lpfc/lpfc.h
39391+++ b/drivers/scsi/lpfc/lpfc.h
39392@@ -424,7 +424,7 @@ struct lpfc_vport {
39393 struct dentry *debug_nodelist;
39394 struct dentry *vport_debugfs_root;
39395 struct lpfc_debugfs_trc *disc_trc;
39396- atomic_t disc_trc_cnt;
39397+ atomic_unchecked_t disc_trc_cnt;
39398 #endif
39399 uint8_t stat_data_enabled;
39400 uint8_t stat_data_blocked;
39401@@ -842,8 +842,8 @@ struct lpfc_hba {
39402 struct timer_list fabric_block_timer;
39403 unsigned long bit_flags;
39404 #define FABRIC_COMANDS_BLOCKED 0
39405- atomic_t num_rsrc_err;
39406- atomic_t num_cmd_success;
39407+ atomic_unchecked_t num_rsrc_err;
39408+ atomic_unchecked_t num_cmd_success;
39409 unsigned long last_rsrc_error_time;
39410 unsigned long last_ramp_down_time;
39411 unsigned long last_ramp_up_time;
39412@@ -879,7 +879,7 @@ struct lpfc_hba {
39413
39414 struct dentry *debug_slow_ring_trc;
39415 struct lpfc_debugfs_trc *slow_ring_trc;
39416- atomic_t slow_ring_trc_cnt;
39417+ atomic_unchecked_t slow_ring_trc_cnt;
39418 /* iDiag debugfs sub-directory */
39419 struct dentry *idiag_root;
39420 struct dentry *idiag_pci_cfg;
39421diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
39422index f63f5ff..de29189 100644
39423--- a/drivers/scsi/lpfc/lpfc_debugfs.c
39424+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
39425@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
39426
39427 #include <linux/debugfs.h>
39428
39429-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
39430+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
39431 static unsigned long lpfc_debugfs_start_time = 0L;
39432
39433 /* iDiag */
39434@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
39435 lpfc_debugfs_enable = 0;
39436
39437 len = 0;
39438- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
39439+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
39440 (lpfc_debugfs_max_disc_trc - 1);
39441 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
39442 dtp = vport->disc_trc + i;
39443@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
39444 lpfc_debugfs_enable = 0;
39445
39446 len = 0;
39447- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
39448+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
39449 (lpfc_debugfs_max_slow_ring_trc - 1);
39450 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
39451 dtp = phba->slow_ring_trc + i;
39452@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
39453 !vport || !vport->disc_trc)
39454 return;
39455
39456- index = atomic_inc_return(&vport->disc_trc_cnt) &
39457+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
39458 (lpfc_debugfs_max_disc_trc - 1);
39459 dtp = vport->disc_trc + index;
39460 dtp->fmt = fmt;
39461 dtp->data1 = data1;
39462 dtp->data2 = data2;
39463 dtp->data3 = data3;
39464- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
39465+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
39466 dtp->jif = jiffies;
39467 #endif
39468 return;
39469@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
39470 !phba || !phba->slow_ring_trc)
39471 return;
39472
39473- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
39474+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
39475 (lpfc_debugfs_max_slow_ring_trc - 1);
39476 dtp = phba->slow_ring_trc + index;
39477 dtp->fmt = fmt;
39478 dtp->data1 = data1;
39479 dtp->data2 = data2;
39480 dtp->data3 = data3;
39481- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
39482+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
39483 dtp->jif = jiffies;
39484 #endif
39485 return;
39486@@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
39487 "slow_ring buffer\n");
39488 goto debug_failed;
39489 }
39490- atomic_set(&phba->slow_ring_trc_cnt, 0);
39491+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
39492 memset(phba->slow_ring_trc, 0,
39493 (sizeof(struct lpfc_debugfs_trc) *
39494 lpfc_debugfs_max_slow_ring_trc));
39495@@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
39496 "buffer\n");
39497 goto debug_failed;
39498 }
39499- atomic_set(&vport->disc_trc_cnt, 0);
39500+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
39501
39502 snprintf(name, sizeof(name), "discovery_trace");
39503 vport->debug_disc_trc =
39504diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
39505index 89ad558..76956c4 100644
39506--- a/drivers/scsi/lpfc/lpfc_init.c
39507+++ b/drivers/scsi/lpfc/lpfc_init.c
39508@@ -10618,8 +10618,10 @@ lpfc_init(void)
39509 "misc_register returned with status %d", error);
39510
39511 if (lpfc_enable_npiv) {
39512- lpfc_transport_functions.vport_create = lpfc_vport_create;
39513- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
39514+ pax_open_kernel();
39515+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
39516+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
39517+ pax_close_kernel();
39518 }
39519 lpfc_transport_template =
39520 fc_attach_transport(&lpfc_transport_functions);
39521diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
39522index 60e5a17..ff7a793 100644
39523--- a/drivers/scsi/lpfc/lpfc_scsi.c
39524+++ b/drivers/scsi/lpfc/lpfc_scsi.c
39525@@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
39526 uint32_t evt_posted;
39527
39528 spin_lock_irqsave(&phba->hbalock, flags);
39529- atomic_inc(&phba->num_rsrc_err);
39530+ atomic_inc_unchecked(&phba->num_rsrc_err);
39531 phba->last_rsrc_error_time = jiffies;
39532
39533 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
39534@@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
39535 unsigned long flags;
39536 struct lpfc_hba *phba = vport->phba;
39537 uint32_t evt_posted;
39538- atomic_inc(&phba->num_cmd_success);
39539+ atomic_inc_unchecked(&phba->num_cmd_success);
39540
39541 if (vport->cfg_lun_queue_depth <= queue_depth)
39542 return;
39543@@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
39544 unsigned long num_rsrc_err, num_cmd_success;
39545 int i;
39546
39547- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
39548- num_cmd_success = atomic_read(&phba->num_cmd_success);
39549+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
39550+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
39551
39552 /*
39553 * The error and success command counters are global per
39554@@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
39555 }
39556 }
39557 lpfc_destroy_vport_work_array(phba, vports);
39558- atomic_set(&phba->num_rsrc_err, 0);
39559- atomic_set(&phba->num_cmd_success, 0);
39560+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
39561+ atomic_set_unchecked(&phba->num_cmd_success, 0);
39562 }
39563
39564 /**
39565@@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
39566 }
39567 }
39568 lpfc_destroy_vport_work_array(phba, vports);
39569- atomic_set(&phba->num_rsrc_err, 0);
39570- atomic_set(&phba->num_cmd_success, 0);
39571+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
39572+ atomic_set_unchecked(&phba->num_cmd_success, 0);
39573 }
39574
39575 /**
39576diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
39577index b46f5e9..c4c4ccb 100644
39578--- a/drivers/scsi/pmcraid.c
39579+++ b/drivers/scsi/pmcraid.c
39580@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
39581 res->scsi_dev = scsi_dev;
39582 scsi_dev->hostdata = res;
39583 res->change_detected = 0;
39584- atomic_set(&res->read_failures, 0);
39585- atomic_set(&res->write_failures, 0);
39586+ atomic_set_unchecked(&res->read_failures, 0);
39587+ atomic_set_unchecked(&res->write_failures, 0);
39588 rc = 0;
39589 }
39590 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
39591@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
39592
39593 /* If this was a SCSI read/write command keep count of errors */
39594 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
39595- atomic_inc(&res->read_failures);
39596+ atomic_inc_unchecked(&res->read_failures);
39597 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
39598- atomic_inc(&res->write_failures);
39599+ atomic_inc_unchecked(&res->write_failures);
39600
39601 if (!RES_IS_GSCSI(res->cfg_entry) &&
39602 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
39603@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
39604 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
39605 * hrrq_id assigned here in queuecommand
39606 */
39607- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
39608+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
39609 pinstance->num_hrrq;
39610 cmd->cmd_done = pmcraid_io_done;
39611
39612@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
39613 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
39614 * hrrq_id assigned here in queuecommand
39615 */
39616- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
39617+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
39618 pinstance->num_hrrq;
39619
39620 if (request_size) {
39621@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
39622
39623 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
39624 /* add resources only after host is added into system */
39625- if (!atomic_read(&pinstance->expose_resources))
39626+ if (!atomic_read_unchecked(&pinstance->expose_resources))
39627 return;
39628
39629 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
39630@@ -5324,8 +5324,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
39631 init_waitqueue_head(&pinstance->reset_wait_q);
39632
39633 atomic_set(&pinstance->outstanding_cmds, 0);
39634- atomic_set(&pinstance->last_message_id, 0);
39635- atomic_set(&pinstance->expose_resources, 0);
39636+ atomic_set_unchecked(&pinstance->last_message_id, 0);
39637+ atomic_set_unchecked(&pinstance->expose_resources, 0);
39638
39639 INIT_LIST_HEAD(&pinstance->free_res_q);
39640 INIT_LIST_HEAD(&pinstance->used_res_q);
39641@@ -6038,7 +6038,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
39642 /* Schedule worker thread to handle CCN and take care of adding and
39643 * removing devices to OS
39644 */
39645- atomic_set(&pinstance->expose_resources, 1);
39646+ atomic_set_unchecked(&pinstance->expose_resources, 1);
39647 schedule_work(&pinstance->worker_q);
39648 return rc;
39649
39650diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
39651index e1d150f..6c6df44 100644
39652--- a/drivers/scsi/pmcraid.h
39653+++ b/drivers/scsi/pmcraid.h
39654@@ -748,7 +748,7 @@ struct pmcraid_instance {
39655 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
39656
39657 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
39658- atomic_t last_message_id;
39659+ atomic_unchecked_t last_message_id;
39660
39661 /* configuration table */
39662 struct pmcraid_config_table *cfg_table;
39663@@ -777,7 +777,7 @@ struct pmcraid_instance {
39664 atomic_t outstanding_cmds;
39665
39666 /* should add/delete resources to mid-layer now ?*/
39667- atomic_t expose_resources;
39668+ atomic_unchecked_t expose_resources;
39669
39670
39671
39672@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
39673 struct pmcraid_config_table_entry_ext cfg_entry_ext;
39674 };
39675 struct scsi_device *scsi_dev; /* Link scsi_device structure */
39676- atomic_t read_failures; /* count of failed READ commands */
39677- atomic_t write_failures; /* count of failed WRITE commands */
39678+ atomic_unchecked_t read_failures; /* count of failed READ commands */
39679+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
39680
39681 /* To indicate add/delete/modify during CCN */
39682 u8 change_detected;
39683diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
39684index 83d7984..a27d947 100644
39685--- a/drivers/scsi/qla2xxx/qla_attr.c
39686+++ b/drivers/scsi/qla2xxx/qla_attr.c
39687@@ -1969,7 +1969,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
39688 return 0;
39689 }
39690
39691-struct fc_function_template qla2xxx_transport_functions = {
39692+fc_function_template_no_const qla2xxx_transport_functions = {
39693
39694 .show_host_node_name = 1,
39695 .show_host_port_name = 1,
39696@@ -2016,7 +2016,7 @@ struct fc_function_template qla2xxx_transport_functions = {
39697 .bsg_timeout = qla24xx_bsg_timeout,
39698 };
39699
39700-struct fc_function_template qla2xxx_transport_vport_functions = {
39701+fc_function_template_no_const qla2xxx_transport_vport_functions = {
39702
39703 .show_host_node_name = 1,
39704 .show_host_port_name = 1,
39705diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
39706index 2411d1a..4673766 100644
39707--- a/drivers/scsi/qla2xxx/qla_gbl.h
39708+++ b/drivers/scsi/qla2xxx/qla_gbl.h
39709@@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
39710 struct device_attribute;
39711 extern struct device_attribute *qla2x00_host_attrs[];
39712 struct fc_function_template;
39713-extern struct fc_function_template qla2xxx_transport_functions;
39714-extern struct fc_function_template qla2xxx_transport_vport_functions;
39715+extern fc_function_template_no_const qla2xxx_transport_functions;
39716+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
39717 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
39718 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
39719 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
39720diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
39721index 10d23f8..a7d5d4c 100644
39722--- a/drivers/scsi/qla2xxx/qla_os.c
39723+++ b/drivers/scsi/qla2xxx/qla_os.c
39724@@ -1472,8 +1472,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
39725 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
39726 /* Ok, a 64bit DMA mask is applicable. */
39727 ha->flags.enable_64bit_addressing = 1;
39728- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
39729- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
39730+ pax_open_kernel();
39731+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
39732+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
39733+ pax_close_kernel();
39734 return;
39735 }
39736 }
39737diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
39738index 329d553..f20d31d 100644
39739--- a/drivers/scsi/qla4xxx/ql4_def.h
39740+++ b/drivers/scsi/qla4xxx/ql4_def.h
39741@@ -273,7 +273,7 @@ struct ddb_entry {
39742 * (4000 only) */
39743 atomic_t relogin_timer; /* Max Time to wait for
39744 * relogin to complete */
39745- atomic_t relogin_retry_count; /* Num of times relogin has been
39746+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
39747 * retried */
39748 uint32_t default_time2wait; /* Default Min time between
39749 * relogins (+aens) */
39750diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
39751index 4cec123..7c1329f 100644
39752--- a/drivers/scsi/qla4xxx/ql4_os.c
39753+++ b/drivers/scsi/qla4xxx/ql4_os.c
39754@@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
39755 */
39756 if (!iscsi_is_session_online(cls_sess)) {
39757 /* Reset retry relogin timer */
39758- atomic_inc(&ddb_entry->relogin_retry_count);
39759+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
39760 DEBUG2(ql4_printk(KERN_INFO, ha,
39761 "%s: index[%d] relogin timed out-retrying"
39762 " relogin (%d), retry (%d)\n", __func__,
39763 ddb_entry->fw_ddb_index,
39764- atomic_read(&ddb_entry->relogin_retry_count),
39765+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
39766 ddb_entry->default_time2wait + 4));
39767 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
39768 atomic_set(&ddb_entry->retry_relogin_timer,
39769@@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
39770
39771 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
39772 atomic_set(&ddb_entry->relogin_timer, 0);
39773- atomic_set(&ddb_entry->relogin_retry_count, 0);
39774+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
39775 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
39776 ddb_entry->default_relogin_timeout =
39777 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
39778diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
39779index 2c0d0ec..4e8681a 100644
39780--- a/drivers/scsi/scsi.c
39781+++ b/drivers/scsi/scsi.c
39782@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
39783 unsigned long timeout;
39784 int rtn = 0;
39785
39786- atomic_inc(&cmd->device->iorequest_cnt);
39787+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
39788
39789 /* check if the device is still usable */
39790 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
39791diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
39792index f1bf5af..f67e943 100644
39793--- a/drivers/scsi/scsi_lib.c
39794+++ b/drivers/scsi/scsi_lib.c
39795@@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
39796 shost = sdev->host;
39797 scsi_init_cmd_errh(cmd);
39798 cmd->result = DID_NO_CONNECT << 16;
39799- atomic_inc(&cmd->device->iorequest_cnt);
39800+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
39801
39802 /*
39803 * SCSI request completion path will do scsi_device_unbusy(),
39804@@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
39805
39806 INIT_LIST_HEAD(&cmd->eh_entry);
39807
39808- atomic_inc(&cmd->device->iodone_cnt);
39809+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
39810 if (cmd->result)
39811- atomic_inc(&cmd->device->ioerr_cnt);
39812+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
39813
39814 disposition = scsi_decide_disposition(cmd);
39815 if (disposition != SUCCESS &&
39816diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
39817index 931a7d9..0c2a754 100644
39818--- a/drivers/scsi/scsi_sysfs.c
39819+++ b/drivers/scsi/scsi_sysfs.c
39820@@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
39821 char *buf) \
39822 { \
39823 struct scsi_device *sdev = to_scsi_device(dev); \
39824- unsigned long long count = atomic_read(&sdev->field); \
39825+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
39826 return snprintf(buf, 20, "0x%llx\n", count); \
39827 } \
39828 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
39829diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
39830index 84a1fdf..693b0d6 100644
39831--- a/drivers/scsi/scsi_tgt_lib.c
39832+++ b/drivers/scsi/scsi_tgt_lib.c
39833@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
39834 int err;
39835
39836 dprintk("%lx %u\n", uaddr, len);
39837- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
39838+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
39839 if (err) {
39840 /*
39841 * TODO: need to fixup sg_tablesize, max_segment_size,
39842diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
39843index e894ca7..de9d7660 100644
39844--- a/drivers/scsi/scsi_transport_fc.c
39845+++ b/drivers/scsi/scsi_transport_fc.c
39846@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
39847 * Netlink Infrastructure
39848 */
39849
39850-static atomic_t fc_event_seq;
39851+static atomic_unchecked_t fc_event_seq;
39852
39853 /**
39854 * fc_get_event_number - Obtain the next sequential FC event number
39855@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
39856 u32
39857 fc_get_event_number(void)
39858 {
39859- return atomic_add_return(1, &fc_event_seq);
39860+ return atomic_add_return_unchecked(1, &fc_event_seq);
39861 }
39862 EXPORT_SYMBOL(fc_get_event_number);
39863
39864@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
39865 {
39866 int error;
39867
39868- atomic_set(&fc_event_seq, 0);
39869+ atomic_set_unchecked(&fc_event_seq, 0);
39870
39871 error = transport_class_register(&fc_host_class);
39872 if (error)
39873@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
39874 char *cp;
39875
39876 *val = simple_strtoul(buf, &cp, 0);
39877- if ((*cp && (*cp != '\n')) || (*val < 0))
39878+ if (*cp && (*cp != '\n'))
39879 return -EINVAL;
39880 /*
39881 * Check for overflow; dev_loss_tmo is u32
39882diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
39883index 31969f2..2b348f0 100644
39884--- a/drivers/scsi/scsi_transport_iscsi.c
39885+++ b/drivers/scsi/scsi_transport_iscsi.c
39886@@ -79,7 +79,7 @@ struct iscsi_internal {
39887 struct transport_container session_cont;
39888 };
39889
39890-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
39891+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
39892 static struct workqueue_struct *iscsi_eh_timer_workq;
39893
39894 static DEFINE_IDA(iscsi_sess_ida);
39895@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
39896 int err;
39897
39898 ihost = shost->shost_data;
39899- session->sid = atomic_add_return(1, &iscsi_session_nr);
39900+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
39901
39902 if (target_id == ISCSI_MAX_TARGET) {
39903 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
39904@@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
39905 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
39906 ISCSI_TRANSPORT_VERSION);
39907
39908- atomic_set(&iscsi_session_nr, 0);
39909+ atomic_set_unchecked(&iscsi_session_nr, 0);
39910
39911 err = class_register(&iscsi_transport_class);
39912 if (err)
39913diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
39914index f379c7f..e8fc69c 100644
39915--- a/drivers/scsi/scsi_transport_srp.c
39916+++ b/drivers/scsi/scsi_transport_srp.c
39917@@ -33,7 +33,7 @@
39918 #include "scsi_transport_srp_internal.h"
39919
39920 struct srp_host_attrs {
39921- atomic_t next_port_id;
39922+ atomic_unchecked_t next_port_id;
39923 };
39924 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
39925
39926@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
39927 struct Scsi_Host *shost = dev_to_shost(dev);
39928 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
39929
39930- atomic_set(&srp_host->next_port_id, 0);
39931+ atomic_set_unchecked(&srp_host->next_port_id, 0);
39932 return 0;
39933 }
39934
39935@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
39936 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
39937 rport->roles = ids->roles;
39938
39939- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
39940+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
39941 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
39942
39943 transport_setup_device(&rport->dev);
39944diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
39945index 7992635..609faf8 100644
39946--- a/drivers/scsi/sd.c
39947+++ b/drivers/scsi/sd.c
39948@@ -2909,7 +2909,7 @@ static int sd_probe(struct device *dev)
39949 sdkp->disk = gd;
39950 sdkp->index = index;
39951 atomic_set(&sdkp->openers, 0);
39952- atomic_set(&sdkp->device->ioerr_cnt, 0);
39953+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
39954
39955 if (!sdp->request_queue->rq_timeout) {
39956 if (sdp->type != TYPE_MOD)
39957diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
39958index be2c9a6..275525c 100644
39959--- a/drivers/scsi/sg.c
39960+++ b/drivers/scsi/sg.c
39961@@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
39962 sdp->disk->disk_name,
39963 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
39964 NULL,
39965- (char *)arg);
39966+ (char __user *)arg);
39967 case BLKTRACESTART:
39968 return blk_trace_startstop(sdp->device->request_queue, 1);
39969 case BLKTRACESTOP:
39970diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
39971index 19ee901..6e8c2ef 100644
39972--- a/drivers/spi/spi.c
39973+++ b/drivers/spi/spi.c
39974@@ -1616,7 +1616,7 @@ int spi_bus_unlock(struct spi_master *master)
39975 EXPORT_SYMBOL_GPL(spi_bus_unlock);
39976
39977 /* portable code must never pass more than 32 bytes */
39978-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
39979+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
39980
39981 static u8 *buf;
39982
39983diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
39984index 34afc16..ffe44dd 100644
39985--- a/drivers/staging/octeon/ethernet-rx.c
39986+++ b/drivers/staging/octeon/ethernet-rx.c
39987@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
39988 /* Increment RX stats for virtual ports */
39989 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
39990 #ifdef CONFIG_64BIT
39991- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
39992- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
39993+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
39994+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
39995 #else
39996- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
39997- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
39998+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
39999+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
40000 #endif
40001 }
40002 netif_receive_skb(skb);
40003@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
40004 dev->name);
40005 */
40006 #ifdef CONFIG_64BIT
40007- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
40008+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
40009 #else
40010- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
40011+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
40012 #endif
40013 dev_kfree_skb_irq(skb);
40014 }
40015diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
40016index ef32dc1..a159d68 100644
40017--- a/drivers/staging/octeon/ethernet.c
40018+++ b/drivers/staging/octeon/ethernet.c
40019@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
40020 * since the RX tasklet also increments it.
40021 */
40022 #ifdef CONFIG_64BIT
40023- atomic64_add(rx_status.dropped_packets,
40024- (atomic64_t *)&priv->stats.rx_dropped);
40025+ atomic64_add_unchecked(rx_status.dropped_packets,
40026+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
40027 #else
40028- atomic_add(rx_status.dropped_packets,
40029- (atomic_t *)&priv->stats.rx_dropped);
40030+ atomic_add_unchecked(rx_status.dropped_packets,
40031+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
40032 #endif
40033 }
40034
40035diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
40036index a2b7e03..aaf3630 100644
40037--- a/drivers/staging/ramster/tmem.c
40038+++ b/drivers/staging/ramster/tmem.c
40039@@ -50,25 +50,25 @@
40040 * A tmem host implementation must use this function to register callbacks
40041 * for memory allocation.
40042 */
40043-static struct tmem_hostops tmem_hostops;
40044+static struct tmem_hostops *tmem_hostops;
40045
40046 static void tmem_objnode_tree_init(void);
40047
40048 void tmem_register_hostops(struct tmem_hostops *m)
40049 {
40050 tmem_objnode_tree_init();
40051- tmem_hostops = *m;
40052+ tmem_hostops = m;
40053 }
40054
40055 /*
40056 * A tmem host implementation must use this function to register
40057 * callbacks for a page-accessible memory (PAM) implementation.
40058 */
40059-static struct tmem_pamops tmem_pamops;
40060+static struct tmem_pamops *tmem_pamops;
40061
40062 void tmem_register_pamops(struct tmem_pamops *m)
40063 {
40064- tmem_pamops = *m;
40065+ tmem_pamops = m;
40066 }
40067
40068 /*
40069@@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
40070 obj->pampd_count = 0;
40071 #ifdef CONFIG_RAMSTER
40072 if (tmem_pamops.new_obj != NULL)
40073- (*tmem_pamops.new_obj)(obj);
40074+ (tmem_pamops->new_obj)(obj);
40075 #endif
40076 SET_SENTINEL(obj, OBJ);
40077
40078@@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
40079 rbnode = rb_next(rbnode);
40080 tmem_pampd_destroy_all_in_obj(obj, true);
40081 tmem_obj_free(obj, hb);
40082- (*tmem_hostops.obj_free)(obj, pool);
40083+ (tmem_hostops->obj_free)(obj, pool);
40084 }
40085 spin_unlock(&hb->lock);
40086 }
40087@@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
40088 ASSERT_SENTINEL(obj, OBJ);
40089 BUG_ON(obj->pool == NULL);
40090 ASSERT_SENTINEL(obj->pool, POOL);
40091- objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
40092+ objnode = (tmem_hostops->objnode_alloc)(obj->pool);
40093 if (unlikely(objnode == NULL))
40094 goto out;
40095 objnode->obj = obj;
40096@@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
40097 ASSERT_SENTINEL(pool, POOL);
40098 objnode->obj->objnode_count--;
40099 objnode->obj = NULL;
40100- (*tmem_hostops.objnode_free)(objnode, pool);
40101+ (tmem_hostops->objnode_free)(objnode, pool);
40102 }
40103
40104 /*
40105@@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
40106 void *old_pampd = *(void **)slot;
40107 *(void **)slot = new_pampd;
40108 if (!no_free)
40109- (*tmem_pamops.free)(old_pampd, obj->pool,
40110+ (tmem_pamops->free)(old_pampd, obj->pool,
40111 NULL, 0, false);
40112 ret = new_pampd;
40113 }
40114@@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
40115 if (objnode->slots[i]) {
40116 if (ht == 1) {
40117 obj->pampd_count--;
40118- (*tmem_pamops.free)(objnode->slots[i],
40119+ (tmem_pamops->free)(objnode->slots[i],
40120 obj->pool, NULL, 0, true);
40121 objnode->slots[i] = NULL;
40122 continue;
40123@@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
40124 return;
40125 if (obj->objnode_tree_height == 0) {
40126 obj->pampd_count--;
40127- (*tmem_pamops.free)(obj->objnode_tree_root,
40128+ (tmem_pamops->free)(obj->objnode_tree_root,
40129 obj->pool, NULL, 0, true);
40130 } else {
40131 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
40132@@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
40133 obj->objnode_tree_root = NULL;
40134 #ifdef CONFIG_RAMSTER
40135 if (tmem_pamops.free_obj != NULL)
40136- (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
40137+ (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
40138 #endif
40139 }
40140
40141@@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
40142 /* if found, is a dup put, flush the old one */
40143 pampd_del = tmem_pampd_delete_from_obj(obj, index);
40144 BUG_ON(pampd_del != pampd);
40145- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
40146+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
40147 if (obj->pampd_count == 0) {
40148 objnew = obj;
40149 objfound = NULL;
40150@@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
40151 pampd = NULL;
40152 }
40153 } else {
40154- obj = objnew = (*tmem_hostops.obj_alloc)(pool);
40155+ obj = objnew = (tmem_hostops->obj_alloc)(pool);
40156 if (unlikely(obj == NULL)) {
40157 ret = -ENOMEM;
40158 goto out;
40159@@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
40160 if (unlikely(ret == -ENOMEM))
40161 /* may have partially built objnode tree ("stump") */
40162 goto delete_and_free;
40163- (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
40164+ (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
40165 goto out;
40166
40167 delete_and_free:
40168 (void)tmem_pampd_delete_from_obj(obj, index);
40169 if (pampd)
40170- (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
40171+ (tmem_pamops->free)(pampd, pool, NULL, 0, true);
40172 if (objnew) {
40173 tmem_obj_free(objnew, hb);
40174- (*tmem_hostops.obj_free)(objnew, pool);
40175+ (tmem_hostops->obj_free)(objnew, pool);
40176 }
40177 out:
40178 spin_unlock(&hb->lock);
40179@@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
40180 if (pampd != NULL) {
40181 BUG_ON(obj == NULL);
40182 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
40183- (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
40184+ (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
40185 } else if (delete) {
40186 BUG_ON(obj == NULL);
40187 (void)tmem_pampd_delete_from_obj(obj, index);
40188@@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
40189 int ret = 0;
40190
40191 if (!is_ephemeral(pool))
40192- new_pampd = (*tmem_pamops.repatriate_preload)(
40193+ new_pampd = (tmem_pamops->repatriate_preload)(
40194 old_pampd, pool, oidp, index, &intransit);
40195 if (intransit)
40196 ret = -EAGAIN;
40197@@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
40198 /* must release the hb->lock else repatriate can't sleep */
40199 spin_unlock(&hb->lock);
40200 if (!intransit)
40201- ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
40202+ ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
40203 oidp, index, free, data);
40204 if (ret == -EAGAIN) {
40205 /* rare I think, but should cond_resched()??? */
40206@@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
40207 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
40208 /* if we bug here, pamops wasn't properly set up for ramster */
40209 BUG_ON(tmem_pamops.replace_in_obj == NULL);
40210- ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
40211+ ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
40212 out:
40213 spin_unlock(&hb->lock);
40214 return ret;
40215@@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
40216 if (free) {
40217 if (obj->pampd_count == 0) {
40218 tmem_obj_free(obj, hb);
40219- (*tmem_hostops.obj_free)(obj, pool);
40220+ (tmem_hostops->obj_free)(obj, pool);
40221 obj = NULL;
40222 }
40223 }
40224 if (free)
40225- ret = (*tmem_pamops.get_data_and_free)(
40226+ ret = (tmem_pamops->get_data_and_free)(
40227 data, sizep, raw, pampd, pool, oidp, index);
40228 else
40229- ret = (*tmem_pamops.get_data)(
40230+ ret = (tmem_pamops->get_data)(
40231 data, sizep, raw, pampd, pool, oidp, index);
40232 if (ret < 0)
40233 goto out;
40234@@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
40235 pampd = tmem_pampd_delete_from_obj(obj, index);
40236 if (pampd == NULL)
40237 goto out;
40238- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
40239+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
40240 if (obj->pampd_count == 0) {
40241 tmem_obj_free(obj, hb);
40242- (*tmem_hostops.obj_free)(obj, pool);
40243+ (tmem_hostops->obj_free)(obj, pool);
40244 }
40245 ret = 0;
40246
40247@@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
40248 goto out;
40249 tmem_pampd_destroy_all_in_obj(obj, false);
40250 tmem_obj_free(obj, hb);
40251- (*tmem_hostops.obj_free)(obj, pool);
40252+ (tmem_hostops->obj_free)(obj, pool);
40253 ret = 0;
40254
40255 out:
40256diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
40257index dc23395..cf7e9b1 100644
40258--- a/drivers/staging/rtl8712/rtl871x_io.h
40259+++ b/drivers/staging/rtl8712/rtl871x_io.h
40260@@ -108,7 +108,7 @@ struct _io_ops {
40261 u8 *pmem);
40262 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
40263 u8 *pmem);
40264-};
40265+} __no_const;
40266
40267 struct io_req {
40268 struct list_head list;
40269diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
40270index 1f5088b..0e59820 100644
40271--- a/drivers/staging/sbe-2t3e3/netdev.c
40272+++ b/drivers/staging/sbe-2t3e3/netdev.c
40273@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40274 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
40275
40276 if (rlen)
40277- if (copy_to_user(data, &resp, rlen))
40278+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
40279 return -EFAULT;
40280
40281 return 0;
40282diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
40283index 5dddc4d..34fcb2f 100644
40284--- a/drivers/staging/usbip/vhci.h
40285+++ b/drivers/staging/usbip/vhci.h
40286@@ -83,7 +83,7 @@ struct vhci_hcd {
40287 unsigned resuming:1;
40288 unsigned long re_timeout;
40289
40290- atomic_t seqnum;
40291+ atomic_unchecked_t seqnum;
40292
40293 /*
40294 * NOTE:
40295diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
40296index c3aa219..bf8b3de 100644
40297--- a/drivers/staging/usbip/vhci_hcd.c
40298+++ b/drivers/staging/usbip/vhci_hcd.c
40299@@ -451,7 +451,7 @@ static void vhci_tx_urb(struct urb *urb)
40300 return;
40301 }
40302
40303- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
40304+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
40305 if (priv->seqnum == 0xffff)
40306 dev_info(&urb->dev->dev, "seqnum max\n");
40307
40308@@ -703,7 +703,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
40309 return -ENOMEM;
40310 }
40311
40312- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
40313+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
40314 if (unlink->seqnum == 0xffff)
40315 pr_info("seqnum max\n");
40316
40317@@ -907,7 +907,7 @@ static int vhci_start(struct usb_hcd *hcd)
40318 vdev->rhport = rhport;
40319 }
40320
40321- atomic_set(&vhci->seqnum, 0);
40322+ atomic_set_unchecked(&vhci->seqnum, 0);
40323 spin_lock_init(&vhci->lock);
40324
40325 hcd->power_budget = 0; /* no limit */
40326diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
40327index ba5f1c0..11d8122 100644
40328--- a/drivers/staging/usbip/vhci_rx.c
40329+++ b/drivers/staging/usbip/vhci_rx.c
40330@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
40331 if (!urb) {
40332 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
40333 pr_info("max seqnum %d\n",
40334- atomic_read(&the_controller->seqnum));
40335+ atomic_read_unchecked(&the_controller->seqnum));
40336 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
40337 return;
40338 }
40339diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
40340index 5f13890..36a044b 100644
40341--- a/drivers/staging/vt6655/hostap.c
40342+++ b/drivers/staging/vt6655/hostap.c
40343@@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
40344 *
40345 */
40346
40347+static net_device_ops_no_const apdev_netdev_ops;
40348+
40349 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
40350 {
40351 PSDevice apdev_priv;
40352 struct net_device *dev = pDevice->dev;
40353 int ret;
40354- const struct net_device_ops apdev_netdev_ops = {
40355- .ndo_start_xmit = pDevice->tx_80211,
40356- };
40357
40358 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
40359
40360@@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
40361 *apdev_priv = *pDevice;
40362 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
40363
40364+ /* only half broken now */
40365+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
40366 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
40367
40368 pDevice->apdev->type = ARPHRD_IEEE80211;
40369diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
40370index 26a7d0e..897b083 100644
40371--- a/drivers/staging/vt6656/hostap.c
40372+++ b/drivers/staging/vt6656/hostap.c
40373@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
40374 *
40375 */
40376
40377+static net_device_ops_no_const apdev_netdev_ops;
40378+
40379 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
40380 {
40381 PSDevice apdev_priv;
40382 struct net_device *dev = pDevice->dev;
40383 int ret;
40384- const struct net_device_ops apdev_netdev_ops = {
40385- .ndo_start_xmit = pDevice->tx_80211,
40386- };
40387
40388 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
40389
40390@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
40391 *apdev_priv = *pDevice;
40392 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
40393
40394+ /* only half broken now */
40395+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
40396 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
40397
40398 pDevice->apdev->type = ARPHRD_IEEE80211;
40399diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
40400index 56c8e60..1920c63 100644
40401--- a/drivers/staging/zcache/tmem.c
40402+++ b/drivers/staging/zcache/tmem.c
40403@@ -39,7 +39,7 @@
40404 * A tmem host implementation must use this function to register callbacks
40405 * for memory allocation.
40406 */
40407-static struct tmem_hostops tmem_hostops;
40408+static tmem_hostops_no_const tmem_hostops;
40409
40410 static void tmem_objnode_tree_init(void);
40411
40412@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
40413 * A tmem host implementation must use this function to register
40414 * callbacks for a page-accessible memory (PAM) implementation
40415 */
40416-static struct tmem_pamops tmem_pamops;
40417+static tmem_pamops_no_const tmem_pamops;
40418
40419 void tmem_register_pamops(struct tmem_pamops *m)
40420 {
40421diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
40422index 0d4aa82..f7832d4 100644
40423--- a/drivers/staging/zcache/tmem.h
40424+++ b/drivers/staging/zcache/tmem.h
40425@@ -180,6 +180,7 @@ struct tmem_pamops {
40426 void (*new_obj)(struct tmem_obj *);
40427 int (*replace_in_obj)(void *, struct tmem_obj *);
40428 };
40429+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
40430 extern void tmem_register_pamops(struct tmem_pamops *m);
40431
40432 /* memory allocation methods provided by the host implementation */
40433@@ -189,6 +190,7 @@ struct tmem_hostops {
40434 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
40435 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
40436 };
40437+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
40438 extern void tmem_register_hostops(struct tmem_hostops *m);
40439
40440 /* core tmem accessor functions */
40441diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
40442index f2aa754..11337b1 100644
40443--- a/drivers/target/target_core_device.c
40444+++ b/drivers/target/target_core_device.c
40445@@ -1375,7 +1375,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
40446 spin_lock_init(&dev->se_port_lock);
40447 spin_lock_init(&dev->se_tmr_lock);
40448 spin_lock_init(&dev->qf_cmd_lock);
40449- atomic_set(&dev->dev_ordered_id, 0);
40450+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
40451 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
40452 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
40453 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
40454diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
40455index bd587b7..173daf3 100644
40456--- a/drivers/target/target_core_transport.c
40457+++ b/drivers/target/target_core_transport.c
40458@@ -1077,7 +1077,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
40459 * Used to determine when ORDERED commands should go from
40460 * Dormant to Active status.
40461 */
40462- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
40463+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
40464 smp_mb__after_atomic_inc();
40465 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
40466 cmd->se_ordered_id, cmd->sam_task_attr,
40467diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
40468index b09c8d1f..c4225c0 100644
40469--- a/drivers/tty/cyclades.c
40470+++ b/drivers/tty/cyclades.c
40471@@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
40472 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
40473 info->port.count);
40474 #endif
40475- info->port.count++;
40476+ atomic_inc(&info->port.count);
40477 #ifdef CY_DEBUG_COUNT
40478 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
40479- current->pid, info->port.count);
40480+ current->pid, atomic_read(&info->port.count));
40481 #endif
40482
40483 /*
40484@@ -3991,7 +3991,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
40485 for (j = 0; j < cy_card[i].nports; j++) {
40486 info = &cy_card[i].ports[j];
40487
40488- if (info->port.count) {
40489+ if (atomic_read(&info->port.count)) {
40490 /* XXX is the ldisc num worth this? */
40491 struct tty_struct *tty;
40492 struct tty_ldisc *ld;
40493diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
40494index 13ee53b..418d164 100644
40495--- a/drivers/tty/hvc/hvc_console.c
40496+++ b/drivers/tty/hvc/hvc_console.c
40497@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
40498
40499 spin_lock_irqsave(&hp->port.lock, flags);
40500 /* Check and then increment for fast path open. */
40501- if (hp->port.count++ > 0) {
40502+ if (atomic_inc_return(&hp->port.count) > 1) {
40503 spin_unlock_irqrestore(&hp->port.lock, flags);
40504 hvc_kick();
40505 return 0;
40506@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
40507
40508 spin_lock_irqsave(&hp->port.lock, flags);
40509
40510- if (--hp->port.count == 0) {
40511+ if (atomic_dec_return(&hp->port.count) == 0) {
40512 spin_unlock_irqrestore(&hp->port.lock, flags);
40513 /* We are done with the tty pointer now. */
40514 tty_port_tty_set(&hp->port, NULL);
40515@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
40516 */
40517 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
40518 } else {
40519- if (hp->port.count < 0)
40520+ if (atomic_read(&hp->port.count) < 0)
40521 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
40522- hp->vtermno, hp->port.count);
40523+ hp->vtermno, atomic_read(&hp->port.count));
40524 spin_unlock_irqrestore(&hp->port.lock, flags);
40525 }
40526 }
40527@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
40528 * open->hangup case this can be called after the final close so prevent
40529 * that from happening for now.
40530 */
40531- if (hp->port.count <= 0) {
40532+ if (atomic_read(&hp->port.count) <= 0) {
40533 spin_unlock_irqrestore(&hp->port.lock, flags);
40534 return;
40535 }
40536
40537- hp->port.count = 0;
40538+ atomic_set(&hp->port.count, 0);
40539 spin_unlock_irqrestore(&hp->port.lock, flags);
40540 tty_port_tty_set(&hp->port, NULL);
40541
40542@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
40543 return -EPIPE;
40544
40545 /* FIXME what's this (unprotected) check for? */
40546- if (hp->port.count <= 0)
40547+ if (atomic_read(&hp->port.count) <= 0)
40548 return -EIO;
40549
40550 spin_lock_irqsave(&hp->lock, flags);
40551diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
40552index 8776357..b2d4afd 100644
40553--- a/drivers/tty/hvc/hvcs.c
40554+++ b/drivers/tty/hvc/hvcs.c
40555@@ -83,6 +83,7 @@
40556 #include <asm/hvcserver.h>
40557 #include <asm/uaccess.h>
40558 #include <asm/vio.h>
40559+#include <asm/local.h>
40560
40561 /*
40562 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
40563@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
40564
40565 spin_lock_irqsave(&hvcsd->lock, flags);
40566
40567- if (hvcsd->port.count > 0) {
40568+ if (atomic_read(&hvcsd->port.count) > 0) {
40569 spin_unlock_irqrestore(&hvcsd->lock, flags);
40570 printk(KERN_INFO "HVCS: vterm state unchanged. "
40571 "The hvcs device node is still in use.\n");
40572@@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
40573 }
40574 }
40575
40576- hvcsd->port.count = 0;
40577+ atomic_set(&hvcsd->port.count, 0);
40578 hvcsd->port.tty = tty;
40579 tty->driver_data = hvcsd;
40580
40581@@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
40582 unsigned long flags;
40583
40584 spin_lock_irqsave(&hvcsd->lock, flags);
40585- hvcsd->port.count++;
40586+ atomic_inc(&hvcsd->port.count);
40587 hvcsd->todo_mask |= HVCS_SCHED_READ;
40588 spin_unlock_irqrestore(&hvcsd->lock, flags);
40589
40590@@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
40591 hvcsd = tty->driver_data;
40592
40593 spin_lock_irqsave(&hvcsd->lock, flags);
40594- if (--hvcsd->port.count == 0) {
40595+ if (atomic_dec_and_test(&hvcsd->port.count)) {
40596
40597 vio_disable_interrupts(hvcsd->vdev);
40598
40599@@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
40600
40601 free_irq(irq, hvcsd);
40602 return;
40603- } else if (hvcsd->port.count < 0) {
40604+ } else if (atomic_read(&hvcsd->port.count) < 0) {
40605 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
40606 " is missmanaged.\n",
40607- hvcsd->vdev->unit_address, hvcsd->port.count);
40608+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
40609 }
40610
40611 spin_unlock_irqrestore(&hvcsd->lock, flags);
40612@@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
40613
40614 spin_lock_irqsave(&hvcsd->lock, flags);
40615 /* Preserve this so that we know how many kref refs to put */
40616- temp_open_count = hvcsd->port.count;
40617+ temp_open_count = atomic_read(&hvcsd->port.count);
40618
40619 /*
40620 * Don't kref put inside the spinlock because the destruction
40621@@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
40622 tty->driver_data = NULL;
40623 hvcsd->port.tty = NULL;
40624
40625- hvcsd->port.count = 0;
40626+ atomic_set(&hvcsd->port.count, 0);
40627
40628 /* This will drop any buffered data on the floor which is OK in a hangup
40629 * scenario. */
40630@@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
40631 * the middle of a write operation? This is a crummy place to do this
40632 * but we want to keep it all in the spinlock.
40633 */
40634- if (hvcsd->port.count <= 0) {
40635+ if (atomic_read(&hvcsd->port.count) <= 0) {
40636 spin_unlock_irqrestore(&hvcsd->lock, flags);
40637 return -ENODEV;
40638 }
40639@@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
40640 {
40641 struct hvcs_struct *hvcsd = tty->driver_data;
40642
40643- if (!hvcsd || hvcsd->port.count <= 0)
40644+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
40645 return 0;
40646
40647 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
40648diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
40649index 2cde13d..645d78f 100644
40650--- a/drivers/tty/ipwireless/tty.c
40651+++ b/drivers/tty/ipwireless/tty.c
40652@@ -29,6 +29,7 @@
40653 #include <linux/tty_driver.h>
40654 #include <linux/tty_flip.h>
40655 #include <linux/uaccess.h>
40656+#include <asm/local.h>
40657
40658 #include "tty.h"
40659 #include "network.h"
40660@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
40661 mutex_unlock(&tty->ipw_tty_mutex);
40662 return -ENODEV;
40663 }
40664- if (tty->port.count == 0)
40665+ if (atomic_read(&tty->port.count) == 0)
40666 tty->tx_bytes_queued = 0;
40667
40668- tty->port.count++;
40669+ atomic_inc(&tty->port.count);
40670
40671 tty->port.tty = linux_tty;
40672 linux_tty->driver_data = tty;
40673@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
40674
40675 static void do_ipw_close(struct ipw_tty *tty)
40676 {
40677- tty->port.count--;
40678-
40679- if (tty->port.count == 0) {
40680+ if (atomic_dec_return(&tty->port.count) == 0) {
40681 struct tty_struct *linux_tty = tty->port.tty;
40682
40683 if (linux_tty != NULL) {
40684@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
40685 return;
40686
40687 mutex_lock(&tty->ipw_tty_mutex);
40688- if (tty->port.count == 0) {
40689+ if (atomic_read(&tty->port.count) == 0) {
40690 mutex_unlock(&tty->ipw_tty_mutex);
40691 return;
40692 }
40693@@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
40694 return;
40695 }
40696
40697- if (!tty->port.count) {
40698+ if (!atomic_read(&tty->port.count)) {
40699 mutex_unlock(&tty->ipw_tty_mutex);
40700 return;
40701 }
40702@@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
40703 return -ENODEV;
40704
40705 mutex_lock(&tty->ipw_tty_mutex);
40706- if (!tty->port.count) {
40707+ if (!atomic_read(&tty->port.count)) {
40708 mutex_unlock(&tty->ipw_tty_mutex);
40709 return -EINVAL;
40710 }
40711@@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
40712 if (!tty)
40713 return -ENODEV;
40714
40715- if (!tty->port.count)
40716+ if (!atomic_read(&tty->port.count))
40717 return -EINVAL;
40718
40719 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
40720@@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
40721 if (!tty)
40722 return 0;
40723
40724- if (!tty->port.count)
40725+ if (!atomic_read(&tty->port.count))
40726 return 0;
40727
40728 return tty->tx_bytes_queued;
40729@@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
40730 if (!tty)
40731 return -ENODEV;
40732
40733- if (!tty->port.count)
40734+ if (!atomic_read(&tty->port.count))
40735 return -EINVAL;
40736
40737 return get_control_lines(tty);
40738@@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
40739 if (!tty)
40740 return -ENODEV;
40741
40742- if (!tty->port.count)
40743+ if (!atomic_read(&tty->port.count))
40744 return -EINVAL;
40745
40746 return set_control_lines(tty, set, clear);
40747@@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
40748 if (!tty)
40749 return -ENODEV;
40750
40751- if (!tty->port.count)
40752+ if (!atomic_read(&tty->port.count))
40753 return -EINVAL;
40754
40755 /* FIXME: Exactly how is the tty object locked here .. */
40756@@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
40757 * are gone */
40758 mutex_lock(&ttyj->ipw_tty_mutex);
40759 }
40760- while (ttyj->port.count)
40761+ while (atomic_read(&ttyj->port.count))
40762 do_ipw_close(ttyj);
40763 ipwireless_disassociate_network_ttys(network,
40764 ttyj->channel_idx);
40765diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
40766index f9d2850..b006f04 100644
40767--- a/drivers/tty/moxa.c
40768+++ b/drivers/tty/moxa.c
40769@@ -1193,7 +1193,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
40770 }
40771
40772 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
40773- ch->port.count++;
40774+ atomic_inc(&ch->port.count);
40775 tty->driver_data = ch;
40776 tty_port_tty_set(&ch->port, tty);
40777 mutex_lock(&ch->port.mutex);
40778diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
40779index bfd6771..e0d93c4 100644
40780--- a/drivers/tty/n_gsm.c
40781+++ b/drivers/tty/n_gsm.c
40782@@ -1636,7 +1636,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
40783 spin_lock_init(&dlci->lock);
40784 mutex_init(&dlci->mutex);
40785 dlci->fifo = &dlci->_fifo;
40786- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
40787+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
40788 kfree(dlci);
40789 return NULL;
40790 }
40791@@ -2936,7 +2936,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
40792 struct gsm_dlci *dlci = tty->driver_data;
40793 struct tty_port *port = &dlci->port;
40794
40795- port->count++;
40796+ atomic_inc(&port->count);
40797 dlci_get(dlci);
40798 dlci_get(dlci->gsm->dlci[0]);
40799 mux_get(dlci->gsm);
40800diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
40801index 19083ef..6e34e97 100644
40802--- a/drivers/tty/n_tty.c
40803+++ b/drivers/tty/n_tty.c
40804@@ -2196,6 +2196,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
40805 {
40806 *ops = tty_ldisc_N_TTY;
40807 ops->owner = NULL;
40808- ops->refcount = ops->flags = 0;
40809+ atomic_set(&ops->refcount, 0);
40810+ ops->flags = 0;
40811 }
40812 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
40813diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
40814index 79ff3a5..1fe9399 100644
40815--- a/drivers/tty/pty.c
40816+++ b/drivers/tty/pty.c
40817@@ -791,8 +791,10 @@ static void __init unix98_pty_init(void)
40818 panic("Couldn't register Unix98 pts driver");
40819
40820 /* Now create the /dev/ptmx special device */
40821+ pax_open_kernel();
40822 tty_default_fops(&ptmx_fops);
40823- ptmx_fops.open = ptmx_open;
40824+ *(void **)&ptmx_fops.open = ptmx_open;
40825+ pax_close_kernel();
40826
40827 cdev_init(&ptmx_cdev, &ptmx_fops);
40828 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
40829diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
40830index e42009a..566a036 100644
40831--- a/drivers/tty/rocket.c
40832+++ b/drivers/tty/rocket.c
40833@@ -925,7 +925,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
40834 tty->driver_data = info;
40835 tty_port_tty_set(port, tty);
40836
40837- if (port->count++ == 0) {
40838+ if (atomic_inc_return(&port->count) == 1) {
40839 atomic_inc(&rp_num_ports_open);
40840
40841 #ifdef ROCKET_DEBUG_OPEN
40842@@ -934,7 +934,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
40843 #endif
40844 }
40845 #ifdef ROCKET_DEBUG_OPEN
40846- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
40847+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
40848 #endif
40849
40850 /*
40851@@ -1529,7 +1529,7 @@ static void rp_hangup(struct tty_struct *tty)
40852 spin_unlock_irqrestore(&info->port.lock, flags);
40853 return;
40854 }
40855- if (info->port.count)
40856+ if (atomic_read(&info->port.count))
40857 atomic_dec(&rp_num_ports_open);
40858 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
40859 spin_unlock_irqrestore(&info->port.lock, flags);
40860diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
40861index 1002054..dd644a8 100644
40862--- a/drivers/tty/serial/kgdboc.c
40863+++ b/drivers/tty/serial/kgdboc.c
40864@@ -24,8 +24,9 @@
40865 #define MAX_CONFIG_LEN 40
40866
40867 static struct kgdb_io kgdboc_io_ops;
40868+static struct kgdb_io kgdboc_io_ops_console;
40869
40870-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
40871+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
40872 static int configured = -1;
40873
40874 static char config[MAX_CONFIG_LEN];
40875@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
40876 kgdboc_unregister_kbd();
40877 if (configured == 1)
40878 kgdb_unregister_io_module(&kgdboc_io_ops);
40879+ else if (configured == 2)
40880+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
40881 }
40882
40883 static int configure_kgdboc(void)
40884@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
40885 int err;
40886 char *cptr = config;
40887 struct console *cons;
40888+ int is_console = 0;
40889
40890 err = kgdboc_option_setup(config);
40891 if (err || !strlen(config) || isspace(config[0]))
40892 goto noconfig;
40893
40894 err = -ENODEV;
40895- kgdboc_io_ops.is_console = 0;
40896 kgdb_tty_driver = NULL;
40897
40898 kgdboc_use_kms = 0;
40899@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
40900 int idx;
40901 if (cons->device && cons->device(cons, &idx) == p &&
40902 idx == tty_line) {
40903- kgdboc_io_ops.is_console = 1;
40904+ is_console = 1;
40905 break;
40906 }
40907 cons = cons->next;
40908@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
40909 kgdb_tty_line = tty_line;
40910
40911 do_register:
40912- err = kgdb_register_io_module(&kgdboc_io_ops);
40913+ if (is_console) {
40914+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
40915+ configured = 2;
40916+ } else {
40917+ err = kgdb_register_io_module(&kgdboc_io_ops);
40918+ configured = 1;
40919+ }
40920 if (err)
40921 goto noconfig;
40922
40923@@ -205,8 +214,6 @@ do_register:
40924 if (err)
40925 goto nmi_con_failed;
40926
40927- configured = 1;
40928-
40929 return 0;
40930
40931 nmi_con_failed:
40932@@ -223,7 +230,7 @@ noconfig:
40933 static int __init init_kgdboc(void)
40934 {
40935 /* Already configured? */
40936- if (configured == 1)
40937+ if (configured >= 1)
40938 return 0;
40939
40940 return configure_kgdboc();
40941@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
40942 if (config[len - 1] == '\n')
40943 config[len - 1] = '\0';
40944
40945- if (configured == 1)
40946+ if (configured >= 1)
40947 cleanup_kgdboc();
40948
40949 /* Go and configure with the new params. */
40950@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
40951 .post_exception = kgdboc_post_exp_handler,
40952 };
40953
40954+static struct kgdb_io kgdboc_io_ops_console = {
40955+ .name = "kgdboc",
40956+ .read_char = kgdboc_get_char,
40957+ .write_char = kgdboc_put_char,
40958+ .pre_exception = kgdboc_pre_exp_handler,
40959+ .post_exception = kgdboc_post_exp_handler,
40960+ .is_console = 1
40961+};
40962+
40963 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
40964 /* This is only available if kgdboc is a built in for early debugging */
40965 static int __init kgdboc_early_init(char *opt)
40966diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
40967index e514b3a..c73d614 100644
40968--- a/drivers/tty/serial/samsung.c
40969+++ b/drivers/tty/serial/samsung.c
40970@@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
40971 }
40972 }
40973
40974+static int s3c64xx_serial_startup(struct uart_port *port);
40975 static int s3c24xx_serial_startup(struct uart_port *port)
40976 {
40977 struct s3c24xx_uart_port *ourport = to_ourport(port);
40978 int ret;
40979
40980+ /* Startup sequence is different for s3c64xx and higher SoC's */
40981+ if (s3c24xx_serial_has_interrupt_mask(port))
40982+ return s3c64xx_serial_startup(port);
40983+
40984 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
40985 port->mapbase, port->membase);
40986
40987@@ -1122,10 +1127,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
40988 /* setup info for port */
40989 port->dev = &platdev->dev;
40990
40991- /* Startup sequence is different for s3c64xx and higher SoC's */
40992- if (s3c24xx_serial_has_interrupt_mask(port))
40993- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
40994-
40995 port->uartclk = 1;
40996
40997 if (cfg->uart_flags & UPF_CONS_FLOW) {
40998diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
40999index 2c7230a..2104f16 100644
41000--- a/drivers/tty/serial/serial_core.c
41001+++ b/drivers/tty/serial/serial_core.c
41002@@ -1455,7 +1455,7 @@ static void uart_hangup(struct tty_struct *tty)
41003 uart_flush_buffer(tty);
41004 uart_shutdown(tty, state);
41005 spin_lock_irqsave(&port->lock, flags);
41006- port->count = 0;
41007+ atomic_set(&port->count, 0);
41008 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
41009 spin_unlock_irqrestore(&port->lock, flags);
41010 tty_port_tty_set(port, NULL);
41011@@ -1551,7 +1551,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
41012 goto end;
41013 }
41014
41015- port->count++;
41016+ atomic_inc(&port->count);
41017 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
41018 retval = -ENXIO;
41019 goto err_dec_count;
41020@@ -1578,7 +1578,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
41021 /*
41022 * Make sure the device is in D0 state.
41023 */
41024- if (port->count == 1)
41025+ if (atomic_read(&port->count) == 1)
41026 uart_change_pm(state, 0);
41027
41028 /*
41029@@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
41030 end:
41031 return retval;
41032 err_dec_count:
41033- port->count--;
41034+ atomic_inc(&port->count);
41035 mutex_unlock(&port->mutex);
41036 goto end;
41037 }
41038diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
41039index 9e071f6..f30ae69 100644
41040--- a/drivers/tty/synclink.c
41041+++ b/drivers/tty/synclink.c
41042@@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
41043
41044 if (debug_level >= DEBUG_LEVEL_INFO)
41045 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
41046- __FILE__,__LINE__, info->device_name, info->port.count);
41047+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
41048
41049 if (tty_port_close_start(&info->port, tty, filp) == 0)
41050 goto cleanup;
41051@@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
41052 cleanup:
41053 if (debug_level >= DEBUG_LEVEL_INFO)
41054 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
41055- tty->driver->name, info->port.count);
41056+ tty->driver->name, atomic_read(&info->port.count));
41057
41058 } /* end of mgsl_close() */
41059
41060@@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
41061
41062 mgsl_flush_buffer(tty);
41063 shutdown(info);
41064-
41065- info->port.count = 0;
41066+
41067+ atomic_set(&info->port.count, 0);
41068 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
41069 info->port.tty = NULL;
41070
41071@@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
41072
41073 if (debug_level >= DEBUG_LEVEL_INFO)
41074 printk("%s(%d):block_til_ready before block on %s count=%d\n",
41075- __FILE__,__LINE__, tty->driver->name, port->count );
41076+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
41077
41078 spin_lock_irqsave(&info->irq_spinlock, flags);
41079 if (!tty_hung_up_p(filp)) {
41080 extra_count = true;
41081- port->count--;
41082+ atomic_dec(&port->count);
41083 }
41084 spin_unlock_irqrestore(&info->irq_spinlock, flags);
41085 port->blocked_open++;
41086@@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
41087
41088 if (debug_level >= DEBUG_LEVEL_INFO)
41089 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
41090- __FILE__,__LINE__, tty->driver->name, port->count );
41091+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
41092
41093 tty_unlock(tty);
41094 schedule();
41095@@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
41096
41097 /* FIXME: Racy on hangup during close wait */
41098 if (extra_count)
41099- port->count++;
41100+ atomic_inc(&port->count);
41101 port->blocked_open--;
41102
41103 if (debug_level >= DEBUG_LEVEL_INFO)
41104 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
41105- __FILE__,__LINE__, tty->driver->name, port->count );
41106+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
41107
41108 if (!retval)
41109 port->flags |= ASYNC_NORMAL_ACTIVE;
41110@@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
41111
41112 if (debug_level >= DEBUG_LEVEL_INFO)
41113 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
41114- __FILE__,__LINE__,tty->driver->name, info->port.count);
41115+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
41116
41117 /* If port is closing, signal caller to try again */
41118 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
41119@@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
41120 spin_unlock_irqrestore(&info->netlock, flags);
41121 goto cleanup;
41122 }
41123- info->port.count++;
41124+ atomic_inc(&info->port.count);
41125 spin_unlock_irqrestore(&info->netlock, flags);
41126
41127- if (info->port.count == 1) {
41128+ if (atomic_read(&info->port.count) == 1) {
41129 /* 1st open on this device, init hardware */
41130 retval = startup(info);
41131 if (retval < 0)
41132@@ -3451,8 +3451,8 @@ cleanup:
41133 if (retval) {
41134 if (tty->count == 1)
41135 info->port.tty = NULL; /* tty layer will release tty struct */
41136- if(info->port.count)
41137- info->port.count--;
41138+ if (atomic_read(&info->port.count))
41139+ atomic_dec(&info->port.count);
41140 }
41141
41142 return retval;
41143@@ -7662,7 +7662,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
41144 unsigned short new_crctype;
41145
41146 /* return error if TTY interface open */
41147- if (info->port.count)
41148+ if (atomic_read(&info->port.count))
41149 return -EBUSY;
41150
41151 switch (encoding)
41152@@ -7757,7 +7757,7 @@ static int hdlcdev_open(struct net_device *dev)
41153
41154 /* arbitrate between network and tty opens */
41155 spin_lock_irqsave(&info->netlock, flags);
41156- if (info->port.count != 0 || info->netcount != 0) {
41157+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
41158 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
41159 spin_unlock_irqrestore(&info->netlock, flags);
41160 return -EBUSY;
41161@@ -7843,7 +7843,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
41162 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
41163
41164 /* return error if TTY interface open */
41165- if (info->port.count)
41166+ if (atomic_read(&info->port.count))
41167 return -EBUSY;
41168
41169 if (cmd != SIOCWANDEV)
41170diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
41171index aba1e59..877ac33 100644
41172--- a/drivers/tty/synclink_gt.c
41173+++ b/drivers/tty/synclink_gt.c
41174@@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
41175 tty->driver_data = info;
41176 info->port.tty = tty;
41177
41178- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
41179+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
41180
41181 /* If port is closing, signal caller to try again */
41182 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
41183@@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
41184 mutex_unlock(&info->port.mutex);
41185 goto cleanup;
41186 }
41187- info->port.count++;
41188+ atomic_inc(&info->port.count);
41189 spin_unlock_irqrestore(&info->netlock, flags);
41190
41191- if (info->port.count == 1) {
41192+ if (atomic_read(&info->port.count) == 1) {
41193 /* 1st open on this device, init hardware */
41194 retval = startup(info);
41195 if (retval < 0) {
41196@@ -716,8 +716,8 @@ cleanup:
41197 if (retval) {
41198 if (tty->count == 1)
41199 info->port.tty = NULL; /* tty layer will release tty struct */
41200- if(info->port.count)
41201- info->port.count--;
41202+ if(atomic_read(&info->port.count))
41203+ atomic_dec(&info->port.count);
41204 }
41205
41206 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
41207@@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
41208
41209 if (sanity_check(info, tty->name, "close"))
41210 return;
41211- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
41212+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
41213
41214 if (tty_port_close_start(&info->port, tty, filp) == 0)
41215 goto cleanup;
41216@@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
41217 tty_port_close_end(&info->port, tty);
41218 info->port.tty = NULL;
41219 cleanup:
41220- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
41221+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
41222 }
41223
41224 static void hangup(struct tty_struct *tty)
41225@@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
41226 shutdown(info);
41227
41228 spin_lock_irqsave(&info->port.lock, flags);
41229- info->port.count = 0;
41230+ atomic_set(&info->port.count, 0);
41231 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
41232 info->port.tty = NULL;
41233 spin_unlock_irqrestore(&info->port.lock, flags);
41234@@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
41235 unsigned short new_crctype;
41236
41237 /* return error if TTY interface open */
41238- if (info->port.count)
41239+ if (atomic_read(&info->port.count))
41240 return -EBUSY;
41241
41242 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
41243@@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
41244
41245 /* arbitrate between network and tty opens */
41246 spin_lock_irqsave(&info->netlock, flags);
41247- if (info->port.count != 0 || info->netcount != 0) {
41248+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
41249 DBGINFO(("%s hdlc_open busy\n", dev->name));
41250 spin_unlock_irqrestore(&info->netlock, flags);
41251 return -EBUSY;
41252@@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
41253 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
41254
41255 /* return error if TTY interface open */
41256- if (info->port.count)
41257+ if (atomic_read(&info->port.count))
41258 return -EBUSY;
41259
41260 if (cmd != SIOCWANDEV)
41261@@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
41262 if (port == NULL)
41263 continue;
41264 spin_lock(&port->lock);
41265- if ((port->port.count || port->netcount) &&
41266+ if ((atomic_read(&port->port.count) || port->netcount) &&
41267 port->pending_bh && !port->bh_running &&
41268 !port->bh_requested) {
41269 DBGISR(("%s bh queued\n", port->device_name));
41270@@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
41271 spin_lock_irqsave(&info->lock, flags);
41272 if (!tty_hung_up_p(filp)) {
41273 extra_count = true;
41274- port->count--;
41275+ atomic_dec(&port->count);
41276 }
41277 spin_unlock_irqrestore(&info->lock, flags);
41278 port->blocked_open++;
41279@@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
41280 remove_wait_queue(&port->open_wait, &wait);
41281
41282 if (extra_count)
41283- port->count++;
41284+ atomic_inc(&port->count);
41285 port->blocked_open--;
41286
41287 if (!retval)
41288diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
41289index fd43fb6..34704ad 100644
41290--- a/drivers/tty/synclinkmp.c
41291+++ b/drivers/tty/synclinkmp.c
41292@@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
41293
41294 if (debug_level >= DEBUG_LEVEL_INFO)
41295 printk("%s(%d):%s open(), old ref count = %d\n",
41296- __FILE__,__LINE__,tty->driver->name, info->port.count);
41297+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
41298
41299 /* If port is closing, signal caller to try again */
41300 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
41301@@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
41302 spin_unlock_irqrestore(&info->netlock, flags);
41303 goto cleanup;
41304 }
41305- info->port.count++;
41306+ atomic_inc(&info->port.count);
41307 spin_unlock_irqrestore(&info->netlock, flags);
41308
41309- if (info->port.count == 1) {
41310+ if (atomic_read(&info->port.count) == 1) {
41311 /* 1st open on this device, init hardware */
41312 retval = startup(info);
41313 if (retval < 0)
41314@@ -797,8 +797,8 @@ cleanup:
41315 if (retval) {
41316 if (tty->count == 1)
41317 info->port.tty = NULL; /* tty layer will release tty struct */
41318- if(info->port.count)
41319- info->port.count--;
41320+ if(atomic_read(&info->port.count))
41321+ atomic_dec(&info->port.count);
41322 }
41323
41324 return retval;
41325@@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
41326
41327 if (debug_level >= DEBUG_LEVEL_INFO)
41328 printk("%s(%d):%s close() entry, count=%d\n",
41329- __FILE__,__LINE__, info->device_name, info->port.count);
41330+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
41331
41332 if (tty_port_close_start(&info->port, tty, filp) == 0)
41333 goto cleanup;
41334@@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
41335 cleanup:
41336 if (debug_level >= DEBUG_LEVEL_INFO)
41337 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
41338- tty->driver->name, info->port.count);
41339+ tty->driver->name, atomic_read(&info->port.count));
41340 }
41341
41342 /* Called by tty_hangup() when a hangup is signaled.
41343@@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
41344 shutdown(info);
41345
41346 spin_lock_irqsave(&info->port.lock, flags);
41347- info->port.count = 0;
41348+ atomic_set(&info->port.count, 0);
41349 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
41350 info->port.tty = NULL;
41351 spin_unlock_irqrestore(&info->port.lock, flags);
41352@@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
41353 unsigned short new_crctype;
41354
41355 /* return error if TTY interface open */
41356- if (info->port.count)
41357+ if (atomic_read(&info->port.count))
41358 return -EBUSY;
41359
41360 switch (encoding)
41361@@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
41362
41363 /* arbitrate between network and tty opens */
41364 spin_lock_irqsave(&info->netlock, flags);
41365- if (info->port.count != 0 || info->netcount != 0) {
41366+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
41367 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
41368 spin_unlock_irqrestore(&info->netlock, flags);
41369 return -EBUSY;
41370@@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
41371 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
41372
41373 /* return error if TTY interface open */
41374- if (info->port.count)
41375+ if (atomic_read(&info->port.count))
41376 return -EBUSY;
41377
41378 if (cmd != SIOCWANDEV)
41379@@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
41380 * do not request bottom half processing if the
41381 * device is not open in a normal mode.
41382 */
41383- if ( port && (port->port.count || port->netcount) &&
41384+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
41385 port->pending_bh && !port->bh_running &&
41386 !port->bh_requested ) {
41387 if ( debug_level >= DEBUG_LEVEL_ISR )
41388@@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
41389
41390 if (debug_level >= DEBUG_LEVEL_INFO)
41391 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
41392- __FILE__,__LINE__, tty->driver->name, port->count );
41393+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
41394
41395 spin_lock_irqsave(&info->lock, flags);
41396 if (!tty_hung_up_p(filp)) {
41397 extra_count = true;
41398- port->count--;
41399+ atomic_dec(&port->count);
41400 }
41401 spin_unlock_irqrestore(&info->lock, flags);
41402 port->blocked_open++;
41403@@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
41404
41405 if (debug_level >= DEBUG_LEVEL_INFO)
41406 printk("%s(%d):%s block_til_ready() count=%d\n",
41407- __FILE__,__LINE__, tty->driver->name, port->count );
41408+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
41409
41410 tty_unlock(tty);
41411 schedule();
41412@@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
41413 remove_wait_queue(&port->open_wait, &wait);
41414
41415 if (extra_count)
41416- port->count++;
41417+ atomic_inc(&port->count);
41418 port->blocked_open--;
41419
41420 if (debug_level >= DEBUG_LEVEL_INFO)
41421 printk("%s(%d):%s block_til_ready() after, count=%d\n",
41422- __FILE__,__LINE__, tty->driver->name, port->count );
41423+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
41424
41425 if (!retval)
41426 port->flags |= ASYNC_NORMAL_ACTIVE;
41427diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
41428index b3c4a25..723916f 100644
41429--- a/drivers/tty/sysrq.c
41430+++ b/drivers/tty/sysrq.c
41431@@ -867,7 +867,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
41432 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
41433 size_t count, loff_t *ppos)
41434 {
41435- if (count) {
41436+ if (count && capable(CAP_SYS_ADMIN)) {
41437 char c;
41438
41439 if (get_user(c, buf))
41440diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
41441index da9fde8..c07975f 100644
41442--- a/drivers/tty/tty_io.c
41443+++ b/drivers/tty/tty_io.c
41444@@ -3391,7 +3391,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
41445
41446 void tty_default_fops(struct file_operations *fops)
41447 {
41448- *fops = tty_fops;
41449+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
41450 }
41451
41452 /*
41453diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
41454index c578229..45aa9ee 100644
41455--- a/drivers/tty/tty_ldisc.c
41456+++ b/drivers/tty/tty_ldisc.c
41457@@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
41458 if (atomic_dec_and_test(&ld->users)) {
41459 struct tty_ldisc_ops *ldo = ld->ops;
41460
41461- ldo->refcount--;
41462+ atomic_dec(&ldo->refcount);
41463 module_put(ldo->owner);
41464 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
41465
41466@@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
41467 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
41468 tty_ldiscs[disc] = new_ldisc;
41469 new_ldisc->num = disc;
41470- new_ldisc->refcount = 0;
41471+ atomic_set(&new_ldisc->refcount, 0);
41472 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
41473
41474 return ret;
41475@@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
41476 return -EINVAL;
41477
41478 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
41479- if (tty_ldiscs[disc]->refcount)
41480+ if (atomic_read(&tty_ldiscs[disc]->refcount))
41481 ret = -EBUSY;
41482 else
41483 tty_ldiscs[disc] = NULL;
41484@@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
41485 if (ldops) {
41486 ret = ERR_PTR(-EAGAIN);
41487 if (try_module_get(ldops->owner)) {
41488- ldops->refcount++;
41489+ atomic_inc(&ldops->refcount);
41490 ret = ldops;
41491 }
41492 }
41493@@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
41494 unsigned long flags;
41495
41496 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
41497- ldops->refcount--;
41498+ atomic_dec(&ldops->refcount);
41499 module_put(ldops->owner);
41500 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
41501 }
41502diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
41503index b7ff59d..7c6105e 100644
41504--- a/drivers/tty/tty_port.c
41505+++ b/drivers/tty/tty_port.c
41506@@ -218,7 +218,7 @@ void tty_port_hangup(struct tty_port *port)
41507 unsigned long flags;
41508
41509 spin_lock_irqsave(&port->lock, flags);
41510- port->count = 0;
41511+ atomic_set(&port->count, 0);
41512 port->flags &= ~ASYNC_NORMAL_ACTIVE;
41513 if (port->tty) {
41514 set_bit(TTY_IO_ERROR, &port->tty->flags);
41515@@ -344,7 +344,7 @@ int tty_port_block_til_ready(struct tty_port *port,
41516 /* The port lock protects the port counts */
41517 spin_lock_irqsave(&port->lock, flags);
41518 if (!tty_hung_up_p(filp))
41519- port->count--;
41520+ atomic_dec(&port->count);
41521 port->blocked_open++;
41522 spin_unlock_irqrestore(&port->lock, flags);
41523
41524@@ -386,7 +386,7 @@ int tty_port_block_til_ready(struct tty_port *port,
41525 we must not mess that up further */
41526 spin_lock_irqsave(&port->lock, flags);
41527 if (!tty_hung_up_p(filp))
41528- port->count++;
41529+ atomic_inc(&port->count);
41530 port->blocked_open--;
41531 if (retval == 0)
41532 port->flags |= ASYNC_NORMAL_ACTIVE;
41533@@ -406,19 +406,19 @@ int tty_port_close_start(struct tty_port *port,
41534 return 0;
41535 }
41536
41537- if (tty->count == 1 && port->count != 1) {
41538+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
41539 printk(KERN_WARNING
41540 "tty_port_close_start: tty->count = 1 port count = %d.\n",
41541- port->count);
41542- port->count = 1;
41543+ atomic_read(&port->count));
41544+ atomic_set(&port->count, 1);
41545 }
41546- if (--port->count < 0) {
41547+ if (atomic_dec_return(&port->count) < 0) {
41548 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
41549- port->count);
41550- port->count = 0;
41551+ atomic_read(&port->count));
41552+ atomic_set(&port->count, 0);
41553 }
41554
41555- if (port->count) {
41556+ if (atomic_read(&port->count)) {
41557 spin_unlock_irqrestore(&port->lock, flags);
41558 if (port->ops->drop)
41559 port->ops->drop(port);
41560@@ -516,7 +516,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
41561 {
41562 spin_lock_irq(&port->lock);
41563 if (!tty_hung_up_p(filp))
41564- ++port->count;
41565+ atomic_inc(&port->count);
41566 spin_unlock_irq(&port->lock);
41567 tty_port_tty_set(port, tty);
41568
41569diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
41570index 681765b..d3ccdf2 100644
41571--- a/drivers/tty/vt/keyboard.c
41572+++ b/drivers/tty/vt/keyboard.c
41573@@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
41574 kbd->kbdmode == VC_OFF) &&
41575 value != KVAL(K_SAK))
41576 return; /* SAK is allowed even in raw mode */
41577+
41578+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
41579+ {
41580+ void *func = fn_handler[value];
41581+ if (func == fn_show_state || func == fn_show_ptregs ||
41582+ func == fn_show_mem)
41583+ return;
41584+ }
41585+#endif
41586+
41587 fn_handler[value](vc);
41588 }
41589
41590@@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
41591 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
41592 return -EFAULT;
41593
41594- if (!capable(CAP_SYS_TTY_CONFIG))
41595- perm = 0;
41596-
41597 switch (cmd) {
41598 case KDGKBENT:
41599 /* Ensure another thread doesn't free it under us */
41600@@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
41601 spin_unlock_irqrestore(&kbd_event_lock, flags);
41602 return put_user(val, &user_kbe->kb_value);
41603 case KDSKBENT:
41604+ if (!capable(CAP_SYS_TTY_CONFIG))
41605+ perm = 0;
41606+
41607 if (!perm)
41608 return -EPERM;
41609 if (!i && v == K_NOSUCHMAP) {
41610@@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
41611 int i, j, k;
41612 int ret;
41613
41614- if (!capable(CAP_SYS_TTY_CONFIG))
41615- perm = 0;
41616-
41617 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
41618 if (!kbs) {
41619 ret = -ENOMEM;
41620@@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
41621 kfree(kbs);
41622 return ((p && *p) ? -EOVERFLOW : 0);
41623 case KDSKBSENT:
41624+ if (!capable(CAP_SYS_TTY_CONFIG))
41625+ perm = 0;
41626+
41627 if (!perm) {
41628 ret = -EPERM;
41629 goto reterr;
41630diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
41631index 5110f36..8dc0a74 100644
41632--- a/drivers/uio/uio.c
41633+++ b/drivers/uio/uio.c
41634@@ -25,6 +25,7 @@
41635 #include <linux/kobject.h>
41636 #include <linux/cdev.h>
41637 #include <linux/uio_driver.h>
41638+#include <asm/local.h>
41639
41640 #define UIO_MAX_DEVICES (1U << MINORBITS)
41641
41642@@ -32,10 +33,10 @@ struct uio_device {
41643 struct module *owner;
41644 struct device *dev;
41645 int minor;
41646- atomic_t event;
41647+ atomic_unchecked_t event;
41648 struct fasync_struct *async_queue;
41649 wait_queue_head_t wait;
41650- int vma_count;
41651+ local_t vma_count;
41652 struct uio_info *info;
41653 struct kobject *map_dir;
41654 struct kobject *portio_dir;
41655@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
41656 struct device_attribute *attr, char *buf)
41657 {
41658 struct uio_device *idev = dev_get_drvdata(dev);
41659- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
41660+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
41661 }
41662
41663 static struct device_attribute uio_class_attributes[] = {
41664@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
41665 {
41666 struct uio_device *idev = info->uio_dev;
41667
41668- atomic_inc(&idev->event);
41669+ atomic_inc_unchecked(&idev->event);
41670 wake_up_interruptible(&idev->wait);
41671 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
41672 }
41673@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
41674 }
41675
41676 listener->dev = idev;
41677- listener->event_count = atomic_read(&idev->event);
41678+ listener->event_count = atomic_read_unchecked(&idev->event);
41679 filep->private_data = listener;
41680
41681 if (idev->info->open) {
41682@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
41683 return -EIO;
41684
41685 poll_wait(filep, &idev->wait, wait);
41686- if (listener->event_count != atomic_read(&idev->event))
41687+ if (listener->event_count != atomic_read_unchecked(&idev->event))
41688 return POLLIN | POLLRDNORM;
41689 return 0;
41690 }
41691@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
41692 do {
41693 set_current_state(TASK_INTERRUPTIBLE);
41694
41695- event_count = atomic_read(&idev->event);
41696+ event_count = atomic_read_unchecked(&idev->event);
41697 if (event_count != listener->event_count) {
41698 if (copy_to_user(buf, &event_count, count))
41699 retval = -EFAULT;
41700@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
41701 static void uio_vma_open(struct vm_area_struct *vma)
41702 {
41703 struct uio_device *idev = vma->vm_private_data;
41704- idev->vma_count++;
41705+ local_inc(&idev->vma_count);
41706 }
41707
41708 static void uio_vma_close(struct vm_area_struct *vma)
41709 {
41710 struct uio_device *idev = vma->vm_private_data;
41711- idev->vma_count--;
41712+ local_dec(&idev->vma_count);
41713 }
41714
41715 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41716@@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
41717 idev->owner = owner;
41718 idev->info = info;
41719 init_waitqueue_head(&idev->wait);
41720- atomic_set(&idev->event, 0);
41721+ atomic_set_unchecked(&idev->event, 0);
41722
41723 ret = uio_get_minor(idev);
41724 if (ret)
41725diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
41726index b7eb86a..36d28af 100644
41727--- a/drivers/usb/atm/cxacru.c
41728+++ b/drivers/usb/atm/cxacru.c
41729@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
41730 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
41731 if (ret < 2)
41732 return -EINVAL;
41733- if (index < 0 || index > 0x7f)
41734+ if (index > 0x7f)
41735 return -EINVAL;
41736 pos += tmp;
41737
41738diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
41739index 35f10bf..6a38a0b 100644
41740--- a/drivers/usb/atm/usbatm.c
41741+++ b/drivers/usb/atm/usbatm.c
41742@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41743 if (printk_ratelimit())
41744 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
41745 __func__, vpi, vci);
41746- atomic_inc(&vcc->stats->rx_err);
41747+ atomic_inc_unchecked(&vcc->stats->rx_err);
41748 return;
41749 }
41750
41751@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41752 if (length > ATM_MAX_AAL5_PDU) {
41753 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
41754 __func__, length, vcc);
41755- atomic_inc(&vcc->stats->rx_err);
41756+ atomic_inc_unchecked(&vcc->stats->rx_err);
41757 goto out;
41758 }
41759
41760@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41761 if (sarb->len < pdu_length) {
41762 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
41763 __func__, pdu_length, sarb->len, vcc);
41764- atomic_inc(&vcc->stats->rx_err);
41765+ atomic_inc_unchecked(&vcc->stats->rx_err);
41766 goto out;
41767 }
41768
41769 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
41770 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
41771 __func__, vcc);
41772- atomic_inc(&vcc->stats->rx_err);
41773+ atomic_inc_unchecked(&vcc->stats->rx_err);
41774 goto out;
41775 }
41776
41777@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41778 if (printk_ratelimit())
41779 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
41780 __func__, length);
41781- atomic_inc(&vcc->stats->rx_drop);
41782+ atomic_inc_unchecked(&vcc->stats->rx_drop);
41783 goto out;
41784 }
41785
41786@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41787
41788 vcc->push(vcc, skb);
41789
41790- atomic_inc(&vcc->stats->rx);
41791+ atomic_inc_unchecked(&vcc->stats->rx);
41792 out:
41793 skb_trim(sarb, 0);
41794 }
41795@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
41796 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
41797
41798 usbatm_pop(vcc, skb);
41799- atomic_inc(&vcc->stats->tx);
41800+ atomic_inc_unchecked(&vcc->stats->tx);
41801
41802 skb = skb_dequeue(&instance->sndqueue);
41803 }
41804@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
41805 if (!left--)
41806 return sprintf(page,
41807 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
41808- atomic_read(&atm_dev->stats.aal5.tx),
41809- atomic_read(&atm_dev->stats.aal5.tx_err),
41810- atomic_read(&atm_dev->stats.aal5.rx),
41811- atomic_read(&atm_dev->stats.aal5.rx_err),
41812- atomic_read(&atm_dev->stats.aal5.rx_drop));
41813+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
41814+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
41815+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
41816+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
41817+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
41818
41819 if (!left--) {
41820 if (instance->disconnected)
41821diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
41822index cbacea9..246cccd 100644
41823--- a/drivers/usb/core/devices.c
41824+++ b/drivers/usb/core/devices.c
41825@@ -126,7 +126,7 @@ static const char format_endpt[] =
41826 * time it gets called.
41827 */
41828 static struct device_connect_event {
41829- atomic_t count;
41830+ atomic_unchecked_t count;
41831 wait_queue_head_t wait;
41832 } device_event = {
41833 .count = ATOMIC_INIT(1),
41834@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
41835
41836 void usbfs_conn_disc_event(void)
41837 {
41838- atomic_add(2, &device_event.count);
41839+ atomic_add_unchecked(2, &device_event.count);
41840 wake_up(&device_event.wait);
41841 }
41842
41843@@ -645,7 +645,7 @@ static unsigned int usb_device_poll(struct file *file,
41844
41845 poll_wait(file, &device_event.wait, wait);
41846
41847- event_count = atomic_read(&device_event.count);
41848+ event_count = atomic_read_unchecked(&device_event.count);
41849 if (file->f_version != event_count) {
41850 file->f_version = event_count;
41851 return POLLIN | POLLRDNORM;
41852diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
41853index 8e64adf..9a33a3c 100644
41854--- a/drivers/usb/core/hcd.c
41855+++ b/drivers/usb/core/hcd.c
41856@@ -1522,7 +1522,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
41857 */
41858 usb_get_urb(urb);
41859 atomic_inc(&urb->use_count);
41860- atomic_inc(&urb->dev->urbnum);
41861+ atomic_inc_unchecked(&urb->dev->urbnum);
41862 usbmon_urb_submit(&hcd->self, urb);
41863
41864 /* NOTE requirements on root-hub callers (usbfs and the hub
41865@@ -1549,7 +1549,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
41866 urb->hcpriv = NULL;
41867 INIT_LIST_HEAD(&urb->urb_list);
41868 atomic_dec(&urb->use_count);
41869- atomic_dec(&urb->dev->urbnum);
41870+ atomic_dec_unchecked(&urb->dev->urbnum);
41871 if (atomic_read(&urb->reject))
41872 wake_up(&usb_kill_urb_queue);
41873 usb_put_urb(urb);
41874diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
41875index 818e4a0..0fc9589 100644
41876--- a/drivers/usb/core/sysfs.c
41877+++ b/drivers/usb/core/sysfs.c
41878@@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
41879 struct usb_device *udev;
41880
41881 udev = to_usb_device(dev);
41882- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
41883+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
41884 }
41885 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
41886
41887diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
41888index f81b925..78d22ec 100644
41889--- a/drivers/usb/core/usb.c
41890+++ b/drivers/usb/core/usb.c
41891@@ -388,7 +388,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
41892 set_dev_node(&dev->dev, dev_to_node(bus->controller));
41893 dev->state = USB_STATE_ATTACHED;
41894 dev->lpm_disable_count = 1;
41895- atomic_set(&dev->urbnum, 0);
41896+ atomic_set_unchecked(&dev->urbnum, 0);
41897
41898 INIT_LIST_HEAD(&dev->ep0.urb_list);
41899 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
41900diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
41901index 5e29dde..eca992f 100644
41902--- a/drivers/usb/early/ehci-dbgp.c
41903+++ b/drivers/usb/early/ehci-dbgp.c
41904@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
41905
41906 #ifdef CONFIG_KGDB
41907 static struct kgdb_io kgdbdbgp_io_ops;
41908-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
41909+static struct kgdb_io kgdbdbgp_io_ops_console;
41910+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
41911 #else
41912 #define dbgp_kgdb_mode (0)
41913 #endif
41914@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
41915 .write_char = kgdbdbgp_write_char,
41916 };
41917
41918+static struct kgdb_io kgdbdbgp_io_ops_console = {
41919+ .name = "kgdbdbgp",
41920+ .read_char = kgdbdbgp_read_char,
41921+ .write_char = kgdbdbgp_write_char,
41922+ .is_console = 1
41923+};
41924+
41925 static int kgdbdbgp_wait_time;
41926
41927 static int __init kgdbdbgp_parse_config(char *str)
41928@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
41929 ptr++;
41930 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
41931 }
41932- kgdb_register_io_module(&kgdbdbgp_io_ops);
41933- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
41934+ if (early_dbgp_console.index != -1)
41935+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
41936+ else
41937+ kgdb_register_io_module(&kgdbdbgp_io_ops);
41938
41939 return 0;
41940 }
41941diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
41942index 598dcc1..032dd4f 100644
41943--- a/drivers/usb/gadget/u_serial.c
41944+++ b/drivers/usb/gadget/u_serial.c
41945@@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
41946 spin_lock_irq(&port->port_lock);
41947
41948 /* already open? Great. */
41949- if (port->port.count) {
41950+ if (atomic_read(&port->port.count)) {
41951 status = 0;
41952- port->port.count++;
41953+ atomic_inc(&port->port.count);
41954
41955 /* currently opening/closing? wait ... */
41956 } else if (port->openclose) {
41957@@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
41958 tty->driver_data = port;
41959 port->port.tty = tty;
41960
41961- port->port.count = 1;
41962+ atomic_set(&port->port.count, 1);
41963 port->openclose = false;
41964
41965 /* if connected, start the I/O stream */
41966@@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
41967
41968 spin_lock_irq(&port->port_lock);
41969
41970- if (port->port.count != 1) {
41971- if (port->port.count == 0)
41972+ if (atomic_read(&port->port.count) != 1) {
41973+ if (atomic_read(&port->port.count) == 0)
41974 WARN_ON(1);
41975 else
41976- --port->port.count;
41977+ atomic_dec(&port->port.count);
41978 goto exit;
41979 }
41980
41981@@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
41982 * and sleep if necessary
41983 */
41984 port->openclose = true;
41985- port->port.count = 0;
41986+ atomic_set(&port->port.count, 0);
41987
41988 gser = port->port_usb;
41989 if (gser && gser->disconnect)
41990@@ -1159,7 +1159,7 @@ static int gs_closed(struct gs_port *port)
41991 int cond;
41992
41993 spin_lock_irq(&port->port_lock);
41994- cond = (port->port.count == 0) && !port->openclose;
41995+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
41996 spin_unlock_irq(&port->port_lock);
41997 return cond;
41998 }
41999@@ -1273,7 +1273,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
42000 /* if it's already open, start I/O ... and notify the serial
42001 * protocol about open/close status (connect/disconnect).
42002 */
42003- if (port->port.count) {
42004+ if (atomic_read(&port->port.count)) {
42005 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
42006 gs_start_io(port);
42007 if (gser->connect)
42008@@ -1320,7 +1320,7 @@ void gserial_disconnect(struct gserial *gser)
42009
42010 port->port_usb = NULL;
42011 gser->ioport = NULL;
42012- if (port->port.count > 0 || port->openclose) {
42013+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
42014 wake_up_interruptible(&port->drain_wait);
42015 if (port->port.tty)
42016 tty_hangup(port->port.tty);
42017@@ -1336,7 +1336,7 @@ void gserial_disconnect(struct gserial *gser)
42018
42019 /* finally, free any unused/unusable I/O buffers */
42020 spin_lock_irqsave(&port->port_lock, flags);
42021- if (port->port.count == 0 && !port->openclose)
42022+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
42023 gs_buf_free(&port->port_write_buf);
42024 gs_free_requests(gser->out, &port->read_pool, NULL);
42025 gs_free_requests(gser->out, &port->read_queue, NULL);
42026diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
42027index 5f3bcd3..bfca43f 100644
42028--- a/drivers/usb/serial/console.c
42029+++ b/drivers/usb/serial/console.c
42030@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
42031
42032 info->port = port;
42033
42034- ++port->port.count;
42035+ atomic_inc(&port->port.count);
42036 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
42037 if (serial->type->set_termios) {
42038 /*
42039@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
42040 }
42041 /* Now that any required fake tty operations are completed restore
42042 * the tty port count */
42043- --port->port.count;
42044+ atomic_dec(&port->port.count);
42045 /* The console is special in terms of closing the device so
42046 * indicate this port is now acting as a system console. */
42047 port->port.console = 1;
42048@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
42049 free_tty:
42050 kfree(tty);
42051 reset_open_count:
42052- port->port.count = 0;
42053+ atomic_set(&port->port.count, 0);
42054 usb_autopm_put_interface(serial->interface);
42055 error_get_interface:
42056 usb_serial_put(serial);
42057diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
42058index d6bea3e..60b250e 100644
42059--- a/drivers/usb/wusbcore/wa-hc.h
42060+++ b/drivers/usb/wusbcore/wa-hc.h
42061@@ -192,7 +192,7 @@ struct wahc {
42062 struct list_head xfer_delayed_list;
42063 spinlock_t xfer_list_lock;
42064 struct work_struct xfer_work;
42065- atomic_t xfer_id_count;
42066+ atomic_unchecked_t xfer_id_count;
42067 };
42068
42069
42070@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
42071 INIT_LIST_HEAD(&wa->xfer_delayed_list);
42072 spin_lock_init(&wa->xfer_list_lock);
42073 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
42074- atomic_set(&wa->xfer_id_count, 1);
42075+ atomic_set_unchecked(&wa->xfer_id_count, 1);
42076 }
42077
42078 /**
42079diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
42080index 57c01ab..8a05959 100644
42081--- a/drivers/usb/wusbcore/wa-xfer.c
42082+++ b/drivers/usb/wusbcore/wa-xfer.c
42083@@ -296,7 +296,7 @@ out:
42084 */
42085 static void wa_xfer_id_init(struct wa_xfer *xfer)
42086 {
42087- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
42088+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
42089 }
42090
42091 /*
42092diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
42093index 8c55011..eed4ae1a 100644
42094--- a/drivers/video/aty/aty128fb.c
42095+++ b/drivers/video/aty/aty128fb.c
42096@@ -149,7 +149,7 @@ enum {
42097 };
42098
42099 /* Must match above enum */
42100-static char * const r128_family[] = {
42101+static const char * const r128_family[] = {
42102 "AGP",
42103 "PCI",
42104 "PRO AGP",
42105diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
42106index 5c3960d..15cf8fc 100644
42107--- a/drivers/video/fbcmap.c
42108+++ b/drivers/video/fbcmap.c
42109@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
42110 rc = -ENODEV;
42111 goto out;
42112 }
42113- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
42114- !info->fbops->fb_setcmap)) {
42115+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
42116 rc = -EINVAL;
42117 goto out1;
42118 }
42119diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
42120index dc61c12..e29796e 100644
42121--- a/drivers/video/fbmem.c
42122+++ b/drivers/video/fbmem.c
42123@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
42124 image->dx += image->width + 8;
42125 }
42126 } else if (rotate == FB_ROTATE_UD) {
42127- for (x = 0; x < num && image->dx >= 0; x++) {
42128+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
42129 info->fbops->fb_imageblit(info, image);
42130 image->dx -= image->width + 8;
42131 }
42132@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
42133 image->dy += image->height + 8;
42134 }
42135 } else if (rotate == FB_ROTATE_CCW) {
42136- for (x = 0; x < num && image->dy >= 0; x++) {
42137+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
42138 info->fbops->fb_imageblit(info, image);
42139 image->dy -= image->height + 8;
42140 }
42141@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
42142 return -EFAULT;
42143 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
42144 return -EINVAL;
42145- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
42146+ if (con2fb.framebuffer >= FB_MAX)
42147 return -EINVAL;
42148 if (!registered_fb[con2fb.framebuffer])
42149 request_module("fb%d", con2fb.framebuffer);
42150diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
42151index 7672d2e..b56437f 100644
42152--- a/drivers/video/i810/i810_accel.c
42153+++ b/drivers/video/i810/i810_accel.c
42154@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
42155 }
42156 }
42157 printk("ringbuffer lockup!!!\n");
42158+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
42159 i810_report_error(mmio);
42160 par->dev_flags |= LOCKUP;
42161 info->pixmap.scan_align = 1;
42162diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
42163index 3c14e43..eafa544 100644
42164--- a/drivers/video/logo/logo_linux_clut224.ppm
42165+++ b/drivers/video/logo/logo_linux_clut224.ppm
42166@@ -1,1604 +1,1123 @@
42167 P3
42168-# Standard 224-color Linux logo
42169 80 80
42170 255
42171- 0 0 0 0 0 0 0 0 0 0 0 0
42172- 0 0 0 0 0 0 0 0 0 0 0 0
42173- 0 0 0 0 0 0 0 0 0 0 0 0
42174- 0 0 0 0 0 0 0 0 0 0 0 0
42175- 0 0 0 0 0 0 0 0 0 0 0 0
42176- 0 0 0 0 0 0 0 0 0 0 0 0
42177- 0 0 0 0 0 0 0 0 0 0 0 0
42178- 0 0 0 0 0 0 0 0 0 0 0 0
42179- 0 0 0 0 0 0 0 0 0 0 0 0
42180- 6 6 6 6 6 6 10 10 10 10 10 10
42181- 10 10 10 6 6 6 6 6 6 6 6 6
42182- 0 0 0 0 0 0 0 0 0 0 0 0
42183- 0 0 0 0 0 0 0 0 0 0 0 0
42184- 0 0 0 0 0 0 0 0 0 0 0 0
42185- 0 0 0 0 0 0 0 0 0 0 0 0
42186- 0 0 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- 0 0 0 0 0 0 0 0 0 0 0 0
42192- 0 0 0 0 0 0 0 0 0 0 0 0
42193- 0 0 0 0 0 0 0 0 0 0 0 0
42194- 0 0 0 0 0 0 0 0 0 0 0 0
42195- 0 0 0 0 0 0 0 0 0 0 0 0
42196- 0 0 0 0 0 0 0 0 0 0 0 0
42197- 0 0 0 0 0 0 0 0 0 0 0 0
42198- 0 0 0 0 0 0 0 0 0 0 0 0
42199- 0 0 0 6 6 6 10 10 10 14 14 14
42200- 22 22 22 26 26 26 30 30 30 34 34 34
42201- 30 30 30 30 30 30 26 26 26 18 18 18
42202- 14 14 14 10 10 10 6 6 6 0 0 0
42203- 0 0 0 0 0 0 0 0 0 0 0 0
42204- 0 0 0 0 0 0 0 0 0 0 0 0
42205- 0 0 0 0 0 0 0 0 0 0 0 0
42206- 0 0 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- 0 0 0 0 0 0 0 0 0 0 0 0
42212- 0 0 0 0 0 1 0 0 1 0 0 0
42213- 0 0 0 0 0 0 0 0 0 0 0 0
42214- 0 0 0 0 0 0 0 0 0 0 0 0
42215- 0 0 0 0 0 0 0 0 0 0 0 0
42216- 0 0 0 0 0 0 0 0 0 0 0 0
42217- 0 0 0 0 0 0 0 0 0 0 0 0
42218- 0 0 0 0 0 0 0 0 0 0 0 0
42219- 6 6 6 14 14 14 26 26 26 42 42 42
42220- 54 54 54 66 66 66 78 78 78 78 78 78
42221- 78 78 78 74 74 74 66 66 66 54 54 54
42222- 42 42 42 26 26 26 18 18 18 10 10 10
42223- 6 6 6 0 0 0 0 0 0 0 0 0
42224- 0 0 0 0 0 0 0 0 0 0 0 0
42225- 0 0 0 0 0 0 0 0 0 0 0 0
42226- 0 0 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- 0 0 0 0 0 0 0 0 0 0 0 0
42232- 0 0 1 0 0 0 0 0 0 0 0 0
42233- 0 0 0 0 0 0 0 0 0 0 0 0
42234- 0 0 0 0 0 0 0 0 0 0 0 0
42235- 0 0 0 0 0 0 0 0 0 0 0 0
42236- 0 0 0 0 0 0 0 0 0 0 0 0
42237- 0 0 0 0 0 0 0 0 0 0 0 0
42238- 0 0 0 0 0 0 0 0 0 10 10 10
42239- 22 22 22 42 42 42 66 66 66 86 86 86
42240- 66 66 66 38 38 38 38 38 38 22 22 22
42241- 26 26 26 34 34 34 54 54 54 66 66 66
42242- 86 86 86 70 70 70 46 46 46 26 26 26
42243- 14 14 14 6 6 6 0 0 0 0 0 0
42244- 0 0 0 0 0 0 0 0 0 0 0 0
42245- 0 0 0 0 0 0 0 0 0 0 0 0
42246- 0 0 0 0 0 0 0 0 0 0 0 0
42247- 0 0 0 0 0 0 0 0 0 0 0 0
42248- 0 0 0 0 0 0 0 0 0 0 0 0
42249- 0 0 0 0 0 0 0 0 0 0 0 0
42250- 0 0 0 0 0 0 0 0 0 0 0 0
42251- 0 0 0 0 0 0 0 0 0 0 0 0
42252- 0 0 1 0 0 1 0 0 1 0 0 0
42253- 0 0 0 0 0 0 0 0 0 0 0 0
42254- 0 0 0 0 0 0 0 0 0 0 0 0
42255- 0 0 0 0 0 0 0 0 0 0 0 0
42256- 0 0 0 0 0 0 0 0 0 0 0 0
42257- 0 0 0 0 0 0 0 0 0 0 0 0
42258- 0 0 0 0 0 0 10 10 10 26 26 26
42259- 50 50 50 82 82 82 58 58 58 6 6 6
42260- 2 2 6 2 2 6 2 2 6 2 2 6
42261- 2 2 6 2 2 6 2 2 6 2 2 6
42262- 6 6 6 54 54 54 86 86 86 66 66 66
42263- 38 38 38 18 18 18 6 6 6 0 0 0
42264- 0 0 0 0 0 0 0 0 0 0 0 0
42265- 0 0 0 0 0 0 0 0 0 0 0 0
42266- 0 0 0 0 0 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 0 0 0
42271- 0 0 0 0 0 0 0 0 0 0 0 0
42272- 0 0 0 0 0 0 0 0 0 0 0 0
42273- 0 0 0 0 0 0 0 0 0 0 0 0
42274- 0 0 0 0 0 0 0 0 0 0 0 0
42275- 0 0 0 0 0 0 0 0 0 0 0 0
42276- 0 0 0 0 0 0 0 0 0 0 0 0
42277- 0 0 0 0 0 0 0 0 0 0 0 0
42278- 0 0 0 6 6 6 22 22 22 50 50 50
42279- 78 78 78 34 34 34 2 2 6 2 2 6
42280- 2 2 6 2 2 6 2 2 6 2 2 6
42281- 2 2 6 2 2 6 2 2 6 2 2 6
42282- 2 2 6 2 2 6 6 6 6 70 70 70
42283- 78 78 78 46 46 46 22 22 22 6 6 6
42284- 0 0 0 0 0 0 0 0 0 0 0 0
42285- 0 0 0 0 0 0 0 0 0 0 0 0
42286- 0 0 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 0 0 0
42291- 0 0 0 0 0 0 0 0 0 0 0 0
42292- 0 0 1 0 0 1 0 0 1 0 0 0
42293- 0 0 0 0 0 0 0 0 0 0 0 0
42294- 0 0 0 0 0 0 0 0 0 0 0 0
42295- 0 0 0 0 0 0 0 0 0 0 0 0
42296- 0 0 0 0 0 0 0 0 0 0 0 0
42297- 0 0 0 0 0 0 0 0 0 0 0 0
42298- 6 6 6 18 18 18 42 42 42 82 82 82
42299- 26 26 26 2 2 6 2 2 6 2 2 6
42300- 2 2 6 2 2 6 2 2 6 2 2 6
42301- 2 2 6 2 2 6 2 2 6 14 14 14
42302- 46 46 46 34 34 34 6 6 6 2 2 6
42303- 42 42 42 78 78 78 42 42 42 18 18 18
42304- 6 6 6 0 0 0 0 0 0 0 0 0
42305- 0 0 0 0 0 0 0 0 0 0 0 0
42306- 0 0 0 0 0 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 0 0 0
42311- 0 0 0 0 0 0 0 0 0 0 0 0
42312- 0 0 1 0 0 0 0 0 1 0 0 0
42313- 0 0 0 0 0 0 0 0 0 0 0 0
42314- 0 0 0 0 0 0 0 0 0 0 0 0
42315- 0 0 0 0 0 0 0 0 0 0 0 0
42316- 0 0 0 0 0 0 0 0 0 0 0 0
42317- 0 0 0 0 0 0 0 0 0 0 0 0
42318- 10 10 10 30 30 30 66 66 66 58 58 58
42319- 2 2 6 2 2 6 2 2 6 2 2 6
42320- 2 2 6 2 2 6 2 2 6 2 2 6
42321- 2 2 6 2 2 6 2 2 6 26 26 26
42322- 86 86 86 101 101 101 46 46 46 10 10 10
42323- 2 2 6 58 58 58 70 70 70 34 34 34
42324- 10 10 10 0 0 0 0 0 0 0 0 0
42325- 0 0 0 0 0 0 0 0 0 0 0 0
42326- 0 0 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 0 0 0
42331- 0 0 0 0 0 0 0 0 0 0 0 0
42332- 0 0 1 0 0 1 0 0 1 0 0 0
42333- 0 0 0 0 0 0 0 0 0 0 0 0
42334- 0 0 0 0 0 0 0 0 0 0 0 0
42335- 0 0 0 0 0 0 0 0 0 0 0 0
42336- 0 0 0 0 0 0 0 0 0 0 0 0
42337- 0 0 0 0 0 0 0 0 0 0 0 0
42338- 14 14 14 42 42 42 86 86 86 10 10 10
42339- 2 2 6 2 2 6 2 2 6 2 2 6
42340- 2 2 6 2 2 6 2 2 6 2 2 6
42341- 2 2 6 2 2 6 2 2 6 30 30 30
42342- 94 94 94 94 94 94 58 58 58 26 26 26
42343- 2 2 6 6 6 6 78 78 78 54 54 54
42344- 22 22 22 6 6 6 0 0 0 0 0 0
42345- 0 0 0 0 0 0 0 0 0 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 0 0 0
42351- 0 0 0 0 0 0 0 0 0 0 0 0
42352- 0 0 0 0 0 0 0 0 0 0 0 0
42353- 0 0 0 0 0 0 0 0 0 0 0 0
42354- 0 0 0 0 0 0 0 0 0 0 0 0
42355- 0 0 0 0 0 0 0 0 0 0 0 0
42356- 0 0 0 0 0 0 0 0 0 0 0 0
42357- 0 0 0 0 0 0 0 0 0 6 6 6
42358- 22 22 22 62 62 62 62 62 62 2 2 6
42359- 2 2 6 2 2 6 2 2 6 2 2 6
42360- 2 2 6 2 2 6 2 2 6 2 2 6
42361- 2 2 6 2 2 6 2 2 6 26 26 26
42362- 54 54 54 38 38 38 18 18 18 10 10 10
42363- 2 2 6 2 2 6 34 34 34 82 82 82
42364- 38 38 38 14 14 14 0 0 0 0 0 0
42365- 0 0 0 0 0 0 0 0 0 0 0 0
42366- 0 0 0 0 0 0 0 0 0 0 0 0
42367- 0 0 0 0 0 0 0 0 0 0 0 0
42368- 0 0 0 0 0 0 0 0 0 0 0 0
42369- 0 0 0 0 0 0 0 0 0 0 0 0
42370- 0 0 0 0 0 0 0 0 0 0 0 0
42371- 0 0 0 0 0 0 0 0 0 0 0 0
42372- 0 0 0 0 0 1 0 0 1 0 0 0
42373- 0 0 0 0 0 0 0 0 0 0 0 0
42374- 0 0 0 0 0 0 0 0 0 0 0 0
42375- 0 0 0 0 0 0 0 0 0 0 0 0
42376- 0 0 0 0 0 0 0 0 0 0 0 0
42377- 0 0 0 0 0 0 0 0 0 6 6 6
42378- 30 30 30 78 78 78 30 30 30 2 2 6
42379- 2 2 6 2 2 6 2 2 6 2 2 6
42380- 2 2 6 2 2 6 2 2 6 2 2 6
42381- 2 2 6 2 2 6 2 2 6 10 10 10
42382- 10 10 10 2 2 6 2 2 6 2 2 6
42383- 2 2 6 2 2 6 2 2 6 78 78 78
42384- 50 50 50 18 18 18 6 6 6 0 0 0
42385- 0 0 0 0 0 0 0 0 0 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 0 0 0
42391- 0 0 0 0 0 0 0 0 0 0 0 0
42392- 0 0 1 0 0 0 0 0 0 0 0 0
42393- 0 0 0 0 0 0 0 0 0 0 0 0
42394- 0 0 0 0 0 0 0 0 0 0 0 0
42395- 0 0 0 0 0 0 0 0 0 0 0 0
42396- 0 0 0 0 0 0 0 0 0 0 0 0
42397- 0 0 0 0 0 0 0 0 0 10 10 10
42398- 38 38 38 86 86 86 14 14 14 2 2 6
42399- 2 2 6 2 2 6 2 2 6 2 2 6
42400- 2 2 6 2 2 6 2 2 6 2 2 6
42401- 2 2 6 2 2 6 2 2 6 2 2 6
42402- 2 2 6 2 2 6 2 2 6 2 2 6
42403- 2 2 6 2 2 6 2 2 6 54 54 54
42404- 66 66 66 26 26 26 6 6 6 0 0 0
42405- 0 0 0 0 0 0 0 0 0 0 0 0
42406- 0 0 0 0 0 0 0 0 0 0 0 0
42407- 0 0 0 0 0 0 0 0 0 0 0 0
42408- 0 0 0 0 0 0 0 0 0 0 0 0
42409- 0 0 0 0 0 0 0 0 0 0 0 0
42410- 0 0 0 0 0 0 0 0 0 0 0 0
42411- 0 0 0 0 0 0 0 0 0 0 0 0
42412- 0 0 0 0 0 1 0 0 1 0 0 0
42413- 0 0 0 0 0 0 0 0 0 0 0 0
42414- 0 0 0 0 0 0 0 0 0 0 0 0
42415- 0 0 0 0 0 0 0 0 0 0 0 0
42416- 0 0 0 0 0 0 0 0 0 0 0 0
42417- 0 0 0 0 0 0 0 0 0 14 14 14
42418- 42 42 42 82 82 82 2 2 6 2 2 6
42419- 2 2 6 6 6 6 10 10 10 2 2 6
42420- 2 2 6 2 2 6 2 2 6 2 2 6
42421- 2 2 6 2 2 6 2 2 6 6 6 6
42422- 14 14 14 10 10 10 2 2 6 2 2 6
42423- 2 2 6 2 2 6 2 2 6 18 18 18
42424- 82 82 82 34 34 34 10 10 10 0 0 0
42425- 0 0 0 0 0 0 0 0 0 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 0 0 0
42431- 0 0 0 0 0 0 0 0 0 0 0 0
42432- 0 0 1 0 0 0 0 0 0 0 0 0
42433- 0 0 0 0 0 0 0 0 0 0 0 0
42434- 0 0 0 0 0 0 0 0 0 0 0 0
42435- 0 0 0 0 0 0 0 0 0 0 0 0
42436- 0 0 0 0 0 0 0 0 0 0 0 0
42437- 0 0 0 0 0 0 0 0 0 14 14 14
42438- 46 46 46 86 86 86 2 2 6 2 2 6
42439- 6 6 6 6 6 6 22 22 22 34 34 34
42440- 6 6 6 2 2 6 2 2 6 2 2 6
42441- 2 2 6 2 2 6 18 18 18 34 34 34
42442- 10 10 10 50 50 50 22 22 22 2 2 6
42443- 2 2 6 2 2 6 2 2 6 10 10 10
42444- 86 86 86 42 42 42 14 14 14 0 0 0
42445- 0 0 0 0 0 0 0 0 0 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 0 0 0
42451- 0 0 0 0 0 0 0 0 0 0 0 0
42452- 0 0 1 0 0 1 0 0 1 0 0 0
42453- 0 0 0 0 0 0 0 0 0 0 0 0
42454- 0 0 0 0 0 0 0 0 0 0 0 0
42455- 0 0 0 0 0 0 0 0 0 0 0 0
42456- 0 0 0 0 0 0 0 0 0 0 0 0
42457- 0 0 0 0 0 0 0 0 0 14 14 14
42458- 46 46 46 86 86 86 2 2 6 2 2 6
42459- 38 38 38 116 116 116 94 94 94 22 22 22
42460- 22 22 22 2 2 6 2 2 6 2 2 6
42461- 14 14 14 86 86 86 138 138 138 162 162 162
42462-154 154 154 38 38 38 26 26 26 6 6 6
42463- 2 2 6 2 2 6 2 2 6 2 2 6
42464- 86 86 86 46 46 46 14 14 14 0 0 0
42465- 0 0 0 0 0 0 0 0 0 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 0 0 0
42471- 0 0 0 0 0 0 0 0 0 0 0 0
42472- 0 0 0 0 0 0 0 0 0 0 0 0
42473- 0 0 0 0 0 0 0 0 0 0 0 0
42474- 0 0 0 0 0 0 0 0 0 0 0 0
42475- 0 0 0 0 0 0 0 0 0 0 0 0
42476- 0 0 0 0 0 0 0 0 0 0 0 0
42477- 0 0 0 0 0 0 0 0 0 14 14 14
42478- 46 46 46 86 86 86 2 2 6 14 14 14
42479-134 134 134 198 198 198 195 195 195 116 116 116
42480- 10 10 10 2 2 6 2 2 6 6 6 6
42481-101 98 89 187 187 187 210 210 210 218 218 218
42482-214 214 214 134 134 134 14 14 14 6 6 6
42483- 2 2 6 2 2 6 2 2 6 2 2 6
42484- 86 86 86 50 50 50 18 18 18 6 6 6
42485- 0 0 0 0 0 0 0 0 0 0 0 0
42486- 0 0 0 0 0 0 0 0 0 0 0 0
42487- 0 0 0 0 0 0 0 0 0 0 0 0
42488- 0 0 0 0 0 0 0 0 0 0 0 0
42489- 0 0 0 0 0 0 0 0 0 0 0 0
42490- 0 0 0 0 0 0 0 0 0 0 0 0
42491- 0 0 0 0 0 0 0 0 1 0 0 0
42492- 0 0 1 0 0 1 0 0 1 0 0 0
42493- 0 0 0 0 0 0 0 0 0 0 0 0
42494- 0 0 0 0 0 0 0 0 0 0 0 0
42495- 0 0 0 0 0 0 0 0 0 0 0 0
42496- 0 0 0 0 0 0 0 0 0 0 0 0
42497- 0 0 0 0 0 0 0 0 0 14 14 14
42498- 46 46 46 86 86 86 2 2 6 54 54 54
42499-218 218 218 195 195 195 226 226 226 246 246 246
42500- 58 58 58 2 2 6 2 2 6 30 30 30
42501-210 210 210 253 253 253 174 174 174 123 123 123
42502-221 221 221 234 234 234 74 74 74 2 2 6
42503- 2 2 6 2 2 6 2 2 6 2 2 6
42504- 70 70 70 58 58 58 22 22 22 6 6 6
42505- 0 0 0 0 0 0 0 0 0 0 0 0
42506- 0 0 0 0 0 0 0 0 0 0 0 0
42507- 0 0 0 0 0 0 0 0 0 0 0 0
42508- 0 0 0 0 0 0 0 0 0 0 0 0
42509- 0 0 0 0 0 0 0 0 0 0 0 0
42510- 0 0 0 0 0 0 0 0 0 0 0 0
42511- 0 0 0 0 0 0 0 0 0 0 0 0
42512- 0 0 0 0 0 0 0 0 0 0 0 0
42513- 0 0 0 0 0 0 0 0 0 0 0 0
42514- 0 0 0 0 0 0 0 0 0 0 0 0
42515- 0 0 0 0 0 0 0 0 0 0 0 0
42516- 0 0 0 0 0 0 0 0 0 0 0 0
42517- 0 0 0 0 0 0 0 0 0 14 14 14
42518- 46 46 46 82 82 82 2 2 6 106 106 106
42519-170 170 170 26 26 26 86 86 86 226 226 226
42520-123 123 123 10 10 10 14 14 14 46 46 46
42521-231 231 231 190 190 190 6 6 6 70 70 70
42522- 90 90 90 238 238 238 158 158 158 2 2 6
42523- 2 2 6 2 2 6 2 2 6 2 2 6
42524- 70 70 70 58 58 58 22 22 22 6 6 6
42525- 0 0 0 0 0 0 0 0 0 0 0 0
42526- 0 0 0 0 0 0 0 0 0 0 0 0
42527- 0 0 0 0 0 0 0 0 0 0 0 0
42528- 0 0 0 0 0 0 0 0 0 0 0 0
42529- 0 0 0 0 0 0 0 0 0 0 0 0
42530- 0 0 0 0 0 0 0 0 0 0 0 0
42531- 0 0 0 0 0 0 0 0 1 0 0 0
42532- 0 0 1 0 0 1 0 0 1 0 0 0
42533- 0 0 0 0 0 0 0 0 0 0 0 0
42534- 0 0 0 0 0 0 0 0 0 0 0 0
42535- 0 0 0 0 0 0 0 0 0 0 0 0
42536- 0 0 0 0 0 0 0 0 0 0 0 0
42537- 0 0 0 0 0 0 0 0 0 14 14 14
42538- 42 42 42 86 86 86 6 6 6 116 116 116
42539-106 106 106 6 6 6 70 70 70 149 149 149
42540-128 128 128 18 18 18 38 38 38 54 54 54
42541-221 221 221 106 106 106 2 2 6 14 14 14
42542- 46 46 46 190 190 190 198 198 198 2 2 6
42543- 2 2 6 2 2 6 2 2 6 2 2 6
42544- 74 74 74 62 62 62 22 22 22 6 6 6
42545- 0 0 0 0 0 0 0 0 0 0 0 0
42546- 0 0 0 0 0 0 0 0 0 0 0 0
42547- 0 0 0 0 0 0 0 0 0 0 0 0
42548- 0 0 0 0 0 0 0 0 0 0 0 0
42549- 0 0 0 0 0 0 0 0 0 0 0 0
42550- 0 0 0 0 0 0 0 0 0 0 0 0
42551- 0 0 0 0 0 0 0 0 1 0 0 0
42552- 0 0 1 0 0 0 0 0 1 0 0 0
42553- 0 0 0 0 0 0 0 0 0 0 0 0
42554- 0 0 0 0 0 0 0 0 0 0 0 0
42555- 0 0 0 0 0 0 0 0 0 0 0 0
42556- 0 0 0 0 0 0 0 0 0 0 0 0
42557- 0 0 0 0 0 0 0 0 0 14 14 14
42558- 42 42 42 94 94 94 14 14 14 101 101 101
42559-128 128 128 2 2 6 18 18 18 116 116 116
42560-118 98 46 121 92 8 121 92 8 98 78 10
42561-162 162 162 106 106 106 2 2 6 2 2 6
42562- 2 2 6 195 195 195 195 195 195 6 6 6
42563- 2 2 6 2 2 6 2 2 6 2 2 6
42564- 74 74 74 62 62 62 22 22 22 6 6 6
42565- 0 0 0 0 0 0 0 0 0 0 0 0
42566- 0 0 0 0 0 0 0 0 0 0 0 0
42567- 0 0 0 0 0 0 0 0 0 0 0 0
42568- 0 0 0 0 0 0 0 0 0 0 0 0
42569- 0 0 0 0 0 0 0 0 0 0 0 0
42570- 0 0 0 0 0 0 0 0 0 0 0 0
42571- 0 0 0 0 0 0 0 0 1 0 0 1
42572- 0 0 1 0 0 0 0 0 1 0 0 0
42573- 0 0 0 0 0 0 0 0 0 0 0 0
42574- 0 0 0 0 0 0 0 0 0 0 0 0
42575- 0 0 0 0 0 0 0 0 0 0 0 0
42576- 0 0 0 0 0 0 0 0 0 0 0 0
42577- 0 0 0 0 0 0 0 0 0 10 10 10
42578- 38 38 38 90 90 90 14 14 14 58 58 58
42579-210 210 210 26 26 26 54 38 6 154 114 10
42580-226 170 11 236 186 11 225 175 15 184 144 12
42581-215 174 15 175 146 61 37 26 9 2 2 6
42582- 70 70 70 246 246 246 138 138 138 2 2 6
42583- 2 2 6 2 2 6 2 2 6 2 2 6
42584- 70 70 70 66 66 66 26 26 26 6 6 6
42585- 0 0 0 0 0 0 0 0 0 0 0 0
42586- 0 0 0 0 0 0 0 0 0 0 0 0
42587- 0 0 0 0 0 0 0 0 0 0 0 0
42588- 0 0 0 0 0 0 0 0 0 0 0 0
42589- 0 0 0 0 0 0 0 0 0 0 0 0
42590- 0 0 0 0 0 0 0 0 0 0 0 0
42591- 0 0 0 0 0 0 0 0 0 0 0 0
42592- 0 0 0 0 0 0 0 0 0 0 0 0
42593- 0 0 0 0 0 0 0 0 0 0 0 0
42594- 0 0 0 0 0 0 0 0 0 0 0 0
42595- 0 0 0 0 0 0 0 0 0 0 0 0
42596- 0 0 0 0 0 0 0 0 0 0 0 0
42597- 0 0 0 0 0 0 0 0 0 10 10 10
42598- 38 38 38 86 86 86 14 14 14 10 10 10
42599-195 195 195 188 164 115 192 133 9 225 175 15
42600-239 182 13 234 190 10 232 195 16 232 200 30
42601-245 207 45 241 208 19 232 195 16 184 144 12
42602-218 194 134 211 206 186 42 42 42 2 2 6
42603- 2 2 6 2 2 6 2 2 6 2 2 6
42604- 50 50 50 74 74 74 30 30 30 6 6 6
42605- 0 0 0 0 0 0 0 0 0 0 0 0
42606- 0 0 0 0 0 0 0 0 0 0 0 0
42607- 0 0 0 0 0 0 0 0 0 0 0 0
42608- 0 0 0 0 0 0 0 0 0 0 0 0
42609- 0 0 0 0 0 0 0 0 0 0 0 0
42610- 0 0 0 0 0 0 0 0 0 0 0 0
42611- 0 0 0 0 0 0 0 0 0 0 0 0
42612- 0 0 0 0 0 0 0 0 0 0 0 0
42613- 0 0 0 0 0 0 0 0 0 0 0 0
42614- 0 0 0 0 0 0 0 0 0 0 0 0
42615- 0 0 0 0 0 0 0 0 0 0 0 0
42616- 0 0 0 0 0 0 0 0 0 0 0 0
42617- 0 0 0 0 0 0 0 0 0 10 10 10
42618- 34 34 34 86 86 86 14 14 14 2 2 6
42619-121 87 25 192 133 9 219 162 10 239 182 13
42620-236 186 11 232 195 16 241 208 19 244 214 54
42621-246 218 60 246 218 38 246 215 20 241 208 19
42622-241 208 19 226 184 13 121 87 25 2 2 6
42623- 2 2 6 2 2 6 2 2 6 2 2 6
42624- 50 50 50 82 82 82 34 34 34 10 10 10
42625- 0 0 0 0 0 0 0 0 0 0 0 0
42626- 0 0 0 0 0 0 0 0 0 0 0 0
42627- 0 0 0 0 0 0 0 0 0 0 0 0
42628- 0 0 0 0 0 0 0 0 0 0 0 0
42629- 0 0 0 0 0 0 0 0 0 0 0 0
42630- 0 0 0 0 0 0 0 0 0 0 0 0
42631- 0 0 0 0 0 0 0 0 0 0 0 0
42632- 0 0 0 0 0 0 0 0 0 0 0 0
42633- 0 0 0 0 0 0 0 0 0 0 0 0
42634- 0 0 0 0 0 0 0 0 0 0 0 0
42635- 0 0 0 0 0 0 0 0 0 0 0 0
42636- 0 0 0 0 0 0 0 0 0 0 0 0
42637- 0 0 0 0 0 0 0 0 0 10 10 10
42638- 34 34 34 82 82 82 30 30 30 61 42 6
42639-180 123 7 206 145 10 230 174 11 239 182 13
42640-234 190 10 238 202 15 241 208 19 246 218 74
42641-246 218 38 246 215 20 246 215 20 246 215 20
42642-226 184 13 215 174 15 184 144 12 6 6 6
42643- 2 2 6 2 2 6 2 2 6 2 2 6
42644- 26 26 26 94 94 94 42 42 42 14 14 14
42645- 0 0 0 0 0 0 0 0 0 0 0 0
42646- 0 0 0 0 0 0 0 0 0 0 0 0
42647- 0 0 0 0 0 0 0 0 0 0 0 0
42648- 0 0 0 0 0 0 0 0 0 0 0 0
42649- 0 0 0 0 0 0 0 0 0 0 0 0
42650- 0 0 0 0 0 0 0 0 0 0 0 0
42651- 0 0 0 0 0 0 0 0 0 0 0 0
42652- 0 0 0 0 0 0 0 0 0 0 0 0
42653- 0 0 0 0 0 0 0 0 0 0 0 0
42654- 0 0 0 0 0 0 0 0 0 0 0 0
42655- 0 0 0 0 0 0 0 0 0 0 0 0
42656- 0 0 0 0 0 0 0 0 0 0 0 0
42657- 0 0 0 0 0 0 0 0 0 10 10 10
42658- 30 30 30 78 78 78 50 50 50 104 69 6
42659-192 133 9 216 158 10 236 178 12 236 186 11
42660-232 195 16 241 208 19 244 214 54 245 215 43
42661-246 215 20 246 215 20 241 208 19 198 155 10
42662-200 144 11 216 158 10 156 118 10 2 2 6
42663- 2 2 6 2 2 6 2 2 6 2 2 6
42664- 6 6 6 90 90 90 54 54 54 18 18 18
42665- 6 6 6 0 0 0 0 0 0 0 0 0
42666- 0 0 0 0 0 0 0 0 0 0 0 0
42667- 0 0 0 0 0 0 0 0 0 0 0 0
42668- 0 0 0 0 0 0 0 0 0 0 0 0
42669- 0 0 0 0 0 0 0 0 0 0 0 0
42670- 0 0 0 0 0 0 0 0 0 0 0 0
42671- 0 0 0 0 0 0 0 0 0 0 0 0
42672- 0 0 0 0 0 0 0 0 0 0 0 0
42673- 0 0 0 0 0 0 0 0 0 0 0 0
42674- 0 0 0 0 0 0 0 0 0 0 0 0
42675- 0 0 0 0 0 0 0 0 0 0 0 0
42676- 0 0 0 0 0 0 0 0 0 0 0 0
42677- 0 0 0 0 0 0 0 0 0 10 10 10
42678- 30 30 30 78 78 78 46 46 46 22 22 22
42679-137 92 6 210 162 10 239 182 13 238 190 10
42680-238 202 15 241 208 19 246 215 20 246 215 20
42681-241 208 19 203 166 17 185 133 11 210 150 10
42682-216 158 10 210 150 10 102 78 10 2 2 6
42683- 6 6 6 54 54 54 14 14 14 2 2 6
42684- 2 2 6 62 62 62 74 74 74 30 30 30
42685- 10 10 10 0 0 0 0 0 0 0 0 0
42686- 0 0 0 0 0 0 0 0 0 0 0 0
42687- 0 0 0 0 0 0 0 0 0 0 0 0
42688- 0 0 0 0 0 0 0 0 0 0 0 0
42689- 0 0 0 0 0 0 0 0 0 0 0 0
42690- 0 0 0 0 0 0 0 0 0 0 0 0
42691- 0 0 0 0 0 0 0 0 0 0 0 0
42692- 0 0 0 0 0 0 0 0 0 0 0 0
42693- 0 0 0 0 0 0 0 0 0 0 0 0
42694- 0 0 0 0 0 0 0 0 0 0 0 0
42695- 0 0 0 0 0 0 0 0 0 0 0 0
42696- 0 0 0 0 0 0 0 0 0 0 0 0
42697- 0 0 0 0 0 0 0 0 0 10 10 10
42698- 34 34 34 78 78 78 50 50 50 6 6 6
42699- 94 70 30 139 102 15 190 146 13 226 184 13
42700-232 200 30 232 195 16 215 174 15 190 146 13
42701-168 122 10 192 133 9 210 150 10 213 154 11
42702-202 150 34 182 157 106 101 98 89 2 2 6
42703- 2 2 6 78 78 78 116 116 116 58 58 58
42704- 2 2 6 22 22 22 90 90 90 46 46 46
42705- 18 18 18 6 6 6 0 0 0 0 0 0
42706- 0 0 0 0 0 0 0 0 0 0 0 0
42707- 0 0 0 0 0 0 0 0 0 0 0 0
42708- 0 0 0 0 0 0 0 0 0 0 0 0
42709- 0 0 0 0 0 0 0 0 0 0 0 0
42710- 0 0 0 0 0 0 0 0 0 0 0 0
42711- 0 0 0 0 0 0 0 0 0 0 0 0
42712- 0 0 0 0 0 0 0 0 0 0 0 0
42713- 0 0 0 0 0 0 0 0 0 0 0 0
42714- 0 0 0 0 0 0 0 0 0 0 0 0
42715- 0 0 0 0 0 0 0 0 0 0 0 0
42716- 0 0 0 0 0 0 0 0 0 0 0 0
42717- 0 0 0 0 0 0 0 0 0 10 10 10
42718- 38 38 38 86 86 86 50 50 50 6 6 6
42719-128 128 128 174 154 114 156 107 11 168 122 10
42720-198 155 10 184 144 12 197 138 11 200 144 11
42721-206 145 10 206 145 10 197 138 11 188 164 115
42722-195 195 195 198 198 198 174 174 174 14 14 14
42723- 2 2 6 22 22 22 116 116 116 116 116 116
42724- 22 22 22 2 2 6 74 74 74 70 70 70
42725- 30 30 30 10 10 10 0 0 0 0 0 0
42726- 0 0 0 0 0 0 0 0 0 0 0 0
42727- 0 0 0 0 0 0 0 0 0 0 0 0
42728- 0 0 0 0 0 0 0 0 0 0 0 0
42729- 0 0 0 0 0 0 0 0 0 0 0 0
42730- 0 0 0 0 0 0 0 0 0 0 0 0
42731- 0 0 0 0 0 0 0 0 0 0 0 0
42732- 0 0 0 0 0 0 0 0 0 0 0 0
42733- 0 0 0 0 0 0 0 0 0 0 0 0
42734- 0 0 0 0 0 0 0 0 0 0 0 0
42735- 0 0 0 0 0 0 0 0 0 0 0 0
42736- 0 0 0 0 0 0 0 0 0 0 0 0
42737- 0 0 0 0 0 0 6 6 6 18 18 18
42738- 50 50 50 101 101 101 26 26 26 10 10 10
42739-138 138 138 190 190 190 174 154 114 156 107 11
42740-197 138 11 200 144 11 197 138 11 192 133 9
42741-180 123 7 190 142 34 190 178 144 187 187 187
42742-202 202 202 221 221 221 214 214 214 66 66 66
42743- 2 2 6 2 2 6 50 50 50 62 62 62
42744- 6 6 6 2 2 6 10 10 10 90 90 90
42745- 50 50 50 18 18 18 6 6 6 0 0 0
42746- 0 0 0 0 0 0 0 0 0 0 0 0
42747- 0 0 0 0 0 0 0 0 0 0 0 0
42748- 0 0 0 0 0 0 0 0 0 0 0 0
42749- 0 0 0 0 0 0 0 0 0 0 0 0
42750- 0 0 0 0 0 0 0 0 0 0 0 0
42751- 0 0 0 0 0 0 0 0 0 0 0 0
42752- 0 0 0 0 0 0 0 0 0 0 0 0
42753- 0 0 0 0 0 0 0 0 0 0 0 0
42754- 0 0 0 0 0 0 0 0 0 0 0 0
42755- 0 0 0 0 0 0 0 0 0 0 0 0
42756- 0 0 0 0 0 0 0 0 0 0 0 0
42757- 0 0 0 0 0 0 10 10 10 34 34 34
42758- 74 74 74 74 74 74 2 2 6 6 6 6
42759-144 144 144 198 198 198 190 190 190 178 166 146
42760-154 121 60 156 107 11 156 107 11 168 124 44
42761-174 154 114 187 187 187 190 190 190 210 210 210
42762-246 246 246 253 253 253 253 253 253 182 182 182
42763- 6 6 6 2 2 6 2 2 6 2 2 6
42764- 2 2 6 2 2 6 2 2 6 62 62 62
42765- 74 74 74 34 34 34 14 14 14 0 0 0
42766- 0 0 0 0 0 0 0 0 0 0 0 0
42767- 0 0 0 0 0 0 0 0 0 0 0 0
42768- 0 0 0 0 0 0 0 0 0 0 0 0
42769- 0 0 0 0 0 0 0 0 0 0 0 0
42770- 0 0 0 0 0 0 0 0 0 0 0 0
42771- 0 0 0 0 0 0 0 0 0 0 0 0
42772- 0 0 0 0 0 0 0 0 0 0 0 0
42773- 0 0 0 0 0 0 0 0 0 0 0 0
42774- 0 0 0 0 0 0 0 0 0 0 0 0
42775- 0 0 0 0 0 0 0 0 0 0 0 0
42776- 0 0 0 0 0 0 0 0 0 0 0 0
42777- 0 0 0 10 10 10 22 22 22 54 54 54
42778- 94 94 94 18 18 18 2 2 6 46 46 46
42779-234 234 234 221 221 221 190 190 190 190 190 190
42780-190 190 190 187 187 187 187 187 187 190 190 190
42781-190 190 190 195 195 195 214 214 214 242 242 242
42782-253 253 253 253 253 253 253 253 253 253 253 253
42783- 82 82 82 2 2 6 2 2 6 2 2 6
42784- 2 2 6 2 2 6 2 2 6 14 14 14
42785- 86 86 86 54 54 54 22 22 22 6 6 6
42786- 0 0 0 0 0 0 0 0 0 0 0 0
42787- 0 0 0 0 0 0 0 0 0 0 0 0
42788- 0 0 0 0 0 0 0 0 0 0 0 0
42789- 0 0 0 0 0 0 0 0 0 0 0 0
42790- 0 0 0 0 0 0 0 0 0 0 0 0
42791- 0 0 0 0 0 0 0 0 0 0 0 0
42792- 0 0 0 0 0 0 0 0 0 0 0 0
42793- 0 0 0 0 0 0 0 0 0 0 0 0
42794- 0 0 0 0 0 0 0 0 0 0 0 0
42795- 0 0 0 0 0 0 0 0 0 0 0 0
42796- 0 0 0 0 0 0 0 0 0 0 0 0
42797- 6 6 6 18 18 18 46 46 46 90 90 90
42798- 46 46 46 18 18 18 6 6 6 182 182 182
42799-253 253 253 246 246 246 206 206 206 190 190 190
42800-190 190 190 190 190 190 190 190 190 190 190 190
42801-206 206 206 231 231 231 250 250 250 253 253 253
42802-253 253 253 253 253 253 253 253 253 253 253 253
42803-202 202 202 14 14 14 2 2 6 2 2 6
42804- 2 2 6 2 2 6 2 2 6 2 2 6
42805- 42 42 42 86 86 86 42 42 42 18 18 18
42806- 6 6 6 0 0 0 0 0 0 0 0 0
42807- 0 0 0 0 0 0 0 0 0 0 0 0
42808- 0 0 0 0 0 0 0 0 0 0 0 0
42809- 0 0 0 0 0 0 0 0 0 0 0 0
42810- 0 0 0 0 0 0 0 0 0 0 0 0
42811- 0 0 0 0 0 0 0 0 0 0 0 0
42812- 0 0 0 0 0 0 0 0 0 0 0 0
42813- 0 0 0 0 0 0 0 0 0 0 0 0
42814- 0 0 0 0 0 0 0 0 0 0 0 0
42815- 0 0 0 0 0 0 0 0 0 0 0 0
42816- 0 0 0 0 0 0 0 0 0 6 6 6
42817- 14 14 14 38 38 38 74 74 74 66 66 66
42818- 2 2 6 6 6 6 90 90 90 250 250 250
42819-253 253 253 253 253 253 238 238 238 198 198 198
42820-190 190 190 190 190 190 195 195 195 221 221 221
42821-246 246 246 253 253 253 253 253 253 253 253 253
42822-253 253 253 253 253 253 253 253 253 253 253 253
42823-253 253 253 82 82 82 2 2 6 2 2 6
42824- 2 2 6 2 2 6 2 2 6 2 2 6
42825- 2 2 6 78 78 78 70 70 70 34 34 34
42826- 14 14 14 6 6 6 0 0 0 0 0 0
42827- 0 0 0 0 0 0 0 0 0 0 0 0
42828- 0 0 0 0 0 0 0 0 0 0 0 0
42829- 0 0 0 0 0 0 0 0 0 0 0 0
42830- 0 0 0 0 0 0 0 0 0 0 0 0
42831- 0 0 0 0 0 0 0 0 0 0 0 0
42832- 0 0 0 0 0 0 0 0 0 0 0 0
42833- 0 0 0 0 0 0 0 0 0 0 0 0
42834- 0 0 0 0 0 0 0 0 0 0 0 0
42835- 0 0 0 0 0 0 0 0 0 0 0 0
42836- 0 0 0 0 0 0 0 0 0 14 14 14
42837- 34 34 34 66 66 66 78 78 78 6 6 6
42838- 2 2 6 18 18 18 218 218 218 253 253 253
42839-253 253 253 253 253 253 253 253 253 246 246 246
42840-226 226 226 231 231 231 246 246 246 253 253 253
42841-253 253 253 253 253 253 253 253 253 253 253 253
42842-253 253 253 253 253 253 253 253 253 253 253 253
42843-253 253 253 178 178 178 2 2 6 2 2 6
42844- 2 2 6 2 2 6 2 2 6 2 2 6
42845- 2 2 6 18 18 18 90 90 90 62 62 62
42846- 30 30 30 10 10 10 0 0 0 0 0 0
42847- 0 0 0 0 0 0 0 0 0 0 0 0
42848- 0 0 0 0 0 0 0 0 0 0 0 0
42849- 0 0 0 0 0 0 0 0 0 0 0 0
42850- 0 0 0 0 0 0 0 0 0 0 0 0
42851- 0 0 0 0 0 0 0 0 0 0 0 0
42852- 0 0 0 0 0 0 0 0 0 0 0 0
42853- 0 0 0 0 0 0 0 0 0 0 0 0
42854- 0 0 0 0 0 0 0 0 0 0 0 0
42855- 0 0 0 0 0 0 0 0 0 0 0 0
42856- 0 0 0 0 0 0 10 10 10 26 26 26
42857- 58 58 58 90 90 90 18 18 18 2 2 6
42858- 2 2 6 110 110 110 253 253 253 253 253 253
42859-253 253 253 253 253 253 253 253 253 253 253 253
42860-250 250 250 253 253 253 253 253 253 253 253 253
42861-253 253 253 253 253 253 253 253 253 253 253 253
42862-253 253 253 253 253 253 253 253 253 253 253 253
42863-253 253 253 231 231 231 18 18 18 2 2 6
42864- 2 2 6 2 2 6 2 2 6 2 2 6
42865- 2 2 6 2 2 6 18 18 18 94 94 94
42866- 54 54 54 26 26 26 10 10 10 0 0 0
42867- 0 0 0 0 0 0 0 0 0 0 0 0
42868- 0 0 0 0 0 0 0 0 0 0 0 0
42869- 0 0 0 0 0 0 0 0 0 0 0 0
42870- 0 0 0 0 0 0 0 0 0 0 0 0
42871- 0 0 0 0 0 0 0 0 0 0 0 0
42872- 0 0 0 0 0 0 0 0 0 0 0 0
42873- 0 0 0 0 0 0 0 0 0 0 0 0
42874- 0 0 0 0 0 0 0 0 0 0 0 0
42875- 0 0 0 0 0 0 0 0 0 0 0 0
42876- 0 0 0 6 6 6 22 22 22 50 50 50
42877- 90 90 90 26 26 26 2 2 6 2 2 6
42878- 14 14 14 195 195 195 250 250 250 253 253 253
42879-253 253 253 253 253 253 253 253 253 253 253 253
42880-253 253 253 253 253 253 253 253 253 253 253 253
42881-253 253 253 253 253 253 253 253 253 253 253 253
42882-253 253 253 253 253 253 253 253 253 253 253 253
42883-250 250 250 242 242 242 54 54 54 2 2 6
42884- 2 2 6 2 2 6 2 2 6 2 2 6
42885- 2 2 6 2 2 6 2 2 6 38 38 38
42886- 86 86 86 50 50 50 22 22 22 6 6 6
42887- 0 0 0 0 0 0 0 0 0 0 0 0
42888- 0 0 0 0 0 0 0 0 0 0 0 0
42889- 0 0 0 0 0 0 0 0 0 0 0 0
42890- 0 0 0 0 0 0 0 0 0 0 0 0
42891- 0 0 0 0 0 0 0 0 0 0 0 0
42892- 0 0 0 0 0 0 0 0 0 0 0 0
42893- 0 0 0 0 0 0 0 0 0 0 0 0
42894- 0 0 0 0 0 0 0 0 0 0 0 0
42895- 0 0 0 0 0 0 0 0 0 0 0 0
42896- 6 6 6 14 14 14 38 38 38 82 82 82
42897- 34 34 34 2 2 6 2 2 6 2 2 6
42898- 42 42 42 195 195 195 246 246 246 253 253 253
42899-253 253 253 253 253 253 253 253 253 250 250 250
42900-242 242 242 242 242 242 250 250 250 253 253 253
42901-253 253 253 253 253 253 253 253 253 253 253 253
42902-253 253 253 250 250 250 246 246 246 238 238 238
42903-226 226 226 231 231 231 101 101 101 6 6 6
42904- 2 2 6 2 2 6 2 2 6 2 2 6
42905- 2 2 6 2 2 6 2 2 6 2 2 6
42906- 38 38 38 82 82 82 42 42 42 14 14 14
42907- 6 6 6 0 0 0 0 0 0 0 0 0
42908- 0 0 0 0 0 0 0 0 0 0 0 0
42909- 0 0 0 0 0 0 0 0 0 0 0 0
42910- 0 0 0 0 0 0 0 0 0 0 0 0
42911- 0 0 0 0 0 0 0 0 0 0 0 0
42912- 0 0 0 0 0 0 0 0 0 0 0 0
42913- 0 0 0 0 0 0 0 0 0 0 0 0
42914- 0 0 0 0 0 0 0 0 0 0 0 0
42915- 0 0 0 0 0 0 0 0 0 0 0 0
42916- 10 10 10 26 26 26 62 62 62 66 66 66
42917- 2 2 6 2 2 6 2 2 6 6 6 6
42918- 70 70 70 170 170 170 206 206 206 234 234 234
42919-246 246 246 250 250 250 250 250 250 238 238 238
42920-226 226 226 231 231 231 238 238 238 250 250 250
42921-250 250 250 250 250 250 246 246 246 231 231 231
42922-214 214 214 206 206 206 202 202 202 202 202 202
42923-198 198 198 202 202 202 182 182 182 18 18 18
42924- 2 2 6 2 2 6 2 2 6 2 2 6
42925- 2 2 6 2 2 6 2 2 6 2 2 6
42926- 2 2 6 62 62 62 66 66 66 30 30 30
42927- 10 10 10 0 0 0 0 0 0 0 0 0
42928- 0 0 0 0 0 0 0 0 0 0 0 0
42929- 0 0 0 0 0 0 0 0 0 0 0 0
42930- 0 0 0 0 0 0 0 0 0 0 0 0
42931- 0 0 0 0 0 0 0 0 0 0 0 0
42932- 0 0 0 0 0 0 0 0 0 0 0 0
42933- 0 0 0 0 0 0 0 0 0 0 0 0
42934- 0 0 0 0 0 0 0 0 0 0 0 0
42935- 0 0 0 0 0 0 0 0 0 0 0 0
42936- 14 14 14 42 42 42 82 82 82 18 18 18
42937- 2 2 6 2 2 6 2 2 6 10 10 10
42938- 94 94 94 182 182 182 218 218 218 242 242 242
42939-250 250 250 253 253 253 253 253 253 250 250 250
42940-234 234 234 253 253 253 253 253 253 253 253 253
42941-253 253 253 253 253 253 253 253 253 246 246 246
42942-238 238 238 226 226 226 210 210 210 202 202 202
42943-195 195 195 195 195 195 210 210 210 158 158 158
42944- 6 6 6 14 14 14 50 50 50 14 14 14
42945- 2 2 6 2 2 6 2 2 6 2 2 6
42946- 2 2 6 6 6 6 86 86 86 46 46 46
42947- 18 18 18 6 6 6 0 0 0 0 0 0
42948- 0 0 0 0 0 0 0 0 0 0 0 0
42949- 0 0 0 0 0 0 0 0 0 0 0 0
42950- 0 0 0 0 0 0 0 0 0 0 0 0
42951- 0 0 0 0 0 0 0 0 0 0 0 0
42952- 0 0 0 0 0 0 0 0 0 0 0 0
42953- 0 0 0 0 0 0 0 0 0 0 0 0
42954- 0 0 0 0 0 0 0 0 0 0 0 0
42955- 0 0 0 0 0 0 0 0 0 6 6 6
42956- 22 22 22 54 54 54 70 70 70 2 2 6
42957- 2 2 6 10 10 10 2 2 6 22 22 22
42958-166 166 166 231 231 231 250 250 250 253 253 253
42959-253 253 253 253 253 253 253 253 253 250 250 250
42960-242 242 242 253 253 253 253 253 253 253 253 253
42961-253 253 253 253 253 253 253 253 253 253 253 253
42962-253 253 253 253 253 253 253 253 253 246 246 246
42963-231 231 231 206 206 206 198 198 198 226 226 226
42964- 94 94 94 2 2 6 6 6 6 38 38 38
42965- 30 30 30 2 2 6 2 2 6 2 2 6
42966- 2 2 6 2 2 6 62 62 62 66 66 66
42967- 26 26 26 10 10 10 0 0 0 0 0 0
42968- 0 0 0 0 0 0 0 0 0 0 0 0
42969- 0 0 0 0 0 0 0 0 0 0 0 0
42970- 0 0 0 0 0 0 0 0 0 0 0 0
42971- 0 0 0 0 0 0 0 0 0 0 0 0
42972- 0 0 0 0 0 0 0 0 0 0 0 0
42973- 0 0 0 0 0 0 0 0 0 0 0 0
42974- 0 0 0 0 0 0 0 0 0 0 0 0
42975- 0 0 0 0 0 0 0 0 0 10 10 10
42976- 30 30 30 74 74 74 50 50 50 2 2 6
42977- 26 26 26 26 26 26 2 2 6 106 106 106
42978-238 238 238 253 253 253 253 253 253 253 253 253
42979-253 253 253 253 253 253 253 253 253 253 253 253
42980-253 253 253 253 253 253 253 253 253 253 253 253
42981-253 253 253 253 253 253 253 253 253 253 253 253
42982-253 253 253 253 253 253 253 253 253 253 253 253
42983-253 253 253 246 246 246 218 218 218 202 202 202
42984-210 210 210 14 14 14 2 2 6 2 2 6
42985- 30 30 30 22 22 22 2 2 6 2 2 6
42986- 2 2 6 2 2 6 18 18 18 86 86 86
42987- 42 42 42 14 14 14 0 0 0 0 0 0
42988- 0 0 0 0 0 0 0 0 0 0 0 0
42989- 0 0 0 0 0 0 0 0 0 0 0 0
42990- 0 0 0 0 0 0 0 0 0 0 0 0
42991- 0 0 0 0 0 0 0 0 0 0 0 0
42992- 0 0 0 0 0 0 0 0 0 0 0 0
42993- 0 0 0 0 0 0 0 0 0 0 0 0
42994- 0 0 0 0 0 0 0 0 0 0 0 0
42995- 0 0 0 0 0 0 0 0 0 14 14 14
42996- 42 42 42 90 90 90 22 22 22 2 2 6
42997- 42 42 42 2 2 6 18 18 18 218 218 218
42998-253 253 253 253 253 253 253 253 253 253 253 253
42999-253 253 253 253 253 253 253 253 253 253 253 253
43000-253 253 253 253 253 253 253 253 253 253 253 253
43001-253 253 253 253 253 253 253 253 253 253 253 253
43002-253 253 253 253 253 253 253 253 253 253 253 253
43003-253 253 253 253 253 253 250 250 250 221 221 221
43004-218 218 218 101 101 101 2 2 6 14 14 14
43005- 18 18 18 38 38 38 10 10 10 2 2 6
43006- 2 2 6 2 2 6 2 2 6 78 78 78
43007- 58 58 58 22 22 22 6 6 6 0 0 0
43008- 0 0 0 0 0 0 0 0 0 0 0 0
43009- 0 0 0 0 0 0 0 0 0 0 0 0
43010- 0 0 0 0 0 0 0 0 0 0 0 0
43011- 0 0 0 0 0 0 0 0 0 0 0 0
43012- 0 0 0 0 0 0 0 0 0 0 0 0
43013- 0 0 0 0 0 0 0 0 0 0 0 0
43014- 0 0 0 0 0 0 0 0 0 0 0 0
43015- 0 0 0 0 0 0 6 6 6 18 18 18
43016- 54 54 54 82 82 82 2 2 6 26 26 26
43017- 22 22 22 2 2 6 123 123 123 253 253 253
43018-253 253 253 253 253 253 253 253 253 253 253 253
43019-253 253 253 253 253 253 253 253 253 253 253 253
43020-253 253 253 253 253 253 253 253 253 253 253 253
43021-253 253 253 253 253 253 253 253 253 253 253 253
43022-253 253 253 253 253 253 253 253 253 253 253 253
43023-253 253 253 253 253 253 253 253 253 250 250 250
43024-238 238 238 198 198 198 6 6 6 38 38 38
43025- 58 58 58 26 26 26 38 38 38 2 2 6
43026- 2 2 6 2 2 6 2 2 6 46 46 46
43027- 78 78 78 30 30 30 10 10 10 0 0 0
43028- 0 0 0 0 0 0 0 0 0 0 0 0
43029- 0 0 0 0 0 0 0 0 0 0 0 0
43030- 0 0 0 0 0 0 0 0 0 0 0 0
43031- 0 0 0 0 0 0 0 0 0 0 0 0
43032- 0 0 0 0 0 0 0 0 0 0 0 0
43033- 0 0 0 0 0 0 0 0 0 0 0 0
43034- 0 0 0 0 0 0 0 0 0 0 0 0
43035- 0 0 0 0 0 0 10 10 10 30 30 30
43036- 74 74 74 58 58 58 2 2 6 42 42 42
43037- 2 2 6 22 22 22 231 231 231 253 253 253
43038-253 253 253 253 253 253 253 253 253 253 253 253
43039-253 253 253 253 253 253 253 253 253 250 250 250
43040-253 253 253 253 253 253 253 253 253 253 253 253
43041-253 253 253 253 253 253 253 253 253 253 253 253
43042-253 253 253 253 253 253 253 253 253 253 253 253
43043-253 253 253 253 253 253 253 253 253 253 253 253
43044-253 253 253 246 246 246 46 46 46 38 38 38
43045- 42 42 42 14 14 14 38 38 38 14 14 14
43046- 2 2 6 2 2 6 2 2 6 6 6 6
43047- 86 86 86 46 46 46 14 14 14 0 0 0
43048- 0 0 0 0 0 0 0 0 0 0 0 0
43049- 0 0 0 0 0 0 0 0 0 0 0 0
43050- 0 0 0 0 0 0 0 0 0 0 0 0
43051- 0 0 0 0 0 0 0 0 0 0 0 0
43052- 0 0 0 0 0 0 0 0 0 0 0 0
43053- 0 0 0 0 0 0 0 0 0 0 0 0
43054- 0 0 0 0 0 0 0 0 0 0 0 0
43055- 0 0 0 6 6 6 14 14 14 42 42 42
43056- 90 90 90 18 18 18 18 18 18 26 26 26
43057- 2 2 6 116 116 116 253 253 253 253 253 253
43058-253 253 253 253 253 253 253 253 253 253 253 253
43059-253 253 253 253 253 253 250 250 250 238 238 238
43060-253 253 253 253 253 253 253 253 253 253 253 253
43061-253 253 253 253 253 253 253 253 253 253 253 253
43062-253 253 253 253 253 253 253 253 253 253 253 253
43063-253 253 253 253 253 253 253 253 253 253 253 253
43064-253 253 253 253 253 253 94 94 94 6 6 6
43065- 2 2 6 2 2 6 10 10 10 34 34 34
43066- 2 2 6 2 2 6 2 2 6 2 2 6
43067- 74 74 74 58 58 58 22 22 22 6 6 6
43068- 0 0 0 0 0 0 0 0 0 0 0 0
43069- 0 0 0 0 0 0 0 0 0 0 0 0
43070- 0 0 0 0 0 0 0 0 0 0 0 0
43071- 0 0 0 0 0 0 0 0 0 0 0 0
43072- 0 0 0 0 0 0 0 0 0 0 0 0
43073- 0 0 0 0 0 0 0 0 0 0 0 0
43074- 0 0 0 0 0 0 0 0 0 0 0 0
43075- 0 0 0 10 10 10 26 26 26 66 66 66
43076- 82 82 82 2 2 6 38 38 38 6 6 6
43077- 14 14 14 210 210 210 253 253 253 253 253 253
43078-253 253 253 253 253 253 253 253 253 253 253 253
43079-253 253 253 253 253 253 246 246 246 242 242 242
43080-253 253 253 253 253 253 253 253 253 253 253 253
43081-253 253 253 253 253 253 253 253 253 253 253 253
43082-253 253 253 253 253 253 253 253 253 253 253 253
43083-253 253 253 253 253 253 253 253 253 253 253 253
43084-253 253 253 253 253 253 144 144 144 2 2 6
43085- 2 2 6 2 2 6 2 2 6 46 46 46
43086- 2 2 6 2 2 6 2 2 6 2 2 6
43087- 42 42 42 74 74 74 30 30 30 10 10 10
43088- 0 0 0 0 0 0 0 0 0 0 0 0
43089- 0 0 0 0 0 0 0 0 0 0 0 0
43090- 0 0 0 0 0 0 0 0 0 0 0 0
43091- 0 0 0 0 0 0 0 0 0 0 0 0
43092- 0 0 0 0 0 0 0 0 0 0 0 0
43093- 0 0 0 0 0 0 0 0 0 0 0 0
43094- 0 0 0 0 0 0 0 0 0 0 0 0
43095- 6 6 6 14 14 14 42 42 42 90 90 90
43096- 26 26 26 6 6 6 42 42 42 2 2 6
43097- 74 74 74 250 250 250 253 253 253 253 253 253
43098-253 253 253 253 253 253 253 253 253 253 253 253
43099-253 253 253 253 253 253 242 242 242 242 242 242
43100-253 253 253 253 253 253 253 253 253 253 253 253
43101-253 253 253 253 253 253 253 253 253 253 253 253
43102-253 253 253 253 253 253 253 253 253 253 253 253
43103-253 253 253 253 253 253 253 253 253 253 253 253
43104-253 253 253 253 253 253 182 182 182 2 2 6
43105- 2 2 6 2 2 6 2 2 6 46 46 46
43106- 2 2 6 2 2 6 2 2 6 2 2 6
43107- 10 10 10 86 86 86 38 38 38 10 10 10
43108- 0 0 0 0 0 0 0 0 0 0 0 0
43109- 0 0 0 0 0 0 0 0 0 0 0 0
43110- 0 0 0 0 0 0 0 0 0 0 0 0
43111- 0 0 0 0 0 0 0 0 0 0 0 0
43112- 0 0 0 0 0 0 0 0 0 0 0 0
43113- 0 0 0 0 0 0 0 0 0 0 0 0
43114- 0 0 0 0 0 0 0 0 0 0 0 0
43115- 10 10 10 26 26 26 66 66 66 82 82 82
43116- 2 2 6 22 22 22 18 18 18 2 2 6
43117-149 149 149 253 253 253 253 253 253 253 253 253
43118-253 253 253 253 253 253 253 253 253 253 253 253
43119-253 253 253 253 253 253 234 234 234 242 242 242
43120-253 253 253 253 253 253 253 253 253 253 253 253
43121-253 253 253 253 253 253 253 253 253 253 253 253
43122-253 253 253 253 253 253 253 253 253 253 253 253
43123-253 253 253 253 253 253 253 253 253 253 253 253
43124-253 253 253 253 253 253 206 206 206 2 2 6
43125- 2 2 6 2 2 6 2 2 6 38 38 38
43126- 2 2 6 2 2 6 2 2 6 2 2 6
43127- 6 6 6 86 86 86 46 46 46 14 14 14
43128- 0 0 0 0 0 0 0 0 0 0 0 0
43129- 0 0 0 0 0 0 0 0 0 0 0 0
43130- 0 0 0 0 0 0 0 0 0 0 0 0
43131- 0 0 0 0 0 0 0 0 0 0 0 0
43132- 0 0 0 0 0 0 0 0 0 0 0 0
43133- 0 0 0 0 0 0 0 0 0 0 0 0
43134- 0 0 0 0 0 0 0 0 0 6 6 6
43135- 18 18 18 46 46 46 86 86 86 18 18 18
43136- 2 2 6 34 34 34 10 10 10 6 6 6
43137-210 210 210 253 253 253 253 253 253 253 253 253
43138-253 253 253 253 253 253 253 253 253 253 253 253
43139-253 253 253 253 253 253 234 234 234 242 242 242
43140-253 253 253 253 253 253 253 253 253 253 253 253
43141-253 253 253 253 253 253 253 253 253 253 253 253
43142-253 253 253 253 253 253 253 253 253 253 253 253
43143-253 253 253 253 253 253 253 253 253 253 253 253
43144-253 253 253 253 253 253 221 221 221 6 6 6
43145- 2 2 6 2 2 6 6 6 6 30 30 30
43146- 2 2 6 2 2 6 2 2 6 2 2 6
43147- 2 2 6 82 82 82 54 54 54 18 18 18
43148- 6 6 6 0 0 0 0 0 0 0 0 0
43149- 0 0 0 0 0 0 0 0 0 0 0 0
43150- 0 0 0 0 0 0 0 0 0 0 0 0
43151- 0 0 0 0 0 0 0 0 0 0 0 0
43152- 0 0 0 0 0 0 0 0 0 0 0 0
43153- 0 0 0 0 0 0 0 0 0 0 0 0
43154- 0 0 0 0 0 0 0 0 0 10 10 10
43155- 26 26 26 66 66 66 62 62 62 2 2 6
43156- 2 2 6 38 38 38 10 10 10 26 26 26
43157-238 238 238 253 253 253 253 253 253 253 253 253
43158-253 253 253 253 253 253 253 253 253 253 253 253
43159-253 253 253 253 253 253 231 231 231 238 238 238
43160-253 253 253 253 253 253 253 253 253 253 253 253
43161-253 253 253 253 253 253 253 253 253 253 253 253
43162-253 253 253 253 253 253 253 253 253 253 253 253
43163-253 253 253 253 253 253 253 253 253 253 253 253
43164-253 253 253 253 253 253 231 231 231 6 6 6
43165- 2 2 6 2 2 6 10 10 10 30 30 30
43166- 2 2 6 2 2 6 2 2 6 2 2 6
43167- 2 2 6 66 66 66 58 58 58 22 22 22
43168- 6 6 6 0 0 0 0 0 0 0 0 0
43169- 0 0 0 0 0 0 0 0 0 0 0 0
43170- 0 0 0 0 0 0 0 0 0 0 0 0
43171- 0 0 0 0 0 0 0 0 0 0 0 0
43172- 0 0 0 0 0 0 0 0 0 0 0 0
43173- 0 0 0 0 0 0 0 0 0 0 0 0
43174- 0 0 0 0 0 0 0 0 0 10 10 10
43175- 38 38 38 78 78 78 6 6 6 2 2 6
43176- 2 2 6 46 46 46 14 14 14 42 42 42
43177-246 246 246 253 253 253 253 253 253 253 253 253
43178-253 253 253 253 253 253 253 253 253 253 253 253
43179-253 253 253 253 253 253 231 231 231 242 242 242
43180-253 253 253 253 253 253 253 253 253 253 253 253
43181-253 253 253 253 253 253 253 253 253 253 253 253
43182-253 253 253 253 253 253 253 253 253 253 253 253
43183-253 253 253 253 253 253 253 253 253 253 253 253
43184-253 253 253 253 253 253 234 234 234 10 10 10
43185- 2 2 6 2 2 6 22 22 22 14 14 14
43186- 2 2 6 2 2 6 2 2 6 2 2 6
43187- 2 2 6 66 66 66 62 62 62 22 22 22
43188- 6 6 6 0 0 0 0 0 0 0 0 0
43189- 0 0 0 0 0 0 0 0 0 0 0 0
43190- 0 0 0 0 0 0 0 0 0 0 0 0
43191- 0 0 0 0 0 0 0 0 0 0 0 0
43192- 0 0 0 0 0 0 0 0 0 0 0 0
43193- 0 0 0 0 0 0 0 0 0 0 0 0
43194- 0 0 0 0 0 0 6 6 6 18 18 18
43195- 50 50 50 74 74 74 2 2 6 2 2 6
43196- 14 14 14 70 70 70 34 34 34 62 62 62
43197-250 250 250 253 253 253 253 253 253 253 253 253
43198-253 253 253 253 253 253 253 253 253 253 253 253
43199-253 253 253 253 253 253 231 231 231 246 246 246
43200-253 253 253 253 253 253 253 253 253 253 253 253
43201-253 253 253 253 253 253 253 253 253 253 253 253
43202-253 253 253 253 253 253 253 253 253 253 253 253
43203-253 253 253 253 253 253 253 253 253 253 253 253
43204-253 253 253 253 253 253 234 234 234 14 14 14
43205- 2 2 6 2 2 6 30 30 30 2 2 6
43206- 2 2 6 2 2 6 2 2 6 2 2 6
43207- 2 2 6 66 66 66 62 62 62 22 22 22
43208- 6 6 6 0 0 0 0 0 0 0 0 0
43209- 0 0 0 0 0 0 0 0 0 0 0 0
43210- 0 0 0 0 0 0 0 0 0 0 0 0
43211- 0 0 0 0 0 0 0 0 0 0 0 0
43212- 0 0 0 0 0 0 0 0 0 0 0 0
43213- 0 0 0 0 0 0 0 0 0 0 0 0
43214- 0 0 0 0 0 0 6 6 6 18 18 18
43215- 54 54 54 62 62 62 2 2 6 2 2 6
43216- 2 2 6 30 30 30 46 46 46 70 70 70
43217-250 250 250 253 253 253 253 253 253 253 253 253
43218-253 253 253 253 253 253 253 253 253 253 253 253
43219-253 253 253 253 253 253 231 231 231 246 246 246
43220-253 253 253 253 253 253 253 253 253 253 253 253
43221-253 253 253 253 253 253 253 253 253 253 253 253
43222-253 253 253 253 253 253 253 253 253 253 253 253
43223-253 253 253 253 253 253 253 253 253 253 253 253
43224-253 253 253 253 253 253 226 226 226 10 10 10
43225- 2 2 6 6 6 6 30 30 30 2 2 6
43226- 2 2 6 2 2 6 2 2 6 2 2 6
43227- 2 2 6 66 66 66 58 58 58 22 22 22
43228- 6 6 6 0 0 0 0 0 0 0 0 0
43229- 0 0 0 0 0 0 0 0 0 0 0 0
43230- 0 0 0 0 0 0 0 0 0 0 0 0
43231- 0 0 0 0 0 0 0 0 0 0 0 0
43232- 0 0 0 0 0 0 0 0 0 0 0 0
43233- 0 0 0 0 0 0 0 0 0 0 0 0
43234- 0 0 0 0 0 0 6 6 6 22 22 22
43235- 58 58 58 62 62 62 2 2 6 2 2 6
43236- 2 2 6 2 2 6 30 30 30 78 78 78
43237-250 250 250 253 253 253 253 253 253 253 253 253
43238-253 253 253 253 253 253 253 253 253 253 253 253
43239-253 253 253 253 253 253 231 231 231 246 246 246
43240-253 253 253 253 253 253 253 253 253 253 253 253
43241-253 253 253 253 253 253 253 253 253 253 253 253
43242-253 253 253 253 253 253 253 253 253 253 253 253
43243-253 253 253 253 253 253 253 253 253 253 253 253
43244-253 253 253 253 253 253 206 206 206 2 2 6
43245- 22 22 22 34 34 34 18 14 6 22 22 22
43246- 26 26 26 18 18 18 6 6 6 2 2 6
43247- 2 2 6 82 82 82 54 54 54 18 18 18
43248- 6 6 6 0 0 0 0 0 0 0 0 0
43249- 0 0 0 0 0 0 0 0 0 0 0 0
43250- 0 0 0 0 0 0 0 0 0 0 0 0
43251- 0 0 0 0 0 0 0 0 0 0 0 0
43252- 0 0 0 0 0 0 0 0 0 0 0 0
43253- 0 0 0 0 0 0 0 0 0 0 0 0
43254- 0 0 0 0 0 0 6 6 6 26 26 26
43255- 62 62 62 106 106 106 74 54 14 185 133 11
43256-210 162 10 121 92 8 6 6 6 62 62 62
43257-238 238 238 253 253 253 253 253 253 253 253 253
43258-253 253 253 253 253 253 253 253 253 253 253 253
43259-253 253 253 253 253 253 231 231 231 246 246 246
43260-253 253 253 253 253 253 253 253 253 253 253 253
43261-253 253 253 253 253 253 253 253 253 253 253 253
43262-253 253 253 253 253 253 253 253 253 253 253 253
43263-253 253 253 253 253 253 253 253 253 253 253 253
43264-253 253 253 253 253 253 158 158 158 18 18 18
43265- 14 14 14 2 2 6 2 2 6 2 2 6
43266- 6 6 6 18 18 18 66 66 66 38 38 38
43267- 6 6 6 94 94 94 50 50 50 18 18 18
43268- 6 6 6 0 0 0 0 0 0 0 0 0
43269- 0 0 0 0 0 0 0 0 0 0 0 0
43270- 0 0 0 0 0 0 0 0 0 0 0 0
43271- 0 0 0 0 0 0 0 0 0 0 0 0
43272- 0 0 0 0 0 0 0 0 0 0 0 0
43273- 0 0 0 0 0 0 0 0 0 6 6 6
43274- 10 10 10 10 10 10 18 18 18 38 38 38
43275- 78 78 78 142 134 106 216 158 10 242 186 14
43276-246 190 14 246 190 14 156 118 10 10 10 10
43277- 90 90 90 238 238 238 253 253 253 253 253 253
43278-253 253 253 253 253 253 253 253 253 253 253 253
43279-253 253 253 253 253 253 231 231 231 250 250 250
43280-253 253 253 253 253 253 253 253 253 253 253 253
43281-253 253 253 253 253 253 253 253 253 253 253 253
43282-253 253 253 253 253 253 253 253 253 253 253 253
43283-253 253 253 253 253 253 253 253 253 246 230 190
43284-238 204 91 238 204 91 181 142 44 37 26 9
43285- 2 2 6 2 2 6 2 2 6 2 2 6
43286- 2 2 6 2 2 6 38 38 38 46 46 46
43287- 26 26 26 106 106 106 54 54 54 18 18 18
43288- 6 6 6 0 0 0 0 0 0 0 0 0
43289- 0 0 0 0 0 0 0 0 0 0 0 0
43290- 0 0 0 0 0 0 0 0 0 0 0 0
43291- 0 0 0 0 0 0 0 0 0 0 0 0
43292- 0 0 0 0 0 0 0 0 0 0 0 0
43293- 0 0 0 6 6 6 14 14 14 22 22 22
43294- 30 30 30 38 38 38 50 50 50 70 70 70
43295-106 106 106 190 142 34 226 170 11 242 186 14
43296-246 190 14 246 190 14 246 190 14 154 114 10
43297- 6 6 6 74 74 74 226 226 226 253 253 253
43298-253 253 253 253 253 253 253 253 253 253 253 253
43299-253 253 253 253 253 253 231 231 231 250 250 250
43300-253 253 253 253 253 253 253 253 253 253 253 253
43301-253 253 253 253 253 253 253 253 253 253 253 253
43302-253 253 253 253 253 253 253 253 253 253 253 253
43303-253 253 253 253 253 253 253 253 253 228 184 62
43304-241 196 14 241 208 19 232 195 16 38 30 10
43305- 2 2 6 2 2 6 2 2 6 2 2 6
43306- 2 2 6 6 6 6 30 30 30 26 26 26
43307-203 166 17 154 142 90 66 66 66 26 26 26
43308- 6 6 6 0 0 0 0 0 0 0 0 0
43309- 0 0 0 0 0 0 0 0 0 0 0 0
43310- 0 0 0 0 0 0 0 0 0 0 0 0
43311- 0 0 0 0 0 0 0 0 0 0 0 0
43312- 0 0 0 0 0 0 0 0 0 0 0 0
43313- 6 6 6 18 18 18 38 38 38 58 58 58
43314- 78 78 78 86 86 86 101 101 101 123 123 123
43315-175 146 61 210 150 10 234 174 13 246 186 14
43316-246 190 14 246 190 14 246 190 14 238 190 10
43317-102 78 10 2 2 6 46 46 46 198 198 198
43318-253 253 253 253 253 253 253 253 253 253 253 253
43319-253 253 253 253 253 253 234 234 234 242 242 242
43320-253 253 253 253 253 253 253 253 253 253 253 253
43321-253 253 253 253 253 253 253 253 253 253 253 253
43322-253 253 253 253 253 253 253 253 253 253 253 253
43323-253 253 253 253 253 253 253 253 253 224 178 62
43324-242 186 14 241 196 14 210 166 10 22 18 6
43325- 2 2 6 2 2 6 2 2 6 2 2 6
43326- 2 2 6 2 2 6 6 6 6 121 92 8
43327-238 202 15 232 195 16 82 82 82 34 34 34
43328- 10 10 10 0 0 0 0 0 0 0 0 0
43329- 0 0 0 0 0 0 0 0 0 0 0 0
43330- 0 0 0 0 0 0 0 0 0 0 0 0
43331- 0 0 0 0 0 0 0 0 0 0 0 0
43332- 0 0 0 0 0 0 0 0 0 0 0 0
43333- 14 14 14 38 38 38 70 70 70 154 122 46
43334-190 142 34 200 144 11 197 138 11 197 138 11
43335-213 154 11 226 170 11 242 186 14 246 190 14
43336-246 190 14 246 190 14 246 190 14 246 190 14
43337-225 175 15 46 32 6 2 2 6 22 22 22
43338-158 158 158 250 250 250 253 253 253 253 253 253
43339-253 253 253 253 253 253 253 253 253 253 253 253
43340-253 253 253 253 253 253 253 253 253 253 253 253
43341-253 253 253 253 253 253 253 253 253 253 253 253
43342-253 253 253 253 253 253 253 253 253 253 253 253
43343-253 253 253 250 250 250 242 242 242 224 178 62
43344-239 182 13 236 186 11 213 154 11 46 32 6
43345- 2 2 6 2 2 6 2 2 6 2 2 6
43346- 2 2 6 2 2 6 61 42 6 225 175 15
43347-238 190 10 236 186 11 112 100 78 42 42 42
43348- 14 14 14 0 0 0 0 0 0 0 0 0
43349- 0 0 0 0 0 0 0 0 0 0 0 0
43350- 0 0 0 0 0 0 0 0 0 0 0 0
43351- 0 0 0 0 0 0 0 0 0 0 0 0
43352- 0 0 0 0 0 0 0 0 0 6 6 6
43353- 22 22 22 54 54 54 154 122 46 213 154 11
43354-226 170 11 230 174 11 226 170 11 226 170 11
43355-236 178 12 242 186 14 246 190 14 246 190 14
43356-246 190 14 246 190 14 246 190 14 246 190 14
43357-241 196 14 184 144 12 10 10 10 2 2 6
43358- 6 6 6 116 116 116 242 242 242 253 253 253
43359-253 253 253 253 253 253 253 253 253 253 253 253
43360-253 253 253 253 253 253 253 253 253 253 253 253
43361-253 253 253 253 253 253 253 253 253 253 253 253
43362-253 253 253 253 253 253 253 253 253 253 253 253
43363-253 253 253 231 231 231 198 198 198 214 170 54
43364-236 178 12 236 178 12 210 150 10 137 92 6
43365- 18 14 6 2 2 6 2 2 6 2 2 6
43366- 6 6 6 70 47 6 200 144 11 236 178 12
43367-239 182 13 239 182 13 124 112 88 58 58 58
43368- 22 22 22 6 6 6 0 0 0 0 0 0
43369- 0 0 0 0 0 0 0 0 0 0 0 0
43370- 0 0 0 0 0 0 0 0 0 0 0 0
43371- 0 0 0 0 0 0 0 0 0 0 0 0
43372- 0 0 0 0 0 0 0 0 0 10 10 10
43373- 30 30 30 70 70 70 180 133 36 226 170 11
43374-239 182 13 242 186 14 242 186 14 246 186 14
43375-246 190 14 246 190 14 246 190 14 246 190 14
43376-246 190 14 246 190 14 246 190 14 246 190 14
43377-246 190 14 232 195 16 98 70 6 2 2 6
43378- 2 2 6 2 2 6 66 66 66 221 221 221
43379-253 253 253 253 253 253 253 253 253 253 253 253
43380-253 253 253 253 253 253 253 253 253 253 253 253
43381-253 253 253 253 253 253 253 253 253 253 253 253
43382-253 253 253 253 253 253 253 253 253 253 253 253
43383-253 253 253 206 206 206 198 198 198 214 166 58
43384-230 174 11 230 174 11 216 158 10 192 133 9
43385-163 110 8 116 81 8 102 78 10 116 81 8
43386-167 114 7 197 138 11 226 170 11 239 182 13
43387-242 186 14 242 186 14 162 146 94 78 78 78
43388- 34 34 34 14 14 14 6 6 6 0 0 0
43389- 0 0 0 0 0 0 0 0 0 0 0 0
43390- 0 0 0 0 0 0 0 0 0 0 0 0
43391- 0 0 0 0 0 0 0 0 0 0 0 0
43392- 0 0 0 0 0 0 0 0 0 6 6 6
43393- 30 30 30 78 78 78 190 142 34 226 170 11
43394-239 182 13 246 190 14 246 190 14 246 190 14
43395-246 190 14 246 190 14 246 190 14 246 190 14
43396-246 190 14 246 190 14 246 190 14 246 190 14
43397-246 190 14 241 196 14 203 166 17 22 18 6
43398- 2 2 6 2 2 6 2 2 6 38 38 38
43399-218 218 218 253 253 253 253 253 253 253 253 253
43400-253 253 253 253 253 253 253 253 253 253 253 253
43401-253 253 253 253 253 253 253 253 253 253 253 253
43402-253 253 253 253 253 253 253 253 253 253 253 253
43403-250 250 250 206 206 206 198 198 198 202 162 69
43404-226 170 11 236 178 12 224 166 10 210 150 10
43405-200 144 11 197 138 11 192 133 9 197 138 11
43406-210 150 10 226 170 11 242 186 14 246 190 14
43407-246 190 14 246 186 14 225 175 15 124 112 88
43408- 62 62 62 30 30 30 14 14 14 6 6 6
43409- 0 0 0 0 0 0 0 0 0 0 0 0
43410- 0 0 0 0 0 0 0 0 0 0 0 0
43411- 0 0 0 0 0 0 0 0 0 0 0 0
43412- 0 0 0 0 0 0 0 0 0 10 10 10
43413- 30 30 30 78 78 78 174 135 50 224 166 10
43414-239 182 13 246 190 14 246 190 14 246 190 14
43415-246 190 14 246 190 14 246 190 14 246 190 14
43416-246 190 14 246 190 14 246 190 14 246 190 14
43417-246 190 14 246 190 14 241 196 14 139 102 15
43418- 2 2 6 2 2 6 2 2 6 2 2 6
43419- 78 78 78 250 250 250 253 253 253 253 253 253
43420-253 253 253 253 253 253 253 253 253 253 253 253
43421-253 253 253 253 253 253 253 253 253 253 253 253
43422-253 253 253 253 253 253 253 253 253 253 253 253
43423-250 250 250 214 214 214 198 198 198 190 150 46
43424-219 162 10 236 178 12 234 174 13 224 166 10
43425-216 158 10 213 154 11 213 154 11 216 158 10
43426-226 170 11 239 182 13 246 190 14 246 190 14
43427-246 190 14 246 190 14 242 186 14 206 162 42
43428-101 101 101 58 58 58 30 30 30 14 14 14
43429- 6 6 6 0 0 0 0 0 0 0 0 0
43430- 0 0 0 0 0 0 0 0 0 0 0 0
43431- 0 0 0 0 0 0 0 0 0 0 0 0
43432- 0 0 0 0 0 0 0 0 0 10 10 10
43433- 30 30 30 74 74 74 174 135 50 216 158 10
43434-236 178 12 246 190 14 246 190 14 246 190 14
43435-246 190 14 246 190 14 246 190 14 246 190 14
43436-246 190 14 246 190 14 246 190 14 246 190 14
43437-246 190 14 246 190 14 241 196 14 226 184 13
43438- 61 42 6 2 2 6 2 2 6 2 2 6
43439- 22 22 22 238 238 238 253 253 253 253 253 253
43440-253 253 253 253 253 253 253 253 253 253 253 253
43441-253 253 253 253 253 253 253 253 253 253 253 253
43442-253 253 253 253 253 253 253 253 253 253 253 253
43443-253 253 253 226 226 226 187 187 187 180 133 36
43444-216 158 10 236 178 12 239 182 13 236 178 12
43445-230 174 11 226 170 11 226 170 11 230 174 11
43446-236 178 12 242 186 14 246 190 14 246 190 14
43447-246 190 14 246 190 14 246 186 14 239 182 13
43448-206 162 42 106 106 106 66 66 66 34 34 34
43449- 14 14 14 6 6 6 0 0 0 0 0 0
43450- 0 0 0 0 0 0 0 0 0 0 0 0
43451- 0 0 0 0 0 0 0 0 0 0 0 0
43452- 0 0 0 0 0 0 0 0 0 6 6 6
43453- 26 26 26 70 70 70 163 133 67 213 154 11
43454-236 178 12 246 190 14 246 190 14 246 190 14
43455-246 190 14 246 190 14 246 190 14 246 190 14
43456-246 190 14 246 190 14 246 190 14 246 190 14
43457-246 190 14 246 190 14 246 190 14 241 196 14
43458-190 146 13 18 14 6 2 2 6 2 2 6
43459- 46 46 46 246 246 246 253 253 253 253 253 253
43460-253 253 253 253 253 253 253 253 253 253 253 253
43461-253 253 253 253 253 253 253 253 253 253 253 253
43462-253 253 253 253 253 253 253 253 253 253 253 253
43463-253 253 253 221 221 221 86 86 86 156 107 11
43464-216 158 10 236 178 12 242 186 14 246 186 14
43465-242 186 14 239 182 13 239 182 13 242 186 14
43466-242 186 14 246 186 14 246 190 14 246 190 14
43467-246 190 14 246 190 14 246 190 14 246 190 14
43468-242 186 14 225 175 15 142 122 72 66 66 66
43469- 30 30 30 10 10 10 0 0 0 0 0 0
43470- 0 0 0 0 0 0 0 0 0 0 0 0
43471- 0 0 0 0 0 0 0 0 0 0 0 0
43472- 0 0 0 0 0 0 0 0 0 6 6 6
43473- 26 26 26 70 70 70 163 133 67 210 150 10
43474-236 178 12 246 190 14 246 190 14 246 190 14
43475-246 190 14 246 190 14 246 190 14 246 190 14
43476-246 190 14 246 190 14 246 190 14 246 190 14
43477-246 190 14 246 190 14 246 190 14 246 190 14
43478-232 195 16 121 92 8 34 34 34 106 106 106
43479-221 221 221 253 253 253 253 253 253 253 253 253
43480-253 253 253 253 253 253 253 253 253 253 253 253
43481-253 253 253 253 253 253 253 253 253 253 253 253
43482-253 253 253 253 253 253 253 253 253 253 253 253
43483-242 242 242 82 82 82 18 14 6 163 110 8
43484-216 158 10 236 178 12 242 186 14 246 190 14
43485-246 190 14 246 190 14 246 190 14 246 190 14
43486-246 190 14 246 190 14 246 190 14 246 190 14
43487-246 190 14 246 190 14 246 190 14 246 190 14
43488-246 190 14 246 190 14 242 186 14 163 133 67
43489- 46 46 46 18 18 18 6 6 6 0 0 0
43490- 0 0 0 0 0 0 0 0 0 0 0 0
43491- 0 0 0 0 0 0 0 0 0 0 0 0
43492- 0 0 0 0 0 0 0 0 0 10 10 10
43493- 30 30 30 78 78 78 163 133 67 210 150 10
43494-236 178 12 246 186 14 246 190 14 246 190 14
43495-246 190 14 246 190 14 246 190 14 246 190 14
43496-246 190 14 246 190 14 246 190 14 246 190 14
43497-246 190 14 246 190 14 246 190 14 246 190 14
43498-241 196 14 215 174 15 190 178 144 253 253 253
43499-253 253 253 253 253 253 253 253 253 253 253 253
43500-253 253 253 253 253 253 253 253 253 253 253 253
43501-253 253 253 253 253 253 253 253 253 253 253 253
43502-253 253 253 253 253 253 253 253 253 218 218 218
43503- 58 58 58 2 2 6 22 18 6 167 114 7
43504-216 158 10 236 178 12 246 186 14 246 190 14
43505-246 190 14 246 190 14 246 190 14 246 190 14
43506-246 190 14 246 190 14 246 190 14 246 190 14
43507-246 190 14 246 190 14 246 190 14 246 190 14
43508-246 190 14 246 186 14 242 186 14 190 150 46
43509- 54 54 54 22 22 22 6 6 6 0 0 0
43510- 0 0 0 0 0 0 0 0 0 0 0 0
43511- 0 0 0 0 0 0 0 0 0 0 0 0
43512- 0 0 0 0 0 0 0 0 0 14 14 14
43513- 38 38 38 86 86 86 180 133 36 213 154 11
43514-236 178 12 246 186 14 246 190 14 246 190 14
43515-246 190 14 246 190 14 246 190 14 246 190 14
43516-246 190 14 246 190 14 246 190 14 246 190 14
43517-246 190 14 246 190 14 246 190 14 246 190 14
43518-246 190 14 232 195 16 190 146 13 214 214 214
43519-253 253 253 253 253 253 253 253 253 253 253 253
43520-253 253 253 253 253 253 253 253 253 253 253 253
43521-253 253 253 253 253 253 253 253 253 253 253 253
43522-253 253 253 250 250 250 170 170 170 26 26 26
43523- 2 2 6 2 2 6 37 26 9 163 110 8
43524-219 162 10 239 182 13 246 186 14 246 190 14
43525-246 190 14 246 190 14 246 190 14 246 190 14
43526-246 190 14 246 190 14 246 190 14 246 190 14
43527-246 190 14 246 190 14 246 190 14 246 190 14
43528-246 186 14 236 178 12 224 166 10 142 122 72
43529- 46 46 46 18 18 18 6 6 6 0 0 0
43530- 0 0 0 0 0 0 0 0 0 0 0 0
43531- 0 0 0 0 0 0 0 0 0 0 0 0
43532- 0 0 0 0 0 0 6 6 6 18 18 18
43533- 50 50 50 109 106 95 192 133 9 224 166 10
43534-242 186 14 246 190 14 246 190 14 246 190 14
43535-246 190 14 246 190 14 246 190 14 246 190 14
43536-246 190 14 246 190 14 246 190 14 246 190 14
43537-246 190 14 246 190 14 246 190 14 246 190 14
43538-242 186 14 226 184 13 210 162 10 142 110 46
43539-226 226 226 253 253 253 253 253 253 253 253 253
43540-253 253 253 253 253 253 253 253 253 253 253 253
43541-253 253 253 253 253 253 253 253 253 253 253 253
43542-198 198 198 66 66 66 2 2 6 2 2 6
43543- 2 2 6 2 2 6 50 34 6 156 107 11
43544-219 162 10 239 182 13 246 186 14 246 190 14
43545-246 190 14 246 190 14 246 190 14 246 190 14
43546-246 190 14 246 190 14 246 190 14 246 190 14
43547-246 190 14 246 190 14 246 190 14 242 186 14
43548-234 174 13 213 154 11 154 122 46 66 66 66
43549- 30 30 30 10 10 10 0 0 0 0 0 0
43550- 0 0 0 0 0 0 0 0 0 0 0 0
43551- 0 0 0 0 0 0 0 0 0 0 0 0
43552- 0 0 0 0 0 0 6 6 6 22 22 22
43553- 58 58 58 154 121 60 206 145 10 234 174 13
43554-242 186 14 246 186 14 246 190 14 246 190 14
43555-246 190 14 246 190 14 246 190 14 246 190 14
43556-246 190 14 246 190 14 246 190 14 246 190 14
43557-246 190 14 246 190 14 246 190 14 246 190 14
43558-246 186 14 236 178 12 210 162 10 163 110 8
43559- 61 42 6 138 138 138 218 218 218 250 250 250
43560-253 253 253 253 253 253 253 253 253 250 250 250
43561-242 242 242 210 210 210 144 144 144 66 66 66
43562- 6 6 6 2 2 6 2 2 6 2 2 6
43563- 2 2 6 2 2 6 61 42 6 163 110 8
43564-216 158 10 236 178 12 246 190 14 246 190 14
43565-246 190 14 246 190 14 246 190 14 246 190 14
43566-246 190 14 246 190 14 246 190 14 246 190 14
43567-246 190 14 239 182 13 230 174 11 216 158 10
43568-190 142 34 124 112 88 70 70 70 38 38 38
43569- 18 18 18 6 6 6 0 0 0 0 0 0
43570- 0 0 0 0 0 0 0 0 0 0 0 0
43571- 0 0 0 0 0 0 0 0 0 0 0 0
43572- 0 0 0 0 0 0 6 6 6 22 22 22
43573- 62 62 62 168 124 44 206 145 10 224 166 10
43574-236 178 12 239 182 13 242 186 14 242 186 14
43575-246 186 14 246 190 14 246 190 14 246 190 14
43576-246 190 14 246 190 14 246 190 14 246 190 14
43577-246 190 14 246 190 14 246 190 14 246 190 14
43578-246 190 14 236 178 12 216 158 10 175 118 6
43579- 80 54 7 2 2 6 6 6 6 30 30 30
43580- 54 54 54 62 62 62 50 50 50 38 38 38
43581- 14 14 14 2 2 6 2 2 6 2 2 6
43582- 2 2 6 2 2 6 2 2 6 2 2 6
43583- 2 2 6 6 6 6 80 54 7 167 114 7
43584-213 154 11 236 178 12 246 190 14 246 190 14
43585-246 190 14 246 190 14 246 190 14 246 190 14
43586-246 190 14 242 186 14 239 182 13 239 182 13
43587-230 174 11 210 150 10 174 135 50 124 112 88
43588- 82 82 82 54 54 54 34 34 34 18 18 18
43589- 6 6 6 0 0 0 0 0 0 0 0 0
43590- 0 0 0 0 0 0 0 0 0 0 0 0
43591- 0 0 0 0 0 0 0 0 0 0 0 0
43592- 0 0 0 0 0 0 6 6 6 18 18 18
43593- 50 50 50 158 118 36 192 133 9 200 144 11
43594-216 158 10 219 162 10 224 166 10 226 170 11
43595-230 174 11 236 178 12 239 182 13 239 182 13
43596-242 186 14 246 186 14 246 190 14 246 190 14
43597-246 190 14 246 190 14 246 190 14 246 190 14
43598-246 186 14 230 174 11 210 150 10 163 110 8
43599-104 69 6 10 10 10 2 2 6 2 2 6
43600- 2 2 6 2 2 6 2 2 6 2 2 6
43601- 2 2 6 2 2 6 2 2 6 2 2 6
43602- 2 2 6 2 2 6 2 2 6 2 2 6
43603- 2 2 6 6 6 6 91 60 6 167 114 7
43604-206 145 10 230 174 11 242 186 14 246 190 14
43605-246 190 14 246 190 14 246 186 14 242 186 14
43606-239 182 13 230 174 11 224 166 10 213 154 11
43607-180 133 36 124 112 88 86 86 86 58 58 58
43608- 38 38 38 22 22 22 10 10 10 6 6 6
43609- 0 0 0 0 0 0 0 0 0 0 0 0
43610- 0 0 0 0 0 0 0 0 0 0 0 0
43611- 0 0 0 0 0 0 0 0 0 0 0 0
43612- 0 0 0 0 0 0 0 0 0 14 14 14
43613- 34 34 34 70 70 70 138 110 50 158 118 36
43614-167 114 7 180 123 7 192 133 9 197 138 11
43615-200 144 11 206 145 10 213 154 11 219 162 10
43616-224 166 10 230 174 11 239 182 13 242 186 14
43617-246 186 14 246 186 14 246 186 14 246 186 14
43618-239 182 13 216 158 10 185 133 11 152 99 6
43619-104 69 6 18 14 6 2 2 6 2 2 6
43620- 2 2 6 2 2 6 2 2 6 2 2 6
43621- 2 2 6 2 2 6 2 2 6 2 2 6
43622- 2 2 6 2 2 6 2 2 6 2 2 6
43623- 2 2 6 6 6 6 80 54 7 152 99 6
43624-192 133 9 219 162 10 236 178 12 239 182 13
43625-246 186 14 242 186 14 239 182 13 236 178 12
43626-224 166 10 206 145 10 192 133 9 154 121 60
43627- 94 94 94 62 62 62 42 42 42 22 22 22
43628- 14 14 14 6 6 6 0 0 0 0 0 0
43629- 0 0 0 0 0 0 0 0 0 0 0 0
43630- 0 0 0 0 0 0 0 0 0 0 0 0
43631- 0 0 0 0 0 0 0 0 0 0 0 0
43632- 0 0 0 0 0 0 0 0 0 6 6 6
43633- 18 18 18 34 34 34 58 58 58 78 78 78
43634-101 98 89 124 112 88 142 110 46 156 107 11
43635-163 110 8 167 114 7 175 118 6 180 123 7
43636-185 133 11 197 138 11 210 150 10 219 162 10
43637-226 170 11 236 178 12 236 178 12 234 174 13
43638-219 162 10 197 138 11 163 110 8 130 83 6
43639- 91 60 6 10 10 10 2 2 6 2 2 6
43640- 18 18 18 38 38 38 38 38 38 38 38 38
43641- 38 38 38 38 38 38 38 38 38 38 38 38
43642- 38 38 38 38 38 38 26 26 26 2 2 6
43643- 2 2 6 6 6 6 70 47 6 137 92 6
43644-175 118 6 200 144 11 219 162 10 230 174 11
43645-234 174 13 230 174 11 219 162 10 210 150 10
43646-192 133 9 163 110 8 124 112 88 82 82 82
43647- 50 50 50 30 30 30 14 14 14 6 6 6
43648- 0 0 0 0 0 0 0 0 0 0 0 0
43649- 0 0 0 0 0 0 0 0 0 0 0 0
43650- 0 0 0 0 0 0 0 0 0 0 0 0
43651- 0 0 0 0 0 0 0 0 0 0 0 0
43652- 0 0 0 0 0 0 0 0 0 0 0 0
43653- 6 6 6 14 14 14 22 22 22 34 34 34
43654- 42 42 42 58 58 58 74 74 74 86 86 86
43655-101 98 89 122 102 70 130 98 46 121 87 25
43656-137 92 6 152 99 6 163 110 8 180 123 7
43657-185 133 11 197 138 11 206 145 10 200 144 11
43658-180 123 7 156 107 11 130 83 6 104 69 6
43659- 50 34 6 54 54 54 110 110 110 101 98 89
43660- 86 86 86 82 82 82 78 78 78 78 78 78
43661- 78 78 78 78 78 78 78 78 78 78 78 78
43662- 78 78 78 82 82 82 86 86 86 94 94 94
43663-106 106 106 101 101 101 86 66 34 124 80 6
43664-156 107 11 180 123 7 192 133 9 200 144 11
43665-206 145 10 200 144 11 192 133 9 175 118 6
43666-139 102 15 109 106 95 70 70 70 42 42 42
43667- 22 22 22 10 10 10 0 0 0 0 0 0
43668- 0 0 0 0 0 0 0 0 0 0 0 0
43669- 0 0 0 0 0 0 0 0 0 0 0 0
43670- 0 0 0 0 0 0 0 0 0 0 0 0
43671- 0 0 0 0 0 0 0 0 0 0 0 0
43672- 0 0 0 0 0 0 0 0 0 0 0 0
43673- 0 0 0 0 0 0 6 6 6 10 10 10
43674- 14 14 14 22 22 22 30 30 30 38 38 38
43675- 50 50 50 62 62 62 74 74 74 90 90 90
43676-101 98 89 112 100 78 121 87 25 124 80 6
43677-137 92 6 152 99 6 152 99 6 152 99 6
43678-138 86 6 124 80 6 98 70 6 86 66 30
43679-101 98 89 82 82 82 58 58 58 46 46 46
43680- 38 38 38 34 34 34 34 34 34 34 34 34
43681- 34 34 34 34 34 34 34 34 34 34 34 34
43682- 34 34 34 34 34 34 38 38 38 42 42 42
43683- 54 54 54 82 82 82 94 86 76 91 60 6
43684-134 86 6 156 107 11 167 114 7 175 118 6
43685-175 118 6 167 114 7 152 99 6 121 87 25
43686-101 98 89 62 62 62 34 34 34 18 18 18
43687- 6 6 6 0 0 0 0 0 0 0 0 0
43688- 0 0 0 0 0 0 0 0 0 0 0 0
43689- 0 0 0 0 0 0 0 0 0 0 0 0
43690- 0 0 0 0 0 0 0 0 0 0 0 0
43691- 0 0 0 0 0 0 0 0 0 0 0 0
43692- 0 0 0 0 0 0 0 0 0 0 0 0
43693- 0 0 0 0 0 0 0 0 0 0 0 0
43694- 0 0 0 6 6 6 6 6 6 10 10 10
43695- 18 18 18 22 22 22 30 30 30 42 42 42
43696- 50 50 50 66 66 66 86 86 86 101 98 89
43697-106 86 58 98 70 6 104 69 6 104 69 6
43698-104 69 6 91 60 6 82 62 34 90 90 90
43699- 62 62 62 38 38 38 22 22 22 14 14 14
43700- 10 10 10 10 10 10 10 10 10 10 10 10
43701- 10 10 10 10 10 10 6 6 6 10 10 10
43702- 10 10 10 10 10 10 10 10 10 14 14 14
43703- 22 22 22 42 42 42 70 70 70 89 81 66
43704- 80 54 7 104 69 6 124 80 6 137 92 6
43705-134 86 6 116 81 8 100 82 52 86 86 86
43706- 58 58 58 30 30 30 14 14 14 6 6 6
43707- 0 0 0 0 0 0 0 0 0 0 0 0
43708- 0 0 0 0 0 0 0 0 0 0 0 0
43709- 0 0 0 0 0 0 0 0 0 0 0 0
43710- 0 0 0 0 0 0 0 0 0 0 0 0
43711- 0 0 0 0 0 0 0 0 0 0 0 0
43712- 0 0 0 0 0 0 0 0 0 0 0 0
43713- 0 0 0 0 0 0 0 0 0 0 0 0
43714- 0 0 0 0 0 0 0 0 0 0 0 0
43715- 0 0 0 6 6 6 10 10 10 14 14 14
43716- 18 18 18 26 26 26 38 38 38 54 54 54
43717- 70 70 70 86 86 86 94 86 76 89 81 66
43718- 89 81 66 86 86 86 74 74 74 50 50 50
43719- 30 30 30 14 14 14 6 6 6 0 0 0
43720- 0 0 0 0 0 0 0 0 0 0 0 0
43721- 0 0 0 0 0 0 0 0 0 0 0 0
43722- 0 0 0 0 0 0 0 0 0 0 0 0
43723- 6 6 6 18 18 18 34 34 34 58 58 58
43724- 82 82 82 89 81 66 89 81 66 89 81 66
43725- 94 86 66 94 86 76 74 74 74 50 50 50
43726- 26 26 26 14 14 14 6 6 6 0 0 0
43727- 0 0 0 0 0 0 0 0 0 0 0 0
43728- 0 0 0 0 0 0 0 0 0 0 0 0
43729- 0 0 0 0 0 0 0 0 0 0 0 0
43730- 0 0 0 0 0 0 0 0 0 0 0 0
43731- 0 0 0 0 0 0 0 0 0 0 0 0
43732- 0 0 0 0 0 0 0 0 0 0 0 0
43733- 0 0 0 0 0 0 0 0 0 0 0 0
43734- 0 0 0 0 0 0 0 0 0 0 0 0
43735- 0 0 0 0 0 0 0 0 0 0 0 0
43736- 6 6 6 6 6 6 14 14 14 18 18 18
43737- 30 30 30 38 38 38 46 46 46 54 54 54
43738- 50 50 50 42 42 42 30 30 30 18 18 18
43739- 10 10 10 0 0 0 0 0 0 0 0 0
43740- 0 0 0 0 0 0 0 0 0 0 0 0
43741- 0 0 0 0 0 0 0 0 0 0 0 0
43742- 0 0 0 0 0 0 0 0 0 0 0 0
43743- 0 0 0 6 6 6 14 14 14 26 26 26
43744- 38 38 38 50 50 50 58 58 58 58 58 58
43745- 54 54 54 42 42 42 30 30 30 18 18 18
43746- 10 10 10 0 0 0 0 0 0 0 0 0
43747- 0 0 0 0 0 0 0 0 0 0 0 0
43748- 0 0 0 0 0 0 0 0 0 0 0 0
43749- 0 0 0 0 0 0 0 0 0 0 0 0
43750- 0 0 0 0 0 0 0 0 0 0 0 0
43751- 0 0 0 0 0 0 0 0 0 0 0 0
43752- 0 0 0 0 0 0 0 0 0 0 0 0
43753- 0 0 0 0 0 0 0 0 0 0 0 0
43754- 0 0 0 0 0 0 0 0 0 0 0 0
43755- 0 0 0 0 0 0 0 0 0 0 0 0
43756- 0 0 0 0 0 0 0 0 0 6 6 6
43757- 6 6 6 10 10 10 14 14 14 18 18 18
43758- 18 18 18 14 14 14 10 10 10 6 6 6
43759- 0 0 0 0 0 0 0 0 0 0 0 0
43760- 0 0 0 0 0 0 0 0 0 0 0 0
43761- 0 0 0 0 0 0 0 0 0 0 0 0
43762- 0 0 0 0 0 0 0 0 0 0 0 0
43763- 0 0 0 0 0 0 0 0 0 6 6 6
43764- 14 14 14 18 18 18 22 22 22 22 22 22
43765- 18 18 18 14 14 14 10 10 10 6 6 6
43766- 0 0 0 0 0 0 0 0 0 0 0 0
43767- 0 0 0 0 0 0 0 0 0 0 0 0
43768- 0 0 0 0 0 0 0 0 0 0 0 0
43769- 0 0 0 0 0 0 0 0 0 0 0 0
43770- 0 0 0 0 0 0 0 0 0 0 0 0
43771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43772+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43774+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43775+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43784+4 4 4 4 4 4
43785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43786+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43788+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43789+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43794+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43798+4 4 4 4 4 4
43799+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43800+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43801+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43802+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43803+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43806+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43807+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43808+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43809+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43811+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43812+4 4 4 4 4 4
43813+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43814+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43815+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43816+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43817+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43820+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43821+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43822+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43823+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43825+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43826+4 4 4 4 4 4
43827+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43828+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43829+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43830+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43831+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43834+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43835+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43836+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43837+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43838+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43839+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43840+4 4 4 4 4 4
43841+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43842+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43843+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43844+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43845+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43846+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43848+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43849+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43850+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43851+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43852+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43853+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43854+4 4 4 4 4 4
43855+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43856+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43857+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43858+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43859+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
43860+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
43861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43862+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43863+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43864+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
43865+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
43866+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
43867+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43868+4 4 4 4 4 4
43869+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43870+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43871+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43872+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43873+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
43874+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
43875+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43876+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43877+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43878+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
43879+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
43880+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
43881+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43882+4 4 4 4 4 4
43883+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43884+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43885+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43886+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43887+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
43888+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
43889+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
43890+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43891+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43892+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
43893+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
43894+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
43895+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
43896+4 4 4 4 4 4
43897+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43898+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43899+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43900+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
43901+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
43902+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
43903+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
43904+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43905+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
43906+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
43907+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
43908+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
43909+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
43910+4 4 4 4 4 4
43911+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43912+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43913+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43914+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
43915+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
43916+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
43917+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
43918+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43919+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
43920+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
43921+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
43922+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
43923+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
43924+4 4 4 4 4 4
43925+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43926+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43927+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43928+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
43929+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
43930+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
43931+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
43932+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
43933+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
43934+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
43935+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
43936+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
43937+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
43938+4 4 4 4 4 4
43939+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43940+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43941+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
43942+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
43943+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
43944+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
43945+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
43946+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
43947+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
43948+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
43949+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
43950+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
43951+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
43952+4 4 4 4 4 4
43953+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43954+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43955+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
43956+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
43957+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
43958+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
43959+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
43960+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
43961+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
43962+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
43963+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
43964+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
43965+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
43966+4 4 4 4 4 4
43967+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43968+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43969+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
43970+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
43971+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
43972+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
43973+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
43974+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
43975+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
43976+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
43977+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
43978+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
43979+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
43980+4 4 4 4 4 4
43981+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43982+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43983+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
43984+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
43985+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
43986+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
43987+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
43988+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
43989+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
43990+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
43991+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
43992+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
43993+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
43994+4 4 4 4 4 4
43995+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43996+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
43997+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
43998+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
43999+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
44000+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
44001+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
44002+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
44003+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
44004+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
44005+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
44006+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
44007+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
44008+4 4 4 4 4 4
44009+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44010+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
44011+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
44012+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
44013+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
44014+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
44015+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
44016+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
44017+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
44018+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
44019+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
44020+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
44021+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
44022+0 0 0 4 4 4
44023+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
44024+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
44025+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
44026+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
44027+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
44028+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
44029+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
44030+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
44031+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
44032+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
44033+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
44034+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
44035+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
44036+2 0 0 0 0 0
44037+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
44038+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
44039+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
44040+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
44041+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
44042+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
44043+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
44044+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
44045+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
44046+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
44047+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
44048+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
44049+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
44050+37 38 37 0 0 0
44051+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
44052+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
44053+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
44054+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
44055+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
44056+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
44057+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
44058+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
44059+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
44060+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
44061+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
44062+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
44063+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
44064+85 115 134 4 0 0
44065+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
44066+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
44067+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
44068+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
44069+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
44070+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
44071+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
44072+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
44073+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
44074+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
44075+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
44076+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
44077+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
44078+60 73 81 4 0 0
44079+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
44080+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
44081+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
44082+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
44083+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
44084+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
44085+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
44086+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
44087+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
44088+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
44089+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
44090+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
44091+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
44092+16 19 21 4 0 0
44093+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
44094+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
44095+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
44096+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
44097+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
44098+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
44099+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
44100+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
44101+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
44102+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
44103+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
44104+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
44105+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
44106+4 0 0 4 3 3
44107+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
44108+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
44109+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
44110+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
44111+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
44112+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
44113+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
44114+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
44115+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
44116+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
44117+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
44118+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
44119+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
44120+3 2 2 4 4 4
44121+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
44122+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
44123+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
44124+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
44125+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
44126+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
44127+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
44128+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
44129+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
44130+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
44131+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
44132+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
44133+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
44134+4 4 4 4 4 4
44135+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
44136+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
44137+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
44138+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
44139+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
44140+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
44141+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
44142+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
44143+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
44144+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
44145+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
44146+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
44147+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
44148+4 4 4 4 4 4
44149+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
44150+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
44151+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
44152+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
44153+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
44154+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
44155+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
44156+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
44157+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
44158+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
44159+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
44160+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
44161+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
44162+5 5 5 5 5 5
44163+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
44164+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
44165+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
44166+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
44167+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
44168+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44169+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
44170+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
44171+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
44172+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
44173+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
44174+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
44175+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
44176+5 5 5 4 4 4
44177+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
44178+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
44179+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
44180+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
44181+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
44182+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
44183+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
44184+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
44185+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
44186+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
44187+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
44188+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
44189+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44190+4 4 4 4 4 4
44191+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
44192+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
44193+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
44194+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
44195+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
44196+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44197+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44198+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
44199+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
44200+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
44201+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
44202+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
44203+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44204+4 4 4 4 4 4
44205+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
44206+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
44207+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
44208+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
44209+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
44210+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
44211+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
44212+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
44213+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
44214+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
44215+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
44216+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44217+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44218+4 4 4 4 4 4
44219+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
44220+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
44221+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
44222+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
44223+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
44224+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44225+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44226+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
44227+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
44228+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
44229+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
44230+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44231+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44232+4 4 4 4 4 4
44233+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
44234+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
44235+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
44236+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
44237+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
44238+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
44239+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
44240+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
44241+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
44242+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
44243+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44244+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44245+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44246+4 4 4 4 4 4
44247+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
44248+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
44249+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
44250+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
44251+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
44252+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
44253+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
44254+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
44255+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
44256+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
44257+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
44258+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44259+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44260+4 4 4 4 4 4
44261+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
44262+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
44263+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
44264+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
44265+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
44266+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
44267+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
44268+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
44269+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
44270+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
44271+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
44272+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44273+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44274+4 4 4 4 4 4
44275+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
44276+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
44277+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
44278+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
44279+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
44280+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
44281+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
44282+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
44283+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
44284+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
44285+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44286+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44287+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44288+4 4 4 4 4 4
44289+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
44290+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
44291+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
44292+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
44293+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44294+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
44295+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
44296+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
44297+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
44298+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
44299+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44300+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44301+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44302+4 4 4 4 4 4
44303+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
44304+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
44305+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
44306+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
44307+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44308+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
44309+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
44310+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
44311+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
44312+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
44313+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44314+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44315+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44316+4 4 4 4 4 4
44317+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
44318+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
44319+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
44320+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
44321+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44322+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
44323+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
44324+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
44325+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
44326+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44327+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44328+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44329+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44330+4 4 4 4 4 4
44331+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
44332+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
44333+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
44334+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
44335+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
44336+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
44337+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
44338+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
44339+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
44340+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44341+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44342+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44343+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44344+4 4 4 4 4 4
44345+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
44346+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
44347+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
44348+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
44349+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44350+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
44351+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
44352+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
44353+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
44354+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44355+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44356+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44357+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44358+4 4 4 4 4 4
44359+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
44360+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
44361+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
44362+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
44363+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
44364+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
44365+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
44366+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
44367+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
44368+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44369+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44370+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44371+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44372+4 4 4 4 4 4
44373+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
44374+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
44375+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
44376+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
44377+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
44378+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
44379+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
44380+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
44381+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
44382+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44383+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44384+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44385+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44386+4 4 4 4 4 4
44387+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
44388+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
44389+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
44390+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
44391+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
44392+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
44393+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
44394+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
44395+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
44396+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44397+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44398+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44399+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44400+4 4 4 4 4 4
44401+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
44402+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
44403+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
44404+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
44405+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
44406+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
44407+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
44408+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
44409+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
44410+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44411+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44412+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44413+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44414+4 4 4 4 4 4
44415+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
44416+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
44417+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
44418+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
44419+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
44420+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
44421+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
44422+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
44423+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
44424+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44425+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44426+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44427+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44428+4 4 4 4 4 4
44429+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
44430+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
44431+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
44432+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
44433+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
44434+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
44435+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
44436+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
44437+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
44438+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44439+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44440+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44441+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44442+4 4 4 4 4 4
44443+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
44444+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
44445+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
44446+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
44447+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
44448+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
44449+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44450+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
44451+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
44452+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44453+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44454+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44455+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44456+4 4 4 4 4 4
44457+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
44458+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
44459+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
44460+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
44461+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
44462+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
44463+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44464+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
44465+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
44466+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44467+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44468+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44469+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44470+4 4 4 4 4 4
44471+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
44472+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
44473+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
44474+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
44475+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
44476+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
44477+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
44478+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
44479+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
44480+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44481+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44482+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44483+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44484+4 4 4 4 4 4
44485+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
44486+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
44487+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
44488+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
44489+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
44490+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
44491+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
44492+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
44493+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
44494+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44495+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44496+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44497+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44498+4 4 4 4 4 4
44499+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
44500+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
44501+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
44502+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
44503+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
44504+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
44505+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
44506+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
44507+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
44508+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44509+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44510+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44511+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44512+4 4 4 4 4 4
44513+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
44514+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
44515+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
44516+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
44517+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
44518+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
44519+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
44520+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
44521+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
44522+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44523+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44524+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44525+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44526+4 4 4 4 4 4
44527+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
44528+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
44529+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
44530+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
44531+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
44532+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
44533+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
44534+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
44535+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
44536+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
44537+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44538+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44539+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44540+4 4 4 4 4 4
44541+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
44542+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
44543+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
44544+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
44545+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
44546+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
44547+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
44548+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
44549+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
44550+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
44551+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44552+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44553+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44554+4 4 4 4 4 4
44555+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
44556+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
44557+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
44558+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
44559+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
44560+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
44561+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44562+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
44563+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
44564+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
44565+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
44566+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44567+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44568+4 4 4 4 4 4
44569+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
44570+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
44571+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
44572+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
44573+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
44574+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
44575+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
44576+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
44577+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
44578+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
44579+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44580+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44581+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44582+4 4 4 4 4 4
44583+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
44584+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
44585+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
44586+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
44587+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
44588+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
44589+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
44590+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
44591+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
44592+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
44593+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44594+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44595+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44596+4 4 4 4 4 4
44597+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
44598+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
44599+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
44600+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
44601+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
44602+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
44603+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
44604+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
44605+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
44606+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
44607+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44608+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44609+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44610+4 4 4 4 4 4
44611+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
44612+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
44613+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
44614+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
44615+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
44616+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
44617+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
44618+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
44619+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
44620+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
44621+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44622+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44623+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44624+4 4 4 4 4 4
44625+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
44626+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
44627+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
44628+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
44629+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
44630+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
44631+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
44632+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
44633+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
44634+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
44635+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44636+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44637+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44638+4 4 4 4 4 4
44639+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
44640+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
44641+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
44642+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
44643+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
44644+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
44645+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
44646+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
44647+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
44648+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44649+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44650+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44651+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44652+4 4 4 4 4 4
44653+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
44654+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
44655+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
44656+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
44657+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
44658+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
44659+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
44660+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
44661+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
44662+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44663+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44664+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
44667+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
44668+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
44669+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
44670+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
44671+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
44672+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
44673+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
44674+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
44675+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44676+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44677+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
44681+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
44682+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
44683+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
44684+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
44685+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
44686+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
44687+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
44688+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
44689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44691+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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
44695+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
44696+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
44697+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
44698+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
44699+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
44700+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
44701+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
44702+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
44703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44705+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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
44709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
44710+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
44711+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
44712+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
44713+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
44714+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
44715+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
44716+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
44717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44719+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44720+4 4 4 4 4 4 4 4 4 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
44723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44724+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
44725+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
44726+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
44727+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
44728+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
44729+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
44730+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
44731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44733+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44734+4 4 4 4 4 4 4 4 4 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
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 5 5 5 5 5 5 5 5 5
44739+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
44740+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
44741+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
44742+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
44743+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
44744+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
44745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44747+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44748+4 4 4 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
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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
44754+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
44755+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
44756+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
44757+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
44758+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
44759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44761+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
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 5 5 5
44768+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
44769+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
44770+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
44771+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
44772+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44774+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44775+4 4 4 4 4 4 4 4 4 4 4 4 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
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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
44783+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
44784+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
44785+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
44786+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44788+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44789+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44792+4 4 4 4 4 4
44793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44794+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44796+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
44797+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
44798+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
44799+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
44800+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44801+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44802+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44803+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44806+4 4 4 4 4 4
44807+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44808+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44809+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44810+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
44811+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
44812+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
44813+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
44814+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44815+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44816+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44817+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44820+4 4 4 4 4 4
44821+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44822+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44823+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
44825+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
44826+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
44827+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44828+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44829+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44830+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44831+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44834+4 4 4 4 4 4
44835+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44836+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44837+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44838+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44839+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
44840+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
44841+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
44842+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44843+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44844+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44845+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44846+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44848+4 4 4 4 4 4
44849+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44850+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44851+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44852+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44853+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
44854+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
44855+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44856+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44857+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44858+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44859+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44860+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44862+4 4 4 4 4 4
44863+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44864+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44865+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44866+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44867+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
44868+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
44869+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44870+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44871+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44872+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44873+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44874+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44875+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44876+4 4 4 4 4 4
44877+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44878+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44879+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44880+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44881+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
44882+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
44883+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44884+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44885+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44886+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44887+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44888+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44889+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44890+4 4 4 4 4 4
44891diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
44892index 86d449e..af6a7f7 100644
44893--- a/drivers/video/udlfb.c
44894+++ b/drivers/video/udlfb.c
44895@@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
44896 dlfb_urb_completion(urb);
44897
44898 error:
44899- atomic_add(bytes_sent, &dev->bytes_sent);
44900- atomic_add(bytes_identical, &dev->bytes_identical);
44901- atomic_add(width*height*2, &dev->bytes_rendered);
44902+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
44903+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
44904+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
44905 end_cycles = get_cycles();
44906- atomic_add(((unsigned int) ((end_cycles - start_cycles)
44907+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
44908 >> 10)), /* Kcycles */
44909 &dev->cpu_kcycles_used);
44910
44911@@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
44912 dlfb_urb_completion(urb);
44913
44914 error:
44915- atomic_add(bytes_sent, &dev->bytes_sent);
44916- atomic_add(bytes_identical, &dev->bytes_identical);
44917- atomic_add(bytes_rendered, &dev->bytes_rendered);
44918+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
44919+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
44920+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
44921 end_cycles = get_cycles();
44922- atomic_add(((unsigned int) ((end_cycles - start_cycles)
44923+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
44924 >> 10)), /* Kcycles */
44925 &dev->cpu_kcycles_used);
44926 }
44927@@ -1372,7 +1372,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
44928 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44929 struct dlfb_data *dev = fb_info->par;
44930 return snprintf(buf, PAGE_SIZE, "%u\n",
44931- atomic_read(&dev->bytes_rendered));
44932+ atomic_read_unchecked(&dev->bytes_rendered));
44933 }
44934
44935 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
44936@@ -1380,7 +1380,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
44937 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44938 struct dlfb_data *dev = fb_info->par;
44939 return snprintf(buf, PAGE_SIZE, "%u\n",
44940- atomic_read(&dev->bytes_identical));
44941+ atomic_read_unchecked(&dev->bytes_identical));
44942 }
44943
44944 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
44945@@ -1388,7 +1388,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
44946 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44947 struct dlfb_data *dev = fb_info->par;
44948 return snprintf(buf, PAGE_SIZE, "%u\n",
44949- atomic_read(&dev->bytes_sent));
44950+ atomic_read_unchecked(&dev->bytes_sent));
44951 }
44952
44953 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
44954@@ -1396,7 +1396,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
44955 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44956 struct dlfb_data *dev = fb_info->par;
44957 return snprintf(buf, PAGE_SIZE, "%u\n",
44958- atomic_read(&dev->cpu_kcycles_used));
44959+ atomic_read_unchecked(&dev->cpu_kcycles_used));
44960 }
44961
44962 static ssize_t edid_show(
44963@@ -1456,10 +1456,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
44964 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44965 struct dlfb_data *dev = fb_info->par;
44966
44967- atomic_set(&dev->bytes_rendered, 0);
44968- atomic_set(&dev->bytes_identical, 0);
44969- atomic_set(&dev->bytes_sent, 0);
44970- atomic_set(&dev->cpu_kcycles_used, 0);
44971+ atomic_set_unchecked(&dev->bytes_rendered, 0);
44972+ atomic_set_unchecked(&dev->bytes_identical, 0);
44973+ atomic_set_unchecked(&dev->bytes_sent, 0);
44974+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
44975
44976 return count;
44977 }
44978diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
44979index b75db01..5631c6d 100644
44980--- a/drivers/video/uvesafb.c
44981+++ b/drivers/video/uvesafb.c
44982@@ -19,6 +19,7 @@
44983 #include <linux/io.h>
44984 #include <linux/mutex.h>
44985 #include <linux/slab.h>
44986+#include <linux/moduleloader.h>
44987 #include <video/edid.h>
44988 #include <video/uvesafb.h>
44989 #ifdef CONFIG_X86
44990@@ -569,10 +570,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
44991 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
44992 par->pmi_setpal = par->ypan = 0;
44993 } else {
44994+
44995+#ifdef CONFIG_PAX_KERNEXEC
44996+#ifdef CONFIG_MODULES
44997+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
44998+#endif
44999+ if (!par->pmi_code) {
45000+ par->pmi_setpal = par->ypan = 0;
45001+ return 0;
45002+ }
45003+#endif
45004+
45005 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
45006 + task->t.regs.edi);
45007+
45008+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45009+ pax_open_kernel();
45010+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
45011+ pax_close_kernel();
45012+
45013+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
45014+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
45015+#else
45016 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
45017 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
45018+#endif
45019+
45020 printk(KERN_INFO "uvesafb: protected mode interface info at "
45021 "%04x:%04x\n",
45022 (u16)task->t.regs.es, (u16)task->t.regs.edi);
45023@@ -817,13 +840,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
45024 par->ypan = ypan;
45025
45026 if (par->pmi_setpal || par->ypan) {
45027+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
45028 if (__supported_pte_mask & _PAGE_NX) {
45029 par->pmi_setpal = par->ypan = 0;
45030 printk(KERN_WARNING "uvesafb: NX protection is actively."
45031 "We have better not to use the PMI.\n");
45032- } else {
45033+ } else
45034+#endif
45035 uvesafb_vbe_getpmi(task, par);
45036- }
45037 }
45038 #else
45039 /* The protected mode interface is not available on non-x86. */
45040@@ -1836,6 +1860,11 @@ out:
45041 if (par->vbe_modes)
45042 kfree(par->vbe_modes);
45043
45044+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45045+ if (par->pmi_code)
45046+ module_free_exec(NULL, par->pmi_code);
45047+#endif
45048+
45049 framebuffer_release(info);
45050 return err;
45051 }
45052@@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
45053 kfree(par->vbe_state_orig);
45054 if (par->vbe_state_saved)
45055 kfree(par->vbe_state_saved);
45056+
45057+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45058+ if (par->pmi_code)
45059+ module_free_exec(NULL, par->pmi_code);
45060+#endif
45061+
45062 }
45063
45064 framebuffer_release(info);
45065diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
45066index 501b340..86bd4cf 100644
45067--- a/drivers/video/vesafb.c
45068+++ b/drivers/video/vesafb.c
45069@@ -9,6 +9,7 @@
45070 */
45071
45072 #include <linux/module.h>
45073+#include <linux/moduleloader.h>
45074 #include <linux/kernel.h>
45075 #include <linux/errno.h>
45076 #include <linux/string.h>
45077@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
45078 static int vram_total __initdata; /* Set total amount of memory */
45079 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
45080 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
45081-static void (*pmi_start)(void) __read_mostly;
45082-static void (*pmi_pal) (void) __read_mostly;
45083+static void (*pmi_start)(void) __read_only;
45084+static void (*pmi_pal) (void) __read_only;
45085 static int depth __read_mostly;
45086 static int vga_compat __read_mostly;
45087 /* --------------------------------------------------------------------- */
45088@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
45089 unsigned int size_vmode;
45090 unsigned int size_remap;
45091 unsigned int size_total;
45092+ void *pmi_code = NULL;
45093
45094 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
45095 return -ENODEV;
45096@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
45097 size_remap = size_total;
45098 vesafb_fix.smem_len = size_remap;
45099
45100-#ifndef __i386__
45101- screen_info.vesapm_seg = 0;
45102-#endif
45103-
45104 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
45105 printk(KERN_WARNING
45106 "vesafb: cannot reserve video memory at 0x%lx\n",
45107@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
45108 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
45109 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
45110
45111+#ifdef __i386__
45112+
45113+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45114+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
45115+ if (!pmi_code)
45116+#elif !defined(CONFIG_PAX_KERNEXEC)
45117+ if (0)
45118+#endif
45119+
45120+#endif
45121+ screen_info.vesapm_seg = 0;
45122+
45123 if (screen_info.vesapm_seg) {
45124- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
45125- screen_info.vesapm_seg,screen_info.vesapm_off);
45126+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
45127+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
45128 }
45129
45130 if (screen_info.vesapm_seg < 0xc000)
45131@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
45132
45133 if (ypan || pmi_setpal) {
45134 unsigned short *pmi_base;
45135+
45136 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
45137- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
45138- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
45139+
45140+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45141+ pax_open_kernel();
45142+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
45143+#else
45144+ pmi_code = pmi_base;
45145+#endif
45146+
45147+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
45148+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
45149+
45150+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45151+ pmi_start = ktva_ktla(pmi_start);
45152+ pmi_pal = ktva_ktla(pmi_pal);
45153+ pax_close_kernel();
45154+#endif
45155+
45156 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
45157 if (pmi_base[3]) {
45158 printk(KERN_INFO "vesafb: pmi: ports = ");
45159@@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
45160 info->node, info->fix.id);
45161 return 0;
45162 err:
45163+
45164+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45165+ module_free_exec(NULL, pmi_code);
45166+#endif
45167+
45168 if (info->screen_base)
45169 iounmap(info->screen_base);
45170 framebuffer_release(info);
45171diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
45172index 88714ae..16c2e11 100644
45173--- a/drivers/video/via/via_clock.h
45174+++ b/drivers/video/via/via_clock.h
45175@@ -56,7 +56,7 @@ struct via_clock {
45176
45177 void (*set_engine_pll_state)(u8 state);
45178 void (*set_engine_pll)(struct via_pll_config config);
45179-};
45180+} __no_const;
45181
45182
45183 static inline u32 get_pll_internal_frequency(u32 ref_freq,
45184diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
45185index fef20db..d28b1ab 100644
45186--- a/drivers/xen/xenfs/xenstored.c
45187+++ b/drivers/xen/xenfs/xenstored.c
45188@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
45189 static int xsd_kva_open(struct inode *inode, struct file *file)
45190 {
45191 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
45192+#ifdef CONFIG_GRKERNSEC_HIDESYM
45193+ NULL);
45194+#else
45195 xen_store_interface);
45196+#endif
45197+
45198 if (!file->private_data)
45199 return -ENOMEM;
45200 return 0;
45201diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
45202index 890bed5..17ae73e 100644
45203--- a/fs/9p/vfs_inode.c
45204+++ b/fs/9p/vfs_inode.c
45205@@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
45206 void
45207 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
45208 {
45209- char *s = nd_get_link(nd);
45210+ const char *s = nd_get_link(nd);
45211
45212 p9_debug(P9_DEBUG_VFS, " %s %s\n",
45213 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
45214diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
45215index 0efd152..b5802ad 100644
45216--- a/fs/Kconfig.binfmt
45217+++ b/fs/Kconfig.binfmt
45218@@ -89,7 +89,7 @@ config HAVE_AOUT
45219
45220 config BINFMT_AOUT
45221 tristate "Kernel support for a.out and ECOFF binaries"
45222- depends on HAVE_AOUT
45223+ depends on HAVE_AOUT && BROKEN
45224 ---help---
45225 A.out (Assembler.OUTput) is a set of formats for libraries and
45226 executables used in the earliest versions of UNIX. Linux used
45227diff --git a/fs/aio.c b/fs/aio.c
45228index 71f613c..9d01f1f 100644
45229--- a/fs/aio.c
45230+++ b/fs/aio.c
45231@@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
45232 size += sizeof(struct io_event) * nr_events;
45233 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
45234
45235- if (nr_pages < 0)
45236+ if (nr_pages <= 0)
45237 return -EINVAL;
45238
45239 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
45240@@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
45241 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
45242 {
45243 ssize_t ret;
45244+ struct iovec iovstack;
45245
45246 #ifdef CONFIG_COMPAT
45247 if (compat)
45248 ret = compat_rw_copy_check_uvector(type,
45249 (struct compat_iovec __user *)kiocb->ki_buf,
45250- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
45251+ kiocb->ki_nbytes, 1, &iovstack,
45252 &kiocb->ki_iovec);
45253 else
45254 #endif
45255 ret = rw_copy_check_uvector(type,
45256 (struct iovec __user *)kiocb->ki_buf,
45257- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
45258+ kiocb->ki_nbytes, 1, &iovstack,
45259 &kiocb->ki_iovec);
45260 if (ret < 0)
45261 goto out;
45262@@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
45263 if (ret < 0)
45264 goto out;
45265
45266+ if (kiocb->ki_iovec == &iovstack) {
45267+ kiocb->ki_inline_vec = iovstack;
45268+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
45269+ }
45270 kiocb->ki_nr_segs = kiocb->ki_nbytes;
45271 kiocb->ki_cur_seg = 0;
45272 /* ki_nbytes/left now reflect bytes instead of segs */
45273diff --git a/fs/attr.c b/fs/attr.c
45274index 1449adb..a2038c2 100644
45275--- a/fs/attr.c
45276+++ b/fs/attr.c
45277@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
45278 unsigned long limit;
45279
45280 limit = rlimit(RLIMIT_FSIZE);
45281+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
45282 if (limit != RLIM_INFINITY && offset > limit)
45283 goto out_sig;
45284 if (offset > inode->i_sb->s_maxbytes)
45285diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
45286index 03bc1d3..6205356 100644
45287--- a/fs/autofs4/waitq.c
45288+++ b/fs/autofs4/waitq.c
45289@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
45290 {
45291 unsigned long sigpipe, flags;
45292 mm_segment_t fs;
45293- const char *data = (const char *)addr;
45294+ const char __user *data = (const char __force_user *)addr;
45295 ssize_t wr = 0;
45296
45297 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
45298@@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
45299 return 1;
45300 }
45301
45302+#ifdef CONFIG_GRKERNSEC_HIDESYM
45303+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
45304+#endif
45305+
45306 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
45307 enum autofs_notify notify)
45308 {
45309@@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
45310
45311 /* If this is a direct mount request create a dummy name */
45312 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
45313+#ifdef CONFIG_GRKERNSEC_HIDESYM
45314+ /* this name does get written to userland via autofs4_write() */
45315+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
45316+#else
45317 qstr.len = sprintf(name, "%p", dentry);
45318+#endif
45319 else {
45320 qstr.len = autofs4_getpath(sbi, dentry, &name);
45321 if (!qstr.len) {
45322diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
45323index 2b3bda8..6a2d4be 100644
45324--- a/fs/befs/linuxvfs.c
45325+++ b/fs/befs/linuxvfs.c
45326@@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
45327 {
45328 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
45329 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
45330- char *link = nd_get_link(nd);
45331+ const char *link = nd_get_link(nd);
45332 if (!IS_ERR(link))
45333 kfree(link);
45334 }
45335diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
45336index 6043567..16a9239 100644
45337--- a/fs/binfmt_aout.c
45338+++ b/fs/binfmt_aout.c
45339@@ -16,6 +16,7 @@
45340 #include <linux/string.h>
45341 #include <linux/fs.h>
45342 #include <linux/file.h>
45343+#include <linux/security.h>
45344 #include <linux/stat.h>
45345 #include <linux/fcntl.h>
45346 #include <linux/ptrace.h>
45347@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
45348 #endif
45349 # define START_STACK(u) ((void __user *)u.start_stack)
45350
45351+ memset(&dump, 0, sizeof(dump));
45352+
45353 fs = get_fs();
45354 set_fs(KERNEL_DS);
45355 has_dumped = 1;
45356@@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
45357
45358 /* If the size of the dump file exceeds the rlimit, then see what would happen
45359 if we wrote the stack, but not the data area. */
45360+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
45361 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
45362 dump.u_dsize = 0;
45363
45364 /* Make sure we have enough room to write the stack and data areas. */
45365+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
45366 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
45367 dump.u_ssize = 0;
45368
45369@@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
45370 rlim = rlimit(RLIMIT_DATA);
45371 if (rlim >= RLIM_INFINITY)
45372 rlim = ~0;
45373+
45374+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
45375 if (ex.a_data + ex.a_bss > rlim)
45376 return -ENOMEM;
45377
45378@@ -268,6 +275,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
45379
45380 install_exec_creds(bprm);
45381
45382+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45383+ current->mm->pax_flags = 0UL;
45384+#endif
45385+
45386+#ifdef CONFIG_PAX_PAGEEXEC
45387+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
45388+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
45389+
45390+#ifdef CONFIG_PAX_EMUTRAMP
45391+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
45392+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
45393+#endif
45394+
45395+#ifdef CONFIG_PAX_MPROTECT
45396+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
45397+ current->mm->pax_flags |= MF_PAX_MPROTECT;
45398+#endif
45399+
45400+ }
45401+#endif
45402+
45403 if (N_MAGIC(ex) == OMAGIC) {
45404 unsigned long text_addr, map_size;
45405 loff_t pos;
45406@@ -333,7 +361,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
45407 }
45408
45409 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
45410- PROT_READ | PROT_WRITE | PROT_EXEC,
45411+ PROT_READ | PROT_WRITE,
45412 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
45413 fd_offset + ex.a_text);
45414 if (error != N_DATADDR(ex)) {
45415diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
45416index 0c42cdb..f4be023 100644
45417--- a/fs/binfmt_elf.c
45418+++ b/fs/binfmt_elf.c
45419@@ -33,6 +33,7 @@
45420 #include <linux/elf.h>
45421 #include <linux/utsname.h>
45422 #include <linux/coredump.h>
45423+#include <linux/xattr.h>
45424 #include <asm/uaccess.h>
45425 #include <asm/param.h>
45426 #include <asm/page.h>
45427@@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
45428 #define elf_core_dump NULL
45429 #endif
45430
45431+#ifdef CONFIG_PAX_MPROTECT
45432+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
45433+#endif
45434+
45435 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
45436 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
45437 #else
45438@@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
45439 .load_binary = load_elf_binary,
45440 .load_shlib = load_elf_library,
45441 .core_dump = elf_core_dump,
45442+
45443+#ifdef CONFIG_PAX_MPROTECT
45444+ .handle_mprotect= elf_handle_mprotect,
45445+#endif
45446+
45447 .min_coredump = ELF_EXEC_PAGESIZE,
45448 };
45449
45450@@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
45451
45452 static int set_brk(unsigned long start, unsigned long end)
45453 {
45454+ unsigned long e = end;
45455+
45456 start = ELF_PAGEALIGN(start);
45457 end = ELF_PAGEALIGN(end);
45458 if (end > start) {
45459@@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
45460 if (BAD_ADDR(addr))
45461 return addr;
45462 }
45463- current->mm->start_brk = current->mm->brk = end;
45464+ current->mm->start_brk = current->mm->brk = e;
45465 return 0;
45466 }
45467
45468@@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
45469 elf_addr_t __user *u_rand_bytes;
45470 const char *k_platform = ELF_PLATFORM;
45471 const char *k_base_platform = ELF_BASE_PLATFORM;
45472- unsigned char k_rand_bytes[16];
45473+ u32 k_rand_bytes[4];
45474 int items;
45475 elf_addr_t *elf_info;
45476 int ei_index = 0;
45477 const struct cred *cred = current_cred();
45478 struct vm_area_struct *vma;
45479+ unsigned long saved_auxv[AT_VECTOR_SIZE];
45480
45481 /*
45482 * In some cases (e.g. Hyper-Threading), we want to avoid L1
45483@@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
45484 * Generate 16 random bytes for userspace PRNG seeding.
45485 */
45486 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
45487- u_rand_bytes = (elf_addr_t __user *)
45488- STACK_ALLOC(p, sizeof(k_rand_bytes));
45489+ srandom32(k_rand_bytes[0] ^ random32());
45490+ srandom32(k_rand_bytes[1] ^ random32());
45491+ srandom32(k_rand_bytes[2] ^ random32());
45492+ srandom32(k_rand_bytes[3] ^ random32());
45493+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
45494+ u_rand_bytes = (elf_addr_t __user *) p;
45495 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
45496 return -EFAULT;
45497
45498@@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
45499 return -EFAULT;
45500 current->mm->env_end = p;
45501
45502+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
45503+
45504 /* Put the elf_info on the stack in the right place. */
45505 sp = (elf_addr_t __user *)envp + 1;
45506- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
45507+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
45508 return -EFAULT;
45509 return 0;
45510 }
45511@@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
45512 an ELF header */
45513
45514 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
45515- struct file *interpreter, unsigned long *interp_map_addr,
45516- unsigned long no_base)
45517+ struct file *interpreter, unsigned long no_base)
45518 {
45519 struct elf_phdr *elf_phdata;
45520 struct elf_phdr *eppnt;
45521- unsigned long load_addr = 0;
45522+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
45523 int load_addr_set = 0;
45524 unsigned long last_bss = 0, elf_bss = 0;
45525- unsigned long error = ~0UL;
45526+ unsigned long error = -EINVAL;
45527 unsigned long total_size;
45528 int retval, i, size;
45529
45530@@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
45531 goto out_close;
45532 }
45533
45534+#ifdef CONFIG_PAX_SEGMEXEC
45535+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
45536+ pax_task_size = SEGMEXEC_TASK_SIZE;
45537+#endif
45538+
45539 eppnt = elf_phdata;
45540 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
45541 if (eppnt->p_type == PT_LOAD) {
45542@@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
45543 map_addr = elf_map(interpreter, load_addr + vaddr,
45544 eppnt, elf_prot, elf_type, total_size);
45545 total_size = 0;
45546- if (!*interp_map_addr)
45547- *interp_map_addr = map_addr;
45548 error = map_addr;
45549 if (BAD_ADDR(map_addr))
45550 goto out_close;
45551@@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
45552 k = load_addr + eppnt->p_vaddr;
45553 if (BAD_ADDR(k) ||
45554 eppnt->p_filesz > eppnt->p_memsz ||
45555- eppnt->p_memsz > TASK_SIZE ||
45556- TASK_SIZE - eppnt->p_memsz < k) {
45557+ eppnt->p_memsz > pax_task_size ||
45558+ pax_task_size - eppnt->p_memsz < k) {
45559 error = -ENOMEM;
45560 goto out_close;
45561 }
45562@@ -530,6 +551,315 @@ out:
45563 return error;
45564 }
45565
45566+#ifdef CONFIG_PAX_PT_PAX_FLAGS
45567+#ifdef CONFIG_PAX_SOFTMODE
45568+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
45569+{
45570+ unsigned long pax_flags = 0UL;
45571+
45572+#ifdef CONFIG_PAX_PAGEEXEC
45573+ if (elf_phdata->p_flags & PF_PAGEEXEC)
45574+ pax_flags |= MF_PAX_PAGEEXEC;
45575+#endif
45576+
45577+#ifdef CONFIG_PAX_SEGMEXEC
45578+ if (elf_phdata->p_flags & PF_SEGMEXEC)
45579+ pax_flags |= MF_PAX_SEGMEXEC;
45580+#endif
45581+
45582+#ifdef CONFIG_PAX_EMUTRAMP
45583+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
45584+ pax_flags |= MF_PAX_EMUTRAMP;
45585+#endif
45586+
45587+#ifdef CONFIG_PAX_MPROTECT
45588+ if (elf_phdata->p_flags & PF_MPROTECT)
45589+ pax_flags |= MF_PAX_MPROTECT;
45590+#endif
45591+
45592+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
45593+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
45594+ pax_flags |= MF_PAX_RANDMMAP;
45595+#endif
45596+
45597+ return pax_flags;
45598+}
45599+#endif
45600+
45601+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
45602+{
45603+ unsigned long pax_flags = 0UL;
45604+
45605+#ifdef CONFIG_PAX_PAGEEXEC
45606+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
45607+ pax_flags |= MF_PAX_PAGEEXEC;
45608+#endif
45609+
45610+#ifdef CONFIG_PAX_SEGMEXEC
45611+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
45612+ pax_flags |= MF_PAX_SEGMEXEC;
45613+#endif
45614+
45615+#ifdef CONFIG_PAX_EMUTRAMP
45616+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
45617+ pax_flags |= MF_PAX_EMUTRAMP;
45618+#endif
45619+
45620+#ifdef CONFIG_PAX_MPROTECT
45621+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
45622+ pax_flags |= MF_PAX_MPROTECT;
45623+#endif
45624+
45625+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
45626+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
45627+ pax_flags |= MF_PAX_RANDMMAP;
45628+#endif
45629+
45630+ return pax_flags;
45631+}
45632+#endif
45633+
45634+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
45635+#ifdef CONFIG_PAX_SOFTMODE
45636+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
45637+{
45638+ unsigned long pax_flags = 0UL;
45639+
45640+#ifdef CONFIG_PAX_PAGEEXEC
45641+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
45642+ pax_flags |= MF_PAX_PAGEEXEC;
45643+#endif
45644+
45645+#ifdef CONFIG_PAX_SEGMEXEC
45646+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
45647+ pax_flags |= MF_PAX_SEGMEXEC;
45648+#endif
45649+
45650+#ifdef CONFIG_PAX_EMUTRAMP
45651+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
45652+ pax_flags |= MF_PAX_EMUTRAMP;
45653+#endif
45654+
45655+#ifdef CONFIG_PAX_MPROTECT
45656+ if (pax_flags_softmode & MF_PAX_MPROTECT)
45657+ pax_flags |= MF_PAX_MPROTECT;
45658+#endif
45659+
45660+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
45661+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
45662+ pax_flags |= MF_PAX_RANDMMAP;
45663+#endif
45664+
45665+ return pax_flags;
45666+}
45667+#endif
45668+
45669+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
45670+{
45671+ unsigned long pax_flags = 0UL;
45672+
45673+#ifdef CONFIG_PAX_PAGEEXEC
45674+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
45675+ pax_flags |= MF_PAX_PAGEEXEC;
45676+#endif
45677+
45678+#ifdef CONFIG_PAX_SEGMEXEC
45679+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
45680+ pax_flags |= MF_PAX_SEGMEXEC;
45681+#endif
45682+
45683+#ifdef CONFIG_PAX_EMUTRAMP
45684+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
45685+ pax_flags |= MF_PAX_EMUTRAMP;
45686+#endif
45687+
45688+#ifdef CONFIG_PAX_MPROTECT
45689+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
45690+ pax_flags |= MF_PAX_MPROTECT;
45691+#endif
45692+
45693+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
45694+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
45695+ pax_flags |= MF_PAX_RANDMMAP;
45696+#endif
45697+
45698+ return pax_flags;
45699+}
45700+#endif
45701+
45702+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45703+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
45704+{
45705+ unsigned long pax_flags = 0UL;
45706+
45707+#ifdef CONFIG_PAX_EI_PAX
45708+
45709+#ifdef CONFIG_PAX_PAGEEXEC
45710+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
45711+ pax_flags |= MF_PAX_PAGEEXEC;
45712+#endif
45713+
45714+#ifdef CONFIG_PAX_SEGMEXEC
45715+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
45716+ pax_flags |= MF_PAX_SEGMEXEC;
45717+#endif
45718+
45719+#ifdef CONFIG_PAX_EMUTRAMP
45720+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
45721+ pax_flags |= MF_PAX_EMUTRAMP;
45722+#endif
45723+
45724+#ifdef CONFIG_PAX_MPROTECT
45725+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
45726+ pax_flags |= MF_PAX_MPROTECT;
45727+#endif
45728+
45729+#ifdef CONFIG_PAX_ASLR
45730+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
45731+ pax_flags |= MF_PAX_RANDMMAP;
45732+#endif
45733+
45734+#else
45735+
45736+#ifdef CONFIG_PAX_PAGEEXEC
45737+ pax_flags |= MF_PAX_PAGEEXEC;
45738+#endif
45739+
45740+#ifdef CONFIG_PAX_SEGMEXEC
45741+ pax_flags |= MF_PAX_SEGMEXEC;
45742+#endif
45743+
45744+#ifdef CONFIG_PAX_MPROTECT
45745+ pax_flags |= MF_PAX_MPROTECT;
45746+#endif
45747+
45748+#ifdef CONFIG_PAX_RANDMMAP
45749+ if (randomize_va_space)
45750+ pax_flags |= MF_PAX_RANDMMAP;
45751+#endif
45752+
45753+#endif
45754+
45755+ return pax_flags;
45756+}
45757+
45758+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
45759+{
45760+
45761+#ifdef CONFIG_PAX_PT_PAX_FLAGS
45762+ unsigned long i;
45763+
45764+ for (i = 0UL; i < elf_ex->e_phnum; i++)
45765+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
45766+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
45767+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
45768+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
45769+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
45770+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
45771+ return ~0UL;
45772+
45773+#ifdef CONFIG_PAX_SOFTMODE
45774+ if (pax_softmode)
45775+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
45776+ else
45777+#endif
45778+
45779+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
45780+ break;
45781+ }
45782+#endif
45783+
45784+ return ~0UL;
45785+}
45786+
45787+static unsigned long pax_parse_xattr_pax(struct file * const file)
45788+{
45789+
45790+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
45791+ ssize_t xattr_size, i;
45792+ unsigned char xattr_value[5];
45793+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
45794+
45795+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
45796+ if (xattr_size <= 0 || xattr_size > 5)
45797+ return ~0UL;
45798+
45799+ for (i = 0; i < xattr_size; i++)
45800+ switch (xattr_value[i]) {
45801+ default:
45802+ return ~0UL;
45803+
45804+#define parse_flag(option1, option2, flag) \
45805+ case option1: \
45806+ if (pax_flags_hardmode & MF_PAX_##flag) \
45807+ return ~0UL; \
45808+ pax_flags_hardmode |= MF_PAX_##flag; \
45809+ break; \
45810+ case option2: \
45811+ if (pax_flags_softmode & MF_PAX_##flag) \
45812+ return ~0UL; \
45813+ pax_flags_softmode |= MF_PAX_##flag; \
45814+ break;
45815+
45816+ parse_flag('p', 'P', PAGEEXEC);
45817+ parse_flag('e', 'E', EMUTRAMP);
45818+ parse_flag('m', 'M', MPROTECT);
45819+ parse_flag('r', 'R', RANDMMAP);
45820+ parse_flag('s', 'S', SEGMEXEC);
45821+
45822+#undef parse_flag
45823+ }
45824+
45825+ if (pax_flags_hardmode & pax_flags_softmode)
45826+ return ~0UL;
45827+
45828+#ifdef CONFIG_PAX_SOFTMODE
45829+ if (pax_softmode)
45830+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
45831+ else
45832+#endif
45833+
45834+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
45835+#else
45836+ return ~0UL;
45837+#endif
45838+
45839+}
45840+
45841+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
45842+{
45843+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
45844+
45845+ pax_flags = pax_parse_ei_pax(elf_ex);
45846+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
45847+ xattr_pax_flags = pax_parse_xattr_pax(file);
45848+
45849+ if (pt_pax_flags == ~0UL)
45850+ pt_pax_flags = xattr_pax_flags;
45851+ else if (xattr_pax_flags == ~0UL)
45852+ xattr_pax_flags = pt_pax_flags;
45853+ if (pt_pax_flags != xattr_pax_flags)
45854+ return -EINVAL;
45855+ if (pt_pax_flags != ~0UL)
45856+ pax_flags = pt_pax_flags;
45857+
45858+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
45859+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45860+ if ((__supported_pte_mask & _PAGE_NX))
45861+ pax_flags &= ~MF_PAX_SEGMEXEC;
45862+ else
45863+ pax_flags &= ~MF_PAX_PAGEEXEC;
45864+ }
45865+#endif
45866+
45867+ if (0 > pax_check_flags(&pax_flags))
45868+ return -EINVAL;
45869+
45870+ current->mm->pax_flags = pax_flags;
45871+ return 0;
45872+}
45873+#endif
45874+
45875 /*
45876 * These are the functions used to load ELF style executables and shared
45877 * libraries. There is no binary dependent code anywhere else.
45878@@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
45879 {
45880 unsigned int random_variable = 0;
45881
45882+#ifdef CONFIG_PAX_RANDUSTACK
45883+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
45884+ return stack_top - current->mm->delta_stack;
45885+#endif
45886+
45887 if ((current->flags & PF_RANDOMIZE) &&
45888 !(current->personality & ADDR_NO_RANDOMIZE)) {
45889 random_variable = get_random_int() & STACK_RND_MASK;
45890@@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
45891 unsigned long load_addr = 0, load_bias = 0;
45892 int load_addr_set = 0;
45893 char * elf_interpreter = NULL;
45894- unsigned long error;
45895+ unsigned long error = 0;
45896 struct elf_phdr *elf_ppnt, *elf_phdata;
45897 unsigned long elf_bss, elf_brk;
45898 int retval, i;
45899@@ -574,12 +909,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
45900 unsigned long start_code, end_code, start_data, end_data;
45901 unsigned long reloc_func_desc __maybe_unused = 0;
45902 int executable_stack = EXSTACK_DEFAULT;
45903- unsigned long def_flags = 0;
45904 struct pt_regs *regs = current_pt_regs();
45905 struct {
45906 struct elfhdr elf_ex;
45907 struct elfhdr interp_elf_ex;
45908 } *loc;
45909+ unsigned long pax_task_size = TASK_SIZE;
45910
45911 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
45912 if (!loc) {
45913@@ -715,11 +1050,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
45914 goto out_free_dentry;
45915
45916 /* OK, This is the point of no return */
45917- current->mm->def_flags = def_flags;
45918+
45919+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45920+ current->mm->pax_flags = 0UL;
45921+#endif
45922+
45923+#ifdef CONFIG_PAX_DLRESOLVE
45924+ current->mm->call_dl_resolve = 0UL;
45925+#endif
45926+
45927+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
45928+ current->mm->call_syscall = 0UL;
45929+#endif
45930+
45931+#ifdef CONFIG_PAX_ASLR
45932+ current->mm->delta_mmap = 0UL;
45933+ current->mm->delta_stack = 0UL;
45934+#endif
45935+
45936+ current->mm->def_flags = 0;
45937+
45938+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45939+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
45940+ send_sig(SIGKILL, current, 0);
45941+ goto out_free_dentry;
45942+ }
45943+#endif
45944+
45945+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
45946+ pax_set_initial_flags(bprm);
45947+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
45948+ if (pax_set_initial_flags_func)
45949+ (pax_set_initial_flags_func)(bprm);
45950+#endif
45951+
45952+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
45953+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
45954+ current->mm->context.user_cs_limit = PAGE_SIZE;
45955+ current->mm->def_flags |= VM_PAGEEXEC;
45956+ }
45957+#endif
45958+
45959+#ifdef CONFIG_PAX_SEGMEXEC
45960+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
45961+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
45962+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
45963+ pax_task_size = SEGMEXEC_TASK_SIZE;
45964+ current->mm->def_flags |= VM_NOHUGEPAGE;
45965+ }
45966+#endif
45967+
45968+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
45969+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45970+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
45971+ put_cpu();
45972+ }
45973+#endif
45974
45975 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
45976 may depend on the personality. */
45977 SET_PERSONALITY(loc->elf_ex);
45978+
45979+#ifdef CONFIG_PAX_ASLR
45980+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
45981+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
45982+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
45983+ }
45984+#endif
45985+
45986+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45987+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45988+ executable_stack = EXSTACK_DISABLE_X;
45989+ current->personality &= ~READ_IMPLIES_EXEC;
45990+ } else
45991+#endif
45992+
45993 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
45994 current->personality |= READ_IMPLIES_EXEC;
45995
45996@@ -810,6 +1215,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
45997 #else
45998 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
45999 #endif
46000+
46001+#ifdef CONFIG_PAX_RANDMMAP
46002+ /* PaX: randomize base address at the default exe base if requested */
46003+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
46004+#ifdef CONFIG_SPARC64
46005+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
46006+#else
46007+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
46008+#endif
46009+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
46010+ elf_flags |= MAP_FIXED;
46011+ }
46012+#endif
46013+
46014 }
46015
46016 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
46017@@ -842,9 +1261,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
46018 * allowed task size. Note that p_filesz must always be
46019 * <= p_memsz so it is only necessary to check p_memsz.
46020 */
46021- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
46022- elf_ppnt->p_memsz > TASK_SIZE ||
46023- TASK_SIZE - elf_ppnt->p_memsz < k) {
46024+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
46025+ elf_ppnt->p_memsz > pax_task_size ||
46026+ pax_task_size - elf_ppnt->p_memsz < k) {
46027 /* set_brk can never work. Avoid overflows. */
46028 send_sig(SIGKILL, current, 0);
46029 retval = -EINVAL;
46030@@ -883,17 +1302,44 @@ static int load_elf_binary(struct linux_binprm *bprm)
46031 goto out_free_dentry;
46032 }
46033 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
46034- send_sig(SIGSEGV, current, 0);
46035- retval = -EFAULT; /* Nobody gets to see this, but.. */
46036- goto out_free_dentry;
46037+ /*
46038+ * This bss-zeroing can fail if the ELF
46039+ * file specifies odd protections. So
46040+ * we don't check the return value
46041+ */
46042 }
46043
46044+#ifdef CONFIG_PAX_RANDMMAP
46045+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
46046+ unsigned long start, size;
46047+
46048+ start = ELF_PAGEALIGN(elf_brk);
46049+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
46050+ down_read(&current->mm->mmap_sem);
46051+ retval = -ENOMEM;
46052+ if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
46053+ unsigned long prot = PROT_NONE;
46054+
46055+ up_read(&current->mm->mmap_sem);
46056+ current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
46057+// if (current->personality & ADDR_NO_RANDOMIZE)
46058+// prot = PROT_READ;
46059+ start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
46060+ retval = IS_ERR_VALUE(start) ? start : 0;
46061+ } else
46062+ up_read(&current->mm->mmap_sem);
46063+ if (retval == 0)
46064+ retval = set_brk(start + size, start + size + PAGE_SIZE);
46065+ if (retval < 0) {
46066+ send_sig(SIGKILL, current, 0);
46067+ goto out_free_dentry;
46068+ }
46069+ }
46070+#endif
46071+
46072 if (elf_interpreter) {
46073- unsigned long interp_map_addr = 0;
46074-
46075 elf_entry = load_elf_interp(&loc->interp_elf_ex,
46076 interpreter,
46077- &interp_map_addr,
46078 load_bias);
46079 if (!IS_ERR((void *)elf_entry)) {
46080 /*
46081@@ -1115,7 +1561,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
46082 * Decide what to dump of a segment, part, all or none.
46083 */
46084 static unsigned long vma_dump_size(struct vm_area_struct *vma,
46085- unsigned long mm_flags)
46086+ unsigned long mm_flags, long signr)
46087 {
46088 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
46089
46090@@ -1152,7 +1598,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
46091 if (vma->vm_file == NULL)
46092 return 0;
46093
46094- if (FILTER(MAPPED_PRIVATE))
46095+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
46096 goto whole;
46097
46098 /*
46099@@ -1374,9 +1820,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
46100 {
46101 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
46102 int i = 0;
46103- do
46104+ do {
46105 i += 2;
46106- while (auxv[i - 2] != AT_NULL);
46107+ } while (auxv[i - 2] != AT_NULL);
46108 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
46109 }
46110
46111@@ -2006,14 +2452,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
46112 }
46113
46114 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
46115- unsigned long mm_flags)
46116+ struct coredump_params *cprm)
46117 {
46118 struct vm_area_struct *vma;
46119 size_t size = 0;
46120
46121 for (vma = first_vma(current, gate_vma); vma != NULL;
46122 vma = next_vma(vma, gate_vma))
46123- size += vma_dump_size(vma, mm_flags);
46124+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
46125 return size;
46126 }
46127
46128@@ -2107,7 +2553,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46129
46130 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
46131
46132- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
46133+ offset += elf_core_vma_data_size(gate_vma, cprm);
46134 offset += elf_core_extra_data_size();
46135 e_shoff = offset;
46136
46137@@ -2121,10 +2567,12 @@ static int elf_core_dump(struct coredump_params *cprm)
46138 offset = dataoff;
46139
46140 size += sizeof(*elf);
46141+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
46142 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
46143 goto end_coredump;
46144
46145 size += sizeof(*phdr4note);
46146+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
46147 if (size > cprm->limit
46148 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
46149 goto end_coredump;
46150@@ -2138,7 +2586,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46151 phdr.p_offset = offset;
46152 phdr.p_vaddr = vma->vm_start;
46153 phdr.p_paddr = 0;
46154- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
46155+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
46156 phdr.p_memsz = vma->vm_end - vma->vm_start;
46157 offset += phdr.p_filesz;
46158 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
46159@@ -2149,6 +2597,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46160 phdr.p_align = ELF_EXEC_PAGESIZE;
46161
46162 size += sizeof(phdr);
46163+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
46164 if (size > cprm->limit
46165 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
46166 goto end_coredump;
46167@@ -2173,7 +2622,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46168 unsigned long addr;
46169 unsigned long end;
46170
46171- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
46172+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
46173
46174 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
46175 struct page *page;
46176@@ -2182,6 +2631,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46177 page = get_dump_page(addr);
46178 if (page) {
46179 void *kaddr = kmap(page);
46180+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
46181 stop = ((size += PAGE_SIZE) > cprm->limit) ||
46182 !dump_write(cprm->file, kaddr,
46183 PAGE_SIZE);
46184@@ -2199,6 +2649,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46185
46186 if (e_phnum == PN_XNUM) {
46187 size += sizeof(*shdr4extnum);
46188+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
46189 if (size > cprm->limit
46190 || !dump_write(cprm->file, shdr4extnum,
46191 sizeof(*shdr4extnum)))
46192@@ -2219,6 +2670,97 @@ out:
46193
46194 #endif /* CONFIG_ELF_CORE */
46195
46196+#ifdef CONFIG_PAX_MPROTECT
46197+/* PaX: non-PIC ELF libraries need relocations on their executable segments
46198+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
46199+ * we'll remove VM_MAYWRITE for good on RELRO segments.
46200+ *
46201+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
46202+ * basis because we want to allow the common case and not the special ones.
46203+ */
46204+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
46205+{
46206+ struct elfhdr elf_h;
46207+ struct elf_phdr elf_p;
46208+ unsigned long i;
46209+ unsigned long oldflags;
46210+ bool is_textrel_rw, is_textrel_rx, is_relro;
46211+
46212+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
46213+ return;
46214+
46215+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
46216+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
46217+
46218+#ifdef CONFIG_PAX_ELFRELOCS
46219+ /* possible TEXTREL */
46220+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
46221+ 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);
46222+#else
46223+ is_textrel_rw = false;
46224+ is_textrel_rx = false;
46225+#endif
46226+
46227+ /* possible RELRO */
46228+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
46229+
46230+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
46231+ return;
46232+
46233+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
46234+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
46235+
46236+#ifdef CONFIG_PAX_ETEXECRELOCS
46237+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
46238+#else
46239+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
46240+#endif
46241+
46242+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
46243+ !elf_check_arch(&elf_h) ||
46244+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
46245+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
46246+ return;
46247+
46248+ for (i = 0UL; i < elf_h.e_phnum; i++) {
46249+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
46250+ return;
46251+ switch (elf_p.p_type) {
46252+ case PT_DYNAMIC:
46253+ if (!is_textrel_rw && !is_textrel_rx)
46254+ continue;
46255+ i = 0UL;
46256+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
46257+ elf_dyn dyn;
46258+
46259+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
46260+ return;
46261+ if (dyn.d_tag == DT_NULL)
46262+ return;
46263+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
46264+ gr_log_textrel(vma);
46265+ if (is_textrel_rw)
46266+ vma->vm_flags |= VM_MAYWRITE;
46267+ else
46268+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
46269+ vma->vm_flags &= ~VM_MAYWRITE;
46270+ return;
46271+ }
46272+ i++;
46273+ }
46274+ return;
46275+
46276+ case PT_GNU_RELRO:
46277+ if (!is_relro)
46278+ continue;
46279+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
46280+ vma->vm_flags &= ~VM_MAYWRITE;
46281+ return;
46282+ }
46283+ }
46284+}
46285+#endif
46286+
46287 static int __init init_elf_binfmt(void)
46288 {
46289 register_binfmt(&elf_format);
46290diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
46291index b563719..3868998 100644
46292--- a/fs/binfmt_flat.c
46293+++ b/fs/binfmt_flat.c
46294@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
46295 realdatastart = (unsigned long) -ENOMEM;
46296 printk("Unable to allocate RAM for process data, errno %d\n",
46297 (int)-realdatastart);
46298+ down_write(&current->mm->mmap_sem);
46299 vm_munmap(textpos, text_len);
46300+ up_write(&current->mm->mmap_sem);
46301 ret = realdatastart;
46302 goto err;
46303 }
46304@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
46305 }
46306 if (IS_ERR_VALUE(result)) {
46307 printk("Unable to read data+bss, errno %d\n", (int)-result);
46308+ down_write(&current->mm->mmap_sem);
46309 vm_munmap(textpos, text_len);
46310 vm_munmap(realdatastart, len);
46311+ up_write(&current->mm->mmap_sem);
46312 ret = result;
46313 goto err;
46314 }
46315@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
46316 }
46317 if (IS_ERR_VALUE(result)) {
46318 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
46319+ down_write(&current->mm->mmap_sem);
46320 vm_munmap(textpos, text_len + data_len + extra +
46321 MAX_SHARED_LIBS * sizeof(unsigned long));
46322+ up_write(&current->mm->mmap_sem);
46323 ret = result;
46324 goto err;
46325 }
46326diff --git a/fs/bio.c b/fs/bio.c
46327index b96fc6c..431d628 100644
46328--- a/fs/bio.c
46329+++ b/fs/bio.c
46330@@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
46331 /*
46332 * Overflow, abort
46333 */
46334- if (end < start)
46335+ if (end < start || end - start > INT_MAX - nr_pages)
46336 return ERR_PTR(-EINVAL);
46337
46338 nr_pages += end - start;
46339@@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
46340 /*
46341 * Overflow, abort
46342 */
46343- if (end < start)
46344+ if (end < start || end - start > INT_MAX - nr_pages)
46345 return ERR_PTR(-EINVAL);
46346
46347 nr_pages += end - start;
46348@@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
46349 const int read = bio_data_dir(bio) == READ;
46350 struct bio_map_data *bmd = bio->bi_private;
46351 int i;
46352- char *p = bmd->sgvecs[0].iov_base;
46353+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
46354
46355 __bio_for_each_segment(bvec, bio, i, 0) {
46356 char *addr = page_address(bvec->bv_page);
46357diff --git a/fs/block_dev.c b/fs/block_dev.c
46358index 78333a3..23dcb4d 100644
46359--- a/fs/block_dev.c
46360+++ b/fs/block_dev.c
46361@@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
46362 else if (bdev->bd_contains == bdev)
46363 return true; /* is a whole device which isn't held */
46364
46365- else if (whole->bd_holder == bd_may_claim)
46366+ else if (whole->bd_holder == (void *)bd_may_claim)
46367 return true; /* is a partition of a device that is being partitioned */
46368 else if (whole->bd_holder != NULL)
46369 return false; /* is a partition of a held device */
46370diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
46371index eea5da7..88fead70 100644
46372--- a/fs/btrfs/ctree.c
46373+++ b/fs/btrfs/ctree.c
46374@@ -1033,9 +1033,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
46375 free_extent_buffer(buf);
46376 add_root_to_dirty_list(root);
46377 } else {
46378- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
46379- parent_start = parent->start;
46380- else
46381+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
46382+ if (parent)
46383+ parent_start = parent->start;
46384+ else
46385+ parent_start = 0;
46386+ } else
46387 parent_start = 0;
46388
46389 WARN_ON(trans->transid != btrfs_header_generation(parent));
46390diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
46391index cc93b23..f3c42bf 100644
46392--- a/fs/btrfs/inode.c
46393+++ b/fs/btrfs/inode.c
46394@@ -7296,7 +7296,7 @@ fail:
46395 return -ENOMEM;
46396 }
46397
46398-static int btrfs_getattr(struct vfsmount *mnt,
46399+int btrfs_getattr(struct vfsmount *mnt,
46400 struct dentry *dentry, struct kstat *stat)
46401 {
46402 struct inode *inode = dentry->d_inode;
46403@@ -7310,6 +7310,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
46404 return 0;
46405 }
46406
46407+EXPORT_SYMBOL(btrfs_getattr);
46408+
46409+dev_t get_btrfs_dev_from_inode(struct inode *inode)
46410+{
46411+ return BTRFS_I(inode)->root->anon_dev;
46412+}
46413+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
46414+
46415 /*
46416 * If a file is moved, it will inherit the cow and compression flags of the new
46417 * directory.
46418diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
46419index 338f259..b657640 100644
46420--- a/fs/btrfs/ioctl.c
46421+++ b/fs/btrfs/ioctl.c
46422@@ -3033,9 +3033,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
46423 for (i = 0; i < num_types; i++) {
46424 struct btrfs_space_info *tmp;
46425
46426+ /* Don't copy in more than we allocated */
46427 if (!slot_count)
46428 break;
46429
46430+ slot_count--;
46431+
46432 info = NULL;
46433 rcu_read_lock();
46434 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
46435@@ -3057,10 +3060,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
46436 memcpy(dest, &space, sizeof(space));
46437 dest++;
46438 space_args.total_spaces++;
46439- slot_count--;
46440 }
46441- if (!slot_count)
46442- break;
46443 }
46444 up_read(&info->groups_sem);
46445 }
46446diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
46447index 300e09a..9fe4539 100644
46448--- a/fs/btrfs/relocation.c
46449+++ b/fs/btrfs/relocation.c
46450@@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
46451 }
46452 spin_unlock(&rc->reloc_root_tree.lock);
46453
46454- BUG_ON((struct btrfs_root *)node->data != root);
46455+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
46456
46457 if (!del) {
46458 spin_lock(&rc->reloc_root_tree.lock);
46459diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
46460index d8982e9..29a85fa 100644
46461--- a/fs/btrfs/super.c
46462+++ b/fs/btrfs/super.c
46463@@ -267,7 +267,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
46464 function, line, errstr);
46465 return;
46466 }
46467- ACCESS_ONCE(trans->transaction->aborted) = errno;
46468+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
46469 __btrfs_std_error(root->fs_info, function, line, errno, NULL);
46470 }
46471 /*
46472diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
46473index 622f469..e8d2d55 100644
46474--- a/fs/cachefiles/bind.c
46475+++ b/fs/cachefiles/bind.c
46476@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
46477 args);
46478
46479 /* start by checking things over */
46480- ASSERT(cache->fstop_percent >= 0 &&
46481- cache->fstop_percent < cache->fcull_percent &&
46482+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
46483 cache->fcull_percent < cache->frun_percent &&
46484 cache->frun_percent < 100);
46485
46486- ASSERT(cache->bstop_percent >= 0 &&
46487- cache->bstop_percent < cache->bcull_percent &&
46488+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
46489 cache->bcull_percent < cache->brun_percent &&
46490 cache->brun_percent < 100);
46491
46492diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
46493index 0a1467b..6a53245 100644
46494--- a/fs/cachefiles/daemon.c
46495+++ b/fs/cachefiles/daemon.c
46496@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
46497 if (n > buflen)
46498 return -EMSGSIZE;
46499
46500- if (copy_to_user(_buffer, buffer, n) != 0)
46501+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
46502 return -EFAULT;
46503
46504 return n;
46505@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
46506 if (test_bit(CACHEFILES_DEAD, &cache->flags))
46507 return -EIO;
46508
46509- if (datalen < 0 || datalen > PAGE_SIZE - 1)
46510+ if (datalen > PAGE_SIZE - 1)
46511 return -EOPNOTSUPP;
46512
46513 /* drag the command string into the kernel so we can parse it */
46514@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
46515 if (args[0] != '%' || args[1] != '\0')
46516 return -EINVAL;
46517
46518- if (fstop < 0 || fstop >= cache->fcull_percent)
46519+ if (fstop >= cache->fcull_percent)
46520 return cachefiles_daemon_range_error(cache, args);
46521
46522 cache->fstop_percent = fstop;
46523@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
46524 if (args[0] != '%' || args[1] != '\0')
46525 return -EINVAL;
46526
46527- if (bstop < 0 || bstop >= cache->bcull_percent)
46528+ if (bstop >= cache->bcull_percent)
46529 return cachefiles_daemon_range_error(cache, args);
46530
46531 cache->bstop_percent = bstop;
46532diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
46533index 4938251..7e01445 100644
46534--- a/fs/cachefiles/internal.h
46535+++ b/fs/cachefiles/internal.h
46536@@ -59,7 +59,7 @@ struct cachefiles_cache {
46537 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
46538 struct rb_root active_nodes; /* active nodes (can't be culled) */
46539 rwlock_t active_lock; /* lock for active_nodes */
46540- atomic_t gravecounter; /* graveyard uniquifier */
46541+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
46542 unsigned frun_percent; /* when to stop culling (% files) */
46543 unsigned fcull_percent; /* when to start culling (% files) */
46544 unsigned fstop_percent; /* when to stop allocating (% files) */
46545@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
46546 * proc.c
46547 */
46548 #ifdef CONFIG_CACHEFILES_HISTOGRAM
46549-extern atomic_t cachefiles_lookup_histogram[HZ];
46550-extern atomic_t cachefiles_mkdir_histogram[HZ];
46551-extern atomic_t cachefiles_create_histogram[HZ];
46552+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
46553+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
46554+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
46555
46556 extern int __init cachefiles_proc_init(void);
46557 extern void cachefiles_proc_cleanup(void);
46558 static inline
46559-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
46560+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
46561 {
46562 unsigned long jif = jiffies - start_jif;
46563 if (jif >= HZ)
46564 jif = HZ - 1;
46565- atomic_inc(&histogram[jif]);
46566+ atomic_inc_unchecked(&histogram[jif]);
46567 }
46568
46569 #else
46570diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
46571index 8c01c5fc..15f982e 100644
46572--- a/fs/cachefiles/namei.c
46573+++ b/fs/cachefiles/namei.c
46574@@ -317,7 +317,7 @@ try_again:
46575 /* first step is to make up a grave dentry in the graveyard */
46576 sprintf(nbuffer, "%08x%08x",
46577 (uint32_t) get_seconds(),
46578- (uint32_t) atomic_inc_return(&cache->gravecounter));
46579+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
46580
46581 /* do the multiway lock magic */
46582 trap = lock_rename(cache->graveyard, dir);
46583diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
46584index eccd339..4c1d995 100644
46585--- a/fs/cachefiles/proc.c
46586+++ b/fs/cachefiles/proc.c
46587@@ -14,9 +14,9 @@
46588 #include <linux/seq_file.h>
46589 #include "internal.h"
46590
46591-atomic_t cachefiles_lookup_histogram[HZ];
46592-atomic_t cachefiles_mkdir_histogram[HZ];
46593-atomic_t cachefiles_create_histogram[HZ];
46594+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
46595+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
46596+atomic_unchecked_t cachefiles_create_histogram[HZ];
46597
46598 /*
46599 * display the latency histogram
46600@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
46601 return 0;
46602 default:
46603 index = (unsigned long) v - 3;
46604- x = atomic_read(&cachefiles_lookup_histogram[index]);
46605- y = atomic_read(&cachefiles_mkdir_histogram[index]);
46606- z = atomic_read(&cachefiles_create_histogram[index]);
46607+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
46608+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
46609+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
46610 if (x == 0 && y == 0 && z == 0)
46611 return 0;
46612
46613diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
46614index 4809922..aab2c39 100644
46615--- a/fs/cachefiles/rdwr.c
46616+++ b/fs/cachefiles/rdwr.c
46617@@ -965,7 +965,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
46618 old_fs = get_fs();
46619 set_fs(KERNEL_DS);
46620 ret = file->f_op->write(
46621- file, (const void __user *) data, len, &pos);
46622+ file, (const void __force_user *) data, len, &pos);
46623 set_fs(old_fs);
46624 kunmap(page);
46625 if (ret != len)
46626diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
46627index 8c1aabe..bbf856a 100644
46628--- a/fs/ceph/dir.c
46629+++ b/fs/ceph/dir.c
46630@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
46631 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
46632 struct ceph_mds_client *mdsc = fsc->mdsc;
46633 unsigned frag = fpos_frag(filp->f_pos);
46634- int off = fpos_off(filp->f_pos);
46635+ unsigned int off = fpos_off(filp->f_pos);
46636 int err;
46637 u32 ftype;
46638 struct ceph_mds_reply_info_parsed *rinfo;
46639diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
46640index d9ea6ed..1e6c8ac 100644
46641--- a/fs/cifs/cifs_debug.c
46642+++ b/fs/cifs/cifs_debug.c
46643@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
46644
46645 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
46646 #ifdef CONFIG_CIFS_STATS2
46647- atomic_set(&totBufAllocCount, 0);
46648- atomic_set(&totSmBufAllocCount, 0);
46649+ atomic_set_unchecked(&totBufAllocCount, 0);
46650+ atomic_set_unchecked(&totSmBufAllocCount, 0);
46651 #endif /* CONFIG_CIFS_STATS2 */
46652 spin_lock(&cifs_tcp_ses_lock);
46653 list_for_each(tmp1, &cifs_tcp_ses_list) {
46654@@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
46655 tcon = list_entry(tmp3,
46656 struct cifs_tcon,
46657 tcon_list);
46658- atomic_set(&tcon->num_smbs_sent, 0);
46659+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
46660 if (server->ops->clear_stats)
46661 server->ops->clear_stats(tcon);
46662 }
46663@@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
46664 smBufAllocCount.counter, cifs_min_small);
46665 #ifdef CONFIG_CIFS_STATS2
46666 seq_printf(m, "Total Large %d Small %d Allocations\n",
46667- atomic_read(&totBufAllocCount),
46668- atomic_read(&totSmBufAllocCount));
46669+ atomic_read_unchecked(&totBufAllocCount),
46670+ atomic_read_unchecked(&totSmBufAllocCount));
46671 #endif /* CONFIG_CIFS_STATS2 */
46672
46673 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
46674@@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
46675 if (tcon->need_reconnect)
46676 seq_puts(m, "\tDISCONNECTED ");
46677 seq_printf(m, "\nSMBs: %d",
46678- atomic_read(&tcon->num_smbs_sent));
46679+ atomic_read_unchecked(&tcon->num_smbs_sent));
46680 if (server->ops->print_stats)
46681 server->ops->print_stats(m, tcon);
46682 }
46683diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
46684index de7f916..6cb22a9 100644
46685--- a/fs/cifs/cifsfs.c
46686+++ b/fs/cifs/cifsfs.c
46687@@ -997,7 +997,7 @@ cifs_init_request_bufs(void)
46688 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
46689 cifs_req_cachep = kmem_cache_create("cifs_request",
46690 CIFSMaxBufSize + max_hdr_size, 0,
46691- SLAB_HWCACHE_ALIGN, NULL);
46692+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
46693 if (cifs_req_cachep == NULL)
46694 return -ENOMEM;
46695
46696@@ -1024,7 +1024,7 @@ cifs_init_request_bufs(void)
46697 efficient to alloc 1 per page off the slab compared to 17K (5page)
46698 alloc of large cifs buffers even when page debugging is on */
46699 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
46700- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
46701+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
46702 NULL);
46703 if (cifs_sm_req_cachep == NULL) {
46704 mempool_destroy(cifs_req_poolp);
46705@@ -1109,8 +1109,8 @@ init_cifs(void)
46706 atomic_set(&bufAllocCount, 0);
46707 atomic_set(&smBufAllocCount, 0);
46708 #ifdef CONFIG_CIFS_STATS2
46709- atomic_set(&totBufAllocCount, 0);
46710- atomic_set(&totSmBufAllocCount, 0);
46711+ atomic_set_unchecked(&totBufAllocCount, 0);
46712+ atomic_set_unchecked(&totSmBufAllocCount, 0);
46713 #endif /* CONFIG_CIFS_STATS2 */
46714
46715 atomic_set(&midCount, 0);
46716diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
46717index e6899ce..d6b2920 100644
46718--- a/fs/cifs/cifsglob.h
46719+++ b/fs/cifs/cifsglob.h
46720@@ -751,35 +751,35 @@ struct cifs_tcon {
46721 __u16 Flags; /* optional support bits */
46722 enum statusEnum tidStatus;
46723 #ifdef CONFIG_CIFS_STATS
46724- atomic_t num_smbs_sent;
46725+ atomic_unchecked_t num_smbs_sent;
46726 union {
46727 struct {
46728- atomic_t num_writes;
46729- atomic_t num_reads;
46730- atomic_t num_flushes;
46731- atomic_t num_oplock_brks;
46732- atomic_t num_opens;
46733- atomic_t num_closes;
46734- atomic_t num_deletes;
46735- atomic_t num_mkdirs;
46736- atomic_t num_posixopens;
46737- atomic_t num_posixmkdirs;
46738- atomic_t num_rmdirs;
46739- atomic_t num_renames;
46740- atomic_t num_t2renames;
46741- atomic_t num_ffirst;
46742- atomic_t num_fnext;
46743- atomic_t num_fclose;
46744- atomic_t num_hardlinks;
46745- atomic_t num_symlinks;
46746- atomic_t num_locks;
46747- atomic_t num_acl_get;
46748- atomic_t num_acl_set;
46749+ atomic_unchecked_t num_writes;
46750+ atomic_unchecked_t num_reads;
46751+ atomic_unchecked_t num_flushes;
46752+ atomic_unchecked_t num_oplock_brks;
46753+ atomic_unchecked_t num_opens;
46754+ atomic_unchecked_t num_closes;
46755+ atomic_unchecked_t num_deletes;
46756+ atomic_unchecked_t num_mkdirs;
46757+ atomic_unchecked_t num_posixopens;
46758+ atomic_unchecked_t num_posixmkdirs;
46759+ atomic_unchecked_t num_rmdirs;
46760+ atomic_unchecked_t num_renames;
46761+ atomic_unchecked_t num_t2renames;
46762+ atomic_unchecked_t num_ffirst;
46763+ atomic_unchecked_t num_fnext;
46764+ atomic_unchecked_t num_fclose;
46765+ atomic_unchecked_t num_hardlinks;
46766+ atomic_unchecked_t num_symlinks;
46767+ atomic_unchecked_t num_locks;
46768+ atomic_unchecked_t num_acl_get;
46769+ atomic_unchecked_t num_acl_set;
46770 } cifs_stats;
46771 #ifdef CONFIG_CIFS_SMB2
46772 struct {
46773- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
46774- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
46775+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
46776+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
46777 } smb2_stats;
46778 #endif /* CONFIG_CIFS_SMB2 */
46779 } stats;
46780@@ -1080,7 +1080,7 @@ convert_delimiter(char *path, char delim)
46781 }
46782
46783 #ifdef CONFIG_CIFS_STATS
46784-#define cifs_stats_inc atomic_inc
46785+#define cifs_stats_inc atomic_inc_unchecked
46786
46787 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
46788 unsigned int bytes)
46789@@ -1445,8 +1445,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
46790 /* Various Debug counters */
46791 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
46792 #ifdef CONFIG_CIFS_STATS2
46793-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
46794-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
46795+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
46796+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
46797 #endif
46798 GLOBAL_EXTERN atomic_t smBufAllocCount;
46799 GLOBAL_EXTERN atomic_t midCount;
46800diff --git a/fs/cifs/link.c b/fs/cifs/link.c
46801index 51dc2fb..1e12a33 100644
46802--- a/fs/cifs/link.c
46803+++ b/fs/cifs/link.c
46804@@ -616,7 +616,7 @@ symlink_exit:
46805
46806 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
46807 {
46808- char *p = nd_get_link(nd);
46809+ const char *p = nd_get_link(nd);
46810 if (!IS_ERR(p))
46811 kfree(p);
46812 }
46813diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
46814index 3a00c0d..42d901c 100644
46815--- a/fs/cifs/misc.c
46816+++ b/fs/cifs/misc.c
46817@@ -169,7 +169,7 @@ cifs_buf_get(void)
46818 memset(ret_buf, 0, buf_size + 3);
46819 atomic_inc(&bufAllocCount);
46820 #ifdef CONFIG_CIFS_STATS2
46821- atomic_inc(&totBufAllocCount);
46822+ atomic_inc_unchecked(&totBufAllocCount);
46823 #endif /* CONFIG_CIFS_STATS2 */
46824 }
46825
46826@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
46827 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
46828 atomic_inc(&smBufAllocCount);
46829 #ifdef CONFIG_CIFS_STATS2
46830- atomic_inc(&totSmBufAllocCount);
46831+ atomic_inc_unchecked(&totSmBufAllocCount);
46832 #endif /* CONFIG_CIFS_STATS2 */
46833
46834 }
46835diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
46836index 47bc5a8..10decbe 100644
46837--- a/fs/cifs/smb1ops.c
46838+++ b/fs/cifs/smb1ops.c
46839@@ -586,27 +586,27 @@ static void
46840 cifs_clear_stats(struct cifs_tcon *tcon)
46841 {
46842 #ifdef CONFIG_CIFS_STATS
46843- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
46844- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
46845- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
46846- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
46847- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
46848- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
46849- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
46850- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
46851- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
46852- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
46853- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
46854- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
46855- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
46856- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
46857- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
46858- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
46859- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
46860- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
46861- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
46862- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
46863- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
46864+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
46865+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
46866+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
46867+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
46868+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
46869+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
46870+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
46871+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
46872+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
46873+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
46874+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
46875+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
46876+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
46877+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
46878+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
46879+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
46880+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
46881+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
46882+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
46883+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
46884+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
46885 #endif
46886 }
46887
46888@@ -615,36 +615,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
46889 {
46890 #ifdef CONFIG_CIFS_STATS
46891 seq_printf(m, " Oplocks breaks: %d",
46892- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
46893+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
46894 seq_printf(m, "\nReads: %d Bytes: %llu",
46895- atomic_read(&tcon->stats.cifs_stats.num_reads),
46896+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
46897 (long long)(tcon->bytes_read));
46898 seq_printf(m, "\nWrites: %d Bytes: %llu",
46899- atomic_read(&tcon->stats.cifs_stats.num_writes),
46900+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
46901 (long long)(tcon->bytes_written));
46902 seq_printf(m, "\nFlushes: %d",
46903- atomic_read(&tcon->stats.cifs_stats.num_flushes));
46904+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
46905 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
46906- atomic_read(&tcon->stats.cifs_stats.num_locks),
46907- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
46908- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
46909+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
46910+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
46911+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
46912 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
46913- atomic_read(&tcon->stats.cifs_stats.num_opens),
46914- atomic_read(&tcon->stats.cifs_stats.num_closes),
46915- atomic_read(&tcon->stats.cifs_stats.num_deletes));
46916+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
46917+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
46918+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
46919 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
46920- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
46921- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
46922+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
46923+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
46924 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
46925- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
46926- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
46927+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
46928+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
46929 seq_printf(m, "\nRenames: %d T2 Renames %d",
46930- atomic_read(&tcon->stats.cifs_stats.num_renames),
46931- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
46932+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
46933+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
46934 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
46935- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
46936- atomic_read(&tcon->stats.cifs_stats.num_fnext),
46937- atomic_read(&tcon->stats.cifs_stats.num_fclose));
46938+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
46939+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
46940+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
46941 #endif
46942 }
46943
46944diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
46945index c9c7aa7..065056a 100644
46946--- a/fs/cifs/smb2ops.c
46947+++ b/fs/cifs/smb2ops.c
46948@@ -274,8 +274,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
46949 #ifdef CONFIG_CIFS_STATS
46950 int i;
46951 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
46952- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
46953- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
46954+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
46955+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
46956 }
46957 #endif
46958 }
46959@@ -284,66 +284,66 @@ static void
46960 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
46961 {
46962 #ifdef CONFIG_CIFS_STATS
46963- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
46964- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
46965+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
46966+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
46967 seq_printf(m, "\nNegotiates: %d sent %d failed",
46968- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
46969- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
46970+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
46971+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
46972 seq_printf(m, "\nSessionSetups: %d sent %d failed",
46973- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
46974- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
46975+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
46976+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
46977 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
46978 seq_printf(m, "\nLogoffs: %d sent %d failed",
46979- atomic_read(&sent[SMB2_LOGOFF_HE]),
46980- atomic_read(&failed[SMB2_LOGOFF_HE]));
46981+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
46982+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
46983 seq_printf(m, "\nTreeConnects: %d sent %d failed",
46984- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
46985- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
46986+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
46987+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
46988 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
46989- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
46990- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
46991+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
46992+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
46993 seq_printf(m, "\nCreates: %d sent %d failed",
46994- atomic_read(&sent[SMB2_CREATE_HE]),
46995- atomic_read(&failed[SMB2_CREATE_HE]));
46996+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
46997+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
46998 seq_printf(m, "\nCloses: %d sent %d failed",
46999- atomic_read(&sent[SMB2_CLOSE_HE]),
47000- atomic_read(&failed[SMB2_CLOSE_HE]));
47001+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
47002+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
47003 seq_printf(m, "\nFlushes: %d sent %d failed",
47004- atomic_read(&sent[SMB2_FLUSH_HE]),
47005- atomic_read(&failed[SMB2_FLUSH_HE]));
47006+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
47007+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
47008 seq_printf(m, "\nReads: %d sent %d failed",
47009- atomic_read(&sent[SMB2_READ_HE]),
47010- atomic_read(&failed[SMB2_READ_HE]));
47011+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
47012+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
47013 seq_printf(m, "\nWrites: %d sent %d failed",
47014- atomic_read(&sent[SMB2_WRITE_HE]),
47015- atomic_read(&failed[SMB2_WRITE_HE]));
47016+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
47017+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
47018 seq_printf(m, "\nLocks: %d sent %d failed",
47019- atomic_read(&sent[SMB2_LOCK_HE]),
47020- atomic_read(&failed[SMB2_LOCK_HE]));
47021+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
47022+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
47023 seq_printf(m, "\nIOCTLs: %d sent %d failed",
47024- atomic_read(&sent[SMB2_IOCTL_HE]),
47025- atomic_read(&failed[SMB2_IOCTL_HE]));
47026+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
47027+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
47028 seq_printf(m, "\nCancels: %d sent %d failed",
47029- atomic_read(&sent[SMB2_CANCEL_HE]),
47030- atomic_read(&failed[SMB2_CANCEL_HE]));
47031+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
47032+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
47033 seq_printf(m, "\nEchos: %d sent %d failed",
47034- atomic_read(&sent[SMB2_ECHO_HE]),
47035- atomic_read(&failed[SMB2_ECHO_HE]));
47036+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
47037+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
47038 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
47039- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
47040- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
47041+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
47042+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
47043 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
47044- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
47045- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
47046+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
47047+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
47048 seq_printf(m, "\nQueryInfos: %d sent %d failed",
47049- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
47050- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
47051+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
47052+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
47053 seq_printf(m, "\nSetInfos: %d sent %d failed",
47054- atomic_read(&sent[SMB2_SET_INFO_HE]),
47055- atomic_read(&failed[SMB2_SET_INFO_HE]));
47056+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
47057+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
47058 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
47059- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
47060- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
47061+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
47062+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
47063 #endif
47064 }
47065
47066diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
47067index 41d9d07..dbb4772 100644
47068--- a/fs/cifs/smb2pdu.c
47069+++ b/fs/cifs/smb2pdu.c
47070@@ -1761,8 +1761,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
47071 default:
47072 cERROR(1, "info level %u isn't supported",
47073 srch_inf->info_level);
47074- rc = -EINVAL;
47075- goto qdir_exit;
47076+ return -EINVAL;
47077 }
47078
47079 req->FileIndex = cpu_to_le32(index);
47080diff --git a/fs/coda/cache.c b/fs/coda/cache.c
47081index 958ae0e..505c9d0 100644
47082--- a/fs/coda/cache.c
47083+++ b/fs/coda/cache.c
47084@@ -24,7 +24,7 @@
47085 #include "coda_linux.h"
47086 #include "coda_cache.h"
47087
47088-static atomic_t permission_epoch = ATOMIC_INIT(0);
47089+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
47090
47091 /* replace or extend an acl cache hit */
47092 void coda_cache_enter(struct inode *inode, int mask)
47093@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
47094 struct coda_inode_info *cii = ITOC(inode);
47095
47096 spin_lock(&cii->c_lock);
47097- cii->c_cached_epoch = atomic_read(&permission_epoch);
47098+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
47099 if (cii->c_uid != current_fsuid()) {
47100 cii->c_uid = current_fsuid();
47101 cii->c_cached_perm = mask;
47102@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
47103 {
47104 struct coda_inode_info *cii = ITOC(inode);
47105 spin_lock(&cii->c_lock);
47106- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
47107+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
47108 spin_unlock(&cii->c_lock);
47109 }
47110
47111 /* remove all acl caches */
47112 void coda_cache_clear_all(struct super_block *sb)
47113 {
47114- atomic_inc(&permission_epoch);
47115+ atomic_inc_unchecked(&permission_epoch);
47116 }
47117
47118
47119@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
47120 spin_lock(&cii->c_lock);
47121 hit = (mask & cii->c_cached_perm) == mask &&
47122 cii->c_uid == current_fsuid() &&
47123- cii->c_cached_epoch == atomic_read(&permission_epoch);
47124+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
47125 spin_unlock(&cii->c_lock);
47126
47127 return hit;
47128diff --git a/fs/compat.c b/fs/compat.c
47129index 015e1e1..5ce8e54 100644
47130--- a/fs/compat.c
47131+++ b/fs/compat.c
47132@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
47133
47134 set_fs(KERNEL_DS);
47135 /* The __user pointer cast is valid because of the set_fs() */
47136- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
47137+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
47138 set_fs(oldfs);
47139 /* truncating is ok because it's a user address */
47140 if (!ret)
47141@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
47142 goto out;
47143
47144 ret = -EINVAL;
47145- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
47146+ if (nr_segs > UIO_MAXIOV)
47147 goto out;
47148 if (nr_segs > fast_segs) {
47149 ret = -ENOMEM;
47150@@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
47151
47152 struct compat_readdir_callback {
47153 struct compat_old_linux_dirent __user *dirent;
47154+ struct file * file;
47155 int result;
47156 };
47157
47158@@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
47159 buf->result = -EOVERFLOW;
47160 return -EOVERFLOW;
47161 }
47162+
47163+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47164+ return 0;
47165+
47166 buf->result++;
47167 dirent = buf->dirent;
47168 if (!access_ok(VERIFY_WRITE, dirent,
47169@@ -878,6 +883,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
47170
47171 buf.result = 0;
47172 buf.dirent = dirent;
47173+ buf.file = f.file;
47174
47175 error = vfs_readdir(f.file, compat_fillonedir, &buf);
47176 if (buf.result)
47177@@ -897,6 +903,7 @@ struct compat_linux_dirent {
47178 struct compat_getdents_callback {
47179 struct compat_linux_dirent __user *current_dir;
47180 struct compat_linux_dirent __user *previous;
47181+ struct file * file;
47182 int count;
47183 int error;
47184 };
47185@@ -918,6 +925,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
47186 buf->error = -EOVERFLOW;
47187 return -EOVERFLOW;
47188 }
47189+
47190+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47191+ return 0;
47192+
47193 dirent = buf->previous;
47194 if (dirent) {
47195 if (__put_user(offset, &dirent->d_off))
47196@@ -963,6 +974,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
47197 buf.previous = NULL;
47198 buf.count = count;
47199 buf.error = 0;
47200+ buf.file = f.file;
47201
47202 error = vfs_readdir(f.file, compat_filldir, &buf);
47203 if (error >= 0)
47204@@ -983,6 +995,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
47205 struct compat_getdents_callback64 {
47206 struct linux_dirent64 __user *current_dir;
47207 struct linux_dirent64 __user *previous;
47208+ struct file * file;
47209 int count;
47210 int error;
47211 };
47212@@ -999,6 +1012,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
47213 buf->error = -EINVAL; /* only used if we fail.. */
47214 if (reclen > buf->count)
47215 return -EINVAL;
47216+
47217+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47218+ return 0;
47219+
47220 dirent = buf->previous;
47221
47222 if (dirent) {
47223@@ -1048,13 +1065,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
47224 buf.previous = NULL;
47225 buf.count = count;
47226 buf.error = 0;
47227+ buf.file = f.file;
47228
47229 error = vfs_readdir(f.file, compat_filldir64, &buf);
47230 if (error >= 0)
47231 error = buf.error;
47232 lastdirent = buf.previous;
47233 if (lastdirent) {
47234- typeof(lastdirent->d_off) d_off = f.file->f_pos;
47235+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
47236 if (__put_user_unaligned(d_off, &lastdirent->d_off))
47237 error = -EFAULT;
47238 else
47239diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
47240index a81147e..20bf2b5 100644
47241--- a/fs/compat_binfmt_elf.c
47242+++ b/fs/compat_binfmt_elf.c
47243@@ -30,11 +30,13 @@
47244 #undef elf_phdr
47245 #undef elf_shdr
47246 #undef elf_note
47247+#undef elf_dyn
47248 #undef elf_addr_t
47249 #define elfhdr elf32_hdr
47250 #define elf_phdr elf32_phdr
47251 #define elf_shdr elf32_shdr
47252 #define elf_note elf32_note
47253+#define elf_dyn Elf32_Dyn
47254 #define elf_addr_t Elf32_Addr
47255
47256 /*
47257diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
47258index e2f57a0..3c78771 100644
47259--- a/fs/compat_ioctl.c
47260+++ b/fs/compat_ioctl.c
47261@@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
47262 return -EFAULT;
47263 if (__get_user(udata, &ss32->iomem_base))
47264 return -EFAULT;
47265- ss.iomem_base = compat_ptr(udata);
47266+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
47267 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
47268 __get_user(ss.port_high, &ss32->port_high))
47269 return -EFAULT;
47270@@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
47271 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
47272 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
47273 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
47274- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
47275+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
47276 return -EFAULT;
47277
47278 return ioctl_preallocate(file, p);
47279@@ -1620,8 +1620,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
47280 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
47281 {
47282 unsigned int a, b;
47283- a = *(unsigned int *)p;
47284- b = *(unsigned int *)q;
47285+ a = *(const unsigned int *)p;
47286+ b = *(const unsigned int *)q;
47287 if (a > b)
47288 return 1;
47289 if (a < b)
47290diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
47291index 712b10f..c33c4ca 100644
47292--- a/fs/configfs/dir.c
47293+++ b/fs/configfs/dir.c
47294@@ -1037,10 +1037,11 @@ static int configfs_dump(struct configfs_dirent *sd, int level)
47295 static int configfs_depend_prep(struct dentry *origin,
47296 struct config_item *target)
47297 {
47298- struct configfs_dirent *child_sd, *sd = origin->d_fsdata;
47299+ struct configfs_dirent *child_sd, *sd;
47300 int ret = 0;
47301
47302- BUG_ON(!origin || !sd);
47303+ BUG_ON(!origin || !origin->d_fsdata);
47304+ sd = origin->d_fsdata;
47305
47306 if (sd->s_element == target) /* Boo-yah */
47307 goto out;
47308@@ -1564,7 +1565,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
47309 }
47310 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
47311 struct configfs_dirent *next;
47312- const char * name;
47313+ const unsigned char * name;
47314+ char d_name[sizeof(next->s_dentry->d_iname)];
47315 int len;
47316 struct inode *inode = NULL;
47317
47318@@ -1574,7 +1576,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
47319 continue;
47320
47321 name = configfs_get_name(next);
47322- len = strlen(name);
47323+ if (next->s_dentry && name == next->s_dentry->d_iname) {
47324+ len = next->s_dentry->d_name.len;
47325+ memcpy(d_name, name, len);
47326+ name = d_name;
47327+ } else
47328+ len = strlen(name);
47329
47330 /*
47331 * We'll have a dentry and an inode for
47332diff --git a/fs/coredump.c b/fs/coredump.c
47333index 1774932..5812106 100644
47334--- a/fs/coredump.c
47335+++ b/fs/coredump.c
47336@@ -52,7 +52,7 @@ struct core_name {
47337 char *corename;
47338 int used, size;
47339 };
47340-static atomic_t call_count = ATOMIC_INIT(1);
47341+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
47342
47343 /* The maximal length of core_pattern is also specified in sysctl.c */
47344
47345@@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
47346 {
47347 char *old_corename = cn->corename;
47348
47349- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
47350+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
47351 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
47352
47353 if (!cn->corename) {
47354@@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
47355 int pid_in_pattern = 0;
47356 int err = 0;
47357
47358- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
47359+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
47360 cn->corename = kmalloc(cn->size, GFP_KERNEL);
47361 cn->used = 0;
47362
47363@@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
47364 pipe = file->f_path.dentry->d_inode->i_pipe;
47365
47366 pipe_lock(pipe);
47367- pipe->readers++;
47368- pipe->writers--;
47369+ atomic_inc(&pipe->readers);
47370+ atomic_dec(&pipe->writers);
47371
47372- while ((pipe->readers > 1) && (!signal_pending(current))) {
47373+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
47374 wake_up_interruptible_sync(&pipe->wait);
47375 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
47376 pipe_wait(pipe);
47377 }
47378
47379- pipe->readers--;
47380- pipe->writers++;
47381+ atomic_dec(&pipe->readers);
47382+ atomic_inc(&pipe->writers);
47383 pipe_unlock(pipe);
47384
47385 }
47386@@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo)
47387 int ispipe;
47388 struct files_struct *displaced;
47389 bool need_nonrelative = false;
47390- static atomic_t core_dump_count = ATOMIC_INIT(0);
47391+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
47392+ long signr = siginfo->si_signo;
47393 struct coredump_params cprm = {
47394 .siginfo = siginfo,
47395 .regs = signal_pt_regs(),
47396@@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo)
47397 .mm_flags = mm->flags,
47398 };
47399
47400- audit_core_dumps(siginfo->si_signo);
47401+ audit_core_dumps(signr);
47402+
47403+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
47404+ gr_handle_brute_attach(cprm.mm_flags);
47405
47406 binfmt = mm->binfmt;
47407 if (!binfmt || !binfmt->core_dump)
47408@@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo)
47409 need_nonrelative = true;
47410 }
47411
47412- retval = coredump_wait(siginfo->si_signo, &core_state);
47413+ retval = coredump_wait(signr, &core_state);
47414 if (retval < 0)
47415 goto fail_creds;
47416
47417@@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo)
47418 }
47419 cprm.limit = RLIM_INFINITY;
47420
47421- dump_count = atomic_inc_return(&core_dump_count);
47422+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
47423 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
47424 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
47425 task_tgid_vnr(current), current->comm);
47426@@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo)
47427 } else {
47428 struct inode *inode;
47429
47430+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
47431+
47432 if (cprm.limit < binfmt->min_coredump)
47433 goto fail_unlock;
47434
47435@@ -640,7 +646,7 @@ close_fail:
47436 filp_close(cprm.file, NULL);
47437 fail_dropcount:
47438 if (ispipe)
47439- atomic_dec(&core_dump_count);
47440+ atomic_dec_unchecked(&core_dump_count);
47441 fail_unlock:
47442 kfree(cn.corename);
47443 fail_corename:
47444@@ -659,7 +665,7 @@ fail:
47445 */
47446 int dump_write(struct file *file, const void *addr, int nr)
47447 {
47448- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
47449+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
47450 }
47451 EXPORT_SYMBOL(dump_write);
47452
47453diff --git a/fs/dcache.c b/fs/dcache.c
47454index 19153a0..428c2f5 100644
47455--- a/fs/dcache.c
47456+++ b/fs/dcache.c
47457@@ -3133,7 +3133,7 @@ void __init vfs_caches_init(unsigned long mempages)
47458 mempages -= reserve;
47459
47460 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
47461- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
47462+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
47463
47464 dcache_init();
47465 inode_init();
47466diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
47467index a5f12b7..4ee8a6f 100644
47468--- a/fs/debugfs/inode.c
47469+++ b/fs/debugfs/inode.c
47470@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
47471 */
47472 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
47473 {
47474+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
47475+ return __create_file(name, S_IFDIR | S_IRWXU,
47476+#else
47477 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
47478+#endif
47479 parent, NULL, NULL);
47480 }
47481 EXPORT_SYMBOL_GPL(debugfs_create_dir);
47482diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
47483index cc7709e..7e7211f 100644
47484--- a/fs/ecryptfs/inode.c
47485+++ b/fs/ecryptfs/inode.c
47486@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
47487 old_fs = get_fs();
47488 set_fs(get_ds());
47489 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
47490- (char __user *)lower_buf,
47491+ (char __force_user *)lower_buf,
47492 PATH_MAX);
47493 set_fs(old_fs);
47494 if (rc < 0)
47495@@ -706,7 +706,7 @@ out:
47496 static void
47497 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
47498 {
47499- char *buf = nd_get_link(nd);
47500+ const char *buf = nd_get_link(nd);
47501 if (!IS_ERR(buf)) {
47502 /* Free the char* */
47503 kfree(buf);
47504diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
47505index 412e6ed..4292d22 100644
47506--- a/fs/ecryptfs/miscdev.c
47507+++ b/fs/ecryptfs/miscdev.c
47508@@ -315,7 +315,7 @@ check_list:
47509 goto out_unlock_msg_ctx;
47510 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
47511 if (msg_ctx->msg) {
47512- if (copy_to_user(&buf[i], packet_length, packet_length_size))
47513+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
47514 goto out_unlock_msg_ctx;
47515 i += packet_length_size;
47516 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
47517diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
47518index b2a34a1..162fa69 100644
47519--- a/fs/ecryptfs/read_write.c
47520+++ b/fs/ecryptfs/read_write.c
47521@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
47522 return -EIO;
47523 fs_save = get_fs();
47524 set_fs(get_ds());
47525- rc = vfs_write(lower_file, data, size, &offset);
47526+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
47527 set_fs(fs_save);
47528 mark_inode_dirty_sync(ecryptfs_inode);
47529 return rc;
47530@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
47531 return -EIO;
47532 fs_save = get_fs();
47533 set_fs(get_ds());
47534- rc = vfs_read(lower_file, data, size, &offset);
47535+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
47536 set_fs(fs_save);
47537 return rc;
47538 }
47539diff --git a/fs/exec.c b/fs/exec.c
47540index 20df02c..1dff97d 100644
47541--- a/fs/exec.c
47542+++ b/fs/exec.c
47543@@ -55,6 +55,17 @@
47544 #include <linux/pipe_fs_i.h>
47545 #include <linux/oom.h>
47546 #include <linux/compat.h>
47547+#include <linux/random.h>
47548+#include <linux/seq_file.h>
47549+#include <linux/coredump.h>
47550+#include <linux/mman.h>
47551+
47552+#ifdef CONFIG_PAX_REFCOUNT
47553+#include <linux/kallsyms.h>
47554+#include <linux/kdebug.h>
47555+#endif
47556+
47557+#include <trace/events/fs.h>
47558
47559 #include <asm/uaccess.h>
47560 #include <asm/mmu_context.h>
47561@@ -66,6 +77,18 @@
47562
47563 #include <trace/events/sched.h>
47564
47565+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
47566+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
47567+{
47568+ 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");
47569+}
47570+#endif
47571+
47572+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
47573+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
47574+EXPORT_SYMBOL(pax_set_initial_flags_func);
47575+#endif
47576+
47577 int suid_dumpable = 0;
47578
47579 static LIST_HEAD(formats);
47580@@ -180,18 +203,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
47581 int write)
47582 {
47583 struct page *page;
47584- int ret;
47585
47586-#ifdef CONFIG_STACK_GROWSUP
47587- if (write) {
47588- ret = expand_downwards(bprm->vma, pos);
47589- if (ret < 0)
47590- return NULL;
47591- }
47592-#endif
47593- ret = get_user_pages(current, bprm->mm, pos,
47594- 1, write, 1, &page, NULL);
47595- if (ret <= 0)
47596+ if (0 > expand_downwards(bprm->vma, pos))
47597+ return NULL;
47598+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
47599 return NULL;
47600
47601 if (write) {
47602@@ -207,6 +222,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
47603 if (size <= ARG_MAX)
47604 return page;
47605
47606+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47607+ // only allow 512KB for argv+env on suid/sgid binaries
47608+ // to prevent easy ASLR exhaustion
47609+ if (((bprm->cred->euid != current_euid()) ||
47610+ (bprm->cred->egid != current_egid())) &&
47611+ (size > (512 * 1024))) {
47612+ put_page(page);
47613+ return NULL;
47614+ }
47615+#endif
47616+
47617 /*
47618 * Limit to 1/4-th the stack size for the argv+env strings.
47619 * This ensures that:
47620@@ -266,6 +292,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
47621 vma->vm_end = STACK_TOP_MAX;
47622 vma->vm_start = vma->vm_end - PAGE_SIZE;
47623 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
47624+
47625+#ifdef CONFIG_PAX_SEGMEXEC
47626+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
47627+#endif
47628+
47629 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
47630 INIT_LIST_HEAD(&vma->anon_vma_chain);
47631
47632@@ -276,6 +307,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
47633 mm->stack_vm = mm->total_vm = 1;
47634 up_write(&mm->mmap_sem);
47635 bprm->p = vma->vm_end - sizeof(void *);
47636+
47637+#ifdef CONFIG_PAX_RANDUSTACK
47638+ if (randomize_va_space)
47639+ bprm->p ^= random32() & ~PAGE_MASK;
47640+#endif
47641+
47642 return 0;
47643 err:
47644 up_write(&mm->mmap_sem);
47645@@ -384,19 +421,7 @@ err:
47646 return err;
47647 }
47648
47649-struct user_arg_ptr {
47650-#ifdef CONFIG_COMPAT
47651- bool is_compat;
47652-#endif
47653- union {
47654- const char __user *const __user *native;
47655-#ifdef CONFIG_COMPAT
47656- const compat_uptr_t __user *compat;
47657-#endif
47658- } ptr;
47659-};
47660-
47661-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
47662+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
47663 {
47664 const char __user *native;
47665
47666@@ -405,14 +430,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
47667 compat_uptr_t compat;
47668
47669 if (get_user(compat, argv.ptr.compat + nr))
47670- return ERR_PTR(-EFAULT);
47671+ return (const char __force_user *)ERR_PTR(-EFAULT);
47672
47673 return compat_ptr(compat);
47674 }
47675 #endif
47676
47677 if (get_user(native, argv.ptr.native + nr))
47678- return ERR_PTR(-EFAULT);
47679+ return (const char __force_user *)ERR_PTR(-EFAULT);
47680
47681 return native;
47682 }
47683@@ -431,7 +456,7 @@ static int count(struct user_arg_ptr argv, int max)
47684 if (!p)
47685 break;
47686
47687- if (IS_ERR(p))
47688+ if (IS_ERR((const char __force_kernel *)p))
47689 return -EFAULT;
47690
47691 if (i >= max)
47692@@ -466,7 +491,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
47693
47694 ret = -EFAULT;
47695 str = get_user_arg_ptr(argv, argc);
47696- if (IS_ERR(str))
47697+ if (IS_ERR((const char __force_kernel *)str))
47698 goto out;
47699
47700 len = strnlen_user(str, MAX_ARG_STRLEN);
47701@@ -548,7 +573,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
47702 int r;
47703 mm_segment_t oldfs = get_fs();
47704 struct user_arg_ptr argv = {
47705- .ptr.native = (const char __user *const __user *)__argv,
47706+ .ptr.native = (const char __force_user *const __force_user *)__argv,
47707 };
47708
47709 set_fs(KERNEL_DS);
47710@@ -583,7 +608,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
47711 unsigned long new_end = old_end - shift;
47712 struct mmu_gather tlb;
47713
47714- BUG_ON(new_start > new_end);
47715+ if (new_start >= new_end || new_start < mmap_min_addr)
47716+ return -ENOMEM;
47717
47718 /*
47719 * ensure there are no vmas between where we want to go
47720@@ -592,6 +618,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
47721 if (vma != find_vma(mm, new_start))
47722 return -EFAULT;
47723
47724+#ifdef CONFIG_PAX_SEGMEXEC
47725+ BUG_ON(pax_find_mirror_vma(vma));
47726+#endif
47727+
47728 /*
47729 * cover the whole range: [new_start, old_end)
47730 */
47731@@ -672,10 +702,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
47732 stack_top = arch_align_stack(stack_top);
47733 stack_top = PAGE_ALIGN(stack_top);
47734
47735- if (unlikely(stack_top < mmap_min_addr) ||
47736- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
47737- return -ENOMEM;
47738-
47739 stack_shift = vma->vm_end - stack_top;
47740
47741 bprm->p -= stack_shift;
47742@@ -687,8 +713,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
47743 bprm->exec -= stack_shift;
47744
47745 down_write(&mm->mmap_sem);
47746+
47747+ /* Move stack pages down in memory. */
47748+ if (stack_shift) {
47749+ ret = shift_arg_pages(vma, stack_shift);
47750+ if (ret)
47751+ goto out_unlock;
47752+ }
47753+
47754 vm_flags = VM_STACK_FLAGS;
47755
47756+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
47757+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
47758+ vm_flags &= ~VM_EXEC;
47759+
47760+#ifdef CONFIG_PAX_MPROTECT
47761+ if (mm->pax_flags & MF_PAX_MPROTECT)
47762+ vm_flags &= ~VM_MAYEXEC;
47763+#endif
47764+
47765+ }
47766+#endif
47767+
47768 /*
47769 * Adjust stack execute permissions; explicitly enable for
47770 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
47771@@ -707,13 +753,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
47772 goto out_unlock;
47773 BUG_ON(prev != vma);
47774
47775- /* Move stack pages down in memory. */
47776- if (stack_shift) {
47777- ret = shift_arg_pages(vma, stack_shift);
47778- if (ret)
47779- goto out_unlock;
47780- }
47781-
47782 /* mprotect_fixup is overkill to remove the temporary stack flags */
47783 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
47784
47785@@ -737,6 +776,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
47786 #endif
47787 current->mm->start_stack = bprm->p;
47788 ret = expand_stack(vma, stack_base);
47789+
47790+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_ASLR)
47791+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
47792+ unsigned long size, flags, vm_flags;
47793+
47794+ size = STACK_TOP - vma->vm_end;
47795+ flags = MAP_FIXED | MAP_PRIVATE;
47796+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
47797+
47798+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, flags, vm_flags, 0);
47799+
47800+#ifdef CONFIG_X86
47801+ if (!ret) {
47802+ size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
47803+ ret = 0 != mmap_region(NULL, 0, size, flags, vm_flags, 0);
47804+ }
47805+#endif
47806+
47807+ }
47808+#endif
47809+
47810 if (ret)
47811 ret = -EFAULT;
47812
47813@@ -772,6 +832,8 @@ struct file *open_exec(const char *name)
47814
47815 fsnotify_open(file);
47816
47817+ trace_open_exec(name);
47818+
47819 err = deny_write_access(file);
47820 if (err)
47821 goto exit;
47822@@ -795,7 +857,7 @@ int kernel_read(struct file *file, loff_t offset,
47823 old_fs = get_fs();
47824 set_fs(get_ds());
47825 /* The cast to a user pointer is valid due to the set_fs() */
47826- result = vfs_read(file, (void __user *)addr, count, &pos);
47827+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
47828 set_fs(old_fs);
47829 return result;
47830 }
47831@@ -1247,7 +1309,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
47832 }
47833 rcu_read_unlock();
47834
47835- if (p->fs->users > n_fs) {
47836+ if (atomic_read(&p->fs->users) > n_fs) {
47837 bprm->unsafe |= LSM_UNSAFE_SHARE;
47838 } else {
47839 res = -EAGAIN;
47840@@ -1447,6 +1509,28 @@ int search_binary_handler(struct linux_binprm *bprm)
47841
47842 EXPORT_SYMBOL(search_binary_handler);
47843
47844+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47845+static DEFINE_PER_CPU(u64, exec_counter);
47846+static int __init init_exec_counters(void)
47847+{
47848+ unsigned int cpu;
47849+
47850+ for_each_possible_cpu(cpu) {
47851+ per_cpu(exec_counter, cpu) = (u64)cpu;
47852+ }
47853+
47854+ return 0;
47855+}
47856+early_initcall(init_exec_counters);
47857+static inline void increment_exec_counter(void)
47858+{
47859+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
47860+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
47861+}
47862+#else
47863+static inline void increment_exec_counter(void) {}
47864+#endif
47865+
47866 /*
47867 * sys_execve() executes a new program.
47868 */
47869@@ -1454,6 +1538,11 @@ static int do_execve_common(const char *filename,
47870 struct user_arg_ptr argv,
47871 struct user_arg_ptr envp)
47872 {
47873+#ifdef CONFIG_GRKERNSEC
47874+ struct file *old_exec_file;
47875+ struct acl_subject_label *old_acl;
47876+ struct rlimit old_rlim[RLIM_NLIMITS];
47877+#endif
47878 struct linux_binprm *bprm;
47879 struct file *file;
47880 struct files_struct *displaced;
47881@@ -1461,6 +1550,8 @@ static int do_execve_common(const char *filename,
47882 int retval;
47883 const struct cred *cred = current_cred();
47884
47885+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
47886+
47887 /*
47888 * We move the actual failure in case of RLIMIT_NPROC excess from
47889 * set*uid() to execve() because too many poorly written programs
47890@@ -1501,12 +1592,27 @@ static int do_execve_common(const char *filename,
47891 if (IS_ERR(file))
47892 goto out_unmark;
47893
47894+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
47895+ retval = -EPERM;
47896+ goto out_file;
47897+ }
47898+
47899 sched_exec();
47900
47901 bprm->file = file;
47902 bprm->filename = filename;
47903 bprm->interp = filename;
47904
47905+ if (gr_process_user_ban()) {
47906+ retval = -EPERM;
47907+ goto out_file;
47908+ }
47909+
47910+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
47911+ retval = -EACCES;
47912+ goto out_file;
47913+ }
47914+
47915 retval = bprm_mm_init(bprm);
47916 if (retval)
47917 goto out_file;
47918@@ -1523,24 +1629,65 @@ static int do_execve_common(const char *filename,
47919 if (retval < 0)
47920 goto out;
47921
47922+#ifdef CONFIG_GRKERNSEC
47923+ old_acl = current->acl;
47924+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
47925+ old_exec_file = current->exec_file;
47926+ get_file(file);
47927+ current->exec_file = file;
47928+#endif
47929+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47930+ /* limit suid stack to 8MB
47931+ * we saved the old limits above and will restore them if this exec fails
47932+ */
47933+ if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
47934+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
47935+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
47936+#endif
47937+
47938+ if (!gr_tpe_allow(file)) {
47939+ retval = -EACCES;
47940+ goto out_fail;
47941+ }
47942+
47943+ if (gr_check_crash_exec(file)) {
47944+ retval = -EACCES;
47945+ goto out_fail;
47946+ }
47947+
47948+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
47949+ bprm->unsafe);
47950+ if (retval < 0)
47951+ goto out_fail;
47952+
47953 retval = copy_strings_kernel(1, &bprm->filename, bprm);
47954 if (retval < 0)
47955- goto out;
47956+ goto out_fail;
47957
47958 bprm->exec = bprm->p;
47959 retval = copy_strings(bprm->envc, envp, bprm);
47960 if (retval < 0)
47961- goto out;
47962+ goto out_fail;
47963
47964 retval = copy_strings(bprm->argc, argv, bprm);
47965 if (retval < 0)
47966- goto out;
47967+ goto out_fail;
47968+
47969+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
47970+
47971+ gr_handle_exec_args(bprm, argv);
47972
47973 retval = search_binary_handler(bprm);
47974 if (retval < 0)
47975- goto out;
47976+ goto out_fail;
47977+#ifdef CONFIG_GRKERNSEC
47978+ if (old_exec_file)
47979+ fput(old_exec_file);
47980+#endif
47981
47982 /* execve succeeded */
47983+
47984+ increment_exec_counter();
47985 current->fs->in_exec = 0;
47986 current->in_execve = 0;
47987 acct_update_integrals(current);
47988@@ -1549,6 +1696,14 @@ static int do_execve_common(const char *filename,
47989 put_files_struct(displaced);
47990 return retval;
47991
47992+out_fail:
47993+#ifdef CONFIG_GRKERNSEC
47994+ current->acl = old_acl;
47995+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
47996+ fput(current->exec_file);
47997+ current->exec_file = old_exec_file;
47998+#endif
47999+
48000 out:
48001 if (bprm->mm) {
48002 acct_arg_size(bprm, 0);
48003@@ -1697,3 +1852,253 @@ asmlinkage long compat_sys_execve(const char __user * filename,
48004 return error;
48005 }
48006 #endif
48007+
48008+int pax_check_flags(unsigned long *flags)
48009+{
48010+ int retval = 0;
48011+
48012+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
48013+ if (*flags & MF_PAX_SEGMEXEC)
48014+ {
48015+ *flags &= ~MF_PAX_SEGMEXEC;
48016+ retval = -EINVAL;
48017+ }
48018+#endif
48019+
48020+ if ((*flags & MF_PAX_PAGEEXEC)
48021+
48022+#ifdef CONFIG_PAX_PAGEEXEC
48023+ && (*flags & MF_PAX_SEGMEXEC)
48024+#endif
48025+
48026+ )
48027+ {
48028+ *flags &= ~MF_PAX_PAGEEXEC;
48029+ retval = -EINVAL;
48030+ }
48031+
48032+ if ((*flags & MF_PAX_MPROTECT)
48033+
48034+#ifdef CONFIG_PAX_MPROTECT
48035+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
48036+#endif
48037+
48038+ )
48039+ {
48040+ *flags &= ~MF_PAX_MPROTECT;
48041+ retval = -EINVAL;
48042+ }
48043+
48044+ if ((*flags & MF_PAX_EMUTRAMP)
48045+
48046+#ifdef CONFIG_PAX_EMUTRAMP
48047+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
48048+#endif
48049+
48050+ )
48051+ {
48052+ *flags &= ~MF_PAX_EMUTRAMP;
48053+ retval = -EINVAL;
48054+ }
48055+
48056+ return retval;
48057+}
48058+
48059+EXPORT_SYMBOL(pax_check_flags);
48060+
48061+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
48062+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
48063+{
48064+ struct task_struct *tsk = current;
48065+ struct mm_struct *mm = current->mm;
48066+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
48067+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
48068+ char *path_exec = NULL;
48069+ char *path_fault = NULL;
48070+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
48071+ siginfo_t info = { };
48072+
48073+ if (buffer_exec && buffer_fault) {
48074+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
48075+
48076+ down_read(&mm->mmap_sem);
48077+ vma = mm->mmap;
48078+ while (vma && (!vma_exec || !vma_fault)) {
48079+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
48080+ vma_exec = vma;
48081+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
48082+ vma_fault = vma;
48083+ vma = vma->vm_next;
48084+ }
48085+ if (vma_exec) {
48086+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
48087+ if (IS_ERR(path_exec))
48088+ path_exec = "<path too long>";
48089+ else {
48090+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
48091+ if (path_exec) {
48092+ *path_exec = 0;
48093+ path_exec = buffer_exec;
48094+ } else
48095+ path_exec = "<path too long>";
48096+ }
48097+ }
48098+ if (vma_fault) {
48099+ start = vma_fault->vm_start;
48100+ end = vma_fault->vm_end;
48101+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
48102+ if (vma_fault->vm_file) {
48103+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
48104+ if (IS_ERR(path_fault))
48105+ path_fault = "<path too long>";
48106+ else {
48107+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
48108+ if (path_fault) {
48109+ *path_fault = 0;
48110+ path_fault = buffer_fault;
48111+ } else
48112+ path_fault = "<path too long>";
48113+ }
48114+ } else
48115+ path_fault = "<anonymous mapping>";
48116+ }
48117+ up_read(&mm->mmap_sem);
48118+ }
48119+ if (tsk->signal->curr_ip)
48120+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
48121+ else
48122+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
48123+ 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),
48124+ from_kuid(&init_user_ns, task_uid(tsk)), from_kuid(&init_user_ns, task_euid(tsk)), pc, sp);
48125+ free_page((unsigned long)buffer_exec);
48126+ free_page((unsigned long)buffer_fault);
48127+ pax_report_insns(regs, pc, sp);
48128+ info.si_signo = SIGKILL;
48129+ info.si_errno = 0;
48130+ info.si_code = SI_KERNEL;
48131+ info.si_pid = 0;
48132+ info.si_uid = 0;
48133+ do_coredump(&info);
48134+}
48135+#endif
48136+
48137+#ifdef CONFIG_PAX_REFCOUNT
48138+void pax_report_refcount_overflow(struct pt_regs *regs)
48139+{
48140+ if (current->signal->curr_ip)
48141+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
48142+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
48143+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
48144+ else
48145+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
48146+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
48147+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
48148+ show_regs(regs);
48149+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
48150+}
48151+#endif
48152+
48153+#ifdef CONFIG_PAX_USERCOPY
48154+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
48155+static noinline int check_stack_object(const void *obj, unsigned long len)
48156+{
48157+ const void * const stack = task_stack_page(current);
48158+ const void * const stackend = stack + THREAD_SIZE;
48159+
48160+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
48161+ const void *frame = NULL;
48162+ const void *oldframe;
48163+#endif
48164+
48165+ if (obj + len < obj)
48166+ return -1;
48167+
48168+ if (obj + len <= stack || stackend <= obj)
48169+ return 0;
48170+
48171+ if (obj < stack || stackend < obj + len)
48172+ return -1;
48173+
48174+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
48175+ oldframe = __builtin_frame_address(1);
48176+ if (oldframe)
48177+ frame = __builtin_frame_address(2);
48178+ /*
48179+ low ----------------------------------------------> high
48180+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
48181+ ^----------------^
48182+ allow copies only within here
48183+ */
48184+ while (stack <= frame && frame < stackend) {
48185+ /* if obj + len extends past the last frame, this
48186+ check won't pass and the next frame will be 0,
48187+ causing us to bail out and correctly report
48188+ the copy as invalid
48189+ */
48190+ if (obj + len <= frame)
48191+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
48192+ oldframe = frame;
48193+ frame = *(const void * const *)frame;
48194+ }
48195+ return -1;
48196+#else
48197+ return 1;
48198+#endif
48199+}
48200+
48201+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
48202+{
48203+ if (current->signal->curr_ip)
48204+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
48205+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
48206+ else
48207+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
48208+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
48209+ dump_stack();
48210+ gr_handle_kernel_exploit();
48211+ do_group_exit(SIGKILL);
48212+}
48213+#endif
48214+
48215+void __check_object_size(const void *ptr, unsigned long n, bool to)
48216+{
48217+
48218+#ifdef CONFIG_PAX_USERCOPY
48219+ const char *type;
48220+
48221+ if (!n)
48222+ return;
48223+
48224+ type = check_heap_object(ptr, n);
48225+ if (!type) {
48226+ if (check_stack_object(ptr, n) != -1)
48227+ return;
48228+ type = "<process stack>";
48229+ }
48230+
48231+ pax_report_usercopy(ptr, n, to, type);
48232+#endif
48233+
48234+}
48235+EXPORT_SYMBOL(__check_object_size);
48236+
48237+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
48238+void pax_track_stack(void)
48239+{
48240+ unsigned long sp = (unsigned long)&sp;
48241+ if (sp < current_thread_info()->lowest_stack &&
48242+ sp > (unsigned long)task_stack_page(current))
48243+ current_thread_info()->lowest_stack = sp;
48244+}
48245+EXPORT_SYMBOL(pax_track_stack);
48246+#endif
48247+
48248+#ifdef CONFIG_PAX_SIZE_OVERFLOW
48249+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
48250+{
48251+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
48252+ dump_stack();
48253+ do_group_exit(SIGKILL);
48254+}
48255+EXPORT_SYMBOL(report_size_overflow);
48256+#endif
48257diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
48258index 2616d0e..2ffdec9 100644
48259--- a/fs/ext2/balloc.c
48260+++ b/fs/ext2/balloc.c
48261@@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
48262
48263 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
48264 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
48265- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
48266+ if (free_blocks < root_blocks + 1 &&
48267 !uid_eq(sbi->s_resuid, current_fsuid()) &&
48268 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
48269- !in_group_p (sbi->s_resgid))) {
48270+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
48271 return 0;
48272 }
48273 return 1;
48274diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
48275index 22548f5..41521d8 100644
48276--- a/fs/ext3/balloc.c
48277+++ b/fs/ext3/balloc.c
48278@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
48279
48280 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
48281 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
48282- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
48283+ if (free_blocks < root_blocks + 1 &&
48284 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
48285 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
48286- !in_group_p (sbi->s_resgid))) {
48287+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
48288 return 0;
48289 }
48290 return 1;
48291diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
48292index cf18217..8f6b9c3 100644
48293--- a/fs/ext4/balloc.c
48294+++ b/fs/ext4/balloc.c
48295@@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
48296 /* Hm, nope. Are (enough) root reserved clusters available? */
48297 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
48298 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
48299- capable(CAP_SYS_RESOURCE) ||
48300- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
48301+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
48302+ capable_nolog(CAP_SYS_RESOURCE)) {
48303
48304 if (free_clusters >= (nclusters + dirty_clusters))
48305 return 1;
48306diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
48307index 8462eb3..4a71af6 100644
48308--- a/fs/ext4/ext4.h
48309+++ b/fs/ext4/ext4.h
48310@@ -1265,19 +1265,19 @@ struct ext4_sb_info {
48311 unsigned long s_mb_last_start;
48312
48313 /* stats for buddy allocator */
48314- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
48315- atomic_t s_bal_success; /* we found long enough chunks */
48316- atomic_t s_bal_allocated; /* in blocks */
48317- atomic_t s_bal_ex_scanned; /* total extents scanned */
48318- atomic_t s_bal_goals; /* goal hits */
48319- atomic_t s_bal_breaks; /* too long searches */
48320- atomic_t s_bal_2orders; /* 2^order hits */
48321+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
48322+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
48323+ atomic_unchecked_t s_bal_allocated; /* in blocks */
48324+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
48325+ atomic_unchecked_t s_bal_goals; /* goal hits */
48326+ atomic_unchecked_t s_bal_breaks; /* too long searches */
48327+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
48328 spinlock_t s_bal_lock;
48329 unsigned long s_mb_buddies_generated;
48330 unsigned long long s_mb_generation_time;
48331- atomic_t s_mb_lost_chunks;
48332- atomic_t s_mb_preallocated;
48333- atomic_t s_mb_discarded;
48334+ atomic_unchecked_t s_mb_lost_chunks;
48335+ atomic_unchecked_t s_mb_preallocated;
48336+ atomic_unchecked_t s_mb_discarded;
48337 atomic_t s_lock_busy;
48338
48339 /* locality groups */
48340diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
48341index 1bf6fe7..1a5bdef 100644
48342--- a/fs/ext4/mballoc.c
48343+++ b/fs/ext4/mballoc.c
48344@@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
48345 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
48346
48347 if (EXT4_SB(sb)->s_mb_stats)
48348- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
48349+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
48350
48351 break;
48352 }
48353@@ -2044,7 +2044,7 @@ repeat:
48354 ac->ac_status = AC_STATUS_CONTINUE;
48355 ac->ac_flags |= EXT4_MB_HINT_FIRST;
48356 cr = 3;
48357- atomic_inc(&sbi->s_mb_lost_chunks);
48358+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
48359 goto repeat;
48360 }
48361 }
48362@@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
48363 if (sbi->s_mb_stats) {
48364 ext4_msg(sb, KERN_INFO,
48365 "mballoc: %u blocks %u reqs (%u success)",
48366- atomic_read(&sbi->s_bal_allocated),
48367- atomic_read(&sbi->s_bal_reqs),
48368- atomic_read(&sbi->s_bal_success));
48369+ atomic_read_unchecked(&sbi->s_bal_allocated),
48370+ atomic_read_unchecked(&sbi->s_bal_reqs),
48371+ atomic_read_unchecked(&sbi->s_bal_success));
48372 ext4_msg(sb, KERN_INFO,
48373 "mballoc: %u extents scanned, %u goal hits, "
48374 "%u 2^N hits, %u breaks, %u lost",
48375- atomic_read(&sbi->s_bal_ex_scanned),
48376- atomic_read(&sbi->s_bal_goals),
48377- atomic_read(&sbi->s_bal_2orders),
48378- atomic_read(&sbi->s_bal_breaks),
48379- atomic_read(&sbi->s_mb_lost_chunks));
48380+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
48381+ atomic_read_unchecked(&sbi->s_bal_goals),
48382+ atomic_read_unchecked(&sbi->s_bal_2orders),
48383+ atomic_read_unchecked(&sbi->s_bal_breaks),
48384+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
48385 ext4_msg(sb, KERN_INFO,
48386 "mballoc: %lu generated and it took %Lu",
48387 sbi->s_mb_buddies_generated,
48388 sbi->s_mb_generation_time);
48389 ext4_msg(sb, KERN_INFO,
48390 "mballoc: %u preallocated, %u discarded",
48391- atomic_read(&sbi->s_mb_preallocated),
48392- atomic_read(&sbi->s_mb_discarded));
48393+ atomic_read_unchecked(&sbi->s_mb_preallocated),
48394+ atomic_read_unchecked(&sbi->s_mb_discarded));
48395 }
48396
48397 free_percpu(sbi->s_locality_groups);
48398@@ -3060,16 +3060,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
48399 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
48400
48401 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
48402- atomic_inc(&sbi->s_bal_reqs);
48403- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
48404+ atomic_inc_unchecked(&sbi->s_bal_reqs);
48405+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
48406 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
48407- atomic_inc(&sbi->s_bal_success);
48408- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
48409+ atomic_inc_unchecked(&sbi->s_bal_success);
48410+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
48411 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
48412 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
48413- atomic_inc(&sbi->s_bal_goals);
48414+ atomic_inc_unchecked(&sbi->s_bal_goals);
48415 if (ac->ac_found > sbi->s_mb_max_to_scan)
48416- atomic_inc(&sbi->s_bal_breaks);
48417+ atomic_inc_unchecked(&sbi->s_bal_breaks);
48418 }
48419
48420 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
48421@@ -3469,7 +3469,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
48422 trace_ext4_mb_new_inode_pa(ac, pa);
48423
48424 ext4_mb_use_inode_pa(ac, pa);
48425- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
48426+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
48427
48428 ei = EXT4_I(ac->ac_inode);
48429 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
48430@@ -3529,7 +3529,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
48431 trace_ext4_mb_new_group_pa(ac, pa);
48432
48433 ext4_mb_use_group_pa(ac, pa);
48434- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
48435+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
48436
48437 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
48438 lg = ac->ac_lg;
48439@@ -3618,7 +3618,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
48440 * from the bitmap and continue.
48441 */
48442 }
48443- atomic_add(free, &sbi->s_mb_discarded);
48444+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
48445
48446 return err;
48447 }
48448@@ -3636,7 +3636,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
48449 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
48450 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
48451 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
48452- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
48453+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
48454 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
48455
48456 return 0;
48457diff --git a/fs/fcntl.c b/fs/fcntl.c
48458index 71a600a..20d87b1 100644
48459--- a/fs/fcntl.c
48460+++ b/fs/fcntl.c
48461@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
48462 if (err)
48463 return err;
48464
48465+ if (gr_handle_chroot_fowner(pid, type))
48466+ return -ENOENT;
48467+ if (gr_check_protected_task_fowner(pid, type))
48468+ return -EACCES;
48469+
48470 f_modown(filp, pid, type, force);
48471 return 0;
48472 }
48473diff --git a/fs/fhandle.c b/fs/fhandle.c
48474index 999ff5c..41f4109 100644
48475--- a/fs/fhandle.c
48476+++ b/fs/fhandle.c
48477@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
48478 } else
48479 retval = 0;
48480 /* copy the mount id */
48481- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
48482- sizeof(*mnt_id)) ||
48483+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
48484 copy_to_user(ufh, handle,
48485 sizeof(struct file_handle) + handle_bytes))
48486 retval = -EFAULT;
48487diff --git a/fs/fifo.c b/fs/fifo.c
48488index cf6f434..3d7942c 100644
48489--- a/fs/fifo.c
48490+++ b/fs/fifo.c
48491@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
48492 */
48493 filp->f_op = &read_pipefifo_fops;
48494 pipe->r_counter++;
48495- if (pipe->readers++ == 0)
48496+ if (atomic_inc_return(&pipe->readers) == 1)
48497 wake_up_partner(inode);
48498
48499- if (!pipe->writers) {
48500+ if (!atomic_read(&pipe->writers)) {
48501 if ((filp->f_flags & O_NONBLOCK)) {
48502 /* suppress POLLHUP until we have
48503 * seen a writer */
48504@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
48505 * errno=ENXIO when there is no process reading the FIFO.
48506 */
48507 ret = -ENXIO;
48508- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
48509+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
48510 goto err;
48511
48512 filp->f_op = &write_pipefifo_fops;
48513 pipe->w_counter++;
48514- if (!pipe->writers++)
48515+ if (atomic_inc_return(&pipe->writers) == 1)
48516 wake_up_partner(inode);
48517
48518- if (!pipe->readers) {
48519+ if (!atomic_read(&pipe->readers)) {
48520 if (wait_for_partner(inode, &pipe->r_counter))
48521 goto err_wr;
48522 }
48523@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
48524 */
48525 filp->f_op = &rdwr_pipefifo_fops;
48526
48527- pipe->readers++;
48528- pipe->writers++;
48529+ atomic_inc(&pipe->readers);
48530+ atomic_inc(&pipe->writers);
48531 pipe->r_counter++;
48532 pipe->w_counter++;
48533- if (pipe->readers == 1 || pipe->writers == 1)
48534+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
48535 wake_up_partner(inode);
48536 break;
48537
48538@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
48539 return 0;
48540
48541 err_rd:
48542- if (!--pipe->readers)
48543+ if (atomic_dec_and_test(&pipe->readers))
48544 wake_up_interruptible(&pipe->wait);
48545 ret = -ERESTARTSYS;
48546 goto err;
48547
48548 err_wr:
48549- if (!--pipe->writers)
48550+ if (atomic_dec_and_test(&pipe->writers))
48551 wake_up_interruptible(&pipe->wait);
48552 ret = -ERESTARTSYS;
48553 goto err;
48554
48555 err:
48556- if (!pipe->readers && !pipe->writers)
48557+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
48558 free_pipe_info(inode);
48559
48560 err_nocleanup:
48561diff --git a/fs/file.c b/fs/file.c
48562index 2b3570b..c57924b 100644
48563--- a/fs/file.c
48564+++ b/fs/file.c
48565@@ -16,6 +16,7 @@
48566 #include <linux/slab.h>
48567 #include <linux/vmalloc.h>
48568 #include <linux/file.h>
48569+#include <linux/security.h>
48570 #include <linux/fdtable.h>
48571 #include <linux/bitops.h>
48572 #include <linux/interrupt.h>
48573@@ -892,6 +893,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
48574 if (!file)
48575 return __close_fd(files, fd);
48576
48577+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
48578 if (fd >= rlimit(RLIMIT_NOFILE))
48579 return -EBADF;
48580
48581@@ -918,6 +920,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
48582 if (unlikely(oldfd == newfd))
48583 return -EINVAL;
48584
48585+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
48586 if (newfd >= rlimit(RLIMIT_NOFILE))
48587 return -EBADF;
48588
48589@@ -973,6 +976,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
48590 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
48591 {
48592 int err;
48593+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
48594 if (from >= rlimit(RLIMIT_NOFILE))
48595 return -EINVAL;
48596 err = alloc_fd(from, flags);
48597diff --git a/fs/filesystems.c b/fs/filesystems.c
48598index da165f6..3671bdb 100644
48599--- a/fs/filesystems.c
48600+++ b/fs/filesystems.c
48601@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
48602 int len = dot ? dot - name : strlen(name);
48603
48604 fs = __get_fs_type(name, len);
48605+
48606+#ifdef CONFIG_GRKERNSEC_MODHARDEN
48607+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
48608+#else
48609 if (!fs && (request_module("%.*s", len, name) == 0))
48610+#endif
48611 fs = __get_fs_type(name, len);
48612
48613 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
48614diff --git a/fs/fs_struct.c b/fs/fs_struct.c
48615index fe6ca58..65318cf 100644
48616--- a/fs/fs_struct.c
48617+++ b/fs/fs_struct.c
48618@@ -4,6 +4,7 @@
48619 #include <linux/path.h>
48620 #include <linux/slab.h>
48621 #include <linux/fs_struct.h>
48622+#include <linux/grsecurity.h>
48623 #include "internal.h"
48624
48625 /*
48626@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
48627 write_seqcount_begin(&fs->seq);
48628 old_root = fs->root;
48629 fs->root = *path;
48630+ gr_set_chroot_entries(current, path);
48631 write_seqcount_end(&fs->seq);
48632 spin_unlock(&fs->lock);
48633 if (old_root.dentry)
48634@@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
48635 return 1;
48636 }
48637
48638+static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
48639+{
48640+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
48641+ return 0;
48642+ *p = *new;
48643+
48644+ /* This function is only called from pivot_root(). Leave our
48645+ gr_chroot_dentry and is_chrooted flags as-is, so that a
48646+ pivoted root isn't treated as a chroot
48647+ */
48648+ //gr_set_chroot_entries(task, new);
48649+
48650+ return 1;
48651+}
48652+
48653 void chroot_fs_refs(struct path *old_root, struct path *new_root)
48654 {
48655 struct task_struct *g, *p;
48656@@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
48657 int hits = 0;
48658 spin_lock(&fs->lock);
48659 write_seqcount_begin(&fs->seq);
48660- hits += replace_path(&fs->root, old_root, new_root);
48661+ hits += replace_root_path(p, &fs->root, old_root, new_root);
48662 hits += replace_path(&fs->pwd, old_root, new_root);
48663 write_seqcount_end(&fs->seq);
48664 while (hits--) {
48665@@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
48666 task_lock(tsk);
48667 spin_lock(&fs->lock);
48668 tsk->fs = NULL;
48669- kill = !--fs->users;
48670+ gr_clear_chroot_entries(tsk);
48671+ kill = !atomic_dec_return(&fs->users);
48672 spin_unlock(&fs->lock);
48673 task_unlock(tsk);
48674 if (kill)
48675@@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
48676 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
48677 /* We don't need to lock fs - think why ;-) */
48678 if (fs) {
48679- fs->users = 1;
48680+ atomic_set(&fs->users, 1);
48681 fs->in_exec = 0;
48682 spin_lock_init(&fs->lock);
48683 seqcount_init(&fs->seq);
48684@@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
48685 spin_lock(&old->lock);
48686 fs->root = old->root;
48687 path_get(&fs->root);
48688+ /* instead of calling gr_set_chroot_entries here,
48689+ we call it from every caller of this function
48690+ */
48691 fs->pwd = old->pwd;
48692 path_get(&fs->pwd);
48693 spin_unlock(&old->lock);
48694@@ -139,8 +160,9 @@ int unshare_fs_struct(void)
48695
48696 task_lock(current);
48697 spin_lock(&fs->lock);
48698- kill = !--fs->users;
48699+ kill = !atomic_dec_return(&fs->users);
48700 current->fs = new_fs;
48701+ gr_set_chroot_entries(current, &new_fs->root);
48702 spin_unlock(&fs->lock);
48703 task_unlock(current);
48704
48705@@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
48706
48707 int current_umask(void)
48708 {
48709- return current->fs->umask;
48710+ return current->fs->umask | gr_acl_umask();
48711 }
48712 EXPORT_SYMBOL(current_umask);
48713
48714 /* to be mentioned only in INIT_TASK */
48715 struct fs_struct init_fs = {
48716- .users = 1,
48717+ .users = ATOMIC_INIT(1),
48718 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
48719 .seq = SEQCNT_ZERO,
48720 .umask = 0022,
48721diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
48722index 8dcb114..b1072e2 100644
48723--- a/fs/fscache/cookie.c
48724+++ b/fs/fscache/cookie.c
48725@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
48726 parent ? (char *) parent->def->name : "<no-parent>",
48727 def->name, netfs_data);
48728
48729- fscache_stat(&fscache_n_acquires);
48730+ fscache_stat_unchecked(&fscache_n_acquires);
48731
48732 /* if there's no parent cookie, then we don't create one here either */
48733 if (!parent) {
48734- fscache_stat(&fscache_n_acquires_null);
48735+ fscache_stat_unchecked(&fscache_n_acquires_null);
48736 _leave(" [no parent]");
48737 return NULL;
48738 }
48739@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
48740 /* allocate and initialise a cookie */
48741 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
48742 if (!cookie) {
48743- fscache_stat(&fscache_n_acquires_oom);
48744+ fscache_stat_unchecked(&fscache_n_acquires_oom);
48745 _leave(" [ENOMEM]");
48746 return NULL;
48747 }
48748@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
48749
48750 switch (cookie->def->type) {
48751 case FSCACHE_COOKIE_TYPE_INDEX:
48752- fscache_stat(&fscache_n_cookie_index);
48753+ fscache_stat_unchecked(&fscache_n_cookie_index);
48754 break;
48755 case FSCACHE_COOKIE_TYPE_DATAFILE:
48756- fscache_stat(&fscache_n_cookie_data);
48757+ fscache_stat_unchecked(&fscache_n_cookie_data);
48758 break;
48759 default:
48760- fscache_stat(&fscache_n_cookie_special);
48761+ fscache_stat_unchecked(&fscache_n_cookie_special);
48762 break;
48763 }
48764
48765@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
48766 if (fscache_acquire_non_index_cookie(cookie) < 0) {
48767 atomic_dec(&parent->n_children);
48768 __fscache_cookie_put(cookie);
48769- fscache_stat(&fscache_n_acquires_nobufs);
48770+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
48771 _leave(" = NULL");
48772 return NULL;
48773 }
48774 }
48775
48776- fscache_stat(&fscache_n_acquires_ok);
48777+ fscache_stat_unchecked(&fscache_n_acquires_ok);
48778 _leave(" = %p", cookie);
48779 return cookie;
48780 }
48781@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
48782 cache = fscache_select_cache_for_object(cookie->parent);
48783 if (!cache) {
48784 up_read(&fscache_addremove_sem);
48785- fscache_stat(&fscache_n_acquires_no_cache);
48786+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
48787 _leave(" = -ENOMEDIUM [no cache]");
48788 return -ENOMEDIUM;
48789 }
48790@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
48791 object = cache->ops->alloc_object(cache, cookie);
48792 fscache_stat_d(&fscache_n_cop_alloc_object);
48793 if (IS_ERR(object)) {
48794- fscache_stat(&fscache_n_object_no_alloc);
48795+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
48796 ret = PTR_ERR(object);
48797 goto error;
48798 }
48799
48800- fscache_stat(&fscache_n_object_alloc);
48801+ fscache_stat_unchecked(&fscache_n_object_alloc);
48802
48803 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
48804
48805@@ -378,7 +378,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
48806
48807 _enter("{%s}", cookie->def->name);
48808
48809- fscache_stat(&fscache_n_invalidates);
48810+ fscache_stat_unchecked(&fscache_n_invalidates);
48811
48812 /* Only permit invalidation of data files. Invalidating an index will
48813 * require the caller to release all its attachments to the tree rooted
48814@@ -437,10 +437,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
48815 struct fscache_object *object;
48816 struct hlist_node *_p;
48817
48818- fscache_stat(&fscache_n_updates);
48819+ fscache_stat_unchecked(&fscache_n_updates);
48820
48821 if (!cookie) {
48822- fscache_stat(&fscache_n_updates_null);
48823+ fscache_stat_unchecked(&fscache_n_updates_null);
48824 _leave(" [no cookie]");
48825 return;
48826 }
48827@@ -474,12 +474,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
48828 struct fscache_object *object;
48829 unsigned long event;
48830
48831- fscache_stat(&fscache_n_relinquishes);
48832+ fscache_stat_unchecked(&fscache_n_relinquishes);
48833 if (retire)
48834- fscache_stat(&fscache_n_relinquishes_retire);
48835+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
48836
48837 if (!cookie) {
48838- fscache_stat(&fscache_n_relinquishes_null);
48839+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
48840 _leave(" [no cookie]");
48841 return;
48842 }
48843@@ -495,7 +495,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
48844
48845 /* wait for the cookie to finish being instantiated (or to fail) */
48846 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
48847- fscache_stat(&fscache_n_relinquishes_waitcrt);
48848+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
48849 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
48850 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
48851 }
48852diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
48853index ee38fef..0a326d4 100644
48854--- a/fs/fscache/internal.h
48855+++ b/fs/fscache/internal.h
48856@@ -148,101 +148,101 @@ extern void fscache_proc_cleanup(void);
48857 * stats.c
48858 */
48859 #ifdef CONFIG_FSCACHE_STATS
48860-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
48861-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
48862+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
48863+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
48864
48865-extern atomic_t fscache_n_op_pend;
48866-extern atomic_t fscache_n_op_run;
48867-extern atomic_t fscache_n_op_enqueue;
48868-extern atomic_t fscache_n_op_deferred_release;
48869-extern atomic_t fscache_n_op_release;
48870-extern atomic_t fscache_n_op_gc;
48871-extern atomic_t fscache_n_op_cancelled;
48872-extern atomic_t fscache_n_op_rejected;
48873+extern atomic_unchecked_t fscache_n_op_pend;
48874+extern atomic_unchecked_t fscache_n_op_run;
48875+extern atomic_unchecked_t fscache_n_op_enqueue;
48876+extern atomic_unchecked_t fscache_n_op_deferred_release;
48877+extern atomic_unchecked_t fscache_n_op_release;
48878+extern atomic_unchecked_t fscache_n_op_gc;
48879+extern atomic_unchecked_t fscache_n_op_cancelled;
48880+extern atomic_unchecked_t fscache_n_op_rejected;
48881
48882-extern atomic_t fscache_n_attr_changed;
48883-extern atomic_t fscache_n_attr_changed_ok;
48884-extern atomic_t fscache_n_attr_changed_nobufs;
48885-extern atomic_t fscache_n_attr_changed_nomem;
48886-extern atomic_t fscache_n_attr_changed_calls;
48887+extern atomic_unchecked_t fscache_n_attr_changed;
48888+extern atomic_unchecked_t fscache_n_attr_changed_ok;
48889+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
48890+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
48891+extern atomic_unchecked_t fscache_n_attr_changed_calls;
48892
48893-extern atomic_t fscache_n_allocs;
48894-extern atomic_t fscache_n_allocs_ok;
48895-extern atomic_t fscache_n_allocs_wait;
48896-extern atomic_t fscache_n_allocs_nobufs;
48897-extern atomic_t fscache_n_allocs_intr;
48898-extern atomic_t fscache_n_allocs_object_dead;
48899-extern atomic_t fscache_n_alloc_ops;
48900-extern atomic_t fscache_n_alloc_op_waits;
48901+extern atomic_unchecked_t fscache_n_allocs;
48902+extern atomic_unchecked_t fscache_n_allocs_ok;
48903+extern atomic_unchecked_t fscache_n_allocs_wait;
48904+extern atomic_unchecked_t fscache_n_allocs_nobufs;
48905+extern atomic_unchecked_t fscache_n_allocs_intr;
48906+extern atomic_unchecked_t fscache_n_allocs_object_dead;
48907+extern atomic_unchecked_t fscache_n_alloc_ops;
48908+extern atomic_unchecked_t fscache_n_alloc_op_waits;
48909
48910-extern atomic_t fscache_n_retrievals;
48911-extern atomic_t fscache_n_retrievals_ok;
48912-extern atomic_t fscache_n_retrievals_wait;
48913-extern atomic_t fscache_n_retrievals_nodata;
48914-extern atomic_t fscache_n_retrievals_nobufs;
48915-extern atomic_t fscache_n_retrievals_intr;
48916-extern atomic_t fscache_n_retrievals_nomem;
48917-extern atomic_t fscache_n_retrievals_object_dead;
48918-extern atomic_t fscache_n_retrieval_ops;
48919-extern atomic_t fscache_n_retrieval_op_waits;
48920+extern atomic_unchecked_t fscache_n_retrievals;
48921+extern atomic_unchecked_t fscache_n_retrievals_ok;
48922+extern atomic_unchecked_t fscache_n_retrievals_wait;
48923+extern atomic_unchecked_t fscache_n_retrievals_nodata;
48924+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
48925+extern atomic_unchecked_t fscache_n_retrievals_intr;
48926+extern atomic_unchecked_t fscache_n_retrievals_nomem;
48927+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
48928+extern atomic_unchecked_t fscache_n_retrieval_ops;
48929+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
48930
48931-extern atomic_t fscache_n_stores;
48932-extern atomic_t fscache_n_stores_ok;
48933-extern atomic_t fscache_n_stores_again;
48934-extern atomic_t fscache_n_stores_nobufs;
48935-extern atomic_t fscache_n_stores_oom;
48936-extern atomic_t fscache_n_store_ops;
48937-extern atomic_t fscache_n_store_calls;
48938-extern atomic_t fscache_n_store_pages;
48939-extern atomic_t fscache_n_store_radix_deletes;
48940-extern atomic_t fscache_n_store_pages_over_limit;
48941+extern atomic_unchecked_t fscache_n_stores;
48942+extern atomic_unchecked_t fscache_n_stores_ok;
48943+extern atomic_unchecked_t fscache_n_stores_again;
48944+extern atomic_unchecked_t fscache_n_stores_nobufs;
48945+extern atomic_unchecked_t fscache_n_stores_oom;
48946+extern atomic_unchecked_t fscache_n_store_ops;
48947+extern atomic_unchecked_t fscache_n_store_calls;
48948+extern atomic_unchecked_t fscache_n_store_pages;
48949+extern atomic_unchecked_t fscache_n_store_radix_deletes;
48950+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
48951
48952-extern atomic_t fscache_n_store_vmscan_not_storing;
48953-extern atomic_t fscache_n_store_vmscan_gone;
48954-extern atomic_t fscache_n_store_vmscan_busy;
48955-extern atomic_t fscache_n_store_vmscan_cancelled;
48956-extern atomic_t fscache_n_store_vmscan_wait;
48957+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
48958+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
48959+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
48960+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
48961+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
48962
48963-extern atomic_t fscache_n_marks;
48964-extern atomic_t fscache_n_uncaches;
48965+extern atomic_unchecked_t fscache_n_marks;
48966+extern atomic_unchecked_t fscache_n_uncaches;
48967
48968-extern atomic_t fscache_n_acquires;
48969-extern atomic_t fscache_n_acquires_null;
48970-extern atomic_t fscache_n_acquires_no_cache;
48971-extern atomic_t fscache_n_acquires_ok;
48972-extern atomic_t fscache_n_acquires_nobufs;
48973-extern atomic_t fscache_n_acquires_oom;
48974+extern atomic_unchecked_t fscache_n_acquires;
48975+extern atomic_unchecked_t fscache_n_acquires_null;
48976+extern atomic_unchecked_t fscache_n_acquires_no_cache;
48977+extern atomic_unchecked_t fscache_n_acquires_ok;
48978+extern atomic_unchecked_t fscache_n_acquires_nobufs;
48979+extern atomic_unchecked_t fscache_n_acquires_oom;
48980
48981-extern atomic_t fscache_n_invalidates;
48982-extern atomic_t fscache_n_invalidates_run;
48983+extern atomic_unchecked_t fscache_n_invalidates;
48984+extern atomic_unchecked_t fscache_n_invalidates_run;
48985
48986-extern atomic_t fscache_n_updates;
48987-extern atomic_t fscache_n_updates_null;
48988-extern atomic_t fscache_n_updates_run;
48989+extern atomic_unchecked_t fscache_n_updates;
48990+extern atomic_unchecked_t fscache_n_updates_null;
48991+extern atomic_unchecked_t fscache_n_updates_run;
48992
48993-extern atomic_t fscache_n_relinquishes;
48994-extern atomic_t fscache_n_relinquishes_null;
48995-extern atomic_t fscache_n_relinquishes_waitcrt;
48996-extern atomic_t fscache_n_relinquishes_retire;
48997+extern atomic_unchecked_t fscache_n_relinquishes;
48998+extern atomic_unchecked_t fscache_n_relinquishes_null;
48999+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
49000+extern atomic_unchecked_t fscache_n_relinquishes_retire;
49001
49002-extern atomic_t fscache_n_cookie_index;
49003-extern atomic_t fscache_n_cookie_data;
49004-extern atomic_t fscache_n_cookie_special;
49005+extern atomic_unchecked_t fscache_n_cookie_index;
49006+extern atomic_unchecked_t fscache_n_cookie_data;
49007+extern atomic_unchecked_t fscache_n_cookie_special;
49008
49009-extern atomic_t fscache_n_object_alloc;
49010-extern atomic_t fscache_n_object_no_alloc;
49011-extern atomic_t fscache_n_object_lookups;
49012-extern atomic_t fscache_n_object_lookups_negative;
49013-extern atomic_t fscache_n_object_lookups_positive;
49014-extern atomic_t fscache_n_object_lookups_timed_out;
49015-extern atomic_t fscache_n_object_created;
49016-extern atomic_t fscache_n_object_avail;
49017-extern atomic_t fscache_n_object_dead;
49018+extern atomic_unchecked_t fscache_n_object_alloc;
49019+extern atomic_unchecked_t fscache_n_object_no_alloc;
49020+extern atomic_unchecked_t fscache_n_object_lookups;
49021+extern atomic_unchecked_t fscache_n_object_lookups_negative;
49022+extern atomic_unchecked_t fscache_n_object_lookups_positive;
49023+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
49024+extern atomic_unchecked_t fscache_n_object_created;
49025+extern atomic_unchecked_t fscache_n_object_avail;
49026+extern atomic_unchecked_t fscache_n_object_dead;
49027
49028-extern atomic_t fscache_n_checkaux_none;
49029-extern atomic_t fscache_n_checkaux_okay;
49030-extern atomic_t fscache_n_checkaux_update;
49031-extern atomic_t fscache_n_checkaux_obsolete;
49032+extern atomic_unchecked_t fscache_n_checkaux_none;
49033+extern atomic_unchecked_t fscache_n_checkaux_okay;
49034+extern atomic_unchecked_t fscache_n_checkaux_update;
49035+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
49036
49037 extern atomic_t fscache_n_cop_alloc_object;
49038 extern atomic_t fscache_n_cop_lookup_object;
49039@@ -267,6 +267,11 @@ static inline void fscache_stat(atomic_t *stat)
49040 atomic_inc(stat);
49041 }
49042
49043+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
49044+{
49045+ atomic_inc_unchecked(stat);
49046+}
49047+
49048 static inline void fscache_stat_d(atomic_t *stat)
49049 {
49050 atomic_dec(stat);
49051@@ -279,6 +284,7 @@ extern const struct file_operations fscache_stats_fops;
49052
49053 #define __fscache_stat(stat) (NULL)
49054 #define fscache_stat(stat) do {} while (0)
49055+#define fscache_stat_unchecked(stat) do {} while (0)
49056 #define fscache_stat_d(stat) do {} while (0)
49057 #endif
49058
49059diff --git a/fs/fscache/object.c b/fs/fscache/object.c
49060index 50d41c1..10ee117 100644
49061--- a/fs/fscache/object.c
49062+++ b/fs/fscache/object.c
49063@@ -143,7 +143,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
49064 /* Invalidate an object on disk */
49065 case FSCACHE_OBJECT_INVALIDATING:
49066 clear_bit(FSCACHE_OBJECT_EV_INVALIDATE, &object->events);
49067- fscache_stat(&fscache_n_invalidates_run);
49068+ fscache_stat_unchecked(&fscache_n_invalidates_run);
49069 fscache_stat(&fscache_n_cop_invalidate_object);
49070 fscache_invalidate_object(object);
49071 fscache_stat_d(&fscache_n_cop_invalidate_object);
49072@@ -153,7 +153,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
49073 /* update the object metadata on disk */
49074 case FSCACHE_OBJECT_UPDATING:
49075 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
49076- fscache_stat(&fscache_n_updates_run);
49077+ fscache_stat_unchecked(&fscache_n_updates_run);
49078 fscache_stat(&fscache_n_cop_update_object);
49079 object->cache->ops->update_object(object);
49080 fscache_stat_d(&fscache_n_cop_update_object);
49081@@ -242,7 +242,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
49082 spin_lock(&object->lock);
49083 object->state = FSCACHE_OBJECT_DEAD;
49084 spin_unlock(&object->lock);
49085- fscache_stat(&fscache_n_object_dead);
49086+ fscache_stat_unchecked(&fscache_n_object_dead);
49087 goto terminal_transit;
49088
49089 /* handle the parent cache of this object being withdrawn from
49090@@ -257,7 +257,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
49091 spin_lock(&object->lock);
49092 object->state = FSCACHE_OBJECT_DEAD;
49093 spin_unlock(&object->lock);
49094- fscache_stat(&fscache_n_object_dead);
49095+ fscache_stat_unchecked(&fscache_n_object_dead);
49096 goto terminal_transit;
49097
49098 /* complain about the object being woken up once it is
49099@@ -495,7 +495,7 @@ static void fscache_lookup_object(struct fscache_object *object)
49100 parent->cookie->def->name, cookie->def->name,
49101 object->cache->tag->name);
49102
49103- fscache_stat(&fscache_n_object_lookups);
49104+ fscache_stat_unchecked(&fscache_n_object_lookups);
49105 fscache_stat(&fscache_n_cop_lookup_object);
49106 ret = object->cache->ops->lookup_object(object);
49107 fscache_stat_d(&fscache_n_cop_lookup_object);
49108@@ -506,7 +506,7 @@ static void fscache_lookup_object(struct fscache_object *object)
49109 if (ret == -ETIMEDOUT) {
49110 /* probably stuck behind another object, so move this one to
49111 * the back of the queue */
49112- fscache_stat(&fscache_n_object_lookups_timed_out);
49113+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
49114 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
49115 }
49116
49117@@ -529,7 +529,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
49118
49119 spin_lock(&object->lock);
49120 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
49121- fscache_stat(&fscache_n_object_lookups_negative);
49122+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
49123
49124 /* transit here to allow write requests to begin stacking up
49125 * and read requests to begin returning ENODATA */
49126@@ -575,7 +575,7 @@ void fscache_obtained_object(struct fscache_object *object)
49127 * result, in which case there may be data available */
49128 spin_lock(&object->lock);
49129 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
49130- fscache_stat(&fscache_n_object_lookups_positive);
49131+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
49132
49133 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
49134
49135@@ -589,7 +589,7 @@ void fscache_obtained_object(struct fscache_object *object)
49136 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
49137 } else {
49138 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
49139- fscache_stat(&fscache_n_object_created);
49140+ fscache_stat_unchecked(&fscache_n_object_created);
49141
49142 object->state = FSCACHE_OBJECT_AVAILABLE;
49143 spin_unlock(&object->lock);
49144@@ -634,7 +634,7 @@ static void fscache_object_available(struct fscache_object *object)
49145 fscache_enqueue_dependents(object);
49146
49147 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
49148- fscache_stat(&fscache_n_object_avail);
49149+ fscache_stat_unchecked(&fscache_n_object_avail);
49150
49151 _leave("");
49152 }
49153@@ -894,7 +894,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
49154 enum fscache_checkaux result;
49155
49156 if (!object->cookie->def->check_aux) {
49157- fscache_stat(&fscache_n_checkaux_none);
49158+ fscache_stat_unchecked(&fscache_n_checkaux_none);
49159 return FSCACHE_CHECKAUX_OKAY;
49160 }
49161
49162@@ -903,17 +903,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
49163 switch (result) {
49164 /* entry okay as is */
49165 case FSCACHE_CHECKAUX_OKAY:
49166- fscache_stat(&fscache_n_checkaux_okay);
49167+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
49168 break;
49169
49170 /* entry requires update */
49171 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
49172- fscache_stat(&fscache_n_checkaux_update);
49173+ fscache_stat_unchecked(&fscache_n_checkaux_update);
49174 break;
49175
49176 /* entry requires deletion */
49177 case FSCACHE_CHECKAUX_OBSOLETE:
49178- fscache_stat(&fscache_n_checkaux_obsolete);
49179+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
49180 break;
49181
49182 default:
49183diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
49184index 762a9ec..2023284 100644
49185--- a/fs/fscache/operation.c
49186+++ b/fs/fscache/operation.c
49187@@ -17,7 +17,7 @@
49188 #include <linux/slab.h>
49189 #include "internal.h"
49190
49191-atomic_t fscache_op_debug_id;
49192+atomic_unchecked_t fscache_op_debug_id;
49193 EXPORT_SYMBOL(fscache_op_debug_id);
49194
49195 /**
49196@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
49197 ASSERTCMP(atomic_read(&op->usage), >, 0);
49198 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
49199
49200- fscache_stat(&fscache_n_op_enqueue);
49201+ fscache_stat_unchecked(&fscache_n_op_enqueue);
49202 switch (op->flags & FSCACHE_OP_TYPE) {
49203 case FSCACHE_OP_ASYNC:
49204 _debug("queue async");
49205@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
49206 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
49207 if (op->processor)
49208 fscache_enqueue_operation(op);
49209- fscache_stat(&fscache_n_op_run);
49210+ fscache_stat_unchecked(&fscache_n_op_run);
49211 }
49212
49213 /*
49214@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
49215 if (object->n_in_progress > 0) {
49216 atomic_inc(&op->usage);
49217 list_add_tail(&op->pend_link, &object->pending_ops);
49218- fscache_stat(&fscache_n_op_pend);
49219+ fscache_stat_unchecked(&fscache_n_op_pend);
49220 } else if (!list_empty(&object->pending_ops)) {
49221 atomic_inc(&op->usage);
49222 list_add_tail(&op->pend_link, &object->pending_ops);
49223- fscache_stat(&fscache_n_op_pend);
49224+ fscache_stat_unchecked(&fscache_n_op_pend);
49225 fscache_start_operations(object);
49226 } else {
49227 ASSERTCMP(object->n_in_progress, ==, 0);
49228@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
49229 object->n_exclusive++; /* reads and writes must wait */
49230 atomic_inc(&op->usage);
49231 list_add_tail(&op->pend_link, &object->pending_ops);
49232- fscache_stat(&fscache_n_op_pend);
49233+ fscache_stat_unchecked(&fscache_n_op_pend);
49234 ret = 0;
49235 } else {
49236 /* If we're in any other state, there must have been an I/O
49237@@ -215,11 +215,11 @@ int fscache_submit_op(struct fscache_object *object,
49238 if (object->n_exclusive > 0) {
49239 atomic_inc(&op->usage);
49240 list_add_tail(&op->pend_link, &object->pending_ops);
49241- fscache_stat(&fscache_n_op_pend);
49242+ fscache_stat_unchecked(&fscache_n_op_pend);
49243 } else if (!list_empty(&object->pending_ops)) {
49244 atomic_inc(&op->usage);
49245 list_add_tail(&op->pend_link, &object->pending_ops);
49246- fscache_stat(&fscache_n_op_pend);
49247+ fscache_stat_unchecked(&fscache_n_op_pend);
49248 fscache_start_operations(object);
49249 } else {
49250 ASSERTCMP(object->n_exclusive, ==, 0);
49251@@ -231,12 +231,12 @@ int fscache_submit_op(struct fscache_object *object,
49252 object->n_ops++;
49253 atomic_inc(&op->usage);
49254 list_add_tail(&op->pend_link, &object->pending_ops);
49255- fscache_stat(&fscache_n_op_pend);
49256+ fscache_stat_unchecked(&fscache_n_op_pend);
49257 ret = 0;
49258 } else if (object->state == FSCACHE_OBJECT_DYING ||
49259 object->state == FSCACHE_OBJECT_LC_DYING ||
49260 object->state == FSCACHE_OBJECT_WITHDRAWING) {
49261- fscache_stat(&fscache_n_op_rejected);
49262+ fscache_stat_unchecked(&fscache_n_op_rejected);
49263 op->state = FSCACHE_OP_ST_CANCELLED;
49264 ret = -ENOBUFS;
49265 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
49266@@ -315,7 +315,7 @@ int fscache_cancel_op(struct fscache_operation *op,
49267 ret = -EBUSY;
49268 if (op->state == FSCACHE_OP_ST_PENDING) {
49269 ASSERT(!list_empty(&op->pend_link));
49270- fscache_stat(&fscache_n_op_cancelled);
49271+ fscache_stat_unchecked(&fscache_n_op_cancelled);
49272 list_del_init(&op->pend_link);
49273 if (do_cancel)
49274 do_cancel(op);
49275@@ -347,7 +347,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
49276 while (!list_empty(&object->pending_ops)) {
49277 op = list_entry(object->pending_ops.next,
49278 struct fscache_operation, pend_link);
49279- fscache_stat(&fscache_n_op_cancelled);
49280+ fscache_stat_unchecked(&fscache_n_op_cancelled);
49281 list_del_init(&op->pend_link);
49282
49283 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
49284@@ -419,7 +419,7 @@ void fscache_put_operation(struct fscache_operation *op)
49285 op->state, ==, FSCACHE_OP_ST_CANCELLED);
49286 op->state = FSCACHE_OP_ST_DEAD;
49287
49288- fscache_stat(&fscache_n_op_release);
49289+ fscache_stat_unchecked(&fscache_n_op_release);
49290
49291 if (op->release) {
49292 op->release(op);
49293@@ -442,7 +442,7 @@ void fscache_put_operation(struct fscache_operation *op)
49294 * lock, and defer it otherwise */
49295 if (!spin_trylock(&object->lock)) {
49296 _debug("defer put");
49297- fscache_stat(&fscache_n_op_deferred_release);
49298+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
49299
49300 cache = object->cache;
49301 spin_lock(&cache->op_gc_list_lock);
49302@@ -495,7 +495,7 @@ void fscache_operation_gc(struct work_struct *work)
49303
49304 _debug("GC DEFERRED REL OBJ%x OP%x",
49305 object->debug_id, op->debug_id);
49306- fscache_stat(&fscache_n_op_gc);
49307+ fscache_stat_unchecked(&fscache_n_op_gc);
49308
49309 ASSERTCMP(atomic_read(&op->usage), ==, 0);
49310 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
49311diff --git a/fs/fscache/page.c b/fs/fscache/page.c
49312index ff000e5..c44ec6d 100644
49313--- a/fs/fscache/page.c
49314+++ b/fs/fscache/page.c
49315@@ -61,7 +61,7 @@ try_again:
49316 val = radix_tree_lookup(&cookie->stores, page->index);
49317 if (!val) {
49318 rcu_read_unlock();
49319- fscache_stat(&fscache_n_store_vmscan_not_storing);
49320+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
49321 __fscache_uncache_page(cookie, page);
49322 return true;
49323 }
49324@@ -91,11 +91,11 @@ try_again:
49325 spin_unlock(&cookie->stores_lock);
49326
49327 if (xpage) {
49328- fscache_stat(&fscache_n_store_vmscan_cancelled);
49329- fscache_stat(&fscache_n_store_radix_deletes);
49330+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
49331+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
49332 ASSERTCMP(xpage, ==, page);
49333 } else {
49334- fscache_stat(&fscache_n_store_vmscan_gone);
49335+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
49336 }
49337
49338 wake_up_bit(&cookie->flags, 0);
49339@@ -110,11 +110,11 @@ page_busy:
49340 * sleeping on memory allocation, so we may need to impose a timeout
49341 * too. */
49342 if (!(gfp & __GFP_WAIT)) {
49343- fscache_stat(&fscache_n_store_vmscan_busy);
49344+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
49345 return false;
49346 }
49347
49348- fscache_stat(&fscache_n_store_vmscan_wait);
49349+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
49350 __fscache_wait_on_page_write(cookie, page);
49351 gfp &= ~__GFP_WAIT;
49352 goto try_again;
49353@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
49354 FSCACHE_COOKIE_STORING_TAG);
49355 if (!radix_tree_tag_get(&cookie->stores, page->index,
49356 FSCACHE_COOKIE_PENDING_TAG)) {
49357- fscache_stat(&fscache_n_store_radix_deletes);
49358+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
49359 xpage = radix_tree_delete(&cookie->stores, page->index);
49360 }
49361 spin_unlock(&cookie->stores_lock);
49362@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
49363
49364 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
49365
49366- fscache_stat(&fscache_n_attr_changed_calls);
49367+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
49368
49369 if (fscache_object_is_active(object)) {
49370 fscache_stat(&fscache_n_cop_attr_changed);
49371@@ -187,11 +187,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
49372
49373 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
49374
49375- fscache_stat(&fscache_n_attr_changed);
49376+ fscache_stat_unchecked(&fscache_n_attr_changed);
49377
49378 op = kzalloc(sizeof(*op), GFP_KERNEL);
49379 if (!op) {
49380- fscache_stat(&fscache_n_attr_changed_nomem);
49381+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
49382 _leave(" = -ENOMEM");
49383 return -ENOMEM;
49384 }
49385@@ -209,7 +209,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
49386 if (fscache_submit_exclusive_op(object, op) < 0)
49387 goto nobufs;
49388 spin_unlock(&cookie->lock);
49389- fscache_stat(&fscache_n_attr_changed_ok);
49390+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
49391 fscache_put_operation(op);
49392 _leave(" = 0");
49393 return 0;
49394@@ -217,7 +217,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
49395 nobufs:
49396 spin_unlock(&cookie->lock);
49397 kfree(op);
49398- fscache_stat(&fscache_n_attr_changed_nobufs);
49399+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
49400 _leave(" = %d", -ENOBUFS);
49401 return -ENOBUFS;
49402 }
49403@@ -255,7 +255,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
49404 /* allocate a retrieval operation and attempt to submit it */
49405 op = kzalloc(sizeof(*op), GFP_NOIO);
49406 if (!op) {
49407- fscache_stat(&fscache_n_retrievals_nomem);
49408+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
49409 return NULL;
49410 }
49411
49412@@ -283,13 +283,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
49413 return 0;
49414 }
49415
49416- fscache_stat(&fscache_n_retrievals_wait);
49417+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
49418
49419 jif = jiffies;
49420 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
49421 fscache_wait_bit_interruptible,
49422 TASK_INTERRUPTIBLE) != 0) {
49423- fscache_stat(&fscache_n_retrievals_intr);
49424+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
49425 _leave(" = -ERESTARTSYS");
49426 return -ERESTARTSYS;
49427 }
49428@@ -318,8 +318,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
49429 */
49430 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
49431 struct fscache_retrieval *op,
49432- atomic_t *stat_op_waits,
49433- atomic_t *stat_object_dead)
49434+ atomic_unchecked_t *stat_op_waits,
49435+ atomic_unchecked_t *stat_object_dead)
49436 {
49437 int ret;
49438
49439@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
49440 goto check_if_dead;
49441
49442 _debug(">>> WT");
49443- fscache_stat(stat_op_waits);
49444+ fscache_stat_unchecked(stat_op_waits);
49445 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
49446 fscache_wait_bit_interruptible,
49447 TASK_INTERRUPTIBLE) != 0) {
49448@@ -344,14 +344,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
49449
49450 check_if_dead:
49451 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
49452- fscache_stat(stat_object_dead);
49453+ fscache_stat_unchecked(stat_object_dead);
49454 _leave(" = -ENOBUFS [cancelled]");
49455 return -ENOBUFS;
49456 }
49457 if (unlikely(fscache_object_is_dead(object))) {
49458 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
49459 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
49460- fscache_stat(stat_object_dead);
49461+ fscache_stat_unchecked(stat_object_dead);
49462 return -ENOBUFS;
49463 }
49464 return 0;
49465@@ -378,7 +378,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
49466
49467 _enter("%p,%p,,,", cookie, page);
49468
49469- fscache_stat(&fscache_n_retrievals);
49470+ fscache_stat_unchecked(&fscache_n_retrievals);
49471
49472 if (hlist_empty(&cookie->backing_objects))
49473 goto nobufs;
49474@@ -417,7 +417,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
49475 goto nobufs_unlock_dec;
49476 spin_unlock(&cookie->lock);
49477
49478- fscache_stat(&fscache_n_retrieval_ops);
49479+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
49480
49481 /* pin the netfs read context in case we need to do the actual netfs
49482 * read because we've encountered a cache read failure */
49483@@ -447,15 +447,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
49484
49485 error:
49486 if (ret == -ENOMEM)
49487- fscache_stat(&fscache_n_retrievals_nomem);
49488+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
49489 else if (ret == -ERESTARTSYS)
49490- fscache_stat(&fscache_n_retrievals_intr);
49491+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
49492 else if (ret == -ENODATA)
49493- fscache_stat(&fscache_n_retrievals_nodata);
49494+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
49495 else if (ret < 0)
49496- fscache_stat(&fscache_n_retrievals_nobufs);
49497+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49498 else
49499- fscache_stat(&fscache_n_retrievals_ok);
49500+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
49501
49502 fscache_put_retrieval(op);
49503 _leave(" = %d", ret);
49504@@ -467,7 +467,7 @@ nobufs_unlock:
49505 spin_unlock(&cookie->lock);
49506 kfree(op);
49507 nobufs:
49508- fscache_stat(&fscache_n_retrievals_nobufs);
49509+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49510 _leave(" = -ENOBUFS");
49511 return -ENOBUFS;
49512 }
49513@@ -505,7 +505,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
49514
49515 _enter("%p,,%d,,,", cookie, *nr_pages);
49516
49517- fscache_stat(&fscache_n_retrievals);
49518+ fscache_stat_unchecked(&fscache_n_retrievals);
49519
49520 if (hlist_empty(&cookie->backing_objects))
49521 goto nobufs;
49522@@ -541,7 +541,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
49523 goto nobufs_unlock_dec;
49524 spin_unlock(&cookie->lock);
49525
49526- fscache_stat(&fscache_n_retrieval_ops);
49527+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
49528
49529 /* pin the netfs read context in case we need to do the actual netfs
49530 * read because we've encountered a cache read failure */
49531@@ -571,15 +571,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
49532
49533 error:
49534 if (ret == -ENOMEM)
49535- fscache_stat(&fscache_n_retrievals_nomem);
49536+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
49537 else if (ret == -ERESTARTSYS)
49538- fscache_stat(&fscache_n_retrievals_intr);
49539+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
49540 else if (ret == -ENODATA)
49541- fscache_stat(&fscache_n_retrievals_nodata);
49542+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
49543 else if (ret < 0)
49544- fscache_stat(&fscache_n_retrievals_nobufs);
49545+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49546 else
49547- fscache_stat(&fscache_n_retrievals_ok);
49548+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
49549
49550 fscache_put_retrieval(op);
49551 _leave(" = %d", ret);
49552@@ -591,7 +591,7 @@ nobufs_unlock:
49553 spin_unlock(&cookie->lock);
49554 kfree(op);
49555 nobufs:
49556- fscache_stat(&fscache_n_retrievals_nobufs);
49557+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49558 _leave(" = -ENOBUFS");
49559 return -ENOBUFS;
49560 }
49561@@ -615,7 +615,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
49562
49563 _enter("%p,%p,,,", cookie, page);
49564
49565- fscache_stat(&fscache_n_allocs);
49566+ fscache_stat_unchecked(&fscache_n_allocs);
49567
49568 if (hlist_empty(&cookie->backing_objects))
49569 goto nobufs;
49570@@ -647,7 +647,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
49571 goto nobufs_unlock;
49572 spin_unlock(&cookie->lock);
49573
49574- fscache_stat(&fscache_n_alloc_ops);
49575+ fscache_stat_unchecked(&fscache_n_alloc_ops);
49576
49577 ret = fscache_wait_for_retrieval_activation(
49578 object, op,
49579@@ -663,11 +663,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
49580
49581 error:
49582 if (ret == -ERESTARTSYS)
49583- fscache_stat(&fscache_n_allocs_intr);
49584+ fscache_stat_unchecked(&fscache_n_allocs_intr);
49585 else if (ret < 0)
49586- fscache_stat(&fscache_n_allocs_nobufs);
49587+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
49588 else
49589- fscache_stat(&fscache_n_allocs_ok);
49590+ fscache_stat_unchecked(&fscache_n_allocs_ok);
49591
49592 fscache_put_retrieval(op);
49593 _leave(" = %d", ret);
49594@@ -677,7 +677,7 @@ nobufs_unlock:
49595 spin_unlock(&cookie->lock);
49596 kfree(op);
49597 nobufs:
49598- fscache_stat(&fscache_n_allocs_nobufs);
49599+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
49600 _leave(" = -ENOBUFS");
49601 return -ENOBUFS;
49602 }
49603@@ -736,7 +736,7 @@ static void fscache_write_op(struct fscache_operation *_op)
49604
49605 spin_lock(&cookie->stores_lock);
49606
49607- fscache_stat(&fscache_n_store_calls);
49608+ fscache_stat_unchecked(&fscache_n_store_calls);
49609
49610 /* find a page to store */
49611 page = NULL;
49612@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
49613 page = results[0];
49614 _debug("gang %d [%lx]", n, page->index);
49615 if (page->index > op->store_limit) {
49616- fscache_stat(&fscache_n_store_pages_over_limit);
49617+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
49618 goto superseded;
49619 }
49620
49621@@ -759,7 +759,7 @@ static void fscache_write_op(struct fscache_operation *_op)
49622 spin_unlock(&cookie->stores_lock);
49623 spin_unlock(&object->lock);
49624
49625- fscache_stat(&fscache_n_store_pages);
49626+ fscache_stat_unchecked(&fscache_n_store_pages);
49627 fscache_stat(&fscache_n_cop_write_page);
49628 ret = object->cache->ops->write_page(op, page);
49629 fscache_stat_d(&fscache_n_cop_write_page);
49630@@ -860,7 +860,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49631 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
49632 ASSERT(PageFsCache(page));
49633
49634- fscache_stat(&fscache_n_stores);
49635+ fscache_stat_unchecked(&fscache_n_stores);
49636
49637 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
49638 _leave(" = -ENOBUFS [invalidating]");
49639@@ -916,7 +916,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49640 spin_unlock(&cookie->stores_lock);
49641 spin_unlock(&object->lock);
49642
49643- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
49644+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
49645 op->store_limit = object->store_limit;
49646
49647 if (fscache_submit_op(object, &op->op) < 0)
49648@@ -924,8 +924,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49649
49650 spin_unlock(&cookie->lock);
49651 radix_tree_preload_end();
49652- fscache_stat(&fscache_n_store_ops);
49653- fscache_stat(&fscache_n_stores_ok);
49654+ fscache_stat_unchecked(&fscache_n_store_ops);
49655+ fscache_stat_unchecked(&fscache_n_stores_ok);
49656
49657 /* the work queue now carries its own ref on the object */
49658 fscache_put_operation(&op->op);
49659@@ -933,14 +933,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49660 return 0;
49661
49662 already_queued:
49663- fscache_stat(&fscache_n_stores_again);
49664+ fscache_stat_unchecked(&fscache_n_stores_again);
49665 already_pending:
49666 spin_unlock(&cookie->stores_lock);
49667 spin_unlock(&object->lock);
49668 spin_unlock(&cookie->lock);
49669 radix_tree_preload_end();
49670 kfree(op);
49671- fscache_stat(&fscache_n_stores_ok);
49672+ fscache_stat_unchecked(&fscache_n_stores_ok);
49673 _leave(" = 0");
49674 return 0;
49675
49676@@ -959,14 +959,14 @@ nobufs:
49677 spin_unlock(&cookie->lock);
49678 radix_tree_preload_end();
49679 kfree(op);
49680- fscache_stat(&fscache_n_stores_nobufs);
49681+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
49682 _leave(" = -ENOBUFS");
49683 return -ENOBUFS;
49684
49685 nomem_free:
49686 kfree(op);
49687 nomem:
49688- fscache_stat(&fscache_n_stores_oom);
49689+ fscache_stat_unchecked(&fscache_n_stores_oom);
49690 _leave(" = -ENOMEM");
49691 return -ENOMEM;
49692 }
49693@@ -984,7 +984,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
49694 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
49695 ASSERTCMP(page, !=, NULL);
49696
49697- fscache_stat(&fscache_n_uncaches);
49698+ fscache_stat_unchecked(&fscache_n_uncaches);
49699
49700 /* cache withdrawal may beat us to it */
49701 if (!PageFsCache(page))
49702@@ -1035,7 +1035,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
49703 struct fscache_cookie *cookie = op->op.object->cookie;
49704
49705 #ifdef CONFIG_FSCACHE_STATS
49706- atomic_inc(&fscache_n_marks);
49707+ atomic_inc_unchecked(&fscache_n_marks);
49708 #endif
49709
49710 _debug("- mark %p{%lx}", page, page->index);
49711diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
49712index 8179e8b..5072cc7 100644
49713--- a/fs/fscache/stats.c
49714+++ b/fs/fscache/stats.c
49715@@ -18,99 +18,99 @@
49716 /*
49717 * operation counters
49718 */
49719-atomic_t fscache_n_op_pend;
49720-atomic_t fscache_n_op_run;
49721-atomic_t fscache_n_op_enqueue;
49722-atomic_t fscache_n_op_requeue;
49723-atomic_t fscache_n_op_deferred_release;
49724-atomic_t fscache_n_op_release;
49725-atomic_t fscache_n_op_gc;
49726-atomic_t fscache_n_op_cancelled;
49727-atomic_t fscache_n_op_rejected;
49728+atomic_unchecked_t fscache_n_op_pend;
49729+atomic_unchecked_t fscache_n_op_run;
49730+atomic_unchecked_t fscache_n_op_enqueue;
49731+atomic_unchecked_t fscache_n_op_requeue;
49732+atomic_unchecked_t fscache_n_op_deferred_release;
49733+atomic_unchecked_t fscache_n_op_release;
49734+atomic_unchecked_t fscache_n_op_gc;
49735+atomic_unchecked_t fscache_n_op_cancelled;
49736+atomic_unchecked_t fscache_n_op_rejected;
49737
49738-atomic_t fscache_n_attr_changed;
49739-atomic_t fscache_n_attr_changed_ok;
49740-atomic_t fscache_n_attr_changed_nobufs;
49741-atomic_t fscache_n_attr_changed_nomem;
49742-atomic_t fscache_n_attr_changed_calls;
49743+atomic_unchecked_t fscache_n_attr_changed;
49744+atomic_unchecked_t fscache_n_attr_changed_ok;
49745+atomic_unchecked_t fscache_n_attr_changed_nobufs;
49746+atomic_unchecked_t fscache_n_attr_changed_nomem;
49747+atomic_unchecked_t fscache_n_attr_changed_calls;
49748
49749-atomic_t fscache_n_allocs;
49750-atomic_t fscache_n_allocs_ok;
49751-atomic_t fscache_n_allocs_wait;
49752-atomic_t fscache_n_allocs_nobufs;
49753-atomic_t fscache_n_allocs_intr;
49754-atomic_t fscache_n_allocs_object_dead;
49755-atomic_t fscache_n_alloc_ops;
49756-atomic_t fscache_n_alloc_op_waits;
49757+atomic_unchecked_t fscache_n_allocs;
49758+atomic_unchecked_t fscache_n_allocs_ok;
49759+atomic_unchecked_t fscache_n_allocs_wait;
49760+atomic_unchecked_t fscache_n_allocs_nobufs;
49761+atomic_unchecked_t fscache_n_allocs_intr;
49762+atomic_unchecked_t fscache_n_allocs_object_dead;
49763+atomic_unchecked_t fscache_n_alloc_ops;
49764+atomic_unchecked_t fscache_n_alloc_op_waits;
49765
49766-atomic_t fscache_n_retrievals;
49767-atomic_t fscache_n_retrievals_ok;
49768-atomic_t fscache_n_retrievals_wait;
49769-atomic_t fscache_n_retrievals_nodata;
49770-atomic_t fscache_n_retrievals_nobufs;
49771-atomic_t fscache_n_retrievals_intr;
49772-atomic_t fscache_n_retrievals_nomem;
49773-atomic_t fscache_n_retrievals_object_dead;
49774-atomic_t fscache_n_retrieval_ops;
49775-atomic_t fscache_n_retrieval_op_waits;
49776+atomic_unchecked_t fscache_n_retrievals;
49777+atomic_unchecked_t fscache_n_retrievals_ok;
49778+atomic_unchecked_t fscache_n_retrievals_wait;
49779+atomic_unchecked_t fscache_n_retrievals_nodata;
49780+atomic_unchecked_t fscache_n_retrievals_nobufs;
49781+atomic_unchecked_t fscache_n_retrievals_intr;
49782+atomic_unchecked_t fscache_n_retrievals_nomem;
49783+atomic_unchecked_t fscache_n_retrievals_object_dead;
49784+atomic_unchecked_t fscache_n_retrieval_ops;
49785+atomic_unchecked_t fscache_n_retrieval_op_waits;
49786
49787-atomic_t fscache_n_stores;
49788-atomic_t fscache_n_stores_ok;
49789-atomic_t fscache_n_stores_again;
49790-atomic_t fscache_n_stores_nobufs;
49791-atomic_t fscache_n_stores_oom;
49792-atomic_t fscache_n_store_ops;
49793-atomic_t fscache_n_store_calls;
49794-atomic_t fscache_n_store_pages;
49795-atomic_t fscache_n_store_radix_deletes;
49796-atomic_t fscache_n_store_pages_over_limit;
49797+atomic_unchecked_t fscache_n_stores;
49798+atomic_unchecked_t fscache_n_stores_ok;
49799+atomic_unchecked_t fscache_n_stores_again;
49800+atomic_unchecked_t fscache_n_stores_nobufs;
49801+atomic_unchecked_t fscache_n_stores_oom;
49802+atomic_unchecked_t fscache_n_store_ops;
49803+atomic_unchecked_t fscache_n_store_calls;
49804+atomic_unchecked_t fscache_n_store_pages;
49805+atomic_unchecked_t fscache_n_store_radix_deletes;
49806+atomic_unchecked_t fscache_n_store_pages_over_limit;
49807
49808-atomic_t fscache_n_store_vmscan_not_storing;
49809-atomic_t fscache_n_store_vmscan_gone;
49810-atomic_t fscache_n_store_vmscan_busy;
49811-atomic_t fscache_n_store_vmscan_cancelled;
49812-atomic_t fscache_n_store_vmscan_wait;
49813+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
49814+atomic_unchecked_t fscache_n_store_vmscan_gone;
49815+atomic_unchecked_t fscache_n_store_vmscan_busy;
49816+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
49817+atomic_unchecked_t fscache_n_store_vmscan_wait;
49818
49819-atomic_t fscache_n_marks;
49820-atomic_t fscache_n_uncaches;
49821+atomic_unchecked_t fscache_n_marks;
49822+atomic_unchecked_t fscache_n_uncaches;
49823
49824-atomic_t fscache_n_acquires;
49825-atomic_t fscache_n_acquires_null;
49826-atomic_t fscache_n_acquires_no_cache;
49827-atomic_t fscache_n_acquires_ok;
49828-atomic_t fscache_n_acquires_nobufs;
49829-atomic_t fscache_n_acquires_oom;
49830+atomic_unchecked_t fscache_n_acquires;
49831+atomic_unchecked_t fscache_n_acquires_null;
49832+atomic_unchecked_t fscache_n_acquires_no_cache;
49833+atomic_unchecked_t fscache_n_acquires_ok;
49834+atomic_unchecked_t fscache_n_acquires_nobufs;
49835+atomic_unchecked_t fscache_n_acquires_oom;
49836
49837-atomic_t fscache_n_invalidates;
49838-atomic_t fscache_n_invalidates_run;
49839+atomic_unchecked_t fscache_n_invalidates;
49840+atomic_unchecked_t fscache_n_invalidates_run;
49841
49842-atomic_t fscache_n_updates;
49843-atomic_t fscache_n_updates_null;
49844-atomic_t fscache_n_updates_run;
49845+atomic_unchecked_t fscache_n_updates;
49846+atomic_unchecked_t fscache_n_updates_null;
49847+atomic_unchecked_t fscache_n_updates_run;
49848
49849-atomic_t fscache_n_relinquishes;
49850-atomic_t fscache_n_relinquishes_null;
49851-atomic_t fscache_n_relinquishes_waitcrt;
49852-atomic_t fscache_n_relinquishes_retire;
49853+atomic_unchecked_t fscache_n_relinquishes;
49854+atomic_unchecked_t fscache_n_relinquishes_null;
49855+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
49856+atomic_unchecked_t fscache_n_relinquishes_retire;
49857
49858-atomic_t fscache_n_cookie_index;
49859-atomic_t fscache_n_cookie_data;
49860-atomic_t fscache_n_cookie_special;
49861+atomic_unchecked_t fscache_n_cookie_index;
49862+atomic_unchecked_t fscache_n_cookie_data;
49863+atomic_unchecked_t fscache_n_cookie_special;
49864
49865-atomic_t fscache_n_object_alloc;
49866-atomic_t fscache_n_object_no_alloc;
49867-atomic_t fscache_n_object_lookups;
49868-atomic_t fscache_n_object_lookups_negative;
49869-atomic_t fscache_n_object_lookups_positive;
49870-atomic_t fscache_n_object_lookups_timed_out;
49871-atomic_t fscache_n_object_created;
49872-atomic_t fscache_n_object_avail;
49873-atomic_t fscache_n_object_dead;
49874+atomic_unchecked_t fscache_n_object_alloc;
49875+atomic_unchecked_t fscache_n_object_no_alloc;
49876+atomic_unchecked_t fscache_n_object_lookups;
49877+atomic_unchecked_t fscache_n_object_lookups_negative;
49878+atomic_unchecked_t fscache_n_object_lookups_positive;
49879+atomic_unchecked_t fscache_n_object_lookups_timed_out;
49880+atomic_unchecked_t fscache_n_object_created;
49881+atomic_unchecked_t fscache_n_object_avail;
49882+atomic_unchecked_t fscache_n_object_dead;
49883
49884-atomic_t fscache_n_checkaux_none;
49885-atomic_t fscache_n_checkaux_okay;
49886-atomic_t fscache_n_checkaux_update;
49887-atomic_t fscache_n_checkaux_obsolete;
49888+atomic_unchecked_t fscache_n_checkaux_none;
49889+atomic_unchecked_t fscache_n_checkaux_okay;
49890+atomic_unchecked_t fscache_n_checkaux_update;
49891+atomic_unchecked_t fscache_n_checkaux_obsolete;
49892
49893 atomic_t fscache_n_cop_alloc_object;
49894 atomic_t fscache_n_cop_lookup_object;
49895@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
49896 seq_puts(m, "FS-Cache statistics\n");
49897
49898 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
49899- atomic_read(&fscache_n_cookie_index),
49900- atomic_read(&fscache_n_cookie_data),
49901- atomic_read(&fscache_n_cookie_special));
49902+ atomic_read_unchecked(&fscache_n_cookie_index),
49903+ atomic_read_unchecked(&fscache_n_cookie_data),
49904+ atomic_read_unchecked(&fscache_n_cookie_special));
49905
49906 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
49907- atomic_read(&fscache_n_object_alloc),
49908- atomic_read(&fscache_n_object_no_alloc),
49909- atomic_read(&fscache_n_object_avail),
49910- atomic_read(&fscache_n_object_dead));
49911+ atomic_read_unchecked(&fscache_n_object_alloc),
49912+ atomic_read_unchecked(&fscache_n_object_no_alloc),
49913+ atomic_read_unchecked(&fscache_n_object_avail),
49914+ atomic_read_unchecked(&fscache_n_object_dead));
49915 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
49916- atomic_read(&fscache_n_checkaux_none),
49917- atomic_read(&fscache_n_checkaux_okay),
49918- atomic_read(&fscache_n_checkaux_update),
49919- atomic_read(&fscache_n_checkaux_obsolete));
49920+ atomic_read_unchecked(&fscache_n_checkaux_none),
49921+ atomic_read_unchecked(&fscache_n_checkaux_okay),
49922+ atomic_read_unchecked(&fscache_n_checkaux_update),
49923+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
49924
49925 seq_printf(m, "Pages : mrk=%u unc=%u\n",
49926- atomic_read(&fscache_n_marks),
49927- atomic_read(&fscache_n_uncaches));
49928+ atomic_read_unchecked(&fscache_n_marks),
49929+ atomic_read_unchecked(&fscache_n_uncaches));
49930
49931 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
49932 " oom=%u\n",
49933- atomic_read(&fscache_n_acquires),
49934- atomic_read(&fscache_n_acquires_null),
49935- atomic_read(&fscache_n_acquires_no_cache),
49936- atomic_read(&fscache_n_acquires_ok),
49937- atomic_read(&fscache_n_acquires_nobufs),
49938- atomic_read(&fscache_n_acquires_oom));
49939+ atomic_read_unchecked(&fscache_n_acquires),
49940+ atomic_read_unchecked(&fscache_n_acquires_null),
49941+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
49942+ atomic_read_unchecked(&fscache_n_acquires_ok),
49943+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
49944+ atomic_read_unchecked(&fscache_n_acquires_oom));
49945
49946 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
49947- atomic_read(&fscache_n_object_lookups),
49948- atomic_read(&fscache_n_object_lookups_negative),
49949- atomic_read(&fscache_n_object_lookups_positive),
49950- atomic_read(&fscache_n_object_created),
49951- atomic_read(&fscache_n_object_lookups_timed_out));
49952+ atomic_read_unchecked(&fscache_n_object_lookups),
49953+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
49954+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
49955+ atomic_read_unchecked(&fscache_n_object_created),
49956+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
49957
49958 seq_printf(m, "Invals : n=%u run=%u\n",
49959- atomic_read(&fscache_n_invalidates),
49960- atomic_read(&fscache_n_invalidates_run));
49961+ atomic_read_unchecked(&fscache_n_invalidates),
49962+ atomic_read_unchecked(&fscache_n_invalidates_run));
49963
49964 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
49965- atomic_read(&fscache_n_updates),
49966- atomic_read(&fscache_n_updates_null),
49967- atomic_read(&fscache_n_updates_run));
49968+ atomic_read_unchecked(&fscache_n_updates),
49969+ atomic_read_unchecked(&fscache_n_updates_null),
49970+ atomic_read_unchecked(&fscache_n_updates_run));
49971
49972 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
49973- atomic_read(&fscache_n_relinquishes),
49974- atomic_read(&fscache_n_relinquishes_null),
49975- atomic_read(&fscache_n_relinquishes_waitcrt),
49976- atomic_read(&fscache_n_relinquishes_retire));
49977+ atomic_read_unchecked(&fscache_n_relinquishes),
49978+ atomic_read_unchecked(&fscache_n_relinquishes_null),
49979+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
49980+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
49981
49982 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
49983- atomic_read(&fscache_n_attr_changed),
49984- atomic_read(&fscache_n_attr_changed_ok),
49985- atomic_read(&fscache_n_attr_changed_nobufs),
49986- atomic_read(&fscache_n_attr_changed_nomem),
49987- atomic_read(&fscache_n_attr_changed_calls));
49988+ atomic_read_unchecked(&fscache_n_attr_changed),
49989+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
49990+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
49991+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
49992+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
49993
49994 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
49995- atomic_read(&fscache_n_allocs),
49996- atomic_read(&fscache_n_allocs_ok),
49997- atomic_read(&fscache_n_allocs_wait),
49998- atomic_read(&fscache_n_allocs_nobufs),
49999- atomic_read(&fscache_n_allocs_intr));
50000+ atomic_read_unchecked(&fscache_n_allocs),
50001+ atomic_read_unchecked(&fscache_n_allocs_ok),
50002+ atomic_read_unchecked(&fscache_n_allocs_wait),
50003+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
50004+ atomic_read_unchecked(&fscache_n_allocs_intr));
50005 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
50006- atomic_read(&fscache_n_alloc_ops),
50007- atomic_read(&fscache_n_alloc_op_waits),
50008- atomic_read(&fscache_n_allocs_object_dead));
50009+ atomic_read_unchecked(&fscache_n_alloc_ops),
50010+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
50011+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
50012
50013 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
50014 " int=%u oom=%u\n",
50015- atomic_read(&fscache_n_retrievals),
50016- atomic_read(&fscache_n_retrievals_ok),
50017- atomic_read(&fscache_n_retrievals_wait),
50018- atomic_read(&fscache_n_retrievals_nodata),
50019- atomic_read(&fscache_n_retrievals_nobufs),
50020- atomic_read(&fscache_n_retrievals_intr),
50021- atomic_read(&fscache_n_retrievals_nomem));
50022+ atomic_read_unchecked(&fscache_n_retrievals),
50023+ atomic_read_unchecked(&fscache_n_retrievals_ok),
50024+ atomic_read_unchecked(&fscache_n_retrievals_wait),
50025+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
50026+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
50027+ atomic_read_unchecked(&fscache_n_retrievals_intr),
50028+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
50029 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
50030- atomic_read(&fscache_n_retrieval_ops),
50031- atomic_read(&fscache_n_retrieval_op_waits),
50032- atomic_read(&fscache_n_retrievals_object_dead));
50033+ atomic_read_unchecked(&fscache_n_retrieval_ops),
50034+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
50035+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
50036
50037 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
50038- atomic_read(&fscache_n_stores),
50039- atomic_read(&fscache_n_stores_ok),
50040- atomic_read(&fscache_n_stores_again),
50041- atomic_read(&fscache_n_stores_nobufs),
50042- atomic_read(&fscache_n_stores_oom));
50043+ atomic_read_unchecked(&fscache_n_stores),
50044+ atomic_read_unchecked(&fscache_n_stores_ok),
50045+ atomic_read_unchecked(&fscache_n_stores_again),
50046+ atomic_read_unchecked(&fscache_n_stores_nobufs),
50047+ atomic_read_unchecked(&fscache_n_stores_oom));
50048 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
50049- atomic_read(&fscache_n_store_ops),
50050- atomic_read(&fscache_n_store_calls),
50051- atomic_read(&fscache_n_store_pages),
50052- atomic_read(&fscache_n_store_radix_deletes),
50053- atomic_read(&fscache_n_store_pages_over_limit));
50054+ atomic_read_unchecked(&fscache_n_store_ops),
50055+ atomic_read_unchecked(&fscache_n_store_calls),
50056+ atomic_read_unchecked(&fscache_n_store_pages),
50057+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
50058+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
50059
50060 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
50061- atomic_read(&fscache_n_store_vmscan_not_storing),
50062- atomic_read(&fscache_n_store_vmscan_gone),
50063- atomic_read(&fscache_n_store_vmscan_busy),
50064- atomic_read(&fscache_n_store_vmscan_cancelled),
50065- atomic_read(&fscache_n_store_vmscan_wait));
50066+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
50067+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
50068+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
50069+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
50070+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
50071
50072 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
50073- atomic_read(&fscache_n_op_pend),
50074- atomic_read(&fscache_n_op_run),
50075- atomic_read(&fscache_n_op_enqueue),
50076- atomic_read(&fscache_n_op_cancelled),
50077- atomic_read(&fscache_n_op_rejected));
50078+ atomic_read_unchecked(&fscache_n_op_pend),
50079+ atomic_read_unchecked(&fscache_n_op_run),
50080+ atomic_read_unchecked(&fscache_n_op_enqueue),
50081+ atomic_read_unchecked(&fscache_n_op_cancelled),
50082+ atomic_read_unchecked(&fscache_n_op_rejected));
50083 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
50084- atomic_read(&fscache_n_op_deferred_release),
50085- atomic_read(&fscache_n_op_release),
50086- atomic_read(&fscache_n_op_gc));
50087+ atomic_read_unchecked(&fscache_n_op_deferred_release),
50088+ atomic_read_unchecked(&fscache_n_op_release),
50089+ atomic_read_unchecked(&fscache_n_op_gc));
50090
50091 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
50092 atomic_read(&fscache_n_cop_alloc_object),
50093diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
50094index e397b67..b0d8709 100644
50095--- a/fs/fuse/cuse.c
50096+++ b/fs/fuse/cuse.c
50097@@ -593,10 +593,12 @@ static int __init cuse_init(void)
50098 INIT_LIST_HEAD(&cuse_conntbl[i]);
50099
50100 /* inherit and extend fuse_dev_operations */
50101- cuse_channel_fops = fuse_dev_operations;
50102- cuse_channel_fops.owner = THIS_MODULE;
50103- cuse_channel_fops.open = cuse_channel_open;
50104- cuse_channel_fops.release = cuse_channel_release;
50105+ pax_open_kernel();
50106+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
50107+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
50108+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
50109+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
50110+ pax_close_kernel();
50111
50112 cuse_class = class_create(THIS_MODULE, "cuse");
50113 if (IS_ERR(cuse_class))
50114diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
50115index e83351a..41e3c9c 100644
50116--- a/fs/fuse/dev.c
50117+++ b/fs/fuse/dev.c
50118@@ -1236,7 +1236,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
50119 ret = 0;
50120 pipe_lock(pipe);
50121
50122- if (!pipe->readers) {
50123+ if (!atomic_read(&pipe->readers)) {
50124 send_sig(SIGPIPE, current, 0);
50125 if (!ret)
50126 ret = -EPIPE;
50127diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
50128index b7c09f9..3eff736 100644
50129--- a/fs/fuse/dir.c
50130+++ b/fs/fuse/dir.c
50131@@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
50132 return link;
50133 }
50134
50135-static void free_link(char *link)
50136+static void free_link(const char *link)
50137 {
50138 if (!IS_ERR(link))
50139 free_page((unsigned long) link);
50140diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
50141index 2b6f569..fcb4d1f 100644
50142--- a/fs/gfs2/inode.c
50143+++ b/fs/gfs2/inode.c
50144@@ -1499,7 +1499,7 @@ out:
50145
50146 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
50147 {
50148- char *s = nd_get_link(nd);
50149+ const char *s = nd_get_link(nd);
50150 if (!IS_ERR(s))
50151 kfree(s);
50152 }
50153diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
50154index 78bde32..767e906 100644
50155--- a/fs/hugetlbfs/inode.c
50156+++ b/fs/hugetlbfs/inode.c
50157@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
50158 struct mm_struct *mm = current->mm;
50159 struct vm_area_struct *vma;
50160 struct hstate *h = hstate_file(file);
50161+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
50162 struct vm_unmapped_area_info info;
50163
50164 if (len & ~huge_page_mask(h))
50165@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
50166 return addr;
50167 }
50168
50169+#ifdef CONFIG_PAX_RANDMMAP
50170+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
50171+#endif
50172+
50173 if (addr) {
50174 addr = ALIGN(addr, huge_page_size(h));
50175 vma = find_vma(mm, addr);
50176- if (TASK_SIZE - len >= addr &&
50177- (!vma || addr + len <= vma->vm_start))
50178+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
50179 return addr;
50180 }
50181
50182 info.flags = 0;
50183 info.length = len;
50184 info.low_limit = TASK_UNMAPPED_BASE;
50185+
50186+#ifdef CONFIG_PAX_RANDMMAP
50187+ if (mm->pax_flags & MF_PAX_RANDMMAP)
50188+ info.low_limit += mm->delta_mmap;
50189+#endif
50190+
50191 info.high_limit = TASK_SIZE;
50192 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
50193 info.align_offset = 0;
50194@@ -897,7 +907,7 @@ static struct file_system_type hugetlbfs_fs_type = {
50195 .kill_sb = kill_litter_super,
50196 };
50197
50198-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
50199+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
50200
50201 static int can_do_hugetlb_shm(void)
50202 {
50203diff --git a/fs/inode.c b/fs/inode.c
50204index 14084b7..29af1d9 100644
50205--- a/fs/inode.c
50206+++ b/fs/inode.c
50207@@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
50208
50209 #ifdef CONFIG_SMP
50210 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
50211- static atomic_t shared_last_ino;
50212- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
50213+ static atomic_unchecked_t shared_last_ino;
50214+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
50215
50216 res = next - LAST_INO_BATCH;
50217 }
50218diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
50219index 4a6cf28..d3a29d3 100644
50220--- a/fs/jffs2/erase.c
50221+++ b/fs/jffs2/erase.c
50222@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
50223 struct jffs2_unknown_node marker = {
50224 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
50225 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
50226- .totlen = cpu_to_je32(c->cleanmarker_size)
50227+ .totlen = cpu_to_je32(c->cleanmarker_size),
50228+ .hdr_crc = cpu_to_je32(0)
50229 };
50230
50231 jffs2_prealloc_raw_node_refs(c, jeb, 1);
50232diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
50233index a6597d6..41b30ec 100644
50234--- a/fs/jffs2/wbuf.c
50235+++ b/fs/jffs2/wbuf.c
50236@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
50237 {
50238 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
50239 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
50240- .totlen = constant_cpu_to_je32(8)
50241+ .totlen = constant_cpu_to_je32(8),
50242+ .hdr_crc = constant_cpu_to_je32(0)
50243 };
50244
50245 /*
50246diff --git a/fs/jfs/super.c b/fs/jfs/super.c
50247index 1a543be..d803c40 100644
50248--- a/fs/jfs/super.c
50249+++ b/fs/jfs/super.c
50250@@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
50251
50252 jfs_inode_cachep =
50253 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
50254- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
50255+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
50256 init_once);
50257 if (jfs_inode_cachep == NULL)
50258 return -ENOMEM;
50259diff --git a/fs/libfs.c b/fs/libfs.c
50260index 916da8c..1588998 100644
50261--- a/fs/libfs.c
50262+++ b/fs/libfs.c
50263@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
50264
50265 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
50266 struct dentry *next;
50267+ char d_name[sizeof(next->d_iname)];
50268+ const unsigned char *name;
50269+
50270 next = list_entry(p, struct dentry, d_u.d_child);
50271 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
50272 if (!simple_positive(next)) {
50273@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
50274
50275 spin_unlock(&next->d_lock);
50276 spin_unlock(&dentry->d_lock);
50277- if (filldir(dirent, next->d_name.name,
50278+ name = next->d_name.name;
50279+ if (name == next->d_iname) {
50280+ memcpy(d_name, name, next->d_name.len);
50281+ name = d_name;
50282+ }
50283+ if (filldir(dirent, name,
50284 next->d_name.len, filp->f_pos,
50285 next->d_inode->i_ino,
50286 dt_type(next->d_inode)) < 0)
50287diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
50288index 52e5120..808936e 100644
50289--- a/fs/lockd/clntproc.c
50290+++ b/fs/lockd/clntproc.c
50291@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
50292 /*
50293 * Cookie counter for NLM requests
50294 */
50295-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
50296+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
50297
50298 void nlmclnt_next_cookie(struct nlm_cookie *c)
50299 {
50300- u32 cookie = atomic_inc_return(&nlm_cookie);
50301+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
50302
50303 memcpy(c->data, &cookie, 4);
50304 c->len=4;
50305diff --git a/fs/locks.c b/fs/locks.c
50306index a94e331..060bce3 100644
50307--- a/fs/locks.c
50308+++ b/fs/locks.c
50309@@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
50310 return;
50311
50312 if (filp->f_op && filp->f_op->flock) {
50313- struct file_lock fl = {
50314+ struct file_lock flock = {
50315 .fl_pid = current->tgid,
50316 .fl_file = filp,
50317 .fl_flags = FL_FLOCK,
50318 .fl_type = F_UNLCK,
50319 .fl_end = OFFSET_MAX,
50320 };
50321- filp->f_op->flock(filp, F_SETLKW, &fl);
50322- if (fl.fl_ops && fl.fl_ops->fl_release_private)
50323- fl.fl_ops->fl_release_private(&fl);
50324+ filp->f_op->flock(filp, F_SETLKW, &flock);
50325+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
50326+ flock.fl_ops->fl_release_private(&flock);
50327 }
50328
50329 lock_flocks();
50330diff --git a/fs/namei.c b/fs/namei.c
50331index 43a97ee..4e585fd 100644
50332--- a/fs/namei.c
50333+++ b/fs/namei.c
50334@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
50335 if (ret != -EACCES)
50336 return ret;
50337
50338+#ifdef CONFIG_GRKERNSEC
50339+ /* we'll block if we have to log due to a denied capability use */
50340+ if (mask & MAY_NOT_BLOCK)
50341+ return -ECHILD;
50342+#endif
50343+
50344 if (S_ISDIR(inode->i_mode)) {
50345 /* DACs are overridable for directories */
50346- if (inode_capable(inode, CAP_DAC_OVERRIDE))
50347- return 0;
50348 if (!(mask & MAY_WRITE))
50349- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
50350+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
50351+ inode_capable(inode, CAP_DAC_READ_SEARCH))
50352 return 0;
50353+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
50354+ return 0;
50355 return -EACCES;
50356 }
50357 /*
50358+ * Searching includes executable on directories, else just read.
50359+ */
50360+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
50361+ if (mask == MAY_READ)
50362+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
50363+ inode_capable(inode, CAP_DAC_READ_SEARCH))
50364+ return 0;
50365+
50366+ /*
50367 * Read/write DACs are always overridable.
50368 * Executable DACs are overridable when there is
50369 * at least one exec bit set.
50370@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
50371 if (inode_capable(inode, CAP_DAC_OVERRIDE))
50372 return 0;
50373
50374- /*
50375- * Searching includes executable on directories, else just read.
50376- */
50377- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
50378- if (mask == MAY_READ)
50379- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
50380- return 0;
50381-
50382 return -EACCES;
50383 }
50384
50385@@ -826,7 +834,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
50386 {
50387 struct dentry *dentry = link->dentry;
50388 int error;
50389- char *s;
50390+ const char *s;
50391
50392 BUG_ON(nd->flags & LOOKUP_RCU);
50393
50394@@ -847,6 +855,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
50395 if (error)
50396 goto out_put_nd_path;
50397
50398+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
50399+ dentry->d_inode, dentry, nd->path.mnt)) {
50400+ error = -EACCES;
50401+ goto out_put_nd_path;
50402+ }
50403+
50404 nd->last_type = LAST_BIND;
50405 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
50406 error = PTR_ERR(*p);
50407@@ -1596,6 +1610,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
50408 break;
50409 res = walk_component(nd, path, &nd->last,
50410 nd->last_type, LOOKUP_FOLLOW);
50411+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
50412+ res = -EACCES;
50413 put_link(nd, &link, cookie);
50414 } while (res > 0);
50415
50416@@ -1694,7 +1710,7 @@ EXPORT_SYMBOL(full_name_hash);
50417 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
50418 {
50419 unsigned long a, b, adata, bdata, mask, hash, len;
50420- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
50421+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
50422
50423 hash = a = 0;
50424 len = -sizeof(unsigned long);
50425@@ -1979,6 +1995,8 @@ static int path_lookupat(int dfd, const char *name,
50426 if (err)
50427 break;
50428 err = lookup_last(nd, &path);
50429+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
50430+ err = -EACCES;
50431 put_link(nd, &link, cookie);
50432 }
50433 }
50434@@ -1986,6 +2004,19 @@ static int path_lookupat(int dfd, const char *name,
50435 if (!err)
50436 err = complete_walk(nd);
50437
50438+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
50439+#ifdef CONFIG_GRKERNSEC
50440+ if (flags & LOOKUP_RCU) {
50441+ path_put(&nd->path);
50442+ err = -ECHILD;
50443+ } else
50444+#endif
50445+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
50446+ path_put(&nd->path);
50447+ err = -ENOENT;
50448+ }
50449+ }
50450+
50451 if (!err && nd->flags & LOOKUP_DIRECTORY) {
50452 if (!nd->inode->i_op->lookup) {
50453 path_put(&nd->path);
50454@@ -2013,8 +2044,17 @@ static int filename_lookup(int dfd, struct filename *name,
50455 retval = path_lookupat(dfd, name->name,
50456 flags | LOOKUP_REVAL, nd);
50457
50458- if (likely(!retval))
50459+ if (likely(!retval)) {
50460+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
50461+#ifdef CONFIG_GRKERNSEC
50462+ if (flags & LOOKUP_RCU)
50463+ return -ECHILD;
50464+#endif
50465+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
50466+ return -ENOENT;
50467+ }
50468 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
50469+ }
50470 return retval;
50471 }
50472
50473@@ -2392,6 +2432,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
50474 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
50475 return -EPERM;
50476
50477+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
50478+ return -EPERM;
50479+ if (gr_handle_rawio(inode))
50480+ return -EPERM;
50481+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
50482+ return -EACCES;
50483+
50484 return 0;
50485 }
50486
50487@@ -2613,7 +2660,7 @@ looked_up:
50488 * cleared otherwise prior to returning.
50489 */
50490 static int lookup_open(struct nameidata *nd, struct path *path,
50491- struct file *file,
50492+ struct path *link, struct file *file,
50493 const struct open_flags *op,
50494 bool got_write, int *opened)
50495 {
50496@@ -2648,6 +2695,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
50497 /* Negative dentry, just create the file */
50498 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
50499 umode_t mode = op->mode;
50500+
50501+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
50502+ error = -EACCES;
50503+ goto out_dput;
50504+ }
50505+
50506+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
50507+ error = -EACCES;
50508+ goto out_dput;
50509+ }
50510+
50511 if (!IS_POSIXACL(dir->d_inode))
50512 mode &= ~current_umask();
50513 /*
50514@@ -2669,6 +2727,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
50515 nd->flags & LOOKUP_EXCL);
50516 if (error)
50517 goto out_dput;
50518+ else
50519+ gr_handle_create(dentry, nd->path.mnt);
50520 }
50521 out_no_open:
50522 path->dentry = dentry;
50523@@ -2683,7 +2743,7 @@ out_dput:
50524 /*
50525 * Handle the last step of open()
50526 */
50527-static int do_last(struct nameidata *nd, struct path *path,
50528+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
50529 struct file *file, const struct open_flags *op,
50530 int *opened, struct filename *name)
50531 {
50532@@ -2712,16 +2772,44 @@ static int do_last(struct nameidata *nd, struct path *path,
50533 error = complete_walk(nd);
50534 if (error)
50535 return error;
50536+#ifdef CONFIG_GRKERNSEC
50537+ if (nd->flags & LOOKUP_RCU) {
50538+ error = -ECHILD;
50539+ goto out;
50540+ }
50541+#endif
50542+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
50543+ error = -ENOENT;
50544+ goto out;
50545+ }
50546 audit_inode(name, nd->path.dentry, 0);
50547 if (open_flag & O_CREAT) {
50548 error = -EISDIR;
50549 goto out;
50550 }
50551+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
50552+ error = -EACCES;
50553+ goto out;
50554+ }
50555 goto finish_open;
50556 case LAST_BIND:
50557 error = complete_walk(nd);
50558 if (error)
50559 return error;
50560+#ifdef CONFIG_GRKERNSEC
50561+ if (nd->flags & LOOKUP_RCU) {
50562+ error = -ECHILD;
50563+ goto out;
50564+ }
50565+#endif
50566+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
50567+ error = -ENOENT;
50568+ goto out;
50569+ }
50570+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
50571+ error = -EACCES;
50572+ goto out;
50573+ }
50574 audit_inode(name, dir, 0);
50575 goto finish_open;
50576 }
50577@@ -2770,7 +2858,7 @@ retry_lookup:
50578 */
50579 }
50580 mutex_lock(&dir->d_inode->i_mutex);
50581- error = lookup_open(nd, path, file, op, got_write, opened);
50582+ error = lookup_open(nd, path, link, file, op, got_write, opened);
50583 mutex_unlock(&dir->d_inode->i_mutex);
50584
50585 if (error <= 0) {
50586@@ -2794,11 +2882,28 @@ retry_lookup:
50587 goto finish_open_created;
50588 }
50589
50590+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
50591+ error = -ENOENT;
50592+ goto exit_dput;
50593+ }
50594+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
50595+ error = -EACCES;
50596+ goto exit_dput;
50597+ }
50598+
50599 /*
50600 * create/update audit record if it already exists.
50601 */
50602- if (path->dentry->d_inode)
50603+ if (path->dentry->d_inode) {
50604+ /* only check if O_CREAT is specified, all other checks need to go
50605+ into may_open */
50606+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
50607+ error = -EACCES;
50608+ goto exit_dput;
50609+ }
50610+
50611 audit_inode(name, path->dentry, 0);
50612+ }
50613
50614 /*
50615 * If atomic_open() acquired write access it is dropped now due to
50616@@ -2839,6 +2944,11 @@ finish_lookup:
50617 }
50618 }
50619 BUG_ON(inode != path->dentry->d_inode);
50620+ /* if we're resolving a symlink to another symlink */
50621+ if (link && gr_handle_symlink_owner(link, inode)) {
50622+ error = -EACCES;
50623+ goto out;
50624+ }
50625 return 1;
50626 }
50627
50628@@ -2848,7 +2958,6 @@ finish_lookup:
50629 save_parent.dentry = nd->path.dentry;
50630 save_parent.mnt = mntget(path->mnt);
50631 nd->path.dentry = path->dentry;
50632-
50633 }
50634 nd->inode = inode;
50635 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
50636@@ -2857,6 +2966,22 @@ finish_lookup:
50637 path_put(&save_parent);
50638 return error;
50639 }
50640+
50641+#ifdef CONFIG_GRKERNSEC
50642+ if (nd->flags & LOOKUP_RCU) {
50643+ error = -ECHILD;
50644+ goto out;
50645+ }
50646+#endif
50647+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
50648+ error = -ENOENT;
50649+ goto out;
50650+ }
50651+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
50652+ error = -EACCES;
50653+ goto out;
50654+ }
50655+
50656 error = -EISDIR;
50657 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
50658 goto out;
50659@@ -2955,7 +3080,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
50660 if (unlikely(error))
50661 goto out;
50662
50663- error = do_last(nd, &path, file, op, &opened, pathname);
50664+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
50665 while (unlikely(error > 0)) { /* trailing symlink */
50666 struct path link = path;
50667 void *cookie;
50668@@ -2973,7 +3098,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
50669 error = follow_link(&link, nd, &cookie);
50670 if (unlikely(error))
50671 break;
50672- error = do_last(nd, &path, file, op, &opened, pathname);
50673+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
50674 put_link(nd, &link, cookie);
50675 }
50676 out:
50677@@ -3073,8 +3198,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
50678 goto unlock;
50679
50680 error = -EEXIST;
50681- if (dentry->d_inode)
50682+ if (dentry->d_inode) {
50683+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
50684+ error = -ENOENT;
50685+ }
50686 goto fail;
50687+ }
50688 /*
50689 * Special case - lookup gave negative, but... we had foo/bar/
50690 * From the vfs_mknod() POV we just have a negative dentry -
50691@@ -3126,6 +3255,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
50692 }
50693 EXPORT_SYMBOL(user_path_create);
50694
50695+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
50696+{
50697+ struct filename *tmp = getname(pathname);
50698+ struct dentry *res;
50699+ if (IS_ERR(tmp))
50700+ return ERR_CAST(tmp);
50701+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
50702+ if (IS_ERR(res))
50703+ putname(tmp);
50704+ else
50705+ *to = tmp;
50706+ return res;
50707+}
50708+
50709 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
50710 {
50711 int error = may_create(dir, dentry);
50712@@ -3188,6 +3331,17 @@ retry:
50713
50714 if (!IS_POSIXACL(path.dentry->d_inode))
50715 mode &= ~current_umask();
50716+
50717+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
50718+ error = -EPERM;
50719+ goto out;
50720+ }
50721+
50722+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
50723+ error = -EACCES;
50724+ goto out;
50725+ }
50726+
50727 error = security_path_mknod(&path, dentry, mode, dev);
50728 if (error)
50729 goto out;
50730@@ -3204,6 +3358,8 @@ retry:
50731 break;
50732 }
50733 out:
50734+ if (!error)
50735+ gr_handle_create(dentry, path.mnt);
50736 done_path_create(&path, dentry);
50737 if (retry_estale(error, lookup_flags)) {
50738 lookup_flags |= LOOKUP_REVAL;
50739@@ -3256,9 +3412,16 @@ retry:
50740
50741 if (!IS_POSIXACL(path.dentry->d_inode))
50742 mode &= ~current_umask();
50743+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
50744+ error = -EACCES;
50745+ goto out;
50746+ }
50747 error = security_path_mkdir(&path, dentry, mode);
50748 if (!error)
50749 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
50750+ if (!error)
50751+ gr_handle_create(dentry, path.mnt);
50752+out:
50753 done_path_create(&path, dentry);
50754 if (retry_estale(error, lookup_flags)) {
50755 lookup_flags |= LOOKUP_REVAL;
50756@@ -3339,6 +3502,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
50757 struct filename *name;
50758 struct dentry *dentry;
50759 struct nameidata nd;
50760+ ino_t saved_ino = 0;
50761+ dev_t saved_dev = 0;
50762 unsigned int lookup_flags = 0;
50763 retry:
50764 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
50765@@ -3371,10 +3536,21 @@ retry:
50766 error = -ENOENT;
50767 goto exit3;
50768 }
50769+
50770+ saved_ino = dentry->d_inode->i_ino;
50771+ saved_dev = gr_get_dev_from_dentry(dentry);
50772+
50773+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
50774+ error = -EACCES;
50775+ goto exit3;
50776+ }
50777+
50778 error = security_path_rmdir(&nd.path, dentry);
50779 if (error)
50780 goto exit3;
50781 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
50782+ if (!error && (saved_dev || saved_ino))
50783+ gr_handle_delete(saved_ino, saved_dev);
50784 exit3:
50785 dput(dentry);
50786 exit2:
50787@@ -3440,6 +3616,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
50788 struct dentry *dentry;
50789 struct nameidata nd;
50790 struct inode *inode = NULL;
50791+ ino_t saved_ino = 0;
50792+ dev_t saved_dev = 0;
50793 unsigned int lookup_flags = 0;
50794 retry:
50795 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
50796@@ -3466,10 +3644,22 @@ retry:
50797 if (!inode)
50798 goto slashes;
50799 ihold(inode);
50800+
50801+ if (inode->i_nlink <= 1) {
50802+ saved_ino = inode->i_ino;
50803+ saved_dev = gr_get_dev_from_dentry(dentry);
50804+ }
50805+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
50806+ error = -EACCES;
50807+ goto exit2;
50808+ }
50809+
50810 error = security_path_unlink(&nd.path, dentry);
50811 if (error)
50812 goto exit2;
50813 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
50814+ if (!error && (saved_ino || saved_dev))
50815+ gr_handle_delete(saved_ino, saved_dev);
50816 exit2:
50817 dput(dentry);
50818 }
50819@@ -3547,9 +3737,17 @@ retry:
50820 if (IS_ERR(dentry))
50821 goto out_putname;
50822
50823+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
50824+ error = -EACCES;
50825+ goto out;
50826+ }
50827+
50828 error = security_path_symlink(&path, dentry, from->name);
50829 if (!error)
50830 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
50831+ if (!error)
50832+ gr_handle_create(dentry, path.mnt);
50833+out:
50834 done_path_create(&path, dentry);
50835 if (retry_estale(error, lookup_flags)) {
50836 lookup_flags |= LOOKUP_REVAL;
50837@@ -3623,6 +3821,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
50838 {
50839 struct dentry *new_dentry;
50840 struct path old_path, new_path;
50841+ struct filename *to = NULL;
50842 int how = 0;
50843 int error;
50844
50845@@ -3646,7 +3845,7 @@ retry:
50846 if (error)
50847 return error;
50848
50849- new_dentry = user_path_create(newdfd, newname, &new_path,
50850+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
50851 (how & LOOKUP_REVAL));
50852 error = PTR_ERR(new_dentry);
50853 if (IS_ERR(new_dentry))
50854@@ -3658,11 +3857,28 @@ retry:
50855 error = may_linkat(&old_path);
50856 if (unlikely(error))
50857 goto out_dput;
50858+
50859+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
50860+ old_path.dentry->d_inode,
50861+ old_path.dentry->d_inode->i_mode, to)) {
50862+ error = -EACCES;
50863+ goto out_dput;
50864+ }
50865+
50866+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
50867+ old_path.dentry, old_path.mnt, to)) {
50868+ error = -EACCES;
50869+ goto out_dput;
50870+ }
50871+
50872 error = security_path_link(old_path.dentry, &new_path, new_dentry);
50873 if (error)
50874 goto out_dput;
50875 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
50876+ if (!error)
50877+ gr_handle_create(new_dentry, new_path.mnt);
50878 out_dput:
50879+ putname(to);
50880 done_path_create(&new_path, new_dentry);
50881 if (retry_estale(error, how)) {
50882 how |= LOOKUP_REVAL;
50883@@ -3908,12 +4124,21 @@ retry:
50884 if (new_dentry == trap)
50885 goto exit5;
50886
50887+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
50888+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
50889+ to);
50890+ if (error)
50891+ goto exit5;
50892+
50893 error = security_path_rename(&oldnd.path, old_dentry,
50894 &newnd.path, new_dentry);
50895 if (error)
50896 goto exit5;
50897 error = vfs_rename(old_dir->d_inode, old_dentry,
50898 new_dir->d_inode, new_dentry);
50899+ if (!error)
50900+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
50901+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
50902 exit5:
50903 dput(new_dentry);
50904 exit4:
50905@@ -3945,6 +4170,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
50906
50907 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
50908 {
50909+ char tmpbuf[64];
50910+ const char *newlink;
50911 int len;
50912
50913 len = PTR_ERR(link);
50914@@ -3954,7 +4181,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
50915 len = strlen(link);
50916 if (len > (unsigned) buflen)
50917 len = buflen;
50918- if (copy_to_user(buffer, link, len))
50919+
50920+ if (len < sizeof(tmpbuf)) {
50921+ memcpy(tmpbuf, link, len);
50922+ newlink = tmpbuf;
50923+ } else
50924+ newlink = link;
50925+
50926+ if (copy_to_user(buffer, newlink, len))
50927 len = -EFAULT;
50928 out:
50929 return len;
50930diff --git a/fs/namespace.c b/fs/namespace.c
50931index a51054f..f9b53e5 100644
50932--- a/fs/namespace.c
50933+++ b/fs/namespace.c
50934@@ -1215,6 +1215,9 @@ static int do_umount(struct mount *mnt, int flags)
50935 if (!(sb->s_flags & MS_RDONLY))
50936 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
50937 up_write(&sb->s_umount);
50938+
50939+ gr_log_remount(mnt->mnt_devname, retval);
50940+
50941 return retval;
50942 }
50943
50944@@ -1234,6 +1237,9 @@ static int do_umount(struct mount *mnt, int flags)
50945 br_write_unlock(&vfsmount_lock);
50946 up_write(&namespace_sem);
50947 release_mounts(&umount_list);
50948+
50949+ gr_log_unmount(mnt->mnt_devname, retval);
50950+
50951 return retval;
50952 }
50953
50954@@ -2287,6 +2293,16 @@ long do_mount(const char *dev_name, const char *dir_name,
50955 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
50956 MS_STRICTATIME);
50957
50958+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
50959+ retval = -EPERM;
50960+ goto dput_out;
50961+ }
50962+
50963+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
50964+ retval = -EPERM;
50965+ goto dput_out;
50966+ }
50967+
50968 if (flags & MS_REMOUNT)
50969 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
50970 data_page);
50971@@ -2301,6 +2317,9 @@ long do_mount(const char *dev_name, const char *dir_name,
50972 dev_name, data_page);
50973 dput_out:
50974 path_put(&path);
50975+
50976+ gr_log_mount(dev_name, dir_name, retval);
50977+
50978 return retval;
50979 }
50980
50981@@ -2587,6 +2606,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
50982 if (error)
50983 goto out2;
50984
50985+ if (gr_handle_chroot_pivot()) {
50986+ error = -EPERM;
50987+ goto out2;
50988+ }
50989+
50990 get_fs_root(current->fs, &root);
50991 error = lock_mount(&old);
50992 if (error)
50993@@ -2790,7 +2814,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
50994 !nsown_capable(CAP_SYS_ADMIN))
50995 return -EPERM;
50996
50997- if (fs->users != 1)
50998+ if (atomic_read(&fs->users) != 1)
50999 return -EINVAL;
51000
51001 get_mnt_ns(mnt_ns);
51002diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
51003index ebeb94c..ff35337 100644
51004--- a/fs/nfs/inode.c
51005+++ b/fs/nfs/inode.c
51006@@ -1042,16 +1042,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
51007 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
51008 }
51009
51010-static atomic_long_t nfs_attr_generation_counter;
51011+static atomic_long_unchecked_t nfs_attr_generation_counter;
51012
51013 static unsigned long nfs_read_attr_generation_counter(void)
51014 {
51015- return atomic_long_read(&nfs_attr_generation_counter);
51016+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
51017 }
51018
51019 unsigned long nfs_inc_attr_generation_counter(void)
51020 {
51021- return atomic_long_inc_return(&nfs_attr_generation_counter);
51022+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
51023 }
51024
51025 void nfs_fattr_init(struct nfs_fattr *fattr)
51026diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
51027index d586117..143d568 100644
51028--- a/fs/nfsd/vfs.c
51029+++ b/fs/nfsd/vfs.c
51030@@ -939,7 +939,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
51031 } else {
51032 oldfs = get_fs();
51033 set_fs(KERNEL_DS);
51034- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
51035+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
51036 set_fs(oldfs);
51037 }
51038
51039@@ -1025,7 +1025,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
51040
51041 /* Write the data. */
51042 oldfs = get_fs(); set_fs(KERNEL_DS);
51043- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
51044+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
51045 set_fs(oldfs);
51046 if (host_err < 0)
51047 goto out_nfserr;
51048@@ -1571,7 +1571,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
51049 */
51050
51051 oldfs = get_fs(); set_fs(KERNEL_DS);
51052- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
51053+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
51054 set_fs(oldfs);
51055
51056 if (host_err < 0)
51057diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
51058index 9ff4a5e..deb1f0f 100644
51059--- a/fs/notify/fanotify/fanotify_user.c
51060+++ b/fs/notify/fanotify/fanotify_user.c
51061@@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
51062
51063 fd = fanotify_event_metadata.fd;
51064 ret = -EFAULT;
51065- if (copy_to_user(buf, &fanotify_event_metadata,
51066- fanotify_event_metadata.event_len))
51067+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
51068+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
51069 goto out_close_fd;
51070
51071 ret = prepare_for_access_response(group, event, fd);
51072diff --git a/fs/notify/notification.c b/fs/notify/notification.c
51073index 7b51b05..5ea5ef6 100644
51074--- a/fs/notify/notification.c
51075+++ b/fs/notify/notification.c
51076@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
51077 * get set to 0 so it will never get 'freed'
51078 */
51079 static struct fsnotify_event *q_overflow_event;
51080-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
51081+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
51082
51083 /**
51084 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
51085@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
51086 */
51087 u32 fsnotify_get_cookie(void)
51088 {
51089- return atomic_inc_return(&fsnotify_sync_cookie);
51090+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
51091 }
51092 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
51093
51094diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
51095index 99e3610..02c1068 100644
51096--- a/fs/ntfs/dir.c
51097+++ b/fs/ntfs/dir.c
51098@@ -1329,7 +1329,7 @@ find_next_index_buffer:
51099 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
51100 ~(s64)(ndir->itype.index.block_size - 1)));
51101 /* Bounds checks. */
51102- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
51103+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
51104 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
51105 "inode 0x%lx or driver bug.", vdir->i_ino);
51106 goto err_out;
51107diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
51108index 5b2d4f0..c6de396 100644
51109--- a/fs/ntfs/file.c
51110+++ b/fs/ntfs/file.c
51111@@ -2242,6 +2242,6 @@ const struct inode_operations ntfs_file_inode_ops = {
51112 #endif /* NTFS_RW */
51113 };
51114
51115-const struct file_operations ntfs_empty_file_ops = {};
51116+const struct file_operations ntfs_empty_file_ops __read_only;
51117
51118-const struct inode_operations ntfs_empty_inode_ops = {};
51119+const struct inode_operations ntfs_empty_inode_ops __read_only;
51120diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
51121index a9f78c7..ed8a381 100644
51122--- a/fs/ocfs2/localalloc.c
51123+++ b/fs/ocfs2/localalloc.c
51124@@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
51125 goto bail;
51126 }
51127
51128- atomic_inc(&osb->alloc_stats.moves);
51129+ atomic_inc_unchecked(&osb->alloc_stats.moves);
51130
51131 bail:
51132 if (handle)
51133diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
51134index d355e6e..578d905 100644
51135--- a/fs/ocfs2/ocfs2.h
51136+++ b/fs/ocfs2/ocfs2.h
51137@@ -235,11 +235,11 @@ enum ocfs2_vol_state
51138
51139 struct ocfs2_alloc_stats
51140 {
51141- atomic_t moves;
51142- atomic_t local_data;
51143- atomic_t bitmap_data;
51144- atomic_t bg_allocs;
51145- atomic_t bg_extends;
51146+ atomic_unchecked_t moves;
51147+ atomic_unchecked_t local_data;
51148+ atomic_unchecked_t bitmap_data;
51149+ atomic_unchecked_t bg_allocs;
51150+ atomic_unchecked_t bg_extends;
51151 };
51152
51153 enum ocfs2_local_alloc_state
51154diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
51155index f169da4..9112253 100644
51156--- a/fs/ocfs2/suballoc.c
51157+++ b/fs/ocfs2/suballoc.c
51158@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
51159 mlog_errno(status);
51160 goto bail;
51161 }
51162- atomic_inc(&osb->alloc_stats.bg_extends);
51163+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
51164
51165 /* You should never ask for this much metadata */
51166 BUG_ON(bits_wanted >
51167@@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
51168 mlog_errno(status);
51169 goto bail;
51170 }
51171- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51172+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51173
51174 *suballoc_loc = res.sr_bg_blkno;
51175 *suballoc_bit_start = res.sr_bit_offset;
51176@@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
51177 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
51178 res->sr_bits);
51179
51180- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51181+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51182
51183 BUG_ON(res->sr_bits != 1);
51184
51185@@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
51186 mlog_errno(status);
51187 goto bail;
51188 }
51189- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51190+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51191
51192 BUG_ON(res.sr_bits != 1);
51193
51194@@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
51195 cluster_start,
51196 num_clusters);
51197 if (!status)
51198- atomic_inc(&osb->alloc_stats.local_data);
51199+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
51200 } else {
51201 if (min_clusters > (osb->bitmap_cpg - 1)) {
51202 /* The only paths asking for contiguousness
51203@@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
51204 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
51205 res.sr_bg_blkno,
51206 res.sr_bit_offset);
51207- atomic_inc(&osb->alloc_stats.bitmap_data);
51208+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
51209 *num_clusters = res.sr_bits;
51210 }
51211 }
51212diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
51213index 0e91ec2..f4b3fc6 100644
51214--- a/fs/ocfs2/super.c
51215+++ b/fs/ocfs2/super.c
51216@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
51217 "%10s => GlobalAllocs: %d LocalAllocs: %d "
51218 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
51219 "Stats",
51220- atomic_read(&osb->alloc_stats.bitmap_data),
51221- atomic_read(&osb->alloc_stats.local_data),
51222- atomic_read(&osb->alloc_stats.bg_allocs),
51223- atomic_read(&osb->alloc_stats.moves),
51224- atomic_read(&osb->alloc_stats.bg_extends));
51225+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
51226+ atomic_read_unchecked(&osb->alloc_stats.local_data),
51227+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
51228+ atomic_read_unchecked(&osb->alloc_stats.moves),
51229+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
51230
51231 out += snprintf(buf + out, len - out,
51232 "%10s => State: %u Descriptor: %llu Size: %u bits "
51233@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
51234 spin_lock_init(&osb->osb_xattr_lock);
51235 ocfs2_init_steal_slots(osb);
51236
51237- atomic_set(&osb->alloc_stats.moves, 0);
51238- atomic_set(&osb->alloc_stats.local_data, 0);
51239- atomic_set(&osb->alloc_stats.bitmap_data, 0);
51240- atomic_set(&osb->alloc_stats.bg_allocs, 0);
51241- atomic_set(&osb->alloc_stats.bg_extends, 0);
51242+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
51243+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
51244+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
51245+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
51246+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
51247
51248 /* Copy the blockcheck stats from the superblock probe */
51249 osb->osb_ecc_stats = *stats;
51250diff --git a/fs/open.c b/fs/open.c
51251index 9b33c0c..2ffcca2 100644
51252--- a/fs/open.c
51253+++ b/fs/open.c
51254@@ -31,6 +31,8 @@
51255 #include <linux/ima.h>
51256 #include <linux/dnotify.h>
51257
51258+#define CREATE_TRACE_POINTS
51259+#include <trace/events/fs.h>
51260 #include "internal.h"
51261
51262 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
51263@@ -101,6 +103,8 @@ long vfs_truncate(struct path *path, loff_t length)
51264 error = locks_verify_truncate(inode, NULL, length);
51265 if (!error)
51266 error = security_path_truncate(path);
51267+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
51268+ error = -EACCES;
51269 if (!error)
51270 error = do_truncate(path->dentry, length, 0, NULL);
51271
51272@@ -178,6 +182,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
51273 error = locks_verify_truncate(inode, f.file, length);
51274 if (!error)
51275 error = security_path_truncate(&f.file->f_path);
51276+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
51277+ error = -EACCES;
51278 if (!error)
51279 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
51280 sb_end_write(inode->i_sb);
51281@@ -373,6 +379,9 @@ retry:
51282 if (__mnt_is_readonly(path.mnt))
51283 res = -EROFS;
51284
51285+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
51286+ res = -EACCES;
51287+
51288 out_path_release:
51289 path_put(&path);
51290 if (retry_estale(res, lookup_flags)) {
51291@@ -404,6 +413,8 @@ retry:
51292 if (error)
51293 goto dput_and_out;
51294
51295+ gr_log_chdir(path.dentry, path.mnt);
51296+
51297 set_fs_pwd(current->fs, &path);
51298
51299 dput_and_out:
51300@@ -433,6 +444,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
51301 goto out_putf;
51302
51303 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
51304+
51305+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
51306+ error = -EPERM;
51307+
51308+ if (!error)
51309+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
51310+
51311 if (!error)
51312 set_fs_pwd(current->fs, &f.file->f_path);
51313 out_putf:
51314@@ -462,7 +480,13 @@ retry:
51315 if (error)
51316 goto dput_and_out;
51317
51318+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
51319+ goto dput_and_out;
51320+
51321 set_fs_root(current->fs, &path);
51322+
51323+ gr_handle_chroot_chdir(&path);
51324+
51325 error = 0;
51326 dput_and_out:
51327 path_put(&path);
51328@@ -484,6 +508,16 @@ static int chmod_common(struct path *path, umode_t mode)
51329 if (error)
51330 return error;
51331 mutex_lock(&inode->i_mutex);
51332+
51333+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
51334+ error = -EACCES;
51335+ goto out_unlock;
51336+ }
51337+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
51338+ error = -EACCES;
51339+ goto out_unlock;
51340+ }
51341+
51342 error = security_path_chmod(path, mode);
51343 if (error)
51344 goto out_unlock;
51345@@ -544,6 +578,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
51346 uid = make_kuid(current_user_ns(), user);
51347 gid = make_kgid(current_user_ns(), group);
51348
51349+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
51350+ return -EACCES;
51351+
51352 newattrs.ia_valid = ATTR_CTIME;
51353 if (user != (uid_t) -1) {
51354 if (!uid_valid(uid))
51355@@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
51356 } else {
51357 fsnotify_open(f);
51358 fd_install(fd, f);
51359+ trace_do_sys_open(tmp->name, flags, mode);
51360 }
51361 }
51362 putname(tmp);
51363diff --git a/fs/pipe.c b/fs/pipe.c
51364index bd3479d..fb92c4d 100644
51365--- a/fs/pipe.c
51366+++ b/fs/pipe.c
51367@@ -438,9 +438,9 @@ redo:
51368 }
51369 if (bufs) /* More to do? */
51370 continue;
51371- if (!pipe->writers)
51372+ if (!atomic_read(&pipe->writers))
51373 break;
51374- if (!pipe->waiting_writers) {
51375+ if (!atomic_read(&pipe->waiting_writers)) {
51376 /* syscall merging: Usually we must not sleep
51377 * if O_NONBLOCK is set, or if we got some data.
51378 * But if a writer sleeps in kernel space, then
51379@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
51380 mutex_lock(&inode->i_mutex);
51381 pipe = inode->i_pipe;
51382
51383- if (!pipe->readers) {
51384+ if (!atomic_read(&pipe->readers)) {
51385 send_sig(SIGPIPE, current, 0);
51386 ret = -EPIPE;
51387 goto out;
51388@@ -553,7 +553,7 @@ redo1:
51389 for (;;) {
51390 int bufs;
51391
51392- if (!pipe->readers) {
51393+ if (!atomic_read(&pipe->readers)) {
51394 send_sig(SIGPIPE, current, 0);
51395 if (!ret)
51396 ret = -EPIPE;
51397@@ -644,9 +644,9 @@ redo2:
51398 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
51399 do_wakeup = 0;
51400 }
51401- pipe->waiting_writers++;
51402+ atomic_inc(&pipe->waiting_writers);
51403 pipe_wait(pipe);
51404- pipe->waiting_writers--;
51405+ atomic_dec(&pipe->waiting_writers);
51406 }
51407 out:
51408 mutex_unlock(&inode->i_mutex);
51409@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
51410 mask = 0;
51411 if (filp->f_mode & FMODE_READ) {
51412 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
51413- if (!pipe->writers && filp->f_version != pipe->w_counter)
51414+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
51415 mask |= POLLHUP;
51416 }
51417
51418@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
51419 * Most Unices do not set POLLERR for FIFOs but on Linux they
51420 * behave exactly like pipes for poll().
51421 */
51422- if (!pipe->readers)
51423+ if (!atomic_read(&pipe->readers))
51424 mask |= POLLERR;
51425 }
51426
51427@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
51428
51429 mutex_lock(&inode->i_mutex);
51430 pipe = inode->i_pipe;
51431- pipe->readers -= decr;
51432- pipe->writers -= decw;
51433+ atomic_sub(decr, &pipe->readers);
51434+ atomic_sub(decw, &pipe->writers);
51435
51436- if (!pipe->readers && !pipe->writers) {
51437+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
51438 free_pipe_info(inode);
51439 } else {
51440 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
51441@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
51442
51443 if (inode->i_pipe) {
51444 ret = 0;
51445- inode->i_pipe->readers++;
51446+ atomic_inc(&inode->i_pipe->readers);
51447 }
51448
51449 mutex_unlock(&inode->i_mutex);
51450@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
51451
51452 if (inode->i_pipe) {
51453 ret = 0;
51454- inode->i_pipe->writers++;
51455+ atomic_inc(&inode->i_pipe->writers);
51456 }
51457
51458 mutex_unlock(&inode->i_mutex);
51459@@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
51460 if (inode->i_pipe) {
51461 ret = 0;
51462 if (filp->f_mode & FMODE_READ)
51463- inode->i_pipe->readers++;
51464+ atomic_inc(&inode->i_pipe->readers);
51465 if (filp->f_mode & FMODE_WRITE)
51466- inode->i_pipe->writers++;
51467+ atomic_inc(&inode->i_pipe->writers);
51468 }
51469
51470 mutex_unlock(&inode->i_mutex);
51471@@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
51472 inode->i_pipe = NULL;
51473 }
51474
51475-static struct vfsmount *pipe_mnt __read_mostly;
51476+struct vfsmount *pipe_mnt __read_mostly;
51477
51478 /*
51479 * pipefs_dname() is called from d_path().
51480@@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
51481 goto fail_iput;
51482 inode->i_pipe = pipe;
51483
51484- pipe->readers = pipe->writers = 1;
51485+ atomic_set(&pipe->readers, 1);
51486+ atomic_set(&pipe->writers, 1);
51487 inode->i_fop = &rdwr_pipefifo_fops;
51488
51489 /*
51490diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
51491index 15af622..0e9f4467 100644
51492--- a/fs/proc/Kconfig
51493+++ b/fs/proc/Kconfig
51494@@ -30,12 +30,12 @@ config PROC_FS
51495
51496 config PROC_KCORE
51497 bool "/proc/kcore support" if !ARM
51498- depends on PROC_FS && MMU
51499+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
51500
51501 config PROC_VMCORE
51502 bool "/proc/vmcore support"
51503- depends on PROC_FS && CRASH_DUMP
51504- default y
51505+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
51506+ default n
51507 help
51508 Exports the dump image of crashed kernel in ELF format.
51509
51510@@ -59,8 +59,8 @@ config PROC_SYSCTL
51511 limited in memory.
51512
51513 config PROC_PAGE_MONITOR
51514- default y
51515- depends on PROC_FS && MMU
51516+ default n
51517+ depends on PROC_FS && MMU && !GRKERNSEC
51518 bool "Enable /proc page monitoring" if EXPERT
51519 help
51520 Various /proc files exist to monitor process memory utilization:
51521diff --git a/fs/proc/array.c b/fs/proc/array.c
51522index 6a91e6f..e54dbc14 100644
51523--- a/fs/proc/array.c
51524+++ b/fs/proc/array.c
51525@@ -60,6 +60,7 @@
51526 #include <linux/tty.h>
51527 #include <linux/string.h>
51528 #include <linux/mman.h>
51529+#include <linux/grsecurity.h>
51530 #include <linux/proc_fs.h>
51531 #include <linux/ioport.h>
51532 #include <linux/uaccess.h>
51533@@ -362,6 +363,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
51534 seq_putc(m, '\n');
51535 }
51536
51537+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
51538+static inline void task_pax(struct seq_file *m, struct task_struct *p)
51539+{
51540+ if (p->mm)
51541+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
51542+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
51543+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
51544+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
51545+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
51546+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
51547+ else
51548+ seq_printf(m, "PaX:\t-----\n");
51549+}
51550+#endif
51551+
51552 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
51553 struct pid *pid, struct task_struct *task)
51554 {
51555@@ -380,9 +396,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
51556 task_cpus_allowed(m, task);
51557 cpuset_task_status_allowed(m, task);
51558 task_context_switch_counts(m, task);
51559+
51560+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
51561+ task_pax(m, task);
51562+#endif
51563+
51564+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
51565+ task_grsec_rbac(m, task);
51566+#endif
51567+
51568 return 0;
51569 }
51570
51571+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51572+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
51573+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
51574+ _mm->pax_flags & MF_PAX_SEGMEXEC))
51575+#endif
51576+
51577 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51578 struct pid *pid, struct task_struct *task, int whole)
51579 {
51580@@ -404,6 +435,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51581 char tcomm[sizeof(task->comm)];
51582 unsigned long flags;
51583
51584+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51585+ if (current->exec_id != m->exec_id) {
51586+ gr_log_badprocpid("stat");
51587+ return 0;
51588+ }
51589+#endif
51590+
51591 state = *get_task_state(task);
51592 vsize = eip = esp = 0;
51593 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
51594@@ -475,6 +513,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51595 gtime = task->gtime;
51596 }
51597
51598+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51599+ if (PAX_RAND_FLAGS(mm)) {
51600+ eip = 0;
51601+ esp = 0;
51602+ wchan = 0;
51603+ }
51604+#endif
51605+#ifdef CONFIG_GRKERNSEC_HIDESYM
51606+ wchan = 0;
51607+ eip =0;
51608+ esp =0;
51609+#endif
51610+
51611 /* scale priority and nice values from timeslices to -20..20 */
51612 /* to make it look like a "normal" Unix priority/nice value */
51613 priority = task_prio(task);
51614@@ -511,9 +562,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51615 seq_put_decimal_ull(m, ' ', vsize);
51616 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
51617 seq_put_decimal_ull(m, ' ', rsslim);
51618+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51619+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
51620+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
51621+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
51622+#else
51623 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
51624 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
51625 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
51626+#endif
51627 seq_put_decimal_ull(m, ' ', esp);
51628 seq_put_decimal_ull(m, ' ', eip);
51629 /* The signal information here is obsolete.
51630@@ -535,7 +592,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51631 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
51632 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
51633
51634- if (mm && permitted) {
51635+ if (mm && permitted
51636+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51637+ && !PAX_RAND_FLAGS(mm)
51638+#endif
51639+ ) {
51640 seq_put_decimal_ull(m, ' ', mm->start_data);
51641 seq_put_decimal_ull(m, ' ', mm->end_data);
51642 seq_put_decimal_ull(m, ' ', mm->start_brk);
51643@@ -573,8 +634,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
51644 struct pid *pid, struct task_struct *task)
51645 {
51646 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
51647- struct mm_struct *mm = get_task_mm(task);
51648+ struct mm_struct *mm;
51649
51650+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51651+ if (current->exec_id != m->exec_id) {
51652+ gr_log_badprocpid("statm");
51653+ return 0;
51654+ }
51655+#endif
51656+ mm = get_task_mm(task);
51657 if (mm) {
51658 size = task_statm(mm, &shared, &text, &data, &resident);
51659 mmput(mm);
51660@@ -597,6 +665,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
51661 return 0;
51662 }
51663
51664+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
51665+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
51666+{
51667+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
51668+}
51669+#endif
51670+
51671 #ifdef CONFIG_CHECKPOINT_RESTORE
51672 static struct pid *
51673 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
51674diff --git a/fs/proc/base.c b/fs/proc/base.c
51675index 9b43ff77..3d6a99f 100644
51676--- a/fs/proc/base.c
51677+++ b/fs/proc/base.c
51678@@ -111,6 +111,14 @@ struct pid_entry {
51679 union proc_op op;
51680 };
51681
51682+struct getdents_callback {
51683+ struct linux_dirent __user * current_dir;
51684+ struct linux_dirent __user * previous;
51685+ struct file * file;
51686+ int count;
51687+ int error;
51688+};
51689+
51690 #define NOD(NAME, MODE, IOP, FOP, OP) { \
51691 .name = (NAME), \
51692 .len = sizeof(NAME) - 1, \
51693@@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
51694 if (!mm->arg_end)
51695 goto out_mm; /* Shh! No looking before we're done */
51696
51697+ if (gr_acl_handle_procpidmem(task))
51698+ goto out_mm;
51699+
51700 len = mm->arg_end - mm->arg_start;
51701
51702 if (len > PAGE_SIZE)
51703@@ -235,12 +246,28 @@ out:
51704 return res;
51705 }
51706
51707+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51708+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
51709+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
51710+ _mm->pax_flags & MF_PAX_SEGMEXEC))
51711+#endif
51712+
51713 static int proc_pid_auxv(struct task_struct *task, char *buffer)
51714 {
51715 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
51716 int res = PTR_ERR(mm);
51717 if (mm && !IS_ERR(mm)) {
51718 unsigned int nwords = 0;
51719+
51720+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51721+ /* allow if we're currently ptracing this task */
51722+ if (PAX_RAND_FLAGS(mm) &&
51723+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
51724+ mmput(mm);
51725+ return 0;
51726+ }
51727+#endif
51728+
51729 do {
51730 nwords += 2;
51731 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
51732@@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
51733 }
51734
51735
51736-#ifdef CONFIG_KALLSYMS
51737+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51738 /*
51739 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
51740 * Returns the resolved symbol. If that fails, simply return the address.
51741@@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
51742 mutex_unlock(&task->signal->cred_guard_mutex);
51743 }
51744
51745-#ifdef CONFIG_STACKTRACE
51746+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51747
51748 #define MAX_STACK_TRACE_DEPTH 64
51749
51750@@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
51751 return count;
51752 }
51753
51754-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
51755+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51756 static int proc_pid_syscall(struct task_struct *task, char *buffer)
51757 {
51758 long nr;
51759@@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
51760 /************************************************************************/
51761
51762 /* permission checks */
51763-static int proc_fd_access_allowed(struct inode *inode)
51764+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
51765 {
51766 struct task_struct *task;
51767 int allowed = 0;
51768@@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
51769 */
51770 task = get_proc_task(inode);
51771 if (task) {
51772- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
51773+ if (log)
51774+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
51775+ else
51776+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
51777 put_task_struct(task);
51778 }
51779 return allowed;
51780@@ -555,10 +585,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
51781 struct task_struct *task,
51782 int hide_pid_min)
51783 {
51784+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51785+ return false;
51786+
51787+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51788+ rcu_read_lock();
51789+ {
51790+ const struct cred *tmpcred = current_cred();
51791+ const struct cred *cred = __task_cred(task);
51792+
51793+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
51794+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51795+ || in_group_p(grsec_proc_gid)
51796+#endif
51797+ ) {
51798+ rcu_read_unlock();
51799+ return true;
51800+ }
51801+ }
51802+ rcu_read_unlock();
51803+
51804+ if (!pid->hide_pid)
51805+ return false;
51806+#endif
51807+
51808 if (pid->hide_pid < hide_pid_min)
51809 return true;
51810 if (in_group_p(pid->pid_gid))
51811 return true;
51812+
51813 return ptrace_may_access(task, PTRACE_MODE_READ);
51814 }
51815
51816@@ -576,7 +631,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
51817 put_task_struct(task);
51818
51819 if (!has_perms) {
51820+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51821+ {
51822+#else
51823 if (pid->hide_pid == 2) {
51824+#endif
51825 /*
51826 * Let's make getdents(), stat(), and open()
51827 * consistent with each other. If a process
51828@@ -674,6 +733,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
51829 if (!task)
51830 return -ESRCH;
51831
51832+ if (gr_acl_handle_procpidmem(task)) {
51833+ put_task_struct(task);
51834+ return -EPERM;
51835+ }
51836+
51837 mm = mm_access(task, mode);
51838 put_task_struct(task);
51839
51840@@ -689,6 +753,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
51841
51842 file->private_data = mm;
51843
51844+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51845+ file->f_version = current->exec_id;
51846+#endif
51847+
51848 return 0;
51849 }
51850
51851@@ -710,6 +778,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
51852 ssize_t copied;
51853 char *page;
51854
51855+#ifdef CONFIG_GRKERNSEC
51856+ if (write)
51857+ return -EPERM;
51858+#endif
51859+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51860+ if (file->f_version != current->exec_id) {
51861+ gr_log_badprocpid("mem");
51862+ return 0;
51863+ }
51864+#endif
51865+
51866 if (!mm)
51867 return 0;
51868
51869@@ -814,6 +893,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
51870 if (!mm)
51871 return 0;
51872
51873+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51874+ if (file->f_version != current->exec_id) {
51875+ gr_log_badprocpid("environ");
51876+ return 0;
51877+ }
51878+#endif
51879+
51880 page = (char *)__get_free_page(GFP_TEMPORARY);
51881 if (!page)
51882 return -ENOMEM;
51883@@ -1429,7 +1515,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
51884 int error = -EACCES;
51885
51886 /* Are we allowed to snoop on the tasks file descriptors? */
51887- if (!proc_fd_access_allowed(inode))
51888+ if (!proc_fd_access_allowed(inode, 0))
51889 goto out;
51890
51891 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
51892@@ -1473,8 +1559,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
51893 struct path path;
51894
51895 /* Are we allowed to snoop on the tasks file descriptors? */
51896- if (!proc_fd_access_allowed(inode))
51897- goto out;
51898+ /* logging this is needed for learning on chromium to work properly,
51899+ but we don't want to flood the logs from 'ps' which does a readlink
51900+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
51901+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
51902+ */
51903+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
51904+ if (!proc_fd_access_allowed(inode,0))
51905+ goto out;
51906+ } else {
51907+ if (!proc_fd_access_allowed(inode,1))
51908+ goto out;
51909+ }
51910
51911 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
51912 if (error)
51913@@ -1524,7 +1620,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
51914 rcu_read_lock();
51915 cred = __task_cred(task);
51916 inode->i_uid = cred->euid;
51917+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51918+ inode->i_gid = grsec_proc_gid;
51919+#else
51920 inode->i_gid = cred->egid;
51921+#endif
51922 rcu_read_unlock();
51923 }
51924 security_task_to_inode(task, inode);
51925@@ -1560,10 +1660,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
51926 return -ENOENT;
51927 }
51928 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
51929+#ifdef CONFIG_GRKERNSEC_PROC_USER
51930+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
51931+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51932+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
51933+#endif
51934 task_dumpable(task)) {
51935 cred = __task_cred(task);
51936 stat->uid = cred->euid;
51937+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51938+ stat->gid = grsec_proc_gid;
51939+#else
51940 stat->gid = cred->egid;
51941+#endif
51942 }
51943 }
51944 rcu_read_unlock();
51945@@ -1601,11 +1710,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
51946
51947 if (task) {
51948 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
51949+#ifdef CONFIG_GRKERNSEC_PROC_USER
51950+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
51951+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51952+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
51953+#endif
51954 task_dumpable(task)) {
51955 rcu_read_lock();
51956 cred = __task_cred(task);
51957 inode->i_uid = cred->euid;
51958+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51959+ inode->i_gid = grsec_proc_gid;
51960+#else
51961 inode->i_gid = cred->egid;
51962+#endif
51963 rcu_read_unlock();
51964 } else {
51965 inode->i_uid = GLOBAL_ROOT_UID;
51966@@ -2058,6 +2176,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
51967 if (!task)
51968 goto out_no_task;
51969
51970+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51971+ goto out;
51972+
51973 /*
51974 * Yes, it does not scale. And it should not. Don't add
51975 * new entries into /proc/<tgid>/ without very good reasons.
51976@@ -2102,6 +2223,9 @@ static int proc_pident_readdir(struct file *filp,
51977 if (!task)
51978 goto out_no_task;
51979
51980+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51981+ goto out;
51982+
51983 ret = 0;
51984 i = filp->f_pos;
51985 switch (i) {
51986@@ -2515,7 +2639,7 @@ static const struct pid_entry tgid_base_stuff[] = {
51987 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
51988 #endif
51989 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
51990-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
51991+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51992 INF("syscall", S_IRUGO, proc_pid_syscall),
51993 #endif
51994 INF("cmdline", S_IRUGO, proc_pid_cmdline),
51995@@ -2540,10 +2664,10 @@ static const struct pid_entry tgid_base_stuff[] = {
51996 #ifdef CONFIG_SECURITY
51997 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
51998 #endif
51999-#ifdef CONFIG_KALLSYMS
52000+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52001 INF("wchan", S_IRUGO, proc_pid_wchan),
52002 #endif
52003-#ifdef CONFIG_STACKTRACE
52004+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52005 ONE("stack", S_IRUGO, proc_pid_stack),
52006 #endif
52007 #ifdef CONFIG_SCHEDSTATS
52008@@ -2577,6 +2701,9 @@ static const struct pid_entry tgid_base_stuff[] = {
52009 #ifdef CONFIG_HARDWALL
52010 INF("hardwall", S_IRUGO, proc_pid_hardwall),
52011 #endif
52012+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
52013+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
52014+#endif
52015 #ifdef CONFIG_USER_NS
52016 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
52017 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
52018@@ -2705,7 +2832,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
52019 if (!inode)
52020 goto out;
52021
52022+#ifdef CONFIG_GRKERNSEC_PROC_USER
52023+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
52024+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52025+ inode->i_gid = grsec_proc_gid;
52026+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
52027+#else
52028 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
52029+#endif
52030 inode->i_op = &proc_tgid_base_inode_operations;
52031 inode->i_fop = &proc_tgid_base_operations;
52032 inode->i_flags|=S_IMMUTABLE;
52033@@ -2743,7 +2877,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
52034 if (!task)
52035 goto out;
52036
52037+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
52038+ goto out_put_task;
52039+
52040 result = proc_pid_instantiate(dir, dentry, task, NULL);
52041+out_put_task:
52042 put_task_struct(task);
52043 out:
52044 return result;
52045@@ -2806,6 +2944,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
52046 static int fake_filldir(void *buf, const char *name, int namelen,
52047 loff_t offset, u64 ino, unsigned d_type)
52048 {
52049+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
52050+ __buf->error = -EINVAL;
52051 return 0;
52052 }
52053
52054@@ -2857,7 +2997,7 @@ static const struct pid_entry tid_base_stuff[] = {
52055 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
52056 #endif
52057 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
52058-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
52059+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
52060 INF("syscall", S_IRUGO, proc_pid_syscall),
52061 #endif
52062 INF("cmdline", S_IRUGO, proc_pid_cmdline),
52063@@ -2884,10 +3024,10 @@ static const struct pid_entry tid_base_stuff[] = {
52064 #ifdef CONFIG_SECURITY
52065 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
52066 #endif
52067-#ifdef CONFIG_KALLSYMS
52068+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52069 INF("wchan", S_IRUGO, proc_pid_wchan),
52070 #endif
52071-#ifdef CONFIG_STACKTRACE
52072+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52073 ONE("stack", S_IRUGO, proc_pid_stack),
52074 #endif
52075 #ifdef CONFIG_SCHEDSTATS
52076diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
52077index 82676e3..5f8518a 100644
52078--- a/fs/proc/cmdline.c
52079+++ b/fs/proc/cmdline.c
52080@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
52081
52082 static int __init proc_cmdline_init(void)
52083 {
52084+#ifdef CONFIG_GRKERNSEC_PROC_ADD
52085+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
52086+#else
52087 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
52088+#endif
52089 return 0;
52090 }
52091 module_init(proc_cmdline_init);
52092diff --git a/fs/proc/devices.c b/fs/proc/devices.c
52093index b143471..bb105e5 100644
52094--- a/fs/proc/devices.c
52095+++ b/fs/proc/devices.c
52096@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
52097
52098 static int __init proc_devices_init(void)
52099 {
52100+#ifdef CONFIG_GRKERNSEC_PROC_ADD
52101+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
52102+#else
52103 proc_create("devices", 0, NULL, &proc_devinfo_operations);
52104+#endif
52105 return 0;
52106 }
52107 module_init(proc_devices_init);
52108diff --git a/fs/proc/fd.c b/fs/proc/fd.c
52109index d7a4a28..0201742 100644
52110--- a/fs/proc/fd.c
52111+++ b/fs/proc/fd.c
52112@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
52113 if (!task)
52114 return -ENOENT;
52115
52116- files = get_files_struct(task);
52117+ if (!gr_acl_handle_procpidmem(task))
52118+ files = get_files_struct(task);
52119 put_task_struct(task);
52120
52121 if (files) {
52122@@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
52123 */
52124 int proc_fd_permission(struct inode *inode, int mask)
52125 {
52126+ struct task_struct *task;
52127 int rv = generic_permission(inode, mask);
52128- if (rv == 0)
52129- return 0;
52130+
52131 if (task_pid(current) == proc_pid(inode))
52132 rv = 0;
52133+
52134+ task = get_proc_task(inode);
52135+ if (task == NULL)
52136+ return rv;
52137+
52138+ if (gr_acl_handle_procpidmem(task))
52139+ rv = -EACCES;
52140+
52141+ put_task_struct(task);
52142+
52143 return rv;
52144 }
52145
52146diff --git a/fs/proc/inode.c b/fs/proc/inode.c
52147index 439ae688..c21ac36 100644
52148--- a/fs/proc/inode.c
52149+++ b/fs/proc/inode.c
52150@@ -21,11 +21,17 @@
52151 #include <linux/seq_file.h>
52152 #include <linux/slab.h>
52153 #include <linux/mount.h>
52154+#include <linux/grsecurity.h>
52155
52156 #include <asm/uaccess.h>
52157
52158 #include "internal.h"
52159
52160+#ifdef CONFIG_PROC_SYSCTL
52161+extern const struct inode_operations proc_sys_inode_operations;
52162+extern const struct inode_operations proc_sys_dir_operations;
52163+#endif
52164+
52165 static void proc_evict_inode(struct inode *inode)
52166 {
52167 struct proc_dir_entry *de;
52168@@ -53,6 +59,13 @@ static void proc_evict_inode(struct inode *inode)
52169 ns = PROC_I(inode)->ns;
52170 if (ns_ops && ns)
52171 ns_ops->put(ns);
52172+
52173+#ifdef CONFIG_PROC_SYSCTL
52174+ if (inode->i_op == &proc_sys_inode_operations ||
52175+ inode->i_op == &proc_sys_dir_operations)
52176+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
52177+#endif
52178+
52179 }
52180
52181 static struct kmem_cache * proc_inode_cachep;
52182@@ -457,7 +470,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
52183 if (de->mode) {
52184 inode->i_mode = de->mode;
52185 inode->i_uid = de->uid;
52186+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52187+ inode->i_gid = grsec_proc_gid;
52188+#else
52189 inode->i_gid = de->gid;
52190+#endif
52191 }
52192 if (de->size)
52193 inode->i_size = de->size;
52194diff --git a/fs/proc/internal.h b/fs/proc/internal.h
52195index 252544c..04395b9 100644
52196--- a/fs/proc/internal.h
52197+++ b/fs/proc/internal.h
52198@@ -55,6 +55,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
52199 struct pid *pid, struct task_struct *task);
52200 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
52201 struct pid *pid, struct task_struct *task);
52202+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
52203+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
52204+#endif
52205 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
52206
52207 extern const struct file_operations proc_tid_children_operations;
52208diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
52209index e96d4f1..8b116ed 100644
52210--- a/fs/proc/kcore.c
52211+++ b/fs/proc/kcore.c
52212@@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
52213 * the addresses in the elf_phdr on our list.
52214 */
52215 start = kc_offset_to_vaddr(*fpos - elf_buflen);
52216- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
52217+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
52218+ if (tsz > buflen)
52219 tsz = buflen;
52220-
52221+
52222 while (buflen) {
52223 struct kcore_list *m;
52224
52225@@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
52226 kfree(elf_buf);
52227 } else {
52228 if (kern_addr_valid(start)) {
52229- unsigned long n;
52230+ char *elf_buf;
52231+ mm_segment_t oldfs;
52232
52233- n = copy_to_user(buffer, (char *)start, tsz);
52234- /*
52235- * We cannot distinguish between fault on source
52236- * and fault on destination. When this happens
52237- * we clear too and hope it will trigger the
52238- * EFAULT again.
52239- */
52240- if (n) {
52241- if (clear_user(buffer + tsz - n,
52242- n))
52243+ elf_buf = kmalloc(tsz, GFP_KERNEL);
52244+ if (!elf_buf)
52245+ return -ENOMEM;
52246+ oldfs = get_fs();
52247+ set_fs(KERNEL_DS);
52248+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
52249+ set_fs(oldfs);
52250+ if (copy_to_user(buffer, elf_buf, tsz)) {
52251+ kfree(elf_buf);
52252 return -EFAULT;
52253+ }
52254 }
52255+ set_fs(oldfs);
52256+ kfree(elf_buf);
52257 } else {
52258 if (clear_user(buffer, tsz))
52259 return -EFAULT;
52260@@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
52261
52262 static int open_kcore(struct inode *inode, struct file *filp)
52263 {
52264+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
52265+ return -EPERM;
52266+#endif
52267 if (!capable(CAP_SYS_RAWIO))
52268 return -EPERM;
52269 if (kcore_need_update)
52270diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
52271index 80e4645..53e5fcf 100644
52272--- a/fs/proc/meminfo.c
52273+++ b/fs/proc/meminfo.c
52274@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
52275 vmi.used >> 10,
52276 vmi.largest_chunk >> 10
52277 #ifdef CONFIG_MEMORY_FAILURE
52278- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
52279+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
52280 #endif
52281 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
52282 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
52283diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
52284index b1822dd..df622cb 100644
52285--- a/fs/proc/nommu.c
52286+++ b/fs/proc/nommu.c
52287@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
52288 if (len < 1)
52289 len = 1;
52290 seq_printf(m, "%*c", len, ' ');
52291- seq_path(m, &file->f_path, "");
52292+ seq_path(m, &file->f_path, "\n\\");
52293 }
52294
52295 seq_putc(m, '\n');
52296diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
52297index fe72cd0..cb9b67d 100644
52298--- a/fs/proc/proc_net.c
52299+++ b/fs/proc/proc_net.c
52300@@ -23,6 +23,7 @@
52301 #include <linux/nsproxy.h>
52302 #include <net/net_namespace.h>
52303 #include <linux/seq_file.h>
52304+#include <linux/grsecurity.h>
52305
52306 #include "internal.h"
52307
52308@@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
52309 struct task_struct *task;
52310 struct nsproxy *ns;
52311 struct net *net = NULL;
52312+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52313+ const struct cred *cred = current_cred();
52314+#endif
52315+
52316+#ifdef CONFIG_GRKERNSEC_PROC_USER
52317+ if (cred->fsuid)
52318+ return net;
52319+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52320+ if (cred->fsuid && !in_group_p(grsec_proc_gid))
52321+ return net;
52322+#endif
52323
52324 rcu_read_lock();
52325 task = pid_task(proc_pid(dir), PIDTYPE_PID);
52326diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
52327index 1827d88..9a60b01 100644
52328--- a/fs/proc/proc_sysctl.c
52329+++ b/fs/proc/proc_sysctl.c
52330@@ -12,11 +12,15 @@
52331 #include <linux/module.h>
52332 #include "internal.h"
52333
52334+extern int gr_handle_chroot_sysctl(const int op);
52335+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
52336+ const int op);
52337+
52338 static const struct dentry_operations proc_sys_dentry_operations;
52339 static const struct file_operations proc_sys_file_operations;
52340-static const struct inode_operations proc_sys_inode_operations;
52341+const struct inode_operations proc_sys_inode_operations;
52342 static const struct file_operations proc_sys_dir_file_operations;
52343-static const struct inode_operations proc_sys_dir_operations;
52344+const struct inode_operations proc_sys_dir_operations;
52345
52346 void proc_sys_poll_notify(struct ctl_table_poll *poll)
52347 {
52348@@ -466,6 +470,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
52349
52350 err = NULL;
52351 d_set_d_op(dentry, &proc_sys_dentry_operations);
52352+
52353+ gr_handle_proc_create(dentry, inode);
52354+
52355 d_add(dentry, inode);
52356
52357 out:
52358@@ -481,6 +488,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
52359 struct inode *inode = filp->f_path.dentry->d_inode;
52360 struct ctl_table_header *head = grab_header(inode);
52361 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
52362+ int op = write ? MAY_WRITE : MAY_READ;
52363 ssize_t error;
52364 size_t res;
52365
52366@@ -492,7 +500,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
52367 * and won't be until we finish.
52368 */
52369 error = -EPERM;
52370- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
52371+ if (sysctl_perm(head, table, op))
52372 goto out;
52373
52374 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
52375@@ -500,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
52376 if (!table->proc_handler)
52377 goto out;
52378
52379+#ifdef CONFIG_GRKERNSEC
52380+ error = -EPERM;
52381+ if (gr_handle_chroot_sysctl(op))
52382+ goto out;
52383+ dget(filp->f_path.dentry);
52384+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
52385+ dput(filp->f_path.dentry);
52386+ goto out;
52387+ }
52388+ dput(filp->f_path.dentry);
52389+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
52390+ goto out;
52391+ if (write && !capable(CAP_SYS_ADMIN))
52392+ goto out;
52393+#endif
52394+
52395 /* careful: calling conventions are nasty here */
52396 res = count;
52397 error = table->proc_handler(table, write, buf, &res, ppos);
52398@@ -597,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
52399 return -ENOMEM;
52400 } else {
52401 d_set_d_op(child, &proc_sys_dentry_operations);
52402+
52403+ gr_handle_proc_create(child, inode);
52404+
52405 d_add(child, inode);
52406 }
52407 } else {
52408@@ -640,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
52409 if ((*pos)++ < file->f_pos)
52410 return 0;
52411
52412+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
52413+ return 0;
52414+
52415 if (unlikely(S_ISLNK(table->mode)))
52416 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
52417 else
52418@@ -750,6 +780,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
52419 if (IS_ERR(head))
52420 return PTR_ERR(head);
52421
52422+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
52423+ return -ENOENT;
52424+
52425 generic_fillattr(inode, stat);
52426 if (table)
52427 stat->mode = (stat->mode & S_IFMT) | table->mode;
52428@@ -772,13 +805,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
52429 .llseek = generic_file_llseek,
52430 };
52431
52432-static const struct inode_operations proc_sys_inode_operations = {
52433+const struct inode_operations proc_sys_inode_operations = {
52434 .permission = proc_sys_permission,
52435 .setattr = proc_sys_setattr,
52436 .getattr = proc_sys_getattr,
52437 };
52438
52439-static const struct inode_operations proc_sys_dir_operations = {
52440+const struct inode_operations proc_sys_dir_operations = {
52441 .lookup = proc_sys_lookup,
52442 .permission = proc_sys_permission,
52443 .setattr = proc_sys_setattr,
52444diff --git a/fs/proc/root.c b/fs/proc/root.c
52445index c6e9fac..a740964 100644
52446--- a/fs/proc/root.c
52447+++ b/fs/proc/root.c
52448@@ -176,7 +176,15 @@ void __init proc_root_init(void)
52449 #ifdef CONFIG_PROC_DEVICETREE
52450 proc_device_tree_init();
52451 #endif
52452+#ifdef CONFIG_GRKERNSEC_PROC_ADD
52453+#ifdef CONFIG_GRKERNSEC_PROC_USER
52454+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
52455+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52456+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
52457+#endif
52458+#else
52459 proc_mkdir("bus", NULL);
52460+#endif
52461 proc_sys_init();
52462 }
52463
52464diff --git a/fs/proc/self.c b/fs/proc/self.c
52465index aa5cc3b..c91a5d0 100644
52466--- a/fs/proc/self.c
52467+++ b/fs/proc/self.c
52468@@ -37,7 +37,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
52469 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
52470 void *cookie)
52471 {
52472- char *s = nd_get_link(nd);
52473+ const char *s = nd_get_link(nd);
52474 if (!IS_ERR(s))
52475 kfree(s);
52476 }
52477diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
52478index ca5ce7f..02c1cf0 100644
52479--- a/fs/proc/task_mmu.c
52480+++ b/fs/proc/task_mmu.c
52481@@ -11,12 +11,19 @@
52482 #include <linux/rmap.h>
52483 #include <linux/swap.h>
52484 #include <linux/swapops.h>
52485+#include <linux/grsecurity.h>
52486
52487 #include <asm/elf.h>
52488 #include <asm/uaccess.h>
52489 #include <asm/tlbflush.h>
52490 #include "internal.h"
52491
52492+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52493+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
52494+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
52495+ _mm->pax_flags & MF_PAX_SEGMEXEC))
52496+#endif
52497+
52498 void task_mem(struct seq_file *m, struct mm_struct *mm)
52499 {
52500 unsigned long data, text, lib, swap;
52501@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
52502 "VmExe:\t%8lu kB\n"
52503 "VmLib:\t%8lu kB\n"
52504 "VmPTE:\t%8lu kB\n"
52505- "VmSwap:\t%8lu kB\n",
52506- hiwater_vm << (PAGE_SHIFT-10),
52507+ "VmSwap:\t%8lu kB\n"
52508+
52509+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
52510+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
52511+#endif
52512+
52513+ ,hiwater_vm << (PAGE_SHIFT-10),
52514 total_vm << (PAGE_SHIFT-10),
52515 mm->locked_vm << (PAGE_SHIFT-10),
52516 mm->pinned_vm << (PAGE_SHIFT-10),
52517@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
52518 data << (PAGE_SHIFT-10),
52519 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
52520 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
52521- swap << (PAGE_SHIFT-10));
52522+ swap << (PAGE_SHIFT-10)
52523+
52524+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
52525+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52526+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
52527+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
52528+#else
52529+ , mm->context.user_cs_base
52530+ , mm->context.user_cs_limit
52531+#endif
52532+#endif
52533+
52534+ );
52535 }
52536
52537 unsigned long task_vsize(struct mm_struct *mm)
52538@@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
52539 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
52540 }
52541
52542- /* We don't show the stack guard page in /proc/maps */
52543+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52544+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
52545+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
52546+#else
52547 start = vma->vm_start;
52548- if (stack_guard_page_start(vma, start))
52549- start += PAGE_SIZE;
52550 end = vma->vm_end;
52551- if (stack_guard_page_end(vma, end))
52552- end -= PAGE_SIZE;
52553+#endif
52554
52555 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
52556 start,
52557@@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
52558 flags & VM_WRITE ? 'w' : '-',
52559 flags & VM_EXEC ? 'x' : '-',
52560 flags & VM_MAYSHARE ? 's' : 'p',
52561+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52562+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
52563+#else
52564 pgoff,
52565+#endif
52566 MAJOR(dev), MINOR(dev), ino, &len);
52567
52568 /*
52569@@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
52570 */
52571 if (file) {
52572 pad_len_spaces(m, len);
52573- seq_path(m, &file->f_path, "\n");
52574+ seq_path(m, &file->f_path, "\n\\");
52575 goto done;
52576 }
52577
52578@@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
52579 * Thread stack in /proc/PID/task/TID/maps or
52580 * the main process stack.
52581 */
52582- if (!is_pid || (vma->vm_start <= mm->start_stack &&
52583- vma->vm_end >= mm->start_stack)) {
52584+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
52585+ (vma->vm_start <= mm->start_stack &&
52586+ vma->vm_end >= mm->start_stack)) {
52587 name = "[stack]";
52588 } else {
52589 /* Thread stack in /proc/PID/maps */
52590@@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
52591 struct proc_maps_private *priv = m->private;
52592 struct task_struct *task = priv->task;
52593
52594+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52595+ if (current->exec_id != m->exec_id) {
52596+ gr_log_badprocpid("maps");
52597+ return 0;
52598+ }
52599+#endif
52600+
52601 show_map_vma(m, vma, is_pid);
52602
52603 if (m->count < m->size) /* vma is copied successfully */
52604@@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
52605 .private = &mss,
52606 };
52607
52608+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52609+ if (current->exec_id != m->exec_id) {
52610+ gr_log_badprocpid("smaps");
52611+ return 0;
52612+ }
52613+#endif
52614 memset(&mss, 0, sizeof mss);
52615- mss.vma = vma;
52616- /* mmap_sem is held in m_start */
52617- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
52618- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
52619-
52620+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52621+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
52622+#endif
52623+ mss.vma = vma;
52624+ /* mmap_sem is held in m_start */
52625+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
52626+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
52627+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52628+ }
52629+#endif
52630 show_map_vma(m, vma, is_pid);
52631
52632 seq_printf(m,
52633@@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
52634 "KernelPageSize: %8lu kB\n"
52635 "MMUPageSize: %8lu kB\n"
52636 "Locked: %8lu kB\n",
52637+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52638+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
52639+#else
52640 (vma->vm_end - vma->vm_start) >> 10,
52641+#endif
52642 mss.resident >> 10,
52643 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
52644 mss.shared_clean >> 10,
52645@@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
52646 int n;
52647 char buffer[50];
52648
52649+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52650+ if (current->exec_id != m->exec_id) {
52651+ gr_log_badprocpid("numa_maps");
52652+ return 0;
52653+ }
52654+#endif
52655+
52656 if (!mm)
52657 return 0;
52658
52659@@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
52660 mpol_to_str(buffer, sizeof(buffer), pol);
52661 mpol_cond_put(pol);
52662
52663+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52664+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
52665+#else
52666 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
52667+#endif
52668
52669 if (file) {
52670 seq_printf(m, " file=");
52671- seq_path(m, &file->f_path, "\n\t= ");
52672+ seq_path(m, &file->f_path, "\n\t\\= ");
52673 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
52674 seq_printf(m, " heap");
52675 } else {
52676diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
52677index 1ccfa53..0848f95 100644
52678--- a/fs/proc/task_nommu.c
52679+++ b/fs/proc/task_nommu.c
52680@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
52681 else
52682 bytes += kobjsize(mm);
52683
52684- if (current->fs && current->fs->users > 1)
52685+ if (current->fs && atomic_read(&current->fs->users) > 1)
52686 sbytes += kobjsize(current->fs);
52687 else
52688 bytes += kobjsize(current->fs);
52689@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
52690
52691 if (file) {
52692 pad_len_spaces(m, len);
52693- seq_path(m, &file->f_path, "");
52694+ seq_path(m, &file->f_path, "\n\\");
52695 } else if (mm) {
52696 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
52697
52698diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
52699index 16e8abb..2dcf914 100644
52700--- a/fs/quota/netlink.c
52701+++ b/fs/quota/netlink.c
52702@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
52703 void quota_send_warning(struct kqid qid, dev_t dev,
52704 const char warntype)
52705 {
52706- static atomic_t seq;
52707+ static atomic_unchecked_t seq;
52708 struct sk_buff *skb;
52709 void *msg_head;
52710 int ret;
52711@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
52712 "VFS: Not enough memory to send quota warning.\n");
52713 return;
52714 }
52715- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
52716+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
52717 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
52718 if (!msg_head) {
52719 printk(KERN_ERR
52720diff --git a/fs/readdir.c b/fs/readdir.c
52721index 5e69ef5..e5d9099 100644
52722--- a/fs/readdir.c
52723+++ b/fs/readdir.c
52724@@ -17,6 +17,7 @@
52725 #include <linux/security.h>
52726 #include <linux/syscalls.h>
52727 #include <linux/unistd.h>
52728+#include <linux/namei.h>
52729
52730 #include <asm/uaccess.h>
52731
52732@@ -67,6 +68,7 @@ struct old_linux_dirent {
52733
52734 struct readdir_callback {
52735 struct old_linux_dirent __user * dirent;
52736+ struct file * file;
52737 int result;
52738 };
52739
52740@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
52741 buf->result = -EOVERFLOW;
52742 return -EOVERFLOW;
52743 }
52744+
52745+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
52746+ return 0;
52747+
52748 buf->result++;
52749 dirent = buf->dirent;
52750 if (!access_ok(VERIFY_WRITE, dirent,
52751@@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
52752
52753 buf.result = 0;
52754 buf.dirent = dirent;
52755+ buf.file = f.file;
52756
52757 error = vfs_readdir(f.file, fillonedir, &buf);
52758 if (buf.result)
52759@@ -139,6 +146,7 @@ struct linux_dirent {
52760 struct getdents_callback {
52761 struct linux_dirent __user * current_dir;
52762 struct linux_dirent __user * previous;
52763+ struct file * file;
52764 int count;
52765 int error;
52766 };
52767@@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
52768 buf->error = -EOVERFLOW;
52769 return -EOVERFLOW;
52770 }
52771+
52772+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
52773+ return 0;
52774+
52775 dirent = buf->previous;
52776 if (dirent) {
52777 if (__put_user(offset, &dirent->d_off))
52778@@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
52779 buf.previous = NULL;
52780 buf.count = count;
52781 buf.error = 0;
52782+ buf.file = f.file;
52783
52784 error = vfs_readdir(f.file, filldir, &buf);
52785 if (error >= 0)
52786@@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
52787 struct getdents_callback64 {
52788 struct linux_dirent64 __user * current_dir;
52789 struct linux_dirent64 __user * previous;
52790+ struct file *file;
52791 int count;
52792 int error;
52793 };
52794@@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
52795 buf->error = -EINVAL; /* only used if we fail.. */
52796 if (reclen > buf->count)
52797 return -EINVAL;
52798+
52799+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
52800+ return 0;
52801+
52802 dirent = buf->previous;
52803 if (dirent) {
52804 if (__put_user(offset, &dirent->d_off))
52805@@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
52806
52807 buf.current_dir = dirent;
52808 buf.previous = NULL;
52809+ buf.file = f.file;
52810 buf.count = count;
52811 buf.error = 0;
52812
52813@@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
52814 error = buf.error;
52815 lastdirent = buf.previous;
52816 if (lastdirent) {
52817- typeof(lastdirent->d_off) d_off = f.file->f_pos;
52818+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
52819 if (__put_user(d_off, &lastdirent->d_off))
52820 error = -EFAULT;
52821 else
52822diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
52823index 2b7882b..1c5ef48 100644
52824--- a/fs/reiserfs/do_balan.c
52825+++ b/fs/reiserfs/do_balan.c
52826@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
52827 return;
52828 }
52829
52830- atomic_inc(&(fs_generation(tb->tb_sb)));
52831+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
52832 do_balance_starts(tb);
52833
52834 /* balance leaf returns 0 except if combining L R and S into
52835diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
52836index e60e870..f40ac16 100644
52837--- a/fs/reiserfs/procfs.c
52838+++ b/fs/reiserfs/procfs.c
52839@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
52840 "SMALL_TAILS " : "NO_TAILS ",
52841 replay_only(sb) ? "REPLAY_ONLY " : "",
52842 convert_reiserfs(sb) ? "CONV " : "",
52843- atomic_read(&r->s_generation_counter),
52844+ atomic_read_unchecked(&r->s_generation_counter),
52845 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
52846 SF(s_do_balance), SF(s_unneeded_left_neighbor),
52847 SF(s_good_search_by_key_reada), SF(s_bmaps),
52848diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
52849index 157e474..65a6114 100644
52850--- a/fs/reiserfs/reiserfs.h
52851+++ b/fs/reiserfs/reiserfs.h
52852@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
52853 /* Comment? -Hans */
52854 wait_queue_head_t s_wait;
52855 /* To be obsoleted soon by per buffer seals.. -Hans */
52856- atomic_t s_generation_counter; // increased by one every time the
52857+ atomic_unchecked_t s_generation_counter; // increased by one every time the
52858 // tree gets re-balanced
52859 unsigned long s_properties; /* File system properties. Currently holds
52860 on-disk FS format */
52861@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
52862 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
52863
52864 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
52865-#define get_generation(s) atomic_read (&fs_generation(s))
52866+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
52867 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
52868 #define __fs_changed(gen,s) (gen != get_generation (s))
52869 #define fs_changed(gen,s) \
52870diff --git a/fs/select.c b/fs/select.c
52871index 2ef72d9..f213b17 100644
52872--- a/fs/select.c
52873+++ b/fs/select.c
52874@@ -20,6 +20,7 @@
52875 #include <linux/export.h>
52876 #include <linux/slab.h>
52877 #include <linux/poll.h>
52878+#include <linux/security.h>
52879 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
52880 #include <linux/file.h>
52881 #include <linux/fdtable.h>
52882@@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
52883 struct poll_list *walk = head;
52884 unsigned long todo = nfds;
52885
52886+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
52887 if (nfds > rlimit(RLIMIT_NOFILE))
52888 return -EINVAL;
52889
52890diff --git a/fs/seq_file.c b/fs/seq_file.c
52891index f2bc3df..239d4f6 100644
52892--- a/fs/seq_file.c
52893+++ b/fs/seq_file.c
52894@@ -10,6 +10,7 @@
52895 #include <linux/seq_file.h>
52896 #include <linux/slab.h>
52897 #include <linux/cred.h>
52898+#include <linux/sched.h>
52899
52900 #include <asm/uaccess.h>
52901 #include <asm/page.h>
52902@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
52903 #ifdef CONFIG_USER_NS
52904 p->user_ns = file->f_cred->user_ns;
52905 #endif
52906+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52907+ p->exec_id = current->exec_id;
52908+#endif
52909
52910 /*
52911 * Wrappers around seq_open(e.g. swaps_open) need to be
52912@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
52913 return 0;
52914 }
52915 if (!m->buf) {
52916- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
52917+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
52918 if (!m->buf)
52919 return -ENOMEM;
52920 }
52921@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
52922 Eoverflow:
52923 m->op->stop(m, p);
52924 kfree(m->buf);
52925- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
52926+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
52927 return !m->buf ? -ENOMEM : -EAGAIN;
52928 }
52929
52930@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
52931
52932 /* grab buffer if we didn't have one */
52933 if (!m->buf) {
52934- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
52935+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
52936 if (!m->buf)
52937 goto Enomem;
52938 }
52939@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
52940 goto Fill;
52941 m->op->stop(m, p);
52942 kfree(m->buf);
52943- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
52944+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
52945 if (!m->buf)
52946 goto Enomem;
52947 m->count = 0;
52948@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
52949 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
52950 void *data)
52951 {
52952- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
52953+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
52954 int res = -ENOMEM;
52955
52956 if (op) {
52957diff --git a/fs/splice.c b/fs/splice.c
52958index 6909d89..5b2e8f9 100644
52959--- a/fs/splice.c
52960+++ b/fs/splice.c
52961@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
52962 pipe_lock(pipe);
52963
52964 for (;;) {
52965- if (!pipe->readers) {
52966+ if (!atomic_read(&pipe->readers)) {
52967 send_sig(SIGPIPE, current, 0);
52968 if (!ret)
52969 ret = -EPIPE;
52970@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
52971 do_wakeup = 0;
52972 }
52973
52974- pipe->waiting_writers++;
52975+ atomic_inc(&pipe->waiting_writers);
52976 pipe_wait(pipe);
52977- pipe->waiting_writers--;
52978+ atomic_dec(&pipe->waiting_writers);
52979 }
52980
52981 pipe_unlock(pipe);
52982@@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
52983 old_fs = get_fs();
52984 set_fs(get_ds());
52985 /* The cast to a user pointer is valid due to the set_fs() */
52986- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
52987+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
52988 set_fs(old_fs);
52989
52990 return res;
52991@@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
52992 old_fs = get_fs();
52993 set_fs(get_ds());
52994 /* The cast to a user pointer is valid due to the set_fs() */
52995- res = vfs_write(file, (const char __user *)buf, count, &pos);
52996+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
52997 set_fs(old_fs);
52998
52999 return res;
53000@@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
53001 goto err;
53002
53003 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
53004- vec[i].iov_base = (void __user *) page_address(page);
53005+ vec[i].iov_base = (void __force_user *) page_address(page);
53006 vec[i].iov_len = this_len;
53007 spd.pages[i] = page;
53008 spd.nr_pages++;
53009@@ -851,10 +851,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
53010 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
53011 {
53012 while (!pipe->nrbufs) {
53013- if (!pipe->writers)
53014+ if (!atomic_read(&pipe->writers))
53015 return 0;
53016
53017- if (!pipe->waiting_writers && sd->num_spliced)
53018+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
53019 return 0;
53020
53021 if (sd->flags & SPLICE_F_NONBLOCK)
53022@@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
53023 * out of the pipe right after the splice_to_pipe(). So set
53024 * PIPE_READERS appropriately.
53025 */
53026- pipe->readers = 1;
53027+ atomic_set(&pipe->readers, 1);
53028
53029 current->splice_pipe = pipe;
53030 }
53031@@ -1738,9 +1738,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
53032 ret = -ERESTARTSYS;
53033 break;
53034 }
53035- if (!pipe->writers)
53036+ if (!atomic_read(&pipe->writers))
53037 break;
53038- if (!pipe->waiting_writers) {
53039+ if (!atomic_read(&pipe->waiting_writers)) {
53040 if (flags & SPLICE_F_NONBLOCK) {
53041 ret = -EAGAIN;
53042 break;
53043@@ -1772,7 +1772,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
53044 pipe_lock(pipe);
53045
53046 while (pipe->nrbufs >= pipe->buffers) {
53047- if (!pipe->readers) {
53048+ if (!atomic_read(&pipe->readers)) {
53049 send_sig(SIGPIPE, current, 0);
53050 ret = -EPIPE;
53051 break;
53052@@ -1785,9 +1785,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
53053 ret = -ERESTARTSYS;
53054 break;
53055 }
53056- pipe->waiting_writers++;
53057+ atomic_inc(&pipe->waiting_writers);
53058 pipe_wait(pipe);
53059- pipe->waiting_writers--;
53060+ atomic_dec(&pipe->waiting_writers);
53061 }
53062
53063 pipe_unlock(pipe);
53064@@ -1823,14 +1823,14 @@ retry:
53065 pipe_double_lock(ipipe, opipe);
53066
53067 do {
53068- if (!opipe->readers) {
53069+ if (!atomic_read(&opipe->readers)) {
53070 send_sig(SIGPIPE, current, 0);
53071 if (!ret)
53072 ret = -EPIPE;
53073 break;
53074 }
53075
53076- if (!ipipe->nrbufs && !ipipe->writers)
53077+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
53078 break;
53079
53080 /*
53081@@ -1927,7 +1927,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
53082 pipe_double_lock(ipipe, opipe);
53083
53084 do {
53085- if (!opipe->readers) {
53086+ if (!atomic_read(&opipe->readers)) {
53087 send_sig(SIGPIPE, current, 0);
53088 if (!ret)
53089 ret = -EPIPE;
53090@@ -1972,7 +1972,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
53091 * return EAGAIN if we have the potential of some data in the
53092 * future, otherwise just return 0
53093 */
53094- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
53095+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
53096 ret = -EAGAIN;
53097
53098 pipe_unlock(ipipe);
53099diff --git a/fs/stat.c b/fs/stat.c
53100index 14f4545..9b7f55b 100644
53101--- a/fs/stat.c
53102+++ b/fs/stat.c
53103@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
53104 stat->gid = inode->i_gid;
53105 stat->rdev = inode->i_rdev;
53106 stat->size = i_size_read(inode);
53107- stat->atime = inode->i_atime;
53108- stat->mtime = inode->i_mtime;
53109+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
53110+ stat->atime = inode->i_ctime;
53111+ stat->mtime = inode->i_ctime;
53112+ } else {
53113+ stat->atime = inode->i_atime;
53114+ stat->mtime = inode->i_mtime;
53115+ }
53116 stat->ctime = inode->i_ctime;
53117 stat->blksize = (1 << inode->i_blkbits);
53118 stat->blocks = inode->i_blocks;
53119@@ -46,8 +51,14 @@ int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
53120 if (retval)
53121 return retval;
53122
53123- if (inode->i_op->getattr)
53124- return inode->i_op->getattr(mnt, dentry, stat);
53125+ if (inode->i_op->getattr) {
53126+ retval = inode->i_op->getattr(mnt, dentry, stat);
53127+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
53128+ stat->atime = stat->ctime;
53129+ stat->mtime = stat->ctime;
53130+ }
53131+ return retval;
53132+ }
53133
53134 generic_fillattr(inode, stat);
53135 return 0;
53136diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
53137index 2fbdff6..5530a61 100644
53138--- a/fs/sysfs/dir.c
53139+++ b/fs/sysfs/dir.c
53140@@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
53141 struct sysfs_dirent *sd;
53142 int rc;
53143
53144+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
53145+ const char *parent_name = parent_sd->s_name;
53146+
53147+ mode = S_IFDIR | S_IRWXU;
53148+
53149+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
53150+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
53151+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
53152+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
53153+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
53154+#endif
53155+
53156 /* allocate */
53157 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
53158 if (!sd)
53159diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
53160index 602f56d..6853db8 100644
53161--- a/fs/sysfs/file.c
53162+++ b/fs/sysfs/file.c
53163@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
53164
53165 struct sysfs_open_dirent {
53166 atomic_t refcnt;
53167- atomic_t event;
53168+ atomic_unchecked_t event;
53169 wait_queue_head_t poll;
53170 struct list_head buffers; /* goes through sysfs_buffer.list */
53171 };
53172@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
53173 if (!sysfs_get_active(attr_sd))
53174 return -ENODEV;
53175
53176- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
53177+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
53178 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
53179
53180 sysfs_put_active(attr_sd);
53181@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
53182 return -ENOMEM;
53183
53184 atomic_set(&new_od->refcnt, 0);
53185- atomic_set(&new_od->event, 1);
53186+ atomic_set_unchecked(&new_od->event, 1);
53187 init_waitqueue_head(&new_od->poll);
53188 INIT_LIST_HEAD(&new_od->buffers);
53189 goto retry;
53190@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
53191
53192 sysfs_put_active(attr_sd);
53193
53194- if (buffer->event != atomic_read(&od->event))
53195+ if (buffer->event != atomic_read_unchecked(&od->event))
53196 goto trigger;
53197
53198 return DEFAULT_POLLMASK;
53199@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
53200
53201 od = sd->s_attr.open;
53202 if (od) {
53203- atomic_inc(&od->event);
53204+ atomic_inc_unchecked(&od->event);
53205 wake_up_interruptible(&od->poll);
53206 }
53207
53208diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
53209index 3c9eb56..9dea5be 100644
53210--- a/fs/sysfs/symlink.c
53211+++ b/fs/sysfs/symlink.c
53212@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
53213
53214 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
53215 {
53216- char *page = nd_get_link(nd);
53217+ const char *page = nd_get_link(nd);
53218 if (!IS_ERR(page))
53219 free_page((unsigned long)page);
53220 }
53221diff --git a/fs/udf/misc.c b/fs/udf/misc.c
53222index c175b4d..8f36a16 100644
53223--- a/fs/udf/misc.c
53224+++ b/fs/udf/misc.c
53225@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
53226
53227 u8 udf_tag_checksum(const struct tag *t)
53228 {
53229- u8 *data = (u8 *)t;
53230+ const u8 *data = (const u8 *)t;
53231 u8 checksum = 0;
53232 int i;
53233 for (i = 0; i < sizeof(struct tag); ++i)
53234diff --git a/fs/utimes.c b/fs/utimes.c
53235index f4fb7ec..3fe03c0 100644
53236--- a/fs/utimes.c
53237+++ b/fs/utimes.c
53238@@ -1,6 +1,7 @@
53239 #include <linux/compiler.h>
53240 #include <linux/file.h>
53241 #include <linux/fs.h>
53242+#include <linux/security.h>
53243 #include <linux/linkage.h>
53244 #include <linux/mount.h>
53245 #include <linux/namei.h>
53246@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
53247 goto mnt_drop_write_and_out;
53248 }
53249 }
53250+
53251+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
53252+ error = -EACCES;
53253+ goto mnt_drop_write_and_out;
53254+ }
53255+
53256 mutex_lock(&inode->i_mutex);
53257 error = notify_change(path->dentry, &newattrs);
53258 mutex_unlock(&inode->i_mutex);
53259diff --git a/fs/xattr.c b/fs/xattr.c
53260index 3377dff..4feded6 100644
53261--- a/fs/xattr.c
53262+++ b/fs/xattr.c
53263@@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
53264 * Extended attribute SET operations
53265 */
53266 static long
53267-setxattr(struct dentry *d, const char __user *name, const void __user *value,
53268+setxattr(struct path *path, const char __user *name, const void __user *value,
53269 size_t size, int flags)
53270 {
53271 int error;
53272@@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
53273 posix_acl_fix_xattr_from_user(kvalue, size);
53274 }
53275
53276- error = vfs_setxattr(d, kname, kvalue, size, flags);
53277+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
53278+ error = -EACCES;
53279+ goto out;
53280+ }
53281+
53282+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
53283 out:
53284 if (vvalue)
53285 vfree(vvalue);
53286@@ -377,7 +382,7 @@ retry:
53287 return error;
53288 error = mnt_want_write(path.mnt);
53289 if (!error) {
53290- error = setxattr(path.dentry, name, value, size, flags);
53291+ error = setxattr(&path, name, value, size, flags);
53292 mnt_drop_write(path.mnt);
53293 }
53294 path_put(&path);
53295@@ -401,7 +406,7 @@ retry:
53296 return error;
53297 error = mnt_want_write(path.mnt);
53298 if (!error) {
53299- error = setxattr(path.dentry, name, value, size, flags);
53300+ error = setxattr(&path, name, value, size, flags);
53301 mnt_drop_write(path.mnt);
53302 }
53303 path_put(&path);
53304@@ -416,16 +421,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
53305 const void __user *,value, size_t, size, int, flags)
53306 {
53307 struct fd f = fdget(fd);
53308- struct dentry *dentry;
53309 int error = -EBADF;
53310
53311 if (!f.file)
53312 return error;
53313- dentry = f.file->f_path.dentry;
53314- audit_inode(NULL, dentry, 0);
53315+ audit_inode(NULL, f.file->f_path.dentry, 0);
53316 error = mnt_want_write_file(f.file);
53317 if (!error) {
53318- error = setxattr(dentry, name, value, size, flags);
53319+ error = setxattr(&f.file->f_path, name, value, size, flags);
53320 mnt_drop_write_file(f.file);
53321 }
53322 fdput(f);
53323diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
53324index 9fbea87..6b19972 100644
53325--- a/fs/xattr_acl.c
53326+++ b/fs/xattr_acl.c
53327@@ -76,8 +76,8 @@ struct posix_acl *
53328 posix_acl_from_xattr(struct user_namespace *user_ns,
53329 const void *value, size_t size)
53330 {
53331- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
53332- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
53333+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
53334+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
53335 int count;
53336 struct posix_acl *acl;
53337 struct posix_acl_entry *acl_e;
53338diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
53339index cdb2d33..704ce7f 100644
53340--- a/fs/xfs/xfs_bmap.c
53341+++ b/fs/xfs/xfs_bmap.c
53342@@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
53343 int nmap,
53344 int ret_nmap);
53345 #else
53346-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
53347+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
53348 #endif /* DEBUG */
53349
53350 STATIC int
53351diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
53352index 1b9fc3e..e1bdde0 100644
53353--- a/fs/xfs/xfs_dir2_sf.c
53354+++ b/fs/xfs/xfs_dir2_sf.c
53355@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
53356 }
53357
53358 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
53359- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
53360+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
53361+ char name[sfep->namelen];
53362+ memcpy(name, sfep->name, sfep->namelen);
53363+ if (filldir(dirent, name, sfep->namelen,
53364+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
53365+ *offset = off & 0x7fffffff;
53366+ return 0;
53367+ }
53368+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
53369 off & 0x7fffffff, ino, DT_UNKNOWN)) {
53370 *offset = off & 0x7fffffff;
53371 return 0;
53372diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
53373index c1c3ef8..0952438 100644
53374--- a/fs/xfs/xfs_ioctl.c
53375+++ b/fs/xfs/xfs_ioctl.c
53376@@ -127,7 +127,7 @@ xfs_find_handle(
53377 }
53378
53379 error = -EFAULT;
53380- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
53381+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
53382 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
53383 goto out_put;
53384
53385diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
53386index d82efaa..0904a8e 100644
53387--- a/fs/xfs/xfs_iops.c
53388+++ b/fs/xfs/xfs_iops.c
53389@@ -395,7 +395,7 @@ xfs_vn_put_link(
53390 struct nameidata *nd,
53391 void *p)
53392 {
53393- char *s = nd_get_link(nd);
53394+ const char *s = nd_get_link(nd);
53395
53396 if (!IS_ERR(s))
53397 kfree(s);
53398diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
53399new file mode 100644
53400index 0000000..92247e4
53401--- /dev/null
53402+++ b/grsecurity/Kconfig
53403@@ -0,0 +1,1021 @@
53404+#
53405+# grecurity configuration
53406+#
53407+menu "Memory Protections"
53408+depends on GRKERNSEC
53409+
53410+config GRKERNSEC_KMEM
53411+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
53412+ default y if GRKERNSEC_CONFIG_AUTO
53413+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
53414+ help
53415+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
53416+ be written to or read from to modify or leak the contents of the running
53417+ kernel. /dev/port will also not be allowed to be opened and support
53418+ for /dev/cpu/*/msr will be removed. If you have module
53419+ support disabled, enabling this will close up five ways that are
53420+ currently used to insert malicious code into the running kernel.
53421+
53422+ Even with all these features enabled, we still highly recommend that
53423+ you use the RBAC system, as it is still possible for an attacker to
53424+ modify the running kernel through privileged I/O granted by ioperm/iopl.
53425+
53426+ If you are not using XFree86, you may be able to stop this additional
53427+ case by enabling the 'Disable privileged I/O' option. Though nothing
53428+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
53429+ but only to video memory, which is the only writing we allow in this
53430+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
53431+ not be allowed to mprotect it with PROT_WRITE later.
53432+ Enabling this feature will prevent the "cpupower" and "powertop" tools
53433+ from working.
53434+
53435+ It is highly recommended that you say Y here if you meet all the
53436+ conditions above.
53437+
53438+config GRKERNSEC_VM86
53439+ bool "Restrict VM86 mode"
53440+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
53441+ depends on X86_32
53442+
53443+ help
53444+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
53445+ make use of a special execution mode on 32bit x86 processors called
53446+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
53447+ video cards and will still work with this option enabled. The purpose
53448+ of the option is to prevent exploitation of emulation errors in
53449+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
53450+ Nearly all users should be able to enable this option.
53451+
53452+config GRKERNSEC_IO
53453+ bool "Disable privileged I/O"
53454+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
53455+ depends on X86
53456+ select RTC_CLASS
53457+ select RTC_INTF_DEV
53458+ select RTC_DRV_CMOS
53459+
53460+ help
53461+ If you say Y here, all ioperm and iopl calls will return an error.
53462+ Ioperm and iopl can be used to modify the running kernel.
53463+ Unfortunately, some programs need this access to operate properly,
53464+ the most notable of which are XFree86 and hwclock. hwclock can be
53465+ remedied by having RTC support in the kernel, so real-time
53466+ clock support is enabled if this option is enabled, to ensure
53467+ that hwclock operates correctly. XFree86 still will not
53468+ operate correctly with this option enabled, so DO NOT CHOOSE Y
53469+ IF YOU USE XFree86. If you use XFree86 and you still want to
53470+ protect your kernel against modification, use the RBAC system.
53471+
53472+config GRKERNSEC_JIT_HARDEN
53473+ bool "Harden BPF JIT against spray attacks"
53474+ default y if GRKERNSEC_CONFIG_AUTO
53475+ depends on BPF_JIT
53476+ help
53477+ If you say Y here, the native code generated by the kernel's Berkeley
53478+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
53479+ attacks that attempt to fit attacker-beneficial instructions in
53480+ 32bit immediate fields of JIT-generated native instructions. The
53481+ attacker will generally aim to cause an unintended instruction sequence
53482+ of JIT-generated native code to execute by jumping into the middle of
53483+ a generated instruction. This feature effectively randomizes the 32bit
53484+ immediate constants present in the generated code to thwart such attacks.
53485+
53486+ If you're using KERNEXEC, it's recommended that you enable this option
53487+ to supplement the hardening of the kernel.
53488+
53489+config GRKERNSEC_RAND_THREADSTACK
53490+ bool "Insert random gaps between thread stacks"
53491+ default y if GRKERNSEC_CONFIG_AUTO
53492+ depends on PAX_RANDMMAP && !PPC
53493+ help
53494+ If you say Y here, a random-sized gap will be enforced between allocated
53495+ thread stacks. Glibc's NPTL and other threading libraries that
53496+ pass MAP_STACK to the kernel for thread stack allocation are supported.
53497+ The implementation currently provides 8 bits of entropy for the gap.
53498+
53499+ Many distributions do not compile threaded remote services with the
53500+ -fstack-check argument to GCC, causing the variable-sized stack-based
53501+ allocator, alloca(), to not probe the stack on allocation. This
53502+ permits an unbounded alloca() to skip over any guard page and potentially
53503+ modify another thread's stack reliably. An enforced random gap
53504+ reduces the reliability of such an attack and increases the chance
53505+ that such a read/write to another thread's stack instead lands in
53506+ an unmapped area, causing a crash and triggering grsecurity's
53507+ anti-bruteforcing logic.
53508+
53509+config GRKERNSEC_PROC_MEMMAP
53510+ bool "Harden ASLR against information leaks and entropy reduction"
53511+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
53512+ depends on PAX_NOEXEC || PAX_ASLR
53513+ help
53514+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
53515+ give no information about the addresses of its mappings if
53516+ PaX features that rely on random addresses are enabled on the task.
53517+ In addition to sanitizing this information and disabling other
53518+ dangerous sources of information, this option causes reads of sensitive
53519+ /proc/<pid> entries where the file descriptor was opened in a different
53520+ task than the one performing the read. Such attempts are logged.
53521+ This option also limits argv/env strings for suid/sgid binaries
53522+ to 512KB to prevent a complete exhaustion of the stack entropy provided
53523+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
53524+ binaries to prevent alternative mmap layouts from being abused.
53525+
53526+ If you use PaX it is essential that you say Y here as it closes up
53527+ several holes that make full ASLR useless locally.
53528+
53529+config GRKERNSEC_BRUTE
53530+ bool "Deter exploit bruteforcing"
53531+ default y if GRKERNSEC_CONFIG_AUTO
53532+ help
53533+ If you say Y here, attempts to bruteforce exploits against forking
53534+ daemons such as apache or sshd, as well as against suid/sgid binaries
53535+ will be deterred. When a child of a forking daemon is killed by PaX
53536+ or crashes due to an illegal instruction or other suspicious signal,
53537+ the parent process will be delayed 30 seconds upon every subsequent
53538+ fork until the administrator is able to assess the situation and
53539+ restart the daemon.
53540+ In the suid/sgid case, the attempt is logged, the user has all their
53541+ processes terminated, and they are prevented from executing any further
53542+ processes for 15 minutes.
53543+ It is recommended that you also enable signal logging in the auditing
53544+ section so that logs are generated when a process triggers a suspicious
53545+ signal.
53546+ If the sysctl option is enabled, a sysctl option with name
53547+ "deter_bruteforce" is created.
53548+
53549+
53550+config GRKERNSEC_MODHARDEN
53551+ bool "Harden module auto-loading"
53552+ default y if GRKERNSEC_CONFIG_AUTO
53553+ depends on MODULES
53554+ help
53555+ If you say Y here, module auto-loading in response to use of some
53556+ feature implemented by an unloaded module will be restricted to
53557+ root users. Enabling this option helps defend against attacks
53558+ by unprivileged users who abuse the auto-loading behavior to
53559+ cause a vulnerable module to load that is then exploited.
53560+
53561+ If this option prevents a legitimate use of auto-loading for a
53562+ non-root user, the administrator can execute modprobe manually
53563+ with the exact name of the module mentioned in the alert log.
53564+ Alternatively, the administrator can add the module to the list
53565+ of modules loaded at boot by modifying init scripts.
53566+
53567+ Modification of init scripts will most likely be needed on
53568+ Ubuntu servers with encrypted home directory support enabled,
53569+ as the first non-root user logging in will cause the ecb(aes),
53570+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
53571+
53572+config GRKERNSEC_HIDESYM
53573+ bool "Hide kernel symbols"
53574+ default y if GRKERNSEC_CONFIG_AUTO
53575+ select PAX_USERCOPY_SLABS
53576+ help
53577+ If you say Y here, getting information on loaded modules, and
53578+ displaying all kernel symbols through a syscall will be restricted
53579+ to users with CAP_SYS_MODULE. For software compatibility reasons,
53580+ /proc/kallsyms will be restricted to the root user. The RBAC
53581+ system can hide that entry even from root.
53582+
53583+ This option also prevents leaking of kernel addresses through
53584+ several /proc entries.
53585+
53586+ Note that this option is only effective provided the following
53587+ conditions are met:
53588+ 1) The kernel using grsecurity is not precompiled by some distribution
53589+ 2) You have also enabled GRKERNSEC_DMESG
53590+ 3) You are using the RBAC system and hiding other files such as your
53591+ kernel image and System.map. Alternatively, enabling this option
53592+ causes the permissions on /boot, /lib/modules, and the kernel
53593+ source directory to change at compile time to prevent
53594+ reading by non-root users.
53595+ If the above conditions are met, this option will aid in providing a
53596+ useful protection against local kernel exploitation of overflows
53597+ and arbitrary read/write vulnerabilities.
53598+
53599+config GRKERNSEC_KERN_LOCKOUT
53600+ bool "Active kernel exploit response"
53601+ default y if GRKERNSEC_CONFIG_AUTO
53602+ depends on X86 || ARM || PPC || SPARC
53603+ help
53604+ If you say Y here, when a PaX alert is triggered due to suspicious
53605+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
53606+ or an OOPS occurs due to bad memory accesses, instead of just
53607+ terminating the offending process (and potentially allowing
53608+ a subsequent exploit from the same user), we will take one of two
53609+ actions:
53610+ If the user was root, we will panic the system
53611+ If the user was non-root, we will log the attempt, terminate
53612+ all processes owned by the user, then prevent them from creating
53613+ any new processes until the system is restarted
53614+ This deters repeated kernel exploitation/bruteforcing attempts
53615+ and is useful for later forensics.
53616+
53617+endmenu
53618+menu "Role Based Access Control Options"
53619+depends on GRKERNSEC
53620+
53621+config GRKERNSEC_RBAC_DEBUG
53622+ bool
53623+
53624+config GRKERNSEC_NO_RBAC
53625+ bool "Disable RBAC system"
53626+ help
53627+ If you say Y here, the /dev/grsec device will be removed from the kernel,
53628+ preventing the RBAC system from being enabled. You should only say Y
53629+ here if you have no intention of using the RBAC system, so as to prevent
53630+ an attacker with root access from misusing the RBAC system to hide files
53631+ and processes when loadable module support and /dev/[k]mem have been
53632+ locked down.
53633+
53634+config GRKERNSEC_ACL_HIDEKERN
53635+ bool "Hide kernel processes"
53636+ help
53637+ If you say Y here, all kernel threads will be hidden to all
53638+ processes but those whose subject has the "view hidden processes"
53639+ flag.
53640+
53641+config GRKERNSEC_ACL_MAXTRIES
53642+ int "Maximum tries before password lockout"
53643+ default 3
53644+ help
53645+ This option enforces the maximum number of times a user can attempt
53646+ to authorize themselves with the grsecurity RBAC system before being
53647+ denied the ability to attempt authorization again for a specified time.
53648+ The lower the number, the harder it will be to brute-force a password.
53649+
53650+config GRKERNSEC_ACL_TIMEOUT
53651+ int "Time to wait after max password tries, in seconds"
53652+ default 30
53653+ help
53654+ This option specifies the time the user must wait after attempting to
53655+ authorize to the RBAC system with the maximum number of invalid
53656+ passwords. The higher the number, the harder it will be to brute-force
53657+ a password.
53658+
53659+endmenu
53660+menu "Filesystem Protections"
53661+depends on GRKERNSEC
53662+
53663+config GRKERNSEC_PROC
53664+ bool "Proc restrictions"
53665+ default y if GRKERNSEC_CONFIG_AUTO
53666+ help
53667+ If you say Y here, the permissions of the /proc filesystem
53668+ will be altered to enhance system security and privacy. You MUST
53669+ choose either a user only restriction or a user and group restriction.
53670+ Depending upon the option you choose, you can either restrict users to
53671+ see only the processes they themselves run, or choose a group that can
53672+ view all processes and files normally restricted to root if you choose
53673+ the "restrict to user only" option. NOTE: If you're running identd or
53674+ ntpd as a non-root user, you will have to run it as the group you
53675+ specify here.
53676+
53677+config GRKERNSEC_PROC_USER
53678+ bool "Restrict /proc to user only"
53679+ depends on GRKERNSEC_PROC
53680+ help
53681+ If you say Y here, non-root users will only be able to view their own
53682+ processes, and restricts them from viewing network-related information,
53683+ and viewing kernel symbol and module information.
53684+
53685+config GRKERNSEC_PROC_USERGROUP
53686+ bool "Allow special group"
53687+ default y if GRKERNSEC_CONFIG_AUTO
53688+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
53689+ help
53690+ If you say Y here, you will be able to select a group that will be
53691+ able to view all processes and network-related information. If you've
53692+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
53693+ remain hidden. This option is useful if you want to run identd as
53694+ a non-root user. The group you select may also be chosen at boot time
53695+ via "grsec_proc_gid=" on the kernel commandline.
53696+
53697+config GRKERNSEC_PROC_GID
53698+ int "GID for special group"
53699+ depends on GRKERNSEC_PROC_USERGROUP
53700+ default 1001
53701+
53702+config GRKERNSEC_PROC_ADD
53703+ bool "Additional restrictions"
53704+ default y if GRKERNSEC_CONFIG_AUTO
53705+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
53706+ help
53707+ If you say Y here, additional restrictions will be placed on
53708+ /proc that keep normal users from viewing device information and
53709+ slabinfo information that could be useful for exploits.
53710+
53711+config GRKERNSEC_LINK
53712+ bool "Linking restrictions"
53713+ default y if GRKERNSEC_CONFIG_AUTO
53714+ help
53715+ If you say Y here, /tmp race exploits will be prevented, since users
53716+ will no longer be able to follow symlinks owned by other users in
53717+ world-writable +t directories (e.g. /tmp), unless the owner of the
53718+ symlink is the owner of the directory. users will also not be
53719+ able to hardlink to files they do not own. If the sysctl option is
53720+ enabled, a sysctl option with name "linking_restrictions" is created.
53721+
53722+config GRKERNSEC_SYMLINKOWN
53723+ bool "Kernel-enforced SymlinksIfOwnerMatch"
53724+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
53725+ help
53726+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
53727+ that prevents it from being used as a security feature. As Apache
53728+ verifies the symlink by performing a stat() against the target of
53729+ the symlink before it is followed, an attacker can setup a symlink
53730+ to point to a same-owned file, then replace the symlink with one
53731+ that targets another user's file just after Apache "validates" the
53732+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
53733+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
53734+ will be in place for the group you specify. If the sysctl option
53735+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
53736+ created.
53737+
53738+config GRKERNSEC_SYMLINKOWN_GID
53739+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
53740+ depends on GRKERNSEC_SYMLINKOWN
53741+ default 1006
53742+ help
53743+ Setting this GID determines what group kernel-enforced
53744+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
53745+ is enabled, a sysctl option with name "symlinkown_gid" is created.
53746+
53747+config GRKERNSEC_FIFO
53748+ bool "FIFO restrictions"
53749+ default y if GRKERNSEC_CONFIG_AUTO
53750+ help
53751+ If you say Y here, users will not be able to write to FIFOs they don't
53752+ own in world-writable +t directories (e.g. /tmp), unless the owner of
53753+ the FIFO is the same owner of the directory it's held in. If the sysctl
53754+ option is enabled, a sysctl option with name "fifo_restrictions" is
53755+ created.
53756+
53757+config GRKERNSEC_SYSFS_RESTRICT
53758+ bool "Sysfs/debugfs restriction"
53759+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
53760+ depends on SYSFS
53761+ help
53762+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
53763+ any filesystem normally mounted under it (e.g. debugfs) will be
53764+ mostly accessible only by root. These filesystems generally provide access
53765+ to hardware and debug information that isn't appropriate for unprivileged
53766+ users of the system. Sysfs and debugfs have also become a large source
53767+ of new vulnerabilities, ranging from infoleaks to local compromise.
53768+ There has been very little oversight with an eye toward security involved
53769+ in adding new exporters of information to these filesystems, so their
53770+ use is discouraged.
53771+ For reasons of compatibility, a few directories have been whitelisted
53772+ for access by non-root users:
53773+ /sys/fs/selinux
53774+ /sys/fs/fuse
53775+ /sys/devices/system/cpu
53776+
53777+config GRKERNSEC_ROFS
53778+ bool "Runtime read-only mount protection"
53779+ help
53780+ If you say Y here, a sysctl option with name "romount_protect" will
53781+ be created. By setting this option to 1 at runtime, filesystems
53782+ will be protected in the following ways:
53783+ * No new writable mounts will be allowed
53784+ * Existing read-only mounts won't be able to be remounted read/write
53785+ * Write operations will be denied on all block devices
53786+ This option acts independently of grsec_lock: once it is set to 1,
53787+ it cannot be turned off. Therefore, please be mindful of the resulting
53788+ behavior if this option is enabled in an init script on a read-only
53789+ filesystem. This feature is mainly intended for secure embedded systems.
53790+
53791+config GRKERNSEC_DEVICE_SIDECHANNEL
53792+ bool "Eliminate stat/notify-based device sidechannels"
53793+ default y if GRKERNSEC_CONFIG_AUTO
53794+ help
53795+ If you say Y here, timing analyses on block or character
53796+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
53797+ will be thwarted for unprivileged users. If a process without
53798+ CAP_MKNOD stats such a device, the last access and last modify times
53799+ will match the device's create time. No access or modify events
53800+ will be triggered through inotify/dnotify/fanotify for such devices.
53801+ This feature will prevent attacks that may at a minimum
53802+ allow an attacker to determine the administrator's password length.
53803+
53804+config GRKERNSEC_CHROOT
53805+ bool "Chroot jail restrictions"
53806+ default y if GRKERNSEC_CONFIG_AUTO
53807+ help
53808+ If you say Y here, you will be able to choose several options that will
53809+ make breaking out of a chrooted jail much more difficult. If you
53810+ encounter no software incompatibilities with the following options, it
53811+ is recommended that you enable each one.
53812+
53813+config GRKERNSEC_CHROOT_MOUNT
53814+ bool "Deny mounts"
53815+ default y if GRKERNSEC_CONFIG_AUTO
53816+ depends on GRKERNSEC_CHROOT
53817+ help
53818+ If you say Y here, processes inside a chroot will not be able to
53819+ mount or remount filesystems. If the sysctl option is enabled, a
53820+ sysctl option with name "chroot_deny_mount" is created.
53821+
53822+config GRKERNSEC_CHROOT_DOUBLE
53823+ bool "Deny double-chroots"
53824+ default y if GRKERNSEC_CONFIG_AUTO
53825+ depends on GRKERNSEC_CHROOT
53826+ help
53827+ If you say Y here, processes inside a chroot will not be able to chroot
53828+ again outside the chroot. This is a widely used method of breaking
53829+ out of a chroot jail and should not be allowed. If the sysctl
53830+ option is enabled, a sysctl option with name
53831+ "chroot_deny_chroot" is created.
53832+
53833+config GRKERNSEC_CHROOT_PIVOT
53834+ bool "Deny pivot_root in chroot"
53835+ default y if GRKERNSEC_CONFIG_AUTO
53836+ depends on GRKERNSEC_CHROOT
53837+ help
53838+ If you say Y here, processes inside a chroot will not be able to use
53839+ a function called pivot_root() that was introduced in Linux 2.3.41. It
53840+ works similar to chroot in that it changes the root filesystem. This
53841+ function could be misused in a chrooted process to attempt to break out
53842+ of the chroot, and therefore should not be allowed. If the sysctl
53843+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
53844+ created.
53845+
53846+config GRKERNSEC_CHROOT_CHDIR
53847+ bool "Enforce chdir(\"/\") on all chroots"
53848+ default y if GRKERNSEC_CONFIG_AUTO
53849+ depends on GRKERNSEC_CHROOT
53850+ help
53851+ If you say Y here, the current working directory of all newly-chrooted
53852+ applications will be set to the the root directory of the chroot.
53853+ The man page on chroot(2) states:
53854+ Note that this call does not change the current working
53855+ directory, so that `.' can be outside the tree rooted at
53856+ `/'. In particular, the super-user can escape from a
53857+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
53858+
53859+ It is recommended that you say Y here, since it's not known to break
53860+ any software. If the sysctl option is enabled, a sysctl option with
53861+ name "chroot_enforce_chdir" is created.
53862+
53863+config GRKERNSEC_CHROOT_CHMOD
53864+ bool "Deny (f)chmod +s"
53865+ default y if GRKERNSEC_CONFIG_AUTO
53866+ depends on GRKERNSEC_CHROOT
53867+ help
53868+ If you say Y here, processes inside a chroot will not be able to chmod
53869+ or fchmod files to make them have suid or sgid bits. This protects
53870+ against another published method of breaking a chroot. If the sysctl
53871+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
53872+ created.
53873+
53874+config GRKERNSEC_CHROOT_FCHDIR
53875+ bool "Deny fchdir out of chroot"
53876+ default y if GRKERNSEC_CONFIG_AUTO
53877+ depends on GRKERNSEC_CHROOT
53878+ help
53879+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
53880+ to a file descriptor of the chrooting process that points to a directory
53881+ outside the filesystem will be stopped. If the sysctl option
53882+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
53883+
53884+config GRKERNSEC_CHROOT_MKNOD
53885+ bool "Deny mknod"
53886+ default y if GRKERNSEC_CONFIG_AUTO
53887+ depends on GRKERNSEC_CHROOT
53888+ help
53889+ If you say Y here, processes inside a chroot will not be allowed to
53890+ mknod. The problem with using mknod inside a chroot is that it
53891+ would allow an attacker to create a device entry that is the same
53892+ as one on the physical root of your system, which could range from
53893+ anything from the console device to a device for your harddrive (which
53894+ they could then use to wipe the drive or steal data). It is recommended
53895+ that you say Y here, unless you run into software incompatibilities.
53896+ If the sysctl option is enabled, a sysctl option with name
53897+ "chroot_deny_mknod" is created.
53898+
53899+config GRKERNSEC_CHROOT_SHMAT
53900+ bool "Deny shmat() out of chroot"
53901+ default y if GRKERNSEC_CONFIG_AUTO
53902+ depends on GRKERNSEC_CHROOT
53903+ help
53904+ If you say Y here, processes inside a chroot will not be able to attach
53905+ to shared memory segments that were created outside of the chroot jail.
53906+ It is recommended that you say Y here. If the sysctl option is enabled,
53907+ a sysctl option with name "chroot_deny_shmat" is created.
53908+
53909+config GRKERNSEC_CHROOT_UNIX
53910+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
53911+ default y if GRKERNSEC_CONFIG_AUTO
53912+ depends on GRKERNSEC_CHROOT
53913+ help
53914+ If you say Y here, processes inside a chroot will not be able to
53915+ connect to abstract (meaning not belonging to a filesystem) Unix
53916+ domain sockets that were bound outside of a chroot. It is recommended
53917+ that you say Y here. If the sysctl option is enabled, a sysctl option
53918+ with name "chroot_deny_unix" is created.
53919+
53920+config GRKERNSEC_CHROOT_FINDTASK
53921+ bool "Protect outside processes"
53922+ default y if GRKERNSEC_CONFIG_AUTO
53923+ depends on GRKERNSEC_CHROOT
53924+ help
53925+ If you say Y here, processes inside a chroot will not be able to
53926+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
53927+ getsid, or view any process outside of the chroot. If the sysctl
53928+ option is enabled, a sysctl option with name "chroot_findtask" is
53929+ created.
53930+
53931+config GRKERNSEC_CHROOT_NICE
53932+ bool "Restrict priority changes"
53933+ default y if GRKERNSEC_CONFIG_AUTO
53934+ depends on GRKERNSEC_CHROOT
53935+ help
53936+ If you say Y here, processes inside a chroot will not be able to raise
53937+ the priority of processes in the chroot, or alter the priority of
53938+ processes outside the chroot. This provides more security than simply
53939+ removing CAP_SYS_NICE from the process' capability set. If the
53940+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
53941+ is created.
53942+
53943+config GRKERNSEC_CHROOT_SYSCTL
53944+ bool "Deny sysctl writes"
53945+ default y if GRKERNSEC_CONFIG_AUTO
53946+ depends on GRKERNSEC_CHROOT
53947+ help
53948+ If you say Y here, an attacker in a chroot will not be able to
53949+ write to sysctl entries, either by sysctl(2) or through a /proc
53950+ interface. It is strongly recommended that you say Y here. If the
53951+ sysctl option is enabled, a sysctl option with name
53952+ "chroot_deny_sysctl" is created.
53953+
53954+config GRKERNSEC_CHROOT_CAPS
53955+ bool "Capability restrictions"
53956+ default y if GRKERNSEC_CONFIG_AUTO
53957+ depends on GRKERNSEC_CHROOT
53958+ help
53959+ If you say Y here, the capabilities on all processes within a
53960+ chroot jail will be lowered to stop module insertion, raw i/o,
53961+ system and net admin tasks, rebooting the system, modifying immutable
53962+ files, modifying IPC owned by another, and changing the system time.
53963+ This is left an option because it can break some apps. Disable this
53964+ if your chrooted apps are having problems performing those kinds of
53965+ tasks. If the sysctl option is enabled, a sysctl option with
53966+ name "chroot_caps" is created.
53967+
53968+endmenu
53969+menu "Kernel Auditing"
53970+depends on GRKERNSEC
53971+
53972+config GRKERNSEC_AUDIT_GROUP
53973+ bool "Single group for auditing"
53974+ help
53975+ If you say Y here, the exec and chdir logging features will only operate
53976+ on a group you specify. This option is recommended if you only want to
53977+ watch certain users instead of having a large amount of logs from the
53978+ entire system. If the sysctl option is enabled, a sysctl option with
53979+ name "audit_group" is created.
53980+
53981+config GRKERNSEC_AUDIT_GID
53982+ int "GID for auditing"
53983+ depends on GRKERNSEC_AUDIT_GROUP
53984+ default 1007
53985+
53986+config GRKERNSEC_EXECLOG
53987+ bool "Exec logging"
53988+ help
53989+ If you say Y here, all execve() calls will be logged (since the
53990+ other exec*() calls are frontends to execve(), all execution
53991+ will be logged). Useful for shell-servers that like to keep track
53992+ of their users. If the sysctl option is enabled, a sysctl option with
53993+ name "exec_logging" is created.
53994+ WARNING: This option when enabled will produce a LOT of logs, especially
53995+ on an active system.
53996+
53997+config GRKERNSEC_RESLOG
53998+ bool "Resource logging"
53999+ default y if GRKERNSEC_CONFIG_AUTO
54000+ help
54001+ If you say Y here, all attempts to overstep resource limits will
54002+ be logged with the resource name, the requested size, and the current
54003+ limit. It is highly recommended that you say Y here. If the sysctl
54004+ option is enabled, a sysctl option with name "resource_logging" is
54005+ created. If the RBAC system is enabled, the sysctl value is ignored.
54006+
54007+config GRKERNSEC_CHROOT_EXECLOG
54008+ bool "Log execs within chroot"
54009+ help
54010+ If you say Y here, all executions inside a chroot jail will be logged
54011+ to syslog. This can cause a large amount of logs if certain
54012+ applications (eg. djb's daemontools) are installed on the system, and
54013+ is therefore left as an option. If the sysctl option is enabled, a
54014+ sysctl option with name "chroot_execlog" is created.
54015+
54016+config GRKERNSEC_AUDIT_PTRACE
54017+ bool "Ptrace logging"
54018+ help
54019+ If you say Y here, all attempts to attach to a process via ptrace
54020+ will be logged. If the sysctl option is enabled, a sysctl option
54021+ with name "audit_ptrace" is created.
54022+
54023+config GRKERNSEC_AUDIT_CHDIR
54024+ bool "Chdir logging"
54025+ help
54026+ If you say Y here, all chdir() calls will be logged. If the sysctl
54027+ option is enabled, a sysctl option with name "audit_chdir" is created.
54028+
54029+config GRKERNSEC_AUDIT_MOUNT
54030+ bool "(Un)Mount logging"
54031+ help
54032+ If you say Y here, all mounts and unmounts will be logged. If the
54033+ sysctl option is enabled, a sysctl option with name "audit_mount" is
54034+ created.
54035+
54036+config GRKERNSEC_SIGNAL
54037+ bool "Signal logging"
54038+ default y if GRKERNSEC_CONFIG_AUTO
54039+ help
54040+ If you say Y here, certain important signals will be logged, such as
54041+ SIGSEGV, which will as a result inform you of when a error in a program
54042+ occurred, which in some cases could mean a possible exploit attempt.
54043+ If the sysctl option is enabled, a sysctl option with name
54044+ "signal_logging" is created.
54045+
54046+config GRKERNSEC_FORKFAIL
54047+ bool "Fork failure logging"
54048+ help
54049+ If you say Y here, all failed fork() attempts will be logged.
54050+ This could suggest a fork bomb, or someone attempting to overstep
54051+ their process limit. If the sysctl option is enabled, a sysctl option
54052+ with name "forkfail_logging" is created.
54053+
54054+config GRKERNSEC_TIME
54055+ bool "Time change logging"
54056+ default y if GRKERNSEC_CONFIG_AUTO
54057+ help
54058+ If you say Y here, any changes of the system clock will be logged.
54059+ If the sysctl option is enabled, a sysctl option with name
54060+ "timechange_logging" is created.
54061+
54062+config GRKERNSEC_PROC_IPADDR
54063+ bool "/proc/<pid>/ipaddr support"
54064+ default y if GRKERNSEC_CONFIG_AUTO
54065+ help
54066+ If you say Y here, a new entry will be added to each /proc/<pid>
54067+ directory that contains the IP address of the person using the task.
54068+ The IP is carried across local TCP and AF_UNIX stream sockets.
54069+ This information can be useful for IDS/IPSes to perform remote response
54070+ to a local attack. The entry is readable by only the owner of the
54071+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
54072+ the RBAC system), and thus does not create privacy concerns.
54073+
54074+config GRKERNSEC_RWXMAP_LOG
54075+ bool 'Denied RWX mmap/mprotect logging'
54076+ default y if GRKERNSEC_CONFIG_AUTO
54077+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
54078+ help
54079+ If you say Y here, calls to mmap() and mprotect() with explicit
54080+ usage of PROT_WRITE and PROT_EXEC together will be logged when
54081+ denied by the PAX_MPROTECT feature. If the sysctl option is
54082+ enabled, a sysctl option with name "rwxmap_logging" is created.
54083+
54084+config GRKERNSEC_AUDIT_TEXTREL
54085+ bool 'ELF text relocations logging (READ HELP)'
54086+ depends on PAX_MPROTECT
54087+ help
54088+ If you say Y here, text relocations will be logged with the filename
54089+ of the offending library or binary. The purpose of the feature is
54090+ to help Linux distribution developers get rid of libraries and
54091+ binaries that need text relocations which hinder the future progress
54092+ of PaX. Only Linux distribution developers should say Y here, and
54093+ never on a production machine, as this option creates an information
54094+ leak that could aid an attacker in defeating the randomization of
54095+ a single memory region. If the sysctl option is enabled, a sysctl
54096+ option with name "audit_textrel" is created.
54097+
54098+endmenu
54099+
54100+menu "Executable Protections"
54101+depends on GRKERNSEC
54102+
54103+config GRKERNSEC_DMESG
54104+ bool "Dmesg(8) restriction"
54105+ default y if GRKERNSEC_CONFIG_AUTO
54106+ help
54107+ If you say Y here, non-root users will not be able to use dmesg(8)
54108+ to view the contents of the kernel's circular log buffer.
54109+ The kernel's log buffer often contains kernel addresses and other
54110+ identifying information useful to an attacker in fingerprinting a
54111+ system for a targeted exploit.
54112+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
54113+ created.
54114+
54115+config GRKERNSEC_HARDEN_PTRACE
54116+ bool "Deter ptrace-based process snooping"
54117+ default y if GRKERNSEC_CONFIG_AUTO
54118+ help
54119+ If you say Y here, TTY sniffers and other malicious monitoring
54120+ programs implemented through ptrace will be defeated. If you
54121+ have been using the RBAC system, this option has already been
54122+ enabled for several years for all users, with the ability to make
54123+ fine-grained exceptions.
54124+
54125+ This option only affects the ability of non-root users to ptrace
54126+ processes that are not a descendent of the ptracing process.
54127+ This means that strace ./binary and gdb ./binary will still work,
54128+ but attaching to arbitrary processes will not. If the sysctl
54129+ option is enabled, a sysctl option with name "harden_ptrace" is
54130+ created.
54131+
54132+config GRKERNSEC_PTRACE_READEXEC
54133+ bool "Require read access to ptrace sensitive binaries"
54134+ default y if GRKERNSEC_CONFIG_AUTO
54135+ help
54136+ If you say Y here, unprivileged users will not be able to ptrace unreadable
54137+ binaries. This option is useful in environments that
54138+ remove the read bits (e.g. file mode 4711) from suid binaries to
54139+ prevent infoleaking of their contents. This option adds
54140+ consistency to the use of that file mode, as the binary could normally
54141+ be read out when run without privileges while ptracing.
54142+
54143+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
54144+ is created.
54145+
54146+config GRKERNSEC_SETXID
54147+ bool "Enforce consistent multithreaded privileges"
54148+ default y if GRKERNSEC_CONFIG_AUTO
54149+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
54150+ help
54151+ If you say Y here, a change from a root uid to a non-root uid
54152+ in a multithreaded application will cause the resulting uids,
54153+ gids, supplementary groups, and capabilities in that thread
54154+ to be propagated to the other threads of the process. In most
54155+ cases this is unnecessary, as glibc will emulate this behavior
54156+ on behalf of the application. Other libcs do not act in the
54157+ same way, allowing the other threads of the process to continue
54158+ running with root privileges. If the sysctl option is enabled,
54159+ a sysctl option with name "consistent_setxid" is created.
54160+
54161+config GRKERNSEC_TPE
54162+ bool "Trusted Path Execution (TPE)"
54163+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
54164+ help
54165+ If you say Y here, you will be able to choose a gid to add to the
54166+ supplementary groups of users you want to mark as "untrusted."
54167+ These users will not be able to execute any files that are not in
54168+ root-owned directories writable only by root. If the sysctl option
54169+ is enabled, a sysctl option with name "tpe" is created.
54170+
54171+config GRKERNSEC_TPE_ALL
54172+ bool "Partially restrict all non-root users"
54173+ depends on GRKERNSEC_TPE
54174+ help
54175+ If you say Y here, all non-root users will be covered under
54176+ a weaker TPE restriction. This is separate from, and in addition to,
54177+ the main TPE options that you have selected elsewhere. Thus, if a
54178+ "trusted" GID is chosen, this restriction applies to even that GID.
54179+ Under this restriction, all non-root users will only be allowed to
54180+ execute files in directories they own that are not group or
54181+ world-writable, or in directories owned by root and writable only by
54182+ root. If the sysctl option is enabled, a sysctl option with name
54183+ "tpe_restrict_all" is created.
54184+
54185+config GRKERNSEC_TPE_INVERT
54186+ bool "Invert GID option"
54187+ depends on GRKERNSEC_TPE
54188+ help
54189+ If you say Y here, the group you specify in the TPE configuration will
54190+ decide what group TPE restrictions will be *disabled* for. This
54191+ option is useful if you want TPE restrictions to be applied to most
54192+ users on the system. If the sysctl option is enabled, a sysctl option
54193+ with name "tpe_invert" is created. Unlike other sysctl options, this
54194+ entry will default to on for backward-compatibility.
54195+
54196+config GRKERNSEC_TPE_GID
54197+ int
54198+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
54199+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
54200+
54201+config GRKERNSEC_TPE_UNTRUSTED_GID
54202+ int "GID for TPE-untrusted users"
54203+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
54204+ default 1005
54205+ help
54206+ Setting this GID determines what group TPE restrictions will be
54207+ *enabled* for. If the sysctl option is enabled, a sysctl option
54208+ with name "tpe_gid" is created.
54209+
54210+config GRKERNSEC_TPE_TRUSTED_GID
54211+ int "GID for TPE-trusted users"
54212+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
54213+ default 1005
54214+ help
54215+ Setting this GID determines what group TPE restrictions will be
54216+ *disabled* for. If the sysctl option is enabled, a sysctl option
54217+ with name "tpe_gid" is created.
54218+
54219+endmenu
54220+menu "Network Protections"
54221+depends on GRKERNSEC
54222+
54223+config GRKERNSEC_RANDNET
54224+ bool "Larger entropy pools"
54225+ default y if GRKERNSEC_CONFIG_AUTO
54226+ help
54227+ If you say Y here, the entropy pools used for many features of Linux
54228+ and grsecurity will be doubled in size. Since several grsecurity
54229+ features use additional randomness, it is recommended that you say Y
54230+ here. Saying Y here has a similar effect as modifying
54231+ /proc/sys/kernel/random/poolsize.
54232+
54233+config GRKERNSEC_BLACKHOLE
54234+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
54235+ default y if GRKERNSEC_CONFIG_AUTO
54236+ depends on NET
54237+ help
54238+ If you say Y here, neither TCP resets nor ICMP
54239+ destination-unreachable packets will be sent in response to packets
54240+ sent to ports for which no associated listening process exists.
54241+ This feature supports both IPV4 and IPV6 and exempts the
54242+ loopback interface from blackholing. Enabling this feature
54243+ makes a host more resilient to DoS attacks and reduces network
54244+ visibility against scanners.
54245+
54246+ The blackhole feature as-implemented is equivalent to the FreeBSD
54247+ blackhole feature, as it prevents RST responses to all packets, not
54248+ just SYNs. Under most application behavior this causes no
54249+ problems, but applications (like haproxy) may not close certain
54250+ connections in a way that cleanly terminates them on the remote
54251+ end, leaving the remote host in LAST_ACK state. Because of this
54252+ side-effect and to prevent intentional LAST_ACK DoSes, this
54253+ feature also adds automatic mitigation against such attacks.
54254+ The mitigation drastically reduces the amount of time a socket
54255+ can spend in LAST_ACK state. If you're using haproxy and not
54256+ all servers it connects to have this option enabled, consider
54257+ disabling this feature on the haproxy host.
54258+
54259+ If the sysctl option is enabled, two sysctl options with names
54260+ "ip_blackhole" and "lastack_retries" will be created.
54261+ While "ip_blackhole" takes the standard zero/non-zero on/off
54262+ toggle, "lastack_retries" uses the same kinds of values as
54263+ "tcp_retries1" and "tcp_retries2". The default value of 4
54264+ prevents a socket from lasting more than 45 seconds in LAST_ACK
54265+ state.
54266+
54267+config GRKERNSEC_NO_SIMULT_CONNECT
54268+ bool "Disable TCP Simultaneous Connect"
54269+ default y if GRKERNSEC_CONFIG_AUTO
54270+ depends on NET
54271+ help
54272+ If you say Y here, a feature by Willy Tarreau will be enabled that
54273+ removes a weakness in Linux's strict implementation of TCP that
54274+ allows two clients to connect to each other without either entering
54275+ a listening state. The weakness allows an attacker to easily prevent
54276+ a client from connecting to a known server provided the source port
54277+ for the connection is guessed correctly.
54278+
54279+ As the weakness could be used to prevent an antivirus or IPS from
54280+ fetching updates, or prevent an SSL gateway from fetching a CRL,
54281+ it should be eliminated by enabling this option. Though Linux is
54282+ one of few operating systems supporting simultaneous connect, it
54283+ has no legitimate use in practice and is rarely supported by firewalls.
54284+
54285+config GRKERNSEC_SOCKET
54286+ bool "Socket restrictions"
54287+ depends on NET
54288+ help
54289+ If you say Y here, you will be able to choose from several options.
54290+ If you assign a GID on your system and add it to the supplementary
54291+ groups of users you want to restrict socket access to, this patch
54292+ will perform up to three things, based on the option(s) you choose.
54293+
54294+config GRKERNSEC_SOCKET_ALL
54295+ bool "Deny any sockets to group"
54296+ depends on GRKERNSEC_SOCKET
54297+ help
54298+ If you say Y here, you will be able to choose a GID of whose users will
54299+ be unable to connect to other hosts from your machine or run server
54300+ applications from your machine. If the sysctl option is enabled, a
54301+ sysctl option with name "socket_all" is created.
54302+
54303+config GRKERNSEC_SOCKET_ALL_GID
54304+ int "GID to deny all sockets for"
54305+ depends on GRKERNSEC_SOCKET_ALL
54306+ default 1004
54307+ help
54308+ Here you can choose the GID to disable socket access for. Remember to
54309+ add the users you want socket access disabled for to the GID
54310+ specified here. If the sysctl option is enabled, a sysctl option
54311+ with name "socket_all_gid" is created.
54312+
54313+config GRKERNSEC_SOCKET_CLIENT
54314+ bool "Deny client sockets to group"
54315+ depends on GRKERNSEC_SOCKET
54316+ help
54317+ If you say Y here, you will be able to choose a GID of whose users will
54318+ be unable to connect to other hosts from your machine, but will be
54319+ able to run servers. If this option is enabled, all users in the group
54320+ you specify will have to use passive mode when initiating ftp transfers
54321+ from the shell on your machine. If the sysctl option is enabled, a
54322+ sysctl option with name "socket_client" is created.
54323+
54324+config GRKERNSEC_SOCKET_CLIENT_GID
54325+ int "GID to deny client sockets for"
54326+ depends on GRKERNSEC_SOCKET_CLIENT
54327+ default 1003
54328+ help
54329+ Here you can choose the GID to disable client socket access for.
54330+ Remember to add the users you want client socket access disabled for to
54331+ the GID specified here. If the sysctl option is enabled, a sysctl
54332+ option with name "socket_client_gid" is created.
54333+
54334+config GRKERNSEC_SOCKET_SERVER
54335+ bool "Deny server sockets to group"
54336+ depends on GRKERNSEC_SOCKET
54337+ help
54338+ If you say Y here, you will be able to choose a GID of whose users will
54339+ be unable to run server applications from your machine. If the sysctl
54340+ option is enabled, a sysctl option with name "socket_server" is created.
54341+
54342+config GRKERNSEC_SOCKET_SERVER_GID
54343+ int "GID to deny server sockets for"
54344+ depends on GRKERNSEC_SOCKET_SERVER
54345+ default 1002
54346+ help
54347+ Here you can choose the GID to disable server socket access for.
54348+ Remember to add the users you want server socket access disabled for to
54349+ the GID specified here. If the sysctl option is enabled, a sysctl
54350+ option with name "socket_server_gid" is created.
54351+
54352+endmenu
54353+menu "Sysctl Support"
54354+depends on GRKERNSEC && SYSCTL
54355+
54356+config GRKERNSEC_SYSCTL
54357+ bool "Sysctl support"
54358+ default y if GRKERNSEC_CONFIG_AUTO
54359+ help
54360+ If you say Y here, you will be able to change the options that
54361+ grsecurity runs with at bootup, without having to recompile your
54362+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
54363+ to enable (1) or disable (0) various features. All the sysctl entries
54364+ are mutable until the "grsec_lock" entry is set to a non-zero value.
54365+ All features enabled in the kernel configuration are disabled at boot
54366+ if you do not say Y to the "Turn on features by default" option.
54367+ All options should be set at startup, and the grsec_lock entry should
54368+ be set to a non-zero value after all the options are set.
54369+ *THIS IS EXTREMELY IMPORTANT*
54370+
54371+config GRKERNSEC_SYSCTL_DISTRO
54372+ bool "Extra sysctl support for distro makers (READ HELP)"
54373+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
54374+ help
54375+ If you say Y here, additional sysctl options will be created
54376+ for features that affect processes running as root. Therefore,
54377+ it is critical when using this option that the grsec_lock entry be
54378+ enabled after boot. Only distros with prebuilt kernel packages
54379+ with this option enabled that can ensure grsec_lock is enabled
54380+ after boot should use this option.
54381+ *Failure to set grsec_lock after boot makes all grsec features
54382+ this option covers useless*
54383+
54384+ Currently this option creates the following sysctl entries:
54385+ "Disable Privileged I/O": "disable_priv_io"
54386+
54387+config GRKERNSEC_SYSCTL_ON
54388+ bool "Turn on features by default"
54389+ default y if GRKERNSEC_CONFIG_AUTO
54390+ depends on GRKERNSEC_SYSCTL
54391+ help
54392+ If you say Y here, instead of having all features enabled in the
54393+ kernel configuration disabled at boot time, the features will be
54394+ enabled at boot time. It is recommended you say Y here unless
54395+ there is some reason you would want all sysctl-tunable features to
54396+ be disabled by default. As mentioned elsewhere, it is important
54397+ to enable the grsec_lock entry once you have finished modifying
54398+ the sysctl entries.
54399+
54400+endmenu
54401+menu "Logging Options"
54402+depends on GRKERNSEC
54403+
54404+config GRKERNSEC_FLOODTIME
54405+ int "Seconds in between log messages (minimum)"
54406+ default 10
54407+ help
54408+ This option allows you to enforce the number of seconds between
54409+ grsecurity log messages. The default should be suitable for most
54410+ people, however, if you choose to change it, choose a value small enough
54411+ to allow informative logs to be produced, but large enough to
54412+ prevent flooding.
54413+
54414+config GRKERNSEC_FLOODBURST
54415+ int "Number of messages in a burst (maximum)"
54416+ default 6
54417+ help
54418+ This option allows you to choose the maximum number of messages allowed
54419+ within the flood time interval you chose in a separate option. The
54420+ default should be suitable for most people, however if you find that
54421+ many of your logs are being interpreted as flooding, you may want to
54422+ raise this value.
54423+
54424+endmenu
54425diff --git a/grsecurity/Makefile b/grsecurity/Makefile
54426new file mode 100644
54427index 0000000..1b9afa9
54428--- /dev/null
54429+++ b/grsecurity/Makefile
54430@@ -0,0 +1,38 @@
54431+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
54432+# during 2001-2009 it has been completely redesigned by Brad Spengler
54433+# into an RBAC system
54434+#
54435+# All code in this directory and various hooks inserted throughout the kernel
54436+# are copyright Brad Spengler - Open Source Security, Inc., and released
54437+# under the GPL v2 or higher
54438+
54439+KBUILD_CFLAGS += -Werror
54440+
54441+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
54442+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
54443+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
54444+
54445+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
54446+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
54447+ gracl_learn.o grsec_log.o
54448+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
54449+
54450+ifdef CONFIG_NET
54451+obj-y += grsec_sock.o
54452+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
54453+endif
54454+
54455+ifndef CONFIG_GRKERNSEC
54456+obj-y += grsec_disabled.o
54457+endif
54458+
54459+ifdef CONFIG_GRKERNSEC_HIDESYM
54460+extra-y := grsec_hidesym.o
54461+$(obj)/grsec_hidesym.o:
54462+ @-chmod -f 500 /boot
54463+ @-chmod -f 500 /lib/modules
54464+ @-chmod -f 500 /lib64/modules
54465+ @-chmod -f 500 /lib32/modules
54466+ @-chmod -f 700 .
54467+ @echo ' grsec: protected kernel image paths'
54468+endif
54469diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
54470new file mode 100644
54471index 0000000..69e1320
54472--- /dev/null
54473+++ b/grsecurity/gracl.c
54474@@ -0,0 +1,4019 @@
54475+#include <linux/kernel.h>
54476+#include <linux/module.h>
54477+#include <linux/sched.h>
54478+#include <linux/mm.h>
54479+#include <linux/file.h>
54480+#include <linux/fs.h>
54481+#include <linux/namei.h>
54482+#include <linux/mount.h>
54483+#include <linux/tty.h>
54484+#include <linux/proc_fs.h>
54485+#include <linux/lglock.h>
54486+#include <linux/slab.h>
54487+#include <linux/vmalloc.h>
54488+#include <linux/types.h>
54489+#include <linux/sysctl.h>
54490+#include <linux/netdevice.h>
54491+#include <linux/ptrace.h>
54492+#include <linux/gracl.h>
54493+#include <linux/gralloc.h>
54494+#include <linux/security.h>
54495+#include <linux/grinternal.h>
54496+#include <linux/pid_namespace.h>
54497+#include <linux/stop_machine.h>
54498+#include <linux/fdtable.h>
54499+#include <linux/percpu.h>
54500+#include <linux/lglock.h>
54501+#include <linux/hugetlb.h>
54502+#include "../fs/mount.h"
54503+
54504+#include <asm/uaccess.h>
54505+#include <asm/errno.h>
54506+#include <asm/mman.h>
54507+
54508+extern struct lglock vfsmount_lock;
54509+
54510+static struct acl_role_db acl_role_set;
54511+static struct name_db name_set;
54512+static struct inodev_db inodev_set;
54513+
54514+/* for keeping track of userspace pointers used for subjects, so we
54515+ can share references in the kernel as well
54516+*/
54517+
54518+static struct path real_root;
54519+
54520+static struct acl_subj_map_db subj_map_set;
54521+
54522+static struct acl_role_label *default_role;
54523+
54524+static struct acl_role_label *role_list;
54525+
54526+static u16 acl_sp_role_value;
54527+
54528+extern char *gr_shared_page[4];
54529+static DEFINE_MUTEX(gr_dev_mutex);
54530+DEFINE_RWLOCK(gr_inode_lock);
54531+
54532+struct gr_arg *gr_usermode;
54533+
54534+static unsigned int gr_status __read_only = GR_STATUS_INIT;
54535+
54536+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
54537+extern void gr_clear_learn_entries(void);
54538+
54539+unsigned char *gr_system_salt;
54540+unsigned char *gr_system_sum;
54541+
54542+static struct sprole_pw **acl_special_roles = NULL;
54543+static __u16 num_sprole_pws = 0;
54544+
54545+static struct acl_role_label *kernel_role = NULL;
54546+
54547+static unsigned int gr_auth_attempts = 0;
54548+static unsigned long gr_auth_expires = 0UL;
54549+
54550+#ifdef CONFIG_NET
54551+extern struct vfsmount *sock_mnt;
54552+#endif
54553+
54554+extern struct vfsmount *pipe_mnt;
54555+extern struct vfsmount *shm_mnt;
54556+
54557+#ifdef CONFIG_HUGETLBFS
54558+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
54559+#endif
54560+
54561+static struct acl_object_label *fakefs_obj_rw;
54562+static struct acl_object_label *fakefs_obj_rwx;
54563+
54564+extern int gr_init_uidset(void);
54565+extern void gr_free_uidset(void);
54566+extern void gr_remove_uid(uid_t uid);
54567+extern int gr_find_uid(uid_t uid);
54568+
54569+__inline__ int
54570+gr_acl_is_enabled(void)
54571+{
54572+ return (gr_status & GR_READY);
54573+}
54574+
54575+#ifdef CONFIG_BTRFS_FS
54576+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
54577+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
54578+#endif
54579+
54580+static inline dev_t __get_dev(const struct dentry *dentry)
54581+{
54582+#ifdef CONFIG_BTRFS_FS
54583+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
54584+ return get_btrfs_dev_from_inode(dentry->d_inode);
54585+ else
54586+#endif
54587+ return dentry->d_inode->i_sb->s_dev;
54588+}
54589+
54590+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
54591+{
54592+ return __get_dev(dentry);
54593+}
54594+
54595+static char gr_task_roletype_to_char(struct task_struct *task)
54596+{
54597+ switch (task->role->roletype &
54598+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
54599+ GR_ROLE_SPECIAL)) {
54600+ case GR_ROLE_DEFAULT:
54601+ return 'D';
54602+ case GR_ROLE_USER:
54603+ return 'U';
54604+ case GR_ROLE_GROUP:
54605+ return 'G';
54606+ case GR_ROLE_SPECIAL:
54607+ return 'S';
54608+ }
54609+
54610+ return 'X';
54611+}
54612+
54613+char gr_roletype_to_char(void)
54614+{
54615+ return gr_task_roletype_to_char(current);
54616+}
54617+
54618+__inline__ int
54619+gr_acl_tpe_check(void)
54620+{
54621+ if (unlikely(!(gr_status & GR_READY)))
54622+ return 0;
54623+ if (current->role->roletype & GR_ROLE_TPE)
54624+ return 1;
54625+ else
54626+ return 0;
54627+}
54628+
54629+int
54630+gr_handle_rawio(const struct inode *inode)
54631+{
54632+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
54633+ if (inode && S_ISBLK(inode->i_mode) &&
54634+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
54635+ !capable(CAP_SYS_RAWIO))
54636+ return 1;
54637+#endif
54638+ return 0;
54639+}
54640+
54641+static int
54642+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
54643+{
54644+ if (likely(lena != lenb))
54645+ return 0;
54646+
54647+ return !memcmp(a, b, lena);
54648+}
54649+
54650+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
54651+{
54652+ *buflen -= namelen;
54653+ if (*buflen < 0)
54654+ return -ENAMETOOLONG;
54655+ *buffer -= namelen;
54656+ memcpy(*buffer, str, namelen);
54657+ return 0;
54658+}
54659+
54660+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
54661+{
54662+ return prepend(buffer, buflen, name->name, name->len);
54663+}
54664+
54665+static int prepend_path(const struct path *path, struct path *root,
54666+ char **buffer, int *buflen)
54667+{
54668+ struct dentry *dentry = path->dentry;
54669+ struct vfsmount *vfsmnt = path->mnt;
54670+ struct mount *mnt = real_mount(vfsmnt);
54671+ bool slash = false;
54672+ int error = 0;
54673+
54674+ while (dentry != root->dentry || vfsmnt != root->mnt) {
54675+ struct dentry * parent;
54676+
54677+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
54678+ /* Global root? */
54679+ if (!mnt_has_parent(mnt)) {
54680+ goto out;
54681+ }
54682+ dentry = mnt->mnt_mountpoint;
54683+ mnt = mnt->mnt_parent;
54684+ vfsmnt = &mnt->mnt;
54685+ continue;
54686+ }
54687+ parent = dentry->d_parent;
54688+ prefetch(parent);
54689+ spin_lock(&dentry->d_lock);
54690+ error = prepend_name(buffer, buflen, &dentry->d_name);
54691+ spin_unlock(&dentry->d_lock);
54692+ if (!error)
54693+ error = prepend(buffer, buflen, "/", 1);
54694+ if (error)
54695+ break;
54696+
54697+ slash = true;
54698+ dentry = parent;
54699+ }
54700+
54701+out:
54702+ if (!error && !slash)
54703+ error = prepend(buffer, buflen, "/", 1);
54704+
54705+ return error;
54706+}
54707+
54708+/* this must be called with vfsmount_lock and rename_lock held */
54709+
54710+static char *__our_d_path(const struct path *path, struct path *root,
54711+ char *buf, int buflen)
54712+{
54713+ char *res = buf + buflen;
54714+ int error;
54715+
54716+ prepend(&res, &buflen, "\0", 1);
54717+ error = prepend_path(path, root, &res, &buflen);
54718+ if (error)
54719+ return ERR_PTR(error);
54720+
54721+ return res;
54722+}
54723+
54724+static char *
54725+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
54726+{
54727+ char *retval;
54728+
54729+ retval = __our_d_path(path, root, buf, buflen);
54730+ if (unlikely(IS_ERR(retval)))
54731+ retval = strcpy(buf, "<path too long>");
54732+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
54733+ retval[1] = '\0';
54734+
54735+ return retval;
54736+}
54737+
54738+static char *
54739+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
54740+ char *buf, int buflen)
54741+{
54742+ struct path path;
54743+ char *res;
54744+
54745+ path.dentry = (struct dentry *)dentry;
54746+ path.mnt = (struct vfsmount *)vfsmnt;
54747+
54748+ /* we can use real_root.dentry, real_root.mnt, because this is only called
54749+ by the RBAC system */
54750+ res = gen_full_path(&path, &real_root, buf, buflen);
54751+
54752+ return res;
54753+}
54754+
54755+static char *
54756+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
54757+ char *buf, int buflen)
54758+{
54759+ char *res;
54760+ struct path path;
54761+ struct path root;
54762+ struct task_struct *reaper = init_pid_ns.child_reaper;
54763+
54764+ path.dentry = (struct dentry *)dentry;
54765+ path.mnt = (struct vfsmount *)vfsmnt;
54766+
54767+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
54768+ get_fs_root(reaper->fs, &root);
54769+
54770+ write_seqlock(&rename_lock);
54771+ br_read_lock(&vfsmount_lock);
54772+ res = gen_full_path(&path, &root, buf, buflen);
54773+ br_read_unlock(&vfsmount_lock);
54774+ write_sequnlock(&rename_lock);
54775+
54776+ path_put(&root);
54777+ return res;
54778+}
54779+
54780+static char *
54781+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
54782+{
54783+ char *ret;
54784+ write_seqlock(&rename_lock);
54785+ br_read_lock(&vfsmount_lock);
54786+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
54787+ PAGE_SIZE);
54788+ br_read_unlock(&vfsmount_lock);
54789+ write_sequnlock(&rename_lock);
54790+ return ret;
54791+}
54792+
54793+static char *
54794+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
54795+{
54796+ char *ret;
54797+ char *buf;
54798+ int buflen;
54799+
54800+ write_seqlock(&rename_lock);
54801+ br_read_lock(&vfsmount_lock);
54802+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
54803+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
54804+ buflen = (int)(ret - buf);
54805+ if (buflen >= 5)
54806+ prepend(&ret, &buflen, "/proc", 5);
54807+ else
54808+ ret = strcpy(buf, "<path too long>");
54809+ br_read_unlock(&vfsmount_lock);
54810+ write_sequnlock(&rename_lock);
54811+ return ret;
54812+}
54813+
54814+char *
54815+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
54816+{
54817+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
54818+ PAGE_SIZE);
54819+}
54820+
54821+char *
54822+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
54823+{
54824+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
54825+ PAGE_SIZE);
54826+}
54827+
54828+char *
54829+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
54830+{
54831+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
54832+ PAGE_SIZE);
54833+}
54834+
54835+char *
54836+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
54837+{
54838+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
54839+ PAGE_SIZE);
54840+}
54841+
54842+char *
54843+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
54844+{
54845+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
54846+ PAGE_SIZE);
54847+}
54848+
54849+__inline__ __u32
54850+to_gr_audit(const __u32 reqmode)
54851+{
54852+ /* masks off auditable permission flags, then shifts them to create
54853+ auditing flags, and adds the special case of append auditing if
54854+ we're requesting write */
54855+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
54856+}
54857+
54858+struct acl_subject_label *
54859+lookup_subject_map(const struct acl_subject_label *userp)
54860+{
54861+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
54862+ struct subject_map *match;
54863+
54864+ match = subj_map_set.s_hash[index];
54865+
54866+ while (match && match->user != userp)
54867+ match = match->next;
54868+
54869+ if (match != NULL)
54870+ return match->kernel;
54871+ else
54872+ return NULL;
54873+}
54874+
54875+static void
54876+insert_subj_map_entry(struct subject_map *subjmap)
54877+{
54878+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
54879+ struct subject_map **curr;
54880+
54881+ subjmap->prev = NULL;
54882+
54883+ curr = &subj_map_set.s_hash[index];
54884+ if (*curr != NULL)
54885+ (*curr)->prev = subjmap;
54886+
54887+ subjmap->next = *curr;
54888+ *curr = subjmap;
54889+
54890+ return;
54891+}
54892+
54893+static struct acl_role_label *
54894+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
54895+ const gid_t gid)
54896+{
54897+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
54898+ struct acl_role_label *match;
54899+ struct role_allowed_ip *ipp;
54900+ unsigned int x;
54901+ u32 curr_ip = task->signal->curr_ip;
54902+
54903+ task->signal->saved_ip = curr_ip;
54904+
54905+ match = acl_role_set.r_hash[index];
54906+
54907+ while (match) {
54908+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
54909+ for (x = 0; x < match->domain_child_num; x++) {
54910+ if (match->domain_children[x] == uid)
54911+ goto found;
54912+ }
54913+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
54914+ break;
54915+ match = match->next;
54916+ }
54917+found:
54918+ if (match == NULL) {
54919+ try_group:
54920+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
54921+ match = acl_role_set.r_hash[index];
54922+
54923+ while (match) {
54924+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
54925+ for (x = 0; x < match->domain_child_num; x++) {
54926+ if (match->domain_children[x] == gid)
54927+ goto found2;
54928+ }
54929+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
54930+ break;
54931+ match = match->next;
54932+ }
54933+found2:
54934+ if (match == NULL)
54935+ match = default_role;
54936+ if (match->allowed_ips == NULL)
54937+ return match;
54938+ else {
54939+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
54940+ if (likely
54941+ ((ntohl(curr_ip) & ipp->netmask) ==
54942+ (ntohl(ipp->addr) & ipp->netmask)))
54943+ return match;
54944+ }
54945+ match = default_role;
54946+ }
54947+ } else if (match->allowed_ips == NULL) {
54948+ return match;
54949+ } else {
54950+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
54951+ if (likely
54952+ ((ntohl(curr_ip) & ipp->netmask) ==
54953+ (ntohl(ipp->addr) & ipp->netmask)))
54954+ return match;
54955+ }
54956+ goto try_group;
54957+ }
54958+
54959+ return match;
54960+}
54961+
54962+struct acl_subject_label *
54963+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
54964+ const struct acl_role_label *role)
54965+{
54966+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
54967+ struct acl_subject_label *match;
54968+
54969+ match = role->subj_hash[index];
54970+
54971+ while (match && (match->inode != ino || match->device != dev ||
54972+ (match->mode & GR_DELETED))) {
54973+ match = match->next;
54974+ }
54975+
54976+ if (match && !(match->mode & GR_DELETED))
54977+ return match;
54978+ else
54979+ return NULL;
54980+}
54981+
54982+struct acl_subject_label *
54983+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
54984+ const struct acl_role_label *role)
54985+{
54986+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
54987+ struct acl_subject_label *match;
54988+
54989+ match = role->subj_hash[index];
54990+
54991+ while (match && (match->inode != ino || match->device != dev ||
54992+ !(match->mode & GR_DELETED))) {
54993+ match = match->next;
54994+ }
54995+
54996+ if (match && (match->mode & GR_DELETED))
54997+ return match;
54998+ else
54999+ return NULL;
55000+}
55001+
55002+static struct acl_object_label *
55003+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
55004+ const struct acl_subject_label *subj)
55005+{
55006+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
55007+ struct acl_object_label *match;
55008+
55009+ match = subj->obj_hash[index];
55010+
55011+ while (match && (match->inode != ino || match->device != dev ||
55012+ (match->mode & GR_DELETED))) {
55013+ match = match->next;
55014+ }
55015+
55016+ if (match && !(match->mode & GR_DELETED))
55017+ return match;
55018+ else
55019+ return NULL;
55020+}
55021+
55022+static struct acl_object_label *
55023+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
55024+ const struct acl_subject_label *subj)
55025+{
55026+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
55027+ struct acl_object_label *match;
55028+
55029+ match = subj->obj_hash[index];
55030+
55031+ while (match && (match->inode != ino || match->device != dev ||
55032+ !(match->mode & GR_DELETED))) {
55033+ match = match->next;
55034+ }
55035+
55036+ if (match && (match->mode & GR_DELETED))
55037+ return match;
55038+
55039+ match = subj->obj_hash[index];
55040+
55041+ while (match && (match->inode != ino || match->device != dev ||
55042+ (match->mode & GR_DELETED))) {
55043+ match = match->next;
55044+ }
55045+
55046+ if (match && !(match->mode & GR_DELETED))
55047+ return match;
55048+ else
55049+ return NULL;
55050+}
55051+
55052+static struct name_entry *
55053+lookup_name_entry(const char *name)
55054+{
55055+ unsigned int len = strlen(name);
55056+ unsigned int key = full_name_hash(name, len);
55057+ unsigned int index = key % name_set.n_size;
55058+ struct name_entry *match;
55059+
55060+ match = name_set.n_hash[index];
55061+
55062+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
55063+ match = match->next;
55064+
55065+ return match;
55066+}
55067+
55068+static struct name_entry *
55069+lookup_name_entry_create(const char *name)
55070+{
55071+ unsigned int len = strlen(name);
55072+ unsigned int key = full_name_hash(name, len);
55073+ unsigned int index = key % name_set.n_size;
55074+ struct name_entry *match;
55075+
55076+ match = name_set.n_hash[index];
55077+
55078+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
55079+ !match->deleted))
55080+ match = match->next;
55081+
55082+ if (match && match->deleted)
55083+ return match;
55084+
55085+ match = name_set.n_hash[index];
55086+
55087+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
55088+ match->deleted))
55089+ match = match->next;
55090+
55091+ if (match && !match->deleted)
55092+ return match;
55093+ else
55094+ return NULL;
55095+}
55096+
55097+static struct inodev_entry *
55098+lookup_inodev_entry(const ino_t ino, const dev_t dev)
55099+{
55100+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
55101+ struct inodev_entry *match;
55102+
55103+ match = inodev_set.i_hash[index];
55104+
55105+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
55106+ match = match->next;
55107+
55108+ return match;
55109+}
55110+
55111+static void
55112+insert_inodev_entry(struct inodev_entry *entry)
55113+{
55114+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
55115+ inodev_set.i_size);
55116+ struct inodev_entry **curr;
55117+
55118+ entry->prev = NULL;
55119+
55120+ curr = &inodev_set.i_hash[index];
55121+ if (*curr != NULL)
55122+ (*curr)->prev = entry;
55123+
55124+ entry->next = *curr;
55125+ *curr = entry;
55126+
55127+ return;
55128+}
55129+
55130+static void
55131+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
55132+{
55133+ unsigned int index =
55134+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
55135+ struct acl_role_label **curr;
55136+ struct acl_role_label *tmp, *tmp2;
55137+
55138+ curr = &acl_role_set.r_hash[index];
55139+
55140+ /* simple case, slot is empty, just set it to our role */
55141+ if (*curr == NULL) {
55142+ *curr = role;
55143+ } else {
55144+ /* example:
55145+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
55146+ 2 -> 3
55147+ */
55148+ /* first check to see if we can already be reached via this slot */
55149+ tmp = *curr;
55150+ while (tmp && tmp != role)
55151+ tmp = tmp->next;
55152+ if (tmp == role) {
55153+ /* we don't need to add ourselves to this slot's chain */
55154+ return;
55155+ }
55156+ /* we need to add ourselves to this chain, two cases */
55157+ if (role->next == NULL) {
55158+ /* simple case, append the current chain to our role */
55159+ role->next = *curr;
55160+ *curr = role;
55161+ } else {
55162+ /* 1 -> 2 -> 3 -> 4
55163+ 2 -> 3 -> 4
55164+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
55165+ */
55166+ /* trickier case: walk our role's chain until we find
55167+ the role for the start of the current slot's chain */
55168+ tmp = role;
55169+ tmp2 = *curr;
55170+ while (tmp->next && tmp->next != tmp2)
55171+ tmp = tmp->next;
55172+ if (tmp->next == tmp2) {
55173+ /* from example above, we found 3, so just
55174+ replace this slot's chain with ours */
55175+ *curr = role;
55176+ } else {
55177+ /* we didn't find a subset of our role's chain
55178+ in the current slot's chain, so append their
55179+ chain to ours, and set us as the first role in
55180+ the slot's chain
55181+
55182+ we could fold this case with the case above,
55183+ but making it explicit for clarity
55184+ */
55185+ tmp->next = tmp2;
55186+ *curr = role;
55187+ }
55188+ }
55189+ }
55190+
55191+ return;
55192+}
55193+
55194+static void
55195+insert_acl_role_label(struct acl_role_label *role)
55196+{
55197+ int i;
55198+
55199+ if (role_list == NULL) {
55200+ role_list = role;
55201+ role->prev = NULL;
55202+ } else {
55203+ role->prev = role_list;
55204+ role_list = role;
55205+ }
55206+
55207+ /* used for hash chains */
55208+ role->next = NULL;
55209+
55210+ if (role->roletype & GR_ROLE_DOMAIN) {
55211+ for (i = 0; i < role->domain_child_num; i++)
55212+ __insert_acl_role_label(role, role->domain_children[i]);
55213+ } else
55214+ __insert_acl_role_label(role, role->uidgid);
55215+}
55216+
55217+static int
55218+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
55219+{
55220+ struct name_entry **curr, *nentry;
55221+ struct inodev_entry *ientry;
55222+ unsigned int len = strlen(name);
55223+ unsigned int key = full_name_hash(name, len);
55224+ unsigned int index = key % name_set.n_size;
55225+
55226+ curr = &name_set.n_hash[index];
55227+
55228+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
55229+ curr = &((*curr)->next);
55230+
55231+ if (*curr != NULL)
55232+ return 1;
55233+
55234+ nentry = acl_alloc(sizeof (struct name_entry));
55235+ if (nentry == NULL)
55236+ return 0;
55237+ ientry = acl_alloc(sizeof (struct inodev_entry));
55238+ if (ientry == NULL)
55239+ return 0;
55240+ ientry->nentry = nentry;
55241+
55242+ nentry->key = key;
55243+ nentry->name = name;
55244+ nentry->inode = inode;
55245+ nentry->device = device;
55246+ nentry->len = len;
55247+ nentry->deleted = deleted;
55248+
55249+ nentry->prev = NULL;
55250+ curr = &name_set.n_hash[index];
55251+ if (*curr != NULL)
55252+ (*curr)->prev = nentry;
55253+ nentry->next = *curr;
55254+ *curr = nentry;
55255+
55256+ /* insert us into the table searchable by inode/dev */
55257+ insert_inodev_entry(ientry);
55258+
55259+ return 1;
55260+}
55261+
55262+static void
55263+insert_acl_obj_label(struct acl_object_label *obj,
55264+ struct acl_subject_label *subj)
55265+{
55266+ unsigned int index =
55267+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
55268+ struct acl_object_label **curr;
55269+
55270+
55271+ obj->prev = NULL;
55272+
55273+ curr = &subj->obj_hash[index];
55274+ if (*curr != NULL)
55275+ (*curr)->prev = obj;
55276+
55277+ obj->next = *curr;
55278+ *curr = obj;
55279+
55280+ return;
55281+}
55282+
55283+static void
55284+insert_acl_subj_label(struct acl_subject_label *obj,
55285+ struct acl_role_label *role)
55286+{
55287+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
55288+ struct acl_subject_label **curr;
55289+
55290+ obj->prev = NULL;
55291+
55292+ curr = &role->subj_hash[index];
55293+ if (*curr != NULL)
55294+ (*curr)->prev = obj;
55295+
55296+ obj->next = *curr;
55297+ *curr = obj;
55298+
55299+ return;
55300+}
55301+
55302+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
55303+
55304+static void *
55305+create_table(__u32 * len, int elementsize)
55306+{
55307+ unsigned int table_sizes[] = {
55308+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
55309+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
55310+ 4194301, 8388593, 16777213, 33554393, 67108859
55311+ };
55312+ void *newtable = NULL;
55313+ unsigned int pwr = 0;
55314+
55315+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
55316+ table_sizes[pwr] <= *len)
55317+ pwr++;
55318+
55319+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
55320+ return newtable;
55321+
55322+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
55323+ newtable =
55324+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
55325+ else
55326+ newtable = vmalloc(table_sizes[pwr] * elementsize);
55327+
55328+ *len = table_sizes[pwr];
55329+
55330+ return newtable;
55331+}
55332+
55333+static int
55334+init_variables(const struct gr_arg *arg)
55335+{
55336+ struct task_struct *reaper = init_pid_ns.child_reaper;
55337+ unsigned int stacksize;
55338+
55339+ subj_map_set.s_size = arg->role_db.num_subjects;
55340+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
55341+ name_set.n_size = arg->role_db.num_objects;
55342+ inodev_set.i_size = arg->role_db.num_objects;
55343+
55344+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
55345+ !name_set.n_size || !inodev_set.i_size)
55346+ return 1;
55347+
55348+ if (!gr_init_uidset())
55349+ return 1;
55350+
55351+ /* set up the stack that holds allocation info */
55352+
55353+ stacksize = arg->role_db.num_pointers + 5;
55354+
55355+ if (!acl_alloc_stack_init(stacksize))
55356+ return 1;
55357+
55358+ /* grab reference for the real root dentry and vfsmount */
55359+ get_fs_root(reaper->fs, &real_root);
55360+
55361+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55362+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
55363+#endif
55364+
55365+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
55366+ if (fakefs_obj_rw == NULL)
55367+ return 1;
55368+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
55369+
55370+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
55371+ if (fakefs_obj_rwx == NULL)
55372+ return 1;
55373+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
55374+
55375+ subj_map_set.s_hash =
55376+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
55377+ acl_role_set.r_hash =
55378+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
55379+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
55380+ inodev_set.i_hash =
55381+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
55382+
55383+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
55384+ !name_set.n_hash || !inodev_set.i_hash)
55385+ return 1;
55386+
55387+ memset(subj_map_set.s_hash, 0,
55388+ sizeof(struct subject_map *) * subj_map_set.s_size);
55389+ memset(acl_role_set.r_hash, 0,
55390+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
55391+ memset(name_set.n_hash, 0,
55392+ sizeof (struct name_entry *) * name_set.n_size);
55393+ memset(inodev_set.i_hash, 0,
55394+ sizeof (struct inodev_entry *) * inodev_set.i_size);
55395+
55396+ return 0;
55397+}
55398+
55399+/* free information not needed after startup
55400+ currently contains user->kernel pointer mappings for subjects
55401+*/
55402+
55403+static void
55404+free_init_variables(void)
55405+{
55406+ __u32 i;
55407+
55408+ if (subj_map_set.s_hash) {
55409+ for (i = 0; i < subj_map_set.s_size; i++) {
55410+ if (subj_map_set.s_hash[i]) {
55411+ kfree(subj_map_set.s_hash[i]);
55412+ subj_map_set.s_hash[i] = NULL;
55413+ }
55414+ }
55415+
55416+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
55417+ PAGE_SIZE)
55418+ kfree(subj_map_set.s_hash);
55419+ else
55420+ vfree(subj_map_set.s_hash);
55421+ }
55422+
55423+ return;
55424+}
55425+
55426+static void
55427+free_variables(void)
55428+{
55429+ struct acl_subject_label *s;
55430+ struct acl_role_label *r;
55431+ struct task_struct *task, *task2;
55432+ unsigned int x;
55433+
55434+ gr_clear_learn_entries();
55435+
55436+ read_lock(&tasklist_lock);
55437+ do_each_thread(task2, task) {
55438+ task->acl_sp_role = 0;
55439+ task->acl_role_id = 0;
55440+ task->acl = NULL;
55441+ task->role = NULL;
55442+ } while_each_thread(task2, task);
55443+ read_unlock(&tasklist_lock);
55444+
55445+ /* release the reference to the real root dentry and vfsmount */
55446+ path_put(&real_root);
55447+ memset(&real_root, 0, sizeof(real_root));
55448+
55449+ /* free all object hash tables */
55450+
55451+ FOR_EACH_ROLE_START(r)
55452+ if (r->subj_hash == NULL)
55453+ goto next_role;
55454+ FOR_EACH_SUBJECT_START(r, s, x)
55455+ if (s->obj_hash == NULL)
55456+ break;
55457+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
55458+ kfree(s->obj_hash);
55459+ else
55460+ vfree(s->obj_hash);
55461+ FOR_EACH_SUBJECT_END(s, x)
55462+ FOR_EACH_NESTED_SUBJECT_START(r, s)
55463+ if (s->obj_hash == NULL)
55464+ break;
55465+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
55466+ kfree(s->obj_hash);
55467+ else
55468+ vfree(s->obj_hash);
55469+ FOR_EACH_NESTED_SUBJECT_END(s)
55470+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
55471+ kfree(r->subj_hash);
55472+ else
55473+ vfree(r->subj_hash);
55474+ r->subj_hash = NULL;
55475+next_role:
55476+ FOR_EACH_ROLE_END(r)
55477+
55478+ acl_free_all();
55479+
55480+ if (acl_role_set.r_hash) {
55481+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
55482+ PAGE_SIZE)
55483+ kfree(acl_role_set.r_hash);
55484+ else
55485+ vfree(acl_role_set.r_hash);
55486+ }
55487+ if (name_set.n_hash) {
55488+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
55489+ PAGE_SIZE)
55490+ kfree(name_set.n_hash);
55491+ else
55492+ vfree(name_set.n_hash);
55493+ }
55494+
55495+ if (inodev_set.i_hash) {
55496+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
55497+ PAGE_SIZE)
55498+ kfree(inodev_set.i_hash);
55499+ else
55500+ vfree(inodev_set.i_hash);
55501+ }
55502+
55503+ gr_free_uidset();
55504+
55505+ memset(&name_set, 0, sizeof (struct name_db));
55506+ memset(&inodev_set, 0, sizeof (struct inodev_db));
55507+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
55508+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
55509+
55510+ default_role = NULL;
55511+ kernel_role = NULL;
55512+ role_list = NULL;
55513+
55514+ return;
55515+}
55516+
55517+static __u32
55518+count_user_objs(struct acl_object_label *userp)
55519+{
55520+ struct acl_object_label o_tmp;
55521+ __u32 num = 0;
55522+
55523+ while (userp) {
55524+ if (copy_from_user(&o_tmp, userp,
55525+ sizeof (struct acl_object_label)))
55526+ break;
55527+
55528+ userp = o_tmp.prev;
55529+ num++;
55530+ }
55531+
55532+ return num;
55533+}
55534+
55535+static struct acl_subject_label *
55536+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
55537+
55538+static int
55539+copy_user_glob(struct acl_object_label *obj)
55540+{
55541+ struct acl_object_label *g_tmp, **guser;
55542+ unsigned int len;
55543+ char *tmp;
55544+
55545+ if (obj->globbed == NULL)
55546+ return 0;
55547+
55548+ guser = &obj->globbed;
55549+ while (*guser) {
55550+ g_tmp = (struct acl_object_label *)
55551+ acl_alloc(sizeof (struct acl_object_label));
55552+ if (g_tmp == NULL)
55553+ return -ENOMEM;
55554+
55555+ if (copy_from_user(g_tmp, *guser,
55556+ sizeof (struct acl_object_label)))
55557+ return -EFAULT;
55558+
55559+ len = strnlen_user(g_tmp->filename, PATH_MAX);
55560+
55561+ if (!len || len >= PATH_MAX)
55562+ return -EINVAL;
55563+
55564+ if ((tmp = (char *) acl_alloc(len)) == NULL)
55565+ return -ENOMEM;
55566+
55567+ if (copy_from_user(tmp, g_tmp->filename, len))
55568+ return -EFAULT;
55569+ tmp[len-1] = '\0';
55570+ g_tmp->filename = tmp;
55571+
55572+ *guser = g_tmp;
55573+ guser = &(g_tmp->next);
55574+ }
55575+
55576+ return 0;
55577+}
55578+
55579+static int
55580+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
55581+ struct acl_role_label *role)
55582+{
55583+ struct acl_object_label *o_tmp;
55584+ unsigned int len;
55585+ int ret;
55586+ char *tmp;
55587+
55588+ while (userp) {
55589+ if ((o_tmp = (struct acl_object_label *)
55590+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
55591+ return -ENOMEM;
55592+
55593+ if (copy_from_user(o_tmp, userp,
55594+ sizeof (struct acl_object_label)))
55595+ return -EFAULT;
55596+
55597+ userp = o_tmp->prev;
55598+
55599+ len = strnlen_user(o_tmp->filename, PATH_MAX);
55600+
55601+ if (!len || len >= PATH_MAX)
55602+ return -EINVAL;
55603+
55604+ if ((tmp = (char *) acl_alloc(len)) == NULL)
55605+ return -ENOMEM;
55606+
55607+ if (copy_from_user(tmp, o_tmp->filename, len))
55608+ return -EFAULT;
55609+ tmp[len-1] = '\0';
55610+ o_tmp->filename = tmp;
55611+
55612+ insert_acl_obj_label(o_tmp, subj);
55613+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
55614+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
55615+ return -ENOMEM;
55616+
55617+ ret = copy_user_glob(o_tmp);
55618+ if (ret)
55619+ return ret;
55620+
55621+ if (o_tmp->nested) {
55622+ int already_copied;
55623+
55624+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
55625+ if (IS_ERR(o_tmp->nested))
55626+ return PTR_ERR(o_tmp->nested);
55627+
55628+ /* insert into nested subject list if we haven't copied this one yet
55629+ to prevent duplicate entries */
55630+ if (!already_copied) {
55631+ o_tmp->nested->next = role->hash->first;
55632+ role->hash->first = o_tmp->nested;
55633+ }
55634+ }
55635+ }
55636+
55637+ return 0;
55638+}
55639+
55640+static __u32
55641+count_user_subjs(struct acl_subject_label *userp)
55642+{
55643+ struct acl_subject_label s_tmp;
55644+ __u32 num = 0;
55645+
55646+ while (userp) {
55647+ if (copy_from_user(&s_tmp, userp,
55648+ sizeof (struct acl_subject_label)))
55649+ break;
55650+
55651+ userp = s_tmp.prev;
55652+ }
55653+
55654+ return num;
55655+}
55656+
55657+static int
55658+copy_user_allowedips(struct acl_role_label *rolep)
55659+{
55660+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
55661+
55662+ ruserip = rolep->allowed_ips;
55663+
55664+ while (ruserip) {
55665+ rlast = rtmp;
55666+
55667+ if ((rtmp = (struct role_allowed_ip *)
55668+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
55669+ return -ENOMEM;
55670+
55671+ if (copy_from_user(rtmp, ruserip,
55672+ sizeof (struct role_allowed_ip)))
55673+ return -EFAULT;
55674+
55675+ ruserip = rtmp->prev;
55676+
55677+ if (!rlast) {
55678+ rtmp->prev = NULL;
55679+ rolep->allowed_ips = rtmp;
55680+ } else {
55681+ rlast->next = rtmp;
55682+ rtmp->prev = rlast;
55683+ }
55684+
55685+ if (!ruserip)
55686+ rtmp->next = NULL;
55687+ }
55688+
55689+ return 0;
55690+}
55691+
55692+static int
55693+copy_user_transitions(struct acl_role_label *rolep)
55694+{
55695+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
55696+
55697+ unsigned int len;
55698+ char *tmp;
55699+
55700+ rusertp = rolep->transitions;
55701+
55702+ while (rusertp) {
55703+ rlast = rtmp;
55704+
55705+ if ((rtmp = (struct role_transition *)
55706+ acl_alloc(sizeof (struct role_transition))) == NULL)
55707+ return -ENOMEM;
55708+
55709+ if (copy_from_user(rtmp, rusertp,
55710+ sizeof (struct role_transition)))
55711+ return -EFAULT;
55712+
55713+ rusertp = rtmp->prev;
55714+
55715+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
55716+
55717+ if (!len || len >= GR_SPROLE_LEN)
55718+ return -EINVAL;
55719+
55720+ if ((tmp = (char *) acl_alloc(len)) == NULL)
55721+ return -ENOMEM;
55722+
55723+ if (copy_from_user(tmp, rtmp->rolename, len))
55724+ return -EFAULT;
55725+ tmp[len-1] = '\0';
55726+ rtmp->rolename = tmp;
55727+
55728+ if (!rlast) {
55729+ rtmp->prev = NULL;
55730+ rolep->transitions = rtmp;
55731+ } else {
55732+ rlast->next = rtmp;
55733+ rtmp->prev = rlast;
55734+ }
55735+
55736+ if (!rusertp)
55737+ rtmp->next = NULL;
55738+ }
55739+
55740+ return 0;
55741+}
55742+
55743+static struct acl_subject_label *
55744+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
55745+{
55746+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
55747+ unsigned int len;
55748+ char *tmp;
55749+ __u32 num_objs;
55750+ struct acl_ip_label **i_tmp, *i_utmp2;
55751+ struct gr_hash_struct ghash;
55752+ struct subject_map *subjmap;
55753+ unsigned int i_num;
55754+ int err;
55755+
55756+ if (already_copied != NULL)
55757+ *already_copied = 0;
55758+
55759+ s_tmp = lookup_subject_map(userp);
55760+
55761+ /* we've already copied this subject into the kernel, just return
55762+ the reference to it, and don't copy it over again
55763+ */
55764+ if (s_tmp) {
55765+ if (already_copied != NULL)
55766+ *already_copied = 1;
55767+ return(s_tmp);
55768+ }
55769+
55770+ if ((s_tmp = (struct acl_subject_label *)
55771+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
55772+ return ERR_PTR(-ENOMEM);
55773+
55774+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
55775+ if (subjmap == NULL)
55776+ return ERR_PTR(-ENOMEM);
55777+
55778+ subjmap->user = userp;
55779+ subjmap->kernel = s_tmp;
55780+ insert_subj_map_entry(subjmap);
55781+
55782+ if (copy_from_user(s_tmp, userp,
55783+ sizeof (struct acl_subject_label)))
55784+ return ERR_PTR(-EFAULT);
55785+
55786+ len = strnlen_user(s_tmp->filename, PATH_MAX);
55787+
55788+ if (!len || len >= PATH_MAX)
55789+ return ERR_PTR(-EINVAL);
55790+
55791+ if ((tmp = (char *) acl_alloc(len)) == NULL)
55792+ return ERR_PTR(-ENOMEM);
55793+
55794+ if (copy_from_user(tmp, s_tmp->filename, len))
55795+ return ERR_PTR(-EFAULT);
55796+ tmp[len-1] = '\0';
55797+ s_tmp->filename = tmp;
55798+
55799+ if (!strcmp(s_tmp->filename, "/"))
55800+ role->root_label = s_tmp;
55801+
55802+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
55803+ return ERR_PTR(-EFAULT);
55804+
55805+ /* copy user and group transition tables */
55806+
55807+ if (s_tmp->user_trans_num) {
55808+ uid_t *uidlist;
55809+
55810+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
55811+ if (uidlist == NULL)
55812+ return ERR_PTR(-ENOMEM);
55813+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
55814+ return ERR_PTR(-EFAULT);
55815+
55816+ s_tmp->user_transitions = uidlist;
55817+ }
55818+
55819+ if (s_tmp->group_trans_num) {
55820+ gid_t *gidlist;
55821+
55822+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
55823+ if (gidlist == NULL)
55824+ return ERR_PTR(-ENOMEM);
55825+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
55826+ return ERR_PTR(-EFAULT);
55827+
55828+ s_tmp->group_transitions = gidlist;
55829+ }
55830+
55831+ /* set up object hash table */
55832+ num_objs = count_user_objs(ghash.first);
55833+
55834+ s_tmp->obj_hash_size = num_objs;
55835+ s_tmp->obj_hash =
55836+ (struct acl_object_label **)
55837+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
55838+
55839+ if (!s_tmp->obj_hash)
55840+ return ERR_PTR(-ENOMEM);
55841+
55842+ memset(s_tmp->obj_hash, 0,
55843+ s_tmp->obj_hash_size *
55844+ sizeof (struct acl_object_label *));
55845+
55846+ /* add in objects */
55847+ err = copy_user_objs(ghash.first, s_tmp, role);
55848+
55849+ if (err)
55850+ return ERR_PTR(err);
55851+
55852+ /* set pointer for parent subject */
55853+ if (s_tmp->parent_subject) {
55854+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
55855+
55856+ if (IS_ERR(s_tmp2))
55857+ return s_tmp2;
55858+
55859+ s_tmp->parent_subject = s_tmp2;
55860+ }
55861+
55862+ /* add in ip acls */
55863+
55864+ if (!s_tmp->ip_num) {
55865+ s_tmp->ips = NULL;
55866+ goto insert;
55867+ }
55868+
55869+ i_tmp =
55870+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
55871+ sizeof (struct acl_ip_label *));
55872+
55873+ if (!i_tmp)
55874+ return ERR_PTR(-ENOMEM);
55875+
55876+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
55877+ *(i_tmp + i_num) =
55878+ (struct acl_ip_label *)
55879+ acl_alloc(sizeof (struct acl_ip_label));
55880+ if (!*(i_tmp + i_num))
55881+ return ERR_PTR(-ENOMEM);
55882+
55883+ if (copy_from_user
55884+ (&i_utmp2, s_tmp->ips + i_num,
55885+ sizeof (struct acl_ip_label *)))
55886+ return ERR_PTR(-EFAULT);
55887+
55888+ if (copy_from_user
55889+ (*(i_tmp + i_num), i_utmp2,
55890+ sizeof (struct acl_ip_label)))
55891+ return ERR_PTR(-EFAULT);
55892+
55893+ if ((*(i_tmp + i_num))->iface == NULL)
55894+ continue;
55895+
55896+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
55897+ if (!len || len >= IFNAMSIZ)
55898+ return ERR_PTR(-EINVAL);
55899+ tmp = acl_alloc(len);
55900+ if (tmp == NULL)
55901+ return ERR_PTR(-ENOMEM);
55902+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
55903+ return ERR_PTR(-EFAULT);
55904+ (*(i_tmp + i_num))->iface = tmp;
55905+ }
55906+
55907+ s_tmp->ips = i_tmp;
55908+
55909+insert:
55910+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
55911+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
55912+ return ERR_PTR(-ENOMEM);
55913+
55914+ return s_tmp;
55915+}
55916+
55917+static int
55918+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
55919+{
55920+ struct acl_subject_label s_pre;
55921+ struct acl_subject_label * ret;
55922+ int err;
55923+
55924+ while (userp) {
55925+ if (copy_from_user(&s_pre, userp,
55926+ sizeof (struct acl_subject_label)))
55927+ return -EFAULT;
55928+
55929+ ret = do_copy_user_subj(userp, role, NULL);
55930+
55931+ err = PTR_ERR(ret);
55932+ if (IS_ERR(ret))
55933+ return err;
55934+
55935+ insert_acl_subj_label(ret, role);
55936+
55937+ userp = s_pre.prev;
55938+ }
55939+
55940+ return 0;
55941+}
55942+
55943+static int
55944+copy_user_acl(struct gr_arg *arg)
55945+{
55946+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
55947+ struct acl_subject_label *subj_list;
55948+ struct sprole_pw *sptmp;
55949+ struct gr_hash_struct *ghash;
55950+ uid_t *domainlist;
55951+ unsigned int r_num;
55952+ unsigned int len;
55953+ char *tmp;
55954+ int err = 0;
55955+ __u16 i;
55956+ __u32 num_subjs;
55957+
55958+ /* we need a default and kernel role */
55959+ if (arg->role_db.num_roles < 2)
55960+ return -EINVAL;
55961+
55962+ /* copy special role authentication info from userspace */
55963+
55964+ num_sprole_pws = arg->num_sprole_pws;
55965+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
55966+
55967+ if (!acl_special_roles && num_sprole_pws)
55968+ return -ENOMEM;
55969+
55970+ for (i = 0; i < num_sprole_pws; i++) {
55971+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
55972+ if (!sptmp)
55973+ return -ENOMEM;
55974+ if (copy_from_user(sptmp, arg->sprole_pws + i,
55975+ sizeof (struct sprole_pw)))
55976+ return -EFAULT;
55977+
55978+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
55979+
55980+ if (!len || len >= GR_SPROLE_LEN)
55981+ return -EINVAL;
55982+
55983+ if ((tmp = (char *) acl_alloc(len)) == NULL)
55984+ return -ENOMEM;
55985+
55986+ if (copy_from_user(tmp, sptmp->rolename, len))
55987+ return -EFAULT;
55988+
55989+ tmp[len-1] = '\0';
55990+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55991+ printk(KERN_ALERT "Copying special role %s\n", tmp);
55992+#endif
55993+ sptmp->rolename = tmp;
55994+ acl_special_roles[i] = sptmp;
55995+ }
55996+
55997+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
55998+
55999+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
56000+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
56001+
56002+ if (!r_tmp)
56003+ return -ENOMEM;
56004+
56005+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
56006+ sizeof (struct acl_role_label *)))
56007+ return -EFAULT;
56008+
56009+ if (copy_from_user(r_tmp, r_utmp2,
56010+ sizeof (struct acl_role_label)))
56011+ return -EFAULT;
56012+
56013+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
56014+
56015+ if (!len || len >= PATH_MAX)
56016+ return -EINVAL;
56017+
56018+ if ((tmp = (char *) acl_alloc(len)) == NULL)
56019+ return -ENOMEM;
56020+
56021+ if (copy_from_user(tmp, r_tmp->rolename, len))
56022+ return -EFAULT;
56023+
56024+ tmp[len-1] = '\0';
56025+ r_tmp->rolename = tmp;
56026+
56027+ if (!strcmp(r_tmp->rolename, "default")
56028+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
56029+ default_role = r_tmp;
56030+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
56031+ kernel_role = r_tmp;
56032+ }
56033+
56034+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
56035+ return -ENOMEM;
56036+
56037+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
56038+ return -EFAULT;
56039+
56040+ r_tmp->hash = ghash;
56041+
56042+ num_subjs = count_user_subjs(r_tmp->hash->first);
56043+
56044+ r_tmp->subj_hash_size = num_subjs;
56045+ r_tmp->subj_hash =
56046+ (struct acl_subject_label **)
56047+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
56048+
56049+ if (!r_tmp->subj_hash)
56050+ return -ENOMEM;
56051+
56052+ err = copy_user_allowedips(r_tmp);
56053+ if (err)
56054+ return err;
56055+
56056+ /* copy domain info */
56057+ if (r_tmp->domain_children != NULL) {
56058+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
56059+ if (domainlist == NULL)
56060+ return -ENOMEM;
56061+
56062+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
56063+ return -EFAULT;
56064+
56065+ r_tmp->domain_children = domainlist;
56066+ }
56067+
56068+ err = copy_user_transitions(r_tmp);
56069+ if (err)
56070+ return err;
56071+
56072+ memset(r_tmp->subj_hash, 0,
56073+ r_tmp->subj_hash_size *
56074+ sizeof (struct acl_subject_label *));
56075+
56076+ /* acquire the list of subjects, then NULL out
56077+ the list prior to parsing the subjects for this role,
56078+ as during this parsing the list is replaced with a list
56079+ of *nested* subjects for the role
56080+ */
56081+ subj_list = r_tmp->hash->first;
56082+
56083+ /* set nested subject list to null */
56084+ r_tmp->hash->first = NULL;
56085+
56086+ err = copy_user_subjs(subj_list, r_tmp);
56087+
56088+ if (err)
56089+ return err;
56090+
56091+ insert_acl_role_label(r_tmp);
56092+ }
56093+
56094+ if (default_role == NULL || kernel_role == NULL)
56095+ return -EINVAL;
56096+
56097+ return err;
56098+}
56099+
56100+static int
56101+gracl_init(struct gr_arg *args)
56102+{
56103+ int error = 0;
56104+
56105+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
56106+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
56107+
56108+ if (init_variables(args)) {
56109+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
56110+ error = -ENOMEM;
56111+ free_variables();
56112+ goto out;
56113+ }
56114+
56115+ error = copy_user_acl(args);
56116+ free_init_variables();
56117+ if (error) {
56118+ free_variables();
56119+ goto out;
56120+ }
56121+
56122+ if ((error = gr_set_acls(0))) {
56123+ free_variables();
56124+ goto out;
56125+ }
56126+
56127+ pax_open_kernel();
56128+ gr_status |= GR_READY;
56129+ pax_close_kernel();
56130+
56131+ out:
56132+ return error;
56133+}
56134+
56135+/* derived from glibc fnmatch() 0: match, 1: no match*/
56136+
56137+static int
56138+glob_match(const char *p, const char *n)
56139+{
56140+ char c;
56141+
56142+ while ((c = *p++) != '\0') {
56143+ switch (c) {
56144+ case '?':
56145+ if (*n == '\0')
56146+ return 1;
56147+ else if (*n == '/')
56148+ return 1;
56149+ break;
56150+ case '\\':
56151+ if (*n != c)
56152+ return 1;
56153+ break;
56154+ case '*':
56155+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
56156+ if (*n == '/')
56157+ return 1;
56158+ else if (c == '?') {
56159+ if (*n == '\0')
56160+ return 1;
56161+ else
56162+ ++n;
56163+ }
56164+ }
56165+ if (c == '\0') {
56166+ return 0;
56167+ } else {
56168+ const char *endp;
56169+
56170+ if ((endp = strchr(n, '/')) == NULL)
56171+ endp = n + strlen(n);
56172+
56173+ if (c == '[') {
56174+ for (--p; n < endp; ++n)
56175+ if (!glob_match(p, n))
56176+ return 0;
56177+ } else if (c == '/') {
56178+ while (*n != '\0' && *n != '/')
56179+ ++n;
56180+ if (*n == '/' && !glob_match(p, n + 1))
56181+ return 0;
56182+ } else {
56183+ for (--p; n < endp; ++n)
56184+ if (*n == c && !glob_match(p, n))
56185+ return 0;
56186+ }
56187+
56188+ return 1;
56189+ }
56190+ case '[':
56191+ {
56192+ int not;
56193+ char cold;
56194+
56195+ if (*n == '\0' || *n == '/')
56196+ return 1;
56197+
56198+ not = (*p == '!' || *p == '^');
56199+ if (not)
56200+ ++p;
56201+
56202+ c = *p++;
56203+ for (;;) {
56204+ unsigned char fn = (unsigned char)*n;
56205+
56206+ if (c == '\0')
56207+ return 1;
56208+ else {
56209+ if (c == fn)
56210+ goto matched;
56211+ cold = c;
56212+ c = *p++;
56213+
56214+ if (c == '-' && *p != ']') {
56215+ unsigned char cend = *p++;
56216+
56217+ if (cend == '\0')
56218+ return 1;
56219+
56220+ if (cold <= fn && fn <= cend)
56221+ goto matched;
56222+
56223+ c = *p++;
56224+ }
56225+ }
56226+
56227+ if (c == ']')
56228+ break;
56229+ }
56230+ if (!not)
56231+ return 1;
56232+ break;
56233+ matched:
56234+ while (c != ']') {
56235+ if (c == '\0')
56236+ return 1;
56237+
56238+ c = *p++;
56239+ }
56240+ if (not)
56241+ return 1;
56242+ }
56243+ break;
56244+ default:
56245+ if (c != *n)
56246+ return 1;
56247+ }
56248+
56249+ ++n;
56250+ }
56251+
56252+ if (*n == '\0')
56253+ return 0;
56254+
56255+ if (*n == '/')
56256+ return 0;
56257+
56258+ return 1;
56259+}
56260+
56261+static struct acl_object_label *
56262+chk_glob_label(struct acl_object_label *globbed,
56263+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
56264+{
56265+ struct acl_object_label *tmp;
56266+
56267+ if (*path == NULL)
56268+ *path = gr_to_filename_nolock(dentry, mnt);
56269+
56270+ tmp = globbed;
56271+
56272+ while (tmp) {
56273+ if (!glob_match(tmp->filename, *path))
56274+ return tmp;
56275+ tmp = tmp->next;
56276+ }
56277+
56278+ return NULL;
56279+}
56280+
56281+static struct acl_object_label *
56282+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
56283+ const ino_t curr_ino, const dev_t curr_dev,
56284+ const struct acl_subject_label *subj, char **path, const int checkglob)
56285+{
56286+ struct acl_subject_label *tmpsubj;
56287+ struct acl_object_label *retval;
56288+ struct acl_object_label *retval2;
56289+
56290+ tmpsubj = (struct acl_subject_label *) subj;
56291+ read_lock(&gr_inode_lock);
56292+ do {
56293+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
56294+ if (retval) {
56295+ if (checkglob && retval->globbed) {
56296+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
56297+ if (retval2)
56298+ retval = retval2;
56299+ }
56300+ break;
56301+ }
56302+ } while ((tmpsubj = tmpsubj->parent_subject));
56303+ read_unlock(&gr_inode_lock);
56304+
56305+ return retval;
56306+}
56307+
56308+static __inline__ struct acl_object_label *
56309+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
56310+ struct dentry *curr_dentry,
56311+ const struct acl_subject_label *subj, char **path, const int checkglob)
56312+{
56313+ int newglob = checkglob;
56314+ ino_t inode;
56315+ dev_t device;
56316+
56317+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
56318+ as we don't want a / * rule to match instead of the / object
56319+ don't do this for create lookups that call this function though, since they're looking up
56320+ on the parent and thus need globbing checks on all paths
56321+ */
56322+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
56323+ newglob = GR_NO_GLOB;
56324+
56325+ spin_lock(&curr_dentry->d_lock);
56326+ inode = curr_dentry->d_inode->i_ino;
56327+ device = __get_dev(curr_dentry);
56328+ spin_unlock(&curr_dentry->d_lock);
56329+
56330+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
56331+}
56332+
56333+#ifdef CONFIG_HUGETLBFS
56334+static inline bool
56335+is_hugetlbfs_mnt(const struct vfsmount *mnt)
56336+{
56337+ int i;
56338+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
56339+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
56340+ return true;
56341+ }
56342+
56343+ return false;
56344+}
56345+#endif
56346+
56347+static struct acl_object_label *
56348+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56349+ const struct acl_subject_label *subj, char *path, const int checkglob)
56350+{
56351+ struct dentry *dentry = (struct dentry *) l_dentry;
56352+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
56353+ struct mount *real_mnt = real_mount(mnt);
56354+ struct acl_object_label *retval;
56355+ struct dentry *parent;
56356+
56357+ write_seqlock(&rename_lock);
56358+ br_read_lock(&vfsmount_lock);
56359+
56360+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
56361+#ifdef CONFIG_NET
56362+ mnt == sock_mnt ||
56363+#endif
56364+#ifdef CONFIG_HUGETLBFS
56365+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
56366+#endif
56367+ /* ignore Eric Biederman */
56368+ IS_PRIVATE(l_dentry->d_inode))) {
56369+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
56370+ goto out;
56371+ }
56372+
56373+ for (;;) {
56374+ if (dentry == real_root.dentry && mnt == real_root.mnt)
56375+ break;
56376+
56377+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
56378+ if (!mnt_has_parent(real_mnt))
56379+ break;
56380+
56381+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
56382+ if (retval != NULL)
56383+ goto out;
56384+
56385+ dentry = real_mnt->mnt_mountpoint;
56386+ real_mnt = real_mnt->mnt_parent;
56387+ mnt = &real_mnt->mnt;
56388+ continue;
56389+ }
56390+
56391+ parent = dentry->d_parent;
56392+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
56393+ if (retval != NULL)
56394+ goto out;
56395+
56396+ dentry = parent;
56397+ }
56398+
56399+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
56400+
56401+ /* real_root is pinned so we don't have to hold a reference */
56402+ if (retval == NULL)
56403+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
56404+out:
56405+ br_read_unlock(&vfsmount_lock);
56406+ write_sequnlock(&rename_lock);
56407+
56408+ BUG_ON(retval == NULL);
56409+
56410+ return retval;
56411+}
56412+
56413+static __inline__ struct acl_object_label *
56414+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56415+ const struct acl_subject_label *subj)
56416+{
56417+ char *path = NULL;
56418+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
56419+}
56420+
56421+static __inline__ struct acl_object_label *
56422+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56423+ const struct acl_subject_label *subj)
56424+{
56425+ char *path = NULL;
56426+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
56427+}
56428+
56429+static __inline__ struct acl_object_label *
56430+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56431+ const struct acl_subject_label *subj, char *path)
56432+{
56433+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
56434+}
56435+
56436+static struct acl_subject_label *
56437+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56438+ const struct acl_role_label *role)
56439+{
56440+ struct dentry *dentry = (struct dentry *) l_dentry;
56441+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
56442+ struct mount *real_mnt = real_mount(mnt);
56443+ struct acl_subject_label *retval;
56444+ struct dentry *parent;
56445+
56446+ write_seqlock(&rename_lock);
56447+ br_read_lock(&vfsmount_lock);
56448+
56449+ for (;;) {
56450+ if (dentry == real_root.dentry && mnt == real_root.mnt)
56451+ break;
56452+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
56453+ if (!mnt_has_parent(real_mnt))
56454+ break;
56455+
56456+ spin_lock(&dentry->d_lock);
56457+ read_lock(&gr_inode_lock);
56458+ retval =
56459+ lookup_acl_subj_label(dentry->d_inode->i_ino,
56460+ __get_dev(dentry), role);
56461+ read_unlock(&gr_inode_lock);
56462+ spin_unlock(&dentry->d_lock);
56463+ if (retval != NULL)
56464+ goto out;
56465+
56466+ dentry = real_mnt->mnt_mountpoint;
56467+ real_mnt = real_mnt->mnt_parent;
56468+ mnt = &real_mnt->mnt;
56469+ continue;
56470+ }
56471+
56472+ spin_lock(&dentry->d_lock);
56473+ read_lock(&gr_inode_lock);
56474+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
56475+ __get_dev(dentry), role);
56476+ read_unlock(&gr_inode_lock);
56477+ parent = dentry->d_parent;
56478+ spin_unlock(&dentry->d_lock);
56479+
56480+ if (retval != NULL)
56481+ goto out;
56482+
56483+ dentry = parent;
56484+ }
56485+
56486+ spin_lock(&dentry->d_lock);
56487+ read_lock(&gr_inode_lock);
56488+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
56489+ __get_dev(dentry), role);
56490+ read_unlock(&gr_inode_lock);
56491+ spin_unlock(&dentry->d_lock);
56492+
56493+ if (unlikely(retval == NULL)) {
56494+ /* real_root is pinned, we don't need to hold a reference */
56495+ read_lock(&gr_inode_lock);
56496+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
56497+ __get_dev(real_root.dentry), role);
56498+ read_unlock(&gr_inode_lock);
56499+ }
56500+out:
56501+ br_read_unlock(&vfsmount_lock);
56502+ write_sequnlock(&rename_lock);
56503+
56504+ BUG_ON(retval == NULL);
56505+
56506+ return retval;
56507+}
56508+
56509+static void
56510+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
56511+{
56512+ struct task_struct *task = current;
56513+ const struct cred *cred = current_cred();
56514+
56515+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
56516+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
56517+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
56518+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
56519+
56520+ return;
56521+}
56522+
56523+static void
56524+gr_log_learn_id_change(const char type, const unsigned int real,
56525+ const unsigned int effective, const unsigned int fs)
56526+{
56527+ struct task_struct *task = current;
56528+ const struct cred *cred = current_cred();
56529+
56530+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
56531+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
56532+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
56533+ type, real, effective, fs, &task->signal->saved_ip);
56534+
56535+ return;
56536+}
56537+
56538+__u32
56539+gr_search_file(const struct dentry * dentry, const __u32 mode,
56540+ const struct vfsmount * mnt)
56541+{
56542+ __u32 retval = mode;
56543+ struct acl_subject_label *curracl;
56544+ struct acl_object_label *currobj;
56545+
56546+ if (unlikely(!(gr_status & GR_READY)))
56547+ return (mode & ~GR_AUDITS);
56548+
56549+ curracl = current->acl;
56550+
56551+ currobj = chk_obj_label(dentry, mnt, curracl);
56552+ retval = currobj->mode & mode;
56553+
56554+ /* if we're opening a specified transfer file for writing
56555+ (e.g. /dev/initctl), then transfer our role to init
56556+ */
56557+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
56558+ current->role->roletype & GR_ROLE_PERSIST)) {
56559+ struct task_struct *task = init_pid_ns.child_reaper;
56560+
56561+ if (task->role != current->role) {
56562+ task->acl_sp_role = 0;
56563+ task->acl_role_id = current->acl_role_id;
56564+ task->role = current->role;
56565+ rcu_read_lock();
56566+ read_lock(&grsec_exec_file_lock);
56567+ gr_apply_subject_to_task(task);
56568+ read_unlock(&grsec_exec_file_lock);
56569+ rcu_read_unlock();
56570+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
56571+ }
56572+ }
56573+
56574+ if (unlikely
56575+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
56576+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
56577+ __u32 new_mode = mode;
56578+
56579+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
56580+
56581+ retval = new_mode;
56582+
56583+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
56584+ new_mode |= GR_INHERIT;
56585+
56586+ if (!(mode & GR_NOLEARN))
56587+ gr_log_learn(dentry, mnt, new_mode);
56588+ }
56589+
56590+ return retval;
56591+}
56592+
56593+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
56594+ const struct dentry *parent,
56595+ const struct vfsmount *mnt)
56596+{
56597+ struct name_entry *match;
56598+ struct acl_object_label *matchpo;
56599+ struct acl_subject_label *curracl;
56600+ char *path;
56601+
56602+ if (unlikely(!(gr_status & GR_READY)))
56603+ return NULL;
56604+
56605+ preempt_disable();
56606+ path = gr_to_filename_rbac(new_dentry, mnt);
56607+ match = lookup_name_entry_create(path);
56608+
56609+ curracl = current->acl;
56610+
56611+ if (match) {
56612+ read_lock(&gr_inode_lock);
56613+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
56614+ read_unlock(&gr_inode_lock);
56615+
56616+ if (matchpo) {
56617+ preempt_enable();
56618+ return matchpo;
56619+ }
56620+ }
56621+
56622+ // lookup parent
56623+
56624+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
56625+
56626+ preempt_enable();
56627+ return matchpo;
56628+}
56629+
56630+__u32
56631+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
56632+ const struct vfsmount * mnt, const __u32 mode)
56633+{
56634+ struct acl_object_label *matchpo;
56635+ __u32 retval;
56636+
56637+ if (unlikely(!(gr_status & GR_READY)))
56638+ return (mode & ~GR_AUDITS);
56639+
56640+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
56641+
56642+ retval = matchpo->mode & mode;
56643+
56644+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
56645+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
56646+ __u32 new_mode = mode;
56647+
56648+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
56649+
56650+ gr_log_learn(new_dentry, mnt, new_mode);
56651+ return new_mode;
56652+ }
56653+
56654+ return retval;
56655+}
56656+
56657+__u32
56658+gr_check_link(const struct dentry * new_dentry,
56659+ const struct dentry * parent_dentry,
56660+ const struct vfsmount * parent_mnt,
56661+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
56662+{
56663+ struct acl_object_label *obj;
56664+ __u32 oldmode, newmode;
56665+ __u32 needmode;
56666+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
56667+ GR_DELETE | GR_INHERIT;
56668+
56669+ if (unlikely(!(gr_status & GR_READY)))
56670+ return (GR_CREATE | GR_LINK);
56671+
56672+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
56673+ oldmode = obj->mode;
56674+
56675+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
56676+ newmode = obj->mode;
56677+
56678+ needmode = newmode & checkmodes;
56679+
56680+ // old name for hardlink must have at least the permissions of the new name
56681+ if ((oldmode & needmode) != needmode)
56682+ goto bad;
56683+
56684+ // if old name had restrictions/auditing, make sure the new name does as well
56685+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
56686+
56687+ // don't allow hardlinking of suid/sgid/fcapped files without permission
56688+ if (is_privileged_binary(old_dentry))
56689+ needmode |= GR_SETID;
56690+
56691+ if ((newmode & needmode) != needmode)
56692+ goto bad;
56693+
56694+ // enforce minimum permissions
56695+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
56696+ return newmode;
56697+bad:
56698+ needmode = oldmode;
56699+ if (is_privileged_binary(old_dentry))
56700+ needmode |= GR_SETID;
56701+
56702+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
56703+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
56704+ return (GR_CREATE | GR_LINK);
56705+ } else if (newmode & GR_SUPPRESS)
56706+ return GR_SUPPRESS;
56707+ else
56708+ return 0;
56709+}
56710+
56711+int
56712+gr_check_hidden_task(const struct task_struct *task)
56713+{
56714+ if (unlikely(!(gr_status & GR_READY)))
56715+ return 0;
56716+
56717+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
56718+ return 1;
56719+
56720+ return 0;
56721+}
56722+
56723+int
56724+gr_check_protected_task(const struct task_struct *task)
56725+{
56726+ if (unlikely(!(gr_status & GR_READY) || !task))
56727+ return 0;
56728+
56729+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
56730+ task->acl != current->acl)
56731+ return 1;
56732+
56733+ return 0;
56734+}
56735+
56736+int
56737+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
56738+{
56739+ struct task_struct *p;
56740+ int ret = 0;
56741+
56742+ if (unlikely(!(gr_status & GR_READY) || !pid))
56743+ return ret;
56744+
56745+ read_lock(&tasklist_lock);
56746+ do_each_pid_task(pid, type, p) {
56747+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
56748+ p->acl != current->acl) {
56749+ ret = 1;
56750+ goto out;
56751+ }
56752+ } while_each_pid_task(pid, type, p);
56753+out:
56754+ read_unlock(&tasklist_lock);
56755+
56756+ return ret;
56757+}
56758+
56759+void
56760+gr_copy_label(struct task_struct *tsk)
56761+{
56762+ tsk->signal->used_accept = 0;
56763+ tsk->acl_sp_role = 0;
56764+ tsk->acl_role_id = current->acl_role_id;
56765+ tsk->acl = current->acl;
56766+ tsk->role = current->role;
56767+ tsk->signal->curr_ip = current->signal->curr_ip;
56768+ tsk->signal->saved_ip = current->signal->saved_ip;
56769+ if (current->exec_file)
56770+ get_file(current->exec_file);
56771+ tsk->exec_file = current->exec_file;
56772+ tsk->is_writable = current->is_writable;
56773+ if (unlikely(current->signal->used_accept)) {
56774+ current->signal->curr_ip = 0;
56775+ current->signal->saved_ip = 0;
56776+ }
56777+
56778+ return;
56779+}
56780+
56781+static void
56782+gr_set_proc_res(struct task_struct *task)
56783+{
56784+ struct acl_subject_label *proc;
56785+ unsigned short i;
56786+
56787+ proc = task->acl;
56788+
56789+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
56790+ return;
56791+
56792+ for (i = 0; i < RLIM_NLIMITS; i++) {
56793+ if (!(proc->resmask & (1 << i)))
56794+ continue;
56795+
56796+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
56797+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
56798+ }
56799+
56800+ return;
56801+}
56802+
56803+extern int __gr_process_user_ban(struct user_struct *user);
56804+
56805+int
56806+gr_check_user_change(int real, int effective, int fs)
56807+{
56808+ unsigned int i;
56809+ __u16 num;
56810+ uid_t *uidlist;
56811+ int curuid;
56812+ int realok = 0;
56813+ int effectiveok = 0;
56814+ int fsok = 0;
56815+
56816+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
56817+ struct user_struct *user;
56818+
56819+ if (real == -1)
56820+ goto skipit;
56821+
56822+ user = find_user(real);
56823+ if (user == NULL)
56824+ goto skipit;
56825+
56826+ if (__gr_process_user_ban(user)) {
56827+ /* for find_user */
56828+ free_uid(user);
56829+ return 1;
56830+ }
56831+
56832+ /* for find_user */
56833+ free_uid(user);
56834+
56835+skipit:
56836+#endif
56837+
56838+ if (unlikely(!(gr_status & GR_READY)))
56839+ return 0;
56840+
56841+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
56842+ gr_log_learn_id_change('u', real, effective, fs);
56843+
56844+ num = current->acl->user_trans_num;
56845+ uidlist = current->acl->user_transitions;
56846+
56847+ if (uidlist == NULL)
56848+ return 0;
56849+
56850+ if (real == -1)
56851+ realok = 1;
56852+ if (effective == -1)
56853+ effectiveok = 1;
56854+ if (fs == -1)
56855+ fsok = 1;
56856+
56857+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
56858+ for (i = 0; i < num; i++) {
56859+ curuid = (int)uidlist[i];
56860+ if (real == curuid)
56861+ realok = 1;
56862+ if (effective == curuid)
56863+ effectiveok = 1;
56864+ if (fs == curuid)
56865+ fsok = 1;
56866+ }
56867+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
56868+ for (i = 0; i < num; i++) {
56869+ curuid = (int)uidlist[i];
56870+ if (real == curuid)
56871+ break;
56872+ if (effective == curuid)
56873+ break;
56874+ if (fs == curuid)
56875+ break;
56876+ }
56877+ /* not in deny list */
56878+ if (i == num) {
56879+ realok = 1;
56880+ effectiveok = 1;
56881+ fsok = 1;
56882+ }
56883+ }
56884+
56885+ if (realok && effectiveok && fsok)
56886+ return 0;
56887+ else {
56888+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
56889+ return 1;
56890+ }
56891+}
56892+
56893+int
56894+gr_check_group_change(int real, int effective, int fs)
56895+{
56896+ unsigned int i;
56897+ __u16 num;
56898+ gid_t *gidlist;
56899+ int curgid;
56900+ int realok = 0;
56901+ int effectiveok = 0;
56902+ int fsok = 0;
56903+
56904+ if (unlikely(!(gr_status & GR_READY)))
56905+ return 0;
56906+
56907+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
56908+ gr_log_learn_id_change('g', real, effective, fs);
56909+
56910+ num = current->acl->group_trans_num;
56911+ gidlist = current->acl->group_transitions;
56912+
56913+ if (gidlist == NULL)
56914+ return 0;
56915+
56916+ if (real == -1)
56917+ realok = 1;
56918+ if (effective == -1)
56919+ effectiveok = 1;
56920+ if (fs == -1)
56921+ fsok = 1;
56922+
56923+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
56924+ for (i = 0; i < num; i++) {
56925+ curgid = (int)gidlist[i];
56926+ if (real == curgid)
56927+ realok = 1;
56928+ if (effective == curgid)
56929+ effectiveok = 1;
56930+ if (fs == curgid)
56931+ fsok = 1;
56932+ }
56933+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
56934+ for (i = 0; i < num; i++) {
56935+ curgid = (int)gidlist[i];
56936+ if (real == curgid)
56937+ break;
56938+ if (effective == curgid)
56939+ break;
56940+ if (fs == curgid)
56941+ break;
56942+ }
56943+ /* not in deny list */
56944+ if (i == num) {
56945+ realok = 1;
56946+ effectiveok = 1;
56947+ fsok = 1;
56948+ }
56949+ }
56950+
56951+ if (realok && effectiveok && fsok)
56952+ return 0;
56953+ else {
56954+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
56955+ return 1;
56956+ }
56957+}
56958+
56959+extern int gr_acl_is_capable(const int cap);
56960+
56961+void
56962+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
56963+{
56964+ struct acl_role_label *role = task->role;
56965+ struct acl_subject_label *subj = NULL;
56966+ struct acl_object_label *obj;
56967+ struct file *filp;
56968+
56969+ if (unlikely(!(gr_status & GR_READY)))
56970+ return;
56971+
56972+ filp = task->exec_file;
56973+
56974+ /* kernel process, we'll give them the kernel role */
56975+ if (unlikely(!filp)) {
56976+ task->role = kernel_role;
56977+ task->acl = kernel_role->root_label;
56978+ return;
56979+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
56980+ role = lookup_acl_role_label(task, uid, gid);
56981+
56982+ /* don't change the role if we're not a privileged process */
56983+ if (role && task->role != role &&
56984+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
56985+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
56986+ return;
56987+
56988+ /* perform subject lookup in possibly new role
56989+ we can use this result below in the case where role == task->role
56990+ */
56991+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
56992+
56993+ /* if we changed uid/gid, but result in the same role
56994+ and are using inheritance, don't lose the inherited subject
56995+ if current subject is other than what normal lookup
56996+ would result in, we arrived via inheritance, don't
56997+ lose subject
56998+ */
56999+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
57000+ (subj == task->acl)))
57001+ task->acl = subj;
57002+
57003+ task->role = role;
57004+
57005+ task->is_writable = 0;
57006+
57007+ /* ignore additional mmap checks for processes that are writable
57008+ by the default ACL */
57009+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
57010+ if (unlikely(obj->mode & GR_WRITE))
57011+ task->is_writable = 1;
57012+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
57013+ if (unlikely(obj->mode & GR_WRITE))
57014+ task->is_writable = 1;
57015+
57016+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57017+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
57018+#endif
57019+
57020+ gr_set_proc_res(task);
57021+
57022+ return;
57023+}
57024+
57025+int
57026+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57027+ const int unsafe_flags)
57028+{
57029+ struct task_struct *task = current;
57030+ struct acl_subject_label *newacl;
57031+ struct acl_object_label *obj;
57032+ __u32 retmode;
57033+
57034+ if (unlikely(!(gr_status & GR_READY)))
57035+ return 0;
57036+
57037+ newacl = chk_subj_label(dentry, mnt, task->role);
57038+
57039+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
57040+ did an exec
57041+ */
57042+ rcu_read_lock();
57043+ read_lock(&tasklist_lock);
57044+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
57045+ (task->parent->acl->mode & GR_POVERRIDE))) {
57046+ read_unlock(&tasklist_lock);
57047+ rcu_read_unlock();
57048+ goto skip_check;
57049+ }
57050+ read_unlock(&tasklist_lock);
57051+ rcu_read_unlock();
57052+
57053+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
57054+ !(task->role->roletype & GR_ROLE_GOD) &&
57055+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
57056+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
57057+ if (unsafe_flags & LSM_UNSAFE_SHARE)
57058+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
57059+ else
57060+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
57061+ return -EACCES;
57062+ }
57063+
57064+skip_check:
57065+
57066+ obj = chk_obj_label(dentry, mnt, task->acl);
57067+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
57068+
57069+ if (!(task->acl->mode & GR_INHERITLEARN) &&
57070+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
57071+ if (obj->nested)
57072+ task->acl = obj->nested;
57073+ else
57074+ task->acl = newacl;
57075+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
57076+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
57077+
57078+ task->is_writable = 0;
57079+
57080+ /* ignore additional mmap checks for processes that are writable
57081+ by the default ACL */
57082+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
57083+ if (unlikely(obj->mode & GR_WRITE))
57084+ task->is_writable = 1;
57085+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
57086+ if (unlikely(obj->mode & GR_WRITE))
57087+ task->is_writable = 1;
57088+
57089+ gr_set_proc_res(task);
57090+
57091+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57092+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
57093+#endif
57094+ return 0;
57095+}
57096+
57097+/* always called with valid inodev ptr */
57098+static void
57099+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
57100+{
57101+ struct acl_object_label *matchpo;
57102+ struct acl_subject_label *matchps;
57103+ struct acl_subject_label *subj;
57104+ struct acl_role_label *role;
57105+ unsigned int x;
57106+
57107+ FOR_EACH_ROLE_START(role)
57108+ FOR_EACH_SUBJECT_START(role, subj, x)
57109+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
57110+ matchpo->mode |= GR_DELETED;
57111+ FOR_EACH_SUBJECT_END(subj,x)
57112+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
57113+ /* nested subjects aren't in the role's subj_hash table */
57114+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
57115+ matchpo->mode |= GR_DELETED;
57116+ FOR_EACH_NESTED_SUBJECT_END(subj)
57117+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
57118+ matchps->mode |= GR_DELETED;
57119+ FOR_EACH_ROLE_END(role)
57120+
57121+ inodev->nentry->deleted = 1;
57122+
57123+ return;
57124+}
57125+
57126+void
57127+gr_handle_delete(const ino_t ino, const dev_t dev)
57128+{
57129+ struct inodev_entry *inodev;
57130+
57131+ if (unlikely(!(gr_status & GR_READY)))
57132+ return;
57133+
57134+ write_lock(&gr_inode_lock);
57135+ inodev = lookup_inodev_entry(ino, dev);
57136+ if (inodev != NULL)
57137+ do_handle_delete(inodev, ino, dev);
57138+ write_unlock(&gr_inode_lock);
57139+
57140+ return;
57141+}
57142+
57143+static void
57144+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
57145+ const ino_t newinode, const dev_t newdevice,
57146+ struct acl_subject_label *subj)
57147+{
57148+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
57149+ struct acl_object_label *match;
57150+
57151+ match = subj->obj_hash[index];
57152+
57153+ while (match && (match->inode != oldinode ||
57154+ match->device != olddevice ||
57155+ !(match->mode & GR_DELETED)))
57156+ match = match->next;
57157+
57158+ if (match && (match->inode == oldinode)
57159+ && (match->device == olddevice)
57160+ && (match->mode & GR_DELETED)) {
57161+ if (match->prev == NULL) {
57162+ subj->obj_hash[index] = match->next;
57163+ if (match->next != NULL)
57164+ match->next->prev = NULL;
57165+ } else {
57166+ match->prev->next = match->next;
57167+ if (match->next != NULL)
57168+ match->next->prev = match->prev;
57169+ }
57170+ match->prev = NULL;
57171+ match->next = NULL;
57172+ match->inode = newinode;
57173+ match->device = newdevice;
57174+ match->mode &= ~GR_DELETED;
57175+
57176+ insert_acl_obj_label(match, subj);
57177+ }
57178+
57179+ return;
57180+}
57181+
57182+static void
57183+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
57184+ const ino_t newinode, const dev_t newdevice,
57185+ struct acl_role_label *role)
57186+{
57187+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
57188+ struct acl_subject_label *match;
57189+
57190+ match = role->subj_hash[index];
57191+
57192+ while (match && (match->inode != oldinode ||
57193+ match->device != olddevice ||
57194+ !(match->mode & GR_DELETED)))
57195+ match = match->next;
57196+
57197+ if (match && (match->inode == oldinode)
57198+ && (match->device == olddevice)
57199+ && (match->mode & GR_DELETED)) {
57200+ if (match->prev == NULL) {
57201+ role->subj_hash[index] = match->next;
57202+ if (match->next != NULL)
57203+ match->next->prev = NULL;
57204+ } else {
57205+ match->prev->next = match->next;
57206+ if (match->next != NULL)
57207+ match->next->prev = match->prev;
57208+ }
57209+ match->prev = NULL;
57210+ match->next = NULL;
57211+ match->inode = newinode;
57212+ match->device = newdevice;
57213+ match->mode &= ~GR_DELETED;
57214+
57215+ insert_acl_subj_label(match, role);
57216+ }
57217+
57218+ return;
57219+}
57220+
57221+static void
57222+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
57223+ const ino_t newinode, const dev_t newdevice)
57224+{
57225+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
57226+ struct inodev_entry *match;
57227+
57228+ match = inodev_set.i_hash[index];
57229+
57230+ while (match && (match->nentry->inode != oldinode ||
57231+ match->nentry->device != olddevice || !match->nentry->deleted))
57232+ match = match->next;
57233+
57234+ if (match && (match->nentry->inode == oldinode)
57235+ && (match->nentry->device == olddevice) &&
57236+ match->nentry->deleted) {
57237+ if (match->prev == NULL) {
57238+ inodev_set.i_hash[index] = match->next;
57239+ if (match->next != NULL)
57240+ match->next->prev = NULL;
57241+ } else {
57242+ match->prev->next = match->next;
57243+ if (match->next != NULL)
57244+ match->next->prev = match->prev;
57245+ }
57246+ match->prev = NULL;
57247+ match->next = NULL;
57248+ match->nentry->inode = newinode;
57249+ match->nentry->device = newdevice;
57250+ match->nentry->deleted = 0;
57251+
57252+ insert_inodev_entry(match);
57253+ }
57254+
57255+ return;
57256+}
57257+
57258+static void
57259+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
57260+{
57261+ struct acl_subject_label *subj;
57262+ struct acl_role_label *role;
57263+ unsigned int x;
57264+
57265+ FOR_EACH_ROLE_START(role)
57266+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
57267+
57268+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
57269+ if ((subj->inode == ino) && (subj->device == dev)) {
57270+ subj->inode = ino;
57271+ subj->device = dev;
57272+ }
57273+ /* nested subjects aren't in the role's subj_hash table */
57274+ update_acl_obj_label(matchn->inode, matchn->device,
57275+ ino, dev, subj);
57276+ FOR_EACH_NESTED_SUBJECT_END(subj)
57277+ FOR_EACH_SUBJECT_START(role, subj, x)
57278+ update_acl_obj_label(matchn->inode, matchn->device,
57279+ ino, dev, subj);
57280+ FOR_EACH_SUBJECT_END(subj,x)
57281+ FOR_EACH_ROLE_END(role)
57282+
57283+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
57284+
57285+ return;
57286+}
57287+
57288+static void
57289+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
57290+ const struct vfsmount *mnt)
57291+{
57292+ ino_t ino = dentry->d_inode->i_ino;
57293+ dev_t dev = __get_dev(dentry);
57294+
57295+ __do_handle_create(matchn, ino, dev);
57296+
57297+ return;
57298+}
57299+
57300+void
57301+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57302+{
57303+ struct name_entry *matchn;
57304+
57305+ if (unlikely(!(gr_status & GR_READY)))
57306+ return;
57307+
57308+ preempt_disable();
57309+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
57310+
57311+ if (unlikely((unsigned long)matchn)) {
57312+ write_lock(&gr_inode_lock);
57313+ do_handle_create(matchn, dentry, mnt);
57314+ write_unlock(&gr_inode_lock);
57315+ }
57316+ preempt_enable();
57317+
57318+ return;
57319+}
57320+
57321+void
57322+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57323+{
57324+ struct name_entry *matchn;
57325+
57326+ if (unlikely(!(gr_status & GR_READY)))
57327+ return;
57328+
57329+ preempt_disable();
57330+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
57331+
57332+ if (unlikely((unsigned long)matchn)) {
57333+ write_lock(&gr_inode_lock);
57334+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
57335+ write_unlock(&gr_inode_lock);
57336+ }
57337+ preempt_enable();
57338+
57339+ return;
57340+}
57341+
57342+void
57343+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57344+ struct dentry *old_dentry,
57345+ struct dentry *new_dentry,
57346+ struct vfsmount *mnt, const __u8 replace)
57347+{
57348+ struct name_entry *matchn;
57349+ struct inodev_entry *inodev;
57350+ struct inode *inode = new_dentry->d_inode;
57351+ ino_t old_ino = old_dentry->d_inode->i_ino;
57352+ dev_t old_dev = __get_dev(old_dentry);
57353+
57354+ /* vfs_rename swaps the name and parent link for old_dentry and
57355+ new_dentry
57356+ at this point, old_dentry has the new name, parent link, and inode
57357+ for the renamed file
57358+ if a file is being replaced by a rename, new_dentry has the inode
57359+ and name for the replaced file
57360+ */
57361+
57362+ if (unlikely(!(gr_status & GR_READY)))
57363+ return;
57364+
57365+ preempt_disable();
57366+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
57367+
57368+ /* we wouldn't have to check d_inode if it weren't for
57369+ NFS silly-renaming
57370+ */
57371+
57372+ write_lock(&gr_inode_lock);
57373+ if (unlikely(replace && inode)) {
57374+ ino_t new_ino = inode->i_ino;
57375+ dev_t new_dev = __get_dev(new_dentry);
57376+
57377+ inodev = lookup_inodev_entry(new_ino, new_dev);
57378+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
57379+ do_handle_delete(inodev, new_ino, new_dev);
57380+ }
57381+
57382+ inodev = lookup_inodev_entry(old_ino, old_dev);
57383+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
57384+ do_handle_delete(inodev, old_ino, old_dev);
57385+
57386+ if (unlikely((unsigned long)matchn))
57387+ do_handle_create(matchn, old_dentry, mnt);
57388+
57389+ write_unlock(&gr_inode_lock);
57390+ preempt_enable();
57391+
57392+ return;
57393+}
57394+
57395+static int
57396+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
57397+ unsigned char **sum)
57398+{
57399+ struct acl_role_label *r;
57400+ struct role_allowed_ip *ipp;
57401+ struct role_transition *trans;
57402+ unsigned int i;
57403+ int found = 0;
57404+ u32 curr_ip = current->signal->curr_ip;
57405+
57406+ current->signal->saved_ip = curr_ip;
57407+
57408+ /* check transition table */
57409+
57410+ for (trans = current->role->transitions; trans; trans = trans->next) {
57411+ if (!strcmp(rolename, trans->rolename)) {
57412+ found = 1;
57413+ break;
57414+ }
57415+ }
57416+
57417+ if (!found)
57418+ return 0;
57419+
57420+ /* handle special roles that do not require authentication
57421+ and check ip */
57422+
57423+ FOR_EACH_ROLE_START(r)
57424+ if (!strcmp(rolename, r->rolename) &&
57425+ (r->roletype & GR_ROLE_SPECIAL)) {
57426+ found = 0;
57427+ if (r->allowed_ips != NULL) {
57428+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
57429+ if ((ntohl(curr_ip) & ipp->netmask) ==
57430+ (ntohl(ipp->addr) & ipp->netmask))
57431+ found = 1;
57432+ }
57433+ } else
57434+ found = 2;
57435+ if (!found)
57436+ return 0;
57437+
57438+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
57439+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
57440+ *salt = NULL;
57441+ *sum = NULL;
57442+ return 1;
57443+ }
57444+ }
57445+ FOR_EACH_ROLE_END(r)
57446+
57447+ for (i = 0; i < num_sprole_pws; i++) {
57448+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
57449+ *salt = acl_special_roles[i]->salt;
57450+ *sum = acl_special_roles[i]->sum;
57451+ return 1;
57452+ }
57453+ }
57454+
57455+ return 0;
57456+}
57457+
57458+static void
57459+assign_special_role(char *rolename)
57460+{
57461+ struct acl_object_label *obj;
57462+ struct acl_role_label *r;
57463+ struct acl_role_label *assigned = NULL;
57464+ struct task_struct *tsk;
57465+ struct file *filp;
57466+
57467+ FOR_EACH_ROLE_START(r)
57468+ if (!strcmp(rolename, r->rolename) &&
57469+ (r->roletype & GR_ROLE_SPECIAL)) {
57470+ assigned = r;
57471+ break;
57472+ }
57473+ FOR_EACH_ROLE_END(r)
57474+
57475+ if (!assigned)
57476+ return;
57477+
57478+ read_lock(&tasklist_lock);
57479+ read_lock(&grsec_exec_file_lock);
57480+
57481+ tsk = current->real_parent;
57482+ if (tsk == NULL)
57483+ goto out_unlock;
57484+
57485+ filp = tsk->exec_file;
57486+ if (filp == NULL)
57487+ goto out_unlock;
57488+
57489+ tsk->is_writable = 0;
57490+
57491+ tsk->acl_sp_role = 1;
57492+ tsk->acl_role_id = ++acl_sp_role_value;
57493+ tsk->role = assigned;
57494+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
57495+
57496+ /* ignore additional mmap checks for processes that are writable
57497+ by the default ACL */
57498+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
57499+ if (unlikely(obj->mode & GR_WRITE))
57500+ tsk->is_writable = 1;
57501+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
57502+ if (unlikely(obj->mode & GR_WRITE))
57503+ tsk->is_writable = 1;
57504+
57505+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57506+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
57507+#endif
57508+
57509+out_unlock:
57510+ read_unlock(&grsec_exec_file_lock);
57511+ read_unlock(&tasklist_lock);
57512+ return;
57513+}
57514+
57515+int gr_check_secure_terminal(struct task_struct *task)
57516+{
57517+ struct task_struct *p, *p2, *p3;
57518+ struct files_struct *files;
57519+ struct fdtable *fdt;
57520+ struct file *our_file = NULL, *file;
57521+ int i;
57522+
57523+ if (task->signal->tty == NULL)
57524+ return 1;
57525+
57526+ files = get_files_struct(task);
57527+ if (files != NULL) {
57528+ rcu_read_lock();
57529+ fdt = files_fdtable(files);
57530+ for (i=0; i < fdt->max_fds; i++) {
57531+ file = fcheck_files(files, i);
57532+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
57533+ get_file(file);
57534+ our_file = file;
57535+ }
57536+ }
57537+ rcu_read_unlock();
57538+ put_files_struct(files);
57539+ }
57540+
57541+ if (our_file == NULL)
57542+ return 1;
57543+
57544+ read_lock(&tasklist_lock);
57545+ do_each_thread(p2, p) {
57546+ files = get_files_struct(p);
57547+ if (files == NULL ||
57548+ (p->signal && p->signal->tty == task->signal->tty)) {
57549+ if (files != NULL)
57550+ put_files_struct(files);
57551+ continue;
57552+ }
57553+ rcu_read_lock();
57554+ fdt = files_fdtable(files);
57555+ for (i=0; i < fdt->max_fds; i++) {
57556+ file = fcheck_files(files, i);
57557+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
57558+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
57559+ p3 = task;
57560+ while (p3->pid > 0) {
57561+ if (p3 == p)
57562+ break;
57563+ p3 = p3->real_parent;
57564+ }
57565+ if (p3 == p)
57566+ break;
57567+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
57568+ gr_handle_alertkill(p);
57569+ rcu_read_unlock();
57570+ put_files_struct(files);
57571+ read_unlock(&tasklist_lock);
57572+ fput(our_file);
57573+ return 0;
57574+ }
57575+ }
57576+ rcu_read_unlock();
57577+ put_files_struct(files);
57578+ } while_each_thread(p2, p);
57579+ read_unlock(&tasklist_lock);
57580+
57581+ fput(our_file);
57582+ return 1;
57583+}
57584+
57585+static int gr_rbac_disable(void *unused)
57586+{
57587+ pax_open_kernel();
57588+ gr_status &= ~GR_READY;
57589+ pax_close_kernel();
57590+
57591+ return 0;
57592+}
57593+
57594+ssize_t
57595+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
57596+{
57597+ struct gr_arg_wrapper uwrap;
57598+ unsigned char *sprole_salt = NULL;
57599+ unsigned char *sprole_sum = NULL;
57600+ int error = sizeof (struct gr_arg_wrapper);
57601+ int error2 = 0;
57602+
57603+ mutex_lock(&gr_dev_mutex);
57604+
57605+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
57606+ error = -EPERM;
57607+ goto out;
57608+ }
57609+
57610+ if (count != sizeof (struct gr_arg_wrapper)) {
57611+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
57612+ error = -EINVAL;
57613+ goto out;
57614+ }
57615+
57616+
57617+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
57618+ gr_auth_expires = 0;
57619+ gr_auth_attempts = 0;
57620+ }
57621+
57622+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
57623+ error = -EFAULT;
57624+ goto out;
57625+ }
57626+
57627+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
57628+ error = -EINVAL;
57629+ goto out;
57630+ }
57631+
57632+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
57633+ error = -EFAULT;
57634+ goto out;
57635+ }
57636+
57637+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
57638+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
57639+ time_after(gr_auth_expires, get_seconds())) {
57640+ error = -EBUSY;
57641+ goto out;
57642+ }
57643+
57644+ /* if non-root trying to do anything other than use a special role,
57645+ do not attempt authentication, do not count towards authentication
57646+ locking
57647+ */
57648+
57649+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
57650+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
57651+ !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
57652+ error = -EPERM;
57653+ goto out;
57654+ }
57655+
57656+ /* ensure pw and special role name are null terminated */
57657+
57658+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
57659+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
57660+
57661+ /* Okay.
57662+ * We have our enough of the argument structure..(we have yet
57663+ * to copy_from_user the tables themselves) . Copy the tables
57664+ * only if we need them, i.e. for loading operations. */
57665+
57666+ switch (gr_usermode->mode) {
57667+ case GR_STATUS:
57668+ if (gr_status & GR_READY) {
57669+ error = 1;
57670+ if (!gr_check_secure_terminal(current))
57671+ error = 3;
57672+ } else
57673+ error = 2;
57674+ goto out;
57675+ case GR_SHUTDOWN:
57676+ if ((gr_status & GR_READY)
57677+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
57678+ stop_machine(gr_rbac_disable, NULL, NULL);
57679+ free_variables();
57680+ memset(gr_usermode, 0, sizeof (struct gr_arg));
57681+ memset(gr_system_salt, 0, GR_SALT_LEN);
57682+ memset(gr_system_sum, 0, GR_SHA_LEN);
57683+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
57684+ } else if (gr_status & GR_READY) {
57685+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
57686+ error = -EPERM;
57687+ } else {
57688+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
57689+ error = -EAGAIN;
57690+ }
57691+ break;
57692+ case GR_ENABLE:
57693+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
57694+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
57695+ else {
57696+ if (gr_status & GR_READY)
57697+ error = -EAGAIN;
57698+ else
57699+ error = error2;
57700+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
57701+ }
57702+ break;
57703+ case GR_RELOAD:
57704+ if (!(gr_status & GR_READY)) {
57705+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
57706+ error = -EAGAIN;
57707+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
57708+ stop_machine(gr_rbac_disable, NULL, NULL);
57709+ free_variables();
57710+ error2 = gracl_init(gr_usermode);
57711+ if (!error2)
57712+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
57713+ else {
57714+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
57715+ error = error2;
57716+ }
57717+ } else {
57718+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
57719+ error = -EPERM;
57720+ }
57721+ break;
57722+ case GR_SEGVMOD:
57723+ if (unlikely(!(gr_status & GR_READY))) {
57724+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
57725+ error = -EAGAIN;
57726+ break;
57727+ }
57728+
57729+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
57730+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
57731+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
57732+ struct acl_subject_label *segvacl;
57733+ segvacl =
57734+ lookup_acl_subj_label(gr_usermode->segv_inode,
57735+ gr_usermode->segv_device,
57736+ current->role);
57737+ if (segvacl) {
57738+ segvacl->crashes = 0;
57739+ segvacl->expires = 0;
57740+ }
57741+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
57742+ gr_remove_uid(gr_usermode->segv_uid);
57743+ }
57744+ } else {
57745+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
57746+ error = -EPERM;
57747+ }
57748+ break;
57749+ case GR_SPROLE:
57750+ case GR_SPROLEPAM:
57751+ if (unlikely(!(gr_status & GR_READY))) {
57752+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
57753+ error = -EAGAIN;
57754+ break;
57755+ }
57756+
57757+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
57758+ current->role->expires = 0;
57759+ current->role->auth_attempts = 0;
57760+ }
57761+
57762+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
57763+ time_after(current->role->expires, get_seconds())) {
57764+ error = -EBUSY;
57765+ goto out;
57766+ }
57767+
57768+ if (lookup_special_role_auth
57769+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
57770+ && ((!sprole_salt && !sprole_sum)
57771+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
57772+ char *p = "";
57773+ assign_special_role(gr_usermode->sp_role);
57774+ read_lock(&tasklist_lock);
57775+ if (current->real_parent)
57776+ p = current->real_parent->role->rolename;
57777+ read_unlock(&tasklist_lock);
57778+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
57779+ p, acl_sp_role_value);
57780+ } else {
57781+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
57782+ error = -EPERM;
57783+ if(!(current->role->auth_attempts++))
57784+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
57785+
57786+ goto out;
57787+ }
57788+ break;
57789+ case GR_UNSPROLE:
57790+ if (unlikely(!(gr_status & GR_READY))) {
57791+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
57792+ error = -EAGAIN;
57793+ break;
57794+ }
57795+
57796+ if (current->role->roletype & GR_ROLE_SPECIAL) {
57797+ char *p = "";
57798+ int i = 0;
57799+
57800+ read_lock(&tasklist_lock);
57801+ if (current->real_parent) {
57802+ p = current->real_parent->role->rolename;
57803+ i = current->real_parent->acl_role_id;
57804+ }
57805+ read_unlock(&tasklist_lock);
57806+
57807+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
57808+ gr_set_acls(1);
57809+ } else {
57810+ error = -EPERM;
57811+ goto out;
57812+ }
57813+ break;
57814+ default:
57815+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
57816+ error = -EINVAL;
57817+ break;
57818+ }
57819+
57820+ if (error != -EPERM)
57821+ goto out;
57822+
57823+ if(!(gr_auth_attempts++))
57824+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
57825+
57826+ out:
57827+ mutex_unlock(&gr_dev_mutex);
57828+ return error;
57829+}
57830+
57831+/* must be called with
57832+ rcu_read_lock();
57833+ read_lock(&tasklist_lock);
57834+ read_lock(&grsec_exec_file_lock);
57835+*/
57836+int gr_apply_subject_to_task(struct task_struct *task)
57837+{
57838+ struct acl_object_label *obj;
57839+ char *tmpname;
57840+ struct acl_subject_label *tmpsubj;
57841+ struct file *filp;
57842+ struct name_entry *nmatch;
57843+
57844+ filp = task->exec_file;
57845+ if (filp == NULL)
57846+ return 0;
57847+
57848+ /* the following is to apply the correct subject
57849+ on binaries running when the RBAC system
57850+ is enabled, when the binaries have been
57851+ replaced or deleted since their execution
57852+ -----
57853+ when the RBAC system starts, the inode/dev
57854+ from exec_file will be one the RBAC system
57855+ is unaware of. It only knows the inode/dev
57856+ of the present file on disk, or the absence
57857+ of it.
57858+ */
57859+ preempt_disable();
57860+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
57861+
57862+ nmatch = lookup_name_entry(tmpname);
57863+ preempt_enable();
57864+ tmpsubj = NULL;
57865+ if (nmatch) {
57866+ if (nmatch->deleted)
57867+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
57868+ else
57869+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
57870+ if (tmpsubj != NULL)
57871+ task->acl = tmpsubj;
57872+ }
57873+ if (tmpsubj == NULL)
57874+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
57875+ task->role);
57876+ if (task->acl) {
57877+ task->is_writable = 0;
57878+ /* ignore additional mmap checks for processes that are writable
57879+ by the default ACL */
57880+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
57881+ if (unlikely(obj->mode & GR_WRITE))
57882+ task->is_writable = 1;
57883+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
57884+ if (unlikely(obj->mode & GR_WRITE))
57885+ task->is_writable = 1;
57886+
57887+ gr_set_proc_res(task);
57888+
57889+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57890+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
57891+#endif
57892+ } else {
57893+ return 1;
57894+ }
57895+
57896+ return 0;
57897+}
57898+
57899+int
57900+gr_set_acls(const int type)
57901+{
57902+ struct task_struct *task, *task2;
57903+ struct acl_role_label *role = current->role;
57904+ __u16 acl_role_id = current->acl_role_id;
57905+ const struct cred *cred;
57906+ int ret;
57907+
57908+ rcu_read_lock();
57909+ read_lock(&tasklist_lock);
57910+ read_lock(&grsec_exec_file_lock);
57911+ do_each_thread(task2, task) {
57912+ /* check to see if we're called from the exit handler,
57913+ if so, only replace ACLs that have inherited the admin
57914+ ACL */
57915+
57916+ if (type && (task->role != role ||
57917+ task->acl_role_id != acl_role_id))
57918+ continue;
57919+
57920+ task->acl_role_id = 0;
57921+ task->acl_sp_role = 0;
57922+
57923+ if (task->exec_file) {
57924+ cred = __task_cred(task);
57925+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
57926+ ret = gr_apply_subject_to_task(task);
57927+ if (ret) {
57928+ read_unlock(&grsec_exec_file_lock);
57929+ read_unlock(&tasklist_lock);
57930+ rcu_read_unlock();
57931+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
57932+ return ret;
57933+ }
57934+ } else {
57935+ // it's a kernel process
57936+ task->role = kernel_role;
57937+ task->acl = kernel_role->root_label;
57938+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
57939+ task->acl->mode &= ~GR_PROCFIND;
57940+#endif
57941+ }
57942+ } while_each_thread(task2, task);
57943+ read_unlock(&grsec_exec_file_lock);
57944+ read_unlock(&tasklist_lock);
57945+ rcu_read_unlock();
57946+
57947+ return 0;
57948+}
57949+
57950+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
57951+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
57952+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
57953+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
57954+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
57955+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
57956+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
57957+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
57958+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
57959+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
57960+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
57961+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
57962+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
57963+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
57964+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
57965+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
57966+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
57967+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
57968+};
57969+
57970+void
57971+gr_learn_resource(const struct task_struct *task,
57972+ const int res, const unsigned long wanted, const int gt)
57973+{
57974+ struct acl_subject_label *acl;
57975+ const struct cred *cred;
57976+
57977+ if (unlikely((gr_status & GR_READY) &&
57978+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
57979+ goto skip_reslog;
57980+
57981+ gr_log_resource(task, res, wanted, gt);
57982+skip_reslog:
57983+
57984+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
57985+ return;
57986+
57987+ acl = task->acl;
57988+
57989+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
57990+ !(acl->resmask & (1 << (unsigned short) res))))
57991+ return;
57992+
57993+ if (wanted >= acl->res[res].rlim_cur) {
57994+ unsigned long res_add;
57995+
57996+ res_add = wanted + res_learn_bumps[res];
57997+
57998+ acl->res[res].rlim_cur = res_add;
57999+
58000+ if (wanted > acl->res[res].rlim_max)
58001+ acl->res[res].rlim_max = res_add;
58002+
58003+ /* only log the subject filename, since resource logging is supported for
58004+ single-subject learning only */
58005+ rcu_read_lock();
58006+ cred = __task_cred(task);
58007+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
58008+ task->role->roletype, cred->uid, cred->gid, acl->filename,
58009+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
58010+ "", (unsigned long) res, &task->signal->saved_ip);
58011+ rcu_read_unlock();
58012+ }
58013+
58014+ return;
58015+}
58016+EXPORT_SYMBOL(gr_learn_resource);
58017+#endif
58018+
58019+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
58020+void
58021+pax_set_initial_flags(struct linux_binprm *bprm)
58022+{
58023+ struct task_struct *task = current;
58024+ struct acl_subject_label *proc;
58025+ unsigned long flags;
58026+
58027+ if (unlikely(!(gr_status & GR_READY)))
58028+ return;
58029+
58030+ flags = pax_get_flags(task);
58031+
58032+ proc = task->acl;
58033+
58034+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
58035+ flags &= ~MF_PAX_PAGEEXEC;
58036+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
58037+ flags &= ~MF_PAX_SEGMEXEC;
58038+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
58039+ flags &= ~MF_PAX_RANDMMAP;
58040+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
58041+ flags &= ~MF_PAX_EMUTRAMP;
58042+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
58043+ flags &= ~MF_PAX_MPROTECT;
58044+
58045+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
58046+ flags |= MF_PAX_PAGEEXEC;
58047+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
58048+ flags |= MF_PAX_SEGMEXEC;
58049+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
58050+ flags |= MF_PAX_RANDMMAP;
58051+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
58052+ flags |= MF_PAX_EMUTRAMP;
58053+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
58054+ flags |= MF_PAX_MPROTECT;
58055+
58056+ pax_set_flags(task, flags);
58057+
58058+ return;
58059+}
58060+#endif
58061+
58062+int
58063+gr_handle_proc_ptrace(struct task_struct *task)
58064+{
58065+ struct file *filp;
58066+ struct task_struct *tmp = task;
58067+ struct task_struct *curtemp = current;
58068+ __u32 retmode;
58069+
58070+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
58071+ if (unlikely(!(gr_status & GR_READY)))
58072+ return 0;
58073+#endif
58074+
58075+ read_lock(&tasklist_lock);
58076+ read_lock(&grsec_exec_file_lock);
58077+ filp = task->exec_file;
58078+
58079+ while (tmp->pid > 0) {
58080+ if (tmp == curtemp)
58081+ break;
58082+ tmp = tmp->real_parent;
58083+ }
58084+
58085+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
58086+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
58087+ read_unlock(&grsec_exec_file_lock);
58088+ read_unlock(&tasklist_lock);
58089+ return 1;
58090+ }
58091+
58092+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58093+ if (!(gr_status & GR_READY)) {
58094+ read_unlock(&grsec_exec_file_lock);
58095+ read_unlock(&tasklist_lock);
58096+ return 0;
58097+ }
58098+#endif
58099+
58100+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
58101+ read_unlock(&grsec_exec_file_lock);
58102+ read_unlock(&tasklist_lock);
58103+
58104+ if (retmode & GR_NOPTRACE)
58105+ return 1;
58106+
58107+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
58108+ && (current->acl != task->acl || (current->acl != current->role->root_label
58109+ && current->pid != task->pid)))
58110+ return 1;
58111+
58112+ return 0;
58113+}
58114+
58115+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
58116+{
58117+ if (unlikely(!(gr_status & GR_READY)))
58118+ return;
58119+
58120+ if (!(current->role->roletype & GR_ROLE_GOD))
58121+ return;
58122+
58123+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
58124+ p->role->rolename, gr_task_roletype_to_char(p),
58125+ p->acl->filename);
58126+}
58127+
58128+int
58129+gr_handle_ptrace(struct task_struct *task, const long request)
58130+{
58131+ struct task_struct *tmp = task;
58132+ struct task_struct *curtemp = current;
58133+ __u32 retmode;
58134+
58135+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
58136+ if (unlikely(!(gr_status & GR_READY)))
58137+ return 0;
58138+#endif
58139+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
58140+ read_lock(&tasklist_lock);
58141+ while (tmp->pid > 0) {
58142+ if (tmp == curtemp)
58143+ break;
58144+ tmp = tmp->real_parent;
58145+ }
58146+
58147+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
58148+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
58149+ read_unlock(&tasklist_lock);
58150+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
58151+ return 1;
58152+ }
58153+ read_unlock(&tasklist_lock);
58154+ }
58155+
58156+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58157+ if (!(gr_status & GR_READY))
58158+ return 0;
58159+#endif
58160+
58161+ read_lock(&grsec_exec_file_lock);
58162+ if (unlikely(!task->exec_file)) {
58163+ read_unlock(&grsec_exec_file_lock);
58164+ return 0;
58165+ }
58166+
58167+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
58168+ read_unlock(&grsec_exec_file_lock);
58169+
58170+ if (retmode & GR_NOPTRACE) {
58171+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
58172+ return 1;
58173+ }
58174+
58175+ if (retmode & GR_PTRACERD) {
58176+ switch (request) {
58177+ case PTRACE_SEIZE:
58178+ case PTRACE_POKETEXT:
58179+ case PTRACE_POKEDATA:
58180+ case PTRACE_POKEUSR:
58181+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
58182+ case PTRACE_SETREGS:
58183+ case PTRACE_SETFPREGS:
58184+#endif
58185+#ifdef CONFIG_X86
58186+ case PTRACE_SETFPXREGS:
58187+#endif
58188+#ifdef CONFIG_ALTIVEC
58189+ case PTRACE_SETVRREGS:
58190+#endif
58191+ return 1;
58192+ default:
58193+ return 0;
58194+ }
58195+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
58196+ !(current->role->roletype & GR_ROLE_GOD) &&
58197+ (current->acl != task->acl)) {
58198+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
58199+ return 1;
58200+ }
58201+
58202+ return 0;
58203+}
58204+
58205+static int is_writable_mmap(const struct file *filp)
58206+{
58207+ struct task_struct *task = current;
58208+ struct acl_object_label *obj, *obj2;
58209+
58210+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
58211+ !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))) {
58212+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
58213+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
58214+ task->role->root_label);
58215+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
58216+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
58217+ return 1;
58218+ }
58219+ }
58220+ return 0;
58221+}
58222+
58223+int
58224+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
58225+{
58226+ __u32 mode;
58227+
58228+ if (unlikely(!file || !(prot & PROT_EXEC)))
58229+ return 1;
58230+
58231+ if (is_writable_mmap(file))
58232+ return 0;
58233+
58234+ mode =
58235+ gr_search_file(file->f_path.dentry,
58236+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
58237+ file->f_path.mnt);
58238+
58239+ if (!gr_tpe_allow(file))
58240+ return 0;
58241+
58242+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
58243+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
58244+ return 0;
58245+ } else if (unlikely(!(mode & GR_EXEC))) {
58246+ return 0;
58247+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
58248+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
58249+ return 1;
58250+ }
58251+
58252+ return 1;
58253+}
58254+
58255+int
58256+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
58257+{
58258+ __u32 mode;
58259+
58260+ if (unlikely(!file || !(prot & PROT_EXEC)))
58261+ return 1;
58262+
58263+ if (is_writable_mmap(file))
58264+ return 0;
58265+
58266+ mode =
58267+ gr_search_file(file->f_path.dentry,
58268+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
58269+ file->f_path.mnt);
58270+
58271+ if (!gr_tpe_allow(file))
58272+ return 0;
58273+
58274+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
58275+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
58276+ return 0;
58277+ } else if (unlikely(!(mode & GR_EXEC))) {
58278+ return 0;
58279+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
58280+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
58281+ return 1;
58282+ }
58283+
58284+ return 1;
58285+}
58286+
58287+void
58288+gr_acl_handle_psacct(struct task_struct *task, const long code)
58289+{
58290+ unsigned long runtime;
58291+ unsigned long cputime;
58292+ unsigned int wday, cday;
58293+ __u8 whr, chr;
58294+ __u8 wmin, cmin;
58295+ __u8 wsec, csec;
58296+ struct timespec timeval;
58297+
58298+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
58299+ !(task->acl->mode & GR_PROCACCT)))
58300+ return;
58301+
58302+ do_posix_clock_monotonic_gettime(&timeval);
58303+ runtime = timeval.tv_sec - task->start_time.tv_sec;
58304+ wday = runtime / (3600 * 24);
58305+ runtime -= wday * (3600 * 24);
58306+ whr = runtime / 3600;
58307+ runtime -= whr * 3600;
58308+ wmin = runtime / 60;
58309+ runtime -= wmin * 60;
58310+ wsec = runtime;
58311+
58312+ cputime = (task->utime + task->stime) / HZ;
58313+ cday = cputime / (3600 * 24);
58314+ cputime -= cday * (3600 * 24);
58315+ chr = cputime / 3600;
58316+ cputime -= chr * 3600;
58317+ cmin = cputime / 60;
58318+ cputime -= cmin * 60;
58319+ csec = cputime;
58320+
58321+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
58322+
58323+ return;
58324+}
58325+
58326+void gr_set_kernel_label(struct task_struct *task)
58327+{
58328+ if (gr_status & GR_READY) {
58329+ task->role = kernel_role;
58330+ task->acl = kernel_role->root_label;
58331+ }
58332+ return;
58333+}
58334+
58335+#ifdef CONFIG_TASKSTATS
58336+int gr_is_taskstats_denied(int pid)
58337+{
58338+ struct task_struct *task;
58339+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
58340+ const struct cred *cred;
58341+#endif
58342+ int ret = 0;
58343+
58344+ /* restrict taskstats viewing to un-chrooted root users
58345+ who have the 'view' subject flag if the RBAC system is enabled
58346+ */
58347+
58348+ rcu_read_lock();
58349+ read_lock(&tasklist_lock);
58350+ task = find_task_by_vpid(pid);
58351+ if (task) {
58352+#ifdef CONFIG_GRKERNSEC_CHROOT
58353+ if (proc_is_chrooted(task))
58354+ ret = -EACCES;
58355+#endif
58356+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
58357+ cred = __task_cred(task);
58358+#ifdef CONFIG_GRKERNSEC_PROC_USER
58359+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
58360+ ret = -EACCES;
58361+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
58362+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
58363+ ret = -EACCES;
58364+#endif
58365+#endif
58366+ if (gr_status & GR_READY) {
58367+ if (!(task->acl->mode & GR_VIEW))
58368+ ret = -EACCES;
58369+ }
58370+ } else
58371+ ret = -ENOENT;
58372+
58373+ read_unlock(&tasklist_lock);
58374+ rcu_read_unlock();
58375+
58376+ return ret;
58377+}
58378+#endif
58379+
58380+/* AUXV entries are filled via a descendant of search_binary_handler
58381+ after we've already applied the subject for the target
58382+*/
58383+int gr_acl_enable_at_secure(void)
58384+{
58385+ if (unlikely(!(gr_status & GR_READY)))
58386+ return 0;
58387+
58388+ if (current->acl->mode & GR_ATSECURE)
58389+ return 1;
58390+
58391+ return 0;
58392+}
58393+
58394+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
58395+{
58396+ struct task_struct *task = current;
58397+ struct dentry *dentry = file->f_path.dentry;
58398+ struct vfsmount *mnt = file->f_path.mnt;
58399+ struct acl_object_label *obj, *tmp;
58400+ struct acl_subject_label *subj;
58401+ unsigned int bufsize;
58402+ int is_not_root;
58403+ char *path;
58404+ dev_t dev = __get_dev(dentry);
58405+
58406+ if (unlikely(!(gr_status & GR_READY)))
58407+ return 1;
58408+
58409+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
58410+ return 1;
58411+
58412+ /* ignore Eric Biederman */
58413+ if (IS_PRIVATE(dentry->d_inode))
58414+ return 1;
58415+
58416+ subj = task->acl;
58417+ read_lock(&gr_inode_lock);
58418+ do {
58419+ obj = lookup_acl_obj_label(ino, dev, subj);
58420+ if (obj != NULL) {
58421+ read_unlock(&gr_inode_lock);
58422+ return (obj->mode & GR_FIND) ? 1 : 0;
58423+ }
58424+ } while ((subj = subj->parent_subject));
58425+ read_unlock(&gr_inode_lock);
58426+
58427+ /* this is purely an optimization since we're looking for an object
58428+ for the directory we're doing a readdir on
58429+ if it's possible for any globbed object to match the entry we're
58430+ filling into the directory, then the object we find here will be
58431+ an anchor point with attached globbed objects
58432+ */
58433+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
58434+ if (obj->globbed == NULL)
58435+ return (obj->mode & GR_FIND) ? 1 : 0;
58436+
58437+ is_not_root = ((obj->filename[0] == '/') &&
58438+ (obj->filename[1] == '\0')) ? 0 : 1;
58439+ bufsize = PAGE_SIZE - namelen - is_not_root;
58440+
58441+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
58442+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
58443+ return 1;
58444+
58445+ preempt_disable();
58446+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
58447+ bufsize);
58448+
58449+ bufsize = strlen(path);
58450+
58451+ /* if base is "/", don't append an additional slash */
58452+ if (is_not_root)
58453+ *(path + bufsize) = '/';
58454+ memcpy(path + bufsize + is_not_root, name, namelen);
58455+ *(path + bufsize + namelen + is_not_root) = '\0';
58456+
58457+ tmp = obj->globbed;
58458+ while (tmp) {
58459+ if (!glob_match(tmp->filename, path)) {
58460+ preempt_enable();
58461+ return (tmp->mode & GR_FIND) ? 1 : 0;
58462+ }
58463+ tmp = tmp->next;
58464+ }
58465+ preempt_enable();
58466+ return (obj->mode & GR_FIND) ? 1 : 0;
58467+}
58468+
58469+void gr_put_exec_file(struct task_struct *task)
58470+{
58471+ struct file *filp;
58472+
58473+ write_lock(&grsec_exec_file_lock);
58474+ filp = task->exec_file;
58475+ task->exec_file = NULL;
58476+ write_unlock(&grsec_exec_file_lock);
58477+
58478+ if (filp)
58479+ fput(filp);
58480+
58481+ return;
58482+}
58483+
58484+
58485+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
58486+EXPORT_SYMBOL(gr_acl_is_enabled);
58487+#endif
58488+EXPORT_SYMBOL(gr_set_kernel_label);
58489+#ifdef CONFIG_SECURITY
58490+EXPORT_SYMBOL(gr_check_user_change);
58491+EXPORT_SYMBOL(gr_check_group_change);
58492+#endif
58493+
58494diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
58495new file mode 100644
58496index 0000000..34fefda
58497--- /dev/null
58498+++ b/grsecurity/gracl_alloc.c
58499@@ -0,0 +1,105 @@
58500+#include <linux/kernel.h>
58501+#include <linux/mm.h>
58502+#include <linux/slab.h>
58503+#include <linux/vmalloc.h>
58504+#include <linux/gracl.h>
58505+#include <linux/grsecurity.h>
58506+
58507+static unsigned long alloc_stack_next = 1;
58508+static unsigned long alloc_stack_size = 1;
58509+static void **alloc_stack;
58510+
58511+static __inline__ int
58512+alloc_pop(void)
58513+{
58514+ if (alloc_stack_next == 1)
58515+ return 0;
58516+
58517+ kfree(alloc_stack[alloc_stack_next - 2]);
58518+
58519+ alloc_stack_next--;
58520+
58521+ return 1;
58522+}
58523+
58524+static __inline__ int
58525+alloc_push(void *buf)
58526+{
58527+ if (alloc_stack_next >= alloc_stack_size)
58528+ return 1;
58529+
58530+ alloc_stack[alloc_stack_next - 1] = buf;
58531+
58532+ alloc_stack_next++;
58533+
58534+ return 0;
58535+}
58536+
58537+void *
58538+acl_alloc(unsigned long len)
58539+{
58540+ void *ret = NULL;
58541+
58542+ if (!len || len > PAGE_SIZE)
58543+ goto out;
58544+
58545+ ret = kmalloc(len, GFP_KERNEL);
58546+
58547+ if (ret) {
58548+ if (alloc_push(ret)) {
58549+ kfree(ret);
58550+ ret = NULL;
58551+ }
58552+ }
58553+
58554+out:
58555+ return ret;
58556+}
58557+
58558+void *
58559+acl_alloc_num(unsigned long num, unsigned long len)
58560+{
58561+ if (!len || (num > (PAGE_SIZE / len)))
58562+ return NULL;
58563+
58564+ return acl_alloc(num * len);
58565+}
58566+
58567+void
58568+acl_free_all(void)
58569+{
58570+ if (gr_acl_is_enabled() || !alloc_stack)
58571+ return;
58572+
58573+ while (alloc_pop()) ;
58574+
58575+ if (alloc_stack) {
58576+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
58577+ kfree(alloc_stack);
58578+ else
58579+ vfree(alloc_stack);
58580+ }
58581+
58582+ alloc_stack = NULL;
58583+ alloc_stack_size = 1;
58584+ alloc_stack_next = 1;
58585+
58586+ return;
58587+}
58588+
58589+int
58590+acl_alloc_stack_init(unsigned long size)
58591+{
58592+ if ((size * sizeof (void *)) <= PAGE_SIZE)
58593+ alloc_stack =
58594+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
58595+ else
58596+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
58597+
58598+ alloc_stack_size = size;
58599+
58600+ if (!alloc_stack)
58601+ return 0;
58602+ else
58603+ return 1;
58604+}
58605diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
58606new file mode 100644
58607index 0000000..6d21049
58608--- /dev/null
58609+++ b/grsecurity/gracl_cap.c
58610@@ -0,0 +1,110 @@
58611+#include <linux/kernel.h>
58612+#include <linux/module.h>
58613+#include <linux/sched.h>
58614+#include <linux/gracl.h>
58615+#include <linux/grsecurity.h>
58616+#include <linux/grinternal.h>
58617+
58618+extern const char *captab_log[];
58619+extern int captab_log_entries;
58620+
58621+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58622+{
58623+ struct acl_subject_label *curracl;
58624+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
58625+ kernel_cap_t cap_audit = __cap_empty_set;
58626+
58627+ if (!gr_acl_is_enabled())
58628+ return 1;
58629+
58630+ curracl = task->acl;
58631+
58632+ cap_drop = curracl->cap_lower;
58633+ cap_mask = curracl->cap_mask;
58634+ cap_audit = curracl->cap_invert_audit;
58635+
58636+ while ((curracl = curracl->parent_subject)) {
58637+ /* if the cap isn't specified in the current computed mask but is specified in the
58638+ current level subject, and is lowered in the current level subject, then add
58639+ it to the set of dropped capabilities
58640+ otherwise, add the current level subject's mask to the current computed mask
58641+ */
58642+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
58643+ cap_raise(cap_mask, cap);
58644+ if (cap_raised(curracl->cap_lower, cap))
58645+ cap_raise(cap_drop, cap);
58646+ if (cap_raised(curracl->cap_invert_audit, cap))
58647+ cap_raise(cap_audit, cap);
58648+ }
58649+ }
58650+
58651+ if (!cap_raised(cap_drop, cap)) {
58652+ if (cap_raised(cap_audit, cap))
58653+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
58654+ return 1;
58655+ }
58656+
58657+ curracl = task->acl;
58658+
58659+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
58660+ && cap_raised(cred->cap_effective, cap)) {
58661+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
58662+ task->role->roletype, cred->uid,
58663+ cred->gid, task->exec_file ?
58664+ gr_to_filename(task->exec_file->f_path.dentry,
58665+ task->exec_file->f_path.mnt) : curracl->filename,
58666+ curracl->filename, 0UL,
58667+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
58668+ return 1;
58669+ }
58670+
58671+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
58672+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
58673+
58674+ return 0;
58675+}
58676+
58677+int
58678+gr_acl_is_capable(const int cap)
58679+{
58680+ return gr_task_acl_is_capable(current, current_cred(), cap);
58681+}
58682+
58683+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
58684+{
58685+ struct acl_subject_label *curracl;
58686+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
58687+
58688+ if (!gr_acl_is_enabled())
58689+ return 1;
58690+
58691+ curracl = task->acl;
58692+
58693+ cap_drop = curracl->cap_lower;
58694+ cap_mask = curracl->cap_mask;
58695+
58696+ while ((curracl = curracl->parent_subject)) {
58697+ /* if the cap isn't specified in the current computed mask but is specified in the
58698+ current level subject, and is lowered in the current level subject, then add
58699+ it to the set of dropped capabilities
58700+ otherwise, add the current level subject's mask to the current computed mask
58701+ */
58702+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
58703+ cap_raise(cap_mask, cap);
58704+ if (cap_raised(curracl->cap_lower, cap))
58705+ cap_raise(cap_drop, cap);
58706+ }
58707+ }
58708+
58709+ if (!cap_raised(cap_drop, cap))
58710+ return 1;
58711+
58712+ return 0;
58713+}
58714+
58715+int
58716+gr_acl_is_capable_nolog(const int cap)
58717+{
58718+ return gr_task_acl_is_capable_nolog(current, cap);
58719+}
58720+
58721diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
58722new file mode 100644
58723index 0000000..a340c17
58724--- /dev/null
58725+++ b/grsecurity/gracl_fs.c
58726@@ -0,0 +1,431 @@
58727+#include <linux/kernel.h>
58728+#include <linux/sched.h>
58729+#include <linux/types.h>
58730+#include <linux/fs.h>
58731+#include <linux/file.h>
58732+#include <linux/stat.h>
58733+#include <linux/grsecurity.h>
58734+#include <linux/grinternal.h>
58735+#include <linux/gracl.h>
58736+
58737+umode_t
58738+gr_acl_umask(void)
58739+{
58740+ if (unlikely(!gr_acl_is_enabled()))
58741+ return 0;
58742+
58743+ return current->role->umask;
58744+}
58745+
58746+__u32
58747+gr_acl_handle_hidden_file(const struct dentry * dentry,
58748+ const struct vfsmount * mnt)
58749+{
58750+ __u32 mode;
58751+
58752+ if (unlikely(!dentry->d_inode))
58753+ return GR_FIND;
58754+
58755+ mode =
58756+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
58757+
58758+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
58759+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
58760+ return mode;
58761+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
58762+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
58763+ return 0;
58764+ } else if (unlikely(!(mode & GR_FIND)))
58765+ return 0;
58766+
58767+ return GR_FIND;
58768+}
58769+
58770+__u32
58771+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
58772+ int acc_mode)
58773+{
58774+ __u32 reqmode = GR_FIND;
58775+ __u32 mode;
58776+
58777+ if (unlikely(!dentry->d_inode))
58778+ return reqmode;
58779+
58780+ if (acc_mode & MAY_APPEND)
58781+ reqmode |= GR_APPEND;
58782+ else if (acc_mode & MAY_WRITE)
58783+ reqmode |= GR_WRITE;
58784+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
58785+ reqmode |= GR_READ;
58786+
58787+ mode =
58788+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
58789+ mnt);
58790+
58791+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
58792+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
58793+ reqmode & GR_READ ? " reading" : "",
58794+ reqmode & GR_WRITE ? " writing" : reqmode &
58795+ GR_APPEND ? " appending" : "");
58796+ return reqmode;
58797+ } else
58798+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
58799+ {
58800+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
58801+ reqmode & GR_READ ? " reading" : "",
58802+ reqmode & GR_WRITE ? " writing" : reqmode &
58803+ GR_APPEND ? " appending" : "");
58804+ return 0;
58805+ } else if (unlikely((mode & reqmode) != reqmode))
58806+ return 0;
58807+
58808+ return reqmode;
58809+}
58810+
58811+__u32
58812+gr_acl_handle_creat(const struct dentry * dentry,
58813+ const struct dentry * p_dentry,
58814+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
58815+ const int imode)
58816+{
58817+ __u32 reqmode = GR_WRITE | GR_CREATE;
58818+ __u32 mode;
58819+
58820+ if (acc_mode & MAY_APPEND)
58821+ reqmode |= GR_APPEND;
58822+ // if a directory was required or the directory already exists, then
58823+ // don't count this open as a read
58824+ if ((acc_mode & MAY_READ) &&
58825+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
58826+ reqmode |= GR_READ;
58827+ if ((open_flags & O_CREAT) &&
58828+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
58829+ reqmode |= GR_SETID;
58830+
58831+ mode =
58832+ gr_check_create(dentry, p_dentry, p_mnt,
58833+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
58834+
58835+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
58836+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
58837+ reqmode & GR_READ ? " reading" : "",
58838+ reqmode & GR_WRITE ? " writing" : reqmode &
58839+ GR_APPEND ? " appending" : "");
58840+ return reqmode;
58841+ } else
58842+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
58843+ {
58844+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
58845+ reqmode & GR_READ ? " reading" : "",
58846+ reqmode & GR_WRITE ? " writing" : reqmode &
58847+ GR_APPEND ? " appending" : "");
58848+ return 0;
58849+ } else if (unlikely((mode & reqmode) != reqmode))
58850+ return 0;
58851+
58852+ return reqmode;
58853+}
58854+
58855+__u32
58856+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
58857+ const int fmode)
58858+{
58859+ __u32 mode, reqmode = GR_FIND;
58860+
58861+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
58862+ reqmode |= GR_EXEC;
58863+ if (fmode & S_IWOTH)
58864+ reqmode |= GR_WRITE;
58865+ if (fmode & S_IROTH)
58866+ reqmode |= GR_READ;
58867+
58868+ mode =
58869+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
58870+ mnt);
58871+
58872+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
58873+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
58874+ reqmode & GR_READ ? " reading" : "",
58875+ reqmode & GR_WRITE ? " writing" : "",
58876+ reqmode & GR_EXEC ? " executing" : "");
58877+ return reqmode;
58878+ } else
58879+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
58880+ {
58881+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
58882+ reqmode & GR_READ ? " reading" : "",
58883+ reqmode & GR_WRITE ? " writing" : "",
58884+ reqmode & GR_EXEC ? " executing" : "");
58885+ return 0;
58886+ } else if (unlikely((mode & reqmode) != reqmode))
58887+ return 0;
58888+
58889+ return reqmode;
58890+}
58891+
58892+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
58893+{
58894+ __u32 mode;
58895+
58896+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
58897+
58898+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
58899+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
58900+ return mode;
58901+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
58902+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
58903+ return 0;
58904+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
58905+ return 0;
58906+
58907+ return (reqmode);
58908+}
58909+
58910+__u32
58911+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
58912+{
58913+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
58914+}
58915+
58916+__u32
58917+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
58918+{
58919+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
58920+}
58921+
58922+__u32
58923+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
58924+{
58925+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
58926+}
58927+
58928+__u32
58929+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
58930+{
58931+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
58932+}
58933+
58934+__u32
58935+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
58936+ umode_t *modeptr)
58937+{
58938+ umode_t mode;
58939+
58940+ *modeptr &= ~gr_acl_umask();
58941+ mode = *modeptr;
58942+
58943+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
58944+ return 1;
58945+
58946+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
58947+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
58948+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
58949+ GR_CHMOD_ACL_MSG);
58950+ } else {
58951+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
58952+ }
58953+}
58954+
58955+__u32
58956+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
58957+{
58958+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
58959+}
58960+
58961+__u32
58962+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
58963+{
58964+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
58965+}
58966+
58967+__u32
58968+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
58969+{
58970+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
58971+}
58972+
58973+__u32
58974+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
58975+{
58976+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
58977+ GR_UNIXCONNECT_ACL_MSG);
58978+}
58979+
58980+/* hardlinks require at minimum create and link permission,
58981+ any additional privilege required is based on the
58982+ privilege of the file being linked to
58983+*/
58984+__u32
58985+gr_acl_handle_link(const struct dentry * new_dentry,
58986+ const struct dentry * parent_dentry,
58987+ const struct vfsmount * parent_mnt,
58988+ const struct dentry * old_dentry,
58989+ const struct vfsmount * old_mnt, const struct filename *to)
58990+{
58991+ __u32 mode;
58992+ __u32 needmode = GR_CREATE | GR_LINK;
58993+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
58994+
58995+ mode =
58996+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
58997+ old_mnt);
58998+
58999+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
59000+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
59001+ return mode;
59002+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
59003+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
59004+ return 0;
59005+ } else if (unlikely((mode & needmode) != needmode))
59006+ return 0;
59007+
59008+ return 1;
59009+}
59010+
59011+__u32
59012+gr_acl_handle_symlink(const struct dentry * new_dentry,
59013+ const struct dentry * parent_dentry,
59014+ const struct vfsmount * parent_mnt, const struct filename *from)
59015+{
59016+ __u32 needmode = GR_WRITE | GR_CREATE;
59017+ __u32 mode;
59018+
59019+ mode =
59020+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
59021+ GR_CREATE | GR_AUDIT_CREATE |
59022+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
59023+
59024+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
59025+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
59026+ return mode;
59027+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
59028+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
59029+ return 0;
59030+ } else if (unlikely((mode & needmode) != needmode))
59031+ return 0;
59032+
59033+ return (GR_WRITE | GR_CREATE);
59034+}
59035+
59036+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)
59037+{
59038+ __u32 mode;
59039+
59040+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
59041+
59042+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
59043+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
59044+ return mode;
59045+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
59046+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
59047+ return 0;
59048+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
59049+ return 0;
59050+
59051+ return (reqmode);
59052+}
59053+
59054+__u32
59055+gr_acl_handle_mknod(const struct dentry * new_dentry,
59056+ const struct dentry * parent_dentry,
59057+ const struct vfsmount * parent_mnt,
59058+ const int mode)
59059+{
59060+ __u32 reqmode = GR_WRITE | GR_CREATE;
59061+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
59062+ reqmode |= GR_SETID;
59063+
59064+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
59065+ reqmode, GR_MKNOD_ACL_MSG);
59066+}
59067+
59068+__u32
59069+gr_acl_handle_mkdir(const struct dentry *new_dentry,
59070+ const struct dentry *parent_dentry,
59071+ const struct vfsmount *parent_mnt)
59072+{
59073+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
59074+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
59075+}
59076+
59077+#define RENAME_CHECK_SUCCESS(old, new) \
59078+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
59079+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
59080+
59081+int
59082+gr_acl_handle_rename(struct dentry *new_dentry,
59083+ struct dentry *parent_dentry,
59084+ const struct vfsmount *parent_mnt,
59085+ struct dentry *old_dentry,
59086+ struct inode *old_parent_inode,
59087+ struct vfsmount *old_mnt, const struct filename *newname)
59088+{
59089+ __u32 comp1, comp2;
59090+ int error = 0;
59091+
59092+ if (unlikely(!gr_acl_is_enabled()))
59093+ return 0;
59094+
59095+ if (!new_dentry->d_inode) {
59096+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
59097+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
59098+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
59099+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
59100+ GR_DELETE | GR_AUDIT_DELETE |
59101+ GR_AUDIT_READ | GR_AUDIT_WRITE |
59102+ GR_SUPPRESS, old_mnt);
59103+ } else {
59104+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
59105+ GR_CREATE | GR_DELETE |
59106+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
59107+ GR_AUDIT_READ | GR_AUDIT_WRITE |
59108+ GR_SUPPRESS, parent_mnt);
59109+ comp2 =
59110+ gr_search_file(old_dentry,
59111+ GR_READ | GR_WRITE | GR_AUDIT_READ |
59112+ GR_DELETE | GR_AUDIT_DELETE |
59113+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
59114+ }
59115+
59116+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
59117+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
59118+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
59119+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
59120+ && !(comp2 & GR_SUPPRESS)) {
59121+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
59122+ error = -EACCES;
59123+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
59124+ error = -EACCES;
59125+
59126+ return error;
59127+}
59128+
59129+void
59130+gr_acl_handle_exit(void)
59131+{
59132+ u16 id;
59133+ char *rolename;
59134+
59135+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
59136+ !(current->role->roletype & GR_ROLE_PERSIST))) {
59137+ id = current->acl_role_id;
59138+ rolename = current->role->rolename;
59139+ gr_set_acls(1);
59140+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
59141+ }
59142+
59143+ gr_put_exec_file(current);
59144+ return;
59145+}
59146+
59147+int
59148+gr_acl_handle_procpidmem(const struct task_struct *task)
59149+{
59150+ if (unlikely(!gr_acl_is_enabled()))
59151+ return 0;
59152+
59153+ if (task != current && task->acl->mode & GR_PROTPROCFD)
59154+ return -EACCES;
59155+
59156+ return 0;
59157+}
59158diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
59159new file mode 100644
59160index 0000000..58800a7
59161--- /dev/null
59162+++ b/grsecurity/gracl_ip.c
59163@@ -0,0 +1,384 @@
59164+#include <linux/kernel.h>
59165+#include <asm/uaccess.h>
59166+#include <asm/errno.h>
59167+#include <net/sock.h>
59168+#include <linux/file.h>
59169+#include <linux/fs.h>
59170+#include <linux/net.h>
59171+#include <linux/in.h>
59172+#include <linux/skbuff.h>
59173+#include <linux/ip.h>
59174+#include <linux/udp.h>
59175+#include <linux/types.h>
59176+#include <linux/sched.h>
59177+#include <linux/netdevice.h>
59178+#include <linux/inetdevice.h>
59179+#include <linux/gracl.h>
59180+#include <linux/grsecurity.h>
59181+#include <linux/grinternal.h>
59182+
59183+#define GR_BIND 0x01
59184+#define GR_CONNECT 0x02
59185+#define GR_INVERT 0x04
59186+#define GR_BINDOVERRIDE 0x08
59187+#define GR_CONNECTOVERRIDE 0x10
59188+#define GR_SOCK_FAMILY 0x20
59189+
59190+static const char * gr_protocols[IPPROTO_MAX] = {
59191+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
59192+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
59193+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
59194+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
59195+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
59196+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
59197+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
59198+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
59199+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
59200+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
59201+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
59202+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
59203+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
59204+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
59205+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
59206+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
59207+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
59208+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
59209+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
59210+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
59211+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
59212+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
59213+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
59214+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
59215+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
59216+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
59217+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
59218+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
59219+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
59220+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
59221+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
59222+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
59223+ };
59224+
59225+static const char * gr_socktypes[SOCK_MAX] = {
59226+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
59227+ "unknown:7", "unknown:8", "unknown:9", "packet"
59228+ };
59229+
59230+static const char * gr_sockfamilies[AF_MAX+1] = {
59231+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
59232+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
59233+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
59234+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
59235+ };
59236+
59237+const char *
59238+gr_proto_to_name(unsigned char proto)
59239+{
59240+ return gr_protocols[proto];
59241+}
59242+
59243+const char *
59244+gr_socktype_to_name(unsigned char type)
59245+{
59246+ return gr_socktypes[type];
59247+}
59248+
59249+const char *
59250+gr_sockfamily_to_name(unsigned char family)
59251+{
59252+ return gr_sockfamilies[family];
59253+}
59254+
59255+int
59256+gr_search_socket(const int domain, const int type, const int protocol)
59257+{
59258+ struct acl_subject_label *curr;
59259+ const struct cred *cred = current_cred();
59260+
59261+ if (unlikely(!gr_acl_is_enabled()))
59262+ goto exit;
59263+
59264+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
59265+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
59266+ goto exit; // let the kernel handle it
59267+
59268+ curr = current->acl;
59269+
59270+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
59271+ /* the family is allowed, if this is PF_INET allow it only if
59272+ the extra sock type/protocol checks pass */
59273+ if (domain == PF_INET)
59274+ goto inet_check;
59275+ goto exit;
59276+ } else {
59277+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
59278+ __u32 fakeip = 0;
59279+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
59280+ current->role->roletype, cred->uid,
59281+ cred->gid, current->exec_file ?
59282+ gr_to_filename(current->exec_file->f_path.dentry,
59283+ current->exec_file->f_path.mnt) :
59284+ curr->filename, curr->filename,
59285+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
59286+ &current->signal->saved_ip);
59287+ goto exit;
59288+ }
59289+ goto exit_fail;
59290+ }
59291+
59292+inet_check:
59293+ /* the rest of this checking is for IPv4 only */
59294+ if (!curr->ips)
59295+ goto exit;
59296+
59297+ if ((curr->ip_type & (1 << type)) &&
59298+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
59299+ goto exit;
59300+
59301+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
59302+ /* we don't place acls on raw sockets , and sometimes
59303+ dgram/ip sockets are opened for ioctl and not
59304+ bind/connect, so we'll fake a bind learn log */
59305+ if (type == SOCK_RAW || type == SOCK_PACKET) {
59306+ __u32 fakeip = 0;
59307+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
59308+ current->role->roletype, cred->uid,
59309+ cred->gid, current->exec_file ?
59310+ gr_to_filename(current->exec_file->f_path.dentry,
59311+ current->exec_file->f_path.mnt) :
59312+ curr->filename, curr->filename,
59313+ &fakeip, 0, type,
59314+ protocol, GR_CONNECT, &current->signal->saved_ip);
59315+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
59316+ __u32 fakeip = 0;
59317+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
59318+ current->role->roletype, cred->uid,
59319+ cred->gid, current->exec_file ?
59320+ gr_to_filename(current->exec_file->f_path.dentry,
59321+ current->exec_file->f_path.mnt) :
59322+ curr->filename, curr->filename,
59323+ &fakeip, 0, type,
59324+ protocol, GR_BIND, &current->signal->saved_ip);
59325+ }
59326+ /* we'll log when they use connect or bind */
59327+ goto exit;
59328+ }
59329+
59330+exit_fail:
59331+ if (domain == PF_INET)
59332+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
59333+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
59334+ else
59335+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
59336+ gr_socktype_to_name(type), protocol);
59337+
59338+ return 0;
59339+exit:
59340+ return 1;
59341+}
59342+
59343+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)
59344+{
59345+ if ((ip->mode & mode) &&
59346+ (ip_port >= ip->low) &&
59347+ (ip_port <= ip->high) &&
59348+ ((ntohl(ip_addr) & our_netmask) ==
59349+ (ntohl(our_addr) & our_netmask))
59350+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
59351+ && (ip->type & (1 << type))) {
59352+ if (ip->mode & GR_INVERT)
59353+ return 2; // specifically denied
59354+ else
59355+ return 1; // allowed
59356+ }
59357+
59358+ return 0; // not specifically allowed, may continue parsing
59359+}
59360+
59361+static int
59362+gr_search_connectbind(const int full_mode, struct sock *sk,
59363+ struct sockaddr_in *addr, const int type)
59364+{
59365+ char iface[IFNAMSIZ] = {0};
59366+ struct acl_subject_label *curr;
59367+ struct acl_ip_label *ip;
59368+ struct inet_sock *isk;
59369+ struct net_device *dev;
59370+ struct in_device *idev;
59371+ unsigned long i;
59372+ int ret;
59373+ int mode = full_mode & (GR_BIND | GR_CONNECT);
59374+ __u32 ip_addr = 0;
59375+ __u32 our_addr;
59376+ __u32 our_netmask;
59377+ char *p;
59378+ __u16 ip_port = 0;
59379+ const struct cred *cred = current_cred();
59380+
59381+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
59382+ return 0;
59383+
59384+ curr = current->acl;
59385+ isk = inet_sk(sk);
59386+
59387+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
59388+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
59389+ addr->sin_addr.s_addr = curr->inaddr_any_override;
59390+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
59391+ struct sockaddr_in saddr;
59392+ int err;
59393+
59394+ saddr.sin_family = AF_INET;
59395+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
59396+ saddr.sin_port = isk->inet_sport;
59397+
59398+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
59399+ if (err)
59400+ return err;
59401+
59402+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
59403+ if (err)
59404+ return err;
59405+ }
59406+
59407+ if (!curr->ips)
59408+ return 0;
59409+
59410+ ip_addr = addr->sin_addr.s_addr;
59411+ ip_port = ntohs(addr->sin_port);
59412+
59413+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
59414+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
59415+ current->role->roletype, cred->uid,
59416+ cred->gid, current->exec_file ?
59417+ gr_to_filename(current->exec_file->f_path.dentry,
59418+ current->exec_file->f_path.mnt) :
59419+ curr->filename, curr->filename,
59420+ &ip_addr, ip_port, type,
59421+ sk->sk_protocol, mode, &current->signal->saved_ip);
59422+ return 0;
59423+ }
59424+
59425+ for (i = 0; i < curr->ip_num; i++) {
59426+ ip = *(curr->ips + i);
59427+ if (ip->iface != NULL) {
59428+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
59429+ p = strchr(iface, ':');
59430+ if (p != NULL)
59431+ *p = '\0';
59432+ dev = dev_get_by_name(sock_net(sk), iface);
59433+ if (dev == NULL)
59434+ continue;
59435+ idev = in_dev_get(dev);
59436+ if (idev == NULL) {
59437+ dev_put(dev);
59438+ continue;
59439+ }
59440+ rcu_read_lock();
59441+ for_ifa(idev) {
59442+ if (!strcmp(ip->iface, ifa->ifa_label)) {
59443+ our_addr = ifa->ifa_address;
59444+ our_netmask = 0xffffffff;
59445+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
59446+ if (ret == 1) {
59447+ rcu_read_unlock();
59448+ in_dev_put(idev);
59449+ dev_put(dev);
59450+ return 0;
59451+ } else if (ret == 2) {
59452+ rcu_read_unlock();
59453+ in_dev_put(idev);
59454+ dev_put(dev);
59455+ goto denied;
59456+ }
59457+ }
59458+ } endfor_ifa(idev);
59459+ rcu_read_unlock();
59460+ in_dev_put(idev);
59461+ dev_put(dev);
59462+ } else {
59463+ our_addr = ip->addr;
59464+ our_netmask = ip->netmask;
59465+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
59466+ if (ret == 1)
59467+ return 0;
59468+ else if (ret == 2)
59469+ goto denied;
59470+ }
59471+ }
59472+
59473+denied:
59474+ if (mode == GR_BIND)
59475+ 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));
59476+ else if (mode == GR_CONNECT)
59477+ 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));
59478+
59479+ return -EACCES;
59480+}
59481+
59482+int
59483+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
59484+{
59485+ /* always allow disconnection of dgram sockets with connect */
59486+ if (addr->sin_family == AF_UNSPEC)
59487+ return 0;
59488+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
59489+}
59490+
59491+int
59492+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
59493+{
59494+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
59495+}
59496+
59497+int gr_search_listen(struct socket *sock)
59498+{
59499+ struct sock *sk = sock->sk;
59500+ struct sockaddr_in addr;
59501+
59502+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
59503+ addr.sin_port = inet_sk(sk)->inet_sport;
59504+
59505+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
59506+}
59507+
59508+int gr_search_accept(struct socket *sock)
59509+{
59510+ struct sock *sk = sock->sk;
59511+ struct sockaddr_in addr;
59512+
59513+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
59514+ addr.sin_port = inet_sk(sk)->inet_sport;
59515+
59516+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
59517+}
59518+
59519+int
59520+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
59521+{
59522+ if (addr)
59523+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
59524+ else {
59525+ struct sockaddr_in sin;
59526+ const struct inet_sock *inet = inet_sk(sk);
59527+
59528+ sin.sin_addr.s_addr = inet->inet_daddr;
59529+ sin.sin_port = inet->inet_dport;
59530+
59531+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
59532+ }
59533+}
59534+
59535+int
59536+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
59537+{
59538+ struct sockaddr_in sin;
59539+
59540+ if (unlikely(skb->len < sizeof (struct udphdr)))
59541+ return 0; // skip this packet
59542+
59543+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
59544+ sin.sin_port = udp_hdr(skb)->source;
59545+
59546+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
59547+}
59548diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
59549new file mode 100644
59550index 0000000..25f54ef
59551--- /dev/null
59552+++ b/grsecurity/gracl_learn.c
59553@@ -0,0 +1,207 @@
59554+#include <linux/kernel.h>
59555+#include <linux/mm.h>
59556+#include <linux/sched.h>
59557+#include <linux/poll.h>
59558+#include <linux/string.h>
59559+#include <linux/file.h>
59560+#include <linux/types.h>
59561+#include <linux/vmalloc.h>
59562+#include <linux/grinternal.h>
59563+
59564+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
59565+ size_t count, loff_t *ppos);
59566+extern int gr_acl_is_enabled(void);
59567+
59568+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
59569+static int gr_learn_attached;
59570+
59571+/* use a 512k buffer */
59572+#define LEARN_BUFFER_SIZE (512 * 1024)
59573+
59574+static DEFINE_SPINLOCK(gr_learn_lock);
59575+static DEFINE_MUTEX(gr_learn_user_mutex);
59576+
59577+/* we need to maintain two buffers, so that the kernel context of grlearn
59578+ uses a semaphore around the userspace copying, and the other kernel contexts
59579+ use a spinlock when copying into the buffer, since they cannot sleep
59580+*/
59581+static char *learn_buffer;
59582+static char *learn_buffer_user;
59583+static int learn_buffer_len;
59584+static int learn_buffer_user_len;
59585+
59586+static ssize_t
59587+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
59588+{
59589+ DECLARE_WAITQUEUE(wait, current);
59590+ ssize_t retval = 0;
59591+
59592+ add_wait_queue(&learn_wait, &wait);
59593+ set_current_state(TASK_INTERRUPTIBLE);
59594+ do {
59595+ mutex_lock(&gr_learn_user_mutex);
59596+ spin_lock(&gr_learn_lock);
59597+ if (learn_buffer_len)
59598+ break;
59599+ spin_unlock(&gr_learn_lock);
59600+ mutex_unlock(&gr_learn_user_mutex);
59601+ if (file->f_flags & O_NONBLOCK) {
59602+ retval = -EAGAIN;
59603+ goto out;
59604+ }
59605+ if (signal_pending(current)) {
59606+ retval = -ERESTARTSYS;
59607+ goto out;
59608+ }
59609+
59610+ schedule();
59611+ } while (1);
59612+
59613+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
59614+ learn_buffer_user_len = learn_buffer_len;
59615+ retval = learn_buffer_len;
59616+ learn_buffer_len = 0;
59617+
59618+ spin_unlock(&gr_learn_lock);
59619+
59620+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
59621+ retval = -EFAULT;
59622+
59623+ mutex_unlock(&gr_learn_user_mutex);
59624+out:
59625+ set_current_state(TASK_RUNNING);
59626+ remove_wait_queue(&learn_wait, &wait);
59627+ return retval;
59628+}
59629+
59630+static unsigned int
59631+poll_learn(struct file * file, poll_table * wait)
59632+{
59633+ poll_wait(file, &learn_wait, wait);
59634+
59635+ if (learn_buffer_len)
59636+ return (POLLIN | POLLRDNORM);
59637+
59638+ return 0;
59639+}
59640+
59641+void
59642+gr_clear_learn_entries(void)
59643+{
59644+ char *tmp;
59645+
59646+ mutex_lock(&gr_learn_user_mutex);
59647+ spin_lock(&gr_learn_lock);
59648+ tmp = learn_buffer;
59649+ learn_buffer = NULL;
59650+ spin_unlock(&gr_learn_lock);
59651+ if (tmp)
59652+ vfree(tmp);
59653+ if (learn_buffer_user != NULL) {
59654+ vfree(learn_buffer_user);
59655+ learn_buffer_user = NULL;
59656+ }
59657+ learn_buffer_len = 0;
59658+ mutex_unlock(&gr_learn_user_mutex);
59659+
59660+ return;
59661+}
59662+
59663+void
59664+gr_add_learn_entry(const char *fmt, ...)
59665+{
59666+ va_list args;
59667+ unsigned int len;
59668+
59669+ if (!gr_learn_attached)
59670+ return;
59671+
59672+ spin_lock(&gr_learn_lock);
59673+
59674+ /* leave a gap at the end so we know when it's "full" but don't have to
59675+ compute the exact length of the string we're trying to append
59676+ */
59677+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
59678+ spin_unlock(&gr_learn_lock);
59679+ wake_up_interruptible(&learn_wait);
59680+ return;
59681+ }
59682+ if (learn_buffer == NULL) {
59683+ spin_unlock(&gr_learn_lock);
59684+ return;
59685+ }
59686+
59687+ va_start(args, fmt);
59688+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
59689+ va_end(args);
59690+
59691+ learn_buffer_len += len + 1;
59692+
59693+ spin_unlock(&gr_learn_lock);
59694+ wake_up_interruptible(&learn_wait);
59695+
59696+ return;
59697+}
59698+
59699+static int
59700+open_learn(struct inode *inode, struct file *file)
59701+{
59702+ if (file->f_mode & FMODE_READ && gr_learn_attached)
59703+ return -EBUSY;
59704+ if (file->f_mode & FMODE_READ) {
59705+ int retval = 0;
59706+ mutex_lock(&gr_learn_user_mutex);
59707+ if (learn_buffer == NULL)
59708+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
59709+ if (learn_buffer_user == NULL)
59710+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
59711+ if (learn_buffer == NULL) {
59712+ retval = -ENOMEM;
59713+ goto out_error;
59714+ }
59715+ if (learn_buffer_user == NULL) {
59716+ retval = -ENOMEM;
59717+ goto out_error;
59718+ }
59719+ learn_buffer_len = 0;
59720+ learn_buffer_user_len = 0;
59721+ gr_learn_attached = 1;
59722+out_error:
59723+ mutex_unlock(&gr_learn_user_mutex);
59724+ return retval;
59725+ }
59726+ return 0;
59727+}
59728+
59729+static int
59730+close_learn(struct inode *inode, struct file *file)
59731+{
59732+ if (file->f_mode & FMODE_READ) {
59733+ char *tmp = NULL;
59734+ mutex_lock(&gr_learn_user_mutex);
59735+ spin_lock(&gr_learn_lock);
59736+ tmp = learn_buffer;
59737+ learn_buffer = NULL;
59738+ spin_unlock(&gr_learn_lock);
59739+ if (tmp)
59740+ vfree(tmp);
59741+ if (learn_buffer_user != NULL) {
59742+ vfree(learn_buffer_user);
59743+ learn_buffer_user = NULL;
59744+ }
59745+ learn_buffer_len = 0;
59746+ learn_buffer_user_len = 0;
59747+ gr_learn_attached = 0;
59748+ mutex_unlock(&gr_learn_user_mutex);
59749+ }
59750+
59751+ return 0;
59752+}
59753+
59754+const struct file_operations grsec_fops = {
59755+ .read = read_learn,
59756+ .write = write_grsec_handler,
59757+ .open = open_learn,
59758+ .release = close_learn,
59759+ .poll = poll_learn,
59760+};
59761diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
59762new file mode 100644
59763index 0000000..39645c9
59764--- /dev/null
59765+++ b/grsecurity/gracl_res.c
59766@@ -0,0 +1,68 @@
59767+#include <linux/kernel.h>
59768+#include <linux/sched.h>
59769+#include <linux/gracl.h>
59770+#include <linux/grinternal.h>
59771+
59772+static const char *restab_log[] = {
59773+ [RLIMIT_CPU] = "RLIMIT_CPU",
59774+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
59775+ [RLIMIT_DATA] = "RLIMIT_DATA",
59776+ [RLIMIT_STACK] = "RLIMIT_STACK",
59777+ [RLIMIT_CORE] = "RLIMIT_CORE",
59778+ [RLIMIT_RSS] = "RLIMIT_RSS",
59779+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
59780+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
59781+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
59782+ [RLIMIT_AS] = "RLIMIT_AS",
59783+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
59784+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
59785+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
59786+ [RLIMIT_NICE] = "RLIMIT_NICE",
59787+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
59788+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
59789+ [GR_CRASH_RES] = "RLIMIT_CRASH"
59790+};
59791+
59792+void
59793+gr_log_resource(const struct task_struct *task,
59794+ const int res, const unsigned long wanted, const int gt)
59795+{
59796+ const struct cred *cred;
59797+ unsigned long rlim;
59798+
59799+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
59800+ return;
59801+
59802+ // not yet supported resource
59803+ if (unlikely(!restab_log[res]))
59804+ return;
59805+
59806+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
59807+ rlim = task_rlimit_max(task, res);
59808+ else
59809+ rlim = task_rlimit(task, res);
59810+
59811+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
59812+ return;
59813+
59814+ rcu_read_lock();
59815+ cred = __task_cred(task);
59816+
59817+ if (res == RLIMIT_NPROC &&
59818+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
59819+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
59820+ goto out_rcu_unlock;
59821+ else if (res == RLIMIT_MEMLOCK &&
59822+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
59823+ goto out_rcu_unlock;
59824+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
59825+ goto out_rcu_unlock;
59826+ rcu_read_unlock();
59827+
59828+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
59829+
59830+ return;
59831+out_rcu_unlock:
59832+ rcu_read_unlock();
59833+ return;
59834+}
59835diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
59836new file mode 100644
59837index 0000000..25197e9
59838--- /dev/null
59839+++ b/grsecurity/gracl_segv.c
59840@@ -0,0 +1,299 @@
59841+#include <linux/kernel.h>
59842+#include <linux/mm.h>
59843+#include <asm/uaccess.h>
59844+#include <asm/errno.h>
59845+#include <asm/mman.h>
59846+#include <net/sock.h>
59847+#include <linux/file.h>
59848+#include <linux/fs.h>
59849+#include <linux/net.h>
59850+#include <linux/in.h>
59851+#include <linux/slab.h>
59852+#include <linux/types.h>
59853+#include <linux/sched.h>
59854+#include <linux/timer.h>
59855+#include <linux/gracl.h>
59856+#include <linux/grsecurity.h>
59857+#include <linux/grinternal.h>
59858+
59859+static struct crash_uid *uid_set;
59860+static unsigned short uid_used;
59861+static DEFINE_SPINLOCK(gr_uid_lock);
59862+extern rwlock_t gr_inode_lock;
59863+extern struct acl_subject_label *
59864+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
59865+ struct acl_role_label *role);
59866+
59867+#ifdef CONFIG_BTRFS_FS
59868+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
59869+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
59870+#endif
59871+
59872+static inline dev_t __get_dev(const struct dentry *dentry)
59873+{
59874+#ifdef CONFIG_BTRFS_FS
59875+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
59876+ return get_btrfs_dev_from_inode(dentry->d_inode);
59877+ else
59878+#endif
59879+ return dentry->d_inode->i_sb->s_dev;
59880+}
59881+
59882+int
59883+gr_init_uidset(void)
59884+{
59885+ uid_set =
59886+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
59887+ uid_used = 0;
59888+
59889+ return uid_set ? 1 : 0;
59890+}
59891+
59892+void
59893+gr_free_uidset(void)
59894+{
59895+ if (uid_set)
59896+ kfree(uid_set);
59897+
59898+ return;
59899+}
59900+
59901+int
59902+gr_find_uid(const uid_t uid)
59903+{
59904+ struct crash_uid *tmp = uid_set;
59905+ uid_t buid;
59906+ int low = 0, high = uid_used - 1, mid;
59907+
59908+ while (high >= low) {
59909+ mid = (low + high) >> 1;
59910+ buid = tmp[mid].uid;
59911+ if (buid == uid)
59912+ return mid;
59913+ if (buid > uid)
59914+ high = mid - 1;
59915+ if (buid < uid)
59916+ low = mid + 1;
59917+ }
59918+
59919+ return -1;
59920+}
59921+
59922+static __inline__ void
59923+gr_insertsort(void)
59924+{
59925+ unsigned short i, j;
59926+ struct crash_uid index;
59927+
59928+ for (i = 1; i < uid_used; i++) {
59929+ index = uid_set[i];
59930+ j = i;
59931+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
59932+ uid_set[j] = uid_set[j - 1];
59933+ j--;
59934+ }
59935+ uid_set[j] = index;
59936+ }
59937+
59938+ return;
59939+}
59940+
59941+static __inline__ void
59942+gr_insert_uid(const uid_t uid, const unsigned long expires)
59943+{
59944+ int loc;
59945+
59946+ if (uid_used == GR_UIDTABLE_MAX)
59947+ return;
59948+
59949+ loc = gr_find_uid(uid);
59950+
59951+ if (loc >= 0) {
59952+ uid_set[loc].expires = expires;
59953+ return;
59954+ }
59955+
59956+ uid_set[uid_used].uid = uid;
59957+ uid_set[uid_used].expires = expires;
59958+ uid_used++;
59959+
59960+ gr_insertsort();
59961+
59962+ return;
59963+}
59964+
59965+void
59966+gr_remove_uid(const unsigned short loc)
59967+{
59968+ unsigned short i;
59969+
59970+ for (i = loc + 1; i < uid_used; i++)
59971+ uid_set[i - 1] = uid_set[i];
59972+
59973+ uid_used--;
59974+
59975+ return;
59976+}
59977+
59978+int
59979+gr_check_crash_uid(const uid_t uid)
59980+{
59981+ int loc;
59982+ int ret = 0;
59983+
59984+ if (unlikely(!gr_acl_is_enabled()))
59985+ return 0;
59986+
59987+ spin_lock(&gr_uid_lock);
59988+ loc = gr_find_uid(uid);
59989+
59990+ if (loc < 0)
59991+ goto out_unlock;
59992+
59993+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
59994+ gr_remove_uid(loc);
59995+ else
59996+ ret = 1;
59997+
59998+out_unlock:
59999+ spin_unlock(&gr_uid_lock);
60000+ return ret;
60001+}
60002+
60003+static __inline__ int
60004+proc_is_setxid(const struct cred *cred)
60005+{
60006+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
60007+ !uid_eq(cred->uid, cred->fsuid))
60008+ return 1;
60009+ if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
60010+ !uid_eq(cred->gid, cred->fsgid))
60011+ return 1;
60012+
60013+ return 0;
60014+}
60015+
60016+extern int gr_fake_force_sig(int sig, struct task_struct *t);
60017+
60018+void
60019+gr_handle_crash(struct task_struct *task, const int sig)
60020+{
60021+ struct acl_subject_label *curr;
60022+ struct task_struct *tsk, *tsk2;
60023+ const struct cred *cred;
60024+ const struct cred *cred2;
60025+
60026+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
60027+ return;
60028+
60029+ if (unlikely(!gr_acl_is_enabled()))
60030+ return;
60031+
60032+ curr = task->acl;
60033+
60034+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
60035+ return;
60036+
60037+ if (time_before_eq(curr->expires, get_seconds())) {
60038+ curr->expires = 0;
60039+ curr->crashes = 0;
60040+ }
60041+
60042+ curr->crashes++;
60043+
60044+ if (!curr->expires)
60045+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
60046+
60047+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
60048+ time_after(curr->expires, get_seconds())) {
60049+ rcu_read_lock();
60050+ cred = __task_cred(task);
60051+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
60052+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
60053+ spin_lock(&gr_uid_lock);
60054+ gr_insert_uid(cred->uid, curr->expires);
60055+ spin_unlock(&gr_uid_lock);
60056+ curr->expires = 0;
60057+ curr->crashes = 0;
60058+ read_lock(&tasklist_lock);
60059+ do_each_thread(tsk2, tsk) {
60060+ cred2 = __task_cred(tsk);
60061+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
60062+ gr_fake_force_sig(SIGKILL, tsk);
60063+ } while_each_thread(tsk2, tsk);
60064+ read_unlock(&tasklist_lock);
60065+ } else {
60066+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
60067+ read_lock(&tasklist_lock);
60068+ read_lock(&grsec_exec_file_lock);
60069+ do_each_thread(tsk2, tsk) {
60070+ if (likely(tsk != task)) {
60071+ // if this thread has the same subject as the one that triggered
60072+ // RES_CRASH and it's the same binary, kill it
60073+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
60074+ gr_fake_force_sig(SIGKILL, tsk);
60075+ }
60076+ } while_each_thread(tsk2, tsk);
60077+ read_unlock(&grsec_exec_file_lock);
60078+ read_unlock(&tasklist_lock);
60079+ }
60080+ rcu_read_unlock();
60081+ }
60082+
60083+ return;
60084+}
60085+
60086+int
60087+gr_check_crash_exec(const struct file *filp)
60088+{
60089+ struct acl_subject_label *curr;
60090+
60091+ if (unlikely(!gr_acl_is_enabled()))
60092+ return 0;
60093+
60094+ read_lock(&gr_inode_lock);
60095+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
60096+ __get_dev(filp->f_path.dentry),
60097+ current->role);
60098+ read_unlock(&gr_inode_lock);
60099+
60100+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
60101+ (!curr->crashes && !curr->expires))
60102+ return 0;
60103+
60104+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
60105+ time_after(curr->expires, get_seconds()))
60106+ return 1;
60107+ else if (time_before_eq(curr->expires, get_seconds())) {
60108+ curr->crashes = 0;
60109+ curr->expires = 0;
60110+ }
60111+
60112+ return 0;
60113+}
60114+
60115+void
60116+gr_handle_alertkill(struct task_struct *task)
60117+{
60118+ struct acl_subject_label *curracl;
60119+ __u32 curr_ip;
60120+ struct task_struct *p, *p2;
60121+
60122+ if (unlikely(!gr_acl_is_enabled()))
60123+ return;
60124+
60125+ curracl = task->acl;
60126+ curr_ip = task->signal->curr_ip;
60127+
60128+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
60129+ read_lock(&tasklist_lock);
60130+ do_each_thread(p2, p) {
60131+ if (p->signal->curr_ip == curr_ip)
60132+ gr_fake_force_sig(SIGKILL, p);
60133+ } while_each_thread(p2, p);
60134+ read_unlock(&tasklist_lock);
60135+ } else if (curracl->mode & GR_KILLPROC)
60136+ gr_fake_force_sig(SIGKILL, task);
60137+
60138+ return;
60139+}
60140diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
60141new file mode 100644
60142index 0000000..9d83a69
60143--- /dev/null
60144+++ b/grsecurity/gracl_shm.c
60145@@ -0,0 +1,40 @@
60146+#include <linux/kernel.h>
60147+#include <linux/mm.h>
60148+#include <linux/sched.h>
60149+#include <linux/file.h>
60150+#include <linux/ipc.h>
60151+#include <linux/gracl.h>
60152+#include <linux/grsecurity.h>
60153+#include <linux/grinternal.h>
60154+
60155+int
60156+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
60157+ const time_t shm_createtime, const uid_t cuid, const int shmid)
60158+{
60159+ struct task_struct *task;
60160+
60161+ if (!gr_acl_is_enabled())
60162+ return 1;
60163+
60164+ rcu_read_lock();
60165+ read_lock(&tasklist_lock);
60166+
60167+ task = find_task_by_vpid(shm_cprid);
60168+
60169+ if (unlikely(!task))
60170+ task = find_task_by_vpid(shm_lapid);
60171+
60172+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
60173+ (task->pid == shm_lapid)) &&
60174+ (task->acl->mode & GR_PROTSHM) &&
60175+ (task->acl != current->acl))) {
60176+ read_unlock(&tasklist_lock);
60177+ rcu_read_unlock();
60178+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
60179+ return 0;
60180+ }
60181+ read_unlock(&tasklist_lock);
60182+ rcu_read_unlock();
60183+
60184+ return 1;
60185+}
60186diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
60187new file mode 100644
60188index 0000000..bc0be01
60189--- /dev/null
60190+++ b/grsecurity/grsec_chdir.c
60191@@ -0,0 +1,19 @@
60192+#include <linux/kernel.h>
60193+#include <linux/sched.h>
60194+#include <linux/fs.h>
60195+#include <linux/file.h>
60196+#include <linux/grsecurity.h>
60197+#include <linux/grinternal.h>
60198+
60199+void
60200+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
60201+{
60202+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60203+ if ((grsec_enable_chdir && grsec_enable_group &&
60204+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
60205+ !grsec_enable_group)) {
60206+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
60207+ }
60208+#endif
60209+ return;
60210+}
60211diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
60212new file mode 100644
60213index 0000000..70fe0ae
60214--- /dev/null
60215+++ b/grsecurity/grsec_chroot.c
60216@@ -0,0 +1,357 @@
60217+#include <linux/kernel.h>
60218+#include <linux/module.h>
60219+#include <linux/sched.h>
60220+#include <linux/file.h>
60221+#include <linux/fs.h>
60222+#include <linux/mount.h>
60223+#include <linux/types.h>
60224+#include "../fs/mount.h"
60225+#include <linux/grsecurity.h>
60226+#include <linux/grinternal.h>
60227+
60228+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
60229+{
60230+#ifdef CONFIG_GRKERNSEC
60231+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
60232+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
60233+ task->gr_is_chrooted = 1;
60234+ else
60235+ task->gr_is_chrooted = 0;
60236+
60237+ task->gr_chroot_dentry = path->dentry;
60238+#endif
60239+ return;
60240+}
60241+
60242+void gr_clear_chroot_entries(struct task_struct *task)
60243+{
60244+#ifdef CONFIG_GRKERNSEC
60245+ task->gr_is_chrooted = 0;
60246+ task->gr_chroot_dentry = NULL;
60247+#endif
60248+ return;
60249+}
60250+
60251+int
60252+gr_handle_chroot_unix(const pid_t pid)
60253+{
60254+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
60255+ struct task_struct *p;
60256+
60257+ if (unlikely(!grsec_enable_chroot_unix))
60258+ return 1;
60259+
60260+ if (likely(!proc_is_chrooted(current)))
60261+ return 1;
60262+
60263+ rcu_read_lock();
60264+ read_lock(&tasklist_lock);
60265+ p = find_task_by_vpid_unrestricted(pid);
60266+ if (unlikely(p && !have_same_root(current, p))) {
60267+ read_unlock(&tasklist_lock);
60268+ rcu_read_unlock();
60269+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
60270+ return 0;
60271+ }
60272+ read_unlock(&tasklist_lock);
60273+ rcu_read_unlock();
60274+#endif
60275+ return 1;
60276+}
60277+
60278+int
60279+gr_handle_chroot_nice(void)
60280+{
60281+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60282+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
60283+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
60284+ return -EPERM;
60285+ }
60286+#endif
60287+ return 0;
60288+}
60289+
60290+int
60291+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
60292+{
60293+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60294+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
60295+ && proc_is_chrooted(current)) {
60296+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
60297+ return -EACCES;
60298+ }
60299+#endif
60300+ return 0;
60301+}
60302+
60303+int
60304+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
60305+{
60306+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60307+ struct task_struct *p;
60308+ int ret = 0;
60309+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
60310+ return ret;
60311+
60312+ read_lock(&tasklist_lock);
60313+ do_each_pid_task(pid, type, p) {
60314+ if (!have_same_root(current, p)) {
60315+ ret = 1;
60316+ goto out;
60317+ }
60318+ } while_each_pid_task(pid, type, p);
60319+out:
60320+ read_unlock(&tasklist_lock);
60321+ return ret;
60322+#endif
60323+ return 0;
60324+}
60325+
60326+int
60327+gr_pid_is_chrooted(struct task_struct *p)
60328+{
60329+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60330+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
60331+ return 0;
60332+
60333+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
60334+ !have_same_root(current, p)) {
60335+ return 1;
60336+ }
60337+#endif
60338+ return 0;
60339+}
60340+
60341+EXPORT_SYMBOL(gr_pid_is_chrooted);
60342+
60343+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
60344+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
60345+{
60346+ struct path path, currentroot;
60347+ int ret = 0;
60348+
60349+ path.dentry = (struct dentry *)u_dentry;
60350+ path.mnt = (struct vfsmount *)u_mnt;
60351+ get_fs_root(current->fs, &currentroot);
60352+ if (path_is_under(&path, &currentroot))
60353+ ret = 1;
60354+ path_put(&currentroot);
60355+
60356+ return ret;
60357+}
60358+#endif
60359+
60360+int
60361+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
60362+{
60363+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60364+ if (!grsec_enable_chroot_fchdir)
60365+ return 1;
60366+
60367+ if (!proc_is_chrooted(current))
60368+ return 1;
60369+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
60370+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
60371+ return 0;
60372+ }
60373+#endif
60374+ return 1;
60375+}
60376+
60377+int
60378+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
60379+ const time_t shm_createtime)
60380+{
60381+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
60382+ struct task_struct *p;
60383+ time_t starttime;
60384+
60385+ if (unlikely(!grsec_enable_chroot_shmat))
60386+ return 1;
60387+
60388+ if (likely(!proc_is_chrooted(current)))
60389+ return 1;
60390+
60391+ rcu_read_lock();
60392+ read_lock(&tasklist_lock);
60393+
60394+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
60395+ starttime = p->start_time.tv_sec;
60396+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
60397+ if (have_same_root(current, p)) {
60398+ goto allow;
60399+ } else {
60400+ read_unlock(&tasklist_lock);
60401+ rcu_read_unlock();
60402+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
60403+ return 0;
60404+ }
60405+ }
60406+ /* creator exited, pid reuse, fall through to next check */
60407+ }
60408+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
60409+ if (unlikely(!have_same_root(current, p))) {
60410+ read_unlock(&tasklist_lock);
60411+ rcu_read_unlock();
60412+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
60413+ return 0;
60414+ }
60415+ }
60416+
60417+allow:
60418+ read_unlock(&tasklist_lock);
60419+ rcu_read_unlock();
60420+#endif
60421+ return 1;
60422+}
60423+
60424+void
60425+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
60426+{
60427+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60428+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
60429+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
60430+#endif
60431+ return;
60432+}
60433+
60434+int
60435+gr_handle_chroot_mknod(const struct dentry *dentry,
60436+ const struct vfsmount *mnt, const int mode)
60437+{
60438+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60439+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
60440+ proc_is_chrooted(current)) {
60441+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
60442+ return -EPERM;
60443+ }
60444+#endif
60445+ return 0;
60446+}
60447+
60448+int
60449+gr_handle_chroot_mount(const struct dentry *dentry,
60450+ const struct vfsmount *mnt, const char *dev_name)
60451+{
60452+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
60453+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
60454+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
60455+ return -EPERM;
60456+ }
60457+#endif
60458+ return 0;
60459+}
60460+
60461+int
60462+gr_handle_chroot_pivot(void)
60463+{
60464+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60465+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
60466+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
60467+ return -EPERM;
60468+ }
60469+#endif
60470+ return 0;
60471+}
60472+
60473+int
60474+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
60475+{
60476+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60477+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
60478+ !gr_is_outside_chroot(dentry, mnt)) {
60479+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
60480+ return -EPERM;
60481+ }
60482+#endif
60483+ return 0;
60484+}
60485+
60486+extern const char *captab_log[];
60487+extern int captab_log_entries;
60488+
60489+int
60490+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
60491+{
60492+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60493+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
60494+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
60495+ if (cap_raised(chroot_caps, cap)) {
60496+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
60497+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
60498+ }
60499+ return 0;
60500+ }
60501+ }
60502+#endif
60503+ return 1;
60504+}
60505+
60506+int
60507+gr_chroot_is_capable(const int cap)
60508+{
60509+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60510+ return gr_task_chroot_is_capable(current, current_cred(), cap);
60511+#endif
60512+ return 1;
60513+}
60514+
60515+int
60516+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
60517+{
60518+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60519+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
60520+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
60521+ if (cap_raised(chroot_caps, cap)) {
60522+ return 0;
60523+ }
60524+ }
60525+#endif
60526+ return 1;
60527+}
60528+
60529+int
60530+gr_chroot_is_capable_nolog(const int cap)
60531+{
60532+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60533+ return gr_task_chroot_is_capable_nolog(current, cap);
60534+#endif
60535+ return 1;
60536+}
60537+
60538+int
60539+gr_handle_chroot_sysctl(const int op)
60540+{
60541+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60542+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
60543+ proc_is_chrooted(current))
60544+ return -EACCES;
60545+#endif
60546+ return 0;
60547+}
60548+
60549+void
60550+gr_handle_chroot_chdir(struct path *path)
60551+{
60552+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60553+ if (grsec_enable_chroot_chdir)
60554+ set_fs_pwd(current->fs, path);
60555+#endif
60556+ return;
60557+}
60558+
60559+int
60560+gr_handle_chroot_chmod(const struct dentry *dentry,
60561+ const struct vfsmount *mnt, const int mode)
60562+{
60563+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60564+ /* allow chmod +s on directories, but not files */
60565+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
60566+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
60567+ proc_is_chrooted(current)) {
60568+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
60569+ return -EPERM;
60570+ }
60571+#endif
60572+ return 0;
60573+}
60574diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
60575new file mode 100644
60576index 0000000..e6796b3
60577--- /dev/null
60578+++ b/grsecurity/grsec_disabled.c
60579@@ -0,0 +1,434 @@
60580+#include <linux/kernel.h>
60581+#include <linux/module.h>
60582+#include <linux/sched.h>
60583+#include <linux/file.h>
60584+#include <linux/fs.h>
60585+#include <linux/kdev_t.h>
60586+#include <linux/net.h>
60587+#include <linux/in.h>
60588+#include <linux/ip.h>
60589+#include <linux/skbuff.h>
60590+#include <linux/sysctl.h>
60591+
60592+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
60593+void
60594+pax_set_initial_flags(struct linux_binprm *bprm)
60595+{
60596+ return;
60597+}
60598+#endif
60599+
60600+#ifdef CONFIG_SYSCTL
60601+__u32
60602+gr_handle_sysctl(const struct ctl_table * table, const int op)
60603+{
60604+ return 0;
60605+}
60606+#endif
60607+
60608+#ifdef CONFIG_TASKSTATS
60609+int gr_is_taskstats_denied(int pid)
60610+{
60611+ return 0;
60612+}
60613+#endif
60614+
60615+int
60616+gr_acl_is_enabled(void)
60617+{
60618+ return 0;
60619+}
60620+
60621+void
60622+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
60623+{
60624+ return;
60625+}
60626+
60627+int
60628+gr_handle_rawio(const struct inode *inode)
60629+{
60630+ return 0;
60631+}
60632+
60633+void
60634+gr_acl_handle_psacct(struct task_struct *task, const long code)
60635+{
60636+ return;
60637+}
60638+
60639+int
60640+gr_handle_ptrace(struct task_struct *task, const long request)
60641+{
60642+ return 0;
60643+}
60644+
60645+int
60646+gr_handle_proc_ptrace(struct task_struct *task)
60647+{
60648+ return 0;
60649+}
60650+
60651+int
60652+gr_set_acls(const int type)
60653+{
60654+ return 0;
60655+}
60656+
60657+int
60658+gr_check_hidden_task(const struct task_struct *tsk)
60659+{
60660+ return 0;
60661+}
60662+
60663+int
60664+gr_check_protected_task(const struct task_struct *task)
60665+{
60666+ return 0;
60667+}
60668+
60669+int
60670+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
60671+{
60672+ return 0;
60673+}
60674+
60675+void
60676+gr_copy_label(struct task_struct *tsk)
60677+{
60678+ return;
60679+}
60680+
60681+void
60682+gr_set_pax_flags(struct task_struct *task)
60683+{
60684+ return;
60685+}
60686+
60687+int
60688+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
60689+ const int unsafe_share)
60690+{
60691+ return 0;
60692+}
60693+
60694+void
60695+gr_handle_delete(const ino_t ino, const dev_t dev)
60696+{
60697+ return;
60698+}
60699+
60700+void
60701+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
60702+{
60703+ return;
60704+}
60705+
60706+void
60707+gr_handle_crash(struct task_struct *task, const int sig)
60708+{
60709+ return;
60710+}
60711+
60712+int
60713+gr_check_crash_exec(const struct file *filp)
60714+{
60715+ return 0;
60716+}
60717+
60718+int
60719+gr_check_crash_uid(const uid_t uid)
60720+{
60721+ return 0;
60722+}
60723+
60724+void
60725+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
60726+ struct dentry *old_dentry,
60727+ struct dentry *new_dentry,
60728+ struct vfsmount *mnt, const __u8 replace)
60729+{
60730+ return;
60731+}
60732+
60733+int
60734+gr_search_socket(const int family, const int type, const int protocol)
60735+{
60736+ return 1;
60737+}
60738+
60739+int
60740+gr_search_connectbind(const int mode, const struct socket *sock,
60741+ const struct sockaddr_in *addr)
60742+{
60743+ return 0;
60744+}
60745+
60746+void
60747+gr_handle_alertkill(struct task_struct *task)
60748+{
60749+ return;
60750+}
60751+
60752+__u32
60753+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
60754+{
60755+ return 1;
60756+}
60757+
60758+__u32
60759+gr_acl_handle_hidden_file(const struct dentry * dentry,
60760+ const struct vfsmount * mnt)
60761+{
60762+ return 1;
60763+}
60764+
60765+__u32
60766+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
60767+ int acc_mode)
60768+{
60769+ return 1;
60770+}
60771+
60772+__u32
60773+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
60774+{
60775+ return 1;
60776+}
60777+
60778+__u32
60779+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
60780+{
60781+ return 1;
60782+}
60783+
60784+int
60785+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
60786+ unsigned int *vm_flags)
60787+{
60788+ return 1;
60789+}
60790+
60791+__u32
60792+gr_acl_handle_truncate(const struct dentry * dentry,
60793+ const struct vfsmount * mnt)
60794+{
60795+ return 1;
60796+}
60797+
60798+__u32
60799+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
60800+{
60801+ return 1;
60802+}
60803+
60804+__u32
60805+gr_acl_handle_access(const struct dentry * dentry,
60806+ const struct vfsmount * mnt, const int fmode)
60807+{
60808+ return 1;
60809+}
60810+
60811+__u32
60812+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
60813+ umode_t *mode)
60814+{
60815+ return 1;
60816+}
60817+
60818+__u32
60819+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
60820+{
60821+ return 1;
60822+}
60823+
60824+__u32
60825+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
60826+{
60827+ return 1;
60828+}
60829+
60830+void
60831+grsecurity_init(void)
60832+{
60833+ return;
60834+}
60835+
60836+umode_t gr_acl_umask(void)
60837+{
60838+ return 0;
60839+}
60840+
60841+__u32
60842+gr_acl_handle_mknod(const struct dentry * new_dentry,
60843+ const struct dentry * parent_dentry,
60844+ const struct vfsmount * parent_mnt,
60845+ const int mode)
60846+{
60847+ return 1;
60848+}
60849+
60850+__u32
60851+gr_acl_handle_mkdir(const struct dentry * new_dentry,
60852+ const struct dentry * parent_dentry,
60853+ const struct vfsmount * parent_mnt)
60854+{
60855+ return 1;
60856+}
60857+
60858+__u32
60859+gr_acl_handle_symlink(const struct dentry * new_dentry,
60860+ const struct dentry * parent_dentry,
60861+ const struct vfsmount * parent_mnt, const struct filename *from)
60862+{
60863+ return 1;
60864+}
60865+
60866+__u32
60867+gr_acl_handle_link(const struct dentry * new_dentry,
60868+ const struct dentry * parent_dentry,
60869+ const struct vfsmount * parent_mnt,
60870+ const struct dentry * old_dentry,
60871+ const struct vfsmount * old_mnt, const struct filename *to)
60872+{
60873+ return 1;
60874+}
60875+
60876+int
60877+gr_acl_handle_rename(const struct dentry *new_dentry,
60878+ const struct dentry *parent_dentry,
60879+ const struct vfsmount *parent_mnt,
60880+ const struct dentry *old_dentry,
60881+ const struct inode *old_parent_inode,
60882+ const struct vfsmount *old_mnt, const struct filename *newname)
60883+{
60884+ return 0;
60885+}
60886+
60887+int
60888+gr_acl_handle_filldir(const struct file *file, const char *name,
60889+ const int namelen, const ino_t ino)
60890+{
60891+ return 1;
60892+}
60893+
60894+int
60895+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
60896+ const time_t shm_createtime, const uid_t cuid, const int shmid)
60897+{
60898+ return 1;
60899+}
60900+
60901+int
60902+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
60903+{
60904+ return 0;
60905+}
60906+
60907+int
60908+gr_search_accept(const struct socket *sock)
60909+{
60910+ return 0;
60911+}
60912+
60913+int
60914+gr_search_listen(const struct socket *sock)
60915+{
60916+ return 0;
60917+}
60918+
60919+int
60920+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
60921+{
60922+ return 0;
60923+}
60924+
60925+__u32
60926+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
60927+{
60928+ return 1;
60929+}
60930+
60931+__u32
60932+gr_acl_handle_creat(const struct dentry * dentry,
60933+ const struct dentry * p_dentry,
60934+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
60935+ const int imode)
60936+{
60937+ return 1;
60938+}
60939+
60940+void
60941+gr_acl_handle_exit(void)
60942+{
60943+ return;
60944+}
60945+
60946+int
60947+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
60948+{
60949+ return 1;
60950+}
60951+
60952+void
60953+gr_set_role_label(const uid_t uid, const gid_t gid)
60954+{
60955+ return;
60956+}
60957+
60958+int
60959+gr_acl_handle_procpidmem(const struct task_struct *task)
60960+{
60961+ return 0;
60962+}
60963+
60964+int
60965+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
60966+{
60967+ return 0;
60968+}
60969+
60970+int
60971+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
60972+{
60973+ return 0;
60974+}
60975+
60976+void
60977+gr_set_kernel_label(struct task_struct *task)
60978+{
60979+ return;
60980+}
60981+
60982+int
60983+gr_check_user_change(int real, int effective, int fs)
60984+{
60985+ return 0;
60986+}
60987+
60988+int
60989+gr_check_group_change(int real, int effective, int fs)
60990+{
60991+ return 0;
60992+}
60993+
60994+int gr_acl_enable_at_secure(void)
60995+{
60996+ return 0;
60997+}
60998+
60999+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
61000+{
61001+ return dentry->d_inode->i_sb->s_dev;
61002+}
61003+
61004+void gr_put_exec_file(struct task_struct *task)
61005+{
61006+ return;
61007+}
61008+
61009+EXPORT_SYMBOL(gr_set_kernel_label);
61010+#ifdef CONFIG_SECURITY
61011+EXPORT_SYMBOL(gr_check_user_change);
61012+EXPORT_SYMBOL(gr_check_group_change);
61013+#endif
61014diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
61015new file mode 100644
61016index 0000000..abfa971
61017--- /dev/null
61018+++ b/grsecurity/grsec_exec.c
61019@@ -0,0 +1,174 @@
61020+#include <linux/kernel.h>
61021+#include <linux/sched.h>
61022+#include <linux/file.h>
61023+#include <linux/binfmts.h>
61024+#include <linux/fs.h>
61025+#include <linux/types.h>
61026+#include <linux/grdefs.h>
61027+#include <linux/grsecurity.h>
61028+#include <linux/grinternal.h>
61029+#include <linux/capability.h>
61030+#include <linux/module.h>
61031+
61032+#include <asm/uaccess.h>
61033+
61034+#ifdef CONFIG_GRKERNSEC_EXECLOG
61035+static char gr_exec_arg_buf[132];
61036+static DEFINE_MUTEX(gr_exec_arg_mutex);
61037+#endif
61038+
61039+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
61040+
61041+void
61042+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
61043+{
61044+#ifdef CONFIG_GRKERNSEC_EXECLOG
61045+ char *grarg = gr_exec_arg_buf;
61046+ unsigned int i, x, execlen = 0;
61047+ char c;
61048+
61049+ if (!((grsec_enable_execlog && grsec_enable_group &&
61050+ in_group_p(grsec_audit_gid))
61051+ || (grsec_enable_execlog && !grsec_enable_group)))
61052+ return;
61053+
61054+ mutex_lock(&gr_exec_arg_mutex);
61055+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
61056+
61057+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
61058+ const char __user *p;
61059+ unsigned int len;
61060+
61061+ p = get_user_arg_ptr(argv, i);
61062+ if (IS_ERR(p))
61063+ goto log;
61064+
61065+ len = strnlen_user(p, 128 - execlen);
61066+ if (len > 128 - execlen)
61067+ len = 128 - execlen;
61068+ else if (len > 0)
61069+ len--;
61070+ if (copy_from_user(grarg + execlen, p, len))
61071+ goto log;
61072+
61073+ /* rewrite unprintable characters */
61074+ for (x = 0; x < len; x++) {
61075+ c = *(grarg + execlen + x);
61076+ if (c < 32 || c > 126)
61077+ *(grarg + execlen + x) = ' ';
61078+ }
61079+
61080+ execlen += len;
61081+ *(grarg + execlen) = ' ';
61082+ *(grarg + execlen + 1) = '\0';
61083+ execlen++;
61084+ }
61085+
61086+ log:
61087+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
61088+ bprm->file->f_path.mnt, grarg);
61089+ mutex_unlock(&gr_exec_arg_mutex);
61090+#endif
61091+ return;
61092+}
61093+
61094+#ifdef CONFIG_GRKERNSEC
61095+extern int gr_acl_is_capable(const int cap);
61096+extern int gr_acl_is_capable_nolog(const int cap);
61097+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
61098+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
61099+extern int gr_chroot_is_capable(const int cap);
61100+extern int gr_chroot_is_capable_nolog(const int cap);
61101+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
61102+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
61103+#endif
61104+
61105+const char *captab_log[] = {
61106+ "CAP_CHOWN",
61107+ "CAP_DAC_OVERRIDE",
61108+ "CAP_DAC_READ_SEARCH",
61109+ "CAP_FOWNER",
61110+ "CAP_FSETID",
61111+ "CAP_KILL",
61112+ "CAP_SETGID",
61113+ "CAP_SETUID",
61114+ "CAP_SETPCAP",
61115+ "CAP_LINUX_IMMUTABLE",
61116+ "CAP_NET_BIND_SERVICE",
61117+ "CAP_NET_BROADCAST",
61118+ "CAP_NET_ADMIN",
61119+ "CAP_NET_RAW",
61120+ "CAP_IPC_LOCK",
61121+ "CAP_IPC_OWNER",
61122+ "CAP_SYS_MODULE",
61123+ "CAP_SYS_RAWIO",
61124+ "CAP_SYS_CHROOT",
61125+ "CAP_SYS_PTRACE",
61126+ "CAP_SYS_PACCT",
61127+ "CAP_SYS_ADMIN",
61128+ "CAP_SYS_BOOT",
61129+ "CAP_SYS_NICE",
61130+ "CAP_SYS_RESOURCE",
61131+ "CAP_SYS_TIME",
61132+ "CAP_SYS_TTY_CONFIG",
61133+ "CAP_MKNOD",
61134+ "CAP_LEASE",
61135+ "CAP_AUDIT_WRITE",
61136+ "CAP_AUDIT_CONTROL",
61137+ "CAP_SETFCAP",
61138+ "CAP_MAC_OVERRIDE",
61139+ "CAP_MAC_ADMIN",
61140+ "CAP_SYSLOG",
61141+ "CAP_WAKE_ALARM"
61142+};
61143+
61144+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
61145+
61146+int gr_is_capable(const int cap)
61147+{
61148+#ifdef CONFIG_GRKERNSEC
61149+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
61150+ return 1;
61151+ return 0;
61152+#else
61153+ return 1;
61154+#endif
61155+}
61156+
61157+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
61158+{
61159+#ifdef CONFIG_GRKERNSEC
61160+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
61161+ return 1;
61162+ return 0;
61163+#else
61164+ return 1;
61165+#endif
61166+}
61167+
61168+int gr_is_capable_nolog(const int cap)
61169+{
61170+#ifdef CONFIG_GRKERNSEC
61171+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
61172+ return 1;
61173+ return 0;
61174+#else
61175+ return 1;
61176+#endif
61177+}
61178+
61179+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
61180+{
61181+#ifdef CONFIG_GRKERNSEC
61182+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
61183+ return 1;
61184+ return 0;
61185+#else
61186+ return 1;
61187+#endif
61188+}
61189+
61190+EXPORT_SYMBOL(gr_is_capable);
61191+EXPORT_SYMBOL(gr_is_capable_nolog);
61192+EXPORT_SYMBOL(gr_task_is_capable);
61193+EXPORT_SYMBOL(gr_task_is_capable_nolog);
61194diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
61195new file mode 100644
61196index 0000000..d3ee748
61197--- /dev/null
61198+++ b/grsecurity/grsec_fifo.c
61199@@ -0,0 +1,24 @@
61200+#include <linux/kernel.h>
61201+#include <linux/sched.h>
61202+#include <linux/fs.h>
61203+#include <linux/file.h>
61204+#include <linux/grinternal.h>
61205+
61206+int
61207+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
61208+ const struct dentry *dir, const int flag, const int acc_mode)
61209+{
61210+#ifdef CONFIG_GRKERNSEC_FIFO
61211+ const struct cred *cred = current_cred();
61212+
61213+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
61214+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
61215+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
61216+ (cred->fsuid != dentry->d_inode->i_uid)) {
61217+ if (!inode_permission(dentry->d_inode, acc_mode))
61218+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
61219+ return -EACCES;
61220+ }
61221+#endif
61222+ return 0;
61223+}
61224diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
61225new file mode 100644
61226index 0000000..8ca18bf
61227--- /dev/null
61228+++ b/grsecurity/grsec_fork.c
61229@@ -0,0 +1,23 @@
61230+#include <linux/kernel.h>
61231+#include <linux/sched.h>
61232+#include <linux/grsecurity.h>
61233+#include <linux/grinternal.h>
61234+#include <linux/errno.h>
61235+
61236+void
61237+gr_log_forkfail(const int retval)
61238+{
61239+#ifdef CONFIG_GRKERNSEC_FORKFAIL
61240+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
61241+ switch (retval) {
61242+ case -EAGAIN:
61243+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
61244+ break;
61245+ case -ENOMEM:
61246+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
61247+ break;
61248+ }
61249+ }
61250+#endif
61251+ return;
61252+}
61253diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
61254new file mode 100644
61255index 0000000..05a6015
61256--- /dev/null
61257+++ b/grsecurity/grsec_init.c
61258@@ -0,0 +1,283 @@
61259+#include <linux/kernel.h>
61260+#include <linux/sched.h>
61261+#include <linux/mm.h>
61262+#include <linux/gracl.h>
61263+#include <linux/slab.h>
61264+#include <linux/vmalloc.h>
61265+#include <linux/percpu.h>
61266+#include <linux/module.h>
61267+
61268+int grsec_enable_ptrace_readexec;
61269+int grsec_enable_setxid;
61270+int grsec_enable_symlinkown;
61271+int grsec_symlinkown_gid;
61272+int grsec_enable_brute;
61273+int grsec_enable_link;
61274+int grsec_enable_dmesg;
61275+int grsec_enable_harden_ptrace;
61276+int grsec_enable_fifo;
61277+int grsec_enable_execlog;
61278+int grsec_enable_signal;
61279+int grsec_enable_forkfail;
61280+int grsec_enable_audit_ptrace;
61281+int grsec_enable_time;
61282+int grsec_enable_audit_textrel;
61283+int grsec_enable_group;
61284+int grsec_audit_gid;
61285+int grsec_enable_chdir;
61286+int grsec_enable_mount;
61287+int grsec_enable_rofs;
61288+int grsec_enable_chroot_findtask;
61289+int grsec_enable_chroot_mount;
61290+int grsec_enable_chroot_shmat;
61291+int grsec_enable_chroot_fchdir;
61292+int grsec_enable_chroot_double;
61293+int grsec_enable_chroot_pivot;
61294+int grsec_enable_chroot_chdir;
61295+int grsec_enable_chroot_chmod;
61296+int grsec_enable_chroot_mknod;
61297+int grsec_enable_chroot_nice;
61298+int grsec_enable_chroot_execlog;
61299+int grsec_enable_chroot_caps;
61300+int grsec_enable_chroot_sysctl;
61301+int grsec_enable_chroot_unix;
61302+int grsec_enable_tpe;
61303+int grsec_tpe_gid;
61304+int grsec_enable_blackhole;
61305+#ifdef CONFIG_IPV6_MODULE
61306+EXPORT_SYMBOL(grsec_enable_blackhole);
61307+#endif
61308+int grsec_lastack_retries;
61309+int grsec_enable_tpe_all;
61310+int grsec_enable_tpe_invert;
61311+int grsec_enable_socket_all;
61312+int grsec_socket_all_gid;
61313+int grsec_enable_socket_client;
61314+int grsec_socket_client_gid;
61315+int grsec_enable_socket_server;
61316+int grsec_socket_server_gid;
61317+int grsec_resource_logging;
61318+int grsec_disable_privio;
61319+int grsec_enable_log_rwxmaps;
61320+int grsec_lock;
61321+
61322+DEFINE_SPINLOCK(grsec_alert_lock);
61323+unsigned long grsec_alert_wtime = 0;
61324+unsigned long grsec_alert_fyet = 0;
61325+
61326+DEFINE_SPINLOCK(grsec_audit_lock);
61327+
61328+DEFINE_RWLOCK(grsec_exec_file_lock);
61329+
61330+char *gr_shared_page[4];
61331+
61332+char *gr_alert_log_fmt;
61333+char *gr_audit_log_fmt;
61334+char *gr_alert_log_buf;
61335+char *gr_audit_log_buf;
61336+
61337+extern struct gr_arg *gr_usermode;
61338+extern unsigned char *gr_system_salt;
61339+extern unsigned char *gr_system_sum;
61340+
61341+void __init
61342+grsecurity_init(void)
61343+{
61344+ int j;
61345+ /* create the per-cpu shared pages */
61346+
61347+#ifdef CONFIG_X86
61348+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
61349+#endif
61350+
61351+ for (j = 0; j < 4; j++) {
61352+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
61353+ if (gr_shared_page[j] == NULL) {
61354+ panic("Unable to allocate grsecurity shared page");
61355+ return;
61356+ }
61357+ }
61358+
61359+ /* allocate log buffers */
61360+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
61361+ if (!gr_alert_log_fmt) {
61362+ panic("Unable to allocate grsecurity alert log format buffer");
61363+ return;
61364+ }
61365+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
61366+ if (!gr_audit_log_fmt) {
61367+ panic("Unable to allocate grsecurity audit log format buffer");
61368+ return;
61369+ }
61370+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
61371+ if (!gr_alert_log_buf) {
61372+ panic("Unable to allocate grsecurity alert log buffer");
61373+ return;
61374+ }
61375+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
61376+ if (!gr_audit_log_buf) {
61377+ panic("Unable to allocate grsecurity audit log buffer");
61378+ return;
61379+ }
61380+
61381+ /* allocate memory for authentication structure */
61382+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
61383+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
61384+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
61385+
61386+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
61387+ panic("Unable to allocate grsecurity authentication structure");
61388+ return;
61389+ }
61390+
61391+
61392+#ifdef CONFIG_GRKERNSEC_IO
61393+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
61394+ grsec_disable_privio = 1;
61395+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
61396+ grsec_disable_privio = 1;
61397+#else
61398+ grsec_disable_privio = 0;
61399+#endif
61400+#endif
61401+
61402+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
61403+ /* for backward compatibility, tpe_invert always defaults to on if
61404+ enabled in the kernel
61405+ */
61406+ grsec_enable_tpe_invert = 1;
61407+#endif
61408+
61409+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
61410+#ifndef CONFIG_GRKERNSEC_SYSCTL
61411+ grsec_lock = 1;
61412+#endif
61413+
61414+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
61415+ grsec_enable_audit_textrel = 1;
61416+#endif
61417+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61418+ grsec_enable_log_rwxmaps = 1;
61419+#endif
61420+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
61421+ grsec_enable_group = 1;
61422+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
61423+#endif
61424+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
61425+ grsec_enable_ptrace_readexec = 1;
61426+#endif
61427+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
61428+ grsec_enable_chdir = 1;
61429+#endif
61430+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61431+ grsec_enable_harden_ptrace = 1;
61432+#endif
61433+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61434+ grsec_enable_mount = 1;
61435+#endif
61436+#ifdef CONFIG_GRKERNSEC_LINK
61437+ grsec_enable_link = 1;
61438+#endif
61439+#ifdef CONFIG_GRKERNSEC_BRUTE
61440+ grsec_enable_brute = 1;
61441+#endif
61442+#ifdef CONFIG_GRKERNSEC_DMESG
61443+ grsec_enable_dmesg = 1;
61444+#endif
61445+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
61446+ grsec_enable_blackhole = 1;
61447+ grsec_lastack_retries = 4;
61448+#endif
61449+#ifdef CONFIG_GRKERNSEC_FIFO
61450+ grsec_enable_fifo = 1;
61451+#endif
61452+#ifdef CONFIG_GRKERNSEC_EXECLOG
61453+ grsec_enable_execlog = 1;
61454+#endif
61455+#ifdef CONFIG_GRKERNSEC_SETXID
61456+ grsec_enable_setxid = 1;
61457+#endif
61458+#ifdef CONFIG_GRKERNSEC_SIGNAL
61459+ grsec_enable_signal = 1;
61460+#endif
61461+#ifdef CONFIG_GRKERNSEC_FORKFAIL
61462+ grsec_enable_forkfail = 1;
61463+#endif
61464+#ifdef CONFIG_GRKERNSEC_TIME
61465+ grsec_enable_time = 1;
61466+#endif
61467+#ifdef CONFIG_GRKERNSEC_RESLOG
61468+ grsec_resource_logging = 1;
61469+#endif
61470+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61471+ grsec_enable_chroot_findtask = 1;
61472+#endif
61473+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
61474+ grsec_enable_chroot_unix = 1;
61475+#endif
61476+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
61477+ grsec_enable_chroot_mount = 1;
61478+#endif
61479+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
61480+ grsec_enable_chroot_fchdir = 1;
61481+#endif
61482+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
61483+ grsec_enable_chroot_shmat = 1;
61484+#endif
61485+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
61486+ grsec_enable_audit_ptrace = 1;
61487+#endif
61488+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
61489+ grsec_enable_chroot_double = 1;
61490+#endif
61491+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
61492+ grsec_enable_chroot_pivot = 1;
61493+#endif
61494+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
61495+ grsec_enable_chroot_chdir = 1;
61496+#endif
61497+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
61498+ grsec_enable_chroot_chmod = 1;
61499+#endif
61500+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
61501+ grsec_enable_chroot_mknod = 1;
61502+#endif
61503+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
61504+ grsec_enable_chroot_nice = 1;
61505+#endif
61506+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
61507+ grsec_enable_chroot_execlog = 1;
61508+#endif
61509+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
61510+ grsec_enable_chroot_caps = 1;
61511+#endif
61512+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
61513+ grsec_enable_chroot_sysctl = 1;
61514+#endif
61515+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
61516+ grsec_enable_symlinkown = 1;
61517+ grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
61518+#endif
61519+#ifdef CONFIG_GRKERNSEC_TPE
61520+ grsec_enable_tpe = 1;
61521+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
61522+#ifdef CONFIG_GRKERNSEC_TPE_ALL
61523+ grsec_enable_tpe_all = 1;
61524+#endif
61525+#endif
61526+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
61527+ grsec_enable_socket_all = 1;
61528+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
61529+#endif
61530+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
61531+ grsec_enable_socket_client = 1;
61532+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
61533+#endif
61534+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61535+ grsec_enable_socket_server = 1;
61536+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
61537+#endif
61538+#endif
61539+
61540+ return;
61541+}
61542diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
61543new file mode 100644
61544index 0000000..6095407
61545--- /dev/null
61546+++ b/grsecurity/grsec_link.c
61547@@ -0,0 +1,58 @@
61548+#include <linux/kernel.h>
61549+#include <linux/sched.h>
61550+#include <linux/fs.h>
61551+#include <linux/file.h>
61552+#include <linux/grinternal.h>
61553+
61554+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
61555+{
61556+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
61557+ const struct inode *link_inode = link->dentry->d_inode;
61558+
61559+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
61560+ /* ignore root-owned links, e.g. /proc/self */
61561+ !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
61562+ !uid_eq(link_inode->i_uid, target->i_uid)) {
61563+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
61564+ return 1;
61565+ }
61566+#endif
61567+ return 0;
61568+}
61569+
61570+int
61571+gr_handle_follow_link(const struct inode *parent,
61572+ const struct inode *inode,
61573+ const struct dentry *dentry, const struct vfsmount *mnt)
61574+{
61575+#ifdef CONFIG_GRKERNSEC_LINK
61576+ const struct cred *cred = current_cred();
61577+
61578+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
61579+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
61580+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
61581+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
61582+ return -EACCES;
61583+ }
61584+#endif
61585+ return 0;
61586+}
61587+
61588+int
61589+gr_handle_hardlink(const struct dentry *dentry,
61590+ const struct vfsmount *mnt,
61591+ struct inode *inode, const int mode, const struct filename *to)
61592+{
61593+#ifdef CONFIG_GRKERNSEC_LINK
61594+ const struct cred *cred = current_cred();
61595+
61596+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
61597+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
61598+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
61599+ !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
61600+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
61601+ return -EPERM;
61602+ }
61603+#endif
61604+ return 0;
61605+}
61606diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
61607new file mode 100644
61608index 0000000..7bd6c2b
61609--- /dev/null
61610+++ b/grsecurity/grsec_log.c
61611@@ -0,0 +1,329 @@
61612+#include <linux/kernel.h>
61613+#include <linux/sched.h>
61614+#include <linux/file.h>
61615+#include <linux/tty.h>
61616+#include <linux/fs.h>
61617+#include <linux/grinternal.h>
61618+
61619+#ifdef CONFIG_TREE_PREEMPT_RCU
61620+#define DISABLE_PREEMPT() preempt_disable()
61621+#define ENABLE_PREEMPT() preempt_enable()
61622+#else
61623+#define DISABLE_PREEMPT()
61624+#define ENABLE_PREEMPT()
61625+#endif
61626+
61627+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
61628+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
61629+
61630+#define BEGIN_LOCKS(x) \
61631+ DISABLE_PREEMPT(); \
61632+ rcu_read_lock(); \
61633+ read_lock(&tasklist_lock); \
61634+ read_lock(&grsec_exec_file_lock); \
61635+ if (x != GR_DO_AUDIT) \
61636+ spin_lock(&grsec_alert_lock); \
61637+ else \
61638+ spin_lock(&grsec_audit_lock)
61639+
61640+#define END_LOCKS(x) \
61641+ if (x != GR_DO_AUDIT) \
61642+ spin_unlock(&grsec_alert_lock); \
61643+ else \
61644+ spin_unlock(&grsec_audit_lock); \
61645+ read_unlock(&grsec_exec_file_lock); \
61646+ read_unlock(&tasklist_lock); \
61647+ rcu_read_unlock(); \
61648+ ENABLE_PREEMPT(); \
61649+ if (x == GR_DONT_AUDIT) \
61650+ gr_handle_alertkill(current)
61651+
61652+enum {
61653+ FLOODING,
61654+ NO_FLOODING
61655+};
61656+
61657+extern char *gr_alert_log_fmt;
61658+extern char *gr_audit_log_fmt;
61659+extern char *gr_alert_log_buf;
61660+extern char *gr_audit_log_buf;
61661+
61662+static int gr_log_start(int audit)
61663+{
61664+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
61665+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
61666+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
61667+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
61668+ unsigned long curr_secs = get_seconds();
61669+
61670+ if (audit == GR_DO_AUDIT)
61671+ goto set_fmt;
61672+
61673+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
61674+ grsec_alert_wtime = curr_secs;
61675+ grsec_alert_fyet = 0;
61676+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
61677+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
61678+ grsec_alert_fyet++;
61679+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
61680+ grsec_alert_wtime = curr_secs;
61681+ grsec_alert_fyet++;
61682+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
61683+ return FLOODING;
61684+ }
61685+ else return FLOODING;
61686+
61687+set_fmt:
61688+#endif
61689+ memset(buf, 0, PAGE_SIZE);
61690+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
61691+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
61692+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
61693+ } else if (current->signal->curr_ip) {
61694+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
61695+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
61696+ } else if (gr_acl_is_enabled()) {
61697+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
61698+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
61699+ } else {
61700+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
61701+ strcpy(buf, fmt);
61702+ }
61703+
61704+ return NO_FLOODING;
61705+}
61706+
61707+static void gr_log_middle(int audit, const char *msg, va_list ap)
61708+ __attribute__ ((format (printf, 2, 0)));
61709+
61710+static void gr_log_middle(int audit, const char *msg, va_list ap)
61711+{
61712+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
61713+ unsigned int len = strlen(buf);
61714+
61715+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
61716+
61717+ return;
61718+}
61719+
61720+static void gr_log_middle_varargs(int audit, const char *msg, ...)
61721+ __attribute__ ((format (printf, 2, 3)));
61722+
61723+static void gr_log_middle_varargs(int audit, const char *msg, ...)
61724+{
61725+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
61726+ unsigned int len = strlen(buf);
61727+ va_list ap;
61728+
61729+ va_start(ap, msg);
61730+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
61731+ va_end(ap);
61732+
61733+ return;
61734+}
61735+
61736+static void gr_log_end(int audit, int append_default)
61737+{
61738+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
61739+ if (append_default) {
61740+ struct task_struct *task = current;
61741+ struct task_struct *parent = task->real_parent;
61742+ const struct cred *cred = __task_cred(task);
61743+ const struct cred *pcred = __task_cred(parent);
61744+ unsigned int len = strlen(buf);
61745+
61746+ 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));
61747+ }
61748+
61749+ printk("%s\n", buf);
61750+
61751+ return;
61752+}
61753+
61754+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
61755+{
61756+ int logtype;
61757+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
61758+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
61759+ void *voidptr = NULL;
61760+ int num1 = 0, num2 = 0;
61761+ unsigned long ulong1 = 0, ulong2 = 0;
61762+ struct dentry *dentry = NULL;
61763+ struct vfsmount *mnt = NULL;
61764+ struct file *file = NULL;
61765+ struct task_struct *task = NULL;
61766+ const struct cred *cred, *pcred;
61767+ va_list ap;
61768+
61769+ BEGIN_LOCKS(audit);
61770+ logtype = gr_log_start(audit);
61771+ if (logtype == FLOODING) {
61772+ END_LOCKS(audit);
61773+ return;
61774+ }
61775+ va_start(ap, argtypes);
61776+ switch (argtypes) {
61777+ case GR_TTYSNIFF:
61778+ task = va_arg(ap, struct task_struct *);
61779+ 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));
61780+ break;
61781+ case GR_SYSCTL_HIDDEN:
61782+ str1 = va_arg(ap, char *);
61783+ gr_log_middle_varargs(audit, msg, result, str1);
61784+ break;
61785+ case GR_RBAC:
61786+ dentry = va_arg(ap, struct dentry *);
61787+ mnt = va_arg(ap, struct vfsmount *);
61788+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
61789+ break;
61790+ case GR_RBAC_STR:
61791+ dentry = va_arg(ap, struct dentry *);
61792+ mnt = va_arg(ap, struct vfsmount *);
61793+ str1 = va_arg(ap, char *);
61794+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
61795+ break;
61796+ case GR_STR_RBAC:
61797+ str1 = va_arg(ap, char *);
61798+ dentry = va_arg(ap, struct dentry *);
61799+ mnt = va_arg(ap, struct vfsmount *);
61800+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
61801+ break;
61802+ case GR_RBAC_MODE2:
61803+ dentry = va_arg(ap, struct dentry *);
61804+ mnt = va_arg(ap, struct vfsmount *);
61805+ str1 = va_arg(ap, char *);
61806+ str2 = va_arg(ap, char *);
61807+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
61808+ break;
61809+ case GR_RBAC_MODE3:
61810+ dentry = va_arg(ap, struct dentry *);
61811+ mnt = va_arg(ap, struct vfsmount *);
61812+ str1 = va_arg(ap, char *);
61813+ str2 = va_arg(ap, char *);
61814+ str3 = va_arg(ap, char *);
61815+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
61816+ break;
61817+ case GR_FILENAME:
61818+ dentry = va_arg(ap, struct dentry *);
61819+ mnt = va_arg(ap, struct vfsmount *);
61820+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
61821+ break;
61822+ case GR_STR_FILENAME:
61823+ str1 = va_arg(ap, char *);
61824+ dentry = va_arg(ap, struct dentry *);
61825+ mnt = va_arg(ap, struct vfsmount *);
61826+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
61827+ break;
61828+ case GR_FILENAME_STR:
61829+ dentry = va_arg(ap, struct dentry *);
61830+ mnt = va_arg(ap, struct vfsmount *);
61831+ str1 = va_arg(ap, char *);
61832+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
61833+ break;
61834+ case GR_FILENAME_TWO_INT:
61835+ dentry = va_arg(ap, struct dentry *);
61836+ mnt = va_arg(ap, struct vfsmount *);
61837+ num1 = va_arg(ap, int);
61838+ num2 = va_arg(ap, int);
61839+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
61840+ break;
61841+ case GR_FILENAME_TWO_INT_STR:
61842+ dentry = va_arg(ap, struct dentry *);
61843+ mnt = va_arg(ap, struct vfsmount *);
61844+ num1 = va_arg(ap, int);
61845+ num2 = va_arg(ap, int);
61846+ str1 = va_arg(ap, char *);
61847+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
61848+ break;
61849+ case GR_TEXTREL:
61850+ file = va_arg(ap, struct file *);
61851+ ulong1 = va_arg(ap, unsigned long);
61852+ ulong2 = va_arg(ap, unsigned long);
61853+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
61854+ break;
61855+ case GR_PTRACE:
61856+ task = va_arg(ap, struct task_struct *);
61857+ 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));
61858+ break;
61859+ case GR_RESOURCE:
61860+ task = va_arg(ap, struct task_struct *);
61861+ cred = __task_cred(task);
61862+ pcred = __task_cred(task->real_parent);
61863+ ulong1 = va_arg(ap, unsigned long);
61864+ str1 = va_arg(ap, char *);
61865+ ulong2 = va_arg(ap, unsigned long);
61866+ 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));
61867+ break;
61868+ case GR_CAP:
61869+ task = va_arg(ap, struct task_struct *);
61870+ cred = __task_cred(task);
61871+ pcred = __task_cred(task->real_parent);
61872+ str1 = va_arg(ap, char *);
61873+ 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));
61874+ break;
61875+ case GR_SIG:
61876+ str1 = va_arg(ap, char *);
61877+ voidptr = va_arg(ap, void *);
61878+ gr_log_middle_varargs(audit, msg, str1, voidptr);
61879+ break;
61880+ case GR_SIG2:
61881+ task = va_arg(ap, struct task_struct *);
61882+ cred = __task_cred(task);
61883+ pcred = __task_cred(task->real_parent);
61884+ num1 = va_arg(ap, int);
61885+ 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));
61886+ break;
61887+ case GR_CRASH1:
61888+ task = va_arg(ap, struct task_struct *);
61889+ cred = __task_cred(task);
61890+ pcred = __task_cred(task->real_parent);
61891+ ulong1 = va_arg(ap, unsigned long);
61892+ 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);
61893+ break;
61894+ case GR_CRASH2:
61895+ task = va_arg(ap, struct task_struct *);
61896+ cred = __task_cred(task);
61897+ pcred = __task_cred(task->real_parent);
61898+ ulong1 = va_arg(ap, unsigned long);
61899+ 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);
61900+ break;
61901+ case GR_RWXMAP:
61902+ file = va_arg(ap, struct file *);
61903+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
61904+ break;
61905+ case GR_PSACCT:
61906+ {
61907+ unsigned int wday, cday;
61908+ __u8 whr, chr;
61909+ __u8 wmin, cmin;
61910+ __u8 wsec, csec;
61911+ char cur_tty[64] = { 0 };
61912+ char parent_tty[64] = { 0 };
61913+
61914+ task = va_arg(ap, struct task_struct *);
61915+ wday = va_arg(ap, unsigned int);
61916+ cday = va_arg(ap, unsigned int);
61917+ whr = va_arg(ap, int);
61918+ chr = va_arg(ap, int);
61919+ wmin = va_arg(ap, int);
61920+ cmin = va_arg(ap, int);
61921+ wsec = va_arg(ap, int);
61922+ csec = va_arg(ap, int);
61923+ ulong1 = va_arg(ap, unsigned long);
61924+ cred = __task_cred(task);
61925+ pcred = __task_cred(task->real_parent);
61926+
61927+ 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));
61928+ }
61929+ break;
61930+ default:
61931+ gr_log_middle(audit, msg, ap);
61932+ }
61933+ va_end(ap);
61934+ // these don't need DEFAULTSECARGS printed on the end
61935+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
61936+ gr_log_end(audit, 0);
61937+ else
61938+ gr_log_end(audit, 1);
61939+ END_LOCKS(audit);
61940+}
61941diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
61942new file mode 100644
61943index 0000000..f536303
61944--- /dev/null
61945+++ b/grsecurity/grsec_mem.c
61946@@ -0,0 +1,40 @@
61947+#include <linux/kernel.h>
61948+#include <linux/sched.h>
61949+#include <linux/mm.h>
61950+#include <linux/mman.h>
61951+#include <linux/grinternal.h>
61952+
61953+void
61954+gr_handle_ioperm(void)
61955+{
61956+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
61957+ return;
61958+}
61959+
61960+void
61961+gr_handle_iopl(void)
61962+{
61963+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
61964+ return;
61965+}
61966+
61967+void
61968+gr_handle_mem_readwrite(u64 from, u64 to)
61969+{
61970+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
61971+ return;
61972+}
61973+
61974+void
61975+gr_handle_vm86(void)
61976+{
61977+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
61978+ return;
61979+}
61980+
61981+void
61982+gr_log_badprocpid(const char *entry)
61983+{
61984+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
61985+ return;
61986+}
61987diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
61988new file mode 100644
61989index 0000000..2131422
61990--- /dev/null
61991+++ b/grsecurity/grsec_mount.c
61992@@ -0,0 +1,62 @@
61993+#include <linux/kernel.h>
61994+#include <linux/sched.h>
61995+#include <linux/mount.h>
61996+#include <linux/grsecurity.h>
61997+#include <linux/grinternal.h>
61998+
61999+void
62000+gr_log_remount(const char *devname, const int retval)
62001+{
62002+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
62003+ if (grsec_enable_mount && (retval >= 0))
62004+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
62005+#endif
62006+ return;
62007+}
62008+
62009+void
62010+gr_log_unmount(const char *devname, const int retval)
62011+{
62012+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
62013+ if (grsec_enable_mount && (retval >= 0))
62014+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
62015+#endif
62016+ return;
62017+}
62018+
62019+void
62020+gr_log_mount(const char *from, const char *to, const int retval)
62021+{
62022+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
62023+ if (grsec_enable_mount && (retval >= 0))
62024+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
62025+#endif
62026+ return;
62027+}
62028+
62029+int
62030+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
62031+{
62032+#ifdef CONFIG_GRKERNSEC_ROFS
62033+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
62034+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
62035+ return -EPERM;
62036+ } else
62037+ return 0;
62038+#endif
62039+ return 0;
62040+}
62041+
62042+int
62043+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
62044+{
62045+#ifdef CONFIG_GRKERNSEC_ROFS
62046+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
62047+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
62048+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
62049+ return -EPERM;
62050+ } else
62051+ return 0;
62052+#endif
62053+ return 0;
62054+}
62055diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
62056new file mode 100644
62057index 0000000..a3b12a0
62058--- /dev/null
62059+++ b/grsecurity/grsec_pax.c
62060@@ -0,0 +1,36 @@
62061+#include <linux/kernel.h>
62062+#include <linux/sched.h>
62063+#include <linux/mm.h>
62064+#include <linux/file.h>
62065+#include <linux/grinternal.h>
62066+#include <linux/grsecurity.h>
62067+
62068+void
62069+gr_log_textrel(struct vm_area_struct * vma)
62070+{
62071+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
62072+ if (grsec_enable_audit_textrel)
62073+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
62074+#endif
62075+ return;
62076+}
62077+
62078+void
62079+gr_log_rwxmmap(struct file *file)
62080+{
62081+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
62082+ if (grsec_enable_log_rwxmaps)
62083+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
62084+#endif
62085+ return;
62086+}
62087+
62088+void
62089+gr_log_rwxmprotect(struct file *file)
62090+{
62091+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
62092+ if (grsec_enable_log_rwxmaps)
62093+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
62094+#endif
62095+ return;
62096+}
62097diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
62098new file mode 100644
62099index 0000000..f7f29aa
62100--- /dev/null
62101+++ b/grsecurity/grsec_ptrace.c
62102@@ -0,0 +1,30 @@
62103+#include <linux/kernel.h>
62104+#include <linux/sched.h>
62105+#include <linux/grinternal.h>
62106+#include <linux/security.h>
62107+
62108+void
62109+gr_audit_ptrace(struct task_struct *task)
62110+{
62111+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
62112+ if (grsec_enable_audit_ptrace)
62113+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
62114+#endif
62115+ return;
62116+}
62117+
62118+int
62119+gr_ptrace_readexec(struct file *file, int unsafe_flags)
62120+{
62121+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
62122+ const struct dentry *dentry = file->f_path.dentry;
62123+ const struct vfsmount *mnt = file->f_path.mnt;
62124+
62125+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
62126+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
62127+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
62128+ return -EACCES;
62129+ }
62130+#endif
62131+ return 0;
62132+}
62133diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
62134new file mode 100644
62135index 0000000..5c00416
62136--- /dev/null
62137+++ b/grsecurity/grsec_sig.c
62138@@ -0,0 +1,222 @@
62139+#include <linux/kernel.h>
62140+#include <linux/sched.h>
62141+#include <linux/delay.h>
62142+#include <linux/grsecurity.h>
62143+#include <linux/grinternal.h>
62144+#include <linux/hardirq.h>
62145+
62146+char *signames[] = {
62147+ [SIGSEGV] = "Segmentation fault",
62148+ [SIGILL] = "Illegal instruction",
62149+ [SIGABRT] = "Abort",
62150+ [SIGBUS] = "Invalid alignment/Bus error"
62151+};
62152+
62153+void
62154+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
62155+{
62156+#ifdef CONFIG_GRKERNSEC_SIGNAL
62157+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
62158+ (sig == SIGABRT) || (sig == SIGBUS))) {
62159+ if (t->pid == current->pid) {
62160+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
62161+ } else {
62162+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
62163+ }
62164+ }
62165+#endif
62166+ return;
62167+}
62168+
62169+int
62170+gr_handle_signal(const struct task_struct *p, const int sig)
62171+{
62172+#ifdef CONFIG_GRKERNSEC
62173+ /* ignore the 0 signal for protected task checks */
62174+ if (current->pid > 1 && sig && gr_check_protected_task(p)) {
62175+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
62176+ return -EPERM;
62177+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
62178+ return -EPERM;
62179+ }
62180+#endif
62181+ return 0;
62182+}
62183+
62184+#ifdef CONFIG_GRKERNSEC
62185+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
62186+
62187+int gr_fake_force_sig(int sig, struct task_struct *t)
62188+{
62189+ unsigned long int flags;
62190+ int ret, blocked, ignored;
62191+ struct k_sigaction *action;
62192+
62193+ spin_lock_irqsave(&t->sighand->siglock, flags);
62194+ action = &t->sighand->action[sig-1];
62195+ ignored = action->sa.sa_handler == SIG_IGN;
62196+ blocked = sigismember(&t->blocked, sig);
62197+ if (blocked || ignored) {
62198+ action->sa.sa_handler = SIG_DFL;
62199+ if (blocked) {
62200+ sigdelset(&t->blocked, sig);
62201+ recalc_sigpending_and_wake(t);
62202+ }
62203+ }
62204+ if (action->sa.sa_handler == SIG_DFL)
62205+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
62206+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
62207+
62208+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
62209+
62210+ return ret;
62211+}
62212+#endif
62213+
62214+#ifdef CONFIG_GRKERNSEC_BRUTE
62215+#define GR_USER_BAN_TIME (15 * 60)
62216+#define GR_DAEMON_BRUTE_TIME (30 * 60)
62217+
62218+static int __get_dumpable(unsigned long mm_flags)
62219+{
62220+ int ret;
62221+
62222+ ret = mm_flags & MMF_DUMPABLE_MASK;
62223+ return (ret >= 2) ? 2 : ret;
62224+}
62225+#endif
62226+
62227+void gr_handle_brute_attach(unsigned long mm_flags)
62228+{
62229+#ifdef CONFIG_GRKERNSEC_BRUTE
62230+ struct task_struct *p = current;
62231+ kuid_t uid = GLOBAL_ROOT_UID;
62232+ int daemon = 0;
62233+
62234+ if (!grsec_enable_brute)
62235+ return;
62236+
62237+ rcu_read_lock();
62238+ read_lock(&tasklist_lock);
62239+ read_lock(&grsec_exec_file_lock);
62240+ if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
62241+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
62242+ p->real_parent->brute = 1;
62243+ daemon = 1;
62244+ } else {
62245+ const struct cred *cred = __task_cred(p), *cred2;
62246+ struct task_struct *tsk, *tsk2;
62247+
62248+ if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
62249+ struct user_struct *user;
62250+
62251+ uid = cred->uid;
62252+
62253+ /* this is put upon execution past expiration */
62254+ user = find_user(uid);
62255+ if (user == NULL)
62256+ goto unlock;
62257+ user->banned = 1;
62258+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
62259+ if (user->ban_expires == ~0UL)
62260+ user->ban_expires--;
62261+
62262+ do_each_thread(tsk2, tsk) {
62263+ cred2 = __task_cred(tsk);
62264+ if (tsk != p && uid_eq(cred2->uid, uid))
62265+ gr_fake_force_sig(SIGKILL, tsk);
62266+ } while_each_thread(tsk2, tsk);
62267+ }
62268+ }
62269+unlock:
62270+ read_unlock(&grsec_exec_file_lock);
62271+ read_unlock(&tasklist_lock);
62272+ rcu_read_unlock();
62273+
62274+ if (!uid_eq(uid, GLOBAL_ROOT_UID))
62275+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
62276+ from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
62277+ else if (daemon)
62278+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
62279+
62280+#endif
62281+ return;
62282+}
62283+
62284+void gr_handle_brute_check(void)
62285+{
62286+#ifdef CONFIG_GRKERNSEC_BRUTE
62287+ struct task_struct *p = current;
62288+
62289+ if (unlikely(p->brute)) {
62290+ if (!grsec_enable_brute)
62291+ p->brute = 0;
62292+ else if (time_before(get_seconds(), p->brute_expires))
62293+ msleep(30 * 1000);
62294+ }
62295+#endif
62296+ return;
62297+}
62298+
62299+void gr_handle_kernel_exploit(void)
62300+{
62301+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
62302+ const struct cred *cred;
62303+ struct task_struct *tsk, *tsk2;
62304+ struct user_struct *user;
62305+ kuid_t uid;
62306+
62307+ if (in_irq() || in_serving_softirq() || in_nmi())
62308+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
62309+
62310+ uid = current_uid();
62311+
62312+ if (uid_eq(uid, GLOBAL_ROOT_UID))
62313+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
62314+ else {
62315+ /* kill all the processes of this user, hold a reference
62316+ to their creds struct, and prevent them from creating
62317+ another process until system reset
62318+ */
62319+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
62320+ from_kuid_munged(&init_user_ns, uid));
62321+ /* we intentionally leak this ref */
62322+ user = get_uid(current->cred->user);
62323+ if (user) {
62324+ user->banned = 1;
62325+ user->ban_expires = ~0UL;
62326+ }
62327+
62328+ read_lock(&tasklist_lock);
62329+ do_each_thread(tsk2, tsk) {
62330+ cred = __task_cred(tsk);
62331+ if (uid_eq(cred->uid, uid))
62332+ gr_fake_force_sig(SIGKILL, tsk);
62333+ } while_each_thread(tsk2, tsk);
62334+ read_unlock(&tasklist_lock);
62335+ }
62336+#endif
62337+}
62338+
62339+int __gr_process_user_ban(struct user_struct *user)
62340+{
62341+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
62342+ if (unlikely(user->banned)) {
62343+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
62344+ user->banned = 0;
62345+ user->ban_expires = 0;
62346+ free_uid(user);
62347+ } else
62348+ return -EPERM;
62349+ }
62350+#endif
62351+ return 0;
62352+}
62353+
62354+int gr_process_user_ban(void)
62355+{
62356+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
62357+ return __gr_process_user_ban(current->cred->user);
62358+#endif
62359+ return 0;
62360+}
62361diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
62362new file mode 100644
62363index 0000000..4030d57
62364--- /dev/null
62365+++ b/grsecurity/grsec_sock.c
62366@@ -0,0 +1,244 @@
62367+#include <linux/kernel.h>
62368+#include <linux/module.h>
62369+#include <linux/sched.h>
62370+#include <linux/file.h>
62371+#include <linux/net.h>
62372+#include <linux/in.h>
62373+#include <linux/ip.h>
62374+#include <net/sock.h>
62375+#include <net/inet_sock.h>
62376+#include <linux/grsecurity.h>
62377+#include <linux/grinternal.h>
62378+#include <linux/gracl.h>
62379+
62380+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
62381+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
62382+
62383+EXPORT_SYMBOL(gr_search_udp_recvmsg);
62384+EXPORT_SYMBOL(gr_search_udp_sendmsg);
62385+
62386+#ifdef CONFIG_UNIX_MODULE
62387+EXPORT_SYMBOL(gr_acl_handle_unix);
62388+EXPORT_SYMBOL(gr_acl_handle_mknod);
62389+EXPORT_SYMBOL(gr_handle_chroot_unix);
62390+EXPORT_SYMBOL(gr_handle_create);
62391+#endif
62392+
62393+#ifdef CONFIG_GRKERNSEC
62394+#define gr_conn_table_size 32749
62395+struct conn_table_entry {
62396+ struct conn_table_entry *next;
62397+ struct signal_struct *sig;
62398+};
62399+
62400+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
62401+DEFINE_SPINLOCK(gr_conn_table_lock);
62402+
62403+extern const char * gr_socktype_to_name(unsigned char type);
62404+extern const char * gr_proto_to_name(unsigned char proto);
62405+extern const char * gr_sockfamily_to_name(unsigned char family);
62406+
62407+static __inline__ int
62408+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
62409+{
62410+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
62411+}
62412+
62413+static __inline__ int
62414+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
62415+ __u16 sport, __u16 dport)
62416+{
62417+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
62418+ sig->gr_sport == sport && sig->gr_dport == dport))
62419+ return 1;
62420+ else
62421+ return 0;
62422+}
62423+
62424+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
62425+{
62426+ struct conn_table_entry **match;
62427+ unsigned int index;
62428+
62429+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
62430+ sig->gr_sport, sig->gr_dport,
62431+ gr_conn_table_size);
62432+
62433+ newent->sig = sig;
62434+
62435+ match = &gr_conn_table[index];
62436+ newent->next = *match;
62437+ *match = newent;
62438+
62439+ return;
62440+}
62441+
62442+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
62443+{
62444+ struct conn_table_entry *match, *last = NULL;
62445+ unsigned int index;
62446+
62447+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
62448+ sig->gr_sport, sig->gr_dport,
62449+ gr_conn_table_size);
62450+
62451+ match = gr_conn_table[index];
62452+ while (match && !conn_match(match->sig,
62453+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
62454+ sig->gr_dport)) {
62455+ last = match;
62456+ match = match->next;
62457+ }
62458+
62459+ if (match) {
62460+ if (last)
62461+ last->next = match->next;
62462+ else
62463+ gr_conn_table[index] = NULL;
62464+ kfree(match);
62465+ }
62466+
62467+ return;
62468+}
62469+
62470+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
62471+ __u16 sport, __u16 dport)
62472+{
62473+ struct conn_table_entry *match;
62474+ unsigned int index;
62475+
62476+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
62477+
62478+ match = gr_conn_table[index];
62479+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
62480+ match = match->next;
62481+
62482+ if (match)
62483+ return match->sig;
62484+ else
62485+ return NULL;
62486+}
62487+
62488+#endif
62489+
62490+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
62491+{
62492+#ifdef CONFIG_GRKERNSEC
62493+ struct signal_struct *sig = task->signal;
62494+ struct conn_table_entry *newent;
62495+
62496+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
62497+ if (newent == NULL)
62498+ return;
62499+ /* no bh lock needed since we are called with bh disabled */
62500+ spin_lock(&gr_conn_table_lock);
62501+ gr_del_task_from_ip_table_nolock(sig);
62502+ sig->gr_saddr = inet->inet_rcv_saddr;
62503+ sig->gr_daddr = inet->inet_daddr;
62504+ sig->gr_sport = inet->inet_sport;
62505+ sig->gr_dport = inet->inet_dport;
62506+ gr_add_to_task_ip_table_nolock(sig, newent);
62507+ spin_unlock(&gr_conn_table_lock);
62508+#endif
62509+ return;
62510+}
62511+
62512+void gr_del_task_from_ip_table(struct task_struct *task)
62513+{
62514+#ifdef CONFIG_GRKERNSEC
62515+ spin_lock_bh(&gr_conn_table_lock);
62516+ gr_del_task_from_ip_table_nolock(task->signal);
62517+ spin_unlock_bh(&gr_conn_table_lock);
62518+#endif
62519+ return;
62520+}
62521+
62522+void
62523+gr_attach_curr_ip(const struct sock *sk)
62524+{
62525+#ifdef CONFIG_GRKERNSEC
62526+ struct signal_struct *p, *set;
62527+ const struct inet_sock *inet = inet_sk(sk);
62528+
62529+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
62530+ return;
62531+
62532+ set = current->signal;
62533+
62534+ spin_lock_bh(&gr_conn_table_lock);
62535+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
62536+ inet->inet_dport, inet->inet_sport);
62537+ if (unlikely(p != NULL)) {
62538+ set->curr_ip = p->curr_ip;
62539+ set->used_accept = 1;
62540+ gr_del_task_from_ip_table_nolock(p);
62541+ spin_unlock_bh(&gr_conn_table_lock);
62542+ return;
62543+ }
62544+ spin_unlock_bh(&gr_conn_table_lock);
62545+
62546+ set->curr_ip = inet->inet_daddr;
62547+ set->used_accept = 1;
62548+#endif
62549+ return;
62550+}
62551+
62552+int
62553+gr_handle_sock_all(const int family, const int type, const int protocol)
62554+{
62555+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
62556+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
62557+ (family != AF_UNIX)) {
62558+ if (family == AF_INET)
62559+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
62560+ else
62561+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
62562+ return -EACCES;
62563+ }
62564+#endif
62565+ return 0;
62566+}
62567+
62568+int
62569+gr_handle_sock_server(const struct sockaddr *sck)
62570+{
62571+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
62572+ if (grsec_enable_socket_server &&
62573+ in_group_p(grsec_socket_server_gid) &&
62574+ sck && (sck->sa_family != AF_UNIX) &&
62575+ (sck->sa_family != AF_LOCAL)) {
62576+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
62577+ return -EACCES;
62578+ }
62579+#endif
62580+ return 0;
62581+}
62582+
62583+int
62584+gr_handle_sock_server_other(const struct sock *sck)
62585+{
62586+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
62587+ if (grsec_enable_socket_server &&
62588+ in_group_p(grsec_socket_server_gid) &&
62589+ sck && (sck->sk_family != AF_UNIX) &&
62590+ (sck->sk_family != AF_LOCAL)) {
62591+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
62592+ return -EACCES;
62593+ }
62594+#endif
62595+ return 0;
62596+}
62597+
62598+int
62599+gr_handle_sock_client(const struct sockaddr *sck)
62600+{
62601+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
62602+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
62603+ sck && (sck->sa_family != AF_UNIX) &&
62604+ (sck->sa_family != AF_LOCAL)) {
62605+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
62606+ return -EACCES;
62607+ }
62608+#endif
62609+ return 0;
62610+}
62611diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
62612new file mode 100644
62613index 0000000..f55ef0f
62614--- /dev/null
62615+++ b/grsecurity/grsec_sysctl.c
62616@@ -0,0 +1,469 @@
62617+#include <linux/kernel.h>
62618+#include <linux/sched.h>
62619+#include <linux/sysctl.h>
62620+#include <linux/grsecurity.h>
62621+#include <linux/grinternal.h>
62622+
62623+int
62624+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
62625+{
62626+#ifdef CONFIG_GRKERNSEC_SYSCTL
62627+ if (dirname == NULL || name == NULL)
62628+ return 0;
62629+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
62630+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
62631+ return -EACCES;
62632+ }
62633+#endif
62634+ return 0;
62635+}
62636+
62637+#ifdef CONFIG_GRKERNSEC_ROFS
62638+static int __maybe_unused one = 1;
62639+#endif
62640+
62641+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
62642+struct ctl_table grsecurity_table[] = {
62643+#ifdef CONFIG_GRKERNSEC_SYSCTL
62644+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
62645+#ifdef CONFIG_GRKERNSEC_IO
62646+ {
62647+ .procname = "disable_priv_io",
62648+ .data = &grsec_disable_privio,
62649+ .maxlen = sizeof(int),
62650+ .mode = 0600,
62651+ .proc_handler = &proc_dointvec,
62652+ },
62653+#endif
62654+#endif
62655+#ifdef CONFIG_GRKERNSEC_LINK
62656+ {
62657+ .procname = "linking_restrictions",
62658+ .data = &grsec_enable_link,
62659+ .maxlen = sizeof(int),
62660+ .mode = 0600,
62661+ .proc_handler = &proc_dointvec,
62662+ },
62663+#endif
62664+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
62665+ {
62666+ .procname = "enforce_symlinksifowner",
62667+ .data = &grsec_enable_symlinkown,
62668+ .maxlen = sizeof(int),
62669+ .mode = 0600,
62670+ .proc_handler = &proc_dointvec,
62671+ },
62672+ {
62673+ .procname = "symlinkown_gid",
62674+ .data = &grsec_symlinkown_gid,
62675+ .maxlen = sizeof(int),
62676+ .mode = 0600,
62677+ .proc_handler = &proc_dointvec,
62678+ },
62679+#endif
62680+#ifdef CONFIG_GRKERNSEC_BRUTE
62681+ {
62682+ .procname = "deter_bruteforce",
62683+ .data = &grsec_enable_brute,
62684+ .maxlen = sizeof(int),
62685+ .mode = 0600,
62686+ .proc_handler = &proc_dointvec,
62687+ },
62688+#endif
62689+#ifdef CONFIG_GRKERNSEC_FIFO
62690+ {
62691+ .procname = "fifo_restrictions",
62692+ .data = &grsec_enable_fifo,
62693+ .maxlen = sizeof(int),
62694+ .mode = 0600,
62695+ .proc_handler = &proc_dointvec,
62696+ },
62697+#endif
62698+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
62699+ {
62700+ .procname = "ptrace_readexec",
62701+ .data = &grsec_enable_ptrace_readexec,
62702+ .maxlen = sizeof(int),
62703+ .mode = 0600,
62704+ .proc_handler = &proc_dointvec,
62705+ },
62706+#endif
62707+#ifdef CONFIG_GRKERNSEC_SETXID
62708+ {
62709+ .procname = "consistent_setxid",
62710+ .data = &grsec_enable_setxid,
62711+ .maxlen = sizeof(int),
62712+ .mode = 0600,
62713+ .proc_handler = &proc_dointvec,
62714+ },
62715+#endif
62716+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
62717+ {
62718+ .procname = "ip_blackhole",
62719+ .data = &grsec_enable_blackhole,
62720+ .maxlen = sizeof(int),
62721+ .mode = 0600,
62722+ .proc_handler = &proc_dointvec,
62723+ },
62724+ {
62725+ .procname = "lastack_retries",
62726+ .data = &grsec_lastack_retries,
62727+ .maxlen = sizeof(int),
62728+ .mode = 0600,
62729+ .proc_handler = &proc_dointvec,
62730+ },
62731+#endif
62732+#ifdef CONFIG_GRKERNSEC_EXECLOG
62733+ {
62734+ .procname = "exec_logging",
62735+ .data = &grsec_enable_execlog,
62736+ .maxlen = sizeof(int),
62737+ .mode = 0600,
62738+ .proc_handler = &proc_dointvec,
62739+ },
62740+#endif
62741+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
62742+ {
62743+ .procname = "rwxmap_logging",
62744+ .data = &grsec_enable_log_rwxmaps,
62745+ .maxlen = sizeof(int),
62746+ .mode = 0600,
62747+ .proc_handler = &proc_dointvec,
62748+ },
62749+#endif
62750+#ifdef CONFIG_GRKERNSEC_SIGNAL
62751+ {
62752+ .procname = "signal_logging",
62753+ .data = &grsec_enable_signal,
62754+ .maxlen = sizeof(int),
62755+ .mode = 0600,
62756+ .proc_handler = &proc_dointvec,
62757+ },
62758+#endif
62759+#ifdef CONFIG_GRKERNSEC_FORKFAIL
62760+ {
62761+ .procname = "forkfail_logging",
62762+ .data = &grsec_enable_forkfail,
62763+ .maxlen = sizeof(int),
62764+ .mode = 0600,
62765+ .proc_handler = &proc_dointvec,
62766+ },
62767+#endif
62768+#ifdef CONFIG_GRKERNSEC_TIME
62769+ {
62770+ .procname = "timechange_logging",
62771+ .data = &grsec_enable_time,
62772+ .maxlen = sizeof(int),
62773+ .mode = 0600,
62774+ .proc_handler = &proc_dointvec,
62775+ },
62776+#endif
62777+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
62778+ {
62779+ .procname = "chroot_deny_shmat",
62780+ .data = &grsec_enable_chroot_shmat,
62781+ .maxlen = sizeof(int),
62782+ .mode = 0600,
62783+ .proc_handler = &proc_dointvec,
62784+ },
62785+#endif
62786+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
62787+ {
62788+ .procname = "chroot_deny_unix",
62789+ .data = &grsec_enable_chroot_unix,
62790+ .maxlen = sizeof(int),
62791+ .mode = 0600,
62792+ .proc_handler = &proc_dointvec,
62793+ },
62794+#endif
62795+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
62796+ {
62797+ .procname = "chroot_deny_mount",
62798+ .data = &grsec_enable_chroot_mount,
62799+ .maxlen = sizeof(int),
62800+ .mode = 0600,
62801+ .proc_handler = &proc_dointvec,
62802+ },
62803+#endif
62804+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
62805+ {
62806+ .procname = "chroot_deny_fchdir",
62807+ .data = &grsec_enable_chroot_fchdir,
62808+ .maxlen = sizeof(int),
62809+ .mode = 0600,
62810+ .proc_handler = &proc_dointvec,
62811+ },
62812+#endif
62813+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
62814+ {
62815+ .procname = "chroot_deny_chroot",
62816+ .data = &grsec_enable_chroot_double,
62817+ .maxlen = sizeof(int),
62818+ .mode = 0600,
62819+ .proc_handler = &proc_dointvec,
62820+ },
62821+#endif
62822+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
62823+ {
62824+ .procname = "chroot_deny_pivot",
62825+ .data = &grsec_enable_chroot_pivot,
62826+ .maxlen = sizeof(int),
62827+ .mode = 0600,
62828+ .proc_handler = &proc_dointvec,
62829+ },
62830+#endif
62831+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
62832+ {
62833+ .procname = "chroot_enforce_chdir",
62834+ .data = &grsec_enable_chroot_chdir,
62835+ .maxlen = sizeof(int),
62836+ .mode = 0600,
62837+ .proc_handler = &proc_dointvec,
62838+ },
62839+#endif
62840+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
62841+ {
62842+ .procname = "chroot_deny_chmod",
62843+ .data = &grsec_enable_chroot_chmod,
62844+ .maxlen = sizeof(int),
62845+ .mode = 0600,
62846+ .proc_handler = &proc_dointvec,
62847+ },
62848+#endif
62849+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
62850+ {
62851+ .procname = "chroot_deny_mknod",
62852+ .data = &grsec_enable_chroot_mknod,
62853+ .maxlen = sizeof(int),
62854+ .mode = 0600,
62855+ .proc_handler = &proc_dointvec,
62856+ },
62857+#endif
62858+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
62859+ {
62860+ .procname = "chroot_restrict_nice",
62861+ .data = &grsec_enable_chroot_nice,
62862+ .maxlen = sizeof(int),
62863+ .mode = 0600,
62864+ .proc_handler = &proc_dointvec,
62865+ },
62866+#endif
62867+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
62868+ {
62869+ .procname = "chroot_execlog",
62870+ .data = &grsec_enable_chroot_execlog,
62871+ .maxlen = sizeof(int),
62872+ .mode = 0600,
62873+ .proc_handler = &proc_dointvec,
62874+ },
62875+#endif
62876+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62877+ {
62878+ .procname = "chroot_caps",
62879+ .data = &grsec_enable_chroot_caps,
62880+ .maxlen = sizeof(int),
62881+ .mode = 0600,
62882+ .proc_handler = &proc_dointvec,
62883+ },
62884+#endif
62885+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
62886+ {
62887+ .procname = "chroot_deny_sysctl",
62888+ .data = &grsec_enable_chroot_sysctl,
62889+ .maxlen = sizeof(int),
62890+ .mode = 0600,
62891+ .proc_handler = &proc_dointvec,
62892+ },
62893+#endif
62894+#ifdef CONFIG_GRKERNSEC_TPE
62895+ {
62896+ .procname = "tpe",
62897+ .data = &grsec_enable_tpe,
62898+ .maxlen = sizeof(int),
62899+ .mode = 0600,
62900+ .proc_handler = &proc_dointvec,
62901+ },
62902+ {
62903+ .procname = "tpe_gid",
62904+ .data = &grsec_tpe_gid,
62905+ .maxlen = sizeof(int),
62906+ .mode = 0600,
62907+ .proc_handler = &proc_dointvec,
62908+ },
62909+#endif
62910+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
62911+ {
62912+ .procname = "tpe_invert",
62913+ .data = &grsec_enable_tpe_invert,
62914+ .maxlen = sizeof(int),
62915+ .mode = 0600,
62916+ .proc_handler = &proc_dointvec,
62917+ },
62918+#endif
62919+#ifdef CONFIG_GRKERNSEC_TPE_ALL
62920+ {
62921+ .procname = "tpe_restrict_all",
62922+ .data = &grsec_enable_tpe_all,
62923+ .maxlen = sizeof(int),
62924+ .mode = 0600,
62925+ .proc_handler = &proc_dointvec,
62926+ },
62927+#endif
62928+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
62929+ {
62930+ .procname = "socket_all",
62931+ .data = &grsec_enable_socket_all,
62932+ .maxlen = sizeof(int),
62933+ .mode = 0600,
62934+ .proc_handler = &proc_dointvec,
62935+ },
62936+ {
62937+ .procname = "socket_all_gid",
62938+ .data = &grsec_socket_all_gid,
62939+ .maxlen = sizeof(int),
62940+ .mode = 0600,
62941+ .proc_handler = &proc_dointvec,
62942+ },
62943+#endif
62944+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
62945+ {
62946+ .procname = "socket_client",
62947+ .data = &grsec_enable_socket_client,
62948+ .maxlen = sizeof(int),
62949+ .mode = 0600,
62950+ .proc_handler = &proc_dointvec,
62951+ },
62952+ {
62953+ .procname = "socket_client_gid",
62954+ .data = &grsec_socket_client_gid,
62955+ .maxlen = sizeof(int),
62956+ .mode = 0600,
62957+ .proc_handler = &proc_dointvec,
62958+ },
62959+#endif
62960+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
62961+ {
62962+ .procname = "socket_server",
62963+ .data = &grsec_enable_socket_server,
62964+ .maxlen = sizeof(int),
62965+ .mode = 0600,
62966+ .proc_handler = &proc_dointvec,
62967+ },
62968+ {
62969+ .procname = "socket_server_gid",
62970+ .data = &grsec_socket_server_gid,
62971+ .maxlen = sizeof(int),
62972+ .mode = 0600,
62973+ .proc_handler = &proc_dointvec,
62974+ },
62975+#endif
62976+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
62977+ {
62978+ .procname = "audit_group",
62979+ .data = &grsec_enable_group,
62980+ .maxlen = sizeof(int),
62981+ .mode = 0600,
62982+ .proc_handler = &proc_dointvec,
62983+ },
62984+ {
62985+ .procname = "audit_gid",
62986+ .data = &grsec_audit_gid,
62987+ .maxlen = sizeof(int),
62988+ .mode = 0600,
62989+ .proc_handler = &proc_dointvec,
62990+ },
62991+#endif
62992+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
62993+ {
62994+ .procname = "audit_chdir",
62995+ .data = &grsec_enable_chdir,
62996+ .maxlen = sizeof(int),
62997+ .mode = 0600,
62998+ .proc_handler = &proc_dointvec,
62999+ },
63000+#endif
63001+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
63002+ {
63003+ .procname = "audit_mount",
63004+ .data = &grsec_enable_mount,
63005+ .maxlen = sizeof(int),
63006+ .mode = 0600,
63007+ .proc_handler = &proc_dointvec,
63008+ },
63009+#endif
63010+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
63011+ {
63012+ .procname = "audit_textrel",
63013+ .data = &grsec_enable_audit_textrel,
63014+ .maxlen = sizeof(int),
63015+ .mode = 0600,
63016+ .proc_handler = &proc_dointvec,
63017+ },
63018+#endif
63019+#ifdef CONFIG_GRKERNSEC_DMESG
63020+ {
63021+ .procname = "dmesg",
63022+ .data = &grsec_enable_dmesg,
63023+ .maxlen = sizeof(int),
63024+ .mode = 0600,
63025+ .proc_handler = &proc_dointvec,
63026+ },
63027+#endif
63028+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
63029+ {
63030+ .procname = "chroot_findtask",
63031+ .data = &grsec_enable_chroot_findtask,
63032+ .maxlen = sizeof(int),
63033+ .mode = 0600,
63034+ .proc_handler = &proc_dointvec,
63035+ },
63036+#endif
63037+#ifdef CONFIG_GRKERNSEC_RESLOG
63038+ {
63039+ .procname = "resource_logging",
63040+ .data = &grsec_resource_logging,
63041+ .maxlen = sizeof(int),
63042+ .mode = 0600,
63043+ .proc_handler = &proc_dointvec,
63044+ },
63045+#endif
63046+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
63047+ {
63048+ .procname = "audit_ptrace",
63049+ .data = &grsec_enable_audit_ptrace,
63050+ .maxlen = sizeof(int),
63051+ .mode = 0600,
63052+ .proc_handler = &proc_dointvec,
63053+ },
63054+#endif
63055+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
63056+ {
63057+ .procname = "harden_ptrace",
63058+ .data = &grsec_enable_harden_ptrace,
63059+ .maxlen = sizeof(int),
63060+ .mode = 0600,
63061+ .proc_handler = &proc_dointvec,
63062+ },
63063+#endif
63064+ {
63065+ .procname = "grsec_lock",
63066+ .data = &grsec_lock,
63067+ .maxlen = sizeof(int),
63068+ .mode = 0600,
63069+ .proc_handler = &proc_dointvec,
63070+ },
63071+#endif
63072+#ifdef CONFIG_GRKERNSEC_ROFS
63073+ {
63074+ .procname = "romount_protect",
63075+ .data = &grsec_enable_rofs,
63076+ .maxlen = sizeof(int),
63077+ .mode = 0600,
63078+ .proc_handler = &proc_dointvec_minmax,
63079+ .extra1 = &one,
63080+ .extra2 = &one,
63081+ },
63082+#endif
63083+ { }
63084+};
63085+#endif
63086diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
63087new file mode 100644
63088index 0000000..0dc13c3
63089--- /dev/null
63090+++ b/grsecurity/grsec_time.c
63091@@ -0,0 +1,16 @@
63092+#include <linux/kernel.h>
63093+#include <linux/sched.h>
63094+#include <linux/grinternal.h>
63095+#include <linux/module.h>
63096+
63097+void
63098+gr_log_timechange(void)
63099+{
63100+#ifdef CONFIG_GRKERNSEC_TIME
63101+ if (grsec_enable_time)
63102+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
63103+#endif
63104+ return;
63105+}
63106+
63107+EXPORT_SYMBOL(gr_log_timechange);
63108diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
63109new file mode 100644
63110index 0000000..07e0dc0
63111--- /dev/null
63112+++ b/grsecurity/grsec_tpe.c
63113@@ -0,0 +1,73 @@
63114+#include <linux/kernel.h>
63115+#include <linux/sched.h>
63116+#include <linux/file.h>
63117+#include <linux/fs.h>
63118+#include <linux/grinternal.h>
63119+
63120+extern int gr_acl_tpe_check(void);
63121+
63122+int
63123+gr_tpe_allow(const struct file *file)
63124+{
63125+#ifdef CONFIG_GRKERNSEC
63126+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
63127+ const struct cred *cred = current_cred();
63128+ char *msg = NULL;
63129+ char *msg2 = NULL;
63130+
63131+ // never restrict root
63132+ if (!cred->uid)
63133+ return 1;
63134+
63135+ if (grsec_enable_tpe) {
63136+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
63137+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
63138+ msg = "not being in trusted group";
63139+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
63140+ msg = "being in untrusted group";
63141+#else
63142+ if (in_group_p(grsec_tpe_gid))
63143+ msg = "being in untrusted group";
63144+#endif
63145+ }
63146+ if (!msg && gr_acl_tpe_check())
63147+ msg = "being in untrusted role";
63148+
63149+ // not in any affected group/role
63150+ if (!msg)
63151+ goto next_check;
63152+
63153+ if (inode->i_uid)
63154+ msg2 = "file in non-root-owned directory";
63155+ else if (inode->i_mode & S_IWOTH)
63156+ msg2 = "file in world-writable directory";
63157+ else if (inode->i_mode & S_IWGRP)
63158+ msg2 = "file in group-writable directory";
63159+
63160+ if (msg && msg2) {
63161+ char fullmsg[70] = {0};
63162+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
63163+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
63164+ return 0;
63165+ }
63166+ msg = NULL;
63167+next_check:
63168+#ifdef CONFIG_GRKERNSEC_TPE_ALL
63169+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
63170+ return 1;
63171+
63172+ if (inode->i_uid && (inode->i_uid != cred->uid))
63173+ msg = "directory not owned by user";
63174+ else if (inode->i_mode & S_IWOTH)
63175+ msg = "file in world-writable directory";
63176+ else if (inode->i_mode & S_IWGRP)
63177+ msg = "file in group-writable directory";
63178+
63179+ if (msg) {
63180+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
63181+ return 0;
63182+ }
63183+#endif
63184+#endif
63185+ return 1;
63186+}
63187diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
63188new file mode 100644
63189index 0000000..9f7b1ac
63190--- /dev/null
63191+++ b/grsecurity/grsum.c
63192@@ -0,0 +1,61 @@
63193+#include <linux/err.h>
63194+#include <linux/kernel.h>
63195+#include <linux/sched.h>
63196+#include <linux/mm.h>
63197+#include <linux/scatterlist.h>
63198+#include <linux/crypto.h>
63199+#include <linux/gracl.h>
63200+
63201+
63202+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
63203+#error "crypto and sha256 must be built into the kernel"
63204+#endif
63205+
63206+int
63207+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
63208+{
63209+ char *p;
63210+ struct crypto_hash *tfm;
63211+ struct hash_desc desc;
63212+ struct scatterlist sg;
63213+ unsigned char temp_sum[GR_SHA_LEN];
63214+ volatile int retval = 0;
63215+ volatile int dummy = 0;
63216+ unsigned int i;
63217+
63218+ sg_init_table(&sg, 1);
63219+
63220+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
63221+ if (IS_ERR(tfm)) {
63222+ /* should never happen, since sha256 should be built in */
63223+ return 1;
63224+ }
63225+
63226+ desc.tfm = tfm;
63227+ desc.flags = 0;
63228+
63229+ crypto_hash_init(&desc);
63230+
63231+ p = salt;
63232+ sg_set_buf(&sg, p, GR_SALT_LEN);
63233+ crypto_hash_update(&desc, &sg, sg.length);
63234+
63235+ p = entry->pw;
63236+ sg_set_buf(&sg, p, strlen(p));
63237+
63238+ crypto_hash_update(&desc, &sg, sg.length);
63239+
63240+ crypto_hash_final(&desc, temp_sum);
63241+
63242+ memset(entry->pw, 0, GR_PW_LEN);
63243+
63244+ for (i = 0; i < GR_SHA_LEN; i++)
63245+ if (sum[i] != temp_sum[i])
63246+ retval = 1;
63247+ else
63248+ dummy = 1; // waste a cycle
63249+
63250+ crypto_free_hash(tfm);
63251+
63252+ return retval;
63253+}
63254diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
63255index 77ff547..181834f 100644
63256--- a/include/asm-generic/4level-fixup.h
63257+++ b/include/asm-generic/4level-fixup.h
63258@@ -13,8 +13,10 @@
63259 #define pmd_alloc(mm, pud, address) \
63260 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
63261 NULL: pmd_offset(pud, address))
63262+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
63263
63264 #define pud_alloc(mm, pgd, address) (pgd)
63265+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
63266 #define pud_offset(pgd, start) (pgd)
63267 #define pud_none(pud) 0
63268 #define pud_bad(pud) 0
63269diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
63270index b7babf0..04ad282 100644
63271--- a/include/asm-generic/atomic-long.h
63272+++ b/include/asm-generic/atomic-long.h
63273@@ -22,6 +22,12 @@
63274
63275 typedef atomic64_t atomic_long_t;
63276
63277+#ifdef CONFIG_PAX_REFCOUNT
63278+typedef atomic64_unchecked_t atomic_long_unchecked_t;
63279+#else
63280+typedef atomic64_t atomic_long_unchecked_t;
63281+#endif
63282+
63283 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
63284
63285 static inline long atomic_long_read(atomic_long_t *l)
63286@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
63287 return (long)atomic64_read(v);
63288 }
63289
63290+#ifdef CONFIG_PAX_REFCOUNT
63291+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
63292+{
63293+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63294+
63295+ return (long)atomic64_read_unchecked(v);
63296+}
63297+#endif
63298+
63299 static inline void atomic_long_set(atomic_long_t *l, long i)
63300 {
63301 atomic64_t *v = (atomic64_t *)l;
63302@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
63303 atomic64_set(v, i);
63304 }
63305
63306+#ifdef CONFIG_PAX_REFCOUNT
63307+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
63308+{
63309+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63310+
63311+ atomic64_set_unchecked(v, i);
63312+}
63313+#endif
63314+
63315 static inline void atomic_long_inc(atomic_long_t *l)
63316 {
63317 atomic64_t *v = (atomic64_t *)l;
63318@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
63319 atomic64_inc(v);
63320 }
63321
63322+#ifdef CONFIG_PAX_REFCOUNT
63323+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
63324+{
63325+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63326+
63327+ atomic64_inc_unchecked(v);
63328+}
63329+#endif
63330+
63331 static inline void atomic_long_dec(atomic_long_t *l)
63332 {
63333 atomic64_t *v = (atomic64_t *)l;
63334@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
63335 atomic64_dec(v);
63336 }
63337
63338+#ifdef CONFIG_PAX_REFCOUNT
63339+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
63340+{
63341+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63342+
63343+ atomic64_dec_unchecked(v);
63344+}
63345+#endif
63346+
63347 static inline void atomic_long_add(long i, atomic_long_t *l)
63348 {
63349 atomic64_t *v = (atomic64_t *)l;
63350@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
63351 atomic64_add(i, v);
63352 }
63353
63354+#ifdef CONFIG_PAX_REFCOUNT
63355+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
63356+{
63357+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63358+
63359+ atomic64_add_unchecked(i, v);
63360+}
63361+#endif
63362+
63363 static inline void atomic_long_sub(long i, atomic_long_t *l)
63364 {
63365 atomic64_t *v = (atomic64_t *)l;
63366@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
63367 atomic64_sub(i, v);
63368 }
63369
63370+#ifdef CONFIG_PAX_REFCOUNT
63371+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
63372+{
63373+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63374+
63375+ atomic64_sub_unchecked(i, v);
63376+}
63377+#endif
63378+
63379 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
63380 {
63381 atomic64_t *v = (atomic64_t *)l;
63382@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
63383 return (long)atomic64_add_return(i, v);
63384 }
63385
63386+#ifdef CONFIG_PAX_REFCOUNT
63387+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
63388+{
63389+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63390+
63391+ return (long)atomic64_add_return_unchecked(i, v);
63392+}
63393+#endif
63394+
63395 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
63396 {
63397 atomic64_t *v = (atomic64_t *)l;
63398@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
63399 return (long)atomic64_inc_return(v);
63400 }
63401
63402+#ifdef CONFIG_PAX_REFCOUNT
63403+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
63404+{
63405+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63406+
63407+ return (long)atomic64_inc_return_unchecked(v);
63408+}
63409+#endif
63410+
63411 static inline long atomic_long_dec_return(atomic_long_t *l)
63412 {
63413 atomic64_t *v = (atomic64_t *)l;
63414@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
63415
63416 typedef atomic_t atomic_long_t;
63417
63418+#ifdef CONFIG_PAX_REFCOUNT
63419+typedef atomic_unchecked_t atomic_long_unchecked_t;
63420+#else
63421+typedef atomic_t atomic_long_unchecked_t;
63422+#endif
63423+
63424 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
63425 static inline long atomic_long_read(atomic_long_t *l)
63426 {
63427@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
63428 return (long)atomic_read(v);
63429 }
63430
63431+#ifdef CONFIG_PAX_REFCOUNT
63432+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
63433+{
63434+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63435+
63436+ return (long)atomic_read_unchecked(v);
63437+}
63438+#endif
63439+
63440 static inline void atomic_long_set(atomic_long_t *l, long i)
63441 {
63442 atomic_t *v = (atomic_t *)l;
63443@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
63444 atomic_set(v, i);
63445 }
63446
63447+#ifdef CONFIG_PAX_REFCOUNT
63448+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
63449+{
63450+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63451+
63452+ atomic_set_unchecked(v, i);
63453+}
63454+#endif
63455+
63456 static inline void atomic_long_inc(atomic_long_t *l)
63457 {
63458 atomic_t *v = (atomic_t *)l;
63459@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
63460 atomic_inc(v);
63461 }
63462
63463+#ifdef CONFIG_PAX_REFCOUNT
63464+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
63465+{
63466+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63467+
63468+ atomic_inc_unchecked(v);
63469+}
63470+#endif
63471+
63472 static inline void atomic_long_dec(atomic_long_t *l)
63473 {
63474 atomic_t *v = (atomic_t *)l;
63475@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
63476 atomic_dec(v);
63477 }
63478
63479+#ifdef CONFIG_PAX_REFCOUNT
63480+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
63481+{
63482+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63483+
63484+ atomic_dec_unchecked(v);
63485+}
63486+#endif
63487+
63488 static inline void atomic_long_add(long i, atomic_long_t *l)
63489 {
63490 atomic_t *v = (atomic_t *)l;
63491@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
63492 atomic_add(i, v);
63493 }
63494
63495+#ifdef CONFIG_PAX_REFCOUNT
63496+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
63497+{
63498+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63499+
63500+ atomic_add_unchecked(i, v);
63501+}
63502+#endif
63503+
63504 static inline void atomic_long_sub(long i, atomic_long_t *l)
63505 {
63506 atomic_t *v = (atomic_t *)l;
63507@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
63508 atomic_sub(i, v);
63509 }
63510
63511+#ifdef CONFIG_PAX_REFCOUNT
63512+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
63513+{
63514+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63515+
63516+ atomic_sub_unchecked(i, v);
63517+}
63518+#endif
63519+
63520 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
63521 {
63522 atomic_t *v = (atomic_t *)l;
63523@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
63524 return (long)atomic_add_return(i, v);
63525 }
63526
63527+#ifdef CONFIG_PAX_REFCOUNT
63528+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
63529+{
63530+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63531+
63532+ return (long)atomic_add_return_unchecked(i, v);
63533+}
63534+
63535+#endif
63536+
63537 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
63538 {
63539 atomic_t *v = (atomic_t *)l;
63540@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
63541 return (long)atomic_inc_return(v);
63542 }
63543
63544+#ifdef CONFIG_PAX_REFCOUNT
63545+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
63546+{
63547+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63548+
63549+ return (long)atomic_inc_return_unchecked(v);
63550+}
63551+#endif
63552+
63553 static inline long atomic_long_dec_return(atomic_long_t *l)
63554 {
63555 atomic_t *v = (atomic_t *)l;
63556@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
63557
63558 #endif /* BITS_PER_LONG == 64 */
63559
63560+#ifdef CONFIG_PAX_REFCOUNT
63561+static inline void pax_refcount_needs_these_functions(void)
63562+{
63563+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
63564+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
63565+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
63566+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
63567+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
63568+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
63569+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
63570+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
63571+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
63572+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
63573+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
63574+#ifdef CONFIG_X86
63575+ atomic_clear_mask_unchecked(0, NULL);
63576+ atomic_set_mask_unchecked(0, NULL);
63577+#endif
63578+
63579+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
63580+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
63581+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
63582+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
63583+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
63584+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
63585+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
63586+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
63587+}
63588+#else
63589+#define atomic_read_unchecked(v) atomic_read(v)
63590+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
63591+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
63592+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
63593+#define atomic_inc_unchecked(v) atomic_inc(v)
63594+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
63595+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
63596+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
63597+#define atomic_dec_unchecked(v) atomic_dec(v)
63598+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
63599+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
63600+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
63601+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
63602+
63603+#define atomic_long_read_unchecked(v) atomic_long_read(v)
63604+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
63605+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
63606+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
63607+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
63608+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
63609+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
63610+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
63611+#endif
63612+
63613 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
63614diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
63615index 1ced641..c896ee8 100644
63616--- a/include/asm-generic/atomic.h
63617+++ b/include/asm-generic/atomic.h
63618@@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
63619 * Atomically clears the bits set in @mask from @v
63620 */
63621 #ifndef atomic_clear_mask
63622-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
63623+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
63624 {
63625 unsigned long flags;
63626
63627diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
63628index b18ce4f..2ee2843 100644
63629--- a/include/asm-generic/atomic64.h
63630+++ b/include/asm-generic/atomic64.h
63631@@ -16,6 +16,8 @@ typedef struct {
63632 long long counter;
63633 } atomic64_t;
63634
63635+typedef atomic64_t atomic64_unchecked_t;
63636+
63637 #define ATOMIC64_INIT(i) { (i) }
63638
63639 extern long long atomic64_read(const atomic64_t *v);
63640@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
63641 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
63642 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
63643
63644+#define atomic64_read_unchecked(v) atomic64_read(v)
63645+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
63646+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
63647+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
63648+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
63649+#define atomic64_inc_unchecked(v) atomic64_inc(v)
63650+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
63651+#define atomic64_dec_unchecked(v) atomic64_dec(v)
63652+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
63653+
63654 #endif /* _ASM_GENERIC_ATOMIC64_H */
63655diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
63656index 1bfcfe5..e04c5c9 100644
63657--- a/include/asm-generic/cache.h
63658+++ b/include/asm-generic/cache.h
63659@@ -6,7 +6,7 @@
63660 * cache lines need to provide their own cache.h.
63661 */
63662
63663-#define L1_CACHE_SHIFT 5
63664-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
63665+#define L1_CACHE_SHIFT 5UL
63666+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
63667
63668 #endif /* __ASM_GENERIC_CACHE_H */
63669diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
63670index 0d68a1e..b74a761 100644
63671--- a/include/asm-generic/emergency-restart.h
63672+++ b/include/asm-generic/emergency-restart.h
63673@@ -1,7 +1,7 @@
63674 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
63675 #define _ASM_GENERIC_EMERGENCY_RESTART_H
63676
63677-static inline void machine_emergency_restart(void)
63678+static inline __noreturn void machine_emergency_restart(void)
63679 {
63680 machine_restart(NULL);
63681 }
63682diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
63683index 90f99c7..00ce236 100644
63684--- a/include/asm-generic/kmap_types.h
63685+++ b/include/asm-generic/kmap_types.h
63686@@ -2,9 +2,9 @@
63687 #define _ASM_GENERIC_KMAP_TYPES_H
63688
63689 #ifdef __WITH_KM_FENCE
63690-# define KM_TYPE_NR 41
63691+# define KM_TYPE_NR 42
63692 #else
63693-# define KM_TYPE_NR 20
63694+# define KM_TYPE_NR 21
63695 #endif
63696
63697 #endif
63698diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
63699index 9ceb03b..62b0b8f 100644
63700--- a/include/asm-generic/local.h
63701+++ b/include/asm-generic/local.h
63702@@ -23,24 +23,37 @@ typedef struct
63703 atomic_long_t a;
63704 } local_t;
63705
63706+typedef struct {
63707+ atomic_long_unchecked_t a;
63708+} local_unchecked_t;
63709+
63710 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
63711
63712 #define local_read(l) atomic_long_read(&(l)->a)
63713+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
63714 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
63715+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
63716 #define local_inc(l) atomic_long_inc(&(l)->a)
63717+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
63718 #define local_dec(l) atomic_long_dec(&(l)->a)
63719+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
63720 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
63721+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
63722 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
63723+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
63724
63725 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
63726 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
63727 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
63728 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
63729 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
63730+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
63731 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
63732 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
63733+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
63734
63735 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
63736+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
63737 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
63738 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
63739 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
63740diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
63741index 725612b..9cc513a 100644
63742--- a/include/asm-generic/pgtable-nopmd.h
63743+++ b/include/asm-generic/pgtable-nopmd.h
63744@@ -1,14 +1,19 @@
63745 #ifndef _PGTABLE_NOPMD_H
63746 #define _PGTABLE_NOPMD_H
63747
63748-#ifndef __ASSEMBLY__
63749-
63750 #include <asm-generic/pgtable-nopud.h>
63751
63752-struct mm_struct;
63753-
63754 #define __PAGETABLE_PMD_FOLDED
63755
63756+#define PMD_SHIFT PUD_SHIFT
63757+#define PTRS_PER_PMD 1
63758+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
63759+#define PMD_MASK (~(PMD_SIZE-1))
63760+
63761+#ifndef __ASSEMBLY__
63762+
63763+struct mm_struct;
63764+
63765 /*
63766 * Having the pmd type consist of a pud gets the size right, and allows
63767 * us to conceptually access the pud entry that this pmd is folded into
63768@@ -16,11 +21,6 @@ struct mm_struct;
63769 */
63770 typedef struct { pud_t pud; } pmd_t;
63771
63772-#define PMD_SHIFT PUD_SHIFT
63773-#define PTRS_PER_PMD 1
63774-#define PMD_SIZE (1UL << PMD_SHIFT)
63775-#define PMD_MASK (~(PMD_SIZE-1))
63776-
63777 /*
63778 * The "pud_xxx()" functions here are trivial for a folded two-level
63779 * setup: the pmd is never bad, and a pmd always exists (as it's folded
63780diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
63781index 810431d..0ec4804f 100644
63782--- a/include/asm-generic/pgtable-nopud.h
63783+++ b/include/asm-generic/pgtable-nopud.h
63784@@ -1,10 +1,15 @@
63785 #ifndef _PGTABLE_NOPUD_H
63786 #define _PGTABLE_NOPUD_H
63787
63788-#ifndef __ASSEMBLY__
63789-
63790 #define __PAGETABLE_PUD_FOLDED
63791
63792+#define PUD_SHIFT PGDIR_SHIFT
63793+#define PTRS_PER_PUD 1
63794+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
63795+#define PUD_MASK (~(PUD_SIZE-1))
63796+
63797+#ifndef __ASSEMBLY__
63798+
63799 /*
63800 * Having the pud type consist of a pgd gets the size right, and allows
63801 * us to conceptually access the pgd entry that this pud is folded into
63802@@ -12,11 +17,6 @@
63803 */
63804 typedef struct { pgd_t pgd; } pud_t;
63805
63806-#define PUD_SHIFT PGDIR_SHIFT
63807-#define PTRS_PER_PUD 1
63808-#define PUD_SIZE (1UL << PUD_SHIFT)
63809-#define PUD_MASK (~(PUD_SIZE-1))
63810-
63811 /*
63812 * The "pgd_xxx()" functions here are trivial for a folded two-level
63813 * setup: the pud is never bad, and a pud always exists (as it's folded
63814@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
63815 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
63816
63817 #define pgd_populate(mm, pgd, pud) do { } while (0)
63818+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
63819 /*
63820 * (puds are folded into pgds so this doesn't get actually called,
63821 * but the define is needed for a generic inline function.)
63822diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
63823index 5cf680a..4b74d62 100644
63824--- a/include/asm-generic/pgtable.h
63825+++ b/include/asm-generic/pgtable.h
63826@@ -688,6 +688,14 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
63827 }
63828 #endif /* CONFIG_NUMA_BALANCING */
63829
63830+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
63831+static inline unsigned long pax_open_kernel(void) { return 0; }
63832+#endif
63833+
63834+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
63835+static inline unsigned long pax_close_kernel(void) { return 0; }
63836+#endif
63837+
63838 #endif /* CONFIG_MMU */
63839
63840 #endif /* !__ASSEMBLY__ */
63841diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
63842index d1ea7ce..b1ebf2a 100644
63843--- a/include/asm-generic/vmlinux.lds.h
63844+++ b/include/asm-generic/vmlinux.lds.h
63845@@ -218,6 +218,7 @@
63846 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
63847 VMLINUX_SYMBOL(__start_rodata) = .; \
63848 *(.rodata) *(.rodata.*) \
63849+ *(.data..read_only) \
63850 *(__vermagic) /* Kernel version magic */ \
63851 . = ALIGN(8); \
63852 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
63853@@ -725,17 +726,18 @@
63854 * section in the linker script will go there too. @phdr should have
63855 * a leading colon.
63856 *
63857- * Note that this macros defines __per_cpu_load as an absolute symbol.
63858+ * Note that this macros defines per_cpu_load as an absolute symbol.
63859 * If there is no need to put the percpu section at a predetermined
63860 * address, use PERCPU_SECTION.
63861 */
63862 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
63863- VMLINUX_SYMBOL(__per_cpu_load) = .; \
63864- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
63865+ per_cpu_load = .; \
63866+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
63867 - LOAD_OFFSET) { \
63868+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
63869 PERCPU_INPUT(cacheline) \
63870 } phdr \
63871- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
63872+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
63873
63874 /**
63875 * PERCPU_SECTION - define output section for percpu area, simple version
63876diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
63877index 418d270..bfd2794 100644
63878--- a/include/crypto/algapi.h
63879+++ b/include/crypto/algapi.h
63880@@ -34,7 +34,7 @@ struct crypto_type {
63881 unsigned int maskclear;
63882 unsigned int maskset;
63883 unsigned int tfmsize;
63884-};
63885+} __do_const;
63886
63887 struct crypto_instance {
63888 struct crypto_alg alg;
63889diff --git a/include/drm/drmP.h b/include/drm/drmP.h
63890index fad21c9..3fff955 100644
63891--- a/include/drm/drmP.h
63892+++ b/include/drm/drmP.h
63893@@ -72,6 +72,7 @@
63894 #include <linux/workqueue.h>
63895 #include <linux/poll.h>
63896 #include <asm/pgalloc.h>
63897+#include <asm/local.h>
63898 #include <drm/drm.h>
63899 #include <drm/drm_sarea.h>
63900
63901@@ -1068,7 +1069,7 @@ struct drm_device {
63902
63903 /** \name Usage Counters */
63904 /*@{ */
63905- int open_count; /**< Outstanding files open */
63906+ local_t open_count; /**< Outstanding files open */
63907 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
63908 atomic_t vma_count; /**< Outstanding vma areas open */
63909 int buf_use; /**< Buffers in use -- cannot alloc */
63910@@ -1079,7 +1080,7 @@ struct drm_device {
63911 /*@{ */
63912 unsigned long counters;
63913 enum drm_stat_type types[15];
63914- atomic_t counts[15];
63915+ atomic_unchecked_t counts[15];
63916 /*@} */
63917
63918 struct list_head filelist;
63919diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
63920index f43d556..94d9343 100644
63921--- a/include/drm/drm_crtc_helper.h
63922+++ b/include/drm/drm_crtc_helper.h
63923@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
63924 struct drm_connector *connector);
63925 /* disable encoder when not in use - more explicit than dpms off */
63926 void (*disable)(struct drm_encoder *encoder);
63927-};
63928+} __no_const;
63929
63930 /**
63931 * drm_connector_helper_funcs - helper operations for connectors
63932diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
63933index 72dcbe8..8db58d7 100644
63934--- a/include/drm/ttm/ttm_memory.h
63935+++ b/include/drm/ttm/ttm_memory.h
63936@@ -48,7 +48,7 @@
63937
63938 struct ttm_mem_shrink {
63939 int (*do_shrink) (struct ttm_mem_shrink *);
63940-};
63941+} __no_const;
63942
63943 /**
63944 * struct ttm_mem_global - Global memory accounting structure.
63945diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
63946index c1da539..4db35ec 100644
63947--- a/include/linux/atmdev.h
63948+++ b/include/linux/atmdev.h
63949@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
63950 #endif
63951
63952 struct k_atm_aal_stats {
63953-#define __HANDLE_ITEM(i) atomic_t i
63954+#define __HANDLE_ITEM(i) atomic_unchecked_t i
63955 __AAL_STAT_ITEMS
63956 #undef __HANDLE_ITEM
63957 };
63958diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
63959index 0530b98..b127a9e 100644
63960--- a/include/linux/binfmts.h
63961+++ b/include/linux/binfmts.h
63962@@ -73,6 +73,7 @@ struct linux_binfmt {
63963 int (*load_binary)(struct linux_binprm *);
63964 int (*load_shlib)(struct file *);
63965 int (*core_dump)(struct coredump_params *cprm);
63966+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
63967 unsigned long min_coredump; /* minimal dump size */
63968 };
63969
63970diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
63971index f94bc83..62b9cfe 100644
63972--- a/include/linux/blkdev.h
63973+++ b/include/linux/blkdev.h
63974@@ -1498,7 +1498,7 @@ struct block_device_operations {
63975 /* this callback is with swap_lock and sometimes page table lock held */
63976 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
63977 struct module *owner;
63978-};
63979+} __do_const;
63980
63981 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
63982 unsigned long);
63983diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
63984index 7c2e030..b72475d 100644
63985--- a/include/linux/blktrace_api.h
63986+++ b/include/linux/blktrace_api.h
63987@@ -23,7 +23,7 @@ struct blk_trace {
63988 struct dentry *dir;
63989 struct dentry *dropped_file;
63990 struct dentry *msg_file;
63991- atomic_t dropped;
63992+ atomic_unchecked_t dropped;
63993 };
63994
63995 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
63996diff --git a/include/linux/cache.h b/include/linux/cache.h
63997index 4c57065..4307975 100644
63998--- a/include/linux/cache.h
63999+++ b/include/linux/cache.h
64000@@ -16,6 +16,10 @@
64001 #define __read_mostly
64002 #endif
64003
64004+#ifndef __read_only
64005+#define __read_only __read_mostly
64006+#endif
64007+
64008 #ifndef ____cacheline_aligned
64009 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
64010 #endif
64011diff --git a/include/linux/capability.h b/include/linux/capability.h
64012index 98503b7..cc36d18 100644
64013--- a/include/linux/capability.h
64014+++ b/include/linux/capability.h
64015@@ -211,8 +211,13 @@ extern bool capable(int cap);
64016 extern bool ns_capable(struct user_namespace *ns, int cap);
64017 extern bool nsown_capable(int cap);
64018 extern bool inode_capable(const struct inode *inode, int cap);
64019+extern bool capable_nolog(int cap);
64020+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
64021+extern bool inode_capable_nolog(const struct inode *inode, int cap);
64022
64023 /* audit system wants to get cap info from files as well */
64024 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
64025
64026+extern int is_privileged_binary(const struct dentry *dentry);
64027+
64028 #endif /* !_LINUX_CAPABILITY_H */
64029diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
64030index 8609d57..86e4d79 100644
64031--- a/include/linux/cdrom.h
64032+++ b/include/linux/cdrom.h
64033@@ -87,7 +87,6 @@ struct cdrom_device_ops {
64034
64035 /* driver specifications */
64036 const int capability; /* capability flags */
64037- int n_minors; /* number of active minor devices */
64038 /* handle uniform packets for scsi type devices (scsi,atapi) */
64039 int (*generic_packet) (struct cdrom_device_info *,
64040 struct packet_command *);
64041diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
64042index 42e55de..1cd0e66 100644
64043--- a/include/linux/cleancache.h
64044+++ b/include/linux/cleancache.h
64045@@ -31,7 +31,7 @@ struct cleancache_ops {
64046 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
64047 void (*invalidate_inode)(int, struct cleancache_filekey);
64048 void (*invalidate_fs)(int);
64049-};
64050+} __no_const;
64051
64052 extern struct cleancache_ops
64053 cleancache_register_ops(struct cleancache_ops *ops);
64054diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
64055index 662fd1b..e801992 100644
64056--- a/include/linux/compiler-gcc4.h
64057+++ b/include/linux/compiler-gcc4.h
64058@@ -34,6 +34,21 @@
64059 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
64060
64061 #if __GNUC_MINOR__ >= 5
64062+
64063+#ifdef CONSTIFY_PLUGIN
64064+#define __no_const __attribute__((no_const))
64065+#define __do_const __attribute__((do_const))
64066+#endif
64067+
64068+#ifdef SIZE_OVERFLOW_PLUGIN
64069+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
64070+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
64071+#endif
64072+
64073+#ifdef LATENT_ENTROPY_PLUGIN
64074+#define __latent_entropy __attribute__((latent_entropy))
64075+#endif
64076+
64077 /*
64078 * Mark a position in code as unreachable. This can be used to
64079 * suppress control flow warnings after asm blocks that transfer
64080@@ -49,6 +64,11 @@
64081 #define __noclone __attribute__((__noclone__))
64082
64083 #endif
64084+
64085+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
64086+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
64087+#define __bos0(ptr) __bos((ptr), 0)
64088+#define __bos1(ptr) __bos((ptr), 1)
64089 #endif
64090
64091 #if __GNUC_MINOR__ >= 6
64092diff --git a/include/linux/compiler.h b/include/linux/compiler.h
64093index dd852b7..72924c0 100644
64094--- a/include/linux/compiler.h
64095+++ b/include/linux/compiler.h
64096@@ -5,11 +5,14 @@
64097
64098 #ifdef __CHECKER__
64099 # define __user __attribute__((noderef, address_space(1)))
64100+# define __force_user __force __user
64101 # define __kernel __attribute__((address_space(0)))
64102+# define __force_kernel __force __kernel
64103 # define __safe __attribute__((safe))
64104 # define __force __attribute__((force))
64105 # define __nocast __attribute__((nocast))
64106 # define __iomem __attribute__((noderef, address_space(2)))
64107+# define __force_iomem __force __iomem
64108 # define __must_hold(x) __attribute__((context(x,1,1)))
64109 # define __acquires(x) __attribute__((context(x,0,1)))
64110 # define __releases(x) __attribute__((context(x,1,0)))
64111@@ -17,20 +20,48 @@
64112 # define __release(x) __context__(x,-1)
64113 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
64114 # define __percpu __attribute__((noderef, address_space(3)))
64115+# define __force_percpu __force __percpu
64116 #ifdef CONFIG_SPARSE_RCU_POINTER
64117 # define __rcu __attribute__((noderef, address_space(4)))
64118+# define __force_rcu __force __rcu
64119 #else
64120 # define __rcu
64121+# define __force_rcu
64122 #endif
64123 extern void __chk_user_ptr(const volatile void __user *);
64124 extern void __chk_io_ptr(const volatile void __iomem *);
64125+#elif defined(CHECKER_PLUGIN)
64126+//# define __user
64127+//# define __force_user
64128+//# define __kernel
64129+//# define __force_kernel
64130+# define __safe
64131+# define __force
64132+# define __nocast
64133+# define __iomem
64134+# define __force_iomem
64135+# define __chk_user_ptr(x) (void)0
64136+# define __chk_io_ptr(x) (void)0
64137+# define __builtin_warning(x, y...) (1)
64138+# define __acquires(x)
64139+# define __releases(x)
64140+# define __acquire(x) (void)0
64141+# define __release(x) (void)0
64142+# define __cond_lock(x,c) (c)
64143+# define __percpu
64144+# define __force_percpu
64145+# define __rcu
64146+# define __force_rcu
64147 #else
64148 # define __user
64149+# define __force_user
64150 # define __kernel
64151+# define __force_kernel
64152 # define __safe
64153 # define __force
64154 # define __nocast
64155 # define __iomem
64156+# define __force_iomem
64157 # define __chk_user_ptr(x) (void)0
64158 # define __chk_io_ptr(x) (void)0
64159 # define __builtin_warning(x, y...) (1)
64160@@ -41,7 +72,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
64161 # define __release(x) (void)0
64162 # define __cond_lock(x,c) (c)
64163 # define __percpu
64164+# define __force_percpu
64165 # define __rcu
64166+# define __force_rcu
64167 #endif
64168
64169 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
64170@@ -275,6 +308,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
64171 # define __attribute_const__ /* unimplemented */
64172 #endif
64173
64174+#ifndef __no_const
64175+# define __no_const
64176+#endif
64177+
64178+#ifndef __do_const
64179+# define __do_const
64180+#endif
64181+
64182+#ifndef __size_overflow
64183+# define __size_overflow(...)
64184+#endif
64185+
64186+#ifndef __intentional_overflow
64187+# define __intentional_overflow(...)
64188+#endif
64189+
64190+#ifndef __latent_entropy
64191+# define __latent_entropy
64192+#endif
64193+
64194 /*
64195 * Tell gcc if a function is cold. The compiler will assume any path
64196 * directly leading to the call is unlikely.
64197@@ -284,6 +337,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
64198 #define __cold
64199 #endif
64200
64201+#ifndef __alloc_size
64202+#define __alloc_size(...)
64203+#endif
64204+
64205+#ifndef __bos
64206+#define __bos(ptr, arg)
64207+#endif
64208+
64209+#ifndef __bos0
64210+#define __bos0(ptr)
64211+#endif
64212+
64213+#ifndef __bos1
64214+#define __bos1(ptr)
64215+#endif
64216+
64217 /* Simple shorthand for a section definition */
64218 #ifndef __section
64219 # define __section(S) __attribute__ ((__section__(#S)))
64220@@ -323,6 +392,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
64221 * use is to mediate communication between process-level code and irq/NMI
64222 * handlers, all running on the same CPU.
64223 */
64224-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
64225+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
64226+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
64227
64228 #endif /* __LINUX_COMPILER_H */
64229diff --git a/include/linux/cpu.h b/include/linux/cpu.h
64230index ce7a074..01ab8ac 100644
64231--- a/include/linux/cpu.h
64232+++ b/include/linux/cpu.h
64233@@ -115,7 +115,7 @@ enum {
64234 /* Need to know about CPUs going up/down? */
64235 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
64236 #define cpu_notifier(fn, pri) { \
64237- static struct notifier_block fn##_nb __cpuinitdata = \
64238+ static struct notifier_block fn##_nb = \
64239 { .notifier_call = fn, .priority = pri }; \
64240 register_cpu_notifier(&fn##_nb); \
64241 }
64242diff --git a/include/linux/cred.h b/include/linux/cred.h
64243index 04421e8..6bce4ef 100644
64244--- a/include/linux/cred.h
64245+++ b/include/linux/cred.h
64246@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
64247 static inline void validate_process_creds(void)
64248 {
64249 }
64250+static inline void validate_task_creds(struct task_struct *task)
64251+{
64252+}
64253 #endif
64254
64255 /**
64256diff --git a/include/linux/crypto.h b/include/linux/crypto.h
64257index b92eadf..b4ecdc1 100644
64258--- a/include/linux/crypto.h
64259+++ b/include/linux/crypto.h
64260@@ -373,7 +373,7 @@ struct cipher_tfm {
64261 const u8 *key, unsigned int keylen);
64262 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
64263 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
64264-};
64265+} __no_const;
64266
64267 struct hash_tfm {
64268 int (*init)(struct hash_desc *desc);
64269@@ -394,13 +394,13 @@ struct compress_tfm {
64270 int (*cot_decompress)(struct crypto_tfm *tfm,
64271 const u8 *src, unsigned int slen,
64272 u8 *dst, unsigned int *dlen);
64273-};
64274+} __no_const;
64275
64276 struct rng_tfm {
64277 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
64278 unsigned int dlen);
64279 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
64280-};
64281+} __no_const;
64282
64283 #define crt_ablkcipher crt_u.ablkcipher
64284 #define crt_aead crt_u.aead
64285diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
64286index 7925bf0..d5143d2 100644
64287--- a/include/linux/decompress/mm.h
64288+++ b/include/linux/decompress/mm.h
64289@@ -77,7 +77,7 @@ static void free(void *where)
64290 * warnings when not needed (indeed large_malloc / large_free are not
64291 * needed by inflate */
64292
64293-#define malloc(a) kmalloc(a, GFP_KERNEL)
64294+#define malloc(a) kmalloc((a), GFP_KERNEL)
64295 #define free(a) kfree(a)
64296
64297 #define large_malloc(a) vmalloc(a)
64298diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
64299index 94af418..b1ca7a2 100644
64300--- a/include/linux/dma-mapping.h
64301+++ b/include/linux/dma-mapping.h
64302@@ -54,7 +54,7 @@ struct dma_map_ops {
64303 u64 (*get_required_mask)(struct device *dev);
64304 #endif
64305 int is_phys;
64306-};
64307+} __do_const;
64308
64309 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
64310
64311diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
64312index d3201e4..8281e63 100644
64313--- a/include/linux/dmaengine.h
64314+++ b/include/linux/dmaengine.h
64315@@ -1018,9 +1018,9 @@ struct dma_pinned_list {
64316 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
64317 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
64318
64319-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
64320+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
64321 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
64322-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
64323+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
64324 struct dma_pinned_list *pinned_list, struct page *page,
64325 unsigned int offset, size_t len);
64326
64327diff --git a/include/linux/efi.h b/include/linux/efi.h
64328index 7a9498a..155713d 100644
64329--- a/include/linux/efi.h
64330+++ b/include/linux/efi.h
64331@@ -733,6 +733,7 @@ struct efivar_operations {
64332 efi_set_variable_t *set_variable;
64333 efi_query_variable_info_t *query_variable_info;
64334 };
64335+typedef struct efivar_operations __no_const efivar_operations_no_const;
64336
64337 struct efivars {
64338 /*
64339diff --git a/include/linux/elf.h b/include/linux/elf.h
64340index 8c9048e..16a4665 100644
64341--- a/include/linux/elf.h
64342+++ b/include/linux/elf.h
64343@@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
64344 #define elf_note elf32_note
64345 #define elf_addr_t Elf32_Off
64346 #define Elf_Half Elf32_Half
64347+#define elf_dyn Elf32_Dyn
64348
64349 #else
64350
64351@@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
64352 #define elf_note elf64_note
64353 #define elf_addr_t Elf64_Off
64354 #define Elf_Half Elf64_Half
64355+#define elf_dyn Elf64_Dyn
64356
64357 #endif
64358
64359diff --git a/include/linux/filter.h b/include/linux/filter.h
64360index c45eabc..baa0be5 100644
64361--- a/include/linux/filter.h
64362+++ b/include/linux/filter.h
64363@@ -20,6 +20,7 @@ struct compat_sock_fprog {
64364
64365 struct sk_buff;
64366 struct sock;
64367+struct bpf_jit_work;
64368
64369 struct sk_filter
64370 {
64371@@ -27,6 +28,9 @@ struct sk_filter
64372 unsigned int len; /* Number of filter blocks */
64373 unsigned int (*bpf_func)(const struct sk_buff *skb,
64374 const struct sock_filter *filter);
64375+#ifdef CONFIG_BPF_JIT
64376+ struct bpf_jit_work *work;
64377+#endif
64378 struct rcu_head rcu;
64379 struct sock_filter insns[0];
64380 };
64381diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
64382index 3044254..9767f41 100644
64383--- a/include/linux/frontswap.h
64384+++ b/include/linux/frontswap.h
64385@@ -11,7 +11,7 @@ struct frontswap_ops {
64386 int (*load)(unsigned, pgoff_t, struct page *);
64387 void (*invalidate_page)(unsigned, pgoff_t);
64388 void (*invalidate_area)(unsigned);
64389-};
64390+} __no_const;
64391
64392 extern bool frontswap_enabled;
64393 extern struct frontswap_ops
64394diff --git a/include/linux/fs.h b/include/linux/fs.h
64395index 7617ee0..b575199 100644
64396--- a/include/linux/fs.h
64397+++ b/include/linux/fs.h
64398@@ -1541,7 +1541,8 @@ struct file_operations {
64399 long (*fallocate)(struct file *file, int mode, loff_t offset,
64400 loff_t len);
64401 int (*show_fdinfo)(struct seq_file *m, struct file *f);
64402-};
64403+} __do_const;
64404+typedef struct file_operations __no_const file_operations_no_const;
64405
64406 struct inode_operations {
64407 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
64408@@ -2665,4 +2666,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
64409 inode->i_flags |= S_NOSEC;
64410 }
64411
64412+static inline bool is_sidechannel_device(const struct inode *inode)
64413+{
64414+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
64415+ umode_t mode = inode->i_mode;
64416+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
64417+#else
64418+ return false;
64419+#endif
64420+}
64421+
64422 #endif /* _LINUX_FS_H */
64423diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
64424index d0ae3a8..0244b34 100644
64425--- a/include/linux/fs_struct.h
64426+++ b/include/linux/fs_struct.h
64427@@ -6,7 +6,7 @@
64428 #include <linux/seqlock.h>
64429
64430 struct fs_struct {
64431- int users;
64432+ atomic_t users;
64433 spinlock_t lock;
64434 seqcount_t seq;
64435 int umask;
64436diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
64437index 5dfa0aa..6acf322 100644
64438--- a/include/linux/fscache-cache.h
64439+++ b/include/linux/fscache-cache.h
64440@@ -112,7 +112,7 @@ struct fscache_operation {
64441 fscache_operation_release_t release;
64442 };
64443
64444-extern atomic_t fscache_op_debug_id;
64445+extern atomic_unchecked_t fscache_op_debug_id;
64446 extern void fscache_op_work_func(struct work_struct *work);
64447
64448 extern void fscache_enqueue_operation(struct fscache_operation *);
64449@@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
64450 INIT_WORK(&op->work, fscache_op_work_func);
64451 atomic_set(&op->usage, 1);
64452 op->state = FSCACHE_OP_ST_INITIALISED;
64453- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
64454+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
64455 op->processor = processor;
64456 op->release = release;
64457 INIT_LIST_HEAD(&op->pend_link);
64458diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
64459index 0fbfb46..508eb0d 100644
64460--- a/include/linux/fsnotify.h
64461+++ b/include/linux/fsnotify.h
64462@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
64463 struct inode *inode = path->dentry->d_inode;
64464 __u32 mask = FS_ACCESS;
64465
64466+ if (is_sidechannel_device(inode))
64467+ return;
64468+
64469 if (S_ISDIR(inode->i_mode))
64470 mask |= FS_ISDIR;
64471
64472@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
64473 struct inode *inode = path->dentry->d_inode;
64474 __u32 mask = FS_MODIFY;
64475
64476+ if (is_sidechannel_device(inode))
64477+ return;
64478+
64479 if (S_ISDIR(inode->i_mode))
64480 mask |= FS_ISDIR;
64481
64482@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
64483 */
64484 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
64485 {
64486- return kstrdup(name, GFP_KERNEL);
64487+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
64488 }
64489
64490 /*
64491diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
64492index a3d4895..ddd2a50 100644
64493--- a/include/linux/ftrace_event.h
64494+++ b/include/linux/ftrace_event.h
64495@@ -272,7 +272,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
64496 extern int trace_add_event_call(struct ftrace_event_call *call);
64497 extern void trace_remove_event_call(struct ftrace_event_call *call);
64498
64499-#define is_signed_type(type) (((type)(-1)) < 0)
64500+#define is_signed_type(type) (((type)(-1)) < (type)1)
64501
64502 int trace_set_clr_event(const char *system, const char *event, int set);
64503
64504diff --git a/include/linux/genhd.h b/include/linux/genhd.h
64505index 79b8bba..86b539e 100644
64506--- a/include/linux/genhd.h
64507+++ b/include/linux/genhd.h
64508@@ -194,7 +194,7 @@ struct gendisk {
64509 struct kobject *slave_dir;
64510
64511 struct timer_rand_state *random;
64512- atomic_t sync_io; /* RAID */
64513+ atomic_unchecked_t sync_io; /* RAID */
64514 struct disk_events *ev;
64515 #ifdef CONFIG_BLK_DEV_INTEGRITY
64516 struct blk_integrity *integrity;
64517diff --git a/include/linux/gfp.h b/include/linux/gfp.h
64518index 0f615eb..5c3832f 100644
64519--- a/include/linux/gfp.h
64520+++ b/include/linux/gfp.h
64521@@ -35,6 +35,13 @@ struct vm_area_struct;
64522 #define ___GFP_NO_KSWAPD 0x400000u
64523 #define ___GFP_OTHER_NODE 0x800000u
64524 #define ___GFP_WRITE 0x1000000u
64525+
64526+#ifdef CONFIG_PAX_USERCOPY_SLABS
64527+#define ___GFP_USERCOPY 0x2000000u
64528+#else
64529+#define ___GFP_USERCOPY 0
64530+#endif
64531+
64532 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
64533
64534 /*
64535@@ -92,6 +99,7 @@ struct vm_area_struct;
64536 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
64537 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
64538 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
64539+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
64540
64541 /*
64542 * This may seem redundant, but it's a way of annotating false positives vs.
64543@@ -99,7 +107,7 @@ struct vm_area_struct;
64544 */
64545 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
64546
64547-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
64548+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
64549 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
64550
64551 /* This equals 0, but use constants in case they ever change */
64552@@ -153,6 +161,8 @@ struct vm_area_struct;
64553 /* 4GB DMA on some platforms */
64554 #define GFP_DMA32 __GFP_DMA32
64555
64556+#define GFP_USERCOPY __GFP_USERCOPY
64557+
64558 /* Convert GFP flags to their corresponding migrate type */
64559 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
64560 {
64561diff --git a/include/linux/gracl.h b/include/linux/gracl.h
64562new file mode 100644
64563index 0000000..ebe6d72
64564--- /dev/null
64565+++ b/include/linux/gracl.h
64566@@ -0,0 +1,319 @@
64567+#ifndef GR_ACL_H
64568+#define GR_ACL_H
64569+
64570+#include <linux/grdefs.h>
64571+#include <linux/resource.h>
64572+#include <linux/capability.h>
64573+#include <linux/dcache.h>
64574+#include <asm/resource.h>
64575+
64576+/* Major status information */
64577+
64578+#define GR_VERSION "grsecurity 2.9.1"
64579+#define GRSECURITY_VERSION 0x2901
64580+
64581+enum {
64582+ GR_SHUTDOWN = 0,
64583+ GR_ENABLE = 1,
64584+ GR_SPROLE = 2,
64585+ GR_RELOAD = 3,
64586+ GR_SEGVMOD = 4,
64587+ GR_STATUS = 5,
64588+ GR_UNSPROLE = 6,
64589+ GR_PASSSET = 7,
64590+ GR_SPROLEPAM = 8,
64591+};
64592+
64593+/* Password setup definitions
64594+ * kernel/grhash.c */
64595+enum {
64596+ GR_PW_LEN = 128,
64597+ GR_SALT_LEN = 16,
64598+ GR_SHA_LEN = 32,
64599+};
64600+
64601+enum {
64602+ GR_SPROLE_LEN = 64,
64603+};
64604+
64605+enum {
64606+ GR_NO_GLOB = 0,
64607+ GR_REG_GLOB,
64608+ GR_CREATE_GLOB
64609+};
64610+
64611+#define GR_NLIMITS 32
64612+
64613+/* Begin Data Structures */
64614+
64615+struct sprole_pw {
64616+ unsigned char *rolename;
64617+ unsigned char salt[GR_SALT_LEN];
64618+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
64619+};
64620+
64621+struct name_entry {
64622+ __u32 key;
64623+ ino_t inode;
64624+ dev_t device;
64625+ char *name;
64626+ __u16 len;
64627+ __u8 deleted;
64628+ struct name_entry *prev;
64629+ struct name_entry *next;
64630+};
64631+
64632+struct inodev_entry {
64633+ struct name_entry *nentry;
64634+ struct inodev_entry *prev;
64635+ struct inodev_entry *next;
64636+};
64637+
64638+struct acl_role_db {
64639+ struct acl_role_label **r_hash;
64640+ __u32 r_size;
64641+};
64642+
64643+struct inodev_db {
64644+ struct inodev_entry **i_hash;
64645+ __u32 i_size;
64646+};
64647+
64648+struct name_db {
64649+ struct name_entry **n_hash;
64650+ __u32 n_size;
64651+};
64652+
64653+struct crash_uid {
64654+ uid_t uid;
64655+ unsigned long expires;
64656+};
64657+
64658+struct gr_hash_struct {
64659+ void **table;
64660+ void **nametable;
64661+ void *first;
64662+ __u32 table_size;
64663+ __u32 used_size;
64664+ int type;
64665+};
64666+
64667+/* Userspace Grsecurity ACL data structures */
64668+
64669+struct acl_subject_label {
64670+ char *filename;
64671+ ino_t inode;
64672+ dev_t device;
64673+ __u32 mode;
64674+ kernel_cap_t cap_mask;
64675+ kernel_cap_t cap_lower;
64676+ kernel_cap_t cap_invert_audit;
64677+
64678+ struct rlimit res[GR_NLIMITS];
64679+ __u32 resmask;
64680+
64681+ __u8 user_trans_type;
64682+ __u8 group_trans_type;
64683+ uid_t *user_transitions;
64684+ gid_t *group_transitions;
64685+ __u16 user_trans_num;
64686+ __u16 group_trans_num;
64687+
64688+ __u32 sock_families[2];
64689+ __u32 ip_proto[8];
64690+ __u32 ip_type;
64691+ struct acl_ip_label **ips;
64692+ __u32 ip_num;
64693+ __u32 inaddr_any_override;
64694+
64695+ __u32 crashes;
64696+ unsigned long expires;
64697+
64698+ struct acl_subject_label *parent_subject;
64699+ struct gr_hash_struct *hash;
64700+ struct acl_subject_label *prev;
64701+ struct acl_subject_label *next;
64702+
64703+ struct acl_object_label **obj_hash;
64704+ __u32 obj_hash_size;
64705+ __u16 pax_flags;
64706+};
64707+
64708+struct role_allowed_ip {
64709+ __u32 addr;
64710+ __u32 netmask;
64711+
64712+ struct role_allowed_ip *prev;
64713+ struct role_allowed_ip *next;
64714+};
64715+
64716+struct role_transition {
64717+ char *rolename;
64718+
64719+ struct role_transition *prev;
64720+ struct role_transition *next;
64721+};
64722+
64723+struct acl_role_label {
64724+ char *rolename;
64725+ uid_t uidgid;
64726+ __u16 roletype;
64727+
64728+ __u16 auth_attempts;
64729+ unsigned long expires;
64730+
64731+ struct acl_subject_label *root_label;
64732+ struct gr_hash_struct *hash;
64733+
64734+ struct acl_role_label *prev;
64735+ struct acl_role_label *next;
64736+
64737+ struct role_transition *transitions;
64738+ struct role_allowed_ip *allowed_ips;
64739+ uid_t *domain_children;
64740+ __u16 domain_child_num;
64741+
64742+ umode_t umask;
64743+
64744+ struct acl_subject_label **subj_hash;
64745+ __u32 subj_hash_size;
64746+};
64747+
64748+struct user_acl_role_db {
64749+ struct acl_role_label **r_table;
64750+ __u32 num_pointers; /* Number of allocations to track */
64751+ __u32 num_roles; /* Number of roles */
64752+ __u32 num_domain_children; /* Number of domain children */
64753+ __u32 num_subjects; /* Number of subjects */
64754+ __u32 num_objects; /* Number of objects */
64755+};
64756+
64757+struct acl_object_label {
64758+ char *filename;
64759+ ino_t inode;
64760+ dev_t device;
64761+ __u32 mode;
64762+
64763+ struct acl_subject_label *nested;
64764+ struct acl_object_label *globbed;
64765+
64766+ /* next two structures not used */
64767+
64768+ struct acl_object_label *prev;
64769+ struct acl_object_label *next;
64770+};
64771+
64772+struct acl_ip_label {
64773+ char *iface;
64774+ __u32 addr;
64775+ __u32 netmask;
64776+ __u16 low, high;
64777+ __u8 mode;
64778+ __u32 type;
64779+ __u32 proto[8];
64780+
64781+ /* next two structures not used */
64782+
64783+ struct acl_ip_label *prev;
64784+ struct acl_ip_label *next;
64785+};
64786+
64787+struct gr_arg {
64788+ struct user_acl_role_db role_db;
64789+ unsigned char pw[GR_PW_LEN];
64790+ unsigned char salt[GR_SALT_LEN];
64791+ unsigned char sum[GR_SHA_LEN];
64792+ unsigned char sp_role[GR_SPROLE_LEN];
64793+ struct sprole_pw *sprole_pws;
64794+ dev_t segv_device;
64795+ ino_t segv_inode;
64796+ uid_t segv_uid;
64797+ __u16 num_sprole_pws;
64798+ __u16 mode;
64799+};
64800+
64801+struct gr_arg_wrapper {
64802+ struct gr_arg *arg;
64803+ __u32 version;
64804+ __u32 size;
64805+};
64806+
64807+struct subject_map {
64808+ struct acl_subject_label *user;
64809+ struct acl_subject_label *kernel;
64810+ struct subject_map *prev;
64811+ struct subject_map *next;
64812+};
64813+
64814+struct acl_subj_map_db {
64815+ struct subject_map **s_hash;
64816+ __u32 s_size;
64817+};
64818+
64819+/* End Data Structures Section */
64820+
64821+/* Hash functions generated by empirical testing by Brad Spengler
64822+ Makes good use of the low bits of the inode. Generally 0-1 times
64823+ in loop for successful match. 0-3 for unsuccessful match.
64824+ Shift/add algorithm with modulus of table size and an XOR*/
64825+
64826+static __inline__ unsigned int
64827+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
64828+{
64829+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
64830+}
64831+
64832+ static __inline__ unsigned int
64833+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
64834+{
64835+ return ((const unsigned long)userp % sz);
64836+}
64837+
64838+static __inline__ unsigned int
64839+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
64840+{
64841+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
64842+}
64843+
64844+static __inline__ unsigned int
64845+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
64846+{
64847+ return full_name_hash((const unsigned char *)name, len) % sz;
64848+}
64849+
64850+#define FOR_EACH_ROLE_START(role) \
64851+ role = role_list; \
64852+ while (role) {
64853+
64854+#define FOR_EACH_ROLE_END(role) \
64855+ role = role->prev; \
64856+ }
64857+
64858+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
64859+ subj = NULL; \
64860+ iter = 0; \
64861+ while (iter < role->subj_hash_size) { \
64862+ if (subj == NULL) \
64863+ subj = role->subj_hash[iter]; \
64864+ if (subj == NULL) { \
64865+ iter++; \
64866+ continue; \
64867+ }
64868+
64869+#define FOR_EACH_SUBJECT_END(subj,iter) \
64870+ subj = subj->next; \
64871+ if (subj == NULL) \
64872+ iter++; \
64873+ }
64874+
64875+
64876+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
64877+ subj = role->hash->first; \
64878+ while (subj != NULL) {
64879+
64880+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
64881+ subj = subj->next; \
64882+ }
64883+
64884+#endif
64885+
64886diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
64887new file mode 100644
64888index 0000000..323ecf2
64889--- /dev/null
64890+++ b/include/linux/gralloc.h
64891@@ -0,0 +1,9 @@
64892+#ifndef __GRALLOC_H
64893+#define __GRALLOC_H
64894+
64895+void acl_free_all(void);
64896+int acl_alloc_stack_init(unsigned long size);
64897+void *acl_alloc(unsigned long len);
64898+void *acl_alloc_num(unsigned long num, unsigned long len);
64899+
64900+#endif
64901diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
64902new file mode 100644
64903index 0000000..be66033
64904--- /dev/null
64905+++ b/include/linux/grdefs.h
64906@@ -0,0 +1,140 @@
64907+#ifndef GRDEFS_H
64908+#define GRDEFS_H
64909+
64910+/* Begin grsecurity status declarations */
64911+
64912+enum {
64913+ GR_READY = 0x01,
64914+ GR_STATUS_INIT = 0x00 // disabled state
64915+};
64916+
64917+/* Begin ACL declarations */
64918+
64919+/* Role flags */
64920+
64921+enum {
64922+ GR_ROLE_USER = 0x0001,
64923+ GR_ROLE_GROUP = 0x0002,
64924+ GR_ROLE_DEFAULT = 0x0004,
64925+ GR_ROLE_SPECIAL = 0x0008,
64926+ GR_ROLE_AUTH = 0x0010,
64927+ GR_ROLE_NOPW = 0x0020,
64928+ GR_ROLE_GOD = 0x0040,
64929+ GR_ROLE_LEARN = 0x0080,
64930+ GR_ROLE_TPE = 0x0100,
64931+ GR_ROLE_DOMAIN = 0x0200,
64932+ GR_ROLE_PAM = 0x0400,
64933+ GR_ROLE_PERSIST = 0x0800
64934+};
64935+
64936+/* ACL Subject and Object mode flags */
64937+enum {
64938+ GR_DELETED = 0x80000000
64939+};
64940+
64941+/* ACL Object-only mode flags */
64942+enum {
64943+ GR_READ = 0x00000001,
64944+ GR_APPEND = 0x00000002,
64945+ GR_WRITE = 0x00000004,
64946+ GR_EXEC = 0x00000008,
64947+ GR_FIND = 0x00000010,
64948+ GR_INHERIT = 0x00000020,
64949+ GR_SETID = 0x00000040,
64950+ GR_CREATE = 0x00000080,
64951+ GR_DELETE = 0x00000100,
64952+ GR_LINK = 0x00000200,
64953+ GR_AUDIT_READ = 0x00000400,
64954+ GR_AUDIT_APPEND = 0x00000800,
64955+ GR_AUDIT_WRITE = 0x00001000,
64956+ GR_AUDIT_EXEC = 0x00002000,
64957+ GR_AUDIT_FIND = 0x00004000,
64958+ GR_AUDIT_INHERIT= 0x00008000,
64959+ GR_AUDIT_SETID = 0x00010000,
64960+ GR_AUDIT_CREATE = 0x00020000,
64961+ GR_AUDIT_DELETE = 0x00040000,
64962+ GR_AUDIT_LINK = 0x00080000,
64963+ GR_PTRACERD = 0x00100000,
64964+ GR_NOPTRACE = 0x00200000,
64965+ GR_SUPPRESS = 0x00400000,
64966+ GR_NOLEARN = 0x00800000,
64967+ GR_INIT_TRANSFER= 0x01000000
64968+};
64969+
64970+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
64971+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
64972+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
64973+
64974+/* ACL subject-only mode flags */
64975+enum {
64976+ GR_KILL = 0x00000001,
64977+ GR_VIEW = 0x00000002,
64978+ GR_PROTECTED = 0x00000004,
64979+ GR_LEARN = 0x00000008,
64980+ GR_OVERRIDE = 0x00000010,
64981+ /* just a placeholder, this mode is only used in userspace */
64982+ GR_DUMMY = 0x00000020,
64983+ GR_PROTSHM = 0x00000040,
64984+ GR_KILLPROC = 0x00000080,
64985+ GR_KILLIPPROC = 0x00000100,
64986+ /* just a placeholder, this mode is only used in userspace */
64987+ GR_NOTROJAN = 0x00000200,
64988+ GR_PROTPROCFD = 0x00000400,
64989+ GR_PROCACCT = 0x00000800,
64990+ GR_RELAXPTRACE = 0x00001000,
64991+ //GR_NESTED = 0x00002000,
64992+ GR_INHERITLEARN = 0x00004000,
64993+ GR_PROCFIND = 0x00008000,
64994+ GR_POVERRIDE = 0x00010000,
64995+ GR_KERNELAUTH = 0x00020000,
64996+ GR_ATSECURE = 0x00040000,
64997+ GR_SHMEXEC = 0x00080000
64998+};
64999+
65000+enum {
65001+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
65002+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
65003+ GR_PAX_ENABLE_MPROTECT = 0x0004,
65004+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
65005+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
65006+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
65007+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
65008+ GR_PAX_DISABLE_MPROTECT = 0x0400,
65009+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
65010+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
65011+};
65012+
65013+enum {
65014+ GR_ID_USER = 0x01,
65015+ GR_ID_GROUP = 0x02,
65016+};
65017+
65018+enum {
65019+ GR_ID_ALLOW = 0x01,
65020+ GR_ID_DENY = 0x02,
65021+};
65022+
65023+#define GR_CRASH_RES 31
65024+#define GR_UIDTABLE_MAX 500
65025+
65026+/* begin resource learning section */
65027+enum {
65028+ GR_RLIM_CPU_BUMP = 60,
65029+ GR_RLIM_FSIZE_BUMP = 50000,
65030+ GR_RLIM_DATA_BUMP = 10000,
65031+ GR_RLIM_STACK_BUMP = 1000,
65032+ GR_RLIM_CORE_BUMP = 10000,
65033+ GR_RLIM_RSS_BUMP = 500000,
65034+ GR_RLIM_NPROC_BUMP = 1,
65035+ GR_RLIM_NOFILE_BUMP = 5,
65036+ GR_RLIM_MEMLOCK_BUMP = 50000,
65037+ GR_RLIM_AS_BUMP = 500000,
65038+ GR_RLIM_LOCKS_BUMP = 2,
65039+ GR_RLIM_SIGPENDING_BUMP = 5,
65040+ GR_RLIM_MSGQUEUE_BUMP = 10000,
65041+ GR_RLIM_NICE_BUMP = 1,
65042+ GR_RLIM_RTPRIO_BUMP = 1,
65043+ GR_RLIM_RTTIME_BUMP = 1000000
65044+};
65045+
65046+#endif
65047diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
65048new file mode 100644
65049index 0000000..baa6e96
65050--- /dev/null
65051+++ b/include/linux/grinternal.h
65052@@ -0,0 +1,215 @@
65053+#ifndef __GRINTERNAL_H
65054+#define __GRINTERNAL_H
65055+
65056+#ifdef CONFIG_GRKERNSEC
65057+
65058+#include <linux/fs.h>
65059+#include <linux/mnt_namespace.h>
65060+#include <linux/nsproxy.h>
65061+#include <linux/gracl.h>
65062+#include <linux/grdefs.h>
65063+#include <linux/grmsg.h>
65064+
65065+void gr_add_learn_entry(const char *fmt, ...)
65066+ __attribute__ ((format (printf, 1, 2)));
65067+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
65068+ const struct vfsmount *mnt);
65069+__u32 gr_check_create(const struct dentry *new_dentry,
65070+ const struct dentry *parent,
65071+ const struct vfsmount *mnt, const __u32 mode);
65072+int gr_check_protected_task(const struct task_struct *task);
65073+__u32 to_gr_audit(const __u32 reqmode);
65074+int gr_set_acls(const int type);
65075+int gr_apply_subject_to_task(struct task_struct *task);
65076+int gr_acl_is_enabled(void);
65077+char gr_roletype_to_char(void);
65078+
65079+void gr_handle_alertkill(struct task_struct *task);
65080+char *gr_to_filename(const struct dentry *dentry,
65081+ const struct vfsmount *mnt);
65082+char *gr_to_filename1(const struct dentry *dentry,
65083+ const struct vfsmount *mnt);
65084+char *gr_to_filename2(const struct dentry *dentry,
65085+ const struct vfsmount *mnt);
65086+char *gr_to_filename3(const struct dentry *dentry,
65087+ const struct vfsmount *mnt);
65088+
65089+extern int grsec_enable_ptrace_readexec;
65090+extern int grsec_enable_harden_ptrace;
65091+extern int grsec_enable_link;
65092+extern int grsec_enable_fifo;
65093+extern int grsec_enable_execve;
65094+extern int grsec_enable_shm;
65095+extern int grsec_enable_execlog;
65096+extern int grsec_enable_signal;
65097+extern int grsec_enable_audit_ptrace;
65098+extern int grsec_enable_forkfail;
65099+extern int grsec_enable_time;
65100+extern int grsec_enable_rofs;
65101+extern int grsec_enable_chroot_shmat;
65102+extern int grsec_enable_chroot_mount;
65103+extern int grsec_enable_chroot_double;
65104+extern int grsec_enable_chroot_pivot;
65105+extern int grsec_enable_chroot_chdir;
65106+extern int grsec_enable_chroot_chmod;
65107+extern int grsec_enable_chroot_mknod;
65108+extern int grsec_enable_chroot_fchdir;
65109+extern int grsec_enable_chroot_nice;
65110+extern int grsec_enable_chroot_execlog;
65111+extern int grsec_enable_chroot_caps;
65112+extern int grsec_enable_chroot_sysctl;
65113+extern int grsec_enable_chroot_unix;
65114+extern int grsec_enable_symlinkown;
65115+extern int grsec_symlinkown_gid;
65116+extern int grsec_enable_tpe;
65117+extern int grsec_tpe_gid;
65118+extern int grsec_enable_tpe_all;
65119+extern int grsec_enable_tpe_invert;
65120+extern int grsec_enable_socket_all;
65121+extern int grsec_socket_all_gid;
65122+extern int grsec_enable_socket_client;
65123+extern int grsec_socket_client_gid;
65124+extern int grsec_enable_socket_server;
65125+extern int grsec_socket_server_gid;
65126+extern int grsec_audit_gid;
65127+extern int grsec_enable_group;
65128+extern int grsec_enable_audit_textrel;
65129+extern int grsec_enable_log_rwxmaps;
65130+extern int grsec_enable_mount;
65131+extern int grsec_enable_chdir;
65132+extern int grsec_resource_logging;
65133+extern int grsec_enable_blackhole;
65134+extern int grsec_lastack_retries;
65135+extern int grsec_enable_brute;
65136+extern int grsec_lock;
65137+
65138+extern spinlock_t grsec_alert_lock;
65139+extern unsigned long grsec_alert_wtime;
65140+extern unsigned long grsec_alert_fyet;
65141+
65142+extern spinlock_t grsec_audit_lock;
65143+
65144+extern rwlock_t grsec_exec_file_lock;
65145+
65146+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
65147+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
65148+ (tsk)->exec_file->f_vfsmnt) : "/")
65149+
65150+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
65151+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
65152+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
65153+
65154+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
65155+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
65156+ (tsk)->exec_file->f_vfsmnt) : "/")
65157+
65158+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
65159+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
65160+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
65161+
65162+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
65163+
65164+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
65165+
65166+#define GR_CHROOT_CAPS {{ \
65167+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
65168+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
65169+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
65170+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
65171+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
65172+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
65173+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
65174+
65175+#define security_learn(normal_msg,args...) \
65176+({ \
65177+ read_lock(&grsec_exec_file_lock); \
65178+ gr_add_learn_entry(normal_msg "\n", ## args); \
65179+ read_unlock(&grsec_exec_file_lock); \
65180+})
65181+
65182+enum {
65183+ GR_DO_AUDIT,
65184+ GR_DONT_AUDIT,
65185+ /* used for non-audit messages that we shouldn't kill the task on */
65186+ GR_DONT_AUDIT_GOOD
65187+};
65188+
65189+enum {
65190+ GR_TTYSNIFF,
65191+ GR_RBAC,
65192+ GR_RBAC_STR,
65193+ GR_STR_RBAC,
65194+ GR_RBAC_MODE2,
65195+ GR_RBAC_MODE3,
65196+ GR_FILENAME,
65197+ GR_SYSCTL_HIDDEN,
65198+ GR_NOARGS,
65199+ GR_ONE_INT,
65200+ GR_ONE_INT_TWO_STR,
65201+ GR_ONE_STR,
65202+ GR_STR_INT,
65203+ GR_TWO_STR_INT,
65204+ GR_TWO_INT,
65205+ GR_TWO_U64,
65206+ GR_THREE_INT,
65207+ GR_FIVE_INT_TWO_STR,
65208+ GR_TWO_STR,
65209+ GR_THREE_STR,
65210+ GR_FOUR_STR,
65211+ GR_STR_FILENAME,
65212+ GR_FILENAME_STR,
65213+ GR_FILENAME_TWO_INT,
65214+ GR_FILENAME_TWO_INT_STR,
65215+ GR_TEXTREL,
65216+ GR_PTRACE,
65217+ GR_RESOURCE,
65218+ GR_CAP,
65219+ GR_SIG,
65220+ GR_SIG2,
65221+ GR_CRASH1,
65222+ GR_CRASH2,
65223+ GR_PSACCT,
65224+ GR_RWXMAP
65225+};
65226+
65227+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
65228+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
65229+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
65230+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
65231+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
65232+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
65233+#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)
65234+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
65235+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
65236+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
65237+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
65238+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
65239+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
65240+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
65241+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
65242+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
65243+#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)
65244+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
65245+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
65246+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
65247+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
65248+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
65249+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
65250+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
65251+#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)
65252+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
65253+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
65254+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
65255+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
65256+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
65257+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
65258+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
65259+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
65260+#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)
65261+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
65262+
65263+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
65264+
65265+#endif
65266+
65267+#endif
65268diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
65269new file mode 100644
65270index 0000000..2bd4c8d
65271--- /dev/null
65272+++ b/include/linux/grmsg.h
65273@@ -0,0 +1,111 @@
65274+#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"
65275+#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"
65276+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
65277+#define GR_STOPMOD_MSG "denied modification of module state by "
65278+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
65279+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
65280+#define GR_IOPERM_MSG "denied use of ioperm() by "
65281+#define GR_IOPL_MSG "denied use of iopl() by "
65282+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
65283+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
65284+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
65285+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
65286+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
65287+#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"
65288+#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"
65289+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
65290+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
65291+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
65292+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
65293+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
65294+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
65295+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
65296+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
65297+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
65298+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
65299+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
65300+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
65301+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
65302+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
65303+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
65304+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
65305+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
65306+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
65307+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
65308+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
65309+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
65310+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
65311+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
65312+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
65313+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
65314+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
65315+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
65316+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
65317+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
65318+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
65319+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
65320+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
65321+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
65322+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
65323+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
65324+#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"
65325+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
65326+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
65327+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
65328+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
65329+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
65330+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
65331+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
65332+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
65333+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
65334+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
65335+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
65336+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
65337+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
65338+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
65339+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
65340+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
65341+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
65342+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
65343+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
65344+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
65345+#define GR_FAILFORK_MSG "failed fork with errno %s by "
65346+#define GR_NICE_CHROOT_MSG "denied priority change by "
65347+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
65348+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
65349+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
65350+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
65351+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
65352+#define GR_TIME_MSG "time set by "
65353+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
65354+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
65355+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
65356+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
65357+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
65358+#define GR_BIND_MSG "denied bind() by "
65359+#define GR_CONNECT_MSG "denied connect() by "
65360+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
65361+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
65362+#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"
65363+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
65364+#define GR_CAP_ACL_MSG "use of %s denied for "
65365+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
65366+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
65367+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
65368+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
65369+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
65370+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
65371+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
65372+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
65373+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
65374+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
65375+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
65376+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
65377+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
65378+#define GR_VM86_MSG "denied use of vm86 by "
65379+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
65380+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
65381+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
65382+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
65383+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
65384+#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 "
65385diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
65386new file mode 100644
65387index 0000000..c5e5913
65388--- /dev/null
65389+++ b/include/linux/grsecurity.h
65390@@ -0,0 +1,257 @@
65391+#ifndef GR_SECURITY_H
65392+#define GR_SECURITY_H
65393+#include <linux/fs.h>
65394+#include <linux/fs_struct.h>
65395+#include <linux/binfmts.h>
65396+#include <linux/gracl.h>
65397+
65398+/* notify of brain-dead configs */
65399+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65400+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
65401+#endif
65402+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
65403+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
65404+#endif
65405+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
65406+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
65407+#endif
65408+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
65409+#error "CONFIG_PAX enabled, but no PaX options are enabled."
65410+#endif
65411+
65412+#include <linux/compat.h>
65413+
65414+struct user_arg_ptr {
65415+#ifdef CONFIG_COMPAT
65416+ bool is_compat;
65417+#endif
65418+ union {
65419+ const char __user *const __user *native;
65420+#ifdef CONFIG_COMPAT
65421+ const compat_uptr_t __user *compat;
65422+#endif
65423+ } ptr;
65424+};
65425+
65426+void gr_handle_brute_attach(unsigned long mm_flags);
65427+void gr_handle_brute_check(void);
65428+void gr_handle_kernel_exploit(void);
65429+int gr_process_user_ban(void);
65430+
65431+char gr_roletype_to_char(void);
65432+
65433+int gr_acl_enable_at_secure(void);
65434+
65435+int gr_check_user_change(int real, int effective, int fs);
65436+int gr_check_group_change(int real, int effective, int fs);
65437+
65438+void gr_del_task_from_ip_table(struct task_struct *p);
65439+
65440+int gr_pid_is_chrooted(struct task_struct *p);
65441+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
65442+int gr_handle_chroot_nice(void);
65443+int gr_handle_chroot_sysctl(const int op);
65444+int gr_handle_chroot_setpriority(struct task_struct *p,
65445+ const int niceval);
65446+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
65447+int gr_handle_chroot_chroot(const struct dentry *dentry,
65448+ const struct vfsmount *mnt);
65449+void gr_handle_chroot_chdir(struct path *path);
65450+int gr_handle_chroot_chmod(const struct dentry *dentry,
65451+ const struct vfsmount *mnt, const int mode);
65452+int gr_handle_chroot_mknod(const struct dentry *dentry,
65453+ const struct vfsmount *mnt, const int mode);
65454+int gr_handle_chroot_mount(const struct dentry *dentry,
65455+ const struct vfsmount *mnt,
65456+ const char *dev_name);
65457+int gr_handle_chroot_pivot(void);
65458+int gr_handle_chroot_unix(const pid_t pid);
65459+
65460+int gr_handle_rawio(const struct inode *inode);
65461+
65462+void gr_handle_ioperm(void);
65463+void gr_handle_iopl(void);
65464+
65465+umode_t gr_acl_umask(void);
65466+
65467+int gr_tpe_allow(const struct file *file);
65468+
65469+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
65470+void gr_clear_chroot_entries(struct task_struct *task);
65471+
65472+void gr_log_forkfail(const int retval);
65473+void gr_log_timechange(void);
65474+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
65475+void gr_log_chdir(const struct dentry *dentry,
65476+ const struct vfsmount *mnt);
65477+void gr_log_chroot_exec(const struct dentry *dentry,
65478+ const struct vfsmount *mnt);
65479+void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
65480+void gr_log_remount(const char *devname, const int retval);
65481+void gr_log_unmount(const char *devname, const int retval);
65482+void gr_log_mount(const char *from, const char *to, const int retval);
65483+void gr_log_textrel(struct vm_area_struct *vma);
65484+void gr_log_rwxmmap(struct file *file);
65485+void gr_log_rwxmprotect(struct file *file);
65486+
65487+int gr_handle_follow_link(const struct inode *parent,
65488+ const struct inode *inode,
65489+ const struct dentry *dentry,
65490+ const struct vfsmount *mnt);
65491+int gr_handle_fifo(const struct dentry *dentry,
65492+ const struct vfsmount *mnt,
65493+ const struct dentry *dir, const int flag,
65494+ const int acc_mode);
65495+int gr_handle_hardlink(const struct dentry *dentry,
65496+ const struct vfsmount *mnt,
65497+ struct inode *inode,
65498+ const int mode, const struct filename *to);
65499+
65500+int gr_is_capable(const int cap);
65501+int gr_is_capable_nolog(const int cap);
65502+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
65503+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
65504+
65505+void gr_copy_label(struct task_struct *tsk);
65506+void gr_handle_crash(struct task_struct *task, const int sig);
65507+int gr_handle_signal(const struct task_struct *p, const int sig);
65508+int gr_check_crash_uid(const uid_t uid);
65509+int gr_check_protected_task(const struct task_struct *task);
65510+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
65511+int gr_acl_handle_mmap(const struct file *file,
65512+ const unsigned long prot);
65513+int gr_acl_handle_mprotect(const struct file *file,
65514+ const unsigned long prot);
65515+int gr_check_hidden_task(const struct task_struct *tsk);
65516+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
65517+ const struct vfsmount *mnt);
65518+__u32 gr_acl_handle_utime(const struct dentry *dentry,
65519+ const struct vfsmount *mnt);
65520+__u32 gr_acl_handle_access(const struct dentry *dentry,
65521+ const struct vfsmount *mnt, const int fmode);
65522+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
65523+ const struct vfsmount *mnt, umode_t *mode);
65524+__u32 gr_acl_handle_chown(const struct dentry *dentry,
65525+ const struct vfsmount *mnt);
65526+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
65527+ const struct vfsmount *mnt);
65528+int gr_handle_ptrace(struct task_struct *task, const long request);
65529+int gr_handle_proc_ptrace(struct task_struct *task);
65530+__u32 gr_acl_handle_execve(const struct dentry *dentry,
65531+ const struct vfsmount *mnt);
65532+int gr_check_crash_exec(const struct file *filp);
65533+int gr_acl_is_enabled(void);
65534+void gr_set_kernel_label(struct task_struct *task);
65535+void gr_set_role_label(struct task_struct *task, const uid_t uid,
65536+ const gid_t gid);
65537+int gr_set_proc_label(const struct dentry *dentry,
65538+ const struct vfsmount *mnt,
65539+ const int unsafe_flags);
65540+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
65541+ const struct vfsmount *mnt);
65542+__u32 gr_acl_handle_open(const struct dentry *dentry,
65543+ const struct vfsmount *mnt, int acc_mode);
65544+__u32 gr_acl_handle_creat(const struct dentry *dentry,
65545+ const struct dentry *p_dentry,
65546+ const struct vfsmount *p_mnt,
65547+ int open_flags, int acc_mode, const int imode);
65548+void gr_handle_create(const struct dentry *dentry,
65549+ const struct vfsmount *mnt);
65550+void gr_handle_proc_create(const struct dentry *dentry,
65551+ const struct inode *inode);
65552+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
65553+ const struct dentry *parent_dentry,
65554+ const struct vfsmount *parent_mnt,
65555+ const int mode);
65556+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
65557+ const struct dentry *parent_dentry,
65558+ const struct vfsmount *parent_mnt);
65559+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
65560+ const struct vfsmount *mnt);
65561+void gr_handle_delete(const ino_t ino, const dev_t dev);
65562+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
65563+ const struct vfsmount *mnt);
65564+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
65565+ const struct dentry *parent_dentry,
65566+ const struct vfsmount *parent_mnt,
65567+ const struct filename *from);
65568+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
65569+ const struct dentry *parent_dentry,
65570+ const struct vfsmount *parent_mnt,
65571+ const struct dentry *old_dentry,
65572+ const struct vfsmount *old_mnt, const struct filename *to);
65573+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
65574+int gr_acl_handle_rename(struct dentry *new_dentry,
65575+ struct dentry *parent_dentry,
65576+ const struct vfsmount *parent_mnt,
65577+ struct dentry *old_dentry,
65578+ struct inode *old_parent_inode,
65579+ struct vfsmount *old_mnt, const struct filename *newname);
65580+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
65581+ struct dentry *old_dentry,
65582+ struct dentry *new_dentry,
65583+ struct vfsmount *mnt, const __u8 replace);
65584+__u32 gr_check_link(const struct dentry *new_dentry,
65585+ const struct dentry *parent_dentry,
65586+ const struct vfsmount *parent_mnt,
65587+ const struct dentry *old_dentry,
65588+ const struct vfsmount *old_mnt);
65589+int gr_acl_handle_filldir(const struct file *file, const char *name,
65590+ const unsigned int namelen, const ino_t ino);
65591+
65592+__u32 gr_acl_handle_unix(const struct dentry *dentry,
65593+ const struct vfsmount *mnt);
65594+void gr_acl_handle_exit(void);
65595+void gr_acl_handle_psacct(struct task_struct *task, const long code);
65596+int gr_acl_handle_procpidmem(const struct task_struct *task);
65597+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
65598+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
65599+void gr_audit_ptrace(struct task_struct *task);
65600+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
65601+void gr_put_exec_file(struct task_struct *task);
65602+
65603+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
65604+
65605+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
65606+extern void gr_learn_resource(const struct task_struct *task, const int res,
65607+ const unsigned long wanted, const int gt);
65608+#else
65609+static inline void gr_learn_resource(const struct task_struct *task, const int res,
65610+ const unsigned long wanted, const int gt)
65611+{
65612+}
65613+#endif
65614+
65615+#ifdef CONFIG_GRKERNSEC_RESLOG
65616+extern void gr_log_resource(const struct task_struct *task, const int res,
65617+ const unsigned long wanted, const int gt);
65618+#else
65619+static inline void gr_log_resource(const struct task_struct *task, const int res,
65620+ const unsigned long wanted, const int gt)
65621+{
65622+}
65623+#endif
65624+
65625+#ifdef CONFIG_GRKERNSEC
65626+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
65627+void gr_handle_vm86(void);
65628+void gr_handle_mem_readwrite(u64 from, u64 to);
65629+
65630+void gr_log_badprocpid(const char *entry);
65631+
65632+extern int grsec_enable_dmesg;
65633+extern int grsec_disable_privio;
65634+
65635+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
65636+extern int grsec_proc_gid;
65637+#endif
65638+
65639+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
65640+extern int grsec_enable_chroot_findtask;
65641+#endif
65642+#ifdef CONFIG_GRKERNSEC_SETXID
65643+extern int grsec_enable_setxid;
65644+#endif
65645+#endif
65646+
65647+#endif
65648diff --git a/include/linux/grsock.h b/include/linux/grsock.h
65649new file mode 100644
65650index 0000000..e7ffaaf
65651--- /dev/null
65652+++ b/include/linux/grsock.h
65653@@ -0,0 +1,19 @@
65654+#ifndef __GRSOCK_H
65655+#define __GRSOCK_H
65656+
65657+extern void gr_attach_curr_ip(const struct sock *sk);
65658+extern int gr_handle_sock_all(const int family, const int type,
65659+ const int protocol);
65660+extern int gr_handle_sock_server(const struct sockaddr *sck);
65661+extern int gr_handle_sock_server_other(const struct sock *sck);
65662+extern int gr_handle_sock_client(const struct sockaddr *sck);
65663+extern int gr_search_connect(struct socket * sock,
65664+ struct sockaddr_in * addr);
65665+extern int gr_search_bind(struct socket * sock,
65666+ struct sockaddr_in * addr);
65667+extern int gr_search_listen(struct socket * sock);
65668+extern int gr_search_accept(struct socket * sock);
65669+extern int gr_search_socket(const int domain, const int type,
65670+ const int protocol);
65671+
65672+#endif
65673diff --git a/include/linux/highmem.h b/include/linux/highmem.h
65674index ef788b5..ac41b7b 100644
65675--- a/include/linux/highmem.h
65676+++ b/include/linux/highmem.h
65677@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
65678 kunmap_atomic(kaddr);
65679 }
65680
65681+static inline void sanitize_highpage(struct page *page)
65682+{
65683+ void *kaddr;
65684+ unsigned long flags;
65685+
65686+ local_irq_save(flags);
65687+ kaddr = kmap_atomic(page);
65688+ clear_page(kaddr);
65689+ kunmap_atomic(kaddr);
65690+ local_irq_restore(flags);
65691+}
65692+
65693 static inline void zero_user_segments(struct page *page,
65694 unsigned start1, unsigned end1,
65695 unsigned start2, unsigned end2)
65696diff --git a/include/linux/i2c.h b/include/linux/i2c.h
65697index d0c4db7..61b3577 100644
65698--- a/include/linux/i2c.h
65699+++ b/include/linux/i2c.h
65700@@ -369,6 +369,7 @@ struct i2c_algorithm {
65701 /* To determine what the adapter supports */
65702 u32 (*functionality) (struct i2c_adapter *);
65703 };
65704+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
65705
65706 /*
65707 * i2c_adapter is the structure used to identify a physical i2c bus along
65708diff --git a/include/linux/i2o.h b/include/linux/i2o.h
65709index d23c3c2..eb63c81 100644
65710--- a/include/linux/i2o.h
65711+++ b/include/linux/i2o.h
65712@@ -565,7 +565,7 @@ struct i2o_controller {
65713 struct i2o_device *exec; /* Executive */
65714 #if BITS_PER_LONG == 64
65715 spinlock_t context_list_lock; /* lock for context_list */
65716- atomic_t context_list_counter; /* needed for unique contexts */
65717+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
65718 struct list_head context_list; /* list of context id's
65719 and pointers */
65720 #endif
65721diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
65722index aff7ad8..3942bbd 100644
65723--- a/include/linux/if_pppox.h
65724+++ b/include/linux/if_pppox.h
65725@@ -76,7 +76,7 @@ struct pppox_proto {
65726 int (*ioctl)(struct socket *sock, unsigned int cmd,
65727 unsigned long arg);
65728 struct module *owner;
65729-};
65730+} __do_const;
65731
65732 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
65733 extern void unregister_pppox_proto(int proto_num);
65734diff --git a/include/linux/init.h b/include/linux/init.h
65735index 10ed4f4..8e8490d 100644
65736--- a/include/linux/init.h
65737+++ b/include/linux/init.h
65738@@ -39,9 +39,36 @@
65739 * Also note, that this data cannot be "const".
65740 */
65741
65742+#ifdef MODULE
65743+#define add_init_latent_entropy
65744+#define add_devinit_latent_entropy
65745+#define add_cpuinit_latent_entropy
65746+#define add_meminit_latent_entropy
65747+#else
65748+#define add_init_latent_entropy __latent_entropy
65749+
65750+#ifdef CONFIG_HOTPLUG
65751+#define add_devinit_latent_entropy
65752+#else
65753+#define add_devinit_latent_entropy __latent_entropy
65754+#endif
65755+
65756+#ifdef CONFIG_HOTPLUG_CPU
65757+#define add_cpuinit_latent_entropy
65758+#else
65759+#define add_cpuinit_latent_entropy __latent_entropy
65760+#endif
65761+
65762+#ifdef CONFIG_MEMORY_HOTPLUG
65763+#define add_meminit_latent_entropy
65764+#else
65765+#define add_meminit_latent_entropy __latent_entropy
65766+#endif
65767+#endif
65768+
65769 /* These are for everybody (although not all archs will actually
65770 discard it in modules) */
65771-#define __init __section(.init.text) __cold notrace
65772+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
65773 #define __initdata __section(.init.data)
65774 #define __initconst __constsection(.init.rodata)
65775 #define __exitdata __section(.exit.data)
65776@@ -94,7 +121,7 @@
65777 #define __exit __section(.exit.text) __exitused __cold notrace
65778
65779 /* Used for HOTPLUG_CPU */
65780-#define __cpuinit __section(.cpuinit.text) __cold notrace
65781+#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
65782 #define __cpuinitdata __section(.cpuinit.data)
65783 #define __cpuinitconst __constsection(.cpuinit.rodata)
65784 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
65785@@ -102,7 +129,7 @@
65786 #define __cpuexitconst __constsection(.cpuexit.rodata)
65787
65788 /* Used for MEMORY_HOTPLUG */
65789-#define __meminit __section(.meminit.text) __cold notrace
65790+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
65791 #define __meminitdata __section(.meminit.data)
65792 #define __meminitconst __constsection(.meminit.rodata)
65793 #define __memexit __section(.memexit.text) __exitused __cold notrace
65794diff --git a/include/linux/init_task.h b/include/linux/init_task.h
65795index 6d087c5..401cab8 100644
65796--- a/include/linux/init_task.h
65797+++ b/include/linux/init_task.h
65798@@ -143,6 +143,12 @@ extern struct task_group root_task_group;
65799
65800 #define INIT_TASK_COMM "swapper"
65801
65802+#ifdef CONFIG_X86
65803+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
65804+#else
65805+#define INIT_TASK_THREAD_INFO
65806+#endif
65807+
65808 /*
65809 * INIT_TASK is used to set up the first task table, touch at
65810 * your own risk!. Base=0, limit=0x1fffff (=2MB)
65811@@ -182,6 +188,7 @@ extern struct task_group root_task_group;
65812 RCU_POINTER_INITIALIZER(cred, &init_cred), \
65813 .comm = INIT_TASK_COMM, \
65814 .thread = INIT_THREAD, \
65815+ INIT_TASK_THREAD_INFO \
65816 .fs = &init_fs, \
65817 .files = &init_files, \
65818 .signal = &init_signals, \
65819diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
65820index 5fa5afe..ac55b25 100644
65821--- a/include/linux/interrupt.h
65822+++ b/include/linux/interrupt.h
65823@@ -430,7 +430,7 @@ enum
65824 /* map softirq index to softirq name. update 'softirq_to_name' in
65825 * kernel/softirq.c when adding a new softirq.
65826 */
65827-extern char *softirq_to_name[NR_SOFTIRQS];
65828+extern const char * const softirq_to_name[NR_SOFTIRQS];
65829
65830 /* softirq mask and active fields moved to irq_cpustat_t in
65831 * asm/hardirq.h to get better cache usage. KAO
65832@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
65833
65834 struct softirq_action
65835 {
65836- void (*action)(struct softirq_action *);
65837-};
65838+ void (*action)(void);
65839+} __no_const;
65840
65841 asmlinkage void do_softirq(void);
65842 asmlinkage void __do_softirq(void);
65843-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
65844+extern void open_softirq(int nr, void (*action)(void));
65845 extern void softirq_init(void);
65846 extern void __raise_softirq_irqoff(unsigned int nr);
65847
65848diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
65849index 6883e19..06992b1 100644
65850--- a/include/linux/kallsyms.h
65851+++ b/include/linux/kallsyms.h
65852@@ -15,7 +15,8 @@
65853
65854 struct module;
65855
65856-#ifdef CONFIG_KALLSYMS
65857+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
65858+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65859 /* Lookup the address for a symbol. Returns 0 if not found. */
65860 unsigned long kallsyms_lookup_name(const char *name);
65861
65862@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
65863 /* Stupid that this does nothing, but I didn't create this mess. */
65864 #define __print_symbol(fmt, addr)
65865 #endif /*CONFIG_KALLSYMS*/
65866+#else /* when included by kallsyms.c, vsnprintf.c, or
65867+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
65868+extern void __print_symbol(const char *fmt, unsigned long address);
65869+extern int sprint_backtrace(char *buffer, unsigned long address);
65870+extern int sprint_symbol(char *buffer, unsigned long address);
65871+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
65872+const char *kallsyms_lookup(unsigned long addr,
65873+ unsigned long *symbolsize,
65874+ unsigned long *offset,
65875+ char **modname, char *namebuf);
65876+#endif
65877
65878 /* This macro allows us to keep printk typechecking */
65879 static __printf(1, 2)
65880diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
65881index 4dff0c6..1ca9b72 100644
65882--- a/include/linux/kgdb.h
65883+++ b/include/linux/kgdb.h
65884@@ -53,7 +53,7 @@ extern int kgdb_connected;
65885 extern int kgdb_io_module_registered;
65886
65887 extern atomic_t kgdb_setting_breakpoint;
65888-extern atomic_t kgdb_cpu_doing_single_step;
65889+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
65890
65891 extern struct task_struct *kgdb_usethread;
65892 extern struct task_struct *kgdb_contthread;
65893@@ -255,7 +255,7 @@ struct kgdb_arch {
65894 void (*correct_hw_break)(void);
65895
65896 void (*enable_nmi)(bool on);
65897-};
65898+} __do_const;
65899
65900 /**
65901 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
65902@@ -280,7 +280,7 @@ struct kgdb_io {
65903 void (*pre_exception) (void);
65904 void (*post_exception) (void);
65905 int is_console;
65906-};
65907+} __do_const;
65908
65909 extern struct kgdb_arch arch_kgdb_ops;
65910
65911diff --git a/include/linux/kmod.h b/include/linux/kmod.h
65912index 5398d58..5883a34 100644
65913--- a/include/linux/kmod.h
65914+++ b/include/linux/kmod.h
65915@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
65916 * usually useless though. */
65917 extern __printf(2, 3)
65918 int __request_module(bool wait, const char *name, ...);
65919+extern __printf(3, 4)
65920+int ___request_module(bool wait, char *param_name, const char *name, ...);
65921 #define request_module(mod...) __request_module(true, mod)
65922 #define request_module_nowait(mod...) __request_module(false, mod)
65923 #define try_then_request_module(x, mod...) \
65924diff --git a/include/linux/kobject.h b/include/linux/kobject.h
65925index 939b112..90b7f44 100644
65926--- a/include/linux/kobject.h
65927+++ b/include/linux/kobject.h
65928@@ -111,7 +111,7 @@ struct kobj_type {
65929 struct attribute **default_attrs;
65930 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
65931 const void *(*namespace)(struct kobject *kobj);
65932-};
65933+} __do_const;
65934
65935 struct kobj_uevent_env {
65936 char *envp[UEVENT_NUM_ENVP];
65937diff --git a/include/linux/kref.h b/include/linux/kref.h
65938index 4972e6e..de4d19b 100644
65939--- a/include/linux/kref.h
65940+++ b/include/linux/kref.h
65941@@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
65942 static inline int kref_sub(struct kref *kref, unsigned int count,
65943 void (*release)(struct kref *kref))
65944 {
65945- WARN_ON(release == NULL);
65946+ BUG_ON(release == NULL);
65947
65948 if (atomic_sub_and_test((int) count, &kref->refcount)) {
65949 release(kref);
65950diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
65951index 2c497ab..afe32f5 100644
65952--- a/include/linux/kvm_host.h
65953+++ b/include/linux/kvm_host.h
65954@@ -418,7 +418,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
65955 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
65956 void vcpu_put(struct kvm_vcpu *vcpu);
65957
65958-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
65959+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
65960 struct module *module);
65961 void kvm_exit(void);
65962
65963@@ -574,7 +574,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
65964 struct kvm_guest_debug *dbg);
65965 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
65966
65967-int kvm_arch_init(void *opaque);
65968+int kvm_arch_init(const void *opaque);
65969 void kvm_arch_exit(void);
65970
65971 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
65972diff --git a/include/linux/libata.h b/include/linux/libata.h
65973index 649e5f8..ead5194 100644
65974--- a/include/linux/libata.h
65975+++ b/include/linux/libata.h
65976@@ -915,7 +915,7 @@ struct ata_port_operations {
65977 * fields must be pointers.
65978 */
65979 const struct ata_port_operations *inherits;
65980-};
65981+} __do_const;
65982
65983 struct ata_port_info {
65984 unsigned long flags;
65985diff --git a/include/linux/list.h b/include/linux/list.h
65986index cc6d2aa..71febca 100644
65987--- a/include/linux/list.h
65988+++ b/include/linux/list.h
65989@@ -112,6 +112,9 @@ extern void __list_del_entry(struct list_head *entry);
65990 extern void list_del(struct list_head *entry);
65991 #endif
65992
65993+extern void pax_list_add_tail(struct list_head *new, struct list_head *head);
65994+extern void pax_list_del(struct list_head *entry);
65995+
65996 /**
65997 * list_replace - replace old entry by new one
65998 * @old : the element to be replaced
65999diff --git a/include/linux/mm.h b/include/linux/mm.h
66000index 66e2f7c..ea88001 100644
66001--- a/include/linux/mm.h
66002+++ b/include/linux/mm.h
66003@@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
66004 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
66005 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
66006 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
66007+
66008+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
66009+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
66010+#endif
66011+
66012 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
66013
66014 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
66015@@ -231,6 +236,7 @@ struct vm_operations_struct {
66016 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
66017 unsigned long size, pgoff_t pgoff);
66018 };
66019+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
66020
66021 struct mmu_gather;
66022 struct inode;
66023@@ -1068,34 +1074,6 @@ int set_page_dirty(struct page *page);
66024 int set_page_dirty_lock(struct page *page);
66025 int clear_page_dirty_for_io(struct page *page);
66026
66027-/* Is the vma a continuation of the stack vma above it? */
66028-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
66029-{
66030- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
66031-}
66032-
66033-static inline int stack_guard_page_start(struct vm_area_struct *vma,
66034- unsigned long addr)
66035-{
66036- return (vma->vm_flags & VM_GROWSDOWN) &&
66037- (vma->vm_start == addr) &&
66038- !vma_growsdown(vma->vm_prev, addr);
66039-}
66040-
66041-/* Is the vma a continuation of the stack vma below it? */
66042-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
66043-{
66044- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
66045-}
66046-
66047-static inline int stack_guard_page_end(struct vm_area_struct *vma,
66048- unsigned long addr)
66049-{
66050- return (vma->vm_flags & VM_GROWSUP) &&
66051- (vma->vm_end == addr) &&
66052- !vma_growsup(vma->vm_next, addr);
66053-}
66054-
66055 extern pid_t
66056 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
66057
66058@@ -1198,6 +1176,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
66059 }
66060 #endif
66061
66062+#ifdef CONFIG_MMU
66063+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
66064+#else
66065+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
66066+{
66067+ return __pgprot(0);
66068+}
66069+#endif
66070+
66071 int vma_wants_writenotify(struct vm_area_struct *vma);
66072
66073 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
66074@@ -1216,8 +1203,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
66075 {
66076 return 0;
66077 }
66078+
66079+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
66080+ unsigned long address)
66081+{
66082+ return 0;
66083+}
66084 #else
66085 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
66086+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
66087 #endif
66088
66089 #ifdef __PAGETABLE_PMD_FOLDED
66090@@ -1226,8 +1220,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
66091 {
66092 return 0;
66093 }
66094+
66095+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
66096+ unsigned long address)
66097+{
66098+ return 0;
66099+}
66100 #else
66101 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
66102+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
66103 #endif
66104
66105 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
66106@@ -1245,11 +1246,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
66107 NULL: pud_offset(pgd, address);
66108 }
66109
66110+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
66111+{
66112+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
66113+ NULL: pud_offset(pgd, address);
66114+}
66115+
66116 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
66117 {
66118 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
66119 NULL: pmd_offset(pud, address);
66120 }
66121+
66122+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
66123+{
66124+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
66125+ NULL: pmd_offset(pud, address);
66126+}
66127 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
66128
66129 #if USE_SPLIT_PTLOCKS
66130@@ -1479,6 +1492,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
66131 unsigned long, unsigned long,
66132 unsigned long, unsigned long);
66133 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
66134+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
66135
66136 /* These take the mm semaphore themselves */
66137 extern unsigned long vm_brk(unsigned long, unsigned long);
66138@@ -1573,6 +1587,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
66139 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
66140 struct vm_area_struct **pprev);
66141
66142+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
66143+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
66144+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
66145+
66146 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
66147 NULL if none. Assume start_addr < end_addr. */
66148 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
66149@@ -1601,15 +1619,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
66150 return vma;
66151 }
66152
66153-#ifdef CONFIG_MMU
66154-pgprot_t vm_get_page_prot(unsigned long vm_flags);
66155-#else
66156-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
66157-{
66158- return __pgprot(0);
66159-}
66160-#endif
66161-
66162 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
66163 unsigned long change_prot_numa(struct vm_area_struct *vma,
66164 unsigned long start, unsigned long end);
66165@@ -1721,7 +1730,7 @@ extern int unpoison_memory(unsigned long pfn);
66166 extern int sysctl_memory_failure_early_kill;
66167 extern int sysctl_memory_failure_recovery;
66168 extern void shake_page(struct page *p, int access);
66169-extern atomic_long_t mce_bad_pages;
66170+extern atomic_long_unchecked_t mce_bad_pages;
66171 extern int soft_offline_page(struct page *page, int flags);
66172
66173 extern void dump_page(struct page *page);
66174@@ -1752,5 +1761,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
66175 static inline bool page_is_guard(struct page *page) { return false; }
66176 #endif /* CONFIG_DEBUG_PAGEALLOC */
66177
66178+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
66179+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
66180+#else
66181+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
66182+#endif
66183+
66184 #endif /* __KERNEL__ */
66185 #endif /* _LINUX_MM_H */
66186diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
66187index f8f5162..6276a36 100644
66188--- a/include/linux/mm_types.h
66189+++ b/include/linux/mm_types.h
66190@@ -288,6 +288,8 @@ struct vm_area_struct {
66191 #ifdef CONFIG_NUMA
66192 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
66193 #endif
66194+
66195+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
66196 };
66197
66198 struct core_thread {
66199@@ -362,7 +364,7 @@ struct mm_struct {
66200 unsigned long def_flags;
66201 unsigned long nr_ptes; /* Page table pages */
66202 unsigned long start_code, end_code, start_data, end_data;
66203- unsigned long start_brk, brk, start_stack;
66204+ unsigned long brk_gap, start_brk, brk, start_stack;
66205 unsigned long arg_start, arg_end, env_start, env_end;
66206
66207 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
66208@@ -436,6 +438,24 @@ struct mm_struct {
66209 int first_nid;
66210 #endif
66211 struct uprobes_state uprobes_state;
66212+
66213+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
66214+ unsigned long pax_flags;
66215+#endif
66216+
66217+#ifdef CONFIG_PAX_DLRESOLVE
66218+ unsigned long call_dl_resolve;
66219+#endif
66220+
66221+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
66222+ unsigned long call_syscall;
66223+#endif
66224+
66225+#ifdef CONFIG_PAX_ASLR
66226+ unsigned long delta_mmap; /* randomized offset */
66227+ unsigned long delta_stack; /* randomized offset */
66228+#endif
66229+
66230 };
66231
66232 /* first nid will either be a valid NID or one of these values */
66233diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
66234index c5d5278..f0b68c8 100644
66235--- a/include/linux/mmiotrace.h
66236+++ b/include/linux/mmiotrace.h
66237@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
66238 /* Called from ioremap.c */
66239 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
66240 void __iomem *addr);
66241-extern void mmiotrace_iounmap(volatile void __iomem *addr);
66242+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
66243
66244 /* For anyone to insert markers. Remember trailing newline. */
66245 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
66246@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
66247 {
66248 }
66249
66250-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
66251+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
66252 {
66253 }
66254
66255diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
66256index 73b64a3..6562925 100644
66257--- a/include/linux/mmzone.h
66258+++ b/include/linux/mmzone.h
66259@@ -412,7 +412,7 @@ struct zone {
66260 unsigned long flags; /* zone flags, see below */
66261
66262 /* Zone statistics */
66263- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66264+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66265
66266 /*
66267 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
66268diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
66269index fed3def..7cc3f93 100644
66270--- a/include/linux/mod_devicetable.h
66271+++ b/include/linux/mod_devicetable.h
66272@@ -12,7 +12,7 @@
66273 typedef unsigned long kernel_ulong_t;
66274 #endif
66275
66276-#define PCI_ANY_ID (~0)
66277+#define PCI_ANY_ID ((__u16)~0)
66278
66279 struct pci_device_id {
66280 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
66281@@ -139,7 +139,7 @@ struct usb_device_id {
66282 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
66283 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
66284
66285-#define HID_ANY_ID (~0)
66286+#define HID_ANY_ID (~0U)
66287 #define HID_BUS_ANY 0xffff
66288 #define HID_GROUP_ANY 0x0000
66289
66290diff --git a/include/linux/module.h b/include/linux/module.h
66291index 1375ee3..d631af0 100644
66292--- a/include/linux/module.h
66293+++ b/include/linux/module.h
66294@@ -17,9 +17,11 @@
66295 #include <linux/moduleparam.h>
66296 #include <linux/tracepoint.h>
66297 #include <linux/export.h>
66298+#include <linux/fs.h>
66299
66300 #include <linux/percpu.h>
66301 #include <asm/module.h>
66302+#include <asm/pgtable.h>
66303
66304 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
66305 #define MODULE_SIG_STRING "~Module signature appended~\n"
66306@@ -281,19 +283,16 @@ struct module
66307 int (*init)(void);
66308
66309 /* If this is non-NULL, vfree after init() returns */
66310- void *module_init;
66311+ void *module_init_rx, *module_init_rw;
66312
66313 /* Here is the actual code + data, vfree'd on unload. */
66314- void *module_core;
66315+ void *module_core_rx, *module_core_rw;
66316
66317 /* Here are the sizes of the init and core sections */
66318- unsigned int init_size, core_size;
66319+ unsigned int init_size_rw, core_size_rw;
66320
66321 /* The size of the executable code in each section. */
66322- unsigned int init_text_size, core_text_size;
66323-
66324- /* Size of RO sections of the module (text+rodata) */
66325- unsigned int init_ro_size, core_ro_size;
66326+ unsigned int init_size_rx, core_size_rx;
66327
66328 /* Arch-specific module values */
66329 struct mod_arch_specific arch;
66330@@ -349,6 +348,10 @@ struct module
66331 #ifdef CONFIG_EVENT_TRACING
66332 struct ftrace_event_call **trace_events;
66333 unsigned int num_trace_events;
66334+ struct file_operations trace_id;
66335+ struct file_operations trace_enable;
66336+ struct file_operations trace_format;
66337+ struct file_operations trace_filter;
66338 #endif
66339 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
66340 unsigned int num_ftrace_callsites;
66341@@ -396,16 +399,46 @@ bool is_module_address(unsigned long addr);
66342 bool is_module_percpu_address(unsigned long addr);
66343 bool is_module_text_address(unsigned long addr);
66344
66345+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
66346+{
66347+
66348+#ifdef CONFIG_PAX_KERNEXEC
66349+ if (ktla_ktva(addr) >= (unsigned long)start &&
66350+ ktla_ktva(addr) < (unsigned long)start + size)
66351+ return 1;
66352+#endif
66353+
66354+ return ((void *)addr >= start && (void *)addr < start + size);
66355+}
66356+
66357+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
66358+{
66359+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
66360+}
66361+
66362+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
66363+{
66364+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
66365+}
66366+
66367+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
66368+{
66369+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
66370+}
66371+
66372+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
66373+{
66374+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
66375+}
66376+
66377 static inline int within_module_core(unsigned long addr, struct module *mod)
66378 {
66379- return (unsigned long)mod->module_core <= addr &&
66380- addr < (unsigned long)mod->module_core + mod->core_size;
66381+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
66382 }
66383
66384 static inline int within_module_init(unsigned long addr, struct module *mod)
66385 {
66386- return (unsigned long)mod->module_init <= addr &&
66387- addr < (unsigned long)mod->module_init + mod->init_size;
66388+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
66389 }
66390
66391 /* Search for module by name: must hold module_mutex. */
66392diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
66393index 560ca53..5ee8d73 100644
66394--- a/include/linux/moduleloader.h
66395+++ b/include/linux/moduleloader.h
66396@@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
66397
66398 /* Allocator used for allocating struct module, core sections and init
66399 sections. Returns NULL on failure. */
66400-void *module_alloc(unsigned long size);
66401+void *module_alloc(unsigned long size) __size_overflow(1);
66402+
66403+#ifdef CONFIG_PAX_KERNEXEC
66404+void *module_alloc_exec(unsigned long size) __size_overflow(1);
66405+#else
66406+#define module_alloc_exec(x) module_alloc(x)
66407+#endif
66408
66409 /* Free memory returned from module_alloc. */
66410 void module_free(struct module *mod, void *module_region);
66411
66412+#ifdef CONFIG_PAX_KERNEXEC
66413+void module_free_exec(struct module *mod, void *module_region);
66414+#else
66415+#define module_free_exec(x, y) module_free((x), (y))
66416+#endif
66417+
66418 /*
66419 * Apply the given relocation to the (simplified) ELF. Return -error
66420 * or 0.
66421@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
66422 unsigned int relsec,
66423 struct module *me)
66424 {
66425+#ifdef CONFIG_MODULES
66426 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
66427+#endif
66428 return -ENOEXEC;
66429 }
66430 #endif
66431@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
66432 unsigned int relsec,
66433 struct module *me)
66434 {
66435+#ifdef CONFIG_MODULES
66436 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
66437+#endif
66438 return -ENOEXEC;
66439 }
66440 #endif
66441diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
66442index 137b419..fe663ec 100644
66443--- a/include/linux/moduleparam.h
66444+++ b/include/linux/moduleparam.h
66445@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
66446 * @len is usually just sizeof(string).
66447 */
66448 #define module_param_string(name, string, len, perm) \
66449- static const struct kparam_string __param_string_##name \
66450+ static const struct kparam_string __param_string_##name __used \
66451 = { len, string }; \
66452 __module_param_call(MODULE_PARAM_PREFIX, name, \
66453 &param_ops_string, \
66454@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
66455 */
66456 #define module_param_array_named(name, array, type, nump, perm) \
66457 param_check_##type(name, &(array)[0]); \
66458- static const struct kparam_array __param_arr_##name \
66459+ static const struct kparam_array __param_arr_##name __used \
66460 = { .max = ARRAY_SIZE(array), .num = nump, \
66461 .ops = &param_ops_##type, \
66462 .elemsize = sizeof(array[0]), .elem = array }; \
66463diff --git a/include/linux/namei.h b/include/linux/namei.h
66464index 5a5ff57..5ae5070 100644
66465--- a/include/linux/namei.h
66466+++ b/include/linux/namei.h
66467@@ -19,7 +19,7 @@ struct nameidata {
66468 unsigned seq;
66469 int last_type;
66470 unsigned depth;
66471- char *saved_names[MAX_NESTED_LINKS + 1];
66472+ const char *saved_names[MAX_NESTED_LINKS + 1];
66473 };
66474
66475 /*
66476@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
66477
66478 extern void nd_jump_link(struct nameidata *nd, struct path *path);
66479
66480-static inline void nd_set_link(struct nameidata *nd, char *path)
66481+static inline void nd_set_link(struct nameidata *nd, const char *path)
66482 {
66483 nd->saved_names[nd->depth] = path;
66484 }
66485
66486-static inline char *nd_get_link(struct nameidata *nd)
66487+static inline const char *nd_get_link(const struct nameidata *nd)
66488 {
66489 return nd->saved_names[nd->depth];
66490 }
66491diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
66492index 9ef07d0..130a5d9 100644
66493--- a/include/linux/netdevice.h
66494+++ b/include/linux/netdevice.h
66495@@ -1012,6 +1012,7 @@ struct net_device_ops {
66496 u32 pid, u32 seq,
66497 struct net_device *dev);
66498 };
66499+typedef struct net_device_ops __no_const net_device_ops_no_const;
66500
66501 /*
66502 * The DEVICE structure.
66503@@ -1078,7 +1079,7 @@ struct net_device {
66504 int iflink;
66505
66506 struct net_device_stats stats;
66507- atomic_long_t rx_dropped; /* dropped packets by core network
66508+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
66509 * Do not use this in drivers.
66510 */
66511
66512diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
66513index 7958e84..ed74d7a 100644
66514--- a/include/linux/netfilter/ipset/ip_set.h
66515+++ b/include/linux/netfilter/ipset/ip_set.h
66516@@ -98,7 +98,7 @@ struct ip_set_type_variant {
66517 /* Return true if "b" set is the same as "a"
66518 * according to the create set parameters */
66519 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
66520-};
66521+} __do_const;
66522
66523 /* The core set type structure */
66524 struct ip_set_type {
66525diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
66526index 4966dde..7d8ce06 100644
66527--- a/include/linux/netfilter/nfnetlink.h
66528+++ b/include/linux/netfilter/nfnetlink.h
66529@@ -16,7 +16,7 @@ struct nfnl_callback {
66530 const struct nlattr * const cda[]);
66531 const struct nla_policy *policy; /* netlink attribute policy */
66532 const u_int16_t attr_count; /* number of nlattr's */
66533-};
66534+} __do_const;
66535
66536 struct nfnetlink_subsystem {
66537 const char *name;
66538diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
66539new file mode 100644
66540index 0000000..33f4af8
66541--- /dev/null
66542+++ b/include/linux/netfilter/xt_gradm.h
66543@@ -0,0 +1,9 @@
66544+#ifndef _LINUX_NETFILTER_XT_GRADM_H
66545+#define _LINUX_NETFILTER_XT_GRADM_H 1
66546+
66547+struct xt_gradm_mtinfo {
66548+ __u16 flags;
66549+ __u16 invflags;
66550+};
66551+
66552+#endif
66553diff --git a/include/linux/notifier.h b/include/linux/notifier.h
66554index d65746e..62e72c2 100644
66555--- a/include/linux/notifier.h
66556+++ b/include/linux/notifier.h
66557@@ -51,7 +51,8 @@ struct notifier_block {
66558 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
66559 struct notifier_block __rcu *next;
66560 int priority;
66561-};
66562+} __do_const;
66563+typedef struct notifier_block __no_const notifier_block_no_const;
66564
66565 struct atomic_notifier_head {
66566 spinlock_t lock;
66567diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
66568index a4c5624..79d6d88 100644
66569--- a/include/linux/oprofile.h
66570+++ b/include/linux/oprofile.h
66571@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
66572 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
66573 char const * name, ulong * val);
66574
66575-/** Create a file for read-only access to an atomic_t. */
66576+/** Create a file for read-only access to an atomic_unchecked_t. */
66577 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
66578- char const * name, atomic_t * val);
66579+ char const * name, atomic_unchecked_t * val);
66580
66581 /** create a directory */
66582 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
66583diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
66584index 6bfb2faa..e5bc5e5 100644
66585--- a/include/linux/perf_event.h
66586+++ b/include/linux/perf_event.h
66587@@ -328,8 +328,8 @@ struct perf_event {
66588
66589 enum perf_event_active_state state;
66590 unsigned int attach_state;
66591- local64_t count;
66592- atomic64_t child_count;
66593+ local64_t count; /* PaX: fix it one day */
66594+ atomic64_unchecked_t child_count;
66595
66596 /*
66597 * These are the total time in nanoseconds that the event
66598@@ -380,8 +380,8 @@ struct perf_event {
66599 * These accumulate total time (in nanoseconds) that children
66600 * events have been enabled and running, respectively.
66601 */
66602- atomic64_t child_total_time_enabled;
66603- atomic64_t child_total_time_running;
66604+ atomic64_unchecked_t child_total_time_enabled;
66605+ atomic64_unchecked_t child_total_time_running;
66606
66607 /*
66608 * Protect attach/detach and child_list:
66609@@ -801,7 +801,7 @@ static inline void perf_event_task_tick(void) { }
66610 */
66611 #define perf_cpu_notifier(fn) \
66612 do { \
66613- static struct notifier_block fn##_nb __cpuinitdata = \
66614+ static struct notifier_block fn##_nb = \
66615 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
66616 unsigned long cpu = smp_processor_id(); \
66617 unsigned long flags; \
66618diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
66619index ad1a427..6419649 100644
66620--- a/include/linux/pipe_fs_i.h
66621+++ b/include/linux/pipe_fs_i.h
66622@@ -45,9 +45,9 @@ struct pipe_buffer {
66623 struct pipe_inode_info {
66624 wait_queue_head_t wait;
66625 unsigned int nrbufs, curbuf, buffers;
66626- unsigned int readers;
66627- unsigned int writers;
66628- unsigned int waiting_writers;
66629+ atomic_t readers;
66630+ atomic_t writers;
66631+ atomic_t waiting_writers;
66632 unsigned int r_counter;
66633 unsigned int w_counter;
66634 struct page *tmp_page;
66635diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
66636index 5f28cae..3d23723 100644
66637--- a/include/linux/platform_data/usb-ehci-s5p.h
66638+++ b/include/linux/platform_data/usb-ehci-s5p.h
66639@@ -14,7 +14,7 @@
66640 struct s5p_ehci_platdata {
66641 int (*phy_init)(struct platform_device *pdev, int type);
66642 int (*phy_exit)(struct platform_device *pdev, int type);
66643-};
66644+} __no_const;
66645
66646 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
66647
66648diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
66649index f271860..6b3bec5 100644
66650--- a/include/linux/pm_runtime.h
66651+++ b/include/linux/pm_runtime.h
66652@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
66653
66654 static inline void pm_runtime_mark_last_busy(struct device *dev)
66655 {
66656- ACCESS_ONCE(dev->power.last_busy) = jiffies;
66657+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
66658 }
66659
66660 #else /* !CONFIG_PM_RUNTIME */
66661diff --git a/include/linux/poison.h b/include/linux/poison.h
66662index 2110a81..13a11bb 100644
66663--- a/include/linux/poison.h
66664+++ b/include/linux/poison.h
66665@@ -19,8 +19,8 @@
66666 * under normal circumstances, used to verify that nobody uses
66667 * non-initialized list entries.
66668 */
66669-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
66670-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
66671+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
66672+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
66673
66674 /********** include/linux/timer.h **********/
66675 /*
66676diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
66677index c0f44c2..1572583 100644
66678--- a/include/linux/power/smartreflex.h
66679+++ b/include/linux/power/smartreflex.h
66680@@ -238,7 +238,7 @@ struct omap_sr_class_data {
66681 int (*notify)(struct omap_sr *sr, u32 status);
66682 u8 notify_flags;
66683 u8 class_type;
66684-};
66685+} __do_const;
66686
66687 /**
66688 * struct omap_sr_nvalue_table - Smartreflex n-target value info
66689diff --git a/include/linux/printk.h b/include/linux/printk.h
66690index 9afc01e..92c32e8 100644
66691--- a/include/linux/printk.h
66692+++ b/include/linux/printk.h
66693@@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
66694 extern int printk_needs_cpu(int cpu);
66695 extern void printk_tick(void);
66696
66697+extern int kptr_restrict;
66698+
66699 #ifdef CONFIG_PRINTK
66700 asmlinkage __printf(5, 0)
66701 int vprintk_emit(int facility, int level,
66702@@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
66703
66704 extern int printk_delay_msec;
66705 extern int dmesg_restrict;
66706-extern int kptr_restrict;
66707
66708 void log_buf_kexec_setup(void);
66709 void __init setup_log_buf(int early);
66710diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
66711index 32676b3..8f7a182 100644
66712--- a/include/linux/proc_fs.h
66713+++ b/include/linux/proc_fs.h
66714@@ -159,6 +159,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
66715 return proc_create_data(name, mode, parent, proc_fops, NULL);
66716 }
66717
66718+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
66719+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
66720+{
66721+#ifdef CONFIG_GRKERNSEC_PROC_USER
66722+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
66723+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66724+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
66725+#else
66726+ return proc_create_data(name, mode, parent, proc_fops, NULL);
66727+#endif
66728+}
66729+
66730 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
66731 umode_t mode, struct proc_dir_entry *base,
66732 read_proc_t *read_proc, void * data)
66733diff --git a/include/linux/random.h b/include/linux/random.h
66734index d984608..d6f0042 100644
66735--- a/include/linux/random.h
66736+++ b/include/linux/random.h
66737@@ -39,6 +39,11 @@ void prandom_seed(u32 seed);
66738 u32 prandom_u32_state(struct rnd_state *);
66739 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
66740
66741+static inline unsigned long pax_get_random_long(void)
66742+{
66743+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
66744+}
66745+
66746 /*
66747 * Handle minimum values for seeds
66748 */
66749diff --git a/include/linux/reboot.h b/include/linux/reboot.h
66750index 23b3630..e1bc12b 100644
66751--- a/include/linux/reboot.h
66752+++ b/include/linux/reboot.h
66753@@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
66754 * Architecture-specific implementations of sys_reboot commands.
66755 */
66756
66757-extern void machine_restart(char *cmd);
66758-extern void machine_halt(void);
66759-extern void machine_power_off(void);
66760+extern void machine_restart(char *cmd) __noreturn;
66761+extern void machine_halt(void) __noreturn;
66762+extern void machine_power_off(void) __noreturn;
66763
66764 extern void machine_shutdown(void);
66765 struct pt_regs;
66766@@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
66767 */
66768
66769 extern void kernel_restart_prepare(char *cmd);
66770-extern void kernel_restart(char *cmd);
66771-extern void kernel_halt(void);
66772-extern void kernel_power_off(void);
66773+extern void kernel_restart(char *cmd) __noreturn;
66774+extern void kernel_halt(void) __noreturn;
66775+extern void kernel_power_off(void) __noreturn;
66776
66777 extern int C_A_D; /* for sysctl */
66778 void ctrl_alt_del(void);
66779@@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
66780 * Emergency restart, callable from an interrupt handler.
66781 */
66782
66783-extern void emergency_restart(void);
66784+extern void emergency_restart(void) __noreturn;
66785 #include <asm/emergency-restart.h>
66786
66787 #endif /* _LINUX_REBOOT_H */
66788diff --git a/include/linux/regset.h b/include/linux/regset.h
66789index 8e0c9fe..ac4d221 100644
66790--- a/include/linux/regset.h
66791+++ b/include/linux/regset.h
66792@@ -161,7 +161,8 @@ struct user_regset {
66793 unsigned int align;
66794 unsigned int bias;
66795 unsigned int core_note_type;
66796-};
66797+} __do_const;
66798+typedef struct user_regset __no_const user_regset_no_const;
66799
66800 /**
66801 * struct user_regset_view - available regsets
66802diff --git a/include/linux/relay.h b/include/linux/relay.h
66803index 91cacc3..b55ff74 100644
66804--- a/include/linux/relay.h
66805+++ b/include/linux/relay.h
66806@@ -160,7 +160,7 @@ struct rchan_callbacks
66807 * The callback should return 0 if successful, negative if not.
66808 */
66809 int (*remove_buf_file)(struct dentry *dentry);
66810-};
66811+} __no_const;
66812
66813 /*
66814 * CONFIG_RELAY kernel API, kernel/relay.c
66815diff --git a/include/linux/rio.h b/include/linux/rio.h
66816index a3e7842..d973ca6 100644
66817--- a/include/linux/rio.h
66818+++ b/include/linux/rio.h
66819@@ -339,7 +339,7 @@ struct rio_ops {
66820 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
66821 u64 rstart, u32 size, u32 flags);
66822 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
66823-};
66824+} __no_const;
66825
66826 #define RIO_RESOURCE_MEM 0x00000100
66827 #define RIO_RESOURCE_DOORBELL 0x00000200
66828diff --git a/include/linux/rmap.h b/include/linux/rmap.h
66829index c20635c..2f5def4 100644
66830--- a/include/linux/rmap.h
66831+++ b/include/linux/rmap.h
66832@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
66833 void anon_vma_init(void); /* create anon_vma_cachep */
66834 int anon_vma_prepare(struct vm_area_struct *);
66835 void unlink_anon_vmas(struct vm_area_struct *);
66836-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
66837-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
66838+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
66839+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
66840
66841 static inline void anon_vma_merge(struct vm_area_struct *vma,
66842 struct vm_area_struct *next)
66843diff --git a/include/linux/sched.h b/include/linux/sched.h
66844index d211247..d64a165 100644
66845--- a/include/linux/sched.h
66846+++ b/include/linux/sched.h
66847@@ -61,6 +61,7 @@ struct bio_list;
66848 struct fs_struct;
66849 struct perf_event_context;
66850 struct blk_plug;
66851+struct linux_binprm;
66852
66853 /*
66854 * List of flags we want to share for kernel threads,
66855@@ -354,10 +355,23 @@ struct user_namespace;
66856 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
66857
66858 extern int sysctl_max_map_count;
66859+extern unsigned long sysctl_heap_stack_gap;
66860
66861 #include <linux/aio.h>
66862
66863 #ifdef CONFIG_MMU
66864+
66865+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
66866+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
66867+#else
66868+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
66869+{
66870+ return 0;
66871+}
66872+#endif
66873+
66874+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
66875+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
66876 extern void arch_pick_mmap_layout(struct mm_struct *mm);
66877 extern unsigned long
66878 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
66879@@ -639,6 +653,17 @@ struct signal_struct {
66880 #ifdef CONFIG_TASKSTATS
66881 struct taskstats *stats;
66882 #endif
66883+
66884+#ifdef CONFIG_GRKERNSEC
66885+ u32 curr_ip;
66886+ u32 saved_ip;
66887+ u32 gr_saddr;
66888+ u32 gr_daddr;
66889+ u16 gr_sport;
66890+ u16 gr_dport;
66891+ u8 used_accept:1;
66892+#endif
66893+
66894 #ifdef CONFIG_AUDIT
66895 unsigned audit_tty;
66896 struct tty_audit_buf *tty_audit_buf;
66897@@ -717,6 +742,11 @@ struct user_struct {
66898 struct key *session_keyring; /* UID's default session keyring */
66899 #endif
66900
66901+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
66902+ unsigned int banned;
66903+ unsigned long ban_expires;
66904+#endif
66905+
66906 /* Hash table maintenance information */
66907 struct hlist_node uidhash_node;
66908 kuid_t uid;
66909@@ -1360,8 +1390,8 @@ struct task_struct {
66910 struct list_head thread_group;
66911
66912 struct completion *vfork_done; /* for vfork() */
66913- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
66914- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
66915+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
66916+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
66917
66918 cputime_t utime, stime, utimescaled, stimescaled;
66919 cputime_t gtime;
66920@@ -1377,11 +1407,6 @@ struct task_struct {
66921 struct task_cputime cputime_expires;
66922 struct list_head cpu_timers[3];
66923
66924-/* process credentials */
66925- const struct cred __rcu *real_cred; /* objective and real subjective task
66926- * credentials (COW) */
66927- const struct cred __rcu *cred; /* effective (overridable) subjective task
66928- * credentials (COW) */
66929 char comm[TASK_COMM_LEN]; /* executable name excluding path
66930 - access with [gs]et_task_comm (which lock
66931 it with task_lock())
66932@@ -1398,6 +1423,10 @@ struct task_struct {
66933 #endif
66934 /* CPU-specific state of this task */
66935 struct thread_struct thread;
66936+/* thread_info moved to task_struct */
66937+#ifdef CONFIG_X86
66938+ struct thread_info tinfo;
66939+#endif
66940 /* filesystem information */
66941 struct fs_struct *fs;
66942 /* open file information */
66943@@ -1471,6 +1500,10 @@ struct task_struct {
66944 gfp_t lockdep_reclaim_gfp;
66945 #endif
66946
66947+/* process credentials */
66948+ const struct cred __rcu *real_cred; /* objective and real subjective task
66949+ * credentials (COW) */
66950+
66951 /* journalling filesystem info */
66952 void *journal_info;
66953
66954@@ -1509,6 +1542,10 @@ struct task_struct {
66955 /* cg_list protected by css_set_lock and tsk->alloc_lock */
66956 struct list_head cg_list;
66957 #endif
66958+
66959+ const struct cred __rcu *cred; /* effective (overridable) subjective task
66960+ * credentials (COW) */
66961+
66962 #ifdef CONFIG_FUTEX
66963 struct robust_list_head __user *robust_list;
66964 #ifdef CONFIG_COMPAT
66965@@ -1605,8 +1642,74 @@ struct task_struct {
66966 #ifdef CONFIG_UPROBES
66967 struct uprobe_task *utask;
66968 #endif
66969+
66970+#ifdef CONFIG_GRKERNSEC
66971+ /* grsecurity */
66972+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66973+ u64 exec_id;
66974+#endif
66975+#ifdef CONFIG_GRKERNSEC_SETXID
66976+ const struct cred *delayed_cred;
66977+#endif
66978+ struct dentry *gr_chroot_dentry;
66979+ struct acl_subject_label *acl;
66980+ struct acl_role_label *role;
66981+ struct file *exec_file;
66982+ unsigned long brute_expires;
66983+ u16 acl_role_id;
66984+ /* is this the task that authenticated to the special role */
66985+ u8 acl_sp_role;
66986+ u8 is_writable;
66987+ u8 brute;
66988+ u8 gr_is_chrooted;
66989+#endif
66990+
66991 };
66992
66993+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
66994+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
66995+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
66996+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
66997+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
66998+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
66999+
67000+#ifdef CONFIG_PAX_SOFTMODE
67001+extern int pax_softmode;
67002+#endif
67003+
67004+extern int pax_check_flags(unsigned long *);
67005+
67006+/* if tsk != current then task_lock must be held on it */
67007+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
67008+static inline unsigned long pax_get_flags(struct task_struct *tsk)
67009+{
67010+ if (likely(tsk->mm))
67011+ return tsk->mm->pax_flags;
67012+ else
67013+ return 0UL;
67014+}
67015+
67016+/* if tsk != current then task_lock must be held on it */
67017+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
67018+{
67019+ if (likely(tsk->mm)) {
67020+ tsk->mm->pax_flags = flags;
67021+ return 0;
67022+ }
67023+ return -EINVAL;
67024+}
67025+#endif
67026+
67027+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
67028+extern void pax_set_initial_flags(struct linux_binprm *bprm);
67029+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
67030+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
67031+#endif
67032+
67033+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
67034+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
67035+extern void pax_report_refcount_overflow(struct pt_regs *regs);
67036+
67037 /* Future-safe accessor for struct task_struct's cpus_allowed. */
67038 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
67039
67040@@ -2155,7 +2258,9 @@ void yield(void);
67041 extern struct exec_domain default_exec_domain;
67042
67043 union thread_union {
67044+#ifndef CONFIG_X86
67045 struct thread_info thread_info;
67046+#endif
67047 unsigned long stack[THREAD_SIZE/sizeof(long)];
67048 };
67049
67050@@ -2188,6 +2293,7 @@ extern struct pid_namespace init_pid_ns;
67051 */
67052
67053 extern struct task_struct *find_task_by_vpid(pid_t nr);
67054+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
67055 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
67056 struct pid_namespace *ns);
67057
67058@@ -2344,7 +2450,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
67059 extern void exit_itimers(struct signal_struct *);
67060 extern void flush_itimer_signals(void);
67061
67062-extern void do_group_exit(int);
67063+extern __noreturn void do_group_exit(int);
67064
67065 extern int allow_signal(int);
67066 extern int disallow_signal(int);
67067@@ -2545,9 +2651,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
67068
67069 #endif
67070
67071-static inline int object_is_on_stack(void *obj)
67072+static inline int object_starts_on_stack(void *obj)
67073 {
67074- void *stack = task_stack_page(current);
67075+ const void *stack = task_stack_page(current);
67076
67077 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
67078 }
67079diff --git a/include/linux/security.h b/include/linux/security.h
67080index eee7478..290f7ba 100644
67081--- a/include/linux/security.h
67082+++ b/include/linux/security.h
67083@@ -26,6 +26,7 @@
67084 #include <linux/capability.h>
67085 #include <linux/slab.h>
67086 #include <linux/err.h>
67087+#include <linux/grsecurity.h>
67088
67089 struct linux_binprm;
67090 struct cred;
67091diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
67092index 68a04a3..866e6a1 100644
67093--- a/include/linux/seq_file.h
67094+++ b/include/linux/seq_file.h
67095@@ -26,6 +26,9 @@ struct seq_file {
67096 struct mutex lock;
67097 const struct seq_operations *op;
67098 int poll_event;
67099+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67100+ u64 exec_id;
67101+#endif
67102 #ifdef CONFIG_USER_NS
67103 struct user_namespace *user_ns;
67104 #endif
67105@@ -38,6 +41,7 @@ struct seq_operations {
67106 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
67107 int (*show) (struct seq_file *m, void *v);
67108 };
67109+typedef struct seq_operations __no_const seq_operations_no_const;
67110
67111 #define SEQ_SKIP 1
67112
67113diff --git a/include/linux/shm.h b/include/linux/shm.h
67114index 429c199..4d42e38 100644
67115--- a/include/linux/shm.h
67116+++ b/include/linux/shm.h
67117@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
67118
67119 /* The task created the shm object. NULL if the task is dead. */
67120 struct task_struct *shm_creator;
67121+#ifdef CONFIG_GRKERNSEC
67122+ time_t shm_createtime;
67123+ pid_t shm_lapid;
67124+#endif
67125 };
67126
67127 /* shm_mode upper byte flags */
67128diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
67129index 320e976..fd52553 100644
67130--- a/include/linux/skbuff.h
67131+++ b/include/linux/skbuff.h
67132@@ -590,7 +590,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
67133 extern struct sk_buff *__alloc_skb(unsigned int size,
67134 gfp_t priority, int flags, int node);
67135 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
67136-static inline struct sk_buff *alloc_skb(unsigned int size,
67137+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
67138 gfp_t priority)
67139 {
67140 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
67141@@ -700,7 +700,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
67142 */
67143 static inline int skb_queue_empty(const struct sk_buff_head *list)
67144 {
67145- return list->next == (struct sk_buff *)list;
67146+ return list->next == (const struct sk_buff *)list;
67147 }
67148
67149 /**
67150@@ -713,7 +713,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
67151 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
67152 const struct sk_buff *skb)
67153 {
67154- return skb->next == (struct sk_buff *)list;
67155+ return skb->next == (const struct sk_buff *)list;
67156 }
67157
67158 /**
67159@@ -726,7 +726,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
67160 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
67161 const struct sk_buff *skb)
67162 {
67163- return skb->prev == (struct sk_buff *)list;
67164+ return skb->prev == (const struct sk_buff *)list;
67165 }
67166
67167 /**
67168@@ -1722,7 +1722,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
67169 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
67170 */
67171 #ifndef NET_SKB_PAD
67172-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
67173+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
67174 #endif
67175
67176 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
67177@@ -2300,7 +2300,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
67178 int noblock, int *err);
67179 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
67180 struct poll_table_struct *wait);
67181-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
67182+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
67183 int offset, struct iovec *to,
67184 int size);
67185 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
67186diff --git a/include/linux/slab.h b/include/linux/slab.h
67187index 5d168d7..720bff3 100644
67188--- a/include/linux/slab.h
67189+++ b/include/linux/slab.h
67190@@ -12,13 +12,20 @@
67191 #include <linux/gfp.h>
67192 #include <linux/types.h>
67193 #include <linux/workqueue.h>
67194-
67195+#include <linux/err.h>
67196
67197 /*
67198 * Flags to pass to kmem_cache_create().
67199 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
67200 */
67201 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
67202+
67203+#ifdef CONFIG_PAX_USERCOPY_SLABS
67204+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
67205+#else
67206+#define SLAB_USERCOPY 0x00000000UL
67207+#endif
67208+
67209 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
67210 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
67211 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
67212@@ -89,10 +96,13 @@
67213 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
67214 * Both make kfree a no-op.
67215 */
67216-#define ZERO_SIZE_PTR ((void *)16)
67217+#define ZERO_SIZE_PTR \
67218+({ \
67219+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
67220+ (void *)(-MAX_ERRNO-1L); \
67221+})
67222
67223-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
67224- (unsigned long)ZERO_SIZE_PTR)
67225+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
67226
67227 /*
67228 * Common fields provided in kmem_cache by all slab allocators
67229@@ -112,7 +122,7 @@ struct kmem_cache {
67230 unsigned int align; /* Alignment as calculated */
67231 unsigned long flags; /* Active flags on the slab */
67232 const char *name; /* Slab name for sysfs */
67233- int refcount; /* Use counter */
67234+ atomic_t refcount; /* Use counter */
67235 void (*ctor)(void *); /* Called on object slot creation */
67236 struct list_head list; /* List of all slab caches on the system */
67237 };
67238@@ -232,6 +242,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
67239 void kfree(const void *);
67240 void kzfree(const void *);
67241 size_t ksize(const void *);
67242+const char *check_heap_object(const void *ptr, unsigned long n);
67243+bool is_usercopy_object(const void *ptr);
67244
67245 /*
67246 * Allocator specific definitions. These are mainly used to establish optimized
67247@@ -311,6 +323,7 @@ size_t ksize(const void *);
67248 * for general use, and so are not documented here. For a full list of
67249 * potential flags, always refer to linux/gfp.h.
67250 */
67251+
67252 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
67253 {
67254 if (size != 0 && n > SIZE_MAX / size)
67255@@ -370,7 +383,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
67256 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
67257 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
67258 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
67259-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
67260+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
67261 #define kmalloc_track_caller(size, flags) \
67262 __kmalloc_track_caller(size, flags, _RET_IP_)
67263 #else
67264@@ -390,7 +403,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
67265 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
67266 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
67267 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
67268-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
67269+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
67270 #define kmalloc_node_track_caller(size, flags, node) \
67271 __kmalloc_node_track_caller(size, flags, node, \
67272 _RET_IP_)
67273diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
67274index 8bb6e0e..8eb0dbe 100644
67275--- a/include/linux/slab_def.h
67276+++ b/include/linux/slab_def.h
67277@@ -52,7 +52,7 @@ struct kmem_cache {
67278 /* 4) cache creation/removal */
67279 const char *name;
67280 struct list_head list;
67281- int refcount;
67282+ atomic_t refcount;
67283 int object_size;
67284 int align;
67285
67286@@ -68,10 +68,10 @@ struct kmem_cache {
67287 unsigned long node_allocs;
67288 unsigned long node_frees;
67289 unsigned long node_overflow;
67290- atomic_t allochit;
67291- atomic_t allocmiss;
67292- atomic_t freehit;
67293- atomic_t freemiss;
67294+ atomic_unchecked_t allochit;
67295+ atomic_unchecked_t allocmiss;
67296+ atomic_unchecked_t freehit;
67297+ atomic_unchecked_t freemiss;
67298
67299 /*
67300 * If debugging is enabled, then the allocator can add additional
67301@@ -111,11 +111,16 @@ struct cache_sizes {
67302 #ifdef CONFIG_ZONE_DMA
67303 struct kmem_cache *cs_dmacachep;
67304 #endif
67305+
67306+#ifdef CONFIG_PAX_USERCOPY_SLABS
67307+ struct kmem_cache *cs_usercopycachep;
67308+#endif
67309+
67310 };
67311 extern struct cache_sizes malloc_sizes[];
67312
67313 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
67314-void *__kmalloc(size_t size, gfp_t flags);
67315+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
67316
67317 #ifdef CONFIG_TRACING
67318 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
67319@@ -152,6 +157,13 @@ found:
67320 cachep = malloc_sizes[i].cs_dmacachep;
67321 else
67322 #endif
67323+
67324+#ifdef CONFIG_PAX_USERCOPY_SLABS
67325+ if (flags & GFP_USERCOPY)
67326+ cachep = malloc_sizes[i].cs_usercopycachep;
67327+ else
67328+#endif
67329+
67330 cachep = malloc_sizes[i].cs_cachep;
67331
67332 ret = kmem_cache_alloc_trace(cachep, flags, size);
67333@@ -162,7 +174,7 @@ found:
67334 }
67335
67336 #ifdef CONFIG_NUMA
67337-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
67338+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
67339 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
67340
67341 #ifdef CONFIG_TRACING
67342@@ -205,6 +217,13 @@ found:
67343 cachep = malloc_sizes[i].cs_dmacachep;
67344 else
67345 #endif
67346+
67347+#ifdef CONFIG_PAX_USERCOPY_SLABS
67348+ if (flags & GFP_USERCOPY)
67349+ cachep = malloc_sizes[i].cs_usercopycachep;
67350+ else
67351+#endif
67352+
67353 cachep = malloc_sizes[i].cs_cachep;
67354
67355 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
67356diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
67357index f28e14a..7831211 100644
67358--- a/include/linux/slob_def.h
67359+++ b/include/linux/slob_def.h
67360@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
67361 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
67362 }
67363
67364-void *__kmalloc_node(size_t size, gfp_t flags, int node);
67365+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
67366
67367 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
67368 {
67369@@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
67370 return __kmalloc_node(size, flags, NUMA_NO_NODE);
67371 }
67372
67373-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
67374+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
67375 {
67376 return kmalloc(size, flags);
67377 }
67378diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
67379index 9db4825..ed42fb5 100644
67380--- a/include/linux/slub_def.h
67381+++ b/include/linux/slub_def.h
67382@@ -91,7 +91,7 @@ struct kmem_cache {
67383 struct kmem_cache_order_objects max;
67384 struct kmem_cache_order_objects min;
67385 gfp_t allocflags; /* gfp flags to use on each alloc */
67386- int refcount; /* Refcount for slab cache destroy */
67387+ atomic_t refcount; /* Refcount for slab cache destroy */
67388 void (*ctor)(void *);
67389 int inuse; /* Offset to metadata */
67390 int align; /* Alignment */
67391@@ -156,7 +156,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
67392 * Sorry that the following has to be that ugly but some versions of GCC
67393 * have trouble with constant propagation and loops.
67394 */
67395-static __always_inline int kmalloc_index(size_t size)
67396+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
67397 {
67398 if (!size)
67399 return 0;
67400@@ -221,7 +221,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
67401 }
67402
67403 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
67404-void *__kmalloc(size_t size, gfp_t flags);
67405+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
67406
67407 static __always_inline void *
67408 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
67409@@ -265,7 +265,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
67410 }
67411 #endif
67412
67413-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
67414+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
67415 {
67416 unsigned int order = get_order(size);
67417 return kmalloc_order_trace(size, flags, order);
67418@@ -290,7 +290,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
67419 }
67420
67421 #ifdef CONFIG_NUMA
67422-void *__kmalloc_node(size_t size, gfp_t flags, int node);
67423+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
67424 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
67425
67426 #ifdef CONFIG_TRACING
67427diff --git a/include/linux/sonet.h b/include/linux/sonet.h
67428index 680f9a3..f13aeb0 100644
67429--- a/include/linux/sonet.h
67430+++ b/include/linux/sonet.h
67431@@ -7,7 +7,7 @@
67432 #include <uapi/linux/sonet.h>
67433
67434 struct k_sonet_stats {
67435-#define __HANDLE_ITEM(i) atomic_t i
67436+#define __HANDLE_ITEM(i) atomic_unchecked_t i
67437 __SONET_ITEMS
67438 #undef __HANDLE_ITEM
67439 };
67440diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
67441index 34206b8..f019e06 100644
67442--- a/include/linux/sunrpc/clnt.h
67443+++ b/include/linux/sunrpc/clnt.h
67444@@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
67445 {
67446 switch (sap->sa_family) {
67447 case AF_INET:
67448- return ntohs(((struct sockaddr_in *)sap)->sin_port);
67449+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
67450 case AF_INET6:
67451- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
67452+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
67453 }
67454 return 0;
67455 }
67456@@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
67457 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
67458 const struct sockaddr *src)
67459 {
67460- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
67461+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
67462 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
67463
67464 dsin->sin_family = ssin->sin_family;
67465@@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
67466 if (sa->sa_family != AF_INET6)
67467 return 0;
67468
67469- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
67470+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
67471 }
67472
67473 #endif /* __KERNEL__ */
67474diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
67475index 0b8e3e6..33e0a01 100644
67476--- a/include/linux/sunrpc/svc_rdma.h
67477+++ b/include/linux/sunrpc/svc_rdma.h
67478@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
67479 extern unsigned int svcrdma_max_requests;
67480 extern unsigned int svcrdma_max_req_size;
67481
67482-extern atomic_t rdma_stat_recv;
67483-extern atomic_t rdma_stat_read;
67484-extern atomic_t rdma_stat_write;
67485-extern atomic_t rdma_stat_sq_starve;
67486-extern atomic_t rdma_stat_rq_starve;
67487-extern atomic_t rdma_stat_rq_poll;
67488-extern atomic_t rdma_stat_rq_prod;
67489-extern atomic_t rdma_stat_sq_poll;
67490-extern atomic_t rdma_stat_sq_prod;
67491+extern atomic_unchecked_t rdma_stat_recv;
67492+extern atomic_unchecked_t rdma_stat_read;
67493+extern atomic_unchecked_t rdma_stat_write;
67494+extern atomic_unchecked_t rdma_stat_sq_starve;
67495+extern atomic_unchecked_t rdma_stat_rq_starve;
67496+extern atomic_unchecked_t rdma_stat_rq_poll;
67497+extern atomic_unchecked_t rdma_stat_rq_prod;
67498+extern atomic_unchecked_t rdma_stat_sq_poll;
67499+extern atomic_unchecked_t rdma_stat_sq_prod;
67500
67501 #define RPCRDMA_VERSION 1
67502
67503diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
67504index 14a8ff2..21fe4c7 100644
67505--- a/include/linux/sysctl.h
67506+++ b/include/linux/sysctl.h
67507@@ -41,6 +41,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
67508
67509 extern int proc_dostring(struct ctl_table *, int,
67510 void __user *, size_t *, loff_t *);
67511+extern int proc_dostring_modpriv(struct ctl_table *, int,
67512+ void __user *, size_t *, loff_t *);
67513 extern int proc_dointvec(struct ctl_table *, int,
67514 void __user *, size_t *, loff_t *);
67515 extern int proc_dointvec_minmax(struct ctl_table *, int,
67516diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
67517index 7faf933..c1ad32c 100644
67518--- a/include/linux/sysrq.h
67519+++ b/include/linux/sysrq.h
67520@@ -15,6 +15,7 @@
67521 #define _LINUX_SYSRQ_H
67522
67523 #include <linux/errno.h>
67524+#include <linux/compiler.h>
67525 #include <linux/types.h>
67526
67527 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
67528@@ -36,7 +37,7 @@ struct sysrq_key_op {
67529 char *help_msg;
67530 char *action_msg;
67531 int enable_mask;
67532-};
67533+} __do_const;
67534
67535 #ifdef CONFIG_MAGIC_SYSRQ
67536
67537diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
67538index e7e0473..39b7b52 100644
67539--- a/include/linux/thread_info.h
67540+++ b/include/linux/thread_info.h
67541@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
67542 #error "no set_restore_sigmask() provided and default one won't work"
67543 #endif
67544
67545+extern void __check_object_size(const void *ptr, unsigned long n, bool to);
67546+static inline void check_object_size(const void *ptr, unsigned long n, bool to)
67547+{
67548+#ifndef CONFIG_PAX_USERCOPY_DEBUG
67549+ if (!__builtin_constant_p(n))
67550+#endif
67551+ __check_object_size(ptr, n, to);
67552+}
67553+
67554 #endif /* __KERNEL__ */
67555
67556 #endif /* _LINUX_THREAD_INFO_H */
67557diff --git a/include/linux/tty.h b/include/linux/tty.h
67558index 8db1b56..c16a040 100644
67559--- a/include/linux/tty.h
67560+++ b/include/linux/tty.h
67561@@ -194,7 +194,7 @@ struct tty_port {
67562 const struct tty_port_operations *ops; /* Port operations */
67563 spinlock_t lock; /* Lock protecting tty field */
67564 int blocked_open; /* Waiting to open */
67565- int count; /* Usage count */
67566+ atomic_t count; /* Usage count */
67567 wait_queue_head_t open_wait; /* Open waiters */
67568 wait_queue_head_t close_wait; /* Close waiters */
67569 wait_queue_head_t delta_msr_wait; /* Modem status change */
67570@@ -490,7 +490,7 @@ extern int tty_port_open(struct tty_port *port,
67571 struct tty_struct *tty, struct file *filp);
67572 static inline int tty_port_users(struct tty_port *port)
67573 {
67574- return port->count + port->blocked_open;
67575+ return atomic_read(&port->count) + port->blocked_open;
67576 }
67577
67578 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
67579diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
67580index dd976cf..e272742 100644
67581--- a/include/linux/tty_driver.h
67582+++ b/include/linux/tty_driver.h
67583@@ -284,7 +284,7 @@ struct tty_operations {
67584 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
67585 #endif
67586 const struct file_operations *proc_fops;
67587-};
67588+} __do_const;
67589
67590 struct tty_driver {
67591 int magic; /* magic number for this structure */
67592diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
67593index fb79dd8d..07d4773 100644
67594--- a/include/linux/tty_ldisc.h
67595+++ b/include/linux/tty_ldisc.h
67596@@ -149,7 +149,7 @@ struct tty_ldisc_ops {
67597
67598 struct module *owner;
67599
67600- int refcount;
67601+ atomic_t refcount;
67602 };
67603
67604 struct tty_ldisc {
67605diff --git a/include/linux/types.h b/include/linux/types.h
67606index 4d118ba..c3ee9bf 100644
67607--- a/include/linux/types.h
67608+++ b/include/linux/types.h
67609@@ -176,10 +176,26 @@ typedef struct {
67610 int counter;
67611 } atomic_t;
67612
67613+#ifdef CONFIG_PAX_REFCOUNT
67614+typedef struct {
67615+ int counter;
67616+} atomic_unchecked_t;
67617+#else
67618+typedef atomic_t atomic_unchecked_t;
67619+#endif
67620+
67621 #ifdef CONFIG_64BIT
67622 typedef struct {
67623 long counter;
67624 } atomic64_t;
67625+
67626+#ifdef CONFIG_PAX_REFCOUNT
67627+typedef struct {
67628+ long counter;
67629+} atomic64_unchecked_t;
67630+#else
67631+typedef atomic64_t atomic64_unchecked_t;
67632+#endif
67633 #endif
67634
67635 struct list_head {
67636diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
67637index 5ca0951..ab496a5 100644
67638--- a/include/linux/uaccess.h
67639+++ b/include/linux/uaccess.h
67640@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
67641 long ret; \
67642 mm_segment_t old_fs = get_fs(); \
67643 \
67644- set_fs(KERNEL_DS); \
67645 pagefault_disable(); \
67646- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
67647- pagefault_enable(); \
67648+ set_fs(KERNEL_DS); \
67649+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
67650 set_fs(old_fs); \
67651+ pagefault_enable(); \
67652 ret; \
67653 })
67654
67655diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
67656index 99c1b4d..bb94261 100644
67657--- a/include/linux/unaligned/access_ok.h
67658+++ b/include/linux/unaligned/access_ok.h
67659@@ -6,32 +6,32 @@
67660
67661 static inline u16 get_unaligned_le16(const void *p)
67662 {
67663- return le16_to_cpup((__le16 *)p);
67664+ return le16_to_cpup((const __le16 *)p);
67665 }
67666
67667 static inline u32 get_unaligned_le32(const void *p)
67668 {
67669- return le32_to_cpup((__le32 *)p);
67670+ return le32_to_cpup((const __le32 *)p);
67671 }
67672
67673 static inline u64 get_unaligned_le64(const void *p)
67674 {
67675- return le64_to_cpup((__le64 *)p);
67676+ return le64_to_cpup((const __le64 *)p);
67677 }
67678
67679 static inline u16 get_unaligned_be16(const void *p)
67680 {
67681- return be16_to_cpup((__be16 *)p);
67682+ return be16_to_cpup((const __be16 *)p);
67683 }
67684
67685 static inline u32 get_unaligned_be32(const void *p)
67686 {
67687- return be32_to_cpup((__be32 *)p);
67688+ return be32_to_cpup((const __be32 *)p);
67689 }
67690
67691 static inline u64 get_unaligned_be64(const void *p)
67692 {
67693- return be64_to_cpup((__be64 *)p);
67694+ return be64_to_cpup((const __be64 *)p);
67695 }
67696
67697 static inline void put_unaligned_le16(u16 val, void *p)
67698diff --git a/include/linux/usb.h b/include/linux/usb.h
67699index 4d22d0f..ac43c2f 100644
67700--- a/include/linux/usb.h
67701+++ b/include/linux/usb.h
67702@@ -554,7 +554,7 @@ struct usb_device {
67703 int maxchild;
67704
67705 u32 quirks;
67706- atomic_t urbnum;
67707+ atomic_unchecked_t urbnum;
67708
67709 unsigned long active_duration;
67710
67711diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
67712index c5d36c6..108f4f9 100644
67713--- a/include/linux/usb/renesas_usbhs.h
67714+++ b/include/linux/usb/renesas_usbhs.h
67715@@ -39,7 +39,7 @@ enum {
67716 */
67717 struct renesas_usbhs_driver_callback {
67718 int (*notify_hotplug)(struct platform_device *pdev);
67719-};
67720+} __no_const;
67721
67722 /*
67723 * callback functions for platform
67724diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
67725index b9bd2e6..4ce0093 100644
67726--- a/include/linux/user_namespace.h
67727+++ b/include/linux/user_namespace.h
67728@@ -21,7 +21,7 @@ struct user_namespace {
67729 struct uid_gid_map uid_map;
67730 struct uid_gid_map gid_map;
67731 struct uid_gid_map projid_map;
67732- struct kref kref;
67733+ atomic_t count;
67734 struct user_namespace *parent;
67735 kuid_t owner;
67736 kgid_t group;
67737@@ -35,18 +35,18 @@ extern struct user_namespace init_user_ns;
67738 static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
67739 {
67740 if (ns)
67741- kref_get(&ns->kref);
67742+ atomic_inc(&ns->count);
67743 return ns;
67744 }
67745
67746 extern int create_user_ns(struct cred *new);
67747 extern int unshare_userns(unsigned long unshare_flags, struct cred **new_cred);
67748-extern void free_user_ns(struct kref *kref);
67749+extern void free_user_ns(struct user_namespace *ns);
67750
67751 static inline void put_user_ns(struct user_namespace *ns)
67752 {
67753- if (ns)
67754- kref_put(&ns->kref, free_user_ns);
67755+ if (ns && atomic_dec_and_test(&ns->count))
67756+ free_user_ns(ns);
67757 }
67758
67759 struct seq_operations;
67760diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
67761index 6f8fbcf..8259001 100644
67762--- a/include/linux/vermagic.h
67763+++ b/include/linux/vermagic.h
67764@@ -25,9 +25,35 @@
67765 #define MODULE_ARCH_VERMAGIC ""
67766 #endif
67767
67768+#ifdef CONFIG_PAX_REFCOUNT
67769+#define MODULE_PAX_REFCOUNT "REFCOUNT "
67770+#else
67771+#define MODULE_PAX_REFCOUNT ""
67772+#endif
67773+
67774+#ifdef CONSTIFY_PLUGIN
67775+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
67776+#else
67777+#define MODULE_CONSTIFY_PLUGIN ""
67778+#endif
67779+
67780+#ifdef STACKLEAK_PLUGIN
67781+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
67782+#else
67783+#define MODULE_STACKLEAK_PLUGIN ""
67784+#endif
67785+
67786+#ifdef CONFIG_GRKERNSEC
67787+#define MODULE_GRSEC "GRSEC "
67788+#else
67789+#define MODULE_GRSEC ""
67790+#endif
67791+
67792 #define VERMAGIC_STRING \
67793 UTS_RELEASE " " \
67794 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
67795 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
67796- MODULE_ARCH_VERMAGIC
67797+ MODULE_ARCH_VERMAGIC \
67798+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
67799+ MODULE_GRSEC
67800
67801diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
67802index 6071e91..ca6a489 100644
67803--- a/include/linux/vmalloc.h
67804+++ b/include/linux/vmalloc.h
67805@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
67806 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
67807 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
67808 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
67809+
67810+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
67811+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
67812+#endif
67813+
67814 /* bits [20..32] reserved for arch specific ioremap internals */
67815
67816 /*
67817@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
67818 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
67819 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
67820 unsigned long start, unsigned long end, gfp_t gfp_mask,
67821- pgprot_t prot, int node, const void *caller);
67822+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
67823 extern void vfree(const void *addr);
67824
67825 extern void *vmap(struct page **pages, unsigned int count,
67826@@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
67827 extern void free_vm_area(struct vm_struct *area);
67828
67829 /* for /dev/kmem */
67830-extern long vread(char *buf, char *addr, unsigned long count);
67831-extern long vwrite(char *buf, char *addr, unsigned long count);
67832+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
67833+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
67834
67835 /*
67836 * Internals. Dont't use..
67837diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
67838index a13291f..af51fa3 100644
67839--- a/include/linux/vmstat.h
67840+++ b/include/linux/vmstat.h
67841@@ -95,18 +95,18 @@ static inline void vm_events_fold_cpu(int cpu)
67842 /*
67843 * Zone based page accounting with per cpu differentials.
67844 */
67845-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
67846+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
67847
67848 static inline void zone_page_state_add(long x, struct zone *zone,
67849 enum zone_stat_item item)
67850 {
67851- atomic_long_add(x, &zone->vm_stat[item]);
67852- atomic_long_add(x, &vm_stat[item]);
67853+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
67854+ atomic_long_add_unchecked(x, &vm_stat[item]);
67855 }
67856
67857 static inline unsigned long global_page_state(enum zone_stat_item item)
67858 {
67859- long x = atomic_long_read(&vm_stat[item]);
67860+ long x = atomic_long_read_unchecked(&vm_stat[item]);
67861 #ifdef CONFIG_SMP
67862 if (x < 0)
67863 x = 0;
67864@@ -117,7 +117,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
67865 static inline unsigned long zone_page_state(struct zone *zone,
67866 enum zone_stat_item item)
67867 {
67868- long x = atomic_long_read(&zone->vm_stat[item]);
67869+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
67870 #ifdef CONFIG_SMP
67871 if (x < 0)
67872 x = 0;
67873@@ -134,7 +134,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
67874 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
67875 enum zone_stat_item item)
67876 {
67877- long x = atomic_long_read(&zone->vm_stat[item]);
67878+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
67879
67880 #ifdef CONFIG_SMP
67881 int cpu;
67882@@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
67883
67884 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
67885 {
67886- atomic_long_inc(&zone->vm_stat[item]);
67887- atomic_long_inc(&vm_stat[item]);
67888+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
67889+ atomic_long_inc_unchecked(&vm_stat[item]);
67890 }
67891
67892 static inline void __inc_zone_page_state(struct page *page,
67893@@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
67894
67895 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
67896 {
67897- atomic_long_dec(&zone->vm_stat[item]);
67898- atomic_long_dec(&vm_stat[item]);
67899+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
67900+ atomic_long_dec_unchecked(&vm_stat[item]);
67901 }
67902
67903 static inline void __dec_zone_page_state(struct page *page,
67904diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
67905index 95d1c91..6798cca 100644
67906--- a/include/media/v4l2-dev.h
67907+++ b/include/media/v4l2-dev.h
67908@@ -76,7 +76,7 @@ struct v4l2_file_operations {
67909 int (*mmap) (struct file *, struct vm_area_struct *);
67910 int (*open) (struct file *);
67911 int (*release) (struct file *);
67912-};
67913+} __do_const;
67914
67915 /*
67916 * Newer version of video_device, handled by videodev2.c
67917diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
67918index 4118ad1..cb7e25f 100644
67919--- a/include/media/v4l2-ioctl.h
67920+++ b/include/media/v4l2-ioctl.h
67921@@ -284,7 +284,6 @@ struct v4l2_ioctl_ops {
67922 bool valid_prio, int cmd, void *arg);
67923 };
67924
67925-
67926 /* v4l debugging and diagnostics */
67927
67928 /* Debug bitmask flags to be used on V4L2 */
67929diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
67930index 9e5425b..8136ffc 100644
67931--- a/include/net/caif/cfctrl.h
67932+++ b/include/net/caif/cfctrl.h
67933@@ -52,7 +52,7 @@ struct cfctrl_rsp {
67934 void (*radioset_rsp)(void);
67935 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
67936 struct cflayer *client_layer);
67937-};
67938+} __no_const;
67939
67940 /* Link Setup Parameters for CAIF-Links. */
67941 struct cfctrl_link_param {
67942@@ -101,8 +101,8 @@ struct cfctrl_request_info {
67943 struct cfctrl {
67944 struct cfsrvl serv;
67945 struct cfctrl_rsp res;
67946- atomic_t req_seq_no;
67947- atomic_t rsp_seq_no;
67948+ atomic_unchecked_t req_seq_no;
67949+ atomic_unchecked_t rsp_seq_no;
67950 struct list_head list;
67951 /* Protects from simultaneous access to first_req list */
67952 spinlock_t info_list_lock;
67953diff --git a/include/net/flow.h b/include/net/flow.h
67954index 628e11b..4c475df 100644
67955--- a/include/net/flow.h
67956+++ b/include/net/flow.h
67957@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
67958
67959 extern void flow_cache_flush(void);
67960 extern void flow_cache_flush_deferred(void);
67961-extern atomic_t flow_cache_genid;
67962+extern atomic_unchecked_t flow_cache_genid;
67963
67964 #endif
67965diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
67966index e5062c9..48a9a4b 100644
67967--- a/include/net/gro_cells.h
67968+++ b/include/net/gro_cells.h
67969@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
67970 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
67971
67972 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
67973- atomic_long_inc(&dev->rx_dropped);
67974+ atomic_long_inc_unchecked(&dev->rx_dropped);
67975 kfree_skb(skb);
67976 return;
67977 }
67978@@ -73,8 +73,8 @@ static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *de
67979 int i;
67980
67981 gcells->gro_cells_mask = roundup_pow_of_two(netif_get_num_default_rss_queues()) - 1;
67982- gcells->cells = kcalloc(sizeof(struct gro_cell),
67983- gcells->gro_cells_mask + 1,
67984+ gcells->cells = kcalloc(gcells->gro_cells_mask + 1,
67985+ sizeof(struct gro_cell),
67986 GFP_KERNEL);
67987 if (!gcells->cells)
67988 return -ENOMEM;
67989diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
67990index 1832927..ce39aea 100644
67991--- a/include/net/inet_connection_sock.h
67992+++ b/include/net/inet_connection_sock.h
67993@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
67994 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
67995 int (*bind_conflict)(const struct sock *sk,
67996 const struct inet_bind_bucket *tb, bool relax);
67997-};
67998+} __do_const;
67999
68000 /** inet_connection_sock - INET connection oriented sock
68001 *
68002diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
68003index 53f464d..ba76aaa 100644
68004--- a/include/net/inetpeer.h
68005+++ b/include/net/inetpeer.h
68006@@ -47,8 +47,8 @@ struct inet_peer {
68007 */
68008 union {
68009 struct {
68010- atomic_t rid; /* Frag reception counter */
68011- atomic_t ip_id_count; /* IP ID for the next packet */
68012+ atomic_unchecked_t rid; /* Frag reception counter */
68013+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
68014 };
68015 struct rcu_head rcu;
68016 struct inet_peer *gc_next;
68017@@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
68018 more++;
68019 inet_peer_refcheck(p);
68020 do {
68021- old = atomic_read(&p->ip_id_count);
68022+ old = atomic_read_unchecked(&p->ip_id_count);
68023 new = old + more;
68024 if (!new)
68025 new = 1;
68026- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
68027+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
68028 return new;
68029 }
68030
68031diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
68032index 9497be1..5a4fafe 100644
68033--- a/include/net/ip_fib.h
68034+++ b/include/net/ip_fib.h
68035@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
68036
68037 #define FIB_RES_SADDR(net, res) \
68038 ((FIB_RES_NH(res).nh_saddr_genid == \
68039- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
68040+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
68041 FIB_RES_NH(res).nh_saddr : \
68042 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
68043 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
68044diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
68045index 68c69d5..2ee192b 100644
68046--- a/include/net/ip_vs.h
68047+++ b/include/net/ip_vs.h
68048@@ -599,7 +599,7 @@ struct ip_vs_conn {
68049 struct ip_vs_conn *control; /* Master control connection */
68050 atomic_t n_control; /* Number of controlled ones */
68051 struct ip_vs_dest *dest; /* real server */
68052- atomic_t in_pkts; /* incoming packet counter */
68053+ atomic_unchecked_t in_pkts; /* incoming packet counter */
68054
68055 /* packet transmitter for different forwarding methods. If it
68056 mangles the packet, it must return NF_DROP or better NF_STOLEN,
68057@@ -737,7 +737,7 @@ struct ip_vs_dest {
68058 __be16 port; /* port number of the server */
68059 union nf_inet_addr addr; /* IP address of the server */
68060 volatile unsigned int flags; /* dest status flags */
68061- atomic_t conn_flags; /* flags to copy to conn */
68062+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
68063 atomic_t weight; /* server weight */
68064
68065 atomic_t refcnt; /* reference counter */
68066diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
68067index 80ffde3..968b0f4 100644
68068--- a/include/net/irda/ircomm_tty.h
68069+++ b/include/net/irda/ircomm_tty.h
68070@@ -35,6 +35,7 @@
68071 #include <linux/termios.h>
68072 #include <linux/timer.h>
68073 #include <linux/tty.h> /* struct tty_struct */
68074+#include <asm/local.h>
68075
68076 #include <net/irda/irias_object.h>
68077 #include <net/irda/ircomm_core.h>
68078diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
68079index cc7c197..9f2da2a 100644
68080--- a/include/net/iucv/af_iucv.h
68081+++ b/include/net/iucv/af_iucv.h
68082@@ -141,7 +141,7 @@ struct iucv_sock {
68083 struct iucv_sock_list {
68084 struct hlist_head head;
68085 rwlock_t lock;
68086- atomic_t autobind_name;
68087+ atomic_unchecked_t autobind_name;
68088 };
68089
68090 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
68091diff --git a/include/net/neighbour.h b/include/net/neighbour.h
68092index 0dab173..1b76af0 100644
68093--- a/include/net/neighbour.h
68094+++ b/include/net/neighbour.h
68095@@ -123,7 +123,7 @@ struct neigh_ops {
68096 void (*error_report)(struct neighbour *, struct sk_buff *);
68097 int (*output)(struct neighbour *, struct sk_buff *);
68098 int (*connected_output)(struct neighbour *, struct sk_buff *);
68099-};
68100+} __do_const;
68101
68102 struct pneigh_entry {
68103 struct pneigh_entry *next;
68104diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
68105index de644bc..666aed3 100644
68106--- a/include/net/net_namespace.h
68107+++ b/include/net/net_namespace.h
68108@@ -115,7 +115,7 @@ struct net {
68109 #endif
68110 struct netns_ipvs *ipvs;
68111 struct sock *diag_nlsk;
68112- atomic_t rt_genid;
68113+ atomic_unchecked_t rt_genid;
68114 };
68115
68116 /*
68117@@ -330,12 +330,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
68118
68119 static inline int rt_genid(struct net *net)
68120 {
68121- return atomic_read(&net->rt_genid);
68122+ return atomic_read_unchecked(&net->rt_genid);
68123 }
68124
68125 static inline void rt_genid_bump(struct net *net)
68126 {
68127- atomic_inc(&net->rt_genid);
68128+ atomic_inc_unchecked(&net->rt_genid);
68129 }
68130
68131 #endif /* __NET_NET_NAMESPACE_H */
68132diff --git a/include/net/netdma.h b/include/net/netdma.h
68133index 8ba8ce2..99b7fff 100644
68134--- a/include/net/netdma.h
68135+++ b/include/net/netdma.h
68136@@ -24,7 +24,7 @@
68137 #include <linux/dmaengine.h>
68138 #include <linux/skbuff.h>
68139
68140-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
68141+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
68142 struct sk_buff *skb, int offset, struct iovec *to,
68143 size_t len, struct dma_pinned_list *pinned_list);
68144
68145diff --git a/include/net/netlink.h b/include/net/netlink.h
68146index 9690b0f..87aded7 100644
68147--- a/include/net/netlink.h
68148+++ b/include/net/netlink.h
68149@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
68150 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
68151 {
68152 if (mark)
68153- skb_trim(skb, (unsigned char *) mark - skb->data);
68154+ skb_trim(skb, (const unsigned char *) mark - skb->data);
68155 }
68156
68157 /**
68158diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
68159index 2ae2b83..dbdc85e 100644
68160--- a/include/net/netns/ipv4.h
68161+++ b/include/net/netns/ipv4.h
68162@@ -64,7 +64,7 @@ struct netns_ipv4 {
68163 kgid_t sysctl_ping_group_range[2];
68164 long sysctl_tcp_mem[3];
68165
68166- atomic_t dev_addr_genid;
68167+ atomic_unchecked_t dev_addr_genid;
68168
68169 #ifdef CONFIG_IP_MROUTE
68170 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
68171diff --git a/include/net/protocol.h b/include/net/protocol.h
68172index 047c047..b9dad15 100644
68173--- a/include/net/protocol.h
68174+++ b/include/net/protocol.h
68175@@ -44,7 +44,7 @@ struct net_protocol {
68176 void (*err_handler)(struct sk_buff *skb, u32 info);
68177 unsigned int no_policy:1,
68178 netns_ok:1;
68179-};
68180+} __do_const;
68181
68182 #if IS_ENABLED(CONFIG_IPV6)
68183 struct inet6_protocol {
68184@@ -57,7 +57,7 @@ struct inet6_protocol {
68185 u8 type, u8 code, int offset,
68186 __be32 info);
68187 unsigned int flags; /* INET6_PROTO_xxx */
68188-};
68189+} __do_const;
68190
68191 #define INET6_PROTO_NOPOLICY 0x1
68192 #define INET6_PROTO_FINAL 0x2
68193diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
68194index 7fdf298..197e9f7 100644
68195--- a/include/net/sctp/sctp.h
68196+++ b/include/net/sctp/sctp.h
68197@@ -330,9 +330,9 @@ do { \
68198
68199 #else /* SCTP_DEBUG */
68200
68201-#define SCTP_DEBUG_PRINTK(whatever...)
68202-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
68203-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
68204+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
68205+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
68206+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
68207 #define SCTP_ENABLE_DEBUG
68208 #define SCTP_DISABLE_DEBUG
68209 #define SCTP_ASSERT(expr, str, func)
68210diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
68211index fdeb85a..0c554d5 100644
68212--- a/include/net/sctp/structs.h
68213+++ b/include/net/sctp/structs.h
68214@@ -497,7 +497,7 @@ struct sctp_af {
68215 int sockaddr_len;
68216 sa_family_t sa_family;
68217 struct list_head list;
68218-};
68219+} __do_const;
68220
68221 struct sctp_af *sctp_get_af_specific(sa_family_t);
68222 int sctp_register_af(struct sctp_af *);
68223@@ -517,7 +517,7 @@ struct sctp_pf {
68224 struct sctp_association *asoc);
68225 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
68226 struct sctp_af *af;
68227-};
68228+} __do_const;
68229
68230
68231 /* Structure to track chunk fragments that have been acked, but peer
68232diff --git a/include/net/sock.h b/include/net/sock.h
68233index 25afaa0..8bb0070 100644
68234--- a/include/net/sock.h
68235+++ b/include/net/sock.h
68236@@ -322,7 +322,7 @@ struct sock {
68237 #ifdef CONFIG_RPS
68238 __u32 sk_rxhash;
68239 #endif
68240- atomic_t sk_drops;
68241+ atomic_unchecked_t sk_drops;
68242 int sk_rcvbuf;
68243
68244 struct sk_filter __rcu *sk_filter;
68245@@ -1781,7 +1781,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
68246 }
68247
68248 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
68249- char __user *from, char *to,
68250+ char __user *from, unsigned char *to,
68251 int copy, int offset)
68252 {
68253 if (skb->ip_summed == CHECKSUM_NONE) {
68254@@ -2040,7 +2040,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
68255 }
68256 }
68257
68258-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
68259+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
68260
68261 /**
68262 * sk_page_frag - return an appropriate page_frag
68263diff --git a/include/net/tcp.h b/include/net/tcp.h
68264index aed42c7..43890c6 100644
68265--- a/include/net/tcp.h
68266+++ b/include/net/tcp.h
68267@@ -530,7 +530,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
68268 extern void tcp_xmit_retransmit_queue(struct sock *);
68269 extern void tcp_simple_retransmit(struct sock *);
68270 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
68271-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
68272+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
68273
68274 extern void tcp_send_probe0(struct sock *);
68275 extern void tcp_send_partial(struct sock *);
68276@@ -701,8 +701,8 @@ struct tcp_skb_cb {
68277 struct inet6_skb_parm h6;
68278 #endif
68279 } header; /* For incoming frames */
68280- __u32 seq; /* Starting sequence number */
68281- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
68282+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
68283+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
68284 __u32 when; /* used to compute rtt's */
68285 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
68286
68287@@ -716,7 +716,7 @@ struct tcp_skb_cb {
68288
68289 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
68290 /* 1 byte hole */
68291- __u32 ack_seq; /* Sequence number ACK'd */
68292+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
68293 };
68294
68295 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
68296diff --git a/include/net/xfrm.h b/include/net/xfrm.h
68297index 63445ed..74ef61d 100644
68298--- a/include/net/xfrm.h
68299+++ b/include/net/xfrm.h
68300@@ -423,7 +423,7 @@ struct xfrm_mode {
68301 struct module *owner;
68302 unsigned int encap;
68303 int flags;
68304-};
68305+} __do_const;
68306
68307 /* Flags for xfrm_mode. */
68308 enum {
68309@@ -514,7 +514,7 @@ struct xfrm_policy {
68310 struct timer_list timer;
68311
68312 struct flow_cache_object flo;
68313- atomic_t genid;
68314+ atomic_unchecked_t genid;
68315 u32 priority;
68316 u32 index;
68317 struct xfrm_mark mark;
68318diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
68319index 1a046b1..ee0bef0 100644
68320--- a/include/rdma/iw_cm.h
68321+++ b/include/rdma/iw_cm.h
68322@@ -122,7 +122,7 @@ struct iw_cm_verbs {
68323 int backlog);
68324
68325 int (*destroy_listen)(struct iw_cm_id *cm_id);
68326-};
68327+} __no_const;
68328
68329 /**
68330 * iw_create_cm_id - Create an IW CM identifier.
68331diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
68332index 399162b..b337f1a 100644
68333--- a/include/scsi/libfc.h
68334+++ b/include/scsi/libfc.h
68335@@ -762,6 +762,7 @@ struct libfc_function_template {
68336 */
68337 void (*disc_stop_final) (struct fc_lport *);
68338 };
68339+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
68340
68341 /**
68342 * struct fc_disc - Discovery context
68343@@ -866,7 +867,7 @@ struct fc_lport {
68344 struct fc_vport *vport;
68345
68346 /* Operational Information */
68347- struct libfc_function_template tt;
68348+ libfc_function_template_no_const tt;
68349 u8 link_up;
68350 u8 qfull;
68351 enum fc_lport_state state;
68352diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
68353index e65c62e..aa2e5a2 100644
68354--- a/include/scsi/scsi_device.h
68355+++ b/include/scsi/scsi_device.h
68356@@ -170,9 +170,9 @@ struct scsi_device {
68357 unsigned int max_device_blocked; /* what device_blocked counts down from */
68358 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
68359
68360- atomic_t iorequest_cnt;
68361- atomic_t iodone_cnt;
68362- atomic_t ioerr_cnt;
68363+ atomic_unchecked_t iorequest_cnt;
68364+ atomic_unchecked_t iodone_cnt;
68365+ atomic_unchecked_t ioerr_cnt;
68366
68367 struct device sdev_gendev,
68368 sdev_dev;
68369diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
68370index b797e8f..8e2c3aa 100644
68371--- a/include/scsi/scsi_transport_fc.h
68372+++ b/include/scsi/scsi_transport_fc.h
68373@@ -751,7 +751,8 @@ struct fc_function_template {
68374 unsigned long show_host_system_hostname:1;
68375
68376 unsigned long disable_target_scan:1;
68377-};
68378+} __do_const;
68379+typedef struct fc_function_template __no_const fc_function_template_no_const;
68380
68381
68382 /**
68383diff --git a/include/sound/soc.h b/include/sound/soc.h
68384index bc56738..a4be132 100644
68385--- a/include/sound/soc.h
68386+++ b/include/sound/soc.h
68387@@ -771,7 +771,7 @@ struct snd_soc_codec_driver {
68388 /* probe ordering - for components with runtime dependencies */
68389 int probe_order;
68390 int remove_order;
68391-};
68392+} __do_const;
68393
68394 /* SoC platform interface */
68395 struct snd_soc_platform_driver {
68396@@ -817,7 +817,7 @@ struct snd_soc_platform_driver {
68397 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
68398 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
68399 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
68400-};
68401+} __do_const;
68402
68403 struct snd_soc_platform {
68404 const char *name;
68405diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
68406index 663e34a..91b306a 100644
68407--- a/include/target/target_core_base.h
68408+++ b/include/target/target_core_base.h
68409@@ -654,7 +654,7 @@ struct se_device {
68410 spinlock_t stats_lock;
68411 /* Active commands on this virtual SE device */
68412 atomic_t simple_cmds;
68413- atomic_t dev_ordered_id;
68414+ atomic_unchecked_t dev_ordered_id;
68415 atomic_t dev_ordered_sync;
68416 atomic_t dev_qf_count;
68417 int export_count;
68418diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
68419new file mode 100644
68420index 0000000..fb634b7
68421--- /dev/null
68422+++ b/include/trace/events/fs.h
68423@@ -0,0 +1,53 @@
68424+#undef TRACE_SYSTEM
68425+#define TRACE_SYSTEM fs
68426+
68427+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
68428+#define _TRACE_FS_H
68429+
68430+#include <linux/fs.h>
68431+#include <linux/tracepoint.h>
68432+
68433+TRACE_EVENT(do_sys_open,
68434+
68435+ TP_PROTO(const char *filename, int flags, int mode),
68436+
68437+ TP_ARGS(filename, flags, mode),
68438+
68439+ TP_STRUCT__entry(
68440+ __string( filename, filename )
68441+ __field( int, flags )
68442+ __field( int, mode )
68443+ ),
68444+
68445+ TP_fast_assign(
68446+ __assign_str(filename, filename);
68447+ __entry->flags = flags;
68448+ __entry->mode = mode;
68449+ ),
68450+
68451+ TP_printk("\"%s\" %x %o",
68452+ __get_str(filename), __entry->flags, __entry->mode)
68453+);
68454+
68455+TRACE_EVENT(open_exec,
68456+
68457+ TP_PROTO(const char *filename),
68458+
68459+ TP_ARGS(filename),
68460+
68461+ TP_STRUCT__entry(
68462+ __string( filename, filename )
68463+ ),
68464+
68465+ TP_fast_assign(
68466+ __assign_str(filename, filename);
68467+ ),
68468+
68469+ TP_printk("\"%s\"",
68470+ __get_str(filename))
68471+);
68472+
68473+#endif /* _TRACE_FS_H */
68474+
68475+/* This part must be outside protection */
68476+#include <trace/define_trace.h>
68477diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
68478index 1c09820..7f5ec79 100644
68479--- a/include/trace/events/irq.h
68480+++ b/include/trace/events/irq.h
68481@@ -36,7 +36,7 @@ struct softirq_action;
68482 */
68483 TRACE_EVENT(irq_handler_entry,
68484
68485- TP_PROTO(int irq, struct irqaction *action),
68486+ TP_PROTO(int irq, const struct irqaction *action),
68487
68488 TP_ARGS(irq, action),
68489
68490@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
68491 */
68492 TRACE_EVENT(irq_handler_exit,
68493
68494- TP_PROTO(int irq, struct irqaction *action, int ret),
68495+ TP_PROTO(int irq, const struct irqaction *action, int ret),
68496
68497 TP_ARGS(irq, action, ret),
68498
68499diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
68500index 7caf44c..23c6f27 100644
68501--- a/include/uapi/linux/a.out.h
68502+++ b/include/uapi/linux/a.out.h
68503@@ -39,6 +39,14 @@ enum machine_type {
68504 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
68505 };
68506
68507+/* Constants for the N_FLAGS field */
68508+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
68509+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
68510+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
68511+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
68512+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
68513+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
68514+
68515 #if !defined (N_MAGIC)
68516 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
68517 #endif
68518diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
68519index d876736..b36014e 100644
68520--- a/include/uapi/linux/byteorder/little_endian.h
68521+++ b/include/uapi/linux/byteorder/little_endian.h
68522@@ -42,51 +42,51 @@
68523
68524 static inline __le64 __cpu_to_le64p(const __u64 *p)
68525 {
68526- return (__force __le64)*p;
68527+ return (__force const __le64)*p;
68528 }
68529 static inline __u64 __le64_to_cpup(const __le64 *p)
68530 {
68531- return (__force __u64)*p;
68532+ return (__force const __u64)*p;
68533 }
68534 static inline __le32 __cpu_to_le32p(const __u32 *p)
68535 {
68536- return (__force __le32)*p;
68537+ return (__force const __le32)*p;
68538 }
68539 static inline __u32 __le32_to_cpup(const __le32 *p)
68540 {
68541- return (__force __u32)*p;
68542+ return (__force const __u32)*p;
68543 }
68544 static inline __le16 __cpu_to_le16p(const __u16 *p)
68545 {
68546- return (__force __le16)*p;
68547+ return (__force const __le16)*p;
68548 }
68549 static inline __u16 __le16_to_cpup(const __le16 *p)
68550 {
68551- return (__force __u16)*p;
68552+ return (__force const __u16)*p;
68553 }
68554 static inline __be64 __cpu_to_be64p(const __u64 *p)
68555 {
68556- return (__force __be64)__swab64p(p);
68557+ return (__force const __be64)__swab64p(p);
68558 }
68559 static inline __u64 __be64_to_cpup(const __be64 *p)
68560 {
68561- return __swab64p((__u64 *)p);
68562+ return __swab64p((const __u64 *)p);
68563 }
68564 static inline __be32 __cpu_to_be32p(const __u32 *p)
68565 {
68566- return (__force __be32)__swab32p(p);
68567+ return (__force const __be32)__swab32p(p);
68568 }
68569 static inline __u32 __be32_to_cpup(const __be32 *p)
68570 {
68571- return __swab32p((__u32 *)p);
68572+ return __swab32p((const __u32 *)p);
68573 }
68574 static inline __be16 __cpu_to_be16p(const __u16 *p)
68575 {
68576- return (__force __be16)__swab16p(p);
68577+ return (__force const __be16)__swab16p(p);
68578 }
68579 static inline __u16 __be16_to_cpup(const __be16 *p)
68580 {
68581- return __swab16p((__u16 *)p);
68582+ return __swab16p((const __u16 *)p);
68583 }
68584 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
68585 #define __le64_to_cpus(x) do { (void)(x); } while (0)
68586diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
68587index 126a817..d522bd1 100644
68588--- a/include/uapi/linux/elf.h
68589+++ b/include/uapi/linux/elf.h
68590@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
68591 #define PT_GNU_EH_FRAME 0x6474e550
68592
68593 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
68594+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
68595+
68596+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
68597+
68598+/* Constants for the e_flags field */
68599+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
68600+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
68601+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
68602+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
68603+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
68604+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
68605
68606 /*
68607 * Extended Numbering
68608@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
68609 #define DT_DEBUG 21
68610 #define DT_TEXTREL 22
68611 #define DT_JMPREL 23
68612+#define DT_FLAGS 30
68613+ #define DF_TEXTREL 0x00000004
68614 #define DT_ENCODING 32
68615 #define OLD_DT_LOOS 0x60000000
68616 #define DT_LOOS 0x6000000d
68617@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
68618 #define PF_W 0x2
68619 #define PF_X 0x1
68620
68621+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
68622+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
68623+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
68624+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
68625+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
68626+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
68627+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
68628+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
68629+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
68630+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
68631+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
68632+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
68633+
68634 typedef struct elf32_phdr{
68635 Elf32_Word p_type;
68636 Elf32_Off p_offset;
68637@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
68638 #define EI_OSABI 7
68639 #define EI_PAD 8
68640
68641+#define EI_PAX 14
68642+
68643 #define ELFMAG0 0x7f /* EI_MAG */
68644 #define ELFMAG1 'E'
68645 #define ELFMAG2 'L'
68646diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
68647index aa169c4..6a2771d 100644
68648--- a/include/uapi/linux/personality.h
68649+++ b/include/uapi/linux/personality.h
68650@@ -30,6 +30,7 @@ enum {
68651 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
68652 ADDR_NO_RANDOMIZE | \
68653 ADDR_COMPAT_LAYOUT | \
68654+ ADDR_LIMIT_3GB | \
68655 MMAP_PAGE_ZERO)
68656
68657 /*
68658diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
68659index 7530e74..e714828 100644
68660--- a/include/uapi/linux/screen_info.h
68661+++ b/include/uapi/linux/screen_info.h
68662@@ -43,7 +43,8 @@ struct screen_info {
68663 __u16 pages; /* 0x32 */
68664 __u16 vesa_attributes; /* 0x34 */
68665 __u32 capabilities; /* 0x36 */
68666- __u8 _reserved[6]; /* 0x3a */
68667+ __u16 vesapm_size; /* 0x3a */
68668+ __u8 _reserved[4]; /* 0x3c */
68669 } __attribute__((packed));
68670
68671 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
68672diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
68673index 6d67213..8dab561 100644
68674--- a/include/uapi/linux/sysctl.h
68675+++ b/include/uapi/linux/sysctl.h
68676@@ -155,7 +155,11 @@ enum
68677 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
68678 };
68679
68680-
68681+#ifdef CONFIG_PAX_SOFTMODE
68682+enum {
68683+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
68684+};
68685+#endif
68686
68687 /* CTL_VM names: */
68688 enum
68689diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
68690index 26607bd..588b65f 100644
68691--- a/include/uapi/linux/xattr.h
68692+++ b/include/uapi/linux/xattr.h
68693@@ -60,5 +60,9 @@
68694 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
68695 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
68696
68697+/* User namespace */
68698+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
68699+#define XATTR_PAX_FLAGS_SUFFIX "flags"
68700+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
68701
68702 #endif /* _UAPI_LINUX_XATTR_H */
68703diff --git a/include/video/udlfb.h b/include/video/udlfb.h
68704index f9466fa..f4e2b81 100644
68705--- a/include/video/udlfb.h
68706+++ b/include/video/udlfb.h
68707@@ -53,10 +53,10 @@ struct dlfb_data {
68708 u32 pseudo_palette[256];
68709 int blank_mode; /*one of FB_BLANK_ */
68710 /* blit-only rendering path metrics, exposed through sysfs */
68711- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
68712- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
68713- atomic_t bytes_sent; /* to usb, after compression including overhead */
68714- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
68715+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
68716+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
68717+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
68718+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
68719 };
68720
68721 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
68722diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
68723index 0993a22..32ba2fe 100644
68724--- a/include/video/uvesafb.h
68725+++ b/include/video/uvesafb.h
68726@@ -177,6 +177,7 @@ struct uvesafb_par {
68727 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
68728 u8 pmi_setpal; /* PMI for palette changes */
68729 u16 *pmi_base; /* protected mode interface location */
68730+ u8 *pmi_code; /* protected mode code location */
68731 void *pmi_start;
68732 void *pmi_pal;
68733 u8 *vbe_state_orig; /*
68734diff --git a/init/Kconfig b/init/Kconfig
68735index be8b7f5..b13cb62 100644
68736--- a/init/Kconfig
68737+++ b/init/Kconfig
68738@@ -990,6 +990,7 @@ endif # CGROUPS
68739
68740 config CHECKPOINT_RESTORE
68741 bool "Checkpoint/restore support" if EXPERT
68742+ depends on !GRKERNSEC
68743 default n
68744 help
68745 Enables additional kernel features in a sake of checkpoint/restore.
68746@@ -1079,6 +1080,8 @@ config UIDGID_CONVERTED
68747 depends on OCFS2_FS = n
68748 depends on XFS_FS = n
68749
68750+ depends on GRKERNSEC = n
68751+
68752 config UIDGID_STRICT_TYPE_CHECKS
68753 bool "Require conversions between uid/gids and their internal representation"
68754 depends on UIDGID_CONVERTED
68755@@ -1468,7 +1471,7 @@ config SLUB_DEBUG
68756
68757 config COMPAT_BRK
68758 bool "Disable heap randomization"
68759- default y
68760+ default n
68761 help
68762 Randomizing heap placement makes heap exploits harder, but it
68763 also breaks ancient binaries (including anything libc5 based).
68764@@ -1711,7 +1714,7 @@ config INIT_ALL_POSSIBLE
68765 config STOP_MACHINE
68766 bool
68767 default y
68768- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
68769+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
68770 help
68771 Need stop_machine() primitive.
68772
68773diff --git a/init/Makefile b/init/Makefile
68774index 7bc47ee..6da2dc7 100644
68775--- a/init/Makefile
68776+++ b/init/Makefile
68777@@ -2,6 +2,9 @@
68778 # Makefile for the linux kernel.
68779 #
68780
68781+ccflags-y := $(GCC_PLUGINS_CFLAGS)
68782+asflags-y := $(GCC_PLUGINS_AFLAGS)
68783+
68784 obj-y := main.o version.o mounts.o
68785 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
68786 obj-y += noinitramfs.o
68787diff --git a/init/do_mounts.c b/init/do_mounts.c
68788index 1d1b634..a1c810f 100644
68789--- a/init/do_mounts.c
68790+++ b/init/do_mounts.c
68791@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
68792 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
68793 {
68794 struct super_block *s;
68795- int err = sys_mount(name, "/root", fs, flags, data);
68796+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
68797 if (err)
68798 return err;
68799
68800- sys_chdir("/root");
68801+ sys_chdir((const char __force_user *)"/root");
68802 s = current->fs->pwd.dentry->d_sb;
68803 ROOT_DEV = s->s_dev;
68804 printk(KERN_INFO
68805@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
68806 va_start(args, fmt);
68807 vsprintf(buf, fmt, args);
68808 va_end(args);
68809- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
68810+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
68811 if (fd >= 0) {
68812 sys_ioctl(fd, FDEJECT, 0);
68813 sys_close(fd);
68814 }
68815 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
68816- fd = sys_open("/dev/console", O_RDWR, 0);
68817+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
68818 if (fd >= 0) {
68819 sys_ioctl(fd, TCGETS, (long)&termios);
68820 termios.c_lflag &= ~ICANON;
68821 sys_ioctl(fd, TCSETSF, (long)&termios);
68822- sys_read(fd, &c, 1);
68823+ sys_read(fd, (char __user *)&c, 1);
68824 termios.c_lflag |= ICANON;
68825 sys_ioctl(fd, TCSETSF, (long)&termios);
68826 sys_close(fd);
68827@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
68828 mount_root();
68829 out:
68830 devtmpfs_mount("dev");
68831- sys_mount(".", "/", NULL, MS_MOVE, NULL);
68832- sys_chroot(".");
68833+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
68834+ sys_chroot((const char __force_user *)".");
68835 }
68836diff --git a/init/do_mounts.h b/init/do_mounts.h
68837index f5b978a..69dbfe8 100644
68838--- a/init/do_mounts.h
68839+++ b/init/do_mounts.h
68840@@ -15,15 +15,15 @@ extern int root_mountflags;
68841
68842 static inline int create_dev(char *name, dev_t dev)
68843 {
68844- sys_unlink(name);
68845- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
68846+ sys_unlink((char __force_user *)name);
68847+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
68848 }
68849
68850 #if BITS_PER_LONG == 32
68851 static inline u32 bstat(char *name)
68852 {
68853 struct stat64 stat;
68854- if (sys_stat64(name, &stat) != 0)
68855+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
68856 return 0;
68857 if (!S_ISBLK(stat.st_mode))
68858 return 0;
68859@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
68860 static inline u32 bstat(char *name)
68861 {
68862 struct stat stat;
68863- if (sys_newstat(name, &stat) != 0)
68864+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
68865 return 0;
68866 if (!S_ISBLK(stat.st_mode))
68867 return 0;
68868diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
68869index f9acf71..1e19144 100644
68870--- a/init/do_mounts_initrd.c
68871+++ b/init/do_mounts_initrd.c
68872@@ -58,8 +58,8 @@ static void __init handle_initrd(void)
68873 create_dev("/dev/root.old", Root_RAM0);
68874 /* mount initrd on rootfs' /root */
68875 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
68876- sys_mkdir("/old", 0700);
68877- sys_chdir("/old");
68878+ sys_mkdir((const char __force_user *)"/old", 0700);
68879+ sys_chdir((const char __force_user *)"/old");
68880
68881 /*
68882 * In case that a resume from disk is carried out by linuxrc or one of
68883@@ -73,31 +73,31 @@ static void __init handle_initrd(void)
68884 current->flags &= ~PF_FREEZER_SKIP;
68885
68886 /* move initrd to rootfs' /old */
68887- sys_mount("..", ".", NULL, MS_MOVE, NULL);
68888+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
68889 /* switch root and cwd back to / of rootfs */
68890- sys_chroot("..");
68891+ sys_chroot((const char __force_user *)"..");
68892
68893 if (new_decode_dev(real_root_dev) == Root_RAM0) {
68894- sys_chdir("/old");
68895+ sys_chdir((const char __force_user *)"/old");
68896 return;
68897 }
68898
68899- sys_chdir("/");
68900+ sys_chdir((const char __force_user *)"/");
68901 ROOT_DEV = new_decode_dev(real_root_dev);
68902 mount_root();
68903
68904 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
68905- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
68906+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
68907 if (!error)
68908 printk("okay\n");
68909 else {
68910- int fd = sys_open("/dev/root.old", O_RDWR, 0);
68911+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
68912 if (error == -ENOENT)
68913 printk("/initrd does not exist. Ignored.\n");
68914 else
68915 printk("failed\n");
68916 printk(KERN_NOTICE "Unmounting old root\n");
68917- sys_umount("/old", MNT_DETACH);
68918+ sys_umount((char __force_user *)"/old", MNT_DETACH);
68919 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
68920 if (fd < 0) {
68921 error = fd;
68922@@ -120,11 +120,11 @@ int __init initrd_load(void)
68923 * mounted in the normal path.
68924 */
68925 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
68926- sys_unlink("/initrd.image");
68927+ sys_unlink((const char __force_user *)"/initrd.image");
68928 handle_initrd();
68929 return 1;
68930 }
68931 }
68932- sys_unlink("/initrd.image");
68933+ sys_unlink((const char __force_user *)"/initrd.image");
68934 return 0;
68935 }
68936diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
68937index 8cb6db5..d729f50 100644
68938--- a/init/do_mounts_md.c
68939+++ b/init/do_mounts_md.c
68940@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
68941 partitioned ? "_d" : "", minor,
68942 md_setup_args[ent].device_names);
68943
68944- fd = sys_open(name, 0, 0);
68945+ fd = sys_open((char __force_user *)name, 0, 0);
68946 if (fd < 0) {
68947 printk(KERN_ERR "md: open failed - cannot start "
68948 "array %s\n", name);
68949@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
68950 * array without it
68951 */
68952 sys_close(fd);
68953- fd = sys_open(name, 0, 0);
68954+ fd = sys_open((char __force_user *)name, 0, 0);
68955 sys_ioctl(fd, BLKRRPART, 0);
68956 }
68957 sys_close(fd);
68958@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
68959
68960 wait_for_device_probe();
68961
68962- fd = sys_open("/dev/md0", 0, 0);
68963+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
68964 if (fd >= 0) {
68965 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
68966 sys_close(fd);
68967diff --git a/init/init_task.c b/init/init_task.c
68968index 8b2f399..f0797c9 100644
68969--- a/init/init_task.c
68970+++ b/init/init_task.c
68971@@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
68972 * Initial thread structure. Alignment of this is handled by a special
68973 * linker map entry.
68974 */
68975+#ifdef CONFIG_X86
68976+union thread_union init_thread_union __init_task_data;
68977+#else
68978 union thread_union init_thread_union __init_task_data =
68979 { INIT_THREAD_INFO(init_task) };
68980+#endif
68981diff --git a/init/initramfs.c b/init/initramfs.c
68982index 84c6bf1..8899338 100644
68983--- a/init/initramfs.c
68984+++ b/init/initramfs.c
68985@@ -84,7 +84,7 @@ static void __init free_hash(void)
68986 }
68987 }
68988
68989-static long __init do_utime(char *filename, time_t mtime)
68990+static long __init do_utime(char __force_user *filename, time_t mtime)
68991 {
68992 struct timespec t[2];
68993
68994@@ -119,7 +119,7 @@ static void __init dir_utime(void)
68995 struct dir_entry *de, *tmp;
68996 list_for_each_entry_safe(de, tmp, &dir_list, list) {
68997 list_del(&de->list);
68998- do_utime(de->name, de->mtime);
68999+ do_utime((char __force_user *)de->name, de->mtime);
69000 kfree(de->name);
69001 kfree(de);
69002 }
69003@@ -281,7 +281,7 @@ static int __init maybe_link(void)
69004 if (nlink >= 2) {
69005 char *old = find_link(major, minor, ino, mode, collected);
69006 if (old)
69007- return (sys_link(old, collected) < 0) ? -1 : 1;
69008+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
69009 }
69010 return 0;
69011 }
69012@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
69013 {
69014 struct stat st;
69015
69016- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
69017+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
69018 if (S_ISDIR(st.st_mode))
69019- sys_rmdir(path);
69020+ sys_rmdir((char __force_user *)path);
69021 else
69022- sys_unlink(path);
69023+ sys_unlink((char __force_user *)path);
69024 }
69025 }
69026
69027@@ -315,7 +315,7 @@ static int __init do_name(void)
69028 int openflags = O_WRONLY|O_CREAT;
69029 if (ml != 1)
69030 openflags |= O_TRUNC;
69031- wfd = sys_open(collected, openflags, mode);
69032+ wfd = sys_open((char __force_user *)collected, openflags, mode);
69033
69034 if (wfd >= 0) {
69035 sys_fchown(wfd, uid, gid);
69036@@ -327,17 +327,17 @@ static int __init do_name(void)
69037 }
69038 }
69039 } else if (S_ISDIR(mode)) {
69040- sys_mkdir(collected, mode);
69041- sys_chown(collected, uid, gid);
69042- sys_chmod(collected, mode);
69043+ sys_mkdir((char __force_user *)collected, mode);
69044+ sys_chown((char __force_user *)collected, uid, gid);
69045+ sys_chmod((char __force_user *)collected, mode);
69046 dir_add(collected, mtime);
69047 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
69048 S_ISFIFO(mode) || S_ISSOCK(mode)) {
69049 if (maybe_link() == 0) {
69050- sys_mknod(collected, mode, rdev);
69051- sys_chown(collected, uid, gid);
69052- sys_chmod(collected, mode);
69053- do_utime(collected, mtime);
69054+ sys_mknod((char __force_user *)collected, mode, rdev);
69055+ sys_chown((char __force_user *)collected, uid, gid);
69056+ sys_chmod((char __force_user *)collected, mode);
69057+ do_utime((char __force_user *)collected, mtime);
69058 }
69059 }
69060 return 0;
69061@@ -346,15 +346,15 @@ static int __init do_name(void)
69062 static int __init do_copy(void)
69063 {
69064 if (count >= body_len) {
69065- sys_write(wfd, victim, body_len);
69066+ sys_write(wfd, (char __force_user *)victim, body_len);
69067 sys_close(wfd);
69068- do_utime(vcollected, mtime);
69069+ do_utime((char __force_user *)vcollected, mtime);
69070 kfree(vcollected);
69071 eat(body_len);
69072 state = SkipIt;
69073 return 0;
69074 } else {
69075- sys_write(wfd, victim, count);
69076+ sys_write(wfd, (char __force_user *)victim, count);
69077 body_len -= count;
69078 eat(count);
69079 return 1;
69080@@ -365,9 +365,9 @@ static int __init do_symlink(void)
69081 {
69082 collected[N_ALIGN(name_len) + body_len] = '\0';
69083 clean_path(collected, 0);
69084- sys_symlink(collected + N_ALIGN(name_len), collected);
69085- sys_lchown(collected, uid, gid);
69086- do_utime(collected, mtime);
69087+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
69088+ sys_lchown((char __force_user *)collected, uid, gid);
69089+ do_utime((char __force_user *)collected, mtime);
69090 state = SkipIt;
69091 next_state = Reset;
69092 return 0;
69093diff --git a/init/main.c b/init/main.c
69094index cee4b5c..47f445e 100644
69095--- a/init/main.c
69096+++ b/init/main.c
69097@@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
69098 extern void tc_init(void);
69099 #endif
69100
69101+extern void grsecurity_init(void);
69102+
69103 /*
69104 * Debug helper: via this flag we know that we are in 'early bootup code'
69105 * where only the boot processor is running with IRQ disabled. This means
69106@@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
69107
69108 __setup("reset_devices", set_reset_devices);
69109
69110+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
69111+int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
69112+static int __init setup_grsec_proc_gid(char *str)
69113+{
69114+ grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
69115+ return 1;
69116+}
69117+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
69118+#endif
69119+
69120+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
69121+extern char pax_enter_kernel_user[];
69122+extern char pax_exit_kernel_user[];
69123+extern pgdval_t clone_pgd_mask;
69124+#endif
69125+
69126+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
69127+static int __init setup_pax_nouderef(char *str)
69128+{
69129+#ifdef CONFIG_X86_32
69130+ unsigned int cpu;
69131+ struct desc_struct *gdt;
69132+
69133+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
69134+ gdt = get_cpu_gdt_table(cpu);
69135+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
69136+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
69137+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
69138+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
69139+ }
69140+ loadsegment(ds, __KERNEL_DS);
69141+ loadsegment(es, __KERNEL_DS);
69142+ loadsegment(ss, __KERNEL_DS);
69143+#else
69144+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
69145+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
69146+ clone_pgd_mask = ~(pgdval_t)0UL;
69147+#endif
69148+
69149+ return 0;
69150+}
69151+early_param("pax_nouderef", setup_pax_nouderef);
69152+#endif
69153+
69154+#ifdef CONFIG_PAX_SOFTMODE
69155+int pax_softmode;
69156+
69157+static int __init setup_pax_softmode(char *str)
69158+{
69159+ get_option(&str, &pax_softmode);
69160+ return 1;
69161+}
69162+__setup("pax_softmode=", setup_pax_softmode);
69163+#endif
69164+
69165 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
69166 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
69167 static const char *panic_later, *panic_param;
69168@@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
69169 {
69170 int count = preempt_count();
69171 int ret;
69172+ const char *msg1 = "", *msg2 = "";
69173
69174 if (initcall_debug)
69175 ret = do_one_initcall_debug(fn);
69176@@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
69177 sprintf(msgbuf, "error code %d ", ret);
69178
69179 if (preempt_count() != count) {
69180- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
69181+ msg1 = " preemption imbalance";
69182 preempt_count() = count;
69183 }
69184 if (irqs_disabled()) {
69185- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
69186+ msg2 = " disabled interrupts";
69187 local_irq_enable();
69188 }
69189- if (msgbuf[0]) {
69190- printk("initcall %pF returned with %s\n", fn, msgbuf);
69191+ if (msgbuf[0] || *msg1 || *msg2) {
69192+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
69193 }
69194
69195 return ret;
69196@@ -743,6 +801,10 @@ static char *initcall_level_names[] __initdata = {
69197 "late",
69198 };
69199
69200+#ifdef CONFIG_PAX_LATENT_ENTROPY
69201+u64 latent_entropy;
69202+#endif
69203+
69204 static void __init do_initcall_level(int level)
69205 {
69206 extern const struct kernel_param __start___param[], __stop___param[];
69207@@ -755,8 +817,14 @@ static void __init do_initcall_level(int level)
69208 level, level,
69209 &repair_env_string);
69210
69211- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
69212+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
69213 do_one_initcall(*fn);
69214+
69215+#ifdef CONFIG_PAX_LATENT_ENTROPY
69216+ add_device_randomness(&latent_entropy, sizeof(latent_entropy));
69217+#endif
69218+
69219+ }
69220 }
69221
69222 static void __init do_initcalls(void)
69223@@ -790,8 +858,14 @@ static void __init do_pre_smp_initcalls(void)
69224 {
69225 initcall_t *fn;
69226
69227- for (fn = __initcall_start; fn < __initcall0_start; fn++)
69228+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
69229 do_one_initcall(*fn);
69230+
69231+#ifdef CONFIG_PAX_LATENT_ENTROPY
69232+ add_device_randomness(&latent_entropy, sizeof(latent_entropy));
69233+#endif
69234+
69235+ }
69236 }
69237
69238 static int run_init_process(const char *init_filename)
69239@@ -877,7 +951,7 @@ static noinline void __init kernel_init_freeable(void)
69240 do_basic_setup();
69241
69242 /* Open the /dev/console on the rootfs, this should never fail */
69243- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
69244+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
69245 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
69246
69247 (void) sys_dup(0);
69248@@ -890,11 +964,13 @@ static noinline void __init kernel_init_freeable(void)
69249 if (!ramdisk_execute_command)
69250 ramdisk_execute_command = "/init";
69251
69252- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
69253+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
69254 ramdisk_execute_command = NULL;
69255 prepare_namespace();
69256 }
69257
69258+ grsecurity_init();
69259+
69260 /*
69261 * Ok, we have completed the initial bootup, and
69262 * we're essentially up and running. Get rid of the
69263diff --git a/ipc/mqueue.c b/ipc/mqueue.c
69264index 71a3ca1..cc330ee 100644
69265--- a/ipc/mqueue.c
69266+++ b/ipc/mqueue.c
69267@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
69268 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
69269 info->attr.mq_msgsize);
69270
69271+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
69272 spin_lock(&mq_lock);
69273 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
69274 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
69275diff --git a/ipc/msg.c b/ipc/msg.c
69276index 950572f..266c15f 100644
69277--- a/ipc/msg.c
69278+++ b/ipc/msg.c
69279@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
69280 return security_msg_queue_associate(msq, msgflg);
69281 }
69282
69283+static struct ipc_ops msg_ops = {
69284+ .getnew = newque,
69285+ .associate = msg_security,
69286+ .more_checks = NULL
69287+};
69288+
69289 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
69290 {
69291 struct ipc_namespace *ns;
69292- struct ipc_ops msg_ops;
69293 struct ipc_params msg_params;
69294
69295 ns = current->nsproxy->ipc_ns;
69296
69297- msg_ops.getnew = newque;
69298- msg_ops.associate = msg_security;
69299- msg_ops.more_checks = NULL;
69300-
69301 msg_params.key = key;
69302 msg_params.flg = msgflg;
69303
69304diff --git a/ipc/sem.c b/ipc/sem.c
69305index 58d31f1..cce7a55 100644
69306--- a/ipc/sem.c
69307+++ b/ipc/sem.c
69308@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
69309 return 0;
69310 }
69311
69312+static struct ipc_ops sem_ops = {
69313+ .getnew = newary,
69314+ .associate = sem_security,
69315+ .more_checks = sem_more_checks
69316+};
69317+
69318 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
69319 {
69320 struct ipc_namespace *ns;
69321- struct ipc_ops sem_ops;
69322 struct ipc_params sem_params;
69323
69324 ns = current->nsproxy->ipc_ns;
69325@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
69326 if (nsems < 0 || nsems > ns->sc_semmsl)
69327 return -EINVAL;
69328
69329- sem_ops.getnew = newary;
69330- sem_ops.associate = sem_security;
69331- sem_ops.more_checks = sem_more_checks;
69332-
69333 sem_params.key = key;
69334 sem_params.flg = semflg;
69335 sem_params.u.nsems = nsems;
69336diff --git a/ipc/shm.c b/ipc/shm.c
69337index 4fa6d8f..38dfd0c 100644
69338--- a/ipc/shm.c
69339+++ b/ipc/shm.c
69340@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
69341 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
69342 #endif
69343
69344+#ifdef CONFIG_GRKERNSEC
69345+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
69346+ const time_t shm_createtime, const uid_t cuid,
69347+ const int shmid);
69348+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
69349+ const time_t shm_createtime);
69350+#endif
69351+
69352 void shm_init_ns(struct ipc_namespace *ns)
69353 {
69354 ns->shm_ctlmax = SHMMAX;
69355@@ -521,6 +529,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
69356 shp->shm_lprid = 0;
69357 shp->shm_atim = shp->shm_dtim = 0;
69358 shp->shm_ctim = get_seconds();
69359+#ifdef CONFIG_GRKERNSEC
69360+ {
69361+ struct timespec timeval;
69362+ do_posix_clock_monotonic_gettime(&timeval);
69363+
69364+ shp->shm_createtime = timeval.tv_sec;
69365+ }
69366+#endif
69367 shp->shm_segsz = size;
69368 shp->shm_nattch = 0;
69369 shp->shm_file = file;
69370@@ -572,18 +588,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
69371 return 0;
69372 }
69373
69374+static struct ipc_ops shm_ops = {
69375+ .getnew = newseg,
69376+ .associate = shm_security,
69377+ .more_checks = shm_more_checks
69378+};
69379+
69380 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
69381 {
69382 struct ipc_namespace *ns;
69383- struct ipc_ops shm_ops;
69384 struct ipc_params shm_params;
69385
69386 ns = current->nsproxy->ipc_ns;
69387
69388- shm_ops.getnew = newseg;
69389- shm_ops.associate = shm_security;
69390- shm_ops.more_checks = shm_more_checks;
69391-
69392 shm_params.key = key;
69393 shm_params.flg = shmflg;
69394 shm_params.u.size = size;
69395@@ -1004,6 +1021,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
69396 f_mode = FMODE_READ | FMODE_WRITE;
69397 }
69398 if (shmflg & SHM_EXEC) {
69399+
69400+#ifdef CONFIG_PAX_MPROTECT
69401+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
69402+ goto out;
69403+#endif
69404+
69405 prot |= PROT_EXEC;
69406 acc_mode |= S_IXUGO;
69407 }
69408@@ -1027,9 +1050,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
69409 if (err)
69410 goto out_unlock;
69411
69412+#ifdef CONFIG_GRKERNSEC
69413+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
69414+ shp->shm_perm.cuid, shmid) ||
69415+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
69416+ err = -EACCES;
69417+ goto out_unlock;
69418+ }
69419+#endif
69420+
69421 path = shp->shm_file->f_path;
69422 path_get(&path);
69423 shp->shm_nattch++;
69424+#ifdef CONFIG_GRKERNSEC
69425+ shp->shm_lapid = current->pid;
69426+#endif
69427 size = i_size_read(path.dentry->d_inode);
69428 shm_unlock(shp);
69429
69430diff --git a/kernel/acct.c b/kernel/acct.c
69431index 051e071..15e0920 100644
69432--- a/kernel/acct.c
69433+++ b/kernel/acct.c
69434@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
69435 */
69436 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
69437 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
69438- file->f_op->write(file, (char *)&ac,
69439+ file->f_op->write(file, (char __force_user *)&ac,
69440 sizeof(acct_t), &file->f_pos);
69441 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
69442 set_fs(fs);
69443diff --git a/kernel/audit.c b/kernel/audit.c
69444index d596e53..dbef3c3 100644
69445--- a/kernel/audit.c
69446+++ b/kernel/audit.c
69447@@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
69448 3) suppressed due to audit_rate_limit
69449 4) suppressed due to audit_backlog_limit
69450 */
69451-static atomic_t audit_lost = ATOMIC_INIT(0);
69452+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
69453
69454 /* The netlink socket. */
69455 static struct sock *audit_sock;
69456@@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
69457 unsigned long now;
69458 int print;
69459
69460- atomic_inc(&audit_lost);
69461+ atomic_inc_unchecked(&audit_lost);
69462
69463 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
69464
69465@@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
69466 printk(KERN_WARNING
69467 "audit: audit_lost=%d audit_rate_limit=%d "
69468 "audit_backlog_limit=%d\n",
69469- atomic_read(&audit_lost),
69470+ atomic_read_unchecked(&audit_lost),
69471 audit_rate_limit,
69472 audit_backlog_limit);
69473 audit_panic(message);
69474@@ -681,7 +681,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
69475 status_set.pid = audit_pid;
69476 status_set.rate_limit = audit_rate_limit;
69477 status_set.backlog_limit = audit_backlog_limit;
69478- status_set.lost = atomic_read(&audit_lost);
69479+ status_set.lost = atomic_read_unchecked(&audit_lost);
69480 status_set.backlog = skb_queue_len(&audit_skb_queue);
69481 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
69482 &status_set, sizeof(status_set));
69483diff --git a/kernel/auditsc.c b/kernel/auditsc.c
69484index a371f85..da826c1 100644
69485--- a/kernel/auditsc.c
69486+++ b/kernel/auditsc.c
69487@@ -2292,7 +2292,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
69488 }
69489
69490 /* global counter which is incremented every time something logs in */
69491-static atomic_t session_id = ATOMIC_INIT(0);
69492+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
69493
69494 /**
69495 * audit_set_loginuid - set current task's audit_context loginuid
69496@@ -2316,7 +2316,7 @@ int audit_set_loginuid(kuid_t loginuid)
69497 return -EPERM;
69498 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
69499
69500- sessionid = atomic_inc_return(&session_id);
69501+ sessionid = atomic_inc_return_unchecked(&session_id);
69502 if (context && context->in_syscall) {
69503 struct audit_buffer *ab;
69504
69505diff --git a/kernel/capability.c b/kernel/capability.c
69506index 493d972..f87dfbd 100644
69507--- a/kernel/capability.c
69508+++ b/kernel/capability.c
69509@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
69510 * before modification is attempted and the application
69511 * fails.
69512 */
69513+ if (tocopy > ARRAY_SIZE(kdata))
69514+ return -EFAULT;
69515+
69516 if (copy_to_user(dataptr, kdata, tocopy
69517 * sizeof(struct __user_cap_data_struct))) {
69518 return -EFAULT;
69519@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
69520 int ret;
69521
69522 rcu_read_lock();
69523- ret = security_capable(__task_cred(t), ns, cap);
69524+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
69525+ gr_task_is_capable(t, __task_cred(t), cap);
69526 rcu_read_unlock();
69527
69528- return (ret == 0);
69529+ return ret;
69530 }
69531
69532 /**
69533@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
69534 int ret;
69535
69536 rcu_read_lock();
69537- ret = security_capable_noaudit(__task_cred(t), ns, cap);
69538+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
69539 rcu_read_unlock();
69540
69541- return (ret == 0);
69542+ return ret;
69543 }
69544
69545 /**
69546@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
69547 BUG();
69548 }
69549
69550- if (security_capable(current_cred(), ns, cap) == 0) {
69551+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
69552 current->flags |= PF_SUPERPRIV;
69553 return true;
69554 }
69555@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
69556 }
69557 EXPORT_SYMBOL(ns_capable);
69558
69559+bool ns_capable_nolog(struct user_namespace *ns, int cap)
69560+{
69561+ if (unlikely(!cap_valid(cap))) {
69562+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
69563+ BUG();
69564+ }
69565+
69566+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
69567+ current->flags |= PF_SUPERPRIV;
69568+ return true;
69569+ }
69570+ return false;
69571+}
69572+EXPORT_SYMBOL(ns_capable_nolog);
69573+
69574 /**
69575 * capable - Determine if the current task has a superior capability in effect
69576 * @cap: The capability to be tested for
69577@@ -408,6 +427,12 @@ bool capable(int cap)
69578 }
69579 EXPORT_SYMBOL(capable);
69580
69581+bool capable_nolog(int cap)
69582+{
69583+ return ns_capable_nolog(&init_user_ns, cap);
69584+}
69585+EXPORT_SYMBOL(capable_nolog);
69586+
69587 /**
69588 * nsown_capable - Check superior capability to one's own user_ns
69589 * @cap: The capability in question
69590@@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
69591
69592 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
69593 }
69594+
69595+bool inode_capable_nolog(const struct inode *inode, int cap)
69596+{
69597+ struct user_namespace *ns = current_user_ns();
69598+
69599+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
69600+}
69601diff --git a/kernel/cgroup.c b/kernel/cgroup.c
69602index 4855892..30d23b4 100644
69603--- a/kernel/cgroup.c
69604+++ b/kernel/cgroup.c
69605@@ -5535,7 +5535,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
69606 struct css_set *cg = link->cg;
69607 struct task_struct *task;
69608 int count = 0;
69609- seq_printf(seq, "css_set %p\n", cg);
69610+ seq_printf(seq, "css_set %pK\n", cg);
69611 list_for_each_entry(task, &cg->tasks, cg_list) {
69612 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
69613 seq_puts(seq, " ...\n");
69614diff --git a/kernel/compat.c b/kernel/compat.c
69615index 36700e9..73d770c 100644
69616--- a/kernel/compat.c
69617+++ b/kernel/compat.c
69618@@ -13,6 +13,7 @@
69619
69620 #include <linux/linkage.h>
69621 #include <linux/compat.h>
69622+#include <linux/module.h>
69623 #include <linux/errno.h>
69624 #include <linux/time.h>
69625 #include <linux/signal.h>
69626@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
69627 mm_segment_t oldfs;
69628 long ret;
69629
69630- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
69631+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
69632 oldfs = get_fs();
69633 set_fs(KERNEL_DS);
69634 ret = hrtimer_nanosleep_restart(restart);
69635@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
69636 oldfs = get_fs();
69637 set_fs(KERNEL_DS);
69638 ret = hrtimer_nanosleep(&tu,
69639- rmtp ? (struct timespec __user *)&rmt : NULL,
69640+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
69641 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
69642 set_fs(oldfs);
69643
69644@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
69645 mm_segment_t old_fs = get_fs();
69646
69647 set_fs(KERNEL_DS);
69648- ret = sys_sigpending((old_sigset_t __user *) &s);
69649+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
69650 set_fs(old_fs);
69651 if (ret == 0)
69652 ret = put_user(s, set);
69653@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
69654 mm_segment_t old_fs = get_fs();
69655
69656 set_fs(KERNEL_DS);
69657- ret = sys_old_getrlimit(resource, &r);
69658+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
69659 set_fs(old_fs);
69660
69661 if (!ret) {
69662@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
69663 mm_segment_t old_fs = get_fs();
69664
69665 set_fs(KERNEL_DS);
69666- ret = sys_getrusage(who, (struct rusage __user *) &r);
69667+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
69668 set_fs(old_fs);
69669
69670 if (ret)
69671@@ -552,8 +553,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
69672 set_fs (KERNEL_DS);
69673 ret = sys_wait4(pid,
69674 (stat_addr ?
69675- (unsigned int __user *) &status : NULL),
69676- options, (struct rusage __user *) &r);
69677+ (unsigned int __force_user *) &status : NULL),
69678+ options, (struct rusage __force_user *) &r);
69679 set_fs (old_fs);
69680
69681 if (ret > 0) {
69682@@ -579,8 +580,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
69683 memset(&info, 0, sizeof(info));
69684
69685 set_fs(KERNEL_DS);
69686- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
69687- uru ? (struct rusage __user *)&ru : NULL);
69688+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
69689+ uru ? (struct rusage __force_user *)&ru : NULL);
69690 set_fs(old_fs);
69691
69692 if ((ret < 0) || (info.si_signo == 0))
69693@@ -714,8 +715,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
69694 oldfs = get_fs();
69695 set_fs(KERNEL_DS);
69696 err = sys_timer_settime(timer_id, flags,
69697- (struct itimerspec __user *) &newts,
69698- (struct itimerspec __user *) &oldts);
69699+ (struct itimerspec __force_user *) &newts,
69700+ (struct itimerspec __force_user *) &oldts);
69701 set_fs(oldfs);
69702 if (!err && old && put_compat_itimerspec(old, &oldts))
69703 return -EFAULT;
69704@@ -732,7 +733,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
69705 oldfs = get_fs();
69706 set_fs(KERNEL_DS);
69707 err = sys_timer_gettime(timer_id,
69708- (struct itimerspec __user *) &ts);
69709+ (struct itimerspec __force_user *) &ts);
69710 set_fs(oldfs);
69711 if (!err && put_compat_itimerspec(setting, &ts))
69712 return -EFAULT;
69713@@ -751,7 +752,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
69714 oldfs = get_fs();
69715 set_fs(KERNEL_DS);
69716 err = sys_clock_settime(which_clock,
69717- (struct timespec __user *) &ts);
69718+ (struct timespec __force_user *) &ts);
69719 set_fs(oldfs);
69720 return err;
69721 }
69722@@ -766,7 +767,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
69723 oldfs = get_fs();
69724 set_fs(KERNEL_DS);
69725 err = sys_clock_gettime(which_clock,
69726- (struct timespec __user *) &ts);
69727+ (struct timespec __force_user *) &ts);
69728 set_fs(oldfs);
69729 if (!err && put_compat_timespec(&ts, tp))
69730 return -EFAULT;
69731@@ -786,7 +787,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
69732
69733 oldfs = get_fs();
69734 set_fs(KERNEL_DS);
69735- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
69736+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
69737 set_fs(oldfs);
69738
69739 err = compat_put_timex(utp, &txc);
69740@@ -806,7 +807,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
69741 oldfs = get_fs();
69742 set_fs(KERNEL_DS);
69743 err = sys_clock_getres(which_clock,
69744- (struct timespec __user *) &ts);
69745+ (struct timespec __force_user *) &ts);
69746 set_fs(oldfs);
69747 if (!err && tp && put_compat_timespec(&ts, tp))
69748 return -EFAULT;
69749@@ -818,9 +819,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
69750 long err;
69751 mm_segment_t oldfs;
69752 struct timespec tu;
69753- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
69754+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
69755
69756- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
69757+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
69758 oldfs = get_fs();
69759 set_fs(KERNEL_DS);
69760 err = clock_nanosleep_restart(restart);
69761@@ -852,8 +853,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
69762 oldfs = get_fs();
69763 set_fs(KERNEL_DS);
69764 err = sys_clock_nanosleep(which_clock, flags,
69765- (struct timespec __user *) &in,
69766- (struct timespec __user *) &out);
69767+ (struct timespec __force_user *) &in,
69768+ (struct timespec __force_user *) &out);
69769 set_fs(oldfs);
69770
69771 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
69772diff --git a/kernel/configs.c b/kernel/configs.c
69773index 42e8fa0..9e7406b 100644
69774--- a/kernel/configs.c
69775+++ b/kernel/configs.c
69776@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
69777 struct proc_dir_entry *entry;
69778
69779 /* create the current config file */
69780+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
69781+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
69782+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
69783+ &ikconfig_file_ops);
69784+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69785+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
69786+ &ikconfig_file_ops);
69787+#endif
69788+#else
69789 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
69790 &ikconfig_file_ops);
69791+#endif
69792+
69793 if (!entry)
69794 return -ENOMEM;
69795
69796diff --git a/kernel/cred.c b/kernel/cred.c
69797index e0573a4..eefe488 100644
69798--- a/kernel/cred.c
69799+++ b/kernel/cred.c
69800@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
69801 validate_creds(cred);
69802 alter_cred_subscribers(cred, -1);
69803 put_cred(cred);
69804+
69805+#ifdef CONFIG_GRKERNSEC_SETXID
69806+ cred = (struct cred *) tsk->delayed_cred;
69807+ if (cred != NULL) {
69808+ tsk->delayed_cred = NULL;
69809+ validate_creds(cred);
69810+ alter_cred_subscribers(cred, -1);
69811+ put_cred(cred);
69812+ }
69813+#endif
69814 }
69815
69816 /**
69817@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
69818 * Always returns 0 thus allowing this function to be tail-called at the end
69819 * of, say, sys_setgid().
69820 */
69821-int commit_creds(struct cred *new)
69822+static int __commit_creds(struct cred *new)
69823 {
69824 struct task_struct *task = current;
69825 const struct cred *old = task->real_cred;
69826@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
69827
69828 get_cred(new); /* we will require a ref for the subj creds too */
69829
69830+ gr_set_role_label(task, new->uid, new->gid);
69831+
69832 /* dumpability changes */
69833 if (!uid_eq(old->euid, new->euid) ||
69834 !gid_eq(old->egid, new->egid) ||
69835@@ -479,6 +491,101 @@ int commit_creds(struct cred *new)
69836 put_cred(old);
69837 return 0;
69838 }
69839+#ifdef CONFIG_GRKERNSEC_SETXID
69840+extern int set_user(struct cred *new);
69841+
69842+void gr_delayed_cred_worker(void)
69843+{
69844+ const struct cred *new = current->delayed_cred;
69845+ struct cred *ncred;
69846+
69847+ current->delayed_cred = NULL;
69848+
69849+ if (current_uid() && new != NULL) {
69850+ // from doing get_cred on it when queueing this
69851+ put_cred(new);
69852+ return;
69853+ } else if (new == NULL)
69854+ return;
69855+
69856+ ncred = prepare_creds();
69857+ if (!ncred)
69858+ goto die;
69859+ // uids
69860+ ncred->uid = new->uid;
69861+ ncred->euid = new->euid;
69862+ ncred->suid = new->suid;
69863+ ncred->fsuid = new->fsuid;
69864+ // gids
69865+ ncred->gid = new->gid;
69866+ ncred->egid = new->egid;
69867+ ncred->sgid = new->sgid;
69868+ ncred->fsgid = new->fsgid;
69869+ // groups
69870+ if (set_groups(ncred, new->group_info) < 0) {
69871+ abort_creds(ncred);
69872+ goto die;
69873+ }
69874+ // caps
69875+ ncred->securebits = new->securebits;
69876+ ncred->cap_inheritable = new->cap_inheritable;
69877+ ncred->cap_permitted = new->cap_permitted;
69878+ ncred->cap_effective = new->cap_effective;
69879+ ncred->cap_bset = new->cap_bset;
69880+
69881+ if (set_user(ncred)) {
69882+ abort_creds(ncred);
69883+ goto die;
69884+ }
69885+
69886+ // from doing get_cred on it when queueing this
69887+ put_cred(new);
69888+
69889+ __commit_creds(ncred);
69890+ return;
69891+die:
69892+ // from doing get_cred on it when queueing this
69893+ put_cred(new);
69894+ do_group_exit(SIGKILL);
69895+}
69896+#endif
69897+
69898+int commit_creds(struct cred *new)
69899+{
69900+#ifdef CONFIG_GRKERNSEC_SETXID
69901+ int ret;
69902+ int schedule_it = 0;
69903+ struct task_struct *t;
69904+
69905+ /* we won't get called with tasklist_lock held for writing
69906+ and interrupts disabled as the cred struct in that case is
69907+ init_cred
69908+ */
69909+ if (grsec_enable_setxid && !current_is_single_threaded() &&
69910+ !current_uid() && new->uid) {
69911+ schedule_it = 1;
69912+ }
69913+ ret = __commit_creds(new);
69914+ if (schedule_it) {
69915+ rcu_read_lock();
69916+ read_lock(&tasklist_lock);
69917+ for (t = next_thread(current); t != current;
69918+ t = next_thread(t)) {
69919+ if (t->delayed_cred == NULL) {
69920+ t->delayed_cred = get_cred(new);
69921+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
69922+ set_tsk_need_resched(t);
69923+ }
69924+ }
69925+ read_unlock(&tasklist_lock);
69926+ rcu_read_unlock();
69927+ }
69928+ return ret;
69929+#else
69930+ return __commit_creds(new);
69931+#endif
69932+}
69933+
69934 EXPORT_SYMBOL(commit_creds);
69935
69936 /**
69937diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
69938index 9a61738..c5c8f3a 100644
69939--- a/kernel/debug/debug_core.c
69940+++ b/kernel/debug/debug_core.c
69941@@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
69942 */
69943 static atomic_t masters_in_kgdb;
69944 static atomic_t slaves_in_kgdb;
69945-static atomic_t kgdb_break_tasklet_var;
69946+static atomic_unchecked_t kgdb_break_tasklet_var;
69947 atomic_t kgdb_setting_breakpoint;
69948
69949 struct task_struct *kgdb_usethread;
69950@@ -132,7 +132,7 @@ int kgdb_single_step;
69951 static pid_t kgdb_sstep_pid;
69952
69953 /* to keep track of the CPU which is doing the single stepping*/
69954-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
69955+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
69956
69957 /*
69958 * If you are debugging a problem where roundup (the collection of
69959@@ -540,7 +540,7 @@ return_normal:
69960 * kernel will only try for the value of sstep_tries before
69961 * giving up and continuing on.
69962 */
69963- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
69964+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
69965 (kgdb_info[cpu].task &&
69966 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
69967 atomic_set(&kgdb_active, -1);
69968@@ -634,8 +634,8 @@ cpu_master_loop:
69969 }
69970
69971 kgdb_restore:
69972- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
69973- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
69974+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
69975+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
69976 if (kgdb_info[sstep_cpu].task)
69977 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
69978 else
69979@@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
69980 static void kgdb_tasklet_bpt(unsigned long ing)
69981 {
69982 kgdb_breakpoint();
69983- atomic_set(&kgdb_break_tasklet_var, 0);
69984+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
69985 }
69986
69987 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
69988
69989 void kgdb_schedule_breakpoint(void)
69990 {
69991- if (atomic_read(&kgdb_break_tasklet_var) ||
69992+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
69993 atomic_read(&kgdb_active) != -1 ||
69994 atomic_read(&kgdb_setting_breakpoint))
69995 return;
69996- atomic_inc(&kgdb_break_tasklet_var);
69997+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
69998 tasklet_schedule(&kgdb_tasklet_breakpoint);
69999 }
70000 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
70001diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
70002index 8875254..7cf4928 100644
70003--- a/kernel/debug/kdb/kdb_main.c
70004+++ b/kernel/debug/kdb/kdb_main.c
70005@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
70006 continue;
70007
70008 kdb_printf("%-20s%8u 0x%p ", mod->name,
70009- mod->core_size, (void *)mod);
70010+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
70011 #ifdef CONFIG_MODULE_UNLOAD
70012 kdb_printf("%4ld ", module_refcount(mod));
70013 #endif
70014@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
70015 kdb_printf(" (Loading)");
70016 else
70017 kdb_printf(" (Live)");
70018- kdb_printf(" 0x%p", mod->module_core);
70019+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
70020
70021 #ifdef CONFIG_MODULE_UNLOAD
70022 {
70023diff --git a/kernel/events/core.c b/kernel/events/core.c
70024index 7b6646a..3cb1135 100644
70025--- a/kernel/events/core.c
70026+++ b/kernel/events/core.c
70027@@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
70028 return 0;
70029 }
70030
70031-static atomic64_t perf_event_id;
70032+static atomic64_unchecked_t perf_event_id;
70033
70034 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
70035 enum event_type_t event_type);
70036@@ -2677,7 +2677,7 @@ static void __perf_event_read(void *info)
70037
70038 static inline u64 perf_event_count(struct perf_event *event)
70039 {
70040- return local64_read(&event->count) + atomic64_read(&event->child_count);
70041+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
70042 }
70043
70044 static u64 perf_event_read(struct perf_event *event)
70045@@ -3007,9 +3007,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
70046 mutex_lock(&event->child_mutex);
70047 total += perf_event_read(event);
70048 *enabled += event->total_time_enabled +
70049- atomic64_read(&event->child_total_time_enabled);
70050+ atomic64_read_unchecked(&event->child_total_time_enabled);
70051 *running += event->total_time_running +
70052- atomic64_read(&event->child_total_time_running);
70053+ atomic64_read_unchecked(&event->child_total_time_running);
70054
70055 list_for_each_entry(child, &event->child_list, child_list) {
70056 total += perf_event_read(child);
70057@@ -3412,10 +3412,10 @@ void perf_event_update_userpage(struct perf_event *event)
70058 userpg->offset -= local64_read(&event->hw.prev_count);
70059
70060 userpg->time_enabled = enabled +
70061- atomic64_read(&event->child_total_time_enabled);
70062+ atomic64_read_unchecked(&event->child_total_time_enabled);
70063
70064 userpg->time_running = running +
70065- atomic64_read(&event->child_total_time_running);
70066+ atomic64_read_unchecked(&event->child_total_time_running);
70067
70068 arch_perf_update_userpage(userpg, now);
70069
70070@@ -3974,11 +3974,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
70071 values[n++] = perf_event_count(event);
70072 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
70073 values[n++] = enabled +
70074- atomic64_read(&event->child_total_time_enabled);
70075+ atomic64_read_unchecked(&event->child_total_time_enabled);
70076 }
70077 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
70078 values[n++] = running +
70079- atomic64_read(&event->child_total_time_running);
70080+ atomic64_read_unchecked(&event->child_total_time_running);
70081 }
70082 if (read_format & PERF_FORMAT_ID)
70083 values[n++] = primary_event_id(event);
70084@@ -4721,12 +4721,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
70085 * need to add enough zero bytes after the string to handle
70086 * the 64bit alignment we do later.
70087 */
70088- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
70089+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
70090 if (!buf) {
70091 name = strncpy(tmp, "//enomem", sizeof(tmp));
70092 goto got_name;
70093 }
70094- name = d_path(&file->f_path, buf, PATH_MAX);
70095+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
70096 if (IS_ERR(name)) {
70097 name = strncpy(tmp, "//toolong", sizeof(tmp));
70098 goto got_name;
70099@@ -6165,7 +6165,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
70100 event->parent = parent_event;
70101
70102 event->ns = get_pid_ns(task_active_pid_ns(current));
70103- event->id = atomic64_inc_return(&perf_event_id);
70104+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
70105
70106 event->state = PERF_EVENT_STATE_INACTIVE;
70107
70108@@ -6790,10 +6790,10 @@ static void sync_child_event(struct perf_event *child_event,
70109 /*
70110 * Add back the child's count to the parent's count:
70111 */
70112- atomic64_add(child_val, &parent_event->child_count);
70113- atomic64_add(child_event->total_time_enabled,
70114+ atomic64_add_unchecked(child_val, &parent_event->child_count);
70115+ atomic64_add_unchecked(child_event->total_time_enabled,
70116 &parent_event->child_total_time_enabled);
70117- atomic64_add(child_event->total_time_running,
70118+ atomic64_add_unchecked(child_event->total_time_running,
70119 &parent_event->child_total_time_running);
70120
70121 /*
70122diff --git a/kernel/exit.c b/kernel/exit.c
70123index b4df219..f13c02d 100644
70124--- a/kernel/exit.c
70125+++ b/kernel/exit.c
70126@@ -170,6 +170,10 @@ void release_task(struct task_struct * p)
70127 struct task_struct *leader;
70128 int zap_leader;
70129 repeat:
70130+#ifdef CONFIG_NET
70131+ gr_del_task_from_ip_table(p);
70132+#endif
70133+
70134 /* don't need to get the RCU readlock here - the process is dead and
70135 * can't be modifying its own credentials. But shut RCU-lockdep up */
70136 rcu_read_lock();
70137@@ -338,7 +342,7 @@ int allow_signal(int sig)
70138 * know it'll be handled, so that they don't get converted to
70139 * SIGKILL or just silently dropped.
70140 */
70141- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
70142+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
70143 recalc_sigpending();
70144 spin_unlock_irq(&current->sighand->siglock);
70145 return 0;
70146@@ -708,6 +712,8 @@ void do_exit(long code)
70147 struct task_struct *tsk = current;
70148 int group_dead;
70149
70150+ set_fs(USER_DS);
70151+
70152 profile_task_exit(tsk);
70153
70154 WARN_ON(blk_needs_flush_plug(tsk));
70155@@ -724,7 +730,6 @@ void do_exit(long code)
70156 * mm_release()->clear_child_tid() from writing to a user-controlled
70157 * kernel address.
70158 */
70159- set_fs(USER_DS);
70160
70161 ptrace_event(PTRACE_EVENT_EXIT, code);
70162
70163@@ -783,6 +788,9 @@ void do_exit(long code)
70164 tsk->exit_code = code;
70165 taskstats_exit(tsk, group_dead);
70166
70167+ gr_acl_handle_psacct(tsk, code);
70168+ gr_acl_handle_exit();
70169+
70170 exit_mm(tsk);
70171
70172 if (group_dead)
70173@@ -903,7 +911,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
70174 * Take down every thread in the group. This is called by fatal signals
70175 * as well as by sys_exit_group (below).
70176 */
70177-void
70178+__noreturn void
70179 do_group_exit(int exit_code)
70180 {
70181 struct signal_struct *sig = current->signal;
70182diff --git a/kernel/fork.c b/kernel/fork.c
70183index c535f33..1d768f9 100644
70184--- a/kernel/fork.c
70185+++ b/kernel/fork.c
70186@@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
70187 *stackend = STACK_END_MAGIC; /* for overflow detection */
70188
70189 #ifdef CONFIG_CC_STACKPROTECTOR
70190- tsk->stack_canary = get_random_int();
70191+ tsk->stack_canary = pax_get_random_long();
70192 #endif
70193
70194 /*
70195@@ -344,13 +344,81 @@ free_tsk:
70196 }
70197
70198 #ifdef CONFIG_MMU
70199+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
70200+{
70201+ struct vm_area_struct *tmp;
70202+ unsigned long charge;
70203+ struct mempolicy *pol;
70204+ struct file *file;
70205+
70206+ charge = 0;
70207+ if (mpnt->vm_flags & VM_ACCOUNT) {
70208+ unsigned long len = vma_pages(mpnt);
70209+
70210+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
70211+ goto fail_nomem;
70212+ charge = len;
70213+ }
70214+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
70215+ if (!tmp)
70216+ goto fail_nomem;
70217+ *tmp = *mpnt;
70218+ tmp->vm_mm = mm;
70219+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
70220+ pol = mpol_dup(vma_policy(mpnt));
70221+ if (IS_ERR(pol))
70222+ goto fail_nomem_policy;
70223+ vma_set_policy(tmp, pol);
70224+ if (anon_vma_fork(tmp, mpnt))
70225+ goto fail_nomem_anon_vma_fork;
70226+ tmp->vm_flags &= ~VM_LOCKED;
70227+ tmp->vm_next = tmp->vm_prev = NULL;
70228+ tmp->vm_mirror = NULL;
70229+ file = tmp->vm_file;
70230+ if (file) {
70231+ struct inode *inode = file->f_path.dentry->d_inode;
70232+ struct address_space *mapping = file->f_mapping;
70233+
70234+ get_file(file);
70235+ if (tmp->vm_flags & VM_DENYWRITE)
70236+ atomic_dec(&inode->i_writecount);
70237+ mutex_lock(&mapping->i_mmap_mutex);
70238+ if (tmp->vm_flags & VM_SHARED)
70239+ mapping->i_mmap_writable++;
70240+ flush_dcache_mmap_lock(mapping);
70241+ /* insert tmp into the share list, just after mpnt */
70242+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
70243+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
70244+ else
70245+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
70246+ flush_dcache_mmap_unlock(mapping);
70247+ mutex_unlock(&mapping->i_mmap_mutex);
70248+ }
70249+
70250+ /*
70251+ * Clear hugetlb-related page reserves for children. This only
70252+ * affects MAP_PRIVATE mappings. Faults generated by the child
70253+ * are not guaranteed to succeed, even if read-only
70254+ */
70255+ if (is_vm_hugetlb_page(tmp))
70256+ reset_vma_resv_huge_pages(tmp);
70257+
70258+ return tmp;
70259+
70260+fail_nomem_anon_vma_fork:
70261+ mpol_put(pol);
70262+fail_nomem_policy:
70263+ kmem_cache_free(vm_area_cachep, tmp);
70264+fail_nomem:
70265+ vm_unacct_memory(charge);
70266+ return NULL;
70267+}
70268+
70269 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70270 {
70271 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
70272 struct rb_node **rb_link, *rb_parent;
70273 int retval;
70274- unsigned long charge;
70275- struct mempolicy *pol;
70276
70277 uprobe_start_dup_mmap();
70278 down_write(&oldmm->mmap_sem);
70279@@ -364,8 +432,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70280 mm->locked_vm = 0;
70281 mm->mmap = NULL;
70282 mm->mmap_cache = NULL;
70283- mm->free_area_cache = oldmm->mmap_base;
70284- mm->cached_hole_size = ~0UL;
70285+ mm->free_area_cache = oldmm->free_area_cache;
70286+ mm->cached_hole_size = oldmm->cached_hole_size;
70287 mm->map_count = 0;
70288 cpumask_clear(mm_cpumask(mm));
70289 mm->mm_rb = RB_ROOT;
70290@@ -381,57 +449,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70291
70292 prev = NULL;
70293 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
70294- struct file *file;
70295-
70296 if (mpnt->vm_flags & VM_DONTCOPY) {
70297 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
70298 -vma_pages(mpnt));
70299 continue;
70300 }
70301- charge = 0;
70302- if (mpnt->vm_flags & VM_ACCOUNT) {
70303- unsigned long len = vma_pages(mpnt);
70304-
70305- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
70306- goto fail_nomem;
70307- charge = len;
70308- }
70309- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
70310- if (!tmp)
70311- goto fail_nomem;
70312- *tmp = *mpnt;
70313- INIT_LIST_HEAD(&tmp->anon_vma_chain);
70314- pol = mpol_dup(vma_policy(mpnt));
70315- retval = PTR_ERR(pol);
70316- if (IS_ERR(pol))
70317- goto fail_nomem_policy;
70318- vma_set_policy(tmp, pol);
70319- tmp->vm_mm = mm;
70320- if (anon_vma_fork(tmp, mpnt))
70321- goto fail_nomem_anon_vma_fork;
70322- tmp->vm_flags &= ~VM_LOCKED;
70323- tmp->vm_next = tmp->vm_prev = NULL;
70324- file = tmp->vm_file;
70325- if (file) {
70326- struct inode *inode = file->f_path.dentry->d_inode;
70327- struct address_space *mapping = file->f_mapping;
70328-
70329- get_file(file);
70330- if (tmp->vm_flags & VM_DENYWRITE)
70331- atomic_dec(&inode->i_writecount);
70332- mutex_lock(&mapping->i_mmap_mutex);
70333- if (tmp->vm_flags & VM_SHARED)
70334- mapping->i_mmap_writable++;
70335- flush_dcache_mmap_lock(mapping);
70336- /* insert tmp into the share list, just after mpnt */
70337- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
70338- vma_nonlinear_insert(tmp,
70339- &mapping->i_mmap_nonlinear);
70340- else
70341- vma_interval_tree_insert_after(tmp, mpnt,
70342- &mapping->i_mmap);
70343- flush_dcache_mmap_unlock(mapping);
70344- mutex_unlock(&mapping->i_mmap_mutex);
70345+ tmp = dup_vma(mm, oldmm, mpnt);
70346+ if (!tmp) {
70347+ retval = -ENOMEM;
70348+ goto out;
70349 }
70350
70351 /*
70352@@ -463,6 +489,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70353 if (retval)
70354 goto out;
70355 }
70356+
70357+#ifdef CONFIG_PAX_SEGMEXEC
70358+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
70359+ struct vm_area_struct *mpnt_m;
70360+
70361+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
70362+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
70363+
70364+ if (!mpnt->vm_mirror)
70365+ continue;
70366+
70367+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
70368+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
70369+ mpnt->vm_mirror = mpnt_m;
70370+ } else {
70371+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
70372+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
70373+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
70374+ mpnt->vm_mirror->vm_mirror = mpnt;
70375+ }
70376+ }
70377+ BUG_ON(mpnt_m);
70378+ }
70379+#endif
70380+
70381 /* a new mm has just been created */
70382 arch_dup_mmap(oldmm, mm);
70383 retval = 0;
70384@@ -472,14 +523,6 @@ out:
70385 up_write(&oldmm->mmap_sem);
70386 uprobe_end_dup_mmap();
70387 return retval;
70388-fail_nomem_anon_vma_fork:
70389- mpol_put(pol);
70390-fail_nomem_policy:
70391- kmem_cache_free(vm_area_cachep, tmp);
70392-fail_nomem:
70393- retval = -ENOMEM;
70394- vm_unacct_memory(charge);
70395- goto out;
70396 }
70397
70398 static inline int mm_alloc_pgd(struct mm_struct *mm)
70399@@ -694,8 +737,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
70400 return ERR_PTR(err);
70401
70402 mm = get_task_mm(task);
70403- if (mm && mm != current->mm &&
70404- !ptrace_may_access(task, mode)) {
70405+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
70406+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
70407 mmput(mm);
70408 mm = ERR_PTR(-EACCES);
70409 }
70410@@ -917,13 +960,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
70411 spin_unlock(&fs->lock);
70412 return -EAGAIN;
70413 }
70414- fs->users++;
70415+ atomic_inc(&fs->users);
70416 spin_unlock(&fs->lock);
70417 return 0;
70418 }
70419 tsk->fs = copy_fs_struct(fs);
70420 if (!tsk->fs)
70421 return -ENOMEM;
70422+ /* Carry through gr_chroot_dentry and is_chrooted instead
70423+ of recomputing it here. Already copied when the task struct
70424+ is duplicated. This allows pivot_root to not be treated as
70425+ a chroot
70426+ */
70427+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
70428+
70429 return 0;
70430 }
70431
70432@@ -1193,6 +1243,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
70433 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
70434 #endif
70435 retval = -EAGAIN;
70436+
70437+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
70438+
70439 if (atomic_read(&p->real_cred->user->processes) >=
70440 task_rlimit(p, RLIMIT_NPROC)) {
70441 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
70442@@ -1432,6 +1485,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
70443 goto bad_fork_free_pid;
70444 }
70445
70446+ /* synchronizes with gr_set_acls()
70447+ we need to call this past the point of no return for fork()
70448+ */
70449+ gr_copy_label(p);
70450+
70451 if (clone_flags & CLONE_THREAD) {
70452 current->signal->nr_threads++;
70453 atomic_inc(&current->signal->live);
70454@@ -1515,6 +1573,8 @@ bad_fork_cleanup_count:
70455 bad_fork_free:
70456 free_task(p);
70457 fork_out:
70458+ gr_log_forkfail(retval);
70459+
70460 return ERR_PTR(retval);
70461 }
70462
70463@@ -1565,6 +1625,23 @@ long do_fork(unsigned long clone_flags,
70464 return -EINVAL;
70465 }
70466
70467+#ifdef CONFIG_GRKERNSEC
70468+ if (clone_flags & CLONE_NEWUSER) {
70469+ /*
70470+ * This doesn't really inspire confidence:
70471+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
70472+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
70473+ * Increases kernel attack surface in areas developers
70474+ * previously cared little about ("low importance due
70475+ * to requiring "root" capability")
70476+ * To be removed when this code receives *proper* review
70477+ */
70478+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
70479+ !capable(CAP_SETGID))
70480+ return -EPERM;
70481+ }
70482+#endif
70483+
70484 /*
70485 * Determine whether and which event to report to ptracer. When
70486 * called from kernel_thread or CLONE_UNTRACED is explicitly
70487@@ -1599,6 +1676,8 @@ long do_fork(unsigned long clone_flags,
70488 if (clone_flags & CLONE_PARENT_SETTID)
70489 put_user(nr, parent_tidptr);
70490
70491+ gr_handle_brute_check();
70492+
70493 if (clone_flags & CLONE_VFORK) {
70494 p->vfork_done = &vfork;
70495 init_completion(&vfork);
70496@@ -1752,7 +1831,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
70497 return 0;
70498
70499 /* don't need lock here; in the worst case we'll do useless copy */
70500- if (fs->users == 1)
70501+ if (atomic_read(&fs->users) == 1)
70502 return 0;
70503
70504 *new_fsp = copy_fs_struct(fs);
70505@@ -1866,7 +1945,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
70506 fs = current->fs;
70507 spin_lock(&fs->lock);
70508 current->fs = new_fs;
70509- if (--fs->users)
70510+ gr_set_chroot_entries(current, &current->fs->root);
70511+ if (atomic_dec_return(&fs->users))
70512 new_fs = NULL;
70513 else
70514 new_fs = fs;
70515diff --git a/kernel/futex.c b/kernel/futex.c
70516index 8879430..31696f1 100644
70517--- a/kernel/futex.c
70518+++ b/kernel/futex.c
70519@@ -54,6 +54,7 @@
70520 #include <linux/mount.h>
70521 #include <linux/pagemap.h>
70522 #include <linux/syscalls.h>
70523+#include <linux/ptrace.h>
70524 #include <linux/signal.h>
70525 #include <linux/export.h>
70526 #include <linux/magic.h>
70527@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
70528 struct page *page, *page_head;
70529 int err, ro = 0;
70530
70531+#ifdef CONFIG_PAX_SEGMEXEC
70532+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
70533+ return -EFAULT;
70534+#endif
70535+
70536 /*
70537 * The futex address must be "naturally" aligned.
70538 */
70539@@ -2731,6 +2737,7 @@ static int __init futex_init(void)
70540 {
70541 u32 curval;
70542 int i;
70543+ mm_segment_t oldfs;
70544
70545 /*
70546 * This will fail and we want it. Some arch implementations do
70547@@ -2742,8 +2749,11 @@ static int __init futex_init(void)
70548 * implementation, the non-functional ones will return
70549 * -ENOSYS.
70550 */
70551+ oldfs = get_fs();
70552+ set_fs(USER_DS);
70553 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
70554 futex_cmpxchg_enabled = 1;
70555+ set_fs(oldfs);
70556
70557 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
70558 plist_head_init(&futex_queues[i].chain);
70559diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
70560index 9b22d03..6295b62 100644
70561--- a/kernel/gcov/base.c
70562+++ b/kernel/gcov/base.c
70563@@ -102,11 +102,6 @@ void gcov_enable_events(void)
70564 }
70565
70566 #ifdef CONFIG_MODULES
70567-static inline int within(void *addr, void *start, unsigned long size)
70568-{
70569- return ((addr >= start) && (addr < start + size));
70570-}
70571-
70572 /* Update list and generate events when modules are unloaded. */
70573 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
70574 void *data)
70575@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
70576 prev = NULL;
70577 /* Remove entries located in module from linked list. */
70578 for (info = gcov_info_head; info; info = info->next) {
70579- if (within(info, mod->module_core, mod->core_size)) {
70580+ if (within_module_core_rw((unsigned long)info, mod)) {
70581 if (prev)
70582 prev->next = info->next;
70583 else
70584diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
70585index cdd5607..c3fc919 100644
70586--- a/kernel/hrtimer.c
70587+++ b/kernel/hrtimer.c
70588@@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
70589 local_irq_restore(flags);
70590 }
70591
70592-static void run_hrtimer_softirq(struct softirq_action *h)
70593+static void run_hrtimer_softirq(void)
70594 {
70595 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
70596
70597@@ -1751,7 +1751,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
70598 return NOTIFY_OK;
70599 }
70600
70601-static struct notifier_block __cpuinitdata hrtimers_nb = {
70602+static struct notifier_block hrtimers_nb = {
70603 .notifier_call = hrtimer_cpu_notify,
70604 };
70605
70606diff --git a/kernel/jump_label.c b/kernel/jump_label.c
70607index 60f48fa..7f3a770 100644
70608--- a/kernel/jump_label.c
70609+++ b/kernel/jump_label.c
70610@@ -13,6 +13,7 @@
70611 #include <linux/sort.h>
70612 #include <linux/err.h>
70613 #include <linux/static_key.h>
70614+#include <linux/mm.h>
70615
70616 #ifdef HAVE_JUMP_LABEL
70617
70618@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
70619
70620 size = (((unsigned long)stop - (unsigned long)start)
70621 / sizeof(struct jump_entry));
70622+ pax_open_kernel();
70623 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
70624+ pax_close_kernel();
70625 }
70626
70627 static void jump_label_update(struct static_key *key, int enable);
70628@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
70629 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
70630 struct jump_entry *iter;
70631
70632+ pax_open_kernel();
70633 for (iter = iter_start; iter < iter_stop; iter++) {
70634 if (within_module_init(iter->code, mod))
70635 iter->code = 0;
70636 }
70637+ pax_close_kernel();
70638 }
70639
70640 static int
70641diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
70642index 2169fee..45c017a 100644
70643--- a/kernel/kallsyms.c
70644+++ b/kernel/kallsyms.c
70645@@ -11,6 +11,9 @@
70646 * Changed the compression method from stem compression to "table lookup"
70647 * compression (see scripts/kallsyms.c for a more complete description)
70648 */
70649+#ifdef CONFIG_GRKERNSEC_HIDESYM
70650+#define __INCLUDED_BY_HIDESYM 1
70651+#endif
70652 #include <linux/kallsyms.h>
70653 #include <linux/module.h>
70654 #include <linux/init.h>
70655@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
70656
70657 static inline int is_kernel_inittext(unsigned long addr)
70658 {
70659+ if (system_state != SYSTEM_BOOTING)
70660+ return 0;
70661+
70662 if (addr >= (unsigned long)_sinittext
70663 && addr <= (unsigned long)_einittext)
70664 return 1;
70665 return 0;
70666 }
70667
70668+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
70669+#ifdef CONFIG_MODULES
70670+static inline int is_module_text(unsigned long addr)
70671+{
70672+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
70673+ return 1;
70674+
70675+ addr = ktla_ktva(addr);
70676+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
70677+}
70678+#else
70679+static inline int is_module_text(unsigned long addr)
70680+{
70681+ return 0;
70682+}
70683+#endif
70684+#endif
70685+
70686 static inline int is_kernel_text(unsigned long addr)
70687 {
70688 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
70689@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
70690
70691 static inline int is_kernel(unsigned long addr)
70692 {
70693+
70694+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
70695+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
70696+ return 1;
70697+
70698+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
70699+#else
70700 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
70701+#endif
70702+
70703 return 1;
70704 return in_gate_area_no_mm(addr);
70705 }
70706
70707 static int is_ksym_addr(unsigned long addr)
70708 {
70709+
70710+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
70711+ if (is_module_text(addr))
70712+ return 0;
70713+#endif
70714+
70715 if (all_var)
70716 return is_kernel(addr);
70717
70718@@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
70719
70720 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
70721 {
70722- iter->name[0] = '\0';
70723 iter->nameoff = get_symbol_offset(new_pos);
70724 iter->pos = new_pos;
70725 }
70726@@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
70727 {
70728 struct kallsym_iter *iter = m->private;
70729
70730+#ifdef CONFIG_GRKERNSEC_HIDESYM
70731+ if (current_uid())
70732+ return 0;
70733+#endif
70734+
70735 /* Some debugging symbols have no name. Ignore them. */
70736 if (!iter->name[0])
70737 return 0;
70738@@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
70739 */
70740 type = iter->exported ? toupper(iter->type) :
70741 tolower(iter->type);
70742+
70743 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
70744 type, iter->name, iter->module_name);
70745 } else
70746@@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
70747 struct kallsym_iter *iter;
70748 int ret;
70749
70750- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
70751+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
70752 if (!iter)
70753 return -ENOMEM;
70754 reset_iter(iter, 0);
70755diff --git a/kernel/kcmp.c b/kernel/kcmp.c
70756index e30ac0f..3528cac 100644
70757--- a/kernel/kcmp.c
70758+++ b/kernel/kcmp.c
70759@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
70760 struct task_struct *task1, *task2;
70761 int ret;
70762
70763+#ifdef CONFIG_GRKERNSEC
70764+ return -ENOSYS;
70765+#endif
70766+
70767 rcu_read_lock();
70768
70769 /*
70770diff --git a/kernel/kexec.c b/kernel/kexec.c
70771index 5e4bd78..00c5b91 100644
70772--- a/kernel/kexec.c
70773+++ b/kernel/kexec.c
70774@@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
70775 unsigned long flags)
70776 {
70777 struct compat_kexec_segment in;
70778- struct kexec_segment out, __user *ksegments;
70779+ struct kexec_segment out;
70780+ struct kexec_segment __user *ksegments;
70781 unsigned long i, result;
70782
70783 /* Don't allow clients that don't understand the native
70784diff --git a/kernel/kmod.c b/kernel/kmod.c
70785index 0023a87..3fe3781 100644
70786--- a/kernel/kmod.c
70787+++ b/kernel/kmod.c
70788@@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
70789 kfree(info->argv);
70790 }
70791
70792-static int call_modprobe(char *module_name, int wait)
70793+static int call_modprobe(char *module_name, char *module_param, int wait)
70794 {
70795 static char *envp[] = {
70796 "HOME=/",
70797@@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
70798 NULL
70799 };
70800
70801- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
70802+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
70803 if (!argv)
70804 goto out;
70805
70806@@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
70807 argv[1] = "-q";
70808 argv[2] = "--";
70809 argv[3] = module_name; /* check free_modprobe_argv() */
70810- argv[4] = NULL;
70811+ argv[4] = module_param;
70812+ argv[5] = NULL;
70813
70814 return call_usermodehelper_fns(modprobe_path, argv, envp,
70815 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
70816@@ -120,9 +121,8 @@ out:
70817 * If module auto-loading support is disabled then this function
70818 * becomes a no-operation.
70819 */
70820-int __request_module(bool wait, const char *fmt, ...)
70821+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
70822 {
70823- va_list args;
70824 char module_name[MODULE_NAME_LEN];
70825 unsigned int max_modprobes;
70826 int ret;
70827@@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
70828 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
70829 static int kmod_loop_msg;
70830
70831- va_start(args, fmt);
70832- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
70833- va_end(args);
70834+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
70835 if (ret >= MODULE_NAME_LEN)
70836 return -ENAMETOOLONG;
70837
70838@@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
70839 if (ret)
70840 return ret;
70841
70842+#ifdef CONFIG_GRKERNSEC_MODHARDEN
70843+ if (!current_uid()) {
70844+ /* hack to workaround consolekit/udisks stupidity */
70845+ read_lock(&tasklist_lock);
70846+ if (!strcmp(current->comm, "mount") &&
70847+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
70848+ read_unlock(&tasklist_lock);
70849+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
70850+ return -EPERM;
70851+ }
70852+ read_unlock(&tasklist_lock);
70853+ }
70854+#endif
70855+
70856 /* If modprobe needs a service that is in a module, we get a recursive
70857 * loop. Limit the number of running kmod threads to max_threads/2 or
70858 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
70859@@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
70860
70861 trace_module_request(module_name, wait, _RET_IP_);
70862
70863- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
70864+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
70865
70866 atomic_dec(&kmod_concurrent);
70867 return ret;
70868 }
70869+
70870+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
70871+{
70872+ va_list args;
70873+ int ret;
70874+
70875+ va_start(args, fmt);
70876+ ret = ____request_module(wait, module_param, fmt, args);
70877+ va_end(args);
70878+
70879+ return ret;
70880+}
70881+
70882+int __request_module(bool wait, const char *fmt, ...)
70883+{
70884+ va_list args;
70885+ int ret;
70886+
70887+#ifdef CONFIG_GRKERNSEC_MODHARDEN
70888+ if (current_uid()) {
70889+ char module_param[MODULE_NAME_LEN];
70890+
70891+ memset(module_param, 0, sizeof(module_param));
70892+
70893+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
70894+
70895+ va_start(args, fmt);
70896+ ret = ____request_module(wait, module_param, fmt, args);
70897+ va_end(args);
70898+
70899+ return ret;
70900+ }
70901+#endif
70902+
70903+ va_start(args, fmt);
70904+ ret = ____request_module(wait, NULL, fmt, args);
70905+ va_end(args);
70906+
70907+ return ret;
70908+}
70909+
70910 EXPORT_SYMBOL(__request_module);
70911 #endif /* CONFIG_MODULES */
70912
70913@@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
70914 *
70915 * Thus the __user pointer cast is valid here.
70916 */
70917- sys_wait4(pid, (int __user *)&ret, 0, NULL);
70918+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
70919
70920 /*
70921 * If ret is 0, either ____call_usermodehelper failed and the
70922diff --git a/kernel/kprobes.c b/kernel/kprobes.c
70923index 098f396..fe85ff1 100644
70924--- a/kernel/kprobes.c
70925+++ b/kernel/kprobes.c
70926@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
70927 * kernel image and loaded module images reside. This is required
70928 * so x86_64 can correctly handle the %rip-relative fixups.
70929 */
70930- kip->insns = module_alloc(PAGE_SIZE);
70931+ kip->insns = module_alloc_exec(PAGE_SIZE);
70932 if (!kip->insns) {
70933 kfree(kip);
70934 return NULL;
70935@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
70936 */
70937 if (!list_is_singular(&kip->list)) {
70938 list_del(&kip->list);
70939- module_free(NULL, kip->insns);
70940+ module_free_exec(NULL, kip->insns);
70941 kfree(kip);
70942 }
70943 return 1;
70944@@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
70945 {
70946 int i, err = 0;
70947 unsigned long offset = 0, size = 0;
70948- char *modname, namebuf[128];
70949+ char *modname, namebuf[KSYM_NAME_LEN];
70950 const char *symbol_name;
70951 void *addr;
70952 struct kprobe_blackpoint *kb;
70953@@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
70954 kprobe_type = "k";
70955
70956 if (sym)
70957- seq_printf(pi, "%p %s %s+0x%x %s ",
70958+ seq_printf(pi, "%pK %s %s+0x%x %s ",
70959 p->addr, kprobe_type, sym, offset,
70960 (modname ? modname : " "));
70961 else
70962- seq_printf(pi, "%p %s %p ",
70963+ seq_printf(pi, "%pK %s %pK ",
70964 p->addr, kprobe_type, p->addr);
70965
70966 if (!pp)
70967@@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
70968 const char *sym = NULL;
70969 unsigned int i = *(loff_t *) v;
70970 unsigned long offset = 0;
70971- char *modname, namebuf[128];
70972+ char *modname, namebuf[KSYM_NAME_LEN];
70973
70974 head = &kprobe_table[i];
70975 preempt_disable();
70976diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
70977index 6ada93c..55baf4d 100644
70978--- a/kernel/ksysfs.c
70979+++ b/kernel/ksysfs.c
70980@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
70981 {
70982 if (count+1 > UEVENT_HELPER_PATH_LEN)
70983 return -ENOENT;
70984+ if (!capable(CAP_SYS_ADMIN))
70985+ return -EPERM;
70986 memcpy(uevent_helper, buf, count);
70987 uevent_helper[count] = '\0';
70988 if (count && uevent_helper[count-1] == '\n')
70989diff --git a/kernel/lockdep.c b/kernel/lockdep.c
70990index 7981e5b..7f2105c 100644
70991--- a/kernel/lockdep.c
70992+++ b/kernel/lockdep.c
70993@@ -590,6 +590,10 @@ static int static_obj(void *obj)
70994 end = (unsigned long) &_end,
70995 addr = (unsigned long) obj;
70996
70997+#ifdef CONFIG_PAX_KERNEXEC
70998+ start = ktla_ktva(start);
70999+#endif
71000+
71001 /*
71002 * static variable?
71003 */
71004@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
71005 if (!static_obj(lock->key)) {
71006 debug_locks_off();
71007 printk("INFO: trying to register non-static key.\n");
71008+ printk("lock:%pS key:%pS.\n", lock, lock->key);
71009 printk("the code is fine but needs lockdep annotation.\n");
71010 printk("turning off the locking correctness validator.\n");
71011 dump_stack();
71012@@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
71013 if (!class)
71014 return 0;
71015 }
71016- atomic_inc((atomic_t *)&class->ops);
71017+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
71018 if (very_verbose(class)) {
71019 printk("\nacquire class [%p] %s", class->key, class->name);
71020 if (class->name_version > 1)
71021diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
71022index b2c71c5..7b88d63 100644
71023--- a/kernel/lockdep_proc.c
71024+++ b/kernel/lockdep_proc.c
71025@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
71026 return 0;
71027 }
71028
71029- seq_printf(m, "%p", class->key);
71030+ seq_printf(m, "%pK", class->key);
71031 #ifdef CONFIG_DEBUG_LOCKDEP
71032 seq_printf(m, " OPS:%8ld", class->ops);
71033 #endif
71034@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
71035
71036 list_for_each_entry(entry, &class->locks_after, entry) {
71037 if (entry->distance == 1) {
71038- seq_printf(m, " -> [%p] ", entry->class->key);
71039+ seq_printf(m, " -> [%pK] ", entry->class->key);
71040 print_name(m, entry->class);
71041 seq_puts(m, "\n");
71042 }
71043@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
71044 if (!class->key)
71045 continue;
71046
71047- seq_printf(m, "[%p] ", class->key);
71048+ seq_printf(m, "[%pK] ", class->key);
71049 print_name(m, class);
71050 seq_puts(m, "\n");
71051 }
71052@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
71053 if (!i)
71054 seq_line(m, '-', 40-namelen, namelen);
71055
71056- snprintf(ip, sizeof(ip), "[<%p>]",
71057+ snprintf(ip, sizeof(ip), "[<%pK>]",
71058 (void *)class->contention_point[i]);
71059 seq_printf(m, "%40s %14lu %29s %pS\n",
71060 name, stats->contention_point[i],
71061@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
71062 if (!i)
71063 seq_line(m, '-', 40-namelen, namelen);
71064
71065- snprintf(ip, sizeof(ip), "[<%p>]",
71066+ snprintf(ip, sizeof(ip), "[<%pK>]",
71067 (void *)class->contending_point[i]);
71068 seq_printf(m, "%40s %14lu %29s %pS\n",
71069 name, stats->contending_point[i],
71070diff --git a/kernel/module.c b/kernel/module.c
71071index eab0827..75ede66 100644
71072--- a/kernel/module.c
71073+++ b/kernel/module.c
71074@@ -61,6 +61,7 @@
71075 #include <linux/pfn.h>
71076 #include <linux/bsearch.h>
71077 #include <linux/fips.h>
71078+#include <linux/grsecurity.h>
71079 #include <uapi/linux/module.h>
71080 #include "module-internal.h"
71081
71082@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
71083
71084 /* Bounds of module allocation, for speeding __module_address.
71085 * Protected by module_mutex. */
71086-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
71087+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
71088+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
71089
71090 int register_module_notifier(struct notifier_block * nb)
71091 {
71092@@ -322,7 +324,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
71093 return true;
71094
71095 list_for_each_entry_rcu(mod, &modules, list) {
71096- struct symsearch arr[] = {
71097+ struct symsearch modarr[] = {
71098 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
71099 NOT_GPL_ONLY, false },
71100 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
71101@@ -347,7 +349,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
71102 if (mod->state == MODULE_STATE_UNFORMED)
71103 continue;
71104
71105- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
71106+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
71107 return true;
71108 }
71109 return false;
71110@@ -484,7 +486,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
71111 static int percpu_modalloc(struct module *mod,
71112 unsigned long size, unsigned long align)
71113 {
71114- if (align > PAGE_SIZE) {
71115+ if (align-1 >= PAGE_SIZE) {
71116 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
71117 mod->name, align, PAGE_SIZE);
71118 align = PAGE_SIZE;
71119@@ -1088,7 +1090,7 @@ struct module_attribute module_uevent =
71120 static ssize_t show_coresize(struct module_attribute *mattr,
71121 struct module_kobject *mk, char *buffer)
71122 {
71123- return sprintf(buffer, "%u\n", mk->mod->core_size);
71124+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
71125 }
71126
71127 static struct module_attribute modinfo_coresize =
71128@@ -1097,7 +1099,7 @@ static struct module_attribute modinfo_coresize =
71129 static ssize_t show_initsize(struct module_attribute *mattr,
71130 struct module_kobject *mk, char *buffer)
71131 {
71132- return sprintf(buffer, "%u\n", mk->mod->init_size);
71133+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
71134 }
71135
71136 static struct module_attribute modinfo_initsize =
71137@@ -1311,7 +1313,7 @@ resolve_symbol_wait(struct module *mod,
71138 */
71139 #ifdef CONFIG_SYSFS
71140
71141-#ifdef CONFIG_KALLSYMS
71142+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
71143 static inline bool sect_empty(const Elf_Shdr *sect)
71144 {
71145 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
71146@@ -1777,21 +1779,21 @@ static void set_section_ro_nx(void *base,
71147
71148 static void unset_module_core_ro_nx(struct module *mod)
71149 {
71150- set_page_attributes(mod->module_core + mod->core_text_size,
71151- mod->module_core + mod->core_size,
71152+ set_page_attributes(mod->module_core_rw,
71153+ mod->module_core_rw + mod->core_size_rw,
71154 set_memory_x);
71155- set_page_attributes(mod->module_core,
71156- mod->module_core + mod->core_ro_size,
71157+ set_page_attributes(mod->module_core_rx,
71158+ mod->module_core_rx + mod->core_size_rx,
71159 set_memory_rw);
71160 }
71161
71162 static void unset_module_init_ro_nx(struct module *mod)
71163 {
71164- set_page_attributes(mod->module_init + mod->init_text_size,
71165- mod->module_init + mod->init_size,
71166+ set_page_attributes(mod->module_init_rw,
71167+ mod->module_init_rw + mod->init_size_rw,
71168 set_memory_x);
71169- set_page_attributes(mod->module_init,
71170- mod->module_init + mod->init_ro_size,
71171+ set_page_attributes(mod->module_init_rx,
71172+ mod->module_init_rx + mod->init_size_rx,
71173 set_memory_rw);
71174 }
71175
71176@@ -1804,14 +1806,14 @@ void set_all_modules_text_rw(void)
71177 list_for_each_entry_rcu(mod, &modules, list) {
71178 if (mod->state == MODULE_STATE_UNFORMED)
71179 continue;
71180- if ((mod->module_core) && (mod->core_text_size)) {
71181- set_page_attributes(mod->module_core,
71182- mod->module_core + mod->core_text_size,
71183+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
71184+ set_page_attributes(mod->module_core_rx,
71185+ mod->module_core_rx + mod->core_size_rx,
71186 set_memory_rw);
71187 }
71188- if ((mod->module_init) && (mod->init_text_size)) {
71189- set_page_attributes(mod->module_init,
71190- mod->module_init + mod->init_text_size,
71191+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
71192+ set_page_attributes(mod->module_init_rx,
71193+ mod->module_init_rx + mod->init_size_rx,
71194 set_memory_rw);
71195 }
71196 }
71197@@ -1827,14 +1829,14 @@ void set_all_modules_text_ro(void)
71198 list_for_each_entry_rcu(mod, &modules, list) {
71199 if (mod->state == MODULE_STATE_UNFORMED)
71200 continue;
71201- if ((mod->module_core) && (mod->core_text_size)) {
71202- set_page_attributes(mod->module_core,
71203- mod->module_core + mod->core_text_size,
71204+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
71205+ set_page_attributes(mod->module_core_rx,
71206+ mod->module_core_rx + mod->core_size_rx,
71207 set_memory_ro);
71208 }
71209- if ((mod->module_init) && (mod->init_text_size)) {
71210- set_page_attributes(mod->module_init,
71211- mod->module_init + mod->init_text_size,
71212+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
71213+ set_page_attributes(mod->module_init_rx,
71214+ mod->module_init_rx + mod->init_size_rx,
71215 set_memory_ro);
71216 }
71217 }
71218@@ -1880,16 +1882,19 @@ static void free_module(struct module *mod)
71219
71220 /* This may be NULL, but that's OK */
71221 unset_module_init_ro_nx(mod);
71222- module_free(mod, mod->module_init);
71223+ module_free(mod, mod->module_init_rw);
71224+ module_free_exec(mod, mod->module_init_rx);
71225 kfree(mod->args);
71226 percpu_modfree(mod);
71227
71228 /* Free lock-classes: */
71229- lockdep_free_key_range(mod->module_core, mod->core_size);
71230+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
71231+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
71232
71233 /* Finally, free the core (containing the module structure) */
71234 unset_module_core_ro_nx(mod);
71235- module_free(mod, mod->module_core);
71236+ module_free_exec(mod, mod->module_core_rx);
71237+ module_free(mod, mod->module_core_rw);
71238
71239 #ifdef CONFIG_MPU
71240 update_protections(current->mm);
71241@@ -1959,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
71242 int ret = 0;
71243 const struct kernel_symbol *ksym;
71244
71245+#ifdef CONFIG_GRKERNSEC_MODHARDEN
71246+ int is_fs_load = 0;
71247+ int register_filesystem_found = 0;
71248+ char *p;
71249+
71250+ p = strstr(mod->args, "grsec_modharden_fs");
71251+ if (p) {
71252+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
71253+ /* copy \0 as well */
71254+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
71255+ is_fs_load = 1;
71256+ }
71257+#endif
71258+
71259 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
71260 const char *name = info->strtab + sym[i].st_name;
71261
71262+#ifdef CONFIG_GRKERNSEC_MODHARDEN
71263+ /* it's a real shame this will never get ripped and copied
71264+ upstream! ;(
71265+ */
71266+ if (is_fs_load && !strcmp(name, "register_filesystem"))
71267+ register_filesystem_found = 1;
71268+#endif
71269+
71270 switch (sym[i].st_shndx) {
71271 case SHN_COMMON:
71272 /* We compiled with -fno-common. These are not
71273@@ -1982,7 +2009,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
71274 ksym = resolve_symbol_wait(mod, info, name);
71275 /* Ok if resolved. */
71276 if (ksym && !IS_ERR(ksym)) {
71277+ pax_open_kernel();
71278 sym[i].st_value = ksym->value;
71279+ pax_close_kernel();
71280 break;
71281 }
71282
71283@@ -2001,11 +2030,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
71284 secbase = (unsigned long)mod_percpu(mod);
71285 else
71286 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
71287+ pax_open_kernel();
71288 sym[i].st_value += secbase;
71289+ pax_close_kernel();
71290 break;
71291 }
71292 }
71293
71294+#ifdef CONFIG_GRKERNSEC_MODHARDEN
71295+ if (is_fs_load && !register_filesystem_found) {
71296+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
71297+ ret = -EPERM;
71298+ }
71299+#endif
71300+
71301 return ret;
71302 }
71303
71304@@ -2089,22 +2127,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
71305 || s->sh_entsize != ~0UL
71306 || strstarts(sname, ".init"))
71307 continue;
71308- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
71309+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
71310+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
71311+ else
71312+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
71313 pr_debug("\t%s\n", sname);
71314 }
71315- switch (m) {
71316- case 0: /* executable */
71317- mod->core_size = debug_align(mod->core_size);
71318- mod->core_text_size = mod->core_size;
71319- break;
71320- case 1: /* RO: text and ro-data */
71321- mod->core_size = debug_align(mod->core_size);
71322- mod->core_ro_size = mod->core_size;
71323- break;
71324- case 3: /* whole core */
71325- mod->core_size = debug_align(mod->core_size);
71326- break;
71327- }
71328 }
71329
71330 pr_debug("Init section allocation order:\n");
71331@@ -2118,23 +2146,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
71332 || s->sh_entsize != ~0UL
71333 || !strstarts(sname, ".init"))
71334 continue;
71335- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
71336- | INIT_OFFSET_MASK);
71337+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
71338+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
71339+ else
71340+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
71341+ s->sh_entsize |= INIT_OFFSET_MASK;
71342 pr_debug("\t%s\n", sname);
71343 }
71344- switch (m) {
71345- case 0: /* executable */
71346- mod->init_size = debug_align(mod->init_size);
71347- mod->init_text_size = mod->init_size;
71348- break;
71349- case 1: /* RO: text and ro-data */
71350- mod->init_size = debug_align(mod->init_size);
71351- mod->init_ro_size = mod->init_size;
71352- break;
71353- case 3: /* whole init */
71354- mod->init_size = debug_align(mod->init_size);
71355- break;
71356- }
71357 }
71358 }
71359
71360@@ -2306,7 +2324,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
71361
71362 /* Put symbol section at end of init part of module. */
71363 symsect->sh_flags |= SHF_ALLOC;
71364- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
71365+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
71366 info->index.sym) | INIT_OFFSET_MASK;
71367 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
71368
71369@@ -2323,13 +2341,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
71370 }
71371
71372 /* Append room for core symbols at end of core part. */
71373- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
71374- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
71375- mod->core_size += strtab_size;
71376+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
71377+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
71378+ mod->core_size_rx += strtab_size;
71379
71380 /* Put string table section at end of init part of module. */
71381 strsect->sh_flags |= SHF_ALLOC;
71382- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
71383+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
71384 info->index.str) | INIT_OFFSET_MASK;
71385 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
71386 }
71387@@ -2347,12 +2365,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
71388 /* Make sure we get permanent strtab: don't use info->strtab. */
71389 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
71390
71391+ pax_open_kernel();
71392+
71393 /* Set types up while we still have access to sections. */
71394 for (i = 0; i < mod->num_symtab; i++)
71395 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
71396
71397- mod->core_symtab = dst = mod->module_core + info->symoffs;
71398- mod->core_strtab = s = mod->module_core + info->stroffs;
71399+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
71400+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
71401 src = mod->symtab;
71402 for (ndst = i = 0; i < mod->num_symtab; i++) {
71403 if (i == 0 ||
71404@@ -2364,6 +2384,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
71405 }
71406 }
71407 mod->core_num_syms = ndst;
71408+
71409+ pax_close_kernel();
71410 }
71411 #else
71412 static inline void layout_symtab(struct module *mod, struct load_info *info)
71413@@ -2397,17 +2419,33 @@ void * __weak module_alloc(unsigned long size)
71414 return vmalloc_exec(size);
71415 }
71416
71417-static void *module_alloc_update_bounds(unsigned long size)
71418+static void *module_alloc_update_bounds_rw(unsigned long size)
71419 {
71420 void *ret = module_alloc(size);
71421
71422 if (ret) {
71423 mutex_lock(&module_mutex);
71424 /* Update module bounds. */
71425- if ((unsigned long)ret < module_addr_min)
71426- module_addr_min = (unsigned long)ret;
71427- if ((unsigned long)ret + size > module_addr_max)
71428- module_addr_max = (unsigned long)ret + size;
71429+ if ((unsigned long)ret < module_addr_min_rw)
71430+ module_addr_min_rw = (unsigned long)ret;
71431+ if ((unsigned long)ret + size > module_addr_max_rw)
71432+ module_addr_max_rw = (unsigned long)ret + size;
71433+ mutex_unlock(&module_mutex);
71434+ }
71435+ return ret;
71436+}
71437+
71438+static void *module_alloc_update_bounds_rx(unsigned long size)
71439+{
71440+ void *ret = module_alloc_exec(size);
71441+
71442+ if (ret) {
71443+ mutex_lock(&module_mutex);
71444+ /* Update module bounds. */
71445+ if ((unsigned long)ret < module_addr_min_rx)
71446+ module_addr_min_rx = (unsigned long)ret;
71447+ if ((unsigned long)ret + size > module_addr_max_rx)
71448+ module_addr_max_rx = (unsigned long)ret + size;
71449 mutex_unlock(&module_mutex);
71450 }
71451 return ret;
71452@@ -2683,8 +2721,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
71453 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
71454 {
71455 const char *modmagic = get_modinfo(info, "vermagic");
71456+ const char *license = get_modinfo(info, "license");
71457 int err;
71458
71459+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
71460+ if (!license || !license_is_gpl_compatible(license))
71461+ return -ENOEXEC;
71462+#endif
71463+
71464 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
71465 modmagic = NULL;
71466
71467@@ -2710,7 +2754,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
71468 }
71469
71470 /* Set up license info based on the info section */
71471- set_license(mod, get_modinfo(info, "license"));
71472+ set_license(mod, license);
71473
71474 return 0;
71475 }
71476@@ -2804,7 +2848,7 @@ static int move_module(struct module *mod, struct load_info *info)
71477 void *ptr;
71478
71479 /* Do the allocs. */
71480- ptr = module_alloc_update_bounds(mod->core_size);
71481+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
71482 /*
71483 * The pointer to this block is stored in the module structure
71484 * which is inside the block. Just mark it as not being a
71485@@ -2814,11 +2858,11 @@ static int move_module(struct module *mod, struct load_info *info)
71486 if (!ptr)
71487 return -ENOMEM;
71488
71489- memset(ptr, 0, mod->core_size);
71490- mod->module_core = ptr;
71491+ memset(ptr, 0, mod->core_size_rw);
71492+ mod->module_core_rw = ptr;
71493
71494- if (mod->init_size) {
71495- ptr = module_alloc_update_bounds(mod->init_size);
71496+ if (mod->init_size_rw) {
71497+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
71498 /*
71499 * The pointer to this block is stored in the module structure
71500 * which is inside the block. This block doesn't need to be
71501@@ -2827,13 +2871,45 @@ static int move_module(struct module *mod, struct load_info *info)
71502 */
71503 kmemleak_ignore(ptr);
71504 if (!ptr) {
71505- module_free(mod, mod->module_core);
71506+ module_free(mod, mod->module_core_rw);
71507 return -ENOMEM;
71508 }
71509- memset(ptr, 0, mod->init_size);
71510- mod->module_init = ptr;
71511+ memset(ptr, 0, mod->init_size_rw);
71512+ mod->module_init_rw = ptr;
71513 } else
71514- mod->module_init = NULL;
71515+ mod->module_init_rw = NULL;
71516+
71517+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
71518+ kmemleak_not_leak(ptr);
71519+ if (!ptr) {
71520+ if (mod->module_init_rw)
71521+ module_free(mod, mod->module_init_rw);
71522+ module_free(mod, mod->module_core_rw);
71523+ return -ENOMEM;
71524+ }
71525+
71526+ pax_open_kernel();
71527+ memset(ptr, 0, mod->core_size_rx);
71528+ pax_close_kernel();
71529+ mod->module_core_rx = ptr;
71530+
71531+ if (mod->init_size_rx) {
71532+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
71533+ kmemleak_ignore(ptr);
71534+ if (!ptr && mod->init_size_rx) {
71535+ module_free_exec(mod, mod->module_core_rx);
71536+ if (mod->module_init_rw)
71537+ module_free(mod, mod->module_init_rw);
71538+ module_free(mod, mod->module_core_rw);
71539+ return -ENOMEM;
71540+ }
71541+
71542+ pax_open_kernel();
71543+ memset(ptr, 0, mod->init_size_rx);
71544+ pax_close_kernel();
71545+ mod->module_init_rx = ptr;
71546+ } else
71547+ mod->module_init_rx = NULL;
71548
71549 /* Transfer each section which specifies SHF_ALLOC */
71550 pr_debug("final section addresses:\n");
71551@@ -2844,16 +2920,45 @@ static int move_module(struct module *mod, struct load_info *info)
71552 if (!(shdr->sh_flags & SHF_ALLOC))
71553 continue;
71554
71555- if (shdr->sh_entsize & INIT_OFFSET_MASK)
71556- dest = mod->module_init
71557- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
71558- else
71559- dest = mod->module_core + shdr->sh_entsize;
71560+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
71561+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
71562+ dest = mod->module_init_rw
71563+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
71564+ else
71565+ dest = mod->module_init_rx
71566+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
71567+ } else {
71568+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
71569+ dest = mod->module_core_rw + shdr->sh_entsize;
71570+ else
71571+ dest = mod->module_core_rx + shdr->sh_entsize;
71572+ }
71573+
71574+ if (shdr->sh_type != SHT_NOBITS) {
71575+
71576+#ifdef CONFIG_PAX_KERNEXEC
71577+#ifdef CONFIG_X86_64
71578+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
71579+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
71580+#endif
71581+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
71582+ pax_open_kernel();
71583+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
71584+ pax_close_kernel();
71585+ } else
71586+#endif
71587
71588- if (shdr->sh_type != SHT_NOBITS)
71589 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
71590+ }
71591 /* Update sh_addr to point to copy in image. */
71592- shdr->sh_addr = (unsigned long)dest;
71593+
71594+#ifdef CONFIG_PAX_KERNEXEC
71595+ if (shdr->sh_flags & SHF_EXECINSTR)
71596+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
71597+ else
71598+#endif
71599+
71600+ shdr->sh_addr = (unsigned long)dest;
71601 pr_debug("\t0x%lx %s\n",
71602 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
71603 }
71604@@ -2908,12 +3013,12 @@ static void flush_module_icache(const struct module *mod)
71605 * Do it before processing of module parameters, so the module
71606 * can provide parameter accessor functions of its own.
71607 */
71608- if (mod->module_init)
71609- flush_icache_range((unsigned long)mod->module_init,
71610- (unsigned long)mod->module_init
71611- + mod->init_size);
71612- flush_icache_range((unsigned long)mod->module_core,
71613- (unsigned long)mod->module_core + mod->core_size);
71614+ if (mod->module_init_rx)
71615+ flush_icache_range((unsigned long)mod->module_init_rx,
71616+ (unsigned long)mod->module_init_rx
71617+ + mod->init_size_rx);
71618+ flush_icache_range((unsigned long)mod->module_core_rx,
71619+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
71620
71621 set_fs(old_fs);
71622 }
71623@@ -2983,8 +3088,10 @@ out:
71624 static void module_deallocate(struct module *mod, struct load_info *info)
71625 {
71626 percpu_modfree(mod);
71627- module_free(mod, mod->module_init);
71628- module_free(mod, mod->module_core);
71629+ module_free_exec(mod, mod->module_init_rx);
71630+ module_free_exec(mod, mod->module_core_rx);
71631+ module_free(mod, mod->module_init_rw);
71632+ module_free(mod, mod->module_core_rw);
71633 }
71634
71635 int __weak module_finalize(const Elf_Ehdr *hdr,
71636@@ -2997,7 +3104,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
71637 static int post_relocation(struct module *mod, const struct load_info *info)
71638 {
71639 /* Sort exception table now relocations are done. */
71640+ pax_open_kernel();
71641 sort_extable(mod->extable, mod->extable + mod->num_exentries);
71642+ pax_close_kernel();
71643
71644 /* Copy relocated percpu area over. */
71645 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
71646@@ -3051,16 +3160,16 @@ static int do_init_module(struct module *mod)
71647 MODULE_STATE_COMING, mod);
71648
71649 /* Set RO and NX regions for core */
71650- set_section_ro_nx(mod->module_core,
71651- mod->core_text_size,
71652- mod->core_ro_size,
71653- mod->core_size);
71654+ set_section_ro_nx(mod->module_core_rx,
71655+ mod->core_size_rx,
71656+ mod->core_size_rx,
71657+ mod->core_size_rx);
71658
71659 /* Set RO and NX regions for init */
71660- set_section_ro_nx(mod->module_init,
71661- mod->init_text_size,
71662- mod->init_ro_size,
71663- mod->init_size);
71664+ set_section_ro_nx(mod->module_init_rx,
71665+ mod->init_size_rx,
71666+ mod->init_size_rx,
71667+ mod->init_size_rx);
71668
71669 do_mod_ctors(mod);
71670 /* Start the module */
71671@@ -3122,11 +3231,12 @@ static int do_init_module(struct module *mod)
71672 mod->strtab = mod->core_strtab;
71673 #endif
71674 unset_module_init_ro_nx(mod);
71675- module_free(mod, mod->module_init);
71676- mod->module_init = NULL;
71677- mod->init_size = 0;
71678- mod->init_ro_size = 0;
71679- mod->init_text_size = 0;
71680+ module_free(mod, mod->module_init_rw);
71681+ module_free_exec(mod, mod->module_init_rx);
71682+ mod->module_init_rw = NULL;
71683+ mod->module_init_rx = NULL;
71684+ mod->init_size_rw = 0;
71685+ mod->init_size_rx = 0;
71686 mutex_unlock(&module_mutex);
71687 wake_up_all(&module_wq);
71688
71689@@ -3209,9 +3319,38 @@ again:
71690 if (err)
71691 goto free_unload;
71692
71693+ /* Now copy in args */
71694+ mod->args = strndup_user(uargs, ~0UL >> 1);
71695+ if (IS_ERR(mod->args)) {
71696+ err = PTR_ERR(mod->args);
71697+ goto free_unload;
71698+ }
71699+
71700 /* Set up MODINFO_ATTR fields */
71701 setup_modinfo(mod, info);
71702
71703+#ifdef CONFIG_GRKERNSEC_MODHARDEN
71704+ {
71705+ char *p, *p2;
71706+
71707+ if (strstr(mod->args, "grsec_modharden_netdev")) {
71708+ 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);
71709+ err = -EPERM;
71710+ goto free_modinfo;
71711+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
71712+ p += sizeof("grsec_modharden_normal") - 1;
71713+ p2 = strstr(p, "_");
71714+ if (p2) {
71715+ *p2 = '\0';
71716+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
71717+ *p2 = '_';
71718+ }
71719+ err = -EPERM;
71720+ goto free_modinfo;
71721+ }
71722+ }
71723+#endif
71724+
71725 /* Fix up syms, so that st_value is a pointer to location. */
71726 err = simplify_symbols(mod, info);
71727 if (err < 0)
71728@@ -3227,13 +3366,6 @@ again:
71729
71730 flush_module_icache(mod);
71731
71732- /* Now copy in args */
71733- mod->args = strndup_user(uargs, ~0UL >> 1);
71734- if (IS_ERR(mod->args)) {
71735- err = PTR_ERR(mod->args);
71736- goto free_arch_cleanup;
71737- }
71738-
71739 dynamic_debug_setup(info->debug, info->num_debug);
71740
71741 mutex_lock(&module_mutex);
71742@@ -3278,11 +3410,10 @@ again:
71743 mutex_unlock(&module_mutex);
71744 dynamic_debug_remove(info->debug);
71745 synchronize_sched();
71746- kfree(mod->args);
71747- free_arch_cleanup:
71748 module_arch_cleanup(mod);
71749 free_modinfo:
71750 free_modinfo(mod);
71751+ kfree(mod->args);
71752 free_unload:
71753 module_unload_free(mod);
71754 unlink_mod:
71755@@ -3365,10 +3496,16 @@ static const char *get_ksymbol(struct module *mod,
71756 unsigned long nextval;
71757
71758 /* At worse, next value is at end of module */
71759- if (within_module_init(addr, mod))
71760- nextval = (unsigned long)mod->module_init+mod->init_text_size;
71761+ if (within_module_init_rx(addr, mod))
71762+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
71763+ else if (within_module_init_rw(addr, mod))
71764+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
71765+ else if (within_module_core_rx(addr, mod))
71766+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
71767+ else if (within_module_core_rw(addr, mod))
71768+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
71769 else
71770- nextval = (unsigned long)mod->module_core+mod->core_text_size;
71771+ return NULL;
71772
71773 /* Scan for closest preceding symbol, and next symbol. (ELF
71774 starts real symbols at 1). */
71775@@ -3621,7 +3758,7 @@ static int m_show(struct seq_file *m, void *p)
71776 return 0;
71777
71778 seq_printf(m, "%s %u",
71779- mod->name, mod->init_size + mod->core_size);
71780+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
71781 print_unload_info(m, mod);
71782
71783 /* Informative for users. */
71784@@ -3630,7 +3767,7 @@ static int m_show(struct seq_file *m, void *p)
71785 mod->state == MODULE_STATE_COMING ? "Loading":
71786 "Live");
71787 /* Used by oprofile and other similar tools. */
71788- seq_printf(m, " 0x%pK", mod->module_core);
71789+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
71790
71791 /* Taints info */
71792 if (mod->taints)
71793@@ -3666,7 +3803,17 @@ static const struct file_operations proc_modules_operations = {
71794
71795 static int __init proc_modules_init(void)
71796 {
71797+#ifndef CONFIG_GRKERNSEC_HIDESYM
71798+#ifdef CONFIG_GRKERNSEC_PROC_USER
71799+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
71800+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71801+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
71802+#else
71803 proc_create("modules", 0, NULL, &proc_modules_operations);
71804+#endif
71805+#else
71806+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
71807+#endif
71808 return 0;
71809 }
71810 module_init(proc_modules_init);
71811@@ -3727,14 +3874,14 @@ struct module *__module_address(unsigned long addr)
71812 {
71813 struct module *mod;
71814
71815- if (addr < module_addr_min || addr > module_addr_max)
71816+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
71817+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
71818 return NULL;
71819
71820 list_for_each_entry_rcu(mod, &modules, list) {
71821 if (mod->state == MODULE_STATE_UNFORMED)
71822 continue;
71823- if (within_module_core(addr, mod)
71824- || within_module_init(addr, mod))
71825+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
71826 return mod;
71827 }
71828 return NULL;
71829@@ -3769,11 +3916,20 @@ bool is_module_text_address(unsigned long addr)
71830 */
71831 struct module *__module_text_address(unsigned long addr)
71832 {
71833- struct module *mod = __module_address(addr);
71834+ struct module *mod;
71835+
71836+#ifdef CONFIG_X86_32
71837+ addr = ktla_ktva(addr);
71838+#endif
71839+
71840+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
71841+ return NULL;
71842+
71843+ mod = __module_address(addr);
71844+
71845 if (mod) {
71846 /* Make sure it's within the text section. */
71847- if (!within(addr, mod->module_init, mod->init_text_size)
71848- && !within(addr, mod->module_core, mod->core_text_size))
71849+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
71850 mod = NULL;
71851 }
71852 return mod;
71853diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
71854index 7e3443f..b2a1e6b 100644
71855--- a/kernel/mutex-debug.c
71856+++ b/kernel/mutex-debug.c
71857@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
71858 }
71859
71860 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
71861- struct thread_info *ti)
71862+ struct task_struct *task)
71863 {
71864 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
71865
71866 /* Mark the current thread as blocked on the lock: */
71867- ti->task->blocked_on = waiter;
71868+ task->blocked_on = waiter;
71869 }
71870
71871 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
71872- struct thread_info *ti)
71873+ struct task_struct *task)
71874 {
71875 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
71876- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
71877- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
71878- ti->task->blocked_on = NULL;
71879+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
71880+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
71881+ task->blocked_on = NULL;
71882
71883 list_del_init(&waiter->list);
71884 waiter->task = NULL;
71885diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
71886index 0799fd3..d06ae3b 100644
71887--- a/kernel/mutex-debug.h
71888+++ b/kernel/mutex-debug.h
71889@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
71890 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
71891 extern void debug_mutex_add_waiter(struct mutex *lock,
71892 struct mutex_waiter *waiter,
71893- struct thread_info *ti);
71894+ struct task_struct *task);
71895 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
71896- struct thread_info *ti);
71897+ struct task_struct *task);
71898 extern void debug_mutex_unlock(struct mutex *lock);
71899 extern void debug_mutex_init(struct mutex *lock, const char *name,
71900 struct lock_class_key *key);
71901diff --git a/kernel/mutex.c b/kernel/mutex.c
71902index a307cc9..27fd2e9 100644
71903--- a/kernel/mutex.c
71904+++ b/kernel/mutex.c
71905@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
71906 spin_lock_mutex(&lock->wait_lock, flags);
71907
71908 debug_mutex_lock_common(lock, &waiter);
71909- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
71910+ debug_mutex_add_waiter(lock, &waiter, task);
71911
71912 /* add waiting tasks to the end of the waitqueue (FIFO): */
71913 list_add_tail(&waiter.list, &lock->wait_list);
71914@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
71915 * TASK_UNINTERRUPTIBLE case.)
71916 */
71917 if (unlikely(signal_pending_state(state, task))) {
71918- mutex_remove_waiter(lock, &waiter,
71919- task_thread_info(task));
71920+ mutex_remove_waiter(lock, &waiter, task);
71921 mutex_release(&lock->dep_map, 1, ip);
71922 spin_unlock_mutex(&lock->wait_lock, flags);
71923
71924@@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
71925 done:
71926 lock_acquired(&lock->dep_map, ip);
71927 /* got the lock - rejoice! */
71928- mutex_remove_waiter(lock, &waiter, current_thread_info());
71929+ mutex_remove_waiter(lock, &waiter, task);
71930 mutex_set_owner(lock);
71931
71932 /* set it to 0 if there are no waiters left: */
71933diff --git a/kernel/notifier.c b/kernel/notifier.c
71934index 2d5cc4c..d9ea600 100644
71935--- a/kernel/notifier.c
71936+++ b/kernel/notifier.c
71937@@ -5,6 +5,7 @@
71938 #include <linux/rcupdate.h>
71939 #include <linux/vmalloc.h>
71940 #include <linux/reboot.h>
71941+#include <linux/mm.h>
71942
71943 /*
71944 * Notifier list for kernel code which wants to be called
71945@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
71946 while ((*nl) != NULL) {
71947 if (n->priority > (*nl)->priority)
71948 break;
71949- nl = &((*nl)->next);
71950+ nl = (struct notifier_block **)&((*nl)->next);
71951 }
71952- n->next = *nl;
71953+ pax_open_kernel();
71954+ *(const void **)&n->next = *nl;
71955 rcu_assign_pointer(*nl, n);
71956+ pax_close_kernel();
71957 return 0;
71958 }
71959
71960@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
71961 return 0;
71962 if (n->priority > (*nl)->priority)
71963 break;
71964- nl = &((*nl)->next);
71965+ nl = (struct notifier_block **)&((*nl)->next);
71966 }
71967- n->next = *nl;
71968+ pax_open_kernel();
71969+ *(const void **)&n->next = *nl;
71970 rcu_assign_pointer(*nl, n);
71971+ pax_close_kernel();
71972 return 0;
71973 }
71974
71975@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
71976 {
71977 while ((*nl) != NULL) {
71978 if ((*nl) == n) {
71979+ pax_open_kernel();
71980 rcu_assign_pointer(*nl, n->next);
71981+ pax_close_kernel();
71982 return 0;
71983 }
71984- nl = &((*nl)->next);
71985+ nl = (struct notifier_block **)&((*nl)->next);
71986 }
71987 return -ENOENT;
71988 }
71989diff --git a/kernel/panic.c b/kernel/panic.c
71990index e1b2822..5edc1d9 100644
71991--- a/kernel/panic.c
71992+++ b/kernel/panic.c
71993@@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
71994 const char *board;
71995
71996 printk(KERN_WARNING "------------[ cut here ]------------\n");
71997- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
71998+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
71999 board = dmi_get_system_info(DMI_PRODUCT_NAME);
72000 if (board)
72001 printk(KERN_WARNING "Hardware name: %s\n", board);
72002@@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
72003 */
72004 void __stack_chk_fail(void)
72005 {
72006- panic("stack-protector: Kernel stack is corrupted in: %p\n",
72007+ dump_stack();
72008+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
72009 __builtin_return_address(0));
72010 }
72011 EXPORT_SYMBOL(__stack_chk_fail);
72012diff --git a/kernel/pid.c b/kernel/pid.c
72013index f2c6a68..4922d97 100644
72014--- a/kernel/pid.c
72015+++ b/kernel/pid.c
72016@@ -33,6 +33,7 @@
72017 #include <linux/rculist.h>
72018 #include <linux/bootmem.h>
72019 #include <linux/hash.h>
72020+#include <linux/security.h>
72021 #include <linux/pid_namespace.h>
72022 #include <linux/init_task.h>
72023 #include <linux/syscalls.h>
72024@@ -46,7 +47,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
72025
72026 int pid_max = PID_MAX_DEFAULT;
72027
72028-#define RESERVED_PIDS 300
72029+#define RESERVED_PIDS 500
72030
72031 int pid_max_min = RESERVED_PIDS + 1;
72032 int pid_max_max = PID_MAX_LIMIT;
72033@@ -441,10 +442,18 @@ EXPORT_SYMBOL(pid_task);
72034 */
72035 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
72036 {
72037+ struct task_struct *task;
72038+
72039 rcu_lockdep_assert(rcu_read_lock_held(),
72040 "find_task_by_pid_ns() needs rcu_read_lock()"
72041 " protection");
72042- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
72043+
72044+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
72045+
72046+ if (gr_pid_is_chrooted(task))
72047+ return NULL;
72048+
72049+ return task;
72050 }
72051
72052 struct task_struct *find_task_by_vpid(pid_t vnr)
72053@@ -452,6 +461,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
72054 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
72055 }
72056
72057+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
72058+{
72059+ rcu_lockdep_assert(rcu_read_lock_held(),
72060+ "find_task_by_pid_ns() needs rcu_read_lock()"
72061+ " protection");
72062+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
72063+}
72064+
72065 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
72066 {
72067 struct pid *pid;
72068diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
72069index 942ca27..111e609 100644
72070--- a/kernel/posix-cpu-timers.c
72071+++ b/kernel/posix-cpu-timers.c
72072@@ -1576,14 +1576,14 @@ struct k_clock clock_posix_cpu = {
72073
72074 static __init int init_posix_cpu_timers(void)
72075 {
72076- struct k_clock process = {
72077+ static struct k_clock process = {
72078 .clock_getres = process_cpu_clock_getres,
72079 .clock_get = process_cpu_clock_get,
72080 .timer_create = process_cpu_timer_create,
72081 .nsleep = process_cpu_nsleep,
72082 .nsleep_restart = process_cpu_nsleep_restart,
72083 };
72084- struct k_clock thread = {
72085+ static struct k_clock thread = {
72086 .clock_getres = thread_cpu_clock_getres,
72087 .clock_get = thread_cpu_clock_get,
72088 .timer_create = thread_cpu_timer_create,
72089diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
72090index 69185ae..cc2847a 100644
72091--- a/kernel/posix-timers.c
72092+++ b/kernel/posix-timers.c
72093@@ -43,6 +43,7 @@
72094 #include <linux/idr.h>
72095 #include <linux/posix-clock.h>
72096 #include <linux/posix-timers.h>
72097+#include <linux/grsecurity.h>
72098 #include <linux/syscalls.h>
72099 #include <linux/wait.h>
72100 #include <linux/workqueue.h>
72101@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
72102 * which we beg off on and pass to do_sys_settimeofday().
72103 */
72104
72105-static struct k_clock posix_clocks[MAX_CLOCKS];
72106+static struct k_clock *posix_clocks[MAX_CLOCKS];
72107
72108 /*
72109 * These ones are defined below.
72110@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
72111 */
72112 static __init int init_posix_timers(void)
72113 {
72114- struct k_clock clock_realtime = {
72115+ static struct k_clock clock_realtime = {
72116 .clock_getres = hrtimer_get_res,
72117 .clock_get = posix_clock_realtime_get,
72118 .clock_set = posix_clock_realtime_set,
72119@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
72120 .timer_get = common_timer_get,
72121 .timer_del = common_timer_del,
72122 };
72123- struct k_clock clock_monotonic = {
72124+ static struct k_clock clock_monotonic = {
72125 .clock_getres = hrtimer_get_res,
72126 .clock_get = posix_ktime_get_ts,
72127 .nsleep = common_nsleep,
72128@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
72129 .timer_get = common_timer_get,
72130 .timer_del = common_timer_del,
72131 };
72132- struct k_clock clock_monotonic_raw = {
72133+ static struct k_clock clock_monotonic_raw = {
72134 .clock_getres = hrtimer_get_res,
72135 .clock_get = posix_get_monotonic_raw,
72136 };
72137- struct k_clock clock_realtime_coarse = {
72138+ static struct k_clock clock_realtime_coarse = {
72139 .clock_getres = posix_get_coarse_res,
72140 .clock_get = posix_get_realtime_coarse,
72141 };
72142- struct k_clock clock_monotonic_coarse = {
72143+ static struct k_clock clock_monotonic_coarse = {
72144 .clock_getres = posix_get_coarse_res,
72145 .clock_get = posix_get_monotonic_coarse,
72146 };
72147- struct k_clock clock_boottime = {
72148+ static struct k_clock clock_boottime = {
72149 .clock_getres = hrtimer_get_res,
72150 .clock_get = posix_get_boottime,
72151 .nsleep = common_nsleep,
72152@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
72153 return;
72154 }
72155
72156- posix_clocks[clock_id] = *new_clock;
72157+ posix_clocks[clock_id] = new_clock;
72158 }
72159 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
72160
72161@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
72162 return (id & CLOCKFD_MASK) == CLOCKFD ?
72163 &clock_posix_dynamic : &clock_posix_cpu;
72164
72165- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
72166+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
72167 return NULL;
72168- return &posix_clocks[id];
72169+ return posix_clocks[id];
72170 }
72171
72172 static int common_timer_create(struct k_itimer *new_timer)
72173@@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
72174 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
72175 return -EFAULT;
72176
72177+ /* only the CLOCK_REALTIME clock can be set, all other clocks
72178+ have their clock_set fptr set to a nosettime dummy function
72179+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
72180+ call common_clock_set, which calls do_sys_settimeofday, which
72181+ we hook
72182+ */
72183+
72184 return kc->clock_set(which_clock, &new_tp);
72185 }
72186
72187diff --git a/kernel/power/process.c b/kernel/power/process.c
72188index d5a258b..4271191 100644
72189--- a/kernel/power/process.c
72190+++ b/kernel/power/process.c
72191@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
72192 u64 elapsed_csecs64;
72193 unsigned int elapsed_csecs;
72194 bool wakeup = false;
72195+ bool timedout = false;
72196
72197 do_gettimeofday(&start);
72198
72199@@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
72200
72201 while (true) {
72202 todo = 0;
72203+ if (time_after(jiffies, end_time))
72204+ timedout = true;
72205 read_lock(&tasklist_lock);
72206 do_each_thread(g, p) {
72207 if (p == current || !freeze_task(p))
72208 continue;
72209
72210- if (!freezer_should_skip(p))
72211+ if (!freezer_should_skip(p)) {
72212 todo++;
72213+ if (timedout) {
72214+ printk(KERN_ERR "Task refusing to freeze:\n");
72215+ sched_show_task(p);
72216+ }
72217+ }
72218 } while_each_thread(g, p);
72219 read_unlock(&tasklist_lock);
72220
72221@@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
72222 todo += wq_busy;
72223 }
72224
72225- if (!todo || time_after(jiffies, end_time))
72226+ if (!todo || timedout)
72227 break;
72228
72229 if (pm_wakeup_pending()) {
72230diff --git a/kernel/printk.c b/kernel/printk.c
72231index 267ce78..2487112 100644
72232--- a/kernel/printk.c
72233+++ b/kernel/printk.c
72234@@ -609,11 +609,17 @@ static unsigned int devkmsg_poll(struct file *file, poll_table *wait)
72235 return ret;
72236 }
72237
72238+static int check_syslog_permissions(int type, bool from_file);
72239+
72240 static int devkmsg_open(struct inode *inode, struct file *file)
72241 {
72242 struct devkmsg_user *user;
72243 int err;
72244
72245+ err = check_syslog_permissions(SYSLOG_ACTION_OPEN, SYSLOG_FROM_FILE);
72246+ if (err)
72247+ return err;
72248+
72249 /* write-only does not need any file context */
72250 if ((file->f_flags & O_ACCMODE) == O_WRONLY)
72251 return 0;
72252@@ -822,7 +828,7 @@ static int syslog_action_restricted(int type)
72253 if (dmesg_restrict)
72254 return 1;
72255 /* Unless restricted, we allow "read all" and "get buffer size" for everybody */
72256- return type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
72257+ return type != SYSLOG_ACTION_OPEN && type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
72258 }
72259
72260 static int check_syslog_permissions(int type, bool from_file)
72261@@ -834,6 +840,11 @@ static int check_syslog_permissions(int type, bool from_file)
72262 if (from_file && type != SYSLOG_ACTION_OPEN)
72263 return 0;
72264
72265+#ifdef CONFIG_GRKERNSEC_DMESG
72266+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
72267+ return -EPERM;
72268+#endif
72269+
72270 if (syslog_action_restricted(type)) {
72271 if (capable(CAP_SYSLOG))
72272 return 0;
72273diff --git a/kernel/profile.c b/kernel/profile.c
72274index 1f39181..86093471 100644
72275--- a/kernel/profile.c
72276+++ b/kernel/profile.c
72277@@ -40,7 +40,7 @@ struct profile_hit {
72278 /* Oprofile timer tick hook */
72279 static int (*timer_hook)(struct pt_regs *) __read_mostly;
72280
72281-static atomic_t *prof_buffer;
72282+static atomic_unchecked_t *prof_buffer;
72283 static unsigned long prof_len, prof_shift;
72284
72285 int prof_on __read_mostly;
72286@@ -282,7 +282,7 @@ static void profile_flip_buffers(void)
72287 hits[i].pc = 0;
72288 continue;
72289 }
72290- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
72291+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
72292 hits[i].hits = hits[i].pc = 0;
72293 }
72294 }
72295@@ -343,9 +343,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
72296 * Add the current hit(s) and flush the write-queue out
72297 * to the global buffer:
72298 */
72299- atomic_add(nr_hits, &prof_buffer[pc]);
72300+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
72301 for (i = 0; i < NR_PROFILE_HIT; ++i) {
72302- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
72303+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
72304 hits[i].pc = hits[i].hits = 0;
72305 }
72306 out:
72307@@ -420,7 +420,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
72308 {
72309 unsigned long pc;
72310 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
72311- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
72312+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
72313 }
72314 #endif /* !CONFIG_SMP */
72315
72316@@ -518,7 +518,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
72317 return -EFAULT;
72318 buf++; p++; count--; read++;
72319 }
72320- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
72321+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
72322 if (copy_to_user(buf, (void *)pnt, count))
72323 return -EFAULT;
72324 read += count;
72325@@ -549,7 +549,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
72326 }
72327 #endif
72328 profile_discard_flip_buffers();
72329- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
72330+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
72331 return count;
72332 }
72333
72334diff --git a/kernel/ptrace.c b/kernel/ptrace.c
72335index 6cbeaae..363c48a 100644
72336--- a/kernel/ptrace.c
72337+++ b/kernel/ptrace.c
72338@@ -324,7 +324,7 @@ static int ptrace_attach(struct task_struct *task, long request,
72339 if (seize)
72340 flags |= PT_SEIZED;
72341 rcu_read_lock();
72342- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
72343+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
72344 flags |= PT_PTRACE_CAP;
72345 rcu_read_unlock();
72346 task->ptrace = flags;
72347@@ -535,7 +535,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
72348 break;
72349 return -EIO;
72350 }
72351- if (copy_to_user(dst, buf, retval))
72352+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
72353 return -EFAULT;
72354 copied += retval;
72355 src += retval;
72356@@ -720,7 +720,7 @@ int ptrace_request(struct task_struct *child, long request,
72357 bool seized = child->ptrace & PT_SEIZED;
72358 int ret = -EIO;
72359 siginfo_t siginfo, *si;
72360- void __user *datavp = (void __user *) data;
72361+ void __user *datavp = (__force void __user *) data;
72362 unsigned long __user *datalp = datavp;
72363 unsigned long flags;
72364
72365@@ -922,14 +922,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
72366 goto out;
72367 }
72368
72369+ if (gr_handle_ptrace(child, request)) {
72370+ ret = -EPERM;
72371+ goto out_put_task_struct;
72372+ }
72373+
72374 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
72375 ret = ptrace_attach(child, request, addr, data);
72376 /*
72377 * Some architectures need to do book-keeping after
72378 * a ptrace attach.
72379 */
72380- if (!ret)
72381+ if (!ret) {
72382 arch_ptrace_attach(child);
72383+ gr_audit_ptrace(child);
72384+ }
72385 goto out_put_task_struct;
72386 }
72387
72388@@ -957,7 +964,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
72389 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
72390 if (copied != sizeof(tmp))
72391 return -EIO;
72392- return put_user(tmp, (unsigned long __user *)data);
72393+ return put_user(tmp, (__force unsigned long __user *)data);
72394 }
72395
72396 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
72397@@ -1067,14 +1074,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
72398 goto out;
72399 }
72400
72401+ if (gr_handle_ptrace(child, request)) {
72402+ ret = -EPERM;
72403+ goto out_put_task_struct;
72404+ }
72405+
72406 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
72407 ret = ptrace_attach(child, request, addr, data);
72408 /*
72409 * Some architectures need to do book-keeping after
72410 * a ptrace attach.
72411 */
72412- if (!ret)
72413+ if (!ret) {
72414 arch_ptrace_attach(child);
72415+ gr_audit_ptrace(child);
72416+ }
72417 goto out_put_task_struct;
72418 }
72419
72420diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
72421index e7dce58..ad0d7b7 100644
72422--- a/kernel/rcutiny.c
72423+++ b/kernel/rcutiny.c
72424@@ -46,7 +46,7 @@
72425 struct rcu_ctrlblk;
72426 static void invoke_rcu_callbacks(void);
72427 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
72428-static void rcu_process_callbacks(struct softirq_action *unused);
72429+static void rcu_process_callbacks(void);
72430 static void __call_rcu(struct rcu_head *head,
72431 void (*func)(struct rcu_head *rcu),
72432 struct rcu_ctrlblk *rcp);
72433@@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
72434 rcu_is_callbacks_kthread()));
72435 }
72436
72437-static void rcu_process_callbacks(struct softirq_action *unused)
72438+static void rcu_process_callbacks(void)
72439 {
72440 __rcu_process_callbacks(&rcu_sched_ctrlblk);
72441 __rcu_process_callbacks(&rcu_bh_ctrlblk);
72442diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
72443index f85016a..91cb03b 100644
72444--- a/kernel/rcutiny_plugin.h
72445+++ b/kernel/rcutiny_plugin.h
72446@@ -896,7 +896,7 @@ static int rcu_kthread(void *arg)
72447 have_rcu_kthread_work = morework;
72448 local_irq_restore(flags);
72449 if (work)
72450- rcu_process_callbacks(NULL);
72451+ rcu_process_callbacks();
72452 schedule_timeout_interruptible(1); /* Leave CPU for others. */
72453 }
72454
72455diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
72456index 31dea01..ad91ffb 100644
72457--- a/kernel/rcutorture.c
72458+++ b/kernel/rcutorture.c
72459@@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
72460 { 0 };
72461 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
72462 { 0 };
72463-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
72464-static atomic_t n_rcu_torture_alloc;
72465-static atomic_t n_rcu_torture_alloc_fail;
72466-static atomic_t n_rcu_torture_free;
72467-static atomic_t n_rcu_torture_mberror;
72468-static atomic_t n_rcu_torture_error;
72469+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
72470+static atomic_unchecked_t n_rcu_torture_alloc;
72471+static atomic_unchecked_t n_rcu_torture_alloc_fail;
72472+static atomic_unchecked_t n_rcu_torture_free;
72473+static atomic_unchecked_t n_rcu_torture_mberror;
72474+static atomic_unchecked_t n_rcu_torture_error;
72475 static long n_rcu_torture_barrier_error;
72476 static long n_rcu_torture_boost_ktrerror;
72477 static long n_rcu_torture_boost_rterror;
72478@@ -272,11 +272,11 @@ rcu_torture_alloc(void)
72479
72480 spin_lock_bh(&rcu_torture_lock);
72481 if (list_empty(&rcu_torture_freelist)) {
72482- atomic_inc(&n_rcu_torture_alloc_fail);
72483+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
72484 spin_unlock_bh(&rcu_torture_lock);
72485 return NULL;
72486 }
72487- atomic_inc(&n_rcu_torture_alloc);
72488+ atomic_inc_unchecked(&n_rcu_torture_alloc);
72489 p = rcu_torture_freelist.next;
72490 list_del_init(p);
72491 spin_unlock_bh(&rcu_torture_lock);
72492@@ -289,7 +289,7 @@ rcu_torture_alloc(void)
72493 static void
72494 rcu_torture_free(struct rcu_torture *p)
72495 {
72496- atomic_inc(&n_rcu_torture_free);
72497+ atomic_inc_unchecked(&n_rcu_torture_free);
72498 spin_lock_bh(&rcu_torture_lock);
72499 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
72500 spin_unlock_bh(&rcu_torture_lock);
72501@@ -409,7 +409,7 @@ rcu_torture_cb(struct rcu_head *p)
72502 i = rp->rtort_pipe_count;
72503 if (i > RCU_TORTURE_PIPE_LEN)
72504 i = RCU_TORTURE_PIPE_LEN;
72505- atomic_inc(&rcu_torture_wcount[i]);
72506+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
72507 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
72508 rp->rtort_mbtest = 0;
72509 rcu_torture_free(rp);
72510@@ -457,7 +457,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
72511 i = rp->rtort_pipe_count;
72512 if (i > RCU_TORTURE_PIPE_LEN)
72513 i = RCU_TORTURE_PIPE_LEN;
72514- atomic_inc(&rcu_torture_wcount[i]);
72515+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
72516 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
72517 rp->rtort_mbtest = 0;
72518 list_del(&rp->rtort_free);
72519@@ -975,7 +975,7 @@ rcu_torture_writer(void *arg)
72520 i = old_rp->rtort_pipe_count;
72521 if (i > RCU_TORTURE_PIPE_LEN)
72522 i = RCU_TORTURE_PIPE_LEN;
72523- atomic_inc(&rcu_torture_wcount[i]);
72524+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
72525 old_rp->rtort_pipe_count++;
72526 cur_ops->deferred_free(old_rp);
72527 }
72528@@ -1060,7 +1060,7 @@ static void rcu_torture_timer(unsigned long unused)
72529 }
72530 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
72531 if (p->rtort_mbtest == 0)
72532- atomic_inc(&n_rcu_torture_mberror);
72533+ atomic_inc_unchecked(&n_rcu_torture_mberror);
72534 spin_lock(&rand_lock);
72535 cur_ops->read_delay(&rand);
72536 n_rcu_torture_timers++;
72537@@ -1124,7 +1124,7 @@ rcu_torture_reader(void *arg)
72538 }
72539 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
72540 if (p->rtort_mbtest == 0)
72541- atomic_inc(&n_rcu_torture_mberror);
72542+ atomic_inc_unchecked(&n_rcu_torture_mberror);
72543 cur_ops->read_delay(&rand);
72544 preempt_disable();
72545 pipe_count = p->rtort_pipe_count;
72546@@ -1183,11 +1183,11 @@ rcu_torture_printk(char *page)
72547 rcu_torture_current,
72548 rcu_torture_current_version,
72549 list_empty(&rcu_torture_freelist),
72550- atomic_read(&n_rcu_torture_alloc),
72551- atomic_read(&n_rcu_torture_alloc_fail),
72552- atomic_read(&n_rcu_torture_free));
72553+ atomic_read_unchecked(&n_rcu_torture_alloc),
72554+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
72555+ atomic_read_unchecked(&n_rcu_torture_free));
72556 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
72557- atomic_read(&n_rcu_torture_mberror),
72558+ atomic_read_unchecked(&n_rcu_torture_mberror),
72559 n_rcu_torture_boost_ktrerror,
72560 n_rcu_torture_boost_rterror);
72561 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
72562@@ -1206,14 +1206,14 @@ rcu_torture_printk(char *page)
72563 n_barrier_attempts,
72564 n_rcu_torture_barrier_error);
72565 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
72566- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
72567+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
72568 n_rcu_torture_barrier_error != 0 ||
72569 n_rcu_torture_boost_ktrerror != 0 ||
72570 n_rcu_torture_boost_rterror != 0 ||
72571 n_rcu_torture_boost_failure != 0 ||
72572 i > 1) {
72573 cnt += sprintf(&page[cnt], "!!! ");
72574- atomic_inc(&n_rcu_torture_error);
72575+ atomic_inc_unchecked(&n_rcu_torture_error);
72576 WARN_ON_ONCE(1);
72577 }
72578 cnt += sprintf(&page[cnt], "Reader Pipe: ");
72579@@ -1227,7 +1227,7 @@ rcu_torture_printk(char *page)
72580 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
72581 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
72582 cnt += sprintf(&page[cnt], " %d",
72583- atomic_read(&rcu_torture_wcount[i]));
72584+ atomic_read_unchecked(&rcu_torture_wcount[i]));
72585 }
72586 cnt += sprintf(&page[cnt], "\n");
72587 if (cur_ops->stats)
72588@@ -1920,7 +1920,7 @@ rcu_torture_cleanup(void)
72589
72590 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
72591
72592- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
72593+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
72594 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
72595 else if (n_online_successes != n_online_attempts ||
72596 n_offline_successes != n_offline_attempts)
72597@@ -1989,18 +1989,18 @@ rcu_torture_init(void)
72598
72599 rcu_torture_current = NULL;
72600 rcu_torture_current_version = 0;
72601- atomic_set(&n_rcu_torture_alloc, 0);
72602- atomic_set(&n_rcu_torture_alloc_fail, 0);
72603- atomic_set(&n_rcu_torture_free, 0);
72604- atomic_set(&n_rcu_torture_mberror, 0);
72605- atomic_set(&n_rcu_torture_error, 0);
72606+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
72607+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
72608+ atomic_set_unchecked(&n_rcu_torture_free, 0);
72609+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
72610+ atomic_set_unchecked(&n_rcu_torture_error, 0);
72611 n_rcu_torture_barrier_error = 0;
72612 n_rcu_torture_boost_ktrerror = 0;
72613 n_rcu_torture_boost_rterror = 0;
72614 n_rcu_torture_boost_failure = 0;
72615 n_rcu_torture_boosts = 0;
72616 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
72617- atomic_set(&rcu_torture_wcount[i], 0);
72618+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
72619 for_each_possible_cpu(cpu) {
72620 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
72621 per_cpu(rcu_torture_count, cpu)[i] = 0;
72622diff --git a/kernel/rcutree.c b/kernel/rcutree.c
72623index e441b77..dd54f17 100644
72624--- a/kernel/rcutree.c
72625+++ b/kernel/rcutree.c
72626@@ -349,9 +349,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
72627 rcu_prepare_for_idle(smp_processor_id());
72628 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
72629 smp_mb__before_atomic_inc(); /* See above. */
72630- atomic_inc(&rdtp->dynticks);
72631+ atomic_inc_unchecked(&rdtp->dynticks);
72632 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
72633- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
72634+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
72635
72636 /*
72637 * It is illegal to enter an extended quiescent state while
72638@@ -487,10 +487,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
72639 int user)
72640 {
72641 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
72642- atomic_inc(&rdtp->dynticks);
72643+ atomic_inc_unchecked(&rdtp->dynticks);
72644 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
72645 smp_mb__after_atomic_inc(); /* See above. */
72646- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
72647+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
72648 rcu_cleanup_after_idle(smp_processor_id());
72649 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
72650 if (!user && !is_idle_task(current)) {
72651@@ -629,14 +629,14 @@ void rcu_nmi_enter(void)
72652 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
72653
72654 if (rdtp->dynticks_nmi_nesting == 0 &&
72655- (atomic_read(&rdtp->dynticks) & 0x1))
72656+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
72657 return;
72658 rdtp->dynticks_nmi_nesting++;
72659 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
72660- atomic_inc(&rdtp->dynticks);
72661+ atomic_inc_unchecked(&rdtp->dynticks);
72662 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
72663 smp_mb__after_atomic_inc(); /* See above. */
72664- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
72665+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
72666 }
72667
72668 /**
72669@@ -655,9 +655,9 @@ void rcu_nmi_exit(void)
72670 return;
72671 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
72672 smp_mb__before_atomic_inc(); /* See above. */
72673- atomic_inc(&rdtp->dynticks);
72674+ atomic_inc_unchecked(&rdtp->dynticks);
72675 smp_mb__after_atomic_inc(); /* Force delay to next write. */
72676- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
72677+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
72678 }
72679
72680 /**
72681@@ -671,7 +671,7 @@ int rcu_is_cpu_idle(void)
72682 int ret;
72683
72684 preempt_disable();
72685- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
72686+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
72687 preempt_enable();
72688 return ret;
72689 }
72690@@ -739,7 +739,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
72691 */
72692 static int dyntick_save_progress_counter(struct rcu_data *rdp)
72693 {
72694- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
72695+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
72696 return (rdp->dynticks_snap & 0x1) == 0;
72697 }
72698
72699@@ -754,7 +754,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
72700 unsigned int curr;
72701 unsigned int snap;
72702
72703- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
72704+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
72705 snap = (unsigned int)rdp->dynticks_snap;
72706
72707 /*
72708@@ -802,10 +802,10 @@ static int jiffies_till_stall_check(void)
72709 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
72710 */
72711 if (till_stall_check < 3) {
72712- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
72713+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
72714 till_stall_check = 3;
72715 } else if (till_stall_check > 300) {
72716- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
72717+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
72718 till_stall_check = 300;
72719 }
72720 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
72721@@ -1592,7 +1592,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
72722 rsp->qlen += rdp->qlen;
72723 rdp->n_cbs_orphaned += rdp->qlen;
72724 rdp->qlen_lazy = 0;
72725- ACCESS_ONCE(rdp->qlen) = 0;
72726+ ACCESS_ONCE_RW(rdp->qlen) = 0;
72727 }
72728
72729 /*
72730@@ -1838,7 +1838,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
72731 }
72732 smp_mb(); /* List handling before counting for rcu_barrier(). */
72733 rdp->qlen_lazy -= count_lazy;
72734- ACCESS_ONCE(rdp->qlen) -= count;
72735+ ACCESS_ONCE_RW(rdp->qlen) -= count;
72736 rdp->n_cbs_invoked += count;
72737
72738 /* Reinstate batch limit if we have worked down the excess. */
72739@@ -2031,7 +2031,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
72740 /*
72741 * Do RCU core processing for the current CPU.
72742 */
72743-static void rcu_process_callbacks(struct softirq_action *unused)
72744+static void rcu_process_callbacks(void)
72745 {
72746 struct rcu_state *rsp;
72747
72748@@ -2154,7 +2154,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
72749 local_irq_restore(flags);
72750 return;
72751 }
72752- ACCESS_ONCE(rdp->qlen)++;
72753+ ACCESS_ONCE_RW(rdp->qlen)++;
72754 if (lazy)
72755 rdp->qlen_lazy++;
72756 else
72757@@ -2363,11 +2363,11 @@ void synchronize_sched_expedited(void)
72758 * counter wrap on a 32-bit system. Quite a few more CPUs would of
72759 * course be required on a 64-bit system.
72760 */
72761- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
72762+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
72763 (ulong)atomic_long_read(&rsp->expedited_done) +
72764 ULONG_MAX / 8)) {
72765 synchronize_sched();
72766- atomic_long_inc(&rsp->expedited_wrap);
72767+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
72768 return;
72769 }
72770
72771@@ -2375,7 +2375,7 @@ void synchronize_sched_expedited(void)
72772 * Take a ticket. Note that atomic_inc_return() implies a
72773 * full memory barrier.
72774 */
72775- snap = atomic_long_inc_return(&rsp->expedited_start);
72776+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
72777 firstsnap = snap;
72778 get_online_cpus();
72779 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
72780@@ -2388,14 +2388,14 @@ void synchronize_sched_expedited(void)
72781 synchronize_sched_expedited_cpu_stop,
72782 NULL) == -EAGAIN) {
72783 put_online_cpus();
72784- atomic_long_inc(&rsp->expedited_tryfail);
72785+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
72786
72787 /* Check to see if someone else did our work for us. */
72788 s = atomic_long_read(&rsp->expedited_done);
72789 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
72790 /* ensure test happens before caller kfree */
72791 smp_mb__before_atomic_inc(); /* ^^^ */
72792- atomic_long_inc(&rsp->expedited_workdone1);
72793+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
72794 return;
72795 }
72796
72797@@ -2404,7 +2404,7 @@ void synchronize_sched_expedited(void)
72798 udelay(trycount * num_online_cpus());
72799 } else {
72800 wait_rcu_gp(call_rcu_sched);
72801- atomic_long_inc(&rsp->expedited_normal);
72802+ atomic_long_inc_unchecked(&rsp->expedited_normal);
72803 return;
72804 }
72805
72806@@ -2413,7 +2413,7 @@ void synchronize_sched_expedited(void)
72807 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
72808 /* ensure test happens before caller kfree */
72809 smp_mb__before_atomic_inc(); /* ^^^ */
72810- atomic_long_inc(&rsp->expedited_workdone2);
72811+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
72812 return;
72813 }
72814
72815@@ -2425,10 +2425,10 @@ void synchronize_sched_expedited(void)
72816 * period works for us.
72817 */
72818 get_online_cpus();
72819- snap = atomic_long_read(&rsp->expedited_start);
72820+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
72821 smp_mb(); /* ensure read is before try_stop_cpus(). */
72822 }
72823- atomic_long_inc(&rsp->expedited_stoppedcpus);
72824+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
72825
72826 /*
72827 * Everyone up to our most recent fetch is covered by our grace
72828@@ -2437,16 +2437,16 @@ void synchronize_sched_expedited(void)
72829 * than we did already did their update.
72830 */
72831 do {
72832- atomic_long_inc(&rsp->expedited_done_tries);
72833+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
72834 s = atomic_long_read(&rsp->expedited_done);
72835 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
72836 /* ensure test happens before caller kfree */
72837 smp_mb__before_atomic_inc(); /* ^^^ */
72838- atomic_long_inc(&rsp->expedited_done_lost);
72839+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
72840 break;
72841 }
72842 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
72843- atomic_long_inc(&rsp->expedited_done_exit);
72844+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
72845
72846 put_online_cpus();
72847 }
72848@@ -2620,7 +2620,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
72849 * ACCESS_ONCE() to prevent the compiler from speculating
72850 * the increment to precede the early-exit check.
72851 */
72852- ACCESS_ONCE(rsp->n_barrier_done)++;
72853+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
72854 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
72855 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
72856 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
72857@@ -2670,7 +2670,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
72858
72859 /* Increment ->n_barrier_done to prevent duplicate work. */
72860 smp_mb(); /* Keep increment after above mechanism. */
72861- ACCESS_ONCE(rsp->n_barrier_done)++;
72862+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
72863 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
72864 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
72865 smp_mb(); /* Keep increment before caller's subsequent code. */
72866@@ -2715,10 +2715,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
72867 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
72868 init_callback_list(rdp);
72869 rdp->qlen_lazy = 0;
72870- ACCESS_ONCE(rdp->qlen) = 0;
72871+ ACCESS_ONCE_RW(rdp->qlen) = 0;
72872 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
72873 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
72874- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
72875+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
72876 #ifdef CONFIG_RCU_USER_QS
72877 WARN_ON_ONCE(rdp->dynticks->in_user);
72878 #endif
72879@@ -2754,8 +2754,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
72880 rdp->blimit = blimit;
72881 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
72882 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
72883- atomic_set(&rdp->dynticks->dynticks,
72884- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
72885+ atomic_set_unchecked(&rdp->dynticks->dynticks,
72886+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
72887 rcu_prepare_for_idle_init(cpu);
72888 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
72889
72890diff --git a/kernel/rcutree.h b/kernel/rcutree.h
72891index 4b69291..704c92e 100644
72892--- a/kernel/rcutree.h
72893+++ b/kernel/rcutree.h
72894@@ -86,7 +86,7 @@ struct rcu_dynticks {
72895 long long dynticks_nesting; /* Track irq/process nesting level. */
72896 /* Process level is worth LLONG_MAX/2. */
72897 int dynticks_nmi_nesting; /* Track NMI nesting level. */
72898- atomic_t dynticks; /* Even value for idle, else odd. */
72899+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
72900 #ifdef CONFIG_RCU_FAST_NO_HZ
72901 int dyntick_drain; /* Prepare-for-idle state variable. */
72902 unsigned long dyntick_holdoff;
72903@@ -423,17 +423,17 @@ struct rcu_state {
72904 /* _rcu_barrier(). */
72905 /* End of fields guarded by barrier_mutex. */
72906
72907- atomic_long_t expedited_start; /* Starting ticket. */
72908- atomic_long_t expedited_done; /* Done ticket. */
72909- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
72910- atomic_long_t expedited_tryfail; /* # acquisition failures. */
72911- atomic_long_t expedited_workdone1; /* # done by others #1. */
72912- atomic_long_t expedited_workdone2; /* # done by others #2. */
72913- atomic_long_t expedited_normal; /* # fallbacks to normal. */
72914- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
72915- atomic_long_t expedited_done_tries; /* # tries to update _done. */
72916- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
72917- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
72918+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
72919+ atomic_long_t expedited_done; /* Done ticket. */
72920+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
72921+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
72922+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
72923+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
72924+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
72925+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
72926+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
72927+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
72928+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
72929
72930 unsigned long jiffies_force_qs; /* Time at which to invoke */
72931 /* force_quiescent_state(). */
72932diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
72933index c1cc7e1..5043e0e 100644
72934--- a/kernel/rcutree_plugin.h
72935+++ b/kernel/rcutree_plugin.h
72936@@ -892,7 +892,7 @@ void synchronize_rcu_expedited(void)
72937
72938 /* Clean up and exit. */
72939 smp_mb(); /* ensure expedited GP seen before counter increment. */
72940- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
72941+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
72942 unlock_mb_ret:
72943 mutex_unlock(&sync_rcu_preempt_exp_mutex);
72944 mb_ret:
72945@@ -2072,7 +2072,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
72946 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
72947 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
72948 cpu, ticks_value, ticks_title,
72949- atomic_read(&rdtp->dynticks) & 0xfff,
72950+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
72951 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
72952 fast_no_hz);
72953 }
72954@@ -2192,7 +2192,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
72955
72956 /* Enqueue the callback on the nocb list and update counts. */
72957 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
72958- ACCESS_ONCE(*old_rhpp) = rhp;
72959+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
72960 atomic_long_add(rhcount, &rdp->nocb_q_count);
72961 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
72962
72963@@ -2384,12 +2384,12 @@ static int rcu_nocb_kthread(void *arg)
72964 * Extract queued callbacks, update counts, and wait
72965 * for a grace period to elapse.
72966 */
72967- ACCESS_ONCE(rdp->nocb_head) = NULL;
72968+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
72969 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
72970 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
72971 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
72972- ACCESS_ONCE(rdp->nocb_p_count) += c;
72973- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
72974+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
72975+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
72976 wait_rcu_gp(rdp->rsp->call_remote);
72977
72978 /* Each pass through the following loop invokes a callback. */
72979@@ -2411,8 +2411,8 @@ static int rcu_nocb_kthread(void *arg)
72980 list = next;
72981 }
72982 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
72983- ACCESS_ONCE(rdp->nocb_p_count) -= c;
72984- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
72985+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
72986+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
72987 rdp->n_nocbs_invoked += c;
72988 }
72989 return 0;
72990@@ -2438,7 +2438,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
72991 rdp = per_cpu_ptr(rsp->rda, cpu);
72992 t = kthread_run(rcu_nocb_kthread, rdp, "rcuo%d", cpu);
72993 BUG_ON(IS_ERR(t));
72994- ACCESS_ONCE(rdp->nocb_kthread) = t;
72995+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
72996 }
72997 }
72998
72999diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
73000index 0d095dc..1985b19 100644
73001--- a/kernel/rcutree_trace.c
73002+++ b/kernel/rcutree_trace.c
73003@@ -123,7 +123,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
73004 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
73005 rdp->passed_quiesce, rdp->qs_pending);
73006 seq_printf(m, " dt=%d/%llx/%d df=%lu",
73007- atomic_read(&rdp->dynticks->dynticks),
73008+ atomic_read_unchecked(&rdp->dynticks->dynticks),
73009 rdp->dynticks->dynticks_nesting,
73010 rdp->dynticks->dynticks_nmi_nesting,
73011 rdp->dynticks_fqs);
73012@@ -184,17 +184,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
73013 struct rcu_state *rsp = (struct rcu_state *)m->private;
73014
73015 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",
73016- atomic_long_read(&rsp->expedited_start),
73017+ atomic_long_read_unchecked(&rsp->expedited_start),
73018 atomic_long_read(&rsp->expedited_done),
73019- atomic_long_read(&rsp->expedited_wrap),
73020- atomic_long_read(&rsp->expedited_tryfail),
73021- atomic_long_read(&rsp->expedited_workdone1),
73022- atomic_long_read(&rsp->expedited_workdone2),
73023- atomic_long_read(&rsp->expedited_normal),
73024- atomic_long_read(&rsp->expedited_stoppedcpus),
73025- atomic_long_read(&rsp->expedited_done_tries),
73026- atomic_long_read(&rsp->expedited_done_lost),
73027- atomic_long_read(&rsp->expedited_done_exit));
73028+ atomic_long_read_unchecked(&rsp->expedited_wrap),
73029+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
73030+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
73031+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
73032+ atomic_long_read_unchecked(&rsp->expedited_normal),
73033+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
73034+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
73035+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
73036+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
73037 return 0;
73038 }
73039
73040diff --git a/kernel/resource.c b/kernel/resource.c
73041index 73f35d4..4684fc4 100644
73042--- a/kernel/resource.c
73043+++ b/kernel/resource.c
73044@@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
73045
73046 static int __init ioresources_init(void)
73047 {
73048+#ifdef CONFIG_GRKERNSEC_PROC_ADD
73049+#ifdef CONFIG_GRKERNSEC_PROC_USER
73050+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
73051+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
73052+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
73053+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
73054+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
73055+#endif
73056+#else
73057 proc_create("ioports", 0, NULL, &proc_ioports_operations);
73058 proc_create("iomem", 0, NULL, &proc_iomem_operations);
73059+#endif
73060 return 0;
73061 }
73062 __initcall(ioresources_init);
73063diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
73064index 98ec494..4241d6d 100644
73065--- a/kernel/rtmutex-tester.c
73066+++ b/kernel/rtmutex-tester.c
73067@@ -20,7 +20,7 @@
73068 #define MAX_RT_TEST_MUTEXES 8
73069
73070 static spinlock_t rttest_lock;
73071-static atomic_t rttest_event;
73072+static atomic_unchecked_t rttest_event;
73073
73074 struct test_thread_data {
73075 int opcode;
73076@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73077
73078 case RTTEST_LOCKCONT:
73079 td->mutexes[td->opdata] = 1;
73080- td->event = atomic_add_return(1, &rttest_event);
73081+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73082 return 0;
73083
73084 case RTTEST_RESET:
73085@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73086 return 0;
73087
73088 case RTTEST_RESETEVENT:
73089- atomic_set(&rttest_event, 0);
73090+ atomic_set_unchecked(&rttest_event, 0);
73091 return 0;
73092
73093 default:
73094@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73095 return ret;
73096
73097 td->mutexes[id] = 1;
73098- td->event = atomic_add_return(1, &rttest_event);
73099+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73100 rt_mutex_lock(&mutexes[id]);
73101- td->event = atomic_add_return(1, &rttest_event);
73102+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73103 td->mutexes[id] = 4;
73104 return 0;
73105
73106@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73107 return ret;
73108
73109 td->mutexes[id] = 1;
73110- td->event = atomic_add_return(1, &rttest_event);
73111+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73112 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
73113- td->event = atomic_add_return(1, &rttest_event);
73114+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73115 td->mutexes[id] = ret ? 0 : 4;
73116 return ret ? -EINTR : 0;
73117
73118@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73119 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
73120 return ret;
73121
73122- td->event = atomic_add_return(1, &rttest_event);
73123+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73124 rt_mutex_unlock(&mutexes[id]);
73125- td->event = atomic_add_return(1, &rttest_event);
73126+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73127 td->mutexes[id] = 0;
73128 return 0;
73129
73130@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
73131 break;
73132
73133 td->mutexes[dat] = 2;
73134- td->event = atomic_add_return(1, &rttest_event);
73135+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73136 break;
73137
73138 default:
73139@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
73140 return;
73141
73142 td->mutexes[dat] = 3;
73143- td->event = atomic_add_return(1, &rttest_event);
73144+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73145 break;
73146
73147 case RTTEST_LOCKNOWAIT:
73148@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
73149 return;
73150
73151 td->mutexes[dat] = 1;
73152- td->event = atomic_add_return(1, &rttest_event);
73153+ td->event = atomic_add_return_unchecked(1, &rttest_event);
73154 return;
73155
73156 default:
73157diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
73158index 0984a21..939f183 100644
73159--- a/kernel/sched/auto_group.c
73160+++ b/kernel/sched/auto_group.c
73161@@ -11,7 +11,7 @@
73162
73163 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
73164 static struct autogroup autogroup_default;
73165-static atomic_t autogroup_seq_nr;
73166+static atomic_unchecked_t autogroup_seq_nr;
73167
73168 void __init autogroup_init(struct task_struct *init_task)
73169 {
73170@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
73171
73172 kref_init(&ag->kref);
73173 init_rwsem(&ag->lock);
73174- ag->id = atomic_inc_return(&autogroup_seq_nr);
73175+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
73176 ag->tg = tg;
73177 #ifdef CONFIG_RT_GROUP_SCHED
73178 /*
73179diff --git a/kernel/sched/core.c b/kernel/sched/core.c
73180index 26058d0..06f15dd 100644
73181--- a/kernel/sched/core.c
73182+++ b/kernel/sched/core.c
73183@@ -3631,6 +3631,8 @@ int can_nice(const struct task_struct *p, const int nice)
73184 /* convert nice value [19,-20] to rlimit style value [1,40] */
73185 int nice_rlim = 20 - nice;
73186
73187+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
73188+
73189 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
73190 capable(CAP_SYS_NICE));
73191 }
73192@@ -3664,7 +3666,8 @@ SYSCALL_DEFINE1(nice, int, increment)
73193 if (nice > 19)
73194 nice = 19;
73195
73196- if (increment < 0 && !can_nice(current, nice))
73197+ if (increment < 0 && (!can_nice(current, nice) ||
73198+ gr_handle_chroot_nice()))
73199 return -EPERM;
73200
73201 retval = security_task_setnice(current, nice);
73202@@ -3818,6 +3821,7 @@ recheck:
73203 unsigned long rlim_rtprio =
73204 task_rlimit(p, RLIMIT_RTPRIO);
73205
73206+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
73207 /* can't set/change the rt policy */
73208 if (policy != p->policy && !rlim_rtprio)
73209 return -EPERM;
73210@@ -5162,7 +5166,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
73211 * happens before everything else. This has to be lower priority than
73212 * the notifier in the perf_event subsystem, though.
73213 */
73214-static struct notifier_block __cpuinitdata migration_notifier = {
73215+static struct notifier_block migration_notifier = {
73216 .notifier_call = migration_call,
73217 .priority = CPU_PRI_MIGRATION,
73218 };
73219diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
73220index 81fa536..6ccf96a 100644
73221--- a/kernel/sched/fair.c
73222+++ b/kernel/sched/fair.c
73223@@ -830,7 +830,7 @@ void task_numa_fault(int node, int pages, bool migrated)
73224
73225 static void reset_ptenuma_scan(struct task_struct *p)
73226 {
73227- ACCESS_ONCE(p->mm->numa_scan_seq)++;
73228+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
73229 p->mm->numa_scan_offset = 0;
73230 }
73231
73232@@ -3254,25 +3254,18 @@ find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu)
73233 */
73234 static int select_idle_sibling(struct task_struct *p, int target)
73235 {
73236- int cpu = smp_processor_id();
73237- int prev_cpu = task_cpu(p);
73238 struct sched_domain *sd;
73239 struct sched_group *sg;
73240- int i;
73241+ int i = task_cpu(p);
73242
73243- /*
73244- * If the task is going to be woken-up on this cpu and if it is
73245- * already idle, then it is the right target.
73246- */
73247- if (target == cpu && idle_cpu(cpu))
73248- return cpu;
73249+ if (idle_cpu(target))
73250+ return target;
73251
73252 /*
73253- * If the task is going to be woken-up on the cpu where it previously
73254- * ran and if it is currently idle, then it the right target.
73255+ * If the prevous cpu is cache affine and idle, don't be stupid.
73256 */
73257- if (target == prev_cpu && idle_cpu(prev_cpu))
73258- return prev_cpu;
73259+ if (i != target && cpus_share_cache(i, target) && idle_cpu(i))
73260+ return i;
73261
73262 /*
73263 * Otherwise, iterate the domains and find an elegible idle cpu.
73264@@ -3286,7 +3279,7 @@ static int select_idle_sibling(struct task_struct *p, int target)
73265 goto next;
73266
73267 for_each_cpu(i, sched_group_cpus(sg)) {
73268- if (!idle_cpu(i))
73269+ if (i == target || !idle_cpu(i))
73270 goto next;
73271 }
73272
73273@@ -5663,7 +5656,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
73274 * run_rebalance_domains is triggered when needed from the scheduler tick.
73275 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
73276 */
73277-static void run_rebalance_domains(struct softirq_action *h)
73278+static void run_rebalance_domains(void)
73279 {
73280 int this_cpu = smp_processor_id();
73281 struct rq *this_rq = cpu_rq(this_cpu);
73282diff --git a/kernel/signal.c b/kernel/signal.c
73283index 3d09cf6..a67d2c6 100644
73284--- a/kernel/signal.c
73285+++ b/kernel/signal.c
73286@@ -50,12 +50,12 @@ static struct kmem_cache *sigqueue_cachep;
73287
73288 int print_fatal_signals __read_mostly;
73289
73290-static void __user *sig_handler(struct task_struct *t, int sig)
73291+static __sighandler_t sig_handler(struct task_struct *t, int sig)
73292 {
73293 return t->sighand->action[sig - 1].sa.sa_handler;
73294 }
73295
73296-static int sig_handler_ignored(void __user *handler, int sig)
73297+static int sig_handler_ignored(__sighandler_t handler, int sig)
73298 {
73299 /* Is it explicitly or implicitly ignored? */
73300 return handler == SIG_IGN ||
73301@@ -64,7 +64,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
73302
73303 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
73304 {
73305- void __user *handler;
73306+ __sighandler_t handler;
73307
73308 handler = sig_handler(t, sig);
73309
73310@@ -368,6 +368,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
73311 atomic_inc(&user->sigpending);
73312 rcu_read_unlock();
73313
73314+ if (!override_rlimit)
73315+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
73316+
73317 if (override_rlimit ||
73318 atomic_read(&user->sigpending) <=
73319 task_rlimit(t, RLIMIT_SIGPENDING)) {
73320@@ -492,7 +495,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
73321
73322 int unhandled_signal(struct task_struct *tsk, int sig)
73323 {
73324- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
73325+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
73326 if (is_global_init(tsk))
73327 return 1;
73328 if (handler != SIG_IGN && handler != SIG_DFL)
73329@@ -812,6 +815,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
73330 }
73331 }
73332
73333+ /* allow glibc communication via tgkill to other threads in our
73334+ thread group */
73335+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
73336+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
73337+ && gr_handle_signal(t, sig))
73338+ return -EPERM;
73339+
73340 return security_task_kill(t, info, sig, 0);
73341 }
73342
73343@@ -1194,7 +1204,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
73344 return send_signal(sig, info, p, 1);
73345 }
73346
73347-static int
73348+int
73349 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
73350 {
73351 return send_signal(sig, info, t, 0);
73352@@ -1231,6 +1241,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
73353 unsigned long int flags;
73354 int ret, blocked, ignored;
73355 struct k_sigaction *action;
73356+ int is_unhandled = 0;
73357
73358 spin_lock_irqsave(&t->sighand->siglock, flags);
73359 action = &t->sighand->action[sig-1];
73360@@ -1245,9 +1256,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
73361 }
73362 if (action->sa.sa_handler == SIG_DFL)
73363 t->signal->flags &= ~SIGNAL_UNKILLABLE;
73364+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
73365+ is_unhandled = 1;
73366 ret = specific_send_sig_info(sig, info, t);
73367 spin_unlock_irqrestore(&t->sighand->siglock, flags);
73368
73369+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
73370+ normal operation */
73371+ if (is_unhandled) {
73372+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
73373+ gr_handle_crash(t, sig);
73374+ }
73375+
73376 return ret;
73377 }
73378
73379@@ -1314,8 +1334,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
73380 ret = check_kill_permission(sig, info, p);
73381 rcu_read_unlock();
73382
73383- if (!ret && sig)
73384+ if (!ret && sig) {
73385 ret = do_send_sig_info(sig, info, p, true);
73386+ if (!ret)
73387+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
73388+ }
73389
73390 return ret;
73391 }
73392@@ -2852,7 +2875,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
73393 int error = -ESRCH;
73394
73395 rcu_read_lock();
73396- p = find_task_by_vpid(pid);
73397+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73398+ /* allow glibc communication via tgkill to other threads in our
73399+ thread group */
73400+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
73401+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
73402+ p = find_task_by_vpid_unrestricted(pid);
73403+ else
73404+#endif
73405+ p = find_task_by_vpid(pid);
73406 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
73407 error = check_kill_permission(sig, info, p);
73408 /*
73409@@ -3135,8 +3166,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
73410 }
73411 seg = get_fs();
73412 set_fs(KERNEL_DS);
73413- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
73414- (stack_t __force __user *) &uoss,
73415+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
73416+ (stack_t __force_user *) &uoss,
73417 compat_user_stack_pointer());
73418 set_fs(seg);
73419 if (ret >= 0 && uoss_ptr) {
73420diff --git a/kernel/smp.c b/kernel/smp.c
73421index 69f38bd..77bbf12 100644
73422--- a/kernel/smp.c
73423+++ b/kernel/smp.c
73424@@ -77,7 +77,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
73425 return NOTIFY_OK;
73426 }
73427
73428-static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
73429+static struct notifier_block hotplug_cfd_notifier = {
73430 .notifier_call = hotplug_cfd,
73431 };
73432
73433diff --git a/kernel/softirq.c b/kernel/softirq.c
73434index ed567ba..dc61b61 100644
73435--- a/kernel/softirq.c
73436+++ b/kernel/softirq.c
73437@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
73438 EXPORT_SYMBOL(irq_stat);
73439 #endif
73440
73441-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
73442+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
73443
73444 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
73445
73446-char *softirq_to_name[NR_SOFTIRQS] = {
73447+const char * const softirq_to_name[NR_SOFTIRQS] = {
73448 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
73449 "TASKLET", "SCHED", "HRTIMER", "RCU"
73450 };
73451@@ -244,7 +244,7 @@ restart:
73452 kstat_incr_softirqs_this_cpu(vec_nr);
73453
73454 trace_softirq_entry(vec_nr);
73455- h->action(h);
73456+ h->action();
73457 trace_softirq_exit(vec_nr);
73458 if (unlikely(prev_count != preempt_count())) {
73459 printk(KERN_ERR "huh, entered softirq %u %s %p"
73460@@ -391,7 +391,7 @@ void __raise_softirq_irqoff(unsigned int nr)
73461 or_softirq_pending(1UL << nr);
73462 }
73463
73464-void open_softirq(int nr, void (*action)(struct softirq_action *))
73465+void __init open_softirq(int nr, void (*action)(void))
73466 {
73467 softirq_vec[nr].action = action;
73468 }
73469@@ -447,7 +447,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
73470
73471 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
73472
73473-static void tasklet_action(struct softirq_action *a)
73474+static void tasklet_action(void)
73475 {
73476 struct tasklet_struct *list;
73477
73478@@ -482,7 +482,7 @@ static void tasklet_action(struct softirq_action *a)
73479 }
73480 }
73481
73482-static void tasklet_hi_action(struct softirq_action *a)
73483+static void tasklet_hi_action(void)
73484 {
73485 struct tasklet_struct *list;
73486
73487@@ -718,7 +718,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
73488 return NOTIFY_OK;
73489 }
73490
73491-static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
73492+static struct notifier_block remote_softirq_cpu_notifier = {
73493 .notifier_call = remote_softirq_cpu_notify,
73494 };
73495
73496@@ -835,7 +835,7 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
73497 return NOTIFY_OK;
73498 }
73499
73500-static struct notifier_block __cpuinitdata cpu_nfb = {
73501+static struct notifier_block cpu_nfb = {
73502 .notifier_call = cpu_callback
73503 };
73504
73505diff --git a/kernel/srcu.c b/kernel/srcu.c
73506index 2b85982..d52ab26 100644
73507--- a/kernel/srcu.c
73508+++ b/kernel/srcu.c
73509@@ -305,9 +305,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
73510 preempt_disable();
73511 idx = rcu_dereference_index_check(sp->completed,
73512 rcu_read_lock_sched_held()) & 0x1;
73513- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
73514+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
73515 smp_mb(); /* B */ /* Avoid leaking the critical section. */
73516- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
73517+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
73518 preempt_enable();
73519 return idx;
73520 }
73521@@ -323,7 +323,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
73522 {
73523 preempt_disable();
73524 smp_mb(); /* C */ /* Avoid leaking the critical section. */
73525- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
73526+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
73527 preempt_enable();
73528 }
73529 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
73530diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
73531index 2f194e9..2c05ea9 100644
73532--- a/kernel/stop_machine.c
73533+++ b/kernel/stop_machine.c
73534@@ -362,7 +362,7 @@ static int __cpuinit cpu_stop_cpu_callback(struct notifier_block *nfb,
73535 * cpu notifiers. It currently shares the same priority as sched
73536 * migration_notifier.
73537 */
73538-static struct notifier_block __cpuinitdata cpu_stop_cpu_notifier = {
73539+static struct notifier_block cpu_stop_cpu_notifier = {
73540 .notifier_call = cpu_stop_cpu_callback,
73541 .priority = 10,
73542 };
73543diff --git a/kernel/sys.c b/kernel/sys.c
73544index 265b376..b0cd50d 100644
73545--- a/kernel/sys.c
73546+++ b/kernel/sys.c
73547@@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
73548 error = -EACCES;
73549 goto out;
73550 }
73551+
73552+ if (gr_handle_chroot_setpriority(p, niceval)) {
73553+ error = -EACCES;
73554+ goto out;
73555+ }
73556+
73557 no_nice = security_task_setnice(p, niceval);
73558 if (no_nice) {
73559 error = no_nice;
73560@@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
73561 goto error;
73562 }
73563
73564+ if (gr_check_group_change(new->gid, new->egid, -1))
73565+ goto error;
73566+
73567 if (rgid != (gid_t) -1 ||
73568 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
73569 new->sgid = new->egid;
73570@@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
73571 old = current_cred();
73572
73573 retval = -EPERM;
73574+
73575+ if (gr_check_group_change(kgid, kgid, kgid))
73576+ goto error;
73577+
73578 if (nsown_capable(CAP_SETGID))
73579 new->gid = new->egid = new->sgid = new->fsgid = kgid;
73580 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
73581@@ -647,7 +660,7 @@ error:
73582 /*
73583 * change the user struct in a credentials set to match the new UID
73584 */
73585-static int set_user(struct cred *new)
73586+int set_user(struct cred *new)
73587 {
73588 struct user_struct *new_user;
73589
73590@@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
73591 goto error;
73592 }
73593
73594+ if (gr_check_user_change(new->uid, new->euid, -1))
73595+ goto error;
73596+
73597 if (!uid_eq(new->uid, old->uid)) {
73598 retval = set_user(new);
73599 if (retval < 0)
73600@@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
73601 old = current_cred();
73602
73603 retval = -EPERM;
73604+
73605+ if (gr_check_crash_uid(kuid))
73606+ goto error;
73607+ if (gr_check_user_change(kuid, kuid, kuid))
73608+ goto error;
73609+
73610 if (nsown_capable(CAP_SETUID)) {
73611 new->suid = new->uid = kuid;
73612 if (!uid_eq(kuid, old->uid)) {
73613@@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
73614 goto error;
73615 }
73616
73617+ if (gr_check_user_change(kruid, keuid, -1))
73618+ goto error;
73619+
73620 if (ruid != (uid_t) -1) {
73621 new->uid = kruid;
73622 if (!uid_eq(kruid, old->uid)) {
73623@@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
73624 goto error;
73625 }
73626
73627+ if (gr_check_group_change(krgid, kegid, -1))
73628+ goto error;
73629+
73630 if (rgid != (gid_t) -1)
73631 new->gid = krgid;
73632 if (egid != (gid_t) -1)
73633@@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
73634 if (!uid_valid(kuid))
73635 return old_fsuid;
73636
73637+ if (gr_check_user_change(-1, -1, kuid))
73638+ goto error;
73639+
73640 new = prepare_creds();
73641 if (!new)
73642 return old_fsuid;
73643@@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
73644 }
73645 }
73646
73647+error:
73648 abort_creds(new);
73649 return old_fsuid;
73650
73651@@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
73652 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
73653 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
73654 nsown_capable(CAP_SETGID)) {
73655+ if (gr_check_group_change(-1, -1, kgid))
73656+ goto error;
73657+
73658 if (!gid_eq(kgid, old->fsgid)) {
73659 new->fsgid = kgid;
73660 goto change_okay;
73661 }
73662 }
73663
73664+error:
73665 abort_creds(new);
73666 return old_fsgid;
73667
73668@@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
73669 return -EFAULT;
73670
73671 down_read(&uts_sem);
73672- error = __copy_to_user(&name->sysname, &utsname()->sysname,
73673+ error = __copy_to_user(name->sysname, &utsname()->sysname,
73674 __OLD_UTS_LEN);
73675 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
73676- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
73677+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
73678 __OLD_UTS_LEN);
73679 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
73680- error |= __copy_to_user(&name->release, &utsname()->release,
73681+ error |= __copy_to_user(name->release, &utsname()->release,
73682 __OLD_UTS_LEN);
73683 error |= __put_user(0, name->release + __OLD_UTS_LEN);
73684- error |= __copy_to_user(&name->version, &utsname()->version,
73685+ error |= __copy_to_user(name->version, &utsname()->version,
73686 __OLD_UTS_LEN);
73687 error |= __put_user(0, name->version + __OLD_UTS_LEN);
73688- error |= __copy_to_user(&name->machine, &utsname()->machine,
73689+ error |= __copy_to_user(name->machine, &utsname()->machine,
73690 __OLD_UTS_LEN);
73691 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
73692 up_read(&uts_sem);
73693@@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
73694 error = get_dumpable(me->mm);
73695 break;
73696 case PR_SET_DUMPABLE:
73697- if (arg2 < 0 || arg2 > 1) {
73698+ if (arg2 > 1) {
73699 error = -EINVAL;
73700 break;
73701 }
73702diff --git a/kernel/sysctl.c b/kernel/sysctl.c
73703index c88878d..99d321b 100644
73704--- a/kernel/sysctl.c
73705+++ b/kernel/sysctl.c
73706@@ -92,7 +92,6 @@
73707
73708
73709 #if defined(CONFIG_SYSCTL)
73710-
73711 /* External variables not in a header file. */
73712 extern int sysctl_overcommit_memory;
73713 extern int sysctl_overcommit_ratio;
73714@@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
73715 void __user *buffer, size_t *lenp, loff_t *ppos);
73716 #endif
73717
73718-#ifdef CONFIG_PRINTK
73719 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
73720 void __user *buffer, size_t *lenp, loff_t *ppos);
73721-#endif
73722
73723 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
73724 void __user *buffer, size_t *lenp, loff_t *ppos);
73725@@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
73726
73727 #endif
73728
73729+extern struct ctl_table grsecurity_table[];
73730+
73731 static struct ctl_table kern_table[];
73732 static struct ctl_table vm_table[];
73733 static struct ctl_table fs_table[];
73734@@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
73735 int sysctl_legacy_va_layout;
73736 #endif
73737
73738+#ifdef CONFIG_PAX_SOFTMODE
73739+static ctl_table pax_table[] = {
73740+ {
73741+ .procname = "softmode",
73742+ .data = &pax_softmode,
73743+ .maxlen = sizeof(unsigned int),
73744+ .mode = 0600,
73745+ .proc_handler = &proc_dointvec,
73746+ },
73747+
73748+ { }
73749+};
73750+#endif
73751+
73752 /* The default sysctl tables: */
73753
73754 static struct ctl_table sysctl_base_table[] = {
73755@@ -268,6 +281,22 @@ static int max_extfrag_threshold = 1000;
73756 #endif
73757
73758 static struct ctl_table kern_table[] = {
73759+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
73760+ {
73761+ .procname = "grsecurity",
73762+ .mode = 0500,
73763+ .child = grsecurity_table,
73764+ },
73765+#endif
73766+
73767+#ifdef CONFIG_PAX_SOFTMODE
73768+ {
73769+ .procname = "pax",
73770+ .mode = 0500,
73771+ .child = pax_table,
73772+ },
73773+#endif
73774+
73775 {
73776 .procname = "sched_child_runs_first",
73777 .data = &sysctl_sched_child_runs_first,
73778@@ -593,7 +622,7 @@ static struct ctl_table kern_table[] = {
73779 .data = &modprobe_path,
73780 .maxlen = KMOD_PATH_LEN,
73781 .mode = 0644,
73782- .proc_handler = proc_dostring,
73783+ .proc_handler = proc_dostring_modpriv,
73784 },
73785 {
73786 .procname = "modules_disabled",
73787@@ -760,16 +789,20 @@ static struct ctl_table kern_table[] = {
73788 .extra1 = &zero,
73789 .extra2 = &one,
73790 },
73791+#endif
73792 {
73793 .procname = "kptr_restrict",
73794 .data = &kptr_restrict,
73795 .maxlen = sizeof(int),
73796 .mode = 0644,
73797 .proc_handler = proc_dointvec_minmax_sysadmin,
73798+#ifdef CONFIG_GRKERNSEC_HIDESYM
73799+ .extra1 = &two,
73800+#else
73801 .extra1 = &zero,
73802+#endif
73803 .extra2 = &two,
73804 },
73805-#endif
73806 {
73807 .procname = "ngroups_max",
73808 .data = &ngroups_max,
73809@@ -1266,6 +1299,13 @@ static struct ctl_table vm_table[] = {
73810 .proc_handler = proc_dointvec_minmax,
73811 .extra1 = &zero,
73812 },
73813+ {
73814+ .procname = "heap_stack_gap",
73815+ .data = &sysctl_heap_stack_gap,
73816+ .maxlen = sizeof(sysctl_heap_stack_gap),
73817+ .mode = 0644,
73818+ .proc_handler = proc_doulongvec_minmax,
73819+ },
73820 #else
73821 {
73822 .procname = "nr_trim_pages",
73823@@ -1716,6 +1756,16 @@ int proc_dostring(struct ctl_table *table, int write,
73824 buffer, lenp, ppos);
73825 }
73826
73827+int proc_dostring_modpriv(struct ctl_table *table, int write,
73828+ void __user *buffer, size_t *lenp, loff_t *ppos)
73829+{
73830+ if (write && !capable(CAP_SYS_MODULE))
73831+ return -EPERM;
73832+
73833+ return _proc_do_string(table->data, table->maxlen, write,
73834+ buffer, lenp, ppos);
73835+}
73836+
73837 static size_t proc_skip_spaces(char **buf)
73838 {
73839 size_t ret;
73840@@ -1821,6 +1871,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
73841 len = strlen(tmp);
73842 if (len > *size)
73843 len = *size;
73844+ if (len > sizeof(tmp))
73845+ len = sizeof(tmp);
73846 if (copy_to_user(*buf, tmp, len))
73847 return -EFAULT;
73848 *size -= len;
73849@@ -2013,7 +2065,6 @@ static int proc_taint(struct ctl_table *table, int write,
73850 return err;
73851 }
73852
73853-#ifdef CONFIG_PRINTK
73854 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
73855 void __user *buffer, size_t *lenp, loff_t *ppos)
73856 {
73857@@ -2022,7 +2073,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
73858
73859 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
73860 }
73861-#endif
73862
73863 struct do_proc_dointvec_minmax_conv_param {
73864 int *min;
73865@@ -2169,8 +2219,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
73866 *i = val;
73867 } else {
73868 val = convdiv * (*i) / convmul;
73869- if (!first)
73870+ if (!first) {
73871 err = proc_put_char(&buffer, &left, '\t');
73872+ if (err)
73873+ break;
73874+ }
73875 err = proc_put_long(&buffer, &left, val, false);
73876 if (err)
73877 break;
73878@@ -2562,6 +2615,12 @@ int proc_dostring(struct ctl_table *table, int write,
73879 return -ENOSYS;
73880 }
73881
73882+int proc_dostring_modpriv(struct ctl_table *table, int write,
73883+ void __user *buffer, size_t *lenp, loff_t *ppos)
73884+{
73885+ return -ENOSYS;
73886+}
73887+
73888 int proc_dointvec(struct ctl_table *table, int write,
73889 void __user *buffer, size_t *lenp, loff_t *ppos)
73890 {
73891@@ -2618,5 +2677,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
73892 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
73893 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
73894 EXPORT_SYMBOL(proc_dostring);
73895+EXPORT_SYMBOL(proc_dostring_modpriv);
73896 EXPORT_SYMBOL(proc_doulongvec_minmax);
73897 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
73898diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
73899index 5a63844..a199f50 100644
73900--- a/kernel/sysctl_binary.c
73901+++ b/kernel/sysctl_binary.c
73902@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
73903 int i;
73904
73905 set_fs(KERNEL_DS);
73906- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
73907+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
73908 set_fs(old_fs);
73909 if (result < 0)
73910 goto out_kfree;
73911@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
73912 }
73913
73914 set_fs(KERNEL_DS);
73915- result = vfs_write(file, buffer, str - buffer, &pos);
73916+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
73917 set_fs(old_fs);
73918 if (result < 0)
73919 goto out_kfree;
73920@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
73921 int i;
73922
73923 set_fs(KERNEL_DS);
73924- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
73925+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
73926 set_fs(old_fs);
73927 if (result < 0)
73928 goto out_kfree;
73929@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
73930 }
73931
73932 set_fs(KERNEL_DS);
73933- result = vfs_write(file, buffer, str - buffer, &pos);
73934+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
73935 set_fs(old_fs);
73936 if (result < 0)
73937 goto out_kfree;
73938@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
73939 int i;
73940
73941 set_fs(KERNEL_DS);
73942- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
73943+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
73944 set_fs(old_fs);
73945 if (result < 0)
73946 goto out;
73947@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
73948 __le16 dnaddr;
73949
73950 set_fs(KERNEL_DS);
73951- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
73952+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
73953 set_fs(old_fs);
73954 if (result < 0)
73955 goto out;
73956@@ -1194,9 +1194,10 @@ static ssize_t bin_dn_node_address(struct file *file,
73957
73958 /* Convert the decnet address to binary */
73959 result = -EIO;
73960- nodep = strchr(buf, '.') + 1;
73961+ nodep = strchr(buf, '.');
73962 if (!nodep)
73963 goto out;
73964+ ++nodep;
73965
73966 area = simple_strtoul(buf, NULL, 10);
73967 node = simple_strtoul(nodep, NULL, 10);
73968@@ -1233,7 +1234,7 @@ static ssize_t bin_dn_node_address(struct file *file,
73969 le16_to_cpu(dnaddr) & 0x3ff);
73970
73971 set_fs(KERNEL_DS);
73972- result = vfs_write(file, buf, len, &pos);
73973+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
73974 set_fs(old_fs);
73975 if (result < 0)
73976 goto out;
73977diff --git a/kernel/taskstats.c b/kernel/taskstats.c
73978index 145bb4d..b2aa969 100644
73979--- a/kernel/taskstats.c
73980+++ b/kernel/taskstats.c
73981@@ -28,9 +28,12 @@
73982 #include <linux/fs.h>
73983 #include <linux/file.h>
73984 #include <linux/pid_namespace.h>
73985+#include <linux/grsecurity.h>
73986 #include <net/genetlink.h>
73987 #include <linux/atomic.h>
73988
73989+extern int gr_is_taskstats_denied(int pid);
73990+
73991 /*
73992 * Maximum length of a cpumask that can be specified in
73993 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
73994@@ -570,6 +573,9 @@ err:
73995
73996 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
73997 {
73998+ if (gr_is_taskstats_denied(current->pid))
73999+ return -EACCES;
74000+
74001 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
74002 return cmd_attr_register_cpumask(info);
74003 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
74004diff --git a/kernel/time.c b/kernel/time.c
74005index d226c6a..c7c0960 100644
74006--- a/kernel/time.c
74007+++ b/kernel/time.c
74008@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
74009 return error;
74010
74011 if (tz) {
74012+ /* we log in do_settimeofday called below, so don't log twice
74013+ */
74014+ if (!tv)
74015+ gr_log_timechange();
74016+
74017 sys_tz = *tz;
74018 update_vsyscall_tz();
74019 if (firsttime) {
74020diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
74021index f11d83b..d016d91 100644
74022--- a/kernel/time/alarmtimer.c
74023+++ b/kernel/time/alarmtimer.c
74024@@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
74025 struct platform_device *pdev;
74026 int error = 0;
74027 int i;
74028- struct k_clock alarm_clock = {
74029+ static struct k_clock alarm_clock = {
74030 .clock_getres = alarm_clock_getres,
74031 .clock_get = alarm_clock_get,
74032 .timer_create = alarm_timer_create,
74033diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
74034index f113755..ec24223 100644
74035--- a/kernel/time/tick-broadcast.c
74036+++ b/kernel/time/tick-broadcast.c
74037@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
74038 * then clear the broadcast bit.
74039 */
74040 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
74041- int cpu = smp_processor_id();
74042+ cpu = smp_processor_id();
74043
74044 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
74045 tick_broadcast_clear_oneshot(cpu);
74046diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
74047index cbc6acb..3a77191 100644
74048--- a/kernel/time/timekeeping.c
74049+++ b/kernel/time/timekeeping.c
74050@@ -15,6 +15,7 @@
74051 #include <linux/init.h>
74052 #include <linux/mm.h>
74053 #include <linux/sched.h>
74054+#include <linux/grsecurity.h>
74055 #include <linux/syscore_ops.h>
74056 #include <linux/clocksource.h>
74057 #include <linux/jiffies.h>
74058@@ -412,6 +413,8 @@ int do_settimeofday(const struct timespec *tv)
74059 if (!timespec_valid_strict(tv))
74060 return -EINVAL;
74061
74062+ gr_log_timechange();
74063+
74064 write_seqlock_irqsave(&tk->lock, flags);
74065
74066 timekeeping_forward_now(tk);
74067diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
74068index af5a7e9..715611a 100644
74069--- a/kernel/time/timer_list.c
74070+++ b/kernel/time/timer_list.c
74071@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
74072
74073 static void print_name_offset(struct seq_file *m, void *sym)
74074 {
74075+#ifdef CONFIG_GRKERNSEC_HIDESYM
74076+ SEQ_printf(m, "<%p>", NULL);
74077+#else
74078 char symname[KSYM_NAME_LEN];
74079
74080 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
74081 SEQ_printf(m, "<%pK>", sym);
74082 else
74083 SEQ_printf(m, "%s", symname);
74084+#endif
74085 }
74086
74087 static void
74088@@ -112,7 +116,11 @@ next_one:
74089 static void
74090 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
74091 {
74092+#ifdef CONFIG_GRKERNSEC_HIDESYM
74093+ SEQ_printf(m, " .base: %p\n", NULL);
74094+#else
74095 SEQ_printf(m, " .base: %pK\n", base);
74096+#endif
74097 SEQ_printf(m, " .index: %d\n",
74098 base->index);
74099 SEQ_printf(m, " .resolution: %Lu nsecs\n",
74100@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
74101 {
74102 struct proc_dir_entry *pe;
74103
74104+#ifdef CONFIG_GRKERNSEC_PROC_ADD
74105+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
74106+#else
74107 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
74108+#endif
74109 if (!pe)
74110 return -ENOMEM;
74111 return 0;
74112diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
74113index 0b537f2..40d6c20 100644
74114--- a/kernel/time/timer_stats.c
74115+++ b/kernel/time/timer_stats.c
74116@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
74117 static unsigned long nr_entries;
74118 static struct entry entries[MAX_ENTRIES];
74119
74120-static atomic_t overflow_count;
74121+static atomic_unchecked_t overflow_count;
74122
74123 /*
74124 * The entries are in a hash-table, for fast lookup:
74125@@ -140,7 +140,7 @@ static void reset_entries(void)
74126 nr_entries = 0;
74127 memset(entries, 0, sizeof(entries));
74128 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
74129- atomic_set(&overflow_count, 0);
74130+ atomic_set_unchecked(&overflow_count, 0);
74131 }
74132
74133 static struct entry *alloc_entry(void)
74134@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
74135 if (likely(entry))
74136 entry->count++;
74137 else
74138- atomic_inc(&overflow_count);
74139+ atomic_inc_unchecked(&overflow_count);
74140
74141 out_unlock:
74142 raw_spin_unlock_irqrestore(lock, flags);
74143@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
74144
74145 static void print_name_offset(struct seq_file *m, unsigned long addr)
74146 {
74147+#ifdef CONFIG_GRKERNSEC_HIDESYM
74148+ seq_printf(m, "<%p>", NULL);
74149+#else
74150 char symname[KSYM_NAME_LEN];
74151
74152 if (lookup_symbol_name(addr, symname) < 0)
74153- seq_printf(m, "<%p>", (void *)addr);
74154+ seq_printf(m, "<%pK>", (void *)addr);
74155 else
74156 seq_printf(m, "%s", symname);
74157+#endif
74158 }
74159
74160 static int tstats_show(struct seq_file *m, void *v)
74161@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
74162
74163 seq_puts(m, "Timer Stats Version: v0.2\n");
74164 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
74165- if (atomic_read(&overflow_count))
74166+ if (atomic_read_unchecked(&overflow_count))
74167 seq_printf(m, "Overflow: %d entries\n",
74168- atomic_read(&overflow_count));
74169+ atomic_read_unchecked(&overflow_count));
74170
74171 for (i = 0; i < nr_entries; i++) {
74172 entry = entries + i;
74173@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
74174 {
74175 struct proc_dir_entry *pe;
74176
74177+#ifdef CONFIG_GRKERNSEC_PROC_ADD
74178+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
74179+#else
74180 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
74181+#endif
74182 if (!pe)
74183 return -ENOMEM;
74184 return 0;
74185diff --git a/kernel/timer.c b/kernel/timer.c
74186index 367d008..1ee9ed9 100644
74187--- a/kernel/timer.c
74188+++ b/kernel/timer.c
74189@@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
74190 /*
74191 * This function runs timers and the timer-tq in bottom half context.
74192 */
74193-static void run_timer_softirq(struct softirq_action *h)
74194+static void run_timer_softirq(void)
74195 {
74196 struct tvec_base *base = __this_cpu_read(tvec_bases);
74197
74198@@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
74199 return NOTIFY_OK;
74200 }
74201
74202-static struct notifier_block __cpuinitdata timers_nb = {
74203+static struct notifier_block timers_nb = {
74204 .notifier_call = timer_cpu_notify,
74205 };
74206
74207diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
74208index c0bd030..62a1927 100644
74209--- a/kernel/trace/blktrace.c
74210+++ b/kernel/trace/blktrace.c
74211@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
74212 struct blk_trace *bt = filp->private_data;
74213 char buf[16];
74214
74215- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
74216+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
74217
74218 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
74219 }
74220@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
74221 return 1;
74222
74223 bt = buf->chan->private_data;
74224- atomic_inc(&bt->dropped);
74225+ atomic_inc_unchecked(&bt->dropped);
74226 return 0;
74227 }
74228
74229@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
74230
74231 bt->dir = dir;
74232 bt->dev = dev;
74233- atomic_set(&bt->dropped, 0);
74234+ atomic_set_unchecked(&bt->dropped, 0);
74235
74236 ret = -EIO;
74237 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
74238diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
74239index 41473b4..325fcfc 100644
74240--- a/kernel/trace/ftrace.c
74241+++ b/kernel/trace/ftrace.c
74242@@ -1874,12 +1874,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
74243 if (unlikely(ftrace_disabled))
74244 return 0;
74245
74246+ ret = ftrace_arch_code_modify_prepare();
74247+ FTRACE_WARN_ON(ret);
74248+ if (ret)
74249+ return 0;
74250+
74251 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
74252+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
74253 if (ret) {
74254 ftrace_bug(ret, ip);
74255- return 0;
74256 }
74257- return 1;
74258+ return ret ? 0 : 1;
74259 }
74260
74261 /*
74262@@ -2965,7 +2970,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
74263
74264 int
74265 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
74266- void *data)
74267+ void *data)
74268 {
74269 struct ftrace_func_probe *entry;
74270 struct ftrace_page *pg;
74271@@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
74272 if (!count)
74273 return 0;
74274
74275+ pax_open_kernel();
74276 sort(start, count, sizeof(*start),
74277 ftrace_cmp_ips, ftrace_swap_ips);
74278+ pax_close_kernel();
74279
74280 start_pg = ftrace_allocate_pages(count);
74281 if (!start_pg)
74282@@ -4541,8 +4548,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
74283 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
74284
74285 static int ftrace_graph_active;
74286-static struct notifier_block ftrace_suspend_notifier;
74287-
74288 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
74289 {
74290 return 0;
74291@@ -4686,6 +4691,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
74292 return NOTIFY_DONE;
74293 }
74294
74295+static struct notifier_block ftrace_suspend_notifier = {
74296+ .notifier_call = ftrace_suspend_notifier_call
74297+};
74298+
74299 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
74300 trace_func_graph_ent_t entryfunc)
74301 {
74302@@ -4699,7 +4708,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
74303 goto out;
74304 }
74305
74306- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
74307 register_pm_notifier(&ftrace_suspend_notifier);
74308
74309 ftrace_graph_active++;
74310diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
74311index ce8514f..8233573 100644
74312--- a/kernel/trace/ring_buffer.c
74313+++ b/kernel/trace/ring_buffer.c
74314@@ -346,9 +346,9 @@ struct buffer_data_page {
74315 */
74316 struct buffer_page {
74317 struct list_head list; /* list of buffer pages */
74318- local_t write; /* index for next write */
74319+ local_unchecked_t write; /* index for next write */
74320 unsigned read; /* index for next read */
74321- local_t entries; /* entries on this page */
74322+ local_unchecked_t entries; /* entries on this page */
74323 unsigned long real_end; /* real end of data */
74324 struct buffer_data_page *page; /* Actual data page */
74325 };
74326@@ -461,8 +461,8 @@ struct ring_buffer_per_cpu {
74327 unsigned long last_overrun;
74328 local_t entries_bytes;
74329 local_t entries;
74330- local_t overrun;
74331- local_t commit_overrun;
74332+ local_unchecked_t overrun;
74333+ local_unchecked_t commit_overrun;
74334 local_t dropped_events;
74335 local_t committing;
74336 local_t commits;
74337@@ -861,8 +861,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
74338 *
74339 * We add a counter to the write field to denote this.
74340 */
74341- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
74342- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
74343+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
74344+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
74345
74346 /*
74347 * Just make sure we have seen our old_write and synchronize
74348@@ -890,8 +890,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
74349 * cmpxchg to only update if an interrupt did not already
74350 * do it for us. If the cmpxchg fails, we don't care.
74351 */
74352- (void)local_cmpxchg(&next_page->write, old_write, val);
74353- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
74354+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
74355+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
74356
74357 /*
74358 * No need to worry about races with clearing out the commit.
74359@@ -1250,12 +1250,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
74360
74361 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
74362 {
74363- return local_read(&bpage->entries) & RB_WRITE_MASK;
74364+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
74365 }
74366
74367 static inline unsigned long rb_page_write(struct buffer_page *bpage)
74368 {
74369- return local_read(&bpage->write) & RB_WRITE_MASK;
74370+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
74371 }
74372
74373 static int
74374@@ -1350,7 +1350,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
74375 * bytes consumed in ring buffer from here.
74376 * Increment overrun to account for the lost events.
74377 */
74378- local_add(page_entries, &cpu_buffer->overrun);
74379+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
74380 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
74381 }
74382
74383@@ -1906,7 +1906,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
74384 * it is our responsibility to update
74385 * the counters.
74386 */
74387- local_add(entries, &cpu_buffer->overrun);
74388+ local_add_unchecked(entries, &cpu_buffer->overrun);
74389 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
74390
74391 /*
74392@@ -2056,7 +2056,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
74393 if (tail == BUF_PAGE_SIZE)
74394 tail_page->real_end = 0;
74395
74396- local_sub(length, &tail_page->write);
74397+ local_sub_unchecked(length, &tail_page->write);
74398 return;
74399 }
74400
74401@@ -2091,7 +2091,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
74402 rb_event_set_padding(event);
74403
74404 /* Set the write back to the previous setting */
74405- local_sub(length, &tail_page->write);
74406+ local_sub_unchecked(length, &tail_page->write);
74407 return;
74408 }
74409
74410@@ -2103,7 +2103,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
74411
74412 /* Set write to end of buffer */
74413 length = (tail + length) - BUF_PAGE_SIZE;
74414- local_sub(length, &tail_page->write);
74415+ local_sub_unchecked(length, &tail_page->write);
74416 }
74417
74418 /*
74419@@ -2129,7 +2129,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
74420 * about it.
74421 */
74422 if (unlikely(next_page == commit_page)) {
74423- local_inc(&cpu_buffer->commit_overrun);
74424+ local_inc_unchecked(&cpu_buffer->commit_overrun);
74425 goto out_reset;
74426 }
74427
74428@@ -2185,7 +2185,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
74429 cpu_buffer->tail_page) &&
74430 (cpu_buffer->commit_page ==
74431 cpu_buffer->reader_page))) {
74432- local_inc(&cpu_buffer->commit_overrun);
74433+ local_inc_unchecked(&cpu_buffer->commit_overrun);
74434 goto out_reset;
74435 }
74436 }
74437@@ -2233,7 +2233,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
74438 length += RB_LEN_TIME_EXTEND;
74439
74440 tail_page = cpu_buffer->tail_page;
74441- write = local_add_return(length, &tail_page->write);
74442+ write = local_add_return_unchecked(length, &tail_page->write);
74443
74444 /* set write to only the index of the write */
74445 write &= RB_WRITE_MASK;
74446@@ -2250,7 +2250,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
74447 kmemcheck_annotate_bitfield(event, bitfield);
74448 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
74449
74450- local_inc(&tail_page->entries);
74451+ local_inc_unchecked(&tail_page->entries);
74452
74453 /*
74454 * If this is the first commit on the page, then update
74455@@ -2283,7 +2283,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
74456
74457 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
74458 unsigned long write_mask =
74459- local_read(&bpage->write) & ~RB_WRITE_MASK;
74460+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
74461 unsigned long event_length = rb_event_length(event);
74462 /*
74463 * This is on the tail page. It is possible that
74464@@ -2293,7 +2293,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
74465 */
74466 old_index += write_mask;
74467 new_index += write_mask;
74468- index = local_cmpxchg(&bpage->write, old_index, new_index);
74469+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
74470 if (index == old_index) {
74471 /* update counters */
74472 local_sub(event_length, &cpu_buffer->entries_bytes);
74473@@ -2632,7 +2632,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
74474
74475 /* Do the likely case first */
74476 if (likely(bpage->page == (void *)addr)) {
74477- local_dec(&bpage->entries);
74478+ local_dec_unchecked(&bpage->entries);
74479 return;
74480 }
74481
74482@@ -2644,7 +2644,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
74483 start = bpage;
74484 do {
74485 if (bpage->page == (void *)addr) {
74486- local_dec(&bpage->entries);
74487+ local_dec_unchecked(&bpage->entries);
74488 return;
74489 }
74490 rb_inc_page(cpu_buffer, &bpage);
74491@@ -2926,7 +2926,7 @@ static inline unsigned long
74492 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
74493 {
74494 return local_read(&cpu_buffer->entries) -
74495- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
74496+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
74497 }
74498
74499 /**
74500@@ -3015,7 +3015,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
74501 return 0;
74502
74503 cpu_buffer = buffer->buffers[cpu];
74504- ret = local_read(&cpu_buffer->overrun);
74505+ ret = local_read_unchecked(&cpu_buffer->overrun);
74506
74507 return ret;
74508 }
74509@@ -3038,7 +3038,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
74510 return 0;
74511
74512 cpu_buffer = buffer->buffers[cpu];
74513- ret = local_read(&cpu_buffer->commit_overrun);
74514+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
74515
74516 return ret;
74517 }
74518@@ -3105,7 +3105,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
74519 /* if you care about this being correct, lock the buffer */
74520 for_each_buffer_cpu(buffer, cpu) {
74521 cpu_buffer = buffer->buffers[cpu];
74522- overruns += local_read(&cpu_buffer->overrun);
74523+ overruns += local_read_unchecked(&cpu_buffer->overrun);
74524 }
74525
74526 return overruns;
74527@@ -3281,8 +3281,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
74528 /*
74529 * Reset the reader page to size zero.
74530 */
74531- local_set(&cpu_buffer->reader_page->write, 0);
74532- local_set(&cpu_buffer->reader_page->entries, 0);
74533+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
74534+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
74535 local_set(&cpu_buffer->reader_page->page->commit, 0);
74536 cpu_buffer->reader_page->real_end = 0;
74537
74538@@ -3316,7 +3316,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
74539 * want to compare with the last_overrun.
74540 */
74541 smp_mb();
74542- overwrite = local_read(&(cpu_buffer->overrun));
74543+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
74544
74545 /*
74546 * Here's the tricky part.
74547@@ -3886,8 +3886,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
74548
74549 cpu_buffer->head_page
74550 = list_entry(cpu_buffer->pages, struct buffer_page, list);
74551- local_set(&cpu_buffer->head_page->write, 0);
74552- local_set(&cpu_buffer->head_page->entries, 0);
74553+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
74554+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
74555 local_set(&cpu_buffer->head_page->page->commit, 0);
74556
74557 cpu_buffer->head_page->read = 0;
74558@@ -3897,14 +3897,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
74559
74560 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
74561 INIT_LIST_HEAD(&cpu_buffer->new_pages);
74562- local_set(&cpu_buffer->reader_page->write, 0);
74563- local_set(&cpu_buffer->reader_page->entries, 0);
74564+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
74565+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
74566 local_set(&cpu_buffer->reader_page->page->commit, 0);
74567 cpu_buffer->reader_page->read = 0;
74568
74569 local_set(&cpu_buffer->entries_bytes, 0);
74570- local_set(&cpu_buffer->overrun, 0);
74571- local_set(&cpu_buffer->commit_overrun, 0);
74572+ local_set_unchecked(&cpu_buffer->overrun, 0);
74573+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
74574 local_set(&cpu_buffer->dropped_events, 0);
74575 local_set(&cpu_buffer->entries, 0);
74576 local_set(&cpu_buffer->committing, 0);
74577@@ -4308,8 +4308,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
74578 rb_init_page(bpage);
74579 bpage = reader->page;
74580 reader->page = *data_page;
74581- local_set(&reader->write, 0);
74582- local_set(&reader->entries, 0);
74583+ local_set_unchecked(&reader->write, 0);
74584+ local_set_unchecked(&reader->entries, 0);
74585 reader->read = 0;
74586 *data_page = bpage;
74587
74588diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
74589index 3c13e46..883d039 100644
74590--- a/kernel/trace/trace.c
74591+++ b/kernel/trace/trace.c
74592@@ -4465,10 +4465,9 @@ static const struct file_operations tracing_dyn_info_fops = {
74593 };
74594 #endif
74595
74596-static struct dentry *d_tracer;
74597-
74598 struct dentry *tracing_init_dentry(void)
74599 {
74600+ static struct dentry *d_tracer;
74601 static int once;
74602
74603 if (d_tracer)
74604@@ -4488,10 +4487,9 @@ struct dentry *tracing_init_dentry(void)
74605 return d_tracer;
74606 }
74607
74608-static struct dentry *d_percpu;
74609-
74610 struct dentry *tracing_dentry_percpu(void)
74611 {
74612+ static struct dentry *d_percpu;
74613 static int once;
74614 struct dentry *d_tracer;
74615
74616diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
74617index 880073d..42db7c3 100644
74618--- a/kernel/trace/trace_events.c
74619+++ b/kernel/trace/trace_events.c
74620@@ -1330,10 +1330,6 @@ static LIST_HEAD(ftrace_module_file_list);
74621 struct ftrace_module_file_ops {
74622 struct list_head list;
74623 struct module *mod;
74624- struct file_operations id;
74625- struct file_operations enable;
74626- struct file_operations format;
74627- struct file_operations filter;
74628 };
74629
74630 static struct ftrace_module_file_ops *
74631@@ -1354,17 +1350,12 @@ trace_create_file_ops(struct module *mod)
74632
74633 file_ops->mod = mod;
74634
74635- file_ops->id = ftrace_event_id_fops;
74636- file_ops->id.owner = mod;
74637-
74638- file_ops->enable = ftrace_enable_fops;
74639- file_ops->enable.owner = mod;
74640-
74641- file_ops->filter = ftrace_event_filter_fops;
74642- file_ops->filter.owner = mod;
74643-
74644- file_ops->format = ftrace_event_format_fops;
74645- file_ops->format.owner = mod;
74646+ pax_open_kernel();
74647+ mod->trace_id.owner = mod;
74648+ mod->trace_enable.owner = mod;
74649+ mod->trace_filter.owner = mod;
74650+ mod->trace_format.owner = mod;
74651+ pax_close_kernel();
74652
74653 list_add(&file_ops->list, &ftrace_module_file_list);
74654
74655@@ -1388,8 +1379,8 @@ static void trace_module_add_events(struct module *mod)
74656
74657 for_each_event(call, start, end) {
74658 __trace_add_event_call(*call, mod,
74659- &file_ops->id, &file_ops->enable,
74660- &file_ops->filter, &file_ops->format);
74661+ &mod->trace_id, &mod->trace_enable,
74662+ &mod->trace_filter, &mod->trace_format);
74663 }
74664 }
74665
74666diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
74667index fd3c8aa..5f324a6 100644
74668--- a/kernel/trace/trace_mmiotrace.c
74669+++ b/kernel/trace/trace_mmiotrace.c
74670@@ -24,7 +24,7 @@ struct header_iter {
74671 static struct trace_array *mmio_trace_array;
74672 static bool overrun_detected;
74673 static unsigned long prev_overruns;
74674-static atomic_t dropped_count;
74675+static atomic_unchecked_t dropped_count;
74676
74677 static void mmio_reset_data(struct trace_array *tr)
74678 {
74679@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
74680
74681 static unsigned long count_overruns(struct trace_iterator *iter)
74682 {
74683- unsigned long cnt = atomic_xchg(&dropped_count, 0);
74684+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
74685 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
74686
74687 if (over > prev_overruns)
74688@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
74689 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
74690 sizeof(*entry), 0, pc);
74691 if (!event) {
74692- atomic_inc(&dropped_count);
74693+ atomic_inc_unchecked(&dropped_count);
74694 return;
74695 }
74696 entry = ring_buffer_event_data(event);
74697@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
74698 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
74699 sizeof(*entry), 0, pc);
74700 if (!event) {
74701- atomic_inc(&dropped_count);
74702+ atomic_inc_unchecked(&dropped_count);
74703 return;
74704 }
74705 entry = ring_buffer_event_data(event);
74706diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
74707index 194d796..76edb8f 100644
74708--- a/kernel/trace/trace_output.c
74709+++ b/kernel/trace/trace_output.c
74710@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
74711
74712 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
74713 if (!IS_ERR(p)) {
74714- p = mangle_path(s->buffer + s->len, p, "\n");
74715+ p = mangle_path(s->buffer + s->len, p, "\n\\");
74716 if (p) {
74717 s->len = p - s->buffer;
74718 return 1;
74719@@ -852,14 +852,16 @@ int register_ftrace_event(struct trace_event *event)
74720 goto out;
74721 }
74722
74723+ pax_open_kernel();
74724 if (event->funcs->trace == NULL)
74725- event->funcs->trace = trace_nop_print;
74726+ *(void **)&event->funcs->trace = trace_nop_print;
74727 if (event->funcs->raw == NULL)
74728- event->funcs->raw = trace_nop_print;
74729+ *(void **)&event->funcs->raw = trace_nop_print;
74730 if (event->funcs->hex == NULL)
74731- event->funcs->hex = trace_nop_print;
74732+ *(void **)&event->funcs->hex = trace_nop_print;
74733 if (event->funcs->binary == NULL)
74734- event->funcs->binary = trace_nop_print;
74735+ *(void **)&event->funcs->binary = trace_nop_print;
74736+ pax_close_kernel();
74737
74738 key = event->type & (EVENT_HASHSIZE - 1);
74739
74740diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
74741index 42ca822..cdcacc6 100644
74742--- a/kernel/trace/trace_stack.c
74743+++ b/kernel/trace/trace_stack.c
74744@@ -52,7 +52,7 @@ static inline void check_stack(void)
74745 return;
74746
74747 /* we do not handle interrupt stacks yet */
74748- if (!object_is_on_stack(&this_size))
74749+ if (!object_starts_on_stack(&this_size))
74750 return;
74751
74752 local_irq_save(flags);
74753diff --git a/kernel/user.c b/kernel/user.c
74754index 33acb5e..57ebfd4 100644
74755--- a/kernel/user.c
74756+++ b/kernel/user.c
74757@@ -47,9 +47,7 @@ struct user_namespace init_user_ns = {
74758 .count = 4294967295U,
74759 },
74760 },
74761- .kref = {
74762- .refcount = ATOMIC_INIT(3),
74763- },
74764+ .count = ATOMIC_INIT(3),
74765 .owner = GLOBAL_ROOT_UID,
74766 .group = GLOBAL_ROOT_GID,
74767 .proc_inum = PROC_USER_INIT_INO,
74768diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
74769index 2b042c4..24f8ec3 100644
74770--- a/kernel/user_namespace.c
74771+++ b/kernel/user_namespace.c
74772@@ -78,7 +78,7 @@ int create_user_ns(struct cred *new)
74773 return ret;
74774 }
74775
74776- kref_init(&ns->kref);
74777+ atomic_set(&ns->count, 1);
74778 /* Leave the new->user_ns reference with the new user namespace. */
74779 ns->parent = parent_ns;
74780 ns->owner = owner;
74781@@ -104,15 +104,16 @@ int unshare_userns(unsigned long unshare_flags, struct cred **new_cred)
74782 return create_user_ns(cred);
74783 }
74784
74785-void free_user_ns(struct kref *kref)
74786+void free_user_ns(struct user_namespace *ns)
74787 {
74788- struct user_namespace *parent, *ns =
74789- container_of(kref, struct user_namespace, kref);
74790+ struct user_namespace *parent;
74791
74792- parent = ns->parent;
74793- proc_free_inum(ns->proc_inum);
74794- kmem_cache_free(user_ns_cachep, ns);
74795- put_user_ns(parent);
74796+ do {
74797+ parent = ns->parent;
74798+ proc_free_inum(ns->proc_inum);
74799+ kmem_cache_free(user_ns_cachep, ns);
74800+ ns = parent;
74801+ } while (atomic_dec_and_test(&parent->count));
74802 }
74803 EXPORT_SYMBOL(free_user_ns);
74804
74805diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
74806index 67604e5..3ebb003 100644
74807--- a/lib/Kconfig.debug
74808+++ b/lib/Kconfig.debug
74809@@ -1278,6 +1278,7 @@ config LATENCYTOP
74810 depends on DEBUG_KERNEL
74811 depends on STACKTRACE_SUPPORT
74812 depends on PROC_FS
74813+ depends on !GRKERNSEC_HIDESYM
74814 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
74815 select KALLSYMS
74816 select KALLSYMS_ALL
74817@@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
74818
74819 config PROVIDE_OHCI1394_DMA_INIT
74820 bool "Remote debugging over FireWire early on boot"
74821- depends on PCI && X86
74822+ depends on PCI && X86 && !GRKERNSEC
74823 help
74824 If you want to debug problems which hang or crash the kernel early
74825 on boot and the crashing machine has a FireWire port, you can use
74826@@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
74827
74828 config FIREWIRE_OHCI_REMOTE_DMA
74829 bool "Remote debugging over FireWire with firewire-ohci"
74830- depends on FIREWIRE_OHCI
74831+ depends on FIREWIRE_OHCI && !GRKERNSEC
74832 help
74833 This option lets you use the FireWire bus for remote debugging
74834 with help of the firewire-ohci driver. It enables unfiltered
74835diff --git a/lib/Makefile b/lib/Makefile
74836index 02ed6c0..bd243da 100644
74837--- a/lib/Makefile
74838+++ b/lib/Makefile
74839@@ -47,7 +47,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
74840
74841 obj-$(CONFIG_BTREE) += btree.o
74842 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
74843-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
74844+obj-y += list_debug.o
74845 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
74846
74847 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
74848diff --git a/lib/bitmap.c b/lib/bitmap.c
74849index 06f7e4f..f3cf2b0 100644
74850--- a/lib/bitmap.c
74851+++ b/lib/bitmap.c
74852@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
74853 {
74854 int c, old_c, totaldigits, ndigits, nchunks, nbits;
74855 u32 chunk;
74856- const char __user __force *ubuf = (const char __user __force *)buf;
74857+ const char __user *ubuf = (const char __force_user *)buf;
74858
74859 bitmap_zero(maskp, nmaskbits);
74860
74861@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
74862 {
74863 if (!access_ok(VERIFY_READ, ubuf, ulen))
74864 return -EFAULT;
74865- return __bitmap_parse((const char __force *)ubuf,
74866+ return __bitmap_parse((const char __force_kernel *)ubuf,
74867 ulen, 1, maskp, nmaskbits);
74868
74869 }
74870@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
74871 {
74872 unsigned a, b;
74873 int c, old_c, totaldigits;
74874- const char __user __force *ubuf = (const char __user __force *)buf;
74875+ const char __user *ubuf = (const char __force_user *)buf;
74876 int exp_digit, in_range;
74877
74878 totaldigits = c = 0;
74879@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
74880 {
74881 if (!access_ok(VERIFY_READ, ubuf, ulen))
74882 return -EFAULT;
74883- return __bitmap_parselist((const char __force *)ubuf,
74884+ return __bitmap_parselist((const char __force_kernel *)ubuf,
74885 ulen, 1, maskp, nmaskbits);
74886 }
74887 EXPORT_SYMBOL(bitmap_parselist_user);
74888diff --git a/lib/bug.c b/lib/bug.c
74889index d0cdf14..4d07bd2 100644
74890--- a/lib/bug.c
74891+++ b/lib/bug.c
74892@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
74893 return BUG_TRAP_TYPE_NONE;
74894
74895 bug = find_bug(bugaddr);
74896+ if (!bug)
74897+ return BUG_TRAP_TYPE_NONE;
74898
74899 file = NULL;
74900 line = 0;
74901diff --git a/lib/debugobjects.c b/lib/debugobjects.c
74902index d11808c..dc2d6f8 100644
74903--- a/lib/debugobjects.c
74904+++ b/lib/debugobjects.c
74905@@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
74906 if (limit > 4)
74907 return;
74908
74909- is_on_stack = object_is_on_stack(addr);
74910+ is_on_stack = object_starts_on_stack(addr);
74911 if (is_on_stack == onstack)
74912 return;
74913
74914diff --git a/lib/devres.c b/lib/devres.c
74915index 80b9c76..9e32279 100644
74916--- a/lib/devres.c
74917+++ b/lib/devres.c
74918@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
74919 void devm_iounmap(struct device *dev, void __iomem *addr)
74920 {
74921 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
74922- (void *)addr));
74923+ (void __force *)addr));
74924 iounmap(addr);
74925 }
74926 EXPORT_SYMBOL(devm_iounmap);
74927@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
74928 {
74929 ioport_unmap(addr);
74930 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
74931- devm_ioport_map_match, (void *)addr));
74932+ devm_ioport_map_match, (void __force *)addr));
74933 }
74934 EXPORT_SYMBOL(devm_ioport_unmap);
74935
74936diff --git a/lib/dma-debug.c b/lib/dma-debug.c
74937index 5e396ac..58d5de1 100644
74938--- a/lib/dma-debug.c
74939+++ b/lib/dma-debug.c
74940@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
74941
74942 void dma_debug_add_bus(struct bus_type *bus)
74943 {
74944- struct notifier_block *nb;
74945+ notifier_block_no_const *nb;
74946
74947 if (global_disable)
74948 return;
74949@@ -942,7 +942,7 @@ out:
74950
74951 static void check_for_stack(struct device *dev, void *addr)
74952 {
74953- if (object_is_on_stack(addr))
74954+ if (object_starts_on_stack(addr))
74955 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
74956 "stack [addr=%p]\n", addr);
74957 }
74958diff --git a/lib/idr.c b/lib/idr.c
74959index 6482390..ca5aa00 100644
74960--- a/lib/idr.c
74961+++ b/lib/idr.c
74962@@ -625,7 +625,14 @@ void *idr_get_next(struct idr *idp, int *nextidp)
74963 return p;
74964 }
74965
74966- id += 1 << n;
74967+ /*
74968+ * Proceed to the next layer at the current level. Unlike
74969+ * idr_for_each(), @id isn't guaranteed to be aligned to
74970+ * layer boundary at this point and adding 1 << n may
74971+ * incorrectly skip IDs. Make sure we jump to the
74972+ * beginning of the next layer using round_up().
74973+ */
74974+ id = round_up(id + 1, 1 << n);
74975 while (n < fls(id)) {
74976 n += IDR_BITS;
74977 p = *--paa;
74978diff --git a/lib/inflate.c b/lib/inflate.c
74979index 013a761..c28f3fc 100644
74980--- a/lib/inflate.c
74981+++ b/lib/inflate.c
74982@@ -269,7 +269,7 @@ static void free(void *where)
74983 malloc_ptr = free_mem_ptr;
74984 }
74985 #else
74986-#define malloc(a) kmalloc(a, GFP_KERNEL)
74987+#define malloc(a) kmalloc((a), GFP_KERNEL)
74988 #define free(a) kfree(a)
74989 #endif
74990
74991diff --git a/lib/ioremap.c b/lib/ioremap.c
74992index 0c9216c..863bd89 100644
74993--- a/lib/ioremap.c
74994+++ b/lib/ioremap.c
74995@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
74996 unsigned long next;
74997
74998 phys_addr -= addr;
74999- pmd = pmd_alloc(&init_mm, pud, addr);
75000+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
75001 if (!pmd)
75002 return -ENOMEM;
75003 do {
75004@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
75005 unsigned long next;
75006
75007 phys_addr -= addr;
75008- pud = pud_alloc(&init_mm, pgd, addr);
75009+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
75010 if (!pud)
75011 return -ENOMEM;
75012 do {
75013diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
75014index bd2bea9..6b3c95e 100644
75015--- a/lib/is_single_threaded.c
75016+++ b/lib/is_single_threaded.c
75017@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
75018 struct task_struct *p, *t;
75019 bool ret;
75020
75021+ if (!mm)
75022+ return true;
75023+
75024 if (atomic_read(&task->signal->live) != 1)
75025 return false;
75026
75027diff --git a/lib/list_debug.c b/lib/list_debug.c
75028index c24c2f7..3fc5da0 100644
75029--- a/lib/list_debug.c
75030+++ b/lib/list_debug.c
75031@@ -11,7 +11,9 @@
75032 #include <linux/bug.h>
75033 #include <linux/kernel.h>
75034 #include <linux/rculist.h>
75035+#include <linux/mm.h>
75036
75037+#ifdef CONFIG_DEBUG_LIST
75038 /*
75039 * Insert a new entry between two known consecutive entries.
75040 *
75041@@ -19,21 +21,32 @@
75042 * the prev/next entries already!
75043 */
75044
75045-void __list_add(struct list_head *new,
75046- struct list_head *prev,
75047- struct list_head *next)
75048+static bool __list_add_debug(struct list_head *new,
75049+ struct list_head *prev,
75050+ struct list_head *next)
75051 {
75052- WARN(next->prev != prev,
75053+ if (WARN(next->prev != prev,
75054 "list_add corruption. next->prev should be "
75055 "prev (%p), but was %p. (next=%p).\n",
75056- prev, next->prev, next);
75057- WARN(prev->next != next,
75058+ prev, next->prev, next) ||
75059+ WARN(prev->next != next,
75060 "list_add corruption. prev->next should be "
75061 "next (%p), but was %p. (prev=%p).\n",
75062- next, prev->next, prev);
75063- WARN(new == prev || new == next,
75064+ next, prev->next, prev) ||
75065+ WARN(new == prev || new == next,
75066 "list_add double add: new=%p, prev=%p, next=%p.\n",
75067- new, prev, next);
75068+ new, prev, next))
75069+ return false;
75070+ return true;
75071+}
75072+
75073+void __list_add(struct list_head *new,
75074+ struct list_head *prev,
75075+ struct list_head *next)
75076+{
75077+ if (!__list_add_debug(new, prev, next))
75078+ return;
75079+
75080 next->prev = new;
75081 new->next = next;
75082 new->prev = prev;
75083@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
75084 }
75085 EXPORT_SYMBOL(__list_add);
75086
75087-void __list_del_entry(struct list_head *entry)
75088+static bool __list_del_entry_debug(struct list_head *entry)
75089 {
75090 struct list_head *prev, *next;
75091
75092@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
75093 WARN(next->prev != entry,
75094 "list_del corruption. next->prev should be %p, "
75095 "but was %p\n", entry, next->prev))
75096+ return false;
75097+ return true;
75098+}
75099+
75100+void __list_del_entry(struct list_head *entry)
75101+{
75102+ if (!__list_del_entry_debug(entry))
75103 return;
75104
75105- __list_del(prev, next);
75106+ __list_del(entry->prev, entry->next);
75107 }
75108 EXPORT_SYMBOL(__list_del_entry);
75109
75110@@ -86,15 +106,54 @@ EXPORT_SYMBOL(list_del);
75111 void __list_add_rcu(struct list_head *new,
75112 struct list_head *prev, struct list_head *next)
75113 {
75114- WARN(next->prev != prev,
75115+ if (WARN(next->prev != prev,
75116 "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
75117- prev, next->prev, next);
75118- WARN(prev->next != next,
75119+ prev, next->prev, next) ||
75120+ WARN(prev->next != next,
75121 "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
75122- next, prev->next, prev);
75123+ next, prev->next, prev))
75124+ return;
75125+
75126 new->next = next;
75127 new->prev = prev;
75128 rcu_assign_pointer(list_next_rcu(prev), new);
75129 next->prev = new;
75130 }
75131 EXPORT_SYMBOL(__list_add_rcu);
75132+#endif
75133+
75134+void pax_list_add_tail(struct list_head *new, struct list_head *head)
75135+{
75136+ struct list_head *prev, *next;
75137+
75138+ prev = head->prev;
75139+ next = head;
75140+
75141+#ifdef CONFIG_DEBUG_LIST
75142+ if (!__list_add_debug(new, prev, next))
75143+ return;
75144+#endif
75145+
75146+ pax_open_kernel();
75147+ next->prev = new;
75148+ new->next = next;
75149+ new->prev = prev;
75150+ prev->next = new;
75151+ pax_close_kernel();
75152+}
75153+EXPORT_SYMBOL(pax_list_add_tail);
75154+
75155+void pax_list_del(struct list_head *entry)
75156+{
75157+#ifdef CONFIG_DEBUG_LIST
75158+ if (!__list_del_entry_debug(entry))
75159+ return;
75160+#endif
75161+
75162+ pax_open_kernel();
75163+ __list_del(entry->prev, entry->next);
75164+ entry->next = LIST_POISON1;
75165+ entry->prev = LIST_POISON2;
75166+ pax_close_kernel();
75167+}
75168+EXPORT_SYMBOL(pax_list_del);
75169diff --git a/lib/radix-tree.c b/lib/radix-tree.c
75170index e796429..6e38f9f 100644
75171--- a/lib/radix-tree.c
75172+++ b/lib/radix-tree.c
75173@@ -92,7 +92,7 @@ struct radix_tree_preload {
75174 int nr;
75175 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
75176 };
75177-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
75178+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
75179
75180 static inline void *ptr_to_indirect(void *ptr)
75181 {
75182diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
75183index bb2b201..46abaf9 100644
75184--- a/lib/strncpy_from_user.c
75185+++ b/lib/strncpy_from_user.c
75186@@ -21,7 +21,7 @@
75187 */
75188 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
75189 {
75190- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
75191+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
75192 long res = 0;
75193
75194 /*
75195diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
75196index a28df52..3d55877 100644
75197--- a/lib/strnlen_user.c
75198+++ b/lib/strnlen_user.c
75199@@ -26,7 +26,7 @@
75200 */
75201 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
75202 {
75203- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
75204+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
75205 long align, res = 0;
75206 unsigned long c;
75207
75208diff --git a/lib/vsprintf.c b/lib/vsprintf.c
75209index fab33a9..3b5fe68 100644
75210--- a/lib/vsprintf.c
75211+++ b/lib/vsprintf.c
75212@@ -16,6 +16,9 @@
75213 * - scnprintf and vscnprintf
75214 */
75215
75216+#ifdef CONFIG_GRKERNSEC_HIDESYM
75217+#define __INCLUDED_BY_HIDESYM 1
75218+#endif
75219 #include <stdarg.h>
75220 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
75221 #include <linux/types.h>
75222@@ -541,7 +544,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
75223 char sym[KSYM_SYMBOL_LEN];
75224 if (ext == 'B')
75225 sprint_backtrace(sym, value);
75226- else if (ext != 'f' && ext != 's')
75227+ else if (ext != 'f' && ext != 's' && ext != 'a')
75228 sprint_symbol(sym, value);
75229 else
75230 sprint_symbol_no_offset(sym, value);
75231@@ -974,7 +977,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
75232 return number(buf, end, *(const netdev_features_t *)addr, spec);
75233 }
75234
75235+#ifdef CONFIG_GRKERNSEC_HIDESYM
75236+int kptr_restrict __read_mostly = 2;
75237+#else
75238 int kptr_restrict __read_mostly;
75239+#endif
75240
75241 /*
75242 * Show a '%p' thing. A kernel extension is that the '%p' is followed
75243@@ -988,6 +995,8 @@ int kptr_restrict __read_mostly;
75244 * - 'S' For symbolic direct pointers with offset
75245 * - 's' For symbolic direct pointers without offset
75246 * - 'B' For backtraced symbolic direct pointers with offset
75247+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
75248+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
75249 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
75250 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
75251 * - 'M' For a 6-byte MAC address, it prints the address in the
75252@@ -1043,12 +1052,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
75253
75254 if (!ptr && *fmt != 'K') {
75255 /*
75256- * Print (null) with the same width as a pointer so it makes
75257+ * Print (nil) with the same width as a pointer so it makes
75258 * tabular output look nice.
75259 */
75260 if (spec.field_width == -1)
75261 spec.field_width = default_width;
75262- return string(buf, end, "(null)", spec);
75263+ return string(buf, end, "(nil)", spec);
75264 }
75265
75266 switch (*fmt) {
75267@@ -1058,6 +1067,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
75268 /* Fallthrough */
75269 case 'S':
75270 case 's':
75271+#ifdef CONFIG_GRKERNSEC_HIDESYM
75272+ break;
75273+#else
75274+ return symbol_string(buf, end, ptr, spec, *fmt);
75275+#endif
75276+ case 'A':
75277+ case 'a':
75278 case 'B':
75279 return symbol_string(buf, end, ptr, spec, *fmt);
75280 case 'R':
75281@@ -1098,6 +1114,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
75282 va_end(va);
75283 return buf;
75284 }
75285+ case 'P':
75286+ break;
75287 case 'K':
75288 /*
75289 * %pK cannot be used in IRQ context because its test
75290@@ -1121,6 +1139,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
75291 }
75292 break;
75293 }
75294+
75295+#ifdef CONFIG_GRKERNSEC_HIDESYM
75296+ /* 'P' = approved pointers to copy to userland,
75297+ as in the /proc/kallsyms case, as we make it display nothing
75298+ for non-root users, and the real contents for root users
75299+ Also ignore 'K' pointers, since we force their NULLing for non-root users
75300+ above
75301+ */
75302+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
75303+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
75304+ dump_stack();
75305+ ptr = NULL;
75306+ }
75307+#endif
75308+
75309 spec.flags |= SMALL;
75310 if (spec.field_width == -1) {
75311 spec.field_width = default_width;
75312@@ -1842,11 +1875,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
75313 typeof(type) value; \
75314 if (sizeof(type) == 8) { \
75315 args = PTR_ALIGN(args, sizeof(u32)); \
75316- *(u32 *)&value = *(u32 *)args; \
75317- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
75318+ *(u32 *)&value = *(const u32 *)args; \
75319+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
75320 } else { \
75321 args = PTR_ALIGN(args, sizeof(type)); \
75322- value = *(typeof(type) *)args; \
75323+ value = *(const typeof(type) *)args; \
75324 } \
75325 args += sizeof(type); \
75326 value; \
75327@@ -1909,7 +1942,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
75328 case FORMAT_TYPE_STR: {
75329 const char *str_arg = args;
75330 args += strlen(str_arg) + 1;
75331- str = string(str, end, (char *)str_arg, spec);
75332+ str = string(str, end, str_arg, spec);
75333 break;
75334 }
75335
75336diff --git a/localversion-grsec b/localversion-grsec
75337new file mode 100644
75338index 0000000..7cd6065
75339--- /dev/null
75340+++ b/localversion-grsec
75341@@ -0,0 +1 @@
75342+-grsec
75343diff --git a/mm/Kconfig b/mm/Kconfig
75344index 278e3ab..87c384d 100644
75345--- a/mm/Kconfig
75346+++ b/mm/Kconfig
75347@@ -286,10 +286,10 @@ config KSM
75348 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
75349
75350 config DEFAULT_MMAP_MIN_ADDR
75351- int "Low address space to protect from user allocation"
75352+ int "Low address space to protect from user allocation"
75353 depends on MMU
75354- default 4096
75355- help
75356+ default 65536
75357+ help
75358 This is the portion of low virtual memory which should be protected
75359 from userspace allocation. Keeping a user from writing to low pages
75360 can help reduce the impact of kernel NULL pointer bugs.
75361@@ -320,7 +320,7 @@ config MEMORY_FAILURE
75362
75363 config HWPOISON_INJECT
75364 tristate "HWPoison pages injector"
75365- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
75366+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
75367 select PROC_PAGE_MONITOR
75368
75369 config NOMMU_INITIAL_TRIM_EXCESS
75370diff --git a/mm/filemap.c b/mm/filemap.c
75371index 83efee7..3f99381 100644
75372--- a/mm/filemap.c
75373+++ b/mm/filemap.c
75374@@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
75375 struct address_space *mapping = file->f_mapping;
75376
75377 if (!mapping->a_ops->readpage)
75378- return -ENOEXEC;
75379+ return -ENODEV;
75380 file_accessed(file);
75381 vma->vm_ops = &generic_file_vm_ops;
75382 return 0;
75383@@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
75384 *pos = i_size_read(inode);
75385
75386 if (limit != RLIM_INFINITY) {
75387+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
75388 if (*pos >= limit) {
75389 send_sig(SIGXFSZ, current, 0);
75390 return -EFBIG;
75391diff --git a/mm/fremap.c b/mm/fremap.c
75392index a0aaf0e..20325c3 100644
75393--- a/mm/fremap.c
75394+++ b/mm/fremap.c
75395@@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
75396 retry:
75397 vma = find_vma(mm, start);
75398
75399+#ifdef CONFIG_PAX_SEGMEXEC
75400+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
75401+ goto out;
75402+#endif
75403+
75404 /*
75405 * Make sure the vma is shared, that it supports prefaulting,
75406 * and that the remapped range is valid and fully within
75407diff --git a/mm/highmem.c b/mm/highmem.c
75408index b32b70c..e512eb0 100644
75409--- a/mm/highmem.c
75410+++ b/mm/highmem.c
75411@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
75412 * So no dangers, even with speculative execution.
75413 */
75414 page = pte_page(pkmap_page_table[i]);
75415+ pax_open_kernel();
75416 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
75417-
75418+ pax_close_kernel();
75419 set_page_address(page, NULL);
75420 need_flush = 1;
75421 }
75422@@ -198,9 +199,11 @@ start:
75423 }
75424 }
75425 vaddr = PKMAP_ADDR(last_pkmap_nr);
75426+
75427+ pax_open_kernel();
75428 set_pte_at(&init_mm, vaddr,
75429 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
75430-
75431+ pax_close_kernel();
75432 pkmap_count[last_pkmap_nr] = 1;
75433 set_page_address(page, (void *)vaddr);
75434
75435diff --git a/mm/hugetlb.c b/mm/hugetlb.c
75436index 546db81..01d5c53 100644
75437--- a/mm/hugetlb.c
75438+++ b/mm/hugetlb.c
75439@@ -2511,6 +2511,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
75440 return 1;
75441 }
75442
75443+#ifdef CONFIG_PAX_SEGMEXEC
75444+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
75445+{
75446+ struct mm_struct *mm = vma->vm_mm;
75447+ struct vm_area_struct *vma_m;
75448+ unsigned long address_m;
75449+ pte_t *ptep_m;
75450+
75451+ vma_m = pax_find_mirror_vma(vma);
75452+ if (!vma_m)
75453+ return;
75454+
75455+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75456+ address_m = address + SEGMEXEC_TASK_SIZE;
75457+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
75458+ get_page(page_m);
75459+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
75460+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
75461+}
75462+#endif
75463+
75464 /*
75465 * Hugetlb_cow() should be called with page lock of the original hugepage held.
75466 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
75467@@ -2629,6 +2650,11 @@ retry_avoidcopy:
75468 make_huge_pte(vma, new_page, 1));
75469 page_remove_rmap(old_page);
75470 hugepage_add_new_anon_rmap(new_page, vma, address);
75471+
75472+#ifdef CONFIG_PAX_SEGMEXEC
75473+ pax_mirror_huge_pte(vma, address, new_page);
75474+#endif
75475+
75476 /* Make the old page be freed below */
75477 new_page = old_page;
75478 }
75479@@ -2788,6 +2814,10 @@ retry:
75480 && (vma->vm_flags & VM_SHARED)));
75481 set_huge_pte_at(mm, address, ptep, new_pte);
75482
75483+#ifdef CONFIG_PAX_SEGMEXEC
75484+ pax_mirror_huge_pte(vma, address, page);
75485+#endif
75486+
75487 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
75488 /* Optimization, do the COW without a second fault */
75489 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
75490@@ -2817,6 +2847,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75491 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
75492 struct hstate *h = hstate_vma(vma);
75493
75494+#ifdef CONFIG_PAX_SEGMEXEC
75495+ struct vm_area_struct *vma_m;
75496+#endif
75497+
75498 address &= huge_page_mask(h);
75499
75500 ptep = huge_pte_offset(mm, address);
75501@@ -2830,6 +2864,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75502 VM_FAULT_SET_HINDEX(hstate_index(h));
75503 }
75504
75505+#ifdef CONFIG_PAX_SEGMEXEC
75506+ vma_m = pax_find_mirror_vma(vma);
75507+ if (vma_m) {
75508+ unsigned long address_m;
75509+
75510+ if (vma->vm_start > vma_m->vm_start) {
75511+ address_m = address;
75512+ address -= SEGMEXEC_TASK_SIZE;
75513+ vma = vma_m;
75514+ h = hstate_vma(vma);
75515+ } else
75516+ address_m = address + SEGMEXEC_TASK_SIZE;
75517+
75518+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
75519+ return VM_FAULT_OOM;
75520+ address_m &= HPAGE_MASK;
75521+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
75522+ }
75523+#endif
75524+
75525 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
75526 if (!ptep)
75527 return VM_FAULT_OOM;
75528diff --git a/mm/internal.h b/mm/internal.h
75529index 9ba2110..eaf0674 100644
75530--- a/mm/internal.h
75531+++ b/mm/internal.h
75532@@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
75533 * in mm/page_alloc.c
75534 */
75535 extern void __free_pages_bootmem(struct page *page, unsigned int order);
75536+extern void free_compound_page(struct page *page);
75537 extern void prep_compound_page(struct page *page, unsigned long order);
75538 #ifdef CONFIG_MEMORY_FAILURE
75539 extern bool is_free_buddy_page(struct page *page);
75540diff --git a/mm/kmemleak.c b/mm/kmemleak.c
75541index 752a705..6c3102e 100644
75542--- a/mm/kmemleak.c
75543+++ b/mm/kmemleak.c
75544@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
75545
75546 for (i = 0; i < object->trace_len; i++) {
75547 void *ptr = (void *)object->trace[i];
75548- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
75549+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
75550 }
75551 }
75552
75553@@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
75554 return -ENOMEM;
75555 }
75556
75557- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
75558+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
75559 &kmemleak_fops);
75560 if (!dentry)
75561 pr_warning("Failed to create the debugfs kmemleak file\n");
75562diff --git a/mm/maccess.c b/mm/maccess.c
75563index d53adf9..03a24bf 100644
75564--- a/mm/maccess.c
75565+++ b/mm/maccess.c
75566@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
75567 set_fs(KERNEL_DS);
75568 pagefault_disable();
75569 ret = __copy_from_user_inatomic(dst,
75570- (__force const void __user *)src, size);
75571+ (const void __force_user *)src, size);
75572 pagefault_enable();
75573 set_fs(old_fs);
75574
75575@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
75576
75577 set_fs(KERNEL_DS);
75578 pagefault_disable();
75579- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
75580+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
75581 pagefault_enable();
75582 set_fs(old_fs);
75583
75584diff --git a/mm/madvise.c b/mm/madvise.c
75585index 03dfa5c..b032917 100644
75586--- a/mm/madvise.c
75587+++ b/mm/madvise.c
75588@@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
75589 pgoff_t pgoff;
75590 unsigned long new_flags = vma->vm_flags;
75591
75592+#ifdef CONFIG_PAX_SEGMEXEC
75593+ struct vm_area_struct *vma_m;
75594+#endif
75595+
75596 switch (behavior) {
75597 case MADV_NORMAL:
75598 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
75599@@ -123,6 +127,13 @@ success:
75600 /*
75601 * vm_flags is protected by the mmap_sem held in write mode.
75602 */
75603+
75604+#ifdef CONFIG_PAX_SEGMEXEC
75605+ vma_m = pax_find_mirror_vma(vma);
75606+ if (vma_m)
75607+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
75608+#endif
75609+
75610 vma->vm_flags = new_flags;
75611
75612 out:
75613@@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
75614 struct vm_area_struct ** prev,
75615 unsigned long start, unsigned long end)
75616 {
75617+
75618+#ifdef CONFIG_PAX_SEGMEXEC
75619+ struct vm_area_struct *vma_m;
75620+#endif
75621+
75622 *prev = vma;
75623 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
75624 return -EINVAL;
75625@@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
75626 zap_page_range(vma, start, end - start, &details);
75627 } else
75628 zap_page_range(vma, start, end - start, NULL);
75629+
75630+#ifdef CONFIG_PAX_SEGMEXEC
75631+ vma_m = pax_find_mirror_vma(vma);
75632+ if (vma_m) {
75633+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
75634+ struct zap_details details = {
75635+ .nonlinear_vma = vma_m,
75636+ .last_index = ULONG_MAX,
75637+ };
75638+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
75639+ } else
75640+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
75641+ }
75642+#endif
75643+
75644 return 0;
75645 }
75646
75647@@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
75648 if (end < start)
75649 goto out;
75650
75651+#ifdef CONFIG_PAX_SEGMEXEC
75652+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
75653+ if (end > SEGMEXEC_TASK_SIZE)
75654+ goto out;
75655+ } else
75656+#endif
75657+
75658+ if (end > TASK_SIZE)
75659+ goto out;
75660+
75661 error = 0;
75662 if (end == start)
75663 goto out;
75664diff --git a/mm/memory-failure.c b/mm/memory-failure.c
75665index c6e4dd3..fdb2ca6 100644
75666--- a/mm/memory-failure.c
75667+++ b/mm/memory-failure.c
75668@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
75669
75670 int sysctl_memory_failure_recovery __read_mostly = 1;
75671
75672-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
75673+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
75674
75675 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
75676
75677@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
75678 pfn, t->comm, t->pid);
75679 si.si_signo = SIGBUS;
75680 si.si_errno = 0;
75681- si.si_addr = (void *)addr;
75682+ si.si_addr = (void __user *)addr;
75683 #ifdef __ARCH_SI_TRAPNO
75684 si.si_trapno = trapno;
75685 #endif
75686@@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
75687 }
75688
75689 nr_pages = 1 << compound_trans_order(hpage);
75690- atomic_long_add(nr_pages, &mce_bad_pages);
75691+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
75692
75693 /*
75694 * We need/can do nothing about count=0 pages.
75695@@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
75696 if (!PageHWPoison(hpage)
75697 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
75698 || (p != hpage && TestSetPageHWPoison(hpage))) {
75699- atomic_long_sub(nr_pages, &mce_bad_pages);
75700+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
75701 return 0;
75702 }
75703 set_page_hwpoison_huge_page(hpage);
75704@@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
75705 }
75706 if (hwpoison_filter(p)) {
75707 if (TestClearPageHWPoison(p))
75708- atomic_long_sub(nr_pages, &mce_bad_pages);
75709+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
75710 unlock_page(hpage);
75711 put_page(hpage);
75712 return 0;
75713@@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
75714 return 0;
75715 }
75716 if (TestClearPageHWPoison(p))
75717- atomic_long_sub(nr_pages, &mce_bad_pages);
75718+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
75719 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
75720 return 0;
75721 }
75722@@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
75723 */
75724 if (TestClearPageHWPoison(page)) {
75725 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
75726- atomic_long_sub(nr_pages, &mce_bad_pages);
75727+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
75728 freeit = 1;
75729 if (PageHuge(page))
75730 clear_page_hwpoison_huge_page(page);
75731@@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
75732 }
75733 done:
75734 if (!PageHWPoison(hpage))
75735- atomic_long_add(1 << compound_trans_order(hpage),
75736+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
75737 &mce_bad_pages);
75738 set_page_hwpoison_huge_page(hpage);
75739 dequeue_hwpoisoned_huge_page(hpage);
75740@@ -1583,7 +1583,7 @@ int soft_offline_page(struct page *page, int flags)
75741 return ret;
75742
75743 done:
75744- atomic_long_add(1, &mce_bad_pages);
75745+ atomic_long_add_unchecked(1, &mce_bad_pages);
75746 SetPageHWPoison(page);
75747 /* keep elevated page count for bad page */
75748 return ret;
75749diff --git a/mm/memory.c b/mm/memory.c
75750index bb1369f..efb96b5 100644
75751--- a/mm/memory.c
75752+++ b/mm/memory.c
75753@@ -433,6 +433,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
75754 free_pte_range(tlb, pmd, addr);
75755 } while (pmd++, addr = next, addr != end);
75756
75757+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
75758 start &= PUD_MASK;
75759 if (start < floor)
75760 return;
75761@@ -447,6 +448,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
75762 pmd = pmd_offset(pud, start);
75763 pud_clear(pud);
75764 pmd_free_tlb(tlb, pmd, start);
75765+#endif
75766+
75767 }
75768
75769 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
75770@@ -466,6 +469,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
75771 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
75772 } while (pud++, addr = next, addr != end);
75773
75774+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
75775 start &= PGDIR_MASK;
75776 if (start < floor)
75777 return;
75778@@ -480,6 +484,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
75779 pud = pud_offset(pgd, start);
75780 pgd_clear(pgd);
75781 pud_free_tlb(tlb, pud, start);
75782+#endif
75783+
75784 }
75785
75786 /*
75787@@ -1618,12 +1624,6 @@ no_page_table:
75788 return page;
75789 }
75790
75791-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
75792-{
75793- return stack_guard_page_start(vma, addr) ||
75794- stack_guard_page_end(vma, addr+PAGE_SIZE);
75795-}
75796-
75797 /**
75798 * __get_user_pages() - pin user pages in memory
75799 * @tsk: task_struct of target task
75800@@ -1709,10 +1709,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75801
75802 i = 0;
75803
75804- do {
75805+ while (nr_pages) {
75806 struct vm_area_struct *vma;
75807
75808- vma = find_extend_vma(mm, start);
75809+ vma = find_vma(mm, start);
75810 if (!vma && in_gate_area(mm, start)) {
75811 unsigned long pg = start & PAGE_MASK;
75812 pgd_t *pgd;
75813@@ -1760,7 +1760,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75814 goto next_page;
75815 }
75816
75817- if (!vma ||
75818+ if (!vma || start < vma->vm_start ||
75819 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
75820 !(vm_flags & vma->vm_flags))
75821 return i ? : -EFAULT;
75822@@ -1787,11 +1787,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75823 int ret;
75824 unsigned int fault_flags = 0;
75825
75826- /* For mlock, just skip the stack guard page. */
75827- if (foll_flags & FOLL_MLOCK) {
75828- if (stack_guard_page(vma, start))
75829- goto next_page;
75830- }
75831 if (foll_flags & FOLL_WRITE)
75832 fault_flags |= FAULT_FLAG_WRITE;
75833 if (nonblocking)
75834@@ -1865,7 +1860,7 @@ next_page:
75835 start += PAGE_SIZE;
75836 nr_pages--;
75837 } while (nr_pages && start < vma->vm_end);
75838- } while (nr_pages);
75839+ }
75840 return i;
75841 }
75842 EXPORT_SYMBOL(__get_user_pages);
75843@@ -2072,6 +2067,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
75844 page_add_file_rmap(page);
75845 set_pte_at(mm, addr, pte, mk_pte(page, prot));
75846
75847+#ifdef CONFIG_PAX_SEGMEXEC
75848+ pax_mirror_file_pte(vma, addr, page, ptl);
75849+#endif
75850+
75851 retval = 0;
75852 pte_unmap_unlock(pte, ptl);
75853 return retval;
75854@@ -2116,9 +2115,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
75855 if (!page_count(page))
75856 return -EINVAL;
75857 if (!(vma->vm_flags & VM_MIXEDMAP)) {
75858+
75859+#ifdef CONFIG_PAX_SEGMEXEC
75860+ struct vm_area_struct *vma_m;
75861+#endif
75862+
75863 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
75864 BUG_ON(vma->vm_flags & VM_PFNMAP);
75865 vma->vm_flags |= VM_MIXEDMAP;
75866+
75867+#ifdef CONFIG_PAX_SEGMEXEC
75868+ vma_m = pax_find_mirror_vma(vma);
75869+ if (vma_m)
75870+ vma_m->vm_flags |= VM_MIXEDMAP;
75871+#endif
75872+
75873 }
75874 return insert_page(vma, addr, page, vma->vm_page_prot);
75875 }
75876@@ -2201,6 +2212,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
75877 unsigned long pfn)
75878 {
75879 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
75880+ BUG_ON(vma->vm_mirror);
75881
75882 if (addr < vma->vm_start || addr >= vma->vm_end)
75883 return -EFAULT;
75884@@ -2401,7 +2413,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
75885
75886 BUG_ON(pud_huge(*pud));
75887
75888- pmd = pmd_alloc(mm, pud, addr);
75889+ pmd = (mm == &init_mm) ?
75890+ pmd_alloc_kernel(mm, pud, addr) :
75891+ pmd_alloc(mm, pud, addr);
75892 if (!pmd)
75893 return -ENOMEM;
75894 do {
75895@@ -2421,7 +2435,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
75896 unsigned long next;
75897 int err;
75898
75899- pud = pud_alloc(mm, pgd, addr);
75900+ pud = (mm == &init_mm) ?
75901+ pud_alloc_kernel(mm, pgd, addr) :
75902+ pud_alloc(mm, pgd, addr);
75903 if (!pud)
75904 return -ENOMEM;
75905 do {
75906@@ -2509,6 +2525,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
75907 copy_user_highpage(dst, src, va, vma);
75908 }
75909
75910+#ifdef CONFIG_PAX_SEGMEXEC
75911+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
75912+{
75913+ struct mm_struct *mm = vma->vm_mm;
75914+ spinlock_t *ptl;
75915+ pte_t *pte, entry;
75916+
75917+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
75918+ entry = *pte;
75919+ if (!pte_present(entry)) {
75920+ if (!pte_none(entry)) {
75921+ BUG_ON(pte_file(entry));
75922+ free_swap_and_cache(pte_to_swp_entry(entry));
75923+ pte_clear_not_present_full(mm, address, pte, 0);
75924+ }
75925+ } else {
75926+ struct page *page;
75927+
75928+ flush_cache_page(vma, address, pte_pfn(entry));
75929+ entry = ptep_clear_flush(vma, address, pte);
75930+ BUG_ON(pte_dirty(entry));
75931+ page = vm_normal_page(vma, address, entry);
75932+ if (page) {
75933+ update_hiwater_rss(mm);
75934+ if (PageAnon(page))
75935+ dec_mm_counter_fast(mm, MM_ANONPAGES);
75936+ else
75937+ dec_mm_counter_fast(mm, MM_FILEPAGES);
75938+ page_remove_rmap(page);
75939+ page_cache_release(page);
75940+ }
75941+ }
75942+ pte_unmap_unlock(pte, ptl);
75943+}
75944+
75945+/* PaX: if vma is mirrored, synchronize the mirror's PTE
75946+ *
75947+ * the ptl of the lower mapped page is held on entry and is not released on exit
75948+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
75949+ */
75950+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
75951+{
75952+ struct mm_struct *mm = vma->vm_mm;
75953+ unsigned long address_m;
75954+ spinlock_t *ptl_m;
75955+ struct vm_area_struct *vma_m;
75956+ pmd_t *pmd_m;
75957+ pte_t *pte_m, entry_m;
75958+
75959+ BUG_ON(!page_m || !PageAnon(page_m));
75960+
75961+ vma_m = pax_find_mirror_vma(vma);
75962+ if (!vma_m)
75963+ return;
75964+
75965+ BUG_ON(!PageLocked(page_m));
75966+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75967+ address_m = address + SEGMEXEC_TASK_SIZE;
75968+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
75969+ pte_m = pte_offset_map(pmd_m, address_m);
75970+ ptl_m = pte_lockptr(mm, pmd_m);
75971+ if (ptl != ptl_m) {
75972+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
75973+ if (!pte_none(*pte_m))
75974+ goto out;
75975+ }
75976+
75977+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
75978+ page_cache_get(page_m);
75979+ page_add_anon_rmap(page_m, vma_m, address_m);
75980+ inc_mm_counter_fast(mm, MM_ANONPAGES);
75981+ set_pte_at(mm, address_m, pte_m, entry_m);
75982+ update_mmu_cache(vma_m, address_m, entry_m);
75983+out:
75984+ if (ptl != ptl_m)
75985+ spin_unlock(ptl_m);
75986+ pte_unmap(pte_m);
75987+ unlock_page(page_m);
75988+}
75989+
75990+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
75991+{
75992+ struct mm_struct *mm = vma->vm_mm;
75993+ unsigned long address_m;
75994+ spinlock_t *ptl_m;
75995+ struct vm_area_struct *vma_m;
75996+ pmd_t *pmd_m;
75997+ pte_t *pte_m, entry_m;
75998+
75999+ BUG_ON(!page_m || PageAnon(page_m));
76000+
76001+ vma_m = pax_find_mirror_vma(vma);
76002+ if (!vma_m)
76003+ return;
76004+
76005+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
76006+ address_m = address + SEGMEXEC_TASK_SIZE;
76007+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
76008+ pte_m = pte_offset_map(pmd_m, address_m);
76009+ ptl_m = pte_lockptr(mm, pmd_m);
76010+ if (ptl != ptl_m) {
76011+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
76012+ if (!pte_none(*pte_m))
76013+ goto out;
76014+ }
76015+
76016+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
76017+ page_cache_get(page_m);
76018+ page_add_file_rmap(page_m);
76019+ inc_mm_counter_fast(mm, MM_FILEPAGES);
76020+ set_pte_at(mm, address_m, pte_m, entry_m);
76021+ update_mmu_cache(vma_m, address_m, entry_m);
76022+out:
76023+ if (ptl != ptl_m)
76024+ spin_unlock(ptl_m);
76025+ pte_unmap(pte_m);
76026+}
76027+
76028+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
76029+{
76030+ struct mm_struct *mm = vma->vm_mm;
76031+ unsigned long address_m;
76032+ spinlock_t *ptl_m;
76033+ struct vm_area_struct *vma_m;
76034+ pmd_t *pmd_m;
76035+ pte_t *pte_m, entry_m;
76036+
76037+ vma_m = pax_find_mirror_vma(vma);
76038+ if (!vma_m)
76039+ return;
76040+
76041+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
76042+ address_m = address + SEGMEXEC_TASK_SIZE;
76043+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
76044+ pte_m = pte_offset_map(pmd_m, address_m);
76045+ ptl_m = pte_lockptr(mm, pmd_m);
76046+ if (ptl != ptl_m) {
76047+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
76048+ if (!pte_none(*pte_m))
76049+ goto out;
76050+ }
76051+
76052+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
76053+ set_pte_at(mm, address_m, pte_m, entry_m);
76054+out:
76055+ if (ptl != ptl_m)
76056+ spin_unlock(ptl_m);
76057+ pte_unmap(pte_m);
76058+}
76059+
76060+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
76061+{
76062+ struct page *page_m;
76063+ pte_t entry;
76064+
76065+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
76066+ goto out;
76067+
76068+ entry = *pte;
76069+ page_m = vm_normal_page(vma, address, entry);
76070+ if (!page_m)
76071+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
76072+ else if (PageAnon(page_m)) {
76073+ if (pax_find_mirror_vma(vma)) {
76074+ pte_unmap_unlock(pte, ptl);
76075+ lock_page(page_m);
76076+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
76077+ if (pte_same(entry, *pte))
76078+ pax_mirror_anon_pte(vma, address, page_m, ptl);
76079+ else
76080+ unlock_page(page_m);
76081+ }
76082+ } else
76083+ pax_mirror_file_pte(vma, address, page_m, ptl);
76084+
76085+out:
76086+ pte_unmap_unlock(pte, ptl);
76087+}
76088+#endif
76089+
76090 /*
76091 * This routine handles present pages, when users try to write
76092 * to a shared page. It is done by copying the page to a new address
76093@@ -2725,6 +2921,12 @@ gotten:
76094 */
76095 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
76096 if (likely(pte_same(*page_table, orig_pte))) {
76097+
76098+#ifdef CONFIG_PAX_SEGMEXEC
76099+ if (pax_find_mirror_vma(vma))
76100+ BUG_ON(!trylock_page(new_page));
76101+#endif
76102+
76103 if (old_page) {
76104 if (!PageAnon(old_page)) {
76105 dec_mm_counter_fast(mm, MM_FILEPAGES);
76106@@ -2776,6 +2978,10 @@ gotten:
76107 page_remove_rmap(old_page);
76108 }
76109
76110+#ifdef CONFIG_PAX_SEGMEXEC
76111+ pax_mirror_anon_pte(vma, address, new_page, ptl);
76112+#endif
76113+
76114 /* Free the old page.. */
76115 new_page = old_page;
76116 ret |= VM_FAULT_WRITE;
76117@@ -3051,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
76118 swap_free(entry);
76119 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
76120 try_to_free_swap(page);
76121+
76122+#ifdef CONFIG_PAX_SEGMEXEC
76123+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
76124+#endif
76125+
76126 unlock_page(page);
76127 if (swapcache) {
76128 /*
76129@@ -3074,6 +3285,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
76130
76131 /* No need to invalidate - it was non-present before */
76132 update_mmu_cache(vma, address, page_table);
76133+
76134+#ifdef CONFIG_PAX_SEGMEXEC
76135+ pax_mirror_anon_pte(vma, address, page, ptl);
76136+#endif
76137+
76138 unlock:
76139 pte_unmap_unlock(page_table, ptl);
76140 out:
76141@@ -3093,40 +3309,6 @@ out_release:
76142 }
76143
76144 /*
76145- * This is like a special single-page "expand_{down|up}wards()",
76146- * except we must first make sure that 'address{-|+}PAGE_SIZE'
76147- * doesn't hit another vma.
76148- */
76149-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
76150-{
76151- address &= PAGE_MASK;
76152- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
76153- struct vm_area_struct *prev = vma->vm_prev;
76154-
76155- /*
76156- * Is there a mapping abutting this one below?
76157- *
76158- * That's only ok if it's the same stack mapping
76159- * that has gotten split..
76160- */
76161- if (prev && prev->vm_end == address)
76162- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
76163-
76164- expand_downwards(vma, address - PAGE_SIZE);
76165- }
76166- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
76167- struct vm_area_struct *next = vma->vm_next;
76168-
76169- /* As VM_GROWSDOWN but s/below/above/ */
76170- if (next && next->vm_start == address + PAGE_SIZE)
76171- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
76172-
76173- expand_upwards(vma, address + PAGE_SIZE);
76174- }
76175- return 0;
76176-}
76177-
76178-/*
76179 * We enter with non-exclusive mmap_sem (to exclude vma changes,
76180 * but allow concurrent faults), and pte mapped but not yet locked.
76181 * We return with mmap_sem still held, but pte unmapped and unlocked.
76182@@ -3135,27 +3317,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
76183 unsigned long address, pte_t *page_table, pmd_t *pmd,
76184 unsigned int flags)
76185 {
76186- struct page *page;
76187+ struct page *page = NULL;
76188 spinlock_t *ptl;
76189 pte_t entry;
76190
76191- pte_unmap(page_table);
76192-
76193- /* Check if we need to add a guard page to the stack */
76194- if (check_stack_guard_page(vma, address) < 0)
76195- return VM_FAULT_SIGBUS;
76196-
76197- /* Use the zero-page for reads */
76198 if (!(flags & FAULT_FLAG_WRITE)) {
76199 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
76200 vma->vm_page_prot));
76201- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
76202+ ptl = pte_lockptr(mm, pmd);
76203+ spin_lock(ptl);
76204 if (!pte_none(*page_table))
76205 goto unlock;
76206 goto setpte;
76207 }
76208
76209 /* Allocate our own private page. */
76210+ pte_unmap(page_table);
76211+
76212 if (unlikely(anon_vma_prepare(vma)))
76213 goto oom;
76214 page = alloc_zeroed_user_highpage_movable(vma, address);
76215@@ -3174,6 +3352,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
76216 if (!pte_none(*page_table))
76217 goto release;
76218
76219+#ifdef CONFIG_PAX_SEGMEXEC
76220+ if (pax_find_mirror_vma(vma))
76221+ BUG_ON(!trylock_page(page));
76222+#endif
76223+
76224 inc_mm_counter_fast(mm, MM_ANONPAGES);
76225 page_add_new_anon_rmap(page, vma, address);
76226 setpte:
76227@@ -3181,6 +3364,12 @@ setpte:
76228
76229 /* No need to invalidate - it was non-present before */
76230 update_mmu_cache(vma, address, page_table);
76231+
76232+#ifdef CONFIG_PAX_SEGMEXEC
76233+ if (page)
76234+ pax_mirror_anon_pte(vma, address, page, ptl);
76235+#endif
76236+
76237 unlock:
76238 pte_unmap_unlock(page_table, ptl);
76239 return 0;
76240@@ -3324,6 +3513,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76241 */
76242 /* Only go through if we didn't race with anybody else... */
76243 if (likely(pte_same(*page_table, orig_pte))) {
76244+
76245+#ifdef CONFIG_PAX_SEGMEXEC
76246+ if (anon && pax_find_mirror_vma(vma))
76247+ BUG_ON(!trylock_page(page));
76248+#endif
76249+
76250 flush_icache_page(vma, page);
76251 entry = mk_pte(page, vma->vm_page_prot);
76252 if (flags & FAULT_FLAG_WRITE)
76253@@ -3343,6 +3538,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76254
76255 /* no need to invalidate: a not-present page won't be cached */
76256 update_mmu_cache(vma, address, page_table);
76257+
76258+#ifdef CONFIG_PAX_SEGMEXEC
76259+ if (anon)
76260+ pax_mirror_anon_pte(vma, address, page, ptl);
76261+ else
76262+ pax_mirror_file_pte(vma, address, page, ptl);
76263+#endif
76264+
76265 } else {
76266 if (cow_page)
76267 mem_cgroup_uncharge_page(cow_page);
76268@@ -3664,6 +3867,12 @@ int handle_pte_fault(struct mm_struct *mm,
76269 if (flags & FAULT_FLAG_WRITE)
76270 flush_tlb_fix_spurious_fault(vma, address);
76271 }
76272+
76273+#ifdef CONFIG_PAX_SEGMEXEC
76274+ pax_mirror_pte(vma, address, pte, pmd, ptl);
76275+ return 0;
76276+#endif
76277+
76278 unlock:
76279 pte_unmap_unlock(pte, ptl);
76280 return 0;
76281@@ -3680,6 +3889,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76282 pmd_t *pmd;
76283 pte_t *pte;
76284
76285+#ifdef CONFIG_PAX_SEGMEXEC
76286+ struct vm_area_struct *vma_m;
76287+#endif
76288+
76289 __set_current_state(TASK_RUNNING);
76290
76291 count_vm_event(PGFAULT);
76292@@ -3691,6 +3904,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76293 if (unlikely(is_vm_hugetlb_page(vma)))
76294 return hugetlb_fault(mm, vma, address, flags);
76295
76296+#ifdef CONFIG_PAX_SEGMEXEC
76297+ vma_m = pax_find_mirror_vma(vma);
76298+ if (vma_m) {
76299+ unsigned long address_m;
76300+ pgd_t *pgd_m;
76301+ pud_t *pud_m;
76302+ pmd_t *pmd_m;
76303+
76304+ if (vma->vm_start > vma_m->vm_start) {
76305+ address_m = address;
76306+ address -= SEGMEXEC_TASK_SIZE;
76307+ vma = vma_m;
76308+ } else
76309+ address_m = address + SEGMEXEC_TASK_SIZE;
76310+
76311+ pgd_m = pgd_offset(mm, address_m);
76312+ pud_m = pud_alloc(mm, pgd_m, address_m);
76313+ if (!pud_m)
76314+ return VM_FAULT_OOM;
76315+ pmd_m = pmd_alloc(mm, pud_m, address_m);
76316+ if (!pmd_m)
76317+ return VM_FAULT_OOM;
76318+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
76319+ return VM_FAULT_OOM;
76320+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
76321+ }
76322+#endif
76323+
76324 retry:
76325 pgd = pgd_offset(mm, address);
76326 pud = pud_alloc(mm, pgd, address);
76327@@ -3789,6 +4030,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
76328 spin_unlock(&mm->page_table_lock);
76329 return 0;
76330 }
76331+
76332+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
76333+{
76334+ pud_t *new = pud_alloc_one(mm, address);
76335+ if (!new)
76336+ return -ENOMEM;
76337+
76338+ smp_wmb(); /* See comment in __pte_alloc */
76339+
76340+ spin_lock(&mm->page_table_lock);
76341+ if (pgd_present(*pgd)) /* Another has populated it */
76342+ pud_free(mm, new);
76343+ else
76344+ pgd_populate_kernel(mm, pgd, new);
76345+ spin_unlock(&mm->page_table_lock);
76346+ return 0;
76347+}
76348 #endif /* __PAGETABLE_PUD_FOLDED */
76349
76350 #ifndef __PAGETABLE_PMD_FOLDED
76351@@ -3819,6 +4077,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
76352 spin_unlock(&mm->page_table_lock);
76353 return 0;
76354 }
76355+
76356+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
76357+{
76358+ pmd_t *new = pmd_alloc_one(mm, address);
76359+ if (!new)
76360+ return -ENOMEM;
76361+
76362+ smp_wmb(); /* See comment in __pte_alloc */
76363+
76364+ spin_lock(&mm->page_table_lock);
76365+#ifndef __ARCH_HAS_4LEVEL_HACK
76366+ if (pud_present(*pud)) /* Another has populated it */
76367+ pmd_free(mm, new);
76368+ else
76369+ pud_populate_kernel(mm, pud, new);
76370+#else
76371+ if (pgd_present(*pud)) /* Another has populated it */
76372+ pmd_free(mm, new);
76373+ else
76374+ pgd_populate_kernel(mm, pud, new);
76375+#endif /* __ARCH_HAS_4LEVEL_HACK */
76376+ spin_unlock(&mm->page_table_lock);
76377+ return 0;
76378+}
76379 #endif /* __PAGETABLE_PMD_FOLDED */
76380
76381 int make_pages_present(unsigned long addr, unsigned long end)
76382@@ -3856,7 +4138,7 @@ static int __init gate_vma_init(void)
76383 gate_vma.vm_start = FIXADDR_USER_START;
76384 gate_vma.vm_end = FIXADDR_USER_END;
76385 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
76386- gate_vma.vm_page_prot = __P101;
76387+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
76388
76389 return 0;
76390 }
76391diff --git a/mm/mempolicy.c b/mm/mempolicy.c
76392index e2df1c1..1e31d57 100644
76393--- a/mm/mempolicy.c
76394+++ b/mm/mempolicy.c
76395@@ -721,6 +721,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
76396 unsigned long vmstart;
76397 unsigned long vmend;
76398
76399+#ifdef CONFIG_PAX_SEGMEXEC
76400+ struct vm_area_struct *vma_m;
76401+#endif
76402+
76403 vma = find_vma(mm, start);
76404 if (!vma || vma->vm_start > start)
76405 return -EFAULT;
76406@@ -757,9 +761,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
76407 if (err)
76408 goto out;
76409 }
76410+
76411 err = vma_replace_policy(vma, new_pol);
76412 if (err)
76413 goto out;
76414+
76415+#ifdef CONFIG_PAX_SEGMEXEC
76416+ vma_m = pax_find_mirror_vma(vma);
76417+ if (vma_m) {
76418+ err = vma_replace_policy(vma_m, new_pol);
76419+ if (err)
76420+ goto out;
76421+ }
76422+#endif
76423+
76424 }
76425
76426 out:
76427@@ -1216,6 +1231,17 @@ static long do_mbind(unsigned long start, unsigned long len,
76428
76429 if (end < start)
76430 return -EINVAL;
76431+
76432+#ifdef CONFIG_PAX_SEGMEXEC
76433+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
76434+ if (end > SEGMEXEC_TASK_SIZE)
76435+ return -EINVAL;
76436+ } else
76437+#endif
76438+
76439+ if (end > TASK_SIZE)
76440+ return -EINVAL;
76441+
76442 if (end == start)
76443 return 0;
76444
76445@@ -1445,8 +1471,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
76446 */
76447 tcred = __task_cred(task);
76448 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
76449- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
76450- !capable(CAP_SYS_NICE)) {
76451+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
76452 rcu_read_unlock();
76453 err = -EPERM;
76454 goto out_put;
76455@@ -1477,6 +1502,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
76456 goto out;
76457 }
76458
76459+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76460+ if (mm != current->mm &&
76461+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
76462+ mmput(mm);
76463+ err = -EPERM;
76464+ goto out;
76465+ }
76466+#endif
76467+
76468 err = do_migrate_pages(mm, old, new,
76469 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
76470
76471diff --git a/mm/migrate.c b/mm/migrate.c
76472index 2fd8b4a..d70358f 100644
76473--- a/mm/migrate.c
76474+++ b/mm/migrate.c
76475@@ -1401,8 +1401,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
76476 */
76477 tcred = __task_cred(task);
76478 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
76479- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
76480- !capable(CAP_SYS_NICE)) {
76481+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
76482 rcu_read_unlock();
76483 err = -EPERM;
76484 goto out;
76485diff --git a/mm/mlock.c b/mm/mlock.c
76486index c9bd528..da8d069 100644
76487--- a/mm/mlock.c
76488+++ b/mm/mlock.c
76489@@ -13,6 +13,7 @@
76490 #include <linux/pagemap.h>
76491 #include <linux/mempolicy.h>
76492 #include <linux/syscalls.h>
76493+#include <linux/security.h>
76494 #include <linux/sched.h>
76495 #include <linux/export.h>
76496 #include <linux/rmap.h>
76497@@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
76498 {
76499 unsigned long nstart, end, tmp;
76500 struct vm_area_struct * vma, * prev;
76501- int error;
76502+ int error = 0;
76503
76504 VM_BUG_ON(start & ~PAGE_MASK);
76505 VM_BUG_ON(len != PAGE_ALIGN(len));
76506@@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
76507 return -EINVAL;
76508 if (end == start)
76509 return 0;
76510+ if (end > TASK_SIZE)
76511+ return -EINVAL;
76512+
76513 vma = find_vma(current->mm, start);
76514 if (!vma || vma->vm_start > start)
76515 return -ENOMEM;
76516@@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
76517 for (nstart = start ; ; ) {
76518 vm_flags_t newflags;
76519
76520+#ifdef CONFIG_PAX_SEGMEXEC
76521+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
76522+ break;
76523+#endif
76524+
76525 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
76526
76527 newflags = vma->vm_flags | VM_LOCKED;
76528@@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
76529 lock_limit >>= PAGE_SHIFT;
76530
76531 /* check against resource limits */
76532+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
76533 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
76534 error = do_mlock(start, len, 1);
76535 up_write(&current->mm->mmap_sem);
76536@@ -528,6 +538,12 @@ static int do_mlockall(int flags)
76537 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
76538 vm_flags_t newflags;
76539
76540+#ifdef CONFIG_PAX_SEGMEXEC
76541+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
76542+ break;
76543+#endif
76544+
76545+ BUG_ON(vma->vm_end > TASK_SIZE);
76546 newflags = vma->vm_flags | VM_LOCKED;
76547 if (!(flags & MCL_CURRENT))
76548 newflags &= ~VM_LOCKED;
76549@@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
76550 lock_limit >>= PAGE_SHIFT;
76551
76552 ret = -ENOMEM;
76553+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
76554 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
76555 capable(CAP_IPC_LOCK))
76556 ret = do_mlockall(flags);
76557diff --git a/mm/mmap.c b/mm/mmap.c
76558index d1e4124..7d36e4f 100644
76559--- a/mm/mmap.c
76560+++ b/mm/mmap.c
76561@@ -32,6 +32,7 @@
76562 #include <linux/khugepaged.h>
76563 #include <linux/uprobes.h>
76564 #include <linux/rbtree_augmented.h>
76565+#include <linux/random.h>
76566
76567 #include <asm/uaccess.h>
76568 #include <asm/cacheflush.h>
76569@@ -48,6 +49,16 @@
76570 #define arch_rebalance_pgtables(addr, len) (addr)
76571 #endif
76572
76573+static inline void verify_mm_writelocked(struct mm_struct *mm)
76574+{
76575+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
76576+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
76577+ up_read(&mm->mmap_sem);
76578+ BUG();
76579+ }
76580+#endif
76581+}
76582+
76583 static void unmap_region(struct mm_struct *mm,
76584 struct vm_area_struct *vma, struct vm_area_struct *prev,
76585 unsigned long start, unsigned long end);
76586@@ -67,22 +78,32 @@ static void unmap_region(struct mm_struct *mm,
76587 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
76588 *
76589 */
76590-pgprot_t protection_map[16] = {
76591+pgprot_t protection_map[16] __read_only = {
76592 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
76593 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
76594 };
76595
76596-pgprot_t vm_get_page_prot(unsigned long vm_flags)
76597+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
76598 {
76599- return __pgprot(pgprot_val(protection_map[vm_flags &
76600+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
76601 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
76602 pgprot_val(arch_vm_get_page_prot(vm_flags)));
76603+
76604+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76605+ if (!(__supported_pte_mask & _PAGE_NX) &&
76606+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
76607+ (vm_flags & (VM_READ | VM_WRITE)))
76608+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
76609+#endif
76610+
76611+ return prot;
76612 }
76613 EXPORT_SYMBOL(vm_get_page_prot);
76614
76615 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
76616 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
76617 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
76618+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
76619 /*
76620 * Make sure vm_committed_as in one cacheline and not cacheline shared with
76621 * other variables. It can be updated by several CPUs frequently.
76622@@ -238,6 +259,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
76623 struct vm_area_struct *next = vma->vm_next;
76624
76625 might_sleep();
76626+ BUG_ON(vma->vm_mirror);
76627 if (vma->vm_ops && vma->vm_ops->close)
76628 vma->vm_ops->close(vma);
76629 if (vma->vm_file)
76630@@ -281,6 +303,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
76631 * not page aligned -Ram Gupta
76632 */
76633 rlim = rlimit(RLIMIT_DATA);
76634+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
76635 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
76636 (mm->end_data - mm->start_data) > rlim)
76637 goto out;
76638@@ -888,6 +911,12 @@ static int
76639 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
76640 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
76641 {
76642+
76643+#ifdef CONFIG_PAX_SEGMEXEC
76644+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
76645+ return 0;
76646+#endif
76647+
76648 if (is_mergeable_vma(vma, file, vm_flags) &&
76649 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
76650 if (vma->vm_pgoff == vm_pgoff)
76651@@ -907,6 +936,12 @@ static int
76652 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
76653 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
76654 {
76655+
76656+#ifdef CONFIG_PAX_SEGMEXEC
76657+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
76658+ return 0;
76659+#endif
76660+
76661 if (is_mergeable_vma(vma, file, vm_flags) &&
76662 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
76663 pgoff_t vm_pglen;
76664@@ -949,13 +984,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
76665 struct vm_area_struct *vma_merge(struct mm_struct *mm,
76666 struct vm_area_struct *prev, unsigned long addr,
76667 unsigned long end, unsigned long vm_flags,
76668- struct anon_vma *anon_vma, struct file *file,
76669+ struct anon_vma *anon_vma, struct file *file,
76670 pgoff_t pgoff, struct mempolicy *policy)
76671 {
76672 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
76673 struct vm_area_struct *area, *next;
76674 int err;
76675
76676+#ifdef CONFIG_PAX_SEGMEXEC
76677+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
76678+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
76679+
76680+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
76681+#endif
76682+
76683 /*
76684 * We later require that vma->vm_flags == vm_flags,
76685 * so this tests vma->vm_flags & VM_SPECIAL, too.
76686@@ -971,6 +1013,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
76687 if (next && next->vm_end == end) /* cases 6, 7, 8 */
76688 next = next->vm_next;
76689
76690+#ifdef CONFIG_PAX_SEGMEXEC
76691+ if (prev)
76692+ prev_m = pax_find_mirror_vma(prev);
76693+ if (area)
76694+ area_m = pax_find_mirror_vma(area);
76695+ if (next)
76696+ next_m = pax_find_mirror_vma(next);
76697+#endif
76698+
76699 /*
76700 * Can it merge with the predecessor?
76701 */
76702@@ -990,9 +1041,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
76703 /* cases 1, 6 */
76704 err = vma_adjust(prev, prev->vm_start,
76705 next->vm_end, prev->vm_pgoff, NULL);
76706- } else /* cases 2, 5, 7 */
76707+
76708+#ifdef CONFIG_PAX_SEGMEXEC
76709+ if (!err && prev_m)
76710+ err = vma_adjust(prev_m, prev_m->vm_start,
76711+ next_m->vm_end, prev_m->vm_pgoff, NULL);
76712+#endif
76713+
76714+ } else { /* cases 2, 5, 7 */
76715 err = vma_adjust(prev, prev->vm_start,
76716 end, prev->vm_pgoff, NULL);
76717+
76718+#ifdef CONFIG_PAX_SEGMEXEC
76719+ if (!err && prev_m)
76720+ err = vma_adjust(prev_m, prev_m->vm_start,
76721+ end_m, prev_m->vm_pgoff, NULL);
76722+#endif
76723+
76724+ }
76725 if (err)
76726 return NULL;
76727 khugepaged_enter_vma_merge(prev);
76728@@ -1006,12 +1072,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
76729 mpol_equal(policy, vma_policy(next)) &&
76730 can_vma_merge_before(next, vm_flags,
76731 anon_vma, file, pgoff+pglen)) {
76732- if (prev && addr < prev->vm_end) /* case 4 */
76733+ if (prev && addr < prev->vm_end) { /* case 4 */
76734 err = vma_adjust(prev, prev->vm_start,
76735 addr, prev->vm_pgoff, NULL);
76736- else /* cases 3, 8 */
76737+
76738+#ifdef CONFIG_PAX_SEGMEXEC
76739+ if (!err && prev_m)
76740+ err = vma_adjust(prev_m, prev_m->vm_start,
76741+ addr_m, prev_m->vm_pgoff, NULL);
76742+#endif
76743+
76744+ } else { /* cases 3, 8 */
76745 err = vma_adjust(area, addr, next->vm_end,
76746 next->vm_pgoff - pglen, NULL);
76747+
76748+#ifdef CONFIG_PAX_SEGMEXEC
76749+ if (!err && area_m)
76750+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
76751+ next_m->vm_pgoff - pglen, NULL);
76752+#endif
76753+
76754+ }
76755 if (err)
76756 return NULL;
76757 khugepaged_enter_vma_merge(area);
76758@@ -1120,16 +1201,13 @@ none:
76759 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
76760 struct file *file, long pages)
76761 {
76762- const unsigned long stack_flags
76763- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
76764-
76765 mm->total_vm += pages;
76766
76767 if (file) {
76768 mm->shared_vm += pages;
76769 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
76770 mm->exec_vm += pages;
76771- } else if (flags & stack_flags)
76772+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
76773 mm->stack_vm += pages;
76774 }
76775 #endif /* CONFIG_PROC_FS */
76776@@ -1165,7 +1243,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76777 * (the exception is when the underlying filesystem is noexec
76778 * mounted, in which case we dont add PROT_EXEC.)
76779 */
76780- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
76781+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
76782 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
76783 prot |= PROT_EXEC;
76784
76785@@ -1191,7 +1269,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76786 /* Obtain the address to map to. we verify (or select) it and ensure
76787 * that it represents a valid section of the address space.
76788 */
76789- addr = get_unmapped_area(file, addr, len, pgoff, flags);
76790+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
76791 if (addr & ~PAGE_MASK)
76792 return addr;
76793
76794@@ -1202,6 +1280,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76795 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
76796 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
76797
76798+#ifdef CONFIG_PAX_MPROTECT
76799+ if (mm->pax_flags & MF_PAX_MPROTECT) {
76800+#ifndef CONFIG_PAX_MPROTECT_COMPAT
76801+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
76802+ gr_log_rwxmmap(file);
76803+
76804+#ifdef CONFIG_PAX_EMUPLT
76805+ vm_flags &= ~VM_EXEC;
76806+#else
76807+ return -EPERM;
76808+#endif
76809+
76810+ }
76811+
76812+ if (!(vm_flags & VM_EXEC))
76813+ vm_flags &= ~VM_MAYEXEC;
76814+#else
76815+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
76816+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
76817+#endif
76818+ else
76819+ vm_flags &= ~VM_MAYWRITE;
76820+ }
76821+#endif
76822+
76823+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76824+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
76825+ vm_flags &= ~VM_PAGEEXEC;
76826+#endif
76827+
76828 if (flags & MAP_LOCKED)
76829 if (!can_do_mlock())
76830 return -EPERM;
76831@@ -1213,6 +1321,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76832 locked += mm->locked_vm;
76833 lock_limit = rlimit(RLIMIT_MEMLOCK);
76834 lock_limit >>= PAGE_SHIFT;
76835+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
76836 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
76837 return -EAGAIN;
76838 }
76839@@ -1279,6 +1388,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76840 }
76841 }
76842
76843+ if (!gr_acl_handle_mmap(file, prot))
76844+ return -EACCES;
76845+
76846 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
76847 }
76848
76849@@ -1356,7 +1468,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
76850 vm_flags_t vm_flags = vma->vm_flags;
76851
76852 /* If it was private or non-writable, the write bit is already clear */
76853- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
76854+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
76855 return 0;
76856
76857 /* The backer wishes to know when pages are first written to? */
76858@@ -1405,13 +1517,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
76859 unsigned long charged = 0;
76860 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
76861
76862+#ifdef CONFIG_PAX_SEGMEXEC
76863+ struct vm_area_struct *vma_m = NULL;
76864+#endif
76865+
76866+ /*
76867+ * mm->mmap_sem is required to protect against another thread
76868+ * changing the mappings in case we sleep.
76869+ */
76870+ verify_mm_writelocked(mm);
76871+
76872 /* Clear old maps */
76873 error = -ENOMEM;
76874-munmap_back:
76875 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
76876 if (do_munmap(mm, addr, len))
76877 return -ENOMEM;
76878- goto munmap_back;
76879+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
76880 }
76881
76882 /* Check against address space limit. */
76883@@ -1460,6 +1581,16 @@ munmap_back:
76884 goto unacct_error;
76885 }
76886
76887+#ifdef CONFIG_PAX_SEGMEXEC
76888+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
76889+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76890+ if (!vma_m) {
76891+ error = -ENOMEM;
76892+ goto free_vma;
76893+ }
76894+ }
76895+#endif
76896+
76897 vma->vm_mm = mm;
76898 vma->vm_start = addr;
76899 vma->vm_end = addr + len;
76900@@ -1484,6 +1615,13 @@ munmap_back:
76901 if (error)
76902 goto unmap_and_free_vma;
76903
76904+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76905+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
76906+ vma->vm_flags |= VM_PAGEEXEC;
76907+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
76908+ }
76909+#endif
76910+
76911 /* Can addr have changed??
76912 *
76913 * Answer: Yes, several device drivers can do it in their
76914@@ -1522,6 +1660,11 @@ munmap_back:
76915 vma_link(mm, vma, prev, rb_link, rb_parent);
76916 file = vma->vm_file;
76917
76918+#ifdef CONFIG_PAX_SEGMEXEC
76919+ if (vma_m)
76920+ BUG_ON(pax_mirror_vma(vma_m, vma));
76921+#endif
76922+
76923 /* Once vma denies write, undo our temporary denial count */
76924 if (correct_wcount)
76925 atomic_inc(&inode->i_writecount);
76926@@ -1529,6 +1672,7 @@ out:
76927 perf_event_mmap(vma);
76928
76929 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
76930+ track_exec_limit(mm, addr, addr + len, vm_flags);
76931 if (vm_flags & VM_LOCKED) {
76932 if (!mlock_vma_pages_range(vma, addr, addr + len))
76933 mm->locked_vm += (len >> PAGE_SHIFT);
76934@@ -1550,6 +1694,12 @@ unmap_and_free_vma:
76935 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
76936 charged = 0;
76937 free_vma:
76938+
76939+#ifdef CONFIG_PAX_SEGMEXEC
76940+ if (vma_m)
76941+ kmem_cache_free(vm_area_cachep, vma_m);
76942+#endif
76943+
76944 kmem_cache_free(vm_area_cachep, vma);
76945 unacct_error:
76946 if (charged)
76947@@ -1557,6 +1707,62 @@ unacct_error:
76948 return error;
76949 }
76950
76951+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
76952+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
76953+{
76954+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
76955+ return (random32() & 0xFF) << PAGE_SHIFT;
76956+
76957+ return 0;
76958+}
76959+#endif
76960+
76961+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
76962+{
76963+ if (!vma) {
76964+#ifdef CONFIG_STACK_GROWSUP
76965+ if (addr > sysctl_heap_stack_gap)
76966+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
76967+ else
76968+ vma = find_vma(current->mm, 0);
76969+ if (vma && (vma->vm_flags & VM_GROWSUP))
76970+ return false;
76971+#endif
76972+ return true;
76973+ }
76974+
76975+ if (addr + len > vma->vm_start)
76976+ return false;
76977+
76978+ if (vma->vm_flags & VM_GROWSDOWN)
76979+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
76980+#ifdef CONFIG_STACK_GROWSUP
76981+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
76982+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
76983+#endif
76984+ else if (offset)
76985+ return offset <= vma->vm_start - addr - len;
76986+
76987+ return true;
76988+}
76989+
76990+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
76991+{
76992+ if (vma->vm_start < len)
76993+ return -ENOMEM;
76994+
76995+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
76996+ if (offset <= vma->vm_start - len)
76997+ return vma->vm_start - len - offset;
76998+ else
76999+ return -ENOMEM;
77000+ }
77001+
77002+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
77003+ return vma->vm_start - len - sysctl_heap_stack_gap;
77004+ return -ENOMEM;
77005+}
77006+
77007 unsigned long unmapped_area(struct vm_unmapped_area_info *info)
77008 {
77009 /*
77010@@ -1776,6 +1982,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
77011 struct mm_struct *mm = current->mm;
77012 struct vm_area_struct *vma;
77013 struct vm_unmapped_area_info info;
77014+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
77015
77016 if (len > TASK_SIZE)
77017 return -ENOMEM;
77018@@ -1783,17 +1990,26 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
77019 if (flags & MAP_FIXED)
77020 return addr;
77021
77022+#ifdef CONFIG_PAX_RANDMMAP
77023+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
77024+#endif
77025+
77026 if (addr) {
77027 addr = PAGE_ALIGN(addr);
77028 vma = find_vma(mm, addr);
77029- if (TASK_SIZE - len >= addr &&
77030- (!vma || addr + len <= vma->vm_start))
77031+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
77032 return addr;
77033 }
77034
77035 info.flags = 0;
77036 info.length = len;
77037 info.low_limit = TASK_UNMAPPED_BASE;
77038+
77039+#ifdef CONFIG_PAX_RANDMMAP
77040+ if (mm->pax_flags & MF_PAX_RANDMMAP)
77041+ info.low_limit += mm->delta_mmap;
77042+#endif
77043+
77044 info.high_limit = TASK_SIZE;
77045 info.align_mask = 0;
77046 return vm_unmapped_area(&info);
77047@@ -1802,10 +2018,16 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
77048
77049 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
77050 {
77051+
77052+#ifdef CONFIG_PAX_SEGMEXEC
77053+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
77054+ return;
77055+#endif
77056+
77057 /*
77058 * Is this a new hole at the lowest possible address?
77059 */
77060- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
77061+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
77062 mm->free_area_cache = addr;
77063 }
77064
77065@@ -1823,6 +2045,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
77066 struct mm_struct *mm = current->mm;
77067 unsigned long addr = addr0;
77068 struct vm_unmapped_area_info info;
77069+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
77070
77071 /* requested length too big for entire address space */
77072 if (len > TASK_SIZE)
77073@@ -1831,12 +2054,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
77074 if (flags & MAP_FIXED)
77075 return addr;
77076
77077+#ifdef CONFIG_PAX_RANDMMAP
77078+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
77079+#endif
77080+
77081 /* requesting a specific address */
77082 if (addr) {
77083 addr = PAGE_ALIGN(addr);
77084 vma = find_vma(mm, addr);
77085- if (TASK_SIZE - len >= addr &&
77086- (!vma || addr + len <= vma->vm_start))
77087+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
77088 return addr;
77089 }
77090
77091@@ -1857,6 +2083,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
77092 VM_BUG_ON(addr != -ENOMEM);
77093 info.flags = 0;
77094 info.low_limit = TASK_UNMAPPED_BASE;
77095+
77096+#ifdef CONFIG_PAX_RANDMMAP
77097+ if (mm->pax_flags & MF_PAX_RANDMMAP)
77098+ info.low_limit += mm->delta_mmap;
77099+#endif
77100+
77101 info.high_limit = TASK_SIZE;
77102 addr = vm_unmapped_area(&info);
77103 }
77104@@ -1867,6 +2099,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
77105
77106 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
77107 {
77108+
77109+#ifdef CONFIG_PAX_SEGMEXEC
77110+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
77111+ return;
77112+#endif
77113+
77114 /*
77115 * Is this a new hole at the highest possible address?
77116 */
77117@@ -1874,8 +2112,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
77118 mm->free_area_cache = addr;
77119
77120 /* dont allow allocations above current base */
77121- if (mm->free_area_cache > mm->mmap_base)
77122+ if (mm->free_area_cache > mm->mmap_base) {
77123 mm->free_area_cache = mm->mmap_base;
77124+ mm->cached_hole_size = ~0UL;
77125+ }
77126 }
77127
77128 unsigned long
77129@@ -1974,6 +2214,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
77130 return vma;
77131 }
77132
77133+#ifdef CONFIG_PAX_SEGMEXEC
77134+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
77135+{
77136+ struct vm_area_struct *vma_m;
77137+
77138+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
77139+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
77140+ BUG_ON(vma->vm_mirror);
77141+ return NULL;
77142+ }
77143+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
77144+ vma_m = vma->vm_mirror;
77145+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
77146+ BUG_ON(vma->vm_file != vma_m->vm_file);
77147+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
77148+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
77149+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
77150+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
77151+ return vma_m;
77152+}
77153+#endif
77154+
77155 /*
77156 * Verify that the stack growth is acceptable and
77157 * update accounting. This is shared with both the
77158@@ -1990,6 +2252,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
77159 return -ENOMEM;
77160
77161 /* Stack limit test */
77162+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
77163 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
77164 return -ENOMEM;
77165
77166@@ -2000,6 +2263,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
77167 locked = mm->locked_vm + grow;
77168 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
77169 limit >>= PAGE_SHIFT;
77170+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
77171 if (locked > limit && !capable(CAP_IPC_LOCK))
77172 return -ENOMEM;
77173 }
77174@@ -2029,37 +2293,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
77175 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
77176 * vma is the last one with address > vma->vm_end. Have to extend vma.
77177 */
77178+#ifndef CONFIG_IA64
77179+static
77180+#endif
77181 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
77182 {
77183 int error;
77184+ bool locknext;
77185
77186 if (!(vma->vm_flags & VM_GROWSUP))
77187 return -EFAULT;
77188
77189+ /* Also guard against wrapping around to address 0. */
77190+ if (address < PAGE_ALIGN(address+1))
77191+ address = PAGE_ALIGN(address+1);
77192+ else
77193+ return -ENOMEM;
77194+
77195 /*
77196 * We must make sure the anon_vma is allocated
77197 * so that the anon_vma locking is not a noop.
77198 */
77199 if (unlikely(anon_vma_prepare(vma)))
77200 return -ENOMEM;
77201+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
77202+ if (locknext && anon_vma_prepare(vma->vm_next))
77203+ return -ENOMEM;
77204 vma_lock_anon_vma(vma);
77205+ if (locknext)
77206+ vma_lock_anon_vma(vma->vm_next);
77207
77208 /*
77209 * vma->vm_start/vm_end cannot change under us because the caller
77210 * is required to hold the mmap_sem in read mode. We need the
77211- * anon_vma lock to serialize against concurrent expand_stacks.
77212- * Also guard against wrapping around to address 0.
77213+ * anon_vma locks to serialize against concurrent expand_stacks
77214+ * and expand_upwards.
77215 */
77216- if (address < PAGE_ALIGN(address+4))
77217- address = PAGE_ALIGN(address+4);
77218- else {
77219- vma_unlock_anon_vma(vma);
77220- return -ENOMEM;
77221- }
77222 error = 0;
77223
77224 /* Somebody else might have raced and expanded it already */
77225- if (address > vma->vm_end) {
77226+ 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)
77227+ error = -ENOMEM;
77228+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
77229 unsigned long size, grow;
77230
77231 size = address - vma->vm_start;
77232@@ -2094,6 +2369,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
77233 }
77234 }
77235 }
77236+ if (locknext)
77237+ vma_unlock_anon_vma(vma->vm_next);
77238 vma_unlock_anon_vma(vma);
77239 khugepaged_enter_vma_merge(vma);
77240 validate_mm(vma->vm_mm);
77241@@ -2108,6 +2385,8 @@ int expand_downwards(struct vm_area_struct *vma,
77242 unsigned long address)
77243 {
77244 int error;
77245+ bool lockprev = false;
77246+ struct vm_area_struct *prev;
77247
77248 /*
77249 * We must make sure the anon_vma is allocated
77250@@ -2121,6 +2400,15 @@ int expand_downwards(struct vm_area_struct *vma,
77251 if (error)
77252 return error;
77253
77254+ prev = vma->vm_prev;
77255+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
77256+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
77257+#endif
77258+ if (lockprev && anon_vma_prepare(prev))
77259+ return -ENOMEM;
77260+ if (lockprev)
77261+ vma_lock_anon_vma(prev);
77262+
77263 vma_lock_anon_vma(vma);
77264
77265 /*
77266@@ -2130,9 +2418,17 @@ int expand_downwards(struct vm_area_struct *vma,
77267 */
77268
77269 /* Somebody else might have raced and expanded it already */
77270- if (address < vma->vm_start) {
77271+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
77272+ error = -ENOMEM;
77273+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
77274 unsigned long size, grow;
77275
77276+#ifdef CONFIG_PAX_SEGMEXEC
77277+ struct vm_area_struct *vma_m;
77278+
77279+ vma_m = pax_find_mirror_vma(vma);
77280+#endif
77281+
77282 size = vma->vm_end - address;
77283 grow = (vma->vm_start - address) >> PAGE_SHIFT;
77284
77285@@ -2157,6 +2453,18 @@ int expand_downwards(struct vm_area_struct *vma,
77286 vma->vm_pgoff -= grow;
77287 anon_vma_interval_tree_post_update_vma(vma);
77288 vma_gap_update(vma);
77289+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
77290+
77291+#ifdef CONFIG_PAX_SEGMEXEC
77292+ if (vma_m) {
77293+ anon_vma_interval_tree_pre_update_vma(vma_m);
77294+ vma_m->vm_start -= grow << PAGE_SHIFT;
77295+ vma_m->vm_pgoff -= grow;
77296+ anon_vma_interval_tree_post_update_vma(vma_m);
77297+ vma_gap_update(vma_m);
77298+ }
77299+#endif
77300+
77301 spin_unlock(&vma->vm_mm->page_table_lock);
77302
77303 perf_event_mmap(vma);
77304@@ -2169,9 +2477,28 @@ int expand_downwards(struct vm_area_struct *vma,
77305 return error;
77306 }
77307
77308+/*
77309+ * Note how expand_stack() refuses to expand the stack all the way to
77310+ * abut the next virtual mapping, *unless* that mapping itself is also
77311+ * a stack mapping. We want to leave room for a guard page, after all
77312+ * (the guard page itself is not added here, that is done by the
77313+ * actual page faulting logic)
77314+ *
77315+ * This matches the behavior of the guard page logic (see mm/memory.c:
77316+ * check_stack_guard_page()), which only allows the guard page to be
77317+ * removed under these circumstances.
77318+ */
77319 #ifdef CONFIG_STACK_GROWSUP
77320 int expand_stack(struct vm_area_struct *vma, unsigned long address)
77321 {
77322+ struct vm_area_struct *next;
77323+
77324+ address &= PAGE_MASK;
77325+ next = vma->vm_next;
77326+ if (next && next->vm_start == address + PAGE_SIZE) {
77327+ if (!(next->vm_flags & VM_GROWSUP))
77328+ return -ENOMEM;
77329+ }
77330 return expand_upwards(vma, address);
77331 }
77332
77333@@ -2194,6 +2521,14 @@ find_extend_vma(struct mm_struct *mm, unsigned long addr)
77334 #else
77335 int expand_stack(struct vm_area_struct *vma, unsigned long address)
77336 {
77337+ struct vm_area_struct *prev;
77338+
77339+ address &= PAGE_MASK;
77340+ prev = vma->vm_prev;
77341+ if (prev && prev->vm_end == address) {
77342+ if (!(prev->vm_flags & VM_GROWSDOWN))
77343+ return -ENOMEM;
77344+ }
77345 return expand_downwards(vma, address);
77346 }
77347
77348@@ -2236,6 +2571,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
77349 do {
77350 long nrpages = vma_pages(vma);
77351
77352+#ifdef CONFIG_PAX_SEGMEXEC
77353+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
77354+ vma = remove_vma(vma);
77355+ continue;
77356+ }
77357+#endif
77358+
77359 if (vma->vm_flags & VM_ACCOUNT)
77360 nr_accounted += nrpages;
77361 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
77362@@ -2281,6 +2623,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
77363 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
77364 vma->vm_prev = NULL;
77365 do {
77366+
77367+#ifdef CONFIG_PAX_SEGMEXEC
77368+ if (vma->vm_mirror) {
77369+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
77370+ vma->vm_mirror->vm_mirror = NULL;
77371+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
77372+ vma->vm_mirror = NULL;
77373+ }
77374+#endif
77375+
77376 vma_rb_erase(vma, &mm->mm_rb);
77377 mm->map_count--;
77378 tail_vma = vma;
77379@@ -2312,14 +2664,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77380 struct vm_area_struct *new;
77381 int err = -ENOMEM;
77382
77383+#ifdef CONFIG_PAX_SEGMEXEC
77384+ struct vm_area_struct *vma_m, *new_m = NULL;
77385+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
77386+#endif
77387+
77388 if (is_vm_hugetlb_page(vma) && (addr &
77389 ~(huge_page_mask(hstate_vma(vma)))))
77390 return -EINVAL;
77391
77392+#ifdef CONFIG_PAX_SEGMEXEC
77393+ vma_m = pax_find_mirror_vma(vma);
77394+#endif
77395+
77396 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
77397 if (!new)
77398 goto out_err;
77399
77400+#ifdef CONFIG_PAX_SEGMEXEC
77401+ if (vma_m) {
77402+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
77403+ if (!new_m) {
77404+ kmem_cache_free(vm_area_cachep, new);
77405+ goto out_err;
77406+ }
77407+ }
77408+#endif
77409+
77410 /* most fields are the same, copy all, and then fixup */
77411 *new = *vma;
77412
77413@@ -2332,6 +2703,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77414 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
77415 }
77416
77417+#ifdef CONFIG_PAX_SEGMEXEC
77418+ if (vma_m) {
77419+ *new_m = *vma_m;
77420+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
77421+ new_m->vm_mirror = new;
77422+ new->vm_mirror = new_m;
77423+
77424+ if (new_below)
77425+ new_m->vm_end = addr_m;
77426+ else {
77427+ new_m->vm_start = addr_m;
77428+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
77429+ }
77430+ }
77431+#endif
77432+
77433 pol = mpol_dup(vma_policy(vma));
77434 if (IS_ERR(pol)) {
77435 err = PTR_ERR(pol);
77436@@ -2354,6 +2741,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77437 else
77438 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
77439
77440+#ifdef CONFIG_PAX_SEGMEXEC
77441+ if (!err && vma_m) {
77442+ if (anon_vma_clone(new_m, vma_m))
77443+ goto out_free_mpol;
77444+
77445+ mpol_get(pol);
77446+ vma_set_policy(new_m, pol);
77447+
77448+ if (new_m->vm_file)
77449+ get_file(new_m->vm_file);
77450+
77451+ if (new_m->vm_ops && new_m->vm_ops->open)
77452+ new_m->vm_ops->open(new_m);
77453+
77454+ if (new_below)
77455+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
77456+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
77457+ else
77458+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
77459+
77460+ if (err) {
77461+ if (new_m->vm_ops && new_m->vm_ops->close)
77462+ new_m->vm_ops->close(new_m);
77463+ if (new_m->vm_file)
77464+ fput(new_m->vm_file);
77465+ mpol_put(pol);
77466+ }
77467+ }
77468+#endif
77469+
77470 /* Success. */
77471 if (!err)
77472 return 0;
77473@@ -2363,10 +2780,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77474 new->vm_ops->close(new);
77475 if (new->vm_file)
77476 fput(new->vm_file);
77477- unlink_anon_vmas(new);
77478 out_free_mpol:
77479 mpol_put(pol);
77480 out_free_vma:
77481+
77482+#ifdef CONFIG_PAX_SEGMEXEC
77483+ if (new_m) {
77484+ unlink_anon_vmas(new_m);
77485+ kmem_cache_free(vm_area_cachep, new_m);
77486+ }
77487+#endif
77488+
77489+ unlink_anon_vmas(new);
77490 kmem_cache_free(vm_area_cachep, new);
77491 out_err:
77492 return err;
77493@@ -2379,6 +2804,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77494 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
77495 unsigned long addr, int new_below)
77496 {
77497+
77498+#ifdef CONFIG_PAX_SEGMEXEC
77499+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
77500+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
77501+ if (mm->map_count >= sysctl_max_map_count-1)
77502+ return -ENOMEM;
77503+ } else
77504+#endif
77505+
77506 if (mm->map_count >= sysctl_max_map_count)
77507 return -ENOMEM;
77508
77509@@ -2390,11 +2824,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
77510 * work. This now handles partial unmappings.
77511 * Jeremy Fitzhardinge <jeremy@goop.org>
77512 */
77513+#ifdef CONFIG_PAX_SEGMEXEC
77514 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77515 {
77516+ int ret = __do_munmap(mm, start, len);
77517+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
77518+ return ret;
77519+
77520+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
77521+}
77522+
77523+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77524+#else
77525+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77526+#endif
77527+{
77528 unsigned long end;
77529 struct vm_area_struct *vma, *prev, *last;
77530
77531+ /*
77532+ * mm->mmap_sem is required to protect against another thread
77533+ * changing the mappings in case we sleep.
77534+ */
77535+ verify_mm_writelocked(mm);
77536+
77537 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
77538 return -EINVAL;
77539
77540@@ -2469,6 +2922,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77541 /* Fix up all other VM information */
77542 remove_vma_list(mm, vma);
77543
77544+ track_exec_limit(mm, start, end, 0UL);
77545+
77546 return 0;
77547 }
77548
77549@@ -2477,6 +2932,13 @@ int vm_munmap(unsigned long start, size_t len)
77550 int ret;
77551 struct mm_struct *mm = current->mm;
77552
77553+
77554+#ifdef CONFIG_PAX_SEGMEXEC
77555+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
77556+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
77557+ return -EINVAL;
77558+#endif
77559+
77560 down_write(&mm->mmap_sem);
77561 ret = do_munmap(mm, start, len);
77562 up_write(&mm->mmap_sem);
77563@@ -2490,16 +2952,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
77564 return vm_munmap(addr, len);
77565 }
77566
77567-static inline void verify_mm_writelocked(struct mm_struct *mm)
77568-{
77569-#ifdef CONFIG_DEBUG_VM
77570- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
77571- WARN_ON(1);
77572- up_read(&mm->mmap_sem);
77573- }
77574-#endif
77575-}
77576-
77577 /*
77578 * this is really a simplified "do_mmap". it only handles
77579 * anonymous maps. eventually we may be able to do some
77580@@ -2513,6 +2965,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77581 struct rb_node ** rb_link, * rb_parent;
77582 pgoff_t pgoff = addr >> PAGE_SHIFT;
77583 int error;
77584+ unsigned long charged;
77585
77586 len = PAGE_ALIGN(len);
77587 if (!len)
77588@@ -2520,16 +2973,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77589
77590 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
77591
77592+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
77593+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
77594+ flags &= ~VM_EXEC;
77595+
77596+#ifdef CONFIG_PAX_MPROTECT
77597+ if (mm->pax_flags & MF_PAX_MPROTECT)
77598+ flags &= ~VM_MAYEXEC;
77599+#endif
77600+
77601+ }
77602+#endif
77603+
77604 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
77605 if (error & ~PAGE_MASK)
77606 return error;
77607
77608+ charged = len >> PAGE_SHIFT;
77609+
77610 /*
77611 * mlock MCL_FUTURE?
77612 */
77613 if (mm->def_flags & VM_LOCKED) {
77614 unsigned long locked, lock_limit;
77615- locked = len >> PAGE_SHIFT;
77616+ locked = charged;
77617 locked += mm->locked_vm;
77618 lock_limit = rlimit(RLIMIT_MEMLOCK);
77619 lock_limit >>= PAGE_SHIFT;
77620@@ -2546,21 +3013,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77621 /*
77622 * Clear old maps. this also does some error checking for us
77623 */
77624- munmap_back:
77625 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
77626 if (do_munmap(mm, addr, len))
77627 return -ENOMEM;
77628- goto munmap_back;
77629+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
77630 }
77631
77632 /* Check against address space limits *after* clearing old maps... */
77633- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
77634+ if (!may_expand_vm(mm, charged))
77635 return -ENOMEM;
77636
77637 if (mm->map_count > sysctl_max_map_count)
77638 return -ENOMEM;
77639
77640- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
77641+ if (security_vm_enough_memory_mm(mm, charged))
77642 return -ENOMEM;
77643
77644 /* Can we just expand an old private anonymous mapping? */
77645@@ -2574,7 +3040,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77646 */
77647 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77648 if (!vma) {
77649- vm_unacct_memory(len >> PAGE_SHIFT);
77650+ vm_unacct_memory(charged);
77651 return -ENOMEM;
77652 }
77653
77654@@ -2588,11 +3054,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77655 vma_link(mm, vma, prev, rb_link, rb_parent);
77656 out:
77657 perf_event_mmap(vma);
77658- mm->total_vm += len >> PAGE_SHIFT;
77659+ mm->total_vm += charged;
77660 if (flags & VM_LOCKED) {
77661 if (!mlock_vma_pages_range(vma, addr, addr + len))
77662- mm->locked_vm += (len >> PAGE_SHIFT);
77663+ mm->locked_vm += charged;
77664 }
77665+ track_exec_limit(mm, addr, addr + len, flags);
77666 return addr;
77667 }
77668
77669@@ -2650,6 +3117,7 @@ void exit_mmap(struct mm_struct *mm)
77670 while (vma) {
77671 if (vma->vm_flags & VM_ACCOUNT)
77672 nr_accounted += vma_pages(vma);
77673+ vma->vm_mirror = NULL;
77674 vma = remove_vma(vma);
77675 }
77676 vm_unacct_memory(nr_accounted);
77677@@ -2666,6 +3134,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
77678 struct vm_area_struct *prev;
77679 struct rb_node **rb_link, *rb_parent;
77680
77681+#ifdef CONFIG_PAX_SEGMEXEC
77682+ struct vm_area_struct *vma_m = NULL;
77683+#endif
77684+
77685+ if (security_mmap_addr(vma->vm_start))
77686+ return -EPERM;
77687+
77688 /*
77689 * The vm_pgoff of a purely anonymous vma should be irrelevant
77690 * until its first write fault, when page's anon_vma and index
77691@@ -2689,7 +3164,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
77692 security_vm_enough_memory_mm(mm, vma_pages(vma)))
77693 return -ENOMEM;
77694
77695+#ifdef CONFIG_PAX_SEGMEXEC
77696+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
77697+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77698+ if (!vma_m)
77699+ return -ENOMEM;
77700+ }
77701+#endif
77702+
77703 vma_link(mm, vma, prev, rb_link, rb_parent);
77704+
77705+#ifdef CONFIG_PAX_SEGMEXEC
77706+ if (vma_m)
77707+ BUG_ON(pax_mirror_vma(vma_m, vma));
77708+#endif
77709+
77710 return 0;
77711 }
77712
77713@@ -2709,6 +3198,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
77714 struct mempolicy *pol;
77715 bool faulted_in_anon_vma = true;
77716
77717+ BUG_ON(vma->vm_mirror);
77718+
77719 /*
77720 * If anonymous vma has not yet been faulted, update new pgoff
77721 * to match new location, to increase its chance of merging.
77722@@ -2775,6 +3266,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
77723 return NULL;
77724 }
77725
77726+#ifdef CONFIG_PAX_SEGMEXEC
77727+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
77728+{
77729+ struct vm_area_struct *prev_m;
77730+ struct rb_node **rb_link_m, *rb_parent_m;
77731+ struct mempolicy *pol_m;
77732+
77733+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
77734+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
77735+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
77736+ *vma_m = *vma;
77737+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
77738+ if (anon_vma_clone(vma_m, vma))
77739+ return -ENOMEM;
77740+ pol_m = vma_policy(vma_m);
77741+ mpol_get(pol_m);
77742+ vma_set_policy(vma_m, pol_m);
77743+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
77744+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
77745+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
77746+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
77747+ if (vma_m->vm_file)
77748+ get_file(vma_m->vm_file);
77749+ if (vma_m->vm_ops && vma_m->vm_ops->open)
77750+ vma_m->vm_ops->open(vma_m);
77751+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
77752+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
77753+ vma_m->vm_mirror = vma;
77754+ vma->vm_mirror = vma_m;
77755+ return 0;
77756+}
77757+#endif
77758+
77759 /*
77760 * Return true if the calling process may expand its vm space by the passed
77761 * number of pages
77762@@ -2786,6 +3310,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
77763
77764 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
77765
77766+#ifdef CONFIG_PAX_RANDMMAP
77767+ if (mm->pax_flags & MF_PAX_RANDMMAP)
77768+ cur -= mm->brk_gap;
77769+#endif
77770+
77771+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
77772 if (cur + npages > lim)
77773 return 0;
77774 return 1;
77775@@ -2856,6 +3386,22 @@ int install_special_mapping(struct mm_struct *mm,
77776 vma->vm_start = addr;
77777 vma->vm_end = addr + len;
77778
77779+#ifdef CONFIG_PAX_MPROTECT
77780+ if (mm->pax_flags & MF_PAX_MPROTECT) {
77781+#ifndef CONFIG_PAX_MPROTECT_COMPAT
77782+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
77783+ return -EPERM;
77784+ if (!(vm_flags & VM_EXEC))
77785+ vm_flags &= ~VM_MAYEXEC;
77786+#else
77787+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
77788+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
77789+#endif
77790+ else
77791+ vm_flags &= ~VM_MAYWRITE;
77792+ }
77793+#endif
77794+
77795 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
77796 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
77797
77798diff --git a/mm/mprotect.c b/mm/mprotect.c
77799index 94722a4..9837984 100644
77800--- a/mm/mprotect.c
77801+++ b/mm/mprotect.c
77802@@ -23,10 +23,17 @@
77803 #include <linux/mmu_notifier.h>
77804 #include <linux/migrate.h>
77805 #include <linux/perf_event.h>
77806+
77807+#ifdef CONFIG_PAX_MPROTECT
77808+#include <linux/elf.h>
77809+#include <linux/binfmts.h>
77810+#endif
77811+
77812 #include <asm/uaccess.h>
77813 #include <asm/pgtable.h>
77814 #include <asm/cacheflush.h>
77815 #include <asm/tlbflush.h>
77816+#include <asm/mmu_context.h>
77817
77818 #ifndef pgprot_modify
77819 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
77820@@ -233,6 +240,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
77821 return pages;
77822 }
77823
77824+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
77825+/* called while holding the mmap semaphor for writing except stack expansion */
77826+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
77827+{
77828+ unsigned long oldlimit, newlimit = 0UL;
77829+
77830+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
77831+ return;
77832+
77833+ spin_lock(&mm->page_table_lock);
77834+ oldlimit = mm->context.user_cs_limit;
77835+ if ((prot & VM_EXEC) && oldlimit < end)
77836+ /* USER_CS limit moved up */
77837+ newlimit = end;
77838+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
77839+ /* USER_CS limit moved down */
77840+ newlimit = start;
77841+
77842+ if (newlimit) {
77843+ mm->context.user_cs_limit = newlimit;
77844+
77845+#ifdef CONFIG_SMP
77846+ wmb();
77847+ cpus_clear(mm->context.cpu_user_cs_mask);
77848+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
77849+#endif
77850+
77851+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
77852+ }
77853+ spin_unlock(&mm->page_table_lock);
77854+ if (newlimit == end) {
77855+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
77856+
77857+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
77858+ if (is_vm_hugetlb_page(vma))
77859+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
77860+ else
77861+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
77862+ }
77863+}
77864+#endif
77865+
77866 int
77867 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
77868 unsigned long start, unsigned long end, unsigned long newflags)
77869@@ -245,11 +294,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
77870 int error;
77871 int dirty_accountable = 0;
77872
77873+#ifdef CONFIG_PAX_SEGMEXEC
77874+ struct vm_area_struct *vma_m = NULL;
77875+ unsigned long start_m, end_m;
77876+
77877+ start_m = start + SEGMEXEC_TASK_SIZE;
77878+ end_m = end + SEGMEXEC_TASK_SIZE;
77879+#endif
77880+
77881 if (newflags == oldflags) {
77882 *pprev = vma;
77883 return 0;
77884 }
77885
77886+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
77887+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
77888+
77889+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
77890+ return -ENOMEM;
77891+
77892+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
77893+ return -ENOMEM;
77894+ }
77895+
77896 /*
77897 * If we make a private mapping writable we increase our commit;
77898 * but (without finer accounting) cannot reduce our commit if we
77899@@ -266,6 +333,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
77900 }
77901 }
77902
77903+#ifdef CONFIG_PAX_SEGMEXEC
77904+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
77905+ if (start != vma->vm_start) {
77906+ error = split_vma(mm, vma, start, 1);
77907+ if (error)
77908+ goto fail;
77909+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
77910+ *pprev = (*pprev)->vm_next;
77911+ }
77912+
77913+ if (end != vma->vm_end) {
77914+ error = split_vma(mm, vma, end, 0);
77915+ if (error)
77916+ goto fail;
77917+ }
77918+
77919+ if (pax_find_mirror_vma(vma)) {
77920+ error = __do_munmap(mm, start_m, end_m - start_m);
77921+ if (error)
77922+ goto fail;
77923+ } else {
77924+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77925+ if (!vma_m) {
77926+ error = -ENOMEM;
77927+ goto fail;
77928+ }
77929+ vma->vm_flags = newflags;
77930+ error = pax_mirror_vma(vma_m, vma);
77931+ if (error) {
77932+ vma->vm_flags = oldflags;
77933+ goto fail;
77934+ }
77935+ }
77936+ }
77937+#endif
77938+
77939 /*
77940 * First try to merge with previous and/or next vma.
77941 */
77942@@ -296,9 +399,21 @@ success:
77943 * vm_flags and vm_page_prot are protected by the mmap_sem
77944 * held in write mode.
77945 */
77946+
77947+#ifdef CONFIG_PAX_SEGMEXEC
77948+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
77949+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
77950+#endif
77951+
77952 vma->vm_flags = newflags;
77953+
77954+#ifdef CONFIG_PAX_MPROTECT
77955+ if (mm->binfmt && mm->binfmt->handle_mprotect)
77956+ mm->binfmt->handle_mprotect(vma, newflags);
77957+#endif
77958+
77959 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
77960- vm_get_page_prot(newflags));
77961+ vm_get_page_prot(vma->vm_flags));
77962
77963 if (vma_wants_writenotify(vma)) {
77964 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
77965@@ -337,6 +452,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77966 end = start + len;
77967 if (end <= start)
77968 return -ENOMEM;
77969+
77970+#ifdef CONFIG_PAX_SEGMEXEC
77971+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
77972+ if (end > SEGMEXEC_TASK_SIZE)
77973+ return -EINVAL;
77974+ } else
77975+#endif
77976+
77977+ if (end > TASK_SIZE)
77978+ return -EINVAL;
77979+
77980 if (!arch_validate_prot(prot))
77981 return -EINVAL;
77982
77983@@ -344,7 +470,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77984 /*
77985 * Does the application expect PROT_READ to imply PROT_EXEC:
77986 */
77987- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
77988+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
77989 prot |= PROT_EXEC;
77990
77991 vm_flags = calc_vm_prot_bits(prot);
77992@@ -376,6 +502,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77993 if (start > vma->vm_start)
77994 prev = vma;
77995
77996+#ifdef CONFIG_PAX_MPROTECT
77997+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
77998+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
77999+#endif
78000+
78001 for (nstart = start ; ; ) {
78002 unsigned long newflags;
78003
78004@@ -386,6 +517,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
78005
78006 /* newflags >> 4 shift VM_MAY% in place of VM_% */
78007 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
78008+ if (prot & (PROT_WRITE | PROT_EXEC))
78009+ gr_log_rwxmprotect(vma->vm_file);
78010+
78011+ error = -EACCES;
78012+ goto out;
78013+ }
78014+
78015+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
78016 error = -EACCES;
78017 goto out;
78018 }
78019@@ -400,6 +539,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
78020 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
78021 if (error)
78022 goto out;
78023+
78024+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
78025+
78026 nstart = tmp;
78027
78028 if (nstart < prev->vm_end)
78029diff --git a/mm/mremap.c b/mm/mremap.c
78030index e1031e1..1f2a0a1 100644
78031--- a/mm/mremap.c
78032+++ b/mm/mremap.c
78033@@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
78034 continue;
78035 pte = ptep_get_and_clear(mm, old_addr, old_pte);
78036 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
78037+
78038+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
78039+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
78040+ pte = pte_exprotect(pte);
78041+#endif
78042+
78043 set_pte_at(mm, new_addr, new_pte, pte);
78044 }
78045
78046@@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
78047 if (is_vm_hugetlb_page(vma))
78048 goto Einval;
78049
78050+#ifdef CONFIG_PAX_SEGMEXEC
78051+ if (pax_find_mirror_vma(vma))
78052+ goto Einval;
78053+#endif
78054+
78055 /* We can't remap across vm area boundaries */
78056 if (old_len > vma->vm_end - addr)
78057 goto Efault;
78058@@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
78059 unsigned long ret = -EINVAL;
78060 unsigned long charged = 0;
78061 unsigned long map_flags;
78062+ unsigned long pax_task_size = TASK_SIZE;
78063
78064 if (new_addr & ~PAGE_MASK)
78065 goto out;
78066
78067- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
78068+#ifdef CONFIG_PAX_SEGMEXEC
78069+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
78070+ pax_task_size = SEGMEXEC_TASK_SIZE;
78071+#endif
78072+
78073+ pax_task_size -= PAGE_SIZE;
78074+
78075+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
78076 goto out;
78077
78078 /* Check if the location we're moving into overlaps the
78079 * old location at all, and fail if it does.
78080 */
78081- if ((new_addr <= addr) && (new_addr+new_len) > addr)
78082- goto out;
78083-
78084- if ((addr <= new_addr) && (addr+old_len) > new_addr)
78085+ if (addr + old_len > new_addr && new_addr + new_len > addr)
78086 goto out;
78087
78088 ret = do_munmap(mm, new_addr, new_len);
78089@@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
78090 struct vm_area_struct *vma;
78091 unsigned long ret = -EINVAL;
78092 unsigned long charged = 0;
78093+ unsigned long pax_task_size = TASK_SIZE;
78094
78095 down_write(&current->mm->mmap_sem);
78096
78097@@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
78098 if (!new_len)
78099 goto out;
78100
78101+#ifdef CONFIG_PAX_SEGMEXEC
78102+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
78103+ pax_task_size = SEGMEXEC_TASK_SIZE;
78104+#endif
78105+
78106+ pax_task_size -= PAGE_SIZE;
78107+
78108+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
78109+ old_len > pax_task_size || addr > pax_task_size-old_len)
78110+ goto out;
78111+
78112 if (flags & MREMAP_FIXED) {
78113 if (flags & MREMAP_MAYMOVE)
78114 ret = mremap_to(addr, old_len, new_addr, new_len);
78115@@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
78116 addr + new_len);
78117 }
78118 ret = addr;
78119+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
78120 goto out;
78121 }
78122 }
78123@@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
78124 goto out;
78125 }
78126
78127+ map_flags = vma->vm_flags;
78128 ret = move_vma(vma, addr, old_len, new_len, new_addr);
78129+ if (!(ret & ~PAGE_MASK)) {
78130+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
78131+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
78132+ }
78133 }
78134 out:
78135 if (ret & ~PAGE_MASK)
78136diff --git a/mm/nommu.c b/mm/nommu.c
78137index 79c3cac..4d357e0 100644
78138--- a/mm/nommu.c
78139+++ b/mm/nommu.c
78140@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
78141 int sysctl_overcommit_ratio = 50; /* default is 50% */
78142 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
78143 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
78144-int heap_stack_gap = 0;
78145
78146 atomic_long_t mmap_pages_allocated;
78147
78148@@ -839,15 +838,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
78149 EXPORT_SYMBOL(find_vma);
78150
78151 /*
78152- * find a VMA
78153- * - we don't extend stack VMAs under NOMMU conditions
78154- */
78155-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
78156-{
78157- return find_vma(mm, addr);
78158-}
78159-
78160-/*
78161 * expand a stack to a given address
78162 * - not supported under NOMMU conditions
78163 */
78164@@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
78165
78166 /* most fields are the same, copy all, and then fixup */
78167 *new = *vma;
78168+ INIT_LIST_HEAD(&new->anon_vma_chain);
78169 *region = *vma->vm_region;
78170 new->vm_region = region;
78171
78172diff --git a/mm/page-writeback.c b/mm/page-writeback.c
78173index 0713bfb..e3774e0 100644
78174--- a/mm/page-writeback.c
78175+++ b/mm/page-writeback.c
78176@@ -1630,7 +1630,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
78177 }
78178 }
78179
78180-static struct notifier_block __cpuinitdata ratelimit_nb = {
78181+static struct notifier_block ratelimit_nb = {
78182 .notifier_call = ratelimit_handler,
78183 .next = NULL,
78184 };
78185diff --git a/mm/page_alloc.c b/mm/page_alloc.c
78186index 6a83cd3..bc2dcb6 100644
78187--- a/mm/page_alloc.c
78188+++ b/mm/page_alloc.c
78189@@ -338,7 +338,7 @@ out:
78190 * This usage means that zero-order pages may not be compound.
78191 */
78192
78193-static void free_compound_page(struct page *page)
78194+void free_compound_page(struct page *page)
78195 {
78196 __free_pages_ok(page, compound_order(page));
78197 }
78198@@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
78199 int i;
78200 int bad = 0;
78201
78202+#ifdef CONFIG_PAX_MEMORY_SANITIZE
78203+ unsigned long index = 1UL << order;
78204+#endif
78205+
78206 trace_mm_page_free(page, order);
78207 kmemcheck_free_shadow(page, order);
78208
78209@@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
78210 debug_check_no_obj_freed(page_address(page),
78211 PAGE_SIZE << order);
78212 }
78213+
78214+#ifdef CONFIG_PAX_MEMORY_SANITIZE
78215+ for (; index; --index)
78216+ sanitize_highpage(page + index - 1);
78217+#endif
78218+
78219 arch_free_page(page, order);
78220 kernel_map_pages(page, 1 << order, 0);
78221
78222@@ -861,8 +871,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
78223 arch_alloc_page(page, order);
78224 kernel_map_pages(page, 1 << order, 1);
78225
78226+#ifndef CONFIG_PAX_MEMORY_SANITIZE
78227 if (gfp_flags & __GFP_ZERO)
78228 prep_zero_page(page, order, gfp_flags);
78229+#endif
78230
78231 if (order && (gfp_flags & __GFP_COMP))
78232 prep_compound_page(page, order);
78233@@ -3752,7 +3764,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
78234 unsigned long pfn;
78235
78236 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
78237+#ifdef CONFIG_X86_32
78238+ /* boot failures in VMware 8 on 32bit vanilla since
78239+ this change */
78240+ if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
78241+#else
78242 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
78243+#endif
78244 return 1;
78245 }
78246 return 0;
78247diff --git a/mm/percpu.c b/mm/percpu.c
78248index 8c8e08f..73a5cda 100644
78249--- a/mm/percpu.c
78250+++ b/mm/percpu.c
78251@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
78252 static unsigned int pcpu_high_unit_cpu __read_mostly;
78253
78254 /* the address of the first chunk which starts with the kernel static area */
78255-void *pcpu_base_addr __read_mostly;
78256+void *pcpu_base_addr __read_only;
78257 EXPORT_SYMBOL_GPL(pcpu_base_addr);
78258
78259 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
78260diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
78261index 926b466..b23df53 100644
78262--- a/mm/process_vm_access.c
78263+++ b/mm/process_vm_access.c
78264@@ -13,6 +13,7 @@
78265 #include <linux/uio.h>
78266 #include <linux/sched.h>
78267 #include <linux/highmem.h>
78268+#include <linux/security.h>
78269 #include <linux/ptrace.h>
78270 #include <linux/slab.h>
78271 #include <linux/syscalls.h>
78272@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
78273 size_t iov_l_curr_offset = 0;
78274 ssize_t iov_len;
78275
78276+ return -ENOSYS; // PaX: until properly audited
78277+
78278 /*
78279 * Work out how many pages of struct pages we're going to need
78280 * when eventually calling get_user_pages
78281 */
78282 for (i = 0; i < riovcnt; i++) {
78283 iov_len = rvec[i].iov_len;
78284- if (iov_len > 0) {
78285- nr_pages_iov = ((unsigned long)rvec[i].iov_base
78286- + iov_len)
78287- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
78288- / PAGE_SIZE + 1;
78289- nr_pages = max(nr_pages, nr_pages_iov);
78290- }
78291+ if (iov_len <= 0)
78292+ continue;
78293+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
78294+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
78295+ nr_pages = max(nr_pages, nr_pages_iov);
78296 }
78297
78298 if (nr_pages == 0)
78299@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
78300 goto free_proc_pages;
78301 }
78302
78303+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
78304+ rc = -EPERM;
78305+ goto put_task_struct;
78306+ }
78307+
78308 mm = mm_access(task, PTRACE_MODE_ATTACH);
78309 if (!mm || IS_ERR(mm)) {
78310 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
78311diff --git a/mm/rmap.c b/mm/rmap.c
78312index 2c78f8c..9e9c624 100644
78313--- a/mm/rmap.c
78314+++ b/mm/rmap.c
78315@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
78316 struct anon_vma *anon_vma = vma->anon_vma;
78317 struct anon_vma_chain *avc;
78318
78319+#ifdef CONFIG_PAX_SEGMEXEC
78320+ struct anon_vma_chain *avc_m = NULL;
78321+#endif
78322+
78323 might_sleep();
78324 if (unlikely(!anon_vma)) {
78325 struct mm_struct *mm = vma->vm_mm;
78326@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
78327 if (!avc)
78328 goto out_enomem;
78329
78330+#ifdef CONFIG_PAX_SEGMEXEC
78331+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
78332+ if (!avc_m)
78333+ goto out_enomem_free_avc;
78334+#endif
78335+
78336 anon_vma = find_mergeable_anon_vma(vma);
78337 allocated = NULL;
78338 if (!anon_vma) {
78339@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
78340 /* page_table_lock to protect against threads */
78341 spin_lock(&mm->page_table_lock);
78342 if (likely(!vma->anon_vma)) {
78343+
78344+#ifdef CONFIG_PAX_SEGMEXEC
78345+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
78346+
78347+ if (vma_m) {
78348+ BUG_ON(vma_m->anon_vma);
78349+ vma_m->anon_vma = anon_vma;
78350+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
78351+ avc_m = NULL;
78352+ }
78353+#endif
78354+
78355 vma->anon_vma = anon_vma;
78356 anon_vma_chain_link(vma, avc, anon_vma);
78357 allocated = NULL;
78358@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
78359
78360 if (unlikely(allocated))
78361 put_anon_vma(allocated);
78362+
78363+#ifdef CONFIG_PAX_SEGMEXEC
78364+ if (unlikely(avc_m))
78365+ anon_vma_chain_free(avc_m);
78366+#endif
78367+
78368 if (unlikely(avc))
78369 anon_vma_chain_free(avc);
78370 }
78371 return 0;
78372
78373 out_enomem_free_avc:
78374+
78375+#ifdef CONFIG_PAX_SEGMEXEC
78376+ if (avc_m)
78377+ anon_vma_chain_free(avc_m);
78378+#endif
78379+
78380 anon_vma_chain_free(avc);
78381 out_enomem:
78382 return -ENOMEM;
78383@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
78384 * Attach the anon_vmas from src to dst.
78385 * Returns 0 on success, -ENOMEM on failure.
78386 */
78387-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
78388+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
78389 {
78390 struct anon_vma_chain *avc, *pavc;
78391 struct anon_vma *root = NULL;
78392@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
78393 * the corresponding VMA in the parent process is attached to.
78394 * Returns 0 on success, non-zero on failure.
78395 */
78396-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
78397+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
78398 {
78399 struct anon_vma_chain *avc;
78400 struct anon_vma *anon_vma;
78401diff --git a/mm/shmem.c b/mm/shmem.c
78402index efd0b3a..994b702 100644
78403--- a/mm/shmem.c
78404+++ b/mm/shmem.c
78405@@ -31,7 +31,7 @@
78406 #include <linux/export.h>
78407 #include <linux/swap.h>
78408
78409-static struct vfsmount *shm_mnt;
78410+struct vfsmount *shm_mnt;
78411
78412 #ifdef CONFIG_SHMEM
78413 /*
78414@@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
78415 #define BOGO_DIRENT_SIZE 20
78416
78417 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
78418-#define SHORT_SYMLINK_LEN 128
78419+#define SHORT_SYMLINK_LEN 64
78420
78421 /*
78422 * shmem_fallocate and shmem_writepage communicate via inode->i_private
78423@@ -2202,6 +2202,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
78424 static int shmem_xattr_validate(const char *name)
78425 {
78426 struct { const char *prefix; size_t len; } arr[] = {
78427+
78428+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
78429+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
78430+#endif
78431+
78432 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
78433 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
78434 };
78435@@ -2257,6 +2262,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
78436 if (err)
78437 return err;
78438
78439+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
78440+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
78441+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
78442+ return -EOPNOTSUPP;
78443+ if (size > 8)
78444+ return -EINVAL;
78445+ }
78446+#endif
78447+
78448 return simple_xattr_set(&info->xattrs, name, value, size, flags);
78449 }
78450
78451@@ -2562,8 +2576,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
78452 int err = -ENOMEM;
78453
78454 /* Round up to L1_CACHE_BYTES to resist false sharing */
78455- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
78456- L1_CACHE_BYTES), GFP_KERNEL);
78457+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
78458 if (!sbinfo)
78459 return -ENOMEM;
78460
78461diff --git a/mm/slab.c b/mm/slab.c
78462index e7667a3..b62c169 100644
78463--- a/mm/slab.c
78464+++ b/mm/slab.c
78465@@ -306,7 +306,7 @@ struct kmem_list3 {
78466 * Need this for bootstrapping a per node allocator.
78467 */
78468 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
78469-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
78470+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
78471 #define CACHE_CACHE 0
78472 #define SIZE_AC MAX_NUMNODES
78473 #define SIZE_L3 (2 * MAX_NUMNODES)
78474@@ -407,10 +407,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
78475 if ((x)->max_freeable < i) \
78476 (x)->max_freeable = i; \
78477 } while (0)
78478-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
78479-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
78480-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
78481-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
78482+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
78483+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
78484+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
78485+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
78486 #else
78487 #define STATS_INC_ACTIVE(x) do { } while (0)
78488 #define STATS_DEC_ACTIVE(x) do { } while (0)
78489@@ -518,7 +518,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
78490 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
78491 */
78492 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
78493- const struct slab *slab, void *obj)
78494+ const struct slab *slab, const void *obj)
78495 {
78496 u32 offset = (obj - slab->s_mem);
78497 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
78498@@ -539,12 +539,13 @@ EXPORT_SYMBOL(malloc_sizes);
78499 struct cache_names {
78500 char *name;
78501 char *name_dma;
78502+ char *name_usercopy;
78503 };
78504
78505 static struct cache_names __initdata cache_names[] = {
78506-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
78507+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
78508 #include <linux/kmalloc_sizes.h>
78509- {NULL,}
78510+ {NULL}
78511 #undef CACHE
78512 };
78513
78514@@ -729,6 +730,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
78515 if (unlikely(gfpflags & GFP_DMA))
78516 return csizep->cs_dmacachep;
78517 #endif
78518+
78519+#ifdef CONFIG_PAX_USERCOPY_SLABS
78520+ if (unlikely(gfpflags & GFP_USERCOPY))
78521+ return csizep->cs_usercopycachep;
78522+#endif
78523+
78524 return csizep->cs_cachep;
78525 }
78526
78527@@ -1482,7 +1489,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
78528 return notifier_from_errno(err);
78529 }
78530
78531-static struct notifier_block __cpuinitdata cpucache_notifier = {
78532+static struct notifier_block cpucache_notifier = {
78533 &cpuup_callback, NULL, 0
78534 };
78535
78536@@ -1667,12 +1674,12 @@ void __init kmem_cache_init(void)
78537 */
78538
78539 sizes[INDEX_AC].cs_cachep = create_kmalloc_cache(names[INDEX_AC].name,
78540- sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS);
78541+ sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
78542
78543 if (INDEX_AC != INDEX_L3)
78544 sizes[INDEX_L3].cs_cachep =
78545 create_kmalloc_cache(names[INDEX_L3].name,
78546- sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS);
78547+ sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
78548
78549 slab_early_init = 0;
78550
78551@@ -1686,13 +1693,20 @@ void __init kmem_cache_init(void)
78552 */
78553 if (!sizes->cs_cachep)
78554 sizes->cs_cachep = create_kmalloc_cache(names->name,
78555- sizes->cs_size, ARCH_KMALLOC_FLAGS);
78556+ sizes->cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
78557
78558 #ifdef CONFIG_ZONE_DMA
78559 sizes->cs_dmacachep = create_kmalloc_cache(
78560 names->name_dma, sizes->cs_size,
78561 SLAB_CACHE_DMA|ARCH_KMALLOC_FLAGS);
78562 #endif
78563+
78564+#ifdef CONFIG_PAX_USERCOPY_SLABS
78565+ sizes->cs_usercopycachep = create_kmalloc_cache(
78566+ names->name_usercopy, sizes->cs_size,
78567+ ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
78568+#endif
78569+
78570 sizes++;
78571 names++;
78572 }
78573@@ -4365,10 +4379,10 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
78574 }
78575 /* cpu stats */
78576 {
78577- unsigned long allochit = atomic_read(&cachep->allochit);
78578- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
78579- unsigned long freehit = atomic_read(&cachep->freehit);
78580- unsigned long freemiss = atomic_read(&cachep->freemiss);
78581+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
78582+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
78583+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
78584+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
78585
78586 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
78587 allochit, allocmiss, freehit, freemiss);
78588@@ -4600,13 +4614,71 @@ static const struct file_operations proc_slabstats_operations = {
78589 static int __init slab_proc_init(void)
78590 {
78591 #ifdef CONFIG_DEBUG_SLAB_LEAK
78592- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
78593+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
78594 #endif
78595 return 0;
78596 }
78597 module_init(slab_proc_init);
78598 #endif
78599
78600+bool is_usercopy_object(const void *ptr)
78601+{
78602+ struct page *page;
78603+ struct kmem_cache *cachep;
78604+
78605+ if (ZERO_OR_NULL_PTR(ptr))
78606+ return false;
78607+
78608+ if (!slab_is_available())
78609+ return false;
78610+
78611+ if (!virt_addr_valid(ptr))
78612+ return false;
78613+
78614+ page = virt_to_head_page(ptr);
78615+
78616+ if (!PageSlab(page))
78617+ return false;
78618+
78619+ cachep = page->slab_cache;
78620+ return cachep->flags & SLAB_USERCOPY;
78621+}
78622+
78623+#ifdef CONFIG_PAX_USERCOPY
78624+const char *check_heap_object(const void *ptr, unsigned long n)
78625+{
78626+ struct page *page;
78627+ struct kmem_cache *cachep;
78628+ struct slab *slabp;
78629+ unsigned int objnr;
78630+ unsigned long offset;
78631+
78632+ if (ZERO_OR_NULL_PTR(ptr))
78633+ return "<null>";
78634+
78635+ if (!virt_addr_valid(ptr))
78636+ return NULL;
78637+
78638+ page = virt_to_head_page(ptr);
78639+
78640+ if (!PageSlab(page))
78641+ return NULL;
78642+
78643+ cachep = page->slab_cache;
78644+ if (!(cachep->flags & SLAB_USERCOPY))
78645+ return cachep->name;
78646+
78647+ slabp = page->slab_page;
78648+ objnr = obj_to_index(cachep, slabp, ptr);
78649+ BUG_ON(objnr >= cachep->num);
78650+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
78651+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
78652+ return NULL;
78653+
78654+ return cachep->name;
78655+}
78656+#endif
78657+
78658 /**
78659 * ksize - get the actual amount of memory allocated for a given object
78660 * @objp: Pointer to the object
78661diff --git a/mm/slab.h b/mm/slab.h
78662index 34a98d6..73633d1 100644
78663--- a/mm/slab.h
78664+++ b/mm/slab.h
78665@@ -58,7 +58,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
78666
78667 /* Legal flag mask for kmem_cache_create(), for various configurations */
78668 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
78669- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
78670+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | SLAB_USERCOPY)
78671
78672 #if defined(CONFIG_DEBUG_SLAB)
78673 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
78674@@ -220,6 +220,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
78675 return s;
78676
78677 page = virt_to_head_page(x);
78678+
78679+ BUG_ON(!PageSlab(page));
78680+
78681 cachep = page->slab_cache;
78682 if (slab_equal_or_root(cachep, s))
78683 return cachep;
78684diff --git a/mm/slab_common.c b/mm/slab_common.c
78685index 3f3cd97..e050794 100644
78686--- a/mm/slab_common.c
78687+++ b/mm/slab_common.c
78688@@ -209,7 +209,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
78689
78690 err = __kmem_cache_create(s, flags);
78691 if (!err) {
78692- s->refcount = 1;
78693+ atomic_set(&s->refcount, 1);
78694 list_add(&s->list, &slab_caches);
78695 memcg_cache_list_add(memcg, s);
78696 } else {
78697@@ -255,8 +255,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
78698
78699 get_online_cpus();
78700 mutex_lock(&slab_mutex);
78701- s->refcount--;
78702- if (!s->refcount) {
78703+ if (atomic_dec_and_test(&s->refcount)) {
78704 list_del(&s->list);
78705
78706 if (!__kmem_cache_shutdown(s)) {
78707@@ -302,7 +301,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
78708 panic("Creation of kmalloc slab %s size=%zd failed. Reason %d\n",
78709 name, size, err);
78710
78711- s->refcount = -1; /* Exempt from merging for now */
78712+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
78713 }
78714
78715 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
78716@@ -315,7 +314,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
78717
78718 create_boot_cache(s, name, size, flags);
78719 list_add(&s->list, &slab_caches);
78720- s->refcount = 1;
78721+ atomic_set(&s->refcount, 1);
78722 return s;
78723 }
78724
78725diff --git a/mm/slob.c b/mm/slob.c
78726index a99fdf7..f5b6577 100644
78727--- a/mm/slob.c
78728+++ b/mm/slob.c
78729@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
78730 /*
78731 * Return the size of a slob block.
78732 */
78733-static slobidx_t slob_units(slob_t *s)
78734+static slobidx_t slob_units(const slob_t *s)
78735 {
78736 if (s->units > 0)
78737 return s->units;
78738@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
78739 /*
78740 * Return the next free slob block pointer after this one.
78741 */
78742-static slob_t *slob_next(slob_t *s)
78743+static slob_t *slob_next(const slob_t *s)
78744 {
78745 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
78746 slobidx_t next;
78747@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
78748 /*
78749 * Returns true if s is the last free block in its page.
78750 */
78751-static int slob_last(slob_t *s)
78752+static int slob_last(const slob_t *s)
78753 {
78754 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
78755 }
78756
78757-static void *slob_new_pages(gfp_t gfp, int order, int node)
78758+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
78759 {
78760- void *page;
78761+ struct page *page;
78762
78763 #ifdef CONFIG_NUMA
78764 if (node != NUMA_NO_NODE)
78765@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
78766 if (!page)
78767 return NULL;
78768
78769- return page_address(page);
78770+ __SetPageSlab(page);
78771+ return page;
78772 }
78773
78774-static void slob_free_pages(void *b, int order)
78775+static void slob_free_pages(struct page *sp, int order)
78776 {
78777 if (current->reclaim_state)
78778 current->reclaim_state->reclaimed_slab += 1 << order;
78779- free_pages((unsigned long)b, order);
78780+ __ClearPageSlab(sp);
78781+ reset_page_mapcount(sp);
78782+ sp->private = 0;
78783+ __free_pages(sp, order);
78784 }
78785
78786 /*
78787@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
78788
78789 /* Not enough space: must allocate a new page */
78790 if (!b) {
78791- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
78792- if (!b)
78793+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
78794+ if (!sp)
78795 return NULL;
78796- sp = virt_to_page(b);
78797- __SetPageSlab(sp);
78798+ b = page_address(sp);
78799
78800 spin_lock_irqsave(&slob_lock, flags);
78801 sp->units = SLOB_UNITS(PAGE_SIZE);
78802 sp->freelist = b;
78803+ sp->private = 0;
78804 INIT_LIST_HEAD(&sp->list);
78805 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
78806 set_slob_page_free(sp, slob_list);
78807@@ -359,9 +363,7 @@ static void slob_free(void *block, int size)
78808 if (slob_page_free(sp))
78809 clear_slob_page_free(sp);
78810 spin_unlock_irqrestore(&slob_lock, flags);
78811- __ClearPageSlab(sp);
78812- reset_page_mapcount(sp);
78813- slob_free_pages(b, 0);
78814+ slob_free_pages(sp, 0);
78815 return;
78816 }
78817
78818@@ -424,11 +426,10 @@ out:
78819 */
78820
78821 static __always_inline void *
78822-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
78823+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
78824 {
78825- unsigned int *m;
78826- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78827- void *ret;
78828+ slob_t *m;
78829+ void *ret = NULL;
78830
78831 gfp &= gfp_allowed_mask;
78832
78833@@ -442,23 +443,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
78834
78835 if (!m)
78836 return NULL;
78837- *m = size;
78838+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
78839+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
78840+ m[0].units = size;
78841+ m[1].units = align;
78842 ret = (void *)m + align;
78843
78844 trace_kmalloc_node(caller, ret,
78845 size, size + align, gfp, node);
78846 } else {
78847 unsigned int order = get_order(size);
78848+ struct page *page;
78849
78850 if (likely(order))
78851 gfp |= __GFP_COMP;
78852- ret = slob_new_pages(gfp, order, node);
78853+ page = slob_new_pages(gfp, order, node);
78854+ if (page) {
78855+ ret = page_address(page);
78856+ page->private = size;
78857+ }
78858
78859 trace_kmalloc_node(caller, ret,
78860 size, PAGE_SIZE << order, gfp, node);
78861 }
78862
78863- kmemleak_alloc(ret, size, 1, gfp);
78864+ return ret;
78865+}
78866+
78867+static __always_inline void *
78868+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
78869+{
78870+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78871+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
78872+
78873+ if (!ZERO_OR_NULL_PTR(ret))
78874+ kmemleak_alloc(ret, size, 1, gfp);
78875 return ret;
78876 }
78877
78878@@ -494,33 +513,110 @@ void kfree(const void *block)
78879 kmemleak_free(block);
78880
78881 sp = virt_to_page(block);
78882- if (PageSlab(sp)) {
78883+ VM_BUG_ON(!PageSlab(sp));
78884+ if (!sp->private) {
78885 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78886- unsigned int *m = (unsigned int *)(block - align);
78887- slob_free(m, *m + align);
78888- } else
78889+ slob_t *m = (slob_t *)(block - align);
78890+ slob_free(m, m[0].units + align);
78891+ } else {
78892+ __ClearPageSlab(sp);
78893+ reset_page_mapcount(sp);
78894+ sp->private = 0;
78895 __free_pages(sp, compound_order(sp));
78896+ }
78897 }
78898 EXPORT_SYMBOL(kfree);
78899
78900+bool is_usercopy_object(const void *ptr)
78901+{
78902+ if (!slab_is_available())
78903+ return false;
78904+
78905+ // PAX: TODO
78906+
78907+ return false;
78908+}
78909+
78910+#ifdef CONFIG_PAX_USERCOPY
78911+const char *check_heap_object(const void *ptr, unsigned long n)
78912+{
78913+ struct page *page;
78914+ const slob_t *free;
78915+ const void *base;
78916+ unsigned long flags;
78917+
78918+ if (ZERO_OR_NULL_PTR(ptr))
78919+ return "<null>";
78920+
78921+ if (!virt_addr_valid(ptr))
78922+ return NULL;
78923+
78924+ page = virt_to_head_page(ptr);
78925+ if (!PageSlab(page))
78926+ return NULL;
78927+
78928+ if (page->private) {
78929+ base = page;
78930+ if (base <= ptr && n <= page->private - (ptr - base))
78931+ return NULL;
78932+ return "<slob>";
78933+ }
78934+
78935+ /* some tricky double walking to find the chunk */
78936+ spin_lock_irqsave(&slob_lock, flags);
78937+ base = (void *)((unsigned long)ptr & PAGE_MASK);
78938+ free = page->freelist;
78939+
78940+ while (!slob_last(free) && (void *)free <= ptr) {
78941+ base = free + slob_units(free);
78942+ free = slob_next(free);
78943+ }
78944+
78945+ while (base < (void *)free) {
78946+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
78947+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
78948+ int offset;
78949+
78950+ if (ptr < base + align)
78951+ break;
78952+
78953+ offset = ptr - base - align;
78954+ if (offset >= m) {
78955+ base += size;
78956+ continue;
78957+ }
78958+
78959+ if (n > m - offset)
78960+ break;
78961+
78962+ spin_unlock_irqrestore(&slob_lock, flags);
78963+ return NULL;
78964+ }
78965+
78966+ spin_unlock_irqrestore(&slob_lock, flags);
78967+ return "<slob>";
78968+}
78969+#endif
78970+
78971 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
78972 size_t ksize(const void *block)
78973 {
78974 struct page *sp;
78975 int align;
78976- unsigned int *m;
78977+ slob_t *m;
78978
78979 BUG_ON(!block);
78980 if (unlikely(block == ZERO_SIZE_PTR))
78981 return 0;
78982
78983 sp = virt_to_page(block);
78984- if (unlikely(!PageSlab(sp)))
78985- return PAGE_SIZE << compound_order(sp);
78986+ VM_BUG_ON(!PageSlab(sp));
78987+ if (sp->private)
78988+ return sp->private;
78989
78990 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78991- m = (unsigned int *)(block - align);
78992- return SLOB_UNITS(*m) * SLOB_UNIT;
78993+ m = (slob_t *)(block - align);
78994+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
78995 }
78996 EXPORT_SYMBOL(ksize);
78997
78998@@ -536,23 +632,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
78999
79000 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
79001 {
79002- void *b;
79003+ void *b = NULL;
79004
79005 flags &= gfp_allowed_mask;
79006
79007 lockdep_trace_alloc(flags);
79008
79009+#ifdef CONFIG_PAX_USERCOPY_SLABS
79010+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
79011+#else
79012 if (c->size < PAGE_SIZE) {
79013 b = slob_alloc(c->size, flags, c->align, node);
79014 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
79015 SLOB_UNITS(c->size) * SLOB_UNIT,
79016 flags, node);
79017 } else {
79018- b = slob_new_pages(flags, get_order(c->size), node);
79019+ struct page *sp;
79020+
79021+ sp = slob_new_pages(flags, get_order(c->size), node);
79022+ if (sp) {
79023+ b = page_address(sp);
79024+ sp->private = c->size;
79025+ }
79026 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
79027 PAGE_SIZE << get_order(c->size),
79028 flags, node);
79029 }
79030+#endif
79031
79032 if (c->ctor)
79033 c->ctor(b);
79034@@ -564,10 +670,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
79035
79036 static void __kmem_cache_free(void *b, int size)
79037 {
79038- if (size < PAGE_SIZE)
79039+ struct page *sp;
79040+
79041+ sp = virt_to_page(b);
79042+ BUG_ON(!PageSlab(sp));
79043+ if (!sp->private)
79044 slob_free(b, size);
79045 else
79046- slob_free_pages(b, get_order(size));
79047+ slob_free_pages(sp, get_order(size));
79048 }
79049
79050 static void kmem_rcu_free(struct rcu_head *head)
79051@@ -580,17 +690,31 @@ static void kmem_rcu_free(struct rcu_head *head)
79052
79053 void kmem_cache_free(struct kmem_cache *c, void *b)
79054 {
79055+ int size = c->size;
79056+
79057+#ifdef CONFIG_PAX_USERCOPY_SLABS
79058+ if (size + c->align < PAGE_SIZE) {
79059+ size += c->align;
79060+ b -= c->align;
79061+ }
79062+#endif
79063+
79064 kmemleak_free_recursive(b, c->flags);
79065 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
79066 struct slob_rcu *slob_rcu;
79067- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
79068- slob_rcu->size = c->size;
79069+ slob_rcu = b + (size - sizeof(struct slob_rcu));
79070+ slob_rcu->size = size;
79071 call_rcu(&slob_rcu->head, kmem_rcu_free);
79072 } else {
79073- __kmem_cache_free(b, c->size);
79074+ __kmem_cache_free(b, size);
79075 }
79076
79077+#ifdef CONFIG_PAX_USERCOPY_SLABS
79078+ trace_kfree(_RET_IP_, b);
79079+#else
79080 trace_kmem_cache_free(_RET_IP_, b);
79081+#endif
79082+
79083 }
79084 EXPORT_SYMBOL(kmem_cache_free);
79085
79086diff --git a/mm/slub.c b/mm/slub.c
79087index ba2ca53..00b1f4e 100644
79088--- a/mm/slub.c
79089+++ b/mm/slub.c
79090@@ -197,7 +197,7 @@ struct track {
79091
79092 enum track_item { TRACK_ALLOC, TRACK_FREE };
79093
79094-#ifdef CONFIG_SYSFS
79095+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79096 static int sysfs_slab_add(struct kmem_cache *);
79097 static int sysfs_slab_alias(struct kmem_cache *, const char *);
79098 static void sysfs_slab_remove(struct kmem_cache *);
79099@@ -518,7 +518,7 @@ static void print_track(const char *s, struct track *t)
79100 if (!t->addr)
79101 return;
79102
79103- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
79104+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
79105 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
79106 #ifdef CONFIG_STACKTRACE
79107 {
79108@@ -2653,7 +2653,7 @@ static int slub_min_objects;
79109 * Merge control. If this is set then no merging of slab caches will occur.
79110 * (Could be removed. This was introduced to pacify the merge skeptics.)
79111 */
79112-static int slub_nomerge;
79113+static int slub_nomerge = 1;
79114
79115 /*
79116 * Calculate the order of allocation given an slab object size.
79117@@ -3181,6 +3181,10 @@ EXPORT_SYMBOL(kmalloc_caches);
79118 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
79119 #endif
79120
79121+#ifdef CONFIG_PAX_USERCOPY_SLABS
79122+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
79123+#endif
79124+
79125 static int __init setup_slub_min_order(char *str)
79126 {
79127 get_option(&str, &slub_min_order);
79128@@ -3272,6 +3276,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
79129 return kmalloc_dma_caches[index];
79130
79131 #endif
79132+
79133+#ifdef CONFIG_PAX_USERCOPY_SLABS
79134+ if (flags & SLAB_USERCOPY)
79135+ return kmalloc_usercopy_caches[index];
79136+
79137+#endif
79138+
79139 return kmalloc_caches[index];
79140 }
79141
79142@@ -3340,6 +3351,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
79143 EXPORT_SYMBOL(__kmalloc_node);
79144 #endif
79145
79146+bool is_usercopy_object(const void *ptr)
79147+{
79148+ struct page *page;
79149+ struct kmem_cache *s;
79150+
79151+ if (ZERO_OR_NULL_PTR(ptr))
79152+ return false;
79153+
79154+ if (!slab_is_available())
79155+ return false;
79156+
79157+ if (!virt_addr_valid(ptr))
79158+ return false;
79159+
79160+ page = virt_to_head_page(ptr);
79161+
79162+ if (!PageSlab(page))
79163+ return false;
79164+
79165+ s = page->slab_cache;
79166+ return s->flags & SLAB_USERCOPY;
79167+}
79168+
79169+#ifdef CONFIG_PAX_USERCOPY
79170+const char *check_heap_object(const void *ptr, unsigned long n)
79171+{
79172+ struct page *page;
79173+ struct kmem_cache *s;
79174+ unsigned long offset;
79175+
79176+ if (ZERO_OR_NULL_PTR(ptr))
79177+ return "<null>";
79178+
79179+ if (!virt_addr_valid(ptr))
79180+ return NULL;
79181+
79182+ page = virt_to_head_page(ptr);
79183+
79184+ if (!PageSlab(page))
79185+ return NULL;
79186+
79187+ s = page->slab_cache;
79188+ if (!(s->flags & SLAB_USERCOPY))
79189+ return s->name;
79190+
79191+ offset = (ptr - page_address(page)) % s->size;
79192+ if (offset <= s->object_size && n <= s->object_size - offset)
79193+ return NULL;
79194+
79195+ return s->name;
79196+}
79197+#endif
79198+
79199 size_t ksize(const void *object)
79200 {
79201 struct page *page;
79202@@ -3712,17 +3776,17 @@ void __init kmem_cache_init(void)
79203
79204 /* Caches that are not of the two-to-the-power-of size */
79205 if (KMALLOC_MIN_SIZE <= 32) {
79206- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
79207+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
79208 caches++;
79209 }
79210
79211 if (KMALLOC_MIN_SIZE <= 64) {
79212- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
79213+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
79214 caches++;
79215 }
79216
79217 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
79218- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
79219+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
79220 caches++;
79221 }
79222
79223@@ -3764,6 +3828,22 @@ void __init kmem_cache_init(void)
79224 }
79225 }
79226 #endif
79227+
79228+#ifdef CONFIG_PAX_USERCOPY_SLABS
79229+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
79230+ struct kmem_cache *s = kmalloc_caches[i];
79231+
79232+ if (s && s->size) {
79233+ char *name = kasprintf(GFP_NOWAIT,
79234+ "usercopy-kmalloc-%d", s->object_size);
79235+
79236+ BUG_ON(!name);
79237+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
79238+ s->object_size, SLAB_USERCOPY);
79239+ }
79240+ }
79241+#endif
79242+
79243 printk(KERN_INFO
79244 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
79245 " CPUs=%d, Nodes=%d\n",
79246@@ -3790,7 +3870,7 @@ static int slab_unmergeable(struct kmem_cache *s)
79247 /*
79248 * We may have set a slab to be unmergeable during bootstrap.
79249 */
79250- if (s->refcount < 0)
79251+ if (atomic_read(&s->refcount) < 0)
79252 return 1;
79253
79254 return 0;
79255@@ -3848,7 +3928,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
79256
79257 s = find_mergeable(memcg, size, align, flags, name, ctor);
79258 if (s) {
79259- s->refcount++;
79260+ atomic_inc(&s->refcount);
79261 /*
79262 * Adjust the object sizes so that we clear
79263 * the complete object on kzalloc.
79264@@ -3857,7 +3937,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
79265 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
79266
79267 if (sysfs_slab_alias(s, name)) {
79268- s->refcount--;
79269+ atomic_dec(&s->refcount);
79270 s = NULL;
79271 }
79272 }
79273@@ -3919,7 +3999,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
79274 return NOTIFY_OK;
79275 }
79276
79277-static struct notifier_block __cpuinitdata slab_notifier = {
79278+static struct notifier_block slab_notifier = {
79279 .notifier_call = slab_cpuup_callback
79280 };
79281
79282@@ -3977,7 +4057,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
79283 }
79284 #endif
79285
79286-#ifdef CONFIG_SYSFS
79287+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79288 static int count_inuse(struct page *page)
79289 {
79290 return page->inuse;
79291@@ -4364,12 +4444,12 @@ static void resiliency_test(void)
79292 validate_slab_cache(kmalloc_caches[9]);
79293 }
79294 #else
79295-#ifdef CONFIG_SYSFS
79296+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79297 static void resiliency_test(void) {};
79298 #endif
79299 #endif
79300
79301-#ifdef CONFIG_SYSFS
79302+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79303 enum slab_stat_type {
79304 SL_ALL, /* All slabs */
79305 SL_PARTIAL, /* Only partially allocated slabs */
79306@@ -4613,7 +4693,7 @@ SLAB_ATTR_RO(ctor);
79307
79308 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
79309 {
79310- return sprintf(buf, "%d\n", s->refcount - 1);
79311+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
79312 }
79313 SLAB_ATTR_RO(aliases);
79314
79315@@ -5266,6 +5346,7 @@ static char *create_unique_id(struct kmem_cache *s)
79316 return name;
79317 }
79318
79319+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79320 static int sysfs_slab_add(struct kmem_cache *s)
79321 {
79322 int err;
79323@@ -5323,6 +5404,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
79324 kobject_del(&s->kobj);
79325 kobject_put(&s->kobj);
79326 }
79327+#endif
79328
79329 /*
79330 * Need to buffer aliases during bootup until sysfs becomes
79331@@ -5336,6 +5418,7 @@ struct saved_alias {
79332
79333 static struct saved_alias *alias_list;
79334
79335+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79336 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
79337 {
79338 struct saved_alias *al;
79339@@ -5358,6 +5441,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
79340 alias_list = al;
79341 return 0;
79342 }
79343+#endif
79344
79345 static int __init slab_sysfs_init(void)
79346 {
79347diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
79348index 1b7e22a..3fcd4f3 100644
79349--- a/mm/sparse-vmemmap.c
79350+++ b/mm/sparse-vmemmap.c
79351@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
79352 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
79353 if (!p)
79354 return NULL;
79355- pud_populate(&init_mm, pud, p);
79356+ pud_populate_kernel(&init_mm, pud, p);
79357 }
79358 return pud;
79359 }
79360@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
79361 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
79362 if (!p)
79363 return NULL;
79364- pgd_populate(&init_mm, pgd, p);
79365+ pgd_populate_kernel(&init_mm, pgd, p);
79366 }
79367 return pgd;
79368 }
79369diff --git a/mm/sparse.c b/mm/sparse.c
79370index 6b5fb76..db0c190 100644
79371--- a/mm/sparse.c
79372+++ b/mm/sparse.c
79373@@ -782,7 +782,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
79374
79375 for (i = 0; i < PAGES_PER_SECTION; i++) {
79376 if (PageHWPoison(&memmap[i])) {
79377- atomic_long_sub(1, &mce_bad_pages);
79378+ atomic_long_sub_unchecked(1, &mce_bad_pages);
79379 ClearPageHWPoison(&memmap[i]);
79380 }
79381 }
79382diff --git a/mm/swap.c b/mm/swap.c
79383index 6310dc2..3662b3f 100644
79384--- a/mm/swap.c
79385+++ b/mm/swap.c
79386@@ -30,6 +30,7 @@
79387 #include <linux/backing-dev.h>
79388 #include <linux/memcontrol.h>
79389 #include <linux/gfp.h>
79390+#include <linux/hugetlb.h>
79391
79392 #include "internal.h"
79393
79394@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
79395
79396 __page_cache_release(page);
79397 dtor = get_compound_page_dtor(page);
79398+ if (!PageHuge(page))
79399+ BUG_ON(dtor != free_compound_page);
79400 (*dtor)(page);
79401 }
79402
79403diff --git a/mm/swapfile.c b/mm/swapfile.c
79404index e97a0e5..b50e796 100644
79405--- a/mm/swapfile.c
79406+++ b/mm/swapfile.c
79407@@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
79408
79409 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
79410 /* Activity counter to indicate that a swapon or swapoff has occurred */
79411-static atomic_t proc_poll_event = ATOMIC_INIT(0);
79412+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
79413
79414 static inline unsigned char swap_count(unsigned char ent)
79415 {
79416@@ -1608,7 +1608,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
79417 }
79418 filp_close(swap_file, NULL);
79419 err = 0;
79420- atomic_inc(&proc_poll_event);
79421+ atomic_inc_unchecked(&proc_poll_event);
79422 wake_up_interruptible(&proc_poll_wait);
79423
79424 out_dput:
79425@@ -1625,8 +1625,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
79426
79427 poll_wait(file, &proc_poll_wait, wait);
79428
79429- if (seq->poll_event != atomic_read(&proc_poll_event)) {
79430- seq->poll_event = atomic_read(&proc_poll_event);
79431+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
79432+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
79433 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
79434 }
79435
79436@@ -1724,7 +1724,7 @@ static int swaps_open(struct inode *inode, struct file *file)
79437 return ret;
79438
79439 seq = file->private_data;
79440- seq->poll_event = atomic_read(&proc_poll_event);
79441+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
79442 return 0;
79443 }
79444
79445@@ -2066,7 +2066,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
79446 (frontswap_map) ? "FS" : "");
79447
79448 mutex_unlock(&swapon_mutex);
79449- atomic_inc(&proc_poll_event);
79450+ atomic_inc_unchecked(&proc_poll_event);
79451 wake_up_interruptible(&proc_poll_wait);
79452
79453 if (S_ISREG(inode->i_mode))
79454diff --git a/mm/util.c b/mm/util.c
79455index c55e26b..3f913a9 100644
79456--- a/mm/util.c
79457+++ b/mm/util.c
79458@@ -292,6 +292,12 @@ done:
79459 void arch_pick_mmap_layout(struct mm_struct *mm)
79460 {
79461 mm->mmap_base = TASK_UNMAPPED_BASE;
79462+
79463+#ifdef CONFIG_PAX_RANDMMAP
79464+ if (mm->pax_flags & MF_PAX_RANDMMAP)
79465+ mm->mmap_base += mm->delta_mmap;
79466+#endif
79467+
79468 mm->get_unmapped_area = arch_get_unmapped_area;
79469 mm->unmap_area = arch_unmap_area;
79470 }
79471diff --git a/mm/vmalloc.c b/mm/vmalloc.c
79472index 5123a16..f234a48 100644
79473--- a/mm/vmalloc.c
79474+++ b/mm/vmalloc.c
79475@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
79476
79477 pte = pte_offset_kernel(pmd, addr);
79478 do {
79479- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
79480- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
79481+
79482+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79483+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
79484+ BUG_ON(!pte_exec(*pte));
79485+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
79486+ continue;
79487+ }
79488+#endif
79489+
79490+ {
79491+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
79492+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
79493+ }
79494 } while (pte++, addr += PAGE_SIZE, addr != end);
79495 }
79496
79497@@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
79498 pte = pte_alloc_kernel(pmd, addr);
79499 if (!pte)
79500 return -ENOMEM;
79501+
79502+ pax_open_kernel();
79503 do {
79504 struct page *page = pages[*nr];
79505
79506- if (WARN_ON(!pte_none(*pte)))
79507+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79508+ if (pgprot_val(prot) & _PAGE_NX)
79509+#endif
79510+
79511+ if (!pte_none(*pte)) {
79512+ pax_close_kernel();
79513+ WARN_ON(1);
79514 return -EBUSY;
79515- if (WARN_ON(!page))
79516+ }
79517+ if (!page) {
79518+ pax_close_kernel();
79519+ WARN_ON(1);
79520 return -ENOMEM;
79521+ }
79522 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
79523 (*nr)++;
79524 } while (pte++, addr += PAGE_SIZE, addr != end);
79525+ pax_close_kernel();
79526 return 0;
79527 }
79528
79529@@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
79530 pmd_t *pmd;
79531 unsigned long next;
79532
79533- pmd = pmd_alloc(&init_mm, pud, addr);
79534+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
79535 if (!pmd)
79536 return -ENOMEM;
79537 do {
79538@@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
79539 pud_t *pud;
79540 unsigned long next;
79541
79542- pud = pud_alloc(&init_mm, pgd, addr);
79543+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
79544 if (!pud)
79545 return -ENOMEM;
79546 do {
79547@@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
79548 * and fall back on vmalloc() if that fails. Others
79549 * just put it in the vmalloc space.
79550 */
79551-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
79552+#ifdef CONFIG_MODULES
79553+#ifdef MODULES_VADDR
79554 unsigned long addr = (unsigned long)x;
79555 if (addr >= MODULES_VADDR && addr < MODULES_END)
79556 return 1;
79557 #endif
79558+
79559+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79560+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
79561+ return 1;
79562+#endif
79563+
79564+#endif
79565+
79566 return is_vmalloc_addr(x);
79567 }
79568
79569@@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
79570
79571 if (!pgd_none(*pgd)) {
79572 pud_t *pud = pud_offset(pgd, addr);
79573+#ifdef CONFIG_X86
79574+ if (!pud_large(*pud))
79575+#endif
79576 if (!pud_none(*pud)) {
79577 pmd_t *pmd = pmd_offset(pud, addr);
79578+#ifdef CONFIG_X86
79579+ if (!pmd_large(*pmd))
79580+#endif
79581 if (!pmd_none(*pmd)) {
79582 pte_t *ptep, pte;
79583
79584@@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
79585 * Allocate a region of KVA of the specified size and alignment, within the
79586 * vstart and vend.
79587 */
79588-static struct vmap_area *alloc_vmap_area(unsigned long size,
79589+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
79590 unsigned long align,
79591 unsigned long vstart, unsigned long vend,
79592 int node, gfp_t gfp_mask)
79593@@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
79594 struct vm_struct *area;
79595
79596 BUG_ON(in_interrupt());
79597+
79598+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79599+ if (flags & VM_KERNEXEC) {
79600+ if (start != VMALLOC_START || end != VMALLOC_END)
79601+ return NULL;
79602+ start = (unsigned long)MODULES_EXEC_VADDR;
79603+ end = (unsigned long)MODULES_EXEC_END;
79604+ }
79605+#endif
79606+
79607 if (flags & VM_IOREMAP) {
79608 int bit = fls(size);
79609
79610@@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
79611 if (count > totalram_pages)
79612 return NULL;
79613
79614+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79615+ if (!(pgprot_val(prot) & _PAGE_NX))
79616+ flags |= VM_KERNEXEC;
79617+#endif
79618+
79619 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
79620 __builtin_return_address(0));
79621 if (!area)
79622@@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
79623 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
79624 goto fail;
79625
79626+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79627+ if (!(pgprot_val(prot) & _PAGE_NX))
79628+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
79629+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
79630+ else
79631+#endif
79632+
79633 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
79634 start, end, node, gfp_mask, caller);
79635 if (!area)
79636@@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
79637 * For tight control over page level allocator and protection flags
79638 * use __vmalloc() instead.
79639 */
79640-
79641 void *vmalloc_exec(unsigned long size)
79642 {
79643- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
79644+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
79645 -1, __builtin_return_address(0));
79646 }
79647
79648@@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
79649 unsigned long uaddr = vma->vm_start;
79650 unsigned long usize = vma->vm_end - vma->vm_start;
79651
79652+ BUG_ON(vma->vm_mirror);
79653+
79654 if ((PAGE_SIZE-1) & (unsigned long)addr)
79655 return -EINVAL;
79656
79657@@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
79658 v->addr, v->addr + v->size, v->size);
79659
79660 if (v->caller)
79661+#ifdef CONFIG_GRKERNSEC_HIDESYM
79662+ seq_printf(m, " %pK", v->caller);
79663+#else
79664 seq_printf(m, " %pS", v->caller);
79665+#endif
79666
79667 if (v->nr_pages)
79668 seq_printf(m, " pages=%d", v->nr_pages);
79669diff --git a/mm/vmstat.c b/mm/vmstat.c
79670index 9800306..76b4b27 100644
79671--- a/mm/vmstat.c
79672+++ b/mm/vmstat.c
79673@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
79674 *
79675 * vm_stat contains the global counters
79676 */
79677-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
79678+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
79679 EXPORT_SYMBOL(vm_stat);
79680
79681 #ifdef CONFIG_SMP
79682@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
79683 v = p->vm_stat_diff[i];
79684 p->vm_stat_diff[i] = 0;
79685 local_irq_restore(flags);
79686- atomic_long_add(v, &zone->vm_stat[i]);
79687+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
79688 global_diff[i] += v;
79689 #ifdef CONFIG_NUMA
79690 /* 3 seconds idle till flush */
79691@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
79692
79693 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
79694 if (global_diff[i])
79695- atomic_long_add(global_diff[i], &vm_stat[i]);
79696+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
79697 }
79698
79699 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
79700@@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
79701 if (pset->vm_stat_diff[i]) {
79702 int v = pset->vm_stat_diff[i];
79703 pset->vm_stat_diff[i] = 0;
79704- atomic_long_add(v, &zone->vm_stat[i]);
79705- atomic_long_add(v, &vm_stat[i]);
79706+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
79707+ atomic_long_add_unchecked(v, &vm_stat[i]);
79708 }
79709 }
79710 #endif
79711@@ -1223,7 +1223,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
79712 return NOTIFY_OK;
79713 }
79714
79715-static struct notifier_block __cpuinitdata vmstat_notifier =
79716+static struct notifier_block vmstat_notifier =
79717 { &vmstat_cpuup_callback, NULL, 0 };
79718 #endif
79719
79720@@ -1238,10 +1238,20 @@ static int __init setup_vmstat(void)
79721 start_cpu_timer(cpu);
79722 #endif
79723 #ifdef CONFIG_PROC_FS
79724- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
79725- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
79726- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
79727- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
79728+ {
79729+ mode_t gr_mode = S_IRUGO;
79730+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79731+ gr_mode = S_IRUSR;
79732+#endif
79733+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
79734+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
79735+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79736+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
79737+#else
79738+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
79739+#endif
79740+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
79741+ }
79742 #endif
79743 return 0;
79744 }
79745diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
79746index a292e80..785ee68 100644
79747--- a/net/8021q/vlan.c
79748+++ b/net/8021q/vlan.c
79749@@ -485,7 +485,7 @@ out:
79750 return NOTIFY_DONE;
79751 }
79752
79753-static struct notifier_block vlan_notifier_block __read_mostly = {
79754+static struct notifier_block vlan_notifier_block = {
79755 .notifier_call = vlan_device_event,
79756 };
79757
79758@@ -560,8 +560,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
79759 err = -EPERM;
79760 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
79761 break;
79762- if ((args.u.name_type >= 0) &&
79763- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
79764+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
79765 struct vlan_net *vn;
79766
79767 vn = net_generic(net, vlan_net_id);
79768diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
79769index 02efb25..41541a9 100644
79770--- a/net/9p/trans_fd.c
79771+++ b/net/9p/trans_fd.c
79772@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
79773 oldfs = get_fs();
79774 set_fs(get_ds());
79775 /* The cast to a user pointer is valid due to the set_fs() */
79776- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
79777+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
79778 set_fs(oldfs);
79779
79780 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
79781diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
79782index 876fbe8..8bbea9f 100644
79783--- a/net/atm/atm_misc.c
79784+++ b/net/atm/atm_misc.c
79785@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
79786 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
79787 return 1;
79788 atm_return(vcc, truesize);
79789- atomic_inc(&vcc->stats->rx_drop);
79790+ atomic_inc_unchecked(&vcc->stats->rx_drop);
79791 return 0;
79792 }
79793 EXPORT_SYMBOL(atm_charge);
79794@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
79795 }
79796 }
79797 atm_return(vcc, guess);
79798- atomic_inc(&vcc->stats->rx_drop);
79799+ atomic_inc_unchecked(&vcc->stats->rx_drop);
79800 return NULL;
79801 }
79802 EXPORT_SYMBOL(atm_alloc_charge);
79803@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
79804
79805 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
79806 {
79807-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
79808+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
79809 __SONET_ITEMS
79810 #undef __HANDLE_ITEM
79811 }
79812@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
79813
79814 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
79815 {
79816-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
79817+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
79818 __SONET_ITEMS
79819 #undef __HANDLE_ITEM
79820 }
79821diff --git a/net/atm/lec.h b/net/atm/lec.h
79822index a86aff9..3a0d6f6 100644
79823--- a/net/atm/lec.h
79824+++ b/net/atm/lec.h
79825@@ -48,7 +48,7 @@ struct lane2_ops {
79826 const u8 *tlvs, u32 sizeoftlvs);
79827 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
79828 const u8 *tlvs, u32 sizeoftlvs);
79829-};
79830+} __no_const;
79831
79832 /*
79833 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
79834diff --git a/net/atm/proc.c b/net/atm/proc.c
79835index 0d020de..011c7bb 100644
79836--- a/net/atm/proc.c
79837+++ b/net/atm/proc.c
79838@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
79839 const struct k_atm_aal_stats *stats)
79840 {
79841 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
79842- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
79843- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
79844- atomic_read(&stats->rx_drop));
79845+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
79846+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
79847+ atomic_read_unchecked(&stats->rx_drop));
79848 }
79849
79850 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
79851diff --git a/net/atm/resources.c b/net/atm/resources.c
79852index 0447d5d..3cf4728 100644
79853--- a/net/atm/resources.c
79854+++ b/net/atm/resources.c
79855@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
79856 static void copy_aal_stats(struct k_atm_aal_stats *from,
79857 struct atm_aal_stats *to)
79858 {
79859-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
79860+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
79861 __AAL_STAT_ITEMS
79862 #undef __HANDLE_ITEM
79863 }
79864@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
79865 static void subtract_aal_stats(struct k_atm_aal_stats *from,
79866 struct atm_aal_stats *to)
79867 {
79868-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
79869+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
79870 __AAL_STAT_ITEMS
79871 #undef __HANDLE_ITEM
79872 }
79873diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
79874index 7d02ebd..4d4cc01 100644
79875--- a/net/batman-adv/bat_iv_ogm.c
79876+++ b/net/batman-adv/bat_iv_ogm.c
79877@@ -63,7 +63,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
79878
79879 /* randomize initial seqno to avoid collision */
79880 get_random_bytes(&random_seqno, sizeof(random_seqno));
79881- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
79882+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
79883
79884 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
79885 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
79886@@ -615,9 +615,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
79887 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
79888
79889 /* change sequence number to network order */
79890- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
79891+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
79892 batadv_ogm_packet->seqno = htonl(seqno);
79893- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
79894+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
79895
79896 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
79897 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
79898@@ -1022,7 +1022,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
79899 return;
79900
79901 /* could be changed by schedule_own_packet() */
79902- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
79903+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
79904
79905 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
79906 has_directlink_flag = 1;
79907diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
79908index f1d37cd..4190879 100644
79909--- a/net/batman-adv/hard-interface.c
79910+++ b/net/batman-adv/hard-interface.c
79911@@ -370,7 +370,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
79912 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
79913 dev_add_pack(&hard_iface->batman_adv_ptype);
79914
79915- atomic_set(&hard_iface->frag_seqno, 1);
79916+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
79917 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
79918 hard_iface->net_dev->name);
79919
79920@@ -493,7 +493,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
79921 /* This can't be called via a bat_priv callback because
79922 * we have no bat_priv yet.
79923 */
79924- atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
79925+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
79926 hard_iface->bat_iv.ogm_buff = NULL;
79927
79928 return hard_iface;
79929diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
79930index 6b548fd..fc32c8d 100644
79931--- a/net/batman-adv/soft-interface.c
79932+++ b/net/batman-adv/soft-interface.c
79933@@ -252,7 +252,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
79934 primary_if->net_dev->dev_addr, ETH_ALEN);
79935
79936 /* set broadcast sequence number */
79937- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
79938+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
79939 bcast_packet->seqno = htonl(seqno);
79940
79941 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
79942@@ -497,7 +497,7 @@ struct net_device *batadv_softif_create(const char *name)
79943 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
79944
79945 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
79946- atomic_set(&bat_priv->bcast_seqno, 1);
79947+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
79948 atomic_set(&bat_priv->tt.vn, 0);
79949 atomic_set(&bat_priv->tt.local_changes, 0);
79950 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
79951diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
79952index ae9ac9a..11e0fe7 100644
79953--- a/net/batman-adv/types.h
79954+++ b/net/batman-adv/types.h
79955@@ -48,7 +48,7 @@
79956 struct batadv_hard_iface_bat_iv {
79957 unsigned char *ogm_buff;
79958 int ogm_buff_len;
79959- atomic_t ogm_seqno;
79960+ atomic_unchecked_t ogm_seqno;
79961 };
79962
79963 struct batadv_hard_iface {
79964@@ -56,7 +56,7 @@ struct batadv_hard_iface {
79965 int16_t if_num;
79966 char if_status;
79967 struct net_device *net_dev;
79968- atomic_t frag_seqno;
79969+ atomic_unchecked_t frag_seqno;
79970 struct kobject *hardif_obj;
79971 atomic_t refcount;
79972 struct packet_type batman_adv_ptype;
79973@@ -284,7 +284,7 @@ struct batadv_priv {
79974 atomic_t orig_interval; /* uint */
79975 atomic_t hop_penalty; /* uint */
79976 atomic_t log_level; /* uint */
79977- atomic_t bcast_seqno;
79978+ atomic_unchecked_t bcast_seqno;
79979 atomic_t bcast_queue_left;
79980 atomic_t batman_queue_left;
79981 char num_ifaces;
79982diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
79983index 10aff49..ea8e021 100644
79984--- a/net/batman-adv/unicast.c
79985+++ b/net/batman-adv/unicast.c
79986@@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
79987 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
79988 frag2->flags = large_tail;
79989
79990- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
79991+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
79992 frag1->seqno = htons(seqno - 1);
79993 frag2->seqno = htons(seqno);
79994
79995diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
79996index 07f0739..3c42e34 100644
79997--- a/net/bluetooth/hci_sock.c
79998+++ b/net/bluetooth/hci_sock.c
79999@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
80000 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
80001 }
80002
80003- len = min_t(unsigned int, len, sizeof(uf));
80004+ len = min((size_t)len, sizeof(uf));
80005 if (copy_from_user(&uf, optval, len)) {
80006 err = -EFAULT;
80007 break;
80008diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
80009index 22e6583..426e2f3 100644
80010--- a/net/bluetooth/l2cap_core.c
80011+++ b/net/bluetooth/l2cap_core.c
80012@@ -3400,8 +3400,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
80013 break;
80014
80015 case L2CAP_CONF_RFC:
80016- if (olen == sizeof(rfc))
80017- memcpy(&rfc, (void *)val, olen);
80018+ if (olen != sizeof(rfc))
80019+ break;
80020+
80021+ memcpy(&rfc, (void *)val, olen);
80022
80023 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
80024 rfc.mode != chan->mode)
80025diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
80026index 1bcfb84..dad9f98 100644
80027--- a/net/bluetooth/l2cap_sock.c
80028+++ b/net/bluetooth/l2cap_sock.c
80029@@ -479,7 +479,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
80030 struct sock *sk = sock->sk;
80031 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
80032 struct l2cap_options opts;
80033- int len, err = 0;
80034+ int err = 0;
80035+ size_t len = optlen;
80036 u32 opt;
80037
80038 BT_DBG("sk %p", sk);
80039@@ -501,7 +502,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
80040 opts.max_tx = chan->max_tx;
80041 opts.txwin_size = chan->tx_win;
80042
80043- len = min_t(unsigned int, sizeof(opts), optlen);
80044+ len = min(sizeof(opts), len);
80045 if (copy_from_user((char *) &opts, optval, len)) {
80046 err = -EFAULT;
80047 break;
80048@@ -581,7 +582,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
80049 struct bt_security sec;
80050 struct bt_power pwr;
80051 struct l2cap_conn *conn;
80052- int len, err = 0;
80053+ int err = 0;
80054+ size_t len = optlen;
80055 u32 opt;
80056
80057 BT_DBG("sk %p", sk);
80058@@ -604,7 +606,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
80059
80060 sec.level = BT_SECURITY_LOW;
80061
80062- len = min_t(unsigned int, sizeof(sec), optlen);
80063+ len = min(sizeof(sec), len);
80064 if (copy_from_user((char *) &sec, optval, len)) {
80065 err = -EFAULT;
80066 break;
80067@@ -701,7 +703,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
80068
80069 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
80070
80071- len = min_t(unsigned int, sizeof(pwr), optlen);
80072+ len = min(sizeof(pwr), len);
80073 if (copy_from_user((char *) &pwr, optval, len)) {
80074 err = -EFAULT;
80075 break;
80076diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
80077index ce3f665..2c7d08f 100644
80078--- a/net/bluetooth/rfcomm/sock.c
80079+++ b/net/bluetooth/rfcomm/sock.c
80080@@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
80081 struct sock *sk = sock->sk;
80082 struct bt_security sec;
80083 int err = 0;
80084- size_t len;
80085+ size_t len = optlen;
80086 u32 opt;
80087
80088 BT_DBG("sk %p", sk);
80089@@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
80090
80091 sec.level = BT_SECURITY_LOW;
80092
80093- len = min_t(unsigned int, sizeof(sec), optlen);
80094+ len = min(sizeof(sec), len);
80095 if (copy_from_user((char *) &sec, optval, len)) {
80096 err = -EFAULT;
80097 break;
80098diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
80099index bd6fd0f..6492cba 100644
80100--- a/net/bluetooth/rfcomm/tty.c
80101+++ b/net/bluetooth/rfcomm/tty.c
80102@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
80103 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
80104
80105 spin_lock_irqsave(&dev->port.lock, flags);
80106- if (dev->port.count > 0) {
80107+ if (atomic_read(&dev->port.count) > 0) {
80108 spin_unlock_irqrestore(&dev->port.lock, flags);
80109 return;
80110 }
80111@@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
80112 return -ENODEV;
80113
80114 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
80115- dev->channel, dev->port.count);
80116+ dev->channel, atomic_read(&dev->port.count));
80117
80118 spin_lock_irqsave(&dev->port.lock, flags);
80119- if (++dev->port.count > 1) {
80120+ if (atomic_inc_return(&dev->port.count) > 1) {
80121 spin_unlock_irqrestore(&dev->port.lock, flags);
80122 return 0;
80123 }
80124@@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
80125 return;
80126
80127 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
80128- dev->port.count);
80129+ atomic_read(&dev->port.count));
80130
80131 spin_lock_irqsave(&dev->port.lock, flags);
80132- if (!--dev->port.count) {
80133+ if (!atomic_dec_return(&dev->port.count)) {
80134 spin_unlock_irqrestore(&dev->port.lock, flags);
80135 if (dev->tty_dev->parent)
80136 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
80137diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
80138index 5fe2ff3..121d696 100644
80139--- a/net/bridge/netfilter/ebtables.c
80140+++ b/net/bridge/netfilter/ebtables.c
80141@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
80142 tmp.valid_hooks = t->table->valid_hooks;
80143 }
80144 mutex_unlock(&ebt_mutex);
80145- if (copy_to_user(user, &tmp, *len) != 0){
80146+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
80147 BUGPRINT("c2u Didn't work\n");
80148 ret = -EFAULT;
80149 break;
80150@@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
80151 goto out;
80152 tmp.valid_hooks = t->valid_hooks;
80153
80154- if (copy_to_user(user, &tmp, *len) != 0) {
80155+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
80156 ret = -EFAULT;
80157 break;
80158 }
80159@@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
80160 tmp.entries_size = t->table->entries_size;
80161 tmp.valid_hooks = t->table->valid_hooks;
80162
80163- if (copy_to_user(user, &tmp, *len) != 0) {
80164+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
80165 ret = -EFAULT;
80166 break;
80167 }
80168diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
80169index a376ec1..1fbd6be 100644
80170--- a/net/caif/cfctrl.c
80171+++ b/net/caif/cfctrl.c
80172@@ -10,6 +10,7 @@
80173 #include <linux/spinlock.h>
80174 #include <linux/slab.h>
80175 #include <linux/pkt_sched.h>
80176+#include <linux/sched.h>
80177 #include <net/caif/caif_layer.h>
80178 #include <net/caif/cfpkt.h>
80179 #include <net/caif/cfctrl.h>
80180@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
80181 memset(&dev_info, 0, sizeof(dev_info));
80182 dev_info.id = 0xff;
80183 cfsrvl_init(&this->serv, 0, &dev_info, false);
80184- atomic_set(&this->req_seq_no, 1);
80185- atomic_set(&this->rsp_seq_no, 1);
80186+ atomic_set_unchecked(&this->req_seq_no, 1);
80187+ atomic_set_unchecked(&this->rsp_seq_no, 1);
80188 this->serv.layer.receive = cfctrl_recv;
80189 sprintf(this->serv.layer.name, "ctrl");
80190 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
80191@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
80192 struct cfctrl_request_info *req)
80193 {
80194 spin_lock_bh(&ctrl->info_list_lock);
80195- atomic_inc(&ctrl->req_seq_no);
80196- req->sequence_no = atomic_read(&ctrl->req_seq_no);
80197+ atomic_inc_unchecked(&ctrl->req_seq_no);
80198+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
80199 list_add_tail(&req->list, &ctrl->list);
80200 spin_unlock_bh(&ctrl->info_list_lock);
80201 }
80202@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
80203 if (p != first)
80204 pr_warn("Requests are not received in order\n");
80205
80206- atomic_set(&ctrl->rsp_seq_no,
80207+ atomic_set_unchecked(&ctrl->rsp_seq_no,
80208 p->sequence_no);
80209 list_del(&p->list);
80210 goto out;
80211diff --git a/net/can/af_can.c b/net/can/af_can.c
80212index ddac1ee..3ee0a78 100644
80213--- a/net/can/af_can.c
80214+++ b/net/can/af_can.c
80215@@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
80216 };
80217
80218 /* notifier block for netdevice event */
80219-static struct notifier_block can_netdev_notifier __read_mostly = {
80220+static struct notifier_block can_netdev_notifier = {
80221 .notifier_call = can_notifier,
80222 };
80223
80224diff --git a/net/can/gw.c b/net/can/gw.c
80225index 574dda78e..3d2b3da 100644
80226--- a/net/can/gw.c
80227+++ b/net/can/gw.c
80228@@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
80229 MODULE_ALIAS("can-gw");
80230
80231 static HLIST_HEAD(cgw_list);
80232-static struct notifier_block notifier;
80233
80234 static struct kmem_cache *cgw_cache __read_mostly;
80235
80236@@ -893,6 +892,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
80237 return err;
80238 }
80239
80240+static struct notifier_block notifier = {
80241+ .notifier_call = cgw_notifier
80242+};
80243+
80244 static __init int cgw_module_init(void)
80245 {
80246 printk(banner);
80247@@ -904,7 +907,6 @@ static __init int cgw_module_init(void)
80248 return -ENOMEM;
80249
80250 /* set notifier */
80251- notifier.notifier_call = cgw_notifier;
80252 register_netdevice_notifier(&notifier);
80253
80254 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
80255diff --git a/net/compat.c b/net/compat.c
80256index 79ae884..17c5c09 100644
80257--- a/net/compat.c
80258+++ b/net/compat.c
80259@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
80260 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
80261 __get_user(kmsg->msg_flags, &umsg->msg_flags))
80262 return -EFAULT;
80263- kmsg->msg_name = compat_ptr(tmp1);
80264- kmsg->msg_iov = compat_ptr(tmp2);
80265- kmsg->msg_control = compat_ptr(tmp3);
80266+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
80267+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
80268+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
80269 return 0;
80270 }
80271
80272@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
80273
80274 if (kern_msg->msg_namelen) {
80275 if (mode == VERIFY_READ) {
80276- int err = move_addr_to_kernel(kern_msg->msg_name,
80277+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
80278 kern_msg->msg_namelen,
80279 kern_address);
80280 if (err < 0)
80281@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
80282 kern_msg->msg_name = NULL;
80283
80284 tot_len = iov_from_user_compat_to_kern(kern_iov,
80285- (struct compat_iovec __user *)kern_msg->msg_iov,
80286+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
80287 kern_msg->msg_iovlen);
80288 if (tot_len >= 0)
80289 kern_msg->msg_iov = kern_iov;
80290@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
80291
80292 #define CMSG_COMPAT_FIRSTHDR(msg) \
80293 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
80294- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
80295+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
80296 (struct compat_cmsghdr __user *)NULL)
80297
80298 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
80299 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
80300 (ucmlen) <= (unsigned long) \
80301 ((mhdr)->msg_controllen - \
80302- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
80303+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
80304
80305 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
80306 struct compat_cmsghdr __user *cmsg, int cmsg_len)
80307 {
80308 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
80309- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
80310+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
80311 msg->msg_controllen)
80312 return NULL;
80313 return (struct compat_cmsghdr __user *)ptr;
80314@@ -219,7 +219,7 @@ Efault:
80315
80316 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
80317 {
80318- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
80319+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
80320 struct compat_cmsghdr cmhdr;
80321 struct compat_timeval ctv;
80322 struct compat_timespec cts[3];
80323@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
80324
80325 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
80326 {
80327- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
80328+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
80329 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
80330 int fdnum = scm->fp->count;
80331 struct file **fp = scm->fp->fp;
80332@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
80333 return -EFAULT;
80334 old_fs = get_fs();
80335 set_fs(KERNEL_DS);
80336- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
80337+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
80338 set_fs(old_fs);
80339
80340 return err;
80341@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
80342 len = sizeof(ktime);
80343 old_fs = get_fs();
80344 set_fs(KERNEL_DS);
80345- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
80346+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
80347 set_fs(old_fs);
80348
80349 if (!err) {
80350@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
80351 case MCAST_JOIN_GROUP:
80352 case MCAST_LEAVE_GROUP:
80353 {
80354- struct compat_group_req __user *gr32 = (void *)optval;
80355+ struct compat_group_req __user *gr32 = (void __user *)optval;
80356 struct group_req __user *kgr =
80357 compat_alloc_user_space(sizeof(struct group_req));
80358 u32 interface;
80359@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
80360 case MCAST_BLOCK_SOURCE:
80361 case MCAST_UNBLOCK_SOURCE:
80362 {
80363- struct compat_group_source_req __user *gsr32 = (void *)optval;
80364+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
80365 struct group_source_req __user *kgsr = compat_alloc_user_space(
80366 sizeof(struct group_source_req));
80367 u32 interface;
80368@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
80369 }
80370 case MCAST_MSFILTER:
80371 {
80372- struct compat_group_filter __user *gf32 = (void *)optval;
80373+ struct compat_group_filter __user *gf32 = (void __user *)optval;
80374 struct group_filter __user *kgf;
80375 u32 interface, fmode, numsrc;
80376
80377@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
80378 char __user *optval, int __user *optlen,
80379 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
80380 {
80381- struct compat_group_filter __user *gf32 = (void *)optval;
80382+ struct compat_group_filter __user *gf32 = (void __user *)optval;
80383 struct group_filter __user *kgf;
80384 int __user *koptlen;
80385 u32 interface, fmode, numsrc;
80386@@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
80387
80388 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
80389 return -EINVAL;
80390- if (copy_from_user(a, args, nas[call]))
80391+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
80392 return -EFAULT;
80393 a0 = a[0];
80394 a1 = a[1];
80395diff --git a/net/core/datagram.c b/net/core/datagram.c
80396index 368f9c3..f82d4a3 100644
80397--- a/net/core/datagram.c
80398+++ b/net/core/datagram.c
80399@@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
80400 }
80401
80402 kfree_skb(skb);
80403- atomic_inc(&sk->sk_drops);
80404+ atomic_inc_unchecked(&sk->sk_drops);
80405 sk_mem_reclaim_partial(sk);
80406
80407 return err;
80408diff --git a/net/core/dev.c b/net/core/dev.c
80409index f64e439..8f959e6 100644
80410--- a/net/core/dev.c
80411+++ b/net/core/dev.c
80412@@ -1250,9 +1250,13 @@ void dev_load(struct net *net, const char *name)
80413 if (no_module && capable(CAP_NET_ADMIN))
80414 no_module = request_module("netdev-%s", name);
80415 if (no_module && capable(CAP_SYS_MODULE)) {
80416+#ifdef CONFIG_GRKERNSEC_MODHARDEN
80417+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
80418+#else
80419 if (!request_module("%s", name))
80420 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
80421 name);
80422+#endif
80423 }
80424 }
80425 EXPORT_SYMBOL(dev_load);
80426@@ -1715,7 +1719,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
80427 {
80428 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
80429 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
80430- atomic_long_inc(&dev->rx_dropped);
80431+ atomic_long_inc_unchecked(&dev->rx_dropped);
80432 kfree_skb(skb);
80433 return NET_RX_DROP;
80434 }
80435@@ -1725,7 +1729,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
80436 nf_reset(skb);
80437
80438 if (unlikely(!is_skb_forwardable(dev, skb))) {
80439- atomic_long_inc(&dev->rx_dropped);
80440+ atomic_long_inc_unchecked(&dev->rx_dropped);
80441 kfree_skb(skb);
80442 return NET_RX_DROP;
80443 }
80444@@ -2180,7 +2184,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
80445
80446 struct dev_gso_cb {
80447 void (*destructor)(struct sk_buff *skb);
80448-};
80449+} __no_const;
80450
80451 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
80452
80453@@ -3053,7 +3057,7 @@ enqueue:
80454
80455 local_irq_restore(flags);
80456
80457- atomic_long_inc(&skb->dev->rx_dropped);
80458+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
80459 kfree_skb(skb);
80460 return NET_RX_DROP;
80461 }
80462@@ -3125,7 +3129,7 @@ int netif_rx_ni(struct sk_buff *skb)
80463 }
80464 EXPORT_SYMBOL(netif_rx_ni);
80465
80466-static void net_tx_action(struct softirq_action *h)
80467+static void net_tx_action(void)
80468 {
80469 struct softnet_data *sd = &__get_cpu_var(softnet_data);
80470
80471@@ -3456,7 +3460,7 @@ ncls:
80472 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
80473 } else {
80474 drop:
80475- atomic_long_inc(&skb->dev->rx_dropped);
80476+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
80477 kfree_skb(skb);
80478 /* Jamal, now you will not able to escape explaining
80479 * me how you were going to use this. :-)
80480@@ -4039,7 +4043,7 @@ void netif_napi_del(struct napi_struct *napi)
80481 }
80482 EXPORT_SYMBOL(netif_napi_del);
80483
80484-static void net_rx_action(struct softirq_action *h)
80485+static void net_rx_action(void)
80486 {
80487 struct softnet_data *sd = &__get_cpu_var(softnet_data);
80488 unsigned long time_limit = jiffies + 2;
80489@@ -4523,8 +4527,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
80490 else
80491 seq_printf(seq, "%04x", ntohs(pt->type));
80492
80493+#ifdef CONFIG_GRKERNSEC_HIDESYM
80494+ seq_printf(seq, " %-8s %p\n",
80495+ pt->dev ? pt->dev->name : "", NULL);
80496+#else
80497 seq_printf(seq, " %-8s %pF\n",
80498 pt->dev ? pt->dev->name : "", pt->func);
80499+#endif
80500 }
80501
80502 return 0;
80503@@ -6096,7 +6105,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
80504 } else {
80505 netdev_stats_to_stats64(storage, &dev->stats);
80506 }
80507- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
80508+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
80509 return storage;
80510 }
80511 EXPORT_SYMBOL(dev_get_stats);
80512diff --git a/net/core/flow.c b/net/core/flow.c
80513index b0901ee..7d3c2ca 100644
80514--- a/net/core/flow.c
80515+++ b/net/core/flow.c
80516@@ -61,7 +61,7 @@ struct flow_cache {
80517 struct timer_list rnd_timer;
80518 };
80519
80520-atomic_t flow_cache_genid = ATOMIC_INIT(0);
80521+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
80522 EXPORT_SYMBOL(flow_cache_genid);
80523 static struct flow_cache flow_cache_global;
80524 static struct kmem_cache *flow_cachep __read_mostly;
80525@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
80526
80527 static int flow_entry_valid(struct flow_cache_entry *fle)
80528 {
80529- if (atomic_read(&flow_cache_genid) != fle->genid)
80530+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
80531 return 0;
80532 if (fle->object && !fle->object->ops->check(fle->object))
80533 return 0;
80534@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
80535 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
80536 fcp->hash_count++;
80537 }
80538- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
80539+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
80540 flo = fle->object;
80541 if (!flo)
80542 goto ret_object;
80543@@ -280,7 +280,7 @@ nocache:
80544 }
80545 flo = resolver(net, key, family, dir, flo, ctx);
80546 if (fle) {
80547- fle->genid = atomic_read(&flow_cache_genid);
80548+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
80549 if (!IS_ERR(flo))
80550 fle->object = flo;
80551 else
80552diff --git a/net/core/iovec.c b/net/core/iovec.c
80553index 7e7aeb0..2a998cb 100644
80554--- a/net/core/iovec.c
80555+++ b/net/core/iovec.c
80556@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
80557 if (m->msg_namelen) {
80558 if (mode == VERIFY_READ) {
80559 void __user *namep;
80560- namep = (void __user __force *) m->msg_name;
80561+ namep = (void __force_user *) m->msg_name;
80562 err = move_addr_to_kernel(namep, m->msg_namelen,
80563 address);
80564 if (err < 0)
80565@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
80566 }
80567
80568 size = m->msg_iovlen * sizeof(struct iovec);
80569- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
80570+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
80571 return -EFAULT;
80572
80573 m->msg_iov = iov;
80574diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
80575index 1868625..5f4de62 100644
80576--- a/net/core/rtnetlink.c
80577+++ b/net/core/rtnetlink.c
80578@@ -58,7 +58,7 @@ struct rtnl_link {
80579 rtnl_doit_func doit;
80580 rtnl_dumpit_func dumpit;
80581 rtnl_calcit_func calcit;
80582-};
80583+} __no_const;
80584
80585 static DEFINE_MUTEX(rtnl_mutex);
80586
80587diff --git a/net/core/scm.c b/net/core/scm.c
80588index 905dcc6..14ee2d6 100644
80589--- a/net/core/scm.c
80590+++ b/net/core/scm.c
80591@@ -224,7 +224,7 @@ EXPORT_SYMBOL(__scm_send);
80592 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
80593 {
80594 struct cmsghdr __user *cm
80595- = (__force struct cmsghdr __user *)msg->msg_control;
80596+ = (struct cmsghdr __force_user *)msg->msg_control;
80597 struct cmsghdr cmhdr;
80598 int cmlen = CMSG_LEN(len);
80599 int err;
80600@@ -247,7 +247,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
80601 err = -EFAULT;
80602 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
80603 goto out;
80604- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
80605+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
80606 goto out;
80607 cmlen = CMSG_SPACE(len);
80608 if (msg->msg_controllen < cmlen)
80609@@ -263,7 +263,7 @@ EXPORT_SYMBOL(put_cmsg);
80610 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
80611 {
80612 struct cmsghdr __user *cm
80613- = (__force struct cmsghdr __user*)msg->msg_control;
80614+ = (struct cmsghdr __force_user *)msg->msg_control;
80615
80616 int fdmax = 0;
80617 int fdnum = scm->fp->count;
80618@@ -283,7 +283,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
80619 if (fdnum < fdmax)
80620 fdmax = fdnum;
80621
80622- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
80623+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
80624 i++, cmfptr++)
80625 {
80626 struct socket *sock;
80627diff --git a/net/core/sock.c b/net/core/sock.c
80628index bc131d4..029e378 100644
80629--- a/net/core/sock.c
80630+++ b/net/core/sock.c
80631@@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80632 struct sk_buff_head *list = &sk->sk_receive_queue;
80633
80634 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
80635- atomic_inc(&sk->sk_drops);
80636+ atomic_inc_unchecked(&sk->sk_drops);
80637 trace_sock_rcvqueue_full(sk, skb);
80638 return -ENOMEM;
80639 }
80640@@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80641 return err;
80642
80643 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
80644- atomic_inc(&sk->sk_drops);
80645+ atomic_inc_unchecked(&sk->sk_drops);
80646 return -ENOBUFS;
80647 }
80648
80649@@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80650 skb_dst_force(skb);
80651
80652 spin_lock_irqsave(&list->lock, flags);
80653- skb->dropcount = atomic_read(&sk->sk_drops);
80654+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
80655 __skb_queue_tail(list, skb);
80656 spin_unlock_irqrestore(&list->lock, flags);
80657
80658@@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
80659 skb->dev = NULL;
80660
80661 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
80662- atomic_inc(&sk->sk_drops);
80663+ atomic_inc_unchecked(&sk->sk_drops);
80664 goto discard_and_relse;
80665 }
80666 if (nested)
80667@@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
80668 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
80669 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
80670 bh_unlock_sock(sk);
80671- atomic_inc(&sk->sk_drops);
80672+ atomic_inc_unchecked(&sk->sk_drops);
80673 goto discard_and_relse;
80674 }
80675
80676@@ -930,12 +930,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
80677 struct timeval tm;
80678 } v;
80679
80680- int lv = sizeof(int);
80681- int len;
80682+ unsigned int lv = sizeof(int);
80683+ unsigned int len;
80684
80685 if (get_user(len, optlen))
80686 return -EFAULT;
80687- if (len < 0)
80688+ if (len > INT_MAX)
80689 return -EINVAL;
80690
80691 memset(&v, 0, sizeof(v));
80692@@ -1083,11 +1083,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
80693
80694 case SO_PEERNAME:
80695 {
80696- char address[128];
80697+ char address[_K_SS_MAXSIZE];
80698
80699 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
80700 return -ENOTCONN;
80701- if (lv < len)
80702+ if (lv < len || sizeof address < len)
80703 return -EINVAL;
80704 if (copy_to_user(optval, address, len))
80705 return -EFAULT;
80706@@ -1146,7 +1146,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
80707
80708 if (len > lv)
80709 len = lv;
80710- if (copy_to_user(optval, &v, len))
80711+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
80712 return -EFAULT;
80713 lenout:
80714 if (put_user(len, optlen))
80715@@ -2276,7 +2276,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
80716 */
80717 smp_wmb();
80718 atomic_set(&sk->sk_refcnt, 1);
80719- atomic_set(&sk->sk_drops, 0);
80720+ atomic_set_unchecked(&sk->sk_drops, 0);
80721 }
80722 EXPORT_SYMBOL(sock_init_data);
80723
80724diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
80725index 750f44f..0a699b1 100644
80726--- a/net/core/sock_diag.c
80727+++ b/net/core/sock_diag.c
80728@@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
80729
80730 int sock_diag_check_cookie(void *sk, __u32 *cookie)
80731 {
80732+#ifndef CONFIG_GRKERNSEC_HIDESYM
80733 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
80734 cookie[1] != INET_DIAG_NOCOOKIE) &&
80735 ((u32)(unsigned long)sk != cookie[0] ||
80736 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
80737 return -ESTALE;
80738 else
80739+#endif
80740 return 0;
80741 }
80742 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
80743
80744 void sock_diag_save_cookie(void *sk, __u32 *cookie)
80745 {
80746+#ifdef CONFIG_GRKERNSEC_HIDESYM
80747+ cookie[0] = 0;
80748+ cookie[1] = 0;
80749+#else
80750 cookie[0] = (u32)(unsigned long)sk;
80751 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
80752+#endif
80753 }
80754 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
80755
80756@@ -97,21 +104,6 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
80757 }
80758 EXPORT_SYMBOL_GPL(sock_diag_unregister);
80759
80760-static const inline struct sock_diag_handler *sock_diag_lock_handler(int family)
80761-{
80762- if (sock_diag_handlers[family] == NULL)
80763- request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
80764- NETLINK_SOCK_DIAG, family);
80765-
80766- mutex_lock(&sock_diag_table_mutex);
80767- return sock_diag_handlers[family];
80768-}
80769-
80770-static inline void sock_diag_unlock_handler(const struct sock_diag_handler *h)
80771-{
80772- mutex_unlock(&sock_diag_table_mutex);
80773-}
80774-
80775 static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
80776 {
80777 int err;
80778@@ -124,12 +116,17 @@ static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
80779 if (req->sdiag_family >= AF_MAX)
80780 return -EINVAL;
80781
80782- hndl = sock_diag_lock_handler(req->sdiag_family);
80783+ if (sock_diag_handlers[req->sdiag_family] == NULL)
80784+ request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
80785+ NETLINK_SOCK_DIAG, req->sdiag_family);
80786+
80787+ mutex_lock(&sock_diag_table_mutex);
80788+ hndl = sock_diag_handlers[req->sdiag_family];
80789 if (hndl == NULL)
80790 err = -ENOENT;
80791 else
80792 err = hndl->dump(skb, nlh);
80793- sock_diag_unlock_handler(hndl);
80794+ mutex_unlock(&sock_diag_table_mutex);
80795
80796 return err;
80797 }
80798diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
80799index a55eecc..dd8428c 100644
80800--- a/net/decnet/sysctl_net_decnet.c
80801+++ b/net/decnet/sysctl_net_decnet.c
80802@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
80803
80804 if (len > *lenp) len = *lenp;
80805
80806- if (copy_to_user(buffer, addr, len))
80807+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
80808 return -EFAULT;
80809
80810 *lenp = len;
80811@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
80812
80813 if (len > *lenp) len = *lenp;
80814
80815- if (copy_to_user(buffer, devname, len))
80816+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
80817 return -EFAULT;
80818
80819 *lenp = len;
80820diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
80821index a69b4e4..dbccba5 100644
80822--- a/net/ipv4/ah4.c
80823+++ b/net/ipv4/ah4.c
80824@@ -421,7 +421,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
80825 return;
80826
80827 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
80828- atomic_inc(&flow_cache_genid);
80829+ atomic_inc_unchecked(&flow_cache_genid);
80830 rt_genid_bump(net);
80831
80832 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
80833diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
80834index 3b4f0cd..8cb864c 100644
80835--- a/net/ipv4/esp4.c
80836+++ b/net/ipv4/esp4.c
80837@@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
80838 return;
80839
80840 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
80841- atomic_inc(&flow_cache_genid);
80842+ atomic_inc_unchecked(&flow_cache_genid);
80843 rt_genid_bump(net);
80844
80845 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
80846diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
80847index 5cd75e2..f57ef39 100644
80848--- a/net/ipv4/fib_frontend.c
80849+++ b/net/ipv4/fib_frontend.c
80850@@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
80851 #ifdef CONFIG_IP_ROUTE_MULTIPATH
80852 fib_sync_up(dev);
80853 #endif
80854- atomic_inc(&net->ipv4.dev_addr_genid);
80855+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
80856 rt_cache_flush(dev_net(dev));
80857 break;
80858 case NETDEV_DOWN:
80859 fib_del_ifaddr(ifa, NULL);
80860- atomic_inc(&net->ipv4.dev_addr_genid);
80861+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
80862 if (ifa->ifa_dev->ifa_list == NULL) {
80863 /* Last address was deleted from this interface.
80864 * Disable IP.
80865@@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
80866 #ifdef CONFIG_IP_ROUTE_MULTIPATH
80867 fib_sync_up(dev);
80868 #endif
80869- atomic_inc(&net->ipv4.dev_addr_genid);
80870+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
80871 rt_cache_flush(net);
80872 break;
80873 case NETDEV_DOWN:
80874diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
80875index 4797a80..2bd54e9 100644
80876--- a/net/ipv4/fib_semantics.c
80877+++ b/net/ipv4/fib_semantics.c
80878@@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
80879 nh->nh_saddr = inet_select_addr(nh->nh_dev,
80880 nh->nh_gw,
80881 nh->nh_parent->fib_scope);
80882- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
80883+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
80884
80885 return nh->nh_saddr;
80886 }
80887diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
80888index fa3ae81..0dbe6b8 100644
80889--- a/net/ipv4/inet_hashtables.c
80890+++ b/net/ipv4/inet_hashtables.c
80891@@ -18,12 +18,15 @@
80892 #include <linux/sched.h>
80893 #include <linux/slab.h>
80894 #include <linux/wait.h>
80895+#include <linux/security.h>
80896
80897 #include <net/inet_connection_sock.h>
80898 #include <net/inet_hashtables.h>
80899 #include <net/secure_seq.h>
80900 #include <net/ip.h>
80901
80902+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
80903+
80904 /*
80905 * Allocate and initialize a new local port bind bucket.
80906 * The bindhash mutex for snum's hash chain must be held here.
80907@@ -540,6 +543,8 @@ ok:
80908 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
80909 spin_unlock(&head->lock);
80910
80911+ gr_update_task_in_ip_table(current, inet_sk(sk));
80912+
80913 if (tw) {
80914 inet_twsk_deschedule(tw, death_row);
80915 while (twrefcnt) {
80916diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
80917index 000e3d2..5472da3 100644
80918--- a/net/ipv4/inetpeer.c
80919+++ b/net/ipv4/inetpeer.c
80920@@ -503,8 +503,8 @@ relookup:
80921 if (p) {
80922 p->daddr = *daddr;
80923 atomic_set(&p->refcnt, 1);
80924- atomic_set(&p->rid, 0);
80925- atomic_set(&p->ip_id_count,
80926+ atomic_set_unchecked(&p->rid, 0);
80927+ atomic_set_unchecked(&p->ip_id_count,
80928 (daddr->family == AF_INET) ?
80929 secure_ip_id(daddr->addr.a4) :
80930 secure_ipv6_id(daddr->addr.a6));
80931diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
80932index eb9d63a..50babc1 100644
80933--- a/net/ipv4/ip_fragment.c
80934+++ b/net/ipv4/ip_fragment.c
80935@@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
80936 return 0;
80937
80938 start = qp->rid;
80939- end = atomic_inc_return(&peer->rid);
80940+ end = atomic_inc_return_unchecked(&peer->rid);
80941 qp->rid = end;
80942
80943 rc = qp->q.fragments && (end - start) > max;
80944diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
80945index d9c4f11..02b82db 100644
80946--- a/net/ipv4/ip_sockglue.c
80947+++ b/net/ipv4/ip_sockglue.c
80948@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
80949 len = min_t(unsigned int, len, opt->optlen);
80950 if (put_user(len, optlen))
80951 return -EFAULT;
80952- if (copy_to_user(optval, opt->__data, len))
80953+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
80954+ copy_to_user(optval, opt->__data, len))
80955 return -EFAULT;
80956 return 0;
80957 }
80958@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
80959 if (sk->sk_type != SOCK_STREAM)
80960 return -ENOPROTOOPT;
80961
80962- msg.msg_control = optval;
80963+ msg.msg_control = (void __force_kernel *)optval;
80964 msg.msg_controllen = len;
80965 msg.msg_flags = flags;
80966
80967diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
80968index 9a46dae..5f793a0 100644
80969--- a/net/ipv4/ipcomp.c
80970+++ b/net/ipv4/ipcomp.c
80971@@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
80972 return;
80973
80974 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
80975- atomic_inc(&flow_cache_genid);
80976+ atomic_inc_unchecked(&flow_cache_genid);
80977 rt_genid_bump(net);
80978
80979 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
80980diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
80981index a2e50ae..e152b7c 100644
80982--- a/net/ipv4/ipconfig.c
80983+++ b/net/ipv4/ipconfig.c
80984@@ -323,7 +323,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
80985
80986 mm_segment_t oldfs = get_fs();
80987 set_fs(get_ds());
80988- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
80989+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
80990 set_fs(oldfs);
80991 return res;
80992 }
80993@@ -334,7 +334,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
80994
80995 mm_segment_t oldfs = get_fs();
80996 set_fs(get_ds());
80997- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
80998+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
80999 set_fs(oldfs);
81000 return res;
81001 }
81002@@ -345,7 +345,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
81003
81004 mm_segment_t oldfs = get_fs();
81005 set_fs(get_ds());
81006- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
81007+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
81008 set_fs(oldfs);
81009 return res;
81010 }
81011diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
81012index 3ea4127..849297b 100644
81013--- a/net/ipv4/netfilter/arp_tables.c
81014+++ b/net/ipv4/netfilter/arp_tables.c
81015@@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
81016 #endif
81017
81018 static int get_info(struct net *net, void __user *user,
81019- const int *len, int compat)
81020+ int len, int compat)
81021 {
81022 char name[XT_TABLE_MAXNAMELEN];
81023 struct xt_table *t;
81024 int ret;
81025
81026- if (*len != sizeof(struct arpt_getinfo)) {
81027- duprintf("length %u != %Zu\n", *len,
81028+ if (len != sizeof(struct arpt_getinfo)) {
81029+ duprintf("length %u != %Zu\n", len,
81030 sizeof(struct arpt_getinfo));
81031 return -EINVAL;
81032 }
81033@@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
81034 info.size = private->size;
81035 strcpy(info.name, name);
81036
81037- if (copy_to_user(user, &info, *len) != 0)
81038+ if (copy_to_user(user, &info, len) != 0)
81039 ret = -EFAULT;
81040 else
81041 ret = 0;
81042@@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
81043
81044 switch (cmd) {
81045 case ARPT_SO_GET_INFO:
81046- ret = get_info(sock_net(sk), user, len, 1);
81047+ ret = get_info(sock_net(sk), user, *len, 1);
81048 break;
81049 case ARPT_SO_GET_ENTRIES:
81050 ret = compat_get_entries(sock_net(sk), user, len);
81051@@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
81052
81053 switch (cmd) {
81054 case ARPT_SO_GET_INFO:
81055- ret = get_info(sock_net(sk), user, len, 0);
81056+ ret = get_info(sock_net(sk), user, *len, 0);
81057 break;
81058
81059 case ARPT_SO_GET_ENTRIES:
81060diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
81061index 17c5e06..1b91206 100644
81062--- a/net/ipv4/netfilter/ip_tables.c
81063+++ b/net/ipv4/netfilter/ip_tables.c
81064@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
81065 #endif
81066
81067 static int get_info(struct net *net, void __user *user,
81068- const int *len, int compat)
81069+ int len, int compat)
81070 {
81071 char name[XT_TABLE_MAXNAMELEN];
81072 struct xt_table *t;
81073 int ret;
81074
81075- if (*len != sizeof(struct ipt_getinfo)) {
81076- duprintf("length %u != %zu\n", *len,
81077+ if (len != sizeof(struct ipt_getinfo)) {
81078+ duprintf("length %u != %zu\n", len,
81079 sizeof(struct ipt_getinfo));
81080 return -EINVAL;
81081 }
81082@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
81083 info.size = private->size;
81084 strcpy(info.name, name);
81085
81086- if (copy_to_user(user, &info, *len) != 0)
81087+ if (copy_to_user(user, &info, len) != 0)
81088 ret = -EFAULT;
81089 else
81090 ret = 0;
81091@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
81092
81093 switch (cmd) {
81094 case IPT_SO_GET_INFO:
81095- ret = get_info(sock_net(sk), user, len, 1);
81096+ ret = get_info(sock_net(sk), user, *len, 1);
81097 break;
81098 case IPT_SO_GET_ENTRIES:
81099 ret = compat_get_entries(sock_net(sk), user, len);
81100@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
81101
81102 switch (cmd) {
81103 case IPT_SO_GET_INFO:
81104- ret = get_info(sock_net(sk), user, len, 0);
81105+ ret = get_info(sock_net(sk), user, *len, 0);
81106 break;
81107
81108 case IPT_SO_GET_ENTRIES:
81109diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
81110index dc454cc..5bb917f 100644
81111--- a/net/ipv4/ping.c
81112+++ b/net/ipv4/ping.c
81113@@ -844,7 +844,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
81114 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
81115 0, sock_i_ino(sp),
81116 atomic_read(&sp->sk_refcnt), sp,
81117- atomic_read(&sp->sk_drops), len);
81118+ atomic_read_unchecked(&sp->sk_drops), len);
81119 }
81120
81121 static int ping_seq_show(struct seq_file *seq, void *v)
81122diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
81123index 6f08991..55867ad 100644
81124--- a/net/ipv4/raw.c
81125+++ b/net/ipv4/raw.c
81126@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
81127 int raw_rcv(struct sock *sk, struct sk_buff *skb)
81128 {
81129 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
81130- atomic_inc(&sk->sk_drops);
81131+ atomic_inc_unchecked(&sk->sk_drops);
81132 kfree_skb(skb);
81133 return NET_RX_DROP;
81134 }
81135@@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
81136
81137 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
81138 {
81139+ struct icmp_filter filter;
81140+
81141 if (optlen > sizeof(struct icmp_filter))
81142 optlen = sizeof(struct icmp_filter);
81143- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
81144+ if (copy_from_user(&filter, optval, optlen))
81145 return -EFAULT;
81146+ raw_sk(sk)->filter = filter;
81147 return 0;
81148 }
81149
81150 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
81151 {
81152 int len, ret = -EFAULT;
81153+ struct icmp_filter filter;
81154
81155 if (get_user(len, optlen))
81156 goto out;
81157@@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
81158 if (len > sizeof(struct icmp_filter))
81159 len = sizeof(struct icmp_filter);
81160 ret = -EFAULT;
81161- if (put_user(len, optlen) ||
81162- copy_to_user(optval, &raw_sk(sk)->filter, len))
81163+ filter = raw_sk(sk)->filter;
81164+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
81165 goto out;
81166 ret = 0;
81167 out: return ret;
81168@@ -998,7 +1002,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
81169 0, 0L, 0,
81170 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
81171 0, sock_i_ino(sp),
81172- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
81173+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
81174 }
81175
81176 static int raw_seq_show(struct seq_file *seq, void *v)
81177diff --git a/net/ipv4/route.c b/net/ipv4/route.c
81178index a0fcc47..5949bba1 100644
81179--- a/net/ipv4/route.c
81180+++ b/net/ipv4/route.c
81181@@ -2602,7 +2602,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
81182
81183 static __net_init int rt_genid_init(struct net *net)
81184 {
81185- atomic_set(&net->rt_genid, 0);
81186+ atomic_set_unchecked(&net->rt_genid, 0);
81187 get_random_bytes(&net->ipv4.dev_addr_genid,
81188 sizeof(net->ipv4.dev_addr_genid));
81189 return 0;
81190diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
81191index ad70a96..50cb55b 100644
81192--- a/net/ipv4/tcp_input.c
81193+++ b/net/ipv4/tcp_input.c
81194@@ -4733,7 +4733,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
81195 * simplifies code)
81196 */
81197 static void
81198-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
81199+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
81200 struct sk_buff *head, struct sk_buff *tail,
81201 u32 start, u32 end)
81202 {
81203@@ -5850,6 +5850,7 @@ discard:
81204 tcp_paws_reject(&tp->rx_opt, 0))
81205 goto discard_and_undo;
81206
81207+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
81208 if (th->syn) {
81209 /* We see SYN without ACK. It is attempt of
81210 * simultaneous connect with crossed SYNs.
81211@@ -5900,6 +5901,7 @@ discard:
81212 goto discard;
81213 #endif
81214 }
81215+#endif
81216 /* "fifth, if neither of the SYN or RST bits is set then
81217 * drop the segment and return."
81218 */
81219@@ -5944,7 +5946,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
81220 goto discard;
81221
81222 if (th->syn) {
81223- if (th->fin)
81224+ if (th->fin || th->urg || th->psh)
81225 goto discard;
81226 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
81227 return 1;
81228diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
81229index eadb693..e8f7251 100644
81230--- a/net/ipv4/tcp_ipv4.c
81231+++ b/net/ipv4/tcp_ipv4.c
81232@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
81233 EXPORT_SYMBOL(sysctl_tcp_low_latency);
81234
81235
81236+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81237+extern int grsec_enable_blackhole;
81238+#endif
81239+
81240 #ifdef CONFIG_TCP_MD5SIG
81241 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
81242 __be32 daddr, __be32 saddr, const struct tcphdr *th);
81243@@ -1895,6 +1899,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
81244 return 0;
81245
81246 reset:
81247+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81248+ if (!grsec_enable_blackhole)
81249+#endif
81250 tcp_v4_send_reset(rsk, skb);
81251 discard:
81252 kfree_skb(skb);
81253@@ -1994,12 +2001,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
81254 TCP_SKB_CB(skb)->sacked = 0;
81255
81256 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
81257- if (!sk)
81258+ if (!sk) {
81259+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81260+ ret = 1;
81261+#endif
81262 goto no_tcp_socket;
81263-
81264+ }
81265 process:
81266- if (sk->sk_state == TCP_TIME_WAIT)
81267+ if (sk->sk_state == TCP_TIME_WAIT) {
81268+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81269+ ret = 2;
81270+#endif
81271 goto do_time_wait;
81272+ }
81273
81274 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
81275 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
81276@@ -2050,6 +2064,10 @@ no_tcp_socket:
81277 bad_packet:
81278 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
81279 } else {
81280+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81281+ if (!grsec_enable_blackhole || (ret == 1 &&
81282+ (skb->dev->flags & IFF_LOOPBACK)))
81283+#endif
81284 tcp_v4_send_reset(NULL, skb);
81285 }
81286
81287diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
81288index f35f2df..ccb5ca6 100644
81289--- a/net/ipv4/tcp_minisocks.c
81290+++ b/net/ipv4/tcp_minisocks.c
81291@@ -27,6 +27,10 @@
81292 #include <net/inet_common.h>
81293 #include <net/xfrm.h>
81294
81295+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81296+extern int grsec_enable_blackhole;
81297+#endif
81298+
81299 int sysctl_tcp_syncookies __read_mostly = 1;
81300 EXPORT_SYMBOL(sysctl_tcp_syncookies);
81301
81302@@ -742,7 +746,10 @@ embryonic_reset:
81303 * avoid becoming vulnerable to outside attack aiming at
81304 * resetting legit local connections.
81305 */
81306- req->rsk_ops->send_reset(sk, skb);
81307+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81308+ if (!grsec_enable_blackhole)
81309+#endif
81310+ req->rsk_ops->send_reset(sk, skb);
81311 } else if (fastopen) { /* received a valid RST pkt */
81312 reqsk_fastopen_remove(sk, req, true);
81313 tcp_reset(sk);
81314diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
81315index 4526fe6..1a34e43 100644
81316--- a/net/ipv4/tcp_probe.c
81317+++ b/net/ipv4/tcp_probe.c
81318@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
81319 if (cnt + width >= len)
81320 break;
81321
81322- if (copy_to_user(buf + cnt, tbuf, width))
81323+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
81324 return -EFAULT;
81325 cnt += width;
81326 }
81327diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
81328index b78aac3..e18230b 100644
81329--- a/net/ipv4/tcp_timer.c
81330+++ b/net/ipv4/tcp_timer.c
81331@@ -22,6 +22,10 @@
81332 #include <linux/gfp.h>
81333 #include <net/tcp.h>
81334
81335+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81336+extern int grsec_lastack_retries;
81337+#endif
81338+
81339 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
81340 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
81341 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
81342@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
81343 }
81344 }
81345
81346+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81347+ if ((sk->sk_state == TCP_LAST_ACK) &&
81348+ (grsec_lastack_retries > 0) &&
81349+ (grsec_lastack_retries < retry_until))
81350+ retry_until = grsec_lastack_retries;
81351+#endif
81352+
81353 if (retransmits_timed_out(sk, retry_until,
81354 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
81355 /* Has it gone just too far? */
81356diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
81357index 1f4d405..3524677 100644
81358--- a/net/ipv4/udp.c
81359+++ b/net/ipv4/udp.c
81360@@ -87,6 +87,7 @@
81361 #include <linux/types.h>
81362 #include <linux/fcntl.h>
81363 #include <linux/module.h>
81364+#include <linux/security.h>
81365 #include <linux/socket.h>
81366 #include <linux/sockios.h>
81367 #include <linux/igmp.h>
81368@@ -111,6 +112,10 @@
81369 #include <trace/events/skb.h>
81370 #include "udp_impl.h"
81371
81372+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81373+extern int grsec_enable_blackhole;
81374+#endif
81375+
81376 struct udp_table udp_table __read_mostly;
81377 EXPORT_SYMBOL(udp_table);
81378
81379@@ -569,6 +574,9 @@ found:
81380 return s;
81381 }
81382
81383+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
81384+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
81385+
81386 /*
81387 * This routine is called by the ICMP module when it gets some
81388 * sort of error condition. If err < 0 then the socket should
81389@@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
81390 dport = usin->sin_port;
81391 if (dport == 0)
81392 return -EINVAL;
81393+
81394+ err = gr_search_udp_sendmsg(sk, usin);
81395+ if (err)
81396+ return err;
81397 } else {
81398 if (sk->sk_state != TCP_ESTABLISHED)
81399 return -EDESTADDRREQ;
81400+
81401+ err = gr_search_udp_sendmsg(sk, NULL);
81402+ if (err)
81403+ return err;
81404+
81405 daddr = inet->inet_daddr;
81406 dport = inet->inet_dport;
81407 /* Open fast path for connected socket.
81408@@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
81409 udp_lib_checksum_complete(skb)) {
81410 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
81411 IS_UDPLITE(sk));
81412- atomic_inc(&sk->sk_drops);
81413+ atomic_inc_unchecked(&sk->sk_drops);
81414 __skb_unlink(skb, rcvq);
81415 __skb_queue_tail(&list_kill, skb);
81416 }
81417@@ -1194,6 +1211,10 @@ try_again:
81418 if (!skb)
81419 goto out;
81420
81421+ err = gr_search_udp_recvmsg(sk, skb);
81422+ if (err)
81423+ goto out_free;
81424+
81425 ulen = skb->len - sizeof(struct udphdr);
81426 copied = len;
81427 if (copied > ulen)
81428@@ -1227,7 +1248,7 @@ try_again:
81429 if (unlikely(err)) {
81430 trace_kfree_skb(skb, udp_recvmsg);
81431 if (!peeked) {
81432- atomic_inc(&sk->sk_drops);
81433+ atomic_inc_unchecked(&sk->sk_drops);
81434 UDP_INC_STATS_USER(sock_net(sk),
81435 UDP_MIB_INERRORS, is_udplite);
81436 }
81437@@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
81438
81439 drop:
81440 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
81441- atomic_inc(&sk->sk_drops);
81442+ atomic_inc_unchecked(&sk->sk_drops);
81443 kfree_skb(skb);
81444 return -1;
81445 }
81446@@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
81447 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
81448
81449 if (!skb1) {
81450- atomic_inc(&sk->sk_drops);
81451+ atomic_inc_unchecked(&sk->sk_drops);
81452 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
81453 IS_UDPLITE(sk));
81454 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
81455@@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
81456 goto csum_error;
81457
81458 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
81459+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81460+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
81461+#endif
81462 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
81463
81464 /*
81465@@ -2120,7 +2144,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
81466 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
81467 0, sock_i_ino(sp),
81468 atomic_read(&sp->sk_refcnt), sp,
81469- atomic_read(&sp->sk_drops), len);
81470+ atomic_read_unchecked(&sp->sk_drops), len);
81471 }
81472
81473 int udp4_seq_show(struct seq_file *seq, void *v)
81474diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
81475index 1b5d8cb..2e8c2d9 100644
81476--- a/net/ipv6/addrconf.c
81477+++ b/net/ipv6/addrconf.c
81478@@ -2272,7 +2272,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
81479 p.iph.ihl = 5;
81480 p.iph.protocol = IPPROTO_IPV6;
81481 p.iph.ttl = 64;
81482- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
81483+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
81484
81485 if (ops->ndo_do_ioctl) {
81486 mm_segment_t oldfs = get_fs();
81487diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
81488index 131dd09..7647ada 100644
81489--- a/net/ipv6/ip6_gre.c
81490+++ b/net/ipv6/ip6_gre.c
81491@@ -1337,7 +1337,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
81492 }
81493
81494
81495-static struct inet6_protocol ip6gre_protocol __read_mostly = {
81496+static struct inet6_protocol ip6gre_protocol = {
81497 .handler = ip6gre_rcv,
81498 .err_handler = ip6gre_err,
81499 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
81500diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
81501index d1e2e8e..51c19ae 100644
81502--- a/net/ipv6/ipv6_sockglue.c
81503+++ b/net/ipv6/ipv6_sockglue.c
81504@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
81505 if (sk->sk_type != SOCK_STREAM)
81506 return -ENOPROTOOPT;
81507
81508- msg.msg_control = optval;
81509+ msg.msg_control = (void __force_kernel *)optval;
81510 msg.msg_controllen = len;
81511 msg.msg_flags = flags;
81512
81513diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
81514index 125a90d..2a11f36 100644
81515--- a/net/ipv6/netfilter/ip6_tables.c
81516+++ b/net/ipv6/netfilter/ip6_tables.c
81517@@ -1076,14 +1076,14 @@ static int compat_table_info(const struct xt_table_info *info,
81518 #endif
81519
81520 static int get_info(struct net *net, void __user *user,
81521- const int *len, int compat)
81522+ int len, int compat)
81523 {
81524 char name[XT_TABLE_MAXNAMELEN];
81525 struct xt_table *t;
81526 int ret;
81527
81528- if (*len != sizeof(struct ip6t_getinfo)) {
81529- duprintf("length %u != %zu\n", *len,
81530+ if (len != sizeof(struct ip6t_getinfo)) {
81531+ duprintf("length %u != %zu\n", len,
81532 sizeof(struct ip6t_getinfo));
81533 return -EINVAL;
81534 }
81535@@ -1120,7 +1120,7 @@ static int get_info(struct net *net, void __user *user,
81536 info.size = private->size;
81537 strcpy(info.name, name);
81538
81539- if (copy_to_user(user, &info, *len) != 0)
81540+ if (copy_to_user(user, &info, len) != 0)
81541 ret = -EFAULT;
81542 else
81543 ret = 0;
81544@@ -1974,7 +1974,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
81545
81546 switch (cmd) {
81547 case IP6T_SO_GET_INFO:
81548- ret = get_info(sock_net(sk), user, len, 1);
81549+ ret = get_info(sock_net(sk), user, *len, 1);
81550 break;
81551 case IP6T_SO_GET_ENTRIES:
81552 ret = compat_get_entries(sock_net(sk), user, len);
81553@@ -2021,7 +2021,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
81554
81555 switch (cmd) {
81556 case IP6T_SO_GET_INFO:
81557- ret = get_info(sock_net(sk), user, len, 0);
81558+ ret = get_info(sock_net(sk), user, *len, 0);
81559 break;
81560
81561 case IP6T_SO_GET_ENTRIES:
81562diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
81563index 70fa814..d70c28c 100644
81564--- a/net/ipv6/raw.c
81565+++ b/net/ipv6/raw.c
81566@@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
81567 {
81568 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
81569 skb_checksum_complete(skb)) {
81570- atomic_inc(&sk->sk_drops);
81571+ atomic_inc_unchecked(&sk->sk_drops);
81572 kfree_skb(skb);
81573 return NET_RX_DROP;
81574 }
81575@@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
81576 struct raw6_sock *rp = raw6_sk(sk);
81577
81578 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
81579- atomic_inc(&sk->sk_drops);
81580+ atomic_inc_unchecked(&sk->sk_drops);
81581 kfree_skb(skb);
81582 return NET_RX_DROP;
81583 }
81584@@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
81585
81586 if (inet->hdrincl) {
81587 if (skb_checksum_complete(skb)) {
81588- atomic_inc(&sk->sk_drops);
81589+ atomic_inc_unchecked(&sk->sk_drops);
81590 kfree_skb(skb);
81591 return NET_RX_DROP;
81592 }
81593@@ -604,7 +604,7 @@ out:
81594 return err;
81595 }
81596
81597-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
81598+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
81599 struct flowi6 *fl6, struct dst_entry **dstp,
81600 unsigned int flags)
81601 {
81602@@ -916,12 +916,15 @@ do_confirm:
81603 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
81604 char __user *optval, int optlen)
81605 {
81606+ struct icmp6_filter filter;
81607+
81608 switch (optname) {
81609 case ICMPV6_FILTER:
81610 if (optlen > sizeof(struct icmp6_filter))
81611 optlen = sizeof(struct icmp6_filter);
81612- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
81613+ if (copy_from_user(&filter, optval, optlen))
81614 return -EFAULT;
81615+ raw6_sk(sk)->filter = filter;
81616 return 0;
81617 default:
81618 return -ENOPROTOOPT;
81619@@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
81620 char __user *optval, int __user *optlen)
81621 {
81622 int len;
81623+ struct icmp6_filter filter;
81624
81625 switch (optname) {
81626 case ICMPV6_FILTER:
81627@@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
81628 len = sizeof(struct icmp6_filter);
81629 if (put_user(len, optlen))
81630 return -EFAULT;
81631- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
81632+ filter = raw6_sk(sk)->filter;
81633+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
81634 return -EFAULT;
81635 return 0;
81636 default:
81637@@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
81638 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
81639 0,
81640 sock_i_ino(sp),
81641- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
81642+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
81643 }
81644
81645 static int raw6_seq_show(struct seq_file *seq, void *v)
81646diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
81647index 4f435371..5de9da7 100644
81648--- a/net/ipv6/tcp_ipv6.c
81649+++ b/net/ipv6/tcp_ipv6.c
81650@@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
81651 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
81652 }
81653
81654+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81655+extern int grsec_enable_blackhole;
81656+#endif
81657+
81658 static void tcp_v6_hash(struct sock *sk)
81659 {
81660 if (sk->sk_state != TCP_CLOSE) {
81661@@ -1433,6 +1437,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
81662 return 0;
81663
81664 reset:
81665+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81666+ if (!grsec_enable_blackhole)
81667+#endif
81668 tcp_v6_send_reset(sk, skb);
81669 discard:
81670 if (opt_skb)
81671@@ -1514,12 +1521,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
81672 TCP_SKB_CB(skb)->sacked = 0;
81673
81674 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
81675- if (!sk)
81676+ if (!sk) {
81677+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81678+ ret = 1;
81679+#endif
81680 goto no_tcp_socket;
81681+ }
81682
81683 process:
81684- if (sk->sk_state == TCP_TIME_WAIT)
81685+ if (sk->sk_state == TCP_TIME_WAIT) {
81686+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81687+ ret = 2;
81688+#endif
81689 goto do_time_wait;
81690+ }
81691
81692 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
81693 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
81694@@ -1568,6 +1583,10 @@ no_tcp_socket:
81695 bad_packet:
81696 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
81697 } else {
81698+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81699+ if (!grsec_enable_blackhole || (ret == 1 &&
81700+ (skb->dev->flags & IFF_LOOPBACK)))
81701+#endif
81702 tcp_v6_send_reset(NULL, skb);
81703 }
81704
81705diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
81706index fb08329..2d6919e 100644
81707--- a/net/ipv6/udp.c
81708+++ b/net/ipv6/udp.c
81709@@ -51,6 +51,10 @@
81710 #include <trace/events/skb.h>
81711 #include "udp_impl.h"
81712
81713+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81714+extern int grsec_enable_blackhole;
81715+#endif
81716+
81717 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
81718 {
81719 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
81720@@ -395,7 +399,7 @@ try_again:
81721 if (unlikely(err)) {
81722 trace_kfree_skb(skb, udpv6_recvmsg);
81723 if (!peeked) {
81724- atomic_inc(&sk->sk_drops);
81725+ atomic_inc_unchecked(&sk->sk_drops);
81726 if (is_udp4)
81727 UDP_INC_STATS_USER(sock_net(sk),
81728 UDP_MIB_INERRORS,
81729@@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
81730 return rc;
81731 drop:
81732 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
81733- atomic_inc(&sk->sk_drops);
81734+ atomic_inc_unchecked(&sk->sk_drops);
81735 kfree_skb(skb);
81736 return -1;
81737 }
81738@@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
81739 if (likely(skb1 == NULL))
81740 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
81741 if (!skb1) {
81742- atomic_inc(&sk->sk_drops);
81743+ atomic_inc_unchecked(&sk->sk_drops);
81744 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
81745 IS_UDPLITE(sk));
81746 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
81747@@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
81748 goto discard;
81749
81750 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
81751+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81752+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
81753+#endif
81754 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
81755
81756 kfree_skb(skb);
81757@@ -1379,7 +1386,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
81758 0,
81759 sock_i_ino(sp),
81760 atomic_read(&sp->sk_refcnt), sp,
81761- atomic_read(&sp->sk_drops));
81762+ atomic_read_unchecked(&sp->sk_drops));
81763 }
81764
81765 int udp6_seq_show(struct seq_file *seq, void *v)
81766diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
81767index a68c88c..d55b0c5 100644
81768--- a/net/irda/ircomm/ircomm_tty.c
81769+++ b/net/irda/ircomm/ircomm_tty.c
81770@@ -312,12 +312,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
81771 add_wait_queue(&port->open_wait, &wait);
81772
81773 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
81774- __FILE__, __LINE__, tty->driver->name, port->count);
81775+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
81776
81777 spin_lock_irqsave(&port->lock, flags);
81778 if (!tty_hung_up_p(filp)) {
81779 extra_count = 1;
81780- port->count--;
81781+ atomic_dec(&port->count);
81782 }
81783 spin_unlock_irqrestore(&port->lock, flags);
81784 port->blocked_open++;
81785@@ -353,7 +353,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
81786 }
81787
81788 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
81789- __FILE__, __LINE__, tty->driver->name, port->count);
81790+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
81791
81792 schedule();
81793 }
81794@@ -364,13 +364,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
81795 if (extra_count) {
81796 /* ++ is not atomic, so this should be protected - Jean II */
81797 spin_lock_irqsave(&port->lock, flags);
81798- port->count++;
81799+ atomic_inc(&port->count);
81800 spin_unlock_irqrestore(&port->lock, flags);
81801 }
81802 port->blocked_open--;
81803
81804 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
81805- __FILE__, __LINE__, tty->driver->name, port->count);
81806+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
81807
81808 if (!retval)
81809 port->flags |= ASYNC_NORMAL_ACTIVE;
81810@@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
81811
81812 /* ++ is not atomic, so this should be protected - Jean II */
81813 spin_lock_irqsave(&self->port.lock, flags);
81814- self->port.count++;
81815+ atomic_inc(&self->port.count);
81816 spin_unlock_irqrestore(&self->port.lock, flags);
81817 tty_port_tty_set(&self->port, tty);
81818
81819 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
81820- self->line, self->port.count);
81821+ self->line, atomic_read(&self->port.count));
81822
81823 /* Not really used by us, but lets do it anyway */
81824 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
81825@@ -986,7 +986,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
81826 tty_kref_put(port->tty);
81827 }
81828 port->tty = NULL;
81829- port->count = 0;
81830+ atomic_set(&port->count, 0);
81831 spin_unlock_irqrestore(&port->lock, flags);
81832
81833 wake_up_interruptible(&port->open_wait);
81834@@ -1343,7 +1343,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
81835 seq_putc(m, '\n');
81836
81837 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
81838- seq_printf(m, "Open count: %d\n", self->port.count);
81839+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
81840 seq_printf(m, "Max data size: %d\n", self->max_data_size);
81841 seq_printf(m, "Max header size: %d\n", self->max_header_size);
81842
81843diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
81844index cd6f7a9..e63fe89 100644
81845--- a/net/iucv/af_iucv.c
81846+++ b/net/iucv/af_iucv.c
81847@@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
81848
81849 write_lock_bh(&iucv_sk_list.lock);
81850
81851- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
81852+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
81853 while (__iucv_get_sock_by_name(name)) {
81854 sprintf(name, "%08x",
81855- atomic_inc_return(&iucv_sk_list.autobind_name));
81856+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
81857 }
81858
81859 write_unlock_bh(&iucv_sk_list.lock);
81860diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
81861index df08250..02021fe 100644
81862--- a/net/iucv/iucv.c
81863+++ b/net/iucv/iucv.c
81864@@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
81865 return NOTIFY_OK;
81866 }
81867
81868-static struct notifier_block __refdata iucv_cpu_notifier = {
81869+static struct notifier_block iucv_cpu_notifier = {
81870 .notifier_call = iucv_cpu_notify,
81871 };
81872
81873diff --git a/net/key/af_key.c b/net/key/af_key.c
81874index 5b426a6..970032b 100644
81875--- a/net/key/af_key.c
81876+++ b/net/key/af_key.c
81877@@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
81878 static u32 get_acqseq(void)
81879 {
81880 u32 res;
81881- static atomic_t acqseq;
81882+ static atomic_unchecked_t acqseq;
81883
81884 do {
81885- res = atomic_inc_return(&acqseq);
81886+ res = atomic_inc_return_unchecked(&acqseq);
81887 } while (!res);
81888 return res;
81889 }
81890diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
81891index 0479c64..d031db6 100644
81892--- a/net/mac80211/cfg.c
81893+++ b/net/mac80211/cfg.c
81894@@ -790,7 +790,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
81895 ret = ieee80211_vif_use_channel(sdata, chandef,
81896 IEEE80211_CHANCTX_EXCLUSIVE);
81897 }
81898- } else if (local->open_count == local->monitors) {
81899+ } else if (local_read(&local->open_count) == local->monitors) {
81900 local->_oper_channel = chandef->chan;
81901 local->_oper_channel_type = cfg80211_get_chandef_type(chandef);
81902 ieee80211_hw_config(local, 0);
81903@@ -2716,7 +2716,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
81904 else
81905 local->probe_req_reg--;
81906
81907- if (!local->open_count)
81908+ if (!local_read(&local->open_count))
81909 break;
81910
81911 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
81912diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
81913index 2ed065c..948177f 100644
81914--- a/net/mac80211/ieee80211_i.h
81915+++ b/net/mac80211/ieee80211_i.h
81916@@ -28,6 +28,7 @@
81917 #include <net/ieee80211_radiotap.h>
81918 #include <net/cfg80211.h>
81919 #include <net/mac80211.h>
81920+#include <asm/local.h>
81921 #include "key.h"
81922 #include "sta_info.h"
81923 #include "debug.h"
81924@@ -909,7 +910,7 @@ struct ieee80211_local {
81925 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
81926 spinlock_t queue_stop_reason_lock;
81927
81928- int open_count;
81929+ local_t open_count;
81930 int monitors, cooked_mntrs;
81931 /* number of interfaces with corresponding FIF_ flags */
81932 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
81933diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
81934index 8be854e..ad72a69 100644
81935--- a/net/mac80211/iface.c
81936+++ b/net/mac80211/iface.c
81937@@ -546,7 +546,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
81938 break;
81939 }
81940
81941- if (local->open_count == 0) {
81942+ if (local_read(&local->open_count) == 0) {
81943 res = drv_start(local);
81944 if (res)
81945 goto err_del_bss;
81946@@ -591,7 +591,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
81947 break;
81948 }
81949
81950- if (local->monitors == 0 && local->open_count == 0) {
81951+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
81952 res = ieee80211_add_virtual_monitor(local);
81953 if (res)
81954 goto err_stop;
81955@@ -699,7 +699,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
81956 mutex_unlock(&local->mtx);
81957
81958 if (coming_up)
81959- local->open_count++;
81960+ local_inc(&local->open_count);
81961
81962 if (hw_reconf_flags)
81963 ieee80211_hw_config(local, hw_reconf_flags);
81964@@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
81965 err_del_interface:
81966 drv_remove_interface(local, sdata);
81967 err_stop:
81968- if (!local->open_count)
81969+ if (!local_read(&local->open_count))
81970 drv_stop(local);
81971 err_del_bss:
81972 sdata->bss = NULL;
81973@@ -827,7 +827,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
81974 }
81975
81976 if (going_down)
81977- local->open_count--;
81978+ local_dec(&local->open_count);
81979
81980 switch (sdata->vif.type) {
81981 case NL80211_IFTYPE_AP_VLAN:
81982@@ -884,7 +884,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
81983
81984 ieee80211_recalc_ps(local, -1);
81985
81986- if (local->open_count == 0) {
81987+ if (local_read(&local->open_count) == 0) {
81988 if (local->ops->napi_poll)
81989 napi_disable(&local->napi);
81990 ieee80211_clear_tx_pending(local);
81991@@ -910,7 +910,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
81992 }
81993 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
81994
81995- if (local->monitors == local->open_count && local->monitors > 0)
81996+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
81997 ieee80211_add_virtual_monitor(local);
81998 }
81999
82000diff --git a/net/mac80211/main.c b/net/mac80211/main.c
82001index 1b087ff..bf600e9 100644
82002--- a/net/mac80211/main.c
82003+++ b/net/mac80211/main.c
82004@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
82005 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
82006 IEEE80211_CONF_CHANGE_POWER);
82007
82008- if (changed && local->open_count) {
82009+ if (changed && local_read(&local->open_count)) {
82010 ret = drv_config(local, changed);
82011 /*
82012 * Goal:
82013diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
82014index 79a48f3..5e185c9 100644
82015--- a/net/mac80211/pm.c
82016+++ b/net/mac80211/pm.c
82017@@ -35,7 +35,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
82018 struct sta_info *sta;
82019 struct ieee80211_chanctx *ctx;
82020
82021- if (!local->open_count)
82022+ if (!local_read(&local->open_count))
82023 goto suspend;
82024
82025 ieee80211_scan_cancel(local);
82026@@ -73,7 +73,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
82027 cancel_work_sync(&local->dynamic_ps_enable_work);
82028 del_timer_sync(&local->dynamic_ps_timer);
82029
82030- local->wowlan = wowlan && local->open_count;
82031+ local->wowlan = wowlan && local_read(&local->open_count);
82032 if (local->wowlan) {
82033 int err = drv_suspend(local, wowlan);
82034 if (err < 0) {
82035@@ -187,7 +187,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
82036 mutex_unlock(&local->chanctx_mtx);
82037
82038 /* stop hardware - this must stop RX */
82039- if (local->open_count)
82040+ if (local_read(&local->open_count))
82041 ieee80211_stop_device(local);
82042
82043 suspend:
82044diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
82045index dd88381..eef4dd6 100644
82046--- a/net/mac80211/rate.c
82047+++ b/net/mac80211/rate.c
82048@@ -493,7 +493,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
82049
82050 ASSERT_RTNL();
82051
82052- if (local->open_count)
82053+ if (local_read(&local->open_count))
82054 return -EBUSY;
82055
82056 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
82057diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
82058index c97a065..ff61928 100644
82059--- a/net/mac80211/rc80211_pid_debugfs.c
82060+++ b/net/mac80211/rc80211_pid_debugfs.c
82061@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
82062
82063 spin_unlock_irqrestore(&events->lock, status);
82064
82065- if (copy_to_user(buf, pb, p))
82066+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
82067 return -EFAULT;
82068
82069 return p;
82070diff --git a/net/mac80211/util.c b/net/mac80211/util.c
82071index f11e8c5..08d0013 100644
82072--- a/net/mac80211/util.c
82073+++ b/net/mac80211/util.c
82074@@ -1380,7 +1380,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
82075 }
82076 #endif
82077 /* everything else happens only if HW was up & running */
82078- if (!local->open_count)
82079+ if (!local_read(&local->open_count))
82080 goto wake_up;
82081
82082 /*
82083diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
82084index 49e96df..63a51c3 100644
82085--- a/net/netfilter/Kconfig
82086+++ b/net/netfilter/Kconfig
82087@@ -936,6 +936,16 @@ config NETFILTER_XT_MATCH_ESP
82088
82089 To compile it as a module, choose M here. If unsure, say N.
82090
82091+config NETFILTER_XT_MATCH_GRADM
82092+ tristate '"gradm" match support'
82093+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
82094+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
82095+ ---help---
82096+ The gradm match allows to match on grsecurity RBAC being enabled.
82097+ It is useful when iptables rules are applied early on bootup to
82098+ prevent connections to the machine (except from a trusted host)
82099+ while the RBAC system is disabled.
82100+
82101 config NETFILTER_XT_MATCH_HASHLIMIT
82102 tristate '"hashlimit" match support'
82103 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
82104diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
82105index 3259697..54d5393 100644
82106--- a/net/netfilter/Makefile
82107+++ b/net/netfilter/Makefile
82108@@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
82109 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
82110 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
82111 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
82112+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
82113 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
82114 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
82115 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
82116diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
82117index 30e764a..c3b6a9d 100644
82118--- a/net/netfilter/ipvs/ip_vs_conn.c
82119+++ b/net/netfilter/ipvs/ip_vs_conn.c
82120@@ -554,7 +554,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
82121 /* Increase the refcnt counter of the dest */
82122 atomic_inc(&dest->refcnt);
82123
82124- conn_flags = atomic_read(&dest->conn_flags);
82125+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
82126 if (cp->protocol != IPPROTO_UDP)
82127 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
82128 flags = cp->flags;
82129@@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
82130 atomic_set(&cp->refcnt, 1);
82131
82132 atomic_set(&cp->n_control, 0);
82133- atomic_set(&cp->in_pkts, 0);
82134+ atomic_set_unchecked(&cp->in_pkts, 0);
82135
82136 atomic_inc(&ipvs->conn_count);
82137 if (flags & IP_VS_CONN_F_NO_CPORT)
82138@@ -1180,7 +1180,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
82139
82140 /* Don't drop the entry if its number of incoming packets is not
82141 located in [0, 8] */
82142- i = atomic_read(&cp->in_pkts);
82143+ i = atomic_read_unchecked(&cp->in_pkts);
82144 if (i > 8 || i < 0) return 0;
82145
82146 if (!todrop_rate[i]) return 0;
82147diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
82148index 47edf5a..235b07d 100644
82149--- a/net/netfilter/ipvs/ip_vs_core.c
82150+++ b/net/netfilter/ipvs/ip_vs_core.c
82151@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
82152 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
82153 /* do not touch skb anymore */
82154
82155- atomic_inc(&cp->in_pkts);
82156+ atomic_inc_unchecked(&cp->in_pkts);
82157 ip_vs_conn_put(cp);
82158 return ret;
82159 }
82160@@ -1691,7 +1691,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
82161 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
82162 pkts = sysctl_sync_threshold(ipvs);
82163 else
82164- pkts = atomic_add_return(1, &cp->in_pkts);
82165+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
82166
82167 if (ipvs->sync_state & IP_VS_STATE_MASTER)
82168 ip_vs_sync_conn(net, cp, pkts);
82169diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
82170index ec664cb..cd576ab 100644
82171--- a/net/netfilter/ipvs/ip_vs_ctl.c
82172+++ b/net/netfilter/ipvs/ip_vs_ctl.c
82173@@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
82174 ip_vs_rs_hash(ipvs, dest);
82175 write_unlock_bh(&ipvs->rs_lock);
82176 }
82177- atomic_set(&dest->conn_flags, conn_flags);
82178+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
82179
82180 /* bind the service */
82181 if (!dest->svc) {
82182@@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
82183 " %-7s %-6d %-10d %-10d\n",
82184 &dest->addr.in6,
82185 ntohs(dest->port),
82186- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
82187+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
82188 atomic_read(&dest->weight),
82189 atomic_read(&dest->activeconns),
82190 atomic_read(&dest->inactconns));
82191@@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
82192 "%-7s %-6d %-10d %-10d\n",
82193 ntohl(dest->addr.ip),
82194 ntohs(dest->port),
82195- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
82196+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
82197 atomic_read(&dest->weight),
82198 atomic_read(&dest->activeconns),
82199 atomic_read(&dest->inactconns));
82200@@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
82201
82202 entry.addr = dest->addr.ip;
82203 entry.port = dest->port;
82204- entry.conn_flags = atomic_read(&dest->conn_flags);
82205+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
82206 entry.weight = atomic_read(&dest->weight);
82207 entry.u_threshold = dest->u_threshold;
82208 entry.l_threshold = dest->l_threshold;
82209@@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
82210 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
82211 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
82212 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
82213- (atomic_read(&dest->conn_flags) &
82214+ (atomic_read_unchecked(&dest->conn_flags) &
82215 IP_VS_CONN_F_FWD_MASK)) ||
82216 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
82217 atomic_read(&dest->weight)) ||
82218diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
82219index 44fd10c..2a163b3 100644
82220--- a/net/netfilter/ipvs/ip_vs_sync.c
82221+++ b/net/netfilter/ipvs/ip_vs_sync.c
82222@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
82223 cp = cp->control;
82224 if (cp) {
82225 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
82226- pkts = atomic_add_return(1, &cp->in_pkts);
82227+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
82228 else
82229 pkts = sysctl_sync_threshold(ipvs);
82230 ip_vs_sync_conn(net, cp->control, pkts);
82231@@ -758,7 +758,7 @@ control:
82232 if (!cp)
82233 return;
82234 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
82235- pkts = atomic_add_return(1, &cp->in_pkts);
82236+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
82237 else
82238 pkts = sysctl_sync_threshold(ipvs);
82239 goto sloop;
82240@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
82241
82242 if (opt)
82243 memcpy(&cp->in_seq, opt, sizeof(*opt));
82244- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
82245+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
82246 cp->state = state;
82247 cp->old_state = cp->state;
82248 /*
82249diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
82250index ee6b7a9..f9a89f6 100644
82251--- a/net/netfilter/ipvs/ip_vs_xmit.c
82252+++ b/net/netfilter/ipvs/ip_vs_xmit.c
82253@@ -1210,7 +1210,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
82254 else
82255 rc = NF_ACCEPT;
82256 /* do not touch skb anymore */
82257- atomic_inc(&cp->in_pkts);
82258+ atomic_inc_unchecked(&cp->in_pkts);
82259 goto out;
82260 }
82261
82262@@ -1332,7 +1332,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
82263 else
82264 rc = NF_ACCEPT;
82265 /* do not touch skb anymore */
82266- atomic_inc(&cp->in_pkts);
82267+ atomic_inc_unchecked(&cp->in_pkts);
82268 goto out;
82269 }
82270
82271diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
82272index e4a0c4f..c263f28 100644
82273--- a/net/netfilter/nf_conntrack_core.c
82274+++ b/net/netfilter/nf_conntrack_core.c
82275@@ -1529,6 +1529,10 @@ err_extend:
82276 #define DYING_NULLS_VAL ((1<<30)+1)
82277 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
82278
82279+#ifdef CONFIG_GRKERNSEC_HIDESYM
82280+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
82281+#endif
82282+
82283 static int nf_conntrack_init_net(struct net *net)
82284 {
82285 int ret;
82286@@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
82287 goto err_stat;
82288 }
82289
82290+#ifdef CONFIG_GRKERNSEC_HIDESYM
82291+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
82292+#else
82293 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
82294+#endif
82295 if (!net->ct.slabname) {
82296 ret = -ENOMEM;
82297 goto err_slabname;
82298diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
82299index 92fd8ec..3f6ea4b 100644
82300--- a/net/netfilter/nfnetlink_log.c
82301+++ b/net/netfilter/nfnetlink_log.c
82302@@ -72,7 +72,7 @@ struct nfulnl_instance {
82303 };
82304
82305 static DEFINE_SPINLOCK(instances_lock);
82306-static atomic_t global_seq;
82307+static atomic_unchecked_t global_seq;
82308
82309 #define INSTANCE_BUCKETS 16
82310 static struct hlist_head instance_table[INSTANCE_BUCKETS];
82311@@ -537,7 +537,7 @@ __build_packet_message(struct nfulnl_instance *inst,
82312 /* global sequence number */
82313 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
82314 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
82315- htonl(atomic_inc_return(&global_seq))))
82316+ htonl(atomic_inc_return_unchecked(&global_seq))))
82317 goto nla_put_failure;
82318
82319 if (data_len) {
82320diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
82321new file mode 100644
82322index 0000000..c566332
82323--- /dev/null
82324+++ b/net/netfilter/xt_gradm.c
82325@@ -0,0 +1,51 @@
82326+/*
82327+ * gradm match for netfilter
82328