]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.4.4-201206231147.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.4.4-201206231147.patch
CommitLineData
c2c87ce0
PK
1diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2index b4a898f..a0e01d0 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,9 +51,11 @@
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@@ -69,6 +74,7 @@ Image
38 Module.markers
39 Module.symvers
40 PENDING
41+PERF*
42 SCCS
43 System.map*
44 TAGS
45@@ -80,6 +86,7 @@ aic7*seq.h*
46 aicasm
47 aicdb.h*
48 altivec*.c
49+ashldi3.S
50 asm-offsets.h
51 asm_offsets.h
52 autoconf.h*
53@@ -92,19 +99,24 @@ bounds.h
54 bsetup
55 btfixupprep
56 build
57+builtin-policy.h
58 bvmlinux
59 bzImage*
60 capability_names.h
61 capflags.c
62 classlist.h*
63+clut_vga16.c
64+common-cmds.h
65 comp*.log
66 compile.h*
67 conf
68 config
69 config-*
70 config_data.h*
71+config.c
72 config.mak
73 config.mak.autogen
74+config.tmp
75 conmakehash
76 consolemap_deftbl.c*
77 cpustr.h
78@@ -115,9 +127,11 @@ devlist.h*
79 dnotify_test
80 docproc
81 dslm
82+dtc-lexer.lex.c
83 elf2ecoff
84 elfconfig.h*
85 evergreen_reg_safe.h
86+exception_policy.conf
87 fixdep
88 flask.h
89 fore200e_mkfirm
90@@ -125,12 +139,15 @@ fore200e_pca_fw.c*
91 gconf
92 gconf.glade.h
93 gen-devlist
94+gen-kdb_cmds.c
95 gen_crc32table
96 gen_init_cpio
97 generated
98 genheaders
99 genksyms
100 *_gray256.c
101+hash
102+hid-example
103 hpet_example
104 hugepage-mmap
105 hugepage-shm
106@@ -145,7 +162,7 @@ int32.c
107 int4.c
108 int8.c
109 kallsyms
110-kconfig
111+kern_constants.h
112 keywords.c
113 ksym.c*
114 ksym.h*
115@@ -153,7 +170,7 @@ kxgettext
116 lkc_defs.h
117 lex.c
118 lex.*.c
119-linux
120+lib1funcs.S
121 logo_*.c
122 logo_*_clut224.c
123 logo_*_mono.c
124@@ -164,14 +181,15 @@ machtypes.h
125 map
126 map_hugetlb
127 maui_boot.h
128-media
129 mconf
130+mdp
131 miboot*
132 mk_elfconfig
133 mkboot
134 mkbugboot
135 mkcpustr
136 mkdep
137+mkpiggy
138 mkprep
139 mkregtable
140 mktables
141@@ -188,6 +206,7 @@ oui.c*
142 page-types
143 parse.c
144 parse.h
145+parse-events*
146 patches*
147 pca200e.bin
148 pca200e_ecd.bin2
149@@ -197,6 +216,7 @@ perf-archive
150 piggyback
151 piggy.gzip
152 piggy.S
153+pmu-*
154 pnmtologo
155 ppc_defs.h*
156 pss_boot.h
157@@ -207,6 +227,7 @@ r300_reg_safe.h
158 r420_reg_safe.h
159 r600_reg_safe.h
160 recordmcount
161+regdb.c
162 relocs
163 rlim_names.h
164 rn50_reg_safe.h
165@@ -216,7 +237,9 @@ series
166 setup
167 setup.bin
168 setup.elf
169+size_overflow_hash.h
170 sImage
171+slabinfo
172 sm_tbl*
173 split-include
174 syscalltab.h
175@@ -227,6 +250,7 @@ tftpboot.img
176 timeconst.h
177 times.h*
178 trix_boot.h
179+user_constants.h
180 utsrelease.h*
181 vdso-syms.lds
182 vdso.lds
183@@ -238,13 +262,17 @@ vdso32.lds
184 vdso32.so.dbg
185 vdso64.lds
186 vdso64.so.dbg
187+vdsox32.lds
188+vdsox32-syms.lds
189 version.h*
190 vmImage
191 vmlinux
192 vmlinux-*
193 vmlinux.aout
194 vmlinux.bin.all
195+vmlinux.bin.bz2
196 vmlinux.lds
197+vmlinux.relocs
198 vmlinuz
199 voffset.h
200 vsyscall.lds
201@@ -252,9 +280,11 @@ vsyscall_32.lds
202 wanxlfw.inc
203 uImage
204 unifdef
205+utsrelease.h
206 wakeup.bin
207 wakeup.elf
208 wakeup.lds
209 zImage*
210 zconf.hash.c
211+zconf.lex.c
212 zoffset.h
213diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
214index c1601e5..08557ce 100644
215--- a/Documentation/kernel-parameters.txt
216+++ b/Documentation/kernel-parameters.txt
217@@ -2021,6 +2021,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
218 the specified number of seconds. This is to be used if
219 your oopses keep scrolling off the screen.
220
221+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
222+ virtualization environments that don't cope well with the
223+ expand down segment used by UDEREF on X86-32 or the frequent
224+ page table updates on X86-64.
225+
226+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
227+
228 pcbit= [HW,ISDN]
229
230 pcd. [PARIDE]
231diff --git a/Makefile b/Makefile
232index 058320d..817f7ad 100644
233--- a/Makefile
234+++ b/Makefile
235@@ -245,8 +245,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
236
237 HOSTCC = gcc
238 HOSTCXX = g++
239-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
240-HOSTCXXFLAGS = -O2
241+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
242+HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
243+HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
244
245 # Decide whether to build built-in, modular, or both.
246 # Normally, just do built-in.
247@@ -407,8 +408,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exc
248 # Rules shared between *config targets and build targets
249
250 # Basic helpers built in scripts/
251-PHONY += scripts_basic
252-scripts_basic:
253+PHONY += scripts_basic gcc-plugins
254+scripts_basic: gcc-plugins
255 $(Q)$(MAKE) $(build)=scripts/basic
256 $(Q)rm -f .tmp_quiet_recordmcount
257
258@@ -564,6 +565,56 @@ else
259 KBUILD_CFLAGS += -O2
260 endif
261
262+ifndef DISABLE_PAX_PLUGINS
263+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
264+ifneq ($(PLUGINCC),)
265+ifndef DISABLE_PAX_CONSTIFY_PLUGIN
266+ifndef CONFIG_UML
267+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
268+endif
269+endif
270+ifdef CONFIG_PAX_MEMORY_STACKLEAK
271+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
272+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
273+endif
274+ifdef CONFIG_KALLOCSTAT_PLUGIN
275+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
276+endif
277+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
278+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
279+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
280+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
281+endif
282+ifdef CONFIG_CHECKER_PLUGIN
283+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
284+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
285+endif
286+endif
287+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
288+ifdef CONFIG_PAX_SIZE_OVERFLOW
289+SIZE_OVERFLOW_PLUGIN := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
290+endif
291+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
292+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS) $(SIZE_OVERFLOW_PLUGIN)
293+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
294+export PLUGINCC CONSTIFY_PLUGIN STACKLEAK_PLUGIN KERNEXEC_PLUGIN CHECKER_PLUGIN SIZE_OVERFLOW_PLUGIN
295+ifeq ($(KBUILD_EXTMOD),)
296+gcc-plugins:
297+ $(Q)$(MAKE) $(build)=tools/gcc
298+else
299+gcc-plugins: ;
300+endif
301+else
302+gcc-plugins:
303+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
304+ $(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.))
305+else
306+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
307+endif
308+ $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
309+endif
310+endif
311+
312 include $(srctree)/arch/$(SRCARCH)/Makefile
313
314 ifneq ($(CONFIG_FRAME_WARN),0)
315@@ -708,7 +759,7 @@ export mod_strip_cmd
316
317
318 ifeq ($(KBUILD_EXTMOD),)
319-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
320+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
321
322 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
323 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
324@@ -932,6 +983,8 @@ vmlinux.o: $(modpost-init) $(vmlinux-main) FORCE
325
326 # The actual objects are generated when descending,
327 # make sure no implicit rule kicks in
328+$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
329+$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
330 $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
331
332 # Handle descending into subdirectories listed in $(vmlinux-dirs)
333@@ -941,7 +994,7 @@ $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
334 # Error messages still appears in the original language
335
336 PHONY += $(vmlinux-dirs)
337-$(vmlinux-dirs): prepare scripts
338+$(vmlinux-dirs): gcc-plugins prepare scripts
339 $(Q)$(MAKE) $(build)=$@
340
341 # Store (new) KERNELRELASE string in include/config/kernel.release
342@@ -985,6 +1038,7 @@ prepare0: archprepare FORCE
343 $(Q)$(MAKE) $(build)=.
344
345 # All the preparing..
346+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
347 prepare: prepare0
348
349 # Generate some files
350@@ -1092,6 +1146,8 @@ all: modules
351 # using awk while concatenating to the final file.
352
353 PHONY += modules
354+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
355+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
356 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
357 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
358 @$(kecho) ' Building modules, stage 2.';
359@@ -1107,7 +1163,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
360
361 # Target to prepare building external modules
362 PHONY += modules_prepare
363-modules_prepare: prepare scripts
364+modules_prepare: gcc-plugins prepare scripts
365
366 # Target to install modules
367 PHONY += modules_install
368@@ -1166,7 +1222,7 @@ CLEAN_FILES += vmlinux System.map \
369 MRPROPER_DIRS += include/config usr/include include/generated \
370 arch/*/include/generated
371 MRPROPER_FILES += .config .config.old .version .old_version \
372- include/linux/version.h \
373+ include/linux/version.h tools/gcc/size_overflow_hash.h\
374 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
375
376 # clean - Delete most, but leave enough to build external modules
377@@ -1204,6 +1260,7 @@ distclean: mrproper
378 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
379 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
380 -o -name '.*.rej' \
381+ -o -name '.*.rej' -o -name '*.so' \
382 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
383 -type f -print | xargs rm -f
384
385@@ -1364,6 +1421,8 @@ PHONY += $(module-dirs) modules
386 $(module-dirs): crmodverdir $(objtree)/Module.symvers
387 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
388
389+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
390+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
391 modules: $(module-dirs)
392 @$(kecho) ' Building modules, stage 2.';
393 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
394@@ -1490,17 +1549,21 @@ else
395 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
396 endif
397
398-%.s: %.c prepare scripts FORCE
399+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
400+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
401+%.s: %.c gcc-plugins prepare scripts FORCE
402 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
403 %.i: %.c prepare scripts FORCE
404 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
405-%.o: %.c prepare scripts FORCE
406+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
407+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
408+%.o: %.c gcc-plugins prepare scripts FORCE
409 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
410 %.lst: %.c prepare scripts FORCE
411 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
412-%.s: %.S prepare scripts FORCE
413+%.s: %.S gcc-plugins prepare scripts FORCE
414 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
415-%.o: %.S prepare scripts FORCE
416+%.o: %.S gcc-plugins prepare scripts FORCE
417 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
418 %.symtypes: %.c prepare scripts FORCE
419 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
420@@ -1510,11 +1573,15 @@ endif
421 $(cmd_crmodverdir)
422 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
423 $(build)=$(build-dir)
424-%/: prepare scripts FORCE
425+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
426+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
427+%/: gcc-plugins prepare scripts FORCE
428 $(cmd_crmodverdir)
429 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
430 $(build)=$(build-dir)
431-%.ko: prepare scripts FORCE
432+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
433+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
434+%.ko: gcc-plugins prepare scripts FORCE
435 $(cmd_crmodverdir)
436 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
437 $(build)=$(build-dir) $(@:.ko=.o)
438diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
439index 3bb7ffe..347a54c 100644
440--- a/arch/alpha/include/asm/atomic.h
441+++ b/arch/alpha/include/asm/atomic.h
442@@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
443 #define atomic_dec(v) atomic_sub(1,(v))
444 #define atomic64_dec(v) atomic64_sub(1,(v))
445
446+#define atomic64_read_unchecked(v) atomic64_read(v)
447+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
448+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
449+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
450+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
451+#define atomic64_inc_unchecked(v) atomic64_inc(v)
452+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
453+#define atomic64_dec_unchecked(v) atomic64_dec(v)
454+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
455+
456 #define smp_mb__before_atomic_dec() smp_mb()
457 #define smp_mb__after_atomic_dec() smp_mb()
458 #define smp_mb__before_atomic_inc() smp_mb()
459diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
460index ad368a9..fbe0f25 100644
461--- a/arch/alpha/include/asm/cache.h
462+++ b/arch/alpha/include/asm/cache.h
463@@ -4,19 +4,19 @@
464 #ifndef __ARCH_ALPHA_CACHE_H
465 #define __ARCH_ALPHA_CACHE_H
466
467+#include <linux/const.h>
468
469 /* Bytes per L1 (data) cache line. */
470 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
471-# define L1_CACHE_BYTES 64
472 # define L1_CACHE_SHIFT 6
473 #else
474 /* Both EV4 and EV5 are write-through, read-allocate,
475 direct-mapped, physical.
476 */
477-# define L1_CACHE_BYTES 32
478 # define L1_CACHE_SHIFT 5
479 #endif
480
481+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
482 #define SMP_CACHE_BYTES L1_CACHE_BYTES
483
484 #endif
485diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
486index 968d999..d36b2df 100644
487--- a/arch/alpha/include/asm/elf.h
488+++ b/arch/alpha/include/asm/elf.h
489@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
490
491 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
492
493+#ifdef CONFIG_PAX_ASLR
494+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
495+
496+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
497+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
498+#endif
499+
500 /* $0 is set by ld.so to a pointer to a function which might be
501 registered using atexit. This provides a mean for the dynamic
502 linker to call DT_FINI functions for shared libraries that have
503diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
504index bc2a0da..8ad11ee 100644
505--- a/arch/alpha/include/asm/pgalloc.h
506+++ b/arch/alpha/include/asm/pgalloc.h
507@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
508 pgd_set(pgd, pmd);
509 }
510
511+static inline void
512+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
513+{
514+ pgd_populate(mm, pgd, pmd);
515+}
516+
517 extern pgd_t *pgd_alloc(struct mm_struct *mm);
518
519 static inline void
520diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
521index 81a4342..348b927 100644
522--- a/arch/alpha/include/asm/pgtable.h
523+++ b/arch/alpha/include/asm/pgtable.h
524@@ -102,6 +102,17 @@ struct vm_area_struct;
525 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
526 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
527 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
528+
529+#ifdef CONFIG_PAX_PAGEEXEC
530+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
531+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
532+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
533+#else
534+# define PAGE_SHARED_NOEXEC PAGE_SHARED
535+# define PAGE_COPY_NOEXEC PAGE_COPY
536+# define PAGE_READONLY_NOEXEC PAGE_READONLY
537+#endif
538+
539 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
540
541 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
542diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
543index 2fd00b7..cfd5069 100644
544--- a/arch/alpha/kernel/module.c
545+++ b/arch/alpha/kernel/module.c
546@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
547
548 /* The small sections were sorted to the end of the segment.
549 The following should definitely cover them. */
550- gp = (u64)me->module_core + me->core_size - 0x8000;
551+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
552 got = sechdrs[me->arch.gotsecindex].sh_addr;
553
554 for (i = 0; i < n; i++) {
555diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
556index 49ee319..9ee7d14 100644
557--- a/arch/alpha/kernel/osf_sys.c
558+++ b/arch/alpha/kernel/osf_sys.c
559@@ -1146,7 +1146,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
560 /* At this point: (!vma || addr < vma->vm_end). */
561 if (limit - len < addr)
562 return -ENOMEM;
563- if (!vma || addr + len <= vma->vm_start)
564+ if (check_heap_stack_gap(vma, addr, len))
565 return addr;
566 addr = vma->vm_end;
567 vma = vma->vm_next;
568@@ -1182,6 +1182,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
569 merely specific addresses, but regions of memory -- perhaps
570 this feature should be incorporated into all ports? */
571
572+#ifdef CONFIG_PAX_RANDMMAP
573+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
574+#endif
575+
576 if (addr) {
577 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
578 if (addr != (unsigned long) -ENOMEM)
579@@ -1189,8 +1193,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
580 }
581
582 /* Next, try allocating at TASK_UNMAPPED_BASE. */
583- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
584- len, limit);
585+ addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
586+
587 if (addr != (unsigned long) -ENOMEM)
588 return addr;
589
590diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
591index 5eecab1..609abc0 100644
592--- a/arch/alpha/mm/fault.c
593+++ b/arch/alpha/mm/fault.c
594@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
595 __reload_thread(pcb);
596 }
597
598+#ifdef CONFIG_PAX_PAGEEXEC
599+/*
600+ * PaX: decide what to do with offenders (regs->pc = fault address)
601+ *
602+ * returns 1 when task should be killed
603+ * 2 when patched PLT trampoline was detected
604+ * 3 when unpatched PLT trampoline was detected
605+ */
606+static int pax_handle_fetch_fault(struct pt_regs *regs)
607+{
608+
609+#ifdef CONFIG_PAX_EMUPLT
610+ int err;
611+
612+ do { /* PaX: patched PLT emulation #1 */
613+ unsigned int ldah, ldq, jmp;
614+
615+ err = get_user(ldah, (unsigned int *)regs->pc);
616+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
617+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
618+
619+ if (err)
620+ break;
621+
622+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
623+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
624+ jmp == 0x6BFB0000U)
625+ {
626+ unsigned long r27, addr;
627+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
628+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
629+
630+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
631+ err = get_user(r27, (unsigned long *)addr);
632+ if (err)
633+ break;
634+
635+ regs->r27 = r27;
636+ regs->pc = r27;
637+ return 2;
638+ }
639+ } while (0);
640+
641+ do { /* PaX: patched PLT emulation #2 */
642+ unsigned int ldah, lda, br;
643+
644+ err = get_user(ldah, (unsigned int *)regs->pc);
645+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
646+ err |= get_user(br, (unsigned int *)(regs->pc+8));
647+
648+ if (err)
649+ break;
650+
651+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
652+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
653+ (br & 0xFFE00000U) == 0xC3E00000U)
654+ {
655+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
656+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
657+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
658+
659+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
660+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
661+ return 2;
662+ }
663+ } while (0);
664+
665+ do { /* PaX: unpatched PLT emulation */
666+ unsigned int br;
667+
668+ err = get_user(br, (unsigned int *)regs->pc);
669+
670+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
671+ unsigned int br2, ldq, nop, jmp;
672+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
673+
674+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
675+ err = get_user(br2, (unsigned int *)addr);
676+ err |= get_user(ldq, (unsigned int *)(addr+4));
677+ err |= get_user(nop, (unsigned int *)(addr+8));
678+ err |= get_user(jmp, (unsigned int *)(addr+12));
679+ err |= get_user(resolver, (unsigned long *)(addr+16));
680+
681+ if (err)
682+ break;
683+
684+ if (br2 == 0xC3600000U &&
685+ ldq == 0xA77B000CU &&
686+ nop == 0x47FF041FU &&
687+ jmp == 0x6B7B0000U)
688+ {
689+ regs->r28 = regs->pc+4;
690+ regs->r27 = addr+16;
691+ regs->pc = resolver;
692+ return 3;
693+ }
694+ }
695+ } while (0);
696+#endif
697+
698+ return 1;
699+}
700+
701+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
702+{
703+ unsigned long i;
704+
705+ printk(KERN_ERR "PAX: bytes at PC: ");
706+ for (i = 0; i < 5; i++) {
707+ unsigned int c;
708+ if (get_user(c, (unsigned int *)pc+i))
709+ printk(KERN_CONT "???????? ");
710+ else
711+ printk(KERN_CONT "%08x ", c);
712+ }
713+ printk("\n");
714+}
715+#endif
716
717 /*
718 * This routine handles page faults. It determines the address,
719@@ -130,8 +248,29 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
720 good_area:
721 si_code = SEGV_ACCERR;
722 if (cause < 0) {
723- if (!(vma->vm_flags & VM_EXEC))
724+ if (!(vma->vm_flags & VM_EXEC)) {
725+
726+#ifdef CONFIG_PAX_PAGEEXEC
727+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
728+ goto bad_area;
729+
730+ up_read(&mm->mmap_sem);
731+ switch (pax_handle_fetch_fault(regs)) {
732+
733+#ifdef CONFIG_PAX_EMUPLT
734+ case 2:
735+ case 3:
736+ return;
737+#endif
738+
739+ }
740+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
741+ do_group_exit(SIGKILL);
742+#else
743 goto bad_area;
744+#endif
745+
746+ }
747 } else if (!cause) {
748 /* Allow reads even for write-only mappings */
749 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
750diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
751index 68374ba..cff7196 100644
752--- a/arch/arm/include/asm/atomic.h
753+++ b/arch/arm/include/asm/atomic.h
754@@ -17,17 +17,35 @@
755 #include <asm/barrier.h>
756 #include <asm/cmpxchg.h>
757
758+#ifdef CONFIG_GENERIC_ATOMIC64
759+#include <asm-generic/atomic64.h>
760+#endif
761+
762 #define ATOMIC_INIT(i) { (i) }
763
764 #ifdef __KERNEL__
765
766+#define _ASM_EXTABLE(from, to) \
767+" .pushsection __ex_table,\"a\"\n"\
768+" .align 3\n" \
769+" .long " #from ", " #to"\n" \
770+" .popsection"
771+
772 /*
773 * On ARM, ordinary assignment (str instruction) doesn't clear the local
774 * strex/ldrex monitor on some implementations. The reason we can use it for
775 * atomic_set() is the clrex or dummy strex done on every exception return.
776 */
777 #define atomic_read(v) (*(volatile int *)&(v)->counter)
778+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
779+{
780+ return v->counter;
781+}
782 #define atomic_set(v,i) (((v)->counter) = (i))
783+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
784+{
785+ v->counter = i;
786+}
787
788 #if __LINUX_ARM_ARCH__ >= 6
789
790@@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
791 int result;
792
793 __asm__ __volatile__("@ atomic_add\n"
794+"1: ldrex %1, [%3]\n"
795+" adds %0, %1, %4\n"
796+
797+#ifdef CONFIG_PAX_REFCOUNT
798+" bvc 3f\n"
799+"2: bkpt 0xf103\n"
800+"3:\n"
801+#endif
802+
803+" strex %1, %0, [%3]\n"
804+" teq %1, #0\n"
805+" bne 1b"
806+
807+#ifdef CONFIG_PAX_REFCOUNT
808+"\n4:\n"
809+ _ASM_EXTABLE(2b, 4b)
810+#endif
811+
812+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
813+ : "r" (&v->counter), "Ir" (i)
814+ : "cc");
815+}
816+
817+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
818+{
819+ unsigned long tmp;
820+ int result;
821+
822+ __asm__ __volatile__("@ atomic_add_unchecked\n"
823 "1: ldrex %0, [%3]\n"
824 " add %0, %0, %4\n"
825 " strex %1, %0, [%3]\n"
826@@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
827 smp_mb();
828
829 __asm__ __volatile__("@ atomic_add_return\n"
830+"1: ldrex %1, [%3]\n"
831+" adds %0, %1, %4\n"
832+
833+#ifdef CONFIG_PAX_REFCOUNT
834+" bvc 3f\n"
835+" mov %0, %1\n"
836+"2: bkpt 0xf103\n"
837+"3:\n"
838+#endif
839+
840+" strex %1, %0, [%3]\n"
841+" teq %1, #0\n"
842+" bne 1b"
843+
844+#ifdef CONFIG_PAX_REFCOUNT
845+"\n4:\n"
846+ _ASM_EXTABLE(2b, 4b)
847+#endif
848+
849+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
850+ : "r" (&v->counter), "Ir" (i)
851+ : "cc");
852+
853+ smp_mb();
854+
855+ return result;
856+}
857+
858+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
859+{
860+ unsigned long tmp;
861+ int result;
862+
863+ smp_mb();
864+
865+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
866 "1: ldrex %0, [%3]\n"
867 " add %0, %0, %4\n"
868 " strex %1, %0, [%3]\n"
869@@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
870 int result;
871
872 __asm__ __volatile__("@ atomic_sub\n"
873+"1: ldrex %1, [%3]\n"
874+" subs %0, %1, %4\n"
875+
876+#ifdef CONFIG_PAX_REFCOUNT
877+" bvc 3f\n"
878+"2: bkpt 0xf103\n"
879+"3:\n"
880+#endif
881+
882+" strex %1, %0, [%3]\n"
883+" teq %1, #0\n"
884+" bne 1b"
885+
886+#ifdef CONFIG_PAX_REFCOUNT
887+"\n4:\n"
888+ _ASM_EXTABLE(2b, 4b)
889+#endif
890+
891+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
892+ : "r" (&v->counter), "Ir" (i)
893+ : "cc");
894+}
895+
896+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
897+{
898+ unsigned long tmp;
899+ int result;
900+
901+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
902 "1: ldrex %0, [%3]\n"
903 " sub %0, %0, %4\n"
904 " strex %1, %0, [%3]\n"
905@@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
906 smp_mb();
907
908 __asm__ __volatile__("@ atomic_sub_return\n"
909-"1: ldrex %0, [%3]\n"
910-" sub %0, %0, %4\n"
911+"1: ldrex %1, [%3]\n"
912+" sub %0, %1, %4\n"
913+
914+#ifdef CONFIG_PAX_REFCOUNT
915+" bvc 3f\n"
916+" mov %0, %1\n"
917+"2: bkpt 0xf103\n"
918+"3:\n"
919+#endif
920+
921 " strex %1, %0, [%3]\n"
922 " teq %1, #0\n"
923 " bne 1b"
924+
925+#ifdef CONFIG_PAX_REFCOUNT
926+"\n4:\n"
927+ _ASM_EXTABLE(2b, 4b)
928+#endif
929+
930 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
931 : "r" (&v->counter), "Ir" (i)
932 : "cc");
933@@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
934 return oldval;
935 }
936
937+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
938+{
939+ unsigned long oldval, res;
940+
941+ smp_mb();
942+
943+ do {
944+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
945+ "ldrex %1, [%3]\n"
946+ "mov %0, #0\n"
947+ "teq %1, %4\n"
948+ "strexeq %0, %5, [%3]\n"
949+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
950+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
951+ : "cc");
952+ } while (res);
953+
954+ smp_mb();
955+
956+ return oldval;
957+}
958+
959 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
960 {
961 unsigned long tmp, tmp2;
962@@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
963
964 return val;
965 }
966+
967+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
968+{
969+ return atomic_add_return(i, v);
970+}
971+
972 #define atomic_add(i, v) (void) atomic_add_return(i, v)
973+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
974+{
975+ (void) atomic_add_return(i, v);
976+}
977
978 static inline int atomic_sub_return(int i, atomic_t *v)
979 {
980@@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
981 return val;
982 }
983 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
984+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
985+{
986+ (void) atomic_sub_return(i, v);
987+}
988
989 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
990 {
991@@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
992 return ret;
993 }
994
995+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
996+{
997+ return atomic_cmpxchg(v, old, new);
998+}
999+
1000 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1001 {
1002 unsigned long flags;
1003@@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1004 #endif /* __LINUX_ARM_ARCH__ */
1005
1006 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1007+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1008+{
1009+ return xchg(&v->counter, new);
1010+}
1011
1012 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1013 {
1014@@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1015 }
1016
1017 #define atomic_inc(v) atomic_add(1, v)
1018+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1019+{
1020+ atomic_add_unchecked(1, v);
1021+}
1022 #define atomic_dec(v) atomic_sub(1, v)
1023+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1024+{
1025+ atomic_sub_unchecked(1, v);
1026+}
1027
1028 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1029+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1030+{
1031+ return atomic_add_return_unchecked(1, v) == 0;
1032+}
1033 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1034 #define atomic_inc_return(v) (atomic_add_return(1, v))
1035+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1036+{
1037+ return atomic_add_return_unchecked(1, v);
1038+}
1039 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1040 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1041
1042@@ -241,6 +428,14 @@ typedef struct {
1043 u64 __aligned(8) counter;
1044 } atomic64_t;
1045
1046+#ifdef CONFIG_PAX_REFCOUNT
1047+typedef struct {
1048+ u64 __aligned(8) counter;
1049+} atomic64_unchecked_t;
1050+#else
1051+typedef atomic64_t atomic64_unchecked_t;
1052+#endif
1053+
1054 #define ATOMIC64_INIT(i) { (i) }
1055
1056 static inline u64 atomic64_read(atomic64_t *v)
1057@@ -256,6 +451,19 @@ static inline u64 atomic64_read(atomic64_t *v)
1058 return result;
1059 }
1060
1061+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1062+{
1063+ u64 result;
1064+
1065+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1066+" ldrexd %0, %H0, [%1]"
1067+ : "=&r" (result)
1068+ : "r" (&v->counter), "Qo" (v->counter)
1069+ );
1070+
1071+ return result;
1072+}
1073+
1074 static inline void atomic64_set(atomic64_t *v, u64 i)
1075 {
1076 u64 tmp;
1077@@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1078 : "cc");
1079 }
1080
1081+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1082+{
1083+ u64 tmp;
1084+
1085+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1086+"1: ldrexd %0, %H0, [%2]\n"
1087+" strexd %0, %3, %H3, [%2]\n"
1088+" teq %0, #0\n"
1089+" bne 1b"
1090+ : "=&r" (tmp), "=Qo" (v->counter)
1091+ : "r" (&v->counter), "r" (i)
1092+ : "cc");
1093+}
1094+
1095 static inline void atomic64_add(u64 i, atomic64_t *v)
1096 {
1097 u64 result;
1098@@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1099 __asm__ __volatile__("@ atomic64_add\n"
1100 "1: ldrexd %0, %H0, [%3]\n"
1101 " adds %0, %0, %4\n"
1102+" adcs %H0, %H0, %H4\n"
1103+
1104+#ifdef CONFIG_PAX_REFCOUNT
1105+" bvc 3f\n"
1106+"2: bkpt 0xf103\n"
1107+"3:\n"
1108+#endif
1109+
1110+" strexd %1, %0, %H0, [%3]\n"
1111+" teq %1, #0\n"
1112+" bne 1b"
1113+
1114+#ifdef CONFIG_PAX_REFCOUNT
1115+"\n4:\n"
1116+ _ASM_EXTABLE(2b, 4b)
1117+#endif
1118+
1119+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1120+ : "r" (&v->counter), "r" (i)
1121+ : "cc");
1122+}
1123+
1124+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1125+{
1126+ u64 result;
1127+ unsigned long tmp;
1128+
1129+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1130+"1: ldrexd %0, %H0, [%3]\n"
1131+" adds %0, %0, %4\n"
1132 " adc %H0, %H0, %H4\n"
1133 " strexd %1, %0, %H0, [%3]\n"
1134 " teq %1, #0\n"
1135@@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1136
1137 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1138 {
1139- u64 result;
1140- unsigned long tmp;
1141+ u64 result, tmp;
1142
1143 smp_mb();
1144
1145 __asm__ __volatile__("@ atomic64_add_return\n"
1146+"1: ldrexd %1, %H1, [%3]\n"
1147+" adds %0, %1, %4\n"
1148+" adcs %H0, %H1, %H4\n"
1149+
1150+#ifdef CONFIG_PAX_REFCOUNT
1151+" bvc 3f\n"
1152+" mov %0, %1\n"
1153+" mov %H0, %H1\n"
1154+"2: bkpt 0xf103\n"
1155+"3:\n"
1156+#endif
1157+
1158+" strexd %1, %0, %H0, [%3]\n"
1159+" teq %1, #0\n"
1160+" bne 1b"
1161+
1162+#ifdef CONFIG_PAX_REFCOUNT
1163+"\n4:\n"
1164+ _ASM_EXTABLE(2b, 4b)
1165+#endif
1166+
1167+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1168+ : "r" (&v->counter), "r" (i)
1169+ : "cc");
1170+
1171+ smp_mb();
1172+
1173+ return result;
1174+}
1175+
1176+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1177+{
1178+ u64 result;
1179+ unsigned long tmp;
1180+
1181+ smp_mb();
1182+
1183+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1184 "1: ldrexd %0, %H0, [%3]\n"
1185 " adds %0, %0, %4\n"
1186 " adc %H0, %H0, %H4\n"
1187@@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1188 __asm__ __volatile__("@ atomic64_sub\n"
1189 "1: ldrexd %0, %H0, [%3]\n"
1190 " subs %0, %0, %4\n"
1191+" sbcs %H0, %H0, %H4\n"
1192+
1193+#ifdef CONFIG_PAX_REFCOUNT
1194+" bvc 3f\n"
1195+"2: bkpt 0xf103\n"
1196+"3:\n"
1197+#endif
1198+
1199+" strexd %1, %0, %H0, [%3]\n"
1200+" teq %1, #0\n"
1201+" bne 1b"
1202+
1203+#ifdef CONFIG_PAX_REFCOUNT
1204+"\n4:\n"
1205+ _ASM_EXTABLE(2b, 4b)
1206+#endif
1207+
1208+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1209+ : "r" (&v->counter), "r" (i)
1210+ : "cc");
1211+}
1212+
1213+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1214+{
1215+ u64 result;
1216+ unsigned long tmp;
1217+
1218+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1219+"1: ldrexd %0, %H0, [%3]\n"
1220+" subs %0, %0, %4\n"
1221 " sbc %H0, %H0, %H4\n"
1222 " strexd %1, %0, %H0, [%3]\n"
1223 " teq %1, #0\n"
1224@@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1225
1226 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1227 {
1228- u64 result;
1229- unsigned long tmp;
1230+ u64 result, tmp;
1231
1232 smp_mb();
1233
1234 __asm__ __volatile__("@ atomic64_sub_return\n"
1235-"1: ldrexd %0, %H0, [%3]\n"
1236-" subs %0, %0, %4\n"
1237-" sbc %H0, %H0, %H4\n"
1238+"1: ldrexd %1, %H1, [%3]\n"
1239+" subs %0, %1, %4\n"
1240+" sbc %H0, %H1, %H4\n"
1241+
1242+#ifdef CONFIG_PAX_REFCOUNT
1243+" bvc 3f\n"
1244+" mov %0, %1\n"
1245+" mov %H0, %H1\n"
1246+"2: bkpt 0xf103\n"
1247+"3:\n"
1248+#endif
1249+
1250 " strexd %1, %0, %H0, [%3]\n"
1251 " teq %1, #0\n"
1252 " bne 1b"
1253+
1254+#ifdef CONFIG_PAX_REFCOUNT
1255+"\n4:\n"
1256+ _ASM_EXTABLE(2b, 4b)
1257+#endif
1258+
1259 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1260 : "r" (&v->counter), "r" (i)
1261 : "cc");
1262@@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1263 return oldval;
1264 }
1265
1266+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1267+{
1268+ u64 oldval;
1269+ unsigned long res;
1270+
1271+ smp_mb();
1272+
1273+ do {
1274+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1275+ "ldrexd %1, %H1, [%3]\n"
1276+ "mov %0, #0\n"
1277+ "teq %1, %4\n"
1278+ "teqeq %H1, %H4\n"
1279+ "strexdeq %0, %5, %H5, [%3]"
1280+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1281+ : "r" (&ptr->counter), "r" (old), "r" (new)
1282+ : "cc");
1283+ } while (res);
1284+
1285+ smp_mb();
1286+
1287+ return oldval;
1288+}
1289+
1290 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1291 {
1292 u64 result;
1293@@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1294
1295 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1296 {
1297- u64 result;
1298- unsigned long tmp;
1299+ u64 result, tmp;
1300
1301 smp_mb();
1302
1303 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1304-"1: ldrexd %0, %H0, [%3]\n"
1305-" subs %0, %0, #1\n"
1306-" sbc %H0, %H0, #0\n"
1307+"1: ldrexd %1, %H1, [%3]\n"
1308+" subs %0, %1, #1\n"
1309+" sbc %H0, %H1, #0\n"
1310+
1311+#ifdef CONFIG_PAX_REFCOUNT
1312+" bvc 3f\n"
1313+" mov %0, %1\n"
1314+" mov %H0, %H1\n"
1315+"2: bkpt 0xf103\n"
1316+"3:\n"
1317+#endif
1318+
1319 " teq %H0, #0\n"
1320-" bmi 2f\n"
1321+" bmi 4f\n"
1322 " strexd %1, %0, %H0, [%3]\n"
1323 " teq %1, #0\n"
1324 " bne 1b\n"
1325-"2:"
1326+"4:\n"
1327+
1328+#ifdef CONFIG_PAX_REFCOUNT
1329+ _ASM_EXTABLE(2b, 4b)
1330+#endif
1331+
1332 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1333 : "r" (&v->counter)
1334 : "cc");
1335@@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1336 " teq %0, %5\n"
1337 " teqeq %H0, %H5\n"
1338 " moveq %1, #0\n"
1339-" beq 2f\n"
1340+" beq 4f\n"
1341 " adds %0, %0, %6\n"
1342 " adc %H0, %H0, %H6\n"
1343+
1344+#ifdef CONFIG_PAX_REFCOUNT
1345+" bvc 3f\n"
1346+"2: bkpt 0xf103\n"
1347+"3:\n"
1348+#endif
1349+
1350 " strexd %2, %0, %H0, [%4]\n"
1351 " teq %2, #0\n"
1352 " bne 1b\n"
1353-"2:"
1354+"4:\n"
1355+
1356+#ifdef CONFIG_PAX_REFCOUNT
1357+ _ASM_EXTABLE(2b, 4b)
1358+#endif
1359+
1360 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1361 : "r" (&v->counter), "r" (u), "r" (a)
1362 : "cc");
1363@@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1364
1365 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1366 #define atomic64_inc(v) atomic64_add(1LL, (v))
1367+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1368 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1369+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1370 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1371 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1372 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1373+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1374 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1375 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1376 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1377diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1378index 75fe66b..2255c86 100644
1379--- a/arch/arm/include/asm/cache.h
1380+++ b/arch/arm/include/asm/cache.h
1381@@ -4,8 +4,10 @@
1382 #ifndef __ASMARM_CACHE_H
1383 #define __ASMARM_CACHE_H
1384
1385+#include <linux/const.h>
1386+
1387 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1388-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1389+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1390
1391 /*
1392 * Memory returned by kmalloc() may be used for DMA, so we must make
1393diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1394index 1252a26..9dc17b5 100644
1395--- a/arch/arm/include/asm/cacheflush.h
1396+++ b/arch/arm/include/asm/cacheflush.h
1397@@ -108,7 +108,7 @@ struct cpu_cache_fns {
1398 void (*dma_unmap_area)(const void *, size_t, int);
1399
1400 void (*dma_flush_range)(const void *, const void *);
1401-};
1402+} __no_const;
1403
1404 /*
1405 * Select the calling method
1406diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1407index d41d7cb..9bea5e0 100644
1408--- a/arch/arm/include/asm/cmpxchg.h
1409+++ b/arch/arm/include/asm/cmpxchg.h
1410@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1411
1412 #define xchg(ptr,x) \
1413 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1414+#define xchg_unchecked(ptr,x) \
1415+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1416
1417 #include <asm-generic/cmpxchg-local.h>
1418
1419diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1420index 38050b1..9d90e8b 100644
1421--- a/arch/arm/include/asm/elf.h
1422+++ b/arch/arm/include/asm/elf.h
1423@@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1424 the loader. We need to make sure that it is out of the way of the program
1425 that it will "exec", and that there is sufficient room for the brk. */
1426
1427-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1428+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1429+
1430+#ifdef CONFIG_PAX_ASLR
1431+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1432+
1433+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1434+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1435+#endif
1436
1437 /* When the program starts, a1 contains a pointer to a function to be
1438 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1439@@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1440 extern void elf_set_personality(const struct elf32_hdr *);
1441 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1442
1443-struct mm_struct;
1444-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1445-#define arch_randomize_brk arch_randomize_brk
1446-
1447 #endif
1448diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1449index e51b1e8..32a3113 100644
1450--- a/arch/arm/include/asm/kmap_types.h
1451+++ b/arch/arm/include/asm/kmap_types.h
1452@@ -21,6 +21,7 @@ enum km_type {
1453 KM_L1_CACHE,
1454 KM_L2_CACHE,
1455 KM_KDB,
1456+ KM_CLEARPAGE,
1457 KM_TYPE_NR
1458 };
1459
1460diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1461index 53426c6..c7baff3 100644
1462--- a/arch/arm/include/asm/outercache.h
1463+++ b/arch/arm/include/asm/outercache.h
1464@@ -35,7 +35,7 @@ struct outer_cache_fns {
1465 #endif
1466 void (*set_debug)(unsigned long);
1467 void (*resume)(void);
1468-};
1469+} __no_const;
1470
1471 #ifdef CONFIG_OUTER_CACHE
1472
1473diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1474index 5838361..da6e813 100644
1475--- a/arch/arm/include/asm/page.h
1476+++ b/arch/arm/include/asm/page.h
1477@@ -123,7 +123,7 @@ struct cpu_user_fns {
1478 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1479 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1480 unsigned long vaddr, struct vm_area_struct *vma);
1481-};
1482+} __no_const;
1483
1484 #ifdef MULTI_USER
1485 extern struct cpu_user_fns cpu_user;
1486diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1487index 943504f..bf8d667 100644
1488--- a/arch/arm/include/asm/pgalloc.h
1489+++ b/arch/arm/include/asm/pgalloc.h
1490@@ -43,6 +43,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1491 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1492 }
1493
1494+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1495+{
1496+ pud_populate(mm, pud, pmd);
1497+}
1498+
1499 #else /* !CONFIG_ARM_LPAE */
1500
1501 /*
1502@@ -51,6 +56,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1503 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1504 #define pmd_free(mm, pmd) do { } while (0)
1505 #define pud_populate(mm,pmd,pte) BUG()
1506+#define pud_populate_kernel(mm,pmd,pte) BUG()
1507
1508 #endif /* CONFIG_ARM_LPAE */
1509
1510diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1511index 0f04d84..2be5648 100644
1512--- a/arch/arm/include/asm/thread_info.h
1513+++ b/arch/arm/include/asm/thread_info.h
1514@@ -148,6 +148,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1515 #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
1516 #define TIF_SYSCALL_TRACE 8
1517 #define TIF_SYSCALL_AUDIT 9
1518+
1519+/* within 8 bits of TIF_SYSCALL_TRACE
1520+ to meet flexible second operand requirements
1521+*/
1522+#define TIF_GRSEC_SETXID 10
1523+
1524 #define TIF_POLLING_NRFLAG 16
1525 #define TIF_USING_IWMMXT 17
1526 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1527@@ -163,9 +169,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1528 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1529 #define _TIF_RESTORE_SIGMASK (1 << TIF_RESTORE_SIGMASK)
1530 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1531+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1532
1533 /* Checks for any syscall work in entry-common.S */
1534-#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
1535+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
1536+ _TIF_GRSEC_SETXID)
1537
1538 /*
1539 * Change these and you break ASM code in entry-common.S
1540diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1541index 71f6536..602f279 100644
1542--- a/arch/arm/include/asm/uaccess.h
1543+++ b/arch/arm/include/asm/uaccess.h
1544@@ -22,6 +22,8 @@
1545 #define VERIFY_READ 0
1546 #define VERIFY_WRITE 1
1547
1548+extern void check_object_size(const void *ptr, unsigned long n, bool to);
1549+
1550 /*
1551 * The exception table consists of pairs of addresses: the first is the
1552 * address of an instruction that is allowed to fault, and the second is
1553@@ -387,8 +389,23 @@ do { \
1554
1555
1556 #ifdef CONFIG_MMU
1557-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1558-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1559+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1560+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1561+
1562+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1563+{
1564+ if (!__builtin_constant_p(n))
1565+ check_object_size(to, n, false);
1566+ return ___copy_from_user(to, from, n);
1567+}
1568+
1569+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1570+{
1571+ if (!__builtin_constant_p(n))
1572+ check_object_size(from, n, true);
1573+ return ___copy_to_user(to, from, n);
1574+}
1575+
1576 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1577 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1578 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1579@@ -403,6 +420,9 @@ extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
1580
1581 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1582 {
1583+ if ((long)n < 0)
1584+ return n;
1585+
1586 if (access_ok(VERIFY_READ, from, n))
1587 n = __copy_from_user(to, from, n);
1588 else /* security hole - plug it */
1589@@ -412,6 +432,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1590
1591 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1592 {
1593+ if ((long)n < 0)
1594+ return n;
1595+
1596 if (access_ok(VERIFY_WRITE, to, n))
1597 n = __copy_to_user(to, from, n);
1598 return n;
1599diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1600index b57c75e..ed2d6b2 100644
1601--- a/arch/arm/kernel/armksyms.c
1602+++ b/arch/arm/kernel/armksyms.c
1603@@ -94,8 +94,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
1604 #ifdef CONFIG_MMU
1605 EXPORT_SYMBOL(copy_page);
1606
1607-EXPORT_SYMBOL(__copy_from_user);
1608-EXPORT_SYMBOL(__copy_to_user);
1609+EXPORT_SYMBOL(___copy_from_user);
1610+EXPORT_SYMBOL(___copy_to_user);
1611 EXPORT_SYMBOL(__clear_user);
1612
1613 EXPORT_SYMBOL(__get_user_1);
1614diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1615index 2b7b017..c380fa2 100644
1616--- a/arch/arm/kernel/process.c
1617+++ b/arch/arm/kernel/process.c
1618@@ -28,7 +28,6 @@
1619 #include <linux/tick.h>
1620 #include <linux/utsname.h>
1621 #include <linux/uaccess.h>
1622-#include <linux/random.h>
1623 #include <linux/hw_breakpoint.h>
1624 #include <linux/cpuidle.h>
1625
1626@@ -275,9 +274,10 @@ void machine_power_off(void)
1627 machine_shutdown();
1628 if (pm_power_off)
1629 pm_power_off();
1630+ BUG();
1631 }
1632
1633-void machine_restart(char *cmd)
1634+__noreturn void machine_restart(char *cmd)
1635 {
1636 machine_shutdown();
1637
1638@@ -519,12 +519,6 @@ unsigned long get_wchan(struct task_struct *p)
1639 return 0;
1640 }
1641
1642-unsigned long arch_randomize_brk(struct mm_struct *mm)
1643-{
1644- unsigned long range_end = mm->brk + 0x02000000;
1645- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1646-}
1647-
1648 #ifdef CONFIG_MMU
1649 /*
1650 * The vectors page is always readable from user space for the
1651diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
1652index 9650c14..ae30cdd 100644
1653--- a/arch/arm/kernel/ptrace.c
1654+++ b/arch/arm/kernel/ptrace.c
1655@@ -906,10 +906,19 @@ long arch_ptrace(struct task_struct *child, long request,
1656 return ret;
1657 }
1658
1659+#ifdef CONFIG_GRKERNSEC_SETXID
1660+extern void gr_delayed_cred_worker(void);
1661+#endif
1662+
1663 asmlinkage int syscall_trace(int why, struct pt_regs *regs, int scno)
1664 {
1665 unsigned long ip;
1666
1667+#ifdef CONFIG_GRKERNSEC_SETXID
1668+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
1669+ gr_delayed_cred_worker();
1670+#endif
1671+
1672 if (why)
1673 audit_syscall_exit(regs);
1674 else
1675diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1676index ebfac78..cbea9c0 100644
1677--- a/arch/arm/kernel/setup.c
1678+++ b/arch/arm/kernel/setup.c
1679@@ -111,13 +111,13 @@ struct processor processor __read_mostly;
1680 struct cpu_tlb_fns cpu_tlb __read_mostly;
1681 #endif
1682 #ifdef MULTI_USER
1683-struct cpu_user_fns cpu_user __read_mostly;
1684+struct cpu_user_fns cpu_user __read_only;
1685 #endif
1686 #ifdef MULTI_CACHE
1687-struct cpu_cache_fns cpu_cache __read_mostly;
1688+struct cpu_cache_fns cpu_cache __read_only;
1689 #endif
1690 #ifdef CONFIG_OUTER_CACHE
1691-struct outer_cache_fns outer_cache __read_mostly;
1692+struct outer_cache_fns outer_cache __read_only;
1693 EXPORT_SYMBOL(outer_cache);
1694 #endif
1695
1696diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1697index 63d402f..db1d714 100644
1698--- a/arch/arm/kernel/traps.c
1699+++ b/arch/arm/kernel/traps.c
1700@@ -264,6 +264,8 @@ static int __die(const char *str, int err, struct thread_info *thread, struct pt
1701
1702 static DEFINE_RAW_SPINLOCK(die_lock);
1703
1704+extern void gr_handle_kernel_exploit(void);
1705+
1706 /*
1707 * This function is protected against re-entrancy.
1708 */
1709@@ -296,6 +298,9 @@ void die(const char *str, struct pt_regs *regs, int err)
1710 panic("Fatal exception in interrupt");
1711 if (panic_on_oops)
1712 panic("Fatal exception");
1713+
1714+ gr_handle_kernel_exploit();
1715+
1716 if (ret != NOTIFY_STOP)
1717 do_exit(SIGSEGV);
1718 }
1719diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1720index 66a477a..bee61d3 100644
1721--- a/arch/arm/lib/copy_from_user.S
1722+++ b/arch/arm/lib/copy_from_user.S
1723@@ -16,7 +16,7 @@
1724 /*
1725 * Prototype:
1726 *
1727- * size_t __copy_from_user(void *to, const void *from, size_t n)
1728+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
1729 *
1730 * Purpose:
1731 *
1732@@ -84,11 +84,11 @@
1733
1734 .text
1735
1736-ENTRY(__copy_from_user)
1737+ENTRY(___copy_from_user)
1738
1739 #include "copy_template.S"
1740
1741-ENDPROC(__copy_from_user)
1742+ENDPROC(___copy_from_user)
1743
1744 .pushsection .fixup,"ax"
1745 .align 0
1746diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1747index 6ee2f67..d1cce76 100644
1748--- a/arch/arm/lib/copy_page.S
1749+++ b/arch/arm/lib/copy_page.S
1750@@ -10,6 +10,7 @@
1751 * ASM optimised string functions
1752 */
1753 #include <linux/linkage.h>
1754+#include <linux/const.h>
1755 #include <asm/assembler.h>
1756 #include <asm/asm-offsets.h>
1757 #include <asm/cache.h>
1758diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1759index d066df6..df28194 100644
1760--- a/arch/arm/lib/copy_to_user.S
1761+++ b/arch/arm/lib/copy_to_user.S
1762@@ -16,7 +16,7 @@
1763 /*
1764 * Prototype:
1765 *
1766- * size_t __copy_to_user(void *to, const void *from, size_t n)
1767+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
1768 *
1769 * Purpose:
1770 *
1771@@ -88,11 +88,11 @@
1772 .text
1773
1774 ENTRY(__copy_to_user_std)
1775-WEAK(__copy_to_user)
1776+WEAK(___copy_to_user)
1777
1778 #include "copy_template.S"
1779
1780-ENDPROC(__copy_to_user)
1781+ENDPROC(___copy_to_user)
1782 ENDPROC(__copy_to_user_std)
1783
1784 .pushsection .fixup,"ax"
1785diff --git a/arch/arm/lib/uaccess.S b/arch/arm/lib/uaccess.S
1786index 5c908b1..e712687 100644
1787--- a/arch/arm/lib/uaccess.S
1788+++ b/arch/arm/lib/uaccess.S
1789@@ -20,7 +20,7 @@
1790
1791 #define PAGE_SHIFT 12
1792
1793-/* Prototype: int __copy_to_user(void *to, const char *from, size_t n)
1794+/* Prototype: int ___copy_to_user(void *to, const char *from, size_t n)
1795 * Purpose : copy a block to user memory from kernel memory
1796 * Params : to - user memory
1797 * : from - kernel memory
1798@@ -40,7 +40,7 @@ USER( TUSER( strgtb) r3, [r0], #1) @ May fault
1799 sub r2, r2, ip
1800 b .Lc2u_dest_aligned
1801
1802-ENTRY(__copy_to_user)
1803+ENTRY(___copy_to_user)
1804 stmfd sp!, {r2, r4 - r7, lr}
1805 cmp r2, #4
1806 blt .Lc2u_not_enough
1807@@ -278,14 +278,14 @@ USER( TUSER( strgeb) r3, [r0], #1) @ May fault
1808 ldrgtb r3, [r1], #0
1809 USER( TUSER( strgtb) r3, [r0], #1) @ May fault
1810 b .Lc2u_finished
1811-ENDPROC(__copy_to_user)
1812+ENDPROC(___copy_to_user)
1813
1814 .pushsection .fixup,"ax"
1815 .align 0
1816 9001: ldmfd sp!, {r0, r4 - r7, pc}
1817 .popsection
1818
1819-/* Prototype: unsigned long __copy_from_user(void *to,const void *from,unsigned long n);
1820+/* Prototype: unsigned long ___copy_from_user(void *to,const void *from,unsigned long n);
1821 * Purpose : copy a block from user memory to kernel memory
1822 * Params : to - kernel memory
1823 * : from - user memory
1824@@ -304,7 +304,7 @@ USER( TUSER( ldrgtb) r3, [r1], #1) @ May fault
1825 sub r2, r2, ip
1826 b .Lcfu_dest_aligned
1827
1828-ENTRY(__copy_from_user)
1829+ENTRY(___copy_from_user)
1830 stmfd sp!, {r0, r2, r4 - r7, lr}
1831 cmp r2, #4
1832 blt .Lcfu_not_enough
1833@@ -544,7 +544,7 @@ USER( TUSER( ldrgeb) r3, [r1], #1) @ May fault
1834 USER( TUSER( ldrgtb) r3, [r1], #1) @ May fault
1835 strgtb r3, [r0], #1
1836 b .Lcfu_finished
1837-ENDPROC(__copy_from_user)
1838+ENDPROC(___copy_from_user)
1839
1840 .pushsection .fixup,"ax"
1841 .align 0
1842diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1843index 025f742..8432b08 100644
1844--- a/arch/arm/lib/uaccess_with_memcpy.c
1845+++ b/arch/arm/lib/uaccess_with_memcpy.c
1846@@ -104,7 +104,7 @@ out:
1847 }
1848
1849 unsigned long
1850-__copy_to_user(void __user *to, const void *from, unsigned long n)
1851+___copy_to_user(void __user *to, const void *from, unsigned long n)
1852 {
1853 /*
1854 * This test is stubbed out of the main function above to keep
1855diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1856index 518091c..eae9a76 100644
1857--- a/arch/arm/mach-omap2/board-n8x0.c
1858+++ b/arch/arm/mach-omap2/board-n8x0.c
1859@@ -596,7 +596,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1860 }
1861 #endif
1862
1863-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1864+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1865 .late_init = n8x0_menelaus_late_init,
1866 };
1867
1868diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1869index 5bb4835..4760f68 100644
1870--- a/arch/arm/mm/fault.c
1871+++ b/arch/arm/mm/fault.c
1872@@ -174,6 +174,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1873 }
1874 #endif
1875
1876+#ifdef CONFIG_PAX_PAGEEXEC
1877+ if (fsr & FSR_LNX_PF) {
1878+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1879+ do_group_exit(SIGKILL);
1880+ }
1881+#endif
1882+
1883 tsk->thread.address = addr;
1884 tsk->thread.error_code = fsr;
1885 tsk->thread.trap_no = 14;
1886@@ -397,6 +404,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1887 }
1888 #endif /* CONFIG_MMU */
1889
1890+#ifdef CONFIG_PAX_PAGEEXEC
1891+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1892+{
1893+ long i;
1894+
1895+ printk(KERN_ERR "PAX: bytes at PC: ");
1896+ for (i = 0; i < 20; i++) {
1897+ unsigned char c;
1898+ if (get_user(c, (__force unsigned char __user *)pc+i))
1899+ printk(KERN_CONT "?? ");
1900+ else
1901+ printk(KERN_CONT "%02x ", c);
1902+ }
1903+ printk("\n");
1904+
1905+ printk(KERN_ERR "PAX: bytes at SP-4: ");
1906+ for (i = -1; i < 20; i++) {
1907+ unsigned long c;
1908+ if (get_user(c, (__force unsigned long __user *)sp+i))
1909+ printk(KERN_CONT "???????? ");
1910+ else
1911+ printk(KERN_CONT "%08lx ", c);
1912+ }
1913+ printk("\n");
1914+}
1915+#endif
1916+
1917 /*
1918 * First Level Translation Fault Handler
1919 *
1920@@ -577,6 +611,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1921 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1922 struct siginfo info;
1923
1924+#ifdef CONFIG_PAX_REFCOUNT
1925+ if (fsr_fs(ifsr) == 2) {
1926+ unsigned int bkpt;
1927+
1928+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1929+ current->thread.error_code = ifsr;
1930+ current->thread.trap_no = 0;
1931+ pax_report_refcount_overflow(regs);
1932+ fixup_exception(regs);
1933+ return;
1934+ }
1935+ }
1936+#endif
1937+
1938 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1939 return;
1940
1941diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1942index ce8cb19..3ec539d 100644
1943--- a/arch/arm/mm/mmap.c
1944+++ b/arch/arm/mm/mmap.c
1945@@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1946 if (len > TASK_SIZE)
1947 return -ENOMEM;
1948
1949+#ifdef CONFIG_PAX_RANDMMAP
1950+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1951+#endif
1952+
1953 if (addr) {
1954 if (do_align)
1955 addr = COLOUR_ALIGN(addr, pgoff);
1956@@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1957 addr = PAGE_ALIGN(addr);
1958
1959 vma = find_vma(mm, addr);
1960- if (TASK_SIZE - len >= addr &&
1961- (!vma || addr + len <= vma->vm_start))
1962+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1963 return addr;
1964 }
1965 if (len > mm->cached_hole_size) {
1966- start_addr = addr = mm->free_area_cache;
1967+ start_addr = addr = mm->free_area_cache;
1968 } else {
1969- start_addr = addr = mm->mmap_base;
1970- mm->cached_hole_size = 0;
1971+ start_addr = addr = mm->mmap_base;
1972+ mm->cached_hole_size = 0;
1973 }
1974
1975 full_search:
1976@@ -124,14 +127,14 @@ full_search:
1977 * Start a new search - just in case we missed
1978 * some holes.
1979 */
1980- if (start_addr != TASK_UNMAPPED_BASE) {
1981- start_addr = addr = TASK_UNMAPPED_BASE;
1982+ if (start_addr != mm->mmap_base) {
1983+ start_addr = addr = mm->mmap_base;
1984 mm->cached_hole_size = 0;
1985 goto full_search;
1986 }
1987 return -ENOMEM;
1988 }
1989- if (!vma || addr + len <= vma->vm_start) {
1990+ if (check_heap_stack_gap(vma, addr, len)) {
1991 /*
1992 * Remember the place where we stopped the search:
1993 */
1994@@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
1995
1996 if (mmap_is_legacy()) {
1997 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
1998+
1999+#ifdef CONFIG_PAX_RANDMMAP
2000+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2001+ mm->mmap_base += mm->delta_mmap;
2002+#endif
2003+
2004 mm->get_unmapped_area = arch_get_unmapped_area;
2005 mm->unmap_area = arch_unmap_area;
2006 } else {
2007 mm->mmap_base = mmap_base(random_factor);
2008+
2009+#ifdef CONFIG_PAX_RANDMMAP
2010+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2011+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2012+#endif
2013+
2014 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2015 mm->unmap_area = arch_unmap_area_topdown;
2016 }
2017diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2018index fd556f7..af2e7d2 100644
2019--- a/arch/arm/plat-orion/include/plat/addr-map.h
2020+++ b/arch/arm/plat-orion/include/plat/addr-map.h
2021@@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2022 value in bridge_virt_base */
2023 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2024 const int win);
2025-};
2026+} __no_const;
2027
2028 /*
2029 * Information needed to setup one address mapping.
2030diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2031index 71a6827..e7fbc23 100644
2032--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2033+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2034@@ -43,7 +43,7 @@ struct samsung_dma_ops {
2035 int (*started)(unsigned ch);
2036 int (*flush)(unsigned ch);
2037 int (*stop)(unsigned ch);
2038-};
2039+} __no_const;
2040
2041 extern void *samsung_dmadev_get_ops(void);
2042 extern void *s3c_dma_get_ops(void);
2043diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
2044index 5f28cae..3d23723 100644
2045--- a/arch/arm/plat-samsung/include/plat/ehci.h
2046+++ b/arch/arm/plat-samsung/include/plat/ehci.h
2047@@ -14,7 +14,7 @@
2048 struct s5p_ehci_platdata {
2049 int (*phy_init)(struct platform_device *pdev, int type);
2050 int (*phy_exit)(struct platform_device *pdev, int type);
2051-};
2052+} __no_const;
2053
2054 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
2055
2056diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2057index c3a58a1..78fbf54 100644
2058--- a/arch/avr32/include/asm/cache.h
2059+++ b/arch/avr32/include/asm/cache.h
2060@@ -1,8 +1,10 @@
2061 #ifndef __ASM_AVR32_CACHE_H
2062 #define __ASM_AVR32_CACHE_H
2063
2064+#include <linux/const.h>
2065+
2066 #define L1_CACHE_SHIFT 5
2067-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2068+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2069
2070 /*
2071 * Memory returned by kmalloc() may be used for DMA, so we must make
2072diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2073index 3b3159b..425ea94 100644
2074--- a/arch/avr32/include/asm/elf.h
2075+++ b/arch/avr32/include/asm/elf.h
2076@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2077 the loader. We need to make sure that it is out of the way of the program
2078 that it will "exec", and that there is sufficient room for the brk. */
2079
2080-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2081+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2082
2083+#ifdef CONFIG_PAX_ASLR
2084+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2085+
2086+#define PAX_DELTA_MMAP_LEN 15
2087+#define PAX_DELTA_STACK_LEN 15
2088+#endif
2089
2090 /* This yields a mask that user programs can use to figure out what
2091 instruction set this CPU supports. This could be done in user space,
2092diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2093index b7f5c68..556135c 100644
2094--- a/arch/avr32/include/asm/kmap_types.h
2095+++ b/arch/avr32/include/asm/kmap_types.h
2096@@ -22,7 +22,8 @@ D(10) KM_IRQ0,
2097 D(11) KM_IRQ1,
2098 D(12) KM_SOFTIRQ0,
2099 D(13) KM_SOFTIRQ1,
2100-D(14) KM_TYPE_NR
2101+D(14) KM_CLEARPAGE,
2102+D(15) KM_TYPE_NR
2103 };
2104
2105 #undef D
2106diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2107index f7040a1..db9f300 100644
2108--- a/arch/avr32/mm/fault.c
2109+++ b/arch/avr32/mm/fault.c
2110@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2111
2112 int exception_trace = 1;
2113
2114+#ifdef CONFIG_PAX_PAGEEXEC
2115+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2116+{
2117+ unsigned long i;
2118+
2119+ printk(KERN_ERR "PAX: bytes at PC: ");
2120+ for (i = 0; i < 20; i++) {
2121+ unsigned char c;
2122+ if (get_user(c, (unsigned char *)pc+i))
2123+ printk(KERN_CONT "???????? ");
2124+ else
2125+ printk(KERN_CONT "%02x ", c);
2126+ }
2127+ printk("\n");
2128+}
2129+#endif
2130+
2131 /*
2132 * This routine handles page faults. It determines the address and the
2133 * problem, and then passes it off to one of the appropriate routines.
2134@@ -156,6 +173,16 @@ bad_area:
2135 up_read(&mm->mmap_sem);
2136
2137 if (user_mode(regs)) {
2138+
2139+#ifdef CONFIG_PAX_PAGEEXEC
2140+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2141+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2142+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2143+ do_group_exit(SIGKILL);
2144+ }
2145+ }
2146+#endif
2147+
2148 if (exception_trace && printk_ratelimit())
2149 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2150 "sp %08lx ecr %lu\n",
2151diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2152index 568885a..f8008df 100644
2153--- a/arch/blackfin/include/asm/cache.h
2154+++ b/arch/blackfin/include/asm/cache.h
2155@@ -7,6 +7,7 @@
2156 #ifndef __ARCH_BLACKFIN_CACHE_H
2157 #define __ARCH_BLACKFIN_CACHE_H
2158
2159+#include <linux/const.h>
2160 #include <linux/linkage.h> /* for asmlinkage */
2161
2162 /*
2163@@ -14,7 +15,7 @@
2164 * Blackfin loads 32 bytes for cache
2165 */
2166 #define L1_CACHE_SHIFT 5
2167-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2168+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2169 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2170
2171 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2172diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2173index aea2718..3639a60 100644
2174--- a/arch/cris/include/arch-v10/arch/cache.h
2175+++ b/arch/cris/include/arch-v10/arch/cache.h
2176@@ -1,8 +1,9 @@
2177 #ifndef _ASM_ARCH_CACHE_H
2178 #define _ASM_ARCH_CACHE_H
2179
2180+#include <linux/const.h>
2181 /* Etrax 100LX have 32-byte cache-lines. */
2182-#define L1_CACHE_BYTES 32
2183 #define L1_CACHE_SHIFT 5
2184+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2185
2186 #endif /* _ASM_ARCH_CACHE_H */
2187diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2188index 1de779f..336fad3 100644
2189--- a/arch/cris/include/arch-v32/arch/cache.h
2190+++ b/arch/cris/include/arch-v32/arch/cache.h
2191@@ -1,11 +1,12 @@
2192 #ifndef _ASM_CRIS_ARCH_CACHE_H
2193 #define _ASM_CRIS_ARCH_CACHE_H
2194
2195+#include <linux/const.h>
2196 #include <arch/hwregs/dma.h>
2197
2198 /* A cache-line is 32 bytes. */
2199-#define L1_CACHE_BYTES 32
2200 #define L1_CACHE_SHIFT 5
2201+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2202
2203 #define __read_mostly __attribute__((__section__(".data.read_mostly")))
2204
2205diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2206index b86329d..6709906 100644
2207--- a/arch/frv/include/asm/atomic.h
2208+++ b/arch/frv/include/asm/atomic.h
2209@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
2210 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2211 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2212
2213+#define atomic64_read_unchecked(v) atomic64_read(v)
2214+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2215+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2216+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2217+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2218+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2219+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2220+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2221+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2222+
2223 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2224 {
2225 int c, old;
2226diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2227index 2797163..c2a401d 100644
2228--- a/arch/frv/include/asm/cache.h
2229+++ b/arch/frv/include/asm/cache.h
2230@@ -12,10 +12,11 @@
2231 #ifndef __ASM_CACHE_H
2232 #define __ASM_CACHE_H
2233
2234+#include <linux/const.h>
2235
2236 /* bytes per L1 cache line */
2237 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2238-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2239+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2240
2241 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2242 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2243diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2244index f8e16b2..c73ff79 100644
2245--- a/arch/frv/include/asm/kmap_types.h
2246+++ b/arch/frv/include/asm/kmap_types.h
2247@@ -23,6 +23,7 @@ enum km_type {
2248 KM_IRQ1,
2249 KM_SOFTIRQ0,
2250 KM_SOFTIRQ1,
2251+ KM_CLEARPAGE,
2252 KM_TYPE_NR
2253 };
2254
2255diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2256index 385fd30..6c3d97e 100644
2257--- a/arch/frv/mm/elf-fdpic.c
2258+++ b/arch/frv/mm/elf-fdpic.c
2259@@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2260 if (addr) {
2261 addr = PAGE_ALIGN(addr);
2262 vma = find_vma(current->mm, addr);
2263- if (TASK_SIZE - len >= addr &&
2264- (!vma || addr + len <= vma->vm_start))
2265+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2266 goto success;
2267 }
2268
2269@@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2270 for (; vma; vma = vma->vm_next) {
2271 if (addr > limit)
2272 break;
2273- if (addr + len <= vma->vm_start)
2274+ if (check_heap_stack_gap(vma, addr, len))
2275 goto success;
2276 addr = vma->vm_end;
2277 }
2278@@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2279 for (; vma; vma = vma->vm_next) {
2280 if (addr > limit)
2281 break;
2282- if (addr + len <= vma->vm_start)
2283+ if (check_heap_stack_gap(vma, addr, len))
2284 goto success;
2285 addr = vma->vm_end;
2286 }
2287diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2288index c635028..6d9445a 100644
2289--- a/arch/h8300/include/asm/cache.h
2290+++ b/arch/h8300/include/asm/cache.h
2291@@ -1,8 +1,10 @@
2292 #ifndef __ARCH_H8300_CACHE_H
2293 #define __ARCH_H8300_CACHE_H
2294
2295+#include <linux/const.h>
2296+
2297 /* bytes per L1 cache line */
2298-#define L1_CACHE_BYTES 4
2299+#define L1_CACHE_BYTES _AC(4,UL)
2300
2301 /* m68k-elf-gcc 2.95.2 doesn't like these */
2302
2303diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2304index 0f01de2..d37d309 100644
2305--- a/arch/hexagon/include/asm/cache.h
2306+++ b/arch/hexagon/include/asm/cache.h
2307@@ -21,9 +21,11 @@
2308 #ifndef __ASM_CACHE_H
2309 #define __ASM_CACHE_H
2310
2311+#include <linux/const.h>
2312+
2313 /* Bytes per L1 cache line */
2314-#define L1_CACHE_SHIFT (5)
2315-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2316+#define L1_CACHE_SHIFT 5
2317+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2318
2319 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2320 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2321diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2322index 7d91166..88ab87e 100644
2323--- a/arch/ia64/include/asm/atomic.h
2324+++ b/arch/ia64/include/asm/atomic.h
2325@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2326 #define atomic64_inc(v) atomic64_add(1, (v))
2327 #define atomic64_dec(v) atomic64_sub(1, (v))
2328
2329+#define atomic64_read_unchecked(v) atomic64_read(v)
2330+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2331+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2332+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2333+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2334+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2335+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2336+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2337+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2338+
2339 /* Atomic operations are already serializing */
2340 #define smp_mb__before_atomic_dec() barrier()
2341 #define smp_mb__after_atomic_dec() barrier()
2342diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2343index 988254a..e1ee885 100644
2344--- a/arch/ia64/include/asm/cache.h
2345+++ b/arch/ia64/include/asm/cache.h
2346@@ -1,6 +1,7 @@
2347 #ifndef _ASM_IA64_CACHE_H
2348 #define _ASM_IA64_CACHE_H
2349
2350+#include <linux/const.h>
2351
2352 /*
2353 * Copyright (C) 1998-2000 Hewlett-Packard Co
2354@@ -9,7 +10,7 @@
2355
2356 /* Bytes per L1 (data) cache line. */
2357 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2358-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2359+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2360
2361 #ifdef CONFIG_SMP
2362 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2363diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2364index b5298eb..67c6e62 100644
2365--- a/arch/ia64/include/asm/elf.h
2366+++ b/arch/ia64/include/asm/elf.h
2367@@ -42,6 +42,13 @@
2368 */
2369 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2370
2371+#ifdef CONFIG_PAX_ASLR
2372+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2373+
2374+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2375+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2376+#endif
2377+
2378 #define PT_IA_64_UNWIND 0x70000001
2379
2380 /* IA-64 relocations: */
2381diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
2382index 96a8d92..617a1cf 100644
2383--- a/arch/ia64/include/asm/pgalloc.h
2384+++ b/arch/ia64/include/asm/pgalloc.h
2385@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2386 pgd_val(*pgd_entry) = __pa(pud);
2387 }
2388
2389+static inline void
2390+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2391+{
2392+ pgd_populate(mm, pgd_entry, pud);
2393+}
2394+
2395 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
2396 {
2397 return quicklist_alloc(0, GFP_KERNEL, NULL);
2398@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2399 pud_val(*pud_entry) = __pa(pmd);
2400 }
2401
2402+static inline void
2403+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2404+{
2405+ pud_populate(mm, pud_entry, pmd);
2406+}
2407+
2408 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
2409 {
2410 return quicklist_alloc(0, GFP_KERNEL, NULL);
2411diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2412index 815810c..d60bd4c 100644
2413--- a/arch/ia64/include/asm/pgtable.h
2414+++ b/arch/ia64/include/asm/pgtable.h
2415@@ -12,7 +12,7 @@
2416 * David Mosberger-Tang <davidm@hpl.hp.com>
2417 */
2418
2419-
2420+#include <linux/const.h>
2421 #include <asm/mman.h>
2422 #include <asm/page.h>
2423 #include <asm/processor.h>
2424@@ -142,6 +142,17 @@
2425 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2426 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2427 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2428+
2429+#ifdef CONFIG_PAX_PAGEEXEC
2430+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2431+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2432+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2433+#else
2434+# define PAGE_SHARED_NOEXEC PAGE_SHARED
2435+# define PAGE_READONLY_NOEXEC PAGE_READONLY
2436+# define PAGE_COPY_NOEXEC PAGE_COPY
2437+#endif
2438+
2439 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2440 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2441 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2442diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2443index 54ff557..70c88b7 100644
2444--- a/arch/ia64/include/asm/spinlock.h
2445+++ b/arch/ia64/include/asm/spinlock.h
2446@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2447 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2448
2449 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2450- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2451+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2452 }
2453
2454 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2455diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2456index 449c8c0..432a3d2 100644
2457--- a/arch/ia64/include/asm/uaccess.h
2458+++ b/arch/ia64/include/asm/uaccess.h
2459@@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2460 const void *__cu_from = (from); \
2461 long __cu_len = (n); \
2462 \
2463- if (__access_ok(__cu_to, __cu_len, get_fs())) \
2464+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2465 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2466 __cu_len; \
2467 })
2468@@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2469 long __cu_len = (n); \
2470 \
2471 __chk_user_ptr(__cu_from); \
2472- if (__access_ok(__cu_from, __cu_len, get_fs())) \
2473+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2474 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2475 __cu_len; \
2476 })
2477diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2478index 24603be..948052d 100644
2479--- a/arch/ia64/kernel/module.c
2480+++ b/arch/ia64/kernel/module.c
2481@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2482 void
2483 module_free (struct module *mod, void *module_region)
2484 {
2485- if (mod && mod->arch.init_unw_table &&
2486- module_region == mod->module_init) {
2487+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2488 unw_remove_unwind_table(mod->arch.init_unw_table);
2489 mod->arch.init_unw_table = NULL;
2490 }
2491@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2492 }
2493
2494 static inline int
2495+in_init_rx (const struct module *mod, uint64_t addr)
2496+{
2497+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2498+}
2499+
2500+static inline int
2501+in_init_rw (const struct module *mod, uint64_t addr)
2502+{
2503+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2504+}
2505+
2506+static inline int
2507 in_init (const struct module *mod, uint64_t addr)
2508 {
2509- return addr - (uint64_t) mod->module_init < mod->init_size;
2510+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2511+}
2512+
2513+static inline int
2514+in_core_rx (const struct module *mod, uint64_t addr)
2515+{
2516+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2517+}
2518+
2519+static inline int
2520+in_core_rw (const struct module *mod, uint64_t addr)
2521+{
2522+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2523 }
2524
2525 static inline int
2526 in_core (const struct module *mod, uint64_t addr)
2527 {
2528- return addr - (uint64_t) mod->module_core < mod->core_size;
2529+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2530 }
2531
2532 static inline int
2533@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2534 break;
2535
2536 case RV_BDREL:
2537- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2538+ if (in_init_rx(mod, val))
2539+ val -= (uint64_t) mod->module_init_rx;
2540+ else if (in_init_rw(mod, val))
2541+ val -= (uint64_t) mod->module_init_rw;
2542+ else if (in_core_rx(mod, val))
2543+ val -= (uint64_t) mod->module_core_rx;
2544+ else if (in_core_rw(mod, val))
2545+ val -= (uint64_t) mod->module_core_rw;
2546 break;
2547
2548 case RV_LTV:
2549@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2550 * addresses have been selected...
2551 */
2552 uint64_t gp;
2553- if (mod->core_size > MAX_LTOFF)
2554+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2555 /*
2556 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2557 * at the end of the module.
2558 */
2559- gp = mod->core_size - MAX_LTOFF / 2;
2560+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2561 else
2562- gp = mod->core_size / 2;
2563- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2564+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2565+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2566 mod->arch.gp = gp;
2567 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2568 }
2569diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2570index 609d500..7dde2a8 100644
2571--- a/arch/ia64/kernel/sys_ia64.c
2572+++ b/arch/ia64/kernel/sys_ia64.c
2573@@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2574 if (REGION_NUMBER(addr) == RGN_HPAGE)
2575 addr = 0;
2576 #endif
2577+
2578+#ifdef CONFIG_PAX_RANDMMAP
2579+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2580+ addr = mm->free_area_cache;
2581+ else
2582+#endif
2583+
2584 if (!addr)
2585 addr = mm->free_area_cache;
2586
2587@@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2588 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2589 /* At this point: (!vma || addr < vma->vm_end). */
2590 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2591- if (start_addr != TASK_UNMAPPED_BASE) {
2592+ if (start_addr != mm->mmap_base) {
2593 /* Start a new search --- just in case we missed some holes. */
2594- addr = TASK_UNMAPPED_BASE;
2595+ addr = mm->mmap_base;
2596 goto full_search;
2597 }
2598 return -ENOMEM;
2599 }
2600- if (!vma || addr + len <= vma->vm_start) {
2601+ if (check_heap_stack_gap(vma, addr, len)) {
2602 /* Remember the address where we stopped this search: */
2603 mm->free_area_cache = addr + len;
2604 return addr;
2605diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2606index 0ccb28f..8992469 100644
2607--- a/arch/ia64/kernel/vmlinux.lds.S
2608+++ b/arch/ia64/kernel/vmlinux.lds.S
2609@@ -198,7 +198,7 @@ SECTIONS {
2610 /* Per-cpu data: */
2611 . = ALIGN(PERCPU_PAGE_SIZE);
2612 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2613- __phys_per_cpu_start = __per_cpu_load;
2614+ __phys_per_cpu_start = per_cpu_load;
2615 /*
2616 * ensure percpu data fits
2617 * into percpu page size
2618diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2619index 02d29c2..ea893df 100644
2620--- a/arch/ia64/mm/fault.c
2621+++ b/arch/ia64/mm/fault.c
2622@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
2623 return pte_present(pte);
2624 }
2625
2626+#ifdef CONFIG_PAX_PAGEEXEC
2627+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2628+{
2629+ unsigned long i;
2630+
2631+ printk(KERN_ERR "PAX: bytes at PC: ");
2632+ for (i = 0; i < 8; i++) {
2633+ unsigned int c;
2634+ if (get_user(c, (unsigned int *)pc+i))
2635+ printk(KERN_CONT "???????? ");
2636+ else
2637+ printk(KERN_CONT "%08x ", c);
2638+ }
2639+ printk("\n");
2640+}
2641+#endif
2642+
2643 void __kprobes
2644 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
2645 {
2646@@ -145,9 +162,23 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
2647 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
2648 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
2649
2650- if ((vma->vm_flags & mask) != mask)
2651+ if ((vma->vm_flags & mask) != mask) {
2652+
2653+#ifdef CONFIG_PAX_PAGEEXEC
2654+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2655+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2656+ goto bad_area;
2657+
2658+ up_read(&mm->mmap_sem);
2659+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2660+ do_group_exit(SIGKILL);
2661+ }
2662+#endif
2663+
2664 goto bad_area;
2665
2666+ }
2667+
2668 /*
2669 * If for any reason at all we couldn't handle the fault, make
2670 * sure we exit gracefully rather than endlessly redo the
2671diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2672index 5ca674b..e0e1b70 100644
2673--- a/arch/ia64/mm/hugetlbpage.c
2674+++ b/arch/ia64/mm/hugetlbpage.c
2675@@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2676 /* At this point: (!vmm || addr < vmm->vm_end). */
2677 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2678 return -ENOMEM;
2679- if (!vmm || (addr + len) <= vmm->vm_start)
2680+ if (check_heap_stack_gap(vmm, addr, len))
2681 return addr;
2682 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2683 }
2684diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2685index 0eab454..bd794f2 100644
2686--- a/arch/ia64/mm/init.c
2687+++ b/arch/ia64/mm/init.c
2688@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
2689 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2690 vma->vm_end = vma->vm_start + PAGE_SIZE;
2691 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2692+
2693+#ifdef CONFIG_PAX_PAGEEXEC
2694+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2695+ vma->vm_flags &= ~VM_EXEC;
2696+
2697+#ifdef CONFIG_PAX_MPROTECT
2698+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
2699+ vma->vm_flags &= ~VM_MAYEXEC;
2700+#endif
2701+
2702+ }
2703+#endif
2704+
2705 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2706 down_write(&current->mm->mmap_sem);
2707 if (insert_vm_struct(current->mm, vma)) {
2708diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2709index 40b3ee9..8c2c112 100644
2710--- a/arch/m32r/include/asm/cache.h
2711+++ b/arch/m32r/include/asm/cache.h
2712@@ -1,8 +1,10 @@
2713 #ifndef _ASM_M32R_CACHE_H
2714 #define _ASM_M32R_CACHE_H
2715
2716+#include <linux/const.h>
2717+
2718 /* L1 cache line size */
2719 #define L1_CACHE_SHIFT 4
2720-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2721+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2722
2723 #endif /* _ASM_M32R_CACHE_H */
2724diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2725index 82abd15..d95ae5d 100644
2726--- a/arch/m32r/lib/usercopy.c
2727+++ b/arch/m32r/lib/usercopy.c
2728@@ -14,6 +14,9 @@
2729 unsigned long
2730 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2731 {
2732+ if ((long)n < 0)
2733+ return n;
2734+
2735 prefetch(from);
2736 if (access_ok(VERIFY_WRITE, to, n))
2737 __copy_user(to,from,n);
2738@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2739 unsigned long
2740 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2741 {
2742+ if ((long)n < 0)
2743+ return n;
2744+
2745 prefetchw(to);
2746 if (access_ok(VERIFY_READ, from, n))
2747 __copy_user_zeroing(to,from,n);
2748diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2749index 0395c51..5f26031 100644
2750--- a/arch/m68k/include/asm/cache.h
2751+++ b/arch/m68k/include/asm/cache.h
2752@@ -4,9 +4,11 @@
2753 #ifndef __ARCH_M68K_CACHE_H
2754 #define __ARCH_M68K_CACHE_H
2755
2756+#include <linux/const.h>
2757+
2758 /* bytes per L1 cache line */
2759 #define L1_CACHE_SHIFT 4
2760-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2761+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2762
2763 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2764
2765diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2766index 4efe96a..60e8699 100644
2767--- a/arch/microblaze/include/asm/cache.h
2768+++ b/arch/microblaze/include/asm/cache.h
2769@@ -13,11 +13,12 @@
2770 #ifndef _ASM_MICROBLAZE_CACHE_H
2771 #define _ASM_MICROBLAZE_CACHE_H
2772
2773+#include <linux/const.h>
2774 #include <asm/registers.h>
2775
2776 #define L1_CACHE_SHIFT 5
2777 /* word-granular cache in microblaze */
2778-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2779+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2780
2781 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2782
2783diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2784index 3f4c5cb..3439c6e 100644
2785--- a/arch/mips/include/asm/atomic.h
2786+++ b/arch/mips/include/asm/atomic.h
2787@@ -21,6 +21,10 @@
2788 #include <asm/cmpxchg.h>
2789 #include <asm/war.h>
2790
2791+#ifdef CONFIG_GENERIC_ATOMIC64
2792+#include <asm-generic/atomic64.h>
2793+#endif
2794+
2795 #define ATOMIC_INIT(i) { (i) }
2796
2797 /*
2798@@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2799 */
2800 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2801
2802+#define atomic64_read_unchecked(v) atomic64_read(v)
2803+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2804+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2805+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2806+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2807+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2808+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2809+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2810+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2811+
2812 #endif /* CONFIG_64BIT */
2813
2814 /*
2815diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2816index b4db69f..8f3b093 100644
2817--- a/arch/mips/include/asm/cache.h
2818+++ b/arch/mips/include/asm/cache.h
2819@@ -9,10 +9,11 @@
2820 #ifndef _ASM_CACHE_H
2821 #define _ASM_CACHE_H
2822
2823+#include <linux/const.h>
2824 #include <kmalloc.h>
2825
2826 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2827-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2828+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2829
2830 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2831 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2832diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2833index 455c0ac..ad65fbe 100644
2834--- a/arch/mips/include/asm/elf.h
2835+++ b/arch/mips/include/asm/elf.h
2836@@ -372,13 +372,16 @@ extern const char *__elf_platform;
2837 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2838 #endif
2839
2840+#ifdef CONFIG_PAX_ASLR
2841+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2842+
2843+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2844+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2845+#endif
2846+
2847 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2848 struct linux_binprm;
2849 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2850 int uses_interp);
2851
2852-struct mm_struct;
2853-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2854-#define arch_randomize_brk arch_randomize_brk
2855-
2856 #endif /* _ASM_ELF_H */
2857diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
2858index c1f6afa..38cc6e9 100644
2859--- a/arch/mips/include/asm/exec.h
2860+++ b/arch/mips/include/asm/exec.h
2861@@ -12,6 +12,6 @@
2862 #ifndef _ASM_EXEC_H
2863 #define _ASM_EXEC_H
2864
2865-extern unsigned long arch_align_stack(unsigned long sp);
2866+#define arch_align_stack(x) ((x) & ~0xfUL)
2867
2868 #endif /* _ASM_EXEC_H */
2869diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2870index da9bd7d..91aa7ab 100644
2871--- a/arch/mips/include/asm/page.h
2872+++ b/arch/mips/include/asm/page.h
2873@@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2874 #ifdef CONFIG_CPU_MIPS32
2875 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2876 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2877- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2878+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2879 #else
2880 typedef struct { unsigned long long pte; } pte_t;
2881 #define pte_val(x) ((x).pte)
2882diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
2883index 881d18b..cea38bc 100644
2884--- a/arch/mips/include/asm/pgalloc.h
2885+++ b/arch/mips/include/asm/pgalloc.h
2886@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2887 {
2888 set_pud(pud, __pud((unsigned long)pmd));
2889 }
2890+
2891+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2892+{
2893+ pud_populate(mm, pud, pmd);
2894+}
2895 #endif
2896
2897 /*
2898diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
2899index 0d85d8e..ec71487 100644
2900--- a/arch/mips/include/asm/thread_info.h
2901+++ b/arch/mips/include/asm/thread_info.h
2902@@ -123,6 +123,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
2903 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
2904 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
2905 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
2906+/* li takes a 32bit immediate */
2907+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
2908 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
2909
2910 #ifdef CONFIG_MIPS32_O32
2911@@ -146,15 +148,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
2912 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
2913 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
2914 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
2915+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
2916+
2917+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2918
2919 /* work to do in syscall_trace_leave() */
2920-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
2921+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2922
2923 /* work to do on interrupt/exception return */
2924 #define _TIF_WORK_MASK (0x0000ffef & \
2925 ~(_TIF_SECCOMP | _TIF_SYSCALL_AUDIT))
2926 /* work to do on any return to u-space */
2927-#define _TIF_ALLWORK_MASK (0x8000ffff & ~_TIF_SECCOMP)
2928+#define _TIF_ALLWORK_MASK ((0x8000ffff & ~_TIF_SECCOMP) | _TIF_GRSEC_SETXID)
2929
2930 #endif /* __KERNEL__ */
2931
2932diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2933index 9fdd8bc..4bd7f1a 100644
2934--- a/arch/mips/kernel/binfmt_elfn32.c
2935+++ b/arch/mips/kernel/binfmt_elfn32.c
2936@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2937 #undef ELF_ET_DYN_BASE
2938 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2939
2940+#ifdef CONFIG_PAX_ASLR
2941+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2942+
2943+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2944+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2945+#endif
2946+
2947 #include <asm/processor.h>
2948 #include <linux/module.h>
2949 #include <linux/elfcore.h>
2950diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2951index ff44823..97f8906 100644
2952--- a/arch/mips/kernel/binfmt_elfo32.c
2953+++ b/arch/mips/kernel/binfmt_elfo32.c
2954@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2955 #undef ELF_ET_DYN_BASE
2956 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2957
2958+#ifdef CONFIG_PAX_ASLR
2959+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2960+
2961+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2962+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2963+#endif
2964+
2965 #include <asm/processor.h>
2966
2967 /*
2968diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2969index e9a5fd7..378809a 100644
2970--- a/arch/mips/kernel/process.c
2971+++ b/arch/mips/kernel/process.c
2972@@ -480,15 +480,3 @@ unsigned long get_wchan(struct task_struct *task)
2973 out:
2974 return pc;
2975 }
2976-
2977-/*
2978- * Don't forget that the stack pointer must be aligned on a 8 bytes
2979- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2980- */
2981-unsigned long arch_align_stack(unsigned long sp)
2982-{
2983- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2984- sp -= get_random_int() & ~PAGE_MASK;
2985-
2986- return sp & ALMASK;
2987-}
2988diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
2989index 7c24c29..e2f1981 100644
2990--- a/arch/mips/kernel/ptrace.c
2991+++ b/arch/mips/kernel/ptrace.c
2992@@ -528,6 +528,10 @@ static inline int audit_arch(void)
2993 return arch;
2994 }
2995
2996+#ifdef CONFIG_GRKERNSEC_SETXID
2997+extern void gr_delayed_cred_worker(void);
2998+#endif
2999+
3000 /*
3001 * Notification of system call entry/exit
3002 * - triggered by current->work.syscall_trace
3003@@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
3004 /* do the secure computing check first */
3005 secure_computing(regs->regs[2]);
3006
3007+#ifdef CONFIG_GRKERNSEC_SETXID
3008+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3009+ gr_delayed_cred_worker();
3010+#endif
3011+
3012 if (!(current->ptrace & PT_PTRACED))
3013 goto out;
3014
3015diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3016index a632bc1..0b77c7c 100644
3017--- a/arch/mips/kernel/scall32-o32.S
3018+++ b/arch/mips/kernel/scall32-o32.S
3019@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3020
3021 stack_done:
3022 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3023- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3024+ li t1, _TIF_SYSCALL_WORK
3025 and t0, t1
3026 bnez t0, syscall_trace_entry # -> yes
3027
3028diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3029index 3b5a5e9..e1ee86d 100644
3030--- a/arch/mips/kernel/scall64-64.S
3031+++ b/arch/mips/kernel/scall64-64.S
3032@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
3033
3034 sd a3, PT_R26(sp) # save a3 for syscall restarting
3035
3036- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3037+ li t1, _TIF_SYSCALL_WORK
3038 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3039 and t0, t1, t0
3040 bnez t0, syscall_trace_entry
3041diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
3042index 6be6f70..1859577 100644
3043--- a/arch/mips/kernel/scall64-n32.S
3044+++ b/arch/mips/kernel/scall64-n32.S
3045@@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
3046
3047 sd a3, PT_R26(sp) # save a3 for syscall restarting
3048
3049- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3050+ li t1, _TIF_SYSCALL_WORK
3051 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3052 and t0, t1, t0
3053 bnez t0, n32_syscall_trace_entry
3054diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3055index 5422855..74e63a3 100644
3056--- a/arch/mips/kernel/scall64-o32.S
3057+++ b/arch/mips/kernel/scall64-o32.S
3058@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3059 PTR 4b, bad_stack
3060 .previous
3061
3062- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3063+ li t1, _TIF_SYSCALL_WORK
3064 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3065 and t0, t1, t0
3066 bnez t0, trace_a_syscall
3067diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3068index c14f6df..537e729 100644
3069--- a/arch/mips/mm/fault.c
3070+++ b/arch/mips/mm/fault.c
3071@@ -27,6 +27,23 @@
3072 #include <asm/highmem.h> /* For VMALLOC_END */
3073 #include <linux/kdebug.h>
3074
3075+#ifdef CONFIG_PAX_PAGEEXEC
3076+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3077+{
3078+ unsigned long i;
3079+
3080+ printk(KERN_ERR "PAX: bytes at PC: ");
3081+ for (i = 0; i < 5; i++) {
3082+ unsigned int c;
3083+ if (get_user(c, (unsigned int *)pc+i))
3084+ printk(KERN_CONT "???????? ");
3085+ else
3086+ printk(KERN_CONT "%08x ", c);
3087+ }
3088+ printk("\n");
3089+}
3090+#endif
3091+
3092 /*
3093 * This routine handles page faults. It determines the address,
3094 * and the problem, and then passes it off to one of the appropriate
3095diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3096index 302d779..7d35bf8 100644
3097--- a/arch/mips/mm/mmap.c
3098+++ b/arch/mips/mm/mmap.c
3099@@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3100 do_color_align = 1;
3101
3102 /* requesting a specific address */
3103+
3104+#ifdef CONFIG_PAX_RANDMMAP
3105+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
3106+#endif
3107+
3108 if (addr) {
3109 if (do_color_align)
3110 addr = COLOUR_ALIGN(addr, pgoff);
3111@@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3112 addr = PAGE_ALIGN(addr);
3113
3114 vma = find_vma(mm, addr);
3115- if (TASK_SIZE - len >= addr &&
3116- (!vma || addr + len <= vma->vm_start))
3117+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
3118 return addr;
3119 }
3120
3121@@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3122 /* At this point: (!vma || addr < vma->vm_end). */
3123 if (TASK_SIZE - len < addr)
3124 return -ENOMEM;
3125- if (!vma || addr + len <= vma->vm_start)
3126+ if (check_heap_stack_gap(vmm, addr, len))
3127 return addr;
3128 addr = vma->vm_end;
3129 if (do_color_align)
3130@@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3131 /* make sure it can fit in the remaining address space */
3132 if (likely(addr > len)) {
3133 vma = find_vma(mm, addr - len);
3134- if (!vma || addr <= vma->vm_start) {
3135+ if (check_heap_stack_gap(vmm, addr - len, len))
3136 /* cache the address as a hint for next time */
3137 return mm->free_area_cache = addr - len;
3138 }
3139@@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3140 * return with success:
3141 */
3142 vma = find_vma(mm, addr);
3143- if (likely(!vma || addr + len <= vma->vm_start)) {
3144+ if (check_heap_stack_gap(vmm, addr, len)) {
3145 /* cache the address as a hint for next time */
3146 return mm->free_area_cache = addr;
3147 }
3148@@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3149 mm->unmap_area = arch_unmap_area_topdown;
3150 }
3151 }
3152-
3153-static inline unsigned long brk_rnd(void)
3154-{
3155- unsigned long rnd = get_random_int();
3156-
3157- rnd = rnd << PAGE_SHIFT;
3158- /* 8MB for 32bit, 256MB for 64bit */
3159- if (TASK_IS_32BIT_ADDR)
3160- rnd = rnd & 0x7ffffful;
3161- else
3162- rnd = rnd & 0xffffffful;
3163-
3164- return rnd;
3165-}
3166-
3167-unsigned long arch_randomize_brk(struct mm_struct *mm)
3168-{
3169- unsigned long base = mm->brk;
3170- unsigned long ret;
3171-
3172- ret = PAGE_ALIGN(base + brk_rnd());
3173-
3174- if (ret < mm->brk)
3175- return mm->brk;
3176-
3177- return ret;
3178-}
3179diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3180index 967d144..db12197 100644
3181--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
3182+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3183@@ -11,12 +11,14 @@
3184 #ifndef _ASM_PROC_CACHE_H
3185 #define _ASM_PROC_CACHE_H
3186
3187+#include <linux/const.h>
3188+
3189 /* L1 cache */
3190
3191 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3192 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
3193-#define L1_CACHE_BYTES 16 /* bytes per entry */
3194 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
3195+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3196 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
3197
3198 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3199diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3200index bcb5df2..84fabd2 100644
3201--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3202+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3203@@ -16,13 +16,15 @@
3204 #ifndef _ASM_PROC_CACHE_H
3205 #define _ASM_PROC_CACHE_H
3206
3207+#include <linux/const.h>
3208+
3209 /*
3210 * L1 cache
3211 */
3212 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3213 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
3214-#define L1_CACHE_BYTES 32 /* bytes per entry */
3215 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
3216+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3217 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
3218
3219 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3220diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
3221index 4ce7a01..449202a 100644
3222--- a/arch/openrisc/include/asm/cache.h
3223+++ b/arch/openrisc/include/asm/cache.h
3224@@ -19,11 +19,13 @@
3225 #ifndef __ASM_OPENRISC_CACHE_H
3226 #define __ASM_OPENRISC_CACHE_H
3227
3228+#include <linux/const.h>
3229+
3230 /* FIXME: How can we replace these with values from the CPU...
3231 * they shouldn't be hard-coded!
3232 */
3233
3234-#define L1_CACHE_BYTES 16
3235 #define L1_CACHE_SHIFT 4
3236+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3237
3238 #endif /* __ASM_OPENRISC_CACHE_H */
3239diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
3240index 6c6defc..d30653d 100644
3241--- a/arch/parisc/include/asm/atomic.h
3242+++ b/arch/parisc/include/asm/atomic.h
3243@@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3244
3245 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3246
3247+#define atomic64_read_unchecked(v) atomic64_read(v)
3248+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3249+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3250+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3251+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3252+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3253+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3254+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3255+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3256+
3257 #endif /* !CONFIG_64BIT */
3258
3259
3260diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
3261index 47f11c7..3420df2 100644
3262--- a/arch/parisc/include/asm/cache.h
3263+++ b/arch/parisc/include/asm/cache.h
3264@@ -5,6 +5,7 @@
3265 #ifndef __ARCH_PARISC_CACHE_H
3266 #define __ARCH_PARISC_CACHE_H
3267
3268+#include <linux/const.h>
3269
3270 /*
3271 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
3272@@ -15,13 +16,13 @@
3273 * just ruin performance.
3274 */
3275 #ifdef CONFIG_PA20
3276-#define L1_CACHE_BYTES 64
3277 #define L1_CACHE_SHIFT 6
3278 #else
3279-#define L1_CACHE_BYTES 32
3280 #define L1_CACHE_SHIFT 5
3281 #endif
3282
3283+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3284+
3285 #ifndef __ASSEMBLY__
3286
3287 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3288diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
3289index 19f6cb1..6c78cf2 100644
3290--- a/arch/parisc/include/asm/elf.h
3291+++ b/arch/parisc/include/asm/elf.h
3292@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
3293
3294 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
3295
3296+#ifdef CONFIG_PAX_ASLR
3297+#define PAX_ELF_ET_DYN_BASE 0x10000UL
3298+
3299+#define PAX_DELTA_MMAP_LEN 16
3300+#define PAX_DELTA_STACK_LEN 16
3301+#endif
3302+
3303 /* This yields a mask that user programs can use to figure out what
3304 instruction set this CPU supports. This could be done in user space,
3305 but it's not easy, and we've already done it here. */
3306diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
3307index fc987a1..6e068ef 100644
3308--- a/arch/parisc/include/asm/pgalloc.h
3309+++ b/arch/parisc/include/asm/pgalloc.h
3310@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3311 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
3312 }
3313
3314+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3315+{
3316+ pgd_populate(mm, pgd, pmd);
3317+}
3318+
3319 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
3320 {
3321 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
3322@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
3323 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
3324 #define pmd_free(mm, x) do { } while (0)
3325 #define pgd_populate(mm, pmd, pte) BUG()
3326+#define pgd_populate_kernel(mm, pmd, pte) BUG()
3327
3328 #endif
3329
3330diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
3331index ee99f23..802b0a1 100644
3332--- a/arch/parisc/include/asm/pgtable.h
3333+++ b/arch/parisc/include/asm/pgtable.h
3334@@ -212,6 +212,17 @@ struct vm_area_struct;
3335 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3336 #define PAGE_COPY PAGE_EXECREAD
3337 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3338+
3339+#ifdef CONFIG_PAX_PAGEEXEC
3340+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3341+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3342+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3343+#else
3344+# define PAGE_SHARED_NOEXEC PAGE_SHARED
3345+# define PAGE_COPY_NOEXEC PAGE_COPY
3346+# define PAGE_READONLY_NOEXEC PAGE_READONLY
3347+#endif
3348+
3349 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3350 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3351 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3352diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
3353index 9ac0660..6ed15c4 100644
3354--- a/arch/parisc/include/asm/uaccess.h
3355+++ b/arch/parisc/include/asm/uaccess.h
3356@@ -252,10 +252,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
3357 const void __user *from,
3358 unsigned long n)
3359 {
3360- int sz = __compiletime_object_size(to);
3361+ size_t sz = __compiletime_object_size(to);
3362 int ret = -EFAULT;
3363
3364- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
3365+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
3366 ret = __copy_from_user(to, from, n);
3367 else
3368 copy_from_user_overflow();
3369diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3370index 5e34ccf..672bc9c 100644
3371--- a/arch/parisc/kernel/module.c
3372+++ b/arch/parisc/kernel/module.c
3373@@ -98,16 +98,38 @@
3374
3375 /* three functions to determine where in the module core
3376 * or init pieces the location is */
3377+static inline int in_init_rx(struct module *me, void *loc)
3378+{
3379+ return (loc >= me->module_init_rx &&
3380+ loc < (me->module_init_rx + me->init_size_rx));
3381+}
3382+
3383+static inline int in_init_rw(struct module *me, void *loc)
3384+{
3385+ return (loc >= me->module_init_rw &&
3386+ loc < (me->module_init_rw + me->init_size_rw));
3387+}
3388+
3389 static inline int in_init(struct module *me, void *loc)
3390 {
3391- return (loc >= me->module_init &&
3392- loc <= (me->module_init + me->init_size));
3393+ return in_init_rx(me, loc) || in_init_rw(me, loc);
3394+}
3395+
3396+static inline int in_core_rx(struct module *me, void *loc)
3397+{
3398+ return (loc >= me->module_core_rx &&
3399+ loc < (me->module_core_rx + me->core_size_rx));
3400+}
3401+
3402+static inline int in_core_rw(struct module *me, void *loc)
3403+{
3404+ return (loc >= me->module_core_rw &&
3405+ loc < (me->module_core_rw + me->core_size_rw));
3406 }
3407
3408 static inline int in_core(struct module *me, void *loc)
3409 {
3410- return (loc >= me->module_core &&
3411- loc <= (me->module_core + me->core_size));
3412+ return in_core_rx(me, loc) || in_core_rw(me, loc);
3413 }
3414
3415 static inline int in_local(struct module *me, void *loc)
3416@@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3417 }
3418
3419 /* align things a bit */
3420- me->core_size = ALIGN(me->core_size, 16);
3421- me->arch.got_offset = me->core_size;
3422- me->core_size += gots * sizeof(struct got_entry);
3423+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
3424+ me->arch.got_offset = me->core_size_rw;
3425+ me->core_size_rw += gots * sizeof(struct got_entry);
3426
3427- me->core_size = ALIGN(me->core_size, 16);
3428- me->arch.fdesc_offset = me->core_size;
3429- me->core_size += fdescs * sizeof(Elf_Fdesc);
3430+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
3431+ me->arch.fdesc_offset = me->core_size_rw;
3432+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3433
3434 me->arch.got_max = gots;
3435 me->arch.fdesc_max = fdescs;
3436@@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3437
3438 BUG_ON(value == 0);
3439
3440- got = me->module_core + me->arch.got_offset;
3441+ got = me->module_core_rw + me->arch.got_offset;
3442 for (i = 0; got[i].addr; i++)
3443 if (got[i].addr == value)
3444 goto out;
3445@@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3446 #ifdef CONFIG_64BIT
3447 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3448 {
3449- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3450+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3451
3452 if (!value) {
3453 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3454@@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3455
3456 /* Create new one */
3457 fdesc->addr = value;
3458- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3459+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3460 return (Elf_Addr)fdesc;
3461 }
3462 #endif /* CONFIG_64BIT */
3463@@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3464
3465 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3466 end = table + sechdrs[me->arch.unwind_section].sh_size;
3467- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3468+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3469
3470 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3471 me->arch.unwind_section, table, end, gp);
3472diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3473index c9b9322..02d8940 100644
3474--- a/arch/parisc/kernel/sys_parisc.c
3475+++ b/arch/parisc/kernel/sys_parisc.c
3476@@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3477 /* At this point: (!vma || addr < vma->vm_end). */
3478 if (TASK_SIZE - len < addr)
3479 return -ENOMEM;
3480- if (!vma || addr + len <= vma->vm_start)
3481+ if (check_heap_stack_gap(vma, addr, len))
3482 return addr;
3483 addr = vma->vm_end;
3484 }
3485@@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3486 /* At this point: (!vma || addr < vma->vm_end). */
3487 if (TASK_SIZE - len < addr)
3488 return -ENOMEM;
3489- if (!vma || addr + len <= vma->vm_start)
3490+ if (check_heap_stack_gap(vma, addr, len))
3491 return addr;
3492 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3493 if (addr < vma->vm_end) /* handle wraparound */
3494@@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3495 if (flags & MAP_FIXED)
3496 return addr;
3497 if (!addr)
3498- addr = TASK_UNMAPPED_BASE;
3499+ addr = current->mm->mmap_base;
3500
3501 if (filp) {
3502 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3503diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3504index 45ba99f..8e22c33 100644
3505--- a/arch/parisc/kernel/traps.c
3506+++ b/arch/parisc/kernel/traps.c
3507@@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3508
3509 down_read(&current->mm->mmap_sem);
3510 vma = find_vma(current->mm,regs->iaoq[0]);
3511- if (vma && (regs->iaoq[0] >= vma->vm_start)
3512- && (vma->vm_flags & VM_EXEC)) {
3513-
3514+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3515 fault_address = regs->iaoq[0];
3516 fault_space = regs->iasq[0];
3517
3518diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3519index 18162ce..94de376 100644
3520--- a/arch/parisc/mm/fault.c
3521+++ b/arch/parisc/mm/fault.c
3522@@ -15,6 +15,7 @@
3523 #include <linux/sched.h>
3524 #include <linux/interrupt.h>
3525 #include <linux/module.h>
3526+#include <linux/unistd.h>
3527
3528 #include <asm/uaccess.h>
3529 #include <asm/traps.h>
3530@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3531 static unsigned long
3532 parisc_acctyp(unsigned long code, unsigned int inst)
3533 {
3534- if (code == 6 || code == 16)
3535+ if (code == 6 || code == 7 || code == 16)
3536 return VM_EXEC;
3537
3538 switch (inst & 0xf0000000) {
3539@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3540 }
3541 #endif
3542
3543+#ifdef CONFIG_PAX_PAGEEXEC
3544+/*
3545+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3546+ *
3547+ * returns 1 when task should be killed
3548+ * 2 when rt_sigreturn trampoline was detected
3549+ * 3 when unpatched PLT trampoline was detected
3550+ */
3551+static int pax_handle_fetch_fault(struct pt_regs *regs)
3552+{
3553+
3554+#ifdef CONFIG_PAX_EMUPLT
3555+ int err;
3556+
3557+ do { /* PaX: unpatched PLT emulation */
3558+ unsigned int bl, depwi;
3559+
3560+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3561+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3562+
3563+ if (err)
3564+ break;
3565+
3566+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3567+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3568+
3569+ err = get_user(ldw, (unsigned int *)addr);
3570+ err |= get_user(bv, (unsigned int *)(addr+4));
3571+ err |= get_user(ldw2, (unsigned int *)(addr+8));
3572+
3573+ if (err)
3574+ break;
3575+
3576+ if (ldw == 0x0E801096U &&
3577+ bv == 0xEAC0C000U &&
3578+ ldw2 == 0x0E881095U)
3579+ {
3580+ unsigned int resolver, map;
3581+
3582+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3583+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3584+ if (err)
3585+ break;
3586+
3587+ regs->gr[20] = instruction_pointer(regs)+8;
3588+ regs->gr[21] = map;
3589+ regs->gr[22] = resolver;
3590+ regs->iaoq[0] = resolver | 3UL;
3591+ regs->iaoq[1] = regs->iaoq[0] + 4;
3592+ return 3;
3593+ }
3594+ }
3595+ } while (0);
3596+#endif
3597+
3598+#ifdef CONFIG_PAX_EMUTRAMP
3599+
3600+#ifndef CONFIG_PAX_EMUSIGRT
3601+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3602+ return 1;
3603+#endif
3604+
3605+ do { /* PaX: rt_sigreturn emulation */
3606+ unsigned int ldi1, ldi2, bel, nop;
3607+
3608+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3609+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3610+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3611+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3612+
3613+ if (err)
3614+ break;
3615+
3616+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3617+ ldi2 == 0x3414015AU &&
3618+ bel == 0xE4008200U &&
3619+ nop == 0x08000240U)
3620+ {
3621+ regs->gr[25] = (ldi1 & 2) >> 1;
3622+ regs->gr[20] = __NR_rt_sigreturn;
3623+ regs->gr[31] = regs->iaoq[1] + 16;
3624+ regs->sr[0] = regs->iasq[1];
3625+ regs->iaoq[0] = 0x100UL;
3626+ regs->iaoq[1] = regs->iaoq[0] + 4;
3627+ regs->iasq[0] = regs->sr[2];
3628+ regs->iasq[1] = regs->sr[2];
3629+ return 2;
3630+ }
3631+ } while (0);
3632+#endif
3633+
3634+ return 1;
3635+}
3636+
3637+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3638+{
3639+ unsigned long i;
3640+
3641+ printk(KERN_ERR "PAX: bytes at PC: ");
3642+ for (i = 0; i < 5; i++) {
3643+ unsigned int c;
3644+ if (get_user(c, (unsigned int *)pc+i))
3645+ printk(KERN_CONT "???????? ");
3646+ else
3647+ printk(KERN_CONT "%08x ", c);
3648+ }
3649+ printk("\n");
3650+}
3651+#endif
3652+
3653 int fixup_exception(struct pt_regs *regs)
3654 {
3655 const struct exception_table_entry *fix;
3656@@ -192,8 +303,33 @@ good_area:
3657
3658 acc_type = parisc_acctyp(code,regs->iir);
3659
3660- if ((vma->vm_flags & acc_type) != acc_type)
3661+ if ((vma->vm_flags & acc_type) != acc_type) {
3662+
3663+#ifdef CONFIG_PAX_PAGEEXEC
3664+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3665+ (address & ~3UL) == instruction_pointer(regs))
3666+ {
3667+ up_read(&mm->mmap_sem);
3668+ switch (pax_handle_fetch_fault(regs)) {
3669+
3670+#ifdef CONFIG_PAX_EMUPLT
3671+ case 3:
3672+ return;
3673+#endif
3674+
3675+#ifdef CONFIG_PAX_EMUTRAMP
3676+ case 2:
3677+ return;
3678+#endif
3679+
3680+ }
3681+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3682+ do_group_exit(SIGKILL);
3683+ }
3684+#endif
3685+
3686 goto bad_area;
3687+ }
3688
3689 /*
3690 * If for any reason at all we couldn't handle the fault, make
3691diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3692index da29032..f76c24c 100644
3693--- a/arch/powerpc/include/asm/atomic.h
3694+++ b/arch/powerpc/include/asm/atomic.h
3695@@ -522,6 +522,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
3696 return t1;
3697 }
3698
3699+#define atomic64_read_unchecked(v) atomic64_read(v)
3700+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3701+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3702+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3703+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3704+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3705+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3706+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3707+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3708+
3709 #endif /* __powerpc64__ */
3710
3711 #endif /* __KERNEL__ */
3712diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3713index 9e495c9..b6878e5 100644
3714--- a/arch/powerpc/include/asm/cache.h
3715+++ b/arch/powerpc/include/asm/cache.h
3716@@ -3,6 +3,7 @@
3717
3718 #ifdef __KERNEL__
3719
3720+#include <linux/const.h>
3721
3722 /* bytes per L1 cache line */
3723 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3724@@ -22,7 +23,7 @@
3725 #define L1_CACHE_SHIFT 7
3726 #endif
3727
3728-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3729+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3730
3731 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3732
3733diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3734index 3bf9cca..e7457d0 100644
3735--- a/arch/powerpc/include/asm/elf.h
3736+++ b/arch/powerpc/include/asm/elf.h
3737@@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3738 the loader. We need to make sure that it is out of the way of the program
3739 that it will "exec", and that there is sufficient room for the brk. */
3740
3741-extern unsigned long randomize_et_dyn(unsigned long base);
3742-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3743+#define ELF_ET_DYN_BASE (0x20000000)
3744+
3745+#ifdef CONFIG_PAX_ASLR
3746+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3747+
3748+#ifdef __powerpc64__
3749+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3750+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3751+#else
3752+#define PAX_DELTA_MMAP_LEN 15
3753+#define PAX_DELTA_STACK_LEN 15
3754+#endif
3755+#endif
3756
3757 /*
3758 * Our registers are always unsigned longs, whether we're a 32 bit
3759@@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3760 (0x7ff >> (PAGE_SHIFT - 12)) : \
3761 (0x3ffff >> (PAGE_SHIFT - 12)))
3762
3763-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3764-#define arch_randomize_brk arch_randomize_brk
3765-
3766 #endif /* __KERNEL__ */
3767
3768 /*
3769diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
3770index 8196e9c..d83a9f3 100644
3771--- a/arch/powerpc/include/asm/exec.h
3772+++ b/arch/powerpc/include/asm/exec.h
3773@@ -4,6 +4,6 @@
3774 #ifndef _ASM_POWERPC_EXEC_H
3775 #define _ASM_POWERPC_EXEC_H
3776
3777-extern unsigned long arch_align_stack(unsigned long sp);
3778+#define arch_align_stack(x) ((x) & ~0xfUL)
3779
3780 #endif /* _ASM_POWERPC_EXEC_H */
3781diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3782index bca8fdc..61e9580 100644
3783--- a/arch/powerpc/include/asm/kmap_types.h
3784+++ b/arch/powerpc/include/asm/kmap_types.h
3785@@ -27,6 +27,7 @@ enum km_type {
3786 KM_PPC_SYNC_PAGE,
3787 KM_PPC_SYNC_ICACHE,
3788 KM_KDB,
3789+ KM_CLEARPAGE,
3790 KM_TYPE_NR
3791 };
3792
3793diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3794index d4a7f64..451de1c 100644
3795--- a/arch/powerpc/include/asm/mman.h
3796+++ b/arch/powerpc/include/asm/mman.h
3797@@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3798 }
3799 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3800
3801-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3802+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3803 {
3804 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3805 }
3806diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3807index f072e97..b436dee 100644
3808--- a/arch/powerpc/include/asm/page.h
3809+++ b/arch/powerpc/include/asm/page.h
3810@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3811 * and needs to be executable. This means the whole heap ends
3812 * up being executable.
3813 */
3814-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3815- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3816+#define VM_DATA_DEFAULT_FLAGS32 \
3817+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3818+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3819
3820 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3821 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3822@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3823 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3824 #endif
3825
3826+#define ktla_ktva(addr) (addr)
3827+#define ktva_ktla(addr) (addr)
3828+
3829 /*
3830 * Use the top bit of the higher-level page table entries to indicate whether
3831 * the entries we point to contain hugepages. This works because we know that
3832diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3833index fed85e6..da5c71b 100644
3834--- a/arch/powerpc/include/asm/page_64.h
3835+++ b/arch/powerpc/include/asm/page_64.h
3836@@ -146,15 +146,18 @@ do { \
3837 * stack by default, so in the absence of a PT_GNU_STACK program header
3838 * we turn execute permission off.
3839 */
3840-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3841- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3842+#define VM_STACK_DEFAULT_FLAGS32 \
3843+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3844+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3845
3846 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3847 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3848
3849+#ifndef CONFIG_PAX_PAGEEXEC
3850 #define VM_STACK_DEFAULT_FLAGS \
3851 (is_32bit_task() ? \
3852 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3853+#endif
3854
3855 #include <asm-generic/getorder.h>
3856
3857diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
3858index 292725c..f87ae14 100644
3859--- a/arch/powerpc/include/asm/pgalloc-64.h
3860+++ b/arch/powerpc/include/asm/pgalloc-64.h
3861@@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3862 #ifndef CONFIG_PPC_64K_PAGES
3863
3864 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
3865+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
3866
3867 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3868 {
3869@@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3870 pud_set(pud, (unsigned long)pmd);
3871 }
3872
3873+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3874+{
3875+ pud_populate(mm, pud, pmd);
3876+}
3877+
3878 #define pmd_populate(mm, pmd, pte_page) \
3879 pmd_populate_kernel(mm, pmd, page_address(pte_page))
3880 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
3881@@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3882 #else /* CONFIG_PPC_64K_PAGES */
3883
3884 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
3885+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
3886
3887 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
3888 pte_t *pte)
3889diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3890index 2e0e411..7899c68 100644
3891--- a/arch/powerpc/include/asm/pgtable.h
3892+++ b/arch/powerpc/include/asm/pgtable.h
3893@@ -2,6 +2,7 @@
3894 #define _ASM_POWERPC_PGTABLE_H
3895 #ifdef __KERNEL__
3896
3897+#include <linux/const.h>
3898 #ifndef __ASSEMBLY__
3899 #include <asm/processor.h> /* For TASK_SIZE */
3900 #include <asm/mmu.h>
3901diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3902index 4aad413..85d86bf 100644
3903--- a/arch/powerpc/include/asm/pte-hash32.h
3904+++ b/arch/powerpc/include/asm/pte-hash32.h
3905@@ -21,6 +21,7 @@
3906 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3907 #define _PAGE_USER 0x004 /* usermode access allowed */
3908 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3909+#define _PAGE_EXEC _PAGE_GUARDED
3910 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3911 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3912 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3913diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3914index 9d7f0fb..a28fe69 100644
3915--- a/arch/powerpc/include/asm/reg.h
3916+++ b/arch/powerpc/include/asm/reg.h
3917@@ -212,6 +212,7 @@
3918 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3919 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3920 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3921+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3922 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3923 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3924 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3925diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
3926index 4a741c7..c8162227b 100644
3927--- a/arch/powerpc/include/asm/thread_info.h
3928+++ b/arch/powerpc/include/asm/thread_info.h
3929@@ -104,12 +104,14 @@ static inline struct thread_info *current_thread_info(void)
3930 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
3931 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
3932 #define TIF_SINGLESTEP 8 /* singlestepping active */
3933-#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
3934 #define TIF_SECCOMP 10 /* secure computing */
3935 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
3936 #define TIF_NOERROR 12 /* Force successful syscall return */
3937 #define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
3938 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
3939+#define TIF_MEMDIE 16 /* is terminating due to OOM killer */
3940+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
3941+#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
3942
3943 /* as above, but as bit values */
3944 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3945@@ -127,8 +129,11 @@ static inline struct thread_info *current_thread_info(void)
3946 #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
3947 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
3948 #define _TIF_RUNLATCH (1<<TIF_RUNLATCH)
3949+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3950+
3951 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
3952- _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
3953+ _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT \
3954+ _TIF_GRSEC_SETXID)
3955
3956 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
3957 _TIF_NOTIFY_RESUME)
3958diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3959index bd0fb84..a42a14b 100644
3960--- a/arch/powerpc/include/asm/uaccess.h
3961+++ b/arch/powerpc/include/asm/uaccess.h
3962@@ -13,6 +13,8 @@
3963 #define VERIFY_READ 0
3964 #define VERIFY_WRITE 1
3965
3966+extern void check_object_size(const void *ptr, unsigned long n, bool to);
3967+
3968 /*
3969 * The fs value determines whether argument validity checking should be
3970 * performed or not. If get_fs() == USER_DS, checking is performed, with
3971@@ -327,52 +329,6 @@ do { \
3972 extern unsigned long __copy_tofrom_user(void __user *to,
3973 const void __user *from, unsigned long size);
3974
3975-#ifndef __powerpc64__
3976-
3977-static inline unsigned long copy_from_user(void *to,
3978- const void __user *from, unsigned long n)
3979-{
3980- unsigned long over;
3981-
3982- if (access_ok(VERIFY_READ, from, n))
3983- return __copy_tofrom_user((__force void __user *)to, from, n);
3984- if ((unsigned long)from < TASK_SIZE) {
3985- over = (unsigned long)from + n - TASK_SIZE;
3986- return __copy_tofrom_user((__force void __user *)to, from,
3987- n - over) + over;
3988- }
3989- return n;
3990-}
3991-
3992-static inline unsigned long copy_to_user(void __user *to,
3993- const void *from, unsigned long n)
3994-{
3995- unsigned long over;
3996-
3997- if (access_ok(VERIFY_WRITE, to, n))
3998- return __copy_tofrom_user(to, (__force void __user *)from, n);
3999- if ((unsigned long)to < TASK_SIZE) {
4000- over = (unsigned long)to + n - TASK_SIZE;
4001- return __copy_tofrom_user(to, (__force void __user *)from,
4002- n - over) + over;
4003- }
4004- return n;
4005-}
4006-
4007-#else /* __powerpc64__ */
4008-
4009-#define __copy_in_user(to, from, size) \
4010- __copy_tofrom_user((to), (from), (size))
4011-
4012-extern unsigned long copy_from_user(void *to, const void __user *from,
4013- unsigned long n);
4014-extern unsigned long copy_to_user(void __user *to, const void *from,
4015- unsigned long n);
4016-extern unsigned long copy_in_user(void __user *to, const void __user *from,
4017- unsigned long n);
4018-
4019-#endif /* __powerpc64__ */
4020-
4021 static inline unsigned long __copy_from_user_inatomic(void *to,
4022 const void __user *from, unsigned long n)
4023 {
4024@@ -396,6 +352,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
4025 if (ret == 0)
4026 return 0;
4027 }
4028+
4029+ if (!__builtin_constant_p(n))
4030+ check_object_size(to, n, false);
4031+
4032 return __copy_tofrom_user((__force void __user *)to, from, n);
4033 }
4034
4035@@ -422,6 +382,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
4036 if (ret == 0)
4037 return 0;
4038 }
4039+
4040+ if (!__builtin_constant_p(n))
4041+ check_object_size(from, n, true);
4042+
4043 return __copy_tofrom_user(to, (__force const void __user *)from, n);
4044 }
4045
4046@@ -439,6 +403,92 @@ static inline unsigned long __copy_to_user(void __user *to,
4047 return __copy_to_user_inatomic(to, from, size);
4048 }
4049
4050+#ifndef __powerpc64__
4051+
4052+static inline unsigned long __must_check copy_from_user(void *to,
4053+ const void __user *from, unsigned long n)
4054+{
4055+ unsigned long over;
4056+
4057+ if ((long)n < 0)
4058+ return n;
4059+
4060+ if (access_ok(VERIFY_READ, from, n)) {
4061+ if (!__builtin_constant_p(n))
4062+ check_object_size(to, n, false);
4063+ return __copy_tofrom_user((__force void __user *)to, from, n);
4064+ }
4065+ if ((unsigned long)from < TASK_SIZE) {
4066+ over = (unsigned long)from + n - TASK_SIZE;
4067+ if (!__builtin_constant_p(n - over))
4068+ check_object_size(to, n - over, false);
4069+ return __copy_tofrom_user((__force void __user *)to, from,
4070+ n - over) + over;
4071+ }
4072+ return n;
4073+}
4074+
4075+static inline unsigned long __must_check copy_to_user(void __user *to,
4076+ const void *from, unsigned long n)
4077+{
4078+ unsigned long over;
4079+
4080+ if ((long)n < 0)
4081+ return n;
4082+
4083+ if (access_ok(VERIFY_WRITE, to, n)) {
4084+ if (!__builtin_constant_p(n))
4085+ check_object_size(from, n, true);
4086+ return __copy_tofrom_user(to, (__force void __user *)from, n);
4087+ }
4088+ if ((unsigned long)to < TASK_SIZE) {
4089+ over = (unsigned long)to + n - TASK_SIZE;
4090+ if (!__builtin_constant_p(n))
4091+ check_object_size(from, n - over, true);
4092+ return __copy_tofrom_user(to, (__force void __user *)from,
4093+ n - over) + over;
4094+ }
4095+ return n;
4096+}
4097+
4098+#else /* __powerpc64__ */
4099+
4100+#define __copy_in_user(to, from, size) \
4101+ __copy_tofrom_user((to), (from), (size))
4102+
4103+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4104+{
4105+ if ((long)n < 0 || n > INT_MAX)
4106+ return n;
4107+
4108+ if (!__builtin_constant_p(n))
4109+ check_object_size(to, n, false);
4110+
4111+ if (likely(access_ok(VERIFY_READ, from, n)))
4112+ n = __copy_from_user(to, from, n);
4113+ else
4114+ memset(to, 0, n);
4115+ return n;
4116+}
4117+
4118+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4119+{
4120+ if ((long)n < 0 || n > INT_MAX)
4121+ return n;
4122+
4123+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
4124+ if (!__builtin_constant_p(n))
4125+ check_object_size(from, n, true);
4126+ n = __copy_to_user(to, from, n);
4127+ }
4128+ return n;
4129+}
4130+
4131+extern unsigned long copy_in_user(void __user *to, const void __user *from,
4132+ unsigned long n);
4133+
4134+#endif /* __powerpc64__ */
4135+
4136 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4137
4138 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4139diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4140index 7215cc2..a9730c1 100644
4141--- a/arch/powerpc/kernel/exceptions-64e.S
4142+++ b/arch/powerpc/kernel/exceptions-64e.S
4143@@ -661,6 +661,7 @@ storage_fault_common:
4144 std r14,_DAR(r1)
4145 std r15,_DSISR(r1)
4146 addi r3,r1,STACK_FRAME_OVERHEAD
4147+ bl .save_nvgprs
4148 mr r4,r14
4149 mr r5,r15
4150 ld r14,PACA_EXGEN+EX_R14(r13)
4151@@ -669,8 +670,7 @@ storage_fault_common:
4152 cmpdi r3,0
4153 bne- 1f
4154 b .ret_from_except_lite
4155-1: bl .save_nvgprs
4156- mr r5,r3
4157+1: mr r5,r3
4158 addi r3,r1,STACK_FRAME_OVERHEAD
4159 ld r4,_DAR(r1)
4160 bl .bad_page_fault
4161diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4162index 8f880bc..c5bd2f3 100644
4163--- a/arch/powerpc/kernel/exceptions-64s.S
4164+++ b/arch/powerpc/kernel/exceptions-64s.S
4165@@ -890,10 +890,10 @@ handle_page_fault:
4166 11: ld r4,_DAR(r1)
4167 ld r5,_DSISR(r1)
4168 addi r3,r1,STACK_FRAME_OVERHEAD
4169+ bl .save_nvgprs
4170 bl .do_page_fault
4171 cmpdi r3,0
4172 beq+ 12f
4173- bl .save_nvgprs
4174 mr r5,r3
4175 addi r3,r1,STACK_FRAME_OVERHEAD
4176 lwz r4,_DAR(r1)
4177diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4178index 2e3200c..72095ce 100644
4179--- a/arch/powerpc/kernel/module_32.c
4180+++ b/arch/powerpc/kernel/module_32.c
4181@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4182 me->arch.core_plt_section = i;
4183 }
4184 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4185- printk("Module doesn't contain .plt or .init.plt sections.\n");
4186+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4187 return -ENOEXEC;
4188 }
4189
4190@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4191
4192 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4193 /* Init, or core PLT? */
4194- if (location >= mod->module_core
4195- && location < mod->module_core + mod->core_size)
4196+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
4197+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
4198 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
4199- else
4200+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
4201+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
4202 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
4203+ else {
4204+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
4205+ return ~0UL;
4206+ }
4207
4208 /* Find this entry, or if that fails, the next avail. entry */
4209 while (entry->jump[0]) {
4210diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
4211index 4937c96..70714b7 100644
4212--- a/arch/powerpc/kernel/process.c
4213+++ b/arch/powerpc/kernel/process.c
4214@@ -681,8 +681,8 @@ void show_regs(struct pt_regs * regs)
4215 * Lookup NIP late so we have the best change of getting the
4216 * above info out without failing
4217 */
4218- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
4219- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
4220+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
4221+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
4222 #endif
4223 show_stack(current, (unsigned long *) regs->gpr[1]);
4224 if (!user_mode(regs))
4225@@ -1186,10 +1186,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4226 newsp = stack[0];
4227 ip = stack[STACK_FRAME_LR_SAVE];
4228 if (!firstframe || ip != lr) {
4229- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
4230+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
4231 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4232 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
4233- printk(" (%pS)",
4234+ printk(" (%pA)",
4235 (void *)current->ret_stack[curr_frame].ret);
4236 curr_frame--;
4237 }
4238@@ -1209,7 +1209,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4239 struct pt_regs *regs = (struct pt_regs *)
4240 (sp + STACK_FRAME_OVERHEAD);
4241 lr = regs->link;
4242- printk("--- Exception: %lx at %pS\n LR = %pS\n",
4243+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
4244 regs->trap, (void *)regs->nip, (void *)lr);
4245 firstframe = 1;
4246 }
4247@@ -1282,58 +1282,3 @@ void thread_info_cache_init(void)
4248 }
4249
4250 #endif /* THREAD_SHIFT < PAGE_SHIFT */
4251-
4252-unsigned long arch_align_stack(unsigned long sp)
4253-{
4254- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4255- sp -= get_random_int() & ~PAGE_MASK;
4256- return sp & ~0xf;
4257-}
4258-
4259-static inline unsigned long brk_rnd(void)
4260-{
4261- unsigned long rnd = 0;
4262-
4263- /* 8MB for 32bit, 1GB for 64bit */
4264- if (is_32bit_task())
4265- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4266- else
4267- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4268-
4269- return rnd << PAGE_SHIFT;
4270-}
4271-
4272-unsigned long arch_randomize_brk(struct mm_struct *mm)
4273-{
4274- unsigned long base = mm->brk;
4275- unsigned long ret;
4276-
4277-#ifdef CONFIG_PPC_STD_MMU_64
4278- /*
4279- * If we are using 1TB segments and we are allowed to randomise
4280- * the heap, we can put it above 1TB so it is backed by a 1TB
4281- * segment. Otherwise the heap will be in the bottom 1TB
4282- * which always uses 256MB segments and this may result in a
4283- * performance penalty.
4284- */
4285- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
4286- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
4287-#endif
4288-
4289- ret = PAGE_ALIGN(base + brk_rnd());
4290-
4291- if (ret < mm->brk)
4292- return mm->brk;
4293-
4294- return ret;
4295-}
4296-
4297-unsigned long randomize_et_dyn(unsigned long base)
4298-{
4299- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4300-
4301- if (ret < base)
4302- return base;
4303-
4304- return ret;
4305-}
4306diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
4307index 8d8e028..c2aeb50 100644
4308--- a/arch/powerpc/kernel/ptrace.c
4309+++ b/arch/powerpc/kernel/ptrace.c
4310@@ -1702,6 +1702,10 @@ long arch_ptrace(struct task_struct *child, long request,
4311 return ret;
4312 }
4313
4314+#ifdef CONFIG_GRKERNSEC_SETXID
4315+extern void gr_delayed_cred_worker(void);
4316+#endif
4317+
4318 /*
4319 * We must return the syscall number to actually look up in the table.
4320 * This can be -1L to skip running any syscall at all.
4321@@ -1712,6 +1716,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
4322
4323 secure_computing(regs->gpr[0]);
4324
4325+#ifdef CONFIG_GRKERNSEC_SETXID
4326+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4327+ gr_delayed_cred_worker();
4328+#endif
4329+
4330 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
4331 tracehook_report_syscall_entry(regs))
4332 /*
4333@@ -1746,6 +1755,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
4334 {
4335 int step;
4336
4337+#ifdef CONFIG_GRKERNSEC_SETXID
4338+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4339+ gr_delayed_cred_worker();
4340+#endif
4341+
4342 audit_syscall_exit(regs);
4343
4344 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
4345diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
4346index 45eb998..0cb36bc 100644
4347--- a/arch/powerpc/kernel/signal_32.c
4348+++ b/arch/powerpc/kernel/signal_32.c
4349@@ -861,7 +861,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
4350 /* Save user registers on the stack */
4351 frame = &rt_sf->uc.uc_mcontext;
4352 addr = frame;
4353- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4354+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4355 if (save_user_regs(regs, frame, 0, 1))
4356 goto badframe;
4357 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4358diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
4359index 2692efd..6673d2e 100644
4360--- a/arch/powerpc/kernel/signal_64.c
4361+++ b/arch/powerpc/kernel/signal_64.c
4362@@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
4363 current->thread.fpscr.val = 0;
4364
4365 /* Set up to return from userspace. */
4366- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4367+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4368 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4369 } else {
4370 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4371diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4372index 1589723..cefe690 100644
4373--- a/arch/powerpc/kernel/traps.c
4374+++ b/arch/powerpc/kernel/traps.c
4375@@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4376 return flags;
4377 }
4378
4379+extern void gr_handle_kernel_exploit(void);
4380+
4381 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4382 int signr)
4383 {
4384@@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4385 panic("Fatal exception in interrupt");
4386 if (panic_on_oops)
4387 panic("Fatal exception");
4388+
4389+ gr_handle_kernel_exploit();
4390+
4391 do_exit(signr);
4392 }
4393
4394diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4395index 9eb5b9b..e45498a 100644
4396--- a/arch/powerpc/kernel/vdso.c
4397+++ b/arch/powerpc/kernel/vdso.c
4398@@ -34,6 +34,7 @@
4399 #include <asm/firmware.h>
4400 #include <asm/vdso.h>
4401 #include <asm/vdso_datapage.h>
4402+#include <asm/mman.h>
4403
4404 #include "setup.h"
4405
4406@@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4407 vdso_base = VDSO32_MBASE;
4408 #endif
4409
4410- current->mm->context.vdso_base = 0;
4411+ current->mm->context.vdso_base = ~0UL;
4412
4413 /* vDSO has a problem and was disabled, just don't "enable" it for the
4414 * process
4415@@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4416 vdso_base = get_unmapped_area(NULL, vdso_base,
4417 (vdso_pages << PAGE_SHIFT) +
4418 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4419- 0, 0);
4420+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
4421 if (IS_ERR_VALUE(vdso_base)) {
4422 rc = vdso_base;
4423 goto fail_mmapsem;
4424diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4425index 5eea6f3..5d10396 100644
4426--- a/arch/powerpc/lib/usercopy_64.c
4427+++ b/arch/powerpc/lib/usercopy_64.c
4428@@ -9,22 +9,6 @@
4429 #include <linux/module.h>
4430 #include <asm/uaccess.h>
4431
4432-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4433-{
4434- if (likely(access_ok(VERIFY_READ, from, n)))
4435- n = __copy_from_user(to, from, n);
4436- else
4437- memset(to, 0, n);
4438- return n;
4439-}
4440-
4441-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4442-{
4443- if (likely(access_ok(VERIFY_WRITE, to, n)))
4444- n = __copy_to_user(to, from, n);
4445- return n;
4446-}
4447-
4448 unsigned long copy_in_user(void __user *to, const void __user *from,
4449 unsigned long n)
4450 {
4451@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4452 return n;
4453 }
4454
4455-EXPORT_SYMBOL(copy_from_user);
4456-EXPORT_SYMBOL(copy_to_user);
4457 EXPORT_SYMBOL(copy_in_user);
4458
4459diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4460index 08ffcf5..a0ab912 100644
4461--- a/arch/powerpc/mm/fault.c
4462+++ b/arch/powerpc/mm/fault.c
4463@@ -32,6 +32,10 @@
4464 #include <linux/perf_event.h>
4465 #include <linux/magic.h>
4466 #include <linux/ratelimit.h>
4467+#include <linux/slab.h>
4468+#include <linux/pagemap.h>
4469+#include <linux/compiler.h>
4470+#include <linux/unistd.h>
4471
4472 #include <asm/firmware.h>
4473 #include <asm/page.h>
4474@@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4475 }
4476 #endif
4477
4478+#ifdef CONFIG_PAX_PAGEEXEC
4479+/*
4480+ * PaX: decide what to do with offenders (regs->nip = fault address)
4481+ *
4482+ * returns 1 when task should be killed
4483+ */
4484+static int pax_handle_fetch_fault(struct pt_regs *regs)
4485+{
4486+ return 1;
4487+}
4488+
4489+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4490+{
4491+ unsigned long i;
4492+
4493+ printk(KERN_ERR "PAX: bytes at PC: ");
4494+ for (i = 0; i < 5; i++) {
4495+ unsigned int c;
4496+ if (get_user(c, (unsigned int __user *)pc+i))
4497+ printk(KERN_CONT "???????? ");
4498+ else
4499+ printk(KERN_CONT "%08x ", c);
4500+ }
4501+ printk("\n");
4502+}
4503+#endif
4504+
4505 /*
4506 * Check whether the instruction at regs->nip is a store using
4507 * an update addressing form which will update r1.
4508@@ -215,7 +246,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4509 * indicate errors in DSISR but can validly be set in SRR1.
4510 */
4511 if (trap == 0x400)
4512- error_code &= 0x48200000;
4513+ error_code &= 0x58200000;
4514 else
4515 is_write = error_code & DSISR_ISSTORE;
4516 #else
4517@@ -366,7 +397,7 @@ good_area:
4518 * "undefined". Of those that can be set, this is the only
4519 * one which seems bad.
4520 */
4521- if (error_code & 0x10000000)
4522+ if (error_code & DSISR_GUARDED)
4523 /* Guarded storage error. */
4524 goto bad_area;
4525 #endif /* CONFIG_8xx */
4526@@ -381,7 +412,7 @@ good_area:
4527 * processors use the same I/D cache coherency mechanism
4528 * as embedded.
4529 */
4530- if (error_code & DSISR_PROTFAULT)
4531+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4532 goto bad_area;
4533 #endif /* CONFIG_PPC_STD_MMU */
4534
4535@@ -463,6 +494,23 @@ bad_area:
4536 bad_area_nosemaphore:
4537 /* User mode accesses cause a SIGSEGV */
4538 if (user_mode(regs)) {
4539+
4540+#ifdef CONFIG_PAX_PAGEEXEC
4541+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4542+#ifdef CONFIG_PPC_STD_MMU
4543+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4544+#else
4545+ if (is_exec && regs->nip == address) {
4546+#endif
4547+ switch (pax_handle_fetch_fault(regs)) {
4548+ }
4549+
4550+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4551+ do_group_exit(SIGKILL);
4552+ }
4553+ }
4554+#endif
4555+
4556 _exception(SIGSEGV, regs, code, address);
4557 return 0;
4558 }
4559diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4560index 67a42ed..1c7210c 100644
4561--- a/arch/powerpc/mm/mmap_64.c
4562+++ b/arch/powerpc/mm/mmap_64.c
4563@@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4564 */
4565 if (mmap_is_legacy()) {
4566 mm->mmap_base = TASK_UNMAPPED_BASE;
4567+
4568+#ifdef CONFIG_PAX_RANDMMAP
4569+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4570+ mm->mmap_base += mm->delta_mmap;
4571+#endif
4572+
4573 mm->get_unmapped_area = arch_get_unmapped_area;
4574 mm->unmap_area = arch_unmap_area;
4575 } else {
4576 mm->mmap_base = mmap_base();
4577+
4578+#ifdef CONFIG_PAX_RANDMMAP
4579+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4580+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4581+#endif
4582+
4583 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4584 mm->unmap_area = arch_unmap_area_topdown;
4585 }
4586diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4587index 73709f7..6b90313 100644
4588--- a/arch/powerpc/mm/slice.c
4589+++ b/arch/powerpc/mm/slice.c
4590@@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4591 if ((mm->task_size - len) < addr)
4592 return 0;
4593 vma = find_vma(mm, addr);
4594- return (!vma || (addr + len) <= vma->vm_start);
4595+ return check_heap_stack_gap(vma, addr, len);
4596 }
4597
4598 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4599@@ -256,7 +256,7 @@ full_search:
4600 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4601 continue;
4602 }
4603- if (!vma || addr + len <= vma->vm_start) {
4604+ if (check_heap_stack_gap(vma, addr, len)) {
4605 /*
4606 * Remember the place where we stopped the search:
4607 */
4608@@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4609 }
4610 }
4611
4612- addr = mm->mmap_base;
4613- while (addr > len) {
4614+ if (mm->mmap_base < len)
4615+ addr = -ENOMEM;
4616+ else
4617+ addr = mm->mmap_base - len;
4618+
4619+ while (!IS_ERR_VALUE(addr)) {
4620 /* Go down by chunk size */
4621- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4622+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
4623
4624 /* Check for hit with different page size */
4625 mask = slice_range_to_mask(addr, len);
4626@@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4627 * return with success:
4628 */
4629 vma = find_vma(mm, addr);
4630- if (!vma || (addr + len) <= vma->vm_start) {
4631+ if (check_heap_stack_gap(vma, addr, len)) {
4632 /* remember the address as a hint for next time */
4633 if (use_cache)
4634 mm->free_area_cache = addr;
4635@@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4636 mm->cached_hole_size = vma->vm_start - addr;
4637
4638 /* try just below the current vma->vm_start */
4639- addr = vma->vm_start;
4640+ addr = skip_heap_stack_gap(vma, len);
4641 }
4642
4643 /*
4644@@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4645 if (fixed && addr > (mm->task_size - len))
4646 return -EINVAL;
4647
4648+#ifdef CONFIG_PAX_RANDMMAP
4649+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4650+ addr = 0;
4651+#endif
4652+
4653 /* If hint, make sure it matches our alignment restrictions */
4654 if (!fixed && addr) {
4655 addr = _ALIGN_UP(addr, 1ul << pshift);
4656diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4657index 748347b..81bc6c7 100644
4658--- a/arch/s390/include/asm/atomic.h
4659+++ b/arch/s390/include/asm/atomic.h
4660@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4661 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4662 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4663
4664+#define atomic64_read_unchecked(v) atomic64_read(v)
4665+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4666+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4667+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4668+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4669+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4670+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4671+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4672+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4673+
4674 #define smp_mb__before_atomic_dec() smp_mb()
4675 #define smp_mb__after_atomic_dec() smp_mb()
4676 #define smp_mb__before_atomic_inc() smp_mb()
4677diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4678index 2a30d5a..5e5586f 100644
4679--- a/arch/s390/include/asm/cache.h
4680+++ b/arch/s390/include/asm/cache.h
4681@@ -11,8 +11,10 @@
4682 #ifndef __ARCH_S390_CACHE_H
4683 #define __ARCH_S390_CACHE_H
4684
4685-#define L1_CACHE_BYTES 256
4686+#include <linux/const.h>
4687+
4688 #define L1_CACHE_SHIFT 8
4689+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4690 #define NET_SKB_PAD 32
4691
4692 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4693diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4694index c4ee39f..352881b 100644
4695--- a/arch/s390/include/asm/elf.h
4696+++ b/arch/s390/include/asm/elf.h
4697@@ -161,8 +161,14 @@ extern unsigned int vdso_enabled;
4698 the loader. We need to make sure that it is out of the way of the program
4699 that it will "exec", and that there is sufficient room for the brk. */
4700
4701-extern unsigned long randomize_et_dyn(unsigned long base);
4702-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4703+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4704+
4705+#ifdef CONFIG_PAX_ASLR
4706+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4707+
4708+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4709+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4710+#endif
4711
4712 /* This yields a mask that user programs can use to figure out what
4713 instruction set this CPU supports. */
4714@@ -210,7 +216,4 @@ struct linux_binprm;
4715 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4716 int arch_setup_additional_pages(struct linux_binprm *, int);
4717
4718-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4719-#define arch_randomize_brk arch_randomize_brk
4720-
4721 #endif
4722diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
4723index c4a93d6..4d2a9b4 100644
4724--- a/arch/s390/include/asm/exec.h
4725+++ b/arch/s390/include/asm/exec.h
4726@@ -7,6 +7,6 @@
4727 #ifndef __ASM_EXEC_H
4728 #define __ASM_EXEC_H
4729
4730-extern unsigned long arch_align_stack(unsigned long sp);
4731+#define arch_align_stack(x) ((x) & ~0xfUL)
4732
4733 #endif /* __ASM_EXEC_H */
4734diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4735index 8f2cada..43072c1 100644
4736--- a/arch/s390/include/asm/uaccess.h
4737+++ b/arch/s390/include/asm/uaccess.h
4738@@ -236,6 +236,10 @@ static inline unsigned long __must_check
4739 copy_to_user(void __user *to, const void *from, unsigned long n)
4740 {
4741 might_fault();
4742+
4743+ if ((long)n < 0)
4744+ return n;
4745+
4746 if (access_ok(VERIFY_WRITE, to, n))
4747 n = __copy_to_user(to, from, n);
4748 return n;
4749@@ -261,6 +265,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4750 static inline unsigned long __must_check
4751 __copy_from_user(void *to, const void __user *from, unsigned long n)
4752 {
4753+ if ((long)n < 0)
4754+ return n;
4755+
4756 if (__builtin_constant_p(n) && (n <= 256))
4757 return uaccess.copy_from_user_small(n, from, to);
4758 else
4759@@ -292,10 +299,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
4760 static inline unsigned long __must_check
4761 copy_from_user(void *to, const void __user *from, unsigned long n)
4762 {
4763- unsigned int sz = __compiletime_object_size(to);
4764+ size_t sz = __compiletime_object_size(to);
4765
4766 might_fault();
4767- if (unlikely(sz != -1 && sz < n)) {
4768+
4769+ if ((long)n < 0)
4770+ return n;
4771+
4772+ if (unlikely(sz != (size_t)-1 && sz < n)) {
4773 copy_from_user_overflow();
4774 return n;
4775 }
4776diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4777index dfcb343..eda788a 100644
4778--- a/arch/s390/kernel/module.c
4779+++ b/arch/s390/kernel/module.c
4780@@ -161,11 +161,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4781
4782 /* Increase core size by size of got & plt and set start
4783 offsets for got and plt. */
4784- me->core_size = ALIGN(me->core_size, 4);
4785- me->arch.got_offset = me->core_size;
4786- me->core_size += me->arch.got_size;
4787- me->arch.plt_offset = me->core_size;
4788- me->core_size += me->arch.plt_size;
4789+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
4790+ me->arch.got_offset = me->core_size_rw;
4791+ me->core_size_rw += me->arch.got_size;
4792+ me->arch.plt_offset = me->core_size_rx;
4793+ me->core_size_rx += me->arch.plt_size;
4794 return 0;
4795 }
4796
4797@@ -242,7 +242,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4798 if (info->got_initialized == 0) {
4799 Elf_Addr *gotent;
4800
4801- gotent = me->module_core + me->arch.got_offset +
4802+ gotent = me->module_core_rw + me->arch.got_offset +
4803 info->got_offset;
4804 *gotent = val;
4805 info->got_initialized = 1;
4806@@ -266,7 +266,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4807 else if (r_type == R_390_GOTENT ||
4808 r_type == R_390_GOTPLTENT)
4809 *(unsigned int *) loc =
4810- (val + (Elf_Addr) me->module_core - loc) >> 1;
4811+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4812 else if (r_type == R_390_GOT64 ||
4813 r_type == R_390_GOTPLT64)
4814 *(unsigned long *) loc = val;
4815@@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4816 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4817 if (info->plt_initialized == 0) {
4818 unsigned int *ip;
4819- ip = me->module_core + me->arch.plt_offset +
4820+ ip = me->module_core_rx + me->arch.plt_offset +
4821 info->plt_offset;
4822 #ifndef CONFIG_64BIT
4823 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4824@@ -305,7 +305,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4825 val - loc + 0xffffUL < 0x1ffffeUL) ||
4826 (r_type == R_390_PLT32DBL &&
4827 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4828- val = (Elf_Addr) me->module_core +
4829+ val = (Elf_Addr) me->module_core_rx +
4830 me->arch.plt_offset +
4831 info->plt_offset;
4832 val += rela->r_addend - loc;
4833@@ -327,7 +327,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4834 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4835 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4836 val = val + rela->r_addend -
4837- ((Elf_Addr) me->module_core + me->arch.got_offset);
4838+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4839 if (r_type == R_390_GOTOFF16)
4840 *(unsigned short *) loc = val;
4841 else if (r_type == R_390_GOTOFF32)
4842@@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4843 break;
4844 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4845 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4846- val = (Elf_Addr) me->module_core + me->arch.got_offset +
4847+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4848 rela->r_addend - loc;
4849 if (r_type == R_390_GOTPC)
4850 *(unsigned int *) loc = val;
4851diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4852index 60055ce..ee4b252 100644
4853--- a/arch/s390/kernel/process.c
4854+++ b/arch/s390/kernel/process.c
4855@@ -316,39 +316,3 @@ unsigned long get_wchan(struct task_struct *p)
4856 }
4857 return 0;
4858 }
4859-
4860-unsigned long arch_align_stack(unsigned long sp)
4861-{
4862- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4863- sp -= get_random_int() & ~PAGE_MASK;
4864- return sp & ~0xf;
4865-}
4866-
4867-static inline unsigned long brk_rnd(void)
4868-{
4869- /* 8MB for 32bit, 1GB for 64bit */
4870- if (is_32bit_task())
4871- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4872- else
4873- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4874-}
4875-
4876-unsigned long arch_randomize_brk(struct mm_struct *mm)
4877-{
4878- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4879-
4880- if (ret < mm->brk)
4881- return mm->brk;
4882- return ret;
4883-}
4884-
4885-unsigned long randomize_et_dyn(unsigned long base)
4886-{
4887- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4888-
4889- if (!(current->flags & PF_RANDOMIZE))
4890- return base;
4891- if (ret < base)
4892- return base;
4893- return ret;
4894-}
4895diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4896index 2857c48..d047481 100644
4897--- a/arch/s390/mm/mmap.c
4898+++ b/arch/s390/mm/mmap.c
4899@@ -92,10 +92,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4900 */
4901 if (mmap_is_legacy()) {
4902 mm->mmap_base = TASK_UNMAPPED_BASE;
4903+
4904+#ifdef CONFIG_PAX_RANDMMAP
4905+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4906+ mm->mmap_base += mm->delta_mmap;
4907+#endif
4908+
4909 mm->get_unmapped_area = arch_get_unmapped_area;
4910 mm->unmap_area = arch_unmap_area;
4911 } else {
4912 mm->mmap_base = mmap_base();
4913+
4914+#ifdef CONFIG_PAX_RANDMMAP
4915+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4916+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4917+#endif
4918+
4919 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4920 mm->unmap_area = arch_unmap_area_topdown;
4921 }
4922@@ -166,10 +178,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4923 */
4924 if (mmap_is_legacy()) {
4925 mm->mmap_base = TASK_UNMAPPED_BASE;
4926+
4927+#ifdef CONFIG_PAX_RANDMMAP
4928+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4929+ mm->mmap_base += mm->delta_mmap;
4930+#endif
4931+
4932 mm->get_unmapped_area = s390_get_unmapped_area;
4933 mm->unmap_area = arch_unmap_area;
4934 } else {
4935 mm->mmap_base = mmap_base();
4936+
4937+#ifdef CONFIG_PAX_RANDMMAP
4938+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4939+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4940+#endif
4941+
4942 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4943 mm->unmap_area = arch_unmap_area_topdown;
4944 }
4945diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4946index ae3d59f..f65f075 100644
4947--- a/arch/score/include/asm/cache.h
4948+++ b/arch/score/include/asm/cache.h
4949@@ -1,7 +1,9 @@
4950 #ifndef _ASM_SCORE_CACHE_H
4951 #define _ASM_SCORE_CACHE_H
4952
4953+#include <linux/const.h>
4954+
4955 #define L1_CACHE_SHIFT 4
4956-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4957+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4958
4959 #endif /* _ASM_SCORE_CACHE_H */
4960diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
4961index f9f3cd5..58ff438 100644
4962--- a/arch/score/include/asm/exec.h
4963+++ b/arch/score/include/asm/exec.h
4964@@ -1,6 +1,6 @@
4965 #ifndef _ASM_SCORE_EXEC_H
4966 #define _ASM_SCORE_EXEC_H
4967
4968-extern unsigned long arch_align_stack(unsigned long sp);
4969+#define arch_align_stack(x) (x)
4970
4971 #endif /* _ASM_SCORE_EXEC_H */
4972diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4973index 2707023..1c2a3b7 100644
4974--- a/arch/score/kernel/process.c
4975+++ b/arch/score/kernel/process.c
4976@@ -159,8 +159,3 @@ unsigned long get_wchan(struct task_struct *task)
4977
4978 return task_pt_regs(task)->cp0_epc;
4979 }
4980-
4981-unsigned long arch_align_stack(unsigned long sp)
4982-{
4983- return sp;
4984-}
4985diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
4986index ef9e555..331bd29 100644
4987--- a/arch/sh/include/asm/cache.h
4988+++ b/arch/sh/include/asm/cache.h
4989@@ -9,10 +9,11 @@
4990 #define __ASM_SH_CACHE_H
4991 #ifdef __KERNEL__
4992
4993+#include <linux/const.h>
4994 #include <linux/init.h>
4995 #include <cpu/cache.h>
4996
4997-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4998+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4999
5000 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5001
5002diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
5003index afeb710..d1d1289 100644
5004--- a/arch/sh/mm/mmap.c
5005+++ b/arch/sh/mm/mmap.c
5006@@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5007 addr = PAGE_ALIGN(addr);
5008
5009 vma = find_vma(mm, addr);
5010- if (TASK_SIZE - len >= addr &&
5011- (!vma || addr + len <= vma->vm_start))
5012+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5013 return addr;
5014 }
5015
5016@@ -106,7 +105,7 @@ full_search:
5017 }
5018 return -ENOMEM;
5019 }
5020- if (likely(!vma || addr + len <= vma->vm_start)) {
5021+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5022 /*
5023 * Remember the place where we stopped the search:
5024 */
5025@@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5026 addr = PAGE_ALIGN(addr);
5027
5028 vma = find_vma(mm, addr);
5029- if (TASK_SIZE - len >= addr &&
5030- (!vma || addr + len <= vma->vm_start))
5031+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5032 return addr;
5033 }
5034
5035@@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5036 /* make sure it can fit in the remaining address space */
5037 if (likely(addr > len)) {
5038 vma = find_vma(mm, addr-len);
5039- if (!vma || addr <= vma->vm_start) {
5040+ if (check_heap_stack_gap(vma, addr - len, len)) {
5041 /* remember the address as a hint for next time */
5042 return (mm->free_area_cache = addr-len);
5043 }
5044@@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5045 if (unlikely(mm->mmap_base < len))
5046 goto bottomup;
5047
5048- addr = mm->mmap_base-len;
5049- if (do_colour_align)
5050- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5051+ addr = mm->mmap_base - len;
5052
5053 do {
5054+ if (do_colour_align)
5055+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5056 /*
5057 * Lookup failure means no vma is above this address,
5058 * else if new region fits below vma->vm_start,
5059 * return with success:
5060 */
5061 vma = find_vma(mm, addr);
5062- if (likely(!vma || addr+len <= vma->vm_start)) {
5063+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5064 /* remember the address as a hint for next time */
5065 return (mm->free_area_cache = addr);
5066 }
5067@@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5068 mm->cached_hole_size = vma->vm_start - addr;
5069
5070 /* try just below the current vma->vm_start */
5071- addr = vma->vm_start-len;
5072- if (do_colour_align)
5073- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5074- } while (likely(len < vma->vm_start));
5075+ addr = skip_heap_stack_gap(vma, len);
5076+ } while (!IS_ERR_VALUE(addr));
5077
5078 bottomup:
5079 /*
5080diff --git a/arch/sparc/Makefile b/arch/sparc/Makefile
5081index eddcfb3..b117d90 100644
5082--- a/arch/sparc/Makefile
5083+++ b/arch/sparc/Makefile
5084@@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc/oprofile/
5085 # Export what is needed by arch/sparc/boot/Makefile
5086 export VMLINUX_INIT VMLINUX_MAIN
5087 VMLINUX_INIT := $(head-y) $(init-y)
5088-VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
5089+VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
5090 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
5091 VMLINUX_MAIN += $(drivers-y) $(net-y)
5092
5093diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5094index ce35a1c..2e7b8f9 100644
5095--- a/arch/sparc/include/asm/atomic_64.h
5096+++ b/arch/sparc/include/asm/atomic_64.h
5097@@ -14,18 +14,40 @@
5098 #define ATOMIC64_INIT(i) { (i) }
5099
5100 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5101+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5102+{
5103+ return v->counter;
5104+}
5105 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5106+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5107+{
5108+ return v->counter;
5109+}
5110
5111 #define atomic_set(v, i) (((v)->counter) = i)
5112+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5113+{
5114+ v->counter = i;
5115+}
5116 #define atomic64_set(v, i) (((v)->counter) = i)
5117+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5118+{
5119+ v->counter = i;
5120+}
5121
5122 extern void atomic_add(int, atomic_t *);
5123+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5124 extern void atomic64_add(long, atomic64_t *);
5125+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5126 extern void atomic_sub(int, atomic_t *);
5127+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5128 extern void atomic64_sub(long, atomic64_t *);
5129+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5130
5131 extern int atomic_add_ret(int, atomic_t *);
5132+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5133 extern long atomic64_add_ret(long, atomic64_t *);
5134+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5135 extern int atomic_sub_ret(int, atomic_t *);
5136 extern long atomic64_sub_ret(long, atomic64_t *);
5137
5138@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5139 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5140
5141 #define atomic_inc_return(v) atomic_add_ret(1, v)
5142+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5143+{
5144+ return atomic_add_ret_unchecked(1, v);
5145+}
5146 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5147+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5148+{
5149+ return atomic64_add_ret_unchecked(1, v);
5150+}
5151
5152 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5153 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5154
5155 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5156+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5157+{
5158+ return atomic_add_ret_unchecked(i, v);
5159+}
5160 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5161+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5162+{
5163+ return atomic64_add_ret_unchecked(i, v);
5164+}
5165
5166 /*
5167 * atomic_inc_and_test - increment and test
5168@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5169 * other cases.
5170 */
5171 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5172+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5173+{
5174+ return atomic_inc_return_unchecked(v) == 0;
5175+}
5176 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5177
5178 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5179@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5180 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5181
5182 #define atomic_inc(v) atomic_add(1, v)
5183+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5184+{
5185+ atomic_add_unchecked(1, v);
5186+}
5187 #define atomic64_inc(v) atomic64_add(1, v)
5188+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5189+{
5190+ atomic64_add_unchecked(1, v);
5191+}
5192
5193 #define atomic_dec(v) atomic_sub(1, v)
5194+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5195+{
5196+ atomic_sub_unchecked(1, v);
5197+}
5198 #define atomic64_dec(v) atomic64_sub(1, v)
5199+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5200+{
5201+ atomic64_sub_unchecked(1, v);
5202+}
5203
5204 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5205 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5206
5207 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5208+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5209+{
5210+ return cmpxchg(&v->counter, old, new);
5211+}
5212 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5213+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5214+{
5215+ return xchg(&v->counter, new);
5216+}
5217
5218 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5219 {
5220- int c, old;
5221+ int c, old, new;
5222 c = atomic_read(v);
5223 for (;;) {
5224- if (unlikely(c == (u)))
5225+ if (unlikely(c == u))
5226 break;
5227- old = atomic_cmpxchg((v), c, c + (a));
5228+
5229+ asm volatile("addcc %2, %0, %0\n"
5230+
5231+#ifdef CONFIG_PAX_REFCOUNT
5232+ "tvs %%icc, 6\n"
5233+#endif
5234+
5235+ : "=r" (new)
5236+ : "0" (c), "ir" (a)
5237+ : "cc");
5238+
5239+ old = atomic_cmpxchg(v, c, new);
5240 if (likely(old == c))
5241 break;
5242 c = old;
5243@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5244 #define atomic64_cmpxchg(v, o, n) \
5245 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
5246 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
5247+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
5248+{
5249+ return xchg(&v->counter, new);
5250+}
5251
5252 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5253 {
5254- long c, old;
5255+ long c, old, new;
5256 c = atomic64_read(v);
5257 for (;;) {
5258- if (unlikely(c == (u)))
5259+ if (unlikely(c == u))
5260 break;
5261- old = atomic64_cmpxchg((v), c, c + (a));
5262+
5263+ asm volatile("addcc %2, %0, %0\n"
5264+
5265+#ifdef CONFIG_PAX_REFCOUNT
5266+ "tvs %%xcc, 6\n"
5267+#endif
5268+
5269+ : "=r" (new)
5270+ : "0" (c), "ir" (a)
5271+ : "cc");
5272+
5273+ old = atomic64_cmpxchg(v, c, new);
5274 if (likely(old == c))
5275 break;
5276 c = old;
5277 }
5278- return c != (u);
5279+ return c != u;
5280 }
5281
5282 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5283diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5284index 69358b5..9d0d492 100644
5285--- a/arch/sparc/include/asm/cache.h
5286+++ b/arch/sparc/include/asm/cache.h
5287@@ -7,10 +7,12 @@
5288 #ifndef _SPARC_CACHE_H
5289 #define _SPARC_CACHE_H
5290
5291+#include <linux/const.h>
5292+
5293 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5294
5295 #define L1_CACHE_SHIFT 5
5296-#define L1_CACHE_BYTES 32
5297+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5298
5299 #ifdef CONFIG_SPARC32
5300 #define SMP_CACHE_BYTES_SHIFT 5
5301diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5302index 4269ca6..e3da77f 100644
5303--- a/arch/sparc/include/asm/elf_32.h
5304+++ b/arch/sparc/include/asm/elf_32.h
5305@@ -114,6 +114,13 @@ typedef struct {
5306
5307 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5308
5309+#ifdef CONFIG_PAX_ASLR
5310+#define PAX_ELF_ET_DYN_BASE 0x10000UL
5311+
5312+#define PAX_DELTA_MMAP_LEN 16
5313+#define PAX_DELTA_STACK_LEN 16
5314+#endif
5315+
5316 /* This yields a mask that user programs can use to figure out what
5317 instruction set this cpu supports. This can NOT be done in userspace
5318 on Sparc. */
5319diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5320index 7df8b7f..4946269 100644
5321--- a/arch/sparc/include/asm/elf_64.h
5322+++ b/arch/sparc/include/asm/elf_64.h
5323@@ -180,6 +180,13 @@ typedef struct {
5324 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5325 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5326
5327+#ifdef CONFIG_PAX_ASLR
5328+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5329+
5330+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5331+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5332+#endif
5333+
5334 extern unsigned long sparc64_elf_hwcap;
5335 #define ELF_HWCAP sparc64_elf_hwcap
5336
5337diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5338index ca2b344..c6084f89 100644
5339--- a/arch/sparc/include/asm/pgalloc_32.h
5340+++ b/arch/sparc/include/asm/pgalloc_32.h
5341@@ -37,6 +37,7 @@ BTFIXUPDEF_CALL(void, free_pgd_fast, pgd_t *)
5342 BTFIXUPDEF_CALL(void, pgd_set, pgd_t *, pmd_t *)
5343 #define pgd_set(pgdp,pmdp) BTFIXUP_CALL(pgd_set)(pgdp,pmdp)
5344 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5345+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5346
5347 BTFIXUPDEF_CALL(pmd_t *, pmd_alloc_one, struct mm_struct *, unsigned long)
5348 #define pmd_alloc_one(mm, address) BTFIXUP_CALL(pmd_alloc_one)(mm, address)
5349diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5350index 40b2d7a..22a665b 100644
5351--- a/arch/sparc/include/asm/pgalloc_64.h
5352+++ b/arch/sparc/include/asm/pgalloc_64.h
5353@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5354 }
5355
5356 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5357+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5358
5359 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5360 {
5361diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5362index 3d71018..48a11c5 100644
5363--- a/arch/sparc/include/asm/pgtable_32.h
5364+++ b/arch/sparc/include/asm/pgtable_32.h
5365@@ -45,6 +45,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
5366 BTFIXUPDEF_INT(page_none)
5367 BTFIXUPDEF_INT(page_copy)
5368 BTFIXUPDEF_INT(page_readonly)
5369+
5370+#ifdef CONFIG_PAX_PAGEEXEC
5371+BTFIXUPDEF_INT(page_shared_noexec)
5372+BTFIXUPDEF_INT(page_copy_noexec)
5373+BTFIXUPDEF_INT(page_readonly_noexec)
5374+#endif
5375+
5376 BTFIXUPDEF_INT(page_kernel)
5377
5378 #define PMD_SHIFT SUN4C_PMD_SHIFT
5379@@ -66,6 +73,16 @@ extern pgprot_t PAGE_SHARED;
5380 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
5381 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
5382
5383+#ifdef CONFIG_PAX_PAGEEXEC
5384+extern pgprot_t PAGE_SHARED_NOEXEC;
5385+# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
5386+# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
5387+#else
5388+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5389+# define PAGE_COPY_NOEXEC PAGE_COPY
5390+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5391+#endif
5392+
5393 extern unsigned long page_kernel;
5394
5395 #ifdef MODULE
5396diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5397index f6ae2b2..b03ffc7 100644
5398--- a/arch/sparc/include/asm/pgtsrmmu.h
5399+++ b/arch/sparc/include/asm/pgtsrmmu.h
5400@@ -115,6 +115,13 @@
5401 SRMMU_EXEC | SRMMU_REF)
5402 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5403 SRMMU_EXEC | SRMMU_REF)
5404+
5405+#ifdef CONFIG_PAX_PAGEEXEC
5406+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5407+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5408+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5409+#endif
5410+
5411 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5412 SRMMU_DIRTY | SRMMU_REF)
5413
5414diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5415index 9689176..63c18ea 100644
5416--- a/arch/sparc/include/asm/spinlock_64.h
5417+++ b/arch/sparc/include/asm/spinlock_64.h
5418@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5419
5420 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5421
5422-static void inline arch_read_lock(arch_rwlock_t *lock)
5423+static inline void arch_read_lock(arch_rwlock_t *lock)
5424 {
5425 unsigned long tmp1, tmp2;
5426
5427 __asm__ __volatile__ (
5428 "1: ldsw [%2], %0\n"
5429 " brlz,pn %0, 2f\n"
5430-"4: add %0, 1, %1\n"
5431+"4: addcc %0, 1, %1\n"
5432+
5433+#ifdef CONFIG_PAX_REFCOUNT
5434+" tvs %%icc, 6\n"
5435+#endif
5436+
5437 " cas [%2], %0, %1\n"
5438 " cmp %0, %1\n"
5439 " bne,pn %%icc, 1b\n"
5440@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5441 " .previous"
5442 : "=&r" (tmp1), "=&r" (tmp2)
5443 : "r" (lock)
5444- : "memory");
5445+ : "memory", "cc");
5446 }
5447
5448-static int inline arch_read_trylock(arch_rwlock_t *lock)
5449+static inline int arch_read_trylock(arch_rwlock_t *lock)
5450 {
5451 int tmp1, tmp2;
5452
5453@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5454 "1: ldsw [%2], %0\n"
5455 " brlz,a,pn %0, 2f\n"
5456 " mov 0, %0\n"
5457-" add %0, 1, %1\n"
5458+" addcc %0, 1, %1\n"
5459+
5460+#ifdef CONFIG_PAX_REFCOUNT
5461+" tvs %%icc, 6\n"
5462+#endif
5463+
5464 " cas [%2], %0, %1\n"
5465 " cmp %0, %1\n"
5466 " bne,pn %%icc, 1b\n"
5467@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5468 return tmp1;
5469 }
5470
5471-static void inline arch_read_unlock(arch_rwlock_t *lock)
5472+static inline void arch_read_unlock(arch_rwlock_t *lock)
5473 {
5474 unsigned long tmp1, tmp2;
5475
5476 __asm__ __volatile__(
5477 "1: lduw [%2], %0\n"
5478-" sub %0, 1, %1\n"
5479+" subcc %0, 1, %1\n"
5480+
5481+#ifdef CONFIG_PAX_REFCOUNT
5482+" tvs %%icc, 6\n"
5483+#endif
5484+
5485 " cas [%2], %0, %1\n"
5486 " cmp %0, %1\n"
5487 " bne,pn %%xcc, 1b\n"
5488@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5489 : "memory");
5490 }
5491
5492-static void inline arch_write_lock(arch_rwlock_t *lock)
5493+static inline void arch_write_lock(arch_rwlock_t *lock)
5494 {
5495 unsigned long mask, tmp1, tmp2;
5496
5497@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5498 : "memory");
5499 }
5500
5501-static void inline arch_write_unlock(arch_rwlock_t *lock)
5502+static inline void arch_write_unlock(arch_rwlock_t *lock)
5503 {
5504 __asm__ __volatile__(
5505 " stw %%g0, [%0]"
5506@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5507 : "memory");
5508 }
5509
5510-static int inline arch_write_trylock(arch_rwlock_t *lock)
5511+static inline int arch_write_trylock(arch_rwlock_t *lock)
5512 {
5513 unsigned long mask, tmp1, tmp2, result;
5514
5515diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5516index c2a1080..21ed218 100644
5517--- a/arch/sparc/include/asm/thread_info_32.h
5518+++ b/arch/sparc/include/asm/thread_info_32.h
5519@@ -50,6 +50,8 @@ struct thread_info {
5520 unsigned long w_saved;
5521
5522 struct restart_block restart_block;
5523+
5524+ unsigned long lowest_stack;
5525 };
5526
5527 /*
5528diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5529index 01d057f..13a7d2f 100644
5530--- a/arch/sparc/include/asm/thread_info_64.h
5531+++ b/arch/sparc/include/asm/thread_info_64.h
5532@@ -63,6 +63,8 @@ struct thread_info {
5533 struct pt_regs *kern_una_regs;
5534 unsigned int kern_una_insn;
5535
5536+ unsigned long lowest_stack;
5537+
5538 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5539 };
5540
5541@@ -214,10 +216,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
5542 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
5543 /* flag bit 6 is available */
5544 #define TIF_32BIT 7 /* 32-bit binary */
5545-/* flag bit 8 is available */
5546+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
5547 #define TIF_SECCOMP 9 /* secure computing */
5548 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
5549 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
5550+
5551 /* NOTE: Thread flags >= 12 should be ones we have no interest
5552 * in using in assembly, else we can't use the mask as
5553 * an immediate value in instructions such as andcc.
5554@@ -236,12 +239,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
5555 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
5556 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5557 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
5558+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5559
5560 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
5561 _TIF_DO_NOTIFY_RESUME_MASK | \
5562 _TIF_NEED_RESCHED)
5563 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
5564
5565+#define _TIF_WORK_SYSCALL \
5566+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
5567+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
5568+
5569+
5570 /*
5571 * Thread-synchronous status.
5572 *
5573diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5574index e88fbe5..96b0ce5 100644
5575--- a/arch/sparc/include/asm/uaccess.h
5576+++ b/arch/sparc/include/asm/uaccess.h
5577@@ -1,5 +1,13 @@
5578 #ifndef ___ASM_SPARC_UACCESS_H
5579 #define ___ASM_SPARC_UACCESS_H
5580+
5581+#ifdef __KERNEL__
5582+#ifndef __ASSEMBLY__
5583+#include <linux/types.h>
5584+extern void check_object_size(const void *ptr, unsigned long n, bool to);
5585+#endif
5586+#endif
5587+
5588 #if defined(__sparc__) && defined(__arch64__)
5589 #include <asm/uaccess_64.h>
5590 #else
5591diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5592index 8303ac4..07f333d 100644
5593--- a/arch/sparc/include/asm/uaccess_32.h
5594+++ b/arch/sparc/include/asm/uaccess_32.h
5595@@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5596
5597 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5598 {
5599- if (n && __access_ok((unsigned long) to, n))
5600+ if ((long)n < 0)
5601+ return n;
5602+
5603+ if (n && __access_ok((unsigned long) to, n)) {
5604+ if (!__builtin_constant_p(n))
5605+ check_object_size(from, n, true);
5606 return __copy_user(to, (__force void __user *) from, n);
5607- else
5608+ } else
5609 return n;
5610 }
5611
5612 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5613 {
5614+ if ((long)n < 0)
5615+ return n;
5616+
5617+ if (!__builtin_constant_p(n))
5618+ check_object_size(from, n, true);
5619+
5620 return __copy_user(to, (__force void __user *) from, n);
5621 }
5622
5623 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5624 {
5625- if (n && __access_ok((unsigned long) from, n))
5626+ if ((long)n < 0)
5627+ return n;
5628+
5629+ if (n && __access_ok((unsigned long) from, n)) {
5630+ if (!__builtin_constant_p(n))
5631+ check_object_size(to, n, false);
5632 return __copy_user((__force void __user *) to, from, n);
5633- else
5634+ } else
5635 return n;
5636 }
5637
5638 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5639 {
5640+ if ((long)n < 0)
5641+ return n;
5642+
5643 return __copy_user((__force void __user *) to, from, n);
5644 }
5645
5646diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5647index a1091afb..380228e 100644
5648--- a/arch/sparc/include/asm/uaccess_64.h
5649+++ b/arch/sparc/include/asm/uaccess_64.h
5650@@ -10,6 +10,7 @@
5651 #include <linux/compiler.h>
5652 #include <linux/string.h>
5653 #include <linux/thread_info.h>
5654+#include <linux/kernel.h>
5655 #include <asm/asi.h>
5656 #include <asm/spitfire.h>
5657 #include <asm-generic/uaccess-unaligned.h>
5658@@ -212,8 +213,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5659 static inline unsigned long __must_check
5660 copy_from_user(void *to, const void __user *from, unsigned long size)
5661 {
5662- unsigned long ret = ___copy_from_user(to, from, size);
5663+ unsigned long ret;
5664
5665+ if ((long)size < 0 || size > INT_MAX)
5666+ return size;
5667+
5668+ if (!__builtin_constant_p(size))
5669+ check_object_size(to, size, false);
5670+
5671+ ret = ___copy_from_user(to, from, size);
5672 if (unlikely(ret))
5673 ret = copy_from_user_fixup(to, from, size);
5674
5675@@ -229,8 +237,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5676 static inline unsigned long __must_check
5677 copy_to_user(void __user *to, const void *from, unsigned long size)
5678 {
5679- unsigned long ret = ___copy_to_user(to, from, size);
5680+ unsigned long ret;
5681
5682+ if ((long)size < 0 || size > INT_MAX)
5683+ return size;
5684+
5685+ if (!__builtin_constant_p(size))
5686+ check_object_size(from, size, true);
5687+
5688+ ret = ___copy_to_user(to, from, size);
5689 if (unlikely(ret))
5690 ret = copy_to_user_fixup(to, from, size);
5691 return ret;
5692diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5693index cb85458..e063f17 100644
5694--- a/arch/sparc/kernel/Makefile
5695+++ b/arch/sparc/kernel/Makefile
5696@@ -3,7 +3,7 @@
5697 #
5698
5699 asflags-y := -ansi
5700-ccflags-y := -Werror
5701+#ccflags-y := -Werror
5702
5703 extra-y := head_$(BITS).o
5704 extra-y += init_task.o
5705diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5706index efa0754..74b03fe 100644
5707--- a/arch/sparc/kernel/process_32.c
5708+++ b/arch/sparc/kernel/process_32.c
5709@@ -200,7 +200,7 @@ void __show_backtrace(unsigned long fp)
5710 rw->ins[4], rw->ins[5],
5711 rw->ins[6],
5712 rw->ins[7]);
5713- printk("%pS\n", (void *) rw->ins[7]);
5714+ printk("%pA\n", (void *) rw->ins[7]);
5715 rw = (struct reg_window32 *) rw->ins[6];
5716 }
5717 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
5718@@ -267,14 +267,14 @@ void show_regs(struct pt_regs *r)
5719
5720 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5721 r->psr, r->pc, r->npc, r->y, print_tainted());
5722- printk("PC: <%pS>\n", (void *) r->pc);
5723+ printk("PC: <%pA>\n", (void *) r->pc);
5724 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5725 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5726 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5727 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5728 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5729 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5730- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5731+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5732
5733 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5734 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5735@@ -309,7 +309,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5736 rw = (struct reg_window32 *) fp;
5737 pc = rw->ins[7];
5738 printk("[%08lx : ", pc);
5739- printk("%pS ] ", (void *) pc);
5740+ printk("%pA ] ", (void *) pc);
5741 fp = rw->ins[6];
5742 } while (++count < 16);
5743 printk("\n");
5744diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5745index aff0c72..9067b39 100644
5746--- a/arch/sparc/kernel/process_64.c
5747+++ b/arch/sparc/kernel/process_64.c
5748@@ -179,14 +179,14 @@ static void show_regwindow(struct pt_regs *regs)
5749 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5750 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5751 if (regs->tstate & TSTATE_PRIV)
5752- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5753+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5754 }
5755
5756 void show_regs(struct pt_regs *regs)
5757 {
5758 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5759 regs->tpc, regs->tnpc, regs->y, print_tainted());
5760- printk("TPC: <%pS>\n", (void *) regs->tpc);
5761+ printk("TPC: <%pA>\n", (void *) regs->tpc);
5762 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5763 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5764 regs->u_regs[3]);
5765@@ -199,7 +199,7 @@ void show_regs(struct pt_regs *regs)
5766 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5767 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5768 regs->u_regs[15]);
5769- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5770+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5771 show_regwindow(regs);
5772 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5773 }
5774@@ -284,7 +284,7 @@ void arch_trigger_all_cpu_backtrace(void)
5775 ((tp && tp->task) ? tp->task->pid : -1));
5776
5777 if (gp->tstate & TSTATE_PRIV) {
5778- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5779+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5780 (void *) gp->tpc,
5781 (void *) gp->o7,
5782 (void *) gp->i7,
5783diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
5784index 6f97c07..b1300ec 100644
5785--- a/arch/sparc/kernel/ptrace_64.c
5786+++ b/arch/sparc/kernel/ptrace_64.c
5787@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
5788 return ret;
5789 }
5790
5791+#ifdef CONFIG_GRKERNSEC_SETXID
5792+extern void gr_delayed_cred_worker(void);
5793+#endif
5794+
5795 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5796 {
5797 int ret = 0;
5798@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5799 /* do the secure computing check first */
5800 secure_computing(regs->u_regs[UREG_G1]);
5801
5802+#ifdef CONFIG_GRKERNSEC_SETXID
5803+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5804+ gr_delayed_cred_worker();
5805+#endif
5806+
5807 if (test_thread_flag(TIF_SYSCALL_TRACE))
5808 ret = tracehook_report_syscall_entry(regs);
5809
5810@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5811
5812 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
5813 {
5814+#ifdef CONFIG_GRKERNSEC_SETXID
5815+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5816+ gr_delayed_cred_worker();
5817+#endif
5818+
5819 audit_syscall_exit(regs);
5820
5821 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5822diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5823index 42b282f..28ce9f2 100644
5824--- a/arch/sparc/kernel/sys_sparc_32.c
5825+++ b/arch/sparc/kernel/sys_sparc_32.c
5826@@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5827 if (ARCH_SUN4C && len > 0x20000000)
5828 return -ENOMEM;
5829 if (!addr)
5830- addr = TASK_UNMAPPED_BASE;
5831+ addr = current->mm->mmap_base;
5832
5833 if (flags & MAP_SHARED)
5834 addr = COLOUR_ALIGN(addr);
5835@@ -71,7 +71,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5836 }
5837 if (TASK_SIZE - PAGE_SIZE - len < addr)
5838 return -ENOMEM;
5839- if (!vmm || addr + len <= vmm->vm_start)
5840+ if (check_heap_stack_gap(vmm, addr, len))
5841 return addr;
5842 addr = vmm->vm_end;
5843 if (flags & MAP_SHARED)
5844diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5845index 3ee51f1..2ba4913 100644
5846--- a/arch/sparc/kernel/sys_sparc_64.c
5847+++ b/arch/sparc/kernel/sys_sparc_64.c
5848@@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5849 /* We do not accept a shared mapping if it would violate
5850 * cache aliasing constraints.
5851 */
5852- if ((flags & MAP_SHARED) &&
5853+ if ((filp || (flags & MAP_SHARED)) &&
5854 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5855 return -EINVAL;
5856 return addr;
5857@@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5858 if (filp || (flags & MAP_SHARED))
5859 do_color_align = 1;
5860
5861+#ifdef CONFIG_PAX_RANDMMAP
5862+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5863+#endif
5864+
5865 if (addr) {
5866 if (do_color_align)
5867 addr = COLOUR_ALIGN(addr, pgoff);
5868@@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5869 addr = PAGE_ALIGN(addr);
5870
5871 vma = find_vma(mm, addr);
5872- if (task_size - len >= addr &&
5873- (!vma || addr + len <= vma->vm_start))
5874+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5875 return addr;
5876 }
5877
5878 if (len > mm->cached_hole_size) {
5879- start_addr = addr = mm->free_area_cache;
5880+ start_addr = addr = mm->free_area_cache;
5881 } else {
5882- start_addr = addr = TASK_UNMAPPED_BASE;
5883+ start_addr = addr = mm->mmap_base;
5884 mm->cached_hole_size = 0;
5885 }
5886
5887@@ -174,14 +177,14 @@ full_search:
5888 vma = find_vma(mm, VA_EXCLUDE_END);
5889 }
5890 if (unlikely(task_size < addr)) {
5891- if (start_addr != TASK_UNMAPPED_BASE) {
5892- start_addr = addr = TASK_UNMAPPED_BASE;
5893+ if (start_addr != mm->mmap_base) {
5894+ start_addr = addr = mm->mmap_base;
5895 mm->cached_hole_size = 0;
5896 goto full_search;
5897 }
5898 return -ENOMEM;
5899 }
5900- if (likely(!vma || addr + len <= vma->vm_start)) {
5901+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5902 /*
5903 * Remember the place where we stopped the search:
5904 */
5905@@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5906 /* We do not accept a shared mapping if it would violate
5907 * cache aliasing constraints.
5908 */
5909- if ((flags & MAP_SHARED) &&
5910+ if ((filp || (flags & MAP_SHARED)) &&
5911 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5912 return -EINVAL;
5913 return addr;
5914@@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5915 addr = PAGE_ALIGN(addr);
5916
5917 vma = find_vma(mm, addr);
5918- if (task_size - len >= addr &&
5919- (!vma || addr + len <= vma->vm_start))
5920+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5921 return addr;
5922 }
5923
5924@@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5925 /* make sure it can fit in the remaining address space */
5926 if (likely(addr > len)) {
5927 vma = find_vma(mm, addr-len);
5928- if (!vma || addr <= vma->vm_start) {
5929+ if (check_heap_stack_gap(vma, addr - len, len)) {
5930 /* remember the address as a hint for next time */
5931 return (mm->free_area_cache = addr-len);
5932 }
5933@@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5934 if (unlikely(mm->mmap_base < len))
5935 goto bottomup;
5936
5937- addr = mm->mmap_base-len;
5938- if (do_color_align)
5939- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5940+ addr = mm->mmap_base - len;
5941
5942 do {
5943+ if (do_color_align)
5944+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5945 /*
5946 * Lookup failure means no vma is above this address,
5947 * else if new region fits below vma->vm_start,
5948 * return with success:
5949 */
5950 vma = find_vma(mm, addr);
5951- if (likely(!vma || addr+len <= vma->vm_start)) {
5952+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5953 /* remember the address as a hint for next time */
5954 return (mm->free_area_cache = addr);
5955 }
5956@@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5957 mm->cached_hole_size = vma->vm_start - addr;
5958
5959 /* try just below the current vma->vm_start */
5960- addr = vma->vm_start-len;
5961- if (do_color_align)
5962- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5963- } while (likely(len < vma->vm_start));
5964+ addr = skip_heap_stack_gap(vma, len);
5965+ } while (!IS_ERR_VALUE(addr));
5966
5967 bottomup:
5968 /*
5969@@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5970 gap == RLIM_INFINITY ||
5971 sysctl_legacy_va_layout) {
5972 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5973+
5974+#ifdef CONFIG_PAX_RANDMMAP
5975+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5976+ mm->mmap_base += mm->delta_mmap;
5977+#endif
5978+
5979 mm->get_unmapped_area = arch_get_unmapped_area;
5980 mm->unmap_area = arch_unmap_area;
5981 } else {
5982@@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5983 gap = (task_size / 6 * 5);
5984
5985 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5986+
5987+#ifdef CONFIG_PAX_RANDMMAP
5988+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5989+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5990+#endif
5991+
5992 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5993 mm->unmap_area = arch_unmap_area_topdown;
5994 }
5995diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
5996index 1d7e274..b39c527 100644
5997--- a/arch/sparc/kernel/syscalls.S
5998+++ b/arch/sparc/kernel/syscalls.S
5999@@ -62,7 +62,7 @@ sys32_rt_sigreturn:
6000 #endif
6001 .align 32
6002 1: ldx [%g6 + TI_FLAGS], %l5
6003- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6004+ andcc %l5, _TIF_WORK_SYSCALL, %g0
6005 be,pt %icc, rtrap
6006 nop
6007 call syscall_trace_leave
6008@@ -179,7 +179,7 @@ linux_sparc_syscall32:
6009
6010 srl %i5, 0, %o5 ! IEU1
6011 srl %i2, 0, %o2 ! IEU0 Group
6012- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6013+ andcc %l0, _TIF_WORK_SYSCALL, %g0
6014 bne,pn %icc, linux_syscall_trace32 ! CTI
6015 mov %i0, %l5 ! IEU1
6016 call %l7 ! CTI Group brk forced
6017@@ -202,7 +202,7 @@ linux_sparc_syscall:
6018
6019 mov %i3, %o3 ! IEU1
6020 mov %i4, %o4 ! IEU0 Group
6021- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6022+ andcc %l0, _TIF_WORK_SYSCALL, %g0
6023 bne,pn %icc, linux_syscall_trace ! CTI Group
6024 mov %i0, %l5 ! IEU0
6025 2: call %l7 ! CTI Group brk forced
6026@@ -226,7 +226,7 @@ ret_sys_call:
6027
6028 cmp %o0, -ERESTART_RESTARTBLOCK
6029 bgeu,pn %xcc, 1f
6030- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6031+ andcc %l0, _TIF_WORK_SYSCALL, %l6
6032 80:
6033 /* System call success, clear Carry condition code. */
6034 andn %g3, %g2, %g3
6035@@ -241,7 +241,7 @@ ret_sys_call:
6036 /* System call failure, set Carry condition code.
6037 * Also, get abs(errno) to return to the process.
6038 */
6039- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6040+ andcc %l0, _TIF_WORK_SYSCALL, %l6
6041 sub %g0, %o0, %o0
6042 or %g3, %g2, %g3
6043 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
6044diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6045index d2de213..6b22bc3 100644
6046--- a/arch/sparc/kernel/traps_32.c
6047+++ b/arch/sparc/kernel/traps_32.c
6048@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
6049 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6050 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6051
6052+extern void gr_handle_kernel_exploit(void);
6053+
6054 void die_if_kernel(char *str, struct pt_regs *regs)
6055 {
6056 static int die_counter;
6057@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6058 count++ < 30 &&
6059 (((unsigned long) rw) >= PAGE_OFFSET) &&
6060 !(((unsigned long) rw) & 0x7)) {
6061- printk("Caller[%08lx]: %pS\n", rw->ins[7],
6062+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
6063 (void *) rw->ins[7]);
6064 rw = (struct reg_window32 *)rw->ins[6];
6065 }
6066 }
6067 printk("Instruction DUMP:");
6068 instruction_dump ((unsigned long *) regs->pc);
6069- if(regs->psr & PSR_PS)
6070+ if(regs->psr & PSR_PS) {
6071+ gr_handle_kernel_exploit();
6072 do_exit(SIGKILL);
6073+ }
6074 do_exit(SIGSEGV);
6075 }
6076
6077diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6078index c72fdf5..743a344 100644
6079--- a/arch/sparc/kernel/traps_64.c
6080+++ b/arch/sparc/kernel/traps_64.c
6081@@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6082 i + 1,
6083 p->trapstack[i].tstate, p->trapstack[i].tpc,
6084 p->trapstack[i].tnpc, p->trapstack[i].tt);
6085- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6086+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6087 }
6088 }
6089
6090@@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6091
6092 lvl -= 0x100;
6093 if (regs->tstate & TSTATE_PRIV) {
6094+
6095+#ifdef CONFIG_PAX_REFCOUNT
6096+ if (lvl == 6)
6097+ pax_report_refcount_overflow(regs);
6098+#endif
6099+
6100 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6101 die_if_kernel(buffer, regs);
6102 }
6103@@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6104 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6105 {
6106 char buffer[32];
6107-
6108+
6109 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6110 0, lvl, SIGTRAP) == NOTIFY_STOP)
6111 return;
6112
6113+#ifdef CONFIG_PAX_REFCOUNT
6114+ if (lvl == 6)
6115+ pax_report_refcount_overflow(regs);
6116+#endif
6117+
6118 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6119
6120 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6121@@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6122 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6123 printk("%s" "ERROR(%d): ",
6124 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6125- printk("TPC<%pS>\n", (void *) regs->tpc);
6126+ printk("TPC<%pA>\n", (void *) regs->tpc);
6127 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6128 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6129 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6130@@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6131 smp_processor_id(),
6132 (type & 0x1) ? 'I' : 'D',
6133 regs->tpc);
6134- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6135+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6136 panic("Irrecoverable Cheetah+ parity error.");
6137 }
6138
6139@@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6140 smp_processor_id(),
6141 (type & 0x1) ? 'I' : 'D',
6142 regs->tpc);
6143- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6144+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6145 }
6146
6147 struct sun4v_error_entry {
6148@@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6149
6150 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6151 regs->tpc, tl);
6152- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6153+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6154 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6155- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6156+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6157 (void *) regs->u_regs[UREG_I7]);
6158 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6159 "pte[%lx] error[%lx]\n",
6160@@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6161
6162 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6163 regs->tpc, tl);
6164- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6165+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6166 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6167- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6168+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6169 (void *) regs->u_regs[UREG_I7]);
6170 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6171 "pte[%lx] error[%lx]\n",
6172@@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6173 fp = (unsigned long)sf->fp + STACK_BIAS;
6174 }
6175
6176- printk(" [%016lx] %pS\n", pc, (void *) pc);
6177+ printk(" [%016lx] %pA\n", pc, (void *) pc);
6178 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6179 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6180 int index = tsk->curr_ret_stack;
6181 if (tsk->ret_stack && index >= graph) {
6182 pc = tsk->ret_stack[index - graph].ret;
6183- printk(" [%016lx] %pS\n", pc, (void *) pc);
6184+ printk(" [%016lx] %pA\n", pc, (void *) pc);
6185 graph++;
6186 }
6187 }
6188@@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6189 return (struct reg_window *) (fp + STACK_BIAS);
6190 }
6191
6192+extern void gr_handle_kernel_exploit(void);
6193+
6194 void die_if_kernel(char *str, struct pt_regs *regs)
6195 {
6196 static int die_counter;
6197@@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6198 while (rw &&
6199 count++ < 30 &&
6200 kstack_valid(tp, (unsigned long) rw)) {
6201- printk("Caller[%016lx]: %pS\n", rw->ins[7],
6202+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
6203 (void *) rw->ins[7]);
6204
6205 rw = kernel_stack_up(rw);
6206@@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6207 }
6208 user_instruction_dump ((unsigned int __user *) regs->tpc);
6209 }
6210- if (regs->tstate & TSTATE_PRIV)
6211+ if (regs->tstate & TSTATE_PRIV) {
6212+ gr_handle_kernel_exploit();
6213 do_exit(SIGKILL);
6214+ }
6215 do_exit(SIGSEGV);
6216 }
6217 EXPORT_SYMBOL(die_if_kernel);
6218diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6219index dae85bc..af1e19d 100644
6220--- a/arch/sparc/kernel/unaligned_64.c
6221+++ b/arch/sparc/kernel/unaligned_64.c
6222@@ -279,7 +279,7 @@ static void log_unaligned(struct pt_regs *regs)
6223 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6224
6225 if (__ratelimit(&ratelimit)) {
6226- printk("Kernel unaligned access at TPC[%lx] %pS\n",
6227+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
6228 regs->tpc, (void *) regs->tpc);
6229 }
6230 }
6231diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6232index a3fc437..fea9957 100644
6233--- a/arch/sparc/lib/Makefile
6234+++ b/arch/sparc/lib/Makefile
6235@@ -2,7 +2,7 @@
6236 #
6237
6238 asflags-y := -ansi -DST_DIV0=0x02
6239-ccflags-y := -Werror
6240+#ccflags-y := -Werror
6241
6242 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
6243 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6244diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6245index 59186e0..f747d7a 100644
6246--- a/arch/sparc/lib/atomic_64.S
6247+++ b/arch/sparc/lib/atomic_64.S
6248@@ -18,7 +18,12 @@
6249 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
6250 BACKOFF_SETUP(%o2)
6251 1: lduw [%o1], %g1
6252- add %g1, %o0, %g7
6253+ addcc %g1, %o0, %g7
6254+
6255+#ifdef CONFIG_PAX_REFCOUNT
6256+ tvs %icc, 6
6257+#endif
6258+
6259 cas [%o1], %g1, %g7
6260 cmp %g1, %g7
6261 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6262@@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
6263 2: BACKOFF_SPIN(%o2, %o3, 1b)
6264 .size atomic_add, .-atomic_add
6265
6266+ .globl atomic_add_unchecked
6267+ .type atomic_add_unchecked,#function
6268+atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6269+ BACKOFF_SETUP(%o2)
6270+1: lduw [%o1], %g1
6271+ add %g1, %o0, %g7
6272+ cas [%o1], %g1, %g7
6273+ cmp %g1, %g7
6274+ bne,pn %icc, 2f
6275+ nop
6276+ retl
6277+ nop
6278+2: BACKOFF_SPIN(%o2, %o3, 1b)
6279+ .size atomic_add_unchecked, .-atomic_add_unchecked
6280+
6281 .globl atomic_sub
6282 .type atomic_sub,#function
6283 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6284 BACKOFF_SETUP(%o2)
6285 1: lduw [%o1], %g1
6286- sub %g1, %o0, %g7
6287+ subcc %g1, %o0, %g7
6288+
6289+#ifdef CONFIG_PAX_REFCOUNT
6290+ tvs %icc, 6
6291+#endif
6292+
6293 cas [%o1], %g1, %g7
6294 cmp %g1, %g7
6295 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6296@@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6297 2: BACKOFF_SPIN(%o2, %o3, 1b)
6298 .size atomic_sub, .-atomic_sub
6299
6300+ .globl atomic_sub_unchecked
6301+ .type atomic_sub_unchecked,#function
6302+atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
6303+ BACKOFF_SETUP(%o2)
6304+1: lduw [%o1], %g1
6305+ sub %g1, %o0, %g7
6306+ cas [%o1], %g1, %g7
6307+ cmp %g1, %g7
6308+ bne,pn %icc, 2f
6309+ nop
6310+ retl
6311+ nop
6312+2: BACKOFF_SPIN(%o2, %o3, 1b)
6313+ .size atomic_sub_unchecked, .-atomic_sub_unchecked
6314+
6315 .globl atomic_add_ret
6316 .type atomic_add_ret,#function
6317 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6318 BACKOFF_SETUP(%o2)
6319 1: lduw [%o1], %g1
6320- add %g1, %o0, %g7
6321+ addcc %g1, %o0, %g7
6322+
6323+#ifdef CONFIG_PAX_REFCOUNT
6324+ tvs %icc, 6
6325+#endif
6326+
6327 cas [%o1], %g1, %g7
6328 cmp %g1, %g7
6329 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6330@@ -58,12 +103,33 @@ atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6331 2: BACKOFF_SPIN(%o2, %o3, 1b)
6332 .size atomic_add_ret, .-atomic_add_ret
6333
6334+ .globl atomic_add_ret_unchecked
6335+ .type atomic_add_ret_unchecked,#function
6336+atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6337+ BACKOFF_SETUP(%o2)
6338+1: lduw [%o1], %g1
6339+ addcc %g1, %o0, %g7
6340+ cas [%o1], %g1, %g7
6341+ cmp %g1, %g7
6342+ bne,pn %icc, 2f
6343+ add %g7, %o0, %g7
6344+ sra %g7, 0, %o0
6345+ retl
6346+ nop
6347+2: BACKOFF_SPIN(%o2, %o3, 1b)
6348+ .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
6349+
6350 .globl atomic_sub_ret
6351 .type atomic_sub_ret,#function
6352 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6353 BACKOFF_SETUP(%o2)
6354 1: lduw [%o1], %g1
6355- sub %g1, %o0, %g7
6356+ subcc %g1, %o0, %g7
6357+
6358+#ifdef CONFIG_PAX_REFCOUNT
6359+ tvs %icc, 6
6360+#endif
6361+
6362 cas [%o1], %g1, %g7
6363 cmp %g1, %g7
6364 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6365@@ -78,7 +144,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6366 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
6367 BACKOFF_SETUP(%o2)
6368 1: ldx [%o1], %g1
6369- add %g1, %o0, %g7
6370+ addcc %g1, %o0, %g7
6371+
6372+#ifdef CONFIG_PAX_REFCOUNT
6373+ tvs %xcc, 6
6374+#endif
6375+
6376 casx [%o1], %g1, %g7
6377 cmp %g1, %g7
6378 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6379@@ -88,12 +159,32 @@ atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
6380 2: BACKOFF_SPIN(%o2, %o3, 1b)
6381 .size atomic64_add, .-atomic64_add
6382
6383+ .globl atomic64_add_unchecked
6384+ .type atomic64_add_unchecked,#function
6385+atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6386+ BACKOFF_SETUP(%o2)
6387+1: ldx [%o1], %g1
6388+ addcc %g1, %o0, %g7
6389+ casx [%o1], %g1, %g7
6390+ cmp %g1, %g7
6391+ bne,pn %xcc, 2f
6392+ nop
6393+ retl
6394+ nop
6395+2: BACKOFF_SPIN(%o2, %o3, 1b)
6396+ .size atomic64_add_unchecked, .-atomic64_add_unchecked
6397+
6398 .globl atomic64_sub
6399 .type atomic64_sub,#function
6400 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6401 BACKOFF_SETUP(%o2)
6402 1: ldx [%o1], %g1
6403- sub %g1, %o0, %g7
6404+ subcc %g1, %o0, %g7
6405+
6406+#ifdef CONFIG_PAX_REFCOUNT
6407+ tvs %xcc, 6
6408+#endif
6409+
6410 casx [%o1], %g1, %g7
6411 cmp %g1, %g7
6412 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6413@@ -103,12 +194,32 @@ atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6414 2: BACKOFF_SPIN(%o2, %o3, 1b)
6415 .size atomic64_sub, .-atomic64_sub
6416
6417+ .globl atomic64_sub_unchecked
6418+ .type atomic64_sub_unchecked,#function
6419+atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
6420+ BACKOFF_SETUP(%o2)
6421+1: ldx [%o1], %g1
6422+ subcc %g1, %o0, %g7
6423+ casx [%o1], %g1, %g7
6424+ cmp %g1, %g7
6425+ bne,pn %xcc, 2f
6426+ nop
6427+ retl
6428+ nop
6429+2: BACKOFF_SPIN(%o2, %o3, 1b)
6430+ .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
6431+
6432 .globl atomic64_add_ret
6433 .type atomic64_add_ret,#function
6434 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6435 BACKOFF_SETUP(%o2)
6436 1: ldx [%o1], %g1
6437- add %g1, %o0, %g7
6438+ addcc %g1, %o0, %g7
6439+
6440+#ifdef CONFIG_PAX_REFCOUNT
6441+ tvs %xcc, 6
6442+#endif
6443+
6444 casx [%o1], %g1, %g7
6445 cmp %g1, %g7
6446 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6447@@ -118,12 +229,33 @@ atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6448 2: BACKOFF_SPIN(%o2, %o3, 1b)
6449 .size atomic64_add_ret, .-atomic64_add_ret
6450
6451+ .globl atomic64_add_ret_unchecked
6452+ .type atomic64_add_ret_unchecked,#function
6453+atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6454+ BACKOFF_SETUP(%o2)
6455+1: ldx [%o1], %g1
6456+ addcc %g1, %o0, %g7
6457+ casx [%o1], %g1, %g7
6458+ cmp %g1, %g7
6459+ bne,pn %xcc, 2f
6460+ add %g7, %o0, %g7
6461+ mov %g7, %o0
6462+ retl
6463+ nop
6464+2: BACKOFF_SPIN(%o2, %o3, 1b)
6465+ .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
6466+
6467 .globl atomic64_sub_ret
6468 .type atomic64_sub_ret,#function
6469 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6470 BACKOFF_SETUP(%o2)
6471 1: ldx [%o1], %g1
6472- sub %g1, %o0, %g7
6473+ subcc %g1, %o0, %g7
6474+
6475+#ifdef CONFIG_PAX_REFCOUNT
6476+ tvs %xcc, 6
6477+#endif
6478+
6479 casx [%o1], %g1, %g7
6480 cmp %g1, %g7
6481 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6482diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6483index f73c224..662af10 100644
6484--- a/arch/sparc/lib/ksyms.c
6485+++ b/arch/sparc/lib/ksyms.c
6486@@ -136,12 +136,18 @@ EXPORT_SYMBOL(__downgrade_write);
6487
6488 /* Atomic counter implementation. */
6489 EXPORT_SYMBOL(atomic_add);
6490+EXPORT_SYMBOL(atomic_add_unchecked);
6491 EXPORT_SYMBOL(atomic_add_ret);
6492+EXPORT_SYMBOL(atomic_add_ret_unchecked);
6493 EXPORT_SYMBOL(atomic_sub);
6494+EXPORT_SYMBOL(atomic_sub_unchecked);
6495 EXPORT_SYMBOL(atomic_sub_ret);
6496 EXPORT_SYMBOL(atomic64_add);
6497+EXPORT_SYMBOL(atomic64_add_unchecked);
6498 EXPORT_SYMBOL(atomic64_add_ret);
6499+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6500 EXPORT_SYMBOL(atomic64_sub);
6501+EXPORT_SYMBOL(atomic64_sub_unchecked);
6502 EXPORT_SYMBOL(atomic64_sub_ret);
6503
6504 /* Atomic bit operations. */
6505diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6506index 301421c..e2535d1 100644
6507--- a/arch/sparc/mm/Makefile
6508+++ b/arch/sparc/mm/Makefile
6509@@ -2,7 +2,7 @@
6510 #
6511
6512 asflags-y := -ansi
6513-ccflags-y := -Werror
6514+#ccflags-y := -Werror
6515
6516 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6517 obj-y += fault_$(BITS).o
6518diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6519index df3155a..eb708b8 100644
6520--- a/arch/sparc/mm/fault_32.c
6521+++ b/arch/sparc/mm/fault_32.c
6522@@ -21,6 +21,9 @@
6523 #include <linux/perf_event.h>
6524 #include <linux/interrupt.h>
6525 #include <linux/kdebug.h>
6526+#include <linux/slab.h>
6527+#include <linux/pagemap.h>
6528+#include <linux/compiler.h>
6529
6530 #include <asm/page.h>
6531 #include <asm/pgtable.h>
6532@@ -207,6 +210,268 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6533 return safe_compute_effective_address(regs, insn);
6534 }
6535
6536+#ifdef CONFIG_PAX_PAGEEXEC
6537+#ifdef CONFIG_PAX_DLRESOLVE
6538+static void pax_emuplt_close(struct vm_area_struct *vma)
6539+{
6540+ vma->vm_mm->call_dl_resolve = 0UL;
6541+}
6542+
6543+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6544+{
6545+ unsigned int *kaddr;
6546+
6547+ vmf->page = alloc_page(GFP_HIGHUSER);
6548+ if (!vmf->page)
6549+ return VM_FAULT_OOM;
6550+
6551+ kaddr = kmap(vmf->page);
6552+ memset(kaddr, 0, PAGE_SIZE);
6553+ kaddr[0] = 0x9DE3BFA8U; /* save */
6554+ flush_dcache_page(vmf->page);
6555+ kunmap(vmf->page);
6556+ return VM_FAULT_MAJOR;
6557+}
6558+
6559+static const struct vm_operations_struct pax_vm_ops = {
6560+ .close = pax_emuplt_close,
6561+ .fault = pax_emuplt_fault
6562+};
6563+
6564+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6565+{
6566+ int ret;
6567+
6568+ INIT_LIST_HEAD(&vma->anon_vma_chain);
6569+ vma->vm_mm = current->mm;
6570+ vma->vm_start = addr;
6571+ vma->vm_end = addr + PAGE_SIZE;
6572+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6573+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6574+ vma->vm_ops = &pax_vm_ops;
6575+
6576+ ret = insert_vm_struct(current->mm, vma);
6577+ if (ret)
6578+ return ret;
6579+
6580+ ++current->mm->total_vm;
6581+ return 0;
6582+}
6583+#endif
6584+
6585+/*
6586+ * PaX: decide what to do with offenders (regs->pc = fault address)
6587+ *
6588+ * returns 1 when task should be killed
6589+ * 2 when patched PLT trampoline was detected
6590+ * 3 when unpatched PLT trampoline was detected
6591+ */
6592+static int pax_handle_fetch_fault(struct pt_regs *regs)
6593+{
6594+
6595+#ifdef CONFIG_PAX_EMUPLT
6596+ int err;
6597+
6598+ do { /* PaX: patched PLT emulation #1 */
6599+ unsigned int sethi1, sethi2, jmpl;
6600+
6601+ err = get_user(sethi1, (unsigned int *)regs->pc);
6602+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6603+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6604+
6605+ if (err)
6606+ break;
6607+
6608+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6609+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6610+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6611+ {
6612+ unsigned int addr;
6613+
6614+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6615+ addr = regs->u_regs[UREG_G1];
6616+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6617+ regs->pc = addr;
6618+ regs->npc = addr+4;
6619+ return 2;
6620+ }
6621+ } while (0);
6622+
6623+ { /* PaX: patched PLT emulation #2 */
6624+ unsigned int ba;
6625+
6626+ err = get_user(ba, (unsigned int *)regs->pc);
6627+
6628+ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6629+ unsigned int addr;
6630+
6631+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6632+ regs->pc = addr;
6633+ regs->npc = addr+4;
6634+ return 2;
6635+ }
6636+ }
6637+
6638+ do { /* PaX: patched PLT emulation #3 */
6639+ unsigned int sethi, jmpl, nop;
6640+
6641+ err = get_user(sethi, (unsigned int *)regs->pc);
6642+ err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
6643+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
6644+
6645+ if (err)
6646+ break;
6647+
6648+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6649+ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6650+ nop == 0x01000000U)
6651+ {
6652+ unsigned int addr;
6653+
6654+ addr = (sethi & 0x003FFFFFU) << 10;
6655+ regs->u_regs[UREG_G1] = addr;
6656+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6657+ regs->pc = addr;
6658+ regs->npc = addr+4;
6659+ return 2;
6660+ }
6661+ } while (0);
6662+
6663+ do { /* PaX: unpatched PLT emulation step 1 */
6664+ unsigned int sethi, ba, nop;
6665+
6666+ err = get_user(sethi, (unsigned int *)regs->pc);
6667+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
6668+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
6669+
6670+ if (err)
6671+ break;
6672+
6673+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6674+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6675+ nop == 0x01000000U)
6676+ {
6677+ unsigned int addr, save, call;
6678+
6679+ if ((ba & 0xFFC00000U) == 0x30800000U)
6680+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6681+ else
6682+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6683+
6684+ err = get_user(save, (unsigned int *)addr);
6685+ err |= get_user(call, (unsigned int *)(addr+4));
6686+ err |= get_user(nop, (unsigned int *)(addr+8));
6687+ if (err)
6688+ break;
6689+
6690+#ifdef CONFIG_PAX_DLRESOLVE
6691+ if (save == 0x9DE3BFA8U &&
6692+ (call & 0xC0000000U) == 0x40000000U &&
6693+ nop == 0x01000000U)
6694+ {
6695+ struct vm_area_struct *vma;
6696+ unsigned long call_dl_resolve;
6697+
6698+ down_read(&current->mm->mmap_sem);
6699+ call_dl_resolve = current->mm->call_dl_resolve;
6700+ up_read(&current->mm->mmap_sem);
6701+ if (likely(call_dl_resolve))
6702+ goto emulate;
6703+
6704+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6705+
6706+ down_write(&current->mm->mmap_sem);
6707+ if (current->mm->call_dl_resolve) {
6708+ call_dl_resolve = current->mm->call_dl_resolve;
6709+ up_write(&current->mm->mmap_sem);
6710+ if (vma)
6711+ kmem_cache_free(vm_area_cachep, vma);
6712+ goto emulate;
6713+ }
6714+
6715+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6716+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6717+ up_write(&current->mm->mmap_sem);
6718+ if (vma)
6719+ kmem_cache_free(vm_area_cachep, vma);
6720+ return 1;
6721+ }
6722+
6723+ if (pax_insert_vma(vma, call_dl_resolve)) {
6724+ up_write(&current->mm->mmap_sem);
6725+ kmem_cache_free(vm_area_cachep, vma);
6726+ return 1;
6727+ }
6728+
6729+ current->mm->call_dl_resolve = call_dl_resolve;
6730+ up_write(&current->mm->mmap_sem);
6731+
6732+emulate:
6733+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6734+ regs->pc = call_dl_resolve;
6735+ regs->npc = addr+4;
6736+ return 3;
6737+ }
6738+#endif
6739+
6740+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6741+ if ((save & 0xFFC00000U) == 0x05000000U &&
6742+ (call & 0xFFFFE000U) == 0x85C0A000U &&
6743+ nop == 0x01000000U)
6744+ {
6745+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6746+ regs->u_regs[UREG_G2] = addr + 4;
6747+ addr = (save & 0x003FFFFFU) << 10;
6748+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6749+ regs->pc = addr;
6750+ regs->npc = addr+4;
6751+ return 3;
6752+ }
6753+ }
6754+ } while (0);
6755+
6756+ do { /* PaX: unpatched PLT emulation step 2 */
6757+ unsigned int save, call, nop;
6758+
6759+ err = get_user(save, (unsigned int *)(regs->pc-4));
6760+ err |= get_user(call, (unsigned int *)regs->pc);
6761+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
6762+ if (err)
6763+ break;
6764+
6765+ if (save == 0x9DE3BFA8U &&
6766+ (call & 0xC0000000U) == 0x40000000U &&
6767+ nop == 0x01000000U)
6768+ {
6769+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6770+
6771+ regs->u_regs[UREG_RETPC] = regs->pc;
6772+ regs->pc = dl_resolve;
6773+ regs->npc = dl_resolve+4;
6774+ return 3;
6775+ }
6776+ } while (0);
6777+#endif
6778+
6779+ return 1;
6780+}
6781+
6782+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6783+{
6784+ unsigned long i;
6785+
6786+ printk(KERN_ERR "PAX: bytes at PC: ");
6787+ for (i = 0; i < 8; i++) {
6788+ unsigned int c;
6789+ if (get_user(c, (unsigned int *)pc+i))
6790+ printk(KERN_CONT "???????? ");
6791+ else
6792+ printk(KERN_CONT "%08x ", c);
6793+ }
6794+ printk("\n");
6795+}
6796+#endif
6797+
6798 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6799 int text_fault)
6800 {
6801@@ -282,6 +547,24 @@ good_area:
6802 if(!(vma->vm_flags & VM_WRITE))
6803 goto bad_area;
6804 } else {
6805+
6806+#ifdef CONFIG_PAX_PAGEEXEC
6807+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6808+ up_read(&mm->mmap_sem);
6809+ switch (pax_handle_fetch_fault(regs)) {
6810+
6811+#ifdef CONFIG_PAX_EMUPLT
6812+ case 2:
6813+ case 3:
6814+ return;
6815+#endif
6816+
6817+ }
6818+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6819+ do_group_exit(SIGKILL);
6820+ }
6821+#endif
6822+
6823 /* Allow reads even for write-only mappings */
6824 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
6825 goto bad_area;
6826diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6827index 1fe0429..aee2e87 100644
6828--- a/arch/sparc/mm/fault_64.c
6829+++ b/arch/sparc/mm/fault_64.c
6830@@ -21,6 +21,9 @@
6831 #include <linux/kprobes.h>
6832 #include <linux/kdebug.h>
6833 #include <linux/percpu.h>
6834+#include <linux/slab.h>
6835+#include <linux/pagemap.h>
6836+#include <linux/compiler.h>
6837
6838 #include <asm/page.h>
6839 #include <asm/pgtable.h>
6840@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6841 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6842 regs->tpc);
6843 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6844- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6845+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6846 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6847 dump_stack();
6848 unhandled_fault(regs->tpc, current, regs);
6849@@ -272,6 +275,457 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6850 show_regs(regs);
6851 }
6852
6853+#ifdef CONFIG_PAX_PAGEEXEC
6854+#ifdef CONFIG_PAX_DLRESOLVE
6855+static void pax_emuplt_close(struct vm_area_struct *vma)
6856+{
6857+ vma->vm_mm->call_dl_resolve = 0UL;
6858+}
6859+
6860+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6861+{
6862+ unsigned int *kaddr;
6863+
6864+ vmf->page = alloc_page(GFP_HIGHUSER);
6865+ if (!vmf->page)
6866+ return VM_FAULT_OOM;
6867+
6868+ kaddr = kmap(vmf->page);
6869+ memset(kaddr, 0, PAGE_SIZE);
6870+ kaddr[0] = 0x9DE3BFA8U; /* save */
6871+ flush_dcache_page(vmf->page);
6872+ kunmap(vmf->page);
6873+ return VM_FAULT_MAJOR;
6874+}
6875+
6876+static const struct vm_operations_struct pax_vm_ops = {
6877+ .close = pax_emuplt_close,
6878+ .fault = pax_emuplt_fault
6879+};
6880+
6881+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6882+{
6883+ int ret;
6884+
6885+ INIT_LIST_HEAD(&vma->anon_vma_chain);
6886+ vma->vm_mm = current->mm;
6887+ vma->vm_start = addr;
6888+ vma->vm_end = addr + PAGE_SIZE;
6889+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6890+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6891+ vma->vm_ops = &pax_vm_ops;
6892+
6893+ ret = insert_vm_struct(current->mm, vma);
6894+ if (ret)
6895+ return ret;
6896+
6897+ ++current->mm->total_vm;
6898+ return 0;
6899+}
6900+#endif
6901+
6902+/*
6903+ * PaX: decide what to do with offenders (regs->tpc = fault address)
6904+ *
6905+ * returns 1 when task should be killed
6906+ * 2 when patched PLT trampoline was detected
6907+ * 3 when unpatched PLT trampoline was detected
6908+ */
6909+static int pax_handle_fetch_fault(struct pt_regs *regs)
6910+{
6911+
6912+#ifdef CONFIG_PAX_EMUPLT
6913+ int err;
6914+
6915+ do { /* PaX: patched PLT emulation #1 */
6916+ unsigned int sethi1, sethi2, jmpl;
6917+
6918+ err = get_user(sethi1, (unsigned int *)regs->tpc);
6919+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6920+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6921+
6922+ if (err)
6923+ break;
6924+
6925+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6926+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6927+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6928+ {
6929+ unsigned long addr;
6930+
6931+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6932+ addr = regs->u_regs[UREG_G1];
6933+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6934+
6935+ if (test_thread_flag(TIF_32BIT))
6936+ addr &= 0xFFFFFFFFUL;
6937+
6938+ regs->tpc = addr;
6939+ regs->tnpc = addr+4;
6940+ return 2;
6941+ }
6942+ } while (0);
6943+
6944+ { /* PaX: patched PLT emulation #2 */
6945+ unsigned int ba;
6946+
6947+ err = get_user(ba, (unsigned int *)regs->tpc);
6948+
6949+ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6950+ unsigned long addr;
6951+
6952+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6953+
6954+ if (test_thread_flag(TIF_32BIT))
6955+ addr &= 0xFFFFFFFFUL;
6956+
6957+ regs->tpc = addr;
6958+ regs->tnpc = addr+4;
6959+ return 2;
6960+ }
6961+ }
6962+
6963+ do { /* PaX: patched PLT emulation #3 */
6964+ unsigned int sethi, jmpl, nop;
6965+
6966+ err = get_user(sethi, (unsigned int *)regs->tpc);
6967+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
6968+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6969+
6970+ if (err)
6971+ break;
6972+
6973+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6974+ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6975+ nop == 0x01000000U)
6976+ {
6977+ unsigned long addr;
6978+
6979+ addr = (sethi & 0x003FFFFFU) << 10;
6980+ regs->u_regs[UREG_G1] = addr;
6981+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6982+
6983+ if (test_thread_flag(TIF_32BIT))
6984+ addr &= 0xFFFFFFFFUL;
6985+
6986+ regs->tpc = addr;
6987+ regs->tnpc = addr+4;
6988+ return 2;
6989+ }
6990+ } while (0);
6991+
6992+ do { /* PaX: patched PLT emulation #4 */
6993+ unsigned int sethi, mov1, call, mov2;
6994+
6995+ err = get_user(sethi, (unsigned int *)regs->tpc);
6996+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6997+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
6998+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6999+
7000+ if (err)
7001+ break;
7002+
7003+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7004+ mov1 == 0x8210000FU &&
7005+ (call & 0xC0000000U) == 0x40000000U &&
7006+ mov2 == 0x9E100001U)
7007+ {
7008+ unsigned long addr;
7009+
7010+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
7011+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7012+
7013+ if (test_thread_flag(TIF_32BIT))
7014+ addr &= 0xFFFFFFFFUL;
7015+
7016+ regs->tpc = addr;
7017+ regs->tnpc = addr+4;
7018+ return 2;
7019+ }
7020+ } while (0);
7021+
7022+ do { /* PaX: patched PLT emulation #5 */
7023+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
7024+
7025+ err = get_user(sethi, (unsigned int *)regs->tpc);
7026+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7027+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7028+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
7029+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
7030+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
7031+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
7032+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
7033+
7034+ if (err)
7035+ break;
7036+
7037+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7038+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
7039+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7040+ (or1 & 0xFFFFE000U) == 0x82106000U &&
7041+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
7042+ sllx == 0x83287020U &&
7043+ jmpl == 0x81C04005U &&
7044+ nop == 0x01000000U)
7045+ {
7046+ unsigned long addr;
7047+
7048+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7049+ regs->u_regs[UREG_G1] <<= 32;
7050+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7051+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7052+ regs->tpc = addr;
7053+ regs->tnpc = addr+4;
7054+ return 2;
7055+ }
7056+ } while (0);
7057+
7058+ do { /* PaX: patched PLT emulation #6 */
7059+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7060+
7061+ err = get_user(sethi, (unsigned int *)regs->tpc);
7062+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7063+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7064+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7065+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
7066+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7067+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7068+
7069+ if (err)
7070+ break;
7071+
7072+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7073+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
7074+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7075+ sllx == 0x83287020U &&
7076+ (or & 0xFFFFE000U) == 0x8A116000U &&
7077+ jmpl == 0x81C04005U &&
7078+ nop == 0x01000000U)
7079+ {
7080+ unsigned long addr;
7081+
7082+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7083+ regs->u_regs[UREG_G1] <<= 32;
7084+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7085+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7086+ regs->tpc = addr;
7087+ regs->tnpc = addr+4;
7088+ return 2;
7089+ }
7090+ } while (0);
7091+
7092+ do { /* PaX: unpatched PLT emulation step 1 */
7093+ unsigned int sethi, ba, nop;
7094+
7095+ err = get_user(sethi, (unsigned int *)regs->tpc);
7096+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7097+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7098+
7099+ if (err)
7100+ break;
7101+
7102+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7103+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7104+ nop == 0x01000000U)
7105+ {
7106+ unsigned long addr;
7107+ unsigned int save, call;
7108+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7109+
7110+ if ((ba & 0xFFC00000U) == 0x30800000U)
7111+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7112+ else
7113+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7114+
7115+ if (test_thread_flag(TIF_32BIT))
7116+ addr &= 0xFFFFFFFFUL;
7117+
7118+ err = get_user(save, (unsigned int *)addr);
7119+ err |= get_user(call, (unsigned int *)(addr+4));
7120+ err |= get_user(nop, (unsigned int *)(addr+8));
7121+ if (err)
7122+ break;
7123+
7124+#ifdef CONFIG_PAX_DLRESOLVE
7125+ if (save == 0x9DE3BFA8U &&
7126+ (call & 0xC0000000U) == 0x40000000U &&
7127+ nop == 0x01000000U)
7128+ {
7129+ struct vm_area_struct *vma;
7130+ unsigned long call_dl_resolve;
7131+
7132+ down_read(&current->mm->mmap_sem);
7133+ call_dl_resolve = current->mm->call_dl_resolve;
7134+ up_read(&current->mm->mmap_sem);
7135+ if (likely(call_dl_resolve))
7136+ goto emulate;
7137+
7138+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7139+
7140+ down_write(&current->mm->mmap_sem);
7141+ if (current->mm->call_dl_resolve) {
7142+ call_dl_resolve = current->mm->call_dl_resolve;
7143+ up_write(&current->mm->mmap_sem);
7144+ if (vma)
7145+ kmem_cache_free(vm_area_cachep, vma);
7146+ goto emulate;
7147+ }
7148+
7149+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7150+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7151+ up_write(&current->mm->mmap_sem);
7152+ if (vma)
7153+ kmem_cache_free(vm_area_cachep, vma);
7154+ return 1;
7155+ }
7156+
7157+ if (pax_insert_vma(vma, call_dl_resolve)) {
7158+ up_write(&current->mm->mmap_sem);
7159+ kmem_cache_free(vm_area_cachep, vma);
7160+ return 1;
7161+ }
7162+
7163+ current->mm->call_dl_resolve = call_dl_resolve;
7164+ up_write(&current->mm->mmap_sem);
7165+
7166+emulate:
7167+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7168+ regs->tpc = call_dl_resolve;
7169+ regs->tnpc = addr+4;
7170+ return 3;
7171+ }
7172+#endif
7173+
7174+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7175+ if ((save & 0xFFC00000U) == 0x05000000U &&
7176+ (call & 0xFFFFE000U) == 0x85C0A000U &&
7177+ nop == 0x01000000U)
7178+ {
7179+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7180+ regs->u_regs[UREG_G2] = addr + 4;
7181+ addr = (save & 0x003FFFFFU) << 10;
7182+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7183+
7184+ if (test_thread_flag(TIF_32BIT))
7185+ addr &= 0xFFFFFFFFUL;
7186+
7187+ regs->tpc = addr;
7188+ regs->tnpc = addr+4;
7189+ return 3;
7190+ }
7191+
7192+ /* PaX: 64-bit PLT stub */
7193+ err = get_user(sethi1, (unsigned int *)addr);
7194+ err |= get_user(sethi2, (unsigned int *)(addr+4));
7195+ err |= get_user(or1, (unsigned int *)(addr+8));
7196+ err |= get_user(or2, (unsigned int *)(addr+12));
7197+ err |= get_user(sllx, (unsigned int *)(addr+16));
7198+ err |= get_user(add, (unsigned int *)(addr+20));
7199+ err |= get_user(jmpl, (unsigned int *)(addr+24));
7200+ err |= get_user(nop, (unsigned int *)(addr+28));
7201+ if (err)
7202+ break;
7203+
7204+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7205+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7206+ (or1 & 0xFFFFE000U) == 0x88112000U &&
7207+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
7208+ sllx == 0x89293020U &&
7209+ add == 0x8A010005U &&
7210+ jmpl == 0x89C14000U &&
7211+ nop == 0x01000000U)
7212+ {
7213+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7214+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7215+ regs->u_regs[UREG_G4] <<= 32;
7216+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7217+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7218+ regs->u_regs[UREG_G4] = addr + 24;
7219+ addr = regs->u_regs[UREG_G5];
7220+ regs->tpc = addr;
7221+ regs->tnpc = addr+4;
7222+ return 3;
7223+ }
7224+ }
7225+ } while (0);
7226+
7227+#ifdef CONFIG_PAX_DLRESOLVE
7228+ do { /* PaX: unpatched PLT emulation step 2 */
7229+ unsigned int save, call, nop;
7230+
7231+ err = get_user(save, (unsigned int *)(regs->tpc-4));
7232+ err |= get_user(call, (unsigned int *)regs->tpc);
7233+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7234+ if (err)
7235+ break;
7236+
7237+ if (save == 0x9DE3BFA8U &&
7238+ (call & 0xC0000000U) == 0x40000000U &&
7239+ nop == 0x01000000U)
7240+ {
7241+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7242+
7243+ if (test_thread_flag(TIF_32BIT))
7244+ dl_resolve &= 0xFFFFFFFFUL;
7245+
7246+ regs->u_regs[UREG_RETPC] = regs->tpc;
7247+ regs->tpc = dl_resolve;
7248+ regs->tnpc = dl_resolve+4;
7249+ return 3;
7250+ }
7251+ } while (0);
7252+#endif
7253+
7254+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7255+ unsigned int sethi, ba, nop;
7256+
7257+ err = get_user(sethi, (unsigned int *)regs->tpc);
7258+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7259+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7260+
7261+ if (err)
7262+ break;
7263+
7264+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7265+ (ba & 0xFFF00000U) == 0x30600000U &&
7266+ nop == 0x01000000U)
7267+ {
7268+ unsigned long addr;
7269+
7270+ addr = (sethi & 0x003FFFFFU) << 10;
7271+ regs->u_regs[UREG_G1] = addr;
7272+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7273+
7274+ if (test_thread_flag(TIF_32BIT))
7275+ addr &= 0xFFFFFFFFUL;
7276+
7277+ regs->tpc = addr;
7278+ regs->tnpc = addr+4;
7279+ return 2;
7280+ }
7281+ } while (0);
7282+
7283+#endif
7284+
7285+ return 1;
7286+}
7287+
7288+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7289+{
7290+ unsigned long i;
7291+
7292+ printk(KERN_ERR "PAX: bytes at PC: ");
7293+ for (i = 0; i < 8; i++) {
7294+ unsigned int c;
7295+ if (get_user(c, (unsigned int *)pc+i))
7296+ printk(KERN_CONT "???????? ");
7297+ else
7298+ printk(KERN_CONT "%08x ", c);
7299+ }
7300+ printk("\n");
7301+}
7302+#endif
7303+
7304 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7305 {
7306 struct mm_struct *mm = current->mm;
7307@@ -343,6 +797,29 @@ retry:
7308 if (!vma)
7309 goto bad_area;
7310
7311+#ifdef CONFIG_PAX_PAGEEXEC
7312+ /* PaX: detect ITLB misses on non-exec pages */
7313+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7314+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7315+ {
7316+ if (address != regs->tpc)
7317+ goto good_area;
7318+
7319+ up_read(&mm->mmap_sem);
7320+ switch (pax_handle_fetch_fault(regs)) {
7321+
7322+#ifdef CONFIG_PAX_EMUPLT
7323+ case 2:
7324+ case 3:
7325+ return;
7326+#endif
7327+
7328+ }
7329+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7330+ do_group_exit(SIGKILL);
7331+ }
7332+#endif
7333+
7334 /* Pure DTLB misses do not tell us whether the fault causing
7335 * load/store/atomic was a write or not, it only says that there
7336 * was no match. So in such a case we (carefully) read the
7337diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7338index 07e1453..0a7d9e9 100644
7339--- a/arch/sparc/mm/hugetlbpage.c
7340+++ b/arch/sparc/mm/hugetlbpage.c
7341@@ -67,7 +67,7 @@ full_search:
7342 }
7343 return -ENOMEM;
7344 }
7345- if (likely(!vma || addr + len <= vma->vm_start)) {
7346+ if (likely(check_heap_stack_gap(vma, addr, len))) {
7347 /*
7348 * Remember the place where we stopped the search:
7349 */
7350@@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7351 /* make sure it can fit in the remaining address space */
7352 if (likely(addr > len)) {
7353 vma = find_vma(mm, addr-len);
7354- if (!vma || addr <= vma->vm_start) {
7355+ if (check_heap_stack_gap(vma, addr - len, len)) {
7356 /* remember the address as a hint for next time */
7357 return (mm->free_area_cache = addr-len);
7358 }
7359@@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7360 if (unlikely(mm->mmap_base < len))
7361 goto bottomup;
7362
7363- addr = (mm->mmap_base-len) & HPAGE_MASK;
7364+ addr = mm->mmap_base - len;
7365
7366 do {
7367+ addr &= HPAGE_MASK;
7368 /*
7369 * Lookup failure means no vma is above this address,
7370 * else if new region fits below vma->vm_start,
7371 * return with success:
7372 */
7373 vma = find_vma(mm, addr);
7374- if (likely(!vma || addr+len <= vma->vm_start)) {
7375+ if (likely(check_heap_stack_gap(vma, addr, len))) {
7376 /* remember the address as a hint for next time */
7377 return (mm->free_area_cache = addr);
7378 }
7379@@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7380 mm->cached_hole_size = vma->vm_start - addr;
7381
7382 /* try just below the current vma->vm_start */
7383- addr = (vma->vm_start-len) & HPAGE_MASK;
7384- } while (likely(len < vma->vm_start));
7385+ addr = skip_heap_stack_gap(vma, len);
7386+ } while (!IS_ERR_VALUE(addr));
7387
7388 bottomup:
7389 /*
7390@@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7391 if (addr) {
7392 addr = ALIGN(addr, HPAGE_SIZE);
7393 vma = find_vma(mm, addr);
7394- if (task_size - len >= addr &&
7395- (!vma || addr + len <= vma->vm_start))
7396+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7397 return addr;
7398 }
7399 if (mm->get_unmapped_area == arch_get_unmapped_area)
7400diff --git a/arch/sparc/mm/init_32.c b/arch/sparc/mm/init_32.c
7401index c5f9021..7591bae 100644
7402--- a/arch/sparc/mm/init_32.c
7403+++ b/arch/sparc/mm/init_32.c
7404@@ -315,6 +315,9 @@ extern void device_scan(void);
7405 pgprot_t PAGE_SHARED __read_mostly;
7406 EXPORT_SYMBOL(PAGE_SHARED);
7407
7408+pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
7409+EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
7410+
7411 void __init paging_init(void)
7412 {
7413 switch(sparc_cpu_model) {
7414@@ -343,17 +346,17 @@ void __init paging_init(void)
7415
7416 /* Initialize the protection map with non-constant, MMU dependent values. */
7417 protection_map[0] = PAGE_NONE;
7418- protection_map[1] = PAGE_READONLY;
7419- protection_map[2] = PAGE_COPY;
7420- protection_map[3] = PAGE_COPY;
7421+ protection_map[1] = PAGE_READONLY_NOEXEC;
7422+ protection_map[2] = PAGE_COPY_NOEXEC;
7423+ protection_map[3] = PAGE_COPY_NOEXEC;
7424 protection_map[4] = PAGE_READONLY;
7425 protection_map[5] = PAGE_READONLY;
7426 protection_map[6] = PAGE_COPY;
7427 protection_map[7] = PAGE_COPY;
7428 protection_map[8] = PAGE_NONE;
7429- protection_map[9] = PAGE_READONLY;
7430- protection_map[10] = PAGE_SHARED;
7431- protection_map[11] = PAGE_SHARED;
7432+ protection_map[9] = PAGE_READONLY_NOEXEC;
7433+ protection_map[10] = PAGE_SHARED_NOEXEC;
7434+ protection_map[11] = PAGE_SHARED_NOEXEC;
7435 protection_map[12] = PAGE_READONLY;
7436 protection_map[13] = PAGE_READONLY;
7437 protection_map[14] = PAGE_SHARED;
7438diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
7439index cbef74e..c38fead 100644
7440--- a/arch/sparc/mm/srmmu.c
7441+++ b/arch/sparc/mm/srmmu.c
7442@@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
7443 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
7444 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
7445 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
7446+
7447+#ifdef CONFIG_PAX_PAGEEXEC
7448+ PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
7449+ BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
7450+ BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
7451+#endif
7452+
7453 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
7454 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
7455
7456diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7457index f4500c6..889656c 100644
7458--- a/arch/tile/include/asm/atomic_64.h
7459+++ b/arch/tile/include/asm/atomic_64.h
7460@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7461
7462 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7463
7464+#define atomic64_read_unchecked(v) atomic64_read(v)
7465+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7466+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7467+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7468+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7469+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7470+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7471+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7472+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7473+
7474 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7475 #define smp_mb__before_atomic_dec() smp_mb()
7476 #define smp_mb__after_atomic_dec() smp_mb()
7477diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7478index 392e533..536b092 100644
7479--- a/arch/tile/include/asm/cache.h
7480+++ b/arch/tile/include/asm/cache.h
7481@@ -15,11 +15,12 @@
7482 #ifndef _ASM_TILE_CACHE_H
7483 #define _ASM_TILE_CACHE_H
7484
7485+#include <linux/const.h>
7486 #include <arch/chip.h>
7487
7488 /* bytes per L1 data cache line */
7489 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7490-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7491+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7492
7493 /* bytes per L2 cache line */
7494 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7495diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
7496index ef34d2c..d6ce60c 100644
7497--- a/arch/tile/include/asm/uaccess.h
7498+++ b/arch/tile/include/asm/uaccess.h
7499@@ -361,9 +361,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
7500 const void __user *from,
7501 unsigned long n)
7502 {
7503- int sz = __compiletime_object_size(to);
7504+ size_t sz = __compiletime_object_size(to);
7505
7506- if (likely(sz == -1 || sz >= n))
7507+ if (likely(sz == (size_t)-1 || sz >= n))
7508 n = _copy_from_user(to, from, n);
7509 else
7510 copy_from_user_overflow();
7511diff --git a/arch/um/Makefile b/arch/um/Makefile
7512index 55c0661..86ad413 100644
7513--- a/arch/um/Makefile
7514+++ b/arch/um/Makefile
7515@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7516 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7517 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7518
7519+ifdef CONSTIFY_PLUGIN
7520+USER_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7521+endif
7522+
7523 #This will adjust *FLAGS accordingly to the platform.
7524 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7525
7526diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7527index 19e1bdd..3665b77 100644
7528--- a/arch/um/include/asm/cache.h
7529+++ b/arch/um/include/asm/cache.h
7530@@ -1,6 +1,7 @@
7531 #ifndef __UM_CACHE_H
7532 #define __UM_CACHE_H
7533
7534+#include <linux/const.h>
7535
7536 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7537 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7538@@ -12,6 +13,6 @@
7539 # define L1_CACHE_SHIFT 5
7540 #endif
7541
7542-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7543+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7544
7545 #endif
7546diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7547index 6c03acd..a5e0215 100644
7548--- a/arch/um/include/asm/kmap_types.h
7549+++ b/arch/um/include/asm/kmap_types.h
7550@@ -23,6 +23,7 @@ enum km_type {
7551 KM_IRQ1,
7552 KM_SOFTIRQ0,
7553 KM_SOFTIRQ1,
7554+ KM_CLEARPAGE,
7555 KM_TYPE_NR
7556 };
7557
7558diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7559index 7cfc3ce..cbd1a58 100644
7560--- a/arch/um/include/asm/page.h
7561+++ b/arch/um/include/asm/page.h
7562@@ -14,6 +14,9 @@
7563 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7564 #define PAGE_MASK (~(PAGE_SIZE-1))
7565
7566+#define ktla_ktva(addr) (addr)
7567+#define ktva_ktla(addr) (addr)
7568+
7569 #ifndef __ASSEMBLY__
7570
7571 struct page;
7572diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7573index 0032f92..cd151e0 100644
7574--- a/arch/um/include/asm/pgtable-3level.h
7575+++ b/arch/um/include/asm/pgtable-3level.h
7576@@ -58,6 +58,7 @@
7577 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7578 #define pud_populate(mm, pud, pmd) \
7579 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7580+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7581
7582 #ifdef CONFIG_64BIT
7583 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7584diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7585index 2b73ded..804f540 100644
7586--- a/arch/um/kernel/process.c
7587+++ b/arch/um/kernel/process.c
7588@@ -404,22 +404,6 @@ int singlestepping(void * t)
7589 return 2;
7590 }
7591
7592-/*
7593- * Only x86 and x86_64 have an arch_align_stack().
7594- * All other arches have "#define arch_align_stack(x) (x)"
7595- * in their asm/system.h
7596- * As this is included in UML from asm-um/system-generic.h,
7597- * we can use it to behave as the subarch does.
7598- */
7599-#ifndef arch_align_stack
7600-unsigned long arch_align_stack(unsigned long sp)
7601-{
7602- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7603- sp -= get_random_int() % 8192;
7604- return sp & ~0xf;
7605-}
7606-#endif
7607-
7608 unsigned long get_wchan(struct task_struct *p)
7609 {
7610 unsigned long stack_page, sp, ip;
7611diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7612index ad8f795..2c7eec6 100644
7613--- a/arch/unicore32/include/asm/cache.h
7614+++ b/arch/unicore32/include/asm/cache.h
7615@@ -12,8 +12,10 @@
7616 #ifndef __UNICORE_CACHE_H__
7617 #define __UNICORE_CACHE_H__
7618
7619-#define L1_CACHE_SHIFT (5)
7620-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7621+#include <linux/const.h>
7622+
7623+#define L1_CACHE_SHIFT 5
7624+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7625
7626 /*
7627 * Memory returned by kmalloc() may be used for DMA, so we must make
7628diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7629index c9866b0..fe53aef 100644
7630--- a/arch/x86/Kconfig
7631+++ b/arch/x86/Kconfig
7632@@ -229,7 +229,7 @@ config X86_HT
7633
7634 config X86_32_LAZY_GS
7635 def_bool y
7636- depends on X86_32 && !CC_STACKPROTECTOR
7637+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7638
7639 config ARCH_HWEIGHT_CFLAGS
7640 string
7641@@ -1042,7 +1042,7 @@ choice
7642
7643 config NOHIGHMEM
7644 bool "off"
7645- depends on !X86_NUMAQ
7646+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7647 ---help---
7648 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7649 However, the address space of 32-bit x86 processors is only 4
7650@@ -1079,7 +1079,7 @@ config NOHIGHMEM
7651
7652 config HIGHMEM4G
7653 bool "4GB"
7654- depends on !X86_NUMAQ
7655+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7656 ---help---
7657 Select this if you have a 32-bit processor and between 1 and 4
7658 gigabytes of physical RAM.
7659@@ -1133,7 +1133,7 @@ config PAGE_OFFSET
7660 hex
7661 default 0xB0000000 if VMSPLIT_3G_OPT
7662 default 0x80000000 if VMSPLIT_2G
7663- default 0x78000000 if VMSPLIT_2G_OPT
7664+ default 0x70000000 if VMSPLIT_2G_OPT
7665 default 0x40000000 if VMSPLIT_1G
7666 default 0xC0000000
7667 depends on X86_32
7668@@ -1523,6 +1523,7 @@ config SECCOMP
7669
7670 config CC_STACKPROTECTOR
7671 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
7672+ depends on X86_64 || !PAX_MEMORY_UDEREF
7673 ---help---
7674 This option turns on the -fstack-protector GCC feature. This
7675 feature puts, at the beginning of functions, a canary value on
7676@@ -1580,6 +1581,7 @@ config KEXEC_JUMP
7677 config PHYSICAL_START
7678 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7679 default "0x1000000"
7680+ range 0x400000 0x40000000
7681 ---help---
7682 This gives the physical address where the kernel is loaded.
7683
7684@@ -1643,6 +1645,7 @@ config X86_NEED_RELOCS
7685 config PHYSICAL_ALIGN
7686 hex "Alignment value to which kernel should be aligned" if X86_32
7687 default "0x1000000"
7688+ range 0x400000 0x1000000 if PAX_KERNEXEC
7689 range 0x2000 0x1000000
7690 ---help---
7691 This value puts the alignment restrictions on physical address
7692@@ -1674,9 +1677,10 @@ config HOTPLUG_CPU
7693 Say N if you want to disable CPU hotplug.
7694
7695 config COMPAT_VDSO
7696- def_bool y
7697+ def_bool n
7698 prompt "Compat VDSO support"
7699 depends on X86_32 || IA32_EMULATION
7700+ depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7701 ---help---
7702 Map the 32-bit VDSO to the predictable old-style address too.
7703
7704diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7705index 706e12e..62e4feb 100644
7706--- a/arch/x86/Kconfig.cpu
7707+++ b/arch/x86/Kconfig.cpu
7708@@ -334,7 +334,7 @@ config X86_PPRO_FENCE
7709
7710 config X86_F00F_BUG
7711 def_bool y
7712- depends on M586MMX || M586TSC || M586 || M486 || M386
7713+ depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7714
7715 config X86_INVD_BUG
7716 def_bool y
7717@@ -358,7 +358,7 @@ config X86_POPAD_OK
7718
7719 config X86_ALIGNMENT_16
7720 def_bool y
7721- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7722+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7723
7724 config X86_INTEL_USERCOPY
7725 def_bool y
7726@@ -404,7 +404,7 @@ config X86_CMPXCHG64
7727 # generates cmov.
7728 config X86_CMOV
7729 def_bool y
7730- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7731+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7732
7733 config X86_MINIMUM_CPU_FAMILY
7734 int
7735diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7736index e46c214..7c72b55 100644
7737--- a/arch/x86/Kconfig.debug
7738+++ b/arch/x86/Kconfig.debug
7739@@ -84,7 +84,7 @@ config X86_PTDUMP
7740 config DEBUG_RODATA
7741 bool "Write protect kernel read-only data structures"
7742 default y
7743- depends on DEBUG_KERNEL
7744+ depends on DEBUG_KERNEL && BROKEN
7745 ---help---
7746 Mark the kernel read-only data as write-protected in the pagetables,
7747 in order to catch accidental (and incorrect) writes to such const
7748@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7749
7750 config DEBUG_SET_MODULE_RONX
7751 bool "Set loadable kernel module data as NX and text as RO"
7752- depends on MODULES
7753+ depends on MODULES && BROKEN
7754 ---help---
7755 This option helps catch unintended modifications to loadable
7756 kernel module's text and read-only data. It also prevents execution
7757diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7758index b1c611e..2c1a823 100644
7759--- a/arch/x86/Makefile
7760+++ b/arch/x86/Makefile
7761@@ -46,6 +46,7 @@ else
7762 UTS_MACHINE := x86_64
7763 CHECKFLAGS += -D__x86_64__ -m64
7764
7765+ biarch := $(call cc-option,-m64)
7766 KBUILD_AFLAGS += -m64
7767 KBUILD_CFLAGS += -m64
7768
7769@@ -222,3 +223,12 @@ define archhelp
7770 echo ' FDARGS="..." arguments for the booted kernel'
7771 echo ' FDINITRD=file initrd for the booted kernel'
7772 endef
7773+
7774+define OLD_LD
7775+
7776+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7777+*** Please upgrade your binutils to 2.18 or newer
7778+endef
7779+
7780+archprepare:
7781+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7782diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7783index 5a747dd..ff7b12c 100644
7784--- a/arch/x86/boot/Makefile
7785+++ b/arch/x86/boot/Makefile
7786@@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7787 $(call cc-option, -fno-stack-protector) \
7788 $(call cc-option, -mpreferred-stack-boundary=2)
7789 KBUILD_CFLAGS += $(call cc-option, -m32)
7790+ifdef CONSTIFY_PLUGIN
7791+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7792+endif
7793 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7794 GCOV_PROFILE := n
7795
7796diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7797index 878e4b9..20537ab 100644
7798--- a/arch/x86/boot/bitops.h
7799+++ b/arch/x86/boot/bitops.h
7800@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7801 u8 v;
7802 const u32 *p = (const u32 *)addr;
7803
7804- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7805+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7806 return v;
7807 }
7808
7809@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7810
7811 static inline void set_bit(int nr, void *addr)
7812 {
7813- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7814+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7815 }
7816
7817 #endif /* BOOT_BITOPS_H */
7818diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7819index 18997e5..83d9c67 100644
7820--- a/arch/x86/boot/boot.h
7821+++ b/arch/x86/boot/boot.h
7822@@ -85,7 +85,7 @@ static inline void io_delay(void)
7823 static inline u16 ds(void)
7824 {
7825 u16 seg;
7826- asm("movw %%ds,%0" : "=rm" (seg));
7827+ asm volatile("movw %%ds,%0" : "=rm" (seg));
7828 return seg;
7829 }
7830
7831@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7832 static inline int memcmp(const void *s1, const void *s2, size_t len)
7833 {
7834 u8 diff;
7835- asm("repe; cmpsb; setnz %0"
7836+ asm volatile("repe; cmpsb; setnz %0"
7837 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7838 return diff;
7839 }
7840diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7841index e398bb5..3a382ca 100644
7842--- a/arch/x86/boot/compressed/Makefile
7843+++ b/arch/x86/boot/compressed/Makefile
7844@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7845 KBUILD_CFLAGS += $(cflags-y)
7846 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7847 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7848+ifdef CONSTIFY_PLUGIN
7849+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7850+endif
7851
7852 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7853 GCOV_PROFILE := n
7854diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7855index 0cdfc0d..6e79437 100644
7856--- a/arch/x86/boot/compressed/eboot.c
7857+++ b/arch/x86/boot/compressed/eboot.c
7858@@ -122,7 +122,6 @@ again:
7859 *addr = max_addr;
7860 }
7861
7862-free_pool:
7863 efi_call_phys1(sys_table->boottime->free_pool, map);
7864
7865 fail:
7866@@ -186,7 +185,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7867 if (i == map_size / desc_size)
7868 status = EFI_NOT_FOUND;
7869
7870-free_pool:
7871 efi_call_phys1(sys_table->boottime->free_pool, map);
7872 fail:
7873 return status;
7874diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7875index c85e3ac..6f5aa80 100644
7876--- a/arch/x86/boot/compressed/head_32.S
7877+++ b/arch/x86/boot/compressed/head_32.S
7878@@ -106,7 +106,7 @@ preferred_addr:
7879 notl %eax
7880 andl %eax, %ebx
7881 #else
7882- movl $LOAD_PHYSICAL_ADDR, %ebx
7883+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7884 #endif
7885
7886 /* Target address to relocate to for decompression */
7887@@ -192,7 +192,7 @@ relocated:
7888 * and where it was actually loaded.
7889 */
7890 movl %ebp, %ebx
7891- subl $LOAD_PHYSICAL_ADDR, %ebx
7892+ subl $____LOAD_PHYSICAL_ADDR, %ebx
7893 jz 2f /* Nothing to be done if loaded at compiled addr. */
7894 /*
7895 * Process relocations.
7896@@ -200,8 +200,7 @@ relocated:
7897
7898 1: subl $4, %edi
7899 movl (%edi), %ecx
7900- testl %ecx, %ecx
7901- jz 2f
7902+ jecxz 2f
7903 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7904 jmp 1b
7905 2:
7906diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7907index 87e03a1..0d94c76 100644
7908--- a/arch/x86/boot/compressed/head_64.S
7909+++ b/arch/x86/boot/compressed/head_64.S
7910@@ -91,7 +91,7 @@ ENTRY(startup_32)
7911 notl %eax
7912 andl %eax, %ebx
7913 #else
7914- movl $LOAD_PHYSICAL_ADDR, %ebx
7915+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7916 #endif
7917
7918 /* Target address to relocate to for decompression */
7919@@ -263,7 +263,7 @@ preferred_addr:
7920 notq %rax
7921 andq %rax, %rbp
7922 #else
7923- movq $LOAD_PHYSICAL_ADDR, %rbp
7924+ movq $____LOAD_PHYSICAL_ADDR, %rbp
7925 #endif
7926
7927 /* Target address to relocate to for decompression */
7928diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7929index 7116dcb..d9ae1d7 100644
7930--- a/arch/x86/boot/compressed/misc.c
7931+++ b/arch/x86/boot/compressed/misc.c
7932@@ -310,7 +310,7 @@ static void parse_elf(void *output)
7933 case PT_LOAD:
7934 #ifdef CONFIG_RELOCATABLE
7935 dest = output;
7936- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7937+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7938 #else
7939 dest = (void *)(phdr->p_paddr);
7940 #endif
7941@@ -365,7 +365,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7942 error("Destination address too large");
7943 #endif
7944 #ifndef CONFIG_RELOCATABLE
7945- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7946+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7947 error("Wrong destination address");
7948 #endif
7949
7950diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7951index 4d3ff03..e4972ff 100644
7952--- a/arch/x86/boot/cpucheck.c
7953+++ b/arch/x86/boot/cpucheck.c
7954@@ -74,7 +74,7 @@ static int has_fpu(void)
7955 u16 fcw = -1, fsw = -1;
7956 u32 cr0;
7957
7958- asm("movl %%cr0,%0" : "=r" (cr0));
7959+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
7960 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7961 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7962 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7963@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7964 {
7965 u32 f0, f1;
7966
7967- asm("pushfl ; "
7968+ asm volatile("pushfl ; "
7969 "pushfl ; "
7970 "popl %0 ; "
7971 "movl %0,%1 ; "
7972@@ -115,7 +115,7 @@ static void get_flags(void)
7973 set_bit(X86_FEATURE_FPU, cpu.flags);
7974
7975 if (has_eflag(X86_EFLAGS_ID)) {
7976- asm("cpuid"
7977+ asm volatile("cpuid"
7978 : "=a" (max_intel_level),
7979 "=b" (cpu_vendor[0]),
7980 "=d" (cpu_vendor[1]),
7981@@ -124,7 +124,7 @@ static void get_flags(void)
7982
7983 if (max_intel_level >= 0x00000001 &&
7984 max_intel_level <= 0x0000ffff) {
7985- asm("cpuid"
7986+ asm volatile("cpuid"
7987 : "=a" (tfms),
7988 "=c" (cpu.flags[4]),
7989 "=d" (cpu.flags[0])
7990@@ -136,7 +136,7 @@ static void get_flags(void)
7991 cpu.model += ((tfms >> 16) & 0xf) << 4;
7992 }
7993
7994- asm("cpuid"
7995+ asm volatile("cpuid"
7996 : "=a" (max_amd_level)
7997 : "a" (0x80000000)
7998 : "ebx", "ecx", "edx");
7999@@ -144,7 +144,7 @@ static void get_flags(void)
8000 if (max_amd_level >= 0x80000001 &&
8001 max_amd_level <= 0x8000ffff) {
8002 u32 eax = 0x80000001;
8003- asm("cpuid"
8004+ asm volatile("cpuid"
8005 : "+a" (eax),
8006 "=c" (cpu.flags[6]),
8007 "=d" (cpu.flags[1])
8008@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8009 u32 ecx = MSR_K7_HWCR;
8010 u32 eax, edx;
8011
8012- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8013+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8014 eax &= ~(1 << 15);
8015- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8016+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8017
8018 get_flags(); /* Make sure it really did something */
8019 err = check_flags();
8020@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8021 u32 ecx = MSR_VIA_FCR;
8022 u32 eax, edx;
8023
8024- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8025+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8026 eax |= (1<<1)|(1<<7);
8027- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8028+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8029
8030 set_bit(X86_FEATURE_CX8, cpu.flags);
8031 err = check_flags();
8032@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8033 u32 eax, edx;
8034 u32 level = 1;
8035
8036- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8037- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8038- asm("cpuid"
8039+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8040+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8041+ asm volatile("cpuid"
8042 : "+a" (level), "=d" (cpu.flags[0])
8043 : : "ecx", "ebx");
8044- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8045+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8046
8047 err = check_flags();
8048 }
8049diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
8050index f1bbeeb..aff09cb 100644
8051--- a/arch/x86/boot/header.S
8052+++ b/arch/x86/boot/header.S
8053@@ -372,7 +372,7 @@ setup_data: .quad 0 # 64-bit physical pointer to
8054 # single linked list of
8055 # struct setup_data
8056
8057-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
8058+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
8059
8060 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
8061 #define VO_INIT_SIZE (VO__end - VO__text)
8062diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
8063index db75d07..8e6d0af 100644
8064--- a/arch/x86/boot/memory.c
8065+++ b/arch/x86/boot/memory.c
8066@@ -19,7 +19,7 @@
8067
8068 static int detect_memory_e820(void)
8069 {
8070- int count = 0;
8071+ unsigned int count = 0;
8072 struct biosregs ireg, oreg;
8073 struct e820entry *desc = boot_params.e820_map;
8074 static struct e820entry buf; /* static so it is zeroed */
8075diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
8076index 11e8c6e..fdbb1ed 100644
8077--- a/arch/x86/boot/video-vesa.c
8078+++ b/arch/x86/boot/video-vesa.c
8079@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
8080
8081 boot_params.screen_info.vesapm_seg = oreg.es;
8082 boot_params.screen_info.vesapm_off = oreg.di;
8083+ boot_params.screen_info.vesapm_size = oreg.cx;
8084 }
8085
8086 /*
8087diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8088index 43eda28..5ab5fdb 100644
8089--- a/arch/x86/boot/video.c
8090+++ b/arch/x86/boot/video.c
8091@@ -96,7 +96,7 @@ static void store_mode_params(void)
8092 static unsigned int get_entry(void)
8093 {
8094 char entry_buf[4];
8095- int i, len = 0;
8096+ unsigned int i, len = 0;
8097 int key;
8098 unsigned int v;
8099
8100diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8101index 5b577d5..3c1fed4 100644
8102--- a/arch/x86/crypto/aes-x86_64-asm_64.S
8103+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8104@@ -8,6 +8,8 @@
8105 * including this sentence is retained in full.
8106 */
8107
8108+#include <asm/alternative-asm.h>
8109+
8110 .extern crypto_ft_tab
8111 .extern crypto_it_tab
8112 .extern crypto_fl_tab
8113@@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8114 je B192; \
8115 leaq 32(r9),r9;
8116
8117+#define ret pax_force_retaddr 0, 1; ret
8118+
8119 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8120 movq r1,r2; \
8121 movq r3,r4; \
8122diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8123index 3470624..201259d 100644
8124--- a/arch/x86/crypto/aesni-intel_asm.S
8125+++ b/arch/x86/crypto/aesni-intel_asm.S
8126@@ -31,6 +31,7 @@
8127
8128 #include <linux/linkage.h>
8129 #include <asm/inst.h>
8130+#include <asm/alternative-asm.h>
8131
8132 #ifdef __x86_64__
8133 .data
8134@@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8135 pop %r14
8136 pop %r13
8137 pop %r12
8138+ pax_force_retaddr 0, 1
8139 ret
8140+ENDPROC(aesni_gcm_dec)
8141
8142
8143 /*****************************************************************************
8144@@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8145 pop %r14
8146 pop %r13
8147 pop %r12
8148+ pax_force_retaddr 0, 1
8149 ret
8150+ENDPROC(aesni_gcm_enc)
8151
8152 #endif
8153
8154@@ -1714,6 +1719,7 @@ _key_expansion_256a:
8155 pxor %xmm1, %xmm0
8156 movaps %xmm0, (TKEYP)
8157 add $0x10, TKEYP
8158+ pax_force_retaddr_bts
8159 ret
8160
8161 .align 4
8162@@ -1738,6 +1744,7 @@ _key_expansion_192a:
8163 shufps $0b01001110, %xmm2, %xmm1
8164 movaps %xmm1, 0x10(TKEYP)
8165 add $0x20, TKEYP
8166+ pax_force_retaddr_bts
8167 ret
8168
8169 .align 4
8170@@ -1757,6 +1764,7 @@ _key_expansion_192b:
8171
8172 movaps %xmm0, (TKEYP)
8173 add $0x10, TKEYP
8174+ pax_force_retaddr_bts
8175 ret
8176
8177 .align 4
8178@@ -1769,6 +1777,7 @@ _key_expansion_256b:
8179 pxor %xmm1, %xmm2
8180 movaps %xmm2, (TKEYP)
8181 add $0x10, TKEYP
8182+ pax_force_retaddr_bts
8183 ret
8184
8185 /*
8186@@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8187 #ifndef __x86_64__
8188 popl KEYP
8189 #endif
8190+ pax_force_retaddr 0, 1
8191 ret
8192+ENDPROC(aesni_set_key)
8193
8194 /*
8195 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8196@@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8197 popl KLEN
8198 popl KEYP
8199 #endif
8200+ pax_force_retaddr 0, 1
8201 ret
8202+ENDPROC(aesni_enc)
8203
8204 /*
8205 * _aesni_enc1: internal ABI
8206@@ -1959,6 +1972,7 @@ _aesni_enc1:
8207 AESENC KEY STATE
8208 movaps 0x70(TKEYP), KEY
8209 AESENCLAST KEY STATE
8210+ pax_force_retaddr_bts
8211 ret
8212
8213 /*
8214@@ -2067,6 +2081,7 @@ _aesni_enc4:
8215 AESENCLAST KEY STATE2
8216 AESENCLAST KEY STATE3
8217 AESENCLAST KEY STATE4
8218+ pax_force_retaddr_bts
8219 ret
8220
8221 /*
8222@@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8223 popl KLEN
8224 popl KEYP
8225 #endif
8226+ pax_force_retaddr 0, 1
8227 ret
8228+ENDPROC(aesni_dec)
8229
8230 /*
8231 * _aesni_dec1: internal ABI
8232@@ -2146,6 +2163,7 @@ _aesni_dec1:
8233 AESDEC KEY STATE
8234 movaps 0x70(TKEYP), KEY
8235 AESDECLAST KEY STATE
8236+ pax_force_retaddr_bts
8237 ret
8238
8239 /*
8240@@ -2254,6 +2272,7 @@ _aesni_dec4:
8241 AESDECLAST KEY STATE2
8242 AESDECLAST KEY STATE3
8243 AESDECLAST KEY STATE4
8244+ pax_force_retaddr_bts
8245 ret
8246
8247 /*
8248@@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8249 popl KEYP
8250 popl LEN
8251 #endif
8252+ pax_force_retaddr 0, 1
8253 ret
8254+ENDPROC(aesni_ecb_enc)
8255
8256 /*
8257 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8258@@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8259 popl KEYP
8260 popl LEN
8261 #endif
8262+ pax_force_retaddr 0, 1
8263 ret
8264+ENDPROC(aesni_ecb_dec)
8265
8266 /*
8267 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8268@@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8269 popl LEN
8270 popl IVP
8271 #endif
8272+ pax_force_retaddr 0, 1
8273 ret
8274+ENDPROC(aesni_cbc_enc)
8275
8276 /*
8277 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8278@@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
8279 popl LEN
8280 popl IVP
8281 #endif
8282+ pax_force_retaddr 0, 1
8283 ret
8284+ENDPROC(aesni_cbc_dec)
8285
8286 #ifdef __x86_64__
8287 .align 16
8288@@ -2526,6 +2553,7 @@ _aesni_inc_init:
8289 mov $1, TCTR_LOW
8290 MOVQ_R64_XMM TCTR_LOW INC
8291 MOVQ_R64_XMM CTR TCTR_LOW
8292+ pax_force_retaddr_bts
8293 ret
8294
8295 /*
8296@@ -2554,6 +2582,7 @@ _aesni_inc:
8297 .Linc_low:
8298 movaps CTR, IV
8299 PSHUFB_XMM BSWAP_MASK IV
8300+ pax_force_retaddr_bts
8301 ret
8302
8303 /*
8304@@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
8305 .Lctr_enc_ret:
8306 movups IV, (IVP)
8307 .Lctr_enc_just_ret:
8308+ pax_force_retaddr 0, 1
8309 ret
8310+ENDPROC(aesni_ctr_enc)
8311 #endif
8312diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8313index 391d245..67f35c2 100644
8314--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8315+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8316@@ -20,6 +20,8 @@
8317 *
8318 */
8319
8320+#include <asm/alternative-asm.h>
8321+
8322 .file "blowfish-x86_64-asm.S"
8323 .text
8324
8325@@ -151,9 +153,11 @@ __blowfish_enc_blk:
8326 jnz __enc_xor;
8327
8328 write_block();
8329+ pax_force_retaddr 0, 1
8330 ret;
8331 __enc_xor:
8332 xor_block();
8333+ pax_force_retaddr 0, 1
8334 ret;
8335
8336 .align 8
8337@@ -188,6 +192,7 @@ blowfish_dec_blk:
8338
8339 movq %r11, %rbp;
8340
8341+ pax_force_retaddr 0, 1
8342 ret;
8343
8344 /**********************************************************************
8345@@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8346
8347 popq %rbx;
8348 popq %rbp;
8349+ pax_force_retaddr 0, 1
8350 ret;
8351
8352 __enc_xor4:
8353@@ -349,6 +355,7 @@ __enc_xor4:
8354
8355 popq %rbx;
8356 popq %rbp;
8357+ pax_force_retaddr 0, 1
8358 ret;
8359
8360 .align 8
8361@@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8362 popq %rbx;
8363 popq %rbp;
8364
8365+ pax_force_retaddr 0, 1
8366 ret;
8367
8368diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
8369index 0b33743..7a56206 100644
8370--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
8371+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
8372@@ -20,6 +20,8 @@
8373 *
8374 */
8375
8376+#include <asm/alternative-asm.h>
8377+
8378 .file "camellia-x86_64-asm_64.S"
8379 .text
8380
8381@@ -229,12 +231,14 @@ __enc_done:
8382 enc_outunpack(mov, RT1);
8383
8384 movq RRBP, %rbp;
8385+ pax_force_retaddr 0, 1
8386 ret;
8387
8388 __enc_xor:
8389 enc_outunpack(xor, RT1);
8390
8391 movq RRBP, %rbp;
8392+ pax_force_retaddr 0, 1
8393 ret;
8394
8395 .global camellia_dec_blk;
8396@@ -275,6 +279,7 @@ __dec_rounds16:
8397 dec_outunpack();
8398
8399 movq RRBP, %rbp;
8400+ pax_force_retaddr 0, 1
8401 ret;
8402
8403 /**********************************************************************
8404@@ -468,6 +473,7 @@ __enc2_done:
8405
8406 movq RRBP, %rbp;
8407 popq %rbx;
8408+ pax_force_retaddr 0, 1
8409 ret;
8410
8411 __enc2_xor:
8412@@ -475,6 +481,7 @@ __enc2_xor:
8413
8414 movq RRBP, %rbp;
8415 popq %rbx;
8416+ pax_force_retaddr 0, 1
8417 ret;
8418
8419 .global camellia_dec_blk_2way;
8420@@ -517,4 +524,5 @@ __dec2_rounds16:
8421
8422 movq RRBP, %rbp;
8423 movq RXOR, %rbx;
8424+ pax_force_retaddr 0, 1
8425 ret;
8426diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8427index 6214a9b..1f4fc9a 100644
8428--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8429+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8430@@ -1,3 +1,5 @@
8431+#include <asm/alternative-asm.h>
8432+
8433 # enter ECRYPT_encrypt_bytes
8434 .text
8435 .p2align 5
8436@@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8437 add %r11,%rsp
8438 mov %rdi,%rax
8439 mov %rsi,%rdx
8440+ pax_force_retaddr 0, 1
8441 ret
8442 # bytesatleast65:
8443 ._bytesatleast65:
8444@@ -891,6 +894,7 @@ ECRYPT_keysetup:
8445 add %r11,%rsp
8446 mov %rdi,%rax
8447 mov %rsi,%rdx
8448+ pax_force_retaddr
8449 ret
8450 # enter ECRYPT_ivsetup
8451 .text
8452@@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8453 add %r11,%rsp
8454 mov %rdi,%rax
8455 mov %rsi,%rdx
8456+ pax_force_retaddr
8457 ret
8458diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8459index 3ee1ff0..cbc568b 100644
8460--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8461+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8462@@ -24,6 +24,8 @@
8463 *
8464 */
8465
8466+#include <asm/alternative-asm.h>
8467+
8468 .file "serpent-sse2-x86_64-asm_64.S"
8469 .text
8470
8471@@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
8472 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8473 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8474
8475+ pax_force_retaddr
8476 ret;
8477
8478 __enc_xor8:
8479 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8480 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8481
8482+ pax_force_retaddr
8483 ret;
8484
8485 .align 8
8486@@ -755,4 +759,5 @@ serpent_dec_blk_8way:
8487 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8488 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8489
8490+ pax_force_retaddr
8491 ret;
8492diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8493index b2c2f57..8470cab 100644
8494--- a/arch/x86/crypto/sha1_ssse3_asm.S
8495+++ b/arch/x86/crypto/sha1_ssse3_asm.S
8496@@ -28,6 +28,8 @@
8497 * (at your option) any later version.
8498 */
8499
8500+#include <asm/alternative-asm.h>
8501+
8502 #define CTX %rdi // arg1
8503 #define BUF %rsi // arg2
8504 #define CNT %rdx // arg3
8505@@ -104,6 +106,7 @@
8506 pop %r12
8507 pop %rbp
8508 pop %rbx
8509+ pax_force_retaddr 0, 1
8510 ret
8511
8512 .size \name, .-\name
8513diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8514index 5b012a2..36d5364 100644
8515--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8516+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8517@@ -20,6 +20,8 @@
8518 *
8519 */
8520
8521+#include <asm/alternative-asm.h>
8522+
8523 .file "twofish-x86_64-asm-3way.S"
8524 .text
8525
8526@@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8527 popq %r13;
8528 popq %r14;
8529 popq %r15;
8530+ pax_force_retaddr 0, 1
8531 ret;
8532
8533 __enc_xor3:
8534@@ -271,6 +274,7 @@ __enc_xor3:
8535 popq %r13;
8536 popq %r14;
8537 popq %r15;
8538+ pax_force_retaddr 0, 1
8539 ret;
8540
8541 .global twofish_dec_blk_3way
8542@@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8543 popq %r13;
8544 popq %r14;
8545 popq %r15;
8546+ pax_force_retaddr 0, 1
8547 ret;
8548
8549diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8550index 7bcf3fc..f53832f 100644
8551--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8552+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8553@@ -21,6 +21,7 @@
8554 .text
8555
8556 #include <asm/asm-offsets.h>
8557+#include <asm/alternative-asm.h>
8558
8559 #define a_offset 0
8560 #define b_offset 4
8561@@ -268,6 +269,7 @@ twofish_enc_blk:
8562
8563 popq R1
8564 movq $1,%rax
8565+ pax_force_retaddr 0, 1
8566 ret
8567
8568 twofish_dec_blk:
8569@@ -319,4 +321,5 @@ twofish_dec_blk:
8570
8571 popq R1
8572 movq $1,%rax
8573+ pax_force_retaddr 0, 1
8574 ret
8575diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8576index 07b3a68..bd2a388 100644
8577--- a/arch/x86/ia32/ia32_aout.c
8578+++ b/arch/x86/ia32/ia32_aout.c
8579@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8580 unsigned long dump_start, dump_size;
8581 struct user32 dump;
8582
8583+ memset(&dump, 0, sizeof(dump));
8584+
8585 fs = get_fs();
8586 set_fs(KERNEL_DS);
8587 has_dumped = 1;
8588diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8589index a69245b..6d145f4 100644
8590--- a/arch/x86/ia32/ia32_signal.c
8591+++ b/arch/x86/ia32/ia32_signal.c
8592@@ -168,7 +168,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8593 }
8594 seg = get_fs();
8595 set_fs(KERNEL_DS);
8596- ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8597+ ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8598 set_fs(seg);
8599 if (ret >= 0 && uoss_ptr) {
8600 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8601@@ -369,7 +369,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8602 */
8603 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8604 size_t frame_size,
8605- void **fpstate)
8606+ void __user **fpstate)
8607 {
8608 unsigned long sp;
8609
8610@@ -390,7 +390,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8611
8612 if (used_math()) {
8613 sp = sp - sig_xstate_ia32_size;
8614- *fpstate = (struct _fpstate_ia32 *) sp;
8615+ *fpstate = (struct _fpstate_ia32 __user *) sp;
8616 if (save_i387_xstate_ia32(*fpstate) < 0)
8617 return (void __user *) -1L;
8618 }
8619@@ -398,7 +398,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8620 sp -= frame_size;
8621 /* Align the stack pointer according to the i386 ABI,
8622 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8623- sp = ((sp + 4) & -16ul) - 4;
8624+ sp = ((sp - 12) & -16ul) - 4;
8625 return (void __user *) sp;
8626 }
8627
8628@@ -456,7 +456,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8629 * These are actually not used anymore, but left because some
8630 * gdb versions depend on them as a marker.
8631 */
8632- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8633+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8634 } put_user_catch(err);
8635
8636 if (err)
8637@@ -498,7 +498,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8638 0xb8,
8639 __NR_ia32_rt_sigreturn,
8640 0x80cd,
8641- 0,
8642+ 0
8643 };
8644
8645 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8646@@ -528,16 +528,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8647
8648 if (ka->sa.sa_flags & SA_RESTORER)
8649 restorer = ka->sa.sa_restorer;
8650+ else if (current->mm->context.vdso)
8651+ /* Return stub is in 32bit vsyscall page */
8652+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8653 else
8654- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8655- rt_sigreturn);
8656+ restorer = &frame->retcode;
8657 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8658
8659 /*
8660 * Not actually used anymore, but left because some gdb
8661 * versions need it.
8662 */
8663- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8664+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8665 } put_user_catch(err);
8666
8667 if (err)
8668diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8669index e3e7340..05ed805 100644
8670--- a/arch/x86/ia32/ia32entry.S
8671+++ b/arch/x86/ia32/ia32entry.S
8672@@ -13,8 +13,10 @@
8673 #include <asm/thread_info.h>
8674 #include <asm/segment.h>
8675 #include <asm/irqflags.h>
8676+#include <asm/pgtable.h>
8677 #include <linux/linkage.h>
8678 #include <linux/err.h>
8679+#include <asm/alternative-asm.h>
8680
8681 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8682 #include <linux/elf-em.h>
8683@@ -94,6 +96,32 @@ ENTRY(native_irq_enable_sysexit)
8684 ENDPROC(native_irq_enable_sysexit)
8685 #endif
8686
8687+ .macro pax_enter_kernel_user
8688+ pax_set_fptr_mask
8689+#ifdef CONFIG_PAX_MEMORY_UDEREF
8690+ call pax_enter_kernel_user
8691+#endif
8692+ .endm
8693+
8694+ .macro pax_exit_kernel_user
8695+#ifdef CONFIG_PAX_MEMORY_UDEREF
8696+ call pax_exit_kernel_user
8697+#endif
8698+#ifdef CONFIG_PAX_RANDKSTACK
8699+ pushq %rax
8700+ pushq %r11
8701+ call pax_randomize_kstack
8702+ popq %r11
8703+ popq %rax
8704+#endif
8705+ .endm
8706+
8707+.macro pax_erase_kstack
8708+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8709+ call pax_erase_kstack
8710+#endif
8711+.endm
8712+
8713 /*
8714 * 32bit SYSENTER instruction entry.
8715 *
8716@@ -120,12 +148,6 @@ ENTRY(ia32_sysenter_target)
8717 CFI_REGISTER rsp,rbp
8718 SWAPGS_UNSAFE_STACK
8719 movq PER_CPU_VAR(kernel_stack), %rsp
8720- addq $(KERNEL_STACK_OFFSET),%rsp
8721- /*
8722- * No need to follow this irqs on/off section: the syscall
8723- * disabled irqs, here we enable it straight after entry:
8724- */
8725- ENABLE_INTERRUPTS(CLBR_NONE)
8726 movl %ebp,%ebp /* zero extension */
8727 pushq_cfi $__USER32_DS
8728 /*CFI_REL_OFFSET ss,0*/
8729@@ -133,24 +155,39 @@ ENTRY(ia32_sysenter_target)
8730 CFI_REL_OFFSET rsp,0
8731 pushfq_cfi
8732 /*CFI_REL_OFFSET rflags,0*/
8733- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8734- CFI_REGISTER rip,r10
8735+ orl $X86_EFLAGS_IF,(%rsp)
8736+ GET_THREAD_INFO(%r11)
8737+ movl TI_sysenter_return(%r11), %r11d
8738+ CFI_REGISTER rip,r11
8739 pushq_cfi $__USER32_CS
8740 /*CFI_REL_OFFSET cs,0*/
8741 movl %eax, %eax
8742- pushq_cfi %r10
8743+ pushq_cfi %r11
8744 CFI_REL_OFFSET rip,0
8745 pushq_cfi %rax
8746 cld
8747 SAVE_ARGS 0,1,0
8748+ pax_enter_kernel_user
8749+ /*
8750+ * No need to follow this irqs on/off section: the syscall
8751+ * disabled irqs, here we enable it straight after entry:
8752+ */
8753+ ENABLE_INTERRUPTS(CLBR_NONE)
8754 /* no need to do an access_ok check here because rbp has been
8755 32bit zero extended */
8756+
8757+#ifdef CONFIG_PAX_MEMORY_UDEREF
8758+ mov $PAX_USER_SHADOW_BASE,%r11
8759+ add %r11,%rbp
8760+#endif
8761+
8762 1: movl (%rbp),%ebp
8763 .section __ex_table,"a"
8764 .quad 1b,ia32_badarg
8765 .previous
8766- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8767- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8768+ GET_THREAD_INFO(%r11)
8769+ orl $TS_COMPAT,TI_status(%r11)
8770+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8771 CFI_REMEMBER_STATE
8772 jnz sysenter_tracesys
8773 cmpq $(IA32_NR_syscalls-1),%rax
8774@@ -160,12 +197,15 @@ sysenter_do_call:
8775 sysenter_dispatch:
8776 call *ia32_sys_call_table(,%rax,8)
8777 movq %rax,RAX-ARGOFFSET(%rsp)
8778+ GET_THREAD_INFO(%r11)
8779 DISABLE_INTERRUPTS(CLBR_NONE)
8780 TRACE_IRQS_OFF
8781- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8782+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8783 jnz sysexit_audit
8784 sysexit_from_sys_call:
8785- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8786+ pax_exit_kernel_user
8787+ pax_erase_kstack
8788+ andl $~TS_COMPAT,TI_status(%r11)
8789 /* clear IF, that popfq doesn't enable interrupts early */
8790 andl $~0x200,EFLAGS-R11(%rsp)
8791 movl RIP-R11(%rsp),%edx /* User %eip */
8792@@ -191,6 +231,9 @@ sysexit_from_sys_call:
8793 movl %eax,%esi /* 2nd arg: syscall number */
8794 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8795 call __audit_syscall_entry
8796+
8797+ pax_erase_kstack
8798+
8799 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8800 cmpq $(IA32_NR_syscalls-1),%rax
8801 ja ia32_badsys
8802@@ -202,7 +245,7 @@ sysexit_from_sys_call:
8803 .endm
8804
8805 .macro auditsys_exit exit
8806- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8807+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8808 jnz ia32_ret_from_sys_call
8809 TRACE_IRQS_ON
8810 sti
8811@@ -213,11 +256,12 @@ sysexit_from_sys_call:
8812 1: setbe %al /* 1 if error, 0 if not */
8813 movzbl %al,%edi /* zero-extend that into %edi */
8814 call __audit_syscall_exit
8815+ GET_THREAD_INFO(%r11)
8816 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8817 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8818 cli
8819 TRACE_IRQS_OFF
8820- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8821+ testl %edi,TI_flags(%r11)
8822 jz \exit
8823 CLEAR_RREGS -ARGOFFSET
8824 jmp int_with_check
8825@@ -235,7 +279,7 @@ sysexit_audit:
8826
8827 sysenter_tracesys:
8828 #ifdef CONFIG_AUDITSYSCALL
8829- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8830+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8831 jz sysenter_auditsys
8832 #endif
8833 SAVE_REST
8834@@ -243,6 +287,9 @@ sysenter_tracesys:
8835 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
8836 movq %rsp,%rdi /* &pt_regs -> arg1 */
8837 call syscall_trace_enter
8838+
8839+ pax_erase_kstack
8840+
8841 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8842 RESTORE_REST
8843 cmpq $(IA32_NR_syscalls-1),%rax
8844@@ -274,19 +321,20 @@ ENDPROC(ia32_sysenter_target)
8845 ENTRY(ia32_cstar_target)
8846 CFI_STARTPROC32 simple
8847 CFI_SIGNAL_FRAME
8848- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8849+ CFI_DEF_CFA rsp,0
8850 CFI_REGISTER rip,rcx
8851 /*CFI_REGISTER rflags,r11*/
8852 SWAPGS_UNSAFE_STACK
8853 movl %esp,%r8d
8854 CFI_REGISTER rsp,r8
8855 movq PER_CPU_VAR(kernel_stack),%rsp
8856+ SAVE_ARGS 8*6,0,0
8857+ pax_enter_kernel_user
8858 /*
8859 * No need to follow this irqs on/off section: the syscall
8860 * disabled irqs and here we enable it straight after entry:
8861 */
8862 ENABLE_INTERRUPTS(CLBR_NONE)
8863- SAVE_ARGS 8,0,0
8864 movl %eax,%eax /* zero extension */
8865 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8866 movq %rcx,RIP-ARGOFFSET(%rsp)
8867@@ -302,12 +350,19 @@ ENTRY(ia32_cstar_target)
8868 /* no need to do an access_ok check here because r8 has been
8869 32bit zero extended */
8870 /* hardware stack frame is complete now */
8871+
8872+#ifdef CONFIG_PAX_MEMORY_UDEREF
8873+ mov $PAX_USER_SHADOW_BASE,%r11
8874+ add %r11,%r8
8875+#endif
8876+
8877 1: movl (%r8),%r9d
8878 .section __ex_table,"a"
8879 .quad 1b,ia32_badarg
8880 .previous
8881- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8882- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8883+ GET_THREAD_INFO(%r11)
8884+ orl $TS_COMPAT,TI_status(%r11)
8885+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8886 CFI_REMEMBER_STATE
8887 jnz cstar_tracesys
8888 cmpq $IA32_NR_syscalls-1,%rax
8889@@ -317,12 +372,15 @@ cstar_do_call:
8890 cstar_dispatch:
8891 call *ia32_sys_call_table(,%rax,8)
8892 movq %rax,RAX-ARGOFFSET(%rsp)
8893+ GET_THREAD_INFO(%r11)
8894 DISABLE_INTERRUPTS(CLBR_NONE)
8895 TRACE_IRQS_OFF
8896- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8897+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8898 jnz sysretl_audit
8899 sysretl_from_sys_call:
8900- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8901+ pax_exit_kernel_user
8902+ pax_erase_kstack
8903+ andl $~TS_COMPAT,TI_status(%r11)
8904 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8905 movl RIP-ARGOFFSET(%rsp),%ecx
8906 CFI_REGISTER rip,rcx
8907@@ -350,7 +408,7 @@ sysretl_audit:
8908
8909 cstar_tracesys:
8910 #ifdef CONFIG_AUDITSYSCALL
8911- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8912+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8913 jz cstar_auditsys
8914 #endif
8915 xchgl %r9d,%ebp
8916@@ -359,6 +417,9 @@ cstar_tracesys:
8917 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8918 movq %rsp,%rdi /* &pt_regs -> arg1 */
8919 call syscall_trace_enter
8920+
8921+ pax_erase_kstack
8922+
8923 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
8924 RESTORE_REST
8925 xchgl %ebp,%r9d
8926@@ -404,19 +465,21 @@ ENTRY(ia32_syscall)
8927 CFI_REL_OFFSET rip,RIP-RIP
8928 PARAVIRT_ADJUST_EXCEPTION_FRAME
8929 SWAPGS
8930- /*
8931- * No need to follow this irqs on/off section: the syscall
8932- * disabled irqs and here we enable it straight after entry:
8933- */
8934- ENABLE_INTERRUPTS(CLBR_NONE)
8935 movl %eax,%eax
8936 pushq_cfi %rax
8937 cld
8938 /* note the registers are not zero extended to the sf.
8939 this could be a problem. */
8940 SAVE_ARGS 0,1,0
8941- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8942- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8943+ pax_enter_kernel_user
8944+ /*
8945+ * No need to follow this irqs on/off section: the syscall
8946+ * disabled irqs and here we enable it straight after entry:
8947+ */
8948+ ENABLE_INTERRUPTS(CLBR_NONE)
8949+ GET_THREAD_INFO(%r11)
8950+ orl $TS_COMPAT,TI_status(%r11)
8951+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8952 jnz ia32_tracesys
8953 cmpq $(IA32_NR_syscalls-1),%rax
8954 ja ia32_badsys
8955@@ -435,6 +498,9 @@ ia32_tracesys:
8956 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8957 movq %rsp,%rdi /* &pt_regs -> arg1 */
8958 call syscall_trace_enter
8959+
8960+ pax_erase_kstack
8961+
8962 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8963 RESTORE_REST
8964 cmpq $(IA32_NR_syscalls-1),%rax
8965diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8966index aec2202..f76174e 100644
8967--- a/arch/x86/ia32/sys_ia32.c
8968+++ b/arch/x86/ia32/sys_ia32.c
8969@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8970 */
8971 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8972 {
8973- typeof(ubuf->st_uid) uid = 0;
8974- typeof(ubuf->st_gid) gid = 0;
8975+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
8976+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
8977 SET_UID(uid, stat->uid);
8978 SET_GID(gid, stat->gid);
8979 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8980@@ -292,7 +292,7 @@ asmlinkage long sys32_alarm(unsigned int seconds)
8981 return alarm_setitimer(seconds);
8982 }
8983
8984-asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
8985+asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
8986 int options)
8987 {
8988 return compat_sys_wait4(pid, stat_addr, options, NULL);
8989@@ -313,7 +313,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8990 mm_segment_t old_fs = get_fs();
8991
8992 set_fs(KERNEL_DS);
8993- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8994+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
8995 set_fs(old_fs);
8996 if (put_compat_timespec(&t, interval))
8997 return -EFAULT;
8998@@ -329,7 +329,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
8999 mm_segment_t old_fs = get_fs();
9000
9001 set_fs(KERNEL_DS);
9002- ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
9003+ ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
9004 set_fs(old_fs);
9005 if (!ret) {
9006 switch (_NSIG_WORDS) {
9007@@ -354,7 +354,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
9008 if (copy_siginfo_from_user32(&info, uinfo))
9009 return -EFAULT;
9010 set_fs(KERNEL_DS);
9011- ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
9012+ ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
9013 set_fs(old_fs);
9014 return ret;
9015 }
9016@@ -399,7 +399,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
9017 return -EFAULT;
9018
9019 set_fs(KERNEL_DS);
9020- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
9021+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
9022 count);
9023 set_fs(old_fs);
9024
9025diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
9026index 952bd01..7692c6f 100644
9027--- a/arch/x86/include/asm/alternative-asm.h
9028+++ b/arch/x86/include/asm/alternative-asm.h
9029@@ -15,6 +15,45 @@
9030 .endm
9031 #endif
9032
9033+#ifdef KERNEXEC_PLUGIN
9034+ .macro pax_force_retaddr_bts rip=0
9035+ btsq $63,\rip(%rsp)
9036+ .endm
9037+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9038+ .macro pax_force_retaddr rip=0, reload=0
9039+ btsq $63,\rip(%rsp)
9040+ .endm
9041+ .macro pax_force_fptr ptr
9042+ btsq $63,\ptr
9043+ .endm
9044+ .macro pax_set_fptr_mask
9045+ .endm
9046+#endif
9047+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
9048+ .macro pax_force_retaddr rip=0, reload=0
9049+ .if \reload
9050+ pax_set_fptr_mask
9051+ .endif
9052+ orq %r10,\rip(%rsp)
9053+ .endm
9054+ .macro pax_force_fptr ptr
9055+ orq %r10,\ptr
9056+ .endm
9057+ .macro pax_set_fptr_mask
9058+ movabs $0x8000000000000000,%r10
9059+ .endm
9060+#endif
9061+#else
9062+ .macro pax_force_retaddr rip=0, reload=0
9063+ .endm
9064+ .macro pax_force_fptr ptr
9065+ .endm
9066+ .macro pax_force_retaddr_bts rip=0
9067+ .endm
9068+ .macro pax_set_fptr_mask
9069+ .endm
9070+#endif
9071+
9072 .macro altinstruction_entry orig alt feature orig_len alt_len
9073 .long \orig - .
9074 .long \alt - .
9075diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9076index 49331be..9706065 100644
9077--- a/arch/x86/include/asm/alternative.h
9078+++ b/arch/x86/include/asm/alternative.h
9079@@ -89,7 +89,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9080 ".section .discard,\"aw\",@progbits\n" \
9081 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
9082 ".previous\n" \
9083- ".section .altinstr_replacement, \"ax\"\n" \
9084+ ".section .altinstr_replacement, \"a\"\n" \
9085 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
9086 ".previous"
9087
9088diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9089index d854101..f6ea947 100644
9090--- a/arch/x86/include/asm/apic.h
9091+++ b/arch/x86/include/asm/apic.h
9092@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9093
9094 #ifdef CONFIG_X86_LOCAL_APIC
9095
9096-extern unsigned int apic_verbosity;
9097+extern int apic_verbosity;
9098 extern int local_apic_timer_c2_ok;
9099
9100 extern int disable_apic;
9101diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9102index 20370c6..a2eb9b0 100644
9103--- a/arch/x86/include/asm/apm.h
9104+++ b/arch/x86/include/asm/apm.h
9105@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9106 __asm__ __volatile__(APM_DO_ZERO_SEGS
9107 "pushl %%edi\n\t"
9108 "pushl %%ebp\n\t"
9109- "lcall *%%cs:apm_bios_entry\n\t"
9110+ "lcall *%%ss:apm_bios_entry\n\t"
9111 "setc %%al\n\t"
9112 "popl %%ebp\n\t"
9113 "popl %%edi\n\t"
9114@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9115 __asm__ __volatile__(APM_DO_ZERO_SEGS
9116 "pushl %%edi\n\t"
9117 "pushl %%ebp\n\t"
9118- "lcall *%%cs:apm_bios_entry\n\t"
9119+ "lcall *%%ss:apm_bios_entry\n\t"
9120 "setc %%bl\n\t"
9121 "popl %%ebp\n\t"
9122 "popl %%edi\n\t"
9123diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9124index 58cb6d4..ca9010d 100644
9125--- a/arch/x86/include/asm/atomic.h
9126+++ b/arch/x86/include/asm/atomic.h
9127@@ -22,7 +22,18 @@
9128 */
9129 static inline int atomic_read(const atomic_t *v)
9130 {
9131- return (*(volatile int *)&(v)->counter);
9132+ return (*(volatile const int *)&(v)->counter);
9133+}
9134+
9135+/**
9136+ * atomic_read_unchecked - read atomic variable
9137+ * @v: pointer of type atomic_unchecked_t
9138+ *
9139+ * Atomically reads the value of @v.
9140+ */
9141+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9142+{
9143+ return (*(volatile const int *)&(v)->counter);
9144 }
9145
9146 /**
9147@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9148 }
9149
9150 /**
9151+ * atomic_set_unchecked - set atomic variable
9152+ * @v: pointer of type atomic_unchecked_t
9153+ * @i: required value
9154+ *
9155+ * Atomically sets the value of @v to @i.
9156+ */
9157+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9158+{
9159+ v->counter = i;
9160+}
9161+
9162+/**
9163 * atomic_add - add integer to atomic variable
9164 * @i: integer value to add
9165 * @v: pointer of type atomic_t
9166@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9167 */
9168 static inline void atomic_add(int i, atomic_t *v)
9169 {
9170- asm volatile(LOCK_PREFIX "addl %1,%0"
9171+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
9172+
9173+#ifdef CONFIG_PAX_REFCOUNT
9174+ "jno 0f\n"
9175+ LOCK_PREFIX "subl %1,%0\n"
9176+ "int $4\n0:\n"
9177+ _ASM_EXTABLE(0b, 0b)
9178+#endif
9179+
9180+ : "+m" (v->counter)
9181+ : "ir" (i));
9182+}
9183+
9184+/**
9185+ * atomic_add_unchecked - add integer to atomic variable
9186+ * @i: integer value to add
9187+ * @v: pointer of type atomic_unchecked_t
9188+ *
9189+ * Atomically adds @i to @v.
9190+ */
9191+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9192+{
9193+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
9194 : "+m" (v->counter)
9195 : "ir" (i));
9196 }
9197@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9198 */
9199 static inline void atomic_sub(int i, atomic_t *v)
9200 {
9201- asm volatile(LOCK_PREFIX "subl %1,%0"
9202+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
9203+
9204+#ifdef CONFIG_PAX_REFCOUNT
9205+ "jno 0f\n"
9206+ LOCK_PREFIX "addl %1,%0\n"
9207+ "int $4\n0:\n"
9208+ _ASM_EXTABLE(0b, 0b)
9209+#endif
9210+
9211+ : "+m" (v->counter)
9212+ : "ir" (i));
9213+}
9214+
9215+/**
9216+ * atomic_sub_unchecked - subtract integer from atomic variable
9217+ * @i: integer value to subtract
9218+ * @v: pointer of type atomic_unchecked_t
9219+ *
9220+ * Atomically subtracts @i from @v.
9221+ */
9222+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9223+{
9224+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
9225 : "+m" (v->counter)
9226 : "ir" (i));
9227 }
9228@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9229 {
9230 unsigned char c;
9231
9232- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9233+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
9234+
9235+#ifdef CONFIG_PAX_REFCOUNT
9236+ "jno 0f\n"
9237+ LOCK_PREFIX "addl %2,%0\n"
9238+ "int $4\n0:\n"
9239+ _ASM_EXTABLE(0b, 0b)
9240+#endif
9241+
9242+ "sete %1\n"
9243 : "+m" (v->counter), "=qm" (c)
9244 : "ir" (i) : "memory");
9245 return c;
9246@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9247 */
9248 static inline void atomic_inc(atomic_t *v)
9249 {
9250- asm volatile(LOCK_PREFIX "incl %0"
9251+ asm volatile(LOCK_PREFIX "incl %0\n"
9252+
9253+#ifdef CONFIG_PAX_REFCOUNT
9254+ "jno 0f\n"
9255+ LOCK_PREFIX "decl %0\n"
9256+ "int $4\n0:\n"
9257+ _ASM_EXTABLE(0b, 0b)
9258+#endif
9259+
9260+ : "+m" (v->counter));
9261+}
9262+
9263+/**
9264+ * atomic_inc_unchecked - increment atomic variable
9265+ * @v: pointer of type atomic_unchecked_t
9266+ *
9267+ * Atomically increments @v by 1.
9268+ */
9269+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9270+{
9271+ asm volatile(LOCK_PREFIX "incl %0\n"
9272 : "+m" (v->counter));
9273 }
9274
9275@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9276 */
9277 static inline void atomic_dec(atomic_t *v)
9278 {
9279- asm volatile(LOCK_PREFIX "decl %0"
9280+ asm volatile(LOCK_PREFIX "decl %0\n"
9281+
9282+#ifdef CONFIG_PAX_REFCOUNT
9283+ "jno 0f\n"
9284+ LOCK_PREFIX "incl %0\n"
9285+ "int $4\n0:\n"
9286+ _ASM_EXTABLE(0b, 0b)
9287+#endif
9288+
9289+ : "+m" (v->counter));
9290+}
9291+
9292+/**
9293+ * atomic_dec_unchecked - decrement atomic variable
9294+ * @v: pointer of type atomic_unchecked_t
9295+ *
9296+ * Atomically decrements @v by 1.
9297+ */
9298+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9299+{
9300+ asm volatile(LOCK_PREFIX "decl %0\n"
9301 : "+m" (v->counter));
9302 }
9303
9304@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9305 {
9306 unsigned char c;
9307
9308- asm volatile(LOCK_PREFIX "decl %0; sete %1"
9309+ asm volatile(LOCK_PREFIX "decl %0\n"
9310+
9311+#ifdef CONFIG_PAX_REFCOUNT
9312+ "jno 0f\n"
9313+ LOCK_PREFIX "incl %0\n"
9314+ "int $4\n0:\n"
9315+ _ASM_EXTABLE(0b, 0b)
9316+#endif
9317+
9318+ "sete %1\n"
9319 : "+m" (v->counter), "=qm" (c)
9320 : : "memory");
9321 return c != 0;
9322@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9323 {
9324 unsigned char c;
9325
9326- asm volatile(LOCK_PREFIX "incl %0; sete %1"
9327+ asm volatile(LOCK_PREFIX "incl %0\n"
9328+
9329+#ifdef CONFIG_PAX_REFCOUNT
9330+ "jno 0f\n"
9331+ LOCK_PREFIX "decl %0\n"
9332+ "int $4\n0:\n"
9333+ _ASM_EXTABLE(0b, 0b)
9334+#endif
9335+
9336+ "sete %1\n"
9337+ : "+m" (v->counter), "=qm" (c)
9338+ : : "memory");
9339+ return c != 0;
9340+}
9341+
9342+/**
9343+ * atomic_inc_and_test_unchecked - increment and test
9344+ * @v: pointer of type atomic_unchecked_t
9345+ *
9346+ * Atomically increments @v by 1
9347+ * and returns true if the result is zero, or false for all
9348+ * other cases.
9349+ */
9350+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9351+{
9352+ unsigned char c;
9353+
9354+ asm volatile(LOCK_PREFIX "incl %0\n"
9355+ "sete %1\n"
9356 : "+m" (v->counter), "=qm" (c)
9357 : : "memory");
9358 return c != 0;
9359@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9360 {
9361 unsigned char c;
9362
9363- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9364+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
9365+
9366+#ifdef CONFIG_PAX_REFCOUNT
9367+ "jno 0f\n"
9368+ LOCK_PREFIX "subl %2,%0\n"
9369+ "int $4\n0:\n"
9370+ _ASM_EXTABLE(0b, 0b)
9371+#endif
9372+
9373+ "sets %1\n"
9374 : "+m" (v->counter), "=qm" (c)
9375 : "ir" (i) : "memory");
9376 return c;
9377@@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9378 goto no_xadd;
9379 #endif
9380 /* Modern 486+ processor */
9381- return i + xadd(&v->counter, i);
9382+ return i + xadd_check_overflow(&v->counter, i);
9383
9384 #ifdef CONFIG_M386
9385 no_xadd: /* Legacy 386 processor */
9386@@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9387 }
9388
9389 /**
9390+ * atomic_add_return_unchecked - add integer and return
9391+ * @i: integer value to add
9392+ * @v: pointer of type atomic_unchecked_t
9393+ *
9394+ * Atomically adds @i to @v and returns @i + @v
9395+ */
9396+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9397+{
9398+#ifdef CONFIG_M386
9399+ int __i;
9400+ unsigned long flags;
9401+ if (unlikely(boot_cpu_data.x86 <= 3))
9402+ goto no_xadd;
9403+#endif
9404+ /* Modern 486+ processor */
9405+ return i + xadd(&v->counter, i);
9406+
9407+#ifdef CONFIG_M386
9408+no_xadd: /* Legacy 386 processor */
9409+ raw_local_irq_save(flags);
9410+ __i = atomic_read_unchecked(v);
9411+ atomic_set_unchecked(v, i + __i);
9412+ raw_local_irq_restore(flags);
9413+ return i + __i;
9414+#endif
9415+}
9416+
9417+/**
9418 * atomic_sub_return - subtract integer and return
9419 * @v: pointer of type atomic_t
9420 * @i: integer value to subtract
9421@@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9422 }
9423
9424 #define atomic_inc_return(v) (atomic_add_return(1, v))
9425+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9426+{
9427+ return atomic_add_return_unchecked(1, v);
9428+}
9429 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9430
9431 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9432@@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9433 return cmpxchg(&v->counter, old, new);
9434 }
9435
9436+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9437+{
9438+ return cmpxchg(&v->counter, old, new);
9439+}
9440+
9441 static inline int atomic_xchg(atomic_t *v, int new)
9442 {
9443 return xchg(&v->counter, new);
9444 }
9445
9446+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9447+{
9448+ return xchg(&v->counter, new);
9449+}
9450+
9451 /**
9452 * __atomic_add_unless - add unless the number is already a given value
9453 * @v: pointer of type atomic_t
9454@@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9455 */
9456 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9457 {
9458- int c, old;
9459+ int c, old, new;
9460 c = atomic_read(v);
9461 for (;;) {
9462- if (unlikely(c == (u)))
9463+ if (unlikely(c == u))
9464 break;
9465- old = atomic_cmpxchg((v), c, c + (a));
9466+
9467+ asm volatile("addl %2,%0\n"
9468+
9469+#ifdef CONFIG_PAX_REFCOUNT
9470+ "jno 0f\n"
9471+ "subl %2,%0\n"
9472+ "int $4\n0:\n"
9473+ _ASM_EXTABLE(0b, 0b)
9474+#endif
9475+
9476+ : "=r" (new)
9477+ : "0" (c), "ir" (a));
9478+
9479+ old = atomic_cmpxchg(v, c, new);
9480 if (likely(old == c))
9481 break;
9482 c = old;
9483@@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9484 return c;
9485 }
9486
9487+/**
9488+ * atomic_inc_not_zero_hint - increment if not null
9489+ * @v: pointer of type atomic_t
9490+ * @hint: probable value of the atomic before the increment
9491+ *
9492+ * This version of atomic_inc_not_zero() gives a hint of probable
9493+ * value of the atomic. This helps processor to not read the memory
9494+ * before doing the atomic read/modify/write cycle, lowering
9495+ * number of bus transactions on some arches.
9496+ *
9497+ * Returns: 0 if increment was not done, 1 otherwise.
9498+ */
9499+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9500+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9501+{
9502+ int val, c = hint, new;
9503+
9504+ /* sanity test, should be removed by compiler if hint is a constant */
9505+ if (!hint)
9506+ return __atomic_add_unless(v, 1, 0);
9507+
9508+ do {
9509+ asm volatile("incl %0\n"
9510+
9511+#ifdef CONFIG_PAX_REFCOUNT
9512+ "jno 0f\n"
9513+ "decl %0\n"
9514+ "int $4\n0:\n"
9515+ _ASM_EXTABLE(0b, 0b)
9516+#endif
9517+
9518+ : "=r" (new)
9519+ : "0" (c));
9520+
9521+ val = atomic_cmpxchg(v, c, new);
9522+ if (val == c)
9523+ return 1;
9524+ c = val;
9525+ } while (c);
9526+
9527+ return 0;
9528+}
9529
9530 /*
9531 * atomic_dec_if_positive - decrement by 1 if old value positive
9532diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9533index 1981199..36b9dfb 100644
9534--- a/arch/x86/include/asm/atomic64_32.h
9535+++ b/arch/x86/include/asm/atomic64_32.h
9536@@ -12,6 +12,14 @@ typedef struct {
9537 u64 __aligned(8) counter;
9538 } atomic64_t;
9539
9540+#ifdef CONFIG_PAX_REFCOUNT
9541+typedef struct {
9542+ u64 __aligned(8) counter;
9543+} atomic64_unchecked_t;
9544+#else
9545+typedef atomic64_t atomic64_unchecked_t;
9546+#endif
9547+
9548 #define ATOMIC64_INIT(val) { (val) }
9549
9550 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
9551@@ -37,21 +45,31 @@ typedef struct {
9552 ATOMIC64_DECL_ONE(sym##_386)
9553
9554 ATOMIC64_DECL_ONE(add_386);
9555+ATOMIC64_DECL_ONE(add_unchecked_386);
9556 ATOMIC64_DECL_ONE(sub_386);
9557+ATOMIC64_DECL_ONE(sub_unchecked_386);
9558 ATOMIC64_DECL_ONE(inc_386);
9559+ATOMIC64_DECL_ONE(inc_unchecked_386);
9560 ATOMIC64_DECL_ONE(dec_386);
9561+ATOMIC64_DECL_ONE(dec_unchecked_386);
9562 #endif
9563
9564 #define alternative_atomic64(f, out, in...) \
9565 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
9566
9567 ATOMIC64_DECL(read);
9568+ATOMIC64_DECL(read_unchecked);
9569 ATOMIC64_DECL(set);
9570+ATOMIC64_DECL(set_unchecked);
9571 ATOMIC64_DECL(xchg);
9572 ATOMIC64_DECL(add_return);
9573+ATOMIC64_DECL(add_return_unchecked);
9574 ATOMIC64_DECL(sub_return);
9575+ATOMIC64_DECL(sub_return_unchecked);
9576 ATOMIC64_DECL(inc_return);
9577+ATOMIC64_DECL(inc_return_unchecked);
9578 ATOMIC64_DECL(dec_return);
9579+ATOMIC64_DECL(dec_return_unchecked);
9580 ATOMIC64_DECL(dec_if_positive);
9581 ATOMIC64_DECL(inc_not_zero);
9582 ATOMIC64_DECL(add_unless);
9583@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9584 }
9585
9586 /**
9587+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9588+ * @p: pointer to type atomic64_unchecked_t
9589+ * @o: expected value
9590+ * @n: new value
9591+ *
9592+ * Atomically sets @v to @n if it was equal to @o and returns
9593+ * the old value.
9594+ */
9595+
9596+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9597+{
9598+ return cmpxchg64(&v->counter, o, n);
9599+}
9600+
9601+/**
9602 * atomic64_xchg - xchg atomic64 variable
9603 * @v: pointer to type atomic64_t
9604 * @n: value to assign
9605@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9606 }
9607
9608 /**
9609+ * atomic64_set_unchecked - set atomic64 variable
9610+ * @v: pointer to type atomic64_unchecked_t
9611+ * @n: value to assign
9612+ *
9613+ * Atomically sets the value of @v to @n.
9614+ */
9615+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9616+{
9617+ unsigned high = (unsigned)(i >> 32);
9618+ unsigned low = (unsigned)i;
9619+ alternative_atomic64(set, /* no output */,
9620+ "S" (v), "b" (low), "c" (high)
9621+ : "eax", "edx", "memory");
9622+}
9623+
9624+/**
9625 * atomic64_read - read atomic64 variable
9626 * @v: pointer to type atomic64_t
9627 *
9628@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
9629 }
9630
9631 /**
9632+ * atomic64_read_unchecked - read atomic64 variable
9633+ * @v: pointer to type atomic64_unchecked_t
9634+ *
9635+ * Atomically reads the value of @v and returns it.
9636+ */
9637+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9638+{
9639+ long long r;
9640+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
9641+ return r;
9642+ }
9643+
9644+/**
9645 * atomic64_add_return - add and return
9646 * @i: integer value to add
9647 * @v: pointer to type atomic64_t
9648@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9649 return i;
9650 }
9651
9652+/**
9653+ * atomic64_add_return_unchecked - add and return
9654+ * @i: integer value to add
9655+ * @v: pointer to type atomic64_unchecked_t
9656+ *
9657+ * Atomically adds @i to @v and returns @i + *@v
9658+ */
9659+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9660+{
9661+ alternative_atomic64(add_return_unchecked,
9662+ ASM_OUTPUT2("+A" (i), "+c" (v)),
9663+ ASM_NO_INPUT_CLOBBER("memory"));
9664+ return i;
9665+}
9666+
9667 /*
9668 * Other variants with different arithmetic operators:
9669 */
9670@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9671 return a;
9672 }
9673
9674+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9675+{
9676+ long long a;
9677+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
9678+ "S" (v) : "memory", "ecx");
9679+ return a;
9680+}
9681+
9682 static inline long long atomic64_dec_return(atomic64_t *v)
9683 {
9684 long long a;
9685@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9686 }
9687
9688 /**
9689+ * atomic64_add_unchecked - add integer to atomic64 variable
9690+ * @i: integer value to add
9691+ * @v: pointer to type atomic64_unchecked_t
9692+ *
9693+ * Atomically adds @i to @v.
9694+ */
9695+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9696+{
9697+ __alternative_atomic64(add_unchecked, add_return_unchecked,
9698+ ASM_OUTPUT2("+A" (i), "+c" (v)),
9699+ ASM_NO_INPUT_CLOBBER("memory"));
9700+ return i;
9701+}
9702+
9703+/**
9704 * atomic64_sub - subtract the atomic64 variable
9705 * @i: integer value to subtract
9706 * @v: pointer to type atomic64_t
9707diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9708index 0e1cbfc..5623683 100644
9709--- a/arch/x86/include/asm/atomic64_64.h
9710+++ b/arch/x86/include/asm/atomic64_64.h
9711@@ -18,7 +18,19 @@
9712 */
9713 static inline long atomic64_read(const atomic64_t *v)
9714 {
9715- return (*(volatile long *)&(v)->counter);
9716+ return (*(volatile const long *)&(v)->counter);
9717+}
9718+
9719+/**
9720+ * atomic64_read_unchecked - read atomic64 variable
9721+ * @v: pointer of type atomic64_unchecked_t
9722+ *
9723+ * Atomically reads the value of @v.
9724+ * Doesn't imply a read memory barrier.
9725+ */
9726+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9727+{
9728+ return (*(volatile const long *)&(v)->counter);
9729 }
9730
9731 /**
9732@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9733 }
9734
9735 /**
9736+ * atomic64_set_unchecked - set atomic64 variable
9737+ * @v: pointer to type atomic64_unchecked_t
9738+ * @i: required value
9739+ *
9740+ * Atomically sets the value of @v to @i.
9741+ */
9742+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9743+{
9744+ v->counter = i;
9745+}
9746+
9747+/**
9748 * atomic64_add - add integer to atomic64 variable
9749 * @i: integer value to add
9750 * @v: pointer to type atomic64_t
9751@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9752 */
9753 static inline void atomic64_add(long i, atomic64_t *v)
9754 {
9755+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
9756+
9757+#ifdef CONFIG_PAX_REFCOUNT
9758+ "jno 0f\n"
9759+ LOCK_PREFIX "subq %1,%0\n"
9760+ "int $4\n0:\n"
9761+ _ASM_EXTABLE(0b, 0b)
9762+#endif
9763+
9764+ : "=m" (v->counter)
9765+ : "er" (i), "m" (v->counter));
9766+}
9767+
9768+/**
9769+ * atomic64_add_unchecked - add integer to atomic64 variable
9770+ * @i: integer value to add
9771+ * @v: pointer to type atomic64_unchecked_t
9772+ *
9773+ * Atomically adds @i to @v.
9774+ */
9775+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9776+{
9777 asm volatile(LOCK_PREFIX "addq %1,%0"
9778 : "=m" (v->counter)
9779 : "er" (i), "m" (v->counter));
9780@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9781 */
9782 static inline void atomic64_sub(long i, atomic64_t *v)
9783 {
9784- asm volatile(LOCK_PREFIX "subq %1,%0"
9785+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
9786+
9787+#ifdef CONFIG_PAX_REFCOUNT
9788+ "jno 0f\n"
9789+ LOCK_PREFIX "addq %1,%0\n"
9790+ "int $4\n0:\n"
9791+ _ASM_EXTABLE(0b, 0b)
9792+#endif
9793+
9794+ : "=m" (v->counter)
9795+ : "er" (i), "m" (v->counter));
9796+}
9797+
9798+/**
9799+ * atomic64_sub_unchecked - subtract the atomic64 variable
9800+ * @i: integer value to subtract
9801+ * @v: pointer to type atomic64_unchecked_t
9802+ *
9803+ * Atomically subtracts @i from @v.
9804+ */
9805+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9806+{
9807+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
9808 : "=m" (v->counter)
9809 : "er" (i), "m" (v->counter));
9810 }
9811@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9812 {
9813 unsigned char c;
9814
9815- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9816+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
9817+
9818+#ifdef CONFIG_PAX_REFCOUNT
9819+ "jno 0f\n"
9820+ LOCK_PREFIX "addq %2,%0\n"
9821+ "int $4\n0:\n"
9822+ _ASM_EXTABLE(0b, 0b)
9823+#endif
9824+
9825+ "sete %1\n"
9826 : "=m" (v->counter), "=qm" (c)
9827 : "er" (i), "m" (v->counter) : "memory");
9828 return c;
9829@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9830 */
9831 static inline void atomic64_inc(atomic64_t *v)
9832 {
9833+ asm volatile(LOCK_PREFIX "incq %0\n"
9834+
9835+#ifdef CONFIG_PAX_REFCOUNT
9836+ "jno 0f\n"
9837+ LOCK_PREFIX "decq %0\n"
9838+ "int $4\n0:\n"
9839+ _ASM_EXTABLE(0b, 0b)
9840+#endif
9841+
9842+ : "=m" (v->counter)
9843+ : "m" (v->counter));
9844+}
9845+
9846+/**
9847+ * atomic64_inc_unchecked - increment atomic64 variable
9848+ * @v: pointer to type atomic64_unchecked_t
9849+ *
9850+ * Atomically increments @v by 1.
9851+ */
9852+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9853+{
9854 asm volatile(LOCK_PREFIX "incq %0"
9855 : "=m" (v->counter)
9856 : "m" (v->counter));
9857@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9858 */
9859 static inline void atomic64_dec(atomic64_t *v)
9860 {
9861- asm volatile(LOCK_PREFIX "decq %0"
9862+ asm volatile(LOCK_PREFIX "decq %0\n"
9863+
9864+#ifdef CONFIG_PAX_REFCOUNT
9865+ "jno 0f\n"
9866+ LOCK_PREFIX "incq %0\n"
9867+ "int $4\n0:\n"
9868+ _ASM_EXTABLE(0b, 0b)
9869+#endif
9870+
9871+ : "=m" (v->counter)
9872+ : "m" (v->counter));
9873+}
9874+
9875+/**
9876+ * atomic64_dec_unchecked - decrement atomic64 variable
9877+ * @v: pointer to type atomic64_t
9878+ *
9879+ * Atomically decrements @v by 1.
9880+ */
9881+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9882+{
9883+ asm volatile(LOCK_PREFIX "decq %0\n"
9884 : "=m" (v->counter)
9885 : "m" (v->counter));
9886 }
9887@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9888 {
9889 unsigned char c;
9890
9891- asm volatile(LOCK_PREFIX "decq %0; sete %1"
9892+ asm volatile(LOCK_PREFIX "decq %0\n"
9893+
9894+#ifdef CONFIG_PAX_REFCOUNT
9895+ "jno 0f\n"
9896+ LOCK_PREFIX "incq %0\n"
9897+ "int $4\n0:\n"
9898+ _ASM_EXTABLE(0b, 0b)
9899+#endif
9900+
9901+ "sete %1\n"
9902 : "=m" (v->counter), "=qm" (c)
9903 : "m" (v->counter) : "memory");
9904 return c != 0;
9905@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9906 {
9907 unsigned char c;
9908
9909- asm volatile(LOCK_PREFIX "incq %0; sete %1"
9910+ asm volatile(LOCK_PREFIX "incq %0\n"
9911+
9912+#ifdef CONFIG_PAX_REFCOUNT
9913+ "jno 0f\n"
9914+ LOCK_PREFIX "decq %0\n"
9915+ "int $4\n0:\n"
9916+ _ASM_EXTABLE(0b, 0b)
9917+#endif
9918+
9919+ "sete %1\n"
9920 : "=m" (v->counter), "=qm" (c)
9921 : "m" (v->counter) : "memory");
9922 return c != 0;
9923@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9924 {
9925 unsigned char c;
9926
9927- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9928+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
9929+
9930+#ifdef CONFIG_PAX_REFCOUNT
9931+ "jno 0f\n"
9932+ LOCK_PREFIX "subq %2,%0\n"
9933+ "int $4\n0:\n"
9934+ _ASM_EXTABLE(0b, 0b)
9935+#endif
9936+
9937+ "sets %1\n"
9938 : "=m" (v->counter), "=qm" (c)
9939 : "er" (i), "m" (v->counter) : "memory");
9940 return c;
9941@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9942 */
9943 static inline long atomic64_add_return(long i, atomic64_t *v)
9944 {
9945+ return i + xadd_check_overflow(&v->counter, i);
9946+}
9947+
9948+/**
9949+ * atomic64_add_return_unchecked - add and return
9950+ * @i: integer value to add
9951+ * @v: pointer to type atomic64_unchecked_t
9952+ *
9953+ * Atomically adds @i to @v and returns @i + @v
9954+ */
9955+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9956+{
9957 return i + xadd(&v->counter, i);
9958 }
9959
9960@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
9961 }
9962
9963 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
9964+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9965+{
9966+ return atomic64_add_return_unchecked(1, v);
9967+}
9968 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
9969
9970 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9971@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9972 return cmpxchg(&v->counter, old, new);
9973 }
9974
9975+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
9976+{
9977+ return cmpxchg(&v->counter, old, new);
9978+}
9979+
9980 static inline long atomic64_xchg(atomic64_t *v, long new)
9981 {
9982 return xchg(&v->counter, new);
9983@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
9984 */
9985 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
9986 {
9987- long c, old;
9988+ long c, old, new;
9989 c = atomic64_read(v);
9990 for (;;) {
9991- if (unlikely(c == (u)))
9992+ if (unlikely(c == u))
9993 break;
9994- old = atomic64_cmpxchg((v), c, c + (a));
9995+
9996+ asm volatile("add %2,%0\n"
9997+
9998+#ifdef CONFIG_PAX_REFCOUNT
9999+ "jno 0f\n"
10000+ "sub %2,%0\n"
10001+ "int $4\n0:\n"
10002+ _ASM_EXTABLE(0b, 0b)
10003+#endif
10004+
10005+ : "=r" (new)
10006+ : "0" (c), "ir" (a));
10007+
10008+ old = atomic64_cmpxchg(v, c, new);
10009 if (likely(old == c))
10010 break;
10011 c = old;
10012 }
10013- return c != (u);
10014+ return c != u;
10015 }
10016
10017 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10018diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10019index b97596e..9bd48b06 100644
10020--- a/arch/x86/include/asm/bitops.h
10021+++ b/arch/x86/include/asm/bitops.h
10022@@ -38,7 +38,7 @@
10023 * a mask operation on a byte.
10024 */
10025 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10026-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10027+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10028 #define CONST_MASK(nr) (1 << ((nr) & 7))
10029
10030 /**
10031diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10032index 5e1a2ee..c9f9533 100644
10033--- a/arch/x86/include/asm/boot.h
10034+++ b/arch/x86/include/asm/boot.h
10035@@ -11,10 +11,15 @@
10036 #include <asm/pgtable_types.h>
10037
10038 /* Physical address where kernel should be loaded. */
10039-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10040+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10041 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10042 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10043
10044+#ifndef __ASSEMBLY__
10045+extern unsigned char __LOAD_PHYSICAL_ADDR[];
10046+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10047+#endif
10048+
10049 /* Minimum kernel alignment, as a power of two */
10050 #ifdef CONFIG_X86_64
10051 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10052diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10053index 48f99f1..d78ebf9 100644
10054--- a/arch/x86/include/asm/cache.h
10055+++ b/arch/x86/include/asm/cache.h
10056@@ -5,12 +5,13 @@
10057
10058 /* L1 cache line size */
10059 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10060-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10061+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10062
10063 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10064+#define __read_only __attribute__((__section__(".data..read_only")))
10065
10066 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10067-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10068+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10069
10070 #ifdef CONFIG_X86_VSMP
10071 #ifdef CONFIG_SMP
10072diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10073index 9863ee3..4a1f8e1 100644
10074--- a/arch/x86/include/asm/cacheflush.h
10075+++ b/arch/x86/include/asm/cacheflush.h
10076@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10077 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10078
10079 if (pg_flags == _PGMT_DEFAULT)
10080- return -1;
10081+ return ~0UL;
10082 else if (pg_flags == _PGMT_WC)
10083 return _PAGE_CACHE_WC;
10084 else if (pg_flags == _PGMT_UC_MINUS)
10085diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10086index 46fc474..b02b0f9 100644
10087--- a/arch/x86/include/asm/checksum_32.h
10088+++ b/arch/x86/include/asm/checksum_32.h
10089@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10090 int len, __wsum sum,
10091 int *src_err_ptr, int *dst_err_ptr);
10092
10093+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10094+ int len, __wsum sum,
10095+ int *src_err_ptr, int *dst_err_ptr);
10096+
10097+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10098+ int len, __wsum sum,
10099+ int *src_err_ptr, int *dst_err_ptr);
10100+
10101 /*
10102 * Note: when you get a NULL pointer exception here this means someone
10103 * passed in an incorrect kernel address to one of these functions.
10104@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10105 int *err_ptr)
10106 {
10107 might_sleep();
10108- return csum_partial_copy_generic((__force void *)src, dst,
10109+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
10110 len, sum, err_ptr, NULL);
10111 }
10112
10113@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10114 {
10115 might_sleep();
10116 if (access_ok(VERIFY_WRITE, dst, len))
10117- return csum_partial_copy_generic(src, (__force void *)dst,
10118+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10119 len, sum, NULL, err_ptr);
10120
10121 if (len)
10122diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10123index 99480e5..d81165b 100644
10124--- a/arch/x86/include/asm/cmpxchg.h
10125+++ b/arch/x86/include/asm/cmpxchg.h
10126@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10127 __compiletime_error("Bad argument size for cmpxchg");
10128 extern void __xadd_wrong_size(void)
10129 __compiletime_error("Bad argument size for xadd");
10130+extern void __xadd_check_overflow_wrong_size(void)
10131+ __compiletime_error("Bad argument size for xadd_check_overflow");
10132 extern void __add_wrong_size(void)
10133 __compiletime_error("Bad argument size for add");
10134+extern void __add_check_overflow_wrong_size(void)
10135+ __compiletime_error("Bad argument size for add_check_overflow");
10136
10137 /*
10138 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10139@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10140 __ret; \
10141 })
10142
10143+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10144+ ({ \
10145+ __typeof__ (*(ptr)) __ret = (arg); \
10146+ switch (sizeof(*(ptr))) { \
10147+ case __X86_CASE_L: \
10148+ asm volatile (lock #op "l %0, %1\n" \
10149+ "jno 0f\n" \
10150+ "mov %0,%1\n" \
10151+ "int $4\n0:\n" \
10152+ _ASM_EXTABLE(0b, 0b) \
10153+ : "+r" (__ret), "+m" (*(ptr)) \
10154+ : : "memory", "cc"); \
10155+ break; \
10156+ case __X86_CASE_Q: \
10157+ asm volatile (lock #op "q %q0, %1\n" \
10158+ "jno 0f\n" \
10159+ "mov %0,%1\n" \
10160+ "int $4\n0:\n" \
10161+ _ASM_EXTABLE(0b, 0b) \
10162+ : "+r" (__ret), "+m" (*(ptr)) \
10163+ : : "memory", "cc"); \
10164+ break; \
10165+ default: \
10166+ __ ## op ## _check_overflow_wrong_size(); \
10167+ } \
10168+ __ret; \
10169+ })
10170+
10171 /*
10172 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10173 * Since this is generally used to protect other memory information, we
10174@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10175 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10176 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10177
10178+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10179+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10180+
10181 #define __add(ptr, inc, lock) \
10182 ({ \
10183 __typeof__ (*(ptr)) __ret = (inc); \
10184diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10185index 340ee49..4238ced 100644
10186--- a/arch/x86/include/asm/cpufeature.h
10187+++ b/arch/x86/include/asm/cpufeature.h
10188@@ -371,7 +371,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10189 ".section .discard,\"aw\",@progbits\n"
10190 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10191 ".previous\n"
10192- ".section .altinstr_replacement,\"ax\"\n"
10193+ ".section .altinstr_replacement,\"a\"\n"
10194 "3: movb $1,%0\n"
10195 "4:\n"
10196 ".previous\n"
10197diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10198index e95822d..a90010e 100644
10199--- a/arch/x86/include/asm/desc.h
10200+++ b/arch/x86/include/asm/desc.h
10201@@ -4,6 +4,7 @@
10202 #include <asm/desc_defs.h>
10203 #include <asm/ldt.h>
10204 #include <asm/mmu.h>
10205+#include <asm/pgtable.h>
10206
10207 #include <linux/smp.h>
10208
10209@@ -16,6 +17,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10210
10211 desc->type = (info->read_exec_only ^ 1) << 1;
10212 desc->type |= info->contents << 2;
10213+ desc->type |= info->seg_not_present ^ 1;
10214
10215 desc->s = 1;
10216 desc->dpl = 0x3;
10217@@ -34,19 +36,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10218 }
10219
10220 extern struct desc_ptr idt_descr;
10221-extern gate_desc idt_table[];
10222 extern struct desc_ptr nmi_idt_descr;
10223-extern gate_desc nmi_idt_table[];
10224-
10225-struct gdt_page {
10226- struct desc_struct gdt[GDT_ENTRIES];
10227-} __attribute__((aligned(PAGE_SIZE)));
10228-
10229-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10230+extern gate_desc idt_table[256];
10231+extern gate_desc nmi_idt_table[256];
10232
10233+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10234 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10235 {
10236- return per_cpu(gdt_page, cpu).gdt;
10237+ return cpu_gdt_table[cpu];
10238 }
10239
10240 #ifdef CONFIG_X86_64
10241@@ -71,8 +68,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10242 unsigned long base, unsigned dpl, unsigned flags,
10243 unsigned short seg)
10244 {
10245- gate->a = (seg << 16) | (base & 0xffff);
10246- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10247+ gate->gate.offset_low = base;
10248+ gate->gate.seg = seg;
10249+ gate->gate.reserved = 0;
10250+ gate->gate.type = type;
10251+ gate->gate.s = 0;
10252+ gate->gate.dpl = dpl;
10253+ gate->gate.p = 1;
10254+ gate->gate.offset_high = base >> 16;
10255 }
10256
10257 #endif
10258@@ -117,12 +120,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10259
10260 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10261 {
10262+ pax_open_kernel();
10263 memcpy(&idt[entry], gate, sizeof(*gate));
10264+ pax_close_kernel();
10265 }
10266
10267 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10268 {
10269+ pax_open_kernel();
10270 memcpy(&ldt[entry], desc, 8);
10271+ pax_close_kernel();
10272 }
10273
10274 static inline void
10275@@ -136,7 +143,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10276 default: size = sizeof(*gdt); break;
10277 }
10278
10279+ pax_open_kernel();
10280 memcpy(&gdt[entry], desc, size);
10281+ pax_close_kernel();
10282 }
10283
10284 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10285@@ -209,7 +218,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10286
10287 static inline void native_load_tr_desc(void)
10288 {
10289+ pax_open_kernel();
10290 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10291+ pax_close_kernel();
10292 }
10293
10294 static inline void native_load_gdt(const struct desc_ptr *dtr)
10295@@ -246,8 +257,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10296 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10297 unsigned int i;
10298
10299+ pax_open_kernel();
10300 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10301 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10302+ pax_close_kernel();
10303 }
10304
10305 #define _LDT_empty(info) \
10306@@ -310,7 +323,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10307 }
10308
10309 #ifdef CONFIG_X86_64
10310-static inline void set_nmi_gate(int gate, void *addr)
10311+static inline void set_nmi_gate(int gate, const void *addr)
10312 {
10313 gate_desc s;
10314
10315@@ -319,7 +332,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10316 }
10317 #endif
10318
10319-static inline void _set_gate(int gate, unsigned type, void *addr,
10320+static inline void _set_gate(int gate, unsigned type, const void *addr,
10321 unsigned dpl, unsigned ist, unsigned seg)
10322 {
10323 gate_desc s;
10324@@ -338,7 +351,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10325 * Pentium F0 0F bugfix can have resulted in the mapped
10326 * IDT being write-protected.
10327 */
10328-static inline void set_intr_gate(unsigned int n, void *addr)
10329+static inline void set_intr_gate(unsigned int n, const void *addr)
10330 {
10331 BUG_ON((unsigned)n > 0xFF);
10332 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10333@@ -368,19 +381,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10334 /*
10335 * This routine sets up an interrupt gate at directory privilege level 3.
10336 */
10337-static inline void set_system_intr_gate(unsigned int n, void *addr)
10338+static inline void set_system_intr_gate(unsigned int n, const void *addr)
10339 {
10340 BUG_ON((unsigned)n > 0xFF);
10341 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10342 }
10343
10344-static inline void set_system_trap_gate(unsigned int n, void *addr)
10345+static inline void set_system_trap_gate(unsigned int n, const void *addr)
10346 {
10347 BUG_ON((unsigned)n > 0xFF);
10348 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10349 }
10350
10351-static inline void set_trap_gate(unsigned int n, void *addr)
10352+static inline void set_trap_gate(unsigned int n, const void *addr)
10353 {
10354 BUG_ON((unsigned)n > 0xFF);
10355 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10356@@ -389,19 +402,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10357 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10358 {
10359 BUG_ON((unsigned)n > 0xFF);
10360- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10361+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10362 }
10363
10364-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10365+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10366 {
10367 BUG_ON((unsigned)n > 0xFF);
10368 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10369 }
10370
10371-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10372+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10373 {
10374 BUG_ON((unsigned)n > 0xFF);
10375 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10376 }
10377
10378+#ifdef CONFIG_X86_32
10379+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10380+{
10381+ struct desc_struct d;
10382+
10383+ if (likely(limit))
10384+ limit = (limit - 1UL) >> PAGE_SHIFT;
10385+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
10386+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10387+}
10388+#endif
10389+
10390 #endif /* _ASM_X86_DESC_H */
10391diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10392index 278441f..b95a174 100644
10393--- a/arch/x86/include/asm/desc_defs.h
10394+++ b/arch/x86/include/asm/desc_defs.h
10395@@ -31,6 +31,12 @@ struct desc_struct {
10396 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10397 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10398 };
10399+ struct {
10400+ u16 offset_low;
10401+ u16 seg;
10402+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10403+ unsigned offset_high: 16;
10404+ } gate;
10405 };
10406 } __attribute__((packed));
10407
10408diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10409index 3778256..c5d4fce 100644
10410--- a/arch/x86/include/asm/e820.h
10411+++ b/arch/x86/include/asm/e820.h
10412@@ -69,7 +69,7 @@ struct e820map {
10413 #define ISA_START_ADDRESS 0xa0000
10414 #define ISA_END_ADDRESS 0x100000
10415
10416-#define BIOS_BEGIN 0x000a0000
10417+#define BIOS_BEGIN 0x000c0000
10418 #define BIOS_END 0x00100000
10419
10420 #define BIOS_ROM_BASE 0xffe00000
10421diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10422index 5939f44..f8845f6 100644
10423--- a/arch/x86/include/asm/elf.h
10424+++ b/arch/x86/include/asm/elf.h
10425@@ -243,7 +243,25 @@ extern int force_personality32;
10426 the loader. We need to make sure that it is out of the way of the program
10427 that it will "exec", and that there is sufficient room for the brk. */
10428
10429+#ifdef CONFIG_PAX_SEGMEXEC
10430+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10431+#else
10432 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10433+#endif
10434+
10435+#ifdef CONFIG_PAX_ASLR
10436+#ifdef CONFIG_X86_32
10437+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10438+
10439+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10440+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10441+#else
10442+#define PAX_ELF_ET_DYN_BASE 0x400000UL
10443+
10444+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10445+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10446+#endif
10447+#endif
10448
10449 /* This yields a mask that user programs can use to figure out what
10450 instruction set this CPU supports. This could be done in user space,
10451@@ -296,16 +314,12 @@ do { \
10452
10453 #define ARCH_DLINFO \
10454 do { \
10455- if (vdso_enabled) \
10456- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10457- (unsigned long)current->mm->context.vdso); \
10458+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10459 } while (0)
10460
10461 #define ARCH_DLINFO_X32 \
10462 do { \
10463- if (vdso_enabled) \
10464- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10465- (unsigned long)current->mm->context.vdso); \
10466+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10467 } while (0)
10468
10469 #define AT_SYSINFO 32
10470@@ -320,7 +334,7 @@ else \
10471
10472 #endif /* !CONFIG_X86_32 */
10473
10474-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10475+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10476
10477 #define VDSO_ENTRY \
10478 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10479@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
10480 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10481 #define compat_arch_setup_additional_pages syscall32_setup_pages
10482
10483-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10484-#define arch_randomize_brk arch_randomize_brk
10485-
10486 /*
10487 * True on X86_32 or when emulating IA32 on X86_64
10488 */
10489diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10490index cc70c1c..d96d011 100644
10491--- a/arch/x86/include/asm/emergency-restart.h
10492+++ b/arch/x86/include/asm/emergency-restart.h
10493@@ -15,6 +15,6 @@ enum reboot_type {
10494
10495 extern enum reboot_type reboot_type;
10496
10497-extern void machine_emergency_restart(void);
10498+extern void machine_emergency_restart(void) __noreturn;
10499
10500 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10501diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
10502index 4fa8815..71b121a 100644
10503--- a/arch/x86/include/asm/fpu-internal.h
10504+++ b/arch/x86/include/asm/fpu-internal.h
10505@@ -86,6 +86,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10506 {
10507 int err;
10508
10509+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10510+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10511+ fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10512+#endif
10513+
10514 /* See comment in fxsave() below. */
10515 #ifdef CONFIG_AS_FXSAVEQ
10516 asm volatile("1: fxrstorq %[fx]\n\t"
10517@@ -115,6 +120,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10518 {
10519 int err;
10520
10521+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10522+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10523+ fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10524+#endif
10525+
10526 /*
10527 * Clear the bytes not touched by the fxsave and reserved
10528 * for the SW usage.
10529@@ -271,7 +281,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10530 "emms\n\t" /* clear stack tags */
10531 "fildl %P[addr]", /* set F?P to defined value */
10532 X86_FEATURE_FXSAVE_LEAK,
10533- [addr] "m" (tsk->thread.fpu.has_fpu));
10534+ [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10535
10536 return fpu_restore_checking(&tsk->thread.fpu);
10537 }
10538diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10539index 71ecbcb..bac10b7 100644
10540--- a/arch/x86/include/asm/futex.h
10541+++ b/arch/x86/include/asm/futex.h
10542@@ -11,16 +11,18 @@
10543 #include <asm/processor.h>
10544
10545 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10546+ typecheck(u32 __user *, uaddr); \
10547 asm volatile("1:\t" insn "\n" \
10548 "2:\t.section .fixup,\"ax\"\n" \
10549 "3:\tmov\t%3, %1\n" \
10550 "\tjmp\t2b\n" \
10551 "\t.previous\n" \
10552 _ASM_EXTABLE(1b, 3b) \
10553- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10554+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10555 : "i" (-EFAULT), "0" (oparg), "1" (0))
10556
10557 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10558+ typecheck(u32 __user *, uaddr); \
10559 asm volatile("1:\tmovl %2, %0\n" \
10560 "\tmovl\t%0, %3\n" \
10561 "\t" insn "\n" \
10562@@ -33,7 +35,7 @@
10563 _ASM_EXTABLE(1b, 4b) \
10564 _ASM_EXTABLE(2b, 4b) \
10565 : "=&a" (oldval), "=&r" (ret), \
10566- "+m" (*uaddr), "=&r" (tem) \
10567+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10568 : "r" (oparg), "i" (-EFAULT), "1" (0))
10569
10570 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10571@@ -60,10 +62,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10572
10573 switch (op) {
10574 case FUTEX_OP_SET:
10575- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10576+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10577 break;
10578 case FUTEX_OP_ADD:
10579- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10580+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10581 uaddr, oparg);
10582 break;
10583 case FUTEX_OP_OR:
10584@@ -122,13 +124,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10585 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10586 return -EFAULT;
10587
10588- asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10589+ asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10590 "2:\t.section .fixup, \"ax\"\n"
10591 "3:\tmov %3, %0\n"
10592 "\tjmp 2b\n"
10593 "\t.previous\n"
10594 _ASM_EXTABLE(1b, 3b)
10595- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10596+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10597 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10598 : "memory"
10599 );
10600diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10601index eb92a6e..b98b2f4 100644
10602--- a/arch/x86/include/asm/hw_irq.h
10603+++ b/arch/x86/include/asm/hw_irq.h
10604@@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10605 extern void enable_IO_APIC(void);
10606
10607 /* Statistics */
10608-extern atomic_t irq_err_count;
10609-extern atomic_t irq_mis_count;
10610+extern atomic_unchecked_t irq_err_count;
10611+extern atomic_unchecked_t irq_mis_count;
10612
10613 /* EISA */
10614 extern void eisa_set_level_irq(unsigned int irq);
10615diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10616index d8e8eef..99f81ae 100644
10617--- a/arch/x86/include/asm/io.h
10618+++ b/arch/x86/include/asm/io.h
10619@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10620
10621 #include <linux/vmalloc.h>
10622
10623+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10624+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10625+{
10626+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10627+}
10628+
10629+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10630+{
10631+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10632+}
10633+
10634 /*
10635 * Convert a virtual cached pointer to an uncached pointer
10636 */
10637diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10638index bba3cf8..06bc8da 100644
10639--- a/arch/x86/include/asm/irqflags.h
10640+++ b/arch/x86/include/asm/irqflags.h
10641@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10642 sti; \
10643 sysexit
10644
10645+#define GET_CR0_INTO_RDI mov %cr0, %rdi
10646+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10647+#define GET_CR3_INTO_RDI mov %cr3, %rdi
10648+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10649+
10650 #else
10651 #define INTERRUPT_RETURN iret
10652 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10653diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10654index 5478825..839e88c 100644
10655--- a/arch/x86/include/asm/kprobes.h
10656+++ b/arch/x86/include/asm/kprobes.h
10657@@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10658 #define RELATIVEJUMP_SIZE 5
10659 #define RELATIVECALL_OPCODE 0xe8
10660 #define RELATIVE_ADDR_SIZE 4
10661-#define MAX_STACK_SIZE 64
10662-#define MIN_STACK_SIZE(ADDR) \
10663- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10664- THREAD_SIZE - (unsigned long)(ADDR))) \
10665- ? (MAX_STACK_SIZE) \
10666- : (((unsigned long)current_thread_info()) + \
10667- THREAD_SIZE - (unsigned long)(ADDR)))
10668+#define MAX_STACK_SIZE 64UL
10669+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10670
10671 #define flush_insn_slot(p) do { } while (0)
10672
10673diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10674index e216ba0..453f6ec 100644
10675--- a/arch/x86/include/asm/kvm_host.h
10676+++ b/arch/x86/include/asm/kvm_host.h
10677@@ -679,7 +679,7 @@ struct kvm_x86_ops {
10678 int (*check_intercept)(struct kvm_vcpu *vcpu,
10679 struct x86_instruction_info *info,
10680 enum x86_intercept_stage stage);
10681-};
10682+} __do_const;
10683
10684 struct kvm_arch_async_pf {
10685 u32 token;
10686diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10687index c8bed0d..e5721fa 100644
10688--- a/arch/x86/include/asm/local.h
10689+++ b/arch/x86/include/asm/local.h
10690@@ -17,26 +17,58 @@ typedef struct {
10691
10692 static inline void local_inc(local_t *l)
10693 {
10694- asm volatile(_ASM_INC "%0"
10695+ asm volatile(_ASM_INC "%0\n"
10696+
10697+#ifdef CONFIG_PAX_REFCOUNT
10698+ "jno 0f\n"
10699+ _ASM_DEC "%0\n"
10700+ "int $4\n0:\n"
10701+ _ASM_EXTABLE(0b, 0b)
10702+#endif
10703+
10704 : "+m" (l->a.counter));
10705 }
10706
10707 static inline void local_dec(local_t *l)
10708 {
10709- asm volatile(_ASM_DEC "%0"
10710+ asm volatile(_ASM_DEC "%0\n"
10711+
10712+#ifdef CONFIG_PAX_REFCOUNT
10713+ "jno 0f\n"
10714+ _ASM_INC "%0\n"
10715+ "int $4\n0:\n"
10716+ _ASM_EXTABLE(0b, 0b)
10717+#endif
10718+
10719 : "+m" (l->a.counter));
10720 }
10721
10722 static inline void local_add(long i, local_t *l)
10723 {
10724- asm volatile(_ASM_ADD "%1,%0"
10725+ asm volatile(_ASM_ADD "%1,%0\n"
10726+
10727+#ifdef CONFIG_PAX_REFCOUNT
10728+ "jno 0f\n"
10729+ _ASM_SUB "%1,%0\n"
10730+ "int $4\n0:\n"
10731+ _ASM_EXTABLE(0b, 0b)
10732+#endif
10733+
10734 : "+m" (l->a.counter)
10735 : "ir" (i));
10736 }
10737
10738 static inline void local_sub(long i, local_t *l)
10739 {
10740- asm volatile(_ASM_SUB "%1,%0"
10741+ asm volatile(_ASM_SUB "%1,%0\n"
10742+
10743+#ifdef CONFIG_PAX_REFCOUNT
10744+ "jno 0f\n"
10745+ _ASM_ADD "%1,%0\n"
10746+ "int $4\n0:\n"
10747+ _ASM_EXTABLE(0b, 0b)
10748+#endif
10749+
10750 : "+m" (l->a.counter)
10751 : "ir" (i));
10752 }
10753@@ -54,7 +86,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10754 {
10755 unsigned char c;
10756
10757- asm volatile(_ASM_SUB "%2,%0; sete %1"
10758+ asm volatile(_ASM_SUB "%2,%0\n"
10759+
10760+#ifdef CONFIG_PAX_REFCOUNT
10761+ "jno 0f\n"
10762+ _ASM_ADD "%2,%0\n"
10763+ "int $4\n0:\n"
10764+ _ASM_EXTABLE(0b, 0b)
10765+#endif
10766+
10767+ "sete %1\n"
10768 : "+m" (l->a.counter), "=qm" (c)
10769 : "ir" (i) : "memory");
10770 return c;
10771@@ -72,7 +113,16 @@ static inline int local_dec_and_test(local_t *l)
10772 {
10773 unsigned char c;
10774
10775- asm volatile(_ASM_DEC "%0; sete %1"
10776+ asm volatile(_ASM_DEC "%0\n"
10777+
10778+#ifdef CONFIG_PAX_REFCOUNT
10779+ "jno 0f\n"
10780+ _ASM_INC "%0\n"
10781+ "int $4\n0:\n"
10782+ _ASM_EXTABLE(0b, 0b)
10783+#endif
10784+
10785+ "sete %1\n"
10786 : "+m" (l->a.counter), "=qm" (c)
10787 : : "memory");
10788 return c != 0;
10789@@ -90,7 +140,16 @@ static inline int local_inc_and_test(local_t *l)
10790 {
10791 unsigned char c;
10792
10793- asm volatile(_ASM_INC "%0; sete %1"
10794+ asm volatile(_ASM_INC "%0\n"
10795+
10796+#ifdef CONFIG_PAX_REFCOUNT
10797+ "jno 0f\n"
10798+ _ASM_DEC "%0\n"
10799+ "int $4\n0:\n"
10800+ _ASM_EXTABLE(0b, 0b)
10801+#endif
10802+
10803+ "sete %1\n"
10804 : "+m" (l->a.counter), "=qm" (c)
10805 : : "memory");
10806 return c != 0;
10807@@ -109,7 +168,16 @@ static inline int local_add_negative(long i, local_t *l)
10808 {
10809 unsigned char c;
10810
10811- asm volatile(_ASM_ADD "%2,%0; sets %1"
10812+ asm volatile(_ASM_ADD "%2,%0\n"
10813+
10814+#ifdef CONFIG_PAX_REFCOUNT
10815+ "jno 0f\n"
10816+ _ASM_SUB "%2,%0\n"
10817+ "int $4\n0:\n"
10818+ _ASM_EXTABLE(0b, 0b)
10819+#endif
10820+
10821+ "sets %1\n"
10822 : "+m" (l->a.counter), "=qm" (c)
10823 : "ir" (i) : "memory");
10824 return c;
10825@@ -132,7 +200,15 @@ static inline long local_add_return(long i, local_t *l)
10826 #endif
10827 /* Modern 486+ processor */
10828 __i = i;
10829- asm volatile(_ASM_XADD "%0, %1;"
10830+ asm volatile(_ASM_XADD "%0, %1\n"
10831+
10832+#ifdef CONFIG_PAX_REFCOUNT
10833+ "jno 0f\n"
10834+ _ASM_MOV "%0,%1\n"
10835+ "int $4\n0:\n"
10836+ _ASM_EXTABLE(0b, 0b)
10837+#endif
10838+
10839 : "+r" (i), "+m" (l->a.counter)
10840 : : "memory");
10841 return i + __i;
10842diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10843index 593e51d..fa69c9a 100644
10844--- a/arch/x86/include/asm/mman.h
10845+++ b/arch/x86/include/asm/mman.h
10846@@ -5,4 +5,14 @@
10847
10848 #include <asm-generic/mman.h>
10849
10850+#ifdef __KERNEL__
10851+#ifndef __ASSEMBLY__
10852+#ifdef CONFIG_X86_32
10853+#define arch_mmap_check i386_mmap_check
10854+int i386_mmap_check(unsigned long addr, unsigned long len,
10855+ unsigned long flags);
10856+#endif
10857+#endif
10858+#endif
10859+
10860 #endif /* _ASM_X86_MMAN_H */
10861diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10862index 5f55e69..e20bfb1 100644
10863--- a/arch/x86/include/asm/mmu.h
10864+++ b/arch/x86/include/asm/mmu.h
10865@@ -9,7 +9,7 @@
10866 * we put the segment information here.
10867 */
10868 typedef struct {
10869- void *ldt;
10870+ struct desc_struct *ldt;
10871 int size;
10872
10873 #ifdef CONFIG_X86_64
10874@@ -18,7 +18,19 @@ typedef struct {
10875 #endif
10876
10877 struct mutex lock;
10878- void *vdso;
10879+ unsigned long vdso;
10880+
10881+#ifdef CONFIG_X86_32
10882+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10883+ unsigned long user_cs_base;
10884+ unsigned long user_cs_limit;
10885+
10886+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10887+ cpumask_t cpu_user_cs_mask;
10888+#endif
10889+
10890+#endif
10891+#endif
10892 } mm_context_t;
10893
10894 #ifdef CONFIG_SMP
10895diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10896index 6902152..da4283a 100644
10897--- a/arch/x86/include/asm/mmu_context.h
10898+++ b/arch/x86/include/asm/mmu_context.h
10899@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10900
10901 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10902 {
10903+
10904+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10905+ unsigned int i;
10906+ pgd_t *pgd;
10907+
10908+ pax_open_kernel();
10909+ pgd = get_cpu_pgd(smp_processor_id());
10910+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10911+ set_pgd_batched(pgd+i, native_make_pgd(0));
10912+ pax_close_kernel();
10913+#endif
10914+
10915 #ifdef CONFIG_SMP
10916 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10917 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10918@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10919 struct task_struct *tsk)
10920 {
10921 unsigned cpu = smp_processor_id();
10922+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10923+ int tlbstate = TLBSTATE_OK;
10924+#endif
10925
10926 if (likely(prev != next)) {
10927 #ifdef CONFIG_SMP
10928+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10929+ tlbstate = percpu_read(cpu_tlbstate.state);
10930+#endif
10931 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10932 percpu_write(cpu_tlbstate.active_mm, next);
10933 #endif
10934 cpumask_set_cpu(cpu, mm_cpumask(next));
10935
10936 /* Re-load page tables */
10937+#ifdef CONFIG_PAX_PER_CPU_PGD
10938+ pax_open_kernel();
10939+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
10940+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
10941+ pax_close_kernel();
10942+ load_cr3(get_cpu_pgd(cpu));
10943+#else
10944 load_cr3(next->pgd);
10945+#endif
10946
10947 /* stop flush ipis for the previous mm */
10948 cpumask_clear_cpu(cpu, mm_cpumask(prev));
10949@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10950 */
10951 if (unlikely(prev->context.ldt != next->context.ldt))
10952 load_LDT_nolock(&next->context);
10953- }
10954+
10955+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10956+ if (!(__supported_pte_mask & _PAGE_NX)) {
10957+ smp_mb__before_clear_bit();
10958+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
10959+ smp_mb__after_clear_bit();
10960+ cpu_set(cpu, next->context.cpu_user_cs_mask);
10961+ }
10962+#endif
10963+
10964+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10965+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
10966+ prev->context.user_cs_limit != next->context.user_cs_limit))
10967+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10968 #ifdef CONFIG_SMP
10969+ else if (unlikely(tlbstate != TLBSTATE_OK))
10970+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10971+#endif
10972+#endif
10973+
10974+ }
10975 else {
10976+
10977+#ifdef CONFIG_PAX_PER_CPU_PGD
10978+ pax_open_kernel();
10979+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
10980+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
10981+ pax_close_kernel();
10982+ load_cr3(get_cpu_pgd(cpu));
10983+#endif
10984+
10985+#ifdef CONFIG_SMP
10986 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10987 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
10988
10989@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10990 * tlb flush IPI delivery. We must reload CR3
10991 * to make sure to use no freed page tables.
10992 */
10993+
10994+#ifndef CONFIG_PAX_PER_CPU_PGD
10995 load_cr3(next->pgd);
10996+#endif
10997+
10998 load_LDT_nolock(&next->context);
10999+
11000+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
11001+ if (!(__supported_pte_mask & _PAGE_NX))
11002+ cpu_set(cpu, next->context.cpu_user_cs_mask);
11003+#endif
11004+
11005+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11006+#ifdef CONFIG_PAX_PAGEEXEC
11007+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
11008+#endif
11009+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11010+#endif
11011+
11012 }
11013+#endif
11014 }
11015-#endif
11016 }
11017
11018 #define activate_mm(prev, next) \
11019diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11020index 9eae775..c914fea 100644
11021--- a/arch/x86/include/asm/module.h
11022+++ b/arch/x86/include/asm/module.h
11023@@ -5,6 +5,7 @@
11024
11025 #ifdef CONFIG_X86_64
11026 /* X86_64 does not define MODULE_PROC_FAMILY */
11027+#define MODULE_PROC_FAMILY ""
11028 #elif defined CONFIG_M386
11029 #define MODULE_PROC_FAMILY "386 "
11030 #elif defined CONFIG_M486
11031@@ -59,8 +60,20 @@
11032 #error unknown processor family
11033 #endif
11034
11035-#ifdef CONFIG_X86_32
11036-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11037+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11038+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11039+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11040+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11041+#else
11042+#define MODULE_PAX_KERNEXEC ""
11043 #endif
11044
11045+#ifdef CONFIG_PAX_MEMORY_UDEREF
11046+#define MODULE_PAX_UDEREF "UDEREF "
11047+#else
11048+#define MODULE_PAX_UDEREF ""
11049+#endif
11050+
11051+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11052+
11053 #endif /* _ASM_X86_MODULE_H */
11054diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11055index 7639dbf..e08a58c 100644
11056--- a/arch/x86/include/asm/page_64_types.h
11057+++ b/arch/x86/include/asm/page_64_types.h
11058@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11059
11060 /* duplicated to the one in bootmem.h */
11061 extern unsigned long max_pfn;
11062-extern unsigned long phys_base;
11063+extern const unsigned long phys_base;
11064
11065 extern unsigned long __phys_addr(unsigned long);
11066 #define __phys_reloc_hide(x) (x)
11067diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11068index aa0f913..0c5bc6a 100644
11069--- a/arch/x86/include/asm/paravirt.h
11070+++ b/arch/x86/include/asm/paravirt.h
11071@@ -668,6 +668,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11072 val);
11073 }
11074
11075+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11076+{
11077+ pgdval_t val = native_pgd_val(pgd);
11078+
11079+ if (sizeof(pgdval_t) > sizeof(long))
11080+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11081+ val, (u64)val >> 32);
11082+ else
11083+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11084+ val);
11085+}
11086+
11087 static inline void pgd_clear(pgd_t *pgdp)
11088 {
11089 set_pgd(pgdp, __pgd(0));
11090@@ -749,6 +761,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11091 pv_mmu_ops.set_fixmap(idx, phys, flags);
11092 }
11093
11094+#ifdef CONFIG_PAX_KERNEXEC
11095+static inline unsigned long pax_open_kernel(void)
11096+{
11097+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11098+}
11099+
11100+static inline unsigned long pax_close_kernel(void)
11101+{
11102+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11103+}
11104+#else
11105+static inline unsigned long pax_open_kernel(void) { return 0; }
11106+static inline unsigned long pax_close_kernel(void) { return 0; }
11107+#endif
11108+
11109 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11110
11111 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11112@@ -965,7 +992,7 @@ extern void default_banner(void);
11113
11114 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11115 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11116-#define PARA_INDIRECT(addr) *%cs:addr
11117+#define PARA_INDIRECT(addr) *%ss:addr
11118 #endif
11119
11120 #define INTERRUPT_RETURN \
11121@@ -1042,6 +1069,21 @@ extern void default_banner(void);
11122 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11123 CLBR_NONE, \
11124 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11125+
11126+#define GET_CR0_INTO_RDI \
11127+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11128+ mov %rax,%rdi
11129+
11130+#define SET_RDI_INTO_CR0 \
11131+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11132+
11133+#define GET_CR3_INTO_RDI \
11134+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11135+ mov %rax,%rdi
11136+
11137+#define SET_RDI_INTO_CR3 \
11138+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11139+
11140 #endif /* CONFIG_X86_32 */
11141
11142 #endif /* __ASSEMBLY__ */
11143diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11144index 8e8b9a4..f07d725 100644
11145--- a/arch/x86/include/asm/paravirt_types.h
11146+++ b/arch/x86/include/asm/paravirt_types.h
11147@@ -84,20 +84,20 @@ struct pv_init_ops {
11148 */
11149 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11150 unsigned long addr, unsigned len);
11151-};
11152+} __no_const;
11153
11154
11155 struct pv_lazy_ops {
11156 /* Set deferred update mode, used for batching operations. */
11157 void (*enter)(void);
11158 void (*leave)(void);
11159-};
11160+} __no_const;
11161
11162 struct pv_time_ops {
11163 unsigned long long (*sched_clock)(void);
11164 unsigned long long (*steal_clock)(int cpu);
11165 unsigned long (*get_tsc_khz)(void);
11166-};
11167+} __no_const;
11168
11169 struct pv_cpu_ops {
11170 /* hooks for various privileged instructions */
11171@@ -193,7 +193,7 @@ struct pv_cpu_ops {
11172
11173 void (*start_context_switch)(struct task_struct *prev);
11174 void (*end_context_switch)(struct task_struct *next);
11175-};
11176+} __no_const;
11177
11178 struct pv_irq_ops {
11179 /*
11180@@ -224,7 +224,7 @@ struct pv_apic_ops {
11181 unsigned long start_eip,
11182 unsigned long start_esp);
11183 #endif
11184-};
11185+} __no_const;
11186
11187 struct pv_mmu_ops {
11188 unsigned long (*read_cr2)(void);
11189@@ -313,6 +313,7 @@ struct pv_mmu_ops {
11190 struct paravirt_callee_save make_pud;
11191
11192 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11193+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11194 #endif /* PAGETABLE_LEVELS == 4 */
11195 #endif /* PAGETABLE_LEVELS >= 3 */
11196
11197@@ -324,6 +325,12 @@ struct pv_mmu_ops {
11198 an mfn. We can tell which is which from the index. */
11199 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11200 phys_addr_t phys, pgprot_t flags);
11201+
11202+#ifdef CONFIG_PAX_KERNEXEC
11203+ unsigned long (*pax_open_kernel)(void);
11204+ unsigned long (*pax_close_kernel)(void);
11205+#endif
11206+
11207 };
11208
11209 struct arch_spinlock;
11210@@ -334,7 +341,7 @@ struct pv_lock_ops {
11211 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11212 int (*spin_trylock)(struct arch_spinlock *lock);
11213 void (*spin_unlock)(struct arch_spinlock *lock);
11214-};
11215+} __no_const;
11216
11217 /* This contains all the paravirt structures: we get a convenient
11218 * number for each function using the offset which we use to indicate
11219diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11220index b4389a4..7024269 100644
11221--- a/arch/x86/include/asm/pgalloc.h
11222+++ b/arch/x86/include/asm/pgalloc.h
11223@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11224 pmd_t *pmd, pte_t *pte)
11225 {
11226 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11227+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11228+}
11229+
11230+static inline void pmd_populate_user(struct mm_struct *mm,
11231+ pmd_t *pmd, pte_t *pte)
11232+{
11233+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11234 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11235 }
11236
11237@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11238
11239 #ifdef CONFIG_X86_PAE
11240 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11241+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11242+{
11243+ pud_populate(mm, pudp, pmd);
11244+}
11245 #else /* !CONFIG_X86_PAE */
11246 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11247 {
11248 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11249 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11250 }
11251+
11252+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11253+{
11254+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11255+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11256+}
11257 #endif /* CONFIG_X86_PAE */
11258
11259 #if PAGETABLE_LEVELS > 3
11260@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11261 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11262 }
11263
11264+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11265+{
11266+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11267+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11268+}
11269+
11270 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11271 {
11272 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11273diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11274index 98391db..8f6984e 100644
11275--- a/arch/x86/include/asm/pgtable-2level.h
11276+++ b/arch/x86/include/asm/pgtable-2level.h
11277@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11278
11279 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11280 {
11281+ pax_open_kernel();
11282 *pmdp = pmd;
11283+ pax_close_kernel();
11284 }
11285
11286 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11287diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11288index effff47..bbb8295 100644
11289--- a/arch/x86/include/asm/pgtable-3level.h
11290+++ b/arch/x86/include/asm/pgtable-3level.h
11291@@ -31,6 +31,56 @@ static inline void native_set_pte(pte_t *ptep, pte_t pte)
11292 ptep->pte_low = pte.pte_low;
11293 }
11294
11295+#define __HAVE_ARCH_READ_PMD_ATOMIC
11296+/*
11297+ * pte_offset_map_lock on 32bit PAE kernels was reading the pmd_t with
11298+ * a "*pmdp" dereference done by gcc. Problem is, in certain places
11299+ * where pte_offset_map_lock is called, concurrent page faults are
11300+ * allowed, if the mmap_sem is hold for reading. An example is mincore
11301+ * vs page faults vs MADV_DONTNEED. On the page fault side
11302+ * pmd_populate rightfully does a set_64bit, but if we're reading the
11303+ * pmd_t with a "*pmdp" on the mincore side, a SMP race can happen
11304+ * because gcc will not read the 64bit of the pmd atomically. To fix
11305+ * this all places running pmd_offset_map_lock() while holding the
11306+ * mmap_sem in read mode, shall read the pmdp pointer using this
11307+ * function to know if the pmd is null nor not, and in turn to know if
11308+ * they can run pmd_offset_map_lock or pmd_trans_huge or other pmd
11309+ * operations.
11310+ *
11311+ * Without THP if the mmap_sem is hold for reading, the
11312+ * pmd can only transition from null to not null while read_pmd_atomic runs.
11313+ * So there's no need of literally reading it atomically.
11314+ *
11315+ * With THP if the mmap_sem is hold for reading, the pmd can become
11316+ * THP or null or point to a pte (and in turn become "stable") at any
11317+ * time under read_pmd_atomic, so it's mandatory to read it atomically
11318+ * with cmpxchg8b.
11319+ */
11320+#ifndef CONFIG_TRANSPARENT_HUGEPAGE
11321+static inline pmd_t read_pmd_atomic(pmd_t *pmdp)
11322+{
11323+ pmdval_t ret;
11324+ u32 *tmp = (u32 *)pmdp;
11325+
11326+ ret = (pmdval_t) (*tmp);
11327+ if (ret) {
11328+ /*
11329+ * If the low part is null, we must not read the high part
11330+ * or we can end up with a partial pmd.
11331+ */
11332+ smp_rmb();
11333+ ret |= ((pmdval_t)*(tmp + 1)) << 32;
11334+ }
11335+
11336+ return __pmd(ret);
11337+}
11338+#else /* CONFIG_TRANSPARENT_HUGEPAGE */
11339+static inline pmd_t read_pmd_atomic(pmd_t *pmdp)
11340+{
11341+ return __pmd(atomic64_read((atomic64_t *)pmdp));
11342+}
11343+#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
11344+
11345 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11346 {
11347 set_64bit((unsigned long long *)(ptep), native_pte_val(pte));
11348@@ -38,12 +88,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11349
11350 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11351 {
11352+ pax_open_kernel();
11353 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11354+ pax_close_kernel();
11355 }
11356
11357 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11358 {
11359+ pax_open_kernel();
11360 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11361+ pax_close_kernel();
11362 }
11363
11364 /*
11365diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11366index 49afb3f..91a8c63 100644
11367--- a/arch/x86/include/asm/pgtable.h
11368+++ b/arch/x86/include/asm/pgtable.h
11369@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11370
11371 #ifndef __PAGETABLE_PUD_FOLDED
11372 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11373+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11374 #define pgd_clear(pgd) native_pgd_clear(pgd)
11375 #endif
11376
11377@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11378
11379 #define arch_end_context_switch(prev) do {} while(0)
11380
11381+#define pax_open_kernel() native_pax_open_kernel()
11382+#define pax_close_kernel() native_pax_close_kernel()
11383 #endif /* CONFIG_PARAVIRT */
11384
11385+#define __HAVE_ARCH_PAX_OPEN_KERNEL
11386+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11387+
11388+#ifdef CONFIG_PAX_KERNEXEC
11389+static inline unsigned long native_pax_open_kernel(void)
11390+{
11391+ unsigned long cr0;
11392+
11393+ preempt_disable();
11394+ barrier();
11395+ cr0 = read_cr0() ^ X86_CR0_WP;
11396+ BUG_ON(unlikely(cr0 & X86_CR0_WP));
11397+ write_cr0(cr0);
11398+ return cr0 ^ X86_CR0_WP;
11399+}
11400+
11401+static inline unsigned long native_pax_close_kernel(void)
11402+{
11403+ unsigned long cr0;
11404+
11405+ cr0 = read_cr0() ^ X86_CR0_WP;
11406+ BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11407+ write_cr0(cr0);
11408+ barrier();
11409+ preempt_enable_no_resched();
11410+ return cr0 ^ X86_CR0_WP;
11411+}
11412+#else
11413+static inline unsigned long native_pax_open_kernel(void) { return 0; }
11414+static inline unsigned long native_pax_close_kernel(void) { return 0; }
11415+#endif
11416+
11417 /*
11418 * The following only work if pte_present() is true.
11419 * Undefined behaviour if not..
11420 */
11421+static inline int pte_user(pte_t pte)
11422+{
11423+ return pte_val(pte) & _PAGE_USER;
11424+}
11425+
11426 static inline int pte_dirty(pte_t pte)
11427 {
11428 return pte_flags(pte) & _PAGE_DIRTY;
11429@@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11430 return pte_clear_flags(pte, _PAGE_RW);
11431 }
11432
11433+static inline pte_t pte_mkread(pte_t pte)
11434+{
11435+ return __pte(pte_val(pte) | _PAGE_USER);
11436+}
11437+
11438 static inline pte_t pte_mkexec(pte_t pte)
11439 {
11440- return pte_clear_flags(pte, _PAGE_NX);
11441+#ifdef CONFIG_X86_PAE
11442+ if (__supported_pte_mask & _PAGE_NX)
11443+ return pte_clear_flags(pte, _PAGE_NX);
11444+ else
11445+#endif
11446+ return pte_set_flags(pte, _PAGE_USER);
11447+}
11448+
11449+static inline pte_t pte_exprotect(pte_t pte)
11450+{
11451+#ifdef CONFIG_X86_PAE
11452+ if (__supported_pte_mask & _PAGE_NX)
11453+ return pte_set_flags(pte, _PAGE_NX);
11454+ else
11455+#endif
11456+ return pte_clear_flags(pte, _PAGE_USER);
11457 }
11458
11459 static inline pte_t pte_mkdirty(pte_t pte)
11460@@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11461 #endif
11462
11463 #ifndef __ASSEMBLY__
11464+
11465+#ifdef CONFIG_PAX_PER_CPU_PGD
11466+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11467+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11468+{
11469+ return cpu_pgd[cpu];
11470+}
11471+#endif
11472+
11473 #include <linux/mm_types.h>
11474
11475 static inline int pte_none(pte_t pte)
11476@@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11477
11478 static inline int pgd_bad(pgd_t pgd)
11479 {
11480- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11481+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11482 }
11483
11484 static inline int pgd_none(pgd_t pgd)
11485@@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
11486 * pgd_offset() returns a (pgd_t *)
11487 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11488 */
11489-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11490+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11491+
11492+#ifdef CONFIG_PAX_PER_CPU_PGD
11493+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11494+#endif
11495+
11496 /*
11497 * a shortcut which implies the use of the kernel's pgd, instead
11498 * of a process's
11499@@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
11500 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11501 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11502
11503+#ifdef CONFIG_X86_32
11504+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11505+#else
11506+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11507+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11508+
11509+#ifdef CONFIG_PAX_MEMORY_UDEREF
11510+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11511+#else
11512+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11513+#endif
11514+
11515+#endif
11516+
11517 #ifndef __ASSEMBLY__
11518
11519 extern int direct_gbpages;
11520@@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11521 * dst and src can be on the same page, but the range must not overlap,
11522 * and must not cross a page boundary.
11523 */
11524-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11525+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11526 {
11527- memcpy(dst, src, count * sizeof(pgd_t));
11528+ pax_open_kernel();
11529+ while (count--)
11530+ *dst++ = *src++;
11531+ pax_close_kernel();
11532 }
11533
11534+#ifdef CONFIG_PAX_PER_CPU_PGD
11535+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11536+#endif
11537+
11538+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11539+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11540+#else
11541+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11542+#endif
11543
11544 #include <asm-generic/pgtable.h>
11545 #endif /* __ASSEMBLY__ */
11546diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11547index 0c92113..34a77c6 100644
11548--- a/arch/x86/include/asm/pgtable_32.h
11549+++ b/arch/x86/include/asm/pgtable_32.h
11550@@ -25,9 +25,6 @@
11551 struct mm_struct;
11552 struct vm_area_struct;
11553
11554-extern pgd_t swapper_pg_dir[1024];
11555-extern pgd_t initial_page_table[1024];
11556-
11557 static inline void pgtable_cache_init(void) { }
11558 static inline void check_pgt_cache(void) { }
11559 void paging_init(void);
11560@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11561 # include <asm/pgtable-2level.h>
11562 #endif
11563
11564+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11565+extern pgd_t initial_page_table[PTRS_PER_PGD];
11566+#ifdef CONFIG_X86_PAE
11567+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11568+#endif
11569+
11570 #if defined(CONFIG_HIGHPTE)
11571 #define pte_offset_map(dir, address) \
11572 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11573@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11574 /* Clear a kernel PTE and flush it from the TLB */
11575 #define kpte_clear_flush(ptep, vaddr) \
11576 do { \
11577+ pax_open_kernel(); \
11578 pte_clear(&init_mm, (vaddr), (ptep)); \
11579+ pax_close_kernel(); \
11580 __flush_tlb_one((vaddr)); \
11581 } while (0)
11582
11583@@ -74,6 +79,9 @@ do { \
11584
11585 #endif /* !__ASSEMBLY__ */
11586
11587+#define HAVE_ARCH_UNMAPPED_AREA
11588+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11589+
11590 /*
11591 * kern_addr_valid() is (1) for FLATMEM and (0) for
11592 * SPARSEMEM and DISCONTIGMEM
11593diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11594index ed5903b..c7fe163 100644
11595--- a/arch/x86/include/asm/pgtable_32_types.h
11596+++ b/arch/x86/include/asm/pgtable_32_types.h
11597@@ -8,7 +8,7 @@
11598 */
11599 #ifdef CONFIG_X86_PAE
11600 # include <asm/pgtable-3level_types.h>
11601-# define PMD_SIZE (1UL << PMD_SHIFT)
11602+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11603 # define PMD_MASK (~(PMD_SIZE - 1))
11604 #else
11605 # include <asm/pgtable-2level_types.h>
11606@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11607 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11608 #endif
11609
11610+#ifdef CONFIG_PAX_KERNEXEC
11611+#ifndef __ASSEMBLY__
11612+extern unsigned char MODULES_EXEC_VADDR[];
11613+extern unsigned char MODULES_EXEC_END[];
11614+#endif
11615+#include <asm/boot.h>
11616+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11617+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11618+#else
11619+#define ktla_ktva(addr) (addr)
11620+#define ktva_ktla(addr) (addr)
11621+#endif
11622+
11623 #define MODULES_VADDR VMALLOC_START
11624 #define MODULES_END VMALLOC_END
11625 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11626diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11627index 975f709..9f779c9 100644
11628--- a/arch/x86/include/asm/pgtable_64.h
11629+++ b/arch/x86/include/asm/pgtable_64.h
11630@@ -16,10 +16,14 @@
11631
11632 extern pud_t level3_kernel_pgt[512];
11633 extern pud_t level3_ident_pgt[512];
11634+extern pud_t level3_vmalloc_start_pgt[512];
11635+extern pud_t level3_vmalloc_end_pgt[512];
11636+extern pud_t level3_vmemmap_pgt[512];
11637+extern pud_t level2_vmemmap_pgt[512];
11638 extern pmd_t level2_kernel_pgt[512];
11639 extern pmd_t level2_fixmap_pgt[512];
11640-extern pmd_t level2_ident_pgt[512];
11641-extern pgd_t init_level4_pgt[];
11642+extern pmd_t level2_ident_pgt[512*2];
11643+extern pgd_t init_level4_pgt[512];
11644
11645 #define swapper_pg_dir init_level4_pgt
11646
11647@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11648
11649 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11650 {
11651+ pax_open_kernel();
11652 *pmdp = pmd;
11653+ pax_close_kernel();
11654 }
11655
11656 static inline void native_pmd_clear(pmd_t *pmd)
11657@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11658
11659 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11660 {
11661+ pax_open_kernel();
11662 *pudp = pud;
11663+ pax_close_kernel();
11664 }
11665
11666 static inline void native_pud_clear(pud_t *pud)
11667@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11668
11669 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11670 {
11671+ pax_open_kernel();
11672+ *pgdp = pgd;
11673+ pax_close_kernel();
11674+}
11675+
11676+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11677+{
11678 *pgdp = pgd;
11679 }
11680
11681diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11682index 766ea16..5b96cb3 100644
11683--- a/arch/x86/include/asm/pgtable_64_types.h
11684+++ b/arch/x86/include/asm/pgtable_64_types.h
11685@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11686 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11687 #define MODULES_END _AC(0xffffffffff000000, UL)
11688 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11689+#define MODULES_EXEC_VADDR MODULES_VADDR
11690+#define MODULES_EXEC_END MODULES_END
11691+
11692+#define ktla_ktva(addr) (addr)
11693+#define ktva_ktla(addr) (addr)
11694
11695 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11696diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11697index 013286a..8b42f4f 100644
11698--- a/arch/x86/include/asm/pgtable_types.h
11699+++ b/arch/x86/include/asm/pgtable_types.h
11700@@ -16,13 +16,12 @@
11701 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11702 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11703 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11704-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11705+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11706 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11707 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11708 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11709-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11710-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11711-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11712+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11713+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11714 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11715
11716 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11717@@ -40,7 +39,6 @@
11718 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11719 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11720 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11721-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11722 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11723 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11724 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11725@@ -57,8 +55,10 @@
11726
11727 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11728 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11729-#else
11730+#elif defined(CONFIG_KMEMCHECK)
11731 #define _PAGE_NX (_AT(pteval_t, 0))
11732+#else
11733+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11734 #endif
11735
11736 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11737@@ -96,6 +96,9 @@
11738 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11739 _PAGE_ACCESSED)
11740
11741+#define PAGE_READONLY_NOEXEC PAGE_READONLY
11742+#define PAGE_SHARED_NOEXEC PAGE_SHARED
11743+
11744 #define __PAGE_KERNEL_EXEC \
11745 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11746 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11747@@ -106,7 +109,7 @@
11748 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11749 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11750 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11751-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11752+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11753 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11754 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11755 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11756@@ -168,8 +171,8 @@
11757 * bits are combined, this will alow user to access the high address mapped
11758 * VDSO in the presence of CONFIG_COMPAT_VDSO
11759 */
11760-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11761-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11762+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11763+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11764 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11765 #endif
11766
11767@@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11768 {
11769 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11770 }
11771+#endif
11772
11773+#if PAGETABLE_LEVELS == 3
11774+#include <asm-generic/pgtable-nopud.h>
11775+#endif
11776+
11777+#if PAGETABLE_LEVELS == 2
11778+#include <asm-generic/pgtable-nopmd.h>
11779+#endif
11780+
11781+#ifndef __ASSEMBLY__
11782 #if PAGETABLE_LEVELS > 3
11783 typedef struct { pudval_t pud; } pud_t;
11784
11785@@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11786 return pud.pud;
11787 }
11788 #else
11789-#include <asm-generic/pgtable-nopud.h>
11790-
11791 static inline pudval_t native_pud_val(pud_t pud)
11792 {
11793 return native_pgd_val(pud.pgd);
11794@@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11795 return pmd.pmd;
11796 }
11797 #else
11798-#include <asm-generic/pgtable-nopmd.h>
11799-
11800 static inline pmdval_t native_pmd_val(pmd_t pmd)
11801 {
11802 return native_pgd_val(pmd.pud.pgd);
11803@@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11804
11805 extern pteval_t __supported_pte_mask;
11806 extern void set_nx(void);
11807-extern int nx_enabled;
11808
11809 #define pgprot_writecombine pgprot_writecombine
11810 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11811diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11812index 4fa7dcc..764e33a 100644
11813--- a/arch/x86/include/asm/processor.h
11814+++ b/arch/x86/include/asm/processor.h
11815@@ -276,7 +276,7 @@ struct tss_struct {
11816
11817 } ____cacheline_aligned;
11818
11819-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11820+extern struct tss_struct init_tss[NR_CPUS];
11821
11822 /*
11823 * Save the original ist values for checking stack pointers during debugging
11824@@ -807,11 +807,18 @@ static inline void spin_lock_prefetch(const void *x)
11825 */
11826 #define TASK_SIZE PAGE_OFFSET
11827 #define TASK_SIZE_MAX TASK_SIZE
11828+
11829+#ifdef CONFIG_PAX_SEGMEXEC
11830+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11831+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11832+#else
11833 #define STACK_TOP TASK_SIZE
11834-#define STACK_TOP_MAX STACK_TOP
11835+#endif
11836+
11837+#define STACK_TOP_MAX TASK_SIZE
11838
11839 #define INIT_THREAD { \
11840- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11841+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11842 .vm86_info = NULL, \
11843 .sysenter_cs = __KERNEL_CS, \
11844 .io_bitmap_ptr = NULL, \
11845@@ -825,7 +832,7 @@ static inline void spin_lock_prefetch(const void *x)
11846 */
11847 #define INIT_TSS { \
11848 .x86_tss = { \
11849- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11850+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11851 .ss0 = __KERNEL_DS, \
11852 .ss1 = __KERNEL_CS, \
11853 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11854@@ -836,11 +843,7 @@ static inline void spin_lock_prefetch(const void *x)
11855 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11856
11857 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11858-#define KSTK_TOP(info) \
11859-({ \
11860- unsigned long *__ptr = (unsigned long *)(info); \
11861- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11862-})
11863+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11864
11865 /*
11866 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11867@@ -855,7 +858,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11868 #define task_pt_regs(task) \
11869 ({ \
11870 struct pt_regs *__regs__; \
11871- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11872+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11873 __regs__ - 1; \
11874 })
11875
11876@@ -865,13 +868,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11877 /*
11878 * User space process size. 47bits minus one guard page.
11879 */
11880-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11881+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11882
11883 /* This decides where the kernel will search for a free chunk of vm
11884 * space during mmap's.
11885 */
11886 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11887- 0xc0000000 : 0xFFFFe000)
11888+ 0xc0000000 : 0xFFFFf000)
11889
11890 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
11891 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11892@@ -882,11 +885,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11893 #define STACK_TOP_MAX TASK_SIZE_MAX
11894
11895 #define INIT_THREAD { \
11896- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11897+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11898 }
11899
11900 #define INIT_TSS { \
11901- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11902+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11903 }
11904
11905 /*
11906@@ -914,6 +917,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11907 */
11908 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11909
11910+#ifdef CONFIG_PAX_SEGMEXEC
11911+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11912+#endif
11913+
11914 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11915
11916 /* Get/set a process' ability to use the timestamp counter instruction */
11917@@ -976,12 +983,12 @@ extern bool cpu_has_amd_erratum(const int *);
11918
11919 void cpu_idle_wait(void);
11920
11921-extern unsigned long arch_align_stack(unsigned long sp);
11922+#define arch_align_stack(x) ((x) & ~0xfUL)
11923 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11924
11925 void default_idle(void);
11926 bool set_pm_idle_to_default(void);
11927
11928-void stop_this_cpu(void *dummy);
11929+void stop_this_cpu(void *dummy) __noreturn;
11930
11931 #endif /* _ASM_X86_PROCESSOR_H */
11932diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11933index dcfde52..dbfea06 100644
11934--- a/arch/x86/include/asm/ptrace.h
11935+++ b/arch/x86/include/asm/ptrace.h
11936@@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11937 }
11938
11939 /*
11940- * user_mode_vm(regs) determines whether a register set came from user mode.
11941+ * user_mode(regs) determines whether a register set came from user mode.
11942 * This is true if V8086 mode was enabled OR if the register set was from
11943 * protected mode with RPL-3 CS value. This tricky test checks that with
11944 * one comparison. Many places in the kernel can bypass this full check
11945- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11946+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11947+ * be used.
11948 */
11949-static inline int user_mode(struct pt_regs *regs)
11950+static inline int user_mode_novm(struct pt_regs *regs)
11951 {
11952 #ifdef CONFIG_X86_32
11953 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11954 #else
11955- return !!(regs->cs & 3);
11956+ return !!(regs->cs & SEGMENT_RPL_MASK);
11957 #endif
11958 }
11959
11960-static inline int user_mode_vm(struct pt_regs *regs)
11961+static inline int user_mode(struct pt_regs *regs)
11962 {
11963 #ifdef CONFIG_X86_32
11964 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11965 USER_RPL;
11966 #else
11967- return user_mode(regs);
11968+ return user_mode_novm(regs);
11969 #endif
11970 }
11971
11972@@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
11973 #ifdef CONFIG_X86_64
11974 static inline bool user_64bit_mode(struct pt_regs *regs)
11975 {
11976+ unsigned long cs = regs->cs & 0xffff;
11977 #ifndef CONFIG_PARAVIRT
11978 /*
11979 * On non-paravirt systems, this is the only long mode CPL 3
11980 * selector. We do not allow long mode selectors in the LDT.
11981 */
11982- return regs->cs == __USER_CS;
11983+ return cs == __USER_CS;
11984 #else
11985 /* Headers are too twisted for this to go in paravirt.h. */
11986- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
11987+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
11988 #endif
11989 }
11990 #endif
11991diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
11992index 92f29706..a79cbbb 100644
11993--- a/arch/x86/include/asm/reboot.h
11994+++ b/arch/x86/include/asm/reboot.h
11995@@ -6,19 +6,19 @@
11996 struct pt_regs;
11997
11998 struct machine_ops {
11999- void (*restart)(char *cmd);
12000- void (*halt)(void);
12001- void (*power_off)(void);
12002+ void (* __noreturn restart)(char *cmd);
12003+ void (* __noreturn halt)(void);
12004+ void (* __noreturn power_off)(void);
12005 void (*shutdown)(void);
12006 void (*crash_shutdown)(struct pt_regs *);
12007- void (*emergency_restart)(void);
12008-};
12009+ void (* __noreturn emergency_restart)(void);
12010+} __no_const;
12011
12012 extern struct machine_ops machine_ops;
12013
12014 void native_machine_crash_shutdown(struct pt_regs *regs);
12015 void native_machine_shutdown(void);
12016-void machine_real_restart(unsigned int type);
12017+void machine_real_restart(unsigned int type) __noreturn;
12018 /* These must match dispatch_table in reboot_32.S */
12019 #define MRR_BIOS 0
12020 #define MRR_APM 1
12021diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
12022index 2dbe4a7..ce1db00 100644
12023--- a/arch/x86/include/asm/rwsem.h
12024+++ b/arch/x86/include/asm/rwsem.h
12025@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
12026 {
12027 asm volatile("# beginning down_read\n\t"
12028 LOCK_PREFIX _ASM_INC "(%1)\n\t"
12029+
12030+#ifdef CONFIG_PAX_REFCOUNT
12031+ "jno 0f\n"
12032+ LOCK_PREFIX _ASM_DEC "(%1)\n"
12033+ "int $4\n0:\n"
12034+ _ASM_EXTABLE(0b, 0b)
12035+#endif
12036+
12037 /* adds 0x00000001 */
12038 " jns 1f\n"
12039 " call call_rwsem_down_read_failed\n"
12040@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
12041 "1:\n\t"
12042 " mov %1,%2\n\t"
12043 " add %3,%2\n\t"
12044+
12045+#ifdef CONFIG_PAX_REFCOUNT
12046+ "jno 0f\n"
12047+ "sub %3,%2\n"
12048+ "int $4\n0:\n"
12049+ _ASM_EXTABLE(0b, 0b)
12050+#endif
12051+
12052 " jle 2f\n\t"
12053 LOCK_PREFIX " cmpxchg %2,%0\n\t"
12054 " jnz 1b\n\t"
12055@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
12056 long tmp;
12057 asm volatile("# beginning down_write\n\t"
12058 LOCK_PREFIX " xadd %1,(%2)\n\t"
12059+
12060+#ifdef CONFIG_PAX_REFCOUNT
12061+ "jno 0f\n"
12062+ "mov %1,(%2)\n"
12063+ "int $4\n0:\n"
12064+ _ASM_EXTABLE(0b, 0b)
12065+#endif
12066+
12067 /* adds 0xffff0001, returns the old value */
12068 " test %1,%1\n\t"
12069 /* was the count 0 before? */
12070@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12071 long tmp;
12072 asm volatile("# beginning __up_read\n\t"
12073 LOCK_PREFIX " xadd %1,(%2)\n\t"
12074+
12075+#ifdef CONFIG_PAX_REFCOUNT
12076+ "jno 0f\n"
12077+ "mov %1,(%2)\n"
12078+ "int $4\n0:\n"
12079+ _ASM_EXTABLE(0b, 0b)
12080+#endif
12081+
12082 /* subtracts 1, returns the old value */
12083 " jns 1f\n\t"
12084 " call call_rwsem_wake\n" /* expects old value in %edx */
12085@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12086 long tmp;
12087 asm volatile("# beginning __up_write\n\t"
12088 LOCK_PREFIX " xadd %1,(%2)\n\t"
12089+
12090+#ifdef CONFIG_PAX_REFCOUNT
12091+ "jno 0f\n"
12092+ "mov %1,(%2)\n"
12093+ "int $4\n0:\n"
12094+ _ASM_EXTABLE(0b, 0b)
12095+#endif
12096+
12097 /* subtracts 0xffff0001, returns the old value */
12098 " jns 1f\n\t"
12099 " call call_rwsem_wake\n" /* expects old value in %edx */
12100@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12101 {
12102 asm volatile("# beginning __downgrade_write\n\t"
12103 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12104+
12105+#ifdef CONFIG_PAX_REFCOUNT
12106+ "jno 0f\n"
12107+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12108+ "int $4\n0:\n"
12109+ _ASM_EXTABLE(0b, 0b)
12110+#endif
12111+
12112 /*
12113 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12114 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12115@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12116 */
12117 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12118 {
12119- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12120+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12121+
12122+#ifdef CONFIG_PAX_REFCOUNT
12123+ "jno 0f\n"
12124+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
12125+ "int $4\n0:\n"
12126+ _ASM_EXTABLE(0b, 0b)
12127+#endif
12128+
12129 : "+m" (sem->count)
12130 : "er" (delta));
12131 }
12132@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12133 */
12134 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12135 {
12136- return delta + xadd(&sem->count, delta);
12137+ return delta + xadd_check_overflow(&sem->count, delta);
12138 }
12139
12140 #endif /* __KERNEL__ */
12141diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12142index 1654662..5af4157 100644
12143--- a/arch/x86/include/asm/segment.h
12144+++ b/arch/x86/include/asm/segment.h
12145@@ -64,10 +64,15 @@
12146 * 26 - ESPFIX small SS
12147 * 27 - per-cpu [ offset to per-cpu data area ]
12148 * 28 - stack_canary-20 [ for stack protector ]
12149- * 29 - unused
12150- * 30 - unused
12151+ * 29 - PCI BIOS CS
12152+ * 30 - PCI BIOS DS
12153 * 31 - TSS for double fault handler
12154 */
12155+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12156+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12157+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12158+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12159+
12160 #define GDT_ENTRY_TLS_MIN 6
12161 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12162
12163@@ -79,6 +84,8 @@
12164
12165 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12166
12167+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12168+
12169 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12170
12171 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12172@@ -104,6 +111,12 @@
12173 #define __KERNEL_STACK_CANARY 0
12174 #endif
12175
12176+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12177+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12178+
12179+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12180+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12181+
12182 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12183
12184 /*
12185@@ -141,7 +154,7 @@
12186 */
12187
12188 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12189-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12190+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12191
12192
12193 #else
12194@@ -165,6 +178,8 @@
12195 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12196 #define __USER32_DS __USER_DS
12197
12198+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12199+
12200 #define GDT_ENTRY_TSS 8 /* needs two entries */
12201 #define GDT_ENTRY_LDT 10 /* needs two entries */
12202 #define GDT_ENTRY_TLS_MIN 12
12203@@ -185,6 +200,7 @@
12204 #endif
12205
12206 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12207+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12208 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12209 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12210 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12211@@ -263,7 +279,7 @@ static inline unsigned long get_limit(unsigned long segment)
12212 {
12213 unsigned long __limit;
12214 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12215- return __limit + 1;
12216+ return __limit;
12217 }
12218
12219 #endif /* !__ASSEMBLY__ */
12220diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12221index 0434c40..1714bf0 100644
12222--- a/arch/x86/include/asm/smp.h
12223+++ b/arch/x86/include/asm/smp.h
12224@@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
12225 /* cpus sharing the last level cache: */
12226 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
12227 DECLARE_PER_CPU(u16, cpu_llc_id);
12228-DECLARE_PER_CPU(int, cpu_number);
12229+DECLARE_PER_CPU(unsigned int, cpu_number);
12230
12231 static inline struct cpumask *cpu_sibling_mask(int cpu)
12232 {
12233@@ -77,7 +77,7 @@ struct smp_ops {
12234
12235 void (*send_call_func_ipi)(const struct cpumask *mask);
12236 void (*send_call_func_single_ipi)(int cpu);
12237-};
12238+} __no_const;
12239
12240 /* Globals due to paravirt */
12241 extern void set_cpu_sibling_map(int cpu);
12242@@ -192,14 +192,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12243 extern int safe_smp_processor_id(void);
12244
12245 #elif defined(CONFIG_X86_64_SMP)
12246-#define raw_smp_processor_id() (percpu_read(cpu_number))
12247-
12248-#define stack_smp_processor_id() \
12249-({ \
12250- struct thread_info *ti; \
12251- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12252- ti->cpu; \
12253-})
12254+#define raw_smp_processor_id() (percpu_read(cpu_number))
12255+#define stack_smp_processor_id() raw_smp_processor_id()
12256 #define safe_smp_processor_id() smp_processor_id()
12257
12258 #endif
12259diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12260index 76bfa2c..12d3fe7 100644
12261--- a/arch/x86/include/asm/spinlock.h
12262+++ b/arch/x86/include/asm/spinlock.h
12263@@ -175,6 +175,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12264 static inline void arch_read_lock(arch_rwlock_t *rw)
12265 {
12266 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12267+
12268+#ifdef CONFIG_PAX_REFCOUNT
12269+ "jno 0f\n"
12270+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12271+ "int $4\n0:\n"
12272+ _ASM_EXTABLE(0b, 0b)
12273+#endif
12274+
12275 "jns 1f\n"
12276 "call __read_lock_failed\n\t"
12277 "1:\n"
12278@@ -184,6 +192,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12279 static inline void arch_write_lock(arch_rwlock_t *rw)
12280 {
12281 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12282+
12283+#ifdef CONFIG_PAX_REFCOUNT
12284+ "jno 0f\n"
12285+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12286+ "int $4\n0:\n"
12287+ _ASM_EXTABLE(0b, 0b)
12288+#endif
12289+
12290 "jz 1f\n"
12291 "call __write_lock_failed\n\t"
12292 "1:\n"
12293@@ -213,13 +229,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12294
12295 static inline void arch_read_unlock(arch_rwlock_t *rw)
12296 {
12297- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12298+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12299+
12300+#ifdef CONFIG_PAX_REFCOUNT
12301+ "jno 0f\n"
12302+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12303+ "int $4\n0:\n"
12304+ _ASM_EXTABLE(0b, 0b)
12305+#endif
12306+
12307 :"+m" (rw->lock) : : "memory");
12308 }
12309
12310 static inline void arch_write_unlock(arch_rwlock_t *rw)
12311 {
12312- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12313+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12314+
12315+#ifdef CONFIG_PAX_REFCOUNT
12316+ "jno 0f\n"
12317+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12318+ "int $4\n0:\n"
12319+ _ASM_EXTABLE(0b, 0b)
12320+#endif
12321+
12322 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12323 }
12324
12325diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12326index b5d9533..41655fa 100644
12327--- a/arch/x86/include/asm/stackprotector.h
12328+++ b/arch/x86/include/asm/stackprotector.h
12329@@ -47,7 +47,7 @@
12330 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12331 */
12332 #define GDT_STACK_CANARY_INIT \
12333- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12334+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12335
12336 /*
12337 * Initialize the stackprotector canary value.
12338@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12339
12340 static inline void load_stack_canary_segment(void)
12341 {
12342-#ifdef CONFIG_X86_32
12343+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12344 asm volatile ("mov %0, %%gs" : : "r" (0));
12345 #endif
12346 }
12347diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12348index 70bbe39..4ae2bd4 100644
12349--- a/arch/x86/include/asm/stacktrace.h
12350+++ b/arch/x86/include/asm/stacktrace.h
12351@@ -11,28 +11,20 @@
12352
12353 extern int kstack_depth_to_print;
12354
12355-struct thread_info;
12356+struct task_struct;
12357 struct stacktrace_ops;
12358
12359-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12360- unsigned long *stack,
12361- unsigned long bp,
12362- const struct stacktrace_ops *ops,
12363- void *data,
12364- unsigned long *end,
12365- int *graph);
12366+typedef unsigned long walk_stack_t(struct task_struct *task,
12367+ void *stack_start,
12368+ unsigned long *stack,
12369+ unsigned long bp,
12370+ const struct stacktrace_ops *ops,
12371+ void *data,
12372+ unsigned long *end,
12373+ int *graph);
12374
12375-extern unsigned long
12376-print_context_stack(struct thread_info *tinfo,
12377- unsigned long *stack, unsigned long bp,
12378- const struct stacktrace_ops *ops, void *data,
12379- unsigned long *end, int *graph);
12380-
12381-extern unsigned long
12382-print_context_stack_bp(struct thread_info *tinfo,
12383- unsigned long *stack, unsigned long bp,
12384- const struct stacktrace_ops *ops, void *data,
12385- unsigned long *end, int *graph);
12386+extern walk_stack_t print_context_stack;
12387+extern walk_stack_t print_context_stack_bp;
12388
12389 /* Generic stack tracer with callbacks */
12390
12391@@ -40,7 +32,7 @@ struct stacktrace_ops {
12392 void (*address)(void *data, unsigned long address, int reliable);
12393 /* On negative return stop dumping */
12394 int (*stack)(void *data, char *name);
12395- walk_stack_t walk_stack;
12396+ walk_stack_t *walk_stack;
12397 };
12398
12399 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12400diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12401index 4ec45b3..a4f0a8a 100644
12402--- a/arch/x86/include/asm/switch_to.h
12403+++ b/arch/x86/include/asm/switch_to.h
12404@@ -108,7 +108,7 @@ do { \
12405 "call __switch_to\n\t" \
12406 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12407 __switch_canary \
12408- "movq %P[thread_info](%%rsi),%%r8\n\t" \
12409+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12410 "movq %%rax,%%rdi\n\t" \
12411 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12412 "jnz ret_from_fork\n\t" \
12413@@ -119,7 +119,7 @@ do { \
12414 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12415 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12416 [_tif_fork] "i" (_TIF_FORK), \
12417- [thread_info] "i" (offsetof(struct task_struct, stack)), \
12418+ [thread_info] "m" (current_tinfo), \
12419 [current_task] "m" (current_task) \
12420 __switch_canary_iparam \
12421 : "memory", "cc" __EXTRA_CLOBBER)
12422diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12423index 3fda9db4..4ca1c61 100644
12424--- a/arch/x86/include/asm/sys_ia32.h
12425+++ b/arch/x86/include/asm/sys_ia32.h
12426@@ -40,7 +40,7 @@ asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *,
12427 struct old_sigaction32 __user *);
12428 asmlinkage long sys32_alarm(unsigned int);
12429
12430-asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12431+asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12432 asmlinkage long sys32_sysfs(int, u32, u32);
12433
12434 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12435diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12436index ad6df8c..5e0cf6e 100644
12437--- a/arch/x86/include/asm/thread_info.h
12438+++ b/arch/x86/include/asm/thread_info.h
12439@@ -10,6 +10,7 @@
12440 #include <linux/compiler.h>
12441 #include <asm/page.h>
12442 #include <asm/types.h>
12443+#include <asm/percpu.h>
12444
12445 /*
12446 * low level task data that entry.S needs immediate access to
12447@@ -24,7 +25,6 @@ struct exec_domain;
12448 #include <linux/atomic.h>
12449
12450 struct thread_info {
12451- struct task_struct *task; /* main task structure */
12452 struct exec_domain *exec_domain; /* execution domain */
12453 __u32 flags; /* low level flags */
12454 __u32 status; /* thread synchronous flags */
12455@@ -34,19 +34,13 @@ struct thread_info {
12456 mm_segment_t addr_limit;
12457 struct restart_block restart_block;
12458 void __user *sysenter_return;
12459-#ifdef CONFIG_X86_32
12460- unsigned long previous_esp; /* ESP of the previous stack in
12461- case of nested (IRQ) stacks
12462- */
12463- __u8 supervisor_stack[0];
12464-#endif
12465+ unsigned long lowest_stack;
12466 unsigned int sig_on_uaccess_error:1;
12467 unsigned int uaccess_err:1; /* uaccess failed */
12468 };
12469
12470-#define INIT_THREAD_INFO(tsk) \
12471+#define INIT_THREAD_INFO \
12472 { \
12473- .task = &tsk, \
12474 .exec_domain = &default_exec_domain, \
12475 .flags = 0, \
12476 .cpu = 0, \
12477@@ -57,7 +51,7 @@ struct thread_info {
12478 }, \
12479 }
12480
12481-#define init_thread_info (init_thread_union.thread_info)
12482+#define init_thread_info (init_thread_union.stack)
12483 #define init_stack (init_thread_union.stack)
12484
12485 #else /* !__ASSEMBLY__ */
12486@@ -97,6 +91,7 @@ struct thread_info {
12487 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12488 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12489 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12490+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12491
12492 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12493 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12494@@ -120,16 +115,18 @@ struct thread_info {
12495 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12496 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12497 #define _TIF_X32 (1 << TIF_X32)
12498+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12499
12500 /* work to do in syscall_trace_enter() */
12501 #define _TIF_WORK_SYSCALL_ENTRY \
12502 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12503- _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12504+ _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12505+ _TIF_GRSEC_SETXID)
12506
12507 /* work to do in syscall_trace_leave() */
12508 #define _TIF_WORK_SYSCALL_EXIT \
12509 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12510- _TIF_SYSCALL_TRACEPOINT)
12511+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12512
12513 /* work to do on interrupt/exception return */
12514 #define _TIF_WORK_MASK \
12515@@ -139,7 +136,8 @@ struct thread_info {
12516
12517 /* work to do on any return to user space */
12518 #define _TIF_ALLWORK_MASK \
12519- ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12520+ ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12521+ _TIF_GRSEC_SETXID)
12522
12523 /* Only used for 64 bit */
12524 #define _TIF_DO_NOTIFY_MASK \
12525@@ -173,45 +171,40 @@ struct thread_info {
12526 ret; \
12527 })
12528
12529-#ifdef CONFIG_X86_32
12530-
12531-#define STACK_WARN (THREAD_SIZE/8)
12532-/*
12533- * macros/functions for gaining access to the thread information structure
12534- *
12535- * preempt_count needs to be 1 initially, until the scheduler is functional.
12536- */
12537-#ifndef __ASSEMBLY__
12538-
12539-
12540-/* how to get the current stack pointer from C */
12541-register unsigned long current_stack_pointer asm("esp") __used;
12542-
12543-/* how to get the thread information struct from C */
12544-static inline struct thread_info *current_thread_info(void)
12545-{
12546- return (struct thread_info *)
12547- (current_stack_pointer & ~(THREAD_SIZE - 1));
12548-}
12549-
12550-#else /* !__ASSEMBLY__ */
12551-
12552+#ifdef __ASSEMBLY__
12553 /* how to get the thread information struct from ASM */
12554 #define GET_THREAD_INFO(reg) \
12555- movl $-THREAD_SIZE, reg; \
12556- andl %esp, reg
12557+ mov PER_CPU_VAR(current_tinfo), reg
12558
12559 /* use this one if reg already contains %esp */
12560-#define GET_THREAD_INFO_WITH_ESP(reg) \
12561- andl $-THREAD_SIZE, reg
12562+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12563+#else
12564+/* how to get the thread information struct from C */
12565+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12566+
12567+static __always_inline struct thread_info *current_thread_info(void)
12568+{
12569+ return percpu_read_stable(current_tinfo);
12570+}
12571+#endif
12572+
12573+#ifdef CONFIG_X86_32
12574+
12575+#define STACK_WARN (THREAD_SIZE/8)
12576+/*
12577+ * macros/functions for gaining access to the thread information structure
12578+ *
12579+ * preempt_count needs to be 1 initially, until the scheduler is functional.
12580+ */
12581+#ifndef __ASSEMBLY__
12582+
12583+/* how to get the current stack pointer from C */
12584+register unsigned long current_stack_pointer asm("esp") __used;
12585
12586 #endif
12587
12588 #else /* X86_32 */
12589
12590-#include <asm/percpu.h>
12591-#define KERNEL_STACK_OFFSET (5*8)
12592-
12593 /*
12594 * macros/functions for gaining access to the thread information structure
12595 * preempt_count needs to be 1 initially, until the scheduler is functional.
12596@@ -219,27 +212,8 @@ static inline struct thread_info *current_thread_info(void)
12597 #ifndef __ASSEMBLY__
12598 DECLARE_PER_CPU(unsigned long, kernel_stack);
12599
12600-static inline struct thread_info *current_thread_info(void)
12601-{
12602- struct thread_info *ti;
12603- ti = (void *)(percpu_read_stable(kernel_stack) +
12604- KERNEL_STACK_OFFSET - THREAD_SIZE);
12605- return ti;
12606-}
12607-
12608-#else /* !__ASSEMBLY__ */
12609-
12610-/* how to get the thread information struct from ASM */
12611-#define GET_THREAD_INFO(reg) \
12612- movq PER_CPU_VAR(kernel_stack),reg ; \
12613- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12614-
12615-/*
12616- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12617- * a certain register (to be used in assembler memory operands).
12618- */
12619-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12620-
12621+/* how to get the current stack pointer from C */
12622+register unsigned long current_stack_pointer asm("rsp") __used;
12623 #endif
12624
12625 #endif /* !X86_32 */
12626@@ -285,5 +259,16 @@ extern void arch_task_cache_init(void);
12627 extern void free_thread_info(struct thread_info *ti);
12628 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12629 #define arch_task_cache_init arch_task_cache_init
12630+
12631+#define __HAVE_THREAD_FUNCTIONS
12632+#define task_thread_info(task) (&(task)->tinfo)
12633+#define task_stack_page(task) ((task)->stack)
12634+#define setup_thread_stack(p, org) do {} while (0)
12635+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12636+
12637+#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
12638+extern struct task_struct *alloc_task_struct_node(int node);
12639+extern void free_task_struct(struct task_struct *);
12640+
12641 #endif
12642 #endif /* _ASM_X86_THREAD_INFO_H */
12643diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12644index e054459..14bc8a7 100644
12645--- a/arch/x86/include/asm/uaccess.h
12646+++ b/arch/x86/include/asm/uaccess.h
12647@@ -7,12 +7,15 @@
12648 #include <linux/compiler.h>
12649 #include <linux/thread_info.h>
12650 #include <linux/string.h>
12651+#include <linux/sched.h>
12652 #include <asm/asm.h>
12653 #include <asm/page.h>
12654
12655 #define VERIFY_READ 0
12656 #define VERIFY_WRITE 1
12657
12658+extern void check_object_size(const void *ptr, unsigned long n, bool to);
12659+
12660 /*
12661 * The fs value determines whether argument validity checking should be
12662 * performed or not. If get_fs() == USER_DS, checking is performed, with
12663@@ -28,7 +31,12 @@
12664
12665 #define get_ds() (KERNEL_DS)
12666 #define get_fs() (current_thread_info()->addr_limit)
12667+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12668+void __set_fs(mm_segment_t x);
12669+void set_fs(mm_segment_t x);
12670+#else
12671 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12672+#endif
12673
12674 #define segment_eq(a, b) ((a).seg == (b).seg)
12675
12676@@ -76,7 +84,33 @@
12677 * checks that the pointer is in the user space range - after calling
12678 * this function, memory access functions may still return -EFAULT.
12679 */
12680-#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12681+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12682+#define access_ok(type, addr, size) \
12683+({ \
12684+ long __size = size; \
12685+ unsigned long __addr = (unsigned long)addr; \
12686+ unsigned long __addr_ao = __addr & PAGE_MASK; \
12687+ unsigned long __end_ao = __addr + __size - 1; \
12688+ bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
12689+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12690+ while(__addr_ao <= __end_ao) { \
12691+ char __c_ao; \
12692+ __addr_ao += PAGE_SIZE; \
12693+ if (__size > PAGE_SIZE) \
12694+ cond_resched(); \
12695+ if (__get_user(__c_ao, (char __user *)__addr)) \
12696+ break; \
12697+ if (type != VERIFY_WRITE) { \
12698+ __addr = __addr_ao; \
12699+ continue; \
12700+ } \
12701+ if (__put_user(__c_ao, (char __user *)__addr)) \
12702+ break; \
12703+ __addr = __addr_ao; \
12704+ } \
12705+ } \
12706+ __ret_ao; \
12707+})
12708
12709 /*
12710 * The exception table consists of pairs of addresses: the first is the
12711@@ -182,12 +216,20 @@ extern int __get_user_bad(void);
12712 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12713 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12714
12715-
12716+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12717+#define __copyuser_seg "gs;"
12718+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12719+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12720+#else
12721+#define __copyuser_seg
12722+#define __COPYUSER_SET_ES
12723+#define __COPYUSER_RESTORE_ES
12724+#endif
12725
12726 #ifdef CONFIG_X86_32
12727 #define __put_user_asm_u64(x, addr, err, errret) \
12728- asm volatile("1: movl %%eax,0(%2)\n" \
12729- "2: movl %%edx,4(%2)\n" \
12730+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12731+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12732 "3:\n" \
12733 ".section .fixup,\"ax\"\n" \
12734 "4: movl %3,%0\n" \
12735@@ -199,8 +241,8 @@ extern int __get_user_bad(void);
12736 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12737
12738 #define __put_user_asm_ex_u64(x, addr) \
12739- asm volatile("1: movl %%eax,0(%1)\n" \
12740- "2: movl %%edx,4(%1)\n" \
12741+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12742+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12743 "3:\n" \
12744 _ASM_EXTABLE(1b, 2b - 1b) \
12745 _ASM_EXTABLE(2b, 3b - 2b) \
12746@@ -252,7 +294,7 @@ extern void __put_user_8(void);
12747 __typeof__(*(ptr)) __pu_val; \
12748 __chk_user_ptr(ptr); \
12749 might_fault(); \
12750- __pu_val = x; \
12751+ __pu_val = (x); \
12752 switch (sizeof(*(ptr))) { \
12753 case 1: \
12754 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12755@@ -373,7 +415,7 @@ do { \
12756 } while (0)
12757
12758 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12759- asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12760+ asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12761 "2:\n" \
12762 ".section .fixup,\"ax\"\n" \
12763 "3: mov %3,%0\n" \
12764@@ -381,7 +423,7 @@ do { \
12765 " jmp 2b\n" \
12766 ".previous\n" \
12767 _ASM_EXTABLE(1b, 3b) \
12768- : "=r" (err), ltype(x) \
12769+ : "=r" (err), ltype (x) \
12770 : "m" (__m(addr)), "i" (errret), "0" (err))
12771
12772 #define __get_user_size_ex(x, ptr, size) \
12773@@ -406,7 +448,7 @@ do { \
12774 } while (0)
12775
12776 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12777- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12778+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12779 "2:\n" \
12780 _ASM_EXTABLE(1b, 2b - 1b) \
12781 : ltype(x) : "m" (__m(addr)))
12782@@ -423,13 +465,24 @@ do { \
12783 int __gu_err; \
12784 unsigned long __gu_val; \
12785 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12786- (x) = (__force __typeof__(*(ptr)))__gu_val; \
12787+ (x) = (__typeof__(*(ptr)))__gu_val; \
12788 __gu_err; \
12789 })
12790
12791 /* FIXME: this hack is definitely wrong -AK */
12792 struct __large_struct { unsigned long buf[100]; };
12793-#define __m(x) (*(struct __large_struct __user *)(x))
12794+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12795+#define ____m(x) \
12796+({ \
12797+ unsigned long ____x = (unsigned long)(x); \
12798+ if (____x < PAX_USER_SHADOW_BASE) \
12799+ ____x += PAX_USER_SHADOW_BASE; \
12800+ (void __user *)____x; \
12801+})
12802+#else
12803+#define ____m(x) (x)
12804+#endif
12805+#define __m(x) (*(struct __large_struct __user *)____m(x))
12806
12807 /*
12808 * Tell gcc we read from memory instead of writing: this is because
12809@@ -437,7 +490,7 @@ struct __large_struct { unsigned long buf[100]; };
12810 * aliasing issues.
12811 */
12812 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12813- asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12814+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12815 "2:\n" \
12816 ".section .fixup,\"ax\"\n" \
12817 "3: mov %3,%0\n" \
12818@@ -445,10 +498,10 @@ struct __large_struct { unsigned long buf[100]; };
12819 ".previous\n" \
12820 _ASM_EXTABLE(1b, 3b) \
12821 : "=r"(err) \
12822- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12823+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12824
12825 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12826- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12827+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12828 "2:\n" \
12829 _ASM_EXTABLE(1b, 2b - 1b) \
12830 : : ltype(x), "m" (__m(addr)))
12831@@ -487,8 +540,12 @@ struct __large_struct { unsigned long buf[100]; };
12832 * On error, the variable @x is set to zero.
12833 */
12834
12835+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12836+#define __get_user(x, ptr) get_user((x), (ptr))
12837+#else
12838 #define __get_user(x, ptr) \
12839 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12840+#endif
12841
12842 /**
12843 * __put_user: - Write a simple value into user space, with less checking.
12844@@ -510,8 +567,12 @@ struct __large_struct { unsigned long buf[100]; };
12845 * Returns zero on success, or -EFAULT on error.
12846 */
12847
12848+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12849+#define __put_user(x, ptr) put_user((x), (ptr))
12850+#else
12851 #define __put_user(x, ptr) \
12852 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12853+#endif
12854
12855 #define __get_user_unaligned __get_user
12856 #define __put_user_unaligned __put_user
12857@@ -529,7 +590,7 @@ struct __large_struct { unsigned long buf[100]; };
12858 #define get_user_ex(x, ptr) do { \
12859 unsigned long __gue_val; \
12860 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12861- (x) = (__force __typeof__(*(ptr)))__gue_val; \
12862+ (x) = (__typeof__(*(ptr)))__gue_val; \
12863 } while (0)
12864
12865 #ifdef CONFIG_X86_WP_WORKS_OK
12866diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12867index 8084bc7..3d6ec37 100644
12868--- a/arch/x86/include/asm/uaccess_32.h
12869+++ b/arch/x86/include/asm/uaccess_32.h
12870@@ -11,15 +11,15 @@
12871 #include <asm/page.h>
12872
12873 unsigned long __must_check __copy_to_user_ll
12874- (void __user *to, const void *from, unsigned long n);
12875+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12876 unsigned long __must_check __copy_from_user_ll
12877- (void *to, const void __user *from, unsigned long n);
12878+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12879 unsigned long __must_check __copy_from_user_ll_nozero
12880- (void *to, const void __user *from, unsigned long n);
12881+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12882 unsigned long __must_check __copy_from_user_ll_nocache
12883- (void *to, const void __user *from, unsigned long n);
12884+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12885 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12886- (void *to, const void __user *from, unsigned long n);
12887+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12888
12889 /**
12890 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12891@@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12892 static __always_inline unsigned long __must_check
12893 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12894 {
12895+ if ((long)n < 0)
12896+ return n;
12897+
12898 if (__builtin_constant_p(n)) {
12899 unsigned long ret;
12900
12901@@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12902 return ret;
12903 }
12904 }
12905+ if (!__builtin_constant_p(n))
12906+ check_object_size(from, n, true);
12907 return __copy_to_user_ll(to, from, n);
12908 }
12909
12910@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12911 __copy_to_user(void __user *to, const void *from, unsigned long n)
12912 {
12913 might_fault();
12914+
12915 return __copy_to_user_inatomic(to, from, n);
12916 }
12917
12918 static __always_inline unsigned long
12919 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12920 {
12921+ if ((long)n < 0)
12922+ return n;
12923+
12924 /* Avoid zeroing the tail if the copy fails..
12925 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12926 * but as the zeroing behaviour is only significant when n is not
12927@@ -137,6 +146,10 @@ static __always_inline unsigned long
12928 __copy_from_user(void *to, const void __user *from, unsigned long n)
12929 {
12930 might_fault();
12931+
12932+ if ((long)n < 0)
12933+ return n;
12934+
12935 if (__builtin_constant_p(n)) {
12936 unsigned long ret;
12937
12938@@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12939 return ret;
12940 }
12941 }
12942+ if (!__builtin_constant_p(n))
12943+ check_object_size(to, n, false);
12944 return __copy_from_user_ll(to, from, n);
12945 }
12946
12947@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12948 const void __user *from, unsigned long n)
12949 {
12950 might_fault();
12951+
12952+ if ((long)n < 0)
12953+ return n;
12954+
12955 if (__builtin_constant_p(n)) {
12956 unsigned long ret;
12957
12958@@ -181,15 +200,19 @@ static __always_inline unsigned long
12959 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12960 unsigned long n)
12961 {
12962- return __copy_from_user_ll_nocache_nozero(to, from, n);
12963+ if ((long)n < 0)
12964+ return n;
12965+
12966+ return __copy_from_user_ll_nocache_nozero(to, from, n);
12967 }
12968
12969-unsigned long __must_check copy_to_user(void __user *to,
12970- const void *from, unsigned long n);
12971-unsigned long __must_check _copy_from_user(void *to,
12972- const void __user *from,
12973- unsigned long n);
12974-
12975+extern void copy_to_user_overflow(void)
12976+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12977+ __compiletime_error("copy_to_user() buffer size is not provably correct")
12978+#else
12979+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
12980+#endif
12981+;
12982
12983 extern void copy_from_user_overflow(void)
12984 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12985@@ -199,17 +222,61 @@ extern void copy_from_user_overflow(void)
12986 #endif
12987 ;
12988
12989-static inline unsigned long __must_check copy_from_user(void *to,
12990- const void __user *from,
12991- unsigned long n)
12992+/**
12993+ * copy_to_user: - Copy a block of data into user space.
12994+ * @to: Destination address, in user space.
12995+ * @from: Source address, in kernel space.
12996+ * @n: Number of bytes to copy.
12997+ *
12998+ * Context: User context only. This function may sleep.
12999+ *
13000+ * Copy data from kernel space to user space.
13001+ *
13002+ * Returns number of bytes that could not be copied.
13003+ * On success, this will be zero.
13004+ */
13005+static inline unsigned long __must_check
13006+copy_to_user(void __user *to, const void *from, unsigned long n)
13007 {
13008- int sz = __compiletime_object_size(to);
13009+ size_t sz = __compiletime_object_size(from);
13010
13011- if (likely(sz == -1 || sz >= n))
13012- n = _copy_from_user(to, from, n);
13013- else
13014+ if (unlikely(sz != (size_t)-1 && sz < n))
13015+ copy_to_user_overflow();
13016+ else if (access_ok(VERIFY_WRITE, to, n))
13017+ n = __copy_to_user(to, from, n);
13018+ return n;
13019+}
13020+
13021+/**
13022+ * copy_from_user: - Copy a block of data from user space.
13023+ * @to: Destination address, in kernel space.
13024+ * @from: Source address, in user space.
13025+ * @n: Number of bytes to copy.
13026+ *
13027+ * Context: User context only. This function may sleep.
13028+ *
13029+ * Copy data from user space to kernel space.
13030+ *
13031+ * Returns number of bytes that could not be copied.
13032+ * On success, this will be zero.
13033+ *
13034+ * If some data could not be copied, this function will pad the copied
13035+ * data to the requested size using zero bytes.
13036+ */
13037+static inline unsigned long __must_check
13038+copy_from_user(void *to, const void __user *from, unsigned long n)
13039+{
13040+ size_t sz = __compiletime_object_size(to);
13041+
13042+ if (unlikely(sz != (size_t)-1 && sz < n))
13043 copy_from_user_overflow();
13044-
13045+ else if (access_ok(VERIFY_READ, from, n))
13046+ n = __copy_from_user(to, from, n);
13047+ else if ((long)n > 0) {
13048+ if (!__builtin_constant_p(n))
13049+ check_object_size(to, n, false);
13050+ memset(to, 0, n);
13051+ }
13052 return n;
13053 }
13054
13055@@ -230,7 +297,7 @@ static inline unsigned long __must_check copy_from_user(void *to,
13056 #define strlen_user(str) strnlen_user(str, LONG_MAX)
13057
13058 long strnlen_user(const char __user *str, long n);
13059-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13060-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13061+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13062+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13063
13064 #endif /* _ASM_X86_UACCESS_32_H */
13065diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
13066index fcd4b6f..ef04f8f 100644
13067--- a/arch/x86/include/asm/uaccess_64.h
13068+++ b/arch/x86/include/asm/uaccess_64.h
13069@@ -10,6 +10,9 @@
13070 #include <asm/alternative.h>
13071 #include <asm/cpufeature.h>
13072 #include <asm/page.h>
13073+#include <asm/pgtable.h>
13074+
13075+#define set_fs(x) (current_thread_info()->addr_limit = (x))
13076
13077 /*
13078 * Copy To/From Userspace
13079@@ -17,12 +20,14 @@
13080
13081 /* Handles exceptions in both to and from, but doesn't do access_ok */
13082 __must_check unsigned long
13083-copy_user_generic_string(void *to, const void *from, unsigned len);
13084+copy_user_generic_string(void *to, const void *from, unsigned long len) __size_overflow(3);
13085 __must_check unsigned long
13086-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13087+copy_user_generic_unrolled(void *to, const void *from, unsigned long len) __size_overflow(3);
13088
13089 static __always_inline __must_check unsigned long
13090-copy_user_generic(void *to, const void *from, unsigned len)
13091+copy_user_generic(void *to, const void *from, unsigned long len) __size_overflow(3);
13092+static __always_inline __must_check unsigned long
13093+copy_user_generic(void *to, const void *from, unsigned long len)
13094 {
13095 unsigned ret;
13096
13097@@ -32,142 +37,238 @@ copy_user_generic(void *to, const void *from, unsigned len)
13098 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13099 "=d" (len)),
13100 "1" (to), "2" (from), "3" (len)
13101- : "memory", "rcx", "r8", "r9", "r10", "r11");
13102+ : "memory", "rcx", "r8", "r9", "r11");
13103 return ret;
13104 }
13105
13106+static __always_inline __must_check unsigned long
13107+__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13108+static __always_inline __must_check unsigned long
13109+__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13110 __must_check unsigned long
13111-_copy_to_user(void __user *to, const void *from, unsigned len);
13112-__must_check unsigned long
13113-_copy_from_user(void *to, const void __user *from, unsigned len);
13114-__must_check unsigned long
13115-copy_in_user(void __user *to, const void __user *from, unsigned len);
13116+copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13117+
13118+extern void copy_to_user_overflow(void)
13119+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13120+ __compiletime_error("copy_to_user() buffer size is not provably correct")
13121+#else
13122+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
13123+#endif
13124+;
13125+
13126+extern void copy_from_user_overflow(void)
13127+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13128+ __compiletime_error("copy_from_user() buffer size is not provably correct")
13129+#else
13130+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
13131+#endif
13132+;
13133
13134 static inline unsigned long __must_check copy_from_user(void *to,
13135 const void __user *from,
13136 unsigned long n)
13137 {
13138- int sz = __compiletime_object_size(to);
13139-
13140 might_fault();
13141- if (likely(sz == -1 || sz >= n))
13142- n = _copy_from_user(to, from, n);
13143-#ifdef CONFIG_DEBUG_VM
13144- else
13145- WARN(1, "Buffer overflow detected!\n");
13146-#endif
13147+
13148+ if (access_ok(VERIFY_READ, from, n))
13149+ n = __copy_from_user(to, from, n);
13150+ else if (n < INT_MAX) {
13151+ if (!__builtin_constant_p(n))
13152+ check_object_size(to, n, false);
13153+ memset(to, 0, n);
13154+ }
13155 return n;
13156 }
13157
13158 static __always_inline __must_check
13159-int copy_to_user(void __user *dst, const void *src, unsigned size)
13160+int copy_to_user(void __user *dst, const void *src, unsigned long size)
13161 {
13162 might_fault();
13163
13164- return _copy_to_user(dst, src, size);
13165+ if (access_ok(VERIFY_WRITE, dst, size))
13166+ size = __copy_to_user(dst, src, size);
13167+ return size;
13168 }
13169
13170 static __always_inline __must_check
13171-int __copy_from_user(void *dst, const void __user *src, unsigned size)
13172+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13173 {
13174- int ret = 0;
13175+ size_t sz = __compiletime_object_size(dst);
13176+ unsigned ret = 0;
13177
13178 might_fault();
13179- if (!__builtin_constant_p(size))
13180- return copy_user_generic(dst, (__force void *)src, size);
13181+
13182+ if (size > INT_MAX)
13183+ return size;
13184+
13185+#ifdef CONFIG_PAX_MEMORY_UDEREF
13186+ if (!__access_ok(VERIFY_READ, src, size))
13187+ return size;
13188+#endif
13189+
13190+ if (unlikely(sz != (size_t)-1 && sz < size)) {
13191+ copy_from_user_overflow();
13192+ return size;
13193+ }
13194+
13195+ if (!__builtin_constant_p(size)) {
13196+ check_object_size(dst, size, false);
13197+
13198+#ifdef CONFIG_PAX_MEMORY_UDEREF
13199+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13200+ src += PAX_USER_SHADOW_BASE;
13201+#endif
13202+
13203+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13204+ }
13205 switch (size) {
13206- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13207+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13208 ret, "b", "b", "=q", 1);
13209 return ret;
13210- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13211+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13212 ret, "w", "w", "=r", 2);
13213 return ret;
13214- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13215+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13216 ret, "l", "k", "=r", 4);
13217 return ret;
13218- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13219+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13220 ret, "q", "", "=r", 8);
13221 return ret;
13222 case 10:
13223- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13224+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13225 ret, "q", "", "=r", 10);
13226 if (unlikely(ret))
13227 return ret;
13228 __get_user_asm(*(u16 *)(8 + (char *)dst),
13229- (u16 __user *)(8 + (char __user *)src),
13230+ (const u16 __user *)(8 + (const char __user *)src),
13231 ret, "w", "w", "=r", 2);
13232 return ret;
13233 case 16:
13234- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13235+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13236 ret, "q", "", "=r", 16);
13237 if (unlikely(ret))
13238 return ret;
13239 __get_user_asm(*(u64 *)(8 + (char *)dst),
13240- (u64 __user *)(8 + (char __user *)src),
13241+ (const u64 __user *)(8 + (const char __user *)src),
13242 ret, "q", "", "=r", 8);
13243 return ret;
13244 default:
13245- return copy_user_generic(dst, (__force void *)src, size);
13246+
13247+#ifdef CONFIG_PAX_MEMORY_UDEREF
13248+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13249+ src += PAX_USER_SHADOW_BASE;
13250+#endif
13251+
13252+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13253 }
13254 }
13255
13256 static __always_inline __must_check
13257-int __copy_to_user(void __user *dst, const void *src, unsigned size)
13258+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13259 {
13260- int ret = 0;
13261+ size_t sz = __compiletime_object_size(src);
13262+ unsigned ret = 0;
13263
13264 might_fault();
13265- if (!__builtin_constant_p(size))
13266- return copy_user_generic((__force void *)dst, src, size);
13267+
13268+ if (size > INT_MAX)
13269+ return size;
13270+
13271+#ifdef CONFIG_PAX_MEMORY_UDEREF
13272+ if (!__access_ok(VERIFY_WRITE, dst, size))
13273+ return size;
13274+#endif
13275+
13276+ if (unlikely(sz != (size_t)-1 && sz < size)) {
13277+ copy_to_user_overflow();
13278+ return size;
13279+ }
13280+
13281+ if (!__builtin_constant_p(size)) {
13282+ check_object_size(src, size, true);
13283+
13284+#ifdef CONFIG_PAX_MEMORY_UDEREF
13285+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13286+ dst += PAX_USER_SHADOW_BASE;
13287+#endif
13288+
13289+ return copy_user_generic((__force_kernel void *)dst, src, size);
13290+ }
13291 switch (size) {
13292- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13293+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13294 ret, "b", "b", "iq", 1);
13295 return ret;
13296- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13297+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13298 ret, "w", "w", "ir", 2);
13299 return ret;
13300- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13301+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13302 ret, "l", "k", "ir", 4);
13303 return ret;
13304- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13305+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13306 ret, "q", "", "er", 8);
13307 return ret;
13308 case 10:
13309- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13310+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13311 ret, "q", "", "er", 10);
13312 if (unlikely(ret))
13313 return ret;
13314 asm("":::"memory");
13315- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13316+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13317 ret, "w", "w", "ir", 2);
13318 return ret;
13319 case 16:
13320- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13321+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13322 ret, "q", "", "er", 16);
13323 if (unlikely(ret))
13324 return ret;
13325 asm("":::"memory");
13326- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13327+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13328 ret, "q", "", "er", 8);
13329 return ret;
13330 default:
13331- return copy_user_generic((__force void *)dst, src, size);
13332+
13333+#ifdef CONFIG_PAX_MEMORY_UDEREF
13334+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13335+ dst += PAX_USER_SHADOW_BASE;
13336+#endif
13337+
13338+ return copy_user_generic((__force_kernel void *)dst, src, size);
13339 }
13340 }
13341
13342 static __always_inline __must_check
13343-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13344+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13345 {
13346- int ret = 0;
13347+ unsigned ret = 0;
13348
13349 might_fault();
13350- if (!__builtin_constant_p(size))
13351- return copy_user_generic((__force void *)dst,
13352- (__force void *)src, size);
13353+
13354+ if (size > INT_MAX)
13355+ return size;
13356+
13357+#ifdef CONFIG_PAX_MEMORY_UDEREF
13358+ if (!__access_ok(VERIFY_READ, src, size))
13359+ return size;
13360+ if (!__access_ok(VERIFY_WRITE, dst, size))
13361+ return size;
13362+#endif
13363+
13364+ if (!__builtin_constant_p(size)) {
13365+
13366+#ifdef CONFIG_PAX_MEMORY_UDEREF
13367+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13368+ src += PAX_USER_SHADOW_BASE;
13369+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13370+ dst += PAX_USER_SHADOW_BASE;
13371+#endif
13372+
13373+ return copy_user_generic((__force_kernel void *)dst,
13374+ (__force_kernel const void *)src, size);
13375+ }
13376 switch (size) {
13377 case 1: {
13378 u8 tmp;
13379- __get_user_asm(tmp, (u8 __user *)src,
13380+ __get_user_asm(tmp, (const u8 __user *)src,
13381 ret, "b", "b", "=q", 1);
13382 if (likely(!ret))
13383 __put_user_asm(tmp, (u8 __user *)dst,
13384@@ -176,7 +277,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13385 }
13386 case 2: {
13387 u16 tmp;
13388- __get_user_asm(tmp, (u16 __user *)src,
13389+ __get_user_asm(tmp, (const u16 __user *)src,
13390 ret, "w", "w", "=r", 2);
13391 if (likely(!ret))
13392 __put_user_asm(tmp, (u16 __user *)dst,
13393@@ -186,7 +287,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13394
13395 case 4: {
13396 u32 tmp;
13397- __get_user_asm(tmp, (u32 __user *)src,
13398+ __get_user_asm(tmp, (const u32 __user *)src,
13399 ret, "l", "k", "=r", 4);
13400 if (likely(!ret))
13401 __put_user_asm(tmp, (u32 __user *)dst,
13402@@ -195,7 +296,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13403 }
13404 case 8: {
13405 u64 tmp;
13406- __get_user_asm(tmp, (u64 __user *)src,
13407+ __get_user_asm(tmp, (const u64 __user *)src,
13408 ret, "q", "", "=r", 8);
13409 if (likely(!ret))
13410 __put_user_asm(tmp, (u64 __user *)dst,
13411@@ -203,47 +304,92 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13412 return ret;
13413 }
13414 default:
13415- return copy_user_generic((__force void *)dst,
13416- (__force void *)src, size);
13417+
13418+#ifdef CONFIG_PAX_MEMORY_UDEREF
13419+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13420+ src += PAX_USER_SHADOW_BASE;
13421+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13422+ dst += PAX_USER_SHADOW_BASE;
13423+#endif
13424+
13425+ return copy_user_generic((__force_kernel void *)dst,
13426+ (__force_kernel const void *)src, size);
13427 }
13428 }
13429
13430 __must_check long strnlen_user(const char __user *str, long n);
13431 __must_check long __strnlen_user(const char __user *str, long n);
13432 __must_check long strlen_user(const char __user *str);
13433-__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13434-__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13435+__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13436+__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13437
13438 static __must_check __always_inline int
13439-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13440+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13441 {
13442- return copy_user_generic(dst, (__force const void *)src, size);
13443+ if (size > INT_MAX)
13444+ return size;
13445+
13446+#ifdef CONFIG_PAX_MEMORY_UDEREF
13447+ if (!__access_ok(VERIFY_READ, src, size))
13448+ return size;
13449+
13450+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13451+ src += PAX_USER_SHADOW_BASE;
13452+#endif
13453+
13454+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13455 }
13456
13457-static __must_check __always_inline int
13458-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13459+static __must_check __always_inline unsigned long
13460+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13461 {
13462- return copy_user_generic((__force void *)dst, src, size);
13463+ if (size > INT_MAX)
13464+ return size;
13465+
13466+#ifdef CONFIG_PAX_MEMORY_UDEREF
13467+ if (!__access_ok(VERIFY_WRITE, dst, size))
13468+ return size;
13469+
13470+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13471+ dst += PAX_USER_SHADOW_BASE;
13472+#endif
13473+
13474+ return copy_user_generic((__force_kernel void *)dst, src, size);
13475 }
13476
13477-extern long __copy_user_nocache(void *dst, const void __user *src,
13478- unsigned size, int zerorest);
13479+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13480+ unsigned long size, int zerorest) __size_overflow(3);
13481
13482-static inline int
13483-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13484+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13485 {
13486 might_sleep();
13487+
13488+ if (size > INT_MAX)
13489+ return size;
13490+
13491+#ifdef CONFIG_PAX_MEMORY_UDEREF
13492+ if (!__access_ok(VERIFY_READ, src, size))
13493+ return size;
13494+#endif
13495+
13496 return __copy_user_nocache(dst, src, size, 1);
13497 }
13498
13499-static inline int
13500-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13501- unsigned size)
13502+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13503+ unsigned long size)
13504 {
13505+ if (size > INT_MAX)
13506+ return size;
13507+
13508+#ifdef CONFIG_PAX_MEMORY_UDEREF
13509+ if (!__access_ok(VERIFY_READ, src, size))
13510+ return size;
13511+#endif
13512+
13513 return __copy_user_nocache(dst, src, size, 0);
13514 }
13515
13516-unsigned long
13517-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13518+extern unsigned long
13519+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13520
13521 #endif /* _ASM_X86_UACCESS_64_H */
13522diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13523index bb05228..d763d5b 100644
13524--- a/arch/x86/include/asm/vdso.h
13525+++ b/arch/x86/include/asm/vdso.h
13526@@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13527 #define VDSO32_SYMBOL(base, name) \
13528 ({ \
13529 extern const char VDSO32_##name[]; \
13530- (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13531+ (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13532 })
13533 #endif
13534
13535diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13536index 764b66a..ad3cfc8 100644
13537--- a/arch/x86/include/asm/x86_init.h
13538+++ b/arch/x86/include/asm/x86_init.h
13539@@ -29,7 +29,7 @@ struct x86_init_mpparse {
13540 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13541 void (*find_smp_config)(void);
13542 void (*get_smp_config)(unsigned int early);
13543-};
13544+} __no_const;
13545
13546 /**
13547 * struct x86_init_resources - platform specific resource related ops
13548@@ -43,7 +43,7 @@ struct x86_init_resources {
13549 void (*probe_roms)(void);
13550 void (*reserve_resources)(void);
13551 char *(*memory_setup)(void);
13552-};
13553+} __no_const;
13554
13555 /**
13556 * struct x86_init_irqs - platform specific interrupt setup
13557@@ -56,7 +56,7 @@ struct x86_init_irqs {
13558 void (*pre_vector_init)(void);
13559 void (*intr_init)(void);
13560 void (*trap_init)(void);
13561-};
13562+} __no_const;
13563
13564 /**
13565 * struct x86_init_oem - oem platform specific customizing functions
13566@@ -66,7 +66,7 @@ struct x86_init_irqs {
13567 struct x86_init_oem {
13568 void (*arch_setup)(void);
13569 void (*banner)(void);
13570-};
13571+} __no_const;
13572
13573 /**
13574 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13575@@ -77,7 +77,7 @@ struct x86_init_oem {
13576 */
13577 struct x86_init_mapping {
13578 void (*pagetable_reserve)(u64 start, u64 end);
13579-};
13580+} __no_const;
13581
13582 /**
13583 * struct x86_init_paging - platform specific paging functions
13584@@ -87,7 +87,7 @@ struct x86_init_mapping {
13585 struct x86_init_paging {
13586 void (*pagetable_setup_start)(pgd_t *base);
13587 void (*pagetable_setup_done)(pgd_t *base);
13588-};
13589+} __no_const;
13590
13591 /**
13592 * struct x86_init_timers - platform specific timer setup
13593@@ -102,7 +102,7 @@ struct x86_init_timers {
13594 void (*tsc_pre_init)(void);
13595 void (*timer_init)(void);
13596 void (*wallclock_init)(void);
13597-};
13598+} __no_const;
13599
13600 /**
13601 * struct x86_init_iommu - platform specific iommu setup
13602@@ -110,7 +110,7 @@ struct x86_init_timers {
13603 */
13604 struct x86_init_iommu {
13605 int (*iommu_init)(void);
13606-};
13607+} __no_const;
13608
13609 /**
13610 * struct x86_init_pci - platform specific pci init functions
13611@@ -124,7 +124,7 @@ struct x86_init_pci {
13612 int (*init)(void);
13613 void (*init_irq)(void);
13614 void (*fixup_irqs)(void);
13615-};
13616+} __no_const;
13617
13618 /**
13619 * struct x86_init_ops - functions for platform specific setup
13620@@ -140,7 +140,7 @@ struct x86_init_ops {
13621 struct x86_init_timers timers;
13622 struct x86_init_iommu iommu;
13623 struct x86_init_pci pci;
13624-};
13625+} __no_const;
13626
13627 /**
13628 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13629@@ -151,7 +151,7 @@ struct x86_cpuinit_ops {
13630 void (*setup_percpu_clockev)(void);
13631 void (*early_percpu_clock_init)(void);
13632 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13633-};
13634+} __no_const;
13635
13636 /**
13637 * struct x86_platform_ops - platform specific runtime functions
13638@@ -177,7 +177,7 @@ struct x86_platform_ops {
13639 int (*i8042_detect)(void);
13640 void (*save_sched_clock_state)(void);
13641 void (*restore_sched_clock_state)(void);
13642-};
13643+} __no_const;
13644
13645 struct pci_dev;
13646
13647@@ -186,7 +186,7 @@ struct x86_msi_ops {
13648 void (*teardown_msi_irq)(unsigned int irq);
13649 void (*teardown_msi_irqs)(struct pci_dev *dev);
13650 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13651-};
13652+} __no_const;
13653
13654 extern struct x86_init_ops x86_init;
13655 extern struct x86_cpuinit_ops x86_cpuinit;
13656diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13657index c6ce245..ffbdab7 100644
13658--- a/arch/x86/include/asm/xsave.h
13659+++ b/arch/x86/include/asm/xsave.h
13660@@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13661 {
13662 int err;
13663
13664+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13665+ if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13666+ buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13667+#endif
13668+
13669 /*
13670 * Clear the xsave header first, so that reserved fields are
13671 * initialized to zero.
13672@@ -96,10 +101,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13673 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13674 {
13675 int err;
13676- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13677+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13678 u32 lmask = mask;
13679 u32 hmask = mask >> 32;
13680
13681+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13682+ if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13683+ xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13684+#endif
13685+
13686 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13687 "2:\n"
13688 ".section .fixup,\"ax\"\n"
13689diff --git a/arch/x86/kernel/acpi/realmode/Makefile b/arch/x86/kernel/acpi/realmode/Makefile
13690index 6a564ac..9b1340c 100644
13691--- a/arch/x86/kernel/acpi/realmode/Makefile
13692+++ b/arch/x86/kernel/acpi/realmode/Makefile
13693@@ -41,6 +41,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D_WAKEUP -D__KERNEL__ \
13694 $(call cc-option, -fno-stack-protector) \
13695 $(call cc-option, -mpreferred-stack-boundary=2)
13696 KBUILD_CFLAGS += $(call cc-option, -m32)
13697+ifdef CONSTIFY_PLUGIN
13698+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
13699+endif
13700 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13701 GCOV_PROFILE := n
13702
13703diff --git a/arch/x86/kernel/acpi/realmode/wakeup.S b/arch/x86/kernel/acpi/realmode/wakeup.S
13704index b4fd836..4358fe3 100644
13705--- a/arch/x86/kernel/acpi/realmode/wakeup.S
13706+++ b/arch/x86/kernel/acpi/realmode/wakeup.S
13707@@ -108,6 +108,9 @@ wakeup_code:
13708 /* Do any other stuff... */
13709
13710 #ifndef CONFIG_64BIT
13711+ /* Recheck NX bit overrides (64bit path does this in trampoline */
13712+ call verify_cpu
13713+
13714 /* This could also be done in C code... */
13715 movl pmode_cr3, %eax
13716 movl %eax, %cr3
13717@@ -131,6 +134,7 @@ wakeup_code:
13718 movl pmode_cr0, %eax
13719 movl %eax, %cr0
13720 jmp pmode_return
13721+# include "../../verify_cpu.S"
13722 #else
13723 pushw $0
13724 pushw trampoline_segment
13725diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13726index 146a49c..1b5338b 100644
13727--- a/arch/x86/kernel/acpi/sleep.c
13728+++ b/arch/x86/kernel/acpi/sleep.c
13729@@ -98,8 +98,12 @@ int acpi_suspend_lowlevel(void)
13730 header->trampoline_segment = trampoline_address() >> 4;
13731 #ifdef CONFIG_SMP
13732 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13733+
13734+ pax_open_kernel();
13735 early_gdt_descr.address =
13736 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13737+ pax_close_kernel();
13738+
13739 initial_gs = per_cpu_offset(smp_processor_id());
13740 #endif
13741 initial_code = (unsigned long)wakeup_long64;
13742diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13743index 7261083..5c12053 100644
13744--- a/arch/x86/kernel/acpi/wakeup_32.S
13745+++ b/arch/x86/kernel/acpi/wakeup_32.S
13746@@ -30,13 +30,11 @@ wakeup_pmode_return:
13747 # and restore the stack ... but you need gdt for this to work
13748 movl saved_context_esp, %esp
13749
13750- movl %cs:saved_magic, %eax
13751- cmpl $0x12345678, %eax
13752+ cmpl $0x12345678, saved_magic
13753 jne bogus_magic
13754
13755 # jump to place where we left off
13756- movl saved_eip, %eax
13757- jmp *%eax
13758+ jmp *(saved_eip)
13759
13760 bogus_magic:
13761 jmp bogus_magic
13762diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13763index 1f84794..e23f862 100644
13764--- a/arch/x86/kernel/alternative.c
13765+++ b/arch/x86/kernel/alternative.c
13766@@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13767 */
13768 for (a = start; a < end; a++) {
13769 instr = (u8 *)&a->instr_offset + a->instr_offset;
13770+
13771+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13772+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13773+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13774+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13775+#endif
13776+
13777 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13778 BUG_ON(a->replacementlen > a->instrlen);
13779 BUG_ON(a->instrlen > sizeof(insnbuf));
13780@@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13781 for (poff = start; poff < end; poff++) {
13782 u8 *ptr = (u8 *)poff + *poff;
13783
13784+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13785+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13786+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13787+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13788+#endif
13789+
13790 if (!*poff || ptr < text || ptr >= text_end)
13791 continue;
13792 /* turn DS segment override prefix into lock prefix */
13793- if (*ptr == 0x3e)
13794+ if (*ktla_ktva(ptr) == 0x3e)
13795 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13796 };
13797 mutex_unlock(&text_mutex);
13798@@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13799 for (poff = start; poff < end; poff++) {
13800 u8 *ptr = (u8 *)poff + *poff;
13801
13802+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13803+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13804+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13805+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13806+#endif
13807+
13808 if (!*poff || ptr < text || ptr >= text_end)
13809 continue;
13810 /* turn lock prefix into DS segment override prefix */
13811- if (*ptr == 0xf0)
13812+ if (*ktla_ktva(ptr) == 0xf0)
13813 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13814 };
13815 mutex_unlock(&text_mutex);
13816@@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13817
13818 BUG_ON(p->len > MAX_PATCH_LEN);
13819 /* prep the buffer with the original instructions */
13820- memcpy(insnbuf, p->instr, p->len);
13821+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13822 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13823 (unsigned long)p->instr, p->len);
13824
13825@@ -568,7 +587,7 @@ void __init alternative_instructions(void)
13826 if (smp_alt_once)
13827 free_init_pages("SMP alternatives",
13828 (unsigned long)__smp_locks,
13829- (unsigned long)__smp_locks_end);
13830+ PAGE_ALIGN((unsigned long)__smp_locks_end));
13831
13832 restart_nmi();
13833 }
13834@@ -585,13 +604,17 @@ void __init alternative_instructions(void)
13835 * instructions. And on the local CPU you need to be protected again NMI or MCE
13836 * handlers seeing an inconsistent instruction while you patch.
13837 */
13838-void *__init_or_module text_poke_early(void *addr, const void *opcode,
13839+void *__kprobes text_poke_early(void *addr, const void *opcode,
13840 size_t len)
13841 {
13842 unsigned long flags;
13843 local_irq_save(flags);
13844- memcpy(addr, opcode, len);
13845+
13846+ pax_open_kernel();
13847+ memcpy(ktla_ktva(addr), opcode, len);
13848 sync_core();
13849+ pax_close_kernel();
13850+
13851 local_irq_restore(flags);
13852 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13853 that causes hangs on some VIA CPUs. */
13854@@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13855 */
13856 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13857 {
13858- unsigned long flags;
13859- char *vaddr;
13860+ unsigned char *vaddr = ktla_ktva(addr);
13861 struct page *pages[2];
13862- int i;
13863+ size_t i;
13864
13865 if (!core_kernel_text((unsigned long)addr)) {
13866- pages[0] = vmalloc_to_page(addr);
13867- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13868+ pages[0] = vmalloc_to_page(vaddr);
13869+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13870 } else {
13871- pages[0] = virt_to_page(addr);
13872+ pages[0] = virt_to_page(vaddr);
13873 WARN_ON(!PageReserved(pages[0]));
13874- pages[1] = virt_to_page(addr + PAGE_SIZE);
13875+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13876 }
13877 BUG_ON(!pages[0]);
13878- local_irq_save(flags);
13879- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13880- if (pages[1])
13881- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13882- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13883- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13884- clear_fixmap(FIX_TEXT_POKE0);
13885- if (pages[1])
13886- clear_fixmap(FIX_TEXT_POKE1);
13887- local_flush_tlb();
13888- sync_core();
13889- /* Could also do a CLFLUSH here to speed up CPU recovery; but
13890- that causes hangs on some VIA CPUs. */
13891+ text_poke_early(addr, opcode, len);
13892 for (i = 0; i < len; i++)
13893- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13894- local_irq_restore(flags);
13895+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13896 return addr;
13897 }
13898
13899diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13900index edc2448..553e7c5 100644
13901--- a/arch/x86/kernel/apic/apic.c
13902+++ b/arch/x86/kernel/apic/apic.c
13903@@ -184,7 +184,7 @@ int first_system_vector = 0xfe;
13904 /*
13905 * Debug level, exported for io_apic.c
13906 */
13907-unsigned int apic_verbosity;
13908+int apic_verbosity;
13909
13910 int pic_mode;
13911
13912@@ -1917,7 +1917,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13913 apic_write(APIC_ESR, 0);
13914 v1 = apic_read(APIC_ESR);
13915 ack_APIC_irq();
13916- atomic_inc(&irq_err_count);
13917+ atomic_inc_unchecked(&irq_err_count);
13918
13919 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13920 smp_processor_id(), v0 , v1);
13921diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13922index e88300d..cd5a87a 100644
13923--- a/arch/x86/kernel/apic/io_apic.c
13924+++ b/arch/x86/kernel/apic/io_apic.c
13925@@ -83,7 +83,9 @@ static struct io_apic_ops io_apic_ops = {
13926
13927 void __init set_io_apic_ops(const struct io_apic_ops *ops)
13928 {
13929- io_apic_ops = *ops;
13930+ pax_open_kernel();
13931+ memcpy((void*)&io_apic_ops, ops, sizeof io_apic_ops);
13932+ pax_close_kernel();
13933 }
13934
13935 /*
13936@@ -1135,7 +1137,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13937 }
13938 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13939
13940-void lock_vector_lock(void)
13941+void lock_vector_lock(void) __acquires(vector_lock)
13942 {
13943 /* Used to the online set of cpus does not change
13944 * during assign_irq_vector.
13945@@ -1143,7 +1145,7 @@ void lock_vector_lock(void)
13946 raw_spin_lock(&vector_lock);
13947 }
13948
13949-void unlock_vector_lock(void)
13950+void unlock_vector_lock(void) __releases(vector_lock)
13951 {
13952 raw_spin_unlock(&vector_lock);
13953 }
13954@@ -2549,7 +2551,7 @@ static void ack_apic_edge(struct irq_data *data)
13955 ack_APIC_irq();
13956 }
13957
13958-atomic_t irq_mis_count;
13959+atomic_unchecked_t irq_mis_count;
13960
13961 #ifdef CONFIG_GENERIC_PENDING_IRQ
13962 static inline bool ioapic_irqd_mask(struct irq_data *data, struct irq_cfg *cfg)
13963@@ -2667,7 +2669,7 @@ static void ack_apic_level(struct irq_data *data)
13964 * at the cpu.
13965 */
13966 if (!(v & (1 << (i & 0x1f)))) {
13967- atomic_inc(&irq_mis_count);
13968+ atomic_inc_unchecked(&irq_mis_count);
13969
13970 eoi_ioapic_irq(irq, cfg);
13971 }
13972diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13973index 459e78c..f037006 100644
13974--- a/arch/x86/kernel/apm_32.c
13975+++ b/arch/x86/kernel/apm_32.c
13976@@ -410,7 +410,7 @@ static DEFINE_MUTEX(apm_mutex);
13977 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13978 * even though they are called in protected mode.
13979 */
13980-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13981+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13982 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13983
13984 static const char driver_version[] = "1.16ac"; /* no spaces */
13985@@ -588,7 +588,10 @@ static long __apm_bios_call(void *_call)
13986 BUG_ON(cpu != 0);
13987 gdt = get_cpu_gdt_table(cpu);
13988 save_desc_40 = gdt[0x40 / 8];
13989+
13990+ pax_open_kernel();
13991 gdt[0x40 / 8] = bad_bios_desc;
13992+ pax_close_kernel();
13993
13994 apm_irq_save(flags);
13995 APM_DO_SAVE_SEGS;
13996@@ -597,7 +600,11 @@ static long __apm_bios_call(void *_call)
13997 &call->esi);
13998 APM_DO_RESTORE_SEGS;
13999 apm_irq_restore(flags);
14000+
14001+ pax_open_kernel();
14002 gdt[0x40 / 8] = save_desc_40;
14003+ pax_close_kernel();
14004+
14005 put_cpu();
14006
14007 return call->eax & 0xff;
14008@@ -664,7 +671,10 @@ static long __apm_bios_call_simple(void *_call)
14009 BUG_ON(cpu != 0);
14010 gdt = get_cpu_gdt_table(cpu);
14011 save_desc_40 = gdt[0x40 / 8];
14012+
14013+ pax_open_kernel();
14014 gdt[0x40 / 8] = bad_bios_desc;
14015+ pax_close_kernel();
14016
14017 apm_irq_save(flags);
14018 APM_DO_SAVE_SEGS;
14019@@ -672,7 +682,11 @@ static long __apm_bios_call_simple(void *_call)
14020 &call->eax);
14021 APM_DO_RESTORE_SEGS;
14022 apm_irq_restore(flags);
14023+
14024+ pax_open_kernel();
14025 gdt[0x40 / 8] = save_desc_40;
14026+ pax_close_kernel();
14027+
14028 put_cpu();
14029 return error;
14030 }
14031@@ -2345,12 +2359,15 @@ static int __init apm_init(void)
14032 * code to that CPU.
14033 */
14034 gdt = get_cpu_gdt_table(0);
14035+
14036+ pax_open_kernel();
14037 set_desc_base(&gdt[APM_CS >> 3],
14038 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
14039 set_desc_base(&gdt[APM_CS_16 >> 3],
14040 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
14041 set_desc_base(&gdt[APM_DS >> 3],
14042 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
14043+ pax_close_kernel();
14044
14045 proc_create("apm", 0, NULL, &apm_file_ops);
14046
14047diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
14048index 68de2dc..1f3c720 100644
14049--- a/arch/x86/kernel/asm-offsets.c
14050+++ b/arch/x86/kernel/asm-offsets.c
14051@@ -33,6 +33,8 @@ void common(void) {
14052 OFFSET(TI_status, thread_info, status);
14053 OFFSET(TI_addr_limit, thread_info, addr_limit);
14054 OFFSET(TI_preempt_count, thread_info, preempt_count);
14055+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
14056+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
14057
14058 BLANK();
14059 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
14060@@ -53,8 +55,26 @@ void common(void) {
14061 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
14062 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
14063 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
14064+
14065+#ifdef CONFIG_PAX_KERNEXEC
14066+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
14067 #endif
14068
14069+#ifdef CONFIG_PAX_MEMORY_UDEREF
14070+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
14071+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
14072+#ifdef CONFIG_X86_64
14073+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
14074+#endif
14075+#endif
14076+
14077+#endif
14078+
14079+ BLANK();
14080+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
14081+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
14082+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
14083+
14084 #ifdef CONFIG_XEN
14085 BLANK();
14086 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14087diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14088index 1b4754f..fbb4227 100644
14089--- a/arch/x86/kernel/asm-offsets_64.c
14090+++ b/arch/x86/kernel/asm-offsets_64.c
14091@@ -76,6 +76,7 @@ int main(void)
14092 BLANK();
14093 #undef ENTRY
14094
14095+ DEFINE(TSS_size, sizeof(struct tss_struct));
14096 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14097 BLANK();
14098
14099diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14100index 6ab6aa2..8f71507 100644
14101--- a/arch/x86/kernel/cpu/Makefile
14102+++ b/arch/x86/kernel/cpu/Makefile
14103@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14104 CFLAGS_REMOVE_perf_event.o = -pg
14105 endif
14106
14107-# Make sure load_percpu_segment has no stackprotector
14108-nostackp := $(call cc-option, -fno-stack-protector)
14109-CFLAGS_common.o := $(nostackp)
14110-
14111 obj-y := intel_cacheinfo.o scattered.o topology.o
14112 obj-y += proc.o capflags.o powerflags.o common.o
14113 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
14114diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14115index 146bb62..ac9c74a 100644
14116--- a/arch/x86/kernel/cpu/amd.c
14117+++ b/arch/x86/kernel/cpu/amd.c
14118@@ -691,7 +691,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14119 unsigned int size)
14120 {
14121 /* AMD errata T13 (order #21922) */
14122- if ((c->x86 == 6)) {
14123+ if (c->x86 == 6) {
14124 /* Duron Rev A0 */
14125 if (c->x86_model == 3 && c->x86_mask == 0)
14126 size = 64;
14127diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14128index cf79302..b1b28ae 100644
14129--- a/arch/x86/kernel/cpu/common.c
14130+++ b/arch/x86/kernel/cpu/common.c
14131@@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14132
14133 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14134
14135-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14136-#ifdef CONFIG_X86_64
14137- /*
14138- * We need valid kernel segments for data and code in long mode too
14139- * IRET will check the segment types kkeil 2000/10/28
14140- * Also sysret mandates a special GDT layout
14141- *
14142- * TLS descriptors are currently at a different place compared to i386.
14143- * Hopefully nobody expects them at a fixed place (Wine?)
14144- */
14145- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14146- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14147- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14148- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14149- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14150- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14151-#else
14152- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14153- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14154- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14155- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14156- /*
14157- * Segments used for calling PnP BIOS have byte granularity.
14158- * They code segments and data segments have fixed 64k limits,
14159- * the transfer segment sizes are set at run time.
14160- */
14161- /* 32-bit code */
14162- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14163- /* 16-bit code */
14164- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14165- /* 16-bit data */
14166- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14167- /* 16-bit data */
14168- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14169- /* 16-bit data */
14170- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14171- /*
14172- * The APM segments have byte granularity and their bases
14173- * are set at run time. All have 64k limits.
14174- */
14175- /* 32-bit code */
14176- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14177- /* 16-bit code */
14178- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14179- /* data */
14180- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14181-
14182- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14183- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14184- GDT_STACK_CANARY_INIT
14185-#endif
14186-} };
14187-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14188-
14189 static int __init x86_xsave_setup(char *s)
14190 {
14191 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14192@@ -374,7 +320,7 @@ void switch_to_new_gdt(int cpu)
14193 {
14194 struct desc_ptr gdt_descr;
14195
14196- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14197+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14198 gdt_descr.size = GDT_SIZE - 1;
14199 load_gdt(&gdt_descr);
14200 /* Reload the per-cpu base */
14201@@ -841,6 +787,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14202 /* Filter out anything that depends on CPUID levels we don't have */
14203 filter_cpuid_features(c, true);
14204
14205+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14206+ setup_clear_cpu_cap(X86_FEATURE_SEP);
14207+#endif
14208+
14209 /* If the model name is still unset, do table lookup. */
14210 if (!c->x86_model_id[0]) {
14211 const char *p;
14212@@ -1021,10 +971,12 @@ static __init int setup_disablecpuid(char *arg)
14213 }
14214 __setup("clearcpuid=", setup_disablecpuid);
14215
14216+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14217+EXPORT_PER_CPU_SYMBOL(current_tinfo);
14218+
14219 #ifdef CONFIG_X86_64
14220 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14221-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14222- (unsigned long) nmi_idt_table };
14223+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14224
14225 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14226 irq_stack_union) __aligned(PAGE_SIZE);
14227@@ -1038,7 +990,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14228 EXPORT_PER_CPU_SYMBOL(current_task);
14229
14230 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14231- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14232+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14233 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14234
14235 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14236@@ -1126,7 +1078,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14237 {
14238 memset(regs, 0, sizeof(struct pt_regs));
14239 regs->fs = __KERNEL_PERCPU;
14240- regs->gs = __KERNEL_STACK_CANARY;
14241+ savesegment(gs, regs->gs);
14242
14243 return regs;
14244 }
14245@@ -1181,7 +1133,7 @@ void __cpuinit cpu_init(void)
14246 int i;
14247
14248 cpu = stack_smp_processor_id();
14249- t = &per_cpu(init_tss, cpu);
14250+ t = init_tss + cpu;
14251 oist = &per_cpu(orig_ist, cpu);
14252
14253 #ifdef CONFIG_NUMA
14254@@ -1207,7 +1159,7 @@ void __cpuinit cpu_init(void)
14255 switch_to_new_gdt(cpu);
14256 loadsegment(fs, 0);
14257
14258- load_idt((const struct desc_ptr *)&idt_descr);
14259+ load_idt(&idt_descr);
14260
14261 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14262 syscall_init();
14263@@ -1216,7 +1168,6 @@ void __cpuinit cpu_init(void)
14264 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14265 barrier();
14266
14267- x86_configure_nx();
14268 if (cpu != 0)
14269 enable_x2apic();
14270
14271@@ -1272,7 +1223,7 @@ void __cpuinit cpu_init(void)
14272 {
14273 int cpu = smp_processor_id();
14274 struct task_struct *curr = current;
14275- struct tss_struct *t = &per_cpu(init_tss, cpu);
14276+ struct tss_struct *t = init_tss + cpu;
14277 struct thread_struct *thread = &curr->thread;
14278
14279 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14280diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14281index 3e6ff6c..54b4992 100644
14282--- a/arch/x86/kernel/cpu/intel.c
14283+++ b/arch/x86/kernel/cpu/intel.c
14284@@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14285 * Update the IDT descriptor and reload the IDT so that
14286 * it uses the read-only mapped virtual address.
14287 */
14288- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14289+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14290 load_idt(&idt_descr);
14291 }
14292 #endif
14293diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14294index 61604ae..98250a5 100644
14295--- a/arch/x86/kernel/cpu/mcheck/mce.c
14296+++ b/arch/x86/kernel/cpu/mcheck/mce.c
14297@@ -42,6 +42,7 @@
14298 #include <asm/processor.h>
14299 #include <asm/mce.h>
14300 #include <asm/msr.h>
14301+#include <asm/local.h>
14302
14303 #include "mce-internal.h"
14304
14305@@ -250,7 +251,7 @@ static void print_mce(struct mce *m)
14306 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14307 m->cs, m->ip);
14308
14309- if (m->cs == __KERNEL_CS)
14310+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14311 print_symbol("{%s}", m->ip);
14312 pr_cont("\n");
14313 }
14314@@ -283,10 +284,10 @@ static void print_mce(struct mce *m)
14315
14316 #define PANIC_TIMEOUT 5 /* 5 seconds */
14317
14318-static atomic_t mce_paniced;
14319+static atomic_unchecked_t mce_paniced;
14320
14321 static int fake_panic;
14322-static atomic_t mce_fake_paniced;
14323+static atomic_unchecked_t mce_fake_paniced;
14324
14325 /* Panic in progress. Enable interrupts and wait for final IPI */
14326 static void wait_for_panic(void)
14327@@ -310,7 +311,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14328 /*
14329 * Make sure only one CPU runs in machine check panic
14330 */
14331- if (atomic_inc_return(&mce_paniced) > 1)
14332+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14333 wait_for_panic();
14334 barrier();
14335
14336@@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14337 console_verbose();
14338 } else {
14339 /* Don't log too much for fake panic */
14340- if (atomic_inc_return(&mce_fake_paniced) > 1)
14341+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14342 return;
14343 }
14344 /* First print corrected ones that are still unlogged */
14345@@ -684,7 +685,7 @@ static int mce_timed_out(u64 *t)
14346 * might have been modified by someone else.
14347 */
14348 rmb();
14349- if (atomic_read(&mce_paniced))
14350+ if (atomic_read_unchecked(&mce_paniced))
14351 wait_for_panic();
14352 if (!monarch_timeout)
14353 goto out;
14354@@ -1535,7 +1536,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14355 }
14356
14357 /* Call the installed machine check handler for this CPU setup. */
14358-void (*machine_check_vector)(struct pt_regs *, long error_code) =
14359+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14360 unexpected_machine_check;
14361
14362 /*
14363@@ -1558,7 +1559,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14364 return;
14365 }
14366
14367+ pax_open_kernel();
14368 machine_check_vector = do_machine_check;
14369+ pax_close_kernel();
14370
14371 __mcheck_cpu_init_generic();
14372 __mcheck_cpu_init_vendor(c);
14373@@ -1572,7 +1575,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14374 */
14375
14376 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14377-static int mce_chrdev_open_count; /* #times opened */
14378+static local_t mce_chrdev_open_count; /* #times opened */
14379 static int mce_chrdev_open_exclu; /* already open exclusive? */
14380
14381 static int mce_chrdev_open(struct inode *inode, struct file *file)
14382@@ -1580,7 +1583,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14383 spin_lock(&mce_chrdev_state_lock);
14384
14385 if (mce_chrdev_open_exclu ||
14386- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14387+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14388 spin_unlock(&mce_chrdev_state_lock);
14389
14390 return -EBUSY;
14391@@ -1588,7 +1591,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14392
14393 if (file->f_flags & O_EXCL)
14394 mce_chrdev_open_exclu = 1;
14395- mce_chrdev_open_count++;
14396+ local_inc(&mce_chrdev_open_count);
14397
14398 spin_unlock(&mce_chrdev_state_lock);
14399
14400@@ -1599,7 +1602,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14401 {
14402 spin_lock(&mce_chrdev_state_lock);
14403
14404- mce_chrdev_open_count--;
14405+ local_dec(&mce_chrdev_open_count);
14406 mce_chrdev_open_exclu = 0;
14407
14408 spin_unlock(&mce_chrdev_state_lock);
14409@@ -2324,7 +2327,7 @@ struct dentry *mce_get_debugfs_dir(void)
14410 static void mce_reset(void)
14411 {
14412 cpu_missing = 0;
14413- atomic_set(&mce_fake_paniced, 0);
14414+ atomic_set_unchecked(&mce_fake_paniced, 0);
14415 atomic_set(&mce_executing, 0);
14416 atomic_set(&mce_callin, 0);
14417 atomic_set(&global_nwo, 0);
14418diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14419index 2d5454c..51987eb 100644
14420--- a/arch/x86/kernel/cpu/mcheck/p5.c
14421+++ b/arch/x86/kernel/cpu/mcheck/p5.c
14422@@ -11,6 +11,7 @@
14423 #include <asm/processor.h>
14424 #include <asm/mce.h>
14425 #include <asm/msr.h>
14426+#include <asm/pgtable.h>
14427
14428 /* By default disabled */
14429 int mce_p5_enabled __read_mostly;
14430@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14431 if (!cpu_has(c, X86_FEATURE_MCE))
14432 return;
14433
14434+ pax_open_kernel();
14435 machine_check_vector = pentium_machine_check;
14436+ pax_close_kernel();
14437 /* Make sure the vector pointer is visible before we enable MCEs: */
14438 wmb();
14439
14440diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14441index 2d7998f..17c9de1 100644
14442--- a/arch/x86/kernel/cpu/mcheck/winchip.c
14443+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14444@@ -10,6 +10,7 @@
14445 #include <asm/processor.h>
14446 #include <asm/mce.h>
14447 #include <asm/msr.h>
14448+#include <asm/pgtable.h>
14449
14450 /* Machine check handler for WinChip C6: */
14451 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14452@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14453 {
14454 u32 lo, hi;
14455
14456+ pax_open_kernel();
14457 machine_check_vector = winchip_machine_check;
14458+ pax_close_kernel();
14459 /* Make sure the vector pointer is visible before we enable MCEs: */
14460 wmb();
14461
14462diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14463index 6b96110..0da73eb 100644
14464--- a/arch/x86/kernel/cpu/mtrr/main.c
14465+++ b/arch/x86/kernel/cpu/mtrr/main.c
14466@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14467 u64 size_or_mask, size_and_mask;
14468 static bool mtrr_aps_delayed_init;
14469
14470-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14471+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14472
14473 const struct mtrr_ops *mtrr_if;
14474
14475diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14476index df5e41f..816c719 100644
14477--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14478+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14479@@ -25,7 +25,7 @@ struct mtrr_ops {
14480 int (*validate_add_page)(unsigned long base, unsigned long size,
14481 unsigned int type);
14482 int (*have_wrcomb)(void);
14483-};
14484+} __do_const;
14485
14486 extern int generic_get_free_region(unsigned long base, unsigned long size,
14487 int replace_reg);
14488diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14489index bb8e034..fb9020b 100644
14490--- a/arch/x86/kernel/cpu/perf_event.c
14491+++ b/arch/x86/kernel/cpu/perf_event.c
14492@@ -1835,7 +1835,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14493 break;
14494
14495 perf_callchain_store(entry, frame.return_address);
14496- fp = frame.next_frame;
14497+ fp = (const void __force_user *)frame.next_frame;
14498 }
14499 }
14500
14501diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14502index 13ad899..f642b9a 100644
14503--- a/arch/x86/kernel/crash.c
14504+++ b/arch/x86/kernel/crash.c
14505@@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14506 {
14507 #ifdef CONFIG_X86_32
14508 struct pt_regs fixed_regs;
14509-#endif
14510
14511-#ifdef CONFIG_X86_32
14512- if (!user_mode_vm(regs)) {
14513+ if (!user_mode(regs)) {
14514 crash_fixup_ss_esp(&fixed_regs, regs);
14515 regs = &fixed_regs;
14516 }
14517diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14518index 37250fe..bf2ec74 100644
14519--- a/arch/x86/kernel/doublefault_32.c
14520+++ b/arch/x86/kernel/doublefault_32.c
14521@@ -11,7 +11,7 @@
14522
14523 #define DOUBLEFAULT_STACKSIZE (1024)
14524 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14525-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14526+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14527
14528 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14529
14530@@ -21,7 +21,7 @@ static void doublefault_fn(void)
14531 unsigned long gdt, tss;
14532
14533 store_gdt(&gdt_desc);
14534- gdt = gdt_desc.address;
14535+ gdt = (unsigned long)gdt_desc.address;
14536
14537 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14538
14539@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14540 /* 0x2 bit is always set */
14541 .flags = X86_EFLAGS_SF | 0x2,
14542 .sp = STACK_START,
14543- .es = __USER_DS,
14544+ .es = __KERNEL_DS,
14545 .cs = __KERNEL_CS,
14546 .ss = __KERNEL_DS,
14547- .ds = __USER_DS,
14548+ .ds = __KERNEL_DS,
14549 .fs = __KERNEL_PERCPU,
14550
14551 .__cr3 = __pa_nodebug(swapper_pg_dir),
14552diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14553index 1b81839..0b4e7b0 100644
14554--- a/arch/x86/kernel/dumpstack.c
14555+++ b/arch/x86/kernel/dumpstack.c
14556@@ -2,6 +2,9 @@
14557 * Copyright (C) 1991, 1992 Linus Torvalds
14558 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14559 */
14560+#ifdef CONFIG_GRKERNSEC_HIDESYM
14561+#define __INCLUDED_BY_HIDESYM 1
14562+#endif
14563 #include <linux/kallsyms.h>
14564 #include <linux/kprobes.h>
14565 #include <linux/uaccess.h>
14566@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14567 static void
14568 print_ftrace_graph_addr(unsigned long addr, void *data,
14569 const struct stacktrace_ops *ops,
14570- struct thread_info *tinfo, int *graph)
14571+ struct task_struct *task, int *graph)
14572 {
14573- struct task_struct *task;
14574 unsigned long ret_addr;
14575 int index;
14576
14577 if (addr != (unsigned long)return_to_handler)
14578 return;
14579
14580- task = tinfo->task;
14581 index = task->curr_ret_stack;
14582
14583 if (!task->ret_stack || index < *graph)
14584@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14585 static inline void
14586 print_ftrace_graph_addr(unsigned long addr, void *data,
14587 const struct stacktrace_ops *ops,
14588- struct thread_info *tinfo, int *graph)
14589+ struct task_struct *task, int *graph)
14590 { }
14591 #endif
14592
14593@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14594 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14595 */
14596
14597-static inline int valid_stack_ptr(struct thread_info *tinfo,
14598- void *p, unsigned int size, void *end)
14599+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14600 {
14601- void *t = tinfo;
14602 if (end) {
14603 if (p < end && p >= (end-THREAD_SIZE))
14604 return 1;
14605@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14606 }
14607
14608 unsigned long
14609-print_context_stack(struct thread_info *tinfo,
14610+print_context_stack(struct task_struct *task, void *stack_start,
14611 unsigned long *stack, unsigned long bp,
14612 const struct stacktrace_ops *ops, void *data,
14613 unsigned long *end, int *graph)
14614 {
14615 struct stack_frame *frame = (struct stack_frame *)bp;
14616
14617- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14618+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14619 unsigned long addr;
14620
14621 addr = *stack;
14622@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14623 } else {
14624 ops->address(data, addr, 0);
14625 }
14626- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14627+ print_ftrace_graph_addr(addr, data, ops, task, graph);
14628 }
14629 stack++;
14630 }
14631@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14632 EXPORT_SYMBOL_GPL(print_context_stack);
14633
14634 unsigned long
14635-print_context_stack_bp(struct thread_info *tinfo,
14636+print_context_stack_bp(struct task_struct *task, void *stack_start,
14637 unsigned long *stack, unsigned long bp,
14638 const struct stacktrace_ops *ops, void *data,
14639 unsigned long *end, int *graph)
14640@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14641 struct stack_frame *frame = (struct stack_frame *)bp;
14642 unsigned long *ret_addr = &frame->return_address;
14643
14644- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14645+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14646 unsigned long addr = *ret_addr;
14647
14648 if (!__kernel_text_address(addr))
14649@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14650 ops->address(data, addr, 1);
14651 frame = frame->next_frame;
14652 ret_addr = &frame->return_address;
14653- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14654+ print_ftrace_graph_addr(addr, data, ops, task, graph);
14655 }
14656
14657 return (unsigned long)frame;
14658@@ -189,7 +188,7 @@ void dump_stack(void)
14659
14660 bp = stack_frame(current, NULL);
14661 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14662- current->pid, current->comm, print_tainted(),
14663+ task_pid_nr(current), current->comm, print_tainted(),
14664 init_utsname()->release,
14665 (int)strcspn(init_utsname()->version, " "),
14666 init_utsname()->version);
14667@@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14668 }
14669 EXPORT_SYMBOL_GPL(oops_begin);
14670
14671+extern void gr_handle_kernel_exploit(void);
14672+
14673 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14674 {
14675 if (regs && kexec_should_crash(current))
14676@@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14677 panic("Fatal exception in interrupt");
14678 if (panic_on_oops)
14679 panic("Fatal exception");
14680- do_exit(signr);
14681+
14682+ gr_handle_kernel_exploit();
14683+
14684+ do_group_exit(signr);
14685 }
14686
14687 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14688@@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14689
14690 show_registers(regs);
14691 #ifdef CONFIG_X86_32
14692- if (user_mode_vm(regs)) {
14693+ if (user_mode(regs)) {
14694 sp = regs->sp;
14695 ss = regs->ss & 0xffff;
14696 } else {
14697@@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14698 unsigned long flags = oops_begin();
14699 int sig = SIGSEGV;
14700
14701- if (!user_mode_vm(regs))
14702+ if (!user_mode(regs))
14703 report_bug(regs->ip, regs);
14704
14705 if (__die(str, regs, err))
14706diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14707index 88ec912..e95e935 100644
14708--- a/arch/x86/kernel/dumpstack_32.c
14709+++ b/arch/x86/kernel/dumpstack_32.c
14710@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14711 bp = stack_frame(task, regs);
14712
14713 for (;;) {
14714- struct thread_info *context;
14715+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14716
14717- context = (struct thread_info *)
14718- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14719- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14720+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14721
14722- stack = (unsigned long *)context->previous_esp;
14723- if (!stack)
14724+ if (stack_start == task_stack_page(task))
14725 break;
14726+ stack = *(unsigned long **)stack_start;
14727 if (ops->stack(data, "IRQ") < 0)
14728 break;
14729 touch_nmi_watchdog();
14730@@ -87,7 +85,7 @@ void show_registers(struct pt_regs *regs)
14731 int i;
14732
14733 print_modules();
14734- __show_regs(regs, !user_mode_vm(regs));
14735+ __show_regs(regs, !user_mode(regs));
14736
14737 printk(KERN_EMERG "Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14738 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14739@@ -96,21 +94,22 @@ void show_registers(struct pt_regs *regs)
14740 * When in-kernel, we also print out the stack and code at the
14741 * time of the fault..
14742 */
14743- if (!user_mode_vm(regs)) {
14744+ if (!user_mode(regs)) {
14745 unsigned int code_prologue = code_bytes * 43 / 64;
14746 unsigned int code_len = code_bytes;
14747 unsigned char c;
14748 u8 *ip;
14749+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14750
14751 printk(KERN_EMERG "Stack:\n");
14752 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14753
14754 printk(KERN_EMERG "Code: ");
14755
14756- ip = (u8 *)regs->ip - code_prologue;
14757+ ip = (u8 *)regs->ip - code_prologue + cs_base;
14758 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14759 /* try starting at IP */
14760- ip = (u8 *)regs->ip;
14761+ ip = (u8 *)regs->ip + cs_base;
14762 code_len = code_len - code_prologue + 1;
14763 }
14764 for (i = 0; i < code_len; i++, ip++) {
14765@@ -119,7 +118,7 @@ void show_registers(struct pt_regs *regs)
14766 printk(KERN_CONT " Bad EIP value.");
14767 break;
14768 }
14769- if (ip == (u8 *)regs->ip)
14770+ if (ip == (u8 *)regs->ip + cs_base)
14771 printk(KERN_CONT "<%02x> ", c);
14772 else
14773 printk(KERN_CONT "%02x ", c);
14774@@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
14775 {
14776 unsigned short ud2;
14777
14778+ ip = ktla_ktva(ip);
14779 if (ip < PAGE_OFFSET)
14780 return 0;
14781 if (probe_kernel_address((unsigned short *)ip, ud2))
14782@@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
14783
14784 return ud2 == 0x0b0f;
14785 }
14786+
14787+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14788+void pax_check_alloca(unsigned long size)
14789+{
14790+ unsigned long sp = (unsigned long)&sp, stack_left;
14791+
14792+ /* all kernel stacks are of the same size */
14793+ stack_left = sp & (THREAD_SIZE - 1);
14794+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14795+}
14796+EXPORT_SYMBOL(pax_check_alloca);
14797+#endif
14798diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14799index 17107bd..9623722 100644
14800--- a/arch/x86/kernel/dumpstack_64.c
14801+++ b/arch/x86/kernel/dumpstack_64.c
14802@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14803 unsigned long *irq_stack_end =
14804 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14805 unsigned used = 0;
14806- struct thread_info *tinfo;
14807 int graph = 0;
14808 unsigned long dummy;
14809+ void *stack_start;
14810
14811 if (!task)
14812 task = current;
14813@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14814 * current stack address. If the stacks consist of nested
14815 * exceptions
14816 */
14817- tinfo = task_thread_info(task);
14818 for (;;) {
14819 char *id;
14820 unsigned long *estack_end;
14821+
14822 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14823 &used, &id);
14824
14825@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14826 if (ops->stack(data, id) < 0)
14827 break;
14828
14829- bp = ops->walk_stack(tinfo, stack, bp, ops,
14830+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14831 data, estack_end, &graph);
14832 ops->stack(data, "<EOE>");
14833 /*
14834@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14835 * second-to-last pointer (index -2 to end) in the
14836 * exception stack:
14837 */
14838+ if ((u16)estack_end[-1] != __KERNEL_DS)
14839+ goto out;
14840 stack = (unsigned long *) estack_end[-2];
14841 continue;
14842 }
14843@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14844 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14845 if (ops->stack(data, "IRQ") < 0)
14846 break;
14847- bp = ops->walk_stack(tinfo, stack, bp,
14848+ bp = ops->walk_stack(task, irq_stack, stack, bp,
14849 ops, data, irq_stack_end, &graph);
14850 /*
14851 * We link to the next stack (which would be
14852@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14853 /*
14854 * This handles the process stack:
14855 */
14856- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14857+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14858+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14859+out:
14860 put_cpu();
14861 }
14862 EXPORT_SYMBOL(dump_trace);
14863@@ -305,3 +309,50 @@ int is_valid_bugaddr(unsigned long ip)
14864
14865 return ud2 == 0x0b0f;
14866 }
14867+
14868+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14869+void pax_check_alloca(unsigned long size)
14870+{
14871+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14872+ unsigned cpu, used;
14873+ char *id;
14874+
14875+ /* check the process stack first */
14876+ stack_start = (unsigned long)task_stack_page(current);
14877+ stack_end = stack_start + THREAD_SIZE;
14878+ if (likely(stack_start <= sp && sp < stack_end)) {
14879+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
14880+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14881+ return;
14882+ }
14883+
14884+ cpu = get_cpu();
14885+
14886+ /* check the irq stacks */
14887+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14888+ stack_start = stack_end - IRQ_STACK_SIZE;
14889+ if (stack_start <= sp && sp < stack_end) {
14890+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14891+ put_cpu();
14892+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14893+ return;
14894+ }
14895+
14896+ /* check the exception stacks */
14897+ used = 0;
14898+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14899+ stack_start = stack_end - EXCEPTION_STKSZ;
14900+ if (stack_end && stack_start <= sp && sp < stack_end) {
14901+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14902+ put_cpu();
14903+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14904+ return;
14905+ }
14906+
14907+ put_cpu();
14908+
14909+ /* unknown stack */
14910+ BUG();
14911+}
14912+EXPORT_SYMBOL(pax_check_alloca);
14913+#endif
14914diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14915index 9b9f18b..9fcaa04 100644
14916--- a/arch/x86/kernel/early_printk.c
14917+++ b/arch/x86/kernel/early_printk.c
14918@@ -7,6 +7,7 @@
14919 #include <linux/pci_regs.h>
14920 #include <linux/pci_ids.h>
14921 #include <linux/errno.h>
14922+#include <linux/sched.h>
14923 #include <asm/io.h>
14924 #include <asm/processor.h>
14925 #include <asm/fcntl.h>
14926diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14927index 7b784f4..db6b628 100644
14928--- a/arch/x86/kernel/entry_32.S
14929+++ b/arch/x86/kernel/entry_32.S
14930@@ -179,13 +179,146 @@
14931 /*CFI_REL_OFFSET gs, PT_GS*/
14932 .endm
14933 .macro SET_KERNEL_GS reg
14934+
14935+#ifdef CONFIG_CC_STACKPROTECTOR
14936 movl $(__KERNEL_STACK_CANARY), \reg
14937+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14938+ movl $(__USER_DS), \reg
14939+#else
14940+ xorl \reg, \reg
14941+#endif
14942+
14943 movl \reg, %gs
14944 .endm
14945
14946 #endif /* CONFIG_X86_32_LAZY_GS */
14947
14948-.macro SAVE_ALL
14949+.macro pax_enter_kernel
14950+#ifdef CONFIG_PAX_KERNEXEC
14951+ call pax_enter_kernel
14952+#endif
14953+.endm
14954+
14955+.macro pax_exit_kernel
14956+#ifdef CONFIG_PAX_KERNEXEC
14957+ call pax_exit_kernel
14958+#endif
14959+.endm
14960+
14961+#ifdef CONFIG_PAX_KERNEXEC
14962+ENTRY(pax_enter_kernel)
14963+#ifdef CONFIG_PARAVIRT
14964+ pushl %eax
14965+ pushl %ecx
14966+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
14967+ mov %eax, %esi
14968+#else
14969+ mov %cr0, %esi
14970+#endif
14971+ bts $16, %esi
14972+ jnc 1f
14973+ mov %cs, %esi
14974+ cmp $__KERNEL_CS, %esi
14975+ jz 3f
14976+ ljmp $__KERNEL_CS, $3f
14977+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
14978+2:
14979+#ifdef CONFIG_PARAVIRT
14980+ mov %esi, %eax
14981+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14982+#else
14983+ mov %esi, %cr0
14984+#endif
14985+3:
14986+#ifdef CONFIG_PARAVIRT
14987+ popl %ecx
14988+ popl %eax
14989+#endif
14990+ ret
14991+ENDPROC(pax_enter_kernel)
14992+
14993+ENTRY(pax_exit_kernel)
14994+#ifdef CONFIG_PARAVIRT
14995+ pushl %eax
14996+ pushl %ecx
14997+#endif
14998+ mov %cs, %esi
14999+ cmp $__KERNEXEC_KERNEL_CS, %esi
15000+ jnz 2f
15001+#ifdef CONFIG_PARAVIRT
15002+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
15003+ mov %eax, %esi
15004+#else
15005+ mov %cr0, %esi
15006+#endif
15007+ btr $16, %esi
15008+ ljmp $__KERNEL_CS, $1f
15009+1:
15010+#ifdef CONFIG_PARAVIRT
15011+ mov %esi, %eax
15012+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
15013+#else
15014+ mov %esi, %cr0
15015+#endif
15016+2:
15017+#ifdef CONFIG_PARAVIRT
15018+ popl %ecx
15019+ popl %eax
15020+#endif
15021+ ret
15022+ENDPROC(pax_exit_kernel)
15023+#endif
15024+
15025+.macro pax_erase_kstack
15026+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15027+ call pax_erase_kstack
15028+#endif
15029+.endm
15030+
15031+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15032+/*
15033+ * ebp: thread_info
15034+ * ecx, edx: can be clobbered
15035+ */
15036+ENTRY(pax_erase_kstack)
15037+ pushl %edi
15038+ pushl %eax
15039+
15040+ mov TI_lowest_stack(%ebp), %edi
15041+ mov $-0xBEEF, %eax
15042+ std
15043+
15044+1: mov %edi, %ecx
15045+ and $THREAD_SIZE_asm - 1, %ecx
15046+ shr $2, %ecx
15047+ repne scasl
15048+ jecxz 2f
15049+
15050+ cmp $2*16, %ecx
15051+ jc 2f
15052+
15053+ mov $2*16, %ecx
15054+ repe scasl
15055+ jecxz 2f
15056+ jne 1b
15057+
15058+2: cld
15059+ mov %esp, %ecx
15060+ sub %edi, %ecx
15061+ shr $2, %ecx
15062+ rep stosl
15063+
15064+ mov TI_task_thread_sp0(%ebp), %edi
15065+ sub $128, %edi
15066+ mov %edi, TI_lowest_stack(%ebp)
15067+
15068+ popl %eax
15069+ popl %edi
15070+ ret
15071+ENDPROC(pax_erase_kstack)
15072+#endif
15073+
15074+.macro __SAVE_ALL _DS
15075 cld
15076 PUSH_GS
15077 pushl_cfi %fs
15078@@ -208,7 +341,7 @@
15079 CFI_REL_OFFSET ecx, 0
15080 pushl_cfi %ebx
15081 CFI_REL_OFFSET ebx, 0
15082- movl $(__USER_DS), %edx
15083+ movl $\_DS, %edx
15084 movl %edx, %ds
15085 movl %edx, %es
15086 movl $(__KERNEL_PERCPU), %edx
15087@@ -216,6 +349,15 @@
15088 SET_KERNEL_GS %edx
15089 .endm
15090
15091+.macro SAVE_ALL
15092+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15093+ __SAVE_ALL __KERNEL_DS
15094+ pax_enter_kernel
15095+#else
15096+ __SAVE_ALL __USER_DS
15097+#endif
15098+.endm
15099+
15100 .macro RESTORE_INT_REGS
15101 popl_cfi %ebx
15102 CFI_RESTORE ebx
15103@@ -301,7 +443,7 @@ ENTRY(ret_from_fork)
15104 popfl_cfi
15105 jmp syscall_exit
15106 CFI_ENDPROC
15107-END(ret_from_fork)
15108+ENDPROC(ret_from_fork)
15109
15110 /*
15111 * Interrupt exit functions should be protected against kprobes
15112@@ -335,7 +477,15 @@ resume_userspace_sig:
15113 andl $SEGMENT_RPL_MASK, %eax
15114 #endif
15115 cmpl $USER_RPL, %eax
15116+
15117+#ifdef CONFIG_PAX_KERNEXEC
15118+ jae resume_userspace
15119+
15120+ pax_exit_kernel
15121+ jmp resume_kernel
15122+#else
15123 jb resume_kernel # not returning to v8086 or userspace
15124+#endif
15125
15126 ENTRY(resume_userspace)
15127 LOCKDEP_SYS_EXIT
15128@@ -347,8 +497,8 @@ ENTRY(resume_userspace)
15129 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15130 # int/exception return?
15131 jne work_pending
15132- jmp restore_all
15133-END(ret_from_exception)
15134+ jmp restore_all_pax
15135+ENDPROC(ret_from_exception)
15136
15137 #ifdef CONFIG_PREEMPT
15138 ENTRY(resume_kernel)
15139@@ -363,7 +513,7 @@ need_resched:
15140 jz restore_all
15141 call preempt_schedule_irq
15142 jmp need_resched
15143-END(resume_kernel)
15144+ENDPROC(resume_kernel)
15145 #endif
15146 CFI_ENDPROC
15147 /*
15148@@ -397,23 +547,34 @@ sysenter_past_esp:
15149 /*CFI_REL_OFFSET cs, 0*/
15150 /*
15151 * Push current_thread_info()->sysenter_return to the stack.
15152- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15153- * pushed above; +8 corresponds to copy_thread's esp0 setting.
15154 */
15155- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15156+ pushl_cfi $0
15157 CFI_REL_OFFSET eip, 0
15158
15159 pushl_cfi %eax
15160 SAVE_ALL
15161+ GET_THREAD_INFO(%ebp)
15162+ movl TI_sysenter_return(%ebp),%ebp
15163+ movl %ebp,PT_EIP(%esp)
15164 ENABLE_INTERRUPTS(CLBR_NONE)
15165
15166 /*
15167 * Load the potential sixth argument from user stack.
15168 * Careful about security.
15169 */
15170+ movl PT_OLDESP(%esp),%ebp
15171+
15172+#ifdef CONFIG_PAX_MEMORY_UDEREF
15173+ mov PT_OLDSS(%esp),%ds
15174+1: movl %ds:(%ebp),%ebp
15175+ push %ss
15176+ pop %ds
15177+#else
15178 cmpl $__PAGE_OFFSET-3,%ebp
15179 jae syscall_fault
15180 1: movl (%ebp),%ebp
15181+#endif
15182+
15183 movl %ebp,PT_EBP(%esp)
15184 .section __ex_table,"a"
15185 .align 4
15186@@ -436,12 +597,24 @@ sysenter_do_call:
15187 testl $_TIF_ALLWORK_MASK, %ecx
15188 jne sysexit_audit
15189 sysenter_exit:
15190+
15191+#ifdef CONFIG_PAX_RANDKSTACK
15192+ pushl_cfi %eax
15193+ movl %esp, %eax
15194+ call pax_randomize_kstack
15195+ popl_cfi %eax
15196+#endif
15197+
15198+ pax_erase_kstack
15199+
15200 /* if something modifies registers it must also disable sysexit */
15201 movl PT_EIP(%esp), %edx
15202 movl PT_OLDESP(%esp), %ecx
15203 xorl %ebp,%ebp
15204 TRACE_IRQS_ON
15205 1: mov PT_FS(%esp), %fs
15206+2: mov PT_DS(%esp), %ds
15207+3: mov PT_ES(%esp), %es
15208 PTGS_TO_GS
15209 ENABLE_INTERRUPTS_SYSEXIT
15210
15211@@ -458,6 +631,9 @@ sysenter_audit:
15212 movl %eax,%edx /* 2nd arg: syscall number */
15213 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15214 call __audit_syscall_entry
15215+
15216+ pax_erase_kstack
15217+
15218 pushl_cfi %ebx
15219 movl PT_EAX(%esp),%eax /* reload syscall number */
15220 jmp sysenter_do_call
15221@@ -483,11 +659,17 @@ sysexit_audit:
15222
15223 CFI_ENDPROC
15224 .pushsection .fixup,"ax"
15225-2: movl $0,PT_FS(%esp)
15226+4: movl $0,PT_FS(%esp)
15227+ jmp 1b
15228+5: movl $0,PT_DS(%esp)
15229+ jmp 1b
15230+6: movl $0,PT_ES(%esp)
15231 jmp 1b
15232 .section __ex_table,"a"
15233 .align 4
15234- .long 1b,2b
15235+ .long 1b,4b
15236+ .long 2b,5b
15237+ .long 3b,6b
15238 .popsection
15239 PTGS_TO_GS_EX
15240 ENDPROC(ia32_sysenter_target)
15241@@ -520,6 +702,15 @@ syscall_exit:
15242 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15243 jne syscall_exit_work
15244
15245+restore_all_pax:
15246+
15247+#ifdef CONFIG_PAX_RANDKSTACK
15248+ movl %esp, %eax
15249+ call pax_randomize_kstack
15250+#endif
15251+
15252+ pax_erase_kstack
15253+
15254 restore_all:
15255 TRACE_IRQS_IRET
15256 restore_all_notrace:
15257@@ -579,14 +770,34 @@ ldt_ss:
15258 * compensating for the offset by changing to the ESPFIX segment with
15259 * a base address that matches for the difference.
15260 */
15261-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15262+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15263 mov %esp, %edx /* load kernel esp */
15264 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15265 mov %dx, %ax /* eax: new kernel esp */
15266 sub %eax, %edx /* offset (low word is 0) */
15267+#ifdef CONFIG_SMP
15268+ movl PER_CPU_VAR(cpu_number), %ebx
15269+ shll $PAGE_SHIFT_asm, %ebx
15270+ addl $cpu_gdt_table, %ebx
15271+#else
15272+ movl $cpu_gdt_table, %ebx
15273+#endif
15274 shr $16, %edx
15275- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15276- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15277+
15278+#ifdef CONFIG_PAX_KERNEXEC
15279+ mov %cr0, %esi
15280+ btr $16, %esi
15281+ mov %esi, %cr0
15282+#endif
15283+
15284+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15285+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15286+
15287+#ifdef CONFIG_PAX_KERNEXEC
15288+ bts $16, %esi
15289+ mov %esi, %cr0
15290+#endif
15291+
15292 pushl_cfi $__ESPFIX_SS
15293 pushl_cfi %eax /* new kernel esp */
15294 /* Disable interrupts, but do not irqtrace this section: we
15295@@ -615,38 +826,30 @@ work_resched:
15296 movl TI_flags(%ebp), %ecx
15297 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15298 # than syscall tracing?
15299- jz restore_all
15300+ jz restore_all_pax
15301 testb $_TIF_NEED_RESCHED, %cl
15302 jnz work_resched
15303
15304 work_notifysig: # deal with pending signals and
15305 # notify-resume requests
15306+ movl %esp, %eax
15307 #ifdef CONFIG_VM86
15308 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15309- movl %esp, %eax
15310- jne work_notifysig_v86 # returning to kernel-space or
15311+ jz 1f # returning to kernel-space or
15312 # vm86-space
15313- TRACE_IRQS_ON
15314- ENABLE_INTERRUPTS(CLBR_NONE)
15315- xorl %edx, %edx
15316- call do_notify_resume
15317- jmp resume_userspace_sig
15318
15319- ALIGN
15320-work_notifysig_v86:
15321 pushl_cfi %ecx # save ti_flags for do_notify_resume
15322 call save_v86_state # %eax contains pt_regs pointer
15323 popl_cfi %ecx
15324 movl %eax, %esp
15325-#else
15326- movl %esp, %eax
15327+1:
15328 #endif
15329 TRACE_IRQS_ON
15330 ENABLE_INTERRUPTS(CLBR_NONE)
15331 xorl %edx, %edx
15332 call do_notify_resume
15333 jmp resume_userspace_sig
15334-END(work_pending)
15335+ENDPROC(work_pending)
15336
15337 # perform syscall exit tracing
15338 ALIGN
15339@@ -654,11 +857,14 @@ syscall_trace_entry:
15340 movl $-ENOSYS,PT_EAX(%esp)
15341 movl %esp, %eax
15342 call syscall_trace_enter
15343+
15344+ pax_erase_kstack
15345+
15346 /* What it returned is what we'll actually use. */
15347 cmpl $(NR_syscalls), %eax
15348 jnae syscall_call
15349 jmp syscall_exit
15350-END(syscall_trace_entry)
15351+ENDPROC(syscall_trace_entry)
15352
15353 # perform syscall exit tracing
15354 ALIGN
15355@@ -671,20 +877,24 @@ syscall_exit_work:
15356 movl %esp, %eax
15357 call syscall_trace_leave
15358 jmp resume_userspace
15359-END(syscall_exit_work)
15360+ENDPROC(syscall_exit_work)
15361 CFI_ENDPROC
15362
15363 RING0_INT_FRAME # can't unwind into user space anyway
15364 syscall_fault:
15365+#ifdef CONFIG_PAX_MEMORY_UDEREF
15366+ push %ss
15367+ pop %ds
15368+#endif
15369 GET_THREAD_INFO(%ebp)
15370 movl $-EFAULT,PT_EAX(%esp)
15371 jmp resume_userspace
15372-END(syscall_fault)
15373+ENDPROC(syscall_fault)
15374
15375 syscall_badsys:
15376 movl $-ENOSYS,PT_EAX(%esp)
15377 jmp resume_userspace
15378-END(syscall_badsys)
15379+ENDPROC(syscall_badsys)
15380 CFI_ENDPROC
15381 /*
15382 * End of kprobes section
15383@@ -756,6 +966,36 @@ ENTRY(ptregs_clone)
15384 CFI_ENDPROC
15385 ENDPROC(ptregs_clone)
15386
15387+ ALIGN;
15388+ENTRY(kernel_execve)
15389+ CFI_STARTPROC
15390+ pushl_cfi %ebp
15391+ sub $PT_OLDSS+4,%esp
15392+ pushl_cfi %edi
15393+ pushl_cfi %ecx
15394+ pushl_cfi %eax
15395+ lea 3*4(%esp),%edi
15396+ mov $PT_OLDSS/4+1,%ecx
15397+ xorl %eax,%eax
15398+ rep stosl
15399+ popl_cfi %eax
15400+ popl_cfi %ecx
15401+ popl_cfi %edi
15402+ movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15403+ pushl_cfi %esp
15404+ call sys_execve
15405+ add $4,%esp
15406+ CFI_ADJUST_CFA_OFFSET -4
15407+ GET_THREAD_INFO(%ebp)
15408+ test %eax,%eax
15409+ jz syscall_exit
15410+ add $PT_OLDSS+4,%esp
15411+ CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15412+ popl_cfi %ebp
15413+ ret
15414+ CFI_ENDPROC
15415+ENDPROC(kernel_execve)
15416+
15417 .macro FIXUP_ESPFIX_STACK
15418 /*
15419 * Switch back for ESPFIX stack to the normal zerobased stack
15420@@ -765,8 +1005,15 @@ ENDPROC(ptregs_clone)
15421 * normal stack and adjusts ESP with the matching offset.
15422 */
15423 /* fixup the stack */
15424- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15425- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15426+#ifdef CONFIG_SMP
15427+ movl PER_CPU_VAR(cpu_number), %ebx
15428+ shll $PAGE_SHIFT_asm, %ebx
15429+ addl $cpu_gdt_table, %ebx
15430+#else
15431+ movl $cpu_gdt_table, %ebx
15432+#endif
15433+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15434+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15435 shl $16, %eax
15436 addl %esp, %eax /* the adjusted stack pointer */
15437 pushl_cfi $__KERNEL_DS
15438@@ -819,7 +1066,7 @@ vector=vector+1
15439 .endr
15440 2: jmp common_interrupt
15441 .endr
15442-END(irq_entries_start)
15443+ENDPROC(irq_entries_start)
15444
15445 .previous
15446 END(interrupt)
15447@@ -867,7 +1114,7 @@ ENTRY(coprocessor_error)
15448 pushl_cfi $do_coprocessor_error
15449 jmp error_code
15450 CFI_ENDPROC
15451-END(coprocessor_error)
15452+ENDPROC(coprocessor_error)
15453
15454 ENTRY(simd_coprocessor_error)
15455 RING0_INT_FRAME
15456@@ -888,7 +1135,7 @@ ENTRY(simd_coprocessor_error)
15457 #endif
15458 jmp error_code
15459 CFI_ENDPROC
15460-END(simd_coprocessor_error)
15461+ENDPROC(simd_coprocessor_error)
15462
15463 ENTRY(device_not_available)
15464 RING0_INT_FRAME
15465@@ -896,7 +1143,7 @@ ENTRY(device_not_available)
15466 pushl_cfi $do_device_not_available
15467 jmp error_code
15468 CFI_ENDPROC
15469-END(device_not_available)
15470+ENDPROC(device_not_available)
15471
15472 #ifdef CONFIG_PARAVIRT
15473 ENTRY(native_iret)
15474@@ -905,12 +1152,12 @@ ENTRY(native_iret)
15475 .align 4
15476 .long native_iret, iret_exc
15477 .previous
15478-END(native_iret)
15479+ENDPROC(native_iret)
15480
15481 ENTRY(native_irq_enable_sysexit)
15482 sti
15483 sysexit
15484-END(native_irq_enable_sysexit)
15485+ENDPROC(native_irq_enable_sysexit)
15486 #endif
15487
15488 ENTRY(overflow)
15489@@ -919,7 +1166,7 @@ ENTRY(overflow)
15490 pushl_cfi $do_overflow
15491 jmp error_code
15492 CFI_ENDPROC
15493-END(overflow)
15494+ENDPROC(overflow)
15495
15496 ENTRY(bounds)
15497 RING0_INT_FRAME
15498@@ -927,7 +1174,7 @@ ENTRY(bounds)
15499 pushl_cfi $do_bounds
15500 jmp error_code
15501 CFI_ENDPROC
15502-END(bounds)
15503+ENDPROC(bounds)
15504
15505 ENTRY(invalid_op)
15506 RING0_INT_FRAME
15507@@ -935,7 +1182,7 @@ ENTRY(invalid_op)
15508 pushl_cfi $do_invalid_op
15509 jmp error_code
15510 CFI_ENDPROC
15511-END(invalid_op)
15512+ENDPROC(invalid_op)
15513
15514 ENTRY(coprocessor_segment_overrun)
15515 RING0_INT_FRAME
15516@@ -943,35 +1190,35 @@ ENTRY(coprocessor_segment_overrun)
15517 pushl_cfi $do_coprocessor_segment_overrun
15518 jmp error_code
15519 CFI_ENDPROC
15520-END(coprocessor_segment_overrun)
15521+ENDPROC(coprocessor_segment_overrun)
15522
15523 ENTRY(invalid_TSS)
15524 RING0_EC_FRAME
15525 pushl_cfi $do_invalid_TSS
15526 jmp error_code
15527 CFI_ENDPROC
15528-END(invalid_TSS)
15529+ENDPROC(invalid_TSS)
15530
15531 ENTRY(segment_not_present)
15532 RING0_EC_FRAME
15533 pushl_cfi $do_segment_not_present
15534 jmp error_code
15535 CFI_ENDPROC
15536-END(segment_not_present)
15537+ENDPROC(segment_not_present)
15538
15539 ENTRY(stack_segment)
15540 RING0_EC_FRAME
15541 pushl_cfi $do_stack_segment
15542 jmp error_code
15543 CFI_ENDPROC
15544-END(stack_segment)
15545+ENDPROC(stack_segment)
15546
15547 ENTRY(alignment_check)
15548 RING0_EC_FRAME
15549 pushl_cfi $do_alignment_check
15550 jmp error_code
15551 CFI_ENDPROC
15552-END(alignment_check)
15553+ENDPROC(alignment_check)
15554
15555 ENTRY(divide_error)
15556 RING0_INT_FRAME
15557@@ -979,7 +1226,7 @@ ENTRY(divide_error)
15558 pushl_cfi $do_divide_error
15559 jmp error_code
15560 CFI_ENDPROC
15561-END(divide_error)
15562+ENDPROC(divide_error)
15563
15564 #ifdef CONFIG_X86_MCE
15565 ENTRY(machine_check)
15566@@ -988,7 +1235,7 @@ ENTRY(machine_check)
15567 pushl_cfi machine_check_vector
15568 jmp error_code
15569 CFI_ENDPROC
15570-END(machine_check)
15571+ENDPROC(machine_check)
15572 #endif
15573
15574 ENTRY(spurious_interrupt_bug)
15575@@ -997,7 +1244,7 @@ ENTRY(spurious_interrupt_bug)
15576 pushl_cfi $do_spurious_interrupt_bug
15577 jmp error_code
15578 CFI_ENDPROC
15579-END(spurious_interrupt_bug)
15580+ENDPROC(spurious_interrupt_bug)
15581 /*
15582 * End of kprobes section
15583 */
15584@@ -1112,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15585
15586 ENTRY(mcount)
15587 ret
15588-END(mcount)
15589+ENDPROC(mcount)
15590
15591 ENTRY(ftrace_caller)
15592 cmpl $0, function_trace_stop
15593@@ -1141,7 +1388,7 @@ ftrace_graph_call:
15594 .globl ftrace_stub
15595 ftrace_stub:
15596 ret
15597-END(ftrace_caller)
15598+ENDPROC(ftrace_caller)
15599
15600 #else /* ! CONFIG_DYNAMIC_FTRACE */
15601
15602@@ -1177,7 +1424,7 @@ trace:
15603 popl %ecx
15604 popl %eax
15605 jmp ftrace_stub
15606-END(mcount)
15607+ENDPROC(mcount)
15608 #endif /* CONFIG_DYNAMIC_FTRACE */
15609 #endif /* CONFIG_FUNCTION_TRACER */
15610
15611@@ -1198,7 +1445,7 @@ ENTRY(ftrace_graph_caller)
15612 popl %ecx
15613 popl %eax
15614 ret
15615-END(ftrace_graph_caller)
15616+ENDPROC(ftrace_graph_caller)
15617
15618 .globl return_to_handler
15619 return_to_handler:
15620@@ -1253,15 +1500,18 @@ error_code:
15621 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15622 REG_TO_PTGS %ecx
15623 SET_KERNEL_GS %ecx
15624- movl $(__USER_DS), %ecx
15625+ movl $(__KERNEL_DS), %ecx
15626 movl %ecx, %ds
15627 movl %ecx, %es
15628+
15629+ pax_enter_kernel
15630+
15631 TRACE_IRQS_OFF
15632 movl %esp,%eax # pt_regs pointer
15633 call *%edi
15634 jmp ret_from_exception
15635 CFI_ENDPROC
15636-END(page_fault)
15637+ENDPROC(page_fault)
15638
15639 /*
15640 * Debug traps and NMI can happen at the one SYSENTER instruction
15641@@ -1303,7 +1553,7 @@ debug_stack_correct:
15642 call do_debug
15643 jmp ret_from_exception
15644 CFI_ENDPROC
15645-END(debug)
15646+ENDPROC(debug)
15647
15648 /*
15649 * NMI is doubly nasty. It can happen _while_ we're handling
15650@@ -1340,6 +1590,9 @@ nmi_stack_correct:
15651 xorl %edx,%edx # zero error code
15652 movl %esp,%eax # pt_regs pointer
15653 call do_nmi
15654+
15655+ pax_exit_kernel
15656+
15657 jmp restore_all_notrace
15658 CFI_ENDPROC
15659
15660@@ -1376,12 +1629,15 @@ nmi_espfix_stack:
15661 FIXUP_ESPFIX_STACK # %eax == %esp
15662 xorl %edx,%edx # zero error code
15663 call do_nmi
15664+
15665+ pax_exit_kernel
15666+
15667 RESTORE_REGS
15668 lss 12+4(%esp), %esp # back to espfix stack
15669 CFI_ADJUST_CFA_OFFSET -24
15670 jmp irq_return
15671 CFI_ENDPROC
15672-END(nmi)
15673+ENDPROC(nmi)
15674
15675 ENTRY(int3)
15676 RING0_INT_FRAME
15677@@ -1393,14 +1649,14 @@ ENTRY(int3)
15678 call do_int3
15679 jmp ret_from_exception
15680 CFI_ENDPROC
15681-END(int3)
15682+ENDPROC(int3)
15683
15684 ENTRY(general_protection)
15685 RING0_EC_FRAME
15686 pushl_cfi $do_general_protection
15687 jmp error_code
15688 CFI_ENDPROC
15689-END(general_protection)
15690+ENDPROC(general_protection)
15691
15692 #ifdef CONFIG_KVM_GUEST
15693 ENTRY(async_page_fault)
15694@@ -1408,7 +1664,7 @@ ENTRY(async_page_fault)
15695 pushl_cfi $do_async_page_fault
15696 jmp error_code
15697 CFI_ENDPROC
15698-END(async_page_fault)
15699+ENDPROC(async_page_fault)
15700 #endif
15701
15702 /*
15703diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15704index cdc79b5..4710a75 100644
15705--- a/arch/x86/kernel/entry_64.S
15706+++ b/arch/x86/kernel/entry_64.S
15707@@ -56,6 +56,8 @@
15708 #include <asm/ftrace.h>
15709 #include <asm/percpu.h>
15710 #include <linux/err.h>
15711+#include <asm/pgtable.h>
15712+#include <asm/alternative-asm.h>
15713
15714 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15715 #include <linux/elf-em.h>
15716@@ -69,8 +71,9 @@
15717 #ifdef CONFIG_FUNCTION_TRACER
15718 #ifdef CONFIG_DYNAMIC_FTRACE
15719 ENTRY(mcount)
15720+ pax_force_retaddr
15721 retq
15722-END(mcount)
15723+ENDPROC(mcount)
15724
15725 ENTRY(ftrace_caller)
15726 cmpl $0, function_trace_stop
15727@@ -93,8 +96,9 @@ GLOBAL(ftrace_graph_call)
15728 #endif
15729
15730 GLOBAL(ftrace_stub)
15731+ pax_force_retaddr
15732 retq
15733-END(ftrace_caller)
15734+ENDPROC(ftrace_caller)
15735
15736 #else /* ! CONFIG_DYNAMIC_FTRACE */
15737 ENTRY(mcount)
15738@@ -113,6 +117,7 @@ ENTRY(mcount)
15739 #endif
15740
15741 GLOBAL(ftrace_stub)
15742+ pax_force_retaddr
15743 retq
15744
15745 trace:
15746@@ -122,12 +127,13 @@ trace:
15747 movq 8(%rbp), %rsi
15748 subq $MCOUNT_INSN_SIZE, %rdi
15749
15750+ pax_force_fptr ftrace_trace_function
15751 call *ftrace_trace_function
15752
15753 MCOUNT_RESTORE_FRAME
15754
15755 jmp ftrace_stub
15756-END(mcount)
15757+ENDPROC(mcount)
15758 #endif /* CONFIG_DYNAMIC_FTRACE */
15759 #endif /* CONFIG_FUNCTION_TRACER */
15760
15761@@ -147,8 +153,9 @@ ENTRY(ftrace_graph_caller)
15762
15763 MCOUNT_RESTORE_FRAME
15764
15765+ pax_force_retaddr
15766 retq
15767-END(ftrace_graph_caller)
15768+ENDPROC(ftrace_graph_caller)
15769
15770 GLOBAL(return_to_handler)
15771 subq $24, %rsp
15772@@ -164,6 +171,7 @@ GLOBAL(return_to_handler)
15773 movq 8(%rsp), %rdx
15774 movq (%rsp), %rax
15775 addq $24, %rsp
15776+ pax_force_fptr %rdi
15777 jmp *%rdi
15778 #endif
15779
15780@@ -179,6 +187,282 @@ ENTRY(native_usergs_sysret64)
15781 ENDPROC(native_usergs_sysret64)
15782 #endif /* CONFIG_PARAVIRT */
15783
15784+ .macro ljmpq sel, off
15785+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15786+ .byte 0x48; ljmp *1234f(%rip)
15787+ .pushsection .rodata
15788+ .align 16
15789+ 1234: .quad \off; .word \sel
15790+ .popsection
15791+#else
15792+ pushq $\sel
15793+ pushq $\off
15794+ lretq
15795+#endif
15796+ .endm
15797+
15798+ .macro pax_enter_kernel
15799+ pax_set_fptr_mask
15800+#ifdef CONFIG_PAX_KERNEXEC
15801+ call pax_enter_kernel
15802+#endif
15803+ .endm
15804+
15805+ .macro pax_exit_kernel
15806+#ifdef CONFIG_PAX_KERNEXEC
15807+ call pax_exit_kernel
15808+#endif
15809+ .endm
15810+
15811+#ifdef CONFIG_PAX_KERNEXEC
15812+ENTRY(pax_enter_kernel)
15813+ pushq %rdi
15814+
15815+#ifdef CONFIG_PARAVIRT
15816+ PV_SAVE_REGS(CLBR_RDI)
15817+#endif
15818+
15819+ GET_CR0_INTO_RDI
15820+ bts $16,%rdi
15821+ jnc 3f
15822+ mov %cs,%edi
15823+ cmp $__KERNEL_CS,%edi
15824+ jnz 2f
15825+1:
15826+
15827+#ifdef CONFIG_PARAVIRT
15828+ PV_RESTORE_REGS(CLBR_RDI)
15829+#endif
15830+
15831+ popq %rdi
15832+ pax_force_retaddr
15833+ retq
15834+
15835+2: ljmpq __KERNEL_CS,1f
15836+3: ljmpq __KERNEXEC_KERNEL_CS,4f
15837+4: SET_RDI_INTO_CR0
15838+ jmp 1b
15839+ENDPROC(pax_enter_kernel)
15840+
15841+ENTRY(pax_exit_kernel)
15842+ pushq %rdi
15843+
15844+#ifdef CONFIG_PARAVIRT
15845+ PV_SAVE_REGS(CLBR_RDI)
15846+#endif
15847+
15848+ mov %cs,%rdi
15849+ cmp $__KERNEXEC_KERNEL_CS,%edi
15850+ jz 2f
15851+1:
15852+
15853+#ifdef CONFIG_PARAVIRT
15854+ PV_RESTORE_REGS(CLBR_RDI);
15855+#endif
15856+
15857+ popq %rdi
15858+ pax_force_retaddr
15859+ retq
15860+
15861+2: GET_CR0_INTO_RDI
15862+ btr $16,%rdi
15863+ ljmpq __KERNEL_CS,3f
15864+3: SET_RDI_INTO_CR0
15865+ jmp 1b
15866+#ifdef CONFIG_PARAVIRT
15867+ PV_RESTORE_REGS(CLBR_RDI);
15868+#endif
15869+
15870+ popq %rdi
15871+ pax_force_retaddr
15872+ retq
15873+ENDPROC(pax_exit_kernel)
15874+#endif
15875+
15876+ .macro pax_enter_kernel_user
15877+ pax_set_fptr_mask
15878+#ifdef CONFIG_PAX_MEMORY_UDEREF
15879+ call pax_enter_kernel_user
15880+#endif
15881+ .endm
15882+
15883+ .macro pax_exit_kernel_user
15884+#ifdef CONFIG_PAX_MEMORY_UDEREF
15885+ call pax_exit_kernel_user
15886+#endif
15887+#ifdef CONFIG_PAX_RANDKSTACK
15888+ pushq %rax
15889+ call pax_randomize_kstack
15890+ popq %rax
15891+#endif
15892+ .endm
15893+
15894+#ifdef CONFIG_PAX_MEMORY_UDEREF
15895+ENTRY(pax_enter_kernel_user)
15896+ pushq %rdi
15897+ pushq %rbx
15898+
15899+#ifdef CONFIG_PARAVIRT
15900+ PV_SAVE_REGS(CLBR_RDI)
15901+#endif
15902+
15903+ GET_CR3_INTO_RDI
15904+ mov %rdi,%rbx
15905+ add $__START_KERNEL_map,%rbx
15906+ sub phys_base(%rip),%rbx
15907+
15908+#ifdef CONFIG_PARAVIRT
15909+ pushq %rdi
15910+ cmpl $0, pv_info+PARAVIRT_enabled
15911+ jz 1f
15912+ i = 0
15913+ .rept USER_PGD_PTRS
15914+ mov i*8(%rbx),%rsi
15915+ mov $0,%sil
15916+ lea i*8(%rbx),%rdi
15917+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15918+ i = i + 1
15919+ .endr
15920+ jmp 2f
15921+1:
15922+#endif
15923+
15924+ i = 0
15925+ .rept USER_PGD_PTRS
15926+ movb $0,i*8(%rbx)
15927+ i = i + 1
15928+ .endr
15929+
15930+#ifdef CONFIG_PARAVIRT
15931+2: popq %rdi
15932+#endif
15933+ SET_RDI_INTO_CR3
15934+
15935+#ifdef CONFIG_PAX_KERNEXEC
15936+ GET_CR0_INTO_RDI
15937+ bts $16,%rdi
15938+ SET_RDI_INTO_CR0
15939+#endif
15940+
15941+#ifdef CONFIG_PARAVIRT
15942+ PV_RESTORE_REGS(CLBR_RDI)
15943+#endif
15944+
15945+ popq %rbx
15946+ popq %rdi
15947+ pax_force_retaddr
15948+ retq
15949+ENDPROC(pax_enter_kernel_user)
15950+
15951+ENTRY(pax_exit_kernel_user)
15952+ push %rdi
15953+
15954+#ifdef CONFIG_PARAVIRT
15955+ pushq %rbx
15956+ PV_SAVE_REGS(CLBR_RDI)
15957+#endif
15958+
15959+#ifdef CONFIG_PAX_KERNEXEC
15960+ GET_CR0_INTO_RDI
15961+ btr $16,%rdi
15962+ SET_RDI_INTO_CR0
15963+#endif
15964+
15965+ GET_CR3_INTO_RDI
15966+ add $__START_KERNEL_map,%rdi
15967+ sub phys_base(%rip),%rdi
15968+
15969+#ifdef CONFIG_PARAVIRT
15970+ cmpl $0, pv_info+PARAVIRT_enabled
15971+ jz 1f
15972+ mov %rdi,%rbx
15973+ i = 0
15974+ .rept USER_PGD_PTRS
15975+ mov i*8(%rbx),%rsi
15976+ mov $0x67,%sil
15977+ lea i*8(%rbx),%rdi
15978+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15979+ i = i + 1
15980+ .endr
15981+ jmp 2f
15982+1:
15983+#endif
15984+
15985+ i = 0
15986+ .rept USER_PGD_PTRS
15987+ movb $0x67,i*8(%rdi)
15988+ i = i + 1
15989+ .endr
15990+
15991+#ifdef CONFIG_PARAVIRT
15992+2: PV_RESTORE_REGS(CLBR_RDI)
15993+ popq %rbx
15994+#endif
15995+
15996+ popq %rdi
15997+ pax_force_retaddr
15998+ retq
15999+ENDPROC(pax_exit_kernel_user)
16000+#endif
16001+
16002+.macro pax_erase_kstack
16003+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16004+ call pax_erase_kstack
16005+#endif
16006+.endm
16007+
16008+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16009+/*
16010+ * r11: thread_info
16011+ * rcx, rdx: can be clobbered
16012+ */
16013+ENTRY(pax_erase_kstack)
16014+ pushq %rdi
16015+ pushq %rax
16016+ pushq %r11
16017+
16018+ GET_THREAD_INFO(%r11)
16019+ mov TI_lowest_stack(%r11), %rdi
16020+ mov $-0xBEEF, %rax
16021+ std
16022+
16023+1: mov %edi, %ecx
16024+ and $THREAD_SIZE_asm - 1, %ecx
16025+ shr $3, %ecx
16026+ repne scasq
16027+ jecxz 2f
16028+
16029+ cmp $2*8, %ecx
16030+ jc 2f
16031+
16032+ mov $2*8, %ecx
16033+ repe scasq
16034+ jecxz 2f
16035+ jne 1b
16036+
16037+2: cld
16038+ mov %esp, %ecx
16039+ sub %edi, %ecx
16040+
16041+ cmp $THREAD_SIZE_asm, %rcx
16042+ jb 3f
16043+ ud2
16044+3:
16045+
16046+ shr $3, %ecx
16047+ rep stosq
16048+
16049+ mov TI_task_thread_sp0(%r11), %rdi
16050+ sub $256, %rdi
16051+ mov %rdi, TI_lowest_stack(%r11)
16052+
16053+ popq %r11
16054+ popq %rax
16055+ popq %rdi
16056+ pax_force_retaddr
16057+ ret
16058+ENDPROC(pax_erase_kstack)
16059+#endif
16060
16061 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
16062 #ifdef CONFIG_TRACE_IRQFLAGS
16063@@ -232,8 +516,8 @@ ENDPROC(native_usergs_sysret64)
16064 .endm
16065
16066 .macro UNFAKE_STACK_FRAME
16067- addq $8*6, %rsp
16068- CFI_ADJUST_CFA_OFFSET -(6*8)
16069+ addq $8*6 + ARG_SKIP, %rsp
16070+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
16071 .endm
16072
16073 /*
16074@@ -320,7 +604,7 @@ ENDPROC(native_usergs_sysret64)
16075 movq %rsp, %rsi
16076
16077 leaq -RBP(%rsp),%rdi /* arg1 for handler */
16078- testl $3, CS-RBP(%rsi)
16079+ testb $3, CS-RBP(%rsi)
16080 je 1f
16081 SWAPGS
16082 /*
16083@@ -355,9 +639,10 @@ ENTRY(save_rest)
16084 movq_cfi r15, R15+16
16085 movq %r11, 8(%rsp) /* return address */
16086 FIXUP_TOP_OF_STACK %r11, 16
16087+ pax_force_retaddr
16088 ret
16089 CFI_ENDPROC
16090-END(save_rest)
16091+ENDPROC(save_rest)
16092
16093 /* save complete stack frame */
16094 .pushsection .kprobes.text, "ax"
16095@@ -386,9 +671,10 @@ ENTRY(save_paranoid)
16096 js 1f /* negative -> in kernel */
16097 SWAPGS
16098 xorl %ebx,%ebx
16099-1: ret
16100+1: pax_force_retaddr_bts
16101+ ret
16102 CFI_ENDPROC
16103-END(save_paranoid)
16104+ENDPROC(save_paranoid)
16105 .popsection
16106
16107 /*
16108@@ -410,7 +696,7 @@ ENTRY(ret_from_fork)
16109
16110 RESTORE_REST
16111
16112- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16113+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16114 jz retint_restore_args
16115
16116 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16117@@ -420,7 +706,7 @@ ENTRY(ret_from_fork)
16118 jmp ret_from_sys_call # go to the SYSRET fastpath
16119
16120 CFI_ENDPROC
16121-END(ret_from_fork)
16122+ENDPROC(ret_from_fork)
16123
16124 /*
16125 * System call entry. Up to 6 arguments in registers are supported.
16126@@ -456,7 +742,7 @@ END(ret_from_fork)
16127 ENTRY(system_call)
16128 CFI_STARTPROC simple
16129 CFI_SIGNAL_FRAME
16130- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16131+ CFI_DEF_CFA rsp,0
16132 CFI_REGISTER rip,rcx
16133 /*CFI_REGISTER rflags,r11*/
16134 SWAPGS_UNSAFE_STACK
16135@@ -469,16 +755,18 @@ GLOBAL(system_call_after_swapgs)
16136
16137 movq %rsp,PER_CPU_VAR(old_rsp)
16138 movq PER_CPU_VAR(kernel_stack),%rsp
16139+ SAVE_ARGS 8*6,0
16140+ pax_enter_kernel_user
16141 /*
16142 * No need to follow this irqs off/on section - it's straight
16143 * and short:
16144 */
16145 ENABLE_INTERRUPTS(CLBR_NONE)
16146- SAVE_ARGS 8,0
16147 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16148 movq %rcx,RIP-ARGOFFSET(%rsp)
16149 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16150- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16151+ GET_THREAD_INFO(%rcx)
16152+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16153 jnz tracesys
16154 system_call_fastpath:
16155 #if __SYSCALL_MASK == ~0
16156@@ -488,7 +776,7 @@ system_call_fastpath:
16157 cmpl $__NR_syscall_max,%eax
16158 #endif
16159 ja badsys
16160- movq %r10,%rcx
16161+ movq R10-ARGOFFSET(%rsp),%rcx
16162 call *sys_call_table(,%rax,8) # XXX: rip relative
16163 movq %rax,RAX-ARGOFFSET(%rsp)
16164 /*
16165@@ -502,10 +790,13 @@ sysret_check:
16166 LOCKDEP_SYS_EXIT
16167 DISABLE_INTERRUPTS(CLBR_NONE)
16168 TRACE_IRQS_OFF
16169- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16170+ GET_THREAD_INFO(%rcx)
16171+ movl TI_flags(%rcx),%edx
16172 andl %edi,%edx
16173 jnz sysret_careful
16174 CFI_REMEMBER_STATE
16175+ pax_exit_kernel_user
16176+ pax_erase_kstack
16177 /*
16178 * sysretq will re-enable interrupts:
16179 */
16180@@ -557,14 +848,18 @@ badsys:
16181 * jump back to the normal fast path.
16182 */
16183 auditsys:
16184- movq %r10,%r9 /* 6th arg: 4th syscall arg */
16185+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16186 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16187 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16188 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16189 movq %rax,%rsi /* 2nd arg: syscall number */
16190 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16191 call __audit_syscall_entry
16192+
16193+ pax_erase_kstack
16194+
16195 LOAD_ARGS 0 /* reload call-clobbered registers */
16196+ pax_set_fptr_mask
16197 jmp system_call_fastpath
16198
16199 /*
16200@@ -585,7 +880,7 @@ sysret_audit:
16201 /* Do syscall tracing */
16202 tracesys:
16203 #ifdef CONFIG_AUDITSYSCALL
16204- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16205+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16206 jz auditsys
16207 #endif
16208 SAVE_REST
16209@@ -593,12 +888,16 @@ tracesys:
16210 FIXUP_TOP_OF_STACK %rdi
16211 movq %rsp,%rdi
16212 call syscall_trace_enter
16213+
16214+ pax_erase_kstack
16215+
16216 /*
16217 * Reload arg registers from stack in case ptrace changed them.
16218 * We don't reload %rax because syscall_trace_enter() returned
16219 * the value it wants us to use in the table lookup.
16220 */
16221 LOAD_ARGS ARGOFFSET, 1
16222+ pax_set_fptr_mask
16223 RESTORE_REST
16224 #if __SYSCALL_MASK == ~0
16225 cmpq $__NR_syscall_max,%rax
16226@@ -607,7 +906,7 @@ tracesys:
16227 cmpl $__NR_syscall_max,%eax
16228 #endif
16229 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16230- movq %r10,%rcx /* fixup for C */
16231+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16232 call *sys_call_table(,%rax,8)
16233 movq %rax,RAX-ARGOFFSET(%rsp)
16234 /* Use IRET because user could have changed frame */
16235@@ -628,6 +927,7 @@ GLOBAL(int_with_check)
16236 andl %edi,%edx
16237 jnz int_careful
16238 andl $~TS_COMPAT,TI_status(%rcx)
16239+ pax_erase_kstack
16240 jmp retint_swapgs
16241
16242 /* Either reschedule or signal or syscall exit tracking needed. */
16243@@ -674,7 +974,7 @@ int_restore_rest:
16244 TRACE_IRQS_OFF
16245 jmp int_with_check
16246 CFI_ENDPROC
16247-END(system_call)
16248+ENDPROC(system_call)
16249
16250 /*
16251 * Certain special system calls that need to save a complete full stack frame.
16252@@ -690,7 +990,7 @@ ENTRY(\label)
16253 call \func
16254 jmp ptregscall_common
16255 CFI_ENDPROC
16256-END(\label)
16257+ENDPROC(\label)
16258 .endm
16259
16260 PTREGSCALL stub_clone, sys_clone, %r8
16261@@ -708,9 +1008,10 @@ ENTRY(ptregscall_common)
16262 movq_cfi_restore R12+8, r12
16263 movq_cfi_restore RBP+8, rbp
16264 movq_cfi_restore RBX+8, rbx
16265+ pax_force_retaddr
16266 ret $REST_SKIP /* pop extended registers */
16267 CFI_ENDPROC
16268-END(ptregscall_common)
16269+ENDPROC(ptregscall_common)
16270
16271 ENTRY(stub_execve)
16272 CFI_STARTPROC
16273@@ -725,7 +1026,7 @@ ENTRY(stub_execve)
16274 RESTORE_REST
16275 jmp int_ret_from_sys_call
16276 CFI_ENDPROC
16277-END(stub_execve)
16278+ENDPROC(stub_execve)
16279
16280 /*
16281 * sigreturn is special because it needs to restore all registers on return.
16282@@ -743,7 +1044,7 @@ ENTRY(stub_rt_sigreturn)
16283 RESTORE_REST
16284 jmp int_ret_from_sys_call
16285 CFI_ENDPROC
16286-END(stub_rt_sigreturn)
16287+ENDPROC(stub_rt_sigreturn)
16288
16289 #ifdef CONFIG_X86_X32_ABI
16290 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16291@@ -812,7 +1113,7 @@ vector=vector+1
16292 2: jmp common_interrupt
16293 .endr
16294 CFI_ENDPROC
16295-END(irq_entries_start)
16296+ENDPROC(irq_entries_start)
16297
16298 .previous
16299 END(interrupt)
16300@@ -832,6 +1133,16 @@ END(interrupt)
16301 subq $ORIG_RAX-RBP, %rsp
16302 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16303 SAVE_ARGS_IRQ
16304+#ifdef CONFIG_PAX_MEMORY_UDEREF
16305+ testb $3, CS(%rdi)
16306+ jnz 1f
16307+ pax_enter_kernel
16308+ jmp 2f
16309+1: pax_enter_kernel_user
16310+2:
16311+#else
16312+ pax_enter_kernel
16313+#endif
16314 call \func
16315 .endm
16316
16317@@ -863,7 +1174,7 @@ ret_from_intr:
16318
16319 exit_intr:
16320 GET_THREAD_INFO(%rcx)
16321- testl $3,CS-ARGOFFSET(%rsp)
16322+ testb $3,CS-ARGOFFSET(%rsp)
16323 je retint_kernel
16324
16325 /* Interrupt came from user space */
16326@@ -885,12 +1196,15 @@ retint_swapgs: /* return to user-space */
16327 * The iretq could re-enable interrupts:
16328 */
16329 DISABLE_INTERRUPTS(CLBR_ANY)
16330+ pax_exit_kernel_user
16331 TRACE_IRQS_IRETQ
16332 SWAPGS
16333 jmp restore_args
16334
16335 retint_restore_args: /* return to kernel space */
16336 DISABLE_INTERRUPTS(CLBR_ANY)
16337+ pax_exit_kernel
16338+ pax_force_retaddr RIP-ARGOFFSET
16339 /*
16340 * The iretq could re-enable interrupts:
16341 */
16342@@ -979,7 +1293,7 @@ ENTRY(retint_kernel)
16343 #endif
16344
16345 CFI_ENDPROC
16346-END(common_interrupt)
16347+ENDPROC(common_interrupt)
16348 /*
16349 * End of kprobes section
16350 */
16351@@ -996,7 +1310,7 @@ ENTRY(\sym)
16352 interrupt \do_sym
16353 jmp ret_from_intr
16354 CFI_ENDPROC
16355-END(\sym)
16356+ENDPROC(\sym)
16357 .endm
16358
16359 #ifdef CONFIG_SMP
16360@@ -1069,12 +1383,22 @@ ENTRY(\sym)
16361 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16362 call error_entry
16363 DEFAULT_FRAME 0
16364+#ifdef CONFIG_PAX_MEMORY_UDEREF
16365+ testb $3, CS(%rsp)
16366+ jnz 1f
16367+ pax_enter_kernel
16368+ jmp 2f
16369+1: pax_enter_kernel_user
16370+2:
16371+#else
16372+ pax_enter_kernel
16373+#endif
16374 movq %rsp,%rdi /* pt_regs pointer */
16375 xorl %esi,%esi /* no error code */
16376 call \do_sym
16377 jmp error_exit /* %ebx: no swapgs flag */
16378 CFI_ENDPROC
16379-END(\sym)
16380+ENDPROC(\sym)
16381 .endm
16382
16383 .macro paranoidzeroentry sym do_sym
16384@@ -1086,15 +1410,25 @@ ENTRY(\sym)
16385 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16386 call save_paranoid
16387 TRACE_IRQS_OFF
16388+#ifdef CONFIG_PAX_MEMORY_UDEREF
16389+ testb $3, CS(%rsp)
16390+ jnz 1f
16391+ pax_enter_kernel
16392+ jmp 2f
16393+1: pax_enter_kernel_user
16394+2:
16395+#else
16396+ pax_enter_kernel
16397+#endif
16398 movq %rsp,%rdi /* pt_regs pointer */
16399 xorl %esi,%esi /* no error code */
16400 call \do_sym
16401 jmp paranoid_exit /* %ebx: no swapgs flag */
16402 CFI_ENDPROC
16403-END(\sym)
16404+ENDPROC(\sym)
16405 .endm
16406
16407-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16408+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16409 .macro paranoidzeroentry_ist sym do_sym ist
16410 ENTRY(\sym)
16411 INTR_FRAME
16412@@ -1104,14 +1438,30 @@ ENTRY(\sym)
16413 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16414 call save_paranoid
16415 TRACE_IRQS_OFF
16416+#ifdef CONFIG_PAX_MEMORY_UDEREF
16417+ testb $3, CS(%rsp)
16418+ jnz 1f
16419+ pax_enter_kernel
16420+ jmp 2f
16421+1: pax_enter_kernel_user
16422+2:
16423+#else
16424+ pax_enter_kernel
16425+#endif
16426 movq %rsp,%rdi /* pt_regs pointer */
16427 xorl %esi,%esi /* no error code */
16428+#ifdef CONFIG_SMP
16429+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16430+ lea init_tss(%r12), %r12
16431+#else
16432+ lea init_tss(%rip), %r12
16433+#endif
16434 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16435 call \do_sym
16436 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16437 jmp paranoid_exit /* %ebx: no swapgs flag */
16438 CFI_ENDPROC
16439-END(\sym)
16440+ENDPROC(\sym)
16441 .endm
16442
16443 .macro errorentry sym do_sym
16444@@ -1122,13 +1472,23 @@ ENTRY(\sym)
16445 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16446 call error_entry
16447 DEFAULT_FRAME 0
16448+#ifdef CONFIG_PAX_MEMORY_UDEREF
16449+ testb $3, CS(%rsp)
16450+ jnz 1f
16451+ pax_enter_kernel
16452+ jmp 2f
16453+1: pax_enter_kernel_user
16454+2:
16455+#else
16456+ pax_enter_kernel
16457+#endif
16458 movq %rsp,%rdi /* pt_regs pointer */
16459 movq ORIG_RAX(%rsp),%rsi /* get error code */
16460 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16461 call \do_sym
16462 jmp error_exit /* %ebx: no swapgs flag */
16463 CFI_ENDPROC
16464-END(\sym)
16465+ENDPROC(\sym)
16466 .endm
16467
16468 /* error code is on the stack already */
16469@@ -1141,13 +1501,23 @@ ENTRY(\sym)
16470 call save_paranoid
16471 DEFAULT_FRAME 0
16472 TRACE_IRQS_OFF
16473+#ifdef CONFIG_PAX_MEMORY_UDEREF
16474+ testb $3, CS(%rsp)
16475+ jnz 1f
16476+ pax_enter_kernel
16477+ jmp 2f
16478+1: pax_enter_kernel_user
16479+2:
16480+#else
16481+ pax_enter_kernel
16482+#endif
16483 movq %rsp,%rdi /* pt_regs pointer */
16484 movq ORIG_RAX(%rsp),%rsi /* get error code */
16485 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16486 call \do_sym
16487 jmp paranoid_exit /* %ebx: no swapgs flag */
16488 CFI_ENDPROC
16489-END(\sym)
16490+ENDPROC(\sym)
16491 .endm
16492
16493 zeroentry divide_error do_divide_error
16494@@ -1177,9 +1547,10 @@ gs_change:
16495 2: mfence /* workaround */
16496 SWAPGS
16497 popfq_cfi
16498+ pax_force_retaddr
16499 ret
16500 CFI_ENDPROC
16501-END(native_load_gs_index)
16502+ENDPROC(native_load_gs_index)
16503
16504 .section __ex_table,"a"
16505 .align 8
16506@@ -1201,13 +1572,14 @@ ENTRY(kernel_thread_helper)
16507 * Here we are in the child and the registers are set as they were
16508 * at kernel_thread() invocation in the parent.
16509 */
16510+ pax_force_fptr %rsi
16511 call *%rsi
16512 # exit
16513 mov %eax, %edi
16514 call do_exit
16515 ud2 # padding for call trace
16516 CFI_ENDPROC
16517-END(kernel_thread_helper)
16518+ENDPROC(kernel_thread_helper)
16519
16520 /*
16521 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16522@@ -1234,11 +1606,11 @@ ENTRY(kernel_execve)
16523 RESTORE_REST
16524 testq %rax,%rax
16525 je int_ret_from_sys_call
16526- RESTORE_ARGS
16527 UNFAKE_STACK_FRAME
16528+ pax_force_retaddr
16529 ret
16530 CFI_ENDPROC
16531-END(kernel_execve)
16532+ENDPROC(kernel_execve)
16533
16534 /* Call softirq on interrupt stack. Interrupts are off. */
16535 ENTRY(call_softirq)
16536@@ -1256,9 +1628,10 @@ ENTRY(call_softirq)
16537 CFI_DEF_CFA_REGISTER rsp
16538 CFI_ADJUST_CFA_OFFSET -8
16539 decl PER_CPU_VAR(irq_count)
16540+ pax_force_retaddr
16541 ret
16542 CFI_ENDPROC
16543-END(call_softirq)
16544+ENDPROC(call_softirq)
16545
16546 #ifdef CONFIG_XEN
16547 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16548@@ -1296,7 +1669,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16549 decl PER_CPU_VAR(irq_count)
16550 jmp error_exit
16551 CFI_ENDPROC
16552-END(xen_do_hypervisor_callback)
16553+ENDPROC(xen_do_hypervisor_callback)
16554
16555 /*
16556 * Hypervisor uses this for application faults while it executes.
16557@@ -1355,7 +1728,7 @@ ENTRY(xen_failsafe_callback)
16558 SAVE_ALL
16559 jmp error_exit
16560 CFI_ENDPROC
16561-END(xen_failsafe_callback)
16562+ENDPROC(xen_failsafe_callback)
16563
16564 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16565 xen_hvm_callback_vector xen_evtchn_do_upcall
16566@@ -1404,16 +1777,31 @@ ENTRY(paranoid_exit)
16567 TRACE_IRQS_OFF
16568 testl %ebx,%ebx /* swapgs needed? */
16569 jnz paranoid_restore
16570- testl $3,CS(%rsp)
16571+ testb $3,CS(%rsp)
16572 jnz paranoid_userspace
16573+#ifdef CONFIG_PAX_MEMORY_UDEREF
16574+ pax_exit_kernel
16575+ TRACE_IRQS_IRETQ 0
16576+ SWAPGS_UNSAFE_STACK
16577+ RESTORE_ALL 8
16578+ pax_force_retaddr_bts
16579+ jmp irq_return
16580+#endif
16581 paranoid_swapgs:
16582+#ifdef CONFIG_PAX_MEMORY_UDEREF
16583+ pax_exit_kernel_user
16584+#else
16585+ pax_exit_kernel
16586+#endif
16587 TRACE_IRQS_IRETQ 0
16588 SWAPGS_UNSAFE_STACK
16589 RESTORE_ALL 8
16590 jmp irq_return
16591 paranoid_restore:
16592+ pax_exit_kernel
16593 TRACE_IRQS_IRETQ 0
16594 RESTORE_ALL 8
16595+ pax_force_retaddr_bts
16596 jmp irq_return
16597 paranoid_userspace:
16598 GET_THREAD_INFO(%rcx)
16599@@ -1442,7 +1830,7 @@ paranoid_schedule:
16600 TRACE_IRQS_OFF
16601 jmp paranoid_userspace
16602 CFI_ENDPROC
16603-END(paranoid_exit)
16604+ENDPROC(paranoid_exit)
16605
16606 /*
16607 * Exception entry point. This expects an error code/orig_rax on the stack.
16608@@ -1469,12 +1857,13 @@ ENTRY(error_entry)
16609 movq_cfi r14, R14+8
16610 movq_cfi r15, R15+8
16611 xorl %ebx,%ebx
16612- testl $3,CS+8(%rsp)
16613+ testb $3,CS+8(%rsp)
16614 je error_kernelspace
16615 error_swapgs:
16616 SWAPGS
16617 error_sti:
16618 TRACE_IRQS_OFF
16619+ pax_force_retaddr_bts
16620 ret
16621
16622 /*
16623@@ -1501,7 +1890,7 @@ bstep_iret:
16624 movq %rcx,RIP+8(%rsp)
16625 jmp error_swapgs
16626 CFI_ENDPROC
16627-END(error_entry)
16628+ENDPROC(error_entry)
16629
16630
16631 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16632@@ -1521,7 +1910,7 @@ ENTRY(error_exit)
16633 jnz retint_careful
16634 jmp retint_swapgs
16635 CFI_ENDPROC
16636-END(error_exit)
16637+ENDPROC(error_exit)
16638
16639 /*
16640 * Test if a given stack is an NMI stack or not.
16641@@ -1579,9 +1968,11 @@ ENTRY(nmi)
16642 * If %cs was not the kernel segment, then the NMI triggered in user
16643 * space, which means it is definitely not nested.
16644 */
16645+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16646+ je 1f
16647 cmpl $__KERNEL_CS, 16(%rsp)
16648 jne first_nmi
16649-
16650+1:
16651 /*
16652 * Check the special variable on the stack to see if NMIs are
16653 * executing.
16654@@ -1728,6 +2119,16 @@ end_repeat_nmi:
16655 */
16656 call save_paranoid
16657 DEFAULT_FRAME 0
16658+#ifdef CONFIG_PAX_MEMORY_UDEREF
16659+ testb $3, CS(%rsp)
16660+ jnz 1f
16661+ pax_enter_kernel
16662+ jmp 2f
16663+1: pax_enter_kernel_user
16664+2:
16665+#else
16666+ pax_enter_kernel
16667+#endif
16668 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16669 movq %rsp,%rdi
16670 movq $-1,%rsi
16671@@ -1735,21 +2136,32 @@ end_repeat_nmi:
16672 testl %ebx,%ebx /* swapgs needed? */
16673 jnz nmi_restore
16674 nmi_swapgs:
16675+#ifdef CONFIG_PAX_MEMORY_UDEREF
16676+ pax_exit_kernel_user
16677+#else
16678+ pax_exit_kernel
16679+#endif
16680 SWAPGS_UNSAFE_STACK
16681+ RESTORE_ALL 8
16682+ /* Clear the NMI executing stack variable */
16683+ movq $0, 10*8(%rsp)
16684+ jmp irq_return
16685 nmi_restore:
16686+ pax_exit_kernel
16687 RESTORE_ALL 8
16688+ pax_force_retaddr_bts
16689 /* Clear the NMI executing stack variable */
16690 movq $0, 10*8(%rsp)
16691 jmp irq_return
16692 CFI_ENDPROC
16693-END(nmi)
16694+ENDPROC(nmi)
16695
16696 ENTRY(ignore_sysret)
16697 CFI_STARTPROC
16698 mov $-ENOSYS,%eax
16699 sysret
16700 CFI_ENDPROC
16701-END(ignore_sysret)
16702+ENDPROC(ignore_sysret)
16703
16704 /*
16705 * End of kprobes section
16706diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16707index c9a281f..ce2f317 100644
16708--- a/arch/x86/kernel/ftrace.c
16709+++ b/arch/x86/kernel/ftrace.c
16710@@ -126,7 +126,7 @@ static void *mod_code_ip; /* holds the IP to write to */
16711 static const void *mod_code_newcode; /* holds the text to write to the IP */
16712
16713 static unsigned nmi_wait_count;
16714-static atomic_t nmi_update_count = ATOMIC_INIT(0);
16715+static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
16716
16717 int ftrace_arch_read_dyn_info(char *buf, int size)
16718 {
16719@@ -134,7 +134,7 @@ int ftrace_arch_read_dyn_info(char *buf, int size)
16720
16721 r = snprintf(buf, size, "%u %u",
16722 nmi_wait_count,
16723- atomic_read(&nmi_update_count));
16724+ atomic_read_unchecked(&nmi_update_count));
16725 return r;
16726 }
16727
16728@@ -177,8 +177,10 @@ void ftrace_nmi_enter(void)
16729
16730 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
16731 smp_rmb();
16732+ pax_open_kernel();
16733 ftrace_mod_code();
16734- atomic_inc(&nmi_update_count);
16735+ pax_close_kernel();
16736+ atomic_inc_unchecked(&nmi_update_count);
16737 }
16738 /* Must have previous changes seen before executions */
16739 smp_mb();
16740@@ -271,6 +273,8 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
16741 {
16742 unsigned char replaced[MCOUNT_INSN_SIZE];
16743
16744+ ip = ktla_ktva(ip);
16745+
16746 /*
16747 * Note: Due to modules and __init, code can
16748 * disappear and change, we need to protect against faulting
16749@@ -327,7 +331,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16750 unsigned char old[MCOUNT_INSN_SIZE], *new;
16751 int ret;
16752
16753- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16754+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16755 new = ftrace_call_replace(ip, (unsigned long)func);
16756 ret = ftrace_modify_code(ip, old, new);
16757
16758@@ -353,6 +357,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16759 {
16760 unsigned char code[MCOUNT_INSN_SIZE];
16761
16762+ ip = ktla_ktva(ip);
16763+
16764 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16765 return -EFAULT;
16766
16767diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16768index 51ff186..9e77418 100644
16769--- a/arch/x86/kernel/head32.c
16770+++ b/arch/x86/kernel/head32.c
16771@@ -19,6 +19,7 @@
16772 #include <asm/io_apic.h>
16773 #include <asm/bios_ebda.h>
16774 #include <asm/tlbflush.h>
16775+#include <asm/boot.h>
16776
16777 static void __init i386_default_early_setup(void)
16778 {
16779@@ -31,8 +32,7 @@ static void __init i386_default_early_setup(void)
16780
16781 void __init i386_start_kernel(void)
16782 {
16783- memblock_reserve(__pa_symbol(&_text),
16784- __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16785+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16786
16787 #ifdef CONFIG_BLK_DEV_INITRD
16788 /* Reserve INITRD */
16789diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16790index ce0be7c..c41476e 100644
16791--- a/arch/x86/kernel/head_32.S
16792+++ b/arch/x86/kernel/head_32.S
16793@@ -25,6 +25,12 @@
16794 /* Physical address */
16795 #define pa(X) ((X) - __PAGE_OFFSET)
16796
16797+#ifdef CONFIG_PAX_KERNEXEC
16798+#define ta(X) (X)
16799+#else
16800+#define ta(X) ((X) - __PAGE_OFFSET)
16801+#endif
16802+
16803 /*
16804 * References to members of the new_cpu_data structure.
16805 */
16806@@ -54,11 +60,7 @@
16807 * and small than max_low_pfn, otherwise will waste some page table entries
16808 */
16809
16810-#if PTRS_PER_PMD > 1
16811-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16812-#else
16813-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16814-#endif
16815+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16816
16817 /* Number of possible pages in the lowmem region */
16818 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16819@@ -77,6 +79,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16820 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16821
16822 /*
16823+ * Real beginning of normal "text" segment
16824+ */
16825+ENTRY(stext)
16826+ENTRY(_stext)
16827+
16828+/*
16829 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16830 * %esi points to the real-mode code as a 32-bit pointer.
16831 * CS and DS must be 4 GB flat segments, but we don't depend on
16832@@ -84,6 +92,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16833 * can.
16834 */
16835 __HEAD
16836+
16837+#ifdef CONFIG_PAX_KERNEXEC
16838+ jmp startup_32
16839+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16840+.fill PAGE_SIZE-5,1,0xcc
16841+#endif
16842+
16843 ENTRY(startup_32)
16844 movl pa(stack_start),%ecx
16845
16846@@ -105,6 +120,57 @@ ENTRY(startup_32)
16847 2:
16848 leal -__PAGE_OFFSET(%ecx),%esp
16849
16850+#ifdef CONFIG_SMP
16851+ movl $pa(cpu_gdt_table),%edi
16852+ movl $__per_cpu_load,%eax
16853+ movw %ax,__KERNEL_PERCPU + 2(%edi)
16854+ rorl $16,%eax
16855+ movb %al,__KERNEL_PERCPU + 4(%edi)
16856+ movb %ah,__KERNEL_PERCPU + 7(%edi)
16857+ movl $__per_cpu_end - 1,%eax
16858+ subl $__per_cpu_start,%eax
16859+ movw %ax,__KERNEL_PERCPU + 0(%edi)
16860+#endif
16861+
16862+#ifdef CONFIG_PAX_MEMORY_UDEREF
16863+ movl $NR_CPUS,%ecx
16864+ movl $pa(cpu_gdt_table),%edi
16865+1:
16866+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16867+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16868+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16869+ addl $PAGE_SIZE_asm,%edi
16870+ loop 1b
16871+#endif
16872+
16873+#ifdef CONFIG_PAX_KERNEXEC
16874+ movl $pa(boot_gdt),%edi
16875+ movl $__LOAD_PHYSICAL_ADDR,%eax
16876+ movw %ax,__BOOT_CS + 2(%edi)
16877+ rorl $16,%eax
16878+ movb %al,__BOOT_CS + 4(%edi)
16879+ movb %ah,__BOOT_CS + 7(%edi)
16880+ rorl $16,%eax
16881+
16882+ ljmp $(__BOOT_CS),$1f
16883+1:
16884+
16885+ movl $NR_CPUS,%ecx
16886+ movl $pa(cpu_gdt_table),%edi
16887+ addl $__PAGE_OFFSET,%eax
16888+1:
16889+ movw %ax,__KERNEL_CS + 2(%edi)
16890+ movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16891+ rorl $16,%eax
16892+ movb %al,__KERNEL_CS + 4(%edi)
16893+ movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16894+ movb %ah,__KERNEL_CS + 7(%edi)
16895+ movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16896+ rorl $16,%eax
16897+ addl $PAGE_SIZE_asm,%edi
16898+ loop 1b
16899+#endif
16900+
16901 /*
16902 * Clear BSS first so that there are no surprises...
16903 */
16904@@ -195,8 +261,11 @@ ENTRY(startup_32)
16905 movl %eax, pa(max_pfn_mapped)
16906
16907 /* Do early initialization of the fixmap area */
16908- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16909- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16910+#ifdef CONFIG_COMPAT_VDSO
16911+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16912+#else
16913+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16914+#endif
16915 #else /* Not PAE */
16916
16917 page_pde_offset = (__PAGE_OFFSET >> 20);
16918@@ -226,8 +295,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16919 movl %eax, pa(max_pfn_mapped)
16920
16921 /* Do early initialization of the fixmap area */
16922- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16923- movl %eax,pa(initial_page_table+0xffc)
16924+#ifdef CONFIG_COMPAT_VDSO
16925+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16926+#else
16927+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16928+#endif
16929 #endif
16930
16931 #ifdef CONFIG_PARAVIRT
16932@@ -241,9 +313,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16933 cmpl $num_subarch_entries, %eax
16934 jae bad_subarch
16935
16936- movl pa(subarch_entries)(,%eax,4), %eax
16937- subl $__PAGE_OFFSET, %eax
16938- jmp *%eax
16939+ jmp *pa(subarch_entries)(,%eax,4)
16940
16941 bad_subarch:
16942 WEAK(lguest_entry)
16943@@ -255,10 +325,10 @@ WEAK(xen_entry)
16944 __INITDATA
16945
16946 subarch_entries:
16947- .long default_entry /* normal x86/PC */
16948- .long lguest_entry /* lguest hypervisor */
16949- .long xen_entry /* Xen hypervisor */
16950- .long default_entry /* Moorestown MID */
16951+ .long ta(default_entry) /* normal x86/PC */
16952+ .long ta(lguest_entry) /* lguest hypervisor */
16953+ .long ta(xen_entry) /* Xen hypervisor */
16954+ .long ta(default_entry) /* Moorestown MID */
16955 num_subarch_entries = (. - subarch_entries) / 4
16956 .previous
16957 #else
16958@@ -312,6 +382,7 @@ default_entry:
16959 orl %edx,%eax
16960 movl %eax,%cr4
16961
16962+#ifdef CONFIG_X86_PAE
16963 testb $X86_CR4_PAE, %al # check if PAE is enabled
16964 jz 6f
16965
16966@@ -340,6 +411,9 @@ default_entry:
16967 /* Make changes effective */
16968 wrmsr
16969
16970+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
16971+#endif
16972+
16973 6:
16974
16975 /*
16976@@ -443,7 +517,7 @@ is386: movl $2,%ecx # set MP
16977 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
16978 movl %eax,%ss # after changing gdt.
16979
16980- movl $(__USER_DS),%eax # DS/ES contains default USER segment
16981+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
16982 movl %eax,%ds
16983 movl %eax,%es
16984
16985@@ -457,15 +531,22 @@ is386: movl $2,%ecx # set MP
16986 */
16987 cmpb $0,ready
16988 jne 1f
16989- movl $gdt_page,%eax
16990+ movl $cpu_gdt_table,%eax
16991 movl $stack_canary,%ecx
16992+#ifdef CONFIG_SMP
16993+ addl $__per_cpu_load,%ecx
16994+#endif
16995 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
16996 shrl $16, %ecx
16997 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
16998 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
16999 1:
17000-#endif
17001 movl $(__KERNEL_STACK_CANARY),%eax
17002+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17003+ movl $(__USER_DS),%eax
17004+#else
17005+ xorl %eax,%eax
17006+#endif
17007 movl %eax,%gs
17008
17009 xorl %eax,%eax # Clear LDT
17010@@ -558,22 +639,22 @@ early_page_fault:
17011 jmp early_fault
17012
17013 early_fault:
17014- cld
17015 #ifdef CONFIG_PRINTK
17016+ cmpl $1,%ss:early_recursion_flag
17017+ je hlt_loop
17018+ incl %ss:early_recursion_flag
17019+ cld
17020 pusha
17021 movl $(__KERNEL_DS),%eax
17022 movl %eax,%ds
17023 movl %eax,%es
17024- cmpl $2,early_recursion_flag
17025- je hlt_loop
17026- incl early_recursion_flag
17027 movl %cr2,%eax
17028 pushl %eax
17029 pushl %edx /* trapno */
17030 pushl $fault_msg
17031 call printk
17032+; call dump_stack
17033 #endif
17034- call dump_stack
17035 hlt_loop:
17036 hlt
17037 jmp hlt_loop
17038@@ -581,8 +662,11 @@ hlt_loop:
17039 /* This is the default interrupt "handler" :-) */
17040 ALIGN
17041 ignore_int:
17042- cld
17043 #ifdef CONFIG_PRINTK
17044+ cmpl $2,%ss:early_recursion_flag
17045+ je hlt_loop
17046+ incl %ss:early_recursion_flag
17047+ cld
17048 pushl %eax
17049 pushl %ecx
17050 pushl %edx
17051@@ -591,9 +675,6 @@ ignore_int:
17052 movl $(__KERNEL_DS),%eax
17053 movl %eax,%ds
17054 movl %eax,%es
17055- cmpl $2,early_recursion_flag
17056- je hlt_loop
17057- incl early_recursion_flag
17058 pushl 16(%esp)
17059 pushl 24(%esp)
17060 pushl 32(%esp)
17061@@ -622,29 +703,43 @@ ENTRY(initial_code)
17062 /*
17063 * BSS section
17064 */
17065-__PAGE_ALIGNED_BSS
17066- .align PAGE_SIZE
17067 #ifdef CONFIG_X86_PAE
17068+.section .initial_pg_pmd,"a",@progbits
17069 initial_pg_pmd:
17070 .fill 1024*KPMDS,4,0
17071 #else
17072+.section .initial_page_table,"a",@progbits
17073 ENTRY(initial_page_table)
17074 .fill 1024,4,0
17075 #endif
17076+.section .initial_pg_fixmap,"a",@progbits
17077 initial_pg_fixmap:
17078 .fill 1024,4,0
17079+.section .empty_zero_page,"a",@progbits
17080 ENTRY(empty_zero_page)
17081 .fill 4096,1,0
17082+.section .swapper_pg_dir,"a",@progbits
17083 ENTRY(swapper_pg_dir)
17084+#ifdef CONFIG_X86_PAE
17085+ .fill 4,8,0
17086+#else
17087 .fill 1024,4,0
17088+#endif
17089+
17090+/*
17091+ * The IDT has to be page-aligned to simplify the Pentium
17092+ * F0 0F bug workaround.. We have a special link segment
17093+ * for this.
17094+ */
17095+.section .idt,"a",@progbits
17096+ENTRY(idt_table)
17097+ .fill 256,8,0
17098
17099 /*
17100 * This starts the data section.
17101 */
17102 #ifdef CONFIG_X86_PAE
17103-__PAGE_ALIGNED_DATA
17104- /* Page-aligned for the benefit of paravirt? */
17105- .align PAGE_SIZE
17106+.section .initial_page_table,"a",@progbits
17107 ENTRY(initial_page_table)
17108 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17109 # if KPMDS == 3
17110@@ -663,18 +758,27 @@ ENTRY(initial_page_table)
17111 # error "Kernel PMDs should be 1, 2 or 3"
17112 # endif
17113 .align PAGE_SIZE /* needs to be page-sized too */
17114+
17115+#ifdef CONFIG_PAX_PER_CPU_PGD
17116+ENTRY(cpu_pgd)
17117+ .rept NR_CPUS
17118+ .fill 4,8,0
17119+ .endr
17120+#endif
17121+
17122 #endif
17123
17124 .data
17125 .balign 4
17126 ENTRY(stack_start)
17127- .long init_thread_union+THREAD_SIZE
17128+ .long init_thread_union+THREAD_SIZE-8
17129
17130+ready: .byte 0
17131+
17132+.section .rodata,"a",@progbits
17133 early_recursion_flag:
17134 .long 0
17135
17136-ready: .byte 0
17137-
17138 int_msg:
17139 .asciz "Unknown interrupt or fault at: %p %p %p\n"
17140
17141@@ -707,7 +811,7 @@ fault_msg:
17142 .word 0 # 32 bit align gdt_desc.address
17143 boot_gdt_descr:
17144 .word __BOOT_DS+7
17145- .long boot_gdt - __PAGE_OFFSET
17146+ .long pa(boot_gdt)
17147
17148 .word 0 # 32-bit align idt_desc.address
17149 idt_descr:
17150@@ -718,7 +822,7 @@ idt_descr:
17151 .word 0 # 32 bit align gdt_desc.address
17152 ENTRY(early_gdt_descr)
17153 .word GDT_ENTRIES*8-1
17154- .long gdt_page /* Overwritten for secondary CPUs */
17155+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
17156
17157 /*
17158 * The boot_gdt must mirror the equivalent in setup.S and is
17159@@ -727,5 +831,65 @@ ENTRY(early_gdt_descr)
17160 .align L1_CACHE_BYTES
17161 ENTRY(boot_gdt)
17162 .fill GDT_ENTRY_BOOT_CS,8,0
17163- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17164- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17165+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17166+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17167+
17168+ .align PAGE_SIZE_asm
17169+ENTRY(cpu_gdt_table)
17170+ .rept NR_CPUS
17171+ .quad 0x0000000000000000 /* NULL descriptor */
17172+ .quad 0x0000000000000000 /* 0x0b reserved */
17173+ .quad 0x0000000000000000 /* 0x13 reserved */
17174+ .quad 0x0000000000000000 /* 0x1b reserved */
17175+
17176+#ifdef CONFIG_PAX_KERNEXEC
17177+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17178+#else
17179+ .quad 0x0000000000000000 /* 0x20 unused */
17180+#endif
17181+
17182+ .quad 0x0000000000000000 /* 0x28 unused */
17183+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17184+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17185+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17186+ .quad 0x0000000000000000 /* 0x4b reserved */
17187+ .quad 0x0000000000000000 /* 0x53 reserved */
17188+ .quad 0x0000000000000000 /* 0x5b reserved */
17189+
17190+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17191+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17192+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17193+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17194+
17195+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17196+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17197+
17198+ /*
17199+ * Segments used for calling PnP BIOS have byte granularity.
17200+ * The code segments and data segments have fixed 64k limits,
17201+ * the transfer segment sizes are set at run time.
17202+ */
17203+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
17204+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
17205+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
17206+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
17207+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
17208+
17209+ /*
17210+ * The APM segments have byte granularity and their bases
17211+ * are set at run time. All have 64k limits.
17212+ */
17213+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17214+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17215+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
17216+
17217+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17218+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17219+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17220+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17221+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17222+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17223+
17224+ /* Be sure this is zeroed to avoid false validations in Xen */
17225+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17226+ .endr
17227diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17228index 40f4eb3..6d24d9d 100644
17229--- a/arch/x86/kernel/head_64.S
17230+++ b/arch/x86/kernel/head_64.S
17231@@ -19,6 +19,8 @@
17232 #include <asm/cache.h>
17233 #include <asm/processor-flags.h>
17234 #include <asm/percpu.h>
17235+#include <asm/cpufeature.h>
17236+#include <asm/alternative-asm.h>
17237
17238 #ifdef CONFIG_PARAVIRT
17239 #include <asm/asm-offsets.h>
17240@@ -38,6 +40,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17241 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17242 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17243 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17244+L4_VMALLOC_START = pgd_index(VMALLOC_START)
17245+L3_VMALLOC_START = pud_index(VMALLOC_START)
17246+L4_VMALLOC_END = pgd_index(VMALLOC_END)
17247+L3_VMALLOC_END = pud_index(VMALLOC_END)
17248+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17249+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17250
17251 .text
17252 __HEAD
17253@@ -85,35 +93,23 @@ startup_64:
17254 */
17255 addq %rbp, init_level4_pgt + 0(%rip)
17256 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17257+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17258+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17259+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17260 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17261
17262 addq %rbp, level3_ident_pgt + 0(%rip)
17263+#ifndef CONFIG_XEN
17264+ addq %rbp, level3_ident_pgt + 8(%rip)
17265+#endif
17266
17267- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17268- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17269+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17270+
17271+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17272+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17273
17274 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17275-
17276- /* Add an Identity mapping if I am above 1G */
17277- leaq _text(%rip), %rdi
17278- andq $PMD_PAGE_MASK, %rdi
17279-
17280- movq %rdi, %rax
17281- shrq $PUD_SHIFT, %rax
17282- andq $(PTRS_PER_PUD - 1), %rax
17283- jz ident_complete
17284-
17285- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17286- leaq level3_ident_pgt(%rip), %rbx
17287- movq %rdx, 0(%rbx, %rax, 8)
17288-
17289- movq %rdi, %rax
17290- shrq $PMD_SHIFT, %rax
17291- andq $(PTRS_PER_PMD - 1), %rax
17292- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17293- leaq level2_spare_pgt(%rip), %rbx
17294- movq %rdx, 0(%rbx, %rax, 8)
17295-ident_complete:
17296+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17297
17298 /*
17299 * Fixup the kernel text+data virtual addresses. Note that
17300@@ -160,8 +156,8 @@ ENTRY(secondary_startup_64)
17301 * after the boot processor executes this code.
17302 */
17303
17304- /* Enable PAE mode and PGE */
17305- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17306+ /* Enable PAE mode and PSE/PGE */
17307+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17308 movq %rax, %cr4
17309
17310 /* Setup early boot stage 4 level pagetables. */
17311@@ -183,9 +179,17 @@ ENTRY(secondary_startup_64)
17312 movl $MSR_EFER, %ecx
17313 rdmsr
17314 btsl $_EFER_SCE, %eax /* Enable System Call */
17315- btl $20,%edi /* No Execute supported? */
17316+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17317 jnc 1f
17318 btsl $_EFER_NX, %eax
17319+ leaq init_level4_pgt(%rip), %rdi
17320+#ifndef CONFIG_EFI
17321+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17322+#endif
17323+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17324+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17325+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17326+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17327 1: wrmsr /* Make changes effective */
17328
17329 /* Setup cr0 */
17330@@ -247,6 +251,7 @@ ENTRY(secondary_startup_64)
17331 * jump. In addition we need to ensure %cs is set so we make this
17332 * a far return.
17333 */
17334+ pax_set_fptr_mask
17335 movq initial_code(%rip),%rax
17336 pushq $0 # fake return address to stop unwinder
17337 pushq $__KERNEL_CS # set correct cs
17338@@ -269,7 +274,7 @@ ENTRY(secondary_startup_64)
17339 bad_address:
17340 jmp bad_address
17341
17342- .section ".init.text","ax"
17343+ __INIT
17344 #ifdef CONFIG_EARLY_PRINTK
17345 .globl early_idt_handlers
17346 early_idt_handlers:
17347@@ -314,18 +319,23 @@ ENTRY(early_idt_handler)
17348 #endif /* EARLY_PRINTK */
17349 1: hlt
17350 jmp 1b
17351+ .previous
17352
17353 #ifdef CONFIG_EARLY_PRINTK
17354+ __INITDATA
17355 early_recursion_flag:
17356 .long 0
17357+ .previous
17358
17359+ .section .rodata,"a",@progbits
17360 early_idt_msg:
17361 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17362 early_idt_ripmsg:
17363 .asciz "RIP %s\n"
17364+ .previous
17365 #endif /* CONFIG_EARLY_PRINTK */
17366- .previous
17367
17368+ .section .rodata,"a",@progbits
17369 #define NEXT_PAGE(name) \
17370 .balign PAGE_SIZE; \
17371 ENTRY(name)
17372@@ -338,7 +348,6 @@ ENTRY(name)
17373 i = i + 1 ; \
17374 .endr
17375
17376- .data
17377 /*
17378 * This default setting generates an ident mapping at address 0x100000
17379 * and a mapping for the kernel that precisely maps virtual address
17380@@ -349,13 +358,41 @@ NEXT_PAGE(init_level4_pgt)
17381 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17382 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17383 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17384+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
17385+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17386+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
17387+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17388+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17389+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17390 .org init_level4_pgt + L4_START_KERNEL*8, 0
17391 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17392 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17393
17394+#ifdef CONFIG_PAX_PER_CPU_PGD
17395+NEXT_PAGE(cpu_pgd)
17396+ .rept NR_CPUS
17397+ .fill 512,8,0
17398+ .endr
17399+#endif
17400+
17401 NEXT_PAGE(level3_ident_pgt)
17402 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17403+#ifdef CONFIG_XEN
17404 .fill 511,8,0
17405+#else
17406+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17407+ .fill 510,8,0
17408+#endif
17409+
17410+NEXT_PAGE(level3_vmalloc_start_pgt)
17411+ .fill 512,8,0
17412+
17413+NEXT_PAGE(level3_vmalloc_end_pgt)
17414+ .fill 512,8,0
17415+
17416+NEXT_PAGE(level3_vmemmap_pgt)
17417+ .fill L3_VMEMMAP_START,8,0
17418+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17419
17420 NEXT_PAGE(level3_kernel_pgt)
17421 .fill L3_START_KERNEL,8,0
17422@@ -363,20 +400,23 @@ NEXT_PAGE(level3_kernel_pgt)
17423 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17424 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17425
17426+NEXT_PAGE(level2_vmemmap_pgt)
17427+ .fill 512,8,0
17428+
17429 NEXT_PAGE(level2_fixmap_pgt)
17430- .fill 506,8,0
17431- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17432- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17433- .fill 5,8,0
17434+ .fill 507,8,0
17435+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17436+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17437+ .fill 4,8,0
17438
17439-NEXT_PAGE(level1_fixmap_pgt)
17440+NEXT_PAGE(level1_vsyscall_pgt)
17441 .fill 512,8,0
17442
17443-NEXT_PAGE(level2_ident_pgt)
17444- /* Since I easily can, map the first 1G.
17445+ /* Since I easily can, map the first 2G.
17446 * Don't set NX because code runs from these pages.
17447 */
17448- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17449+NEXT_PAGE(level2_ident_pgt)
17450+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17451
17452 NEXT_PAGE(level2_kernel_pgt)
17453 /*
17454@@ -389,37 +429,59 @@ NEXT_PAGE(level2_kernel_pgt)
17455 * If you want to increase this then increase MODULES_VADDR
17456 * too.)
17457 */
17458- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17459- KERNEL_IMAGE_SIZE/PMD_SIZE)
17460-
17461-NEXT_PAGE(level2_spare_pgt)
17462- .fill 512, 8, 0
17463+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17464
17465 #undef PMDS
17466 #undef NEXT_PAGE
17467
17468- .data
17469+ .align PAGE_SIZE
17470+ENTRY(cpu_gdt_table)
17471+ .rept NR_CPUS
17472+ .quad 0x0000000000000000 /* NULL descriptor */
17473+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17474+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
17475+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
17476+ .quad 0x00cffb000000ffff /* __USER32_CS */
17477+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17478+ .quad 0x00affb000000ffff /* __USER_CS */
17479+
17480+#ifdef CONFIG_PAX_KERNEXEC
17481+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17482+#else
17483+ .quad 0x0 /* unused */
17484+#endif
17485+
17486+ .quad 0,0 /* TSS */
17487+ .quad 0,0 /* LDT */
17488+ .quad 0,0,0 /* three TLS descriptors */
17489+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
17490+ /* asm/segment.h:GDT_ENTRIES must match this */
17491+
17492+ /* zero the remaining page */
17493+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17494+ .endr
17495+
17496 .align 16
17497 .globl early_gdt_descr
17498 early_gdt_descr:
17499 .word GDT_ENTRIES*8-1
17500 early_gdt_descr_base:
17501- .quad INIT_PER_CPU_VAR(gdt_page)
17502+ .quad cpu_gdt_table
17503
17504 ENTRY(phys_base)
17505 /* This must match the first entry in level2_kernel_pgt */
17506 .quad 0x0000000000000000
17507
17508 #include "../../x86/xen/xen-head.S"
17509-
17510- .section .bss, "aw", @nobits
17511+
17512+ .section .rodata,"a",@progbits
17513 .align L1_CACHE_BYTES
17514 ENTRY(idt_table)
17515- .skip IDT_ENTRIES * 16
17516+ .fill 512,8,0
17517
17518 .align L1_CACHE_BYTES
17519 ENTRY(nmi_idt_table)
17520- .skip IDT_ENTRIES * 16
17521+ .fill 512,8,0
17522
17523 __PAGE_ALIGNED_BSS
17524 .align PAGE_SIZE
17525diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17526index 9c3bd4a..e1d9b35 100644
17527--- a/arch/x86/kernel/i386_ksyms_32.c
17528+++ b/arch/x86/kernel/i386_ksyms_32.c
17529@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17530 EXPORT_SYMBOL(cmpxchg8b_emu);
17531 #endif
17532
17533+EXPORT_SYMBOL_GPL(cpu_gdt_table);
17534+
17535 /* Networking helper routines. */
17536 EXPORT_SYMBOL(csum_partial_copy_generic);
17537+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17538+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17539
17540 EXPORT_SYMBOL(__get_user_1);
17541 EXPORT_SYMBOL(__get_user_2);
17542@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17543
17544 EXPORT_SYMBOL(csum_partial);
17545 EXPORT_SYMBOL(empty_zero_page);
17546+
17547+#ifdef CONFIG_PAX_KERNEXEC
17548+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17549+#endif
17550diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17551index 2d6e649..df6e1af 100644
17552--- a/arch/x86/kernel/i387.c
17553+++ b/arch/x86/kernel/i387.c
17554@@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17555 static inline bool interrupted_user_mode(void)
17556 {
17557 struct pt_regs *regs = get_irq_regs();
17558- return regs && user_mode_vm(regs);
17559+ return regs && user_mode(regs);
17560 }
17561
17562 /*
17563diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17564index 36d1853..bf25736 100644
17565--- a/arch/x86/kernel/i8259.c
17566+++ b/arch/x86/kernel/i8259.c
17567@@ -209,7 +209,7 @@ spurious_8259A_irq:
17568 "spurious 8259A interrupt: IRQ%d.\n", irq);
17569 spurious_irq_mask |= irqmask;
17570 }
17571- atomic_inc(&irq_err_count);
17572+ atomic_inc_unchecked(&irq_err_count);
17573 /*
17574 * Theoretically we do not have to handle this IRQ,
17575 * but in Linux this does not cause problems and is
17576diff --git a/arch/x86/kernel/init_task.c b/arch/x86/kernel/init_task.c
17577index 43e9ccf..44ccf6f 100644
17578--- a/arch/x86/kernel/init_task.c
17579+++ b/arch/x86/kernel/init_task.c
17580@@ -20,8 +20,7 @@ static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
17581 * way process stacks are handled. This is done by having a special
17582 * "init_task" linker map entry..
17583 */
17584-union thread_union init_thread_union __init_task_data =
17585- { INIT_THREAD_INFO(init_task) };
17586+union thread_union init_thread_union __init_task_data;
17587
17588 /*
17589 * Initial task structure.
17590@@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
17591 * section. Since TSS's are completely CPU-local, we want them
17592 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
17593 */
17594-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
17595-
17596+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
17597+EXPORT_SYMBOL(init_tss);
17598diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17599index 8c96897..be66bfa 100644
17600--- a/arch/x86/kernel/ioport.c
17601+++ b/arch/x86/kernel/ioport.c
17602@@ -6,6 +6,7 @@
17603 #include <linux/sched.h>
17604 #include <linux/kernel.h>
17605 #include <linux/capability.h>
17606+#include <linux/security.h>
17607 #include <linux/errno.h>
17608 #include <linux/types.h>
17609 #include <linux/ioport.h>
17610@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17611
17612 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17613 return -EINVAL;
17614+#ifdef CONFIG_GRKERNSEC_IO
17615+ if (turn_on && grsec_disable_privio) {
17616+ gr_handle_ioperm();
17617+ return -EPERM;
17618+ }
17619+#endif
17620 if (turn_on && !capable(CAP_SYS_RAWIO))
17621 return -EPERM;
17622
17623@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17624 * because the ->io_bitmap_max value must match the bitmap
17625 * contents:
17626 */
17627- tss = &per_cpu(init_tss, get_cpu());
17628+ tss = init_tss + get_cpu();
17629
17630 if (turn_on)
17631 bitmap_clear(t->io_bitmap_ptr, from, num);
17632@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17633 return -EINVAL;
17634 /* Trying to gain more privileges? */
17635 if (level > old) {
17636+#ifdef CONFIG_GRKERNSEC_IO
17637+ if (grsec_disable_privio) {
17638+ gr_handle_iopl();
17639+ return -EPERM;
17640+ }
17641+#endif
17642 if (!capable(CAP_SYS_RAWIO))
17643 return -EPERM;
17644 }
17645diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17646index 3dafc60..aa8e9c4 100644
17647--- a/arch/x86/kernel/irq.c
17648+++ b/arch/x86/kernel/irq.c
17649@@ -18,7 +18,7 @@
17650 #include <asm/mce.h>
17651 #include <asm/hw_irq.h>
17652
17653-atomic_t irq_err_count;
17654+atomic_unchecked_t irq_err_count;
17655
17656 /* Function pointer for generic interrupt vector handling */
17657 void (*x86_platform_ipi_callback)(void) = NULL;
17658@@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17659 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17660 seq_printf(p, " Machine check polls\n");
17661 #endif
17662- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17663+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17664 #if defined(CONFIG_X86_IO_APIC)
17665- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17666+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17667 #endif
17668 return 0;
17669 }
17670@@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17671
17672 u64 arch_irq_stat(void)
17673 {
17674- u64 sum = atomic_read(&irq_err_count);
17675+ u64 sum = atomic_read_unchecked(&irq_err_count);
17676
17677 #ifdef CONFIG_X86_IO_APIC
17678- sum += atomic_read(&irq_mis_count);
17679+ sum += atomic_read_unchecked(&irq_mis_count);
17680 #endif
17681 return sum;
17682 }
17683diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17684index 58b7f27..e112d08 100644
17685--- a/arch/x86/kernel/irq_32.c
17686+++ b/arch/x86/kernel/irq_32.c
17687@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17688 __asm__ __volatile__("andl %%esp,%0" :
17689 "=r" (sp) : "0" (THREAD_SIZE - 1));
17690
17691- return sp < (sizeof(struct thread_info) + STACK_WARN);
17692+ return sp < STACK_WARN;
17693 }
17694
17695 static void print_stack_overflow(void)
17696@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17697 * per-CPU IRQ handling contexts (thread information and stack)
17698 */
17699 union irq_ctx {
17700- struct thread_info tinfo;
17701- u32 stack[THREAD_SIZE/sizeof(u32)];
17702+ unsigned long previous_esp;
17703+ u32 stack[THREAD_SIZE/sizeof(u32)];
17704 } __attribute__((aligned(THREAD_SIZE)));
17705
17706 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17707@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17708 static inline int
17709 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17710 {
17711- union irq_ctx *curctx, *irqctx;
17712+ union irq_ctx *irqctx;
17713 u32 *isp, arg1, arg2;
17714
17715- curctx = (union irq_ctx *) current_thread_info();
17716 irqctx = __this_cpu_read(hardirq_ctx);
17717
17718 /*
17719@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17720 * handler) we can't do that and just have to keep using the
17721 * current stack (which is the irq stack already after all)
17722 */
17723- if (unlikely(curctx == irqctx))
17724+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17725 return 0;
17726
17727 /* build the stack frame on the IRQ stack */
17728- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17729- irqctx->tinfo.task = curctx->tinfo.task;
17730- irqctx->tinfo.previous_esp = current_stack_pointer;
17731+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17732+ irqctx->previous_esp = current_stack_pointer;
17733
17734- /* Copy the preempt_count so that the [soft]irq checks work. */
17735- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17736+#ifdef CONFIG_PAX_MEMORY_UDEREF
17737+ __set_fs(MAKE_MM_SEG(0));
17738+#endif
17739
17740 if (unlikely(overflow))
17741 call_on_stack(print_stack_overflow, isp);
17742@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17743 : "0" (irq), "1" (desc), "2" (isp),
17744 "D" (desc->handle_irq)
17745 : "memory", "cc", "ecx");
17746+
17747+#ifdef CONFIG_PAX_MEMORY_UDEREF
17748+ __set_fs(current_thread_info()->addr_limit);
17749+#endif
17750+
17751 return 1;
17752 }
17753
17754@@ -121,29 +125,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17755 */
17756 void __cpuinit irq_ctx_init(int cpu)
17757 {
17758- union irq_ctx *irqctx;
17759-
17760 if (per_cpu(hardirq_ctx, cpu))
17761 return;
17762
17763- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17764- THREAD_FLAGS,
17765- THREAD_ORDER));
17766- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17767- irqctx->tinfo.cpu = cpu;
17768- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17769- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17770-
17771- per_cpu(hardirq_ctx, cpu) = irqctx;
17772-
17773- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17774- THREAD_FLAGS,
17775- THREAD_ORDER));
17776- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17777- irqctx->tinfo.cpu = cpu;
17778- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17779-
17780- per_cpu(softirq_ctx, cpu) = irqctx;
17781+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17782+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17783
17784 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17785 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17786@@ -152,7 +138,6 @@ void __cpuinit irq_ctx_init(int cpu)
17787 asmlinkage void do_softirq(void)
17788 {
17789 unsigned long flags;
17790- struct thread_info *curctx;
17791 union irq_ctx *irqctx;
17792 u32 *isp;
17793
17794@@ -162,15 +147,22 @@ asmlinkage void do_softirq(void)
17795 local_irq_save(flags);
17796
17797 if (local_softirq_pending()) {
17798- curctx = current_thread_info();
17799 irqctx = __this_cpu_read(softirq_ctx);
17800- irqctx->tinfo.task = curctx->task;
17801- irqctx->tinfo.previous_esp = current_stack_pointer;
17802+ irqctx->previous_esp = current_stack_pointer;
17803
17804 /* build the stack frame on the softirq stack */
17805- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17806+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17807+
17808+#ifdef CONFIG_PAX_MEMORY_UDEREF
17809+ __set_fs(MAKE_MM_SEG(0));
17810+#endif
17811
17812 call_on_stack(__do_softirq, isp);
17813+
17814+#ifdef CONFIG_PAX_MEMORY_UDEREF
17815+ __set_fs(current_thread_info()->addr_limit);
17816+#endif
17817+
17818 /*
17819 * Shouldn't happen, we returned above if in_interrupt():
17820 */
17821@@ -191,7 +183,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17822 if (unlikely(!desc))
17823 return false;
17824
17825- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17826+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17827 if (unlikely(overflow))
17828 print_stack_overflow();
17829 desc->handle_irq(irq, desc);
17830diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17831index d04d3ec..ea4b374 100644
17832--- a/arch/x86/kernel/irq_64.c
17833+++ b/arch/x86/kernel/irq_64.c
17834@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17835 u64 estack_top, estack_bottom;
17836 u64 curbase = (u64)task_stack_page(current);
17837
17838- if (user_mode_vm(regs))
17839+ if (user_mode(regs))
17840 return;
17841
17842 if (regs->sp >= curbase + sizeof(struct thread_info) +
17843diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17844index 1d5d31e..ab846ed 100644
17845--- a/arch/x86/kernel/kdebugfs.c
17846+++ b/arch/x86/kernel/kdebugfs.c
17847@@ -28,6 +28,8 @@ struct setup_data_node {
17848 };
17849
17850 static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17851+ size_t count, loff_t *ppos) __size_overflow(3);
17852+static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17853 size_t count, loff_t *ppos)
17854 {
17855 struct setup_data_node *node = file->private_data;
17856diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17857index 8bfb614..2b3b35f 100644
17858--- a/arch/x86/kernel/kgdb.c
17859+++ b/arch/x86/kernel/kgdb.c
17860@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17861 #ifdef CONFIG_X86_32
17862 switch (regno) {
17863 case GDB_SS:
17864- if (!user_mode_vm(regs))
17865+ if (!user_mode(regs))
17866 *(unsigned long *)mem = __KERNEL_DS;
17867 break;
17868 case GDB_SP:
17869- if (!user_mode_vm(regs))
17870+ if (!user_mode(regs))
17871 *(unsigned long *)mem = kernel_stack_pointer(regs);
17872 break;
17873 case GDB_GS:
17874@@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17875 case 'k':
17876 /* clear the trace bit */
17877 linux_regs->flags &= ~X86_EFLAGS_TF;
17878- atomic_set(&kgdb_cpu_doing_single_step, -1);
17879+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17880
17881 /* set the trace bit if we're stepping */
17882 if (remcomInBuffer[0] == 's') {
17883 linux_regs->flags |= X86_EFLAGS_TF;
17884- atomic_set(&kgdb_cpu_doing_single_step,
17885+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17886 raw_smp_processor_id());
17887 }
17888
17889@@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17890
17891 switch (cmd) {
17892 case DIE_DEBUG:
17893- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17894+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17895 if (user_mode(regs))
17896 return single_step_cont(regs, args);
17897 break;
17898diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17899index c5e410e..da6aaf9 100644
17900--- a/arch/x86/kernel/kprobes-opt.c
17901+++ b/arch/x86/kernel/kprobes-opt.c
17902@@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17903 * Verify if the address gap is in 2GB range, because this uses
17904 * a relative jump.
17905 */
17906- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17907+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17908 if (abs(rel) > 0x7fffffff)
17909 return -ERANGE;
17910
17911@@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17912 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17913
17914 /* Set probe function call */
17915- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17916+ synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17917
17918 /* Set returning jmp instruction at the tail of out-of-line buffer */
17919 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17920- (u8 *)op->kp.addr + op->optinsn.size);
17921+ (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17922
17923 flush_icache_range((unsigned long) buf,
17924 (unsigned long) buf + TMPL_END_IDX +
17925@@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17926 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17927
17928 /* Backup instructions which will be replaced by jump address */
17929- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17930+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17931 RELATIVE_ADDR_SIZE);
17932
17933 insn_buf[0] = RELATIVEJUMP_OPCODE;
17934diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17935index e213fc8..d783ba4 100644
17936--- a/arch/x86/kernel/kprobes.c
17937+++ b/arch/x86/kernel/kprobes.c
17938@@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17939 } __attribute__((packed)) *insn;
17940
17941 insn = (struct __arch_relative_insn *)from;
17942+
17943+ pax_open_kernel();
17944 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17945 insn->op = op;
17946+ pax_close_kernel();
17947 }
17948
17949 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17950@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
17951 kprobe_opcode_t opcode;
17952 kprobe_opcode_t *orig_opcodes = opcodes;
17953
17954- if (search_exception_tables((unsigned long)opcodes))
17955+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17956 return 0; /* Page fault may occur on this address. */
17957
17958 retry:
17959@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17960 /* Another subsystem puts a breakpoint, failed to recover */
17961 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
17962 return 0;
17963+ pax_open_kernel();
17964 memcpy(dest, insn.kaddr, insn.length);
17965+ pax_close_kernel();
17966
17967 #ifdef CONFIG_X86_64
17968 if (insn_rip_relative(&insn)) {
17969@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17970 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
17971 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
17972 disp = (u8 *) dest + insn_offset_displacement(&insn);
17973+ pax_open_kernel();
17974 *(s32 *) disp = (s32) newdisp;
17975+ pax_close_kernel();
17976 }
17977 #endif
17978 return insn.length;
17979@@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17980 * nor set current_kprobe, because it doesn't use single
17981 * stepping.
17982 */
17983- regs->ip = (unsigned long)p->ainsn.insn;
17984+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17985 preempt_enable_no_resched();
17986 return;
17987 }
17988@@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17989 if (p->opcode == BREAKPOINT_INSTRUCTION)
17990 regs->ip = (unsigned long)p->addr;
17991 else
17992- regs->ip = (unsigned long)p->ainsn.insn;
17993+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17994 }
17995
17996 /*
17997@@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
17998 setup_singlestep(p, regs, kcb, 0);
17999 return 1;
18000 }
18001- } else if (*addr != BREAKPOINT_INSTRUCTION) {
18002+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
18003 /*
18004 * The breakpoint instruction was removed right
18005 * after we hit it. Another cpu has removed
18006@@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
18007 " movq %rax, 152(%rsp)\n"
18008 RESTORE_REGS_STRING
18009 " popfq\n"
18010+#ifdef KERNEXEC_PLUGIN
18011+ " btsq $63,(%rsp)\n"
18012+#endif
18013 #else
18014 " pushf\n"
18015 SAVE_REGS_STRING
18016@@ -765,7 +775,7 @@ static void __kprobes
18017 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
18018 {
18019 unsigned long *tos = stack_addr(regs);
18020- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
18021+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
18022 unsigned long orig_ip = (unsigned long)p->addr;
18023 kprobe_opcode_t *insn = p->ainsn.insn;
18024
18025@@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
18026 struct die_args *args = data;
18027 int ret = NOTIFY_DONE;
18028
18029- if (args->regs && user_mode_vm(args->regs))
18030+ if (args->regs && user_mode(args->regs))
18031 return ret;
18032
18033 switch (val) {
18034diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
18035index ebc9873..1b9724b 100644
18036--- a/arch/x86/kernel/ldt.c
18037+++ b/arch/x86/kernel/ldt.c
18038@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
18039 if (reload) {
18040 #ifdef CONFIG_SMP
18041 preempt_disable();
18042- load_LDT(pc);
18043+ load_LDT_nolock(pc);
18044 if (!cpumask_equal(mm_cpumask(current->mm),
18045 cpumask_of(smp_processor_id())))
18046 smp_call_function(flush_ldt, current->mm, 1);
18047 preempt_enable();
18048 #else
18049- load_LDT(pc);
18050+ load_LDT_nolock(pc);
18051 #endif
18052 }
18053 if (oldsize) {
18054@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
18055 return err;
18056
18057 for (i = 0; i < old->size; i++)
18058- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
18059+ write_ldt_entry(new->ldt, i, old->ldt + i);
18060 return 0;
18061 }
18062
18063@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
18064 retval = copy_ldt(&mm->context, &old_mm->context);
18065 mutex_unlock(&old_mm->context.lock);
18066 }
18067+
18068+ if (tsk == current) {
18069+ mm->context.vdso = 0;
18070+
18071+#ifdef CONFIG_X86_32
18072+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18073+ mm->context.user_cs_base = 0UL;
18074+ mm->context.user_cs_limit = ~0UL;
18075+
18076+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18077+ cpus_clear(mm->context.cpu_user_cs_mask);
18078+#endif
18079+
18080+#endif
18081+#endif
18082+
18083+ }
18084+
18085 return retval;
18086 }
18087
18088@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18089 }
18090 }
18091
18092+#ifdef CONFIG_PAX_SEGMEXEC
18093+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18094+ error = -EINVAL;
18095+ goto out_unlock;
18096+ }
18097+#endif
18098+
18099 fill_ldt(&ldt, &ldt_info);
18100 if (oldmode)
18101 ldt.avl = 0;
18102diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18103index 5b19e4d..6476a76 100644
18104--- a/arch/x86/kernel/machine_kexec_32.c
18105+++ b/arch/x86/kernel/machine_kexec_32.c
18106@@ -26,7 +26,7 @@
18107 #include <asm/cacheflush.h>
18108 #include <asm/debugreg.h>
18109
18110-static void set_idt(void *newidt, __u16 limit)
18111+static void set_idt(struct desc_struct *newidt, __u16 limit)
18112 {
18113 struct desc_ptr curidt;
18114
18115@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
18116 }
18117
18118
18119-static void set_gdt(void *newgdt, __u16 limit)
18120+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18121 {
18122 struct desc_ptr curgdt;
18123
18124@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
18125 }
18126
18127 control_page = page_address(image->control_code_page);
18128- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18129+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18130
18131 relocate_kernel_ptr = control_page;
18132 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18133diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18134index 0327e2b..e43737b 100644
18135--- a/arch/x86/kernel/microcode_intel.c
18136+++ b/arch/x86/kernel/microcode_intel.c
18137@@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18138
18139 static int get_ucode_user(void *to, const void *from, size_t n)
18140 {
18141- return copy_from_user(to, from, n);
18142+ return copy_from_user(to, (const void __force_user *)from, n);
18143 }
18144
18145 static enum ucode_state
18146 request_microcode_user(int cpu, const void __user *buf, size_t size)
18147 {
18148- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18149+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18150 }
18151
18152 static void microcode_fini_cpu(int cpu)
18153diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18154index f21fd94..61565cd 100644
18155--- a/arch/x86/kernel/module.c
18156+++ b/arch/x86/kernel/module.c
18157@@ -35,15 +35,60 @@
18158 #define DEBUGP(fmt...)
18159 #endif
18160
18161-void *module_alloc(unsigned long size)
18162+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18163 {
18164- if (PAGE_ALIGN(size) > MODULES_LEN)
18165+ if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18166 return NULL;
18167 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18168- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18169+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18170 -1, __builtin_return_address(0));
18171 }
18172
18173+void *module_alloc(unsigned long size)
18174+{
18175+
18176+#ifdef CONFIG_PAX_KERNEXEC
18177+ return __module_alloc(size, PAGE_KERNEL);
18178+#else
18179+ return __module_alloc(size, PAGE_KERNEL_EXEC);
18180+#endif
18181+
18182+}
18183+
18184+#ifdef CONFIG_PAX_KERNEXEC
18185+#ifdef CONFIG_X86_32
18186+void *module_alloc_exec(unsigned long size)
18187+{
18188+ struct vm_struct *area;
18189+
18190+ if (size == 0)
18191+ return NULL;
18192+
18193+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18194+ return area ? area->addr : NULL;
18195+}
18196+EXPORT_SYMBOL(module_alloc_exec);
18197+
18198+void module_free_exec(struct module *mod, void *module_region)
18199+{
18200+ vunmap(module_region);
18201+}
18202+EXPORT_SYMBOL(module_free_exec);
18203+#else
18204+void module_free_exec(struct module *mod, void *module_region)
18205+{
18206+ module_free(mod, module_region);
18207+}
18208+EXPORT_SYMBOL(module_free_exec);
18209+
18210+void *module_alloc_exec(unsigned long size)
18211+{
18212+ return __module_alloc(size, PAGE_KERNEL_RX);
18213+}
18214+EXPORT_SYMBOL(module_alloc_exec);
18215+#endif
18216+#endif
18217+
18218 #ifdef CONFIG_X86_32
18219 int apply_relocate(Elf32_Shdr *sechdrs,
18220 const char *strtab,
18221@@ -54,14 +99,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18222 unsigned int i;
18223 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18224 Elf32_Sym *sym;
18225- uint32_t *location;
18226+ uint32_t *plocation, location;
18227
18228 DEBUGP("Applying relocate section %u to %u\n", relsec,
18229 sechdrs[relsec].sh_info);
18230 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18231 /* This is where to make the change */
18232- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18233- + rel[i].r_offset;
18234+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18235+ location = (uint32_t)plocation;
18236+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18237+ plocation = ktla_ktva((void *)plocation);
18238 /* This is the symbol it is referring to. Note that all
18239 undefined symbols have been resolved. */
18240 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18241@@ -70,11 +117,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18242 switch (ELF32_R_TYPE(rel[i].r_info)) {
18243 case R_386_32:
18244 /* We add the value into the location given */
18245- *location += sym->st_value;
18246+ pax_open_kernel();
18247+ *plocation += sym->st_value;
18248+ pax_close_kernel();
18249 break;
18250 case R_386_PC32:
18251 /* Add the value, subtract its postition */
18252- *location += sym->st_value - (uint32_t)location;
18253+ pax_open_kernel();
18254+ *plocation += sym->st_value - location;
18255+ pax_close_kernel();
18256 break;
18257 default:
18258 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
18259@@ -119,21 +170,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18260 case R_X86_64_NONE:
18261 break;
18262 case R_X86_64_64:
18263+ pax_open_kernel();
18264 *(u64 *)loc = val;
18265+ pax_close_kernel();
18266 break;
18267 case R_X86_64_32:
18268+ pax_open_kernel();
18269 *(u32 *)loc = val;
18270+ pax_close_kernel();
18271 if (val != *(u32 *)loc)
18272 goto overflow;
18273 break;
18274 case R_X86_64_32S:
18275+ pax_open_kernel();
18276 *(s32 *)loc = val;
18277+ pax_close_kernel();
18278 if ((s64)val != *(s32 *)loc)
18279 goto overflow;
18280 break;
18281 case R_X86_64_PC32:
18282 val -= (u64)loc;
18283+ pax_open_kernel();
18284 *(u32 *)loc = val;
18285+ pax_close_kernel();
18286+
18287 #if 0
18288 if ((s64)val != *(s32 *)loc)
18289 goto overflow;
18290diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18291index 32856fa..ce95eaa 100644
18292--- a/arch/x86/kernel/nmi.c
18293+++ b/arch/x86/kernel/nmi.c
18294@@ -507,6 +507,17 @@ static inline void nmi_nesting_postprocess(void)
18295 dotraplinkage notrace __kprobes void
18296 do_nmi(struct pt_regs *regs, long error_code)
18297 {
18298+
18299+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18300+ if (!user_mode(regs)) {
18301+ unsigned long cs = regs->cs & 0xFFFF;
18302+ unsigned long ip = ktva_ktla(regs->ip);
18303+
18304+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18305+ regs->ip = ip;
18306+ }
18307+#endif
18308+
18309 nmi_nesting_preprocess(regs);
18310
18311 nmi_enter();
18312diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18313index 676b8c7..870ba04 100644
18314--- a/arch/x86/kernel/paravirt-spinlocks.c
18315+++ b/arch/x86/kernel/paravirt-spinlocks.c
18316@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18317 arch_spin_lock(lock);
18318 }
18319
18320-struct pv_lock_ops pv_lock_ops = {
18321+struct pv_lock_ops pv_lock_ops __read_only = {
18322 #ifdef CONFIG_SMP
18323 .spin_is_locked = __ticket_spin_is_locked,
18324 .spin_is_contended = __ticket_spin_is_contended,
18325diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18326index ab13760..01218e0 100644
18327--- a/arch/x86/kernel/paravirt.c
18328+++ b/arch/x86/kernel/paravirt.c
18329@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18330 {
18331 return x;
18332 }
18333+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18334+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18335+#endif
18336
18337 void __init default_banner(void)
18338 {
18339@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18340 if (opfunc == NULL)
18341 /* If there's no function, patch it with a ud2a (BUG) */
18342 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18343- else if (opfunc == _paravirt_nop)
18344+ else if (opfunc == (void *)_paravirt_nop)
18345 /* If the operation is a nop, then nop the callsite */
18346 ret = paravirt_patch_nop();
18347
18348 /* identity functions just return their single argument */
18349- else if (opfunc == _paravirt_ident_32)
18350+ else if (opfunc == (void *)_paravirt_ident_32)
18351 ret = paravirt_patch_ident_32(insnbuf, len);
18352- else if (opfunc == _paravirt_ident_64)
18353+ else if (opfunc == (void *)_paravirt_ident_64)
18354 ret = paravirt_patch_ident_64(insnbuf, len);
18355+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18356+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18357+ ret = paravirt_patch_ident_64(insnbuf, len);
18358+#endif
18359
18360 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18361 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18362@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18363 if (insn_len > len || start == NULL)
18364 insn_len = len;
18365 else
18366- memcpy(insnbuf, start, insn_len);
18367+ memcpy(insnbuf, ktla_ktva(start), insn_len);
18368
18369 return insn_len;
18370 }
18371@@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18372 preempt_enable();
18373 }
18374
18375-struct pv_info pv_info = {
18376+struct pv_info pv_info __read_only = {
18377 .name = "bare hardware",
18378 .paravirt_enabled = 0,
18379 .kernel_rpl = 0,
18380@@ -315,16 +322,16 @@ struct pv_info pv_info = {
18381 #endif
18382 };
18383
18384-struct pv_init_ops pv_init_ops = {
18385+struct pv_init_ops pv_init_ops __read_only = {
18386 .patch = native_patch,
18387 };
18388
18389-struct pv_time_ops pv_time_ops = {
18390+struct pv_time_ops pv_time_ops __read_only = {
18391 .sched_clock = native_sched_clock,
18392 .steal_clock = native_steal_clock,
18393 };
18394
18395-struct pv_irq_ops pv_irq_ops = {
18396+struct pv_irq_ops pv_irq_ops __read_only = {
18397 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18398 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18399 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18400@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18401 #endif
18402 };
18403
18404-struct pv_cpu_ops pv_cpu_ops = {
18405+struct pv_cpu_ops pv_cpu_ops __read_only = {
18406 .cpuid = native_cpuid,
18407 .get_debugreg = native_get_debugreg,
18408 .set_debugreg = native_set_debugreg,
18409@@ -397,21 +404,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18410 .end_context_switch = paravirt_nop,
18411 };
18412
18413-struct pv_apic_ops pv_apic_ops = {
18414+struct pv_apic_ops pv_apic_ops __read_only = {
18415 #ifdef CONFIG_X86_LOCAL_APIC
18416 .startup_ipi_hook = paravirt_nop,
18417 #endif
18418 };
18419
18420-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18421+#ifdef CONFIG_X86_32
18422+#ifdef CONFIG_X86_PAE
18423+/* 64-bit pagetable entries */
18424+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18425+#else
18426 /* 32-bit pagetable entries */
18427 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18428+#endif
18429 #else
18430 /* 64-bit pagetable entries */
18431 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18432 #endif
18433
18434-struct pv_mmu_ops pv_mmu_ops = {
18435+struct pv_mmu_ops pv_mmu_ops __read_only = {
18436
18437 .read_cr2 = native_read_cr2,
18438 .write_cr2 = native_write_cr2,
18439@@ -461,6 +473,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18440 .make_pud = PTE_IDENT,
18441
18442 .set_pgd = native_set_pgd,
18443+ .set_pgd_batched = native_set_pgd_batched,
18444 #endif
18445 #endif /* PAGETABLE_LEVELS >= 3 */
18446
18447@@ -480,6 +493,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18448 },
18449
18450 .set_fixmap = native_set_fixmap,
18451+
18452+#ifdef CONFIG_PAX_KERNEXEC
18453+ .pax_open_kernel = native_pax_open_kernel,
18454+ .pax_close_kernel = native_pax_close_kernel,
18455+#endif
18456+
18457 };
18458
18459 EXPORT_SYMBOL_GPL(pv_time_ops);
18460diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18461index 35ccf75..7a15747 100644
18462--- a/arch/x86/kernel/pci-iommu_table.c
18463+++ b/arch/x86/kernel/pci-iommu_table.c
18464@@ -2,7 +2,7 @@
18465 #include <asm/iommu_table.h>
18466 #include <linux/string.h>
18467 #include <linux/kallsyms.h>
18468-
18469+#include <linux/sched.h>
18470
18471 #define DEBUG 1
18472
18473diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18474index 1d92a5a..7bc8c29 100644
18475--- a/arch/x86/kernel/process.c
18476+++ b/arch/x86/kernel/process.c
18477@@ -69,16 +69,33 @@ void free_thread_xstate(struct task_struct *tsk)
18478
18479 void free_thread_info(struct thread_info *ti)
18480 {
18481- free_thread_xstate(ti->task);
18482 free_pages((unsigned long)ti, THREAD_ORDER);
18483 }
18484
18485+static struct kmem_cache *task_struct_cachep;
18486+
18487 void arch_task_cache_init(void)
18488 {
18489- task_xstate_cachep =
18490- kmem_cache_create("task_xstate", xstate_size,
18491+ /* create a slab on which task_structs can be allocated */
18492+ task_struct_cachep =
18493+ kmem_cache_create("task_struct", sizeof(struct task_struct),
18494+ ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
18495+
18496+ task_xstate_cachep =
18497+ kmem_cache_create("task_xstate", xstate_size,
18498 __alignof__(union thread_xstate),
18499- SLAB_PANIC | SLAB_NOTRACK, NULL);
18500+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18501+}
18502+
18503+struct task_struct *alloc_task_struct_node(int node)
18504+{
18505+ return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
18506+}
18507+
18508+void free_task_struct(struct task_struct *task)
18509+{
18510+ free_thread_xstate(task);
18511+ kmem_cache_free(task_struct_cachep, task);
18512 }
18513
18514 /*
18515@@ -91,7 +108,7 @@ void exit_thread(void)
18516 unsigned long *bp = t->io_bitmap_ptr;
18517
18518 if (bp) {
18519- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18520+ struct tss_struct *tss = init_tss + get_cpu();
18521
18522 t->io_bitmap_ptr = NULL;
18523 clear_thread_flag(TIF_IO_BITMAP);
18524@@ -127,7 +144,7 @@ void show_regs_common(void)
18525
18526 printk(KERN_CONT "\n");
18527 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
18528- current->pid, current->comm, print_tainted(),
18529+ task_pid_nr(current), current->comm, print_tainted(),
18530 init_utsname()->release,
18531 (int)strcspn(init_utsname()->version, " "),
18532 init_utsname()->version);
18533@@ -141,6 +158,9 @@ void flush_thread(void)
18534 {
18535 struct task_struct *tsk = current;
18536
18537+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18538+ loadsegment(gs, 0);
18539+#endif
18540 flush_ptrace_hw_breakpoint(tsk);
18541 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18542 /*
18543@@ -303,10 +323,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18544 regs.di = (unsigned long) arg;
18545
18546 #ifdef CONFIG_X86_32
18547- regs.ds = __USER_DS;
18548- regs.es = __USER_DS;
18549+ regs.ds = __KERNEL_DS;
18550+ regs.es = __KERNEL_DS;
18551 regs.fs = __KERNEL_PERCPU;
18552- regs.gs = __KERNEL_STACK_CANARY;
18553+ savesegment(gs, regs.gs);
18554 #else
18555 regs.ss = __KERNEL_DS;
18556 #endif
18557@@ -392,7 +412,7 @@ static void __exit_idle(void)
18558 void exit_idle(void)
18559 {
18560 /* idle loop has pid 0 */
18561- if (current->pid)
18562+ if (task_pid_nr(current))
18563 return;
18564 __exit_idle();
18565 }
18566@@ -501,7 +521,7 @@ bool set_pm_idle_to_default(void)
18567
18568 return ret;
18569 }
18570-void stop_this_cpu(void *dummy)
18571+__noreturn void stop_this_cpu(void *dummy)
18572 {
18573 local_irq_disable();
18574 /*
18575@@ -743,16 +763,37 @@ static int __init idle_setup(char *str)
18576 }
18577 early_param("idle", idle_setup);
18578
18579-unsigned long arch_align_stack(unsigned long sp)
18580+#ifdef CONFIG_PAX_RANDKSTACK
18581+void pax_randomize_kstack(struct pt_regs *regs)
18582 {
18583- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18584- sp -= get_random_int() % 8192;
18585- return sp & ~0xf;
18586-}
18587+ struct thread_struct *thread = &current->thread;
18588+ unsigned long time;
18589
18590-unsigned long arch_randomize_brk(struct mm_struct *mm)
18591-{
18592- unsigned long range_end = mm->brk + 0x02000000;
18593- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18594-}
18595+ if (!randomize_va_space)
18596+ return;
18597+
18598+ if (v8086_mode(regs))
18599+ return;
18600
18601+ rdtscl(time);
18602+
18603+ /* P4 seems to return a 0 LSB, ignore it */
18604+#ifdef CONFIG_MPENTIUM4
18605+ time &= 0x3EUL;
18606+ time <<= 2;
18607+#elif defined(CONFIG_X86_64)
18608+ time &= 0xFUL;
18609+ time <<= 4;
18610+#else
18611+ time &= 0x1FUL;
18612+ time <<= 3;
18613+#endif
18614+
18615+ thread->sp0 ^= time;
18616+ load_sp0(init_tss + smp_processor_id(), thread);
18617+
18618+#ifdef CONFIG_X86_64
18619+ percpu_write(kernel_stack, thread->sp0);
18620+#endif
18621+}
18622+#endif
18623diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18624index ae68473..7b0bb71 100644
18625--- a/arch/x86/kernel/process_32.c
18626+++ b/arch/x86/kernel/process_32.c
18627@@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18628 unsigned long thread_saved_pc(struct task_struct *tsk)
18629 {
18630 return ((unsigned long *)tsk->thread.sp)[3];
18631+//XXX return tsk->thread.eip;
18632 }
18633
18634 void __show_regs(struct pt_regs *regs, int all)
18635@@ -73,15 +74,14 @@ void __show_regs(struct pt_regs *regs, int all)
18636 unsigned long sp;
18637 unsigned short ss, gs;
18638
18639- if (user_mode_vm(regs)) {
18640+ if (user_mode(regs)) {
18641 sp = regs->sp;
18642 ss = regs->ss & 0xffff;
18643- gs = get_user_gs(regs);
18644 } else {
18645 sp = kernel_stack_pointer(regs);
18646 savesegment(ss, ss);
18647- savesegment(gs, gs);
18648 }
18649+ gs = get_user_gs(regs);
18650
18651 show_regs_common();
18652
18653@@ -143,13 +143,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18654 struct task_struct *tsk;
18655 int err;
18656
18657- childregs = task_pt_regs(p);
18658+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18659 *childregs = *regs;
18660 childregs->ax = 0;
18661 childregs->sp = sp;
18662
18663 p->thread.sp = (unsigned long) childregs;
18664 p->thread.sp0 = (unsigned long) (childregs+1);
18665+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18666
18667 p->thread.ip = (unsigned long) ret_from_fork;
18668
18669@@ -240,7 +241,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18670 struct thread_struct *prev = &prev_p->thread,
18671 *next = &next_p->thread;
18672 int cpu = smp_processor_id();
18673- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18674+ struct tss_struct *tss = init_tss + cpu;
18675 fpu_switch_t fpu;
18676
18677 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18678@@ -264,6 +265,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18679 */
18680 lazy_save_gs(prev->gs);
18681
18682+#ifdef CONFIG_PAX_MEMORY_UDEREF
18683+ __set_fs(task_thread_info(next_p)->addr_limit);
18684+#endif
18685+
18686 /*
18687 * Load the per-thread Thread-Local Storage descriptor.
18688 */
18689@@ -294,6 +299,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18690 */
18691 arch_end_context_switch(next_p);
18692
18693+ percpu_write(current_task, next_p);
18694+ percpu_write(current_tinfo, &next_p->tinfo);
18695+
18696 /*
18697 * Restore %gs if needed (which is common)
18698 */
18699@@ -302,8 +310,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18700
18701 switch_fpu_finish(next_p, fpu);
18702
18703- percpu_write(current_task, next_p);
18704-
18705 return prev_p;
18706 }
18707
18708@@ -333,4 +339,3 @@ unsigned long get_wchan(struct task_struct *p)
18709 } while (count++ < 16);
18710 return 0;
18711 }
18712-
18713diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18714index 43d8b48..c45d566 100644
18715--- a/arch/x86/kernel/process_64.c
18716+++ b/arch/x86/kernel/process_64.c
18717@@ -162,8 +162,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18718 struct pt_regs *childregs;
18719 struct task_struct *me = current;
18720
18721- childregs = ((struct pt_regs *)
18722- (THREAD_SIZE + task_stack_page(p))) - 1;
18723+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18724 *childregs = *regs;
18725
18726 childregs->ax = 0;
18727@@ -175,6 +174,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18728 p->thread.sp = (unsigned long) childregs;
18729 p->thread.sp0 = (unsigned long) (childregs+1);
18730 p->thread.usersp = me->thread.usersp;
18731+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18732
18733 set_tsk_thread_flag(p, TIF_FORK);
18734
18735@@ -280,7 +280,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18736 struct thread_struct *prev = &prev_p->thread;
18737 struct thread_struct *next = &next_p->thread;
18738 int cpu = smp_processor_id();
18739- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18740+ struct tss_struct *tss = init_tss + cpu;
18741 unsigned fsindex, gsindex;
18742 fpu_switch_t fpu;
18743
18744@@ -362,10 +362,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18745 prev->usersp = percpu_read(old_rsp);
18746 percpu_write(old_rsp, next->usersp);
18747 percpu_write(current_task, next_p);
18748+ percpu_write(current_tinfo, &next_p->tinfo);
18749
18750- percpu_write(kernel_stack,
18751- (unsigned long)task_stack_page(next_p) +
18752- THREAD_SIZE - KERNEL_STACK_OFFSET);
18753+ percpu_write(kernel_stack, next->sp0);
18754
18755 /*
18756 * Now maybe reload the debug registers and handle I/O bitmaps
18757@@ -434,12 +433,11 @@ unsigned long get_wchan(struct task_struct *p)
18758 if (!p || p == current || p->state == TASK_RUNNING)
18759 return 0;
18760 stack = (unsigned long)task_stack_page(p);
18761- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18762+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18763 return 0;
18764 fp = *(u64 *)(p->thread.sp);
18765 do {
18766- if (fp < (unsigned long)stack ||
18767- fp >= (unsigned long)stack+THREAD_SIZE)
18768+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18769 return 0;
18770 ip = *(u64 *)(fp+8);
18771 if (!in_sched_functions(ip))
18772diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18773index cf11783..e7ce551 100644
18774--- a/arch/x86/kernel/ptrace.c
18775+++ b/arch/x86/kernel/ptrace.c
18776@@ -824,7 +824,7 @@ long arch_ptrace(struct task_struct *child, long request,
18777 unsigned long addr, unsigned long data)
18778 {
18779 int ret;
18780- unsigned long __user *datap = (unsigned long __user *)data;
18781+ unsigned long __user *datap = (__force unsigned long __user *)data;
18782
18783 switch (request) {
18784 /* read the word at location addr in the USER area. */
18785@@ -909,14 +909,14 @@ long arch_ptrace(struct task_struct *child, long request,
18786 if ((int) addr < 0)
18787 return -EIO;
18788 ret = do_get_thread_area(child, addr,
18789- (struct user_desc __user *)data);
18790+ (__force struct user_desc __user *) data);
18791 break;
18792
18793 case PTRACE_SET_THREAD_AREA:
18794 if ((int) addr < 0)
18795 return -EIO;
18796 ret = do_set_thread_area(child, addr,
18797- (struct user_desc __user *)data, 0);
18798+ (__force struct user_desc __user *) data, 0);
18799 break;
18800 #endif
18801
18802@@ -1426,7 +1426,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18803 memset(info, 0, sizeof(*info));
18804 info->si_signo = SIGTRAP;
18805 info->si_code = si_code;
18806- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18807+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18808 }
18809
18810 void user_single_step_siginfo(struct task_struct *tsk,
18811@@ -1455,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18812 # define IS_IA32 0
18813 #endif
18814
18815+#ifdef CONFIG_GRKERNSEC_SETXID
18816+extern void gr_delayed_cred_worker(void);
18817+#endif
18818+
18819 /*
18820 * We must return the syscall number to actually look up in the table.
18821 * This can be -1L to skip running any syscall at all.
18822@@ -1463,6 +1467,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18823 {
18824 long ret = 0;
18825
18826+#ifdef CONFIG_GRKERNSEC_SETXID
18827+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18828+ gr_delayed_cred_worker();
18829+#endif
18830+
18831 /*
18832 * If we stepped into a sysenter/syscall insn, it trapped in
18833 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18834@@ -1506,6 +1515,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18835 {
18836 bool step;
18837
18838+#ifdef CONFIG_GRKERNSEC_SETXID
18839+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18840+ gr_delayed_cred_worker();
18841+#endif
18842+
18843 audit_syscall_exit(regs);
18844
18845 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18846diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18847index 42eb330..139955c 100644
18848--- a/arch/x86/kernel/pvclock.c
18849+++ b/arch/x86/kernel/pvclock.c
18850@@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18851 return pv_tsc_khz;
18852 }
18853
18854-static atomic64_t last_value = ATOMIC64_INIT(0);
18855+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18856
18857 void pvclock_resume(void)
18858 {
18859- atomic64_set(&last_value, 0);
18860+ atomic64_set_unchecked(&last_value, 0);
18861 }
18862
18863 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18864@@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18865 * updating at the same time, and one of them could be slightly behind,
18866 * making the assumption that last_value always go forward fail to hold.
18867 */
18868- last = atomic64_read(&last_value);
18869+ last = atomic64_read_unchecked(&last_value);
18870 do {
18871 if (ret < last)
18872 return last;
18873- last = atomic64_cmpxchg(&last_value, last, ret);
18874+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18875 } while (unlikely(last != ret));
18876
18877 return ret;
18878diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18879index d840e69..98e9581 100644
18880--- a/arch/x86/kernel/reboot.c
18881+++ b/arch/x86/kernel/reboot.c
18882@@ -35,7 +35,7 @@ void (*pm_power_off)(void);
18883 EXPORT_SYMBOL(pm_power_off);
18884
18885 static const struct desc_ptr no_idt = {};
18886-static int reboot_mode;
18887+static unsigned short reboot_mode;
18888 enum reboot_type reboot_type = BOOT_ACPI;
18889 int reboot_force;
18890
18891@@ -335,13 +335,17 @@ core_initcall(reboot_init);
18892 extern const unsigned char machine_real_restart_asm[];
18893 extern const u64 machine_real_restart_gdt[3];
18894
18895-void machine_real_restart(unsigned int type)
18896+__noreturn void machine_real_restart(unsigned int type)
18897 {
18898 void *restart_va;
18899 unsigned long restart_pa;
18900- void (*restart_lowmem)(unsigned int);
18901+ void (* __noreturn restart_lowmem)(unsigned int);
18902 u64 *lowmem_gdt;
18903
18904+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18905+ struct desc_struct *gdt;
18906+#endif
18907+
18908 local_irq_disable();
18909
18910 /* Write zero to CMOS register number 0x0f, which the BIOS POST
18911@@ -367,14 +371,14 @@ void machine_real_restart(unsigned int type)
18912 boot)". This seems like a fairly standard thing that gets set by
18913 REBOOT.COM programs, and the previous reset routine did this
18914 too. */
18915- *((unsigned short *)0x472) = reboot_mode;
18916+ *(unsigned short *)(__va(0x472)) = reboot_mode;
18917
18918 /* Patch the GDT in the low memory trampoline */
18919 lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt);
18920
18921 restart_va = TRAMPOLINE_SYM(machine_real_restart_asm);
18922 restart_pa = virt_to_phys(restart_va);
18923- restart_lowmem = (void (*)(unsigned int))restart_pa;
18924+ restart_lowmem = (void *)restart_pa;
18925
18926 /* GDT[0]: GDT self-pointer */
18927 lowmem_gdt[0] =
18928@@ -385,7 +389,33 @@ void machine_real_restart(unsigned int type)
18929 GDT_ENTRY(0x009b, restart_pa, 0xffff);
18930
18931 /* Jump to the identity-mapped low memory code */
18932+
18933+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18934+ gdt = get_cpu_gdt_table(smp_processor_id());
18935+ pax_open_kernel();
18936+#ifdef CONFIG_PAX_MEMORY_UDEREF
18937+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18938+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18939+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
18940+#endif
18941+#ifdef CONFIG_PAX_KERNEXEC
18942+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18943+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18944+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18945+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18946+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18947+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18948+#endif
18949+ pax_close_kernel();
18950+#endif
18951+
18952+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18953+ asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
18954+ unreachable();
18955+#else
18956 restart_lowmem(type);
18957+#endif
18958+
18959 }
18960 #ifdef CONFIG_APM_MODULE
18961 EXPORT_SYMBOL(machine_real_restart);
18962@@ -556,7 +586,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18963 * try to force a triple fault and then cycle between hitting the keyboard
18964 * controller and doing that
18965 */
18966-static void native_machine_emergency_restart(void)
18967+__noreturn static void native_machine_emergency_restart(void)
18968 {
18969 int i;
18970 int attempt = 0;
18971@@ -680,13 +710,13 @@ void native_machine_shutdown(void)
18972 #endif
18973 }
18974
18975-static void __machine_emergency_restart(int emergency)
18976+static __noreturn void __machine_emergency_restart(int emergency)
18977 {
18978 reboot_emergency = emergency;
18979 machine_ops.emergency_restart();
18980 }
18981
18982-static void native_machine_restart(char *__unused)
18983+static __noreturn void native_machine_restart(char *__unused)
18984 {
18985 printk("machine restart\n");
18986
18987@@ -695,7 +725,7 @@ static void native_machine_restart(char *__unused)
18988 __machine_emergency_restart(0);
18989 }
18990
18991-static void native_machine_halt(void)
18992+static __noreturn void native_machine_halt(void)
18993 {
18994 /* stop other cpus and apics */
18995 machine_shutdown();
18996@@ -706,7 +736,7 @@ static void native_machine_halt(void)
18997 stop_this_cpu(NULL);
18998 }
18999
19000-static void native_machine_power_off(void)
19001+__noreturn static void native_machine_power_off(void)
19002 {
19003 if (pm_power_off) {
19004 if (!reboot_force)
19005@@ -715,6 +745,7 @@ static void native_machine_power_off(void)
19006 }
19007 /* a fallback in case there is no PM info available */
19008 tboot_shutdown(TB_SHUTDOWN_HALT);
19009+ unreachable();
19010 }
19011
19012 struct machine_ops machine_ops = {
19013diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
19014index 7a6f3b3..bed145d7 100644
19015--- a/arch/x86/kernel/relocate_kernel_64.S
19016+++ b/arch/x86/kernel/relocate_kernel_64.S
19017@@ -11,6 +11,7 @@
19018 #include <asm/kexec.h>
19019 #include <asm/processor-flags.h>
19020 #include <asm/pgtable_types.h>
19021+#include <asm/alternative-asm.h>
19022
19023 /*
19024 * Must be relocatable PIC code callable as a C function
19025@@ -160,13 +161,14 @@ identity_mapped:
19026 xorq %rbp, %rbp
19027 xorq %r8, %r8
19028 xorq %r9, %r9
19029- xorq %r10, %r9
19030+ xorq %r10, %r10
19031 xorq %r11, %r11
19032 xorq %r12, %r12
19033 xorq %r13, %r13
19034 xorq %r14, %r14
19035 xorq %r15, %r15
19036
19037+ pax_force_retaddr 0, 1
19038 ret
19039
19040 1:
19041diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
19042index 1a29015..712f324 100644
19043--- a/arch/x86/kernel/setup.c
19044+++ b/arch/x86/kernel/setup.c
19045@@ -447,7 +447,7 @@ static void __init parse_setup_data(void)
19046
19047 switch (data->type) {
19048 case SETUP_E820_EXT:
19049- parse_e820_ext(data);
19050+ parse_e820_ext((struct setup_data __force_kernel *)data);
19051 break;
19052 case SETUP_DTB:
19053 add_dtb(pa_data);
19054@@ -639,7 +639,7 @@ static void __init trim_bios_range(void)
19055 * area (640->1Mb) as ram even though it is not.
19056 * take them out.
19057 */
19058- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
19059+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
19060 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
19061 }
19062
19063@@ -763,14 +763,14 @@ void __init setup_arch(char **cmdline_p)
19064
19065 if (!boot_params.hdr.root_flags)
19066 root_mountflags &= ~MS_RDONLY;
19067- init_mm.start_code = (unsigned long) _text;
19068- init_mm.end_code = (unsigned long) _etext;
19069+ init_mm.start_code = ktla_ktva((unsigned long) _text);
19070+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
19071 init_mm.end_data = (unsigned long) _edata;
19072 init_mm.brk = _brk_end;
19073
19074- code_resource.start = virt_to_phys(_text);
19075- code_resource.end = virt_to_phys(_etext)-1;
19076- data_resource.start = virt_to_phys(_etext);
19077+ code_resource.start = virt_to_phys(ktla_ktva(_text));
19078+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
19079+ data_resource.start = virt_to_phys(_sdata);
19080 data_resource.end = virt_to_phys(_edata)-1;
19081 bss_resource.start = virt_to_phys(&__bss_start);
19082 bss_resource.end = virt_to_phys(&__bss_stop)-1;
19083diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
19084index 5a98aa2..2f9288d 100644
19085--- a/arch/x86/kernel/setup_percpu.c
19086+++ b/arch/x86/kernel/setup_percpu.c
19087@@ -21,19 +21,17 @@
19088 #include <asm/cpu.h>
19089 #include <asm/stackprotector.h>
19090
19091-DEFINE_PER_CPU(int, cpu_number);
19092+#ifdef CONFIG_SMP
19093+DEFINE_PER_CPU(unsigned int, cpu_number);
19094 EXPORT_PER_CPU_SYMBOL(cpu_number);
19095+#endif
19096
19097-#ifdef CONFIG_X86_64
19098 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
19099-#else
19100-#define BOOT_PERCPU_OFFSET 0
19101-#endif
19102
19103 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
19104 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
19105
19106-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
19107+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
19108 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19109 };
19110 EXPORT_SYMBOL(__per_cpu_offset);
19111@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
19112 {
19113 #ifdef CONFIG_X86_32
19114 struct desc_struct gdt;
19115+ unsigned long base = per_cpu_offset(cpu);
19116
19117- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19118- 0x2 | DESCTYPE_S, 0x8);
19119- gdt.s = 1;
19120+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19121+ 0x83 | DESCTYPE_S, 0xC);
19122 write_gdt_entry(get_cpu_gdt_table(cpu),
19123 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19124 #endif
19125@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
19126 /* alrighty, percpu areas up and running */
19127 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19128 for_each_possible_cpu(cpu) {
19129+#ifdef CONFIG_CC_STACKPROTECTOR
19130+#ifdef CONFIG_X86_32
19131+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
19132+#endif
19133+#endif
19134 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19135 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19136 per_cpu(cpu_number, cpu) = cpu;
19137@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
19138 */
19139 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
19140 #endif
19141+#ifdef CONFIG_CC_STACKPROTECTOR
19142+#ifdef CONFIG_X86_32
19143+ if (!cpu)
19144+ per_cpu(stack_canary.canary, cpu) = canary;
19145+#endif
19146+#endif
19147 /*
19148 * Up to this point, the boot CPU has been using .init.data
19149 * area. Reload any changed state for the boot CPU.
19150diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19151index 115eac4..c0591d5 100644
19152--- a/arch/x86/kernel/signal.c
19153+++ b/arch/x86/kernel/signal.c
19154@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
19155 * Align the stack pointer according to the i386 ABI,
19156 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19157 */
19158- sp = ((sp + 4) & -16ul) - 4;
19159+ sp = ((sp - 12) & -16ul) - 4;
19160 #else /* !CONFIG_X86_32 */
19161 sp = round_down(sp, 16) - 8;
19162 #endif
19163@@ -241,11 +241,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19164 * Return an always-bogus address instead so we will die with SIGSEGV.
19165 */
19166 if (onsigstack && !likely(on_sig_stack(sp)))
19167- return (void __user *)-1L;
19168+ return (__force void __user *)-1L;
19169
19170 /* save i387 state */
19171 if (used_math() && save_i387_xstate(*fpstate) < 0)
19172- return (void __user *)-1L;
19173+ return (__force void __user *)-1L;
19174
19175 return (void __user *)sp;
19176 }
19177@@ -300,9 +300,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19178 }
19179
19180 if (current->mm->context.vdso)
19181- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19182+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19183 else
19184- restorer = &frame->retcode;
19185+ restorer = (void __user *)&frame->retcode;
19186 if (ka->sa.sa_flags & SA_RESTORER)
19187 restorer = ka->sa.sa_restorer;
19188
19189@@ -316,7 +316,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19190 * reasons and because gdb uses it as a signature to notice
19191 * signal handler stack frames.
19192 */
19193- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19194+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19195
19196 if (err)
19197 return -EFAULT;
19198@@ -370,7 +370,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19199 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19200
19201 /* Set up to return from userspace. */
19202- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19203+ if (current->mm->context.vdso)
19204+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19205+ else
19206+ restorer = (void __user *)&frame->retcode;
19207 if (ka->sa.sa_flags & SA_RESTORER)
19208 restorer = ka->sa.sa_restorer;
19209 put_user_ex(restorer, &frame->pretcode);
19210@@ -382,7 +385,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19211 * reasons and because gdb uses it as a signature to notice
19212 * signal handler stack frames.
19213 */
19214- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19215+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19216 } put_user_catch(err);
19217
19218 if (err)
19219@@ -773,7 +776,7 @@ static void do_signal(struct pt_regs *regs)
19220 * X86_32: vm86 regs switched out by assembly code before reaching
19221 * here, so testing against kernel CS suffices.
19222 */
19223- if (!user_mode(regs))
19224+ if (!user_mode_novm(regs))
19225 return;
19226
19227 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
19228diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19229index 6e1e406..edfb7cb 100644
19230--- a/arch/x86/kernel/smpboot.c
19231+++ b/arch/x86/kernel/smpboot.c
19232@@ -699,17 +699,20 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)
19233 set_idle_for_cpu(cpu, c_idle.idle);
19234 do_rest:
19235 per_cpu(current_task, cpu) = c_idle.idle;
19236+ per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
19237 #ifdef CONFIG_X86_32
19238 /* Stack for startup_32 can be just as for start_secondary onwards */
19239 irq_ctx_init(cpu);
19240 #else
19241 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
19242 initial_gs = per_cpu_offset(cpu);
19243- per_cpu(kernel_stack, cpu) =
19244- (unsigned long)task_stack_page(c_idle.idle) -
19245- KERNEL_STACK_OFFSET + THREAD_SIZE;
19246+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
19247 #endif
19248+
19249+ pax_open_kernel();
19250 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19251+ pax_close_kernel();
19252+
19253 initial_code = (unsigned long)start_secondary;
19254 stack_start = c_idle.idle->thread.sp;
19255
19256@@ -851,6 +854,12 @@ int __cpuinit native_cpu_up(unsigned int cpu)
19257
19258 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19259
19260+#ifdef CONFIG_PAX_PER_CPU_PGD
19261+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19262+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19263+ KERNEL_PGD_PTRS);
19264+#endif
19265+
19266 err = do_boot_cpu(apicid, cpu);
19267 if (err) {
19268 pr_debug("do_boot_cpu failed %d\n", err);
19269diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19270index c346d11..d43b163 100644
19271--- a/arch/x86/kernel/step.c
19272+++ b/arch/x86/kernel/step.c
19273@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19274 struct desc_struct *desc;
19275 unsigned long base;
19276
19277- seg &= ~7UL;
19278+ seg >>= 3;
19279
19280 mutex_lock(&child->mm->context.lock);
19281- if (unlikely((seg >> 3) >= child->mm->context.size))
19282+ if (unlikely(seg >= child->mm->context.size))
19283 addr = -1L; /* bogus selector, access would fault */
19284 else {
19285 desc = child->mm->context.ldt + seg;
19286@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19287 addr += base;
19288 }
19289 mutex_unlock(&child->mm->context.lock);
19290- }
19291+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19292+ addr = ktla_ktva(addr);
19293
19294 return addr;
19295 }
19296@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19297 unsigned char opcode[15];
19298 unsigned long addr = convert_ip_to_linear(child, regs);
19299
19300+ if (addr == -EINVAL)
19301+ return 0;
19302+
19303 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19304 for (i = 0; i < copied; i++) {
19305 switch (opcode[i]) {
19306diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19307index 0b0cb5f..db6b9ed 100644
19308--- a/arch/x86/kernel/sys_i386_32.c
19309+++ b/arch/x86/kernel/sys_i386_32.c
19310@@ -24,17 +24,224 @@
19311
19312 #include <asm/syscalls.h>
19313
19314-/*
19315- * Do a system call from kernel instead of calling sys_execve so we
19316- * end up with proper pt_regs.
19317- */
19318-int kernel_execve(const char *filename,
19319- const char *const argv[],
19320- const char *const envp[])
19321+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19322 {
19323- long __res;
19324- asm volatile ("int $0x80"
19325- : "=a" (__res)
19326- : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19327- return __res;
19328+ unsigned long pax_task_size = TASK_SIZE;
19329+
19330+#ifdef CONFIG_PAX_SEGMEXEC
19331+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19332+ pax_task_size = SEGMEXEC_TASK_SIZE;
19333+#endif
19334+
19335+ if (len > pax_task_size || addr > pax_task_size - len)
19336+ return -EINVAL;
19337+
19338+ return 0;
19339+}
19340+
19341+unsigned long
19342+arch_get_unmapped_area(struct file *filp, unsigned long addr,
19343+ unsigned long len, unsigned long pgoff, unsigned long flags)
19344+{
19345+ struct mm_struct *mm = current->mm;
19346+ struct vm_area_struct *vma;
19347+ unsigned long start_addr, pax_task_size = TASK_SIZE;
19348+
19349+#ifdef CONFIG_PAX_SEGMEXEC
19350+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19351+ pax_task_size = SEGMEXEC_TASK_SIZE;
19352+#endif
19353+
19354+ pax_task_size -= PAGE_SIZE;
19355+
19356+ if (len > pax_task_size)
19357+ return -ENOMEM;
19358+
19359+ if (flags & MAP_FIXED)
19360+ return addr;
19361+
19362+#ifdef CONFIG_PAX_RANDMMAP
19363+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19364+#endif
19365+
19366+ if (addr) {
19367+ addr = PAGE_ALIGN(addr);
19368+ if (pax_task_size - len >= addr) {
19369+ vma = find_vma(mm, addr);
19370+ if (check_heap_stack_gap(vma, addr, len))
19371+ return addr;
19372+ }
19373+ }
19374+ if (len > mm->cached_hole_size) {
19375+ start_addr = addr = mm->free_area_cache;
19376+ } else {
19377+ start_addr = addr = mm->mmap_base;
19378+ mm->cached_hole_size = 0;
19379+ }
19380+
19381+#ifdef CONFIG_PAX_PAGEEXEC
19382+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19383+ start_addr = 0x00110000UL;
19384+
19385+#ifdef CONFIG_PAX_RANDMMAP
19386+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19387+ start_addr += mm->delta_mmap & 0x03FFF000UL;
19388+#endif
19389+
19390+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19391+ start_addr = addr = mm->mmap_base;
19392+ else
19393+ addr = start_addr;
19394+ }
19395+#endif
19396+
19397+full_search:
19398+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19399+ /* At this point: (!vma || addr < vma->vm_end). */
19400+ if (pax_task_size - len < addr) {
19401+ /*
19402+ * Start a new search - just in case we missed
19403+ * some holes.
19404+ */
19405+ if (start_addr != mm->mmap_base) {
19406+ start_addr = addr = mm->mmap_base;
19407+ mm->cached_hole_size = 0;
19408+ goto full_search;
19409+ }
19410+ return -ENOMEM;
19411+ }
19412+ if (check_heap_stack_gap(vma, addr, len))
19413+ break;
19414+ if (addr + mm->cached_hole_size < vma->vm_start)
19415+ mm->cached_hole_size = vma->vm_start - addr;
19416+ addr = vma->vm_end;
19417+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
19418+ start_addr = addr = mm->mmap_base;
19419+ mm->cached_hole_size = 0;
19420+ goto full_search;
19421+ }
19422+ }
19423+
19424+ /*
19425+ * Remember the place where we stopped the search:
19426+ */
19427+ mm->free_area_cache = addr + len;
19428+ return addr;
19429+}
19430+
19431+unsigned long
19432+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19433+ const unsigned long len, const unsigned long pgoff,
19434+ const unsigned long flags)
19435+{
19436+ struct vm_area_struct *vma;
19437+ struct mm_struct *mm = current->mm;
19438+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19439+
19440+#ifdef CONFIG_PAX_SEGMEXEC
19441+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19442+ pax_task_size = SEGMEXEC_TASK_SIZE;
19443+#endif
19444+
19445+ pax_task_size -= PAGE_SIZE;
19446+
19447+ /* requested length too big for entire address space */
19448+ if (len > pax_task_size)
19449+ return -ENOMEM;
19450+
19451+ if (flags & MAP_FIXED)
19452+ return addr;
19453+
19454+#ifdef CONFIG_PAX_PAGEEXEC
19455+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19456+ goto bottomup;
19457+#endif
19458+
19459+#ifdef CONFIG_PAX_RANDMMAP
19460+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19461+#endif
19462+
19463+ /* requesting a specific address */
19464+ if (addr) {
19465+ addr = PAGE_ALIGN(addr);
19466+ if (pax_task_size - len >= addr) {
19467+ vma = find_vma(mm, addr);
19468+ if (check_heap_stack_gap(vma, addr, len))
19469+ return addr;
19470+ }
19471+ }
19472+
19473+ /* check if free_area_cache is useful for us */
19474+ if (len <= mm->cached_hole_size) {
19475+ mm->cached_hole_size = 0;
19476+ mm->free_area_cache = mm->mmap_base;
19477+ }
19478+
19479+ /* either no address requested or can't fit in requested address hole */
19480+ addr = mm->free_area_cache;
19481+
19482+ /* make sure it can fit in the remaining address space */
19483+ if (addr > len) {
19484+ vma = find_vma(mm, addr-len);
19485+ if (check_heap_stack_gap(vma, addr - len, len))
19486+ /* remember the address as a hint for next time */
19487+ return (mm->free_area_cache = addr-len);
19488+ }
19489+
19490+ if (mm->mmap_base < len)
19491+ goto bottomup;
19492+
19493+ addr = mm->mmap_base-len;
19494+
19495+ do {
19496+ /*
19497+ * Lookup failure means no vma is above this address,
19498+ * else if new region fits below vma->vm_start,
19499+ * return with success:
19500+ */
19501+ vma = find_vma(mm, addr);
19502+ if (check_heap_stack_gap(vma, addr, len))
19503+ /* remember the address as a hint for next time */
19504+ return (mm->free_area_cache = addr);
19505+
19506+ /* remember the largest hole we saw so far */
19507+ if (addr + mm->cached_hole_size < vma->vm_start)
19508+ mm->cached_hole_size = vma->vm_start - addr;
19509+
19510+ /* try just below the current vma->vm_start */
19511+ addr = skip_heap_stack_gap(vma, len);
19512+ } while (!IS_ERR_VALUE(addr));
19513+
19514+bottomup:
19515+ /*
19516+ * A failed mmap() very likely causes application failure,
19517+ * so fall back to the bottom-up function here. This scenario
19518+ * can happen with large stack limits and large mmap()
19519+ * allocations.
19520+ */
19521+
19522+#ifdef CONFIG_PAX_SEGMEXEC
19523+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19524+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19525+ else
19526+#endif
19527+
19528+ mm->mmap_base = TASK_UNMAPPED_BASE;
19529+
19530+#ifdef CONFIG_PAX_RANDMMAP
19531+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19532+ mm->mmap_base += mm->delta_mmap;
19533+#endif
19534+
19535+ mm->free_area_cache = mm->mmap_base;
19536+ mm->cached_hole_size = ~0UL;
19537+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19538+ /*
19539+ * Restore the topdown base:
19540+ */
19541+ mm->mmap_base = base;
19542+ mm->free_area_cache = base;
19543+ mm->cached_hole_size = ~0UL;
19544+
19545+ return addr;
19546 }
19547diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19548index b4d3c39..82bb73b 100644
19549--- a/arch/x86/kernel/sys_x86_64.c
19550+++ b/arch/x86/kernel/sys_x86_64.c
19551@@ -95,8 +95,8 @@ out:
19552 return error;
19553 }
19554
19555-static void find_start_end(unsigned long flags, unsigned long *begin,
19556- unsigned long *end)
19557+static void find_start_end(struct mm_struct *mm, unsigned long flags,
19558+ unsigned long *begin, unsigned long *end)
19559 {
19560 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19561 unsigned long new_begin;
19562@@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19563 *begin = new_begin;
19564 }
19565 } else {
19566- *begin = TASK_UNMAPPED_BASE;
19567+ *begin = mm->mmap_base;
19568 *end = TASK_SIZE;
19569 }
19570 }
19571@@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19572 if (flags & MAP_FIXED)
19573 return addr;
19574
19575- find_start_end(flags, &begin, &end);
19576+ find_start_end(mm, flags, &begin, &end);
19577
19578 if (len > end)
19579 return -ENOMEM;
19580
19581+#ifdef CONFIG_PAX_RANDMMAP
19582+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19583+#endif
19584+
19585 if (addr) {
19586 addr = PAGE_ALIGN(addr);
19587 vma = find_vma(mm, addr);
19588- if (end - len >= addr &&
19589- (!vma || addr + len <= vma->vm_start))
19590+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19591 return addr;
19592 }
19593 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19594@@ -172,7 +175,7 @@ full_search:
19595 }
19596 return -ENOMEM;
19597 }
19598- if (!vma || addr + len <= vma->vm_start) {
19599+ if (check_heap_stack_gap(vma, addr, len)) {
19600 /*
19601 * Remember the place where we stopped the search:
19602 */
19603@@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19604 {
19605 struct vm_area_struct *vma;
19606 struct mm_struct *mm = current->mm;
19607- unsigned long addr = addr0, start_addr;
19608+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19609
19610 /* requested length too big for entire address space */
19611 if (len > TASK_SIZE)
19612@@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19613 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19614 goto bottomup;
19615
19616+#ifdef CONFIG_PAX_RANDMMAP
19617+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19618+#endif
19619+
19620 /* requesting a specific address */
19621 if (addr) {
19622 addr = PAGE_ALIGN(addr);
19623- vma = find_vma(mm, addr);
19624- if (TASK_SIZE - len >= addr &&
19625- (!vma || addr + len <= vma->vm_start))
19626- return addr;
19627+ if (TASK_SIZE - len >= addr) {
19628+ vma = find_vma(mm, addr);
19629+ if (check_heap_stack_gap(vma, addr, len))
19630+ return addr;
19631+ }
19632 }
19633
19634 /* check if free_area_cache is useful for us */
19635@@ -240,7 +248,7 @@ try_again:
19636 * return with success:
19637 */
19638 vma = find_vma(mm, addr);
19639- if (!vma || addr+len <= vma->vm_start)
19640+ if (check_heap_stack_gap(vma, addr, len))
19641 /* remember the address as a hint for next time */
19642 return mm->free_area_cache = addr;
19643
19644@@ -249,8 +257,8 @@ try_again:
19645 mm->cached_hole_size = vma->vm_start - addr;
19646
19647 /* try just below the current vma->vm_start */
19648- addr = vma->vm_start-len;
19649- } while (len < vma->vm_start);
19650+ addr = skip_heap_stack_gap(vma, len);
19651+ } while (!IS_ERR_VALUE(addr));
19652
19653 fail:
19654 /*
19655@@ -270,13 +278,21 @@ bottomup:
19656 * can happen with large stack limits and large mmap()
19657 * allocations.
19658 */
19659+ mm->mmap_base = TASK_UNMAPPED_BASE;
19660+
19661+#ifdef CONFIG_PAX_RANDMMAP
19662+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19663+ mm->mmap_base += mm->delta_mmap;
19664+#endif
19665+
19666+ mm->free_area_cache = mm->mmap_base;
19667 mm->cached_hole_size = ~0UL;
19668- mm->free_area_cache = TASK_UNMAPPED_BASE;
19669 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19670 /*
19671 * Restore the topdown base:
19672 */
19673- mm->free_area_cache = mm->mmap_base;
19674+ mm->mmap_base = base;
19675+ mm->free_area_cache = base;
19676 mm->cached_hole_size = ~0UL;
19677
19678 return addr;
19679diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19680index 6410744..79758f0 100644
19681--- a/arch/x86/kernel/tboot.c
19682+++ b/arch/x86/kernel/tboot.c
19683@@ -219,7 +219,7 @@ static int tboot_setup_sleep(void)
19684
19685 void tboot_shutdown(u32 shutdown_type)
19686 {
19687- void (*shutdown)(void);
19688+ void (* __noreturn shutdown)(void);
19689
19690 if (!tboot_enabled())
19691 return;
19692@@ -241,7 +241,7 @@ void tboot_shutdown(u32 shutdown_type)
19693
19694 switch_to_tboot_pt();
19695
19696- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19697+ shutdown = (void *)tboot->shutdown_entry;
19698 shutdown();
19699
19700 /* should not reach here */
19701@@ -299,7 +299,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19702 return 0;
19703 }
19704
19705-static atomic_t ap_wfs_count;
19706+static atomic_unchecked_t ap_wfs_count;
19707
19708 static int tboot_wait_for_aps(int num_aps)
19709 {
19710@@ -323,9 +323,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19711 {
19712 switch (action) {
19713 case CPU_DYING:
19714- atomic_inc(&ap_wfs_count);
19715+ atomic_inc_unchecked(&ap_wfs_count);
19716 if (num_online_cpus() == 1)
19717- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19718+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19719 return NOTIFY_BAD;
19720 break;
19721 }
19722@@ -344,7 +344,7 @@ static __init int tboot_late_init(void)
19723
19724 tboot_create_trampoline();
19725
19726- atomic_set(&ap_wfs_count, 0);
19727+ atomic_set_unchecked(&ap_wfs_count, 0);
19728 register_hotcpu_notifier(&tboot_cpu_notifier);
19729
19730 acpi_os_set_prepare_sleep(&tboot_sleep);
19731diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19732index c6eba2b..3303326 100644
19733--- a/arch/x86/kernel/time.c
19734+++ b/arch/x86/kernel/time.c
19735@@ -31,9 +31,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19736 {
19737 unsigned long pc = instruction_pointer(regs);
19738
19739- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19740+ if (!user_mode(regs) && in_lock_functions(pc)) {
19741 #ifdef CONFIG_FRAME_POINTER
19742- return *(unsigned long *)(regs->bp + sizeof(long));
19743+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19744 #else
19745 unsigned long *sp =
19746 (unsigned long *)kernel_stack_pointer(regs);
19747@@ -42,11 +42,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19748 * or above a saved flags. Eflags has bits 22-31 zero,
19749 * kernel addresses don't.
19750 */
19751+
19752+#ifdef CONFIG_PAX_KERNEXEC
19753+ return ktla_ktva(sp[0]);
19754+#else
19755 if (sp[0] >> 22)
19756 return sp[0];
19757 if (sp[1] >> 22)
19758 return sp[1];
19759 #endif
19760+
19761+#endif
19762 }
19763 return pc;
19764 }
19765diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19766index 9d9d2f9..ed344e4 100644
19767--- a/arch/x86/kernel/tls.c
19768+++ b/arch/x86/kernel/tls.c
19769@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19770 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19771 return -EINVAL;
19772
19773+#ifdef CONFIG_PAX_SEGMEXEC
19774+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19775+ return -EINVAL;
19776+#endif
19777+
19778 set_tls_desc(p, idx, &info, 1);
19779
19780 return 0;
19781diff --git a/arch/x86/kernel/trampoline_32.S b/arch/x86/kernel/trampoline_32.S
19782index 451c0a7..e57f551 100644
19783--- a/arch/x86/kernel/trampoline_32.S
19784+++ b/arch/x86/kernel/trampoline_32.S
19785@@ -32,6 +32,12 @@
19786 #include <asm/segment.h>
19787 #include <asm/page_types.h>
19788
19789+#ifdef CONFIG_PAX_KERNEXEC
19790+#define ta(X) (X)
19791+#else
19792+#define ta(X) ((X) - __PAGE_OFFSET)
19793+#endif
19794+
19795 #ifdef CONFIG_SMP
19796
19797 .section ".x86_trampoline","a"
19798@@ -62,7 +68,7 @@ r_base = .
19799 inc %ax # protected mode (PE) bit
19800 lmsw %ax # into protected mode
19801 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
19802- ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
19803+ ljmpl $__BOOT_CS, $ta(startup_32_smp)
19804
19805 # These need to be in the same 64K segment as the above;
19806 # hence we don't use the boot_gdt_descr defined in head.S
19807diff --git a/arch/x86/kernel/trampoline_64.S b/arch/x86/kernel/trampoline_64.S
19808index 09ff517..df19fbff 100644
19809--- a/arch/x86/kernel/trampoline_64.S
19810+++ b/arch/x86/kernel/trampoline_64.S
19811@@ -90,7 +90,7 @@ startup_32:
19812 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
19813 movl %eax, %ds
19814
19815- movl $X86_CR4_PAE, %eax
19816+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
19817 movl %eax, %cr4 # Enable PAE mode
19818
19819 # Setup trampoline 4 level pagetables
19820@@ -138,7 +138,7 @@ tidt:
19821 # so the kernel can live anywhere
19822 .balign 4
19823 tgdt:
19824- .short tgdt_end - tgdt # gdt limit
19825+ .short tgdt_end - tgdt - 1 # gdt limit
19826 .long tgdt - r_base
19827 .short 0
19828 .quad 0x00cf9b000000ffff # __KERNEL32_CS
19829diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19830index ff9281f1..30cb4ac 100644
19831--- a/arch/x86/kernel/traps.c
19832+++ b/arch/x86/kernel/traps.c
19833@@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19834
19835 /* Do we ignore FPU interrupts ? */
19836 char ignore_fpu_irq;
19837-
19838-/*
19839- * The IDT has to be page-aligned to simplify the Pentium
19840- * F0 0F bug workaround.
19841- */
19842-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19843 #endif
19844
19845 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19846@@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19847 }
19848
19849 static void __kprobes
19850-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19851+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19852 long error_code, siginfo_t *info)
19853 {
19854 struct task_struct *tsk = current;
19855
19856 #ifdef CONFIG_X86_32
19857- if (regs->flags & X86_VM_MASK) {
19858+ if (v8086_mode(regs)) {
19859 /*
19860 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19861 * On nmi (interrupt 2), do_trap should not be called.
19862@@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19863 }
19864 #endif
19865
19866- if (!user_mode(regs))
19867+ if (!user_mode_novm(regs))
19868 goto kernel_trap;
19869
19870 #ifdef CONFIG_X86_32
19871@@ -148,7 +142,7 @@ trap_signal:
19872 printk_ratelimit()) {
19873 printk(KERN_INFO
19874 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19875- tsk->comm, tsk->pid, str,
19876+ tsk->comm, task_pid_nr(tsk), str,
19877 regs->ip, regs->sp, error_code);
19878 print_vma_addr(" in ", regs->ip);
19879 printk("\n");
19880@@ -165,8 +159,20 @@ kernel_trap:
19881 if (!fixup_exception(regs)) {
19882 tsk->thread.error_code = error_code;
19883 tsk->thread.trap_nr = trapnr;
19884+
19885+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19886+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19887+ str = "PAX: suspicious stack segment fault";
19888+#endif
19889+
19890 die(str, regs, error_code);
19891 }
19892+
19893+#ifdef CONFIG_PAX_REFCOUNT
19894+ if (trapnr == 4)
19895+ pax_report_refcount_overflow(regs);
19896+#endif
19897+
19898 return;
19899
19900 #ifdef CONFIG_X86_32
19901@@ -259,14 +265,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19902 conditional_sti(regs);
19903
19904 #ifdef CONFIG_X86_32
19905- if (regs->flags & X86_VM_MASK)
19906+ if (v8086_mode(regs))
19907 goto gp_in_vm86;
19908 #endif
19909
19910 tsk = current;
19911- if (!user_mode(regs))
19912+ if (!user_mode_novm(regs))
19913 goto gp_in_kernel;
19914
19915+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19916+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19917+ struct mm_struct *mm = tsk->mm;
19918+ unsigned long limit;
19919+
19920+ down_write(&mm->mmap_sem);
19921+ limit = mm->context.user_cs_limit;
19922+ if (limit < TASK_SIZE) {
19923+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19924+ up_write(&mm->mmap_sem);
19925+ return;
19926+ }
19927+ up_write(&mm->mmap_sem);
19928+ }
19929+#endif
19930+
19931 tsk->thread.error_code = error_code;
19932 tsk->thread.trap_nr = X86_TRAP_GP;
19933
19934@@ -299,6 +321,13 @@ gp_in_kernel:
19935 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19936 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19937 return;
19938+
19939+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19940+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19941+ die("PAX: suspicious general protection fault", regs, error_code);
19942+ else
19943+#endif
19944+
19945 die("general protection fault", regs, error_code);
19946 }
19947
19948@@ -425,7 +454,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19949 /* It's safe to allow irq's after DR6 has been saved */
19950 preempt_conditional_sti(regs);
19951
19952- if (regs->flags & X86_VM_MASK) {
19953+ if (v8086_mode(regs)) {
19954 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
19955 X86_TRAP_DB);
19956 preempt_conditional_cli(regs);
19957@@ -440,7 +469,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19958 * We already checked v86 mode above, so we can check for kernel mode
19959 * by just checking the CPL of CS.
19960 */
19961- if ((dr6 & DR_STEP) && !user_mode(regs)) {
19962+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19963 tsk->thread.debugreg6 &= ~DR_STEP;
19964 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19965 regs->flags &= ~X86_EFLAGS_TF;
19966@@ -471,7 +500,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19967 return;
19968 conditional_sti(regs);
19969
19970- if (!user_mode_vm(regs))
19971+ if (!user_mode(regs))
19972 {
19973 if (!fixup_exception(regs)) {
19974 task->thread.error_code = error_code;
19975diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19976index b9242ba..50c5edd 100644
19977--- a/arch/x86/kernel/verify_cpu.S
19978+++ b/arch/x86/kernel/verify_cpu.S
19979@@ -20,6 +20,7 @@
19980 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19981 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19982 * arch/x86/kernel/head_32.S: processor startup
19983+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19984 *
19985 * verify_cpu, returns the status of longmode and SSE in register %eax.
19986 * 0: Success 1: Failure
19987diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19988index 255f58a..5e91150 100644
19989--- a/arch/x86/kernel/vm86_32.c
19990+++ b/arch/x86/kernel/vm86_32.c
19991@@ -41,6 +41,7 @@
19992 #include <linux/ptrace.h>
19993 #include <linux/audit.h>
19994 #include <linux/stddef.h>
19995+#include <linux/grsecurity.h>
19996
19997 #include <asm/uaccess.h>
19998 #include <asm/io.h>
19999@@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
20000 do_exit(SIGSEGV);
20001 }
20002
20003- tss = &per_cpu(init_tss, get_cpu());
20004+ tss = init_tss + get_cpu();
20005 current->thread.sp0 = current->thread.saved_sp0;
20006 current->thread.sysenter_cs = __KERNEL_CS;
20007 load_sp0(tss, &current->thread);
20008@@ -210,6 +211,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
20009 struct task_struct *tsk;
20010 int tmp, ret = -EPERM;
20011
20012+#ifdef CONFIG_GRKERNSEC_VM86
20013+ if (!capable(CAP_SYS_RAWIO)) {
20014+ gr_handle_vm86();
20015+ goto out;
20016+ }
20017+#endif
20018+
20019 tsk = current;
20020 if (tsk->thread.saved_sp0)
20021 goto out;
20022@@ -240,6 +248,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
20023 int tmp, ret;
20024 struct vm86plus_struct __user *v86;
20025
20026+#ifdef CONFIG_GRKERNSEC_VM86
20027+ if (!capable(CAP_SYS_RAWIO)) {
20028+ gr_handle_vm86();
20029+ ret = -EPERM;
20030+ goto out;
20031+ }
20032+#endif
20033+
20034 tsk = current;
20035 switch (cmd) {
20036 case VM86_REQUEST_IRQ:
20037@@ -326,7 +342,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
20038 tsk->thread.saved_fs = info->regs32->fs;
20039 tsk->thread.saved_gs = get_user_gs(info->regs32);
20040
20041- tss = &per_cpu(init_tss, get_cpu());
20042+ tss = init_tss + get_cpu();
20043 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
20044 if (cpu_has_sep)
20045 tsk->thread.sysenter_cs = 0;
20046@@ -533,7 +549,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
20047 goto cannot_handle;
20048 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
20049 goto cannot_handle;
20050- intr_ptr = (unsigned long __user *) (i << 2);
20051+ intr_ptr = (__force unsigned long __user *) (i << 2);
20052 if (get_user(segoffs, intr_ptr))
20053 goto cannot_handle;
20054 if ((segoffs >> 16) == BIOSSEG)
20055diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
20056index 0f703f1..9e15f64 100644
20057--- a/arch/x86/kernel/vmlinux.lds.S
20058+++ b/arch/x86/kernel/vmlinux.lds.S
20059@@ -26,6 +26,13 @@
20060 #include <asm/page_types.h>
20061 #include <asm/cache.h>
20062 #include <asm/boot.h>
20063+#include <asm/segment.h>
20064+
20065+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20066+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
20067+#else
20068+#define __KERNEL_TEXT_OFFSET 0
20069+#endif
20070
20071 #undef i386 /* in case the preprocessor is a 32bit one */
20072
20073@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
20074
20075 PHDRS {
20076 text PT_LOAD FLAGS(5); /* R_E */
20077+#ifdef CONFIG_X86_32
20078+ module PT_LOAD FLAGS(5); /* R_E */
20079+#endif
20080+#ifdef CONFIG_XEN
20081+ rodata PT_LOAD FLAGS(5); /* R_E */
20082+#else
20083+ rodata PT_LOAD FLAGS(4); /* R__ */
20084+#endif
20085 data PT_LOAD FLAGS(6); /* RW_ */
20086-#ifdef CONFIG_X86_64
20087+ init.begin PT_LOAD FLAGS(6); /* RW_ */
20088 #ifdef CONFIG_SMP
20089 percpu PT_LOAD FLAGS(6); /* RW_ */
20090 #endif
20091+ text.init PT_LOAD FLAGS(5); /* R_E */
20092+ text.exit PT_LOAD FLAGS(5); /* R_E */
20093 init PT_LOAD FLAGS(7); /* RWE */
20094-#endif
20095 note PT_NOTE FLAGS(0); /* ___ */
20096 }
20097
20098 SECTIONS
20099 {
20100 #ifdef CONFIG_X86_32
20101- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
20102- phys_startup_32 = startup_32 - LOAD_OFFSET;
20103+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
20104 #else
20105- . = __START_KERNEL;
20106- phys_startup_64 = startup_64 - LOAD_OFFSET;
20107+ . = __START_KERNEL;
20108 #endif
20109
20110 /* Text and read-only data */
20111- .text : AT(ADDR(.text) - LOAD_OFFSET) {
20112- _text = .;
20113+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20114 /* bootstrapping code */
20115+#ifdef CONFIG_X86_32
20116+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20117+#else
20118+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20119+#endif
20120+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20121+ _text = .;
20122 HEAD_TEXT
20123 #ifdef CONFIG_X86_32
20124 . = ALIGN(PAGE_SIZE);
20125@@ -108,13 +128,47 @@ SECTIONS
20126 IRQENTRY_TEXT
20127 *(.fixup)
20128 *(.gnu.warning)
20129- /* End of text section */
20130- _etext = .;
20131 } :text = 0x9090
20132
20133- NOTES :text :note
20134+ . += __KERNEL_TEXT_OFFSET;
20135
20136- EXCEPTION_TABLE(16) :text = 0x9090
20137+#ifdef CONFIG_X86_32
20138+ . = ALIGN(PAGE_SIZE);
20139+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
20140+
20141+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
20142+ MODULES_EXEC_VADDR = .;
20143+ BYTE(0)
20144+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
20145+ . = ALIGN(HPAGE_SIZE);
20146+ MODULES_EXEC_END = . - 1;
20147+#endif
20148+
20149+ } :module
20150+#endif
20151+
20152+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20153+ /* End of text section */
20154+ _etext = . - __KERNEL_TEXT_OFFSET;
20155+ }
20156+
20157+#ifdef CONFIG_X86_32
20158+ . = ALIGN(PAGE_SIZE);
20159+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20160+ *(.idt)
20161+ . = ALIGN(PAGE_SIZE);
20162+ *(.empty_zero_page)
20163+ *(.initial_pg_fixmap)
20164+ *(.initial_pg_pmd)
20165+ *(.initial_page_table)
20166+ *(.swapper_pg_dir)
20167+ } :rodata
20168+#endif
20169+
20170+ . = ALIGN(PAGE_SIZE);
20171+ NOTES :rodata :note
20172+
20173+ EXCEPTION_TABLE(16) :rodata
20174
20175 #if defined(CONFIG_DEBUG_RODATA)
20176 /* .text should occupy whole number of pages */
20177@@ -126,16 +180,20 @@ SECTIONS
20178
20179 /* Data */
20180 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20181+
20182+#ifdef CONFIG_PAX_KERNEXEC
20183+ . = ALIGN(HPAGE_SIZE);
20184+#else
20185+ . = ALIGN(PAGE_SIZE);
20186+#endif
20187+
20188 /* Start of data section */
20189 _sdata = .;
20190
20191 /* init_task */
20192 INIT_TASK_DATA(THREAD_SIZE)
20193
20194-#ifdef CONFIG_X86_32
20195- /* 32 bit has nosave before _edata */
20196 NOSAVE_DATA
20197-#endif
20198
20199 PAGE_ALIGNED_DATA(PAGE_SIZE)
20200
20201@@ -176,12 +234,19 @@ SECTIONS
20202 #endif /* CONFIG_X86_64 */
20203
20204 /* Init code and data - will be freed after init */
20205- . = ALIGN(PAGE_SIZE);
20206 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20207+ BYTE(0)
20208+
20209+#ifdef CONFIG_PAX_KERNEXEC
20210+ . = ALIGN(HPAGE_SIZE);
20211+#else
20212+ . = ALIGN(PAGE_SIZE);
20213+#endif
20214+
20215 __init_begin = .; /* paired with __init_end */
20216- }
20217+ } :init.begin
20218
20219-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20220+#ifdef CONFIG_SMP
20221 /*
20222 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20223 * output PHDR, so the next output section - .init.text - should
20224@@ -190,12 +255,27 @@ SECTIONS
20225 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20226 #endif
20227
20228- INIT_TEXT_SECTION(PAGE_SIZE)
20229-#ifdef CONFIG_X86_64
20230- :init
20231-#endif
20232+ . = ALIGN(PAGE_SIZE);
20233+ init_begin = .;
20234+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20235+ VMLINUX_SYMBOL(_sinittext) = .;
20236+ INIT_TEXT
20237+ VMLINUX_SYMBOL(_einittext) = .;
20238+ . = ALIGN(PAGE_SIZE);
20239+ } :text.init
20240
20241- INIT_DATA_SECTION(16)
20242+ /*
20243+ * .exit.text is discard at runtime, not link time, to deal with
20244+ * references from .altinstructions and .eh_frame
20245+ */
20246+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20247+ EXIT_TEXT
20248+ . = ALIGN(16);
20249+ } :text.exit
20250+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20251+
20252+ . = ALIGN(PAGE_SIZE);
20253+ INIT_DATA_SECTION(16) :init
20254
20255 /*
20256 * Code and data for a variety of lowlevel trampolines, to be
20257@@ -269,19 +349,12 @@ SECTIONS
20258 }
20259
20260 . = ALIGN(8);
20261- /*
20262- * .exit.text is discard at runtime, not link time, to deal with
20263- * references from .altinstructions and .eh_frame
20264- */
20265- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20266- EXIT_TEXT
20267- }
20268
20269 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20270 EXIT_DATA
20271 }
20272
20273-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20274+#ifndef CONFIG_SMP
20275 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20276 #endif
20277
20278@@ -300,16 +373,10 @@ SECTIONS
20279 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20280 __smp_locks = .;
20281 *(.smp_locks)
20282- . = ALIGN(PAGE_SIZE);
20283 __smp_locks_end = .;
20284+ . = ALIGN(PAGE_SIZE);
20285 }
20286
20287-#ifdef CONFIG_X86_64
20288- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20289- NOSAVE_DATA
20290- }
20291-#endif
20292-
20293 /* BSS */
20294 . = ALIGN(PAGE_SIZE);
20295 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20296@@ -325,6 +392,7 @@ SECTIONS
20297 __brk_base = .;
20298 . += 64 * 1024; /* 64k alignment slop space */
20299 *(.brk_reservation) /* areas brk users have reserved */
20300+ . = ALIGN(HPAGE_SIZE);
20301 __brk_limit = .;
20302 }
20303
20304@@ -351,13 +419,12 @@ SECTIONS
20305 * for the boot processor.
20306 */
20307 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20308-INIT_PER_CPU(gdt_page);
20309 INIT_PER_CPU(irq_stack_union);
20310
20311 /*
20312 * Build-time check on the image size:
20313 */
20314-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20315+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20316 "kernel image bigger than KERNEL_IMAGE_SIZE");
20317
20318 #ifdef CONFIG_SMP
20319diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20320index 7515cf0..331a1a0 100644
20321--- a/arch/x86/kernel/vsyscall_64.c
20322+++ b/arch/x86/kernel/vsyscall_64.c
20323@@ -54,15 +54,13 @@
20324 DEFINE_VVAR(int, vgetcpu_mode);
20325 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20326
20327-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20328+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20329
20330 static int __init vsyscall_setup(char *str)
20331 {
20332 if (str) {
20333 if (!strcmp("emulate", str))
20334 vsyscall_mode = EMULATE;
20335- else if (!strcmp("native", str))
20336- vsyscall_mode = NATIVE;
20337 else if (!strcmp("none", str))
20338 vsyscall_mode = NONE;
20339 else
20340@@ -206,7 +204,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
20341
20342 tsk = current;
20343 if (seccomp_mode(&tsk->seccomp))
20344- do_exit(SIGKILL);
20345+ do_group_exit(SIGKILL);
20346
20347 /*
20348 * With a real vsyscall, page faults cause SIGSEGV. We want to
20349@@ -278,8 +276,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
20350 return true;
20351
20352 sigsegv:
20353- force_sig(SIGSEGV, current);
20354- return true;
20355+ do_group_exit(SIGKILL);
20356 }
20357
20358 /*
20359@@ -332,10 +329,7 @@ void __init map_vsyscall(void)
20360 extern char __vvar_page;
20361 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20362
20363- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20364- vsyscall_mode == NATIVE
20365- ? PAGE_KERNEL_VSYSCALL
20366- : PAGE_KERNEL_VVAR);
20367+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20368 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20369 (unsigned long)VSYSCALL_START);
20370
20371diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20372index 9796c2f..f686fbf 100644
20373--- a/arch/x86/kernel/x8664_ksyms_64.c
20374+++ b/arch/x86/kernel/x8664_ksyms_64.c
20375@@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
20376 EXPORT_SYMBOL(copy_user_generic_string);
20377 EXPORT_SYMBOL(copy_user_generic_unrolled);
20378 EXPORT_SYMBOL(__copy_user_nocache);
20379-EXPORT_SYMBOL(_copy_from_user);
20380-EXPORT_SYMBOL(_copy_to_user);
20381
20382 EXPORT_SYMBOL(copy_page);
20383 EXPORT_SYMBOL(clear_page);
20384diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20385index e62728e..5fc3a07 100644
20386--- a/arch/x86/kernel/xsave.c
20387+++ b/arch/x86/kernel/xsave.c
20388@@ -131,7 +131,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20389 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20390 return -EINVAL;
20391
20392- err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20393+ err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20394 fx_sw_user->extended_size -
20395 FP_XSTATE_MAGIC2_SIZE));
20396 if (err)
20397@@ -267,7 +267,7 @@ fx_only:
20398 * the other extended state.
20399 */
20400 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20401- return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20402+ return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20403 }
20404
20405 /*
20406@@ -296,7 +296,7 @@ int restore_i387_xstate(void __user *buf)
20407 if (use_xsave())
20408 err = restore_user_xstate(buf);
20409 else
20410- err = fxrstor_checking((__force struct i387_fxsave_struct *)
20411+ err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20412 buf);
20413 if (unlikely(err)) {
20414 /*
20415diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20416index 9fed5be..18fd595 100644
20417--- a/arch/x86/kvm/cpuid.c
20418+++ b/arch/x86/kvm/cpuid.c
20419@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20420 struct kvm_cpuid2 *cpuid,
20421 struct kvm_cpuid_entry2 __user *entries)
20422 {
20423- int r;
20424+ int r, i;
20425
20426 r = -E2BIG;
20427 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20428 goto out;
20429 r = -EFAULT;
20430- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20431- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20432+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20433 goto out;
20434+ for (i = 0; i < cpuid->nent; ++i) {
20435+ struct kvm_cpuid_entry2 cpuid_entry;
20436+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20437+ goto out;
20438+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
20439+ }
20440 vcpu->arch.cpuid_nent = cpuid->nent;
20441 kvm_apic_set_version(vcpu);
20442 kvm_x86_ops->cpuid_update(vcpu);
20443@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20444 struct kvm_cpuid2 *cpuid,
20445 struct kvm_cpuid_entry2 __user *entries)
20446 {
20447- int r;
20448+ int r, i;
20449
20450 r = -E2BIG;
20451 if (cpuid->nent < vcpu->arch.cpuid_nent)
20452 goto out;
20453 r = -EFAULT;
20454- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20455- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20456+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20457 goto out;
20458+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20459+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20460+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20461+ goto out;
20462+ }
20463 return 0;
20464
20465 out:
20466diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20467index 8375622..b7bca1a 100644
20468--- a/arch/x86/kvm/emulate.c
20469+++ b/arch/x86/kvm/emulate.c
20470@@ -252,6 +252,7 @@ struct gprefix {
20471
20472 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20473 do { \
20474+ unsigned long _tmp; \
20475 __asm__ __volatile__ ( \
20476 _PRE_EFLAGS("0", "4", "2") \
20477 _op _suffix " %"_x"3,%1; " \
20478@@ -266,8 +267,6 @@ struct gprefix {
20479 /* Raw emulation: instruction has two explicit operands. */
20480 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20481 do { \
20482- unsigned long _tmp; \
20483- \
20484 switch ((ctxt)->dst.bytes) { \
20485 case 2: \
20486 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20487@@ -283,7 +282,6 @@ struct gprefix {
20488
20489 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20490 do { \
20491- unsigned long _tmp; \
20492 switch ((ctxt)->dst.bytes) { \
20493 case 1: \
20494 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20495diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20496index 8584322..17d5955 100644
20497--- a/arch/x86/kvm/lapic.c
20498+++ b/arch/x86/kvm/lapic.c
20499@@ -54,7 +54,7 @@
20500 #define APIC_BUS_CYCLE_NS 1
20501
20502 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20503-#define apic_debug(fmt, arg...)
20504+#define apic_debug(fmt, arg...) do {} while (0)
20505
20506 #define APIC_LVT_NUM 6
20507 /* 14 is the version for Xeon and Pentium 8.4.8*/
20508diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20509index df5a703..63748a7 100644
20510--- a/arch/x86/kvm/paging_tmpl.h
20511+++ b/arch/x86/kvm/paging_tmpl.h
20512@@ -197,7 +197,7 @@ retry_walk:
20513 if (unlikely(kvm_is_error_hva(host_addr)))
20514 goto error;
20515
20516- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20517+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20518 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20519 goto error;
20520
20521diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20522index e334389..6839087 100644
20523--- a/arch/x86/kvm/svm.c
20524+++ b/arch/x86/kvm/svm.c
20525@@ -3509,7 +3509,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20526 int cpu = raw_smp_processor_id();
20527
20528 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20529+
20530+ pax_open_kernel();
20531 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20532+ pax_close_kernel();
20533+
20534 load_TR_desc();
20535 }
20536
20537@@ -3887,6 +3891,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20538 #endif
20539 #endif
20540
20541+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20542+ __set_fs(current_thread_info()->addr_limit);
20543+#endif
20544+
20545 reload_tss(vcpu);
20546
20547 local_irq_disable();
20548diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20549index 4ff0ab9..2ff68d3 100644
20550--- a/arch/x86/kvm/vmx.c
20551+++ b/arch/x86/kvm/vmx.c
20552@@ -1303,7 +1303,11 @@ static void reload_tss(void)
20553 struct desc_struct *descs;
20554
20555 descs = (void *)gdt->address;
20556+
20557+ pax_open_kernel();
20558 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20559+ pax_close_kernel();
20560+
20561 load_TR_desc();
20562 }
20563
20564@@ -2625,8 +2629,11 @@ static __init int hardware_setup(void)
20565 if (!cpu_has_vmx_flexpriority())
20566 flexpriority_enabled = 0;
20567
20568- if (!cpu_has_vmx_tpr_shadow())
20569- kvm_x86_ops->update_cr8_intercept = NULL;
20570+ if (!cpu_has_vmx_tpr_shadow()) {
20571+ pax_open_kernel();
20572+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20573+ pax_close_kernel();
20574+ }
20575
20576 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20577 kvm_disable_largepages();
20578@@ -3642,7 +3649,7 @@ static void vmx_set_constant_host_state(void)
20579 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20580
20581 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20582- vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20583+ vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20584
20585 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20586 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20587@@ -6180,6 +6187,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20588 "jmp .Lkvm_vmx_return \n\t"
20589 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20590 ".Lkvm_vmx_return: "
20591+
20592+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20593+ "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20594+ ".Lkvm_vmx_return2: "
20595+#endif
20596+
20597 /* Save guest registers, load host registers, keep flags */
20598 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20599 "pop %0 \n\t"
20600@@ -6228,6 +6241,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20601 #endif
20602 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20603 [wordsize]"i"(sizeof(ulong))
20604+
20605+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20606+ ,[cs]"i"(__KERNEL_CS)
20607+#endif
20608+
20609 : "cc", "memory"
20610 , R"ax", R"bx", R"di", R"si"
20611 #ifdef CONFIG_X86_64
20612@@ -6256,7 +6274,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20613 }
20614 }
20615
20616- asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
20617+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
20618+
20619+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20620+ loadsegment(fs, __KERNEL_PERCPU);
20621+#endif
20622+
20623+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20624+ __set_fs(current_thread_info()->addr_limit);
20625+#endif
20626+
20627 vmx->loaded_vmcs->launched = 1;
20628
20629 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
20630diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20631index 185a2b8..866d2a6 100644
20632--- a/arch/x86/kvm/x86.c
20633+++ b/arch/x86/kvm/x86.c
20634@@ -1357,8 +1357,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20635 {
20636 struct kvm *kvm = vcpu->kvm;
20637 int lm = is_long_mode(vcpu);
20638- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20639- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20640+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20641+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20642 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20643 : kvm->arch.xen_hvm_config.blob_size_32;
20644 u32 page_num = data & ~PAGE_MASK;
20645@@ -2213,6 +2213,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20646 if (n < msr_list.nmsrs)
20647 goto out;
20648 r = -EFAULT;
20649+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20650+ goto out;
20651 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20652 num_msrs_to_save * sizeof(u32)))
20653 goto out;
20654@@ -2338,7 +2340,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20655 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20656 struct kvm_interrupt *irq)
20657 {
20658- if (irq->irq < 0 || irq->irq >= 256)
20659+ if (irq->irq >= 256)
20660 return -EINVAL;
20661 if (irqchip_in_kernel(vcpu->kvm))
20662 return -ENXIO;
20663@@ -4860,7 +4862,7 @@ static void kvm_set_mmio_spte_mask(void)
20664 kvm_mmu_set_mmio_spte_mask(mask);
20665 }
20666
20667-int kvm_arch_init(void *opaque)
20668+int kvm_arch_init(const void *opaque)
20669 {
20670 int r;
20671 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20672diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20673index 642d880..44e0f3f 100644
20674--- a/arch/x86/lguest/boot.c
20675+++ b/arch/x86/lguest/boot.c
20676@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20677 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20678 * Launcher to reboot us.
20679 */
20680-static void lguest_restart(char *reason)
20681+static __noreturn void lguest_restart(char *reason)
20682 {
20683 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20684+ BUG();
20685 }
20686
20687 /*G:050
20688diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20689index 00933d5..3a64af9 100644
20690--- a/arch/x86/lib/atomic64_386_32.S
20691+++ b/arch/x86/lib/atomic64_386_32.S
20692@@ -48,6 +48,10 @@ BEGIN(read)
20693 movl (v), %eax
20694 movl 4(v), %edx
20695 RET_ENDP
20696+BEGIN(read_unchecked)
20697+ movl (v), %eax
20698+ movl 4(v), %edx
20699+RET_ENDP
20700 #undef v
20701
20702 #define v %esi
20703@@ -55,6 +59,10 @@ BEGIN(set)
20704 movl %ebx, (v)
20705 movl %ecx, 4(v)
20706 RET_ENDP
20707+BEGIN(set_unchecked)
20708+ movl %ebx, (v)
20709+ movl %ecx, 4(v)
20710+RET_ENDP
20711 #undef v
20712
20713 #define v %esi
20714@@ -70,6 +78,20 @@ RET_ENDP
20715 BEGIN(add)
20716 addl %eax, (v)
20717 adcl %edx, 4(v)
20718+
20719+#ifdef CONFIG_PAX_REFCOUNT
20720+ jno 0f
20721+ subl %eax, (v)
20722+ sbbl %edx, 4(v)
20723+ int $4
20724+0:
20725+ _ASM_EXTABLE(0b, 0b)
20726+#endif
20727+
20728+RET_ENDP
20729+BEGIN(add_unchecked)
20730+ addl %eax, (v)
20731+ adcl %edx, 4(v)
20732 RET_ENDP
20733 #undef v
20734
20735@@ -77,6 +99,24 @@ RET_ENDP
20736 BEGIN(add_return)
20737 addl (v), %eax
20738 adcl 4(v), %edx
20739+
20740+#ifdef CONFIG_PAX_REFCOUNT
20741+ into
20742+1234:
20743+ _ASM_EXTABLE(1234b, 2f)
20744+#endif
20745+
20746+ movl %eax, (v)
20747+ movl %edx, 4(v)
20748+
20749+#ifdef CONFIG_PAX_REFCOUNT
20750+2:
20751+#endif
20752+
20753+RET_ENDP
20754+BEGIN(add_return_unchecked)
20755+ addl (v), %eax
20756+ adcl 4(v), %edx
20757 movl %eax, (v)
20758 movl %edx, 4(v)
20759 RET_ENDP
20760@@ -86,6 +126,20 @@ RET_ENDP
20761 BEGIN(sub)
20762 subl %eax, (v)
20763 sbbl %edx, 4(v)
20764+
20765+#ifdef CONFIG_PAX_REFCOUNT
20766+ jno 0f
20767+ addl %eax, (v)
20768+ adcl %edx, 4(v)
20769+ int $4
20770+0:
20771+ _ASM_EXTABLE(0b, 0b)
20772+#endif
20773+
20774+RET_ENDP
20775+BEGIN(sub_unchecked)
20776+ subl %eax, (v)
20777+ sbbl %edx, 4(v)
20778 RET_ENDP
20779 #undef v
20780
20781@@ -96,6 +150,27 @@ BEGIN(sub_return)
20782 sbbl $0, %edx
20783 addl (v), %eax
20784 adcl 4(v), %edx
20785+
20786+#ifdef CONFIG_PAX_REFCOUNT
20787+ into
20788+1234:
20789+ _ASM_EXTABLE(1234b, 2f)
20790+#endif
20791+
20792+ movl %eax, (v)
20793+ movl %edx, 4(v)
20794+
20795+#ifdef CONFIG_PAX_REFCOUNT
20796+2:
20797+#endif
20798+
20799+RET_ENDP
20800+BEGIN(sub_return_unchecked)
20801+ negl %edx
20802+ negl %eax
20803+ sbbl $0, %edx
20804+ addl (v), %eax
20805+ adcl 4(v), %edx
20806 movl %eax, (v)
20807 movl %edx, 4(v)
20808 RET_ENDP
20809@@ -105,6 +180,20 @@ RET_ENDP
20810 BEGIN(inc)
20811 addl $1, (v)
20812 adcl $0, 4(v)
20813+
20814+#ifdef CONFIG_PAX_REFCOUNT
20815+ jno 0f
20816+ subl $1, (v)
20817+ sbbl $0, 4(v)
20818+ int $4
20819+0:
20820+ _ASM_EXTABLE(0b, 0b)
20821+#endif
20822+
20823+RET_ENDP
20824+BEGIN(inc_unchecked)
20825+ addl $1, (v)
20826+ adcl $0, 4(v)
20827 RET_ENDP
20828 #undef v
20829
20830@@ -114,6 +203,26 @@ BEGIN(inc_return)
20831 movl 4(v), %edx
20832 addl $1, %eax
20833 adcl $0, %edx
20834+
20835+#ifdef CONFIG_PAX_REFCOUNT
20836+ into
20837+1234:
20838+ _ASM_EXTABLE(1234b, 2f)
20839+#endif
20840+
20841+ movl %eax, (v)
20842+ movl %edx, 4(v)
20843+
20844+#ifdef CONFIG_PAX_REFCOUNT
20845+2:
20846+#endif
20847+
20848+RET_ENDP
20849+BEGIN(inc_return_unchecked)
20850+ movl (v), %eax
20851+ movl 4(v), %edx
20852+ addl $1, %eax
20853+ adcl $0, %edx
20854 movl %eax, (v)
20855 movl %edx, 4(v)
20856 RET_ENDP
20857@@ -123,6 +232,20 @@ RET_ENDP
20858 BEGIN(dec)
20859 subl $1, (v)
20860 sbbl $0, 4(v)
20861+
20862+#ifdef CONFIG_PAX_REFCOUNT
20863+ jno 0f
20864+ addl $1, (v)
20865+ adcl $0, 4(v)
20866+ int $4
20867+0:
20868+ _ASM_EXTABLE(0b, 0b)
20869+#endif
20870+
20871+RET_ENDP
20872+BEGIN(dec_unchecked)
20873+ subl $1, (v)
20874+ sbbl $0, 4(v)
20875 RET_ENDP
20876 #undef v
20877
20878@@ -132,6 +255,26 @@ BEGIN(dec_return)
20879 movl 4(v), %edx
20880 subl $1, %eax
20881 sbbl $0, %edx
20882+
20883+#ifdef CONFIG_PAX_REFCOUNT
20884+ into
20885+1234:
20886+ _ASM_EXTABLE(1234b, 2f)
20887+#endif
20888+
20889+ movl %eax, (v)
20890+ movl %edx, 4(v)
20891+
20892+#ifdef CONFIG_PAX_REFCOUNT
20893+2:
20894+#endif
20895+
20896+RET_ENDP
20897+BEGIN(dec_return_unchecked)
20898+ movl (v), %eax
20899+ movl 4(v), %edx
20900+ subl $1, %eax
20901+ sbbl $0, %edx
20902 movl %eax, (v)
20903 movl %edx, 4(v)
20904 RET_ENDP
20905@@ -143,6 +286,13 @@ BEGIN(add_unless)
20906 adcl %edx, %edi
20907 addl (v), %eax
20908 adcl 4(v), %edx
20909+
20910+#ifdef CONFIG_PAX_REFCOUNT
20911+ into
20912+1234:
20913+ _ASM_EXTABLE(1234b, 2f)
20914+#endif
20915+
20916 cmpl %eax, %ecx
20917 je 3f
20918 1:
20919@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20920 1:
20921 addl $1, %eax
20922 adcl $0, %edx
20923+
20924+#ifdef CONFIG_PAX_REFCOUNT
20925+ into
20926+1234:
20927+ _ASM_EXTABLE(1234b, 2f)
20928+#endif
20929+
20930 movl %eax, (v)
20931 movl %edx, 4(v)
20932 movl $1, %eax
20933@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20934 movl 4(v), %edx
20935 subl $1, %eax
20936 sbbl $0, %edx
20937+
20938+#ifdef CONFIG_PAX_REFCOUNT
20939+ into
20940+1234:
20941+ _ASM_EXTABLE(1234b, 1f)
20942+#endif
20943+
20944 js 1f
20945 movl %eax, (v)
20946 movl %edx, 4(v)
20947diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20948index f5cc9eb..51fa319 100644
20949--- a/arch/x86/lib/atomic64_cx8_32.S
20950+++ b/arch/x86/lib/atomic64_cx8_32.S
20951@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20952 CFI_STARTPROC
20953
20954 read64 %ecx
20955+ pax_force_retaddr
20956 ret
20957 CFI_ENDPROC
20958 ENDPROC(atomic64_read_cx8)
20959
20960+ENTRY(atomic64_read_unchecked_cx8)
20961+ CFI_STARTPROC
20962+
20963+ read64 %ecx
20964+ pax_force_retaddr
20965+ ret
20966+ CFI_ENDPROC
20967+ENDPROC(atomic64_read_unchecked_cx8)
20968+
20969 ENTRY(atomic64_set_cx8)
20970 CFI_STARTPROC
20971
20972@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20973 cmpxchg8b (%esi)
20974 jne 1b
20975
20976+ pax_force_retaddr
20977 ret
20978 CFI_ENDPROC
20979 ENDPROC(atomic64_set_cx8)
20980
20981+ENTRY(atomic64_set_unchecked_cx8)
20982+ CFI_STARTPROC
20983+
20984+1:
20985+/* we don't need LOCK_PREFIX since aligned 64-bit writes
20986+ * are atomic on 586 and newer */
20987+ cmpxchg8b (%esi)
20988+ jne 1b
20989+
20990+ pax_force_retaddr
20991+ ret
20992+ CFI_ENDPROC
20993+ENDPROC(atomic64_set_unchecked_cx8)
20994+
20995 ENTRY(atomic64_xchg_cx8)
20996 CFI_STARTPROC
20997
20998@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
20999 cmpxchg8b (%esi)
21000 jne 1b
21001
21002+ pax_force_retaddr
21003 ret
21004 CFI_ENDPROC
21005 ENDPROC(atomic64_xchg_cx8)
21006
21007-.macro addsub_return func ins insc
21008-ENTRY(atomic64_\func\()_return_cx8)
21009+.macro addsub_return func ins insc unchecked=""
21010+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21011 CFI_STARTPROC
21012 SAVE ebp
21013 SAVE ebx
21014@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
21015 movl %edx, %ecx
21016 \ins\()l %esi, %ebx
21017 \insc\()l %edi, %ecx
21018+
21019+.ifb \unchecked
21020+#ifdef CONFIG_PAX_REFCOUNT
21021+ into
21022+2:
21023+ _ASM_EXTABLE(2b, 3f)
21024+#endif
21025+.endif
21026+
21027 LOCK_PREFIX
21028 cmpxchg8b (%ebp)
21029 jne 1b
21030-
21031-10:
21032 movl %ebx, %eax
21033 movl %ecx, %edx
21034+
21035+.ifb \unchecked
21036+#ifdef CONFIG_PAX_REFCOUNT
21037+3:
21038+#endif
21039+.endif
21040+
21041 RESTORE edi
21042 RESTORE esi
21043 RESTORE ebx
21044 RESTORE ebp
21045+ pax_force_retaddr
21046 ret
21047 CFI_ENDPROC
21048-ENDPROC(atomic64_\func\()_return_cx8)
21049+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21050 .endm
21051
21052 addsub_return add add adc
21053 addsub_return sub sub sbb
21054+addsub_return add add adc _unchecked
21055+addsub_return sub sub sbb _unchecked
21056
21057-.macro incdec_return func ins insc
21058-ENTRY(atomic64_\func\()_return_cx8)
21059+.macro incdec_return func ins insc unchecked=""
21060+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21061 CFI_STARTPROC
21062 SAVE ebx
21063
21064@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
21065 movl %edx, %ecx
21066 \ins\()l $1, %ebx
21067 \insc\()l $0, %ecx
21068+
21069+.ifb \unchecked
21070+#ifdef CONFIG_PAX_REFCOUNT
21071+ into
21072+2:
21073+ _ASM_EXTABLE(2b, 3f)
21074+#endif
21075+.endif
21076+
21077 LOCK_PREFIX
21078 cmpxchg8b (%esi)
21079 jne 1b
21080
21081-10:
21082 movl %ebx, %eax
21083 movl %ecx, %edx
21084+
21085+.ifb \unchecked
21086+#ifdef CONFIG_PAX_REFCOUNT
21087+3:
21088+#endif
21089+.endif
21090+
21091 RESTORE ebx
21092+ pax_force_retaddr
21093 ret
21094 CFI_ENDPROC
21095-ENDPROC(atomic64_\func\()_return_cx8)
21096+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21097 .endm
21098
21099 incdec_return inc add adc
21100 incdec_return dec sub sbb
21101+incdec_return inc add adc _unchecked
21102+incdec_return dec sub sbb _unchecked
21103
21104 ENTRY(atomic64_dec_if_positive_cx8)
21105 CFI_STARTPROC
21106@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
21107 movl %edx, %ecx
21108 subl $1, %ebx
21109 sbb $0, %ecx
21110+
21111+#ifdef CONFIG_PAX_REFCOUNT
21112+ into
21113+1234:
21114+ _ASM_EXTABLE(1234b, 2f)
21115+#endif
21116+
21117 js 2f
21118 LOCK_PREFIX
21119 cmpxchg8b (%esi)
21120@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
21121 movl %ebx, %eax
21122 movl %ecx, %edx
21123 RESTORE ebx
21124+ pax_force_retaddr
21125 ret
21126 CFI_ENDPROC
21127 ENDPROC(atomic64_dec_if_positive_cx8)
21128@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
21129 movl %edx, %ecx
21130 addl %ebp, %ebx
21131 adcl %edi, %ecx
21132+
21133+#ifdef CONFIG_PAX_REFCOUNT
21134+ into
21135+1234:
21136+ _ASM_EXTABLE(1234b, 3f)
21137+#endif
21138+
21139 LOCK_PREFIX
21140 cmpxchg8b (%esi)
21141 jne 1b
21142@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
21143 CFI_ADJUST_CFA_OFFSET -8
21144 RESTORE ebx
21145 RESTORE ebp
21146+ pax_force_retaddr
21147 ret
21148 4:
21149 cmpl %edx, 4(%esp)
21150@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21151 xorl %ecx, %ecx
21152 addl $1, %ebx
21153 adcl %edx, %ecx
21154+
21155+#ifdef CONFIG_PAX_REFCOUNT
21156+ into
21157+1234:
21158+ _ASM_EXTABLE(1234b, 3f)
21159+#endif
21160+
21161 LOCK_PREFIX
21162 cmpxchg8b (%esi)
21163 jne 1b
21164@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21165 movl $1, %eax
21166 3:
21167 RESTORE ebx
21168+ pax_force_retaddr
21169 ret
21170 CFI_ENDPROC
21171 ENDPROC(atomic64_inc_not_zero_cx8)
21172diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21173index 78d16a5..fbcf666 100644
21174--- a/arch/x86/lib/checksum_32.S
21175+++ b/arch/x86/lib/checksum_32.S
21176@@ -28,7 +28,8 @@
21177 #include <linux/linkage.h>
21178 #include <asm/dwarf2.h>
21179 #include <asm/errno.h>
21180-
21181+#include <asm/segment.h>
21182+
21183 /*
21184 * computes a partial checksum, e.g. for TCP/UDP fragments
21185 */
21186@@ -296,9 +297,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21187
21188 #define ARGBASE 16
21189 #define FP 12
21190-
21191-ENTRY(csum_partial_copy_generic)
21192+
21193+ENTRY(csum_partial_copy_generic_to_user)
21194 CFI_STARTPROC
21195+
21196+#ifdef CONFIG_PAX_MEMORY_UDEREF
21197+ pushl_cfi %gs
21198+ popl_cfi %es
21199+ jmp csum_partial_copy_generic
21200+#endif
21201+
21202+ENTRY(csum_partial_copy_generic_from_user)
21203+
21204+#ifdef CONFIG_PAX_MEMORY_UDEREF
21205+ pushl_cfi %gs
21206+ popl_cfi %ds
21207+#endif
21208+
21209+ENTRY(csum_partial_copy_generic)
21210 subl $4,%esp
21211 CFI_ADJUST_CFA_OFFSET 4
21212 pushl_cfi %edi
21213@@ -320,7 +336,7 @@ ENTRY(csum_partial_copy_generic)
21214 jmp 4f
21215 SRC(1: movw (%esi), %bx )
21216 addl $2, %esi
21217-DST( movw %bx, (%edi) )
21218+DST( movw %bx, %es:(%edi) )
21219 addl $2, %edi
21220 addw %bx, %ax
21221 adcl $0, %eax
21222@@ -332,30 +348,30 @@ DST( movw %bx, (%edi) )
21223 SRC(1: movl (%esi), %ebx )
21224 SRC( movl 4(%esi), %edx )
21225 adcl %ebx, %eax
21226-DST( movl %ebx, (%edi) )
21227+DST( movl %ebx, %es:(%edi) )
21228 adcl %edx, %eax
21229-DST( movl %edx, 4(%edi) )
21230+DST( movl %edx, %es:4(%edi) )
21231
21232 SRC( movl 8(%esi), %ebx )
21233 SRC( movl 12(%esi), %edx )
21234 adcl %ebx, %eax
21235-DST( movl %ebx, 8(%edi) )
21236+DST( movl %ebx, %es:8(%edi) )
21237 adcl %edx, %eax
21238-DST( movl %edx, 12(%edi) )
21239+DST( movl %edx, %es:12(%edi) )
21240
21241 SRC( movl 16(%esi), %ebx )
21242 SRC( movl 20(%esi), %edx )
21243 adcl %ebx, %eax
21244-DST( movl %ebx, 16(%edi) )
21245+DST( movl %ebx, %es:16(%edi) )
21246 adcl %edx, %eax
21247-DST( movl %edx, 20(%edi) )
21248+DST( movl %edx, %es:20(%edi) )
21249
21250 SRC( movl 24(%esi), %ebx )
21251 SRC( movl 28(%esi), %edx )
21252 adcl %ebx, %eax
21253-DST( movl %ebx, 24(%edi) )
21254+DST( movl %ebx, %es:24(%edi) )
21255 adcl %edx, %eax
21256-DST( movl %edx, 28(%edi) )
21257+DST( movl %edx, %es:28(%edi) )
21258
21259 lea 32(%esi), %esi
21260 lea 32(%edi), %edi
21261@@ -369,7 +385,7 @@ DST( movl %edx, 28(%edi) )
21262 shrl $2, %edx # This clears CF
21263 SRC(3: movl (%esi), %ebx )
21264 adcl %ebx, %eax
21265-DST( movl %ebx, (%edi) )
21266+DST( movl %ebx, %es:(%edi) )
21267 lea 4(%esi), %esi
21268 lea 4(%edi), %edi
21269 dec %edx
21270@@ -381,12 +397,12 @@ DST( movl %ebx, (%edi) )
21271 jb 5f
21272 SRC( movw (%esi), %cx )
21273 leal 2(%esi), %esi
21274-DST( movw %cx, (%edi) )
21275+DST( movw %cx, %es:(%edi) )
21276 leal 2(%edi), %edi
21277 je 6f
21278 shll $16,%ecx
21279 SRC(5: movb (%esi), %cl )
21280-DST( movb %cl, (%edi) )
21281+DST( movb %cl, %es:(%edi) )
21282 6: addl %ecx, %eax
21283 adcl $0, %eax
21284 7:
21285@@ -397,7 +413,7 @@ DST( movb %cl, (%edi) )
21286
21287 6001:
21288 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21289- movl $-EFAULT, (%ebx)
21290+ movl $-EFAULT, %ss:(%ebx)
21291
21292 # zero the complete destination - computing the rest
21293 # is too much work
21294@@ -410,11 +426,15 @@ DST( movb %cl, (%edi) )
21295
21296 6002:
21297 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21298- movl $-EFAULT,(%ebx)
21299+ movl $-EFAULT,%ss:(%ebx)
21300 jmp 5000b
21301
21302 .previous
21303
21304+ pushl_cfi %ss
21305+ popl_cfi %ds
21306+ pushl_cfi %ss
21307+ popl_cfi %es
21308 popl_cfi %ebx
21309 CFI_RESTORE ebx
21310 popl_cfi %esi
21311@@ -424,26 +444,43 @@ DST( movb %cl, (%edi) )
21312 popl_cfi %ecx # equivalent to addl $4,%esp
21313 ret
21314 CFI_ENDPROC
21315-ENDPROC(csum_partial_copy_generic)
21316+ENDPROC(csum_partial_copy_generic_to_user)
21317
21318 #else
21319
21320 /* Version for PentiumII/PPro */
21321
21322 #define ROUND1(x) \
21323+ nop; nop; nop; \
21324 SRC(movl x(%esi), %ebx ) ; \
21325 addl %ebx, %eax ; \
21326- DST(movl %ebx, x(%edi) ) ;
21327+ DST(movl %ebx, %es:x(%edi)) ;
21328
21329 #define ROUND(x) \
21330+ nop; nop; nop; \
21331 SRC(movl x(%esi), %ebx ) ; \
21332 adcl %ebx, %eax ; \
21333- DST(movl %ebx, x(%edi) ) ;
21334+ DST(movl %ebx, %es:x(%edi)) ;
21335
21336 #define ARGBASE 12
21337-
21338-ENTRY(csum_partial_copy_generic)
21339+
21340+ENTRY(csum_partial_copy_generic_to_user)
21341 CFI_STARTPROC
21342+
21343+#ifdef CONFIG_PAX_MEMORY_UDEREF
21344+ pushl_cfi %gs
21345+ popl_cfi %es
21346+ jmp csum_partial_copy_generic
21347+#endif
21348+
21349+ENTRY(csum_partial_copy_generic_from_user)
21350+
21351+#ifdef CONFIG_PAX_MEMORY_UDEREF
21352+ pushl_cfi %gs
21353+ popl_cfi %ds
21354+#endif
21355+
21356+ENTRY(csum_partial_copy_generic)
21357 pushl_cfi %ebx
21358 CFI_REL_OFFSET ebx, 0
21359 pushl_cfi %edi
21360@@ -464,7 +501,7 @@ ENTRY(csum_partial_copy_generic)
21361 subl %ebx, %edi
21362 lea -1(%esi),%edx
21363 andl $-32,%edx
21364- lea 3f(%ebx,%ebx), %ebx
21365+ lea 3f(%ebx,%ebx,2), %ebx
21366 testl %esi, %esi
21367 jmp *%ebx
21368 1: addl $64,%esi
21369@@ -485,19 +522,19 @@ ENTRY(csum_partial_copy_generic)
21370 jb 5f
21371 SRC( movw (%esi), %dx )
21372 leal 2(%esi), %esi
21373-DST( movw %dx, (%edi) )
21374+DST( movw %dx, %es:(%edi) )
21375 leal 2(%edi), %edi
21376 je 6f
21377 shll $16,%edx
21378 5:
21379 SRC( movb (%esi), %dl )
21380-DST( movb %dl, (%edi) )
21381+DST( movb %dl, %es:(%edi) )
21382 6: addl %edx, %eax
21383 adcl $0, %eax
21384 7:
21385 .section .fixup, "ax"
21386 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21387- movl $-EFAULT, (%ebx)
21388+ movl $-EFAULT, %ss:(%ebx)
21389 # zero the complete destination (computing the rest is too much work)
21390 movl ARGBASE+8(%esp),%edi # dst
21391 movl ARGBASE+12(%esp),%ecx # len
21392@@ -505,10 +542,17 @@ DST( movb %dl, (%edi) )
21393 rep; stosb
21394 jmp 7b
21395 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21396- movl $-EFAULT, (%ebx)
21397+ movl $-EFAULT, %ss:(%ebx)
21398 jmp 7b
21399 .previous
21400
21401+#ifdef CONFIG_PAX_MEMORY_UDEREF
21402+ pushl_cfi %ss
21403+ popl_cfi %ds
21404+ pushl_cfi %ss
21405+ popl_cfi %es
21406+#endif
21407+
21408 popl_cfi %esi
21409 CFI_RESTORE esi
21410 popl_cfi %edi
21411@@ -517,7 +561,7 @@ DST( movb %dl, (%edi) )
21412 CFI_RESTORE ebx
21413 ret
21414 CFI_ENDPROC
21415-ENDPROC(csum_partial_copy_generic)
21416+ENDPROC(csum_partial_copy_generic_to_user)
21417
21418 #undef ROUND
21419 #undef ROUND1
21420diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21421index f2145cf..cea889d 100644
21422--- a/arch/x86/lib/clear_page_64.S
21423+++ b/arch/x86/lib/clear_page_64.S
21424@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21425 movl $4096/8,%ecx
21426 xorl %eax,%eax
21427 rep stosq
21428+ pax_force_retaddr
21429 ret
21430 CFI_ENDPROC
21431 ENDPROC(clear_page_c)
21432@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21433 movl $4096,%ecx
21434 xorl %eax,%eax
21435 rep stosb
21436+ pax_force_retaddr
21437 ret
21438 CFI_ENDPROC
21439 ENDPROC(clear_page_c_e)
21440@@ -43,6 +45,7 @@ ENTRY(clear_page)
21441 leaq 64(%rdi),%rdi
21442 jnz .Lloop
21443 nop
21444+ pax_force_retaddr
21445 ret
21446 CFI_ENDPROC
21447 .Lclear_page_end:
21448@@ -58,7 +61,7 @@ ENDPROC(clear_page)
21449
21450 #include <asm/cpufeature.h>
21451
21452- .section .altinstr_replacement,"ax"
21453+ .section .altinstr_replacement,"a"
21454 1: .byte 0xeb /* jmp <disp8> */
21455 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21456 2: .byte 0xeb /* jmp <disp8> */
21457diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21458index 1e572c5..2a162cd 100644
21459--- a/arch/x86/lib/cmpxchg16b_emu.S
21460+++ b/arch/x86/lib/cmpxchg16b_emu.S
21461@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21462
21463 popf
21464 mov $1, %al
21465+ pax_force_retaddr
21466 ret
21467
21468 not_same:
21469 popf
21470 xor %al,%al
21471+ pax_force_retaddr
21472 ret
21473
21474 CFI_ENDPROC
21475diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21476index 6b34d04..dccb07f 100644
21477--- a/arch/x86/lib/copy_page_64.S
21478+++ b/arch/x86/lib/copy_page_64.S
21479@@ -9,6 +9,7 @@ copy_page_c:
21480 CFI_STARTPROC
21481 movl $4096/8,%ecx
21482 rep movsq
21483+ pax_force_retaddr
21484 ret
21485 CFI_ENDPROC
21486 ENDPROC(copy_page_c)
21487@@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21488
21489 ENTRY(copy_page)
21490 CFI_STARTPROC
21491- subq $2*8,%rsp
21492- CFI_ADJUST_CFA_OFFSET 2*8
21493+ subq $3*8,%rsp
21494+ CFI_ADJUST_CFA_OFFSET 3*8
21495 movq %rbx,(%rsp)
21496 CFI_REL_OFFSET rbx, 0
21497 movq %r12,1*8(%rsp)
21498 CFI_REL_OFFSET r12, 1*8
21499+ movq %r13,2*8(%rsp)
21500+ CFI_REL_OFFSET r13, 2*8
21501
21502 movl $(4096/64)-5,%ecx
21503 .p2align 4
21504@@ -37,7 +40,7 @@ ENTRY(copy_page)
21505 movq 16 (%rsi), %rdx
21506 movq 24 (%rsi), %r8
21507 movq 32 (%rsi), %r9
21508- movq 40 (%rsi), %r10
21509+ movq 40 (%rsi), %r13
21510 movq 48 (%rsi), %r11
21511 movq 56 (%rsi), %r12
21512
21513@@ -48,7 +51,7 @@ ENTRY(copy_page)
21514 movq %rdx, 16 (%rdi)
21515 movq %r8, 24 (%rdi)
21516 movq %r9, 32 (%rdi)
21517- movq %r10, 40 (%rdi)
21518+ movq %r13, 40 (%rdi)
21519 movq %r11, 48 (%rdi)
21520 movq %r12, 56 (%rdi)
21521
21522@@ -67,7 +70,7 @@ ENTRY(copy_page)
21523 movq 16 (%rsi), %rdx
21524 movq 24 (%rsi), %r8
21525 movq 32 (%rsi), %r9
21526- movq 40 (%rsi), %r10
21527+ movq 40 (%rsi), %r13
21528 movq 48 (%rsi), %r11
21529 movq 56 (%rsi), %r12
21530
21531@@ -76,7 +79,7 @@ ENTRY(copy_page)
21532 movq %rdx, 16 (%rdi)
21533 movq %r8, 24 (%rdi)
21534 movq %r9, 32 (%rdi)
21535- movq %r10, 40 (%rdi)
21536+ movq %r13, 40 (%rdi)
21537 movq %r11, 48 (%rdi)
21538 movq %r12, 56 (%rdi)
21539
21540@@ -89,8 +92,11 @@ ENTRY(copy_page)
21541 CFI_RESTORE rbx
21542 movq 1*8(%rsp),%r12
21543 CFI_RESTORE r12
21544- addq $2*8,%rsp
21545- CFI_ADJUST_CFA_OFFSET -2*8
21546+ movq 2*8(%rsp),%r13
21547+ CFI_RESTORE r13
21548+ addq $3*8,%rsp
21549+ CFI_ADJUST_CFA_OFFSET -3*8
21550+ pax_force_retaddr
21551 ret
21552 .Lcopy_page_end:
21553 CFI_ENDPROC
21554@@ -101,7 +107,7 @@ ENDPROC(copy_page)
21555
21556 #include <asm/cpufeature.h>
21557
21558- .section .altinstr_replacement,"ax"
21559+ .section .altinstr_replacement,"a"
21560 1: .byte 0xeb /* jmp <disp8> */
21561 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21562 2:
21563diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21564index 0248402..821c786 100644
21565--- a/arch/x86/lib/copy_user_64.S
21566+++ b/arch/x86/lib/copy_user_64.S
21567@@ -16,6 +16,7 @@
21568 #include <asm/thread_info.h>
21569 #include <asm/cpufeature.h>
21570 #include <asm/alternative-asm.h>
21571+#include <asm/pgtable.h>
21572
21573 /*
21574 * By placing feature2 after feature1 in altinstructions section, we logically
21575@@ -29,7 +30,7 @@
21576 .byte 0xe9 /* 32bit jump */
21577 .long \orig-1f /* by default jump to orig */
21578 1:
21579- .section .altinstr_replacement,"ax"
21580+ .section .altinstr_replacement,"a"
21581 2: .byte 0xe9 /* near jump with 32bit immediate */
21582 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21583 3: .byte 0xe9 /* near jump with 32bit immediate */
21584@@ -71,47 +72,20 @@
21585 #endif
21586 .endm
21587
21588-/* Standard copy_to_user with segment limit checking */
21589-ENTRY(_copy_to_user)
21590- CFI_STARTPROC
21591- GET_THREAD_INFO(%rax)
21592- movq %rdi,%rcx
21593- addq %rdx,%rcx
21594- jc bad_to_user
21595- cmpq TI_addr_limit(%rax),%rcx
21596- ja bad_to_user
21597- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21598- copy_user_generic_unrolled,copy_user_generic_string, \
21599- copy_user_enhanced_fast_string
21600- CFI_ENDPROC
21601-ENDPROC(_copy_to_user)
21602-
21603-/* Standard copy_from_user with segment limit checking */
21604-ENTRY(_copy_from_user)
21605- CFI_STARTPROC
21606- GET_THREAD_INFO(%rax)
21607- movq %rsi,%rcx
21608- addq %rdx,%rcx
21609- jc bad_from_user
21610- cmpq TI_addr_limit(%rax),%rcx
21611- ja bad_from_user
21612- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21613- copy_user_generic_unrolled,copy_user_generic_string, \
21614- copy_user_enhanced_fast_string
21615- CFI_ENDPROC
21616-ENDPROC(_copy_from_user)
21617-
21618 .section .fixup,"ax"
21619 /* must zero dest */
21620 ENTRY(bad_from_user)
21621 bad_from_user:
21622 CFI_STARTPROC
21623+ testl %edx,%edx
21624+ js bad_to_user
21625 movl %edx,%ecx
21626 xorl %eax,%eax
21627 rep
21628 stosb
21629 bad_to_user:
21630 movl %edx,%eax
21631+ pax_force_retaddr
21632 ret
21633 CFI_ENDPROC
21634 ENDPROC(bad_from_user)
21635@@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
21636 jz 17f
21637 1: movq (%rsi),%r8
21638 2: movq 1*8(%rsi),%r9
21639-3: movq 2*8(%rsi),%r10
21640+3: movq 2*8(%rsi),%rax
21641 4: movq 3*8(%rsi),%r11
21642 5: movq %r8,(%rdi)
21643 6: movq %r9,1*8(%rdi)
21644-7: movq %r10,2*8(%rdi)
21645+7: movq %rax,2*8(%rdi)
21646 8: movq %r11,3*8(%rdi)
21647 9: movq 4*8(%rsi),%r8
21648 10: movq 5*8(%rsi),%r9
21649-11: movq 6*8(%rsi),%r10
21650+11: movq 6*8(%rsi),%rax
21651 12: movq 7*8(%rsi),%r11
21652 13: movq %r8,4*8(%rdi)
21653 14: movq %r9,5*8(%rdi)
21654-15: movq %r10,6*8(%rdi)
21655+15: movq %rax,6*8(%rdi)
21656 16: movq %r11,7*8(%rdi)
21657 leaq 64(%rsi),%rsi
21658 leaq 64(%rdi),%rdi
21659@@ -179,6 +153,7 @@ ENTRY(copy_user_generic_unrolled)
21660 decl %ecx
21661 jnz 21b
21662 23: xor %eax,%eax
21663+ pax_force_retaddr
21664 ret
21665
21666 .section .fixup,"ax"
21667@@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
21668 3: rep
21669 movsb
21670 4: xorl %eax,%eax
21671+ pax_force_retaddr
21672 ret
21673
21674 .section .fixup,"ax"
21675@@ -287,6 +263,7 @@ ENTRY(copy_user_enhanced_fast_string)
21676 1: rep
21677 movsb
21678 2: xorl %eax,%eax
21679+ pax_force_retaddr
21680 ret
21681
21682 .section .fixup,"ax"
21683diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21684index cb0c112..e3a6895 100644
21685--- a/arch/x86/lib/copy_user_nocache_64.S
21686+++ b/arch/x86/lib/copy_user_nocache_64.S
21687@@ -8,12 +8,14 @@
21688
21689 #include <linux/linkage.h>
21690 #include <asm/dwarf2.h>
21691+#include <asm/alternative-asm.h>
21692
21693 #define FIX_ALIGNMENT 1
21694
21695 #include <asm/current.h>
21696 #include <asm/asm-offsets.h>
21697 #include <asm/thread_info.h>
21698+#include <asm/pgtable.h>
21699
21700 .macro ALIGN_DESTINATION
21701 #ifdef FIX_ALIGNMENT
21702@@ -50,6 +52,15 @@
21703 */
21704 ENTRY(__copy_user_nocache)
21705 CFI_STARTPROC
21706+
21707+#ifdef CONFIG_PAX_MEMORY_UDEREF
21708+ mov $PAX_USER_SHADOW_BASE,%rcx
21709+ cmp %rcx,%rsi
21710+ jae 1f
21711+ add %rcx,%rsi
21712+1:
21713+#endif
21714+
21715 cmpl $8,%edx
21716 jb 20f /* less then 8 bytes, go to byte copy loop */
21717 ALIGN_DESTINATION
21718@@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
21719 jz 17f
21720 1: movq (%rsi),%r8
21721 2: movq 1*8(%rsi),%r9
21722-3: movq 2*8(%rsi),%r10
21723+3: movq 2*8(%rsi),%rax
21724 4: movq 3*8(%rsi),%r11
21725 5: movnti %r8,(%rdi)
21726 6: movnti %r9,1*8(%rdi)
21727-7: movnti %r10,2*8(%rdi)
21728+7: movnti %rax,2*8(%rdi)
21729 8: movnti %r11,3*8(%rdi)
21730 9: movq 4*8(%rsi),%r8
21731 10: movq 5*8(%rsi),%r9
21732-11: movq 6*8(%rsi),%r10
21733+11: movq 6*8(%rsi),%rax
21734 12: movq 7*8(%rsi),%r11
21735 13: movnti %r8,4*8(%rdi)
21736 14: movnti %r9,5*8(%rdi)
21737-15: movnti %r10,6*8(%rdi)
21738+15: movnti %rax,6*8(%rdi)
21739 16: movnti %r11,7*8(%rdi)
21740 leaq 64(%rsi),%rsi
21741 leaq 64(%rdi),%rdi
21742@@ -98,6 +109,7 @@ ENTRY(__copy_user_nocache)
21743 jnz 21b
21744 23: xorl %eax,%eax
21745 sfence
21746+ pax_force_retaddr
21747 ret
21748
21749 .section .fixup,"ax"
21750diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21751index fb903b7..c92b7f7 100644
21752--- a/arch/x86/lib/csum-copy_64.S
21753+++ b/arch/x86/lib/csum-copy_64.S
21754@@ -8,6 +8,7 @@
21755 #include <linux/linkage.h>
21756 #include <asm/dwarf2.h>
21757 #include <asm/errno.h>
21758+#include <asm/alternative-asm.h>
21759
21760 /*
21761 * Checksum copy with exception handling.
21762@@ -228,6 +229,7 @@ ENTRY(csum_partial_copy_generic)
21763 CFI_RESTORE rbp
21764 addq $7*8, %rsp
21765 CFI_ADJUST_CFA_OFFSET -7*8
21766+ pax_force_retaddr 0, 1
21767 ret
21768 CFI_RESTORE_STATE
21769
21770diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21771index 459b58a..9570bc7 100644
21772--- a/arch/x86/lib/csum-wrappers_64.c
21773+++ b/arch/x86/lib/csum-wrappers_64.c
21774@@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21775 len -= 2;
21776 }
21777 }
21778- isum = csum_partial_copy_generic((__force const void *)src,
21779+
21780+#ifdef CONFIG_PAX_MEMORY_UDEREF
21781+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21782+ src += PAX_USER_SHADOW_BASE;
21783+#endif
21784+
21785+ isum = csum_partial_copy_generic((const void __force_kernel *)src,
21786 dst, len, isum, errp, NULL);
21787 if (unlikely(*errp))
21788 goto out_err;
21789@@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21790 }
21791
21792 *errp = 0;
21793- return csum_partial_copy_generic(src, (void __force *)dst,
21794+
21795+#ifdef CONFIG_PAX_MEMORY_UDEREF
21796+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21797+ dst += PAX_USER_SHADOW_BASE;
21798+#endif
21799+
21800+ return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21801 len, isum, NULL, errp);
21802 }
21803 EXPORT_SYMBOL(csum_partial_copy_to_user);
21804diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21805index 51f1504..ddac4c1 100644
21806--- a/arch/x86/lib/getuser.S
21807+++ b/arch/x86/lib/getuser.S
21808@@ -33,15 +33,38 @@
21809 #include <asm/asm-offsets.h>
21810 #include <asm/thread_info.h>
21811 #include <asm/asm.h>
21812+#include <asm/segment.h>
21813+#include <asm/pgtable.h>
21814+#include <asm/alternative-asm.h>
21815+
21816+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21817+#define __copyuser_seg gs;
21818+#else
21819+#define __copyuser_seg
21820+#endif
21821
21822 .text
21823 ENTRY(__get_user_1)
21824 CFI_STARTPROC
21825+
21826+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21827 GET_THREAD_INFO(%_ASM_DX)
21828 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21829 jae bad_get_user
21830-1: movzb (%_ASM_AX),%edx
21831+
21832+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21833+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21834+ cmp %_ASM_DX,%_ASM_AX
21835+ jae 1234f
21836+ add %_ASM_DX,%_ASM_AX
21837+1234:
21838+#endif
21839+
21840+#endif
21841+
21842+1: __copyuser_seg movzb (%_ASM_AX),%edx
21843 xor %eax,%eax
21844+ pax_force_retaddr
21845 ret
21846 CFI_ENDPROC
21847 ENDPROC(__get_user_1)
21848@@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21849 ENTRY(__get_user_2)
21850 CFI_STARTPROC
21851 add $1,%_ASM_AX
21852+
21853+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21854 jc bad_get_user
21855 GET_THREAD_INFO(%_ASM_DX)
21856 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21857 jae bad_get_user
21858-2: movzwl -1(%_ASM_AX),%edx
21859+
21860+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21861+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21862+ cmp %_ASM_DX,%_ASM_AX
21863+ jae 1234f
21864+ add %_ASM_DX,%_ASM_AX
21865+1234:
21866+#endif
21867+
21868+#endif
21869+
21870+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21871 xor %eax,%eax
21872+ pax_force_retaddr
21873 ret
21874 CFI_ENDPROC
21875 ENDPROC(__get_user_2)
21876@@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21877 ENTRY(__get_user_4)
21878 CFI_STARTPROC
21879 add $3,%_ASM_AX
21880+
21881+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21882 jc bad_get_user
21883 GET_THREAD_INFO(%_ASM_DX)
21884 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21885 jae bad_get_user
21886-3: mov -3(%_ASM_AX),%edx
21887+
21888+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21889+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21890+ cmp %_ASM_DX,%_ASM_AX
21891+ jae 1234f
21892+ add %_ASM_DX,%_ASM_AX
21893+1234:
21894+#endif
21895+
21896+#endif
21897+
21898+3: __copyuser_seg mov -3(%_ASM_AX),%edx
21899 xor %eax,%eax
21900+ pax_force_retaddr
21901 ret
21902 CFI_ENDPROC
21903 ENDPROC(__get_user_4)
21904@@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21905 GET_THREAD_INFO(%_ASM_DX)
21906 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21907 jae bad_get_user
21908+
21909+#ifdef CONFIG_PAX_MEMORY_UDEREF
21910+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21911+ cmp %_ASM_DX,%_ASM_AX
21912+ jae 1234f
21913+ add %_ASM_DX,%_ASM_AX
21914+1234:
21915+#endif
21916+
21917 4: movq -7(%_ASM_AX),%_ASM_DX
21918 xor %eax,%eax
21919+ pax_force_retaddr
21920 ret
21921 CFI_ENDPROC
21922 ENDPROC(__get_user_8)
21923@@ -91,6 +152,7 @@ bad_get_user:
21924 CFI_STARTPROC
21925 xor %edx,%edx
21926 mov $(-EFAULT),%_ASM_AX
21927+ pax_force_retaddr
21928 ret
21929 CFI_ENDPROC
21930 END(bad_get_user)
21931diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21932index b1e6c4b..21ae8fc 100644
21933--- a/arch/x86/lib/insn.c
21934+++ b/arch/x86/lib/insn.c
21935@@ -21,6 +21,11 @@
21936 #include <linux/string.h>
21937 #include <asm/inat.h>
21938 #include <asm/insn.h>
21939+#ifdef __KERNEL__
21940+#include <asm/pgtable_types.h>
21941+#else
21942+#define ktla_ktva(addr) addr
21943+#endif
21944
21945 /* Verify next sizeof(t) bytes can be on the same instruction */
21946 #define validate_next(t, insn, n) \
21947@@ -49,8 +54,8 @@
21948 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21949 {
21950 memset(insn, 0, sizeof(*insn));
21951- insn->kaddr = kaddr;
21952- insn->next_byte = kaddr;
21953+ insn->kaddr = ktla_ktva(kaddr);
21954+ insn->next_byte = ktla_ktva(kaddr);
21955 insn->x86_64 = x86_64 ? 1 : 0;
21956 insn->opnd_bytes = 4;
21957 if (x86_64)
21958diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21959index 05a95e7..326f2fa 100644
21960--- a/arch/x86/lib/iomap_copy_64.S
21961+++ b/arch/x86/lib/iomap_copy_64.S
21962@@ -17,6 +17,7 @@
21963
21964 #include <linux/linkage.h>
21965 #include <asm/dwarf2.h>
21966+#include <asm/alternative-asm.h>
21967
21968 /*
21969 * override generic version in lib/iomap_copy.c
21970@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21971 CFI_STARTPROC
21972 movl %edx,%ecx
21973 rep movsd
21974+ pax_force_retaddr
21975 ret
21976 CFI_ENDPROC
21977 ENDPROC(__iowrite32_copy)
21978diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21979index 1c273be..da9cc0e 100644
21980--- a/arch/x86/lib/memcpy_64.S
21981+++ b/arch/x86/lib/memcpy_64.S
21982@@ -33,6 +33,7 @@
21983 rep movsq
21984 movl %edx, %ecx
21985 rep movsb
21986+ pax_force_retaddr
21987 ret
21988 .Lmemcpy_e:
21989 .previous
21990@@ -49,6 +50,7 @@
21991 movq %rdi, %rax
21992 movq %rdx, %rcx
21993 rep movsb
21994+ pax_force_retaddr
21995 ret
21996 .Lmemcpy_e_e:
21997 .previous
21998@@ -76,13 +78,13 @@ ENTRY(memcpy)
21999 */
22000 movq 0*8(%rsi), %r8
22001 movq 1*8(%rsi), %r9
22002- movq 2*8(%rsi), %r10
22003+ movq 2*8(%rsi), %rcx
22004 movq 3*8(%rsi), %r11
22005 leaq 4*8(%rsi), %rsi
22006
22007 movq %r8, 0*8(%rdi)
22008 movq %r9, 1*8(%rdi)
22009- movq %r10, 2*8(%rdi)
22010+ movq %rcx, 2*8(%rdi)
22011 movq %r11, 3*8(%rdi)
22012 leaq 4*8(%rdi), %rdi
22013 jae .Lcopy_forward_loop
22014@@ -105,12 +107,12 @@ ENTRY(memcpy)
22015 subq $0x20, %rdx
22016 movq -1*8(%rsi), %r8
22017 movq -2*8(%rsi), %r9
22018- movq -3*8(%rsi), %r10
22019+ movq -3*8(%rsi), %rcx
22020 movq -4*8(%rsi), %r11
22021 leaq -4*8(%rsi), %rsi
22022 movq %r8, -1*8(%rdi)
22023 movq %r9, -2*8(%rdi)
22024- movq %r10, -3*8(%rdi)
22025+ movq %rcx, -3*8(%rdi)
22026 movq %r11, -4*8(%rdi)
22027 leaq -4*8(%rdi), %rdi
22028 jae .Lcopy_backward_loop
22029@@ -130,12 +132,13 @@ ENTRY(memcpy)
22030 */
22031 movq 0*8(%rsi), %r8
22032 movq 1*8(%rsi), %r9
22033- movq -2*8(%rsi, %rdx), %r10
22034+ movq -2*8(%rsi, %rdx), %rcx
22035 movq -1*8(%rsi, %rdx), %r11
22036 movq %r8, 0*8(%rdi)
22037 movq %r9, 1*8(%rdi)
22038- movq %r10, -2*8(%rdi, %rdx)
22039+ movq %rcx, -2*8(%rdi, %rdx)
22040 movq %r11, -1*8(%rdi, %rdx)
22041+ pax_force_retaddr
22042 retq
22043 .p2align 4
22044 .Lless_16bytes:
22045@@ -148,6 +151,7 @@ ENTRY(memcpy)
22046 movq -1*8(%rsi, %rdx), %r9
22047 movq %r8, 0*8(%rdi)
22048 movq %r9, -1*8(%rdi, %rdx)
22049+ pax_force_retaddr
22050 retq
22051 .p2align 4
22052 .Lless_8bytes:
22053@@ -161,6 +165,7 @@ ENTRY(memcpy)
22054 movl -4(%rsi, %rdx), %r8d
22055 movl %ecx, (%rdi)
22056 movl %r8d, -4(%rdi, %rdx)
22057+ pax_force_retaddr
22058 retq
22059 .p2align 4
22060 .Lless_3bytes:
22061@@ -179,6 +184,7 @@ ENTRY(memcpy)
22062 movb %cl, (%rdi)
22063
22064 .Lend:
22065+ pax_force_retaddr
22066 retq
22067 CFI_ENDPROC
22068 ENDPROC(memcpy)
22069diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
22070index ee16461..c39c199 100644
22071--- a/arch/x86/lib/memmove_64.S
22072+++ b/arch/x86/lib/memmove_64.S
22073@@ -61,13 +61,13 @@ ENTRY(memmove)
22074 5:
22075 sub $0x20, %rdx
22076 movq 0*8(%rsi), %r11
22077- movq 1*8(%rsi), %r10
22078+ movq 1*8(%rsi), %rcx
22079 movq 2*8(%rsi), %r9
22080 movq 3*8(%rsi), %r8
22081 leaq 4*8(%rsi), %rsi
22082
22083 movq %r11, 0*8(%rdi)
22084- movq %r10, 1*8(%rdi)
22085+ movq %rcx, 1*8(%rdi)
22086 movq %r9, 2*8(%rdi)
22087 movq %r8, 3*8(%rdi)
22088 leaq 4*8(%rdi), %rdi
22089@@ -81,10 +81,10 @@ ENTRY(memmove)
22090 4:
22091 movq %rdx, %rcx
22092 movq -8(%rsi, %rdx), %r11
22093- lea -8(%rdi, %rdx), %r10
22094+ lea -8(%rdi, %rdx), %r9
22095 shrq $3, %rcx
22096 rep movsq
22097- movq %r11, (%r10)
22098+ movq %r11, (%r9)
22099 jmp 13f
22100 .Lmemmove_end_forward:
22101
22102@@ -95,14 +95,14 @@ ENTRY(memmove)
22103 7:
22104 movq %rdx, %rcx
22105 movq (%rsi), %r11
22106- movq %rdi, %r10
22107+ movq %rdi, %r9
22108 leaq -8(%rsi, %rdx), %rsi
22109 leaq -8(%rdi, %rdx), %rdi
22110 shrq $3, %rcx
22111 std
22112 rep movsq
22113 cld
22114- movq %r11, (%r10)
22115+ movq %r11, (%r9)
22116 jmp 13f
22117
22118 /*
22119@@ -127,13 +127,13 @@ ENTRY(memmove)
22120 8:
22121 subq $0x20, %rdx
22122 movq -1*8(%rsi), %r11
22123- movq -2*8(%rsi), %r10
22124+ movq -2*8(%rsi), %rcx
22125 movq -3*8(%rsi), %r9
22126 movq -4*8(%rsi), %r8
22127 leaq -4*8(%rsi), %rsi
22128
22129 movq %r11, -1*8(%rdi)
22130- movq %r10, -2*8(%rdi)
22131+ movq %rcx, -2*8(%rdi)
22132 movq %r9, -3*8(%rdi)
22133 movq %r8, -4*8(%rdi)
22134 leaq -4*8(%rdi), %rdi
22135@@ -151,11 +151,11 @@ ENTRY(memmove)
22136 * Move data from 16 bytes to 31 bytes.
22137 */
22138 movq 0*8(%rsi), %r11
22139- movq 1*8(%rsi), %r10
22140+ movq 1*8(%rsi), %rcx
22141 movq -2*8(%rsi, %rdx), %r9
22142 movq -1*8(%rsi, %rdx), %r8
22143 movq %r11, 0*8(%rdi)
22144- movq %r10, 1*8(%rdi)
22145+ movq %rcx, 1*8(%rdi)
22146 movq %r9, -2*8(%rdi, %rdx)
22147 movq %r8, -1*8(%rdi, %rdx)
22148 jmp 13f
22149@@ -167,9 +167,9 @@ ENTRY(memmove)
22150 * Move data from 8 bytes to 15 bytes.
22151 */
22152 movq 0*8(%rsi), %r11
22153- movq -1*8(%rsi, %rdx), %r10
22154+ movq -1*8(%rsi, %rdx), %r9
22155 movq %r11, 0*8(%rdi)
22156- movq %r10, -1*8(%rdi, %rdx)
22157+ movq %r9, -1*8(%rdi, %rdx)
22158 jmp 13f
22159 10:
22160 cmpq $4, %rdx
22161@@ -178,9 +178,9 @@ ENTRY(memmove)
22162 * Move data from 4 bytes to 7 bytes.
22163 */
22164 movl (%rsi), %r11d
22165- movl -4(%rsi, %rdx), %r10d
22166+ movl -4(%rsi, %rdx), %r9d
22167 movl %r11d, (%rdi)
22168- movl %r10d, -4(%rdi, %rdx)
22169+ movl %r9d, -4(%rdi, %rdx)
22170 jmp 13f
22171 11:
22172 cmp $2, %rdx
22173@@ -189,9 +189,9 @@ ENTRY(memmove)
22174 * Move data from 2 bytes to 3 bytes.
22175 */
22176 movw (%rsi), %r11w
22177- movw -2(%rsi, %rdx), %r10w
22178+ movw -2(%rsi, %rdx), %r9w
22179 movw %r11w, (%rdi)
22180- movw %r10w, -2(%rdi, %rdx)
22181+ movw %r9w, -2(%rdi, %rdx)
22182 jmp 13f
22183 12:
22184 cmp $1, %rdx
22185@@ -202,6 +202,7 @@ ENTRY(memmove)
22186 movb (%rsi), %r11b
22187 movb %r11b, (%rdi)
22188 13:
22189+ pax_force_retaddr
22190 retq
22191 CFI_ENDPROC
22192
22193@@ -210,6 +211,7 @@ ENTRY(memmove)
22194 /* Forward moving data. */
22195 movq %rdx, %rcx
22196 rep movsb
22197+ pax_force_retaddr
22198 retq
22199 .Lmemmove_end_forward_efs:
22200 .previous
22201diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22202index 2dcb380..963660a 100644
22203--- a/arch/x86/lib/memset_64.S
22204+++ b/arch/x86/lib/memset_64.S
22205@@ -30,6 +30,7 @@
22206 movl %edx,%ecx
22207 rep stosb
22208 movq %r9,%rax
22209+ pax_force_retaddr
22210 ret
22211 .Lmemset_e:
22212 .previous
22213@@ -52,6 +53,7 @@
22214 movq %rdx,%rcx
22215 rep stosb
22216 movq %r9,%rax
22217+ pax_force_retaddr
22218 ret
22219 .Lmemset_e_e:
22220 .previous
22221@@ -59,7 +61,7 @@
22222 ENTRY(memset)
22223 ENTRY(__memset)
22224 CFI_STARTPROC
22225- movq %rdi,%r10
22226+ movq %rdi,%r11
22227
22228 /* expand byte value */
22229 movzbl %sil,%ecx
22230@@ -117,7 +119,8 @@ ENTRY(__memset)
22231 jnz .Lloop_1
22232
22233 .Lende:
22234- movq %r10,%rax
22235+ movq %r11,%rax
22236+ pax_force_retaddr
22237 ret
22238
22239 CFI_RESTORE_STATE
22240diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22241index c9f2d9b..e7fd2c0 100644
22242--- a/arch/x86/lib/mmx_32.c
22243+++ b/arch/x86/lib/mmx_32.c
22244@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22245 {
22246 void *p;
22247 int i;
22248+ unsigned long cr0;
22249
22250 if (unlikely(in_interrupt()))
22251 return __memcpy(to, from, len);
22252@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22253 kernel_fpu_begin();
22254
22255 __asm__ __volatile__ (
22256- "1: prefetch (%0)\n" /* This set is 28 bytes */
22257- " prefetch 64(%0)\n"
22258- " prefetch 128(%0)\n"
22259- " prefetch 192(%0)\n"
22260- " prefetch 256(%0)\n"
22261+ "1: prefetch (%1)\n" /* This set is 28 bytes */
22262+ " prefetch 64(%1)\n"
22263+ " prefetch 128(%1)\n"
22264+ " prefetch 192(%1)\n"
22265+ " prefetch 256(%1)\n"
22266 "2: \n"
22267 ".section .fixup, \"ax\"\n"
22268- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22269+ "3: \n"
22270+
22271+#ifdef CONFIG_PAX_KERNEXEC
22272+ " movl %%cr0, %0\n"
22273+ " movl %0, %%eax\n"
22274+ " andl $0xFFFEFFFF, %%eax\n"
22275+ " movl %%eax, %%cr0\n"
22276+#endif
22277+
22278+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22279+
22280+#ifdef CONFIG_PAX_KERNEXEC
22281+ " movl %0, %%cr0\n"
22282+#endif
22283+
22284 " jmp 2b\n"
22285 ".previous\n"
22286 _ASM_EXTABLE(1b, 3b)
22287- : : "r" (from));
22288+ : "=&r" (cr0) : "r" (from) : "ax");
22289
22290 for ( ; i > 5; i--) {
22291 __asm__ __volatile__ (
22292- "1: prefetch 320(%0)\n"
22293- "2: movq (%0), %%mm0\n"
22294- " movq 8(%0), %%mm1\n"
22295- " movq 16(%0), %%mm2\n"
22296- " movq 24(%0), %%mm3\n"
22297- " movq %%mm0, (%1)\n"
22298- " movq %%mm1, 8(%1)\n"
22299- " movq %%mm2, 16(%1)\n"
22300- " movq %%mm3, 24(%1)\n"
22301- " movq 32(%0), %%mm0\n"
22302- " movq 40(%0), %%mm1\n"
22303- " movq 48(%0), %%mm2\n"
22304- " movq 56(%0), %%mm3\n"
22305- " movq %%mm0, 32(%1)\n"
22306- " movq %%mm1, 40(%1)\n"
22307- " movq %%mm2, 48(%1)\n"
22308- " movq %%mm3, 56(%1)\n"
22309+ "1: prefetch 320(%1)\n"
22310+ "2: movq (%1), %%mm0\n"
22311+ " movq 8(%1), %%mm1\n"
22312+ " movq 16(%1), %%mm2\n"
22313+ " movq 24(%1), %%mm3\n"
22314+ " movq %%mm0, (%2)\n"
22315+ " movq %%mm1, 8(%2)\n"
22316+ " movq %%mm2, 16(%2)\n"
22317+ " movq %%mm3, 24(%2)\n"
22318+ " movq 32(%1), %%mm0\n"
22319+ " movq 40(%1), %%mm1\n"
22320+ " movq 48(%1), %%mm2\n"
22321+ " movq 56(%1), %%mm3\n"
22322+ " movq %%mm0, 32(%2)\n"
22323+ " movq %%mm1, 40(%2)\n"
22324+ " movq %%mm2, 48(%2)\n"
22325+ " movq %%mm3, 56(%2)\n"
22326 ".section .fixup, \"ax\"\n"
22327- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22328+ "3:\n"
22329+
22330+#ifdef CONFIG_PAX_KERNEXEC
22331+ " movl %%cr0, %0\n"
22332+ " movl %0, %%eax\n"
22333+ " andl $0xFFFEFFFF, %%eax\n"
22334+ " movl %%eax, %%cr0\n"
22335+#endif
22336+
22337+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22338+
22339+#ifdef CONFIG_PAX_KERNEXEC
22340+ " movl %0, %%cr0\n"
22341+#endif
22342+
22343 " jmp 2b\n"
22344 ".previous\n"
22345 _ASM_EXTABLE(1b, 3b)
22346- : : "r" (from), "r" (to) : "memory");
22347+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22348
22349 from += 64;
22350 to += 64;
22351@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22352 static void fast_copy_page(void *to, void *from)
22353 {
22354 int i;
22355+ unsigned long cr0;
22356
22357 kernel_fpu_begin();
22358
22359@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22360 * but that is for later. -AV
22361 */
22362 __asm__ __volatile__(
22363- "1: prefetch (%0)\n"
22364- " prefetch 64(%0)\n"
22365- " prefetch 128(%0)\n"
22366- " prefetch 192(%0)\n"
22367- " prefetch 256(%0)\n"
22368+ "1: prefetch (%1)\n"
22369+ " prefetch 64(%1)\n"
22370+ " prefetch 128(%1)\n"
22371+ " prefetch 192(%1)\n"
22372+ " prefetch 256(%1)\n"
22373 "2: \n"
22374 ".section .fixup, \"ax\"\n"
22375- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22376+ "3: \n"
22377+
22378+#ifdef CONFIG_PAX_KERNEXEC
22379+ " movl %%cr0, %0\n"
22380+ " movl %0, %%eax\n"
22381+ " andl $0xFFFEFFFF, %%eax\n"
22382+ " movl %%eax, %%cr0\n"
22383+#endif
22384+
22385+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22386+
22387+#ifdef CONFIG_PAX_KERNEXEC
22388+ " movl %0, %%cr0\n"
22389+#endif
22390+
22391 " jmp 2b\n"
22392 ".previous\n"
22393- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22394+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22395
22396 for (i = 0; i < (4096-320)/64; i++) {
22397 __asm__ __volatile__ (
22398- "1: prefetch 320(%0)\n"
22399- "2: movq (%0), %%mm0\n"
22400- " movntq %%mm0, (%1)\n"
22401- " movq 8(%0), %%mm1\n"
22402- " movntq %%mm1, 8(%1)\n"
22403- " movq 16(%0), %%mm2\n"
22404- " movntq %%mm2, 16(%1)\n"
22405- " movq 24(%0), %%mm3\n"
22406- " movntq %%mm3, 24(%1)\n"
22407- " movq 32(%0), %%mm4\n"
22408- " movntq %%mm4, 32(%1)\n"
22409- " movq 40(%0), %%mm5\n"
22410- " movntq %%mm5, 40(%1)\n"
22411- " movq 48(%0), %%mm6\n"
22412- " movntq %%mm6, 48(%1)\n"
22413- " movq 56(%0), %%mm7\n"
22414- " movntq %%mm7, 56(%1)\n"
22415+ "1: prefetch 320(%1)\n"
22416+ "2: movq (%1), %%mm0\n"
22417+ " movntq %%mm0, (%2)\n"
22418+ " movq 8(%1), %%mm1\n"
22419+ " movntq %%mm1, 8(%2)\n"
22420+ " movq 16(%1), %%mm2\n"
22421+ " movntq %%mm2, 16(%2)\n"
22422+ " movq 24(%1), %%mm3\n"
22423+ " movntq %%mm3, 24(%2)\n"
22424+ " movq 32(%1), %%mm4\n"
22425+ " movntq %%mm4, 32(%2)\n"
22426+ " movq 40(%1), %%mm5\n"
22427+ " movntq %%mm5, 40(%2)\n"
22428+ " movq 48(%1), %%mm6\n"
22429+ " movntq %%mm6, 48(%2)\n"
22430+ " movq 56(%1), %%mm7\n"
22431+ " movntq %%mm7, 56(%2)\n"
22432 ".section .fixup, \"ax\"\n"
22433- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22434+ "3:\n"
22435+
22436+#ifdef CONFIG_PAX_KERNEXEC
22437+ " movl %%cr0, %0\n"
22438+ " movl %0, %%eax\n"
22439+ " andl $0xFFFEFFFF, %%eax\n"
22440+ " movl %%eax, %%cr0\n"
22441+#endif
22442+
22443+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22444+
22445+#ifdef CONFIG_PAX_KERNEXEC
22446+ " movl %0, %%cr0\n"
22447+#endif
22448+
22449 " jmp 2b\n"
22450 ".previous\n"
22451- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22452+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22453
22454 from += 64;
22455 to += 64;
22456@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22457 static void fast_copy_page(void *to, void *from)
22458 {
22459 int i;
22460+ unsigned long cr0;
22461
22462 kernel_fpu_begin();
22463
22464 __asm__ __volatile__ (
22465- "1: prefetch (%0)\n"
22466- " prefetch 64(%0)\n"
22467- " prefetch 128(%0)\n"
22468- " prefetch 192(%0)\n"
22469- " prefetch 256(%0)\n"
22470+ "1: prefetch (%1)\n"
22471+ " prefetch 64(%1)\n"
22472+ " prefetch 128(%1)\n"
22473+ " prefetch 192(%1)\n"
22474+ " prefetch 256(%1)\n"
22475 "2: \n"
22476 ".section .fixup, \"ax\"\n"
22477- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22478+ "3: \n"
22479+
22480+#ifdef CONFIG_PAX_KERNEXEC
22481+ " movl %%cr0, %0\n"
22482+ " movl %0, %%eax\n"
22483+ " andl $0xFFFEFFFF, %%eax\n"
22484+ " movl %%eax, %%cr0\n"
22485+#endif
22486+
22487+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22488+
22489+#ifdef CONFIG_PAX_KERNEXEC
22490+ " movl %0, %%cr0\n"
22491+#endif
22492+
22493 " jmp 2b\n"
22494 ".previous\n"
22495- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22496+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22497
22498 for (i = 0; i < 4096/64; i++) {
22499 __asm__ __volatile__ (
22500- "1: prefetch 320(%0)\n"
22501- "2: movq (%0), %%mm0\n"
22502- " movq 8(%0), %%mm1\n"
22503- " movq 16(%0), %%mm2\n"
22504- " movq 24(%0), %%mm3\n"
22505- " movq %%mm0, (%1)\n"
22506- " movq %%mm1, 8(%1)\n"
22507- " movq %%mm2, 16(%1)\n"
22508- " movq %%mm3, 24(%1)\n"
22509- " movq 32(%0), %%mm0\n"
22510- " movq 40(%0), %%mm1\n"
22511- " movq 48(%0), %%mm2\n"
22512- " movq 56(%0), %%mm3\n"
22513- " movq %%mm0, 32(%1)\n"
22514- " movq %%mm1, 40(%1)\n"
22515- " movq %%mm2, 48(%1)\n"
22516- " movq %%mm3, 56(%1)\n"
22517+ "1: prefetch 320(%1)\n"
22518+ "2: movq (%1), %%mm0\n"
22519+ " movq 8(%1), %%mm1\n"
22520+ " movq 16(%1), %%mm2\n"
22521+ " movq 24(%1), %%mm3\n"
22522+ " movq %%mm0, (%2)\n"
22523+ " movq %%mm1, 8(%2)\n"
22524+ " movq %%mm2, 16(%2)\n"
22525+ " movq %%mm3, 24(%2)\n"
22526+ " movq 32(%1), %%mm0\n"
22527+ " movq 40(%1), %%mm1\n"
22528+ " movq 48(%1), %%mm2\n"
22529+ " movq 56(%1), %%mm3\n"
22530+ " movq %%mm0, 32(%2)\n"
22531+ " movq %%mm1, 40(%2)\n"
22532+ " movq %%mm2, 48(%2)\n"
22533+ " movq %%mm3, 56(%2)\n"
22534 ".section .fixup, \"ax\"\n"
22535- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22536+ "3:\n"
22537+
22538+#ifdef CONFIG_PAX_KERNEXEC
22539+ " movl %%cr0, %0\n"
22540+ " movl %0, %%eax\n"
22541+ " andl $0xFFFEFFFF, %%eax\n"
22542+ " movl %%eax, %%cr0\n"
22543+#endif
22544+
22545+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22546+
22547+#ifdef CONFIG_PAX_KERNEXEC
22548+ " movl %0, %%cr0\n"
22549+#endif
22550+
22551 " jmp 2b\n"
22552 ".previous\n"
22553 _ASM_EXTABLE(1b, 3b)
22554- : : "r" (from), "r" (to) : "memory");
22555+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22556
22557 from += 64;
22558 to += 64;
22559diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22560index 69fa106..adda88b 100644
22561--- a/arch/x86/lib/msr-reg.S
22562+++ b/arch/x86/lib/msr-reg.S
22563@@ -3,6 +3,7 @@
22564 #include <asm/dwarf2.h>
22565 #include <asm/asm.h>
22566 #include <asm/msr.h>
22567+#include <asm/alternative-asm.h>
22568
22569 #ifdef CONFIG_X86_64
22570 /*
22571@@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
22572 CFI_STARTPROC
22573 pushq_cfi %rbx
22574 pushq_cfi %rbp
22575- movq %rdi, %r10 /* Save pointer */
22576+ movq %rdi, %r9 /* Save pointer */
22577 xorl %r11d, %r11d /* Return value */
22578 movl (%rdi), %eax
22579 movl 4(%rdi), %ecx
22580@@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
22581 movl 28(%rdi), %edi
22582 CFI_REMEMBER_STATE
22583 1: \op
22584-2: movl %eax, (%r10)
22585+2: movl %eax, (%r9)
22586 movl %r11d, %eax /* Return value */
22587- movl %ecx, 4(%r10)
22588- movl %edx, 8(%r10)
22589- movl %ebx, 12(%r10)
22590- movl %ebp, 20(%r10)
22591- movl %esi, 24(%r10)
22592- movl %edi, 28(%r10)
22593+ movl %ecx, 4(%r9)
22594+ movl %edx, 8(%r9)
22595+ movl %ebx, 12(%r9)
22596+ movl %ebp, 20(%r9)
22597+ movl %esi, 24(%r9)
22598+ movl %edi, 28(%r9)
22599 popq_cfi %rbp
22600 popq_cfi %rbx
22601+ pax_force_retaddr
22602 ret
22603 3:
22604 CFI_RESTORE_STATE
22605diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22606index 36b0d15..d381858 100644
22607--- a/arch/x86/lib/putuser.S
22608+++ b/arch/x86/lib/putuser.S
22609@@ -15,7 +15,9 @@
22610 #include <asm/thread_info.h>
22611 #include <asm/errno.h>
22612 #include <asm/asm.h>
22613-
22614+#include <asm/segment.h>
22615+#include <asm/pgtable.h>
22616+#include <asm/alternative-asm.h>
22617
22618 /*
22619 * __put_user_X
22620@@ -29,52 +31,119 @@
22621 * as they get called from within inline assembly.
22622 */
22623
22624-#define ENTER CFI_STARTPROC ; \
22625- GET_THREAD_INFO(%_ASM_BX)
22626-#define EXIT ret ; \
22627+#define ENTER CFI_STARTPROC
22628+#define EXIT pax_force_retaddr; ret ; \
22629 CFI_ENDPROC
22630
22631+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22632+#define _DEST %_ASM_CX,%_ASM_BX
22633+#else
22634+#define _DEST %_ASM_CX
22635+#endif
22636+
22637+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22638+#define __copyuser_seg gs;
22639+#else
22640+#define __copyuser_seg
22641+#endif
22642+
22643 .text
22644 ENTRY(__put_user_1)
22645 ENTER
22646+
22647+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22648+ GET_THREAD_INFO(%_ASM_BX)
22649 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22650 jae bad_put_user
22651-1: movb %al,(%_ASM_CX)
22652+
22653+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22654+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22655+ cmp %_ASM_BX,%_ASM_CX
22656+ jb 1234f
22657+ xor %ebx,%ebx
22658+1234:
22659+#endif
22660+
22661+#endif
22662+
22663+1: __copyuser_seg movb %al,(_DEST)
22664 xor %eax,%eax
22665 EXIT
22666 ENDPROC(__put_user_1)
22667
22668 ENTRY(__put_user_2)
22669 ENTER
22670+
22671+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22672+ GET_THREAD_INFO(%_ASM_BX)
22673 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22674 sub $1,%_ASM_BX
22675 cmp %_ASM_BX,%_ASM_CX
22676 jae bad_put_user
22677-2: movw %ax,(%_ASM_CX)
22678+
22679+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22680+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22681+ cmp %_ASM_BX,%_ASM_CX
22682+ jb 1234f
22683+ xor %ebx,%ebx
22684+1234:
22685+#endif
22686+
22687+#endif
22688+
22689+2: __copyuser_seg movw %ax,(_DEST)
22690 xor %eax,%eax
22691 EXIT
22692 ENDPROC(__put_user_2)
22693
22694 ENTRY(__put_user_4)
22695 ENTER
22696+
22697+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22698+ GET_THREAD_INFO(%_ASM_BX)
22699 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22700 sub $3,%_ASM_BX
22701 cmp %_ASM_BX,%_ASM_CX
22702 jae bad_put_user
22703-3: movl %eax,(%_ASM_CX)
22704+
22705+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22706+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22707+ cmp %_ASM_BX,%_ASM_CX
22708+ jb 1234f
22709+ xor %ebx,%ebx
22710+1234:
22711+#endif
22712+
22713+#endif
22714+
22715+3: __copyuser_seg movl %eax,(_DEST)
22716 xor %eax,%eax
22717 EXIT
22718 ENDPROC(__put_user_4)
22719
22720 ENTRY(__put_user_8)
22721 ENTER
22722+
22723+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22724+ GET_THREAD_INFO(%_ASM_BX)
22725 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22726 sub $7,%_ASM_BX
22727 cmp %_ASM_BX,%_ASM_CX
22728 jae bad_put_user
22729-4: mov %_ASM_AX,(%_ASM_CX)
22730+
22731+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22732+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22733+ cmp %_ASM_BX,%_ASM_CX
22734+ jb 1234f
22735+ xor %ebx,%ebx
22736+1234:
22737+#endif
22738+
22739+#endif
22740+
22741+4: __copyuser_seg mov %_ASM_AX,(_DEST)
22742 #ifdef CONFIG_X86_32
22743-5: movl %edx,4(%_ASM_CX)
22744+5: __copyuser_seg movl %edx,4(_DEST)
22745 #endif
22746 xor %eax,%eax
22747 EXIT
22748diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22749index 1cad221..de671ee 100644
22750--- a/arch/x86/lib/rwlock.S
22751+++ b/arch/x86/lib/rwlock.S
22752@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22753 FRAME
22754 0: LOCK_PREFIX
22755 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22756+
22757+#ifdef CONFIG_PAX_REFCOUNT
22758+ jno 1234f
22759+ LOCK_PREFIX
22760+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22761+ int $4
22762+1234:
22763+ _ASM_EXTABLE(1234b, 1234b)
22764+#endif
22765+
22766 1: rep; nop
22767 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22768 jne 1b
22769 LOCK_PREFIX
22770 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22771+
22772+#ifdef CONFIG_PAX_REFCOUNT
22773+ jno 1234f
22774+ LOCK_PREFIX
22775+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22776+ int $4
22777+1234:
22778+ _ASM_EXTABLE(1234b, 1234b)
22779+#endif
22780+
22781 jnz 0b
22782 ENDFRAME
22783+ pax_force_retaddr
22784 ret
22785 CFI_ENDPROC
22786 END(__write_lock_failed)
22787@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22788 FRAME
22789 0: LOCK_PREFIX
22790 READ_LOCK_SIZE(inc) (%__lock_ptr)
22791+
22792+#ifdef CONFIG_PAX_REFCOUNT
22793+ jno 1234f
22794+ LOCK_PREFIX
22795+ READ_LOCK_SIZE(dec) (%__lock_ptr)
22796+ int $4
22797+1234:
22798+ _ASM_EXTABLE(1234b, 1234b)
22799+#endif
22800+
22801 1: rep; nop
22802 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22803 js 1b
22804 LOCK_PREFIX
22805 READ_LOCK_SIZE(dec) (%__lock_ptr)
22806+
22807+#ifdef CONFIG_PAX_REFCOUNT
22808+ jno 1234f
22809+ LOCK_PREFIX
22810+ READ_LOCK_SIZE(inc) (%__lock_ptr)
22811+ int $4
22812+1234:
22813+ _ASM_EXTABLE(1234b, 1234b)
22814+#endif
22815+
22816 js 0b
22817 ENDFRAME
22818+ pax_force_retaddr
22819 ret
22820 CFI_ENDPROC
22821 END(__read_lock_failed)
22822diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22823index 5dff5f0..cadebf4 100644
22824--- a/arch/x86/lib/rwsem.S
22825+++ b/arch/x86/lib/rwsem.S
22826@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22827 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22828 CFI_RESTORE __ASM_REG(dx)
22829 restore_common_regs
22830+ pax_force_retaddr
22831 ret
22832 CFI_ENDPROC
22833 ENDPROC(call_rwsem_down_read_failed)
22834@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22835 movq %rax,%rdi
22836 call rwsem_down_write_failed
22837 restore_common_regs
22838+ pax_force_retaddr
22839 ret
22840 CFI_ENDPROC
22841 ENDPROC(call_rwsem_down_write_failed)
22842@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22843 movq %rax,%rdi
22844 call rwsem_wake
22845 restore_common_regs
22846-1: ret
22847+1: pax_force_retaddr
22848+ ret
22849 CFI_ENDPROC
22850 ENDPROC(call_rwsem_wake)
22851
22852@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22853 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22854 CFI_RESTORE __ASM_REG(dx)
22855 restore_common_regs
22856+ pax_force_retaddr
22857 ret
22858 CFI_ENDPROC
22859 ENDPROC(call_rwsem_downgrade_wake)
22860diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22861index a63efd6..ccecad8 100644
22862--- a/arch/x86/lib/thunk_64.S
22863+++ b/arch/x86/lib/thunk_64.S
22864@@ -8,6 +8,7 @@
22865 #include <linux/linkage.h>
22866 #include <asm/dwarf2.h>
22867 #include <asm/calling.h>
22868+#include <asm/alternative-asm.h>
22869
22870 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22871 .macro THUNK name, func, put_ret_addr_in_rdi=0
22872@@ -41,5 +42,6 @@
22873 SAVE_ARGS
22874 restore:
22875 RESTORE_ARGS
22876+ pax_force_retaddr
22877 ret
22878 CFI_ENDPROC
22879diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22880index ef2a6a5..3b28862 100644
22881--- a/arch/x86/lib/usercopy_32.c
22882+++ b/arch/x86/lib/usercopy_32.c
22883@@ -41,10 +41,12 @@ do { \
22884 int __d0; \
22885 might_fault(); \
22886 __asm__ __volatile__( \
22887+ __COPYUSER_SET_ES \
22888 "0: rep; stosl\n" \
22889 " movl %2,%0\n" \
22890 "1: rep; stosb\n" \
22891 "2:\n" \
22892+ __COPYUSER_RESTORE_ES \
22893 ".section .fixup,\"ax\"\n" \
22894 "3: lea 0(%2,%0,4),%0\n" \
22895 " jmp 2b\n" \
22896@@ -113,6 +115,7 @@ long strnlen_user(const char __user *s, long n)
22897 might_fault();
22898
22899 __asm__ __volatile__(
22900+ __COPYUSER_SET_ES
22901 " testl %0, %0\n"
22902 " jz 3f\n"
22903 " andl %0,%%ecx\n"
22904@@ -121,6 +124,7 @@ long strnlen_user(const char __user *s, long n)
22905 " subl %%ecx,%0\n"
22906 " addl %0,%%eax\n"
22907 "1:\n"
22908+ __COPYUSER_RESTORE_ES
22909 ".section .fixup,\"ax\"\n"
22910 "2: xorl %%eax,%%eax\n"
22911 " jmp 1b\n"
22912@@ -140,7 +144,7 @@ EXPORT_SYMBOL(strnlen_user);
22913
22914 #ifdef CONFIG_X86_INTEL_USERCOPY
22915 static unsigned long
22916-__copy_user_intel(void __user *to, const void *from, unsigned long size)
22917+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22918 {
22919 int d0, d1;
22920 __asm__ __volatile__(
22921@@ -152,36 +156,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22922 " .align 2,0x90\n"
22923 "3: movl 0(%4), %%eax\n"
22924 "4: movl 4(%4), %%edx\n"
22925- "5: movl %%eax, 0(%3)\n"
22926- "6: movl %%edx, 4(%3)\n"
22927+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22928+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22929 "7: movl 8(%4), %%eax\n"
22930 "8: movl 12(%4),%%edx\n"
22931- "9: movl %%eax, 8(%3)\n"
22932- "10: movl %%edx, 12(%3)\n"
22933+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22934+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22935 "11: movl 16(%4), %%eax\n"
22936 "12: movl 20(%4), %%edx\n"
22937- "13: movl %%eax, 16(%3)\n"
22938- "14: movl %%edx, 20(%3)\n"
22939+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22940+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22941 "15: movl 24(%4), %%eax\n"
22942 "16: movl 28(%4), %%edx\n"
22943- "17: movl %%eax, 24(%3)\n"
22944- "18: movl %%edx, 28(%3)\n"
22945+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22946+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22947 "19: movl 32(%4), %%eax\n"
22948 "20: movl 36(%4), %%edx\n"
22949- "21: movl %%eax, 32(%3)\n"
22950- "22: movl %%edx, 36(%3)\n"
22951+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22952+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22953 "23: movl 40(%4), %%eax\n"
22954 "24: movl 44(%4), %%edx\n"
22955- "25: movl %%eax, 40(%3)\n"
22956- "26: movl %%edx, 44(%3)\n"
22957+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22958+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22959 "27: movl 48(%4), %%eax\n"
22960 "28: movl 52(%4), %%edx\n"
22961- "29: movl %%eax, 48(%3)\n"
22962- "30: movl %%edx, 52(%3)\n"
22963+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22964+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22965 "31: movl 56(%4), %%eax\n"
22966 "32: movl 60(%4), %%edx\n"
22967- "33: movl %%eax, 56(%3)\n"
22968- "34: movl %%edx, 60(%3)\n"
22969+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22970+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22971 " addl $-64, %0\n"
22972 " addl $64, %4\n"
22973 " addl $64, %3\n"
22974@@ -191,10 +195,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22975 " shrl $2, %0\n"
22976 " andl $3, %%eax\n"
22977 " cld\n"
22978+ __COPYUSER_SET_ES
22979 "99: rep; movsl\n"
22980 "36: movl %%eax, %0\n"
22981 "37: rep; movsb\n"
22982 "100:\n"
22983+ __COPYUSER_RESTORE_ES
22984 ".section .fixup,\"ax\"\n"
22985 "101: lea 0(%%eax,%0,4),%0\n"
22986 " jmp 100b\n"
22987@@ -247,46 +253,155 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22988 }
22989
22990 static unsigned long
22991+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22992+{
22993+ int d0, d1;
22994+ __asm__ __volatile__(
22995+ " .align 2,0x90\n"
22996+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22997+ " cmpl $67, %0\n"
22998+ " jbe 3f\n"
22999+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
23000+ " .align 2,0x90\n"
23001+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
23002+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
23003+ "5: movl %%eax, 0(%3)\n"
23004+ "6: movl %%edx, 4(%3)\n"
23005+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
23006+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
23007+ "9: movl %%eax, 8(%3)\n"
23008+ "10: movl %%edx, 12(%3)\n"
23009+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
23010+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
23011+ "13: movl %%eax, 16(%3)\n"
23012+ "14: movl %%edx, 20(%3)\n"
23013+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
23014+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
23015+ "17: movl %%eax, 24(%3)\n"
23016+ "18: movl %%edx, 28(%3)\n"
23017+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
23018+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
23019+ "21: movl %%eax, 32(%3)\n"
23020+ "22: movl %%edx, 36(%3)\n"
23021+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
23022+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
23023+ "25: movl %%eax, 40(%3)\n"
23024+ "26: movl %%edx, 44(%3)\n"
23025+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
23026+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
23027+ "29: movl %%eax, 48(%3)\n"
23028+ "30: movl %%edx, 52(%3)\n"
23029+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
23030+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
23031+ "33: movl %%eax, 56(%3)\n"
23032+ "34: movl %%edx, 60(%3)\n"
23033+ " addl $-64, %0\n"
23034+ " addl $64, %4\n"
23035+ " addl $64, %3\n"
23036+ " cmpl $63, %0\n"
23037+ " ja 1b\n"
23038+ "35: movl %0, %%eax\n"
23039+ " shrl $2, %0\n"
23040+ " andl $3, %%eax\n"
23041+ " cld\n"
23042+ "99: rep; "__copyuser_seg" movsl\n"
23043+ "36: movl %%eax, %0\n"
23044+ "37: rep; "__copyuser_seg" movsb\n"
23045+ "100:\n"
23046+ ".section .fixup,\"ax\"\n"
23047+ "101: lea 0(%%eax,%0,4),%0\n"
23048+ " jmp 100b\n"
23049+ ".previous\n"
23050+ ".section __ex_table,\"a\"\n"
23051+ " .align 4\n"
23052+ " .long 1b,100b\n"
23053+ " .long 2b,100b\n"
23054+ " .long 3b,100b\n"
23055+ " .long 4b,100b\n"
23056+ " .long 5b,100b\n"
23057+ " .long 6b,100b\n"
23058+ " .long 7b,100b\n"
23059+ " .long 8b,100b\n"
23060+ " .long 9b,100b\n"
23061+ " .long 10b,100b\n"
23062+ " .long 11b,100b\n"
23063+ " .long 12b,100b\n"
23064+ " .long 13b,100b\n"
23065+ " .long 14b,100b\n"
23066+ " .long 15b,100b\n"
23067+ " .long 16b,100b\n"
23068+ " .long 17b,100b\n"
23069+ " .long 18b,100b\n"
23070+ " .long 19b,100b\n"
23071+ " .long 20b,100b\n"
23072+ " .long 21b,100b\n"
23073+ " .long 22b,100b\n"
23074+ " .long 23b,100b\n"
23075+ " .long 24b,100b\n"
23076+ " .long 25b,100b\n"
23077+ " .long 26b,100b\n"
23078+ " .long 27b,100b\n"
23079+ " .long 28b,100b\n"
23080+ " .long 29b,100b\n"
23081+ " .long 30b,100b\n"
23082+ " .long 31b,100b\n"
23083+ " .long 32b,100b\n"
23084+ " .long 33b,100b\n"
23085+ " .long 34b,100b\n"
23086+ " .long 35b,100b\n"
23087+ " .long 36b,100b\n"
23088+ " .long 37b,100b\n"
23089+ " .long 99b,101b\n"
23090+ ".previous"
23091+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
23092+ : "1"(to), "2"(from), "0"(size)
23093+ : "eax", "edx", "memory");
23094+ return size;
23095+}
23096+
23097+static unsigned long
23098+__copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size) __size_overflow(3);
23099+static unsigned long
23100 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23101 {
23102 int d0, d1;
23103 __asm__ __volatile__(
23104 " .align 2,0x90\n"
23105- "0: movl 32(%4), %%eax\n"
23106+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23107 " cmpl $67, %0\n"
23108 " jbe 2f\n"
23109- "1: movl 64(%4), %%eax\n"
23110+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23111 " .align 2,0x90\n"
23112- "2: movl 0(%4), %%eax\n"
23113- "21: movl 4(%4), %%edx\n"
23114+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23115+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23116 " movl %%eax, 0(%3)\n"
23117 " movl %%edx, 4(%3)\n"
23118- "3: movl 8(%4), %%eax\n"
23119- "31: movl 12(%4),%%edx\n"
23120+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23121+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23122 " movl %%eax, 8(%3)\n"
23123 " movl %%edx, 12(%3)\n"
23124- "4: movl 16(%4), %%eax\n"
23125- "41: movl 20(%4), %%edx\n"
23126+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23127+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23128 " movl %%eax, 16(%3)\n"
23129 " movl %%edx, 20(%3)\n"
23130- "10: movl 24(%4), %%eax\n"
23131- "51: movl 28(%4), %%edx\n"
23132+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23133+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23134 " movl %%eax, 24(%3)\n"
23135 " movl %%edx, 28(%3)\n"
23136- "11: movl 32(%4), %%eax\n"
23137- "61: movl 36(%4), %%edx\n"
23138+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23139+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23140 " movl %%eax, 32(%3)\n"
23141 " movl %%edx, 36(%3)\n"
23142- "12: movl 40(%4), %%eax\n"
23143- "71: movl 44(%4), %%edx\n"
23144+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23145+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23146 " movl %%eax, 40(%3)\n"
23147 " movl %%edx, 44(%3)\n"
23148- "13: movl 48(%4), %%eax\n"
23149- "81: movl 52(%4), %%edx\n"
23150+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23151+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23152 " movl %%eax, 48(%3)\n"
23153 " movl %%edx, 52(%3)\n"
23154- "14: movl 56(%4), %%eax\n"
23155- "91: movl 60(%4), %%edx\n"
23156+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23157+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23158 " movl %%eax, 56(%3)\n"
23159 " movl %%edx, 60(%3)\n"
23160 " addl $-64, %0\n"
23161@@ -298,9 +413,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23162 " shrl $2, %0\n"
23163 " andl $3, %%eax\n"
23164 " cld\n"
23165- "6: rep; movsl\n"
23166+ "6: rep; "__copyuser_seg" movsl\n"
23167 " movl %%eax,%0\n"
23168- "7: rep; movsb\n"
23169+ "7: rep; "__copyuser_seg" movsb\n"
23170 "8:\n"
23171 ".section .fixup,\"ax\"\n"
23172 "9: lea 0(%%eax,%0,4),%0\n"
23173@@ -347,47 +462,49 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23174 */
23175
23176 static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23177+ const void __user *from, unsigned long size) __size_overflow(3);
23178+static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23179 const void __user *from, unsigned long size)
23180 {
23181 int d0, d1;
23182
23183 __asm__ __volatile__(
23184 " .align 2,0x90\n"
23185- "0: movl 32(%4), %%eax\n"
23186+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23187 " cmpl $67, %0\n"
23188 " jbe 2f\n"
23189- "1: movl 64(%4), %%eax\n"
23190+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23191 " .align 2,0x90\n"
23192- "2: movl 0(%4), %%eax\n"
23193- "21: movl 4(%4), %%edx\n"
23194+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23195+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23196 " movnti %%eax, 0(%3)\n"
23197 " movnti %%edx, 4(%3)\n"
23198- "3: movl 8(%4), %%eax\n"
23199- "31: movl 12(%4),%%edx\n"
23200+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23201+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23202 " movnti %%eax, 8(%3)\n"
23203 " movnti %%edx, 12(%3)\n"
23204- "4: movl 16(%4), %%eax\n"
23205- "41: movl 20(%4), %%edx\n"
23206+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23207+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23208 " movnti %%eax, 16(%3)\n"
23209 " movnti %%edx, 20(%3)\n"
23210- "10: movl 24(%4), %%eax\n"
23211- "51: movl 28(%4), %%edx\n"
23212+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23213+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23214 " movnti %%eax, 24(%3)\n"
23215 " movnti %%edx, 28(%3)\n"
23216- "11: movl 32(%4), %%eax\n"
23217- "61: movl 36(%4), %%edx\n"
23218+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23219+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23220 " movnti %%eax, 32(%3)\n"
23221 " movnti %%edx, 36(%3)\n"
23222- "12: movl 40(%4), %%eax\n"
23223- "71: movl 44(%4), %%edx\n"
23224+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23225+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23226 " movnti %%eax, 40(%3)\n"
23227 " movnti %%edx, 44(%3)\n"
23228- "13: movl 48(%4), %%eax\n"
23229- "81: movl 52(%4), %%edx\n"
23230+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23231+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23232 " movnti %%eax, 48(%3)\n"
23233 " movnti %%edx, 52(%3)\n"
23234- "14: movl 56(%4), %%eax\n"
23235- "91: movl 60(%4), %%edx\n"
23236+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23237+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23238 " movnti %%eax, 56(%3)\n"
23239 " movnti %%edx, 60(%3)\n"
23240 " addl $-64, %0\n"
23241@@ -400,9 +517,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23242 " shrl $2, %0\n"
23243 " andl $3, %%eax\n"
23244 " cld\n"
23245- "6: rep; movsl\n"
23246+ "6: rep; "__copyuser_seg" movsl\n"
23247 " movl %%eax,%0\n"
23248- "7: rep; movsb\n"
23249+ "7: rep; "__copyuser_seg" movsb\n"
23250 "8:\n"
23251 ".section .fixup,\"ax\"\n"
23252 "9: lea 0(%%eax,%0,4),%0\n"
23253@@ -444,47 +561,49 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23254 }
23255
23256 static unsigned long __copy_user_intel_nocache(void *to,
23257+ const void __user *from, unsigned long size) __size_overflow(3);
23258+static unsigned long __copy_user_intel_nocache(void *to,
23259 const void __user *from, unsigned long size)
23260 {
23261 int d0, d1;
23262
23263 __asm__ __volatile__(
23264 " .align 2,0x90\n"
23265- "0: movl 32(%4), %%eax\n"
23266+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23267 " cmpl $67, %0\n"
23268 " jbe 2f\n"
23269- "1: movl 64(%4), %%eax\n"
23270+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23271 " .align 2,0x90\n"
23272- "2: movl 0(%4), %%eax\n"
23273- "21: movl 4(%4), %%edx\n"
23274+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23275+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23276 " movnti %%eax, 0(%3)\n"
23277 " movnti %%edx, 4(%3)\n"
23278- "3: movl 8(%4), %%eax\n"
23279- "31: movl 12(%4),%%edx\n"
23280+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23281+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23282 " movnti %%eax, 8(%3)\n"
23283 " movnti %%edx, 12(%3)\n"
23284- "4: movl 16(%4), %%eax\n"
23285- "41: movl 20(%4), %%edx\n"
23286+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23287+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23288 " movnti %%eax, 16(%3)\n"
23289 " movnti %%edx, 20(%3)\n"
23290- "10: movl 24(%4), %%eax\n"
23291- "51: movl 28(%4), %%edx\n"
23292+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23293+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23294 " movnti %%eax, 24(%3)\n"
23295 " movnti %%edx, 28(%3)\n"
23296- "11: movl 32(%4), %%eax\n"
23297- "61: movl 36(%4), %%edx\n"
23298+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23299+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23300 " movnti %%eax, 32(%3)\n"
23301 " movnti %%edx, 36(%3)\n"
23302- "12: movl 40(%4), %%eax\n"
23303- "71: movl 44(%4), %%edx\n"
23304+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23305+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23306 " movnti %%eax, 40(%3)\n"
23307 " movnti %%edx, 44(%3)\n"
23308- "13: movl 48(%4), %%eax\n"
23309- "81: movl 52(%4), %%edx\n"
23310+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23311+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23312 " movnti %%eax, 48(%3)\n"
23313 " movnti %%edx, 52(%3)\n"
23314- "14: movl 56(%4), %%eax\n"
23315- "91: movl 60(%4), %%edx\n"
23316+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23317+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23318 " movnti %%eax, 56(%3)\n"
23319 " movnti %%edx, 60(%3)\n"
23320 " addl $-64, %0\n"
23321@@ -497,9 +616,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23322 " shrl $2, %0\n"
23323 " andl $3, %%eax\n"
23324 " cld\n"
23325- "6: rep; movsl\n"
23326+ "6: rep; "__copyuser_seg" movsl\n"
23327 " movl %%eax,%0\n"
23328- "7: rep; movsb\n"
23329+ "7: rep; "__copyuser_seg" movsb\n"
23330 "8:\n"
23331 ".section .fixup,\"ax\"\n"
23332 "9: lea 0(%%eax,%0,4),%0\n"
23333@@ -542,32 +661,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23334 */
23335 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23336 unsigned long size);
23337-unsigned long __copy_user_intel(void __user *to, const void *from,
23338+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23339+ unsigned long size);
23340+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23341 unsigned long size);
23342 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23343 const void __user *from, unsigned long size);
23344 #endif /* CONFIG_X86_INTEL_USERCOPY */
23345
23346 /* Generic arbitrary sized copy. */
23347-#define __copy_user(to, from, size) \
23348+#define __copy_user(to, from, size, prefix, set, restore) \
23349 do { \
23350 int __d0, __d1, __d2; \
23351 __asm__ __volatile__( \
23352+ set \
23353 " cmp $7,%0\n" \
23354 " jbe 1f\n" \
23355 " movl %1,%0\n" \
23356 " negl %0\n" \
23357 " andl $7,%0\n" \
23358 " subl %0,%3\n" \
23359- "4: rep; movsb\n" \
23360+ "4: rep; "prefix"movsb\n" \
23361 " movl %3,%0\n" \
23362 " shrl $2,%0\n" \
23363 " andl $3,%3\n" \
23364 " .align 2,0x90\n" \
23365- "0: rep; movsl\n" \
23366+ "0: rep; "prefix"movsl\n" \
23367 " movl %3,%0\n" \
23368- "1: rep; movsb\n" \
23369+ "1: rep; "prefix"movsb\n" \
23370 "2:\n" \
23371+ restore \
23372 ".section .fixup,\"ax\"\n" \
23373 "5: addl %3,%0\n" \
23374 " jmp 2b\n" \
23375@@ -595,14 +718,14 @@ do { \
23376 " negl %0\n" \
23377 " andl $7,%0\n" \
23378 " subl %0,%3\n" \
23379- "4: rep; movsb\n" \
23380+ "4: rep; "__copyuser_seg"movsb\n" \
23381 " movl %3,%0\n" \
23382 " shrl $2,%0\n" \
23383 " andl $3,%3\n" \
23384 " .align 2,0x90\n" \
23385- "0: rep; movsl\n" \
23386+ "0: rep; "__copyuser_seg"movsl\n" \
23387 " movl %3,%0\n" \
23388- "1: rep; movsb\n" \
23389+ "1: rep; "__copyuser_seg"movsb\n" \
23390 "2:\n" \
23391 ".section .fixup,\"ax\"\n" \
23392 "5: addl %3,%0\n" \
23393@@ -688,9 +811,9 @@ survive:
23394 }
23395 #endif
23396 if (movsl_is_ok(to, from, n))
23397- __copy_user(to, from, n);
23398+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23399 else
23400- n = __copy_user_intel(to, from, n);
23401+ n = __generic_copy_to_user_intel(to, from, n);
23402 return n;
23403 }
23404 EXPORT_SYMBOL(__copy_to_user_ll);
23405@@ -710,10 +833,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23406 unsigned long n)
23407 {
23408 if (movsl_is_ok(to, from, n))
23409- __copy_user(to, from, n);
23410+ __copy_user(to, from, n, __copyuser_seg, "", "");
23411 else
23412- n = __copy_user_intel((void __user *)to,
23413- (const void *)from, n);
23414+ n = __generic_copy_from_user_intel(to, from, n);
23415 return n;
23416 }
23417 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23418@@ -740,65 +862,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23419 if (n > 64 && cpu_has_xmm2)
23420 n = __copy_user_intel_nocache(to, from, n);
23421 else
23422- __copy_user(to, from, n);
23423+ __copy_user(to, from, n, __copyuser_seg, "", "");
23424 #else
23425- __copy_user(to, from, n);
23426+ __copy_user(to, from, n, __copyuser_seg, "", "");
23427 #endif
23428 return n;
23429 }
23430 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23431
23432-/**
23433- * copy_to_user: - Copy a block of data into user space.
23434- * @to: Destination address, in user space.
23435- * @from: Source address, in kernel space.
23436- * @n: Number of bytes to copy.
23437- *
23438- * Context: User context only. This function may sleep.
23439- *
23440- * Copy data from kernel space to user space.
23441- *
23442- * Returns number of bytes that could not be copied.
23443- * On success, this will be zero.
23444- */
23445-unsigned long
23446-copy_to_user(void __user *to, const void *from, unsigned long n)
23447-{
23448- if (access_ok(VERIFY_WRITE, to, n))
23449- n = __copy_to_user(to, from, n);
23450- return n;
23451-}
23452-EXPORT_SYMBOL(copy_to_user);
23453-
23454-/**
23455- * copy_from_user: - Copy a block of data from user space.
23456- * @to: Destination address, in kernel space.
23457- * @from: Source address, in user space.
23458- * @n: Number of bytes to copy.
23459- *
23460- * Context: User context only. This function may sleep.
23461- *
23462- * Copy data from user space to kernel space.
23463- *
23464- * Returns number of bytes that could not be copied.
23465- * On success, this will be zero.
23466- *
23467- * If some data could not be copied, this function will pad the copied
23468- * data to the requested size using zero bytes.
23469- */
23470-unsigned long
23471-_copy_from_user(void *to, const void __user *from, unsigned long n)
23472-{
23473- if (access_ok(VERIFY_READ, from, n))
23474- n = __copy_from_user(to, from, n);
23475- else
23476- memset(to, 0, n);
23477- return n;
23478-}
23479-EXPORT_SYMBOL(_copy_from_user);
23480-
23481 void copy_from_user_overflow(void)
23482 {
23483 WARN(1, "Buffer overflow detected!\n");
23484 }
23485 EXPORT_SYMBOL(copy_from_user_overflow);
23486+
23487+void copy_to_user_overflow(void)
23488+{
23489+ WARN(1, "Buffer overflow detected!\n");
23490+}
23491+EXPORT_SYMBOL(copy_to_user_overflow);
23492+
23493+#ifdef CONFIG_PAX_MEMORY_UDEREF
23494+void __set_fs(mm_segment_t x)
23495+{
23496+ switch (x.seg) {
23497+ case 0:
23498+ loadsegment(gs, 0);
23499+ break;
23500+ case TASK_SIZE_MAX:
23501+ loadsegment(gs, __USER_DS);
23502+ break;
23503+ case -1UL:
23504+ loadsegment(gs, __KERNEL_DS);
23505+ break;
23506+ default:
23507+ BUG();
23508+ }
23509+ return;
23510+}
23511+EXPORT_SYMBOL(__set_fs);
23512+
23513+void set_fs(mm_segment_t x)
23514+{
23515+ current_thread_info()->addr_limit = x;
23516+ __set_fs(x);
23517+}
23518+EXPORT_SYMBOL(set_fs);
23519+#endif
23520diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23521index 0d0326f..6a6155b 100644
23522--- a/arch/x86/lib/usercopy_64.c
23523+++ b/arch/x86/lib/usercopy_64.c
23524@@ -16,6 +16,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23525 {
23526 long __d0;
23527 might_fault();
23528+
23529+#ifdef CONFIG_PAX_MEMORY_UDEREF
23530+ if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23531+ addr += PAX_USER_SHADOW_BASE;
23532+#endif
23533+
23534 /* no memory constraint because it doesn't change any memory gcc knows
23535 about */
23536 asm volatile(
23537@@ -100,12 +106,20 @@ long strlen_user(const char __user *s)
23538 }
23539 EXPORT_SYMBOL(strlen_user);
23540
23541-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23542+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23543 {
23544- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23545- return copy_user_generic((__force void *)to, (__force void *)from, len);
23546- }
23547- return len;
23548+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23549+
23550+#ifdef CONFIG_PAX_MEMORY_UDEREF
23551+ if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23552+ to += PAX_USER_SHADOW_BASE;
23553+ if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23554+ from += PAX_USER_SHADOW_BASE;
23555+#endif
23556+
23557+ return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23558+ }
23559+ return len;
23560 }
23561 EXPORT_SYMBOL(copy_in_user);
23562
23563@@ -115,7 +129,7 @@ EXPORT_SYMBOL(copy_in_user);
23564 * it is not necessary to optimize tail handling.
23565 */
23566 unsigned long
23567-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23568+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23569 {
23570 char c;
23571 unsigned zero_len;
23572@@ -132,3 +146,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23573 break;
23574 return len;
23575 }
23576+
23577+void copy_from_user_overflow(void)
23578+{
23579+ WARN(1, "Buffer overflow detected!\n");
23580+}
23581+EXPORT_SYMBOL(copy_from_user_overflow);
23582+
23583+void copy_to_user_overflow(void)
23584+{
23585+ WARN(1, "Buffer overflow detected!\n");
23586+}
23587+EXPORT_SYMBOL(copy_to_user_overflow);
23588diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23589index 1fb85db..8b3540b 100644
23590--- a/arch/x86/mm/extable.c
23591+++ b/arch/x86/mm/extable.c
23592@@ -8,7 +8,7 @@ int fixup_exception(struct pt_regs *regs)
23593 const struct exception_table_entry *fixup;
23594
23595 #ifdef CONFIG_PNPBIOS
23596- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23597+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23598 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23599 extern u32 pnp_bios_is_utter_crap;
23600 pnp_bios_is_utter_crap = 1;
23601diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23602index 3ecfd1a..304d554 100644
23603--- a/arch/x86/mm/fault.c
23604+++ b/arch/x86/mm/fault.c
23605@@ -13,11 +13,18 @@
23606 #include <linux/perf_event.h> /* perf_sw_event */
23607 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23608 #include <linux/prefetch.h> /* prefetchw */
23609+#include <linux/unistd.h>
23610+#include <linux/compiler.h>
23611
23612 #include <asm/traps.h> /* dotraplinkage, ... */
23613 #include <asm/pgalloc.h> /* pgd_*(), ... */
23614 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23615 #include <asm/fixmap.h> /* VSYSCALL_START */
23616+#include <asm/tlbflush.h>
23617+
23618+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23619+#include <asm/stacktrace.h>
23620+#endif
23621
23622 /*
23623 * Page fault error code bits:
23624@@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23625 int ret = 0;
23626
23627 /* kprobe_running() needs smp_processor_id() */
23628- if (kprobes_built_in() && !user_mode_vm(regs)) {
23629+ if (kprobes_built_in() && !user_mode(regs)) {
23630 preempt_disable();
23631 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23632 ret = 1;
23633@@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23634 return !instr_lo || (instr_lo>>1) == 1;
23635 case 0x00:
23636 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23637- if (probe_kernel_address(instr, opcode))
23638+ if (user_mode(regs)) {
23639+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23640+ return 0;
23641+ } else if (probe_kernel_address(instr, opcode))
23642 return 0;
23643
23644 *prefetch = (instr_lo == 0xF) &&
23645@@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23646 while (instr < max_instr) {
23647 unsigned char opcode;
23648
23649- if (probe_kernel_address(instr, opcode))
23650+ if (user_mode(regs)) {
23651+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23652+ break;
23653+ } else if (probe_kernel_address(instr, opcode))
23654 break;
23655
23656 instr++;
23657@@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23658 force_sig_info(si_signo, &info, tsk);
23659 }
23660
23661+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23662+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23663+#endif
23664+
23665+#ifdef CONFIG_PAX_EMUTRAMP
23666+static int pax_handle_fetch_fault(struct pt_regs *regs);
23667+#endif
23668+
23669+#ifdef CONFIG_PAX_PAGEEXEC
23670+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23671+{
23672+ pgd_t *pgd;
23673+ pud_t *pud;
23674+ pmd_t *pmd;
23675+
23676+ pgd = pgd_offset(mm, address);
23677+ if (!pgd_present(*pgd))
23678+ return NULL;
23679+ pud = pud_offset(pgd, address);
23680+ if (!pud_present(*pud))
23681+ return NULL;
23682+ pmd = pmd_offset(pud, address);
23683+ if (!pmd_present(*pmd))
23684+ return NULL;
23685+ return pmd;
23686+}
23687+#endif
23688+
23689 DEFINE_SPINLOCK(pgd_lock);
23690 LIST_HEAD(pgd_list);
23691
23692@@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23693 for (address = VMALLOC_START & PMD_MASK;
23694 address >= TASK_SIZE && address < FIXADDR_TOP;
23695 address += PMD_SIZE) {
23696+
23697+#ifdef CONFIG_PAX_PER_CPU_PGD
23698+ unsigned long cpu;
23699+#else
23700 struct page *page;
23701+#endif
23702
23703 spin_lock(&pgd_lock);
23704+
23705+#ifdef CONFIG_PAX_PER_CPU_PGD
23706+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23707+ pgd_t *pgd = get_cpu_pgd(cpu);
23708+ pmd_t *ret;
23709+#else
23710 list_for_each_entry(page, &pgd_list, lru) {
23711+ pgd_t *pgd = page_address(page);
23712 spinlock_t *pgt_lock;
23713 pmd_t *ret;
23714
23715@@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23716 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23717
23718 spin_lock(pgt_lock);
23719- ret = vmalloc_sync_one(page_address(page), address);
23720+#endif
23721+
23722+ ret = vmalloc_sync_one(pgd, address);
23723+
23724+#ifndef CONFIG_PAX_PER_CPU_PGD
23725 spin_unlock(pgt_lock);
23726+#endif
23727
23728 if (!ret)
23729 break;
23730@@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23731 * an interrupt in the middle of a task switch..
23732 */
23733 pgd_paddr = read_cr3();
23734+
23735+#ifdef CONFIG_PAX_PER_CPU_PGD
23736+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23737+#endif
23738+
23739 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23740 if (!pmd_k)
23741 return -1;
23742@@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23743 * happen within a race in page table update. In the later
23744 * case just flush:
23745 */
23746+
23747+#ifdef CONFIG_PAX_PER_CPU_PGD
23748+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23749+ pgd = pgd_offset_cpu(smp_processor_id(), address);
23750+#else
23751 pgd = pgd_offset(current->active_mm, address);
23752+#endif
23753+
23754 pgd_ref = pgd_offset_k(address);
23755 if (pgd_none(*pgd_ref))
23756 return -1;
23757@@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23758 static int is_errata100(struct pt_regs *regs, unsigned long address)
23759 {
23760 #ifdef CONFIG_X86_64
23761- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23762+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23763 return 1;
23764 #endif
23765 return 0;
23766@@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23767 }
23768
23769 static const char nx_warning[] = KERN_CRIT
23770-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23771+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23772
23773 static void
23774 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23775@@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23776 if (!oops_may_print())
23777 return;
23778
23779- if (error_code & PF_INSTR) {
23780+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23781 unsigned int level;
23782
23783 pte_t *pte = lookup_address(address, &level);
23784
23785 if (pte && pte_present(*pte) && !pte_exec(*pte))
23786- printk(nx_warning, current_uid());
23787+ printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
23788 }
23789
23790+#ifdef CONFIG_PAX_KERNEXEC
23791+ if (init_mm.start_code <= address && address < init_mm.end_code) {
23792+ if (current->signal->curr_ip)
23793+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23794+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23795+ else
23796+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23797+ current->comm, task_pid_nr(current), current_uid(), current_euid());
23798+ }
23799+#endif
23800+
23801 printk(KERN_ALERT "BUG: unable to handle kernel ");
23802 if (address < PAGE_SIZE)
23803 printk(KERN_CONT "NULL pointer dereference");
23804@@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23805 }
23806 #endif
23807
23808+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23809+ if (pax_is_fetch_fault(regs, error_code, address)) {
23810+
23811+#ifdef CONFIG_PAX_EMUTRAMP
23812+ switch (pax_handle_fetch_fault(regs)) {
23813+ case 2:
23814+ return;
23815+ }
23816+#endif
23817+
23818+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23819+ do_group_exit(SIGKILL);
23820+ }
23821+#endif
23822+
23823 if (unlikely(show_unhandled_signals))
23824 show_signal_msg(regs, error_code, address, tsk);
23825
23826@@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23827 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23828 printk(KERN_ERR
23829 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23830- tsk->comm, tsk->pid, address);
23831+ tsk->comm, task_pid_nr(tsk), address);
23832 code = BUS_MCEERR_AR;
23833 }
23834 #endif
23835@@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23836 return 1;
23837 }
23838
23839+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23840+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23841+{
23842+ pte_t *pte;
23843+ pmd_t *pmd;
23844+ spinlock_t *ptl;
23845+ unsigned char pte_mask;
23846+
23847+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23848+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
23849+ return 0;
23850+
23851+ /* PaX: it's our fault, let's handle it if we can */
23852+
23853+ /* PaX: take a look at read faults before acquiring any locks */
23854+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23855+ /* instruction fetch attempt from a protected page in user mode */
23856+ up_read(&mm->mmap_sem);
23857+
23858+#ifdef CONFIG_PAX_EMUTRAMP
23859+ switch (pax_handle_fetch_fault(regs)) {
23860+ case 2:
23861+ return 1;
23862+ }
23863+#endif
23864+
23865+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23866+ do_group_exit(SIGKILL);
23867+ }
23868+
23869+ pmd = pax_get_pmd(mm, address);
23870+ if (unlikely(!pmd))
23871+ return 0;
23872+
23873+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23874+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23875+ pte_unmap_unlock(pte, ptl);
23876+ return 0;
23877+ }
23878+
23879+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23880+ /* write attempt to a protected page in user mode */
23881+ pte_unmap_unlock(pte, ptl);
23882+ return 0;
23883+ }
23884+
23885+#ifdef CONFIG_SMP
23886+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23887+#else
23888+ if (likely(address > get_limit(regs->cs)))
23889+#endif
23890+ {
23891+ set_pte(pte, pte_mkread(*pte));
23892+ __flush_tlb_one(address);
23893+ pte_unmap_unlock(pte, ptl);
23894+ up_read(&mm->mmap_sem);
23895+ return 1;
23896+ }
23897+
23898+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23899+
23900+ /*
23901+ * PaX: fill DTLB with user rights and retry
23902+ */
23903+ __asm__ __volatile__ (
23904+ "orb %2,(%1)\n"
23905+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23906+/*
23907+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23908+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23909+ * page fault when examined during a TLB load attempt. this is true not only
23910+ * for PTEs holding a non-present entry but also present entries that will
23911+ * raise a page fault (such as those set up by PaX, or the copy-on-write
23912+ * mechanism). in effect it means that we do *not* need to flush the TLBs
23913+ * for our target pages since their PTEs are simply not in the TLBs at all.
23914+
23915+ * the best thing in omitting it is that we gain around 15-20% speed in the
23916+ * fast path of the page fault handler and can get rid of tracing since we
23917+ * can no longer flush unintended entries.
23918+ */
23919+ "invlpg (%0)\n"
23920+#endif
23921+ __copyuser_seg"testb $0,(%0)\n"
23922+ "xorb %3,(%1)\n"
23923+ :
23924+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23925+ : "memory", "cc");
23926+ pte_unmap_unlock(pte, ptl);
23927+ up_read(&mm->mmap_sem);
23928+ return 1;
23929+}
23930+#endif
23931+
23932 /*
23933 * Handle a spurious fault caused by a stale TLB entry.
23934 *
23935@@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23936 static inline int
23937 access_error(unsigned long error_code, struct vm_area_struct *vma)
23938 {
23939+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23940+ return 1;
23941+
23942 if (error_code & PF_WRITE) {
23943 /* write, present and write, not present: */
23944 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23945@@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23946 {
23947 struct vm_area_struct *vma;
23948 struct task_struct *tsk;
23949- unsigned long address;
23950 struct mm_struct *mm;
23951 int fault;
23952 int write = error_code & PF_WRITE;
23953 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23954 (write ? FAULT_FLAG_WRITE : 0);
23955
23956- tsk = current;
23957- mm = tsk->mm;
23958-
23959 /* Get the faulting address: */
23960- address = read_cr2();
23961+ unsigned long address = read_cr2();
23962+
23963+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23964+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23965+ if (!search_exception_tables(regs->ip)) {
23966+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23967+ bad_area_nosemaphore(regs, error_code, address);
23968+ return;
23969+ }
23970+ if (address < PAX_USER_SHADOW_BASE) {
23971+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23972+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
23973+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
23974+ } else
23975+ address -= PAX_USER_SHADOW_BASE;
23976+ }
23977+#endif
23978+
23979+ tsk = current;
23980+ mm = tsk->mm;
23981
23982 /*
23983 * Detect and handle instructions that would cause a page fault for
23984@@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23985 * User-mode registers count as a user access even for any
23986 * potential system fault or CPU buglet:
23987 */
23988- if (user_mode_vm(regs)) {
23989+ if (user_mode(regs)) {
23990 local_irq_enable();
23991 error_code |= PF_USER;
23992 } else {
23993@@ -1132,6 +1339,11 @@ retry:
23994 might_sleep();
23995 }
23996
23997+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23998+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
23999+ return;
24000+#endif
24001+
24002 vma = find_vma(mm, address);
24003 if (unlikely(!vma)) {
24004 bad_area(regs, error_code, address);
24005@@ -1143,18 +1355,24 @@ retry:
24006 bad_area(regs, error_code, address);
24007 return;
24008 }
24009- if (error_code & PF_USER) {
24010- /*
24011- * Accessing the stack below %sp is always a bug.
24012- * The large cushion allows instructions like enter
24013- * and pusha to work. ("enter $65535, $31" pushes
24014- * 32 pointers and then decrements %sp by 65535.)
24015- */
24016- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
24017- bad_area(regs, error_code, address);
24018- return;
24019- }
24020+ /*
24021+ * Accessing the stack below %sp is always a bug.
24022+ * The large cushion allows instructions like enter
24023+ * and pusha to work. ("enter $65535, $31" pushes
24024+ * 32 pointers and then decrements %sp by 65535.)
24025+ */
24026+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
24027+ bad_area(regs, error_code, address);
24028+ return;
24029 }
24030+
24031+#ifdef CONFIG_PAX_SEGMEXEC
24032+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
24033+ bad_area(regs, error_code, address);
24034+ return;
24035+ }
24036+#endif
24037+
24038 if (unlikely(expand_stack(vma, address))) {
24039 bad_area(regs, error_code, address);
24040 return;
24041@@ -1209,3 +1427,292 @@ good_area:
24042
24043 up_read(&mm->mmap_sem);
24044 }
24045+
24046+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24047+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
24048+{
24049+ struct mm_struct *mm = current->mm;
24050+ unsigned long ip = regs->ip;
24051+
24052+ if (v8086_mode(regs))
24053+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24054+
24055+#ifdef CONFIG_PAX_PAGEEXEC
24056+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24057+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24058+ return true;
24059+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24060+ return true;
24061+ return false;
24062+ }
24063+#endif
24064+
24065+#ifdef CONFIG_PAX_SEGMEXEC
24066+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24067+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24068+ return true;
24069+ return false;
24070+ }
24071+#endif
24072+
24073+ return false;
24074+}
24075+#endif
24076+
24077+#ifdef CONFIG_PAX_EMUTRAMP
24078+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24079+{
24080+ int err;
24081+
24082+ do { /* PaX: libffi trampoline emulation */
24083+ unsigned char mov, jmp;
24084+ unsigned int addr1, addr2;
24085+
24086+#ifdef CONFIG_X86_64
24087+ if ((regs->ip + 9) >> 32)
24088+ break;
24089+#endif
24090+
24091+ err = get_user(mov, (unsigned char __user *)regs->ip);
24092+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24093+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24094+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24095+
24096+ if (err)
24097+ break;
24098+
24099+ if (mov == 0xB8 && jmp == 0xE9) {
24100+ regs->ax = addr1;
24101+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24102+ return 2;
24103+ }
24104+ } while (0);
24105+
24106+ do { /* PaX: gcc trampoline emulation #1 */
24107+ unsigned char mov1, mov2;
24108+ unsigned short jmp;
24109+ unsigned int addr1, addr2;
24110+
24111+#ifdef CONFIG_X86_64
24112+ if ((regs->ip + 11) >> 32)
24113+ break;
24114+#endif
24115+
24116+ err = get_user(mov1, (unsigned char __user *)regs->ip);
24117+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24118+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24119+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24120+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24121+
24122+ if (err)
24123+ break;
24124+
24125+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24126+ regs->cx = addr1;
24127+ regs->ax = addr2;
24128+ regs->ip = addr2;
24129+ return 2;
24130+ }
24131+ } while (0);
24132+
24133+ do { /* PaX: gcc trampoline emulation #2 */
24134+ unsigned char mov, jmp;
24135+ unsigned int addr1, addr2;
24136+
24137+#ifdef CONFIG_X86_64
24138+ if ((regs->ip + 9) >> 32)
24139+ break;
24140+#endif
24141+
24142+ err = get_user(mov, (unsigned char __user *)regs->ip);
24143+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24144+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24145+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24146+
24147+ if (err)
24148+ break;
24149+
24150+ if (mov == 0xB9 && jmp == 0xE9) {
24151+ regs->cx = addr1;
24152+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24153+ return 2;
24154+ }
24155+ } while (0);
24156+
24157+ return 1; /* PaX in action */
24158+}
24159+
24160+#ifdef CONFIG_X86_64
24161+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24162+{
24163+ int err;
24164+
24165+ do { /* PaX: libffi trampoline emulation */
24166+ unsigned short mov1, mov2, jmp1;
24167+ unsigned char stcclc, jmp2;
24168+ unsigned long addr1, addr2;
24169+
24170+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24171+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24172+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24173+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24174+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24175+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24176+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24177+
24178+ if (err)
24179+ break;
24180+
24181+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24182+ regs->r11 = addr1;
24183+ regs->r10 = addr2;
24184+ if (stcclc == 0xF8)
24185+ regs->flags &= ~X86_EFLAGS_CF;
24186+ else
24187+ regs->flags |= X86_EFLAGS_CF;
24188+ regs->ip = addr1;
24189+ return 2;
24190+ }
24191+ } while (0);
24192+
24193+ do { /* PaX: gcc trampoline emulation #1 */
24194+ unsigned short mov1, mov2, jmp1;
24195+ unsigned char jmp2;
24196+ unsigned int addr1;
24197+ unsigned long addr2;
24198+
24199+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24200+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24201+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24202+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24203+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24204+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24205+
24206+ if (err)
24207+ break;
24208+
24209+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24210+ regs->r11 = addr1;
24211+ regs->r10 = addr2;
24212+ regs->ip = addr1;
24213+ return 2;
24214+ }
24215+ } while (0);
24216+
24217+ do { /* PaX: gcc trampoline emulation #2 */
24218+ unsigned short mov1, mov2, jmp1;
24219+ unsigned char jmp2;
24220+ unsigned long addr1, addr2;
24221+
24222+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24223+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24224+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24225+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24226+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24227+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24228+
24229+ if (err)
24230+ break;
24231+
24232+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24233+ regs->r11 = addr1;
24234+ regs->r10 = addr2;
24235+ regs->ip = addr1;
24236+ return 2;
24237+ }
24238+ } while (0);
24239+
24240+ return 1; /* PaX in action */
24241+}
24242+#endif
24243+
24244+/*
24245+ * PaX: decide what to do with offenders (regs->ip = fault address)
24246+ *
24247+ * returns 1 when task should be killed
24248+ * 2 when gcc trampoline was detected
24249+ */
24250+static int pax_handle_fetch_fault(struct pt_regs *regs)
24251+{
24252+ if (v8086_mode(regs))
24253+ return 1;
24254+
24255+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24256+ return 1;
24257+
24258+#ifdef CONFIG_X86_32
24259+ return pax_handle_fetch_fault_32(regs);
24260+#else
24261+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24262+ return pax_handle_fetch_fault_32(regs);
24263+ else
24264+ return pax_handle_fetch_fault_64(regs);
24265+#endif
24266+}
24267+#endif
24268+
24269+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24270+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24271+{
24272+ long i;
24273+
24274+ printk(KERN_ERR "PAX: bytes at PC: ");
24275+ for (i = 0; i < 20; i++) {
24276+ unsigned char c;
24277+ if (get_user(c, (unsigned char __force_user *)pc+i))
24278+ printk(KERN_CONT "?? ");
24279+ else
24280+ printk(KERN_CONT "%02x ", c);
24281+ }
24282+ printk("\n");
24283+
24284+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24285+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
24286+ unsigned long c;
24287+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
24288+#ifdef CONFIG_X86_32
24289+ printk(KERN_CONT "???????? ");
24290+#else
24291+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24292+ printk(KERN_CONT "???????? ???????? ");
24293+ else
24294+ printk(KERN_CONT "???????????????? ");
24295+#endif
24296+ } else {
24297+#ifdef CONFIG_X86_64
24298+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24299+ printk(KERN_CONT "%08x ", (unsigned int)c);
24300+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24301+ } else
24302+#endif
24303+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24304+ }
24305+ }
24306+ printk("\n");
24307+}
24308+#endif
24309+
24310+/**
24311+ * probe_kernel_write(): safely attempt to write to a location
24312+ * @dst: address to write to
24313+ * @src: pointer to the data that shall be written
24314+ * @size: size of the data chunk
24315+ *
24316+ * Safely write to address @dst from the buffer at @src. If a kernel fault
24317+ * happens, handle that and return -EFAULT.
24318+ */
24319+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24320+{
24321+ long ret;
24322+ mm_segment_t old_fs = get_fs();
24323+
24324+ set_fs(KERNEL_DS);
24325+ pagefault_disable();
24326+ pax_open_kernel();
24327+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24328+ pax_close_kernel();
24329+ pagefault_enable();
24330+ set_fs(old_fs);
24331+
24332+ return ret ? -EFAULT : 0;
24333+}
24334diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24335index dd74e46..7d26398 100644
24336--- a/arch/x86/mm/gup.c
24337+++ b/arch/x86/mm/gup.c
24338@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24339 addr = start;
24340 len = (unsigned long) nr_pages << PAGE_SHIFT;
24341 end = start + len;
24342- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24343+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24344 (void __user *)start, len)))
24345 return 0;
24346
24347diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24348index 6f31ee5..8ee4164 100644
24349--- a/arch/x86/mm/highmem_32.c
24350+++ b/arch/x86/mm/highmem_32.c
24351@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24352 idx = type + KM_TYPE_NR*smp_processor_id();
24353 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24354 BUG_ON(!pte_none(*(kmap_pte-idx)));
24355+
24356+ pax_open_kernel();
24357 set_pte(kmap_pte-idx, mk_pte(page, prot));
24358+ pax_close_kernel();
24359+
24360 arch_flush_lazy_mmu_mode();
24361
24362 return (void *)vaddr;
24363diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24364index f6679a7..8f795a3 100644
24365--- a/arch/x86/mm/hugetlbpage.c
24366+++ b/arch/x86/mm/hugetlbpage.c
24367@@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24368 struct hstate *h = hstate_file(file);
24369 struct mm_struct *mm = current->mm;
24370 struct vm_area_struct *vma;
24371- unsigned long start_addr;
24372+ unsigned long start_addr, pax_task_size = TASK_SIZE;
24373+
24374+#ifdef CONFIG_PAX_SEGMEXEC
24375+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24376+ pax_task_size = SEGMEXEC_TASK_SIZE;
24377+#endif
24378+
24379+ pax_task_size -= PAGE_SIZE;
24380
24381 if (len > mm->cached_hole_size) {
24382- start_addr = mm->free_area_cache;
24383+ start_addr = mm->free_area_cache;
24384 } else {
24385- start_addr = TASK_UNMAPPED_BASE;
24386- mm->cached_hole_size = 0;
24387+ start_addr = mm->mmap_base;
24388+ mm->cached_hole_size = 0;
24389 }
24390
24391 full_search:
24392@@ -280,26 +287,27 @@ full_search:
24393
24394 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24395 /* At this point: (!vma || addr < vma->vm_end). */
24396- if (TASK_SIZE - len < addr) {
24397+ if (pax_task_size - len < addr) {
24398 /*
24399 * Start a new search - just in case we missed
24400 * some holes.
24401 */
24402- if (start_addr != TASK_UNMAPPED_BASE) {
24403- start_addr = TASK_UNMAPPED_BASE;
24404+ if (start_addr != mm->mmap_base) {
24405+ start_addr = mm->mmap_base;
24406 mm->cached_hole_size = 0;
24407 goto full_search;
24408 }
24409 return -ENOMEM;
24410 }
24411- if (!vma || addr + len <= vma->vm_start) {
24412- mm->free_area_cache = addr + len;
24413- return addr;
24414- }
24415+ if (check_heap_stack_gap(vma, addr, len))
24416+ break;
24417 if (addr + mm->cached_hole_size < vma->vm_start)
24418 mm->cached_hole_size = vma->vm_start - addr;
24419 addr = ALIGN(vma->vm_end, huge_page_size(h));
24420 }
24421+
24422+ mm->free_area_cache = addr + len;
24423+ return addr;
24424 }
24425
24426 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24427@@ -310,9 +318,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24428 struct mm_struct *mm = current->mm;
24429 struct vm_area_struct *vma;
24430 unsigned long base = mm->mmap_base;
24431- unsigned long addr = addr0;
24432+ unsigned long addr;
24433 unsigned long largest_hole = mm->cached_hole_size;
24434- unsigned long start_addr;
24435
24436 /* don't allow allocations above current base */
24437 if (mm->free_area_cache > base)
24438@@ -322,16 +329,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24439 largest_hole = 0;
24440 mm->free_area_cache = base;
24441 }
24442-try_again:
24443- start_addr = mm->free_area_cache;
24444
24445 /* make sure it can fit in the remaining address space */
24446 if (mm->free_area_cache < len)
24447 goto fail;
24448
24449 /* either no address requested or can't fit in requested address hole */
24450- addr = (mm->free_area_cache - len) & huge_page_mask(h);
24451+ addr = mm->free_area_cache - len;
24452 do {
24453+ addr &= huge_page_mask(h);
24454 /*
24455 * Lookup failure means no vma is above this address,
24456 * i.e. return with success:
24457@@ -340,10 +346,10 @@ try_again:
24458 if (!vma)
24459 return addr;
24460
24461- if (addr + len <= vma->vm_start) {
24462+ if (check_heap_stack_gap(vma, addr, len)) {
24463 /* remember the address as a hint for next time */
24464- mm->cached_hole_size = largest_hole;
24465- return (mm->free_area_cache = addr);
24466+ mm->cached_hole_size = largest_hole;
24467+ return (mm->free_area_cache = addr);
24468 } else if (mm->free_area_cache == vma->vm_end) {
24469 /* pull free_area_cache down to the first hole */
24470 mm->free_area_cache = vma->vm_start;
24471@@ -352,29 +358,34 @@ try_again:
24472
24473 /* remember the largest hole we saw so far */
24474 if (addr + largest_hole < vma->vm_start)
24475- largest_hole = vma->vm_start - addr;
24476+ largest_hole = vma->vm_start - addr;
24477
24478 /* try just below the current vma->vm_start */
24479- addr = (vma->vm_start - len) & huge_page_mask(h);
24480- } while (len <= vma->vm_start);
24481+ addr = skip_heap_stack_gap(vma, len);
24482+ } while (!IS_ERR_VALUE(addr));
24483
24484 fail:
24485 /*
24486- * if hint left us with no space for the requested
24487- * mapping then try again:
24488- */
24489- if (start_addr != base) {
24490- mm->free_area_cache = base;
24491- largest_hole = 0;
24492- goto try_again;
24493- }
24494- /*
24495 * A failed mmap() very likely causes application failure,
24496 * so fall back to the bottom-up function here. This scenario
24497 * can happen with large stack limits and large mmap()
24498 * allocations.
24499 */
24500- mm->free_area_cache = TASK_UNMAPPED_BASE;
24501+
24502+#ifdef CONFIG_PAX_SEGMEXEC
24503+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24504+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24505+ else
24506+#endif
24507+
24508+ mm->mmap_base = TASK_UNMAPPED_BASE;
24509+
24510+#ifdef CONFIG_PAX_RANDMMAP
24511+ if (mm->pax_flags & MF_PAX_RANDMMAP)
24512+ mm->mmap_base += mm->delta_mmap;
24513+#endif
24514+
24515+ mm->free_area_cache = mm->mmap_base;
24516 mm->cached_hole_size = ~0UL;
24517 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24518 len, pgoff, flags);
24519@@ -382,6 +393,7 @@ fail:
24520 /*
24521 * Restore the topdown base:
24522 */
24523+ mm->mmap_base = base;
24524 mm->free_area_cache = base;
24525 mm->cached_hole_size = ~0UL;
24526
24527@@ -395,10 +407,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24528 struct hstate *h = hstate_file(file);
24529 struct mm_struct *mm = current->mm;
24530 struct vm_area_struct *vma;
24531+ unsigned long pax_task_size = TASK_SIZE;
24532
24533 if (len & ~huge_page_mask(h))
24534 return -EINVAL;
24535- if (len > TASK_SIZE)
24536+
24537+#ifdef CONFIG_PAX_SEGMEXEC
24538+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24539+ pax_task_size = SEGMEXEC_TASK_SIZE;
24540+#endif
24541+
24542+ pax_task_size -= PAGE_SIZE;
24543+
24544+ if (len > pax_task_size)
24545 return -ENOMEM;
24546
24547 if (flags & MAP_FIXED) {
24548@@ -410,8 +431,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24549 if (addr) {
24550 addr = ALIGN(addr, huge_page_size(h));
24551 vma = find_vma(mm, addr);
24552- if (TASK_SIZE - len >= addr &&
24553- (!vma || addr + len <= vma->vm_start))
24554+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24555 return addr;
24556 }
24557 if (mm->get_unmapped_area == arch_get_unmapped_area)
24558diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24559index 4f0cec7..00976ce 100644
24560--- a/arch/x86/mm/init.c
24561+++ b/arch/x86/mm/init.c
24562@@ -16,6 +16,8 @@
24563 #include <asm/tlb.h>
24564 #include <asm/proto.h>
24565 #include <asm/dma.h> /* for MAX_DMA_PFN */
24566+#include <asm/desc.h>
24567+#include <asm/bios_ebda.h>
24568
24569 unsigned long __initdata pgt_buf_start;
24570 unsigned long __meminitdata pgt_buf_end;
24571@@ -32,7 +34,7 @@ int direct_gbpages
24572 static void __init find_early_table_space(unsigned long end, int use_pse,
24573 int use_gbpages)
24574 {
24575- unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
24576+ unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
24577 phys_addr_t base;
24578
24579 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
24580@@ -311,10 +313,37 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24581 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24582 * mmio resources as well as potential bios/acpi data regions.
24583 */
24584+
24585+#ifdef CONFIG_GRKERNSEC_KMEM
24586+static unsigned int ebda_start __read_only;
24587+static unsigned int ebda_end __read_only;
24588+#endif
24589+
24590 int devmem_is_allowed(unsigned long pagenr)
24591 {
24592+#ifdef CONFIG_GRKERNSEC_KMEM
24593+ /* allow BDA */
24594+ if (!pagenr)
24595+ return 1;
24596+ /* allow EBDA */
24597+ if (pagenr >= ebda_start && pagenr < ebda_end)
24598+ return 1;
24599+#else
24600+ if (!pagenr)
24601+ return 1;
24602+#ifdef CONFIG_VM86
24603+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24604+ return 1;
24605+#endif
24606+#endif
24607+
24608+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24609+ return 1;
24610+#ifdef CONFIG_GRKERNSEC_KMEM
24611+ /* throw out everything else below 1MB */
24612 if (pagenr <= 256)
24613- return 1;
24614+ return 0;
24615+#endif
24616 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24617 return 0;
24618 if (!page_is_ram(pagenr))
24619@@ -371,8 +400,116 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24620 #endif
24621 }
24622
24623+#ifdef CONFIG_GRKERNSEC_KMEM
24624+static inline void gr_init_ebda(void)
24625+{
24626+ unsigned int ebda_addr;
24627+ unsigned int ebda_size = 0;
24628+
24629+ ebda_addr = get_bios_ebda();
24630+ if (ebda_addr) {
24631+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24632+ ebda_size <<= 10;
24633+ }
24634+ if (ebda_addr && ebda_size) {
24635+ ebda_start = ebda_addr >> PAGE_SHIFT;
24636+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24637+ } else {
24638+ ebda_start = 0x9f000 >> PAGE_SHIFT;
24639+ ebda_end = 0xa0000 >> PAGE_SHIFT;
24640+ }
24641+}
24642+#else
24643+static inline void gr_init_ebda(void) { }
24644+#endif
24645+
24646 void free_initmem(void)
24647 {
24648+#ifdef CONFIG_PAX_KERNEXEC
24649+#ifdef CONFIG_X86_32
24650+ /* PaX: limit KERNEL_CS to actual size */
24651+ unsigned long addr, limit;
24652+ struct desc_struct d;
24653+ int cpu;
24654+#else
24655+ pgd_t *pgd;
24656+ pud_t *pud;
24657+ pmd_t *pmd;
24658+ unsigned long addr, end;
24659+#endif
24660+#endif
24661+
24662+ gr_init_ebda();
24663+
24664+#ifdef CONFIG_PAX_KERNEXEC
24665+#ifdef CONFIG_X86_32
24666+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24667+ limit = (limit - 1UL) >> PAGE_SHIFT;
24668+
24669+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24670+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24671+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24672+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24673+ }
24674+
24675+ /* PaX: make KERNEL_CS read-only */
24676+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24677+ if (!paravirt_enabled())
24678+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24679+/*
24680+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24681+ pgd = pgd_offset_k(addr);
24682+ pud = pud_offset(pgd, addr);
24683+ pmd = pmd_offset(pud, addr);
24684+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24685+ }
24686+*/
24687+#ifdef CONFIG_X86_PAE
24688+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24689+/*
24690+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24691+ pgd = pgd_offset_k(addr);
24692+ pud = pud_offset(pgd, addr);
24693+ pmd = pmd_offset(pud, addr);
24694+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24695+ }
24696+*/
24697+#endif
24698+
24699+#ifdef CONFIG_MODULES
24700+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24701+#endif
24702+
24703+#else
24704+ /* PaX: make kernel code/rodata read-only, rest non-executable */
24705+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24706+ pgd = pgd_offset_k(addr);
24707+ pud = pud_offset(pgd, addr);
24708+ pmd = pmd_offset(pud, addr);
24709+ if (!pmd_present(*pmd))
24710+ continue;
24711+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24712+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24713+ else
24714+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24715+ }
24716+
24717+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24718+ end = addr + KERNEL_IMAGE_SIZE;
24719+ for (; addr < end; addr += PMD_SIZE) {
24720+ pgd = pgd_offset_k(addr);
24721+ pud = pud_offset(pgd, addr);
24722+ pmd = pmd_offset(pud, addr);
24723+ if (!pmd_present(*pmd))
24724+ continue;
24725+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24726+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24727+ }
24728+#endif
24729+
24730+ flush_tlb_all();
24731+#endif
24732+
24733 free_init_pages("unused kernel memory",
24734 (unsigned long)(&__init_begin),
24735 (unsigned long)(&__init_end));
24736diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24737index 575d86f..4987469 100644
24738--- a/arch/x86/mm/init_32.c
24739+++ b/arch/x86/mm/init_32.c
24740@@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24741 }
24742
24743 /*
24744- * Creates a middle page table and puts a pointer to it in the
24745- * given global directory entry. This only returns the gd entry
24746- * in non-PAE compilation mode, since the middle layer is folded.
24747- */
24748-static pmd_t * __init one_md_table_init(pgd_t *pgd)
24749-{
24750- pud_t *pud;
24751- pmd_t *pmd_table;
24752-
24753-#ifdef CONFIG_X86_PAE
24754- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24755- if (after_bootmem)
24756- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24757- else
24758- pmd_table = (pmd_t *)alloc_low_page();
24759- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24760- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24761- pud = pud_offset(pgd, 0);
24762- BUG_ON(pmd_table != pmd_offset(pud, 0));
24763-
24764- return pmd_table;
24765- }
24766-#endif
24767- pud = pud_offset(pgd, 0);
24768- pmd_table = pmd_offset(pud, 0);
24769-
24770- return pmd_table;
24771-}
24772-
24773-/*
24774 * Create a page table and place a pointer to it in a middle page
24775 * directory entry:
24776 */
24777@@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24778 page_table = (pte_t *)alloc_low_page();
24779
24780 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24781+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24782+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24783+#else
24784 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24785+#endif
24786 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24787 }
24788
24789 return pte_offset_kernel(pmd, 0);
24790 }
24791
24792+static pmd_t * __init one_md_table_init(pgd_t *pgd)
24793+{
24794+ pud_t *pud;
24795+ pmd_t *pmd_table;
24796+
24797+ pud = pud_offset(pgd, 0);
24798+ pmd_table = pmd_offset(pud, 0);
24799+
24800+ return pmd_table;
24801+}
24802+
24803 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24804 {
24805 int pgd_idx = pgd_index(vaddr);
24806@@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24807 int pgd_idx, pmd_idx;
24808 unsigned long vaddr;
24809 pgd_t *pgd;
24810+ pud_t *pud;
24811 pmd_t *pmd;
24812 pte_t *pte = NULL;
24813
24814@@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24815 pgd = pgd_base + pgd_idx;
24816
24817 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24818- pmd = one_md_table_init(pgd);
24819- pmd = pmd + pmd_index(vaddr);
24820+ pud = pud_offset(pgd, vaddr);
24821+ pmd = pmd_offset(pud, vaddr);
24822+
24823+#ifdef CONFIG_X86_PAE
24824+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24825+#endif
24826+
24827 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24828 pmd++, pmd_idx++) {
24829 pte = page_table_kmap_check(one_page_table_init(pmd),
24830@@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24831 }
24832 }
24833
24834-static inline int is_kernel_text(unsigned long addr)
24835+static inline int is_kernel_text(unsigned long start, unsigned long end)
24836 {
24837- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24838- return 1;
24839- return 0;
24840+ if ((start > ktla_ktva((unsigned long)_etext) ||
24841+ end <= ktla_ktva((unsigned long)_stext)) &&
24842+ (start > ktla_ktva((unsigned long)_einittext) ||
24843+ end <= ktla_ktva((unsigned long)_sinittext)) &&
24844+
24845+#ifdef CONFIG_ACPI_SLEEP
24846+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24847+#endif
24848+
24849+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24850+ return 0;
24851+ return 1;
24852 }
24853
24854 /*
24855@@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24856 unsigned long last_map_addr = end;
24857 unsigned long start_pfn, end_pfn;
24858 pgd_t *pgd_base = swapper_pg_dir;
24859- int pgd_idx, pmd_idx, pte_ofs;
24860+ unsigned int pgd_idx, pmd_idx, pte_ofs;
24861 unsigned long pfn;
24862 pgd_t *pgd;
24863+ pud_t *pud;
24864 pmd_t *pmd;
24865 pte_t *pte;
24866 unsigned pages_2m, pages_4k;
24867@@ -280,8 +281,13 @@ repeat:
24868 pfn = start_pfn;
24869 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24870 pgd = pgd_base + pgd_idx;
24871- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24872- pmd = one_md_table_init(pgd);
24873+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24874+ pud = pud_offset(pgd, 0);
24875+ pmd = pmd_offset(pud, 0);
24876+
24877+#ifdef CONFIG_X86_PAE
24878+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24879+#endif
24880
24881 if (pfn >= end_pfn)
24882 continue;
24883@@ -293,14 +299,13 @@ repeat:
24884 #endif
24885 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24886 pmd++, pmd_idx++) {
24887- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24888+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24889
24890 /*
24891 * Map with big pages if possible, otherwise
24892 * create normal page tables:
24893 */
24894 if (use_pse) {
24895- unsigned int addr2;
24896 pgprot_t prot = PAGE_KERNEL_LARGE;
24897 /*
24898 * first pass will use the same initial
24899@@ -310,11 +315,7 @@ repeat:
24900 __pgprot(PTE_IDENT_ATTR |
24901 _PAGE_PSE);
24902
24903- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24904- PAGE_OFFSET + PAGE_SIZE-1;
24905-
24906- if (is_kernel_text(addr) ||
24907- is_kernel_text(addr2))
24908+ if (is_kernel_text(address, address + PMD_SIZE))
24909 prot = PAGE_KERNEL_LARGE_EXEC;
24910
24911 pages_2m++;
24912@@ -331,7 +332,7 @@ repeat:
24913 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24914 pte += pte_ofs;
24915 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24916- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24917+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24918 pgprot_t prot = PAGE_KERNEL;
24919 /*
24920 * first pass will use the same initial
24921@@ -339,7 +340,7 @@ repeat:
24922 */
24923 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24924
24925- if (is_kernel_text(addr))
24926+ if (is_kernel_text(address, address + PAGE_SIZE))
24927 prot = PAGE_KERNEL_EXEC;
24928
24929 pages_4k++;
24930@@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24931
24932 pud = pud_offset(pgd, va);
24933 pmd = pmd_offset(pud, va);
24934- if (!pmd_present(*pmd))
24935+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
24936 break;
24937
24938 pte = pte_offset_kernel(pmd, va);
24939@@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
24940
24941 static void __init pagetable_init(void)
24942 {
24943- pgd_t *pgd_base = swapper_pg_dir;
24944-
24945- permanent_kmaps_init(pgd_base);
24946+ permanent_kmaps_init(swapper_pg_dir);
24947 }
24948
24949-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24950+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24951 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24952
24953 /* user-defined highmem size */
24954@@ -734,6 +733,12 @@ void __init mem_init(void)
24955
24956 pci_iommu_alloc();
24957
24958+#ifdef CONFIG_PAX_PER_CPU_PGD
24959+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24960+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24961+ KERNEL_PGD_PTRS);
24962+#endif
24963+
24964 #ifdef CONFIG_FLATMEM
24965 BUG_ON(!mem_map);
24966 #endif
24967@@ -760,7 +765,7 @@ void __init mem_init(void)
24968 reservedpages++;
24969
24970 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24971- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
24972+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
24973 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
24974
24975 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
24976@@ -801,10 +806,10 @@ void __init mem_init(void)
24977 ((unsigned long)&__init_end -
24978 (unsigned long)&__init_begin) >> 10,
24979
24980- (unsigned long)&_etext, (unsigned long)&_edata,
24981- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
24982+ (unsigned long)&_sdata, (unsigned long)&_edata,
24983+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
24984
24985- (unsigned long)&_text, (unsigned long)&_etext,
24986+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
24987 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
24988
24989 /*
24990@@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
24991 if (!kernel_set_to_readonly)
24992 return;
24993
24994+ start = ktla_ktva(start);
24995 pr_debug("Set kernel text: %lx - %lx for read write\n",
24996 start, start+size);
24997
24998@@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
24999 if (!kernel_set_to_readonly)
25000 return;
25001
25002+ start = ktla_ktva(start);
25003 pr_debug("Set kernel text: %lx - %lx for read only\n",
25004 start, start+size);
25005
25006@@ -924,6 +931,7 @@ void mark_rodata_ro(void)
25007 unsigned long start = PFN_ALIGN(_text);
25008 unsigned long size = PFN_ALIGN(_etext) - start;
25009
25010+ start = ktla_ktva(start);
25011 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
25012 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
25013 size >> 10);
25014diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
25015index fc18be0..e539653 100644
25016--- a/arch/x86/mm/init_64.c
25017+++ b/arch/x86/mm/init_64.c
25018@@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
25019 * around without checking the pgd every time.
25020 */
25021
25022-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
25023+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
25024 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25025
25026 int force_personality32;
25027@@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25028
25029 for (address = start; address <= end; address += PGDIR_SIZE) {
25030 const pgd_t *pgd_ref = pgd_offset_k(address);
25031+
25032+#ifdef CONFIG_PAX_PER_CPU_PGD
25033+ unsigned long cpu;
25034+#else
25035 struct page *page;
25036+#endif
25037
25038 if (pgd_none(*pgd_ref))
25039 continue;
25040
25041 spin_lock(&pgd_lock);
25042+
25043+#ifdef CONFIG_PAX_PER_CPU_PGD
25044+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25045+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
25046+#else
25047 list_for_each_entry(page, &pgd_list, lru) {
25048 pgd_t *pgd;
25049 spinlock_t *pgt_lock;
25050@@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25051 /* the pgt_lock only for Xen */
25052 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25053 spin_lock(pgt_lock);
25054+#endif
25055
25056 if (pgd_none(*pgd))
25057 set_pgd(pgd, *pgd_ref);
25058@@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25059 BUG_ON(pgd_page_vaddr(*pgd)
25060 != pgd_page_vaddr(*pgd_ref));
25061
25062+#ifndef CONFIG_PAX_PER_CPU_PGD
25063 spin_unlock(pgt_lock);
25064+#endif
25065+
25066 }
25067 spin_unlock(&pgd_lock);
25068 }
25069@@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
25070 {
25071 if (pgd_none(*pgd)) {
25072 pud_t *pud = (pud_t *)spp_getpage();
25073- pgd_populate(&init_mm, pgd, pud);
25074+ pgd_populate_kernel(&init_mm, pgd, pud);
25075 if (pud != pud_offset(pgd, 0))
25076 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
25077 pud, pud_offset(pgd, 0));
25078@@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
25079 {
25080 if (pud_none(*pud)) {
25081 pmd_t *pmd = (pmd_t *) spp_getpage();
25082- pud_populate(&init_mm, pud, pmd);
25083+ pud_populate_kernel(&init_mm, pud, pmd);
25084 if (pmd != pmd_offset(pud, 0))
25085 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
25086 pmd, pmd_offset(pud, 0));
25087@@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25088 pmd = fill_pmd(pud, vaddr);
25089 pte = fill_pte(pmd, vaddr);
25090
25091+ pax_open_kernel();
25092 set_pte(pte, new_pte);
25093+ pax_close_kernel();
25094
25095 /*
25096 * It's enough to flush this one mapping.
25097@@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25098 pgd = pgd_offset_k((unsigned long)__va(phys));
25099 if (pgd_none(*pgd)) {
25100 pud = (pud_t *) spp_getpage();
25101- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25102- _PAGE_USER));
25103+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25104 }
25105 pud = pud_offset(pgd, (unsigned long)__va(phys));
25106 if (pud_none(*pud)) {
25107 pmd = (pmd_t *) spp_getpage();
25108- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25109- _PAGE_USER));
25110+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25111 }
25112 pmd = pmd_offset(pud, phys);
25113 BUG_ON(!pmd_none(*pmd));
25114@@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
25115 if (pfn >= pgt_buf_top)
25116 panic("alloc_low_page: ran out of memory");
25117
25118- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25119+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25120 clear_page(adr);
25121 *phys = pfn * PAGE_SIZE;
25122 return adr;
25123@@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
25124
25125 phys = __pa(virt);
25126 left = phys & (PAGE_SIZE - 1);
25127- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25128+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25129 adr = (void *)(((unsigned long)adr) | left);
25130
25131 return adr;
25132@@ -545,7 +559,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25133 unmap_low_page(pmd);
25134
25135 spin_lock(&init_mm.page_table_lock);
25136- pud_populate(&init_mm, pud, __va(pmd_phys));
25137+ pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25138 spin_unlock(&init_mm.page_table_lock);
25139 }
25140 __flush_tlb_all();
25141@@ -591,7 +605,7 @@ kernel_physical_mapping_init(unsigned long start,
25142 unmap_low_page(pud);
25143
25144 spin_lock(&init_mm.page_table_lock);
25145- pgd_populate(&init_mm, pgd, __va(pud_phys));
25146+ pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25147 spin_unlock(&init_mm.page_table_lock);
25148 pgd_changed = true;
25149 }
25150@@ -683,6 +697,12 @@ void __init mem_init(void)
25151
25152 pci_iommu_alloc();
25153
25154+#ifdef CONFIG_PAX_PER_CPU_PGD
25155+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25156+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25157+ KERNEL_PGD_PTRS);
25158+#endif
25159+
25160 /* clear_bss() already clear the empty_zero_page */
25161
25162 reservedpages = 0;
25163@@ -843,8 +863,8 @@ int kern_addr_valid(unsigned long addr)
25164 static struct vm_area_struct gate_vma = {
25165 .vm_start = VSYSCALL_START,
25166 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25167- .vm_page_prot = PAGE_READONLY_EXEC,
25168- .vm_flags = VM_READ | VM_EXEC
25169+ .vm_page_prot = PAGE_READONLY,
25170+ .vm_flags = VM_READ
25171 };
25172
25173 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25174@@ -878,7 +898,7 @@ int in_gate_area_no_mm(unsigned long addr)
25175
25176 const char *arch_vma_name(struct vm_area_struct *vma)
25177 {
25178- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25179+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25180 return "[vdso]";
25181 if (vma == &gate_vma)
25182 return "[vsyscall]";
25183diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25184index 7b179b4..6bd1777 100644
25185--- a/arch/x86/mm/iomap_32.c
25186+++ b/arch/x86/mm/iomap_32.c
25187@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25188 type = kmap_atomic_idx_push();
25189 idx = type + KM_TYPE_NR * smp_processor_id();
25190 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25191+
25192+ pax_open_kernel();
25193 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25194+ pax_close_kernel();
25195+
25196 arch_flush_lazy_mmu_mode();
25197
25198 return (void *)vaddr;
25199diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25200index be1ef57..55f0160 100644
25201--- a/arch/x86/mm/ioremap.c
25202+++ b/arch/x86/mm/ioremap.c
25203@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25204 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25205 int is_ram = page_is_ram(pfn);
25206
25207- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25208+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25209 return NULL;
25210 WARN_ON_ONCE(is_ram);
25211 }
25212@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25213
25214 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25215 if (page_is_ram(start >> PAGE_SHIFT))
25216+#ifdef CONFIG_HIGHMEM
25217+ if ((start >> PAGE_SHIFT) < max_low_pfn)
25218+#endif
25219 return __va(phys);
25220
25221 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25222@@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25223 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25224
25225 static __initdata int after_paging_init;
25226-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25227+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25228
25229 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25230 {
25231@@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25232 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25233
25234 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25235- memset(bm_pte, 0, sizeof(bm_pte));
25236- pmd_populate_kernel(&init_mm, pmd, bm_pte);
25237+ pmd_populate_user(&init_mm, pmd, bm_pte);
25238
25239 /*
25240 * The boot-ioremap range spans multiple pmds, for which
25241diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25242index d87dd6d..bf3fa66 100644
25243--- a/arch/x86/mm/kmemcheck/kmemcheck.c
25244+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25245@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25246 * memory (e.g. tracked pages)? For now, we need this to avoid
25247 * invoking kmemcheck for PnP BIOS calls.
25248 */
25249- if (regs->flags & X86_VM_MASK)
25250+ if (v8086_mode(regs))
25251 return false;
25252- if (regs->cs != __KERNEL_CS)
25253+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25254 return false;
25255
25256 pte = kmemcheck_pte_lookup(address);
25257diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25258index 845df68..1d8d29f 100644
25259--- a/arch/x86/mm/mmap.c
25260+++ b/arch/x86/mm/mmap.c
25261@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25262 * Leave an at least ~128 MB hole with possible stack randomization.
25263 */
25264 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25265-#define MAX_GAP (TASK_SIZE/6*5)
25266+#define MAX_GAP (pax_task_size/6*5)
25267
25268 static int mmap_is_legacy(void)
25269 {
25270@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25271 return rnd << PAGE_SHIFT;
25272 }
25273
25274-static unsigned long mmap_base(void)
25275+static unsigned long mmap_base(struct mm_struct *mm)
25276 {
25277 unsigned long gap = rlimit(RLIMIT_STACK);
25278+ unsigned long pax_task_size = TASK_SIZE;
25279+
25280+#ifdef CONFIG_PAX_SEGMEXEC
25281+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25282+ pax_task_size = SEGMEXEC_TASK_SIZE;
25283+#endif
25284
25285 if (gap < MIN_GAP)
25286 gap = MIN_GAP;
25287 else if (gap > MAX_GAP)
25288 gap = MAX_GAP;
25289
25290- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25291+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25292 }
25293
25294 /*
25295 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25296 * does, but not when emulating X86_32
25297 */
25298-static unsigned long mmap_legacy_base(void)
25299+static unsigned long mmap_legacy_base(struct mm_struct *mm)
25300 {
25301- if (mmap_is_ia32())
25302+ if (mmap_is_ia32()) {
25303+
25304+#ifdef CONFIG_PAX_SEGMEXEC
25305+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25306+ return SEGMEXEC_TASK_UNMAPPED_BASE;
25307+ else
25308+#endif
25309+
25310 return TASK_UNMAPPED_BASE;
25311- else
25312+ } else
25313 return TASK_UNMAPPED_BASE + mmap_rnd();
25314 }
25315
25316@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25317 void arch_pick_mmap_layout(struct mm_struct *mm)
25318 {
25319 if (mmap_is_legacy()) {
25320- mm->mmap_base = mmap_legacy_base();
25321+ mm->mmap_base = mmap_legacy_base(mm);
25322+
25323+#ifdef CONFIG_PAX_RANDMMAP
25324+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25325+ mm->mmap_base += mm->delta_mmap;
25326+#endif
25327+
25328 mm->get_unmapped_area = arch_get_unmapped_area;
25329 mm->unmap_area = arch_unmap_area;
25330 } else {
25331- mm->mmap_base = mmap_base();
25332+ mm->mmap_base = mmap_base(mm);
25333+
25334+#ifdef CONFIG_PAX_RANDMMAP
25335+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25336+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25337+#endif
25338+
25339 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25340 mm->unmap_area = arch_unmap_area_topdown;
25341 }
25342diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25343index dc0b727..dc9d71a 100644
25344--- a/arch/x86/mm/mmio-mod.c
25345+++ b/arch/x86/mm/mmio-mod.c
25346@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25347 break;
25348 default:
25349 {
25350- unsigned char *ip = (unsigned char *)instptr;
25351+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25352 my_trace->opcode = MMIO_UNKNOWN_OP;
25353 my_trace->width = 0;
25354 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25355@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25356 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25357 void __iomem *addr)
25358 {
25359- static atomic_t next_id;
25360+ static atomic_unchecked_t next_id;
25361 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25362 /* These are page-unaligned. */
25363 struct mmiotrace_map map = {
25364@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25365 .private = trace
25366 },
25367 .phys = offset,
25368- .id = atomic_inc_return(&next_id)
25369+ .id = atomic_inc_return_unchecked(&next_id)
25370 };
25371 map.map_id = trace->id;
25372
25373diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25374index b008656..773eac2 100644
25375--- a/arch/x86/mm/pageattr-test.c
25376+++ b/arch/x86/mm/pageattr-test.c
25377@@ -36,7 +36,7 @@ enum {
25378
25379 static int pte_testbit(pte_t pte)
25380 {
25381- return pte_flags(pte) & _PAGE_UNUSED1;
25382+ return pte_flags(pte) & _PAGE_CPA_TEST;
25383 }
25384
25385 struct split_state {
25386diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25387index e1ebde3..b1e1db38 100644
25388--- a/arch/x86/mm/pageattr.c
25389+++ b/arch/x86/mm/pageattr.c
25390@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25391 */
25392 #ifdef CONFIG_PCI_BIOS
25393 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25394- pgprot_val(forbidden) |= _PAGE_NX;
25395+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25396 #endif
25397
25398 /*
25399@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25400 * Does not cover __inittext since that is gone later on. On
25401 * 64bit we do not enforce !NX on the low mapping
25402 */
25403- if (within(address, (unsigned long)_text, (unsigned long)_etext))
25404- pgprot_val(forbidden) |= _PAGE_NX;
25405+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25406+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25407
25408+#ifdef CONFIG_DEBUG_RODATA
25409 /*
25410 * The .rodata section needs to be read-only. Using the pfn
25411 * catches all aliases.
25412@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25413 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25414 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25415 pgprot_val(forbidden) |= _PAGE_RW;
25416+#endif
25417
25418 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25419 /*
25420@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25421 }
25422 #endif
25423
25424+#ifdef CONFIG_PAX_KERNEXEC
25425+ if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25426+ pgprot_val(forbidden) |= _PAGE_RW;
25427+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25428+ }
25429+#endif
25430+
25431 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25432
25433 return prot;
25434@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25435 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25436 {
25437 /* change init_mm */
25438+ pax_open_kernel();
25439 set_pte_atomic(kpte, pte);
25440+
25441 #ifdef CONFIG_X86_32
25442 if (!SHARED_KERNEL_PMD) {
25443+
25444+#ifdef CONFIG_PAX_PER_CPU_PGD
25445+ unsigned long cpu;
25446+#else
25447 struct page *page;
25448+#endif
25449
25450+#ifdef CONFIG_PAX_PER_CPU_PGD
25451+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25452+ pgd_t *pgd = get_cpu_pgd(cpu);
25453+#else
25454 list_for_each_entry(page, &pgd_list, lru) {
25455- pgd_t *pgd;
25456+ pgd_t *pgd = (pgd_t *)page_address(page);
25457+#endif
25458+
25459 pud_t *pud;
25460 pmd_t *pmd;
25461
25462- pgd = (pgd_t *)page_address(page) + pgd_index(address);
25463+ pgd += pgd_index(address);
25464 pud = pud_offset(pgd, address);
25465 pmd = pmd_offset(pud, address);
25466 set_pte_atomic((pte_t *)pmd, pte);
25467 }
25468 }
25469 #endif
25470+ pax_close_kernel();
25471 }
25472
25473 static int
25474diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25475index f6ff57b..481690f 100644
25476--- a/arch/x86/mm/pat.c
25477+++ b/arch/x86/mm/pat.c
25478@@ -361,7 +361,7 @@ int free_memtype(u64 start, u64 end)
25479
25480 if (!entry) {
25481 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
25482- current->comm, current->pid, start, end);
25483+ current->comm, task_pid_nr(current), start, end);
25484 return -EINVAL;
25485 }
25486
25487@@ -492,8 +492,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25488 while (cursor < to) {
25489 if (!devmem_is_allowed(pfn)) {
25490 printk(KERN_INFO
25491- "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
25492- current->comm, from, to);
25493+ "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
25494+ current->comm, from, to, cursor);
25495 return 0;
25496 }
25497 cursor += PAGE_SIZE;
25498@@ -557,7 +557,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25499 printk(KERN_INFO
25500 "%s:%d ioremap_change_attr failed %s "
25501 "for %Lx-%Lx\n",
25502- current->comm, current->pid,
25503+ current->comm, task_pid_nr(current),
25504 cattr_name(flags),
25505 base, (unsigned long long)(base + size));
25506 return -EINVAL;
25507@@ -593,7 +593,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25508 if (want_flags != flags) {
25509 printk(KERN_WARNING
25510 "%s:%d map pfn RAM range req %s for %Lx-%Lx, got %s\n",
25511- current->comm, current->pid,
25512+ current->comm, task_pid_nr(current),
25513 cattr_name(want_flags),
25514 (unsigned long long)paddr,
25515 (unsigned long long)(paddr + size),
25516@@ -615,7 +615,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25517 free_memtype(paddr, paddr + size);
25518 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25519 " for %Lx-%Lx, got %s\n",
25520- current->comm, current->pid,
25521+ current->comm, task_pid_nr(current),
25522 cattr_name(want_flags),
25523 (unsigned long long)paddr,
25524 (unsigned long long)(paddr + size),
25525diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25526index 9f0614d..92ae64a 100644
25527--- a/arch/x86/mm/pf_in.c
25528+++ b/arch/x86/mm/pf_in.c
25529@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25530 int i;
25531 enum reason_type rv = OTHERS;
25532
25533- p = (unsigned char *)ins_addr;
25534+ p = (unsigned char *)ktla_ktva(ins_addr);
25535 p += skip_prefix(p, &prf);
25536 p += get_opcode(p, &opcode);
25537
25538@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25539 struct prefix_bits prf;
25540 int i;
25541
25542- p = (unsigned char *)ins_addr;
25543+ p = (unsigned char *)ktla_ktva(ins_addr);
25544 p += skip_prefix(p, &prf);
25545 p += get_opcode(p, &opcode);
25546
25547@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25548 struct prefix_bits prf;
25549 int i;
25550
25551- p = (unsigned char *)ins_addr;
25552+ p = (unsigned char *)ktla_ktva(ins_addr);
25553 p += skip_prefix(p, &prf);
25554 p += get_opcode(p, &opcode);
25555
25556@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25557 struct prefix_bits prf;
25558 int i;
25559
25560- p = (unsigned char *)ins_addr;
25561+ p = (unsigned char *)ktla_ktva(ins_addr);
25562 p += skip_prefix(p, &prf);
25563 p += get_opcode(p, &opcode);
25564 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25565@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25566 struct prefix_bits prf;
25567 int i;
25568
25569- p = (unsigned char *)ins_addr;
25570+ p = (unsigned char *)ktla_ktva(ins_addr);
25571 p += skip_prefix(p, &prf);
25572 p += get_opcode(p, &opcode);
25573 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25574diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25575index 8573b83..4f3ed7e 100644
25576--- a/arch/x86/mm/pgtable.c
25577+++ b/arch/x86/mm/pgtable.c
25578@@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25579 list_del(&page->lru);
25580 }
25581
25582-#define UNSHARED_PTRS_PER_PGD \
25583- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25584+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25585+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25586
25587+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25588+{
25589+ unsigned int count = USER_PGD_PTRS;
25590
25591+ while (count--)
25592+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25593+}
25594+#endif
25595+
25596+#ifdef CONFIG_PAX_PER_CPU_PGD
25597+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25598+{
25599+ unsigned int count = USER_PGD_PTRS;
25600+
25601+ while (count--) {
25602+ pgd_t pgd;
25603+
25604+#ifdef CONFIG_X86_64
25605+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25606+#else
25607+ pgd = *src++;
25608+#endif
25609+
25610+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25611+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25612+#endif
25613+
25614+ *dst++ = pgd;
25615+ }
25616+
25617+}
25618+#endif
25619+
25620+#ifdef CONFIG_X86_64
25621+#define pxd_t pud_t
25622+#define pyd_t pgd_t
25623+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25624+#define pxd_free(mm, pud) pud_free((mm), (pud))
25625+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25626+#define pyd_offset(mm, address) pgd_offset((mm), (address))
25627+#define PYD_SIZE PGDIR_SIZE
25628+#else
25629+#define pxd_t pmd_t
25630+#define pyd_t pud_t
25631+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25632+#define pxd_free(mm, pud) pmd_free((mm), (pud))
25633+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25634+#define pyd_offset(mm, address) pud_offset((mm), (address))
25635+#define PYD_SIZE PUD_SIZE
25636+#endif
25637+
25638+#ifdef CONFIG_PAX_PER_CPU_PGD
25639+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25640+static inline void pgd_dtor(pgd_t *pgd) {}
25641+#else
25642 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25643 {
25644 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25645@@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25646 pgd_list_del(pgd);
25647 spin_unlock(&pgd_lock);
25648 }
25649+#endif
25650
25651 /*
25652 * List of all pgd's needed for non-PAE so it can invalidate entries
25653@@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25654 * -- wli
25655 */
25656
25657-#ifdef CONFIG_X86_PAE
25658+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25659 /*
25660 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25661 * updating the top-level pagetable entries to guarantee the
25662@@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25663 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25664 * and initialize the kernel pmds here.
25665 */
25666-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25667+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25668
25669 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25670 {
25671@@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25672 */
25673 flush_tlb_mm(mm);
25674 }
25675+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25676+#define PREALLOCATED_PXDS USER_PGD_PTRS
25677 #else /* !CONFIG_X86_PAE */
25678
25679 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25680-#define PREALLOCATED_PMDS 0
25681+#define PREALLOCATED_PXDS 0
25682
25683 #endif /* CONFIG_X86_PAE */
25684
25685-static void free_pmds(pmd_t *pmds[])
25686+static void free_pxds(pxd_t *pxds[])
25687 {
25688 int i;
25689
25690- for(i = 0; i < PREALLOCATED_PMDS; i++)
25691- if (pmds[i])
25692- free_page((unsigned long)pmds[i]);
25693+ for(i = 0; i < PREALLOCATED_PXDS; i++)
25694+ if (pxds[i])
25695+ free_page((unsigned long)pxds[i]);
25696 }
25697
25698-static int preallocate_pmds(pmd_t *pmds[])
25699+static int preallocate_pxds(pxd_t *pxds[])
25700 {
25701 int i;
25702 bool failed = false;
25703
25704- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25705- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25706- if (pmd == NULL)
25707+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25708+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25709+ if (pxd == NULL)
25710 failed = true;
25711- pmds[i] = pmd;
25712+ pxds[i] = pxd;
25713 }
25714
25715 if (failed) {
25716- free_pmds(pmds);
25717+ free_pxds(pxds);
25718 return -ENOMEM;
25719 }
25720
25721@@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25722 * preallocate which never got a corresponding vma will need to be
25723 * freed manually.
25724 */
25725-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25726+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25727 {
25728 int i;
25729
25730- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25731+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25732 pgd_t pgd = pgdp[i];
25733
25734 if (pgd_val(pgd) != 0) {
25735- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25736+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25737
25738- pgdp[i] = native_make_pgd(0);
25739+ set_pgd(pgdp + i, native_make_pgd(0));
25740
25741- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25742- pmd_free(mm, pmd);
25743+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25744+ pxd_free(mm, pxd);
25745 }
25746 }
25747 }
25748
25749-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25750+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25751 {
25752- pud_t *pud;
25753+ pyd_t *pyd;
25754 unsigned long addr;
25755 int i;
25756
25757- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25758+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25759 return;
25760
25761- pud = pud_offset(pgd, 0);
25762+#ifdef CONFIG_X86_64
25763+ pyd = pyd_offset(mm, 0L);
25764+#else
25765+ pyd = pyd_offset(pgd, 0L);
25766+#endif
25767
25768- for (addr = i = 0; i < PREALLOCATED_PMDS;
25769- i++, pud++, addr += PUD_SIZE) {
25770- pmd_t *pmd = pmds[i];
25771+ for (addr = i = 0; i < PREALLOCATED_PXDS;
25772+ i++, pyd++, addr += PYD_SIZE) {
25773+ pxd_t *pxd = pxds[i];
25774
25775 if (i >= KERNEL_PGD_BOUNDARY)
25776- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25777- sizeof(pmd_t) * PTRS_PER_PMD);
25778+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25779+ sizeof(pxd_t) * PTRS_PER_PMD);
25780
25781- pud_populate(mm, pud, pmd);
25782+ pyd_populate(mm, pyd, pxd);
25783 }
25784 }
25785
25786 pgd_t *pgd_alloc(struct mm_struct *mm)
25787 {
25788 pgd_t *pgd;
25789- pmd_t *pmds[PREALLOCATED_PMDS];
25790+ pxd_t *pxds[PREALLOCATED_PXDS];
25791
25792 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25793
25794@@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25795
25796 mm->pgd = pgd;
25797
25798- if (preallocate_pmds(pmds) != 0)
25799+ if (preallocate_pxds(pxds) != 0)
25800 goto out_free_pgd;
25801
25802 if (paravirt_pgd_alloc(mm) != 0)
25803- goto out_free_pmds;
25804+ goto out_free_pxds;
25805
25806 /*
25807 * Make sure that pre-populating the pmds is atomic with
25808@@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25809 spin_lock(&pgd_lock);
25810
25811 pgd_ctor(mm, pgd);
25812- pgd_prepopulate_pmd(mm, pgd, pmds);
25813+ pgd_prepopulate_pxd(mm, pgd, pxds);
25814
25815 spin_unlock(&pgd_lock);
25816
25817 return pgd;
25818
25819-out_free_pmds:
25820- free_pmds(pmds);
25821+out_free_pxds:
25822+ free_pxds(pxds);
25823 out_free_pgd:
25824 free_page((unsigned long)pgd);
25825 out:
25826@@ -295,7 +356,7 @@ out:
25827
25828 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25829 {
25830- pgd_mop_up_pmds(mm, pgd);
25831+ pgd_mop_up_pxds(mm, pgd);
25832 pgd_dtor(pgd);
25833 paravirt_pgd_free(mm, pgd);
25834 free_page((unsigned long)pgd);
25835diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25836index a69bcb8..19068ab 100644
25837--- a/arch/x86/mm/pgtable_32.c
25838+++ b/arch/x86/mm/pgtable_32.c
25839@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25840 return;
25841 }
25842 pte = pte_offset_kernel(pmd, vaddr);
25843+
25844+ pax_open_kernel();
25845 if (pte_val(pteval))
25846 set_pte_at(&init_mm, vaddr, pte, pteval);
25847 else
25848 pte_clear(&init_mm, vaddr, pte);
25849+ pax_close_kernel();
25850
25851 /*
25852 * It's enough to flush this one mapping.
25853diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25854index 410531d..0f16030 100644
25855--- a/arch/x86/mm/setup_nx.c
25856+++ b/arch/x86/mm/setup_nx.c
25857@@ -5,8 +5,10 @@
25858 #include <asm/pgtable.h>
25859 #include <asm/proto.h>
25860
25861+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25862 static int disable_nx __cpuinitdata;
25863
25864+#ifndef CONFIG_PAX_PAGEEXEC
25865 /*
25866 * noexec = on|off
25867 *
25868@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25869 return 0;
25870 }
25871 early_param("noexec", noexec_setup);
25872+#endif
25873+
25874+#endif
25875
25876 void __cpuinit x86_configure_nx(void)
25877 {
25878+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25879 if (cpu_has_nx && !disable_nx)
25880 __supported_pte_mask |= _PAGE_NX;
25881 else
25882+#endif
25883 __supported_pte_mask &= ~_PAGE_NX;
25884 }
25885
25886diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25887index d6c0418..06a0ad5 100644
25888--- a/arch/x86/mm/tlb.c
25889+++ b/arch/x86/mm/tlb.c
25890@@ -65,7 +65,11 @@ void leave_mm(int cpu)
25891 BUG();
25892 cpumask_clear_cpu(cpu,
25893 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
25894+
25895+#ifndef CONFIG_PAX_PER_CPU_PGD
25896 load_cr3(swapper_pg_dir);
25897+#endif
25898+
25899 }
25900 EXPORT_SYMBOL_GPL(leave_mm);
25901
25902diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25903index 877b9a1..a8ecf42 100644
25904--- a/arch/x86/net/bpf_jit.S
25905+++ b/arch/x86/net/bpf_jit.S
25906@@ -9,6 +9,7 @@
25907 */
25908 #include <linux/linkage.h>
25909 #include <asm/dwarf2.h>
25910+#include <asm/alternative-asm.h>
25911
25912 /*
25913 * Calling convention :
25914@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
25915 jle bpf_slow_path_word
25916 mov (SKBDATA,%rsi),%eax
25917 bswap %eax /* ntohl() */
25918+ pax_force_retaddr
25919 ret
25920
25921 sk_load_half:
25922@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
25923 jle bpf_slow_path_half
25924 movzwl (SKBDATA,%rsi),%eax
25925 rol $8,%ax # ntohs()
25926+ pax_force_retaddr
25927 ret
25928
25929 sk_load_byte:
25930@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
25931 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25932 jle bpf_slow_path_byte
25933 movzbl (SKBDATA,%rsi),%eax
25934+ pax_force_retaddr
25935 ret
25936
25937 /**
25938@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
25939 movzbl (SKBDATA,%rsi),%ebx
25940 and $15,%bl
25941 shl $2,%bl
25942+ pax_force_retaddr
25943 ret
25944
25945 /* rsi contains offset and can be scratched */
25946@@ -109,6 +114,7 @@ bpf_slow_path_word:
25947 js bpf_error
25948 mov -12(%rbp),%eax
25949 bswap %eax
25950+ pax_force_retaddr
25951 ret
25952
25953 bpf_slow_path_half:
25954@@ -117,12 +123,14 @@ bpf_slow_path_half:
25955 mov -12(%rbp),%ax
25956 rol $8,%ax
25957 movzwl %ax,%eax
25958+ pax_force_retaddr
25959 ret
25960
25961 bpf_slow_path_byte:
25962 bpf_slow_path_common(1)
25963 js bpf_error
25964 movzbl -12(%rbp),%eax
25965+ pax_force_retaddr
25966 ret
25967
25968 bpf_slow_path_byte_msh:
25969@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
25970 and $15,%al
25971 shl $2,%al
25972 xchg %eax,%ebx
25973+ pax_force_retaddr
25974 ret
25975
25976 #define sk_negative_common(SIZE) \
25977@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
25978 sk_negative_common(4)
25979 mov (%rax), %eax
25980 bswap %eax
25981+ pax_force_retaddr
25982 ret
25983
25984 bpf_slow_path_half_neg:
25985@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
25986 mov (%rax),%ax
25987 rol $8,%ax
25988 movzwl %ax,%eax
25989+ pax_force_retaddr
25990 ret
25991
25992 bpf_slow_path_byte_neg:
25993@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
25994 .globl sk_load_byte_negative_offset
25995 sk_negative_common(1)
25996 movzbl (%rax), %eax
25997+ pax_force_retaddr
25998 ret
25999
26000 bpf_slow_path_byte_msh_neg:
26001@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
26002 and $15,%al
26003 shl $2,%al
26004 xchg %eax,%ebx
26005+ pax_force_retaddr
26006 ret
26007
26008 bpf_error:
26009@@ -197,4 +210,5 @@ bpf_error:
26010 xor %eax,%eax
26011 mov -8(%rbp),%rbx
26012 leaveq
26013+ pax_force_retaddr
26014 ret
26015diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
26016index 0597f95..a12c36e 100644
26017--- a/arch/x86/net/bpf_jit_comp.c
26018+++ b/arch/x86/net/bpf_jit_comp.c
26019@@ -120,6 +120,11 @@ static inline void bpf_flush_icache(void *start, void *end)
26020 set_fs(old_fs);
26021 }
26022
26023+struct bpf_jit_work {
26024+ struct work_struct work;
26025+ void *image;
26026+};
26027+
26028 #define CHOOSE_LOAD_FUNC(K, func) \
26029 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
26030
26031@@ -146,6 +151,10 @@ void bpf_jit_compile(struct sk_filter *fp)
26032 if (addrs == NULL)
26033 return;
26034
26035+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
26036+ if (!fp->work)
26037+ goto out;
26038+
26039 /* Before first pass, make a rough estimation of addrs[]
26040 * each bpf instruction is translated to less than 64 bytes
26041 */
26042@@ -589,17 +598,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26043 break;
26044 default:
26045 /* hmm, too complex filter, give up with jit compiler */
26046- goto out;
26047+ goto error;
26048 }
26049 ilen = prog - temp;
26050 if (image) {
26051 if (unlikely(proglen + ilen > oldproglen)) {
26052 pr_err("bpb_jit_compile fatal error\n");
26053- kfree(addrs);
26054- module_free(NULL, image);
26055- return;
26056+ module_free_exec(NULL, image);
26057+ goto error;
26058 }
26059+ pax_open_kernel();
26060 memcpy(image + proglen, temp, ilen);
26061+ pax_close_kernel();
26062 }
26063 proglen += ilen;
26064 addrs[i] = proglen;
26065@@ -620,11 +630,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26066 break;
26067 }
26068 if (proglen == oldproglen) {
26069- image = module_alloc(max_t(unsigned int,
26070- proglen,
26071- sizeof(struct work_struct)));
26072+ image = module_alloc_exec(proglen);
26073 if (!image)
26074- goto out;
26075+ goto error;
26076 }
26077 oldproglen = proglen;
26078 }
26079@@ -640,7 +648,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26080 bpf_flush_icache(image, image + proglen);
26081
26082 fp->bpf_func = (void *)image;
26083- }
26084+ } else
26085+error:
26086+ kfree(fp->work);
26087+
26088 out:
26089 kfree(addrs);
26090 return;
26091@@ -648,18 +659,20 @@ out:
26092
26093 static void jit_free_defer(struct work_struct *arg)
26094 {
26095- module_free(NULL, arg);
26096+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
26097+ kfree(arg);
26098 }
26099
26100 /* run from softirq, we must use a work_struct to call
26101- * module_free() from process context
26102+ * module_free_exec() from process context
26103 */
26104 void bpf_jit_free(struct sk_filter *fp)
26105 {
26106 if (fp->bpf_func != sk_run_filter) {
26107- struct work_struct *work = (struct work_struct *)fp->bpf_func;
26108+ struct work_struct *work = &fp->work->work;
26109
26110 INIT_WORK(work, jit_free_defer);
26111+ fp->work->image = fp->bpf_func;
26112 schedule_work(work);
26113 }
26114 }
26115diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26116index d6aa6e8..266395a 100644
26117--- a/arch/x86/oprofile/backtrace.c
26118+++ b/arch/x86/oprofile/backtrace.c
26119@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
26120 struct stack_frame_ia32 *fp;
26121 unsigned long bytes;
26122
26123- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26124+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26125 if (bytes != sizeof(bufhead))
26126 return NULL;
26127
26128- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26129+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26130
26131 oprofile_add_trace(bufhead[0].return_address);
26132
26133@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26134 struct stack_frame bufhead[2];
26135 unsigned long bytes;
26136
26137- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26138+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26139 if (bytes != sizeof(bufhead))
26140 return NULL;
26141
26142@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26143 {
26144 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26145
26146- if (!user_mode_vm(regs)) {
26147+ if (!user_mode(regs)) {
26148 unsigned long stack = kernel_stack_pointer(regs);
26149 if (depth)
26150 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26151diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26152index 140942f..8a5cc55 100644
26153--- a/arch/x86/pci/mrst.c
26154+++ b/arch/x86/pci/mrst.c
26155@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
26156 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
26157 pci_mmcfg_late_init();
26158 pcibios_enable_irq = mrst_pci_irq_enable;
26159- pci_root_ops = pci_mrst_ops;
26160+ pax_open_kernel();
26161+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26162+ pax_close_kernel();
26163 pci_soc_mode = 1;
26164 /* Continue with standard init */
26165 return 1;
26166diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26167index da8fe05..7ee6704 100644
26168--- a/arch/x86/pci/pcbios.c
26169+++ b/arch/x86/pci/pcbios.c
26170@@ -79,50 +79,93 @@ union bios32 {
26171 static struct {
26172 unsigned long address;
26173 unsigned short segment;
26174-} bios32_indirect = { 0, __KERNEL_CS };
26175+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26176
26177 /*
26178 * Returns the entry point for the given service, NULL on error
26179 */
26180
26181-static unsigned long bios32_service(unsigned long service)
26182+static unsigned long __devinit bios32_service(unsigned long service)
26183 {
26184 unsigned char return_code; /* %al */
26185 unsigned long address; /* %ebx */
26186 unsigned long length; /* %ecx */
26187 unsigned long entry; /* %edx */
26188 unsigned long flags;
26189+ struct desc_struct d, *gdt;
26190
26191 local_irq_save(flags);
26192- __asm__("lcall *(%%edi); cld"
26193+
26194+ gdt = get_cpu_gdt_table(smp_processor_id());
26195+
26196+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26197+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26198+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26199+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26200+
26201+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26202 : "=a" (return_code),
26203 "=b" (address),
26204 "=c" (length),
26205 "=d" (entry)
26206 : "0" (service),
26207 "1" (0),
26208- "D" (&bios32_indirect));
26209+ "D" (&bios32_indirect),
26210+ "r"(__PCIBIOS_DS)
26211+ : "memory");
26212+
26213+ pax_open_kernel();
26214+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26215+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26216+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26217+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26218+ pax_close_kernel();
26219+
26220 local_irq_restore(flags);
26221
26222 switch (return_code) {
26223- case 0:
26224- return address + entry;
26225- case 0x80: /* Not present */
26226- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26227- return 0;
26228- default: /* Shouldn't happen */
26229- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26230- service, return_code);
26231+ case 0: {
26232+ int cpu;
26233+ unsigned char flags;
26234+
26235+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26236+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26237+ printk(KERN_WARNING "bios32_service: not valid\n");
26238 return 0;
26239+ }
26240+ address = address + PAGE_OFFSET;
26241+ length += 16UL; /* some BIOSs underreport this... */
26242+ flags = 4;
26243+ if (length >= 64*1024*1024) {
26244+ length >>= PAGE_SHIFT;
26245+ flags |= 8;
26246+ }
26247+
26248+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26249+ gdt = get_cpu_gdt_table(cpu);
26250+ pack_descriptor(&d, address, length, 0x9b, flags);
26251+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26252+ pack_descriptor(&d, address, length, 0x93, flags);
26253+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26254+ }
26255+ return entry;
26256+ }
26257+ case 0x80: /* Not present */
26258+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26259+ return 0;
26260+ default: /* Shouldn't happen */
26261+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26262+ service, return_code);
26263+ return 0;
26264 }
26265 }
26266
26267 static struct {
26268 unsigned long address;
26269 unsigned short segment;
26270-} pci_indirect = { 0, __KERNEL_CS };
26271+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26272
26273-static int pci_bios_present;
26274+static int pci_bios_present __read_only;
26275
26276 static int __devinit check_pcibios(void)
26277 {
26278@@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26279 unsigned long flags, pcibios_entry;
26280
26281 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26282- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26283+ pci_indirect.address = pcibios_entry;
26284
26285 local_irq_save(flags);
26286- __asm__(
26287- "lcall *(%%edi); cld\n\t"
26288+ __asm__("movw %w6, %%ds\n\t"
26289+ "lcall *%%ss:(%%edi); cld\n\t"
26290+ "push %%ss\n\t"
26291+ "pop %%ds\n\t"
26292 "jc 1f\n\t"
26293 "xor %%ah, %%ah\n"
26294 "1:"
26295@@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26296 "=b" (ebx),
26297 "=c" (ecx)
26298 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26299- "D" (&pci_indirect)
26300+ "D" (&pci_indirect),
26301+ "r" (__PCIBIOS_DS)
26302 : "memory");
26303 local_irq_restore(flags);
26304
26305@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26306
26307 switch (len) {
26308 case 1:
26309- __asm__("lcall *(%%esi); cld\n\t"
26310+ __asm__("movw %w6, %%ds\n\t"
26311+ "lcall *%%ss:(%%esi); cld\n\t"
26312+ "push %%ss\n\t"
26313+ "pop %%ds\n\t"
26314 "jc 1f\n\t"
26315 "xor %%ah, %%ah\n"
26316 "1:"
26317@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26318 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26319 "b" (bx),
26320 "D" ((long)reg),
26321- "S" (&pci_indirect));
26322+ "S" (&pci_indirect),
26323+ "r" (__PCIBIOS_DS));
26324 /*
26325 * Zero-extend the result beyond 8 bits, do not trust the
26326 * BIOS having done it:
26327@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26328 *value &= 0xff;
26329 break;
26330 case 2:
26331- __asm__("lcall *(%%esi); cld\n\t"
26332+ __asm__("movw %w6, %%ds\n\t"
26333+ "lcall *%%ss:(%%esi); cld\n\t"
26334+ "push %%ss\n\t"
26335+ "pop %%ds\n\t"
26336 "jc 1f\n\t"
26337 "xor %%ah, %%ah\n"
26338 "1:"
26339@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26340 : "1" (PCIBIOS_READ_CONFIG_WORD),
26341 "b" (bx),
26342 "D" ((long)reg),
26343- "S" (&pci_indirect));
26344+ "S" (&pci_indirect),
26345+ "r" (__PCIBIOS_DS));
26346 /*
26347 * Zero-extend the result beyond 16 bits, do not trust the
26348 * BIOS having done it:
26349@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26350 *value &= 0xffff;
26351 break;
26352 case 4:
26353- __asm__("lcall *(%%esi); cld\n\t"
26354+ __asm__("movw %w6, %%ds\n\t"
26355+ "lcall *%%ss:(%%esi); cld\n\t"
26356+ "push %%ss\n\t"
26357+ "pop %%ds\n\t"
26358 "jc 1f\n\t"
26359 "xor %%ah, %%ah\n"
26360 "1:"
26361@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26362 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26363 "b" (bx),
26364 "D" ((long)reg),
26365- "S" (&pci_indirect));
26366+ "S" (&pci_indirect),
26367+ "r" (__PCIBIOS_DS));
26368 break;
26369 }
26370
26371@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26372
26373 switch (len) {
26374 case 1:
26375- __asm__("lcall *(%%esi); cld\n\t"
26376+ __asm__("movw %w6, %%ds\n\t"
26377+ "lcall *%%ss:(%%esi); cld\n\t"
26378+ "push %%ss\n\t"
26379+ "pop %%ds\n\t"
26380 "jc 1f\n\t"
26381 "xor %%ah, %%ah\n"
26382 "1:"
26383@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26384 "c" (value),
26385 "b" (bx),
26386 "D" ((long)reg),
26387- "S" (&pci_indirect));
26388+ "S" (&pci_indirect),
26389+ "r" (__PCIBIOS_DS));
26390 break;
26391 case 2:
26392- __asm__("lcall *(%%esi); cld\n\t"
26393+ __asm__("movw %w6, %%ds\n\t"
26394+ "lcall *%%ss:(%%esi); cld\n\t"
26395+ "push %%ss\n\t"
26396+ "pop %%ds\n\t"
26397 "jc 1f\n\t"
26398 "xor %%ah, %%ah\n"
26399 "1:"
26400@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26401 "c" (value),
26402 "b" (bx),
26403 "D" ((long)reg),
26404- "S" (&pci_indirect));
26405+ "S" (&pci_indirect),
26406+ "r" (__PCIBIOS_DS));
26407 break;
26408 case 4:
26409- __asm__("lcall *(%%esi); cld\n\t"
26410+ __asm__("movw %w6, %%ds\n\t"
26411+ "lcall *%%ss:(%%esi); cld\n\t"
26412+ "push %%ss\n\t"
26413+ "pop %%ds\n\t"
26414 "jc 1f\n\t"
26415 "xor %%ah, %%ah\n"
26416 "1:"
26417@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26418 "c" (value),
26419 "b" (bx),
26420 "D" ((long)reg),
26421- "S" (&pci_indirect));
26422+ "S" (&pci_indirect),
26423+ "r" (__PCIBIOS_DS));
26424 break;
26425 }
26426
26427@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26428
26429 DBG("PCI: Fetching IRQ routing table... ");
26430 __asm__("push %%es\n\t"
26431+ "movw %w8, %%ds\n\t"
26432 "push %%ds\n\t"
26433 "pop %%es\n\t"
26434- "lcall *(%%esi); cld\n\t"
26435+ "lcall *%%ss:(%%esi); cld\n\t"
26436 "pop %%es\n\t"
26437+ "push %%ss\n\t"
26438+ "pop %%ds\n"
26439 "jc 1f\n\t"
26440 "xor %%ah, %%ah\n"
26441 "1:"
26442@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26443 "1" (0),
26444 "D" ((long) &opt),
26445 "S" (&pci_indirect),
26446- "m" (opt)
26447+ "m" (opt),
26448+ "r" (__PCIBIOS_DS)
26449 : "memory");
26450 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26451 if (ret & 0xff00)
26452@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26453 {
26454 int ret;
26455
26456- __asm__("lcall *(%%esi); cld\n\t"
26457+ __asm__("movw %w5, %%ds\n\t"
26458+ "lcall *%%ss:(%%esi); cld\n\t"
26459+ "push %%ss\n\t"
26460+ "pop %%ds\n"
26461 "jc 1f\n\t"
26462 "xor %%ah, %%ah\n"
26463 "1:"
26464@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26465 : "0" (PCIBIOS_SET_PCI_HW_INT),
26466 "b" ((dev->bus->number << 8) | dev->devfn),
26467 "c" ((irq << 8) | (pin + 10)),
26468- "S" (&pci_indirect));
26469+ "S" (&pci_indirect),
26470+ "r" (__PCIBIOS_DS));
26471 return !(ret & 0xff00);
26472 }
26473 EXPORT_SYMBOL(pcibios_set_irq_routing);
26474diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26475index 40e4469..1ab536e 100644
26476--- a/arch/x86/platform/efi/efi_32.c
26477+++ b/arch/x86/platform/efi/efi_32.c
26478@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26479 {
26480 struct desc_ptr gdt_descr;
26481
26482+#ifdef CONFIG_PAX_KERNEXEC
26483+ struct desc_struct d;
26484+#endif
26485+
26486 local_irq_save(efi_rt_eflags);
26487
26488 load_cr3(initial_page_table);
26489 __flush_tlb_all();
26490
26491+#ifdef CONFIG_PAX_KERNEXEC
26492+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26493+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26494+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26495+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26496+#endif
26497+
26498 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26499 gdt_descr.size = GDT_SIZE - 1;
26500 load_gdt(&gdt_descr);
26501@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26502 {
26503 struct desc_ptr gdt_descr;
26504
26505+#ifdef CONFIG_PAX_KERNEXEC
26506+ struct desc_struct d;
26507+
26508+ memset(&d, 0, sizeof d);
26509+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26510+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26511+#endif
26512+
26513 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26514 gdt_descr.size = GDT_SIZE - 1;
26515 load_gdt(&gdt_descr);
26516diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26517index fbe66e6..c5c0dd2 100644
26518--- a/arch/x86/platform/efi/efi_stub_32.S
26519+++ b/arch/x86/platform/efi/efi_stub_32.S
26520@@ -6,7 +6,9 @@
26521 */
26522
26523 #include <linux/linkage.h>
26524+#include <linux/init.h>
26525 #include <asm/page_types.h>
26526+#include <asm/segment.h>
26527
26528 /*
26529 * efi_call_phys(void *, ...) is a function with variable parameters.
26530@@ -20,7 +22,7 @@
26531 * service functions will comply with gcc calling convention, too.
26532 */
26533
26534-.text
26535+__INIT
26536 ENTRY(efi_call_phys)
26537 /*
26538 * 0. The function can only be called in Linux kernel. So CS has been
26539@@ -36,9 +38,11 @@ ENTRY(efi_call_phys)
26540 * The mapping of lower virtual memory has been created in prelog and
26541 * epilog.
26542 */
26543- movl $1f, %edx
26544- subl $__PAGE_OFFSET, %edx
26545- jmp *%edx
26546+ movl $(__KERNEXEC_EFI_DS), %edx
26547+ mov %edx, %ds
26548+ mov %edx, %es
26549+ mov %edx, %ss
26550+ ljmp $(__KERNEXEC_EFI_CS),$1f-__PAGE_OFFSET
26551 1:
26552
26553 /*
26554@@ -47,14 +51,8 @@ ENTRY(efi_call_phys)
26555 * parameter 2, ..., param n. To make things easy, we save the return
26556 * address of efi_call_phys in a global variable.
26557 */
26558- popl %edx
26559- movl %edx, saved_return_addr
26560- /* get the function pointer into ECX*/
26561- popl %ecx
26562- movl %ecx, efi_rt_function_ptr
26563- movl $2f, %edx
26564- subl $__PAGE_OFFSET, %edx
26565- pushl %edx
26566+ popl (saved_return_addr)
26567+ popl (efi_rt_function_ptr)
26568
26569 /*
26570 * 3. Clear PG bit in %CR0.
26571@@ -73,9 +71,8 @@ ENTRY(efi_call_phys)
26572 /*
26573 * 5. Call the physical function.
26574 */
26575- jmp *%ecx
26576+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
26577
26578-2:
26579 /*
26580 * 6. After EFI runtime service returns, control will return to
26581 * following instruction. We'd better readjust stack pointer first.
26582@@ -88,35 +85,32 @@ ENTRY(efi_call_phys)
26583 movl %cr0, %edx
26584 orl $0x80000000, %edx
26585 movl %edx, %cr0
26586- jmp 1f
26587-1:
26588+
26589 /*
26590 * 8. Now restore the virtual mode from flat mode by
26591 * adding EIP with PAGE_OFFSET.
26592 */
26593- movl $1f, %edx
26594- jmp *%edx
26595+ ljmp $(__KERNEL_CS),$1f+__PAGE_OFFSET
26596 1:
26597+ movl $(__KERNEL_DS), %edx
26598+ mov %edx, %ds
26599+ mov %edx, %es
26600+ mov %edx, %ss
26601
26602 /*
26603 * 9. Balance the stack. And because EAX contain the return value,
26604 * we'd better not clobber it.
26605 */
26606- leal efi_rt_function_ptr, %edx
26607- movl (%edx), %ecx
26608- pushl %ecx
26609+ pushl (efi_rt_function_ptr)
26610
26611 /*
26612- * 10. Push the saved return address onto the stack and return.
26613+ * 10. Return to the saved return address.
26614 */
26615- leal saved_return_addr, %edx
26616- movl (%edx), %ecx
26617- pushl %ecx
26618- ret
26619+ jmpl *(saved_return_addr)
26620 ENDPROC(efi_call_phys)
26621 .previous
26622
26623-.data
26624+__INITDATA
26625 saved_return_addr:
26626 .long 0
26627 efi_rt_function_ptr:
26628diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26629index 4c07cca..2c8427d 100644
26630--- a/arch/x86/platform/efi/efi_stub_64.S
26631+++ b/arch/x86/platform/efi/efi_stub_64.S
26632@@ -7,6 +7,7 @@
26633 */
26634
26635 #include <linux/linkage.h>
26636+#include <asm/alternative-asm.h>
26637
26638 #define SAVE_XMM \
26639 mov %rsp, %rax; \
26640@@ -40,6 +41,7 @@ ENTRY(efi_call0)
26641 call *%rdi
26642 addq $32, %rsp
26643 RESTORE_XMM
26644+ pax_force_retaddr 0, 1
26645 ret
26646 ENDPROC(efi_call0)
26647
26648@@ -50,6 +52,7 @@ ENTRY(efi_call1)
26649 call *%rdi
26650 addq $32, %rsp
26651 RESTORE_XMM
26652+ pax_force_retaddr 0, 1
26653 ret
26654 ENDPROC(efi_call1)
26655
26656@@ -60,6 +63,7 @@ ENTRY(efi_call2)
26657 call *%rdi
26658 addq $32, %rsp
26659 RESTORE_XMM
26660+ pax_force_retaddr 0, 1
26661 ret
26662 ENDPROC(efi_call2)
26663
26664@@ -71,6 +75,7 @@ ENTRY(efi_call3)
26665 call *%rdi
26666 addq $32, %rsp
26667 RESTORE_XMM
26668+ pax_force_retaddr 0, 1
26669 ret
26670 ENDPROC(efi_call3)
26671
26672@@ -83,6 +88,7 @@ ENTRY(efi_call4)
26673 call *%rdi
26674 addq $32, %rsp
26675 RESTORE_XMM
26676+ pax_force_retaddr 0, 1
26677 ret
26678 ENDPROC(efi_call4)
26679
26680@@ -96,6 +102,7 @@ ENTRY(efi_call5)
26681 call *%rdi
26682 addq $48, %rsp
26683 RESTORE_XMM
26684+ pax_force_retaddr 0, 1
26685 ret
26686 ENDPROC(efi_call5)
26687
26688@@ -112,5 +119,6 @@ ENTRY(efi_call6)
26689 call *%rdi
26690 addq $48, %rsp
26691 RESTORE_XMM
26692+ pax_force_retaddr 0, 1
26693 ret
26694 ENDPROC(efi_call6)
26695diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26696index e31bcd8..f12dc46 100644
26697--- a/arch/x86/platform/mrst/mrst.c
26698+++ b/arch/x86/platform/mrst/mrst.c
26699@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26700 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26701 int sfi_mrtc_num;
26702
26703-static void mrst_power_off(void)
26704+static __noreturn void mrst_power_off(void)
26705 {
26706+ BUG();
26707 }
26708
26709-static void mrst_reboot(void)
26710+static __noreturn void mrst_reboot(void)
26711 {
26712 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26713+ BUG();
26714 }
26715
26716 /* parse all the mtimer info to a static mtimer array */
26717diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26718index 218cdb1..fd55c08 100644
26719--- a/arch/x86/power/cpu.c
26720+++ b/arch/x86/power/cpu.c
26721@@ -132,7 +132,7 @@ static void do_fpu_end(void)
26722 static void fix_processor_context(void)
26723 {
26724 int cpu = smp_processor_id();
26725- struct tss_struct *t = &per_cpu(init_tss, cpu);
26726+ struct tss_struct *t = init_tss + cpu;
26727
26728 set_tss_desc(cpu, t); /*
26729 * This just modifies memory; should not be
26730@@ -142,7 +142,9 @@ static void fix_processor_context(void)
26731 */
26732
26733 #ifdef CONFIG_X86_64
26734+ pax_open_kernel();
26735 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26736+ pax_close_kernel();
26737
26738 syscall_init(); /* This sets MSR_*STAR and related */
26739 #endif
26740diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
26741index b685296..e00eb65 100644
26742--- a/arch/x86/tools/relocs.c
26743+++ b/arch/x86/tools/relocs.c
26744@@ -12,10 +12,13 @@
26745 #include <regex.h>
26746 #include <tools/le_byteshift.h>
26747
26748+#include "../../../include/generated/autoconf.h"
26749+
26750 static void die(char *fmt, ...);
26751
26752 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
26753 static Elf32_Ehdr ehdr;
26754+static Elf32_Phdr *phdr;
26755 static unsigned long reloc_count, reloc_idx;
26756 static unsigned long *relocs;
26757 static unsigned long reloc16_count, reloc16_idx;
26758@@ -323,9 +326,39 @@ static void read_ehdr(FILE *fp)
26759 }
26760 }
26761
26762+static void read_phdrs(FILE *fp)
26763+{
26764+ unsigned int i;
26765+
26766+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
26767+ if (!phdr) {
26768+ die("Unable to allocate %d program headers\n",
26769+ ehdr.e_phnum);
26770+ }
26771+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
26772+ die("Seek to %d failed: %s\n",
26773+ ehdr.e_phoff, strerror(errno));
26774+ }
26775+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
26776+ die("Cannot read ELF program headers: %s\n",
26777+ strerror(errno));
26778+ }
26779+ for(i = 0; i < ehdr.e_phnum; i++) {
26780+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
26781+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
26782+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
26783+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
26784+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
26785+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
26786+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
26787+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
26788+ }
26789+
26790+}
26791+
26792 static void read_shdrs(FILE *fp)
26793 {
26794- int i;
26795+ unsigned int i;
26796 Elf32_Shdr shdr;
26797
26798 secs = calloc(ehdr.e_shnum, sizeof(struct section));
26799@@ -360,7 +393,7 @@ static void read_shdrs(FILE *fp)
26800
26801 static void read_strtabs(FILE *fp)
26802 {
26803- int i;
26804+ unsigned int i;
26805 for (i = 0; i < ehdr.e_shnum; i++) {
26806 struct section *sec = &secs[i];
26807 if (sec->shdr.sh_type != SHT_STRTAB) {
26808@@ -385,7 +418,7 @@ static void read_strtabs(FILE *fp)
26809
26810 static void read_symtabs(FILE *fp)
26811 {
26812- int i,j;
26813+ unsigned int i,j;
26814 for (i = 0; i < ehdr.e_shnum; i++) {
26815 struct section *sec = &secs[i];
26816 if (sec->shdr.sh_type != SHT_SYMTAB) {
26817@@ -418,7 +451,9 @@ static void read_symtabs(FILE *fp)
26818
26819 static void read_relocs(FILE *fp)
26820 {
26821- int i,j;
26822+ unsigned int i,j;
26823+ uint32_t base;
26824+
26825 for (i = 0; i < ehdr.e_shnum; i++) {
26826 struct section *sec = &secs[i];
26827 if (sec->shdr.sh_type != SHT_REL) {
26828@@ -438,9 +473,22 @@ static void read_relocs(FILE *fp)
26829 die("Cannot read symbol table: %s\n",
26830 strerror(errno));
26831 }
26832+ base = 0;
26833+
26834+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
26835+ for (j = 0; j < ehdr.e_phnum; j++) {
26836+ if (phdr[j].p_type != PT_LOAD )
26837+ continue;
26838+ 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)
26839+ continue;
26840+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
26841+ break;
26842+ }
26843+#endif
26844+
26845 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
26846 Elf32_Rel *rel = &sec->reltab[j];
26847- rel->r_offset = elf32_to_cpu(rel->r_offset);
26848+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
26849 rel->r_info = elf32_to_cpu(rel->r_info);
26850 }
26851 }
26852@@ -449,13 +497,13 @@ static void read_relocs(FILE *fp)
26853
26854 static void print_absolute_symbols(void)
26855 {
26856- int i;
26857+ unsigned int i;
26858 printf("Absolute symbols\n");
26859 printf(" Num: Value Size Type Bind Visibility Name\n");
26860 for (i = 0; i < ehdr.e_shnum; i++) {
26861 struct section *sec = &secs[i];
26862 char *sym_strtab;
26863- int j;
26864+ unsigned int j;
26865
26866 if (sec->shdr.sh_type != SHT_SYMTAB) {
26867 continue;
26868@@ -482,14 +530,14 @@ static void print_absolute_symbols(void)
26869
26870 static void print_absolute_relocs(void)
26871 {
26872- int i, printed = 0;
26873+ unsigned int i, printed = 0;
26874
26875 for (i = 0; i < ehdr.e_shnum; i++) {
26876 struct section *sec = &secs[i];
26877 struct section *sec_applies, *sec_symtab;
26878 char *sym_strtab;
26879 Elf32_Sym *sh_symtab;
26880- int j;
26881+ unsigned int j;
26882 if (sec->shdr.sh_type != SHT_REL) {
26883 continue;
26884 }
26885@@ -551,13 +599,13 @@ static void print_absolute_relocs(void)
26886 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26887 int use_real_mode)
26888 {
26889- int i;
26890+ unsigned int i;
26891 /* Walk through the relocations */
26892 for (i = 0; i < ehdr.e_shnum; i++) {
26893 char *sym_strtab;
26894 Elf32_Sym *sh_symtab;
26895 struct section *sec_applies, *sec_symtab;
26896- int j;
26897+ unsigned int j;
26898 struct section *sec = &secs[i];
26899
26900 if (sec->shdr.sh_type != SHT_REL) {
26901@@ -581,6 +629,22 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26902 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
26903 r_type = ELF32_R_TYPE(rel->r_info);
26904
26905+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
26906+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
26907+ continue;
26908+
26909+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
26910+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
26911+ if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
26912+ continue;
26913+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
26914+ continue;
26915+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
26916+ continue;
26917+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
26918+ continue;
26919+#endif
26920+
26921 shn_abs = sym->st_shndx == SHN_ABS;
26922
26923 switch (r_type) {
26924@@ -674,7 +738,7 @@ static int write32(unsigned int v, FILE *f)
26925
26926 static void emit_relocs(int as_text, int use_real_mode)
26927 {
26928- int i;
26929+ unsigned int i;
26930 /* Count how many relocations I have and allocate space for them. */
26931 reloc_count = 0;
26932 walk_relocs(count_reloc, use_real_mode);
26933@@ -801,6 +865,7 @@ int main(int argc, char **argv)
26934 fname, strerror(errno));
26935 }
26936 read_ehdr(fp);
26937+ read_phdrs(fp);
26938 read_shdrs(fp);
26939 read_strtabs(fp);
26940 read_symtabs(fp);
26941diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
26942index fd14be1..e3c79c0 100644
26943--- a/arch/x86/vdso/Makefile
26944+++ b/arch/x86/vdso/Makefile
26945@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
26946 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
26947 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
26948
26949-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26950+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26951 GCOV_PROFILE := n
26952
26953 #
26954diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
26955index 66e6d93..587f435 100644
26956--- a/arch/x86/vdso/vdso32-setup.c
26957+++ b/arch/x86/vdso/vdso32-setup.c
26958@@ -25,6 +25,7 @@
26959 #include <asm/tlbflush.h>
26960 #include <asm/vdso.h>
26961 #include <asm/proto.h>
26962+#include <asm/mman.h>
26963
26964 enum {
26965 VDSO_DISABLED = 0,
26966@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
26967 void enable_sep_cpu(void)
26968 {
26969 int cpu = get_cpu();
26970- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26971+ struct tss_struct *tss = init_tss + cpu;
26972
26973 if (!boot_cpu_has(X86_FEATURE_SEP)) {
26974 put_cpu();
26975@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
26976 gate_vma.vm_start = FIXADDR_USER_START;
26977 gate_vma.vm_end = FIXADDR_USER_END;
26978 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
26979- gate_vma.vm_page_prot = __P101;
26980+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
26981
26982 return 0;
26983 }
26984@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26985 if (compat)
26986 addr = VDSO_HIGH_BASE;
26987 else {
26988- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
26989+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
26990 if (IS_ERR_VALUE(addr)) {
26991 ret = addr;
26992 goto up_fail;
26993 }
26994 }
26995
26996- current->mm->context.vdso = (void *)addr;
26997+ current->mm->context.vdso = addr;
26998
26999 if (compat_uses_vma || !compat) {
27000 /*
27001@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27002 }
27003
27004 current_thread_info()->sysenter_return =
27005- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27006+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27007
27008 up_fail:
27009 if (ret)
27010- current->mm->context.vdso = NULL;
27011+ current->mm->context.vdso = 0;
27012
27013 up_write(&mm->mmap_sem);
27014
27015@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
27016
27017 const char *arch_vma_name(struct vm_area_struct *vma)
27018 {
27019- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27020+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27021 return "[vdso]";
27022+
27023+#ifdef CONFIG_PAX_SEGMEXEC
27024+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
27025+ return "[vdso]";
27026+#endif
27027+
27028 return NULL;
27029 }
27030
27031@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27032 * Check to see if the corresponding task was created in compat vdso
27033 * mode.
27034 */
27035- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
27036+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
27037 return &gate_vma;
27038 return NULL;
27039 }
27040diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
27041index 00aaf04..4a26505 100644
27042--- a/arch/x86/vdso/vma.c
27043+++ b/arch/x86/vdso/vma.c
27044@@ -16,8 +16,6 @@
27045 #include <asm/vdso.h>
27046 #include <asm/page.h>
27047
27048-unsigned int __read_mostly vdso_enabled = 1;
27049-
27050 extern char vdso_start[], vdso_end[];
27051 extern unsigned short vdso_sync_cpuid;
27052
27053@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27054 * unaligned here as a result of stack start randomization.
27055 */
27056 addr = PAGE_ALIGN(addr);
27057- addr = align_addr(addr, NULL, ALIGN_VDSO);
27058
27059 return addr;
27060 }
27061@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
27062 unsigned size)
27063 {
27064 struct mm_struct *mm = current->mm;
27065- unsigned long addr;
27066+ unsigned long addr = 0;
27067 int ret;
27068
27069- if (!vdso_enabled)
27070- return 0;
27071-
27072 down_write(&mm->mmap_sem);
27073+
27074+#ifdef CONFIG_PAX_RANDMMAP
27075+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27076+#endif
27077+
27078 addr = vdso_addr(mm->start_stack, size);
27079+ addr = align_addr(addr, NULL, ALIGN_VDSO);
27080 addr = get_unmapped_area(NULL, addr, size, 0, 0);
27081 if (IS_ERR_VALUE(addr)) {
27082 ret = addr;
27083 goto up_fail;
27084 }
27085
27086- current->mm->context.vdso = (void *)addr;
27087+ mm->context.vdso = addr;
27088
27089 ret = install_special_mapping(mm, addr, size,
27090 VM_READ|VM_EXEC|
27091 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
27092 pages);
27093- if (ret) {
27094- current->mm->context.vdso = NULL;
27095- goto up_fail;
27096- }
27097+ if (ret)
27098+ mm->context.vdso = 0;
27099
27100 up_fail:
27101 up_write(&mm->mmap_sem);
27102@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27103 vdsox32_size);
27104 }
27105 #endif
27106-
27107-static __init int vdso_setup(char *s)
27108-{
27109- vdso_enabled = simple_strtoul(s, NULL, 0);
27110- return 0;
27111-}
27112-__setup("vdso=", vdso_setup);
27113diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27114index 40edfc3..b4d80ac 100644
27115--- a/arch/x86/xen/enlighten.c
27116+++ b/arch/x86/xen/enlighten.c
27117@@ -95,8 +95,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27118
27119 struct shared_info xen_dummy_shared_info;
27120
27121-void *xen_initial_gdt;
27122-
27123 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27124 __read_mostly int xen_have_vector_callback;
27125 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27126@@ -1165,30 +1163,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27127 #endif
27128 };
27129
27130-static void xen_reboot(int reason)
27131+static __noreturn void xen_reboot(int reason)
27132 {
27133 struct sched_shutdown r = { .reason = reason };
27134
27135- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27136- BUG();
27137+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27138+ BUG();
27139 }
27140
27141-static void xen_restart(char *msg)
27142+static __noreturn void xen_restart(char *msg)
27143 {
27144 xen_reboot(SHUTDOWN_reboot);
27145 }
27146
27147-static void xen_emergency_restart(void)
27148+static __noreturn void xen_emergency_restart(void)
27149 {
27150 xen_reboot(SHUTDOWN_reboot);
27151 }
27152
27153-static void xen_machine_halt(void)
27154+static __noreturn void xen_machine_halt(void)
27155 {
27156 xen_reboot(SHUTDOWN_poweroff);
27157 }
27158
27159-static void xen_machine_power_off(void)
27160+static __noreturn void xen_machine_power_off(void)
27161 {
27162 if (pm_power_off)
27163 pm_power_off();
27164@@ -1291,7 +1289,17 @@ asmlinkage void __init xen_start_kernel(void)
27165 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27166
27167 /* Work out if we support NX */
27168- x86_configure_nx();
27169+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27170+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27171+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27172+ unsigned l, h;
27173+
27174+ __supported_pte_mask |= _PAGE_NX;
27175+ rdmsr(MSR_EFER, l, h);
27176+ l |= EFER_NX;
27177+ wrmsr(MSR_EFER, l, h);
27178+ }
27179+#endif
27180
27181 xen_setup_features();
27182
27183@@ -1322,13 +1330,6 @@ asmlinkage void __init xen_start_kernel(void)
27184
27185 machine_ops = xen_machine_ops;
27186
27187- /*
27188- * The only reliable way to retain the initial address of the
27189- * percpu gdt_page is to remember it here, so we can go and
27190- * mark it RW later, when the initial percpu area is freed.
27191- */
27192- xen_initial_gdt = &per_cpu(gdt_page, 0);
27193-
27194 xen_smp_init();
27195
27196 #ifdef CONFIG_ACPI_NUMA
27197diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27198index 69f5857..0699dc5 100644
27199--- a/arch/x86/xen/mmu.c
27200+++ b/arch/x86/xen/mmu.c
27201@@ -1738,6 +1738,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27202 convert_pfn_mfn(init_level4_pgt);
27203 convert_pfn_mfn(level3_ident_pgt);
27204 convert_pfn_mfn(level3_kernel_pgt);
27205+ convert_pfn_mfn(level3_vmalloc_start_pgt);
27206+ convert_pfn_mfn(level3_vmalloc_end_pgt);
27207+ convert_pfn_mfn(level3_vmemmap_pgt);
27208
27209 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27210 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27211@@ -1756,7 +1759,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27212 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27213 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27214 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27215+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27216+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27217+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27218 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27219+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27220 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27221 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27222
27223@@ -1964,6 +1971,7 @@ static void __init xen_post_allocator_init(void)
27224 pv_mmu_ops.set_pud = xen_set_pud;
27225 #if PAGETABLE_LEVELS == 4
27226 pv_mmu_ops.set_pgd = xen_set_pgd;
27227+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27228 #endif
27229
27230 /* This will work as long as patching hasn't happened yet
27231@@ -2045,6 +2053,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27232 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27233 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27234 .set_pgd = xen_set_pgd_hyper,
27235+ .set_pgd_batched = xen_set_pgd_hyper,
27236
27237 .alloc_pud = xen_alloc_pmd_init,
27238 .release_pud = xen_release_pmd_init,
27239diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27240index 0503c0c..ceb2d16 100644
27241--- a/arch/x86/xen/smp.c
27242+++ b/arch/x86/xen/smp.c
27243@@ -215,11 +215,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27244 {
27245 BUG_ON(smp_processor_id() != 0);
27246 native_smp_prepare_boot_cpu();
27247-
27248- /* We've switched to the "real" per-cpu gdt, so make sure the
27249- old memory can be recycled */
27250- make_lowmem_page_readwrite(xen_initial_gdt);
27251-
27252 xen_filter_cpu_maps();
27253 xen_setup_vcpu_info_placement();
27254 }
27255@@ -296,12 +291,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27256 gdt = get_cpu_gdt_table(cpu);
27257
27258 ctxt->flags = VGCF_IN_KERNEL;
27259- ctxt->user_regs.ds = __USER_DS;
27260- ctxt->user_regs.es = __USER_DS;
27261+ ctxt->user_regs.ds = __KERNEL_DS;
27262+ ctxt->user_regs.es = __KERNEL_DS;
27263 ctxt->user_regs.ss = __KERNEL_DS;
27264 #ifdef CONFIG_X86_32
27265 ctxt->user_regs.fs = __KERNEL_PERCPU;
27266- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27267+ savesegment(gs, ctxt->user_regs.gs);
27268 #else
27269 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27270 #endif
27271@@ -352,13 +347,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu)
27272 int rc;
27273
27274 per_cpu(current_task, cpu) = idle;
27275+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
27276 #ifdef CONFIG_X86_32
27277 irq_ctx_init(cpu);
27278 #else
27279 clear_tsk_thread_flag(idle, TIF_FORK);
27280- per_cpu(kernel_stack, cpu) =
27281- (unsigned long)task_stack_page(idle) -
27282- KERNEL_STACK_OFFSET + THREAD_SIZE;
27283+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27284 #endif
27285 xen_setup_runstate_info(cpu);
27286 xen_setup_timer(cpu);
27287diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27288index b040b0e..8cc4fe0 100644
27289--- a/arch/x86/xen/xen-asm_32.S
27290+++ b/arch/x86/xen/xen-asm_32.S
27291@@ -83,14 +83,14 @@ ENTRY(xen_iret)
27292 ESP_OFFSET=4 # bytes pushed onto stack
27293
27294 /*
27295- * Store vcpu_info pointer for easy access. Do it this way to
27296- * avoid having to reload %fs
27297+ * Store vcpu_info pointer for easy access.
27298 */
27299 #ifdef CONFIG_SMP
27300- GET_THREAD_INFO(%eax)
27301- movl TI_cpu(%eax), %eax
27302- movl __per_cpu_offset(,%eax,4), %eax
27303- mov xen_vcpu(%eax), %eax
27304+ push %fs
27305+ mov $(__KERNEL_PERCPU), %eax
27306+ mov %eax, %fs
27307+ mov PER_CPU_VAR(xen_vcpu), %eax
27308+ pop %fs
27309 #else
27310 movl xen_vcpu, %eax
27311 #endif
27312diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27313index aaa7291..3f77960 100644
27314--- a/arch/x86/xen/xen-head.S
27315+++ b/arch/x86/xen/xen-head.S
27316@@ -19,6 +19,17 @@ ENTRY(startup_xen)
27317 #ifdef CONFIG_X86_32
27318 mov %esi,xen_start_info
27319 mov $init_thread_union+THREAD_SIZE,%esp
27320+#ifdef CONFIG_SMP
27321+ movl $cpu_gdt_table,%edi
27322+ movl $__per_cpu_load,%eax
27323+ movw %ax,__KERNEL_PERCPU + 2(%edi)
27324+ rorl $16,%eax
27325+ movb %al,__KERNEL_PERCPU + 4(%edi)
27326+ movb %ah,__KERNEL_PERCPU + 7(%edi)
27327+ movl $__per_cpu_end - 1,%eax
27328+ subl $__per_cpu_start,%eax
27329+ movw %ax,__KERNEL_PERCPU + 0(%edi)
27330+#endif
27331 #else
27332 mov %rsi,xen_start_info
27333 mov $init_thread_union+THREAD_SIZE,%rsp
27334diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27335index b095739..8c17bcd 100644
27336--- a/arch/x86/xen/xen-ops.h
27337+++ b/arch/x86/xen/xen-ops.h
27338@@ -10,8 +10,6 @@
27339 extern const char xen_hypervisor_callback[];
27340 extern const char xen_failsafe_callback[];
27341
27342-extern void *xen_initial_gdt;
27343-
27344 struct trap_info;
27345 void xen_copy_trap_info(struct trap_info *traps);
27346
27347diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27348index 525bd3d..ef888b1 100644
27349--- a/arch/xtensa/variants/dc232b/include/variant/core.h
27350+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27351@@ -119,9 +119,9 @@
27352 ----------------------------------------------------------------------*/
27353
27354 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27355-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27356 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27357 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27358+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27359
27360 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27361 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27362diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27363index 2f33760..835e50a 100644
27364--- a/arch/xtensa/variants/fsf/include/variant/core.h
27365+++ b/arch/xtensa/variants/fsf/include/variant/core.h
27366@@ -11,6 +11,7 @@
27367 #ifndef _XTENSA_CORE_H
27368 #define _XTENSA_CORE_H
27369
27370+#include <linux/const.h>
27371
27372 /****************************************************************************
27373 Parameters Useful for Any Code, USER or PRIVILEGED
27374@@ -112,9 +113,9 @@
27375 ----------------------------------------------------------------------*/
27376
27377 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27378-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27379 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27380 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27381+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27382
27383 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27384 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27385diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27386index af00795..2bb8105 100644
27387--- a/arch/xtensa/variants/s6000/include/variant/core.h
27388+++ b/arch/xtensa/variants/s6000/include/variant/core.h
27389@@ -11,6 +11,7 @@
27390 #ifndef _XTENSA_CORE_CONFIGURATION_H
27391 #define _XTENSA_CORE_CONFIGURATION_H
27392
27393+#include <linux/const.h>
27394
27395 /****************************************************************************
27396 Parameters Useful for Any Code, USER or PRIVILEGED
27397@@ -118,9 +119,9 @@
27398 ----------------------------------------------------------------------*/
27399
27400 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27401-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27402 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27403 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27404+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27405
27406 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27407 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27408diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27409index 58916af..9cb880b 100644
27410--- a/block/blk-iopoll.c
27411+++ b/block/blk-iopoll.c
27412@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27413 }
27414 EXPORT_SYMBOL(blk_iopoll_complete);
27415
27416-static void blk_iopoll_softirq(struct softirq_action *h)
27417+static void blk_iopoll_softirq(void)
27418 {
27419 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27420 int rearm = 0, budget = blk_iopoll_budget;
27421diff --git a/block/blk-map.c b/block/blk-map.c
27422index 623e1cd..ca1e109 100644
27423--- a/block/blk-map.c
27424+++ b/block/blk-map.c
27425@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27426 if (!len || !kbuf)
27427 return -EINVAL;
27428
27429- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27430+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27431 if (do_copy)
27432 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27433 else
27434diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27435index 467c8de..4bddc6d 100644
27436--- a/block/blk-softirq.c
27437+++ b/block/blk-softirq.c
27438@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27439 * Softirq action handler - move entries to local list and loop over them
27440 * while passing them to the queue registered handler.
27441 */
27442-static void blk_done_softirq(struct softirq_action *h)
27443+static void blk_done_softirq(void)
27444 {
27445 struct list_head *cpu_list, local_list;
27446
27447diff --git a/block/bsg.c b/block/bsg.c
27448index ff64ae3..593560c 100644
27449--- a/block/bsg.c
27450+++ b/block/bsg.c
27451@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27452 struct sg_io_v4 *hdr, struct bsg_device *bd,
27453 fmode_t has_write_perm)
27454 {
27455+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27456+ unsigned char *cmdptr;
27457+
27458 if (hdr->request_len > BLK_MAX_CDB) {
27459 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27460 if (!rq->cmd)
27461 return -ENOMEM;
27462- }
27463+ cmdptr = rq->cmd;
27464+ } else
27465+ cmdptr = tmpcmd;
27466
27467- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27468+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27469 hdr->request_len))
27470 return -EFAULT;
27471
27472+ if (cmdptr != rq->cmd)
27473+ memcpy(rq->cmd, cmdptr, hdr->request_len);
27474+
27475 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27476 if (blk_verify_command(rq->cmd, has_write_perm))
27477 return -EPERM;
27478diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27479index 7c668c8..db3521c 100644
27480--- a/block/compat_ioctl.c
27481+++ b/block/compat_ioctl.c
27482@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27483 err |= __get_user(f->spec1, &uf->spec1);
27484 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27485 err |= __get_user(name, &uf->name);
27486- f->name = compat_ptr(name);
27487+ f->name = (void __force_kernel *)compat_ptr(name);
27488 if (err) {
27489 err = -EFAULT;
27490 goto out;
27491diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27492index 6296b40..417c00f 100644
27493--- a/block/partitions/efi.c
27494+++ b/block/partitions/efi.c
27495@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27496 if (!gpt)
27497 return NULL;
27498
27499+ if (!le32_to_cpu(gpt->num_partition_entries))
27500+ return NULL;
27501+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27502+ if (!pte)
27503+ return NULL;
27504+
27505 count = le32_to_cpu(gpt->num_partition_entries) *
27506 le32_to_cpu(gpt->sizeof_partition_entry);
27507- if (!count)
27508- return NULL;
27509- pte = kzalloc(count, GFP_KERNEL);
27510- if (!pte)
27511- return NULL;
27512-
27513 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27514 (u8 *) pte,
27515 count) < count) {
27516diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27517index 260fa80..e8f3caf 100644
27518--- a/block/scsi_ioctl.c
27519+++ b/block/scsi_ioctl.c
27520@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27521 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27522 struct sg_io_hdr *hdr, fmode_t mode)
27523 {
27524- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27525+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27526+ unsigned char *cmdptr;
27527+
27528+ if (rq->cmd != rq->__cmd)
27529+ cmdptr = rq->cmd;
27530+ else
27531+ cmdptr = tmpcmd;
27532+
27533+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27534 return -EFAULT;
27535+
27536+ if (cmdptr != rq->cmd)
27537+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27538+
27539 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27540 return -EPERM;
27541
27542@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27543 int err;
27544 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27545 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27546+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27547+ unsigned char *cmdptr;
27548
27549 if (!sic)
27550 return -EINVAL;
27551@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27552 */
27553 err = -EFAULT;
27554 rq->cmd_len = cmdlen;
27555- if (copy_from_user(rq->cmd, sic->data, cmdlen))
27556+
27557+ if (rq->cmd != rq->__cmd)
27558+ cmdptr = rq->cmd;
27559+ else
27560+ cmdptr = tmpcmd;
27561+
27562+ if (copy_from_user(cmdptr, sic->data, cmdlen))
27563 goto error;
27564
27565+ if (rq->cmd != cmdptr)
27566+ memcpy(rq->cmd, cmdptr, cmdlen);
27567+
27568 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27569 goto error;
27570
27571diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27572index 671d4d6..5f24030 100644
27573--- a/crypto/cryptd.c
27574+++ b/crypto/cryptd.c
27575@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27576
27577 struct cryptd_blkcipher_request_ctx {
27578 crypto_completion_t complete;
27579-};
27580+} __no_const;
27581
27582 struct cryptd_hash_ctx {
27583 struct crypto_shash *child;
27584@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27585
27586 struct cryptd_aead_request_ctx {
27587 crypto_completion_t complete;
27588-};
27589+} __no_const;
27590
27591 static void cryptd_queue_worker(struct work_struct *work);
27592
27593diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27594index e6defd8..c26a225 100644
27595--- a/drivers/acpi/apei/cper.c
27596+++ b/drivers/acpi/apei/cper.c
27597@@ -38,12 +38,12 @@
27598 */
27599 u64 cper_next_record_id(void)
27600 {
27601- static atomic64_t seq;
27602+ static atomic64_unchecked_t seq;
27603
27604- if (!atomic64_read(&seq))
27605- atomic64_set(&seq, ((u64)get_seconds()) << 32);
27606+ if (!atomic64_read_unchecked(&seq))
27607+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27608
27609- return atomic64_inc_return(&seq);
27610+ return atomic64_inc_return_unchecked(&seq);
27611 }
27612 EXPORT_SYMBOL_GPL(cper_next_record_id);
27613
27614diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27615index 7586544..636a2f0 100644
27616--- a/drivers/acpi/ec_sys.c
27617+++ b/drivers/acpi/ec_sys.c
27618@@ -12,6 +12,7 @@
27619 #include <linux/acpi.h>
27620 #include <linux/debugfs.h>
27621 #include <linux/module.h>
27622+#include <linux/uaccess.h>
27623 #include "internal.h"
27624
27625 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27626@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27627 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27628 */
27629 unsigned int size = EC_SPACE_SIZE;
27630- u8 *data = (u8 *) buf;
27631+ u8 data;
27632 loff_t init_off = *off;
27633 int err = 0;
27634
27635@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27636 size = count;
27637
27638 while (size) {
27639- err = ec_read(*off, &data[*off - init_off]);
27640+ err = ec_read(*off, &data);
27641 if (err)
27642 return err;
27643+ if (put_user(data, &buf[*off - init_off]))
27644+ return -EFAULT;
27645 *off += 1;
27646 size--;
27647 }
27648@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27649
27650 unsigned int size = count;
27651 loff_t init_off = *off;
27652- u8 *data = (u8 *) buf;
27653 int err = 0;
27654
27655 if (*off >= EC_SPACE_SIZE)
27656@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27657 }
27658
27659 while (size) {
27660- u8 byte_write = data[*off - init_off];
27661+ u8 byte_write;
27662+ if (get_user(byte_write, &buf[*off - init_off]))
27663+ return -EFAULT;
27664 err = ec_write(*off, byte_write);
27665 if (err)
27666 return err;
27667diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27668index 251c7b62..000462d 100644
27669--- a/drivers/acpi/proc.c
27670+++ b/drivers/acpi/proc.c
27671@@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27672 size_t count, loff_t * ppos)
27673 {
27674 struct list_head *node, *next;
27675- char strbuf[5];
27676- char str[5] = "";
27677- unsigned int len = count;
27678+ char strbuf[5] = {0};
27679
27680- if (len > 4)
27681- len = 4;
27682- if (len < 0)
27683+ if (count > 4)
27684+ count = 4;
27685+ if (copy_from_user(strbuf, buffer, count))
27686 return -EFAULT;
27687-
27688- if (copy_from_user(strbuf, buffer, len))
27689- return -EFAULT;
27690- strbuf[len] = '\0';
27691- sscanf(strbuf, "%s", str);
27692+ strbuf[count] = '\0';
27693
27694 mutex_lock(&acpi_device_lock);
27695 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27696@@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27697 if (!dev->wakeup.flags.valid)
27698 continue;
27699
27700- if (!strncmp(dev->pnp.bus_id, str, 4)) {
27701+ if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27702 if (device_can_wakeup(&dev->dev)) {
27703 bool enable = !device_may_wakeup(&dev->dev);
27704 device_set_wakeup_enable(&dev->dev, enable);
27705diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27706index 0734086..3ad3e4c 100644
27707--- a/drivers/acpi/processor_driver.c
27708+++ b/drivers/acpi/processor_driver.c
27709@@ -556,7 +556,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27710 return 0;
27711 #endif
27712
27713- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27714+ BUG_ON(pr->id >= nr_cpu_ids);
27715
27716 /*
27717 * Buggy BIOS check
27718diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27719index d31ee55..8363a8b 100644
27720--- a/drivers/ata/libata-core.c
27721+++ b/drivers/ata/libata-core.c
27722@@ -4742,7 +4742,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27723 struct ata_port *ap;
27724 unsigned int tag;
27725
27726- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27727+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27728 ap = qc->ap;
27729
27730 qc->flags = 0;
27731@@ -4758,7 +4758,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27732 struct ata_port *ap;
27733 struct ata_link *link;
27734
27735- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27736+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27737 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27738 ap = qc->ap;
27739 link = qc->dev->link;
27740@@ -5822,6 +5822,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27741 return;
27742
27743 spin_lock(&lock);
27744+ pax_open_kernel();
27745
27746 for (cur = ops->inherits; cur; cur = cur->inherits) {
27747 void **inherit = (void **)cur;
27748@@ -5835,8 +5836,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27749 if (IS_ERR(*pp))
27750 *pp = NULL;
27751
27752- ops->inherits = NULL;
27753+ *(struct ata_port_operations **)&ops->inherits = NULL;
27754
27755+ pax_close_kernel();
27756 spin_unlock(&lock);
27757 }
27758
27759diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27760index 3239517..343b5f6 100644
27761--- a/drivers/ata/pata_arasan_cf.c
27762+++ b/drivers/ata/pata_arasan_cf.c
27763@@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27764 /* Handle platform specific quirks */
27765 if (pdata->quirk) {
27766 if (pdata->quirk & CF_BROKEN_PIO) {
27767- ap->ops->set_piomode = NULL;
27768+ pax_open_kernel();
27769+ *(void **)&ap->ops->set_piomode = NULL;
27770+ pax_close_kernel();
27771 ap->pio_mask = 0;
27772 }
27773 if (pdata->quirk & CF_BROKEN_MWDMA)
27774diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27775index f9b983a..887b9d8 100644
27776--- a/drivers/atm/adummy.c
27777+++ b/drivers/atm/adummy.c
27778@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27779 vcc->pop(vcc, skb);
27780 else
27781 dev_kfree_skb_any(skb);
27782- atomic_inc(&vcc->stats->tx);
27783+ atomic_inc_unchecked(&vcc->stats->tx);
27784
27785 return 0;
27786 }
27787diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27788index f8f41e0..1f987dd 100644
27789--- a/drivers/atm/ambassador.c
27790+++ b/drivers/atm/ambassador.c
27791@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27792 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27793
27794 // VC layer stats
27795- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27796+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27797
27798 // free the descriptor
27799 kfree (tx_descr);
27800@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27801 dump_skb ("<<<", vc, skb);
27802
27803 // VC layer stats
27804- atomic_inc(&atm_vcc->stats->rx);
27805+ atomic_inc_unchecked(&atm_vcc->stats->rx);
27806 __net_timestamp(skb);
27807 // end of our responsibility
27808 atm_vcc->push (atm_vcc, skb);
27809@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27810 } else {
27811 PRINTK (KERN_INFO, "dropped over-size frame");
27812 // should we count this?
27813- atomic_inc(&atm_vcc->stats->rx_drop);
27814+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27815 }
27816
27817 } else {
27818@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
27819 }
27820
27821 if (check_area (skb->data, skb->len)) {
27822- atomic_inc(&atm_vcc->stats->tx_err);
27823+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
27824 return -ENOMEM; // ?
27825 }
27826
27827diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
27828index b22d71c..d6e1049 100644
27829--- a/drivers/atm/atmtcp.c
27830+++ b/drivers/atm/atmtcp.c
27831@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27832 if (vcc->pop) vcc->pop(vcc,skb);
27833 else dev_kfree_skb(skb);
27834 if (dev_data) return 0;
27835- atomic_inc(&vcc->stats->tx_err);
27836+ atomic_inc_unchecked(&vcc->stats->tx_err);
27837 return -ENOLINK;
27838 }
27839 size = skb->len+sizeof(struct atmtcp_hdr);
27840@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27841 if (!new_skb) {
27842 if (vcc->pop) vcc->pop(vcc,skb);
27843 else dev_kfree_skb(skb);
27844- atomic_inc(&vcc->stats->tx_err);
27845+ atomic_inc_unchecked(&vcc->stats->tx_err);
27846 return -ENOBUFS;
27847 }
27848 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
27849@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27850 if (vcc->pop) vcc->pop(vcc,skb);
27851 else dev_kfree_skb(skb);
27852 out_vcc->push(out_vcc,new_skb);
27853- atomic_inc(&vcc->stats->tx);
27854- atomic_inc(&out_vcc->stats->rx);
27855+ atomic_inc_unchecked(&vcc->stats->tx);
27856+ atomic_inc_unchecked(&out_vcc->stats->rx);
27857 return 0;
27858 }
27859
27860@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27861 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
27862 read_unlock(&vcc_sklist_lock);
27863 if (!out_vcc) {
27864- atomic_inc(&vcc->stats->tx_err);
27865+ atomic_inc_unchecked(&vcc->stats->tx_err);
27866 goto done;
27867 }
27868 skb_pull(skb,sizeof(struct atmtcp_hdr));
27869@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27870 __net_timestamp(new_skb);
27871 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
27872 out_vcc->push(out_vcc,new_skb);
27873- atomic_inc(&vcc->stats->tx);
27874- atomic_inc(&out_vcc->stats->rx);
27875+ atomic_inc_unchecked(&vcc->stats->tx);
27876+ atomic_inc_unchecked(&out_vcc->stats->rx);
27877 done:
27878 if (vcc->pop) vcc->pop(vcc,skb);
27879 else dev_kfree_skb(skb);
27880diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
27881index 2059ee4..faf51c7 100644
27882--- a/drivers/atm/eni.c
27883+++ b/drivers/atm/eni.c
27884@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
27885 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
27886 vcc->dev->number);
27887 length = 0;
27888- atomic_inc(&vcc->stats->rx_err);
27889+ atomic_inc_unchecked(&vcc->stats->rx_err);
27890 }
27891 else {
27892 length = ATM_CELL_SIZE-1; /* no HEC */
27893@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27894 size);
27895 }
27896 eff = length = 0;
27897- atomic_inc(&vcc->stats->rx_err);
27898+ atomic_inc_unchecked(&vcc->stats->rx_err);
27899 }
27900 else {
27901 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
27902@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27903 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
27904 vcc->dev->number,vcc->vci,length,size << 2,descr);
27905 length = eff = 0;
27906- atomic_inc(&vcc->stats->rx_err);
27907+ atomic_inc_unchecked(&vcc->stats->rx_err);
27908 }
27909 }
27910 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
27911@@ -767,7 +767,7 @@ rx_dequeued++;
27912 vcc->push(vcc,skb);
27913 pushed++;
27914 }
27915- atomic_inc(&vcc->stats->rx);
27916+ atomic_inc_unchecked(&vcc->stats->rx);
27917 }
27918 wake_up(&eni_dev->rx_wait);
27919 }
27920@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
27921 PCI_DMA_TODEVICE);
27922 if (vcc->pop) vcc->pop(vcc,skb);
27923 else dev_kfree_skb_irq(skb);
27924- atomic_inc(&vcc->stats->tx);
27925+ atomic_inc_unchecked(&vcc->stats->tx);
27926 wake_up(&eni_dev->tx_wait);
27927 dma_complete++;
27928 }
27929@@ -1567,7 +1567,7 @@ tx_complete++;
27930 /*--------------------------------- entries ---------------------------------*/
27931
27932
27933-static const char *media_name[] __devinitdata = {
27934+static const char *media_name[] __devinitconst = {
27935 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
27936 "UTP", "05?", "06?", "07?", /* 4- 7 */
27937 "TAXI","09?", "10?", "11?", /* 8-11 */
27938diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
27939index 86fed1b..6dc4721 100644
27940--- a/drivers/atm/firestream.c
27941+++ b/drivers/atm/firestream.c
27942@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
27943 }
27944 }
27945
27946- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27947+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27948
27949 fs_dprintk (FS_DEBUG_TXMEM, "i");
27950 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
27951@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27952 #endif
27953 skb_put (skb, qe->p1 & 0xffff);
27954 ATM_SKB(skb)->vcc = atm_vcc;
27955- atomic_inc(&atm_vcc->stats->rx);
27956+ atomic_inc_unchecked(&atm_vcc->stats->rx);
27957 __net_timestamp(skb);
27958 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
27959 atm_vcc->push (atm_vcc, skb);
27960@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27961 kfree (pe);
27962 }
27963 if (atm_vcc)
27964- atomic_inc(&atm_vcc->stats->rx_drop);
27965+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27966 break;
27967 case 0x1f: /* Reassembly abort: no buffers. */
27968 /* Silently increment error counter. */
27969 if (atm_vcc)
27970- atomic_inc(&atm_vcc->stats->rx_drop);
27971+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27972 break;
27973 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
27974 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
27975diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
27976index 361f5ae..7fc552d 100644
27977--- a/drivers/atm/fore200e.c
27978+++ b/drivers/atm/fore200e.c
27979@@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
27980 #endif
27981 /* check error condition */
27982 if (*entry->status & STATUS_ERROR)
27983- atomic_inc(&vcc->stats->tx_err);
27984+ atomic_inc_unchecked(&vcc->stats->tx_err);
27985 else
27986- atomic_inc(&vcc->stats->tx);
27987+ atomic_inc_unchecked(&vcc->stats->tx);
27988 }
27989 }
27990
27991@@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27992 if (skb == NULL) {
27993 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
27994
27995- atomic_inc(&vcc->stats->rx_drop);
27996+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27997 return -ENOMEM;
27998 }
27999
28000@@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28001
28002 dev_kfree_skb_any(skb);
28003
28004- atomic_inc(&vcc->stats->rx_drop);
28005+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28006 return -ENOMEM;
28007 }
28008
28009 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28010
28011 vcc->push(vcc, skb);
28012- atomic_inc(&vcc->stats->rx);
28013+ atomic_inc_unchecked(&vcc->stats->rx);
28014
28015 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28016
28017@@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
28018 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
28019 fore200e->atm_dev->number,
28020 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
28021- atomic_inc(&vcc->stats->rx_err);
28022+ atomic_inc_unchecked(&vcc->stats->rx_err);
28023 }
28024 }
28025
28026@@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
28027 goto retry_here;
28028 }
28029
28030- atomic_inc(&vcc->stats->tx_err);
28031+ atomic_inc_unchecked(&vcc->stats->tx_err);
28032
28033 fore200e->tx_sat++;
28034 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
28035diff --git a/drivers/atm/he.c b/drivers/atm/he.c
28036index b182c2f..1c6fa8a 100644
28037--- a/drivers/atm/he.c
28038+++ b/drivers/atm/he.c
28039@@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28040
28041 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
28042 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
28043- atomic_inc(&vcc->stats->rx_drop);
28044+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28045 goto return_host_buffers;
28046 }
28047
28048@@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28049 RBRQ_LEN_ERR(he_dev->rbrq_head)
28050 ? "LEN_ERR" : "",
28051 vcc->vpi, vcc->vci);
28052- atomic_inc(&vcc->stats->rx_err);
28053+ atomic_inc_unchecked(&vcc->stats->rx_err);
28054 goto return_host_buffers;
28055 }
28056
28057@@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28058 vcc->push(vcc, skb);
28059 spin_lock(&he_dev->global_lock);
28060
28061- atomic_inc(&vcc->stats->rx);
28062+ atomic_inc_unchecked(&vcc->stats->rx);
28063
28064 return_host_buffers:
28065 ++pdus_assembled;
28066@@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28067 tpd->vcc->pop(tpd->vcc, tpd->skb);
28068 else
28069 dev_kfree_skb_any(tpd->skb);
28070- atomic_inc(&tpd->vcc->stats->tx_err);
28071+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28072 }
28073 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28074 return;
28075@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28076 vcc->pop(vcc, skb);
28077 else
28078 dev_kfree_skb_any(skb);
28079- atomic_inc(&vcc->stats->tx_err);
28080+ atomic_inc_unchecked(&vcc->stats->tx_err);
28081 return -EINVAL;
28082 }
28083
28084@@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28085 vcc->pop(vcc, skb);
28086 else
28087 dev_kfree_skb_any(skb);
28088- atomic_inc(&vcc->stats->tx_err);
28089+ atomic_inc_unchecked(&vcc->stats->tx_err);
28090 return -EINVAL;
28091 }
28092 #endif
28093@@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28094 vcc->pop(vcc, skb);
28095 else
28096 dev_kfree_skb_any(skb);
28097- atomic_inc(&vcc->stats->tx_err);
28098+ atomic_inc_unchecked(&vcc->stats->tx_err);
28099 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28100 return -ENOMEM;
28101 }
28102@@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28103 vcc->pop(vcc, skb);
28104 else
28105 dev_kfree_skb_any(skb);
28106- atomic_inc(&vcc->stats->tx_err);
28107+ atomic_inc_unchecked(&vcc->stats->tx_err);
28108 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28109 return -ENOMEM;
28110 }
28111@@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28112 __enqueue_tpd(he_dev, tpd, cid);
28113 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28114
28115- atomic_inc(&vcc->stats->tx);
28116+ atomic_inc_unchecked(&vcc->stats->tx);
28117
28118 return 0;
28119 }
28120diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28121index 75fd691..2d20b14 100644
28122--- a/drivers/atm/horizon.c
28123+++ b/drivers/atm/horizon.c
28124@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28125 {
28126 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28127 // VC layer stats
28128- atomic_inc(&vcc->stats->rx);
28129+ atomic_inc_unchecked(&vcc->stats->rx);
28130 __net_timestamp(skb);
28131 // end of our responsibility
28132 vcc->push (vcc, skb);
28133@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28134 dev->tx_iovec = NULL;
28135
28136 // VC layer stats
28137- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28138+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28139
28140 // free the skb
28141 hrz_kfree_skb (skb);
28142diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28143index 1c05212..c28e200 100644
28144--- a/drivers/atm/idt77252.c
28145+++ b/drivers/atm/idt77252.c
28146@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28147 else
28148 dev_kfree_skb(skb);
28149
28150- atomic_inc(&vcc->stats->tx);
28151+ atomic_inc_unchecked(&vcc->stats->tx);
28152 }
28153
28154 atomic_dec(&scq->used);
28155@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28156 if ((sb = dev_alloc_skb(64)) == NULL) {
28157 printk("%s: Can't allocate buffers for aal0.\n",
28158 card->name);
28159- atomic_add(i, &vcc->stats->rx_drop);
28160+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
28161 break;
28162 }
28163 if (!atm_charge(vcc, sb->truesize)) {
28164 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28165 card->name);
28166- atomic_add(i - 1, &vcc->stats->rx_drop);
28167+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28168 dev_kfree_skb(sb);
28169 break;
28170 }
28171@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28172 ATM_SKB(sb)->vcc = vcc;
28173 __net_timestamp(sb);
28174 vcc->push(vcc, sb);
28175- atomic_inc(&vcc->stats->rx);
28176+ atomic_inc_unchecked(&vcc->stats->rx);
28177
28178 cell += ATM_CELL_PAYLOAD;
28179 }
28180@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28181 "(CDC: %08x)\n",
28182 card->name, len, rpp->len, readl(SAR_REG_CDC));
28183 recycle_rx_pool_skb(card, rpp);
28184- atomic_inc(&vcc->stats->rx_err);
28185+ atomic_inc_unchecked(&vcc->stats->rx_err);
28186 return;
28187 }
28188 if (stat & SAR_RSQE_CRC) {
28189 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28190 recycle_rx_pool_skb(card, rpp);
28191- atomic_inc(&vcc->stats->rx_err);
28192+ atomic_inc_unchecked(&vcc->stats->rx_err);
28193 return;
28194 }
28195 if (skb_queue_len(&rpp->queue) > 1) {
28196@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28197 RXPRINTK("%s: Can't alloc RX skb.\n",
28198 card->name);
28199 recycle_rx_pool_skb(card, rpp);
28200- atomic_inc(&vcc->stats->rx_err);
28201+ atomic_inc_unchecked(&vcc->stats->rx_err);
28202 return;
28203 }
28204 if (!atm_charge(vcc, skb->truesize)) {
28205@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28206 __net_timestamp(skb);
28207
28208 vcc->push(vcc, skb);
28209- atomic_inc(&vcc->stats->rx);
28210+ atomic_inc_unchecked(&vcc->stats->rx);
28211
28212 return;
28213 }
28214@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28215 __net_timestamp(skb);
28216
28217 vcc->push(vcc, skb);
28218- atomic_inc(&vcc->stats->rx);
28219+ atomic_inc_unchecked(&vcc->stats->rx);
28220
28221 if (skb->truesize > SAR_FB_SIZE_3)
28222 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28223@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28224 if (vcc->qos.aal != ATM_AAL0) {
28225 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28226 card->name, vpi, vci);
28227- atomic_inc(&vcc->stats->rx_drop);
28228+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28229 goto drop;
28230 }
28231
28232 if ((sb = dev_alloc_skb(64)) == NULL) {
28233 printk("%s: Can't allocate buffers for AAL0.\n",
28234 card->name);
28235- atomic_inc(&vcc->stats->rx_err);
28236+ atomic_inc_unchecked(&vcc->stats->rx_err);
28237 goto drop;
28238 }
28239
28240@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28241 ATM_SKB(sb)->vcc = vcc;
28242 __net_timestamp(sb);
28243 vcc->push(vcc, sb);
28244- atomic_inc(&vcc->stats->rx);
28245+ atomic_inc_unchecked(&vcc->stats->rx);
28246
28247 drop:
28248 skb_pull(queue, 64);
28249@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28250
28251 if (vc == NULL) {
28252 printk("%s: NULL connection in send().\n", card->name);
28253- atomic_inc(&vcc->stats->tx_err);
28254+ atomic_inc_unchecked(&vcc->stats->tx_err);
28255 dev_kfree_skb(skb);
28256 return -EINVAL;
28257 }
28258 if (!test_bit(VCF_TX, &vc->flags)) {
28259 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28260- atomic_inc(&vcc->stats->tx_err);
28261+ atomic_inc_unchecked(&vcc->stats->tx_err);
28262 dev_kfree_skb(skb);
28263 return -EINVAL;
28264 }
28265@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28266 break;
28267 default:
28268 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28269- atomic_inc(&vcc->stats->tx_err);
28270+ atomic_inc_unchecked(&vcc->stats->tx_err);
28271 dev_kfree_skb(skb);
28272 return -EINVAL;
28273 }
28274
28275 if (skb_shinfo(skb)->nr_frags != 0) {
28276 printk("%s: No scatter-gather yet.\n", card->name);
28277- atomic_inc(&vcc->stats->tx_err);
28278+ atomic_inc_unchecked(&vcc->stats->tx_err);
28279 dev_kfree_skb(skb);
28280 return -EINVAL;
28281 }
28282@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28283
28284 err = queue_skb(card, vc, skb, oam);
28285 if (err) {
28286- atomic_inc(&vcc->stats->tx_err);
28287+ atomic_inc_unchecked(&vcc->stats->tx_err);
28288 dev_kfree_skb(skb);
28289 return err;
28290 }
28291@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28292 skb = dev_alloc_skb(64);
28293 if (!skb) {
28294 printk("%s: Out of memory in send_oam().\n", card->name);
28295- atomic_inc(&vcc->stats->tx_err);
28296+ atomic_inc_unchecked(&vcc->stats->tx_err);
28297 return -ENOMEM;
28298 }
28299 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28300diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28301index d438601..8b98495 100644
28302--- a/drivers/atm/iphase.c
28303+++ b/drivers/atm/iphase.c
28304@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28305 status = (u_short) (buf_desc_ptr->desc_mode);
28306 if (status & (RX_CER | RX_PTE | RX_OFL))
28307 {
28308- atomic_inc(&vcc->stats->rx_err);
28309+ atomic_inc_unchecked(&vcc->stats->rx_err);
28310 IF_ERR(printk("IA: bad packet, dropping it");)
28311 if (status & RX_CER) {
28312 IF_ERR(printk(" cause: packet CRC error\n");)
28313@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28314 len = dma_addr - buf_addr;
28315 if (len > iadev->rx_buf_sz) {
28316 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28317- atomic_inc(&vcc->stats->rx_err);
28318+ atomic_inc_unchecked(&vcc->stats->rx_err);
28319 goto out_free_desc;
28320 }
28321
28322@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28323 ia_vcc = INPH_IA_VCC(vcc);
28324 if (ia_vcc == NULL)
28325 {
28326- atomic_inc(&vcc->stats->rx_err);
28327+ atomic_inc_unchecked(&vcc->stats->rx_err);
28328 atm_return(vcc, skb->truesize);
28329 dev_kfree_skb_any(skb);
28330 goto INCR_DLE;
28331@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28332 if ((length > iadev->rx_buf_sz) || (length >
28333 (skb->len - sizeof(struct cpcs_trailer))))
28334 {
28335- atomic_inc(&vcc->stats->rx_err);
28336+ atomic_inc_unchecked(&vcc->stats->rx_err);
28337 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28338 length, skb->len);)
28339 atm_return(vcc, skb->truesize);
28340@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28341
28342 IF_RX(printk("rx_dle_intr: skb push");)
28343 vcc->push(vcc,skb);
28344- atomic_inc(&vcc->stats->rx);
28345+ atomic_inc_unchecked(&vcc->stats->rx);
28346 iadev->rx_pkt_cnt++;
28347 }
28348 INCR_DLE:
28349@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28350 {
28351 struct k_sonet_stats *stats;
28352 stats = &PRIV(_ia_dev[board])->sonet_stats;
28353- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28354- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28355- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28356- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28357- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28358- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28359- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28360- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28361- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28362+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28363+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28364+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28365+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28366+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28367+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28368+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28369+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28370+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28371 }
28372 ia_cmds.status = 0;
28373 break;
28374@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28375 if ((desc == 0) || (desc > iadev->num_tx_desc))
28376 {
28377 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28378- atomic_inc(&vcc->stats->tx);
28379+ atomic_inc_unchecked(&vcc->stats->tx);
28380 if (vcc->pop)
28381 vcc->pop(vcc, skb);
28382 else
28383@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28384 ATM_DESC(skb) = vcc->vci;
28385 skb_queue_tail(&iadev->tx_dma_q, skb);
28386
28387- atomic_inc(&vcc->stats->tx);
28388+ atomic_inc_unchecked(&vcc->stats->tx);
28389 iadev->tx_pkt_cnt++;
28390 /* Increment transaction counter */
28391 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28392
28393 #if 0
28394 /* add flow control logic */
28395- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28396+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28397 if (iavcc->vc_desc_cnt > 10) {
28398 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28399 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28400diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28401index 68c7588..7036683 100644
28402--- a/drivers/atm/lanai.c
28403+++ b/drivers/atm/lanai.c
28404@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28405 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28406 lanai_endtx(lanai, lvcc);
28407 lanai_free_skb(lvcc->tx.atmvcc, skb);
28408- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28409+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28410 }
28411
28412 /* Try to fill the buffer - don't call unless there is backlog */
28413@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28414 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28415 __net_timestamp(skb);
28416 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28417- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28418+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28419 out:
28420 lvcc->rx.buf.ptr = end;
28421 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28422@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28423 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28424 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28425 lanai->stats.service_rxnotaal5++;
28426- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28427+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28428 return 0;
28429 }
28430 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28431@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28432 int bytes;
28433 read_unlock(&vcc_sklist_lock);
28434 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28435- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28436+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28437 lvcc->stats.x.aal5.service_trash++;
28438 bytes = (SERVICE_GET_END(s) * 16) -
28439 (((unsigned long) lvcc->rx.buf.ptr) -
28440@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28441 }
28442 if (s & SERVICE_STREAM) {
28443 read_unlock(&vcc_sklist_lock);
28444- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28445+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28446 lvcc->stats.x.aal5.service_stream++;
28447 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28448 "PDU on VCI %d!\n", lanai->number, vci);
28449@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28450 return 0;
28451 }
28452 DPRINTK("got rx crc error on vci %d\n", vci);
28453- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28454+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28455 lvcc->stats.x.aal5.service_rxcrc++;
28456 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28457 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28458diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28459index 1c70c45..300718d 100644
28460--- a/drivers/atm/nicstar.c
28461+++ b/drivers/atm/nicstar.c
28462@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28463 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28464 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28465 card->index);
28466- atomic_inc(&vcc->stats->tx_err);
28467+ atomic_inc_unchecked(&vcc->stats->tx_err);
28468 dev_kfree_skb_any(skb);
28469 return -EINVAL;
28470 }
28471@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28472 if (!vc->tx) {
28473 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28474 card->index);
28475- atomic_inc(&vcc->stats->tx_err);
28476+ atomic_inc_unchecked(&vcc->stats->tx_err);
28477 dev_kfree_skb_any(skb);
28478 return -EINVAL;
28479 }
28480@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28481 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28482 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28483 card->index);
28484- atomic_inc(&vcc->stats->tx_err);
28485+ atomic_inc_unchecked(&vcc->stats->tx_err);
28486 dev_kfree_skb_any(skb);
28487 return -EINVAL;
28488 }
28489
28490 if (skb_shinfo(skb)->nr_frags != 0) {
28491 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28492- atomic_inc(&vcc->stats->tx_err);
28493+ atomic_inc_unchecked(&vcc->stats->tx_err);
28494 dev_kfree_skb_any(skb);
28495 return -EINVAL;
28496 }
28497@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28498 }
28499
28500 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28501- atomic_inc(&vcc->stats->tx_err);
28502+ atomic_inc_unchecked(&vcc->stats->tx_err);
28503 dev_kfree_skb_any(skb);
28504 return -EIO;
28505 }
28506- atomic_inc(&vcc->stats->tx);
28507+ atomic_inc_unchecked(&vcc->stats->tx);
28508
28509 return 0;
28510 }
28511@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28512 printk
28513 ("nicstar%d: Can't allocate buffers for aal0.\n",
28514 card->index);
28515- atomic_add(i, &vcc->stats->rx_drop);
28516+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
28517 break;
28518 }
28519 if (!atm_charge(vcc, sb->truesize)) {
28520 RXPRINTK
28521 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28522 card->index);
28523- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28524+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28525 dev_kfree_skb_any(sb);
28526 break;
28527 }
28528@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28529 ATM_SKB(sb)->vcc = vcc;
28530 __net_timestamp(sb);
28531 vcc->push(vcc, sb);
28532- atomic_inc(&vcc->stats->rx);
28533+ atomic_inc_unchecked(&vcc->stats->rx);
28534 cell += ATM_CELL_PAYLOAD;
28535 }
28536
28537@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28538 if (iovb == NULL) {
28539 printk("nicstar%d: Out of iovec buffers.\n",
28540 card->index);
28541- atomic_inc(&vcc->stats->rx_drop);
28542+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28543 recycle_rx_buf(card, skb);
28544 return;
28545 }
28546@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28547 small or large buffer itself. */
28548 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28549 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28550- atomic_inc(&vcc->stats->rx_err);
28551+ atomic_inc_unchecked(&vcc->stats->rx_err);
28552 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28553 NS_MAX_IOVECS);
28554 NS_PRV_IOVCNT(iovb) = 0;
28555@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28556 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28557 card->index);
28558 which_list(card, skb);
28559- atomic_inc(&vcc->stats->rx_err);
28560+ atomic_inc_unchecked(&vcc->stats->rx_err);
28561 recycle_rx_buf(card, skb);
28562 vc->rx_iov = NULL;
28563 recycle_iov_buf(card, iovb);
28564@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28565 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28566 card->index);
28567 which_list(card, skb);
28568- atomic_inc(&vcc->stats->rx_err);
28569+ atomic_inc_unchecked(&vcc->stats->rx_err);
28570 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28571 NS_PRV_IOVCNT(iovb));
28572 vc->rx_iov = NULL;
28573@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28574 printk(" - PDU size mismatch.\n");
28575 else
28576 printk(".\n");
28577- atomic_inc(&vcc->stats->rx_err);
28578+ atomic_inc_unchecked(&vcc->stats->rx_err);
28579 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28580 NS_PRV_IOVCNT(iovb));
28581 vc->rx_iov = NULL;
28582@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28583 /* skb points to a small buffer */
28584 if (!atm_charge(vcc, skb->truesize)) {
28585 push_rxbufs(card, skb);
28586- atomic_inc(&vcc->stats->rx_drop);
28587+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28588 } else {
28589 skb_put(skb, len);
28590 dequeue_sm_buf(card, skb);
28591@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28592 ATM_SKB(skb)->vcc = vcc;
28593 __net_timestamp(skb);
28594 vcc->push(vcc, skb);
28595- atomic_inc(&vcc->stats->rx);
28596+ atomic_inc_unchecked(&vcc->stats->rx);
28597 }
28598 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28599 struct sk_buff *sb;
28600@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28601 if (len <= NS_SMBUFSIZE) {
28602 if (!atm_charge(vcc, sb->truesize)) {
28603 push_rxbufs(card, sb);
28604- atomic_inc(&vcc->stats->rx_drop);
28605+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28606 } else {
28607 skb_put(sb, len);
28608 dequeue_sm_buf(card, sb);
28609@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28610 ATM_SKB(sb)->vcc = vcc;
28611 __net_timestamp(sb);
28612 vcc->push(vcc, sb);
28613- atomic_inc(&vcc->stats->rx);
28614+ atomic_inc_unchecked(&vcc->stats->rx);
28615 }
28616
28617 push_rxbufs(card, skb);
28618@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28619
28620 if (!atm_charge(vcc, skb->truesize)) {
28621 push_rxbufs(card, skb);
28622- atomic_inc(&vcc->stats->rx_drop);
28623+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28624 } else {
28625 dequeue_lg_buf(card, skb);
28626 #ifdef NS_USE_DESTRUCTORS
28627@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28628 ATM_SKB(skb)->vcc = vcc;
28629 __net_timestamp(skb);
28630 vcc->push(vcc, skb);
28631- atomic_inc(&vcc->stats->rx);
28632+ atomic_inc_unchecked(&vcc->stats->rx);
28633 }
28634
28635 push_rxbufs(card, sb);
28636@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28637 printk
28638 ("nicstar%d: Out of huge buffers.\n",
28639 card->index);
28640- atomic_inc(&vcc->stats->rx_drop);
28641+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28642 recycle_iovec_rx_bufs(card,
28643 (struct iovec *)
28644 iovb->data,
28645@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28646 card->hbpool.count++;
28647 } else
28648 dev_kfree_skb_any(hb);
28649- atomic_inc(&vcc->stats->rx_drop);
28650+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28651 } else {
28652 /* Copy the small buffer to the huge buffer */
28653 sb = (struct sk_buff *)iov->iov_base;
28654@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28655 #endif /* NS_USE_DESTRUCTORS */
28656 __net_timestamp(hb);
28657 vcc->push(vcc, hb);
28658- atomic_inc(&vcc->stats->rx);
28659+ atomic_inc_unchecked(&vcc->stats->rx);
28660 }
28661 }
28662
28663diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28664index 9851093..adb2b1e 100644
28665--- a/drivers/atm/solos-pci.c
28666+++ b/drivers/atm/solos-pci.c
28667@@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28668 }
28669 atm_charge(vcc, skb->truesize);
28670 vcc->push(vcc, skb);
28671- atomic_inc(&vcc->stats->rx);
28672+ atomic_inc_unchecked(&vcc->stats->rx);
28673 break;
28674
28675 case PKT_STATUS:
28676@@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28677 vcc = SKB_CB(oldskb)->vcc;
28678
28679 if (vcc) {
28680- atomic_inc(&vcc->stats->tx);
28681+ atomic_inc_unchecked(&vcc->stats->tx);
28682 solos_pop(vcc, oldskb);
28683 } else
28684 dev_kfree_skb_irq(oldskb);
28685diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28686index 0215934..ce9f5b1 100644
28687--- a/drivers/atm/suni.c
28688+++ b/drivers/atm/suni.c
28689@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28690
28691
28692 #define ADD_LIMITED(s,v) \
28693- atomic_add((v),&stats->s); \
28694- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28695+ atomic_add_unchecked((v),&stats->s); \
28696+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28697
28698
28699 static void suni_hz(unsigned long from_timer)
28700diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28701index 5120a96..e2572bd 100644
28702--- a/drivers/atm/uPD98402.c
28703+++ b/drivers/atm/uPD98402.c
28704@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28705 struct sonet_stats tmp;
28706 int error = 0;
28707
28708- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28709+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28710 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28711 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28712 if (zero && !error) {
28713@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28714
28715
28716 #define ADD_LIMITED(s,v) \
28717- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28718- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28719- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28720+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28721+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28722+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28723
28724
28725 static void stat_event(struct atm_dev *dev)
28726@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28727 if (reason & uPD98402_INT_PFM) stat_event(dev);
28728 if (reason & uPD98402_INT_PCO) {
28729 (void) GET(PCOCR); /* clear interrupt cause */
28730- atomic_add(GET(HECCT),
28731+ atomic_add_unchecked(GET(HECCT),
28732 &PRIV(dev)->sonet_stats.uncorr_hcs);
28733 }
28734 if ((reason & uPD98402_INT_RFO) &&
28735@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28736 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28737 uPD98402_INT_LOS),PIMR); /* enable them */
28738 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28739- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28740- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28741- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28742+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28743+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28744+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28745 return 0;
28746 }
28747
28748diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28749index abe4e20..83c4727 100644
28750--- a/drivers/atm/zatm.c
28751+++ b/drivers/atm/zatm.c
28752@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28753 }
28754 if (!size) {
28755 dev_kfree_skb_irq(skb);
28756- if (vcc) atomic_inc(&vcc->stats->rx_err);
28757+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28758 continue;
28759 }
28760 if (!atm_charge(vcc,skb->truesize)) {
28761@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28762 skb->len = size;
28763 ATM_SKB(skb)->vcc = vcc;
28764 vcc->push(vcc,skb);
28765- atomic_inc(&vcc->stats->rx);
28766+ atomic_inc_unchecked(&vcc->stats->rx);
28767 }
28768 zout(pos & 0xffff,MTA(mbx));
28769 #if 0 /* probably a stupid idea */
28770@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28771 skb_queue_head(&zatm_vcc->backlog,skb);
28772 break;
28773 }
28774- atomic_inc(&vcc->stats->tx);
28775+ atomic_inc_unchecked(&vcc->stats->tx);
28776 wake_up(&zatm_vcc->tx_wait);
28777 }
28778
28779diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28780index 8493536..31adee0 100644
28781--- a/drivers/base/devtmpfs.c
28782+++ b/drivers/base/devtmpfs.c
28783@@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
28784 if (!thread)
28785 return 0;
28786
28787- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28788+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28789 if (err)
28790 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28791 else
28792diff --git a/drivers/base/node.c b/drivers/base/node.c
28793index 90aa2a1..af1a177 100644
28794--- a/drivers/base/node.c
28795+++ b/drivers/base/node.c
28796@@ -592,11 +592,9 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
28797 {
28798 int n;
28799
28800- n = nodelist_scnprintf(buf, PAGE_SIZE, node_states[state]);
28801- if (n > 0 && PAGE_SIZE > n + 1) {
28802- *(buf + n++) = '\n';
28803- *(buf + n++) = '\0';
28804- }
28805+ n = nodelist_scnprintf(buf, PAGE_SIZE-2, node_states[state]);
28806+ buf[n++] = '\n';
28807+ buf[n] = '\0';
28808 return n;
28809 }
28810
28811diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28812index 2a3e581..3d6a73f 100644
28813--- a/drivers/base/power/wakeup.c
28814+++ b/drivers/base/power/wakeup.c
28815@@ -30,14 +30,14 @@ bool events_check_enabled;
28816 * They need to be modified together atomically, so it's better to use one
28817 * atomic variable to hold them both.
28818 */
28819-static atomic_t combined_event_count = ATOMIC_INIT(0);
28820+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28821
28822 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28823 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28824
28825 static void split_counters(unsigned int *cnt, unsigned int *inpr)
28826 {
28827- unsigned int comb = atomic_read(&combined_event_count);
28828+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
28829
28830 *cnt = (comb >> IN_PROGRESS_BITS);
28831 *inpr = comb & MAX_IN_PROGRESS;
28832@@ -379,7 +379,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
28833 ws->last_time = ktime_get();
28834
28835 /* Increment the counter of events in progress. */
28836- atomic_inc(&combined_event_count);
28837+ atomic_inc_unchecked(&combined_event_count);
28838 }
28839
28840 /**
28841@@ -475,7 +475,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
28842 * Increment the counter of registered wakeup events and decrement the
28843 * couter of wakeup events in progress simultaneously.
28844 */
28845- atomic_add(MAX_IN_PROGRESS, &combined_event_count);
28846+ atomic_add_unchecked(MAX_IN_PROGRESS, &combined_event_count);
28847 }
28848
28849 /**
28850diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
28851index b0f553b..77b928b 100644
28852--- a/drivers/block/cciss.c
28853+++ b/drivers/block/cciss.c
28854@@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
28855 int err;
28856 u32 cp;
28857
28858+ memset(&arg64, 0, sizeof(arg64));
28859+
28860 err = 0;
28861 err |=
28862 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
28863@@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
28864 while (!list_empty(&h->reqQ)) {
28865 c = list_entry(h->reqQ.next, CommandList_struct, list);
28866 /* can't do anything if fifo is full */
28867- if ((h->access.fifo_full(h))) {
28868+ if ((h->access->fifo_full(h))) {
28869 dev_warn(&h->pdev->dev, "fifo full\n");
28870 break;
28871 }
28872@@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
28873 h->Qdepth--;
28874
28875 /* Tell the controller execute command */
28876- h->access.submit_command(h, c);
28877+ h->access->submit_command(h, c);
28878
28879 /* Put job onto the completed Q */
28880 addQ(&h->cmpQ, c);
28881@@ -3443,17 +3445,17 @@ startio:
28882
28883 static inline unsigned long get_next_completion(ctlr_info_t *h)
28884 {
28885- return h->access.command_completed(h);
28886+ return h->access->command_completed(h);
28887 }
28888
28889 static inline int interrupt_pending(ctlr_info_t *h)
28890 {
28891- return h->access.intr_pending(h);
28892+ return h->access->intr_pending(h);
28893 }
28894
28895 static inline long interrupt_not_for_us(ctlr_info_t *h)
28896 {
28897- return ((h->access.intr_pending(h) == 0) ||
28898+ return ((h->access->intr_pending(h) == 0) ||
28899 (h->interrupts_enabled == 0));
28900 }
28901
28902@@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
28903 u32 a;
28904
28905 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
28906- return h->access.command_completed(h);
28907+ return h->access->command_completed(h);
28908
28909 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
28910 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
28911@@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
28912 trans_support & CFGTBL_Trans_use_short_tags);
28913
28914 /* Change the access methods to the performant access methods */
28915- h->access = SA5_performant_access;
28916+ h->access = &SA5_performant_access;
28917 h->transMethod = CFGTBL_Trans_Performant;
28918
28919 return;
28920@@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
28921 if (prod_index < 0)
28922 return -ENODEV;
28923 h->product_name = products[prod_index].product_name;
28924- h->access = *(products[prod_index].access);
28925+ h->access = products[prod_index].access;
28926
28927 if (cciss_board_disabled(h)) {
28928 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
28929@@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
28930 }
28931
28932 /* make sure the board interrupts are off */
28933- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28934+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28935 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
28936 if (rc)
28937 goto clean2;
28938@@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
28939 * fake ones to scoop up any residual completions.
28940 */
28941 spin_lock_irqsave(&h->lock, flags);
28942- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28943+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28944 spin_unlock_irqrestore(&h->lock, flags);
28945 free_irq(h->intr[h->intr_mode], h);
28946 rc = cciss_request_irq(h, cciss_msix_discard_completions,
28947@@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
28948 dev_info(&h->pdev->dev, "Board READY.\n");
28949 dev_info(&h->pdev->dev,
28950 "Waiting for stale completions to drain.\n");
28951- h->access.set_intr_mask(h, CCISS_INTR_ON);
28952+ h->access->set_intr_mask(h, CCISS_INTR_ON);
28953 msleep(10000);
28954- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28955+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28956
28957 rc = controller_reset_failed(h->cfgtable);
28958 if (rc)
28959@@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
28960 cciss_scsi_setup(h);
28961
28962 /* Turn the interrupts on so we can service requests */
28963- h->access.set_intr_mask(h, CCISS_INTR_ON);
28964+ h->access->set_intr_mask(h, CCISS_INTR_ON);
28965
28966 /* Get the firmware version */
28967 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
28968@@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
28969 kfree(flush_buf);
28970 if (return_code != IO_OK)
28971 dev_warn(&h->pdev->dev, "Error flushing cache\n");
28972- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28973+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28974 free_irq(h->intr[h->intr_mode], h);
28975 }
28976
28977diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
28978index 7fda30e..eb5dfe0 100644
28979--- a/drivers/block/cciss.h
28980+++ b/drivers/block/cciss.h
28981@@ -101,7 +101,7 @@ struct ctlr_info
28982 /* information about each logical volume */
28983 drive_info_struct *drv[CISS_MAX_LUN];
28984
28985- struct access_method access;
28986+ struct access_method *access;
28987
28988 /* queue and queue Info */
28989 struct list_head reqQ;
28990diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
28991index 9125bbe..eede5c8 100644
28992--- a/drivers/block/cpqarray.c
28993+++ b/drivers/block/cpqarray.c
28994@@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28995 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
28996 goto Enomem4;
28997 }
28998- hba[i]->access.set_intr_mask(hba[i], 0);
28999+ hba[i]->access->set_intr_mask(hba[i], 0);
29000 if (request_irq(hba[i]->intr, do_ida_intr,
29001 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
29002 {
29003@@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29004 add_timer(&hba[i]->timer);
29005
29006 /* Enable IRQ now that spinlock and rate limit timer are set up */
29007- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29008+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29009
29010 for(j=0; j<NWD; j++) {
29011 struct gendisk *disk = ida_gendisk[i][j];
29012@@ -694,7 +694,7 @@ DBGINFO(
29013 for(i=0; i<NR_PRODUCTS; i++) {
29014 if (board_id == products[i].board_id) {
29015 c->product_name = products[i].product_name;
29016- c->access = *(products[i].access);
29017+ c->access = products[i].access;
29018 break;
29019 }
29020 }
29021@@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
29022 hba[ctlr]->intr = intr;
29023 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
29024 hba[ctlr]->product_name = products[j].product_name;
29025- hba[ctlr]->access = *(products[j].access);
29026+ hba[ctlr]->access = products[j].access;
29027 hba[ctlr]->ctlr = ctlr;
29028 hba[ctlr]->board_id = board_id;
29029 hba[ctlr]->pci_dev = NULL; /* not PCI */
29030@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
29031
29032 while((c = h->reqQ) != NULL) {
29033 /* Can't do anything if we're busy */
29034- if (h->access.fifo_full(h) == 0)
29035+ if (h->access->fifo_full(h) == 0)
29036 return;
29037
29038 /* Get the first entry from the request Q */
29039@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
29040 h->Qdepth--;
29041
29042 /* Tell the controller to do our bidding */
29043- h->access.submit_command(h, c);
29044+ h->access->submit_command(h, c);
29045
29046 /* Get onto the completion Q */
29047 addQ(&h->cmpQ, c);
29048@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29049 unsigned long flags;
29050 __u32 a,a1;
29051
29052- istat = h->access.intr_pending(h);
29053+ istat = h->access->intr_pending(h);
29054 /* Is this interrupt for us? */
29055 if (istat == 0)
29056 return IRQ_NONE;
29057@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29058 */
29059 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
29060 if (istat & FIFO_NOT_EMPTY) {
29061- while((a = h->access.command_completed(h))) {
29062+ while((a = h->access->command_completed(h))) {
29063 a1 = a; a &= ~3;
29064 if ((c = h->cmpQ) == NULL)
29065 {
29066@@ -1449,11 +1449,11 @@ static int sendcmd(
29067 /*
29068 * Disable interrupt
29069 */
29070- info_p->access.set_intr_mask(info_p, 0);
29071+ info_p->access->set_intr_mask(info_p, 0);
29072 /* Make sure there is room in the command FIFO */
29073 /* Actually it should be completely empty at this time. */
29074 for (i = 200000; i > 0; i--) {
29075- temp = info_p->access.fifo_full(info_p);
29076+ temp = info_p->access->fifo_full(info_p);
29077 if (temp != 0) {
29078 break;
29079 }
29080@@ -1466,7 +1466,7 @@ DBG(
29081 /*
29082 * Send the cmd
29083 */
29084- info_p->access.submit_command(info_p, c);
29085+ info_p->access->submit_command(info_p, c);
29086 complete = pollcomplete(ctlr);
29087
29088 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29089@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29090 * we check the new geometry. Then turn interrupts back on when
29091 * we're done.
29092 */
29093- host->access.set_intr_mask(host, 0);
29094+ host->access->set_intr_mask(host, 0);
29095 getgeometry(ctlr);
29096- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29097+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29098
29099 for(i=0; i<NWD; i++) {
29100 struct gendisk *disk = ida_gendisk[ctlr][i];
29101@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29102 /* Wait (up to 2 seconds) for a command to complete */
29103
29104 for (i = 200000; i > 0; i--) {
29105- done = hba[ctlr]->access.command_completed(hba[ctlr]);
29106+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
29107 if (done == 0) {
29108 udelay(10); /* a short fixed delay */
29109 } else
29110diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29111index be73e9d..7fbf140 100644
29112--- a/drivers/block/cpqarray.h
29113+++ b/drivers/block/cpqarray.h
29114@@ -99,7 +99,7 @@ struct ctlr_info {
29115 drv_info_t drv[NWD];
29116 struct proc_dir_entry *proc;
29117
29118- struct access_method access;
29119+ struct access_method *access;
29120
29121 cmdlist_t *reqQ;
29122 cmdlist_t *cmpQ;
29123diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29124index 8d68056..e67050f 100644
29125--- a/drivers/block/drbd/drbd_int.h
29126+++ b/drivers/block/drbd/drbd_int.h
29127@@ -736,7 +736,7 @@ struct drbd_request;
29128 struct drbd_epoch {
29129 struct list_head list;
29130 unsigned int barrier_nr;
29131- atomic_t epoch_size; /* increased on every request added. */
29132+ atomic_unchecked_t epoch_size; /* increased on every request added. */
29133 atomic_t active; /* increased on every req. added, and dec on every finished. */
29134 unsigned long flags;
29135 };
29136@@ -1108,7 +1108,7 @@ struct drbd_conf {
29137 void *int_dig_in;
29138 void *int_dig_vv;
29139 wait_queue_head_t seq_wait;
29140- atomic_t packet_seq;
29141+ atomic_unchecked_t packet_seq;
29142 unsigned int peer_seq;
29143 spinlock_t peer_seq_lock;
29144 unsigned int minor;
29145@@ -1617,30 +1617,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29146
29147 static inline void drbd_tcp_cork(struct socket *sock)
29148 {
29149- int __user val = 1;
29150+ int val = 1;
29151 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29152- (char __user *)&val, sizeof(val));
29153+ (char __force_user *)&val, sizeof(val));
29154 }
29155
29156 static inline void drbd_tcp_uncork(struct socket *sock)
29157 {
29158- int __user val = 0;
29159+ int val = 0;
29160 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29161- (char __user *)&val, sizeof(val));
29162+ (char __force_user *)&val, sizeof(val));
29163 }
29164
29165 static inline void drbd_tcp_nodelay(struct socket *sock)
29166 {
29167- int __user val = 1;
29168+ int val = 1;
29169 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29170- (char __user *)&val, sizeof(val));
29171+ (char __force_user *)&val, sizeof(val));
29172 }
29173
29174 static inline void drbd_tcp_quickack(struct socket *sock)
29175 {
29176- int __user val = 2;
29177+ int val = 2;
29178 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29179- (char __user *)&val, sizeof(val));
29180+ (char __force_user *)&val, sizeof(val));
29181 }
29182
29183 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29184diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29185index 211fc44..c5116f1 100644
29186--- a/drivers/block/drbd/drbd_main.c
29187+++ b/drivers/block/drbd/drbd_main.c
29188@@ -2397,7 +2397,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29189 p.sector = sector;
29190 p.block_id = block_id;
29191 p.blksize = blksize;
29192- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29193+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29194
29195 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29196 return false;
29197@@ -2696,7 +2696,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29198 p.sector = cpu_to_be64(req->sector);
29199 p.block_id = (unsigned long)req;
29200 p.seq_num = cpu_to_be32(req->seq_num =
29201- atomic_add_return(1, &mdev->packet_seq));
29202+ atomic_add_return_unchecked(1, &mdev->packet_seq));
29203
29204 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29205
29206@@ -2981,7 +2981,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29207 atomic_set(&mdev->unacked_cnt, 0);
29208 atomic_set(&mdev->local_cnt, 0);
29209 atomic_set(&mdev->net_cnt, 0);
29210- atomic_set(&mdev->packet_seq, 0);
29211+ atomic_set_unchecked(&mdev->packet_seq, 0);
29212 atomic_set(&mdev->pp_in_use, 0);
29213 atomic_set(&mdev->pp_in_use_by_net, 0);
29214 atomic_set(&mdev->rs_sect_in, 0);
29215@@ -3063,8 +3063,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29216 mdev->receiver.t_state);
29217
29218 /* no need to lock it, I'm the only thread alive */
29219- if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29220- dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29221+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29222+ dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29223 mdev->al_writ_cnt =
29224 mdev->bm_writ_cnt =
29225 mdev->read_cnt =
29226diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29227index 946166e..356b39a 100644
29228--- a/drivers/block/drbd/drbd_nl.c
29229+++ b/drivers/block/drbd/drbd_nl.c
29230@@ -2359,7 +2359,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29231 module_put(THIS_MODULE);
29232 }
29233
29234-static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29235+static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29236
29237 static unsigned short *
29238 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29239@@ -2430,7 +2430,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29240 cn_reply->id.idx = CN_IDX_DRBD;
29241 cn_reply->id.val = CN_VAL_DRBD;
29242
29243- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29244+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29245 cn_reply->ack = 0; /* not used here. */
29246 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29247 (int)((char *)tl - (char *)reply->tag_list);
29248@@ -2462,7 +2462,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29249 cn_reply->id.idx = CN_IDX_DRBD;
29250 cn_reply->id.val = CN_VAL_DRBD;
29251
29252- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29253+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29254 cn_reply->ack = 0; /* not used here. */
29255 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29256 (int)((char *)tl - (char *)reply->tag_list);
29257@@ -2540,7 +2540,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29258 cn_reply->id.idx = CN_IDX_DRBD;
29259 cn_reply->id.val = CN_VAL_DRBD;
29260
29261- cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29262+ cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29263 cn_reply->ack = 0; // not used here.
29264 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29265 (int)((char*)tl - (char*)reply->tag_list);
29266@@ -2579,7 +2579,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29267 cn_reply->id.idx = CN_IDX_DRBD;
29268 cn_reply->id.val = CN_VAL_DRBD;
29269
29270- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29271+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29272 cn_reply->ack = 0; /* not used here. */
29273 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29274 (int)((char *)tl - (char *)reply->tag_list);
29275diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29276index 43beaca..4a5b1dd 100644
29277--- a/drivers/block/drbd/drbd_receiver.c
29278+++ b/drivers/block/drbd/drbd_receiver.c
29279@@ -894,7 +894,7 @@ retry:
29280 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29281 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29282
29283- atomic_set(&mdev->packet_seq, 0);
29284+ atomic_set_unchecked(&mdev->packet_seq, 0);
29285 mdev->peer_seq = 0;
29286
29287 drbd_thread_start(&mdev->asender);
29288@@ -985,7 +985,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29289 do {
29290 next_epoch = NULL;
29291
29292- epoch_size = atomic_read(&epoch->epoch_size);
29293+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29294
29295 switch (ev & ~EV_CLEANUP) {
29296 case EV_PUT:
29297@@ -1020,7 +1020,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29298 rv = FE_DESTROYED;
29299 } else {
29300 epoch->flags = 0;
29301- atomic_set(&epoch->epoch_size, 0);
29302+ atomic_set_unchecked(&epoch->epoch_size, 0);
29303 /* atomic_set(&epoch->active, 0); is already zero */
29304 if (rv == FE_STILL_LIVE)
29305 rv = FE_RECYCLED;
29306@@ -1191,14 +1191,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29307 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29308 drbd_flush(mdev);
29309
29310- if (atomic_read(&mdev->current_epoch->epoch_size)) {
29311+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29312 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29313 if (epoch)
29314 break;
29315 }
29316
29317 epoch = mdev->current_epoch;
29318- wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29319+ wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29320
29321 D_ASSERT(atomic_read(&epoch->active) == 0);
29322 D_ASSERT(epoch->flags == 0);
29323@@ -1210,11 +1210,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29324 }
29325
29326 epoch->flags = 0;
29327- atomic_set(&epoch->epoch_size, 0);
29328+ atomic_set_unchecked(&epoch->epoch_size, 0);
29329 atomic_set(&epoch->active, 0);
29330
29331 spin_lock(&mdev->epoch_lock);
29332- if (atomic_read(&mdev->current_epoch->epoch_size)) {
29333+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29334 list_add(&epoch->list, &mdev->current_epoch->list);
29335 mdev->current_epoch = epoch;
29336 mdev->epochs++;
29337@@ -1663,7 +1663,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29338 spin_unlock(&mdev->peer_seq_lock);
29339
29340 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29341- atomic_inc(&mdev->current_epoch->epoch_size);
29342+ atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29343 return drbd_drain_block(mdev, data_size);
29344 }
29345
29346@@ -1689,7 +1689,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29347
29348 spin_lock(&mdev->epoch_lock);
29349 e->epoch = mdev->current_epoch;
29350- atomic_inc(&e->epoch->epoch_size);
29351+ atomic_inc_unchecked(&e->epoch->epoch_size);
29352 atomic_inc(&e->epoch->active);
29353 spin_unlock(&mdev->epoch_lock);
29354
29355@@ -3885,7 +3885,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29356 D_ASSERT(list_empty(&mdev->done_ee));
29357
29358 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29359- atomic_set(&mdev->current_epoch->epoch_size, 0);
29360+ atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29361 D_ASSERT(list_empty(&mdev->current_epoch->list));
29362 }
29363
29364diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29365index bbca966..65e37dd 100644
29366--- a/drivers/block/loop.c
29367+++ b/drivers/block/loop.c
29368@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29369 mm_segment_t old_fs = get_fs();
29370
29371 set_fs(get_ds());
29372- bw = file->f_op->write(file, buf, len, &pos);
29373+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29374 set_fs(old_fs);
29375 if (likely(bw == len))
29376 return 0;
29377diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29378index ee94686..3e09ad3 100644
29379--- a/drivers/char/Kconfig
29380+++ b/drivers/char/Kconfig
29381@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29382
29383 config DEVKMEM
29384 bool "/dev/kmem virtual device support"
29385- default y
29386+ default n
29387+ depends on !GRKERNSEC_KMEM
29388 help
29389 Say Y here if you want to support the /dev/kmem device. The
29390 /dev/kmem device is rarely used, but can be used for certain
29391@@ -581,6 +582,7 @@ config DEVPORT
29392 bool
29393 depends on !M68K
29394 depends on ISA || PCI
29395+ depends on !GRKERNSEC_KMEM
29396 default y
29397
29398 source "drivers/s390/char/Kconfig"
29399diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29400index 2e04433..22afc64 100644
29401--- a/drivers/char/agp/frontend.c
29402+++ b/drivers/char/agp/frontend.c
29403@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29404 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29405 return -EFAULT;
29406
29407- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29408+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29409 return -EFAULT;
29410
29411 client = agp_find_client_by_pid(reserve.pid);
29412diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29413index 21cb980..f15107c 100644
29414--- a/drivers/char/genrtc.c
29415+++ b/drivers/char/genrtc.c
29416@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29417 switch (cmd) {
29418
29419 case RTC_PLL_GET:
29420+ memset(&pll, 0, sizeof(pll));
29421 if (get_rtc_pll(&pll))
29422 return -EINVAL;
29423 else
29424diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29425index dfd7876..c0b0885 100644
29426--- a/drivers/char/hpet.c
29427+++ b/drivers/char/hpet.c
29428@@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29429 }
29430
29431 static int
29432-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29433+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29434 struct hpet_info *info)
29435 {
29436 struct hpet_timer __iomem *timer;
29437diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29438index 2c29942..604c5ba 100644
29439--- a/drivers/char/ipmi/ipmi_msghandler.c
29440+++ b/drivers/char/ipmi/ipmi_msghandler.c
29441@@ -420,7 +420,7 @@ struct ipmi_smi {
29442 struct proc_dir_entry *proc_dir;
29443 char proc_dir_name[10];
29444
29445- atomic_t stats[IPMI_NUM_STATS];
29446+ atomic_unchecked_t stats[IPMI_NUM_STATS];
29447
29448 /*
29449 * run_to_completion duplicate of smb_info, smi_info
29450@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29451
29452
29453 #define ipmi_inc_stat(intf, stat) \
29454- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29455+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29456 #define ipmi_get_stat(intf, stat) \
29457- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29458+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29459
29460 static int is_lan_addr(struct ipmi_addr *addr)
29461 {
29462@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29463 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29464 init_waitqueue_head(&intf->waitq);
29465 for (i = 0; i < IPMI_NUM_STATS; i++)
29466- atomic_set(&intf->stats[i], 0);
29467+ atomic_set_unchecked(&intf->stats[i], 0);
29468
29469 intf->proc_dir = NULL;
29470
29471diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29472index 1e638ff..a869ef5 100644
29473--- a/drivers/char/ipmi/ipmi_si_intf.c
29474+++ b/drivers/char/ipmi/ipmi_si_intf.c
29475@@ -275,7 +275,7 @@ struct smi_info {
29476 unsigned char slave_addr;
29477
29478 /* Counters and things for the proc filesystem. */
29479- atomic_t stats[SI_NUM_STATS];
29480+ atomic_unchecked_t stats[SI_NUM_STATS];
29481
29482 struct task_struct *thread;
29483
29484@@ -284,9 +284,9 @@ struct smi_info {
29485 };
29486
29487 #define smi_inc_stat(smi, stat) \
29488- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29489+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29490 #define smi_get_stat(smi, stat) \
29491- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29492+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29493
29494 #define SI_MAX_PARMS 4
29495
29496@@ -3209,7 +3209,7 @@ static int try_smi_init(struct smi_info *new_smi)
29497 atomic_set(&new_smi->req_events, 0);
29498 new_smi->run_to_completion = 0;
29499 for (i = 0; i < SI_NUM_STATS; i++)
29500- atomic_set(&new_smi->stats[i], 0);
29501+ atomic_set_unchecked(&new_smi->stats[i], 0);
29502
29503 new_smi->interrupt_disabled = 1;
29504 atomic_set(&new_smi->stop_operation, 0);
29505diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29506index 47ff7e4..0c7d340 100644
29507--- a/drivers/char/mbcs.c
29508+++ b/drivers/char/mbcs.c
29509@@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29510 return 0;
29511 }
29512
29513-static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29514+static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29515 {
29516 .part_num = MBCS_PART_NUM,
29517 .mfg_num = MBCS_MFG_NUM,
29518diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29519index d6e9d08..4493e89 100644
29520--- a/drivers/char/mem.c
29521+++ b/drivers/char/mem.c
29522@@ -18,6 +18,7 @@
29523 #include <linux/raw.h>
29524 #include <linux/tty.h>
29525 #include <linux/capability.h>
29526+#include <linux/security.h>
29527 #include <linux/ptrace.h>
29528 #include <linux/device.h>
29529 #include <linux/highmem.h>
29530@@ -35,6 +36,10 @@
29531 # include <linux/efi.h>
29532 #endif
29533
29534+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29535+extern const struct file_operations grsec_fops;
29536+#endif
29537+
29538 static inline unsigned long size_inside_page(unsigned long start,
29539 unsigned long size)
29540 {
29541@@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29542
29543 while (cursor < to) {
29544 if (!devmem_is_allowed(pfn)) {
29545+#ifdef CONFIG_GRKERNSEC_KMEM
29546+ gr_handle_mem_readwrite(from, to);
29547+#else
29548 printk(KERN_INFO
29549 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29550 current->comm, from, to);
29551+#endif
29552 return 0;
29553 }
29554 cursor += PAGE_SIZE;
29555@@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29556 }
29557 return 1;
29558 }
29559+#elif defined(CONFIG_GRKERNSEC_KMEM)
29560+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29561+{
29562+ return 0;
29563+}
29564 #else
29565 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29566 {
29567@@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29568
29569 while (count > 0) {
29570 unsigned long remaining;
29571+ char *temp;
29572
29573 sz = size_inside_page(p, count);
29574
29575@@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29576 if (!ptr)
29577 return -EFAULT;
29578
29579- remaining = copy_to_user(buf, ptr, sz);
29580+#ifdef CONFIG_PAX_USERCOPY
29581+ temp = kmalloc(sz, GFP_KERNEL);
29582+ if (!temp) {
29583+ unxlate_dev_mem_ptr(p, ptr);
29584+ return -ENOMEM;
29585+ }
29586+ memcpy(temp, ptr, sz);
29587+#else
29588+ temp = ptr;
29589+#endif
29590+
29591+ remaining = copy_to_user(buf, temp, sz);
29592+
29593+#ifdef CONFIG_PAX_USERCOPY
29594+ kfree(temp);
29595+#endif
29596+
29597 unxlate_dev_mem_ptr(p, ptr);
29598 if (remaining)
29599 return -EFAULT;
29600@@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29601 size_t count, loff_t *ppos)
29602 {
29603 unsigned long p = *ppos;
29604- ssize_t low_count, read, sz;
29605+ ssize_t low_count, read, sz, err = 0;
29606 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29607- int err = 0;
29608
29609 read = 0;
29610 if (p < (unsigned long) high_memory) {
29611@@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29612 }
29613 #endif
29614 while (low_count > 0) {
29615+ char *temp;
29616+
29617 sz = size_inside_page(p, low_count);
29618
29619 /*
29620@@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29621 */
29622 kbuf = xlate_dev_kmem_ptr((char *)p);
29623
29624- if (copy_to_user(buf, kbuf, sz))
29625+#ifdef CONFIG_PAX_USERCOPY
29626+ temp = kmalloc(sz, GFP_KERNEL);
29627+ if (!temp)
29628+ return -ENOMEM;
29629+ memcpy(temp, kbuf, sz);
29630+#else
29631+ temp = kbuf;
29632+#endif
29633+
29634+ err = copy_to_user(buf, temp, sz);
29635+
29636+#ifdef CONFIG_PAX_USERCOPY
29637+ kfree(temp);
29638+#endif
29639+
29640+ if (err)
29641 return -EFAULT;
29642 buf += sz;
29643 p += sz;
29644@@ -867,6 +914,9 @@ static const struct memdev {
29645 #ifdef CONFIG_CRASH_DUMP
29646 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29647 #endif
29648+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29649+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29650+#endif
29651 };
29652
29653 static int memory_open(struct inode *inode, struct file *filp)
29654diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29655index 9df78e2..01ba9ae 100644
29656--- a/drivers/char/nvram.c
29657+++ b/drivers/char/nvram.c
29658@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29659
29660 spin_unlock_irq(&rtc_lock);
29661
29662- if (copy_to_user(buf, contents, tmp - contents))
29663+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29664 return -EFAULT;
29665
29666 *ppos = i;
29667diff --git a/drivers/char/random.c b/drivers/char/random.c
29668index 4ec04a7..4a092ed 100644
29669--- a/drivers/char/random.c
29670+++ b/drivers/char/random.c
29671@@ -261,8 +261,13 @@
29672 /*
29673 * Configuration information
29674 */
29675+#ifdef CONFIG_GRKERNSEC_RANDNET
29676+#define INPUT_POOL_WORDS 512
29677+#define OUTPUT_POOL_WORDS 128
29678+#else
29679 #define INPUT_POOL_WORDS 128
29680 #define OUTPUT_POOL_WORDS 32
29681+#endif
29682 #define SEC_XFER_SIZE 512
29683 #define EXTRACT_SIZE 10
29684
29685@@ -300,10 +305,17 @@ static struct poolinfo {
29686 int poolwords;
29687 int tap1, tap2, tap3, tap4, tap5;
29688 } poolinfo_table[] = {
29689+#ifdef CONFIG_GRKERNSEC_RANDNET
29690+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29691+ { 512, 411, 308, 208, 104, 1 },
29692+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29693+ { 128, 103, 76, 51, 25, 1 },
29694+#else
29695 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29696 { 128, 103, 76, 51, 25, 1 },
29697 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29698 { 32, 26, 20, 14, 7, 1 },
29699+#endif
29700 #if 0
29701 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29702 { 2048, 1638, 1231, 819, 411, 1 },
29703@@ -913,7 +925,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29704
29705 extract_buf(r, tmp);
29706 i = min_t(int, nbytes, EXTRACT_SIZE);
29707- if (copy_to_user(buf, tmp, i)) {
29708+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29709 ret = -EFAULT;
29710 break;
29711 }
29712@@ -1238,7 +1250,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29713 #include <linux/sysctl.h>
29714
29715 static int min_read_thresh = 8, min_write_thresh;
29716-static int max_read_thresh = INPUT_POOL_WORDS * 32;
29717+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29718 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29719 static char sysctl_bootid[16];
29720
29721diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
29722index 45713f0..8286d21 100644
29723--- a/drivers/char/sonypi.c
29724+++ b/drivers/char/sonypi.c
29725@@ -54,6 +54,7 @@
29726
29727 #include <asm/uaccess.h>
29728 #include <asm/io.h>
29729+#include <asm/local.h>
29730
29731 #include <linux/sonypi.h>
29732
29733@@ -490,7 +491,7 @@ static struct sonypi_device {
29734 spinlock_t fifo_lock;
29735 wait_queue_head_t fifo_proc_list;
29736 struct fasync_struct *fifo_async;
29737- int open_count;
29738+ local_t open_count;
29739 int model;
29740 struct input_dev *input_jog_dev;
29741 struct input_dev *input_key_dev;
29742@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
29743 static int sonypi_misc_release(struct inode *inode, struct file *file)
29744 {
29745 mutex_lock(&sonypi_device.lock);
29746- sonypi_device.open_count--;
29747+ local_dec(&sonypi_device.open_count);
29748 mutex_unlock(&sonypi_device.lock);
29749 return 0;
29750 }
29751@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
29752 {
29753 mutex_lock(&sonypi_device.lock);
29754 /* Flush input queue on first open */
29755- if (!sonypi_device.open_count)
29756+ if (!local_read(&sonypi_device.open_count))
29757 kfifo_reset(&sonypi_device.fifo);
29758- sonypi_device.open_count++;
29759+ local_inc(&sonypi_device.open_count);
29760 mutex_unlock(&sonypi_device.lock);
29761
29762 return 0;
29763diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
29764index ad7c732..5aa8054 100644
29765--- a/drivers/char/tpm/tpm.c
29766+++ b/drivers/char/tpm/tpm.c
29767@@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
29768 chip->vendor.req_complete_val)
29769 goto out_recv;
29770
29771- if ((status == chip->vendor.req_canceled)) {
29772+ if (status == chip->vendor.req_canceled) {
29773 dev_err(chip->dev, "Operation Canceled\n");
29774 rc = -ECANCELED;
29775 goto out;
29776diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
29777index 0636520..169c1d0 100644
29778--- a/drivers/char/tpm/tpm_bios.c
29779+++ b/drivers/char/tpm/tpm_bios.c
29780@@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
29781 event = addr;
29782
29783 if ((event->event_type == 0 && event->event_size == 0) ||
29784- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
29785+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
29786 return NULL;
29787
29788 return addr;
29789@@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
29790 return NULL;
29791
29792 if ((event->event_type == 0 && event->event_size == 0) ||
29793- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
29794+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
29795 return NULL;
29796
29797 (*pos)++;
29798@@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
29799 int i;
29800
29801 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
29802- seq_putc(m, data[i]);
29803+ if (!seq_putc(m, data[i]))
29804+ return -EFAULT;
29805
29806 return 0;
29807 }
29808@@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
29809 log->bios_event_log_end = log->bios_event_log + len;
29810
29811 virt = acpi_os_map_memory(start, len);
29812+ if (!virt) {
29813+ kfree(log->bios_event_log);
29814+ log->bios_event_log = NULL;
29815+ return -EFAULT;
29816+ }
29817
29818- memcpy(log->bios_event_log, virt, len);
29819+ memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
29820
29821 acpi_os_unmap_memory(virt, len);
29822 return 0;
29823diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
29824index cdf2f54..e55c197 100644
29825--- a/drivers/char/virtio_console.c
29826+++ b/drivers/char/virtio_console.c
29827@@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
29828 if (to_user) {
29829 ssize_t ret;
29830
29831- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
29832+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
29833 if (ret)
29834 return -EFAULT;
29835 } else {
29836@@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
29837 if (!port_has_data(port) && !port->host_connected)
29838 return 0;
29839
29840- return fill_readbuf(port, ubuf, count, true);
29841+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
29842 }
29843
29844 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
29845diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
29846index 97f5064..202b6e6 100644
29847--- a/drivers/edac/edac_pci_sysfs.c
29848+++ b/drivers/edac/edac_pci_sysfs.c
29849@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
29850 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
29851 static int edac_pci_poll_msec = 1000; /* one second workq period */
29852
29853-static atomic_t pci_parity_count = ATOMIC_INIT(0);
29854-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
29855+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
29856+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
29857
29858 static struct kobject *edac_pci_top_main_kobj;
29859 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
29860@@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29861 edac_printk(KERN_CRIT, EDAC_PCI,
29862 "Signaled System Error on %s\n",
29863 pci_name(dev));
29864- atomic_inc(&pci_nonparity_count);
29865+ atomic_inc_unchecked(&pci_nonparity_count);
29866 }
29867
29868 if (status & (PCI_STATUS_PARITY)) {
29869@@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29870 "Master Data Parity Error on %s\n",
29871 pci_name(dev));
29872
29873- atomic_inc(&pci_parity_count);
29874+ atomic_inc_unchecked(&pci_parity_count);
29875 }
29876
29877 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29878@@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29879 "Detected Parity Error on %s\n",
29880 pci_name(dev));
29881
29882- atomic_inc(&pci_parity_count);
29883+ atomic_inc_unchecked(&pci_parity_count);
29884 }
29885 }
29886
29887@@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29888 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
29889 "Signaled System Error on %s\n",
29890 pci_name(dev));
29891- atomic_inc(&pci_nonparity_count);
29892+ atomic_inc_unchecked(&pci_nonparity_count);
29893 }
29894
29895 if (status & (PCI_STATUS_PARITY)) {
29896@@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29897 "Master Data Parity Error on "
29898 "%s\n", pci_name(dev));
29899
29900- atomic_inc(&pci_parity_count);
29901+ atomic_inc_unchecked(&pci_parity_count);
29902 }
29903
29904 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29905@@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29906 "Detected Parity Error on %s\n",
29907 pci_name(dev));
29908
29909- atomic_inc(&pci_parity_count);
29910+ atomic_inc_unchecked(&pci_parity_count);
29911 }
29912 }
29913 }
29914@@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
29915 if (!check_pci_errors)
29916 return;
29917
29918- before_count = atomic_read(&pci_parity_count);
29919+ before_count = atomic_read_unchecked(&pci_parity_count);
29920
29921 /* scan all PCI devices looking for a Parity Error on devices and
29922 * bridges.
29923@@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
29924 /* Only if operator has selected panic on PCI Error */
29925 if (edac_pci_get_panic_on_pe()) {
29926 /* If the count is different 'after' from 'before' */
29927- if (before_count != atomic_read(&pci_parity_count))
29928+ if (before_count != atomic_read_unchecked(&pci_parity_count))
29929 panic("EDAC: PCI Parity Error");
29930 }
29931 }
29932diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
29933index c6074c5..88a9e2e 100644
29934--- a/drivers/edac/mce_amd.h
29935+++ b/drivers/edac/mce_amd.h
29936@@ -82,7 +82,7 @@ extern const char * const ii_msgs[];
29937 struct amd_decoder_ops {
29938 bool (*dc_mce)(u16, u8);
29939 bool (*ic_mce)(u16, u8);
29940-};
29941+} __no_const;
29942
29943 void amd_report_gart_errors(bool);
29944 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
29945diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
29946index cc595eb..4ec702a 100644
29947--- a/drivers/firewire/core-card.c
29948+++ b/drivers/firewire/core-card.c
29949@@ -679,7 +679,7 @@ void fw_card_release(struct kref *kref)
29950
29951 void fw_core_remove_card(struct fw_card *card)
29952 {
29953- struct fw_card_driver dummy_driver = dummy_driver_template;
29954+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
29955
29956 card->driver->update_phy_reg(card, 4,
29957 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
29958diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
29959index 2e6b245..c3857d9 100644
29960--- a/drivers/firewire/core-cdev.c
29961+++ b/drivers/firewire/core-cdev.c
29962@@ -1341,8 +1341,7 @@ static int init_iso_resource(struct client *client,
29963 int ret;
29964
29965 if ((request->channels == 0 && request->bandwidth == 0) ||
29966- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
29967- request->bandwidth < 0)
29968+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
29969 return -EINVAL;
29970
29971 r = kmalloc(sizeof(*r), GFP_KERNEL);
29972diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
29973index dea2dcc..a4fb978 100644
29974--- a/drivers/firewire/core-transaction.c
29975+++ b/drivers/firewire/core-transaction.c
29976@@ -37,6 +37,7 @@
29977 #include <linux/timer.h>
29978 #include <linux/types.h>
29979 #include <linux/workqueue.h>
29980+#include <linux/sched.h>
29981
29982 #include <asm/byteorder.h>
29983
29984diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
29985index 9047f55..e47c7ff 100644
29986--- a/drivers/firewire/core.h
29987+++ b/drivers/firewire/core.h
29988@@ -110,6 +110,7 @@ struct fw_card_driver {
29989
29990 int (*stop_iso)(struct fw_iso_context *ctx);
29991 };
29992+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
29993
29994 void fw_card_initialize(struct fw_card *card,
29995 const struct fw_card_driver *driver, struct device *device);
29996diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
29997index 153980b..4b4d046 100644
29998--- a/drivers/firmware/dmi_scan.c
29999+++ b/drivers/firmware/dmi_scan.c
30000@@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
30001 }
30002 }
30003 else {
30004- /*
30005- * no iounmap() for that ioremap(); it would be a no-op, but
30006- * it's so early in setup that sucker gets confused into doing
30007- * what it shouldn't if we actually call it.
30008- */
30009 p = dmi_ioremap(0xF0000, 0x10000);
30010 if (p == NULL)
30011 goto error;
30012@@ -723,7 +718,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30013 if (buf == NULL)
30014 return -1;
30015
30016- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30017+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30018
30019 iounmap(buf);
30020 return 0;
30021diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30022index 82d5c20..44a7177 100644
30023--- a/drivers/gpio/gpio-vr41xx.c
30024+++ b/drivers/gpio/gpio-vr41xx.c
30025@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30026 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30027 maskl, pendl, maskh, pendh);
30028
30029- atomic_inc(&irq_err_count);
30030+ atomic_inc_unchecked(&irq_err_count);
30031
30032 return -EINVAL;
30033 }
30034diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30035index 8111889..367b253 100644
30036--- a/drivers/gpu/drm/drm_crtc_helper.c
30037+++ b/drivers/gpu/drm/drm_crtc_helper.c
30038@@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30039 struct drm_crtc *tmp;
30040 int crtc_mask = 1;
30041
30042- WARN(!crtc, "checking null crtc?\n");
30043+ BUG_ON(!crtc);
30044
30045 dev = crtc->dev;
30046
30047diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30048index 6116e3b..c29dd16 100644
30049--- a/drivers/gpu/drm/drm_drv.c
30050+++ b/drivers/gpu/drm/drm_drv.c
30051@@ -316,7 +316,7 @@ module_exit(drm_core_exit);
30052 /**
30053 * Copy and IOCTL return string to user space
30054 */
30055-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30056+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30057 {
30058 int len;
30059
30060@@ -399,7 +399,7 @@ long drm_ioctl(struct file *filp,
30061 return -ENODEV;
30062
30063 atomic_inc(&dev->ioctl_count);
30064- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30065+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30066 ++file_priv->ioctl_count;
30067
30068 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30069diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30070index 123de28..43a0897 100644
30071--- a/drivers/gpu/drm/drm_fops.c
30072+++ b/drivers/gpu/drm/drm_fops.c
30073@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30074 }
30075
30076 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30077- atomic_set(&dev->counts[i], 0);
30078+ atomic_set_unchecked(&dev->counts[i], 0);
30079
30080 dev->sigdata.lock = NULL;
30081
30082@@ -138,8 +138,8 @@ int drm_open(struct inode *inode, struct file *filp)
30083
30084 retcode = drm_open_helper(inode, filp, dev);
30085 if (!retcode) {
30086- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30087- if (!dev->open_count++)
30088+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30089+ if (local_inc_return(&dev->open_count) == 1)
30090 retcode = drm_setup(dev);
30091 }
30092 if (!retcode) {
30093@@ -482,7 +482,7 @@ int drm_release(struct inode *inode, struct file *filp)
30094
30095 mutex_lock(&drm_global_mutex);
30096
30097- DRM_DEBUG("open_count = %d\n", dev->open_count);
30098+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30099
30100 if (dev->driver->preclose)
30101 dev->driver->preclose(dev, file_priv);
30102@@ -491,10 +491,10 @@ int drm_release(struct inode *inode, struct file *filp)
30103 * Begin inline drm_release
30104 */
30105
30106- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30107+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30108 task_pid_nr(current),
30109 (long)old_encode_dev(file_priv->minor->device),
30110- dev->open_count);
30111+ local_read(&dev->open_count));
30112
30113 /* Release any auth tokens that might point to this file_priv,
30114 (do that under the drm_global_mutex) */
30115@@ -584,8 +584,8 @@ int drm_release(struct inode *inode, struct file *filp)
30116 * End inline drm_release
30117 */
30118
30119- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30120- if (!--dev->open_count) {
30121+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30122+ if (local_dec_and_test(&dev->open_count)) {
30123 if (atomic_read(&dev->ioctl_count)) {
30124 DRM_ERROR("Device busy: %d\n",
30125 atomic_read(&dev->ioctl_count));
30126diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30127index c87dc96..326055d 100644
30128--- a/drivers/gpu/drm/drm_global.c
30129+++ b/drivers/gpu/drm/drm_global.c
30130@@ -36,7 +36,7 @@
30131 struct drm_global_item {
30132 struct mutex mutex;
30133 void *object;
30134- int refcount;
30135+ atomic_t refcount;
30136 };
30137
30138 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30139@@ -49,7 +49,7 @@ void drm_global_init(void)
30140 struct drm_global_item *item = &glob[i];
30141 mutex_init(&item->mutex);
30142 item->object = NULL;
30143- item->refcount = 0;
30144+ atomic_set(&item->refcount, 0);
30145 }
30146 }
30147
30148@@ -59,7 +59,7 @@ void drm_global_release(void)
30149 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30150 struct drm_global_item *item = &glob[i];
30151 BUG_ON(item->object != NULL);
30152- BUG_ON(item->refcount != 0);
30153+ BUG_ON(atomic_read(&item->refcount) != 0);
30154 }
30155 }
30156
30157@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30158 void *object;
30159
30160 mutex_lock(&item->mutex);
30161- if (item->refcount == 0) {
30162+ if (atomic_read(&item->refcount) == 0) {
30163 item->object = kzalloc(ref->size, GFP_KERNEL);
30164 if (unlikely(item->object == NULL)) {
30165 ret = -ENOMEM;
30166@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30167 goto out_err;
30168
30169 }
30170- ++item->refcount;
30171+ atomic_inc(&item->refcount);
30172 ref->object = item->object;
30173 object = item->object;
30174 mutex_unlock(&item->mutex);
30175@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30176 struct drm_global_item *item = &glob[ref->global_type];
30177
30178 mutex_lock(&item->mutex);
30179- BUG_ON(item->refcount == 0);
30180+ BUG_ON(atomic_read(&item->refcount) == 0);
30181 BUG_ON(ref->object != item->object);
30182- if (--item->refcount == 0) {
30183+ if (atomic_dec_and_test(&item->refcount)) {
30184 ref->release(ref);
30185 item->object = NULL;
30186 }
30187diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30188index ab1162d..42587b2 100644
30189--- a/drivers/gpu/drm/drm_info.c
30190+++ b/drivers/gpu/drm/drm_info.c
30191@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30192 struct drm_local_map *map;
30193 struct drm_map_list *r_list;
30194
30195- /* Hardcoded from _DRM_FRAME_BUFFER,
30196- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30197- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30198- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30199+ static const char * const types[] = {
30200+ [_DRM_FRAME_BUFFER] = "FB",
30201+ [_DRM_REGISTERS] = "REG",
30202+ [_DRM_SHM] = "SHM",
30203+ [_DRM_AGP] = "AGP",
30204+ [_DRM_SCATTER_GATHER] = "SG",
30205+ [_DRM_CONSISTENT] = "PCI",
30206+ [_DRM_GEM] = "GEM" };
30207 const char *type;
30208 int i;
30209
30210@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30211 map = r_list->map;
30212 if (!map)
30213 continue;
30214- if (map->type < 0 || map->type > 5)
30215+ if (map->type >= ARRAY_SIZE(types))
30216 type = "??";
30217 else
30218 type = types[map->type];
30219@@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30220 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30221 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30222 vma->vm_flags & VM_IO ? 'i' : '-',
30223+#ifdef CONFIG_GRKERNSEC_HIDESYM
30224+ 0);
30225+#else
30226 vma->vm_pgoff);
30227+#endif
30228
30229 #if defined(__i386__)
30230 pgprot = pgprot_val(vma->vm_page_prot);
30231diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30232index 637fcc3..e890b33 100644
30233--- a/drivers/gpu/drm/drm_ioc32.c
30234+++ b/drivers/gpu/drm/drm_ioc32.c
30235@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30236 request = compat_alloc_user_space(nbytes);
30237 if (!access_ok(VERIFY_WRITE, request, nbytes))
30238 return -EFAULT;
30239- list = (struct drm_buf_desc *) (request + 1);
30240+ list = (struct drm_buf_desc __user *) (request + 1);
30241
30242 if (__put_user(count, &request->count)
30243 || __put_user(list, &request->list))
30244@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30245 request = compat_alloc_user_space(nbytes);
30246 if (!access_ok(VERIFY_WRITE, request, nbytes))
30247 return -EFAULT;
30248- list = (struct drm_buf_pub *) (request + 1);
30249+ list = (struct drm_buf_pub __user *) (request + 1);
30250
30251 if (__put_user(count, &request->count)
30252 || __put_user(list, &request->list))
30253diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30254index cf85155..f2665cb 100644
30255--- a/drivers/gpu/drm/drm_ioctl.c
30256+++ b/drivers/gpu/drm/drm_ioctl.c
30257@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30258 stats->data[i].value =
30259 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30260 else
30261- stats->data[i].value = atomic_read(&dev->counts[i]);
30262+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30263 stats->data[i].type = dev->types[i];
30264 }
30265
30266diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30267index c79c713..2048588 100644
30268--- a/drivers/gpu/drm/drm_lock.c
30269+++ b/drivers/gpu/drm/drm_lock.c
30270@@ -90,7 +90,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30271 if (drm_lock_take(&master->lock, lock->context)) {
30272 master->lock.file_priv = file_priv;
30273 master->lock.lock_time = jiffies;
30274- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30275+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30276 break; /* Got lock */
30277 }
30278
30279@@ -161,7 +161,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30280 return -EINVAL;
30281 }
30282
30283- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30284+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30285
30286 if (drm_lock_free(&master->lock, lock->context)) {
30287 /* FIXME: Should really bail out here. */
30288diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30289index aa454f8..6d38580 100644
30290--- a/drivers/gpu/drm/drm_stub.c
30291+++ b/drivers/gpu/drm/drm_stub.c
30292@@ -512,7 +512,7 @@ void drm_unplug_dev(struct drm_device *dev)
30293
30294 drm_device_set_unplugged(dev);
30295
30296- if (dev->open_count == 0) {
30297+ if (local_read(&dev->open_count) == 0) {
30298 drm_put_dev(dev);
30299 }
30300 mutex_unlock(&drm_global_mutex);
30301diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30302index f920fb5..001c52d 100644
30303--- a/drivers/gpu/drm/i810/i810_dma.c
30304+++ b/drivers/gpu/drm/i810/i810_dma.c
30305@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30306 dma->buflist[vertex->idx],
30307 vertex->discard, vertex->used);
30308
30309- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30310- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30311+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30312+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30313 sarea_priv->last_enqueue = dev_priv->counter - 1;
30314 sarea_priv->last_dispatch = (int)hw_status[5];
30315
30316@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30317 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30318 mc->last_render);
30319
30320- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30321- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30322+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30323+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30324 sarea_priv->last_enqueue = dev_priv->counter - 1;
30325 sarea_priv->last_dispatch = (int)hw_status[5];
30326
30327diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30328index c9339f4..f5e1b9d 100644
30329--- a/drivers/gpu/drm/i810/i810_drv.h
30330+++ b/drivers/gpu/drm/i810/i810_drv.h
30331@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30332 int page_flipping;
30333
30334 wait_queue_head_t irq_queue;
30335- atomic_t irq_received;
30336- atomic_t irq_emitted;
30337+ atomic_unchecked_t irq_received;
30338+ atomic_unchecked_t irq_emitted;
30339
30340 int front_offset;
30341 } drm_i810_private_t;
30342diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30343index e6162a1..b2ff486 100644
30344--- a/drivers/gpu/drm/i915/i915_debugfs.c
30345+++ b/drivers/gpu/drm/i915/i915_debugfs.c
30346@@ -500,7 +500,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30347 I915_READ(GTIMR));
30348 }
30349 seq_printf(m, "Interrupts received: %d\n",
30350- atomic_read(&dev_priv->irq_received));
30351+ atomic_read_unchecked(&dev_priv->irq_received));
30352 for (i = 0; i < I915_NUM_RINGS; i++) {
30353 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30354 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30355@@ -1313,7 +1313,7 @@ static int i915_opregion(struct seq_file *m, void *unused)
30356 return ret;
30357
30358 if (opregion->header)
30359- seq_write(m, opregion->header, OPREGION_SIZE);
30360+ seq_write(m, (const void __force_kernel *)opregion->header, OPREGION_SIZE);
30361
30362 mutex_unlock(&dev->struct_mutex);
30363
30364diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30365index ba60f3c..e2dff7f 100644
30366--- a/drivers/gpu/drm/i915/i915_dma.c
30367+++ b/drivers/gpu/drm/i915/i915_dma.c
30368@@ -1178,7 +1178,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30369 bool can_switch;
30370
30371 spin_lock(&dev->count_lock);
30372- can_switch = (dev->open_count == 0);
30373+ can_switch = (local_read(&dev->open_count) == 0);
30374 spin_unlock(&dev->count_lock);
30375 return can_switch;
30376 }
30377diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30378index 5fabc6c..0b08aa1 100644
30379--- a/drivers/gpu/drm/i915/i915_drv.h
30380+++ b/drivers/gpu/drm/i915/i915_drv.h
30381@@ -240,7 +240,7 @@ struct drm_i915_display_funcs {
30382 /* render clock increase/decrease */
30383 /* display clock increase/decrease */
30384 /* pll clock increase/decrease */
30385-};
30386+} __no_const;
30387
30388 struct intel_device_info {
30389 u8 gen;
30390@@ -350,7 +350,7 @@ typedef struct drm_i915_private {
30391 int current_page;
30392 int page_flipping;
30393
30394- atomic_t irq_received;
30395+ atomic_unchecked_t irq_received;
30396
30397 /* protects the irq masks */
30398 spinlock_t irq_lock;
30399@@ -937,7 +937,7 @@ struct drm_i915_gem_object {
30400 * will be page flipped away on the next vblank. When it
30401 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30402 */
30403- atomic_t pending_flip;
30404+ atomic_unchecked_t pending_flip;
30405 };
30406
30407 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30408@@ -1359,7 +1359,7 @@ extern int intel_setup_gmbus(struct drm_device *dev);
30409 extern void intel_teardown_gmbus(struct drm_device *dev);
30410 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30411 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30412-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30413+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30414 {
30415 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30416 }
30417diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30418index de43194..a14c4cc 100644
30419--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30420+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30421@@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30422 i915_gem_clflush_object(obj);
30423
30424 if (obj->base.pending_write_domain)
30425- cd->flips |= atomic_read(&obj->pending_flip);
30426+ cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30427
30428 /* The actual obj->write_domain will be updated with
30429 * pending_write_domain after we emit the accumulated flush for all
30430@@ -933,9 +933,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30431
30432 static int
30433 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30434- int count)
30435+ unsigned int count)
30436 {
30437- int i;
30438+ unsigned int i;
30439
30440 for (i = 0; i < count; i++) {
30441 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30442diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30443index f57e5cf..c82f79d 100644
30444--- a/drivers/gpu/drm/i915/i915_irq.c
30445+++ b/drivers/gpu/drm/i915/i915_irq.c
30446@@ -472,7 +472,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30447 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30448 struct drm_i915_master_private *master_priv;
30449
30450- atomic_inc(&dev_priv->irq_received);
30451+ atomic_inc_unchecked(&dev_priv->irq_received);
30452
30453 /* disable master interrupt before clearing iir */
30454 de_ier = I915_READ(DEIER);
30455@@ -563,7 +563,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30456 struct drm_i915_master_private *master_priv;
30457 u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT;
30458
30459- atomic_inc(&dev_priv->irq_received);
30460+ atomic_inc_unchecked(&dev_priv->irq_received);
30461
30462 if (IS_GEN6(dev))
30463 bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT;
30464@@ -1292,7 +1292,7 @@ static irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
30465 int ret = IRQ_NONE, pipe;
30466 bool blc_event = false;
30467
30468- atomic_inc(&dev_priv->irq_received);
30469+ atomic_inc_unchecked(&dev_priv->irq_received);
30470
30471 iir = I915_READ(IIR);
30472
30473@@ -1803,7 +1803,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30474 {
30475 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30476
30477- atomic_set(&dev_priv->irq_received, 0);
30478+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30479
30480 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
30481 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
30482@@ -1980,7 +1980,7 @@ static void i915_driver_irq_preinstall(struct drm_device * dev)
30483 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30484 int pipe;
30485
30486- atomic_set(&dev_priv->irq_received, 0);
30487+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30488
30489 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
30490 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
30491diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30492index d4d162f..e80037c 100644
30493--- a/drivers/gpu/drm/i915/intel_display.c
30494+++ b/drivers/gpu/drm/i915/intel_display.c
30495@@ -2254,7 +2254,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
30496
30497 wait_event(dev_priv->pending_flip_queue,
30498 atomic_read(&dev_priv->mm.wedged) ||
30499- atomic_read(&obj->pending_flip) == 0);
30500+ atomic_read_unchecked(&obj->pending_flip) == 0);
30501
30502 /* Big Hammer, we also need to ensure that any pending
30503 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30504@@ -2919,7 +2919,7 @@ static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
30505 obj = to_intel_framebuffer(crtc->fb)->obj;
30506 dev_priv = crtc->dev->dev_private;
30507 wait_event(dev_priv->pending_flip_queue,
30508- atomic_read(&obj->pending_flip) == 0);
30509+ atomic_read_unchecked(&obj->pending_flip) == 0);
30510 }
30511
30512 static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
30513@@ -7286,7 +7286,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30514
30515 atomic_clear_mask(1 << intel_crtc->plane,
30516 &obj->pending_flip.counter);
30517- if (atomic_read(&obj->pending_flip) == 0)
30518+ if (atomic_read_unchecked(&obj->pending_flip) == 0)
30519 wake_up(&dev_priv->pending_flip_queue);
30520
30521 schedule_work(&work->work);
30522@@ -7582,7 +7582,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30523 /* Block clients from rendering to the new back buffer until
30524 * the flip occurs and the object is no longer visible.
30525 */
30526- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30527+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30528
30529 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30530 if (ret)
30531@@ -7596,7 +7596,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30532 return 0;
30533
30534 cleanup_pending:
30535- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30536+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30537 drm_gem_object_unreference(&work->old_fb_obj->base);
30538 drm_gem_object_unreference(&obj->base);
30539 mutex_unlock(&dev->struct_mutex);
30540diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30541index 54558a0..2d97005 100644
30542--- a/drivers/gpu/drm/mga/mga_drv.h
30543+++ b/drivers/gpu/drm/mga/mga_drv.h
30544@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30545 u32 clear_cmd;
30546 u32 maccess;
30547
30548- atomic_t vbl_received; /**< Number of vblanks received. */
30549+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30550 wait_queue_head_t fence_queue;
30551- atomic_t last_fence_retired;
30552+ atomic_unchecked_t last_fence_retired;
30553 u32 next_fence_to_post;
30554
30555 unsigned int fb_cpp;
30556diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30557index 2581202..f230a8d9 100644
30558--- a/drivers/gpu/drm/mga/mga_irq.c
30559+++ b/drivers/gpu/drm/mga/mga_irq.c
30560@@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30561 if (crtc != 0)
30562 return 0;
30563
30564- return atomic_read(&dev_priv->vbl_received);
30565+ return atomic_read_unchecked(&dev_priv->vbl_received);
30566 }
30567
30568
30569@@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30570 /* VBLANK interrupt */
30571 if (status & MGA_VLINEPEN) {
30572 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30573- atomic_inc(&dev_priv->vbl_received);
30574+ atomic_inc_unchecked(&dev_priv->vbl_received);
30575 drm_handle_vblank(dev, 0);
30576 handled = 1;
30577 }
30578@@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30579 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30580 MGA_WRITE(MGA_PRIMEND, prim_end);
30581
30582- atomic_inc(&dev_priv->last_fence_retired);
30583+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
30584 DRM_WAKEUP(&dev_priv->fence_queue);
30585 handled = 1;
30586 }
30587@@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30588 * using fences.
30589 */
30590 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30591- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30592+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30593 - *sequence) <= (1 << 23)));
30594
30595 *sequence = cur_fence;
30596diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30597index 0be4a81..7464804 100644
30598--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30599+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30600@@ -5329,7 +5329,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30601 struct bit_table {
30602 const char id;
30603 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30604-};
30605+} __no_const;
30606
30607 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30608
30609diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30610index 3aef353..0ad1322 100644
30611--- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30612+++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30613@@ -240,7 +240,7 @@ struct nouveau_channel {
30614 struct list_head pending;
30615 uint32_t sequence;
30616 uint32_t sequence_ack;
30617- atomic_t last_sequence_irq;
30618+ atomic_unchecked_t last_sequence_irq;
30619 struct nouveau_vma vma;
30620 } fence;
30621
30622@@ -321,7 +321,7 @@ struct nouveau_exec_engine {
30623 u32 handle, u16 class);
30624 void (*set_tile_region)(struct drm_device *dev, int i);
30625 void (*tlb_flush)(struct drm_device *, int engine);
30626-};
30627+} __no_const;
30628
30629 struct nouveau_instmem_engine {
30630 void *priv;
30631@@ -343,13 +343,13 @@ struct nouveau_instmem_engine {
30632 struct nouveau_mc_engine {
30633 int (*init)(struct drm_device *dev);
30634 void (*takedown)(struct drm_device *dev);
30635-};
30636+} __no_const;
30637
30638 struct nouveau_timer_engine {
30639 int (*init)(struct drm_device *dev);
30640 void (*takedown)(struct drm_device *dev);
30641 uint64_t (*read)(struct drm_device *dev);
30642-};
30643+} __no_const;
30644
30645 struct nouveau_fb_engine {
30646 int num_tiles;
30647@@ -590,7 +590,7 @@ struct nouveau_vram_engine {
30648 void (*put)(struct drm_device *, struct nouveau_mem **);
30649
30650 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30651-};
30652+} __no_const;
30653
30654 struct nouveau_engine {
30655 struct nouveau_instmem_engine instmem;
30656@@ -739,7 +739,7 @@ struct drm_nouveau_private {
30657 struct drm_global_reference mem_global_ref;
30658 struct ttm_bo_global_ref bo_global_ref;
30659 struct ttm_bo_device bdev;
30660- atomic_t validate_sequence;
30661+ atomic_unchecked_t validate_sequence;
30662 } ttm;
30663
30664 struct {
30665diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
30666index c1dc20f..4df673c 100644
30667--- a/drivers/gpu/drm/nouveau/nouveau_fence.c
30668+++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
30669@@ -85,7 +85,7 @@ nouveau_fence_update(struct nouveau_channel *chan)
30670 if (USE_REFCNT(dev))
30671 sequence = nvchan_rd32(chan, 0x48);
30672 else
30673- sequence = atomic_read(&chan->fence.last_sequence_irq);
30674+ sequence = atomic_read_unchecked(&chan->fence.last_sequence_irq);
30675
30676 if (chan->fence.sequence_ack == sequence)
30677 goto out;
30678@@ -538,7 +538,7 @@ nouveau_fence_channel_init(struct nouveau_channel *chan)
30679 return ret;
30680 }
30681
30682- atomic_set(&chan->fence.last_sequence_irq, 0);
30683+ atomic_set_unchecked(&chan->fence.last_sequence_irq, 0);
30684 return 0;
30685 }
30686
30687diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30688index ed52a6f..484acdc 100644
30689--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30690+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30691@@ -314,7 +314,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30692 int trycnt = 0;
30693 int ret, i;
30694
30695- sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30696+ sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30697 retry:
30698 if (++trycnt > 100000) {
30699 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30700diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30701index c2a8511..4b996f9 100644
30702--- a/drivers/gpu/drm/nouveau/nouveau_state.c
30703+++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30704@@ -588,7 +588,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30705 bool can_switch;
30706
30707 spin_lock(&dev->count_lock);
30708- can_switch = (dev->open_count == 0);
30709+ can_switch = (local_read(&dev->open_count) == 0);
30710 spin_unlock(&dev->count_lock);
30711 return can_switch;
30712 }
30713diff --git a/drivers/gpu/drm/nouveau/nv04_graph.c b/drivers/gpu/drm/nouveau/nv04_graph.c
30714index dbdea8e..cd6eeeb 100644
30715--- a/drivers/gpu/drm/nouveau/nv04_graph.c
30716+++ b/drivers/gpu/drm/nouveau/nv04_graph.c
30717@@ -554,7 +554,7 @@ static int
30718 nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
30719 u32 class, u32 mthd, u32 data)
30720 {
30721- atomic_set(&chan->fence.last_sequence_irq, data);
30722+ atomic_set_unchecked(&chan->fence.last_sequence_irq, data);
30723 return 0;
30724 }
30725
30726diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
30727index 2746402..c8dc4a4 100644
30728--- a/drivers/gpu/drm/nouveau/nv50_sor.c
30729+++ b/drivers/gpu/drm/nouveau/nv50_sor.c
30730@@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
30731 }
30732
30733 if (nv_encoder->dcb->type == OUTPUT_DP) {
30734- struct dp_train_func func = {
30735+ static struct dp_train_func func = {
30736 .link_set = nv50_sor_dp_link_set,
30737 .train_set = nv50_sor_dp_train_set,
30738 .train_adj = nv50_sor_dp_train_adj
30739diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
30740index 0247250..d2f6aaf 100644
30741--- a/drivers/gpu/drm/nouveau/nvd0_display.c
30742+++ b/drivers/gpu/drm/nouveau/nvd0_display.c
30743@@ -1366,7 +1366,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
30744 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
30745
30746 if (nv_encoder->dcb->type == OUTPUT_DP) {
30747- struct dp_train_func func = {
30748+ static struct dp_train_func func = {
30749 .link_set = nvd0_sor_dp_link_set,
30750 .train_set = nvd0_sor_dp_train_set,
30751 .train_adj = nvd0_sor_dp_train_adj
30752diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
30753index bcac90b..53bfc76 100644
30754--- a/drivers/gpu/drm/r128/r128_cce.c
30755+++ b/drivers/gpu/drm/r128/r128_cce.c
30756@@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
30757
30758 /* GH: Simple idle check.
30759 */
30760- atomic_set(&dev_priv->idle_count, 0);
30761+ atomic_set_unchecked(&dev_priv->idle_count, 0);
30762
30763 /* We don't support anything other than bus-mastering ring mode,
30764 * but the ring can be in either AGP or PCI space for the ring
30765diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
30766index 930c71b..499aded 100644
30767--- a/drivers/gpu/drm/r128/r128_drv.h
30768+++ b/drivers/gpu/drm/r128/r128_drv.h
30769@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
30770 int is_pci;
30771 unsigned long cce_buffers_offset;
30772
30773- atomic_t idle_count;
30774+ atomic_unchecked_t idle_count;
30775
30776 int page_flipping;
30777 int current_page;
30778 u32 crtc_offset;
30779 u32 crtc_offset_cntl;
30780
30781- atomic_t vbl_received;
30782+ atomic_unchecked_t vbl_received;
30783
30784 u32 color_fmt;
30785 unsigned int front_offset;
30786diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
30787index 429d5a0..7e899ed 100644
30788--- a/drivers/gpu/drm/r128/r128_irq.c
30789+++ b/drivers/gpu/drm/r128/r128_irq.c
30790@@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
30791 if (crtc != 0)
30792 return 0;
30793
30794- return atomic_read(&dev_priv->vbl_received);
30795+ return atomic_read_unchecked(&dev_priv->vbl_received);
30796 }
30797
30798 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30799@@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30800 /* VBLANK interrupt */
30801 if (status & R128_CRTC_VBLANK_INT) {
30802 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
30803- atomic_inc(&dev_priv->vbl_received);
30804+ atomic_inc_unchecked(&dev_priv->vbl_received);
30805 drm_handle_vblank(dev, 0);
30806 return IRQ_HANDLED;
30807 }
30808diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
30809index a9e33ce..09edd4b 100644
30810--- a/drivers/gpu/drm/r128/r128_state.c
30811+++ b/drivers/gpu/drm/r128/r128_state.c
30812@@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
30813
30814 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
30815 {
30816- if (atomic_read(&dev_priv->idle_count) == 0)
30817+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
30818 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
30819 else
30820- atomic_set(&dev_priv->idle_count, 0);
30821+ atomic_set_unchecked(&dev_priv->idle_count, 0);
30822 }
30823
30824 #endif
30825diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
30826index 5a82b6b..9e69c73 100644
30827--- a/drivers/gpu/drm/radeon/mkregtable.c
30828+++ b/drivers/gpu/drm/radeon/mkregtable.c
30829@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
30830 regex_t mask_rex;
30831 regmatch_t match[4];
30832 char buf[1024];
30833- size_t end;
30834+ long end;
30835 int len;
30836 int done = 0;
30837 int r;
30838 unsigned o;
30839 struct offset *offset;
30840 char last_reg_s[10];
30841- int last_reg;
30842+ unsigned long last_reg;
30843
30844 if (regcomp
30845 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
30846diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
30847index 138b952..d74f9cb 100644
30848--- a/drivers/gpu/drm/radeon/radeon.h
30849+++ b/drivers/gpu/drm/radeon/radeon.h
30850@@ -253,7 +253,7 @@ struct radeon_fence_driver {
30851 uint32_t scratch_reg;
30852 uint64_t gpu_addr;
30853 volatile uint32_t *cpu_addr;
30854- atomic_t seq;
30855+ atomic_unchecked_t seq;
30856 uint32_t last_seq;
30857 unsigned long last_jiffies;
30858 unsigned long last_timeout;
30859@@ -753,7 +753,7 @@ struct r600_blit_cp_primitives {
30860 int x2, int y2);
30861 void (*draw_auto)(struct radeon_device *rdev);
30862 void (*set_default_state)(struct radeon_device *rdev);
30863-};
30864+} __no_const;
30865
30866 struct r600_blit {
30867 struct mutex mutex;
30868@@ -1246,7 +1246,7 @@ struct radeon_asic {
30869 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
30870 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
30871 } pflip;
30872-};
30873+} __no_const;
30874
30875 /*
30876 * Asic structures
30877diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
30878index 5992502..c19c633 100644
30879--- a/drivers/gpu/drm/radeon/radeon_device.c
30880+++ b/drivers/gpu/drm/radeon/radeon_device.c
30881@@ -691,7 +691,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
30882 bool can_switch;
30883
30884 spin_lock(&dev->count_lock);
30885- can_switch = (dev->open_count == 0);
30886+ can_switch = (local_read(&dev->open_count) == 0);
30887 spin_unlock(&dev->count_lock);
30888 return can_switch;
30889 }
30890diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
30891index a1b59ca..86f2d44 100644
30892--- a/drivers/gpu/drm/radeon/radeon_drv.h
30893+++ b/drivers/gpu/drm/radeon/radeon_drv.h
30894@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
30895
30896 /* SW interrupt */
30897 wait_queue_head_t swi_queue;
30898- atomic_t swi_emitted;
30899+ atomic_unchecked_t swi_emitted;
30900 int vblank_crtc;
30901 uint32_t irq_enable_reg;
30902 uint32_t r500_disp_irq_reg;
30903diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
30904index 4bd36a3..e66fe9c 100644
30905--- a/drivers/gpu/drm/radeon/radeon_fence.c
30906+++ b/drivers/gpu/drm/radeon/radeon_fence.c
30907@@ -70,7 +70,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
30908 write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
30909 return 0;
30910 }
30911- fence->seq = atomic_add_return(1, &rdev->fence_drv[fence->ring].seq);
30912+ fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv[fence->ring].seq);
30913 if (!rdev->ring[fence->ring].ready)
30914 /* FIXME: cp is not running assume everythings is done right
30915 * away
30916@@ -405,7 +405,7 @@ int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring)
30917 }
30918 rdev->fence_drv[ring].cpu_addr = &rdev->wb.wb[index/4];
30919 rdev->fence_drv[ring].gpu_addr = rdev->wb.gpu_addr + index;
30920- radeon_fence_write(rdev, atomic_read(&rdev->fence_drv[ring].seq), ring);
30921+ radeon_fence_write(rdev, atomic_read_unchecked(&rdev->fence_drv[ring].seq), ring);
30922 rdev->fence_drv[ring].initialized = true;
30923 DRM_INFO("fence driver on ring %d use gpu addr 0x%08Lx and cpu addr 0x%p\n",
30924 ring, rdev->fence_drv[ring].gpu_addr, rdev->fence_drv[ring].cpu_addr);
30925@@ -418,7 +418,7 @@ static void radeon_fence_driver_init_ring(struct radeon_device *rdev, int ring)
30926 rdev->fence_drv[ring].scratch_reg = -1;
30927 rdev->fence_drv[ring].cpu_addr = NULL;
30928 rdev->fence_drv[ring].gpu_addr = 0;
30929- atomic_set(&rdev->fence_drv[ring].seq, 0);
30930+ atomic_set_unchecked(&rdev->fence_drv[ring].seq, 0);
30931 INIT_LIST_HEAD(&rdev->fence_drv[ring].created);
30932 INIT_LIST_HEAD(&rdev->fence_drv[ring].emitted);
30933 INIT_LIST_HEAD(&rdev->fence_drv[ring].signaled);
30934diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
30935index 48b7cea..342236f 100644
30936--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
30937+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
30938@@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
30939 request = compat_alloc_user_space(sizeof(*request));
30940 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
30941 || __put_user(req32.param, &request->param)
30942- || __put_user((void __user *)(unsigned long)req32.value,
30943+ || __put_user((unsigned long)req32.value,
30944 &request->value))
30945 return -EFAULT;
30946
30947diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
30948index 00da384..32f972d 100644
30949--- a/drivers/gpu/drm/radeon/radeon_irq.c
30950+++ b/drivers/gpu/drm/radeon/radeon_irq.c
30951@@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
30952 unsigned int ret;
30953 RING_LOCALS;
30954
30955- atomic_inc(&dev_priv->swi_emitted);
30956- ret = atomic_read(&dev_priv->swi_emitted);
30957+ atomic_inc_unchecked(&dev_priv->swi_emitted);
30958+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
30959
30960 BEGIN_RING(4);
30961 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
30962@@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
30963 drm_radeon_private_t *dev_priv =
30964 (drm_radeon_private_t *) dev->dev_private;
30965
30966- atomic_set(&dev_priv->swi_emitted, 0);
30967+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
30968 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
30969
30970 dev->max_vblank_count = 0x001fffff;
30971diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
30972index e8422ae..d22d4a8 100644
30973--- a/drivers/gpu/drm/radeon/radeon_state.c
30974+++ b/drivers/gpu/drm/radeon/radeon_state.c
30975@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
30976 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
30977 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
30978
30979- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30980+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30981 sarea_priv->nbox * sizeof(depth_boxes[0])))
30982 return -EFAULT;
30983
30984@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
30985 {
30986 drm_radeon_private_t *dev_priv = dev->dev_private;
30987 drm_radeon_getparam_t *param = data;
30988- int value;
30989+ int value = 0;
30990
30991 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
30992
30993diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
30994index f493c64..524ab6b 100644
30995--- a/drivers/gpu/drm/radeon/radeon_ttm.c
30996+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
30997@@ -843,8 +843,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
30998 }
30999 if (unlikely(ttm_vm_ops == NULL)) {
31000 ttm_vm_ops = vma->vm_ops;
31001- radeon_ttm_vm_ops = *ttm_vm_ops;
31002- radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31003+ pax_open_kernel();
31004+ memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
31005+ *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31006+ pax_close_kernel();
31007 }
31008 vma->vm_ops = &radeon_ttm_vm_ops;
31009 return 0;
31010diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31011index f2c3b9d..d5a376b 100644
31012--- a/drivers/gpu/drm/radeon/rs690.c
31013+++ b/drivers/gpu/drm/radeon/rs690.c
31014@@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31015 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31016 rdev->pm.sideport_bandwidth.full)
31017 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31018- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31019+ read_delay_latency.full = dfixed_const(800 * 1000);
31020 read_delay_latency.full = dfixed_div(read_delay_latency,
31021 rdev->pm.igp_sideport_mclk);
31022+ a.full = dfixed_const(370);
31023+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31024 } else {
31025 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31026 rdev->pm.k8_bandwidth.full)
31027diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31028index ebc6fac..a8313ed 100644
31029--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31030+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31031@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
31032 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31033 struct shrink_control *sc)
31034 {
31035- static atomic_t start_pool = ATOMIC_INIT(0);
31036+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31037 unsigned i;
31038- unsigned pool_offset = atomic_add_return(1, &start_pool);
31039+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31040 struct ttm_page_pool *pool;
31041 int shrink_pages = sc->nr_to_scan;
31042
31043diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31044index 88edacc..1e5412b 100644
31045--- a/drivers/gpu/drm/via/via_drv.h
31046+++ b/drivers/gpu/drm/via/via_drv.h
31047@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31048 typedef uint32_t maskarray_t[5];
31049
31050 typedef struct drm_via_irq {
31051- atomic_t irq_received;
31052+ atomic_unchecked_t irq_received;
31053 uint32_t pending_mask;
31054 uint32_t enable_mask;
31055 wait_queue_head_t irq_queue;
31056@@ -75,7 +75,7 @@ typedef struct drm_via_private {
31057 struct timeval last_vblank;
31058 int last_vblank_valid;
31059 unsigned usec_per_vblank;
31060- atomic_t vbl_received;
31061+ atomic_unchecked_t vbl_received;
31062 drm_via_state_t hc_state;
31063 char pci_buf[VIA_PCI_BUF_SIZE];
31064 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31065diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31066index d391f48..10c8ca3 100644
31067--- a/drivers/gpu/drm/via/via_irq.c
31068+++ b/drivers/gpu/drm/via/via_irq.c
31069@@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31070 if (crtc != 0)
31071 return 0;
31072
31073- return atomic_read(&dev_priv->vbl_received);
31074+ return atomic_read_unchecked(&dev_priv->vbl_received);
31075 }
31076
31077 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31078@@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31079
31080 status = VIA_READ(VIA_REG_INTERRUPT);
31081 if (status & VIA_IRQ_VBLANK_PENDING) {
31082- atomic_inc(&dev_priv->vbl_received);
31083- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31084+ atomic_inc_unchecked(&dev_priv->vbl_received);
31085+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31086 do_gettimeofday(&cur_vblank);
31087 if (dev_priv->last_vblank_valid) {
31088 dev_priv->usec_per_vblank =
31089@@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31090 dev_priv->last_vblank = cur_vblank;
31091 dev_priv->last_vblank_valid = 1;
31092 }
31093- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31094+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31095 DRM_DEBUG("US per vblank is: %u\n",
31096 dev_priv->usec_per_vblank);
31097 }
31098@@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31099
31100 for (i = 0; i < dev_priv->num_irqs; ++i) {
31101 if (status & cur_irq->pending_mask) {
31102- atomic_inc(&cur_irq->irq_received);
31103+ atomic_inc_unchecked(&cur_irq->irq_received);
31104 DRM_WAKEUP(&cur_irq->irq_queue);
31105 handled = 1;
31106 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31107@@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31108 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31109 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31110 masks[irq][4]));
31111- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31112+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31113 } else {
31114 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31115 (((cur_irq_sequence =
31116- atomic_read(&cur_irq->irq_received)) -
31117+ atomic_read_unchecked(&cur_irq->irq_received)) -
31118 *sequence) <= (1 << 23)));
31119 }
31120 *sequence = cur_irq_sequence;
31121@@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31122 }
31123
31124 for (i = 0; i < dev_priv->num_irqs; ++i) {
31125- atomic_set(&cur_irq->irq_received, 0);
31126+ atomic_set_unchecked(&cur_irq->irq_received, 0);
31127 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31128 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31129 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31130@@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31131 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31132 case VIA_IRQ_RELATIVE:
31133 irqwait->request.sequence +=
31134- atomic_read(&cur_irq->irq_received);
31135+ atomic_read_unchecked(&cur_irq->irq_received);
31136 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31137 case VIA_IRQ_ABSOLUTE:
31138 break;
31139diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31140index d0f2c07..9ebd9c3 100644
31141--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31142+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31143@@ -263,7 +263,7 @@ struct vmw_private {
31144 * Fencing and IRQs.
31145 */
31146
31147- atomic_t marker_seq;
31148+ atomic_unchecked_t marker_seq;
31149 wait_queue_head_t fence_queue;
31150 wait_queue_head_t fifo_queue;
31151 int fence_queue_waiters; /* Protected by hw_mutex */
31152diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31153index a0c2f12..68ae6cb 100644
31154--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31155+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31156@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31157 (unsigned int) min,
31158 (unsigned int) fifo->capabilities);
31159
31160- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31161+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31162 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31163 vmw_marker_queue_init(&fifo->marker_queue);
31164 return vmw_fifo_send_fence(dev_priv, &dummy);
31165@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31166 if (reserveable)
31167 iowrite32(bytes, fifo_mem +
31168 SVGA_FIFO_RESERVED);
31169- return fifo_mem + (next_cmd >> 2);
31170+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31171 } else {
31172 need_bounce = true;
31173 }
31174@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31175
31176 fm = vmw_fifo_reserve(dev_priv, bytes);
31177 if (unlikely(fm == NULL)) {
31178- *seqno = atomic_read(&dev_priv->marker_seq);
31179+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31180 ret = -ENOMEM;
31181 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31182 false, 3*HZ);
31183@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31184 }
31185
31186 do {
31187- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31188+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31189 } while (*seqno == 0);
31190
31191 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31192diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31193index cabc95f..14b3d77 100644
31194--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31195+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31196@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31197 * emitted. Then the fence is stale and signaled.
31198 */
31199
31200- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31201+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31202 > VMW_FENCE_WRAP);
31203
31204 return ret;
31205@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31206
31207 if (fifo_idle)
31208 down_read(&fifo_state->rwsem);
31209- signal_seq = atomic_read(&dev_priv->marker_seq);
31210+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31211 ret = 0;
31212
31213 for (;;) {
31214diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31215index 8a8725c..afed796 100644
31216--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31217+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31218@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31219 while (!vmw_lag_lt(queue, us)) {
31220 spin_lock(&queue->lock);
31221 if (list_empty(&queue->head))
31222- seqno = atomic_read(&dev_priv->marker_seq);
31223+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31224 else {
31225 marker = list_first_entry(&queue->head,
31226 struct vmw_marker, head);
31227diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31228index 4da66b4..e948655 100644
31229--- a/drivers/hid/hid-core.c
31230+++ b/drivers/hid/hid-core.c
31231@@ -2063,7 +2063,7 @@ static bool hid_ignore(struct hid_device *hdev)
31232
31233 int hid_add_device(struct hid_device *hdev)
31234 {
31235- static atomic_t id = ATOMIC_INIT(0);
31236+ static atomic_unchecked_t id = ATOMIC_INIT(0);
31237 int ret;
31238
31239 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31240@@ -2078,7 +2078,7 @@ int hid_add_device(struct hid_device *hdev)
31241 /* XXX hack, any other cleaner solution after the driver core
31242 * is converted to allow more than 20 bytes as the device name? */
31243 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31244- hdev->vendor, hdev->product, atomic_inc_return(&id));
31245+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31246
31247 hid_debug_register(hdev, dev_name(&hdev->dev));
31248 ret = device_add(&hdev->dev);
31249diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31250index eec3291..8ed706b 100644
31251--- a/drivers/hid/hid-wiimote-debug.c
31252+++ b/drivers/hid/hid-wiimote-debug.c
31253@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31254 else if (size == 0)
31255 return -EIO;
31256
31257- if (copy_to_user(u, buf, size))
31258+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
31259 return -EFAULT;
31260
31261 *off += size;
31262diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31263index b1ec0e2..c295a61 100644
31264--- a/drivers/hid/usbhid/hiddev.c
31265+++ b/drivers/hid/usbhid/hiddev.c
31266@@ -624,7 +624,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31267 break;
31268
31269 case HIDIOCAPPLICATION:
31270- if (arg < 0 || arg >= hid->maxapplication)
31271+ if (arg >= hid->maxapplication)
31272 break;
31273
31274 for (i = 0; i < hid->maxcollection; i++)
31275diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31276index 4065374..10ed7dc 100644
31277--- a/drivers/hv/channel.c
31278+++ b/drivers/hv/channel.c
31279@@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31280 int ret = 0;
31281 int t;
31282
31283- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31284- atomic_inc(&vmbus_connection.next_gpadl_handle);
31285+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31286+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31287
31288 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31289 if (ret)
31290diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31291index 15956bd..ea34398 100644
31292--- a/drivers/hv/hv.c
31293+++ b/drivers/hv/hv.c
31294@@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31295 u64 output_address = (output) ? virt_to_phys(output) : 0;
31296 u32 output_address_hi = output_address >> 32;
31297 u32 output_address_lo = output_address & 0xFFFFFFFF;
31298- void *hypercall_page = hv_context.hypercall_page;
31299+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31300
31301 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31302 "=a"(hv_status_lo) : "d" (control_hi),
31303diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31304index 699f0d8..f4f19250 100644
31305--- a/drivers/hv/hyperv_vmbus.h
31306+++ b/drivers/hv/hyperv_vmbus.h
31307@@ -555,7 +555,7 @@ enum vmbus_connect_state {
31308 struct vmbus_connection {
31309 enum vmbus_connect_state conn_state;
31310
31311- atomic_t next_gpadl_handle;
31312+ atomic_unchecked_t next_gpadl_handle;
31313
31314 /*
31315 * Represents channel interrupts. Each bit position represents a
31316diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31317index a220e57..428f54d 100644
31318--- a/drivers/hv/vmbus_drv.c
31319+++ b/drivers/hv/vmbus_drv.c
31320@@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31321 {
31322 int ret = 0;
31323
31324- static atomic_t device_num = ATOMIC_INIT(0);
31325+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31326
31327 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31328- atomic_inc_return(&device_num));
31329+ atomic_inc_return_unchecked(&device_num));
31330
31331 child_device_obj->device.bus = &hv_bus;
31332 child_device_obj->device.parent = &hv_acpi_dev->dev;
31333diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
31334index 9140236..ceaef4e 100644
31335--- a/drivers/hwmon/acpi_power_meter.c
31336+++ b/drivers/hwmon/acpi_power_meter.c
31337@@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
31338 return res;
31339
31340 temp /= 1000;
31341- if (temp < 0)
31342- return -EINVAL;
31343
31344 mutex_lock(&resource->lock);
31345 resource->trip[attr->index - 7] = temp;
31346diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31347index 8b011d0..3de24a1 100644
31348--- a/drivers/hwmon/sht15.c
31349+++ b/drivers/hwmon/sht15.c
31350@@ -166,7 +166,7 @@ struct sht15_data {
31351 int supply_uV;
31352 bool supply_uV_valid;
31353 struct work_struct update_supply_work;
31354- atomic_t interrupt_handled;
31355+ atomic_unchecked_t interrupt_handled;
31356 };
31357
31358 /**
31359@@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31360 return ret;
31361
31362 gpio_direction_input(data->pdata->gpio_data);
31363- atomic_set(&data->interrupt_handled, 0);
31364+ atomic_set_unchecked(&data->interrupt_handled, 0);
31365
31366 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31367 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31368 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31369 /* Only relevant if the interrupt hasn't occurred. */
31370- if (!atomic_read(&data->interrupt_handled))
31371+ if (!atomic_read_unchecked(&data->interrupt_handled))
31372 schedule_work(&data->read_work);
31373 }
31374 ret = wait_event_timeout(data->wait_queue,
31375@@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31376
31377 /* First disable the interrupt */
31378 disable_irq_nosync(irq);
31379- atomic_inc(&data->interrupt_handled);
31380+ atomic_inc_unchecked(&data->interrupt_handled);
31381 /* Then schedule a reading work struct */
31382 if (data->state != SHT15_READING_NOTHING)
31383 schedule_work(&data->read_work);
31384@@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31385 * If not, then start the interrupt again - care here as could
31386 * have gone low in meantime so verify it hasn't!
31387 */
31388- atomic_set(&data->interrupt_handled, 0);
31389+ atomic_set_unchecked(&data->interrupt_handled, 0);
31390 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31391 /* If still not occurred or another handler was scheduled */
31392 if (gpio_get_value(data->pdata->gpio_data)
31393- || atomic_read(&data->interrupt_handled))
31394+ || atomic_read_unchecked(&data->interrupt_handled))
31395 return;
31396 }
31397
31398diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31399index 378fcb5..5e91fa8 100644
31400--- a/drivers/i2c/busses/i2c-amd756-s4882.c
31401+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31402@@ -43,7 +43,7 @@
31403 extern struct i2c_adapter amd756_smbus;
31404
31405 static struct i2c_adapter *s4882_adapter;
31406-static struct i2c_algorithm *s4882_algo;
31407+static i2c_algorithm_no_const *s4882_algo;
31408
31409 /* Wrapper access functions for multiplexed SMBus */
31410 static DEFINE_MUTEX(amd756_lock);
31411diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31412index 29015eb..af2d8e9 100644
31413--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31414+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31415@@ -41,7 +41,7 @@
31416 extern struct i2c_adapter *nforce2_smbus;
31417
31418 static struct i2c_adapter *s4985_adapter;
31419-static struct i2c_algorithm *s4985_algo;
31420+static i2c_algorithm_no_const *s4985_algo;
31421
31422 /* Wrapper access functions for multiplexed SMBus */
31423 static DEFINE_MUTEX(nforce2_lock);
31424diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31425index d7a4833..7fae376 100644
31426--- a/drivers/i2c/i2c-mux.c
31427+++ b/drivers/i2c/i2c-mux.c
31428@@ -28,7 +28,7 @@
31429 /* multiplexer per channel data */
31430 struct i2c_mux_priv {
31431 struct i2c_adapter adap;
31432- struct i2c_algorithm algo;
31433+ i2c_algorithm_no_const algo;
31434
31435 struct i2c_adapter *parent;
31436 void *mux_dev; /* the mux chip/device */
31437diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31438index 57d00ca..0145194 100644
31439--- a/drivers/ide/aec62xx.c
31440+++ b/drivers/ide/aec62xx.c
31441@@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31442 .cable_detect = atp86x_cable_detect,
31443 };
31444
31445-static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31446+static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31447 { /* 0: AEC6210 */
31448 .name = DRV_NAME,
31449 .init_chipset = init_chipset_aec62xx,
31450diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31451index 2c8016a..911a27c 100644
31452--- a/drivers/ide/alim15x3.c
31453+++ b/drivers/ide/alim15x3.c
31454@@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31455 .dma_sff_read_status = ide_dma_sff_read_status,
31456 };
31457
31458-static const struct ide_port_info ali15x3_chipset __devinitdata = {
31459+static const struct ide_port_info ali15x3_chipset __devinitconst = {
31460 .name = DRV_NAME,
31461 .init_chipset = init_chipset_ali15x3,
31462 .init_hwif = init_hwif_ali15x3,
31463diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31464index 3747b25..56fc995 100644
31465--- a/drivers/ide/amd74xx.c
31466+++ b/drivers/ide/amd74xx.c
31467@@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31468 .udma_mask = udma, \
31469 }
31470
31471-static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31472+static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31473 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31474 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31475 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31476diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31477index 15f0ead..cb43480 100644
31478--- a/drivers/ide/atiixp.c
31479+++ b/drivers/ide/atiixp.c
31480@@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31481 .cable_detect = atiixp_cable_detect,
31482 };
31483
31484-static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31485+static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31486 { /* 0: IXP200/300/400/700 */
31487 .name = DRV_NAME,
31488 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31489diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31490index 5f80312..d1fc438 100644
31491--- a/drivers/ide/cmd64x.c
31492+++ b/drivers/ide/cmd64x.c
31493@@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31494 .dma_sff_read_status = ide_dma_sff_read_status,
31495 };
31496
31497-static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31498+static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31499 { /* 0: CMD643 */
31500 .name = DRV_NAME,
31501 .init_chipset = init_chipset_cmd64x,
31502diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31503index 2c1e5f7..1444762 100644
31504--- a/drivers/ide/cs5520.c
31505+++ b/drivers/ide/cs5520.c
31506@@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31507 .set_dma_mode = cs5520_set_dma_mode,
31508 };
31509
31510-static const struct ide_port_info cyrix_chipset __devinitdata = {
31511+static const struct ide_port_info cyrix_chipset __devinitconst = {
31512 .name = DRV_NAME,
31513 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31514 .port_ops = &cs5520_port_ops,
31515diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31516index 4dc4eb9..49b40ad 100644
31517--- a/drivers/ide/cs5530.c
31518+++ b/drivers/ide/cs5530.c
31519@@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31520 .udma_filter = cs5530_udma_filter,
31521 };
31522
31523-static const struct ide_port_info cs5530_chipset __devinitdata = {
31524+static const struct ide_port_info cs5530_chipset __devinitconst = {
31525 .name = DRV_NAME,
31526 .init_chipset = init_chipset_cs5530,
31527 .init_hwif = init_hwif_cs5530,
31528diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31529index 5059faf..18d4c85 100644
31530--- a/drivers/ide/cs5535.c
31531+++ b/drivers/ide/cs5535.c
31532@@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31533 .cable_detect = cs5535_cable_detect,
31534 };
31535
31536-static const struct ide_port_info cs5535_chipset __devinitdata = {
31537+static const struct ide_port_info cs5535_chipset __devinitconst = {
31538 .name = DRV_NAME,
31539 .port_ops = &cs5535_port_ops,
31540 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31541diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31542index 847553f..3ffb49d 100644
31543--- a/drivers/ide/cy82c693.c
31544+++ b/drivers/ide/cy82c693.c
31545@@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31546 .set_dma_mode = cy82c693_set_dma_mode,
31547 };
31548
31549-static const struct ide_port_info cy82c693_chipset __devinitdata = {
31550+static const struct ide_port_info cy82c693_chipset __devinitconst = {
31551 .name = DRV_NAME,
31552 .init_iops = init_iops_cy82c693,
31553 .port_ops = &cy82c693_port_ops,
31554diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31555index 58c51cd..4aec3b8 100644
31556--- a/drivers/ide/hpt366.c
31557+++ b/drivers/ide/hpt366.c
31558@@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31559 }
31560 };
31561
31562-static const struct hpt_info hpt36x __devinitdata = {
31563+static const struct hpt_info hpt36x __devinitconst = {
31564 .chip_name = "HPT36x",
31565 .chip_type = HPT36x,
31566 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31567@@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31568 .timings = &hpt36x_timings
31569 };
31570
31571-static const struct hpt_info hpt370 __devinitdata = {
31572+static const struct hpt_info hpt370 __devinitconst = {
31573 .chip_name = "HPT370",
31574 .chip_type = HPT370,
31575 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31576@@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31577 .timings = &hpt37x_timings
31578 };
31579
31580-static const struct hpt_info hpt370a __devinitdata = {
31581+static const struct hpt_info hpt370a __devinitconst = {
31582 .chip_name = "HPT370A",
31583 .chip_type = HPT370A,
31584 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31585@@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31586 .timings = &hpt37x_timings
31587 };
31588
31589-static const struct hpt_info hpt374 __devinitdata = {
31590+static const struct hpt_info hpt374 __devinitconst = {
31591 .chip_name = "HPT374",
31592 .chip_type = HPT374,
31593 .udma_mask = ATA_UDMA5,
31594@@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31595 .timings = &hpt37x_timings
31596 };
31597
31598-static const struct hpt_info hpt372 __devinitdata = {
31599+static const struct hpt_info hpt372 __devinitconst = {
31600 .chip_name = "HPT372",
31601 .chip_type = HPT372,
31602 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31603@@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31604 .timings = &hpt37x_timings
31605 };
31606
31607-static const struct hpt_info hpt372a __devinitdata = {
31608+static const struct hpt_info hpt372a __devinitconst = {
31609 .chip_name = "HPT372A",
31610 .chip_type = HPT372A,
31611 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31612@@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31613 .timings = &hpt37x_timings
31614 };
31615
31616-static const struct hpt_info hpt302 __devinitdata = {
31617+static const struct hpt_info hpt302 __devinitconst = {
31618 .chip_name = "HPT302",
31619 .chip_type = HPT302,
31620 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31621@@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31622 .timings = &hpt37x_timings
31623 };
31624
31625-static const struct hpt_info hpt371 __devinitdata = {
31626+static const struct hpt_info hpt371 __devinitconst = {
31627 .chip_name = "HPT371",
31628 .chip_type = HPT371,
31629 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31630@@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31631 .timings = &hpt37x_timings
31632 };
31633
31634-static const struct hpt_info hpt372n __devinitdata = {
31635+static const struct hpt_info hpt372n __devinitconst = {
31636 .chip_name = "HPT372N",
31637 .chip_type = HPT372N,
31638 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31639@@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31640 .timings = &hpt37x_timings
31641 };
31642
31643-static const struct hpt_info hpt302n __devinitdata = {
31644+static const struct hpt_info hpt302n __devinitconst = {
31645 .chip_name = "HPT302N",
31646 .chip_type = HPT302N,
31647 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31648@@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31649 .timings = &hpt37x_timings
31650 };
31651
31652-static const struct hpt_info hpt371n __devinitdata = {
31653+static const struct hpt_info hpt371n __devinitconst = {
31654 .chip_name = "HPT371N",
31655 .chip_type = HPT371N,
31656 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31657@@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31658 .dma_sff_read_status = ide_dma_sff_read_status,
31659 };
31660
31661-static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31662+static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31663 { /* 0: HPT36x */
31664 .name = DRV_NAME,
31665 .init_chipset = init_chipset_hpt366,
31666diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31667index 8126824..55a2798 100644
31668--- a/drivers/ide/ide-cd.c
31669+++ b/drivers/ide/ide-cd.c
31670@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31671 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31672 if ((unsigned long)buf & alignment
31673 || blk_rq_bytes(rq) & q->dma_pad_mask
31674- || object_is_on_stack(buf))
31675+ || object_starts_on_stack(buf))
31676 drive->dma = 0;
31677 }
31678 }
31679diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31680index 7f56b73..dab5b67 100644
31681--- a/drivers/ide/ide-pci-generic.c
31682+++ b/drivers/ide/ide-pci-generic.c
31683@@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31684 .udma_mask = ATA_UDMA6, \
31685 }
31686
31687-static const struct ide_port_info generic_chipsets[] __devinitdata = {
31688+static const struct ide_port_info generic_chipsets[] __devinitconst = {
31689 /* 0: Unknown */
31690 DECLARE_GENERIC_PCI_DEV(0),
31691
31692diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31693index 560e66d..d5dd180 100644
31694--- a/drivers/ide/it8172.c
31695+++ b/drivers/ide/it8172.c
31696@@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31697 .set_dma_mode = it8172_set_dma_mode,
31698 };
31699
31700-static const struct ide_port_info it8172_port_info __devinitdata = {
31701+static const struct ide_port_info it8172_port_info __devinitconst = {
31702 .name = DRV_NAME,
31703 .port_ops = &it8172_port_ops,
31704 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31705diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31706index 46816ba..1847aeb 100644
31707--- a/drivers/ide/it8213.c
31708+++ b/drivers/ide/it8213.c
31709@@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31710 .cable_detect = it8213_cable_detect,
31711 };
31712
31713-static const struct ide_port_info it8213_chipset __devinitdata = {
31714+static const struct ide_port_info it8213_chipset __devinitconst = {
31715 .name = DRV_NAME,
31716 .enablebits = { {0x41, 0x80, 0x80} },
31717 .port_ops = &it8213_port_ops,
31718diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31719index 2e3169f..c5611db 100644
31720--- a/drivers/ide/it821x.c
31721+++ b/drivers/ide/it821x.c
31722@@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31723 .cable_detect = it821x_cable_detect,
31724 };
31725
31726-static const struct ide_port_info it821x_chipset __devinitdata = {
31727+static const struct ide_port_info it821x_chipset __devinitconst = {
31728 .name = DRV_NAME,
31729 .init_chipset = init_chipset_it821x,
31730 .init_hwif = init_hwif_it821x,
31731diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31732index 74c2c4a..efddd7d 100644
31733--- a/drivers/ide/jmicron.c
31734+++ b/drivers/ide/jmicron.c
31735@@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31736 .cable_detect = jmicron_cable_detect,
31737 };
31738
31739-static const struct ide_port_info jmicron_chipset __devinitdata = {
31740+static const struct ide_port_info jmicron_chipset __devinitconst = {
31741 .name = DRV_NAME,
31742 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31743 .port_ops = &jmicron_port_ops,
31744diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31745index 95327a2..73f78d8 100644
31746--- a/drivers/ide/ns87415.c
31747+++ b/drivers/ide/ns87415.c
31748@@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31749 .dma_sff_read_status = superio_dma_sff_read_status,
31750 };
31751
31752-static const struct ide_port_info ns87415_chipset __devinitdata = {
31753+static const struct ide_port_info ns87415_chipset __devinitconst = {
31754 .name = DRV_NAME,
31755 .init_hwif = init_hwif_ns87415,
31756 .tp_ops = &ns87415_tp_ops,
31757diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31758index 1a53a4c..39edc66 100644
31759--- a/drivers/ide/opti621.c
31760+++ b/drivers/ide/opti621.c
31761@@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31762 .set_pio_mode = opti621_set_pio_mode,
31763 };
31764
31765-static const struct ide_port_info opti621_chipset __devinitdata = {
31766+static const struct ide_port_info opti621_chipset __devinitconst = {
31767 .name = DRV_NAME,
31768 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31769 .port_ops = &opti621_port_ops,
31770diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31771index 9546fe2..2e5ceb6 100644
31772--- a/drivers/ide/pdc202xx_new.c
31773+++ b/drivers/ide/pdc202xx_new.c
31774@@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31775 .udma_mask = udma, \
31776 }
31777
31778-static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
31779+static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
31780 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
31781 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
31782 };
31783diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
31784index 3a35ec6..5634510 100644
31785--- a/drivers/ide/pdc202xx_old.c
31786+++ b/drivers/ide/pdc202xx_old.c
31787@@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
31788 .max_sectors = sectors, \
31789 }
31790
31791-static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
31792+static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
31793 { /* 0: PDC20246 */
31794 .name = DRV_NAME,
31795 .init_chipset = init_chipset_pdc202xx,
31796diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
31797index 1892e81..fe0fd60 100644
31798--- a/drivers/ide/piix.c
31799+++ b/drivers/ide/piix.c
31800@@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
31801 .udma_mask = udma, \
31802 }
31803
31804-static const struct ide_port_info piix_pci_info[] __devinitdata = {
31805+static const struct ide_port_info piix_pci_info[] __devinitconst = {
31806 /* 0: MPIIX */
31807 { /*
31808 * MPIIX actually has only a single IDE channel mapped to
31809diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
31810index a6414a8..c04173e 100644
31811--- a/drivers/ide/rz1000.c
31812+++ b/drivers/ide/rz1000.c
31813@@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
31814 }
31815 }
31816
31817-static const struct ide_port_info rz1000_chipset __devinitdata = {
31818+static const struct ide_port_info rz1000_chipset __devinitconst = {
31819 .name = DRV_NAME,
31820 .host_flags = IDE_HFLAG_NO_DMA,
31821 };
31822diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
31823index 356b9b5..d4758eb 100644
31824--- a/drivers/ide/sc1200.c
31825+++ b/drivers/ide/sc1200.c
31826@@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
31827 .dma_sff_read_status = ide_dma_sff_read_status,
31828 };
31829
31830-static const struct ide_port_info sc1200_chipset __devinitdata = {
31831+static const struct ide_port_info sc1200_chipset __devinitconst = {
31832 .name = DRV_NAME,
31833 .port_ops = &sc1200_port_ops,
31834 .dma_ops = &sc1200_dma_ops,
31835diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
31836index b7f5b0c..9701038 100644
31837--- a/drivers/ide/scc_pata.c
31838+++ b/drivers/ide/scc_pata.c
31839@@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
31840 .dma_sff_read_status = scc_dma_sff_read_status,
31841 };
31842
31843-static const struct ide_port_info scc_chipset __devinitdata = {
31844+static const struct ide_port_info scc_chipset __devinitconst = {
31845 .name = "sccIDE",
31846 .init_iops = init_iops_scc,
31847 .init_dma = scc_init_dma,
31848diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
31849index 35fb8da..24d72ef 100644
31850--- a/drivers/ide/serverworks.c
31851+++ b/drivers/ide/serverworks.c
31852@@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
31853 .cable_detect = svwks_cable_detect,
31854 };
31855
31856-static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
31857+static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
31858 { /* 0: OSB4 */
31859 .name = DRV_NAME,
31860 .init_chipset = init_chipset_svwks,
31861diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
31862index ddeda44..46f7e30 100644
31863--- a/drivers/ide/siimage.c
31864+++ b/drivers/ide/siimage.c
31865@@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
31866 .udma_mask = ATA_UDMA6, \
31867 }
31868
31869-static const struct ide_port_info siimage_chipsets[] __devinitdata = {
31870+static const struct ide_port_info siimage_chipsets[] __devinitconst = {
31871 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
31872 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
31873 };
31874diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
31875index 4a00225..09e61b4 100644
31876--- a/drivers/ide/sis5513.c
31877+++ b/drivers/ide/sis5513.c
31878@@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
31879 .cable_detect = sis_cable_detect,
31880 };
31881
31882-static const struct ide_port_info sis5513_chipset __devinitdata = {
31883+static const struct ide_port_info sis5513_chipset __devinitconst = {
31884 .name = DRV_NAME,
31885 .init_chipset = init_chipset_sis5513,
31886 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
31887diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
31888index f21dc2a..d051cd2 100644
31889--- a/drivers/ide/sl82c105.c
31890+++ b/drivers/ide/sl82c105.c
31891@@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
31892 .dma_sff_read_status = ide_dma_sff_read_status,
31893 };
31894
31895-static const struct ide_port_info sl82c105_chipset __devinitdata = {
31896+static const struct ide_port_info sl82c105_chipset __devinitconst = {
31897 .name = DRV_NAME,
31898 .init_chipset = init_chipset_sl82c105,
31899 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
31900diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
31901index 864ffe0..863a5e9 100644
31902--- a/drivers/ide/slc90e66.c
31903+++ b/drivers/ide/slc90e66.c
31904@@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
31905 .cable_detect = slc90e66_cable_detect,
31906 };
31907
31908-static const struct ide_port_info slc90e66_chipset __devinitdata = {
31909+static const struct ide_port_info slc90e66_chipset __devinitconst = {
31910 .name = DRV_NAME,
31911 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
31912 .port_ops = &slc90e66_port_ops,
31913diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
31914index 4799d5c..1794678 100644
31915--- a/drivers/ide/tc86c001.c
31916+++ b/drivers/ide/tc86c001.c
31917@@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
31918 .dma_sff_read_status = ide_dma_sff_read_status,
31919 };
31920
31921-static const struct ide_port_info tc86c001_chipset __devinitdata = {
31922+static const struct ide_port_info tc86c001_chipset __devinitconst = {
31923 .name = DRV_NAME,
31924 .init_hwif = init_hwif_tc86c001,
31925 .port_ops = &tc86c001_port_ops,
31926diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
31927index 281c914..55ce1b8 100644
31928--- a/drivers/ide/triflex.c
31929+++ b/drivers/ide/triflex.c
31930@@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
31931 .set_dma_mode = triflex_set_mode,
31932 };
31933
31934-static const struct ide_port_info triflex_device __devinitdata = {
31935+static const struct ide_port_info triflex_device __devinitconst = {
31936 .name = DRV_NAME,
31937 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
31938 .port_ops = &triflex_port_ops,
31939diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
31940index 4b42ca0..e494a98 100644
31941--- a/drivers/ide/trm290.c
31942+++ b/drivers/ide/trm290.c
31943@@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
31944 .dma_check = trm290_dma_check,
31945 };
31946
31947-static const struct ide_port_info trm290_chipset __devinitdata = {
31948+static const struct ide_port_info trm290_chipset __devinitconst = {
31949 .name = DRV_NAME,
31950 .init_hwif = init_hwif_trm290,
31951 .tp_ops = &trm290_tp_ops,
31952diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
31953index f46f49c..eb77678 100644
31954--- a/drivers/ide/via82cxxx.c
31955+++ b/drivers/ide/via82cxxx.c
31956@@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
31957 .cable_detect = via82cxxx_cable_detect,
31958 };
31959
31960-static const struct ide_port_info via82cxxx_chipset __devinitdata = {
31961+static const struct ide_port_info via82cxxx_chipset __devinitconst = {
31962 .name = DRV_NAME,
31963 .init_chipset = init_chipset_via82cxxx,
31964 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
31965diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
31966index 73d4531..c90cd2d 100644
31967--- a/drivers/ieee802154/fakehard.c
31968+++ b/drivers/ieee802154/fakehard.c
31969@@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
31970 phy->transmit_power = 0xbf;
31971
31972 dev->netdev_ops = &fake_ops;
31973- dev->ml_priv = &fake_mlme;
31974+ dev->ml_priv = (void *)&fake_mlme;
31975
31976 priv = netdev_priv(dev);
31977 priv->phy = phy;
31978diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
31979index c889aae..6cf5aa7 100644
31980--- a/drivers/infiniband/core/cm.c
31981+++ b/drivers/infiniband/core/cm.c
31982@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
31983
31984 struct cm_counter_group {
31985 struct kobject obj;
31986- atomic_long_t counter[CM_ATTR_COUNT];
31987+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
31988 };
31989
31990 struct cm_counter_attribute {
31991@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
31992 struct ib_mad_send_buf *msg = NULL;
31993 int ret;
31994
31995- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31996+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31997 counter[CM_REQ_COUNTER]);
31998
31999 /* Quick state check to discard duplicate REQs. */
32000@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
32001 if (!cm_id_priv)
32002 return;
32003
32004- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32005+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32006 counter[CM_REP_COUNTER]);
32007 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32008 if (ret)
32009@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32010 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32011 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32012 spin_unlock_irq(&cm_id_priv->lock);
32013- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32014+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32015 counter[CM_RTU_COUNTER]);
32016 goto out;
32017 }
32018@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32019 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32020 dreq_msg->local_comm_id);
32021 if (!cm_id_priv) {
32022- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32023+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32024 counter[CM_DREQ_COUNTER]);
32025 cm_issue_drep(work->port, work->mad_recv_wc);
32026 return -EINVAL;
32027@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32028 case IB_CM_MRA_REP_RCVD:
32029 break;
32030 case IB_CM_TIMEWAIT:
32031- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32032+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32033 counter[CM_DREQ_COUNTER]);
32034 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32035 goto unlock;
32036@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32037 cm_free_msg(msg);
32038 goto deref;
32039 case IB_CM_DREQ_RCVD:
32040- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32041+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32042 counter[CM_DREQ_COUNTER]);
32043 goto unlock;
32044 default:
32045@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32046 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32047 cm_id_priv->msg, timeout)) {
32048 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32049- atomic_long_inc(&work->port->
32050+ atomic_long_inc_unchecked(&work->port->
32051 counter_group[CM_RECV_DUPLICATES].
32052 counter[CM_MRA_COUNTER]);
32053 goto out;
32054@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32055 break;
32056 case IB_CM_MRA_REQ_RCVD:
32057 case IB_CM_MRA_REP_RCVD:
32058- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32059+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32060 counter[CM_MRA_COUNTER]);
32061 /* fall through */
32062 default:
32063@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32064 case IB_CM_LAP_IDLE:
32065 break;
32066 case IB_CM_MRA_LAP_SENT:
32067- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32068+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32069 counter[CM_LAP_COUNTER]);
32070 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32071 goto unlock;
32072@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32073 cm_free_msg(msg);
32074 goto deref;
32075 case IB_CM_LAP_RCVD:
32076- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32077+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32078 counter[CM_LAP_COUNTER]);
32079 goto unlock;
32080 default:
32081@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32082 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32083 if (cur_cm_id_priv) {
32084 spin_unlock_irq(&cm.lock);
32085- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32086+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32087 counter[CM_SIDR_REQ_COUNTER]);
32088 goto out; /* Duplicate message. */
32089 }
32090@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32091 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32092 msg->retries = 1;
32093
32094- atomic_long_add(1 + msg->retries,
32095+ atomic_long_add_unchecked(1 + msg->retries,
32096 &port->counter_group[CM_XMIT].counter[attr_index]);
32097 if (msg->retries)
32098- atomic_long_add(msg->retries,
32099+ atomic_long_add_unchecked(msg->retries,
32100 &port->counter_group[CM_XMIT_RETRIES].
32101 counter[attr_index]);
32102
32103@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32104 }
32105
32106 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32107- atomic_long_inc(&port->counter_group[CM_RECV].
32108+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32109 counter[attr_id - CM_ATTR_ID_OFFSET]);
32110
32111 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32112@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32113 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32114
32115 return sprintf(buf, "%ld\n",
32116- atomic_long_read(&group->counter[cm_attr->index]));
32117+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32118 }
32119
32120 static const struct sysfs_ops cm_counter_ops = {
32121diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32122index 176c8f9..2627b62 100644
32123--- a/drivers/infiniband/core/fmr_pool.c
32124+++ b/drivers/infiniband/core/fmr_pool.c
32125@@ -98,8 +98,8 @@ struct ib_fmr_pool {
32126
32127 struct task_struct *thread;
32128
32129- atomic_t req_ser;
32130- atomic_t flush_ser;
32131+ atomic_unchecked_t req_ser;
32132+ atomic_unchecked_t flush_ser;
32133
32134 wait_queue_head_t force_wait;
32135 };
32136@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32137 struct ib_fmr_pool *pool = pool_ptr;
32138
32139 do {
32140- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32141+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32142 ib_fmr_batch_release(pool);
32143
32144- atomic_inc(&pool->flush_ser);
32145+ atomic_inc_unchecked(&pool->flush_ser);
32146 wake_up_interruptible(&pool->force_wait);
32147
32148 if (pool->flush_function)
32149@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32150 }
32151
32152 set_current_state(TASK_INTERRUPTIBLE);
32153- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32154+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32155 !kthread_should_stop())
32156 schedule();
32157 __set_current_state(TASK_RUNNING);
32158@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32159 pool->dirty_watermark = params->dirty_watermark;
32160 pool->dirty_len = 0;
32161 spin_lock_init(&pool->pool_lock);
32162- atomic_set(&pool->req_ser, 0);
32163- atomic_set(&pool->flush_ser, 0);
32164+ atomic_set_unchecked(&pool->req_ser, 0);
32165+ atomic_set_unchecked(&pool->flush_ser, 0);
32166 init_waitqueue_head(&pool->force_wait);
32167
32168 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32169@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32170 }
32171 spin_unlock_irq(&pool->pool_lock);
32172
32173- serial = atomic_inc_return(&pool->req_ser);
32174+ serial = atomic_inc_return_unchecked(&pool->req_ser);
32175 wake_up_process(pool->thread);
32176
32177 if (wait_event_interruptible(pool->force_wait,
32178- atomic_read(&pool->flush_ser) - serial >= 0))
32179+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32180 return -EINTR;
32181
32182 return 0;
32183@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32184 } else {
32185 list_add_tail(&fmr->list, &pool->dirty_list);
32186 if (++pool->dirty_len >= pool->dirty_watermark) {
32187- atomic_inc(&pool->req_ser);
32188+ atomic_inc_unchecked(&pool->req_ser);
32189 wake_up_process(pool->thread);
32190 }
32191 }
32192diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32193index 40c8353..946b0e4 100644
32194--- a/drivers/infiniband/hw/cxgb4/mem.c
32195+++ b/drivers/infiniband/hw/cxgb4/mem.c
32196@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32197 int err;
32198 struct fw_ri_tpte tpt;
32199 u32 stag_idx;
32200- static atomic_t key;
32201+ static atomic_unchecked_t key;
32202
32203 if (c4iw_fatal_error(rdev))
32204 return -EIO;
32205@@ -135,7 +135,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32206 &rdev->resource.tpt_fifo_lock);
32207 if (!stag_idx)
32208 return -ENOMEM;
32209- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32210+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32211 }
32212 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32213 __func__, stag_state, type, pdid, stag_idx);
32214diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32215index 79b3dbc..96e5fcc 100644
32216--- a/drivers/infiniband/hw/ipath/ipath_rc.c
32217+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32218@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32219 struct ib_atomic_eth *ateth;
32220 struct ipath_ack_entry *e;
32221 u64 vaddr;
32222- atomic64_t *maddr;
32223+ atomic64_unchecked_t *maddr;
32224 u64 sdata;
32225 u32 rkey;
32226 u8 next;
32227@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32228 IB_ACCESS_REMOTE_ATOMIC)))
32229 goto nack_acc_unlck;
32230 /* Perform atomic OP and save result. */
32231- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32232+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32233 sdata = be64_to_cpu(ateth->swap_data);
32234 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32235 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32236- (u64) atomic64_add_return(sdata, maddr) - sdata :
32237+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32238 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32239 be64_to_cpu(ateth->compare_data),
32240 sdata);
32241diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32242index 1f95bba..9530f87 100644
32243--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32244+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32245@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32246 unsigned long flags;
32247 struct ib_wc wc;
32248 u64 sdata;
32249- atomic64_t *maddr;
32250+ atomic64_unchecked_t *maddr;
32251 enum ib_wc_status send_status;
32252
32253 /*
32254@@ -382,11 +382,11 @@ again:
32255 IB_ACCESS_REMOTE_ATOMIC)))
32256 goto acc_err;
32257 /* Perform atomic OP and save result. */
32258- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32259+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32260 sdata = wqe->wr.wr.atomic.compare_add;
32261 *(u64 *) sqp->s_sge.sge.vaddr =
32262 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32263- (u64) atomic64_add_return(sdata, maddr) - sdata :
32264+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32265 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32266 sdata, wqe->wr.wr.atomic.swap);
32267 goto send_comp;
32268diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32269index 7140199..da60063 100644
32270--- a/drivers/infiniband/hw/nes/nes.c
32271+++ b/drivers/infiniband/hw/nes/nes.c
32272@@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32273 LIST_HEAD(nes_adapter_list);
32274 static LIST_HEAD(nes_dev_list);
32275
32276-atomic_t qps_destroyed;
32277+atomic_unchecked_t qps_destroyed;
32278
32279 static unsigned int ee_flsh_adapter;
32280 static unsigned int sysfs_nonidx_addr;
32281@@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32282 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32283 struct nes_adapter *nesadapter = nesdev->nesadapter;
32284
32285- atomic_inc(&qps_destroyed);
32286+ atomic_inc_unchecked(&qps_destroyed);
32287
32288 /* Free the control structures */
32289
32290diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32291index c438e46..ca30356 100644
32292--- a/drivers/infiniband/hw/nes/nes.h
32293+++ b/drivers/infiniband/hw/nes/nes.h
32294@@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32295 extern unsigned int wqm_quanta;
32296 extern struct list_head nes_adapter_list;
32297
32298-extern atomic_t cm_connects;
32299-extern atomic_t cm_accepts;
32300-extern atomic_t cm_disconnects;
32301-extern atomic_t cm_closes;
32302-extern atomic_t cm_connecteds;
32303-extern atomic_t cm_connect_reqs;
32304-extern atomic_t cm_rejects;
32305-extern atomic_t mod_qp_timouts;
32306-extern atomic_t qps_created;
32307-extern atomic_t qps_destroyed;
32308-extern atomic_t sw_qps_destroyed;
32309+extern atomic_unchecked_t cm_connects;
32310+extern atomic_unchecked_t cm_accepts;
32311+extern atomic_unchecked_t cm_disconnects;
32312+extern atomic_unchecked_t cm_closes;
32313+extern atomic_unchecked_t cm_connecteds;
32314+extern atomic_unchecked_t cm_connect_reqs;
32315+extern atomic_unchecked_t cm_rejects;
32316+extern atomic_unchecked_t mod_qp_timouts;
32317+extern atomic_unchecked_t qps_created;
32318+extern atomic_unchecked_t qps_destroyed;
32319+extern atomic_unchecked_t sw_qps_destroyed;
32320 extern u32 mh_detected;
32321 extern u32 mh_pauses_sent;
32322 extern u32 cm_packets_sent;
32323@@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32324 extern u32 cm_packets_received;
32325 extern u32 cm_packets_dropped;
32326 extern u32 cm_packets_retrans;
32327-extern atomic_t cm_listens_created;
32328-extern atomic_t cm_listens_destroyed;
32329+extern atomic_unchecked_t cm_listens_created;
32330+extern atomic_unchecked_t cm_listens_destroyed;
32331 extern u32 cm_backlog_drops;
32332-extern atomic_t cm_loopbacks;
32333-extern atomic_t cm_nodes_created;
32334-extern atomic_t cm_nodes_destroyed;
32335-extern atomic_t cm_accel_dropped_pkts;
32336-extern atomic_t cm_resets_recvd;
32337-extern atomic_t pau_qps_created;
32338-extern atomic_t pau_qps_destroyed;
32339+extern atomic_unchecked_t cm_loopbacks;
32340+extern atomic_unchecked_t cm_nodes_created;
32341+extern atomic_unchecked_t cm_nodes_destroyed;
32342+extern atomic_unchecked_t cm_accel_dropped_pkts;
32343+extern atomic_unchecked_t cm_resets_recvd;
32344+extern atomic_unchecked_t pau_qps_created;
32345+extern atomic_unchecked_t pau_qps_destroyed;
32346
32347 extern u32 int_mod_timer_init;
32348 extern u32 int_mod_cq_depth_256;
32349diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32350index 71edfbb..15b62ae 100644
32351--- a/drivers/infiniband/hw/nes/nes_cm.c
32352+++ b/drivers/infiniband/hw/nes/nes_cm.c
32353@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32354 u32 cm_packets_retrans;
32355 u32 cm_packets_created;
32356 u32 cm_packets_received;
32357-atomic_t cm_listens_created;
32358-atomic_t cm_listens_destroyed;
32359+atomic_unchecked_t cm_listens_created;
32360+atomic_unchecked_t cm_listens_destroyed;
32361 u32 cm_backlog_drops;
32362-atomic_t cm_loopbacks;
32363-atomic_t cm_nodes_created;
32364-atomic_t cm_nodes_destroyed;
32365-atomic_t cm_accel_dropped_pkts;
32366-atomic_t cm_resets_recvd;
32367+atomic_unchecked_t cm_loopbacks;
32368+atomic_unchecked_t cm_nodes_created;
32369+atomic_unchecked_t cm_nodes_destroyed;
32370+atomic_unchecked_t cm_accel_dropped_pkts;
32371+atomic_unchecked_t cm_resets_recvd;
32372
32373 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32374 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32375@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32376
32377 static struct nes_cm_core *g_cm_core;
32378
32379-atomic_t cm_connects;
32380-atomic_t cm_accepts;
32381-atomic_t cm_disconnects;
32382-atomic_t cm_closes;
32383-atomic_t cm_connecteds;
32384-atomic_t cm_connect_reqs;
32385-atomic_t cm_rejects;
32386+atomic_unchecked_t cm_connects;
32387+atomic_unchecked_t cm_accepts;
32388+atomic_unchecked_t cm_disconnects;
32389+atomic_unchecked_t cm_closes;
32390+atomic_unchecked_t cm_connecteds;
32391+atomic_unchecked_t cm_connect_reqs;
32392+atomic_unchecked_t cm_rejects;
32393
32394 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32395 {
32396@@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32397 kfree(listener);
32398 listener = NULL;
32399 ret = 0;
32400- atomic_inc(&cm_listens_destroyed);
32401+ atomic_inc_unchecked(&cm_listens_destroyed);
32402 } else {
32403 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32404 }
32405@@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32406 cm_node->rem_mac);
32407
32408 add_hte_node(cm_core, cm_node);
32409- atomic_inc(&cm_nodes_created);
32410+ atomic_inc_unchecked(&cm_nodes_created);
32411
32412 return cm_node;
32413 }
32414@@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32415 }
32416
32417 atomic_dec(&cm_core->node_cnt);
32418- atomic_inc(&cm_nodes_destroyed);
32419+ atomic_inc_unchecked(&cm_nodes_destroyed);
32420 nesqp = cm_node->nesqp;
32421 if (nesqp) {
32422 nesqp->cm_node = NULL;
32423@@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32424
32425 static void drop_packet(struct sk_buff *skb)
32426 {
32427- atomic_inc(&cm_accel_dropped_pkts);
32428+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
32429 dev_kfree_skb_any(skb);
32430 }
32431
32432@@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32433 {
32434
32435 int reset = 0; /* whether to send reset in case of err.. */
32436- atomic_inc(&cm_resets_recvd);
32437+ atomic_inc_unchecked(&cm_resets_recvd);
32438 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32439 " refcnt=%d\n", cm_node, cm_node->state,
32440 atomic_read(&cm_node->ref_count));
32441@@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32442 rem_ref_cm_node(cm_node->cm_core, cm_node);
32443 return NULL;
32444 }
32445- atomic_inc(&cm_loopbacks);
32446+ atomic_inc_unchecked(&cm_loopbacks);
32447 loopbackremotenode->loopbackpartner = cm_node;
32448 loopbackremotenode->tcp_cntxt.rcv_wscale =
32449 NES_CM_DEFAULT_RCV_WND_SCALE;
32450@@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32451 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32452 else {
32453 rem_ref_cm_node(cm_core, cm_node);
32454- atomic_inc(&cm_accel_dropped_pkts);
32455+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
32456 dev_kfree_skb_any(skb);
32457 }
32458 break;
32459@@ -2890,7 +2890,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32460
32461 if ((cm_id) && (cm_id->event_handler)) {
32462 if (issue_disconn) {
32463- atomic_inc(&cm_disconnects);
32464+ atomic_inc_unchecked(&cm_disconnects);
32465 cm_event.event = IW_CM_EVENT_DISCONNECT;
32466 cm_event.status = disconn_status;
32467 cm_event.local_addr = cm_id->local_addr;
32468@@ -2912,7 +2912,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32469 }
32470
32471 if (issue_close) {
32472- atomic_inc(&cm_closes);
32473+ atomic_inc_unchecked(&cm_closes);
32474 nes_disconnect(nesqp, 1);
32475
32476 cm_id->provider_data = nesqp;
32477@@ -3048,7 +3048,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32478
32479 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32480 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32481- atomic_inc(&cm_accepts);
32482+ atomic_inc_unchecked(&cm_accepts);
32483
32484 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32485 netdev_refcnt_read(nesvnic->netdev));
32486@@ -3250,7 +3250,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32487 struct nes_cm_core *cm_core;
32488 u8 *start_buff;
32489
32490- atomic_inc(&cm_rejects);
32491+ atomic_inc_unchecked(&cm_rejects);
32492 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32493 loopback = cm_node->loopbackpartner;
32494 cm_core = cm_node->cm_core;
32495@@ -3310,7 +3310,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32496 ntohl(cm_id->local_addr.sin_addr.s_addr),
32497 ntohs(cm_id->local_addr.sin_port));
32498
32499- atomic_inc(&cm_connects);
32500+ atomic_inc_unchecked(&cm_connects);
32501 nesqp->active_conn = 1;
32502
32503 /* cache the cm_id in the qp */
32504@@ -3416,7 +3416,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32505 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32506 return err;
32507 }
32508- atomic_inc(&cm_listens_created);
32509+ atomic_inc_unchecked(&cm_listens_created);
32510 }
32511
32512 cm_id->add_ref(cm_id);
32513@@ -3517,7 +3517,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32514
32515 if (nesqp->destroyed)
32516 return;
32517- atomic_inc(&cm_connecteds);
32518+ atomic_inc_unchecked(&cm_connecteds);
32519 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32520 " local port 0x%04X. jiffies = %lu.\n",
32521 nesqp->hwqp.qp_id,
32522@@ -3704,7 +3704,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32523
32524 cm_id->add_ref(cm_id);
32525 ret = cm_id->event_handler(cm_id, &cm_event);
32526- atomic_inc(&cm_closes);
32527+ atomic_inc_unchecked(&cm_closes);
32528 cm_event.event = IW_CM_EVENT_CLOSE;
32529 cm_event.status = 0;
32530 cm_event.provider_data = cm_id->provider_data;
32531@@ -3740,7 +3740,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32532 return;
32533 cm_id = cm_node->cm_id;
32534
32535- atomic_inc(&cm_connect_reqs);
32536+ atomic_inc_unchecked(&cm_connect_reqs);
32537 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32538 cm_node, cm_id, jiffies);
32539
32540@@ -3780,7 +3780,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32541 return;
32542 cm_id = cm_node->cm_id;
32543
32544- atomic_inc(&cm_connect_reqs);
32545+ atomic_inc_unchecked(&cm_connect_reqs);
32546 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32547 cm_node, cm_id, jiffies);
32548
32549diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32550index 3ba7be3..c81f6ff 100644
32551--- a/drivers/infiniband/hw/nes/nes_mgt.c
32552+++ b/drivers/infiniband/hw/nes/nes_mgt.c
32553@@ -40,8 +40,8 @@
32554 #include "nes.h"
32555 #include "nes_mgt.h"
32556
32557-atomic_t pau_qps_created;
32558-atomic_t pau_qps_destroyed;
32559+atomic_unchecked_t pau_qps_created;
32560+atomic_unchecked_t pau_qps_destroyed;
32561
32562 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32563 {
32564@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32565 {
32566 struct sk_buff *skb;
32567 unsigned long flags;
32568- atomic_inc(&pau_qps_destroyed);
32569+ atomic_inc_unchecked(&pau_qps_destroyed);
32570
32571 /* Free packets that have not yet been forwarded */
32572 /* Lock is acquired by skb_dequeue when removing the skb */
32573@@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32574 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32575 skb_queue_head_init(&nesqp->pau_list);
32576 spin_lock_init(&nesqp->pau_lock);
32577- atomic_inc(&pau_qps_created);
32578+ atomic_inc_unchecked(&pau_qps_created);
32579 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32580 }
32581
32582diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32583index f3a3ecf..57d311d 100644
32584--- a/drivers/infiniband/hw/nes/nes_nic.c
32585+++ b/drivers/infiniband/hw/nes/nes_nic.c
32586@@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32587 target_stat_values[++index] = mh_detected;
32588 target_stat_values[++index] = mh_pauses_sent;
32589 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32590- target_stat_values[++index] = atomic_read(&cm_connects);
32591- target_stat_values[++index] = atomic_read(&cm_accepts);
32592- target_stat_values[++index] = atomic_read(&cm_disconnects);
32593- target_stat_values[++index] = atomic_read(&cm_connecteds);
32594- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32595- target_stat_values[++index] = atomic_read(&cm_rejects);
32596- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32597- target_stat_values[++index] = atomic_read(&qps_created);
32598- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32599- target_stat_values[++index] = atomic_read(&qps_destroyed);
32600- target_stat_values[++index] = atomic_read(&cm_closes);
32601+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32602+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32603+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32604+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32605+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32606+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32607+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32608+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32609+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32610+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32611+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32612 target_stat_values[++index] = cm_packets_sent;
32613 target_stat_values[++index] = cm_packets_bounced;
32614 target_stat_values[++index] = cm_packets_created;
32615 target_stat_values[++index] = cm_packets_received;
32616 target_stat_values[++index] = cm_packets_dropped;
32617 target_stat_values[++index] = cm_packets_retrans;
32618- target_stat_values[++index] = atomic_read(&cm_listens_created);
32619- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32620+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32621+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32622 target_stat_values[++index] = cm_backlog_drops;
32623- target_stat_values[++index] = atomic_read(&cm_loopbacks);
32624- target_stat_values[++index] = atomic_read(&cm_nodes_created);
32625- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32626- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32627- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32628+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32629+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32630+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32631+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32632+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32633 target_stat_values[++index] = nesadapter->free_4kpbl;
32634 target_stat_values[++index] = nesadapter->free_256pbl;
32635 target_stat_values[++index] = int_mod_timer_init;
32636 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32637 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32638 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32639- target_stat_values[++index] = atomic_read(&pau_qps_created);
32640- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32641+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32642+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32643 }
32644
32645 /**
32646diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32647index 8b8812d..a5e1133 100644
32648--- a/drivers/infiniband/hw/nes/nes_verbs.c
32649+++ b/drivers/infiniband/hw/nes/nes_verbs.c
32650@@ -46,9 +46,9 @@
32651
32652 #include <rdma/ib_umem.h>
32653
32654-atomic_t mod_qp_timouts;
32655-atomic_t qps_created;
32656-atomic_t sw_qps_destroyed;
32657+atomic_unchecked_t mod_qp_timouts;
32658+atomic_unchecked_t qps_created;
32659+atomic_unchecked_t sw_qps_destroyed;
32660
32661 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32662
32663@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32664 if (init_attr->create_flags)
32665 return ERR_PTR(-EINVAL);
32666
32667- atomic_inc(&qps_created);
32668+ atomic_inc_unchecked(&qps_created);
32669 switch (init_attr->qp_type) {
32670 case IB_QPT_RC:
32671 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32672@@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32673 struct iw_cm_event cm_event;
32674 int ret = 0;
32675
32676- atomic_inc(&sw_qps_destroyed);
32677+ atomic_inc_unchecked(&sw_qps_destroyed);
32678 nesqp->destroyed = 1;
32679
32680 /* Blow away the connection if it exists. */
32681diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32682index 6b811e3..f8acf88 100644
32683--- a/drivers/infiniband/hw/qib/qib.h
32684+++ b/drivers/infiniband/hw/qib/qib.h
32685@@ -51,6 +51,7 @@
32686 #include <linux/completion.h>
32687 #include <linux/kref.h>
32688 #include <linux/sched.h>
32689+#include <linux/slab.h>
32690
32691 #include "qib_common.h"
32692 #include "qib_verbs.h"
32693diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32694index da739d9..da1c7f4 100644
32695--- a/drivers/input/gameport/gameport.c
32696+++ b/drivers/input/gameport/gameport.c
32697@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32698 */
32699 static void gameport_init_port(struct gameport *gameport)
32700 {
32701- static atomic_t gameport_no = ATOMIC_INIT(0);
32702+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32703
32704 __module_get(THIS_MODULE);
32705
32706 mutex_init(&gameport->drv_mutex);
32707 device_initialize(&gameport->dev);
32708 dev_set_name(&gameport->dev, "gameport%lu",
32709- (unsigned long)atomic_inc_return(&gameport_no) - 1);
32710+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32711 gameport->dev.bus = &gameport_bus;
32712 gameport->dev.release = gameport_release_port;
32713 if (gameport->parent)
32714diff --git a/drivers/input/input.c b/drivers/input/input.c
32715index 8921c61..f5cd63d 100644
32716--- a/drivers/input/input.c
32717+++ b/drivers/input/input.c
32718@@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32719 */
32720 int input_register_device(struct input_dev *dev)
32721 {
32722- static atomic_t input_no = ATOMIC_INIT(0);
32723+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32724 struct input_handler *handler;
32725 const char *path;
32726 int error;
32727@@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32728 dev->setkeycode = input_default_setkeycode;
32729
32730 dev_set_name(&dev->dev, "input%ld",
32731- (unsigned long) atomic_inc_return(&input_no) - 1);
32732+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32733
32734 error = device_add(&dev->dev);
32735 if (error)
32736diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32737index b8d8611..7a4a04b 100644
32738--- a/drivers/input/joystick/sidewinder.c
32739+++ b/drivers/input/joystick/sidewinder.c
32740@@ -30,6 +30,7 @@
32741 #include <linux/kernel.h>
32742 #include <linux/module.h>
32743 #include <linux/slab.h>
32744+#include <linux/sched.h>
32745 #include <linux/init.h>
32746 #include <linux/input.h>
32747 #include <linux/gameport.h>
32748diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32749index fd7a0d5..a4af10c 100644
32750--- a/drivers/input/joystick/xpad.c
32751+++ b/drivers/input/joystick/xpad.c
32752@@ -710,7 +710,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32753
32754 static int xpad_led_probe(struct usb_xpad *xpad)
32755 {
32756- static atomic_t led_seq = ATOMIC_INIT(0);
32757+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32758 long led_no;
32759 struct xpad_led *led;
32760 struct led_classdev *led_cdev;
32761@@ -723,7 +723,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32762 if (!led)
32763 return -ENOMEM;
32764
32765- led_no = (long)atomic_inc_return(&led_seq) - 1;
32766+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32767
32768 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32769 led->xpad = xpad;
32770diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32771index 0110b5a..d3ad144 100644
32772--- a/drivers/input/mousedev.c
32773+++ b/drivers/input/mousedev.c
32774@@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32775
32776 spin_unlock_irq(&client->packet_lock);
32777
32778- if (copy_to_user(buffer, data, count))
32779+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
32780 return -EFAULT;
32781
32782 return count;
32783diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
32784index d0f7533..fb8215b 100644
32785--- a/drivers/input/serio/serio.c
32786+++ b/drivers/input/serio/serio.c
32787@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
32788 */
32789 static void serio_init_port(struct serio *serio)
32790 {
32791- static atomic_t serio_no = ATOMIC_INIT(0);
32792+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
32793
32794 __module_get(THIS_MODULE);
32795
32796@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
32797 mutex_init(&serio->drv_mutex);
32798 device_initialize(&serio->dev);
32799 dev_set_name(&serio->dev, "serio%ld",
32800- (long)atomic_inc_return(&serio_no) - 1);
32801+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
32802 serio->dev.bus = &serio_bus;
32803 serio->dev.release = serio_release_port;
32804 serio->dev.groups = serio_device_attr_groups;
32805diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
32806index b902794..fc7b85b 100644
32807--- a/drivers/isdn/capi/capi.c
32808+++ b/drivers/isdn/capi/capi.c
32809@@ -83,8 +83,8 @@ struct capiminor {
32810
32811 struct capi20_appl *ap;
32812 u32 ncci;
32813- atomic_t datahandle;
32814- atomic_t msgid;
32815+ atomic_unchecked_t datahandle;
32816+ atomic_unchecked_t msgid;
32817
32818 struct tty_port port;
32819 int ttyinstop;
32820@@ -397,7 +397,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
32821 capimsg_setu16(s, 2, mp->ap->applid);
32822 capimsg_setu8 (s, 4, CAPI_DATA_B3);
32823 capimsg_setu8 (s, 5, CAPI_RESP);
32824- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
32825+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
32826 capimsg_setu32(s, 8, mp->ncci);
32827 capimsg_setu16(s, 12, datahandle);
32828 }
32829@@ -518,14 +518,14 @@ static void handle_minor_send(struct capiminor *mp)
32830 mp->outbytes -= len;
32831 spin_unlock_bh(&mp->outlock);
32832
32833- datahandle = atomic_inc_return(&mp->datahandle);
32834+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
32835 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
32836 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32837 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32838 capimsg_setu16(skb->data, 2, mp->ap->applid);
32839 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
32840 capimsg_setu8 (skb->data, 5, CAPI_REQ);
32841- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
32842+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
32843 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
32844 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
32845 capimsg_setu16(skb->data, 16, len); /* Data length */
32846diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
32847index 821f7ac..28d4030 100644
32848--- a/drivers/isdn/hardware/avm/b1.c
32849+++ b/drivers/isdn/hardware/avm/b1.c
32850@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
32851 }
32852 if (left) {
32853 if (t4file->user) {
32854- if (copy_from_user(buf, dp, left))
32855+ if (left > sizeof buf || copy_from_user(buf, dp, left))
32856 return -EFAULT;
32857 } else {
32858 memcpy(buf, dp, left);
32859@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
32860 }
32861 if (left) {
32862 if (config->user) {
32863- if (copy_from_user(buf, dp, left))
32864+ if (left > sizeof buf || copy_from_user(buf, dp, left))
32865 return -EFAULT;
32866 } else {
32867 memcpy(buf, dp, left);
32868diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
32869index dd6b53a..19d9ee6 100644
32870--- a/drivers/isdn/hardware/eicon/divasync.h
32871+++ b/drivers/isdn/hardware/eicon/divasync.h
32872@@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
32873 } diva_didd_add_adapter_t;
32874 typedef struct _diva_didd_remove_adapter {
32875 IDI_CALL p_request;
32876-} diva_didd_remove_adapter_t;
32877+} __no_const diva_didd_remove_adapter_t;
32878 typedef struct _diva_didd_read_adapter_array {
32879 void *buffer;
32880 dword length;
32881diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
32882index d303e65..28bcb7b 100644
32883--- a/drivers/isdn/hardware/eicon/xdi_adapter.h
32884+++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
32885@@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
32886 typedef struct _diva_os_idi_adapter_interface {
32887 diva_init_card_proc_t cleanup_adapter_proc;
32888 diva_cmd_card_proc_t cmd_proc;
32889-} diva_os_idi_adapter_interface_t;
32890+} __no_const diva_os_idi_adapter_interface_t;
32891
32892 typedef struct _diva_os_xdi_adapter {
32893 struct list_head link;
32894diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
32895index e74df7c..03a03ba 100644
32896--- a/drivers/isdn/icn/icn.c
32897+++ b/drivers/isdn/icn/icn.c
32898@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
32899 if (count > len)
32900 count = len;
32901 if (user) {
32902- if (copy_from_user(msg, buf, count))
32903+ if (count > sizeof msg || copy_from_user(msg, buf, count))
32904 return -EFAULT;
32905 } else
32906 memcpy(msg, buf, count);
32907diff --git a/drivers/leds/leds-mc13783.c b/drivers/leds/leds-mc13783.c
32908index 8bc4915..4cc6a2e 100644
32909--- a/drivers/leds/leds-mc13783.c
32910+++ b/drivers/leds/leds-mc13783.c
32911@@ -280,7 +280,7 @@ static int __devinit mc13783_led_probe(struct platform_device *pdev)
32912 return -EINVAL;
32913 }
32914
32915- led = kzalloc(sizeof(*led) * pdata->num_leds, GFP_KERNEL);
32916+ led = kcalloc(pdata->num_leds, sizeof(*led), GFP_KERNEL);
32917 if (led == NULL) {
32918 dev_err(&pdev->dev, "failed to alloc memory\n");
32919 return -ENOMEM;
32920diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
32921index b5fdcb7..5b6c59f 100644
32922--- a/drivers/lguest/core.c
32923+++ b/drivers/lguest/core.c
32924@@ -92,9 +92,17 @@ static __init int map_switcher(void)
32925 * it's worked so far. The end address needs +1 because __get_vm_area
32926 * allocates an extra guard page, so we need space for that.
32927 */
32928+
32929+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32930+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32931+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
32932+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32933+#else
32934 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32935 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
32936 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32937+#endif
32938+
32939 if (!switcher_vma) {
32940 err = -ENOMEM;
32941 printk("lguest: could not map switcher pages high\n");
32942@@ -119,7 +127,7 @@ static __init int map_switcher(void)
32943 * Now the Switcher is mapped at the right address, we can't fail!
32944 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
32945 */
32946- memcpy(switcher_vma->addr, start_switcher_text,
32947+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
32948 end_switcher_text - start_switcher_text);
32949
32950 printk(KERN_INFO "lguest: mapped switcher at %p\n",
32951diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
32952index 3980903..ce25c5e 100644
32953--- a/drivers/lguest/x86/core.c
32954+++ b/drivers/lguest/x86/core.c
32955@@ -59,7 +59,7 @@ static struct {
32956 /* Offset from where switcher.S was compiled to where we've copied it */
32957 static unsigned long switcher_offset(void)
32958 {
32959- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
32960+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
32961 }
32962
32963 /* This cpu's struct lguest_pages. */
32964@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
32965 * These copies are pretty cheap, so we do them unconditionally: */
32966 /* Save the current Host top-level page directory.
32967 */
32968+
32969+#ifdef CONFIG_PAX_PER_CPU_PGD
32970+ pages->state.host_cr3 = read_cr3();
32971+#else
32972 pages->state.host_cr3 = __pa(current->mm->pgd);
32973+#endif
32974+
32975 /*
32976 * Set up the Guest's page tables to see this CPU's pages (and no
32977 * other CPU's pages).
32978@@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
32979 * compiled-in switcher code and the high-mapped copy we just made.
32980 */
32981 for (i = 0; i < IDT_ENTRIES; i++)
32982- default_idt_entries[i] += switcher_offset();
32983+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
32984
32985 /*
32986 * Set up the Switcher's per-cpu areas.
32987@@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
32988 * it will be undisturbed when we switch. To change %cs and jump we
32989 * need this structure to feed to Intel's "lcall" instruction.
32990 */
32991- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
32992+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
32993 lguest_entry.segment = LGUEST_CS;
32994
32995 /*
32996diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
32997index 40634b0..4f5855e 100644
32998--- a/drivers/lguest/x86/switcher_32.S
32999+++ b/drivers/lguest/x86/switcher_32.S
33000@@ -87,6 +87,7 @@
33001 #include <asm/page.h>
33002 #include <asm/segment.h>
33003 #include <asm/lguest.h>
33004+#include <asm/processor-flags.h>
33005
33006 // We mark the start of the code to copy
33007 // It's placed in .text tho it's never run here
33008@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33009 // Changes type when we load it: damn Intel!
33010 // For after we switch over our page tables
33011 // That entry will be read-only: we'd crash.
33012+
33013+#ifdef CONFIG_PAX_KERNEXEC
33014+ mov %cr0, %edx
33015+ xor $X86_CR0_WP, %edx
33016+ mov %edx, %cr0
33017+#endif
33018+
33019 movl $(GDT_ENTRY_TSS*8), %edx
33020 ltr %dx
33021
33022@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33023 // Let's clear it again for our return.
33024 // The GDT descriptor of the Host
33025 // Points to the table after two "size" bytes
33026- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33027+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33028 // Clear "used" from type field (byte 5, bit 2)
33029- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33030+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33031+
33032+#ifdef CONFIG_PAX_KERNEXEC
33033+ mov %cr0, %eax
33034+ xor $X86_CR0_WP, %eax
33035+ mov %eax, %cr0
33036+#endif
33037
33038 // Once our page table's switched, the Guest is live!
33039 // The Host fades as we run this final step.
33040@@ -295,13 +309,12 @@ deliver_to_host:
33041 // I consulted gcc, and it gave
33042 // These instructions, which I gladly credit:
33043 leal (%edx,%ebx,8), %eax
33044- movzwl (%eax),%edx
33045- movl 4(%eax), %eax
33046- xorw %ax, %ax
33047- orl %eax, %edx
33048+ movl 4(%eax), %edx
33049+ movw (%eax), %dx
33050 // Now the address of the handler's in %edx
33051 // We call it now: its "iret" drops us home.
33052- jmp *%edx
33053+ ljmp $__KERNEL_CS, $1f
33054+1: jmp *%edx
33055
33056 // Every interrupt can come to us here
33057 // But we must truly tell each apart.
33058diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33059index 20e5c2c..9e849a9 100644
33060--- a/drivers/macintosh/macio_asic.c
33061+++ b/drivers/macintosh/macio_asic.c
33062@@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33063 * MacIO is matched against any Apple ID, it's probe() function
33064 * will then decide wether it applies or not
33065 */
33066-static const struct pci_device_id __devinitdata pci_ids [] = { {
33067+static const struct pci_device_id __devinitconst pci_ids [] = { {
33068 .vendor = PCI_VENDOR_ID_APPLE,
33069 .device = PCI_ANY_ID,
33070 .subvendor = PCI_ANY_ID,
33071diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33072index 17e2b47..bcbeec4 100644
33073--- a/drivers/md/bitmap.c
33074+++ b/drivers/md/bitmap.c
33075@@ -1823,7 +1823,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33076 chunk_kb ? "KB" : "B");
33077 if (bitmap->file) {
33078 seq_printf(seq, ", file: ");
33079- seq_path(seq, &bitmap->file->f_path, " \t\n");
33080+ seq_path(seq, &bitmap->file->f_path, " \t\n\\");
33081 }
33082
33083 seq_printf(seq, "\n");
33084diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33085index a1a3e6d..1918bfc 100644
33086--- a/drivers/md/dm-ioctl.c
33087+++ b/drivers/md/dm-ioctl.c
33088@@ -1590,7 +1590,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33089 cmd == DM_LIST_VERSIONS_CMD)
33090 return 0;
33091
33092- if ((cmd == DM_DEV_CREATE_CMD)) {
33093+ if (cmd == DM_DEV_CREATE_CMD) {
33094 if (!*param->name) {
33095 DMWARN("name not supplied when creating device");
33096 return -EINVAL;
33097diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33098index d039de8..0cf5b87 100644
33099--- a/drivers/md/dm-raid1.c
33100+++ b/drivers/md/dm-raid1.c
33101@@ -40,7 +40,7 @@ enum dm_raid1_error {
33102
33103 struct mirror {
33104 struct mirror_set *ms;
33105- atomic_t error_count;
33106+ atomic_unchecked_t error_count;
33107 unsigned long error_type;
33108 struct dm_dev *dev;
33109 sector_t offset;
33110@@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33111 struct mirror *m;
33112
33113 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33114- if (!atomic_read(&m->error_count))
33115+ if (!atomic_read_unchecked(&m->error_count))
33116 return m;
33117
33118 return NULL;
33119@@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33120 * simple way to tell if a device has encountered
33121 * errors.
33122 */
33123- atomic_inc(&m->error_count);
33124+ atomic_inc_unchecked(&m->error_count);
33125
33126 if (test_and_set_bit(error_type, &m->error_type))
33127 return;
33128@@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33129 struct mirror *m = get_default_mirror(ms);
33130
33131 do {
33132- if (likely(!atomic_read(&m->error_count)))
33133+ if (likely(!atomic_read_unchecked(&m->error_count)))
33134 return m;
33135
33136 if (m-- == ms->mirror)
33137@@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33138 {
33139 struct mirror *default_mirror = get_default_mirror(m->ms);
33140
33141- return !atomic_read(&default_mirror->error_count);
33142+ return !atomic_read_unchecked(&default_mirror->error_count);
33143 }
33144
33145 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33146@@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33147 */
33148 if (likely(region_in_sync(ms, region, 1)))
33149 m = choose_mirror(ms, bio->bi_sector);
33150- else if (m && atomic_read(&m->error_count))
33151+ else if (m && atomic_read_unchecked(&m->error_count))
33152 m = NULL;
33153
33154 if (likely(m))
33155@@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33156 }
33157
33158 ms->mirror[mirror].ms = ms;
33159- atomic_set(&(ms->mirror[mirror].error_count), 0);
33160+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33161 ms->mirror[mirror].error_type = 0;
33162 ms->mirror[mirror].offset = offset;
33163
33164@@ -1351,7 +1351,7 @@ static void mirror_resume(struct dm_target *ti)
33165 */
33166 static char device_status_char(struct mirror *m)
33167 {
33168- if (!atomic_read(&(m->error_count)))
33169+ if (!atomic_read_unchecked(&(m->error_count)))
33170 return 'A';
33171
33172 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33173diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33174index 35c94ff..20d4c17 100644
33175--- a/drivers/md/dm-stripe.c
33176+++ b/drivers/md/dm-stripe.c
33177@@ -20,7 +20,7 @@ struct stripe {
33178 struct dm_dev *dev;
33179 sector_t physical_start;
33180
33181- atomic_t error_count;
33182+ atomic_unchecked_t error_count;
33183 };
33184
33185 struct stripe_c {
33186@@ -193,7 +193,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33187 kfree(sc);
33188 return r;
33189 }
33190- atomic_set(&(sc->stripe[i].error_count), 0);
33191+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33192 }
33193
33194 ti->private = sc;
33195@@ -315,7 +315,7 @@ static int stripe_status(struct dm_target *ti,
33196 DMEMIT("%d ", sc->stripes);
33197 for (i = 0; i < sc->stripes; i++) {
33198 DMEMIT("%s ", sc->stripe[i].dev->name);
33199- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33200+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33201 'D' : 'A';
33202 }
33203 buffer[i] = '\0';
33204@@ -362,8 +362,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33205 */
33206 for (i = 0; i < sc->stripes; i++)
33207 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33208- atomic_inc(&(sc->stripe[i].error_count));
33209- if (atomic_read(&(sc->stripe[i].error_count)) <
33210+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
33211+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33212 DM_IO_ERROR_THRESHOLD)
33213 schedule_work(&sc->trigger_event);
33214 }
33215diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33216index 2e227fb..44ead1f 100644
33217--- a/drivers/md/dm-table.c
33218+++ b/drivers/md/dm-table.c
33219@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33220 if (!dev_size)
33221 return 0;
33222
33223- if ((start >= dev_size) || (start + len > dev_size)) {
33224+ if ((start >= dev_size) || (len > dev_size - start)) {
33225 DMWARN("%s: %s too small for target: "
33226 "start=%llu, len=%llu, dev_size=%llu",
33227 dm_device_name(ti->table->md), bdevname(bdev, b),
33228diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33229index 737d388..811ad5a 100644
33230--- a/drivers/md/dm-thin-metadata.c
33231+++ b/drivers/md/dm-thin-metadata.c
33232@@ -432,7 +432,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33233
33234 pmd->info.tm = tm;
33235 pmd->info.levels = 2;
33236- pmd->info.value_type.context = pmd->data_sm;
33237+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33238 pmd->info.value_type.size = sizeof(__le64);
33239 pmd->info.value_type.inc = data_block_inc;
33240 pmd->info.value_type.dec = data_block_dec;
33241@@ -451,7 +451,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33242
33243 pmd->bl_info.tm = tm;
33244 pmd->bl_info.levels = 1;
33245- pmd->bl_info.value_type.context = pmd->data_sm;
33246+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33247 pmd->bl_info.value_type.size = sizeof(__le64);
33248 pmd->bl_info.value_type.inc = data_block_inc;
33249 pmd->bl_info.value_type.dec = data_block_dec;
33250diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33251index e24143c..ce2f21a1 100644
33252--- a/drivers/md/dm.c
33253+++ b/drivers/md/dm.c
33254@@ -176,9 +176,9 @@ struct mapped_device {
33255 /*
33256 * Event handling.
33257 */
33258- atomic_t event_nr;
33259+ atomic_unchecked_t event_nr;
33260 wait_queue_head_t eventq;
33261- atomic_t uevent_seq;
33262+ atomic_unchecked_t uevent_seq;
33263 struct list_head uevent_list;
33264 spinlock_t uevent_lock; /* Protect access to uevent_list */
33265
33266@@ -1845,8 +1845,8 @@ static struct mapped_device *alloc_dev(int minor)
33267 rwlock_init(&md->map_lock);
33268 atomic_set(&md->holders, 1);
33269 atomic_set(&md->open_count, 0);
33270- atomic_set(&md->event_nr, 0);
33271- atomic_set(&md->uevent_seq, 0);
33272+ atomic_set_unchecked(&md->event_nr, 0);
33273+ atomic_set_unchecked(&md->uevent_seq, 0);
33274 INIT_LIST_HEAD(&md->uevent_list);
33275 spin_lock_init(&md->uevent_lock);
33276
33277@@ -1980,7 +1980,7 @@ static void event_callback(void *context)
33278
33279 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33280
33281- atomic_inc(&md->event_nr);
33282+ atomic_inc_unchecked(&md->event_nr);
33283 wake_up(&md->eventq);
33284 }
33285
33286@@ -2622,18 +2622,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33287
33288 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33289 {
33290- return atomic_add_return(1, &md->uevent_seq);
33291+ return atomic_add_return_unchecked(1, &md->uevent_seq);
33292 }
33293
33294 uint32_t dm_get_event_nr(struct mapped_device *md)
33295 {
33296- return atomic_read(&md->event_nr);
33297+ return atomic_read_unchecked(&md->event_nr);
33298 }
33299
33300 int dm_wait_event(struct mapped_device *md, int event_nr)
33301 {
33302 return wait_event_interruptible(md->eventq,
33303- (event_nr != atomic_read(&md->event_nr)));
33304+ (event_nr != atomic_read_unchecked(&md->event_nr)));
33305 }
33306
33307 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33308diff --git a/drivers/md/md.c b/drivers/md/md.c
33309index 2b30ffd..bf789ce 100644
33310--- a/drivers/md/md.c
33311+++ b/drivers/md/md.c
33312@@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33313 * start build, activate spare
33314 */
33315 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33316-static atomic_t md_event_count;
33317+static atomic_unchecked_t md_event_count;
33318 void md_new_event(struct mddev *mddev)
33319 {
33320- atomic_inc(&md_event_count);
33321+ atomic_inc_unchecked(&md_event_count);
33322 wake_up(&md_event_waiters);
33323 }
33324 EXPORT_SYMBOL_GPL(md_new_event);
33325@@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33326 */
33327 static void md_new_event_inintr(struct mddev *mddev)
33328 {
33329- atomic_inc(&md_event_count);
33330+ atomic_inc_unchecked(&md_event_count);
33331 wake_up(&md_event_waiters);
33332 }
33333
33334@@ -1526,7 +1526,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33335
33336 rdev->preferred_minor = 0xffff;
33337 rdev->data_offset = le64_to_cpu(sb->data_offset);
33338- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33339+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33340
33341 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33342 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33343@@ -1745,7 +1745,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33344 else
33345 sb->resync_offset = cpu_to_le64(0);
33346
33347- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33348+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33349
33350 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33351 sb->size = cpu_to_le64(mddev->dev_sectors);
33352@@ -2691,7 +2691,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33353 static ssize_t
33354 errors_show(struct md_rdev *rdev, char *page)
33355 {
33356- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33357+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33358 }
33359
33360 static ssize_t
33361@@ -2700,7 +2700,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33362 char *e;
33363 unsigned long n = simple_strtoul(buf, &e, 10);
33364 if (*buf && (*e == 0 || *e == '\n')) {
33365- atomic_set(&rdev->corrected_errors, n);
33366+ atomic_set_unchecked(&rdev->corrected_errors, n);
33367 return len;
33368 }
33369 return -EINVAL;
33370@@ -3086,8 +3086,8 @@ int md_rdev_init(struct md_rdev *rdev)
33371 rdev->sb_loaded = 0;
33372 rdev->bb_page = NULL;
33373 atomic_set(&rdev->nr_pending, 0);
33374- atomic_set(&rdev->read_errors, 0);
33375- atomic_set(&rdev->corrected_errors, 0);
33376+ atomic_set_unchecked(&rdev->read_errors, 0);
33377+ atomic_set_unchecked(&rdev->corrected_errors, 0);
33378
33379 INIT_LIST_HEAD(&rdev->same_set);
33380 init_waitqueue_head(&rdev->blocked_wait);
33381@@ -6738,7 +6738,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33382
33383 spin_unlock(&pers_lock);
33384 seq_printf(seq, "\n");
33385- seq->poll_event = atomic_read(&md_event_count);
33386+ seq->poll_event = atomic_read_unchecked(&md_event_count);
33387 return 0;
33388 }
33389 if (v == (void*)2) {
33390@@ -6841,7 +6841,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33391 return error;
33392
33393 seq = file->private_data;
33394- seq->poll_event = atomic_read(&md_event_count);
33395+ seq->poll_event = atomic_read_unchecked(&md_event_count);
33396 return error;
33397 }
33398
33399@@ -6855,7 +6855,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33400 /* always allow read */
33401 mask = POLLIN | POLLRDNORM;
33402
33403- if (seq->poll_event != atomic_read(&md_event_count))
33404+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33405 mask |= POLLERR | POLLPRI;
33406 return mask;
33407 }
33408@@ -6899,7 +6899,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33409 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33410 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33411 (int)part_stat_read(&disk->part0, sectors[1]) -
33412- atomic_read(&disk->sync_io);
33413+ atomic_read_unchecked(&disk->sync_io);
33414 /* sync IO will cause sync_io to increase before the disk_stats
33415 * as sync_io is counted when a request starts, and
33416 * disk_stats is counted when it completes.
33417diff --git a/drivers/md/md.h b/drivers/md/md.h
33418index 1c2063c..9639970 100644
33419--- a/drivers/md/md.h
33420+++ b/drivers/md/md.h
33421@@ -93,13 +93,13 @@ struct md_rdev {
33422 * only maintained for arrays that
33423 * support hot removal
33424 */
33425- atomic_t read_errors; /* number of consecutive read errors that
33426+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
33427 * we have tried to ignore.
33428 */
33429 struct timespec last_read_error; /* monotonic time since our
33430 * last read error
33431 */
33432- atomic_t corrected_errors; /* number of corrected read errors,
33433+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33434 * for reporting to userspace and storing
33435 * in superblock.
33436 */
33437@@ -429,7 +429,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33438
33439 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33440 {
33441- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33442+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33443 }
33444
33445 struct md_personality
33446diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
33447index 50ed53b..4f29d7d 100644
33448--- a/drivers/md/persistent-data/dm-space-map-checker.c
33449+++ b/drivers/md/persistent-data/dm-space-map-checker.c
33450@@ -159,7 +159,7 @@ static void ca_destroy(struct count_array *ca)
33451 /*----------------------------------------------------------------*/
33452
33453 struct sm_checker {
33454- struct dm_space_map sm;
33455+ dm_space_map_no_const sm;
33456
33457 struct count_array old_counts;
33458 struct count_array counts;
33459diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33460index fc469ba..2d91555 100644
33461--- a/drivers/md/persistent-data/dm-space-map-disk.c
33462+++ b/drivers/md/persistent-data/dm-space-map-disk.c
33463@@ -23,7 +23,7 @@
33464 * Space map interface.
33465 */
33466 struct sm_disk {
33467- struct dm_space_map sm;
33468+ dm_space_map_no_const sm;
33469
33470 struct ll_disk ll;
33471 struct ll_disk old_ll;
33472diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33473index e89ae5e..062e4c2 100644
33474--- a/drivers/md/persistent-data/dm-space-map-metadata.c
33475+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33476@@ -43,7 +43,7 @@ struct block_op {
33477 };
33478
33479 struct sm_metadata {
33480- struct dm_space_map sm;
33481+ dm_space_map_no_const sm;
33482
33483 struct ll_disk ll;
33484 struct ll_disk old_ll;
33485diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33486index 1cbfc6b..56e1dbb 100644
33487--- a/drivers/md/persistent-data/dm-space-map.h
33488+++ b/drivers/md/persistent-data/dm-space-map.h
33489@@ -60,6 +60,7 @@ struct dm_space_map {
33490 int (*root_size)(struct dm_space_map *sm, size_t *result);
33491 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33492 };
33493+typedef struct dm_space_map __no_const dm_space_map_no_const;
33494
33495 /*----------------------------------------------------------------*/
33496
33497diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33498index d7e9577..faa512f2 100644
33499--- a/drivers/md/raid1.c
33500+++ b/drivers/md/raid1.c
33501@@ -1688,7 +1688,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33502 if (r1_sync_page_io(rdev, sect, s,
33503 bio->bi_io_vec[idx].bv_page,
33504 READ) != 0)
33505- atomic_add(s, &rdev->corrected_errors);
33506+ atomic_add_unchecked(s, &rdev->corrected_errors);
33507 }
33508 sectors -= s;
33509 sect += s;
33510@@ -1902,7 +1902,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33511 test_bit(In_sync, &rdev->flags)) {
33512 if (r1_sync_page_io(rdev, sect, s,
33513 conf->tmppage, READ)) {
33514- atomic_add(s, &rdev->corrected_errors);
33515+ atomic_add_unchecked(s, &rdev->corrected_errors);
33516 printk(KERN_INFO
33517 "md/raid1:%s: read error corrected "
33518 "(%d sectors at %llu on %s)\n",
33519diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33520index d037adb..ed17dc9 100644
33521--- a/drivers/md/raid10.c
33522+++ b/drivers/md/raid10.c
33523@@ -1684,7 +1684,7 @@ static void end_sync_read(struct bio *bio, int error)
33524 /* The write handler will notice the lack of
33525 * R10BIO_Uptodate and record any errors etc
33526 */
33527- atomic_add(r10_bio->sectors,
33528+ atomic_add_unchecked(r10_bio->sectors,
33529 &conf->mirrors[d].rdev->corrected_errors);
33530
33531 /* for reconstruct, we always reschedule after a read.
33532@@ -2033,7 +2033,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33533 {
33534 struct timespec cur_time_mon;
33535 unsigned long hours_since_last;
33536- unsigned int read_errors = atomic_read(&rdev->read_errors);
33537+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33538
33539 ktime_get_ts(&cur_time_mon);
33540
33541@@ -2055,9 +2055,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33542 * overflowing the shift of read_errors by hours_since_last.
33543 */
33544 if (hours_since_last >= 8 * sizeof(read_errors))
33545- atomic_set(&rdev->read_errors, 0);
33546+ atomic_set_unchecked(&rdev->read_errors, 0);
33547 else
33548- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33549+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33550 }
33551
33552 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33553@@ -2111,8 +2111,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33554 return;
33555
33556 check_decay_read_errors(mddev, rdev);
33557- atomic_inc(&rdev->read_errors);
33558- if (atomic_read(&rdev->read_errors) > max_read_errors) {
33559+ atomic_inc_unchecked(&rdev->read_errors);
33560+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33561 char b[BDEVNAME_SIZE];
33562 bdevname(rdev->bdev, b);
33563
33564@@ -2120,7 +2120,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33565 "md/raid10:%s: %s: Raid device exceeded "
33566 "read_error threshold [cur %d:max %d]\n",
33567 mdname(mddev), b,
33568- atomic_read(&rdev->read_errors), max_read_errors);
33569+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33570 printk(KERN_NOTICE
33571 "md/raid10:%s: %s: Failing raid device\n",
33572 mdname(mddev), b);
33573@@ -2271,7 +2271,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33574 (unsigned long long)(
33575 sect + rdev->data_offset),
33576 bdevname(rdev->bdev, b));
33577- atomic_add(s, &rdev->corrected_errors);
33578+ atomic_add_unchecked(s, &rdev->corrected_errors);
33579 }
33580
33581 rdev_dec_pending(rdev, mddev);
33582diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33583index f351422..85c01bb 100644
33584--- a/drivers/md/raid5.c
33585+++ b/drivers/md/raid5.c
33586@@ -1686,18 +1686,18 @@ static void raid5_end_read_request(struct bio * bi, int error)
33587 (unsigned long long)(sh->sector
33588 + rdev->data_offset),
33589 bdevname(rdev->bdev, b));
33590- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33591+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33592 clear_bit(R5_ReadError, &sh->dev[i].flags);
33593 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33594 }
33595- if (atomic_read(&rdev->read_errors))
33596- atomic_set(&rdev->read_errors, 0);
33597+ if (atomic_read_unchecked(&rdev->read_errors))
33598+ atomic_set_unchecked(&rdev->read_errors, 0);
33599 } else {
33600 const char *bdn = bdevname(rdev->bdev, b);
33601 int retry = 0;
33602
33603 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33604- atomic_inc(&rdev->read_errors);
33605+ atomic_inc_unchecked(&rdev->read_errors);
33606 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33607 printk_ratelimited(
33608 KERN_WARNING
33609@@ -1726,7 +1726,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33610 (unsigned long long)(sh->sector
33611 + rdev->data_offset),
33612 bdn);
33613- else if (atomic_read(&rdev->read_errors)
33614+ else if (atomic_read_unchecked(&rdev->read_errors)
33615 > conf->max_nr_stripes)
33616 printk(KERN_WARNING
33617 "md/raid:%s: Too many read errors, failing device %s.\n",
33618diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33619index d88c4aa..17c80b1 100644
33620--- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33621+++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33622@@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
33623 .subvendor = _subvend, .subdevice = _subdev, \
33624 .driver_data = (unsigned long)&_driverdata }
33625
33626-static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33627+static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33628 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33629 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33630 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33631diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33632index a7d876f..8c21b61 100644
33633--- a/drivers/media/dvb/dvb-core/dvb_demux.h
33634+++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33635@@ -73,7 +73,7 @@ struct dvb_demux_feed {
33636 union {
33637 dmx_ts_cb ts;
33638 dmx_section_cb sec;
33639- } cb;
33640+ } __no_const cb;
33641
33642 struct dvb_demux *demux;
33643 void *priv;
33644diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33645index 00a6732..70a682e 100644
33646--- a/drivers/media/dvb/dvb-core/dvbdev.c
33647+++ b/drivers/media/dvb/dvb-core/dvbdev.c
33648@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33649 const struct dvb_device *template, void *priv, int type)
33650 {
33651 struct dvb_device *dvbdev;
33652- struct file_operations *dvbdevfops;
33653+ file_operations_no_const *dvbdevfops;
33654 struct device *clsdev;
33655 int minor;
33656 int id;
33657diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33658index 3940bb0..fb3952a 100644
33659--- a/drivers/media/dvb/dvb-usb/cxusb.c
33660+++ b/drivers/media/dvb/dvb-usb/cxusb.c
33661@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33662
33663 struct dib0700_adapter_state {
33664 int (*set_param_save) (struct dvb_frontend *);
33665-};
33666+} __no_const;
33667
33668 static int dib7070_set_param_override(struct dvb_frontend *fe)
33669 {
33670diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33671index 451c5a7..649f711 100644
33672--- a/drivers/media/dvb/dvb-usb/dw2102.c
33673+++ b/drivers/media/dvb/dvb-usb/dw2102.c
33674@@ -95,7 +95,7 @@ struct su3000_state {
33675
33676 struct s6x0_state {
33677 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33678-};
33679+} __no_const;
33680
33681 /* debug */
33682 static int dvb_usb_dw2102_debug;
33683diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33684index 404f63a..4796533 100644
33685--- a/drivers/media/dvb/frontends/dib3000.h
33686+++ b/drivers/media/dvb/frontends/dib3000.h
33687@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33688 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33689 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33690 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33691-};
33692+} __no_const;
33693
33694 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33695 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33696diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33697index 7539a5d..06531a6 100644
33698--- a/drivers/media/dvb/ngene/ngene-cards.c
33699+++ b/drivers/media/dvb/ngene/ngene-cards.c
33700@@ -478,7 +478,7 @@ static struct ngene_info ngene_info_m780 = {
33701
33702 /****************************************************************************/
33703
33704-static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33705+static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33706 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33707 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33708 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33709diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33710index 16a089f..1661b11 100644
33711--- a/drivers/media/radio/radio-cadet.c
33712+++ b/drivers/media/radio/radio-cadet.c
33713@@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33714 unsigned char readbuf[RDS_BUFFER];
33715 int i = 0;
33716
33717+ if (count > RDS_BUFFER)
33718+ return -EFAULT;
33719 mutex_lock(&dev->lock);
33720 if (dev->rdsstat == 0) {
33721 dev->rdsstat = 1;
33722@@ -347,7 +349,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33723 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
33724 mutex_unlock(&dev->lock);
33725
33726- if (copy_to_user(data, readbuf, i))
33727+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
33728 return -EFAULT;
33729 return i;
33730 }
33731diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
33732index 9cde353..8c6a1c3 100644
33733--- a/drivers/media/video/au0828/au0828.h
33734+++ b/drivers/media/video/au0828/au0828.h
33735@@ -191,7 +191,7 @@ struct au0828_dev {
33736
33737 /* I2C */
33738 struct i2c_adapter i2c_adap;
33739- struct i2c_algorithm i2c_algo;
33740+ i2c_algorithm_no_const i2c_algo;
33741 struct i2c_client i2c_client;
33742 u32 i2c_rc;
33743
33744diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
33745index 04bf662..e0ac026 100644
33746--- a/drivers/media/video/cx88/cx88-alsa.c
33747+++ b/drivers/media/video/cx88/cx88-alsa.c
33748@@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
33749 * Only boards with eeprom and byte 1 at eeprom=1 have it
33750 */
33751
33752-static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
33753+static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
33754 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33755 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33756 {0, }
33757diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
33758index 88cf9d9..bbc4b2c 100644
33759--- a/drivers/media/video/omap/omap_vout.c
33760+++ b/drivers/media/video/omap/omap_vout.c
33761@@ -64,7 +64,6 @@ enum omap_vout_channels {
33762 OMAP_VIDEO2,
33763 };
33764
33765-static struct videobuf_queue_ops video_vbq_ops;
33766 /* Variables configurable through module params*/
33767 static u32 video1_numbuffers = 3;
33768 static u32 video2_numbuffers = 3;
33769@@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
33770 {
33771 struct videobuf_queue *q;
33772 struct omap_vout_device *vout = NULL;
33773+ static struct videobuf_queue_ops video_vbq_ops = {
33774+ .buf_setup = omap_vout_buffer_setup,
33775+ .buf_prepare = omap_vout_buffer_prepare,
33776+ .buf_release = omap_vout_buffer_release,
33777+ .buf_queue = omap_vout_buffer_queue,
33778+ };
33779
33780 vout = video_drvdata(file);
33781 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
33782@@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
33783 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
33784
33785 q = &vout->vbq;
33786- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
33787- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
33788- video_vbq_ops.buf_release = omap_vout_buffer_release;
33789- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
33790 spin_lock_init(&vout->vbq_lock);
33791
33792 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
33793diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33794index 305e6aa..0143317 100644
33795--- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33796+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33797@@ -196,7 +196,7 @@ struct pvr2_hdw {
33798
33799 /* I2C stuff */
33800 struct i2c_adapter i2c_adap;
33801- struct i2c_algorithm i2c_algo;
33802+ i2c_algorithm_no_const i2c_algo;
33803 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
33804 int i2c_cx25840_hack_state;
33805 int i2c_linked;
33806diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
33807index 02194c0..091733b 100644
33808--- a/drivers/media/video/timblogiw.c
33809+++ b/drivers/media/video/timblogiw.c
33810@@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
33811
33812 /* Platform device functions */
33813
33814-static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33815+static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
33816 .vidioc_querycap = timblogiw_querycap,
33817 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
33818 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
33819@@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33820 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
33821 };
33822
33823-static __devinitconst struct v4l2_file_operations timblogiw_fops = {
33824+static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
33825 .owner = THIS_MODULE,
33826 .open = timblogiw_open,
33827 .release = timblogiw_close,
33828diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
33829index a5c591f..db692a3 100644
33830--- a/drivers/message/fusion/mptbase.c
33831+++ b/drivers/message/fusion/mptbase.c
33832@@ -6754,8 +6754,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
33833 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
33834 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33835
33836+#ifdef CONFIG_GRKERNSEC_HIDESYM
33837+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
33838+#else
33839 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33840 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33841+#endif
33842+
33843 /*
33844 * Rounding UP to nearest 4-kB boundary here...
33845 */
33846diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
33847index 551262e..7551198 100644
33848--- a/drivers/message/fusion/mptsas.c
33849+++ b/drivers/message/fusion/mptsas.c
33850@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
33851 return 0;
33852 }
33853
33854+static inline void
33855+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33856+{
33857+ if (phy_info->port_details) {
33858+ phy_info->port_details->rphy = rphy;
33859+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33860+ ioc->name, rphy));
33861+ }
33862+
33863+ if (rphy) {
33864+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33865+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33866+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33867+ ioc->name, rphy, rphy->dev.release));
33868+ }
33869+}
33870+
33871 /* no mutex */
33872 static void
33873 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
33874@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
33875 return NULL;
33876 }
33877
33878-static inline void
33879-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33880-{
33881- if (phy_info->port_details) {
33882- phy_info->port_details->rphy = rphy;
33883- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33884- ioc->name, rphy));
33885- }
33886-
33887- if (rphy) {
33888- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33889- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33890- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33891- ioc->name, rphy, rphy->dev.release));
33892- }
33893-}
33894-
33895 static inline struct sas_port *
33896 mptsas_get_port(struct mptsas_phyinfo *phy_info)
33897 {
33898diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
33899index 0c3ced7..1fe34ec 100644
33900--- a/drivers/message/fusion/mptscsih.c
33901+++ b/drivers/message/fusion/mptscsih.c
33902@@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
33903
33904 h = shost_priv(SChost);
33905
33906- if (h) {
33907- if (h->info_kbuf == NULL)
33908- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33909- return h->info_kbuf;
33910- h->info_kbuf[0] = '\0';
33911+ if (!h)
33912+ return NULL;
33913
33914- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33915- h->info_kbuf[size-1] = '\0';
33916- }
33917+ if (h->info_kbuf == NULL)
33918+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33919+ return h->info_kbuf;
33920+ h->info_kbuf[0] = '\0';
33921+
33922+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33923+ h->info_kbuf[size-1] = '\0';
33924
33925 return h->info_kbuf;
33926 }
33927diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
33928index 6d115c7..58ff7fd 100644
33929--- a/drivers/message/i2o/i2o_proc.c
33930+++ b/drivers/message/i2o/i2o_proc.c
33931@@ -255,13 +255,6 @@ static char *scsi_devices[] = {
33932 "Array Controller Device"
33933 };
33934
33935-static char *chtostr(u8 * chars, int n)
33936-{
33937- char tmp[256];
33938- tmp[0] = 0;
33939- return strncat(tmp, (char *)chars, n);
33940-}
33941-
33942 static int i2o_report_query_status(struct seq_file *seq, int block_status,
33943 char *group)
33944 {
33945@@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
33946
33947 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
33948 seq_printf(seq, "%-#8x", ddm_table.module_id);
33949- seq_printf(seq, "%-29s",
33950- chtostr(ddm_table.module_name_version, 28));
33951+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
33952 seq_printf(seq, "%9d ", ddm_table.data_size);
33953 seq_printf(seq, "%8d", ddm_table.code_size);
33954
33955@@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
33956
33957 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
33958 seq_printf(seq, "%-#8x", dst->module_id);
33959- seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
33960- seq_printf(seq, "%-9s", chtostr(dst->date, 8));
33961+ seq_printf(seq, "%-.28s", dst->module_name_version);
33962+ seq_printf(seq, "%-.8s", dst->date);
33963 seq_printf(seq, "%8d ", dst->module_size);
33964 seq_printf(seq, "%8d ", dst->mpb_size);
33965 seq_printf(seq, "0x%04x", dst->module_flags);
33966@@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
33967 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
33968 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
33969 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
33970- seq_printf(seq, "Vendor info : %s\n",
33971- chtostr((u8 *) (work32 + 2), 16));
33972- seq_printf(seq, "Product info : %s\n",
33973- chtostr((u8 *) (work32 + 6), 16));
33974- seq_printf(seq, "Description : %s\n",
33975- chtostr((u8 *) (work32 + 10), 16));
33976- seq_printf(seq, "Product rev. : %s\n",
33977- chtostr((u8 *) (work32 + 14), 8));
33978+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
33979+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
33980+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
33981+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
33982
33983 seq_printf(seq, "Serial number : ");
33984 print_serial_number(seq, (u8 *) (work32 + 16),
33985@@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
33986 }
33987
33988 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
33989- seq_printf(seq, "Module name : %s\n",
33990- chtostr(result.module_name, 24));
33991- seq_printf(seq, "Module revision : %s\n",
33992- chtostr(result.module_rev, 8));
33993+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
33994+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
33995
33996 seq_printf(seq, "Serial number : ");
33997 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
33998@@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
33999 return 0;
34000 }
34001
34002- seq_printf(seq, "Device name : %s\n",
34003- chtostr(result.device_name, 64));
34004- seq_printf(seq, "Service name : %s\n",
34005- chtostr(result.service_name, 64));
34006- seq_printf(seq, "Physical name : %s\n",
34007- chtostr(result.physical_location, 64));
34008- seq_printf(seq, "Instance number : %s\n",
34009- chtostr(result.instance_number, 4));
34010+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
34011+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
34012+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34013+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34014
34015 return 0;
34016 }
34017diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34018index a8c08f3..155fe3d 100644
34019--- a/drivers/message/i2o/iop.c
34020+++ b/drivers/message/i2o/iop.c
34021@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34022
34023 spin_lock_irqsave(&c->context_list_lock, flags);
34024
34025- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34026- atomic_inc(&c->context_list_counter);
34027+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34028+ atomic_inc_unchecked(&c->context_list_counter);
34029
34030- entry->context = atomic_read(&c->context_list_counter);
34031+ entry->context = atomic_read_unchecked(&c->context_list_counter);
34032
34033 list_add(&entry->list, &c->context_list);
34034
34035@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34036
34037 #if BITS_PER_LONG == 64
34038 spin_lock_init(&c->context_list_lock);
34039- atomic_set(&c->context_list_counter, 0);
34040+ atomic_set_unchecked(&c->context_list_counter, 0);
34041 INIT_LIST_HEAD(&c->context_list);
34042 #endif
34043
34044diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34045index 7ce65f4..e66e9bc 100644
34046--- a/drivers/mfd/abx500-core.c
34047+++ b/drivers/mfd/abx500-core.c
34048@@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34049
34050 struct abx500_device_entry {
34051 struct list_head list;
34052- struct abx500_ops ops;
34053+ abx500_ops_no_const ops;
34054 struct device *dev;
34055 };
34056
34057diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34058index a9223ed..4127b13 100644
34059--- a/drivers/mfd/janz-cmodio.c
34060+++ b/drivers/mfd/janz-cmodio.c
34061@@ -13,6 +13,7 @@
34062
34063 #include <linux/kernel.h>
34064 #include <linux/module.h>
34065+#include <linux/slab.h>
34066 #include <linux/init.h>
34067 #include <linux/pci.h>
34068 #include <linux/interrupt.h>
34069diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34070index a981e2a..5ca0c8b 100644
34071--- a/drivers/misc/lis3lv02d/lis3lv02d.c
34072+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34073@@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34074 * the lid is closed. This leads to interrupts as soon as a little move
34075 * is done.
34076 */
34077- atomic_inc(&lis3->count);
34078+ atomic_inc_unchecked(&lis3->count);
34079
34080 wake_up_interruptible(&lis3->misc_wait);
34081 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34082@@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34083 if (lis3->pm_dev)
34084 pm_runtime_get_sync(lis3->pm_dev);
34085
34086- atomic_set(&lis3->count, 0);
34087+ atomic_set_unchecked(&lis3->count, 0);
34088 return 0;
34089 }
34090
34091@@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34092 add_wait_queue(&lis3->misc_wait, &wait);
34093 while (true) {
34094 set_current_state(TASK_INTERRUPTIBLE);
34095- data = atomic_xchg(&lis3->count, 0);
34096+ data = atomic_xchg_unchecked(&lis3->count, 0);
34097 if (data)
34098 break;
34099
34100@@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34101 struct lis3lv02d, miscdev);
34102
34103 poll_wait(file, &lis3->misc_wait, wait);
34104- if (atomic_read(&lis3->count))
34105+ if (atomic_read_unchecked(&lis3->count))
34106 return POLLIN | POLLRDNORM;
34107 return 0;
34108 }
34109diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34110index 2b1482a..5d33616 100644
34111--- a/drivers/misc/lis3lv02d/lis3lv02d.h
34112+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34113@@ -266,7 +266,7 @@ struct lis3lv02d {
34114 struct input_polled_dev *idev; /* input device */
34115 struct platform_device *pdev; /* platform device */
34116 struct regulator_bulk_data regulators[2];
34117- atomic_t count; /* interrupt count after last read */
34118+ atomic_unchecked_t count; /* interrupt count after last read */
34119 union axis_conversion ac; /* hw -> logical axis */
34120 int mapped_btns[3];
34121
34122diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34123index 2f30bad..c4c13d0 100644
34124--- a/drivers/misc/sgi-gru/gruhandles.c
34125+++ b/drivers/misc/sgi-gru/gruhandles.c
34126@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34127 unsigned long nsec;
34128
34129 nsec = CLKS2NSEC(clks);
34130- atomic_long_inc(&mcs_op_statistics[op].count);
34131- atomic_long_add(nsec, &mcs_op_statistics[op].total);
34132+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34133+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34134 if (mcs_op_statistics[op].max < nsec)
34135 mcs_op_statistics[op].max = nsec;
34136 }
34137diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34138index 950dbe9..eeef0f8 100644
34139--- a/drivers/misc/sgi-gru/gruprocfs.c
34140+++ b/drivers/misc/sgi-gru/gruprocfs.c
34141@@ -32,9 +32,9 @@
34142
34143 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34144
34145-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34146+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34147 {
34148- unsigned long val = atomic_long_read(v);
34149+ unsigned long val = atomic_long_read_unchecked(v);
34150
34151 seq_printf(s, "%16lu %s\n", val, id);
34152 }
34153@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34154
34155 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34156 for (op = 0; op < mcsop_last; op++) {
34157- count = atomic_long_read(&mcs_op_statistics[op].count);
34158- total = atomic_long_read(&mcs_op_statistics[op].total);
34159+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34160+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34161 max = mcs_op_statistics[op].max;
34162 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34163 count ? total / count : 0, max);
34164diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34165index 5c3ce24..4915ccb 100644
34166--- a/drivers/misc/sgi-gru/grutables.h
34167+++ b/drivers/misc/sgi-gru/grutables.h
34168@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34169 * GRU statistics.
34170 */
34171 struct gru_stats_s {
34172- atomic_long_t vdata_alloc;
34173- atomic_long_t vdata_free;
34174- atomic_long_t gts_alloc;
34175- atomic_long_t gts_free;
34176- atomic_long_t gms_alloc;
34177- atomic_long_t gms_free;
34178- atomic_long_t gts_double_allocate;
34179- atomic_long_t assign_context;
34180- atomic_long_t assign_context_failed;
34181- atomic_long_t free_context;
34182- atomic_long_t load_user_context;
34183- atomic_long_t load_kernel_context;
34184- atomic_long_t lock_kernel_context;
34185- atomic_long_t unlock_kernel_context;
34186- atomic_long_t steal_user_context;
34187- atomic_long_t steal_kernel_context;
34188- atomic_long_t steal_context_failed;
34189- atomic_long_t nopfn;
34190- atomic_long_t asid_new;
34191- atomic_long_t asid_next;
34192- atomic_long_t asid_wrap;
34193- atomic_long_t asid_reuse;
34194- atomic_long_t intr;
34195- atomic_long_t intr_cbr;
34196- atomic_long_t intr_tfh;
34197- atomic_long_t intr_spurious;
34198- atomic_long_t intr_mm_lock_failed;
34199- atomic_long_t call_os;
34200- atomic_long_t call_os_wait_queue;
34201- atomic_long_t user_flush_tlb;
34202- atomic_long_t user_unload_context;
34203- atomic_long_t user_exception;
34204- atomic_long_t set_context_option;
34205- atomic_long_t check_context_retarget_intr;
34206- atomic_long_t check_context_unload;
34207- atomic_long_t tlb_dropin;
34208- atomic_long_t tlb_preload_page;
34209- atomic_long_t tlb_dropin_fail_no_asid;
34210- atomic_long_t tlb_dropin_fail_upm;
34211- atomic_long_t tlb_dropin_fail_invalid;
34212- atomic_long_t tlb_dropin_fail_range_active;
34213- atomic_long_t tlb_dropin_fail_idle;
34214- atomic_long_t tlb_dropin_fail_fmm;
34215- atomic_long_t tlb_dropin_fail_no_exception;
34216- atomic_long_t tfh_stale_on_fault;
34217- atomic_long_t mmu_invalidate_range;
34218- atomic_long_t mmu_invalidate_page;
34219- atomic_long_t flush_tlb;
34220- atomic_long_t flush_tlb_gru;
34221- atomic_long_t flush_tlb_gru_tgh;
34222- atomic_long_t flush_tlb_gru_zero_asid;
34223+ atomic_long_unchecked_t vdata_alloc;
34224+ atomic_long_unchecked_t vdata_free;
34225+ atomic_long_unchecked_t gts_alloc;
34226+ atomic_long_unchecked_t gts_free;
34227+ atomic_long_unchecked_t gms_alloc;
34228+ atomic_long_unchecked_t gms_free;
34229+ atomic_long_unchecked_t gts_double_allocate;
34230+ atomic_long_unchecked_t assign_context;
34231+ atomic_long_unchecked_t assign_context_failed;
34232+ atomic_long_unchecked_t free_context;
34233+ atomic_long_unchecked_t load_user_context;
34234+ atomic_long_unchecked_t load_kernel_context;
34235+ atomic_long_unchecked_t lock_kernel_context;
34236+ atomic_long_unchecked_t unlock_kernel_context;
34237+ atomic_long_unchecked_t steal_user_context;
34238+ atomic_long_unchecked_t steal_kernel_context;
34239+ atomic_long_unchecked_t steal_context_failed;
34240+ atomic_long_unchecked_t nopfn;
34241+ atomic_long_unchecked_t asid_new;
34242+ atomic_long_unchecked_t asid_next;
34243+ atomic_long_unchecked_t asid_wrap;
34244+ atomic_long_unchecked_t asid_reuse;
34245+ atomic_long_unchecked_t intr;
34246+ atomic_long_unchecked_t intr_cbr;
34247+ atomic_long_unchecked_t intr_tfh;
34248+ atomic_long_unchecked_t intr_spurious;
34249+ atomic_long_unchecked_t intr_mm_lock_failed;
34250+ atomic_long_unchecked_t call_os;
34251+ atomic_long_unchecked_t call_os_wait_queue;
34252+ atomic_long_unchecked_t user_flush_tlb;
34253+ atomic_long_unchecked_t user_unload_context;
34254+ atomic_long_unchecked_t user_exception;
34255+ atomic_long_unchecked_t set_context_option;
34256+ atomic_long_unchecked_t check_context_retarget_intr;
34257+ atomic_long_unchecked_t check_context_unload;
34258+ atomic_long_unchecked_t tlb_dropin;
34259+ atomic_long_unchecked_t tlb_preload_page;
34260+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34261+ atomic_long_unchecked_t tlb_dropin_fail_upm;
34262+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
34263+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
34264+ atomic_long_unchecked_t tlb_dropin_fail_idle;
34265+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
34266+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34267+ atomic_long_unchecked_t tfh_stale_on_fault;
34268+ atomic_long_unchecked_t mmu_invalidate_range;
34269+ atomic_long_unchecked_t mmu_invalidate_page;
34270+ atomic_long_unchecked_t flush_tlb;
34271+ atomic_long_unchecked_t flush_tlb_gru;
34272+ atomic_long_unchecked_t flush_tlb_gru_tgh;
34273+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34274
34275- atomic_long_t copy_gpa;
34276- atomic_long_t read_gpa;
34277+ atomic_long_unchecked_t copy_gpa;
34278+ atomic_long_unchecked_t read_gpa;
34279
34280- atomic_long_t mesq_receive;
34281- atomic_long_t mesq_receive_none;
34282- atomic_long_t mesq_send;
34283- atomic_long_t mesq_send_failed;
34284- atomic_long_t mesq_noop;
34285- atomic_long_t mesq_send_unexpected_error;
34286- atomic_long_t mesq_send_lb_overflow;
34287- atomic_long_t mesq_send_qlimit_reached;
34288- atomic_long_t mesq_send_amo_nacked;
34289- atomic_long_t mesq_send_put_nacked;
34290- atomic_long_t mesq_page_overflow;
34291- atomic_long_t mesq_qf_locked;
34292- atomic_long_t mesq_qf_noop_not_full;
34293- atomic_long_t mesq_qf_switch_head_failed;
34294- atomic_long_t mesq_qf_unexpected_error;
34295- atomic_long_t mesq_noop_unexpected_error;
34296- atomic_long_t mesq_noop_lb_overflow;
34297- atomic_long_t mesq_noop_qlimit_reached;
34298- atomic_long_t mesq_noop_amo_nacked;
34299- atomic_long_t mesq_noop_put_nacked;
34300- atomic_long_t mesq_noop_page_overflow;
34301+ atomic_long_unchecked_t mesq_receive;
34302+ atomic_long_unchecked_t mesq_receive_none;
34303+ atomic_long_unchecked_t mesq_send;
34304+ atomic_long_unchecked_t mesq_send_failed;
34305+ atomic_long_unchecked_t mesq_noop;
34306+ atomic_long_unchecked_t mesq_send_unexpected_error;
34307+ atomic_long_unchecked_t mesq_send_lb_overflow;
34308+ atomic_long_unchecked_t mesq_send_qlimit_reached;
34309+ atomic_long_unchecked_t mesq_send_amo_nacked;
34310+ atomic_long_unchecked_t mesq_send_put_nacked;
34311+ atomic_long_unchecked_t mesq_page_overflow;
34312+ atomic_long_unchecked_t mesq_qf_locked;
34313+ atomic_long_unchecked_t mesq_qf_noop_not_full;
34314+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
34315+ atomic_long_unchecked_t mesq_qf_unexpected_error;
34316+ atomic_long_unchecked_t mesq_noop_unexpected_error;
34317+ atomic_long_unchecked_t mesq_noop_lb_overflow;
34318+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
34319+ atomic_long_unchecked_t mesq_noop_amo_nacked;
34320+ atomic_long_unchecked_t mesq_noop_put_nacked;
34321+ atomic_long_unchecked_t mesq_noop_page_overflow;
34322
34323 };
34324
34325@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34326 tghop_invalidate, mcsop_last};
34327
34328 struct mcs_op_statistic {
34329- atomic_long_t count;
34330- atomic_long_t total;
34331+ atomic_long_unchecked_t count;
34332+ atomic_long_unchecked_t total;
34333 unsigned long max;
34334 };
34335
34336@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34337
34338 #define STAT(id) do { \
34339 if (gru_options & OPT_STATS) \
34340- atomic_long_inc(&gru_stats.id); \
34341+ atomic_long_inc_unchecked(&gru_stats.id); \
34342 } while (0)
34343
34344 #ifdef CONFIG_SGI_GRU_DEBUG
34345diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34346index c862cd4..0d176fe 100644
34347--- a/drivers/misc/sgi-xp/xp.h
34348+++ b/drivers/misc/sgi-xp/xp.h
34349@@ -288,7 +288,7 @@ struct xpc_interface {
34350 xpc_notify_func, void *);
34351 void (*received) (short, int, void *);
34352 enum xp_retval (*partid_to_nasids) (short, void *);
34353-};
34354+} __no_const;
34355
34356 extern struct xpc_interface xpc_interface;
34357
34358diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34359index b94d5f7..7f494c5 100644
34360--- a/drivers/misc/sgi-xp/xpc.h
34361+++ b/drivers/misc/sgi-xp/xpc.h
34362@@ -835,6 +835,7 @@ struct xpc_arch_operations {
34363 void (*received_payload) (struct xpc_channel *, void *);
34364 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34365 };
34366+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34367
34368 /* struct xpc_partition act_state values (for XPC HB) */
34369
34370@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34371 /* found in xpc_main.c */
34372 extern struct device *xpc_part;
34373 extern struct device *xpc_chan;
34374-extern struct xpc_arch_operations xpc_arch_ops;
34375+extern xpc_arch_operations_no_const xpc_arch_ops;
34376 extern int xpc_disengage_timelimit;
34377 extern int xpc_disengage_timedout;
34378 extern int xpc_activate_IRQ_rcvd;
34379diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34380index 8d082b4..aa749ae 100644
34381--- a/drivers/misc/sgi-xp/xpc_main.c
34382+++ b/drivers/misc/sgi-xp/xpc_main.c
34383@@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34384 .notifier_call = xpc_system_die,
34385 };
34386
34387-struct xpc_arch_operations xpc_arch_ops;
34388+xpc_arch_operations_no_const xpc_arch_ops;
34389
34390 /*
34391 * Timer function to enforce the timelimit on the partition disengage.
34392diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34393index 69ef0be..f3ef91e 100644
34394--- a/drivers/mmc/host/sdhci-pci.c
34395+++ b/drivers/mmc/host/sdhci-pci.c
34396@@ -652,7 +652,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34397 .probe = via_probe,
34398 };
34399
34400-static const struct pci_device_id pci_ids[] __devinitdata = {
34401+static const struct pci_device_id pci_ids[] __devinitconst = {
34402 {
34403 .vendor = PCI_VENDOR_ID_RICOH,
34404 .device = PCI_DEVICE_ID_RICOH_R5C822,
34405diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34406index a4eb8b5..8c0628f 100644
34407--- a/drivers/mtd/devices/doc2000.c
34408+++ b/drivers/mtd/devices/doc2000.c
34409@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34410
34411 /* The ECC will not be calculated correctly if less than 512 is written */
34412 /* DBB-
34413- if (len != 0x200 && eccbuf)
34414+ if (len != 0x200)
34415 printk(KERN_WARNING
34416 "ECC needs a full sector write (adr: %lx size %lx)\n",
34417 (long) to, (long) len);
34418diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34419index a9e57d6..c6d8731 100644
34420--- a/drivers/mtd/nand/denali.c
34421+++ b/drivers/mtd/nand/denali.c
34422@@ -26,6 +26,7 @@
34423 #include <linux/pci.h>
34424 #include <linux/mtd/mtd.h>
34425 #include <linux/module.h>
34426+#include <linux/slab.h>
34427
34428 #include "denali.h"
34429
34430diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34431index 51b9d6a..52af9a7 100644
34432--- a/drivers/mtd/nftlmount.c
34433+++ b/drivers/mtd/nftlmount.c
34434@@ -24,6 +24,7 @@
34435 #include <asm/errno.h>
34436 #include <linux/delay.h>
34437 #include <linux/slab.h>
34438+#include <linux/sched.h>
34439 #include <linux/mtd/mtd.h>
34440 #include <linux/mtd/nand.h>
34441 #include <linux/mtd/nftl.h>
34442diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34443index 6762dc4..9956862 100644
34444--- a/drivers/net/ethernet/atheros/atlx/atl2.c
34445+++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34446@@ -2859,7 +2859,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34447 */
34448
34449 #define ATL2_PARAM(X, desc) \
34450- static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34451+ static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34452 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34453 MODULE_PARM_DESC(X, desc);
34454 #else
34455diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34456index 61a7670..7da6e34 100644
34457--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34458+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34459@@ -483,7 +483,7 @@ struct bnx2x_rx_mode_obj {
34460
34461 int (*wait_comp)(struct bnx2x *bp,
34462 struct bnx2x_rx_mode_ramrod_params *p);
34463-};
34464+} __no_const;
34465
34466 /********************** Set multicast group ***********************************/
34467
34468diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34469index 93865f8..5448741 100644
34470--- a/drivers/net/ethernet/broadcom/tg3.h
34471+++ b/drivers/net/ethernet/broadcom/tg3.h
34472@@ -140,6 +140,7 @@
34473 #define CHIPREV_ID_5750_A0 0x4000
34474 #define CHIPREV_ID_5750_A1 0x4001
34475 #define CHIPREV_ID_5750_A3 0x4003
34476+#define CHIPREV_ID_5750_C1 0x4201
34477 #define CHIPREV_ID_5750_C2 0x4202
34478 #define CHIPREV_ID_5752_A0_HW 0x5000
34479 #define CHIPREV_ID_5752_A0 0x6000
34480diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34481index c4e8643..0979484 100644
34482--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34483+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34484@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34485 */
34486 struct l2t_skb_cb {
34487 arp_failure_handler_func arp_failure_handler;
34488-};
34489+} __no_const;
34490
34491 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34492
34493diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34494index 18b106c..2b38d36 100644
34495--- a/drivers/net/ethernet/dec/tulip/de4x5.c
34496+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34497@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34498 for (i=0; i<ETH_ALEN; i++) {
34499 tmp.addr[i] = dev->dev_addr[i];
34500 }
34501- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34502+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34503 break;
34504
34505 case DE4X5_SET_HWADDR: /* Set the hardware address */
34506@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34507 spin_lock_irqsave(&lp->lock, flags);
34508 memcpy(&statbuf, &lp->pktStats, ioc->len);
34509 spin_unlock_irqrestore(&lp->lock, flags);
34510- if (copy_to_user(ioc->data, &statbuf, ioc->len))
34511+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34512 return -EFAULT;
34513 break;
34514 }
34515diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34516index ed7d1dc..d426748 100644
34517--- a/drivers/net/ethernet/dec/tulip/eeprom.c
34518+++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34519@@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34520 {NULL}};
34521
34522
34523-static const char *block_name[] __devinitdata = {
34524+static const char *block_name[] __devinitconst = {
34525 "21140 non-MII",
34526 "21140 MII PHY",
34527 "21142 Serial PHY",
34528diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34529index 2ac6fff..2d127d0 100644
34530--- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34531+++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34532@@ -236,7 +236,7 @@ struct pci_id_info {
34533 int drv_flags; /* Driver use, intended as capability flags. */
34534 };
34535
34536-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34537+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34538 { /* Sometime a Level-One switch card. */
34539 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34540 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34541diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34542index d783f4f..97fa1b0 100644
34543--- a/drivers/net/ethernet/dlink/sundance.c
34544+++ b/drivers/net/ethernet/dlink/sundance.c
34545@@ -218,7 +218,7 @@ enum {
34546 struct pci_id_info {
34547 const char *name;
34548 };
34549-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34550+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34551 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34552 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34553 {"D-Link DFE-580TX 4 port Server Adapter"},
34554diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34555index 528a886..e6a98a3 100644
34556--- a/drivers/net/ethernet/emulex/benet/be_main.c
34557+++ b/drivers/net/ethernet/emulex/benet/be_main.c
34558@@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34559
34560 if (wrapped)
34561 newacc += 65536;
34562- ACCESS_ONCE(*acc) = newacc;
34563+ ACCESS_ONCE_RW(*acc) = newacc;
34564 }
34565
34566 void be_parse_stats(struct be_adapter *adapter)
34567diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34568index 16b0704..d2c07d7 100644
34569--- a/drivers/net/ethernet/faraday/ftgmac100.c
34570+++ b/drivers/net/ethernet/faraday/ftgmac100.c
34571@@ -31,6 +31,8 @@
34572 #include <linux/netdevice.h>
34573 #include <linux/phy.h>
34574 #include <linux/platform_device.h>
34575+#include <linux/interrupt.h>
34576+#include <linux/irqreturn.h>
34577 #include <net/ip.h>
34578
34579 #include "ftgmac100.h"
34580diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34581index 829b109..4ae5f6a 100644
34582--- a/drivers/net/ethernet/faraday/ftmac100.c
34583+++ b/drivers/net/ethernet/faraday/ftmac100.c
34584@@ -31,6 +31,8 @@
34585 #include <linux/module.h>
34586 #include <linux/netdevice.h>
34587 #include <linux/platform_device.h>
34588+#include <linux/interrupt.h>
34589+#include <linux/irqreturn.h>
34590
34591 #include "ftmac100.h"
34592
34593diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34594index 1637b98..c42f87b 100644
34595--- a/drivers/net/ethernet/fealnx.c
34596+++ b/drivers/net/ethernet/fealnx.c
34597@@ -150,7 +150,7 @@ struct chip_info {
34598 int flags;
34599 };
34600
34601-static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
34602+static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
34603 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34604 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
34605 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34606diff --git a/drivers/net/ethernet/intel/e1000e/e1000.h b/drivers/net/ethernet/intel/e1000e/e1000.h
34607index b83897f..b2d970f 100644
34608--- a/drivers/net/ethernet/intel/e1000e/e1000.h
34609+++ b/drivers/net/ethernet/intel/e1000e/e1000.h
34610@@ -181,7 +181,7 @@ struct e1000_info;
34611 #define E1000_TXDCTL_DMA_BURST_ENABLE \
34612 (E1000_TXDCTL_GRAN | /* set descriptor granularity */ \
34613 E1000_TXDCTL_COUNT_DESC | \
34614- (5 << 16) | /* wthresh must be +1 more than desired */\
34615+ (1 << 16) | /* wthresh must be +1 more than desired */\
34616 (1 << 8) | /* hthresh */ \
34617 0x1f) /* pthresh */
34618
34619diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34620index f82ecf5..7d59ecb 100644
34621--- a/drivers/net/ethernet/intel/e1000e/hw.h
34622+++ b/drivers/net/ethernet/intel/e1000e/hw.h
34623@@ -784,6 +784,7 @@ struct e1000_mac_operations {
34624 void (*config_collision_dist)(struct e1000_hw *);
34625 s32 (*read_mac_addr)(struct e1000_hw *);
34626 };
34627+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34628
34629 /*
34630 * When to use various PHY register access functions:
34631@@ -824,6 +825,7 @@ struct e1000_phy_operations {
34632 void (*power_up)(struct e1000_hw *);
34633 void (*power_down)(struct e1000_hw *);
34634 };
34635+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34636
34637 /* Function pointers for the NVM. */
34638 struct e1000_nvm_operations {
34639@@ -836,9 +838,10 @@ struct e1000_nvm_operations {
34640 s32 (*validate)(struct e1000_hw *);
34641 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34642 };
34643+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34644
34645 struct e1000_mac_info {
34646- struct e1000_mac_operations ops;
34647+ e1000_mac_operations_no_const ops;
34648 u8 addr[ETH_ALEN];
34649 u8 perm_addr[ETH_ALEN];
34650
34651@@ -879,7 +882,7 @@ struct e1000_mac_info {
34652 };
34653
34654 struct e1000_phy_info {
34655- struct e1000_phy_operations ops;
34656+ e1000_phy_operations_no_const ops;
34657
34658 enum e1000_phy_type type;
34659
34660@@ -913,7 +916,7 @@ struct e1000_phy_info {
34661 };
34662
34663 struct e1000_nvm_info {
34664- struct e1000_nvm_operations ops;
34665+ e1000_nvm_operations_no_const ops;
34666
34667 enum e1000_nvm_type type;
34668 enum e1000_nvm_override override;
34669diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
34670index f67cbd3..cef9e3d 100644
34671--- a/drivers/net/ethernet/intel/igb/e1000_hw.h
34672+++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
34673@@ -314,6 +314,7 @@ struct e1000_mac_operations {
34674 s32 (*read_mac_addr)(struct e1000_hw *);
34675 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
34676 };
34677+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34678
34679 struct e1000_phy_operations {
34680 s32 (*acquire)(struct e1000_hw *);
34681@@ -330,6 +331,7 @@ struct e1000_phy_operations {
34682 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
34683 s32 (*write_reg)(struct e1000_hw *, u32, u16);
34684 };
34685+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34686
34687 struct e1000_nvm_operations {
34688 s32 (*acquire)(struct e1000_hw *);
34689@@ -339,6 +341,7 @@ struct e1000_nvm_operations {
34690 s32 (*update)(struct e1000_hw *);
34691 s32 (*validate)(struct e1000_hw *);
34692 };
34693+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34694
34695 struct e1000_info {
34696 s32 (*get_invariants)(struct e1000_hw *);
34697@@ -350,7 +353,7 @@ struct e1000_info {
34698 extern const struct e1000_info e1000_82575_info;
34699
34700 struct e1000_mac_info {
34701- struct e1000_mac_operations ops;
34702+ e1000_mac_operations_no_const ops;
34703
34704 u8 addr[6];
34705 u8 perm_addr[6];
34706@@ -388,7 +391,7 @@ struct e1000_mac_info {
34707 };
34708
34709 struct e1000_phy_info {
34710- struct e1000_phy_operations ops;
34711+ e1000_phy_operations_no_const ops;
34712
34713 enum e1000_phy_type type;
34714
34715@@ -423,7 +426,7 @@ struct e1000_phy_info {
34716 };
34717
34718 struct e1000_nvm_info {
34719- struct e1000_nvm_operations ops;
34720+ e1000_nvm_operations_no_const ops;
34721 enum e1000_nvm_type type;
34722 enum e1000_nvm_override override;
34723
34724@@ -468,6 +471,7 @@ struct e1000_mbx_operations {
34725 s32 (*check_for_ack)(struct e1000_hw *, u16);
34726 s32 (*check_for_rst)(struct e1000_hw *, u16);
34727 };
34728+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34729
34730 struct e1000_mbx_stats {
34731 u32 msgs_tx;
34732@@ -479,7 +483,7 @@ struct e1000_mbx_stats {
34733 };
34734
34735 struct e1000_mbx_info {
34736- struct e1000_mbx_operations ops;
34737+ e1000_mbx_operations_no_const ops;
34738 struct e1000_mbx_stats stats;
34739 u32 timeout;
34740 u32 usec_delay;
34741diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
34742index 57db3c6..aa825fc 100644
34743--- a/drivers/net/ethernet/intel/igbvf/vf.h
34744+++ b/drivers/net/ethernet/intel/igbvf/vf.h
34745@@ -189,9 +189,10 @@ struct e1000_mac_operations {
34746 s32 (*read_mac_addr)(struct e1000_hw *);
34747 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
34748 };
34749+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34750
34751 struct e1000_mac_info {
34752- struct e1000_mac_operations ops;
34753+ e1000_mac_operations_no_const ops;
34754 u8 addr[6];
34755 u8 perm_addr[6];
34756
34757@@ -213,6 +214,7 @@ struct e1000_mbx_operations {
34758 s32 (*check_for_ack)(struct e1000_hw *);
34759 s32 (*check_for_rst)(struct e1000_hw *);
34760 };
34761+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34762
34763 struct e1000_mbx_stats {
34764 u32 msgs_tx;
34765@@ -224,7 +226,7 @@ struct e1000_mbx_stats {
34766 };
34767
34768 struct e1000_mbx_info {
34769- struct e1000_mbx_operations ops;
34770+ e1000_mbx_operations_no_const ops;
34771 struct e1000_mbx_stats stats;
34772 u32 timeout;
34773 u32 usec_delay;
34774diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34775index 8636e83..ab9bbc3 100644
34776--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34777+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34778@@ -2710,6 +2710,7 @@ struct ixgbe_eeprom_operations {
34779 s32 (*update_checksum)(struct ixgbe_hw *);
34780 u16 (*calc_checksum)(struct ixgbe_hw *);
34781 };
34782+typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
34783
34784 struct ixgbe_mac_operations {
34785 s32 (*init_hw)(struct ixgbe_hw *);
34786@@ -2773,6 +2774,7 @@ struct ixgbe_mac_operations {
34787 /* Manageability interface */
34788 s32 (*set_fw_drv_ver)(struct ixgbe_hw *, u8, u8, u8, u8);
34789 };
34790+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34791
34792 struct ixgbe_phy_operations {
34793 s32 (*identify)(struct ixgbe_hw *);
34794@@ -2792,9 +2794,10 @@ struct ixgbe_phy_operations {
34795 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
34796 s32 (*check_overtemp)(struct ixgbe_hw *);
34797 };
34798+typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
34799
34800 struct ixgbe_eeprom_info {
34801- struct ixgbe_eeprom_operations ops;
34802+ ixgbe_eeprom_operations_no_const ops;
34803 enum ixgbe_eeprom_type type;
34804 u32 semaphore_delay;
34805 u16 word_size;
34806@@ -2804,7 +2807,7 @@ struct ixgbe_eeprom_info {
34807
34808 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
34809 struct ixgbe_mac_info {
34810- struct ixgbe_mac_operations ops;
34811+ ixgbe_mac_operations_no_const ops;
34812 enum ixgbe_mac_type type;
34813 u8 addr[ETH_ALEN];
34814 u8 perm_addr[ETH_ALEN];
34815@@ -2832,7 +2835,7 @@ struct ixgbe_mac_info {
34816 };
34817
34818 struct ixgbe_phy_info {
34819- struct ixgbe_phy_operations ops;
34820+ ixgbe_phy_operations_no_const ops;
34821 struct mdio_if_info mdio;
34822 enum ixgbe_phy_type type;
34823 u32 id;
34824@@ -2860,6 +2863,7 @@ struct ixgbe_mbx_operations {
34825 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
34826 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
34827 };
34828+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34829
34830 struct ixgbe_mbx_stats {
34831 u32 msgs_tx;
34832@@ -2871,7 +2875,7 @@ struct ixgbe_mbx_stats {
34833 };
34834
34835 struct ixgbe_mbx_info {
34836- struct ixgbe_mbx_operations ops;
34837+ ixgbe_mbx_operations_no_const ops;
34838 struct ixgbe_mbx_stats stats;
34839 u32 timeout;
34840 u32 usec_delay;
34841diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
34842index 25c951d..cc7cf33 100644
34843--- a/drivers/net/ethernet/intel/ixgbevf/vf.h
34844+++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
34845@@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
34846 s32 (*clear_vfta)(struct ixgbe_hw *);
34847 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
34848 };
34849+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34850
34851 enum ixgbe_mac_type {
34852 ixgbe_mac_unknown = 0,
34853@@ -79,7 +80,7 @@ enum ixgbe_mac_type {
34854 };
34855
34856 struct ixgbe_mac_info {
34857- struct ixgbe_mac_operations ops;
34858+ ixgbe_mac_operations_no_const ops;
34859 u8 addr[6];
34860 u8 perm_addr[6];
34861
34862@@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
34863 s32 (*check_for_ack)(struct ixgbe_hw *);
34864 s32 (*check_for_rst)(struct ixgbe_hw *);
34865 };
34866+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34867
34868 struct ixgbe_mbx_stats {
34869 u32 msgs_tx;
34870@@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
34871 };
34872
34873 struct ixgbe_mbx_info {
34874- struct ixgbe_mbx_operations ops;
34875+ ixgbe_mbx_operations_no_const ops;
34876 struct ixgbe_mbx_stats stats;
34877 u32 timeout;
34878 u32 udelay;
34879diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
34880index 8bb05b4..074796f 100644
34881--- a/drivers/net/ethernet/mellanox/mlx4/main.c
34882+++ b/drivers/net/ethernet/mellanox/mlx4/main.c
34883@@ -41,6 +41,7 @@
34884 #include <linux/slab.h>
34885 #include <linux/io-mapping.h>
34886 #include <linux/delay.h>
34887+#include <linux/sched.h>
34888
34889 #include <linux/mlx4/device.h>
34890 #include <linux/mlx4/doorbell.h>
34891diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
34892index 5046a64..71ca936 100644
34893--- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
34894+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
34895@@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
34896 void (*link_down)(struct __vxge_hw_device *devh);
34897 void (*crit_err)(struct __vxge_hw_device *devh,
34898 enum vxge_hw_event type, u64 ext_data);
34899-};
34900+} __no_const;
34901
34902 /*
34903 * struct __vxge_hw_blockpool_entry - Block private data structure
34904diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34905index 4a518a3..936b334 100644
34906--- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34907+++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34908@@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
34909 struct vxge_hw_mempool_dma *dma_object,
34910 u32 index,
34911 u32 is_last);
34912-};
34913+} __no_const;
34914
34915 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
34916 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
34917diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
34918index ce6b44d..74f10c2 100644
34919--- a/drivers/net/ethernet/realtek/r8169.c
34920+++ b/drivers/net/ethernet/realtek/r8169.c
34921@@ -708,17 +708,17 @@ struct rtl8169_private {
34922 struct mdio_ops {
34923 void (*write)(void __iomem *, int, int);
34924 int (*read)(void __iomem *, int);
34925- } mdio_ops;
34926+ } __no_const mdio_ops;
34927
34928 struct pll_power_ops {
34929 void (*down)(struct rtl8169_private *);
34930 void (*up)(struct rtl8169_private *);
34931- } pll_power_ops;
34932+ } __no_const pll_power_ops;
34933
34934 struct jumbo_ops {
34935 void (*enable)(struct rtl8169_private *);
34936 void (*disable)(struct rtl8169_private *);
34937- } jumbo_ops;
34938+ } __no_const jumbo_ops;
34939
34940 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
34941 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
34942diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
34943index a9deda8..5507c31 100644
34944--- a/drivers/net/ethernet/sis/sis190.c
34945+++ b/drivers/net/ethernet/sis/sis190.c
34946@@ -1620,7 +1620,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
34947 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
34948 struct net_device *dev)
34949 {
34950- static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
34951+ static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
34952 struct sis190_private *tp = netdev_priv(dev);
34953 struct pci_dev *isa_bridge;
34954 u8 reg, tmp8;
34955diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
34956index c07cfe9..81cbf7e 100644
34957--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
34958+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
34959@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
34960
34961 writel(value, ioaddr + MMC_CNTRL);
34962
34963- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
34964- MMC_CNTRL, value);
34965+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
34966+// MMC_CNTRL, value);
34967 }
34968
34969 /* To mask all all interrupts.*/
34970diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
34971index 48d56da..a27e46c 100644
34972--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
34973+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
34974@@ -1584,7 +1584,7 @@ static const struct file_operations stmmac_rings_status_fops = {
34975 .open = stmmac_sysfs_ring_open,
34976 .read = seq_read,
34977 .llseek = seq_lseek,
34978- .release = seq_release,
34979+ .release = single_release,
34980 };
34981
34982 static int stmmac_sysfs_dma_cap_read(struct seq_file *seq, void *v)
34983@@ -1656,7 +1656,7 @@ static const struct file_operations stmmac_dma_cap_fops = {
34984 .open = stmmac_sysfs_dma_cap_open,
34985 .read = seq_read,
34986 .llseek = seq_lseek,
34987- .release = seq_release,
34988+ .release = single_release,
34989 };
34990
34991 static int stmmac_init_fs(struct net_device *dev)
34992diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
34993index c358245..8c1de63 100644
34994--- a/drivers/net/hyperv/hyperv_net.h
34995+++ b/drivers/net/hyperv/hyperv_net.h
34996@@ -98,7 +98,7 @@ struct rndis_device {
34997
34998 enum rndis_device_state state;
34999 bool link_state;
35000- atomic_t new_req_id;
35001+ atomic_unchecked_t new_req_id;
35002
35003 spinlock_t request_lock;
35004 struct list_head req_list;
35005diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35006index d6be64b..5d97e3b 100644
35007--- a/drivers/net/hyperv/rndis_filter.c
35008+++ b/drivers/net/hyperv/rndis_filter.c
35009@@ -97,7 +97,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35010 * template
35011 */
35012 set = &rndis_msg->msg.set_req;
35013- set->req_id = atomic_inc_return(&dev->new_req_id);
35014+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35015
35016 /* Add to the request list */
35017 spin_lock_irqsave(&dev->request_lock, flags);
35018@@ -648,7 +648,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35019
35020 /* Setup the rndis set */
35021 halt = &request->request_msg.msg.halt_req;
35022- halt->req_id = atomic_inc_return(&dev->new_req_id);
35023+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35024
35025 /* Ignore return since this msg is optional. */
35026 rndis_filter_send_request(dev, request);
35027diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
35028index cb8fd50..003ec38 100644
35029--- a/drivers/net/macvtap.c
35030+++ b/drivers/net/macvtap.c
35031@@ -528,6 +528,8 @@ static int zerocopy_sg_from_iovec(struct sk_buff *skb, const struct iovec *from,
35032 }
35033 base = (unsigned long)from->iov_base + offset1;
35034 size = ((base & ~PAGE_MASK) + len + ~PAGE_MASK) >> PAGE_SHIFT;
35035+ if (i + size >= MAX_SKB_FRAGS)
35036+ return -EFAULT;
35037 num_pages = get_user_pages_fast(base, size, 0, &page[i]);
35038 if ((num_pages != size) ||
35039 (num_pages > MAX_SKB_FRAGS - skb_shinfo(skb)->nr_frags))
35040diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35041index 21d7151..8034208 100644
35042--- a/drivers/net/ppp/ppp_generic.c
35043+++ b/drivers/net/ppp/ppp_generic.c
35044@@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35045 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35046 struct ppp_stats stats;
35047 struct ppp_comp_stats cstats;
35048- char *vers;
35049
35050 switch (cmd) {
35051 case SIOCGPPPSTATS:
35052@@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35053 break;
35054
35055 case SIOCGPPPVER:
35056- vers = PPP_VERSION;
35057- if (copy_to_user(addr, vers, strlen(vers) + 1))
35058+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35059 break;
35060 err = 0;
35061 break;
35062diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
35063index b715e6b..6d2490f 100644
35064--- a/drivers/net/tokenring/abyss.c
35065+++ b/drivers/net/tokenring/abyss.c
35066@@ -450,10 +450,12 @@ static struct pci_driver abyss_driver = {
35067
35068 static int __init abyss_init (void)
35069 {
35070- abyss_netdev_ops = tms380tr_netdev_ops;
35071+ pax_open_kernel();
35072+ memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35073
35074- abyss_netdev_ops.ndo_open = abyss_open;
35075- abyss_netdev_ops.ndo_stop = abyss_close;
35076+ *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
35077+ *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
35078+ pax_close_kernel();
35079
35080 return pci_register_driver(&abyss_driver);
35081 }
35082diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
35083index 28adcdf..ae82f35 100644
35084--- a/drivers/net/tokenring/madgemc.c
35085+++ b/drivers/net/tokenring/madgemc.c
35086@@ -742,9 +742,11 @@ static struct mca_driver madgemc_driver = {
35087
35088 static int __init madgemc_init (void)
35089 {
35090- madgemc_netdev_ops = tms380tr_netdev_ops;
35091- madgemc_netdev_ops.ndo_open = madgemc_open;
35092- madgemc_netdev_ops.ndo_stop = madgemc_close;
35093+ pax_open_kernel();
35094+ memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35095+ *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
35096+ *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
35097+ pax_close_kernel();
35098
35099 return mca_register_driver (&madgemc_driver);
35100 }
35101diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
35102index 62d90e4..9d84237 100644
35103--- a/drivers/net/tokenring/proteon.c
35104+++ b/drivers/net/tokenring/proteon.c
35105@@ -352,9 +352,11 @@ static int __init proteon_init(void)
35106 struct platform_device *pdev;
35107 int i, num = 0, err = 0;
35108
35109- proteon_netdev_ops = tms380tr_netdev_ops;
35110- proteon_netdev_ops.ndo_open = proteon_open;
35111- proteon_netdev_ops.ndo_stop = tms380tr_close;
35112+ pax_open_kernel();
35113+ memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35114+ *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
35115+ *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
35116+ pax_close_kernel();
35117
35118 err = platform_driver_register(&proteon_driver);
35119 if (err)
35120diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
35121index ee11e93..c8f19c7 100644
35122--- a/drivers/net/tokenring/skisa.c
35123+++ b/drivers/net/tokenring/skisa.c
35124@@ -362,9 +362,11 @@ static int __init sk_isa_init(void)
35125 struct platform_device *pdev;
35126 int i, num = 0, err = 0;
35127
35128- sk_isa_netdev_ops = tms380tr_netdev_ops;
35129- sk_isa_netdev_ops.ndo_open = sk_isa_open;
35130- sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35131+ pax_open_kernel();
35132+ memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35133+ *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
35134+ *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35135+ pax_close_kernel();
35136
35137 err = platform_driver_register(&sk_isa_driver);
35138 if (err)
35139diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35140index 2d2a688..35f2372 100644
35141--- a/drivers/net/usb/hso.c
35142+++ b/drivers/net/usb/hso.c
35143@@ -71,7 +71,7 @@
35144 #include <asm/byteorder.h>
35145 #include <linux/serial_core.h>
35146 #include <linux/serial.h>
35147-
35148+#include <asm/local.h>
35149
35150 #define MOD_AUTHOR "Option Wireless"
35151 #define MOD_DESCRIPTION "USB High Speed Option driver"
35152@@ -257,7 +257,7 @@ struct hso_serial {
35153
35154 /* from usb_serial_port */
35155 struct tty_struct *tty;
35156- int open_count;
35157+ local_t open_count;
35158 spinlock_t serial_lock;
35159
35160 int (*write_data) (struct hso_serial *serial);
35161@@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35162 struct urb *urb;
35163
35164 urb = serial->rx_urb[0];
35165- if (serial->open_count > 0) {
35166+ if (local_read(&serial->open_count) > 0) {
35167 count = put_rxbuf_data(urb, serial);
35168 if (count == -1)
35169 return;
35170@@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35171 DUMP1(urb->transfer_buffer, urb->actual_length);
35172
35173 /* Anyone listening? */
35174- if (serial->open_count == 0)
35175+ if (local_read(&serial->open_count) == 0)
35176 return;
35177
35178 if (status == 0) {
35179@@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35180 spin_unlock_irq(&serial->serial_lock);
35181
35182 /* check for port already opened, if not set the termios */
35183- serial->open_count++;
35184- if (serial->open_count == 1) {
35185+ if (local_inc_return(&serial->open_count) == 1) {
35186 serial->rx_state = RX_IDLE;
35187 /* Force default termio settings */
35188 _hso_serial_set_termios(tty, NULL);
35189@@ -1324,7 +1323,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35190 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35191 if (result) {
35192 hso_stop_serial_device(serial->parent);
35193- serial->open_count--;
35194+ local_dec(&serial->open_count);
35195 kref_put(&serial->parent->ref, hso_serial_ref_free);
35196 }
35197 } else {
35198@@ -1361,10 +1360,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35199
35200 /* reset the rts and dtr */
35201 /* do the actual close */
35202- serial->open_count--;
35203+ local_dec(&serial->open_count);
35204
35205- if (serial->open_count <= 0) {
35206- serial->open_count = 0;
35207+ if (local_read(&serial->open_count) <= 0) {
35208+ local_set(&serial->open_count, 0);
35209 spin_lock_irq(&serial->serial_lock);
35210 if (serial->tty == tty) {
35211 serial->tty->driver_data = NULL;
35212@@ -1446,7 +1445,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35213
35214 /* the actual setup */
35215 spin_lock_irqsave(&serial->serial_lock, flags);
35216- if (serial->open_count)
35217+ if (local_read(&serial->open_count))
35218 _hso_serial_set_termios(tty, old);
35219 else
35220 tty->termios = old;
35221@@ -1905,7 +1904,7 @@ static void intr_callback(struct urb *urb)
35222 D1("Pending read interrupt on port %d\n", i);
35223 spin_lock(&serial->serial_lock);
35224 if (serial->rx_state == RX_IDLE &&
35225- serial->open_count > 0) {
35226+ local_read(&serial->open_count) > 0) {
35227 /* Setup and send a ctrl req read on
35228 * port i */
35229 if (!serial->rx_urb_filled[0]) {
35230@@ -3098,7 +3097,7 @@ static int hso_resume(struct usb_interface *iface)
35231 /* Start all serial ports */
35232 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35233 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35234- if (dev2ser(serial_table[i])->open_count) {
35235+ if (local_read(&dev2ser(serial_table[i])->open_count)) {
35236 result =
35237 hso_start_serial_device(serial_table[i], GFP_NOIO);
35238 hso_kick_transmit(dev2ser(serial_table[i]));
35239diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35240index c54b7d37..af1f359 100644
35241--- a/drivers/net/wireless/ath/ath.h
35242+++ b/drivers/net/wireless/ath/ath.h
35243@@ -119,6 +119,7 @@ struct ath_ops {
35244 void (*write_flush) (void *);
35245 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35246 };
35247+typedef struct ath_ops __no_const ath_ops_no_const;
35248
35249 struct ath_common;
35250 struct ath_bus_ops;
35251diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35252index aa2abaf..5f5152d 100644
35253--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35254+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35255@@ -183,8 +183,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35256 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35257 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35258
35259- ACCESS_ONCE(ads->ds_link) = i->link;
35260- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35261+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
35262+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35263
35264 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35265 ctl6 = SM(i->keytype, AR_EncrType);
35266@@ -198,26 +198,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35267
35268 if ((i->is_first || i->is_last) &&
35269 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35270- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35271+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35272 | set11nTries(i->rates, 1)
35273 | set11nTries(i->rates, 2)
35274 | set11nTries(i->rates, 3)
35275 | (i->dur_update ? AR_DurUpdateEna : 0)
35276 | SM(0, AR_BurstDur);
35277
35278- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35279+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35280 | set11nRate(i->rates, 1)
35281 | set11nRate(i->rates, 2)
35282 | set11nRate(i->rates, 3);
35283 } else {
35284- ACCESS_ONCE(ads->ds_ctl2) = 0;
35285- ACCESS_ONCE(ads->ds_ctl3) = 0;
35286+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35287+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35288 }
35289
35290 if (!i->is_first) {
35291- ACCESS_ONCE(ads->ds_ctl0) = 0;
35292- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35293- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35294+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35295+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35296+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35297 return;
35298 }
35299
35300@@ -242,7 +242,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35301 break;
35302 }
35303
35304- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35305+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35306 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35307 | SM(i->txpower, AR_XmitPower)
35308 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35309@@ -252,19 +252,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35310 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35311 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35312
35313- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35314- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35315+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35316+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35317
35318 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35319 return;
35320
35321- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35322+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35323 | set11nPktDurRTSCTS(i->rates, 1);
35324
35325- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35326+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35327 | set11nPktDurRTSCTS(i->rates, 3);
35328
35329- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35330+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35331 | set11nRateFlags(i->rates, 1)
35332 | set11nRateFlags(i->rates, 2)
35333 | set11nRateFlags(i->rates, 3)
35334diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35335index a66a13b..0ef399e 100644
35336--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35337+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35338@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35339 (i->qcu << AR_TxQcuNum_S) | desc_len;
35340
35341 checksum += val;
35342- ACCESS_ONCE(ads->info) = val;
35343+ ACCESS_ONCE_RW(ads->info) = val;
35344
35345 checksum += i->link;
35346- ACCESS_ONCE(ads->link) = i->link;
35347+ ACCESS_ONCE_RW(ads->link) = i->link;
35348
35349 checksum += i->buf_addr[0];
35350- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35351+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35352 checksum += i->buf_addr[1];
35353- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35354+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35355 checksum += i->buf_addr[2];
35356- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35357+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35358 checksum += i->buf_addr[3];
35359- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35360+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35361
35362 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35363- ACCESS_ONCE(ads->ctl3) = val;
35364+ ACCESS_ONCE_RW(ads->ctl3) = val;
35365 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35366- ACCESS_ONCE(ads->ctl5) = val;
35367+ ACCESS_ONCE_RW(ads->ctl5) = val;
35368 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35369- ACCESS_ONCE(ads->ctl7) = val;
35370+ ACCESS_ONCE_RW(ads->ctl7) = val;
35371 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35372- ACCESS_ONCE(ads->ctl9) = val;
35373+ ACCESS_ONCE_RW(ads->ctl9) = val;
35374
35375 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35376- ACCESS_ONCE(ads->ctl10) = checksum;
35377+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
35378
35379 if (i->is_first || i->is_last) {
35380- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35381+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35382 | set11nTries(i->rates, 1)
35383 | set11nTries(i->rates, 2)
35384 | set11nTries(i->rates, 3)
35385 | (i->dur_update ? AR_DurUpdateEna : 0)
35386 | SM(0, AR_BurstDur);
35387
35388- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35389+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35390 | set11nRate(i->rates, 1)
35391 | set11nRate(i->rates, 2)
35392 | set11nRate(i->rates, 3);
35393 } else {
35394- ACCESS_ONCE(ads->ctl13) = 0;
35395- ACCESS_ONCE(ads->ctl14) = 0;
35396+ ACCESS_ONCE_RW(ads->ctl13) = 0;
35397+ ACCESS_ONCE_RW(ads->ctl14) = 0;
35398 }
35399
35400 ads->ctl20 = 0;
35401@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35402
35403 ctl17 = SM(i->keytype, AR_EncrType);
35404 if (!i->is_first) {
35405- ACCESS_ONCE(ads->ctl11) = 0;
35406- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35407- ACCESS_ONCE(ads->ctl15) = 0;
35408- ACCESS_ONCE(ads->ctl16) = 0;
35409- ACCESS_ONCE(ads->ctl17) = ctl17;
35410- ACCESS_ONCE(ads->ctl18) = 0;
35411- ACCESS_ONCE(ads->ctl19) = 0;
35412+ ACCESS_ONCE_RW(ads->ctl11) = 0;
35413+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35414+ ACCESS_ONCE_RW(ads->ctl15) = 0;
35415+ ACCESS_ONCE_RW(ads->ctl16) = 0;
35416+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35417+ ACCESS_ONCE_RW(ads->ctl18) = 0;
35418+ ACCESS_ONCE_RW(ads->ctl19) = 0;
35419 return;
35420 }
35421
35422- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35423+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35424 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35425 | SM(i->txpower, AR_XmitPower)
35426 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35427@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35428 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35429 ctl12 |= SM(val, AR_PAPRDChainMask);
35430
35431- ACCESS_ONCE(ads->ctl12) = ctl12;
35432- ACCESS_ONCE(ads->ctl17) = ctl17;
35433+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35434+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35435
35436- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35437+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35438 | set11nPktDurRTSCTS(i->rates, 1);
35439
35440- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35441+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35442 | set11nPktDurRTSCTS(i->rates, 3);
35443
35444- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35445+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35446 | set11nRateFlags(i->rates, 1)
35447 | set11nRateFlags(i->rates, 2)
35448 | set11nRateFlags(i->rates, 3)
35449 | SM(i->rtscts_rate, AR_RTSCTSRate);
35450
35451- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35452+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35453 }
35454
35455 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35456diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35457index e88f182..4e57f5d 100644
35458--- a/drivers/net/wireless/ath/ath9k/hw.h
35459+++ b/drivers/net/wireless/ath/ath9k/hw.h
35460@@ -614,7 +614,7 @@ struct ath_hw_private_ops {
35461
35462 /* ANI */
35463 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35464-};
35465+} __no_const;
35466
35467 /**
35468 * struct ath_hw_ops - callbacks used by hardware code and driver code
35469@@ -644,7 +644,7 @@ struct ath_hw_ops {
35470 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35471 struct ath_hw_antcomb_conf *antconf);
35472
35473-};
35474+} __no_const;
35475
35476 struct ath_nf_limits {
35477 s16 max;
35478@@ -664,7 +664,7 @@ enum ath_cal_list {
35479 #define AH_FASTCC 0x4
35480
35481 struct ath_hw {
35482- struct ath_ops reg_ops;
35483+ ath_ops_no_const reg_ops;
35484
35485 struct ieee80211_hw *hw;
35486 struct ath_common common;
35487diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35488index af00e2c..ab04d34 100644
35489--- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35490+++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35491@@ -545,7 +545,7 @@ struct phy_func_ptr {
35492 void (*carrsuppr)(struct brcms_phy *);
35493 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35494 void (*detach)(struct brcms_phy *);
35495-};
35496+} __no_const;
35497
35498 struct brcms_phy {
35499 struct brcms_phy_pub pubpi_ro;
35500diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35501index faec404..a5277f1 100644
35502--- a/drivers/net/wireless/iwlegacy/3945-mac.c
35503+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35504@@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35505 */
35506 if (il3945_mod_params.disable_hw_scan) {
35507 D_INFO("Disabling hw_scan\n");
35508- il3945_mac_ops.hw_scan = NULL;
35509+ pax_open_kernel();
35510+ *(void **)&il3945_mac_ops.hw_scan = NULL;
35511+ pax_close_kernel();
35512 }
35513
35514 D_INFO("*** LOAD DRIVER ***\n");
35515diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35516index b7ce6a6..5649756 100644
35517--- a/drivers/net/wireless/mac80211_hwsim.c
35518+++ b/drivers/net/wireless/mac80211_hwsim.c
35519@@ -1721,9 +1721,11 @@ static int __init init_mac80211_hwsim(void)
35520 return -EINVAL;
35521
35522 if (fake_hw_scan) {
35523- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35524- mac80211_hwsim_ops.sw_scan_start = NULL;
35525- mac80211_hwsim_ops.sw_scan_complete = NULL;
35526+ pax_open_kernel();
35527+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35528+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35529+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35530+ pax_close_kernel();
35531 }
35532
35533 spin_lock_init(&hwsim_radio_lock);
35534diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35535index 35225e9..95e6bf9 100644
35536--- a/drivers/net/wireless/mwifiex/main.h
35537+++ b/drivers/net/wireless/mwifiex/main.h
35538@@ -537,7 +537,7 @@ struct mwifiex_if_ops {
35539 void (*cleanup_mpa_buf) (struct mwifiex_adapter *);
35540 int (*cmdrsp_complete) (struct mwifiex_adapter *, struct sk_buff *);
35541 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35542-};
35543+} __no_const;
35544
35545 struct mwifiex_adapter {
35546 u8 iface_type;
35547diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35548index d66e298..55b0a89 100644
35549--- a/drivers/net/wireless/rndis_wlan.c
35550+++ b/drivers/net/wireless/rndis_wlan.c
35551@@ -1278,7 +1278,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35552
35553 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35554
35555- if (rts_threshold < 0 || rts_threshold > 2347)
35556+ if (rts_threshold > 2347)
35557 rts_threshold = 2347;
35558
35559 tmp = cpu_to_le32(rts_threshold);
35560diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
35561index c264dfa..08ee30e 100644
35562--- a/drivers/net/wireless/rt2x00/rt2x00.h
35563+++ b/drivers/net/wireless/rt2x00/rt2x00.h
35564@@ -396,7 +396,7 @@ struct rt2x00_intf {
35565 * for hardware which doesn't support hardware
35566 * sequence counting.
35567 */
35568- atomic_t seqno;
35569+ atomic_unchecked_t seqno;
35570 };
35571
35572 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
35573diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
35574index 50f92d5..f3afc41 100644
35575--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
35576+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
35577@@ -229,9 +229,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
35578 * sequence counter given by mac80211.
35579 */
35580 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
35581- seqno = atomic_add_return(0x10, &intf->seqno);
35582+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
35583 else
35584- seqno = atomic_read(&intf->seqno);
35585+ seqno = atomic_read_unchecked(&intf->seqno);
35586
35587 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
35588 hdr->seq_ctrl |= cpu_to_le16(seqno);
35589diff --git a/drivers/net/wireless/wl1251/wl1251.h b/drivers/net/wireless/wl1251/wl1251.h
35590index 9d8f581..0f6589e 100644
35591--- a/drivers/net/wireless/wl1251/wl1251.h
35592+++ b/drivers/net/wireless/wl1251/wl1251.h
35593@@ -266,7 +266,7 @@ struct wl1251_if_operations {
35594 void (*reset)(struct wl1251 *wl);
35595 void (*enable_irq)(struct wl1251 *wl);
35596 void (*disable_irq)(struct wl1251 *wl);
35597-};
35598+} __no_const;
35599
35600 struct wl1251 {
35601 struct ieee80211_hw *hw;
35602diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
35603index f34b5b2..b5abb9f 100644
35604--- a/drivers/oprofile/buffer_sync.c
35605+++ b/drivers/oprofile/buffer_sync.c
35606@@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
35607 if (cookie == NO_COOKIE)
35608 offset = pc;
35609 if (cookie == INVALID_COOKIE) {
35610- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35611+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35612 offset = pc;
35613 }
35614 if (cookie != last_cookie) {
35615@@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
35616 /* add userspace sample */
35617
35618 if (!mm) {
35619- atomic_inc(&oprofile_stats.sample_lost_no_mm);
35620+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
35621 return 0;
35622 }
35623
35624 cookie = lookup_dcookie(mm, s->eip, &offset);
35625
35626 if (cookie == INVALID_COOKIE) {
35627- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35628+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35629 return 0;
35630 }
35631
35632@@ -563,7 +563,7 @@ void sync_buffer(int cpu)
35633 /* ignore backtraces if failed to add a sample */
35634 if (state == sb_bt_start) {
35635 state = sb_bt_ignore;
35636- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
35637+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
35638 }
35639 }
35640 release_mm(mm);
35641diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
35642index c0cc4e7..44d4e54 100644
35643--- a/drivers/oprofile/event_buffer.c
35644+++ b/drivers/oprofile/event_buffer.c
35645@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
35646 }
35647
35648 if (buffer_pos == buffer_size) {
35649- atomic_inc(&oprofile_stats.event_lost_overflow);
35650+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
35651 return;
35652 }
35653
35654diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
35655index ed2c3ec..deda85a 100644
35656--- a/drivers/oprofile/oprof.c
35657+++ b/drivers/oprofile/oprof.c
35658@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
35659 if (oprofile_ops.switch_events())
35660 return;
35661
35662- atomic_inc(&oprofile_stats.multiplex_counter);
35663+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
35664 start_switch_worker();
35665 }
35666
35667diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
35668index 917d28e..d62d981 100644
35669--- a/drivers/oprofile/oprofile_stats.c
35670+++ b/drivers/oprofile/oprofile_stats.c
35671@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
35672 cpu_buf->sample_invalid_eip = 0;
35673 }
35674
35675- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
35676- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
35677- atomic_set(&oprofile_stats.event_lost_overflow, 0);
35678- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
35679- atomic_set(&oprofile_stats.multiplex_counter, 0);
35680+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
35681+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
35682+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
35683+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
35684+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
35685 }
35686
35687
35688diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
35689index 38b6fc0..b5cbfce 100644
35690--- a/drivers/oprofile/oprofile_stats.h
35691+++ b/drivers/oprofile/oprofile_stats.h
35692@@ -13,11 +13,11 @@
35693 #include <linux/atomic.h>
35694
35695 struct oprofile_stat_struct {
35696- atomic_t sample_lost_no_mm;
35697- atomic_t sample_lost_no_mapping;
35698- atomic_t bt_lost_no_mapping;
35699- atomic_t event_lost_overflow;
35700- atomic_t multiplex_counter;
35701+ atomic_unchecked_t sample_lost_no_mm;
35702+ atomic_unchecked_t sample_lost_no_mapping;
35703+ atomic_unchecked_t bt_lost_no_mapping;
35704+ atomic_unchecked_t event_lost_overflow;
35705+ atomic_unchecked_t multiplex_counter;
35706 };
35707
35708 extern struct oprofile_stat_struct oprofile_stats;
35709diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
35710index 849357c..b83c1e0 100644
35711--- a/drivers/oprofile/oprofilefs.c
35712+++ b/drivers/oprofile/oprofilefs.c
35713@@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
35714
35715
35716 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
35717- char const *name, atomic_t *val)
35718+ char const *name, atomic_unchecked_t *val)
35719 {
35720 return __oprofilefs_create_file(sb, root, name,
35721 &atomic_ro_fops, 0444, val);
35722diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
35723index 3f56bc0..707d642 100644
35724--- a/drivers/parport/procfs.c
35725+++ b/drivers/parport/procfs.c
35726@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
35727
35728 *ppos += len;
35729
35730- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
35731+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
35732 }
35733
35734 #ifdef CONFIG_PARPORT_1284
35735@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
35736
35737 *ppos += len;
35738
35739- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
35740+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
35741 }
35742 #endif /* IEEE1284.3 support. */
35743
35744diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
35745index 9fff878..ad0ad53 100644
35746--- a/drivers/pci/hotplug/cpci_hotplug.h
35747+++ b/drivers/pci/hotplug/cpci_hotplug.h
35748@@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
35749 int (*hardware_test) (struct slot* slot, u32 value);
35750 u8 (*get_power) (struct slot* slot);
35751 int (*set_power) (struct slot* slot, int value);
35752-};
35753+} __no_const;
35754
35755 struct cpci_hp_controller {
35756 unsigned int irq;
35757diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
35758index 76ba8a1..20ca857 100644
35759--- a/drivers/pci/hotplug/cpqphp_nvram.c
35760+++ b/drivers/pci/hotplug/cpqphp_nvram.c
35761@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
35762
35763 void compaq_nvram_init (void __iomem *rom_start)
35764 {
35765+
35766+#ifndef CONFIG_PAX_KERNEXEC
35767 if (rom_start) {
35768 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
35769 }
35770+#endif
35771+
35772 dbg("int15 entry = %p\n", compaq_int15_entry_point);
35773
35774 /* initialize our int15 lock */
35775diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
35776index b500840..d7159d3 100644
35777--- a/drivers/pci/pcie/aspm.c
35778+++ b/drivers/pci/pcie/aspm.c
35779@@ -27,9 +27,9 @@
35780 #define MODULE_PARAM_PREFIX "pcie_aspm."
35781
35782 /* Note: those are not register definitions */
35783-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
35784-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
35785-#define ASPM_STATE_L1 (4) /* L1 state */
35786+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
35787+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
35788+#define ASPM_STATE_L1 (4U) /* L1 state */
35789 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
35790 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
35791
35792diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
35793index 5e1ca3c..08082fe 100644
35794--- a/drivers/pci/probe.c
35795+++ b/drivers/pci/probe.c
35796@@ -215,7 +215,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
35797 u16 orig_cmd;
35798 struct pci_bus_region region;
35799
35800- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
35801+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
35802
35803 if (!dev->mmio_always_on) {
35804 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
35805diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
35806index 27911b5..5b6db88 100644
35807--- a/drivers/pci/proc.c
35808+++ b/drivers/pci/proc.c
35809@@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
35810 static int __init pci_proc_init(void)
35811 {
35812 struct pci_dev *dev = NULL;
35813+
35814+#ifdef CONFIG_GRKERNSEC_PROC_ADD
35815+#ifdef CONFIG_GRKERNSEC_PROC_USER
35816+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
35817+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
35818+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
35819+#endif
35820+#else
35821 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
35822+#endif
35823 proc_create("devices", 0, proc_bus_pci_dir,
35824 &proc_bus_pci_dev_operations);
35825 proc_initialized = 1;
35826diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
35827index d68c000..f6094ca 100644
35828--- a/drivers/platform/x86/thinkpad_acpi.c
35829+++ b/drivers/platform/x86/thinkpad_acpi.c
35830@@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
35831 return 0;
35832 }
35833
35834-void static hotkey_mask_warn_incomplete_mask(void)
35835+static void hotkey_mask_warn_incomplete_mask(void)
35836 {
35837 /* log only what the user can fix... */
35838 const u32 wantedmask = hotkey_driver_mask &
35839@@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
35840 }
35841 }
35842
35843-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35844- struct tp_nvram_state *newn,
35845- const u32 event_mask)
35846-{
35847-
35848 #define TPACPI_COMPARE_KEY(__scancode, __member) \
35849 do { \
35850 if ((event_mask & (1 << __scancode)) && \
35851@@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35852 tpacpi_hotkey_send_key(__scancode); \
35853 } while (0)
35854
35855- void issue_volchange(const unsigned int oldvol,
35856- const unsigned int newvol)
35857- {
35858- unsigned int i = oldvol;
35859+static void issue_volchange(const unsigned int oldvol,
35860+ const unsigned int newvol,
35861+ const u32 event_mask)
35862+{
35863+ unsigned int i = oldvol;
35864
35865- while (i > newvol) {
35866- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35867- i--;
35868- }
35869- while (i < newvol) {
35870- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35871- i++;
35872- }
35873+ while (i > newvol) {
35874+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35875+ i--;
35876 }
35877+ while (i < newvol) {
35878+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35879+ i++;
35880+ }
35881+}
35882
35883- void issue_brightnesschange(const unsigned int oldbrt,
35884- const unsigned int newbrt)
35885- {
35886- unsigned int i = oldbrt;
35887+static void issue_brightnesschange(const unsigned int oldbrt,
35888+ const unsigned int newbrt,
35889+ const u32 event_mask)
35890+{
35891+ unsigned int i = oldbrt;
35892
35893- while (i > newbrt) {
35894- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35895- i--;
35896- }
35897- while (i < newbrt) {
35898- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35899- i++;
35900- }
35901+ while (i > newbrt) {
35902+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35903+ i--;
35904+ }
35905+ while (i < newbrt) {
35906+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35907+ i++;
35908 }
35909+}
35910
35911+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35912+ struct tp_nvram_state *newn,
35913+ const u32 event_mask)
35914+{
35915 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
35916 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
35917 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
35918@@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35919 oldn->volume_level != newn->volume_level) {
35920 /* recently muted, or repeated mute keypress, or
35921 * multiple presses ending in mute */
35922- issue_volchange(oldn->volume_level, newn->volume_level);
35923+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35924 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
35925 }
35926 } else {
35927@@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35928 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35929 }
35930 if (oldn->volume_level != newn->volume_level) {
35931- issue_volchange(oldn->volume_level, newn->volume_level);
35932+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35933 } else if (oldn->volume_toggle != newn->volume_toggle) {
35934 /* repeated vol up/down keypress at end of scale ? */
35935 if (newn->volume_level == 0)
35936@@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35937 /* handle brightness */
35938 if (oldn->brightness_level != newn->brightness_level) {
35939 issue_brightnesschange(oldn->brightness_level,
35940- newn->brightness_level);
35941+ newn->brightness_level,
35942+ event_mask);
35943 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
35944 /* repeated key presses that didn't change state */
35945 if (newn->brightness_level == 0)
35946@@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35947 && !tp_features.bright_unkfw)
35948 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35949 }
35950+}
35951
35952 #undef TPACPI_COMPARE_KEY
35953 #undef TPACPI_MAY_SEND_KEY
35954-}
35955
35956 /*
35957 * Polling driver
35958diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
35959index 769d265..a3a05ca 100644
35960--- a/drivers/pnp/pnpbios/bioscalls.c
35961+++ b/drivers/pnp/pnpbios/bioscalls.c
35962@@ -58,7 +58,7 @@ do { \
35963 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
35964 } while(0)
35965
35966-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
35967+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
35968 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
35969
35970 /*
35971@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
35972
35973 cpu = get_cpu();
35974 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
35975+
35976+ pax_open_kernel();
35977 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
35978+ pax_close_kernel();
35979
35980 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
35981 spin_lock_irqsave(&pnp_bios_lock, flags);
35982@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
35983 :"memory");
35984 spin_unlock_irqrestore(&pnp_bios_lock, flags);
35985
35986+ pax_open_kernel();
35987 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
35988+ pax_close_kernel();
35989+
35990 put_cpu();
35991
35992 /* If we get here and this is set then the PnP BIOS faulted on us. */
35993@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
35994 return status;
35995 }
35996
35997-void pnpbios_calls_init(union pnp_bios_install_struct *header)
35998+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
35999 {
36000 int i;
36001
36002@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36003 pnp_bios_callpoint.offset = header->fields.pm16offset;
36004 pnp_bios_callpoint.segment = PNP_CS16;
36005
36006+ pax_open_kernel();
36007+
36008 for_each_possible_cpu(i) {
36009 struct desc_struct *gdt = get_cpu_gdt_table(i);
36010 if (!gdt)
36011@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36012 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36013 (unsigned long)__va(header->fields.pm16dseg));
36014 }
36015+
36016+ pax_close_kernel();
36017 }
36018diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36019index b0ecacb..7c9da2e 100644
36020--- a/drivers/pnp/resource.c
36021+++ b/drivers/pnp/resource.c
36022@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36023 return 1;
36024
36025 /* check if the resource is valid */
36026- if (*irq < 0 || *irq > 15)
36027+ if (*irq > 15)
36028 return 0;
36029
36030 /* check if the resource is reserved */
36031@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36032 return 1;
36033
36034 /* check if the resource is valid */
36035- if (*dma < 0 || *dma == 4 || *dma > 7)
36036+ if (*dma == 4 || *dma > 7)
36037 return 0;
36038
36039 /* check if the resource is reserved */
36040diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36041index 222ccd8..6275fa5 100644
36042--- a/drivers/power/bq27x00_battery.c
36043+++ b/drivers/power/bq27x00_battery.c
36044@@ -72,7 +72,7 @@
36045 struct bq27x00_device_info;
36046 struct bq27x00_access_methods {
36047 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36048-};
36049+} __no_const;
36050
36051 enum bq27x00_chip { BQ27000, BQ27500 };
36052
36053diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36054index 4c5b053..104263e 100644
36055--- a/drivers/regulator/max8660.c
36056+++ b/drivers/regulator/max8660.c
36057@@ -385,8 +385,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36058 max8660->shadow_regs[MAX8660_OVER1] = 5;
36059 } else {
36060 /* Otherwise devices can be toggled via software */
36061- max8660_dcdc_ops.enable = max8660_dcdc_enable;
36062- max8660_dcdc_ops.disable = max8660_dcdc_disable;
36063+ pax_open_kernel();
36064+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36065+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36066+ pax_close_kernel();
36067 }
36068
36069 /*
36070diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36071index 845aa22..99ec402 100644
36072--- a/drivers/regulator/mc13892-regulator.c
36073+++ b/drivers/regulator/mc13892-regulator.c
36074@@ -574,10 +574,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36075 }
36076 mc13xxx_unlock(mc13892);
36077
36078- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36079+ pax_open_kernel();
36080+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36081 = mc13892_vcam_set_mode;
36082- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36083+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36084 = mc13892_vcam_get_mode;
36085+ pax_close_kernel();
36086
36087 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36088 ARRAY_SIZE(mc13892_regulators));
36089diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36090index cace6d3..f623fda 100644
36091--- a/drivers/rtc/rtc-dev.c
36092+++ b/drivers/rtc/rtc-dev.c
36093@@ -14,6 +14,7 @@
36094 #include <linux/module.h>
36095 #include <linux/rtc.h>
36096 #include <linux/sched.h>
36097+#include <linux/grsecurity.h>
36098 #include "rtc-core.h"
36099
36100 static dev_t rtc_devt;
36101@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36102 if (copy_from_user(&tm, uarg, sizeof(tm)))
36103 return -EFAULT;
36104
36105+ gr_log_timechange();
36106+
36107 return rtc_set_time(rtc, &tm);
36108
36109 case RTC_PIE_ON:
36110diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36111index 3fcf627..f334910 100644
36112--- a/drivers/scsi/aacraid/aacraid.h
36113+++ b/drivers/scsi/aacraid/aacraid.h
36114@@ -492,7 +492,7 @@ struct adapter_ops
36115 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36116 /* Administrative operations */
36117 int (*adapter_comm)(struct aac_dev * dev, int comm);
36118-};
36119+} __no_const;
36120
36121 /*
36122 * Define which interrupt handler needs to be installed
36123diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36124index 0d279c44..3d25a97 100644
36125--- a/drivers/scsi/aacraid/linit.c
36126+++ b/drivers/scsi/aacraid/linit.c
36127@@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36128 #elif defined(__devinitconst)
36129 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36130 #else
36131-static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36132+static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36133 #endif
36134 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36135 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36136diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36137index ff80552..1c4120c 100644
36138--- a/drivers/scsi/aic94xx/aic94xx_init.c
36139+++ b/drivers/scsi/aic94xx/aic94xx_init.c
36140@@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36141 .lldd_ata_set_dmamode = asd_set_dmamode,
36142 };
36143
36144-static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36145+static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36146 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36147 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36148 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36149diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36150index 4ad7e36..d004679 100644
36151--- a/drivers/scsi/bfa/bfa.h
36152+++ b/drivers/scsi/bfa/bfa.h
36153@@ -196,7 +196,7 @@ struct bfa_hwif_s {
36154 u32 *end);
36155 int cpe_vec_q0;
36156 int rme_vec_q0;
36157-};
36158+} __no_const;
36159 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36160
36161 struct bfa_faa_cbfn_s {
36162diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36163index f0f80e2..8ec946b 100644
36164--- a/drivers/scsi/bfa/bfa_fcpim.c
36165+++ b/drivers/scsi/bfa/bfa_fcpim.c
36166@@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36167
36168 bfa_iotag_attach(fcp);
36169
36170- fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36171+ fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36172 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36173 (fcp->num_itns * sizeof(struct bfa_itn_s));
36174 memset(fcp->itn_arr, 0,
36175@@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36176 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36177 {
36178 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36179- struct bfa_itn_s *itn;
36180+ bfa_itn_s_no_const *itn;
36181
36182 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36183 itn->isr = isr;
36184diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36185index 36f26da..38a34a8 100644
36186--- a/drivers/scsi/bfa/bfa_fcpim.h
36187+++ b/drivers/scsi/bfa/bfa_fcpim.h
36188@@ -37,6 +37,7 @@ struct bfa_iotag_s {
36189 struct bfa_itn_s {
36190 bfa_isr_func_t isr;
36191 };
36192+typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36193
36194 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36195 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36196@@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36197 struct list_head iotag_tio_free_q; /* free IO resources */
36198 struct list_head iotag_unused_q; /* unused IO resources*/
36199 struct bfa_iotag_s *iotag_arr;
36200- struct bfa_itn_s *itn_arr;
36201+ bfa_itn_s_no_const *itn_arr;
36202 int num_ioim_reqs;
36203 int num_fwtio_reqs;
36204 int num_itns;
36205diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36206index 1a99d4b..e85d64b 100644
36207--- a/drivers/scsi/bfa/bfa_ioc.h
36208+++ b/drivers/scsi/bfa/bfa_ioc.h
36209@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36210 bfa_ioc_disable_cbfn_t disable_cbfn;
36211 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36212 bfa_ioc_reset_cbfn_t reset_cbfn;
36213-};
36214+} __no_const;
36215
36216 /*
36217 * IOC event notification mechanism.
36218@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36219 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36220 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36221 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36222-};
36223+} __no_const;
36224
36225 /*
36226 * Queue element to wait for room in request queue. FIFO order is
36227diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36228index a3a056a..b9bbc2f 100644
36229--- a/drivers/scsi/hosts.c
36230+++ b/drivers/scsi/hosts.c
36231@@ -42,7 +42,7 @@
36232 #include "scsi_logging.h"
36233
36234
36235-static atomic_t scsi_host_next_hn; /* host_no for next new host */
36236+static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
36237
36238
36239 static void scsi_host_cls_release(struct device *dev)
36240@@ -360,7 +360,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36241 * subtract one because we increment first then return, but we need to
36242 * know what the next host number was before increment
36243 */
36244- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36245+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36246 shost->dma_channel = 0xff;
36247
36248 /* These three are default values which can be overridden */
36249diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36250index 500e20d..ebd3059 100644
36251--- a/drivers/scsi/hpsa.c
36252+++ b/drivers/scsi/hpsa.c
36253@@ -521,7 +521,7 @@ static inline u32 next_command(struct ctlr_info *h)
36254 u32 a;
36255
36256 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36257- return h->access.command_completed(h);
36258+ return h->access->command_completed(h);
36259
36260 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36261 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36262@@ -3002,7 +3002,7 @@ static void start_io(struct ctlr_info *h)
36263 while (!list_empty(&h->reqQ)) {
36264 c = list_entry(h->reqQ.next, struct CommandList, list);
36265 /* can't do anything if fifo is full */
36266- if ((h->access.fifo_full(h))) {
36267+ if ((h->access->fifo_full(h))) {
36268 dev_warn(&h->pdev->dev, "fifo full\n");
36269 break;
36270 }
36271@@ -3012,7 +3012,7 @@ static void start_io(struct ctlr_info *h)
36272 h->Qdepth--;
36273
36274 /* Tell the controller execute command */
36275- h->access.submit_command(h, c);
36276+ h->access->submit_command(h, c);
36277
36278 /* Put job onto the completed Q */
36279 addQ(&h->cmpQ, c);
36280@@ -3021,17 +3021,17 @@ static void start_io(struct ctlr_info *h)
36281
36282 static inline unsigned long get_next_completion(struct ctlr_info *h)
36283 {
36284- return h->access.command_completed(h);
36285+ return h->access->command_completed(h);
36286 }
36287
36288 static inline bool interrupt_pending(struct ctlr_info *h)
36289 {
36290- return h->access.intr_pending(h);
36291+ return h->access->intr_pending(h);
36292 }
36293
36294 static inline long interrupt_not_for_us(struct ctlr_info *h)
36295 {
36296- return (h->access.intr_pending(h) == 0) ||
36297+ return (h->access->intr_pending(h) == 0) ||
36298 (h->interrupts_enabled == 0);
36299 }
36300
36301@@ -3930,7 +3930,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36302 if (prod_index < 0)
36303 return -ENODEV;
36304 h->product_name = products[prod_index].product_name;
36305- h->access = *(products[prod_index].access);
36306+ h->access = products[prod_index].access;
36307
36308 if (hpsa_board_disabled(h->pdev)) {
36309 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36310@@ -4175,7 +4175,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36311
36312 assert_spin_locked(&lockup_detector_lock);
36313 remove_ctlr_from_lockup_detector_list(h);
36314- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36315+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36316 spin_lock_irqsave(&h->lock, flags);
36317 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36318 spin_unlock_irqrestore(&h->lock, flags);
36319@@ -4355,7 +4355,7 @@ reinit_after_soft_reset:
36320 }
36321
36322 /* make sure the board interrupts are off */
36323- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36324+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36325
36326 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36327 goto clean2;
36328@@ -4389,7 +4389,7 @@ reinit_after_soft_reset:
36329 * fake ones to scoop up any residual completions.
36330 */
36331 spin_lock_irqsave(&h->lock, flags);
36332- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36333+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36334 spin_unlock_irqrestore(&h->lock, flags);
36335 free_irq(h->intr[h->intr_mode], h);
36336 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36337@@ -4408,9 +4408,9 @@ reinit_after_soft_reset:
36338 dev_info(&h->pdev->dev, "Board READY.\n");
36339 dev_info(&h->pdev->dev,
36340 "Waiting for stale completions to drain.\n");
36341- h->access.set_intr_mask(h, HPSA_INTR_ON);
36342+ h->access->set_intr_mask(h, HPSA_INTR_ON);
36343 msleep(10000);
36344- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36345+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36346
36347 rc = controller_reset_failed(h->cfgtable);
36348 if (rc)
36349@@ -4431,7 +4431,7 @@ reinit_after_soft_reset:
36350 }
36351
36352 /* Turn the interrupts on so we can service requests */
36353- h->access.set_intr_mask(h, HPSA_INTR_ON);
36354+ h->access->set_intr_mask(h, HPSA_INTR_ON);
36355
36356 hpsa_hba_inquiry(h);
36357 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36358@@ -4483,7 +4483,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36359 * To write all data in the battery backed cache to disks
36360 */
36361 hpsa_flush_cache(h);
36362- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36363+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36364 free_irq(h->intr[h->intr_mode], h);
36365 #ifdef CONFIG_PCI_MSI
36366 if (h->msix_vector)
36367@@ -4657,7 +4657,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36368 return;
36369 }
36370 /* Change the access methods to the performant access methods */
36371- h->access = SA5_performant_access;
36372+ h->access = &SA5_performant_access;
36373 h->transMethod = CFGTBL_Trans_Performant;
36374 }
36375
36376diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36377index 7b28d54..952f23a 100644
36378--- a/drivers/scsi/hpsa.h
36379+++ b/drivers/scsi/hpsa.h
36380@@ -72,7 +72,7 @@ struct ctlr_info {
36381 unsigned int msix_vector;
36382 unsigned int msi_vector;
36383 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36384- struct access_method access;
36385+ struct access_method *access;
36386
36387 /* queue and queue Info */
36388 struct list_head reqQ;
36389diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36390index f2df059..a3a9930 100644
36391--- a/drivers/scsi/ips.h
36392+++ b/drivers/scsi/ips.h
36393@@ -1027,7 +1027,7 @@ typedef struct {
36394 int (*intr)(struct ips_ha *);
36395 void (*enableint)(struct ips_ha *);
36396 uint32_t (*statupd)(struct ips_ha *);
36397-} ips_hw_func_t;
36398+} __no_const ips_hw_func_t;
36399
36400 typedef struct ips_ha {
36401 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36402diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36403index aceffad..c35c08d 100644
36404--- a/drivers/scsi/libfc/fc_exch.c
36405+++ b/drivers/scsi/libfc/fc_exch.c
36406@@ -105,12 +105,12 @@ struct fc_exch_mgr {
36407 * all together if not used XXX
36408 */
36409 struct {
36410- atomic_t no_free_exch;
36411- atomic_t no_free_exch_xid;
36412- atomic_t xid_not_found;
36413- atomic_t xid_busy;
36414- atomic_t seq_not_found;
36415- atomic_t non_bls_resp;
36416+ atomic_unchecked_t no_free_exch;
36417+ atomic_unchecked_t no_free_exch_xid;
36418+ atomic_unchecked_t xid_not_found;
36419+ atomic_unchecked_t xid_busy;
36420+ atomic_unchecked_t seq_not_found;
36421+ atomic_unchecked_t non_bls_resp;
36422 } stats;
36423 };
36424
36425@@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36426 /* allocate memory for exchange */
36427 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36428 if (!ep) {
36429- atomic_inc(&mp->stats.no_free_exch);
36430+ atomic_inc_unchecked(&mp->stats.no_free_exch);
36431 goto out;
36432 }
36433 memset(ep, 0, sizeof(*ep));
36434@@ -780,7 +780,7 @@ out:
36435 return ep;
36436 err:
36437 spin_unlock_bh(&pool->lock);
36438- atomic_inc(&mp->stats.no_free_exch_xid);
36439+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36440 mempool_free(ep, mp->ep_pool);
36441 return NULL;
36442 }
36443@@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36444 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36445 ep = fc_exch_find(mp, xid);
36446 if (!ep) {
36447- atomic_inc(&mp->stats.xid_not_found);
36448+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36449 reject = FC_RJT_OX_ID;
36450 goto out;
36451 }
36452@@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36453 ep = fc_exch_find(mp, xid);
36454 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36455 if (ep) {
36456- atomic_inc(&mp->stats.xid_busy);
36457+ atomic_inc_unchecked(&mp->stats.xid_busy);
36458 reject = FC_RJT_RX_ID;
36459 goto rel;
36460 }
36461@@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36462 }
36463 xid = ep->xid; /* get our XID */
36464 } else if (!ep) {
36465- atomic_inc(&mp->stats.xid_not_found);
36466+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36467 reject = FC_RJT_RX_ID; /* XID not found */
36468 goto out;
36469 }
36470@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36471 } else {
36472 sp = &ep->seq;
36473 if (sp->id != fh->fh_seq_id) {
36474- atomic_inc(&mp->stats.seq_not_found);
36475+ atomic_inc_unchecked(&mp->stats.seq_not_found);
36476 if (f_ctl & FC_FC_END_SEQ) {
36477 /*
36478 * Update sequence_id based on incoming last
36479@@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36480
36481 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36482 if (!ep) {
36483- atomic_inc(&mp->stats.xid_not_found);
36484+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36485 goto out;
36486 }
36487 if (ep->esb_stat & ESB_ST_COMPLETE) {
36488- atomic_inc(&mp->stats.xid_not_found);
36489+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36490 goto rel;
36491 }
36492 if (ep->rxid == FC_XID_UNKNOWN)
36493 ep->rxid = ntohs(fh->fh_rx_id);
36494 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36495- atomic_inc(&mp->stats.xid_not_found);
36496+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36497 goto rel;
36498 }
36499 if (ep->did != ntoh24(fh->fh_s_id) &&
36500 ep->did != FC_FID_FLOGI) {
36501- atomic_inc(&mp->stats.xid_not_found);
36502+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36503 goto rel;
36504 }
36505 sof = fr_sof(fp);
36506@@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36507 sp->ssb_stat |= SSB_ST_RESP;
36508 sp->id = fh->fh_seq_id;
36509 } else if (sp->id != fh->fh_seq_id) {
36510- atomic_inc(&mp->stats.seq_not_found);
36511+ atomic_inc_unchecked(&mp->stats.seq_not_found);
36512 goto rel;
36513 }
36514
36515@@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36516 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36517
36518 if (!sp)
36519- atomic_inc(&mp->stats.xid_not_found);
36520+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36521 else
36522- atomic_inc(&mp->stats.non_bls_resp);
36523+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
36524
36525 fc_frame_free(fp);
36526 }
36527diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36528index 441d88a..689ad71 100644
36529--- a/drivers/scsi/libsas/sas_ata.c
36530+++ b/drivers/scsi/libsas/sas_ata.c
36531@@ -529,7 +529,7 @@ static struct ata_port_operations sas_sata_ops = {
36532 .postreset = ata_std_postreset,
36533 .error_handler = ata_std_error_handler,
36534 .post_internal_cmd = sas_ata_post_internal,
36535- .qc_defer = ata_std_qc_defer,
36536+ .qc_defer = ata_std_qc_defer,
36537 .qc_prep = ata_noop_qc_prep,
36538 .qc_issue = sas_ata_qc_issue,
36539 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36540diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36541index 3a1ffdd..8eb7c71 100644
36542--- a/drivers/scsi/lpfc/lpfc.h
36543+++ b/drivers/scsi/lpfc/lpfc.h
36544@@ -413,7 +413,7 @@ struct lpfc_vport {
36545 struct dentry *debug_nodelist;
36546 struct dentry *vport_debugfs_root;
36547 struct lpfc_debugfs_trc *disc_trc;
36548- atomic_t disc_trc_cnt;
36549+ atomic_unchecked_t disc_trc_cnt;
36550 #endif
36551 uint8_t stat_data_enabled;
36552 uint8_t stat_data_blocked;
36553@@ -826,8 +826,8 @@ struct lpfc_hba {
36554 struct timer_list fabric_block_timer;
36555 unsigned long bit_flags;
36556 #define FABRIC_COMANDS_BLOCKED 0
36557- atomic_t num_rsrc_err;
36558- atomic_t num_cmd_success;
36559+ atomic_unchecked_t num_rsrc_err;
36560+ atomic_unchecked_t num_cmd_success;
36561 unsigned long last_rsrc_error_time;
36562 unsigned long last_ramp_down_time;
36563 unsigned long last_ramp_up_time;
36564@@ -863,7 +863,7 @@ struct lpfc_hba {
36565
36566 struct dentry *debug_slow_ring_trc;
36567 struct lpfc_debugfs_trc *slow_ring_trc;
36568- atomic_t slow_ring_trc_cnt;
36569+ atomic_unchecked_t slow_ring_trc_cnt;
36570 /* iDiag debugfs sub-directory */
36571 struct dentry *idiag_root;
36572 struct dentry *idiag_pci_cfg;
36573diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
36574index af04b0d..8f1a97e 100644
36575--- a/drivers/scsi/lpfc/lpfc_debugfs.c
36576+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
36577@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
36578
36579 #include <linux/debugfs.h>
36580
36581-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36582+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36583 static unsigned long lpfc_debugfs_start_time = 0L;
36584
36585 /* iDiag */
36586@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
36587 lpfc_debugfs_enable = 0;
36588
36589 len = 0;
36590- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
36591+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
36592 (lpfc_debugfs_max_disc_trc - 1);
36593 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
36594 dtp = vport->disc_trc + i;
36595@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
36596 lpfc_debugfs_enable = 0;
36597
36598 len = 0;
36599- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
36600+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
36601 (lpfc_debugfs_max_slow_ring_trc - 1);
36602 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
36603 dtp = phba->slow_ring_trc + i;
36604@@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
36605 !vport || !vport->disc_trc)
36606 return;
36607
36608- index = atomic_inc_return(&vport->disc_trc_cnt) &
36609+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
36610 (lpfc_debugfs_max_disc_trc - 1);
36611 dtp = vport->disc_trc + index;
36612 dtp->fmt = fmt;
36613 dtp->data1 = data1;
36614 dtp->data2 = data2;
36615 dtp->data3 = data3;
36616- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36617+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36618 dtp->jif = jiffies;
36619 #endif
36620 return;
36621@@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
36622 !phba || !phba->slow_ring_trc)
36623 return;
36624
36625- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
36626+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
36627 (lpfc_debugfs_max_slow_ring_trc - 1);
36628 dtp = phba->slow_ring_trc + index;
36629 dtp->fmt = fmt;
36630 dtp->data1 = data1;
36631 dtp->data2 = data2;
36632 dtp->data3 = data3;
36633- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36634+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36635 dtp->jif = jiffies;
36636 #endif
36637 return;
36638@@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36639 "slow_ring buffer\n");
36640 goto debug_failed;
36641 }
36642- atomic_set(&phba->slow_ring_trc_cnt, 0);
36643+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
36644 memset(phba->slow_ring_trc, 0,
36645 (sizeof(struct lpfc_debugfs_trc) *
36646 lpfc_debugfs_max_slow_ring_trc));
36647@@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36648 "buffer\n");
36649 goto debug_failed;
36650 }
36651- atomic_set(&vport->disc_trc_cnt, 0);
36652+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
36653
36654 snprintf(name, sizeof(name), "discovery_trace");
36655 vport->debug_disc_trc =
36656diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
36657index 9598fdc..7e9f3d9 100644
36658--- a/drivers/scsi/lpfc/lpfc_init.c
36659+++ b/drivers/scsi/lpfc/lpfc_init.c
36660@@ -10266,8 +10266,10 @@ lpfc_init(void)
36661 "misc_register returned with status %d", error);
36662
36663 if (lpfc_enable_npiv) {
36664- lpfc_transport_functions.vport_create = lpfc_vport_create;
36665- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36666+ pax_open_kernel();
36667+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
36668+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36669+ pax_close_kernel();
36670 }
36671 lpfc_transport_template =
36672 fc_attach_transport(&lpfc_transport_functions);
36673diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
36674index 88f3a83..686d3fa 100644
36675--- a/drivers/scsi/lpfc/lpfc_scsi.c
36676+++ b/drivers/scsi/lpfc/lpfc_scsi.c
36677@@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
36678 uint32_t evt_posted;
36679
36680 spin_lock_irqsave(&phba->hbalock, flags);
36681- atomic_inc(&phba->num_rsrc_err);
36682+ atomic_inc_unchecked(&phba->num_rsrc_err);
36683 phba->last_rsrc_error_time = jiffies;
36684
36685 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
36686@@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
36687 unsigned long flags;
36688 struct lpfc_hba *phba = vport->phba;
36689 uint32_t evt_posted;
36690- atomic_inc(&phba->num_cmd_success);
36691+ atomic_inc_unchecked(&phba->num_cmd_success);
36692
36693 if (vport->cfg_lun_queue_depth <= queue_depth)
36694 return;
36695@@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36696 unsigned long num_rsrc_err, num_cmd_success;
36697 int i;
36698
36699- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
36700- num_cmd_success = atomic_read(&phba->num_cmd_success);
36701+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
36702+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
36703
36704 vports = lpfc_create_vport_work_array(phba);
36705 if (vports != NULL)
36706@@ -417,8 +417,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36707 }
36708 }
36709 lpfc_destroy_vport_work_array(phba, vports);
36710- atomic_set(&phba->num_rsrc_err, 0);
36711- atomic_set(&phba->num_cmd_success, 0);
36712+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
36713+ atomic_set_unchecked(&phba->num_cmd_success, 0);
36714 }
36715
36716 /**
36717@@ -452,8 +452,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
36718 }
36719 }
36720 lpfc_destroy_vport_work_array(phba, vports);
36721- atomic_set(&phba->num_rsrc_err, 0);
36722- atomic_set(&phba->num_cmd_success, 0);
36723+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
36724+ atomic_set_unchecked(&phba->num_cmd_success, 0);
36725 }
36726
36727 /**
36728diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
36729index ea8a0b4..812a124 100644
36730--- a/drivers/scsi/pmcraid.c
36731+++ b/drivers/scsi/pmcraid.c
36732@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
36733 res->scsi_dev = scsi_dev;
36734 scsi_dev->hostdata = res;
36735 res->change_detected = 0;
36736- atomic_set(&res->read_failures, 0);
36737- atomic_set(&res->write_failures, 0);
36738+ atomic_set_unchecked(&res->read_failures, 0);
36739+ atomic_set_unchecked(&res->write_failures, 0);
36740 rc = 0;
36741 }
36742 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
36743@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
36744
36745 /* If this was a SCSI read/write command keep count of errors */
36746 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
36747- atomic_inc(&res->read_failures);
36748+ atomic_inc_unchecked(&res->read_failures);
36749 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
36750- atomic_inc(&res->write_failures);
36751+ atomic_inc_unchecked(&res->write_failures);
36752
36753 if (!RES_IS_GSCSI(res->cfg_entry) &&
36754 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
36755@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
36756 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36757 * hrrq_id assigned here in queuecommand
36758 */
36759- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36760+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36761 pinstance->num_hrrq;
36762 cmd->cmd_done = pmcraid_io_done;
36763
36764@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
36765 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36766 * hrrq_id assigned here in queuecommand
36767 */
36768- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36769+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36770 pinstance->num_hrrq;
36771
36772 if (request_size) {
36773@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
36774
36775 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
36776 /* add resources only after host is added into system */
36777- if (!atomic_read(&pinstance->expose_resources))
36778+ if (!atomic_read_unchecked(&pinstance->expose_resources))
36779 return;
36780
36781 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
36782@@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
36783 init_waitqueue_head(&pinstance->reset_wait_q);
36784
36785 atomic_set(&pinstance->outstanding_cmds, 0);
36786- atomic_set(&pinstance->last_message_id, 0);
36787- atomic_set(&pinstance->expose_resources, 0);
36788+ atomic_set_unchecked(&pinstance->last_message_id, 0);
36789+ atomic_set_unchecked(&pinstance->expose_resources, 0);
36790
36791 INIT_LIST_HEAD(&pinstance->free_res_q);
36792 INIT_LIST_HEAD(&pinstance->used_res_q);
36793@@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
36794 /* Schedule worker thread to handle CCN and take care of adding and
36795 * removing devices to OS
36796 */
36797- atomic_set(&pinstance->expose_resources, 1);
36798+ atomic_set_unchecked(&pinstance->expose_resources, 1);
36799 schedule_work(&pinstance->worker_q);
36800 return rc;
36801
36802diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
36803index e1d150f..6c6df44 100644
36804--- a/drivers/scsi/pmcraid.h
36805+++ b/drivers/scsi/pmcraid.h
36806@@ -748,7 +748,7 @@ struct pmcraid_instance {
36807 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
36808
36809 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
36810- atomic_t last_message_id;
36811+ atomic_unchecked_t last_message_id;
36812
36813 /* configuration table */
36814 struct pmcraid_config_table *cfg_table;
36815@@ -777,7 +777,7 @@ struct pmcraid_instance {
36816 atomic_t outstanding_cmds;
36817
36818 /* should add/delete resources to mid-layer now ?*/
36819- atomic_t expose_resources;
36820+ atomic_unchecked_t expose_resources;
36821
36822
36823
36824@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
36825 struct pmcraid_config_table_entry_ext cfg_entry_ext;
36826 };
36827 struct scsi_device *scsi_dev; /* Link scsi_device structure */
36828- atomic_t read_failures; /* count of failed READ commands */
36829- atomic_t write_failures; /* count of failed WRITE commands */
36830+ atomic_unchecked_t read_failures; /* count of failed READ commands */
36831+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
36832
36833 /* To indicate add/delete/modify during CCN */
36834 u8 change_detected;
36835diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
36836index a244303..6015eb7 100644
36837--- a/drivers/scsi/qla2xxx/qla_def.h
36838+++ b/drivers/scsi/qla2xxx/qla_def.h
36839@@ -2264,7 +2264,7 @@ struct isp_operations {
36840 int (*start_scsi) (srb_t *);
36841 int (*abort_isp) (struct scsi_qla_host *);
36842 int (*iospace_config)(struct qla_hw_data*);
36843-};
36844+} __no_const;
36845
36846 /* MSI-X Support *************************************************************/
36847
36848diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
36849index 7f2492e..5113877 100644
36850--- a/drivers/scsi/qla4xxx/ql4_def.h
36851+++ b/drivers/scsi/qla4xxx/ql4_def.h
36852@@ -268,7 +268,7 @@ struct ddb_entry {
36853 * (4000 only) */
36854 atomic_t relogin_timer; /* Max Time to wait for
36855 * relogin to complete */
36856- atomic_t relogin_retry_count; /* Num of times relogin has been
36857+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
36858 * retried */
36859 uint32_t default_time2wait; /* Default Min time between
36860 * relogins (+aens) */
36861diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
36862index ee47820..a83b1f4 100644
36863--- a/drivers/scsi/qla4xxx/ql4_os.c
36864+++ b/drivers/scsi/qla4xxx/ql4_os.c
36865@@ -2551,12 +2551,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
36866 */
36867 if (!iscsi_is_session_online(cls_sess)) {
36868 /* Reset retry relogin timer */
36869- atomic_inc(&ddb_entry->relogin_retry_count);
36870+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
36871 DEBUG2(ql4_printk(KERN_INFO, ha,
36872 "%s: index[%d] relogin timed out-retrying"
36873 " relogin (%d), retry (%d)\n", __func__,
36874 ddb_entry->fw_ddb_index,
36875- atomic_read(&ddb_entry->relogin_retry_count),
36876+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
36877 ddb_entry->default_time2wait + 4));
36878 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
36879 atomic_set(&ddb_entry->retry_relogin_timer,
36880@@ -4453,7 +4453,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
36881
36882 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
36883 atomic_set(&ddb_entry->relogin_timer, 0);
36884- atomic_set(&ddb_entry->relogin_retry_count, 0);
36885+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
36886 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
36887 ddb_entry->default_relogin_timeout =
36888 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
36889diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
36890index 07322ec..91ccc23 100644
36891--- a/drivers/scsi/scsi.c
36892+++ b/drivers/scsi/scsi.c
36893@@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
36894 unsigned long timeout;
36895 int rtn = 0;
36896
36897- atomic_inc(&cmd->device->iorequest_cnt);
36898+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36899
36900 /* check if the device is still usable */
36901 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
36902diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
36903index 4037fd5..a19fcc7 100644
36904--- a/drivers/scsi/scsi_lib.c
36905+++ b/drivers/scsi/scsi_lib.c
36906@@ -1415,7 +1415,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
36907 shost = sdev->host;
36908 scsi_init_cmd_errh(cmd);
36909 cmd->result = DID_NO_CONNECT << 16;
36910- atomic_inc(&cmd->device->iorequest_cnt);
36911+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36912
36913 /*
36914 * SCSI request completion path will do scsi_device_unbusy(),
36915@@ -1441,9 +1441,9 @@ static void scsi_softirq_done(struct request *rq)
36916
36917 INIT_LIST_HEAD(&cmd->eh_entry);
36918
36919- atomic_inc(&cmd->device->iodone_cnt);
36920+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
36921 if (cmd->result)
36922- atomic_inc(&cmd->device->ioerr_cnt);
36923+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
36924
36925 disposition = scsi_decide_disposition(cmd);
36926 if (disposition != SUCCESS &&
36927diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
36928index 04c2a27..9d8bd66 100644
36929--- a/drivers/scsi/scsi_sysfs.c
36930+++ b/drivers/scsi/scsi_sysfs.c
36931@@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
36932 char *buf) \
36933 { \
36934 struct scsi_device *sdev = to_scsi_device(dev); \
36935- unsigned long long count = atomic_read(&sdev->field); \
36936+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
36937 return snprintf(buf, 20, "0x%llx\n", count); \
36938 } \
36939 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
36940diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
36941index 84a1fdf..693b0d6 100644
36942--- a/drivers/scsi/scsi_tgt_lib.c
36943+++ b/drivers/scsi/scsi_tgt_lib.c
36944@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
36945 int err;
36946
36947 dprintk("%lx %u\n", uaddr, len);
36948- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
36949+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
36950 if (err) {
36951 /*
36952 * TODO: need to fixup sg_tablesize, max_segment_size,
36953diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
36954index 80fbe2a..efa223b 100644
36955--- a/drivers/scsi/scsi_transport_fc.c
36956+++ b/drivers/scsi/scsi_transport_fc.c
36957@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
36958 * Netlink Infrastructure
36959 */
36960
36961-static atomic_t fc_event_seq;
36962+static atomic_unchecked_t fc_event_seq;
36963
36964 /**
36965 * fc_get_event_number - Obtain the next sequential FC event number
36966@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
36967 u32
36968 fc_get_event_number(void)
36969 {
36970- return atomic_add_return(1, &fc_event_seq);
36971+ return atomic_add_return_unchecked(1, &fc_event_seq);
36972 }
36973 EXPORT_SYMBOL(fc_get_event_number);
36974
36975@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
36976 {
36977 int error;
36978
36979- atomic_set(&fc_event_seq, 0);
36980+ atomic_set_unchecked(&fc_event_seq, 0);
36981
36982 error = transport_class_register(&fc_host_class);
36983 if (error)
36984@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
36985 char *cp;
36986
36987 *val = simple_strtoul(buf, &cp, 0);
36988- if ((*cp && (*cp != '\n')) || (*val < 0))
36989+ if (*cp && (*cp != '\n'))
36990 return -EINVAL;
36991 /*
36992 * Check for overflow; dev_loss_tmo is u32
36993diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
36994index 1cf640e..78e9014 100644
36995--- a/drivers/scsi/scsi_transport_iscsi.c
36996+++ b/drivers/scsi/scsi_transport_iscsi.c
36997@@ -79,7 +79,7 @@ struct iscsi_internal {
36998 struct transport_container session_cont;
36999 };
37000
37001-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37002+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37003 static struct workqueue_struct *iscsi_eh_timer_workq;
37004
37005 static DEFINE_IDA(iscsi_sess_ida);
37006@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37007 int err;
37008
37009 ihost = shost->shost_data;
37010- session->sid = atomic_add_return(1, &iscsi_session_nr);
37011+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37012
37013 if (target_id == ISCSI_MAX_TARGET) {
37014 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37015@@ -2940,7 +2940,7 @@ static __init int iscsi_transport_init(void)
37016 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37017 ISCSI_TRANSPORT_VERSION);
37018
37019- atomic_set(&iscsi_session_nr, 0);
37020+ atomic_set_unchecked(&iscsi_session_nr, 0);
37021
37022 err = class_register(&iscsi_transport_class);
37023 if (err)
37024diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37025index 21a045e..ec89e03 100644
37026--- a/drivers/scsi/scsi_transport_srp.c
37027+++ b/drivers/scsi/scsi_transport_srp.c
37028@@ -33,7 +33,7 @@
37029 #include "scsi_transport_srp_internal.h"
37030
37031 struct srp_host_attrs {
37032- atomic_t next_port_id;
37033+ atomic_unchecked_t next_port_id;
37034 };
37035 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37036
37037@@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37038 struct Scsi_Host *shost = dev_to_shost(dev);
37039 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37040
37041- atomic_set(&srp_host->next_port_id, 0);
37042+ atomic_set_unchecked(&srp_host->next_port_id, 0);
37043 return 0;
37044 }
37045
37046@@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37047 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37048 rport->roles = ids->roles;
37049
37050- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37051+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37052 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37053
37054 transport_setup_device(&rport->dev);
37055diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37056index eacd46b..e3f4d62 100644
37057--- a/drivers/scsi/sg.c
37058+++ b/drivers/scsi/sg.c
37059@@ -1077,7 +1077,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37060 sdp->disk->disk_name,
37061 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37062 NULL,
37063- (char *)arg);
37064+ (char __user *)arg);
37065 case BLKTRACESTART:
37066 return blk_trace_startstop(sdp->device->request_queue, 1);
37067 case BLKTRACESTOP:
37068@@ -2312,7 +2312,7 @@ struct sg_proc_leaf {
37069 const struct file_operations * fops;
37070 };
37071
37072-static struct sg_proc_leaf sg_proc_leaf_arr[] = {
37073+static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
37074 {"allow_dio", &adio_fops},
37075 {"debug", &debug_fops},
37076 {"def_reserved_size", &dressz_fops},
37077@@ -2332,7 +2332,7 @@ sg_proc_init(void)
37078 if (!sg_proc_sgp)
37079 return 1;
37080 for (k = 0; k < num_leaves; ++k) {
37081- struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
37082+ const struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
37083 umode_t mask = leaf->fops->write ? S_IRUGO | S_IWUSR : S_IRUGO;
37084 proc_create(leaf->name, mask, sg_proc_sgp, leaf->fops);
37085 }
37086diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37087index 3d8f662..070f1a5 100644
37088--- a/drivers/spi/spi.c
37089+++ b/drivers/spi/spi.c
37090@@ -1361,7 +1361,7 @@ int spi_bus_unlock(struct spi_master *master)
37091 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37092
37093 /* portable code must never pass more than 32 bytes */
37094-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37095+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37096
37097 static u8 *buf;
37098
37099diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37100index d91751f..a3a9e36 100644
37101--- a/drivers/staging/octeon/ethernet-rx.c
37102+++ b/drivers/staging/octeon/ethernet-rx.c
37103@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37104 /* Increment RX stats for virtual ports */
37105 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37106 #ifdef CONFIG_64BIT
37107- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37108- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37109+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37110+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37111 #else
37112- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37113- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37114+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37115+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37116 #endif
37117 }
37118 netif_receive_skb(skb);
37119@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37120 dev->name);
37121 */
37122 #ifdef CONFIG_64BIT
37123- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37124+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37125 #else
37126- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37127+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37128 #endif
37129 dev_kfree_skb_irq(skb);
37130 }
37131diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37132index 60cba81..71eb239 100644
37133--- a/drivers/staging/octeon/ethernet.c
37134+++ b/drivers/staging/octeon/ethernet.c
37135@@ -259,11 +259,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37136 * since the RX tasklet also increments it.
37137 */
37138 #ifdef CONFIG_64BIT
37139- atomic64_add(rx_status.dropped_packets,
37140- (atomic64_t *)&priv->stats.rx_dropped);
37141+ atomic64_add_unchecked(rx_status.dropped_packets,
37142+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37143 #else
37144- atomic_add(rx_status.dropped_packets,
37145- (atomic_t *)&priv->stats.rx_dropped);
37146+ atomic_add_unchecked(rx_status.dropped_packets,
37147+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
37148 #endif
37149 }
37150
37151diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37152index d3d8727..f9327bb8 100644
37153--- a/drivers/staging/rtl8712/rtl871x_io.h
37154+++ b/drivers/staging/rtl8712/rtl871x_io.h
37155@@ -108,7 +108,7 @@ struct _io_ops {
37156 u8 *pmem);
37157 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37158 u8 *pmem);
37159-};
37160+} __no_const;
37161
37162 struct io_req {
37163 struct list_head list;
37164diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37165index c7b5e8b..783d6cb 100644
37166--- a/drivers/staging/sbe-2t3e3/netdev.c
37167+++ b/drivers/staging/sbe-2t3e3/netdev.c
37168@@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37169 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37170
37171 if (rlen)
37172- if (copy_to_user(data, &resp, rlen))
37173+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37174 return -EFAULT;
37175
37176 return 0;
37177diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c
37178index 42cdafe..2769103 100644
37179--- a/drivers/staging/speakup/speakup_soft.c
37180+++ b/drivers/staging/speakup/speakup_soft.c
37181@@ -241,11 +241,11 @@ static ssize_t softsynth_read(struct file *fp, char *buf, size_t count,
37182 break;
37183 } else if (!initialized) {
37184 if (*init) {
37185- ch = *init;
37186 init++;
37187 } else {
37188 initialized = 1;
37189 }
37190+ ch = *init;
37191 } else {
37192 ch = synth_buffer_getc();
37193 }
37194diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37195index c7b888c..c94be93 100644
37196--- a/drivers/staging/usbip/usbip_common.h
37197+++ b/drivers/staging/usbip/usbip_common.h
37198@@ -289,7 +289,7 @@ struct usbip_device {
37199 void (*shutdown)(struct usbip_device *);
37200 void (*reset)(struct usbip_device *);
37201 void (*unusable)(struct usbip_device *);
37202- } eh_ops;
37203+ } __no_const eh_ops;
37204 };
37205
37206 /* usbip_common.c */
37207diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37208index 88b3298..3783eee 100644
37209--- a/drivers/staging/usbip/vhci.h
37210+++ b/drivers/staging/usbip/vhci.h
37211@@ -88,7 +88,7 @@ struct vhci_hcd {
37212 unsigned resuming:1;
37213 unsigned long re_timeout;
37214
37215- atomic_t seqnum;
37216+ atomic_unchecked_t seqnum;
37217
37218 /*
37219 * NOTE:
37220diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37221index dca9bf1..80735c9 100644
37222--- a/drivers/staging/usbip/vhci_hcd.c
37223+++ b/drivers/staging/usbip/vhci_hcd.c
37224@@ -488,7 +488,7 @@ static void vhci_tx_urb(struct urb *urb)
37225 return;
37226 }
37227
37228- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37229+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37230 if (priv->seqnum == 0xffff)
37231 dev_info(&urb->dev->dev, "seqnum max\n");
37232
37233@@ -740,7 +740,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37234 return -ENOMEM;
37235 }
37236
37237- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37238+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37239 if (unlink->seqnum == 0xffff)
37240 pr_info("seqnum max\n");
37241
37242@@ -928,7 +928,7 @@ static int vhci_start(struct usb_hcd *hcd)
37243 vdev->rhport = rhport;
37244 }
37245
37246- atomic_set(&vhci->seqnum, 0);
37247+ atomic_set_unchecked(&vhci->seqnum, 0);
37248 spin_lock_init(&vhci->lock);
37249
37250 hcd->power_budget = 0; /* no limit */
37251diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37252index f5fba732..210a16c 100644
37253--- a/drivers/staging/usbip/vhci_rx.c
37254+++ b/drivers/staging/usbip/vhci_rx.c
37255@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37256 if (!urb) {
37257 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37258 pr_info("max seqnum %d\n",
37259- atomic_read(&the_controller->seqnum));
37260+ atomic_read_unchecked(&the_controller->seqnum));
37261 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37262 return;
37263 }
37264diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37265index 7735027..30eed13 100644
37266--- a/drivers/staging/vt6655/hostap.c
37267+++ b/drivers/staging/vt6655/hostap.c
37268@@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
37269 *
37270 */
37271
37272+static net_device_ops_no_const apdev_netdev_ops;
37273+
37274 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37275 {
37276 PSDevice apdev_priv;
37277 struct net_device *dev = pDevice->dev;
37278 int ret;
37279- const struct net_device_ops apdev_netdev_ops = {
37280- .ndo_start_xmit = pDevice->tx_80211,
37281- };
37282
37283 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37284
37285@@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37286 *apdev_priv = *pDevice;
37287 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37288
37289+ /* only half broken now */
37290+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37291 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37292
37293 pDevice->apdev->type = ARPHRD_IEEE80211;
37294diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37295index 51b5adf..098e320 100644
37296--- a/drivers/staging/vt6656/hostap.c
37297+++ b/drivers/staging/vt6656/hostap.c
37298@@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
37299 *
37300 */
37301
37302+static net_device_ops_no_const apdev_netdev_ops;
37303+
37304 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37305 {
37306 PSDevice apdev_priv;
37307 struct net_device *dev = pDevice->dev;
37308 int ret;
37309- const struct net_device_ops apdev_netdev_ops = {
37310- .ndo_start_xmit = pDevice->tx_80211,
37311- };
37312
37313 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37314
37315@@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37316 *apdev_priv = *pDevice;
37317 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37318
37319+ /* only half broken now */
37320+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37321 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37322
37323 pDevice->apdev->type = ARPHRD_IEEE80211;
37324diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37325index 7843dfd..3db105f 100644
37326--- a/drivers/staging/wlan-ng/hfa384x_usb.c
37327+++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37328@@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37329
37330 struct usbctlx_completor {
37331 int (*complete) (struct usbctlx_completor *);
37332-};
37333+} __no_const;
37334
37335 static int
37336 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37337diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37338index 1ca66ea..76f1343 100644
37339--- a/drivers/staging/zcache/tmem.c
37340+++ b/drivers/staging/zcache/tmem.c
37341@@ -39,7 +39,7 @@
37342 * A tmem host implementation must use this function to register callbacks
37343 * for memory allocation.
37344 */
37345-static struct tmem_hostops tmem_hostops;
37346+static tmem_hostops_no_const tmem_hostops;
37347
37348 static void tmem_objnode_tree_init(void);
37349
37350@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37351 * A tmem host implementation must use this function to register
37352 * callbacks for a page-accessible memory (PAM) implementation
37353 */
37354-static struct tmem_pamops tmem_pamops;
37355+static tmem_pamops_no_const tmem_pamops;
37356
37357 void tmem_register_pamops(struct tmem_pamops *m)
37358 {
37359diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37360index 0d4aa82..f7832d4 100644
37361--- a/drivers/staging/zcache/tmem.h
37362+++ b/drivers/staging/zcache/tmem.h
37363@@ -180,6 +180,7 @@ struct tmem_pamops {
37364 void (*new_obj)(struct tmem_obj *);
37365 int (*replace_in_obj)(void *, struct tmem_obj *);
37366 };
37367+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37368 extern void tmem_register_pamops(struct tmem_pamops *m);
37369
37370 /* memory allocation methods provided by the host implementation */
37371@@ -189,6 +190,7 @@ struct tmem_hostops {
37372 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37373 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37374 };
37375+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37376 extern void tmem_register_hostops(struct tmem_hostops *m);
37377
37378 /* core tmem accessor functions */
37379diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
37380index f015839..b15dfc4 100644
37381--- a/drivers/target/target_core_tmr.c
37382+++ b/drivers/target/target_core_tmr.c
37383@@ -327,7 +327,7 @@ static void core_tmr_drain_task_list(
37384 cmd->se_tfo->get_task_tag(cmd), cmd->pr_res_key,
37385 cmd->t_task_list_num,
37386 atomic_read(&cmd->t_task_cdbs_left),
37387- atomic_read(&cmd->t_task_cdbs_sent),
37388+ atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37389 (cmd->transport_state & CMD_T_ACTIVE) != 0,
37390 (cmd->transport_state & CMD_T_STOP) != 0,
37391 (cmd->transport_state & CMD_T_SENT) != 0);
37392diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37393index 443704f..92d3517 100644
37394--- a/drivers/target/target_core_transport.c
37395+++ b/drivers/target/target_core_transport.c
37396@@ -1355,7 +1355,7 @@ struct se_device *transport_add_device_to_core_hba(
37397 spin_lock_init(&dev->se_port_lock);
37398 spin_lock_init(&dev->se_tmr_lock);
37399 spin_lock_init(&dev->qf_cmd_lock);
37400- atomic_set(&dev->dev_ordered_id, 0);
37401+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
37402
37403 se_dev_set_default_attribs(dev, dev_limits);
37404
37405@@ -1542,7 +1542,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37406 * Used to determine when ORDERED commands should go from
37407 * Dormant to Active status.
37408 */
37409- cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37410+ cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37411 smp_mb__after_atomic_inc();
37412 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37413 cmd->se_ordered_id, cmd->sam_task_attr,
37414@@ -1956,7 +1956,7 @@ void transport_generic_request_failure(struct se_cmd *cmd)
37415 " CMD_T_ACTIVE: %d CMD_T_STOP: %d CMD_T_SENT: %d\n",
37416 cmd->t_task_list_num,
37417 atomic_read(&cmd->t_task_cdbs_left),
37418- atomic_read(&cmd->t_task_cdbs_sent),
37419+ atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37420 atomic_read(&cmd->t_task_cdbs_ex_left),
37421 (cmd->transport_state & CMD_T_ACTIVE) != 0,
37422 (cmd->transport_state & CMD_T_STOP) != 0,
37423@@ -2216,9 +2216,9 @@ check_depth:
37424 cmd = task->task_se_cmd;
37425 spin_lock_irqsave(&cmd->t_state_lock, flags);
37426 task->task_flags |= (TF_ACTIVE | TF_SENT);
37427- atomic_inc(&cmd->t_task_cdbs_sent);
37428+ atomic_inc_unchecked(&cmd->t_task_cdbs_sent);
37429
37430- if (atomic_read(&cmd->t_task_cdbs_sent) ==
37431+ if (atomic_read_unchecked(&cmd->t_task_cdbs_sent) ==
37432 cmd->t_task_list_num)
37433 cmd->transport_state |= CMD_T_SENT;
37434
37435diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37436index 3436436..772237b 100644
37437--- a/drivers/tty/hvc/hvcs.c
37438+++ b/drivers/tty/hvc/hvcs.c
37439@@ -83,6 +83,7 @@
37440 #include <asm/hvcserver.h>
37441 #include <asm/uaccess.h>
37442 #include <asm/vio.h>
37443+#include <asm/local.h>
37444
37445 /*
37446 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37447@@ -270,7 +271,7 @@ struct hvcs_struct {
37448 unsigned int index;
37449
37450 struct tty_struct *tty;
37451- int open_count;
37452+ local_t open_count;
37453
37454 /*
37455 * Used to tell the driver kernel_thread what operations need to take
37456@@ -422,7 +423,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37457
37458 spin_lock_irqsave(&hvcsd->lock, flags);
37459
37460- if (hvcsd->open_count > 0) {
37461+ if (local_read(&hvcsd->open_count) > 0) {
37462 spin_unlock_irqrestore(&hvcsd->lock, flags);
37463 printk(KERN_INFO "HVCS: vterm state unchanged. "
37464 "The hvcs device node is still in use.\n");
37465@@ -1138,7 +1139,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37466 if ((retval = hvcs_partner_connect(hvcsd)))
37467 goto error_release;
37468
37469- hvcsd->open_count = 1;
37470+ local_set(&hvcsd->open_count, 1);
37471 hvcsd->tty = tty;
37472 tty->driver_data = hvcsd;
37473
37474@@ -1172,7 +1173,7 @@ fast_open:
37475
37476 spin_lock_irqsave(&hvcsd->lock, flags);
37477 kref_get(&hvcsd->kref);
37478- hvcsd->open_count++;
37479+ local_inc(&hvcsd->open_count);
37480 hvcsd->todo_mask |= HVCS_SCHED_READ;
37481 spin_unlock_irqrestore(&hvcsd->lock, flags);
37482
37483@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37484 hvcsd = tty->driver_data;
37485
37486 spin_lock_irqsave(&hvcsd->lock, flags);
37487- if (--hvcsd->open_count == 0) {
37488+ if (local_dec_and_test(&hvcsd->open_count)) {
37489
37490 vio_disable_interrupts(hvcsd->vdev);
37491
37492@@ -1242,10 +1243,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37493 free_irq(irq, hvcsd);
37494 kref_put(&hvcsd->kref, destroy_hvcs_struct);
37495 return;
37496- } else if (hvcsd->open_count < 0) {
37497+ } else if (local_read(&hvcsd->open_count) < 0) {
37498 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37499 " is missmanaged.\n",
37500- hvcsd->vdev->unit_address, hvcsd->open_count);
37501+ hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
37502 }
37503
37504 spin_unlock_irqrestore(&hvcsd->lock, flags);
37505@@ -1261,7 +1262,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37506
37507 spin_lock_irqsave(&hvcsd->lock, flags);
37508 /* Preserve this so that we know how many kref refs to put */
37509- temp_open_count = hvcsd->open_count;
37510+ temp_open_count = local_read(&hvcsd->open_count);
37511
37512 /*
37513 * Don't kref put inside the spinlock because the destruction
37514@@ -1276,7 +1277,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37515 hvcsd->tty->driver_data = NULL;
37516 hvcsd->tty = NULL;
37517
37518- hvcsd->open_count = 0;
37519+ local_set(&hvcsd->open_count, 0);
37520
37521 /* This will drop any buffered data on the floor which is OK in a hangup
37522 * scenario. */
37523@@ -1347,7 +1348,7 @@ static int hvcs_write(struct tty_struct *tty,
37524 * the middle of a write operation? This is a crummy place to do this
37525 * but we want to keep it all in the spinlock.
37526 */
37527- if (hvcsd->open_count <= 0) {
37528+ if (local_read(&hvcsd->open_count) <= 0) {
37529 spin_unlock_irqrestore(&hvcsd->lock, flags);
37530 return -ENODEV;
37531 }
37532@@ -1421,7 +1422,7 @@ static int hvcs_write_room(struct tty_struct *tty)
37533 {
37534 struct hvcs_struct *hvcsd = tty->driver_data;
37535
37536- if (!hvcsd || hvcsd->open_count <= 0)
37537+ if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
37538 return 0;
37539
37540 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
37541diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
37542index 4daf962..b4a2281 100644
37543--- a/drivers/tty/ipwireless/tty.c
37544+++ b/drivers/tty/ipwireless/tty.c
37545@@ -29,6 +29,7 @@
37546 #include <linux/tty_driver.h>
37547 #include <linux/tty_flip.h>
37548 #include <linux/uaccess.h>
37549+#include <asm/local.h>
37550
37551 #include "tty.h"
37552 #include "network.h"
37553@@ -51,7 +52,7 @@ struct ipw_tty {
37554 int tty_type;
37555 struct ipw_network *network;
37556 struct tty_struct *linux_tty;
37557- int open_count;
37558+ local_t open_count;
37559 unsigned int control_lines;
37560 struct mutex ipw_tty_mutex;
37561 int tx_bytes_queued;
37562@@ -117,10 +118,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37563 mutex_unlock(&tty->ipw_tty_mutex);
37564 return -ENODEV;
37565 }
37566- if (tty->open_count == 0)
37567+ if (local_read(&tty->open_count) == 0)
37568 tty->tx_bytes_queued = 0;
37569
37570- tty->open_count++;
37571+ local_inc(&tty->open_count);
37572
37573 tty->linux_tty = linux_tty;
37574 linux_tty->driver_data = tty;
37575@@ -136,9 +137,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37576
37577 static void do_ipw_close(struct ipw_tty *tty)
37578 {
37579- tty->open_count--;
37580-
37581- if (tty->open_count == 0) {
37582+ if (local_dec_return(&tty->open_count) == 0) {
37583 struct tty_struct *linux_tty = tty->linux_tty;
37584
37585 if (linux_tty != NULL) {
37586@@ -159,7 +158,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
37587 return;
37588
37589 mutex_lock(&tty->ipw_tty_mutex);
37590- if (tty->open_count == 0) {
37591+ if (local_read(&tty->open_count) == 0) {
37592 mutex_unlock(&tty->ipw_tty_mutex);
37593 return;
37594 }
37595@@ -188,7 +187,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
37596 return;
37597 }
37598
37599- if (!tty->open_count) {
37600+ if (!local_read(&tty->open_count)) {
37601 mutex_unlock(&tty->ipw_tty_mutex);
37602 return;
37603 }
37604@@ -230,7 +229,7 @@ static int ipw_write(struct tty_struct *linux_tty,
37605 return -ENODEV;
37606
37607 mutex_lock(&tty->ipw_tty_mutex);
37608- if (!tty->open_count) {
37609+ if (!local_read(&tty->open_count)) {
37610 mutex_unlock(&tty->ipw_tty_mutex);
37611 return -EINVAL;
37612 }
37613@@ -270,7 +269,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
37614 if (!tty)
37615 return -ENODEV;
37616
37617- if (!tty->open_count)
37618+ if (!local_read(&tty->open_count))
37619 return -EINVAL;
37620
37621 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
37622@@ -312,7 +311,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
37623 if (!tty)
37624 return 0;
37625
37626- if (!tty->open_count)
37627+ if (!local_read(&tty->open_count))
37628 return 0;
37629
37630 return tty->tx_bytes_queued;
37631@@ -393,7 +392,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
37632 if (!tty)
37633 return -ENODEV;
37634
37635- if (!tty->open_count)
37636+ if (!local_read(&tty->open_count))
37637 return -EINVAL;
37638
37639 return get_control_lines(tty);
37640@@ -409,7 +408,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
37641 if (!tty)
37642 return -ENODEV;
37643
37644- if (!tty->open_count)
37645+ if (!local_read(&tty->open_count))
37646 return -EINVAL;
37647
37648 return set_control_lines(tty, set, clear);
37649@@ -423,7 +422,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
37650 if (!tty)
37651 return -ENODEV;
37652
37653- if (!tty->open_count)
37654+ if (!local_read(&tty->open_count))
37655 return -EINVAL;
37656
37657 /* FIXME: Exactly how is the tty object locked here .. */
37658@@ -572,7 +571,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
37659 against a parallel ioctl etc */
37660 mutex_lock(&ttyj->ipw_tty_mutex);
37661 }
37662- while (ttyj->open_count)
37663+ while (local_read(&ttyj->open_count))
37664 do_ipw_close(ttyj);
37665 ipwireless_disassociate_network_ttys(network,
37666 ttyj->channel_idx);
37667diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
37668index c43b683..0a88f1c 100644
37669--- a/drivers/tty/n_gsm.c
37670+++ b/drivers/tty/n_gsm.c
37671@@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
37672 kref_init(&dlci->ref);
37673 mutex_init(&dlci->mutex);
37674 dlci->fifo = &dlci->_fifo;
37675- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
37676+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
37677 kfree(dlci);
37678 return NULL;
37679 }
37680diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
37681index 94b6eda..15f7cec 100644
37682--- a/drivers/tty/n_tty.c
37683+++ b/drivers/tty/n_tty.c
37684@@ -2122,6 +2122,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
37685 {
37686 *ops = tty_ldisc_N_TTY;
37687 ops->owner = NULL;
37688- ops->refcount = ops->flags = 0;
37689+ atomic_set(&ops->refcount, 0);
37690+ ops->flags = 0;
37691 }
37692 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
37693diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
37694index eeae7fa..177a743 100644
37695--- a/drivers/tty/pty.c
37696+++ b/drivers/tty/pty.c
37697@@ -707,8 +707,10 @@ static void __init unix98_pty_init(void)
37698 panic("Couldn't register Unix98 pts driver");
37699
37700 /* Now create the /dev/ptmx special device */
37701+ pax_open_kernel();
37702 tty_default_fops(&ptmx_fops);
37703- ptmx_fops.open = ptmx_open;
37704+ *(void **)&ptmx_fops.open = ptmx_open;
37705+ pax_close_kernel();
37706
37707 cdev_init(&ptmx_cdev, &ptmx_fops);
37708 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
37709diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
37710index 2b42a01..32a2ed3 100644
37711--- a/drivers/tty/serial/kgdboc.c
37712+++ b/drivers/tty/serial/kgdboc.c
37713@@ -24,8 +24,9 @@
37714 #define MAX_CONFIG_LEN 40
37715
37716 static struct kgdb_io kgdboc_io_ops;
37717+static struct kgdb_io kgdboc_io_ops_console;
37718
37719-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
37720+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
37721 static int configured = -1;
37722
37723 static char config[MAX_CONFIG_LEN];
37724@@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
37725 kgdboc_unregister_kbd();
37726 if (configured == 1)
37727 kgdb_unregister_io_module(&kgdboc_io_ops);
37728+ else if (configured == 2)
37729+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
37730 }
37731
37732 static int configure_kgdboc(void)
37733@@ -157,13 +160,13 @@ static int configure_kgdboc(void)
37734 int err;
37735 char *cptr = config;
37736 struct console *cons;
37737+ int is_console = 0;
37738
37739 err = kgdboc_option_setup(config);
37740 if (err || !strlen(config) || isspace(config[0]))
37741 goto noconfig;
37742
37743 err = -ENODEV;
37744- kgdboc_io_ops.is_console = 0;
37745 kgdb_tty_driver = NULL;
37746
37747 kgdboc_use_kms = 0;
37748@@ -184,7 +187,7 @@ static int configure_kgdboc(void)
37749 int idx;
37750 if (cons->device && cons->device(cons, &idx) == p &&
37751 idx == tty_line) {
37752- kgdboc_io_ops.is_console = 1;
37753+ is_console = 1;
37754 break;
37755 }
37756 cons = cons->next;
37757@@ -194,12 +197,16 @@ static int configure_kgdboc(void)
37758 kgdb_tty_line = tty_line;
37759
37760 do_register:
37761- err = kgdb_register_io_module(&kgdboc_io_ops);
37762+ if (is_console) {
37763+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
37764+ configured = 2;
37765+ } else {
37766+ err = kgdb_register_io_module(&kgdboc_io_ops);
37767+ configured = 1;
37768+ }
37769 if (err)
37770 goto noconfig;
37771
37772- configured = 1;
37773-
37774 return 0;
37775
37776 noconfig:
37777@@ -213,7 +220,7 @@ noconfig:
37778 static int __init init_kgdboc(void)
37779 {
37780 /* Already configured? */
37781- if (configured == 1)
37782+ if (configured >= 1)
37783 return 0;
37784
37785 return configure_kgdboc();
37786@@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
37787 if (config[len - 1] == '\n')
37788 config[len - 1] = '\0';
37789
37790- if (configured == 1)
37791+ if (configured >= 1)
37792 cleanup_kgdboc();
37793
37794 /* Go and configure with the new params. */
37795@@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
37796 .post_exception = kgdboc_post_exp_handler,
37797 };
37798
37799+static struct kgdb_io kgdboc_io_ops_console = {
37800+ .name = "kgdboc",
37801+ .read_char = kgdboc_get_char,
37802+ .write_char = kgdboc_put_char,
37803+ .pre_exception = kgdboc_pre_exp_handler,
37804+ .post_exception = kgdboc_post_exp_handler,
37805+ .is_console = 1
37806+};
37807+
37808 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
37809 /* This is only available if kgdboc is a built in for early debugging */
37810 static int __init kgdboc_early_init(char *opt)
37811diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
37812index 05728894..b9d44c6 100644
37813--- a/drivers/tty/sysrq.c
37814+++ b/drivers/tty/sysrq.c
37815@@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
37816 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
37817 size_t count, loff_t *ppos)
37818 {
37819- if (count) {
37820+ if (count && capable(CAP_SYS_ADMIN)) {
37821 char c;
37822
37823 if (get_user(c, buf))
37824diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
37825index d939bd7..33d92cd 100644
37826--- a/drivers/tty/tty_io.c
37827+++ b/drivers/tty/tty_io.c
37828@@ -3278,7 +3278,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
37829
37830 void tty_default_fops(struct file_operations *fops)
37831 {
37832- *fops = tty_fops;
37833+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
37834 }
37835
37836 /*
37837diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
37838index 24b95db..9c078d0 100644
37839--- a/drivers/tty/tty_ldisc.c
37840+++ b/drivers/tty/tty_ldisc.c
37841@@ -57,7 +57,7 @@ static void put_ldisc(struct tty_ldisc *ld)
37842 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
37843 struct tty_ldisc_ops *ldo = ld->ops;
37844
37845- ldo->refcount--;
37846+ atomic_dec(&ldo->refcount);
37847 module_put(ldo->owner);
37848 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
37849
37850@@ -92,7 +92,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
37851 spin_lock_irqsave(&tty_ldisc_lock, flags);
37852 tty_ldiscs[disc] = new_ldisc;
37853 new_ldisc->num = disc;
37854- new_ldisc->refcount = 0;
37855+ atomic_set(&new_ldisc->refcount, 0);
37856 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
37857
37858 return ret;
37859@@ -120,7 +120,7 @@ int tty_unregister_ldisc(int disc)
37860 return -EINVAL;
37861
37862 spin_lock_irqsave(&tty_ldisc_lock, flags);
37863- if (tty_ldiscs[disc]->refcount)
37864+ if (atomic_read(&tty_ldiscs[disc]->refcount))
37865 ret = -EBUSY;
37866 else
37867 tty_ldiscs[disc] = NULL;
37868@@ -141,7 +141,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
37869 if (ldops) {
37870 ret = ERR_PTR(-EAGAIN);
37871 if (try_module_get(ldops->owner)) {
37872- ldops->refcount++;
37873+ atomic_inc(&ldops->refcount);
37874 ret = ldops;
37875 }
37876 }
37877@@ -154,7 +154,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
37878 unsigned long flags;
37879
37880 spin_lock_irqsave(&tty_ldisc_lock, flags);
37881- ldops->refcount--;
37882+ atomic_dec(&ldops->refcount);
37883 module_put(ldops->owner);
37884 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
37885 }
37886diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
37887index 3b0c4e3..f98a992 100644
37888--- a/drivers/tty/vt/keyboard.c
37889+++ b/drivers/tty/vt/keyboard.c
37890@@ -663,6 +663,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
37891 kbd->kbdmode == VC_OFF) &&
37892 value != KVAL(K_SAK))
37893 return; /* SAK is allowed even in raw mode */
37894+
37895+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
37896+ {
37897+ void *func = fn_handler[value];
37898+ if (func == fn_show_state || func == fn_show_ptregs ||
37899+ func == fn_show_mem)
37900+ return;
37901+ }
37902+#endif
37903+
37904 fn_handler[value](vc);
37905 }
37906
37907@@ -1812,9 +1822,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
37908 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
37909 return -EFAULT;
37910
37911- if (!capable(CAP_SYS_TTY_CONFIG))
37912- perm = 0;
37913-
37914 switch (cmd) {
37915 case KDGKBENT:
37916 /* Ensure another thread doesn't free it under us */
37917@@ -1829,6 +1836,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
37918 spin_unlock_irqrestore(&kbd_event_lock, flags);
37919 return put_user(val, &user_kbe->kb_value);
37920 case KDSKBENT:
37921+ if (!capable(CAP_SYS_TTY_CONFIG))
37922+ perm = 0;
37923+
37924 if (!perm)
37925 return -EPERM;
37926 if (!i && v == K_NOSUCHMAP) {
37927@@ -1919,9 +1929,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
37928 int i, j, k;
37929 int ret;
37930
37931- if (!capable(CAP_SYS_TTY_CONFIG))
37932- perm = 0;
37933-
37934 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
37935 if (!kbs) {
37936 ret = -ENOMEM;
37937@@ -1955,6 +1962,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
37938 kfree(kbs);
37939 return ((p && *p) ? -EOVERFLOW : 0);
37940 case KDSKBSENT:
37941+ if (!capable(CAP_SYS_TTY_CONFIG))
37942+ perm = 0;
37943+
37944 if (!perm) {
37945 ret = -EPERM;
37946 goto reterr;
37947diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
37948index a783d53..cb30d94 100644
37949--- a/drivers/uio/uio.c
37950+++ b/drivers/uio/uio.c
37951@@ -25,6 +25,7 @@
37952 #include <linux/kobject.h>
37953 #include <linux/cdev.h>
37954 #include <linux/uio_driver.h>
37955+#include <asm/local.h>
37956
37957 #define UIO_MAX_DEVICES (1U << MINORBITS)
37958
37959@@ -32,10 +33,10 @@ struct uio_device {
37960 struct module *owner;
37961 struct device *dev;
37962 int minor;
37963- atomic_t event;
37964+ atomic_unchecked_t event;
37965 struct fasync_struct *async_queue;
37966 wait_queue_head_t wait;
37967- int vma_count;
37968+ local_t vma_count;
37969 struct uio_info *info;
37970 struct kobject *map_dir;
37971 struct kobject *portio_dir;
37972@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
37973 struct device_attribute *attr, char *buf)
37974 {
37975 struct uio_device *idev = dev_get_drvdata(dev);
37976- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
37977+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
37978 }
37979
37980 static struct device_attribute uio_class_attributes[] = {
37981@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
37982 {
37983 struct uio_device *idev = info->uio_dev;
37984
37985- atomic_inc(&idev->event);
37986+ atomic_inc_unchecked(&idev->event);
37987 wake_up_interruptible(&idev->wait);
37988 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
37989 }
37990@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
37991 }
37992
37993 listener->dev = idev;
37994- listener->event_count = atomic_read(&idev->event);
37995+ listener->event_count = atomic_read_unchecked(&idev->event);
37996 filep->private_data = listener;
37997
37998 if (idev->info->open) {
37999@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
38000 return -EIO;
38001
38002 poll_wait(filep, &idev->wait, wait);
38003- if (listener->event_count != atomic_read(&idev->event))
38004+ if (listener->event_count != atomic_read_unchecked(&idev->event))
38005 return POLLIN | POLLRDNORM;
38006 return 0;
38007 }
38008@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
38009 do {
38010 set_current_state(TASK_INTERRUPTIBLE);
38011
38012- event_count = atomic_read(&idev->event);
38013+ event_count = atomic_read_unchecked(&idev->event);
38014 if (event_count != listener->event_count) {
38015 if (copy_to_user(buf, &event_count, count))
38016 retval = -EFAULT;
38017@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
38018 static void uio_vma_open(struct vm_area_struct *vma)
38019 {
38020 struct uio_device *idev = vma->vm_private_data;
38021- idev->vma_count++;
38022+ local_inc(&idev->vma_count);
38023 }
38024
38025 static void uio_vma_close(struct vm_area_struct *vma)
38026 {
38027 struct uio_device *idev = vma->vm_private_data;
38028- idev->vma_count--;
38029+ local_dec(&idev->vma_count);
38030 }
38031
38032 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38033@@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
38034 idev->owner = owner;
38035 idev->info = info;
38036 init_waitqueue_head(&idev->wait);
38037- atomic_set(&idev->event, 0);
38038+ atomic_set_unchecked(&idev->event, 0);
38039
38040 ret = uio_get_minor(idev);
38041 if (ret)
38042diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
38043index 98b89fe..aff824e 100644
38044--- a/drivers/usb/atm/cxacru.c
38045+++ b/drivers/usb/atm/cxacru.c
38046@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
38047 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
38048 if (ret < 2)
38049 return -EINVAL;
38050- if (index < 0 || index > 0x7f)
38051+ if (index > 0x7f)
38052 return -EINVAL;
38053 pos += tmp;
38054
38055diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
38056index d3448ca..d2864ca 100644
38057--- a/drivers/usb/atm/usbatm.c
38058+++ b/drivers/usb/atm/usbatm.c
38059@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38060 if (printk_ratelimit())
38061 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
38062 __func__, vpi, vci);
38063- atomic_inc(&vcc->stats->rx_err);
38064+ atomic_inc_unchecked(&vcc->stats->rx_err);
38065 return;
38066 }
38067
38068@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38069 if (length > ATM_MAX_AAL5_PDU) {
38070 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
38071 __func__, length, vcc);
38072- atomic_inc(&vcc->stats->rx_err);
38073+ atomic_inc_unchecked(&vcc->stats->rx_err);
38074 goto out;
38075 }
38076
38077@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38078 if (sarb->len < pdu_length) {
38079 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
38080 __func__, pdu_length, sarb->len, vcc);
38081- atomic_inc(&vcc->stats->rx_err);
38082+ atomic_inc_unchecked(&vcc->stats->rx_err);
38083 goto out;
38084 }
38085
38086 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
38087 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
38088 __func__, vcc);
38089- atomic_inc(&vcc->stats->rx_err);
38090+ atomic_inc_unchecked(&vcc->stats->rx_err);
38091 goto out;
38092 }
38093
38094@@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38095 if (printk_ratelimit())
38096 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
38097 __func__, length);
38098- atomic_inc(&vcc->stats->rx_drop);
38099+ atomic_inc_unchecked(&vcc->stats->rx_drop);
38100 goto out;
38101 }
38102
38103@@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38104
38105 vcc->push(vcc, skb);
38106
38107- atomic_inc(&vcc->stats->rx);
38108+ atomic_inc_unchecked(&vcc->stats->rx);
38109 out:
38110 skb_trim(sarb, 0);
38111 }
38112@@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
38113 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
38114
38115 usbatm_pop(vcc, skb);
38116- atomic_inc(&vcc->stats->tx);
38117+ atomic_inc_unchecked(&vcc->stats->tx);
38118
38119 skb = skb_dequeue(&instance->sndqueue);
38120 }
38121@@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
38122 if (!left--)
38123 return sprintf(page,
38124 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
38125- atomic_read(&atm_dev->stats.aal5.tx),
38126- atomic_read(&atm_dev->stats.aal5.tx_err),
38127- atomic_read(&atm_dev->stats.aal5.rx),
38128- atomic_read(&atm_dev->stats.aal5.rx_err),
38129- atomic_read(&atm_dev->stats.aal5.rx_drop));
38130+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
38131+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
38132+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
38133+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
38134+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
38135
38136 if (!left--) {
38137 if (instance->disconnected)
38138diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
38139index d956965..4179a77 100644
38140--- a/drivers/usb/core/devices.c
38141+++ b/drivers/usb/core/devices.c
38142@@ -126,7 +126,7 @@ static const char format_endpt[] =
38143 * time it gets called.
38144 */
38145 static struct device_connect_event {
38146- atomic_t count;
38147+ atomic_unchecked_t count;
38148 wait_queue_head_t wait;
38149 } device_event = {
38150 .count = ATOMIC_INIT(1),
38151@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
38152
38153 void usbfs_conn_disc_event(void)
38154 {
38155- atomic_add(2, &device_event.count);
38156+ atomic_add_unchecked(2, &device_event.count);
38157 wake_up(&device_event.wait);
38158 }
38159
38160@@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
38161
38162 poll_wait(file, &device_event.wait, wait);
38163
38164- event_count = atomic_read(&device_event.count);
38165+ event_count = atomic_read_unchecked(&device_event.count);
38166 if (file->f_version != event_count) {
38167 file->f_version = event_count;
38168 return POLLIN | POLLRDNORM;
38169diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
38170index 1fc8f12..20647c1 100644
38171--- a/drivers/usb/early/ehci-dbgp.c
38172+++ b/drivers/usb/early/ehci-dbgp.c
38173@@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
38174
38175 #ifdef CONFIG_KGDB
38176 static struct kgdb_io kgdbdbgp_io_ops;
38177-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
38178+static struct kgdb_io kgdbdbgp_io_ops_console;
38179+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
38180 #else
38181 #define dbgp_kgdb_mode (0)
38182 #endif
38183@@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
38184 .write_char = kgdbdbgp_write_char,
38185 };
38186
38187+static struct kgdb_io kgdbdbgp_io_ops_console = {
38188+ .name = "kgdbdbgp",
38189+ .read_char = kgdbdbgp_read_char,
38190+ .write_char = kgdbdbgp_write_char,
38191+ .is_console = 1
38192+};
38193+
38194 static int kgdbdbgp_wait_time;
38195
38196 static int __init kgdbdbgp_parse_config(char *str)
38197@@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
38198 ptr++;
38199 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
38200 }
38201- kgdb_register_io_module(&kgdbdbgp_io_ops);
38202- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
38203+ if (early_dbgp_console.index != -1)
38204+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
38205+ else
38206+ kgdb_register_io_module(&kgdbdbgp_io_ops);
38207
38208 return 0;
38209 }
38210diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
38211index d6bea3e..60b250e 100644
38212--- a/drivers/usb/wusbcore/wa-hc.h
38213+++ b/drivers/usb/wusbcore/wa-hc.h
38214@@ -192,7 +192,7 @@ struct wahc {
38215 struct list_head xfer_delayed_list;
38216 spinlock_t xfer_list_lock;
38217 struct work_struct xfer_work;
38218- atomic_t xfer_id_count;
38219+ atomic_unchecked_t xfer_id_count;
38220 };
38221
38222
38223@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
38224 INIT_LIST_HEAD(&wa->xfer_delayed_list);
38225 spin_lock_init(&wa->xfer_list_lock);
38226 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
38227- atomic_set(&wa->xfer_id_count, 1);
38228+ atomic_set_unchecked(&wa->xfer_id_count, 1);
38229 }
38230
38231 /**
38232diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
38233index 57c01ab..8a05959 100644
38234--- a/drivers/usb/wusbcore/wa-xfer.c
38235+++ b/drivers/usb/wusbcore/wa-xfer.c
38236@@ -296,7 +296,7 @@ out:
38237 */
38238 static void wa_xfer_id_init(struct wa_xfer *xfer)
38239 {
38240- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
38241+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
38242 }
38243
38244 /*
38245diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
38246index 51e4c1e..9d87e2a 100644
38247--- a/drivers/vhost/vhost.c
38248+++ b/drivers/vhost/vhost.c
38249@@ -632,7 +632,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
38250 return 0;
38251 }
38252
38253-static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
38254+static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
38255 {
38256 struct file *eventfp, *filep = NULL,
38257 *pollstart = NULL, *pollstop = NULL;
38258diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
38259index b0b2ac3..89a4399 100644
38260--- a/drivers/video/aty/aty128fb.c
38261+++ b/drivers/video/aty/aty128fb.c
38262@@ -148,7 +148,7 @@ enum {
38263 };
38264
38265 /* Must match above enum */
38266-static const char *r128_family[] __devinitdata = {
38267+static const char *r128_family[] __devinitconst = {
38268 "AGP",
38269 "PCI",
38270 "PRO AGP",
38271diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
38272index 5c3960d..15cf8fc 100644
38273--- a/drivers/video/fbcmap.c
38274+++ b/drivers/video/fbcmap.c
38275@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
38276 rc = -ENODEV;
38277 goto out;
38278 }
38279- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
38280- !info->fbops->fb_setcmap)) {
38281+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
38282 rc = -EINVAL;
38283 goto out1;
38284 }
38285diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
38286index c6ce416..3b9b642 100644
38287--- a/drivers/video/fbmem.c
38288+++ b/drivers/video/fbmem.c
38289@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38290 image->dx += image->width + 8;
38291 }
38292 } else if (rotate == FB_ROTATE_UD) {
38293- for (x = 0; x < num && image->dx >= 0; x++) {
38294+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
38295 info->fbops->fb_imageblit(info, image);
38296 image->dx -= image->width + 8;
38297 }
38298@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38299 image->dy += image->height + 8;
38300 }
38301 } else if (rotate == FB_ROTATE_CCW) {
38302- for (x = 0; x < num && image->dy >= 0; x++) {
38303+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
38304 info->fbops->fb_imageblit(info, image);
38305 image->dy -= image->height + 8;
38306 }
38307@@ -1157,7 +1157,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
38308 return -EFAULT;
38309 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
38310 return -EINVAL;
38311- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
38312+ if (con2fb.framebuffer >= FB_MAX)
38313 return -EINVAL;
38314 if (!registered_fb[con2fb.framebuffer])
38315 request_module("fb%d", con2fb.framebuffer);
38316diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
38317index 5a5d092..265c5ed 100644
38318--- a/drivers/video/geode/gx1fb_core.c
38319+++ b/drivers/video/geode/gx1fb_core.c
38320@@ -29,7 +29,7 @@ static int crt_option = 1;
38321 static char panel_option[32] = "";
38322
38323 /* Modes relevant to the GX1 (taken from modedb.c) */
38324-static const struct fb_videomode __devinitdata gx1_modedb[] = {
38325+static const struct fb_videomode __devinitconst gx1_modedb[] = {
38326 /* 640x480-60 VESA */
38327 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
38328 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
38329diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
38330index 0fad23f..0e9afa4 100644
38331--- a/drivers/video/gxt4500.c
38332+++ b/drivers/video/gxt4500.c
38333@@ -156,7 +156,7 @@ struct gxt4500_par {
38334 static char *mode_option;
38335
38336 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
38337-static const struct fb_videomode defaultmode __devinitdata = {
38338+static const struct fb_videomode defaultmode __devinitconst = {
38339 .refresh = 60,
38340 .xres = 1280,
38341 .yres = 1024,
38342@@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
38343 return 0;
38344 }
38345
38346-static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
38347+static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
38348 .id = "IBM GXT4500P",
38349 .type = FB_TYPE_PACKED_PIXELS,
38350 .visual = FB_VISUAL_PSEUDOCOLOR,
38351diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
38352index 7672d2e..b56437f 100644
38353--- a/drivers/video/i810/i810_accel.c
38354+++ b/drivers/video/i810/i810_accel.c
38355@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
38356 }
38357 }
38358 printk("ringbuffer lockup!!!\n");
38359+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
38360 i810_report_error(mmio);
38361 par->dev_flags |= LOCKUP;
38362 info->pixmap.scan_align = 1;
38363diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
38364index b83f361..2b05a91 100644
38365--- a/drivers/video/i810/i810_main.c
38366+++ b/drivers/video/i810/i810_main.c
38367@@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
38368 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
38369
38370 /* PCI */
38371-static const char *i810_pci_list[] __devinitdata = {
38372+static const char *i810_pci_list[] __devinitconst = {
38373 "Intel(R) 810 Framebuffer Device" ,
38374 "Intel(R) 810-DC100 Framebuffer Device" ,
38375 "Intel(R) 810E Framebuffer Device" ,
38376diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
38377index de36693..3c63fc2 100644
38378--- a/drivers/video/jz4740_fb.c
38379+++ b/drivers/video/jz4740_fb.c
38380@@ -136,7 +136,7 @@ struct jzfb {
38381 uint32_t pseudo_palette[16];
38382 };
38383
38384-static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
38385+static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
38386 .id = "JZ4740 FB",
38387 .type = FB_TYPE_PACKED_PIXELS,
38388 .visual = FB_VISUAL_TRUECOLOR,
38389diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
38390index 3c14e43..eafa544 100644
38391--- a/drivers/video/logo/logo_linux_clut224.ppm
38392+++ b/drivers/video/logo/logo_linux_clut224.ppm
38393@@ -1,1604 +1,1123 @@
38394 P3
38395-# Standard 224-color Linux logo
38396 80 80
38397 255
38398- 0 0 0 0 0 0 0 0 0 0 0 0
38399- 0 0 0 0 0 0 0 0 0 0 0 0
38400- 0 0 0 0 0 0 0 0 0 0 0 0
38401- 0 0 0 0 0 0 0 0 0 0 0 0
38402- 0 0 0 0 0 0 0 0 0 0 0 0
38403- 0 0 0 0 0 0 0 0 0 0 0 0
38404- 0 0 0 0 0 0 0 0 0 0 0 0
38405- 0 0 0 0 0 0 0 0 0 0 0 0
38406- 0 0 0 0 0 0 0 0 0 0 0 0
38407- 6 6 6 6 6 6 10 10 10 10 10 10
38408- 10 10 10 6 6 6 6 6 6 6 6 6
38409- 0 0 0 0 0 0 0 0 0 0 0 0
38410- 0 0 0 0 0 0 0 0 0 0 0 0
38411- 0 0 0 0 0 0 0 0 0 0 0 0
38412- 0 0 0 0 0 0 0 0 0 0 0 0
38413- 0 0 0 0 0 0 0 0 0 0 0 0
38414- 0 0 0 0 0 0 0 0 0 0 0 0
38415- 0 0 0 0 0 0 0 0 0 0 0 0
38416- 0 0 0 0 0 0 0 0 0 0 0 0
38417- 0 0 0 0 0 0 0 0 0 0 0 0
38418- 0 0 0 0 0 0 0 0 0 0 0 0
38419- 0 0 0 0 0 0 0 0 0 0 0 0
38420- 0 0 0 0 0 0 0 0 0 0 0 0
38421- 0 0 0 0 0 0 0 0 0 0 0 0
38422- 0 0 0 0 0 0 0 0 0 0 0 0
38423- 0 0 0 0 0 0 0 0 0 0 0 0
38424- 0 0 0 0 0 0 0 0 0 0 0 0
38425- 0 0 0 0 0 0 0 0 0 0 0 0
38426- 0 0 0 6 6 6 10 10 10 14 14 14
38427- 22 22 22 26 26 26 30 30 30 34 34 34
38428- 30 30 30 30 30 30 26 26 26 18 18 18
38429- 14 14 14 10 10 10 6 6 6 0 0 0
38430- 0 0 0 0 0 0 0 0 0 0 0 0
38431- 0 0 0 0 0 0 0 0 0 0 0 0
38432- 0 0 0 0 0 0 0 0 0 0 0 0
38433- 0 0 0 0 0 0 0 0 0 0 0 0
38434- 0 0 0 0 0 0 0 0 0 0 0 0
38435- 0 0 0 0 0 0 0 0 0 0 0 0
38436- 0 0 0 0 0 0 0 0 0 0 0 0
38437- 0 0 0 0 0 0 0 0 0 0 0 0
38438- 0 0 0 0 0 0 0 0 0 0 0 0
38439- 0 0 0 0 0 1 0 0 1 0 0 0
38440- 0 0 0 0 0 0 0 0 0 0 0 0
38441- 0 0 0 0 0 0 0 0 0 0 0 0
38442- 0 0 0 0 0 0 0 0 0 0 0 0
38443- 0 0 0 0 0 0 0 0 0 0 0 0
38444- 0 0 0 0 0 0 0 0 0 0 0 0
38445- 0 0 0 0 0 0 0 0 0 0 0 0
38446- 6 6 6 14 14 14 26 26 26 42 42 42
38447- 54 54 54 66 66 66 78 78 78 78 78 78
38448- 78 78 78 74 74 74 66 66 66 54 54 54
38449- 42 42 42 26 26 26 18 18 18 10 10 10
38450- 6 6 6 0 0 0 0 0 0 0 0 0
38451- 0 0 0 0 0 0 0 0 0 0 0 0
38452- 0 0 0 0 0 0 0 0 0 0 0 0
38453- 0 0 0 0 0 0 0 0 0 0 0 0
38454- 0 0 0 0 0 0 0 0 0 0 0 0
38455- 0 0 0 0 0 0 0 0 0 0 0 0
38456- 0 0 0 0 0 0 0 0 0 0 0 0
38457- 0 0 0 0 0 0 0 0 0 0 0 0
38458- 0 0 0 0 0 0 0 0 0 0 0 0
38459- 0 0 1 0 0 0 0 0 0 0 0 0
38460- 0 0 0 0 0 0 0 0 0 0 0 0
38461- 0 0 0 0 0 0 0 0 0 0 0 0
38462- 0 0 0 0 0 0 0 0 0 0 0 0
38463- 0 0 0 0 0 0 0 0 0 0 0 0
38464- 0 0 0 0 0 0 0 0 0 0 0 0
38465- 0 0 0 0 0 0 0 0 0 10 10 10
38466- 22 22 22 42 42 42 66 66 66 86 86 86
38467- 66 66 66 38 38 38 38 38 38 22 22 22
38468- 26 26 26 34 34 34 54 54 54 66 66 66
38469- 86 86 86 70 70 70 46 46 46 26 26 26
38470- 14 14 14 6 6 6 0 0 0 0 0 0
38471- 0 0 0 0 0 0 0 0 0 0 0 0
38472- 0 0 0 0 0 0 0 0 0 0 0 0
38473- 0 0 0 0 0 0 0 0 0 0 0 0
38474- 0 0 0 0 0 0 0 0 0 0 0 0
38475- 0 0 0 0 0 0 0 0 0 0 0 0
38476- 0 0 0 0 0 0 0 0 0 0 0 0
38477- 0 0 0 0 0 0 0 0 0 0 0 0
38478- 0 0 0 0 0 0 0 0 0 0 0 0
38479- 0 0 1 0 0 1 0 0 1 0 0 0
38480- 0 0 0 0 0 0 0 0 0 0 0 0
38481- 0 0 0 0 0 0 0 0 0 0 0 0
38482- 0 0 0 0 0 0 0 0 0 0 0 0
38483- 0 0 0 0 0 0 0 0 0 0 0 0
38484- 0 0 0 0 0 0 0 0 0 0 0 0
38485- 0 0 0 0 0 0 10 10 10 26 26 26
38486- 50 50 50 82 82 82 58 58 58 6 6 6
38487- 2 2 6 2 2 6 2 2 6 2 2 6
38488- 2 2 6 2 2 6 2 2 6 2 2 6
38489- 6 6 6 54 54 54 86 86 86 66 66 66
38490- 38 38 38 18 18 18 6 6 6 0 0 0
38491- 0 0 0 0 0 0 0 0 0 0 0 0
38492- 0 0 0 0 0 0 0 0 0 0 0 0
38493- 0 0 0 0 0 0 0 0 0 0 0 0
38494- 0 0 0 0 0 0 0 0 0 0 0 0
38495- 0 0 0 0 0 0 0 0 0 0 0 0
38496- 0 0 0 0 0 0 0 0 0 0 0 0
38497- 0 0 0 0 0 0 0 0 0 0 0 0
38498- 0 0 0 0 0 0 0 0 0 0 0 0
38499- 0 0 0 0 0 0 0 0 0 0 0 0
38500- 0 0 0 0 0 0 0 0 0 0 0 0
38501- 0 0 0 0 0 0 0 0 0 0 0 0
38502- 0 0 0 0 0 0 0 0 0 0 0 0
38503- 0 0 0 0 0 0 0 0 0 0 0 0
38504- 0 0 0 0 0 0 0 0 0 0 0 0
38505- 0 0 0 6 6 6 22 22 22 50 50 50
38506- 78 78 78 34 34 34 2 2 6 2 2 6
38507- 2 2 6 2 2 6 2 2 6 2 2 6
38508- 2 2 6 2 2 6 2 2 6 2 2 6
38509- 2 2 6 2 2 6 6 6 6 70 70 70
38510- 78 78 78 46 46 46 22 22 22 6 6 6
38511- 0 0 0 0 0 0 0 0 0 0 0 0
38512- 0 0 0 0 0 0 0 0 0 0 0 0
38513- 0 0 0 0 0 0 0 0 0 0 0 0
38514- 0 0 0 0 0 0 0 0 0 0 0 0
38515- 0 0 0 0 0 0 0 0 0 0 0 0
38516- 0 0 0 0 0 0 0 0 0 0 0 0
38517- 0 0 0 0 0 0 0 0 0 0 0 0
38518- 0 0 0 0 0 0 0 0 0 0 0 0
38519- 0 0 1 0 0 1 0 0 1 0 0 0
38520- 0 0 0 0 0 0 0 0 0 0 0 0
38521- 0 0 0 0 0 0 0 0 0 0 0 0
38522- 0 0 0 0 0 0 0 0 0 0 0 0
38523- 0 0 0 0 0 0 0 0 0 0 0 0
38524- 0 0 0 0 0 0 0 0 0 0 0 0
38525- 6 6 6 18 18 18 42 42 42 82 82 82
38526- 26 26 26 2 2 6 2 2 6 2 2 6
38527- 2 2 6 2 2 6 2 2 6 2 2 6
38528- 2 2 6 2 2 6 2 2 6 14 14 14
38529- 46 46 46 34 34 34 6 6 6 2 2 6
38530- 42 42 42 78 78 78 42 42 42 18 18 18
38531- 6 6 6 0 0 0 0 0 0 0 0 0
38532- 0 0 0 0 0 0 0 0 0 0 0 0
38533- 0 0 0 0 0 0 0 0 0 0 0 0
38534- 0 0 0 0 0 0 0 0 0 0 0 0
38535- 0 0 0 0 0 0 0 0 0 0 0 0
38536- 0 0 0 0 0 0 0 0 0 0 0 0
38537- 0 0 0 0 0 0 0 0 0 0 0 0
38538- 0 0 0 0 0 0 0 0 0 0 0 0
38539- 0 0 1 0 0 0 0 0 1 0 0 0
38540- 0 0 0 0 0 0 0 0 0 0 0 0
38541- 0 0 0 0 0 0 0 0 0 0 0 0
38542- 0 0 0 0 0 0 0 0 0 0 0 0
38543- 0 0 0 0 0 0 0 0 0 0 0 0
38544- 0 0 0 0 0 0 0 0 0 0 0 0
38545- 10 10 10 30 30 30 66 66 66 58 58 58
38546- 2 2 6 2 2 6 2 2 6 2 2 6
38547- 2 2 6 2 2 6 2 2 6 2 2 6
38548- 2 2 6 2 2 6 2 2 6 26 26 26
38549- 86 86 86 101 101 101 46 46 46 10 10 10
38550- 2 2 6 58 58 58 70 70 70 34 34 34
38551- 10 10 10 0 0 0 0 0 0 0 0 0
38552- 0 0 0 0 0 0 0 0 0 0 0 0
38553- 0 0 0 0 0 0 0 0 0 0 0 0
38554- 0 0 0 0 0 0 0 0 0 0 0 0
38555- 0 0 0 0 0 0 0 0 0 0 0 0
38556- 0 0 0 0 0 0 0 0 0 0 0 0
38557- 0 0 0 0 0 0 0 0 0 0 0 0
38558- 0 0 0 0 0 0 0 0 0 0 0 0
38559- 0 0 1 0 0 1 0 0 1 0 0 0
38560- 0 0 0 0 0 0 0 0 0 0 0 0
38561- 0 0 0 0 0 0 0 0 0 0 0 0
38562- 0 0 0 0 0 0 0 0 0 0 0 0
38563- 0 0 0 0 0 0 0 0 0 0 0 0
38564- 0 0 0 0 0 0 0 0 0 0 0 0
38565- 14 14 14 42 42 42 86 86 86 10 10 10
38566- 2 2 6 2 2 6 2 2 6 2 2 6
38567- 2 2 6 2 2 6 2 2 6 2 2 6
38568- 2 2 6 2 2 6 2 2 6 30 30 30
38569- 94 94 94 94 94 94 58 58 58 26 26 26
38570- 2 2 6 6 6 6 78 78 78 54 54 54
38571- 22 22 22 6 6 6 0 0 0 0 0 0
38572- 0 0 0 0 0 0 0 0 0 0 0 0
38573- 0 0 0 0 0 0 0 0 0 0 0 0
38574- 0 0 0 0 0 0 0 0 0 0 0 0
38575- 0 0 0 0 0 0 0 0 0 0 0 0
38576- 0 0 0 0 0 0 0 0 0 0 0 0
38577- 0 0 0 0 0 0 0 0 0 0 0 0
38578- 0 0 0 0 0 0 0 0 0 0 0 0
38579- 0 0 0 0 0 0 0 0 0 0 0 0
38580- 0 0 0 0 0 0 0 0 0 0 0 0
38581- 0 0 0 0 0 0 0 0 0 0 0 0
38582- 0 0 0 0 0 0 0 0 0 0 0 0
38583- 0 0 0 0 0 0 0 0 0 0 0 0
38584- 0 0 0 0 0 0 0 0 0 6 6 6
38585- 22 22 22 62 62 62 62 62 62 2 2 6
38586- 2 2 6 2 2 6 2 2 6 2 2 6
38587- 2 2 6 2 2 6 2 2 6 2 2 6
38588- 2 2 6 2 2 6 2 2 6 26 26 26
38589- 54 54 54 38 38 38 18 18 18 10 10 10
38590- 2 2 6 2 2 6 34 34 34 82 82 82
38591- 38 38 38 14 14 14 0 0 0 0 0 0
38592- 0 0 0 0 0 0 0 0 0 0 0 0
38593- 0 0 0 0 0 0 0 0 0 0 0 0
38594- 0 0 0 0 0 0 0 0 0 0 0 0
38595- 0 0 0 0 0 0 0 0 0 0 0 0
38596- 0 0 0 0 0 0 0 0 0 0 0 0
38597- 0 0 0 0 0 0 0 0 0 0 0 0
38598- 0 0 0 0 0 0 0 0 0 0 0 0
38599- 0 0 0 0 0 1 0 0 1 0 0 0
38600- 0 0 0 0 0 0 0 0 0 0 0 0
38601- 0 0 0 0 0 0 0 0 0 0 0 0
38602- 0 0 0 0 0 0 0 0 0 0 0 0
38603- 0 0 0 0 0 0 0 0 0 0 0 0
38604- 0 0 0 0 0 0 0 0 0 6 6 6
38605- 30 30 30 78 78 78 30 30 30 2 2 6
38606- 2 2 6 2 2 6 2 2 6 2 2 6
38607- 2 2 6 2 2 6 2 2 6 2 2 6
38608- 2 2 6 2 2 6 2 2 6 10 10 10
38609- 10 10 10 2 2 6 2 2 6 2 2 6
38610- 2 2 6 2 2 6 2 2 6 78 78 78
38611- 50 50 50 18 18 18 6 6 6 0 0 0
38612- 0 0 0 0 0 0 0 0 0 0 0 0
38613- 0 0 0 0 0 0 0 0 0 0 0 0
38614- 0 0 0 0 0 0 0 0 0 0 0 0
38615- 0 0 0 0 0 0 0 0 0 0 0 0
38616- 0 0 0 0 0 0 0 0 0 0 0 0
38617- 0 0 0 0 0 0 0 0 0 0 0 0
38618- 0 0 0 0 0 0 0 0 0 0 0 0
38619- 0 0 1 0 0 0 0 0 0 0 0 0
38620- 0 0 0 0 0 0 0 0 0 0 0 0
38621- 0 0 0 0 0 0 0 0 0 0 0 0
38622- 0 0 0 0 0 0 0 0 0 0 0 0
38623- 0 0 0 0 0 0 0 0 0 0 0 0
38624- 0 0 0 0 0 0 0 0 0 10 10 10
38625- 38 38 38 86 86 86 14 14 14 2 2 6
38626- 2 2 6 2 2 6 2 2 6 2 2 6
38627- 2 2 6 2 2 6 2 2 6 2 2 6
38628- 2 2 6 2 2 6 2 2 6 2 2 6
38629- 2 2 6 2 2 6 2 2 6 2 2 6
38630- 2 2 6 2 2 6 2 2 6 54 54 54
38631- 66 66 66 26 26 26 6 6 6 0 0 0
38632- 0 0 0 0 0 0 0 0 0 0 0 0
38633- 0 0 0 0 0 0 0 0 0 0 0 0
38634- 0 0 0 0 0 0 0 0 0 0 0 0
38635- 0 0 0 0 0 0 0 0 0 0 0 0
38636- 0 0 0 0 0 0 0 0 0 0 0 0
38637- 0 0 0 0 0 0 0 0 0 0 0 0
38638- 0 0 0 0 0 0 0 0 0 0 0 0
38639- 0 0 0 0 0 1 0 0 1 0 0 0
38640- 0 0 0 0 0 0 0 0 0 0 0 0
38641- 0 0 0 0 0 0 0 0 0 0 0 0
38642- 0 0 0 0 0 0 0 0 0 0 0 0
38643- 0 0 0 0 0 0 0 0 0 0 0 0
38644- 0 0 0 0 0 0 0 0 0 14 14 14
38645- 42 42 42 82 82 82 2 2 6 2 2 6
38646- 2 2 6 6 6 6 10 10 10 2 2 6
38647- 2 2 6 2 2 6 2 2 6 2 2 6
38648- 2 2 6 2 2 6 2 2 6 6 6 6
38649- 14 14 14 10 10 10 2 2 6 2 2 6
38650- 2 2 6 2 2 6 2 2 6 18 18 18
38651- 82 82 82 34 34 34 10 10 10 0 0 0
38652- 0 0 0 0 0 0 0 0 0 0 0 0
38653- 0 0 0 0 0 0 0 0 0 0 0 0
38654- 0 0 0 0 0 0 0 0 0 0 0 0
38655- 0 0 0 0 0 0 0 0 0 0 0 0
38656- 0 0 0 0 0 0 0 0 0 0 0 0
38657- 0 0 0 0 0 0 0 0 0 0 0 0
38658- 0 0 0 0 0 0 0 0 0 0 0 0
38659- 0 0 1 0 0 0 0 0 0 0 0 0
38660- 0 0 0 0 0 0 0 0 0 0 0 0
38661- 0 0 0 0 0 0 0 0 0 0 0 0
38662- 0 0 0 0 0 0 0 0 0 0 0 0
38663- 0 0 0 0 0 0 0 0 0 0 0 0
38664- 0 0 0 0 0 0 0 0 0 14 14 14
38665- 46 46 46 86 86 86 2 2 6 2 2 6
38666- 6 6 6 6 6 6 22 22 22 34 34 34
38667- 6 6 6 2 2 6 2 2 6 2 2 6
38668- 2 2 6 2 2 6 18 18 18 34 34 34
38669- 10 10 10 50 50 50 22 22 22 2 2 6
38670- 2 2 6 2 2 6 2 2 6 10 10 10
38671- 86 86 86 42 42 42 14 14 14 0 0 0
38672- 0 0 0 0 0 0 0 0 0 0 0 0
38673- 0 0 0 0 0 0 0 0 0 0 0 0
38674- 0 0 0 0 0 0 0 0 0 0 0 0
38675- 0 0 0 0 0 0 0 0 0 0 0 0
38676- 0 0 0 0 0 0 0 0 0 0 0 0
38677- 0 0 0 0 0 0 0 0 0 0 0 0
38678- 0 0 0 0 0 0 0 0 0 0 0 0
38679- 0 0 1 0 0 1 0 0 1 0 0 0
38680- 0 0 0 0 0 0 0 0 0 0 0 0
38681- 0 0 0 0 0 0 0 0 0 0 0 0
38682- 0 0 0 0 0 0 0 0 0 0 0 0
38683- 0 0 0 0 0 0 0 0 0 0 0 0
38684- 0 0 0 0 0 0 0 0 0 14 14 14
38685- 46 46 46 86 86 86 2 2 6 2 2 6
38686- 38 38 38 116 116 116 94 94 94 22 22 22
38687- 22 22 22 2 2 6 2 2 6 2 2 6
38688- 14 14 14 86 86 86 138 138 138 162 162 162
38689-154 154 154 38 38 38 26 26 26 6 6 6
38690- 2 2 6 2 2 6 2 2 6 2 2 6
38691- 86 86 86 46 46 46 14 14 14 0 0 0
38692- 0 0 0 0 0 0 0 0 0 0 0 0
38693- 0 0 0 0 0 0 0 0 0 0 0 0
38694- 0 0 0 0 0 0 0 0 0 0 0 0
38695- 0 0 0 0 0 0 0 0 0 0 0 0
38696- 0 0 0 0 0 0 0 0 0 0 0 0
38697- 0 0 0 0 0 0 0 0 0 0 0 0
38698- 0 0 0 0 0 0 0 0 0 0 0 0
38699- 0 0 0 0 0 0 0 0 0 0 0 0
38700- 0 0 0 0 0 0 0 0 0 0 0 0
38701- 0 0 0 0 0 0 0 0 0 0 0 0
38702- 0 0 0 0 0 0 0 0 0 0 0 0
38703- 0 0 0 0 0 0 0 0 0 0 0 0
38704- 0 0 0 0 0 0 0 0 0 14 14 14
38705- 46 46 46 86 86 86 2 2 6 14 14 14
38706-134 134 134 198 198 198 195 195 195 116 116 116
38707- 10 10 10 2 2 6 2 2 6 6 6 6
38708-101 98 89 187 187 187 210 210 210 218 218 218
38709-214 214 214 134 134 134 14 14 14 6 6 6
38710- 2 2 6 2 2 6 2 2 6 2 2 6
38711- 86 86 86 50 50 50 18 18 18 6 6 6
38712- 0 0 0 0 0 0 0 0 0 0 0 0
38713- 0 0 0 0 0 0 0 0 0 0 0 0
38714- 0 0 0 0 0 0 0 0 0 0 0 0
38715- 0 0 0 0 0 0 0 0 0 0 0 0
38716- 0 0 0 0 0 0 0 0 0 0 0 0
38717- 0 0 0 0 0 0 0 0 0 0 0 0
38718- 0 0 0 0 0 0 0 0 1 0 0 0
38719- 0 0 1 0 0 1 0 0 1 0 0 0
38720- 0 0 0 0 0 0 0 0 0 0 0 0
38721- 0 0 0 0 0 0 0 0 0 0 0 0
38722- 0 0 0 0 0 0 0 0 0 0 0 0
38723- 0 0 0 0 0 0 0 0 0 0 0 0
38724- 0 0 0 0 0 0 0 0 0 14 14 14
38725- 46 46 46 86 86 86 2 2 6 54 54 54
38726-218 218 218 195 195 195 226 226 226 246 246 246
38727- 58 58 58 2 2 6 2 2 6 30 30 30
38728-210 210 210 253 253 253 174 174 174 123 123 123
38729-221 221 221 234 234 234 74 74 74 2 2 6
38730- 2 2 6 2 2 6 2 2 6 2 2 6
38731- 70 70 70 58 58 58 22 22 22 6 6 6
38732- 0 0 0 0 0 0 0 0 0 0 0 0
38733- 0 0 0 0 0 0 0 0 0 0 0 0
38734- 0 0 0 0 0 0 0 0 0 0 0 0
38735- 0 0 0 0 0 0 0 0 0 0 0 0
38736- 0 0 0 0 0 0 0 0 0 0 0 0
38737- 0 0 0 0 0 0 0 0 0 0 0 0
38738- 0 0 0 0 0 0 0 0 0 0 0 0
38739- 0 0 0 0 0 0 0 0 0 0 0 0
38740- 0 0 0 0 0 0 0 0 0 0 0 0
38741- 0 0 0 0 0 0 0 0 0 0 0 0
38742- 0 0 0 0 0 0 0 0 0 0 0 0
38743- 0 0 0 0 0 0 0 0 0 0 0 0
38744- 0 0 0 0 0 0 0 0 0 14 14 14
38745- 46 46 46 82 82 82 2 2 6 106 106 106
38746-170 170 170 26 26 26 86 86 86 226 226 226
38747-123 123 123 10 10 10 14 14 14 46 46 46
38748-231 231 231 190 190 190 6 6 6 70 70 70
38749- 90 90 90 238 238 238 158 158 158 2 2 6
38750- 2 2 6 2 2 6 2 2 6 2 2 6
38751- 70 70 70 58 58 58 22 22 22 6 6 6
38752- 0 0 0 0 0 0 0 0 0 0 0 0
38753- 0 0 0 0 0 0 0 0 0 0 0 0
38754- 0 0 0 0 0 0 0 0 0 0 0 0
38755- 0 0 0 0 0 0 0 0 0 0 0 0
38756- 0 0 0 0 0 0 0 0 0 0 0 0
38757- 0 0 0 0 0 0 0 0 0 0 0 0
38758- 0 0 0 0 0 0 0 0 1 0 0 0
38759- 0 0 1 0 0 1 0 0 1 0 0 0
38760- 0 0 0 0 0 0 0 0 0 0 0 0
38761- 0 0 0 0 0 0 0 0 0 0 0 0
38762- 0 0 0 0 0 0 0 0 0 0 0 0
38763- 0 0 0 0 0 0 0 0 0 0 0 0
38764- 0 0 0 0 0 0 0 0 0 14 14 14
38765- 42 42 42 86 86 86 6 6 6 116 116 116
38766-106 106 106 6 6 6 70 70 70 149 149 149
38767-128 128 128 18 18 18 38 38 38 54 54 54
38768-221 221 221 106 106 106 2 2 6 14 14 14
38769- 46 46 46 190 190 190 198 198 198 2 2 6
38770- 2 2 6 2 2 6 2 2 6 2 2 6
38771- 74 74 74 62 62 62 22 22 22 6 6 6
38772- 0 0 0 0 0 0 0 0 0 0 0 0
38773- 0 0 0 0 0 0 0 0 0 0 0 0
38774- 0 0 0 0 0 0 0 0 0 0 0 0
38775- 0 0 0 0 0 0 0 0 0 0 0 0
38776- 0 0 0 0 0 0 0 0 0 0 0 0
38777- 0 0 0 0 0 0 0 0 0 0 0 0
38778- 0 0 0 0 0 0 0 0 1 0 0 0
38779- 0 0 1 0 0 0 0 0 1 0 0 0
38780- 0 0 0 0 0 0 0 0 0 0 0 0
38781- 0 0 0 0 0 0 0 0 0 0 0 0
38782- 0 0 0 0 0 0 0 0 0 0 0 0
38783- 0 0 0 0 0 0 0 0 0 0 0 0
38784- 0 0 0 0 0 0 0 0 0 14 14 14
38785- 42 42 42 94 94 94 14 14 14 101 101 101
38786-128 128 128 2 2 6 18 18 18 116 116 116
38787-118 98 46 121 92 8 121 92 8 98 78 10
38788-162 162 162 106 106 106 2 2 6 2 2 6
38789- 2 2 6 195 195 195 195 195 195 6 6 6
38790- 2 2 6 2 2 6 2 2 6 2 2 6
38791- 74 74 74 62 62 62 22 22 22 6 6 6
38792- 0 0 0 0 0 0 0 0 0 0 0 0
38793- 0 0 0 0 0 0 0 0 0 0 0 0
38794- 0 0 0 0 0 0 0 0 0 0 0 0
38795- 0 0 0 0 0 0 0 0 0 0 0 0
38796- 0 0 0 0 0 0 0 0 0 0 0 0
38797- 0 0 0 0 0 0 0 0 0 0 0 0
38798- 0 0 0 0 0 0 0 0 1 0 0 1
38799- 0 0 1 0 0 0 0 0 1 0 0 0
38800- 0 0 0 0 0 0 0 0 0 0 0 0
38801- 0 0 0 0 0 0 0 0 0 0 0 0
38802- 0 0 0 0 0 0 0 0 0 0 0 0
38803- 0 0 0 0 0 0 0 0 0 0 0 0
38804- 0 0 0 0 0 0 0 0 0 10 10 10
38805- 38 38 38 90 90 90 14 14 14 58 58 58
38806-210 210 210 26 26 26 54 38 6 154 114 10
38807-226 170 11 236 186 11 225 175 15 184 144 12
38808-215 174 15 175 146 61 37 26 9 2 2 6
38809- 70 70 70 246 246 246 138 138 138 2 2 6
38810- 2 2 6 2 2 6 2 2 6 2 2 6
38811- 70 70 70 66 66 66 26 26 26 6 6 6
38812- 0 0 0 0 0 0 0 0 0 0 0 0
38813- 0 0 0 0 0 0 0 0 0 0 0 0
38814- 0 0 0 0 0 0 0 0 0 0 0 0
38815- 0 0 0 0 0 0 0 0 0 0 0 0
38816- 0 0 0 0 0 0 0 0 0 0 0 0
38817- 0 0 0 0 0 0 0 0 0 0 0 0
38818- 0 0 0 0 0 0 0 0 0 0 0 0
38819- 0 0 0 0 0 0 0 0 0 0 0 0
38820- 0 0 0 0 0 0 0 0 0 0 0 0
38821- 0 0 0 0 0 0 0 0 0 0 0 0
38822- 0 0 0 0 0 0 0 0 0 0 0 0
38823- 0 0 0 0 0 0 0 0 0 0 0 0
38824- 0 0 0 0 0 0 0 0 0 10 10 10
38825- 38 38 38 86 86 86 14 14 14 10 10 10
38826-195 195 195 188 164 115 192 133 9 225 175 15
38827-239 182 13 234 190 10 232 195 16 232 200 30
38828-245 207 45 241 208 19 232 195 16 184 144 12
38829-218 194 134 211 206 186 42 42 42 2 2 6
38830- 2 2 6 2 2 6 2 2 6 2 2 6
38831- 50 50 50 74 74 74 30 30 30 6 6 6
38832- 0 0 0 0 0 0 0 0 0 0 0 0
38833- 0 0 0 0 0 0 0 0 0 0 0 0
38834- 0 0 0 0 0 0 0 0 0 0 0 0
38835- 0 0 0 0 0 0 0 0 0 0 0 0
38836- 0 0 0 0 0 0 0 0 0 0 0 0
38837- 0 0 0 0 0 0 0 0 0 0 0 0
38838- 0 0 0 0 0 0 0 0 0 0 0 0
38839- 0 0 0 0 0 0 0 0 0 0 0 0
38840- 0 0 0 0 0 0 0 0 0 0 0 0
38841- 0 0 0 0 0 0 0 0 0 0 0 0
38842- 0 0 0 0 0 0 0 0 0 0 0 0
38843- 0 0 0 0 0 0 0 0 0 0 0 0
38844- 0 0 0 0 0 0 0 0 0 10 10 10
38845- 34 34 34 86 86 86 14 14 14 2 2 6
38846-121 87 25 192 133 9 219 162 10 239 182 13
38847-236 186 11 232 195 16 241 208 19 244 214 54
38848-246 218 60 246 218 38 246 215 20 241 208 19
38849-241 208 19 226 184 13 121 87 25 2 2 6
38850- 2 2 6 2 2 6 2 2 6 2 2 6
38851- 50 50 50 82 82 82 34 34 34 10 10 10
38852- 0 0 0 0 0 0 0 0 0 0 0 0
38853- 0 0 0 0 0 0 0 0 0 0 0 0
38854- 0 0 0 0 0 0 0 0 0 0 0 0
38855- 0 0 0 0 0 0 0 0 0 0 0 0
38856- 0 0 0 0 0 0 0 0 0 0 0 0
38857- 0 0 0 0 0 0 0 0 0 0 0 0
38858- 0 0 0 0 0 0 0 0 0 0 0 0
38859- 0 0 0 0 0 0 0 0 0 0 0 0
38860- 0 0 0 0 0 0 0 0 0 0 0 0
38861- 0 0 0 0 0 0 0 0 0 0 0 0
38862- 0 0 0 0 0 0 0 0 0 0 0 0
38863- 0 0 0 0 0 0 0 0 0 0 0 0
38864- 0 0 0 0 0 0 0 0 0 10 10 10
38865- 34 34 34 82 82 82 30 30 30 61 42 6
38866-180 123 7 206 145 10 230 174 11 239 182 13
38867-234 190 10 238 202 15 241 208 19 246 218 74
38868-246 218 38 246 215 20 246 215 20 246 215 20
38869-226 184 13 215 174 15 184 144 12 6 6 6
38870- 2 2 6 2 2 6 2 2 6 2 2 6
38871- 26 26 26 94 94 94 42 42 42 14 14 14
38872- 0 0 0 0 0 0 0 0 0 0 0 0
38873- 0 0 0 0 0 0 0 0 0 0 0 0
38874- 0 0 0 0 0 0 0 0 0 0 0 0
38875- 0 0 0 0 0 0 0 0 0 0 0 0
38876- 0 0 0 0 0 0 0 0 0 0 0 0
38877- 0 0 0 0 0 0 0 0 0 0 0 0
38878- 0 0 0 0 0 0 0 0 0 0 0 0
38879- 0 0 0 0 0 0 0 0 0 0 0 0
38880- 0 0 0 0 0 0 0 0 0 0 0 0
38881- 0 0 0 0 0 0 0 0 0 0 0 0
38882- 0 0 0 0 0 0 0 0 0 0 0 0
38883- 0 0 0 0 0 0 0 0 0 0 0 0
38884- 0 0 0 0 0 0 0 0 0 10 10 10
38885- 30 30 30 78 78 78 50 50 50 104 69 6
38886-192 133 9 216 158 10 236 178 12 236 186 11
38887-232 195 16 241 208 19 244 214 54 245 215 43
38888-246 215 20 246 215 20 241 208 19 198 155 10
38889-200 144 11 216 158 10 156 118 10 2 2 6
38890- 2 2 6 2 2 6 2 2 6 2 2 6
38891- 6 6 6 90 90 90 54 54 54 18 18 18
38892- 6 6 6 0 0 0 0 0 0 0 0 0
38893- 0 0 0 0 0 0 0 0 0 0 0 0
38894- 0 0 0 0 0 0 0 0 0 0 0 0
38895- 0 0 0 0 0 0 0 0 0 0 0 0
38896- 0 0 0 0 0 0 0 0 0 0 0 0
38897- 0 0 0 0 0 0 0 0 0 0 0 0
38898- 0 0 0 0 0 0 0 0 0 0 0 0
38899- 0 0 0 0 0 0 0 0 0 0 0 0
38900- 0 0 0 0 0 0 0 0 0 0 0 0
38901- 0 0 0 0 0 0 0 0 0 0 0 0
38902- 0 0 0 0 0 0 0 0 0 0 0 0
38903- 0 0 0 0 0 0 0 0 0 0 0 0
38904- 0 0 0 0 0 0 0 0 0 10 10 10
38905- 30 30 30 78 78 78 46 46 46 22 22 22
38906-137 92 6 210 162 10 239 182 13 238 190 10
38907-238 202 15 241 208 19 246 215 20 246 215 20
38908-241 208 19 203 166 17 185 133 11 210 150 10
38909-216 158 10 210 150 10 102 78 10 2 2 6
38910- 6 6 6 54 54 54 14 14 14 2 2 6
38911- 2 2 6 62 62 62 74 74 74 30 30 30
38912- 10 10 10 0 0 0 0 0 0 0 0 0
38913- 0 0 0 0 0 0 0 0 0 0 0 0
38914- 0 0 0 0 0 0 0 0 0 0 0 0
38915- 0 0 0 0 0 0 0 0 0 0 0 0
38916- 0 0 0 0 0 0 0 0 0 0 0 0
38917- 0 0 0 0 0 0 0 0 0 0 0 0
38918- 0 0 0 0 0 0 0 0 0 0 0 0
38919- 0 0 0 0 0 0 0 0 0 0 0 0
38920- 0 0 0 0 0 0 0 0 0 0 0 0
38921- 0 0 0 0 0 0 0 0 0 0 0 0
38922- 0 0 0 0 0 0 0 0 0 0 0 0
38923- 0 0 0 0 0 0 0 0 0 0 0 0
38924- 0 0 0 0 0 0 0 0 0 10 10 10
38925- 34 34 34 78 78 78 50 50 50 6 6 6
38926- 94 70 30 139 102 15 190 146 13 226 184 13
38927-232 200 30 232 195 16 215 174 15 190 146 13
38928-168 122 10 192 133 9 210 150 10 213 154 11
38929-202 150 34 182 157 106 101 98 89 2 2 6
38930- 2 2 6 78 78 78 116 116 116 58 58 58
38931- 2 2 6 22 22 22 90 90 90 46 46 46
38932- 18 18 18 6 6 6 0 0 0 0 0 0
38933- 0 0 0 0 0 0 0 0 0 0 0 0
38934- 0 0 0 0 0 0 0 0 0 0 0 0
38935- 0 0 0 0 0 0 0 0 0 0 0 0
38936- 0 0 0 0 0 0 0 0 0 0 0 0
38937- 0 0 0 0 0 0 0 0 0 0 0 0
38938- 0 0 0 0 0 0 0 0 0 0 0 0
38939- 0 0 0 0 0 0 0 0 0 0 0 0
38940- 0 0 0 0 0 0 0 0 0 0 0 0
38941- 0 0 0 0 0 0 0 0 0 0 0 0
38942- 0 0 0 0 0 0 0 0 0 0 0 0
38943- 0 0 0 0 0 0 0 0 0 0 0 0
38944- 0 0 0 0 0 0 0 0 0 10 10 10
38945- 38 38 38 86 86 86 50 50 50 6 6 6
38946-128 128 128 174 154 114 156 107 11 168 122 10
38947-198 155 10 184 144 12 197 138 11 200 144 11
38948-206 145 10 206 145 10 197 138 11 188 164 115
38949-195 195 195 198 198 198 174 174 174 14 14 14
38950- 2 2 6 22 22 22 116 116 116 116 116 116
38951- 22 22 22 2 2 6 74 74 74 70 70 70
38952- 30 30 30 10 10 10 0 0 0 0 0 0
38953- 0 0 0 0 0 0 0 0 0 0 0 0
38954- 0 0 0 0 0 0 0 0 0 0 0 0
38955- 0 0 0 0 0 0 0 0 0 0 0 0
38956- 0 0 0 0 0 0 0 0 0 0 0 0
38957- 0 0 0 0 0 0 0 0 0 0 0 0
38958- 0 0 0 0 0 0 0 0 0 0 0 0
38959- 0 0 0 0 0 0 0 0 0 0 0 0
38960- 0 0 0 0 0 0 0 0 0 0 0 0
38961- 0 0 0 0 0 0 0 0 0 0 0 0
38962- 0 0 0 0 0 0 0 0 0 0 0 0
38963- 0 0 0 0 0 0 0 0 0 0 0 0
38964- 0 0 0 0 0 0 6 6 6 18 18 18
38965- 50 50 50 101 101 101 26 26 26 10 10 10
38966-138 138 138 190 190 190 174 154 114 156 107 11
38967-197 138 11 200 144 11 197 138 11 192 133 9
38968-180 123 7 190 142 34 190 178 144 187 187 187
38969-202 202 202 221 221 221 214 214 214 66 66 66
38970- 2 2 6 2 2 6 50 50 50 62 62 62
38971- 6 6 6 2 2 6 10 10 10 90 90 90
38972- 50 50 50 18 18 18 6 6 6 0 0 0
38973- 0 0 0 0 0 0 0 0 0 0 0 0
38974- 0 0 0 0 0 0 0 0 0 0 0 0
38975- 0 0 0 0 0 0 0 0 0 0 0 0
38976- 0 0 0 0 0 0 0 0 0 0 0 0
38977- 0 0 0 0 0 0 0 0 0 0 0 0
38978- 0 0 0 0 0 0 0 0 0 0 0 0
38979- 0 0 0 0 0 0 0 0 0 0 0 0
38980- 0 0 0 0 0 0 0 0 0 0 0 0
38981- 0 0 0 0 0 0 0 0 0 0 0 0
38982- 0 0 0 0 0 0 0 0 0 0 0 0
38983- 0 0 0 0 0 0 0 0 0 0 0 0
38984- 0 0 0 0 0 0 10 10 10 34 34 34
38985- 74 74 74 74 74 74 2 2 6 6 6 6
38986-144 144 144 198 198 198 190 190 190 178 166 146
38987-154 121 60 156 107 11 156 107 11 168 124 44
38988-174 154 114 187 187 187 190 190 190 210 210 210
38989-246 246 246 253 253 253 253 253 253 182 182 182
38990- 6 6 6 2 2 6 2 2 6 2 2 6
38991- 2 2 6 2 2 6 2 2 6 62 62 62
38992- 74 74 74 34 34 34 14 14 14 0 0 0
38993- 0 0 0 0 0 0 0 0 0 0 0 0
38994- 0 0 0 0 0 0 0 0 0 0 0 0
38995- 0 0 0 0 0 0 0 0 0 0 0 0
38996- 0 0 0 0 0 0 0 0 0 0 0 0
38997- 0 0 0 0 0 0 0 0 0 0 0 0
38998- 0 0 0 0 0 0 0 0 0 0 0 0
38999- 0 0 0 0 0 0 0 0 0 0 0 0
39000- 0 0 0 0 0 0 0 0 0 0 0 0
39001- 0 0 0 0 0 0 0 0 0 0 0 0
39002- 0 0 0 0 0 0 0 0 0 0 0 0
39003- 0 0 0 0 0 0 0 0 0 0 0 0
39004- 0 0 0 10 10 10 22 22 22 54 54 54
39005- 94 94 94 18 18 18 2 2 6 46 46 46
39006-234 234 234 221 221 221 190 190 190 190 190 190
39007-190 190 190 187 187 187 187 187 187 190 190 190
39008-190 190 190 195 195 195 214 214 214 242 242 242
39009-253 253 253 253 253 253 253 253 253 253 253 253
39010- 82 82 82 2 2 6 2 2 6 2 2 6
39011- 2 2 6 2 2 6 2 2 6 14 14 14
39012- 86 86 86 54 54 54 22 22 22 6 6 6
39013- 0 0 0 0 0 0 0 0 0 0 0 0
39014- 0 0 0 0 0 0 0 0 0 0 0 0
39015- 0 0 0 0 0 0 0 0 0 0 0 0
39016- 0 0 0 0 0 0 0 0 0 0 0 0
39017- 0 0 0 0 0 0 0 0 0 0 0 0
39018- 0 0 0 0 0 0 0 0 0 0 0 0
39019- 0 0 0 0 0 0 0 0 0 0 0 0
39020- 0 0 0 0 0 0 0 0 0 0 0 0
39021- 0 0 0 0 0 0 0 0 0 0 0 0
39022- 0 0 0 0 0 0 0 0 0 0 0 0
39023- 0 0 0 0 0 0 0 0 0 0 0 0
39024- 6 6 6 18 18 18 46 46 46 90 90 90
39025- 46 46 46 18 18 18 6 6 6 182 182 182
39026-253 253 253 246 246 246 206 206 206 190 190 190
39027-190 190 190 190 190 190 190 190 190 190 190 190
39028-206 206 206 231 231 231 250 250 250 253 253 253
39029-253 253 253 253 253 253 253 253 253 253 253 253
39030-202 202 202 14 14 14 2 2 6 2 2 6
39031- 2 2 6 2 2 6 2 2 6 2 2 6
39032- 42 42 42 86 86 86 42 42 42 18 18 18
39033- 6 6 6 0 0 0 0 0 0 0 0 0
39034- 0 0 0 0 0 0 0 0 0 0 0 0
39035- 0 0 0 0 0 0 0 0 0 0 0 0
39036- 0 0 0 0 0 0 0 0 0 0 0 0
39037- 0 0 0 0 0 0 0 0 0 0 0 0
39038- 0 0 0 0 0 0 0 0 0 0 0 0
39039- 0 0 0 0 0 0 0 0 0 0 0 0
39040- 0 0 0 0 0 0 0 0 0 0 0 0
39041- 0 0 0 0 0 0 0 0 0 0 0 0
39042- 0 0 0 0 0 0 0 0 0 0 0 0
39043- 0 0 0 0 0 0 0 0 0 6 6 6
39044- 14 14 14 38 38 38 74 74 74 66 66 66
39045- 2 2 6 6 6 6 90 90 90 250 250 250
39046-253 253 253 253 253 253 238 238 238 198 198 198
39047-190 190 190 190 190 190 195 195 195 221 221 221
39048-246 246 246 253 253 253 253 253 253 253 253 253
39049-253 253 253 253 253 253 253 253 253 253 253 253
39050-253 253 253 82 82 82 2 2 6 2 2 6
39051- 2 2 6 2 2 6 2 2 6 2 2 6
39052- 2 2 6 78 78 78 70 70 70 34 34 34
39053- 14 14 14 6 6 6 0 0 0 0 0 0
39054- 0 0 0 0 0 0 0 0 0 0 0 0
39055- 0 0 0 0 0 0 0 0 0 0 0 0
39056- 0 0 0 0 0 0 0 0 0 0 0 0
39057- 0 0 0 0 0 0 0 0 0 0 0 0
39058- 0 0 0 0 0 0 0 0 0 0 0 0
39059- 0 0 0 0 0 0 0 0 0 0 0 0
39060- 0 0 0 0 0 0 0 0 0 0 0 0
39061- 0 0 0 0 0 0 0 0 0 0 0 0
39062- 0 0 0 0 0 0 0 0 0 0 0 0
39063- 0 0 0 0 0 0 0 0 0 14 14 14
39064- 34 34 34 66 66 66 78 78 78 6 6 6
39065- 2 2 6 18 18 18 218 218 218 253 253 253
39066-253 253 253 253 253 253 253 253 253 246 246 246
39067-226 226 226 231 231 231 246 246 246 253 253 253
39068-253 253 253 253 253 253 253 253 253 253 253 253
39069-253 253 253 253 253 253 253 253 253 253 253 253
39070-253 253 253 178 178 178 2 2 6 2 2 6
39071- 2 2 6 2 2 6 2 2 6 2 2 6
39072- 2 2 6 18 18 18 90 90 90 62 62 62
39073- 30 30 30 10 10 10 0 0 0 0 0 0
39074- 0 0 0 0 0 0 0 0 0 0 0 0
39075- 0 0 0 0 0 0 0 0 0 0 0 0
39076- 0 0 0 0 0 0 0 0 0 0 0 0
39077- 0 0 0 0 0 0 0 0 0 0 0 0
39078- 0 0 0 0 0 0 0 0 0 0 0 0
39079- 0 0 0 0 0 0 0 0 0 0 0 0
39080- 0 0 0 0 0 0 0 0 0 0 0 0
39081- 0 0 0 0 0 0 0 0 0 0 0 0
39082- 0 0 0 0 0 0 0 0 0 0 0 0
39083- 0 0 0 0 0 0 10 10 10 26 26 26
39084- 58 58 58 90 90 90 18 18 18 2 2 6
39085- 2 2 6 110 110 110 253 253 253 253 253 253
39086-253 253 253 253 253 253 253 253 253 253 253 253
39087-250 250 250 253 253 253 253 253 253 253 253 253
39088-253 253 253 253 253 253 253 253 253 253 253 253
39089-253 253 253 253 253 253 253 253 253 253 253 253
39090-253 253 253 231 231 231 18 18 18 2 2 6
39091- 2 2 6 2 2 6 2 2 6 2 2 6
39092- 2 2 6 2 2 6 18 18 18 94 94 94
39093- 54 54 54 26 26 26 10 10 10 0 0 0
39094- 0 0 0 0 0 0 0 0 0 0 0 0
39095- 0 0 0 0 0 0 0 0 0 0 0 0
39096- 0 0 0 0 0 0 0 0 0 0 0 0
39097- 0 0 0 0 0 0 0 0 0 0 0 0
39098- 0 0 0 0 0 0 0 0 0 0 0 0
39099- 0 0 0 0 0 0 0 0 0 0 0 0
39100- 0 0 0 0 0 0 0 0 0 0 0 0
39101- 0 0 0 0 0 0 0 0 0 0 0 0
39102- 0 0 0 0 0 0 0 0 0 0 0 0
39103- 0 0 0 6 6 6 22 22 22 50 50 50
39104- 90 90 90 26 26 26 2 2 6 2 2 6
39105- 14 14 14 195 195 195 250 250 250 253 253 253
39106-253 253 253 253 253 253 253 253 253 253 253 253
39107-253 253 253 253 253 253 253 253 253 253 253 253
39108-253 253 253 253 253 253 253 253 253 253 253 253
39109-253 253 253 253 253 253 253 253 253 253 253 253
39110-250 250 250 242 242 242 54 54 54 2 2 6
39111- 2 2 6 2 2 6 2 2 6 2 2 6
39112- 2 2 6 2 2 6 2 2 6 38 38 38
39113- 86 86 86 50 50 50 22 22 22 6 6 6
39114- 0 0 0 0 0 0 0 0 0 0 0 0
39115- 0 0 0 0 0 0 0 0 0 0 0 0
39116- 0 0 0 0 0 0 0 0 0 0 0 0
39117- 0 0 0 0 0 0 0 0 0 0 0 0
39118- 0 0 0 0 0 0 0 0 0 0 0 0
39119- 0 0 0 0 0 0 0 0 0 0 0 0
39120- 0 0 0 0 0 0 0 0 0 0 0 0
39121- 0 0 0 0 0 0 0 0 0 0 0 0
39122- 0 0 0 0 0 0 0 0 0 0 0 0
39123- 6 6 6 14 14 14 38 38 38 82 82 82
39124- 34 34 34 2 2 6 2 2 6 2 2 6
39125- 42 42 42 195 195 195 246 246 246 253 253 253
39126-253 253 253 253 253 253 253 253 253 250 250 250
39127-242 242 242 242 242 242 250 250 250 253 253 253
39128-253 253 253 253 253 253 253 253 253 253 253 253
39129-253 253 253 250 250 250 246 246 246 238 238 238
39130-226 226 226 231 231 231 101 101 101 6 6 6
39131- 2 2 6 2 2 6 2 2 6 2 2 6
39132- 2 2 6 2 2 6 2 2 6 2 2 6
39133- 38 38 38 82 82 82 42 42 42 14 14 14
39134- 6 6 6 0 0 0 0 0 0 0 0 0
39135- 0 0 0 0 0 0 0 0 0 0 0 0
39136- 0 0 0 0 0 0 0 0 0 0 0 0
39137- 0 0 0 0 0 0 0 0 0 0 0 0
39138- 0 0 0 0 0 0 0 0 0 0 0 0
39139- 0 0 0 0 0 0 0 0 0 0 0 0
39140- 0 0 0 0 0 0 0 0 0 0 0 0
39141- 0 0 0 0 0 0 0 0 0 0 0 0
39142- 0 0 0 0 0 0 0 0 0 0 0 0
39143- 10 10 10 26 26 26 62 62 62 66 66 66
39144- 2 2 6 2 2 6 2 2 6 6 6 6
39145- 70 70 70 170 170 170 206 206 206 234 234 234
39146-246 246 246 250 250 250 250 250 250 238 238 238
39147-226 226 226 231 231 231 238 238 238 250 250 250
39148-250 250 250 250 250 250 246 246 246 231 231 231
39149-214 214 214 206 206 206 202 202 202 202 202 202
39150-198 198 198 202 202 202 182 182 182 18 18 18
39151- 2 2 6 2 2 6 2 2 6 2 2 6
39152- 2 2 6 2 2 6 2 2 6 2 2 6
39153- 2 2 6 62 62 62 66 66 66 30 30 30
39154- 10 10 10 0 0 0 0 0 0 0 0 0
39155- 0 0 0 0 0 0 0 0 0 0 0 0
39156- 0 0 0 0 0 0 0 0 0 0 0 0
39157- 0 0 0 0 0 0 0 0 0 0 0 0
39158- 0 0 0 0 0 0 0 0 0 0 0 0
39159- 0 0 0 0 0 0 0 0 0 0 0 0
39160- 0 0 0 0 0 0 0 0 0 0 0 0
39161- 0 0 0 0 0 0 0 0 0 0 0 0
39162- 0 0 0 0 0 0 0 0 0 0 0 0
39163- 14 14 14 42 42 42 82 82 82 18 18 18
39164- 2 2 6 2 2 6 2 2 6 10 10 10
39165- 94 94 94 182 182 182 218 218 218 242 242 242
39166-250 250 250 253 253 253 253 253 253 250 250 250
39167-234 234 234 253 253 253 253 253 253 253 253 253
39168-253 253 253 253 253 253 253 253 253 246 246 246
39169-238 238 238 226 226 226 210 210 210 202 202 202
39170-195 195 195 195 195 195 210 210 210 158 158 158
39171- 6 6 6 14 14 14 50 50 50 14 14 14
39172- 2 2 6 2 2 6 2 2 6 2 2 6
39173- 2 2 6 6 6 6 86 86 86 46 46 46
39174- 18 18 18 6 6 6 0 0 0 0 0 0
39175- 0 0 0 0 0 0 0 0 0 0 0 0
39176- 0 0 0 0 0 0 0 0 0 0 0 0
39177- 0 0 0 0 0 0 0 0 0 0 0 0
39178- 0 0 0 0 0 0 0 0 0 0 0 0
39179- 0 0 0 0 0 0 0 0 0 0 0 0
39180- 0 0 0 0 0 0 0 0 0 0 0 0
39181- 0 0 0 0 0 0 0 0 0 0 0 0
39182- 0 0 0 0 0 0 0 0 0 6 6 6
39183- 22 22 22 54 54 54 70 70 70 2 2 6
39184- 2 2 6 10 10 10 2 2 6 22 22 22
39185-166 166 166 231 231 231 250 250 250 253 253 253
39186-253 253 253 253 253 253 253 253 253 250 250 250
39187-242 242 242 253 253 253 253 253 253 253 253 253
39188-253 253 253 253 253 253 253 253 253 253 253 253
39189-253 253 253 253 253 253 253 253 253 246 246 246
39190-231 231 231 206 206 206 198 198 198 226 226 226
39191- 94 94 94 2 2 6 6 6 6 38 38 38
39192- 30 30 30 2 2 6 2 2 6 2 2 6
39193- 2 2 6 2 2 6 62 62 62 66 66 66
39194- 26 26 26 10 10 10 0 0 0 0 0 0
39195- 0 0 0 0 0 0 0 0 0 0 0 0
39196- 0 0 0 0 0 0 0 0 0 0 0 0
39197- 0 0 0 0 0 0 0 0 0 0 0 0
39198- 0 0 0 0 0 0 0 0 0 0 0 0
39199- 0 0 0 0 0 0 0 0 0 0 0 0
39200- 0 0 0 0 0 0 0 0 0 0 0 0
39201- 0 0 0 0 0 0 0 0 0 0 0 0
39202- 0 0 0 0 0 0 0 0 0 10 10 10
39203- 30 30 30 74 74 74 50 50 50 2 2 6
39204- 26 26 26 26 26 26 2 2 6 106 106 106
39205-238 238 238 253 253 253 253 253 253 253 253 253
39206-253 253 253 253 253 253 253 253 253 253 253 253
39207-253 253 253 253 253 253 253 253 253 253 253 253
39208-253 253 253 253 253 253 253 253 253 253 253 253
39209-253 253 253 253 253 253 253 253 253 253 253 253
39210-253 253 253 246 246 246 218 218 218 202 202 202
39211-210 210 210 14 14 14 2 2 6 2 2 6
39212- 30 30 30 22 22 22 2 2 6 2 2 6
39213- 2 2 6 2 2 6 18 18 18 86 86 86
39214- 42 42 42 14 14 14 0 0 0 0 0 0
39215- 0 0 0 0 0 0 0 0 0 0 0 0
39216- 0 0 0 0 0 0 0 0 0 0 0 0
39217- 0 0 0 0 0 0 0 0 0 0 0 0
39218- 0 0 0 0 0 0 0 0 0 0 0 0
39219- 0 0 0 0 0 0 0 0 0 0 0 0
39220- 0 0 0 0 0 0 0 0 0 0 0 0
39221- 0 0 0 0 0 0 0 0 0 0 0 0
39222- 0 0 0 0 0 0 0 0 0 14 14 14
39223- 42 42 42 90 90 90 22 22 22 2 2 6
39224- 42 42 42 2 2 6 18 18 18 218 218 218
39225-253 253 253 253 253 253 253 253 253 253 253 253
39226-253 253 253 253 253 253 253 253 253 253 253 253
39227-253 253 253 253 253 253 253 253 253 253 253 253
39228-253 253 253 253 253 253 253 253 253 253 253 253
39229-253 253 253 253 253 253 253 253 253 253 253 253
39230-253 253 253 253 253 253 250 250 250 221 221 221
39231-218 218 218 101 101 101 2 2 6 14 14 14
39232- 18 18 18 38 38 38 10 10 10 2 2 6
39233- 2 2 6 2 2 6 2 2 6 78 78 78
39234- 58 58 58 22 22 22 6 6 6 0 0 0
39235- 0 0 0 0 0 0 0 0 0 0 0 0
39236- 0 0 0 0 0 0 0 0 0 0 0 0
39237- 0 0 0 0 0 0 0 0 0 0 0 0
39238- 0 0 0 0 0 0 0 0 0 0 0 0
39239- 0 0 0 0 0 0 0 0 0 0 0 0
39240- 0 0 0 0 0 0 0 0 0 0 0 0
39241- 0 0 0 0 0 0 0 0 0 0 0 0
39242- 0 0 0 0 0 0 6 6 6 18 18 18
39243- 54 54 54 82 82 82 2 2 6 26 26 26
39244- 22 22 22 2 2 6 123 123 123 253 253 253
39245-253 253 253 253 253 253 253 253 253 253 253 253
39246-253 253 253 253 253 253 253 253 253 253 253 253
39247-253 253 253 253 253 253 253 253 253 253 253 253
39248-253 253 253 253 253 253 253 253 253 253 253 253
39249-253 253 253 253 253 253 253 253 253 253 253 253
39250-253 253 253 253 253 253 253 253 253 250 250 250
39251-238 238 238 198 198 198 6 6 6 38 38 38
39252- 58 58 58 26 26 26 38 38 38 2 2 6
39253- 2 2 6 2 2 6 2 2 6 46 46 46
39254- 78 78 78 30 30 30 10 10 10 0 0 0
39255- 0 0 0 0 0 0 0 0 0 0 0 0
39256- 0 0 0 0 0 0 0 0 0 0 0 0
39257- 0 0 0 0 0 0 0 0 0 0 0 0
39258- 0 0 0 0 0 0 0 0 0 0 0 0
39259- 0 0 0 0 0 0 0 0 0 0 0 0
39260- 0 0 0 0 0 0 0 0 0 0 0 0
39261- 0 0 0 0 0 0 0 0 0 0 0 0
39262- 0 0 0 0 0 0 10 10 10 30 30 30
39263- 74 74 74 58 58 58 2 2 6 42 42 42
39264- 2 2 6 22 22 22 231 231 231 253 253 253
39265-253 253 253 253 253 253 253 253 253 253 253 253
39266-253 253 253 253 253 253 253 253 253 250 250 250
39267-253 253 253 253 253 253 253 253 253 253 253 253
39268-253 253 253 253 253 253 253 253 253 253 253 253
39269-253 253 253 253 253 253 253 253 253 253 253 253
39270-253 253 253 253 253 253 253 253 253 253 253 253
39271-253 253 253 246 246 246 46 46 46 38 38 38
39272- 42 42 42 14 14 14 38 38 38 14 14 14
39273- 2 2 6 2 2 6 2 2 6 6 6 6
39274- 86 86 86 46 46 46 14 14 14 0 0 0
39275- 0 0 0 0 0 0 0 0 0 0 0 0
39276- 0 0 0 0 0 0 0 0 0 0 0 0
39277- 0 0 0 0 0 0 0 0 0 0 0 0
39278- 0 0 0 0 0 0 0 0 0 0 0 0
39279- 0 0 0 0 0 0 0 0 0 0 0 0
39280- 0 0 0 0 0 0 0 0 0 0 0 0
39281- 0 0 0 0 0 0 0 0 0 0 0 0
39282- 0 0 0 6 6 6 14 14 14 42 42 42
39283- 90 90 90 18 18 18 18 18 18 26 26 26
39284- 2 2 6 116 116 116 253 253 253 253 253 253
39285-253 253 253 253 253 253 253 253 253 253 253 253
39286-253 253 253 253 253 253 250 250 250 238 238 238
39287-253 253 253 253 253 253 253 253 253 253 253 253
39288-253 253 253 253 253 253 253 253 253 253 253 253
39289-253 253 253 253 253 253 253 253 253 253 253 253
39290-253 253 253 253 253 253 253 253 253 253 253 253
39291-253 253 253 253 253 253 94 94 94 6 6 6
39292- 2 2 6 2 2 6 10 10 10 34 34 34
39293- 2 2 6 2 2 6 2 2 6 2 2 6
39294- 74 74 74 58 58 58 22 22 22 6 6 6
39295- 0 0 0 0 0 0 0 0 0 0 0 0
39296- 0 0 0 0 0 0 0 0 0 0 0 0
39297- 0 0 0 0 0 0 0 0 0 0 0 0
39298- 0 0 0 0 0 0 0 0 0 0 0 0
39299- 0 0 0 0 0 0 0 0 0 0 0 0
39300- 0 0 0 0 0 0 0 0 0 0 0 0
39301- 0 0 0 0 0 0 0 0 0 0 0 0
39302- 0 0 0 10 10 10 26 26 26 66 66 66
39303- 82 82 82 2 2 6 38 38 38 6 6 6
39304- 14 14 14 210 210 210 253 253 253 253 253 253
39305-253 253 253 253 253 253 253 253 253 253 253 253
39306-253 253 253 253 253 253 246 246 246 242 242 242
39307-253 253 253 253 253 253 253 253 253 253 253 253
39308-253 253 253 253 253 253 253 253 253 253 253 253
39309-253 253 253 253 253 253 253 253 253 253 253 253
39310-253 253 253 253 253 253 253 253 253 253 253 253
39311-253 253 253 253 253 253 144 144 144 2 2 6
39312- 2 2 6 2 2 6 2 2 6 46 46 46
39313- 2 2 6 2 2 6 2 2 6 2 2 6
39314- 42 42 42 74 74 74 30 30 30 10 10 10
39315- 0 0 0 0 0 0 0 0 0 0 0 0
39316- 0 0 0 0 0 0 0 0 0 0 0 0
39317- 0 0 0 0 0 0 0 0 0 0 0 0
39318- 0 0 0 0 0 0 0 0 0 0 0 0
39319- 0 0 0 0 0 0 0 0 0 0 0 0
39320- 0 0 0 0 0 0 0 0 0 0 0 0
39321- 0 0 0 0 0 0 0 0 0 0 0 0
39322- 6 6 6 14 14 14 42 42 42 90 90 90
39323- 26 26 26 6 6 6 42 42 42 2 2 6
39324- 74 74 74 250 250 250 253 253 253 253 253 253
39325-253 253 253 253 253 253 253 253 253 253 253 253
39326-253 253 253 253 253 253 242 242 242 242 242 242
39327-253 253 253 253 253 253 253 253 253 253 253 253
39328-253 253 253 253 253 253 253 253 253 253 253 253
39329-253 253 253 253 253 253 253 253 253 253 253 253
39330-253 253 253 253 253 253 253 253 253 253 253 253
39331-253 253 253 253 253 253 182 182 182 2 2 6
39332- 2 2 6 2 2 6 2 2 6 46 46 46
39333- 2 2 6 2 2 6 2 2 6 2 2 6
39334- 10 10 10 86 86 86 38 38 38 10 10 10
39335- 0 0 0 0 0 0 0 0 0 0 0 0
39336- 0 0 0 0 0 0 0 0 0 0 0 0
39337- 0 0 0 0 0 0 0 0 0 0 0 0
39338- 0 0 0 0 0 0 0 0 0 0 0 0
39339- 0 0 0 0 0 0 0 0 0 0 0 0
39340- 0 0 0 0 0 0 0 0 0 0 0 0
39341- 0 0 0 0 0 0 0 0 0 0 0 0
39342- 10 10 10 26 26 26 66 66 66 82 82 82
39343- 2 2 6 22 22 22 18 18 18 2 2 6
39344-149 149 149 253 253 253 253 253 253 253 253 253
39345-253 253 253 253 253 253 253 253 253 253 253 253
39346-253 253 253 253 253 253 234 234 234 242 242 242
39347-253 253 253 253 253 253 253 253 253 253 253 253
39348-253 253 253 253 253 253 253 253 253 253 253 253
39349-253 253 253 253 253 253 253 253 253 253 253 253
39350-253 253 253 253 253 253 253 253 253 253 253 253
39351-253 253 253 253 253 253 206 206 206 2 2 6
39352- 2 2 6 2 2 6 2 2 6 38 38 38
39353- 2 2 6 2 2 6 2 2 6 2 2 6
39354- 6 6 6 86 86 86 46 46 46 14 14 14
39355- 0 0 0 0 0 0 0 0 0 0 0 0
39356- 0 0 0 0 0 0 0 0 0 0 0 0
39357- 0 0 0 0 0 0 0 0 0 0 0 0
39358- 0 0 0 0 0 0 0 0 0 0 0 0
39359- 0 0 0 0 0 0 0 0 0 0 0 0
39360- 0 0 0 0 0 0 0 0 0 0 0 0
39361- 0 0 0 0 0 0 0 0 0 6 6 6
39362- 18 18 18 46 46 46 86 86 86 18 18 18
39363- 2 2 6 34 34 34 10 10 10 6 6 6
39364-210 210 210 253 253 253 253 253 253 253 253 253
39365-253 253 253 253 253 253 253 253 253 253 253 253
39366-253 253 253 253 253 253 234 234 234 242 242 242
39367-253 253 253 253 253 253 253 253 253 253 253 253
39368-253 253 253 253 253 253 253 253 253 253 253 253
39369-253 253 253 253 253 253 253 253 253 253 253 253
39370-253 253 253 253 253 253 253 253 253 253 253 253
39371-253 253 253 253 253 253 221 221 221 6 6 6
39372- 2 2 6 2 2 6 6 6 6 30 30 30
39373- 2 2 6 2 2 6 2 2 6 2 2 6
39374- 2 2 6 82 82 82 54 54 54 18 18 18
39375- 6 6 6 0 0 0 0 0 0 0 0 0
39376- 0 0 0 0 0 0 0 0 0 0 0 0
39377- 0 0 0 0 0 0 0 0 0 0 0 0
39378- 0 0 0 0 0 0 0 0 0 0 0 0
39379- 0 0 0 0 0 0 0 0 0 0 0 0
39380- 0 0 0 0 0 0 0 0 0 0 0 0
39381- 0 0 0 0 0 0 0 0 0 10 10 10
39382- 26 26 26 66 66 66 62 62 62 2 2 6
39383- 2 2 6 38 38 38 10 10 10 26 26 26
39384-238 238 238 253 253 253 253 253 253 253 253 253
39385-253 253 253 253 253 253 253 253 253 253 253 253
39386-253 253 253 253 253 253 231 231 231 238 238 238
39387-253 253 253 253 253 253 253 253 253 253 253 253
39388-253 253 253 253 253 253 253 253 253 253 253 253
39389-253 253 253 253 253 253 253 253 253 253 253 253
39390-253 253 253 253 253 253 253 253 253 253 253 253
39391-253 253 253 253 253 253 231 231 231 6 6 6
39392- 2 2 6 2 2 6 10 10 10 30 30 30
39393- 2 2 6 2 2 6 2 2 6 2 2 6
39394- 2 2 6 66 66 66 58 58 58 22 22 22
39395- 6 6 6 0 0 0 0 0 0 0 0 0
39396- 0 0 0 0 0 0 0 0 0 0 0 0
39397- 0 0 0 0 0 0 0 0 0 0 0 0
39398- 0 0 0 0 0 0 0 0 0 0 0 0
39399- 0 0 0 0 0 0 0 0 0 0 0 0
39400- 0 0 0 0 0 0 0 0 0 0 0 0
39401- 0 0 0 0 0 0 0 0 0 10 10 10
39402- 38 38 38 78 78 78 6 6 6 2 2 6
39403- 2 2 6 46 46 46 14 14 14 42 42 42
39404-246 246 246 253 253 253 253 253 253 253 253 253
39405-253 253 253 253 253 253 253 253 253 253 253 253
39406-253 253 253 253 253 253 231 231 231 242 242 242
39407-253 253 253 253 253 253 253 253 253 253 253 253
39408-253 253 253 253 253 253 253 253 253 253 253 253
39409-253 253 253 253 253 253 253 253 253 253 253 253
39410-253 253 253 253 253 253 253 253 253 253 253 253
39411-253 253 253 253 253 253 234 234 234 10 10 10
39412- 2 2 6 2 2 6 22 22 22 14 14 14
39413- 2 2 6 2 2 6 2 2 6 2 2 6
39414- 2 2 6 66 66 66 62 62 62 22 22 22
39415- 6 6 6 0 0 0 0 0 0 0 0 0
39416- 0 0 0 0 0 0 0 0 0 0 0 0
39417- 0 0 0 0 0 0 0 0 0 0 0 0
39418- 0 0 0 0 0 0 0 0 0 0 0 0
39419- 0 0 0 0 0 0 0 0 0 0 0 0
39420- 0 0 0 0 0 0 0 0 0 0 0 0
39421- 0 0 0 0 0 0 6 6 6 18 18 18
39422- 50 50 50 74 74 74 2 2 6 2 2 6
39423- 14 14 14 70 70 70 34 34 34 62 62 62
39424-250 250 250 253 253 253 253 253 253 253 253 253
39425-253 253 253 253 253 253 253 253 253 253 253 253
39426-253 253 253 253 253 253 231 231 231 246 246 246
39427-253 253 253 253 253 253 253 253 253 253 253 253
39428-253 253 253 253 253 253 253 253 253 253 253 253
39429-253 253 253 253 253 253 253 253 253 253 253 253
39430-253 253 253 253 253 253 253 253 253 253 253 253
39431-253 253 253 253 253 253 234 234 234 14 14 14
39432- 2 2 6 2 2 6 30 30 30 2 2 6
39433- 2 2 6 2 2 6 2 2 6 2 2 6
39434- 2 2 6 66 66 66 62 62 62 22 22 22
39435- 6 6 6 0 0 0 0 0 0 0 0 0
39436- 0 0 0 0 0 0 0 0 0 0 0 0
39437- 0 0 0 0 0 0 0 0 0 0 0 0
39438- 0 0 0 0 0 0 0 0 0 0 0 0
39439- 0 0 0 0 0 0 0 0 0 0 0 0
39440- 0 0 0 0 0 0 0 0 0 0 0 0
39441- 0 0 0 0 0 0 6 6 6 18 18 18
39442- 54 54 54 62 62 62 2 2 6 2 2 6
39443- 2 2 6 30 30 30 46 46 46 70 70 70
39444-250 250 250 253 253 253 253 253 253 253 253 253
39445-253 253 253 253 253 253 253 253 253 253 253 253
39446-253 253 253 253 253 253 231 231 231 246 246 246
39447-253 253 253 253 253 253 253 253 253 253 253 253
39448-253 253 253 253 253 253 253 253 253 253 253 253
39449-253 253 253 253 253 253 253 253 253 253 253 253
39450-253 253 253 253 253 253 253 253 253 253 253 253
39451-253 253 253 253 253 253 226 226 226 10 10 10
39452- 2 2 6 6 6 6 30 30 30 2 2 6
39453- 2 2 6 2 2 6 2 2 6 2 2 6
39454- 2 2 6 66 66 66 58 58 58 22 22 22
39455- 6 6 6 0 0 0 0 0 0 0 0 0
39456- 0 0 0 0 0 0 0 0 0 0 0 0
39457- 0 0 0 0 0 0 0 0 0 0 0 0
39458- 0 0 0 0 0 0 0 0 0 0 0 0
39459- 0 0 0 0 0 0 0 0 0 0 0 0
39460- 0 0 0 0 0 0 0 0 0 0 0 0
39461- 0 0 0 0 0 0 6 6 6 22 22 22
39462- 58 58 58 62 62 62 2 2 6 2 2 6
39463- 2 2 6 2 2 6 30 30 30 78 78 78
39464-250 250 250 253 253 253 253 253 253 253 253 253
39465-253 253 253 253 253 253 253 253 253 253 253 253
39466-253 253 253 253 253 253 231 231 231 246 246 246
39467-253 253 253 253 253 253 253 253 253 253 253 253
39468-253 253 253 253 253 253 253 253 253 253 253 253
39469-253 253 253 253 253 253 253 253 253 253 253 253
39470-253 253 253 253 253 253 253 253 253 253 253 253
39471-253 253 253 253 253 253 206 206 206 2 2 6
39472- 22 22 22 34 34 34 18 14 6 22 22 22
39473- 26 26 26 18 18 18 6 6 6 2 2 6
39474- 2 2 6 82 82 82 54 54 54 18 18 18
39475- 6 6 6 0 0 0 0 0 0 0 0 0
39476- 0 0 0 0 0 0 0 0 0 0 0 0
39477- 0 0 0 0 0 0 0 0 0 0 0 0
39478- 0 0 0 0 0 0 0 0 0 0 0 0
39479- 0 0 0 0 0 0 0 0 0 0 0 0
39480- 0 0 0 0 0 0 0 0 0 0 0 0
39481- 0 0 0 0 0 0 6 6 6 26 26 26
39482- 62 62 62 106 106 106 74 54 14 185 133 11
39483-210 162 10 121 92 8 6 6 6 62 62 62
39484-238 238 238 253 253 253 253 253 253 253 253 253
39485-253 253 253 253 253 253 253 253 253 253 253 253
39486-253 253 253 253 253 253 231 231 231 246 246 246
39487-253 253 253 253 253 253 253 253 253 253 253 253
39488-253 253 253 253 253 253 253 253 253 253 253 253
39489-253 253 253 253 253 253 253 253 253 253 253 253
39490-253 253 253 253 253 253 253 253 253 253 253 253
39491-253 253 253 253 253 253 158 158 158 18 18 18
39492- 14 14 14 2 2 6 2 2 6 2 2 6
39493- 6 6 6 18 18 18 66 66 66 38 38 38
39494- 6 6 6 94 94 94 50 50 50 18 18 18
39495- 6 6 6 0 0 0 0 0 0 0 0 0
39496- 0 0 0 0 0 0 0 0 0 0 0 0
39497- 0 0 0 0 0 0 0 0 0 0 0 0
39498- 0 0 0 0 0 0 0 0 0 0 0 0
39499- 0 0 0 0 0 0 0 0 0 0 0 0
39500- 0 0 0 0 0 0 0 0 0 6 6 6
39501- 10 10 10 10 10 10 18 18 18 38 38 38
39502- 78 78 78 142 134 106 216 158 10 242 186 14
39503-246 190 14 246 190 14 156 118 10 10 10 10
39504- 90 90 90 238 238 238 253 253 253 253 253 253
39505-253 253 253 253 253 253 253 253 253 253 253 253
39506-253 253 253 253 253 253 231 231 231 250 250 250
39507-253 253 253 253 253 253 253 253 253 253 253 253
39508-253 253 253 253 253 253 253 253 253 253 253 253
39509-253 253 253 253 253 253 253 253 253 253 253 253
39510-253 253 253 253 253 253 253 253 253 246 230 190
39511-238 204 91 238 204 91 181 142 44 37 26 9
39512- 2 2 6 2 2 6 2 2 6 2 2 6
39513- 2 2 6 2 2 6 38 38 38 46 46 46
39514- 26 26 26 106 106 106 54 54 54 18 18 18
39515- 6 6 6 0 0 0 0 0 0 0 0 0
39516- 0 0 0 0 0 0 0 0 0 0 0 0
39517- 0 0 0 0 0 0 0 0 0 0 0 0
39518- 0 0 0 0 0 0 0 0 0 0 0 0
39519- 0 0 0 0 0 0 0 0 0 0 0 0
39520- 0 0 0 6 6 6 14 14 14 22 22 22
39521- 30 30 30 38 38 38 50 50 50 70 70 70
39522-106 106 106 190 142 34 226 170 11 242 186 14
39523-246 190 14 246 190 14 246 190 14 154 114 10
39524- 6 6 6 74 74 74 226 226 226 253 253 253
39525-253 253 253 253 253 253 253 253 253 253 253 253
39526-253 253 253 253 253 253 231 231 231 250 250 250
39527-253 253 253 253 253 253 253 253 253 253 253 253
39528-253 253 253 253 253 253 253 253 253 253 253 253
39529-253 253 253 253 253 253 253 253 253 253 253 253
39530-253 253 253 253 253 253 253 253 253 228 184 62
39531-241 196 14 241 208 19 232 195 16 38 30 10
39532- 2 2 6 2 2 6 2 2 6 2 2 6
39533- 2 2 6 6 6 6 30 30 30 26 26 26
39534-203 166 17 154 142 90 66 66 66 26 26 26
39535- 6 6 6 0 0 0 0 0 0 0 0 0
39536- 0 0 0 0 0 0 0 0 0 0 0 0
39537- 0 0 0 0 0 0 0 0 0 0 0 0
39538- 0 0 0 0 0 0 0 0 0 0 0 0
39539- 0 0 0 0 0 0 0 0 0 0 0 0
39540- 6 6 6 18 18 18 38 38 38 58 58 58
39541- 78 78 78 86 86 86 101 101 101 123 123 123
39542-175 146 61 210 150 10 234 174 13 246 186 14
39543-246 190 14 246 190 14 246 190 14 238 190 10
39544-102 78 10 2 2 6 46 46 46 198 198 198
39545-253 253 253 253 253 253 253 253 253 253 253 253
39546-253 253 253 253 253 253 234 234 234 242 242 242
39547-253 253 253 253 253 253 253 253 253 253 253 253
39548-253 253 253 253 253 253 253 253 253 253 253 253
39549-253 253 253 253 253 253 253 253 253 253 253 253
39550-253 253 253 253 253 253 253 253 253 224 178 62
39551-242 186 14 241 196 14 210 166 10 22 18 6
39552- 2 2 6 2 2 6 2 2 6 2 2 6
39553- 2 2 6 2 2 6 6 6 6 121 92 8
39554-238 202 15 232 195 16 82 82 82 34 34 34
39555- 10 10 10 0 0 0 0 0 0 0 0 0
39556- 0 0 0 0 0 0 0 0 0 0 0 0
39557- 0 0 0 0 0 0 0 0 0 0 0 0
39558- 0 0 0 0 0 0 0 0 0 0 0 0
39559- 0 0 0 0 0 0 0 0 0 0 0 0
39560- 14 14 14 38 38 38 70 70 70 154 122 46
39561-190 142 34 200 144 11 197 138 11 197 138 11
39562-213 154 11 226 170 11 242 186 14 246 190 14
39563-246 190 14 246 190 14 246 190 14 246 190 14
39564-225 175 15 46 32 6 2 2 6 22 22 22
39565-158 158 158 250 250 250 253 253 253 253 253 253
39566-253 253 253 253 253 253 253 253 253 253 253 253
39567-253 253 253 253 253 253 253 253 253 253 253 253
39568-253 253 253 253 253 253 253 253 253 253 253 253
39569-253 253 253 253 253 253 253 253 253 253 253 253
39570-253 253 253 250 250 250 242 242 242 224 178 62
39571-239 182 13 236 186 11 213 154 11 46 32 6
39572- 2 2 6 2 2 6 2 2 6 2 2 6
39573- 2 2 6 2 2 6 61 42 6 225 175 15
39574-238 190 10 236 186 11 112 100 78 42 42 42
39575- 14 14 14 0 0 0 0 0 0 0 0 0
39576- 0 0 0 0 0 0 0 0 0 0 0 0
39577- 0 0 0 0 0 0 0 0 0 0 0 0
39578- 0 0 0 0 0 0 0 0 0 0 0 0
39579- 0 0 0 0 0 0 0 0 0 6 6 6
39580- 22 22 22 54 54 54 154 122 46 213 154 11
39581-226 170 11 230 174 11 226 170 11 226 170 11
39582-236 178 12 242 186 14 246 190 14 246 190 14
39583-246 190 14 246 190 14 246 190 14 246 190 14
39584-241 196 14 184 144 12 10 10 10 2 2 6
39585- 6 6 6 116 116 116 242 242 242 253 253 253
39586-253 253 253 253 253 253 253 253 253 253 253 253
39587-253 253 253 253 253 253 253 253 253 253 253 253
39588-253 253 253 253 253 253 253 253 253 253 253 253
39589-253 253 253 253 253 253 253 253 253 253 253 253
39590-253 253 253 231 231 231 198 198 198 214 170 54
39591-236 178 12 236 178 12 210 150 10 137 92 6
39592- 18 14 6 2 2 6 2 2 6 2 2 6
39593- 6 6 6 70 47 6 200 144 11 236 178 12
39594-239 182 13 239 182 13 124 112 88 58 58 58
39595- 22 22 22 6 6 6 0 0 0 0 0 0
39596- 0 0 0 0 0 0 0 0 0 0 0 0
39597- 0 0 0 0 0 0 0 0 0 0 0 0
39598- 0 0 0 0 0 0 0 0 0 0 0 0
39599- 0 0 0 0 0 0 0 0 0 10 10 10
39600- 30 30 30 70 70 70 180 133 36 226 170 11
39601-239 182 13 242 186 14 242 186 14 246 186 14
39602-246 190 14 246 190 14 246 190 14 246 190 14
39603-246 190 14 246 190 14 246 190 14 246 190 14
39604-246 190 14 232 195 16 98 70 6 2 2 6
39605- 2 2 6 2 2 6 66 66 66 221 221 221
39606-253 253 253 253 253 253 253 253 253 253 253 253
39607-253 253 253 253 253 253 253 253 253 253 253 253
39608-253 253 253 253 253 253 253 253 253 253 253 253
39609-253 253 253 253 253 253 253 253 253 253 253 253
39610-253 253 253 206 206 206 198 198 198 214 166 58
39611-230 174 11 230 174 11 216 158 10 192 133 9
39612-163 110 8 116 81 8 102 78 10 116 81 8
39613-167 114 7 197 138 11 226 170 11 239 182 13
39614-242 186 14 242 186 14 162 146 94 78 78 78
39615- 34 34 34 14 14 14 6 6 6 0 0 0
39616- 0 0 0 0 0 0 0 0 0 0 0 0
39617- 0 0 0 0 0 0 0 0 0 0 0 0
39618- 0 0 0 0 0 0 0 0 0 0 0 0
39619- 0 0 0 0 0 0 0 0 0 6 6 6
39620- 30 30 30 78 78 78 190 142 34 226 170 11
39621-239 182 13 246 190 14 246 190 14 246 190 14
39622-246 190 14 246 190 14 246 190 14 246 190 14
39623-246 190 14 246 190 14 246 190 14 246 190 14
39624-246 190 14 241 196 14 203 166 17 22 18 6
39625- 2 2 6 2 2 6 2 2 6 38 38 38
39626-218 218 218 253 253 253 253 253 253 253 253 253
39627-253 253 253 253 253 253 253 253 253 253 253 253
39628-253 253 253 253 253 253 253 253 253 253 253 253
39629-253 253 253 253 253 253 253 253 253 253 253 253
39630-250 250 250 206 206 206 198 198 198 202 162 69
39631-226 170 11 236 178 12 224 166 10 210 150 10
39632-200 144 11 197 138 11 192 133 9 197 138 11
39633-210 150 10 226 170 11 242 186 14 246 190 14
39634-246 190 14 246 186 14 225 175 15 124 112 88
39635- 62 62 62 30 30 30 14 14 14 6 6 6
39636- 0 0 0 0 0 0 0 0 0 0 0 0
39637- 0 0 0 0 0 0 0 0 0 0 0 0
39638- 0 0 0 0 0 0 0 0 0 0 0 0
39639- 0 0 0 0 0 0 0 0 0 10 10 10
39640- 30 30 30 78 78 78 174 135 50 224 166 10
39641-239 182 13 246 190 14 246 190 14 246 190 14
39642-246 190 14 246 190 14 246 190 14 246 190 14
39643-246 190 14 246 190 14 246 190 14 246 190 14
39644-246 190 14 246 190 14 241 196 14 139 102 15
39645- 2 2 6 2 2 6 2 2 6 2 2 6
39646- 78 78 78 250 250 250 253 253 253 253 253 253
39647-253 253 253 253 253 253 253 253 253 253 253 253
39648-253 253 253 253 253 253 253 253 253 253 253 253
39649-253 253 253 253 253 253 253 253 253 253 253 253
39650-250 250 250 214 214 214 198 198 198 190 150 46
39651-219 162 10 236 178 12 234 174 13 224 166 10
39652-216 158 10 213 154 11 213 154 11 216 158 10
39653-226 170 11 239 182 13 246 190 14 246 190 14
39654-246 190 14 246 190 14 242 186 14 206 162 42
39655-101 101 101 58 58 58 30 30 30 14 14 14
39656- 6 6 6 0 0 0 0 0 0 0 0 0
39657- 0 0 0 0 0 0 0 0 0 0 0 0
39658- 0 0 0 0 0 0 0 0 0 0 0 0
39659- 0 0 0 0 0 0 0 0 0 10 10 10
39660- 30 30 30 74 74 74 174 135 50 216 158 10
39661-236 178 12 246 190 14 246 190 14 246 190 14
39662-246 190 14 246 190 14 246 190 14 246 190 14
39663-246 190 14 246 190 14 246 190 14 246 190 14
39664-246 190 14 246 190 14 241 196 14 226 184 13
39665- 61 42 6 2 2 6 2 2 6 2 2 6
39666- 22 22 22 238 238 238 253 253 253 253 253 253
39667-253 253 253 253 253 253 253 253 253 253 253 253
39668-253 253 253 253 253 253 253 253 253 253 253 253
39669-253 253 253 253 253 253 253 253 253 253 253 253
39670-253 253 253 226 226 226 187 187 187 180 133 36
39671-216 158 10 236 178 12 239 182 13 236 178 12
39672-230 174 11 226 170 11 226 170 11 230 174 11
39673-236 178 12 242 186 14 246 190 14 246 190 14
39674-246 190 14 246 190 14 246 186 14 239 182 13
39675-206 162 42 106 106 106 66 66 66 34 34 34
39676- 14 14 14 6 6 6 0 0 0 0 0 0
39677- 0 0 0 0 0 0 0 0 0 0 0 0
39678- 0 0 0 0 0 0 0 0 0 0 0 0
39679- 0 0 0 0 0 0 0 0 0 6 6 6
39680- 26 26 26 70 70 70 163 133 67 213 154 11
39681-236 178 12 246 190 14 246 190 14 246 190 14
39682-246 190 14 246 190 14 246 190 14 246 190 14
39683-246 190 14 246 190 14 246 190 14 246 190 14
39684-246 190 14 246 190 14 246 190 14 241 196 14
39685-190 146 13 18 14 6 2 2 6 2 2 6
39686- 46 46 46 246 246 246 253 253 253 253 253 253
39687-253 253 253 253 253 253 253 253 253 253 253 253
39688-253 253 253 253 253 253 253 253 253 253 253 253
39689-253 253 253 253 253 253 253 253 253 253 253 253
39690-253 253 253 221 221 221 86 86 86 156 107 11
39691-216 158 10 236 178 12 242 186 14 246 186 14
39692-242 186 14 239 182 13 239 182 13 242 186 14
39693-242 186 14 246 186 14 246 190 14 246 190 14
39694-246 190 14 246 190 14 246 190 14 246 190 14
39695-242 186 14 225 175 15 142 122 72 66 66 66
39696- 30 30 30 10 10 10 0 0 0 0 0 0
39697- 0 0 0 0 0 0 0 0 0 0 0 0
39698- 0 0 0 0 0 0 0 0 0 0 0 0
39699- 0 0 0 0 0 0 0 0 0 6 6 6
39700- 26 26 26 70 70 70 163 133 67 210 150 10
39701-236 178 12 246 190 14 246 190 14 246 190 14
39702-246 190 14 246 190 14 246 190 14 246 190 14
39703-246 190 14 246 190 14 246 190 14 246 190 14
39704-246 190 14 246 190 14 246 190 14 246 190 14
39705-232 195 16 121 92 8 34 34 34 106 106 106
39706-221 221 221 253 253 253 253 253 253 253 253 253
39707-253 253 253 253 253 253 253 253 253 253 253 253
39708-253 253 253 253 253 253 253 253 253 253 253 253
39709-253 253 253 253 253 253 253 253 253 253 253 253
39710-242 242 242 82 82 82 18 14 6 163 110 8
39711-216 158 10 236 178 12 242 186 14 246 190 14
39712-246 190 14 246 190 14 246 190 14 246 190 14
39713-246 190 14 246 190 14 246 190 14 246 190 14
39714-246 190 14 246 190 14 246 190 14 246 190 14
39715-246 190 14 246 190 14 242 186 14 163 133 67
39716- 46 46 46 18 18 18 6 6 6 0 0 0
39717- 0 0 0 0 0 0 0 0 0 0 0 0
39718- 0 0 0 0 0 0 0 0 0 0 0 0
39719- 0 0 0 0 0 0 0 0 0 10 10 10
39720- 30 30 30 78 78 78 163 133 67 210 150 10
39721-236 178 12 246 186 14 246 190 14 246 190 14
39722-246 190 14 246 190 14 246 190 14 246 190 14
39723-246 190 14 246 190 14 246 190 14 246 190 14
39724-246 190 14 246 190 14 246 190 14 246 190 14
39725-241 196 14 215 174 15 190 178 144 253 253 253
39726-253 253 253 253 253 253 253 253 253 253 253 253
39727-253 253 253 253 253 253 253 253 253 253 253 253
39728-253 253 253 253 253 253 253 253 253 253 253 253
39729-253 253 253 253 253 253 253 253 253 218 218 218
39730- 58 58 58 2 2 6 22 18 6 167 114 7
39731-216 158 10 236 178 12 246 186 14 246 190 14
39732-246 190 14 246 190 14 246 190 14 246 190 14
39733-246 190 14 246 190 14 246 190 14 246 190 14
39734-246 190 14 246 190 14 246 190 14 246 190 14
39735-246 190 14 246 186 14 242 186 14 190 150 46
39736- 54 54 54 22 22 22 6 6 6 0 0 0
39737- 0 0 0 0 0 0 0 0 0 0 0 0
39738- 0 0 0 0 0 0 0 0 0 0 0 0
39739- 0 0 0 0 0 0 0 0 0 14 14 14
39740- 38 38 38 86 86 86 180 133 36 213 154 11
39741-236 178 12 246 186 14 246 190 14 246 190 14
39742-246 190 14 246 190 14 246 190 14 246 190 14
39743-246 190 14 246 190 14 246 190 14 246 190 14
39744-246 190 14 246 190 14 246 190 14 246 190 14
39745-246 190 14 232 195 16 190 146 13 214 214 214
39746-253 253 253 253 253 253 253 253 253 253 253 253
39747-253 253 253 253 253 253 253 253 253 253 253 253
39748-253 253 253 253 253 253 253 253 253 253 253 253
39749-253 253 253 250 250 250 170 170 170 26 26 26
39750- 2 2 6 2 2 6 37 26 9 163 110 8
39751-219 162 10 239 182 13 246 186 14 246 190 14
39752-246 190 14 246 190 14 246 190 14 246 190 14
39753-246 190 14 246 190 14 246 190 14 246 190 14
39754-246 190 14 246 190 14 246 190 14 246 190 14
39755-246 186 14 236 178 12 224 166 10 142 122 72
39756- 46 46 46 18 18 18 6 6 6 0 0 0
39757- 0 0 0 0 0 0 0 0 0 0 0 0
39758- 0 0 0 0 0 0 0 0 0 0 0 0
39759- 0 0 0 0 0 0 6 6 6 18 18 18
39760- 50 50 50 109 106 95 192 133 9 224 166 10
39761-242 186 14 246 190 14 246 190 14 246 190 14
39762-246 190 14 246 190 14 246 190 14 246 190 14
39763-246 190 14 246 190 14 246 190 14 246 190 14
39764-246 190 14 246 190 14 246 190 14 246 190 14
39765-242 186 14 226 184 13 210 162 10 142 110 46
39766-226 226 226 253 253 253 253 253 253 253 253 253
39767-253 253 253 253 253 253 253 253 253 253 253 253
39768-253 253 253 253 253 253 253 253 253 253 253 253
39769-198 198 198 66 66 66 2 2 6 2 2 6
39770- 2 2 6 2 2 6 50 34 6 156 107 11
39771-219 162 10 239 182 13 246 186 14 246 190 14
39772-246 190 14 246 190 14 246 190 14 246 190 14
39773-246 190 14 246 190 14 246 190 14 246 190 14
39774-246 190 14 246 190 14 246 190 14 242 186 14
39775-234 174 13 213 154 11 154 122 46 66 66 66
39776- 30 30 30 10 10 10 0 0 0 0 0 0
39777- 0 0 0 0 0 0 0 0 0 0 0 0
39778- 0 0 0 0 0 0 0 0 0 0 0 0
39779- 0 0 0 0 0 0 6 6 6 22 22 22
39780- 58 58 58 154 121 60 206 145 10 234 174 13
39781-242 186 14 246 186 14 246 190 14 246 190 14
39782-246 190 14 246 190 14 246 190 14 246 190 14
39783-246 190 14 246 190 14 246 190 14 246 190 14
39784-246 190 14 246 190 14 246 190 14 246 190 14
39785-246 186 14 236 178 12 210 162 10 163 110 8
39786- 61 42 6 138 138 138 218 218 218 250 250 250
39787-253 253 253 253 253 253 253 253 253 250 250 250
39788-242 242 242 210 210 210 144 144 144 66 66 66
39789- 6 6 6 2 2 6 2 2 6 2 2 6
39790- 2 2 6 2 2 6 61 42 6 163 110 8
39791-216 158 10 236 178 12 246 190 14 246 190 14
39792-246 190 14 246 190 14 246 190 14 246 190 14
39793-246 190 14 246 190 14 246 190 14 246 190 14
39794-246 190 14 239 182 13 230 174 11 216 158 10
39795-190 142 34 124 112 88 70 70 70 38 38 38
39796- 18 18 18 6 6 6 0 0 0 0 0 0
39797- 0 0 0 0 0 0 0 0 0 0 0 0
39798- 0 0 0 0 0 0 0 0 0 0 0 0
39799- 0 0 0 0 0 0 6 6 6 22 22 22
39800- 62 62 62 168 124 44 206 145 10 224 166 10
39801-236 178 12 239 182 13 242 186 14 242 186 14
39802-246 186 14 246 190 14 246 190 14 246 190 14
39803-246 190 14 246 190 14 246 190 14 246 190 14
39804-246 190 14 246 190 14 246 190 14 246 190 14
39805-246 190 14 236 178 12 216 158 10 175 118 6
39806- 80 54 7 2 2 6 6 6 6 30 30 30
39807- 54 54 54 62 62 62 50 50 50 38 38 38
39808- 14 14 14 2 2 6 2 2 6 2 2 6
39809- 2 2 6 2 2 6 2 2 6 2 2 6
39810- 2 2 6 6 6 6 80 54 7 167 114 7
39811-213 154 11 236 178 12 246 190 14 246 190 14
39812-246 190 14 246 190 14 246 190 14 246 190 14
39813-246 190 14 242 186 14 239 182 13 239 182 13
39814-230 174 11 210 150 10 174 135 50 124 112 88
39815- 82 82 82 54 54 54 34 34 34 18 18 18
39816- 6 6 6 0 0 0 0 0 0 0 0 0
39817- 0 0 0 0 0 0 0 0 0 0 0 0
39818- 0 0 0 0 0 0 0 0 0 0 0 0
39819- 0 0 0 0 0 0 6 6 6 18 18 18
39820- 50 50 50 158 118 36 192 133 9 200 144 11
39821-216 158 10 219 162 10 224 166 10 226 170 11
39822-230 174 11 236 178 12 239 182 13 239 182 13
39823-242 186 14 246 186 14 246 190 14 246 190 14
39824-246 190 14 246 190 14 246 190 14 246 190 14
39825-246 186 14 230 174 11 210 150 10 163 110 8
39826-104 69 6 10 10 10 2 2 6 2 2 6
39827- 2 2 6 2 2 6 2 2 6 2 2 6
39828- 2 2 6 2 2 6 2 2 6 2 2 6
39829- 2 2 6 2 2 6 2 2 6 2 2 6
39830- 2 2 6 6 6 6 91 60 6 167 114 7
39831-206 145 10 230 174 11 242 186 14 246 190 14
39832-246 190 14 246 190 14 246 186 14 242 186 14
39833-239 182 13 230 174 11 224 166 10 213 154 11
39834-180 133 36 124 112 88 86 86 86 58 58 58
39835- 38 38 38 22 22 22 10 10 10 6 6 6
39836- 0 0 0 0 0 0 0 0 0 0 0 0
39837- 0 0 0 0 0 0 0 0 0 0 0 0
39838- 0 0 0 0 0 0 0 0 0 0 0 0
39839- 0 0 0 0 0 0 0 0 0 14 14 14
39840- 34 34 34 70 70 70 138 110 50 158 118 36
39841-167 114 7 180 123 7 192 133 9 197 138 11
39842-200 144 11 206 145 10 213 154 11 219 162 10
39843-224 166 10 230 174 11 239 182 13 242 186 14
39844-246 186 14 246 186 14 246 186 14 246 186 14
39845-239 182 13 216 158 10 185 133 11 152 99 6
39846-104 69 6 18 14 6 2 2 6 2 2 6
39847- 2 2 6 2 2 6 2 2 6 2 2 6
39848- 2 2 6 2 2 6 2 2 6 2 2 6
39849- 2 2 6 2 2 6 2 2 6 2 2 6
39850- 2 2 6 6 6 6 80 54 7 152 99 6
39851-192 133 9 219 162 10 236 178 12 239 182 13
39852-246 186 14 242 186 14 239 182 13 236 178 12
39853-224 166 10 206 145 10 192 133 9 154 121 60
39854- 94 94 94 62 62 62 42 42 42 22 22 22
39855- 14 14 14 6 6 6 0 0 0 0 0 0
39856- 0 0 0 0 0 0 0 0 0 0 0 0
39857- 0 0 0 0 0 0 0 0 0 0 0 0
39858- 0 0 0 0 0 0 0 0 0 0 0 0
39859- 0 0 0 0 0 0 0 0 0 6 6 6
39860- 18 18 18 34 34 34 58 58 58 78 78 78
39861-101 98 89 124 112 88 142 110 46 156 107 11
39862-163 110 8 167 114 7 175 118 6 180 123 7
39863-185 133 11 197 138 11 210 150 10 219 162 10
39864-226 170 11 236 178 12 236 178 12 234 174 13
39865-219 162 10 197 138 11 163 110 8 130 83 6
39866- 91 60 6 10 10 10 2 2 6 2 2 6
39867- 18 18 18 38 38 38 38 38 38 38 38 38
39868- 38 38 38 38 38 38 38 38 38 38 38 38
39869- 38 38 38 38 38 38 26 26 26 2 2 6
39870- 2 2 6 6 6 6 70 47 6 137 92 6
39871-175 118 6 200 144 11 219 162 10 230 174 11
39872-234 174 13 230 174 11 219 162 10 210 150 10
39873-192 133 9 163 110 8 124 112 88 82 82 82
39874- 50 50 50 30 30 30 14 14 14 6 6 6
39875- 0 0 0 0 0 0 0 0 0 0 0 0
39876- 0 0 0 0 0 0 0 0 0 0 0 0
39877- 0 0 0 0 0 0 0 0 0 0 0 0
39878- 0 0 0 0 0 0 0 0 0 0 0 0
39879- 0 0 0 0 0 0 0 0 0 0 0 0
39880- 6 6 6 14 14 14 22 22 22 34 34 34
39881- 42 42 42 58 58 58 74 74 74 86 86 86
39882-101 98 89 122 102 70 130 98 46 121 87 25
39883-137 92 6 152 99 6 163 110 8 180 123 7
39884-185 133 11 197 138 11 206 145 10 200 144 11
39885-180 123 7 156 107 11 130 83 6 104 69 6
39886- 50 34 6 54 54 54 110 110 110 101 98 89
39887- 86 86 86 82 82 82 78 78 78 78 78 78
39888- 78 78 78 78 78 78 78 78 78 78 78 78
39889- 78 78 78 82 82 82 86 86 86 94 94 94
39890-106 106 106 101 101 101 86 66 34 124 80 6
39891-156 107 11 180 123 7 192 133 9 200 144 11
39892-206 145 10 200 144 11 192 133 9 175 118 6
39893-139 102 15 109 106 95 70 70 70 42 42 42
39894- 22 22 22 10 10 10 0 0 0 0 0 0
39895- 0 0 0 0 0 0 0 0 0 0 0 0
39896- 0 0 0 0 0 0 0 0 0 0 0 0
39897- 0 0 0 0 0 0 0 0 0 0 0 0
39898- 0 0 0 0 0 0 0 0 0 0 0 0
39899- 0 0 0 0 0 0 0 0 0 0 0 0
39900- 0 0 0 0 0 0 6 6 6 10 10 10
39901- 14 14 14 22 22 22 30 30 30 38 38 38
39902- 50 50 50 62 62 62 74 74 74 90 90 90
39903-101 98 89 112 100 78 121 87 25 124 80 6
39904-137 92 6 152 99 6 152 99 6 152 99 6
39905-138 86 6 124 80 6 98 70 6 86 66 30
39906-101 98 89 82 82 82 58 58 58 46 46 46
39907- 38 38 38 34 34 34 34 34 34 34 34 34
39908- 34 34 34 34 34 34 34 34 34 34 34 34
39909- 34 34 34 34 34 34 38 38 38 42 42 42
39910- 54 54 54 82 82 82 94 86 76 91 60 6
39911-134 86 6 156 107 11 167 114 7 175 118 6
39912-175 118 6 167 114 7 152 99 6 121 87 25
39913-101 98 89 62 62 62 34 34 34 18 18 18
39914- 6 6 6 0 0 0 0 0 0 0 0 0
39915- 0 0 0 0 0 0 0 0 0 0 0 0
39916- 0 0 0 0 0 0 0 0 0 0 0 0
39917- 0 0 0 0 0 0 0 0 0 0 0 0
39918- 0 0 0 0 0 0 0 0 0 0 0 0
39919- 0 0 0 0 0 0 0 0 0 0 0 0
39920- 0 0 0 0 0 0 0 0 0 0 0 0
39921- 0 0 0 6 6 6 6 6 6 10 10 10
39922- 18 18 18 22 22 22 30 30 30 42 42 42
39923- 50 50 50 66 66 66 86 86 86 101 98 89
39924-106 86 58 98 70 6 104 69 6 104 69 6
39925-104 69 6 91 60 6 82 62 34 90 90 90
39926- 62 62 62 38 38 38 22 22 22 14 14 14
39927- 10 10 10 10 10 10 10 10 10 10 10 10
39928- 10 10 10 10 10 10 6 6 6 10 10 10
39929- 10 10 10 10 10 10 10 10 10 14 14 14
39930- 22 22 22 42 42 42 70 70 70 89 81 66
39931- 80 54 7 104 69 6 124 80 6 137 92 6
39932-134 86 6 116 81 8 100 82 52 86 86 86
39933- 58 58 58 30 30 30 14 14 14 6 6 6
39934- 0 0 0 0 0 0 0 0 0 0 0 0
39935- 0 0 0 0 0 0 0 0 0 0 0 0
39936- 0 0 0 0 0 0 0 0 0 0 0 0
39937- 0 0 0 0 0 0 0 0 0 0 0 0
39938- 0 0 0 0 0 0 0 0 0 0 0 0
39939- 0 0 0 0 0 0 0 0 0 0 0 0
39940- 0 0 0 0 0 0 0 0 0 0 0 0
39941- 0 0 0 0 0 0 0 0 0 0 0 0
39942- 0 0 0 6 6 6 10 10 10 14 14 14
39943- 18 18 18 26 26 26 38 38 38 54 54 54
39944- 70 70 70 86 86 86 94 86 76 89 81 66
39945- 89 81 66 86 86 86 74 74 74 50 50 50
39946- 30 30 30 14 14 14 6 6 6 0 0 0
39947- 0 0 0 0 0 0 0 0 0 0 0 0
39948- 0 0 0 0 0 0 0 0 0 0 0 0
39949- 0 0 0 0 0 0 0 0 0 0 0 0
39950- 6 6 6 18 18 18 34 34 34 58 58 58
39951- 82 82 82 89 81 66 89 81 66 89 81 66
39952- 94 86 66 94 86 76 74 74 74 50 50 50
39953- 26 26 26 14 14 14 6 6 6 0 0 0
39954- 0 0 0 0 0 0 0 0 0 0 0 0
39955- 0 0 0 0 0 0 0 0 0 0 0 0
39956- 0 0 0 0 0 0 0 0 0 0 0 0
39957- 0 0 0 0 0 0 0 0 0 0 0 0
39958- 0 0 0 0 0 0 0 0 0 0 0 0
39959- 0 0 0 0 0 0 0 0 0 0 0 0
39960- 0 0 0 0 0 0 0 0 0 0 0 0
39961- 0 0 0 0 0 0 0 0 0 0 0 0
39962- 0 0 0 0 0 0 0 0 0 0 0 0
39963- 6 6 6 6 6 6 14 14 14 18 18 18
39964- 30 30 30 38 38 38 46 46 46 54 54 54
39965- 50 50 50 42 42 42 30 30 30 18 18 18
39966- 10 10 10 0 0 0 0 0 0 0 0 0
39967- 0 0 0 0 0 0 0 0 0 0 0 0
39968- 0 0 0 0 0 0 0 0 0 0 0 0
39969- 0 0 0 0 0 0 0 0 0 0 0 0
39970- 0 0 0 6 6 6 14 14 14 26 26 26
39971- 38 38 38 50 50 50 58 58 58 58 58 58
39972- 54 54 54 42 42 42 30 30 30 18 18 18
39973- 10 10 10 0 0 0 0 0 0 0 0 0
39974- 0 0 0 0 0 0 0 0 0 0 0 0
39975- 0 0 0 0 0 0 0 0 0 0 0 0
39976- 0 0 0 0 0 0 0 0 0 0 0 0
39977- 0 0 0 0 0 0 0 0 0 0 0 0
39978- 0 0 0 0 0 0 0 0 0 0 0 0
39979- 0 0 0 0 0 0 0 0 0 0 0 0
39980- 0 0 0 0 0 0 0 0 0 0 0 0
39981- 0 0 0 0 0 0 0 0 0 0 0 0
39982- 0 0 0 0 0 0 0 0 0 0 0 0
39983- 0 0 0 0 0 0 0 0 0 6 6 6
39984- 6 6 6 10 10 10 14 14 14 18 18 18
39985- 18 18 18 14 14 14 10 10 10 6 6 6
39986- 0 0 0 0 0 0 0 0 0 0 0 0
39987- 0 0 0 0 0 0 0 0 0 0 0 0
39988- 0 0 0 0 0 0 0 0 0 0 0 0
39989- 0 0 0 0 0 0 0 0 0 0 0 0
39990- 0 0 0 0 0 0 0 0 0 6 6 6
39991- 14 14 14 18 18 18 22 22 22 22 22 22
39992- 18 18 18 14 14 14 10 10 10 6 6 6
39993- 0 0 0 0 0 0 0 0 0 0 0 0
39994- 0 0 0 0 0 0 0 0 0 0 0 0
39995- 0 0 0 0 0 0 0 0 0 0 0 0
39996- 0 0 0 0 0 0 0 0 0 0 0 0
39997- 0 0 0 0 0 0 0 0 0 0 0 0
39998+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39999+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40000+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40001+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40002+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40003+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40004+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40005+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40006+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40007+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40008+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40009+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40010+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40011+4 4 4 4 4 4
40012+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40013+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40014+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40015+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40016+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40017+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40018+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40019+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40020+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40021+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40022+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40023+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40024+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40025+4 4 4 4 4 4
40026+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40027+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40028+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40029+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40030+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40031+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40032+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40033+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40034+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40035+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40036+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40037+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40038+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40039+4 4 4 4 4 4
40040+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40041+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40042+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40043+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40044+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40045+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40046+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40047+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40048+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40049+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40050+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40051+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40052+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40053+4 4 4 4 4 4
40054+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40055+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40056+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40057+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40058+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40059+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40060+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40061+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40062+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40063+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40064+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40065+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40066+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40067+4 4 4 4 4 4
40068+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40069+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40070+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40071+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40072+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40073+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40074+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40075+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40076+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40077+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40078+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40079+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40080+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40081+4 4 4 4 4 4
40082+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40083+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40084+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40085+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40086+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
40087+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
40088+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40089+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40090+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40091+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
40092+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40093+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
40094+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40095+4 4 4 4 4 4
40096+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40097+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40098+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40099+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40100+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
40101+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
40102+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40103+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40104+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40105+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
40106+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
40107+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
40108+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40109+4 4 4 4 4 4
40110+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40111+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40112+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40113+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40114+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
40115+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
40116+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40117+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40118+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40119+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
40120+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
40121+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
40122+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
40123+4 4 4 4 4 4
40124+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40125+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40126+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40127+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
40128+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
40129+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
40130+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
40131+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40132+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40133+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
40134+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
40135+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
40136+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
40137+4 4 4 4 4 4
40138+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40139+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40140+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40141+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
40142+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
40143+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
40144+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
40145+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40146+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
40147+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
40148+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
40149+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
40150+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
40151+4 4 4 4 4 4
40152+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40153+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40154+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40155+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
40156+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
40157+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
40158+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
40159+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
40160+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
40161+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
40162+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
40163+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
40164+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
40165+4 4 4 4 4 4
40166+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40167+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40168+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
40169+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
40170+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
40171+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
40172+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
40173+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
40174+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
40175+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
40176+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
40177+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
40178+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
40179+4 4 4 4 4 4
40180+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40181+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40182+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
40183+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
40184+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
40185+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
40186+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
40187+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
40188+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
40189+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
40190+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
40191+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
40192+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
40193+4 4 4 4 4 4
40194+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40195+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40196+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
40197+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
40198+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
40199+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
40200+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
40201+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
40202+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
40203+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
40204+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
40205+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
40206+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40207+4 4 4 4 4 4
40208+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40209+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40210+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
40211+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
40212+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
40213+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
40214+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
40215+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
40216+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
40217+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
40218+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
40219+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
40220+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
40221+4 4 4 4 4 4
40222+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40223+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
40224+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
40225+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
40226+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
40227+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
40228+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
40229+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
40230+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
40231+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
40232+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
40233+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
40234+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
40235+4 4 4 4 4 4
40236+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40237+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
40238+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
40239+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
40240+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
40241+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
40242+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
40243+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
40244+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
40245+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
40246+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
40247+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
40248+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
40249+0 0 0 4 4 4
40250+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40251+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
40252+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
40253+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
40254+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
40255+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
40256+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
40257+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
40258+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
40259+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
40260+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
40261+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
40262+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
40263+2 0 0 0 0 0
40264+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
40265+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
40266+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
40267+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
40268+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
40269+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
40270+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
40271+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
40272+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
40273+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
40274+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
40275+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
40276+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
40277+37 38 37 0 0 0
40278+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40279+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
40280+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
40281+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
40282+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
40283+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
40284+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
40285+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
40286+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
40287+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
40288+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
40289+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
40290+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
40291+85 115 134 4 0 0
40292+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
40293+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
40294+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
40295+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
40296+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
40297+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
40298+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
40299+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
40300+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
40301+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
40302+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
40303+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
40304+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
40305+60 73 81 4 0 0
40306+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
40307+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
40308+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
40309+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
40310+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
40311+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
40312+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
40313+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
40314+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
40315+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
40316+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
40317+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
40318+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
40319+16 19 21 4 0 0
40320+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
40321+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
40322+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
40323+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
40324+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
40325+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
40326+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
40327+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
40328+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
40329+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
40330+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
40331+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
40332+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
40333+4 0 0 4 3 3
40334+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
40335+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
40336+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
40337+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
40338+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
40339+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
40340+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
40341+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
40342+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
40343+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
40344+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
40345+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
40346+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
40347+3 2 2 4 4 4
40348+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
40349+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
40350+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
40351+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40352+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
40353+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
40354+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
40355+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
40356+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
40357+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
40358+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
40359+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
40360+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
40361+4 4 4 4 4 4
40362+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
40363+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
40364+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
40365+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
40366+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
40367+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
40368+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
40369+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
40370+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
40371+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
40372+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
40373+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
40374+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
40375+4 4 4 4 4 4
40376+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
40377+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
40378+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
40379+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
40380+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
40381+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
40382+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
40383+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
40384+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
40385+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
40386+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
40387+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
40388+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
40389+5 5 5 5 5 5
40390+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
40391+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
40392+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
40393+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
40394+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
40395+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40396+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
40397+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
40398+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
40399+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
40400+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
40401+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
40402+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
40403+5 5 5 4 4 4
40404+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
40405+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
40406+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
40407+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
40408+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40409+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
40410+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
40411+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
40412+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
40413+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
40414+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
40415+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
40416+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40417+4 4 4 4 4 4
40418+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
40419+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
40420+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
40421+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
40422+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
40423+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40424+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40425+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
40426+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
40427+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
40428+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
40429+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
40430+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40431+4 4 4 4 4 4
40432+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
40433+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
40434+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
40435+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
40436+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40437+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
40438+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
40439+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
40440+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
40441+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
40442+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
40443+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40444+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40445+4 4 4 4 4 4
40446+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
40447+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
40448+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
40449+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
40450+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40451+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40452+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40453+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
40454+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
40455+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
40456+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
40457+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40458+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40459+4 4 4 4 4 4
40460+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
40461+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
40462+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
40463+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
40464+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40465+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
40466+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
40467+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
40468+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
40469+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
40470+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40471+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40472+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40473+4 4 4 4 4 4
40474+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
40475+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
40476+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
40477+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
40478+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40479+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
40480+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
40481+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
40482+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
40483+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
40484+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
40485+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40486+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40487+4 4 4 4 4 4
40488+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
40489+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
40490+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
40491+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
40492+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40493+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
40494+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
40495+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
40496+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
40497+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
40498+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
40499+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40500+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40501+4 4 4 4 4 4
40502+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
40503+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
40504+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
40505+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
40506+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
40507+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
40508+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
40509+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
40510+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
40511+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
40512+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40513+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40514+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40515+4 4 4 4 4 4
40516+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
40517+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
40518+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
40519+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
40520+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40521+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
40522+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
40523+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
40524+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
40525+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
40526+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40527+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40528+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40529+4 4 4 4 4 4
40530+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
40531+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
40532+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
40533+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
40534+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40535+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
40536+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
40537+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
40538+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
40539+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
40540+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40541+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40542+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40543+4 4 4 4 4 4
40544+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
40545+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
40546+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
40547+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
40548+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40549+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
40550+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
40551+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
40552+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
40553+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40554+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40555+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40556+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40557+4 4 4 4 4 4
40558+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
40559+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
40560+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
40561+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
40562+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
40563+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
40564+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
40565+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
40566+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40567+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40568+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40569+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40570+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40571+4 4 4 4 4 4
40572+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
40573+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
40574+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
40575+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
40576+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40577+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
40578+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
40579+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
40580+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
40581+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40582+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40583+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40584+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40585+4 4 4 4 4 4
40586+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
40587+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
40588+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
40589+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
40590+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
40591+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
40592+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
40593+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
40594+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40595+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40596+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40597+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40598+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40599+4 4 4 4 4 4
40600+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
40601+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
40602+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
40603+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
40604+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
40605+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
40606+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
40607+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
40608+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
40609+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40610+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40611+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40612+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40613+4 4 4 4 4 4
40614+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
40615+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
40616+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
40617+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
40618+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
40619+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
40620+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
40621+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
40622+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40623+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40624+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40625+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40626+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40627+4 4 4 4 4 4
40628+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
40629+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
40630+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
40631+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
40632+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
40633+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
40634+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
40635+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
40636+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
40637+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40638+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40639+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40640+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40641+4 4 4 4 4 4
40642+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
40643+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
40644+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
40645+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
40646+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
40647+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
40648+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
40649+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
40650+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40651+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40652+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40653+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40654+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40655+4 4 4 4 4 4
40656+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40657+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
40658+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
40659+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
40660+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
40661+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
40662+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
40663+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
40664+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
40665+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40666+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40668+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40669+4 4 4 4 4 4
40670+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
40671+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
40672+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
40673+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
40674+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
40675+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
40676+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40677+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
40678+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40679+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40680+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40683+4 4 4 4 4 4
40684+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40685+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
40686+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
40687+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
40688+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
40689+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
40690+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40691+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
40692+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
40693+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40694+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40697+4 4 4 4 4 4
40698+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
40699+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
40700+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
40701+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
40702+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
40703+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
40704+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
40705+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
40706+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
40707+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40708+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40711+4 4 4 4 4 4
40712+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40713+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
40714+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
40715+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
40716+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
40717+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
40718+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
40719+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
40720+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
40721+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40722+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40725+4 4 4 4 4 4
40726+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
40727+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
40728+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
40729+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
40730+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
40731+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
40732+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
40733+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
40734+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
40735+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40736+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40739+4 4 4 4 4 4
40740+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40741+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
40742+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
40743+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
40744+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
40745+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
40746+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
40747+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
40748+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
40749+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40750+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40753+4 4 4 4 4 4
40754+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
40755+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
40756+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
40757+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
40758+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
40759+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
40760+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
40761+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
40762+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
40763+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
40764+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40766+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40767+4 4 4 4 4 4
40768+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
40769+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
40770+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
40771+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
40772+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
40773+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
40774+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
40775+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
40776+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
40777+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
40778+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40781+4 4 4 4 4 4
40782+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
40783+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
40784+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
40785+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
40786+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
40787+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
40788+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40789+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
40790+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
40791+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
40792+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40794+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40795+4 4 4 4 4 4
40796+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
40797+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
40798+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
40799+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
40800+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
40801+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
40802+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
40803+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
40804+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
40805+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
40806+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40807+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40808+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40809+4 4 4 4 4 4
40810+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
40811+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
40812+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
40813+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
40814+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
40815+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
40816+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
40817+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
40818+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
40819+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
40820+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40821+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40822+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40823+4 4 4 4 4 4
40824+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
40825+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
40826+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
40827+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
40828+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
40829+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
40830+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
40831+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
40832+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
40833+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
40834+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40835+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40836+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40837+4 4 4 4 4 4
40838+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
40839+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
40840+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
40841+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
40842+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
40843+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
40844+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
40845+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
40846+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
40847+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
40848+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40849+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40850+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40851+4 4 4 4 4 4
40852+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
40853+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
40854+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
40855+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
40856+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
40857+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
40858+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
40859+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
40860+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
40861+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40862+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40863+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40864+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40865+4 4 4 4 4 4
40866+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
40867+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
40868+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
40869+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
40870+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
40871+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
40872+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
40873+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
40874+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
40875+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40876+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40877+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40878+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40879+4 4 4 4 4 4
40880+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
40881+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
40882+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
40883+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
40884+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
40885+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
40886+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
40887+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
40888+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
40889+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40890+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40891+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40892+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40893+4 4 4 4 4 4
40894+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
40895+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
40896+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
40897+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
40898+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
40899+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
40900+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
40901+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
40902+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40903+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40904+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40905+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40906+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40907+4 4 4 4 4 4
40908+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
40909+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
40910+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
40911+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
40912+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
40913+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
40914+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
40915+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
40916+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40917+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40918+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40919+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40920+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40921+4 4 4 4 4 4
40922+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
40923+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
40924+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
40925+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
40926+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
40927+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
40928+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
40929+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
40930+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40931+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40932+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40933+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40934+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40935+4 4 4 4 4 4
40936+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40937+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
40938+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
40939+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
40940+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
40941+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
40942+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
40943+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
40944+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40945+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40946+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40947+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40948+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40949+4 4 4 4 4 4
40950+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40951+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
40952+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
40953+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
40954+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
40955+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
40956+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
40957+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
40958+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40959+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40960+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40961+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40962+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40963+4 4 4 4 4 4
40964+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40965+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
40966+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
40967+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
40968+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
40969+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
40970+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
40971+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40972+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40973+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40974+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40975+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40976+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40977+4 4 4 4 4 4
40978+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40979+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40980+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
40981+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
40982+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
40983+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
40984+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
40985+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40986+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40987+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40988+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40989+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40990+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40991+4 4 4 4 4 4
40992+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40993+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40994+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40995+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
40996+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
40997+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
40998+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
40999+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41000+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41001+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41002+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41003+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41004+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41005+4 4 4 4 4 4
41006+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41007+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41008+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41009+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41010+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41011+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
41012+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
41013+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41014+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41015+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41016+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41017+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41018+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41019+4 4 4 4 4 4
41020+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41021+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41022+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41023+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41024+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41025+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41026+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
41027+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41028+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41029+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41030+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41031+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41032+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41033+4 4 4 4 4 4
41034+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41035+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41036+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41037+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
41038+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
41039+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
41040+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
41041+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41042+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41043+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41044+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41045+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41046+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41047+4 4 4 4 4 4
41048+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41049+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41050+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41051+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41052+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
41053+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41054+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41055+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41056+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41057+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41058+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41059+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41060+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41061+4 4 4 4 4 4
41062+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41063+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41064+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41065+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41066+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
41067+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
41068+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41069+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41070+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41071+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41072+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41073+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41074+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41075+4 4 4 4 4 4
41076+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41077+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41078+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41079+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41080+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
41081+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
41082+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41083+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41084+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41085+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41086+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41087+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41088+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41089+4 4 4 4 4 4
41090+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41091+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41092+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41093+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41094+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
41095+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
41096+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41097+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41098+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41099+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41100+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41101+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41102+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41103+4 4 4 4 4 4
41104+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41105+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41106+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41107+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41108+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41109+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
41110+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41111+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41112+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41113+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41114+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41115+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41116+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41117+4 4 4 4 4 4
41118diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
41119index a159b63..4ab532d 100644
41120--- a/drivers/video/udlfb.c
41121+++ b/drivers/video/udlfb.c
41122@@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
41123 dlfb_urb_completion(urb);
41124
41125 error:
41126- atomic_add(bytes_sent, &dev->bytes_sent);
41127- atomic_add(bytes_identical, &dev->bytes_identical);
41128- atomic_add(width*height*2, &dev->bytes_rendered);
41129+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41130+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41131+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
41132 end_cycles = get_cycles();
41133- atomic_add(((unsigned int) ((end_cycles - start_cycles)
41134+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41135 >> 10)), /* Kcycles */
41136 &dev->cpu_kcycles_used);
41137
41138@@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
41139 dlfb_urb_completion(urb);
41140
41141 error:
41142- atomic_add(bytes_sent, &dev->bytes_sent);
41143- atomic_add(bytes_identical, &dev->bytes_identical);
41144- atomic_add(bytes_rendered, &dev->bytes_rendered);
41145+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41146+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41147+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
41148 end_cycles = get_cycles();
41149- atomic_add(((unsigned int) ((end_cycles - start_cycles)
41150+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41151 >> 10)), /* Kcycles */
41152 &dev->cpu_kcycles_used);
41153 }
41154@@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
41155 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41156 struct dlfb_data *dev = fb_info->par;
41157 return snprintf(buf, PAGE_SIZE, "%u\n",
41158- atomic_read(&dev->bytes_rendered));
41159+ atomic_read_unchecked(&dev->bytes_rendered));
41160 }
41161
41162 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41163@@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41164 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41165 struct dlfb_data *dev = fb_info->par;
41166 return snprintf(buf, PAGE_SIZE, "%u\n",
41167- atomic_read(&dev->bytes_identical));
41168+ atomic_read_unchecked(&dev->bytes_identical));
41169 }
41170
41171 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41172@@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41173 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41174 struct dlfb_data *dev = fb_info->par;
41175 return snprintf(buf, PAGE_SIZE, "%u\n",
41176- atomic_read(&dev->bytes_sent));
41177+ atomic_read_unchecked(&dev->bytes_sent));
41178 }
41179
41180 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41181@@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41182 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41183 struct dlfb_data *dev = fb_info->par;
41184 return snprintf(buf, PAGE_SIZE, "%u\n",
41185- atomic_read(&dev->cpu_kcycles_used));
41186+ atomic_read_unchecked(&dev->cpu_kcycles_used));
41187 }
41188
41189 static ssize_t edid_show(
41190@@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
41191 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41192 struct dlfb_data *dev = fb_info->par;
41193
41194- atomic_set(&dev->bytes_rendered, 0);
41195- atomic_set(&dev->bytes_identical, 0);
41196- atomic_set(&dev->bytes_sent, 0);
41197- atomic_set(&dev->cpu_kcycles_used, 0);
41198+ atomic_set_unchecked(&dev->bytes_rendered, 0);
41199+ atomic_set_unchecked(&dev->bytes_identical, 0);
41200+ atomic_set_unchecked(&dev->bytes_sent, 0);
41201+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
41202
41203 return count;
41204 }
41205diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
41206index b0e2a42..e2df3ad 100644
41207--- a/drivers/video/uvesafb.c
41208+++ b/drivers/video/uvesafb.c
41209@@ -19,6 +19,7 @@
41210 #include <linux/io.h>
41211 #include <linux/mutex.h>
41212 #include <linux/slab.h>
41213+#include <linux/moduleloader.h>
41214 #include <video/edid.h>
41215 #include <video/uvesafb.h>
41216 #ifdef CONFIG_X86
41217@@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
41218 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
41219 par->pmi_setpal = par->ypan = 0;
41220 } else {
41221+
41222+#ifdef CONFIG_PAX_KERNEXEC
41223+#ifdef CONFIG_MODULES
41224+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
41225+#endif
41226+ if (!par->pmi_code) {
41227+ par->pmi_setpal = par->ypan = 0;
41228+ return 0;
41229+ }
41230+#endif
41231+
41232 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
41233 + task->t.regs.edi);
41234+
41235+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41236+ pax_open_kernel();
41237+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
41238+ pax_close_kernel();
41239+
41240+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
41241+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
41242+#else
41243 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
41244 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
41245+#endif
41246+
41247 printk(KERN_INFO "uvesafb: protected mode interface info at "
41248 "%04x:%04x\n",
41249 (u16)task->t.regs.es, (u16)task->t.regs.edi);
41250@@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
41251 par->ypan = ypan;
41252
41253 if (par->pmi_setpal || par->ypan) {
41254+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
41255 if (__supported_pte_mask & _PAGE_NX) {
41256 par->pmi_setpal = par->ypan = 0;
41257 printk(KERN_WARNING "uvesafb: NX protection is actively."
41258 "We have better not to use the PMI.\n");
41259- } else {
41260+ } else
41261+#endif
41262 uvesafb_vbe_getpmi(task, par);
41263- }
41264 }
41265 #else
41266 /* The protected mode interface is not available on non-x86. */
41267@@ -1836,6 +1860,11 @@ out:
41268 if (par->vbe_modes)
41269 kfree(par->vbe_modes);
41270
41271+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41272+ if (par->pmi_code)
41273+ module_free_exec(NULL, par->pmi_code);
41274+#endif
41275+
41276 framebuffer_release(info);
41277 return err;
41278 }
41279@@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
41280 kfree(par->vbe_state_orig);
41281 if (par->vbe_state_saved)
41282 kfree(par->vbe_state_saved);
41283+
41284+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41285+ if (par->pmi_code)
41286+ module_free_exec(NULL, par->pmi_code);
41287+#endif
41288+
41289 }
41290
41291 framebuffer_release(info);
41292diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
41293index 501b340..86bd4cf 100644
41294--- a/drivers/video/vesafb.c
41295+++ b/drivers/video/vesafb.c
41296@@ -9,6 +9,7 @@
41297 */
41298
41299 #include <linux/module.h>
41300+#include <linux/moduleloader.h>
41301 #include <linux/kernel.h>
41302 #include <linux/errno.h>
41303 #include <linux/string.h>
41304@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
41305 static int vram_total __initdata; /* Set total amount of memory */
41306 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
41307 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
41308-static void (*pmi_start)(void) __read_mostly;
41309-static void (*pmi_pal) (void) __read_mostly;
41310+static void (*pmi_start)(void) __read_only;
41311+static void (*pmi_pal) (void) __read_only;
41312 static int depth __read_mostly;
41313 static int vga_compat __read_mostly;
41314 /* --------------------------------------------------------------------- */
41315@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
41316 unsigned int size_vmode;
41317 unsigned int size_remap;
41318 unsigned int size_total;
41319+ void *pmi_code = NULL;
41320
41321 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
41322 return -ENODEV;
41323@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
41324 size_remap = size_total;
41325 vesafb_fix.smem_len = size_remap;
41326
41327-#ifndef __i386__
41328- screen_info.vesapm_seg = 0;
41329-#endif
41330-
41331 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
41332 printk(KERN_WARNING
41333 "vesafb: cannot reserve video memory at 0x%lx\n",
41334@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
41335 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
41336 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
41337
41338+#ifdef __i386__
41339+
41340+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41341+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
41342+ if (!pmi_code)
41343+#elif !defined(CONFIG_PAX_KERNEXEC)
41344+ if (0)
41345+#endif
41346+
41347+#endif
41348+ screen_info.vesapm_seg = 0;
41349+
41350 if (screen_info.vesapm_seg) {
41351- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
41352- screen_info.vesapm_seg,screen_info.vesapm_off);
41353+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
41354+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
41355 }
41356
41357 if (screen_info.vesapm_seg < 0xc000)
41358@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
41359
41360 if (ypan || pmi_setpal) {
41361 unsigned short *pmi_base;
41362+
41363 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
41364- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
41365- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
41366+
41367+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41368+ pax_open_kernel();
41369+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
41370+#else
41371+ pmi_code = pmi_base;
41372+#endif
41373+
41374+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
41375+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
41376+
41377+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41378+ pmi_start = ktva_ktla(pmi_start);
41379+ pmi_pal = ktva_ktla(pmi_pal);
41380+ pax_close_kernel();
41381+#endif
41382+
41383 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
41384 if (pmi_base[3]) {
41385 printk(KERN_INFO "vesafb: pmi: ports = ");
41386@@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
41387 info->node, info->fix.id);
41388 return 0;
41389 err:
41390+
41391+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41392+ module_free_exec(NULL, pmi_code);
41393+#endif
41394+
41395 if (info->screen_base)
41396 iounmap(info->screen_base);
41397 framebuffer_release(info);
41398diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
41399index 88714ae..16c2e11 100644
41400--- a/drivers/video/via/via_clock.h
41401+++ b/drivers/video/via/via_clock.h
41402@@ -56,7 +56,7 @@ struct via_clock {
41403
41404 void (*set_engine_pll_state)(u8 state);
41405 void (*set_engine_pll)(struct via_pll_config config);
41406-};
41407+} __no_const;
41408
41409
41410 static inline u32 get_pll_internal_frequency(u32 ref_freq,
41411diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
41412index e56c934..fc22f4b 100644
41413--- a/drivers/xen/xen-pciback/conf_space.h
41414+++ b/drivers/xen/xen-pciback/conf_space.h
41415@@ -44,15 +44,15 @@ struct config_field {
41416 struct {
41417 conf_dword_write write;
41418 conf_dword_read read;
41419- } dw;
41420+ } __no_const dw;
41421 struct {
41422 conf_word_write write;
41423 conf_word_read read;
41424- } w;
41425+ } __no_const w;
41426 struct {
41427 conf_byte_write write;
41428 conf_byte_read read;
41429- } b;
41430+ } __no_const b;
41431 } u;
41432 struct list_head list;
41433 };
41434diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
41435index 014c8dd..6f3dfe6 100644
41436--- a/fs/9p/vfs_inode.c
41437+++ b/fs/9p/vfs_inode.c
41438@@ -1303,7 +1303,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
41439 void
41440 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
41441 {
41442- char *s = nd_get_link(nd);
41443+ const char *s = nd_get_link(nd);
41444
41445 p9_debug(P9_DEBUG_VFS, " %s %s\n",
41446 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
41447diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
41448index e95d1b6..3454244 100644
41449--- a/fs/Kconfig.binfmt
41450+++ b/fs/Kconfig.binfmt
41451@@ -89,7 +89,7 @@ config HAVE_AOUT
41452
41453 config BINFMT_AOUT
41454 tristate "Kernel support for a.out and ECOFF binaries"
41455- depends on HAVE_AOUT
41456+ depends on HAVE_AOUT && BROKEN
41457 ---help---
41458 A.out (Assembler.OUTput) is a set of formats for libraries and
41459 executables used in the earliest versions of UNIX. Linux used
41460diff --git a/fs/aio.c b/fs/aio.c
41461index e7f2fad..15ad8a4 100644
41462--- a/fs/aio.c
41463+++ b/fs/aio.c
41464@@ -118,7 +118,7 @@ static int aio_setup_ring(struct kioctx *ctx)
41465 size += sizeof(struct io_event) * nr_events;
41466 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
41467
41468- if (nr_pages < 0)
41469+ if (nr_pages <= 0)
41470 return -EINVAL;
41471
41472 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
41473@@ -1440,18 +1440,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
41474 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
41475 {
41476 ssize_t ret;
41477+ struct iovec iovstack;
41478
41479 #ifdef CONFIG_COMPAT
41480 if (compat)
41481 ret = compat_rw_copy_check_uvector(type,
41482 (struct compat_iovec __user *)kiocb->ki_buf,
41483- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
41484+ kiocb->ki_nbytes, 1, &iovstack,
41485 &kiocb->ki_iovec, 1);
41486 else
41487 #endif
41488 ret = rw_copy_check_uvector(type,
41489 (struct iovec __user *)kiocb->ki_buf,
41490- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
41491+ kiocb->ki_nbytes, 1, &iovstack,
41492 &kiocb->ki_iovec, 1);
41493 if (ret < 0)
41494 goto out;
41495@@ -1460,6 +1461,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
41496 if (ret < 0)
41497 goto out;
41498
41499+ if (kiocb->ki_iovec == &iovstack) {
41500+ kiocb->ki_inline_vec = iovstack;
41501+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
41502+ }
41503 kiocb->ki_nr_segs = kiocb->ki_nbytes;
41504 kiocb->ki_cur_seg = 0;
41505 /* ki_nbytes/left now reflect bytes instead of segs */
41506diff --git a/fs/attr.c b/fs/attr.c
41507index d94d1b6..f9bccd6 100644
41508--- a/fs/attr.c
41509+++ b/fs/attr.c
41510@@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
41511 unsigned long limit;
41512
41513 limit = rlimit(RLIMIT_FSIZE);
41514+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
41515 if (limit != RLIM_INFINITY && offset > limit)
41516 goto out_sig;
41517 if (offset > inode->i_sb->s_maxbytes)
41518diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
41519index da8876d..9f3e6d8 100644
41520--- a/fs/autofs4/waitq.c
41521+++ b/fs/autofs4/waitq.c
41522@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
41523 {
41524 unsigned long sigpipe, flags;
41525 mm_segment_t fs;
41526- const char *data = (const char *)addr;
41527+ const char __user *data = (const char __force_user *)addr;
41528 ssize_t wr = 0;
41529
41530 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
41531diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
41532index e18da23..affc30e 100644
41533--- a/fs/befs/linuxvfs.c
41534+++ b/fs/befs/linuxvfs.c
41535@@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
41536 {
41537 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
41538 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
41539- char *link = nd_get_link(nd);
41540+ const char *link = nd_get_link(nd);
41541 if (!IS_ERR(link))
41542 kfree(link);
41543 }
41544diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
41545index d146e18..12d1bd1 100644
41546--- a/fs/binfmt_aout.c
41547+++ b/fs/binfmt_aout.c
41548@@ -16,6 +16,7 @@
41549 #include <linux/string.h>
41550 #include <linux/fs.h>
41551 #include <linux/file.h>
41552+#include <linux/security.h>
41553 #include <linux/stat.h>
41554 #include <linux/fcntl.h>
41555 #include <linux/ptrace.h>
41556@@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
41557 #endif
41558 # define START_STACK(u) ((void __user *)u.start_stack)
41559
41560+ memset(&dump, 0, sizeof(dump));
41561+
41562 fs = get_fs();
41563 set_fs(KERNEL_DS);
41564 has_dumped = 1;
41565@@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
41566
41567 /* If the size of the dump file exceeds the rlimit, then see what would happen
41568 if we wrote the stack, but not the data area. */
41569+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
41570 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
41571 dump.u_dsize = 0;
41572
41573 /* Make sure we have enough room to write the stack and data areas. */
41574+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
41575 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
41576 dump.u_ssize = 0;
41577
41578@@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41579 rlim = rlimit(RLIMIT_DATA);
41580 if (rlim >= RLIM_INFINITY)
41581 rlim = ~0;
41582+
41583+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
41584 if (ex.a_data + ex.a_bss > rlim)
41585 return -ENOMEM;
41586
41587@@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41588
41589 install_exec_creds(bprm);
41590
41591+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
41592+ current->mm->pax_flags = 0UL;
41593+#endif
41594+
41595+#ifdef CONFIG_PAX_PAGEEXEC
41596+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
41597+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
41598+
41599+#ifdef CONFIG_PAX_EMUTRAMP
41600+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
41601+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
41602+#endif
41603+
41604+#ifdef CONFIG_PAX_MPROTECT
41605+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
41606+ current->mm->pax_flags |= MF_PAX_MPROTECT;
41607+#endif
41608+
41609+ }
41610+#endif
41611+
41612 if (N_MAGIC(ex) == OMAGIC) {
41613 unsigned long text_addr, map_size;
41614 loff_t pos;
41615@@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41616 }
41617
41618 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
41619- PROT_READ | PROT_WRITE | PROT_EXEC,
41620+ PROT_READ | PROT_WRITE,
41621 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
41622 fd_offset + ex.a_text);
41623 if (error != N_DATADDR(ex)) {
41624diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
41625index 16f7354..185d8dc 100644
41626--- a/fs/binfmt_elf.c
41627+++ b/fs/binfmt_elf.c
41628@@ -32,6 +32,7 @@
41629 #include <linux/elf.h>
41630 #include <linux/utsname.h>
41631 #include <linux/coredump.h>
41632+#include <linux/xattr.h>
41633 #include <asm/uaccess.h>
41634 #include <asm/param.h>
41635 #include <asm/page.h>
41636@@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
41637 #define elf_core_dump NULL
41638 #endif
41639
41640+#ifdef CONFIG_PAX_MPROTECT
41641+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
41642+#endif
41643+
41644 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
41645 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
41646 #else
41647@@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
41648 .load_binary = load_elf_binary,
41649 .load_shlib = load_elf_library,
41650 .core_dump = elf_core_dump,
41651+
41652+#ifdef CONFIG_PAX_MPROTECT
41653+ .handle_mprotect= elf_handle_mprotect,
41654+#endif
41655+
41656 .min_coredump = ELF_EXEC_PAGESIZE,
41657 };
41658
41659@@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
41660
41661 static int set_brk(unsigned long start, unsigned long end)
41662 {
41663+ unsigned long e = end;
41664+
41665 start = ELF_PAGEALIGN(start);
41666 end = ELF_PAGEALIGN(end);
41667 if (end > start) {
41668@@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
41669 if (BAD_ADDR(addr))
41670 return addr;
41671 }
41672- current->mm->start_brk = current->mm->brk = end;
41673+ current->mm->start_brk = current->mm->brk = e;
41674 return 0;
41675 }
41676
41677@@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
41678 elf_addr_t __user *u_rand_bytes;
41679 const char *k_platform = ELF_PLATFORM;
41680 const char *k_base_platform = ELF_BASE_PLATFORM;
41681- unsigned char k_rand_bytes[16];
41682+ u32 k_rand_bytes[4];
41683 int items;
41684 elf_addr_t *elf_info;
41685 int ei_index = 0;
41686 const struct cred *cred = current_cred();
41687 struct vm_area_struct *vma;
41688+ unsigned long saved_auxv[AT_VECTOR_SIZE];
41689
41690 /*
41691 * In some cases (e.g. Hyper-Threading), we want to avoid L1
41692@@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
41693 * Generate 16 random bytes for userspace PRNG seeding.
41694 */
41695 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
41696- u_rand_bytes = (elf_addr_t __user *)
41697- STACK_ALLOC(p, sizeof(k_rand_bytes));
41698+ srandom32(k_rand_bytes[0] ^ random32());
41699+ srandom32(k_rand_bytes[1] ^ random32());
41700+ srandom32(k_rand_bytes[2] ^ random32());
41701+ srandom32(k_rand_bytes[3] ^ random32());
41702+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
41703+ u_rand_bytes = (elf_addr_t __user *) p;
41704 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
41705 return -EFAULT;
41706
41707@@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
41708 return -EFAULT;
41709 current->mm->env_end = p;
41710
41711+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
41712+
41713 /* Put the elf_info on the stack in the right place. */
41714 sp = (elf_addr_t __user *)envp + 1;
41715- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
41716+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
41717 return -EFAULT;
41718 return 0;
41719 }
41720@@ -380,10 +399,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
41721 {
41722 struct elf_phdr *elf_phdata;
41723 struct elf_phdr *eppnt;
41724- unsigned long load_addr = 0;
41725+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
41726 int load_addr_set = 0;
41727 unsigned long last_bss = 0, elf_bss = 0;
41728- unsigned long error = ~0UL;
41729+ unsigned long error = -EINVAL;
41730 unsigned long total_size;
41731 int retval, i, size;
41732
41733@@ -429,6 +448,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
41734 goto out_close;
41735 }
41736
41737+#ifdef CONFIG_PAX_SEGMEXEC
41738+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
41739+ pax_task_size = SEGMEXEC_TASK_SIZE;
41740+#endif
41741+
41742 eppnt = elf_phdata;
41743 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
41744 if (eppnt->p_type == PT_LOAD) {
41745@@ -472,8 +496,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
41746 k = load_addr + eppnt->p_vaddr;
41747 if (BAD_ADDR(k) ||
41748 eppnt->p_filesz > eppnt->p_memsz ||
41749- eppnt->p_memsz > TASK_SIZE ||
41750- TASK_SIZE - eppnt->p_memsz < k) {
41751+ eppnt->p_memsz > pax_task_size ||
41752+ pax_task_size - eppnt->p_memsz < k) {
41753 error = -ENOMEM;
41754 goto out_close;
41755 }
41756@@ -525,6 +549,351 @@ out:
41757 return error;
41758 }
41759
41760+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
41761+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
41762+{
41763+ unsigned long pax_flags = 0UL;
41764+
41765+#ifdef CONFIG_PAX_PT_PAX_FLAGS
41766+
41767+#ifdef CONFIG_PAX_PAGEEXEC
41768+ if (elf_phdata->p_flags & PF_PAGEEXEC)
41769+ pax_flags |= MF_PAX_PAGEEXEC;
41770+#endif
41771+
41772+#ifdef CONFIG_PAX_SEGMEXEC
41773+ if (elf_phdata->p_flags & PF_SEGMEXEC)
41774+ pax_flags |= MF_PAX_SEGMEXEC;
41775+#endif
41776+
41777+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41778+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41779+ if ((__supported_pte_mask & _PAGE_NX))
41780+ pax_flags &= ~MF_PAX_SEGMEXEC;
41781+ else
41782+ pax_flags &= ~MF_PAX_PAGEEXEC;
41783+ }
41784+#endif
41785+
41786+#ifdef CONFIG_PAX_EMUTRAMP
41787+ if (elf_phdata->p_flags & PF_EMUTRAMP)
41788+ pax_flags |= MF_PAX_EMUTRAMP;
41789+#endif
41790+
41791+#ifdef CONFIG_PAX_MPROTECT
41792+ if (elf_phdata->p_flags & PF_MPROTECT)
41793+ pax_flags |= MF_PAX_MPROTECT;
41794+#endif
41795+
41796+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41797+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
41798+ pax_flags |= MF_PAX_RANDMMAP;
41799+#endif
41800+
41801+#endif
41802+
41803+ return pax_flags;
41804+}
41805+
41806+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
41807+{
41808+ unsigned long pax_flags = 0UL;
41809+
41810+#ifdef CONFIG_PAX_PT_PAX_FLAGS
41811+
41812+#ifdef CONFIG_PAX_PAGEEXEC
41813+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
41814+ pax_flags |= MF_PAX_PAGEEXEC;
41815+#endif
41816+
41817+#ifdef CONFIG_PAX_SEGMEXEC
41818+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
41819+ pax_flags |= MF_PAX_SEGMEXEC;
41820+#endif
41821+
41822+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41823+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41824+ if ((__supported_pte_mask & _PAGE_NX))
41825+ pax_flags &= ~MF_PAX_SEGMEXEC;
41826+ else
41827+ pax_flags &= ~MF_PAX_PAGEEXEC;
41828+ }
41829+#endif
41830+
41831+#ifdef CONFIG_PAX_EMUTRAMP
41832+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
41833+ pax_flags |= MF_PAX_EMUTRAMP;
41834+#endif
41835+
41836+#ifdef CONFIG_PAX_MPROTECT
41837+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
41838+ pax_flags |= MF_PAX_MPROTECT;
41839+#endif
41840+
41841+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41842+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
41843+ pax_flags |= MF_PAX_RANDMMAP;
41844+#endif
41845+
41846+#endif
41847+
41848+ return pax_flags;
41849+}
41850+
41851+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
41852+{
41853+ unsigned long pax_flags = 0UL;
41854+
41855+#ifdef CONFIG_PAX_EI_PAX
41856+
41857+#ifdef CONFIG_PAX_PAGEEXEC
41858+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
41859+ pax_flags |= MF_PAX_PAGEEXEC;
41860+#endif
41861+
41862+#ifdef CONFIG_PAX_SEGMEXEC
41863+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
41864+ pax_flags |= MF_PAX_SEGMEXEC;
41865+#endif
41866+
41867+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41868+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41869+ if ((__supported_pte_mask & _PAGE_NX))
41870+ pax_flags &= ~MF_PAX_SEGMEXEC;
41871+ else
41872+ pax_flags &= ~MF_PAX_PAGEEXEC;
41873+ }
41874+#endif
41875+
41876+#ifdef CONFIG_PAX_EMUTRAMP
41877+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
41878+ pax_flags |= MF_PAX_EMUTRAMP;
41879+#endif
41880+
41881+#ifdef CONFIG_PAX_MPROTECT
41882+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
41883+ pax_flags |= MF_PAX_MPROTECT;
41884+#endif
41885+
41886+#ifdef CONFIG_PAX_ASLR
41887+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
41888+ pax_flags |= MF_PAX_RANDMMAP;
41889+#endif
41890+
41891+#else
41892+
41893+#ifdef CONFIG_PAX_PAGEEXEC
41894+ pax_flags |= MF_PAX_PAGEEXEC;
41895+#endif
41896+
41897+#ifdef CONFIG_PAX_MPROTECT
41898+ pax_flags |= MF_PAX_MPROTECT;
41899+#endif
41900+
41901+#ifdef CONFIG_PAX_RANDMMAP
41902+ pax_flags |= MF_PAX_RANDMMAP;
41903+#endif
41904+
41905+#ifdef CONFIG_PAX_SEGMEXEC
41906+ if (!(pax_flags & MF_PAX_PAGEEXEC) || !(__supported_pte_mask & _PAGE_NX)) {
41907+ pax_flags &= ~MF_PAX_PAGEEXEC;
41908+ pax_flags |= MF_PAX_SEGMEXEC;
41909+ }
41910+#endif
41911+
41912+#endif
41913+
41914+ return pax_flags;
41915+}
41916+
41917+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
41918+{
41919+
41920+#ifdef CONFIG_PAX_PT_PAX_FLAGS
41921+ unsigned long i;
41922+
41923+ for (i = 0UL; i < elf_ex->e_phnum; i++)
41924+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
41925+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
41926+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
41927+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
41928+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
41929+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
41930+ return ~0UL;
41931+
41932+#ifdef CONFIG_PAX_SOFTMODE
41933+ if (pax_softmode)
41934+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
41935+ else
41936+#endif
41937+
41938+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
41939+ break;
41940+ }
41941+#endif
41942+
41943+ return ~0UL;
41944+}
41945+
41946+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
41947+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
41948+{
41949+ unsigned long pax_flags = 0UL;
41950+
41951+#ifdef CONFIG_PAX_PAGEEXEC
41952+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
41953+ pax_flags |= MF_PAX_PAGEEXEC;
41954+#endif
41955+
41956+#ifdef CONFIG_PAX_SEGMEXEC
41957+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
41958+ pax_flags |= MF_PAX_SEGMEXEC;
41959+#endif
41960+
41961+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41962+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41963+ if ((__supported_pte_mask & _PAGE_NX))
41964+ pax_flags &= ~MF_PAX_SEGMEXEC;
41965+ else
41966+ pax_flags &= ~MF_PAX_PAGEEXEC;
41967+ }
41968+#endif
41969+
41970+#ifdef CONFIG_PAX_EMUTRAMP
41971+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
41972+ pax_flags |= MF_PAX_EMUTRAMP;
41973+#endif
41974+
41975+#ifdef CONFIG_PAX_MPROTECT
41976+ if (pax_flags_softmode & MF_PAX_MPROTECT)
41977+ pax_flags |= MF_PAX_MPROTECT;
41978+#endif
41979+
41980+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41981+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
41982+ pax_flags |= MF_PAX_RANDMMAP;
41983+#endif
41984+
41985+ return pax_flags;
41986+}
41987+
41988+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
41989+{
41990+ unsigned long pax_flags = 0UL;
41991+
41992+#ifdef CONFIG_PAX_PAGEEXEC
41993+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
41994+ pax_flags |= MF_PAX_PAGEEXEC;
41995+#endif
41996+
41997+#ifdef CONFIG_PAX_SEGMEXEC
41998+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
41999+ pax_flags |= MF_PAX_SEGMEXEC;
42000+#endif
42001+
42002+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42003+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42004+ if ((__supported_pte_mask & _PAGE_NX))
42005+ pax_flags &= ~MF_PAX_SEGMEXEC;
42006+ else
42007+ pax_flags &= ~MF_PAX_PAGEEXEC;
42008+ }
42009+#endif
42010+
42011+#ifdef CONFIG_PAX_EMUTRAMP
42012+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
42013+ pax_flags |= MF_PAX_EMUTRAMP;
42014+#endif
42015+
42016+#ifdef CONFIG_PAX_MPROTECT
42017+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
42018+ pax_flags |= MF_PAX_MPROTECT;
42019+#endif
42020+
42021+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42022+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
42023+ pax_flags |= MF_PAX_RANDMMAP;
42024+#endif
42025+
42026+ return pax_flags;
42027+}
42028+#endif
42029+
42030+static unsigned long pax_parse_xattr_pax(struct file * const file)
42031+{
42032+
42033+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42034+ ssize_t xattr_size, i;
42035+ unsigned char xattr_value[5];
42036+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
42037+
42038+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
42039+ if (xattr_size <= 0)
42040+ return ~0UL;
42041+
42042+ for (i = 0; i < xattr_size; i++)
42043+ switch (xattr_value[i]) {
42044+ default:
42045+ return ~0UL;
42046+
42047+#define parse_flag(option1, option2, flag) \
42048+ case option1: \
42049+ pax_flags_hardmode |= MF_PAX_##flag; \
42050+ break; \
42051+ case option2: \
42052+ pax_flags_softmode |= MF_PAX_##flag; \
42053+ break;
42054+
42055+ parse_flag('p', 'P', PAGEEXEC);
42056+ parse_flag('e', 'E', EMUTRAMP);
42057+ parse_flag('m', 'M', MPROTECT);
42058+ parse_flag('r', 'R', RANDMMAP);
42059+ parse_flag('s', 'S', SEGMEXEC);
42060+
42061+#undef parse_flag
42062+ }
42063+
42064+ if (pax_flags_hardmode & pax_flags_softmode)
42065+ return ~0UL;
42066+
42067+#ifdef CONFIG_PAX_SOFTMODE
42068+ if (pax_softmode)
42069+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
42070+ else
42071+#endif
42072+
42073+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
42074+#else
42075+ return ~0UL;
42076+#endif
42077+
42078+}
42079+
42080+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
42081+{
42082+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
42083+
42084+ pax_flags = pax_parse_ei_pax(elf_ex);
42085+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
42086+ xattr_pax_flags = pax_parse_xattr_pax(file);
42087+
42088+ if (pt_pax_flags == ~0UL)
42089+ pt_pax_flags = xattr_pax_flags;
42090+ else if (xattr_pax_flags == ~0UL)
42091+ xattr_pax_flags = pt_pax_flags;
42092+ if (pt_pax_flags != xattr_pax_flags)
42093+ return -EINVAL;
42094+ if (pt_pax_flags != ~0UL)
42095+ pax_flags = pt_pax_flags;
42096+
42097+ if (0 > pax_check_flags(&pax_flags))
42098+ return -EINVAL;
42099+
42100+ current->mm->pax_flags = pax_flags;
42101+ return 0;
42102+}
42103+#endif
42104+
42105 /*
42106 * These are the functions used to load ELF style executables and shared
42107 * libraries. There is no binary dependent code anywhere else.
42108@@ -541,6 +910,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
42109 {
42110 unsigned int random_variable = 0;
42111
42112+#ifdef CONFIG_PAX_RANDUSTACK
42113+ if (randomize_va_space)
42114+ return stack_top - current->mm->delta_stack;
42115+#endif
42116+
42117 if ((current->flags & PF_RANDOMIZE) &&
42118 !(current->personality & ADDR_NO_RANDOMIZE)) {
42119 random_variable = get_random_int() & STACK_RND_MASK;
42120@@ -559,7 +933,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42121 unsigned long load_addr = 0, load_bias = 0;
42122 int load_addr_set = 0;
42123 char * elf_interpreter = NULL;
42124- unsigned long error;
42125+ unsigned long error = 0;
42126 struct elf_phdr *elf_ppnt, *elf_phdata;
42127 unsigned long elf_bss, elf_brk;
42128 int retval, i;
42129@@ -569,11 +943,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42130 unsigned long start_code, end_code, start_data, end_data;
42131 unsigned long reloc_func_desc __maybe_unused = 0;
42132 int executable_stack = EXSTACK_DEFAULT;
42133- unsigned long def_flags = 0;
42134 struct {
42135 struct elfhdr elf_ex;
42136 struct elfhdr interp_elf_ex;
42137 } *loc;
42138+ unsigned long pax_task_size = TASK_SIZE;
42139
42140 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
42141 if (!loc) {
42142@@ -709,11 +1083,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42143 goto out_free_dentry;
42144
42145 /* OK, This is the point of no return */
42146- current->mm->def_flags = def_flags;
42147+
42148+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42149+ current->mm->pax_flags = 0UL;
42150+#endif
42151+
42152+#ifdef CONFIG_PAX_DLRESOLVE
42153+ current->mm->call_dl_resolve = 0UL;
42154+#endif
42155+
42156+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
42157+ current->mm->call_syscall = 0UL;
42158+#endif
42159+
42160+#ifdef CONFIG_PAX_ASLR
42161+ current->mm->delta_mmap = 0UL;
42162+ current->mm->delta_stack = 0UL;
42163+#endif
42164+
42165+ current->mm->def_flags = 0;
42166+
42167+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
42168+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
42169+ send_sig(SIGKILL, current, 0);
42170+ goto out_free_dentry;
42171+ }
42172+#endif
42173+
42174+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
42175+ pax_set_initial_flags(bprm);
42176+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
42177+ if (pax_set_initial_flags_func)
42178+ (pax_set_initial_flags_func)(bprm);
42179+#endif
42180+
42181+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
42182+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
42183+ current->mm->context.user_cs_limit = PAGE_SIZE;
42184+ current->mm->def_flags |= VM_PAGEEXEC;
42185+ }
42186+#endif
42187+
42188+#ifdef CONFIG_PAX_SEGMEXEC
42189+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
42190+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
42191+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
42192+ pax_task_size = SEGMEXEC_TASK_SIZE;
42193+ current->mm->def_flags |= VM_NOHUGEPAGE;
42194+ }
42195+#endif
42196+
42197+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
42198+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42199+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
42200+ put_cpu();
42201+ }
42202+#endif
42203
42204 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
42205 may depend on the personality. */
42206 SET_PERSONALITY(loc->elf_ex);
42207+
42208+#ifdef CONFIG_PAX_ASLR
42209+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42210+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
42211+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
42212+ }
42213+#endif
42214+
42215+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
42216+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42217+ executable_stack = EXSTACK_DISABLE_X;
42218+ current->personality &= ~READ_IMPLIES_EXEC;
42219+ } else
42220+#endif
42221+
42222 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
42223 current->personality |= READ_IMPLIES_EXEC;
42224
42225@@ -804,6 +1248,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42226 #else
42227 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
42228 #endif
42229+
42230+#ifdef CONFIG_PAX_RANDMMAP
42231+ /* PaX: randomize base address at the default exe base if requested */
42232+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
42233+#ifdef CONFIG_SPARC64
42234+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
42235+#else
42236+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
42237+#endif
42238+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
42239+ elf_flags |= MAP_FIXED;
42240+ }
42241+#endif
42242+
42243 }
42244
42245 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
42246@@ -836,9 +1294,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42247 * allowed task size. Note that p_filesz must always be
42248 * <= p_memsz so it is only necessary to check p_memsz.
42249 */
42250- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42251- elf_ppnt->p_memsz > TASK_SIZE ||
42252- TASK_SIZE - elf_ppnt->p_memsz < k) {
42253+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42254+ elf_ppnt->p_memsz > pax_task_size ||
42255+ pax_task_size - elf_ppnt->p_memsz < k) {
42256 /* set_brk can never work. Avoid overflows. */
42257 send_sig(SIGKILL, current, 0);
42258 retval = -EINVAL;
42259@@ -877,11 +1335,40 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42260 goto out_free_dentry;
42261 }
42262 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
42263- send_sig(SIGSEGV, current, 0);
42264- retval = -EFAULT; /* Nobody gets to see this, but.. */
42265- goto out_free_dentry;
42266+ /*
42267+ * This bss-zeroing can fail if the ELF
42268+ * file specifies odd protections. So
42269+ * we don't check the return value
42270+ */
42271 }
42272
42273+#ifdef CONFIG_PAX_RANDMMAP
42274+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42275+ unsigned long start, size;
42276+
42277+ start = ELF_PAGEALIGN(elf_brk);
42278+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
42279+ down_write(&current->mm->mmap_sem);
42280+ retval = -ENOMEM;
42281+ if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
42282+ unsigned long prot = PROT_NONE;
42283+
42284+ current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
42285+// if (current->personality & ADDR_NO_RANDOMIZE)
42286+// prot = PROT_READ;
42287+ start = do_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
42288+ retval = IS_ERR_VALUE(start) ? start : 0;
42289+ }
42290+ up_write(&current->mm->mmap_sem);
42291+ if (retval == 0)
42292+ retval = set_brk(start + size, start + size + PAGE_SIZE);
42293+ if (retval < 0) {
42294+ send_sig(SIGKILL, current, 0);
42295+ goto out_free_dentry;
42296+ }
42297+ }
42298+#endif
42299+
42300 if (elf_interpreter) {
42301 unsigned long uninitialized_var(interp_map_addr);
42302
42303@@ -1109,7 +1596,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
42304 * Decide what to dump of a segment, part, all or none.
42305 */
42306 static unsigned long vma_dump_size(struct vm_area_struct *vma,
42307- unsigned long mm_flags)
42308+ unsigned long mm_flags, long signr)
42309 {
42310 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
42311
42312@@ -1146,7 +1633,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
42313 if (vma->vm_file == NULL)
42314 return 0;
42315
42316- if (FILTER(MAPPED_PRIVATE))
42317+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
42318 goto whole;
42319
42320 /*
42321@@ -1368,9 +1855,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
42322 {
42323 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
42324 int i = 0;
42325- do
42326+ do {
42327 i += 2;
42328- while (auxv[i - 2] != AT_NULL);
42329+ } while (auxv[i - 2] != AT_NULL);
42330 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
42331 }
42332
42333@@ -1892,14 +2379,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
42334 }
42335
42336 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
42337- unsigned long mm_flags)
42338+ struct coredump_params *cprm)
42339 {
42340 struct vm_area_struct *vma;
42341 size_t size = 0;
42342
42343 for (vma = first_vma(current, gate_vma); vma != NULL;
42344 vma = next_vma(vma, gate_vma))
42345- size += vma_dump_size(vma, mm_flags);
42346+ size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42347 return size;
42348 }
42349
42350@@ -1993,7 +2480,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42351
42352 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
42353
42354- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
42355+ offset += elf_core_vma_data_size(gate_vma, cprm);
42356 offset += elf_core_extra_data_size();
42357 e_shoff = offset;
42358
42359@@ -2007,10 +2494,12 @@ static int elf_core_dump(struct coredump_params *cprm)
42360 offset = dataoff;
42361
42362 size += sizeof(*elf);
42363+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
42364 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
42365 goto end_coredump;
42366
42367 size += sizeof(*phdr4note);
42368+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
42369 if (size > cprm->limit
42370 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
42371 goto end_coredump;
42372@@ -2024,7 +2513,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42373 phdr.p_offset = offset;
42374 phdr.p_vaddr = vma->vm_start;
42375 phdr.p_paddr = 0;
42376- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
42377+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42378 phdr.p_memsz = vma->vm_end - vma->vm_start;
42379 offset += phdr.p_filesz;
42380 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
42381@@ -2035,6 +2524,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42382 phdr.p_align = ELF_EXEC_PAGESIZE;
42383
42384 size += sizeof(phdr);
42385+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
42386 if (size > cprm->limit
42387 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
42388 goto end_coredump;
42389@@ -2059,7 +2549,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42390 unsigned long addr;
42391 unsigned long end;
42392
42393- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
42394+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42395
42396 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
42397 struct page *page;
42398@@ -2068,6 +2558,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42399 page = get_dump_page(addr);
42400 if (page) {
42401 void *kaddr = kmap(page);
42402+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
42403 stop = ((size += PAGE_SIZE) > cprm->limit) ||
42404 !dump_write(cprm->file, kaddr,
42405 PAGE_SIZE);
42406@@ -2085,6 +2576,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42407
42408 if (e_phnum == PN_XNUM) {
42409 size += sizeof(*shdr4extnum);
42410+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
42411 if (size > cprm->limit
42412 || !dump_write(cprm->file, shdr4extnum,
42413 sizeof(*shdr4extnum)))
42414@@ -2105,6 +2597,97 @@ out:
42415
42416 #endif /* CONFIG_ELF_CORE */
42417
42418+#ifdef CONFIG_PAX_MPROTECT
42419+/* PaX: non-PIC ELF libraries need relocations on their executable segments
42420+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
42421+ * we'll remove VM_MAYWRITE for good on RELRO segments.
42422+ *
42423+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
42424+ * basis because we want to allow the common case and not the special ones.
42425+ */
42426+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
42427+{
42428+ struct elfhdr elf_h;
42429+ struct elf_phdr elf_p;
42430+ unsigned long i;
42431+ unsigned long oldflags;
42432+ bool is_textrel_rw, is_textrel_rx, is_relro;
42433+
42434+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
42435+ return;
42436+
42437+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
42438+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
42439+
42440+#ifdef CONFIG_PAX_ELFRELOCS
42441+ /* possible TEXTREL */
42442+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
42443+ 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);
42444+#else
42445+ is_textrel_rw = false;
42446+ is_textrel_rx = false;
42447+#endif
42448+
42449+ /* possible RELRO */
42450+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
42451+
42452+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
42453+ return;
42454+
42455+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
42456+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
42457+
42458+#ifdef CONFIG_PAX_ETEXECRELOCS
42459+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
42460+#else
42461+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
42462+#endif
42463+
42464+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
42465+ !elf_check_arch(&elf_h) ||
42466+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
42467+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
42468+ return;
42469+
42470+ for (i = 0UL; i < elf_h.e_phnum; i++) {
42471+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
42472+ return;
42473+ switch (elf_p.p_type) {
42474+ case PT_DYNAMIC:
42475+ if (!is_textrel_rw && !is_textrel_rx)
42476+ continue;
42477+ i = 0UL;
42478+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
42479+ elf_dyn dyn;
42480+
42481+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
42482+ return;
42483+ if (dyn.d_tag == DT_NULL)
42484+ return;
42485+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
42486+ gr_log_textrel(vma);
42487+ if (is_textrel_rw)
42488+ vma->vm_flags |= VM_MAYWRITE;
42489+ else
42490+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
42491+ vma->vm_flags &= ~VM_MAYWRITE;
42492+ return;
42493+ }
42494+ i++;
42495+ }
42496+ return;
42497+
42498+ case PT_GNU_RELRO:
42499+ if (!is_relro)
42500+ continue;
42501+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
42502+ vma->vm_flags &= ~VM_MAYWRITE;
42503+ return;
42504+ }
42505+ }
42506+}
42507+#endif
42508+
42509 static int __init init_elf_binfmt(void)
42510 {
42511 register_binfmt(&elf_format);
42512diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
42513index 6b2daf9..a70dccb 100644
42514--- a/fs/binfmt_flat.c
42515+++ b/fs/binfmt_flat.c
42516@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
42517 realdatastart = (unsigned long) -ENOMEM;
42518 printk("Unable to allocate RAM for process data, errno %d\n",
42519 (int)-realdatastart);
42520+ down_write(&current->mm->mmap_sem);
42521 do_munmap(current->mm, textpos, text_len);
42522+ up_write(&current->mm->mmap_sem);
42523 ret = realdatastart;
42524 goto err;
42525 }
42526@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
42527 }
42528 if (IS_ERR_VALUE(result)) {
42529 printk("Unable to read data+bss, errno %d\n", (int)-result);
42530+ down_write(&current->mm->mmap_sem);
42531 do_munmap(current->mm, textpos, text_len);
42532 do_munmap(current->mm, realdatastart, len);
42533+ up_write(&current->mm->mmap_sem);
42534 ret = result;
42535 goto err;
42536 }
42537@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
42538 }
42539 if (IS_ERR_VALUE(result)) {
42540 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
42541+ down_write(&current->mm->mmap_sem);
42542 do_munmap(current->mm, textpos, text_len + data_len + extra +
42543 MAX_SHARED_LIBS * sizeof(unsigned long));
42544+ up_write(&current->mm->mmap_sem);
42545 ret = result;
42546 goto err;
42547 }
42548diff --git a/fs/bio.c b/fs/bio.c
42549index 84da885..2149cd9 100644
42550--- a/fs/bio.c
42551+++ b/fs/bio.c
42552@@ -838,7 +838,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
42553 /*
42554 * Overflow, abort
42555 */
42556- if (end < start)
42557+ if (end < start || end - start > INT_MAX - nr_pages)
42558 return ERR_PTR(-EINVAL);
42559
42560 nr_pages += end - start;
42561@@ -1234,7 +1234,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
42562 const int read = bio_data_dir(bio) == READ;
42563 struct bio_map_data *bmd = bio->bi_private;
42564 int i;
42565- char *p = bmd->sgvecs[0].iov_base;
42566+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
42567
42568 __bio_for_each_segment(bvec, bio, i, 0) {
42569 char *addr = page_address(bvec->bv_page);
42570diff --git a/fs/block_dev.c b/fs/block_dev.c
42571index ba11c30..623d736 100644
42572--- a/fs/block_dev.c
42573+++ b/fs/block_dev.c
42574@@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
42575 else if (bdev->bd_contains == bdev)
42576 return true; /* is a whole device which isn't held */
42577
42578- else if (whole->bd_holder == bd_may_claim)
42579+ else if (whole->bd_holder == (void *)bd_may_claim)
42580 return true; /* is a partition of a device that is being partitioned */
42581 else if (whole->bd_holder != NULL)
42582 return false; /* is a partition of a held device */
42583diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
42584index c053e90..e5f1afc 100644
42585--- a/fs/btrfs/check-integrity.c
42586+++ b/fs/btrfs/check-integrity.c
42587@@ -156,7 +156,7 @@ struct btrfsic_block {
42588 union {
42589 bio_end_io_t *bio;
42590 bh_end_io_t *bh;
42591- } orig_bio_bh_end_io;
42592+ } __no_const orig_bio_bh_end_io;
42593 int submit_bio_bh_rw;
42594 u64 flush_gen; /* only valid if !never_written */
42595 };
42596diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
42597index 4106264..8157ede 100644
42598--- a/fs/btrfs/ctree.c
42599+++ b/fs/btrfs/ctree.c
42600@@ -513,9 +513,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
42601 free_extent_buffer(buf);
42602 add_root_to_dirty_list(root);
42603 } else {
42604- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
42605- parent_start = parent->start;
42606- else
42607+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
42608+ if (parent)
42609+ parent_start = parent->start;
42610+ else
42611+ parent_start = 0;
42612+ } else
42613 parent_start = 0;
42614
42615 WARN_ON(trans->transid != btrfs_header_generation(parent));
42616diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
42617index 0df0d1f..4bdcbfe 100644
42618--- a/fs/btrfs/inode.c
42619+++ b/fs/btrfs/inode.c
42620@@ -7074,7 +7074,7 @@ fail:
42621 return -ENOMEM;
42622 }
42623
42624-static int btrfs_getattr(struct vfsmount *mnt,
42625+int btrfs_getattr(struct vfsmount *mnt,
42626 struct dentry *dentry, struct kstat *stat)
42627 {
42628 struct inode *inode = dentry->d_inode;
42629@@ -7088,6 +7088,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
42630 return 0;
42631 }
42632
42633+EXPORT_SYMBOL(btrfs_getattr);
42634+
42635+dev_t get_btrfs_dev_from_inode(struct inode *inode)
42636+{
42637+ return BTRFS_I(inode)->root->anon_dev;
42638+}
42639+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
42640+
42641 /*
42642 * If a file is moved, it will inherit the cow and compression flags of the new
42643 * directory.
42644diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
42645index 14f8e1f..ab8d81f 100644
42646--- a/fs/btrfs/ioctl.c
42647+++ b/fs/btrfs/ioctl.c
42648@@ -2882,9 +2882,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
42649 for (i = 0; i < num_types; i++) {
42650 struct btrfs_space_info *tmp;
42651
42652+ /* Don't copy in more than we allocated */
42653 if (!slot_count)
42654 break;
42655
42656+ slot_count--;
42657+
42658 info = NULL;
42659 rcu_read_lock();
42660 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
42661@@ -2906,15 +2909,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
42662 memcpy(dest, &space, sizeof(space));
42663 dest++;
42664 space_args.total_spaces++;
42665- slot_count--;
42666 }
42667- if (!slot_count)
42668- break;
42669 }
42670 up_read(&info->groups_sem);
42671 }
42672
42673- user_dest = (struct btrfs_ioctl_space_info *)
42674+ user_dest = (struct btrfs_ioctl_space_info __user *)
42675 (arg + sizeof(struct btrfs_ioctl_space_args));
42676
42677 if (copy_to_user(user_dest, dest_orig, alloc_size))
42678diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
42679index 646ee21..f020f87 100644
42680--- a/fs/btrfs/relocation.c
42681+++ b/fs/btrfs/relocation.c
42682@@ -1268,7 +1268,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
42683 }
42684 spin_unlock(&rc->reloc_root_tree.lock);
42685
42686- BUG_ON((struct btrfs_root *)node->data != root);
42687+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
42688
42689 if (!del) {
42690 spin_lock(&rc->reloc_root_tree.lock);
42691diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
42692index 622f469..e8d2d55 100644
42693--- a/fs/cachefiles/bind.c
42694+++ b/fs/cachefiles/bind.c
42695@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
42696 args);
42697
42698 /* start by checking things over */
42699- ASSERT(cache->fstop_percent >= 0 &&
42700- cache->fstop_percent < cache->fcull_percent &&
42701+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
42702 cache->fcull_percent < cache->frun_percent &&
42703 cache->frun_percent < 100);
42704
42705- ASSERT(cache->bstop_percent >= 0 &&
42706- cache->bstop_percent < cache->bcull_percent &&
42707+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
42708 cache->bcull_percent < cache->brun_percent &&
42709 cache->brun_percent < 100);
42710
42711diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
42712index 0a1467b..6a53245 100644
42713--- a/fs/cachefiles/daemon.c
42714+++ b/fs/cachefiles/daemon.c
42715@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
42716 if (n > buflen)
42717 return -EMSGSIZE;
42718
42719- if (copy_to_user(_buffer, buffer, n) != 0)
42720+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
42721 return -EFAULT;
42722
42723 return n;
42724@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
42725 if (test_bit(CACHEFILES_DEAD, &cache->flags))
42726 return -EIO;
42727
42728- if (datalen < 0 || datalen > PAGE_SIZE - 1)
42729+ if (datalen > PAGE_SIZE - 1)
42730 return -EOPNOTSUPP;
42731
42732 /* drag the command string into the kernel so we can parse it */
42733@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
42734 if (args[0] != '%' || args[1] != '\0')
42735 return -EINVAL;
42736
42737- if (fstop < 0 || fstop >= cache->fcull_percent)
42738+ if (fstop >= cache->fcull_percent)
42739 return cachefiles_daemon_range_error(cache, args);
42740
42741 cache->fstop_percent = fstop;
42742@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
42743 if (args[0] != '%' || args[1] != '\0')
42744 return -EINVAL;
42745
42746- if (bstop < 0 || bstop >= cache->bcull_percent)
42747+ if (bstop >= cache->bcull_percent)
42748 return cachefiles_daemon_range_error(cache, args);
42749
42750 cache->bstop_percent = bstop;
42751diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
42752index bd6bc1b..b627b53 100644
42753--- a/fs/cachefiles/internal.h
42754+++ b/fs/cachefiles/internal.h
42755@@ -57,7 +57,7 @@ struct cachefiles_cache {
42756 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
42757 struct rb_root active_nodes; /* active nodes (can't be culled) */
42758 rwlock_t active_lock; /* lock for active_nodes */
42759- atomic_t gravecounter; /* graveyard uniquifier */
42760+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
42761 unsigned frun_percent; /* when to stop culling (% files) */
42762 unsigned fcull_percent; /* when to start culling (% files) */
42763 unsigned fstop_percent; /* when to stop allocating (% files) */
42764@@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
42765 * proc.c
42766 */
42767 #ifdef CONFIG_CACHEFILES_HISTOGRAM
42768-extern atomic_t cachefiles_lookup_histogram[HZ];
42769-extern atomic_t cachefiles_mkdir_histogram[HZ];
42770-extern atomic_t cachefiles_create_histogram[HZ];
42771+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
42772+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
42773+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
42774
42775 extern int __init cachefiles_proc_init(void);
42776 extern void cachefiles_proc_cleanup(void);
42777 static inline
42778-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
42779+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
42780 {
42781 unsigned long jif = jiffies - start_jif;
42782 if (jif >= HZ)
42783 jif = HZ - 1;
42784- atomic_inc(&histogram[jif]);
42785+ atomic_inc_unchecked(&histogram[jif]);
42786 }
42787
42788 #else
42789diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
42790index 7f0771d..87d4f36 100644
42791--- a/fs/cachefiles/namei.c
42792+++ b/fs/cachefiles/namei.c
42793@@ -318,7 +318,7 @@ try_again:
42794 /* first step is to make up a grave dentry in the graveyard */
42795 sprintf(nbuffer, "%08x%08x",
42796 (uint32_t) get_seconds(),
42797- (uint32_t) atomic_inc_return(&cache->gravecounter));
42798+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
42799
42800 /* do the multiway lock magic */
42801 trap = lock_rename(cache->graveyard, dir);
42802diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
42803index eccd339..4c1d995 100644
42804--- a/fs/cachefiles/proc.c
42805+++ b/fs/cachefiles/proc.c
42806@@ -14,9 +14,9 @@
42807 #include <linux/seq_file.h>
42808 #include "internal.h"
42809
42810-atomic_t cachefiles_lookup_histogram[HZ];
42811-atomic_t cachefiles_mkdir_histogram[HZ];
42812-atomic_t cachefiles_create_histogram[HZ];
42813+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
42814+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
42815+atomic_unchecked_t cachefiles_create_histogram[HZ];
42816
42817 /*
42818 * display the latency histogram
42819@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
42820 return 0;
42821 default:
42822 index = (unsigned long) v - 3;
42823- x = atomic_read(&cachefiles_lookup_histogram[index]);
42824- y = atomic_read(&cachefiles_mkdir_histogram[index]);
42825- z = atomic_read(&cachefiles_create_histogram[index]);
42826+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
42827+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
42828+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
42829 if (x == 0 && y == 0 && z == 0)
42830 return 0;
42831
42832diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
42833index 0e3c092..818480e 100644
42834--- a/fs/cachefiles/rdwr.c
42835+++ b/fs/cachefiles/rdwr.c
42836@@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
42837 old_fs = get_fs();
42838 set_fs(KERNEL_DS);
42839 ret = file->f_op->write(
42840- file, (const void __user *) data, len, &pos);
42841+ file, (const void __force_user *) data, len, &pos);
42842 set_fs(old_fs);
42843 kunmap(page);
42844 if (ret != len)
42845diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
42846index 3e8094b..cb3ff3d 100644
42847--- a/fs/ceph/dir.c
42848+++ b/fs/ceph/dir.c
42849@@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
42850 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
42851 struct ceph_mds_client *mdsc = fsc->mdsc;
42852 unsigned frag = fpos_frag(filp->f_pos);
42853- int off = fpos_off(filp->f_pos);
42854+ unsigned int off = fpos_off(filp->f_pos);
42855 int err;
42856 u32 ftype;
42857 struct ceph_mds_reply_info_parsed *rinfo;
42858@@ -598,7 +598,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
42859 if (nd &&
42860 (nd->flags & LOOKUP_OPEN) &&
42861 !(nd->intent.open.flags & O_CREAT)) {
42862- int mode = nd->intent.open.create_mode & ~current->fs->umask;
42863+ int mode = nd->intent.open.create_mode & ~current_umask();
42864 return ceph_lookup_open(dir, dentry, nd, mode, 1);
42865 }
42866
42867diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
42868index 2704646..c581c91 100644
42869--- a/fs/cifs/cifs_debug.c
42870+++ b/fs/cifs/cifs_debug.c
42871@@ -265,8 +265,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
42872
42873 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
42874 #ifdef CONFIG_CIFS_STATS2
42875- atomic_set(&totBufAllocCount, 0);
42876- atomic_set(&totSmBufAllocCount, 0);
42877+ atomic_set_unchecked(&totBufAllocCount, 0);
42878+ atomic_set_unchecked(&totSmBufAllocCount, 0);
42879 #endif /* CONFIG_CIFS_STATS2 */
42880 spin_lock(&cifs_tcp_ses_lock);
42881 list_for_each(tmp1, &cifs_tcp_ses_list) {
42882@@ -279,25 +279,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
42883 tcon = list_entry(tmp3,
42884 struct cifs_tcon,
42885 tcon_list);
42886- atomic_set(&tcon->num_smbs_sent, 0);
42887- atomic_set(&tcon->num_writes, 0);
42888- atomic_set(&tcon->num_reads, 0);
42889- atomic_set(&tcon->num_oplock_brks, 0);
42890- atomic_set(&tcon->num_opens, 0);
42891- atomic_set(&tcon->num_posixopens, 0);
42892- atomic_set(&tcon->num_posixmkdirs, 0);
42893- atomic_set(&tcon->num_closes, 0);
42894- atomic_set(&tcon->num_deletes, 0);
42895- atomic_set(&tcon->num_mkdirs, 0);
42896- atomic_set(&tcon->num_rmdirs, 0);
42897- atomic_set(&tcon->num_renames, 0);
42898- atomic_set(&tcon->num_t2renames, 0);
42899- atomic_set(&tcon->num_ffirst, 0);
42900- atomic_set(&tcon->num_fnext, 0);
42901- atomic_set(&tcon->num_fclose, 0);
42902- atomic_set(&tcon->num_hardlinks, 0);
42903- atomic_set(&tcon->num_symlinks, 0);
42904- atomic_set(&tcon->num_locks, 0);
42905+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
42906+ atomic_set_unchecked(&tcon->num_writes, 0);
42907+ atomic_set_unchecked(&tcon->num_reads, 0);
42908+ atomic_set_unchecked(&tcon->num_oplock_brks, 0);
42909+ atomic_set_unchecked(&tcon->num_opens, 0);
42910+ atomic_set_unchecked(&tcon->num_posixopens, 0);
42911+ atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
42912+ atomic_set_unchecked(&tcon->num_closes, 0);
42913+ atomic_set_unchecked(&tcon->num_deletes, 0);
42914+ atomic_set_unchecked(&tcon->num_mkdirs, 0);
42915+ atomic_set_unchecked(&tcon->num_rmdirs, 0);
42916+ atomic_set_unchecked(&tcon->num_renames, 0);
42917+ atomic_set_unchecked(&tcon->num_t2renames, 0);
42918+ atomic_set_unchecked(&tcon->num_ffirst, 0);
42919+ atomic_set_unchecked(&tcon->num_fnext, 0);
42920+ atomic_set_unchecked(&tcon->num_fclose, 0);
42921+ atomic_set_unchecked(&tcon->num_hardlinks, 0);
42922+ atomic_set_unchecked(&tcon->num_symlinks, 0);
42923+ atomic_set_unchecked(&tcon->num_locks, 0);
42924 }
42925 }
42926 }
42927@@ -327,8 +327,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
42928 smBufAllocCount.counter, cifs_min_small);
42929 #ifdef CONFIG_CIFS_STATS2
42930 seq_printf(m, "Total Large %d Small %d Allocations\n",
42931- atomic_read(&totBufAllocCount),
42932- atomic_read(&totSmBufAllocCount));
42933+ atomic_read_unchecked(&totBufAllocCount),
42934+ atomic_read_unchecked(&totSmBufAllocCount));
42935 #endif /* CONFIG_CIFS_STATS2 */
42936
42937 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
42938@@ -357,41 +357,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
42939 if (tcon->need_reconnect)
42940 seq_puts(m, "\tDISCONNECTED ");
42941 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
42942- atomic_read(&tcon->num_smbs_sent),
42943- atomic_read(&tcon->num_oplock_brks));
42944+ atomic_read_unchecked(&tcon->num_smbs_sent),
42945+ atomic_read_unchecked(&tcon->num_oplock_brks));
42946 seq_printf(m, "\nReads: %d Bytes: %lld",
42947- atomic_read(&tcon->num_reads),
42948+ atomic_read_unchecked(&tcon->num_reads),
42949 (long long)(tcon->bytes_read));
42950 seq_printf(m, "\nWrites: %d Bytes: %lld",
42951- atomic_read(&tcon->num_writes),
42952+ atomic_read_unchecked(&tcon->num_writes),
42953 (long long)(tcon->bytes_written));
42954 seq_printf(m, "\nFlushes: %d",
42955- atomic_read(&tcon->num_flushes));
42956+ atomic_read_unchecked(&tcon->num_flushes));
42957 seq_printf(m, "\nLocks: %d HardLinks: %d "
42958 "Symlinks: %d",
42959- atomic_read(&tcon->num_locks),
42960- atomic_read(&tcon->num_hardlinks),
42961- atomic_read(&tcon->num_symlinks));
42962+ atomic_read_unchecked(&tcon->num_locks),
42963+ atomic_read_unchecked(&tcon->num_hardlinks),
42964+ atomic_read_unchecked(&tcon->num_symlinks));
42965 seq_printf(m, "\nOpens: %d Closes: %d "
42966 "Deletes: %d",
42967- atomic_read(&tcon->num_opens),
42968- atomic_read(&tcon->num_closes),
42969- atomic_read(&tcon->num_deletes));
42970+ atomic_read_unchecked(&tcon->num_opens),
42971+ atomic_read_unchecked(&tcon->num_closes),
42972+ atomic_read_unchecked(&tcon->num_deletes));
42973 seq_printf(m, "\nPosix Opens: %d "
42974 "Posix Mkdirs: %d",
42975- atomic_read(&tcon->num_posixopens),
42976- atomic_read(&tcon->num_posixmkdirs));
42977+ atomic_read_unchecked(&tcon->num_posixopens),
42978+ atomic_read_unchecked(&tcon->num_posixmkdirs));
42979 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
42980- atomic_read(&tcon->num_mkdirs),
42981- atomic_read(&tcon->num_rmdirs));
42982+ atomic_read_unchecked(&tcon->num_mkdirs),
42983+ atomic_read_unchecked(&tcon->num_rmdirs));
42984 seq_printf(m, "\nRenames: %d T2 Renames %d",
42985- atomic_read(&tcon->num_renames),
42986- atomic_read(&tcon->num_t2renames));
42987+ atomic_read_unchecked(&tcon->num_renames),
42988+ atomic_read_unchecked(&tcon->num_t2renames));
42989 seq_printf(m, "\nFindFirst: %d FNext %d "
42990 "FClose %d",
42991- atomic_read(&tcon->num_ffirst),
42992- atomic_read(&tcon->num_fnext),
42993- atomic_read(&tcon->num_fclose));
42994+ atomic_read_unchecked(&tcon->num_ffirst),
42995+ atomic_read_unchecked(&tcon->num_fnext),
42996+ atomic_read_unchecked(&tcon->num_fclose));
42997 }
42998 }
42999 }
43000diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
43001index 541ef81..a78deb8 100644
43002--- a/fs/cifs/cifsfs.c
43003+++ b/fs/cifs/cifsfs.c
43004@@ -985,7 +985,7 @@ cifs_init_request_bufs(void)
43005 cifs_req_cachep = kmem_cache_create("cifs_request",
43006 CIFSMaxBufSize +
43007 MAX_CIFS_HDR_SIZE, 0,
43008- SLAB_HWCACHE_ALIGN, NULL);
43009+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
43010 if (cifs_req_cachep == NULL)
43011 return -ENOMEM;
43012
43013@@ -1012,7 +1012,7 @@ cifs_init_request_bufs(void)
43014 efficient to alloc 1 per page off the slab compared to 17K (5page)
43015 alloc of large cifs buffers even when page debugging is on */
43016 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
43017- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
43018+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
43019 NULL);
43020 if (cifs_sm_req_cachep == NULL) {
43021 mempool_destroy(cifs_req_poolp);
43022@@ -1097,8 +1097,8 @@ init_cifs(void)
43023 atomic_set(&bufAllocCount, 0);
43024 atomic_set(&smBufAllocCount, 0);
43025 #ifdef CONFIG_CIFS_STATS2
43026- atomic_set(&totBufAllocCount, 0);
43027- atomic_set(&totSmBufAllocCount, 0);
43028+ atomic_set_unchecked(&totBufAllocCount, 0);
43029+ atomic_set_unchecked(&totSmBufAllocCount, 0);
43030 #endif /* CONFIG_CIFS_STATS2 */
43031
43032 atomic_set(&midCount, 0);
43033diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
43034index 73fea28..b996b84 100644
43035--- a/fs/cifs/cifsglob.h
43036+++ b/fs/cifs/cifsglob.h
43037@@ -439,28 +439,28 @@ struct cifs_tcon {
43038 __u16 Flags; /* optional support bits */
43039 enum statusEnum tidStatus;
43040 #ifdef CONFIG_CIFS_STATS
43041- atomic_t num_smbs_sent;
43042- atomic_t num_writes;
43043- atomic_t num_reads;
43044- atomic_t num_flushes;
43045- atomic_t num_oplock_brks;
43046- atomic_t num_opens;
43047- atomic_t num_closes;
43048- atomic_t num_deletes;
43049- atomic_t num_mkdirs;
43050- atomic_t num_posixopens;
43051- atomic_t num_posixmkdirs;
43052- atomic_t num_rmdirs;
43053- atomic_t num_renames;
43054- atomic_t num_t2renames;
43055- atomic_t num_ffirst;
43056- atomic_t num_fnext;
43057- atomic_t num_fclose;
43058- atomic_t num_hardlinks;
43059- atomic_t num_symlinks;
43060- atomic_t num_locks;
43061- atomic_t num_acl_get;
43062- atomic_t num_acl_set;
43063+ atomic_unchecked_t num_smbs_sent;
43064+ atomic_unchecked_t num_writes;
43065+ atomic_unchecked_t num_reads;
43066+ atomic_unchecked_t num_flushes;
43067+ atomic_unchecked_t num_oplock_brks;
43068+ atomic_unchecked_t num_opens;
43069+ atomic_unchecked_t num_closes;
43070+ atomic_unchecked_t num_deletes;
43071+ atomic_unchecked_t num_mkdirs;
43072+ atomic_unchecked_t num_posixopens;
43073+ atomic_unchecked_t num_posixmkdirs;
43074+ atomic_unchecked_t num_rmdirs;
43075+ atomic_unchecked_t num_renames;
43076+ atomic_unchecked_t num_t2renames;
43077+ atomic_unchecked_t num_ffirst;
43078+ atomic_unchecked_t num_fnext;
43079+ atomic_unchecked_t num_fclose;
43080+ atomic_unchecked_t num_hardlinks;
43081+ atomic_unchecked_t num_symlinks;
43082+ atomic_unchecked_t num_locks;
43083+ atomic_unchecked_t num_acl_get;
43084+ atomic_unchecked_t num_acl_set;
43085 #ifdef CONFIG_CIFS_STATS2
43086 unsigned long long time_writes;
43087 unsigned long long time_reads;
43088@@ -677,7 +677,7 @@ convert_delimiter(char *path, char delim)
43089 }
43090
43091 #ifdef CONFIG_CIFS_STATS
43092-#define cifs_stats_inc atomic_inc
43093+#define cifs_stats_inc atomic_inc_unchecked
43094
43095 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
43096 unsigned int bytes)
43097@@ -1036,8 +1036,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
43098 /* Various Debug counters */
43099 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
43100 #ifdef CONFIG_CIFS_STATS2
43101-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
43102-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
43103+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
43104+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
43105 #endif
43106 GLOBAL_EXTERN atomic_t smBufAllocCount;
43107 GLOBAL_EXTERN atomic_t midCount;
43108diff --git a/fs/cifs/link.c b/fs/cifs/link.c
43109index 6b0e064..94e6c3c 100644
43110--- a/fs/cifs/link.c
43111+++ b/fs/cifs/link.c
43112@@ -600,7 +600,7 @@ symlink_exit:
43113
43114 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
43115 {
43116- char *p = nd_get_link(nd);
43117+ const char *p = nd_get_link(nd);
43118 if (!IS_ERR(p))
43119 kfree(p);
43120 }
43121diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
43122index c29d1aa..58018da 100644
43123--- a/fs/cifs/misc.c
43124+++ b/fs/cifs/misc.c
43125@@ -156,7 +156,7 @@ cifs_buf_get(void)
43126 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
43127 atomic_inc(&bufAllocCount);
43128 #ifdef CONFIG_CIFS_STATS2
43129- atomic_inc(&totBufAllocCount);
43130+ atomic_inc_unchecked(&totBufAllocCount);
43131 #endif /* CONFIG_CIFS_STATS2 */
43132 }
43133
43134@@ -191,7 +191,7 @@ cifs_small_buf_get(void)
43135 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
43136 atomic_inc(&smBufAllocCount);
43137 #ifdef CONFIG_CIFS_STATS2
43138- atomic_inc(&totSmBufAllocCount);
43139+ atomic_inc_unchecked(&totSmBufAllocCount);
43140 #endif /* CONFIG_CIFS_STATS2 */
43141
43142 }
43143diff --git a/fs/coda/cache.c b/fs/coda/cache.c
43144index 6901578..d402eb5 100644
43145--- a/fs/coda/cache.c
43146+++ b/fs/coda/cache.c
43147@@ -24,7 +24,7 @@
43148 #include "coda_linux.h"
43149 #include "coda_cache.h"
43150
43151-static atomic_t permission_epoch = ATOMIC_INIT(0);
43152+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
43153
43154 /* replace or extend an acl cache hit */
43155 void coda_cache_enter(struct inode *inode, int mask)
43156@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
43157 struct coda_inode_info *cii = ITOC(inode);
43158
43159 spin_lock(&cii->c_lock);
43160- cii->c_cached_epoch = atomic_read(&permission_epoch);
43161+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
43162 if (cii->c_uid != current_fsuid()) {
43163 cii->c_uid = current_fsuid();
43164 cii->c_cached_perm = mask;
43165@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
43166 {
43167 struct coda_inode_info *cii = ITOC(inode);
43168 spin_lock(&cii->c_lock);
43169- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
43170+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
43171 spin_unlock(&cii->c_lock);
43172 }
43173
43174 /* remove all acl caches */
43175 void coda_cache_clear_all(struct super_block *sb)
43176 {
43177- atomic_inc(&permission_epoch);
43178+ atomic_inc_unchecked(&permission_epoch);
43179 }
43180
43181
43182@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
43183 spin_lock(&cii->c_lock);
43184 hit = (mask & cii->c_cached_perm) == mask &&
43185 cii->c_uid == current_fsuid() &&
43186- cii->c_cached_epoch == atomic_read(&permission_epoch);
43187+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
43188 spin_unlock(&cii->c_lock);
43189
43190 return hit;
43191diff --git a/fs/compat.c b/fs/compat.c
43192index f2944ac..62845d2 100644
43193--- a/fs/compat.c
43194+++ b/fs/compat.c
43195@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
43196
43197 set_fs(KERNEL_DS);
43198 /* The __user pointer cast is valid because of the set_fs() */
43199- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
43200+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
43201 set_fs(oldfs);
43202 /* truncating is ok because it's a user address */
43203 if (!ret)
43204@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
43205 goto out;
43206
43207 ret = -EINVAL;
43208- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
43209+ if (nr_segs > UIO_MAXIOV)
43210 goto out;
43211 if (nr_segs > fast_segs) {
43212 ret = -ENOMEM;
43213@@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
43214
43215 struct compat_readdir_callback {
43216 struct compat_old_linux_dirent __user *dirent;
43217+ struct file * file;
43218 int result;
43219 };
43220
43221@@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
43222 buf->result = -EOVERFLOW;
43223 return -EOVERFLOW;
43224 }
43225+
43226+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43227+ return 0;
43228+
43229 buf->result++;
43230 dirent = buf->dirent;
43231 if (!access_ok(VERIFY_WRITE, dirent,
43232@@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
43233
43234 buf.result = 0;
43235 buf.dirent = dirent;
43236+ buf.file = file;
43237
43238 error = vfs_readdir(file, compat_fillonedir, &buf);
43239 if (buf.result)
43240@@ -900,6 +906,7 @@ struct compat_linux_dirent {
43241 struct compat_getdents_callback {
43242 struct compat_linux_dirent __user *current_dir;
43243 struct compat_linux_dirent __user *previous;
43244+ struct file * file;
43245 int count;
43246 int error;
43247 };
43248@@ -921,6 +928,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
43249 buf->error = -EOVERFLOW;
43250 return -EOVERFLOW;
43251 }
43252+
43253+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43254+ return 0;
43255+
43256 dirent = buf->previous;
43257 if (dirent) {
43258 if (__put_user(offset, &dirent->d_off))
43259@@ -968,6 +979,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
43260 buf.previous = NULL;
43261 buf.count = count;
43262 buf.error = 0;
43263+ buf.file = file;
43264
43265 error = vfs_readdir(file, compat_filldir, &buf);
43266 if (error >= 0)
43267@@ -989,6 +1001,7 @@ out:
43268 struct compat_getdents_callback64 {
43269 struct linux_dirent64 __user *current_dir;
43270 struct linux_dirent64 __user *previous;
43271+ struct file * file;
43272 int count;
43273 int error;
43274 };
43275@@ -1005,6 +1018,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
43276 buf->error = -EINVAL; /* only used if we fail.. */
43277 if (reclen > buf->count)
43278 return -EINVAL;
43279+
43280+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43281+ return 0;
43282+
43283 dirent = buf->previous;
43284
43285 if (dirent) {
43286@@ -1056,13 +1073,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
43287 buf.previous = NULL;
43288 buf.count = count;
43289 buf.error = 0;
43290+ buf.file = file;
43291
43292 error = vfs_readdir(file, compat_filldir64, &buf);
43293 if (error >= 0)
43294 error = buf.error;
43295 lastdirent = buf.previous;
43296 if (lastdirent) {
43297- typeof(lastdirent->d_off) d_off = file->f_pos;
43298+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
43299 if (__put_user_unaligned(d_off, &lastdirent->d_off))
43300 error = -EFAULT;
43301 else
43302diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
43303index 112e45a..b59845b 100644
43304--- a/fs/compat_binfmt_elf.c
43305+++ b/fs/compat_binfmt_elf.c
43306@@ -30,11 +30,13 @@
43307 #undef elf_phdr
43308 #undef elf_shdr
43309 #undef elf_note
43310+#undef elf_dyn
43311 #undef elf_addr_t
43312 #define elfhdr elf32_hdr
43313 #define elf_phdr elf32_phdr
43314 #define elf_shdr elf32_shdr
43315 #define elf_note elf32_note
43316+#define elf_dyn Elf32_Dyn
43317 #define elf_addr_t Elf32_Addr
43318
43319 /*
43320diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
43321index debdfe0..75d31d4 100644
43322--- a/fs/compat_ioctl.c
43323+++ b/fs/compat_ioctl.c
43324@@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
43325
43326 err = get_user(palp, &up->palette);
43327 err |= get_user(length, &up->length);
43328+ if (err)
43329+ return -EFAULT;
43330
43331 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
43332 err = put_user(compat_ptr(palp), &up_native->palette);
43333@@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
43334 return -EFAULT;
43335 if (__get_user(udata, &ss32->iomem_base))
43336 return -EFAULT;
43337- ss.iomem_base = compat_ptr(udata);
43338+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
43339 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
43340 __get_user(ss.port_high, &ss32->port_high))
43341 return -EFAULT;
43342@@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
43343 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
43344 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
43345 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
43346- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43347+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43348 return -EFAULT;
43349
43350 return ioctl_preallocate(file, p);
43351@@ -1610,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
43352 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
43353 {
43354 unsigned int a, b;
43355- a = *(unsigned int *)p;
43356- b = *(unsigned int *)q;
43357+ a = *(const unsigned int *)p;
43358+ b = *(const unsigned int *)q;
43359 if (a > b)
43360 return 1;
43361 if (a < b)
43362diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
43363index 7e6c52d..94bc756 100644
43364--- a/fs/configfs/dir.c
43365+++ b/fs/configfs/dir.c
43366@@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43367 }
43368 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
43369 struct configfs_dirent *next;
43370- const char * name;
43371+ const unsigned char * name;
43372+ char d_name[sizeof(next->s_dentry->d_iname)];
43373 int len;
43374 struct inode *inode = NULL;
43375
43376@@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43377 continue;
43378
43379 name = configfs_get_name(next);
43380- len = strlen(name);
43381+ if (next->s_dentry && name == next->s_dentry->d_iname) {
43382+ len = next->s_dentry->d_name.len;
43383+ memcpy(d_name, name, len);
43384+ name = d_name;
43385+ } else
43386+ len = strlen(name);
43387
43388 /*
43389 * We'll have a dentry and an inode for
43390diff --git a/fs/dcache.c b/fs/dcache.c
43391index b80531c..8ca7e2d 100644
43392--- a/fs/dcache.c
43393+++ b/fs/dcache.c
43394@@ -3084,7 +3084,7 @@ void __init vfs_caches_init(unsigned long mempages)
43395 mempages -= reserve;
43396
43397 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
43398- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
43399+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
43400
43401 dcache_init();
43402 inode_init();
43403diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
43404index b80bc84..0d46d1a 100644
43405--- a/fs/debugfs/inode.c
43406+++ b/fs/debugfs/inode.c
43407@@ -408,7 +408,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
43408 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
43409 {
43410 return debugfs_create_file(name,
43411+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
43412+ S_IFDIR | S_IRWXU,
43413+#else
43414 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
43415+#endif
43416 parent, NULL, NULL);
43417 }
43418 EXPORT_SYMBOL_GPL(debugfs_create_dir);
43419diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
43420index ab35b11..b30af66 100644
43421--- a/fs/ecryptfs/inode.c
43422+++ b/fs/ecryptfs/inode.c
43423@@ -672,7 +672,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
43424 old_fs = get_fs();
43425 set_fs(get_ds());
43426 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
43427- (char __user *)lower_buf,
43428+ (char __force_user *)lower_buf,
43429 lower_bufsiz);
43430 set_fs(old_fs);
43431 if (rc < 0)
43432@@ -718,7 +718,7 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
43433 }
43434 old_fs = get_fs();
43435 set_fs(get_ds());
43436- rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
43437+ rc = dentry->d_inode->i_op->readlink(dentry, (char __force_user *)buf, len);
43438 set_fs(old_fs);
43439 if (rc < 0) {
43440 kfree(buf);
43441@@ -733,7 +733,7 @@ out:
43442 static void
43443 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
43444 {
43445- char *buf = nd_get_link(nd);
43446+ const char *buf = nd_get_link(nd);
43447 if (!IS_ERR(buf)) {
43448 /* Free the char* */
43449 kfree(buf);
43450diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
43451index 3a06f40..f7af544 100644
43452--- a/fs/ecryptfs/miscdev.c
43453+++ b/fs/ecryptfs/miscdev.c
43454@@ -345,7 +345,7 @@ check_list:
43455 goto out_unlock_msg_ctx;
43456 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
43457 if (msg_ctx->msg) {
43458- if (copy_to_user(&buf[i], packet_length, packet_length_size))
43459+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
43460 goto out_unlock_msg_ctx;
43461 i += packet_length_size;
43462 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
43463diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
43464index b2a34a1..162fa69 100644
43465--- a/fs/ecryptfs/read_write.c
43466+++ b/fs/ecryptfs/read_write.c
43467@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
43468 return -EIO;
43469 fs_save = get_fs();
43470 set_fs(get_ds());
43471- rc = vfs_write(lower_file, data, size, &offset);
43472+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
43473 set_fs(fs_save);
43474 mark_inode_dirty_sync(ecryptfs_inode);
43475 return rc;
43476@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
43477 return -EIO;
43478 fs_save = get_fs();
43479 set_fs(get_ds());
43480- rc = vfs_read(lower_file, data, size, &offset);
43481+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
43482 set_fs(fs_save);
43483 return rc;
43484 }
43485diff --git a/fs/exec.c b/fs/exec.c
43486index b1fd202..582240d 100644
43487--- a/fs/exec.c
43488+++ b/fs/exec.c
43489@@ -55,6 +55,15 @@
43490 #include <linux/pipe_fs_i.h>
43491 #include <linux/oom.h>
43492 #include <linux/compat.h>
43493+#include <linux/random.h>
43494+#include <linux/seq_file.h>
43495+
43496+#ifdef CONFIG_PAX_REFCOUNT
43497+#include <linux/kallsyms.h>
43498+#include <linux/kdebug.h>
43499+#endif
43500+
43501+#include <trace/events/fs.h>
43502
43503 #include <asm/uaccess.h>
43504 #include <asm/mmu_context.h>
43505@@ -66,6 +75,18 @@
43506
43507 #include <trace/events/sched.h>
43508
43509+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43510+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
43511+{
43512+ WARN_ONCE(1, "PAX: PAX_HAVE_ACL_FLAGS was enabled without providing the pax_set_initial_flags callback, this is probably not what you wanted.\n");
43513+}
43514+#endif
43515+
43516+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
43517+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
43518+EXPORT_SYMBOL(pax_set_initial_flags_func);
43519+#endif
43520+
43521 int core_uses_pid;
43522 char core_pattern[CORENAME_MAX_SIZE] = "core";
43523 unsigned int core_pipe_limit;
43524@@ -75,7 +96,7 @@ struct core_name {
43525 char *corename;
43526 int used, size;
43527 };
43528-static atomic_t call_count = ATOMIC_INIT(1);
43529+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
43530
43531 /* The maximal length of core_pattern is also specified in sysctl.c */
43532
43533@@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
43534 int write)
43535 {
43536 struct page *page;
43537- int ret;
43538
43539-#ifdef CONFIG_STACK_GROWSUP
43540- if (write) {
43541- ret = expand_downwards(bprm->vma, pos);
43542- if (ret < 0)
43543- return NULL;
43544- }
43545-#endif
43546- ret = get_user_pages(current, bprm->mm, pos,
43547- 1, write, 1, &page, NULL);
43548- if (ret <= 0)
43549+ if (0 > expand_downwards(bprm->vma, pos))
43550+ return NULL;
43551+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
43552 return NULL;
43553
43554 if (write) {
43555@@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
43556 if (size <= ARG_MAX)
43557 return page;
43558
43559+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43560+ // only allow 512KB for argv+env on suid/sgid binaries
43561+ // to prevent easy ASLR exhaustion
43562+ if (((bprm->cred->euid != current_euid()) ||
43563+ (bprm->cred->egid != current_egid())) &&
43564+ (size > (512 * 1024))) {
43565+ put_page(page);
43566+ return NULL;
43567+ }
43568+#endif
43569+
43570 /*
43571 * Limit to 1/4-th the stack size for the argv+env strings.
43572 * This ensures that:
43573@@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
43574 vma->vm_end = STACK_TOP_MAX;
43575 vma->vm_start = vma->vm_end - PAGE_SIZE;
43576 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
43577+
43578+#ifdef CONFIG_PAX_SEGMEXEC
43579+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
43580+#endif
43581+
43582 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
43583 INIT_LIST_HEAD(&vma->anon_vma_chain);
43584
43585@@ -291,6 +320,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
43586 mm->stack_vm = mm->total_vm = 1;
43587 up_write(&mm->mmap_sem);
43588 bprm->p = vma->vm_end - sizeof(void *);
43589+
43590+#ifdef CONFIG_PAX_RANDUSTACK
43591+ if (randomize_va_space)
43592+ bprm->p ^= random32() & ~PAGE_MASK;
43593+#endif
43594+
43595 return 0;
43596 err:
43597 up_write(&mm->mmap_sem);
43598@@ -399,19 +434,7 @@ err:
43599 return err;
43600 }
43601
43602-struct user_arg_ptr {
43603-#ifdef CONFIG_COMPAT
43604- bool is_compat;
43605-#endif
43606- union {
43607- const char __user *const __user *native;
43608-#ifdef CONFIG_COMPAT
43609- compat_uptr_t __user *compat;
43610-#endif
43611- } ptr;
43612-};
43613-
43614-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
43615+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
43616 {
43617 const char __user *native;
43618
43619@@ -420,14 +443,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
43620 compat_uptr_t compat;
43621
43622 if (get_user(compat, argv.ptr.compat + nr))
43623- return ERR_PTR(-EFAULT);
43624+ return (const char __force_user *)ERR_PTR(-EFAULT);
43625
43626 return compat_ptr(compat);
43627 }
43628 #endif
43629
43630 if (get_user(native, argv.ptr.native + nr))
43631- return ERR_PTR(-EFAULT);
43632+ return (const char __force_user *)ERR_PTR(-EFAULT);
43633
43634 return native;
43635 }
43636@@ -446,7 +469,7 @@ static int count(struct user_arg_ptr argv, int max)
43637 if (!p)
43638 break;
43639
43640- if (IS_ERR(p))
43641+ if (IS_ERR((const char __force_kernel *)p))
43642 return -EFAULT;
43643
43644 if (i++ >= max)
43645@@ -480,7 +503,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
43646
43647 ret = -EFAULT;
43648 str = get_user_arg_ptr(argv, argc);
43649- if (IS_ERR(str))
43650+ if (IS_ERR((const char __force_kernel *)str))
43651 goto out;
43652
43653 len = strnlen_user(str, MAX_ARG_STRLEN);
43654@@ -562,7 +585,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
43655 int r;
43656 mm_segment_t oldfs = get_fs();
43657 struct user_arg_ptr argv = {
43658- .ptr.native = (const char __user *const __user *)__argv,
43659+ .ptr.native = (const char __force_user *const __force_user *)__argv,
43660 };
43661
43662 set_fs(KERNEL_DS);
43663@@ -597,7 +620,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
43664 unsigned long new_end = old_end - shift;
43665 struct mmu_gather tlb;
43666
43667- BUG_ON(new_start > new_end);
43668+ if (new_start >= new_end || new_start < mmap_min_addr)
43669+ return -ENOMEM;
43670
43671 /*
43672 * ensure there are no vmas between where we want to go
43673@@ -606,6 +630,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
43674 if (vma != find_vma(mm, new_start))
43675 return -EFAULT;
43676
43677+#ifdef CONFIG_PAX_SEGMEXEC
43678+ BUG_ON(pax_find_mirror_vma(vma));
43679+#endif
43680+
43681 /*
43682 * cover the whole range: [new_start, old_end)
43683 */
43684@@ -686,10 +714,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
43685 stack_top = arch_align_stack(stack_top);
43686 stack_top = PAGE_ALIGN(stack_top);
43687
43688- if (unlikely(stack_top < mmap_min_addr) ||
43689- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
43690- return -ENOMEM;
43691-
43692 stack_shift = vma->vm_end - stack_top;
43693
43694 bprm->p -= stack_shift;
43695@@ -701,8 +725,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
43696 bprm->exec -= stack_shift;
43697
43698 down_write(&mm->mmap_sem);
43699+
43700+ /* Move stack pages down in memory. */
43701+ if (stack_shift) {
43702+ ret = shift_arg_pages(vma, stack_shift);
43703+ if (ret)
43704+ goto out_unlock;
43705+ }
43706+
43707 vm_flags = VM_STACK_FLAGS;
43708
43709+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43710+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43711+ vm_flags &= ~VM_EXEC;
43712+
43713+#ifdef CONFIG_PAX_MPROTECT
43714+ if (mm->pax_flags & MF_PAX_MPROTECT)
43715+ vm_flags &= ~VM_MAYEXEC;
43716+#endif
43717+
43718+ }
43719+#endif
43720+
43721 /*
43722 * Adjust stack execute permissions; explicitly enable for
43723 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
43724@@ -721,13 +765,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
43725 goto out_unlock;
43726 BUG_ON(prev != vma);
43727
43728- /* Move stack pages down in memory. */
43729- if (stack_shift) {
43730- ret = shift_arg_pages(vma, stack_shift);
43731- if (ret)
43732- goto out_unlock;
43733- }
43734-
43735 /* mprotect_fixup is overkill to remove the temporary stack flags */
43736 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
43737
43738@@ -785,6 +822,8 @@ struct file *open_exec(const char *name)
43739
43740 fsnotify_open(file);
43741
43742+ trace_open_exec(name);
43743+
43744 err = deny_write_access(file);
43745 if (err)
43746 goto exit;
43747@@ -808,7 +847,7 @@ int kernel_read(struct file *file, loff_t offset,
43748 old_fs = get_fs();
43749 set_fs(get_ds());
43750 /* The cast to a user pointer is valid due to the set_fs() */
43751- result = vfs_read(file, (void __user *)addr, count, &pos);
43752+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
43753 set_fs(old_fs);
43754 return result;
43755 }
43756@@ -1254,7 +1293,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
43757 }
43758 rcu_read_unlock();
43759
43760- if (p->fs->users > n_fs) {
43761+ if (atomic_read(&p->fs->users) > n_fs) {
43762 bprm->unsafe |= LSM_UNSAFE_SHARE;
43763 } else {
43764 res = -EAGAIN;
43765@@ -1451,6 +1490,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
43766
43767 EXPORT_SYMBOL(search_binary_handler);
43768
43769+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43770+static DEFINE_PER_CPU(u64, exec_counter);
43771+static int __init init_exec_counters(void)
43772+{
43773+ unsigned int cpu;
43774+
43775+ for_each_possible_cpu(cpu) {
43776+ per_cpu(exec_counter, cpu) = (u64)cpu;
43777+ }
43778+
43779+ return 0;
43780+}
43781+early_initcall(init_exec_counters);
43782+static inline void increment_exec_counter(void)
43783+{
43784+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
43785+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
43786+}
43787+#else
43788+static inline void increment_exec_counter(void) {}
43789+#endif
43790+
43791 /*
43792 * sys_execve() executes a new program.
43793 */
43794@@ -1459,6 +1520,11 @@ static int do_execve_common(const char *filename,
43795 struct user_arg_ptr envp,
43796 struct pt_regs *regs)
43797 {
43798+#ifdef CONFIG_GRKERNSEC
43799+ struct file *old_exec_file;
43800+ struct acl_subject_label *old_acl;
43801+ struct rlimit old_rlim[RLIM_NLIMITS];
43802+#endif
43803 struct linux_binprm *bprm;
43804 struct file *file;
43805 struct files_struct *displaced;
43806@@ -1466,6 +1532,8 @@ static int do_execve_common(const char *filename,
43807 int retval;
43808 const struct cred *cred = current_cred();
43809
43810+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
43811+
43812 /*
43813 * We move the actual failure in case of RLIMIT_NPROC excess from
43814 * set*uid() to execve() because too many poorly written programs
43815@@ -1506,12 +1574,27 @@ static int do_execve_common(const char *filename,
43816 if (IS_ERR(file))
43817 goto out_unmark;
43818
43819+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
43820+ retval = -EPERM;
43821+ goto out_file;
43822+ }
43823+
43824 sched_exec();
43825
43826 bprm->file = file;
43827 bprm->filename = filename;
43828 bprm->interp = filename;
43829
43830+ if (gr_process_user_ban()) {
43831+ retval = -EPERM;
43832+ goto out_file;
43833+ }
43834+
43835+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
43836+ retval = -EACCES;
43837+ goto out_file;
43838+ }
43839+
43840 retval = bprm_mm_init(bprm);
43841 if (retval)
43842 goto out_file;
43843@@ -1528,24 +1611,65 @@ static int do_execve_common(const char *filename,
43844 if (retval < 0)
43845 goto out;
43846
43847+#ifdef CONFIG_GRKERNSEC
43848+ old_acl = current->acl;
43849+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
43850+ old_exec_file = current->exec_file;
43851+ get_file(file);
43852+ current->exec_file = file;
43853+#endif
43854+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43855+ /* limit suid stack to 8MB
43856+ we saved the old limits above and will restore them if this exec fails
43857+ */
43858+ if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
43859+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
43860+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
43861+#endif
43862+
43863+ if (!gr_tpe_allow(file)) {
43864+ retval = -EACCES;
43865+ goto out_fail;
43866+ }
43867+
43868+ if (gr_check_crash_exec(file)) {
43869+ retval = -EACCES;
43870+ goto out_fail;
43871+ }
43872+
43873+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
43874+ bprm->unsafe);
43875+ if (retval < 0)
43876+ goto out_fail;
43877+
43878 retval = copy_strings_kernel(1, &bprm->filename, bprm);
43879 if (retval < 0)
43880- goto out;
43881+ goto out_fail;
43882
43883 bprm->exec = bprm->p;
43884 retval = copy_strings(bprm->envc, envp, bprm);
43885 if (retval < 0)
43886- goto out;
43887+ goto out_fail;
43888
43889 retval = copy_strings(bprm->argc, argv, bprm);
43890 if (retval < 0)
43891- goto out;
43892+ goto out_fail;
43893+
43894+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
43895+
43896+ gr_handle_exec_args(bprm, argv);
43897
43898 retval = search_binary_handler(bprm,regs);
43899 if (retval < 0)
43900- goto out;
43901+ goto out_fail;
43902+#ifdef CONFIG_GRKERNSEC
43903+ if (old_exec_file)
43904+ fput(old_exec_file);
43905+#endif
43906
43907 /* execve succeeded */
43908+
43909+ increment_exec_counter();
43910 current->fs->in_exec = 0;
43911 current->in_execve = 0;
43912 acct_update_integrals(current);
43913@@ -1554,6 +1678,14 @@ static int do_execve_common(const char *filename,
43914 put_files_struct(displaced);
43915 return retval;
43916
43917+out_fail:
43918+#ifdef CONFIG_GRKERNSEC
43919+ current->acl = old_acl;
43920+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
43921+ fput(current->exec_file);
43922+ current->exec_file = old_exec_file;
43923+#endif
43924+
43925 out:
43926 if (bprm->mm) {
43927 acct_arg_size(bprm, 0);
43928@@ -1627,7 +1759,7 @@ static int expand_corename(struct core_name *cn)
43929 {
43930 char *old_corename = cn->corename;
43931
43932- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
43933+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
43934 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
43935
43936 if (!cn->corename) {
43937@@ -1724,7 +1856,7 @@ static int format_corename(struct core_name *cn, long signr)
43938 int pid_in_pattern = 0;
43939 int err = 0;
43940
43941- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
43942+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
43943 cn->corename = kmalloc(cn->size, GFP_KERNEL);
43944 cn->used = 0;
43945
43946@@ -1821,6 +1953,228 @@ out:
43947 return ispipe;
43948 }
43949
43950+int pax_check_flags(unsigned long *flags)
43951+{
43952+ int retval = 0;
43953+
43954+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
43955+ if (*flags & MF_PAX_SEGMEXEC)
43956+ {
43957+ *flags &= ~MF_PAX_SEGMEXEC;
43958+ retval = -EINVAL;
43959+ }
43960+#endif
43961+
43962+ if ((*flags & MF_PAX_PAGEEXEC)
43963+
43964+#ifdef CONFIG_PAX_PAGEEXEC
43965+ && (*flags & MF_PAX_SEGMEXEC)
43966+#endif
43967+
43968+ )
43969+ {
43970+ *flags &= ~MF_PAX_PAGEEXEC;
43971+ retval = -EINVAL;
43972+ }
43973+
43974+ if ((*flags & MF_PAX_MPROTECT)
43975+
43976+#ifdef CONFIG_PAX_MPROTECT
43977+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
43978+#endif
43979+
43980+ )
43981+ {
43982+ *flags &= ~MF_PAX_MPROTECT;
43983+ retval = -EINVAL;
43984+ }
43985+
43986+ if ((*flags & MF_PAX_EMUTRAMP)
43987+
43988+#ifdef CONFIG_PAX_EMUTRAMP
43989+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
43990+#endif
43991+
43992+ )
43993+ {
43994+ *flags &= ~MF_PAX_EMUTRAMP;
43995+ retval = -EINVAL;
43996+ }
43997+
43998+ return retval;
43999+}
44000+
44001+EXPORT_SYMBOL(pax_check_flags);
44002+
44003+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44004+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
44005+{
44006+ struct task_struct *tsk = current;
44007+ struct mm_struct *mm = current->mm;
44008+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
44009+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
44010+ char *path_exec = NULL;
44011+ char *path_fault = NULL;
44012+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
44013+
44014+ if (buffer_exec && buffer_fault) {
44015+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
44016+
44017+ down_read(&mm->mmap_sem);
44018+ vma = mm->mmap;
44019+ while (vma && (!vma_exec || !vma_fault)) {
44020+ if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
44021+ vma_exec = vma;
44022+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
44023+ vma_fault = vma;
44024+ vma = vma->vm_next;
44025+ }
44026+ if (vma_exec) {
44027+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
44028+ if (IS_ERR(path_exec))
44029+ path_exec = "<path too long>";
44030+ else {
44031+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
44032+ if (path_exec) {
44033+ *path_exec = 0;
44034+ path_exec = buffer_exec;
44035+ } else
44036+ path_exec = "<path too long>";
44037+ }
44038+ }
44039+ if (vma_fault) {
44040+ start = vma_fault->vm_start;
44041+ end = vma_fault->vm_end;
44042+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
44043+ if (vma_fault->vm_file) {
44044+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
44045+ if (IS_ERR(path_fault))
44046+ path_fault = "<path too long>";
44047+ else {
44048+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
44049+ if (path_fault) {
44050+ *path_fault = 0;
44051+ path_fault = buffer_fault;
44052+ } else
44053+ path_fault = "<path too long>";
44054+ }
44055+ } else
44056+ path_fault = "<anonymous mapping>";
44057+ }
44058+ up_read(&mm->mmap_sem);
44059+ }
44060+ if (tsk->signal->curr_ip)
44061+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
44062+ else
44063+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
44064+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
44065+ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
44066+ task_uid(tsk), task_euid(tsk), pc, sp);
44067+ free_page((unsigned long)buffer_exec);
44068+ free_page((unsigned long)buffer_fault);
44069+ pax_report_insns(regs, pc, sp);
44070+ do_coredump(SIGKILL, SIGKILL, regs);
44071+}
44072+#endif
44073+
44074+#ifdef CONFIG_PAX_REFCOUNT
44075+void pax_report_refcount_overflow(struct pt_regs *regs)
44076+{
44077+ if (current->signal->curr_ip)
44078+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44079+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
44080+ else
44081+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44082+ current->comm, task_pid_nr(current), current_uid(), current_euid());
44083+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
44084+ show_regs(regs);
44085+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
44086+}
44087+#endif
44088+
44089+#ifdef CONFIG_PAX_USERCOPY
44090+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
44091+int object_is_on_stack(const void *obj, unsigned long len)
44092+{
44093+ const void * const stack = task_stack_page(current);
44094+ const void * const stackend = stack + THREAD_SIZE;
44095+
44096+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44097+ const void *frame = NULL;
44098+ const void *oldframe;
44099+#endif
44100+
44101+ if (obj + len < obj)
44102+ return -1;
44103+
44104+ if (obj + len <= stack || stackend <= obj)
44105+ return 0;
44106+
44107+ if (obj < stack || stackend < obj + len)
44108+ return -1;
44109+
44110+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44111+ oldframe = __builtin_frame_address(1);
44112+ if (oldframe)
44113+ frame = __builtin_frame_address(2);
44114+ /*
44115+ low ----------------------------------------------> high
44116+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
44117+ ^----------------^
44118+ allow copies only within here
44119+ */
44120+ while (stack <= frame && frame < stackend) {
44121+ /* if obj + len extends past the last frame, this
44122+ check won't pass and the next frame will be 0,
44123+ causing us to bail out and correctly report
44124+ the copy as invalid
44125+ */
44126+ if (obj + len <= frame)
44127+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
44128+ oldframe = frame;
44129+ frame = *(const void * const *)frame;
44130+ }
44131+ return -1;
44132+#else
44133+ return 1;
44134+#endif
44135+}
44136+
44137+__noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
44138+{
44139+ if (current->signal->curr_ip)
44140+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44141+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44142+ else
44143+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44144+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44145+ dump_stack();
44146+ gr_handle_kernel_exploit();
44147+ do_group_exit(SIGKILL);
44148+}
44149+#endif
44150+
44151+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
44152+void pax_track_stack(void)
44153+{
44154+ unsigned long sp = (unsigned long)&sp;
44155+ if (sp < current_thread_info()->lowest_stack &&
44156+ sp > (unsigned long)task_stack_page(current))
44157+ current_thread_info()->lowest_stack = sp;
44158+}
44159+EXPORT_SYMBOL(pax_track_stack);
44160+#endif
44161+
44162+#ifdef CONFIG_PAX_SIZE_OVERFLOW
44163+void report_size_overflow(const char *file, unsigned int line, const char *func)
44164+{
44165+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u\n", func, file, line);
44166+ dump_stack();
44167+ do_group_exit(SIGKILL);
44168+}
44169+EXPORT_SYMBOL(report_size_overflow);
44170+#endif
44171+
44172 static int zap_process(struct task_struct *start, int exit_code)
44173 {
44174 struct task_struct *t;
44175@@ -2018,17 +2372,17 @@ static void wait_for_dump_helpers(struct file *file)
44176 pipe = file->f_path.dentry->d_inode->i_pipe;
44177
44178 pipe_lock(pipe);
44179- pipe->readers++;
44180- pipe->writers--;
44181+ atomic_inc(&pipe->readers);
44182+ atomic_dec(&pipe->writers);
44183
44184- while ((pipe->readers > 1) && (!signal_pending(current))) {
44185+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
44186 wake_up_interruptible_sync(&pipe->wait);
44187 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
44188 pipe_wait(pipe);
44189 }
44190
44191- pipe->readers--;
44192- pipe->writers++;
44193+ atomic_dec(&pipe->readers);
44194+ atomic_inc(&pipe->writers);
44195 pipe_unlock(pipe);
44196
44197 }
44198@@ -2089,7 +2443,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44199 int retval = 0;
44200 int flag = 0;
44201 int ispipe;
44202- static atomic_t core_dump_count = ATOMIC_INIT(0);
44203+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
44204 struct coredump_params cprm = {
44205 .signr = signr,
44206 .regs = regs,
44207@@ -2104,6 +2458,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44208
44209 audit_core_dumps(signr);
44210
44211+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
44212+ gr_handle_brute_attach(current, cprm.mm_flags);
44213+
44214 binfmt = mm->binfmt;
44215 if (!binfmt || !binfmt->core_dump)
44216 goto fail;
44217@@ -2171,7 +2528,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44218 }
44219 cprm.limit = RLIM_INFINITY;
44220
44221- dump_count = atomic_inc_return(&core_dump_count);
44222+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
44223 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
44224 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
44225 task_tgid_vnr(current), current->comm);
44226@@ -2198,6 +2555,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44227 } else {
44228 struct inode *inode;
44229
44230+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
44231+
44232 if (cprm.limit < binfmt->min_coredump)
44233 goto fail_unlock;
44234
44235@@ -2241,7 +2600,7 @@ close_fail:
44236 filp_close(cprm.file, NULL);
44237 fail_dropcount:
44238 if (ispipe)
44239- atomic_dec(&core_dump_count);
44240+ atomic_dec_unchecked(&core_dump_count);
44241 fail_unlock:
44242 kfree(cn.corename);
44243 fail_corename:
44244@@ -2260,7 +2619,7 @@ fail:
44245 */
44246 int dump_write(struct file *file, const void *addr, int nr)
44247 {
44248- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
44249+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
44250 }
44251 EXPORT_SYMBOL(dump_write);
44252
44253diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
44254index a8cbe1b..fed04cb 100644
44255--- a/fs/ext2/balloc.c
44256+++ b/fs/ext2/balloc.c
44257@@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
44258
44259 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44260 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44261- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44262+ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
44263 sbi->s_resuid != current_fsuid() &&
44264 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
44265 return 0;
44266diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
44267index baac1b1..1499b62 100644
44268--- a/fs/ext3/balloc.c
44269+++ b/fs/ext3/balloc.c
44270@@ -1438,9 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
44271
44272 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44273 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44274- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44275+ if (free_blocks < root_blocks + 1 &&
44276 !use_reservation && sbi->s_resuid != current_fsuid() &&
44277- (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
44278+ (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)) &&
44279+ !capable_nolog(CAP_SYS_RESOURCE)) {
44280 return 0;
44281 }
44282 return 1;
44283diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
44284index 8da837b..ed3835b 100644
44285--- a/fs/ext4/balloc.c
44286+++ b/fs/ext4/balloc.c
44287@@ -463,8 +463,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
44288 /* Hm, nope. Are (enough) root reserved clusters available? */
44289 if (sbi->s_resuid == current_fsuid() ||
44290 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
44291- capable(CAP_SYS_RESOURCE) ||
44292- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
44293+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
44294+ capable_nolog(CAP_SYS_RESOURCE)) {
44295
44296 if (free_clusters >= (nclusters + dirty_clusters))
44297 return 1;
44298diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
44299index 0e01e90..ae2bd5e 100644
44300--- a/fs/ext4/ext4.h
44301+++ b/fs/ext4/ext4.h
44302@@ -1225,19 +1225,19 @@ struct ext4_sb_info {
44303 unsigned long s_mb_last_start;
44304
44305 /* stats for buddy allocator */
44306- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
44307- atomic_t s_bal_success; /* we found long enough chunks */
44308- atomic_t s_bal_allocated; /* in blocks */
44309- atomic_t s_bal_ex_scanned; /* total extents scanned */
44310- atomic_t s_bal_goals; /* goal hits */
44311- atomic_t s_bal_breaks; /* too long searches */
44312- atomic_t s_bal_2orders; /* 2^order hits */
44313+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
44314+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
44315+ atomic_unchecked_t s_bal_allocated; /* in blocks */
44316+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
44317+ atomic_unchecked_t s_bal_goals; /* goal hits */
44318+ atomic_unchecked_t s_bal_breaks; /* too long searches */
44319+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
44320 spinlock_t s_bal_lock;
44321 unsigned long s_mb_buddies_generated;
44322 unsigned long long s_mb_generation_time;
44323- atomic_t s_mb_lost_chunks;
44324- atomic_t s_mb_preallocated;
44325- atomic_t s_mb_discarded;
44326+ atomic_unchecked_t s_mb_lost_chunks;
44327+ atomic_unchecked_t s_mb_preallocated;
44328+ atomic_unchecked_t s_mb_discarded;
44329 atomic_t s_lock_busy;
44330
44331 /* locality groups */
44332diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
44333index 6b0a57e..1955a44 100644
44334--- a/fs/ext4/mballoc.c
44335+++ b/fs/ext4/mballoc.c
44336@@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
44337 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
44338
44339 if (EXT4_SB(sb)->s_mb_stats)
44340- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
44341+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
44342
44343 break;
44344 }
44345@@ -2041,7 +2041,7 @@ repeat:
44346 ac->ac_status = AC_STATUS_CONTINUE;
44347 ac->ac_flags |= EXT4_MB_HINT_FIRST;
44348 cr = 3;
44349- atomic_inc(&sbi->s_mb_lost_chunks);
44350+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
44351 goto repeat;
44352 }
44353 }
44354@@ -2545,25 +2545,25 @@ int ext4_mb_release(struct super_block *sb)
44355 if (sbi->s_mb_stats) {
44356 ext4_msg(sb, KERN_INFO,
44357 "mballoc: %u blocks %u reqs (%u success)",
44358- atomic_read(&sbi->s_bal_allocated),
44359- atomic_read(&sbi->s_bal_reqs),
44360- atomic_read(&sbi->s_bal_success));
44361+ atomic_read_unchecked(&sbi->s_bal_allocated),
44362+ atomic_read_unchecked(&sbi->s_bal_reqs),
44363+ atomic_read_unchecked(&sbi->s_bal_success));
44364 ext4_msg(sb, KERN_INFO,
44365 "mballoc: %u extents scanned, %u goal hits, "
44366 "%u 2^N hits, %u breaks, %u lost",
44367- atomic_read(&sbi->s_bal_ex_scanned),
44368- atomic_read(&sbi->s_bal_goals),
44369- atomic_read(&sbi->s_bal_2orders),
44370- atomic_read(&sbi->s_bal_breaks),
44371- atomic_read(&sbi->s_mb_lost_chunks));
44372+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
44373+ atomic_read_unchecked(&sbi->s_bal_goals),
44374+ atomic_read_unchecked(&sbi->s_bal_2orders),
44375+ atomic_read_unchecked(&sbi->s_bal_breaks),
44376+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
44377 ext4_msg(sb, KERN_INFO,
44378 "mballoc: %lu generated and it took %Lu",
44379 sbi->s_mb_buddies_generated,
44380 sbi->s_mb_generation_time);
44381 ext4_msg(sb, KERN_INFO,
44382 "mballoc: %u preallocated, %u discarded",
44383- atomic_read(&sbi->s_mb_preallocated),
44384- atomic_read(&sbi->s_mb_discarded));
44385+ atomic_read_unchecked(&sbi->s_mb_preallocated),
44386+ atomic_read_unchecked(&sbi->s_mb_discarded));
44387 }
44388
44389 free_percpu(sbi->s_locality_groups);
44390@@ -3045,16 +3045,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
44391 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
44392
44393 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
44394- atomic_inc(&sbi->s_bal_reqs);
44395- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
44396+ atomic_inc_unchecked(&sbi->s_bal_reqs);
44397+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
44398 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
44399- atomic_inc(&sbi->s_bal_success);
44400- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
44401+ atomic_inc_unchecked(&sbi->s_bal_success);
44402+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
44403 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
44404 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
44405- atomic_inc(&sbi->s_bal_goals);
44406+ atomic_inc_unchecked(&sbi->s_bal_goals);
44407 if (ac->ac_found > sbi->s_mb_max_to_scan)
44408- atomic_inc(&sbi->s_bal_breaks);
44409+ atomic_inc_unchecked(&sbi->s_bal_breaks);
44410 }
44411
44412 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
44413@@ -3458,7 +3458,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
44414 trace_ext4_mb_new_inode_pa(ac, pa);
44415
44416 ext4_mb_use_inode_pa(ac, pa);
44417- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
44418+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
44419
44420 ei = EXT4_I(ac->ac_inode);
44421 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
44422@@ -3518,7 +3518,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
44423 trace_ext4_mb_new_group_pa(ac, pa);
44424
44425 ext4_mb_use_group_pa(ac, pa);
44426- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44427+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44428
44429 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
44430 lg = ac->ac_lg;
44431@@ -3607,7 +3607,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
44432 * from the bitmap and continue.
44433 */
44434 }
44435- atomic_add(free, &sbi->s_mb_discarded);
44436+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
44437
44438 return err;
44439 }
44440@@ -3625,7 +3625,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
44441 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
44442 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
44443 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
44444- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
44445+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
44446 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
44447
44448 return 0;
44449diff --git a/fs/fcntl.c b/fs/fcntl.c
44450index 75e7c1f..1eb3e4d 100644
44451--- a/fs/fcntl.c
44452+++ b/fs/fcntl.c
44453@@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
44454 if (err)
44455 return err;
44456
44457+ if (gr_handle_chroot_fowner(pid, type))
44458+ return -ENOENT;
44459+ if (gr_check_protected_task_fowner(pid, type))
44460+ return -EACCES;
44461+
44462 f_modown(filp, pid, type, force);
44463 return 0;
44464 }
44465@@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
44466
44467 static int f_setown_ex(struct file *filp, unsigned long arg)
44468 {
44469- struct f_owner_ex * __user owner_p = (void * __user)arg;
44470+ struct f_owner_ex __user *owner_p = (void __user *)arg;
44471 struct f_owner_ex owner;
44472 struct pid *pid;
44473 int type;
44474@@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
44475
44476 static int f_getown_ex(struct file *filp, unsigned long arg)
44477 {
44478- struct f_owner_ex * __user owner_p = (void * __user)arg;
44479+ struct f_owner_ex __user *owner_p = (void __user *)arg;
44480 struct f_owner_ex owner;
44481 int ret = 0;
44482
44483@@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
44484 switch (cmd) {
44485 case F_DUPFD:
44486 case F_DUPFD_CLOEXEC:
44487+ gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
44488 if (arg >= rlimit(RLIMIT_NOFILE))
44489 break;
44490 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
44491diff --git a/fs/fifo.c b/fs/fifo.c
44492index b1a524d..4ee270e 100644
44493--- a/fs/fifo.c
44494+++ b/fs/fifo.c
44495@@ -58,10 +58,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
44496 */
44497 filp->f_op = &read_pipefifo_fops;
44498 pipe->r_counter++;
44499- if (pipe->readers++ == 0)
44500+ if (atomic_inc_return(&pipe->readers) == 1)
44501 wake_up_partner(inode);
44502
44503- if (!pipe->writers) {
44504+ if (!atomic_read(&pipe->writers)) {
44505 if ((filp->f_flags & O_NONBLOCK)) {
44506 /* suppress POLLHUP until we have
44507 * seen a writer */
44508@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
44509 * errno=ENXIO when there is no process reading the FIFO.
44510 */
44511 ret = -ENXIO;
44512- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
44513+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
44514 goto err;
44515
44516 filp->f_op = &write_pipefifo_fops;
44517 pipe->w_counter++;
44518- if (!pipe->writers++)
44519+ if (atomic_inc_return(&pipe->writers) == 1)
44520 wake_up_partner(inode);
44521
44522- if (!pipe->readers) {
44523+ if (!atomic_read(&pipe->readers)) {
44524 wait_for_partner(inode, &pipe->r_counter);
44525 if (signal_pending(current))
44526 goto err_wr;
44527@@ -105,11 +105,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
44528 */
44529 filp->f_op = &rdwr_pipefifo_fops;
44530
44531- pipe->readers++;
44532- pipe->writers++;
44533+ atomic_inc(&pipe->readers);
44534+ atomic_inc(&pipe->writers);
44535 pipe->r_counter++;
44536 pipe->w_counter++;
44537- if (pipe->readers == 1 || pipe->writers == 1)
44538+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
44539 wake_up_partner(inode);
44540 break;
44541
44542@@ -123,19 +123,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
44543 return 0;
44544
44545 err_rd:
44546- if (!--pipe->readers)
44547+ if (atomic_dec_and_test(&pipe->readers))
44548 wake_up_interruptible(&pipe->wait);
44549 ret = -ERESTARTSYS;
44550 goto err;
44551
44552 err_wr:
44553- if (!--pipe->writers)
44554+ if (atomic_dec_and_test(&pipe->writers))
44555 wake_up_interruptible(&pipe->wait);
44556 ret = -ERESTARTSYS;
44557 goto err;
44558
44559 err:
44560- if (!pipe->readers && !pipe->writers)
44561+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
44562 free_pipe_info(inode);
44563
44564 err_nocleanup:
44565diff --git a/fs/file.c b/fs/file.c
44566index ba3f605..fade102 100644
44567--- a/fs/file.c
44568+++ b/fs/file.c
44569@@ -15,6 +15,7 @@
44570 #include <linux/slab.h>
44571 #include <linux/vmalloc.h>
44572 #include <linux/file.h>
44573+#include <linux/security.h>
44574 #include <linux/fdtable.h>
44575 #include <linux/bitops.h>
44576 #include <linux/interrupt.h>
44577@@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
44578 * N.B. For clone tasks sharing a files structure, this test
44579 * will limit the total number of files that can be opened.
44580 */
44581+ gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
44582 if (nr >= rlimit(RLIMIT_NOFILE))
44583 return -EMFILE;
44584
44585diff --git a/fs/filesystems.c b/fs/filesystems.c
44586index 96f2428..f5eeb8e 100644
44587--- a/fs/filesystems.c
44588+++ b/fs/filesystems.c
44589@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
44590 int len = dot ? dot - name : strlen(name);
44591
44592 fs = __get_fs_type(name, len);
44593+
44594+#ifdef CONFIG_GRKERNSEC_MODHARDEN
44595+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
44596+#else
44597 if (!fs && (request_module("%.*s", len, name) == 0))
44598+#endif
44599 fs = __get_fs_type(name, len);
44600
44601 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
44602diff --git a/fs/fs_struct.c b/fs/fs_struct.c
44603index e159e68..e7d2a6f 100644
44604--- a/fs/fs_struct.c
44605+++ b/fs/fs_struct.c
44606@@ -4,6 +4,7 @@
44607 #include <linux/path.h>
44608 #include <linux/slab.h>
44609 #include <linux/fs_struct.h>
44610+#include <linux/grsecurity.h>
44611 #include "internal.h"
44612
44613 static inline void path_get_longterm(struct path *path)
44614@@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
44615 write_seqcount_begin(&fs->seq);
44616 old_root = fs->root;
44617 fs->root = *path;
44618+ gr_set_chroot_entries(current, path);
44619 write_seqcount_end(&fs->seq);
44620 spin_unlock(&fs->lock);
44621 if (old_root.dentry)
44622@@ -65,6 +67,17 @@ static inline int replace_path(struct path *p, const struct path *old, const str
44623 return 1;
44624 }
44625
44626+static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
44627+{
44628+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
44629+ return 0;
44630+ *p = *new;
44631+
44632+ gr_set_chroot_entries(task, new);
44633+
44634+ return 1;
44635+}
44636+
44637 void chroot_fs_refs(struct path *old_root, struct path *new_root)
44638 {
44639 struct task_struct *g, *p;
44640@@ -79,7 +92,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
44641 int hits = 0;
44642 spin_lock(&fs->lock);
44643 write_seqcount_begin(&fs->seq);
44644- hits += replace_path(&fs->root, old_root, new_root);
44645+ hits += replace_root_path(p, &fs->root, old_root, new_root);
44646 hits += replace_path(&fs->pwd, old_root, new_root);
44647 write_seqcount_end(&fs->seq);
44648 while (hits--) {
44649@@ -111,7 +124,8 @@ void exit_fs(struct task_struct *tsk)
44650 task_lock(tsk);
44651 spin_lock(&fs->lock);
44652 tsk->fs = NULL;
44653- kill = !--fs->users;
44654+ gr_clear_chroot_entries(tsk);
44655+ kill = !atomic_dec_return(&fs->users);
44656 spin_unlock(&fs->lock);
44657 task_unlock(tsk);
44658 if (kill)
44659@@ -124,7 +138,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
44660 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
44661 /* We don't need to lock fs - think why ;-) */
44662 if (fs) {
44663- fs->users = 1;
44664+ atomic_set(&fs->users, 1);
44665 fs->in_exec = 0;
44666 spin_lock_init(&fs->lock);
44667 seqcount_init(&fs->seq);
44668@@ -133,6 +147,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
44669 spin_lock(&old->lock);
44670 fs->root = old->root;
44671 path_get_longterm(&fs->root);
44672+ /* instead of calling gr_set_chroot_entries here,
44673+ we call it from every caller of this function
44674+ */
44675 fs->pwd = old->pwd;
44676 path_get_longterm(&fs->pwd);
44677 spin_unlock(&old->lock);
44678@@ -151,8 +168,9 @@ int unshare_fs_struct(void)
44679
44680 task_lock(current);
44681 spin_lock(&fs->lock);
44682- kill = !--fs->users;
44683+ kill = !atomic_dec_return(&fs->users);
44684 current->fs = new_fs;
44685+ gr_set_chroot_entries(current, &new_fs->root);
44686 spin_unlock(&fs->lock);
44687 task_unlock(current);
44688
44689@@ -165,13 +183,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
44690
44691 int current_umask(void)
44692 {
44693- return current->fs->umask;
44694+ return current->fs->umask | gr_acl_umask();
44695 }
44696 EXPORT_SYMBOL(current_umask);
44697
44698 /* to be mentioned only in INIT_TASK */
44699 struct fs_struct init_fs = {
44700- .users = 1,
44701+ .users = ATOMIC_INIT(1),
44702 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
44703 .seq = SEQCNT_ZERO,
44704 .umask = 0022,
44705@@ -187,12 +205,13 @@ void daemonize_fs_struct(void)
44706 task_lock(current);
44707
44708 spin_lock(&init_fs.lock);
44709- init_fs.users++;
44710+ atomic_inc(&init_fs.users);
44711 spin_unlock(&init_fs.lock);
44712
44713 spin_lock(&fs->lock);
44714 current->fs = &init_fs;
44715- kill = !--fs->users;
44716+ gr_set_chroot_entries(current, &current->fs->root);
44717+ kill = !atomic_dec_return(&fs->users);
44718 spin_unlock(&fs->lock);
44719
44720 task_unlock(current);
44721diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
44722index 9905350..02eaec4 100644
44723--- a/fs/fscache/cookie.c
44724+++ b/fs/fscache/cookie.c
44725@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
44726 parent ? (char *) parent->def->name : "<no-parent>",
44727 def->name, netfs_data);
44728
44729- fscache_stat(&fscache_n_acquires);
44730+ fscache_stat_unchecked(&fscache_n_acquires);
44731
44732 /* if there's no parent cookie, then we don't create one here either */
44733 if (!parent) {
44734- fscache_stat(&fscache_n_acquires_null);
44735+ fscache_stat_unchecked(&fscache_n_acquires_null);
44736 _leave(" [no parent]");
44737 return NULL;
44738 }
44739@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
44740 /* allocate and initialise a cookie */
44741 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
44742 if (!cookie) {
44743- fscache_stat(&fscache_n_acquires_oom);
44744+ fscache_stat_unchecked(&fscache_n_acquires_oom);
44745 _leave(" [ENOMEM]");
44746 return NULL;
44747 }
44748@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
44749
44750 switch (cookie->def->type) {
44751 case FSCACHE_COOKIE_TYPE_INDEX:
44752- fscache_stat(&fscache_n_cookie_index);
44753+ fscache_stat_unchecked(&fscache_n_cookie_index);
44754 break;
44755 case FSCACHE_COOKIE_TYPE_DATAFILE:
44756- fscache_stat(&fscache_n_cookie_data);
44757+ fscache_stat_unchecked(&fscache_n_cookie_data);
44758 break;
44759 default:
44760- fscache_stat(&fscache_n_cookie_special);
44761+ fscache_stat_unchecked(&fscache_n_cookie_special);
44762 break;
44763 }
44764
44765@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
44766 if (fscache_acquire_non_index_cookie(cookie) < 0) {
44767 atomic_dec(&parent->n_children);
44768 __fscache_cookie_put(cookie);
44769- fscache_stat(&fscache_n_acquires_nobufs);
44770+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
44771 _leave(" = NULL");
44772 return NULL;
44773 }
44774 }
44775
44776- fscache_stat(&fscache_n_acquires_ok);
44777+ fscache_stat_unchecked(&fscache_n_acquires_ok);
44778 _leave(" = %p", cookie);
44779 return cookie;
44780 }
44781@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
44782 cache = fscache_select_cache_for_object(cookie->parent);
44783 if (!cache) {
44784 up_read(&fscache_addremove_sem);
44785- fscache_stat(&fscache_n_acquires_no_cache);
44786+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
44787 _leave(" = -ENOMEDIUM [no cache]");
44788 return -ENOMEDIUM;
44789 }
44790@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
44791 object = cache->ops->alloc_object(cache, cookie);
44792 fscache_stat_d(&fscache_n_cop_alloc_object);
44793 if (IS_ERR(object)) {
44794- fscache_stat(&fscache_n_object_no_alloc);
44795+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
44796 ret = PTR_ERR(object);
44797 goto error;
44798 }
44799
44800- fscache_stat(&fscache_n_object_alloc);
44801+ fscache_stat_unchecked(&fscache_n_object_alloc);
44802
44803 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
44804
44805@@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
44806 struct fscache_object *object;
44807 struct hlist_node *_p;
44808
44809- fscache_stat(&fscache_n_updates);
44810+ fscache_stat_unchecked(&fscache_n_updates);
44811
44812 if (!cookie) {
44813- fscache_stat(&fscache_n_updates_null);
44814+ fscache_stat_unchecked(&fscache_n_updates_null);
44815 _leave(" [no cookie]");
44816 return;
44817 }
44818@@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
44819 struct fscache_object *object;
44820 unsigned long event;
44821
44822- fscache_stat(&fscache_n_relinquishes);
44823+ fscache_stat_unchecked(&fscache_n_relinquishes);
44824 if (retire)
44825- fscache_stat(&fscache_n_relinquishes_retire);
44826+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
44827
44828 if (!cookie) {
44829- fscache_stat(&fscache_n_relinquishes_null);
44830+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
44831 _leave(" [no cookie]");
44832 return;
44833 }
44834@@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
44835
44836 /* wait for the cookie to finish being instantiated (or to fail) */
44837 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
44838- fscache_stat(&fscache_n_relinquishes_waitcrt);
44839+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
44840 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
44841 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
44842 }
44843diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
44844index f6aad48..88dcf26 100644
44845--- a/fs/fscache/internal.h
44846+++ b/fs/fscache/internal.h
44847@@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
44848 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
44849 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
44850
44851-extern atomic_t fscache_n_op_pend;
44852-extern atomic_t fscache_n_op_run;
44853-extern atomic_t fscache_n_op_enqueue;
44854-extern atomic_t fscache_n_op_deferred_release;
44855-extern atomic_t fscache_n_op_release;
44856-extern atomic_t fscache_n_op_gc;
44857-extern atomic_t fscache_n_op_cancelled;
44858-extern atomic_t fscache_n_op_rejected;
44859+extern atomic_unchecked_t fscache_n_op_pend;
44860+extern atomic_unchecked_t fscache_n_op_run;
44861+extern atomic_unchecked_t fscache_n_op_enqueue;
44862+extern atomic_unchecked_t fscache_n_op_deferred_release;
44863+extern atomic_unchecked_t fscache_n_op_release;
44864+extern atomic_unchecked_t fscache_n_op_gc;
44865+extern atomic_unchecked_t fscache_n_op_cancelled;
44866+extern atomic_unchecked_t fscache_n_op_rejected;
44867
44868-extern atomic_t fscache_n_attr_changed;
44869-extern atomic_t fscache_n_attr_changed_ok;
44870-extern atomic_t fscache_n_attr_changed_nobufs;
44871-extern atomic_t fscache_n_attr_changed_nomem;
44872-extern atomic_t fscache_n_attr_changed_calls;
44873+extern atomic_unchecked_t fscache_n_attr_changed;
44874+extern atomic_unchecked_t fscache_n_attr_changed_ok;
44875+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
44876+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
44877+extern atomic_unchecked_t fscache_n_attr_changed_calls;
44878
44879-extern atomic_t fscache_n_allocs;
44880-extern atomic_t fscache_n_allocs_ok;
44881-extern atomic_t fscache_n_allocs_wait;
44882-extern atomic_t fscache_n_allocs_nobufs;
44883-extern atomic_t fscache_n_allocs_intr;
44884-extern atomic_t fscache_n_allocs_object_dead;
44885-extern atomic_t fscache_n_alloc_ops;
44886-extern atomic_t fscache_n_alloc_op_waits;
44887+extern atomic_unchecked_t fscache_n_allocs;
44888+extern atomic_unchecked_t fscache_n_allocs_ok;
44889+extern atomic_unchecked_t fscache_n_allocs_wait;
44890+extern atomic_unchecked_t fscache_n_allocs_nobufs;
44891+extern atomic_unchecked_t fscache_n_allocs_intr;
44892+extern atomic_unchecked_t fscache_n_allocs_object_dead;
44893+extern atomic_unchecked_t fscache_n_alloc_ops;
44894+extern atomic_unchecked_t fscache_n_alloc_op_waits;
44895
44896-extern atomic_t fscache_n_retrievals;
44897-extern atomic_t fscache_n_retrievals_ok;
44898-extern atomic_t fscache_n_retrievals_wait;
44899-extern atomic_t fscache_n_retrievals_nodata;
44900-extern atomic_t fscache_n_retrievals_nobufs;
44901-extern atomic_t fscache_n_retrievals_intr;
44902-extern atomic_t fscache_n_retrievals_nomem;
44903-extern atomic_t fscache_n_retrievals_object_dead;
44904-extern atomic_t fscache_n_retrieval_ops;
44905-extern atomic_t fscache_n_retrieval_op_waits;
44906+extern atomic_unchecked_t fscache_n_retrievals;
44907+extern atomic_unchecked_t fscache_n_retrievals_ok;
44908+extern atomic_unchecked_t fscache_n_retrievals_wait;
44909+extern atomic_unchecked_t fscache_n_retrievals_nodata;
44910+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
44911+extern atomic_unchecked_t fscache_n_retrievals_intr;
44912+extern atomic_unchecked_t fscache_n_retrievals_nomem;
44913+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
44914+extern atomic_unchecked_t fscache_n_retrieval_ops;
44915+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
44916
44917-extern atomic_t fscache_n_stores;
44918-extern atomic_t fscache_n_stores_ok;
44919-extern atomic_t fscache_n_stores_again;
44920-extern atomic_t fscache_n_stores_nobufs;
44921-extern atomic_t fscache_n_stores_oom;
44922-extern atomic_t fscache_n_store_ops;
44923-extern atomic_t fscache_n_store_calls;
44924-extern atomic_t fscache_n_store_pages;
44925-extern atomic_t fscache_n_store_radix_deletes;
44926-extern atomic_t fscache_n_store_pages_over_limit;
44927+extern atomic_unchecked_t fscache_n_stores;
44928+extern atomic_unchecked_t fscache_n_stores_ok;
44929+extern atomic_unchecked_t fscache_n_stores_again;
44930+extern atomic_unchecked_t fscache_n_stores_nobufs;
44931+extern atomic_unchecked_t fscache_n_stores_oom;
44932+extern atomic_unchecked_t fscache_n_store_ops;
44933+extern atomic_unchecked_t fscache_n_store_calls;
44934+extern atomic_unchecked_t fscache_n_store_pages;
44935+extern atomic_unchecked_t fscache_n_store_radix_deletes;
44936+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
44937
44938-extern atomic_t fscache_n_store_vmscan_not_storing;
44939-extern atomic_t fscache_n_store_vmscan_gone;
44940-extern atomic_t fscache_n_store_vmscan_busy;
44941-extern atomic_t fscache_n_store_vmscan_cancelled;
44942+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
44943+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
44944+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
44945+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
44946
44947-extern atomic_t fscache_n_marks;
44948-extern atomic_t fscache_n_uncaches;
44949+extern atomic_unchecked_t fscache_n_marks;
44950+extern atomic_unchecked_t fscache_n_uncaches;
44951
44952-extern atomic_t fscache_n_acquires;
44953-extern atomic_t fscache_n_acquires_null;
44954-extern atomic_t fscache_n_acquires_no_cache;
44955-extern atomic_t fscache_n_acquires_ok;
44956-extern atomic_t fscache_n_acquires_nobufs;
44957-extern atomic_t fscache_n_acquires_oom;
44958+extern atomic_unchecked_t fscache_n_acquires;
44959+extern atomic_unchecked_t fscache_n_acquires_null;
44960+extern atomic_unchecked_t fscache_n_acquires_no_cache;
44961+extern atomic_unchecked_t fscache_n_acquires_ok;
44962+extern atomic_unchecked_t fscache_n_acquires_nobufs;
44963+extern atomic_unchecked_t fscache_n_acquires_oom;
44964
44965-extern atomic_t fscache_n_updates;
44966-extern atomic_t fscache_n_updates_null;
44967-extern atomic_t fscache_n_updates_run;
44968+extern atomic_unchecked_t fscache_n_updates;
44969+extern atomic_unchecked_t fscache_n_updates_null;
44970+extern atomic_unchecked_t fscache_n_updates_run;
44971
44972-extern atomic_t fscache_n_relinquishes;
44973-extern atomic_t fscache_n_relinquishes_null;
44974-extern atomic_t fscache_n_relinquishes_waitcrt;
44975-extern atomic_t fscache_n_relinquishes_retire;
44976+extern atomic_unchecked_t fscache_n_relinquishes;
44977+extern atomic_unchecked_t fscache_n_relinquishes_null;
44978+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
44979+extern atomic_unchecked_t fscache_n_relinquishes_retire;
44980
44981-extern atomic_t fscache_n_cookie_index;
44982-extern atomic_t fscache_n_cookie_data;
44983-extern atomic_t fscache_n_cookie_special;
44984+extern atomic_unchecked_t fscache_n_cookie_index;
44985+extern atomic_unchecked_t fscache_n_cookie_data;
44986+extern atomic_unchecked_t fscache_n_cookie_special;
44987
44988-extern atomic_t fscache_n_object_alloc;
44989-extern atomic_t fscache_n_object_no_alloc;
44990-extern atomic_t fscache_n_object_lookups;
44991-extern atomic_t fscache_n_object_lookups_negative;
44992-extern atomic_t fscache_n_object_lookups_positive;
44993-extern atomic_t fscache_n_object_lookups_timed_out;
44994-extern atomic_t fscache_n_object_created;
44995-extern atomic_t fscache_n_object_avail;
44996-extern atomic_t fscache_n_object_dead;
44997+extern atomic_unchecked_t fscache_n_object_alloc;
44998+extern atomic_unchecked_t fscache_n_object_no_alloc;
44999+extern atomic_unchecked_t fscache_n_object_lookups;
45000+extern atomic_unchecked_t fscache_n_object_lookups_negative;
45001+extern atomic_unchecked_t fscache_n_object_lookups_positive;
45002+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
45003+extern atomic_unchecked_t fscache_n_object_created;
45004+extern atomic_unchecked_t fscache_n_object_avail;
45005+extern atomic_unchecked_t fscache_n_object_dead;
45006
45007-extern atomic_t fscache_n_checkaux_none;
45008-extern atomic_t fscache_n_checkaux_okay;
45009-extern atomic_t fscache_n_checkaux_update;
45010-extern atomic_t fscache_n_checkaux_obsolete;
45011+extern atomic_unchecked_t fscache_n_checkaux_none;
45012+extern atomic_unchecked_t fscache_n_checkaux_okay;
45013+extern atomic_unchecked_t fscache_n_checkaux_update;
45014+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
45015
45016 extern atomic_t fscache_n_cop_alloc_object;
45017 extern atomic_t fscache_n_cop_lookup_object;
45018@@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
45019 atomic_inc(stat);
45020 }
45021
45022+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
45023+{
45024+ atomic_inc_unchecked(stat);
45025+}
45026+
45027 static inline void fscache_stat_d(atomic_t *stat)
45028 {
45029 atomic_dec(stat);
45030@@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
45031
45032 #define __fscache_stat(stat) (NULL)
45033 #define fscache_stat(stat) do {} while (0)
45034+#define fscache_stat_unchecked(stat) do {} while (0)
45035 #define fscache_stat_d(stat) do {} while (0)
45036 #endif
45037
45038diff --git a/fs/fscache/object.c b/fs/fscache/object.c
45039index b6b897c..0ffff9c 100644
45040--- a/fs/fscache/object.c
45041+++ b/fs/fscache/object.c
45042@@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45043 /* update the object metadata on disk */
45044 case FSCACHE_OBJECT_UPDATING:
45045 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
45046- fscache_stat(&fscache_n_updates_run);
45047+ fscache_stat_unchecked(&fscache_n_updates_run);
45048 fscache_stat(&fscache_n_cop_update_object);
45049 object->cache->ops->update_object(object);
45050 fscache_stat_d(&fscache_n_cop_update_object);
45051@@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45052 spin_lock(&object->lock);
45053 object->state = FSCACHE_OBJECT_DEAD;
45054 spin_unlock(&object->lock);
45055- fscache_stat(&fscache_n_object_dead);
45056+ fscache_stat_unchecked(&fscache_n_object_dead);
45057 goto terminal_transit;
45058
45059 /* handle the parent cache of this object being withdrawn from
45060@@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45061 spin_lock(&object->lock);
45062 object->state = FSCACHE_OBJECT_DEAD;
45063 spin_unlock(&object->lock);
45064- fscache_stat(&fscache_n_object_dead);
45065+ fscache_stat_unchecked(&fscache_n_object_dead);
45066 goto terminal_transit;
45067
45068 /* complain about the object being woken up once it is
45069@@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45070 parent->cookie->def->name, cookie->def->name,
45071 object->cache->tag->name);
45072
45073- fscache_stat(&fscache_n_object_lookups);
45074+ fscache_stat_unchecked(&fscache_n_object_lookups);
45075 fscache_stat(&fscache_n_cop_lookup_object);
45076 ret = object->cache->ops->lookup_object(object);
45077 fscache_stat_d(&fscache_n_cop_lookup_object);
45078@@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45079 if (ret == -ETIMEDOUT) {
45080 /* probably stuck behind another object, so move this one to
45081 * the back of the queue */
45082- fscache_stat(&fscache_n_object_lookups_timed_out);
45083+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
45084 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45085 }
45086
45087@@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
45088
45089 spin_lock(&object->lock);
45090 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45091- fscache_stat(&fscache_n_object_lookups_negative);
45092+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
45093
45094 /* transit here to allow write requests to begin stacking up
45095 * and read requests to begin returning ENODATA */
45096@@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
45097 * result, in which case there may be data available */
45098 spin_lock(&object->lock);
45099 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45100- fscache_stat(&fscache_n_object_lookups_positive);
45101+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
45102
45103 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
45104
45105@@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
45106 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45107 } else {
45108 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
45109- fscache_stat(&fscache_n_object_created);
45110+ fscache_stat_unchecked(&fscache_n_object_created);
45111
45112 object->state = FSCACHE_OBJECT_AVAILABLE;
45113 spin_unlock(&object->lock);
45114@@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
45115 fscache_enqueue_dependents(object);
45116
45117 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
45118- fscache_stat(&fscache_n_object_avail);
45119+ fscache_stat_unchecked(&fscache_n_object_avail);
45120
45121 _leave("");
45122 }
45123@@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45124 enum fscache_checkaux result;
45125
45126 if (!object->cookie->def->check_aux) {
45127- fscache_stat(&fscache_n_checkaux_none);
45128+ fscache_stat_unchecked(&fscache_n_checkaux_none);
45129 return FSCACHE_CHECKAUX_OKAY;
45130 }
45131
45132@@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45133 switch (result) {
45134 /* entry okay as is */
45135 case FSCACHE_CHECKAUX_OKAY:
45136- fscache_stat(&fscache_n_checkaux_okay);
45137+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
45138 break;
45139
45140 /* entry requires update */
45141 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
45142- fscache_stat(&fscache_n_checkaux_update);
45143+ fscache_stat_unchecked(&fscache_n_checkaux_update);
45144 break;
45145
45146 /* entry requires deletion */
45147 case FSCACHE_CHECKAUX_OBSOLETE:
45148- fscache_stat(&fscache_n_checkaux_obsolete);
45149+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
45150 break;
45151
45152 default:
45153diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
45154index 30afdfa..2256596 100644
45155--- a/fs/fscache/operation.c
45156+++ b/fs/fscache/operation.c
45157@@ -17,7 +17,7 @@
45158 #include <linux/slab.h>
45159 #include "internal.h"
45160
45161-atomic_t fscache_op_debug_id;
45162+atomic_unchecked_t fscache_op_debug_id;
45163 EXPORT_SYMBOL(fscache_op_debug_id);
45164
45165 /**
45166@@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
45167 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
45168 ASSERTCMP(atomic_read(&op->usage), >, 0);
45169
45170- fscache_stat(&fscache_n_op_enqueue);
45171+ fscache_stat_unchecked(&fscache_n_op_enqueue);
45172 switch (op->flags & FSCACHE_OP_TYPE) {
45173 case FSCACHE_OP_ASYNC:
45174 _debug("queue async");
45175@@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
45176 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
45177 if (op->processor)
45178 fscache_enqueue_operation(op);
45179- fscache_stat(&fscache_n_op_run);
45180+ fscache_stat_unchecked(&fscache_n_op_run);
45181 }
45182
45183 /*
45184@@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45185 if (object->n_ops > 1) {
45186 atomic_inc(&op->usage);
45187 list_add_tail(&op->pend_link, &object->pending_ops);
45188- fscache_stat(&fscache_n_op_pend);
45189+ fscache_stat_unchecked(&fscache_n_op_pend);
45190 } else if (!list_empty(&object->pending_ops)) {
45191 atomic_inc(&op->usage);
45192 list_add_tail(&op->pend_link, &object->pending_ops);
45193- fscache_stat(&fscache_n_op_pend);
45194+ fscache_stat_unchecked(&fscache_n_op_pend);
45195 fscache_start_operations(object);
45196 } else {
45197 ASSERTCMP(object->n_in_progress, ==, 0);
45198@@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45199 object->n_exclusive++; /* reads and writes must wait */
45200 atomic_inc(&op->usage);
45201 list_add_tail(&op->pend_link, &object->pending_ops);
45202- fscache_stat(&fscache_n_op_pend);
45203+ fscache_stat_unchecked(&fscache_n_op_pend);
45204 ret = 0;
45205 } else {
45206 /* not allowed to submit ops in any other state */
45207@@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
45208 if (object->n_exclusive > 0) {
45209 atomic_inc(&op->usage);
45210 list_add_tail(&op->pend_link, &object->pending_ops);
45211- fscache_stat(&fscache_n_op_pend);
45212+ fscache_stat_unchecked(&fscache_n_op_pend);
45213 } else if (!list_empty(&object->pending_ops)) {
45214 atomic_inc(&op->usage);
45215 list_add_tail(&op->pend_link, &object->pending_ops);
45216- fscache_stat(&fscache_n_op_pend);
45217+ fscache_stat_unchecked(&fscache_n_op_pend);
45218 fscache_start_operations(object);
45219 } else {
45220 ASSERTCMP(object->n_exclusive, ==, 0);
45221@@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
45222 object->n_ops++;
45223 atomic_inc(&op->usage);
45224 list_add_tail(&op->pend_link, &object->pending_ops);
45225- fscache_stat(&fscache_n_op_pend);
45226+ fscache_stat_unchecked(&fscache_n_op_pend);
45227 ret = 0;
45228 } else if (object->state == FSCACHE_OBJECT_DYING ||
45229 object->state == FSCACHE_OBJECT_LC_DYING ||
45230 object->state == FSCACHE_OBJECT_WITHDRAWING) {
45231- fscache_stat(&fscache_n_op_rejected);
45232+ fscache_stat_unchecked(&fscache_n_op_rejected);
45233 ret = -ENOBUFS;
45234 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
45235 fscache_report_unexpected_submission(object, op, ostate);
45236@@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
45237
45238 ret = -EBUSY;
45239 if (!list_empty(&op->pend_link)) {
45240- fscache_stat(&fscache_n_op_cancelled);
45241+ fscache_stat_unchecked(&fscache_n_op_cancelled);
45242 list_del_init(&op->pend_link);
45243 object->n_ops--;
45244 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
45245@@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
45246 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
45247 BUG();
45248
45249- fscache_stat(&fscache_n_op_release);
45250+ fscache_stat_unchecked(&fscache_n_op_release);
45251
45252 if (op->release) {
45253 op->release(op);
45254@@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
45255 * lock, and defer it otherwise */
45256 if (!spin_trylock(&object->lock)) {
45257 _debug("defer put");
45258- fscache_stat(&fscache_n_op_deferred_release);
45259+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
45260
45261 cache = object->cache;
45262 spin_lock(&cache->op_gc_list_lock);
45263@@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
45264
45265 _debug("GC DEFERRED REL OBJ%x OP%x",
45266 object->debug_id, op->debug_id);
45267- fscache_stat(&fscache_n_op_gc);
45268+ fscache_stat_unchecked(&fscache_n_op_gc);
45269
45270 ASSERTCMP(atomic_read(&op->usage), ==, 0);
45271
45272diff --git a/fs/fscache/page.c b/fs/fscache/page.c
45273index 3f7a59b..cf196cc 100644
45274--- a/fs/fscache/page.c
45275+++ b/fs/fscache/page.c
45276@@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45277 val = radix_tree_lookup(&cookie->stores, page->index);
45278 if (!val) {
45279 rcu_read_unlock();
45280- fscache_stat(&fscache_n_store_vmscan_not_storing);
45281+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
45282 __fscache_uncache_page(cookie, page);
45283 return true;
45284 }
45285@@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45286 spin_unlock(&cookie->stores_lock);
45287
45288 if (xpage) {
45289- fscache_stat(&fscache_n_store_vmscan_cancelled);
45290- fscache_stat(&fscache_n_store_radix_deletes);
45291+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
45292+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
45293 ASSERTCMP(xpage, ==, page);
45294 } else {
45295- fscache_stat(&fscache_n_store_vmscan_gone);
45296+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
45297 }
45298
45299 wake_up_bit(&cookie->flags, 0);
45300@@ -107,7 +107,7 @@ page_busy:
45301 /* we might want to wait here, but that could deadlock the allocator as
45302 * the work threads writing to the cache may all end up sleeping
45303 * on memory allocation */
45304- fscache_stat(&fscache_n_store_vmscan_busy);
45305+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
45306 return false;
45307 }
45308 EXPORT_SYMBOL(__fscache_maybe_release_page);
45309@@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
45310 FSCACHE_COOKIE_STORING_TAG);
45311 if (!radix_tree_tag_get(&cookie->stores, page->index,
45312 FSCACHE_COOKIE_PENDING_TAG)) {
45313- fscache_stat(&fscache_n_store_radix_deletes);
45314+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
45315 xpage = radix_tree_delete(&cookie->stores, page->index);
45316 }
45317 spin_unlock(&cookie->stores_lock);
45318@@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
45319
45320 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
45321
45322- fscache_stat(&fscache_n_attr_changed_calls);
45323+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
45324
45325 if (fscache_object_is_active(object)) {
45326 fscache_stat(&fscache_n_cop_attr_changed);
45327@@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45328
45329 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45330
45331- fscache_stat(&fscache_n_attr_changed);
45332+ fscache_stat_unchecked(&fscache_n_attr_changed);
45333
45334 op = kzalloc(sizeof(*op), GFP_KERNEL);
45335 if (!op) {
45336- fscache_stat(&fscache_n_attr_changed_nomem);
45337+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
45338 _leave(" = -ENOMEM");
45339 return -ENOMEM;
45340 }
45341@@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45342 if (fscache_submit_exclusive_op(object, op) < 0)
45343 goto nobufs;
45344 spin_unlock(&cookie->lock);
45345- fscache_stat(&fscache_n_attr_changed_ok);
45346+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
45347 fscache_put_operation(op);
45348 _leave(" = 0");
45349 return 0;
45350@@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45351 nobufs:
45352 spin_unlock(&cookie->lock);
45353 kfree(op);
45354- fscache_stat(&fscache_n_attr_changed_nobufs);
45355+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
45356 _leave(" = %d", -ENOBUFS);
45357 return -ENOBUFS;
45358 }
45359@@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
45360 /* allocate a retrieval operation and attempt to submit it */
45361 op = kzalloc(sizeof(*op), GFP_NOIO);
45362 if (!op) {
45363- fscache_stat(&fscache_n_retrievals_nomem);
45364+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45365 return NULL;
45366 }
45367
45368@@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45369 return 0;
45370 }
45371
45372- fscache_stat(&fscache_n_retrievals_wait);
45373+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
45374
45375 jif = jiffies;
45376 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
45377 fscache_wait_bit_interruptible,
45378 TASK_INTERRUPTIBLE) != 0) {
45379- fscache_stat(&fscache_n_retrievals_intr);
45380+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
45381 _leave(" = -ERESTARTSYS");
45382 return -ERESTARTSYS;
45383 }
45384@@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45385 */
45386 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45387 struct fscache_retrieval *op,
45388- atomic_t *stat_op_waits,
45389- atomic_t *stat_object_dead)
45390+ atomic_unchecked_t *stat_op_waits,
45391+ atomic_unchecked_t *stat_object_dead)
45392 {
45393 int ret;
45394
45395@@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45396 goto check_if_dead;
45397
45398 _debug(">>> WT");
45399- fscache_stat(stat_op_waits);
45400+ fscache_stat_unchecked(stat_op_waits);
45401 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
45402 fscache_wait_bit_interruptible,
45403 TASK_INTERRUPTIBLE) < 0) {
45404@@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45405
45406 check_if_dead:
45407 if (unlikely(fscache_object_is_dead(object))) {
45408- fscache_stat(stat_object_dead);
45409+ fscache_stat_unchecked(stat_object_dead);
45410 return -ENOBUFS;
45411 }
45412 return 0;
45413@@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45414
45415 _enter("%p,%p,,,", cookie, page);
45416
45417- fscache_stat(&fscache_n_retrievals);
45418+ fscache_stat_unchecked(&fscache_n_retrievals);
45419
45420 if (hlist_empty(&cookie->backing_objects))
45421 goto nobufs;
45422@@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45423 goto nobufs_unlock;
45424 spin_unlock(&cookie->lock);
45425
45426- fscache_stat(&fscache_n_retrieval_ops);
45427+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
45428
45429 /* pin the netfs read context in case we need to do the actual netfs
45430 * read because we've encountered a cache read failure */
45431@@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45432
45433 error:
45434 if (ret == -ENOMEM)
45435- fscache_stat(&fscache_n_retrievals_nomem);
45436+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45437 else if (ret == -ERESTARTSYS)
45438- fscache_stat(&fscache_n_retrievals_intr);
45439+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
45440 else if (ret == -ENODATA)
45441- fscache_stat(&fscache_n_retrievals_nodata);
45442+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
45443 else if (ret < 0)
45444- fscache_stat(&fscache_n_retrievals_nobufs);
45445+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45446 else
45447- fscache_stat(&fscache_n_retrievals_ok);
45448+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
45449
45450 fscache_put_retrieval(op);
45451 _leave(" = %d", ret);
45452@@ -429,7 +429,7 @@ nobufs_unlock:
45453 spin_unlock(&cookie->lock);
45454 kfree(op);
45455 nobufs:
45456- fscache_stat(&fscache_n_retrievals_nobufs);
45457+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45458 _leave(" = -ENOBUFS");
45459 return -ENOBUFS;
45460 }
45461@@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45462
45463 _enter("%p,,%d,,,", cookie, *nr_pages);
45464
45465- fscache_stat(&fscache_n_retrievals);
45466+ fscache_stat_unchecked(&fscache_n_retrievals);
45467
45468 if (hlist_empty(&cookie->backing_objects))
45469 goto nobufs;
45470@@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45471 goto nobufs_unlock;
45472 spin_unlock(&cookie->lock);
45473
45474- fscache_stat(&fscache_n_retrieval_ops);
45475+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
45476
45477 /* pin the netfs read context in case we need to do the actual netfs
45478 * read because we've encountered a cache read failure */
45479@@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45480
45481 error:
45482 if (ret == -ENOMEM)
45483- fscache_stat(&fscache_n_retrievals_nomem);
45484+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45485 else if (ret == -ERESTARTSYS)
45486- fscache_stat(&fscache_n_retrievals_intr);
45487+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
45488 else if (ret == -ENODATA)
45489- fscache_stat(&fscache_n_retrievals_nodata);
45490+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
45491 else if (ret < 0)
45492- fscache_stat(&fscache_n_retrievals_nobufs);
45493+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45494 else
45495- fscache_stat(&fscache_n_retrievals_ok);
45496+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
45497
45498 fscache_put_retrieval(op);
45499 _leave(" = %d", ret);
45500@@ -545,7 +545,7 @@ nobufs_unlock:
45501 spin_unlock(&cookie->lock);
45502 kfree(op);
45503 nobufs:
45504- fscache_stat(&fscache_n_retrievals_nobufs);
45505+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45506 _leave(" = -ENOBUFS");
45507 return -ENOBUFS;
45508 }
45509@@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45510
45511 _enter("%p,%p,,,", cookie, page);
45512
45513- fscache_stat(&fscache_n_allocs);
45514+ fscache_stat_unchecked(&fscache_n_allocs);
45515
45516 if (hlist_empty(&cookie->backing_objects))
45517 goto nobufs;
45518@@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45519 goto nobufs_unlock;
45520 spin_unlock(&cookie->lock);
45521
45522- fscache_stat(&fscache_n_alloc_ops);
45523+ fscache_stat_unchecked(&fscache_n_alloc_ops);
45524
45525 ret = fscache_wait_for_retrieval_activation(
45526 object, op,
45527@@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45528
45529 error:
45530 if (ret == -ERESTARTSYS)
45531- fscache_stat(&fscache_n_allocs_intr);
45532+ fscache_stat_unchecked(&fscache_n_allocs_intr);
45533 else if (ret < 0)
45534- fscache_stat(&fscache_n_allocs_nobufs);
45535+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
45536 else
45537- fscache_stat(&fscache_n_allocs_ok);
45538+ fscache_stat_unchecked(&fscache_n_allocs_ok);
45539
45540 fscache_put_retrieval(op);
45541 _leave(" = %d", ret);
45542@@ -625,7 +625,7 @@ nobufs_unlock:
45543 spin_unlock(&cookie->lock);
45544 kfree(op);
45545 nobufs:
45546- fscache_stat(&fscache_n_allocs_nobufs);
45547+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
45548 _leave(" = -ENOBUFS");
45549 return -ENOBUFS;
45550 }
45551@@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45552
45553 spin_lock(&cookie->stores_lock);
45554
45555- fscache_stat(&fscache_n_store_calls);
45556+ fscache_stat_unchecked(&fscache_n_store_calls);
45557
45558 /* find a page to store */
45559 page = NULL;
45560@@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45561 page = results[0];
45562 _debug("gang %d [%lx]", n, page->index);
45563 if (page->index > op->store_limit) {
45564- fscache_stat(&fscache_n_store_pages_over_limit);
45565+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
45566 goto superseded;
45567 }
45568
45569@@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45570 spin_unlock(&cookie->stores_lock);
45571 spin_unlock(&object->lock);
45572
45573- fscache_stat(&fscache_n_store_pages);
45574+ fscache_stat_unchecked(&fscache_n_store_pages);
45575 fscache_stat(&fscache_n_cop_write_page);
45576 ret = object->cache->ops->write_page(op, page);
45577 fscache_stat_d(&fscache_n_cop_write_page);
45578@@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45579 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45580 ASSERT(PageFsCache(page));
45581
45582- fscache_stat(&fscache_n_stores);
45583+ fscache_stat_unchecked(&fscache_n_stores);
45584
45585 op = kzalloc(sizeof(*op), GFP_NOIO);
45586 if (!op)
45587@@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45588 spin_unlock(&cookie->stores_lock);
45589 spin_unlock(&object->lock);
45590
45591- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
45592+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
45593 op->store_limit = object->store_limit;
45594
45595 if (fscache_submit_op(object, &op->op) < 0)
45596@@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45597
45598 spin_unlock(&cookie->lock);
45599 radix_tree_preload_end();
45600- fscache_stat(&fscache_n_store_ops);
45601- fscache_stat(&fscache_n_stores_ok);
45602+ fscache_stat_unchecked(&fscache_n_store_ops);
45603+ fscache_stat_unchecked(&fscache_n_stores_ok);
45604
45605 /* the work queue now carries its own ref on the object */
45606 fscache_put_operation(&op->op);
45607@@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45608 return 0;
45609
45610 already_queued:
45611- fscache_stat(&fscache_n_stores_again);
45612+ fscache_stat_unchecked(&fscache_n_stores_again);
45613 already_pending:
45614 spin_unlock(&cookie->stores_lock);
45615 spin_unlock(&object->lock);
45616 spin_unlock(&cookie->lock);
45617 radix_tree_preload_end();
45618 kfree(op);
45619- fscache_stat(&fscache_n_stores_ok);
45620+ fscache_stat_unchecked(&fscache_n_stores_ok);
45621 _leave(" = 0");
45622 return 0;
45623
45624@@ -851,14 +851,14 @@ nobufs:
45625 spin_unlock(&cookie->lock);
45626 radix_tree_preload_end();
45627 kfree(op);
45628- fscache_stat(&fscache_n_stores_nobufs);
45629+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
45630 _leave(" = -ENOBUFS");
45631 return -ENOBUFS;
45632
45633 nomem_free:
45634 kfree(op);
45635 nomem:
45636- fscache_stat(&fscache_n_stores_oom);
45637+ fscache_stat_unchecked(&fscache_n_stores_oom);
45638 _leave(" = -ENOMEM");
45639 return -ENOMEM;
45640 }
45641@@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
45642 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45643 ASSERTCMP(page, !=, NULL);
45644
45645- fscache_stat(&fscache_n_uncaches);
45646+ fscache_stat_unchecked(&fscache_n_uncaches);
45647
45648 /* cache withdrawal may beat us to it */
45649 if (!PageFsCache(page))
45650@@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
45651 unsigned long loop;
45652
45653 #ifdef CONFIG_FSCACHE_STATS
45654- atomic_add(pagevec->nr, &fscache_n_marks);
45655+ atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
45656 #endif
45657
45658 for (loop = 0; loop < pagevec->nr; loop++) {
45659diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
45660index 4765190..2a067f2 100644
45661--- a/fs/fscache/stats.c
45662+++ b/fs/fscache/stats.c
45663@@ -18,95 +18,95 @@
45664 /*
45665 * operation counters
45666 */
45667-atomic_t fscache_n_op_pend;
45668-atomic_t fscache_n_op_run;
45669-atomic_t fscache_n_op_enqueue;
45670-atomic_t fscache_n_op_requeue;
45671-atomic_t fscache_n_op_deferred_release;
45672-atomic_t fscache_n_op_release;
45673-atomic_t fscache_n_op_gc;
45674-atomic_t fscache_n_op_cancelled;
45675-atomic_t fscache_n_op_rejected;
45676+atomic_unchecked_t fscache_n_op_pend;
45677+atomic_unchecked_t fscache_n_op_run;
45678+atomic_unchecked_t fscache_n_op_enqueue;
45679+atomic_unchecked_t fscache_n_op_requeue;
45680+atomic_unchecked_t fscache_n_op_deferred_release;
45681+atomic_unchecked_t fscache_n_op_release;
45682+atomic_unchecked_t fscache_n_op_gc;
45683+atomic_unchecked_t fscache_n_op_cancelled;
45684+atomic_unchecked_t fscache_n_op_rejected;
45685
45686-atomic_t fscache_n_attr_changed;
45687-atomic_t fscache_n_attr_changed_ok;
45688-atomic_t fscache_n_attr_changed_nobufs;
45689-atomic_t fscache_n_attr_changed_nomem;
45690-atomic_t fscache_n_attr_changed_calls;
45691+atomic_unchecked_t fscache_n_attr_changed;
45692+atomic_unchecked_t fscache_n_attr_changed_ok;
45693+atomic_unchecked_t fscache_n_attr_changed_nobufs;
45694+atomic_unchecked_t fscache_n_attr_changed_nomem;
45695+atomic_unchecked_t fscache_n_attr_changed_calls;
45696
45697-atomic_t fscache_n_allocs;
45698-atomic_t fscache_n_allocs_ok;
45699-atomic_t fscache_n_allocs_wait;
45700-atomic_t fscache_n_allocs_nobufs;
45701-atomic_t fscache_n_allocs_intr;
45702-atomic_t fscache_n_allocs_object_dead;
45703-atomic_t fscache_n_alloc_ops;
45704-atomic_t fscache_n_alloc_op_waits;
45705+atomic_unchecked_t fscache_n_allocs;
45706+atomic_unchecked_t fscache_n_allocs_ok;
45707+atomic_unchecked_t fscache_n_allocs_wait;
45708+atomic_unchecked_t fscache_n_allocs_nobufs;
45709+atomic_unchecked_t fscache_n_allocs_intr;
45710+atomic_unchecked_t fscache_n_allocs_object_dead;
45711+atomic_unchecked_t fscache_n_alloc_ops;
45712+atomic_unchecked_t fscache_n_alloc_op_waits;
45713
45714-atomic_t fscache_n_retrievals;
45715-atomic_t fscache_n_retrievals_ok;
45716-atomic_t fscache_n_retrievals_wait;
45717-atomic_t fscache_n_retrievals_nodata;
45718-atomic_t fscache_n_retrievals_nobufs;
45719-atomic_t fscache_n_retrievals_intr;
45720-atomic_t fscache_n_retrievals_nomem;
45721-atomic_t fscache_n_retrievals_object_dead;
45722-atomic_t fscache_n_retrieval_ops;
45723-atomic_t fscache_n_retrieval_op_waits;
45724+atomic_unchecked_t fscache_n_retrievals;
45725+atomic_unchecked_t fscache_n_retrievals_ok;
45726+atomic_unchecked_t fscache_n_retrievals_wait;
45727+atomic_unchecked_t fscache_n_retrievals_nodata;
45728+atomic_unchecked_t fscache_n_retrievals_nobufs;
45729+atomic_unchecked_t fscache_n_retrievals_intr;
45730+atomic_unchecked_t fscache_n_retrievals_nomem;
45731+atomic_unchecked_t fscache_n_retrievals_object_dead;
45732+atomic_unchecked_t fscache_n_retrieval_ops;
45733+atomic_unchecked_t fscache_n_retrieval_op_waits;
45734
45735-atomic_t fscache_n_stores;
45736-atomic_t fscache_n_stores_ok;
45737-atomic_t fscache_n_stores_again;
45738-atomic_t fscache_n_stores_nobufs;
45739-atomic_t fscache_n_stores_oom;
45740-atomic_t fscache_n_store_ops;
45741-atomic_t fscache_n_store_calls;
45742-atomic_t fscache_n_store_pages;
45743-atomic_t fscache_n_store_radix_deletes;
45744-atomic_t fscache_n_store_pages_over_limit;
45745+atomic_unchecked_t fscache_n_stores;
45746+atomic_unchecked_t fscache_n_stores_ok;
45747+atomic_unchecked_t fscache_n_stores_again;
45748+atomic_unchecked_t fscache_n_stores_nobufs;
45749+atomic_unchecked_t fscache_n_stores_oom;
45750+atomic_unchecked_t fscache_n_store_ops;
45751+atomic_unchecked_t fscache_n_store_calls;
45752+atomic_unchecked_t fscache_n_store_pages;
45753+atomic_unchecked_t fscache_n_store_radix_deletes;
45754+atomic_unchecked_t fscache_n_store_pages_over_limit;
45755
45756-atomic_t fscache_n_store_vmscan_not_storing;
45757-atomic_t fscache_n_store_vmscan_gone;
45758-atomic_t fscache_n_store_vmscan_busy;
45759-atomic_t fscache_n_store_vmscan_cancelled;
45760+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45761+atomic_unchecked_t fscache_n_store_vmscan_gone;
45762+atomic_unchecked_t fscache_n_store_vmscan_busy;
45763+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45764
45765-atomic_t fscache_n_marks;
45766-atomic_t fscache_n_uncaches;
45767+atomic_unchecked_t fscache_n_marks;
45768+atomic_unchecked_t fscache_n_uncaches;
45769
45770-atomic_t fscache_n_acquires;
45771-atomic_t fscache_n_acquires_null;
45772-atomic_t fscache_n_acquires_no_cache;
45773-atomic_t fscache_n_acquires_ok;
45774-atomic_t fscache_n_acquires_nobufs;
45775-atomic_t fscache_n_acquires_oom;
45776+atomic_unchecked_t fscache_n_acquires;
45777+atomic_unchecked_t fscache_n_acquires_null;
45778+atomic_unchecked_t fscache_n_acquires_no_cache;
45779+atomic_unchecked_t fscache_n_acquires_ok;
45780+atomic_unchecked_t fscache_n_acquires_nobufs;
45781+atomic_unchecked_t fscache_n_acquires_oom;
45782
45783-atomic_t fscache_n_updates;
45784-atomic_t fscache_n_updates_null;
45785-atomic_t fscache_n_updates_run;
45786+atomic_unchecked_t fscache_n_updates;
45787+atomic_unchecked_t fscache_n_updates_null;
45788+atomic_unchecked_t fscache_n_updates_run;
45789
45790-atomic_t fscache_n_relinquishes;
45791-atomic_t fscache_n_relinquishes_null;
45792-atomic_t fscache_n_relinquishes_waitcrt;
45793-atomic_t fscache_n_relinquishes_retire;
45794+atomic_unchecked_t fscache_n_relinquishes;
45795+atomic_unchecked_t fscache_n_relinquishes_null;
45796+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45797+atomic_unchecked_t fscache_n_relinquishes_retire;
45798
45799-atomic_t fscache_n_cookie_index;
45800-atomic_t fscache_n_cookie_data;
45801-atomic_t fscache_n_cookie_special;
45802+atomic_unchecked_t fscache_n_cookie_index;
45803+atomic_unchecked_t fscache_n_cookie_data;
45804+atomic_unchecked_t fscache_n_cookie_special;
45805
45806-atomic_t fscache_n_object_alloc;
45807-atomic_t fscache_n_object_no_alloc;
45808-atomic_t fscache_n_object_lookups;
45809-atomic_t fscache_n_object_lookups_negative;
45810-atomic_t fscache_n_object_lookups_positive;
45811-atomic_t fscache_n_object_lookups_timed_out;
45812-atomic_t fscache_n_object_created;
45813-atomic_t fscache_n_object_avail;
45814-atomic_t fscache_n_object_dead;
45815+atomic_unchecked_t fscache_n_object_alloc;
45816+atomic_unchecked_t fscache_n_object_no_alloc;
45817+atomic_unchecked_t fscache_n_object_lookups;
45818+atomic_unchecked_t fscache_n_object_lookups_negative;
45819+atomic_unchecked_t fscache_n_object_lookups_positive;
45820+atomic_unchecked_t fscache_n_object_lookups_timed_out;
45821+atomic_unchecked_t fscache_n_object_created;
45822+atomic_unchecked_t fscache_n_object_avail;
45823+atomic_unchecked_t fscache_n_object_dead;
45824
45825-atomic_t fscache_n_checkaux_none;
45826-atomic_t fscache_n_checkaux_okay;
45827-atomic_t fscache_n_checkaux_update;
45828-atomic_t fscache_n_checkaux_obsolete;
45829+atomic_unchecked_t fscache_n_checkaux_none;
45830+atomic_unchecked_t fscache_n_checkaux_okay;
45831+atomic_unchecked_t fscache_n_checkaux_update;
45832+atomic_unchecked_t fscache_n_checkaux_obsolete;
45833
45834 atomic_t fscache_n_cop_alloc_object;
45835 atomic_t fscache_n_cop_lookup_object;
45836@@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
45837 seq_puts(m, "FS-Cache statistics\n");
45838
45839 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
45840- atomic_read(&fscache_n_cookie_index),
45841- atomic_read(&fscache_n_cookie_data),
45842- atomic_read(&fscache_n_cookie_special));
45843+ atomic_read_unchecked(&fscache_n_cookie_index),
45844+ atomic_read_unchecked(&fscache_n_cookie_data),
45845+ atomic_read_unchecked(&fscache_n_cookie_special));
45846
45847 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
45848- atomic_read(&fscache_n_object_alloc),
45849- atomic_read(&fscache_n_object_no_alloc),
45850- atomic_read(&fscache_n_object_avail),
45851- atomic_read(&fscache_n_object_dead));
45852+ atomic_read_unchecked(&fscache_n_object_alloc),
45853+ atomic_read_unchecked(&fscache_n_object_no_alloc),
45854+ atomic_read_unchecked(&fscache_n_object_avail),
45855+ atomic_read_unchecked(&fscache_n_object_dead));
45856 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
45857- atomic_read(&fscache_n_checkaux_none),
45858- atomic_read(&fscache_n_checkaux_okay),
45859- atomic_read(&fscache_n_checkaux_update),
45860- atomic_read(&fscache_n_checkaux_obsolete));
45861+ atomic_read_unchecked(&fscache_n_checkaux_none),
45862+ atomic_read_unchecked(&fscache_n_checkaux_okay),
45863+ atomic_read_unchecked(&fscache_n_checkaux_update),
45864+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
45865
45866 seq_printf(m, "Pages : mrk=%u unc=%u\n",
45867- atomic_read(&fscache_n_marks),
45868- atomic_read(&fscache_n_uncaches));
45869+ atomic_read_unchecked(&fscache_n_marks),
45870+ atomic_read_unchecked(&fscache_n_uncaches));
45871
45872 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
45873 " oom=%u\n",
45874- atomic_read(&fscache_n_acquires),
45875- atomic_read(&fscache_n_acquires_null),
45876- atomic_read(&fscache_n_acquires_no_cache),
45877- atomic_read(&fscache_n_acquires_ok),
45878- atomic_read(&fscache_n_acquires_nobufs),
45879- atomic_read(&fscache_n_acquires_oom));
45880+ atomic_read_unchecked(&fscache_n_acquires),
45881+ atomic_read_unchecked(&fscache_n_acquires_null),
45882+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
45883+ atomic_read_unchecked(&fscache_n_acquires_ok),
45884+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
45885+ atomic_read_unchecked(&fscache_n_acquires_oom));
45886
45887 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
45888- atomic_read(&fscache_n_object_lookups),
45889- atomic_read(&fscache_n_object_lookups_negative),
45890- atomic_read(&fscache_n_object_lookups_positive),
45891- atomic_read(&fscache_n_object_created),
45892- atomic_read(&fscache_n_object_lookups_timed_out));
45893+ atomic_read_unchecked(&fscache_n_object_lookups),
45894+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
45895+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
45896+ atomic_read_unchecked(&fscache_n_object_created),
45897+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
45898
45899 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
45900- atomic_read(&fscache_n_updates),
45901- atomic_read(&fscache_n_updates_null),
45902- atomic_read(&fscache_n_updates_run));
45903+ atomic_read_unchecked(&fscache_n_updates),
45904+ atomic_read_unchecked(&fscache_n_updates_null),
45905+ atomic_read_unchecked(&fscache_n_updates_run));
45906
45907 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
45908- atomic_read(&fscache_n_relinquishes),
45909- atomic_read(&fscache_n_relinquishes_null),
45910- atomic_read(&fscache_n_relinquishes_waitcrt),
45911- atomic_read(&fscache_n_relinquishes_retire));
45912+ atomic_read_unchecked(&fscache_n_relinquishes),
45913+ atomic_read_unchecked(&fscache_n_relinquishes_null),
45914+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
45915+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
45916
45917 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
45918- atomic_read(&fscache_n_attr_changed),
45919- atomic_read(&fscache_n_attr_changed_ok),
45920- atomic_read(&fscache_n_attr_changed_nobufs),
45921- atomic_read(&fscache_n_attr_changed_nomem),
45922- atomic_read(&fscache_n_attr_changed_calls));
45923+ atomic_read_unchecked(&fscache_n_attr_changed),
45924+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
45925+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
45926+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
45927+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
45928
45929 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
45930- atomic_read(&fscache_n_allocs),
45931- atomic_read(&fscache_n_allocs_ok),
45932- atomic_read(&fscache_n_allocs_wait),
45933- atomic_read(&fscache_n_allocs_nobufs),
45934- atomic_read(&fscache_n_allocs_intr));
45935+ atomic_read_unchecked(&fscache_n_allocs),
45936+ atomic_read_unchecked(&fscache_n_allocs_ok),
45937+ atomic_read_unchecked(&fscache_n_allocs_wait),
45938+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
45939+ atomic_read_unchecked(&fscache_n_allocs_intr));
45940 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
45941- atomic_read(&fscache_n_alloc_ops),
45942- atomic_read(&fscache_n_alloc_op_waits),
45943- atomic_read(&fscache_n_allocs_object_dead));
45944+ atomic_read_unchecked(&fscache_n_alloc_ops),
45945+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
45946+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
45947
45948 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
45949 " int=%u oom=%u\n",
45950- atomic_read(&fscache_n_retrievals),
45951- atomic_read(&fscache_n_retrievals_ok),
45952- atomic_read(&fscache_n_retrievals_wait),
45953- atomic_read(&fscache_n_retrievals_nodata),
45954- atomic_read(&fscache_n_retrievals_nobufs),
45955- atomic_read(&fscache_n_retrievals_intr),
45956- atomic_read(&fscache_n_retrievals_nomem));
45957+ atomic_read_unchecked(&fscache_n_retrievals),
45958+ atomic_read_unchecked(&fscache_n_retrievals_ok),
45959+ atomic_read_unchecked(&fscache_n_retrievals_wait),
45960+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
45961+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
45962+ atomic_read_unchecked(&fscache_n_retrievals_intr),
45963+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
45964 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
45965- atomic_read(&fscache_n_retrieval_ops),
45966- atomic_read(&fscache_n_retrieval_op_waits),
45967- atomic_read(&fscache_n_retrievals_object_dead));
45968+ atomic_read_unchecked(&fscache_n_retrieval_ops),
45969+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
45970+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
45971
45972 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
45973- atomic_read(&fscache_n_stores),
45974- atomic_read(&fscache_n_stores_ok),
45975- atomic_read(&fscache_n_stores_again),
45976- atomic_read(&fscache_n_stores_nobufs),
45977- atomic_read(&fscache_n_stores_oom));
45978+ atomic_read_unchecked(&fscache_n_stores),
45979+ atomic_read_unchecked(&fscache_n_stores_ok),
45980+ atomic_read_unchecked(&fscache_n_stores_again),
45981+ atomic_read_unchecked(&fscache_n_stores_nobufs),
45982+ atomic_read_unchecked(&fscache_n_stores_oom));
45983 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
45984- atomic_read(&fscache_n_store_ops),
45985- atomic_read(&fscache_n_store_calls),
45986- atomic_read(&fscache_n_store_pages),
45987- atomic_read(&fscache_n_store_radix_deletes),
45988- atomic_read(&fscache_n_store_pages_over_limit));
45989+ atomic_read_unchecked(&fscache_n_store_ops),
45990+ atomic_read_unchecked(&fscache_n_store_calls),
45991+ atomic_read_unchecked(&fscache_n_store_pages),
45992+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
45993+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
45994
45995 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
45996- atomic_read(&fscache_n_store_vmscan_not_storing),
45997- atomic_read(&fscache_n_store_vmscan_gone),
45998- atomic_read(&fscache_n_store_vmscan_busy),
45999- atomic_read(&fscache_n_store_vmscan_cancelled));
46000+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
46001+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
46002+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
46003+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
46004
46005 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
46006- atomic_read(&fscache_n_op_pend),
46007- atomic_read(&fscache_n_op_run),
46008- atomic_read(&fscache_n_op_enqueue),
46009- atomic_read(&fscache_n_op_cancelled),
46010- atomic_read(&fscache_n_op_rejected));
46011+ atomic_read_unchecked(&fscache_n_op_pend),
46012+ atomic_read_unchecked(&fscache_n_op_run),
46013+ atomic_read_unchecked(&fscache_n_op_enqueue),
46014+ atomic_read_unchecked(&fscache_n_op_cancelled),
46015+ atomic_read_unchecked(&fscache_n_op_rejected));
46016 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
46017- atomic_read(&fscache_n_op_deferred_release),
46018- atomic_read(&fscache_n_op_release),
46019- atomic_read(&fscache_n_op_gc));
46020+ atomic_read_unchecked(&fscache_n_op_deferred_release),
46021+ atomic_read_unchecked(&fscache_n_op_release),
46022+ atomic_read_unchecked(&fscache_n_op_gc));
46023
46024 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
46025 atomic_read(&fscache_n_cop_alloc_object),
46026diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
46027index 3426521..3b75162 100644
46028--- a/fs/fuse/cuse.c
46029+++ b/fs/fuse/cuse.c
46030@@ -587,10 +587,12 @@ static int __init cuse_init(void)
46031 INIT_LIST_HEAD(&cuse_conntbl[i]);
46032
46033 /* inherit and extend fuse_dev_operations */
46034- cuse_channel_fops = fuse_dev_operations;
46035- cuse_channel_fops.owner = THIS_MODULE;
46036- cuse_channel_fops.open = cuse_channel_open;
46037- cuse_channel_fops.release = cuse_channel_release;
46038+ pax_open_kernel();
46039+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
46040+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
46041+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
46042+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
46043+ pax_close_kernel();
46044
46045 cuse_class = class_create(THIS_MODULE, "cuse");
46046 if (IS_ERR(cuse_class))
46047diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
46048index 7df2b5e..5804aa7 100644
46049--- a/fs/fuse/dev.c
46050+++ b/fs/fuse/dev.c
46051@@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
46052 ret = 0;
46053 pipe_lock(pipe);
46054
46055- if (!pipe->readers) {
46056+ if (!atomic_read(&pipe->readers)) {
46057 send_sig(SIGPIPE, current, 0);
46058 if (!ret)
46059 ret = -EPIPE;
46060diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
46061index bc43832..0cfe5a6 100644
46062--- a/fs/fuse/dir.c
46063+++ b/fs/fuse/dir.c
46064@@ -1181,7 +1181,7 @@ static char *read_link(struct dentry *dentry)
46065 return link;
46066 }
46067
46068-static void free_link(char *link)
46069+static void free_link(const char *link)
46070 {
46071 if (!IS_ERR(link))
46072 free_page((unsigned long) link);
46073diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
46074index a9ba244..d9df391 100644
46075--- a/fs/gfs2/inode.c
46076+++ b/fs/gfs2/inode.c
46077@@ -1496,7 +1496,7 @@ out:
46078
46079 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46080 {
46081- char *s = nd_get_link(nd);
46082+ const char *s = nd_get_link(nd);
46083 if (!IS_ERR(s))
46084 kfree(s);
46085 }
46086diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
46087index 001ef01..f7d5f07 100644
46088--- a/fs/hugetlbfs/inode.c
46089+++ b/fs/hugetlbfs/inode.c
46090@@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
46091 .kill_sb = kill_litter_super,
46092 };
46093
46094-static struct vfsmount *hugetlbfs_vfsmount;
46095+struct vfsmount *hugetlbfs_vfsmount;
46096
46097 static int can_do_hugetlb_shm(void)
46098 {
46099diff --git a/fs/inode.c b/fs/inode.c
46100index 9f4f5fe..6214688 100644
46101--- a/fs/inode.c
46102+++ b/fs/inode.c
46103@@ -860,8 +860,8 @@ unsigned int get_next_ino(void)
46104
46105 #ifdef CONFIG_SMP
46106 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
46107- static atomic_t shared_last_ino;
46108- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
46109+ static atomic_unchecked_t shared_last_ino;
46110+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
46111
46112 res = next - LAST_INO_BATCH;
46113 }
46114diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
46115index 4a6cf28..d3a29d3 100644
46116--- a/fs/jffs2/erase.c
46117+++ b/fs/jffs2/erase.c
46118@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
46119 struct jffs2_unknown_node marker = {
46120 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
46121 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46122- .totlen = cpu_to_je32(c->cleanmarker_size)
46123+ .totlen = cpu_to_je32(c->cleanmarker_size),
46124+ .hdr_crc = cpu_to_je32(0)
46125 };
46126
46127 jffs2_prealloc_raw_node_refs(c, jeb, 1);
46128diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
46129index 74d9be1..d5dd140 100644
46130--- a/fs/jffs2/wbuf.c
46131+++ b/fs/jffs2/wbuf.c
46132@@ -1022,7 +1022,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
46133 {
46134 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
46135 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46136- .totlen = constant_cpu_to_je32(8)
46137+ .totlen = constant_cpu_to_je32(8),
46138+ .hdr_crc = constant_cpu_to_je32(0)
46139 };
46140
46141 /*
46142diff --git a/fs/jfs/super.c b/fs/jfs/super.c
46143index 4a82950..bcaa0cb 100644
46144--- a/fs/jfs/super.c
46145+++ b/fs/jfs/super.c
46146@@ -801,7 +801,7 @@ static int __init init_jfs_fs(void)
46147
46148 jfs_inode_cachep =
46149 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
46150- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
46151+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
46152 init_once);
46153 if (jfs_inode_cachep == NULL)
46154 return -ENOMEM;
46155diff --git a/fs/libfs.c b/fs/libfs.c
46156index 18d08f5..fe3dc64 100644
46157--- a/fs/libfs.c
46158+++ b/fs/libfs.c
46159@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46160
46161 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
46162 struct dentry *next;
46163+ char d_name[sizeof(next->d_iname)];
46164+ const unsigned char *name;
46165+
46166 next = list_entry(p, struct dentry, d_u.d_child);
46167 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
46168 if (!simple_positive(next)) {
46169@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46170
46171 spin_unlock(&next->d_lock);
46172 spin_unlock(&dentry->d_lock);
46173- if (filldir(dirent, next->d_name.name,
46174+ name = next->d_name.name;
46175+ if (name == next->d_iname) {
46176+ memcpy(d_name, name, next->d_name.len);
46177+ name = d_name;
46178+ }
46179+ if (filldir(dirent, name,
46180 next->d_name.len, filp->f_pos,
46181 next->d_inode->i_ino,
46182 dt_type(next->d_inode)) < 0)
46183diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
46184index 8392cb8..80d6193 100644
46185--- a/fs/lockd/clntproc.c
46186+++ b/fs/lockd/clntproc.c
46187@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
46188 /*
46189 * Cookie counter for NLM requests
46190 */
46191-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
46192+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
46193
46194 void nlmclnt_next_cookie(struct nlm_cookie *c)
46195 {
46196- u32 cookie = atomic_inc_return(&nlm_cookie);
46197+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
46198
46199 memcpy(c->data, &cookie, 4);
46200 c->len=4;
46201diff --git a/fs/locks.c b/fs/locks.c
46202index 0d68f1f..f216b79 100644
46203--- a/fs/locks.c
46204+++ b/fs/locks.c
46205@@ -2075,16 +2075,16 @@ void locks_remove_flock(struct file *filp)
46206 return;
46207
46208 if (filp->f_op && filp->f_op->flock) {
46209- struct file_lock fl = {
46210+ struct file_lock flock = {
46211 .fl_pid = current->tgid,
46212 .fl_file = filp,
46213 .fl_flags = FL_FLOCK,
46214 .fl_type = F_UNLCK,
46215 .fl_end = OFFSET_MAX,
46216 };
46217- filp->f_op->flock(filp, F_SETLKW, &fl);
46218- if (fl.fl_ops && fl.fl_ops->fl_release_private)
46219- fl.fl_ops->fl_release_private(&fl);
46220+ filp->f_op->flock(filp, F_SETLKW, &flock);
46221+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
46222+ flock.fl_ops->fl_release_private(&flock);
46223 }
46224
46225 lock_flocks();
46226diff --git a/fs/namei.c b/fs/namei.c
46227index c427919..e37fd3f 100644
46228--- a/fs/namei.c
46229+++ b/fs/namei.c
46230@@ -278,16 +278,32 @@ int generic_permission(struct inode *inode, int mask)
46231 if (ret != -EACCES)
46232 return ret;
46233
46234+#ifdef CONFIG_GRKERNSEC
46235+ /* we'll block if we have to log due to a denied capability use */
46236+ if (mask & MAY_NOT_BLOCK)
46237+ return -ECHILD;
46238+#endif
46239+
46240 if (S_ISDIR(inode->i_mode)) {
46241 /* DACs are overridable for directories */
46242- if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46243- return 0;
46244 if (!(mask & MAY_WRITE))
46245- if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46246+ if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
46247+ ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46248 return 0;
46249+ if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46250+ return 0;
46251 return -EACCES;
46252 }
46253 /*
46254+ * Searching includes executable on directories, else just read.
46255+ */
46256+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
46257+ if (mask == MAY_READ)
46258+ if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
46259+ ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46260+ return 0;
46261+
46262+ /*
46263 * Read/write DACs are always overridable.
46264 * Executable DACs are overridable when there is
46265 * at least one exec bit set.
46266@@ -296,14 +312,6 @@ int generic_permission(struct inode *inode, int mask)
46267 if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46268 return 0;
46269
46270- /*
46271- * Searching includes executable on directories, else just read.
46272- */
46273- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
46274- if (mask == MAY_READ)
46275- if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46276- return 0;
46277-
46278 return -EACCES;
46279 }
46280
46281@@ -652,11 +660,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
46282 return error;
46283 }
46284
46285+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
46286+ dentry->d_inode, dentry, nd->path.mnt)) {
46287+ error = -EACCES;
46288+ *p = ERR_PTR(error); /* no ->put_link(), please */
46289+ path_put(&nd->path);
46290+ return error;
46291+ }
46292+
46293 nd->last_type = LAST_BIND;
46294 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
46295 error = PTR_ERR(*p);
46296 if (!IS_ERR(*p)) {
46297- char *s = nd_get_link(nd);
46298+ const char *s = nd_get_link(nd);
46299 error = 0;
46300 if (s)
46301 error = __vfs_follow_link(nd, s);
46302@@ -1753,6 +1769,21 @@ static int path_lookupat(int dfd, const char *name,
46303 if (!err)
46304 err = complete_walk(nd);
46305
46306+ if (!(nd->flags & LOOKUP_PARENT)) {
46307+#ifdef CONFIG_GRKERNSEC
46308+ if (flags & LOOKUP_RCU) {
46309+ if (!err)
46310+ path_put(&nd->path);
46311+ err = -ECHILD;
46312+ } else
46313+#endif
46314+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46315+ if (!err)
46316+ path_put(&nd->path);
46317+ err = -ENOENT;
46318+ }
46319+ }
46320+
46321 if (!err && nd->flags & LOOKUP_DIRECTORY) {
46322 if (!nd->inode->i_op->lookup) {
46323 path_put(&nd->path);
46324@@ -1780,6 +1811,15 @@ static int do_path_lookup(int dfd, const char *name,
46325 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
46326
46327 if (likely(!retval)) {
46328+ if (*name != '/' && nd->path.dentry && nd->inode) {
46329+#ifdef CONFIG_GRKERNSEC
46330+ if (flags & LOOKUP_RCU)
46331+ return -ECHILD;
46332+#endif
46333+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
46334+ return -ENOENT;
46335+ }
46336+
46337 if (unlikely(!audit_dummy_context())) {
46338 if (nd->path.dentry && nd->inode)
46339 audit_inode(name, nd->path.dentry);
46340@@ -2126,6 +2166,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
46341 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
46342 return -EPERM;
46343
46344+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
46345+ return -EPERM;
46346+ if (gr_handle_rawio(inode))
46347+ return -EPERM;
46348+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
46349+ return -EACCES;
46350+
46351 return 0;
46352 }
46353
46354@@ -2187,6 +2234,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46355 error = complete_walk(nd);
46356 if (error)
46357 return ERR_PTR(error);
46358+#ifdef CONFIG_GRKERNSEC
46359+ if (nd->flags & LOOKUP_RCU) {
46360+ error = -ECHILD;
46361+ goto exit;
46362+ }
46363+#endif
46364+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46365+ error = -ENOENT;
46366+ goto exit;
46367+ }
46368 audit_inode(pathname, nd->path.dentry);
46369 if (open_flag & O_CREAT) {
46370 error = -EISDIR;
46371@@ -2197,6 +2254,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46372 error = complete_walk(nd);
46373 if (error)
46374 return ERR_PTR(error);
46375+#ifdef CONFIG_GRKERNSEC
46376+ if (nd->flags & LOOKUP_RCU) {
46377+ error = -ECHILD;
46378+ goto exit;
46379+ }
46380+#endif
46381+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
46382+ error = -ENOENT;
46383+ goto exit;
46384+ }
46385 audit_inode(pathname, dir);
46386 goto ok;
46387 }
46388@@ -2218,6 +2285,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46389 error = complete_walk(nd);
46390 if (error)
46391 return ERR_PTR(error);
46392+#ifdef CONFIG_GRKERNSEC
46393+ if (nd->flags & LOOKUP_RCU) {
46394+ error = -ECHILD;
46395+ goto exit;
46396+ }
46397+#endif
46398+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46399+ error = -ENOENT;
46400+ goto exit;
46401+ }
46402
46403 error = -ENOTDIR;
46404 if (nd->flags & LOOKUP_DIRECTORY) {
46405@@ -2258,6 +2335,12 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46406 /* Negative dentry, just create the file */
46407 if (!dentry->d_inode) {
46408 umode_t mode = op->mode;
46409+
46410+ if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
46411+ error = -EACCES;
46412+ goto exit_mutex_unlock;
46413+ }
46414+
46415 if (!IS_POSIXACL(dir->d_inode))
46416 mode &= ~current_umask();
46417 /*
46418@@ -2281,6 +2364,8 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46419 error = vfs_create(dir->d_inode, dentry, mode, nd);
46420 if (error)
46421 goto exit_mutex_unlock;
46422+ else
46423+ gr_handle_create(path->dentry, path->mnt);
46424 mutex_unlock(&dir->d_inode->i_mutex);
46425 dput(nd->path.dentry);
46426 nd->path.dentry = dentry;
46427@@ -2290,6 +2375,19 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46428 /*
46429 * It already exists.
46430 */
46431+
46432+ if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
46433+ error = -ENOENT;
46434+ goto exit_mutex_unlock;
46435+ }
46436+
46437+ /* only check if O_CREAT is specified, all other checks need to go
46438+ into may_open */
46439+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
46440+ error = -EACCES;
46441+ goto exit_mutex_unlock;
46442+ }
46443+
46444 mutex_unlock(&dir->d_inode->i_mutex);
46445 audit_inode(pathname, path->dentry);
46446
46447@@ -2502,6 +2600,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
46448 *path = nd.path;
46449 return dentry;
46450 eexist:
46451+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
46452+ dput(dentry);
46453+ dentry = ERR_PTR(-ENOENT);
46454+ goto fail;
46455+ }
46456 dput(dentry);
46457 dentry = ERR_PTR(-EEXIST);
46458 fail:
46459@@ -2524,6 +2627,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
46460 }
46461 EXPORT_SYMBOL(user_path_create);
46462
46463+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
46464+{
46465+ char *tmp = getname(pathname);
46466+ struct dentry *res;
46467+ if (IS_ERR(tmp))
46468+ return ERR_CAST(tmp);
46469+ res = kern_path_create(dfd, tmp, path, is_dir);
46470+ if (IS_ERR(res))
46471+ putname(tmp);
46472+ else
46473+ *to = tmp;
46474+ return res;
46475+}
46476+
46477 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
46478 {
46479 int error = may_create(dir, dentry);
46480@@ -2591,6 +2708,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
46481 error = mnt_want_write(path.mnt);
46482 if (error)
46483 goto out_dput;
46484+
46485+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
46486+ error = -EPERM;
46487+ goto out_drop_write;
46488+ }
46489+
46490+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
46491+ error = -EACCES;
46492+ goto out_drop_write;
46493+ }
46494+
46495 error = security_path_mknod(&path, dentry, mode, dev);
46496 if (error)
46497 goto out_drop_write;
46498@@ -2608,6 +2736,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
46499 }
46500 out_drop_write:
46501 mnt_drop_write(path.mnt);
46502+
46503+ if (!error)
46504+ gr_handle_create(dentry, path.mnt);
46505 out_dput:
46506 dput(dentry);
46507 mutex_unlock(&path.dentry->d_inode->i_mutex);
46508@@ -2661,12 +2792,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
46509 error = mnt_want_write(path.mnt);
46510 if (error)
46511 goto out_dput;
46512+
46513+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
46514+ error = -EACCES;
46515+ goto out_drop_write;
46516+ }
46517+
46518 error = security_path_mkdir(&path, dentry, mode);
46519 if (error)
46520 goto out_drop_write;
46521 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
46522 out_drop_write:
46523 mnt_drop_write(path.mnt);
46524+
46525+ if (!error)
46526+ gr_handle_create(dentry, path.mnt);
46527 out_dput:
46528 dput(dentry);
46529 mutex_unlock(&path.dentry->d_inode->i_mutex);
46530@@ -2746,6 +2886,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
46531 char * name;
46532 struct dentry *dentry;
46533 struct nameidata nd;
46534+ ino_t saved_ino = 0;
46535+ dev_t saved_dev = 0;
46536
46537 error = user_path_parent(dfd, pathname, &nd, &name);
46538 if (error)
46539@@ -2774,6 +2916,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
46540 error = -ENOENT;
46541 goto exit3;
46542 }
46543+
46544+ saved_ino = dentry->d_inode->i_ino;
46545+ saved_dev = gr_get_dev_from_dentry(dentry);
46546+
46547+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
46548+ error = -EACCES;
46549+ goto exit3;
46550+ }
46551+
46552 error = mnt_want_write(nd.path.mnt);
46553 if (error)
46554 goto exit3;
46555@@ -2781,6 +2932,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
46556 if (error)
46557 goto exit4;
46558 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
46559+ if (!error && (saved_dev || saved_ino))
46560+ gr_handle_delete(saved_ino, saved_dev);
46561 exit4:
46562 mnt_drop_write(nd.path.mnt);
46563 exit3:
46564@@ -2843,6 +2996,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46565 struct dentry *dentry;
46566 struct nameidata nd;
46567 struct inode *inode = NULL;
46568+ ino_t saved_ino = 0;
46569+ dev_t saved_dev = 0;
46570
46571 error = user_path_parent(dfd, pathname, &nd, &name);
46572 if (error)
46573@@ -2865,6 +3020,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46574 if (!inode)
46575 goto slashes;
46576 ihold(inode);
46577+
46578+ if (inode->i_nlink <= 1) {
46579+ saved_ino = inode->i_ino;
46580+ saved_dev = gr_get_dev_from_dentry(dentry);
46581+ }
46582+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
46583+ error = -EACCES;
46584+ goto exit2;
46585+ }
46586+
46587 error = mnt_want_write(nd.path.mnt);
46588 if (error)
46589 goto exit2;
46590@@ -2872,6 +3037,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46591 if (error)
46592 goto exit3;
46593 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
46594+ if (!error && (saved_ino || saved_dev))
46595+ gr_handle_delete(saved_ino, saved_dev);
46596 exit3:
46597 mnt_drop_write(nd.path.mnt);
46598 exit2:
46599@@ -2947,10 +3114,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
46600 error = mnt_want_write(path.mnt);
46601 if (error)
46602 goto out_dput;
46603+
46604+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
46605+ error = -EACCES;
46606+ goto out_drop_write;
46607+ }
46608+
46609 error = security_path_symlink(&path, dentry, from);
46610 if (error)
46611 goto out_drop_write;
46612 error = vfs_symlink(path.dentry->d_inode, dentry, from);
46613+ if (!error)
46614+ gr_handle_create(dentry, path.mnt);
46615 out_drop_write:
46616 mnt_drop_write(path.mnt);
46617 out_dput:
46618@@ -3025,6 +3200,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
46619 {
46620 struct dentry *new_dentry;
46621 struct path old_path, new_path;
46622+ char *to = NULL;
46623 int how = 0;
46624 int error;
46625
46626@@ -3048,7 +3224,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
46627 if (error)
46628 return error;
46629
46630- new_dentry = user_path_create(newdfd, newname, &new_path, 0);
46631+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
46632 error = PTR_ERR(new_dentry);
46633 if (IS_ERR(new_dentry))
46634 goto out;
46635@@ -3059,13 +3235,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
46636 error = mnt_want_write(new_path.mnt);
46637 if (error)
46638 goto out_dput;
46639+
46640+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
46641+ old_path.dentry->d_inode,
46642+ old_path.dentry->d_inode->i_mode, to)) {
46643+ error = -EACCES;
46644+ goto out_drop_write;
46645+ }
46646+
46647+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
46648+ old_path.dentry, old_path.mnt, to)) {
46649+ error = -EACCES;
46650+ goto out_drop_write;
46651+ }
46652+
46653 error = security_path_link(old_path.dentry, &new_path, new_dentry);
46654 if (error)
46655 goto out_drop_write;
46656 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
46657+ if (!error)
46658+ gr_handle_create(new_dentry, new_path.mnt);
46659 out_drop_write:
46660 mnt_drop_write(new_path.mnt);
46661 out_dput:
46662+ putname(to);
46663 dput(new_dentry);
46664 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
46665 path_put(&new_path);
46666@@ -3299,6 +3492,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
46667 if (new_dentry == trap)
46668 goto exit5;
46669
46670+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
46671+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
46672+ to);
46673+ if (error)
46674+ goto exit5;
46675+
46676 error = mnt_want_write(oldnd.path.mnt);
46677 if (error)
46678 goto exit5;
46679@@ -3308,6 +3507,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
46680 goto exit6;
46681 error = vfs_rename(old_dir->d_inode, old_dentry,
46682 new_dir->d_inode, new_dentry);
46683+ if (!error)
46684+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
46685+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
46686 exit6:
46687 mnt_drop_write(oldnd.path.mnt);
46688 exit5:
46689@@ -3333,6 +3535,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
46690
46691 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
46692 {
46693+ char tmpbuf[64];
46694+ const char *newlink;
46695 int len;
46696
46697 len = PTR_ERR(link);
46698@@ -3342,7 +3546,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
46699 len = strlen(link);
46700 if (len > (unsigned) buflen)
46701 len = buflen;
46702- if (copy_to_user(buffer, link, len))
46703+
46704+ if (len < sizeof(tmpbuf)) {
46705+ memcpy(tmpbuf, link, len);
46706+ newlink = tmpbuf;
46707+ } else
46708+ newlink = link;
46709+
46710+ if (copy_to_user(buffer, newlink, len))
46711 len = -EFAULT;
46712 out:
46713 return len;
46714diff --git a/fs/namespace.c b/fs/namespace.c
46715index 4e46539..b28253c 100644
46716--- a/fs/namespace.c
46717+++ b/fs/namespace.c
46718@@ -1156,6 +1156,9 @@ static int do_umount(struct mount *mnt, int flags)
46719 if (!(sb->s_flags & MS_RDONLY))
46720 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
46721 up_write(&sb->s_umount);
46722+
46723+ gr_log_remount(mnt->mnt_devname, retval);
46724+
46725 return retval;
46726 }
46727
46728@@ -1175,6 +1178,9 @@ static int do_umount(struct mount *mnt, int flags)
46729 br_write_unlock(vfsmount_lock);
46730 up_write(&namespace_sem);
46731 release_mounts(&umount_list);
46732+
46733+ gr_log_unmount(mnt->mnt_devname, retval);
46734+
46735 return retval;
46736 }
46737
46738@@ -2176,6 +2182,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
46739 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
46740 MS_STRICTATIME);
46741
46742+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
46743+ retval = -EPERM;
46744+ goto dput_out;
46745+ }
46746+
46747+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
46748+ retval = -EPERM;
46749+ goto dput_out;
46750+ }
46751+
46752 if (flags & MS_REMOUNT)
46753 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
46754 data_page);
46755@@ -2190,6 +2206,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
46756 dev_name, data_page);
46757 dput_out:
46758 path_put(&path);
46759+
46760+ gr_log_mount(dev_name, dir_name, retval);
46761+
46762 return retval;
46763 }
46764
46765@@ -2471,6 +2490,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
46766 if (error)
46767 goto out2;
46768
46769+ if (gr_handle_chroot_pivot()) {
46770+ error = -EPERM;
46771+ goto out2;
46772+ }
46773+
46774 get_fs_root(current->fs, &root);
46775 error = lock_mount(&old);
46776 if (error)
46777diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
46778index e8bbfa5..864f936 100644
46779--- a/fs/nfs/inode.c
46780+++ b/fs/nfs/inode.c
46781@@ -152,7 +152,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
46782 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
46783 nfsi->attrtimeo_timestamp = jiffies;
46784
46785- memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
46786+ memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
46787 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
46788 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
46789 else
46790@@ -1005,16 +1005,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
46791 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
46792 }
46793
46794-static atomic_long_t nfs_attr_generation_counter;
46795+static atomic_long_unchecked_t nfs_attr_generation_counter;
46796
46797 static unsigned long nfs_read_attr_generation_counter(void)
46798 {
46799- return atomic_long_read(&nfs_attr_generation_counter);
46800+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
46801 }
46802
46803 unsigned long nfs_inc_attr_generation_counter(void)
46804 {
46805- return atomic_long_inc_return(&nfs_attr_generation_counter);
46806+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
46807 }
46808
46809 void nfs_fattr_init(struct nfs_fattr *fattr)
46810diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
46811index 5686661..80a9a3a 100644
46812--- a/fs/nfsd/vfs.c
46813+++ b/fs/nfsd/vfs.c
46814@@ -933,7 +933,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
46815 } else {
46816 oldfs = get_fs();
46817 set_fs(KERNEL_DS);
46818- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
46819+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
46820 set_fs(oldfs);
46821 }
46822
46823@@ -1037,7 +1037,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
46824
46825 /* Write the data. */
46826 oldfs = get_fs(); set_fs(KERNEL_DS);
46827- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
46828+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
46829 set_fs(oldfs);
46830 if (host_err < 0)
46831 goto out_nfserr;
46832@@ -1573,7 +1573,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
46833 */
46834
46835 oldfs = get_fs(); set_fs(KERNEL_DS);
46836- host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
46837+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
46838 set_fs(oldfs);
46839
46840 if (host_err < 0)
46841diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
46842index 3568c8a..e0240d8 100644
46843--- a/fs/notify/fanotify/fanotify_user.c
46844+++ b/fs/notify/fanotify/fanotify_user.c
46845@@ -278,7 +278,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
46846 goto out_close_fd;
46847
46848 ret = -EFAULT;
46849- if (copy_to_user(buf, &fanotify_event_metadata,
46850+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
46851+ copy_to_user(buf, &fanotify_event_metadata,
46852 fanotify_event_metadata.event_len))
46853 goto out_kill_access_response;
46854
46855diff --git a/fs/notify/notification.c b/fs/notify/notification.c
46856index c887b13..0fdf472 100644
46857--- a/fs/notify/notification.c
46858+++ b/fs/notify/notification.c
46859@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
46860 * get set to 0 so it will never get 'freed'
46861 */
46862 static struct fsnotify_event *q_overflow_event;
46863-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
46864+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
46865
46866 /**
46867 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
46868@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
46869 */
46870 u32 fsnotify_get_cookie(void)
46871 {
46872- return atomic_inc_return(&fsnotify_sync_cookie);
46873+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
46874 }
46875 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
46876
46877diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
46878index 99e3610..02c1068 100644
46879--- a/fs/ntfs/dir.c
46880+++ b/fs/ntfs/dir.c
46881@@ -1329,7 +1329,7 @@ find_next_index_buffer:
46882 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
46883 ~(s64)(ndir->itype.index.block_size - 1)));
46884 /* Bounds checks. */
46885- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
46886+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
46887 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
46888 "inode 0x%lx or driver bug.", vdir->i_ino);
46889 goto err_out;
46890diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
46891index 8639169..76697aa 100644
46892--- a/fs/ntfs/file.c
46893+++ b/fs/ntfs/file.c
46894@@ -2229,6 +2229,6 @@ const struct inode_operations ntfs_file_inode_ops = {
46895 #endif /* NTFS_RW */
46896 };
46897
46898-const struct file_operations ntfs_empty_file_ops = {};
46899+const struct file_operations ntfs_empty_file_ops __read_only;
46900
46901-const struct inode_operations ntfs_empty_inode_ops = {};
46902+const struct inode_operations ntfs_empty_inode_ops __read_only;
46903diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
46904index 210c352..a174f83 100644
46905--- a/fs/ocfs2/localalloc.c
46906+++ b/fs/ocfs2/localalloc.c
46907@@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
46908 goto bail;
46909 }
46910
46911- atomic_inc(&osb->alloc_stats.moves);
46912+ atomic_inc_unchecked(&osb->alloc_stats.moves);
46913
46914 bail:
46915 if (handle)
46916diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
46917index d355e6e..578d905 100644
46918--- a/fs/ocfs2/ocfs2.h
46919+++ b/fs/ocfs2/ocfs2.h
46920@@ -235,11 +235,11 @@ enum ocfs2_vol_state
46921
46922 struct ocfs2_alloc_stats
46923 {
46924- atomic_t moves;
46925- atomic_t local_data;
46926- atomic_t bitmap_data;
46927- atomic_t bg_allocs;
46928- atomic_t bg_extends;
46929+ atomic_unchecked_t moves;
46930+ atomic_unchecked_t local_data;
46931+ atomic_unchecked_t bitmap_data;
46932+ atomic_unchecked_t bg_allocs;
46933+ atomic_unchecked_t bg_extends;
46934 };
46935
46936 enum ocfs2_local_alloc_state
46937diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
46938index f169da4..9112253 100644
46939--- a/fs/ocfs2/suballoc.c
46940+++ b/fs/ocfs2/suballoc.c
46941@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
46942 mlog_errno(status);
46943 goto bail;
46944 }
46945- atomic_inc(&osb->alloc_stats.bg_extends);
46946+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
46947
46948 /* You should never ask for this much metadata */
46949 BUG_ON(bits_wanted >
46950@@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
46951 mlog_errno(status);
46952 goto bail;
46953 }
46954- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46955+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46956
46957 *suballoc_loc = res.sr_bg_blkno;
46958 *suballoc_bit_start = res.sr_bit_offset;
46959@@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
46960 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
46961 res->sr_bits);
46962
46963- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46964+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46965
46966 BUG_ON(res->sr_bits != 1);
46967
46968@@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
46969 mlog_errno(status);
46970 goto bail;
46971 }
46972- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46973+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46974
46975 BUG_ON(res.sr_bits != 1);
46976
46977@@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
46978 cluster_start,
46979 num_clusters);
46980 if (!status)
46981- atomic_inc(&osb->alloc_stats.local_data);
46982+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
46983 } else {
46984 if (min_clusters > (osb->bitmap_cpg - 1)) {
46985 /* The only paths asking for contiguousness
46986@@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
46987 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
46988 res.sr_bg_blkno,
46989 res.sr_bit_offset);
46990- atomic_inc(&osb->alloc_stats.bitmap_data);
46991+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
46992 *num_clusters = res.sr_bits;
46993 }
46994 }
46995diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
46996index 68f4541..89cfe6a 100644
46997--- a/fs/ocfs2/super.c
46998+++ b/fs/ocfs2/super.c
46999@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
47000 "%10s => GlobalAllocs: %d LocalAllocs: %d "
47001 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
47002 "Stats",
47003- atomic_read(&osb->alloc_stats.bitmap_data),
47004- atomic_read(&osb->alloc_stats.local_data),
47005- atomic_read(&osb->alloc_stats.bg_allocs),
47006- atomic_read(&osb->alloc_stats.moves),
47007- atomic_read(&osb->alloc_stats.bg_extends));
47008+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
47009+ atomic_read_unchecked(&osb->alloc_stats.local_data),
47010+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
47011+ atomic_read_unchecked(&osb->alloc_stats.moves),
47012+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
47013
47014 out += snprintf(buf + out, len - out,
47015 "%10s => State: %u Descriptor: %llu Size: %u bits "
47016@@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
47017 spin_lock_init(&osb->osb_xattr_lock);
47018 ocfs2_init_steal_slots(osb);
47019
47020- atomic_set(&osb->alloc_stats.moves, 0);
47021- atomic_set(&osb->alloc_stats.local_data, 0);
47022- atomic_set(&osb->alloc_stats.bitmap_data, 0);
47023- atomic_set(&osb->alloc_stats.bg_allocs, 0);
47024- atomic_set(&osb->alloc_stats.bg_extends, 0);
47025+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
47026+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
47027+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
47028+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
47029+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
47030
47031 /* Copy the blockcheck stats from the superblock probe */
47032 osb->osb_ecc_stats = *stats;
47033diff --git a/fs/ocfs2/symlink.c b/fs/ocfs2/symlink.c
47034index 5d22872..523db20 100644
47035--- a/fs/ocfs2/symlink.c
47036+++ b/fs/ocfs2/symlink.c
47037@@ -142,7 +142,7 @@ bail:
47038
47039 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
47040 {
47041- char *link = nd_get_link(nd);
47042+ const char *link = nd_get_link(nd);
47043 if (!IS_ERR(link))
47044 kfree(link);
47045 }
47046diff --git a/fs/open.c b/fs/open.c
47047index 5720854..ccfe124 100644
47048--- a/fs/open.c
47049+++ b/fs/open.c
47050@@ -31,6 +31,8 @@
47051 #include <linux/ima.h>
47052 #include <linux/dnotify.h>
47053
47054+#define CREATE_TRACE_POINTS
47055+#include <trace/events/fs.h>
47056 #include "internal.h"
47057
47058 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
47059@@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
47060 error = locks_verify_truncate(inode, NULL, length);
47061 if (!error)
47062 error = security_path_truncate(&path);
47063+
47064+ if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
47065+ error = -EACCES;
47066+
47067 if (!error)
47068 error = do_truncate(path.dentry, length, 0, NULL);
47069
47070@@ -358,6 +364,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
47071 if (__mnt_is_readonly(path.mnt))
47072 res = -EROFS;
47073
47074+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
47075+ res = -EACCES;
47076+
47077 out_path_release:
47078 path_put(&path);
47079 out:
47080@@ -384,6 +393,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
47081 if (error)
47082 goto dput_and_out;
47083
47084+ gr_log_chdir(path.dentry, path.mnt);
47085+
47086 set_fs_pwd(current->fs, &path);
47087
47088 dput_and_out:
47089@@ -410,6 +421,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
47090 goto out_putf;
47091
47092 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
47093+
47094+ if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
47095+ error = -EPERM;
47096+
47097+ if (!error)
47098+ gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
47099+
47100 if (!error)
47101 set_fs_pwd(current->fs, &file->f_path);
47102 out_putf:
47103@@ -438,7 +456,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
47104 if (error)
47105 goto dput_and_out;
47106
47107+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
47108+ goto dput_and_out;
47109+
47110 set_fs_root(current->fs, &path);
47111+
47112+ gr_handle_chroot_chdir(&path);
47113+
47114 error = 0;
47115 dput_and_out:
47116 path_put(&path);
47117@@ -456,6 +480,16 @@ static int chmod_common(struct path *path, umode_t mode)
47118 if (error)
47119 return error;
47120 mutex_lock(&inode->i_mutex);
47121+
47122+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
47123+ error = -EACCES;
47124+ goto out_unlock;
47125+ }
47126+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
47127+ error = -EACCES;
47128+ goto out_unlock;
47129+ }
47130+
47131 error = security_path_chmod(path, mode);
47132 if (error)
47133 goto out_unlock;
47134@@ -506,6 +540,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
47135 int error;
47136 struct iattr newattrs;
47137
47138+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
47139+ return -EACCES;
47140+
47141 newattrs.ia_valid = ATTR_CTIME;
47142 if (user != (uid_t) -1) {
47143 newattrs.ia_valid |= ATTR_UID;
47144@@ -987,6 +1024,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
47145 } else {
47146 fsnotify_open(f);
47147 fd_install(fd, f);
47148+ trace_do_sys_open(tmp, flags, mode);
47149 }
47150 }
47151 putname(tmp);
47152diff --git a/fs/pipe.c b/fs/pipe.c
47153index fec5e4a..f4210f9 100644
47154--- a/fs/pipe.c
47155+++ b/fs/pipe.c
47156@@ -438,9 +438,9 @@ redo:
47157 }
47158 if (bufs) /* More to do? */
47159 continue;
47160- if (!pipe->writers)
47161+ if (!atomic_read(&pipe->writers))
47162 break;
47163- if (!pipe->waiting_writers) {
47164+ if (!atomic_read(&pipe->waiting_writers)) {
47165 /* syscall merging: Usually we must not sleep
47166 * if O_NONBLOCK is set, or if we got some data.
47167 * But if a writer sleeps in kernel space, then
47168@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
47169 mutex_lock(&inode->i_mutex);
47170 pipe = inode->i_pipe;
47171
47172- if (!pipe->readers) {
47173+ if (!atomic_read(&pipe->readers)) {
47174 send_sig(SIGPIPE, current, 0);
47175 ret = -EPIPE;
47176 goto out;
47177@@ -553,7 +553,7 @@ redo1:
47178 for (;;) {
47179 int bufs;
47180
47181- if (!pipe->readers) {
47182+ if (!atomic_read(&pipe->readers)) {
47183 send_sig(SIGPIPE, current, 0);
47184 if (!ret)
47185 ret = -EPIPE;
47186@@ -644,9 +644,9 @@ redo2:
47187 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
47188 do_wakeup = 0;
47189 }
47190- pipe->waiting_writers++;
47191+ atomic_inc(&pipe->waiting_writers);
47192 pipe_wait(pipe);
47193- pipe->waiting_writers--;
47194+ atomic_dec(&pipe->waiting_writers);
47195 }
47196 out:
47197 mutex_unlock(&inode->i_mutex);
47198@@ -713,7 +713,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47199 mask = 0;
47200 if (filp->f_mode & FMODE_READ) {
47201 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
47202- if (!pipe->writers && filp->f_version != pipe->w_counter)
47203+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
47204 mask |= POLLHUP;
47205 }
47206
47207@@ -723,7 +723,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47208 * Most Unices do not set POLLERR for FIFOs but on Linux they
47209 * behave exactly like pipes for poll().
47210 */
47211- if (!pipe->readers)
47212+ if (!atomic_read(&pipe->readers))
47213 mask |= POLLERR;
47214 }
47215
47216@@ -737,10 +737,10 @@ pipe_release(struct inode *inode, int decr, int decw)
47217
47218 mutex_lock(&inode->i_mutex);
47219 pipe = inode->i_pipe;
47220- pipe->readers -= decr;
47221- pipe->writers -= decw;
47222+ atomic_sub(decr, &pipe->readers);
47223+ atomic_sub(decw, &pipe->writers);
47224
47225- if (!pipe->readers && !pipe->writers) {
47226+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
47227 free_pipe_info(inode);
47228 } else {
47229 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
47230@@ -830,7 +830,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
47231
47232 if (inode->i_pipe) {
47233 ret = 0;
47234- inode->i_pipe->readers++;
47235+ atomic_inc(&inode->i_pipe->readers);
47236 }
47237
47238 mutex_unlock(&inode->i_mutex);
47239@@ -847,7 +847,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
47240
47241 if (inode->i_pipe) {
47242 ret = 0;
47243- inode->i_pipe->writers++;
47244+ atomic_inc(&inode->i_pipe->writers);
47245 }
47246
47247 mutex_unlock(&inode->i_mutex);
47248@@ -865,9 +865,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
47249 if (inode->i_pipe) {
47250 ret = 0;
47251 if (filp->f_mode & FMODE_READ)
47252- inode->i_pipe->readers++;
47253+ atomic_inc(&inode->i_pipe->readers);
47254 if (filp->f_mode & FMODE_WRITE)
47255- inode->i_pipe->writers++;
47256+ atomic_inc(&inode->i_pipe->writers);
47257 }
47258
47259 mutex_unlock(&inode->i_mutex);
47260@@ -959,7 +959,7 @@ void free_pipe_info(struct inode *inode)
47261 inode->i_pipe = NULL;
47262 }
47263
47264-static struct vfsmount *pipe_mnt __read_mostly;
47265+struct vfsmount *pipe_mnt __read_mostly;
47266
47267 /*
47268 * pipefs_dname() is called from d_path().
47269@@ -989,7 +989,8 @@ static struct inode * get_pipe_inode(void)
47270 goto fail_iput;
47271 inode->i_pipe = pipe;
47272
47273- pipe->readers = pipe->writers = 1;
47274+ atomic_set(&pipe->readers, 1);
47275+ atomic_set(&pipe->writers, 1);
47276 inode->i_fop = &rdwr_pipefifo_fops;
47277
47278 /*
47279diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
47280index 15af622..0e9f4467 100644
47281--- a/fs/proc/Kconfig
47282+++ b/fs/proc/Kconfig
47283@@ -30,12 +30,12 @@ config PROC_FS
47284
47285 config PROC_KCORE
47286 bool "/proc/kcore support" if !ARM
47287- depends on PROC_FS && MMU
47288+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
47289
47290 config PROC_VMCORE
47291 bool "/proc/vmcore support"
47292- depends on PROC_FS && CRASH_DUMP
47293- default y
47294+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
47295+ default n
47296 help
47297 Exports the dump image of crashed kernel in ELF format.
47298
47299@@ -59,8 +59,8 @@ config PROC_SYSCTL
47300 limited in memory.
47301
47302 config PROC_PAGE_MONITOR
47303- default y
47304- depends on PROC_FS && MMU
47305+ default n
47306+ depends on PROC_FS && MMU && !GRKERNSEC
47307 bool "Enable /proc page monitoring" if EXPERT
47308 help
47309 Various /proc files exist to monitor process memory utilization:
47310diff --git a/fs/proc/array.c b/fs/proc/array.c
47311index f9bd395..acb7847 100644
47312--- a/fs/proc/array.c
47313+++ b/fs/proc/array.c
47314@@ -60,6 +60,7 @@
47315 #include <linux/tty.h>
47316 #include <linux/string.h>
47317 #include <linux/mman.h>
47318+#include <linux/grsecurity.h>
47319 #include <linux/proc_fs.h>
47320 #include <linux/ioport.h>
47321 #include <linux/uaccess.h>
47322@@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
47323 seq_putc(m, '\n');
47324 }
47325
47326+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47327+static inline void task_pax(struct seq_file *m, struct task_struct *p)
47328+{
47329+ if (p->mm)
47330+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
47331+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
47332+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
47333+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
47334+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
47335+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
47336+ else
47337+ seq_printf(m, "PaX:\t-----\n");
47338+}
47339+#endif
47340+
47341 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47342 struct pid *pid, struct task_struct *task)
47343 {
47344@@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47345 task_cpus_allowed(m, task);
47346 cpuset_task_status_allowed(m, task);
47347 task_context_switch_counts(m, task);
47348+
47349+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47350+ task_pax(m, task);
47351+#endif
47352+
47353+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
47354+ task_grsec_rbac(m, task);
47355+#endif
47356+
47357 return 0;
47358 }
47359
47360+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47361+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
47362+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
47363+ _mm->pax_flags & MF_PAX_SEGMEXEC))
47364+#endif
47365+
47366 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47367 struct pid *pid, struct task_struct *task, int whole)
47368 {
47369@@ -378,6 +409,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47370 char tcomm[sizeof(task->comm)];
47371 unsigned long flags;
47372
47373+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47374+ if (current->exec_id != m->exec_id) {
47375+ gr_log_badprocpid("stat");
47376+ return 0;
47377+ }
47378+#endif
47379+
47380 state = *get_task_state(task);
47381 vsize = eip = esp = 0;
47382 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
47383@@ -449,6 +487,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47384 gtime = task->gtime;
47385 }
47386
47387+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47388+ if (PAX_RAND_FLAGS(mm)) {
47389+ eip = 0;
47390+ esp = 0;
47391+ wchan = 0;
47392+ }
47393+#endif
47394+#ifdef CONFIG_GRKERNSEC_HIDESYM
47395+ wchan = 0;
47396+ eip =0;
47397+ esp =0;
47398+#endif
47399+
47400 /* scale priority and nice values from timeslices to -20..20 */
47401 /* to make it look like a "normal" Unix priority/nice value */
47402 priority = task_prio(task);
47403@@ -485,9 +536,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47404 seq_put_decimal_ull(m, ' ', vsize);
47405 seq_put_decimal_ll(m, ' ', mm ? get_mm_rss(mm) : 0);
47406 seq_put_decimal_ull(m, ' ', rsslim);
47407+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47408+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
47409+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
47410+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
47411+#else
47412 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
47413 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
47414 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
47415+#endif
47416 seq_put_decimal_ull(m, ' ', esp);
47417 seq_put_decimal_ull(m, ' ', eip);
47418 /* The signal information here is obsolete.
47419@@ -508,9 +565,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47420 seq_put_decimal_ull(m, ' ', delayacct_blkio_ticks(task));
47421 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
47422 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
47423+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47424+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((mm && permitted) ? mm->start_data : 0));
47425+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((mm && permitted) ? mm->end_data : 0));
47426+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((mm && permitted) ? mm->start_brk : 0));
47427+#else
47428 seq_put_decimal_ull(m, ' ', (mm && permitted) ? mm->start_data : 0);
47429 seq_put_decimal_ull(m, ' ', (mm && permitted) ? mm->end_data : 0);
47430 seq_put_decimal_ull(m, ' ', (mm && permitted) ? mm->start_brk : 0);
47431+#endif
47432 seq_putc(m, '\n');
47433 if (mm)
47434 mmput(mm);
47435@@ -533,8 +596,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47436 struct pid *pid, struct task_struct *task)
47437 {
47438 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
47439- struct mm_struct *mm = get_task_mm(task);
47440+ struct mm_struct *mm;
47441
47442+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47443+ if (current->exec_id != m->exec_id) {
47444+ gr_log_badprocpid("statm");
47445+ return 0;
47446+ }
47447+#endif
47448+ mm = get_task_mm(task);
47449 if (mm) {
47450 size = task_statm(mm, &shared, &text, &data, &resident);
47451 mmput(mm);
47452@@ -556,3 +626,18 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47453
47454 return 0;
47455 }
47456+
47457+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
47458+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
47459+{
47460+ u32 curr_ip = 0;
47461+ unsigned long flags;
47462+
47463+ if (lock_task_sighand(task, &flags)) {
47464+ curr_ip = task->signal->curr_ip;
47465+ unlock_task_sighand(task, &flags);
47466+ }
47467+
47468+ return sprintf(buffer, "%pI4\n", &curr_ip);
47469+}
47470+#endif
47471diff --git a/fs/proc/base.c b/fs/proc/base.c
47472index 9fc77b4..04761b8 100644
47473--- a/fs/proc/base.c
47474+++ b/fs/proc/base.c
47475@@ -109,6 +109,14 @@ struct pid_entry {
47476 union proc_op op;
47477 };
47478
47479+struct getdents_callback {
47480+ struct linux_dirent __user * current_dir;
47481+ struct linux_dirent __user * previous;
47482+ struct file * file;
47483+ int count;
47484+ int error;
47485+};
47486+
47487 #define NOD(NAME, MODE, IOP, FOP, OP) { \
47488 .name = (NAME), \
47489 .len = sizeof(NAME) - 1, \
47490@@ -213,6 +221,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
47491 if (!mm->arg_end)
47492 goto out_mm; /* Shh! No looking before we're done */
47493
47494+ if (gr_acl_handle_procpidmem(task))
47495+ goto out_mm;
47496+
47497 len = mm->arg_end - mm->arg_start;
47498
47499 if (len > PAGE_SIZE)
47500@@ -240,12 +251,28 @@ out:
47501 return res;
47502 }
47503
47504+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47505+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
47506+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
47507+ _mm->pax_flags & MF_PAX_SEGMEXEC))
47508+#endif
47509+
47510 static int proc_pid_auxv(struct task_struct *task, char *buffer)
47511 {
47512 struct mm_struct *mm = mm_for_maps(task);
47513 int res = PTR_ERR(mm);
47514 if (mm && !IS_ERR(mm)) {
47515 unsigned int nwords = 0;
47516+
47517+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47518+ /* allow if we're currently ptracing this task */
47519+ if (PAX_RAND_FLAGS(mm) &&
47520+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
47521+ mmput(mm);
47522+ return 0;
47523+ }
47524+#endif
47525+
47526 do {
47527 nwords += 2;
47528 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
47529@@ -259,7 +286,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
47530 }
47531
47532
47533-#ifdef CONFIG_KALLSYMS
47534+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47535 /*
47536 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
47537 * Returns the resolved symbol. If that fails, simply return the address.
47538@@ -298,7 +325,7 @@ static void unlock_trace(struct task_struct *task)
47539 mutex_unlock(&task->signal->cred_guard_mutex);
47540 }
47541
47542-#ifdef CONFIG_STACKTRACE
47543+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47544
47545 #define MAX_STACK_TRACE_DEPTH 64
47546
47547@@ -489,7 +516,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
47548 return count;
47549 }
47550
47551-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
47552+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
47553 static int proc_pid_syscall(struct task_struct *task, char *buffer)
47554 {
47555 long nr;
47556@@ -518,7 +545,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
47557 /************************************************************************/
47558
47559 /* permission checks */
47560-static int proc_fd_access_allowed(struct inode *inode)
47561+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
47562 {
47563 struct task_struct *task;
47564 int allowed = 0;
47565@@ -528,7 +555,10 @@ static int proc_fd_access_allowed(struct inode *inode)
47566 */
47567 task = get_proc_task(inode);
47568 if (task) {
47569- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
47570+ if (log)
47571+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
47572+ else
47573+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
47574 put_task_struct(task);
47575 }
47576 return allowed;
47577@@ -566,10 +596,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
47578 struct task_struct *task,
47579 int hide_pid_min)
47580 {
47581+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47582+ return false;
47583+
47584+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47585+ rcu_read_lock();
47586+ {
47587+ const struct cred *tmpcred = current_cred();
47588+ const struct cred *cred = __task_cred(task);
47589+
47590+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
47591+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47592+ || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
47593+#endif
47594+ ) {
47595+ rcu_read_unlock();
47596+ return true;
47597+ }
47598+ }
47599+ rcu_read_unlock();
47600+
47601+ if (!pid->hide_pid)
47602+ return false;
47603+#endif
47604+
47605 if (pid->hide_pid < hide_pid_min)
47606 return true;
47607 if (in_group_p(pid->pid_gid))
47608 return true;
47609+
47610 return ptrace_may_access(task, PTRACE_MODE_READ);
47611 }
47612
47613@@ -587,7 +642,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
47614 put_task_struct(task);
47615
47616 if (!has_perms) {
47617+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47618+ {
47619+#else
47620 if (pid->hide_pid == 2) {
47621+#endif
47622 /*
47623 * Let's make getdents(), stat(), and open()
47624 * consistent with each other. If a process
47625@@ -702,6 +761,10 @@ static int mem_open(struct inode* inode, struct file* file)
47626 file->f_mode |= FMODE_UNSIGNED_OFFSET;
47627 file->private_data = mm;
47628
47629+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47630+ file->f_version = current->exec_id;
47631+#endif
47632+
47633 return 0;
47634 }
47635
47636@@ -713,6 +776,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
47637 ssize_t copied;
47638 char *page;
47639
47640+#ifdef CONFIG_GRKERNSEC
47641+ if (write)
47642+ return -EPERM;
47643+#endif
47644+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47645+ if (file->f_version != current->exec_id) {
47646+ gr_log_badprocpid("mem");
47647+ return 0;
47648+ }
47649+#endif
47650+
47651 if (!mm)
47652 return 0;
47653
47654@@ -813,6 +887,9 @@ static ssize_t environ_read(struct file *file, char __user *buf,
47655 if (!task)
47656 goto out_no_task;
47657
47658+ if (gr_acl_handle_procpidmem(task))
47659+ goto out;
47660+
47661 ret = -ENOMEM;
47662 page = (char *)__get_free_page(GFP_TEMPORARY);
47663 if (!page)
47664@@ -1433,7 +1510,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
47665 path_put(&nd->path);
47666
47667 /* Are we allowed to snoop on the tasks file descriptors? */
47668- if (!proc_fd_access_allowed(inode))
47669+ if (!proc_fd_access_allowed(inode, 0))
47670 goto out;
47671
47672 error = PROC_I(inode)->op.proc_get_link(dentry, &nd->path);
47673@@ -1472,8 +1549,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
47674 struct path path;
47675
47676 /* Are we allowed to snoop on the tasks file descriptors? */
47677- if (!proc_fd_access_allowed(inode))
47678- goto out;
47679+ /* logging this is needed for learning on chromium to work properly,
47680+ but we don't want to flood the logs from 'ps' which does a readlink
47681+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
47682+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
47683+ */
47684+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
47685+ if (!proc_fd_access_allowed(inode,0))
47686+ goto out;
47687+ } else {
47688+ if (!proc_fd_access_allowed(inode,1))
47689+ goto out;
47690+ }
47691
47692 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
47693 if (error)
47694@@ -1538,7 +1625,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
47695 rcu_read_lock();
47696 cred = __task_cred(task);
47697 inode->i_uid = cred->euid;
47698+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47699+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
47700+#else
47701 inode->i_gid = cred->egid;
47702+#endif
47703 rcu_read_unlock();
47704 }
47705 security_task_to_inode(task, inode);
47706@@ -1574,10 +1665,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
47707 return -ENOENT;
47708 }
47709 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
47710+#ifdef CONFIG_GRKERNSEC_PROC_USER
47711+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
47712+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47713+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
47714+#endif
47715 task_dumpable(task)) {
47716 cred = __task_cred(task);
47717 stat->uid = cred->euid;
47718+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47719+ stat->gid = CONFIG_GRKERNSEC_PROC_GID;
47720+#else
47721 stat->gid = cred->egid;
47722+#endif
47723 }
47724 }
47725 rcu_read_unlock();
47726@@ -1615,11 +1715,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
47727
47728 if (task) {
47729 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
47730+#ifdef CONFIG_GRKERNSEC_PROC_USER
47731+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
47732+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47733+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
47734+#endif
47735 task_dumpable(task)) {
47736 rcu_read_lock();
47737 cred = __task_cred(task);
47738 inode->i_uid = cred->euid;
47739+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47740+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
47741+#else
47742 inode->i_gid = cred->egid;
47743+#endif
47744 rcu_read_unlock();
47745 } else {
47746 inode->i_uid = 0;
47747@@ -1737,7 +1846,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
47748 int fd = proc_fd(inode);
47749
47750 if (task) {
47751- files = get_files_struct(task);
47752+ if (!gr_acl_handle_procpidmem(task))
47753+ files = get_files_struct(task);
47754 put_task_struct(task);
47755 }
47756 if (files) {
47757@@ -2338,11 +2448,21 @@ static const struct file_operations proc_map_files_operations = {
47758 */
47759 static int proc_fd_permission(struct inode *inode, int mask)
47760 {
47761+ struct task_struct *task;
47762 int rv = generic_permission(inode, mask);
47763- if (rv == 0)
47764- return 0;
47765+
47766 if (task_pid(current) == proc_pid(inode))
47767 rv = 0;
47768+
47769+ task = get_proc_task(inode);
47770+ if (task == NULL)
47771+ return rv;
47772+
47773+ if (gr_acl_handle_procpidmem(task))
47774+ rv = -EACCES;
47775+
47776+ put_task_struct(task);
47777+
47778 return rv;
47779 }
47780
47781@@ -2452,6 +2572,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
47782 if (!task)
47783 goto out_no_task;
47784
47785+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47786+ goto out;
47787+
47788 /*
47789 * Yes, it does not scale. And it should not. Don't add
47790 * new entries into /proc/<tgid>/ without very good reasons.
47791@@ -2496,6 +2619,9 @@ static int proc_pident_readdir(struct file *filp,
47792 if (!task)
47793 goto out_no_task;
47794
47795+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47796+ goto out;
47797+
47798 ret = 0;
47799 i = filp->f_pos;
47800 switch (i) {
47801@@ -2766,7 +2892,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
47802 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
47803 void *cookie)
47804 {
47805- char *s = nd_get_link(nd);
47806+ const char *s = nd_get_link(nd);
47807 if (!IS_ERR(s))
47808 __putname(s);
47809 }
47810@@ -2967,7 +3093,7 @@ static const struct pid_entry tgid_base_stuff[] = {
47811 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
47812 #endif
47813 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
47814-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
47815+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
47816 INF("syscall", S_IRUGO, proc_pid_syscall),
47817 #endif
47818 INF("cmdline", S_IRUGO, proc_pid_cmdline),
47819@@ -2992,10 +3118,10 @@ static const struct pid_entry tgid_base_stuff[] = {
47820 #ifdef CONFIG_SECURITY
47821 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
47822 #endif
47823-#ifdef CONFIG_KALLSYMS
47824+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47825 INF("wchan", S_IRUGO, proc_pid_wchan),
47826 #endif
47827-#ifdef CONFIG_STACKTRACE
47828+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47829 ONE("stack", S_IRUGO, proc_pid_stack),
47830 #endif
47831 #ifdef CONFIG_SCHEDSTATS
47832@@ -3029,6 +3155,9 @@ static const struct pid_entry tgid_base_stuff[] = {
47833 #ifdef CONFIG_HARDWALL
47834 INF("hardwall", S_IRUGO, proc_pid_hardwall),
47835 #endif
47836+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
47837+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
47838+#endif
47839 };
47840
47841 static int proc_tgid_base_readdir(struct file * filp,
47842@@ -3155,7 +3284,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
47843 if (!inode)
47844 goto out;
47845
47846+#ifdef CONFIG_GRKERNSEC_PROC_USER
47847+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
47848+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47849+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
47850+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
47851+#else
47852 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
47853+#endif
47854 inode->i_op = &proc_tgid_base_inode_operations;
47855 inode->i_fop = &proc_tgid_base_operations;
47856 inode->i_flags|=S_IMMUTABLE;
47857@@ -3197,7 +3333,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
47858 if (!task)
47859 goto out;
47860
47861+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47862+ goto out_put_task;
47863+
47864 result = proc_pid_instantiate(dir, dentry, task, NULL);
47865+out_put_task:
47866 put_task_struct(task);
47867 out:
47868 return result;
47869@@ -3260,6 +3400,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
47870 static int fake_filldir(void *buf, const char *name, int namelen,
47871 loff_t offset, u64 ino, unsigned d_type)
47872 {
47873+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
47874+ __buf->error = -EINVAL;
47875 return 0;
47876 }
47877
47878@@ -3326,7 +3468,7 @@ static const struct pid_entry tid_base_stuff[] = {
47879 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
47880 #endif
47881 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
47882-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
47883+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
47884 INF("syscall", S_IRUGO, proc_pid_syscall),
47885 #endif
47886 INF("cmdline", S_IRUGO, proc_pid_cmdline),
47887@@ -3350,10 +3492,10 @@ static const struct pid_entry tid_base_stuff[] = {
47888 #ifdef CONFIG_SECURITY
47889 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
47890 #endif
47891-#ifdef CONFIG_KALLSYMS
47892+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47893 INF("wchan", S_IRUGO, proc_pid_wchan),
47894 #endif
47895-#ifdef CONFIG_STACKTRACE
47896+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47897 ONE("stack", S_IRUGO, proc_pid_stack),
47898 #endif
47899 #ifdef CONFIG_SCHEDSTATS
47900diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
47901index 82676e3..5f8518a 100644
47902--- a/fs/proc/cmdline.c
47903+++ b/fs/proc/cmdline.c
47904@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
47905
47906 static int __init proc_cmdline_init(void)
47907 {
47908+#ifdef CONFIG_GRKERNSEC_PROC_ADD
47909+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
47910+#else
47911 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
47912+#endif
47913 return 0;
47914 }
47915 module_init(proc_cmdline_init);
47916diff --git a/fs/proc/devices.c b/fs/proc/devices.c
47917index b143471..bb105e5 100644
47918--- a/fs/proc/devices.c
47919+++ b/fs/proc/devices.c
47920@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
47921
47922 static int __init proc_devices_init(void)
47923 {
47924+#ifdef CONFIG_GRKERNSEC_PROC_ADD
47925+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
47926+#else
47927 proc_create("devices", 0, NULL, &proc_devinfo_operations);
47928+#endif
47929 return 0;
47930 }
47931 module_init(proc_devices_init);
47932diff --git a/fs/proc/inode.c b/fs/proc/inode.c
47933index 205c922..2ee4c57 100644
47934--- a/fs/proc/inode.c
47935+++ b/fs/proc/inode.c
47936@@ -21,11 +21,17 @@
47937 #include <linux/seq_file.h>
47938 #include <linux/slab.h>
47939 #include <linux/mount.h>
47940+#include <linux/grsecurity.h>
47941
47942 #include <asm/uaccess.h>
47943
47944 #include "internal.h"
47945
47946+#ifdef CONFIG_PROC_SYSCTL
47947+extern const struct inode_operations proc_sys_inode_operations;
47948+extern const struct inode_operations proc_sys_dir_operations;
47949+#endif
47950+
47951 static void proc_evict_inode(struct inode *inode)
47952 {
47953 struct proc_dir_entry *de;
47954@@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
47955 ns_ops = PROC_I(inode)->ns_ops;
47956 if (ns_ops && ns_ops->put)
47957 ns_ops->put(PROC_I(inode)->ns);
47958+
47959+#ifdef CONFIG_PROC_SYSCTL
47960+ if (inode->i_op == &proc_sys_inode_operations ||
47961+ inode->i_op == &proc_sys_dir_operations)
47962+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
47963+#endif
47964+
47965 }
47966
47967 static struct kmem_cache * proc_inode_cachep;
47968@@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
47969 if (de->mode) {
47970 inode->i_mode = de->mode;
47971 inode->i_uid = de->uid;
47972+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47973+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
47974+#else
47975 inode->i_gid = de->gid;
47976+#endif
47977 }
47978 if (de->size)
47979 inode->i_size = de->size;
47980diff --git a/fs/proc/internal.h b/fs/proc/internal.h
47981index 5f79bb8..eeccee4 100644
47982--- a/fs/proc/internal.h
47983+++ b/fs/proc/internal.h
47984@@ -54,6 +54,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47985 struct pid *pid, struct task_struct *task);
47986 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47987 struct pid *pid, struct task_struct *task);
47988+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
47989+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
47990+#endif
47991 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
47992
47993 extern const struct file_operations proc_pid_maps_operations;
47994diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
47995index 86c67ee..cdca321 100644
47996--- a/fs/proc/kcore.c
47997+++ b/fs/proc/kcore.c
47998@@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
47999 * the addresses in the elf_phdr on our list.
48000 */
48001 start = kc_offset_to_vaddr(*fpos - elf_buflen);
48002- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
48003+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
48004+ if (tsz > buflen)
48005 tsz = buflen;
48006-
48007+
48008 while (buflen) {
48009 struct kcore_list *m;
48010
48011@@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48012 kfree(elf_buf);
48013 } else {
48014 if (kern_addr_valid(start)) {
48015- unsigned long n;
48016+ char *elf_buf;
48017+ mm_segment_t oldfs;
48018
48019- n = copy_to_user(buffer, (char *)start, tsz);
48020- /*
48021- * We cannot distinguish between fault on source
48022- * and fault on destination. When this happens
48023- * we clear too and hope it will trigger the
48024- * EFAULT again.
48025- */
48026- if (n) {
48027- if (clear_user(buffer + tsz - n,
48028- n))
48029+ elf_buf = kmalloc(tsz, GFP_KERNEL);
48030+ if (!elf_buf)
48031+ return -ENOMEM;
48032+ oldfs = get_fs();
48033+ set_fs(KERNEL_DS);
48034+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
48035+ set_fs(oldfs);
48036+ if (copy_to_user(buffer, elf_buf, tsz)) {
48037+ kfree(elf_buf);
48038 return -EFAULT;
48039+ }
48040 }
48041+ set_fs(oldfs);
48042+ kfree(elf_buf);
48043 } else {
48044 if (clear_user(buffer, tsz))
48045 return -EFAULT;
48046@@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48047
48048 static int open_kcore(struct inode *inode, struct file *filp)
48049 {
48050+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
48051+ return -EPERM;
48052+#endif
48053 if (!capable(CAP_SYS_RAWIO))
48054 return -EPERM;
48055 if (kcore_need_update)
48056diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
48057index 80e4645..53e5fcf 100644
48058--- a/fs/proc/meminfo.c
48059+++ b/fs/proc/meminfo.c
48060@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
48061 vmi.used >> 10,
48062 vmi.largest_chunk >> 10
48063 #ifdef CONFIG_MEMORY_FAILURE
48064- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
48065+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
48066 #endif
48067 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
48068 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
48069diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
48070index b1822dd..df622cb 100644
48071--- a/fs/proc/nommu.c
48072+++ b/fs/proc/nommu.c
48073@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
48074 if (len < 1)
48075 len = 1;
48076 seq_printf(m, "%*c", len, ' ');
48077- seq_path(m, &file->f_path, "");
48078+ seq_path(m, &file->f_path, "\n\\");
48079 }
48080
48081 seq_putc(m, '\n');
48082diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
48083index 06e1cc1..177cd98 100644
48084--- a/fs/proc/proc_net.c
48085+++ b/fs/proc/proc_net.c
48086@@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
48087 struct task_struct *task;
48088 struct nsproxy *ns;
48089 struct net *net = NULL;
48090+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48091+ const struct cred *cred = current_cred();
48092+#endif
48093+
48094+#ifdef CONFIG_GRKERNSEC_PROC_USER
48095+ if (cred->fsuid)
48096+ return net;
48097+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48098+ if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
48099+ return net;
48100+#endif
48101
48102 rcu_read_lock();
48103 task = pid_task(proc_pid(dir), PIDTYPE_PID);
48104diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
48105index 21d836f..bebf3ee 100644
48106--- a/fs/proc/proc_sysctl.c
48107+++ b/fs/proc/proc_sysctl.c
48108@@ -12,11 +12,15 @@
48109 #include <linux/module.h>
48110 #include "internal.h"
48111
48112+extern int gr_handle_chroot_sysctl(const int op);
48113+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
48114+ const int op);
48115+
48116 static const struct dentry_operations proc_sys_dentry_operations;
48117 static const struct file_operations proc_sys_file_operations;
48118-static const struct inode_operations proc_sys_inode_operations;
48119+const struct inode_operations proc_sys_inode_operations;
48120 static const struct file_operations proc_sys_dir_file_operations;
48121-static const struct inode_operations proc_sys_dir_operations;
48122+const struct inode_operations proc_sys_dir_operations;
48123
48124 void proc_sys_poll_notify(struct ctl_table_poll *poll)
48125 {
48126@@ -470,8 +474,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
48127
48128 err = NULL;
48129 d_set_d_op(dentry, &proc_sys_dentry_operations);
48130+
48131+ gr_handle_proc_create(dentry, inode);
48132+
48133 d_add(dentry, inode);
48134
48135+ if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt))
48136+ err = ERR_PTR(-ENOENT);
48137+
48138 out:
48139 sysctl_head_finish(head);
48140 return err;
48141@@ -483,18 +493,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
48142 struct inode *inode = filp->f_path.dentry->d_inode;
48143 struct ctl_table_header *head = grab_header(inode);
48144 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
48145+ int op = write ? MAY_WRITE : MAY_READ;
48146 ssize_t error;
48147 size_t res;
48148
48149 if (IS_ERR(head))
48150 return PTR_ERR(head);
48151
48152+
48153 /*
48154 * At this point we know that the sysctl was not unregistered
48155 * and won't be until we finish.
48156 */
48157 error = -EPERM;
48158- if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
48159+ if (sysctl_perm(head->root, table, op))
48160 goto out;
48161
48162 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
48163@@ -502,6 +514,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
48164 if (!table->proc_handler)
48165 goto out;
48166
48167+#ifdef CONFIG_GRKERNSEC
48168+ error = -EPERM;
48169+ if (gr_handle_chroot_sysctl(op))
48170+ goto out;
48171+ dget(filp->f_path.dentry);
48172+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
48173+ dput(filp->f_path.dentry);
48174+ goto out;
48175+ }
48176+ dput(filp->f_path.dentry);
48177+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
48178+ goto out;
48179+ if (write && !capable(CAP_SYS_ADMIN))
48180+ goto out;
48181+#endif
48182+
48183 /* careful: calling conventions are nasty here */
48184 res = count;
48185 error = table->proc_handler(table, write, buf, &res, ppos);
48186@@ -599,6 +627,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
48187 return -ENOMEM;
48188 } else {
48189 d_set_d_op(child, &proc_sys_dentry_operations);
48190+
48191+ gr_handle_proc_create(child, inode);
48192+
48193 d_add(child, inode);
48194 }
48195 } else {
48196@@ -642,6 +673,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
48197 if ((*pos)++ < file->f_pos)
48198 return 0;
48199
48200+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
48201+ return 0;
48202+
48203 if (unlikely(S_ISLNK(table->mode)))
48204 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
48205 else
48206@@ -759,6 +793,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
48207 if (IS_ERR(head))
48208 return PTR_ERR(head);
48209
48210+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
48211+ return -ENOENT;
48212+
48213 generic_fillattr(inode, stat);
48214 if (table)
48215 stat->mode = (stat->mode & S_IFMT) | table->mode;
48216@@ -781,13 +818,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
48217 .llseek = generic_file_llseek,
48218 };
48219
48220-static const struct inode_operations proc_sys_inode_operations = {
48221+const struct inode_operations proc_sys_inode_operations = {
48222 .permission = proc_sys_permission,
48223 .setattr = proc_sys_setattr,
48224 .getattr = proc_sys_getattr,
48225 };
48226
48227-static const struct inode_operations proc_sys_dir_operations = {
48228+const struct inode_operations proc_sys_dir_operations = {
48229 .lookup = proc_sys_lookup,
48230 .permission = proc_sys_permission,
48231 .setattr = proc_sys_setattr,
48232diff --git a/fs/proc/root.c b/fs/proc/root.c
48233index eed44bf..abeb499 100644
48234--- a/fs/proc/root.c
48235+++ b/fs/proc/root.c
48236@@ -188,7 +188,15 @@ void __init proc_root_init(void)
48237 #ifdef CONFIG_PROC_DEVICETREE
48238 proc_device_tree_init();
48239 #endif
48240+#ifdef CONFIG_GRKERNSEC_PROC_ADD
48241+#ifdef CONFIG_GRKERNSEC_PROC_USER
48242+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
48243+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48244+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
48245+#endif
48246+#else
48247 proc_mkdir("bus", NULL);
48248+#endif
48249 proc_sys_init();
48250 }
48251
48252diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
48253index 7faaf2a..096c28b 100644
48254--- a/fs/proc/task_mmu.c
48255+++ b/fs/proc/task_mmu.c
48256@@ -11,12 +11,19 @@
48257 #include <linux/rmap.h>
48258 #include <linux/swap.h>
48259 #include <linux/swapops.h>
48260+#include <linux/grsecurity.h>
48261
48262 #include <asm/elf.h>
48263 #include <asm/uaccess.h>
48264 #include <asm/tlbflush.h>
48265 #include "internal.h"
48266
48267+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48268+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48269+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
48270+ _mm->pax_flags & MF_PAX_SEGMEXEC))
48271+#endif
48272+
48273 void task_mem(struct seq_file *m, struct mm_struct *mm)
48274 {
48275 unsigned long data, text, lib, swap;
48276@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48277 "VmExe:\t%8lu kB\n"
48278 "VmLib:\t%8lu kB\n"
48279 "VmPTE:\t%8lu kB\n"
48280- "VmSwap:\t%8lu kB\n",
48281- hiwater_vm << (PAGE_SHIFT-10),
48282+ "VmSwap:\t%8lu kB\n"
48283+
48284+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48285+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
48286+#endif
48287+
48288+ ,hiwater_vm << (PAGE_SHIFT-10),
48289 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
48290 mm->locked_vm << (PAGE_SHIFT-10),
48291 mm->pinned_vm << (PAGE_SHIFT-10),
48292@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48293 data << (PAGE_SHIFT-10),
48294 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
48295 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
48296- swap << (PAGE_SHIFT-10));
48297+ swap << (PAGE_SHIFT-10)
48298+
48299+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48300+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48301+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
48302+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
48303+#else
48304+ , mm->context.user_cs_base
48305+ , mm->context.user_cs_limit
48306+#endif
48307+#endif
48308+
48309+ );
48310 }
48311
48312 unsigned long task_vsize(struct mm_struct *mm)
48313@@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
48314 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
48315 }
48316
48317- /* We don't show the stack guard page in /proc/maps */
48318+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48319+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
48320+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
48321+#else
48322 start = vma->vm_start;
48323- if (stack_guard_page_start(vma, start))
48324- start += PAGE_SIZE;
48325 end = vma->vm_end;
48326- if (stack_guard_page_end(vma, end))
48327- end -= PAGE_SIZE;
48328+#endif
48329
48330 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
48331 start,
48332@@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
48333 flags & VM_WRITE ? 'w' : '-',
48334 flags & VM_EXEC ? 'x' : '-',
48335 flags & VM_MAYSHARE ? 's' : 'p',
48336+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48337+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
48338+#else
48339 pgoff,
48340+#endif
48341 MAJOR(dev), MINOR(dev), ino, &len);
48342
48343 /*
48344@@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
48345 */
48346 if (file) {
48347 pad_len_spaces(m, len);
48348- seq_path(m, &file->f_path, "\n");
48349+ seq_path(m, &file->f_path, "\n\\");
48350 goto done;
48351 }
48352
48353@@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
48354 * Thread stack in /proc/PID/task/TID/maps or
48355 * the main process stack.
48356 */
48357- if (!is_pid || (vma->vm_start <= mm->start_stack &&
48358- vma->vm_end >= mm->start_stack)) {
48359+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
48360+ (vma->vm_start <= mm->start_stack &&
48361+ vma->vm_end >= mm->start_stack)) {
48362 name = "[stack]";
48363 } else {
48364 /* Thread stack in /proc/PID/maps */
48365@@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
48366 struct proc_maps_private *priv = m->private;
48367 struct task_struct *task = priv->task;
48368
48369+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48370+ if (current->exec_id != m->exec_id) {
48371+ gr_log_badprocpid("maps");
48372+ return 0;
48373+ }
48374+#endif
48375+
48376 show_map_vma(m, vma, is_pid);
48377
48378 if (m->count < m->size) /* vma is copied successfully */
48379@@ -482,12 +518,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
48380 .private = &mss,
48381 };
48382
48383+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48384+ if (current->exec_id != m->exec_id) {
48385+ gr_log_badprocpid("smaps");
48386+ return 0;
48387+ }
48388+#endif
48389 memset(&mss, 0, sizeof mss);
48390- mss.vma = vma;
48391- /* mmap_sem is held in m_start */
48392- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
48393- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
48394-
48395+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48396+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
48397+#endif
48398+ mss.vma = vma;
48399+ /* mmap_sem is held in m_start */
48400+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
48401+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
48402+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48403+ }
48404+#endif
48405 show_map_vma(m, vma, is_pid);
48406
48407 seq_printf(m,
48408@@ -505,7 +552,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
48409 "KernelPageSize: %8lu kB\n"
48410 "MMUPageSize: %8lu kB\n"
48411 "Locked: %8lu kB\n",
48412+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48413+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
48414+#else
48415 (vma->vm_end - vma->vm_start) >> 10,
48416+#endif
48417 mss.resident >> 10,
48418 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
48419 mss.shared_clean >> 10,
48420@@ -1138,6 +1189,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
48421 int n;
48422 char buffer[50];
48423
48424+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48425+ if (current->exec_id != m->exec_id) {
48426+ gr_log_badprocpid("numa_maps");
48427+ return 0;
48428+ }
48429+#endif
48430+
48431 if (!mm)
48432 return 0;
48433
48434@@ -1155,11 +1213,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
48435 mpol_to_str(buffer, sizeof(buffer), pol, 0);
48436 mpol_cond_put(pol);
48437
48438+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48439+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
48440+#else
48441 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
48442+#endif
48443
48444 if (file) {
48445 seq_printf(m, " file=");
48446- seq_path(m, &file->f_path, "\n\t= ");
48447+ seq_path(m, &file->f_path, "\n\t\\= ");
48448 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
48449 seq_printf(m, " heap");
48450 } else {
48451diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
48452index 74fe164..899e77b 100644
48453--- a/fs/proc/task_nommu.c
48454+++ b/fs/proc/task_nommu.c
48455@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48456 else
48457 bytes += kobjsize(mm);
48458
48459- if (current->fs && current->fs->users > 1)
48460+ if (current->fs && atomic_read(&current->fs->users) > 1)
48461 sbytes += kobjsize(current->fs);
48462 else
48463 bytes += kobjsize(current->fs);
48464@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
48465
48466 if (file) {
48467 pad_len_spaces(m, len);
48468- seq_path(m, &file->f_path, "");
48469+ seq_path(m, &file->f_path, "\n\\");
48470 } else if (mm) {
48471 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
48472
48473diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
48474index d67908b..d13f6a6 100644
48475--- a/fs/quota/netlink.c
48476+++ b/fs/quota/netlink.c
48477@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
48478 void quota_send_warning(short type, unsigned int id, dev_t dev,
48479 const char warntype)
48480 {
48481- static atomic_t seq;
48482+ static atomic_unchecked_t seq;
48483 struct sk_buff *skb;
48484 void *msg_head;
48485 int ret;
48486@@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
48487 "VFS: Not enough memory to send quota warning.\n");
48488 return;
48489 }
48490- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
48491+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
48492 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
48493 if (!msg_head) {
48494 printk(KERN_ERR
48495diff --git a/fs/readdir.c b/fs/readdir.c
48496index cc0a822..43cb195 100644
48497--- a/fs/readdir.c
48498+++ b/fs/readdir.c
48499@@ -17,6 +17,7 @@
48500 #include <linux/security.h>
48501 #include <linux/syscalls.h>
48502 #include <linux/unistd.h>
48503+#include <linux/namei.h>
48504
48505 #include <asm/uaccess.h>
48506
48507@@ -67,6 +68,7 @@ struct old_linux_dirent {
48508
48509 struct readdir_callback {
48510 struct old_linux_dirent __user * dirent;
48511+ struct file * file;
48512 int result;
48513 };
48514
48515@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
48516 buf->result = -EOVERFLOW;
48517 return -EOVERFLOW;
48518 }
48519+
48520+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48521+ return 0;
48522+
48523 buf->result++;
48524 dirent = buf->dirent;
48525 if (!access_ok(VERIFY_WRITE, dirent,
48526@@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
48527
48528 buf.result = 0;
48529 buf.dirent = dirent;
48530+ buf.file = file;
48531
48532 error = vfs_readdir(file, fillonedir, &buf);
48533 if (buf.result)
48534@@ -142,6 +149,7 @@ struct linux_dirent {
48535 struct getdents_callback {
48536 struct linux_dirent __user * current_dir;
48537 struct linux_dirent __user * previous;
48538+ struct file * file;
48539 int count;
48540 int error;
48541 };
48542@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
48543 buf->error = -EOVERFLOW;
48544 return -EOVERFLOW;
48545 }
48546+
48547+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48548+ return 0;
48549+
48550 dirent = buf->previous;
48551 if (dirent) {
48552 if (__put_user(offset, &dirent->d_off))
48553@@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
48554 buf.previous = NULL;
48555 buf.count = count;
48556 buf.error = 0;
48557+ buf.file = file;
48558
48559 error = vfs_readdir(file, filldir, &buf);
48560 if (error >= 0)
48561@@ -229,6 +242,7 @@ out:
48562 struct getdents_callback64 {
48563 struct linux_dirent64 __user * current_dir;
48564 struct linux_dirent64 __user * previous;
48565+ struct file *file;
48566 int count;
48567 int error;
48568 };
48569@@ -244,6 +258,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
48570 buf->error = -EINVAL; /* only used if we fail.. */
48571 if (reclen > buf->count)
48572 return -EINVAL;
48573+
48574+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48575+ return 0;
48576+
48577 dirent = buf->previous;
48578 if (dirent) {
48579 if (__put_user(offset, &dirent->d_off))
48580@@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
48581
48582 buf.current_dir = dirent;
48583 buf.previous = NULL;
48584+ buf.file = file;
48585 buf.count = count;
48586 buf.error = 0;
48587
48588@@ -299,7 +318,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
48589 error = buf.error;
48590 lastdirent = buf.previous;
48591 if (lastdirent) {
48592- typeof(lastdirent->d_off) d_off = file->f_pos;
48593+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
48594 if (__put_user(d_off, &lastdirent->d_off))
48595 error = -EFAULT;
48596 else
48597diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
48598index 2b7882b..1c5ef48 100644
48599--- a/fs/reiserfs/do_balan.c
48600+++ b/fs/reiserfs/do_balan.c
48601@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
48602 return;
48603 }
48604
48605- atomic_inc(&(fs_generation(tb->tb_sb)));
48606+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
48607 do_balance_starts(tb);
48608
48609 /* balance leaf returns 0 except if combining L R and S into
48610diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
48611index 2c1ade6..8c59d8d 100644
48612--- a/fs/reiserfs/procfs.c
48613+++ b/fs/reiserfs/procfs.c
48614@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
48615 "SMALL_TAILS " : "NO_TAILS ",
48616 replay_only(sb) ? "REPLAY_ONLY " : "",
48617 convert_reiserfs(sb) ? "CONV " : "",
48618- atomic_read(&r->s_generation_counter),
48619+ atomic_read_unchecked(&r->s_generation_counter),
48620 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
48621 SF(s_do_balance), SF(s_unneeded_left_neighbor),
48622 SF(s_good_search_by_key_reada), SF(s_bmaps),
48623diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
48624index a59d271..e12d1cf 100644
48625--- a/fs/reiserfs/reiserfs.h
48626+++ b/fs/reiserfs/reiserfs.h
48627@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
48628 /* Comment? -Hans */
48629 wait_queue_head_t s_wait;
48630 /* To be obsoleted soon by per buffer seals.. -Hans */
48631- atomic_t s_generation_counter; // increased by one every time the
48632+ atomic_unchecked_t s_generation_counter; // increased by one every time the
48633 // tree gets re-balanced
48634 unsigned long s_properties; /* File system properties. Currently holds
48635 on-disk FS format */
48636@@ -1973,7 +1973,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
48637 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
48638
48639 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
48640-#define get_generation(s) atomic_read (&fs_generation(s))
48641+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
48642 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
48643 #define __fs_changed(gen,s) (gen != get_generation (s))
48644 #define fs_changed(gen,s) \
48645diff --git a/fs/select.c b/fs/select.c
48646index 17d33d0..da0bf5c 100644
48647--- a/fs/select.c
48648+++ b/fs/select.c
48649@@ -20,6 +20,7 @@
48650 #include <linux/export.h>
48651 #include <linux/slab.h>
48652 #include <linux/poll.h>
48653+#include <linux/security.h>
48654 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
48655 #include <linux/file.h>
48656 #include <linux/fdtable.h>
48657@@ -833,6 +834,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
48658 struct poll_list *walk = head;
48659 unsigned long todo = nfds;
48660
48661+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
48662 if (nfds > rlimit(RLIMIT_NOFILE))
48663 return -EINVAL;
48664
48665diff --git a/fs/seq_file.c b/fs/seq_file.c
48666index 0cbd049..cab1127 100644
48667--- a/fs/seq_file.c
48668+++ b/fs/seq_file.c
48669@@ -9,6 +9,7 @@
48670 #include <linux/export.h>
48671 #include <linux/seq_file.h>
48672 #include <linux/slab.h>
48673+#include <linux/sched.h>
48674
48675 #include <asm/uaccess.h>
48676 #include <asm/page.h>
48677@@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
48678 memset(p, 0, sizeof(*p));
48679 mutex_init(&p->lock);
48680 p->op = op;
48681+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48682+ p->exec_id = current->exec_id;
48683+#endif
48684
48685 /*
48686 * Wrappers around seq_open(e.g. swaps_open) need to be
48687@@ -567,7 +571,7 @@ static void single_stop(struct seq_file *p, void *v)
48688 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
48689 void *data)
48690 {
48691- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
48692+ seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
48693 int res = -ENOMEM;
48694
48695 if (op) {
48696diff --git a/fs/splice.c b/fs/splice.c
48697index f847684..156619e 100644
48698--- a/fs/splice.c
48699+++ b/fs/splice.c
48700@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
48701 pipe_lock(pipe);
48702
48703 for (;;) {
48704- if (!pipe->readers) {
48705+ if (!atomic_read(&pipe->readers)) {
48706 send_sig(SIGPIPE, current, 0);
48707 if (!ret)
48708 ret = -EPIPE;
48709@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
48710 do_wakeup = 0;
48711 }
48712
48713- pipe->waiting_writers++;
48714+ atomic_inc(&pipe->waiting_writers);
48715 pipe_wait(pipe);
48716- pipe->waiting_writers--;
48717+ atomic_dec(&pipe->waiting_writers);
48718 }
48719
48720 pipe_unlock(pipe);
48721@@ -560,7 +560,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
48722 old_fs = get_fs();
48723 set_fs(get_ds());
48724 /* The cast to a user pointer is valid due to the set_fs() */
48725- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
48726+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
48727 set_fs(old_fs);
48728
48729 return res;
48730@@ -575,7 +575,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
48731 old_fs = get_fs();
48732 set_fs(get_ds());
48733 /* The cast to a user pointer is valid due to the set_fs() */
48734- res = vfs_write(file, (const char __user *)buf, count, &pos);
48735+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
48736 set_fs(old_fs);
48737
48738 return res;
48739@@ -626,7 +626,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
48740 goto err;
48741
48742 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
48743- vec[i].iov_base = (void __user *) page_address(page);
48744+ vec[i].iov_base = (void __force_user *) page_address(page);
48745 vec[i].iov_len = this_len;
48746 spd.pages[i] = page;
48747 spd.nr_pages++;
48748@@ -845,10 +845,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
48749 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
48750 {
48751 while (!pipe->nrbufs) {
48752- if (!pipe->writers)
48753+ if (!atomic_read(&pipe->writers))
48754 return 0;
48755
48756- if (!pipe->waiting_writers && sd->num_spliced)
48757+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
48758 return 0;
48759
48760 if (sd->flags & SPLICE_F_NONBLOCK)
48761@@ -1181,7 +1181,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
48762 * out of the pipe right after the splice_to_pipe(). So set
48763 * PIPE_READERS appropriately.
48764 */
48765- pipe->readers = 1;
48766+ atomic_set(&pipe->readers, 1);
48767
48768 current->splice_pipe = pipe;
48769 }
48770@@ -1733,9 +1733,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
48771 ret = -ERESTARTSYS;
48772 break;
48773 }
48774- if (!pipe->writers)
48775+ if (!atomic_read(&pipe->writers))
48776 break;
48777- if (!pipe->waiting_writers) {
48778+ if (!atomic_read(&pipe->waiting_writers)) {
48779 if (flags & SPLICE_F_NONBLOCK) {
48780 ret = -EAGAIN;
48781 break;
48782@@ -1767,7 +1767,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
48783 pipe_lock(pipe);
48784
48785 while (pipe->nrbufs >= pipe->buffers) {
48786- if (!pipe->readers) {
48787+ if (!atomic_read(&pipe->readers)) {
48788 send_sig(SIGPIPE, current, 0);
48789 ret = -EPIPE;
48790 break;
48791@@ -1780,9 +1780,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
48792 ret = -ERESTARTSYS;
48793 break;
48794 }
48795- pipe->waiting_writers++;
48796+ atomic_inc(&pipe->waiting_writers);
48797 pipe_wait(pipe);
48798- pipe->waiting_writers--;
48799+ atomic_dec(&pipe->waiting_writers);
48800 }
48801
48802 pipe_unlock(pipe);
48803@@ -1818,14 +1818,14 @@ retry:
48804 pipe_double_lock(ipipe, opipe);
48805
48806 do {
48807- if (!opipe->readers) {
48808+ if (!atomic_read(&opipe->readers)) {
48809 send_sig(SIGPIPE, current, 0);
48810 if (!ret)
48811 ret = -EPIPE;
48812 break;
48813 }
48814
48815- if (!ipipe->nrbufs && !ipipe->writers)
48816+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
48817 break;
48818
48819 /*
48820@@ -1922,7 +1922,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
48821 pipe_double_lock(ipipe, opipe);
48822
48823 do {
48824- if (!opipe->readers) {
48825+ if (!atomic_read(&opipe->readers)) {
48826 send_sig(SIGPIPE, current, 0);
48827 if (!ret)
48828 ret = -EPIPE;
48829@@ -1967,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
48830 * return EAGAIN if we have the potential of some data in the
48831 * future, otherwise just return 0
48832 */
48833- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
48834+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
48835 ret = -EAGAIN;
48836
48837 pipe_unlock(ipipe);
48838diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
48839index 35a36d3..23424b2 100644
48840--- a/fs/sysfs/dir.c
48841+++ b/fs/sysfs/dir.c
48842@@ -657,6 +657,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
48843 struct sysfs_dirent *sd;
48844 int rc;
48845
48846+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
48847+ const char *parent_name = parent_sd->s_name;
48848+
48849+ mode = S_IFDIR | S_IRWXU;
48850+
48851+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
48852+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
48853+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
48854+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
48855+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
48856+#endif
48857+
48858 /* allocate */
48859 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
48860 if (!sd)
48861diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
48862index 00012e3..8392349 100644
48863--- a/fs/sysfs/file.c
48864+++ b/fs/sysfs/file.c
48865@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
48866
48867 struct sysfs_open_dirent {
48868 atomic_t refcnt;
48869- atomic_t event;
48870+ atomic_unchecked_t event;
48871 wait_queue_head_t poll;
48872 struct list_head buffers; /* goes through sysfs_buffer.list */
48873 };
48874@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
48875 if (!sysfs_get_active(attr_sd))
48876 return -ENODEV;
48877
48878- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
48879+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
48880 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
48881
48882 sysfs_put_active(attr_sd);
48883@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
48884 return -ENOMEM;
48885
48886 atomic_set(&new_od->refcnt, 0);
48887- atomic_set(&new_od->event, 1);
48888+ atomic_set_unchecked(&new_od->event, 1);
48889 init_waitqueue_head(&new_od->poll);
48890 INIT_LIST_HEAD(&new_od->buffers);
48891 goto retry;
48892@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
48893
48894 sysfs_put_active(attr_sd);
48895
48896- if (buffer->event != atomic_read(&od->event))
48897+ if (buffer->event != atomic_read_unchecked(&od->event))
48898 goto trigger;
48899
48900 return DEFAULT_POLLMASK;
48901@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
48902
48903 od = sd->s_attr.open;
48904 if (od) {
48905- atomic_inc(&od->event);
48906+ atomic_inc_unchecked(&od->event);
48907 wake_up_interruptible(&od->poll);
48908 }
48909
48910diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
48911index a7ac78f..02158e1 100644
48912--- a/fs/sysfs/symlink.c
48913+++ b/fs/sysfs/symlink.c
48914@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
48915
48916 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
48917 {
48918- char *page = nd_get_link(nd);
48919+ const char *page = nd_get_link(nd);
48920 if (!IS_ERR(page))
48921 free_page((unsigned long)page);
48922 }
48923diff --git a/fs/udf/misc.c b/fs/udf/misc.c
48924index c175b4d..8f36a16 100644
48925--- a/fs/udf/misc.c
48926+++ b/fs/udf/misc.c
48927@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
48928
48929 u8 udf_tag_checksum(const struct tag *t)
48930 {
48931- u8 *data = (u8 *)t;
48932+ const u8 *data = (const u8 *)t;
48933 u8 checksum = 0;
48934 int i;
48935 for (i = 0; i < sizeof(struct tag); ++i)
48936diff --git a/fs/utimes.c b/fs/utimes.c
48937index ba653f3..06ea4b1 100644
48938--- a/fs/utimes.c
48939+++ b/fs/utimes.c
48940@@ -1,6 +1,7 @@
48941 #include <linux/compiler.h>
48942 #include <linux/file.h>
48943 #include <linux/fs.h>
48944+#include <linux/security.h>
48945 #include <linux/linkage.h>
48946 #include <linux/mount.h>
48947 #include <linux/namei.h>
48948@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
48949 goto mnt_drop_write_and_out;
48950 }
48951 }
48952+
48953+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
48954+ error = -EACCES;
48955+ goto mnt_drop_write_and_out;
48956+ }
48957+
48958 mutex_lock(&inode->i_mutex);
48959 error = notify_change(path->dentry, &newattrs);
48960 mutex_unlock(&inode->i_mutex);
48961diff --git a/fs/xattr.c b/fs/xattr.c
48962index 3c8c1cc..a83c398 100644
48963--- a/fs/xattr.c
48964+++ b/fs/xattr.c
48965@@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
48966 * Extended attribute SET operations
48967 */
48968 static long
48969-setxattr(struct dentry *d, const char __user *name, const void __user *value,
48970+setxattr(struct path *path, const char __user *name, const void __user *value,
48971 size_t size, int flags)
48972 {
48973 int error;
48974@@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
48975 }
48976 }
48977
48978- error = vfs_setxattr(d, kname, kvalue, size, flags);
48979+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
48980+ error = -EACCES;
48981+ goto out;
48982+ }
48983+
48984+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
48985 out:
48986 if (vvalue)
48987 vfree(vvalue);
48988@@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
48989 return error;
48990 error = mnt_want_write(path.mnt);
48991 if (!error) {
48992- error = setxattr(path.dentry, name, value, size, flags);
48993+ error = setxattr(&path, name, value, size, flags);
48994 mnt_drop_write(path.mnt);
48995 }
48996 path_put(&path);
48997@@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
48998 return error;
48999 error = mnt_want_write(path.mnt);
49000 if (!error) {
49001- error = setxattr(path.dentry, name, value, size, flags);
49002+ error = setxattr(&path, name, value, size, flags);
49003 mnt_drop_write(path.mnt);
49004 }
49005 path_put(&path);
49006@@ -400,17 +405,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
49007 const void __user *,value, size_t, size, int, flags)
49008 {
49009 struct file *f;
49010- struct dentry *dentry;
49011 int error = -EBADF;
49012
49013 f = fget(fd);
49014 if (!f)
49015 return error;
49016- dentry = f->f_path.dentry;
49017- audit_inode(NULL, dentry);
49018+ audit_inode(NULL, f->f_path.dentry);
49019 error = mnt_want_write_file(f);
49020 if (!error) {
49021- error = setxattr(dentry, name, value, size, flags);
49022+ error = setxattr(&f->f_path, name, value, size, flags);
49023 mnt_drop_write_file(f);
49024 }
49025 fput(f);
49026diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
49027index 69d06b0..c0996e5 100644
49028--- a/fs/xattr_acl.c
49029+++ b/fs/xattr_acl.c
49030@@ -17,8 +17,8 @@
49031 struct posix_acl *
49032 posix_acl_from_xattr(const void *value, size_t size)
49033 {
49034- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
49035- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
49036+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
49037+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
49038 int count;
49039 struct posix_acl *acl;
49040 struct posix_acl_entry *acl_e;
49041diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
49042index 85e7e32..5344e52 100644
49043--- a/fs/xfs/xfs_bmap.c
49044+++ b/fs/xfs/xfs_bmap.c
49045@@ -190,7 +190,7 @@ xfs_bmap_validate_ret(
49046 int nmap,
49047 int ret_nmap);
49048 #else
49049-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
49050+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
49051 #endif /* DEBUG */
49052
49053 STATIC int
49054diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
49055index 79d05e8..e3e5861 100644
49056--- a/fs/xfs/xfs_dir2_sf.c
49057+++ b/fs/xfs/xfs_dir2_sf.c
49058@@ -852,7 +852,15 @@ xfs_dir2_sf_getdents(
49059 }
49060
49061 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
49062- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49063+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
49064+ char name[sfep->namelen];
49065+ memcpy(name, sfep->name, sfep->namelen);
49066+ if (filldir(dirent, name, sfep->namelen,
49067+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
49068+ *offset = off & 0x7fffffff;
49069+ return 0;
49070+ }
49071+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49072 off & 0x7fffffff, ino, DT_UNKNOWN)) {
49073 *offset = off & 0x7fffffff;
49074 return 0;
49075diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
49076index 91f8ff5..0ce68f9 100644
49077--- a/fs/xfs/xfs_ioctl.c
49078+++ b/fs/xfs/xfs_ioctl.c
49079@@ -128,7 +128,7 @@ xfs_find_handle(
49080 }
49081
49082 error = -EFAULT;
49083- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
49084+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
49085 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
49086 goto out_put;
49087
49088diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
49089index 3011b87..1ab03e9 100644
49090--- a/fs/xfs/xfs_iops.c
49091+++ b/fs/xfs/xfs_iops.c
49092@@ -397,7 +397,7 @@ xfs_vn_put_link(
49093 struct nameidata *nd,
49094 void *p)
49095 {
49096- char *s = nd_get_link(nd);
49097+ const char *s = nd_get_link(nd);
49098
49099 if (!IS_ERR(s))
49100 kfree(s);
49101diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
49102new file mode 100644
49103index 0000000..2645296
49104--- /dev/null
49105+++ b/grsecurity/Kconfig
49106@@ -0,0 +1,1079 @@
49107+#
49108+# grecurity configuration
49109+#
49110+
49111+menu "Grsecurity"
49112+
49113+config GRKERNSEC
49114+ bool "Grsecurity"
49115+ select CRYPTO
49116+ select CRYPTO_SHA256
49117+ help
49118+ If you say Y here, you will be able to configure many features
49119+ that will enhance the security of your system. It is highly
49120+ recommended that you say Y here and read through the help
49121+ for each option so that you fully understand the features and
49122+ can evaluate their usefulness for your machine.
49123+
49124+choice
49125+ prompt "Security Level"
49126+ depends on GRKERNSEC
49127+ default GRKERNSEC_CUSTOM
49128+
49129+config GRKERNSEC_LOW
49130+ bool "Low"
49131+ select GRKERNSEC_LINK
49132+ select GRKERNSEC_FIFO
49133+ select GRKERNSEC_RANDNET
49134+ select GRKERNSEC_DMESG
49135+ select GRKERNSEC_CHROOT
49136+ select GRKERNSEC_CHROOT_CHDIR
49137+
49138+ help
49139+ If you choose this option, several of the grsecurity options will
49140+ be enabled that will give you greater protection against a number
49141+ of attacks, while assuring that none of your software will have any
49142+ conflicts with the additional security measures. If you run a lot
49143+ of unusual software, or you are having problems with the higher
49144+ security levels, you should say Y here. With this option, the
49145+ following features are enabled:
49146+
49147+ - Linking restrictions
49148+ - FIFO restrictions
49149+ - Restricted dmesg
49150+ - Enforced chdir("/") on chroot
49151+ - Runtime module disabling
49152+
49153+config GRKERNSEC_MEDIUM
49154+ bool "Medium"
49155+ select PAX
49156+ select PAX_EI_PAX
49157+ select PAX_PT_PAX_FLAGS
49158+ select PAX_HAVE_ACL_FLAGS
49159+ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
49160+ select GRKERNSEC_CHROOT
49161+ select GRKERNSEC_CHROOT_SYSCTL
49162+ select GRKERNSEC_LINK
49163+ select GRKERNSEC_FIFO
49164+ select GRKERNSEC_DMESG
49165+ select GRKERNSEC_RANDNET
49166+ select GRKERNSEC_FORKFAIL
49167+ select GRKERNSEC_TIME
49168+ select GRKERNSEC_SIGNAL
49169+ select GRKERNSEC_CHROOT
49170+ select GRKERNSEC_CHROOT_UNIX
49171+ select GRKERNSEC_CHROOT_MOUNT
49172+ select GRKERNSEC_CHROOT_PIVOT
49173+ select GRKERNSEC_CHROOT_DOUBLE
49174+ select GRKERNSEC_CHROOT_CHDIR
49175+ select GRKERNSEC_CHROOT_MKNOD
49176+ select GRKERNSEC_PROC
49177+ select GRKERNSEC_PROC_USERGROUP
49178+ select PAX_RANDUSTACK
49179+ select PAX_ASLR
49180+ select PAX_RANDMMAP
49181+ select PAX_REFCOUNT if (X86 || SPARC64)
49182+ select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
49183+
49184+ help
49185+ If you say Y here, several features in addition to those included
49186+ in the low additional security level will be enabled. These
49187+ features provide even more security to your system, though in rare
49188+ cases they may be incompatible with very old or poorly written
49189+ software. If you enable this option, make sure that your auth
49190+ service (identd) is running as gid 1001. With this option,
49191+ the following features (in addition to those provided in the
49192+ low additional security level) will be enabled:
49193+
49194+ - Failed fork logging
49195+ - Time change logging
49196+ - Signal logging
49197+ - Deny mounts in chroot
49198+ - Deny double chrooting
49199+ - Deny sysctl writes in chroot
49200+ - Deny mknod in chroot
49201+ - Deny access to abstract AF_UNIX sockets out of chroot
49202+ - Deny pivot_root in chroot
49203+ - Denied reads/writes of /dev/kmem, /dev/mem, and /dev/port
49204+ - /proc restrictions with special GID set to 10 (usually wheel)
49205+ - Address Space Layout Randomization (ASLR)
49206+ - Prevent exploitation of most refcount overflows
49207+ - Bounds checking of copying between the kernel and userland
49208+
49209+config GRKERNSEC_HIGH
49210+ bool "High"
49211+ select GRKERNSEC_LINK
49212+ select GRKERNSEC_FIFO
49213+ select GRKERNSEC_DMESG
49214+ select GRKERNSEC_FORKFAIL
49215+ select GRKERNSEC_TIME
49216+ select GRKERNSEC_SIGNAL
49217+ select GRKERNSEC_CHROOT
49218+ select GRKERNSEC_CHROOT_SHMAT
49219+ select GRKERNSEC_CHROOT_UNIX
49220+ select GRKERNSEC_CHROOT_MOUNT
49221+ select GRKERNSEC_CHROOT_FCHDIR
49222+ select GRKERNSEC_CHROOT_PIVOT
49223+ select GRKERNSEC_CHROOT_DOUBLE
49224+ select GRKERNSEC_CHROOT_CHDIR
49225+ select GRKERNSEC_CHROOT_MKNOD
49226+ select GRKERNSEC_CHROOT_CAPS
49227+ select GRKERNSEC_CHROOT_SYSCTL
49228+ select GRKERNSEC_CHROOT_FINDTASK
49229+ select GRKERNSEC_SYSFS_RESTRICT
49230+ select GRKERNSEC_PROC
49231+ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
49232+ select GRKERNSEC_HIDESYM
49233+ select GRKERNSEC_BRUTE
49234+ select GRKERNSEC_PROC_USERGROUP
49235+ select GRKERNSEC_KMEM
49236+ select GRKERNSEC_RESLOG
49237+ select GRKERNSEC_RANDNET
49238+ select GRKERNSEC_PROC_ADD
49239+ select GRKERNSEC_CHROOT_CHMOD
49240+ select GRKERNSEC_CHROOT_NICE
49241+ select GRKERNSEC_SETXID if (X86 || SPARC64 || PPC || ARM || MIPS)
49242+ select GRKERNSEC_AUDIT_MOUNT
49243+ select GRKERNSEC_MODHARDEN if (MODULES)
49244+ select GRKERNSEC_HARDEN_PTRACE
49245+ select GRKERNSEC_PTRACE_READEXEC
49246+ select GRKERNSEC_VM86 if (X86_32)
49247+ select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC)
49248+ select PAX
49249+ select PAX_RANDUSTACK
49250+ select PAX_ASLR
49251+ select PAX_RANDMMAP
49252+ select PAX_NOEXEC
49253+ select PAX_MPROTECT
49254+ select PAX_EI_PAX
49255+ select PAX_PT_PAX_FLAGS
49256+ select PAX_HAVE_ACL_FLAGS
49257+ select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
49258+ select PAX_MEMORY_UDEREF if (X86 && !XEN)
49259+ select PAX_RANDKSTACK if (X86_TSC && X86)
49260+ select PAX_SEGMEXEC if (X86_32)
49261+ select PAX_PAGEEXEC
49262+ select PAX_EMUPLT if (ALPHA || PARISC || SPARC)
49263+ select PAX_EMUTRAMP if (PARISC)
49264+ select PAX_EMUSIGRT if (PARISC)
49265+ select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
49266+ select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
49267+ select PAX_REFCOUNT if (X86 || SPARC64)
49268+ select PAX_USERCOPY if ((X86 || PPC || SPARC || ARM) && (SLAB || SLUB || SLOB))
49269+ help
49270+ If you say Y here, many of the features of grsecurity will be
49271+ enabled, which will protect you against many kinds of attacks
49272+ against your system. The heightened security comes at a cost
49273+ of an increased chance of incompatibilities with rare software
49274+ on your machine. Since this security level enables PaX, you should
49275+ view <http://pax.grsecurity.net> and read about the PaX
49276+ project. While you are there, download chpax and run it on
49277+ binaries that cause problems with PaX. Also remember that
49278+ since the /proc restrictions are enabled, you must run your
49279+ identd as gid 1001. This security level enables the following
49280+ features in addition to those listed in the low and medium
49281+ security levels:
49282+
49283+ - Additional /proc restrictions
49284+ - Chmod restrictions in chroot
49285+ - No signals, ptrace, or viewing of processes outside of chroot
49286+ - Capability restrictions in chroot
49287+ - Deny fchdir out of chroot
49288+ - Priority restrictions in chroot
49289+ - Segmentation-based implementation of PaX
49290+ - Mprotect restrictions
49291+ - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
49292+ - Kernel stack randomization
49293+ - Mount/unmount/remount logging
49294+ - Kernel symbol hiding
49295+ - Hardening of module auto-loading
49296+ - Ptrace restrictions
49297+ - Restricted vm86 mode
49298+ - Restricted sysfs/debugfs
49299+ - Active kernel exploit response
49300+
49301+config GRKERNSEC_CUSTOM
49302+ bool "Custom"
49303+ help
49304+ If you say Y here, you will be able to configure every grsecurity
49305+ option, which allows you to enable many more features that aren't
49306+ covered in the basic security levels. These additional features
49307+ include TPE, socket restrictions, and the sysctl system for
49308+ grsecurity. It is advised that you read through the help for
49309+ each option to determine its usefulness in your situation.
49310+
49311+endchoice
49312+
49313+menu "Memory Protections"
49314+depends on GRKERNSEC
49315+
49316+config GRKERNSEC_KMEM
49317+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
49318+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
49319+ help
49320+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
49321+ be written to or read from to modify or leak the contents of the running
49322+ kernel. /dev/port will also not be allowed to be opened. If you have module
49323+ support disabled, enabling this will close up four ways that are
49324+ currently used to insert malicious code into the running kernel.
49325+ Even with all these features enabled, we still highly recommend that
49326+ you use the RBAC system, as it is still possible for an attacker to
49327+ modify the running kernel through privileged I/O granted by ioperm/iopl.
49328+ If you are not using XFree86, you may be able to stop this additional
49329+ case by enabling the 'Disable privileged I/O' option. Though nothing
49330+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
49331+ but only to video memory, which is the only writing we allow in this
49332+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
49333+ not be allowed to mprotect it with PROT_WRITE later.
49334+ It is highly recommended that you say Y here if you meet all the
49335+ conditions above.
49336+
49337+config GRKERNSEC_VM86
49338+ bool "Restrict VM86 mode"
49339+ depends on X86_32
49340+
49341+ help
49342+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
49343+ make use of a special execution mode on 32bit x86 processors called
49344+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
49345+ video cards and will still work with this option enabled. The purpose
49346+ of the option is to prevent exploitation of emulation errors in
49347+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
49348+ Nearly all users should be able to enable this option.
49349+
49350+config GRKERNSEC_IO
49351+ bool "Disable privileged I/O"
49352+ depends on X86
49353+ select RTC_CLASS
49354+ select RTC_INTF_DEV
49355+ select RTC_DRV_CMOS
49356+
49357+ help
49358+ If you say Y here, all ioperm and iopl calls will return an error.
49359+ Ioperm and iopl can be used to modify the running kernel.
49360+ Unfortunately, some programs need this access to operate properly,
49361+ the most notable of which are XFree86 and hwclock. hwclock can be
49362+ remedied by having RTC support in the kernel, so real-time
49363+ clock support is enabled if this option is enabled, to ensure
49364+ that hwclock operates correctly. XFree86 still will not
49365+ operate correctly with this option enabled, so DO NOT CHOOSE Y
49366+ IF YOU USE XFree86. If you use XFree86 and you still want to
49367+ protect your kernel against modification, use the RBAC system.
49368+
49369+config GRKERNSEC_PROC_MEMMAP
49370+ bool "Harden ASLR against information leaks and entropy reduction"
49371+ default y if (PAX_NOEXEC || PAX_ASLR)
49372+ depends on PAX_NOEXEC || PAX_ASLR
49373+ help
49374+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
49375+ give no information about the addresses of its mappings if
49376+ PaX features that rely on random addresses are enabled on the task.
49377+ In addition to sanitizing this information and disabling other
49378+ dangerous sources of information, this option causes reads of sensitive
49379+ /proc/<pid> entries where the file descriptor was opened in a different
49380+ task than the one performing the read. Such attempts are logged.
49381+ This option also limits argv/env strings for suid/sgid binaries
49382+ to 512KB to prevent a complete exhaustion of the stack entropy provided
49383+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
49384+ binaries to prevent alternative mmap layouts from being abused.
49385+
49386+ If you use PaX it is essential that you say Y here as it closes up
49387+ several holes that make full ASLR useless locally.
49388+
49389+config GRKERNSEC_BRUTE
49390+ bool "Deter exploit bruteforcing"
49391+ help
49392+ If you say Y here, attempts to bruteforce exploits against forking
49393+ daemons such as apache or sshd, as well as against suid/sgid binaries
49394+ will be deterred. When a child of a forking daemon is killed by PaX
49395+ or crashes due to an illegal instruction or other suspicious signal,
49396+ the parent process will be delayed 30 seconds upon every subsequent
49397+ fork until the administrator is able to assess the situation and
49398+ restart the daemon.
49399+ In the suid/sgid case, the attempt is logged, the user has all their
49400+ processes terminated, and they are prevented from executing any further
49401+ processes for 15 minutes.
49402+ It is recommended that you also enable signal logging in the auditing
49403+ section so that logs are generated when a process triggers a suspicious
49404+ signal.
49405+ If the sysctl option is enabled, a sysctl option with name
49406+ "deter_bruteforce" is created.
49407+
49408+
49409+config GRKERNSEC_MODHARDEN
49410+ bool "Harden module auto-loading"
49411+ depends on MODULES
49412+ help
49413+ If you say Y here, module auto-loading in response to use of some
49414+ feature implemented by an unloaded module will be restricted to
49415+ root users. Enabling this option helps defend against attacks
49416+ by unprivileged users who abuse the auto-loading behavior to
49417+ cause a vulnerable module to load that is then exploited.
49418+
49419+ If this option prevents a legitimate use of auto-loading for a
49420+ non-root user, the administrator can execute modprobe manually
49421+ with the exact name of the module mentioned in the alert log.
49422+ Alternatively, the administrator can add the module to the list
49423+ of modules loaded at boot by modifying init scripts.
49424+
49425+ Modification of init scripts will most likely be needed on
49426+ Ubuntu servers with encrypted home directory support enabled,
49427+ as the first non-root user logging in will cause the ecb(aes),
49428+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
49429+
49430+config GRKERNSEC_HIDESYM
49431+ bool "Hide kernel symbols"
49432+ help
49433+ If you say Y here, getting information on loaded modules, and
49434+ displaying all kernel symbols through a syscall will be restricted
49435+ to users with CAP_SYS_MODULE. For software compatibility reasons,
49436+ /proc/kallsyms will be restricted to the root user. The RBAC
49437+ system can hide that entry even from root.
49438+
49439+ This option also prevents leaking of kernel addresses through
49440+ several /proc entries.
49441+
49442+ Note that this option is only effective provided the following
49443+ conditions are met:
49444+ 1) The kernel using grsecurity is not precompiled by some distribution
49445+ 2) You have also enabled GRKERNSEC_DMESG
49446+ 3) You are using the RBAC system and hiding other files such as your
49447+ kernel image and System.map. Alternatively, enabling this option
49448+ causes the permissions on /boot, /lib/modules, and the kernel
49449+ source directory to change at compile time to prevent
49450+ reading by non-root users.
49451+ If the above conditions are met, this option will aid in providing a
49452+ useful protection against local kernel exploitation of overflows
49453+ and arbitrary read/write vulnerabilities.
49454+
49455+config GRKERNSEC_KERN_LOCKOUT
49456+ bool "Active kernel exploit response"
49457+ depends on X86 || ARM || PPC || SPARC
49458+ help
49459+ If you say Y here, when a PaX alert is triggered due to suspicious
49460+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
49461+ or an OOPs occurs due to bad memory accesses, instead of just
49462+ terminating the offending process (and potentially allowing
49463+ a subsequent exploit from the same user), we will take one of two
49464+ actions:
49465+ If the user was root, we will panic the system
49466+ If the user was non-root, we will log the attempt, terminate
49467+ all processes owned by the user, then prevent them from creating
49468+ any new processes until the system is restarted
49469+ This deters repeated kernel exploitation/bruteforcing attempts
49470+ and is useful for later forensics.
49471+
49472+endmenu
49473+menu "Role Based Access Control Options"
49474+depends on GRKERNSEC
49475+
49476+config GRKERNSEC_RBAC_DEBUG
49477+ bool
49478+
49479+config GRKERNSEC_NO_RBAC
49480+ bool "Disable RBAC system"
49481+ help
49482+ If you say Y here, the /dev/grsec device will be removed from the kernel,
49483+ preventing the RBAC system from being enabled. You should only say Y
49484+ here if you have no intention of using the RBAC system, so as to prevent
49485+ an attacker with root access from misusing the RBAC system to hide files
49486+ and processes when loadable module support and /dev/[k]mem have been
49487+ locked down.
49488+
49489+config GRKERNSEC_ACL_HIDEKERN
49490+ bool "Hide kernel processes"
49491+ help
49492+ If you say Y here, all kernel threads will be hidden to all
49493+ processes but those whose subject has the "view hidden processes"
49494+ flag.
49495+
49496+config GRKERNSEC_ACL_MAXTRIES
49497+ int "Maximum tries before password lockout"
49498+ default 3
49499+ help
49500+ This option enforces the maximum number of times a user can attempt
49501+ to authorize themselves with the grsecurity RBAC system before being
49502+ denied the ability to attempt authorization again for a specified time.
49503+ The lower the number, the harder it will be to brute-force a password.
49504+
49505+config GRKERNSEC_ACL_TIMEOUT
49506+ int "Time to wait after max password tries, in seconds"
49507+ default 30
49508+ help
49509+ This option specifies the time the user must wait after attempting to
49510+ authorize to the RBAC system with the maximum number of invalid
49511+ passwords. The higher the number, the harder it will be to brute-force
49512+ a password.
49513+
49514+endmenu
49515+menu "Filesystem Protections"
49516+depends on GRKERNSEC
49517+
49518+config GRKERNSEC_PROC
49519+ bool "Proc restrictions"
49520+ help
49521+ If you say Y here, the permissions of the /proc filesystem
49522+ will be altered to enhance system security and privacy. You MUST
49523+ choose either a user only restriction or a user and group restriction.
49524+ Depending upon the option you choose, you can either restrict users to
49525+ see only the processes they themselves run, or choose a group that can
49526+ view all processes and files normally restricted to root if you choose
49527+ the "restrict to user only" option. NOTE: If you're running identd or
49528+ ntpd as a non-root user, you will have to run it as the group you
49529+ specify here.
49530+
49531+config GRKERNSEC_PROC_USER
49532+ bool "Restrict /proc to user only"
49533+ depends on GRKERNSEC_PROC
49534+ help
49535+ If you say Y here, non-root users will only be able to view their own
49536+ processes, and restricts them from viewing network-related information,
49537+ and viewing kernel symbol and module information.
49538+
49539+config GRKERNSEC_PROC_USERGROUP
49540+ bool "Allow special group"
49541+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
49542+ help
49543+ If you say Y here, you will be able to select a group that will be
49544+ able to view all processes and network-related information. If you've
49545+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
49546+ remain hidden. This option is useful if you want to run identd as
49547+ a non-root user.
49548+
49549+config GRKERNSEC_PROC_GID
49550+ int "GID for special group"
49551+ depends on GRKERNSEC_PROC_USERGROUP
49552+ default 1001
49553+
49554+config GRKERNSEC_PROC_ADD
49555+ bool "Additional restrictions"
49556+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
49557+ help
49558+ If you say Y here, additional restrictions will be placed on
49559+ /proc that keep normal users from viewing device information and
49560+ slabinfo information that could be useful for exploits.
49561+
49562+config GRKERNSEC_LINK
49563+ bool "Linking restrictions"
49564+ help
49565+ If you say Y here, /tmp race exploits will be prevented, since users
49566+ will no longer be able to follow symlinks owned by other users in
49567+ world-writable +t directories (e.g. /tmp), unless the owner of the
49568+ symlink is the owner of the directory. users will also not be
49569+ able to hardlink to files they do not own. If the sysctl option is
49570+ enabled, a sysctl option with name "linking_restrictions" is created.
49571+
49572+config GRKERNSEC_FIFO
49573+ bool "FIFO restrictions"
49574+ help
49575+ If you say Y here, users will not be able to write to FIFOs they don't
49576+ own in world-writable +t directories (e.g. /tmp), unless the owner of
49577+ the FIFO is the same owner of the directory it's held in. If the sysctl
49578+ option is enabled, a sysctl option with name "fifo_restrictions" is
49579+ created.
49580+
49581+config GRKERNSEC_SYSFS_RESTRICT
49582+ bool "Sysfs/debugfs restriction"
49583+ depends on SYSFS
49584+ help
49585+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
49586+ any filesystem normally mounted under it (e.g. debugfs) will be
49587+ mostly accessible only by root. These filesystems generally provide access
49588+ to hardware and debug information that isn't appropriate for unprivileged
49589+ users of the system. Sysfs and debugfs have also become a large source
49590+ of new vulnerabilities, ranging from infoleaks to local compromise.
49591+ There has been very little oversight with an eye toward security involved
49592+ in adding new exporters of information to these filesystems, so their
49593+ use is discouraged.
49594+ For reasons of compatibility, a few directories have been whitelisted
49595+ for access by non-root users:
49596+ /sys/fs/selinux
49597+ /sys/fs/fuse
49598+ /sys/devices/system/cpu
49599+
49600+config GRKERNSEC_ROFS
49601+ bool "Runtime read-only mount protection"
49602+ help
49603+ If you say Y here, a sysctl option with name "romount_protect" will
49604+ be created. By setting this option to 1 at runtime, filesystems
49605+ will be protected in the following ways:
49606+ * No new writable mounts will be allowed
49607+ * Existing read-only mounts won't be able to be remounted read/write
49608+ * Write operations will be denied on all block devices
49609+ This option acts independently of grsec_lock: once it is set to 1,
49610+ it cannot be turned off. Therefore, please be mindful of the resulting
49611+ behavior if this option is enabled in an init script on a read-only
49612+ filesystem. This feature is mainly intended for secure embedded systems.
49613+
49614+config GRKERNSEC_CHROOT
49615+ bool "Chroot jail restrictions"
49616+ help
49617+ If you say Y here, you will be able to choose several options that will
49618+ make breaking out of a chrooted jail much more difficult. If you
49619+ encounter no software incompatibilities with the following options, it
49620+ is recommended that you enable each one.
49621+
49622+config GRKERNSEC_CHROOT_MOUNT
49623+ bool "Deny mounts"
49624+ depends on GRKERNSEC_CHROOT
49625+ help
49626+ If you say Y here, processes inside a chroot will not be able to
49627+ mount or remount filesystems. If the sysctl option is enabled, a
49628+ sysctl option with name "chroot_deny_mount" is created.
49629+
49630+config GRKERNSEC_CHROOT_DOUBLE
49631+ bool "Deny double-chroots"
49632+ depends on GRKERNSEC_CHROOT
49633+ help
49634+ If you say Y here, processes inside a chroot will not be able to chroot
49635+ again outside the chroot. This is a widely used method of breaking
49636+ out of a chroot jail and should not be allowed. If the sysctl
49637+ option is enabled, a sysctl option with name
49638+ "chroot_deny_chroot" is created.
49639+
49640+config GRKERNSEC_CHROOT_PIVOT
49641+ bool "Deny pivot_root in chroot"
49642+ depends on GRKERNSEC_CHROOT
49643+ help
49644+ If you say Y here, processes inside a chroot will not be able to use
49645+ a function called pivot_root() that was introduced in Linux 2.3.41. It
49646+ works similar to chroot in that it changes the root filesystem. This
49647+ function could be misused in a chrooted process to attempt to break out
49648+ of the chroot, and therefore should not be allowed. If the sysctl
49649+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
49650+ created.
49651+
49652+config GRKERNSEC_CHROOT_CHDIR
49653+ bool "Enforce chdir(\"/\") on all chroots"
49654+ depends on GRKERNSEC_CHROOT
49655+ help
49656+ If you say Y here, the current working directory of all newly-chrooted
49657+ applications will be set to the the root directory of the chroot.
49658+ The man page on chroot(2) states:
49659+ Note that this call does not change the current working
49660+ directory, so that `.' can be outside the tree rooted at
49661+ `/'. In particular, the super-user can escape from a
49662+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
49663+
49664+ It is recommended that you say Y here, since it's not known to break
49665+ any software. If the sysctl option is enabled, a sysctl option with
49666+ name "chroot_enforce_chdir" is created.
49667+
49668+config GRKERNSEC_CHROOT_CHMOD
49669+ bool "Deny (f)chmod +s"
49670+ depends on GRKERNSEC_CHROOT
49671+ help
49672+ If you say Y here, processes inside a chroot will not be able to chmod
49673+ or fchmod files to make them have suid or sgid bits. This protects
49674+ against another published method of breaking a chroot. If the sysctl
49675+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
49676+ created.
49677+
49678+config GRKERNSEC_CHROOT_FCHDIR
49679+ bool "Deny fchdir out of chroot"
49680+ depends on GRKERNSEC_CHROOT
49681+ help
49682+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
49683+ to a file descriptor of the chrooting process that points to a directory
49684+ outside the filesystem will be stopped. If the sysctl option
49685+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
49686+
49687+config GRKERNSEC_CHROOT_MKNOD
49688+ bool "Deny mknod"
49689+ depends on GRKERNSEC_CHROOT
49690+ help
49691+ If you say Y here, processes inside a chroot will not be allowed to
49692+ mknod. The problem with using mknod inside a chroot is that it
49693+ would allow an attacker to create a device entry that is the same
49694+ as one on the physical root of your system, which could range from
49695+ anything from the console device to a device for your harddrive (which
49696+ they could then use to wipe the drive or steal data). It is recommended
49697+ that you say Y here, unless you run into software incompatibilities.
49698+ If the sysctl option is enabled, a sysctl option with name
49699+ "chroot_deny_mknod" is created.
49700+
49701+config GRKERNSEC_CHROOT_SHMAT
49702+ bool "Deny shmat() out of chroot"
49703+ depends on GRKERNSEC_CHROOT
49704+ help
49705+ If you say Y here, processes inside a chroot will not be able to attach
49706+ to shared memory segments that were created outside of the chroot jail.
49707+ It is recommended that you say Y here. If the sysctl option is enabled,
49708+ a sysctl option with name "chroot_deny_shmat" is created.
49709+
49710+config GRKERNSEC_CHROOT_UNIX
49711+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
49712+ depends on GRKERNSEC_CHROOT
49713+ help
49714+ If you say Y here, processes inside a chroot will not be able to
49715+ connect to abstract (meaning not belonging to a filesystem) Unix
49716+ domain sockets that were bound outside of a chroot. It is recommended
49717+ that you say Y here. If the sysctl option is enabled, a sysctl option
49718+ with name "chroot_deny_unix" is created.
49719+
49720+config GRKERNSEC_CHROOT_FINDTASK
49721+ bool "Protect outside processes"
49722+ depends on GRKERNSEC_CHROOT
49723+ help
49724+ If you say Y here, processes inside a chroot will not be able to
49725+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
49726+ getsid, or view any process outside of the chroot. If the sysctl
49727+ option is enabled, a sysctl option with name "chroot_findtask" is
49728+ created.
49729+
49730+config GRKERNSEC_CHROOT_NICE
49731+ bool "Restrict priority changes"
49732+ depends on GRKERNSEC_CHROOT
49733+ help
49734+ If you say Y here, processes inside a chroot will not be able to raise
49735+ the priority of processes in the chroot, or alter the priority of
49736+ processes outside the chroot. This provides more security than simply
49737+ removing CAP_SYS_NICE from the process' capability set. If the
49738+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
49739+ is created.
49740+
49741+config GRKERNSEC_CHROOT_SYSCTL
49742+ bool "Deny sysctl writes"
49743+ depends on GRKERNSEC_CHROOT
49744+ help
49745+ If you say Y here, an attacker in a chroot will not be able to
49746+ write to sysctl entries, either by sysctl(2) or through a /proc
49747+ interface. It is strongly recommended that you say Y here. If the
49748+ sysctl option is enabled, a sysctl option with name
49749+ "chroot_deny_sysctl" is created.
49750+
49751+config GRKERNSEC_CHROOT_CAPS
49752+ bool "Capability restrictions"
49753+ depends on GRKERNSEC_CHROOT
49754+ help
49755+ If you say Y here, the capabilities on all processes within a
49756+ chroot jail will be lowered to stop module insertion, raw i/o,
49757+ system and net admin tasks, rebooting the system, modifying immutable
49758+ files, modifying IPC owned by another, and changing the system time.
49759+ This is left an option because it can break some apps. Disable this
49760+ if your chrooted apps are having problems performing those kinds of
49761+ tasks. If the sysctl option is enabled, a sysctl option with
49762+ name "chroot_caps" is created.
49763+
49764+endmenu
49765+menu "Kernel Auditing"
49766+depends on GRKERNSEC
49767+
49768+config GRKERNSEC_AUDIT_GROUP
49769+ bool "Single group for auditing"
49770+ help
49771+ If you say Y here, the exec, chdir, and (un)mount logging features
49772+ will only operate on a group you specify. This option is recommended
49773+ if you only want to watch certain users instead of having a large
49774+ amount of logs from the entire system. If the sysctl option is enabled,
49775+ a sysctl option with name "audit_group" is created.
49776+
49777+config GRKERNSEC_AUDIT_GID
49778+ int "GID for auditing"
49779+ depends on GRKERNSEC_AUDIT_GROUP
49780+ default 1007
49781+
49782+config GRKERNSEC_EXECLOG
49783+ bool "Exec logging"
49784+ help
49785+ If you say Y here, all execve() calls will be logged (since the
49786+ other exec*() calls are frontends to execve(), all execution
49787+ will be logged). Useful for shell-servers that like to keep track
49788+ of their users. If the sysctl option is enabled, a sysctl option with
49789+ name "exec_logging" is created.
49790+ WARNING: This option when enabled will produce a LOT of logs, especially
49791+ on an active system.
49792+
49793+config GRKERNSEC_RESLOG
49794+ bool "Resource logging"
49795+ help
49796+ If you say Y here, all attempts to overstep resource limits will
49797+ be logged with the resource name, the requested size, and the current
49798+ limit. It is highly recommended that you say Y here. If the sysctl
49799+ option is enabled, a sysctl option with name "resource_logging" is
49800+ created. If the RBAC system is enabled, the sysctl value is ignored.
49801+
49802+config GRKERNSEC_CHROOT_EXECLOG
49803+ bool "Log execs within chroot"
49804+ help
49805+ If you say Y here, all executions inside a chroot jail will be logged
49806+ to syslog. This can cause a large amount of logs if certain
49807+ applications (eg. djb's daemontools) are installed on the system, and
49808+ is therefore left as an option. If the sysctl option is enabled, a
49809+ sysctl option with name "chroot_execlog" is created.
49810+
49811+config GRKERNSEC_AUDIT_PTRACE
49812+ bool "Ptrace logging"
49813+ help
49814+ If you say Y here, all attempts to attach to a process via ptrace
49815+ will be logged. If the sysctl option is enabled, a sysctl option
49816+ with name "audit_ptrace" is created.
49817+
49818+config GRKERNSEC_AUDIT_CHDIR
49819+ bool "Chdir logging"
49820+ help
49821+ If you say Y here, all chdir() calls will be logged. If the sysctl
49822+ option is enabled, a sysctl option with name "audit_chdir" is created.
49823+
49824+config GRKERNSEC_AUDIT_MOUNT
49825+ bool "(Un)Mount logging"
49826+ help
49827+ If you say Y here, all mounts and unmounts will be logged. If the
49828+ sysctl option is enabled, a sysctl option with name "audit_mount" is
49829+ created.
49830+
49831+config GRKERNSEC_SIGNAL
49832+ bool "Signal logging"
49833+ help
49834+ If you say Y here, certain important signals will be logged, such as
49835+ SIGSEGV, which will as a result inform you of when a error in a program
49836+ occurred, which in some cases could mean a possible exploit attempt.
49837+ If the sysctl option is enabled, a sysctl option with name
49838+ "signal_logging" is created.
49839+
49840+config GRKERNSEC_FORKFAIL
49841+ bool "Fork failure logging"
49842+ help
49843+ If you say Y here, all failed fork() attempts will be logged.
49844+ This could suggest a fork bomb, or someone attempting to overstep
49845+ their process limit. If the sysctl option is enabled, a sysctl option
49846+ with name "forkfail_logging" is created.
49847+
49848+config GRKERNSEC_TIME
49849+ bool "Time change logging"
49850+ help
49851+ If you say Y here, any changes of the system clock will be logged.
49852+ If the sysctl option is enabled, a sysctl option with name
49853+ "timechange_logging" is created.
49854+
49855+config GRKERNSEC_PROC_IPADDR
49856+ bool "/proc/<pid>/ipaddr support"
49857+ help
49858+ If you say Y here, a new entry will be added to each /proc/<pid>
49859+ directory that contains the IP address of the person using the task.
49860+ The IP is carried across local TCP and AF_UNIX stream sockets.
49861+ This information can be useful for IDS/IPSes to perform remote response
49862+ to a local attack. The entry is readable by only the owner of the
49863+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
49864+ the RBAC system), and thus does not create privacy concerns.
49865+
49866+config GRKERNSEC_RWXMAP_LOG
49867+ bool 'Denied RWX mmap/mprotect logging'
49868+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
49869+ help
49870+ If you say Y here, calls to mmap() and mprotect() with explicit
49871+ usage of PROT_WRITE and PROT_EXEC together will be logged when
49872+ denied by the PAX_MPROTECT feature. If the sysctl option is
49873+ enabled, a sysctl option with name "rwxmap_logging" is created.
49874+
49875+config GRKERNSEC_AUDIT_TEXTREL
49876+ bool 'ELF text relocations logging (READ HELP)'
49877+ depends on PAX_MPROTECT
49878+ help
49879+ If you say Y here, text relocations will be logged with the filename
49880+ of the offending library or binary. The purpose of the feature is
49881+ to help Linux distribution developers get rid of libraries and
49882+ binaries that need text relocations which hinder the future progress
49883+ of PaX. Only Linux distribution developers should say Y here, and
49884+ never on a production machine, as this option creates an information
49885+ leak that could aid an attacker in defeating the randomization of
49886+ a single memory region. If the sysctl option is enabled, a sysctl
49887+ option with name "audit_textrel" is created.
49888+
49889+endmenu
49890+
49891+menu "Executable Protections"
49892+depends on GRKERNSEC
49893+
49894+config GRKERNSEC_DMESG
49895+ bool "Dmesg(8) restriction"
49896+ help
49897+ If you say Y here, non-root users will not be able to use dmesg(8)
49898+ to view up to the last 4kb of messages in the kernel's log buffer.
49899+ The kernel's log buffer often contains kernel addresses and other
49900+ identifying information useful to an attacker in fingerprinting a
49901+ system for a targeted exploit.
49902+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
49903+ created.
49904+
49905+config GRKERNSEC_HARDEN_PTRACE
49906+ bool "Deter ptrace-based process snooping"
49907+ help
49908+ If you say Y here, TTY sniffers and other malicious monitoring
49909+ programs implemented through ptrace will be defeated. If you
49910+ have been using the RBAC system, this option has already been
49911+ enabled for several years for all users, with the ability to make
49912+ fine-grained exceptions.
49913+
49914+ This option only affects the ability of non-root users to ptrace
49915+ processes that are not a descendent of the ptracing process.
49916+ This means that strace ./binary and gdb ./binary will still work,
49917+ but attaching to arbitrary processes will not. If the sysctl
49918+ option is enabled, a sysctl option with name "harden_ptrace" is
49919+ created.
49920+
49921+config GRKERNSEC_PTRACE_READEXEC
49922+ bool "Require read access to ptrace sensitive binaries"
49923+ help
49924+ If you say Y here, unprivileged users will not be able to ptrace unreadable
49925+ binaries. This option is useful in environments that
49926+ remove the read bits (e.g. file mode 4711) from suid binaries to
49927+ prevent infoleaking of their contents. This option adds
49928+ consistency to the use of that file mode, as the binary could normally
49929+ be read out when run without privileges while ptracing.
49930+
49931+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
49932+ is created.
49933+
49934+config GRKERNSEC_SETXID
49935+ bool "Enforce consistent multithreaded privileges"
49936+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
49937+ help
49938+ If you say Y here, a change from a root uid to a non-root uid
49939+ in a multithreaded application will cause the resulting uids,
49940+ gids, supplementary groups, and capabilities in that thread
49941+ to be propagated to the other threads of the process. In most
49942+ cases this is unnecessary, as glibc will emulate this behavior
49943+ on behalf of the application. Other libcs do not act in the
49944+ same way, allowing the other threads of the process to continue
49945+ running with root privileges. If the sysctl option is enabled,
49946+ a sysctl option with name "consistent_setxid" is created.
49947+
49948+config GRKERNSEC_TPE
49949+ bool "Trusted Path Execution (TPE)"
49950+ help
49951+ If you say Y here, you will be able to choose a gid to add to the
49952+ supplementary groups of users you want to mark as "untrusted."
49953+ These users will not be able to execute any files that are not in
49954+ root-owned directories writable only by root. If the sysctl option
49955+ is enabled, a sysctl option with name "tpe" is created.
49956+
49957+config GRKERNSEC_TPE_ALL
49958+ bool "Partially restrict all non-root users"
49959+ depends on GRKERNSEC_TPE
49960+ help
49961+ If you say Y here, all non-root users will be covered under
49962+ a weaker TPE restriction. This is separate from, and in addition to,
49963+ the main TPE options that you have selected elsewhere. Thus, if a
49964+ "trusted" GID is chosen, this restriction applies to even that GID.
49965+ Under this restriction, all non-root users will only be allowed to
49966+ execute files in directories they own that are not group or
49967+ world-writable, or in directories owned by root and writable only by
49968+ root. If the sysctl option is enabled, a sysctl option with name
49969+ "tpe_restrict_all" is created.
49970+
49971+config GRKERNSEC_TPE_INVERT
49972+ bool "Invert GID option"
49973+ depends on GRKERNSEC_TPE
49974+ help
49975+ If you say Y here, the group you specify in the TPE configuration will
49976+ decide what group TPE restrictions will be *disabled* for. This
49977+ option is useful if you want TPE restrictions to be applied to most
49978+ users on the system. If the sysctl option is enabled, a sysctl option
49979+ with name "tpe_invert" is created. Unlike other sysctl options, this
49980+ entry will default to on for backward-compatibility.
49981+
49982+config GRKERNSEC_TPE_GID
49983+ int "GID for untrusted users"
49984+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
49985+ default 1005
49986+ help
49987+ Setting this GID determines what group TPE restrictions will be
49988+ *enabled* for. If the sysctl option is enabled, a sysctl option
49989+ with name "tpe_gid" is created.
49990+
49991+config GRKERNSEC_TPE_GID
49992+ int "GID for trusted users"
49993+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
49994+ default 1005
49995+ help
49996+ Setting this GID determines what group TPE restrictions will be
49997+ *disabled* for. If the sysctl option is enabled, a sysctl option
49998+ with name "tpe_gid" is created.
49999+
50000+endmenu
50001+menu "Network Protections"
50002+depends on GRKERNSEC
50003+
50004+config GRKERNSEC_RANDNET
50005+ bool "Larger entropy pools"
50006+ help
50007+ If you say Y here, the entropy pools used for many features of Linux
50008+ and grsecurity will be doubled in size. Since several grsecurity
50009+ features use additional randomness, it is recommended that you say Y
50010+ here. Saying Y here has a similar effect as modifying
50011+ /proc/sys/kernel/random/poolsize.
50012+
50013+config GRKERNSEC_BLACKHOLE
50014+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
50015+ depends on NET
50016+ help
50017+ If you say Y here, neither TCP resets nor ICMP
50018+ destination-unreachable packets will be sent in response to packets
50019+ sent to ports for which no associated listening process exists.
50020+ This feature supports both IPV4 and IPV6 and exempts the
50021+ loopback interface from blackholing. Enabling this feature
50022+ makes a host more resilient to DoS attacks and reduces network
50023+ visibility against scanners.
50024+
50025+ The blackhole feature as-implemented is equivalent to the FreeBSD
50026+ blackhole feature, as it prevents RST responses to all packets, not
50027+ just SYNs. Under most application behavior this causes no
50028+ problems, but applications (like haproxy) may not close certain
50029+ connections in a way that cleanly terminates them on the remote
50030+ end, leaving the remote host in LAST_ACK state. Because of this
50031+ side-effect and to prevent intentional LAST_ACK DoSes, this
50032+ feature also adds automatic mitigation against such attacks.
50033+ The mitigation drastically reduces the amount of time a socket
50034+ can spend in LAST_ACK state. If you're using haproxy and not
50035+ all servers it connects to have this option enabled, consider
50036+ disabling this feature on the haproxy host.
50037+
50038+ If the sysctl option is enabled, two sysctl options with names
50039+ "ip_blackhole" and "lastack_retries" will be created.
50040+ While "ip_blackhole" takes the standard zero/non-zero on/off
50041+ toggle, "lastack_retries" uses the same kinds of values as
50042+ "tcp_retries1" and "tcp_retries2". The default value of 4
50043+ prevents a socket from lasting more than 45 seconds in LAST_ACK
50044+ state.
50045+
50046+config GRKERNSEC_SOCKET
50047+ bool "Socket restrictions"
50048+ depends on NET
50049+ help
50050+ If you say Y here, you will be able to choose from several options.
50051+ If you assign a GID on your system and add it to the supplementary
50052+ groups of users you want to restrict socket access to, this patch
50053+ will perform up to three things, based on the option(s) you choose.
50054+
50055+config GRKERNSEC_SOCKET_ALL
50056+ bool "Deny any sockets to group"
50057+ depends on GRKERNSEC_SOCKET
50058+ help
50059+ If you say Y here, you will be able to choose a GID of whose users will
50060+ be unable to connect to other hosts from your machine or run server
50061+ applications from your machine. If the sysctl option is enabled, a
50062+ sysctl option with name "socket_all" is created.
50063+
50064+config GRKERNSEC_SOCKET_ALL_GID
50065+ int "GID to deny all sockets for"
50066+ depends on GRKERNSEC_SOCKET_ALL
50067+ default 1004
50068+ help
50069+ Here you can choose the GID to disable socket access for. Remember to
50070+ add the users you want socket access disabled for to the GID
50071+ specified here. If the sysctl option is enabled, a sysctl option
50072+ with name "socket_all_gid" is created.
50073+
50074+config GRKERNSEC_SOCKET_CLIENT
50075+ bool "Deny client sockets to group"
50076+ depends on GRKERNSEC_SOCKET
50077+ help
50078+ If you say Y here, you will be able to choose a GID of whose users will
50079+ be unable to connect to other hosts from your machine, but will be
50080+ able to run servers. If this option is enabled, all users in the group
50081+ you specify will have to use passive mode when initiating ftp transfers
50082+ from the shell on your machine. If the sysctl option is enabled, a
50083+ sysctl option with name "socket_client" is created.
50084+
50085+config GRKERNSEC_SOCKET_CLIENT_GID
50086+ int "GID to deny client sockets for"
50087+ depends on GRKERNSEC_SOCKET_CLIENT
50088+ default 1003
50089+ help
50090+ Here you can choose the GID to disable client socket access for.
50091+ Remember to add the users you want client socket access disabled for to
50092+ the GID specified here. If the sysctl option is enabled, a sysctl
50093+ option with name "socket_client_gid" is created.
50094+
50095+config GRKERNSEC_SOCKET_SERVER
50096+ bool "Deny server sockets to group"
50097+ depends on GRKERNSEC_SOCKET
50098+ help
50099+ If you say Y here, you will be able to choose a GID of whose users will
50100+ be unable to run server applications from your machine. If the sysctl
50101+ option is enabled, a sysctl option with name "socket_server" is created.
50102+
50103+config GRKERNSEC_SOCKET_SERVER_GID
50104+ int "GID to deny server sockets for"
50105+ depends on GRKERNSEC_SOCKET_SERVER
50106+ default 1002
50107+ help
50108+ Here you can choose the GID to disable server socket access for.
50109+ Remember to add the users you want server socket access disabled for to
50110+ the GID specified here. If the sysctl option is enabled, a sysctl
50111+ option with name "socket_server_gid" is created.
50112+
50113+endmenu
50114+menu "Sysctl support"
50115+depends on GRKERNSEC && SYSCTL
50116+
50117+config GRKERNSEC_SYSCTL
50118+ bool "Sysctl support"
50119+ help
50120+ If you say Y here, you will be able to change the options that
50121+ grsecurity runs with at bootup, without having to recompile your
50122+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
50123+ to enable (1) or disable (0) various features. All the sysctl entries
50124+ are mutable until the "grsec_lock" entry is set to a non-zero value.
50125+ All features enabled in the kernel configuration are disabled at boot
50126+ if you do not say Y to the "Turn on features by default" option.
50127+ All options should be set at startup, and the grsec_lock entry should
50128+ be set to a non-zero value after all the options are set.
50129+ *THIS IS EXTREMELY IMPORTANT*
50130+
50131+config GRKERNSEC_SYSCTL_DISTRO
50132+ bool "Extra sysctl support for distro makers (READ HELP)"
50133+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
50134+ help
50135+ If you say Y here, additional sysctl options will be created
50136+ for features that affect processes running as root. Therefore,
50137+ it is critical when using this option that the grsec_lock entry be
50138+ enabled after boot. Only distros with prebuilt kernel packages
50139+ with this option enabled that can ensure grsec_lock is enabled
50140+ after boot should use this option.
50141+ *Failure to set grsec_lock after boot makes all grsec features
50142+ this option covers useless*
50143+
50144+ Currently this option creates the following sysctl entries:
50145+ "Disable Privileged I/O": "disable_priv_io"
50146+
50147+config GRKERNSEC_SYSCTL_ON
50148+ bool "Turn on features by default"
50149+ depends on GRKERNSEC_SYSCTL
50150+ help
50151+ If you say Y here, instead of having all features enabled in the
50152+ kernel configuration disabled at boot time, the features will be
50153+ enabled at boot time. It is recommended you say Y here unless
50154+ there is some reason you would want all sysctl-tunable features to
50155+ be disabled by default. As mentioned elsewhere, it is important
50156+ to enable the grsec_lock entry once you have finished modifying
50157+ the sysctl entries.
50158+
50159+endmenu
50160+menu "Logging Options"
50161+depends on GRKERNSEC
50162+
50163+config GRKERNSEC_FLOODTIME
50164+ int "Seconds in between log messages (minimum)"
50165+ default 10
50166+ help
50167+ This option allows you to enforce the number of seconds between
50168+ grsecurity log messages. The default should be suitable for most
50169+ people, however, if you choose to change it, choose a value small enough
50170+ to allow informative logs to be produced, but large enough to
50171+ prevent flooding.
50172+
50173+config GRKERNSEC_FLOODBURST
50174+ int "Number of messages in a burst (maximum)"
50175+ default 6
50176+ help
50177+ This option allows you to choose the maximum number of messages allowed
50178+ within the flood time interval you chose in a separate option. The
50179+ default should be suitable for most people, however if you find that
50180+ many of your logs are being interpreted as flooding, you may want to
50181+ raise this value.
50182+
50183+endmenu
50184+
50185+endmenu
50186diff --git a/grsecurity/Makefile b/grsecurity/Makefile
50187new file mode 100644
50188index 0000000..1b9afa9
50189--- /dev/null
50190+++ b/grsecurity/Makefile
50191@@ -0,0 +1,38 @@
50192+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
50193+# during 2001-2009 it has been completely redesigned by Brad Spengler
50194+# into an RBAC system
50195+#
50196+# All code in this directory and various hooks inserted throughout the kernel
50197+# are copyright Brad Spengler - Open Source Security, Inc., and released
50198+# under the GPL v2 or higher
50199+
50200+KBUILD_CFLAGS += -Werror
50201+
50202+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
50203+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
50204+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
50205+
50206+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
50207+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
50208+ gracl_learn.o grsec_log.o
50209+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
50210+
50211+ifdef CONFIG_NET
50212+obj-y += grsec_sock.o
50213+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
50214+endif
50215+
50216+ifndef CONFIG_GRKERNSEC
50217+obj-y += grsec_disabled.o
50218+endif
50219+
50220+ifdef CONFIG_GRKERNSEC_HIDESYM
50221+extra-y := grsec_hidesym.o
50222+$(obj)/grsec_hidesym.o:
50223+ @-chmod -f 500 /boot
50224+ @-chmod -f 500 /lib/modules
50225+ @-chmod -f 500 /lib64/modules
50226+ @-chmod -f 500 /lib32/modules
50227+ @-chmod -f 700 .
50228+ @echo ' grsec: protected kernel image paths'
50229+endif
50230diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
50231new file mode 100644
50232index 0000000..00b6c54
50233--- /dev/null
50234+++ b/grsecurity/gracl.c
50235@@ -0,0 +1,4012 @@
50236+#include <linux/kernel.h>
50237+#include <linux/module.h>
50238+#include <linux/sched.h>
50239+#include <linux/mm.h>
50240+#include <linux/file.h>
50241+#include <linux/fs.h>
50242+#include <linux/namei.h>
50243+#include <linux/mount.h>
50244+#include <linux/tty.h>
50245+#include <linux/proc_fs.h>
50246+#include <linux/lglock.h>
50247+#include <linux/slab.h>
50248+#include <linux/vmalloc.h>
50249+#include <linux/types.h>
50250+#include <linux/sysctl.h>
50251+#include <linux/netdevice.h>
50252+#include <linux/ptrace.h>
50253+#include <linux/gracl.h>
50254+#include <linux/gralloc.h>
50255+#include <linux/security.h>
50256+#include <linux/grinternal.h>
50257+#include <linux/pid_namespace.h>
50258+#include <linux/fdtable.h>
50259+#include <linux/percpu.h>
50260+#include "../fs/mount.h"
50261+
50262+#include <asm/uaccess.h>
50263+#include <asm/errno.h>
50264+#include <asm/mman.h>
50265+
50266+static struct acl_role_db acl_role_set;
50267+static struct name_db name_set;
50268+static struct inodev_db inodev_set;
50269+
50270+/* for keeping track of userspace pointers used for subjects, so we
50271+ can share references in the kernel as well
50272+*/
50273+
50274+static struct path real_root;
50275+
50276+static struct acl_subj_map_db subj_map_set;
50277+
50278+static struct acl_role_label *default_role;
50279+
50280+static struct acl_role_label *role_list;
50281+
50282+static u16 acl_sp_role_value;
50283+
50284+extern char *gr_shared_page[4];
50285+static DEFINE_MUTEX(gr_dev_mutex);
50286+DEFINE_RWLOCK(gr_inode_lock);
50287+
50288+struct gr_arg *gr_usermode;
50289+
50290+static unsigned int gr_status __read_only = GR_STATUS_INIT;
50291+
50292+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
50293+extern void gr_clear_learn_entries(void);
50294+
50295+#ifdef CONFIG_GRKERNSEC_RESLOG
50296+extern void gr_log_resource(const struct task_struct *task,
50297+ const int res, const unsigned long wanted, const int gt);
50298+#endif
50299+
50300+unsigned char *gr_system_salt;
50301+unsigned char *gr_system_sum;
50302+
50303+static struct sprole_pw **acl_special_roles = NULL;
50304+static __u16 num_sprole_pws = 0;
50305+
50306+static struct acl_role_label *kernel_role = NULL;
50307+
50308+static unsigned int gr_auth_attempts = 0;
50309+static unsigned long gr_auth_expires = 0UL;
50310+
50311+#ifdef CONFIG_NET
50312+extern struct vfsmount *sock_mnt;
50313+#endif
50314+
50315+extern struct vfsmount *pipe_mnt;
50316+extern struct vfsmount *shm_mnt;
50317+#ifdef CONFIG_HUGETLBFS
50318+extern struct vfsmount *hugetlbfs_vfsmount;
50319+#endif
50320+
50321+static struct acl_object_label *fakefs_obj_rw;
50322+static struct acl_object_label *fakefs_obj_rwx;
50323+
50324+extern int gr_init_uidset(void);
50325+extern void gr_free_uidset(void);
50326+extern void gr_remove_uid(uid_t uid);
50327+extern int gr_find_uid(uid_t uid);
50328+
50329+DECLARE_BRLOCK(vfsmount_lock);
50330+
50331+__inline__ int
50332+gr_acl_is_enabled(void)
50333+{
50334+ return (gr_status & GR_READY);
50335+}
50336+
50337+#ifdef CONFIG_BTRFS_FS
50338+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
50339+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
50340+#endif
50341+
50342+static inline dev_t __get_dev(const struct dentry *dentry)
50343+{
50344+#ifdef CONFIG_BTRFS_FS
50345+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
50346+ return get_btrfs_dev_from_inode(dentry->d_inode);
50347+ else
50348+#endif
50349+ return dentry->d_inode->i_sb->s_dev;
50350+}
50351+
50352+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
50353+{
50354+ return __get_dev(dentry);
50355+}
50356+
50357+static char gr_task_roletype_to_char(struct task_struct *task)
50358+{
50359+ switch (task->role->roletype &
50360+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
50361+ GR_ROLE_SPECIAL)) {
50362+ case GR_ROLE_DEFAULT:
50363+ return 'D';
50364+ case GR_ROLE_USER:
50365+ return 'U';
50366+ case GR_ROLE_GROUP:
50367+ return 'G';
50368+ case GR_ROLE_SPECIAL:
50369+ return 'S';
50370+ }
50371+
50372+ return 'X';
50373+}
50374+
50375+char gr_roletype_to_char(void)
50376+{
50377+ return gr_task_roletype_to_char(current);
50378+}
50379+
50380+__inline__ int
50381+gr_acl_tpe_check(void)
50382+{
50383+ if (unlikely(!(gr_status & GR_READY)))
50384+ return 0;
50385+ if (current->role->roletype & GR_ROLE_TPE)
50386+ return 1;
50387+ else
50388+ return 0;
50389+}
50390+
50391+int
50392+gr_handle_rawio(const struct inode *inode)
50393+{
50394+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
50395+ if (inode && S_ISBLK(inode->i_mode) &&
50396+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
50397+ !capable(CAP_SYS_RAWIO))
50398+ return 1;
50399+#endif
50400+ return 0;
50401+}
50402+
50403+static int
50404+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
50405+{
50406+ if (likely(lena != lenb))
50407+ return 0;
50408+
50409+ return !memcmp(a, b, lena);
50410+}
50411+
50412+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
50413+{
50414+ *buflen -= namelen;
50415+ if (*buflen < 0)
50416+ return -ENAMETOOLONG;
50417+ *buffer -= namelen;
50418+ memcpy(*buffer, str, namelen);
50419+ return 0;
50420+}
50421+
50422+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
50423+{
50424+ return prepend(buffer, buflen, name->name, name->len);
50425+}
50426+
50427+static int prepend_path(const struct path *path, struct path *root,
50428+ char **buffer, int *buflen)
50429+{
50430+ struct dentry *dentry = path->dentry;
50431+ struct vfsmount *vfsmnt = path->mnt;
50432+ struct mount *mnt = real_mount(vfsmnt);
50433+ bool slash = false;
50434+ int error = 0;
50435+
50436+ while (dentry != root->dentry || vfsmnt != root->mnt) {
50437+ struct dentry * parent;
50438+
50439+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
50440+ /* Global root? */
50441+ if (!mnt_has_parent(mnt)) {
50442+ goto out;
50443+ }
50444+ dentry = mnt->mnt_mountpoint;
50445+ mnt = mnt->mnt_parent;
50446+ vfsmnt = &mnt->mnt;
50447+ continue;
50448+ }
50449+ parent = dentry->d_parent;
50450+ prefetch(parent);
50451+ spin_lock(&dentry->d_lock);
50452+ error = prepend_name(buffer, buflen, &dentry->d_name);
50453+ spin_unlock(&dentry->d_lock);
50454+ if (!error)
50455+ error = prepend(buffer, buflen, "/", 1);
50456+ if (error)
50457+ break;
50458+
50459+ slash = true;
50460+ dentry = parent;
50461+ }
50462+
50463+out:
50464+ if (!error && !slash)
50465+ error = prepend(buffer, buflen, "/", 1);
50466+
50467+ return error;
50468+}
50469+
50470+/* this must be called with vfsmount_lock and rename_lock held */
50471+
50472+static char *__our_d_path(const struct path *path, struct path *root,
50473+ char *buf, int buflen)
50474+{
50475+ char *res = buf + buflen;
50476+ int error;
50477+
50478+ prepend(&res, &buflen, "\0", 1);
50479+ error = prepend_path(path, root, &res, &buflen);
50480+ if (error)
50481+ return ERR_PTR(error);
50482+
50483+ return res;
50484+}
50485+
50486+static char *
50487+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
50488+{
50489+ char *retval;
50490+
50491+ retval = __our_d_path(path, root, buf, buflen);
50492+ if (unlikely(IS_ERR(retval)))
50493+ retval = strcpy(buf, "<path too long>");
50494+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
50495+ retval[1] = '\0';
50496+
50497+ return retval;
50498+}
50499+
50500+static char *
50501+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
50502+ char *buf, int buflen)
50503+{
50504+ struct path path;
50505+ char *res;
50506+
50507+ path.dentry = (struct dentry *)dentry;
50508+ path.mnt = (struct vfsmount *)vfsmnt;
50509+
50510+ /* we can use real_root.dentry, real_root.mnt, because this is only called
50511+ by the RBAC system */
50512+ res = gen_full_path(&path, &real_root, buf, buflen);
50513+
50514+ return res;
50515+}
50516+
50517+static char *
50518+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
50519+ char *buf, int buflen)
50520+{
50521+ char *res;
50522+ struct path path;
50523+ struct path root;
50524+ struct task_struct *reaper = init_pid_ns.child_reaper;
50525+
50526+ path.dentry = (struct dentry *)dentry;
50527+ path.mnt = (struct vfsmount *)vfsmnt;
50528+
50529+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
50530+ get_fs_root(reaper->fs, &root);
50531+
50532+ write_seqlock(&rename_lock);
50533+ br_read_lock(vfsmount_lock);
50534+ res = gen_full_path(&path, &root, buf, buflen);
50535+ br_read_unlock(vfsmount_lock);
50536+ write_sequnlock(&rename_lock);
50537+
50538+ path_put(&root);
50539+ return res;
50540+}
50541+
50542+static char *
50543+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
50544+{
50545+ char *ret;
50546+ write_seqlock(&rename_lock);
50547+ br_read_lock(vfsmount_lock);
50548+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
50549+ PAGE_SIZE);
50550+ br_read_unlock(vfsmount_lock);
50551+ write_sequnlock(&rename_lock);
50552+ return ret;
50553+}
50554+
50555+static char *
50556+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
50557+{
50558+ char *ret;
50559+ char *buf;
50560+ int buflen;
50561+
50562+ write_seqlock(&rename_lock);
50563+ br_read_lock(vfsmount_lock);
50564+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
50565+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
50566+ buflen = (int)(ret - buf);
50567+ if (buflen >= 5)
50568+ prepend(&ret, &buflen, "/proc", 5);
50569+ else
50570+ ret = strcpy(buf, "<path too long>");
50571+ br_read_unlock(vfsmount_lock);
50572+ write_sequnlock(&rename_lock);
50573+ return ret;
50574+}
50575+
50576+char *
50577+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
50578+{
50579+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
50580+ PAGE_SIZE);
50581+}
50582+
50583+char *
50584+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
50585+{
50586+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
50587+ PAGE_SIZE);
50588+}
50589+
50590+char *
50591+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
50592+{
50593+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
50594+ PAGE_SIZE);
50595+}
50596+
50597+char *
50598+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
50599+{
50600+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
50601+ PAGE_SIZE);
50602+}
50603+
50604+char *
50605+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
50606+{
50607+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
50608+ PAGE_SIZE);
50609+}
50610+
50611+__inline__ __u32
50612+to_gr_audit(const __u32 reqmode)
50613+{
50614+ /* masks off auditable permission flags, then shifts them to create
50615+ auditing flags, and adds the special case of append auditing if
50616+ we're requesting write */
50617+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
50618+}
50619+
50620+struct acl_subject_label *
50621+lookup_subject_map(const struct acl_subject_label *userp)
50622+{
50623+ unsigned int index = shash(userp, subj_map_set.s_size);
50624+ struct subject_map *match;
50625+
50626+ match = subj_map_set.s_hash[index];
50627+
50628+ while (match && match->user != userp)
50629+ match = match->next;
50630+
50631+ if (match != NULL)
50632+ return match->kernel;
50633+ else
50634+ return NULL;
50635+}
50636+
50637+static void
50638+insert_subj_map_entry(struct subject_map *subjmap)
50639+{
50640+ unsigned int index = shash(subjmap->user, subj_map_set.s_size);
50641+ struct subject_map **curr;
50642+
50643+ subjmap->prev = NULL;
50644+
50645+ curr = &subj_map_set.s_hash[index];
50646+ if (*curr != NULL)
50647+ (*curr)->prev = subjmap;
50648+
50649+ subjmap->next = *curr;
50650+ *curr = subjmap;
50651+
50652+ return;
50653+}
50654+
50655+static struct acl_role_label *
50656+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
50657+ const gid_t gid)
50658+{
50659+ unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
50660+ struct acl_role_label *match;
50661+ struct role_allowed_ip *ipp;
50662+ unsigned int x;
50663+ u32 curr_ip = task->signal->curr_ip;
50664+
50665+ task->signal->saved_ip = curr_ip;
50666+
50667+ match = acl_role_set.r_hash[index];
50668+
50669+ while (match) {
50670+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
50671+ for (x = 0; x < match->domain_child_num; x++) {
50672+ if (match->domain_children[x] == uid)
50673+ goto found;
50674+ }
50675+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
50676+ break;
50677+ match = match->next;
50678+ }
50679+found:
50680+ if (match == NULL) {
50681+ try_group:
50682+ index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
50683+ match = acl_role_set.r_hash[index];
50684+
50685+ while (match) {
50686+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
50687+ for (x = 0; x < match->domain_child_num; x++) {
50688+ if (match->domain_children[x] == gid)
50689+ goto found2;
50690+ }
50691+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
50692+ break;
50693+ match = match->next;
50694+ }
50695+found2:
50696+ if (match == NULL)
50697+ match = default_role;
50698+ if (match->allowed_ips == NULL)
50699+ return match;
50700+ else {
50701+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
50702+ if (likely
50703+ ((ntohl(curr_ip) & ipp->netmask) ==
50704+ (ntohl(ipp->addr) & ipp->netmask)))
50705+ return match;
50706+ }
50707+ match = default_role;
50708+ }
50709+ } else if (match->allowed_ips == NULL) {
50710+ return match;
50711+ } else {
50712+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
50713+ if (likely
50714+ ((ntohl(curr_ip) & ipp->netmask) ==
50715+ (ntohl(ipp->addr) & ipp->netmask)))
50716+ return match;
50717+ }
50718+ goto try_group;
50719+ }
50720+
50721+ return match;
50722+}
50723+
50724+struct acl_subject_label *
50725+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
50726+ const struct acl_role_label *role)
50727+{
50728+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
50729+ struct acl_subject_label *match;
50730+
50731+ match = role->subj_hash[index];
50732+
50733+ while (match && (match->inode != ino || match->device != dev ||
50734+ (match->mode & GR_DELETED))) {
50735+ match = match->next;
50736+ }
50737+
50738+ if (match && !(match->mode & GR_DELETED))
50739+ return match;
50740+ else
50741+ return NULL;
50742+}
50743+
50744+struct acl_subject_label *
50745+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
50746+ const struct acl_role_label *role)
50747+{
50748+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
50749+ struct acl_subject_label *match;
50750+
50751+ match = role->subj_hash[index];
50752+
50753+ while (match && (match->inode != ino || match->device != dev ||
50754+ !(match->mode & GR_DELETED))) {
50755+ match = match->next;
50756+ }
50757+
50758+ if (match && (match->mode & GR_DELETED))
50759+ return match;
50760+ else
50761+ return NULL;
50762+}
50763+
50764+static struct acl_object_label *
50765+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
50766+ const struct acl_subject_label *subj)
50767+{
50768+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
50769+ struct acl_object_label *match;
50770+
50771+ match = subj->obj_hash[index];
50772+
50773+ while (match && (match->inode != ino || match->device != dev ||
50774+ (match->mode & GR_DELETED))) {
50775+ match = match->next;
50776+ }
50777+
50778+ if (match && !(match->mode & GR_DELETED))
50779+ return match;
50780+ else
50781+ return NULL;
50782+}
50783+
50784+static struct acl_object_label *
50785+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
50786+ const struct acl_subject_label *subj)
50787+{
50788+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
50789+ struct acl_object_label *match;
50790+
50791+ match = subj->obj_hash[index];
50792+
50793+ while (match && (match->inode != ino || match->device != dev ||
50794+ !(match->mode & GR_DELETED))) {
50795+ match = match->next;
50796+ }
50797+
50798+ if (match && (match->mode & GR_DELETED))
50799+ return match;
50800+
50801+ match = subj->obj_hash[index];
50802+
50803+ while (match && (match->inode != ino || match->device != dev ||
50804+ (match->mode & GR_DELETED))) {
50805+ match = match->next;
50806+ }
50807+
50808+ if (match && !(match->mode & GR_DELETED))
50809+ return match;
50810+ else
50811+ return NULL;
50812+}
50813+
50814+static struct name_entry *
50815+lookup_name_entry(const char *name)
50816+{
50817+ unsigned int len = strlen(name);
50818+ unsigned int key = full_name_hash(name, len);
50819+ unsigned int index = key % name_set.n_size;
50820+ struct name_entry *match;
50821+
50822+ match = name_set.n_hash[index];
50823+
50824+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
50825+ match = match->next;
50826+
50827+ return match;
50828+}
50829+
50830+static struct name_entry *
50831+lookup_name_entry_create(const char *name)
50832+{
50833+ unsigned int len = strlen(name);
50834+ unsigned int key = full_name_hash(name, len);
50835+ unsigned int index = key % name_set.n_size;
50836+ struct name_entry *match;
50837+
50838+ match = name_set.n_hash[index];
50839+
50840+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
50841+ !match->deleted))
50842+ match = match->next;
50843+
50844+ if (match && match->deleted)
50845+ return match;
50846+
50847+ match = name_set.n_hash[index];
50848+
50849+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
50850+ match->deleted))
50851+ match = match->next;
50852+
50853+ if (match && !match->deleted)
50854+ return match;
50855+ else
50856+ return NULL;
50857+}
50858+
50859+static struct inodev_entry *
50860+lookup_inodev_entry(const ino_t ino, const dev_t dev)
50861+{
50862+ unsigned int index = fhash(ino, dev, inodev_set.i_size);
50863+ struct inodev_entry *match;
50864+
50865+ match = inodev_set.i_hash[index];
50866+
50867+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
50868+ match = match->next;
50869+
50870+ return match;
50871+}
50872+
50873+static void
50874+insert_inodev_entry(struct inodev_entry *entry)
50875+{
50876+ unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
50877+ inodev_set.i_size);
50878+ struct inodev_entry **curr;
50879+
50880+ entry->prev = NULL;
50881+
50882+ curr = &inodev_set.i_hash[index];
50883+ if (*curr != NULL)
50884+ (*curr)->prev = entry;
50885+
50886+ entry->next = *curr;
50887+ *curr = entry;
50888+
50889+ return;
50890+}
50891+
50892+static void
50893+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
50894+{
50895+ unsigned int index =
50896+ rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
50897+ struct acl_role_label **curr;
50898+ struct acl_role_label *tmp, *tmp2;
50899+
50900+ curr = &acl_role_set.r_hash[index];
50901+
50902+ /* simple case, slot is empty, just set it to our role */
50903+ if (*curr == NULL) {
50904+ *curr = role;
50905+ } else {
50906+ /* example:
50907+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
50908+ 2 -> 3
50909+ */
50910+ /* first check to see if we can already be reached via this slot */
50911+ tmp = *curr;
50912+ while (tmp && tmp != role)
50913+ tmp = tmp->next;
50914+ if (tmp == role) {
50915+ /* we don't need to add ourselves to this slot's chain */
50916+ return;
50917+ }
50918+ /* we need to add ourselves to this chain, two cases */
50919+ if (role->next == NULL) {
50920+ /* simple case, append the current chain to our role */
50921+ role->next = *curr;
50922+ *curr = role;
50923+ } else {
50924+ /* 1 -> 2 -> 3 -> 4
50925+ 2 -> 3 -> 4
50926+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
50927+ */
50928+ /* trickier case: walk our role's chain until we find
50929+ the role for the start of the current slot's chain */
50930+ tmp = role;
50931+ tmp2 = *curr;
50932+ while (tmp->next && tmp->next != tmp2)
50933+ tmp = tmp->next;
50934+ if (tmp->next == tmp2) {
50935+ /* from example above, we found 3, so just
50936+ replace this slot's chain with ours */
50937+ *curr = role;
50938+ } else {
50939+ /* we didn't find a subset of our role's chain
50940+ in the current slot's chain, so append their
50941+ chain to ours, and set us as the first role in
50942+ the slot's chain
50943+
50944+ we could fold this case with the case above,
50945+ but making it explicit for clarity
50946+ */
50947+ tmp->next = tmp2;
50948+ *curr = role;
50949+ }
50950+ }
50951+ }
50952+
50953+ return;
50954+}
50955+
50956+static void
50957+insert_acl_role_label(struct acl_role_label *role)
50958+{
50959+ int i;
50960+
50961+ if (role_list == NULL) {
50962+ role_list = role;
50963+ role->prev = NULL;
50964+ } else {
50965+ role->prev = role_list;
50966+ role_list = role;
50967+ }
50968+
50969+ /* used for hash chains */
50970+ role->next = NULL;
50971+
50972+ if (role->roletype & GR_ROLE_DOMAIN) {
50973+ for (i = 0; i < role->domain_child_num; i++)
50974+ __insert_acl_role_label(role, role->domain_children[i]);
50975+ } else
50976+ __insert_acl_role_label(role, role->uidgid);
50977+}
50978+
50979+static int
50980+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
50981+{
50982+ struct name_entry **curr, *nentry;
50983+ struct inodev_entry *ientry;
50984+ unsigned int len = strlen(name);
50985+ unsigned int key = full_name_hash(name, len);
50986+ unsigned int index = key % name_set.n_size;
50987+
50988+ curr = &name_set.n_hash[index];
50989+
50990+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
50991+ curr = &((*curr)->next);
50992+
50993+ if (*curr != NULL)
50994+ return 1;
50995+
50996+ nentry = acl_alloc(sizeof (struct name_entry));
50997+ if (nentry == NULL)
50998+ return 0;
50999+ ientry = acl_alloc(sizeof (struct inodev_entry));
51000+ if (ientry == NULL)
51001+ return 0;
51002+ ientry->nentry = nentry;
51003+
51004+ nentry->key = key;
51005+ nentry->name = name;
51006+ nentry->inode = inode;
51007+ nentry->device = device;
51008+ nentry->len = len;
51009+ nentry->deleted = deleted;
51010+
51011+ nentry->prev = NULL;
51012+ curr = &name_set.n_hash[index];
51013+ if (*curr != NULL)
51014+ (*curr)->prev = nentry;
51015+ nentry->next = *curr;
51016+ *curr = nentry;
51017+
51018+ /* insert us into the table searchable by inode/dev */
51019+ insert_inodev_entry(ientry);
51020+
51021+ return 1;
51022+}
51023+
51024+static void
51025+insert_acl_obj_label(struct acl_object_label *obj,
51026+ struct acl_subject_label *subj)
51027+{
51028+ unsigned int index =
51029+ fhash(obj->inode, obj->device, subj->obj_hash_size);
51030+ struct acl_object_label **curr;
51031+
51032+
51033+ obj->prev = NULL;
51034+
51035+ curr = &subj->obj_hash[index];
51036+ if (*curr != NULL)
51037+ (*curr)->prev = obj;
51038+
51039+ obj->next = *curr;
51040+ *curr = obj;
51041+
51042+ return;
51043+}
51044+
51045+static void
51046+insert_acl_subj_label(struct acl_subject_label *obj,
51047+ struct acl_role_label *role)
51048+{
51049+ unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
51050+ struct acl_subject_label **curr;
51051+
51052+ obj->prev = NULL;
51053+
51054+ curr = &role->subj_hash[index];
51055+ if (*curr != NULL)
51056+ (*curr)->prev = obj;
51057+
51058+ obj->next = *curr;
51059+ *curr = obj;
51060+
51061+ return;
51062+}
51063+
51064+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
51065+
51066+static void *
51067+create_table(__u32 * len, int elementsize)
51068+{
51069+ unsigned int table_sizes[] = {
51070+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
51071+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
51072+ 4194301, 8388593, 16777213, 33554393, 67108859
51073+ };
51074+ void *newtable = NULL;
51075+ unsigned int pwr = 0;
51076+
51077+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
51078+ table_sizes[pwr] <= *len)
51079+ pwr++;
51080+
51081+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
51082+ return newtable;
51083+
51084+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
51085+ newtable =
51086+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
51087+ else
51088+ newtable = vmalloc(table_sizes[pwr] * elementsize);
51089+
51090+ *len = table_sizes[pwr];
51091+
51092+ return newtable;
51093+}
51094+
51095+static int
51096+init_variables(const struct gr_arg *arg)
51097+{
51098+ struct task_struct *reaper = init_pid_ns.child_reaper;
51099+ unsigned int stacksize;
51100+
51101+ subj_map_set.s_size = arg->role_db.num_subjects;
51102+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
51103+ name_set.n_size = arg->role_db.num_objects;
51104+ inodev_set.i_size = arg->role_db.num_objects;
51105+
51106+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
51107+ !name_set.n_size || !inodev_set.i_size)
51108+ return 1;
51109+
51110+ if (!gr_init_uidset())
51111+ return 1;
51112+
51113+ /* set up the stack that holds allocation info */
51114+
51115+ stacksize = arg->role_db.num_pointers + 5;
51116+
51117+ if (!acl_alloc_stack_init(stacksize))
51118+ return 1;
51119+
51120+ /* grab reference for the real root dentry and vfsmount */
51121+ get_fs_root(reaper->fs, &real_root);
51122+
51123+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51124+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
51125+#endif
51126+
51127+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
51128+ if (fakefs_obj_rw == NULL)
51129+ return 1;
51130+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
51131+
51132+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
51133+ if (fakefs_obj_rwx == NULL)
51134+ return 1;
51135+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
51136+
51137+ subj_map_set.s_hash =
51138+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
51139+ acl_role_set.r_hash =
51140+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
51141+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
51142+ inodev_set.i_hash =
51143+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
51144+
51145+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
51146+ !name_set.n_hash || !inodev_set.i_hash)
51147+ return 1;
51148+
51149+ memset(subj_map_set.s_hash, 0,
51150+ sizeof(struct subject_map *) * subj_map_set.s_size);
51151+ memset(acl_role_set.r_hash, 0,
51152+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
51153+ memset(name_set.n_hash, 0,
51154+ sizeof (struct name_entry *) * name_set.n_size);
51155+ memset(inodev_set.i_hash, 0,
51156+ sizeof (struct inodev_entry *) * inodev_set.i_size);
51157+
51158+ return 0;
51159+}
51160+
51161+/* free information not needed after startup
51162+ currently contains user->kernel pointer mappings for subjects
51163+*/
51164+
51165+static void
51166+free_init_variables(void)
51167+{
51168+ __u32 i;
51169+
51170+ if (subj_map_set.s_hash) {
51171+ for (i = 0; i < subj_map_set.s_size; i++) {
51172+ if (subj_map_set.s_hash[i]) {
51173+ kfree(subj_map_set.s_hash[i]);
51174+ subj_map_set.s_hash[i] = NULL;
51175+ }
51176+ }
51177+
51178+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
51179+ PAGE_SIZE)
51180+ kfree(subj_map_set.s_hash);
51181+ else
51182+ vfree(subj_map_set.s_hash);
51183+ }
51184+
51185+ return;
51186+}
51187+
51188+static void
51189+free_variables(void)
51190+{
51191+ struct acl_subject_label *s;
51192+ struct acl_role_label *r;
51193+ struct task_struct *task, *task2;
51194+ unsigned int x;
51195+
51196+ gr_clear_learn_entries();
51197+
51198+ read_lock(&tasklist_lock);
51199+ do_each_thread(task2, task) {
51200+ task->acl_sp_role = 0;
51201+ task->acl_role_id = 0;
51202+ task->acl = NULL;
51203+ task->role = NULL;
51204+ } while_each_thread(task2, task);
51205+ read_unlock(&tasklist_lock);
51206+
51207+ /* release the reference to the real root dentry and vfsmount */
51208+ path_put(&real_root);
51209+ memset(&real_root, 0, sizeof(real_root));
51210+
51211+ /* free all object hash tables */
51212+
51213+ FOR_EACH_ROLE_START(r)
51214+ if (r->subj_hash == NULL)
51215+ goto next_role;
51216+ FOR_EACH_SUBJECT_START(r, s, x)
51217+ if (s->obj_hash == NULL)
51218+ break;
51219+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51220+ kfree(s->obj_hash);
51221+ else
51222+ vfree(s->obj_hash);
51223+ FOR_EACH_SUBJECT_END(s, x)
51224+ FOR_EACH_NESTED_SUBJECT_START(r, s)
51225+ if (s->obj_hash == NULL)
51226+ break;
51227+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51228+ kfree(s->obj_hash);
51229+ else
51230+ vfree(s->obj_hash);
51231+ FOR_EACH_NESTED_SUBJECT_END(s)
51232+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
51233+ kfree(r->subj_hash);
51234+ else
51235+ vfree(r->subj_hash);
51236+ r->subj_hash = NULL;
51237+next_role:
51238+ FOR_EACH_ROLE_END(r)
51239+
51240+ acl_free_all();
51241+
51242+ if (acl_role_set.r_hash) {
51243+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
51244+ PAGE_SIZE)
51245+ kfree(acl_role_set.r_hash);
51246+ else
51247+ vfree(acl_role_set.r_hash);
51248+ }
51249+ if (name_set.n_hash) {
51250+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
51251+ PAGE_SIZE)
51252+ kfree(name_set.n_hash);
51253+ else
51254+ vfree(name_set.n_hash);
51255+ }
51256+
51257+ if (inodev_set.i_hash) {
51258+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
51259+ PAGE_SIZE)
51260+ kfree(inodev_set.i_hash);
51261+ else
51262+ vfree(inodev_set.i_hash);
51263+ }
51264+
51265+ gr_free_uidset();
51266+
51267+ memset(&name_set, 0, sizeof (struct name_db));
51268+ memset(&inodev_set, 0, sizeof (struct inodev_db));
51269+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
51270+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
51271+
51272+ default_role = NULL;
51273+ kernel_role = NULL;
51274+ role_list = NULL;
51275+
51276+ return;
51277+}
51278+
51279+static __u32
51280+count_user_objs(struct acl_object_label *userp)
51281+{
51282+ struct acl_object_label o_tmp;
51283+ __u32 num = 0;
51284+
51285+ while (userp) {
51286+ if (copy_from_user(&o_tmp, userp,
51287+ sizeof (struct acl_object_label)))
51288+ break;
51289+
51290+ userp = o_tmp.prev;
51291+ num++;
51292+ }
51293+
51294+ return num;
51295+}
51296+
51297+static struct acl_subject_label *
51298+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
51299+
51300+static int
51301+copy_user_glob(struct acl_object_label *obj)
51302+{
51303+ struct acl_object_label *g_tmp, **guser;
51304+ unsigned int len;
51305+ char *tmp;
51306+
51307+ if (obj->globbed == NULL)
51308+ return 0;
51309+
51310+ guser = &obj->globbed;
51311+ while (*guser) {
51312+ g_tmp = (struct acl_object_label *)
51313+ acl_alloc(sizeof (struct acl_object_label));
51314+ if (g_tmp == NULL)
51315+ return -ENOMEM;
51316+
51317+ if (copy_from_user(g_tmp, *guser,
51318+ sizeof (struct acl_object_label)))
51319+ return -EFAULT;
51320+
51321+ len = strnlen_user(g_tmp->filename, PATH_MAX);
51322+
51323+ if (!len || len >= PATH_MAX)
51324+ return -EINVAL;
51325+
51326+ if ((tmp = (char *) acl_alloc(len)) == NULL)
51327+ return -ENOMEM;
51328+
51329+ if (copy_from_user(tmp, g_tmp->filename, len))
51330+ return -EFAULT;
51331+ tmp[len-1] = '\0';
51332+ g_tmp->filename = tmp;
51333+
51334+ *guser = g_tmp;
51335+ guser = &(g_tmp->next);
51336+ }
51337+
51338+ return 0;
51339+}
51340+
51341+static int
51342+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
51343+ struct acl_role_label *role)
51344+{
51345+ struct acl_object_label *o_tmp;
51346+ unsigned int len;
51347+ int ret;
51348+ char *tmp;
51349+
51350+ while (userp) {
51351+ if ((o_tmp = (struct acl_object_label *)
51352+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
51353+ return -ENOMEM;
51354+
51355+ if (copy_from_user(o_tmp, userp,
51356+ sizeof (struct acl_object_label)))
51357+ return -EFAULT;
51358+
51359+ userp = o_tmp->prev;
51360+
51361+ len = strnlen_user(o_tmp->filename, PATH_MAX);
51362+
51363+ if (!len || len >= PATH_MAX)
51364+ return -EINVAL;
51365+
51366+ if ((tmp = (char *) acl_alloc(len)) == NULL)
51367+ return -ENOMEM;
51368+
51369+ if (copy_from_user(tmp, o_tmp->filename, len))
51370+ return -EFAULT;
51371+ tmp[len-1] = '\0';
51372+ o_tmp->filename = tmp;
51373+
51374+ insert_acl_obj_label(o_tmp, subj);
51375+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
51376+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
51377+ return -ENOMEM;
51378+
51379+ ret = copy_user_glob(o_tmp);
51380+ if (ret)
51381+ return ret;
51382+
51383+ if (o_tmp->nested) {
51384+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
51385+ if (IS_ERR(o_tmp->nested))
51386+ return PTR_ERR(o_tmp->nested);
51387+
51388+ /* insert into nested subject list */
51389+ o_tmp->nested->next = role->hash->first;
51390+ role->hash->first = o_tmp->nested;
51391+ }
51392+ }
51393+
51394+ return 0;
51395+}
51396+
51397+static __u32
51398+count_user_subjs(struct acl_subject_label *userp)
51399+{
51400+ struct acl_subject_label s_tmp;
51401+ __u32 num = 0;
51402+
51403+ while (userp) {
51404+ if (copy_from_user(&s_tmp, userp,
51405+ sizeof (struct acl_subject_label)))
51406+ break;
51407+
51408+ userp = s_tmp.prev;
51409+ /* do not count nested subjects against this count, since
51410+ they are not included in the hash table, but are
51411+ attached to objects. We have already counted
51412+ the subjects in userspace for the allocation
51413+ stack
51414+ */
51415+ if (!(s_tmp.mode & GR_NESTED))
51416+ num++;
51417+ }
51418+
51419+ return num;
51420+}
51421+
51422+static int
51423+copy_user_allowedips(struct acl_role_label *rolep)
51424+{
51425+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
51426+
51427+ ruserip = rolep->allowed_ips;
51428+
51429+ while (ruserip) {
51430+ rlast = rtmp;
51431+
51432+ if ((rtmp = (struct role_allowed_ip *)
51433+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
51434+ return -ENOMEM;
51435+
51436+ if (copy_from_user(rtmp, ruserip,
51437+ sizeof (struct role_allowed_ip)))
51438+ return -EFAULT;
51439+
51440+ ruserip = rtmp->prev;
51441+
51442+ if (!rlast) {
51443+ rtmp->prev = NULL;
51444+ rolep->allowed_ips = rtmp;
51445+ } else {
51446+ rlast->next = rtmp;
51447+ rtmp->prev = rlast;
51448+ }
51449+
51450+ if (!ruserip)
51451+ rtmp->next = NULL;
51452+ }
51453+
51454+ return 0;
51455+}
51456+
51457+static int
51458+copy_user_transitions(struct acl_role_label *rolep)
51459+{
51460+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
51461+
51462+ unsigned int len;
51463+ char *tmp;
51464+
51465+ rusertp = rolep->transitions;
51466+
51467+ while (rusertp) {
51468+ rlast = rtmp;
51469+
51470+ if ((rtmp = (struct role_transition *)
51471+ acl_alloc(sizeof (struct role_transition))) == NULL)
51472+ return -ENOMEM;
51473+
51474+ if (copy_from_user(rtmp, rusertp,
51475+ sizeof (struct role_transition)))
51476+ return -EFAULT;
51477+
51478+ rusertp = rtmp->prev;
51479+
51480+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
51481+
51482+ if (!len || len >= GR_SPROLE_LEN)
51483+ return -EINVAL;
51484+
51485+ if ((tmp = (char *) acl_alloc(len)) == NULL)
51486+ return -ENOMEM;
51487+
51488+ if (copy_from_user(tmp, rtmp->rolename, len))
51489+ return -EFAULT;
51490+ tmp[len-1] = '\0';
51491+ rtmp->rolename = tmp;
51492+
51493+ if (!rlast) {
51494+ rtmp->prev = NULL;
51495+ rolep->transitions = rtmp;
51496+ } else {
51497+ rlast->next = rtmp;
51498+ rtmp->prev = rlast;
51499+ }
51500+
51501+ if (!rusertp)
51502+ rtmp->next = NULL;
51503+ }
51504+
51505+ return 0;
51506+}
51507+
51508+static struct acl_subject_label *
51509+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
51510+{
51511+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
51512+ unsigned int len;
51513+ char *tmp;
51514+ __u32 num_objs;
51515+ struct acl_ip_label **i_tmp, *i_utmp2;
51516+ struct gr_hash_struct ghash;
51517+ struct subject_map *subjmap;
51518+ unsigned int i_num;
51519+ int err;
51520+
51521+ s_tmp = lookup_subject_map(userp);
51522+
51523+ /* we've already copied this subject into the kernel, just return
51524+ the reference to it, and don't copy it over again
51525+ */
51526+ if (s_tmp)
51527+ return(s_tmp);
51528+
51529+ if ((s_tmp = (struct acl_subject_label *)
51530+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
51531+ return ERR_PTR(-ENOMEM);
51532+
51533+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
51534+ if (subjmap == NULL)
51535+ return ERR_PTR(-ENOMEM);
51536+
51537+ subjmap->user = userp;
51538+ subjmap->kernel = s_tmp;
51539+ insert_subj_map_entry(subjmap);
51540+
51541+ if (copy_from_user(s_tmp, userp,
51542+ sizeof (struct acl_subject_label)))
51543+ return ERR_PTR(-EFAULT);
51544+
51545+ len = strnlen_user(s_tmp->filename, PATH_MAX);
51546+
51547+ if (!len || len >= PATH_MAX)
51548+ return ERR_PTR(-EINVAL);
51549+
51550+ if ((tmp = (char *) acl_alloc(len)) == NULL)
51551+ return ERR_PTR(-ENOMEM);
51552+
51553+ if (copy_from_user(tmp, s_tmp->filename, len))
51554+ return ERR_PTR(-EFAULT);
51555+ tmp[len-1] = '\0';
51556+ s_tmp->filename = tmp;
51557+
51558+ if (!strcmp(s_tmp->filename, "/"))
51559+ role->root_label = s_tmp;
51560+
51561+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
51562+ return ERR_PTR(-EFAULT);
51563+
51564+ /* copy user and group transition tables */
51565+
51566+ if (s_tmp->user_trans_num) {
51567+ uid_t *uidlist;
51568+
51569+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
51570+ if (uidlist == NULL)
51571+ return ERR_PTR(-ENOMEM);
51572+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
51573+ return ERR_PTR(-EFAULT);
51574+
51575+ s_tmp->user_transitions = uidlist;
51576+ }
51577+
51578+ if (s_tmp->group_trans_num) {
51579+ gid_t *gidlist;
51580+
51581+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
51582+ if (gidlist == NULL)
51583+ return ERR_PTR(-ENOMEM);
51584+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
51585+ return ERR_PTR(-EFAULT);
51586+
51587+ s_tmp->group_transitions = gidlist;
51588+ }
51589+
51590+ /* set up object hash table */
51591+ num_objs = count_user_objs(ghash.first);
51592+
51593+ s_tmp->obj_hash_size = num_objs;
51594+ s_tmp->obj_hash =
51595+ (struct acl_object_label **)
51596+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
51597+
51598+ if (!s_tmp->obj_hash)
51599+ return ERR_PTR(-ENOMEM);
51600+
51601+ memset(s_tmp->obj_hash, 0,
51602+ s_tmp->obj_hash_size *
51603+ sizeof (struct acl_object_label *));
51604+
51605+ /* add in objects */
51606+ err = copy_user_objs(ghash.first, s_tmp, role);
51607+
51608+ if (err)
51609+ return ERR_PTR(err);
51610+
51611+ /* set pointer for parent subject */
51612+ if (s_tmp->parent_subject) {
51613+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
51614+
51615+ if (IS_ERR(s_tmp2))
51616+ return s_tmp2;
51617+
51618+ s_tmp->parent_subject = s_tmp2;
51619+ }
51620+
51621+ /* add in ip acls */
51622+
51623+ if (!s_tmp->ip_num) {
51624+ s_tmp->ips = NULL;
51625+ goto insert;
51626+ }
51627+
51628+ i_tmp =
51629+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
51630+ sizeof (struct acl_ip_label *));
51631+
51632+ if (!i_tmp)
51633+ return ERR_PTR(-ENOMEM);
51634+
51635+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
51636+ *(i_tmp + i_num) =
51637+ (struct acl_ip_label *)
51638+ acl_alloc(sizeof (struct acl_ip_label));
51639+ if (!*(i_tmp + i_num))
51640+ return ERR_PTR(-ENOMEM);
51641+
51642+ if (copy_from_user
51643+ (&i_utmp2, s_tmp->ips + i_num,
51644+ sizeof (struct acl_ip_label *)))
51645+ return ERR_PTR(-EFAULT);
51646+
51647+ if (copy_from_user
51648+ (*(i_tmp + i_num), i_utmp2,
51649+ sizeof (struct acl_ip_label)))
51650+ return ERR_PTR(-EFAULT);
51651+
51652+ if ((*(i_tmp + i_num))->iface == NULL)
51653+ continue;
51654+
51655+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
51656+ if (!len || len >= IFNAMSIZ)
51657+ return ERR_PTR(-EINVAL);
51658+ tmp = acl_alloc(len);
51659+ if (tmp == NULL)
51660+ return ERR_PTR(-ENOMEM);
51661+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
51662+ return ERR_PTR(-EFAULT);
51663+ (*(i_tmp + i_num))->iface = tmp;
51664+ }
51665+
51666+ s_tmp->ips = i_tmp;
51667+
51668+insert:
51669+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
51670+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
51671+ return ERR_PTR(-ENOMEM);
51672+
51673+ return s_tmp;
51674+}
51675+
51676+static int
51677+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
51678+{
51679+ struct acl_subject_label s_pre;
51680+ struct acl_subject_label * ret;
51681+ int err;
51682+
51683+ while (userp) {
51684+ if (copy_from_user(&s_pre, userp,
51685+ sizeof (struct acl_subject_label)))
51686+ return -EFAULT;
51687+
51688+ /* do not add nested subjects here, add
51689+ while parsing objects
51690+ */
51691+
51692+ if (s_pre.mode & GR_NESTED) {
51693+ userp = s_pre.prev;
51694+ continue;
51695+ }
51696+
51697+ ret = do_copy_user_subj(userp, role);
51698+
51699+ err = PTR_ERR(ret);
51700+ if (IS_ERR(ret))
51701+ return err;
51702+
51703+ insert_acl_subj_label(ret, role);
51704+
51705+ userp = s_pre.prev;
51706+ }
51707+
51708+ return 0;
51709+}
51710+
51711+static int
51712+copy_user_acl(struct gr_arg *arg)
51713+{
51714+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
51715+ struct sprole_pw *sptmp;
51716+ struct gr_hash_struct *ghash;
51717+ uid_t *domainlist;
51718+ unsigned int r_num;
51719+ unsigned int len;
51720+ char *tmp;
51721+ int err = 0;
51722+ __u16 i;
51723+ __u32 num_subjs;
51724+
51725+ /* we need a default and kernel role */
51726+ if (arg->role_db.num_roles < 2)
51727+ return -EINVAL;
51728+
51729+ /* copy special role authentication info from userspace */
51730+
51731+ num_sprole_pws = arg->num_sprole_pws;
51732+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
51733+
51734+ if (!acl_special_roles && num_sprole_pws)
51735+ return -ENOMEM;
51736+
51737+ for (i = 0; i < num_sprole_pws; i++) {
51738+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
51739+ if (!sptmp)
51740+ return -ENOMEM;
51741+ if (copy_from_user(sptmp, arg->sprole_pws + i,
51742+ sizeof (struct sprole_pw)))
51743+ return -EFAULT;
51744+
51745+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
51746+
51747+ if (!len || len >= GR_SPROLE_LEN)
51748+ return -EINVAL;
51749+
51750+ if ((tmp = (char *) acl_alloc(len)) == NULL)
51751+ return -ENOMEM;
51752+
51753+ if (copy_from_user(tmp, sptmp->rolename, len))
51754+ return -EFAULT;
51755+
51756+ tmp[len-1] = '\0';
51757+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51758+ printk(KERN_ALERT "Copying special role %s\n", tmp);
51759+#endif
51760+ sptmp->rolename = tmp;
51761+ acl_special_roles[i] = sptmp;
51762+ }
51763+
51764+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
51765+
51766+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
51767+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
51768+
51769+ if (!r_tmp)
51770+ return -ENOMEM;
51771+
51772+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
51773+ sizeof (struct acl_role_label *)))
51774+ return -EFAULT;
51775+
51776+ if (copy_from_user(r_tmp, r_utmp2,
51777+ sizeof (struct acl_role_label)))
51778+ return -EFAULT;
51779+
51780+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
51781+
51782+ if (!len || len >= PATH_MAX)
51783+ return -EINVAL;
51784+
51785+ if ((tmp = (char *) acl_alloc(len)) == NULL)
51786+ return -ENOMEM;
51787+
51788+ if (copy_from_user(tmp, r_tmp->rolename, len))
51789+ return -EFAULT;
51790+
51791+ tmp[len-1] = '\0';
51792+ r_tmp->rolename = tmp;
51793+
51794+ if (!strcmp(r_tmp->rolename, "default")
51795+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
51796+ default_role = r_tmp;
51797+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
51798+ kernel_role = r_tmp;
51799+ }
51800+
51801+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
51802+ return -ENOMEM;
51803+
51804+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
51805+ return -EFAULT;
51806+
51807+ r_tmp->hash = ghash;
51808+
51809+ num_subjs = count_user_subjs(r_tmp->hash->first);
51810+
51811+ r_tmp->subj_hash_size = num_subjs;
51812+ r_tmp->subj_hash =
51813+ (struct acl_subject_label **)
51814+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
51815+
51816+ if (!r_tmp->subj_hash)
51817+ return -ENOMEM;
51818+
51819+ err = copy_user_allowedips(r_tmp);
51820+ if (err)
51821+ return err;
51822+
51823+ /* copy domain info */
51824+ if (r_tmp->domain_children != NULL) {
51825+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
51826+ if (domainlist == NULL)
51827+ return -ENOMEM;
51828+
51829+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
51830+ return -EFAULT;
51831+
51832+ r_tmp->domain_children = domainlist;
51833+ }
51834+
51835+ err = copy_user_transitions(r_tmp);
51836+ if (err)
51837+ return err;
51838+
51839+ memset(r_tmp->subj_hash, 0,
51840+ r_tmp->subj_hash_size *
51841+ sizeof (struct acl_subject_label *));
51842+
51843+ err = copy_user_subjs(r_tmp->hash->first, r_tmp);
51844+
51845+ if (err)
51846+ return err;
51847+
51848+ /* set nested subject list to null */
51849+ r_tmp->hash->first = NULL;
51850+
51851+ insert_acl_role_label(r_tmp);
51852+ }
51853+
51854+ if (default_role == NULL || kernel_role == NULL)
51855+ return -EINVAL;
51856+
51857+ return err;
51858+}
51859+
51860+static int
51861+gracl_init(struct gr_arg *args)
51862+{
51863+ int error = 0;
51864+
51865+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
51866+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
51867+
51868+ if (init_variables(args)) {
51869+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
51870+ error = -ENOMEM;
51871+ free_variables();
51872+ goto out;
51873+ }
51874+
51875+ error = copy_user_acl(args);
51876+ free_init_variables();
51877+ if (error) {
51878+ free_variables();
51879+ goto out;
51880+ }
51881+
51882+ if ((error = gr_set_acls(0))) {
51883+ free_variables();
51884+ goto out;
51885+ }
51886+
51887+ pax_open_kernel();
51888+ gr_status |= GR_READY;
51889+ pax_close_kernel();
51890+
51891+ out:
51892+ return error;
51893+}
51894+
51895+/* derived from glibc fnmatch() 0: match, 1: no match*/
51896+
51897+static int
51898+glob_match(const char *p, const char *n)
51899+{
51900+ char c;
51901+
51902+ while ((c = *p++) != '\0') {
51903+ switch (c) {
51904+ case '?':
51905+ if (*n == '\0')
51906+ return 1;
51907+ else if (*n == '/')
51908+ return 1;
51909+ break;
51910+ case '\\':
51911+ if (*n != c)
51912+ return 1;
51913+ break;
51914+ case '*':
51915+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
51916+ if (*n == '/')
51917+ return 1;
51918+ else if (c == '?') {
51919+ if (*n == '\0')
51920+ return 1;
51921+ else
51922+ ++n;
51923+ }
51924+ }
51925+ if (c == '\0') {
51926+ return 0;
51927+ } else {
51928+ const char *endp;
51929+
51930+ if ((endp = strchr(n, '/')) == NULL)
51931+ endp = n + strlen(n);
51932+
51933+ if (c == '[') {
51934+ for (--p; n < endp; ++n)
51935+ if (!glob_match(p, n))
51936+ return 0;
51937+ } else if (c == '/') {
51938+ while (*n != '\0' && *n != '/')
51939+ ++n;
51940+ if (*n == '/' && !glob_match(p, n + 1))
51941+ return 0;
51942+ } else {
51943+ for (--p; n < endp; ++n)
51944+ if (*n == c && !glob_match(p, n))
51945+ return 0;
51946+ }
51947+
51948+ return 1;
51949+ }
51950+ case '[':
51951+ {
51952+ int not;
51953+ char cold;
51954+
51955+ if (*n == '\0' || *n == '/')
51956+ return 1;
51957+
51958+ not = (*p == '!' || *p == '^');
51959+ if (not)
51960+ ++p;
51961+
51962+ c = *p++;
51963+ for (;;) {
51964+ unsigned char fn = (unsigned char)*n;
51965+
51966+ if (c == '\0')
51967+ return 1;
51968+ else {
51969+ if (c == fn)
51970+ goto matched;
51971+ cold = c;
51972+ c = *p++;
51973+
51974+ if (c == '-' && *p != ']') {
51975+ unsigned char cend = *p++;
51976+
51977+ if (cend == '\0')
51978+ return 1;
51979+
51980+ if (cold <= fn && fn <= cend)
51981+ goto matched;
51982+
51983+ c = *p++;
51984+ }
51985+ }
51986+
51987+ if (c == ']')
51988+ break;
51989+ }
51990+ if (!not)
51991+ return 1;
51992+ break;
51993+ matched:
51994+ while (c != ']') {
51995+ if (c == '\0')
51996+ return 1;
51997+
51998+ c = *p++;
51999+ }
52000+ if (not)
52001+ return 1;
52002+ }
52003+ break;
52004+ default:
52005+ if (c != *n)
52006+ return 1;
52007+ }
52008+
52009+ ++n;
52010+ }
52011+
52012+ if (*n == '\0')
52013+ return 0;
52014+
52015+ if (*n == '/')
52016+ return 0;
52017+
52018+ return 1;
52019+}
52020+
52021+static struct acl_object_label *
52022+chk_glob_label(struct acl_object_label *globbed,
52023+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
52024+{
52025+ struct acl_object_label *tmp;
52026+
52027+ if (*path == NULL)
52028+ *path = gr_to_filename_nolock(dentry, mnt);
52029+
52030+ tmp = globbed;
52031+
52032+ while (tmp) {
52033+ if (!glob_match(tmp->filename, *path))
52034+ return tmp;
52035+ tmp = tmp->next;
52036+ }
52037+
52038+ return NULL;
52039+}
52040+
52041+static struct acl_object_label *
52042+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52043+ const ino_t curr_ino, const dev_t curr_dev,
52044+ const struct acl_subject_label *subj, char **path, const int checkglob)
52045+{
52046+ struct acl_subject_label *tmpsubj;
52047+ struct acl_object_label *retval;
52048+ struct acl_object_label *retval2;
52049+
52050+ tmpsubj = (struct acl_subject_label *) subj;
52051+ read_lock(&gr_inode_lock);
52052+ do {
52053+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
52054+ if (retval) {
52055+ if (checkglob && retval->globbed) {
52056+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
52057+ if (retval2)
52058+ retval = retval2;
52059+ }
52060+ break;
52061+ }
52062+ } while ((tmpsubj = tmpsubj->parent_subject));
52063+ read_unlock(&gr_inode_lock);
52064+
52065+ return retval;
52066+}
52067+
52068+static __inline__ struct acl_object_label *
52069+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52070+ struct dentry *curr_dentry,
52071+ const struct acl_subject_label *subj, char **path, const int checkglob)
52072+{
52073+ int newglob = checkglob;
52074+ ino_t inode;
52075+ dev_t device;
52076+
52077+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
52078+ as we don't want a / * rule to match instead of the / object
52079+ don't do this for create lookups that call this function though, since they're looking up
52080+ on the parent and thus need globbing checks on all paths
52081+ */
52082+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
52083+ newglob = GR_NO_GLOB;
52084+
52085+ spin_lock(&curr_dentry->d_lock);
52086+ inode = curr_dentry->d_inode->i_ino;
52087+ device = __get_dev(curr_dentry);
52088+ spin_unlock(&curr_dentry->d_lock);
52089+
52090+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
52091+}
52092+
52093+static struct acl_object_label *
52094+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52095+ const struct acl_subject_label *subj, char *path, const int checkglob)
52096+{
52097+ struct dentry *dentry = (struct dentry *) l_dentry;
52098+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52099+ struct mount *real_mnt = real_mount(mnt);
52100+ struct acl_object_label *retval;
52101+ struct dentry *parent;
52102+
52103+ write_seqlock(&rename_lock);
52104+ br_read_lock(vfsmount_lock);
52105+
52106+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
52107+#ifdef CONFIG_NET
52108+ mnt == sock_mnt ||
52109+#endif
52110+#ifdef CONFIG_HUGETLBFS
52111+ (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
52112+#endif
52113+ /* ignore Eric Biederman */
52114+ IS_PRIVATE(l_dentry->d_inode))) {
52115+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
52116+ goto out;
52117+ }
52118+
52119+ for (;;) {
52120+ if (dentry == real_root.dentry && mnt == real_root.mnt)
52121+ break;
52122+
52123+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52124+ if (!mnt_has_parent(real_mnt))
52125+ break;
52126+
52127+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52128+ if (retval != NULL)
52129+ goto out;
52130+
52131+ dentry = real_mnt->mnt_mountpoint;
52132+ real_mnt = real_mnt->mnt_parent;
52133+ mnt = &real_mnt->mnt;
52134+ continue;
52135+ }
52136+
52137+ parent = dentry->d_parent;
52138+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52139+ if (retval != NULL)
52140+ goto out;
52141+
52142+ dentry = parent;
52143+ }
52144+
52145+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52146+
52147+ /* real_root is pinned so we don't have to hold a reference */
52148+ if (retval == NULL)
52149+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
52150+out:
52151+ br_read_unlock(vfsmount_lock);
52152+ write_sequnlock(&rename_lock);
52153+
52154+ BUG_ON(retval == NULL);
52155+
52156+ return retval;
52157+}
52158+
52159+static __inline__ struct acl_object_label *
52160+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52161+ const struct acl_subject_label *subj)
52162+{
52163+ char *path = NULL;
52164+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
52165+}
52166+
52167+static __inline__ struct acl_object_label *
52168+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52169+ const struct acl_subject_label *subj)
52170+{
52171+ char *path = NULL;
52172+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
52173+}
52174+
52175+static __inline__ struct acl_object_label *
52176+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52177+ const struct acl_subject_label *subj, char *path)
52178+{
52179+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
52180+}
52181+
52182+static struct acl_subject_label *
52183+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52184+ const struct acl_role_label *role)
52185+{
52186+ struct dentry *dentry = (struct dentry *) l_dentry;
52187+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52188+ struct mount *real_mnt = real_mount(mnt);
52189+ struct acl_subject_label *retval;
52190+ struct dentry *parent;
52191+
52192+ write_seqlock(&rename_lock);
52193+ br_read_lock(vfsmount_lock);
52194+
52195+ for (;;) {
52196+ if (dentry == real_root.dentry && mnt == real_root.mnt)
52197+ break;
52198+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52199+ if (!mnt_has_parent(real_mnt))
52200+ break;
52201+
52202+ spin_lock(&dentry->d_lock);
52203+ read_lock(&gr_inode_lock);
52204+ retval =
52205+ lookup_acl_subj_label(dentry->d_inode->i_ino,
52206+ __get_dev(dentry), role);
52207+ read_unlock(&gr_inode_lock);
52208+ spin_unlock(&dentry->d_lock);
52209+ if (retval != NULL)
52210+ goto out;
52211+
52212+ dentry = real_mnt->mnt_mountpoint;
52213+ real_mnt = real_mnt->mnt_parent;
52214+ mnt = &real_mnt->mnt;
52215+ continue;
52216+ }
52217+
52218+ spin_lock(&dentry->d_lock);
52219+ read_lock(&gr_inode_lock);
52220+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52221+ __get_dev(dentry), role);
52222+ read_unlock(&gr_inode_lock);
52223+ parent = dentry->d_parent;
52224+ spin_unlock(&dentry->d_lock);
52225+
52226+ if (retval != NULL)
52227+ goto out;
52228+
52229+ dentry = parent;
52230+ }
52231+
52232+ spin_lock(&dentry->d_lock);
52233+ read_lock(&gr_inode_lock);
52234+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52235+ __get_dev(dentry), role);
52236+ read_unlock(&gr_inode_lock);
52237+ spin_unlock(&dentry->d_lock);
52238+
52239+ if (unlikely(retval == NULL)) {
52240+ /* real_root is pinned, we don't need to hold a reference */
52241+ read_lock(&gr_inode_lock);
52242+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
52243+ __get_dev(real_root.dentry), role);
52244+ read_unlock(&gr_inode_lock);
52245+ }
52246+out:
52247+ br_read_unlock(vfsmount_lock);
52248+ write_sequnlock(&rename_lock);
52249+
52250+ BUG_ON(retval == NULL);
52251+
52252+ return retval;
52253+}
52254+
52255+static void
52256+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
52257+{
52258+ struct task_struct *task = current;
52259+ const struct cred *cred = current_cred();
52260+
52261+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
52262+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52263+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52264+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
52265+
52266+ return;
52267+}
52268+
52269+static void
52270+gr_log_learn_id_change(const char type, const unsigned int real,
52271+ const unsigned int effective, const unsigned int fs)
52272+{
52273+ struct task_struct *task = current;
52274+ const struct cred *cred = current_cred();
52275+
52276+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
52277+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52278+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52279+ type, real, effective, fs, &task->signal->saved_ip);
52280+
52281+ return;
52282+}
52283+
52284+__u32
52285+gr_search_file(const struct dentry * dentry, const __u32 mode,
52286+ const struct vfsmount * mnt)
52287+{
52288+ __u32 retval = mode;
52289+ struct acl_subject_label *curracl;
52290+ struct acl_object_label *currobj;
52291+
52292+ if (unlikely(!(gr_status & GR_READY)))
52293+ return (mode & ~GR_AUDITS);
52294+
52295+ curracl = current->acl;
52296+
52297+ currobj = chk_obj_label(dentry, mnt, curracl);
52298+ retval = currobj->mode & mode;
52299+
52300+ /* if we're opening a specified transfer file for writing
52301+ (e.g. /dev/initctl), then transfer our role to init
52302+ */
52303+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
52304+ current->role->roletype & GR_ROLE_PERSIST)) {
52305+ struct task_struct *task = init_pid_ns.child_reaper;
52306+
52307+ if (task->role != current->role) {
52308+ task->acl_sp_role = 0;
52309+ task->acl_role_id = current->acl_role_id;
52310+ task->role = current->role;
52311+ rcu_read_lock();
52312+ read_lock(&grsec_exec_file_lock);
52313+ gr_apply_subject_to_task(task);
52314+ read_unlock(&grsec_exec_file_lock);
52315+ rcu_read_unlock();
52316+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
52317+ }
52318+ }
52319+
52320+ if (unlikely
52321+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
52322+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
52323+ __u32 new_mode = mode;
52324+
52325+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
52326+
52327+ retval = new_mode;
52328+
52329+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
52330+ new_mode |= GR_INHERIT;
52331+
52332+ if (!(mode & GR_NOLEARN))
52333+ gr_log_learn(dentry, mnt, new_mode);
52334+ }
52335+
52336+ return retval;
52337+}
52338+
52339+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
52340+ const struct dentry *parent,
52341+ const struct vfsmount *mnt)
52342+{
52343+ struct name_entry *match;
52344+ struct acl_object_label *matchpo;
52345+ struct acl_subject_label *curracl;
52346+ char *path;
52347+
52348+ if (unlikely(!(gr_status & GR_READY)))
52349+ return NULL;
52350+
52351+ preempt_disable();
52352+ path = gr_to_filename_rbac(new_dentry, mnt);
52353+ match = lookup_name_entry_create(path);
52354+
52355+ curracl = current->acl;
52356+
52357+ if (match) {
52358+ read_lock(&gr_inode_lock);
52359+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
52360+ read_unlock(&gr_inode_lock);
52361+
52362+ if (matchpo) {
52363+ preempt_enable();
52364+ return matchpo;
52365+ }
52366+ }
52367+
52368+ // lookup parent
52369+
52370+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
52371+
52372+ preempt_enable();
52373+ return matchpo;
52374+}
52375+
52376+__u32
52377+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
52378+ const struct vfsmount * mnt, const __u32 mode)
52379+{
52380+ struct acl_object_label *matchpo;
52381+ __u32 retval;
52382+
52383+ if (unlikely(!(gr_status & GR_READY)))
52384+ return (mode & ~GR_AUDITS);
52385+
52386+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
52387+
52388+ retval = matchpo->mode & mode;
52389+
52390+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
52391+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
52392+ __u32 new_mode = mode;
52393+
52394+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
52395+
52396+ gr_log_learn(new_dentry, mnt, new_mode);
52397+ return new_mode;
52398+ }
52399+
52400+ return retval;
52401+}
52402+
52403+__u32
52404+gr_check_link(const struct dentry * new_dentry,
52405+ const struct dentry * parent_dentry,
52406+ const struct vfsmount * parent_mnt,
52407+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
52408+{
52409+ struct acl_object_label *obj;
52410+ __u32 oldmode, newmode;
52411+ __u32 needmode;
52412+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
52413+ GR_DELETE | GR_INHERIT;
52414+
52415+ if (unlikely(!(gr_status & GR_READY)))
52416+ return (GR_CREATE | GR_LINK);
52417+
52418+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
52419+ oldmode = obj->mode;
52420+
52421+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
52422+ newmode = obj->mode;
52423+
52424+ needmode = newmode & checkmodes;
52425+
52426+ // old name for hardlink must have at least the permissions of the new name
52427+ if ((oldmode & needmode) != needmode)
52428+ goto bad;
52429+
52430+ // if old name had restrictions/auditing, make sure the new name does as well
52431+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
52432+
52433+ // don't allow hardlinking of suid/sgid files without permission
52434+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
52435+ needmode |= GR_SETID;
52436+
52437+ if ((newmode & needmode) != needmode)
52438+ goto bad;
52439+
52440+ // enforce minimum permissions
52441+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
52442+ return newmode;
52443+bad:
52444+ needmode = oldmode;
52445+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
52446+ needmode |= GR_SETID;
52447+
52448+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
52449+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
52450+ return (GR_CREATE | GR_LINK);
52451+ } else if (newmode & GR_SUPPRESS)
52452+ return GR_SUPPRESS;
52453+ else
52454+ return 0;
52455+}
52456+
52457+int
52458+gr_check_hidden_task(const struct task_struct *task)
52459+{
52460+ if (unlikely(!(gr_status & GR_READY)))
52461+ return 0;
52462+
52463+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
52464+ return 1;
52465+
52466+ return 0;
52467+}
52468+
52469+int
52470+gr_check_protected_task(const struct task_struct *task)
52471+{
52472+ if (unlikely(!(gr_status & GR_READY) || !task))
52473+ return 0;
52474+
52475+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
52476+ task->acl != current->acl)
52477+ return 1;
52478+
52479+ return 0;
52480+}
52481+
52482+int
52483+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
52484+{
52485+ struct task_struct *p;
52486+ int ret = 0;
52487+
52488+ if (unlikely(!(gr_status & GR_READY) || !pid))
52489+ return ret;
52490+
52491+ read_lock(&tasklist_lock);
52492+ do_each_pid_task(pid, type, p) {
52493+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
52494+ p->acl != current->acl) {
52495+ ret = 1;
52496+ goto out;
52497+ }
52498+ } while_each_pid_task(pid, type, p);
52499+out:
52500+ read_unlock(&tasklist_lock);
52501+
52502+ return ret;
52503+}
52504+
52505+void
52506+gr_copy_label(struct task_struct *tsk)
52507+{
52508+ /* plain copying of fields is already done by dup_task_struct */
52509+ tsk->signal->used_accept = 0;
52510+ tsk->acl_sp_role = 0;
52511+ //tsk->acl_role_id = current->acl_role_id;
52512+ //tsk->acl = current->acl;
52513+ //tsk->role = current->role;
52514+ tsk->signal->curr_ip = current->signal->curr_ip;
52515+ tsk->signal->saved_ip = current->signal->saved_ip;
52516+ if (current->exec_file)
52517+ get_file(current->exec_file);
52518+ //tsk->exec_file = current->exec_file;
52519+ //tsk->is_writable = current->is_writable;
52520+ if (unlikely(current->signal->used_accept)) {
52521+ current->signal->curr_ip = 0;
52522+ current->signal->saved_ip = 0;
52523+ }
52524+
52525+ return;
52526+}
52527+
52528+static void
52529+gr_set_proc_res(struct task_struct *task)
52530+{
52531+ struct acl_subject_label *proc;
52532+ unsigned short i;
52533+
52534+ proc = task->acl;
52535+
52536+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
52537+ return;
52538+
52539+ for (i = 0; i < RLIM_NLIMITS; i++) {
52540+ if (!(proc->resmask & (1 << i)))
52541+ continue;
52542+
52543+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
52544+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
52545+ }
52546+
52547+ return;
52548+}
52549+
52550+extern int __gr_process_user_ban(struct user_struct *user);
52551+
52552+int
52553+gr_check_user_change(int real, int effective, int fs)
52554+{
52555+ unsigned int i;
52556+ __u16 num;
52557+ uid_t *uidlist;
52558+ int curuid;
52559+ int realok = 0;
52560+ int effectiveok = 0;
52561+ int fsok = 0;
52562+
52563+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
52564+ struct user_struct *user;
52565+
52566+ if (real == -1)
52567+ goto skipit;
52568+
52569+ user = find_user(real);
52570+ if (user == NULL)
52571+ goto skipit;
52572+
52573+ if (__gr_process_user_ban(user)) {
52574+ /* for find_user */
52575+ free_uid(user);
52576+ return 1;
52577+ }
52578+
52579+ /* for find_user */
52580+ free_uid(user);
52581+
52582+skipit:
52583+#endif
52584+
52585+ if (unlikely(!(gr_status & GR_READY)))
52586+ return 0;
52587+
52588+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
52589+ gr_log_learn_id_change('u', real, effective, fs);
52590+
52591+ num = current->acl->user_trans_num;
52592+ uidlist = current->acl->user_transitions;
52593+
52594+ if (uidlist == NULL)
52595+ return 0;
52596+
52597+ if (real == -1)
52598+ realok = 1;
52599+ if (effective == -1)
52600+ effectiveok = 1;
52601+ if (fs == -1)
52602+ fsok = 1;
52603+
52604+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
52605+ for (i = 0; i < num; i++) {
52606+ curuid = (int)uidlist[i];
52607+ if (real == curuid)
52608+ realok = 1;
52609+ if (effective == curuid)
52610+ effectiveok = 1;
52611+ if (fs == curuid)
52612+ fsok = 1;
52613+ }
52614+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
52615+ for (i = 0; i < num; i++) {
52616+ curuid = (int)uidlist[i];
52617+ if (real == curuid)
52618+ break;
52619+ if (effective == curuid)
52620+ break;
52621+ if (fs == curuid)
52622+ break;
52623+ }
52624+ /* not in deny list */
52625+ if (i == num) {
52626+ realok = 1;
52627+ effectiveok = 1;
52628+ fsok = 1;
52629+ }
52630+ }
52631+
52632+ if (realok && effectiveok && fsok)
52633+ return 0;
52634+ else {
52635+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
52636+ return 1;
52637+ }
52638+}
52639+
52640+int
52641+gr_check_group_change(int real, int effective, int fs)
52642+{
52643+ unsigned int i;
52644+ __u16 num;
52645+ gid_t *gidlist;
52646+ int curgid;
52647+ int realok = 0;
52648+ int effectiveok = 0;
52649+ int fsok = 0;
52650+
52651+ if (unlikely(!(gr_status & GR_READY)))
52652+ return 0;
52653+
52654+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
52655+ gr_log_learn_id_change('g', real, effective, fs);
52656+
52657+ num = current->acl->group_trans_num;
52658+ gidlist = current->acl->group_transitions;
52659+
52660+ if (gidlist == NULL)
52661+ return 0;
52662+
52663+ if (real == -1)
52664+ realok = 1;
52665+ if (effective == -1)
52666+ effectiveok = 1;
52667+ if (fs == -1)
52668+ fsok = 1;
52669+
52670+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
52671+ for (i = 0; i < num; i++) {
52672+ curgid = (int)gidlist[i];
52673+ if (real == curgid)
52674+ realok = 1;
52675+ if (effective == curgid)
52676+ effectiveok = 1;
52677+ if (fs == curgid)
52678+ fsok = 1;
52679+ }
52680+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
52681+ for (i = 0; i < num; i++) {
52682+ curgid = (int)gidlist[i];
52683+ if (real == curgid)
52684+ break;
52685+ if (effective == curgid)
52686+ break;
52687+ if (fs == curgid)
52688+ break;
52689+ }
52690+ /* not in deny list */
52691+ if (i == num) {
52692+ realok = 1;
52693+ effectiveok = 1;
52694+ fsok = 1;
52695+ }
52696+ }
52697+
52698+ if (realok && effectiveok && fsok)
52699+ return 0;
52700+ else {
52701+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
52702+ return 1;
52703+ }
52704+}
52705+
52706+extern int gr_acl_is_capable(const int cap);
52707+
52708+void
52709+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
52710+{
52711+ struct acl_role_label *role = task->role;
52712+ struct acl_subject_label *subj = NULL;
52713+ struct acl_object_label *obj;
52714+ struct file *filp;
52715+
52716+ if (unlikely(!(gr_status & GR_READY)))
52717+ return;
52718+
52719+ filp = task->exec_file;
52720+
52721+ /* kernel process, we'll give them the kernel role */
52722+ if (unlikely(!filp)) {
52723+ task->role = kernel_role;
52724+ task->acl = kernel_role->root_label;
52725+ return;
52726+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
52727+ role = lookup_acl_role_label(task, uid, gid);
52728+
52729+ /* don't change the role if we're not a privileged process */
52730+ if (role && task->role != role &&
52731+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
52732+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
52733+ return;
52734+
52735+ /* perform subject lookup in possibly new role
52736+ we can use this result below in the case where role == task->role
52737+ */
52738+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
52739+
52740+ /* if we changed uid/gid, but result in the same role
52741+ and are using inheritance, don't lose the inherited subject
52742+ if current subject is other than what normal lookup
52743+ would result in, we arrived via inheritance, don't
52744+ lose subject
52745+ */
52746+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
52747+ (subj == task->acl)))
52748+ task->acl = subj;
52749+
52750+ task->role = role;
52751+
52752+ task->is_writable = 0;
52753+
52754+ /* ignore additional mmap checks for processes that are writable
52755+ by the default ACL */
52756+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
52757+ if (unlikely(obj->mode & GR_WRITE))
52758+ task->is_writable = 1;
52759+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
52760+ if (unlikely(obj->mode & GR_WRITE))
52761+ task->is_writable = 1;
52762+
52763+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52764+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
52765+#endif
52766+
52767+ gr_set_proc_res(task);
52768+
52769+ return;
52770+}
52771+
52772+int
52773+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
52774+ const int unsafe_flags)
52775+{
52776+ struct task_struct *task = current;
52777+ struct acl_subject_label *newacl;
52778+ struct acl_object_label *obj;
52779+ __u32 retmode;
52780+
52781+ if (unlikely(!(gr_status & GR_READY)))
52782+ return 0;
52783+
52784+ newacl = chk_subj_label(dentry, mnt, task->role);
52785+
52786+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
52787+ did an exec
52788+ */
52789+ rcu_read_lock();
52790+ read_lock(&tasklist_lock);
52791+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
52792+ (task->parent->acl->mode & GR_POVERRIDE))) {
52793+ read_unlock(&tasklist_lock);
52794+ rcu_read_unlock();
52795+ goto skip_check;
52796+ }
52797+ read_unlock(&tasklist_lock);
52798+ rcu_read_unlock();
52799+
52800+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
52801+ !(task->role->roletype & GR_ROLE_GOD) &&
52802+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
52803+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
52804+ if (unsafe_flags & LSM_UNSAFE_SHARE)
52805+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
52806+ else
52807+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
52808+ return -EACCES;
52809+ }
52810+
52811+skip_check:
52812+
52813+ obj = chk_obj_label(dentry, mnt, task->acl);
52814+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
52815+
52816+ if (!(task->acl->mode & GR_INHERITLEARN) &&
52817+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
52818+ if (obj->nested)
52819+ task->acl = obj->nested;
52820+ else
52821+ task->acl = newacl;
52822+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
52823+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
52824+
52825+ task->is_writable = 0;
52826+
52827+ /* ignore additional mmap checks for processes that are writable
52828+ by the default ACL */
52829+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
52830+ if (unlikely(obj->mode & GR_WRITE))
52831+ task->is_writable = 1;
52832+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
52833+ if (unlikely(obj->mode & GR_WRITE))
52834+ task->is_writable = 1;
52835+
52836+ gr_set_proc_res(task);
52837+
52838+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52839+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
52840+#endif
52841+ return 0;
52842+}
52843+
52844+/* always called with valid inodev ptr */
52845+static void
52846+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
52847+{
52848+ struct acl_object_label *matchpo;
52849+ struct acl_subject_label *matchps;
52850+ struct acl_subject_label *subj;
52851+ struct acl_role_label *role;
52852+ unsigned int x;
52853+
52854+ FOR_EACH_ROLE_START(role)
52855+ FOR_EACH_SUBJECT_START(role, subj, x)
52856+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
52857+ matchpo->mode |= GR_DELETED;
52858+ FOR_EACH_SUBJECT_END(subj,x)
52859+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
52860+ if (subj->inode == ino && subj->device == dev)
52861+ subj->mode |= GR_DELETED;
52862+ FOR_EACH_NESTED_SUBJECT_END(subj)
52863+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
52864+ matchps->mode |= GR_DELETED;
52865+ FOR_EACH_ROLE_END(role)
52866+
52867+ inodev->nentry->deleted = 1;
52868+
52869+ return;
52870+}
52871+
52872+void
52873+gr_handle_delete(const ino_t ino, const dev_t dev)
52874+{
52875+ struct inodev_entry *inodev;
52876+
52877+ if (unlikely(!(gr_status & GR_READY)))
52878+ return;
52879+
52880+ write_lock(&gr_inode_lock);
52881+ inodev = lookup_inodev_entry(ino, dev);
52882+ if (inodev != NULL)
52883+ do_handle_delete(inodev, ino, dev);
52884+ write_unlock(&gr_inode_lock);
52885+
52886+ return;
52887+}
52888+
52889+static void
52890+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
52891+ const ino_t newinode, const dev_t newdevice,
52892+ struct acl_subject_label *subj)
52893+{
52894+ unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
52895+ struct acl_object_label *match;
52896+
52897+ match = subj->obj_hash[index];
52898+
52899+ while (match && (match->inode != oldinode ||
52900+ match->device != olddevice ||
52901+ !(match->mode & GR_DELETED)))
52902+ match = match->next;
52903+
52904+ if (match && (match->inode == oldinode)
52905+ && (match->device == olddevice)
52906+ && (match->mode & GR_DELETED)) {
52907+ if (match->prev == NULL) {
52908+ subj->obj_hash[index] = match->next;
52909+ if (match->next != NULL)
52910+ match->next->prev = NULL;
52911+ } else {
52912+ match->prev->next = match->next;
52913+ if (match->next != NULL)
52914+ match->next->prev = match->prev;
52915+ }
52916+ match->prev = NULL;
52917+ match->next = NULL;
52918+ match->inode = newinode;
52919+ match->device = newdevice;
52920+ match->mode &= ~GR_DELETED;
52921+
52922+ insert_acl_obj_label(match, subj);
52923+ }
52924+
52925+ return;
52926+}
52927+
52928+static void
52929+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
52930+ const ino_t newinode, const dev_t newdevice,
52931+ struct acl_role_label *role)
52932+{
52933+ unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
52934+ struct acl_subject_label *match;
52935+
52936+ match = role->subj_hash[index];
52937+
52938+ while (match && (match->inode != oldinode ||
52939+ match->device != olddevice ||
52940+ !(match->mode & GR_DELETED)))
52941+ match = match->next;
52942+
52943+ if (match && (match->inode == oldinode)
52944+ && (match->device == olddevice)
52945+ && (match->mode & GR_DELETED)) {
52946+ if (match->prev == NULL) {
52947+ role->subj_hash[index] = match->next;
52948+ if (match->next != NULL)
52949+ match->next->prev = NULL;
52950+ } else {
52951+ match->prev->next = match->next;
52952+ if (match->next != NULL)
52953+ match->next->prev = match->prev;
52954+ }
52955+ match->prev = NULL;
52956+ match->next = NULL;
52957+ match->inode = newinode;
52958+ match->device = newdevice;
52959+ match->mode &= ~GR_DELETED;
52960+
52961+ insert_acl_subj_label(match, role);
52962+ }
52963+
52964+ return;
52965+}
52966+
52967+static void
52968+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
52969+ const ino_t newinode, const dev_t newdevice)
52970+{
52971+ unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
52972+ struct inodev_entry *match;
52973+
52974+ match = inodev_set.i_hash[index];
52975+
52976+ while (match && (match->nentry->inode != oldinode ||
52977+ match->nentry->device != olddevice || !match->nentry->deleted))
52978+ match = match->next;
52979+
52980+ if (match && (match->nentry->inode == oldinode)
52981+ && (match->nentry->device == olddevice) &&
52982+ match->nentry->deleted) {
52983+ if (match->prev == NULL) {
52984+ inodev_set.i_hash[index] = match->next;
52985+ if (match->next != NULL)
52986+ match->next->prev = NULL;
52987+ } else {
52988+ match->prev->next = match->next;
52989+ if (match->next != NULL)
52990+ match->next->prev = match->prev;
52991+ }
52992+ match->prev = NULL;
52993+ match->next = NULL;
52994+ match->nentry->inode = newinode;
52995+ match->nentry->device = newdevice;
52996+ match->nentry->deleted = 0;
52997+
52998+ insert_inodev_entry(match);
52999+ }
53000+
53001+ return;
53002+}
53003+
53004+static void
53005+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
53006+{
53007+ struct acl_subject_label *subj;
53008+ struct acl_role_label *role;
53009+ unsigned int x;
53010+
53011+ FOR_EACH_ROLE_START(role)
53012+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
53013+
53014+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
53015+ if ((subj->inode == ino) && (subj->device == dev)) {
53016+ subj->inode = ino;
53017+ subj->device = dev;
53018+ }
53019+ FOR_EACH_NESTED_SUBJECT_END(subj)
53020+ FOR_EACH_SUBJECT_START(role, subj, x)
53021+ update_acl_obj_label(matchn->inode, matchn->device,
53022+ ino, dev, subj);
53023+ FOR_EACH_SUBJECT_END(subj,x)
53024+ FOR_EACH_ROLE_END(role)
53025+
53026+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
53027+
53028+ return;
53029+}
53030+
53031+static void
53032+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
53033+ const struct vfsmount *mnt)
53034+{
53035+ ino_t ino = dentry->d_inode->i_ino;
53036+ dev_t dev = __get_dev(dentry);
53037+
53038+ __do_handle_create(matchn, ino, dev);
53039+
53040+ return;
53041+}
53042+
53043+void
53044+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
53045+{
53046+ struct name_entry *matchn;
53047+
53048+ if (unlikely(!(gr_status & GR_READY)))
53049+ return;
53050+
53051+ preempt_disable();
53052+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
53053+
53054+ if (unlikely((unsigned long)matchn)) {
53055+ write_lock(&gr_inode_lock);
53056+ do_handle_create(matchn, dentry, mnt);
53057+ write_unlock(&gr_inode_lock);
53058+ }
53059+ preempt_enable();
53060+
53061+ return;
53062+}
53063+
53064+void
53065+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
53066+{
53067+ struct name_entry *matchn;
53068+
53069+ if (unlikely(!(gr_status & GR_READY)))
53070+ return;
53071+
53072+ preempt_disable();
53073+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
53074+
53075+ if (unlikely((unsigned long)matchn)) {
53076+ write_lock(&gr_inode_lock);
53077+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
53078+ write_unlock(&gr_inode_lock);
53079+ }
53080+ preempt_enable();
53081+
53082+ return;
53083+}
53084+
53085+void
53086+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
53087+ struct dentry *old_dentry,
53088+ struct dentry *new_dentry,
53089+ struct vfsmount *mnt, const __u8 replace)
53090+{
53091+ struct name_entry *matchn;
53092+ struct inodev_entry *inodev;
53093+ struct inode *inode = new_dentry->d_inode;
53094+ ino_t old_ino = old_dentry->d_inode->i_ino;
53095+ dev_t old_dev = __get_dev(old_dentry);
53096+
53097+ /* vfs_rename swaps the name and parent link for old_dentry and
53098+ new_dentry
53099+ at this point, old_dentry has the new name, parent link, and inode
53100+ for the renamed file
53101+ if a file is being replaced by a rename, new_dentry has the inode
53102+ and name for the replaced file
53103+ */
53104+
53105+ if (unlikely(!(gr_status & GR_READY)))
53106+ return;
53107+
53108+ preempt_disable();
53109+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
53110+
53111+ /* we wouldn't have to check d_inode if it weren't for
53112+ NFS silly-renaming
53113+ */
53114+
53115+ write_lock(&gr_inode_lock);
53116+ if (unlikely(replace && inode)) {
53117+ ino_t new_ino = inode->i_ino;
53118+ dev_t new_dev = __get_dev(new_dentry);
53119+
53120+ inodev = lookup_inodev_entry(new_ino, new_dev);
53121+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
53122+ do_handle_delete(inodev, new_ino, new_dev);
53123+ }
53124+
53125+ inodev = lookup_inodev_entry(old_ino, old_dev);
53126+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
53127+ do_handle_delete(inodev, old_ino, old_dev);
53128+
53129+ if (unlikely((unsigned long)matchn))
53130+ do_handle_create(matchn, old_dentry, mnt);
53131+
53132+ write_unlock(&gr_inode_lock);
53133+ preempt_enable();
53134+
53135+ return;
53136+}
53137+
53138+static int
53139+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
53140+ unsigned char **sum)
53141+{
53142+ struct acl_role_label *r;
53143+ struct role_allowed_ip *ipp;
53144+ struct role_transition *trans;
53145+ unsigned int i;
53146+ int found = 0;
53147+ u32 curr_ip = current->signal->curr_ip;
53148+
53149+ current->signal->saved_ip = curr_ip;
53150+
53151+ /* check transition table */
53152+
53153+ for (trans = current->role->transitions; trans; trans = trans->next) {
53154+ if (!strcmp(rolename, trans->rolename)) {
53155+ found = 1;
53156+ break;
53157+ }
53158+ }
53159+
53160+ if (!found)
53161+ return 0;
53162+
53163+ /* handle special roles that do not require authentication
53164+ and check ip */
53165+
53166+ FOR_EACH_ROLE_START(r)
53167+ if (!strcmp(rolename, r->rolename) &&
53168+ (r->roletype & GR_ROLE_SPECIAL)) {
53169+ found = 0;
53170+ if (r->allowed_ips != NULL) {
53171+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
53172+ if ((ntohl(curr_ip) & ipp->netmask) ==
53173+ (ntohl(ipp->addr) & ipp->netmask))
53174+ found = 1;
53175+ }
53176+ } else
53177+ found = 2;
53178+ if (!found)
53179+ return 0;
53180+
53181+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
53182+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
53183+ *salt = NULL;
53184+ *sum = NULL;
53185+ return 1;
53186+ }
53187+ }
53188+ FOR_EACH_ROLE_END(r)
53189+
53190+ for (i = 0; i < num_sprole_pws; i++) {
53191+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
53192+ *salt = acl_special_roles[i]->salt;
53193+ *sum = acl_special_roles[i]->sum;
53194+ return 1;
53195+ }
53196+ }
53197+
53198+ return 0;
53199+}
53200+
53201+static void
53202+assign_special_role(char *rolename)
53203+{
53204+ struct acl_object_label *obj;
53205+ struct acl_role_label *r;
53206+ struct acl_role_label *assigned = NULL;
53207+ struct task_struct *tsk;
53208+ struct file *filp;
53209+
53210+ FOR_EACH_ROLE_START(r)
53211+ if (!strcmp(rolename, r->rolename) &&
53212+ (r->roletype & GR_ROLE_SPECIAL)) {
53213+ assigned = r;
53214+ break;
53215+ }
53216+ FOR_EACH_ROLE_END(r)
53217+
53218+ if (!assigned)
53219+ return;
53220+
53221+ read_lock(&tasklist_lock);
53222+ read_lock(&grsec_exec_file_lock);
53223+
53224+ tsk = current->real_parent;
53225+ if (tsk == NULL)
53226+ goto out_unlock;
53227+
53228+ filp = tsk->exec_file;
53229+ if (filp == NULL)
53230+ goto out_unlock;
53231+
53232+ tsk->is_writable = 0;
53233+
53234+ tsk->acl_sp_role = 1;
53235+ tsk->acl_role_id = ++acl_sp_role_value;
53236+ tsk->role = assigned;
53237+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
53238+
53239+ /* ignore additional mmap checks for processes that are writable
53240+ by the default ACL */
53241+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53242+ if (unlikely(obj->mode & GR_WRITE))
53243+ tsk->is_writable = 1;
53244+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
53245+ if (unlikely(obj->mode & GR_WRITE))
53246+ tsk->is_writable = 1;
53247+
53248+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53249+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
53250+#endif
53251+
53252+out_unlock:
53253+ read_unlock(&grsec_exec_file_lock);
53254+ read_unlock(&tasklist_lock);
53255+ return;
53256+}
53257+
53258+int gr_check_secure_terminal(struct task_struct *task)
53259+{
53260+ struct task_struct *p, *p2, *p3;
53261+ struct files_struct *files;
53262+ struct fdtable *fdt;
53263+ struct file *our_file = NULL, *file;
53264+ int i;
53265+
53266+ if (task->signal->tty == NULL)
53267+ return 1;
53268+
53269+ files = get_files_struct(task);
53270+ if (files != NULL) {
53271+ rcu_read_lock();
53272+ fdt = files_fdtable(files);
53273+ for (i=0; i < fdt->max_fds; i++) {
53274+ file = fcheck_files(files, i);
53275+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
53276+ get_file(file);
53277+ our_file = file;
53278+ }
53279+ }
53280+ rcu_read_unlock();
53281+ put_files_struct(files);
53282+ }
53283+
53284+ if (our_file == NULL)
53285+ return 1;
53286+
53287+ read_lock(&tasklist_lock);
53288+ do_each_thread(p2, p) {
53289+ files = get_files_struct(p);
53290+ if (files == NULL ||
53291+ (p->signal && p->signal->tty == task->signal->tty)) {
53292+ if (files != NULL)
53293+ put_files_struct(files);
53294+ continue;
53295+ }
53296+ rcu_read_lock();
53297+ fdt = files_fdtable(files);
53298+ for (i=0; i < fdt->max_fds; i++) {
53299+ file = fcheck_files(files, i);
53300+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
53301+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
53302+ p3 = task;
53303+ while (p3->pid > 0) {
53304+ if (p3 == p)
53305+ break;
53306+ p3 = p3->real_parent;
53307+ }
53308+ if (p3 == p)
53309+ break;
53310+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
53311+ gr_handle_alertkill(p);
53312+ rcu_read_unlock();
53313+ put_files_struct(files);
53314+ read_unlock(&tasklist_lock);
53315+ fput(our_file);
53316+ return 0;
53317+ }
53318+ }
53319+ rcu_read_unlock();
53320+ put_files_struct(files);
53321+ } while_each_thread(p2, p);
53322+ read_unlock(&tasklist_lock);
53323+
53324+ fput(our_file);
53325+ return 1;
53326+}
53327+
53328+ssize_t
53329+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
53330+{
53331+ struct gr_arg_wrapper uwrap;
53332+ unsigned char *sprole_salt = NULL;
53333+ unsigned char *sprole_sum = NULL;
53334+ int error = sizeof (struct gr_arg_wrapper);
53335+ int error2 = 0;
53336+
53337+ mutex_lock(&gr_dev_mutex);
53338+
53339+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
53340+ error = -EPERM;
53341+ goto out;
53342+ }
53343+
53344+ if (count != sizeof (struct gr_arg_wrapper)) {
53345+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
53346+ error = -EINVAL;
53347+ goto out;
53348+ }
53349+
53350+
53351+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
53352+ gr_auth_expires = 0;
53353+ gr_auth_attempts = 0;
53354+ }
53355+
53356+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
53357+ error = -EFAULT;
53358+ goto out;
53359+ }
53360+
53361+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
53362+ error = -EINVAL;
53363+ goto out;
53364+ }
53365+
53366+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
53367+ error = -EFAULT;
53368+ goto out;
53369+ }
53370+
53371+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
53372+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
53373+ time_after(gr_auth_expires, get_seconds())) {
53374+ error = -EBUSY;
53375+ goto out;
53376+ }
53377+
53378+ /* if non-root trying to do anything other than use a special role,
53379+ do not attempt authentication, do not count towards authentication
53380+ locking
53381+ */
53382+
53383+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
53384+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
53385+ current_uid()) {
53386+ error = -EPERM;
53387+ goto out;
53388+ }
53389+
53390+ /* ensure pw and special role name are null terminated */
53391+
53392+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
53393+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
53394+
53395+ /* Okay.
53396+ * We have our enough of the argument structure..(we have yet
53397+ * to copy_from_user the tables themselves) . Copy the tables
53398+ * only if we need them, i.e. for loading operations. */
53399+
53400+ switch (gr_usermode->mode) {
53401+ case GR_STATUS:
53402+ if (gr_status & GR_READY) {
53403+ error = 1;
53404+ if (!gr_check_secure_terminal(current))
53405+ error = 3;
53406+ } else
53407+ error = 2;
53408+ goto out;
53409+ case GR_SHUTDOWN:
53410+ if ((gr_status & GR_READY)
53411+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53412+ pax_open_kernel();
53413+ gr_status &= ~GR_READY;
53414+ pax_close_kernel();
53415+
53416+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
53417+ free_variables();
53418+ memset(gr_usermode, 0, sizeof (struct gr_arg));
53419+ memset(gr_system_salt, 0, GR_SALT_LEN);
53420+ memset(gr_system_sum, 0, GR_SHA_LEN);
53421+ } else if (gr_status & GR_READY) {
53422+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
53423+ error = -EPERM;
53424+ } else {
53425+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
53426+ error = -EAGAIN;
53427+ }
53428+ break;
53429+ case GR_ENABLE:
53430+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
53431+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
53432+ else {
53433+ if (gr_status & GR_READY)
53434+ error = -EAGAIN;
53435+ else
53436+ error = error2;
53437+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
53438+ }
53439+ break;
53440+ case GR_RELOAD:
53441+ if (!(gr_status & GR_READY)) {
53442+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
53443+ error = -EAGAIN;
53444+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53445+ preempt_disable();
53446+
53447+ pax_open_kernel();
53448+ gr_status &= ~GR_READY;
53449+ pax_close_kernel();
53450+
53451+ free_variables();
53452+ if (!(error2 = gracl_init(gr_usermode))) {
53453+ preempt_enable();
53454+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
53455+ } else {
53456+ preempt_enable();
53457+ error = error2;
53458+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
53459+ }
53460+ } else {
53461+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
53462+ error = -EPERM;
53463+ }
53464+ break;
53465+ case GR_SEGVMOD:
53466+ if (unlikely(!(gr_status & GR_READY))) {
53467+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
53468+ error = -EAGAIN;
53469+ break;
53470+ }
53471+
53472+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53473+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
53474+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
53475+ struct acl_subject_label *segvacl;
53476+ segvacl =
53477+ lookup_acl_subj_label(gr_usermode->segv_inode,
53478+ gr_usermode->segv_device,
53479+ current->role);
53480+ if (segvacl) {
53481+ segvacl->crashes = 0;
53482+ segvacl->expires = 0;
53483+ }
53484+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
53485+ gr_remove_uid(gr_usermode->segv_uid);
53486+ }
53487+ } else {
53488+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
53489+ error = -EPERM;
53490+ }
53491+ break;
53492+ case GR_SPROLE:
53493+ case GR_SPROLEPAM:
53494+ if (unlikely(!(gr_status & GR_READY))) {
53495+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
53496+ error = -EAGAIN;
53497+ break;
53498+ }
53499+
53500+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
53501+ current->role->expires = 0;
53502+ current->role->auth_attempts = 0;
53503+ }
53504+
53505+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
53506+ time_after(current->role->expires, get_seconds())) {
53507+ error = -EBUSY;
53508+ goto out;
53509+ }
53510+
53511+ if (lookup_special_role_auth
53512+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
53513+ && ((!sprole_salt && !sprole_sum)
53514+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
53515+ char *p = "";
53516+ assign_special_role(gr_usermode->sp_role);
53517+ read_lock(&tasklist_lock);
53518+ if (current->real_parent)
53519+ p = current->real_parent->role->rolename;
53520+ read_unlock(&tasklist_lock);
53521+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
53522+ p, acl_sp_role_value);
53523+ } else {
53524+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
53525+ error = -EPERM;
53526+ if(!(current->role->auth_attempts++))
53527+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
53528+
53529+ goto out;
53530+ }
53531+ break;
53532+ case GR_UNSPROLE:
53533+ if (unlikely(!(gr_status & GR_READY))) {
53534+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
53535+ error = -EAGAIN;
53536+ break;
53537+ }
53538+
53539+ if (current->role->roletype & GR_ROLE_SPECIAL) {
53540+ char *p = "";
53541+ int i = 0;
53542+
53543+ read_lock(&tasklist_lock);
53544+ if (current->real_parent) {
53545+ p = current->real_parent->role->rolename;
53546+ i = current->real_parent->acl_role_id;
53547+ }
53548+ read_unlock(&tasklist_lock);
53549+
53550+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
53551+ gr_set_acls(1);
53552+ } else {
53553+ error = -EPERM;
53554+ goto out;
53555+ }
53556+ break;
53557+ default:
53558+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
53559+ error = -EINVAL;
53560+ break;
53561+ }
53562+
53563+ if (error != -EPERM)
53564+ goto out;
53565+
53566+ if(!(gr_auth_attempts++))
53567+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
53568+
53569+ out:
53570+ mutex_unlock(&gr_dev_mutex);
53571+ return error;
53572+}
53573+
53574+/* must be called with
53575+ rcu_read_lock();
53576+ read_lock(&tasklist_lock);
53577+ read_lock(&grsec_exec_file_lock);
53578+*/
53579+int gr_apply_subject_to_task(struct task_struct *task)
53580+{
53581+ struct acl_object_label *obj;
53582+ char *tmpname;
53583+ struct acl_subject_label *tmpsubj;
53584+ struct file *filp;
53585+ struct name_entry *nmatch;
53586+
53587+ filp = task->exec_file;
53588+ if (filp == NULL)
53589+ return 0;
53590+
53591+ /* the following is to apply the correct subject
53592+ on binaries running when the RBAC system
53593+ is enabled, when the binaries have been
53594+ replaced or deleted since their execution
53595+ -----
53596+ when the RBAC system starts, the inode/dev
53597+ from exec_file will be one the RBAC system
53598+ is unaware of. It only knows the inode/dev
53599+ of the present file on disk, or the absence
53600+ of it.
53601+ */
53602+ preempt_disable();
53603+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
53604+
53605+ nmatch = lookup_name_entry(tmpname);
53606+ preempt_enable();
53607+ tmpsubj = NULL;
53608+ if (nmatch) {
53609+ if (nmatch->deleted)
53610+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
53611+ else
53612+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
53613+ if (tmpsubj != NULL)
53614+ task->acl = tmpsubj;
53615+ }
53616+ if (tmpsubj == NULL)
53617+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
53618+ task->role);
53619+ if (task->acl) {
53620+ task->is_writable = 0;
53621+ /* ignore additional mmap checks for processes that are writable
53622+ by the default ACL */
53623+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53624+ if (unlikely(obj->mode & GR_WRITE))
53625+ task->is_writable = 1;
53626+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53627+ if (unlikely(obj->mode & GR_WRITE))
53628+ task->is_writable = 1;
53629+
53630+ gr_set_proc_res(task);
53631+
53632+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53633+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53634+#endif
53635+ } else {
53636+ return 1;
53637+ }
53638+
53639+ return 0;
53640+}
53641+
53642+int
53643+gr_set_acls(const int type)
53644+{
53645+ struct task_struct *task, *task2;
53646+ struct acl_role_label *role = current->role;
53647+ __u16 acl_role_id = current->acl_role_id;
53648+ const struct cred *cred;
53649+ int ret;
53650+
53651+ rcu_read_lock();
53652+ read_lock(&tasklist_lock);
53653+ read_lock(&grsec_exec_file_lock);
53654+ do_each_thread(task2, task) {
53655+ /* check to see if we're called from the exit handler,
53656+ if so, only replace ACLs that have inherited the admin
53657+ ACL */
53658+
53659+ if (type && (task->role != role ||
53660+ task->acl_role_id != acl_role_id))
53661+ continue;
53662+
53663+ task->acl_role_id = 0;
53664+ task->acl_sp_role = 0;
53665+
53666+ if (task->exec_file) {
53667+ cred = __task_cred(task);
53668+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
53669+ ret = gr_apply_subject_to_task(task);
53670+ if (ret) {
53671+ read_unlock(&grsec_exec_file_lock);
53672+ read_unlock(&tasklist_lock);
53673+ rcu_read_unlock();
53674+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
53675+ return ret;
53676+ }
53677+ } else {
53678+ // it's a kernel process
53679+ task->role = kernel_role;
53680+ task->acl = kernel_role->root_label;
53681+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
53682+ task->acl->mode &= ~GR_PROCFIND;
53683+#endif
53684+ }
53685+ } while_each_thread(task2, task);
53686+ read_unlock(&grsec_exec_file_lock);
53687+ read_unlock(&tasklist_lock);
53688+ rcu_read_unlock();
53689+
53690+ return 0;
53691+}
53692+
53693+void
53694+gr_learn_resource(const struct task_struct *task,
53695+ const int res, const unsigned long wanted, const int gt)
53696+{
53697+ struct acl_subject_label *acl;
53698+ const struct cred *cred;
53699+
53700+ if (unlikely((gr_status & GR_READY) &&
53701+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
53702+ goto skip_reslog;
53703+
53704+#ifdef CONFIG_GRKERNSEC_RESLOG
53705+ gr_log_resource(task, res, wanted, gt);
53706+#endif
53707+ skip_reslog:
53708+
53709+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
53710+ return;
53711+
53712+ acl = task->acl;
53713+
53714+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
53715+ !(acl->resmask & (1 << (unsigned short) res))))
53716+ return;
53717+
53718+ if (wanted >= acl->res[res].rlim_cur) {
53719+ unsigned long res_add;
53720+
53721+ res_add = wanted;
53722+ switch (res) {
53723+ case RLIMIT_CPU:
53724+ res_add += GR_RLIM_CPU_BUMP;
53725+ break;
53726+ case RLIMIT_FSIZE:
53727+ res_add += GR_RLIM_FSIZE_BUMP;
53728+ break;
53729+ case RLIMIT_DATA:
53730+ res_add += GR_RLIM_DATA_BUMP;
53731+ break;
53732+ case RLIMIT_STACK:
53733+ res_add += GR_RLIM_STACK_BUMP;
53734+ break;
53735+ case RLIMIT_CORE:
53736+ res_add += GR_RLIM_CORE_BUMP;
53737+ break;
53738+ case RLIMIT_RSS:
53739+ res_add += GR_RLIM_RSS_BUMP;
53740+ break;
53741+ case RLIMIT_NPROC:
53742+ res_add += GR_RLIM_NPROC_BUMP;
53743+ break;
53744+ case RLIMIT_NOFILE:
53745+ res_add += GR_RLIM_NOFILE_BUMP;
53746+ break;
53747+ case RLIMIT_MEMLOCK:
53748+ res_add += GR_RLIM_MEMLOCK_BUMP;
53749+ break;
53750+ case RLIMIT_AS:
53751+ res_add += GR_RLIM_AS_BUMP;
53752+ break;
53753+ case RLIMIT_LOCKS:
53754+ res_add += GR_RLIM_LOCKS_BUMP;
53755+ break;
53756+ case RLIMIT_SIGPENDING:
53757+ res_add += GR_RLIM_SIGPENDING_BUMP;
53758+ break;
53759+ case RLIMIT_MSGQUEUE:
53760+ res_add += GR_RLIM_MSGQUEUE_BUMP;
53761+ break;
53762+ case RLIMIT_NICE:
53763+ res_add += GR_RLIM_NICE_BUMP;
53764+ break;
53765+ case RLIMIT_RTPRIO:
53766+ res_add += GR_RLIM_RTPRIO_BUMP;
53767+ break;
53768+ case RLIMIT_RTTIME:
53769+ res_add += GR_RLIM_RTTIME_BUMP;
53770+ break;
53771+ }
53772+
53773+ acl->res[res].rlim_cur = res_add;
53774+
53775+ if (wanted > acl->res[res].rlim_max)
53776+ acl->res[res].rlim_max = res_add;
53777+
53778+ /* only log the subject filename, since resource logging is supported for
53779+ single-subject learning only */
53780+ rcu_read_lock();
53781+ cred = __task_cred(task);
53782+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
53783+ task->role->roletype, cred->uid, cred->gid, acl->filename,
53784+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
53785+ "", (unsigned long) res, &task->signal->saved_ip);
53786+ rcu_read_unlock();
53787+ }
53788+
53789+ return;
53790+}
53791+
53792+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
53793+void
53794+pax_set_initial_flags(struct linux_binprm *bprm)
53795+{
53796+ struct task_struct *task = current;
53797+ struct acl_subject_label *proc;
53798+ unsigned long flags;
53799+
53800+ if (unlikely(!(gr_status & GR_READY)))
53801+ return;
53802+
53803+ flags = pax_get_flags(task);
53804+
53805+ proc = task->acl;
53806+
53807+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
53808+ flags &= ~MF_PAX_PAGEEXEC;
53809+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
53810+ flags &= ~MF_PAX_SEGMEXEC;
53811+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
53812+ flags &= ~MF_PAX_RANDMMAP;
53813+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
53814+ flags &= ~MF_PAX_EMUTRAMP;
53815+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
53816+ flags &= ~MF_PAX_MPROTECT;
53817+
53818+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
53819+ flags |= MF_PAX_PAGEEXEC;
53820+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
53821+ flags |= MF_PAX_SEGMEXEC;
53822+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
53823+ flags |= MF_PAX_RANDMMAP;
53824+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
53825+ flags |= MF_PAX_EMUTRAMP;
53826+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
53827+ flags |= MF_PAX_MPROTECT;
53828+
53829+ pax_set_flags(task, flags);
53830+
53831+ return;
53832+}
53833+#endif
53834+
53835+int
53836+gr_handle_proc_ptrace(struct task_struct *task)
53837+{
53838+ struct file *filp;
53839+ struct task_struct *tmp = task;
53840+ struct task_struct *curtemp = current;
53841+ __u32 retmode;
53842+
53843+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
53844+ if (unlikely(!(gr_status & GR_READY)))
53845+ return 0;
53846+#endif
53847+
53848+ read_lock(&tasklist_lock);
53849+ read_lock(&grsec_exec_file_lock);
53850+ filp = task->exec_file;
53851+
53852+ while (tmp->pid > 0) {
53853+ if (tmp == curtemp)
53854+ break;
53855+ tmp = tmp->real_parent;
53856+ }
53857+
53858+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
53859+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
53860+ read_unlock(&grsec_exec_file_lock);
53861+ read_unlock(&tasklist_lock);
53862+ return 1;
53863+ }
53864+
53865+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
53866+ if (!(gr_status & GR_READY)) {
53867+ read_unlock(&grsec_exec_file_lock);
53868+ read_unlock(&tasklist_lock);
53869+ return 0;
53870+ }
53871+#endif
53872+
53873+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
53874+ read_unlock(&grsec_exec_file_lock);
53875+ read_unlock(&tasklist_lock);
53876+
53877+ if (retmode & GR_NOPTRACE)
53878+ return 1;
53879+
53880+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
53881+ && (current->acl != task->acl || (current->acl != current->role->root_label
53882+ && current->pid != task->pid)))
53883+ return 1;
53884+
53885+ return 0;
53886+}
53887+
53888+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
53889+{
53890+ if (unlikely(!(gr_status & GR_READY)))
53891+ return;
53892+
53893+ if (!(current->role->roletype & GR_ROLE_GOD))
53894+ return;
53895+
53896+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
53897+ p->role->rolename, gr_task_roletype_to_char(p),
53898+ p->acl->filename);
53899+}
53900+
53901+int
53902+gr_handle_ptrace(struct task_struct *task, const long request)
53903+{
53904+ struct task_struct *tmp = task;
53905+ struct task_struct *curtemp = current;
53906+ __u32 retmode;
53907+
53908+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
53909+ if (unlikely(!(gr_status & GR_READY)))
53910+ return 0;
53911+#endif
53912+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
53913+ read_lock(&tasklist_lock);
53914+ while (tmp->pid > 0) {
53915+ if (tmp == curtemp)
53916+ break;
53917+ tmp = tmp->real_parent;
53918+ }
53919+
53920+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
53921+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
53922+ read_unlock(&tasklist_lock);
53923+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
53924+ return 1;
53925+ }
53926+ read_unlock(&tasklist_lock);
53927+ }
53928+
53929+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
53930+ if (!(gr_status & GR_READY))
53931+ return 0;
53932+#endif
53933+
53934+ read_lock(&grsec_exec_file_lock);
53935+ if (unlikely(!task->exec_file)) {
53936+ read_unlock(&grsec_exec_file_lock);
53937+ return 0;
53938+ }
53939+
53940+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
53941+ read_unlock(&grsec_exec_file_lock);
53942+
53943+ if (retmode & GR_NOPTRACE) {
53944+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
53945+ return 1;
53946+ }
53947+
53948+ if (retmode & GR_PTRACERD) {
53949+ switch (request) {
53950+ case PTRACE_SEIZE:
53951+ case PTRACE_POKETEXT:
53952+ case PTRACE_POKEDATA:
53953+ case PTRACE_POKEUSR:
53954+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
53955+ case PTRACE_SETREGS:
53956+ case PTRACE_SETFPREGS:
53957+#endif
53958+#ifdef CONFIG_X86
53959+ case PTRACE_SETFPXREGS:
53960+#endif
53961+#ifdef CONFIG_ALTIVEC
53962+ case PTRACE_SETVRREGS:
53963+#endif
53964+ return 1;
53965+ default:
53966+ return 0;
53967+ }
53968+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
53969+ !(current->role->roletype & GR_ROLE_GOD) &&
53970+ (current->acl != task->acl)) {
53971+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
53972+ return 1;
53973+ }
53974+
53975+ return 0;
53976+}
53977+
53978+static int is_writable_mmap(const struct file *filp)
53979+{
53980+ struct task_struct *task = current;
53981+ struct acl_object_label *obj, *obj2;
53982+
53983+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
53984+ !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))) {
53985+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53986+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
53987+ task->role->root_label);
53988+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
53989+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
53990+ return 1;
53991+ }
53992+ }
53993+ return 0;
53994+}
53995+
53996+int
53997+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
53998+{
53999+ __u32 mode;
54000+
54001+ if (unlikely(!file || !(prot & PROT_EXEC)))
54002+ return 1;
54003+
54004+ if (is_writable_mmap(file))
54005+ return 0;
54006+
54007+ mode =
54008+ gr_search_file(file->f_path.dentry,
54009+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54010+ file->f_path.mnt);
54011+
54012+ if (!gr_tpe_allow(file))
54013+ return 0;
54014+
54015+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54016+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54017+ return 0;
54018+ } else if (unlikely(!(mode & GR_EXEC))) {
54019+ return 0;
54020+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54021+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54022+ return 1;
54023+ }
54024+
54025+ return 1;
54026+}
54027+
54028+int
54029+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
54030+{
54031+ __u32 mode;
54032+
54033+ if (unlikely(!file || !(prot & PROT_EXEC)))
54034+ return 1;
54035+
54036+ if (is_writable_mmap(file))
54037+ return 0;
54038+
54039+ mode =
54040+ gr_search_file(file->f_path.dentry,
54041+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54042+ file->f_path.mnt);
54043+
54044+ if (!gr_tpe_allow(file))
54045+ return 0;
54046+
54047+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54048+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54049+ return 0;
54050+ } else if (unlikely(!(mode & GR_EXEC))) {
54051+ return 0;
54052+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54053+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54054+ return 1;
54055+ }
54056+
54057+ return 1;
54058+}
54059+
54060+void
54061+gr_acl_handle_psacct(struct task_struct *task, const long code)
54062+{
54063+ unsigned long runtime;
54064+ unsigned long cputime;
54065+ unsigned int wday, cday;
54066+ __u8 whr, chr;
54067+ __u8 wmin, cmin;
54068+ __u8 wsec, csec;
54069+ struct timespec timeval;
54070+
54071+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
54072+ !(task->acl->mode & GR_PROCACCT)))
54073+ return;
54074+
54075+ do_posix_clock_monotonic_gettime(&timeval);
54076+ runtime = timeval.tv_sec - task->start_time.tv_sec;
54077+ wday = runtime / (3600 * 24);
54078+ runtime -= wday * (3600 * 24);
54079+ whr = runtime / 3600;
54080+ runtime -= whr * 3600;
54081+ wmin = runtime / 60;
54082+ runtime -= wmin * 60;
54083+ wsec = runtime;
54084+
54085+ cputime = (task->utime + task->stime) / HZ;
54086+ cday = cputime / (3600 * 24);
54087+ cputime -= cday * (3600 * 24);
54088+ chr = cputime / 3600;
54089+ cputime -= chr * 3600;
54090+ cmin = cputime / 60;
54091+ cputime -= cmin * 60;
54092+ csec = cputime;
54093+
54094+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
54095+
54096+ return;
54097+}
54098+
54099+void gr_set_kernel_label(struct task_struct *task)
54100+{
54101+ if (gr_status & GR_READY) {
54102+ task->role = kernel_role;
54103+ task->acl = kernel_role->root_label;
54104+ }
54105+ return;
54106+}
54107+
54108+#ifdef CONFIG_TASKSTATS
54109+int gr_is_taskstats_denied(int pid)
54110+{
54111+ struct task_struct *task;
54112+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54113+ const struct cred *cred;
54114+#endif
54115+ int ret = 0;
54116+
54117+ /* restrict taskstats viewing to un-chrooted root users
54118+ who have the 'view' subject flag if the RBAC system is enabled
54119+ */
54120+
54121+ rcu_read_lock();
54122+ read_lock(&tasklist_lock);
54123+ task = find_task_by_vpid(pid);
54124+ if (task) {
54125+#ifdef CONFIG_GRKERNSEC_CHROOT
54126+ if (proc_is_chrooted(task))
54127+ ret = -EACCES;
54128+#endif
54129+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54130+ cred = __task_cred(task);
54131+#ifdef CONFIG_GRKERNSEC_PROC_USER
54132+ if (cred->uid != 0)
54133+ ret = -EACCES;
54134+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54135+ if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
54136+ ret = -EACCES;
54137+#endif
54138+#endif
54139+ if (gr_status & GR_READY) {
54140+ if (!(task->acl->mode & GR_VIEW))
54141+ ret = -EACCES;
54142+ }
54143+ } else
54144+ ret = -ENOENT;
54145+
54146+ read_unlock(&tasklist_lock);
54147+ rcu_read_unlock();
54148+
54149+ return ret;
54150+}
54151+#endif
54152+
54153+/* AUXV entries are filled via a descendant of search_binary_handler
54154+ after we've already applied the subject for the target
54155+*/
54156+int gr_acl_enable_at_secure(void)
54157+{
54158+ if (unlikely(!(gr_status & GR_READY)))
54159+ return 0;
54160+
54161+ if (current->acl->mode & GR_ATSECURE)
54162+ return 1;
54163+
54164+ return 0;
54165+}
54166+
54167+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
54168+{
54169+ struct task_struct *task = current;
54170+ struct dentry *dentry = file->f_path.dentry;
54171+ struct vfsmount *mnt = file->f_path.mnt;
54172+ struct acl_object_label *obj, *tmp;
54173+ struct acl_subject_label *subj;
54174+ unsigned int bufsize;
54175+ int is_not_root;
54176+ char *path;
54177+ dev_t dev = __get_dev(dentry);
54178+
54179+ if (unlikely(!(gr_status & GR_READY)))
54180+ return 1;
54181+
54182+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54183+ return 1;
54184+
54185+ /* ignore Eric Biederman */
54186+ if (IS_PRIVATE(dentry->d_inode))
54187+ return 1;
54188+
54189+ subj = task->acl;
54190+ do {
54191+ obj = lookup_acl_obj_label(ino, dev, subj);
54192+ if (obj != NULL)
54193+ return (obj->mode & GR_FIND) ? 1 : 0;
54194+ } while ((subj = subj->parent_subject));
54195+
54196+ /* this is purely an optimization since we're looking for an object
54197+ for the directory we're doing a readdir on
54198+ if it's possible for any globbed object to match the entry we're
54199+ filling into the directory, then the object we find here will be
54200+ an anchor point with attached globbed objects
54201+ */
54202+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
54203+ if (obj->globbed == NULL)
54204+ return (obj->mode & GR_FIND) ? 1 : 0;
54205+
54206+ is_not_root = ((obj->filename[0] == '/') &&
54207+ (obj->filename[1] == '\0')) ? 0 : 1;
54208+ bufsize = PAGE_SIZE - namelen - is_not_root;
54209+
54210+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
54211+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
54212+ return 1;
54213+
54214+ preempt_disable();
54215+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
54216+ bufsize);
54217+
54218+ bufsize = strlen(path);
54219+
54220+ /* if base is "/", don't append an additional slash */
54221+ if (is_not_root)
54222+ *(path + bufsize) = '/';
54223+ memcpy(path + bufsize + is_not_root, name, namelen);
54224+ *(path + bufsize + namelen + is_not_root) = '\0';
54225+
54226+ tmp = obj->globbed;
54227+ while (tmp) {
54228+ if (!glob_match(tmp->filename, path)) {
54229+ preempt_enable();
54230+ return (tmp->mode & GR_FIND) ? 1 : 0;
54231+ }
54232+ tmp = tmp->next;
54233+ }
54234+ preempt_enable();
54235+ return (obj->mode & GR_FIND) ? 1 : 0;
54236+}
54237+
54238+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
54239+EXPORT_SYMBOL(gr_acl_is_enabled);
54240+#endif
54241+EXPORT_SYMBOL(gr_learn_resource);
54242+EXPORT_SYMBOL(gr_set_kernel_label);
54243+#ifdef CONFIG_SECURITY
54244+EXPORT_SYMBOL(gr_check_user_change);
54245+EXPORT_SYMBOL(gr_check_group_change);
54246+#endif
54247+
54248diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
54249new file mode 100644
54250index 0000000..34fefda
54251--- /dev/null
54252+++ b/grsecurity/gracl_alloc.c
54253@@ -0,0 +1,105 @@
54254+#include <linux/kernel.h>
54255+#include <linux/mm.h>
54256+#include <linux/slab.h>
54257+#include <linux/vmalloc.h>
54258+#include <linux/gracl.h>
54259+#include <linux/grsecurity.h>
54260+
54261+static unsigned long alloc_stack_next = 1;
54262+static unsigned long alloc_stack_size = 1;
54263+static void **alloc_stack;
54264+
54265+static __inline__ int
54266+alloc_pop(void)
54267+{
54268+ if (alloc_stack_next == 1)
54269+ return 0;
54270+
54271+ kfree(alloc_stack[alloc_stack_next - 2]);
54272+
54273+ alloc_stack_next--;
54274+
54275+ return 1;
54276+}
54277+
54278+static __inline__ int
54279+alloc_push(void *buf)
54280+{
54281+ if (alloc_stack_next >= alloc_stack_size)
54282+ return 1;
54283+
54284+ alloc_stack[alloc_stack_next - 1] = buf;
54285+
54286+ alloc_stack_next++;
54287+
54288+ return 0;
54289+}
54290+
54291+void *
54292+acl_alloc(unsigned long len)
54293+{
54294+ void *ret = NULL;
54295+
54296+ if (!len || len > PAGE_SIZE)
54297+ goto out;
54298+
54299+ ret = kmalloc(len, GFP_KERNEL);
54300+
54301+ if (ret) {
54302+ if (alloc_push(ret)) {
54303+ kfree(ret);
54304+ ret = NULL;
54305+ }
54306+ }
54307+
54308+out:
54309+ return ret;
54310+}
54311+
54312+void *
54313+acl_alloc_num(unsigned long num, unsigned long len)
54314+{
54315+ if (!len || (num > (PAGE_SIZE / len)))
54316+ return NULL;
54317+
54318+ return acl_alloc(num * len);
54319+}
54320+
54321+void
54322+acl_free_all(void)
54323+{
54324+ if (gr_acl_is_enabled() || !alloc_stack)
54325+ return;
54326+
54327+ while (alloc_pop()) ;
54328+
54329+ if (alloc_stack) {
54330+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
54331+ kfree(alloc_stack);
54332+ else
54333+ vfree(alloc_stack);
54334+ }
54335+
54336+ alloc_stack = NULL;
54337+ alloc_stack_size = 1;
54338+ alloc_stack_next = 1;
54339+
54340+ return;
54341+}
54342+
54343+int
54344+acl_alloc_stack_init(unsigned long size)
54345+{
54346+ if ((size * sizeof (void *)) <= PAGE_SIZE)
54347+ alloc_stack =
54348+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
54349+ else
54350+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
54351+
54352+ alloc_stack_size = size;
54353+
54354+ if (!alloc_stack)
54355+ return 0;
54356+ else
54357+ return 1;
54358+}
54359diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
54360new file mode 100644
54361index 0000000..6d21049
54362--- /dev/null
54363+++ b/grsecurity/gracl_cap.c
54364@@ -0,0 +1,110 @@
54365+#include <linux/kernel.h>
54366+#include <linux/module.h>
54367+#include <linux/sched.h>
54368+#include <linux/gracl.h>
54369+#include <linux/grsecurity.h>
54370+#include <linux/grinternal.h>
54371+
54372+extern const char *captab_log[];
54373+extern int captab_log_entries;
54374+
54375+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
54376+{
54377+ struct acl_subject_label *curracl;
54378+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
54379+ kernel_cap_t cap_audit = __cap_empty_set;
54380+
54381+ if (!gr_acl_is_enabled())
54382+ return 1;
54383+
54384+ curracl = task->acl;
54385+
54386+ cap_drop = curracl->cap_lower;
54387+ cap_mask = curracl->cap_mask;
54388+ cap_audit = curracl->cap_invert_audit;
54389+
54390+ while ((curracl = curracl->parent_subject)) {
54391+ /* if the cap isn't specified in the current computed mask but is specified in the
54392+ current level subject, and is lowered in the current level subject, then add
54393+ it to the set of dropped capabilities
54394+ otherwise, add the current level subject's mask to the current computed mask
54395+ */
54396+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
54397+ cap_raise(cap_mask, cap);
54398+ if (cap_raised(curracl->cap_lower, cap))
54399+ cap_raise(cap_drop, cap);
54400+ if (cap_raised(curracl->cap_invert_audit, cap))
54401+ cap_raise(cap_audit, cap);
54402+ }
54403+ }
54404+
54405+ if (!cap_raised(cap_drop, cap)) {
54406+ if (cap_raised(cap_audit, cap))
54407+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
54408+ return 1;
54409+ }
54410+
54411+ curracl = task->acl;
54412+
54413+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
54414+ && cap_raised(cred->cap_effective, cap)) {
54415+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54416+ task->role->roletype, cred->uid,
54417+ cred->gid, task->exec_file ?
54418+ gr_to_filename(task->exec_file->f_path.dentry,
54419+ task->exec_file->f_path.mnt) : curracl->filename,
54420+ curracl->filename, 0UL,
54421+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
54422+ return 1;
54423+ }
54424+
54425+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
54426+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
54427+
54428+ return 0;
54429+}
54430+
54431+int
54432+gr_acl_is_capable(const int cap)
54433+{
54434+ return gr_task_acl_is_capable(current, current_cred(), cap);
54435+}
54436+
54437+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
54438+{
54439+ struct acl_subject_label *curracl;
54440+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
54441+
54442+ if (!gr_acl_is_enabled())
54443+ return 1;
54444+
54445+ curracl = task->acl;
54446+
54447+ cap_drop = curracl->cap_lower;
54448+ cap_mask = curracl->cap_mask;
54449+
54450+ while ((curracl = curracl->parent_subject)) {
54451+ /* if the cap isn't specified in the current computed mask but is specified in the
54452+ current level subject, and is lowered in the current level subject, then add
54453+ it to the set of dropped capabilities
54454+ otherwise, add the current level subject's mask to the current computed mask
54455+ */
54456+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
54457+ cap_raise(cap_mask, cap);
54458+ if (cap_raised(curracl->cap_lower, cap))
54459+ cap_raise(cap_drop, cap);
54460+ }
54461+ }
54462+
54463+ if (!cap_raised(cap_drop, cap))
54464+ return 1;
54465+
54466+ return 0;
54467+}
54468+
54469+int
54470+gr_acl_is_capable_nolog(const int cap)
54471+{
54472+ return gr_task_acl_is_capable_nolog(current, cap);
54473+}
54474+
54475diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
54476new file mode 100644
54477index 0000000..88d0e87
54478--- /dev/null
54479+++ b/grsecurity/gracl_fs.c
54480@@ -0,0 +1,435 @@
54481+#include <linux/kernel.h>
54482+#include <linux/sched.h>
54483+#include <linux/types.h>
54484+#include <linux/fs.h>
54485+#include <linux/file.h>
54486+#include <linux/stat.h>
54487+#include <linux/grsecurity.h>
54488+#include <linux/grinternal.h>
54489+#include <linux/gracl.h>
54490+
54491+umode_t
54492+gr_acl_umask(void)
54493+{
54494+ if (unlikely(!gr_acl_is_enabled()))
54495+ return 0;
54496+
54497+ return current->role->umask;
54498+}
54499+
54500+__u32
54501+gr_acl_handle_hidden_file(const struct dentry * dentry,
54502+ const struct vfsmount * mnt)
54503+{
54504+ __u32 mode;
54505+
54506+ if (unlikely(!dentry->d_inode))
54507+ return GR_FIND;
54508+
54509+ mode =
54510+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
54511+
54512+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
54513+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
54514+ return mode;
54515+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
54516+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
54517+ return 0;
54518+ } else if (unlikely(!(mode & GR_FIND)))
54519+ return 0;
54520+
54521+ return GR_FIND;
54522+}
54523+
54524+__u32
54525+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
54526+ int acc_mode)
54527+{
54528+ __u32 reqmode = GR_FIND;
54529+ __u32 mode;
54530+
54531+ if (unlikely(!dentry->d_inode))
54532+ return reqmode;
54533+
54534+ if (acc_mode & MAY_APPEND)
54535+ reqmode |= GR_APPEND;
54536+ else if (acc_mode & MAY_WRITE)
54537+ reqmode |= GR_WRITE;
54538+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
54539+ reqmode |= GR_READ;
54540+
54541+ mode =
54542+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
54543+ mnt);
54544+
54545+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
54546+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
54547+ reqmode & GR_READ ? " reading" : "",
54548+ reqmode & GR_WRITE ? " writing" : reqmode &
54549+ GR_APPEND ? " appending" : "");
54550+ return reqmode;
54551+ } else
54552+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
54553+ {
54554+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
54555+ reqmode & GR_READ ? " reading" : "",
54556+ reqmode & GR_WRITE ? " writing" : reqmode &
54557+ GR_APPEND ? " appending" : "");
54558+ return 0;
54559+ } else if (unlikely((mode & reqmode) != reqmode))
54560+ return 0;
54561+
54562+ return reqmode;
54563+}
54564+
54565+__u32
54566+gr_acl_handle_creat(const struct dentry * dentry,
54567+ const struct dentry * p_dentry,
54568+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
54569+ const int imode)
54570+{
54571+ __u32 reqmode = GR_WRITE | GR_CREATE;
54572+ __u32 mode;
54573+
54574+ if (acc_mode & MAY_APPEND)
54575+ reqmode |= GR_APPEND;
54576+ // if a directory was required or the directory already exists, then
54577+ // don't count this open as a read
54578+ if ((acc_mode & MAY_READ) &&
54579+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
54580+ reqmode |= GR_READ;
54581+ if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
54582+ reqmode |= GR_SETID;
54583+
54584+ mode =
54585+ gr_check_create(dentry, p_dentry, p_mnt,
54586+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
54587+
54588+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
54589+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
54590+ reqmode & GR_READ ? " reading" : "",
54591+ reqmode & GR_WRITE ? " writing" : reqmode &
54592+ GR_APPEND ? " appending" : "");
54593+ return reqmode;
54594+ } else
54595+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
54596+ {
54597+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
54598+ reqmode & GR_READ ? " reading" : "",
54599+ reqmode & GR_WRITE ? " writing" : reqmode &
54600+ GR_APPEND ? " appending" : "");
54601+ return 0;
54602+ } else if (unlikely((mode & reqmode) != reqmode))
54603+ return 0;
54604+
54605+ return reqmode;
54606+}
54607+
54608+__u32
54609+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
54610+ const int fmode)
54611+{
54612+ __u32 mode, reqmode = GR_FIND;
54613+
54614+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
54615+ reqmode |= GR_EXEC;
54616+ if (fmode & S_IWOTH)
54617+ reqmode |= GR_WRITE;
54618+ if (fmode & S_IROTH)
54619+ reqmode |= GR_READ;
54620+
54621+ mode =
54622+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
54623+ mnt);
54624+
54625+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
54626+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
54627+ reqmode & GR_READ ? " reading" : "",
54628+ reqmode & GR_WRITE ? " writing" : "",
54629+ reqmode & GR_EXEC ? " executing" : "");
54630+ return reqmode;
54631+ } else
54632+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
54633+ {
54634+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
54635+ reqmode & GR_READ ? " reading" : "",
54636+ reqmode & GR_WRITE ? " writing" : "",
54637+ reqmode & GR_EXEC ? " executing" : "");
54638+ return 0;
54639+ } else if (unlikely((mode & reqmode) != reqmode))
54640+ return 0;
54641+
54642+ return reqmode;
54643+}
54644+
54645+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
54646+{
54647+ __u32 mode;
54648+
54649+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
54650+
54651+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
54652+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
54653+ return mode;
54654+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
54655+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
54656+ return 0;
54657+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
54658+ return 0;
54659+
54660+ return (reqmode);
54661+}
54662+
54663+__u32
54664+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
54665+{
54666+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
54667+}
54668+
54669+__u32
54670+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
54671+{
54672+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
54673+}
54674+
54675+__u32
54676+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
54677+{
54678+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
54679+}
54680+
54681+__u32
54682+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
54683+{
54684+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
54685+}
54686+
54687+__u32
54688+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
54689+ umode_t *modeptr)
54690+{
54691+ umode_t mode;
54692+
54693+ *modeptr &= ~gr_acl_umask();
54694+ mode = *modeptr;
54695+
54696+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
54697+ return 1;
54698+
54699+ if (unlikely(mode & (S_ISUID | S_ISGID))) {
54700+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
54701+ GR_CHMOD_ACL_MSG);
54702+ } else {
54703+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
54704+ }
54705+}
54706+
54707+__u32
54708+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
54709+{
54710+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
54711+}
54712+
54713+__u32
54714+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
54715+{
54716+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
54717+}
54718+
54719+__u32
54720+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
54721+{
54722+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
54723+}
54724+
54725+__u32
54726+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
54727+{
54728+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
54729+ GR_UNIXCONNECT_ACL_MSG);
54730+}
54731+
54732+/* hardlinks require at minimum create and link permission,
54733+ any additional privilege required is based on the
54734+ privilege of the file being linked to
54735+*/
54736+__u32
54737+gr_acl_handle_link(const struct dentry * new_dentry,
54738+ const struct dentry * parent_dentry,
54739+ const struct vfsmount * parent_mnt,
54740+ const struct dentry * old_dentry,
54741+ const struct vfsmount * old_mnt, const char *to)
54742+{
54743+ __u32 mode;
54744+ __u32 needmode = GR_CREATE | GR_LINK;
54745+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
54746+
54747+ mode =
54748+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
54749+ old_mnt);
54750+
54751+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
54752+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
54753+ return mode;
54754+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
54755+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
54756+ return 0;
54757+ } else if (unlikely((mode & needmode) != needmode))
54758+ return 0;
54759+
54760+ return 1;
54761+}
54762+
54763+__u32
54764+gr_acl_handle_symlink(const struct dentry * new_dentry,
54765+ const struct dentry * parent_dentry,
54766+ const struct vfsmount * parent_mnt, const char *from)
54767+{
54768+ __u32 needmode = GR_WRITE | GR_CREATE;
54769+ __u32 mode;
54770+
54771+ mode =
54772+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
54773+ GR_CREATE | GR_AUDIT_CREATE |
54774+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
54775+
54776+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
54777+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
54778+ return mode;
54779+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
54780+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
54781+ return 0;
54782+ } else if (unlikely((mode & needmode) != needmode))
54783+ return 0;
54784+
54785+ return (GR_WRITE | GR_CREATE);
54786+}
54787+
54788+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)
54789+{
54790+ __u32 mode;
54791+
54792+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
54793+
54794+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
54795+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
54796+ return mode;
54797+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
54798+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
54799+ return 0;
54800+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
54801+ return 0;
54802+
54803+ return (reqmode);
54804+}
54805+
54806+__u32
54807+gr_acl_handle_mknod(const struct dentry * new_dentry,
54808+ const struct dentry * parent_dentry,
54809+ const struct vfsmount * parent_mnt,
54810+ const int mode)
54811+{
54812+ __u32 reqmode = GR_WRITE | GR_CREATE;
54813+ if (unlikely(mode & (S_ISUID | S_ISGID)))
54814+ reqmode |= GR_SETID;
54815+
54816+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
54817+ reqmode, GR_MKNOD_ACL_MSG);
54818+}
54819+
54820+__u32
54821+gr_acl_handle_mkdir(const struct dentry *new_dentry,
54822+ const struct dentry *parent_dentry,
54823+ const struct vfsmount *parent_mnt)
54824+{
54825+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
54826+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
54827+}
54828+
54829+#define RENAME_CHECK_SUCCESS(old, new) \
54830+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
54831+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
54832+
54833+int
54834+gr_acl_handle_rename(struct dentry *new_dentry,
54835+ struct dentry *parent_dentry,
54836+ const struct vfsmount *parent_mnt,
54837+ struct dentry *old_dentry,
54838+ struct inode *old_parent_inode,
54839+ struct vfsmount *old_mnt, const char *newname)
54840+{
54841+ __u32 comp1, comp2;
54842+ int error = 0;
54843+
54844+ if (unlikely(!gr_acl_is_enabled()))
54845+ return 0;
54846+
54847+ if (!new_dentry->d_inode) {
54848+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
54849+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
54850+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
54851+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
54852+ GR_DELETE | GR_AUDIT_DELETE |
54853+ GR_AUDIT_READ | GR_AUDIT_WRITE |
54854+ GR_SUPPRESS, old_mnt);
54855+ } else {
54856+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
54857+ GR_CREATE | GR_DELETE |
54858+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
54859+ GR_AUDIT_READ | GR_AUDIT_WRITE |
54860+ GR_SUPPRESS, parent_mnt);
54861+ comp2 =
54862+ gr_search_file(old_dentry,
54863+ GR_READ | GR_WRITE | GR_AUDIT_READ |
54864+ GR_DELETE | GR_AUDIT_DELETE |
54865+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
54866+ }
54867+
54868+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
54869+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
54870+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
54871+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
54872+ && !(comp2 & GR_SUPPRESS)) {
54873+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
54874+ error = -EACCES;
54875+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
54876+ error = -EACCES;
54877+
54878+ return error;
54879+}
54880+
54881+void
54882+gr_acl_handle_exit(void)
54883+{
54884+ u16 id;
54885+ char *rolename;
54886+ struct file *exec_file;
54887+
54888+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
54889+ !(current->role->roletype & GR_ROLE_PERSIST))) {
54890+ id = current->acl_role_id;
54891+ rolename = current->role->rolename;
54892+ gr_set_acls(1);
54893+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
54894+ }
54895+
54896+ write_lock(&grsec_exec_file_lock);
54897+ exec_file = current->exec_file;
54898+ current->exec_file = NULL;
54899+ write_unlock(&grsec_exec_file_lock);
54900+
54901+ if (exec_file)
54902+ fput(exec_file);
54903+}
54904+
54905+int
54906+gr_acl_handle_procpidmem(const struct task_struct *task)
54907+{
54908+ if (unlikely(!gr_acl_is_enabled()))
54909+ return 0;
54910+
54911+ if (task != current && task->acl->mode & GR_PROTPROCFD)
54912+ return -EACCES;
54913+
54914+ return 0;
54915+}
54916diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
54917new file mode 100644
54918index 0000000..58800a7
54919--- /dev/null
54920+++ b/grsecurity/gracl_ip.c
54921@@ -0,0 +1,384 @@
54922+#include <linux/kernel.h>
54923+#include <asm/uaccess.h>
54924+#include <asm/errno.h>
54925+#include <net/sock.h>
54926+#include <linux/file.h>
54927+#include <linux/fs.h>
54928+#include <linux/net.h>
54929+#include <linux/in.h>
54930+#include <linux/skbuff.h>
54931+#include <linux/ip.h>
54932+#include <linux/udp.h>
54933+#include <linux/types.h>
54934+#include <linux/sched.h>
54935+#include <linux/netdevice.h>
54936+#include <linux/inetdevice.h>
54937+#include <linux/gracl.h>
54938+#include <linux/grsecurity.h>
54939+#include <linux/grinternal.h>
54940+
54941+#define GR_BIND 0x01
54942+#define GR_CONNECT 0x02
54943+#define GR_INVERT 0x04
54944+#define GR_BINDOVERRIDE 0x08
54945+#define GR_CONNECTOVERRIDE 0x10
54946+#define GR_SOCK_FAMILY 0x20
54947+
54948+static const char * gr_protocols[IPPROTO_MAX] = {
54949+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
54950+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
54951+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
54952+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
54953+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
54954+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
54955+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
54956+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
54957+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
54958+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
54959+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
54960+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
54961+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
54962+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
54963+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
54964+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
54965+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
54966+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
54967+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
54968+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
54969+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
54970+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
54971+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
54972+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
54973+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
54974+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
54975+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
54976+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
54977+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
54978+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
54979+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
54980+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
54981+ };
54982+
54983+static const char * gr_socktypes[SOCK_MAX] = {
54984+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
54985+ "unknown:7", "unknown:8", "unknown:9", "packet"
54986+ };
54987+
54988+static const char * gr_sockfamilies[AF_MAX+1] = {
54989+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
54990+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
54991+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
54992+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
54993+ };
54994+
54995+const char *
54996+gr_proto_to_name(unsigned char proto)
54997+{
54998+ return gr_protocols[proto];
54999+}
55000+
55001+const char *
55002+gr_socktype_to_name(unsigned char type)
55003+{
55004+ return gr_socktypes[type];
55005+}
55006+
55007+const char *
55008+gr_sockfamily_to_name(unsigned char family)
55009+{
55010+ return gr_sockfamilies[family];
55011+}
55012+
55013+int
55014+gr_search_socket(const int domain, const int type, const int protocol)
55015+{
55016+ struct acl_subject_label *curr;
55017+ const struct cred *cred = current_cred();
55018+
55019+ if (unlikely(!gr_acl_is_enabled()))
55020+ goto exit;
55021+
55022+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
55023+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
55024+ goto exit; // let the kernel handle it
55025+
55026+ curr = current->acl;
55027+
55028+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
55029+ /* the family is allowed, if this is PF_INET allow it only if
55030+ the extra sock type/protocol checks pass */
55031+ if (domain == PF_INET)
55032+ goto inet_check;
55033+ goto exit;
55034+ } else {
55035+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55036+ __u32 fakeip = 0;
55037+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55038+ current->role->roletype, cred->uid,
55039+ cred->gid, current->exec_file ?
55040+ gr_to_filename(current->exec_file->f_path.dentry,
55041+ current->exec_file->f_path.mnt) :
55042+ curr->filename, curr->filename,
55043+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
55044+ &current->signal->saved_ip);
55045+ goto exit;
55046+ }
55047+ goto exit_fail;
55048+ }
55049+
55050+inet_check:
55051+ /* the rest of this checking is for IPv4 only */
55052+ if (!curr->ips)
55053+ goto exit;
55054+
55055+ if ((curr->ip_type & (1 << type)) &&
55056+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
55057+ goto exit;
55058+
55059+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55060+ /* we don't place acls on raw sockets , and sometimes
55061+ dgram/ip sockets are opened for ioctl and not
55062+ bind/connect, so we'll fake a bind learn log */
55063+ if (type == SOCK_RAW || type == SOCK_PACKET) {
55064+ __u32 fakeip = 0;
55065+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55066+ current->role->roletype, cred->uid,
55067+ cred->gid, current->exec_file ?
55068+ gr_to_filename(current->exec_file->f_path.dentry,
55069+ current->exec_file->f_path.mnt) :
55070+ curr->filename, curr->filename,
55071+ &fakeip, 0, type,
55072+ protocol, GR_CONNECT, &current->signal->saved_ip);
55073+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
55074+ __u32 fakeip = 0;
55075+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55076+ current->role->roletype, cred->uid,
55077+ cred->gid, current->exec_file ?
55078+ gr_to_filename(current->exec_file->f_path.dentry,
55079+ current->exec_file->f_path.mnt) :
55080+ curr->filename, curr->filename,
55081+ &fakeip, 0, type,
55082+ protocol, GR_BIND, &current->signal->saved_ip);
55083+ }
55084+ /* we'll log when they use connect or bind */
55085+ goto exit;
55086+ }
55087+
55088+exit_fail:
55089+ if (domain == PF_INET)
55090+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
55091+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
55092+ else
55093+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
55094+ gr_socktype_to_name(type), protocol);
55095+
55096+ return 0;
55097+exit:
55098+ return 1;
55099+}
55100+
55101+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)
55102+{
55103+ if ((ip->mode & mode) &&
55104+ (ip_port >= ip->low) &&
55105+ (ip_port <= ip->high) &&
55106+ ((ntohl(ip_addr) & our_netmask) ==
55107+ (ntohl(our_addr) & our_netmask))
55108+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
55109+ && (ip->type & (1 << type))) {
55110+ if (ip->mode & GR_INVERT)
55111+ return 2; // specifically denied
55112+ else
55113+ return 1; // allowed
55114+ }
55115+
55116+ return 0; // not specifically allowed, may continue parsing
55117+}
55118+
55119+static int
55120+gr_search_connectbind(const int full_mode, struct sock *sk,
55121+ struct sockaddr_in *addr, const int type)
55122+{
55123+ char iface[IFNAMSIZ] = {0};
55124+ struct acl_subject_label *curr;
55125+ struct acl_ip_label *ip;
55126+ struct inet_sock *isk;
55127+ struct net_device *dev;
55128+ struct in_device *idev;
55129+ unsigned long i;
55130+ int ret;
55131+ int mode = full_mode & (GR_BIND | GR_CONNECT);
55132+ __u32 ip_addr = 0;
55133+ __u32 our_addr;
55134+ __u32 our_netmask;
55135+ char *p;
55136+ __u16 ip_port = 0;
55137+ const struct cred *cred = current_cred();
55138+
55139+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
55140+ return 0;
55141+
55142+ curr = current->acl;
55143+ isk = inet_sk(sk);
55144+
55145+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
55146+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
55147+ addr->sin_addr.s_addr = curr->inaddr_any_override;
55148+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
55149+ struct sockaddr_in saddr;
55150+ int err;
55151+
55152+ saddr.sin_family = AF_INET;
55153+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
55154+ saddr.sin_port = isk->inet_sport;
55155+
55156+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55157+ if (err)
55158+ return err;
55159+
55160+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55161+ if (err)
55162+ return err;
55163+ }
55164+
55165+ if (!curr->ips)
55166+ return 0;
55167+
55168+ ip_addr = addr->sin_addr.s_addr;
55169+ ip_port = ntohs(addr->sin_port);
55170+
55171+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55172+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55173+ current->role->roletype, cred->uid,
55174+ cred->gid, current->exec_file ?
55175+ gr_to_filename(current->exec_file->f_path.dentry,
55176+ current->exec_file->f_path.mnt) :
55177+ curr->filename, curr->filename,
55178+ &ip_addr, ip_port, type,
55179+ sk->sk_protocol, mode, &current->signal->saved_ip);
55180+ return 0;
55181+ }
55182+
55183+ for (i = 0; i < curr->ip_num; i++) {
55184+ ip = *(curr->ips + i);
55185+ if (ip->iface != NULL) {
55186+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
55187+ p = strchr(iface, ':');
55188+ if (p != NULL)
55189+ *p = '\0';
55190+ dev = dev_get_by_name(sock_net(sk), iface);
55191+ if (dev == NULL)
55192+ continue;
55193+ idev = in_dev_get(dev);
55194+ if (idev == NULL) {
55195+ dev_put(dev);
55196+ continue;
55197+ }
55198+ rcu_read_lock();
55199+ for_ifa(idev) {
55200+ if (!strcmp(ip->iface, ifa->ifa_label)) {
55201+ our_addr = ifa->ifa_address;
55202+ our_netmask = 0xffffffff;
55203+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55204+ if (ret == 1) {
55205+ rcu_read_unlock();
55206+ in_dev_put(idev);
55207+ dev_put(dev);
55208+ return 0;
55209+ } else if (ret == 2) {
55210+ rcu_read_unlock();
55211+ in_dev_put(idev);
55212+ dev_put(dev);
55213+ goto denied;
55214+ }
55215+ }
55216+ } endfor_ifa(idev);
55217+ rcu_read_unlock();
55218+ in_dev_put(idev);
55219+ dev_put(dev);
55220+ } else {
55221+ our_addr = ip->addr;
55222+ our_netmask = ip->netmask;
55223+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55224+ if (ret == 1)
55225+ return 0;
55226+ else if (ret == 2)
55227+ goto denied;
55228+ }
55229+ }
55230+
55231+denied:
55232+ if (mode == GR_BIND)
55233+ 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));
55234+ else if (mode == GR_CONNECT)
55235+ 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));
55236+
55237+ return -EACCES;
55238+}
55239+
55240+int
55241+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
55242+{
55243+ /* always allow disconnection of dgram sockets with connect */
55244+ if (addr->sin_family == AF_UNSPEC)
55245+ return 0;
55246+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
55247+}
55248+
55249+int
55250+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
55251+{
55252+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
55253+}
55254+
55255+int gr_search_listen(struct socket *sock)
55256+{
55257+ struct sock *sk = sock->sk;
55258+ struct sockaddr_in addr;
55259+
55260+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
55261+ addr.sin_port = inet_sk(sk)->inet_sport;
55262+
55263+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
55264+}
55265+
55266+int gr_search_accept(struct socket *sock)
55267+{
55268+ struct sock *sk = sock->sk;
55269+ struct sockaddr_in addr;
55270+
55271+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
55272+ addr.sin_port = inet_sk(sk)->inet_sport;
55273+
55274+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
55275+}
55276+
55277+int
55278+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
55279+{
55280+ if (addr)
55281+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
55282+ else {
55283+ struct sockaddr_in sin;
55284+ const struct inet_sock *inet = inet_sk(sk);
55285+
55286+ sin.sin_addr.s_addr = inet->inet_daddr;
55287+ sin.sin_port = inet->inet_dport;
55288+
55289+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
55290+ }
55291+}
55292+
55293+int
55294+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
55295+{
55296+ struct sockaddr_in sin;
55297+
55298+ if (unlikely(skb->len < sizeof (struct udphdr)))
55299+ return 0; // skip this packet
55300+
55301+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
55302+ sin.sin_port = udp_hdr(skb)->source;
55303+
55304+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
55305+}
55306diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
55307new file mode 100644
55308index 0000000..25f54ef
55309--- /dev/null
55310+++ b/grsecurity/gracl_learn.c
55311@@ -0,0 +1,207 @@
55312+#include <linux/kernel.h>
55313+#include <linux/mm.h>
55314+#include <linux/sched.h>
55315+#include <linux/poll.h>
55316+#include <linux/string.h>
55317+#include <linux/file.h>
55318+#include <linux/types.h>
55319+#include <linux/vmalloc.h>
55320+#include <linux/grinternal.h>
55321+
55322+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
55323+ size_t count, loff_t *ppos);
55324+extern int gr_acl_is_enabled(void);
55325+
55326+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
55327+static int gr_learn_attached;
55328+
55329+/* use a 512k buffer */
55330+#define LEARN_BUFFER_SIZE (512 * 1024)
55331+
55332+static DEFINE_SPINLOCK(gr_learn_lock);
55333+static DEFINE_MUTEX(gr_learn_user_mutex);
55334+
55335+/* we need to maintain two buffers, so that the kernel context of grlearn
55336+ uses a semaphore around the userspace copying, and the other kernel contexts
55337+ use a spinlock when copying into the buffer, since they cannot sleep
55338+*/
55339+static char *learn_buffer;
55340+static char *learn_buffer_user;
55341+static int learn_buffer_len;
55342+static int learn_buffer_user_len;
55343+
55344+static ssize_t
55345+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
55346+{
55347+ DECLARE_WAITQUEUE(wait, current);
55348+ ssize_t retval = 0;
55349+
55350+ add_wait_queue(&learn_wait, &wait);
55351+ set_current_state(TASK_INTERRUPTIBLE);
55352+ do {
55353+ mutex_lock(&gr_learn_user_mutex);
55354+ spin_lock(&gr_learn_lock);
55355+ if (learn_buffer_len)
55356+ break;
55357+ spin_unlock(&gr_learn_lock);
55358+ mutex_unlock(&gr_learn_user_mutex);
55359+ if (file->f_flags & O_NONBLOCK) {
55360+ retval = -EAGAIN;
55361+ goto out;
55362+ }
55363+ if (signal_pending(current)) {
55364+ retval = -ERESTARTSYS;
55365+ goto out;
55366+ }
55367+
55368+ schedule();
55369+ } while (1);
55370+
55371+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
55372+ learn_buffer_user_len = learn_buffer_len;
55373+ retval = learn_buffer_len;
55374+ learn_buffer_len = 0;
55375+
55376+ spin_unlock(&gr_learn_lock);
55377+
55378+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
55379+ retval = -EFAULT;
55380+
55381+ mutex_unlock(&gr_learn_user_mutex);
55382+out:
55383+ set_current_state(TASK_RUNNING);
55384+ remove_wait_queue(&learn_wait, &wait);
55385+ return retval;
55386+}
55387+
55388+static unsigned int
55389+poll_learn(struct file * file, poll_table * wait)
55390+{
55391+ poll_wait(file, &learn_wait, wait);
55392+
55393+ if (learn_buffer_len)
55394+ return (POLLIN | POLLRDNORM);
55395+
55396+ return 0;
55397+}
55398+
55399+void
55400+gr_clear_learn_entries(void)
55401+{
55402+ char *tmp;
55403+
55404+ mutex_lock(&gr_learn_user_mutex);
55405+ spin_lock(&gr_learn_lock);
55406+ tmp = learn_buffer;
55407+ learn_buffer = NULL;
55408+ spin_unlock(&gr_learn_lock);
55409+ if (tmp)
55410+ vfree(tmp);
55411+ if (learn_buffer_user != NULL) {
55412+ vfree(learn_buffer_user);
55413+ learn_buffer_user = NULL;
55414+ }
55415+ learn_buffer_len = 0;
55416+ mutex_unlock(&gr_learn_user_mutex);
55417+
55418+ return;
55419+}
55420+
55421+void
55422+gr_add_learn_entry(const char *fmt, ...)
55423+{
55424+ va_list args;
55425+ unsigned int len;
55426+
55427+ if (!gr_learn_attached)
55428+ return;
55429+
55430+ spin_lock(&gr_learn_lock);
55431+
55432+ /* leave a gap at the end so we know when it's "full" but don't have to
55433+ compute the exact length of the string we're trying to append
55434+ */
55435+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
55436+ spin_unlock(&gr_learn_lock);
55437+ wake_up_interruptible(&learn_wait);
55438+ return;
55439+ }
55440+ if (learn_buffer == NULL) {
55441+ spin_unlock(&gr_learn_lock);
55442+ return;
55443+ }
55444+
55445+ va_start(args, fmt);
55446+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
55447+ va_end(args);
55448+
55449+ learn_buffer_len += len + 1;
55450+
55451+ spin_unlock(&gr_learn_lock);
55452+ wake_up_interruptible(&learn_wait);
55453+
55454+ return;
55455+}
55456+
55457+static int
55458+open_learn(struct inode *inode, struct file *file)
55459+{
55460+ if (file->f_mode & FMODE_READ && gr_learn_attached)
55461+ return -EBUSY;
55462+ if (file->f_mode & FMODE_READ) {
55463+ int retval = 0;
55464+ mutex_lock(&gr_learn_user_mutex);
55465+ if (learn_buffer == NULL)
55466+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
55467+ if (learn_buffer_user == NULL)
55468+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
55469+ if (learn_buffer == NULL) {
55470+ retval = -ENOMEM;
55471+ goto out_error;
55472+ }
55473+ if (learn_buffer_user == NULL) {
55474+ retval = -ENOMEM;
55475+ goto out_error;
55476+ }
55477+ learn_buffer_len = 0;
55478+ learn_buffer_user_len = 0;
55479+ gr_learn_attached = 1;
55480+out_error:
55481+ mutex_unlock(&gr_learn_user_mutex);
55482+ return retval;
55483+ }
55484+ return 0;
55485+}
55486+
55487+static int
55488+close_learn(struct inode *inode, struct file *file)
55489+{
55490+ if (file->f_mode & FMODE_READ) {
55491+ char *tmp = NULL;
55492+ mutex_lock(&gr_learn_user_mutex);
55493+ spin_lock(&gr_learn_lock);
55494+ tmp = learn_buffer;
55495+ learn_buffer = NULL;
55496+ spin_unlock(&gr_learn_lock);
55497+ if (tmp)
55498+ vfree(tmp);
55499+ if (learn_buffer_user != NULL) {
55500+ vfree(learn_buffer_user);
55501+ learn_buffer_user = NULL;
55502+ }
55503+ learn_buffer_len = 0;
55504+ learn_buffer_user_len = 0;
55505+ gr_learn_attached = 0;
55506+ mutex_unlock(&gr_learn_user_mutex);
55507+ }
55508+
55509+ return 0;
55510+}
55511+
55512+const struct file_operations grsec_fops = {
55513+ .read = read_learn,
55514+ .write = write_grsec_handler,
55515+ .open = open_learn,
55516+ .release = close_learn,
55517+ .poll = poll_learn,
55518+};
55519diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
55520new file mode 100644
55521index 0000000..39645c9
55522--- /dev/null
55523+++ b/grsecurity/gracl_res.c
55524@@ -0,0 +1,68 @@
55525+#include <linux/kernel.h>
55526+#include <linux/sched.h>
55527+#include <linux/gracl.h>
55528+#include <linux/grinternal.h>
55529+
55530+static const char *restab_log[] = {
55531+ [RLIMIT_CPU] = "RLIMIT_CPU",
55532+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
55533+ [RLIMIT_DATA] = "RLIMIT_DATA",
55534+ [RLIMIT_STACK] = "RLIMIT_STACK",
55535+ [RLIMIT_CORE] = "RLIMIT_CORE",
55536+ [RLIMIT_RSS] = "RLIMIT_RSS",
55537+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
55538+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
55539+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
55540+ [RLIMIT_AS] = "RLIMIT_AS",
55541+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
55542+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
55543+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
55544+ [RLIMIT_NICE] = "RLIMIT_NICE",
55545+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
55546+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
55547+ [GR_CRASH_RES] = "RLIMIT_CRASH"
55548+};
55549+
55550+void
55551+gr_log_resource(const struct task_struct *task,
55552+ const int res, const unsigned long wanted, const int gt)
55553+{
55554+ const struct cred *cred;
55555+ unsigned long rlim;
55556+
55557+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
55558+ return;
55559+
55560+ // not yet supported resource
55561+ if (unlikely(!restab_log[res]))
55562+ return;
55563+
55564+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
55565+ rlim = task_rlimit_max(task, res);
55566+ else
55567+ rlim = task_rlimit(task, res);
55568+
55569+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
55570+ return;
55571+
55572+ rcu_read_lock();
55573+ cred = __task_cred(task);
55574+
55575+ if (res == RLIMIT_NPROC &&
55576+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
55577+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
55578+ goto out_rcu_unlock;
55579+ else if (res == RLIMIT_MEMLOCK &&
55580+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
55581+ goto out_rcu_unlock;
55582+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
55583+ goto out_rcu_unlock;
55584+ rcu_read_unlock();
55585+
55586+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
55587+
55588+ return;
55589+out_rcu_unlock:
55590+ rcu_read_unlock();
55591+ return;
55592+}
55593diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
55594new file mode 100644
55595index 0000000..5556be3
55596--- /dev/null
55597+++ b/grsecurity/gracl_segv.c
55598@@ -0,0 +1,299 @@
55599+#include <linux/kernel.h>
55600+#include <linux/mm.h>
55601+#include <asm/uaccess.h>
55602+#include <asm/errno.h>
55603+#include <asm/mman.h>
55604+#include <net/sock.h>
55605+#include <linux/file.h>
55606+#include <linux/fs.h>
55607+#include <linux/net.h>
55608+#include <linux/in.h>
55609+#include <linux/slab.h>
55610+#include <linux/types.h>
55611+#include <linux/sched.h>
55612+#include <linux/timer.h>
55613+#include <linux/gracl.h>
55614+#include <linux/grsecurity.h>
55615+#include <linux/grinternal.h>
55616+
55617+static struct crash_uid *uid_set;
55618+static unsigned short uid_used;
55619+static DEFINE_SPINLOCK(gr_uid_lock);
55620+extern rwlock_t gr_inode_lock;
55621+extern struct acl_subject_label *
55622+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
55623+ struct acl_role_label *role);
55624+
55625+#ifdef CONFIG_BTRFS_FS
55626+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
55627+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
55628+#endif
55629+
55630+static inline dev_t __get_dev(const struct dentry *dentry)
55631+{
55632+#ifdef CONFIG_BTRFS_FS
55633+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
55634+ return get_btrfs_dev_from_inode(dentry->d_inode);
55635+ else
55636+#endif
55637+ return dentry->d_inode->i_sb->s_dev;
55638+}
55639+
55640+int
55641+gr_init_uidset(void)
55642+{
55643+ uid_set =
55644+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
55645+ uid_used = 0;
55646+
55647+ return uid_set ? 1 : 0;
55648+}
55649+
55650+void
55651+gr_free_uidset(void)
55652+{
55653+ if (uid_set)
55654+ kfree(uid_set);
55655+
55656+ return;
55657+}
55658+
55659+int
55660+gr_find_uid(const uid_t uid)
55661+{
55662+ struct crash_uid *tmp = uid_set;
55663+ uid_t buid;
55664+ int low = 0, high = uid_used - 1, mid;
55665+
55666+ while (high >= low) {
55667+ mid = (low + high) >> 1;
55668+ buid = tmp[mid].uid;
55669+ if (buid == uid)
55670+ return mid;
55671+ if (buid > uid)
55672+ high = mid - 1;
55673+ if (buid < uid)
55674+ low = mid + 1;
55675+ }
55676+
55677+ return -1;
55678+}
55679+
55680+static __inline__ void
55681+gr_insertsort(void)
55682+{
55683+ unsigned short i, j;
55684+ struct crash_uid index;
55685+
55686+ for (i = 1; i < uid_used; i++) {
55687+ index = uid_set[i];
55688+ j = i;
55689+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
55690+ uid_set[j] = uid_set[j - 1];
55691+ j--;
55692+ }
55693+ uid_set[j] = index;
55694+ }
55695+
55696+ return;
55697+}
55698+
55699+static __inline__ void
55700+gr_insert_uid(const uid_t uid, const unsigned long expires)
55701+{
55702+ int loc;
55703+
55704+ if (uid_used == GR_UIDTABLE_MAX)
55705+ return;
55706+
55707+ loc = gr_find_uid(uid);
55708+
55709+ if (loc >= 0) {
55710+ uid_set[loc].expires = expires;
55711+ return;
55712+ }
55713+
55714+ uid_set[uid_used].uid = uid;
55715+ uid_set[uid_used].expires = expires;
55716+ uid_used++;
55717+
55718+ gr_insertsort();
55719+
55720+ return;
55721+}
55722+
55723+void
55724+gr_remove_uid(const unsigned short loc)
55725+{
55726+ unsigned short i;
55727+
55728+ for (i = loc + 1; i < uid_used; i++)
55729+ uid_set[i - 1] = uid_set[i];
55730+
55731+ uid_used--;
55732+
55733+ return;
55734+}
55735+
55736+int
55737+gr_check_crash_uid(const uid_t uid)
55738+{
55739+ int loc;
55740+ int ret = 0;
55741+
55742+ if (unlikely(!gr_acl_is_enabled()))
55743+ return 0;
55744+
55745+ spin_lock(&gr_uid_lock);
55746+ loc = gr_find_uid(uid);
55747+
55748+ if (loc < 0)
55749+ goto out_unlock;
55750+
55751+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
55752+ gr_remove_uid(loc);
55753+ else
55754+ ret = 1;
55755+
55756+out_unlock:
55757+ spin_unlock(&gr_uid_lock);
55758+ return ret;
55759+}
55760+
55761+static __inline__ int
55762+proc_is_setxid(const struct cred *cred)
55763+{
55764+ if (cred->uid != cred->euid || cred->uid != cred->suid ||
55765+ cred->uid != cred->fsuid)
55766+ return 1;
55767+ if (cred->gid != cred->egid || cred->gid != cred->sgid ||
55768+ cred->gid != cred->fsgid)
55769+ return 1;
55770+
55771+ return 0;
55772+}
55773+
55774+extern int gr_fake_force_sig(int sig, struct task_struct *t);
55775+
55776+void
55777+gr_handle_crash(struct task_struct *task, const int sig)
55778+{
55779+ struct acl_subject_label *curr;
55780+ struct task_struct *tsk, *tsk2;
55781+ const struct cred *cred;
55782+ const struct cred *cred2;
55783+
55784+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
55785+ return;
55786+
55787+ if (unlikely(!gr_acl_is_enabled()))
55788+ return;
55789+
55790+ curr = task->acl;
55791+
55792+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
55793+ return;
55794+
55795+ if (time_before_eq(curr->expires, get_seconds())) {
55796+ curr->expires = 0;
55797+ curr->crashes = 0;
55798+ }
55799+
55800+ curr->crashes++;
55801+
55802+ if (!curr->expires)
55803+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
55804+
55805+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
55806+ time_after(curr->expires, get_seconds())) {
55807+ rcu_read_lock();
55808+ cred = __task_cred(task);
55809+ if (cred->uid && proc_is_setxid(cred)) {
55810+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
55811+ spin_lock(&gr_uid_lock);
55812+ gr_insert_uid(cred->uid, curr->expires);
55813+ spin_unlock(&gr_uid_lock);
55814+ curr->expires = 0;
55815+ curr->crashes = 0;
55816+ read_lock(&tasklist_lock);
55817+ do_each_thread(tsk2, tsk) {
55818+ cred2 = __task_cred(tsk);
55819+ if (tsk != task && cred2->uid == cred->uid)
55820+ gr_fake_force_sig(SIGKILL, tsk);
55821+ } while_each_thread(tsk2, tsk);
55822+ read_unlock(&tasklist_lock);
55823+ } else {
55824+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
55825+ read_lock(&tasklist_lock);
55826+ read_lock(&grsec_exec_file_lock);
55827+ do_each_thread(tsk2, tsk) {
55828+ if (likely(tsk != task)) {
55829+ // if this thread has the same subject as the one that triggered
55830+ // RES_CRASH and it's the same binary, kill it
55831+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
55832+ gr_fake_force_sig(SIGKILL, tsk);
55833+ }
55834+ } while_each_thread(tsk2, tsk);
55835+ read_unlock(&grsec_exec_file_lock);
55836+ read_unlock(&tasklist_lock);
55837+ }
55838+ rcu_read_unlock();
55839+ }
55840+
55841+ return;
55842+}
55843+
55844+int
55845+gr_check_crash_exec(const struct file *filp)
55846+{
55847+ struct acl_subject_label *curr;
55848+
55849+ if (unlikely(!gr_acl_is_enabled()))
55850+ return 0;
55851+
55852+ read_lock(&gr_inode_lock);
55853+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
55854+ __get_dev(filp->f_path.dentry),
55855+ current->role);
55856+ read_unlock(&gr_inode_lock);
55857+
55858+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
55859+ (!curr->crashes && !curr->expires))
55860+ return 0;
55861+
55862+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
55863+ time_after(curr->expires, get_seconds()))
55864+ return 1;
55865+ else if (time_before_eq(curr->expires, get_seconds())) {
55866+ curr->crashes = 0;
55867+ curr->expires = 0;
55868+ }
55869+
55870+ return 0;
55871+}
55872+
55873+void
55874+gr_handle_alertkill(struct task_struct *task)
55875+{
55876+ struct acl_subject_label *curracl;
55877+ __u32 curr_ip;
55878+ struct task_struct *p, *p2;
55879+
55880+ if (unlikely(!gr_acl_is_enabled()))
55881+ return;
55882+
55883+ curracl = task->acl;
55884+ curr_ip = task->signal->curr_ip;
55885+
55886+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
55887+ read_lock(&tasklist_lock);
55888+ do_each_thread(p2, p) {
55889+ if (p->signal->curr_ip == curr_ip)
55890+ gr_fake_force_sig(SIGKILL, p);
55891+ } while_each_thread(p2, p);
55892+ read_unlock(&tasklist_lock);
55893+ } else if (curracl->mode & GR_KILLPROC)
55894+ gr_fake_force_sig(SIGKILL, task);
55895+
55896+ return;
55897+}
55898diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
55899new file mode 100644
55900index 0000000..9d83a69
55901--- /dev/null
55902+++ b/grsecurity/gracl_shm.c
55903@@ -0,0 +1,40 @@
55904+#include <linux/kernel.h>
55905+#include <linux/mm.h>
55906+#include <linux/sched.h>
55907+#include <linux/file.h>
55908+#include <linux/ipc.h>
55909+#include <linux/gracl.h>
55910+#include <linux/grsecurity.h>
55911+#include <linux/grinternal.h>
55912+
55913+int
55914+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
55915+ const time_t shm_createtime, const uid_t cuid, const int shmid)
55916+{
55917+ struct task_struct *task;
55918+
55919+ if (!gr_acl_is_enabled())
55920+ return 1;
55921+
55922+ rcu_read_lock();
55923+ read_lock(&tasklist_lock);
55924+
55925+ task = find_task_by_vpid(shm_cprid);
55926+
55927+ if (unlikely(!task))
55928+ task = find_task_by_vpid(shm_lapid);
55929+
55930+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
55931+ (task->pid == shm_lapid)) &&
55932+ (task->acl->mode & GR_PROTSHM) &&
55933+ (task->acl != current->acl))) {
55934+ read_unlock(&tasklist_lock);
55935+ rcu_read_unlock();
55936+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
55937+ return 0;
55938+ }
55939+ read_unlock(&tasklist_lock);
55940+ rcu_read_unlock();
55941+
55942+ return 1;
55943+}
55944diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
55945new file mode 100644
55946index 0000000..bc0be01
55947--- /dev/null
55948+++ b/grsecurity/grsec_chdir.c
55949@@ -0,0 +1,19 @@
55950+#include <linux/kernel.h>
55951+#include <linux/sched.h>
55952+#include <linux/fs.h>
55953+#include <linux/file.h>
55954+#include <linux/grsecurity.h>
55955+#include <linux/grinternal.h>
55956+
55957+void
55958+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
55959+{
55960+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
55961+ if ((grsec_enable_chdir && grsec_enable_group &&
55962+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
55963+ !grsec_enable_group)) {
55964+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
55965+ }
55966+#endif
55967+ return;
55968+}
55969diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
55970new file mode 100644
55971index 0000000..9807ee2
55972--- /dev/null
55973+++ b/grsecurity/grsec_chroot.c
55974@@ -0,0 +1,368 @@
55975+#include <linux/kernel.h>
55976+#include <linux/module.h>
55977+#include <linux/sched.h>
55978+#include <linux/file.h>
55979+#include <linux/fs.h>
55980+#include <linux/mount.h>
55981+#include <linux/types.h>
55982+#include "../fs/mount.h"
55983+#include <linux/grsecurity.h>
55984+#include <linux/grinternal.h>
55985+
55986+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
55987+{
55988+#ifdef CONFIG_GRKERNSEC
55989+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
55990+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
55991+ task->gr_is_chrooted = 1;
55992+ else
55993+ task->gr_is_chrooted = 0;
55994+
55995+ task->gr_chroot_dentry = path->dentry;
55996+#endif
55997+ return;
55998+}
55999+
56000+void gr_clear_chroot_entries(struct task_struct *task)
56001+{
56002+#ifdef CONFIG_GRKERNSEC
56003+ task->gr_is_chrooted = 0;
56004+ task->gr_chroot_dentry = NULL;
56005+#endif
56006+ return;
56007+}
56008+
56009+int
56010+gr_handle_chroot_unix(const pid_t pid)
56011+{
56012+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
56013+ struct task_struct *p;
56014+
56015+ if (unlikely(!grsec_enable_chroot_unix))
56016+ return 1;
56017+
56018+ if (likely(!proc_is_chrooted(current)))
56019+ return 1;
56020+
56021+ rcu_read_lock();
56022+ read_lock(&tasklist_lock);
56023+ p = find_task_by_vpid_unrestricted(pid);
56024+ if (unlikely(p && !have_same_root(current, p))) {
56025+ read_unlock(&tasklist_lock);
56026+ rcu_read_unlock();
56027+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
56028+ return 0;
56029+ }
56030+ read_unlock(&tasklist_lock);
56031+ rcu_read_unlock();
56032+#endif
56033+ return 1;
56034+}
56035+
56036+int
56037+gr_handle_chroot_nice(void)
56038+{
56039+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56040+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
56041+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
56042+ return -EPERM;
56043+ }
56044+#endif
56045+ return 0;
56046+}
56047+
56048+int
56049+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
56050+{
56051+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56052+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
56053+ && proc_is_chrooted(current)) {
56054+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
56055+ return -EACCES;
56056+ }
56057+#endif
56058+ return 0;
56059+}
56060+
56061+int
56062+gr_handle_chroot_rawio(const struct inode *inode)
56063+{
56064+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56065+ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
56066+ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
56067+ return 1;
56068+#endif
56069+ return 0;
56070+}
56071+
56072+int
56073+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
56074+{
56075+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56076+ struct task_struct *p;
56077+ int ret = 0;
56078+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
56079+ return ret;
56080+
56081+ read_lock(&tasklist_lock);
56082+ do_each_pid_task(pid, type, p) {
56083+ if (!have_same_root(current, p)) {
56084+ ret = 1;
56085+ goto out;
56086+ }
56087+ } while_each_pid_task(pid, type, p);
56088+out:
56089+ read_unlock(&tasklist_lock);
56090+ return ret;
56091+#endif
56092+ return 0;
56093+}
56094+
56095+int
56096+gr_pid_is_chrooted(struct task_struct *p)
56097+{
56098+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56099+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
56100+ return 0;
56101+
56102+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
56103+ !have_same_root(current, p)) {
56104+ return 1;
56105+ }
56106+#endif
56107+ return 0;
56108+}
56109+
56110+EXPORT_SYMBOL(gr_pid_is_chrooted);
56111+
56112+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
56113+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
56114+{
56115+ struct path path, currentroot;
56116+ int ret = 0;
56117+
56118+ path.dentry = (struct dentry *)u_dentry;
56119+ path.mnt = (struct vfsmount *)u_mnt;
56120+ get_fs_root(current->fs, &currentroot);
56121+ if (path_is_under(&path, &currentroot))
56122+ ret = 1;
56123+ path_put(&currentroot);
56124+
56125+ return ret;
56126+}
56127+#endif
56128+
56129+int
56130+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
56131+{
56132+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
56133+ if (!grsec_enable_chroot_fchdir)
56134+ return 1;
56135+
56136+ if (!proc_is_chrooted(current))
56137+ return 1;
56138+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
56139+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
56140+ return 0;
56141+ }
56142+#endif
56143+ return 1;
56144+}
56145+
56146+int
56147+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56148+ const time_t shm_createtime)
56149+{
56150+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
56151+ struct task_struct *p;
56152+ time_t starttime;
56153+
56154+ if (unlikely(!grsec_enable_chroot_shmat))
56155+ return 1;
56156+
56157+ if (likely(!proc_is_chrooted(current)))
56158+ return 1;
56159+
56160+ rcu_read_lock();
56161+ read_lock(&tasklist_lock);
56162+
56163+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
56164+ starttime = p->start_time.tv_sec;
56165+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
56166+ if (have_same_root(current, p)) {
56167+ goto allow;
56168+ } else {
56169+ read_unlock(&tasklist_lock);
56170+ rcu_read_unlock();
56171+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56172+ return 0;
56173+ }
56174+ }
56175+ /* creator exited, pid reuse, fall through to next check */
56176+ }
56177+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
56178+ if (unlikely(!have_same_root(current, p))) {
56179+ read_unlock(&tasklist_lock);
56180+ rcu_read_unlock();
56181+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56182+ return 0;
56183+ }
56184+ }
56185+
56186+allow:
56187+ read_unlock(&tasklist_lock);
56188+ rcu_read_unlock();
56189+#endif
56190+ return 1;
56191+}
56192+
56193+void
56194+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
56195+{
56196+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
56197+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
56198+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
56199+#endif
56200+ return;
56201+}
56202+
56203+int
56204+gr_handle_chroot_mknod(const struct dentry *dentry,
56205+ const struct vfsmount *mnt, const int mode)
56206+{
56207+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
56208+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
56209+ proc_is_chrooted(current)) {
56210+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
56211+ return -EPERM;
56212+ }
56213+#endif
56214+ return 0;
56215+}
56216+
56217+int
56218+gr_handle_chroot_mount(const struct dentry *dentry,
56219+ const struct vfsmount *mnt, const char *dev_name)
56220+{
56221+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
56222+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
56223+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
56224+ return -EPERM;
56225+ }
56226+#endif
56227+ return 0;
56228+}
56229+
56230+int
56231+gr_handle_chroot_pivot(void)
56232+{
56233+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
56234+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
56235+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
56236+ return -EPERM;
56237+ }
56238+#endif
56239+ return 0;
56240+}
56241+
56242+int
56243+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
56244+{
56245+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
56246+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
56247+ !gr_is_outside_chroot(dentry, mnt)) {
56248+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
56249+ return -EPERM;
56250+ }
56251+#endif
56252+ return 0;
56253+}
56254+
56255+extern const char *captab_log[];
56256+extern int captab_log_entries;
56257+
56258+int
56259+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
56260+{
56261+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56262+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
56263+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
56264+ if (cap_raised(chroot_caps, cap)) {
56265+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
56266+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
56267+ }
56268+ return 0;
56269+ }
56270+ }
56271+#endif
56272+ return 1;
56273+}
56274+
56275+int
56276+gr_chroot_is_capable(const int cap)
56277+{
56278+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56279+ return gr_task_chroot_is_capable(current, current_cred(), cap);
56280+#endif
56281+ return 1;
56282+}
56283+
56284+int
56285+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
56286+{
56287+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56288+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
56289+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
56290+ if (cap_raised(chroot_caps, cap)) {
56291+ return 0;
56292+ }
56293+ }
56294+#endif
56295+ return 1;
56296+}
56297+
56298+int
56299+gr_chroot_is_capable_nolog(const int cap)
56300+{
56301+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56302+ return gr_task_chroot_is_capable_nolog(current, cap);
56303+#endif
56304+ return 1;
56305+}
56306+
56307+int
56308+gr_handle_chroot_sysctl(const int op)
56309+{
56310+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
56311+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
56312+ proc_is_chrooted(current))
56313+ return -EACCES;
56314+#endif
56315+ return 0;
56316+}
56317+
56318+void
56319+gr_handle_chroot_chdir(struct path *path)
56320+{
56321+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
56322+ if (grsec_enable_chroot_chdir)
56323+ set_fs_pwd(current->fs, path);
56324+#endif
56325+ return;
56326+}
56327+
56328+int
56329+gr_handle_chroot_chmod(const struct dentry *dentry,
56330+ const struct vfsmount *mnt, const int mode)
56331+{
56332+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
56333+ /* allow chmod +s on directories, but not files */
56334+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
56335+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
56336+ proc_is_chrooted(current)) {
56337+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
56338+ return -EPERM;
56339+ }
56340+#endif
56341+ return 0;
56342+}
56343diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
56344new file mode 100644
56345index 0000000..213ad8b
56346--- /dev/null
56347+++ b/grsecurity/grsec_disabled.c
56348@@ -0,0 +1,437 @@
56349+#include <linux/kernel.h>
56350+#include <linux/module.h>
56351+#include <linux/sched.h>
56352+#include <linux/file.h>
56353+#include <linux/fs.h>
56354+#include <linux/kdev_t.h>
56355+#include <linux/net.h>
56356+#include <linux/in.h>
56357+#include <linux/ip.h>
56358+#include <linux/skbuff.h>
56359+#include <linux/sysctl.h>
56360+
56361+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56362+void
56363+pax_set_initial_flags(struct linux_binprm *bprm)
56364+{
56365+ return;
56366+}
56367+#endif
56368+
56369+#ifdef CONFIG_SYSCTL
56370+__u32
56371+gr_handle_sysctl(const struct ctl_table * table, const int op)
56372+{
56373+ return 0;
56374+}
56375+#endif
56376+
56377+#ifdef CONFIG_TASKSTATS
56378+int gr_is_taskstats_denied(int pid)
56379+{
56380+ return 0;
56381+}
56382+#endif
56383+
56384+int
56385+gr_acl_is_enabled(void)
56386+{
56387+ return 0;
56388+}
56389+
56390+void
56391+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
56392+{
56393+ return;
56394+}
56395+
56396+int
56397+gr_handle_rawio(const struct inode *inode)
56398+{
56399+ return 0;
56400+}
56401+
56402+void
56403+gr_acl_handle_psacct(struct task_struct *task, const long code)
56404+{
56405+ return;
56406+}
56407+
56408+int
56409+gr_handle_ptrace(struct task_struct *task, const long request)
56410+{
56411+ return 0;
56412+}
56413+
56414+int
56415+gr_handle_proc_ptrace(struct task_struct *task)
56416+{
56417+ return 0;
56418+}
56419+
56420+void
56421+gr_learn_resource(const struct task_struct *task,
56422+ const int res, const unsigned long wanted, const int gt)
56423+{
56424+ return;
56425+}
56426+
56427+int
56428+gr_set_acls(const int type)
56429+{
56430+ return 0;
56431+}
56432+
56433+int
56434+gr_check_hidden_task(const struct task_struct *tsk)
56435+{
56436+ return 0;
56437+}
56438+
56439+int
56440+gr_check_protected_task(const struct task_struct *task)
56441+{
56442+ return 0;
56443+}
56444+
56445+int
56446+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
56447+{
56448+ return 0;
56449+}
56450+
56451+void
56452+gr_copy_label(struct task_struct *tsk)
56453+{
56454+ return;
56455+}
56456+
56457+void
56458+gr_set_pax_flags(struct task_struct *task)
56459+{
56460+ return;
56461+}
56462+
56463+int
56464+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
56465+ const int unsafe_share)
56466+{
56467+ return 0;
56468+}
56469+
56470+void
56471+gr_handle_delete(const ino_t ino, const dev_t dev)
56472+{
56473+ return;
56474+}
56475+
56476+void
56477+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
56478+{
56479+ return;
56480+}
56481+
56482+void
56483+gr_handle_crash(struct task_struct *task, const int sig)
56484+{
56485+ return;
56486+}
56487+
56488+int
56489+gr_check_crash_exec(const struct file *filp)
56490+{
56491+ return 0;
56492+}
56493+
56494+int
56495+gr_check_crash_uid(const uid_t uid)
56496+{
56497+ return 0;
56498+}
56499+
56500+void
56501+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
56502+ struct dentry *old_dentry,
56503+ struct dentry *new_dentry,
56504+ struct vfsmount *mnt, const __u8 replace)
56505+{
56506+ return;
56507+}
56508+
56509+int
56510+gr_search_socket(const int family, const int type, const int protocol)
56511+{
56512+ return 1;
56513+}
56514+
56515+int
56516+gr_search_connectbind(const int mode, const struct socket *sock,
56517+ const struct sockaddr_in *addr)
56518+{
56519+ return 0;
56520+}
56521+
56522+void
56523+gr_handle_alertkill(struct task_struct *task)
56524+{
56525+ return;
56526+}
56527+
56528+__u32
56529+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
56530+{
56531+ return 1;
56532+}
56533+
56534+__u32
56535+gr_acl_handle_hidden_file(const struct dentry * dentry,
56536+ const struct vfsmount * mnt)
56537+{
56538+ return 1;
56539+}
56540+
56541+__u32
56542+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
56543+ int acc_mode)
56544+{
56545+ return 1;
56546+}
56547+
56548+__u32
56549+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
56550+{
56551+ return 1;
56552+}
56553+
56554+__u32
56555+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
56556+{
56557+ return 1;
56558+}
56559+
56560+int
56561+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
56562+ unsigned int *vm_flags)
56563+{
56564+ return 1;
56565+}
56566+
56567+__u32
56568+gr_acl_handle_truncate(const struct dentry * dentry,
56569+ const struct vfsmount * mnt)
56570+{
56571+ return 1;
56572+}
56573+
56574+__u32
56575+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
56576+{
56577+ return 1;
56578+}
56579+
56580+__u32
56581+gr_acl_handle_access(const struct dentry * dentry,
56582+ const struct vfsmount * mnt, const int fmode)
56583+{
56584+ return 1;
56585+}
56586+
56587+__u32
56588+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
56589+ umode_t *mode)
56590+{
56591+ return 1;
56592+}
56593+
56594+__u32
56595+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
56596+{
56597+ return 1;
56598+}
56599+
56600+__u32
56601+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
56602+{
56603+ return 1;
56604+}
56605+
56606+void
56607+grsecurity_init(void)
56608+{
56609+ return;
56610+}
56611+
56612+umode_t gr_acl_umask(void)
56613+{
56614+ return 0;
56615+}
56616+
56617+__u32
56618+gr_acl_handle_mknod(const struct dentry * new_dentry,
56619+ const struct dentry * parent_dentry,
56620+ const struct vfsmount * parent_mnt,
56621+ const int mode)
56622+{
56623+ return 1;
56624+}
56625+
56626+__u32
56627+gr_acl_handle_mkdir(const struct dentry * new_dentry,
56628+ const struct dentry * parent_dentry,
56629+ const struct vfsmount * parent_mnt)
56630+{
56631+ return 1;
56632+}
56633+
56634+__u32
56635+gr_acl_handle_symlink(const struct dentry * new_dentry,
56636+ const struct dentry * parent_dentry,
56637+ const struct vfsmount * parent_mnt, const char *from)
56638+{
56639+ return 1;
56640+}
56641+
56642+__u32
56643+gr_acl_handle_link(const struct dentry * new_dentry,
56644+ const struct dentry * parent_dentry,
56645+ const struct vfsmount * parent_mnt,
56646+ const struct dentry * old_dentry,
56647+ const struct vfsmount * old_mnt, const char *to)
56648+{
56649+ return 1;
56650+}
56651+
56652+int
56653+gr_acl_handle_rename(const struct dentry *new_dentry,
56654+ const struct dentry *parent_dentry,
56655+ const struct vfsmount *parent_mnt,
56656+ const struct dentry *old_dentry,
56657+ const struct inode *old_parent_inode,
56658+ const struct vfsmount *old_mnt, const char *newname)
56659+{
56660+ return 0;
56661+}
56662+
56663+int
56664+gr_acl_handle_filldir(const struct file *file, const char *name,
56665+ const int namelen, const ino_t ino)
56666+{
56667+ return 1;
56668+}
56669+
56670+int
56671+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56672+ const time_t shm_createtime, const uid_t cuid, const int shmid)
56673+{
56674+ return 1;
56675+}
56676+
56677+int
56678+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
56679+{
56680+ return 0;
56681+}
56682+
56683+int
56684+gr_search_accept(const struct socket *sock)
56685+{
56686+ return 0;
56687+}
56688+
56689+int
56690+gr_search_listen(const struct socket *sock)
56691+{
56692+ return 0;
56693+}
56694+
56695+int
56696+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
56697+{
56698+ return 0;
56699+}
56700+
56701+__u32
56702+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
56703+{
56704+ return 1;
56705+}
56706+
56707+__u32
56708+gr_acl_handle_creat(const struct dentry * dentry,
56709+ const struct dentry * p_dentry,
56710+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
56711+ const int imode)
56712+{
56713+ return 1;
56714+}
56715+
56716+void
56717+gr_acl_handle_exit(void)
56718+{
56719+ return;
56720+}
56721+
56722+int
56723+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
56724+{
56725+ return 1;
56726+}
56727+
56728+void
56729+gr_set_role_label(const uid_t uid, const gid_t gid)
56730+{
56731+ return;
56732+}
56733+
56734+int
56735+gr_acl_handle_procpidmem(const struct task_struct *task)
56736+{
56737+ return 0;
56738+}
56739+
56740+int
56741+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
56742+{
56743+ return 0;
56744+}
56745+
56746+int
56747+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
56748+{
56749+ return 0;
56750+}
56751+
56752+void
56753+gr_set_kernel_label(struct task_struct *task)
56754+{
56755+ return;
56756+}
56757+
56758+int
56759+gr_check_user_change(int real, int effective, int fs)
56760+{
56761+ return 0;
56762+}
56763+
56764+int
56765+gr_check_group_change(int real, int effective, int fs)
56766+{
56767+ return 0;
56768+}
56769+
56770+int gr_acl_enable_at_secure(void)
56771+{
56772+ return 0;
56773+}
56774+
56775+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
56776+{
56777+ return dentry->d_inode->i_sb->s_dev;
56778+}
56779+
56780+EXPORT_SYMBOL(gr_learn_resource);
56781+EXPORT_SYMBOL(gr_set_kernel_label);
56782+#ifdef CONFIG_SECURITY
56783+EXPORT_SYMBOL(gr_check_user_change);
56784+EXPORT_SYMBOL(gr_check_group_change);
56785+#endif
56786diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
56787new file mode 100644
56788index 0000000..abfa971
56789--- /dev/null
56790+++ b/grsecurity/grsec_exec.c
56791@@ -0,0 +1,174 @@
56792+#include <linux/kernel.h>
56793+#include <linux/sched.h>
56794+#include <linux/file.h>
56795+#include <linux/binfmts.h>
56796+#include <linux/fs.h>
56797+#include <linux/types.h>
56798+#include <linux/grdefs.h>
56799+#include <linux/grsecurity.h>
56800+#include <linux/grinternal.h>
56801+#include <linux/capability.h>
56802+#include <linux/module.h>
56803+
56804+#include <asm/uaccess.h>
56805+
56806+#ifdef CONFIG_GRKERNSEC_EXECLOG
56807+static char gr_exec_arg_buf[132];
56808+static DEFINE_MUTEX(gr_exec_arg_mutex);
56809+#endif
56810+
56811+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
56812+
56813+void
56814+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
56815+{
56816+#ifdef CONFIG_GRKERNSEC_EXECLOG
56817+ char *grarg = gr_exec_arg_buf;
56818+ unsigned int i, x, execlen = 0;
56819+ char c;
56820+
56821+ if (!((grsec_enable_execlog && grsec_enable_group &&
56822+ in_group_p(grsec_audit_gid))
56823+ || (grsec_enable_execlog && !grsec_enable_group)))
56824+ return;
56825+
56826+ mutex_lock(&gr_exec_arg_mutex);
56827+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
56828+
56829+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
56830+ const char __user *p;
56831+ unsigned int len;
56832+
56833+ p = get_user_arg_ptr(argv, i);
56834+ if (IS_ERR(p))
56835+ goto log;
56836+
56837+ len = strnlen_user(p, 128 - execlen);
56838+ if (len > 128 - execlen)
56839+ len = 128 - execlen;
56840+ else if (len > 0)
56841+ len--;
56842+ if (copy_from_user(grarg + execlen, p, len))
56843+ goto log;
56844+
56845+ /* rewrite unprintable characters */
56846+ for (x = 0; x < len; x++) {
56847+ c = *(grarg + execlen + x);
56848+ if (c < 32 || c > 126)
56849+ *(grarg + execlen + x) = ' ';
56850+ }
56851+
56852+ execlen += len;
56853+ *(grarg + execlen) = ' ';
56854+ *(grarg + execlen + 1) = '\0';
56855+ execlen++;
56856+ }
56857+
56858+ log:
56859+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
56860+ bprm->file->f_path.mnt, grarg);
56861+ mutex_unlock(&gr_exec_arg_mutex);
56862+#endif
56863+ return;
56864+}
56865+
56866+#ifdef CONFIG_GRKERNSEC
56867+extern int gr_acl_is_capable(const int cap);
56868+extern int gr_acl_is_capable_nolog(const int cap);
56869+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
56870+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
56871+extern int gr_chroot_is_capable(const int cap);
56872+extern int gr_chroot_is_capable_nolog(const int cap);
56873+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
56874+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
56875+#endif
56876+
56877+const char *captab_log[] = {
56878+ "CAP_CHOWN",
56879+ "CAP_DAC_OVERRIDE",
56880+ "CAP_DAC_READ_SEARCH",
56881+ "CAP_FOWNER",
56882+ "CAP_FSETID",
56883+ "CAP_KILL",
56884+ "CAP_SETGID",
56885+ "CAP_SETUID",
56886+ "CAP_SETPCAP",
56887+ "CAP_LINUX_IMMUTABLE",
56888+ "CAP_NET_BIND_SERVICE",
56889+ "CAP_NET_BROADCAST",
56890+ "CAP_NET_ADMIN",
56891+ "CAP_NET_RAW",
56892+ "CAP_IPC_LOCK",
56893+ "CAP_IPC_OWNER",
56894+ "CAP_SYS_MODULE",
56895+ "CAP_SYS_RAWIO",
56896+ "CAP_SYS_CHROOT",
56897+ "CAP_SYS_PTRACE",
56898+ "CAP_SYS_PACCT",
56899+ "CAP_SYS_ADMIN",
56900+ "CAP_SYS_BOOT",
56901+ "CAP_SYS_NICE",
56902+ "CAP_SYS_RESOURCE",
56903+ "CAP_SYS_TIME",
56904+ "CAP_SYS_TTY_CONFIG",
56905+ "CAP_MKNOD",
56906+ "CAP_LEASE",
56907+ "CAP_AUDIT_WRITE",
56908+ "CAP_AUDIT_CONTROL",
56909+ "CAP_SETFCAP",
56910+ "CAP_MAC_OVERRIDE",
56911+ "CAP_MAC_ADMIN",
56912+ "CAP_SYSLOG",
56913+ "CAP_WAKE_ALARM"
56914+};
56915+
56916+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
56917+
56918+int gr_is_capable(const int cap)
56919+{
56920+#ifdef CONFIG_GRKERNSEC
56921+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
56922+ return 1;
56923+ return 0;
56924+#else
56925+ return 1;
56926+#endif
56927+}
56928+
56929+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
56930+{
56931+#ifdef CONFIG_GRKERNSEC
56932+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
56933+ return 1;
56934+ return 0;
56935+#else
56936+ return 1;
56937+#endif
56938+}
56939+
56940+int gr_is_capable_nolog(const int cap)
56941+{
56942+#ifdef CONFIG_GRKERNSEC
56943+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
56944+ return 1;
56945+ return 0;
56946+#else
56947+ return 1;
56948+#endif
56949+}
56950+
56951+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
56952+{
56953+#ifdef CONFIG_GRKERNSEC
56954+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
56955+ return 1;
56956+ return 0;
56957+#else
56958+ return 1;
56959+#endif
56960+}
56961+
56962+EXPORT_SYMBOL(gr_is_capable);
56963+EXPORT_SYMBOL(gr_is_capable_nolog);
56964+EXPORT_SYMBOL(gr_task_is_capable);
56965+EXPORT_SYMBOL(gr_task_is_capable_nolog);
56966diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
56967new file mode 100644
56968index 0000000..d3ee748
56969--- /dev/null
56970+++ b/grsecurity/grsec_fifo.c
56971@@ -0,0 +1,24 @@
56972+#include <linux/kernel.h>
56973+#include <linux/sched.h>
56974+#include <linux/fs.h>
56975+#include <linux/file.h>
56976+#include <linux/grinternal.h>
56977+
56978+int
56979+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
56980+ const struct dentry *dir, const int flag, const int acc_mode)
56981+{
56982+#ifdef CONFIG_GRKERNSEC_FIFO
56983+ const struct cred *cred = current_cred();
56984+
56985+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
56986+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
56987+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
56988+ (cred->fsuid != dentry->d_inode->i_uid)) {
56989+ if (!inode_permission(dentry->d_inode, acc_mode))
56990+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
56991+ return -EACCES;
56992+ }
56993+#endif
56994+ return 0;
56995+}
56996diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
56997new file mode 100644
56998index 0000000..8ca18bf
56999--- /dev/null
57000+++ b/grsecurity/grsec_fork.c
57001@@ -0,0 +1,23 @@
57002+#include <linux/kernel.h>
57003+#include <linux/sched.h>
57004+#include <linux/grsecurity.h>
57005+#include <linux/grinternal.h>
57006+#include <linux/errno.h>
57007+
57008+void
57009+gr_log_forkfail(const int retval)
57010+{
57011+#ifdef CONFIG_GRKERNSEC_FORKFAIL
57012+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
57013+ switch (retval) {
57014+ case -EAGAIN:
57015+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
57016+ break;
57017+ case -ENOMEM:
57018+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
57019+ break;
57020+ }
57021+ }
57022+#endif
57023+ return;
57024+}
57025diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
57026new file mode 100644
57027index 0000000..01ddde4
57028--- /dev/null
57029+++ b/grsecurity/grsec_init.c
57030@@ -0,0 +1,277 @@
57031+#include <linux/kernel.h>
57032+#include <linux/sched.h>
57033+#include <linux/mm.h>
57034+#include <linux/gracl.h>
57035+#include <linux/slab.h>
57036+#include <linux/vmalloc.h>
57037+#include <linux/percpu.h>
57038+#include <linux/module.h>
57039+
57040+int grsec_enable_ptrace_readexec;
57041+int grsec_enable_setxid;
57042+int grsec_enable_brute;
57043+int grsec_enable_link;
57044+int grsec_enable_dmesg;
57045+int grsec_enable_harden_ptrace;
57046+int grsec_enable_fifo;
57047+int grsec_enable_execlog;
57048+int grsec_enable_signal;
57049+int grsec_enable_forkfail;
57050+int grsec_enable_audit_ptrace;
57051+int grsec_enable_time;
57052+int grsec_enable_audit_textrel;
57053+int grsec_enable_group;
57054+int grsec_audit_gid;
57055+int grsec_enable_chdir;
57056+int grsec_enable_mount;
57057+int grsec_enable_rofs;
57058+int grsec_enable_chroot_findtask;
57059+int grsec_enable_chroot_mount;
57060+int grsec_enable_chroot_shmat;
57061+int grsec_enable_chroot_fchdir;
57062+int grsec_enable_chroot_double;
57063+int grsec_enable_chroot_pivot;
57064+int grsec_enable_chroot_chdir;
57065+int grsec_enable_chroot_chmod;
57066+int grsec_enable_chroot_mknod;
57067+int grsec_enable_chroot_nice;
57068+int grsec_enable_chroot_execlog;
57069+int grsec_enable_chroot_caps;
57070+int grsec_enable_chroot_sysctl;
57071+int grsec_enable_chroot_unix;
57072+int grsec_enable_tpe;
57073+int grsec_tpe_gid;
57074+int grsec_enable_blackhole;
57075+#ifdef CONFIG_IPV6_MODULE
57076+EXPORT_SYMBOL(grsec_enable_blackhole);
57077+#endif
57078+int grsec_lastack_retries;
57079+int grsec_enable_tpe_all;
57080+int grsec_enable_tpe_invert;
57081+int grsec_enable_socket_all;
57082+int grsec_socket_all_gid;
57083+int grsec_enable_socket_client;
57084+int grsec_socket_client_gid;
57085+int grsec_enable_socket_server;
57086+int grsec_socket_server_gid;
57087+int grsec_resource_logging;
57088+int grsec_disable_privio;
57089+int grsec_enable_log_rwxmaps;
57090+int grsec_lock;
57091+
57092+DEFINE_SPINLOCK(grsec_alert_lock);
57093+unsigned long grsec_alert_wtime = 0;
57094+unsigned long grsec_alert_fyet = 0;
57095+
57096+DEFINE_SPINLOCK(grsec_audit_lock);
57097+
57098+DEFINE_RWLOCK(grsec_exec_file_lock);
57099+
57100+char *gr_shared_page[4];
57101+
57102+char *gr_alert_log_fmt;
57103+char *gr_audit_log_fmt;
57104+char *gr_alert_log_buf;
57105+char *gr_audit_log_buf;
57106+
57107+extern struct gr_arg *gr_usermode;
57108+extern unsigned char *gr_system_salt;
57109+extern unsigned char *gr_system_sum;
57110+
57111+void __init
57112+grsecurity_init(void)
57113+{
57114+ int j;
57115+ /* create the per-cpu shared pages */
57116+
57117+#ifdef CONFIG_X86
57118+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
57119+#endif
57120+
57121+ for (j = 0; j < 4; j++) {
57122+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
57123+ if (gr_shared_page[j] == NULL) {
57124+ panic("Unable to allocate grsecurity shared page");
57125+ return;
57126+ }
57127+ }
57128+
57129+ /* allocate log buffers */
57130+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
57131+ if (!gr_alert_log_fmt) {
57132+ panic("Unable to allocate grsecurity alert log format buffer");
57133+ return;
57134+ }
57135+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
57136+ if (!gr_audit_log_fmt) {
57137+ panic("Unable to allocate grsecurity audit log format buffer");
57138+ return;
57139+ }
57140+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57141+ if (!gr_alert_log_buf) {
57142+ panic("Unable to allocate grsecurity alert log buffer");
57143+ return;
57144+ }
57145+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57146+ if (!gr_audit_log_buf) {
57147+ panic("Unable to allocate grsecurity audit log buffer");
57148+ return;
57149+ }
57150+
57151+ /* allocate memory for authentication structure */
57152+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
57153+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
57154+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
57155+
57156+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
57157+ panic("Unable to allocate grsecurity authentication structure");
57158+ return;
57159+ }
57160+
57161+
57162+#ifdef CONFIG_GRKERNSEC_IO
57163+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
57164+ grsec_disable_privio = 1;
57165+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57166+ grsec_disable_privio = 1;
57167+#else
57168+ grsec_disable_privio = 0;
57169+#endif
57170+#endif
57171+
57172+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
57173+ /* for backward compatibility, tpe_invert always defaults to on if
57174+ enabled in the kernel
57175+ */
57176+ grsec_enable_tpe_invert = 1;
57177+#endif
57178+
57179+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57180+#ifndef CONFIG_GRKERNSEC_SYSCTL
57181+ grsec_lock = 1;
57182+#endif
57183+
57184+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
57185+ grsec_enable_audit_textrel = 1;
57186+#endif
57187+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57188+ grsec_enable_log_rwxmaps = 1;
57189+#endif
57190+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
57191+ grsec_enable_group = 1;
57192+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
57193+#endif
57194+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
57195+ grsec_enable_ptrace_readexec = 1;
57196+#endif
57197+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57198+ grsec_enable_chdir = 1;
57199+#endif
57200+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57201+ grsec_enable_harden_ptrace = 1;
57202+#endif
57203+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57204+ grsec_enable_mount = 1;
57205+#endif
57206+#ifdef CONFIG_GRKERNSEC_LINK
57207+ grsec_enable_link = 1;
57208+#endif
57209+#ifdef CONFIG_GRKERNSEC_BRUTE
57210+ grsec_enable_brute = 1;
57211+#endif
57212+#ifdef CONFIG_GRKERNSEC_DMESG
57213+ grsec_enable_dmesg = 1;
57214+#endif
57215+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
57216+ grsec_enable_blackhole = 1;
57217+ grsec_lastack_retries = 4;
57218+#endif
57219+#ifdef CONFIG_GRKERNSEC_FIFO
57220+ grsec_enable_fifo = 1;
57221+#endif
57222+#ifdef CONFIG_GRKERNSEC_EXECLOG
57223+ grsec_enable_execlog = 1;
57224+#endif
57225+#ifdef CONFIG_GRKERNSEC_SETXID
57226+ grsec_enable_setxid = 1;
57227+#endif
57228+#ifdef CONFIG_GRKERNSEC_SIGNAL
57229+ grsec_enable_signal = 1;
57230+#endif
57231+#ifdef CONFIG_GRKERNSEC_FORKFAIL
57232+ grsec_enable_forkfail = 1;
57233+#endif
57234+#ifdef CONFIG_GRKERNSEC_TIME
57235+ grsec_enable_time = 1;
57236+#endif
57237+#ifdef CONFIG_GRKERNSEC_RESLOG
57238+ grsec_resource_logging = 1;
57239+#endif
57240+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57241+ grsec_enable_chroot_findtask = 1;
57242+#endif
57243+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57244+ grsec_enable_chroot_unix = 1;
57245+#endif
57246+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57247+ grsec_enable_chroot_mount = 1;
57248+#endif
57249+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57250+ grsec_enable_chroot_fchdir = 1;
57251+#endif
57252+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57253+ grsec_enable_chroot_shmat = 1;
57254+#endif
57255+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
57256+ grsec_enable_audit_ptrace = 1;
57257+#endif
57258+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57259+ grsec_enable_chroot_double = 1;
57260+#endif
57261+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57262+ grsec_enable_chroot_pivot = 1;
57263+#endif
57264+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57265+ grsec_enable_chroot_chdir = 1;
57266+#endif
57267+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57268+ grsec_enable_chroot_chmod = 1;
57269+#endif
57270+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57271+ grsec_enable_chroot_mknod = 1;
57272+#endif
57273+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57274+ grsec_enable_chroot_nice = 1;
57275+#endif
57276+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57277+ grsec_enable_chroot_execlog = 1;
57278+#endif
57279+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57280+ grsec_enable_chroot_caps = 1;
57281+#endif
57282+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57283+ grsec_enable_chroot_sysctl = 1;
57284+#endif
57285+#ifdef CONFIG_GRKERNSEC_TPE
57286+ grsec_enable_tpe = 1;
57287+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
57288+#ifdef CONFIG_GRKERNSEC_TPE_ALL
57289+ grsec_enable_tpe_all = 1;
57290+#endif
57291+#endif
57292+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
57293+ grsec_enable_socket_all = 1;
57294+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
57295+#endif
57296+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
57297+ grsec_enable_socket_client = 1;
57298+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
57299+#endif
57300+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
57301+ grsec_enable_socket_server = 1;
57302+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
57303+#endif
57304+#endif
57305+
57306+ return;
57307+}
57308diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
57309new file mode 100644
57310index 0000000..3efe141
57311--- /dev/null
57312+++ b/grsecurity/grsec_link.c
57313@@ -0,0 +1,43 @@
57314+#include <linux/kernel.h>
57315+#include <linux/sched.h>
57316+#include <linux/fs.h>
57317+#include <linux/file.h>
57318+#include <linux/grinternal.h>
57319+
57320+int
57321+gr_handle_follow_link(const struct inode *parent,
57322+ const struct inode *inode,
57323+ const struct dentry *dentry, const struct vfsmount *mnt)
57324+{
57325+#ifdef CONFIG_GRKERNSEC_LINK
57326+ const struct cred *cred = current_cred();
57327+
57328+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
57329+ (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
57330+ (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
57331+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
57332+ return -EACCES;
57333+ }
57334+#endif
57335+ return 0;
57336+}
57337+
57338+int
57339+gr_handle_hardlink(const struct dentry *dentry,
57340+ const struct vfsmount *mnt,
57341+ struct inode *inode, const int mode, const char *to)
57342+{
57343+#ifdef CONFIG_GRKERNSEC_LINK
57344+ const struct cred *cred = current_cred();
57345+
57346+ if (grsec_enable_link && cred->fsuid != inode->i_uid &&
57347+ (!S_ISREG(mode) || (mode & S_ISUID) ||
57348+ ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
57349+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
57350+ !capable(CAP_FOWNER) && cred->uid) {
57351+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
57352+ return -EPERM;
57353+ }
57354+#endif
57355+ return 0;
57356+}
57357diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
57358new file mode 100644
57359index 0000000..a45d2e9
57360--- /dev/null
57361+++ b/grsecurity/grsec_log.c
57362@@ -0,0 +1,322 @@
57363+#include <linux/kernel.h>
57364+#include <linux/sched.h>
57365+#include <linux/file.h>
57366+#include <linux/tty.h>
57367+#include <linux/fs.h>
57368+#include <linux/grinternal.h>
57369+
57370+#ifdef CONFIG_TREE_PREEMPT_RCU
57371+#define DISABLE_PREEMPT() preempt_disable()
57372+#define ENABLE_PREEMPT() preempt_enable()
57373+#else
57374+#define DISABLE_PREEMPT()
57375+#define ENABLE_PREEMPT()
57376+#endif
57377+
57378+#define BEGIN_LOCKS(x) \
57379+ DISABLE_PREEMPT(); \
57380+ rcu_read_lock(); \
57381+ read_lock(&tasklist_lock); \
57382+ read_lock(&grsec_exec_file_lock); \
57383+ if (x != GR_DO_AUDIT) \
57384+ spin_lock(&grsec_alert_lock); \
57385+ else \
57386+ spin_lock(&grsec_audit_lock)
57387+
57388+#define END_LOCKS(x) \
57389+ if (x != GR_DO_AUDIT) \
57390+ spin_unlock(&grsec_alert_lock); \
57391+ else \
57392+ spin_unlock(&grsec_audit_lock); \
57393+ read_unlock(&grsec_exec_file_lock); \
57394+ read_unlock(&tasklist_lock); \
57395+ rcu_read_unlock(); \
57396+ ENABLE_PREEMPT(); \
57397+ if (x == GR_DONT_AUDIT) \
57398+ gr_handle_alertkill(current)
57399+
57400+enum {
57401+ FLOODING,
57402+ NO_FLOODING
57403+};
57404+
57405+extern char *gr_alert_log_fmt;
57406+extern char *gr_audit_log_fmt;
57407+extern char *gr_alert_log_buf;
57408+extern char *gr_audit_log_buf;
57409+
57410+static int gr_log_start(int audit)
57411+{
57412+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
57413+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
57414+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57415+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
57416+ unsigned long curr_secs = get_seconds();
57417+
57418+ if (audit == GR_DO_AUDIT)
57419+ goto set_fmt;
57420+
57421+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
57422+ grsec_alert_wtime = curr_secs;
57423+ grsec_alert_fyet = 0;
57424+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
57425+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
57426+ grsec_alert_fyet++;
57427+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
57428+ grsec_alert_wtime = curr_secs;
57429+ grsec_alert_fyet++;
57430+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
57431+ return FLOODING;
57432+ }
57433+ else return FLOODING;
57434+
57435+set_fmt:
57436+#endif
57437+ memset(buf, 0, PAGE_SIZE);
57438+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
57439+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
57440+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
57441+ } else if (current->signal->curr_ip) {
57442+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
57443+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
57444+ } else if (gr_acl_is_enabled()) {
57445+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
57446+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
57447+ } else {
57448+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
57449+ strcpy(buf, fmt);
57450+ }
57451+
57452+ return NO_FLOODING;
57453+}
57454+
57455+static void gr_log_middle(int audit, const char *msg, va_list ap)
57456+ __attribute__ ((format (printf, 2, 0)));
57457+
57458+static void gr_log_middle(int audit, const char *msg, va_list ap)
57459+{
57460+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57461+ unsigned int len = strlen(buf);
57462+
57463+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
57464+
57465+ return;
57466+}
57467+
57468+static void gr_log_middle_varargs(int audit, const char *msg, ...)
57469+ __attribute__ ((format (printf, 2, 3)));
57470+
57471+static void gr_log_middle_varargs(int audit, const char *msg, ...)
57472+{
57473+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57474+ unsigned int len = strlen(buf);
57475+ va_list ap;
57476+
57477+ va_start(ap, msg);
57478+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
57479+ va_end(ap);
57480+
57481+ return;
57482+}
57483+
57484+static void gr_log_end(int audit, int append_default)
57485+{
57486+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57487+
57488+ if (append_default) {
57489+ unsigned int len = strlen(buf);
57490+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
57491+ }
57492+
57493+ printk("%s\n", buf);
57494+
57495+ return;
57496+}
57497+
57498+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
57499+{
57500+ int logtype;
57501+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
57502+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
57503+ void *voidptr = NULL;
57504+ int num1 = 0, num2 = 0;
57505+ unsigned long ulong1 = 0, ulong2 = 0;
57506+ struct dentry *dentry = NULL;
57507+ struct vfsmount *mnt = NULL;
57508+ struct file *file = NULL;
57509+ struct task_struct *task = NULL;
57510+ const struct cred *cred, *pcred;
57511+ va_list ap;
57512+
57513+ BEGIN_LOCKS(audit);
57514+ logtype = gr_log_start(audit);
57515+ if (logtype == FLOODING) {
57516+ END_LOCKS(audit);
57517+ return;
57518+ }
57519+ va_start(ap, argtypes);
57520+ switch (argtypes) {
57521+ case GR_TTYSNIFF:
57522+ task = va_arg(ap, struct task_struct *);
57523+ gr_log_middle_varargs(audit, msg, &task->signal->curr_ip, gr_task_fullpath0(task), task->comm, task->pid, gr_parent_task_fullpath0(task), task->real_parent->comm, task->real_parent->pid);
57524+ break;
57525+ case GR_SYSCTL_HIDDEN:
57526+ str1 = va_arg(ap, char *);
57527+ gr_log_middle_varargs(audit, msg, result, str1);
57528+ break;
57529+ case GR_RBAC:
57530+ dentry = va_arg(ap, struct dentry *);
57531+ mnt = va_arg(ap, struct vfsmount *);
57532+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
57533+ break;
57534+ case GR_RBAC_STR:
57535+ dentry = va_arg(ap, struct dentry *);
57536+ mnt = va_arg(ap, struct vfsmount *);
57537+ str1 = va_arg(ap, char *);
57538+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
57539+ break;
57540+ case GR_STR_RBAC:
57541+ str1 = va_arg(ap, char *);
57542+ dentry = va_arg(ap, struct dentry *);
57543+ mnt = va_arg(ap, struct vfsmount *);
57544+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
57545+ break;
57546+ case GR_RBAC_MODE2:
57547+ dentry = va_arg(ap, struct dentry *);
57548+ mnt = va_arg(ap, struct vfsmount *);
57549+ str1 = va_arg(ap, char *);
57550+ str2 = va_arg(ap, char *);
57551+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
57552+ break;
57553+ case GR_RBAC_MODE3:
57554+ dentry = va_arg(ap, struct dentry *);
57555+ mnt = va_arg(ap, struct vfsmount *);
57556+ str1 = va_arg(ap, char *);
57557+ str2 = va_arg(ap, char *);
57558+ str3 = va_arg(ap, char *);
57559+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
57560+ break;
57561+ case GR_FILENAME:
57562+ dentry = va_arg(ap, struct dentry *);
57563+ mnt = va_arg(ap, struct vfsmount *);
57564+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
57565+ break;
57566+ case GR_STR_FILENAME:
57567+ str1 = va_arg(ap, char *);
57568+ dentry = va_arg(ap, struct dentry *);
57569+ mnt = va_arg(ap, struct vfsmount *);
57570+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
57571+ break;
57572+ case GR_FILENAME_STR:
57573+ dentry = va_arg(ap, struct dentry *);
57574+ mnt = va_arg(ap, struct vfsmount *);
57575+ str1 = va_arg(ap, char *);
57576+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
57577+ break;
57578+ case GR_FILENAME_TWO_INT:
57579+ dentry = va_arg(ap, struct dentry *);
57580+ mnt = va_arg(ap, struct vfsmount *);
57581+ num1 = va_arg(ap, int);
57582+ num2 = va_arg(ap, int);
57583+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
57584+ break;
57585+ case GR_FILENAME_TWO_INT_STR:
57586+ dentry = va_arg(ap, struct dentry *);
57587+ mnt = va_arg(ap, struct vfsmount *);
57588+ num1 = va_arg(ap, int);
57589+ num2 = va_arg(ap, int);
57590+ str1 = va_arg(ap, char *);
57591+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
57592+ break;
57593+ case GR_TEXTREL:
57594+ file = va_arg(ap, struct file *);
57595+ ulong1 = va_arg(ap, unsigned long);
57596+ ulong2 = va_arg(ap, unsigned long);
57597+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
57598+ break;
57599+ case GR_PTRACE:
57600+ task = va_arg(ap, struct task_struct *);
57601+ 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);
57602+ break;
57603+ case GR_RESOURCE:
57604+ task = va_arg(ap, struct task_struct *);
57605+ cred = __task_cred(task);
57606+ pcred = __task_cred(task->real_parent);
57607+ ulong1 = va_arg(ap, unsigned long);
57608+ str1 = va_arg(ap, char *);
57609+ ulong2 = va_arg(ap, unsigned long);
57610+ gr_log_middle_varargs(audit, msg, ulong1, str1, ulong2, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid);
57611+ break;
57612+ case GR_CAP:
57613+ task = va_arg(ap, struct task_struct *);
57614+ cred = __task_cred(task);
57615+ pcred = __task_cred(task->real_parent);
57616+ str1 = va_arg(ap, char *);
57617+ gr_log_middle_varargs(audit, msg, str1, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid);
57618+ break;
57619+ case GR_SIG:
57620+ str1 = va_arg(ap, char *);
57621+ voidptr = va_arg(ap, void *);
57622+ gr_log_middle_varargs(audit, msg, str1, voidptr);
57623+ break;
57624+ case GR_SIG2:
57625+ task = va_arg(ap, struct task_struct *);
57626+ cred = __task_cred(task);
57627+ pcred = __task_cred(task->real_parent);
57628+ num1 = va_arg(ap, int);
57629+ gr_log_middle_varargs(audit, msg, num1, gr_task_fullpath0(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath0(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid);
57630+ break;
57631+ case GR_CRASH1:
57632+ task = va_arg(ap, struct task_struct *);
57633+ cred = __task_cred(task);
57634+ pcred = __task_cred(task->real_parent);
57635+ ulong1 = va_arg(ap, unsigned long);
57636+ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid, cred->uid, ulong1);
57637+ break;
57638+ case GR_CRASH2:
57639+ task = va_arg(ap, struct task_struct *);
57640+ cred = __task_cred(task);
57641+ pcred = __task_cred(task->real_parent);
57642+ ulong1 = va_arg(ap, unsigned long);
57643+ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid, ulong1);
57644+ break;
57645+ case GR_RWXMAP:
57646+ file = va_arg(ap, struct file *);
57647+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
57648+ break;
57649+ case GR_PSACCT:
57650+ {
57651+ unsigned int wday, cday;
57652+ __u8 whr, chr;
57653+ __u8 wmin, cmin;
57654+ __u8 wsec, csec;
57655+ char cur_tty[64] = { 0 };
57656+ char parent_tty[64] = { 0 };
57657+
57658+ task = va_arg(ap, struct task_struct *);
57659+ wday = va_arg(ap, unsigned int);
57660+ cday = va_arg(ap, unsigned int);
57661+ whr = va_arg(ap, int);
57662+ chr = va_arg(ap, int);
57663+ wmin = va_arg(ap, int);
57664+ cmin = va_arg(ap, int);
57665+ wsec = va_arg(ap, int);
57666+ csec = va_arg(ap, int);
57667+ ulong1 = va_arg(ap, unsigned long);
57668+ cred = __task_cred(task);
57669+ pcred = __task_cred(task->real_parent);
57670+
57671+ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, &task->signal->curr_ip, tty_name(task->signal->tty, cur_tty), cred->uid, cred->euid, cred->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->real_parent->pid, &task->real_parent->signal->curr_ip, tty_name(task->real_parent->signal->tty, parent_tty), pcred->uid, pcred->euid, pcred->gid, pcred->egid);
57672+ }
57673+ break;
57674+ default:
57675+ gr_log_middle(audit, msg, ap);
57676+ }
57677+ va_end(ap);
57678+ // these don't need DEFAULTSECARGS printed on the end
57679+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
57680+ gr_log_end(audit, 0);
57681+ else
57682+ gr_log_end(audit, 1);
57683+ END_LOCKS(audit);
57684+}
57685diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
57686new file mode 100644
57687index 0000000..f536303
57688--- /dev/null
57689+++ b/grsecurity/grsec_mem.c
57690@@ -0,0 +1,40 @@
57691+#include <linux/kernel.h>
57692+#include <linux/sched.h>
57693+#include <linux/mm.h>
57694+#include <linux/mman.h>
57695+#include <linux/grinternal.h>
57696+
57697+void
57698+gr_handle_ioperm(void)
57699+{
57700+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
57701+ return;
57702+}
57703+
57704+void
57705+gr_handle_iopl(void)
57706+{
57707+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
57708+ return;
57709+}
57710+
57711+void
57712+gr_handle_mem_readwrite(u64 from, u64 to)
57713+{
57714+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
57715+ return;
57716+}
57717+
57718+void
57719+gr_handle_vm86(void)
57720+{
57721+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
57722+ return;
57723+}
57724+
57725+void
57726+gr_log_badprocpid(const char *entry)
57727+{
57728+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
57729+ return;
57730+}
57731diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
57732new file mode 100644
57733index 0000000..2131422
57734--- /dev/null
57735+++ b/grsecurity/grsec_mount.c
57736@@ -0,0 +1,62 @@
57737+#include <linux/kernel.h>
57738+#include <linux/sched.h>
57739+#include <linux/mount.h>
57740+#include <linux/grsecurity.h>
57741+#include <linux/grinternal.h>
57742+
57743+void
57744+gr_log_remount(const char *devname, const int retval)
57745+{
57746+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57747+ if (grsec_enable_mount && (retval >= 0))
57748+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
57749+#endif
57750+ return;
57751+}
57752+
57753+void
57754+gr_log_unmount(const char *devname, const int retval)
57755+{
57756+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57757+ if (grsec_enable_mount && (retval >= 0))
57758+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
57759+#endif
57760+ return;
57761+}
57762+
57763+void
57764+gr_log_mount(const char *from, const char *to, const int retval)
57765+{
57766+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57767+ if (grsec_enable_mount && (retval >= 0))
57768+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
57769+#endif
57770+ return;
57771+}
57772+
57773+int
57774+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
57775+{
57776+#ifdef CONFIG_GRKERNSEC_ROFS
57777+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
57778+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
57779+ return -EPERM;
57780+ } else
57781+ return 0;
57782+#endif
57783+ return 0;
57784+}
57785+
57786+int
57787+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
57788+{
57789+#ifdef CONFIG_GRKERNSEC_ROFS
57790+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
57791+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
57792+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
57793+ return -EPERM;
57794+ } else
57795+ return 0;
57796+#endif
57797+ return 0;
57798+}
57799diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
57800new file mode 100644
57801index 0000000..a3b12a0
57802--- /dev/null
57803+++ b/grsecurity/grsec_pax.c
57804@@ -0,0 +1,36 @@
57805+#include <linux/kernel.h>
57806+#include <linux/sched.h>
57807+#include <linux/mm.h>
57808+#include <linux/file.h>
57809+#include <linux/grinternal.h>
57810+#include <linux/grsecurity.h>
57811+
57812+void
57813+gr_log_textrel(struct vm_area_struct * vma)
57814+{
57815+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
57816+ if (grsec_enable_audit_textrel)
57817+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
57818+#endif
57819+ return;
57820+}
57821+
57822+void
57823+gr_log_rwxmmap(struct file *file)
57824+{
57825+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57826+ if (grsec_enable_log_rwxmaps)
57827+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
57828+#endif
57829+ return;
57830+}
57831+
57832+void
57833+gr_log_rwxmprotect(struct file *file)
57834+{
57835+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57836+ if (grsec_enable_log_rwxmaps)
57837+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
57838+#endif
57839+ return;
57840+}
57841diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
57842new file mode 100644
57843index 0000000..f7f29aa
57844--- /dev/null
57845+++ b/grsecurity/grsec_ptrace.c
57846@@ -0,0 +1,30 @@
57847+#include <linux/kernel.h>
57848+#include <linux/sched.h>
57849+#include <linux/grinternal.h>
57850+#include <linux/security.h>
57851+
57852+void
57853+gr_audit_ptrace(struct task_struct *task)
57854+{
57855+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
57856+ if (grsec_enable_audit_ptrace)
57857+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
57858+#endif
57859+ return;
57860+}
57861+
57862+int
57863+gr_ptrace_readexec(struct file *file, int unsafe_flags)
57864+{
57865+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
57866+ const struct dentry *dentry = file->f_path.dentry;
57867+ const struct vfsmount *mnt = file->f_path.mnt;
57868+
57869+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
57870+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
57871+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
57872+ return -EACCES;
57873+ }
57874+#endif
57875+ return 0;
57876+}
57877diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
57878new file mode 100644
57879index 0000000..7a5b2de
57880--- /dev/null
57881+++ b/grsecurity/grsec_sig.c
57882@@ -0,0 +1,207 @@
57883+#include <linux/kernel.h>
57884+#include <linux/sched.h>
57885+#include <linux/delay.h>
57886+#include <linux/grsecurity.h>
57887+#include <linux/grinternal.h>
57888+#include <linux/hardirq.h>
57889+
57890+char *signames[] = {
57891+ [SIGSEGV] = "Segmentation fault",
57892+ [SIGILL] = "Illegal instruction",
57893+ [SIGABRT] = "Abort",
57894+ [SIGBUS] = "Invalid alignment/Bus error"
57895+};
57896+
57897+void
57898+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
57899+{
57900+#ifdef CONFIG_GRKERNSEC_SIGNAL
57901+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
57902+ (sig == SIGABRT) || (sig == SIGBUS))) {
57903+ if (t->pid == current->pid) {
57904+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
57905+ } else {
57906+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
57907+ }
57908+ }
57909+#endif
57910+ return;
57911+}
57912+
57913+int
57914+gr_handle_signal(const struct task_struct *p, const int sig)
57915+{
57916+#ifdef CONFIG_GRKERNSEC
57917+ /* ignore the 0 signal for protected task checks */
57918+ if (current->pid > 1 && sig && gr_check_protected_task(p)) {
57919+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
57920+ return -EPERM;
57921+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
57922+ return -EPERM;
57923+ }
57924+#endif
57925+ return 0;
57926+}
57927+
57928+#ifdef CONFIG_GRKERNSEC
57929+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
57930+
57931+int gr_fake_force_sig(int sig, struct task_struct *t)
57932+{
57933+ unsigned long int flags;
57934+ int ret, blocked, ignored;
57935+ struct k_sigaction *action;
57936+
57937+ spin_lock_irqsave(&t->sighand->siglock, flags);
57938+ action = &t->sighand->action[sig-1];
57939+ ignored = action->sa.sa_handler == SIG_IGN;
57940+ blocked = sigismember(&t->blocked, sig);
57941+ if (blocked || ignored) {
57942+ action->sa.sa_handler = SIG_DFL;
57943+ if (blocked) {
57944+ sigdelset(&t->blocked, sig);
57945+ recalc_sigpending_and_wake(t);
57946+ }
57947+ }
57948+ if (action->sa.sa_handler == SIG_DFL)
57949+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
57950+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
57951+
57952+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
57953+
57954+ return ret;
57955+}
57956+#endif
57957+
57958+#ifdef CONFIG_GRKERNSEC_BRUTE
57959+#define GR_USER_BAN_TIME (15 * 60)
57960+
57961+static int __get_dumpable(unsigned long mm_flags)
57962+{
57963+ int ret;
57964+
57965+ ret = mm_flags & MMF_DUMPABLE_MASK;
57966+ return (ret >= 2) ? 2 : ret;
57967+}
57968+#endif
57969+
57970+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
57971+{
57972+#ifdef CONFIG_GRKERNSEC_BRUTE
57973+ uid_t uid = 0;
57974+
57975+ if (!grsec_enable_brute)
57976+ return;
57977+
57978+ rcu_read_lock();
57979+ read_lock(&tasklist_lock);
57980+ read_lock(&grsec_exec_file_lock);
57981+ if (p->real_parent && p->real_parent->exec_file == p->exec_file)
57982+ p->real_parent->brute = 1;
57983+ else {
57984+ const struct cred *cred = __task_cred(p), *cred2;
57985+ struct task_struct *tsk, *tsk2;
57986+
57987+ if (!__get_dumpable(mm_flags) && cred->uid) {
57988+ struct user_struct *user;
57989+
57990+ uid = cred->uid;
57991+
57992+ /* this is put upon execution past expiration */
57993+ user = find_user(uid);
57994+ if (user == NULL)
57995+ goto unlock;
57996+ user->banned = 1;
57997+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
57998+ if (user->ban_expires == ~0UL)
57999+ user->ban_expires--;
58000+
58001+ do_each_thread(tsk2, tsk) {
58002+ cred2 = __task_cred(tsk);
58003+ if (tsk != p && cred2->uid == uid)
58004+ gr_fake_force_sig(SIGKILL, tsk);
58005+ } while_each_thread(tsk2, tsk);
58006+ }
58007+ }
58008+unlock:
58009+ read_unlock(&grsec_exec_file_lock);
58010+ read_unlock(&tasklist_lock);
58011+ rcu_read_unlock();
58012+
58013+ if (uid)
58014+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
58015+
58016+#endif
58017+ return;
58018+}
58019+
58020+void gr_handle_brute_check(void)
58021+{
58022+#ifdef CONFIG_GRKERNSEC_BRUTE
58023+ if (current->brute)
58024+ msleep(30 * 1000);
58025+#endif
58026+ return;
58027+}
58028+
58029+void gr_handle_kernel_exploit(void)
58030+{
58031+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
58032+ const struct cred *cred;
58033+ struct task_struct *tsk, *tsk2;
58034+ struct user_struct *user;
58035+ uid_t uid;
58036+
58037+ if (in_irq() || in_serving_softirq() || in_nmi())
58038+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
58039+
58040+ uid = current_uid();
58041+
58042+ if (uid == 0)
58043+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
58044+ else {
58045+ /* kill all the processes of this user, hold a reference
58046+ to their creds struct, and prevent them from creating
58047+ another process until system reset
58048+ */
58049+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
58050+ /* we intentionally leak this ref */
58051+ user = get_uid(current->cred->user);
58052+ if (user) {
58053+ user->banned = 1;
58054+ user->ban_expires = ~0UL;
58055+ }
58056+
58057+ read_lock(&tasklist_lock);
58058+ do_each_thread(tsk2, tsk) {
58059+ cred = __task_cred(tsk);
58060+ if (cred->uid == uid)
58061+ gr_fake_force_sig(SIGKILL, tsk);
58062+ } while_each_thread(tsk2, tsk);
58063+ read_unlock(&tasklist_lock);
58064+ }
58065+#endif
58066+}
58067+
58068+int __gr_process_user_ban(struct user_struct *user)
58069+{
58070+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58071+ if (unlikely(user->banned)) {
58072+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
58073+ user->banned = 0;
58074+ user->ban_expires = 0;
58075+ free_uid(user);
58076+ } else
58077+ return -EPERM;
58078+ }
58079+#endif
58080+ return 0;
58081+}
58082+
58083+int gr_process_user_ban(void)
58084+{
58085+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58086+ return __gr_process_user_ban(current->cred->user);
58087+#endif
58088+ return 0;
58089+}
58090diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
58091new file mode 100644
58092index 0000000..4030d57
58093--- /dev/null
58094+++ b/grsecurity/grsec_sock.c
58095@@ -0,0 +1,244 @@
58096+#include <linux/kernel.h>
58097+#include <linux/module.h>
58098+#include <linux/sched.h>
58099+#include <linux/file.h>
58100+#include <linux/net.h>
58101+#include <linux/in.h>
58102+#include <linux/ip.h>
58103+#include <net/sock.h>
58104+#include <net/inet_sock.h>
58105+#include <linux/grsecurity.h>
58106+#include <linux/grinternal.h>
58107+#include <linux/gracl.h>
58108+
58109+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
58110+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
58111+
58112+EXPORT_SYMBOL(gr_search_udp_recvmsg);
58113+EXPORT_SYMBOL(gr_search_udp_sendmsg);
58114+
58115+#ifdef CONFIG_UNIX_MODULE
58116+EXPORT_SYMBOL(gr_acl_handle_unix);
58117+EXPORT_SYMBOL(gr_acl_handle_mknod);
58118+EXPORT_SYMBOL(gr_handle_chroot_unix);
58119+EXPORT_SYMBOL(gr_handle_create);
58120+#endif
58121+
58122+#ifdef CONFIG_GRKERNSEC
58123+#define gr_conn_table_size 32749
58124+struct conn_table_entry {
58125+ struct conn_table_entry *next;
58126+ struct signal_struct *sig;
58127+};
58128+
58129+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
58130+DEFINE_SPINLOCK(gr_conn_table_lock);
58131+
58132+extern const char * gr_socktype_to_name(unsigned char type);
58133+extern const char * gr_proto_to_name(unsigned char proto);
58134+extern const char * gr_sockfamily_to_name(unsigned char family);
58135+
58136+static __inline__ int
58137+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
58138+{
58139+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
58140+}
58141+
58142+static __inline__ int
58143+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
58144+ __u16 sport, __u16 dport)
58145+{
58146+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
58147+ sig->gr_sport == sport && sig->gr_dport == dport))
58148+ return 1;
58149+ else
58150+ return 0;
58151+}
58152+
58153+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
58154+{
58155+ struct conn_table_entry **match;
58156+ unsigned int index;
58157+
58158+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58159+ sig->gr_sport, sig->gr_dport,
58160+ gr_conn_table_size);
58161+
58162+ newent->sig = sig;
58163+
58164+ match = &gr_conn_table[index];
58165+ newent->next = *match;
58166+ *match = newent;
58167+
58168+ return;
58169+}
58170+
58171+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
58172+{
58173+ struct conn_table_entry *match, *last = NULL;
58174+ unsigned int index;
58175+
58176+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58177+ sig->gr_sport, sig->gr_dport,
58178+ gr_conn_table_size);
58179+
58180+ match = gr_conn_table[index];
58181+ while (match && !conn_match(match->sig,
58182+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
58183+ sig->gr_dport)) {
58184+ last = match;
58185+ match = match->next;
58186+ }
58187+
58188+ if (match) {
58189+ if (last)
58190+ last->next = match->next;
58191+ else
58192+ gr_conn_table[index] = NULL;
58193+ kfree(match);
58194+ }
58195+
58196+ return;
58197+}
58198+
58199+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
58200+ __u16 sport, __u16 dport)
58201+{
58202+ struct conn_table_entry *match;
58203+ unsigned int index;
58204+
58205+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
58206+
58207+ match = gr_conn_table[index];
58208+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
58209+ match = match->next;
58210+
58211+ if (match)
58212+ return match->sig;
58213+ else
58214+ return NULL;
58215+}
58216+
58217+#endif
58218+
58219+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
58220+{
58221+#ifdef CONFIG_GRKERNSEC
58222+ struct signal_struct *sig = task->signal;
58223+ struct conn_table_entry *newent;
58224+
58225+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
58226+ if (newent == NULL)
58227+ return;
58228+ /* no bh lock needed since we are called with bh disabled */
58229+ spin_lock(&gr_conn_table_lock);
58230+ gr_del_task_from_ip_table_nolock(sig);
58231+ sig->gr_saddr = inet->inet_rcv_saddr;
58232+ sig->gr_daddr = inet->inet_daddr;
58233+ sig->gr_sport = inet->inet_sport;
58234+ sig->gr_dport = inet->inet_dport;
58235+ gr_add_to_task_ip_table_nolock(sig, newent);
58236+ spin_unlock(&gr_conn_table_lock);
58237+#endif
58238+ return;
58239+}
58240+
58241+void gr_del_task_from_ip_table(struct task_struct *task)
58242+{
58243+#ifdef CONFIG_GRKERNSEC
58244+ spin_lock_bh(&gr_conn_table_lock);
58245+ gr_del_task_from_ip_table_nolock(task->signal);
58246+ spin_unlock_bh(&gr_conn_table_lock);
58247+#endif
58248+ return;
58249+}
58250+
58251+void
58252+gr_attach_curr_ip(const struct sock *sk)
58253+{
58254+#ifdef CONFIG_GRKERNSEC
58255+ struct signal_struct *p, *set;
58256+ const struct inet_sock *inet = inet_sk(sk);
58257+
58258+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
58259+ return;
58260+
58261+ set = current->signal;
58262+
58263+ spin_lock_bh(&gr_conn_table_lock);
58264+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
58265+ inet->inet_dport, inet->inet_sport);
58266+ if (unlikely(p != NULL)) {
58267+ set->curr_ip = p->curr_ip;
58268+ set->used_accept = 1;
58269+ gr_del_task_from_ip_table_nolock(p);
58270+ spin_unlock_bh(&gr_conn_table_lock);
58271+ return;
58272+ }
58273+ spin_unlock_bh(&gr_conn_table_lock);
58274+
58275+ set->curr_ip = inet->inet_daddr;
58276+ set->used_accept = 1;
58277+#endif
58278+ return;
58279+}
58280+
58281+int
58282+gr_handle_sock_all(const int family, const int type, const int protocol)
58283+{
58284+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58285+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
58286+ (family != AF_UNIX)) {
58287+ if (family == AF_INET)
58288+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
58289+ else
58290+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
58291+ return -EACCES;
58292+ }
58293+#endif
58294+ return 0;
58295+}
58296+
58297+int
58298+gr_handle_sock_server(const struct sockaddr *sck)
58299+{
58300+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58301+ if (grsec_enable_socket_server &&
58302+ in_group_p(grsec_socket_server_gid) &&
58303+ sck && (sck->sa_family != AF_UNIX) &&
58304+ (sck->sa_family != AF_LOCAL)) {
58305+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
58306+ return -EACCES;
58307+ }
58308+#endif
58309+ return 0;
58310+}
58311+
58312+int
58313+gr_handle_sock_server_other(const struct sock *sck)
58314+{
58315+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58316+ if (grsec_enable_socket_server &&
58317+ in_group_p(grsec_socket_server_gid) &&
58318+ sck && (sck->sk_family != AF_UNIX) &&
58319+ (sck->sk_family != AF_LOCAL)) {
58320+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
58321+ return -EACCES;
58322+ }
58323+#endif
58324+ return 0;
58325+}
58326+
58327+int
58328+gr_handle_sock_client(const struct sockaddr *sck)
58329+{
58330+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58331+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
58332+ sck && (sck->sa_family != AF_UNIX) &&
58333+ (sck->sa_family != AF_LOCAL)) {
58334+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
58335+ return -EACCES;
58336+ }
58337+#endif
58338+ return 0;
58339+}
58340diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
58341new file mode 100644
58342index 0000000..8316f6f
58343--- /dev/null
58344+++ b/grsecurity/grsec_sysctl.c
58345@@ -0,0 +1,453 @@
58346+#include <linux/kernel.h>
58347+#include <linux/sched.h>
58348+#include <linux/sysctl.h>
58349+#include <linux/grsecurity.h>
58350+#include <linux/grinternal.h>
58351+
58352+int
58353+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
58354+{
58355+#ifdef CONFIG_GRKERNSEC_SYSCTL
58356+ if (dirname == NULL || name == NULL)
58357+ return 0;
58358+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
58359+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
58360+ return -EACCES;
58361+ }
58362+#endif
58363+ return 0;
58364+}
58365+
58366+#ifdef CONFIG_GRKERNSEC_ROFS
58367+static int __maybe_unused one = 1;
58368+#endif
58369+
58370+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
58371+struct ctl_table grsecurity_table[] = {
58372+#ifdef CONFIG_GRKERNSEC_SYSCTL
58373+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
58374+#ifdef CONFIG_GRKERNSEC_IO
58375+ {
58376+ .procname = "disable_priv_io",
58377+ .data = &grsec_disable_privio,
58378+ .maxlen = sizeof(int),
58379+ .mode = 0600,
58380+ .proc_handler = &proc_dointvec,
58381+ },
58382+#endif
58383+#endif
58384+#ifdef CONFIG_GRKERNSEC_LINK
58385+ {
58386+ .procname = "linking_restrictions",
58387+ .data = &grsec_enable_link,
58388+ .maxlen = sizeof(int),
58389+ .mode = 0600,
58390+ .proc_handler = &proc_dointvec,
58391+ },
58392+#endif
58393+#ifdef CONFIG_GRKERNSEC_BRUTE
58394+ {
58395+ .procname = "deter_bruteforce",
58396+ .data = &grsec_enable_brute,
58397+ .maxlen = sizeof(int),
58398+ .mode = 0600,
58399+ .proc_handler = &proc_dointvec,
58400+ },
58401+#endif
58402+#ifdef CONFIG_GRKERNSEC_FIFO
58403+ {
58404+ .procname = "fifo_restrictions",
58405+ .data = &grsec_enable_fifo,
58406+ .maxlen = sizeof(int),
58407+ .mode = 0600,
58408+ .proc_handler = &proc_dointvec,
58409+ },
58410+#endif
58411+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58412+ {
58413+ .procname = "ptrace_readexec",
58414+ .data = &grsec_enable_ptrace_readexec,
58415+ .maxlen = sizeof(int),
58416+ .mode = 0600,
58417+ .proc_handler = &proc_dointvec,
58418+ },
58419+#endif
58420+#ifdef CONFIG_GRKERNSEC_SETXID
58421+ {
58422+ .procname = "consistent_setxid",
58423+ .data = &grsec_enable_setxid,
58424+ .maxlen = sizeof(int),
58425+ .mode = 0600,
58426+ .proc_handler = &proc_dointvec,
58427+ },
58428+#endif
58429+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58430+ {
58431+ .procname = "ip_blackhole",
58432+ .data = &grsec_enable_blackhole,
58433+ .maxlen = sizeof(int),
58434+ .mode = 0600,
58435+ .proc_handler = &proc_dointvec,
58436+ },
58437+ {
58438+ .procname = "lastack_retries",
58439+ .data = &grsec_lastack_retries,
58440+ .maxlen = sizeof(int),
58441+ .mode = 0600,
58442+ .proc_handler = &proc_dointvec,
58443+ },
58444+#endif
58445+#ifdef CONFIG_GRKERNSEC_EXECLOG
58446+ {
58447+ .procname = "exec_logging",
58448+ .data = &grsec_enable_execlog,
58449+ .maxlen = sizeof(int),
58450+ .mode = 0600,
58451+ .proc_handler = &proc_dointvec,
58452+ },
58453+#endif
58454+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58455+ {
58456+ .procname = "rwxmap_logging",
58457+ .data = &grsec_enable_log_rwxmaps,
58458+ .maxlen = sizeof(int),
58459+ .mode = 0600,
58460+ .proc_handler = &proc_dointvec,
58461+ },
58462+#endif
58463+#ifdef CONFIG_GRKERNSEC_SIGNAL
58464+ {
58465+ .procname = "signal_logging",
58466+ .data = &grsec_enable_signal,
58467+ .maxlen = sizeof(int),
58468+ .mode = 0600,
58469+ .proc_handler = &proc_dointvec,
58470+ },
58471+#endif
58472+#ifdef CONFIG_GRKERNSEC_FORKFAIL
58473+ {
58474+ .procname = "forkfail_logging",
58475+ .data = &grsec_enable_forkfail,
58476+ .maxlen = sizeof(int),
58477+ .mode = 0600,
58478+ .proc_handler = &proc_dointvec,
58479+ },
58480+#endif
58481+#ifdef CONFIG_GRKERNSEC_TIME
58482+ {
58483+ .procname = "timechange_logging",
58484+ .data = &grsec_enable_time,
58485+ .maxlen = sizeof(int),
58486+ .mode = 0600,
58487+ .proc_handler = &proc_dointvec,
58488+ },
58489+#endif
58490+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58491+ {
58492+ .procname = "chroot_deny_shmat",
58493+ .data = &grsec_enable_chroot_shmat,
58494+ .maxlen = sizeof(int),
58495+ .mode = 0600,
58496+ .proc_handler = &proc_dointvec,
58497+ },
58498+#endif
58499+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58500+ {
58501+ .procname = "chroot_deny_unix",
58502+ .data = &grsec_enable_chroot_unix,
58503+ .maxlen = sizeof(int),
58504+ .mode = 0600,
58505+ .proc_handler = &proc_dointvec,
58506+ },
58507+#endif
58508+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58509+ {
58510+ .procname = "chroot_deny_mount",
58511+ .data = &grsec_enable_chroot_mount,
58512+ .maxlen = sizeof(int),
58513+ .mode = 0600,
58514+ .proc_handler = &proc_dointvec,
58515+ },
58516+#endif
58517+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58518+ {
58519+ .procname = "chroot_deny_fchdir",
58520+ .data = &grsec_enable_chroot_fchdir,
58521+ .maxlen = sizeof(int),
58522+ .mode = 0600,
58523+ .proc_handler = &proc_dointvec,
58524+ },
58525+#endif
58526+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58527+ {
58528+ .procname = "chroot_deny_chroot",
58529+ .data = &grsec_enable_chroot_double,
58530+ .maxlen = sizeof(int),
58531+ .mode = 0600,
58532+ .proc_handler = &proc_dointvec,
58533+ },
58534+#endif
58535+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58536+ {
58537+ .procname = "chroot_deny_pivot",
58538+ .data = &grsec_enable_chroot_pivot,
58539+ .maxlen = sizeof(int),
58540+ .mode = 0600,
58541+ .proc_handler = &proc_dointvec,
58542+ },
58543+#endif
58544+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58545+ {
58546+ .procname = "chroot_enforce_chdir",
58547+ .data = &grsec_enable_chroot_chdir,
58548+ .maxlen = sizeof(int),
58549+ .mode = 0600,
58550+ .proc_handler = &proc_dointvec,
58551+ },
58552+#endif
58553+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58554+ {
58555+ .procname = "chroot_deny_chmod",
58556+ .data = &grsec_enable_chroot_chmod,
58557+ .maxlen = sizeof(int),
58558+ .mode = 0600,
58559+ .proc_handler = &proc_dointvec,
58560+ },
58561+#endif
58562+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58563+ {
58564+ .procname = "chroot_deny_mknod",
58565+ .data = &grsec_enable_chroot_mknod,
58566+ .maxlen = sizeof(int),
58567+ .mode = 0600,
58568+ .proc_handler = &proc_dointvec,
58569+ },
58570+#endif
58571+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58572+ {
58573+ .procname = "chroot_restrict_nice",
58574+ .data = &grsec_enable_chroot_nice,
58575+ .maxlen = sizeof(int),
58576+ .mode = 0600,
58577+ .proc_handler = &proc_dointvec,
58578+ },
58579+#endif
58580+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58581+ {
58582+ .procname = "chroot_execlog",
58583+ .data = &grsec_enable_chroot_execlog,
58584+ .maxlen = sizeof(int),
58585+ .mode = 0600,
58586+ .proc_handler = &proc_dointvec,
58587+ },
58588+#endif
58589+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58590+ {
58591+ .procname = "chroot_caps",
58592+ .data = &grsec_enable_chroot_caps,
58593+ .maxlen = sizeof(int),
58594+ .mode = 0600,
58595+ .proc_handler = &proc_dointvec,
58596+ },
58597+#endif
58598+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58599+ {
58600+ .procname = "chroot_deny_sysctl",
58601+ .data = &grsec_enable_chroot_sysctl,
58602+ .maxlen = sizeof(int),
58603+ .mode = 0600,
58604+ .proc_handler = &proc_dointvec,
58605+ },
58606+#endif
58607+#ifdef CONFIG_GRKERNSEC_TPE
58608+ {
58609+ .procname = "tpe",
58610+ .data = &grsec_enable_tpe,
58611+ .maxlen = sizeof(int),
58612+ .mode = 0600,
58613+ .proc_handler = &proc_dointvec,
58614+ },
58615+ {
58616+ .procname = "tpe_gid",
58617+ .data = &grsec_tpe_gid,
58618+ .maxlen = sizeof(int),
58619+ .mode = 0600,
58620+ .proc_handler = &proc_dointvec,
58621+ },
58622+#endif
58623+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58624+ {
58625+ .procname = "tpe_invert",
58626+ .data = &grsec_enable_tpe_invert,
58627+ .maxlen = sizeof(int),
58628+ .mode = 0600,
58629+ .proc_handler = &proc_dointvec,
58630+ },
58631+#endif
58632+#ifdef CONFIG_GRKERNSEC_TPE_ALL
58633+ {
58634+ .procname = "tpe_restrict_all",
58635+ .data = &grsec_enable_tpe_all,
58636+ .maxlen = sizeof(int),
58637+ .mode = 0600,
58638+ .proc_handler = &proc_dointvec,
58639+ },
58640+#endif
58641+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58642+ {
58643+ .procname = "socket_all",
58644+ .data = &grsec_enable_socket_all,
58645+ .maxlen = sizeof(int),
58646+ .mode = 0600,
58647+ .proc_handler = &proc_dointvec,
58648+ },
58649+ {
58650+ .procname = "socket_all_gid",
58651+ .data = &grsec_socket_all_gid,
58652+ .maxlen = sizeof(int),
58653+ .mode = 0600,
58654+ .proc_handler = &proc_dointvec,
58655+ },
58656+#endif
58657+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58658+ {
58659+ .procname = "socket_client",
58660+ .data = &grsec_enable_socket_client,
58661+ .maxlen = sizeof(int),
58662+ .mode = 0600,
58663+ .proc_handler = &proc_dointvec,
58664+ },
58665+ {
58666+ .procname = "socket_client_gid",
58667+ .data = &grsec_socket_client_gid,
58668+ .maxlen = sizeof(int),
58669+ .mode = 0600,
58670+ .proc_handler = &proc_dointvec,
58671+ },
58672+#endif
58673+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58674+ {
58675+ .procname = "socket_server",
58676+ .data = &grsec_enable_socket_server,
58677+ .maxlen = sizeof(int),
58678+ .mode = 0600,
58679+ .proc_handler = &proc_dointvec,
58680+ },
58681+ {
58682+ .procname = "socket_server_gid",
58683+ .data = &grsec_socket_server_gid,
58684+ .maxlen = sizeof(int),
58685+ .mode = 0600,
58686+ .proc_handler = &proc_dointvec,
58687+ },
58688+#endif
58689+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58690+ {
58691+ .procname = "audit_group",
58692+ .data = &grsec_enable_group,
58693+ .maxlen = sizeof(int),
58694+ .mode = 0600,
58695+ .proc_handler = &proc_dointvec,
58696+ },
58697+ {
58698+ .procname = "audit_gid",
58699+ .data = &grsec_audit_gid,
58700+ .maxlen = sizeof(int),
58701+ .mode = 0600,
58702+ .proc_handler = &proc_dointvec,
58703+ },
58704+#endif
58705+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58706+ {
58707+ .procname = "audit_chdir",
58708+ .data = &grsec_enable_chdir,
58709+ .maxlen = sizeof(int),
58710+ .mode = 0600,
58711+ .proc_handler = &proc_dointvec,
58712+ },
58713+#endif
58714+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58715+ {
58716+ .procname = "audit_mount",
58717+ .data = &grsec_enable_mount,
58718+ .maxlen = sizeof(int),
58719+ .mode = 0600,
58720+ .proc_handler = &proc_dointvec,
58721+ },
58722+#endif
58723+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58724+ {
58725+ .procname = "audit_textrel",
58726+ .data = &grsec_enable_audit_textrel,
58727+ .maxlen = sizeof(int),
58728+ .mode = 0600,
58729+ .proc_handler = &proc_dointvec,
58730+ },
58731+#endif
58732+#ifdef CONFIG_GRKERNSEC_DMESG
58733+ {
58734+ .procname = "dmesg",
58735+ .data = &grsec_enable_dmesg,
58736+ .maxlen = sizeof(int),
58737+ .mode = 0600,
58738+ .proc_handler = &proc_dointvec,
58739+ },
58740+#endif
58741+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58742+ {
58743+ .procname = "chroot_findtask",
58744+ .data = &grsec_enable_chroot_findtask,
58745+ .maxlen = sizeof(int),
58746+ .mode = 0600,
58747+ .proc_handler = &proc_dointvec,
58748+ },
58749+#endif
58750+#ifdef CONFIG_GRKERNSEC_RESLOG
58751+ {
58752+ .procname = "resource_logging",
58753+ .data = &grsec_resource_logging,
58754+ .maxlen = sizeof(int),
58755+ .mode = 0600,
58756+ .proc_handler = &proc_dointvec,
58757+ },
58758+#endif
58759+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58760+ {
58761+ .procname = "audit_ptrace",
58762+ .data = &grsec_enable_audit_ptrace,
58763+ .maxlen = sizeof(int),
58764+ .mode = 0600,
58765+ .proc_handler = &proc_dointvec,
58766+ },
58767+#endif
58768+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58769+ {
58770+ .procname = "harden_ptrace",
58771+ .data = &grsec_enable_harden_ptrace,
58772+ .maxlen = sizeof(int),
58773+ .mode = 0600,
58774+ .proc_handler = &proc_dointvec,
58775+ },
58776+#endif
58777+ {
58778+ .procname = "grsec_lock",
58779+ .data = &grsec_lock,
58780+ .maxlen = sizeof(int),
58781+ .mode = 0600,
58782+ .proc_handler = &proc_dointvec,
58783+ },
58784+#endif
58785+#ifdef CONFIG_GRKERNSEC_ROFS
58786+ {
58787+ .procname = "romount_protect",
58788+ .data = &grsec_enable_rofs,
58789+ .maxlen = sizeof(int),
58790+ .mode = 0600,
58791+ .proc_handler = &proc_dointvec_minmax,
58792+ .extra1 = &one,
58793+ .extra2 = &one,
58794+ },
58795+#endif
58796+ { }
58797+};
58798+#endif
58799diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
58800new file mode 100644
58801index 0000000..0dc13c3
58802--- /dev/null
58803+++ b/grsecurity/grsec_time.c
58804@@ -0,0 +1,16 @@
58805+#include <linux/kernel.h>
58806+#include <linux/sched.h>
58807+#include <linux/grinternal.h>
58808+#include <linux/module.h>
58809+
58810+void
58811+gr_log_timechange(void)
58812+{
58813+#ifdef CONFIG_GRKERNSEC_TIME
58814+ if (grsec_enable_time)
58815+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
58816+#endif
58817+ return;
58818+}
58819+
58820+EXPORT_SYMBOL(gr_log_timechange);
58821diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
58822new file mode 100644
58823index 0000000..07e0dc0
58824--- /dev/null
58825+++ b/grsecurity/grsec_tpe.c
58826@@ -0,0 +1,73 @@
58827+#include <linux/kernel.h>
58828+#include <linux/sched.h>
58829+#include <linux/file.h>
58830+#include <linux/fs.h>
58831+#include <linux/grinternal.h>
58832+
58833+extern int gr_acl_tpe_check(void);
58834+
58835+int
58836+gr_tpe_allow(const struct file *file)
58837+{
58838+#ifdef CONFIG_GRKERNSEC
58839+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
58840+ const struct cred *cred = current_cred();
58841+ char *msg = NULL;
58842+ char *msg2 = NULL;
58843+
58844+ // never restrict root
58845+ if (!cred->uid)
58846+ return 1;
58847+
58848+ if (grsec_enable_tpe) {
58849+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58850+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
58851+ msg = "not being in trusted group";
58852+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
58853+ msg = "being in untrusted group";
58854+#else
58855+ if (in_group_p(grsec_tpe_gid))
58856+ msg = "being in untrusted group";
58857+#endif
58858+ }
58859+ if (!msg && gr_acl_tpe_check())
58860+ msg = "being in untrusted role";
58861+
58862+ // not in any affected group/role
58863+ if (!msg)
58864+ goto next_check;
58865+
58866+ if (inode->i_uid)
58867+ msg2 = "file in non-root-owned directory";
58868+ else if (inode->i_mode & S_IWOTH)
58869+ msg2 = "file in world-writable directory";
58870+ else if (inode->i_mode & S_IWGRP)
58871+ msg2 = "file in group-writable directory";
58872+
58873+ if (msg && msg2) {
58874+ char fullmsg[70] = {0};
58875+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
58876+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
58877+ return 0;
58878+ }
58879+ msg = NULL;
58880+next_check:
58881+#ifdef CONFIG_GRKERNSEC_TPE_ALL
58882+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
58883+ return 1;
58884+
58885+ if (inode->i_uid && (inode->i_uid != cred->uid))
58886+ msg = "directory not owned by user";
58887+ else if (inode->i_mode & S_IWOTH)
58888+ msg = "file in world-writable directory";
58889+ else if (inode->i_mode & S_IWGRP)
58890+ msg = "file in group-writable directory";
58891+
58892+ if (msg) {
58893+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
58894+ return 0;
58895+ }
58896+#endif
58897+#endif
58898+ return 1;
58899+}
58900diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
58901new file mode 100644
58902index 0000000..9f7b1ac
58903--- /dev/null
58904+++ b/grsecurity/grsum.c
58905@@ -0,0 +1,61 @@
58906+#include <linux/err.h>
58907+#include <linux/kernel.h>
58908+#include <linux/sched.h>
58909+#include <linux/mm.h>
58910+#include <linux/scatterlist.h>
58911+#include <linux/crypto.h>
58912+#include <linux/gracl.h>
58913+
58914+
58915+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
58916+#error "crypto and sha256 must be built into the kernel"
58917+#endif
58918+
58919+int
58920+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
58921+{
58922+ char *p;
58923+ struct crypto_hash *tfm;
58924+ struct hash_desc desc;
58925+ struct scatterlist sg;
58926+ unsigned char temp_sum[GR_SHA_LEN];
58927+ volatile int retval = 0;
58928+ volatile int dummy = 0;
58929+ unsigned int i;
58930+
58931+ sg_init_table(&sg, 1);
58932+
58933+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
58934+ if (IS_ERR(tfm)) {
58935+ /* should never happen, since sha256 should be built in */
58936+ return 1;
58937+ }
58938+
58939+ desc.tfm = tfm;
58940+ desc.flags = 0;
58941+
58942+ crypto_hash_init(&desc);
58943+
58944+ p = salt;
58945+ sg_set_buf(&sg, p, GR_SALT_LEN);
58946+ crypto_hash_update(&desc, &sg, sg.length);
58947+
58948+ p = entry->pw;
58949+ sg_set_buf(&sg, p, strlen(p));
58950+
58951+ crypto_hash_update(&desc, &sg, sg.length);
58952+
58953+ crypto_hash_final(&desc, temp_sum);
58954+
58955+ memset(entry->pw, 0, GR_PW_LEN);
58956+
58957+ for (i = 0; i < GR_SHA_LEN; i++)
58958+ if (sum[i] != temp_sum[i])
58959+ retval = 1;
58960+ else
58961+ dummy = 1; // waste a cycle
58962+
58963+ crypto_free_hash(tfm);
58964+
58965+ return retval;
58966+}
58967diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
58968index f1c8ca6..b5c1cc7 100644
58969--- a/include/acpi/acpi_bus.h
58970+++ b/include/acpi/acpi_bus.h
58971@@ -107,7 +107,7 @@ struct acpi_device_ops {
58972 acpi_op_bind bind;
58973 acpi_op_unbind unbind;
58974 acpi_op_notify notify;
58975-};
58976+} __no_const;
58977
58978 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
58979
58980diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
58981index b7babf0..71e4e74 100644
58982--- a/include/asm-generic/atomic-long.h
58983+++ b/include/asm-generic/atomic-long.h
58984@@ -22,6 +22,12 @@
58985
58986 typedef atomic64_t atomic_long_t;
58987
58988+#ifdef CONFIG_PAX_REFCOUNT
58989+typedef atomic64_unchecked_t atomic_long_unchecked_t;
58990+#else
58991+typedef atomic64_t atomic_long_unchecked_t;
58992+#endif
58993+
58994 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
58995
58996 static inline long atomic_long_read(atomic_long_t *l)
58997@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
58998 return (long)atomic64_read(v);
58999 }
59000
59001+#ifdef CONFIG_PAX_REFCOUNT
59002+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59003+{
59004+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59005+
59006+ return (long)atomic64_read_unchecked(v);
59007+}
59008+#endif
59009+
59010 static inline void atomic_long_set(atomic_long_t *l, long i)
59011 {
59012 atomic64_t *v = (atomic64_t *)l;
59013@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59014 atomic64_set(v, i);
59015 }
59016
59017+#ifdef CONFIG_PAX_REFCOUNT
59018+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59019+{
59020+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59021+
59022+ atomic64_set_unchecked(v, i);
59023+}
59024+#endif
59025+
59026 static inline void atomic_long_inc(atomic_long_t *l)
59027 {
59028 atomic64_t *v = (atomic64_t *)l;
59029@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59030 atomic64_inc(v);
59031 }
59032
59033+#ifdef CONFIG_PAX_REFCOUNT
59034+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59035+{
59036+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59037+
59038+ atomic64_inc_unchecked(v);
59039+}
59040+#endif
59041+
59042 static inline void atomic_long_dec(atomic_long_t *l)
59043 {
59044 atomic64_t *v = (atomic64_t *)l;
59045@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59046 atomic64_dec(v);
59047 }
59048
59049+#ifdef CONFIG_PAX_REFCOUNT
59050+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59051+{
59052+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59053+
59054+ atomic64_dec_unchecked(v);
59055+}
59056+#endif
59057+
59058 static inline void atomic_long_add(long i, atomic_long_t *l)
59059 {
59060 atomic64_t *v = (atomic64_t *)l;
59061@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59062 atomic64_add(i, v);
59063 }
59064
59065+#ifdef CONFIG_PAX_REFCOUNT
59066+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59067+{
59068+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59069+
59070+ atomic64_add_unchecked(i, v);
59071+}
59072+#endif
59073+
59074 static inline void atomic_long_sub(long i, atomic_long_t *l)
59075 {
59076 atomic64_t *v = (atomic64_t *)l;
59077@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59078 atomic64_sub(i, v);
59079 }
59080
59081+#ifdef CONFIG_PAX_REFCOUNT
59082+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59083+{
59084+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59085+
59086+ atomic64_sub_unchecked(i, v);
59087+}
59088+#endif
59089+
59090 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59091 {
59092 atomic64_t *v = (atomic64_t *)l;
59093@@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59094 return (long)atomic64_inc_return(v);
59095 }
59096
59097+#ifdef CONFIG_PAX_REFCOUNT
59098+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59099+{
59100+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59101+
59102+ return (long)atomic64_inc_return_unchecked(v);
59103+}
59104+#endif
59105+
59106 static inline long atomic_long_dec_return(atomic_long_t *l)
59107 {
59108 atomic64_t *v = (atomic64_t *)l;
59109@@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59110
59111 typedef atomic_t atomic_long_t;
59112
59113+#ifdef CONFIG_PAX_REFCOUNT
59114+typedef atomic_unchecked_t atomic_long_unchecked_t;
59115+#else
59116+typedef atomic_t atomic_long_unchecked_t;
59117+#endif
59118+
59119 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
59120 static inline long atomic_long_read(atomic_long_t *l)
59121 {
59122@@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59123 return (long)atomic_read(v);
59124 }
59125
59126+#ifdef CONFIG_PAX_REFCOUNT
59127+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59128+{
59129+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59130+
59131+ return (long)atomic_read_unchecked(v);
59132+}
59133+#endif
59134+
59135 static inline void atomic_long_set(atomic_long_t *l, long i)
59136 {
59137 atomic_t *v = (atomic_t *)l;
59138@@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59139 atomic_set(v, i);
59140 }
59141
59142+#ifdef CONFIG_PAX_REFCOUNT
59143+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59144+{
59145+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59146+
59147+ atomic_set_unchecked(v, i);
59148+}
59149+#endif
59150+
59151 static inline void atomic_long_inc(atomic_long_t *l)
59152 {
59153 atomic_t *v = (atomic_t *)l;
59154@@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59155 atomic_inc(v);
59156 }
59157
59158+#ifdef CONFIG_PAX_REFCOUNT
59159+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59160+{
59161+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59162+
59163+ atomic_inc_unchecked(v);
59164+}
59165+#endif
59166+
59167 static inline void atomic_long_dec(atomic_long_t *l)
59168 {
59169 atomic_t *v = (atomic_t *)l;
59170@@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59171 atomic_dec(v);
59172 }
59173
59174+#ifdef CONFIG_PAX_REFCOUNT
59175+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59176+{
59177+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59178+
59179+ atomic_dec_unchecked(v);
59180+}
59181+#endif
59182+
59183 static inline void atomic_long_add(long i, atomic_long_t *l)
59184 {
59185 atomic_t *v = (atomic_t *)l;
59186@@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59187 atomic_add(i, v);
59188 }
59189
59190+#ifdef CONFIG_PAX_REFCOUNT
59191+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59192+{
59193+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59194+
59195+ atomic_add_unchecked(i, v);
59196+}
59197+#endif
59198+
59199 static inline void atomic_long_sub(long i, atomic_long_t *l)
59200 {
59201 atomic_t *v = (atomic_t *)l;
59202@@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59203 atomic_sub(i, v);
59204 }
59205
59206+#ifdef CONFIG_PAX_REFCOUNT
59207+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59208+{
59209+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59210+
59211+ atomic_sub_unchecked(i, v);
59212+}
59213+#endif
59214+
59215 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59216 {
59217 atomic_t *v = (atomic_t *)l;
59218@@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59219 return (long)atomic_inc_return(v);
59220 }
59221
59222+#ifdef CONFIG_PAX_REFCOUNT
59223+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59224+{
59225+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59226+
59227+ return (long)atomic_inc_return_unchecked(v);
59228+}
59229+#endif
59230+
59231 static inline long atomic_long_dec_return(atomic_long_t *l)
59232 {
59233 atomic_t *v = (atomic_t *)l;
59234@@ -255,4 +393,49 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59235
59236 #endif /* BITS_PER_LONG == 64 */
59237
59238+#ifdef CONFIG_PAX_REFCOUNT
59239+static inline void pax_refcount_needs_these_functions(void)
59240+{
59241+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
59242+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
59243+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
59244+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
59245+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
59246+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
59247+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
59248+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
59249+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
59250+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
59251+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
59252+
59253+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
59254+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
59255+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
59256+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
59257+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
59258+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
59259+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
59260+}
59261+#else
59262+#define atomic_read_unchecked(v) atomic_read(v)
59263+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
59264+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
59265+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
59266+#define atomic_inc_unchecked(v) atomic_inc(v)
59267+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
59268+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
59269+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
59270+#define atomic_dec_unchecked(v) atomic_dec(v)
59271+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
59272+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
59273+
59274+#define atomic_long_read_unchecked(v) atomic_long_read(v)
59275+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
59276+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
59277+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
59278+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
59279+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
59280+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
59281+#endif
59282+
59283 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
59284diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
59285index b18ce4f..2ee2843 100644
59286--- a/include/asm-generic/atomic64.h
59287+++ b/include/asm-generic/atomic64.h
59288@@ -16,6 +16,8 @@ typedef struct {
59289 long long counter;
59290 } atomic64_t;
59291
59292+typedef atomic64_t atomic64_unchecked_t;
59293+
59294 #define ATOMIC64_INIT(i) { (i) }
59295
59296 extern long long atomic64_read(const atomic64_t *v);
59297@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
59298 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
59299 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
59300
59301+#define atomic64_read_unchecked(v) atomic64_read(v)
59302+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
59303+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
59304+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
59305+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
59306+#define atomic64_inc_unchecked(v) atomic64_inc(v)
59307+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
59308+#define atomic64_dec_unchecked(v) atomic64_dec(v)
59309+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
59310+
59311 #endif /* _ASM_GENERIC_ATOMIC64_H */
59312diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
59313index 1bfcfe5..e04c5c9 100644
59314--- a/include/asm-generic/cache.h
59315+++ b/include/asm-generic/cache.h
59316@@ -6,7 +6,7 @@
59317 * cache lines need to provide their own cache.h.
59318 */
59319
59320-#define L1_CACHE_SHIFT 5
59321-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
59322+#define L1_CACHE_SHIFT 5UL
59323+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
59324
59325 #endif /* __ASM_GENERIC_CACHE_H */
59326diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
59327index 0d68a1e..b74a761 100644
59328--- a/include/asm-generic/emergency-restart.h
59329+++ b/include/asm-generic/emergency-restart.h
59330@@ -1,7 +1,7 @@
59331 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
59332 #define _ASM_GENERIC_EMERGENCY_RESTART_H
59333
59334-static inline void machine_emergency_restart(void)
59335+static inline __noreturn void machine_emergency_restart(void)
59336 {
59337 machine_restart(NULL);
59338 }
59339diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
59340index 0232ccb..13d9165 100644
59341--- a/include/asm-generic/kmap_types.h
59342+++ b/include/asm-generic/kmap_types.h
59343@@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
59344 KMAP_D(17) KM_NMI,
59345 KMAP_D(18) KM_NMI_PTE,
59346 KMAP_D(19) KM_KDB,
59347+KMAP_D(20) KM_CLEARPAGE,
59348 /*
59349 * Remember to update debug_kmap_atomic() when adding new kmap types!
59350 */
59351-KMAP_D(20) KM_TYPE_NR
59352+KMAP_D(21) KM_TYPE_NR
59353 };
59354
59355 #undef KMAP_D
59356diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
59357index 9ceb03b..2efbcbd 100644
59358--- a/include/asm-generic/local.h
59359+++ b/include/asm-generic/local.h
59360@@ -39,6 +39,7 @@ typedef struct
59361 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
59362 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
59363 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
59364+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
59365
59366 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
59367 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
59368diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
59369index 725612b..9cc513a 100644
59370--- a/include/asm-generic/pgtable-nopmd.h
59371+++ b/include/asm-generic/pgtable-nopmd.h
59372@@ -1,14 +1,19 @@
59373 #ifndef _PGTABLE_NOPMD_H
59374 #define _PGTABLE_NOPMD_H
59375
59376-#ifndef __ASSEMBLY__
59377-
59378 #include <asm-generic/pgtable-nopud.h>
59379
59380-struct mm_struct;
59381-
59382 #define __PAGETABLE_PMD_FOLDED
59383
59384+#define PMD_SHIFT PUD_SHIFT
59385+#define PTRS_PER_PMD 1
59386+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
59387+#define PMD_MASK (~(PMD_SIZE-1))
59388+
59389+#ifndef __ASSEMBLY__
59390+
59391+struct mm_struct;
59392+
59393 /*
59394 * Having the pmd type consist of a pud gets the size right, and allows
59395 * us to conceptually access the pud entry that this pmd is folded into
59396@@ -16,11 +21,6 @@ struct mm_struct;
59397 */
59398 typedef struct { pud_t pud; } pmd_t;
59399
59400-#define PMD_SHIFT PUD_SHIFT
59401-#define PTRS_PER_PMD 1
59402-#define PMD_SIZE (1UL << PMD_SHIFT)
59403-#define PMD_MASK (~(PMD_SIZE-1))
59404-
59405 /*
59406 * The "pud_xxx()" functions here are trivial for a folded two-level
59407 * setup: the pmd is never bad, and a pmd always exists (as it's folded
59408diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
59409index 810431d..0ec4804f 100644
59410--- a/include/asm-generic/pgtable-nopud.h
59411+++ b/include/asm-generic/pgtable-nopud.h
59412@@ -1,10 +1,15 @@
59413 #ifndef _PGTABLE_NOPUD_H
59414 #define _PGTABLE_NOPUD_H
59415
59416-#ifndef __ASSEMBLY__
59417-
59418 #define __PAGETABLE_PUD_FOLDED
59419
59420+#define PUD_SHIFT PGDIR_SHIFT
59421+#define PTRS_PER_PUD 1
59422+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
59423+#define PUD_MASK (~(PUD_SIZE-1))
59424+
59425+#ifndef __ASSEMBLY__
59426+
59427 /*
59428 * Having the pud type consist of a pgd gets the size right, and allows
59429 * us to conceptually access the pgd entry that this pud is folded into
59430@@ -12,11 +17,6 @@
59431 */
59432 typedef struct { pgd_t pgd; } pud_t;
59433
59434-#define PUD_SHIFT PGDIR_SHIFT
59435-#define PTRS_PER_PUD 1
59436-#define PUD_SIZE (1UL << PUD_SHIFT)
59437-#define PUD_MASK (~(PUD_SIZE-1))
59438-
59439 /*
59440 * The "pgd_xxx()" functions here are trivial for a folded two-level
59441 * setup: the pud is never bad, and a pud always exists (as it's folded
59442@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
59443 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
59444
59445 #define pgd_populate(mm, pgd, pud) do { } while (0)
59446+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
59447 /*
59448 * (puds are folded into pgds so this doesn't get actually called,
59449 * but the define is needed for a generic inline function.)
59450diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
59451index 125c54e..e95c18e 100644
59452--- a/include/asm-generic/pgtable.h
59453+++ b/include/asm-generic/pgtable.h
59454@@ -446,6 +446,18 @@ static inline int pmd_write(pmd_t pmd)
59455 #endif /* __HAVE_ARCH_PMD_WRITE */
59456 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
59457
59458+#ifndef __HAVE_ARCH_READ_PMD_ATOMIC
59459+static inline pmd_t read_pmd_atomic(pmd_t *pmdp)
59460+{
59461+ /*
59462+ * Depend on compiler for an atomic pmd read. NOTE: this is
59463+ * only going to work, if the pmdval_t isn't larger than
59464+ * an unsigned long.
59465+ */
59466+ return *pmdp;
59467+}
59468+#endif /* __HAVE_ARCH_READ_PMD_ATOMIC */
59469+
59470 /*
59471 * This function is meant to be used by sites walking pagetables with
59472 * the mmap_sem hold in read mode to protect against MADV_DONTNEED and
59473@@ -459,11 +471,17 @@ static inline int pmd_write(pmd_t pmd)
59474 * undefined so behaving like if the pmd was none is safe (because it
59475 * can return none anyway). The compiler level barrier() is critically
59476 * important to compute the two checks atomically on the same pmdval.
59477+ *
59478+ * For 32bit kernels with a 64bit large pmd_t this automatically takes
59479+ * care of reading the pmd atomically to avoid SMP race conditions
59480+ * against pmd_populate() when the mmap_sem is hold for reading by the
59481+ * caller (a special atomic read not done by "gcc" as in the generic
59482+ * version above, is also needed when THP is disabled because the page
59483+ * fault can populate the pmd from under us).
59484 */
59485 static inline int pmd_none_or_trans_huge_or_clear_bad(pmd_t *pmd)
59486 {
59487- /* depend on compiler for an atomic pmd read */
59488- pmd_t pmdval = *pmd;
59489+ pmd_t pmdval = read_pmd_atomic(pmd);
59490 /*
59491 * The barrier will stabilize the pmdval in a register or on
59492 * the stack so that it will stop changing under the code.
59493@@ -503,6 +521,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
59494 #endif
59495 }
59496
59497+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
59498+static inline unsigned long pax_open_kernel(void) { return 0; }
59499+#endif
59500+
59501+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
59502+static inline unsigned long pax_close_kernel(void) { return 0; }
59503+#endif
59504+
59505 #endif /* CONFIG_MMU */
59506
59507 #endif /* !__ASSEMBLY__ */
59508diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
59509index 8aeadf6..f1dc019 100644
59510--- a/include/asm-generic/vmlinux.lds.h
59511+++ b/include/asm-generic/vmlinux.lds.h
59512@@ -218,6 +218,7 @@
59513 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
59514 VMLINUX_SYMBOL(__start_rodata) = .; \
59515 *(.rodata) *(.rodata.*) \
59516+ *(.data..read_only) \
59517 *(__vermagic) /* Kernel version magic */ \
59518 . = ALIGN(8); \
59519 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
59520@@ -716,17 +717,18 @@
59521 * section in the linker script will go there too. @phdr should have
59522 * a leading colon.
59523 *
59524- * Note that this macros defines __per_cpu_load as an absolute symbol.
59525+ * Note that this macros defines per_cpu_load as an absolute symbol.
59526 * If there is no need to put the percpu section at a predetermined
59527 * address, use PERCPU_SECTION.
59528 */
59529 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
59530- VMLINUX_SYMBOL(__per_cpu_load) = .; \
59531- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
59532+ per_cpu_load = .; \
59533+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
59534 - LOAD_OFFSET) { \
59535+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
59536 PERCPU_INPUT(cacheline) \
59537 } phdr \
59538- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
59539+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
59540
59541 /**
59542 * PERCPU_SECTION - define output section for percpu area, simple version
59543diff --git a/include/drm/drmP.h b/include/drm/drmP.h
59544index dd73104..fde86bd 100644
59545--- a/include/drm/drmP.h
59546+++ b/include/drm/drmP.h
59547@@ -72,6 +72,7 @@
59548 #include <linux/workqueue.h>
59549 #include <linux/poll.h>
59550 #include <asm/pgalloc.h>
59551+#include <asm/local.h>
59552 #include "drm.h"
59553
59554 #include <linux/idr.h>
59555@@ -1074,7 +1075,7 @@ struct drm_device {
59556
59557 /** \name Usage Counters */
59558 /*@{ */
59559- int open_count; /**< Outstanding files open */
59560+ local_t open_count; /**< Outstanding files open */
59561 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
59562 atomic_t vma_count; /**< Outstanding vma areas open */
59563 int buf_use; /**< Buffers in use -- cannot alloc */
59564@@ -1085,7 +1086,7 @@ struct drm_device {
59565 /*@{ */
59566 unsigned long counters;
59567 enum drm_stat_type types[15];
59568- atomic_t counts[15];
59569+ atomic_unchecked_t counts[15];
59570 /*@} */
59571
59572 struct list_head filelist;
59573diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
59574index 37515d1..34fa8b0 100644
59575--- a/include/drm/drm_crtc_helper.h
59576+++ b/include/drm/drm_crtc_helper.h
59577@@ -74,7 +74,7 @@ struct drm_crtc_helper_funcs {
59578
59579 /* disable crtc when not in use - more explicit than dpms off */
59580 void (*disable)(struct drm_crtc *crtc);
59581-};
59582+} __no_const;
59583
59584 struct drm_encoder_helper_funcs {
59585 void (*dpms)(struct drm_encoder *encoder, int mode);
59586@@ -95,7 +95,7 @@ struct drm_encoder_helper_funcs {
59587 struct drm_connector *connector);
59588 /* disable encoder when not in use - more explicit than dpms off */
59589 void (*disable)(struct drm_encoder *encoder);
59590-};
59591+} __no_const;
59592
59593 struct drm_connector_helper_funcs {
59594 int (*get_modes)(struct drm_connector *connector);
59595diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
59596index d6d1da4..fdd1ac5 100644
59597--- a/include/drm/ttm/ttm_memory.h
59598+++ b/include/drm/ttm/ttm_memory.h
59599@@ -48,7 +48,7 @@
59600
59601 struct ttm_mem_shrink {
59602 int (*do_shrink) (struct ttm_mem_shrink *);
59603-};
59604+} __no_const;
59605
59606 /**
59607 * struct ttm_mem_global - Global memory accounting structure.
59608diff --git a/include/linux/a.out.h b/include/linux/a.out.h
59609index e86dfca..40cc55f 100644
59610--- a/include/linux/a.out.h
59611+++ b/include/linux/a.out.h
59612@@ -39,6 +39,14 @@ enum machine_type {
59613 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
59614 };
59615
59616+/* Constants for the N_FLAGS field */
59617+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
59618+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
59619+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
59620+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
59621+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
59622+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
59623+
59624 #if !defined (N_MAGIC)
59625 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
59626 #endif
59627diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
59628index 06fd4bb..1caec0d 100644
59629--- a/include/linux/atmdev.h
59630+++ b/include/linux/atmdev.h
59631@@ -237,7 +237,7 @@ struct compat_atm_iobuf {
59632 #endif
59633
59634 struct k_atm_aal_stats {
59635-#define __HANDLE_ITEM(i) atomic_t i
59636+#define __HANDLE_ITEM(i) atomic_unchecked_t i
59637 __AAL_STAT_ITEMS
59638 #undef __HANDLE_ITEM
59639 };
59640diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
59641index 366422b..1fa7f84 100644
59642--- a/include/linux/binfmts.h
59643+++ b/include/linux/binfmts.h
59644@@ -89,6 +89,7 @@ struct linux_binfmt {
59645 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
59646 int (*load_shlib)(struct file *);
59647 int (*core_dump)(struct coredump_params *cprm);
59648+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
59649 unsigned long min_coredump; /* minimal dump size */
59650 };
59651
59652diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
59653index 4d4ac24..2c3ccce 100644
59654--- a/include/linux/blkdev.h
59655+++ b/include/linux/blkdev.h
59656@@ -1376,7 +1376,7 @@ struct block_device_operations {
59657 /* this callback is with swap_lock and sometimes page table lock held */
59658 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
59659 struct module *owner;
59660-};
59661+} __do_const;
59662
59663 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
59664 unsigned long);
59665diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
59666index 4d1a074..88f929a 100644
59667--- a/include/linux/blktrace_api.h
59668+++ b/include/linux/blktrace_api.h
59669@@ -162,7 +162,7 @@ struct blk_trace {
59670 struct dentry *dir;
59671 struct dentry *dropped_file;
59672 struct dentry *msg_file;
59673- atomic_t dropped;
59674+ atomic_unchecked_t dropped;
59675 };
59676
59677 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
59678diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
59679index 83195fb..0b0f77d 100644
59680--- a/include/linux/byteorder/little_endian.h
59681+++ b/include/linux/byteorder/little_endian.h
59682@@ -42,51 +42,51 @@
59683
59684 static inline __le64 __cpu_to_le64p(const __u64 *p)
59685 {
59686- return (__force __le64)*p;
59687+ return (__force const __le64)*p;
59688 }
59689 static inline __u64 __le64_to_cpup(const __le64 *p)
59690 {
59691- return (__force __u64)*p;
59692+ return (__force const __u64)*p;
59693 }
59694 static inline __le32 __cpu_to_le32p(const __u32 *p)
59695 {
59696- return (__force __le32)*p;
59697+ return (__force const __le32)*p;
59698 }
59699 static inline __u32 __le32_to_cpup(const __le32 *p)
59700 {
59701- return (__force __u32)*p;
59702+ return (__force const __u32)*p;
59703 }
59704 static inline __le16 __cpu_to_le16p(const __u16 *p)
59705 {
59706- return (__force __le16)*p;
59707+ return (__force const __le16)*p;
59708 }
59709 static inline __u16 __le16_to_cpup(const __le16 *p)
59710 {
59711- return (__force __u16)*p;
59712+ return (__force const __u16)*p;
59713 }
59714 static inline __be64 __cpu_to_be64p(const __u64 *p)
59715 {
59716- return (__force __be64)__swab64p(p);
59717+ return (__force const __be64)__swab64p(p);
59718 }
59719 static inline __u64 __be64_to_cpup(const __be64 *p)
59720 {
59721- return __swab64p((__u64 *)p);
59722+ return __swab64p((const __u64 *)p);
59723 }
59724 static inline __be32 __cpu_to_be32p(const __u32 *p)
59725 {
59726- return (__force __be32)__swab32p(p);
59727+ return (__force const __be32)__swab32p(p);
59728 }
59729 static inline __u32 __be32_to_cpup(const __be32 *p)
59730 {
59731- return __swab32p((__u32 *)p);
59732+ return __swab32p((const __u32 *)p);
59733 }
59734 static inline __be16 __cpu_to_be16p(const __u16 *p)
59735 {
59736- return (__force __be16)__swab16p(p);
59737+ return (__force const __be16)__swab16p(p);
59738 }
59739 static inline __u16 __be16_to_cpup(const __be16 *p)
59740 {
59741- return __swab16p((__u16 *)p);
59742+ return __swab16p((const __u16 *)p);
59743 }
59744 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
59745 #define __le64_to_cpus(x) do { (void)(x); } while (0)
59746diff --git a/include/linux/cache.h b/include/linux/cache.h
59747index 4c57065..4307975 100644
59748--- a/include/linux/cache.h
59749+++ b/include/linux/cache.h
59750@@ -16,6 +16,10 @@
59751 #define __read_mostly
59752 #endif
59753
59754+#ifndef __read_only
59755+#define __read_only __read_mostly
59756+#endif
59757+
59758 #ifndef ____cacheline_aligned
59759 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
59760 #endif
59761diff --git a/include/linux/capability.h b/include/linux/capability.h
59762index 12d52de..b5f7fa7 100644
59763--- a/include/linux/capability.h
59764+++ b/include/linux/capability.h
59765@@ -548,6 +548,8 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
59766 extern bool capable(int cap);
59767 extern bool ns_capable(struct user_namespace *ns, int cap);
59768 extern bool nsown_capable(int cap);
59769+extern bool capable_nolog(int cap);
59770+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
59771
59772 /* audit system wants to get cap info from files as well */
59773 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
59774diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
59775index 42e55de..1cd0e66 100644
59776--- a/include/linux/cleancache.h
59777+++ b/include/linux/cleancache.h
59778@@ -31,7 +31,7 @@ struct cleancache_ops {
59779 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
59780 void (*invalidate_inode)(int, struct cleancache_filekey);
59781 void (*invalidate_fs)(int);
59782-};
59783+} __no_const;
59784
59785 extern struct cleancache_ops
59786 cleancache_register_ops(struct cleancache_ops *ops);
59787diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
59788index 2f40791..a62d196 100644
59789--- a/include/linux/compiler-gcc4.h
59790+++ b/include/linux/compiler-gcc4.h
59791@@ -32,6 +32,16 @@
59792 #define __linktime_error(message) __attribute__((__error__(message)))
59793
59794 #if __GNUC_MINOR__ >= 5
59795+
59796+#ifdef CONSTIFY_PLUGIN
59797+#define __no_const __attribute__((no_const))
59798+#define __do_const __attribute__((do_const))
59799+#endif
59800+
59801+#ifdef SIZE_OVERFLOW_PLUGIN
59802+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
59803+#endif
59804+
59805 /*
59806 * Mark a position in code as unreachable. This can be used to
59807 * suppress control flow warnings after asm blocks that transfer
59808@@ -47,6 +57,11 @@
59809 #define __noclone __attribute__((__noclone__))
59810
59811 #endif
59812+
59813+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
59814+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
59815+#define __bos0(ptr) __bos((ptr), 0)
59816+#define __bos1(ptr) __bos((ptr), 1)
59817 #endif
59818
59819 #if __GNUC_MINOR__ > 0
59820diff --git a/include/linux/compiler.h b/include/linux/compiler.h
59821index 923d093..726c17f 100644
59822--- a/include/linux/compiler.h
59823+++ b/include/linux/compiler.h
59824@@ -5,31 +5,62 @@
59825
59826 #ifdef __CHECKER__
59827 # define __user __attribute__((noderef, address_space(1)))
59828+# define __force_user __force __user
59829 # define __kernel __attribute__((address_space(0)))
59830+# define __force_kernel __force __kernel
59831 # define __safe __attribute__((safe))
59832 # define __force __attribute__((force))
59833 # define __nocast __attribute__((nocast))
59834 # define __iomem __attribute__((noderef, address_space(2)))
59835+# define __force_iomem __force __iomem
59836 # define __acquires(x) __attribute__((context(x,0,1)))
59837 # define __releases(x) __attribute__((context(x,1,0)))
59838 # define __acquire(x) __context__(x,1)
59839 # define __release(x) __context__(x,-1)
59840 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
59841 # define __percpu __attribute__((noderef, address_space(3)))
59842+# define __force_percpu __force __percpu
59843 #ifdef CONFIG_SPARSE_RCU_POINTER
59844 # define __rcu __attribute__((noderef, address_space(4)))
59845+# define __force_rcu __force __rcu
59846 #else
59847 # define __rcu
59848+# define __force_rcu
59849 #endif
59850 extern void __chk_user_ptr(const volatile void __user *);
59851 extern void __chk_io_ptr(const volatile void __iomem *);
59852+#elif defined(CHECKER_PLUGIN)
59853+//# define __user
59854+//# define __force_user
59855+//# define __kernel
59856+//# define __force_kernel
59857+# define __safe
59858+# define __force
59859+# define __nocast
59860+# define __iomem
59861+# define __force_iomem
59862+# define __chk_user_ptr(x) (void)0
59863+# define __chk_io_ptr(x) (void)0
59864+# define __builtin_warning(x, y...) (1)
59865+# define __acquires(x)
59866+# define __releases(x)
59867+# define __acquire(x) (void)0
59868+# define __release(x) (void)0
59869+# define __cond_lock(x,c) (c)
59870+# define __percpu
59871+# define __force_percpu
59872+# define __rcu
59873+# define __force_rcu
59874 #else
59875 # define __user
59876+# define __force_user
59877 # define __kernel
59878+# define __force_kernel
59879 # define __safe
59880 # define __force
59881 # define __nocast
59882 # define __iomem
59883+# define __force_iomem
59884 # define __chk_user_ptr(x) (void)0
59885 # define __chk_io_ptr(x) (void)0
59886 # define __builtin_warning(x, y...) (1)
59887@@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
59888 # define __release(x) (void)0
59889 # define __cond_lock(x,c) (c)
59890 # define __percpu
59891+# define __force_percpu
59892 # define __rcu
59893+# define __force_rcu
59894 #endif
59895
59896 #ifdef __KERNEL__
59897@@ -264,6 +297,18 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
59898 # define __attribute_const__ /* unimplemented */
59899 #endif
59900
59901+#ifndef __no_const
59902+# define __no_const
59903+#endif
59904+
59905+#ifndef __do_const
59906+# define __do_const
59907+#endif
59908+
59909+#ifndef __size_overflow
59910+# define __size_overflow(...)
59911+#endif
59912+
59913 /*
59914 * Tell gcc if a function is cold. The compiler will assume any path
59915 * directly leading to the call is unlikely.
59916@@ -273,6 +318,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
59917 #define __cold
59918 #endif
59919
59920+#ifndef __alloc_size
59921+#define __alloc_size(...)
59922+#endif
59923+
59924+#ifndef __bos
59925+#define __bos(ptr, arg)
59926+#endif
59927+
59928+#ifndef __bos0
59929+#define __bos0(ptr)
59930+#endif
59931+
59932+#ifndef __bos1
59933+#define __bos1(ptr)
59934+#endif
59935+
59936 /* Simple shorthand for a section definition */
59937 #ifndef __section
59938 # define __section(S) __attribute__ ((__section__(#S)))
59939@@ -308,6 +369,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
59940 * use is to mediate communication between process-level code and irq/NMI
59941 * handlers, all running on the same CPU.
59942 */
59943-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
59944+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
59945+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
59946
59947 #endif /* __LINUX_COMPILER_H */
59948diff --git a/include/linux/cred.h b/include/linux/cred.h
59949index adadf71..6af5560 100644
59950--- a/include/linux/cred.h
59951+++ b/include/linux/cred.h
59952@@ -207,6 +207,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
59953 static inline void validate_process_creds(void)
59954 {
59955 }
59956+static inline void validate_task_creds(struct task_struct *task)
59957+{
59958+}
59959 #endif
59960
59961 /**
59962diff --git a/include/linux/crypto.h b/include/linux/crypto.h
59963index b92eadf..b4ecdc1 100644
59964--- a/include/linux/crypto.h
59965+++ b/include/linux/crypto.h
59966@@ -373,7 +373,7 @@ struct cipher_tfm {
59967 const u8 *key, unsigned int keylen);
59968 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
59969 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
59970-};
59971+} __no_const;
59972
59973 struct hash_tfm {
59974 int (*init)(struct hash_desc *desc);
59975@@ -394,13 +394,13 @@ struct compress_tfm {
59976 int (*cot_decompress)(struct crypto_tfm *tfm,
59977 const u8 *src, unsigned int slen,
59978 u8 *dst, unsigned int *dlen);
59979-};
59980+} __no_const;
59981
59982 struct rng_tfm {
59983 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
59984 unsigned int dlen);
59985 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
59986-};
59987+} __no_const;
59988
59989 #define crt_ablkcipher crt_u.ablkcipher
59990 #define crt_aead crt_u.aead
59991diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
59992index 7925bf0..d5143d2 100644
59993--- a/include/linux/decompress/mm.h
59994+++ b/include/linux/decompress/mm.h
59995@@ -77,7 +77,7 @@ static void free(void *where)
59996 * warnings when not needed (indeed large_malloc / large_free are not
59997 * needed by inflate */
59998
59999-#define malloc(a) kmalloc(a, GFP_KERNEL)
60000+#define malloc(a) kmalloc((a), GFP_KERNEL)
60001 #define free(a) kfree(a)
60002
60003 #define large_malloc(a) vmalloc(a)
60004diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
60005index dfc099e..e583e66 100644
60006--- a/include/linux/dma-mapping.h
60007+++ b/include/linux/dma-mapping.h
60008@@ -51,7 +51,7 @@ struct dma_map_ops {
60009 u64 (*get_required_mask)(struct device *dev);
60010 #endif
60011 int is_phys;
60012-};
60013+} __do_const;
60014
60015 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
60016
60017diff --git a/include/linux/efi.h b/include/linux/efi.h
60018index ec45ccd..9923c32 100644
60019--- a/include/linux/efi.h
60020+++ b/include/linux/efi.h
60021@@ -635,7 +635,7 @@ struct efivar_operations {
60022 efi_get_variable_t *get_variable;
60023 efi_get_next_variable_t *get_next_variable;
60024 efi_set_variable_t *set_variable;
60025-};
60026+} __no_const;
60027
60028 struct efivars {
60029 /*
60030diff --git a/include/linux/elf.h b/include/linux/elf.h
60031index 999b4f5..57753b4 100644
60032--- a/include/linux/elf.h
60033+++ b/include/linux/elf.h
60034@@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
60035 #define PT_GNU_EH_FRAME 0x6474e550
60036
60037 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
60038+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
60039+
60040+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
60041+
60042+/* Constants for the e_flags field */
60043+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60044+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
60045+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
60046+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
60047+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60048+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60049
60050 /*
60051 * Extended Numbering
60052@@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
60053 #define DT_DEBUG 21
60054 #define DT_TEXTREL 22
60055 #define DT_JMPREL 23
60056+#define DT_FLAGS 30
60057+ #define DF_TEXTREL 0x00000004
60058 #define DT_ENCODING 32
60059 #define OLD_DT_LOOS 0x60000000
60060 #define DT_LOOS 0x6000000d
60061@@ -243,6 +256,19 @@ typedef struct elf64_hdr {
60062 #define PF_W 0x2
60063 #define PF_X 0x1
60064
60065+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
60066+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
60067+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
60068+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
60069+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
60070+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
60071+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
60072+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
60073+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
60074+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
60075+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
60076+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
60077+
60078 typedef struct elf32_phdr{
60079 Elf32_Word p_type;
60080 Elf32_Off p_offset;
60081@@ -335,6 +361,8 @@ typedef struct elf64_shdr {
60082 #define EI_OSABI 7
60083 #define EI_PAD 8
60084
60085+#define EI_PAX 14
60086+
60087 #define ELFMAG0 0x7f /* EI_MAG */
60088 #define ELFMAG1 'E'
60089 #define ELFMAG2 'L'
60090@@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
60091 #define elf_note elf32_note
60092 #define elf_addr_t Elf32_Off
60093 #define Elf_Half Elf32_Half
60094+#define elf_dyn Elf32_Dyn
60095
60096 #else
60097
60098@@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
60099 #define elf_note elf64_note
60100 #define elf_addr_t Elf64_Off
60101 #define Elf_Half Elf64_Half
60102+#define elf_dyn Elf64_Dyn
60103
60104 #endif
60105
60106diff --git a/include/linux/filter.h b/include/linux/filter.h
60107index 8eeb205..d59bfa2 100644
60108--- a/include/linux/filter.h
60109+++ b/include/linux/filter.h
60110@@ -134,6 +134,7 @@ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
60111
60112 struct sk_buff;
60113 struct sock;
60114+struct bpf_jit_work;
60115
60116 struct sk_filter
60117 {
60118@@ -141,6 +142,9 @@ struct sk_filter
60119 unsigned int len; /* Number of filter blocks */
60120 unsigned int (*bpf_func)(const struct sk_buff *skb,
60121 const struct sock_filter *filter);
60122+#ifdef CONFIG_BPF_JIT
60123+ struct bpf_jit_work *work;
60124+#endif
60125 struct rcu_head rcu;
60126 struct sock_filter insns[0];
60127 };
60128diff --git a/include/linux/firewire.h b/include/linux/firewire.h
60129index cdc9b71..ce69fb5 100644
60130--- a/include/linux/firewire.h
60131+++ b/include/linux/firewire.h
60132@@ -413,7 +413,7 @@ struct fw_iso_context {
60133 union {
60134 fw_iso_callback_t sc;
60135 fw_iso_mc_callback_t mc;
60136- } callback;
60137+ } __no_const callback;
60138 void *callback_data;
60139 };
60140
60141diff --git a/include/linux/fs.h b/include/linux/fs.h
60142index 25c40b9..1bfd4f4 100644
60143--- a/include/linux/fs.h
60144+++ b/include/linux/fs.h
60145@@ -1634,7 +1634,8 @@ struct file_operations {
60146 int (*setlease)(struct file *, long, struct file_lock **);
60147 long (*fallocate)(struct file *file, int mode, loff_t offset,
60148 loff_t len);
60149-};
60150+} __do_const;
60151+typedef struct file_operations __no_const file_operations_no_const;
60152
60153 struct inode_operations {
60154 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
60155diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
60156index 003dc0f..3c4ea97 100644
60157--- a/include/linux/fs_struct.h
60158+++ b/include/linux/fs_struct.h
60159@@ -6,7 +6,7 @@
60160 #include <linux/seqlock.h>
60161
60162 struct fs_struct {
60163- int users;
60164+ atomic_t users;
60165 spinlock_t lock;
60166 seqcount_t seq;
60167 int umask;
60168diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
60169index ce31408..b1ad003 100644
60170--- a/include/linux/fscache-cache.h
60171+++ b/include/linux/fscache-cache.h
60172@@ -102,7 +102,7 @@ struct fscache_operation {
60173 fscache_operation_release_t release;
60174 };
60175
60176-extern atomic_t fscache_op_debug_id;
60177+extern atomic_unchecked_t fscache_op_debug_id;
60178 extern void fscache_op_work_func(struct work_struct *work);
60179
60180 extern void fscache_enqueue_operation(struct fscache_operation *);
60181@@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
60182 {
60183 INIT_WORK(&op->work, fscache_op_work_func);
60184 atomic_set(&op->usage, 1);
60185- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
60186+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60187 op->processor = processor;
60188 op->release = release;
60189 INIT_LIST_HEAD(&op->pend_link);
60190diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
60191index a6dfe69..569586df 100644
60192--- a/include/linux/fsnotify.h
60193+++ b/include/linux/fsnotify.h
60194@@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
60195 */
60196 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
60197 {
60198- return kstrdup(name, GFP_KERNEL);
60199+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
60200 }
60201
60202 /*
60203diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
60204index 91d0e0a3..035666b 100644
60205--- a/include/linux/fsnotify_backend.h
60206+++ b/include/linux/fsnotify_backend.h
60207@@ -105,6 +105,7 @@ struct fsnotify_ops {
60208 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
60209 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
60210 };
60211+typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
60212
60213 /*
60214 * A group is a "thing" that wants to receive notification about filesystem
60215diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
60216index 176a939..1462211 100644
60217--- a/include/linux/ftrace_event.h
60218+++ b/include/linux/ftrace_event.h
60219@@ -97,7 +97,7 @@ struct trace_event_functions {
60220 trace_print_func raw;
60221 trace_print_func hex;
60222 trace_print_func binary;
60223-};
60224+} __no_const;
60225
60226 struct trace_event {
60227 struct hlist_node node;
60228@@ -263,7 +263,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
60229 extern int trace_add_event_call(struct ftrace_event_call *call);
60230 extern void trace_remove_event_call(struct ftrace_event_call *call);
60231
60232-#define is_signed_type(type) (((type)(-1)) < 0)
60233+#define is_signed_type(type) (((type)(-1)) < (type)1)
60234
60235 int trace_set_clr_event(const char *system, const char *event, int set);
60236
60237diff --git a/include/linux/genhd.h b/include/linux/genhd.h
60238index 017a7fb..33a8507 100644
60239--- a/include/linux/genhd.h
60240+++ b/include/linux/genhd.h
60241@@ -185,7 +185,7 @@ struct gendisk {
60242 struct kobject *slave_dir;
60243
60244 struct timer_rand_state *random;
60245- atomic_t sync_io; /* RAID */
60246+ atomic_unchecked_t sync_io; /* RAID */
60247 struct disk_events *ev;
60248 #ifdef CONFIG_BLK_DEV_INTEGRITY
60249 struct blk_integrity *integrity;
60250diff --git a/include/linux/gracl.h b/include/linux/gracl.h
60251new file mode 100644
60252index 0000000..c938b1f
60253--- /dev/null
60254+++ b/include/linux/gracl.h
60255@@ -0,0 +1,319 @@
60256+#ifndef GR_ACL_H
60257+#define GR_ACL_H
60258+
60259+#include <linux/grdefs.h>
60260+#include <linux/resource.h>
60261+#include <linux/capability.h>
60262+#include <linux/dcache.h>
60263+#include <asm/resource.h>
60264+
60265+/* Major status information */
60266+
60267+#define GR_VERSION "grsecurity 2.9.1"
60268+#define GRSECURITY_VERSION 0x2901
60269+
60270+enum {
60271+ GR_SHUTDOWN = 0,
60272+ GR_ENABLE = 1,
60273+ GR_SPROLE = 2,
60274+ GR_RELOAD = 3,
60275+ GR_SEGVMOD = 4,
60276+ GR_STATUS = 5,
60277+ GR_UNSPROLE = 6,
60278+ GR_PASSSET = 7,
60279+ GR_SPROLEPAM = 8,
60280+};
60281+
60282+/* Password setup definitions
60283+ * kernel/grhash.c */
60284+enum {
60285+ GR_PW_LEN = 128,
60286+ GR_SALT_LEN = 16,
60287+ GR_SHA_LEN = 32,
60288+};
60289+
60290+enum {
60291+ GR_SPROLE_LEN = 64,
60292+};
60293+
60294+enum {
60295+ GR_NO_GLOB = 0,
60296+ GR_REG_GLOB,
60297+ GR_CREATE_GLOB
60298+};
60299+
60300+#define GR_NLIMITS 32
60301+
60302+/* Begin Data Structures */
60303+
60304+struct sprole_pw {
60305+ unsigned char *rolename;
60306+ unsigned char salt[GR_SALT_LEN];
60307+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
60308+};
60309+
60310+struct name_entry {
60311+ __u32 key;
60312+ ino_t inode;
60313+ dev_t device;
60314+ char *name;
60315+ __u16 len;
60316+ __u8 deleted;
60317+ struct name_entry *prev;
60318+ struct name_entry *next;
60319+};
60320+
60321+struct inodev_entry {
60322+ struct name_entry *nentry;
60323+ struct inodev_entry *prev;
60324+ struct inodev_entry *next;
60325+};
60326+
60327+struct acl_role_db {
60328+ struct acl_role_label **r_hash;
60329+ __u32 r_size;
60330+};
60331+
60332+struct inodev_db {
60333+ struct inodev_entry **i_hash;
60334+ __u32 i_size;
60335+};
60336+
60337+struct name_db {
60338+ struct name_entry **n_hash;
60339+ __u32 n_size;
60340+};
60341+
60342+struct crash_uid {
60343+ uid_t uid;
60344+ unsigned long expires;
60345+};
60346+
60347+struct gr_hash_struct {
60348+ void **table;
60349+ void **nametable;
60350+ void *first;
60351+ __u32 table_size;
60352+ __u32 used_size;
60353+ int type;
60354+};
60355+
60356+/* Userspace Grsecurity ACL data structures */
60357+
60358+struct acl_subject_label {
60359+ char *filename;
60360+ ino_t inode;
60361+ dev_t device;
60362+ __u32 mode;
60363+ kernel_cap_t cap_mask;
60364+ kernel_cap_t cap_lower;
60365+ kernel_cap_t cap_invert_audit;
60366+
60367+ struct rlimit res[GR_NLIMITS];
60368+ __u32 resmask;
60369+
60370+ __u8 user_trans_type;
60371+ __u8 group_trans_type;
60372+ uid_t *user_transitions;
60373+ gid_t *group_transitions;
60374+ __u16 user_trans_num;
60375+ __u16 group_trans_num;
60376+
60377+ __u32 sock_families[2];
60378+ __u32 ip_proto[8];
60379+ __u32 ip_type;
60380+ struct acl_ip_label **ips;
60381+ __u32 ip_num;
60382+ __u32 inaddr_any_override;
60383+
60384+ __u32 crashes;
60385+ unsigned long expires;
60386+
60387+ struct acl_subject_label *parent_subject;
60388+ struct gr_hash_struct *hash;
60389+ struct acl_subject_label *prev;
60390+ struct acl_subject_label *next;
60391+
60392+ struct acl_object_label **obj_hash;
60393+ __u32 obj_hash_size;
60394+ __u16 pax_flags;
60395+};
60396+
60397+struct role_allowed_ip {
60398+ __u32 addr;
60399+ __u32 netmask;
60400+
60401+ struct role_allowed_ip *prev;
60402+ struct role_allowed_ip *next;
60403+};
60404+
60405+struct role_transition {
60406+ char *rolename;
60407+
60408+ struct role_transition *prev;
60409+ struct role_transition *next;
60410+};
60411+
60412+struct acl_role_label {
60413+ char *rolename;
60414+ uid_t uidgid;
60415+ __u16 roletype;
60416+
60417+ __u16 auth_attempts;
60418+ unsigned long expires;
60419+
60420+ struct acl_subject_label *root_label;
60421+ struct gr_hash_struct *hash;
60422+
60423+ struct acl_role_label *prev;
60424+ struct acl_role_label *next;
60425+
60426+ struct role_transition *transitions;
60427+ struct role_allowed_ip *allowed_ips;
60428+ uid_t *domain_children;
60429+ __u16 domain_child_num;
60430+
60431+ umode_t umask;
60432+
60433+ struct acl_subject_label **subj_hash;
60434+ __u32 subj_hash_size;
60435+};
60436+
60437+struct user_acl_role_db {
60438+ struct acl_role_label **r_table;
60439+ __u32 num_pointers; /* Number of allocations to track */
60440+ __u32 num_roles; /* Number of roles */
60441+ __u32 num_domain_children; /* Number of domain children */
60442+ __u32 num_subjects; /* Number of subjects */
60443+ __u32 num_objects; /* Number of objects */
60444+};
60445+
60446+struct acl_object_label {
60447+ char *filename;
60448+ ino_t inode;
60449+ dev_t device;
60450+ __u32 mode;
60451+
60452+ struct acl_subject_label *nested;
60453+ struct acl_object_label *globbed;
60454+
60455+ /* next two structures not used */
60456+
60457+ struct acl_object_label *prev;
60458+ struct acl_object_label *next;
60459+};
60460+
60461+struct acl_ip_label {
60462+ char *iface;
60463+ __u32 addr;
60464+ __u32 netmask;
60465+ __u16 low, high;
60466+ __u8 mode;
60467+ __u32 type;
60468+ __u32 proto[8];
60469+
60470+ /* next two structures not used */
60471+
60472+ struct acl_ip_label *prev;
60473+ struct acl_ip_label *next;
60474+};
60475+
60476+struct gr_arg {
60477+ struct user_acl_role_db role_db;
60478+ unsigned char pw[GR_PW_LEN];
60479+ unsigned char salt[GR_SALT_LEN];
60480+ unsigned char sum[GR_SHA_LEN];
60481+ unsigned char sp_role[GR_SPROLE_LEN];
60482+ struct sprole_pw *sprole_pws;
60483+ dev_t segv_device;
60484+ ino_t segv_inode;
60485+ uid_t segv_uid;
60486+ __u16 num_sprole_pws;
60487+ __u16 mode;
60488+};
60489+
60490+struct gr_arg_wrapper {
60491+ struct gr_arg *arg;
60492+ __u32 version;
60493+ __u32 size;
60494+};
60495+
60496+struct subject_map {
60497+ struct acl_subject_label *user;
60498+ struct acl_subject_label *kernel;
60499+ struct subject_map *prev;
60500+ struct subject_map *next;
60501+};
60502+
60503+struct acl_subj_map_db {
60504+ struct subject_map **s_hash;
60505+ __u32 s_size;
60506+};
60507+
60508+/* End Data Structures Section */
60509+
60510+/* Hash functions generated by empirical testing by Brad Spengler
60511+ Makes good use of the low bits of the inode. Generally 0-1 times
60512+ in loop for successful match. 0-3 for unsuccessful match.
60513+ Shift/add algorithm with modulus of table size and an XOR*/
60514+
60515+static __inline__ unsigned int
60516+rhash(const uid_t uid, const __u16 type, const unsigned int sz)
60517+{
60518+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
60519+}
60520+
60521+ static __inline__ unsigned int
60522+shash(const struct acl_subject_label *userp, const unsigned int sz)
60523+{
60524+ return ((const unsigned long)userp % sz);
60525+}
60526+
60527+static __inline__ unsigned int
60528+fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
60529+{
60530+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
60531+}
60532+
60533+static __inline__ unsigned int
60534+nhash(const char *name, const __u16 len, const unsigned int sz)
60535+{
60536+ return full_name_hash((const unsigned char *)name, len) % sz;
60537+}
60538+
60539+#define FOR_EACH_ROLE_START(role) \
60540+ role = role_list; \
60541+ while (role) {
60542+
60543+#define FOR_EACH_ROLE_END(role) \
60544+ role = role->prev; \
60545+ }
60546+
60547+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
60548+ subj = NULL; \
60549+ iter = 0; \
60550+ while (iter < role->subj_hash_size) { \
60551+ if (subj == NULL) \
60552+ subj = role->subj_hash[iter]; \
60553+ if (subj == NULL) { \
60554+ iter++; \
60555+ continue; \
60556+ }
60557+
60558+#define FOR_EACH_SUBJECT_END(subj,iter) \
60559+ subj = subj->next; \
60560+ if (subj == NULL) \
60561+ iter++; \
60562+ }
60563+
60564+
60565+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
60566+ subj = role->hash->first; \
60567+ while (subj != NULL) {
60568+
60569+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
60570+ subj = subj->next; \
60571+ }
60572+
60573+#endif
60574+
60575diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
60576new file mode 100644
60577index 0000000..323ecf2
60578--- /dev/null
60579+++ b/include/linux/gralloc.h
60580@@ -0,0 +1,9 @@
60581+#ifndef __GRALLOC_H
60582+#define __GRALLOC_H
60583+
60584+void acl_free_all(void);
60585+int acl_alloc_stack_init(unsigned long size);
60586+void *acl_alloc(unsigned long len);
60587+void *acl_alloc_num(unsigned long num, unsigned long len);
60588+
60589+#endif
60590diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
60591new file mode 100644
60592index 0000000..b30e9bc
60593--- /dev/null
60594+++ b/include/linux/grdefs.h
60595@@ -0,0 +1,140 @@
60596+#ifndef GRDEFS_H
60597+#define GRDEFS_H
60598+
60599+/* Begin grsecurity status declarations */
60600+
60601+enum {
60602+ GR_READY = 0x01,
60603+ GR_STATUS_INIT = 0x00 // disabled state
60604+};
60605+
60606+/* Begin ACL declarations */
60607+
60608+/* Role flags */
60609+
60610+enum {
60611+ GR_ROLE_USER = 0x0001,
60612+ GR_ROLE_GROUP = 0x0002,
60613+ GR_ROLE_DEFAULT = 0x0004,
60614+ GR_ROLE_SPECIAL = 0x0008,
60615+ GR_ROLE_AUTH = 0x0010,
60616+ GR_ROLE_NOPW = 0x0020,
60617+ GR_ROLE_GOD = 0x0040,
60618+ GR_ROLE_LEARN = 0x0080,
60619+ GR_ROLE_TPE = 0x0100,
60620+ GR_ROLE_DOMAIN = 0x0200,
60621+ GR_ROLE_PAM = 0x0400,
60622+ GR_ROLE_PERSIST = 0x0800
60623+};
60624+
60625+/* ACL Subject and Object mode flags */
60626+enum {
60627+ GR_DELETED = 0x80000000
60628+};
60629+
60630+/* ACL Object-only mode flags */
60631+enum {
60632+ GR_READ = 0x00000001,
60633+ GR_APPEND = 0x00000002,
60634+ GR_WRITE = 0x00000004,
60635+ GR_EXEC = 0x00000008,
60636+ GR_FIND = 0x00000010,
60637+ GR_INHERIT = 0x00000020,
60638+ GR_SETID = 0x00000040,
60639+ GR_CREATE = 0x00000080,
60640+ GR_DELETE = 0x00000100,
60641+ GR_LINK = 0x00000200,
60642+ GR_AUDIT_READ = 0x00000400,
60643+ GR_AUDIT_APPEND = 0x00000800,
60644+ GR_AUDIT_WRITE = 0x00001000,
60645+ GR_AUDIT_EXEC = 0x00002000,
60646+ GR_AUDIT_FIND = 0x00004000,
60647+ GR_AUDIT_INHERIT= 0x00008000,
60648+ GR_AUDIT_SETID = 0x00010000,
60649+ GR_AUDIT_CREATE = 0x00020000,
60650+ GR_AUDIT_DELETE = 0x00040000,
60651+ GR_AUDIT_LINK = 0x00080000,
60652+ GR_PTRACERD = 0x00100000,
60653+ GR_NOPTRACE = 0x00200000,
60654+ GR_SUPPRESS = 0x00400000,
60655+ GR_NOLEARN = 0x00800000,
60656+ GR_INIT_TRANSFER= 0x01000000
60657+};
60658+
60659+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
60660+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
60661+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
60662+
60663+/* ACL subject-only mode flags */
60664+enum {
60665+ GR_KILL = 0x00000001,
60666+ GR_VIEW = 0x00000002,
60667+ GR_PROTECTED = 0x00000004,
60668+ GR_LEARN = 0x00000008,
60669+ GR_OVERRIDE = 0x00000010,
60670+ /* just a placeholder, this mode is only used in userspace */
60671+ GR_DUMMY = 0x00000020,
60672+ GR_PROTSHM = 0x00000040,
60673+ GR_KILLPROC = 0x00000080,
60674+ GR_KILLIPPROC = 0x00000100,
60675+ /* just a placeholder, this mode is only used in userspace */
60676+ GR_NOTROJAN = 0x00000200,
60677+ GR_PROTPROCFD = 0x00000400,
60678+ GR_PROCACCT = 0x00000800,
60679+ GR_RELAXPTRACE = 0x00001000,
60680+ GR_NESTED = 0x00002000,
60681+ GR_INHERITLEARN = 0x00004000,
60682+ GR_PROCFIND = 0x00008000,
60683+ GR_POVERRIDE = 0x00010000,
60684+ GR_KERNELAUTH = 0x00020000,
60685+ GR_ATSECURE = 0x00040000,
60686+ GR_SHMEXEC = 0x00080000
60687+};
60688+
60689+enum {
60690+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
60691+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
60692+ GR_PAX_ENABLE_MPROTECT = 0x0004,
60693+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
60694+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
60695+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
60696+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
60697+ GR_PAX_DISABLE_MPROTECT = 0x0400,
60698+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
60699+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
60700+};
60701+
60702+enum {
60703+ GR_ID_USER = 0x01,
60704+ GR_ID_GROUP = 0x02,
60705+};
60706+
60707+enum {
60708+ GR_ID_ALLOW = 0x01,
60709+ GR_ID_DENY = 0x02,
60710+};
60711+
60712+#define GR_CRASH_RES 31
60713+#define GR_UIDTABLE_MAX 500
60714+
60715+/* begin resource learning section */
60716+enum {
60717+ GR_RLIM_CPU_BUMP = 60,
60718+ GR_RLIM_FSIZE_BUMP = 50000,
60719+ GR_RLIM_DATA_BUMP = 10000,
60720+ GR_RLIM_STACK_BUMP = 1000,
60721+ GR_RLIM_CORE_BUMP = 10000,
60722+ GR_RLIM_RSS_BUMP = 500000,
60723+ GR_RLIM_NPROC_BUMP = 1,
60724+ GR_RLIM_NOFILE_BUMP = 5,
60725+ GR_RLIM_MEMLOCK_BUMP = 50000,
60726+ GR_RLIM_AS_BUMP = 500000,
60727+ GR_RLIM_LOCKS_BUMP = 2,
60728+ GR_RLIM_SIGPENDING_BUMP = 5,
60729+ GR_RLIM_MSGQUEUE_BUMP = 10000,
60730+ GR_RLIM_NICE_BUMP = 1,
60731+ GR_RLIM_RTPRIO_BUMP = 1,
60732+ GR_RLIM_RTTIME_BUMP = 1000000
60733+};
60734+
60735+#endif
60736diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
60737new file mode 100644
60738index 0000000..da390f1
60739--- /dev/null
60740+++ b/include/linux/grinternal.h
60741@@ -0,0 +1,221 @@
60742+#ifndef __GRINTERNAL_H
60743+#define __GRINTERNAL_H
60744+
60745+#ifdef CONFIG_GRKERNSEC
60746+
60747+#include <linux/fs.h>
60748+#include <linux/mnt_namespace.h>
60749+#include <linux/nsproxy.h>
60750+#include <linux/gracl.h>
60751+#include <linux/grdefs.h>
60752+#include <linux/grmsg.h>
60753+
60754+void gr_add_learn_entry(const char *fmt, ...)
60755+ __attribute__ ((format (printf, 1, 2)));
60756+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
60757+ const struct vfsmount *mnt);
60758+__u32 gr_check_create(const struct dentry *new_dentry,
60759+ const struct dentry *parent,
60760+ const struct vfsmount *mnt, const __u32 mode);
60761+int gr_check_protected_task(const struct task_struct *task);
60762+__u32 to_gr_audit(const __u32 reqmode);
60763+int gr_set_acls(const int type);
60764+int gr_apply_subject_to_task(struct task_struct *task);
60765+int gr_acl_is_enabled(void);
60766+char gr_roletype_to_char(void);
60767+
60768+void gr_handle_alertkill(struct task_struct *task);
60769+char *gr_to_filename(const struct dentry *dentry,
60770+ const struct vfsmount *mnt);
60771+char *gr_to_filename1(const struct dentry *dentry,
60772+ const struct vfsmount *mnt);
60773+char *gr_to_filename2(const struct dentry *dentry,
60774+ const struct vfsmount *mnt);
60775+char *gr_to_filename3(const struct dentry *dentry,
60776+ const struct vfsmount *mnt);
60777+
60778+extern int grsec_enable_ptrace_readexec;
60779+extern int grsec_enable_harden_ptrace;
60780+extern int grsec_enable_link;
60781+extern int grsec_enable_fifo;
60782+extern int grsec_enable_execve;
60783+extern int grsec_enable_shm;
60784+extern int grsec_enable_execlog;
60785+extern int grsec_enable_signal;
60786+extern int grsec_enable_audit_ptrace;
60787+extern int grsec_enable_forkfail;
60788+extern int grsec_enable_time;
60789+extern int grsec_enable_rofs;
60790+extern int grsec_enable_chroot_shmat;
60791+extern int grsec_enable_chroot_mount;
60792+extern int grsec_enable_chroot_double;
60793+extern int grsec_enable_chroot_pivot;
60794+extern int grsec_enable_chroot_chdir;
60795+extern int grsec_enable_chroot_chmod;
60796+extern int grsec_enable_chroot_mknod;
60797+extern int grsec_enable_chroot_fchdir;
60798+extern int grsec_enable_chroot_nice;
60799+extern int grsec_enable_chroot_execlog;
60800+extern int grsec_enable_chroot_caps;
60801+extern int grsec_enable_chroot_sysctl;
60802+extern int grsec_enable_chroot_unix;
60803+extern int grsec_enable_tpe;
60804+extern int grsec_tpe_gid;
60805+extern int grsec_enable_tpe_all;
60806+extern int grsec_enable_tpe_invert;
60807+extern int grsec_enable_socket_all;
60808+extern int grsec_socket_all_gid;
60809+extern int grsec_enable_socket_client;
60810+extern int grsec_socket_client_gid;
60811+extern int grsec_enable_socket_server;
60812+extern int grsec_socket_server_gid;
60813+extern int grsec_audit_gid;
60814+extern int grsec_enable_group;
60815+extern int grsec_enable_audit_textrel;
60816+extern int grsec_enable_log_rwxmaps;
60817+extern int grsec_enable_mount;
60818+extern int grsec_enable_chdir;
60819+extern int grsec_resource_logging;
60820+extern int grsec_enable_blackhole;
60821+extern int grsec_lastack_retries;
60822+extern int grsec_enable_brute;
60823+extern int grsec_lock;
60824+
60825+extern spinlock_t grsec_alert_lock;
60826+extern unsigned long grsec_alert_wtime;
60827+extern unsigned long grsec_alert_fyet;
60828+
60829+extern spinlock_t grsec_audit_lock;
60830+
60831+extern rwlock_t grsec_exec_file_lock;
60832+
60833+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
60834+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
60835+ (tsk)->exec_file->f_vfsmnt) : "/")
60836+
60837+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
60838+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
60839+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
60840+
60841+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
60842+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
60843+ (tsk)->exec_file->f_vfsmnt) : "/")
60844+
60845+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
60846+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
60847+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
60848+
60849+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
60850+
60851+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
60852+
60853+#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
60854+ (task)->pid, (cred)->uid, \
60855+ (cred)->euid, (cred)->gid, (cred)->egid, \
60856+ gr_parent_task_fullpath(task), \
60857+ (task)->real_parent->comm, (task)->real_parent->pid, \
60858+ (pcred)->uid, (pcred)->euid, \
60859+ (pcred)->gid, (pcred)->egid
60860+
60861+#define GR_CHROOT_CAPS {{ \
60862+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
60863+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
60864+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
60865+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
60866+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
60867+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
60868+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
60869+
60870+#define security_learn(normal_msg,args...) \
60871+({ \
60872+ read_lock(&grsec_exec_file_lock); \
60873+ gr_add_learn_entry(normal_msg "\n", ## args); \
60874+ read_unlock(&grsec_exec_file_lock); \
60875+})
60876+
60877+enum {
60878+ GR_DO_AUDIT,
60879+ GR_DONT_AUDIT,
60880+ /* used for non-audit messages that we shouldn't kill the task on */
60881+ GR_DONT_AUDIT_GOOD
60882+};
60883+
60884+enum {
60885+ GR_TTYSNIFF,
60886+ GR_RBAC,
60887+ GR_RBAC_STR,
60888+ GR_STR_RBAC,
60889+ GR_RBAC_MODE2,
60890+ GR_RBAC_MODE3,
60891+ GR_FILENAME,
60892+ GR_SYSCTL_HIDDEN,
60893+ GR_NOARGS,
60894+ GR_ONE_INT,
60895+ GR_ONE_INT_TWO_STR,
60896+ GR_ONE_STR,
60897+ GR_STR_INT,
60898+ GR_TWO_STR_INT,
60899+ GR_TWO_INT,
60900+ GR_TWO_U64,
60901+ GR_THREE_INT,
60902+ GR_FIVE_INT_TWO_STR,
60903+ GR_TWO_STR,
60904+ GR_THREE_STR,
60905+ GR_FOUR_STR,
60906+ GR_STR_FILENAME,
60907+ GR_FILENAME_STR,
60908+ GR_FILENAME_TWO_INT,
60909+ GR_FILENAME_TWO_INT_STR,
60910+ GR_TEXTREL,
60911+ GR_PTRACE,
60912+ GR_RESOURCE,
60913+ GR_CAP,
60914+ GR_SIG,
60915+ GR_SIG2,
60916+ GR_CRASH1,
60917+ GR_CRASH2,
60918+ GR_PSACCT,
60919+ GR_RWXMAP
60920+};
60921+
60922+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
60923+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
60924+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
60925+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
60926+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
60927+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
60928+#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)
60929+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
60930+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
60931+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
60932+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
60933+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
60934+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
60935+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
60936+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
60937+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
60938+#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)
60939+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
60940+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
60941+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
60942+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
60943+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
60944+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
60945+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
60946+#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)
60947+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
60948+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
60949+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
60950+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
60951+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
60952+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
60953+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
60954+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
60955+#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)
60956+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
60957+
60958+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
60959+
60960+#endif
60961+
60962+#endif
60963diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
60964new file mode 100644
60965index 0000000..ae576a1
60966--- /dev/null
60967+++ b/include/linux/grmsg.h
60968@@ -0,0 +1,109 @@
60969+#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"
60970+#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"
60971+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
60972+#define GR_STOPMOD_MSG "denied modification of module state by "
60973+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
60974+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
60975+#define GR_IOPERM_MSG "denied use of ioperm() by "
60976+#define GR_IOPL_MSG "denied use of iopl() by "
60977+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
60978+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
60979+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
60980+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
60981+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
60982+#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"
60983+#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"
60984+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
60985+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
60986+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
60987+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
60988+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
60989+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
60990+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
60991+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
60992+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
60993+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
60994+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
60995+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
60996+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
60997+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
60998+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
60999+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
61000+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
61001+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
61002+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
61003+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
61004+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
61005+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
61006+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
61007+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
61008+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
61009+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
61010+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
61011+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
61012+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
61013+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
61014+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
61015+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
61016+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
61017+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
61018+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
61019+#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"
61020+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
61021+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
61022+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
61023+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
61024+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
61025+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
61026+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
61027+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
61028+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
61029+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
61030+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
61031+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
61032+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
61033+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
61034+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
61035+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
61036+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
61037+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
61038+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
61039+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
61040+#define GR_FAILFORK_MSG "failed fork with errno %s by "
61041+#define GR_NICE_CHROOT_MSG "denied priority change by "
61042+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
61043+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
61044+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
61045+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
61046+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
61047+#define GR_TIME_MSG "time set by "
61048+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
61049+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
61050+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
61051+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
61052+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
61053+#define GR_BIND_MSG "denied bind() by "
61054+#define GR_CONNECT_MSG "denied connect() by "
61055+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
61056+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
61057+#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"
61058+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
61059+#define GR_CAP_ACL_MSG "use of %s denied for "
61060+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
61061+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
61062+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
61063+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
61064+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
61065+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
61066+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
61067+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
61068+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
61069+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
61070+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
61071+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
61072+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
61073+#define GR_VM86_MSG "denied use of vm86 by "
61074+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
61075+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
61076+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
61077+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
61078diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
61079new file mode 100644
61080index 0000000..acd05db
61081--- /dev/null
61082+++ b/include/linux/grsecurity.h
61083@@ -0,0 +1,232 @@
61084+#ifndef GR_SECURITY_H
61085+#define GR_SECURITY_H
61086+#include <linux/fs.h>
61087+#include <linux/fs_struct.h>
61088+#include <linux/binfmts.h>
61089+#include <linux/gracl.h>
61090+
61091+/* notify of brain-dead configs */
61092+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61093+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
61094+#endif
61095+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
61096+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
61097+#endif
61098+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
61099+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
61100+#endif
61101+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
61102+#error "CONFIG_PAX enabled, but no PaX options are enabled."
61103+#endif
61104+
61105+#include <linux/compat.h>
61106+
61107+struct user_arg_ptr {
61108+#ifdef CONFIG_COMPAT
61109+ bool is_compat;
61110+#endif
61111+ union {
61112+ const char __user *const __user *native;
61113+#ifdef CONFIG_COMPAT
61114+ compat_uptr_t __user *compat;
61115+#endif
61116+ } ptr;
61117+};
61118+
61119+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
61120+void gr_handle_brute_check(void);
61121+void gr_handle_kernel_exploit(void);
61122+int gr_process_user_ban(void);
61123+
61124+char gr_roletype_to_char(void);
61125+
61126+int gr_acl_enable_at_secure(void);
61127+
61128+int gr_check_user_change(int real, int effective, int fs);
61129+int gr_check_group_change(int real, int effective, int fs);
61130+
61131+void gr_del_task_from_ip_table(struct task_struct *p);
61132+
61133+int gr_pid_is_chrooted(struct task_struct *p);
61134+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
61135+int gr_handle_chroot_nice(void);
61136+int gr_handle_chroot_sysctl(const int op);
61137+int gr_handle_chroot_setpriority(struct task_struct *p,
61138+ const int niceval);
61139+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
61140+int gr_handle_chroot_chroot(const struct dentry *dentry,
61141+ const struct vfsmount *mnt);
61142+void gr_handle_chroot_chdir(struct path *path);
61143+int gr_handle_chroot_chmod(const struct dentry *dentry,
61144+ const struct vfsmount *mnt, const int mode);
61145+int gr_handle_chroot_mknod(const struct dentry *dentry,
61146+ const struct vfsmount *mnt, const int mode);
61147+int gr_handle_chroot_mount(const struct dentry *dentry,
61148+ const struct vfsmount *mnt,
61149+ const char *dev_name);
61150+int gr_handle_chroot_pivot(void);
61151+int gr_handle_chroot_unix(const pid_t pid);
61152+
61153+int gr_handle_rawio(const struct inode *inode);
61154+
61155+void gr_handle_ioperm(void);
61156+void gr_handle_iopl(void);
61157+
61158+umode_t gr_acl_umask(void);
61159+
61160+int gr_tpe_allow(const struct file *file);
61161+
61162+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
61163+void gr_clear_chroot_entries(struct task_struct *task);
61164+
61165+void gr_log_forkfail(const int retval);
61166+void gr_log_timechange(void);
61167+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
61168+void gr_log_chdir(const struct dentry *dentry,
61169+ const struct vfsmount *mnt);
61170+void gr_log_chroot_exec(const struct dentry *dentry,
61171+ const struct vfsmount *mnt);
61172+void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
61173+void gr_log_remount(const char *devname, const int retval);
61174+void gr_log_unmount(const char *devname, const int retval);
61175+void gr_log_mount(const char *from, const char *to, const int retval);
61176+void gr_log_textrel(struct vm_area_struct *vma);
61177+void gr_log_rwxmmap(struct file *file);
61178+void gr_log_rwxmprotect(struct file *file);
61179+
61180+int gr_handle_follow_link(const struct inode *parent,
61181+ const struct inode *inode,
61182+ const struct dentry *dentry,
61183+ const struct vfsmount *mnt);
61184+int gr_handle_fifo(const struct dentry *dentry,
61185+ const struct vfsmount *mnt,
61186+ const struct dentry *dir, const int flag,
61187+ const int acc_mode);
61188+int gr_handle_hardlink(const struct dentry *dentry,
61189+ const struct vfsmount *mnt,
61190+ struct inode *inode,
61191+ const int mode, const char *to);
61192+
61193+int gr_is_capable(const int cap);
61194+int gr_is_capable_nolog(const int cap);
61195+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
61196+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
61197+
61198+void gr_learn_resource(const struct task_struct *task, const int limit,
61199+ const unsigned long wanted, const int gt);
61200+void gr_copy_label(struct task_struct *tsk);
61201+void gr_handle_crash(struct task_struct *task, const int sig);
61202+int gr_handle_signal(const struct task_struct *p, const int sig);
61203+int gr_check_crash_uid(const uid_t uid);
61204+int gr_check_protected_task(const struct task_struct *task);
61205+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
61206+int gr_acl_handle_mmap(const struct file *file,
61207+ const unsigned long prot);
61208+int gr_acl_handle_mprotect(const struct file *file,
61209+ const unsigned long prot);
61210+int gr_check_hidden_task(const struct task_struct *tsk);
61211+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
61212+ const struct vfsmount *mnt);
61213+__u32 gr_acl_handle_utime(const struct dentry *dentry,
61214+ const struct vfsmount *mnt);
61215+__u32 gr_acl_handle_access(const struct dentry *dentry,
61216+ const struct vfsmount *mnt, const int fmode);
61217+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
61218+ const struct vfsmount *mnt, umode_t *mode);
61219+__u32 gr_acl_handle_chown(const struct dentry *dentry,
61220+ const struct vfsmount *mnt);
61221+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
61222+ const struct vfsmount *mnt);
61223+int gr_handle_ptrace(struct task_struct *task, const long request);
61224+int gr_handle_proc_ptrace(struct task_struct *task);
61225+__u32 gr_acl_handle_execve(const struct dentry *dentry,
61226+ const struct vfsmount *mnt);
61227+int gr_check_crash_exec(const struct file *filp);
61228+int gr_acl_is_enabled(void);
61229+void gr_set_kernel_label(struct task_struct *task);
61230+void gr_set_role_label(struct task_struct *task, const uid_t uid,
61231+ const gid_t gid);
61232+int gr_set_proc_label(const struct dentry *dentry,
61233+ const struct vfsmount *mnt,
61234+ const int unsafe_flags);
61235+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
61236+ const struct vfsmount *mnt);
61237+__u32 gr_acl_handle_open(const struct dentry *dentry,
61238+ const struct vfsmount *mnt, int acc_mode);
61239+__u32 gr_acl_handle_creat(const struct dentry *dentry,
61240+ const struct dentry *p_dentry,
61241+ const struct vfsmount *p_mnt,
61242+ int open_flags, int acc_mode, const int imode);
61243+void gr_handle_create(const struct dentry *dentry,
61244+ const struct vfsmount *mnt);
61245+void gr_handle_proc_create(const struct dentry *dentry,
61246+ const struct inode *inode);
61247+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
61248+ const struct dentry *parent_dentry,
61249+ const struct vfsmount *parent_mnt,
61250+ const int mode);
61251+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
61252+ const struct dentry *parent_dentry,
61253+ const struct vfsmount *parent_mnt);
61254+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
61255+ const struct vfsmount *mnt);
61256+void gr_handle_delete(const ino_t ino, const dev_t dev);
61257+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
61258+ const struct vfsmount *mnt);
61259+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
61260+ const struct dentry *parent_dentry,
61261+ const struct vfsmount *parent_mnt,
61262+ const char *from);
61263+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
61264+ const struct dentry *parent_dentry,
61265+ const struct vfsmount *parent_mnt,
61266+ const struct dentry *old_dentry,
61267+ const struct vfsmount *old_mnt, const char *to);
61268+int gr_acl_handle_rename(struct dentry *new_dentry,
61269+ struct dentry *parent_dentry,
61270+ const struct vfsmount *parent_mnt,
61271+ struct dentry *old_dentry,
61272+ struct inode *old_parent_inode,
61273+ struct vfsmount *old_mnt, const char *newname);
61274+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
61275+ struct dentry *old_dentry,
61276+ struct dentry *new_dentry,
61277+ struct vfsmount *mnt, const __u8 replace);
61278+__u32 gr_check_link(const struct dentry *new_dentry,
61279+ const struct dentry *parent_dentry,
61280+ const struct vfsmount *parent_mnt,
61281+ const struct dentry *old_dentry,
61282+ const struct vfsmount *old_mnt);
61283+int gr_acl_handle_filldir(const struct file *file, const char *name,
61284+ const unsigned int namelen, const ino_t ino);
61285+
61286+__u32 gr_acl_handle_unix(const struct dentry *dentry,
61287+ const struct vfsmount *mnt);
61288+void gr_acl_handle_exit(void);
61289+void gr_acl_handle_psacct(struct task_struct *task, const long code);
61290+int gr_acl_handle_procpidmem(const struct task_struct *task);
61291+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
61292+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
61293+void gr_audit_ptrace(struct task_struct *task);
61294+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
61295+
61296+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
61297+
61298+#ifdef CONFIG_GRKERNSEC
61299+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
61300+void gr_handle_vm86(void);
61301+void gr_handle_mem_readwrite(u64 from, u64 to);
61302+
61303+void gr_log_badprocpid(const char *entry);
61304+
61305+extern int grsec_enable_dmesg;
61306+extern int grsec_disable_privio;
61307+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61308+extern int grsec_enable_chroot_findtask;
61309+#endif
61310+#ifdef CONFIG_GRKERNSEC_SETXID
61311+extern int grsec_enable_setxid;
61312+#endif
61313+#endif
61314+
61315+#endif
61316diff --git a/include/linux/grsock.h b/include/linux/grsock.h
61317new file mode 100644
61318index 0000000..e7ffaaf
61319--- /dev/null
61320+++ b/include/linux/grsock.h
61321@@ -0,0 +1,19 @@
61322+#ifndef __GRSOCK_H
61323+#define __GRSOCK_H
61324+
61325+extern void gr_attach_curr_ip(const struct sock *sk);
61326+extern int gr_handle_sock_all(const int family, const int type,
61327+ const int protocol);
61328+extern int gr_handle_sock_server(const struct sockaddr *sck);
61329+extern int gr_handle_sock_server_other(const struct sock *sck);
61330+extern int gr_handle_sock_client(const struct sockaddr *sck);
61331+extern int gr_search_connect(struct socket * sock,
61332+ struct sockaddr_in * addr);
61333+extern int gr_search_bind(struct socket * sock,
61334+ struct sockaddr_in * addr);
61335+extern int gr_search_listen(struct socket * sock);
61336+extern int gr_search_accept(struct socket * sock);
61337+extern int gr_search_socket(const int domain, const int type,
61338+ const int protocol);
61339+
61340+#endif
61341diff --git a/include/linux/hid.h b/include/linux/hid.h
61342index 3a95da6..51986f1 100644
61343--- a/include/linux/hid.h
61344+++ b/include/linux/hid.h
61345@@ -696,7 +696,7 @@ struct hid_ll_driver {
61346 unsigned int code, int value);
61347
61348 int (*parse)(struct hid_device *hdev);
61349-};
61350+} __no_const;
61351
61352 #define PM_HINT_FULLON 1<<5
61353 #define PM_HINT_NORMAL 1<<1
61354diff --git a/include/linux/highmem.h b/include/linux/highmem.h
61355index d3999b4..1304cb4 100644
61356--- a/include/linux/highmem.h
61357+++ b/include/linux/highmem.h
61358@@ -221,6 +221,18 @@ static inline void clear_highpage(struct page *page)
61359 kunmap_atomic(kaddr);
61360 }
61361
61362+static inline void sanitize_highpage(struct page *page)
61363+{
61364+ void *kaddr;
61365+ unsigned long flags;
61366+
61367+ local_irq_save(flags);
61368+ kaddr = kmap_atomic(page);
61369+ clear_page(kaddr);
61370+ kunmap_atomic(kaddr);
61371+ local_irq_restore(flags);
61372+}
61373+
61374 static inline void zero_user_segments(struct page *page,
61375 unsigned start1, unsigned end1,
61376 unsigned start2, unsigned end2)
61377diff --git a/include/linux/i2c.h b/include/linux/i2c.h
61378index 195d8b3..e20cfab 100644
61379--- a/include/linux/i2c.h
61380+++ b/include/linux/i2c.h
61381@@ -365,6 +365,7 @@ struct i2c_algorithm {
61382 /* To determine what the adapter supports */
61383 u32 (*functionality) (struct i2c_adapter *);
61384 };
61385+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
61386
61387 /*
61388 * i2c_adapter is the structure used to identify a physical i2c bus along
61389diff --git a/include/linux/i2o.h b/include/linux/i2o.h
61390index d23c3c2..eb63c81 100644
61391--- a/include/linux/i2o.h
61392+++ b/include/linux/i2o.h
61393@@ -565,7 +565,7 @@ struct i2o_controller {
61394 struct i2o_device *exec; /* Executive */
61395 #if BITS_PER_LONG == 64
61396 spinlock_t context_list_lock; /* lock for context_list */
61397- atomic_t context_list_counter; /* needed for unique contexts */
61398+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
61399 struct list_head context_list; /* list of context id's
61400 and pointers */
61401 #endif
61402diff --git a/include/linux/if_team.h b/include/linux/if_team.h
61403index 58404b0..439ed95 100644
61404--- a/include/linux/if_team.h
61405+++ b/include/linux/if_team.h
61406@@ -64,6 +64,7 @@ struct team_mode_ops {
61407 void (*port_leave)(struct team *team, struct team_port *port);
61408 void (*port_change_mac)(struct team *team, struct team_port *port);
61409 };
61410+typedef struct team_mode_ops __no_const team_mode_ops_no_const;
61411
61412 enum team_option_type {
61413 TEAM_OPTION_TYPE_U32,
61414@@ -112,7 +113,7 @@ struct team {
61415 struct list_head option_list;
61416
61417 const struct team_mode *mode;
61418- struct team_mode_ops ops;
61419+ team_mode_ops_no_const ops;
61420 long mode_priv[TEAM_MODE_PRIV_LONGS];
61421 };
61422
61423diff --git a/include/linux/init.h b/include/linux/init.h
61424index 6b95109..4aca62c 100644
61425--- a/include/linux/init.h
61426+++ b/include/linux/init.h
61427@@ -294,13 +294,13 @@ void __init parse_early_options(char *cmdline);
61428
61429 /* Each module must use one module_init(). */
61430 #define module_init(initfn) \
61431- static inline initcall_t __inittest(void) \
61432+ static inline __used initcall_t __inittest(void) \
61433 { return initfn; } \
61434 int init_module(void) __attribute__((alias(#initfn)));
61435
61436 /* This is only required if you want to be unloadable. */
61437 #define module_exit(exitfn) \
61438- static inline exitcall_t __exittest(void) \
61439+ static inline __used exitcall_t __exittest(void) \
61440 { return exitfn; } \
61441 void cleanup_module(void) __attribute__((alias(#exitfn)));
61442
61443diff --git a/include/linux/init_task.h b/include/linux/init_task.h
61444index e4baff5..83bb175 100644
61445--- a/include/linux/init_task.h
61446+++ b/include/linux/init_task.h
61447@@ -134,6 +134,12 @@ extern struct cred init_cred;
61448
61449 #define INIT_TASK_COMM "swapper"
61450
61451+#ifdef CONFIG_X86
61452+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
61453+#else
61454+#define INIT_TASK_THREAD_INFO
61455+#endif
61456+
61457 /*
61458 * INIT_TASK is used to set up the first task table, touch at
61459 * your own risk!. Base=0, limit=0x1fffff (=2MB)
61460@@ -172,6 +178,7 @@ extern struct cred init_cred;
61461 RCU_INIT_POINTER(.cred, &init_cred), \
61462 .comm = INIT_TASK_COMM, \
61463 .thread = INIT_THREAD, \
61464+ INIT_TASK_THREAD_INFO \
61465 .fs = &init_fs, \
61466 .files = &init_files, \
61467 .signal = &init_signals, \
61468diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
61469index e6ca56d..8583707 100644
61470--- a/include/linux/intel-iommu.h
61471+++ b/include/linux/intel-iommu.h
61472@@ -296,7 +296,7 @@ struct iommu_flush {
61473 u8 fm, u64 type);
61474 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
61475 unsigned int size_order, u64 type);
61476-};
61477+} __no_const;
61478
61479 enum {
61480 SR_DMAR_FECTL_REG,
61481diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
61482index 2aea5d2..0b82f0c 100644
61483--- a/include/linux/interrupt.h
61484+++ b/include/linux/interrupt.h
61485@@ -439,7 +439,7 @@ enum
61486 /* map softirq index to softirq name. update 'softirq_to_name' in
61487 * kernel/softirq.c when adding a new softirq.
61488 */
61489-extern char *softirq_to_name[NR_SOFTIRQS];
61490+extern const char * const softirq_to_name[NR_SOFTIRQS];
61491
61492 /* softirq mask and active fields moved to irq_cpustat_t in
61493 * asm/hardirq.h to get better cache usage. KAO
61494@@ -447,12 +447,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
61495
61496 struct softirq_action
61497 {
61498- void (*action)(struct softirq_action *);
61499+ void (*action)(void);
61500 };
61501
61502 asmlinkage void do_softirq(void);
61503 asmlinkage void __do_softirq(void);
61504-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
61505+extern void open_softirq(int nr, void (*action)(void));
61506 extern void softirq_init(void);
61507 extern void __raise_softirq_irqoff(unsigned int nr);
61508
61509diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
61510index 3875719..4cd454c 100644
61511--- a/include/linux/kallsyms.h
61512+++ b/include/linux/kallsyms.h
61513@@ -15,7 +15,8 @@
61514
61515 struct module;
61516
61517-#ifdef CONFIG_KALLSYMS
61518+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
61519+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
61520 /* Lookup the address for a symbol. Returns 0 if not found. */
61521 unsigned long kallsyms_lookup_name(const char *name);
61522
61523@@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
61524 /* Stupid that this does nothing, but I didn't create this mess. */
61525 #define __print_symbol(fmt, addr)
61526 #endif /*CONFIG_KALLSYMS*/
61527+#else /* when included by kallsyms.c, vsnprintf.c, or
61528+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
61529+extern void __print_symbol(const char *fmt, unsigned long address);
61530+extern int sprint_backtrace(char *buffer, unsigned long address);
61531+extern int sprint_symbol(char *buffer, unsigned long address);
61532+const char *kallsyms_lookup(unsigned long addr,
61533+ unsigned long *symbolsize,
61534+ unsigned long *offset,
61535+ char **modname, char *namebuf);
61536+#endif
61537
61538 /* This macro allows us to keep printk typechecking */
61539 static __printf(1, 2)
61540diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
61541index c4d2fc1..5df9c19 100644
61542--- a/include/linux/kgdb.h
61543+++ b/include/linux/kgdb.h
61544@@ -53,7 +53,7 @@ extern int kgdb_connected;
61545 extern int kgdb_io_module_registered;
61546
61547 extern atomic_t kgdb_setting_breakpoint;
61548-extern atomic_t kgdb_cpu_doing_single_step;
61549+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
61550
61551 extern struct task_struct *kgdb_usethread;
61552 extern struct task_struct *kgdb_contthread;
61553@@ -252,7 +252,7 @@ struct kgdb_arch {
61554 void (*disable_hw_break)(struct pt_regs *regs);
61555 void (*remove_all_hw_break)(void);
61556 void (*correct_hw_break)(void);
61557-};
61558+} __do_const;
61559
61560 /**
61561 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
61562@@ -277,7 +277,7 @@ struct kgdb_io {
61563 void (*pre_exception) (void);
61564 void (*post_exception) (void);
61565 int is_console;
61566-};
61567+} __do_const;
61568
61569 extern struct kgdb_arch arch_kgdb_ops;
61570
61571diff --git a/include/linux/kmod.h b/include/linux/kmod.h
61572index dd99c32..da06047 100644
61573--- a/include/linux/kmod.h
61574+++ b/include/linux/kmod.h
61575@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
61576 * usually useless though. */
61577 extern __printf(2, 3)
61578 int __request_module(bool wait, const char *name, ...);
61579+extern __printf(3, 4)
61580+int ___request_module(bool wait, char *param_name, const char *name, ...);
61581 #define request_module(mod...) __request_module(true, mod)
61582 #define request_module_nowait(mod...) __request_module(false, mod)
61583 #define try_then_request_module(x, mod...) \
61584diff --git a/include/linux/kref.h b/include/linux/kref.h
61585index 9c07dce..a92fa71 100644
61586--- a/include/linux/kref.h
61587+++ b/include/linux/kref.h
61588@@ -63,7 +63,7 @@ static inline void kref_get(struct kref *kref)
61589 static inline int kref_sub(struct kref *kref, unsigned int count,
61590 void (*release)(struct kref *kref))
61591 {
61592- WARN_ON(release == NULL);
61593+ BUG_ON(release == NULL);
61594
61595 if (atomic_sub_and_test((int) count, &kref->refcount)) {
61596 release(kref);
61597diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
61598index 72cbf08..dd0201d 100644
61599--- a/include/linux/kvm_host.h
61600+++ b/include/linux/kvm_host.h
61601@@ -322,7 +322,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
61602 void vcpu_load(struct kvm_vcpu *vcpu);
61603 void vcpu_put(struct kvm_vcpu *vcpu);
61604
61605-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
61606+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
61607 struct module *module);
61608 void kvm_exit(void);
61609
61610@@ -486,7 +486,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
61611 struct kvm_guest_debug *dbg);
61612 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
61613
61614-int kvm_arch_init(void *opaque);
61615+int kvm_arch_init(const void *opaque);
61616 void kvm_arch_exit(void);
61617
61618 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
61619diff --git a/include/linux/libata.h b/include/linux/libata.h
61620index 6e887c7..4539601 100644
61621--- a/include/linux/libata.h
61622+++ b/include/linux/libata.h
61623@@ -910,7 +910,7 @@ struct ata_port_operations {
61624 * fields must be pointers.
61625 */
61626 const struct ata_port_operations *inherits;
61627-};
61628+} __do_const;
61629
61630 struct ata_port_info {
61631 unsigned long flags;
61632diff --git a/include/linux/mca.h b/include/linux/mca.h
61633index 3797270..7765ede 100644
61634--- a/include/linux/mca.h
61635+++ b/include/linux/mca.h
61636@@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
61637 int region);
61638 void * (*mca_transform_memory)(struct mca_device *,
61639 void *memory);
61640-};
61641+} __no_const;
61642
61643 struct mca_bus {
61644 u64 default_dma_mask;
61645diff --git a/include/linux/memory.h b/include/linux/memory.h
61646index 1ac7f6e..a5794d0 100644
61647--- a/include/linux/memory.h
61648+++ b/include/linux/memory.h
61649@@ -143,7 +143,7 @@ struct memory_accessor {
61650 size_t count);
61651 ssize_t (*write)(struct memory_accessor *, const char *buf,
61652 off_t offset, size_t count);
61653-};
61654+} __no_const;
61655
61656 /*
61657 * Kernel text modification mutex, used for code patching. Users of this lock
61658diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
61659index ee96cd5..7823c3a 100644
61660--- a/include/linux/mfd/abx500.h
61661+++ b/include/linux/mfd/abx500.h
61662@@ -455,6 +455,7 @@ struct abx500_ops {
61663 int (*event_registers_startup_state_get) (struct device *, u8 *);
61664 int (*startup_irq_enabled) (struct device *, unsigned int);
61665 };
61666+typedef struct abx500_ops __no_const abx500_ops_no_const;
61667
61668 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
61669 void abx500_remove_ops(struct device *dev);
61670diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
61671index 9b07725..3d55001 100644
61672--- a/include/linux/mfd/abx500/ux500_chargalg.h
61673+++ b/include/linux/mfd/abx500/ux500_chargalg.h
61674@@ -19,7 +19,7 @@ struct ux500_charger_ops {
61675 int (*enable) (struct ux500_charger *, int, int, int);
61676 int (*kick_wd) (struct ux500_charger *);
61677 int (*update_curr) (struct ux500_charger *, int);
61678-};
61679+} __no_const;
61680
61681 /**
61682 * struct ux500_charger - power supply ux500 charger sub class
61683diff --git a/include/linux/mm.h b/include/linux/mm.h
61684index 74aa71b..4ae97ba 100644
61685--- a/include/linux/mm.h
61686+++ b/include/linux/mm.h
61687@@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
61688
61689 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
61690 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
61691+
61692+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
61693+#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
61694+#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
61695+#else
61696 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
61697+#endif
61698+
61699 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
61700 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
61701
61702@@ -1013,34 +1020,6 @@ int set_page_dirty(struct page *page);
61703 int set_page_dirty_lock(struct page *page);
61704 int clear_page_dirty_for_io(struct page *page);
61705
61706-/* Is the vma a continuation of the stack vma above it? */
61707-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
61708-{
61709- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
61710-}
61711-
61712-static inline int stack_guard_page_start(struct vm_area_struct *vma,
61713- unsigned long addr)
61714-{
61715- return (vma->vm_flags & VM_GROWSDOWN) &&
61716- (vma->vm_start == addr) &&
61717- !vma_growsdown(vma->vm_prev, addr);
61718-}
61719-
61720-/* Is the vma a continuation of the stack vma below it? */
61721-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
61722-{
61723- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
61724-}
61725-
61726-static inline int stack_guard_page_end(struct vm_area_struct *vma,
61727- unsigned long addr)
61728-{
61729- return (vma->vm_flags & VM_GROWSUP) &&
61730- (vma->vm_end == addr) &&
61731- !vma_growsup(vma->vm_next, addr);
61732-}
61733-
61734 extern pid_t
61735 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
61736
61737@@ -1139,6 +1118,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
61738 }
61739 #endif
61740
61741+#ifdef CONFIG_MMU
61742+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
61743+#else
61744+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
61745+{
61746+ return __pgprot(0);
61747+}
61748+#endif
61749+
61750 int vma_wants_writenotify(struct vm_area_struct *vma);
61751
61752 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
61753@@ -1157,8 +1145,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
61754 {
61755 return 0;
61756 }
61757+
61758+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
61759+ unsigned long address)
61760+{
61761+ return 0;
61762+}
61763 #else
61764 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
61765+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
61766 #endif
61767
61768 #ifdef __PAGETABLE_PMD_FOLDED
61769@@ -1167,8 +1162,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
61770 {
61771 return 0;
61772 }
61773+
61774+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
61775+ unsigned long address)
61776+{
61777+ return 0;
61778+}
61779 #else
61780 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
61781+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
61782 #endif
61783
61784 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
61785@@ -1186,11 +1188,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
61786 NULL: pud_offset(pgd, address);
61787 }
61788
61789+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
61790+{
61791+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
61792+ NULL: pud_offset(pgd, address);
61793+}
61794+
61795 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
61796 {
61797 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
61798 NULL: pmd_offset(pud, address);
61799 }
61800+
61801+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
61802+{
61803+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
61804+ NULL: pmd_offset(pud, address);
61805+}
61806 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
61807
61808 #if USE_SPLIT_PTLOCKS
61809@@ -1400,6 +1414,7 @@ extern unsigned long do_mmap(struct file *, unsigned long,
61810 unsigned long, unsigned long,
61811 unsigned long, unsigned long);
61812 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
61813+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
61814
61815 /* These take the mm semaphore themselves */
61816 extern unsigned long vm_brk(unsigned long, unsigned long);
61817@@ -1462,6 +1477,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
61818 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
61819 struct vm_area_struct **pprev);
61820
61821+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
61822+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
61823+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
61824+
61825 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
61826 NULL if none. Assume start_addr < end_addr. */
61827 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
61828@@ -1490,15 +1509,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
61829 return vma;
61830 }
61831
61832-#ifdef CONFIG_MMU
61833-pgprot_t vm_get_page_prot(unsigned long vm_flags);
61834-#else
61835-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
61836-{
61837- return __pgprot(0);
61838-}
61839-#endif
61840-
61841 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
61842 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
61843 unsigned long pfn, unsigned long size, pgprot_t);
61844@@ -1602,7 +1612,7 @@ extern int unpoison_memory(unsigned long pfn);
61845 extern int sysctl_memory_failure_early_kill;
61846 extern int sysctl_memory_failure_recovery;
61847 extern void shake_page(struct page *p, int access);
61848-extern atomic_long_t mce_bad_pages;
61849+extern atomic_long_unchecked_t mce_bad_pages;
61850 extern int soft_offline_page(struct page *page, int flags);
61851
61852 extern void dump_page(struct page *page);
61853@@ -1633,5 +1643,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
61854 static inline bool page_is_guard(struct page *page) { return false; }
61855 #endif /* CONFIG_DEBUG_PAGEALLOC */
61856
61857+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
61858+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
61859+#else
61860+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
61861+#endif
61862+
61863 #endif /* __KERNEL__ */
61864 #endif /* _LINUX_MM_H */
61865diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
61866index 3cc3062..efeaeb7 100644
61867--- a/include/linux/mm_types.h
61868+++ b/include/linux/mm_types.h
61869@@ -252,6 +252,8 @@ struct vm_area_struct {
61870 #ifdef CONFIG_NUMA
61871 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
61872 #endif
61873+
61874+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
61875 };
61876
61877 struct core_thread {
61878@@ -326,7 +328,7 @@ struct mm_struct {
61879 unsigned long def_flags;
61880 unsigned long nr_ptes; /* Page table pages */
61881 unsigned long start_code, end_code, start_data, end_data;
61882- unsigned long start_brk, brk, start_stack;
61883+ unsigned long brk_gap, start_brk, brk, start_stack;
61884 unsigned long arg_start, arg_end, env_start, env_end;
61885
61886 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
61887@@ -388,6 +390,24 @@ struct mm_struct {
61888 #ifdef CONFIG_CPUMASK_OFFSTACK
61889 struct cpumask cpumask_allocation;
61890 #endif
61891+
61892+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS) || defined(CONFIG_PAX_HAVE_ACL_FLAGS) || defined(CONFIG_PAX_HOOK_ACL_FLAGS)
61893+ unsigned long pax_flags;
61894+#endif
61895+
61896+#ifdef CONFIG_PAX_DLRESOLVE
61897+ unsigned long call_dl_resolve;
61898+#endif
61899+
61900+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
61901+ unsigned long call_syscall;
61902+#endif
61903+
61904+#ifdef CONFIG_PAX_ASLR
61905+ unsigned long delta_mmap; /* randomized offset */
61906+ unsigned long delta_stack; /* randomized offset */
61907+#endif
61908+
61909 };
61910
61911 static inline void mm_init_cpumask(struct mm_struct *mm)
61912diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
61913index 1d1b1e1..2a13c78 100644
61914--- a/include/linux/mmu_notifier.h
61915+++ b/include/linux/mmu_notifier.h
61916@@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
61917 */
61918 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
61919 ({ \
61920- pte_t __pte; \
61921+ pte_t ___pte; \
61922 struct vm_area_struct *___vma = __vma; \
61923 unsigned long ___address = __address; \
61924- __pte = ptep_clear_flush(___vma, ___address, __ptep); \
61925+ ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
61926 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
61927- __pte; \
61928+ ___pte; \
61929 })
61930
61931 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
61932diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
61933index dff7115..0e001c8 100644
61934--- a/include/linux/mmzone.h
61935+++ b/include/linux/mmzone.h
61936@@ -380,7 +380,7 @@ struct zone {
61937 unsigned long flags; /* zone flags, see below */
61938
61939 /* Zone statistics */
61940- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
61941+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
61942
61943 /*
61944 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
61945diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
61946index 501da4c..ba79bb4 100644
61947--- a/include/linux/mod_devicetable.h
61948+++ b/include/linux/mod_devicetable.h
61949@@ -12,7 +12,7 @@
61950 typedef unsigned long kernel_ulong_t;
61951 #endif
61952
61953-#define PCI_ANY_ID (~0)
61954+#define PCI_ANY_ID ((__u16)~0)
61955
61956 struct pci_device_id {
61957 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
61958@@ -131,7 +131,7 @@ struct usb_device_id {
61959 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
61960 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
61961
61962-#define HID_ANY_ID (~0)
61963+#define HID_ANY_ID (~0U)
61964
61965 struct hid_device_id {
61966 __u16 bus;
61967diff --git a/include/linux/module.h b/include/linux/module.h
61968index fbcafe2..e5d9587 100644
61969--- a/include/linux/module.h
61970+++ b/include/linux/module.h
61971@@ -17,6 +17,7 @@
61972 #include <linux/moduleparam.h>
61973 #include <linux/tracepoint.h>
61974 #include <linux/export.h>
61975+#include <linux/fs.h>
61976
61977 #include <linux/percpu.h>
61978 #include <asm/module.h>
61979@@ -273,19 +274,16 @@ struct module
61980 int (*init)(void);
61981
61982 /* If this is non-NULL, vfree after init() returns */
61983- void *module_init;
61984+ void *module_init_rx, *module_init_rw;
61985
61986 /* Here is the actual code + data, vfree'd on unload. */
61987- void *module_core;
61988+ void *module_core_rx, *module_core_rw;
61989
61990 /* Here are the sizes of the init and core sections */
61991- unsigned int init_size, core_size;
61992+ unsigned int init_size_rw, core_size_rw;
61993
61994 /* The size of the executable code in each section. */
61995- unsigned int init_text_size, core_text_size;
61996-
61997- /* Size of RO sections of the module (text+rodata) */
61998- unsigned int init_ro_size, core_ro_size;
61999+ unsigned int init_size_rx, core_size_rx;
62000
62001 /* Arch-specific module values */
62002 struct mod_arch_specific arch;
62003@@ -341,6 +339,10 @@ struct module
62004 #ifdef CONFIG_EVENT_TRACING
62005 struct ftrace_event_call **trace_events;
62006 unsigned int num_trace_events;
62007+ struct file_operations trace_id;
62008+ struct file_operations trace_enable;
62009+ struct file_operations trace_format;
62010+ struct file_operations trace_filter;
62011 #endif
62012 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
62013 unsigned int num_ftrace_callsites;
62014@@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
62015 bool is_module_percpu_address(unsigned long addr);
62016 bool is_module_text_address(unsigned long addr);
62017
62018+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
62019+{
62020+
62021+#ifdef CONFIG_PAX_KERNEXEC
62022+ if (ktla_ktva(addr) >= (unsigned long)start &&
62023+ ktla_ktva(addr) < (unsigned long)start + size)
62024+ return 1;
62025+#endif
62026+
62027+ return ((void *)addr >= start && (void *)addr < start + size);
62028+}
62029+
62030+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
62031+{
62032+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
62033+}
62034+
62035+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
62036+{
62037+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
62038+}
62039+
62040+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
62041+{
62042+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
62043+}
62044+
62045+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
62046+{
62047+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
62048+}
62049+
62050 static inline int within_module_core(unsigned long addr, struct module *mod)
62051 {
62052- return (unsigned long)mod->module_core <= addr &&
62053- addr < (unsigned long)mod->module_core + mod->core_size;
62054+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
62055 }
62056
62057 static inline int within_module_init(unsigned long addr, struct module *mod)
62058 {
62059- return (unsigned long)mod->module_init <= addr &&
62060- addr < (unsigned long)mod->module_init + mod->init_size;
62061+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
62062 }
62063
62064 /* Search for module by name: must hold module_mutex. */
62065diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
62066index b2be02e..72d2f78 100644
62067--- a/include/linux/moduleloader.h
62068+++ b/include/linux/moduleloader.h
62069@@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
62070
62071 /* Allocator used for allocating struct module, core sections and init
62072 sections. Returns NULL on failure. */
62073-void *module_alloc(unsigned long size);
62074+void *module_alloc(unsigned long size) __size_overflow(1);
62075+
62076+#ifdef CONFIG_PAX_KERNEXEC
62077+void *module_alloc_exec(unsigned long size) __size_overflow(1);
62078+#else
62079+#define module_alloc_exec(x) module_alloc(x)
62080+#endif
62081
62082 /* Free memory returned from module_alloc. */
62083 void module_free(struct module *mod, void *module_region);
62084
62085+#ifdef CONFIG_PAX_KERNEXEC
62086+void module_free_exec(struct module *mod, void *module_region);
62087+#else
62088+#define module_free_exec(x, y) module_free((x), (y))
62089+#endif
62090+
62091 /* Apply the given relocation to the (simplified) ELF. Return -error
62092 or 0. */
62093 int apply_relocate(Elf_Shdr *sechdrs,
62094diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
62095index 944bc18..042d291 100644
62096--- a/include/linux/moduleparam.h
62097+++ b/include/linux/moduleparam.h
62098@@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
62099 * @len is usually just sizeof(string).
62100 */
62101 #define module_param_string(name, string, len, perm) \
62102- static const struct kparam_string __param_string_##name \
62103+ static const struct kparam_string __param_string_##name __used \
62104 = { len, string }; \
62105 __module_param_call(MODULE_PARAM_PREFIX, name, \
62106 &param_ops_string, \
62107@@ -424,7 +424,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
62108 */
62109 #define module_param_array_named(name, array, type, nump, perm) \
62110 param_check_##type(name, &(array)[0]); \
62111- static const struct kparam_array __param_arr_##name \
62112+ static const struct kparam_array __param_arr_##name __used \
62113 = { .max = ARRAY_SIZE(array), .num = nump, \
62114 .ops = &param_ops_##type, \
62115 .elemsize = sizeof(array[0]), .elem = array }; \
62116diff --git a/include/linux/namei.h b/include/linux/namei.h
62117index ffc0213..2c1f2cb 100644
62118--- a/include/linux/namei.h
62119+++ b/include/linux/namei.h
62120@@ -24,7 +24,7 @@ struct nameidata {
62121 unsigned seq;
62122 int last_type;
62123 unsigned depth;
62124- char *saved_names[MAX_NESTED_LINKS + 1];
62125+ const char *saved_names[MAX_NESTED_LINKS + 1];
62126
62127 /* Intent data */
62128 union {
62129@@ -94,12 +94,12 @@ extern int follow_up(struct path *);
62130 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
62131 extern void unlock_rename(struct dentry *, struct dentry *);
62132
62133-static inline void nd_set_link(struct nameidata *nd, char *path)
62134+static inline void nd_set_link(struct nameidata *nd, const char *path)
62135 {
62136 nd->saved_names[nd->depth] = path;
62137 }
62138
62139-static inline char *nd_get_link(struct nameidata *nd)
62140+static inline const char *nd_get_link(const struct nameidata *nd)
62141 {
62142 return nd->saved_names[nd->depth];
62143 }
62144diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
62145index 33900a5..2072000 100644
62146--- a/include/linux/netdevice.h
62147+++ b/include/linux/netdevice.h
62148@@ -1003,6 +1003,7 @@ struct net_device_ops {
62149 int (*ndo_neigh_construct)(struct neighbour *n);
62150 void (*ndo_neigh_destroy)(struct neighbour *n);
62151 };
62152+typedef struct net_device_ops __no_const net_device_ops_no_const;
62153
62154 /*
62155 * The DEVICE structure.
62156@@ -1064,7 +1065,7 @@ struct net_device {
62157 int iflink;
62158
62159 struct net_device_stats stats;
62160- atomic_long_t rx_dropped; /* dropped packets by core network
62161+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
62162 * Do not use this in drivers.
62163 */
62164
62165diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
62166new file mode 100644
62167index 0000000..33f4af8
62168--- /dev/null
62169+++ b/include/linux/netfilter/xt_gradm.h
62170@@ -0,0 +1,9 @@
62171+#ifndef _LINUX_NETFILTER_XT_GRADM_H
62172+#define _LINUX_NETFILTER_XT_GRADM_H 1
62173+
62174+struct xt_gradm_mtinfo {
62175+ __u16 flags;
62176+ __u16 invflags;
62177+};
62178+
62179+#endif
62180diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
62181index c65a18a..0c05f3a 100644
62182--- a/include/linux/of_pdt.h
62183+++ b/include/linux/of_pdt.h
62184@@ -32,7 +32,7 @@ struct of_pdt_ops {
62185
62186 /* return 0 on success; fill in 'len' with number of bytes in path */
62187 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
62188-};
62189+} __no_const;
62190
62191 extern void *prom_early_alloc(unsigned long size);
62192
62193diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
62194index a4c5624..79d6d88 100644
62195--- a/include/linux/oprofile.h
62196+++ b/include/linux/oprofile.h
62197@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
62198 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
62199 char const * name, ulong * val);
62200
62201-/** Create a file for read-only access to an atomic_t. */
62202+/** Create a file for read-only access to an atomic_unchecked_t. */
62203 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
62204- char const * name, atomic_t * val);
62205+ char const * name, atomic_unchecked_t * val);
62206
62207 /** create a directory */
62208 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
62209diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
62210index ddbb6a9..be1680e 100644
62211--- a/include/linux/perf_event.h
62212+++ b/include/linux/perf_event.h
62213@@ -879,8 +879,8 @@ struct perf_event {
62214
62215 enum perf_event_active_state state;
62216 unsigned int attach_state;
62217- local64_t count;
62218- atomic64_t child_count;
62219+ local64_t count; /* PaX: fix it one day */
62220+ atomic64_unchecked_t child_count;
62221
62222 /*
62223 * These are the total time in nanoseconds that the event
62224@@ -931,8 +931,8 @@ struct perf_event {
62225 * These accumulate total time (in nanoseconds) that children
62226 * events have been enabled and running, respectively.
62227 */
62228- atomic64_t child_total_time_enabled;
62229- atomic64_t child_total_time_running;
62230+ atomic64_unchecked_t child_total_time_enabled;
62231+ atomic64_unchecked_t child_total_time_running;
62232
62233 /*
62234 * Protect attach/detach and child_list:
62235diff --git a/include/linux/personality.h b/include/linux/personality.h
62236index 8fc7dd1a..c19d89e 100644
62237--- a/include/linux/personality.h
62238+++ b/include/linux/personality.h
62239@@ -44,6 +44,7 @@ enum {
62240 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
62241 ADDR_NO_RANDOMIZE | \
62242 ADDR_COMPAT_LAYOUT | \
62243+ ADDR_LIMIT_3GB | \
62244 MMAP_PAGE_ZERO)
62245
62246 /*
62247diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
62248index e1ac1ce..0675fed 100644
62249--- a/include/linux/pipe_fs_i.h
62250+++ b/include/linux/pipe_fs_i.h
62251@@ -45,9 +45,9 @@ struct pipe_buffer {
62252 struct pipe_inode_info {
62253 wait_queue_head_t wait;
62254 unsigned int nrbufs, curbuf, buffers;
62255- unsigned int readers;
62256- unsigned int writers;
62257- unsigned int waiting_writers;
62258+ atomic_t readers;
62259+ atomic_t writers;
62260+ atomic_t waiting_writers;
62261 unsigned int r_counter;
62262 unsigned int w_counter;
62263 struct page *tmp_page;
62264diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
62265index 609daae..5392427 100644
62266--- a/include/linux/pm_runtime.h
62267+++ b/include/linux/pm_runtime.h
62268@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
62269
62270 static inline void pm_runtime_mark_last_busy(struct device *dev)
62271 {
62272- ACCESS_ONCE(dev->power.last_busy) = jiffies;
62273+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
62274 }
62275
62276 #else /* !CONFIG_PM_RUNTIME */
62277diff --git a/include/linux/poison.h b/include/linux/poison.h
62278index 2110a81..13a11bb 100644
62279--- a/include/linux/poison.h
62280+++ b/include/linux/poison.h
62281@@ -19,8 +19,8 @@
62282 * under normal circumstances, used to verify that nobody uses
62283 * non-initialized list entries.
62284 */
62285-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
62286-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
62287+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
62288+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
62289
62290 /********** include/linux/timer.h **********/
62291 /*
62292diff --git a/include/linux/preempt.h b/include/linux/preempt.h
62293index 5a710b9..0b0dab9 100644
62294--- a/include/linux/preempt.h
62295+++ b/include/linux/preempt.h
62296@@ -126,7 +126,7 @@ struct preempt_ops {
62297 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
62298 void (*sched_out)(struct preempt_notifier *notifier,
62299 struct task_struct *next);
62300-};
62301+} __no_const;
62302
62303 /**
62304 * preempt_notifier - key for installing preemption notifiers
62305diff --git a/include/linux/printk.h b/include/linux/printk.h
62306index 0525927..a5388b6 100644
62307--- a/include/linux/printk.h
62308+++ b/include/linux/printk.h
62309@@ -94,6 +94,8 @@ void early_printk(const char *fmt, ...);
62310 extern int printk_needs_cpu(int cpu);
62311 extern void printk_tick(void);
62312
62313+extern int kptr_restrict;
62314+
62315 #ifdef CONFIG_PRINTK
62316 asmlinkage __printf(1, 0)
62317 int vprintk(const char *fmt, va_list args);
62318@@ -117,7 +119,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
62319
62320 extern int printk_delay_msec;
62321 extern int dmesg_restrict;
62322-extern int kptr_restrict;
62323
62324 void log_buf_kexec_setup(void);
62325 void __init setup_log_buf(int early);
62326diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
62327index 85c5073..51fac8b 100644
62328--- a/include/linux/proc_fs.h
62329+++ b/include/linux/proc_fs.h
62330@@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
62331 return proc_create_data(name, mode, parent, proc_fops, NULL);
62332 }
62333
62334+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
62335+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
62336+{
62337+#ifdef CONFIG_GRKERNSEC_PROC_USER
62338+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
62339+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62340+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
62341+#else
62342+ return proc_create_data(name, mode, parent, proc_fops, NULL);
62343+#endif
62344+}
62345+
62346 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
62347 umode_t mode, struct proc_dir_entry *base,
62348 read_proc_t *read_proc, void * data)
62349@@ -258,7 +270,7 @@ union proc_op {
62350 int (*proc_show)(struct seq_file *m,
62351 struct pid_namespace *ns, struct pid *pid,
62352 struct task_struct *task);
62353-};
62354+} __no_const;
62355
62356 struct ctl_table_header;
62357 struct ctl_table;
62358diff --git a/include/linux/random.h b/include/linux/random.h
62359index 8f74538..02a1012 100644
62360--- a/include/linux/random.h
62361+++ b/include/linux/random.h
62362@@ -69,12 +69,17 @@ void srandom32(u32 seed);
62363
62364 u32 prandom32(struct rnd_state *);
62365
62366+static inline unsigned long pax_get_random_long(void)
62367+{
62368+ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
62369+}
62370+
62371 /*
62372 * Handle minimum values for seeds
62373 */
62374 static inline u32 __seed(u32 x, u32 m)
62375 {
62376- return (x < m) ? x + m : x;
62377+ return (x <= m) ? x + m + 1 : x;
62378 }
62379
62380 /**
62381diff --git a/include/linux/reboot.h b/include/linux/reboot.h
62382index e0879a7..a12f962 100644
62383--- a/include/linux/reboot.h
62384+++ b/include/linux/reboot.h
62385@@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
62386 * Architecture-specific implementations of sys_reboot commands.
62387 */
62388
62389-extern void machine_restart(char *cmd);
62390-extern void machine_halt(void);
62391-extern void machine_power_off(void);
62392+extern void machine_restart(char *cmd) __noreturn;
62393+extern void machine_halt(void) __noreturn;
62394+extern void machine_power_off(void) __noreturn;
62395
62396 extern void machine_shutdown(void);
62397 struct pt_regs;
62398@@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
62399 */
62400
62401 extern void kernel_restart_prepare(char *cmd);
62402-extern void kernel_restart(char *cmd);
62403-extern void kernel_halt(void);
62404-extern void kernel_power_off(void);
62405+extern void kernel_restart(char *cmd) __noreturn;
62406+extern void kernel_halt(void) __noreturn;
62407+extern void kernel_power_off(void) __noreturn;
62408
62409 extern int C_A_D; /* for sysctl */
62410 void ctrl_alt_del(void);
62411@@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
62412 * Emergency restart, callable from an interrupt handler.
62413 */
62414
62415-extern void emergency_restart(void);
62416+extern void emergency_restart(void) __noreturn;
62417 #include <asm/emergency-restart.h>
62418
62419 #endif
62420diff --git a/include/linux/relay.h b/include/linux/relay.h
62421index 91cacc3..b55ff74 100644
62422--- a/include/linux/relay.h
62423+++ b/include/linux/relay.h
62424@@ -160,7 +160,7 @@ struct rchan_callbacks
62425 * The callback should return 0 if successful, negative if not.
62426 */
62427 int (*remove_buf_file)(struct dentry *dentry);
62428-};
62429+} __no_const;
62430
62431 /*
62432 * CONFIG_RELAY kernel API, kernel/relay.c
62433diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
62434index 6fdf027..ff72610 100644
62435--- a/include/linux/rfkill.h
62436+++ b/include/linux/rfkill.h
62437@@ -147,6 +147,7 @@ struct rfkill_ops {
62438 void (*query)(struct rfkill *rfkill, void *data);
62439 int (*set_block)(void *data, bool blocked);
62440 };
62441+typedef struct rfkill_ops __no_const rfkill_ops_no_const;
62442
62443 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
62444 /**
62445diff --git a/include/linux/rio.h b/include/linux/rio.h
62446index 4d50611..c6858a2 100644
62447--- a/include/linux/rio.h
62448+++ b/include/linux/rio.h
62449@@ -315,7 +315,7 @@ struct rio_ops {
62450 int mbox, void *buffer, size_t len);
62451 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
62452 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
62453-};
62454+} __no_const;
62455
62456 #define RIO_RESOURCE_MEM 0x00000100
62457 #define RIO_RESOURCE_DOORBELL 0x00000200
62458diff --git a/include/linux/rmap.h b/include/linux/rmap.h
62459index fd07c45..4676b8e 100644
62460--- a/include/linux/rmap.h
62461+++ b/include/linux/rmap.h
62462@@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
62463 void anon_vma_init(void); /* create anon_vma_cachep */
62464 int anon_vma_prepare(struct vm_area_struct *);
62465 void unlink_anon_vmas(struct vm_area_struct *);
62466-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
62467+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
62468 void anon_vma_moveto_tail(struct vm_area_struct *);
62469-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
62470+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
62471
62472 static inline void anon_vma_merge(struct vm_area_struct *vma,
62473 struct vm_area_struct *next)
62474diff --git a/include/linux/sched.h b/include/linux/sched.h
62475index 81a173c..85ccd8f 100644
62476--- a/include/linux/sched.h
62477+++ b/include/linux/sched.h
62478@@ -100,6 +100,7 @@ struct bio_list;
62479 struct fs_struct;
62480 struct perf_event_context;
62481 struct blk_plug;
62482+struct linux_binprm;
62483
62484 /*
62485 * List of flags we want to share for kernel threads,
62486@@ -382,10 +383,13 @@ struct user_namespace;
62487 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
62488
62489 extern int sysctl_max_map_count;
62490+extern unsigned long sysctl_heap_stack_gap;
62491
62492 #include <linux/aio.h>
62493
62494 #ifdef CONFIG_MMU
62495+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
62496+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
62497 extern void arch_pick_mmap_layout(struct mm_struct *mm);
62498 extern unsigned long
62499 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
62500@@ -643,6 +647,17 @@ struct signal_struct {
62501 #ifdef CONFIG_TASKSTATS
62502 struct taskstats *stats;
62503 #endif
62504+
62505+#ifdef CONFIG_GRKERNSEC
62506+ u32 curr_ip;
62507+ u32 saved_ip;
62508+ u32 gr_saddr;
62509+ u32 gr_daddr;
62510+ u16 gr_sport;
62511+ u16 gr_dport;
62512+ u8 used_accept:1;
62513+#endif
62514+
62515 #ifdef CONFIG_AUDIT
62516 unsigned audit_tty;
62517 struct tty_audit_buf *tty_audit_buf;
62518@@ -726,6 +741,11 @@ struct user_struct {
62519 struct key *session_keyring; /* UID's default session keyring */
62520 #endif
62521
62522+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
62523+ unsigned int banned;
62524+ unsigned long ban_expires;
62525+#endif
62526+
62527 /* Hash table maintenance information */
62528 struct hlist_node uidhash_node;
62529 uid_t uid;
62530@@ -1386,8 +1406,8 @@ struct task_struct {
62531 struct list_head thread_group;
62532
62533 struct completion *vfork_done; /* for vfork() */
62534- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
62535- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
62536+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
62537+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
62538
62539 cputime_t utime, stime, utimescaled, stimescaled;
62540 cputime_t gtime;
62541@@ -1403,13 +1423,6 @@ struct task_struct {
62542 struct task_cputime cputime_expires;
62543 struct list_head cpu_timers[3];
62544
62545-/* process credentials */
62546- const struct cred __rcu *real_cred; /* objective and real subjective task
62547- * credentials (COW) */
62548- const struct cred __rcu *cred; /* effective (overridable) subjective task
62549- * credentials (COW) */
62550- struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
62551-
62552 char comm[TASK_COMM_LEN]; /* executable name excluding path
62553 - access with [gs]et_task_comm (which lock
62554 it with task_lock())
62555@@ -1426,8 +1439,16 @@ struct task_struct {
62556 #endif
62557 /* CPU-specific state of this task */
62558 struct thread_struct thread;
62559+/* thread_info moved to task_struct */
62560+#ifdef CONFIG_X86
62561+ struct thread_info tinfo;
62562+#endif
62563 /* filesystem information */
62564 struct fs_struct *fs;
62565+
62566+ const struct cred __rcu *cred; /* effective (overridable) subjective task
62567+ * credentials (COW) */
62568+
62569 /* open file information */
62570 struct files_struct *files;
62571 /* namespaces */
62572@@ -1469,6 +1490,11 @@ struct task_struct {
62573 struct rt_mutex_waiter *pi_blocked_on;
62574 #endif
62575
62576+/* process credentials */
62577+ const struct cred __rcu *real_cred; /* objective and real subjective task
62578+ * credentials (COW) */
62579+ struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
62580+
62581 #ifdef CONFIG_DEBUG_MUTEXES
62582 /* mutex deadlock detection */
62583 struct mutex_waiter *blocked_on;
62584@@ -1585,6 +1611,27 @@ struct task_struct {
62585 unsigned long default_timer_slack_ns;
62586
62587 struct list_head *scm_work_list;
62588+
62589+#ifdef CONFIG_GRKERNSEC
62590+ /* grsecurity */
62591+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62592+ u64 exec_id;
62593+#endif
62594+#ifdef CONFIG_GRKERNSEC_SETXID
62595+ const struct cred *delayed_cred;
62596+#endif
62597+ struct dentry *gr_chroot_dentry;
62598+ struct acl_subject_label *acl;
62599+ struct acl_role_label *role;
62600+ struct file *exec_file;
62601+ u16 acl_role_id;
62602+ /* is this the task that authenticated to the special role */
62603+ u8 acl_sp_role;
62604+ u8 is_writable;
62605+ u8 brute;
62606+ u8 gr_is_chrooted;
62607+#endif
62608+
62609 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
62610 /* Index of current stored address in ret_stack */
62611 int curr_ret_stack;
62612@@ -1619,6 +1666,51 @@ struct task_struct {
62613 #endif
62614 };
62615
62616+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
62617+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
62618+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
62619+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
62620+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
62621+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
62622+
62623+#ifdef CONFIG_PAX_SOFTMODE
62624+extern int pax_softmode;
62625+#endif
62626+
62627+extern int pax_check_flags(unsigned long *);
62628+
62629+/* if tsk != current then task_lock must be held on it */
62630+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62631+static inline unsigned long pax_get_flags(struct task_struct *tsk)
62632+{
62633+ if (likely(tsk->mm))
62634+ return tsk->mm->pax_flags;
62635+ else
62636+ return 0UL;
62637+}
62638+
62639+/* if tsk != current then task_lock must be held on it */
62640+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
62641+{
62642+ if (likely(tsk->mm)) {
62643+ tsk->mm->pax_flags = flags;
62644+ return 0;
62645+ }
62646+ return -EINVAL;
62647+}
62648+#endif
62649+
62650+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
62651+extern void pax_set_initial_flags(struct linux_binprm *bprm);
62652+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
62653+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
62654+#endif
62655+
62656+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
62657+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
62658+extern void pax_report_refcount_overflow(struct pt_regs *regs);
62659+extern __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type);
62660+
62661 /* Future-safe accessor for struct task_struct's cpus_allowed. */
62662 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
62663
62664@@ -2138,7 +2230,9 @@ void yield(void);
62665 extern struct exec_domain default_exec_domain;
62666
62667 union thread_union {
62668+#ifndef CONFIG_X86
62669 struct thread_info thread_info;
62670+#endif
62671 unsigned long stack[THREAD_SIZE/sizeof(long)];
62672 };
62673
62674@@ -2171,6 +2265,7 @@ extern struct pid_namespace init_pid_ns;
62675 */
62676
62677 extern struct task_struct *find_task_by_vpid(pid_t nr);
62678+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
62679 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
62680 struct pid_namespace *ns);
62681
62682@@ -2314,7 +2409,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
62683 extern void exit_itimers(struct signal_struct *);
62684 extern void flush_itimer_signals(void);
62685
62686-extern void do_group_exit(int);
62687+extern __noreturn void do_group_exit(int);
62688
62689 extern void daemonize(const char *, ...);
62690 extern int allow_signal(int);
62691@@ -2515,13 +2610,17 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
62692
62693 #endif
62694
62695-static inline int object_is_on_stack(void *obj)
62696+static inline int object_starts_on_stack(void *obj)
62697 {
62698- void *stack = task_stack_page(current);
62699+ const void *stack = task_stack_page(current);
62700
62701 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
62702 }
62703
62704+#ifdef CONFIG_PAX_USERCOPY
62705+extern int object_is_on_stack(const void *obj, unsigned long len);
62706+#endif
62707+
62708 extern void thread_info_cache_init(void);
62709
62710 #ifdef CONFIG_DEBUG_STACK_USAGE
62711diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
62712index 899fbb4..1cb4138 100644
62713--- a/include/linux/screen_info.h
62714+++ b/include/linux/screen_info.h
62715@@ -43,7 +43,8 @@ struct screen_info {
62716 __u16 pages; /* 0x32 */
62717 __u16 vesa_attributes; /* 0x34 */
62718 __u32 capabilities; /* 0x36 */
62719- __u8 _reserved[6]; /* 0x3a */
62720+ __u16 vesapm_size; /* 0x3a */
62721+ __u8 _reserved[4]; /* 0x3c */
62722 } __attribute__((packed));
62723
62724 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
62725diff --git a/include/linux/security.h b/include/linux/security.h
62726index 673afbb..2b7454b 100644
62727--- a/include/linux/security.h
62728+++ b/include/linux/security.h
62729@@ -26,6 +26,7 @@
62730 #include <linux/capability.h>
62731 #include <linux/slab.h>
62732 #include <linux/err.h>
62733+#include <linux/grsecurity.h>
62734
62735 struct linux_binprm;
62736 struct cred;
62737diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
62738index fc61854..d7c490b 100644
62739--- a/include/linux/seq_file.h
62740+++ b/include/linux/seq_file.h
62741@@ -25,6 +25,9 @@ struct seq_file {
62742 struct mutex lock;
62743 const struct seq_operations *op;
62744 int poll_event;
62745+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62746+ u64 exec_id;
62747+#endif
62748 void *private;
62749 };
62750
62751@@ -34,6 +37,7 @@ struct seq_operations {
62752 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
62753 int (*show) (struct seq_file *m, void *v);
62754 };
62755+typedef struct seq_operations __no_const seq_operations_no_const;
62756
62757 #define SEQ_SKIP 1
62758
62759diff --git a/include/linux/shm.h b/include/linux/shm.h
62760index 92808b8..c28cac4 100644
62761--- a/include/linux/shm.h
62762+++ b/include/linux/shm.h
62763@@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
62764
62765 /* The task created the shm object. NULL if the task is dead. */
62766 struct task_struct *shm_creator;
62767+#ifdef CONFIG_GRKERNSEC
62768+ time_t shm_createtime;
62769+ pid_t shm_lapid;
62770+#endif
62771 };
62772
62773 /* shm_mode upper byte flags */
62774diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
62775index c168907..c7756db 100644
62776--- a/include/linux/skbuff.h
62777+++ b/include/linux/skbuff.h
62778@@ -666,7 +666,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
62779 */
62780 static inline int skb_queue_empty(const struct sk_buff_head *list)
62781 {
62782- return list->next == (struct sk_buff *)list;
62783+ return list->next == (const struct sk_buff *)list;
62784 }
62785
62786 /**
62787@@ -679,7 +679,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
62788 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
62789 const struct sk_buff *skb)
62790 {
62791- return skb->next == (struct sk_buff *)list;
62792+ return skb->next == (const struct sk_buff *)list;
62793 }
62794
62795 /**
62796@@ -692,7 +692,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
62797 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
62798 const struct sk_buff *skb)
62799 {
62800- return skb->prev == (struct sk_buff *)list;
62801+ return skb->prev == (const struct sk_buff *)list;
62802 }
62803
62804 /**
62805@@ -1587,7 +1587,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
62806 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
62807 */
62808 #ifndef NET_SKB_PAD
62809-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
62810+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
62811 #endif
62812
62813 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
62814diff --git a/include/linux/slab.h b/include/linux/slab.h
62815index a595dce..c403597 100644
62816--- a/include/linux/slab.h
62817+++ b/include/linux/slab.h
62818@@ -11,12 +11,20 @@
62819
62820 #include <linux/gfp.h>
62821 #include <linux/types.h>
62822+#include <linux/err.h>
62823
62824 /*
62825 * Flags to pass to kmem_cache_create().
62826 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
62827 */
62828 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
62829+
62830+#ifdef CONFIG_PAX_USERCOPY
62831+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
62832+#else
62833+#define SLAB_USERCOPY 0x00000000UL
62834+#endif
62835+
62836 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
62837 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
62838 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
62839@@ -87,10 +95,13 @@
62840 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
62841 * Both make kfree a no-op.
62842 */
62843-#define ZERO_SIZE_PTR ((void *)16)
62844+#define ZERO_SIZE_PTR \
62845+({ \
62846+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
62847+ (void *)(-MAX_ERRNO-1L); \
62848+})
62849
62850-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
62851- (unsigned long)ZERO_SIZE_PTR)
62852+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
62853
62854 /*
62855 * struct kmem_cache related prototypes
62856@@ -161,6 +172,7 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
62857 void kfree(const void *);
62858 void kzfree(const void *);
62859 size_t ksize(const void *);
62860+void check_object_size(const void *ptr, unsigned long n, bool to);
62861
62862 /*
62863 * Allocator specific definitions. These are mainly used to establish optimized
62864@@ -240,6 +252,7 @@ size_t ksize(const void *);
62865 * for general use, and so are not documented here. For a full list of
62866 * potential flags, always refer to linux/gfp.h.
62867 */
62868+static void *kmalloc_array(size_t n, size_t size, gfp_t flags) __size_overflow(1, 2);
62869 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
62870 {
62871 if (size != 0 && n > ULONG_MAX / size)
62872@@ -298,7 +311,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
62873 */
62874 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
62875 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
62876-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
62877+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
62878 #define kmalloc_track_caller(size, flags) \
62879 __kmalloc_track_caller(size, flags, _RET_IP_)
62880 #else
62881@@ -317,7 +330,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
62882 */
62883 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
62884 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
62885-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
62886+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
62887 #define kmalloc_node_track_caller(size, flags, node) \
62888 __kmalloc_node_track_caller(size, flags, node, \
62889 _RET_IP_)
62890diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
62891index fbd1117..d4d8ef8 100644
62892--- a/include/linux/slab_def.h
62893+++ b/include/linux/slab_def.h
62894@@ -66,10 +66,10 @@ struct kmem_cache {
62895 unsigned long node_allocs;
62896 unsigned long node_frees;
62897 unsigned long node_overflow;
62898- atomic_t allochit;
62899- atomic_t allocmiss;
62900- atomic_t freehit;
62901- atomic_t freemiss;
62902+ atomic_unchecked_t allochit;
62903+ atomic_unchecked_t allocmiss;
62904+ atomic_unchecked_t freehit;
62905+ atomic_unchecked_t freemiss;
62906
62907 /*
62908 * If debugging is enabled, then the allocator can add additional
62909@@ -107,7 +107,7 @@ struct cache_sizes {
62910 extern struct cache_sizes malloc_sizes[];
62911
62912 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
62913-void *__kmalloc(size_t size, gfp_t flags);
62914+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
62915
62916 #ifdef CONFIG_TRACING
62917 extern void *kmem_cache_alloc_trace(size_t size,
62918@@ -160,7 +160,7 @@ found:
62919 }
62920
62921 #ifdef CONFIG_NUMA
62922-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
62923+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
62924 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
62925
62926 #ifdef CONFIG_TRACING
62927diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
62928index 0ec00b3..39cb7fc 100644
62929--- a/include/linux/slob_def.h
62930+++ b/include/linux/slob_def.h
62931@@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
62932 return kmem_cache_alloc_node(cachep, flags, -1);
62933 }
62934
62935-void *__kmalloc_node(size_t size, gfp_t flags, int node);
62936+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
62937
62938 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
62939 {
62940@@ -29,6 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
62941 return __kmalloc_node(size, flags, -1);
62942 }
62943
62944+static __always_inline void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
62945 static __always_inline void *__kmalloc(size_t size, gfp_t flags)
62946 {
62947 return kmalloc(size, flags);
62948diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
62949index c2f8c8b..be9e036 100644
62950--- a/include/linux/slub_def.h
62951+++ b/include/linux/slub_def.h
62952@@ -92,7 +92,7 @@ struct kmem_cache {
62953 struct kmem_cache_order_objects max;
62954 struct kmem_cache_order_objects min;
62955 gfp_t allocflags; /* gfp flags to use on each alloc */
62956- int refcount; /* Refcount for slab cache destroy */
62957+ atomic_t refcount; /* Refcount for slab cache destroy */
62958 void (*ctor)(void *);
62959 int inuse; /* Offset to metadata */
62960 int align; /* Alignment */
62961@@ -153,6 +153,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
62962 * Sorry that the following has to be that ugly but some versions of GCC
62963 * have trouble with constant propagation and loops.
62964 */
62965+static __always_inline int kmalloc_index(size_t size) __size_overflow(1);
62966 static __always_inline int kmalloc_index(size_t size)
62967 {
62968 if (!size)
62969@@ -218,7 +219,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
62970 }
62971
62972 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
62973-void *__kmalloc(size_t size, gfp_t flags);
62974+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
62975
62976 static __always_inline void *
62977 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
62978@@ -259,6 +260,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
62979 }
62980 #endif
62981
62982+static __always_inline void *kmalloc_large(size_t size, gfp_t flags) __size_overflow(1);
62983 static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
62984 {
62985 unsigned int order = get_order(size);
62986@@ -284,7 +286,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
62987 }
62988
62989 #ifdef CONFIG_NUMA
62990-void *__kmalloc_node(size_t size, gfp_t flags, int node);
62991+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
62992 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
62993
62994 #ifdef CONFIG_TRACING
62995diff --git a/include/linux/sonet.h b/include/linux/sonet.h
62996index de8832d..0147b46 100644
62997--- a/include/linux/sonet.h
62998+++ b/include/linux/sonet.h
62999@@ -61,7 +61,7 @@ struct sonet_stats {
63000 #include <linux/atomic.h>
63001
63002 struct k_sonet_stats {
63003-#define __HANDLE_ITEM(i) atomic_t i
63004+#define __HANDLE_ITEM(i) atomic_unchecked_t i
63005 __SONET_ITEMS
63006 #undef __HANDLE_ITEM
63007 };
63008diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
63009index 523547e..2cb7140 100644
63010--- a/include/linux/sunrpc/clnt.h
63011+++ b/include/linux/sunrpc/clnt.h
63012@@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
63013 {
63014 switch (sap->sa_family) {
63015 case AF_INET:
63016- return ntohs(((struct sockaddr_in *)sap)->sin_port);
63017+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
63018 case AF_INET6:
63019- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
63020+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
63021 }
63022 return 0;
63023 }
63024@@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
63025 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
63026 const struct sockaddr *src)
63027 {
63028- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
63029+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
63030 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
63031
63032 dsin->sin_family = ssin->sin_family;
63033@@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
63034 if (sa->sa_family != AF_INET6)
63035 return 0;
63036
63037- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
63038+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
63039 }
63040
63041 #endif /* __KERNEL__ */
63042diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
63043index dc0c3cc..8503fb6 100644
63044--- a/include/linux/sunrpc/sched.h
63045+++ b/include/linux/sunrpc/sched.h
63046@@ -106,6 +106,7 @@ struct rpc_call_ops {
63047 void (*rpc_count_stats)(struct rpc_task *, void *);
63048 void (*rpc_release)(void *);
63049 };
63050+typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
63051
63052 struct rpc_task_setup {
63053 struct rpc_task *task;
63054diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
63055index 0b8e3e6..33e0a01 100644
63056--- a/include/linux/sunrpc/svc_rdma.h
63057+++ b/include/linux/sunrpc/svc_rdma.h
63058@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
63059 extern unsigned int svcrdma_max_requests;
63060 extern unsigned int svcrdma_max_req_size;
63061
63062-extern atomic_t rdma_stat_recv;
63063-extern atomic_t rdma_stat_read;
63064-extern atomic_t rdma_stat_write;
63065-extern atomic_t rdma_stat_sq_starve;
63066-extern atomic_t rdma_stat_rq_starve;
63067-extern atomic_t rdma_stat_rq_poll;
63068-extern atomic_t rdma_stat_rq_prod;
63069-extern atomic_t rdma_stat_sq_poll;
63070-extern atomic_t rdma_stat_sq_prod;
63071+extern atomic_unchecked_t rdma_stat_recv;
63072+extern atomic_unchecked_t rdma_stat_read;
63073+extern atomic_unchecked_t rdma_stat_write;
63074+extern atomic_unchecked_t rdma_stat_sq_starve;
63075+extern atomic_unchecked_t rdma_stat_rq_starve;
63076+extern atomic_unchecked_t rdma_stat_rq_poll;
63077+extern atomic_unchecked_t rdma_stat_rq_prod;
63078+extern atomic_unchecked_t rdma_stat_sq_poll;
63079+extern atomic_unchecked_t rdma_stat_sq_prod;
63080
63081 #define RPCRDMA_VERSION 1
63082
63083diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
63084index c34b4c8..a65b67d 100644
63085--- a/include/linux/sysctl.h
63086+++ b/include/linux/sysctl.h
63087@@ -155,7 +155,11 @@ enum
63088 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
63089 };
63090
63091-
63092+#ifdef CONFIG_PAX_SOFTMODE
63093+enum {
63094+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
63095+};
63096+#endif
63097
63098 /* CTL_VM names: */
63099 enum
63100@@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
63101
63102 extern int proc_dostring(struct ctl_table *, int,
63103 void __user *, size_t *, loff_t *);
63104+extern int proc_dostring_modpriv(struct ctl_table *, int,
63105+ void __user *, size_t *, loff_t *);
63106 extern int proc_dointvec(struct ctl_table *, int,
63107 void __user *, size_t *, loff_t *);
63108 extern int proc_dointvec_minmax(struct ctl_table *, int,
63109diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
63110index ff7dc08..893e1bd 100644
63111--- a/include/linux/tty_ldisc.h
63112+++ b/include/linux/tty_ldisc.h
63113@@ -148,7 +148,7 @@ struct tty_ldisc_ops {
63114
63115 struct module *owner;
63116
63117- int refcount;
63118+ atomic_t refcount;
63119 };
63120
63121 struct tty_ldisc {
63122diff --git a/include/linux/types.h b/include/linux/types.h
63123index 7f480db..175c256 100644
63124--- a/include/linux/types.h
63125+++ b/include/linux/types.h
63126@@ -220,10 +220,26 @@ typedef struct {
63127 int counter;
63128 } atomic_t;
63129
63130+#ifdef CONFIG_PAX_REFCOUNT
63131+typedef struct {
63132+ int counter;
63133+} atomic_unchecked_t;
63134+#else
63135+typedef atomic_t atomic_unchecked_t;
63136+#endif
63137+
63138 #ifdef CONFIG_64BIT
63139 typedef struct {
63140 long counter;
63141 } atomic64_t;
63142+
63143+#ifdef CONFIG_PAX_REFCOUNT
63144+typedef struct {
63145+ long counter;
63146+} atomic64_unchecked_t;
63147+#else
63148+typedef atomic64_t atomic64_unchecked_t;
63149+#endif
63150 #endif
63151
63152 struct list_head {
63153diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
63154index 5ca0951..ab496a5 100644
63155--- a/include/linux/uaccess.h
63156+++ b/include/linux/uaccess.h
63157@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
63158 long ret; \
63159 mm_segment_t old_fs = get_fs(); \
63160 \
63161- set_fs(KERNEL_DS); \
63162 pagefault_disable(); \
63163- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
63164- pagefault_enable(); \
63165+ set_fs(KERNEL_DS); \
63166+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
63167 set_fs(old_fs); \
63168+ pagefault_enable(); \
63169 ret; \
63170 })
63171
63172diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
63173index 99c1b4d..bb94261 100644
63174--- a/include/linux/unaligned/access_ok.h
63175+++ b/include/linux/unaligned/access_ok.h
63176@@ -6,32 +6,32 @@
63177
63178 static inline u16 get_unaligned_le16(const void *p)
63179 {
63180- return le16_to_cpup((__le16 *)p);
63181+ return le16_to_cpup((const __le16 *)p);
63182 }
63183
63184 static inline u32 get_unaligned_le32(const void *p)
63185 {
63186- return le32_to_cpup((__le32 *)p);
63187+ return le32_to_cpup((const __le32 *)p);
63188 }
63189
63190 static inline u64 get_unaligned_le64(const void *p)
63191 {
63192- return le64_to_cpup((__le64 *)p);
63193+ return le64_to_cpup((const __le64 *)p);
63194 }
63195
63196 static inline u16 get_unaligned_be16(const void *p)
63197 {
63198- return be16_to_cpup((__be16 *)p);
63199+ return be16_to_cpup((const __be16 *)p);
63200 }
63201
63202 static inline u32 get_unaligned_be32(const void *p)
63203 {
63204- return be32_to_cpup((__be32 *)p);
63205+ return be32_to_cpup((const __be32 *)p);
63206 }
63207
63208 static inline u64 get_unaligned_be64(const void *p)
63209 {
63210- return be64_to_cpup((__be64 *)p);
63211+ return be64_to_cpup((const __be64 *)p);
63212 }
63213
63214 static inline void put_unaligned_le16(u16 val, void *p)
63215diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
63216index 547e59c..db6ad19 100644
63217--- a/include/linux/usb/renesas_usbhs.h
63218+++ b/include/linux/usb/renesas_usbhs.h
63219@@ -39,7 +39,7 @@ enum {
63220 */
63221 struct renesas_usbhs_driver_callback {
63222 int (*notify_hotplug)(struct platform_device *pdev);
63223-};
63224+} __no_const;
63225
63226 /*
63227 * callback functions for platform
63228@@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
63229 * VBUS control is needed for Host
63230 */
63231 int (*set_vbus)(struct platform_device *pdev, int enable);
63232-};
63233+} __no_const;
63234
63235 /*
63236 * parameters for renesas usbhs
63237diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
63238index 6f8fbcf..8259001 100644
63239--- a/include/linux/vermagic.h
63240+++ b/include/linux/vermagic.h
63241@@ -25,9 +25,35 @@
63242 #define MODULE_ARCH_VERMAGIC ""
63243 #endif
63244
63245+#ifdef CONFIG_PAX_REFCOUNT
63246+#define MODULE_PAX_REFCOUNT "REFCOUNT "
63247+#else
63248+#define MODULE_PAX_REFCOUNT ""
63249+#endif
63250+
63251+#ifdef CONSTIFY_PLUGIN
63252+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
63253+#else
63254+#define MODULE_CONSTIFY_PLUGIN ""
63255+#endif
63256+
63257+#ifdef STACKLEAK_PLUGIN
63258+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
63259+#else
63260+#define MODULE_STACKLEAK_PLUGIN ""
63261+#endif
63262+
63263+#ifdef CONFIG_GRKERNSEC
63264+#define MODULE_GRSEC "GRSEC "
63265+#else
63266+#define MODULE_GRSEC ""
63267+#endif
63268+
63269 #define VERMAGIC_STRING \
63270 UTS_RELEASE " " \
63271 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
63272 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
63273- MODULE_ARCH_VERMAGIC
63274+ MODULE_ARCH_VERMAGIC \
63275+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
63276+ MODULE_GRSEC
63277
63278diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
63279index dcdfc2b..ec79ab5 100644
63280--- a/include/linux/vmalloc.h
63281+++ b/include/linux/vmalloc.h
63282@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
63283 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
63284 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
63285 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
63286+
63287+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
63288+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
63289+#endif
63290+
63291 /* bits [20..32] reserved for arch specific ioremap internals */
63292
63293 /*
63294@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
63295 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
63296 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
63297 unsigned long start, unsigned long end, gfp_t gfp_mask,
63298- pgprot_t prot, int node, void *caller);
63299+ pgprot_t prot, int node, void *caller) __size_overflow(1);
63300 extern void vfree(const void *addr);
63301
63302 extern void *vmap(struct page **pages, unsigned int count,
63303@@ -123,8 +128,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
63304 extern void free_vm_area(struct vm_struct *area);
63305
63306 /* for /dev/kmem */
63307-extern long vread(char *buf, char *addr, unsigned long count);
63308-extern long vwrite(char *buf, char *addr, unsigned long count);
63309+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
63310+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
63311
63312 /*
63313 * Internals. Dont't use..
63314diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
63315index 65efb92..137adbb 100644
63316--- a/include/linux/vmstat.h
63317+++ b/include/linux/vmstat.h
63318@@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
63319 /*
63320 * Zone based page accounting with per cpu differentials.
63321 */
63322-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63323+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63324
63325 static inline void zone_page_state_add(long x, struct zone *zone,
63326 enum zone_stat_item item)
63327 {
63328- atomic_long_add(x, &zone->vm_stat[item]);
63329- atomic_long_add(x, &vm_stat[item]);
63330+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
63331+ atomic_long_add_unchecked(x, &vm_stat[item]);
63332 }
63333
63334 static inline unsigned long global_page_state(enum zone_stat_item item)
63335 {
63336- long x = atomic_long_read(&vm_stat[item]);
63337+ long x = atomic_long_read_unchecked(&vm_stat[item]);
63338 #ifdef CONFIG_SMP
63339 if (x < 0)
63340 x = 0;
63341@@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
63342 static inline unsigned long zone_page_state(struct zone *zone,
63343 enum zone_stat_item item)
63344 {
63345- long x = atomic_long_read(&zone->vm_stat[item]);
63346+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
63347 #ifdef CONFIG_SMP
63348 if (x < 0)
63349 x = 0;
63350@@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
63351 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
63352 enum zone_stat_item item)
63353 {
63354- long x = atomic_long_read(&zone->vm_stat[item]);
63355+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
63356
63357 #ifdef CONFIG_SMP
63358 int cpu;
63359@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
63360
63361 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
63362 {
63363- atomic_long_inc(&zone->vm_stat[item]);
63364- atomic_long_inc(&vm_stat[item]);
63365+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
63366+ atomic_long_inc_unchecked(&vm_stat[item]);
63367 }
63368
63369 static inline void __inc_zone_page_state(struct page *page,
63370@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
63371
63372 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
63373 {
63374- atomic_long_dec(&zone->vm_stat[item]);
63375- atomic_long_dec(&vm_stat[item]);
63376+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
63377+ atomic_long_dec_unchecked(&vm_stat[item]);
63378 }
63379
63380 static inline void __dec_zone_page_state(struct page *page,
63381diff --git a/include/linux/xattr.h b/include/linux/xattr.h
63382index e5d1220..ef6e406 100644
63383--- a/include/linux/xattr.h
63384+++ b/include/linux/xattr.h
63385@@ -57,6 +57,11 @@
63386 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
63387 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
63388
63389+/* User namespace */
63390+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
63391+#define XATTR_PAX_FLAGS_SUFFIX "flags"
63392+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
63393+
63394 #ifdef __KERNEL__
63395
63396 #include <linux/types.h>
63397diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
63398index 4aeff96..b378cdc 100644
63399--- a/include/media/saa7146_vv.h
63400+++ b/include/media/saa7146_vv.h
63401@@ -163,7 +163,7 @@ struct saa7146_ext_vv
63402 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
63403
63404 /* the extension can override this */
63405- struct v4l2_ioctl_ops ops;
63406+ v4l2_ioctl_ops_no_const ops;
63407 /* pointer to the saa7146 core ops */
63408 const struct v4l2_ioctl_ops *core_ops;
63409
63410diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
63411index 96d2221..2292f89 100644
63412--- a/include/media/v4l2-dev.h
63413+++ b/include/media/v4l2-dev.h
63414@@ -56,7 +56,7 @@ int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);
63415
63416
63417 struct v4l2_file_operations {
63418- struct module *owner;
63419+ struct module * const owner;
63420 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
63421 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
63422 unsigned int (*poll) (struct file *, struct poll_table_struct *);
63423@@ -71,6 +71,7 @@ struct v4l2_file_operations {
63424 int (*open) (struct file *);
63425 int (*release) (struct file *);
63426 };
63427+typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
63428
63429 /*
63430 * Newer version of video_device, handled by videodev2.c
63431diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
63432index 3cb939c..f23c6bb 100644
63433--- a/include/media/v4l2-ioctl.h
63434+++ b/include/media/v4l2-ioctl.h
63435@@ -281,7 +281,7 @@ struct v4l2_ioctl_ops {
63436 long (*vidioc_default) (struct file *file, void *fh,
63437 bool valid_prio, int cmd, void *arg);
63438 };
63439-
63440+typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
63441
63442 /* v4l debugging and diagnostics */
63443
63444diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
63445index 6db8ecf..8c23861 100644
63446--- a/include/net/caif/caif_hsi.h
63447+++ b/include/net/caif/caif_hsi.h
63448@@ -98,7 +98,7 @@ struct cfhsi_drv {
63449 void (*rx_done_cb) (struct cfhsi_drv *drv);
63450 void (*wake_up_cb) (struct cfhsi_drv *drv);
63451 void (*wake_down_cb) (struct cfhsi_drv *drv);
63452-};
63453+} __no_const;
63454
63455 /* Structure implemented by HSI device. */
63456 struct cfhsi_dev {
63457diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
63458index 9e5425b..8136ffc 100644
63459--- a/include/net/caif/cfctrl.h
63460+++ b/include/net/caif/cfctrl.h
63461@@ -52,7 +52,7 @@ struct cfctrl_rsp {
63462 void (*radioset_rsp)(void);
63463 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
63464 struct cflayer *client_layer);
63465-};
63466+} __no_const;
63467
63468 /* Link Setup Parameters for CAIF-Links. */
63469 struct cfctrl_link_param {
63470@@ -101,8 +101,8 @@ struct cfctrl_request_info {
63471 struct cfctrl {
63472 struct cfsrvl serv;
63473 struct cfctrl_rsp res;
63474- atomic_t req_seq_no;
63475- atomic_t rsp_seq_no;
63476+ atomic_unchecked_t req_seq_no;
63477+ atomic_unchecked_t rsp_seq_no;
63478 struct list_head list;
63479 /* Protects from simultaneous access to first_req list */
63480 spinlock_t info_list_lock;
63481diff --git a/include/net/flow.h b/include/net/flow.h
63482index 6c469db..7743b8e 100644
63483--- a/include/net/flow.h
63484+++ b/include/net/flow.h
63485@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
63486
63487 extern void flow_cache_flush(void);
63488 extern void flow_cache_flush_deferred(void);
63489-extern atomic_t flow_cache_genid;
63490+extern atomic_unchecked_t flow_cache_genid;
63491
63492 #endif
63493diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
63494index b94765e..053f68b 100644
63495--- a/include/net/inetpeer.h
63496+++ b/include/net/inetpeer.h
63497@@ -48,8 +48,8 @@ struct inet_peer {
63498 */
63499 union {
63500 struct {
63501- atomic_t rid; /* Frag reception counter */
63502- atomic_t ip_id_count; /* IP ID for the next packet */
63503+ atomic_unchecked_t rid; /* Frag reception counter */
63504+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
63505 __u32 tcp_ts;
63506 __u32 tcp_ts_stamp;
63507 };
63508@@ -115,11 +115,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
63509 more++;
63510 inet_peer_refcheck(p);
63511 do {
63512- old = atomic_read(&p->ip_id_count);
63513+ old = atomic_read_unchecked(&p->ip_id_count);
63514 new = old + more;
63515 if (!new)
63516 new = 1;
63517- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
63518+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
63519 return new;
63520 }
63521
63522diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
63523index 10422ef..662570f 100644
63524--- a/include/net/ip_fib.h
63525+++ b/include/net/ip_fib.h
63526@@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
63527
63528 #define FIB_RES_SADDR(net, res) \
63529 ((FIB_RES_NH(res).nh_saddr_genid == \
63530- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
63531+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
63532 FIB_RES_NH(res).nh_saddr : \
63533 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
63534 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
63535diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
63536index 72522f0..6f03a2b 100644
63537--- a/include/net/ip_vs.h
63538+++ b/include/net/ip_vs.h
63539@@ -510,7 +510,7 @@ struct ip_vs_conn {
63540 struct ip_vs_conn *control; /* Master control connection */
63541 atomic_t n_control; /* Number of controlled ones */
63542 struct ip_vs_dest *dest; /* real server */
63543- atomic_t in_pkts; /* incoming packet counter */
63544+ atomic_unchecked_t in_pkts; /* incoming packet counter */
63545
63546 /* packet transmitter for different forwarding methods. If it
63547 mangles the packet, it must return NF_DROP or better NF_STOLEN,
63548@@ -648,7 +648,7 @@ struct ip_vs_dest {
63549 __be16 port; /* port number of the server */
63550 union nf_inet_addr addr; /* IP address of the server */
63551 volatile unsigned flags; /* dest status flags */
63552- atomic_t conn_flags; /* flags to copy to conn */
63553+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
63554 atomic_t weight; /* server weight */
63555
63556 atomic_t refcnt; /* reference counter */
63557diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
63558index 69b610a..fe3962c 100644
63559--- a/include/net/irda/ircomm_core.h
63560+++ b/include/net/irda/ircomm_core.h
63561@@ -51,7 +51,7 @@ typedef struct {
63562 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
63563 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
63564 struct ircomm_info *);
63565-} call_t;
63566+} __no_const call_t;
63567
63568 struct ircomm_cb {
63569 irda_queue_t queue;
63570diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
63571index 59ba38bc..d515662 100644
63572--- a/include/net/irda/ircomm_tty.h
63573+++ b/include/net/irda/ircomm_tty.h
63574@@ -35,6 +35,7 @@
63575 #include <linux/termios.h>
63576 #include <linux/timer.h>
63577 #include <linux/tty.h> /* struct tty_struct */
63578+#include <asm/local.h>
63579
63580 #include <net/irda/irias_object.h>
63581 #include <net/irda/ircomm_core.h>
63582@@ -105,8 +106,8 @@ struct ircomm_tty_cb {
63583 unsigned short close_delay;
63584 unsigned short closing_wait; /* time to wait before closing */
63585
63586- int open_count;
63587- int blocked_open; /* # of blocked opens */
63588+ local_t open_count;
63589+ local_t blocked_open; /* # of blocked opens */
63590
63591 /* Protect concurent access to :
63592 * o self->open_count
63593diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
63594index cc7c197..9f2da2a 100644
63595--- a/include/net/iucv/af_iucv.h
63596+++ b/include/net/iucv/af_iucv.h
63597@@ -141,7 +141,7 @@ struct iucv_sock {
63598 struct iucv_sock_list {
63599 struct hlist_head head;
63600 rwlock_t lock;
63601- atomic_t autobind_name;
63602+ atomic_unchecked_t autobind_name;
63603 };
63604
63605 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
63606diff --git a/include/net/neighbour.h b/include/net/neighbour.h
63607index 34c996f..bb3b4d4 100644
63608--- a/include/net/neighbour.h
63609+++ b/include/net/neighbour.h
63610@@ -123,7 +123,7 @@ struct neigh_ops {
63611 void (*error_report)(struct neighbour *, struct sk_buff *);
63612 int (*output)(struct neighbour *, struct sk_buff *);
63613 int (*connected_output)(struct neighbour *, struct sk_buff *);
63614-};
63615+} __do_const;
63616
63617 struct pneigh_entry {
63618 struct pneigh_entry *next;
63619diff --git a/include/net/netlink.h b/include/net/netlink.h
63620index f394fe5..fd073f9 100644
63621--- a/include/net/netlink.h
63622+++ b/include/net/netlink.h
63623@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
63624 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
63625 {
63626 if (mark)
63627- skb_trim(skb, (unsigned char *) mark - skb->data);
63628+ skb_trim(skb, (const unsigned char *) mark - skb->data);
63629 }
63630
63631 /**
63632diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
63633index bbd023a..97c6d0d 100644
63634--- a/include/net/netns/ipv4.h
63635+++ b/include/net/netns/ipv4.h
63636@@ -57,8 +57,8 @@ struct netns_ipv4 {
63637 unsigned int sysctl_ping_group_range[2];
63638 long sysctl_tcp_mem[3];
63639
63640- atomic_t rt_genid;
63641- atomic_t dev_addr_genid;
63642+ atomic_unchecked_t rt_genid;
63643+ atomic_unchecked_t dev_addr_genid;
63644
63645 #ifdef CONFIG_IP_MROUTE
63646 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
63647diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
63648index a2ef814..31a8e3f 100644
63649--- a/include/net/sctp/sctp.h
63650+++ b/include/net/sctp/sctp.h
63651@@ -318,9 +318,9 @@ do { \
63652
63653 #else /* SCTP_DEBUG */
63654
63655-#define SCTP_DEBUG_PRINTK(whatever...)
63656-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
63657-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
63658+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
63659+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
63660+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
63661 #define SCTP_ENABLE_DEBUG
63662 #define SCTP_DISABLE_DEBUG
63663 #define SCTP_ASSERT(expr, str, func)
63664diff --git a/include/net/sock.h b/include/net/sock.h
63665index 5a0a58a..2e3d4d0 100644
63666--- a/include/net/sock.h
63667+++ b/include/net/sock.h
63668@@ -302,7 +302,7 @@ struct sock {
63669 #ifdef CONFIG_RPS
63670 __u32 sk_rxhash;
63671 #endif
63672- atomic_t sk_drops;
63673+ atomic_unchecked_t sk_drops;
63674 int sk_rcvbuf;
63675
63676 struct sk_filter __rcu *sk_filter;
63677@@ -1691,7 +1691,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
63678 }
63679
63680 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
63681- char __user *from, char *to,
63682+ char __user *from, unsigned char *to,
63683 int copy, int offset)
63684 {
63685 if (skb->ip_summed == CHECKSUM_NONE) {
63686diff --git a/include/net/tcp.h b/include/net/tcp.h
63687index f75a04d..702cf06 100644
63688--- a/include/net/tcp.h
63689+++ b/include/net/tcp.h
63690@@ -1425,7 +1425,7 @@ struct tcp_seq_afinfo {
63691 char *name;
63692 sa_family_t family;
63693 const struct file_operations *seq_fops;
63694- struct seq_operations seq_ops;
63695+ seq_operations_no_const seq_ops;
63696 };
63697
63698 struct tcp_iter_state {
63699diff --git a/include/net/udp.h b/include/net/udp.h
63700index 5d606d9..e879f7b 100644
63701--- a/include/net/udp.h
63702+++ b/include/net/udp.h
63703@@ -244,7 +244,7 @@ struct udp_seq_afinfo {
63704 sa_family_t family;
63705 struct udp_table *udp_table;
63706 const struct file_operations *seq_fops;
63707- struct seq_operations seq_ops;
63708+ seq_operations_no_const seq_ops;
63709 };
63710
63711 struct udp_iter_state {
63712diff --git a/include/net/xfrm.h b/include/net/xfrm.h
63713index 96239e7..c85b032 100644
63714--- a/include/net/xfrm.h
63715+++ b/include/net/xfrm.h
63716@@ -505,7 +505,7 @@ struct xfrm_policy {
63717 struct timer_list timer;
63718
63719 struct flow_cache_object flo;
63720- atomic_t genid;
63721+ atomic_unchecked_t genid;
63722 u32 priority;
63723 u32 index;
63724 struct xfrm_mark mark;
63725diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
63726index 1a046b1..ee0bef0 100644
63727--- a/include/rdma/iw_cm.h
63728+++ b/include/rdma/iw_cm.h
63729@@ -122,7 +122,7 @@ struct iw_cm_verbs {
63730 int backlog);
63731
63732 int (*destroy_listen)(struct iw_cm_id *cm_id);
63733-};
63734+} __no_const;
63735
63736 /**
63737 * iw_create_cm_id - Create an IW CM identifier.
63738diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
63739index 8f9dfba..610ab6c 100644
63740--- a/include/scsi/libfc.h
63741+++ b/include/scsi/libfc.h
63742@@ -756,6 +756,7 @@ struct libfc_function_template {
63743 */
63744 void (*disc_stop_final) (struct fc_lport *);
63745 };
63746+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
63747
63748 /**
63749 * struct fc_disc - Discovery context
63750@@ -861,7 +862,7 @@ struct fc_lport {
63751 struct fc_vport *vport;
63752
63753 /* Operational Information */
63754- struct libfc_function_template tt;
63755+ libfc_function_template_no_const tt;
63756 u8 link_up;
63757 u8 qfull;
63758 enum fc_lport_state state;
63759diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
63760index 6efb2e1..cdad57f 100644
63761--- a/include/scsi/scsi_device.h
63762+++ b/include/scsi/scsi_device.h
63763@@ -162,9 +162,9 @@ struct scsi_device {
63764 unsigned int max_device_blocked; /* what device_blocked counts down from */
63765 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
63766
63767- atomic_t iorequest_cnt;
63768- atomic_t iodone_cnt;
63769- atomic_t ioerr_cnt;
63770+ atomic_unchecked_t iorequest_cnt;
63771+ atomic_unchecked_t iodone_cnt;
63772+ atomic_unchecked_t ioerr_cnt;
63773
63774 struct device sdev_gendev,
63775 sdev_dev;
63776diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
63777index 719faf1..d1154d4 100644
63778--- a/include/scsi/scsi_transport_fc.h
63779+++ b/include/scsi/scsi_transport_fc.h
63780@@ -739,7 +739,7 @@ struct fc_function_template {
63781 unsigned long show_host_system_hostname:1;
63782
63783 unsigned long disable_target_scan:1;
63784-};
63785+} __do_const;
63786
63787
63788 /**
63789diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
63790index 030b87c..98a6954 100644
63791--- a/include/sound/ak4xxx-adda.h
63792+++ b/include/sound/ak4xxx-adda.h
63793@@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
63794 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
63795 unsigned char val);
63796 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
63797-};
63798+} __no_const;
63799
63800 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
63801
63802diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
63803index 8c05e47..2b5df97 100644
63804--- a/include/sound/hwdep.h
63805+++ b/include/sound/hwdep.h
63806@@ -49,7 +49,7 @@ struct snd_hwdep_ops {
63807 struct snd_hwdep_dsp_status *status);
63808 int (*dsp_load)(struct snd_hwdep *hw,
63809 struct snd_hwdep_dsp_image *image);
63810-};
63811+} __no_const;
63812
63813 struct snd_hwdep {
63814 struct snd_card *card;
63815diff --git a/include/sound/info.h b/include/sound/info.h
63816index 9ca1a49..aba1728 100644
63817--- a/include/sound/info.h
63818+++ b/include/sound/info.h
63819@@ -44,7 +44,7 @@ struct snd_info_entry_text {
63820 struct snd_info_buffer *buffer);
63821 void (*write)(struct snd_info_entry *entry,
63822 struct snd_info_buffer *buffer);
63823-};
63824+} __no_const;
63825
63826 struct snd_info_entry_ops {
63827 int (*open)(struct snd_info_entry *entry,
63828diff --git a/include/sound/pcm.h b/include/sound/pcm.h
63829index 0d11128..814178e 100644
63830--- a/include/sound/pcm.h
63831+++ b/include/sound/pcm.h
63832@@ -81,6 +81,7 @@ struct snd_pcm_ops {
63833 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
63834 int (*ack)(struct snd_pcm_substream *substream);
63835 };
63836+typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
63837
63838 /*
63839 *
63840diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
63841index af1b49e..a5d55a5 100644
63842--- a/include/sound/sb16_csp.h
63843+++ b/include/sound/sb16_csp.h
63844@@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
63845 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
63846 int (*csp_stop) (struct snd_sb_csp * p);
63847 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
63848-};
63849+} __no_const;
63850
63851 /*
63852 * CSP private data
63853diff --git a/include/sound/soc.h b/include/sound/soc.h
63854index 2ebf787..0276839 100644
63855--- a/include/sound/soc.h
63856+++ b/include/sound/soc.h
63857@@ -711,7 +711,7 @@ struct snd_soc_platform_driver {
63858 /* platform IO - used for platform DAPM */
63859 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
63860 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
63861-};
63862+} __do_const;
63863
63864 struct snd_soc_platform {
63865 const char *name;
63866@@ -887,7 +887,7 @@ struct snd_soc_pcm_runtime {
63867 struct snd_soc_dai_link *dai_link;
63868 struct mutex pcm_mutex;
63869 enum snd_soc_pcm_subclass pcm_subclass;
63870- struct snd_pcm_ops ops;
63871+ snd_pcm_ops_no_const ops;
63872
63873 unsigned int complete:1;
63874 unsigned int dev_registered:1;
63875diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
63876index 4119966..1a4671c 100644
63877--- a/include/sound/ymfpci.h
63878+++ b/include/sound/ymfpci.h
63879@@ -358,7 +358,7 @@ struct snd_ymfpci {
63880 spinlock_t reg_lock;
63881 spinlock_t voice_lock;
63882 wait_queue_head_t interrupt_sleep;
63883- atomic_t interrupt_sleep_count;
63884+ atomic_unchecked_t interrupt_sleep_count;
63885 struct snd_info_entry *proc_entry;
63886 const struct firmware *dsp_microcode;
63887 const struct firmware *controller_microcode;
63888diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
63889index aaccc5f..092d568 100644
63890--- a/include/target/target_core_base.h
63891+++ b/include/target/target_core_base.h
63892@@ -447,7 +447,7 @@ struct t10_reservation_ops {
63893 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
63894 int (*t10_pr_register)(struct se_cmd *);
63895 int (*t10_pr_clear)(struct se_cmd *);
63896-};
63897+} __no_const;
63898
63899 struct t10_reservation {
63900 /* Reservation effects all target ports */
63901@@ -576,7 +576,7 @@ struct se_cmd {
63902 atomic_t t_se_count;
63903 atomic_t t_task_cdbs_left;
63904 atomic_t t_task_cdbs_ex_left;
63905- atomic_t t_task_cdbs_sent;
63906+ atomic_unchecked_t t_task_cdbs_sent;
63907 unsigned int transport_state;
63908 #define CMD_T_ABORTED (1 << 0)
63909 #define CMD_T_ACTIVE (1 << 1)
63910@@ -802,7 +802,7 @@ struct se_device {
63911 spinlock_t stats_lock;
63912 /* Active commands on this virtual SE device */
63913 atomic_t simple_cmds;
63914- atomic_t dev_ordered_id;
63915+ atomic_unchecked_t dev_ordered_id;
63916 atomic_t execute_tasks;
63917 atomic_t dev_ordered_sync;
63918 atomic_t dev_qf_count;
63919diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
63920new file mode 100644
63921index 0000000..2efe49d
63922--- /dev/null
63923+++ b/include/trace/events/fs.h
63924@@ -0,0 +1,53 @@
63925+#undef TRACE_SYSTEM
63926+#define TRACE_SYSTEM fs
63927+
63928+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
63929+#define _TRACE_FS_H
63930+
63931+#include <linux/fs.h>
63932+#include <linux/tracepoint.h>
63933+
63934+TRACE_EVENT(do_sys_open,
63935+
63936+ TP_PROTO(char *filename, int flags, int mode),
63937+
63938+ TP_ARGS(filename, flags, mode),
63939+
63940+ TP_STRUCT__entry(
63941+ __string( filename, filename )
63942+ __field( int, flags )
63943+ __field( int, mode )
63944+ ),
63945+
63946+ TP_fast_assign(
63947+ __assign_str(filename, filename);
63948+ __entry->flags = flags;
63949+ __entry->mode = mode;
63950+ ),
63951+
63952+ TP_printk("\"%s\" %x %o",
63953+ __get_str(filename), __entry->flags, __entry->mode)
63954+);
63955+
63956+TRACE_EVENT(open_exec,
63957+
63958+ TP_PROTO(const char *filename),
63959+
63960+ TP_ARGS(filename),
63961+
63962+ TP_STRUCT__entry(
63963+ __string( filename, filename )
63964+ ),
63965+
63966+ TP_fast_assign(
63967+ __assign_str(filename, filename);
63968+ ),
63969+
63970+ TP_printk("\"%s\"",
63971+ __get_str(filename))
63972+);
63973+
63974+#endif /* _TRACE_FS_H */
63975+
63976+/* This part must be outside protection */
63977+#include <trace/define_trace.h>
63978diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
63979index 1c09820..7f5ec79 100644
63980--- a/include/trace/events/irq.h
63981+++ b/include/trace/events/irq.h
63982@@ -36,7 +36,7 @@ struct softirq_action;
63983 */
63984 TRACE_EVENT(irq_handler_entry,
63985
63986- TP_PROTO(int irq, struct irqaction *action),
63987+ TP_PROTO(int irq, const struct irqaction *action),
63988
63989 TP_ARGS(irq, action),
63990
63991@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
63992 */
63993 TRACE_EVENT(irq_handler_exit,
63994
63995- TP_PROTO(int irq, struct irqaction *action, int ret),
63996+ TP_PROTO(int irq, const struct irqaction *action, int ret),
63997
63998 TP_ARGS(irq, action, ret),
63999
64000diff --git a/include/video/udlfb.h b/include/video/udlfb.h
64001index f9466fa..f4e2b81 100644
64002--- a/include/video/udlfb.h
64003+++ b/include/video/udlfb.h
64004@@ -53,10 +53,10 @@ struct dlfb_data {
64005 u32 pseudo_palette[256];
64006 int blank_mode; /*one of FB_BLANK_ */
64007 /* blit-only rendering path metrics, exposed through sysfs */
64008- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64009- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
64010- atomic_t bytes_sent; /* to usb, after compression including overhead */
64011- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
64012+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64013+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
64014+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
64015+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
64016 };
64017
64018 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
64019diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
64020index 0993a22..32ba2fe 100644
64021--- a/include/video/uvesafb.h
64022+++ b/include/video/uvesafb.h
64023@@ -177,6 +177,7 @@ struct uvesafb_par {
64024 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
64025 u8 pmi_setpal; /* PMI for palette changes */
64026 u16 *pmi_base; /* protected mode interface location */
64027+ u8 *pmi_code; /* protected mode code location */
64028 void *pmi_start;
64029 void *pmi_pal;
64030 u8 *vbe_state_orig; /*
64031diff --git a/init/Kconfig b/init/Kconfig
64032index 6cfd71d..73cb68d 100644
64033--- a/init/Kconfig
64034+++ b/init/Kconfig
64035@@ -790,6 +790,7 @@ endif # CGROUPS
64036
64037 config CHECKPOINT_RESTORE
64038 bool "Checkpoint/restore support" if EXPERT
64039+ depends on !GRKERNSEC
64040 default n
64041 help
64042 Enables additional kernel features in a sake of checkpoint/restore.
64043@@ -1240,7 +1241,7 @@ config SLUB_DEBUG
64044
64045 config COMPAT_BRK
64046 bool "Disable heap randomization"
64047- default y
64048+ default n
64049 help
64050 Randomizing heap placement makes heap exploits harder, but it
64051 also breaks ancient binaries (including anything libc5 based).
64052diff --git a/init/do_mounts.c b/init/do_mounts.c
64053index 42b0707..c06eef4 100644
64054--- a/init/do_mounts.c
64055+++ b/init/do_mounts.c
64056@@ -326,11 +326,11 @@ static void __init get_fs_names(char *page)
64057 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
64058 {
64059 struct super_block *s;
64060- int err = sys_mount(name, "/root", fs, flags, data);
64061+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
64062 if (err)
64063 return err;
64064
64065- sys_chdir((const char __user __force *)"/root");
64066+ sys_chdir((const char __force_user *)"/root");
64067 s = current->fs->pwd.dentry->d_sb;
64068 ROOT_DEV = s->s_dev;
64069 printk(KERN_INFO
64070@@ -450,18 +450,18 @@ void __init change_floppy(char *fmt, ...)
64071 va_start(args, fmt);
64072 vsprintf(buf, fmt, args);
64073 va_end(args);
64074- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
64075+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
64076 if (fd >= 0) {
64077 sys_ioctl(fd, FDEJECT, 0);
64078 sys_close(fd);
64079 }
64080 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
64081- fd = sys_open("/dev/console", O_RDWR, 0);
64082+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
64083 if (fd >= 0) {
64084 sys_ioctl(fd, TCGETS, (long)&termios);
64085 termios.c_lflag &= ~ICANON;
64086 sys_ioctl(fd, TCSETSF, (long)&termios);
64087- sys_read(fd, &c, 1);
64088+ sys_read(fd, (char __user *)&c, 1);
64089 termios.c_lflag |= ICANON;
64090 sys_ioctl(fd, TCSETSF, (long)&termios);
64091 sys_close(fd);
64092@@ -555,6 +555,6 @@ void __init prepare_namespace(void)
64093 mount_root();
64094 out:
64095 devtmpfs_mount("dev");
64096- sys_mount(".", "/", NULL, MS_MOVE, NULL);
64097- sys_chroot((const char __user __force *)".");
64098+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
64099+ sys_chroot((const char __force_user *)".");
64100 }
64101diff --git a/init/do_mounts.h b/init/do_mounts.h
64102index f5b978a..69dbfe8 100644
64103--- a/init/do_mounts.h
64104+++ b/init/do_mounts.h
64105@@ -15,15 +15,15 @@ extern int root_mountflags;
64106
64107 static inline int create_dev(char *name, dev_t dev)
64108 {
64109- sys_unlink(name);
64110- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
64111+ sys_unlink((char __force_user *)name);
64112+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
64113 }
64114
64115 #if BITS_PER_LONG == 32
64116 static inline u32 bstat(char *name)
64117 {
64118 struct stat64 stat;
64119- if (sys_stat64(name, &stat) != 0)
64120+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
64121 return 0;
64122 if (!S_ISBLK(stat.st_mode))
64123 return 0;
64124@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
64125 static inline u32 bstat(char *name)
64126 {
64127 struct stat stat;
64128- if (sys_newstat(name, &stat) != 0)
64129+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
64130 return 0;
64131 if (!S_ISBLK(stat.st_mode))
64132 return 0;
64133diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
64134index 9047330..de0d1fb 100644
64135--- a/init/do_mounts_initrd.c
64136+++ b/init/do_mounts_initrd.c
64137@@ -43,13 +43,13 @@ static void __init handle_initrd(void)
64138 create_dev("/dev/root.old", Root_RAM0);
64139 /* mount initrd on rootfs' /root */
64140 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
64141- sys_mkdir("/old", 0700);
64142- root_fd = sys_open("/", 0, 0);
64143- old_fd = sys_open("/old", 0, 0);
64144+ sys_mkdir((const char __force_user *)"/old", 0700);
64145+ root_fd = sys_open((const char __force_user *)"/", 0, 0);
64146+ old_fd = sys_open((const char __force_user *)"/old", 0, 0);
64147 /* move initrd over / and chdir/chroot in initrd root */
64148- sys_chdir("/root");
64149- sys_mount(".", "/", NULL, MS_MOVE, NULL);
64150- sys_chroot(".");
64151+ sys_chdir((const char __force_user *)"/root");
64152+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
64153+ sys_chroot((const char __force_user *)".");
64154
64155 /*
64156 * In case that a resume from disk is carried out by linuxrc or one of
64157@@ -66,15 +66,15 @@ static void __init handle_initrd(void)
64158
64159 /* move initrd to rootfs' /old */
64160 sys_fchdir(old_fd);
64161- sys_mount("/", ".", NULL, MS_MOVE, NULL);
64162+ sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
64163 /* switch root and cwd back to / of rootfs */
64164 sys_fchdir(root_fd);
64165- sys_chroot(".");
64166+ sys_chroot((const char __force_user *)".");
64167 sys_close(old_fd);
64168 sys_close(root_fd);
64169
64170 if (new_decode_dev(real_root_dev) == Root_RAM0) {
64171- sys_chdir("/old");
64172+ sys_chdir((const char __force_user *)"/old");
64173 return;
64174 }
64175
64176@@ -82,17 +82,17 @@ static void __init handle_initrd(void)
64177 mount_root();
64178
64179 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
64180- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
64181+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
64182 if (!error)
64183 printk("okay\n");
64184 else {
64185- int fd = sys_open("/dev/root.old", O_RDWR, 0);
64186+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
64187 if (error == -ENOENT)
64188 printk("/initrd does not exist. Ignored.\n");
64189 else
64190 printk("failed\n");
64191 printk(KERN_NOTICE "Unmounting old root\n");
64192- sys_umount("/old", MNT_DETACH);
64193+ sys_umount((char __force_user *)"/old", MNT_DETACH);
64194 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
64195 if (fd < 0) {
64196 error = fd;
64197@@ -115,11 +115,11 @@ int __init initrd_load(void)
64198 * mounted in the normal path.
64199 */
64200 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
64201- sys_unlink("/initrd.image");
64202+ sys_unlink((const char __force_user *)"/initrd.image");
64203 handle_initrd();
64204 return 1;
64205 }
64206 }
64207- sys_unlink("/initrd.image");
64208+ sys_unlink((const char __force_user *)"/initrd.image");
64209 return 0;
64210 }
64211diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
64212index 32c4799..c27ee74 100644
64213--- a/init/do_mounts_md.c
64214+++ b/init/do_mounts_md.c
64215@@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
64216 partitioned ? "_d" : "", minor,
64217 md_setup_args[ent].device_names);
64218
64219- fd = sys_open(name, 0, 0);
64220+ fd = sys_open((char __force_user *)name, 0, 0);
64221 if (fd < 0) {
64222 printk(KERN_ERR "md: open failed - cannot start "
64223 "array %s\n", name);
64224@@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
64225 * array without it
64226 */
64227 sys_close(fd);
64228- fd = sys_open(name, 0, 0);
64229+ fd = sys_open((char __force_user *)name, 0, 0);
64230 sys_ioctl(fd, BLKRRPART, 0);
64231 }
64232 sys_close(fd);
64233@@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
64234
64235 wait_for_device_probe();
64236
64237- fd = sys_open((const char __user __force *) "/dev/md0", 0, 0);
64238+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
64239 if (fd >= 0) {
64240 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
64241 sys_close(fd);
64242diff --git a/init/initramfs.c b/init/initramfs.c
64243index 8216c30..25e8e32 100644
64244--- a/init/initramfs.c
64245+++ b/init/initramfs.c
64246@@ -74,7 +74,7 @@ static void __init free_hash(void)
64247 }
64248 }
64249
64250-static long __init do_utime(char __user *filename, time_t mtime)
64251+static long __init do_utime(__force char __user *filename, time_t mtime)
64252 {
64253 struct timespec t[2];
64254
64255@@ -109,7 +109,7 @@ static void __init dir_utime(void)
64256 struct dir_entry *de, *tmp;
64257 list_for_each_entry_safe(de, tmp, &dir_list, list) {
64258 list_del(&de->list);
64259- do_utime(de->name, de->mtime);
64260+ do_utime((char __force_user *)de->name, de->mtime);
64261 kfree(de->name);
64262 kfree(de);
64263 }
64264@@ -271,7 +271,7 @@ static int __init maybe_link(void)
64265 if (nlink >= 2) {
64266 char *old = find_link(major, minor, ino, mode, collected);
64267 if (old)
64268- return (sys_link(old, collected) < 0) ? -1 : 1;
64269+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
64270 }
64271 return 0;
64272 }
64273@@ -280,11 +280,11 @@ static void __init clean_path(char *path, umode_t mode)
64274 {
64275 struct stat st;
64276
64277- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
64278+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
64279 if (S_ISDIR(st.st_mode))
64280- sys_rmdir(path);
64281+ sys_rmdir((char __force_user *)path);
64282 else
64283- sys_unlink(path);
64284+ sys_unlink((char __force_user *)path);
64285 }
64286 }
64287
64288@@ -305,7 +305,7 @@ static int __init do_name(void)
64289 int openflags = O_WRONLY|O_CREAT;
64290 if (ml != 1)
64291 openflags |= O_TRUNC;
64292- wfd = sys_open(collected, openflags, mode);
64293+ wfd = sys_open((char __force_user *)collected, openflags, mode);
64294
64295 if (wfd >= 0) {
64296 sys_fchown(wfd, uid, gid);
64297@@ -317,17 +317,17 @@ static int __init do_name(void)
64298 }
64299 }
64300 } else if (S_ISDIR(mode)) {
64301- sys_mkdir(collected, mode);
64302- sys_chown(collected, uid, gid);
64303- sys_chmod(collected, mode);
64304+ sys_mkdir((char __force_user *)collected, mode);
64305+ sys_chown((char __force_user *)collected, uid, gid);
64306+ sys_chmod((char __force_user *)collected, mode);
64307 dir_add(collected, mtime);
64308 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
64309 S_ISFIFO(mode) || S_ISSOCK(mode)) {
64310 if (maybe_link() == 0) {
64311- sys_mknod(collected, mode, rdev);
64312- sys_chown(collected, uid, gid);
64313- sys_chmod(collected, mode);
64314- do_utime(collected, mtime);
64315+ sys_mknod((char __force_user *)collected, mode, rdev);
64316+ sys_chown((char __force_user *)collected, uid, gid);
64317+ sys_chmod((char __force_user *)collected, mode);
64318+ do_utime((char __force_user *)collected, mtime);
64319 }
64320 }
64321 return 0;
64322@@ -336,15 +336,15 @@ static int __init do_name(void)
64323 static int __init do_copy(void)
64324 {
64325 if (count >= body_len) {
64326- sys_write(wfd, victim, body_len);
64327+ sys_write(wfd, (char __force_user *)victim, body_len);
64328 sys_close(wfd);
64329- do_utime(vcollected, mtime);
64330+ do_utime((char __force_user *)vcollected, mtime);
64331 kfree(vcollected);
64332 eat(body_len);
64333 state = SkipIt;
64334 return 0;
64335 } else {
64336- sys_write(wfd, victim, count);
64337+ sys_write(wfd, (char __force_user *)victim, count);
64338 body_len -= count;
64339 eat(count);
64340 return 1;
64341@@ -355,9 +355,9 @@ static int __init do_symlink(void)
64342 {
64343 collected[N_ALIGN(name_len) + body_len] = '\0';
64344 clean_path(collected, 0);
64345- sys_symlink(collected + N_ALIGN(name_len), collected);
64346- sys_lchown(collected, uid, gid);
64347- do_utime(collected, mtime);
64348+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
64349+ sys_lchown((char __force_user *)collected, uid, gid);
64350+ do_utime((char __force_user *)collected, mtime);
64351 state = SkipIt;
64352 next_state = Reset;
64353 return 0;
64354diff --git a/init/main.c b/init/main.c
64355index b08c5f7..09f865e 100644
64356--- a/init/main.c
64357+++ b/init/main.c
64358@@ -95,6 +95,8 @@ static inline void mark_rodata_ro(void) { }
64359 extern void tc_init(void);
64360 #endif
64361
64362+extern void grsecurity_init(void);
64363+
64364 /*
64365 * Debug helper: via this flag we know that we are in 'early bootup code'
64366 * where only the boot processor is running with IRQ disabled. This means
64367@@ -148,6 +150,49 @@ static int __init set_reset_devices(char *str)
64368
64369 __setup("reset_devices", set_reset_devices);
64370
64371+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
64372+extern char pax_enter_kernel_user[];
64373+extern char pax_exit_kernel_user[];
64374+extern pgdval_t clone_pgd_mask;
64375+#endif
64376+
64377+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
64378+static int __init setup_pax_nouderef(char *str)
64379+{
64380+#ifdef CONFIG_X86_32
64381+ unsigned int cpu;
64382+ struct desc_struct *gdt;
64383+
64384+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
64385+ gdt = get_cpu_gdt_table(cpu);
64386+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
64387+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
64388+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
64389+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
64390+ }
64391+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
64392+#else
64393+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
64394+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
64395+ clone_pgd_mask = ~(pgdval_t)0UL;
64396+#endif
64397+
64398+ return 0;
64399+}
64400+early_param("pax_nouderef", setup_pax_nouderef);
64401+#endif
64402+
64403+#ifdef CONFIG_PAX_SOFTMODE
64404+int pax_softmode;
64405+
64406+static int __init setup_pax_softmode(char *str)
64407+{
64408+ get_option(&str, &pax_softmode);
64409+ return 1;
64410+}
64411+__setup("pax_softmode=", setup_pax_softmode);
64412+#endif
64413+
64414 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
64415 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
64416 static const char *panic_later, *panic_param;
64417@@ -674,6 +719,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
64418 {
64419 int count = preempt_count();
64420 int ret;
64421+ const char *msg1 = "", *msg2 = "";
64422
64423 if (initcall_debug)
64424 ret = do_one_initcall_debug(fn);
64425@@ -686,15 +732,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
64426 sprintf(msgbuf, "error code %d ", ret);
64427
64428 if (preempt_count() != count) {
64429- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
64430+ msg1 = " preemption imbalance";
64431 preempt_count() = count;
64432 }
64433 if (irqs_disabled()) {
64434- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
64435+ msg2 = " disabled interrupts";
64436 local_irq_enable();
64437 }
64438- if (msgbuf[0]) {
64439- printk("initcall %pF returned with %s\n", fn, msgbuf);
64440+ if (msgbuf[0] || *msg1 || *msg2) {
64441+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
64442 }
64443
64444 return ret;
64445@@ -865,7 +911,7 @@ static int __init kernel_init(void * unused)
64446 do_basic_setup();
64447
64448 /* Open the /dev/console on the rootfs, this should never fail */
64449- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
64450+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
64451 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
64452
64453 (void) sys_dup(0);
64454@@ -878,11 +924,13 @@ static int __init kernel_init(void * unused)
64455 if (!ramdisk_execute_command)
64456 ramdisk_execute_command = "/init";
64457
64458- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
64459+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
64460 ramdisk_execute_command = NULL;
64461 prepare_namespace();
64462 }
64463
64464+ grsecurity_init();
64465+
64466 /*
64467 * Ok, we have completed the initial bootup, and
64468 * we're essentially up and running. Get rid of the
64469diff --git a/ipc/mqueue.c b/ipc/mqueue.c
64470index 28bd64d..c66b72a 100644
64471--- a/ipc/mqueue.c
64472+++ b/ipc/mqueue.c
64473@@ -156,6 +156,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
64474 mq_bytes = (mq_msg_tblsz +
64475 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
64476
64477+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
64478 spin_lock(&mq_lock);
64479 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
64480 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
64481diff --git a/ipc/msg.c b/ipc/msg.c
64482index 7385de2..a8180e08 100644
64483--- a/ipc/msg.c
64484+++ b/ipc/msg.c
64485@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
64486 return security_msg_queue_associate(msq, msgflg);
64487 }
64488
64489+static struct ipc_ops msg_ops = {
64490+ .getnew = newque,
64491+ .associate = msg_security,
64492+ .more_checks = NULL
64493+};
64494+
64495 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
64496 {
64497 struct ipc_namespace *ns;
64498- struct ipc_ops msg_ops;
64499 struct ipc_params msg_params;
64500
64501 ns = current->nsproxy->ipc_ns;
64502
64503- msg_ops.getnew = newque;
64504- msg_ops.associate = msg_security;
64505- msg_ops.more_checks = NULL;
64506-
64507 msg_params.key = key;
64508 msg_params.flg = msgflg;
64509
64510diff --git a/ipc/sem.c b/ipc/sem.c
64511index 5215a81..cfc0cac 100644
64512--- a/ipc/sem.c
64513+++ b/ipc/sem.c
64514@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
64515 return 0;
64516 }
64517
64518+static struct ipc_ops sem_ops = {
64519+ .getnew = newary,
64520+ .associate = sem_security,
64521+ .more_checks = sem_more_checks
64522+};
64523+
64524 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
64525 {
64526 struct ipc_namespace *ns;
64527- struct ipc_ops sem_ops;
64528 struct ipc_params sem_params;
64529
64530 ns = current->nsproxy->ipc_ns;
64531@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
64532 if (nsems < 0 || nsems > ns->sc_semmsl)
64533 return -EINVAL;
64534
64535- sem_ops.getnew = newary;
64536- sem_ops.associate = sem_security;
64537- sem_ops.more_checks = sem_more_checks;
64538-
64539 sem_params.key = key;
64540 sem_params.flg = semflg;
64541 sem_params.u.nsems = nsems;
64542diff --git a/ipc/shm.c b/ipc/shm.c
64543index 406c5b2..bc66d67 100644
64544--- a/ipc/shm.c
64545+++ b/ipc/shm.c
64546@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
64547 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
64548 #endif
64549
64550+#ifdef CONFIG_GRKERNSEC
64551+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64552+ const time_t shm_createtime, const uid_t cuid,
64553+ const int shmid);
64554+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64555+ const time_t shm_createtime);
64556+#endif
64557+
64558 void shm_init_ns(struct ipc_namespace *ns)
64559 {
64560 ns->shm_ctlmax = SHMMAX;
64561@@ -508,6 +516,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
64562 shp->shm_lprid = 0;
64563 shp->shm_atim = shp->shm_dtim = 0;
64564 shp->shm_ctim = get_seconds();
64565+#ifdef CONFIG_GRKERNSEC
64566+ {
64567+ struct timespec timeval;
64568+ do_posix_clock_monotonic_gettime(&timeval);
64569+
64570+ shp->shm_createtime = timeval.tv_sec;
64571+ }
64572+#endif
64573 shp->shm_segsz = size;
64574 shp->shm_nattch = 0;
64575 shp->shm_file = file;
64576@@ -559,18 +575,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
64577 return 0;
64578 }
64579
64580+static struct ipc_ops shm_ops = {
64581+ .getnew = newseg,
64582+ .associate = shm_security,
64583+ .more_checks = shm_more_checks
64584+};
64585+
64586 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
64587 {
64588 struct ipc_namespace *ns;
64589- struct ipc_ops shm_ops;
64590 struct ipc_params shm_params;
64591
64592 ns = current->nsproxy->ipc_ns;
64593
64594- shm_ops.getnew = newseg;
64595- shm_ops.associate = shm_security;
64596- shm_ops.more_checks = shm_more_checks;
64597-
64598 shm_params.key = key;
64599 shm_params.flg = shmflg;
64600 shm_params.u.size = size;
64601@@ -988,6 +1005,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
64602 f_mode = FMODE_READ | FMODE_WRITE;
64603 }
64604 if (shmflg & SHM_EXEC) {
64605+
64606+#ifdef CONFIG_PAX_MPROTECT
64607+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
64608+ goto out;
64609+#endif
64610+
64611 prot |= PROT_EXEC;
64612 acc_mode |= S_IXUGO;
64613 }
64614@@ -1011,9 +1034,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
64615 if (err)
64616 goto out_unlock;
64617
64618+#ifdef CONFIG_GRKERNSEC
64619+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
64620+ shp->shm_perm.cuid, shmid) ||
64621+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
64622+ err = -EACCES;
64623+ goto out_unlock;
64624+ }
64625+#endif
64626+
64627 path = shp->shm_file->f_path;
64628 path_get(&path);
64629 shp->shm_nattch++;
64630+#ifdef CONFIG_GRKERNSEC
64631+ shp->shm_lapid = current->pid;
64632+#endif
64633 size = i_size_read(path.dentry->d_inode);
64634 shm_unlock(shp);
64635
64636diff --git a/kernel/acct.c b/kernel/acct.c
64637index 02e6167..54824f7 100644
64638--- a/kernel/acct.c
64639+++ b/kernel/acct.c
64640@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
64641 */
64642 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
64643 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
64644- file->f_op->write(file, (char *)&ac,
64645+ file->f_op->write(file, (char __force_user *)&ac,
64646 sizeof(acct_t), &file->f_pos);
64647 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
64648 set_fs(fs);
64649diff --git a/kernel/audit.c b/kernel/audit.c
64650index 1c7f2c6..9ba5359 100644
64651--- a/kernel/audit.c
64652+++ b/kernel/audit.c
64653@@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
64654 3) suppressed due to audit_rate_limit
64655 4) suppressed due to audit_backlog_limit
64656 */
64657-static atomic_t audit_lost = ATOMIC_INIT(0);
64658+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
64659
64660 /* The netlink socket. */
64661 static struct sock *audit_sock;
64662@@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
64663 unsigned long now;
64664 int print;
64665
64666- atomic_inc(&audit_lost);
64667+ atomic_inc_unchecked(&audit_lost);
64668
64669 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
64670
64671@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
64672 printk(KERN_WARNING
64673 "audit: audit_lost=%d audit_rate_limit=%d "
64674 "audit_backlog_limit=%d\n",
64675- atomic_read(&audit_lost),
64676+ atomic_read_unchecked(&audit_lost),
64677 audit_rate_limit,
64678 audit_backlog_limit);
64679 audit_panic(message);
64680@@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
64681 status_set.pid = audit_pid;
64682 status_set.rate_limit = audit_rate_limit;
64683 status_set.backlog_limit = audit_backlog_limit;
64684- status_set.lost = atomic_read(&audit_lost);
64685+ status_set.lost = atomic_read_unchecked(&audit_lost);
64686 status_set.backlog = skb_queue_len(&audit_skb_queue);
64687 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
64688 &status_set, sizeof(status_set));
64689diff --git a/kernel/auditsc.c b/kernel/auditsc.c
64690index af1de0f..06dfe57 100644
64691--- a/kernel/auditsc.c
64692+++ b/kernel/auditsc.c
64693@@ -2288,7 +2288,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
64694 }
64695
64696 /* global counter which is incremented every time something logs in */
64697-static atomic_t session_id = ATOMIC_INIT(0);
64698+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
64699
64700 /**
64701 * audit_set_loginuid - set current task's audit_context loginuid
64702@@ -2312,7 +2312,7 @@ int audit_set_loginuid(uid_t loginuid)
64703 return -EPERM;
64704 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
64705
64706- sessionid = atomic_inc_return(&session_id);
64707+ sessionid = atomic_inc_return_unchecked(&session_id);
64708 if (context && context->in_syscall) {
64709 struct audit_buffer *ab;
64710
64711diff --git a/kernel/capability.c b/kernel/capability.c
64712index 3f1adb6..c564db0 100644
64713--- a/kernel/capability.c
64714+++ b/kernel/capability.c
64715@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
64716 * before modification is attempted and the application
64717 * fails.
64718 */
64719+ if (tocopy > ARRAY_SIZE(kdata))
64720+ return -EFAULT;
64721+
64722 if (copy_to_user(dataptr, kdata, tocopy
64723 * sizeof(struct __user_cap_data_struct))) {
64724 return -EFAULT;
64725@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
64726 int ret;
64727
64728 rcu_read_lock();
64729- ret = security_capable(__task_cred(t), ns, cap);
64730+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
64731+ gr_task_is_capable(t, __task_cred(t), cap);
64732 rcu_read_unlock();
64733
64734- return (ret == 0);
64735+ return ret;
64736 }
64737
64738 /**
64739@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
64740 int ret;
64741
64742 rcu_read_lock();
64743- ret = security_capable_noaudit(__task_cred(t), ns, cap);
64744+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
64745 rcu_read_unlock();
64746
64747- return (ret == 0);
64748+ return ret;
64749 }
64750
64751 /**
64752@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
64753 BUG();
64754 }
64755
64756- if (security_capable(current_cred(), ns, cap) == 0) {
64757+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
64758 current->flags |= PF_SUPERPRIV;
64759 return true;
64760 }
64761@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
64762 }
64763 EXPORT_SYMBOL(ns_capable);
64764
64765+bool ns_capable_nolog(struct user_namespace *ns, int cap)
64766+{
64767+ if (unlikely(!cap_valid(cap))) {
64768+ printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
64769+ BUG();
64770+ }
64771+
64772+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
64773+ current->flags |= PF_SUPERPRIV;
64774+ return true;
64775+ }
64776+ return false;
64777+}
64778+EXPORT_SYMBOL(ns_capable_nolog);
64779+
64780 /**
64781 * capable - Determine if the current task has a superior capability in effect
64782 * @cap: The capability to be tested for
64783@@ -408,6 +427,12 @@ bool capable(int cap)
64784 }
64785 EXPORT_SYMBOL(capable);
64786
64787+bool capable_nolog(int cap)
64788+{
64789+ return ns_capable_nolog(&init_user_ns, cap);
64790+}
64791+EXPORT_SYMBOL(capable_nolog);
64792+
64793 /**
64794 * nsown_capable - Check superior capability to one's own user_ns
64795 * @cap: The capability in question
64796diff --git a/kernel/compat.c b/kernel/compat.c
64797index d2c67aa..a629b2e 100644
64798--- a/kernel/compat.c
64799+++ b/kernel/compat.c
64800@@ -13,6 +13,7 @@
64801
64802 #include <linux/linkage.h>
64803 #include <linux/compat.h>
64804+#include <linux/module.h>
64805 #include <linux/errno.h>
64806 #include <linux/time.h>
64807 #include <linux/signal.h>
64808@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
64809 mm_segment_t oldfs;
64810 long ret;
64811
64812- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
64813+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
64814 oldfs = get_fs();
64815 set_fs(KERNEL_DS);
64816 ret = hrtimer_nanosleep_restart(restart);
64817@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
64818 oldfs = get_fs();
64819 set_fs(KERNEL_DS);
64820 ret = hrtimer_nanosleep(&tu,
64821- rmtp ? (struct timespec __user *)&rmt : NULL,
64822+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
64823 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
64824 set_fs(oldfs);
64825
64826@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
64827 mm_segment_t old_fs = get_fs();
64828
64829 set_fs(KERNEL_DS);
64830- ret = sys_sigpending((old_sigset_t __user *) &s);
64831+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
64832 set_fs(old_fs);
64833 if (ret == 0)
64834 ret = put_user(s, set);
64835@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
64836 mm_segment_t old_fs = get_fs();
64837
64838 set_fs(KERNEL_DS);
64839- ret = sys_old_getrlimit(resource, &r);
64840+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
64841 set_fs(old_fs);
64842
64843 if (!ret) {
64844@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
64845 mm_segment_t old_fs = get_fs();
64846
64847 set_fs(KERNEL_DS);
64848- ret = sys_getrusage(who, (struct rusage __user *) &r);
64849+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
64850 set_fs(old_fs);
64851
64852 if (ret)
64853@@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
64854 set_fs (KERNEL_DS);
64855 ret = sys_wait4(pid,
64856 (stat_addr ?
64857- (unsigned int __user *) &status : NULL),
64858- options, (struct rusage __user *) &r);
64859+ (unsigned int __force_user *) &status : NULL),
64860+ options, (struct rusage __force_user *) &r);
64861 set_fs (old_fs);
64862
64863 if (ret > 0) {
64864@@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
64865 memset(&info, 0, sizeof(info));
64866
64867 set_fs(KERNEL_DS);
64868- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
64869- uru ? (struct rusage __user *)&ru : NULL);
64870+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
64871+ uru ? (struct rusage __force_user *)&ru : NULL);
64872 set_fs(old_fs);
64873
64874 if ((ret < 0) || (info.si_signo == 0))
64875@@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
64876 oldfs = get_fs();
64877 set_fs(KERNEL_DS);
64878 err = sys_timer_settime(timer_id, flags,
64879- (struct itimerspec __user *) &newts,
64880- (struct itimerspec __user *) &oldts);
64881+ (struct itimerspec __force_user *) &newts,
64882+ (struct itimerspec __force_user *) &oldts);
64883 set_fs(oldfs);
64884 if (!err && old && put_compat_itimerspec(old, &oldts))
64885 return -EFAULT;
64886@@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
64887 oldfs = get_fs();
64888 set_fs(KERNEL_DS);
64889 err = sys_timer_gettime(timer_id,
64890- (struct itimerspec __user *) &ts);
64891+ (struct itimerspec __force_user *) &ts);
64892 set_fs(oldfs);
64893 if (!err && put_compat_itimerspec(setting, &ts))
64894 return -EFAULT;
64895@@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
64896 oldfs = get_fs();
64897 set_fs(KERNEL_DS);
64898 err = sys_clock_settime(which_clock,
64899- (struct timespec __user *) &ts);
64900+ (struct timespec __force_user *) &ts);
64901 set_fs(oldfs);
64902 return err;
64903 }
64904@@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
64905 oldfs = get_fs();
64906 set_fs(KERNEL_DS);
64907 err = sys_clock_gettime(which_clock,
64908- (struct timespec __user *) &ts);
64909+ (struct timespec __force_user *) &ts);
64910 set_fs(oldfs);
64911 if (!err && put_compat_timespec(&ts, tp))
64912 return -EFAULT;
64913@@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
64914
64915 oldfs = get_fs();
64916 set_fs(KERNEL_DS);
64917- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
64918+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
64919 set_fs(oldfs);
64920
64921 err = compat_put_timex(utp, &txc);
64922@@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
64923 oldfs = get_fs();
64924 set_fs(KERNEL_DS);
64925 err = sys_clock_getres(which_clock,
64926- (struct timespec __user *) &ts);
64927+ (struct timespec __force_user *) &ts);
64928 set_fs(oldfs);
64929 if (!err && tp && put_compat_timespec(&ts, tp))
64930 return -EFAULT;
64931@@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
64932 long err;
64933 mm_segment_t oldfs;
64934 struct timespec tu;
64935- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
64936+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
64937
64938- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
64939+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
64940 oldfs = get_fs();
64941 set_fs(KERNEL_DS);
64942 err = clock_nanosleep_restart(restart);
64943@@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
64944 oldfs = get_fs();
64945 set_fs(KERNEL_DS);
64946 err = sys_clock_nanosleep(which_clock, flags,
64947- (struct timespec __user *) &in,
64948- (struct timespec __user *) &out);
64949+ (struct timespec __force_user *) &in,
64950+ (struct timespec __force_user *) &out);
64951 set_fs(oldfs);
64952
64953 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
64954diff --git a/kernel/configs.c b/kernel/configs.c
64955index 42e8fa0..9e7406b 100644
64956--- a/kernel/configs.c
64957+++ b/kernel/configs.c
64958@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
64959 struct proc_dir_entry *entry;
64960
64961 /* create the current config file */
64962+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
64963+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
64964+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
64965+ &ikconfig_file_ops);
64966+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64967+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
64968+ &ikconfig_file_ops);
64969+#endif
64970+#else
64971 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
64972 &ikconfig_file_ops);
64973+#endif
64974+
64975 if (!entry)
64976 return -ENOMEM;
64977
64978diff --git a/kernel/cred.c b/kernel/cred.c
64979index e70683d..27761b6 100644
64980--- a/kernel/cred.c
64981+++ b/kernel/cred.c
64982@@ -205,6 +205,15 @@ void exit_creds(struct task_struct *tsk)
64983 validate_creds(cred);
64984 put_cred(cred);
64985 }
64986+
64987+#ifdef CONFIG_GRKERNSEC_SETXID
64988+ cred = (struct cred *) tsk->delayed_cred;
64989+ if (cred) {
64990+ tsk->delayed_cred = NULL;
64991+ validate_creds(cred);
64992+ put_cred(cred);
64993+ }
64994+#endif
64995 }
64996
64997 /**
64998@@ -473,7 +482,7 @@ error_put:
64999 * Always returns 0 thus allowing this function to be tail-called at the end
65000 * of, say, sys_setgid().
65001 */
65002-int commit_creds(struct cred *new)
65003+static int __commit_creds(struct cred *new)
65004 {
65005 struct task_struct *task = current;
65006 const struct cred *old = task->real_cred;
65007@@ -492,6 +501,8 @@ int commit_creds(struct cred *new)
65008
65009 get_cred(new); /* we will require a ref for the subj creds too */
65010
65011+ gr_set_role_label(task, new->uid, new->gid);
65012+
65013 /* dumpability changes */
65014 if (old->euid != new->euid ||
65015 old->egid != new->egid ||
65016@@ -541,6 +552,101 @@ int commit_creds(struct cred *new)
65017 put_cred(old);
65018 return 0;
65019 }
65020+#ifdef CONFIG_GRKERNSEC_SETXID
65021+extern int set_user(struct cred *new);
65022+
65023+void gr_delayed_cred_worker(void)
65024+{
65025+ const struct cred *new = current->delayed_cred;
65026+ struct cred *ncred;
65027+
65028+ current->delayed_cred = NULL;
65029+
65030+ if (current_uid() && new != NULL) {
65031+ // from doing get_cred on it when queueing this
65032+ put_cred(new);
65033+ return;
65034+ } else if (new == NULL)
65035+ return;
65036+
65037+ ncred = prepare_creds();
65038+ if (!ncred)
65039+ goto die;
65040+ // uids
65041+ ncred->uid = new->uid;
65042+ ncred->euid = new->euid;
65043+ ncred->suid = new->suid;
65044+ ncred->fsuid = new->fsuid;
65045+ // gids
65046+ ncred->gid = new->gid;
65047+ ncred->egid = new->egid;
65048+ ncred->sgid = new->sgid;
65049+ ncred->fsgid = new->fsgid;
65050+ // groups
65051+ if (set_groups(ncred, new->group_info) < 0) {
65052+ abort_creds(ncred);
65053+ goto die;
65054+ }
65055+ // caps
65056+ ncred->securebits = new->securebits;
65057+ ncred->cap_inheritable = new->cap_inheritable;
65058+ ncred->cap_permitted = new->cap_permitted;
65059+ ncred->cap_effective = new->cap_effective;
65060+ ncred->cap_bset = new->cap_bset;
65061+
65062+ if (set_user(ncred)) {
65063+ abort_creds(ncred);
65064+ goto die;
65065+ }
65066+
65067+ // from doing get_cred on it when queueing this
65068+ put_cred(new);
65069+
65070+ __commit_creds(ncred);
65071+ return;
65072+die:
65073+ // from doing get_cred on it when queueing this
65074+ put_cred(new);
65075+ do_group_exit(SIGKILL);
65076+}
65077+#endif
65078+
65079+int commit_creds(struct cred *new)
65080+{
65081+#ifdef CONFIG_GRKERNSEC_SETXID
65082+ int ret;
65083+ int schedule_it = 0;
65084+ struct task_struct *t;
65085+
65086+ /* we won't get called with tasklist_lock held for writing
65087+ and interrupts disabled as the cred struct in that case is
65088+ init_cred
65089+ */
65090+ if (grsec_enable_setxid && !current_is_single_threaded() &&
65091+ !current_uid() && new->uid) {
65092+ schedule_it = 1;
65093+ }
65094+ ret = __commit_creds(new);
65095+ if (schedule_it) {
65096+ rcu_read_lock();
65097+ read_lock(&tasklist_lock);
65098+ for (t = next_thread(current); t != current;
65099+ t = next_thread(t)) {
65100+ if (t->delayed_cred == NULL) {
65101+ t->delayed_cred = get_cred(new);
65102+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
65103+ set_tsk_need_resched(t);
65104+ }
65105+ }
65106+ read_unlock(&tasklist_lock);
65107+ rcu_read_unlock();
65108+ }
65109+ return ret;
65110+#else
65111+ return __commit_creds(new);
65112+#endif
65113+}
65114+
65115 EXPORT_SYMBOL(commit_creds);
65116
65117 /**
65118diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
65119index 0557f24..1a00d9a 100644
65120--- a/kernel/debug/debug_core.c
65121+++ b/kernel/debug/debug_core.c
65122@@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
65123 */
65124 static atomic_t masters_in_kgdb;
65125 static atomic_t slaves_in_kgdb;
65126-static atomic_t kgdb_break_tasklet_var;
65127+static atomic_unchecked_t kgdb_break_tasklet_var;
65128 atomic_t kgdb_setting_breakpoint;
65129
65130 struct task_struct *kgdb_usethread;
65131@@ -132,7 +132,7 @@ int kgdb_single_step;
65132 static pid_t kgdb_sstep_pid;
65133
65134 /* to keep track of the CPU which is doing the single stepping*/
65135-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
65136+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
65137
65138 /*
65139 * If you are debugging a problem where roundup (the collection of
65140@@ -540,7 +540,7 @@ return_normal:
65141 * kernel will only try for the value of sstep_tries before
65142 * giving up and continuing on.
65143 */
65144- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
65145+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
65146 (kgdb_info[cpu].task &&
65147 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
65148 atomic_set(&kgdb_active, -1);
65149@@ -634,8 +634,8 @@ cpu_master_loop:
65150 }
65151
65152 kgdb_restore:
65153- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
65154- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
65155+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
65156+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
65157 if (kgdb_info[sstep_cpu].task)
65158 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
65159 else
65160@@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
65161 static void kgdb_tasklet_bpt(unsigned long ing)
65162 {
65163 kgdb_breakpoint();
65164- atomic_set(&kgdb_break_tasklet_var, 0);
65165+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
65166 }
65167
65168 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
65169
65170 void kgdb_schedule_breakpoint(void)
65171 {
65172- if (atomic_read(&kgdb_break_tasklet_var) ||
65173+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
65174 atomic_read(&kgdb_active) != -1 ||
65175 atomic_read(&kgdb_setting_breakpoint))
65176 return;
65177- atomic_inc(&kgdb_break_tasklet_var);
65178+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
65179 tasklet_schedule(&kgdb_tasklet_breakpoint);
65180 }
65181 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
65182diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
65183index 67b847d..93834dd 100644
65184--- a/kernel/debug/kdb/kdb_main.c
65185+++ b/kernel/debug/kdb/kdb_main.c
65186@@ -1983,7 +1983,7 @@ static int kdb_lsmod(int argc, const char **argv)
65187 list_for_each_entry(mod, kdb_modules, list) {
65188
65189 kdb_printf("%-20s%8u 0x%p ", mod->name,
65190- mod->core_size, (void *)mod);
65191+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
65192 #ifdef CONFIG_MODULE_UNLOAD
65193 kdb_printf("%4ld ", module_refcount(mod));
65194 #endif
65195@@ -1993,7 +1993,7 @@ static int kdb_lsmod(int argc, const char **argv)
65196 kdb_printf(" (Loading)");
65197 else
65198 kdb_printf(" (Live)");
65199- kdb_printf(" 0x%p", mod->module_core);
65200+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
65201
65202 #ifdef CONFIG_MODULE_UNLOAD
65203 {
65204diff --git a/kernel/events/core.c b/kernel/events/core.c
65205index fd126f8..70b755b 100644
65206--- a/kernel/events/core.c
65207+++ b/kernel/events/core.c
65208@@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
65209 return 0;
65210 }
65211
65212-static atomic64_t perf_event_id;
65213+static atomic64_unchecked_t perf_event_id;
65214
65215 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
65216 enum event_type_t event_type);
65217@@ -2659,7 +2659,7 @@ static void __perf_event_read(void *info)
65218
65219 static inline u64 perf_event_count(struct perf_event *event)
65220 {
65221- return local64_read(&event->count) + atomic64_read(&event->child_count);
65222+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
65223 }
65224
65225 static u64 perf_event_read(struct perf_event *event)
65226@@ -2983,9 +2983,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
65227 mutex_lock(&event->child_mutex);
65228 total += perf_event_read(event);
65229 *enabled += event->total_time_enabled +
65230- atomic64_read(&event->child_total_time_enabled);
65231+ atomic64_read_unchecked(&event->child_total_time_enabled);
65232 *running += event->total_time_running +
65233- atomic64_read(&event->child_total_time_running);
65234+ atomic64_read_unchecked(&event->child_total_time_running);
65235
65236 list_for_each_entry(child, &event->child_list, child_list) {
65237 total += perf_event_read(child);
65238@@ -3393,10 +3393,10 @@ void perf_event_update_userpage(struct perf_event *event)
65239 userpg->offset -= local64_read(&event->hw.prev_count);
65240
65241 userpg->time_enabled = enabled +
65242- atomic64_read(&event->child_total_time_enabled);
65243+ atomic64_read_unchecked(&event->child_total_time_enabled);
65244
65245 userpg->time_running = running +
65246- atomic64_read(&event->child_total_time_running);
65247+ atomic64_read_unchecked(&event->child_total_time_running);
65248
65249 arch_perf_update_userpage(userpg, now);
65250
65251@@ -3829,11 +3829,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
65252 values[n++] = perf_event_count(event);
65253 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
65254 values[n++] = enabled +
65255- atomic64_read(&event->child_total_time_enabled);
65256+ atomic64_read_unchecked(&event->child_total_time_enabled);
65257 }
65258 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
65259 values[n++] = running +
65260- atomic64_read(&event->child_total_time_running);
65261+ atomic64_read_unchecked(&event->child_total_time_running);
65262 }
65263 if (read_format & PERF_FORMAT_ID)
65264 values[n++] = primary_event_id(event);
65265@@ -4511,12 +4511,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
65266 * need to add enough zero bytes after the string to handle
65267 * the 64bit alignment we do later.
65268 */
65269- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
65270+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
65271 if (!buf) {
65272 name = strncpy(tmp, "//enomem", sizeof(tmp));
65273 goto got_name;
65274 }
65275- name = d_path(&file->f_path, buf, PATH_MAX);
65276+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
65277 if (IS_ERR(name)) {
65278 name = strncpy(tmp, "//toolong", sizeof(tmp));
65279 goto got_name;
65280@@ -5929,7 +5929,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
65281 event->parent = parent_event;
65282
65283 event->ns = get_pid_ns(current->nsproxy->pid_ns);
65284- event->id = atomic64_inc_return(&perf_event_id);
65285+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
65286
65287 event->state = PERF_EVENT_STATE_INACTIVE;
65288
65289@@ -6491,10 +6491,10 @@ static void sync_child_event(struct perf_event *child_event,
65290 /*
65291 * Add back the child's count to the parent's count:
65292 */
65293- atomic64_add(child_val, &parent_event->child_count);
65294- atomic64_add(child_event->total_time_enabled,
65295+ atomic64_add_unchecked(child_val, &parent_event->child_count);
65296+ atomic64_add_unchecked(child_event->total_time_enabled,
65297 &parent_event->child_total_time_enabled);
65298- atomic64_add(child_event->total_time_running,
65299+ atomic64_add_unchecked(child_event->total_time_running,
65300 &parent_event->child_total_time_running);
65301
65302 /*
65303diff --git a/kernel/exit.c b/kernel/exit.c
65304index d8bd3b42..26bd8dc 100644
65305--- a/kernel/exit.c
65306+++ b/kernel/exit.c
65307@@ -59,6 +59,10 @@
65308 #include <asm/pgtable.h>
65309 #include <asm/mmu_context.h>
65310
65311+#ifdef CONFIG_GRKERNSEC
65312+extern rwlock_t grsec_exec_file_lock;
65313+#endif
65314+
65315 static void exit_mm(struct task_struct * tsk);
65316
65317 static void __unhash_process(struct task_struct *p, bool group_dead)
65318@@ -170,6 +174,10 @@ void release_task(struct task_struct * p)
65319 struct task_struct *leader;
65320 int zap_leader;
65321 repeat:
65322+#ifdef CONFIG_NET
65323+ gr_del_task_from_ip_table(p);
65324+#endif
65325+
65326 /* don't need to get the RCU readlock here - the process is dead and
65327 * can't be modifying its own credentials. But shut RCU-lockdep up */
65328 rcu_read_lock();
65329@@ -382,7 +390,7 @@ int allow_signal(int sig)
65330 * know it'll be handled, so that they don't get converted to
65331 * SIGKILL or just silently dropped.
65332 */
65333- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
65334+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
65335 recalc_sigpending();
65336 spin_unlock_irq(&current->sighand->siglock);
65337 return 0;
65338@@ -418,6 +426,17 @@ void daemonize(const char *name, ...)
65339 vsnprintf(current->comm, sizeof(current->comm), name, args);
65340 va_end(args);
65341
65342+#ifdef CONFIG_GRKERNSEC
65343+ write_lock(&grsec_exec_file_lock);
65344+ if (current->exec_file) {
65345+ fput(current->exec_file);
65346+ current->exec_file = NULL;
65347+ }
65348+ write_unlock(&grsec_exec_file_lock);
65349+#endif
65350+
65351+ gr_set_kernel_label(current);
65352+
65353 /*
65354 * If we were started as result of loading a module, close all of the
65355 * user space pages. We don't need them, and if we didn't close them
65356@@ -900,6 +919,8 @@ void do_exit(long code)
65357 struct task_struct *tsk = current;
65358 int group_dead;
65359
65360+ set_fs(USER_DS);
65361+
65362 profile_task_exit(tsk);
65363
65364 WARN_ON(blk_needs_flush_plug(tsk));
65365@@ -916,7 +937,6 @@ void do_exit(long code)
65366 * mm_release()->clear_child_tid() from writing to a user-controlled
65367 * kernel address.
65368 */
65369- set_fs(USER_DS);
65370
65371 ptrace_event(PTRACE_EVENT_EXIT, code);
65372
65373@@ -977,6 +997,9 @@ void do_exit(long code)
65374 tsk->exit_code = code;
65375 taskstats_exit(tsk, group_dead);
65376
65377+ gr_acl_handle_psacct(tsk, code);
65378+ gr_acl_handle_exit();
65379+
65380 exit_mm(tsk);
65381
65382 if (group_dead)
65383@@ -1093,7 +1116,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
65384 * Take down every thread in the group. This is called by fatal signals
65385 * as well as by sys_exit_group (below).
65386 */
65387-void
65388+__noreturn void
65389 do_group_exit(int exit_code)
65390 {
65391 struct signal_struct *sig = current->signal;
65392diff --git a/kernel/fork.c b/kernel/fork.c
65393index 8163333..efb4692 100644
65394--- a/kernel/fork.c
65395+++ b/kernel/fork.c
65396@@ -286,7 +286,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
65397 *stackend = STACK_END_MAGIC; /* for overflow detection */
65398
65399 #ifdef CONFIG_CC_STACKPROTECTOR
65400- tsk->stack_canary = get_random_int();
65401+ tsk->stack_canary = pax_get_random_long();
65402 #endif
65403
65404 /*
65405@@ -310,13 +310,78 @@ out:
65406 }
65407
65408 #ifdef CONFIG_MMU
65409+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
65410+{
65411+ struct vm_area_struct *tmp;
65412+ unsigned long charge;
65413+ struct mempolicy *pol;
65414+ struct file *file;
65415+
65416+ charge = 0;
65417+ if (mpnt->vm_flags & VM_ACCOUNT) {
65418+ unsigned long len;
65419+ len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
65420+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
65421+ goto fail_nomem;
65422+ charge = len;
65423+ }
65424+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
65425+ if (!tmp)
65426+ goto fail_nomem;
65427+ *tmp = *mpnt;
65428+ tmp->vm_mm = mm;
65429+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
65430+ pol = mpol_dup(vma_policy(mpnt));
65431+ if (IS_ERR(pol))
65432+ goto fail_nomem_policy;
65433+ vma_set_policy(tmp, pol);
65434+ if (anon_vma_fork(tmp, mpnt))
65435+ goto fail_nomem_anon_vma_fork;
65436+ tmp->vm_flags &= ~VM_LOCKED;
65437+ tmp->vm_next = tmp->vm_prev = NULL;
65438+ tmp->vm_mirror = NULL;
65439+ file = tmp->vm_file;
65440+ if (file) {
65441+ struct inode *inode = file->f_path.dentry->d_inode;
65442+ struct address_space *mapping = file->f_mapping;
65443+
65444+ get_file(file);
65445+ if (tmp->vm_flags & VM_DENYWRITE)
65446+ atomic_dec(&inode->i_writecount);
65447+ mutex_lock(&mapping->i_mmap_mutex);
65448+ if (tmp->vm_flags & VM_SHARED)
65449+ mapping->i_mmap_writable++;
65450+ flush_dcache_mmap_lock(mapping);
65451+ /* insert tmp into the share list, just after mpnt */
65452+ vma_prio_tree_add(tmp, mpnt);
65453+ flush_dcache_mmap_unlock(mapping);
65454+ mutex_unlock(&mapping->i_mmap_mutex);
65455+ }
65456+
65457+ /*
65458+ * Clear hugetlb-related page reserves for children. This only
65459+ * affects MAP_PRIVATE mappings. Faults generated by the child
65460+ * are not guaranteed to succeed, even if read-only
65461+ */
65462+ if (is_vm_hugetlb_page(tmp))
65463+ reset_vma_resv_huge_pages(tmp);
65464+
65465+ return tmp;
65466+
65467+fail_nomem_anon_vma_fork:
65468+ mpol_put(pol);
65469+fail_nomem_policy:
65470+ kmem_cache_free(vm_area_cachep, tmp);
65471+fail_nomem:
65472+ vm_unacct_memory(charge);
65473+ return NULL;
65474+}
65475+
65476 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
65477 {
65478 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
65479 struct rb_node **rb_link, *rb_parent;
65480 int retval;
65481- unsigned long charge;
65482- struct mempolicy *pol;
65483
65484 down_write(&oldmm->mmap_sem);
65485 flush_cache_dup_mm(oldmm);
65486@@ -328,8 +393,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
65487 mm->locked_vm = 0;
65488 mm->mmap = NULL;
65489 mm->mmap_cache = NULL;
65490- mm->free_area_cache = oldmm->mmap_base;
65491- mm->cached_hole_size = ~0UL;
65492+ mm->free_area_cache = oldmm->free_area_cache;
65493+ mm->cached_hole_size = oldmm->cached_hole_size;
65494 mm->map_count = 0;
65495 cpumask_clear(mm_cpumask(mm));
65496 mm->mm_rb = RB_ROOT;
65497@@ -345,8 +410,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
65498
65499 prev = NULL;
65500 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
65501- struct file *file;
65502-
65503 if (mpnt->vm_flags & VM_DONTCOPY) {
65504 long pages = vma_pages(mpnt);
65505 mm->total_vm -= pages;
65506@@ -354,54 +417,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
65507 -pages);
65508 continue;
65509 }
65510- charge = 0;
65511- if (mpnt->vm_flags & VM_ACCOUNT) {
65512- unsigned long len;
65513- len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
65514- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
65515- goto fail_nomem;
65516- charge = len;
65517+ tmp = dup_vma(mm, oldmm, mpnt);
65518+ if (!tmp) {
65519+ retval = -ENOMEM;
65520+ goto out;
65521 }
65522- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
65523- if (!tmp)
65524- goto fail_nomem;
65525- *tmp = *mpnt;
65526- INIT_LIST_HEAD(&tmp->anon_vma_chain);
65527- pol = mpol_dup(vma_policy(mpnt));
65528- retval = PTR_ERR(pol);
65529- if (IS_ERR(pol))
65530- goto fail_nomem_policy;
65531- vma_set_policy(tmp, pol);
65532- tmp->vm_mm = mm;
65533- if (anon_vma_fork(tmp, mpnt))
65534- goto fail_nomem_anon_vma_fork;
65535- tmp->vm_flags &= ~VM_LOCKED;
65536- tmp->vm_next = tmp->vm_prev = NULL;
65537- file = tmp->vm_file;
65538- if (file) {
65539- struct inode *inode = file->f_path.dentry->d_inode;
65540- struct address_space *mapping = file->f_mapping;
65541-
65542- get_file(file);
65543- if (tmp->vm_flags & VM_DENYWRITE)
65544- atomic_dec(&inode->i_writecount);
65545- mutex_lock(&mapping->i_mmap_mutex);
65546- if (tmp->vm_flags & VM_SHARED)
65547- mapping->i_mmap_writable++;
65548- flush_dcache_mmap_lock(mapping);
65549- /* insert tmp into the share list, just after mpnt */
65550- vma_prio_tree_add(tmp, mpnt);
65551- flush_dcache_mmap_unlock(mapping);
65552- mutex_unlock(&mapping->i_mmap_mutex);
65553- }
65554-
65555- /*
65556- * Clear hugetlb-related page reserves for children. This only
65557- * affects MAP_PRIVATE mappings. Faults generated by the child
65558- * are not guaranteed to succeed, even if read-only
65559- */
65560- if (is_vm_hugetlb_page(tmp))
65561- reset_vma_resv_huge_pages(tmp);
65562
65563 /*
65564 * Link in the new vma and copy the page table entries.
65565@@ -424,6 +444,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
65566 if (retval)
65567 goto out;
65568 }
65569+
65570+#ifdef CONFIG_PAX_SEGMEXEC
65571+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
65572+ struct vm_area_struct *mpnt_m;
65573+
65574+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
65575+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
65576+
65577+ if (!mpnt->vm_mirror)
65578+ continue;
65579+
65580+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
65581+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
65582+ mpnt->vm_mirror = mpnt_m;
65583+ } else {
65584+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
65585+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
65586+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
65587+ mpnt->vm_mirror->vm_mirror = mpnt;
65588+ }
65589+ }
65590+ BUG_ON(mpnt_m);
65591+ }
65592+#endif
65593+
65594 /* a new mm has just been created */
65595 arch_dup_mmap(oldmm, mm);
65596 retval = 0;
65597@@ -432,14 +477,6 @@ out:
65598 flush_tlb_mm(oldmm);
65599 up_write(&oldmm->mmap_sem);
65600 return retval;
65601-fail_nomem_anon_vma_fork:
65602- mpol_put(pol);
65603-fail_nomem_policy:
65604- kmem_cache_free(vm_area_cachep, tmp);
65605-fail_nomem:
65606- retval = -ENOMEM;
65607- vm_unacct_memory(charge);
65608- goto out;
65609 }
65610
65611 static inline int mm_alloc_pgd(struct mm_struct *mm)
65612@@ -676,8 +713,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
65613 return ERR_PTR(err);
65614
65615 mm = get_task_mm(task);
65616- if (mm && mm != current->mm &&
65617- !ptrace_may_access(task, mode)) {
65618+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
65619+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
65620 mmput(mm);
65621 mm = ERR_PTR(-EACCES);
65622 }
65623@@ -899,13 +936,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
65624 spin_unlock(&fs->lock);
65625 return -EAGAIN;
65626 }
65627- fs->users++;
65628+ atomic_inc(&fs->users);
65629 spin_unlock(&fs->lock);
65630 return 0;
65631 }
65632 tsk->fs = copy_fs_struct(fs);
65633 if (!tsk->fs)
65634 return -ENOMEM;
65635+ gr_set_chroot_entries(tsk, &tsk->fs->root);
65636 return 0;
65637 }
65638
65639@@ -1172,6 +1210,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
65640 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
65641 #endif
65642 retval = -EAGAIN;
65643+
65644+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
65645+
65646 if (atomic_read(&p->real_cred->user->processes) >=
65647 task_rlimit(p, RLIMIT_NPROC)) {
65648 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
65649@@ -1328,6 +1369,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
65650 if (clone_flags & CLONE_THREAD)
65651 p->tgid = current->tgid;
65652
65653+ gr_copy_label(p);
65654+
65655 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
65656 /*
65657 * Clear TID on mm_release()?
65658@@ -1502,6 +1545,8 @@ bad_fork_cleanup_count:
65659 bad_fork_free:
65660 free_task(p);
65661 fork_out:
65662+ gr_log_forkfail(retval);
65663+
65664 return ERR_PTR(retval);
65665 }
65666
65667@@ -1602,6 +1647,8 @@ long do_fork(unsigned long clone_flags,
65668 if (clone_flags & CLONE_PARENT_SETTID)
65669 put_user(nr, parent_tidptr);
65670
65671+ gr_handle_brute_check();
65672+
65673 if (clone_flags & CLONE_VFORK) {
65674 p->vfork_done = &vfork;
65675 init_completion(&vfork);
65676@@ -1700,7 +1747,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
65677 return 0;
65678
65679 /* don't need lock here; in the worst case we'll do useless copy */
65680- if (fs->users == 1)
65681+ if (atomic_read(&fs->users) == 1)
65682 return 0;
65683
65684 *new_fsp = copy_fs_struct(fs);
65685@@ -1789,7 +1836,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
65686 fs = current->fs;
65687 spin_lock(&fs->lock);
65688 current->fs = new_fs;
65689- if (--fs->users)
65690+ gr_set_chroot_entries(current, &current->fs->root);
65691+ if (atomic_dec_return(&fs->users))
65692 new_fs = NULL;
65693 else
65694 new_fs = fs;
65695diff --git a/kernel/futex.c b/kernel/futex.c
65696index e2b0fb9..db818ac 100644
65697--- a/kernel/futex.c
65698+++ b/kernel/futex.c
65699@@ -54,6 +54,7 @@
65700 #include <linux/mount.h>
65701 #include <linux/pagemap.h>
65702 #include <linux/syscalls.h>
65703+#include <linux/ptrace.h>
65704 #include <linux/signal.h>
65705 #include <linux/export.h>
65706 #include <linux/magic.h>
65707@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
65708 struct page *page, *page_head;
65709 int err, ro = 0;
65710
65711+#ifdef CONFIG_PAX_SEGMEXEC
65712+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
65713+ return -EFAULT;
65714+#endif
65715+
65716 /*
65717 * The futex address must be "naturally" aligned.
65718 */
65719@@ -2711,6 +2717,7 @@ static int __init futex_init(void)
65720 {
65721 u32 curval;
65722 int i;
65723+ mm_segment_t oldfs;
65724
65725 /*
65726 * This will fail and we want it. Some arch implementations do
65727@@ -2722,8 +2729,11 @@ static int __init futex_init(void)
65728 * implementation, the non-functional ones will return
65729 * -ENOSYS.
65730 */
65731+ oldfs = get_fs();
65732+ set_fs(USER_DS);
65733 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
65734 futex_cmpxchg_enabled = 1;
65735+ set_fs(oldfs);
65736
65737 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
65738 plist_head_init(&futex_queues[i].chain);
65739diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
65740index 9b22d03..6295b62 100644
65741--- a/kernel/gcov/base.c
65742+++ b/kernel/gcov/base.c
65743@@ -102,11 +102,6 @@ void gcov_enable_events(void)
65744 }
65745
65746 #ifdef CONFIG_MODULES
65747-static inline int within(void *addr, void *start, unsigned long size)
65748-{
65749- return ((addr >= start) && (addr < start + size));
65750-}
65751-
65752 /* Update list and generate events when modules are unloaded. */
65753 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
65754 void *data)
65755@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
65756 prev = NULL;
65757 /* Remove entries located in module from linked list. */
65758 for (info = gcov_info_head; info; info = info->next) {
65759- if (within(info, mod->module_core, mod->core_size)) {
65760+ if (within_module_core_rw((unsigned long)info, mod)) {
65761 if (prev)
65762 prev->next = info->next;
65763 else
65764diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
65765index ae34bf5..4e2f3d0 100644
65766--- a/kernel/hrtimer.c
65767+++ b/kernel/hrtimer.c
65768@@ -1393,7 +1393,7 @@ void hrtimer_peek_ahead_timers(void)
65769 local_irq_restore(flags);
65770 }
65771
65772-static void run_hrtimer_softirq(struct softirq_action *h)
65773+static void run_hrtimer_softirq(void)
65774 {
65775 hrtimer_peek_ahead_timers();
65776 }
65777diff --git a/kernel/jump_label.c b/kernel/jump_label.c
65778index 4304919..408c4c0 100644
65779--- a/kernel/jump_label.c
65780+++ b/kernel/jump_label.c
65781@@ -13,6 +13,7 @@
65782 #include <linux/sort.h>
65783 #include <linux/err.h>
65784 #include <linux/static_key.h>
65785+#include <linux/mm.h>
65786
65787 #ifdef HAVE_JUMP_LABEL
65788
65789@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
65790
65791 size = (((unsigned long)stop - (unsigned long)start)
65792 / sizeof(struct jump_entry));
65793+ pax_open_kernel();
65794 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
65795+ pax_close_kernel();
65796 }
65797
65798 static void jump_label_update(struct static_key *key, int enable);
65799@@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
65800 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
65801 struct jump_entry *iter;
65802
65803+ pax_open_kernel();
65804 for (iter = iter_start; iter < iter_stop; iter++) {
65805 if (within_module_init(iter->code, mod))
65806 iter->code = 0;
65807 }
65808+ pax_close_kernel();
65809 }
65810
65811 static int
65812diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
65813index 079f1d3..a407562 100644
65814--- a/kernel/kallsyms.c
65815+++ b/kernel/kallsyms.c
65816@@ -11,6 +11,9 @@
65817 * Changed the compression method from stem compression to "table lookup"
65818 * compression (see scripts/kallsyms.c for a more complete description)
65819 */
65820+#ifdef CONFIG_GRKERNSEC_HIDESYM
65821+#define __INCLUDED_BY_HIDESYM 1
65822+#endif
65823 #include <linux/kallsyms.h>
65824 #include <linux/module.h>
65825 #include <linux/init.h>
65826@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
65827
65828 static inline int is_kernel_inittext(unsigned long addr)
65829 {
65830+ if (system_state != SYSTEM_BOOTING)
65831+ return 0;
65832+
65833 if (addr >= (unsigned long)_sinittext
65834 && addr <= (unsigned long)_einittext)
65835 return 1;
65836 return 0;
65837 }
65838
65839+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
65840+#ifdef CONFIG_MODULES
65841+static inline int is_module_text(unsigned long addr)
65842+{
65843+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
65844+ return 1;
65845+
65846+ addr = ktla_ktva(addr);
65847+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
65848+}
65849+#else
65850+static inline int is_module_text(unsigned long addr)
65851+{
65852+ return 0;
65853+}
65854+#endif
65855+#endif
65856+
65857 static inline int is_kernel_text(unsigned long addr)
65858 {
65859 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
65860@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
65861
65862 static inline int is_kernel(unsigned long addr)
65863 {
65864+
65865+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
65866+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
65867+ return 1;
65868+
65869+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
65870+#else
65871 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
65872+#endif
65873+
65874 return 1;
65875 return in_gate_area_no_mm(addr);
65876 }
65877
65878 static int is_ksym_addr(unsigned long addr)
65879 {
65880+
65881+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
65882+ if (is_module_text(addr))
65883+ return 0;
65884+#endif
65885+
65886 if (all_var)
65887 return is_kernel(addr);
65888
65889@@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
65890
65891 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
65892 {
65893- iter->name[0] = '\0';
65894 iter->nameoff = get_symbol_offset(new_pos);
65895 iter->pos = new_pos;
65896 }
65897@@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, void *p)
65898 {
65899 struct kallsym_iter *iter = m->private;
65900
65901+#ifdef CONFIG_GRKERNSEC_HIDESYM
65902+ if (current_uid())
65903+ return 0;
65904+#endif
65905+
65906 /* Some debugging symbols have no name. Ignore them. */
65907 if (!iter->name[0])
65908 return 0;
65909@@ -540,7 +583,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
65910 struct kallsym_iter *iter;
65911 int ret;
65912
65913- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
65914+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
65915 if (!iter)
65916 return -ENOMEM;
65917 reset_iter(iter, 0);
65918diff --git a/kernel/kexec.c b/kernel/kexec.c
65919index 4e2e472..cd0c7ae 100644
65920--- a/kernel/kexec.c
65921+++ b/kernel/kexec.c
65922@@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
65923 unsigned long flags)
65924 {
65925 struct compat_kexec_segment in;
65926- struct kexec_segment out, __user *ksegments;
65927+ struct kexec_segment out;
65928+ struct kexec_segment __user *ksegments;
65929 unsigned long i, result;
65930
65931 /* Don't allow clients that don't understand the native
65932diff --git a/kernel/kmod.c b/kernel/kmod.c
65933index 05698a7..a4c1e3a 100644
65934--- a/kernel/kmod.c
65935+++ b/kernel/kmod.c
65936@@ -66,7 +66,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
65937 kfree(info->argv);
65938 }
65939
65940-static int call_modprobe(char *module_name, int wait)
65941+static int call_modprobe(char *module_name, char *module_param, int wait)
65942 {
65943 static char *envp[] = {
65944 "HOME=/",
65945@@ -75,7 +75,7 @@ static int call_modprobe(char *module_name, int wait)
65946 NULL
65947 };
65948
65949- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
65950+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
65951 if (!argv)
65952 goto out;
65953
65954@@ -87,7 +87,8 @@ static int call_modprobe(char *module_name, int wait)
65955 argv[1] = "-q";
65956 argv[2] = "--";
65957 argv[3] = module_name; /* check free_modprobe_argv() */
65958- argv[4] = NULL;
65959+ argv[4] = module_param;
65960+ argv[5] = NULL;
65961
65962 return call_usermodehelper_fns(modprobe_path, argv, envp,
65963 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
65964@@ -112,9 +113,8 @@ out:
65965 * If module auto-loading support is disabled then this function
65966 * becomes a no-operation.
65967 */
65968-int __request_module(bool wait, const char *fmt, ...)
65969+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
65970 {
65971- va_list args;
65972 char module_name[MODULE_NAME_LEN];
65973 unsigned int max_modprobes;
65974 int ret;
65975@@ -122,9 +122,7 @@ int __request_module(bool wait, const char *fmt, ...)
65976 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
65977 static int kmod_loop_msg;
65978
65979- va_start(args, fmt);
65980- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
65981- va_end(args);
65982+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
65983 if (ret >= MODULE_NAME_LEN)
65984 return -ENAMETOOLONG;
65985
65986@@ -132,6 +130,20 @@ int __request_module(bool wait, const char *fmt, ...)
65987 if (ret)
65988 return ret;
65989
65990+#ifdef CONFIG_GRKERNSEC_MODHARDEN
65991+ if (!current_uid()) {
65992+ /* hack to workaround consolekit/udisks stupidity */
65993+ read_lock(&tasklist_lock);
65994+ if (!strcmp(current->comm, "mount") &&
65995+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
65996+ read_unlock(&tasklist_lock);
65997+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
65998+ return -EPERM;
65999+ }
66000+ read_unlock(&tasklist_lock);
66001+ }
66002+#endif
66003+
66004 /* If modprobe needs a service that is in a module, we get a recursive
66005 * loop. Limit the number of running kmod threads to max_threads/2 or
66006 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
66007@@ -160,11 +172,52 @@ int __request_module(bool wait, const char *fmt, ...)
66008
66009 trace_module_request(module_name, wait, _RET_IP_);
66010
66011- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
66012+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
66013
66014 atomic_dec(&kmod_concurrent);
66015 return ret;
66016 }
66017+
66018+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
66019+{
66020+ va_list args;
66021+ int ret;
66022+
66023+ va_start(args, fmt);
66024+ ret = ____request_module(wait, module_param, fmt, args);
66025+ va_end(args);
66026+
66027+ return ret;
66028+}
66029+
66030+int __request_module(bool wait, const char *fmt, ...)
66031+{
66032+ va_list args;
66033+ int ret;
66034+
66035+#ifdef CONFIG_GRKERNSEC_MODHARDEN
66036+ if (current_uid()) {
66037+ char module_param[MODULE_NAME_LEN];
66038+
66039+ memset(module_param, 0, sizeof(module_param));
66040+
66041+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
66042+
66043+ va_start(args, fmt);
66044+ ret = ____request_module(wait, module_param, fmt, args);
66045+ va_end(args);
66046+
66047+ return ret;
66048+ }
66049+#endif
66050+
66051+ va_start(args, fmt);
66052+ ret = ____request_module(wait, NULL, fmt, args);
66053+ va_end(args);
66054+
66055+ return ret;
66056+}
66057+
66058 EXPORT_SYMBOL(__request_module);
66059 #endif /* CONFIG_MODULES */
66060
66061@@ -267,7 +320,7 @@ static int wait_for_helper(void *data)
66062 *
66063 * Thus the __user pointer cast is valid here.
66064 */
66065- sys_wait4(pid, (int __user *)&ret, 0, NULL);
66066+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
66067
66068 /*
66069 * If ret is 0, either ____call_usermodehelper failed and the
66070diff --git a/kernel/kprobes.c b/kernel/kprobes.c
66071index c62b854..cb67968 100644
66072--- a/kernel/kprobes.c
66073+++ b/kernel/kprobes.c
66074@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
66075 * kernel image and loaded module images reside. This is required
66076 * so x86_64 can correctly handle the %rip-relative fixups.
66077 */
66078- kip->insns = module_alloc(PAGE_SIZE);
66079+ kip->insns = module_alloc_exec(PAGE_SIZE);
66080 if (!kip->insns) {
66081 kfree(kip);
66082 return NULL;
66083@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
66084 */
66085 if (!list_is_singular(&kip->list)) {
66086 list_del(&kip->list);
66087- module_free(NULL, kip->insns);
66088+ module_free_exec(NULL, kip->insns);
66089 kfree(kip);
66090 }
66091 return 1;
66092@@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
66093 {
66094 int i, err = 0;
66095 unsigned long offset = 0, size = 0;
66096- char *modname, namebuf[128];
66097+ char *modname, namebuf[KSYM_NAME_LEN];
66098 const char *symbol_name;
66099 void *addr;
66100 struct kprobe_blackpoint *kb;
66101@@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
66102 const char *sym = NULL;
66103 unsigned int i = *(loff_t *) v;
66104 unsigned long offset = 0;
66105- char *modname, namebuf[128];
66106+ char *modname, namebuf[KSYM_NAME_LEN];
66107
66108 head = &kprobe_table[i];
66109 preempt_disable();
66110diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
66111index 4e316e1..5501eef 100644
66112--- a/kernel/ksysfs.c
66113+++ b/kernel/ksysfs.c
66114@@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
66115 {
66116 if (count+1 > UEVENT_HELPER_PATH_LEN)
66117 return -ENOENT;
66118+ if (!capable(CAP_SYS_ADMIN))
66119+ return -EPERM;
66120 memcpy(uevent_helper, buf, count);
66121 uevent_helper[count] = '\0';
66122 if (count && uevent_helper[count-1] == '\n')
66123diff --git a/kernel/lockdep.c b/kernel/lockdep.c
66124index ea9ee45..67ebc8f 100644
66125--- a/kernel/lockdep.c
66126+++ b/kernel/lockdep.c
66127@@ -590,6 +590,10 @@ static int static_obj(void *obj)
66128 end = (unsigned long) &_end,
66129 addr = (unsigned long) obj;
66130
66131+#ifdef CONFIG_PAX_KERNEXEC
66132+ start = ktla_ktva(start);
66133+#endif
66134+
66135 /*
66136 * static variable?
66137 */
66138@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
66139 if (!static_obj(lock->key)) {
66140 debug_locks_off();
66141 printk("INFO: trying to register non-static key.\n");
66142+ printk("lock:%pS key:%pS.\n", lock, lock->key);
66143 printk("the code is fine but needs lockdep annotation.\n");
66144 printk("turning off the locking correctness validator.\n");
66145 dump_stack();
66146@@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
66147 if (!class)
66148 return 0;
66149 }
66150- atomic_inc((atomic_t *)&class->ops);
66151+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
66152 if (very_verbose(class)) {
66153 printk("\nacquire class [%p] %s", class->key, class->name);
66154 if (class->name_version > 1)
66155diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
66156index 91c32a0..b2c71c5 100644
66157--- a/kernel/lockdep_proc.c
66158+++ b/kernel/lockdep_proc.c
66159@@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
66160
66161 static void print_name(struct seq_file *m, struct lock_class *class)
66162 {
66163- char str[128];
66164+ char str[KSYM_NAME_LEN];
66165 const char *name = class->name;
66166
66167 if (!name) {
66168diff --git a/kernel/module.c b/kernel/module.c
66169index 78ac6ec..e87db0e 100644
66170--- a/kernel/module.c
66171+++ b/kernel/module.c
66172@@ -58,6 +58,7 @@
66173 #include <linux/jump_label.h>
66174 #include <linux/pfn.h>
66175 #include <linux/bsearch.h>
66176+#include <linux/grsecurity.h>
66177
66178 #define CREATE_TRACE_POINTS
66179 #include <trace/events/module.h>
66180@@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
66181
66182 /* Bounds of module allocation, for speeding __module_address.
66183 * Protected by module_mutex. */
66184-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
66185+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
66186+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
66187
66188 int register_module_notifier(struct notifier_block * nb)
66189 {
66190@@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
66191 return true;
66192
66193 list_for_each_entry_rcu(mod, &modules, list) {
66194- struct symsearch arr[] = {
66195+ struct symsearch modarr[] = {
66196 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
66197 NOT_GPL_ONLY, false },
66198 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
66199@@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
66200 #endif
66201 };
66202
66203- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
66204+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
66205 return true;
66206 }
66207 return false;
66208@@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
66209 static int percpu_modalloc(struct module *mod,
66210 unsigned long size, unsigned long align)
66211 {
66212- if (align > PAGE_SIZE) {
66213+ if (align-1 >= PAGE_SIZE) {
66214 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
66215 mod->name, align, PAGE_SIZE);
66216 align = PAGE_SIZE;
66217@@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
66218 static ssize_t show_coresize(struct module_attribute *mattr,
66219 struct module_kobject *mk, char *buffer)
66220 {
66221- return sprintf(buffer, "%u\n", mk->mod->core_size);
66222+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
66223 }
66224
66225 static struct module_attribute modinfo_coresize =
66226@@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
66227 static ssize_t show_initsize(struct module_attribute *mattr,
66228 struct module_kobject *mk, char *buffer)
66229 {
66230- return sprintf(buffer, "%u\n", mk->mod->init_size);
66231+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
66232 }
66233
66234 static struct module_attribute modinfo_initsize =
66235@@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
66236 */
66237 #ifdef CONFIG_SYSFS
66238
66239-#ifdef CONFIG_KALLSYMS
66240+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66241 static inline bool sect_empty(const Elf_Shdr *sect)
66242 {
66243 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
66244@@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
66245
66246 static void unset_module_core_ro_nx(struct module *mod)
66247 {
66248- set_page_attributes(mod->module_core + mod->core_text_size,
66249- mod->module_core + mod->core_size,
66250+ set_page_attributes(mod->module_core_rw,
66251+ mod->module_core_rw + mod->core_size_rw,
66252 set_memory_x);
66253- set_page_attributes(mod->module_core,
66254- mod->module_core + mod->core_ro_size,
66255+ set_page_attributes(mod->module_core_rx,
66256+ mod->module_core_rx + mod->core_size_rx,
66257 set_memory_rw);
66258 }
66259
66260 static void unset_module_init_ro_nx(struct module *mod)
66261 {
66262- set_page_attributes(mod->module_init + mod->init_text_size,
66263- mod->module_init + mod->init_size,
66264+ set_page_attributes(mod->module_init_rw,
66265+ mod->module_init_rw + mod->init_size_rw,
66266 set_memory_x);
66267- set_page_attributes(mod->module_init,
66268- mod->module_init + mod->init_ro_size,
66269+ set_page_attributes(mod->module_init_rx,
66270+ mod->module_init_rx + mod->init_size_rx,
66271 set_memory_rw);
66272 }
66273
66274@@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
66275
66276 mutex_lock(&module_mutex);
66277 list_for_each_entry_rcu(mod, &modules, list) {
66278- if ((mod->module_core) && (mod->core_text_size)) {
66279- set_page_attributes(mod->module_core,
66280- mod->module_core + mod->core_text_size,
66281+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
66282+ set_page_attributes(mod->module_core_rx,
66283+ mod->module_core_rx + mod->core_size_rx,
66284 set_memory_rw);
66285 }
66286- if ((mod->module_init) && (mod->init_text_size)) {
66287- set_page_attributes(mod->module_init,
66288- mod->module_init + mod->init_text_size,
66289+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
66290+ set_page_attributes(mod->module_init_rx,
66291+ mod->module_init_rx + mod->init_size_rx,
66292 set_memory_rw);
66293 }
66294 }
66295@@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
66296
66297 mutex_lock(&module_mutex);
66298 list_for_each_entry_rcu(mod, &modules, list) {
66299- if ((mod->module_core) && (mod->core_text_size)) {
66300- set_page_attributes(mod->module_core,
66301- mod->module_core + mod->core_text_size,
66302+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
66303+ set_page_attributes(mod->module_core_rx,
66304+ mod->module_core_rx + mod->core_size_rx,
66305 set_memory_ro);
66306 }
66307- if ((mod->module_init) && (mod->init_text_size)) {
66308- set_page_attributes(mod->module_init,
66309- mod->module_init + mod->init_text_size,
66310+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
66311+ set_page_attributes(mod->module_init_rx,
66312+ mod->module_init_rx + mod->init_size_rx,
66313 set_memory_ro);
66314 }
66315 }
66316@@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
66317
66318 /* This may be NULL, but that's OK */
66319 unset_module_init_ro_nx(mod);
66320- module_free(mod, mod->module_init);
66321+ module_free(mod, mod->module_init_rw);
66322+ module_free_exec(mod, mod->module_init_rx);
66323 kfree(mod->args);
66324 percpu_modfree(mod);
66325
66326 /* Free lock-classes: */
66327- lockdep_free_key_range(mod->module_core, mod->core_size);
66328+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
66329+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
66330
66331 /* Finally, free the core (containing the module structure) */
66332 unset_module_core_ro_nx(mod);
66333- module_free(mod, mod->module_core);
66334+ module_free_exec(mod, mod->module_core_rx);
66335+ module_free(mod, mod->module_core_rw);
66336
66337 #ifdef CONFIG_MPU
66338 update_protections(current->mm);
66339@@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66340 int ret = 0;
66341 const struct kernel_symbol *ksym;
66342
66343+#ifdef CONFIG_GRKERNSEC_MODHARDEN
66344+ int is_fs_load = 0;
66345+ int register_filesystem_found = 0;
66346+ char *p;
66347+
66348+ p = strstr(mod->args, "grsec_modharden_fs");
66349+ if (p) {
66350+ char *endptr = p + strlen("grsec_modharden_fs");
66351+ /* copy \0 as well */
66352+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
66353+ is_fs_load = 1;
66354+ }
66355+#endif
66356+
66357 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
66358 const char *name = info->strtab + sym[i].st_name;
66359
66360+#ifdef CONFIG_GRKERNSEC_MODHARDEN
66361+ /* it's a real shame this will never get ripped and copied
66362+ upstream! ;(
66363+ */
66364+ if (is_fs_load && !strcmp(name, "register_filesystem"))
66365+ register_filesystem_found = 1;
66366+#endif
66367+
66368 switch (sym[i].st_shndx) {
66369 case SHN_COMMON:
66370 /* We compiled with -fno-common. These are not
66371@@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66372 ksym = resolve_symbol_wait(mod, info, name);
66373 /* Ok if resolved. */
66374 if (ksym && !IS_ERR(ksym)) {
66375+ pax_open_kernel();
66376 sym[i].st_value = ksym->value;
66377+ pax_close_kernel();
66378 break;
66379 }
66380
66381@@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66382 secbase = (unsigned long)mod_percpu(mod);
66383 else
66384 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
66385+ pax_open_kernel();
66386 sym[i].st_value += secbase;
66387+ pax_close_kernel();
66388 break;
66389 }
66390 }
66391
66392+#ifdef CONFIG_GRKERNSEC_MODHARDEN
66393+ if (is_fs_load && !register_filesystem_found) {
66394+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
66395+ ret = -EPERM;
66396+ }
66397+#endif
66398+
66399 return ret;
66400 }
66401
66402@@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
66403 || s->sh_entsize != ~0UL
66404 || strstarts(sname, ".init"))
66405 continue;
66406- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
66407+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
66408+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
66409+ else
66410+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
66411 pr_debug("\t%s\n", sname);
66412 }
66413- switch (m) {
66414- case 0: /* executable */
66415- mod->core_size = debug_align(mod->core_size);
66416- mod->core_text_size = mod->core_size;
66417- break;
66418- case 1: /* RO: text and ro-data */
66419- mod->core_size = debug_align(mod->core_size);
66420- mod->core_ro_size = mod->core_size;
66421- break;
66422- case 3: /* whole core */
66423- mod->core_size = debug_align(mod->core_size);
66424- break;
66425- }
66426 }
66427
66428 pr_debug("Init section allocation order:\n");
66429@@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
66430 || s->sh_entsize != ~0UL
66431 || !strstarts(sname, ".init"))
66432 continue;
66433- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
66434- | INIT_OFFSET_MASK);
66435+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
66436+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
66437+ else
66438+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
66439+ s->sh_entsize |= INIT_OFFSET_MASK;
66440 pr_debug("\t%s\n", sname);
66441 }
66442- switch (m) {
66443- case 0: /* executable */
66444- mod->init_size = debug_align(mod->init_size);
66445- mod->init_text_size = mod->init_size;
66446- break;
66447- case 1: /* RO: text and ro-data */
66448- mod->init_size = debug_align(mod->init_size);
66449- mod->init_ro_size = mod->init_size;
66450- break;
66451- case 3: /* whole init */
66452- mod->init_size = debug_align(mod->init_size);
66453- break;
66454- }
66455 }
66456 }
66457
66458@@ -2266,7 +2284,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
66459
66460 /* Put symbol section at end of init part of module. */
66461 symsect->sh_flags |= SHF_ALLOC;
66462- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
66463+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
66464 info->index.sym) | INIT_OFFSET_MASK;
66465 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
66466
66467@@ -2281,13 +2299,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
66468 }
66469
66470 /* Append room for core symbols at end of core part. */
66471- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
66472- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
66473- mod->core_size += strtab_size;
66474+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
66475+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
66476+ mod->core_size_rx += strtab_size;
66477
66478 /* Put string table section at end of init part of module. */
66479 strsect->sh_flags |= SHF_ALLOC;
66480- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
66481+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
66482 info->index.str) | INIT_OFFSET_MASK;
66483 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
66484 }
66485@@ -2305,12 +2323,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
66486 /* Make sure we get permanent strtab: don't use info->strtab. */
66487 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
66488
66489+ pax_open_kernel();
66490+
66491 /* Set types up while we still have access to sections. */
66492 for (i = 0; i < mod->num_symtab; i++)
66493 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
66494
66495- mod->core_symtab = dst = mod->module_core + info->symoffs;
66496- mod->core_strtab = s = mod->module_core + info->stroffs;
66497+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
66498+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
66499 src = mod->symtab;
66500 *dst = *src;
66501 *s++ = 0;
66502@@ -2323,6 +2343,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
66503 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
66504 }
66505 mod->core_num_syms = ndst;
66506+
66507+ pax_close_kernel();
66508 }
66509 #else
66510 static inline void layout_symtab(struct module *mod, struct load_info *info)
66511@@ -2356,17 +2378,33 @@ void * __weak module_alloc(unsigned long size)
66512 return size == 0 ? NULL : vmalloc_exec(size);
66513 }
66514
66515-static void *module_alloc_update_bounds(unsigned long size)
66516+static void *module_alloc_update_bounds_rw(unsigned long size)
66517 {
66518 void *ret = module_alloc(size);
66519
66520 if (ret) {
66521 mutex_lock(&module_mutex);
66522 /* Update module bounds. */
66523- if ((unsigned long)ret < module_addr_min)
66524- module_addr_min = (unsigned long)ret;
66525- if ((unsigned long)ret + size > module_addr_max)
66526- module_addr_max = (unsigned long)ret + size;
66527+ if ((unsigned long)ret < module_addr_min_rw)
66528+ module_addr_min_rw = (unsigned long)ret;
66529+ if ((unsigned long)ret + size > module_addr_max_rw)
66530+ module_addr_max_rw = (unsigned long)ret + size;
66531+ mutex_unlock(&module_mutex);
66532+ }
66533+ return ret;
66534+}
66535+
66536+static void *module_alloc_update_bounds_rx(unsigned long size)
66537+{
66538+ void *ret = module_alloc_exec(size);
66539+
66540+ if (ret) {
66541+ mutex_lock(&module_mutex);
66542+ /* Update module bounds. */
66543+ if ((unsigned long)ret < module_addr_min_rx)
66544+ module_addr_min_rx = (unsigned long)ret;
66545+ if ((unsigned long)ret + size > module_addr_max_rx)
66546+ module_addr_max_rx = (unsigned long)ret + size;
66547 mutex_unlock(&module_mutex);
66548 }
66549 return ret;
66550@@ -2543,8 +2581,14 @@ static struct module *setup_load_info(struct load_info *info)
66551 static int check_modinfo(struct module *mod, struct load_info *info)
66552 {
66553 const char *modmagic = get_modinfo(info, "vermagic");
66554+ const char *license = get_modinfo(info, "license");
66555 int err;
66556
66557+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
66558+ if (!license || !license_is_gpl_compatible(license))
66559+ return -ENOEXEC;
66560+#endif
66561+
66562 /* This is allowed: modprobe --force will invalidate it. */
66563 if (!modmagic) {
66564 err = try_to_force_load(mod, "bad vermagic");
66565@@ -2567,7 +2611,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
66566 }
66567
66568 /* Set up license info based on the info section */
66569- set_license(mod, get_modinfo(info, "license"));
66570+ set_license(mod, license);
66571
66572 return 0;
66573 }
66574@@ -2661,7 +2705,7 @@ static int move_module(struct module *mod, struct load_info *info)
66575 void *ptr;
66576
66577 /* Do the allocs. */
66578- ptr = module_alloc_update_bounds(mod->core_size);
66579+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
66580 /*
66581 * The pointer to this block is stored in the module structure
66582 * which is inside the block. Just mark it as not being a
66583@@ -2671,23 +2715,50 @@ static int move_module(struct module *mod, struct load_info *info)
66584 if (!ptr)
66585 return -ENOMEM;
66586
66587- memset(ptr, 0, mod->core_size);
66588- mod->module_core = ptr;
66589+ memset(ptr, 0, mod->core_size_rw);
66590+ mod->module_core_rw = ptr;
66591
66592- ptr = module_alloc_update_bounds(mod->init_size);
66593+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
66594 /*
66595 * The pointer to this block is stored in the module structure
66596 * which is inside the block. This block doesn't need to be
66597 * scanned as it contains data and code that will be freed
66598 * after the module is initialized.
66599 */
66600- kmemleak_ignore(ptr);
66601- if (!ptr && mod->init_size) {
66602- module_free(mod, mod->module_core);
66603+ kmemleak_not_leak(ptr);
66604+ if (!ptr && mod->init_size_rw) {
66605+ module_free(mod, mod->module_core_rw);
66606 return -ENOMEM;
66607 }
66608- memset(ptr, 0, mod->init_size);
66609- mod->module_init = ptr;
66610+ memset(ptr, 0, mod->init_size_rw);
66611+ mod->module_init_rw = ptr;
66612+
66613+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
66614+ kmemleak_not_leak(ptr);
66615+ if (!ptr) {
66616+ module_free(mod, mod->module_init_rw);
66617+ module_free(mod, mod->module_core_rw);
66618+ return -ENOMEM;
66619+ }
66620+
66621+ pax_open_kernel();
66622+ memset(ptr, 0, mod->core_size_rx);
66623+ pax_close_kernel();
66624+ mod->module_core_rx = ptr;
66625+
66626+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
66627+ kmemleak_not_leak(ptr);
66628+ if (!ptr && mod->init_size_rx) {
66629+ module_free_exec(mod, mod->module_core_rx);
66630+ module_free(mod, mod->module_init_rw);
66631+ module_free(mod, mod->module_core_rw);
66632+ return -ENOMEM;
66633+ }
66634+
66635+ pax_open_kernel();
66636+ memset(ptr, 0, mod->init_size_rx);
66637+ pax_close_kernel();
66638+ mod->module_init_rx = ptr;
66639
66640 /* Transfer each section which specifies SHF_ALLOC */
66641 pr_debug("final section addresses:\n");
66642@@ -2698,16 +2769,45 @@ static int move_module(struct module *mod, struct load_info *info)
66643 if (!(shdr->sh_flags & SHF_ALLOC))
66644 continue;
66645
66646- if (shdr->sh_entsize & INIT_OFFSET_MASK)
66647- dest = mod->module_init
66648- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
66649- else
66650- dest = mod->module_core + shdr->sh_entsize;
66651+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
66652+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
66653+ dest = mod->module_init_rw
66654+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
66655+ else
66656+ dest = mod->module_init_rx
66657+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
66658+ } else {
66659+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
66660+ dest = mod->module_core_rw + shdr->sh_entsize;
66661+ else
66662+ dest = mod->module_core_rx + shdr->sh_entsize;
66663+ }
66664+
66665+ if (shdr->sh_type != SHT_NOBITS) {
66666+
66667+#ifdef CONFIG_PAX_KERNEXEC
66668+#ifdef CONFIG_X86_64
66669+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
66670+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
66671+#endif
66672+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
66673+ pax_open_kernel();
66674+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
66675+ pax_close_kernel();
66676+ } else
66677+#endif
66678
66679- if (shdr->sh_type != SHT_NOBITS)
66680 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
66681+ }
66682 /* Update sh_addr to point to copy in image. */
66683- shdr->sh_addr = (unsigned long)dest;
66684+
66685+#ifdef CONFIG_PAX_KERNEXEC
66686+ if (shdr->sh_flags & SHF_EXECINSTR)
66687+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
66688+ else
66689+#endif
66690+
66691+ shdr->sh_addr = (unsigned long)dest;
66692 pr_debug("\t0x%lx %s\n",
66693 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
66694 }
66695@@ -2758,12 +2858,12 @@ static void flush_module_icache(const struct module *mod)
66696 * Do it before processing of module parameters, so the module
66697 * can provide parameter accessor functions of its own.
66698 */
66699- if (mod->module_init)
66700- flush_icache_range((unsigned long)mod->module_init,
66701- (unsigned long)mod->module_init
66702- + mod->init_size);
66703- flush_icache_range((unsigned long)mod->module_core,
66704- (unsigned long)mod->module_core + mod->core_size);
66705+ if (mod->module_init_rx)
66706+ flush_icache_range((unsigned long)mod->module_init_rx,
66707+ (unsigned long)mod->module_init_rx
66708+ + mod->init_size_rx);
66709+ flush_icache_range((unsigned long)mod->module_core_rx,
66710+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
66711
66712 set_fs(old_fs);
66713 }
66714@@ -2833,8 +2933,10 @@ out:
66715 static void module_deallocate(struct module *mod, struct load_info *info)
66716 {
66717 percpu_modfree(mod);
66718- module_free(mod, mod->module_init);
66719- module_free(mod, mod->module_core);
66720+ module_free_exec(mod, mod->module_init_rx);
66721+ module_free_exec(mod, mod->module_core_rx);
66722+ module_free(mod, mod->module_init_rw);
66723+ module_free(mod, mod->module_core_rw);
66724 }
66725
66726 int __weak module_finalize(const Elf_Ehdr *hdr,
66727@@ -2898,9 +3000,38 @@ static struct module *load_module(void __user *umod,
66728 if (err)
66729 goto free_unload;
66730
66731+ /* Now copy in args */
66732+ mod->args = strndup_user(uargs, ~0UL >> 1);
66733+ if (IS_ERR(mod->args)) {
66734+ err = PTR_ERR(mod->args);
66735+ goto free_unload;
66736+ }
66737+
66738 /* Set up MODINFO_ATTR fields */
66739 setup_modinfo(mod, &info);
66740
66741+#ifdef CONFIG_GRKERNSEC_MODHARDEN
66742+ {
66743+ char *p, *p2;
66744+
66745+ if (strstr(mod->args, "grsec_modharden_netdev")) {
66746+ 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);
66747+ err = -EPERM;
66748+ goto free_modinfo;
66749+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
66750+ p += strlen("grsec_modharden_normal");
66751+ p2 = strstr(p, "_");
66752+ if (p2) {
66753+ *p2 = '\0';
66754+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
66755+ *p2 = '_';
66756+ }
66757+ err = -EPERM;
66758+ goto free_modinfo;
66759+ }
66760+ }
66761+#endif
66762+
66763 /* Fix up syms, so that st_value is a pointer to location. */
66764 err = simplify_symbols(mod, &info);
66765 if (err < 0)
66766@@ -2916,13 +3047,6 @@ static struct module *load_module(void __user *umod,
66767
66768 flush_module_icache(mod);
66769
66770- /* Now copy in args */
66771- mod->args = strndup_user(uargs, ~0UL >> 1);
66772- if (IS_ERR(mod->args)) {
66773- err = PTR_ERR(mod->args);
66774- goto free_arch_cleanup;
66775- }
66776-
66777 /* Mark state as coming so strong_try_module_get() ignores us. */
66778 mod->state = MODULE_STATE_COMING;
66779
66780@@ -2980,11 +3104,10 @@ static struct module *load_module(void __user *umod,
66781 unlock:
66782 mutex_unlock(&module_mutex);
66783 synchronize_sched();
66784- kfree(mod->args);
66785- free_arch_cleanup:
66786 module_arch_cleanup(mod);
66787 free_modinfo:
66788 free_modinfo(mod);
66789+ kfree(mod->args);
66790 free_unload:
66791 module_unload_free(mod);
66792 free_module:
66793@@ -3025,16 +3148,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
66794 MODULE_STATE_COMING, mod);
66795
66796 /* Set RO and NX regions for core */
66797- set_section_ro_nx(mod->module_core,
66798- mod->core_text_size,
66799- mod->core_ro_size,
66800- mod->core_size);
66801+ set_section_ro_nx(mod->module_core_rx,
66802+ mod->core_size_rx,
66803+ mod->core_size_rx,
66804+ mod->core_size_rx);
66805
66806 /* Set RO and NX regions for init */
66807- set_section_ro_nx(mod->module_init,
66808- mod->init_text_size,
66809- mod->init_ro_size,
66810- mod->init_size);
66811+ set_section_ro_nx(mod->module_init_rx,
66812+ mod->init_size_rx,
66813+ mod->init_size_rx,
66814+ mod->init_size_rx);
66815
66816 do_mod_ctors(mod);
66817 /* Start the module */
66818@@ -3080,11 +3203,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
66819 mod->strtab = mod->core_strtab;
66820 #endif
66821 unset_module_init_ro_nx(mod);
66822- module_free(mod, mod->module_init);
66823- mod->module_init = NULL;
66824- mod->init_size = 0;
66825- mod->init_ro_size = 0;
66826- mod->init_text_size = 0;
66827+ module_free(mod, mod->module_init_rw);
66828+ module_free_exec(mod, mod->module_init_rx);
66829+ mod->module_init_rw = NULL;
66830+ mod->module_init_rx = NULL;
66831+ mod->init_size_rw = 0;
66832+ mod->init_size_rx = 0;
66833 mutex_unlock(&module_mutex);
66834
66835 return 0;
66836@@ -3115,10 +3239,16 @@ static const char *get_ksymbol(struct module *mod,
66837 unsigned long nextval;
66838
66839 /* At worse, next value is at end of module */
66840- if (within_module_init(addr, mod))
66841- nextval = (unsigned long)mod->module_init+mod->init_text_size;
66842+ if (within_module_init_rx(addr, mod))
66843+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
66844+ else if (within_module_init_rw(addr, mod))
66845+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
66846+ else if (within_module_core_rx(addr, mod))
66847+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
66848+ else if (within_module_core_rw(addr, mod))
66849+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
66850 else
66851- nextval = (unsigned long)mod->module_core+mod->core_text_size;
66852+ return NULL;
66853
66854 /* Scan for closest preceding symbol, and next symbol. (ELF
66855 starts real symbols at 1). */
66856@@ -3353,7 +3483,7 @@ static int m_show(struct seq_file *m, void *p)
66857 char buf[8];
66858
66859 seq_printf(m, "%s %u",
66860- mod->name, mod->init_size + mod->core_size);
66861+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
66862 print_unload_info(m, mod);
66863
66864 /* Informative for users. */
66865@@ -3362,7 +3492,7 @@ static int m_show(struct seq_file *m, void *p)
66866 mod->state == MODULE_STATE_COMING ? "Loading":
66867 "Live");
66868 /* Used by oprofile and other similar tools. */
66869- seq_printf(m, " 0x%pK", mod->module_core);
66870+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
66871
66872 /* Taints info */
66873 if (mod->taints)
66874@@ -3398,7 +3528,17 @@ static const struct file_operations proc_modules_operations = {
66875
66876 static int __init proc_modules_init(void)
66877 {
66878+#ifndef CONFIG_GRKERNSEC_HIDESYM
66879+#ifdef CONFIG_GRKERNSEC_PROC_USER
66880+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
66881+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66882+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
66883+#else
66884 proc_create("modules", 0, NULL, &proc_modules_operations);
66885+#endif
66886+#else
66887+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
66888+#endif
66889 return 0;
66890 }
66891 module_init(proc_modules_init);
66892@@ -3457,12 +3597,12 @@ struct module *__module_address(unsigned long addr)
66893 {
66894 struct module *mod;
66895
66896- if (addr < module_addr_min || addr > module_addr_max)
66897+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
66898+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
66899 return NULL;
66900
66901 list_for_each_entry_rcu(mod, &modules, list)
66902- if (within_module_core(addr, mod)
66903- || within_module_init(addr, mod))
66904+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
66905 return mod;
66906 return NULL;
66907 }
66908@@ -3496,11 +3636,20 @@ bool is_module_text_address(unsigned long addr)
66909 */
66910 struct module *__module_text_address(unsigned long addr)
66911 {
66912- struct module *mod = __module_address(addr);
66913+ struct module *mod;
66914+
66915+#ifdef CONFIG_X86_32
66916+ addr = ktla_ktva(addr);
66917+#endif
66918+
66919+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
66920+ return NULL;
66921+
66922+ mod = __module_address(addr);
66923+
66924 if (mod) {
66925 /* Make sure it's within the text section. */
66926- if (!within(addr, mod->module_init, mod->init_text_size)
66927- && !within(addr, mod->module_core, mod->core_text_size))
66928+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
66929 mod = NULL;
66930 }
66931 return mod;
66932diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
66933index 7e3443f..b2a1e6b 100644
66934--- a/kernel/mutex-debug.c
66935+++ b/kernel/mutex-debug.c
66936@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
66937 }
66938
66939 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
66940- struct thread_info *ti)
66941+ struct task_struct *task)
66942 {
66943 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
66944
66945 /* Mark the current thread as blocked on the lock: */
66946- ti->task->blocked_on = waiter;
66947+ task->blocked_on = waiter;
66948 }
66949
66950 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
66951- struct thread_info *ti)
66952+ struct task_struct *task)
66953 {
66954 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
66955- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
66956- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
66957- ti->task->blocked_on = NULL;
66958+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
66959+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
66960+ task->blocked_on = NULL;
66961
66962 list_del_init(&waiter->list);
66963 waiter->task = NULL;
66964diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
66965index 0799fd3..d06ae3b 100644
66966--- a/kernel/mutex-debug.h
66967+++ b/kernel/mutex-debug.h
66968@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
66969 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
66970 extern void debug_mutex_add_waiter(struct mutex *lock,
66971 struct mutex_waiter *waiter,
66972- struct thread_info *ti);
66973+ struct task_struct *task);
66974 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
66975- struct thread_info *ti);
66976+ struct task_struct *task);
66977 extern void debug_mutex_unlock(struct mutex *lock);
66978 extern void debug_mutex_init(struct mutex *lock, const char *name,
66979 struct lock_class_key *key);
66980diff --git a/kernel/mutex.c b/kernel/mutex.c
66981index a307cc9..27fd2e9 100644
66982--- a/kernel/mutex.c
66983+++ b/kernel/mutex.c
66984@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
66985 spin_lock_mutex(&lock->wait_lock, flags);
66986
66987 debug_mutex_lock_common(lock, &waiter);
66988- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
66989+ debug_mutex_add_waiter(lock, &waiter, task);
66990
66991 /* add waiting tasks to the end of the waitqueue (FIFO): */
66992 list_add_tail(&waiter.list, &lock->wait_list);
66993@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
66994 * TASK_UNINTERRUPTIBLE case.)
66995 */
66996 if (unlikely(signal_pending_state(state, task))) {
66997- mutex_remove_waiter(lock, &waiter,
66998- task_thread_info(task));
66999+ mutex_remove_waiter(lock, &waiter, task);
67000 mutex_release(&lock->dep_map, 1, ip);
67001 spin_unlock_mutex(&lock->wait_lock, flags);
67002
67003@@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67004 done:
67005 lock_acquired(&lock->dep_map, ip);
67006 /* got the lock - rejoice! */
67007- mutex_remove_waiter(lock, &waiter, current_thread_info());
67008+ mutex_remove_waiter(lock, &waiter, task);
67009 mutex_set_owner(lock);
67010
67011 /* set it to 0 if there are no waiters left: */
67012diff --git a/kernel/panic.c b/kernel/panic.c
67013index 9ed023b..e49543e 100644
67014--- a/kernel/panic.c
67015+++ b/kernel/panic.c
67016@@ -402,7 +402,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
67017 const char *board;
67018
67019 printk(KERN_WARNING "------------[ cut here ]------------\n");
67020- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
67021+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
67022 board = dmi_get_system_info(DMI_PRODUCT_NAME);
67023 if (board)
67024 printk(KERN_WARNING "Hardware name: %s\n", board);
67025@@ -457,7 +457,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
67026 */
67027 void __stack_chk_fail(void)
67028 {
67029- panic("stack-protector: Kernel stack is corrupted in: %p\n",
67030+ dump_stack();
67031+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
67032 __builtin_return_address(0));
67033 }
67034 EXPORT_SYMBOL(__stack_chk_fail);
67035diff --git a/kernel/pid.c b/kernel/pid.c
67036index 9f08dfa..6765c40 100644
67037--- a/kernel/pid.c
67038+++ b/kernel/pid.c
67039@@ -33,6 +33,7 @@
67040 #include <linux/rculist.h>
67041 #include <linux/bootmem.h>
67042 #include <linux/hash.h>
67043+#include <linux/security.h>
67044 #include <linux/pid_namespace.h>
67045 #include <linux/init_task.h>
67046 #include <linux/syscalls.h>
67047@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
67048
67049 int pid_max = PID_MAX_DEFAULT;
67050
67051-#define RESERVED_PIDS 300
67052+#define RESERVED_PIDS 500
67053
67054 int pid_max_min = RESERVED_PIDS + 1;
67055 int pid_max_max = PID_MAX_LIMIT;
67056@@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
67057 */
67058 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
67059 {
67060+ struct task_struct *task;
67061+
67062 rcu_lockdep_assert(rcu_read_lock_held(),
67063 "find_task_by_pid_ns() needs rcu_read_lock()"
67064 " protection");
67065- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
67066+
67067+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
67068+
67069+ if (gr_pid_is_chrooted(task))
67070+ return NULL;
67071+
67072+ return task;
67073 }
67074
67075 struct task_struct *find_task_by_vpid(pid_t vnr)
67076@@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
67077 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
67078 }
67079
67080+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
67081+{
67082+ rcu_lockdep_assert(rcu_read_lock_held(),
67083+ "find_task_by_pid_ns() needs rcu_read_lock()"
67084+ " protection");
67085+ return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
67086+}
67087+
67088 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
67089 {
67090 struct pid *pid;
67091diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
67092index 125cb67..a4d1c30 100644
67093--- a/kernel/posix-cpu-timers.c
67094+++ b/kernel/posix-cpu-timers.c
67095@@ -6,6 +6,7 @@
67096 #include <linux/posix-timers.h>
67097 #include <linux/errno.h>
67098 #include <linux/math64.h>
67099+#include <linux/security.h>
67100 #include <asm/uaccess.h>
67101 #include <linux/kernel_stat.h>
67102 #include <trace/events/timer.h>
67103@@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
67104
67105 static __init int init_posix_cpu_timers(void)
67106 {
67107- struct k_clock process = {
67108+ static struct k_clock process = {
67109 .clock_getres = process_cpu_clock_getres,
67110 .clock_get = process_cpu_clock_get,
67111 .timer_create = process_cpu_timer_create,
67112 .nsleep = process_cpu_nsleep,
67113 .nsleep_restart = process_cpu_nsleep_restart,
67114 };
67115- struct k_clock thread = {
67116+ static struct k_clock thread = {
67117 .clock_getres = thread_cpu_clock_getres,
67118 .clock_get = thread_cpu_clock_get,
67119 .timer_create = thread_cpu_timer_create,
67120diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
67121index 69185ae..cc2847a 100644
67122--- a/kernel/posix-timers.c
67123+++ b/kernel/posix-timers.c
67124@@ -43,6 +43,7 @@
67125 #include <linux/idr.h>
67126 #include <linux/posix-clock.h>
67127 #include <linux/posix-timers.h>
67128+#include <linux/grsecurity.h>
67129 #include <linux/syscalls.h>
67130 #include <linux/wait.h>
67131 #include <linux/workqueue.h>
67132@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
67133 * which we beg off on and pass to do_sys_settimeofday().
67134 */
67135
67136-static struct k_clock posix_clocks[MAX_CLOCKS];
67137+static struct k_clock *posix_clocks[MAX_CLOCKS];
67138
67139 /*
67140 * These ones are defined below.
67141@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
67142 */
67143 static __init int init_posix_timers(void)
67144 {
67145- struct k_clock clock_realtime = {
67146+ static struct k_clock clock_realtime = {
67147 .clock_getres = hrtimer_get_res,
67148 .clock_get = posix_clock_realtime_get,
67149 .clock_set = posix_clock_realtime_set,
67150@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
67151 .timer_get = common_timer_get,
67152 .timer_del = common_timer_del,
67153 };
67154- struct k_clock clock_monotonic = {
67155+ static struct k_clock clock_monotonic = {
67156 .clock_getres = hrtimer_get_res,
67157 .clock_get = posix_ktime_get_ts,
67158 .nsleep = common_nsleep,
67159@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
67160 .timer_get = common_timer_get,
67161 .timer_del = common_timer_del,
67162 };
67163- struct k_clock clock_monotonic_raw = {
67164+ static struct k_clock clock_monotonic_raw = {
67165 .clock_getres = hrtimer_get_res,
67166 .clock_get = posix_get_monotonic_raw,
67167 };
67168- struct k_clock clock_realtime_coarse = {
67169+ static struct k_clock clock_realtime_coarse = {
67170 .clock_getres = posix_get_coarse_res,
67171 .clock_get = posix_get_realtime_coarse,
67172 };
67173- struct k_clock clock_monotonic_coarse = {
67174+ static struct k_clock clock_monotonic_coarse = {
67175 .clock_getres = posix_get_coarse_res,
67176 .clock_get = posix_get_monotonic_coarse,
67177 };
67178- struct k_clock clock_boottime = {
67179+ static struct k_clock clock_boottime = {
67180 .clock_getres = hrtimer_get_res,
67181 .clock_get = posix_get_boottime,
67182 .nsleep = common_nsleep,
67183@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
67184 return;
67185 }
67186
67187- posix_clocks[clock_id] = *new_clock;
67188+ posix_clocks[clock_id] = new_clock;
67189 }
67190 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
67191
67192@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
67193 return (id & CLOCKFD_MASK) == CLOCKFD ?
67194 &clock_posix_dynamic : &clock_posix_cpu;
67195
67196- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
67197+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
67198 return NULL;
67199- return &posix_clocks[id];
67200+ return posix_clocks[id];
67201 }
67202
67203 static int common_timer_create(struct k_itimer *new_timer)
67204@@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
67205 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
67206 return -EFAULT;
67207
67208+ /* only the CLOCK_REALTIME clock can be set, all other clocks
67209+ have their clock_set fptr set to a nosettime dummy function
67210+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
67211+ call common_clock_set, which calls do_sys_settimeofday, which
67212+ we hook
67213+ */
67214+
67215 return kc->clock_set(which_clock, &new_tp);
67216 }
67217
67218diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
67219index d523593..68197a4 100644
67220--- a/kernel/power/poweroff.c
67221+++ b/kernel/power/poweroff.c
67222@@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
67223 .enable_mask = SYSRQ_ENABLE_BOOT,
67224 };
67225
67226-static int pm_sysrq_init(void)
67227+static int __init pm_sysrq_init(void)
67228 {
67229 register_sysrq_key('o', &sysrq_poweroff_op);
67230 return 0;
67231diff --git a/kernel/power/process.c b/kernel/power/process.c
67232index 19db29f..33b52b6 100644
67233--- a/kernel/power/process.c
67234+++ b/kernel/power/process.c
67235@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
67236 u64 elapsed_csecs64;
67237 unsigned int elapsed_csecs;
67238 bool wakeup = false;
67239+ bool timedout = false;
67240
67241 do_gettimeofday(&start);
67242
67243@@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
67244
67245 while (true) {
67246 todo = 0;
67247+ if (time_after(jiffies, end_time))
67248+ timedout = true;
67249 read_lock(&tasklist_lock);
67250 do_each_thread(g, p) {
67251 if (p == current || !freeze_task(p))
67252@@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
67253 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
67254 * transition can't race with task state testing here.
67255 */
67256- if (!task_is_stopped_or_traced(p) &&
67257- !freezer_should_skip(p))
67258+ if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
67259 todo++;
67260+ if (timedout) {
67261+ printk(KERN_ERR "Task refusing to freeze:\n");
67262+ sched_show_task(p);
67263+ }
67264+ }
67265 } while_each_thread(g, p);
67266 read_unlock(&tasklist_lock);
67267
67268@@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
67269 todo += wq_busy;
67270 }
67271
67272- if (!todo || time_after(jiffies, end_time))
67273+ if (!todo || timedout)
67274 break;
67275
67276 if (pm_wakeup_pending()) {
67277diff --git a/kernel/printk.c b/kernel/printk.c
67278index b663c2c..1d6ba7a 100644
67279--- a/kernel/printk.c
67280+++ b/kernel/printk.c
67281@@ -316,6 +316,11 @@ static int check_syslog_permissions(int type, bool from_file)
67282 if (from_file && type != SYSLOG_ACTION_OPEN)
67283 return 0;
67284
67285+#ifdef CONFIG_GRKERNSEC_DMESG
67286+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
67287+ return -EPERM;
67288+#endif
67289+
67290 if (syslog_action_restricted(type)) {
67291 if (capable(CAP_SYSLOG))
67292 return 0;
67293diff --git a/kernel/profile.c b/kernel/profile.c
67294index 76b8e77..a2930e8 100644
67295--- a/kernel/profile.c
67296+++ b/kernel/profile.c
67297@@ -39,7 +39,7 @@ struct profile_hit {
67298 /* Oprofile timer tick hook */
67299 static int (*timer_hook)(struct pt_regs *) __read_mostly;
67300
67301-static atomic_t *prof_buffer;
67302+static atomic_unchecked_t *prof_buffer;
67303 static unsigned long prof_len, prof_shift;
67304
67305 int prof_on __read_mostly;
67306@@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
67307 hits[i].pc = 0;
67308 continue;
67309 }
67310- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
67311+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
67312 hits[i].hits = hits[i].pc = 0;
67313 }
67314 }
67315@@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
67316 * Add the current hit(s) and flush the write-queue out
67317 * to the global buffer:
67318 */
67319- atomic_add(nr_hits, &prof_buffer[pc]);
67320+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
67321 for (i = 0; i < NR_PROFILE_HIT; ++i) {
67322- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
67323+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
67324 hits[i].pc = hits[i].hits = 0;
67325 }
67326 out:
67327@@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
67328 {
67329 unsigned long pc;
67330 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
67331- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
67332+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
67333 }
67334 #endif /* !CONFIG_SMP */
67335
67336@@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
67337 return -EFAULT;
67338 buf++; p++; count--; read++;
67339 }
67340- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
67341+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
67342 if (copy_to_user(buf, (void *)pnt, count))
67343 return -EFAULT;
67344 read += count;
67345@@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
67346 }
67347 #endif
67348 profile_discard_flip_buffers();
67349- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
67350+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
67351 return count;
67352 }
67353
67354diff --git a/kernel/ptrace.c b/kernel/ptrace.c
67355index ee8d49b..bd3d790 100644
67356--- a/kernel/ptrace.c
67357+++ b/kernel/ptrace.c
67358@@ -280,7 +280,7 @@ static int ptrace_attach(struct task_struct *task, long request,
67359
67360 if (seize)
67361 flags |= PT_SEIZED;
67362- if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
67363+ if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
67364 flags |= PT_PTRACE_CAP;
67365 task->ptrace = flags;
67366
67367@@ -487,7 +487,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
67368 break;
67369 return -EIO;
67370 }
67371- if (copy_to_user(dst, buf, retval))
67372+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
67373 return -EFAULT;
67374 copied += retval;
67375 src += retval;
67376@@ -672,7 +672,7 @@ int ptrace_request(struct task_struct *child, long request,
67377 bool seized = child->ptrace & PT_SEIZED;
67378 int ret = -EIO;
67379 siginfo_t siginfo, *si;
67380- void __user *datavp = (void __user *) data;
67381+ void __user *datavp = (__force void __user *) data;
67382 unsigned long __user *datalp = datavp;
67383 unsigned long flags;
67384
67385@@ -874,14 +874,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
67386 goto out;
67387 }
67388
67389+ if (gr_handle_ptrace(child, request)) {
67390+ ret = -EPERM;
67391+ goto out_put_task_struct;
67392+ }
67393+
67394 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
67395 ret = ptrace_attach(child, request, addr, data);
67396 /*
67397 * Some architectures need to do book-keeping after
67398 * a ptrace attach.
67399 */
67400- if (!ret)
67401+ if (!ret) {
67402 arch_ptrace_attach(child);
67403+ gr_audit_ptrace(child);
67404+ }
67405 goto out_put_task_struct;
67406 }
67407
67408@@ -907,7 +914,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
67409 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
67410 if (copied != sizeof(tmp))
67411 return -EIO;
67412- return put_user(tmp, (unsigned long __user *)data);
67413+ return put_user(tmp, (__force unsigned long __user *)data);
67414 }
67415
67416 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
67417@@ -1017,14 +1024,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
67418 goto out;
67419 }
67420
67421+ if (gr_handle_ptrace(child, request)) {
67422+ ret = -EPERM;
67423+ goto out_put_task_struct;
67424+ }
67425+
67426 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
67427 ret = ptrace_attach(child, request, addr, data);
67428 /*
67429 * Some architectures need to do book-keeping after
67430 * a ptrace attach.
67431 */
67432- if (!ret)
67433+ if (!ret) {
67434 arch_ptrace_attach(child);
67435+ gr_audit_ptrace(child);
67436+ }
67437 goto out_put_task_struct;
67438 }
67439
67440diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
67441index 37a5444..eec170a 100644
67442--- a/kernel/rcutiny.c
67443+++ b/kernel/rcutiny.c
67444@@ -46,7 +46,7 @@
67445 struct rcu_ctrlblk;
67446 static void invoke_rcu_callbacks(void);
67447 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
67448-static void rcu_process_callbacks(struct softirq_action *unused);
67449+static void rcu_process_callbacks(void);
67450 static void __call_rcu(struct rcu_head *head,
67451 void (*func)(struct rcu_head *rcu),
67452 struct rcu_ctrlblk *rcp);
67453@@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
67454 rcu_is_callbacks_kthread()));
67455 }
67456
67457-static void rcu_process_callbacks(struct softirq_action *unused)
67458+static void rcu_process_callbacks(void)
67459 {
67460 __rcu_process_callbacks(&rcu_sched_ctrlblk);
67461 __rcu_process_callbacks(&rcu_bh_ctrlblk);
67462diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
67463index 22ecea0..3789898 100644
67464--- a/kernel/rcutiny_plugin.h
67465+++ b/kernel/rcutiny_plugin.h
67466@@ -955,7 +955,7 @@ static int rcu_kthread(void *arg)
67467 have_rcu_kthread_work = morework;
67468 local_irq_restore(flags);
67469 if (work)
67470- rcu_process_callbacks(NULL);
67471+ rcu_process_callbacks();
67472 schedule_timeout_interruptible(1); /* Leave CPU for others. */
67473 }
67474
67475diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
67476index a89b381..efdcad8 100644
67477--- a/kernel/rcutorture.c
67478+++ b/kernel/rcutorture.c
67479@@ -158,12 +158,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
67480 { 0 };
67481 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
67482 { 0 };
67483-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
67484-static atomic_t n_rcu_torture_alloc;
67485-static atomic_t n_rcu_torture_alloc_fail;
67486-static atomic_t n_rcu_torture_free;
67487-static atomic_t n_rcu_torture_mberror;
67488-static atomic_t n_rcu_torture_error;
67489+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
67490+static atomic_unchecked_t n_rcu_torture_alloc;
67491+static atomic_unchecked_t n_rcu_torture_alloc_fail;
67492+static atomic_unchecked_t n_rcu_torture_free;
67493+static atomic_unchecked_t n_rcu_torture_mberror;
67494+static atomic_unchecked_t n_rcu_torture_error;
67495 static long n_rcu_torture_boost_ktrerror;
67496 static long n_rcu_torture_boost_rterror;
67497 static long n_rcu_torture_boost_failure;
67498@@ -253,11 +253,11 @@ rcu_torture_alloc(void)
67499
67500 spin_lock_bh(&rcu_torture_lock);
67501 if (list_empty(&rcu_torture_freelist)) {
67502- atomic_inc(&n_rcu_torture_alloc_fail);
67503+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
67504 spin_unlock_bh(&rcu_torture_lock);
67505 return NULL;
67506 }
67507- atomic_inc(&n_rcu_torture_alloc);
67508+ atomic_inc_unchecked(&n_rcu_torture_alloc);
67509 p = rcu_torture_freelist.next;
67510 list_del_init(p);
67511 spin_unlock_bh(&rcu_torture_lock);
67512@@ -270,7 +270,7 @@ rcu_torture_alloc(void)
67513 static void
67514 rcu_torture_free(struct rcu_torture *p)
67515 {
67516- atomic_inc(&n_rcu_torture_free);
67517+ atomic_inc_unchecked(&n_rcu_torture_free);
67518 spin_lock_bh(&rcu_torture_lock);
67519 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
67520 spin_unlock_bh(&rcu_torture_lock);
67521@@ -390,7 +390,7 @@ rcu_torture_cb(struct rcu_head *p)
67522 i = rp->rtort_pipe_count;
67523 if (i > RCU_TORTURE_PIPE_LEN)
67524 i = RCU_TORTURE_PIPE_LEN;
67525- atomic_inc(&rcu_torture_wcount[i]);
67526+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
67527 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
67528 rp->rtort_mbtest = 0;
67529 rcu_torture_free(rp);
67530@@ -437,7 +437,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
67531 i = rp->rtort_pipe_count;
67532 if (i > RCU_TORTURE_PIPE_LEN)
67533 i = RCU_TORTURE_PIPE_LEN;
67534- atomic_inc(&rcu_torture_wcount[i]);
67535+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
67536 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
67537 rp->rtort_mbtest = 0;
67538 list_del(&rp->rtort_free);
67539@@ -926,7 +926,7 @@ rcu_torture_writer(void *arg)
67540 i = old_rp->rtort_pipe_count;
67541 if (i > RCU_TORTURE_PIPE_LEN)
67542 i = RCU_TORTURE_PIPE_LEN;
67543- atomic_inc(&rcu_torture_wcount[i]);
67544+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
67545 old_rp->rtort_pipe_count++;
67546 cur_ops->deferred_free(old_rp);
67547 }
67548@@ -1007,7 +1007,7 @@ static void rcu_torture_timer(unsigned long unused)
67549 }
67550 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
67551 if (p->rtort_mbtest == 0)
67552- atomic_inc(&n_rcu_torture_mberror);
67553+ atomic_inc_unchecked(&n_rcu_torture_mberror);
67554 spin_lock(&rand_lock);
67555 cur_ops->read_delay(&rand);
67556 n_rcu_torture_timers++;
67557@@ -1071,7 +1071,7 @@ rcu_torture_reader(void *arg)
67558 }
67559 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
67560 if (p->rtort_mbtest == 0)
67561- atomic_inc(&n_rcu_torture_mberror);
67562+ atomic_inc_unchecked(&n_rcu_torture_mberror);
67563 cur_ops->read_delay(&rand);
67564 preempt_disable();
67565 pipe_count = p->rtort_pipe_count;
67566@@ -1133,10 +1133,10 @@ rcu_torture_printk(char *page)
67567 rcu_torture_current,
67568 rcu_torture_current_version,
67569 list_empty(&rcu_torture_freelist),
67570- atomic_read(&n_rcu_torture_alloc),
67571- atomic_read(&n_rcu_torture_alloc_fail),
67572- atomic_read(&n_rcu_torture_free),
67573- atomic_read(&n_rcu_torture_mberror),
67574+ atomic_read_unchecked(&n_rcu_torture_alloc),
67575+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
67576+ atomic_read_unchecked(&n_rcu_torture_free),
67577+ atomic_read_unchecked(&n_rcu_torture_mberror),
67578 n_rcu_torture_boost_ktrerror,
67579 n_rcu_torture_boost_rterror,
67580 n_rcu_torture_boost_failure,
67581@@ -1146,7 +1146,7 @@ rcu_torture_printk(char *page)
67582 n_online_attempts,
67583 n_offline_successes,
67584 n_offline_attempts);
67585- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
67586+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
67587 n_rcu_torture_boost_ktrerror != 0 ||
67588 n_rcu_torture_boost_rterror != 0 ||
67589 n_rcu_torture_boost_failure != 0)
67590@@ -1154,7 +1154,7 @@ rcu_torture_printk(char *page)
67591 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
67592 if (i > 1) {
67593 cnt += sprintf(&page[cnt], "!!! ");
67594- atomic_inc(&n_rcu_torture_error);
67595+ atomic_inc_unchecked(&n_rcu_torture_error);
67596 WARN_ON_ONCE(1);
67597 }
67598 cnt += sprintf(&page[cnt], "Reader Pipe: ");
67599@@ -1168,7 +1168,7 @@ rcu_torture_printk(char *page)
67600 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
67601 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
67602 cnt += sprintf(&page[cnt], " %d",
67603- atomic_read(&rcu_torture_wcount[i]));
67604+ atomic_read_unchecked(&rcu_torture_wcount[i]));
67605 }
67606 cnt += sprintf(&page[cnt], "\n");
67607 if (cur_ops->stats)
67608@@ -1676,7 +1676,7 @@ rcu_torture_cleanup(void)
67609
67610 if (cur_ops->cleanup)
67611 cur_ops->cleanup();
67612- if (atomic_read(&n_rcu_torture_error))
67613+ if (atomic_read_unchecked(&n_rcu_torture_error))
67614 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
67615 else if (n_online_successes != n_online_attempts ||
67616 n_offline_successes != n_offline_attempts)
67617@@ -1744,17 +1744,17 @@ rcu_torture_init(void)
67618
67619 rcu_torture_current = NULL;
67620 rcu_torture_current_version = 0;
67621- atomic_set(&n_rcu_torture_alloc, 0);
67622- atomic_set(&n_rcu_torture_alloc_fail, 0);
67623- atomic_set(&n_rcu_torture_free, 0);
67624- atomic_set(&n_rcu_torture_mberror, 0);
67625- atomic_set(&n_rcu_torture_error, 0);
67626+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
67627+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
67628+ atomic_set_unchecked(&n_rcu_torture_free, 0);
67629+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
67630+ atomic_set_unchecked(&n_rcu_torture_error, 0);
67631 n_rcu_torture_boost_ktrerror = 0;
67632 n_rcu_torture_boost_rterror = 0;
67633 n_rcu_torture_boost_failure = 0;
67634 n_rcu_torture_boosts = 0;
67635 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
67636- atomic_set(&rcu_torture_wcount[i], 0);
67637+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
67638 for_each_possible_cpu(cpu) {
67639 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
67640 per_cpu(rcu_torture_count, cpu)[i] = 0;
67641diff --git a/kernel/rcutree.c b/kernel/rcutree.c
67642index d0c5baf..109b2e7 100644
67643--- a/kernel/rcutree.c
67644+++ b/kernel/rcutree.c
67645@@ -357,9 +357,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
67646 rcu_prepare_for_idle(smp_processor_id());
67647 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
67648 smp_mb__before_atomic_inc(); /* See above. */
67649- atomic_inc(&rdtp->dynticks);
67650+ atomic_inc_unchecked(&rdtp->dynticks);
67651 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
67652- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
67653+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
67654
67655 /*
67656 * The idle task is not permitted to enter the idle loop while
67657@@ -448,10 +448,10 @@ void rcu_irq_exit(void)
67658 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
67659 {
67660 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
67661- atomic_inc(&rdtp->dynticks);
67662+ atomic_inc_unchecked(&rdtp->dynticks);
67663 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
67664 smp_mb__after_atomic_inc(); /* See above. */
67665- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
67666+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
67667 rcu_cleanup_after_idle(smp_processor_id());
67668 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
67669 if (!is_idle_task(current)) {
67670@@ -545,14 +545,14 @@ void rcu_nmi_enter(void)
67671 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
67672
67673 if (rdtp->dynticks_nmi_nesting == 0 &&
67674- (atomic_read(&rdtp->dynticks) & 0x1))
67675+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
67676 return;
67677 rdtp->dynticks_nmi_nesting++;
67678 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
67679- atomic_inc(&rdtp->dynticks);
67680+ atomic_inc_unchecked(&rdtp->dynticks);
67681 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
67682 smp_mb__after_atomic_inc(); /* See above. */
67683- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
67684+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
67685 }
67686
67687 /**
67688@@ -571,9 +571,9 @@ void rcu_nmi_exit(void)
67689 return;
67690 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
67691 smp_mb__before_atomic_inc(); /* See above. */
67692- atomic_inc(&rdtp->dynticks);
67693+ atomic_inc_unchecked(&rdtp->dynticks);
67694 smp_mb__after_atomic_inc(); /* Force delay to next write. */
67695- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
67696+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
67697 }
67698
67699 #ifdef CONFIG_PROVE_RCU
67700@@ -589,7 +589,7 @@ int rcu_is_cpu_idle(void)
67701 int ret;
67702
67703 preempt_disable();
67704- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
67705+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
67706 preempt_enable();
67707 return ret;
67708 }
67709@@ -659,7 +659,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
67710 */
67711 static int dyntick_save_progress_counter(struct rcu_data *rdp)
67712 {
67713- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
67714+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
67715 return (rdp->dynticks_snap & 0x1) == 0;
67716 }
67717
67718@@ -674,7 +674,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
67719 unsigned int curr;
67720 unsigned int snap;
67721
67722- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
67723+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
67724 snap = (unsigned int)rdp->dynticks_snap;
67725
67726 /*
67727@@ -704,10 +704,10 @@ static int jiffies_till_stall_check(void)
67728 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
67729 */
67730 if (till_stall_check < 3) {
67731- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
67732+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
67733 till_stall_check = 3;
67734 } else if (till_stall_check > 300) {
67735- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
67736+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
67737 till_stall_check = 300;
67738 }
67739 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
67740@@ -1766,7 +1766,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
67741 /*
67742 * Do RCU core processing for the current CPU.
67743 */
67744-static void rcu_process_callbacks(struct softirq_action *unused)
67745+static void rcu_process_callbacks(void)
67746 {
67747 trace_rcu_utilization("Start RCU core");
67748 __rcu_process_callbacks(&rcu_sched_state,
67749@@ -1949,8 +1949,8 @@ void synchronize_rcu_bh(void)
67750 }
67751 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
67752
67753-static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
67754-static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
67755+static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
67756+static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
67757
67758 static int synchronize_sched_expedited_cpu_stop(void *data)
67759 {
67760@@ -2011,7 +2011,7 @@ void synchronize_sched_expedited(void)
67761 int firstsnap, s, snap, trycount = 0;
67762
67763 /* Note that atomic_inc_return() implies full memory barrier. */
67764- firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
67765+ firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
67766 get_online_cpus();
67767 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
67768
67769@@ -2033,7 +2033,7 @@ void synchronize_sched_expedited(void)
67770 }
67771
67772 /* Check to see if someone else did our work for us. */
67773- s = atomic_read(&sync_sched_expedited_done);
67774+ s = atomic_read_unchecked(&sync_sched_expedited_done);
67775 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
67776 smp_mb(); /* ensure test happens before caller kfree */
67777 return;
67778@@ -2048,7 +2048,7 @@ void synchronize_sched_expedited(void)
67779 * grace period works for us.
67780 */
67781 get_online_cpus();
67782- snap = atomic_read(&sync_sched_expedited_started);
67783+ snap = atomic_read_unchecked(&sync_sched_expedited_started);
67784 smp_mb(); /* ensure read is before try_stop_cpus(). */
67785 }
67786
67787@@ -2059,12 +2059,12 @@ void synchronize_sched_expedited(void)
67788 * than we did beat us to the punch.
67789 */
67790 do {
67791- s = atomic_read(&sync_sched_expedited_done);
67792+ s = atomic_read_unchecked(&sync_sched_expedited_done);
67793 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
67794 smp_mb(); /* ensure test happens before caller kfree */
67795 break;
67796 }
67797- } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
67798+ } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
67799
67800 put_online_cpus();
67801 }
67802@@ -2262,7 +2262,7 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
67803 rdp->qlen = 0;
67804 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
67805 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
67806- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
67807+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
67808 rdp->cpu = cpu;
67809 rdp->rsp = rsp;
67810 raw_spin_unlock_irqrestore(&rnp->lock, flags);
67811@@ -2290,8 +2290,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
67812 rdp->n_force_qs_snap = rsp->n_force_qs;
67813 rdp->blimit = blimit;
67814 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
67815- atomic_set(&rdp->dynticks->dynticks,
67816- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
67817+ atomic_set_unchecked(&rdp->dynticks->dynticks,
67818+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
67819 rcu_prepare_for_idle_init(cpu);
67820 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
67821
67822diff --git a/kernel/rcutree.h b/kernel/rcutree.h
67823index cdd1be0..5b2efb4 100644
67824--- a/kernel/rcutree.h
67825+++ b/kernel/rcutree.h
67826@@ -87,7 +87,7 @@ struct rcu_dynticks {
67827 long long dynticks_nesting; /* Track irq/process nesting level. */
67828 /* Process level is worth LLONG_MAX/2. */
67829 int dynticks_nmi_nesting; /* Track NMI nesting level. */
67830- atomic_t dynticks; /* Even value for idle, else odd. */
67831+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
67832 };
67833
67834 /* RCU's kthread states for tracing. */
67835diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
67836index c023464..7f57225 100644
67837--- a/kernel/rcutree_plugin.h
67838+++ b/kernel/rcutree_plugin.h
67839@@ -909,7 +909,7 @@ void synchronize_rcu_expedited(void)
67840
67841 /* Clean up and exit. */
67842 smp_mb(); /* ensure expedited GP seen before counter increment. */
67843- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
67844+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
67845 unlock_mb_ret:
67846 mutex_unlock(&sync_rcu_preempt_exp_mutex);
67847 mb_ret:
67848diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
67849index ed459ed..a03c3fa 100644
67850--- a/kernel/rcutree_trace.c
67851+++ b/kernel/rcutree_trace.c
67852@@ -68,7 +68,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
67853 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
67854 rdp->qs_pending);
67855 seq_printf(m, " dt=%d/%llx/%d df=%lu",
67856- atomic_read(&rdp->dynticks->dynticks),
67857+ atomic_read_unchecked(&rdp->dynticks->dynticks),
67858 rdp->dynticks->dynticks_nesting,
67859 rdp->dynticks->dynticks_nmi_nesting,
67860 rdp->dynticks_fqs);
67861@@ -140,7 +140,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
67862 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
67863 rdp->qs_pending);
67864 seq_printf(m, ",%d,%llx,%d,%lu",
67865- atomic_read(&rdp->dynticks->dynticks),
67866+ atomic_read_unchecked(&rdp->dynticks->dynticks),
67867 rdp->dynticks->dynticks_nesting,
67868 rdp->dynticks->dynticks_nmi_nesting,
67869 rdp->dynticks_fqs);
67870diff --git a/kernel/resource.c b/kernel/resource.c
67871index 7e8ea66..1efd11f 100644
67872--- a/kernel/resource.c
67873+++ b/kernel/resource.c
67874@@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
67875
67876 static int __init ioresources_init(void)
67877 {
67878+#ifdef CONFIG_GRKERNSEC_PROC_ADD
67879+#ifdef CONFIG_GRKERNSEC_PROC_USER
67880+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
67881+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
67882+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67883+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
67884+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
67885+#endif
67886+#else
67887 proc_create("ioports", 0, NULL, &proc_ioports_operations);
67888 proc_create("iomem", 0, NULL, &proc_iomem_operations);
67889+#endif
67890 return 0;
67891 }
67892 __initcall(ioresources_init);
67893diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
67894index 98ec494..4241d6d 100644
67895--- a/kernel/rtmutex-tester.c
67896+++ b/kernel/rtmutex-tester.c
67897@@ -20,7 +20,7 @@
67898 #define MAX_RT_TEST_MUTEXES 8
67899
67900 static spinlock_t rttest_lock;
67901-static atomic_t rttest_event;
67902+static atomic_unchecked_t rttest_event;
67903
67904 struct test_thread_data {
67905 int opcode;
67906@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67907
67908 case RTTEST_LOCKCONT:
67909 td->mutexes[td->opdata] = 1;
67910- td->event = atomic_add_return(1, &rttest_event);
67911+ td->event = atomic_add_return_unchecked(1, &rttest_event);
67912 return 0;
67913
67914 case RTTEST_RESET:
67915@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67916 return 0;
67917
67918 case RTTEST_RESETEVENT:
67919- atomic_set(&rttest_event, 0);
67920+ atomic_set_unchecked(&rttest_event, 0);
67921 return 0;
67922
67923 default:
67924@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67925 return ret;
67926
67927 td->mutexes[id] = 1;
67928- td->event = atomic_add_return(1, &rttest_event);
67929+ td->event = atomic_add_return_unchecked(1, &rttest_event);
67930 rt_mutex_lock(&mutexes[id]);
67931- td->event = atomic_add_return(1, &rttest_event);
67932+ td->event = atomic_add_return_unchecked(1, &rttest_event);
67933 td->mutexes[id] = 4;
67934 return 0;
67935
67936@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67937 return ret;
67938
67939 td->mutexes[id] = 1;
67940- td->event = atomic_add_return(1, &rttest_event);
67941+ td->event = atomic_add_return_unchecked(1, &rttest_event);
67942 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
67943- td->event = atomic_add_return(1, &rttest_event);
67944+ td->event = atomic_add_return_unchecked(1, &rttest_event);
67945 td->mutexes[id] = ret ? 0 : 4;
67946 return ret ? -EINTR : 0;
67947
67948@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67949 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
67950 return ret;
67951
67952- td->event = atomic_add_return(1, &rttest_event);
67953+ td->event = atomic_add_return_unchecked(1, &rttest_event);
67954 rt_mutex_unlock(&mutexes[id]);
67955- td->event = atomic_add_return(1, &rttest_event);
67956+ td->event = atomic_add_return_unchecked(1, &rttest_event);
67957 td->mutexes[id] = 0;
67958 return 0;
67959
67960@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
67961 break;
67962
67963 td->mutexes[dat] = 2;
67964- td->event = atomic_add_return(1, &rttest_event);
67965+ td->event = atomic_add_return_unchecked(1, &rttest_event);
67966 break;
67967
67968 default:
67969@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
67970 return;
67971
67972 td->mutexes[dat] = 3;
67973- td->event = atomic_add_return(1, &rttest_event);
67974+ td->event = atomic_add_return_unchecked(1, &rttest_event);
67975 break;
67976
67977 case RTTEST_LOCKNOWAIT:
67978@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
67979 return;
67980
67981 td->mutexes[dat] = 1;
67982- td->event = atomic_add_return(1, &rttest_event);
67983+ td->event = atomic_add_return_unchecked(1, &rttest_event);
67984 return;
67985
67986 default:
67987diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
67988index 0984a21..939f183 100644
67989--- a/kernel/sched/auto_group.c
67990+++ b/kernel/sched/auto_group.c
67991@@ -11,7 +11,7 @@
67992
67993 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
67994 static struct autogroup autogroup_default;
67995-static atomic_t autogroup_seq_nr;
67996+static atomic_unchecked_t autogroup_seq_nr;
67997
67998 void __init autogroup_init(struct task_struct *init_task)
67999 {
68000@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
68001
68002 kref_init(&ag->kref);
68003 init_rwsem(&ag->lock);
68004- ag->id = atomic_inc_return(&autogroup_seq_nr);
68005+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
68006 ag->tg = tg;
68007 #ifdef CONFIG_RT_GROUP_SCHED
68008 /*
68009diff --git a/kernel/sched/core.c b/kernel/sched/core.c
68010index 2000e06..79cf3d8 100644
68011--- a/kernel/sched/core.c
68012+++ b/kernel/sched/core.c
68013@@ -3907,6 +3907,8 @@ int can_nice(const struct task_struct *p, const int nice)
68014 /* convert nice value [19,-20] to rlimit style value [1,40] */
68015 int nice_rlim = 20 - nice;
68016
68017+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
68018+
68019 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
68020 capable(CAP_SYS_NICE));
68021 }
68022@@ -3940,7 +3942,8 @@ SYSCALL_DEFINE1(nice, int, increment)
68023 if (nice > 19)
68024 nice = 19;
68025
68026- if (increment < 0 && !can_nice(current, nice))
68027+ if (increment < 0 && (!can_nice(current, nice) ||
68028+ gr_handle_chroot_nice()))
68029 return -EPERM;
68030
68031 retval = security_task_setnice(current, nice);
68032@@ -4097,6 +4100,7 @@ recheck:
68033 unsigned long rlim_rtprio =
68034 task_rlimit(p, RLIMIT_RTPRIO);
68035
68036+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
68037 /* can't set/change the rt policy */
68038 if (policy != p->policy && !rlim_rtprio)
68039 return -EPERM;
68040diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
68041index e955364..eacd2a4 100644
68042--- a/kernel/sched/fair.c
68043+++ b/kernel/sched/fair.c
68044@@ -5107,7 +5107,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
68045 * run_rebalance_domains is triggered when needed from the scheduler tick.
68046 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
68047 */
68048-static void run_rebalance_domains(struct softirq_action *h)
68049+static void run_rebalance_domains(void)
68050 {
68051 int this_cpu = smp_processor_id();
68052 struct rq *this_rq = cpu_rq(this_cpu);
68053diff --git a/kernel/signal.c b/kernel/signal.c
68054index 17afcaf..4500b05 100644
68055--- a/kernel/signal.c
68056+++ b/kernel/signal.c
68057@@ -47,12 +47,12 @@ static struct kmem_cache *sigqueue_cachep;
68058
68059 int print_fatal_signals __read_mostly;
68060
68061-static void __user *sig_handler(struct task_struct *t, int sig)
68062+static __sighandler_t sig_handler(struct task_struct *t, int sig)
68063 {
68064 return t->sighand->action[sig - 1].sa.sa_handler;
68065 }
68066
68067-static int sig_handler_ignored(void __user *handler, int sig)
68068+static int sig_handler_ignored(__sighandler_t handler, int sig)
68069 {
68070 /* Is it explicitly or implicitly ignored? */
68071 return handler == SIG_IGN ||
68072@@ -61,7 +61,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
68073
68074 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
68075 {
68076- void __user *handler;
68077+ __sighandler_t handler;
68078
68079 handler = sig_handler(t, sig);
68080
68081@@ -365,6 +365,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
68082 atomic_inc(&user->sigpending);
68083 rcu_read_unlock();
68084
68085+ if (!override_rlimit)
68086+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
68087+
68088 if (override_rlimit ||
68089 atomic_read(&user->sigpending) <=
68090 task_rlimit(t, RLIMIT_SIGPENDING)) {
68091@@ -489,7 +492,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
68092
68093 int unhandled_signal(struct task_struct *tsk, int sig)
68094 {
68095- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
68096+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
68097 if (is_global_init(tsk))
68098 return 1;
68099 if (handler != SIG_IGN && handler != SIG_DFL)
68100@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
68101 }
68102 }
68103
68104+ /* allow glibc communication via tgkill to other threads in our
68105+ thread group */
68106+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
68107+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
68108+ && gr_handle_signal(t, sig))
68109+ return -EPERM;
68110+
68111 return security_task_kill(t, info, sig, 0);
68112 }
68113
68114@@ -1204,7 +1214,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
68115 return send_signal(sig, info, p, 1);
68116 }
68117
68118-static int
68119+int
68120 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68121 {
68122 return send_signal(sig, info, t, 0);
68123@@ -1241,6 +1251,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68124 unsigned long int flags;
68125 int ret, blocked, ignored;
68126 struct k_sigaction *action;
68127+ int is_unhandled = 0;
68128
68129 spin_lock_irqsave(&t->sighand->siglock, flags);
68130 action = &t->sighand->action[sig-1];
68131@@ -1255,9 +1266,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68132 }
68133 if (action->sa.sa_handler == SIG_DFL)
68134 t->signal->flags &= ~SIGNAL_UNKILLABLE;
68135+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
68136+ is_unhandled = 1;
68137 ret = specific_send_sig_info(sig, info, t);
68138 spin_unlock_irqrestore(&t->sighand->siglock, flags);
68139
68140+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
68141+ normal operation */
68142+ if (is_unhandled) {
68143+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
68144+ gr_handle_crash(t, sig);
68145+ }
68146+
68147 return ret;
68148 }
68149
68150@@ -1324,8 +1344,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
68151 ret = check_kill_permission(sig, info, p);
68152 rcu_read_unlock();
68153
68154- if (!ret && sig)
68155+ if (!ret && sig) {
68156 ret = do_send_sig_info(sig, info, p, true);
68157+ if (!ret)
68158+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
68159+ }
68160
68161 return ret;
68162 }
68163@@ -2840,7 +2863,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
68164 int error = -ESRCH;
68165
68166 rcu_read_lock();
68167- p = find_task_by_vpid(pid);
68168+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68169+ /* allow glibc communication via tgkill to other threads in our
68170+ thread group */
68171+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
68172+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
68173+ p = find_task_by_vpid_unrestricted(pid);
68174+ else
68175+#endif
68176+ p = find_task_by_vpid(pid);
68177 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
68178 error = check_kill_permission(sig, info, p);
68179 /*
68180diff --git a/kernel/smp.c b/kernel/smp.c
68181index 2f8b10e..a41bc14 100644
68182--- a/kernel/smp.c
68183+++ b/kernel/smp.c
68184@@ -580,22 +580,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
68185 }
68186 EXPORT_SYMBOL(smp_call_function);
68187
68188-void ipi_call_lock(void)
68189+void ipi_call_lock(void) __acquires(call_function.lock)
68190 {
68191 raw_spin_lock(&call_function.lock);
68192 }
68193
68194-void ipi_call_unlock(void)
68195+void ipi_call_unlock(void) __releases(call_function.lock)
68196 {
68197 raw_spin_unlock(&call_function.lock);
68198 }
68199
68200-void ipi_call_lock_irq(void)
68201+void ipi_call_lock_irq(void) __acquires(call_function.lock)
68202 {
68203 raw_spin_lock_irq(&call_function.lock);
68204 }
68205
68206-void ipi_call_unlock_irq(void)
68207+void ipi_call_unlock_irq(void) __releases(call_function.lock)
68208 {
68209 raw_spin_unlock_irq(&call_function.lock);
68210 }
68211diff --git a/kernel/softirq.c b/kernel/softirq.c
68212index 671f959..91c51cb 100644
68213--- a/kernel/softirq.c
68214+++ b/kernel/softirq.c
68215@@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
68216
68217 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
68218
68219-char *softirq_to_name[NR_SOFTIRQS] = {
68220+const char * const softirq_to_name[NR_SOFTIRQS] = {
68221 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
68222 "TASKLET", "SCHED", "HRTIMER", "RCU"
68223 };
68224@@ -235,7 +235,7 @@ restart:
68225 kstat_incr_softirqs_this_cpu(vec_nr);
68226
68227 trace_softirq_entry(vec_nr);
68228- h->action(h);
68229+ h->action();
68230 trace_softirq_exit(vec_nr);
68231 if (unlikely(prev_count != preempt_count())) {
68232 printk(KERN_ERR "huh, entered softirq %u %s %p"
68233@@ -381,9 +381,11 @@ void __raise_softirq_irqoff(unsigned int nr)
68234 or_softirq_pending(1UL << nr);
68235 }
68236
68237-void open_softirq(int nr, void (*action)(struct softirq_action *))
68238+void open_softirq(int nr, void (*action)(void))
68239 {
68240- softirq_vec[nr].action = action;
68241+ pax_open_kernel();
68242+ *(void **)&softirq_vec[nr].action = action;
68243+ pax_close_kernel();
68244 }
68245
68246 /*
68247@@ -437,7 +439,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
68248
68249 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
68250
68251-static void tasklet_action(struct softirq_action *a)
68252+static void tasklet_action(void)
68253 {
68254 struct tasklet_struct *list;
68255
68256@@ -472,7 +474,7 @@ static void tasklet_action(struct softirq_action *a)
68257 }
68258 }
68259
68260-static void tasklet_hi_action(struct softirq_action *a)
68261+static void tasklet_hi_action(void)
68262 {
68263 struct tasklet_struct *list;
68264
68265diff --git a/kernel/sys.c b/kernel/sys.c
68266index e7006eb..8fb7c51 100644
68267--- a/kernel/sys.c
68268+++ b/kernel/sys.c
68269@@ -158,6 +158,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
68270 error = -EACCES;
68271 goto out;
68272 }
68273+
68274+ if (gr_handle_chroot_setpriority(p, niceval)) {
68275+ error = -EACCES;
68276+ goto out;
68277+ }
68278+
68279 no_nice = security_task_setnice(p, niceval);
68280 if (no_nice) {
68281 error = no_nice;
68282@@ -581,6 +587,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
68283 goto error;
68284 }
68285
68286+ if (gr_check_group_change(new->gid, new->egid, -1))
68287+ goto error;
68288+
68289 if (rgid != (gid_t) -1 ||
68290 (egid != (gid_t) -1 && egid != old->gid))
68291 new->sgid = new->egid;
68292@@ -610,6 +619,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
68293 old = current_cred();
68294
68295 retval = -EPERM;
68296+
68297+ if (gr_check_group_change(gid, gid, gid))
68298+ goto error;
68299+
68300 if (nsown_capable(CAP_SETGID))
68301 new->gid = new->egid = new->sgid = new->fsgid = gid;
68302 else if (gid == old->gid || gid == old->sgid)
68303@@ -627,7 +640,7 @@ error:
68304 /*
68305 * change the user struct in a credentials set to match the new UID
68306 */
68307-static int set_user(struct cred *new)
68308+int set_user(struct cred *new)
68309 {
68310 struct user_struct *new_user;
68311
68312@@ -697,6 +710,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
68313 goto error;
68314 }
68315
68316+ if (gr_check_user_change(new->uid, new->euid, -1))
68317+ goto error;
68318+
68319 if (new->uid != old->uid) {
68320 retval = set_user(new);
68321 if (retval < 0)
68322@@ -741,6 +757,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
68323 old = current_cred();
68324
68325 retval = -EPERM;
68326+
68327+ if (gr_check_crash_uid(uid))
68328+ goto error;
68329+ if (gr_check_user_change(uid, uid, uid))
68330+ goto error;
68331+
68332 if (nsown_capable(CAP_SETUID)) {
68333 new->suid = new->uid = uid;
68334 if (uid != old->uid) {
68335@@ -795,6 +817,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
68336 goto error;
68337 }
68338
68339+ if (gr_check_user_change(ruid, euid, -1))
68340+ goto error;
68341+
68342 if (ruid != (uid_t) -1) {
68343 new->uid = ruid;
68344 if (ruid != old->uid) {
68345@@ -859,6 +884,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
68346 goto error;
68347 }
68348
68349+ if (gr_check_group_change(rgid, egid, -1))
68350+ goto error;
68351+
68352 if (rgid != (gid_t) -1)
68353 new->gid = rgid;
68354 if (egid != (gid_t) -1)
68355@@ -905,6 +933,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
68356 old = current_cred();
68357 old_fsuid = old->fsuid;
68358
68359+ if (gr_check_user_change(-1, -1, uid))
68360+ goto error;
68361+
68362 if (uid == old->uid || uid == old->euid ||
68363 uid == old->suid || uid == old->fsuid ||
68364 nsown_capable(CAP_SETUID)) {
68365@@ -915,6 +946,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
68366 }
68367 }
68368
68369+error:
68370 abort_creds(new);
68371 return old_fsuid;
68372
68373@@ -941,12 +973,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
68374 if (gid == old->gid || gid == old->egid ||
68375 gid == old->sgid || gid == old->fsgid ||
68376 nsown_capable(CAP_SETGID)) {
68377+ if (gr_check_group_change(-1, -1, gid))
68378+ goto error;
68379+
68380 if (gid != old_fsgid) {
68381 new->fsgid = gid;
68382 goto change_okay;
68383 }
68384 }
68385
68386+error:
68387 abort_creds(new);
68388 return old_fsgid;
68389
68390@@ -1198,7 +1234,10 @@ static int override_release(char __user *release, int len)
68391 }
68392 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
68393 snprintf(buf, len, "2.6.%u%s", v, rest);
68394- ret = copy_to_user(release, buf, len);
68395+ if (len > sizeof(buf))
68396+ ret = -EFAULT;
68397+ else
68398+ ret = copy_to_user(release, buf, len);
68399 }
68400 return ret;
68401 }
68402@@ -1252,19 +1291,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
68403 return -EFAULT;
68404
68405 down_read(&uts_sem);
68406- error = __copy_to_user(&name->sysname, &utsname()->sysname,
68407+ error = __copy_to_user(name->sysname, &utsname()->sysname,
68408 __OLD_UTS_LEN);
68409 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
68410- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
68411+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
68412 __OLD_UTS_LEN);
68413 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
68414- error |= __copy_to_user(&name->release, &utsname()->release,
68415+ error |= __copy_to_user(name->release, &utsname()->release,
68416 __OLD_UTS_LEN);
68417 error |= __put_user(0, name->release + __OLD_UTS_LEN);
68418- error |= __copy_to_user(&name->version, &utsname()->version,
68419+ error |= __copy_to_user(name->version, &utsname()->version,
68420 __OLD_UTS_LEN);
68421 error |= __put_user(0, name->version + __OLD_UTS_LEN);
68422- error |= __copy_to_user(&name->machine, &utsname()->machine,
68423+ error |= __copy_to_user(name->machine, &utsname()->machine,
68424 __OLD_UTS_LEN);
68425 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
68426 up_read(&uts_sem);
68427@@ -1847,7 +1886,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
68428 error = get_dumpable(me->mm);
68429 break;
68430 case PR_SET_DUMPABLE:
68431- if (arg2 < 0 || arg2 > 1) {
68432+ if (arg2 > 1) {
68433 error = -EINVAL;
68434 break;
68435 }
68436diff --git a/kernel/sysctl.c b/kernel/sysctl.c
68437index 4ab1187..0b75ced 100644
68438--- a/kernel/sysctl.c
68439+++ b/kernel/sysctl.c
68440@@ -91,7 +91,6 @@
68441
68442
68443 #if defined(CONFIG_SYSCTL)
68444-
68445 /* External variables not in a header file. */
68446 extern int sysctl_overcommit_memory;
68447 extern int sysctl_overcommit_ratio;
68448@@ -169,10 +168,8 @@ static int proc_taint(struct ctl_table *table, int write,
68449 void __user *buffer, size_t *lenp, loff_t *ppos);
68450 #endif
68451
68452-#ifdef CONFIG_PRINTK
68453 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
68454 void __user *buffer, size_t *lenp, loff_t *ppos);
68455-#endif
68456
68457 #ifdef CONFIG_MAGIC_SYSRQ
68458 /* Note: sysrq code uses it's own private copy */
68459@@ -196,6 +193,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
68460
68461 #endif
68462
68463+extern struct ctl_table grsecurity_table[];
68464+
68465 static struct ctl_table kern_table[];
68466 static struct ctl_table vm_table[];
68467 static struct ctl_table fs_table[];
68468@@ -210,6 +209,20 @@ extern struct ctl_table epoll_table[];
68469 int sysctl_legacy_va_layout;
68470 #endif
68471
68472+#ifdef CONFIG_PAX_SOFTMODE
68473+static ctl_table pax_table[] = {
68474+ {
68475+ .procname = "softmode",
68476+ .data = &pax_softmode,
68477+ .maxlen = sizeof(unsigned int),
68478+ .mode = 0600,
68479+ .proc_handler = &proc_dointvec,
68480+ },
68481+
68482+ { }
68483+};
68484+#endif
68485+
68486 /* The default sysctl tables: */
68487
68488 static struct ctl_table sysctl_base_table[] = {
68489@@ -256,6 +269,22 @@ static int max_extfrag_threshold = 1000;
68490 #endif
68491
68492 static struct ctl_table kern_table[] = {
68493+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
68494+ {
68495+ .procname = "grsecurity",
68496+ .mode = 0500,
68497+ .child = grsecurity_table,
68498+ },
68499+#endif
68500+
68501+#ifdef CONFIG_PAX_SOFTMODE
68502+ {
68503+ .procname = "pax",
68504+ .mode = 0500,
68505+ .child = pax_table,
68506+ },
68507+#endif
68508+
68509 {
68510 .procname = "sched_child_runs_first",
68511 .data = &sysctl_sched_child_runs_first,
68512@@ -540,7 +569,7 @@ static struct ctl_table kern_table[] = {
68513 .data = &modprobe_path,
68514 .maxlen = KMOD_PATH_LEN,
68515 .mode = 0644,
68516- .proc_handler = proc_dostring,
68517+ .proc_handler = proc_dostring_modpriv,
68518 },
68519 {
68520 .procname = "modules_disabled",
68521@@ -707,16 +736,20 @@ static struct ctl_table kern_table[] = {
68522 .extra1 = &zero,
68523 .extra2 = &one,
68524 },
68525+#endif
68526 {
68527 .procname = "kptr_restrict",
68528 .data = &kptr_restrict,
68529 .maxlen = sizeof(int),
68530 .mode = 0644,
68531 .proc_handler = proc_dointvec_minmax_sysadmin,
68532+#ifdef CONFIG_GRKERNSEC_HIDESYM
68533+ .extra1 = &two,
68534+#else
68535 .extra1 = &zero,
68536+#endif
68537 .extra2 = &two,
68538 },
68539-#endif
68540 {
68541 .procname = "ngroups_max",
68542 .data = &ngroups_max,
68543@@ -1215,6 +1248,13 @@ static struct ctl_table vm_table[] = {
68544 .proc_handler = proc_dointvec_minmax,
68545 .extra1 = &zero,
68546 },
68547+ {
68548+ .procname = "heap_stack_gap",
68549+ .data = &sysctl_heap_stack_gap,
68550+ .maxlen = sizeof(sysctl_heap_stack_gap),
68551+ .mode = 0644,
68552+ .proc_handler = proc_doulongvec_minmax,
68553+ },
68554 #else
68555 {
68556 .procname = "nr_trim_pages",
68557@@ -1645,6 +1685,16 @@ int proc_dostring(struct ctl_table *table, int write,
68558 buffer, lenp, ppos);
68559 }
68560
68561+int proc_dostring_modpriv(struct ctl_table *table, int write,
68562+ void __user *buffer, size_t *lenp, loff_t *ppos)
68563+{
68564+ if (write && !capable(CAP_SYS_MODULE))
68565+ return -EPERM;
68566+
68567+ return _proc_do_string(table->data, table->maxlen, write,
68568+ buffer, lenp, ppos);
68569+}
68570+
68571 static size_t proc_skip_spaces(char **buf)
68572 {
68573 size_t ret;
68574@@ -1750,6 +1800,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
68575 len = strlen(tmp);
68576 if (len > *size)
68577 len = *size;
68578+ if (len > sizeof(tmp))
68579+ len = sizeof(tmp);
68580 if (copy_to_user(*buf, tmp, len))
68581 return -EFAULT;
68582 *size -= len;
68583@@ -1942,7 +1994,6 @@ static int proc_taint(struct ctl_table *table, int write,
68584 return err;
68585 }
68586
68587-#ifdef CONFIG_PRINTK
68588 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
68589 void __user *buffer, size_t *lenp, loff_t *ppos)
68590 {
68591@@ -1951,7 +2002,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
68592
68593 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
68594 }
68595-#endif
68596
68597 struct do_proc_dointvec_minmax_conv_param {
68598 int *min;
68599@@ -2066,8 +2116,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
68600 *i = val;
68601 } else {
68602 val = convdiv * (*i) / convmul;
68603- if (!first)
68604+ if (!first) {
68605 err = proc_put_char(&buffer, &left, '\t');
68606+ if (err)
68607+ break;
68608+ }
68609 err = proc_put_long(&buffer, &left, val, false);
68610 if (err)
68611 break;
68612@@ -2459,6 +2512,12 @@ int proc_dostring(struct ctl_table *table, int write,
68613 return -ENOSYS;
68614 }
68615
68616+int proc_dostring_modpriv(struct ctl_table *table, int write,
68617+ void __user *buffer, size_t *lenp, loff_t *ppos)
68618+{
68619+ return -ENOSYS;
68620+}
68621+
68622 int proc_dointvec(struct ctl_table *table, int write,
68623 void __user *buffer, size_t *lenp, loff_t *ppos)
68624 {
68625@@ -2515,5 +2574,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
68626 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
68627 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
68628 EXPORT_SYMBOL(proc_dostring);
68629+EXPORT_SYMBOL(proc_dostring_modpriv);
68630 EXPORT_SYMBOL(proc_doulongvec_minmax);
68631 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
68632diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
68633index a650694..aaeeb20 100644
68634--- a/kernel/sysctl_binary.c
68635+++ b/kernel/sysctl_binary.c
68636@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
68637 int i;
68638
68639 set_fs(KERNEL_DS);
68640- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
68641+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
68642 set_fs(old_fs);
68643 if (result < 0)
68644 goto out_kfree;
68645@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
68646 }
68647
68648 set_fs(KERNEL_DS);
68649- result = vfs_write(file, buffer, str - buffer, &pos);
68650+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
68651 set_fs(old_fs);
68652 if (result < 0)
68653 goto out_kfree;
68654@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
68655 int i;
68656
68657 set_fs(KERNEL_DS);
68658- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
68659+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
68660 set_fs(old_fs);
68661 if (result < 0)
68662 goto out_kfree;
68663@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
68664 }
68665
68666 set_fs(KERNEL_DS);
68667- result = vfs_write(file, buffer, str - buffer, &pos);
68668+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
68669 set_fs(old_fs);
68670 if (result < 0)
68671 goto out_kfree;
68672@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
68673 int i;
68674
68675 set_fs(KERNEL_DS);
68676- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
68677+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
68678 set_fs(old_fs);
68679 if (result < 0)
68680 goto out;
68681@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
68682 __le16 dnaddr;
68683
68684 set_fs(KERNEL_DS);
68685- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
68686+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
68687 set_fs(old_fs);
68688 if (result < 0)
68689 goto out;
68690@@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
68691 le16_to_cpu(dnaddr) & 0x3ff);
68692
68693 set_fs(KERNEL_DS);
68694- result = vfs_write(file, buf, len, &pos);
68695+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
68696 set_fs(old_fs);
68697 if (result < 0)
68698 goto out;
68699diff --git a/kernel/taskstats.c b/kernel/taskstats.c
68700index e660464..c8b9e67 100644
68701--- a/kernel/taskstats.c
68702+++ b/kernel/taskstats.c
68703@@ -27,9 +27,12 @@
68704 #include <linux/cgroup.h>
68705 #include <linux/fs.h>
68706 #include <linux/file.h>
68707+#include <linux/grsecurity.h>
68708 #include <net/genetlink.h>
68709 #include <linux/atomic.h>
68710
68711+extern int gr_is_taskstats_denied(int pid);
68712+
68713 /*
68714 * Maximum length of a cpumask that can be specified in
68715 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
68716@@ -556,6 +559,9 @@ err:
68717
68718 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
68719 {
68720+ if (gr_is_taskstats_denied(current->pid))
68721+ return -EACCES;
68722+
68723 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
68724 return cmd_attr_register_cpumask(info);
68725 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
68726diff --git a/kernel/time.c b/kernel/time.c
68727index ba744cf..267b7c5 100644
68728--- a/kernel/time.c
68729+++ b/kernel/time.c
68730@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
68731 return error;
68732
68733 if (tz) {
68734+ /* we log in do_settimeofday called below, so don't log twice
68735+ */
68736+ if (!tv)
68737+ gr_log_timechange();
68738+
68739 sys_tz = *tz;
68740 update_vsyscall_tz();
68741 if (firsttime) {
68742diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
68743index 8a538c5..def79d4 100644
68744--- a/kernel/time/alarmtimer.c
68745+++ b/kernel/time/alarmtimer.c
68746@@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
68747 struct platform_device *pdev;
68748 int error = 0;
68749 int i;
68750- struct k_clock alarm_clock = {
68751+ static struct k_clock alarm_clock = {
68752 .clock_getres = alarm_clock_getres,
68753 .clock_get = alarm_clock_get,
68754 .timer_create = alarm_timer_create,
68755diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
68756index f113755..ec24223 100644
68757--- a/kernel/time/tick-broadcast.c
68758+++ b/kernel/time/tick-broadcast.c
68759@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
68760 * then clear the broadcast bit.
68761 */
68762 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
68763- int cpu = smp_processor_id();
68764+ cpu = smp_processor_id();
68765
68766 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
68767 tick_broadcast_clear_oneshot(cpu);
68768diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
68769index d42574df..247414c 100644
68770--- a/kernel/time/timekeeping.c
68771+++ b/kernel/time/timekeeping.c
68772@@ -14,6 +14,7 @@
68773 #include <linux/init.h>
68774 #include <linux/mm.h>
68775 #include <linux/sched.h>
68776+#include <linux/grsecurity.h>
68777 #include <linux/syscore_ops.h>
68778 #include <linux/clocksource.h>
68779 #include <linux/jiffies.h>
68780@@ -373,6 +374,8 @@ int do_settimeofday(const struct timespec *tv)
68781 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
68782 return -EINVAL;
68783
68784+ gr_log_timechange();
68785+
68786 write_seqlock_irqsave(&timekeeper.lock, flags);
68787
68788 timekeeping_forward_now();
68789diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
68790index 3258455..f35227d 100644
68791--- a/kernel/time/timer_list.c
68792+++ b/kernel/time/timer_list.c
68793@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
68794
68795 static void print_name_offset(struct seq_file *m, void *sym)
68796 {
68797+#ifdef CONFIG_GRKERNSEC_HIDESYM
68798+ SEQ_printf(m, "<%p>", NULL);
68799+#else
68800 char symname[KSYM_NAME_LEN];
68801
68802 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
68803 SEQ_printf(m, "<%pK>", sym);
68804 else
68805 SEQ_printf(m, "%s", symname);
68806+#endif
68807 }
68808
68809 static void
68810@@ -112,7 +116,11 @@ next_one:
68811 static void
68812 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
68813 {
68814+#ifdef CONFIG_GRKERNSEC_HIDESYM
68815+ SEQ_printf(m, " .base: %p\n", NULL);
68816+#else
68817 SEQ_printf(m, " .base: %pK\n", base);
68818+#endif
68819 SEQ_printf(m, " .index: %d\n",
68820 base->index);
68821 SEQ_printf(m, " .resolution: %Lu nsecs\n",
68822@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
68823 {
68824 struct proc_dir_entry *pe;
68825
68826+#ifdef CONFIG_GRKERNSEC_PROC_ADD
68827+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
68828+#else
68829 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
68830+#endif
68831 if (!pe)
68832 return -ENOMEM;
68833 return 0;
68834diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
68835index 0b537f2..9e71eca 100644
68836--- a/kernel/time/timer_stats.c
68837+++ b/kernel/time/timer_stats.c
68838@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
68839 static unsigned long nr_entries;
68840 static struct entry entries[MAX_ENTRIES];
68841
68842-static atomic_t overflow_count;
68843+static atomic_unchecked_t overflow_count;
68844
68845 /*
68846 * The entries are in a hash-table, for fast lookup:
68847@@ -140,7 +140,7 @@ static void reset_entries(void)
68848 nr_entries = 0;
68849 memset(entries, 0, sizeof(entries));
68850 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
68851- atomic_set(&overflow_count, 0);
68852+ atomic_set_unchecked(&overflow_count, 0);
68853 }
68854
68855 static struct entry *alloc_entry(void)
68856@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
68857 if (likely(entry))
68858 entry->count++;
68859 else
68860- atomic_inc(&overflow_count);
68861+ atomic_inc_unchecked(&overflow_count);
68862
68863 out_unlock:
68864 raw_spin_unlock_irqrestore(lock, flags);
68865@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
68866
68867 static void print_name_offset(struct seq_file *m, unsigned long addr)
68868 {
68869+#ifdef CONFIG_GRKERNSEC_HIDESYM
68870+ seq_printf(m, "<%p>", NULL);
68871+#else
68872 char symname[KSYM_NAME_LEN];
68873
68874 if (lookup_symbol_name(addr, symname) < 0)
68875 seq_printf(m, "<%p>", (void *)addr);
68876 else
68877 seq_printf(m, "%s", symname);
68878+#endif
68879 }
68880
68881 static int tstats_show(struct seq_file *m, void *v)
68882@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
68883
68884 seq_puts(m, "Timer Stats Version: v0.2\n");
68885 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
68886- if (atomic_read(&overflow_count))
68887+ if (atomic_read_unchecked(&overflow_count))
68888 seq_printf(m, "Overflow: %d entries\n",
68889- atomic_read(&overflow_count));
68890+ atomic_read_unchecked(&overflow_count));
68891
68892 for (i = 0; i < nr_entries; i++) {
68893 entry = entries + i;
68894@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
68895 {
68896 struct proc_dir_entry *pe;
68897
68898+#ifdef CONFIG_GRKERNSEC_PROC_ADD
68899+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
68900+#else
68901 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
68902+#endif
68903 if (!pe)
68904 return -ENOMEM;
68905 return 0;
68906diff --git a/kernel/timer.c b/kernel/timer.c
68907index a297ffc..5e16b0b 100644
68908--- a/kernel/timer.c
68909+++ b/kernel/timer.c
68910@@ -1354,7 +1354,7 @@ void update_process_times(int user_tick)
68911 /*
68912 * This function runs timers and the timer-tq in bottom half context.
68913 */
68914-static void run_timer_softirq(struct softirq_action *h)
68915+static void run_timer_softirq(void)
68916 {
68917 struct tvec_base *base = __this_cpu_read(tvec_bases);
68918
68919diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
68920index c0bd030..62a1927 100644
68921--- a/kernel/trace/blktrace.c
68922+++ b/kernel/trace/blktrace.c
68923@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
68924 struct blk_trace *bt = filp->private_data;
68925 char buf[16];
68926
68927- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
68928+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
68929
68930 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
68931 }
68932@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
68933 return 1;
68934
68935 bt = buf->chan->private_data;
68936- atomic_inc(&bt->dropped);
68937+ atomic_inc_unchecked(&bt->dropped);
68938 return 0;
68939 }
68940
68941@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
68942
68943 bt->dir = dir;
68944 bt->dev = dev;
68945- atomic_set(&bt->dropped, 0);
68946+ atomic_set_unchecked(&bt->dropped, 0);
68947
68948 ret = -EIO;
68949 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
68950diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
68951index 0fa92f6..89950b2 100644
68952--- a/kernel/trace/ftrace.c
68953+++ b/kernel/trace/ftrace.c
68954@@ -1800,12 +1800,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
68955 if (unlikely(ftrace_disabled))
68956 return 0;
68957
68958+ ret = ftrace_arch_code_modify_prepare();
68959+ FTRACE_WARN_ON(ret);
68960+ if (ret)
68961+ return 0;
68962+
68963 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
68964+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
68965 if (ret) {
68966 ftrace_bug(ret, ip);
68967- return 0;
68968 }
68969- return 1;
68970+ return ret ? 0 : 1;
68971 }
68972
68973 /*
68974@@ -2917,7 +2922,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
68975
68976 int
68977 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
68978- void *data)
68979+ void *data)
68980 {
68981 struct ftrace_func_probe *entry;
68982 struct ftrace_page *pg;
68983diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
68984index 464a96f..bc0bd88 100644
68985--- a/kernel/trace/trace.c
68986+++ b/kernel/trace/trace.c
68987@@ -4312,10 +4312,9 @@ static const struct file_operations tracing_dyn_info_fops = {
68988 };
68989 #endif
68990
68991-static struct dentry *d_tracer;
68992-
68993 struct dentry *tracing_init_dentry(void)
68994 {
68995+ static struct dentry *d_tracer;
68996 static int once;
68997
68998 if (d_tracer)
68999@@ -4335,10 +4334,9 @@ struct dentry *tracing_init_dentry(void)
69000 return d_tracer;
69001 }
69002
69003-static struct dentry *d_percpu;
69004-
69005 struct dentry *tracing_dentry_percpu(void)
69006 {
69007+ static struct dentry *d_percpu;
69008 static int once;
69009 struct dentry *d_tracer;
69010
69011diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
69012index 29111da..d190fe2 100644
69013--- a/kernel/trace/trace_events.c
69014+++ b/kernel/trace/trace_events.c
69015@@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
69016 struct ftrace_module_file_ops {
69017 struct list_head list;
69018 struct module *mod;
69019- struct file_operations id;
69020- struct file_operations enable;
69021- struct file_operations format;
69022- struct file_operations filter;
69023 };
69024
69025 static struct ftrace_module_file_ops *
69026@@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
69027
69028 file_ops->mod = mod;
69029
69030- file_ops->id = ftrace_event_id_fops;
69031- file_ops->id.owner = mod;
69032-
69033- file_ops->enable = ftrace_enable_fops;
69034- file_ops->enable.owner = mod;
69035-
69036- file_ops->filter = ftrace_event_filter_fops;
69037- file_ops->filter.owner = mod;
69038-
69039- file_ops->format = ftrace_event_format_fops;
69040- file_ops->format.owner = mod;
69041+ pax_open_kernel();
69042+ *(void **)&mod->trace_id.owner = mod;
69043+ *(void **)&mod->trace_enable.owner = mod;
69044+ *(void **)&mod->trace_filter.owner = mod;
69045+ *(void **)&mod->trace_format.owner = mod;
69046+ pax_close_kernel();
69047
69048 list_add(&file_ops->list, &ftrace_module_file_list);
69049
69050@@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
69051
69052 for_each_event(call, start, end) {
69053 __trace_add_event_call(*call, mod,
69054- &file_ops->id, &file_ops->enable,
69055- &file_ops->filter, &file_ops->format);
69056+ &mod->trace_id, &mod->trace_enable,
69057+ &mod->trace_filter, &mod->trace_format);
69058 }
69059 }
69060
69061diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
69062index 580a05e..9b31acb 100644
69063--- a/kernel/trace/trace_kprobe.c
69064+++ b/kernel/trace/trace_kprobe.c
69065@@ -217,7 +217,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69066 long ret;
69067 int maxlen = get_rloc_len(*(u32 *)dest);
69068 u8 *dst = get_rloc_data(dest);
69069- u8 *src = addr;
69070+ const u8 __user *src = (const u8 __force_user *)addr;
69071 mm_segment_t old_fs = get_fs();
69072 if (!maxlen)
69073 return;
69074@@ -229,7 +229,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69075 pagefault_disable();
69076 do
69077 ret = __copy_from_user_inatomic(dst++, src++, 1);
69078- while (dst[-1] && ret == 0 && src - (u8 *)addr < maxlen);
69079+ while (dst[-1] && ret == 0 && src - (const u8 __force_user *)addr < maxlen);
69080 dst[-1] = '\0';
69081 pagefault_enable();
69082 set_fs(old_fs);
69083@@ -238,7 +238,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69084 ((u8 *)get_rloc_data(dest))[0] = '\0';
69085 *(u32 *)dest = make_data_rloc(0, get_rloc_offs(*(u32 *)dest));
69086 } else
69087- *(u32 *)dest = make_data_rloc(src - (u8 *)addr,
69088+ *(u32 *)dest = make_data_rloc(src - (const u8 __force_user *)addr,
69089 get_rloc_offs(*(u32 *)dest));
69090 }
69091 /* Return the length of string -- including null terminal byte */
69092@@ -252,7 +252,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string_size)(struct pt_regs *regs,
69093 set_fs(KERNEL_DS);
69094 pagefault_disable();
69095 do {
69096- ret = __copy_from_user_inatomic(&c, (u8 *)addr + len, 1);
69097+ ret = __copy_from_user_inatomic(&c, (const u8 __force_user *)addr + len, 1);
69098 len++;
69099 } while (c && ret == 0 && len < MAX_STRING_SIZE);
69100 pagefault_enable();
69101diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
69102index fd3c8aa..5f324a6 100644
69103--- a/kernel/trace/trace_mmiotrace.c
69104+++ b/kernel/trace/trace_mmiotrace.c
69105@@ -24,7 +24,7 @@ struct header_iter {
69106 static struct trace_array *mmio_trace_array;
69107 static bool overrun_detected;
69108 static unsigned long prev_overruns;
69109-static atomic_t dropped_count;
69110+static atomic_unchecked_t dropped_count;
69111
69112 static void mmio_reset_data(struct trace_array *tr)
69113 {
69114@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
69115
69116 static unsigned long count_overruns(struct trace_iterator *iter)
69117 {
69118- unsigned long cnt = atomic_xchg(&dropped_count, 0);
69119+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
69120 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
69121
69122 if (over > prev_overruns)
69123@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
69124 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
69125 sizeof(*entry), 0, pc);
69126 if (!event) {
69127- atomic_inc(&dropped_count);
69128+ atomic_inc_unchecked(&dropped_count);
69129 return;
69130 }
69131 entry = ring_buffer_event_data(event);
69132@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
69133 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
69134 sizeof(*entry), 0, pc);
69135 if (!event) {
69136- atomic_inc(&dropped_count);
69137+ atomic_inc_unchecked(&dropped_count);
69138 return;
69139 }
69140 entry = ring_buffer_event_data(event);
69141diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
69142index df611a0..10d8b32 100644
69143--- a/kernel/trace/trace_output.c
69144+++ b/kernel/trace/trace_output.c
69145@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
69146
69147 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
69148 if (!IS_ERR(p)) {
69149- p = mangle_path(s->buffer + s->len, p, "\n");
69150+ p = mangle_path(s->buffer + s->len, p, "\n\\");
69151 if (p) {
69152 s->len = p - s->buffer;
69153 return 1;
69154diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
69155index d4545f4..a9010a1 100644
69156--- a/kernel/trace/trace_stack.c
69157+++ b/kernel/trace/trace_stack.c
69158@@ -53,7 +53,7 @@ static inline void check_stack(void)
69159 return;
69160
69161 /* we do not handle interrupt stacks yet */
69162- if (!object_is_on_stack(&this_size))
69163+ if (!object_starts_on_stack(&this_size))
69164 return;
69165
69166 local_irq_save(flags);
69167diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c
69168index 209b379..7f76423 100644
69169--- a/kernel/trace/trace_workqueue.c
69170+++ b/kernel/trace/trace_workqueue.c
69171@@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
69172 int cpu;
69173 pid_t pid;
69174 /* Can be inserted from interrupt or user context, need to be atomic */
69175- atomic_t inserted;
69176+ atomic_unchecked_t inserted;
69177 /*
69178 * Don't need to be atomic, works are serialized in a single workqueue thread
69179 * on a single CPU.
69180@@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
69181 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
69182 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
69183 if (node->pid == wq_thread->pid) {
69184- atomic_inc(&node->inserted);
69185+ atomic_inc_unchecked(&node->inserted);
69186 goto found;
69187 }
69188 }
69189@@ -210,7 +210,7 @@ static int workqueue_stat_show(struct seq_file *s, void *p)
69190 tsk = get_pid_task(pid, PIDTYPE_PID);
69191 if (tsk) {
69192 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
69193- atomic_read(&cws->inserted), cws->executed,
69194+ atomic_read_unchecked(&cws->inserted), cws->executed,
69195 tsk->comm);
69196 put_task_struct(tsk);
69197 }
69198diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
69199index 6777153..8519f60 100644
69200--- a/lib/Kconfig.debug
69201+++ b/lib/Kconfig.debug
69202@@ -1132,6 +1132,7 @@ config LATENCYTOP
69203 depends on DEBUG_KERNEL
69204 depends on STACKTRACE_SUPPORT
69205 depends on PROC_FS
69206+ depends on !GRKERNSEC_HIDESYM
69207 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
69208 select KALLSYMS
69209 select KALLSYMS_ALL
69210diff --git a/lib/bitmap.c b/lib/bitmap.c
69211index b5a8b6a..a69623c 100644
69212--- a/lib/bitmap.c
69213+++ b/lib/bitmap.c
69214@@ -421,7 +421,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
69215 {
69216 int c, old_c, totaldigits, ndigits, nchunks, nbits;
69217 u32 chunk;
69218- const char __user __force *ubuf = (const char __user __force *)buf;
69219+ const char __user *ubuf = (const char __force_user *)buf;
69220
69221 bitmap_zero(maskp, nmaskbits);
69222
69223@@ -506,7 +506,7 @@ int bitmap_parse_user(const char __user *ubuf,
69224 {
69225 if (!access_ok(VERIFY_READ, ubuf, ulen))
69226 return -EFAULT;
69227- return __bitmap_parse((const char __force *)ubuf,
69228+ return __bitmap_parse((const char __force_kernel *)ubuf,
69229 ulen, 1, maskp, nmaskbits);
69230
69231 }
69232@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
69233 {
69234 unsigned a, b;
69235 int c, old_c, totaldigits;
69236- const char __user __force *ubuf = (const char __user __force *)buf;
69237+ const char __user *ubuf = (const char __force_user *)buf;
69238 int exp_digit, in_range;
69239
69240 totaldigits = c = 0;
69241@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
69242 {
69243 if (!access_ok(VERIFY_READ, ubuf, ulen))
69244 return -EFAULT;
69245- return __bitmap_parselist((const char __force *)ubuf,
69246+ return __bitmap_parselist((const char __force_kernel *)ubuf,
69247 ulen, 1, maskp, nmaskbits);
69248 }
69249 EXPORT_SYMBOL(bitmap_parselist_user);
69250diff --git a/lib/bug.c b/lib/bug.c
69251index a28c141..2bd3d95 100644
69252--- a/lib/bug.c
69253+++ b/lib/bug.c
69254@@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
69255 return BUG_TRAP_TYPE_NONE;
69256
69257 bug = find_bug(bugaddr);
69258+ if (!bug)
69259+ return BUG_TRAP_TYPE_NONE;
69260
69261 file = NULL;
69262 line = 0;
69263diff --git a/lib/debugobjects.c b/lib/debugobjects.c
69264index 0ab9ae8..f01ceca 100644
69265--- a/lib/debugobjects.c
69266+++ b/lib/debugobjects.c
69267@@ -288,7 +288,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
69268 if (limit > 4)
69269 return;
69270
69271- is_on_stack = object_is_on_stack(addr);
69272+ is_on_stack = object_starts_on_stack(addr);
69273 if (is_on_stack == onstack)
69274 return;
69275
69276diff --git a/lib/devres.c b/lib/devres.c
69277index 80b9c76..9e32279 100644
69278--- a/lib/devres.c
69279+++ b/lib/devres.c
69280@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
69281 void devm_iounmap(struct device *dev, void __iomem *addr)
69282 {
69283 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
69284- (void *)addr));
69285+ (void __force *)addr));
69286 iounmap(addr);
69287 }
69288 EXPORT_SYMBOL(devm_iounmap);
69289@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
69290 {
69291 ioport_unmap(addr);
69292 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
69293- devm_ioport_map_match, (void *)addr));
69294+ devm_ioport_map_match, (void __force *)addr));
69295 }
69296 EXPORT_SYMBOL(devm_ioport_unmap);
69297
69298diff --git a/lib/dma-debug.c b/lib/dma-debug.c
69299index 13ef233..5241683 100644
69300--- a/lib/dma-debug.c
69301+++ b/lib/dma-debug.c
69302@@ -924,7 +924,7 @@ out:
69303
69304 static void check_for_stack(struct device *dev, void *addr)
69305 {
69306- if (object_is_on_stack(addr))
69307+ if (object_starts_on_stack(addr))
69308 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
69309 "stack [addr=%p]\n", addr);
69310 }
69311diff --git a/lib/extable.c b/lib/extable.c
69312index 4cac81e..63e9b8f 100644
69313--- a/lib/extable.c
69314+++ b/lib/extable.c
69315@@ -13,6 +13,7 @@
69316 #include <linux/init.h>
69317 #include <linux/sort.h>
69318 #include <asm/uaccess.h>
69319+#include <asm/pgtable.h>
69320
69321 #ifndef ARCH_HAS_SORT_EXTABLE
69322 /*
69323@@ -36,8 +37,10 @@ static int cmp_ex(const void *a, const void *b)
69324 void sort_extable(struct exception_table_entry *start,
69325 struct exception_table_entry *finish)
69326 {
69327+ pax_open_kernel();
69328 sort(start, finish - start, sizeof(struct exception_table_entry),
69329 cmp_ex, NULL);
69330+ pax_close_kernel();
69331 }
69332
69333 #ifdef CONFIG_MODULES
69334diff --git a/lib/inflate.c b/lib/inflate.c
69335index 013a761..c28f3fc 100644
69336--- a/lib/inflate.c
69337+++ b/lib/inflate.c
69338@@ -269,7 +269,7 @@ static void free(void *where)
69339 malloc_ptr = free_mem_ptr;
69340 }
69341 #else
69342-#define malloc(a) kmalloc(a, GFP_KERNEL)
69343+#define malloc(a) kmalloc((a), GFP_KERNEL)
69344 #define free(a) kfree(a)
69345 #endif
69346
69347diff --git a/lib/ioremap.c b/lib/ioremap.c
69348index 0c9216c..863bd89 100644
69349--- a/lib/ioremap.c
69350+++ b/lib/ioremap.c
69351@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
69352 unsigned long next;
69353
69354 phys_addr -= addr;
69355- pmd = pmd_alloc(&init_mm, pud, addr);
69356+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
69357 if (!pmd)
69358 return -ENOMEM;
69359 do {
69360@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
69361 unsigned long next;
69362
69363 phys_addr -= addr;
69364- pud = pud_alloc(&init_mm, pgd, addr);
69365+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
69366 if (!pud)
69367 return -ENOMEM;
69368 do {
69369diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
69370index bd2bea9..6b3c95e 100644
69371--- a/lib/is_single_threaded.c
69372+++ b/lib/is_single_threaded.c
69373@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
69374 struct task_struct *p, *t;
69375 bool ret;
69376
69377+ if (!mm)
69378+ return true;
69379+
69380 if (atomic_read(&task->signal->live) != 1)
69381 return false;
69382
69383diff --git a/lib/radix-tree.c b/lib/radix-tree.c
69384index 3ac50dc..240bb7e 100644
69385--- a/lib/radix-tree.c
69386+++ b/lib/radix-tree.c
69387@@ -79,7 +79,7 @@ struct radix_tree_preload {
69388 int nr;
69389 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
69390 };
69391-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
69392+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
69393
69394 static inline void *ptr_to_indirect(void *ptr)
69395 {
69396diff --git a/lib/vsprintf.c b/lib/vsprintf.c
69397index abbabec..362988d 100644
69398--- a/lib/vsprintf.c
69399+++ b/lib/vsprintf.c
69400@@ -16,6 +16,9 @@
69401 * - scnprintf and vscnprintf
69402 */
69403
69404+#ifdef CONFIG_GRKERNSEC_HIDESYM
69405+#define __INCLUDED_BY_HIDESYM 1
69406+#endif
69407 #include <stdarg.h>
69408 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
69409 #include <linux/types.h>
69410@@ -433,7 +436,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
69411 char sym[KSYM_SYMBOL_LEN];
69412 if (ext == 'B')
69413 sprint_backtrace(sym, value);
69414- else if (ext != 'f' && ext != 's')
69415+ else if (ext != 'f' && ext != 's' && ext != 'a')
69416 sprint_symbol(sym, value);
69417 else
69418 kallsyms_lookup(value, NULL, NULL, NULL, sym);
69419@@ -809,7 +812,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
69420 return number(buf, end, *(const netdev_features_t *)addr, spec);
69421 }
69422
69423+#ifdef CONFIG_GRKERNSEC_HIDESYM
69424+int kptr_restrict __read_mostly = 2;
69425+#else
69426 int kptr_restrict __read_mostly;
69427+#endif
69428
69429 /*
69430 * Show a '%p' thing. A kernel extension is that the '%p' is followed
69431@@ -823,6 +830,8 @@ int kptr_restrict __read_mostly;
69432 * - 'S' For symbolic direct pointers with offset
69433 * - 's' For symbolic direct pointers without offset
69434 * - 'B' For backtraced symbolic direct pointers with offset
69435+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
69436+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
69437 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
69438 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
69439 * - 'M' For a 6-byte MAC address, it prints the address in the
69440@@ -868,12 +877,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
69441 {
69442 if (!ptr && *fmt != 'K') {
69443 /*
69444- * Print (null) with the same width as a pointer so it makes
69445+ * Print (nil) with the same width as a pointer so it makes
69446 * tabular output look nice.
69447 */
69448 if (spec.field_width == -1)
69449 spec.field_width = 2 * sizeof(void *);
69450- return string(buf, end, "(null)", spec);
69451+ return string(buf, end, "(nil)", spec);
69452 }
69453
69454 switch (*fmt) {
69455@@ -883,6 +892,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
69456 /* Fallthrough */
69457 case 'S':
69458 case 's':
69459+#ifdef CONFIG_GRKERNSEC_HIDESYM
69460+ break;
69461+#else
69462+ return symbol_string(buf, end, ptr, spec, *fmt);
69463+#endif
69464+ case 'A':
69465+ case 'a':
69466 case 'B':
69467 return symbol_string(buf, end, ptr, spec, *fmt);
69468 case 'R':
69469@@ -1653,11 +1669,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
69470 typeof(type) value; \
69471 if (sizeof(type) == 8) { \
69472 args = PTR_ALIGN(args, sizeof(u32)); \
69473- *(u32 *)&value = *(u32 *)args; \
69474- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
69475+ *(u32 *)&value = *(const u32 *)args; \
69476+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
69477 } else { \
69478 args = PTR_ALIGN(args, sizeof(type)); \
69479- value = *(typeof(type) *)args; \
69480+ value = *(const typeof(type) *)args; \
69481 } \
69482 args += sizeof(type); \
69483 value; \
69484@@ -1720,7 +1736,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
69485 case FORMAT_TYPE_STR: {
69486 const char *str_arg = args;
69487 args += strlen(str_arg) + 1;
69488- str = string(str, end, (char *)str_arg, spec);
69489+ str = string(str, end, str_arg, spec);
69490 break;
69491 }
69492
69493diff --git a/localversion-grsec b/localversion-grsec
69494new file mode 100644
69495index 0000000..7cd6065
69496--- /dev/null
69497+++ b/localversion-grsec
69498@@ -0,0 +1 @@
69499+-grsec
69500diff --git a/mm/Kconfig b/mm/Kconfig
69501index e338407..4210331 100644
69502--- a/mm/Kconfig
69503+++ b/mm/Kconfig
69504@@ -247,10 +247,10 @@ config KSM
69505 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
69506
69507 config DEFAULT_MMAP_MIN_ADDR
69508- int "Low address space to protect from user allocation"
69509+ int "Low address space to protect from user allocation"
69510 depends on MMU
69511- default 4096
69512- help
69513+ default 65536
69514+ help
69515 This is the portion of low virtual memory which should be protected
69516 from userspace allocation. Keeping a user from writing to low pages
69517 can help reduce the impact of kernel NULL pointer bugs.
69518@@ -280,7 +280,7 @@ config MEMORY_FAILURE
69519
69520 config HWPOISON_INJECT
69521 tristate "HWPoison pages injector"
69522- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
69523+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
69524 select PROC_PAGE_MONITOR
69525
69526 config NOMMU_INITIAL_TRIM_EXCESS
69527diff --git a/mm/filemap.c b/mm/filemap.c
69528index 79c4b2b..596b417 100644
69529--- a/mm/filemap.c
69530+++ b/mm/filemap.c
69531@@ -1762,7 +1762,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
69532 struct address_space *mapping = file->f_mapping;
69533
69534 if (!mapping->a_ops->readpage)
69535- return -ENOEXEC;
69536+ return -ENODEV;
69537 file_accessed(file);
69538 vma->vm_ops = &generic_file_vm_ops;
69539 vma->vm_flags |= VM_CAN_NONLINEAR;
69540@@ -2168,6 +2168,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
69541 *pos = i_size_read(inode);
69542
69543 if (limit != RLIM_INFINITY) {
69544+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
69545 if (*pos >= limit) {
69546 send_sig(SIGXFSZ, current, 0);
69547 return -EFBIG;
69548diff --git a/mm/fremap.c b/mm/fremap.c
69549index 9ed4fd4..c42648d 100644
69550--- a/mm/fremap.c
69551+++ b/mm/fremap.c
69552@@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
69553 retry:
69554 vma = find_vma(mm, start);
69555
69556+#ifdef CONFIG_PAX_SEGMEXEC
69557+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
69558+ goto out;
69559+#endif
69560+
69561 /*
69562 * Make sure the vma is shared, that it supports prefaulting,
69563 * and that the remapped range is valid and fully within
69564diff --git a/mm/highmem.c b/mm/highmem.c
69565index 57d82c6..e9e0552 100644
69566--- a/mm/highmem.c
69567+++ b/mm/highmem.c
69568@@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
69569 * So no dangers, even with speculative execution.
69570 */
69571 page = pte_page(pkmap_page_table[i]);
69572+ pax_open_kernel();
69573 pte_clear(&init_mm, (unsigned long)page_address(page),
69574 &pkmap_page_table[i]);
69575-
69576+ pax_close_kernel();
69577 set_page_address(page, NULL);
69578 need_flush = 1;
69579 }
69580@@ -186,9 +187,11 @@ start:
69581 }
69582 }
69583 vaddr = PKMAP_ADDR(last_pkmap_nr);
69584+
69585+ pax_open_kernel();
69586 set_pte_at(&init_mm, vaddr,
69587 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
69588-
69589+ pax_close_kernel();
69590 pkmap_count[last_pkmap_nr] = 1;
69591 set_page_address(page, (void *)vaddr);
69592
69593diff --git a/mm/huge_memory.c b/mm/huge_memory.c
69594index f0e5306..cb9398e 100644
69595--- a/mm/huge_memory.c
69596+++ b/mm/huge_memory.c
69597@@ -733,7 +733,7 @@ out:
69598 * run pte_offset_map on the pmd, if an huge pmd could
69599 * materialize from under us from a different thread.
69600 */
69601- if (unlikely(__pte_alloc(mm, vma, pmd, address)))
69602+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
69603 return VM_FAULT_OOM;
69604 /* if an huge pmd materialized from under us just retry later */
69605 if (unlikely(pmd_trans_huge(*pmd)))
69606diff --git a/mm/hugetlb.c b/mm/hugetlb.c
69607index 263e177..3f36aec 100644
69608--- a/mm/hugetlb.c
69609+++ b/mm/hugetlb.c
69610@@ -2446,6 +2446,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
69611 return 1;
69612 }
69613
69614+#ifdef CONFIG_PAX_SEGMEXEC
69615+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
69616+{
69617+ struct mm_struct *mm = vma->vm_mm;
69618+ struct vm_area_struct *vma_m;
69619+ unsigned long address_m;
69620+ pte_t *ptep_m;
69621+
69622+ vma_m = pax_find_mirror_vma(vma);
69623+ if (!vma_m)
69624+ return;
69625+
69626+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
69627+ address_m = address + SEGMEXEC_TASK_SIZE;
69628+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
69629+ get_page(page_m);
69630+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
69631+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
69632+}
69633+#endif
69634+
69635 /*
69636 * Hugetlb_cow() should be called with page lock of the original hugepage held.
69637 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
69638@@ -2558,6 +2579,11 @@ retry_avoidcopy:
69639 make_huge_pte(vma, new_page, 1));
69640 page_remove_rmap(old_page);
69641 hugepage_add_new_anon_rmap(new_page, vma, address);
69642+
69643+#ifdef CONFIG_PAX_SEGMEXEC
69644+ pax_mirror_huge_pte(vma, address, new_page);
69645+#endif
69646+
69647 /* Make the old page be freed below */
69648 new_page = old_page;
69649 mmu_notifier_invalidate_range_end(mm,
69650@@ -2712,6 +2738,10 @@ retry:
69651 && (vma->vm_flags & VM_SHARED)));
69652 set_huge_pte_at(mm, address, ptep, new_pte);
69653
69654+#ifdef CONFIG_PAX_SEGMEXEC
69655+ pax_mirror_huge_pte(vma, address, page);
69656+#endif
69657+
69658 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
69659 /* Optimization, do the COW without a second fault */
69660 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
69661@@ -2741,6 +2771,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69662 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
69663 struct hstate *h = hstate_vma(vma);
69664
69665+#ifdef CONFIG_PAX_SEGMEXEC
69666+ struct vm_area_struct *vma_m;
69667+#endif
69668+
69669 address &= huge_page_mask(h);
69670
69671 ptep = huge_pte_offset(mm, address);
69672@@ -2754,6 +2788,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69673 VM_FAULT_SET_HINDEX(h - hstates);
69674 }
69675
69676+#ifdef CONFIG_PAX_SEGMEXEC
69677+ vma_m = pax_find_mirror_vma(vma);
69678+ if (vma_m) {
69679+ unsigned long address_m;
69680+
69681+ if (vma->vm_start > vma_m->vm_start) {
69682+ address_m = address;
69683+ address -= SEGMEXEC_TASK_SIZE;
69684+ vma = vma_m;
69685+ h = hstate_vma(vma);
69686+ } else
69687+ address_m = address + SEGMEXEC_TASK_SIZE;
69688+
69689+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
69690+ return VM_FAULT_OOM;
69691+ address_m &= HPAGE_MASK;
69692+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
69693+ }
69694+#endif
69695+
69696 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
69697 if (!ptep)
69698 return VM_FAULT_OOM;
69699diff --git a/mm/internal.h b/mm/internal.h
69700index 2189af4..f2ca332 100644
69701--- a/mm/internal.h
69702+++ b/mm/internal.h
69703@@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
69704 * in mm/page_alloc.c
69705 */
69706 extern void __free_pages_bootmem(struct page *page, unsigned int order);
69707+extern void free_compound_page(struct page *page);
69708 extern void prep_compound_page(struct page *page, unsigned long order);
69709 #ifdef CONFIG_MEMORY_FAILURE
69710 extern bool is_free_buddy_page(struct page *page);
69711diff --git a/mm/kmemleak.c b/mm/kmemleak.c
69712index 45eb621..6ccd8ea 100644
69713--- a/mm/kmemleak.c
69714+++ b/mm/kmemleak.c
69715@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
69716
69717 for (i = 0; i < object->trace_len; i++) {
69718 void *ptr = (void *)object->trace[i];
69719- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
69720+ seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
69721 }
69722 }
69723
69724diff --git a/mm/maccess.c b/mm/maccess.c
69725index d53adf9..03a24bf 100644
69726--- a/mm/maccess.c
69727+++ b/mm/maccess.c
69728@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
69729 set_fs(KERNEL_DS);
69730 pagefault_disable();
69731 ret = __copy_from_user_inatomic(dst,
69732- (__force const void __user *)src, size);
69733+ (const void __force_user *)src, size);
69734 pagefault_enable();
69735 set_fs(old_fs);
69736
69737@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
69738
69739 set_fs(KERNEL_DS);
69740 pagefault_disable();
69741- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
69742+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
69743 pagefault_enable();
69744 set_fs(old_fs);
69745
69746diff --git a/mm/madvise.c b/mm/madvise.c
69747index 1ccbba5..79e16f9 100644
69748--- a/mm/madvise.c
69749+++ b/mm/madvise.c
69750@@ -45,6 +45,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
69751 pgoff_t pgoff;
69752 unsigned long new_flags = vma->vm_flags;
69753
69754+#ifdef CONFIG_PAX_SEGMEXEC
69755+ struct vm_area_struct *vma_m;
69756+#endif
69757+
69758 switch (behavior) {
69759 case MADV_NORMAL:
69760 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
69761@@ -116,6 +120,13 @@ success:
69762 /*
69763 * vm_flags is protected by the mmap_sem held in write mode.
69764 */
69765+
69766+#ifdef CONFIG_PAX_SEGMEXEC
69767+ vma_m = pax_find_mirror_vma(vma);
69768+ if (vma_m)
69769+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
69770+#endif
69771+
69772 vma->vm_flags = new_flags;
69773
69774 out:
69775@@ -174,6 +185,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
69776 struct vm_area_struct ** prev,
69777 unsigned long start, unsigned long end)
69778 {
69779+
69780+#ifdef CONFIG_PAX_SEGMEXEC
69781+ struct vm_area_struct *vma_m;
69782+#endif
69783+
69784 *prev = vma;
69785 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
69786 return -EINVAL;
69787@@ -186,6 +202,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
69788 zap_page_range(vma, start, end - start, &details);
69789 } else
69790 zap_page_range(vma, start, end - start, NULL);
69791+
69792+#ifdef CONFIG_PAX_SEGMEXEC
69793+ vma_m = pax_find_mirror_vma(vma);
69794+ if (vma_m) {
69795+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
69796+ struct zap_details details = {
69797+ .nonlinear_vma = vma_m,
69798+ .last_index = ULONG_MAX,
69799+ };
69800+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
69801+ } else
69802+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
69803+ }
69804+#endif
69805+
69806 return 0;
69807 }
69808
69809@@ -384,6 +415,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
69810 if (end < start)
69811 goto out;
69812
69813+#ifdef CONFIG_PAX_SEGMEXEC
69814+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
69815+ if (end > SEGMEXEC_TASK_SIZE)
69816+ goto out;
69817+ } else
69818+#endif
69819+
69820+ if (end > TASK_SIZE)
69821+ goto out;
69822+
69823 error = 0;
69824 if (end == start)
69825 goto out;
69826diff --git a/mm/memory-failure.c b/mm/memory-failure.c
69827index 97cc273..6ed703f 100644
69828--- a/mm/memory-failure.c
69829+++ b/mm/memory-failure.c
69830@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
69831
69832 int sysctl_memory_failure_recovery __read_mostly = 1;
69833
69834-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
69835+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
69836
69837 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
69838
69839@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
69840 pfn, t->comm, t->pid);
69841 si.si_signo = SIGBUS;
69842 si.si_errno = 0;
69843- si.si_addr = (void *)addr;
69844+ si.si_addr = (void __user *)addr;
69845 #ifdef __ARCH_SI_TRAPNO
69846 si.si_trapno = trapno;
69847 #endif
69848@@ -1036,7 +1036,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
69849 }
69850
69851 nr_pages = 1 << compound_trans_order(hpage);
69852- atomic_long_add(nr_pages, &mce_bad_pages);
69853+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
69854
69855 /*
69856 * We need/can do nothing about count=0 pages.
69857@@ -1066,7 +1066,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
69858 if (!PageHWPoison(hpage)
69859 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
69860 || (p != hpage && TestSetPageHWPoison(hpage))) {
69861- atomic_long_sub(nr_pages, &mce_bad_pages);
69862+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69863 return 0;
69864 }
69865 set_page_hwpoison_huge_page(hpage);
69866@@ -1124,7 +1124,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
69867 }
69868 if (hwpoison_filter(p)) {
69869 if (TestClearPageHWPoison(p))
69870- atomic_long_sub(nr_pages, &mce_bad_pages);
69871+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69872 unlock_page(hpage);
69873 put_page(hpage);
69874 return 0;
69875@@ -1319,7 +1319,7 @@ int unpoison_memory(unsigned long pfn)
69876 return 0;
69877 }
69878 if (TestClearPageHWPoison(p))
69879- atomic_long_sub(nr_pages, &mce_bad_pages);
69880+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69881 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
69882 return 0;
69883 }
69884@@ -1333,7 +1333,7 @@ int unpoison_memory(unsigned long pfn)
69885 */
69886 if (TestClearPageHWPoison(page)) {
69887 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
69888- atomic_long_sub(nr_pages, &mce_bad_pages);
69889+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69890 freeit = 1;
69891 if (PageHuge(page))
69892 clear_page_hwpoison_huge_page(page);
69893@@ -1446,7 +1446,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
69894 }
69895 done:
69896 if (!PageHWPoison(hpage))
69897- atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
69898+ atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
69899 set_page_hwpoison_huge_page(hpage);
69900 dequeue_hwpoisoned_huge_page(hpage);
69901 /* keep elevated page count for bad page */
69902@@ -1577,7 +1577,7 @@ int soft_offline_page(struct page *page, int flags)
69903 return ret;
69904
69905 done:
69906- atomic_long_add(1, &mce_bad_pages);
69907+ atomic_long_add_unchecked(1, &mce_bad_pages);
69908 SetPageHWPoison(page);
69909 /* keep elevated page count for bad page */
69910 return ret;
69911diff --git a/mm/memory.c b/mm/memory.c
69912index 6105f47..3363489 100644
69913--- a/mm/memory.c
69914+++ b/mm/memory.c
69915@@ -434,8 +434,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
69916 return;
69917
69918 pmd = pmd_offset(pud, start);
69919+
69920+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
69921 pud_clear(pud);
69922 pmd_free_tlb(tlb, pmd, start);
69923+#endif
69924+
69925 }
69926
69927 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
69928@@ -466,9 +470,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
69929 if (end - 1 > ceiling - 1)
69930 return;
69931
69932+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
69933 pud = pud_offset(pgd, start);
69934 pgd_clear(pgd);
69935 pud_free_tlb(tlb, pud, start);
69936+#endif
69937+
69938 }
69939
69940 /*
69941@@ -1597,12 +1604,6 @@ no_page_table:
69942 return page;
69943 }
69944
69945-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
69946-{
69947- return stack_guard_page_start(vma, addr) ||
69948- stack_guard_page_end(vma, addr+PAGE_SIZE);
69949-}
69950-
69951 /**
69952 * __get_user_pages() - pin user pages in memory
69953 * @tsk: task_struct of target task
69954@@ -1675,10 +1676,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
69955 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
69956 i = 0;
69957
69958- do {
69959+ while (nr_pages) {
69960 struct vm_area_struct *vma;
69961
69962- vma = find_extend_vma(mm, start);
69963+ vma = find_vma(mm, start);
69964 if (!vma && in_gate_area(mm, start)) {
69965 unsigned long pg = start & PAGE_MASK;
69966 pgd_t *pgd;
69967@@ -1726,7 +1727,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
69968 goto next_page;
69969 }
69970
69971- if (!vma ||
69972+ if (!vma || start < vma->vm_start ||
69973 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
69974 !(vm_flags & vma->vm_flags))
69975 return i ? : -EFAULT;
69976@@ -1753,11 +1754,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
69977 int ret;
69978 unsigned int fault_flags = 0;
69979
69980- /* For mlock, just skip the stack guard page. */
69981- if (foll_flags & FOLL_MLOCK) {
69982- if (stack_guard_page(vma, start))
69983- goto next_page;
69984- }
69985 if (foll_flags & FOLL_WRITE)
69986 fault_flags |= FAULT_FLAG_WRITE;
69987 if (nonblocking)
69988@@ -1831,7 +1827,7 @@ next_page:
69989 start += PAGE_SIZE;
69990 nr_pages--;
69991 } while (nr_pages && start < vma->vm_end);
69992- } while (nr_pages);
69993+ }
69994 return i;
69995 }
69996 EXPORT_SYMBOL(__get_user_pages);
69997@@ -2038,6 +2034,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
69998 page_add_file_rmap(page);
69999 set_pte_at(mm, addr, pte, mk_pte(page, prot));
70000
70001+#ifdef CONFIG_PAX_SEGMEXEC
70002+ pax_mirror_file_pte(vma, addr, page, ptl);
70003+#endif
70004+
70005 retval = 0;
70006 pte_unmap_unlock(pte, ptl);
70007 return retval;
70008@@ -2072,10 +2072,22 @@ out:
70009 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
70010 struct page *page)
70011 {
70012+
70013+#ifdef CONFIG_PAX_SEGMEXEC
70014+ struct vm_area_struct *vma_m;
70015+#endif
70016+
70017 if (addr < vma->vm_start || addr >= vma->vm_end)
70018 return -EFAULT;
70019 if (!page_count(page))
70020 return -EINVAL;
70021+
70022+#ifdef CONFIG_PAX_SEGMEXEC
70023+ vma_m = pax_find_mirror_vma(vma);
70024+ if (vma_m)
70025+ vma_m->vm_flags |= VM_INSERTPAGE;
70026+#endif
70027+
70028 vma->vm_flags |= VM_INSERTPAGE;
70029 return insert_page(vma, addr, page, vma->vm_page_prot);
70030 }
70031@@ -2161,6 +2173,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
70032 unsigned long pfn)
70033 {
70034 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
70035+ BUG_ON(vma->vm_mirror);
70036
70037 if (addr < vma->vm_start || addr >= vma->vm_end)
70038 return -EFAULT;
70039@@ -2368,7 +2381,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
70040
70041 BUG_ON(pud_huge(*pud));
70042
70043- pmd = pmd_alloc(mm, pud, addr);
70044+ pmd = (mm == &init_mm) ?
70045+ pmd_alloc_kernel(mm, pud, addr) :
70046+ pmd_alloc(mm, pud, addr);
70047 if (!pmd)
70048 return -ENOMEM;
70049 do {
70050@@ -2388,7 +2403,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
70051 unsigned long next;
70052 int err;
70053
70054- pud = pud_alloc(mm, pgd, addr);
70055+ pud = (mm == &init_mm) ?
70056+ pud_alloc_kernel(mm, pgd, addr) :
70057+ pud_alloc(mm, pgd, addr);
70058 if (!pud)
70059 return -ENOMEM;
70060 do {
70061@@ -2476,6 +2493,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
70062 copy_user_highpage(dst, src, va, vma);
70063 }
70064
70065+#ifdef CONFIG_PAX_SEGMEXEC
70066+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
70067+{
70068+ struct mm_struct *mm = vma->vm_mm;
70069+ spinlock_t *ptl;
70070+ pte_t *pte, entry;
70071+
70072+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
70073+ entry = *pte;
70074+ if (!pte_present(entry)) {
70075+ if (!pte_none(entry)) {
70076+ BUG_ON(pte_file(entry));
70077+ free_swap_and_cache(pte_to_swp_entry(entry));
70078+ pte_clear_not_present_full(mm, address, pte, 0);
70079+ }
70080+ } else {
70081+ struct page *page;
70082+
70083+ flush_cache_page(vma, address, pte_pfn(entry));
70084+ entry = ptep_clear_flush(vma, address, pte);
70085+ BUG_ON(pte_dirty(entry));
70086+ page = vm_normal_page(vma, address, entry);
70087+ if (page) {
70088+ update_hiwater_rss(mm);
70089+ if (PageAnon(page))
70090+ dec_mm_counter_fast(mm, MM_ANONPAGES);
70091+ else
70092+ dec_mm_counter_fast(mm, MM_FILEPAGES);
70093+ page_remove_rmap(page);
70094+ page_cache_release(page);
70095+ }
70096+ }
70097+ pte_unmap_unlock(pte, ptl);
70098+}
70099+
70100+/* PaX: if vma is mirrored, synchronize the mirror's PTE
70101+ *
70102+ * the ptl of the lower mapped page is held on entry and is not released on exit
70103+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
70104+ */
70105+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
70106+{
70107+ struct mm_struct *mm = vma->vm_mm;
70108+ unsigned long address_m;
70109+ spinlock_t *ptl_m;
70110+ struct vm_area_struct *vma_m;
70111+ pmd_t *pmd_m;
70112+ pte_t *pte_m, entry_m;
70113+
70114+ BUG_ON(!page_m || !PageAnon(page_m));
70115+
70116+ vma_m = pax_find_mirror_vma(vma);
70117+ if (!vma_m)
70118+ return;
70119+
70120+ BUG_ON(!PageLocked(page_m));
70121+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70122+ address_m = address + SEGMEXEC_TASK_SIZE;
70123+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70124+ pte_m = pte_offset_map(pmd_m, address_m);
70125+ ptl_m = pte_lockptr(mm, pmd_m);
70126+ if (ptl != ptl_m) {
70127+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70128+ if (!pte_none(*pte_m))
70129+ goto out;
70130+ }
70131+
70132+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
70133+ page_cache_get(page_m);
70134+ page_add_anon_rmap(page_m, vma_m, address_m);
70135+ inc_mm_counter_fast(mm, MM_ANONPAGES);
70136+ set_pte_at(mm, address_m, pte_m, entry_m);
70137+ update_mmu_cache(vma_m, address_m, entry_m);
70138+out:
70139+ if (ptl != ptl_m)
70140+ spin_unlock(ptl_m);
70141+ pte_unmap(pte_m);
70142+ unlock_page(page_m);
70143+}
70144+
70145+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
70146+{
70147+ struct mm_struct *mm = vma->vm_mm;
70148+ unsigned long address_m;
70149+ spinlock_t *ptl_m;
70150+ struct vm_area_struct *vma_m;
70151+ pmd_t *pmd_m;
70152+ pte_t *pte_m, entry_m;
70153+
70154+ BUG_ON(!page_m || PageAnon(page_m));
70155+
70156+ vma_m = pax_find_mirror_vma(vma);
70157+ if (!vma_m)
70158+ return;
70159+
70160+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70161+ address_m = address + SEGMEXEC_TASK_SIZE;
70162+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70163+ pte_m = pte_offset_map(pmd_m, address_m);
70164+ ptl_m = pte_lockptr(mm, pmd_m);
70165+ if (ptl != ptl_m) {
70166+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70167+ if (!pte_none(*pte_m))
70168+ goto out;
70169+ }
70170+
70171+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
70172+ page_cache_get(page_m);
70173+ page_add_file_rmap(page_m);
70174+ inc_mm_counter_fast(mm, MM_FILEPAGES);
70175+ set_pte_at(mm, address_m, pte_m, entry_m);
70176+ update_mmu_cache(vma_m, address_m, entry_m);
70177+out:
70178+ if (ptl != ptl_m)
70179+ spin_unlock(ptl_m);
70180+ pte_unmap(pte_m);
70181+}
70182+
70183+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
70184+{
70185+ struct mm_struct *mm = vma->vm_mm;
70186+ unsigned long address_m;
70187+ spinlock_t *ptl_m;
70188+ struct vm_area_struct *vma_m;
70189+ pmd_t *pmd_m;
70190+ pte_t *pte_m, entry_m;
70191+
70192+ vma_m = pax_find_mirror_vma(vma);
70193+ if (!vma_m)
70194+ return;
70195+
70196+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70197+ address_m = address + SEGMEXEC_TASK_SIZE;
70198+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70199+ pte_m = pte_offset_map(pmd_m, address_m);
70200+ ptl_m = pte_lockptr(mm, pmd_m);
70201+ if (ptl != ptl_m) {
70202+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70203+ if (!pte_none(*pte_m))
70204+ goto out;
70205+ }
70206+
70207+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
70208+ set_pte_at(mm, address_m, pte_m, entry_m);
70209+out:
70210+ if (ptl != ptl_m)
70211+ spin_unlock(ptl_m);
70212+ pte_unmap(pte_m);
70213+}
70214+
70215+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
70216+{
70217+ struct page *page_m;
70218+ pte_t entry;
70219+
70220+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
70221+ goto out;
70222+
70223+ entry = *pte;
70224+ page_m = vm_normal_page(vma, address, entry);
70225+ if (!page_m)
70226+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
70227+ else if (PageAnon(page_m)) {
70228+ if (pax_find_mirror_vma(vma)) {
70229+ pte_unmap_unlock(pte, ptl);
70230+ lock_page(page_m);
70231+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
70232+ if (pte_same(entry, *pte))
70233+ pax_mirror_anon_pte(vma, address, page_m, ptl);
70234+ else
70235+ unlock_page(page_m);
70236+ }
70237+ } else
70238+ pax_mirror_file_pte(vma, address, page_m, ptl);
70239+
70240+out:
70241+ pte_unmap_unlock(pte, ptl);
70242+}
70243+#endif
70244+
70245 /*
70246 * This routine handles present pages, when users try to write
70247 * to a shared page. It is done by copying the page to a new address
70248@@ -2687,6 +2884,12 @@ gotten:
70249 */
70250 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
70251 if (likely(pte_same(*page_table, orig_pte))) {
70252+
70253+#ifdef CONFIG_PAX_SEGMEXEC
70254+ if (pax_find_mirror_vma(vma))
70255+ BUG_ON(!trylock_page(new_page));
70256+#endif
70257+
70258 if (old_page) {
70259 if (!PageAnon(old_page)) {
70260 dec_mm_counter_fast(mm, MM_FILEPAGES);
70261@@ -2738,6 +2941,10 @@ gotten:
70262 page_remove_rmap(old_page);
70263 }
70264
70265+#ifdef CONFIG_PAX_SEGMEXEC
70266+ pax_mirror_anon_pte(vma, address, new_page, ptl);
70267+#endif
70268+
70269 /* Free the old page.. */
70270 new_page = old_page;
70271 ret |= VM_FAULT_WRITE;
70272@@ -3017,6 +3224,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
70273 swap_free(entry);
70274 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
70275 try_to_free_swap(page);
70276+
70277+#ifdef CONFIG_PAX_SEGMEXEC
70278+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
70279+#endif
70280+
70281 unlock_page(page);
70282 if (swapcache) {
70283 /*
70284@@ -3040,6 +3252,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
70285
70286 /* No need to invalidate - it was non-present before */
70287 update_mmu_cache(vma, address, page_table);
70288+
70289+#ifdef CONFIG_PAX_SEGMEXEC
70290+ pax_mirror_anon_pte(vma, address, page, ptl);
70291+#endif
70292+
70293 unlock:
70294 pte_unmap_unlock(page_table, ptl);
70295 out:
70296@@ -3059,40 +3276,6 @@ out_release:
70297 }
70298
70299 /*
70300- * This is like a special single-page "expand_{down|up}wards()",
70301- * except we must first make sure that 'address{-|+}PAGE_SIZE'
70302- * doesn't hit another vma.
70303- */
70304-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
70305-{
70306- address &= PAGE_MASK;
70307- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
70308- struct vm_area_struct *prev = vma->vm_prev;
70309-
70310- /*
70311- * Is there a mapping abutting this one below?
70312- *
70313- * That's only ok if it's the same stack mapping
70314- * that has gotten split..
70315- */
70316- if (prev && prev->vm_end == address)
70317- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
70318-
70319- expand_downwards(vma, address - PAGE_SIZE);
70320- }
70321- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
70322- struct vm_area_struct *next = vma->vm_next;
70323-
70324- /* As VM_GROWSDOWN but s/below/above/ */
70325- if (next && next->vm_start == address + PAGE_SIZE)
70326- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
70327-
70328- expand_upwards(vma, address + PAGE_SIZE);
70329- }
70330- return 0;
70331-}
70332-
70333-/*
70334 * We enter with non-exclusive mmap_sem (to exclude vma changes,
70335 * but allow concurrent faults), and pte mapped but not yet locked.
70336 * We return with mmap_sem still held, but pte unmapped and unlocked.
70337@@ -3101,27 +3284,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
70338 unsigned long address, pte_t *page_table, pmd_t *pmd,
70339 unsigned int flags)
70340 {
70341- struct page *page;
70342+ struct page *page = NULL;
70343 spinlock_t *ptl;
70344 pte_t entry;
70345
70346- pte_unmap(page_table);
70347-
70348- /* Check if we need to add a guard page to the stack */
70349- if (check_stack_guard_page(vma, address) < 0)
70350- return VM_FAULT_SIGBUS;
70351-
70352- /* Use the zero-page for reads */
70353 if (!(flags & FAULT_FLAG_WRITE)) {
70354 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
70355 vma->vm_page_prot));
70356- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
70357+ ptl = pte_lockptr(mm, pmd);
70358+ spin_lock(ptl);
70359 if (!pte_none(*page_table))
70360 goto unlock;
70361 goto setpte;
70362 }
70363
70364 /* Allocate our own private page. */
70365+ pte_unmap(page_table);
70366+
70367 if (unlikely(anon_vma_prepare(vma)))
70368 goto oom;
70369 page = alloc_zeroed_user_highpage_movable(vma, address);
70370@@ -3140,6 +3319,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
70371 if (!pte_none(*page_table))
70372 goto release;
70373
70374+#ifdef CONFIG_PAX_SEGMEXEC
70375+ if (pax_find_mirror_vma(vma))
70376+ BUG_ON(!trylock_page(page));
70377+#endif
70378+
70379 inc_mm_counter_fast(mm, MM_ANONPAGES);
70380 page_add_new_anon_rmap(page, vma, address);
70381 setpte:
70382@@ -3147,6 +3331,12 @@ setpte:
70383
70384 /* No need to invalidate - it was non-present before */
70385 update_mmu_cache(vma, address, page_table);
70386+
70387+#ifdef CONFIG_PAX_SEGMEXEC
70388+ if (page)
70389+ pax_mirror_anon_pte(vma, address, page, ptl);
70390+#endif
70391+
70392 unlock:
70393 pte_unmap_unlock(page_table, ptl);
70394 return 0;
70395@@ -3290,6 +3480,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70396 */
70397 /* Only go through if we didn't race with anybody else... */
70398 if (likely(pte_same(*page_table, orig_pte))) {
70399+
70400+#ifdef CONFIG_PAX_SEGMEXEC
70401+ if (anon && pax_find_mirror_vma(vma))
70402+ BUG_ON(!trylock_page(page));
70403+#endif
70404+
70405 flush_icache_page(vma, page);
70406 entry = mk_pte(page, vma->vm_page_prot);
70407 if (flags & FAULT_FLAG_WRITE)
70408@@ -3309,6 +3505,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70409
70410 /* no need to invalidate: a not-present page won't be cached */
70411 update_mmu_cache(vma, address, page_table);
70412+
70413+#ifdef CONFIG_PAX_SEGMEXEC
70414+ if (anon)
70415+ pax_mirror_anon_pte(vma, address, page, ptl);
70416+ else
70417+ pax_mirror_file_pte(vma, address, page, ptl);
70418+#endif
70419+
70420 } else {
70421 if (cow_page)
70422 mem_cgroup_uncharge_page(cow_page);
70423@@ -3462,6 +3666,12 @@ int handle_pte_fault(struct mm_struct *mm,
70424 if (flags & FAULT_FLAG_WRITE)
70425 flush_tlb_fix_spurious_fault(vma, address);
70426 }
70427+
70428+#ifdef CONFIG_PAX_SEGMEXEC
70429+ pax_mirror_pte(vma, address, pte, pmd, ptl);
70430+ return 0;
70431+#endif
70432+
70433 unlock:
70434 pte_unmap_unlock(pte, ptl);
70435 return 0;
70436@@ -3478,6 +3688,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70437 pmd_t *pmd;
70438 pte_t *pte;
70439
70440+#ifdef CONFIG_PAX_SEGMEXEC
70441+ struct vm_area_struct *vma_m;
70442+#endif
70443+
70444 __set_current_state(TASK_RUNNING);
70445
70446 count_vm_event(PGFAULT);
70447@@ -3489,6 +3703,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70448 if (unlikely(is_vm_hugetlb_page(vma)))
70449 return hugetlb_fault(mm, vma, address, flags);
70450
70451+#ifdef CONFIG_PAX_SEGMEXEC
70452+ vma_m = pax_find_mirror_vma(vma);
70453+ if (vma_m) {
70454+ unsigned long address_m;
70455+ pgd_t *pgd_m;
70456+ pud_t *pud_m;
70457+ pmd_t *pmd_m;
70458+
70459+ if (vma->vm_start > vma_m->vm_start) {
70460+ address_m = address;
70461+ address -= SEGMEXEC_TASK_SIZE;
70462+ vma = vma_m;
70463+ } else
70464+ address_m = address + SEGMEXEC_TASK_SIZE;
70465+
70466+ pgd_m = pgd_offset(mm, address_m);
70467+ pud_m = pud_alloc(mm, pgd_m, address_m);
70468+ if (!pud_m)
70469+ return VM_FAULT_OOM;
70470+ pmd_m = pmd_alloc(mm, pud_m, address_m);
70471+ if (!pmd_m)
70472+ return VM_FAULT_OOM;
70473+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
70474+ return VM_FAULT_OOM;
70475+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
70476+ }
70477+#endif
70478+
70479 pgd = pgd_offset(mm, address);
70480 pud = pud_alloc(mm, pgd, address);
70481 if (!pud)
70482@@ -3518,7 +3760,7 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70483 * run pte_offset_map on the pmd, if an huge pmd could
70484 * materialize from under us from a different thread.
70485 */
70486- if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
70487+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
70488 return VM_FAULT_OOM;
70489 /* if an huge pmd materialized from under us just retry later */
70490 if (unlikely(pmd_trans_huge(*pmd)))
70491@@ -3555,6 +3797,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
70492 spin_unlock(&mm->page_table_lock);
70493 return 0;
70494 }
70495+
70496+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
70497+{
70498+ pud_t *new = pud_alloc_one(mm, address);
70499+ if (!new)
70500+ return -ENOMEM;
70501+
70502+ smp_wmb(); /* See comment in __pte_alloc */
70503+
70504+ spin_lock(&mm->page_table_lock);
70505+ if (pgd_present(*pgd)) /* Another has populated it */
70506+ pud_free(mm, new);
70507+ else
70508+ pgd_populate_kernel(mm, pgd, new);
70509+ spin_unlock(&mm->page_table_lock);
70510+ return 0;
70511+}
70512 #endif /* __PAGETABLE_PUD_FOLDED */
70513
70514 #ifndef __PAGETABLE_PMD_FOLDED
70515@@ -3585,6 +3844,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
70516 spin_unlock(&mm->page_table_lock);
70517 return 0;
70518 }
70519+
70520+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
70521+{
70522+ pmd_t *new = pmd_alloc_one(mm, address);
70523+ if (!new)
70524+ return -ENOMEM;
70525+
70526+ smp_wmb(); /* See comment in __pte_alloc */
70527+
70528+ spin_lock(&mm->page_table_lock);
70529+#ifndef __ARCH_HAS_4LEVEL_HACK
70530+ if (pud_present(*pud)) /* Another has populated it */
70531+ pmd_free(mm, new);
70532+ else
70533+ pud_populate_kernel(mm, pud, new);
70534+#else
70535+ if (pgd_present(*pud)) /* Another has populated it */
70536+ pmd_free(mm, new);
70537+ else
70538+ pgd_populate_kernel(mm, pud, new);
70539+#endif /* __ARCH_HAS_4LEVEL_HACK */
70540+ spin_unlock(&mm->page_table_lock);
70541+ return 0;
70542+}
70543 #endif /* __PAGETABLE_PMD_FOLDED */
70544
70545 int make_pages_present(unsigned long addr, unsigned long end)
70546@@ -3622,7 +3905,7 @@ static int __init gate_vma_init(void)
70547 gate_vma.vm_start = FIXADDR_USER_START;
70548 gate_vma.vm_end = FIXADDR_USER_END;
70549 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
70550- gate_vma.vm_page_prot = __P101;
70551+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
70552
70553 return 0;
70554 }
70555diff --git a/mm/mempolicy.c b/mm/mempolicy.c
70556index bf5b485..e44c2cb 100644
70557--- a/mm/mempolicy.c
70558+++ b/mm/mempolicy.c
70559@@ -619,6 +619,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
70560 unsigned long vmstart;
70561 unsigned long vmend;
70562
70563+#ifdef CONFIG_PAX_SEGMEXEC
70564+ struct vm_area_struct *vma_m;
70565+#endif
70566+
70567 vma = find_vma(mm, start);
70568 if (!vma || vma->vm_start > start)
70569 return -EFAULT;
70570@@ -672,6 +676,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
70571 if (err)
70572 goto out;
70573 }
70574+
70575+#ifdef CONFIG_PAX_SEGMEXEC
70576+ vma_m = pax_find_mirror_vma(vma);
70577+ if (vma_m && vma_m->vm_ops && vma_m->vm_ops->set_policy) {
70578+ err = vma_m->vm_ops->set_policy(vma_m, new_pol);
70579+ if (err)
70580+ goto out;
70581+ }
70582+#endif
70583+
70584 }
70585
70586 out:
70587@@ -1105,6 +1119,17 @@ static long do_mbind(unsigned long start, unsigned long len,
70588
70589 if (end < start)
70590 return -EINVAL;
70591+
70592+#ifdef CONFIG_PAX_SEGMEXEC
70593+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
70594+ if (end > SEGMEXEC_TASK_SIZE)
70595+ return -EINVAL;
70596+ } else
70597+#endif
70598+
70599+ if (end > TASK_SIZE)
70600+ return -EINVAL;
70601+
70602 if (end == start)
70603 return 0;
70604
70605@@ -1328,8 +1353,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
70606 */
70607 tcred = __task_cred(task);
70608 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
70609- cred->uid != tcred->suid && cred->uid != tcred->uid &&
70610- !capable(CAP_SYS_NICE)) {
70611+ cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
70612 rcu_read_unlock();
70613 err = -EPERM;
70614 goto out_put;
70615@@ -1360,6 +1384,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
70616 goto out;
70617 }
70618
70619+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
70620+ if (mm != current->mm &&
70621+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
70622+ mmput(mm);
70623+ err = -EPERM;
70624+ goto out;
70625+ }
70626+#endif
70627+
70628 err = do_migrate_pages(mm, old, new,
70629 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
70630
70631diff --git a/mm/mlock.c b/mm/mlock.c
70632index ef726e8..13e0901 100644
70633--- a/mm/mlock.c
70634+++ b/mm/mlock.c
70635@@ -13,6 +13,7 @@
70636 #include <linux/pagemap.h>
70637 #include <linux/mempolicy.h>
70638 #include <linux/syscalls.h>
70639+#include <linux/security.h>
70640 #include <linux/sched.h>
70641 #include <linux/export.h>
70642 #include <linux/rmap.h>
70643@@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
70644 return -EINVAL;
70645 if (end == start)
70646 return 0;
70647+ if (end > TASK_SIZE)
70648+ return -EINVAL;
70649+
70650 vma = find_vma(current->mm, start);
70651 if (!vma || vma->vm_start > start)
70652 return -ENOMEM;
70653@@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
70654 for (nstart = start ; ; ) {
70655 vm_flags_t newflags;
70656
70657+#ifdef CONFIG_PAX_SEGMEXEC
70658+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
70659+ break;
70660+#endif
70661+
70662 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
70663
70664 newflags = vma->vm_flags | VM_LOCKED;
70665@@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
70666 lock_limit >>= PAGE_SHIFT;
70667
70668 /* check against resource limits */
70669+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
70670 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
70671 error = do_mlock(start, len, 1);
70672 up_write(&current->mm->mmap_sem);
70673@@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
70674 static int do_mlockall(int flags)
70675 {
70676 struct vm_area_struct * vma, * prev = NULL;
70677- unsigned int def_flags = 0;
70678
70679 if (flags & MCL_FUTURE)
70680- def_flags = VM_LOCKED;
70681- current->mm->def_flags = def_flags;
70682+ current->mm->def_flags |= VM_LOCKED;
70683+ else
70684+ current->mm->def_flags &= ~VM_LOCKED;
70685 if (flags == MCL_FUTURE)
70686 goto out;
70687
70688 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
70689 vm_flags_t newflags;
70690
70691+#ifdef CONFIG_PAX_SEGMEXEC
70692+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
70693+ break;
70694+#endif
70695+
70696+ BUG_ON(vma->vm_end > TASK_SIZE);
70697 newflags = vma->vm_flags | VM_LOCKED;
70698 if (!(flags & MCL_CURRENT))
70699 newflags &= ~VM_LOCKED;
70700@@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
70701 lock_limit >>= PAGE_SHIFT;
70702
70703 ret = -ENOMEM;
70704+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
70705 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
70706 capable(CAP_IPC_LOCK))
70707 ret = do_mlockall(flags);
70708diff --git a/mm/mmap.c b/mm/mmap.c
70709index 848ef52..d2b586c 100644
70710--- a/mm/mmap.c
70711+++ b/mm/mmap.c
70712@@ -46,6 +46,16 @@
70713 #define arch_rebalance_pgtables(addr, len) (addr)
70714 #endif
70715
70716+static inline void verify_mm_writelocked(struct mm_struct *mm)
70717+{
70718+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
70719+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
70720+ up_read(&mm->mmap_sem);
70721+ BUG();
70722+ }
70723+#endif
70724+}
70725+
70726 static void unmap_region(struct mm_struct *mm,
70727 struct vm_area_struct *vma, struct vm_area_struct *prev,
70728 unsigned long start, unsigned long end);
70729@@ -71,22 +81,32 @@ static void unmap_region(struct mm_struct *mm,
70730 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
70731 *
70732 */
70733-pgprot_t protection_map[16] = {
70734+pgprot_t protection_map[16] __read_only = {
70735 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
70736 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
70737 };
70738
70739-pgprot_t vm_get_page_prot(unsigned long vm_flags)
70740+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
70741 {
70742- return __pgprot(pgprot_val(protection_map[vm_flags &
70743+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
70744 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
70745 pgprot_val(arch_vm_get_page_prot(vm_flags)));
70746+
70747+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
70748+ if (!(__supported_pte_mask & _PAGE_NX) &&
70749+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
70750+ (vm_flags & (VM_READ | VM_WRITE)))
70751+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
70752+#endif
70753+
70754+ return prot;
70755 }
70756 EXPORT_SYMBOL(vm_get_page_prot);
70757
70758 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
70759 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
70760 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
70761+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
70762 /*
70763 * Make sure vm_committed_as in one cacheline and not cacheline shared with
70764 * other variables. It can be updated by several CPUs frequently.
70765@@ -228,6 +248,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
70766 struct vm_area_struct *next = vma->vm_next;
70767
70768 might_sleep();
70769+ BUG_ON(vma->vm_mirror);
70770 if (vma->vm_ops && vma->vm_ops->close)
70771 vma->vm_ops->close(vma);
70772 if (vma->vm_file) {
70773@@ -274,6 +295,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
70774 * not page aligned -Ram Gupta
70775 */
70776 rlim = rlimit(RLIMIT_DATA);
70777+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
70778 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
70779 (mm->end_data - mm->start_data) > rlim)
70780 goto out;
70781@@ -690,6 +712,12 @@ static int
70782 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
70783 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
70784 {
70785+
70786+#ifdef CONFIG_PAX_SEGMEXEC
70787+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
70788+ return 0;
70789+#endif
70790+
70791 if (is_mergeable_vma(vma, file, vm_flags) &&
70792 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
70793 if (vma->vm_pgoff == vm_pgoff)
70794@@ -709,6 +737,12 @@ static int
70795 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
70796 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
70797 {
70798+
70799+#ifdef CONFIG_PAX_SEGMEXEC
70800+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
70801+ return 0;
70802+#endif
70803+
70804 if (is_mergeable_vma(vma, file, vm_flags) &&
70805 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
70806 pgoff_t vm_pglen;
70807@@ -751,13 +785,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
70808 struct vm_area_struct *vma_merge(struct mm_struct *mm,
70809 struct vm_area_struct *prev, unsigned long addr,
70810 unsigned long end, unsigned long vm_flags,
70811- struct anon_vma *anon_vma, struct file *file,
70812+ struct anon_vma *anon_vma, struct file *file,
70813 pgoff_t pgoff, struct mempolicy *policy)
70814 {
70815 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
70816 struct vm_area_struct *area, *next;
70817 int err;
70818
70819+#ifdef CONFIG_PAX_SEGMEXEC
70820+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
70821+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
70822+
70823+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
70824+#endif
70825+
70826 /*
70827 * We later require that vma->vm_flags == vm_flags,
70828 * so this tests vma->vm_flags & VM_SPECIAL, too.
70829@@ -773,6 +814,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
70830 if (next && next->vm_end == end) /* cases 6, 7, 8 */
70831 next = next->vm_next;
70832
70833+#ifdef CONFIG_PAX_SEGMEXEC
70834+ if (prev)
70835+ prev_m = pax_find_mirror_vma(prev);
70836+ if (area)
70837+ area_m = pax_find_mirror_vma(area);
70838+ if (next)
70839+ next_m = pax_find_mirror_vma(next);
70840+#endif
70841+
70842 /*
70843 * Can it merge with the predecessor?
70844 */
70845@@ -792,9 +842,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
70846 /* cases 1, 6 */
70847 err = vma_adjust(prev, prev->vm_start,
70848 next->vm_end, prev->vm_pgoff, NULL);
70849- } else /* cases 2, 5, 7 */
70850+
70851+#ifdef CONFIG_PAX_SEGMEXEC
70852+ if (!err && prev_m)
70853+ err = vma_adjust(prev_m, prev_m->vm_start,
70854+ next_m->vm_end, prev_m->vm_pgoff, NULL);
70855+#endif
70856+
70857+ } else { /* cases 2, 5, 7 */
70858 err = vma_adjust(prev, prev->vm_start,
70859 end, prev->vm_pgoff, NULL);
70860+
70861+#ifdef CONFIG_PAX_SEGMEXEC
70862+ if (!err && prev_m)
70863+ err = vma_adjust(prev_m, prev_m->vm_start,
70864+ end_m, prev_m->vm_pgoff, NULL);
70865+#endif
70866+
70867+ }
70868 if (err)
70869 return NULL;
70870 khugepaged_enter_vma_merge(prev);
70871@@ -808,12 +873,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
70872 mpol_equal(policy, vma_policy(next)) &&
70873 can_vma_merge_before(next, vm_flags,
70874 anon_vma, file, pgoff+pglen)) {
70875- if (prev && addr < prev->vm_end) /* case 4 */
70876+ if (prev && addr < prev->vm_end) { /* case 4 */
70877 err = vma_adjust(prev, prev->vm_start,
70878 addr, prev->vm_pgoff, NULL);
70879- else /* cases 3, 8 */
70880+
70881+#ifdef CONFIG_PAX_SEGMEXEC
70882+ if (!err && prev_m)
70883+ err = vma_adjust(prev_m, prev_m->vm_start,
70884+ addr_m, prev_m->vm_pgoff, NULL);
70885+#endif
70886+
70887+ } else { /* cases 3, 8 */
70888 err = vma_adjust(area, addr, next->vm_end,
70889 next->vm_pgoff - pglen, NULL);
70890+
70891+#ifdef CONFIG_PAX_SEGMEXEC
70892+ if (!err && area_m)
70893+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
70894+ next_m->vm_pgoff - pglen, NULL);
70895+#endif
70896+
70897+ }
70898 if (err)
70899 return NULL;
70900 khugepaged_enter_vma_merge(area);
70901@@ -922,14 +1002,11 @@ none:
70902 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
70903 struct file *file, long pages)
70904 {
70905- const unsigned long stack_flags
70906- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
70907-
70908 if (file) {
70909 mm->shared_vm += pages;
70910 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
70911 mm->exec_vm += pages;
70912- } else if (flags & stack_flags)
70913+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
70914 mm->stack_vm += pages;
70915 if (flags & (VM_RESERVED|VM_IO))
70916 mm->reserved_vm += pages;
70917@@ -969,7 +1046,7 @@ static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70918 * (the exception is when the underlying filesystem is noexec
70919 * mounted, in which case we dont add PROT_EXEC.)
70920 */
70921- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
70922+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
70923 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
70924 prot |= PROT_EXEC;
70925
70926@@ -995,7 +1072,7 @@ static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70927 /* Obtain the address to map to. we verify (or select) it and ensure
70928 * that it represents a valid section of the address space.
70929 */
70930- addr = get_unmapped_area(file, addr, len, pgoff, flags);
70931+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
70932 if (addr & ~PAGE_MASK)
70933 return addr;
70934
70935@@ -1006,6 +1083,36 @@ static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70936 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
70937 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
70938
70939+#ifdef CONFIG_PAX_MPROTECT
70940+ if (mm->pax_flags & MF_PAX_MPROTECT) {
70941+#ifndef CONFIG_PAX_MPROTECT_COMPAT
70942+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
70943+ gr_log_rwxmmap(file);
70944+
70945+#ifdef CONFIG_PAX_EMUPLT
70946+ vm_flags &= ~VM_EXEC;
70947+#else
70948+ return -EPERM;
70949+#endif
70950+
70951+ }
70952+
70953+ if (!(vm_flags & VM_EXEC))
70954+ vm_flags &= ~VM_MAYEXEC;
70955+#else
70956+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
70957+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
70958+#endif
70959+ else
70960+ vm_flags &= ~VM_MAYWRITE;
70961+ }
70962+#endif
70963+
70964+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
70965+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
70966+ vm_flags &= ~VM_PAGEEXEC;
70967+#endif
70968+
70969 if (flags & MAP_LOCKED)
70970 if (!can_do_mlock())
70971 return -EPERM;
70972@@ -1017,6 +1124,7 @@ static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70973 locked += mm->locked_vm;
70974 lock_limit = rlimit(RLIMIT_MEMLOCK);
70975 lock_limit >>= PAGE_SHIFT;
70976+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
70977 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
70978 return -EAGAIN;
70979 }
70980@@ -1087,6 +1195,9 @@ static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70981 if (error)
70982 return error;
70983
70984+ if (!gr_acl_handle_mmap(file, prot))
70985+ return -EACCES;
70986+
70987 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
70988 }
70989
70990@@ -1192,7 +1303,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
70991 vm_flags_t vm_flags = vma->vm_flags;
70992
70993 /* If it was private or non-writable, the write bit is already clear */
70994- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
70995+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
70996 return 0;
70997
70998 /* The backer wishes to know when pages are first written to? */
70999@@ -1241,14 +1352,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
71000 unsigned long charged = 0;
71001 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
71002
71003+#ifdef CONFIG_PAX_SEGMEXEC
71004+ struct vm_area_struct *vma_m = NULL;
71005+#endif
71006+
71007+ /*
71008+ * mm->mmap_sem is required to protect against another thread
71009+ * changing the mappings in case we sleep.
71010+ */
71011+ verify_mm_writelocked(mm);
71012+
71013 /* Clear old maps */
71014 error = -ENOMEM;
71015-munmap_back:
71016 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71017 if (vma && vma->vm_start < addr + len) {
71018 if (do_munmap(mm, addr, len))
71019 return -ENOMEM;
71020- goto munmap_back;
71021+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71022+ BUG_ON(vma && vma->vm_start < addr + len);
71023 }
71024
71025 /* Check against address space limit. */
71026@@ -1297,6 +1418,16 @@ munmap_back:
71027 goto unacct_error;
71028 }
71029
71030+#ifdef CONFIG_PAX_SEGMEXEC
71031+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
71032+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71033+ if (!vma_m) {
71034+ error = -ENOMEM;
71035+ goto free_vma;
71036+ }
71037+ }
71038+#endif
71039+
71040 vma->vm_mm = mm;
71041 vma->vm_start = addr;
71042 vma->vm_end = addr + len;
71043@@ -1321,6 +1452,19 @@ munmap_back:
71044 error = file->f_op->mmap(file, vma);
71045 if (error)
71046 goto unmap_and_free_vma;
71047+
71048+#ifdef CONFIG_PAX_SEGMEXEC
71049+ if (vma_m && (vm_flags & VM_EXECUTABLE))
71050+ added_exe_file_vma(mm);
71051+#endif
71052+
71053+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71054+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
71055+ vma->vm_flags |= VM_PAGEEXEC;
71056+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
71057+ }
71058+#endif
71059+
71060 if (vm_flags & VM_EXECUTABLE)
71061 added_exe_file_vma(mm);
71062
71063@@ -1358,6 +1502,11 @@ munmap_back:
71064 vma_link(mm, vma, prev, rb_link, rb_parent);
71065 file = vma->vm_file;
71066
71067+#ifdef CONFIG_PAX_SEGMEXEC
71068+ if (vma_m)
71069+ BUG_ON(pax_mirror_vma(vma_m, vma));
71070+#endif
71071+
71072 /* Once vma denies write, undo our temporary denial count */
71073 if (correct_wcount)
71074 atomic_inc(&inode->i_writecount);
71075@@ -1366,6 +1515,7 @@ out:
71076
71077 mm->total_vm += len >> PAGE_SHIFT;
71078 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
71079+ track_exec_limit(mm, addr, addr + len, vm_flags);
71080 if (vm_flags & VM_LOCKED) {
71081 if (!mlock_vma_pages_range(vma, addr, addr + len))
71082 mm->locked_vm += (len >> PAGE_SHIFT);
71083@@ -1383,6 +1533,12 @@ unmap_and_free_vma:
71084 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
71085 charged = 0;
71086 free_vma:
71087+
71088+#ifdef CONFIG_PAX_SEGMEXEC
71089+ if (vma_m)
71090+ kmem_cache_free(vm_area_cachep, vma_m);
71091+#endif
71092+
71093 kmem_cache_free(vm_area_cachep, vma);
71094 unacct_error:
71095 if (charged)
71096@@ -1390,6 +1546,44 @@ unacct_error:
71097 return error;
71098 }
71099
71100+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
71101+{
71102+ if (!vma) {
71103+#ifdef CONFIG_STACK_GROWSUP
71104+ if (addr > sysctl_heap_stack_gap)
71105+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
71106+ else
71107+ vma = find_vma(current->mm, 0);
71108+ if (vma && (vma->vm_flags & VM_GROWSUP))
71109+ return false;
71110+#endif
71111+ return true;
71112+ }
71113+
71114+ if (addr + len > vma->vm_start)
71115+ return false;
71116+
71117+ if (vma->vm_flags & VM_GROWSDOWN)
71118+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
71119+#ifdef CONFIG_STACK_GROWSUP
71120+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
71121+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
71122+#endif
71123+
71124+ return true;
71125+}
71126+
71127+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
71128+{
71129+ if (vma->vm_start < len)
71130+ return -ENOMEM;
71131+ if (!(vma->vm_flags & VM_GROWSDOWN))
71132+ return vma->vm_start - len;
71133+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
71134+ return vma->vm_start - len - sysctl_heap_stack_gap;
71135+ return -ENOMEM;
71136+}
71137+
71138 /* Get an address range which is currently unmapped.
71139 * For shmat() with addr=0.
71140 *
71141@@ -1416,18 +1610,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
71142 if (flags & MAP_FIXED)
71143 return addr;
71144
71145+#ifdef CONFIG_PAX_RANDMMAP
71146+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
71147+#endif
71148+
71149 if (addr) {
71150 addr = PAGE_ALIGN(addr);
71151- vma = find_vma(mm, addr);
71152- if (TASK_SIZE - len >= addr &&
71153- (!vma || addr + len <= vma->vm_start))
71154- return addr;
71155+ if (TASK_SIZE - len >= addr) {
71156+ vma = find_vma(mm, addr);
71157+ if (check_heap_stack_gap(vma, addr, len))
71158+ return addr;
71159+ }
71160 }
71161 if (len > mm->cached_hole_size) {
71162- start_addr = addr = mm->free_area_cache;
71163+ start_addr = addr = mm->free_area_cache;
71164 } else {
71165- start_addr = addr = TASK_UNMAPPED_BASE;
71166- mm->cached_hole_size = 0;
71167+ start_addr = addr = mm->mmap_base;
71168+ mm->cached_hole_size = 0;
71169 }
71170
71171 full_search:
71172@@ -1438,34 +1637,40 @@ full_search:
71173 * Start a new search - just in case we missed
71174 * some holes.
71175 */
71176- if (start_addr != TASK_UNMAPPED_BASE) {
71177- addr = TASK_UNMAPPED_BASE;
71178- start_addr = addr;
71179+ if (start_addr != mm->mmap_base) {
71180+ start_addr = addr = mm->mmap_base;
71181 mm->cached_hole_size = 0;
71182 goto full_search;
71183 }
71184 return -ENOMEM;
71185 }
71186- if (!vma || addr + len <= vma->vm_start) {
71187- /*
71188- * Remember the place where we stopped the search:
71189- */
71190- mm->free_area_cache = addr + len;
71191- return addr;
71192- }
71193+ if (check_heap_stack_gap(vma, addr, len))
71194+ break;
71195 if (addr + mm->cached_hole_size < vma->vm_start)
71196 mm->cached_hole_size = vma->vm_start - addr;
71197 addr = vma->vm_end;
71198 }
71199+
71200+ /*
71201+ * Remember the place where we stopped the search:
71202+ */
71203+ mm->free_area_cache = addr + len;
71204+ return addr;
71205 }
71206 #endif
71207
71208 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
71209 {
71210+
71211+#ifdef CONFIG_PAX_SEGMEXEC
71212+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
71213+ return;
71214+#endif
71215+
71216 /*
71217 * Is this a new hole at the lowest possible address?
71218 */
71219- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
71220+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
71221 mm->free_area_cache = addr;
71222 }
71223
71224@@ -1481,7 +1686,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71225 {
71226 struct vm_area_struct *vma;
71227 struct mm_struct *mm = current->mm;
71228- unsigned long addr = addr0, start_addr;
71229+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
71230
71231 /* requested length too big for entire address space */
71232 if (len > TASK_SIZE)
71233@@ -1490,13 +1695,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71234 if (flags & MAP_FIXED)
71235 return addr;
71236
71237+#ifdef CONFIG_PAX_RANDMMAP
71238+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
71239+#endif
71240+
71241 /* requesting a specific address */
71242 if (addr) {
71243 addr = PAGE_ALIGN(addr);
71244- vma = find_vma(mm, addr);
71245- if (TASK_SIZE - len >= addr &&
71246- (!vma || addr + len <= vma->vm_start))
71247- return addr;
71248+ if (TASK_SIZE - len >= addr) {
71249+ vma = find_vma(mm, addr);
71250+ if (check_heap_stack_gap(vma, addr, len))
71251+ return addr;
71252+ }
71253 }
71254
71255 /* check if free_area_cache is useful for us */
71256@@ -1520,7 +1730,7 @@ try_again:
71257 * return with success:
71258 */
71259 vma = find_vma(mm, addr);
71260- if (!vma || addr+len <= vma->vm_start)
71261+ if (check_heap_stack_gap(vma, addr, len))
71262 /* remember the address as a hint for next time */
71263 return (mm->free_area_cache = addr);
71264
71265@@ -1529,8 +1739,8 @@ try_again:
71266 mm->cached_hole_size = vma->vm_start - addr;
71267
71268 /* try just below the current vma->vm_start */
71269- addr = vma->vm_start-len;
71270- } while (len < vma->vm_start);
71271+ addr = skip_heap_stack_gap(vma, len);
71272+ } while (!IS_ERR_VALUE(addr));
71273
71274 fail:
71275 /*
71276@@ -1553,13 +1763,21 @@ fail:
71277 * can happen with large stack limits and large mmap()
71278 * allocations.
71279 */
71280+ mm->mmap_base = TASK_UNMAPPED_BASE;
71281+
71282+#ifdef CONFIG_PAX_RANDMMAP
71283+ if (mm->pax_flags & MF_PAX_RANDMMAP)
71284+ mm->mmap_base += mm->delta_mmap;
71285+#endif
71286+
71287+ mm->free_area_cache = mm->mmap_base;
71288 mm->cached_hole_size = ~0UL;
71289- mm->free_area_cache = TASK_UNMAPPED_BASE;
71290 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
71291 /*
71292 * Restore the topdown base:
71293 */
71294- mm->free_area_cache = mm->mmap_base;
71295+ mm->mmap_base = base;
71296+ mm->free_area_cache = base;
71297 mm->cached_hole_size = ~0UL;
71298
71299 return addr;
71300@@ -1568,6 +1786,12 @@ fail:
71301
71302 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
71303 {
71304+
71305+#ifdef CONFIG_PAX_SEGMEXEC
71306+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
71307+ return;
71308+#endif
71309+
71310 /*
71311 * Is this a new hole at the highest possible address?
71312 */
71313@@ -1575,8 +1799,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
71314 mm->free_area_cache = addr;
71315
71316 /* dont allow allocations above current base */
71317- if (mm->free_area_cache > mm->mmap_base)
71318+ if (mm->free_area_cache > mm->mmap_base) {
71319 mm->free_area_cache = mm->mmap_base;
71320+ mm->cached_hole_size = ~0UL;
71321+ }
71322 }
71323
71324 unsigned long
71325@@ -1672,6 +1898,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
71326 return vma;
71327 }
71328
71329+#ifdef CONFIG_PAX_SEGMEXEC
71330+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
71331+{
71332+ struct vm_area_struct *vma_m;
71333+
71334+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
71335+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
71336+ BUG_ON(vma->vm_mirror);
71337+ return NULL;
71338+ }
71339+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
71340+ vma_m = vma->vm_mirror;
71341+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
71342+ BUG_ON(vma->vm_file != vma_m->vm_file);
71343+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
71344+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
71345+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
71346+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
71347+ return vma_m;
71348+}
71349+#endif
71350+
71351 /*
71352 * Verify that the stack growth is acceptable and
71353 * update accounting. This is shared with both the
71354@@ -1688,6 +1936,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
71355 return -ENOMEM;
71356
71357 /* Stack limit test */
71358+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
71359 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
71360 return -ENOMEM;
71361
71362@@ -1698,6 +1947,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
71363 locked = mm->locked_vm + grow;
71364 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
71365 limit >>= PAGE_SHIFT;
71366+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
71367 if (locked > limit && !capable(CAP_IPC_LOCK))
71368 return -ENOMEM;
71369 }
71370@@ -1728,37 +1978,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
71371 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
71372 * vma is the last one with address > vma->vm_end. Have to extend vma.
71373 */
71374+#ifndef CONFIG_IA64
71375+static
71376+#endif
71377 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
71378 {
71379 int error;
71380+ bool locknext;
71381
71382 if (!(vma->vm_flags & VM_GROWSUP))
71383 return -EFAULT;
71384
71385+ /* Also guard against wrapping around to address 0. */
71386+ if (address < PAGE_ALIGN(address+1))
71387+ address = PAGE_ALIGN(address+1);
71388+ else
71389+ return -ENOMEM;
71390+
71391 /*
71392 * We must make sure the anon_vma is allocated
71393 * so that the anon_vma locking is not a noop.
71394 */
71395 if (unlikely(anon_vma_prepare(vma)))
71396 return -ENOMEM;
71397+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
71398+ if (locknext && anon_vma_prepare(vma->vm_next))
71399+ return -ENOMEM;
71400 vma_lock_anon_vma(vma);
71401+ if (locknext)
71402+ vma_lock_anon_vma(vma->vm_next);
71403
71404 /*
71405 * vma->vm_start/vm_end cannot change under us because the caller
71406 * is required to hold the mmap_sem in read mode. We need the
71407- * anon_vma lock to serialize against concurrent expand_stacks.
71408- * Also guard against wrapping around to address 0.
71409+ * anon_vma locks to serialize against concurrent expand_stacks
71410+ * and expand_upwards.
71411 */
71412- if (address < PAGE_ALIGN(address+4))
71413- address = PAGE_ALIGN(address+4);
71414- else {
71415- vma_unlock_anon_vma(vma);
71416- return -ENOMEM;
71417- }
71418 error = 0;
71419
71420 /* Somebody else might have raced and expanded it already */
71421- if (address > vma->vm_end) {
71422+ 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)
71423+ error = -ENOMEM;
71424+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
71425 unsigned long size, grow;
71426
71427 size = address - vma->vm_start;
71428@@ -1773,6 +2034,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
71429 }
71430 }
71431 }
71432+ if (locknext)
71433+ vma_unlock_anon_vma(vma->vm_next);
71434 vma_unlock_anon_vma(vma);
71435 khugepaged_enter_vma_merge(vma);
71436 return error;
71437@@ -1786,6 +2049,8 @@ int expand_downwards(struct vm_area_struct *vma,
71438 unsigned long address)
71439 {
71440 int error;
71441+ bool lockprev = false;
71442+ struct vm_area_struct *prev;
71443
71444 /*
71445 * We must make sure the anon_vma is allocated
71446@@ -1799,6 +2064,15 @@ int expand_downwards(struct vm_area_struct *vma,
71447 if (error)
71448 return error;
71449
71450+ prev = vma->vm_prev;
71451+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
71452+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
71453+#endif
71454+ if (lockprev && anon_vma_prepare(prev))
71455+ return -ENOMEM;
71456+ if (lockprev)
71457+ vma_lock_anon_vma(prev);
71458+
71459 vma_lock_anon_vma(vma);
71460
71461 /*
71462@@ -1808,9 +2082,17 @@ int expand_downwards(struct vm_area_struct *vma,
71463 */
71464
71465 /* Somebody else might have raced and expanded it already */
71466- if (address < vma->vm_start) {
71467+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
71468+ error = -ENOMEM;
71469+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
71470 unsigned long size, grow;
71471
71472+#ifdef CONFIG_PAX_SEGMEXEC
71473+ struct vm_area_struct *vma_m;
71474+
71475+ vma_m = pax_find_mirror_vma(vma);
71476+#endif
71477+
71478 size = vma->vm_end - address;
71479 grow = (vma->vm_start - address) >> PAGE_SHIFT;
71480
71481@@ -1820,11 +2102,22 @@ int expand_downwards(struct vm_area_struct *vma,
71482 if (!error) {
71483 vma->vm_start = address;
71484 vma->vm_pgoff -= grow;
71485+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
71486+
71487+#ifdef CONFIG_PAX_SEGMEXEC
71488+ if (vma_m) {
71489+ vma_m->vm_start -= grow << PAGE_SHIFT;
71490+ vma_m->vm_pgoff -= grow;
71491+ }
71492+#endif
71493+
71494 perf_event_mmap(vma);
71495 }
71496 }
71497 }
71498 vma_unlock_anon_vma(vma);
71499+ if (lockprev)
71500+ vma_unlock_anon_vma(prev);
71501 khugepaged_enter_vma_merge(vma);
71502 return error;
71503 }
71504@@ -1894,6 +2187,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
71505 do {
71506 long nrpages = vma_pages(vma);
71507
71508+#ifdef CONFIG_PAX_SEGMEXEC
71509+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
71510+ vma = remove_vma(vma);
71511+ continue;
71512+ }
71513+#endif
71514+
71515 mm->total_vm -= nrpages;
71516 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
71517 vma = remove_vma(vma);
71518@@ -1939,6 +2239,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
71519 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
71520 vma->vm_prev = NULL;
71521 do {
71522+
71523+#ifdef CONFIG_PAX_SEGMEXEC
71524+ if (vma->vm_mirror) {
71525+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
71526+ vma->vm_mirror->vm_mirror = NULL;
71527+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
71528+ vma->vm_mirror = NULL;
71529+ }
71530+#endif
71531+
71532 rb_erase(&vma->vm_rb, &mm->mm_rb);
71533 mm->map_count--;
71534 tail_vma = vma;
71535@@ -1967,14 +2277,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71536 struct vm_area_struct *new;
71537 int err = -ENOMEM;
71538
71539+#ifdef CONFIG_PAX_SEGMEXEC
71540+ struct vm_area_struct *vma_m, *new_m = NULL;
71541+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
71542+#endif
71543+
71544 if (is_vm_hugetlb_page(vma) && (addr &
71545 ~(huge_page_mask(hstate_vma(vma)))))
71546 return -EINVAL;
71547
71548+#ifdef CONFIG_PAX_SEGMEXEC
71549+ vma_m = pax_find_mirror_vma(vma);
71550+#endif
71551+
71552 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
71553 if (!new)
71554 goto out_err;
71555
71556+#ifdef CONFIG_PAX_SEGMEXEC
71557+ if (vma_m) {
71558+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
71559+ if (!new_m) {
71560+ kmem_cache_free(vm_area_cachep, new);
71561+ goto out_err;
71562+ }
71563+ }
71564+#endif
71565+
71566 /* most fields are the same, copy all, and then fixup */
71567 *new = *vma;
71568
71569@@ -1987,6 +2316,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71570 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
71571 }
71572
71573+#ifdef CONFIG_PAX_SEGMEXEC
71574+ if (vma_m) {
71575+ *new_m = *vma_m;
71576+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
71577+ new_m->vm_mirror = new;
71578+ new->vm_mirror = new_m;
71579+
71580+ if (new_below)
71581+ new_m->vm_end = addr_m;
71582+ else {
71583+ new_m->vm_start = addr_m;
71584+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
71585+ }
71586+ }
71587+#endif
71588+
71589 pol = mpol_dup(vma_policy(vma));
71590 if (IS_ERR(pol)) {
71591 err = PTR_ERR(pol);
71592@@ -2012,6 +2357,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71593 else
71594 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
71595
71596+#ifdef CONFIG_PAX_SEGMEXEC
71597+ if (!err && vma_m) {
71598+ if (anon_vma_clone(new_m, vma_m))
71599+ goto out_free_mpol;
71600+
71601+ mpol_get(pol);
71602+ vma_set_policy(new_m, pol);
71603+
71604+ if (new_m->vm_file) {
71605+ get_file(new_m->vm_file);
71606+ if (vma_m->vm_flags & VM_EXECUTABLE)
71607+ added_exe_file_vma(mm);
71608+ }
71609+
71610+ if (new_m->vm_ops && new_m->vm_ops->open)
71611+ new_m->vm_ops->open(new_m);
71612+
71613+ if (new_below)
71614+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
71615+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
71616+ else
71617+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
71618+
71619+ if (err) {
71620+ if (new_m->vm_ops && new_m->vm_ops->close)
71621+ new_m->vm_ops->close(new_m);
71622+ if (new_m->vm_file) {
71623+ if (vma_m->vm_flags & VM_EXECUTABLE)
71624+ removed_exe_file_vma(mm);
71625+ fput(new_m->vm_file);
71626+ }
71627+ mpol_put(pol);
71628+ }
71629+ }
71630+#endif
71631+
71632 /* Success. */
71633 if (!err)
71634 return 0;
71635@@ -2024,10 +2405,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71636 removed_exe_file_vma(mm);
71637 fput(new->vm_file);
71638 }
71639- unlink_anon_vmas(new);
71640 out_free_mpol:
71641 mpol_put(pol);
71642 out_free_vma:
71643+
71644+#ifdef CONFIG_PAX_SEGMEXEC
71645+ if (new_m) {
71646+ unlink_anon_vmas(new_m);
71647+ kmem_cache_free(vm_area_cachep, new_m);
71648+ }
71649+#endif
71650+
71651+ unlink_anon_vmas(new);
71652 kmem_cache_free(vm_area_cachep, new);
71653 out_err:
71654 return err;
71655@@ -2040,6 +2429,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71656 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
71657 unsigned long addr, int new_below)
71658 {
71659+
71660+#ifdef CONFIG_PAX_SEGMEXEC
71661+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
71662+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
71663+ if (mm->map_count >= sysctl_max_map_count-1)
71664+ return -ENOMEM;
71665+ } else
71666+#endif
71667+
71668 if (mm->map_count >= sysctl_max_map_count)
71669 return -ENOMEM;
71670
71671@@ -2051,11 +2449,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
71672 * work. This now handles partial unmappings.
71673 * Jeremy Fitzhardinge <jeremy@goop.org>
71674 */
71675+#ifdef CONFIG_PAX_SEGMEXEC
71676 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71677 {
71678+ int ret = __do_munmap(mm, start, len);
71679+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
71680+ return ret;
71681+
71682+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
71683+}
71684+
71685+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71686+#else
71687+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71688+#endif
71689+{
71690 unsigned long end;
71691 struct vm_area_struct *vma, *prev, *last;
71692
71693+ /*
71694+ * mm->mmap_sem is required to protect against another thread
71695+ * changing the mappings in case we sleep.
71696+ */
71697+ verify_mm_writelocked(mm);
71698+
71699 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
71700 return -EINVAL;
71701
71702@@ -2130,6 +2547,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71703 /* Fix up all other VM information */
71704 remove_vma_list(mm, vma);
71705
71706+ track_exec_limit(mm, start, end, 0UL);
71707+
71708 return 0;
71709 }
71710 EXPORT_SYMBOL(do_munmap);
71711@@ -2139,6 +2558,13 @@ int vm_munmap(unsigned long start, size_t len)
71712 int ret;
71713 struct mm_struct *mm = current->mm;
71714
71715+
71716+#ifdef CONFIG_PAX_SEGMEXEC
71717+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
71718+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
71719+ return -EINVAL;
71720+#endif
71721+
71722 down_write(&mm->mmap_sem);
71723 ret = do_munmap(mm, start, len);
71724 up_write(&mm->mmap_sem);
71725@@ -2152,16 +2578,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
71726 return vm_munmap(addr, len);
71727 }
71728
71729-static inline void verify_mm_writelocked(struct mm_struct *mm)
71730-{
71731-#ifdef CONFIG_DEBUG_VM
71732- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
71733- WARN_ON(1);
71734- up_read(&mm->mmap_sem);
71735- }
71736-#endif
71737-}
71738-
71739 /*
71740 * this is really a simplified "do_mmap". it only handles
71741 * anonymous maps. eventually we may be able to do some
71742@@ -2175,6 +2591,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
71743 struct rb_node ** rb_link, * rb_parent;
71744 pgoff_t pgoff = addr >> PAGE_SHIFT;
71745 int error;
71746+ unsigned long charged;
71747
71748 len = PAGE_ALIGN(len);
71749 if (!len)
71750@@ -2186,16 +2603,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
71751
71752 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
71753
71754+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
71755+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
71756+ flags &= ~VM_EXEC;
71757+
71758+#ifdef CONFIG_PAX_MPROTECT
71759+ if (mm->pax_flags & MF_PAX_MPROTECT)
71760+ flags &= ~VM_MAYEXEC;
71761+#endif
71762+
71763+ }
71764+#endif
71765+
71766 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
71767 if (error & ~PAGE_MASK)
71768 return error;
71769
71770+ charged = len >> PAGE_SHIFT;
71771+
71772 /*
71773 * mlock MCL_FUTURE?
71774 */
71775 if (mm->def_flags & VM_LOCKED) {
71776 unsigned long locked, lock_limit;
71777- locked = len >> PAGE_SHIFT;
71778+ locked = charged;
71779 locked += mm->locked_vm;
71780 lock_limit = rlimit(RLIMIT_MEMLOCK);
71781 lock_limit >>= PAGE_SHIFT;
71782@@ -2212,22 +2643,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
71783 /*
71784 * Clear old maps. this also does some error checking for us
71785 */
71786- munmap_back:
71787 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71788 if (vma && vma->vm_start < addr + len) {
71789 if (do_munmap(mm, addr, len))
71790 return -ENOMEM;
71791- goto munmap_back;
71792- }
71793+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71794+ BUG_ON(vma && vma->vm_start < addr + len);
71795+ }
71796
71797 /* Check against address space limits *after* clearing old maps... */
71798- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
71799+ if (!may_expand_vm(mm, charged))
71800 return -ENOMEM;
71801
71802 if (mm->map_count > sysctl_max_map_count)
71803 return -ENOMEM;
71804
71805- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
71806+ if (security_vm_enough_memory_mm(mm, charged))
71807 return -ENOMEM;
71808
71809 /* Can we just expand an old private anonymous mapping? */
71810@@ -2241,7 +2672,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
71811 */
71812 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71813 if (!vma) {
71814- vm_unacct_memory(len >> PAGE_SHIFT);
71815+ vm_unacct_memory(charged);
71816 return -ENOMEM;
71817 }
71818
71819@@ -2255,11 +2686,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
71820 vma_link(mm, vma, prev, rb_link, rb_parent);
71821 out:
71822 perf_event_mmap(vma);
71823- mm->total_vm += len >> PAGE_SHIFT;
71824+ mm->total_vm += charged;
71825 if (flags & VM_LOCKED) {
71826 if (!mlock_vma_pages_range(vma, addr, addr + len))
71827- mm->locked_vm += (len >> PAGE_SHIFT);
71828+ mm->locked_vm += charged;
71829 }
71830+ track_exec_limit(mm, addr, addr + len, flags);
71831 return addr;
71832 }
71833
71834@@ -2315,8 +2747,10 @@ void exit_mmap(struct mm_struct *mm)
71835 * Walk the list again, actually closing and freeing it,
71836 * with preemption enabled, without holding any MM locks.
71837 */
71838- while (vma)
71839+ while (vma) {
71840+ vma->vm_mirror = NULL;
71841 vma = remove_vma(vma);
71842+ }
71843
71844 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
71845 }
71846@@ -2330,6 +2764,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
71847 struct vm_area_struct * __vma, * prev;
71848 struct rb_node ** rb_link, * rb_parent;
71849
71850+#ifdef CONFIG_PAX_SEGMEXEC
71851+ struct vm_area_struct *vma_m = NULL;
71852+#endif
71853+
71854+ if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
71855+ return -EPERM;
71856+
71857 /*
71858 * The vm_pgoff of a purely anonymous vma should be irrelevant
71859 * until its first write fault, when page's anon_vma and index
71860@@ -2352,7 +2793,22 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
71861 if ((vma->vm_flags & VM_ACCOUNT) &&
71862 security_vm_enough_memory_mm(mm, vma_pages(vma)))
71863 return -ENOMEM;
71864+
71865+#ifdef CONFIG_PAX_SEGMEXEC
71866+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
71867+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71868+ if (!vma_m)
71869+ return -ENOMEM;
71870+ }
71871+#endif
71872+
71873 vma_link(mm, vma, prev, rb_link, rb_parent);
71874+
71875+#ifdef CONFIG_PAX_SEGMEXEC
71876+ if (vma_m)
71877+ BUG_ON(pax_mirror_vma(vma_m, vma));
71878+#endif
71879+
71880 return 0;
71881 }
71882
71883@@ -2371,6 +2827,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
71884 struct mempolicy *pol;
71885 bool faulted_in_anon_vma = true;
71886
71887+ BUG_ON(vma->vm_mirror);
71888+
71889 /*
71890 * If anonymous vma has not yet been faulted, update new pgoff
71891 * to match new location, to increase its chance of merging.
71892@@ -2438,6 +2896,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
71893 return NULL;
71894 }
71895
71896+#ifdef CONFIG_PAX_SEGMEXEC
71897+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
71898+{
71899+ struct vm_area_struct *prev_m;
71900+ struct rb_node **rb_link_m, *rb_parent_m;
71901+ struct mempolicy *pol_m;
71902+
71903+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
71904+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
71905+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
71906+ *vma_m = *vma;
71907+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
71908+ if (anon_vma_clone(vma_m, vma))
71909+ return -ENOMEM;
71910+ pol_m = vma_policy(vma_m);
71911+ mpol_get(pol_m);
71912+ vma_set_policy(vma_m, pol_m);
71913+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
71914+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
71915+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
71916+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
71917+ if (vma_m->vm_file)
71918+ get_file(vma_m->vm_file);
71919+ if (vma_m->vm_ops && vma_m->vm_ops->open)
71920+ vma_m->vm_ops->open(vma_m);
71921+ find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
71922+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
71923+ vma_m->vm_mirror = vma;
71924+ vma->vm_mirror = vma_m;
71925+ return 0;
71926+}
71927+#endif
71928+
71929 /*
71930 * Return true if the calling process may expand its vm space by the passed
71931 * number of pages
71932@@ -2449,6 +2940,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
71933
71934 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
71935
71936+#ifdef CONFIG_PAX_RANDMMAP
71937+ if (mm->pax_flags & MF_PAX_RANDMMAP)
71938+ cur -= mm->brk_gap;
71939+#endif
71940+
71941+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
71942 if (cur + npages > lim)
71943 return 0;
71944 return 1;
71945@@ -2519,6 +3016,22 @@ int install_special_mapping(struct mm_struct *mm,
71946 vma->vm_start = addr;
71947 vma->vm_end = addr + len;
71948
71949+#ifdef CONFIG_PAX_MPROTECT
71950+ if (mm->pax_flags & MF_PAX_MPROTECT) {
71951+#ifndef CONFIG_PAX_MPROTECT_COMPAT
71952+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
71953+ return -EPERM;
71954+ if (!(vm_flags & VM_EXEC))
71955+ vm_flags &= ~VM_MAYEXEC;
71956+#else
71957+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
71958+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
71959+#endif
71960+ else
71961+ vm_flags &= ~VM_MAYWRITE;
71962+ }
71963+#endif
71964+
71965 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
71966 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
71967
71968diff --git a/mm/mprotect.c b/mm/mprotect.c
71969index a409926..8b32e6d 100644
71970--- a/mm/mprotect.c
71971+++ b/mm/mprotect.c
71972@@ -23,10 +23,17 @@
71973 #include <linux/mmu_notifier.h>
71974 #include <linux/migrate.h>
71975 #include <linux/perf_event.h>
71976+
71977+#ifdef CONFIG_PAX_MPROTECT
71978+#include <linux/elf.h>
71979+#include <linux/binfmts.h>
71980+#endif
71981+
71982 #include <asm/uaccess.h>
71983 #include <asm/pgtable.h>
71984 #include <asm/cacheflush.h>
71985 #include <asm/tlbflush.h>
71986+#include <asm/mmu_context.h>
71987
71988 #ifndef pgprot_modify
71989 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
71990@@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
71991 flush_tlb_range(vma, start, end);
71992 }
71993
71994+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
71995+/* called while holding the mmap semaphor for writing except stack expansion */
71996+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
71997+{
71998+ unsigned long oldlimit, newlimit = 0UL;
71999+
72000+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
72001+ return;
72002+
72003+ spin_lock(&mm->page_table_lock);
72004+ oldlimit = mm->context.user_cs_limit;
72005+ if ((prot & VM_EXEC) && oldlimit < end)
72006+ /* USER_CS limit moved up */
72007+ newlimit = end;
72008+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
72009+ /* USER_CS limit moved down */
72010+ newlimit = start;
72011+
72012+ if (newlimit) {
72013+ mm->context.user_cs_limit = newlimit;
72014+
72015+#ifdef CONFIG_SMP
72016+ wmb();
72017+ cpus_clear(mm->context.cpu_user_cs_mask);
72018+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
72019+#endif
72020+
72021+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
72022+ }
72023+ spin_unlock(&mm->page_table_lock);
72024+ if (newlimit == end) {
72025+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
72026+
72027+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
72028+ if (is_vm_hugetlb_page(vma))
72029+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
72030+ else
72031+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
72032+ }
72033+}
72034+#endif
72035+
72036 int
72037 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72038 unsigned long start, unsigned long end, unsigned long newflags)
72039@@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72040 int error;
72041 int dirty_accountable = 0;
72042
72043+#ifdef CONFIG_PAX_SEGMEXEC
72044+ struct vm_area_struct *vma_m = NULL;
72045+ unsigned long start_m, end_m;
72046+
72047+ start_m = start + SEGMEXEC_TASK_SIZE;
72048+ end_m = end + SEGMEXEC_TASK_SIZE;
72049+#endif
72050+
72051 if (newflags == oldflags) {
72052 *pprev = vma;
72053 return 0;
72054 }
72055
72056+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
72057+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
72058+
72059+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
72060+ return -ENOMEM;
72061+
72062+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
72063+ return -ENOMEM;
72064+ }
72065+
72066 /*
72067 * If we make a private mapping writable we increase our commit;
72068 * but (without finer accounting) cannot reduce our commit if we
72069@@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72070 }
72071 }
72072
72073+#ifdef CONFIG_PAX_SEGMEXEC
72074+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
72075+ if (start != vma->vm_start) {
72076+ error = split_vma(mm, vma, start, 1);
72077+ if (error)
72078+ goto fail;
72079+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
72080+ *pprev = (*pprev)->vm_next;
72081+ }
72082+
72083+ if (end != vma->vm_end) {
72084+ error = split_vma(mm, vma, end, 0);
72085+ if (error)
72086+ goto fail;
72087+ }
72088+
72089+ if (pax_find_mirror_vma(vma)) {
72090+ error = __do_munmap(mm, start_m, end_m - start_m);
72091+ if (error)
72092+ goto fail;
72093+ } else {
72094+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72095+ if (!vma_m) {
72096+ error = -ENOMEM;
72097+ goto fail;
72098+ }
72099+ vma->vm_flags = newflags;
72100+ error = pax_mirror_vma(vma_m, vma);
72101+ if (error) {
72102+ vma->vm_flags = oldflags;
72103+ goto fail;
72104+ }
72105+ }
72106+ }
72107+#endif
72108+
72109 /*
72110 * First try to merge with previous and/or next vma.
72111 */
72112@@ -204,9 +307,21 @@ success:
72113 * vm_flags and vm_page_prot are protected by the mmap_sem
72114 * held in write mode.
72115 */
72116+
72117+#ifdef CONFIG_PAX_SEGMEXEC
72118+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
72119+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
72120+#endif
72121+
72122 vma->vm_flags = newflags;
72123+
72124+#ifdef CONFIG_PAX_MPROTECT
72125+ if (mm->binfmt && mm->binfmt->handle_mprotect)
72126+ mm->binfmt->handle_mprotect(vma, newflags);
72127+#endif
72128+
72129 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
72130- vm_get_page_prot(newflags));
72131+ vm_get_page_prot(vma->vm_flags));
72132
72133 if (vma_wants_writenotify(vma)) {
72134 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
72135@@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72136 end = start + len;
72137 if (end <= start)
72138 return -ENOMEM;
72139+
72140+#ifdef CONFIG_PAX_SEGMEXEC
72141+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
72142+ if (end > SEGMEXEC_TASK_SIZE)
72143+ return -EINVAL;
72144+ } else
72145+#endif
72146+
72147+ if (end > TASK_SIZE)
72148+ return -EINVAL;
72149+
72150 if (!arch_validate_prot(prot))
72151 return -EINVAL;
72152
72153@@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72154 /*
72155 * Does the application expect PROT_READ to imply PROT_EXEC:
72156 */
72157- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72158+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72159 prot |= PROT_EXEC;
72160
72161 vm_flags = calc_vm_prot_bits(prot);
72162@@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72163 if (start > vma->vm_start)
72164 prev = vma;
72165
72166+#ifdef CONFIG_PAX_MPROTECT
72167+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
72168+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
72169+#endif
72170+
72171 for (nstart = start ; ; ) {
72172 unsigned long newflags;
72173
72174@@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72175
72176 /* newflags >> 4 shift VM_MAY% in place of VM_% */
72177 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
72178+ if (prot & (PROT_WRITE | PROT_EXEC))
72179+ gr_log_rwxmprotect(vma->vm_file);
72180+
72181+ error = -EACCES;
72182+ goto out;
72183+ }
72184+
72185+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
72186 error = -EACCES;
72187 goto out;
72188 }
72189@@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72190 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
72191 if (error)
72192 goto out;
72193+
72194+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
72195+
72196 nstart = tmp;
72197
72198 if (nstart < prev->vm_end)
72199diff --git a/mm/mremap.c b/mm/mremap.c
72200index db8d983..76506cb 100644
72201--- a/mm/mremap.c
72202+++ b/mm/mremap.c
72203@@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
72204 continue;
72205 pte = ptep_get_and_clear(mm, old_addr, old_pte);
72206 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
72207+
72208+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
72209+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
72210+ pte = pte_exprotect(pte);
72211+#endif
72212+
72213 set_pte_at(mm, new_addr, new_pte, pte);
72214 }
72215
72216@@ -299,6 +305,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
72217 if (is_vm_hugetlb_page(vma))
72218 goto Einval;
72219
72220+#ifdef CONFIG_PAX_SEGMEXEC
72221+ if (pax_find_mirror_vma(vma))
72222+ goto Einval;
72223+#endif
72224+
72225 /* We can't remap across vm area boundaries */
72226 if (old_len > vma->vm_end - addr)
72227 goto Efault;
72228@@ -355,20 +366,25 @@ static unsigned long mremap_to(unsigned long addr,
72229 unsigned long ret = -EINVAL;
72230 unsigned long charged = 0;
72231 unsigned long map_flags;
72232+ unsigned long pax_task_size = TASK_SIZE;
72233
72234 if (new_addr & ~PAGE_MASK)
72235 goto out;
72236
72237- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
72238+#ifdef CONFIG_PAX_SEGMEXEC
72239+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
72240+ pax_task_size = SEGMEXEC_TASK_SIZE;
72241+#endif
72242+
72243+ pax_task_size -= PAGE_SIZE;
72244+
72245+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
72246 goto out;
72247
72248 /* Check if the location we're moving into overlaps the
72249 * old location at all, and fail if it does.
72250 */
72251- if ((new_addr <= addr) && (new_addr+new_len) > addr)
72252- goto out;
72253-
72254- if ((addr <= new_addr) && (addr+old_len) > new_addr)
72255+ if (addr + old_len > new_addr && new_addr + new_len > addr)
72256 goto out;
72257
72258 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
72259@@ -440,6 +456,7 @@ unsigned long do_mremap(unsigned long addr,
72260 struct vm_area_struct *vma;
72261 unsigned long ret = -EINVAL;
72262 unsigned long charged = 0;
72263+ unsigned long pax_task_size = TASK_SIZE;
72264
72265 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
72266 goto out;
72267@@ -458,6 +475,17 @@ unsigned long do_mremap(unsigned long addr,
72268 if (!new_len)
72269 goto out;
72270
72271+#ifdef CONFIG_PAX_SEGMEXEC
72272+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
72273+ pax_task_size = SEGMEXEC_TASK_SIZE;
72274+#endif
72275+
72276+ pax_task_size -= PAGE_SIZE;
72277+
72278+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
72279+ old_len > pax_task_size || addr > pax_task_size-old_len)
72280+ goto out;
72281+
72282 if (flags & MREMAP_FIXED) {
72283 if (flags & MREMAP_MAYMOVE)
72284 ret = mremap_to(addr, old_len, new_addr, new_len);
72285@@ -507,6 +535,7 @@ unsigned long do_mremap(unsigned long addr,
72286 addr + new_len);
72287 }
72288 ret = addr;
72289+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
72290 goto out;
72291 }
72292 }
72293@@ -533,7 +562,13 @@ unsigned long do_mremap(unsigned long addr,
72294 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
72295 if (ret)
72296 goto out;
72297+
72298+ map_flags = vma->vm_flags;
72299 ret = move_vma(vma, addr, old_len, new_len, new_addr);
72300+ if (!(ret & ~PAGE_MASK)) {
72301+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
72302+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
72303+ }
72304 }
72305 out:
72306 if (ret & ~PAGE_MASK)
72307diff --git a/mm/nommu.c b/mm/nommu.c
72308index bb8f4f0..40d3e02 100644
72309--- a/mm/nommu.c
72310+++ b/mm/nommu.c
72311@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
72312 int sysctl_overcommit_ratio = 50; /* default is 50% */
72313 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
72314 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
72315-int heap_stack_gap = 0;
72316
72317 atomic_long_t mmap_pages_allocated;
72318
72319@@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
72320 EXPORT_SYMBOL(find_vma);
72321
72322 /*
72323- * find a VMA
72324- * - we don't extend stack VMAs under NOMMU conditions
72325- */
72326-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
72327-{
72328- return find_vma(mm, addr);
72329-}
72330-
72331-/*
72332 * expand a stack to a given address
72333 * - not supported under NOMMU conditions
72334 */
72335@@ -1580,6 +1570,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72336
72337 /* most fields are the same, copy all, and then fixup */
72338 *new = *vma;
72339+ INIT_LIST_HEAD(&new->anon_vma_chain);
72340 *region = *vma->vm_region;
72341 new->vm_region = region;
72342
72343diff --git a/mm/page_alloc.c b/mm/page_alloc.c
72344index 918330f..ae99ae1 100644
72345--- a/mm/page_alloc.c
72346+++ b/mm/page_alloc.c
72347@@ -335,7 +335,7 @@ out:
72348 * This usage means that zero-order pages may not be compound.
72349 */
72350
72351-static void free_compound_page(struct page *page)
72352+void free_compound_page(struct page *page)
72353 {
72354 __free_pages_ok(page, compound_order(page));
72355 }
72356@@ -692,6 +692,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
72357 int i;
72358 int bad = 0;
72359
72360+#ifdef CONFIG_PAX_MEMORY_SANITIZE
72361+ unsigned long index = 1UL << order;
72362+#endif
72363+
72364 trace_mm_page_free(page, order);
72365 kmemcheck_free_shadow(page, order);
72366
72367@@ -707,6 +711,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
72368 debug_check_no_obj_freed(page_address(page),
72369 PAGE_SIZE << order);
72370 }
72371+
72372+#ifdef CONFIG_PAX_MEMORY_SANITIZE
72373+ for (; index; --index)
72374+ sanitize_highpage(page + index - 1);
72375+#endif
72376+
72377 arch_free_page(page, order);
72378 kernel_map_pages(page, 1 << order, 0);
72379
72380@@ -830,8 +840,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
72381 arch_alloc_page(page, order);
72382 kernel_map_pages(page, 1 << order, 1);
72383
72384+#ifndef CONFIG_PAX_MEMORY_SANITIZE
72385 if (gfp_flags & __GFP_ZERO)
72386 prep_zero_page(page, order, gfp_flags);
72387+#endif
72388
72389 if (order && (gfp_flags & __GFP_COMP))
72390 prep_compound_page(page, order);
72391@@ -3523,7 +3535,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
72392 unsigned long pfn;
72393
72394 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
72395+#ifdef CONFIG_X86_32
72396+ /* boot failures in VMware 8 on 32bit vanilla since
72397+ this change */
72398+ if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
72399+#else
72400 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
72401+#endif
72402 return 1;
72403 }
72404 return 0;
72405diff --git a/mm/percpu.c b/mm/percpu.c
72406index bb4be74..a43ea85 100644
72407--- a/mm/percpu.c
72408+++ b/mm/percpu.c
72409@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
72410 static unsigned int pcpu_high_unit_cpu __read_mostly;
72411
72412 /* the address of the first chunk which starts with the kernel static area */
72413-void *pcpu_base_addr __read_mostly;
72414+void *pcpu_base_addr __read_only;
72415 EXPORT_SYMBOL_GPL(pcpu_base_addr);
72416
72417 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
72418diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
72419index c20ff48..137702a 100644
72420--- a/mm/process_vm_access.c
72421+++ b/mm/process_vm_access.c
72422@@ -13,6 +13,7 @@
72423 #include <linux/uio.h>
72424 #include <linux/sched.h>
72425 #include <linux/highmem.h>
72426+#include <linux/security.h>
72427 #include <linux/ptrace.h>
72428 #include <linux/slab.h>
72429 #include <linux/syscalls.h>
72430@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
72431 size_t iov_l_curr_offset = 0;
72432 ssize_t iov_len;
72433
72434+ return -ENOSYS; // PaX: until properly audited
72435+
72436 /*
72437 * Work out how many pages of struct pages we're going to need
72438 * when eventually calling get_user_pages
72439 */
72440 for (i = 0; i < riovcnt; i++) {
72441 iov_len = rvec[i].iov_len;
72442- if (iov_len > 0) {
72443- nr_pages_iov = ((unsigned long)rvec[i].iov_base
72444- + iov_len)
72445- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
72446- / PAGE_SIZE + 1;
72447- nr_pages = max(nr_pages, nr_pages_iov);
72448- }
72449+ if (iov_len <= 0)
72450+ continue;
72451+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
72452+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
72453+ nr_pages = max(nr_pages, nr_pages_iov);
72454 }
72455
72456 if (nr_pages == 0)
72457@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
72458 goto free_proc_pages;
72459 }
72460
72461+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
72462+ rc = -EPERM;
72463+ goto put_task_struct;
72464+ }
72465+
72466 mm = mm_access(task, PTRACE_MODE_ATTACH);
72467 if (!mm || IS_ERR(mm)) {
72468 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
72469diff --git a/mm/rmap.c b/mm/rmap.c
72470index 5b5ad58..0f77903 100644
72471--- a/mm/rmap.c
72472+++ b/mm/rmap.c
72473@@ -167,6 +167,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
72474 struct anon_vma *anon_vma = vma->anon_vma;
72475 struct anon_vma_chain *avc;
72476
72477+#ifdef CONFIG_PAX_SEGMEXEC
72478+ struct anon_vma_chain *avc_m = NULL;
72479+#endif
72480+
72481 might_sleep();
72482 if (unlikely(!anon_vma)) {
72483 struct mm_struct *mm = vma->vm_mm;
72484@@ -176,6 +180,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
72485 if (!avc)
72486 goto out_enomem;
72487
72488+#ifdef CONFIG_PAX_SEGMEXEC
72489+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
72490+ if (!avc_m)
72491+ goto out_enomem_free_avc;
72492+#endif
72493+
72494 anon_vma = find_mergeable_anon_vma(vma);
72495 allocated = NULL;
72496 if (!anon_vma) {
72497@@ -189,6 +199,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
72498 /* page_table_lock to protect against threads */
72499 spin_lock(&mm->page_table_lock);
72500 if (likely(!vma->anon_vma)) {
72501+
72502+#ifdef CONFIG_PAX_SEGMEXEC
72503+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
72504+
72505+ if (vma_m) {
72506+ BUG_ON(vma_m->anon_vma);
72507+ vma_m->anon_vma = anon_vma;
72508+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
72509+ avc_m = NULL;
72510+ }
72511+#endif
72512+
72513 vma->anon_vma = anon_vma;
72514 anon_vma_chain_link(vma, avc, anon_vma);
72515 allocated = NULL;
72516@@ -199,12 +221,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
72517
72518 if (unlikely(allocated))
72519 put_anon_vma(allocated);
72520+
72521+#ifdef CONFIG_PAX_SEGMEXEC
72522+ if (unlikely(avc_m))
72523+ anon_vma_chain_free(avc_m);
72524+#endif
72525+
72526 if (unlikely(avc))
72527 anon_vma_chain_free(avc);
72528 }
72529 return 0;
72530
72531 out_enomem_free_avc:
72532+
72533+#ifdef CONFIG_PAX_SEGMEXEC
72534+ if (avc_m)
72535+ anon_vma_chain_free(avc_m);
72536+#endif
72537+
72538 anon_vma_chain_free(avc);
72539 out_enomem:
72540 return -ENOMEM;
72541@@ -240,7 +274,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
72542 * Attach the anon_vmas from src to dst.
72543 * Returns 0 on success, -ENOMEM on failure.
72544 */
72545-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
72546+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
72547 {
72548 struct anon_vma_chain *avc, *pavc;
72549 struct anon_vma *root = NULL;
72550@@ -318,7 +352,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
72551 * the corresponding VMA in the parent process is attached to.
72552 * Returns 0 on success, non-zero on failure.
72553 */
72554-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
72555+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
72556 {
72557 struct anon_vma_chain *avc;
72558 struct anon_vma *anon_vma;
72559diff --git a/mm/shmem.c b/mm/shmem.c
72560index f99ff3e..faea8b6 100644
72561--- a/mm/shmem.c
72562+++ b/mm/shmem.c
72563@@ -31,7 +31,7 @@
72564 #include <linux/export.h>
72565 #include <linux/swap.h>
72566
72567-static struct vfsmount *shm_mnt;
72568+struct vfsmount *shm_mnt;
72569
72570 #ifdef CONFIG_SHMEM
72571 /*
72572@@ -74,7 +74,7 @@ static struct vfsmount *shm_mnt;
72573 #define BOGO_DIRENT_SIZE 20
72574
72575 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
72576-#define SHORT_SYMLINK_LEN 128
72577+#define SHORT_SYMLINK_LEN 64
72578
72579 struct shmem_xattr {
72580 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
72581@@ -2235,8 +2235,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
72582 int err = -ENOMEM;
72583
72584 /* Round up to L1_CACHE_BYTES to resist false sharing */
72585- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
72586- L1_CACHE_BYTES), GFP_KERNEL);
72587+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
72588 if (!sbinfo)
72589 return -ENOMEM;
72590
72591diff --git a/mm/slab.c b/mm/slab.c
72592index e901a36..ee8fe97 100644
72593--- a/mm/slab.c
72594+++ b/mm/slab.c
72595@@ -153,7 +153,7 @@
72596
72597 /* Legal flag mask for kmem_cache_create(). */
72598 #if DEBUG
72599-# define CREATE_MASK (SLAB_RED_ZONE | \
72600+# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
72601 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
72602 SLAB_CACHE_DMA | \
72603 SLAB_STORE_USER | \
72604@@ -161,7 +161,7 @@
72605 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
72606 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
72607 #else
72608-# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
72609+# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
72610 SLAB_CACHE_DMA | \
72611 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
72612 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
72613@@ -290,7 +290,7 @@ struct kmem_list3 {
72614 * Need this for bootstrapping a per node allocator.
72615 */
72616 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
72617-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
72618+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
72619 #define CACHE_CACHE 0
72620 #define SIZE_AC MAX_NUMNODES
72621 #define SIZE_L3 (2 * MAX_NUMNODES)
72622@@ -391,10 +391,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
72623 if ((x)->max_freeable < i) \
72624 (x)->max_freeable = i; \
72625 } while (0)
72626-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
72627-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
72628-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
72629-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
72630+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
72631+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
72632+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
72633+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
72634 #else
72635 #define STATS_INC_ACTIVE(x) do { } while (0)
72636 #define STATS_DEC_ACTIVE(x) do { } while (0)
72637@@ -542,7 +542,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
72638 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
72639 */
72640 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
72641- const struct slab *slab, void *obj)
72642+ const struct slab *slab, const void *obj)
72643 {
72644 u32 offset = (obj - slab->s_mem);
72645 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
72646@@ -568,7 +568,7 @@ struct cache_names {
72647 static struct cache_names __initdata cache_names[] = {
72648 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
72649 #include <linux/kmalloc_sizes.h>
72650- {NULL,}
72651+ {NULL}
72652 #undef CACHE
72653 };
72654
72655@@ -1588,7 +1588,7 @@ void __init kmem_cache_init(void)
72656 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
72657 sizes[INDEX_AC].cs_size,
72658 ARCH_KMALLOC_MINALIGN,
72659- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
72660+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
72661 NULL);
72662
72663 if (INDEX_AC != INDEX_L3) {
72664@@ -1596,7 +1596,7 @@ void __init kmem_cache_init(void)
72665 kmem_cache_create(names[INDEX_L3].name,
72666 sizes[INDEX_L3].cs_size,
72667 ARCH_KMALLOC_MINALIGN,
72668- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
72669+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
72670 NULL);
72671 }
72672
72673@@ -1614,7 +1614,7 @@ void __init kmem_cache_init(void)
72674 sizes->cs_cachep = kmem_cache_create(names->name,
72675 sizes->cs_size,
72676 ARCH_KMALLOC_MINALIGN,
72677- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
72678+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
72679 NULL);
72680 }
72681 #ifdef CONFIG_ZONE_DMA
72682@@ -4390,10 +4390,10 @@ static int s_show(struct seq_file *m, void *p)
72683 }
72684 /* cpu stats */
72685 {
72686- unsigned long allochit = atomic_read(&cachep->allochit);
72687- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
72688- unsigned long freehit = atomic_read(&cachep->freehit);
72689- unsigned long freemiss = atomic_read(&cachep->freemiss);
72690+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
72691+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
72692+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
72693+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
72694
72695 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
72696 allochit, allocmiss, freehit, freemiss);
72697@@ -4652,13 +4652,62 @@ static int __init slab_proc_init(void)
72698 {
72699 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
72700 #ifdef CONFIG_DEBUG_SLAB_LEAK
72701- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
72702+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
72703 #endif
72704 return 0;
72705 }
72706 module_init(slab_proc_init);
72707 #endif
72708
72709+void check_object_size(const void *ptr, unsigned long n, bool to)
72710+{
72711+
72712+#ifdef CONFIG_PAX_USERCOPY
72713+ struct page *page;
72714+ struct kmem_cache *cachep = NULL;
72715+ struct slab *slabp;
72716+ unsigned int objnr;
72717+ unsigned long offset;
72718+ const char *type;
72719+
72720+ if (!n)
72721+ return;
72722+
72723+ type = "<null>";
72724+ if (ZERO_OR_NULL_PTR(ptr))
72725+ goto report;
72726+
72727+ if (!virt_addr_valid(ptr))
72728+ return;
72729+
72730+ page = virt_to_head_page(ptr);
72731+
72732+ type = "<process stack>";
72733+ if (!PageSlab(page)) {
72734+ if (object_is_on_stack(ptr, n) == -1)
72735+ goto report;
72736+ return;
72737+ }
72738+
72739+ cachep = page_get_cache(page);
72740+ type = cachep->name;
72741+ if (!(cachep->flags & SLAB_USERCOPY))
72742+ goto report;
72743+
72744+ slabp = page_get_slab(page);
72745+ objnr = obj_to_index(cachep, slabp, ptr);
72746+ BUG_ON(objnr >= cachep->num);
72747+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
72748+ if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
72749+ return;
72750+
72751+report:
72752+ pax_report_usercopy(ptr, n, to, type);
72753+#endif
72754+
72755+}
72756+EXPORT_SYMBOL(check_object_size);
72757+
72758 /**
72759 * ksize - get the actual amount of memory allocated for a given object
72760 * @objp: Pointer to the object
72761diff --git a/mm/slob.c b/mm/slob.c
72762index 8105be4..e045f96 100644
72763--- a/mm/slob.c
72764+++ b/mm/slob.c
72765@@ -29,7 +29,7 @@
72766 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
72767 * alloc_pages() directly, allocating compound pages so the page order
72768 * does not have to be separately tracked, and also stores the exact
72769- * allocation size in page->private so that it can be used to accurately
72770+ * allocation size in slob_page->size so that it can be used to accurately
72771 * provide ksize(). These objects are detected in kfree() because slob_page()
72772 * is false for them.
72773 *
72774@@ -58,6 +58,7 @@
72775 */
72776
72777 #include <linux/kernel.h>
72778+#include <linux/sched.h>
72779 #include <linux/slab.h>
72780 #include <linux/mm.h>
72781 #include <linux/swap.h> /* struct reclaim_state */
72782@@ -102,7 +103,8 @@ struct slob_page {
72783 unsigned long flags; /* mandatory */
72784 atomic_t _count; /* mandatory */
72785 slobidx_t units; /* free units left in page */
72786- unsigned long pad[2];
72787+ unsigned long pad[1];
72788+ unsigned long size; /* size when >=PAGE_SIZE */
72789 slob_t *free; /* first free slob_t in page */
72790 struct list_head list; /* linked list of free pages */
72791 };
72792@@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
72793 */
72794 static inline int is_slob_page(struct slob_page *sp)
72795 {
72796- return PageSlab((struct page *)sp);
72797+ return PageSlab((struct page *)sp) && !sp->size;
72798 }
72799
72800 static inline void set_slob_page(struct slob_page *sp)
72801@@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
72802
72803 static inline struct slob_page *slob_page(const void *addr)
72804 {
72805- return (struct slob_page *)virt_to_page(addr);
72806+ return (struct slob_page *)virt_to_head_page(addr);
72807 }
72808
72809 /*
72810@@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
72811 /*
72812 * Return the size of a slob block.
72813 */
72814-static slobidx_t slob_units(slob_t *s)
72815+static slobidx_t slob_units(const slob_t *s)
72816 {
72817 if (s->units > 0)
72818 return s->units;
72819@@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
72820 /*
72821 * Return the next free slob block pointer after this one.
72822 */
72823-static slob_t *slob_next(slob_t *s)
72824+static slob_t *slob_next(const slob_t *s)
72825 {
72826 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
72827 slobidx_t next;
72828@@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
72829 /*
72830 * Returns true if s is the last free block in its page.
72831 */
72832-static int slob_last(slob_t *s)
72833+static int slob_last(const slob_t *s)
72834 {
72835 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
72836 }
72837@@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
72838 if (!page)
72839 return NULL;
72840
72841+ set_slob_page(page);
72842 return page_address(page);
72843 }
72844
72845@@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
72846 if (!b)
72847 return NULL;
72848 sp = slob_page(b);
72849- set_slob_page(sp);
72850
72851 spin_lock_irqsave(&slob_lock, flags);
72852 sp->units = SLOB_UNITS(PAGE_SIZE);
72853 sp->free = b;
72854+ sp->size = 0;
72855 INIT_LIST_HEAD(&sp->list);
72856 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
72857 set_slob_page_free(sp, slob_list);
72858@@ -476,10 +479,9 @@ out:
72859 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
72860 */
72861
72862-void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72863+static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
72864 {
72865- unsigned int *m;
72866- int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
72867+ slob_t *m;
72868 void *ret;
72869
72870 gfp &= gfp_allowed_mask;
72871@@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72872
72873 if (!m)
72874 return NULL;
72875- *m = size;
72876+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
72877+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
72878+ m[0].units = size;
72879+ m[1].units = align;
72880 ret = (void *)m + align;
72881
72882 trace_kmalloc_node(_RET_IP_, ret,
72883@@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72884 gfp |= __GFP_COMP;
72885 ret = slob_new_pages(gfp, order, node);
72886 if (ret) {
72887- struct page *page;
72888- page = virt_to_page(ret);
72889- page->private = size;
72890+ struct slob_page *sp;
72891+ sp = slob_page(ret);
72892+ sp->size = size;
72893 }
72894
72895 trace_kmalloc_node(_RET_IP_, ret,
72896 size, PAGE_SIZE << order, gfp, node);
72897 }
72898
72899- kmemleak_alloc(ret, size, 1, gfp);
72900+ return ret;
72901+}
72902+
72903+void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72904+{
72905+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
72906+ void *ret = __kmalloc_node_align(size, gfp, node, align);
72907+
72908+ if (!ZERO_OR_NULL_PTR(ret))
72909+ kmemleak_alloc(ret, size, 1, gfp);
72910 return ret;
72911 }
72912 EXPORT_SYMBOL(__kmalloc_node);
72913@@ -533,13 +547,92 @@ void kfree(const void *block)
72914 sp = slob_page(block);
72915 if (is_slob_page(sp)) {
72916 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
72917- unsigned int *m = (unsigned int *)(block - align);
72918- slob_free(m, *m + align);
72919- } else
72920+ slob_t *m = (slob_t *)(block - align);
72921+ slob_free(m, m[0].units + align);
72922+ } else {
72923+ clear_slob_page(sp);
72924+ free_slob_page(sp);
72925+ sp->size = 0;
72926 put_page(&sp->page);
72927+ }
72928 }
72929 EXPORT_SYMBOL(kfree);
72930
72931+void check_object_size(const void *ptr, unsigned long n, bool to)
72932+{
72933+
72934+#ifdef CONFIG_PAX_USERCOPY
72935+ struct slob_page *sp;
72936+ const slob_t *free;
72937+ const void *base;
72938+ unsigned long flags;
72939+ const char *type;
72940+
72941+ if (!n)
72942+ return;
72943+
72944+ type = "<null>";
72945+ if (ZERO_OR_NULL_PTR(ptr))
72946+ goto report;
72947+
72948+ if (!virt_addr_valid(ptr))
72949+ return;
72950+
72951+ type = "<process stack>";
72952+ sp = slob_page(ptr);
72953+ if (!PageSlab((struct page *)sp)) {
72954+ if (object_is_on_stack(ptr, n) == -1)
72955+ goto report;
72956+ return;
72957+ }
72958+
72959+ type = "<slob>";
72960+ if (sp->size) {
72961+ base = page_address(&sp->page);
72962+ if (base <= ptr && n <= sp->size - (ptr - base))
72963+ return;
72964+ goto report;
72965+ }
72966+
72967+ /* some tricky double walking to find the chunk */
72968+ spin_lock_irqsave(&slob_lock, flags);
72969+ base = (void *)((unsigned long)ptr & PAGE_MASK);
72970+ free = sp->free;
72971+
72972+ while (!slob_last(free) && (void *)free <= ptr) {
72973+ base = free + slob_units(free);
72974+ free = slob_next(free);
72975+ }
72976+
72977+ while (base < (void *)free) {
72978+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
72979+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
72980+ int offset;
72981+
72982+ if (ptr < base + align)
72983+ break;
72984+
72985+ offset = ptr - base - align;
72986+ if (offset >= m) {
72987+ base += size;
72988+ continue;
72989+ }
72990+
72991+ if (n > m - offset)
72992+ break;
72993+
72994+ spin_unlock_irqrestore(&slob_lock, flags);
72995+ return;
72996+ }
72997+
72998+ spin_unlock_irqrestore(&slob_lock, flags);
72999+report:
73000+ pax_report_usercopy(ptr, n, to, type);
73001+#endif
73002+
73003+}
73004+EXPORT_SYMBOL(check_object_size);
73005+
73006 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
73007 size_t ksize(const void *block)
73008 {
73009@@ -552,10 +645,10 @@ size_t ksize(const void *block)
73010 sp = slob_page(block);
73011 if (is_slob_page(sp)) {
73012 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73013- unsigned int *m = (unsigned int *)(block - align);
73014- return SLOB_UNITS(*m) * SLOB_UNIT;
73015+ slob_t *m = (slob_t *)(block - align);
73016+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
73017 } else
73018- return sp->page.private;
73019+ return sp->size;
73020 }
73021 EXPORT_SYMBOL(ksize);
73022
73023@@ -571,8 +664,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73024 {
73025 struct kmem_cache *c;
73026
73027+#ifdef CONFIG_PAX_USERCOPY
73028+ c = __kmalloc_node_align(sizeof(struct kmem_cache),
73029+ GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
73030+#else
73031 c = slob_alloc(sizeof(struct kmem_cache),
73032 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
73033+#endif
73034
73035 if (c) {
73036 c->name = name;
73037@@ -614,17 +712,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
73038
73039 lockdep_trace_alloc(flags);
73040
73041+#ifdef CONFIG_PAX_USERCOPY
73042+ b = __kmalloc_node_align(c->size, flags, node, c->align);
73043+#else
73044 if (c->size < PAGE_SIZE) {
73045 b = slob_alloc(c->size, flags, c->align, node);
73046 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
73047 SLOB_UNITS(c->size) * SLOB_UNIT,
73048 flags, node);
73049 } else {
73050+ struct slob_page *sp;
73051+
73052 b = slob_new_pages(flags, get_order(c->size), node);
73053+ sp = slob_page(b);
73054+ sp->size = c->size;
73055 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
73056 PAGE_SIZE << get_order(c->size),
73057 flags, node);
73058 }
73059+#endif
73060
73061 if (c->ctor)
73062 c->ctor(b);
73063@@ -636,10 +742,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
73064
73065 static void __kmem_cache_free(void *b, int size)
73066 {
73067- if (size < PAGE_SIZE)
73068+ struct slob_page *sp = slob_page(b);
73069+
73070+ if (is_slob_page(sp))
73071 slob_free(b, size);
73072- else
73073+ else {
73074+ clear_slob_page(sp);
73075+ free_slob_page(sp);
73076+ sp->size = 0;
73077 slob_free_pages(b, get_order(size));
73078+ }
73079 }
73080
73081 static void kmem_rcu_free(struct rcu_head *head)
73082@@ -652,17 +764,31 @@ static void kmem_rcu_free(struct rcu_head *head)
73083
73084 void kmem_cache_free(struct kmem_cache *c, void *b)
73085 {
73086+ int size = c->size;
73087+
73088+#ifdef CONFIG_PAX_USERCOPY
73089+ if (size + c->align < PAGE_SIZE) {
73090+ size += c->align;
73091+ b -= c->align;
73092+ }
73093+#endif
73094+
73095 kmemleak_free_recursive(b, c->flags);
73096 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
73097 struct slob_rcu *slob_rcu;
73098- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
73099- slob_rcu->size = c->size;
73100+ slob_rcu = b + (size - sizeof(struct slob_rcu));
73101+ slob_rcu->size = size;
73102 call_rcu(&slob_rcu->head, kmem_rcu_free);
73103 } else {
73104- __kmem_cache_free(b, c->size);
73105+ __kmem_cache_free(b, size);
73106 }
73107
73108+#ifdef CONFIG_PAX_USERCOPY
73109+ trace_kfree(_RET_IP_, b);
73110+#else
73111 trace_kmem_cache_free(_RET_IP_, b);
73112+#endif
73113+
73114 }
73115 EXPORT_SYMBOL(kmem_cache_free);
73116
73117diff --git a/mm/slub.c b/mm/slub.c
73118index 71de9b5..dd263c5 100644
73119--- a/mm/slub.c
73120+++ b/mm/slub.c
73121@@ -209,7 +209,7 @@ struct track {
73122
73123 enum track_item { TRACK_ALLOC, TRACK_FREE };
73124
73125-#ifdef CONFIG_SYSFS
73126+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73127 static int sysfs_slab_add(struct kmem_cache *);
73128 static int sysfs_slab_alias(struct kmem_cache *, const char *);
73129 static void sysfs_slab_remove(struct kmem_cache *);
73130@@ -538,7 +538,7 @@ static void print_track(const char *s, struct track *t)
73131 if (!t->addr)
73132 return;
73133
73134- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
73135+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
73136 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
73137 #ifdef CONFIG_STACKTRACE
73138 {
73139@@ -2603,6 +2603,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
73140
73141 page = virt_to_head_page(x);
73142
73143+ BUG_ON(!PageSlab(page));
73144+
73145 slab_free(s, page, x, _RET_IP_);
73146
73147 trace_kmem_cache_free(_RET_IP_, x);
73148@@ -2636,7 +2638,7 @@ static int slub_min_objects;
73149 * Merge control. If this is set then no merging of slab caches will occur.
73150 * (Could be removed. This was introduced to pacify the merge skeptics.)
73151 */
73152-static int slub_nomerge;
73153+static int slub_nomerge = 1;
73154
73155 /*
73156 * Calculate the order of allocation given an slab object size.
73157@@ -3089,7 +3091,7 @@ static int kmem_cache_open(struct kmem_cache *s,
73158 else
73159 s->cpu_partial = 30;
73160
73161- s->refcount = 1;
73162+ atomic_set(&s->refcount, 1);
73163 #ifdef CONFIG_NUMA
73164 s->remote_node_defrag_ratio = 1000;
73165 #endif
73166@@ -3193,8 +3195,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
73167 void kmem_cache_destroy(struct kmem_cache *s)
73168 {
73169 down_write(&slub_lock);
73170- s->refcount--;
73171- if (!s->refcount) {
73172+ if (atomic_dec_and_test(&s->refcount)) {
73173 list_del(&s->list);
73174 up_write(&slub_lock);
73175 if (kmem_cache_close(s)) {
73176@@ -3405,6 +3406,50 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
73177 EXPORT_SYMBOL(__kmalloc_node);
73178 #endif
73179
73180+void check_object_size(const void *ptr, unsigned long n, bool to)
73181+{
73182+
73183+#ifdef CONFIG_PAX_USERCOPY
73184+ struct page *page;
73185+ struct kmem_cache *s = NULL;
73186+ unsigned long offset;
73187+ const char *type;
73188+
73189+ if (!n)
73190+ return;
73191+
73192+ type = "<null>";
73193+ if (ZERO_OR_NULL_PTR(ptr))
73194+ goto report;
73195+
73196+ if (!virt_addr_valid(ptr))
73197+ return;
73198+
73199+ page = virt_to_head_page(ptr);
73200+
73201+ type = "<process stack>";
73202+ if (!PageSlab(page)) {
73203+ if (object_is_on_stack(ptr, n) == -1)
73204+ goto report;
73205+ return;
73206+ }
73207+
73208+ s = page->slab;
73209+ type = s->name;
73210+ if (!(s->flags & SLAB_USERCOPY))
73211+ goto report;
73212+
73213+ offset = (ptr - page_address(page)) % s->size;
73214+ if (offset <= s->objsize && n <= s->objsize - offset)
73215+ return;
73216+
73217+report:
73218+ pax_report_usercopy(ptr, n, to, type);
73219+#endif
73220+
73221+}
73222+EXPORT_SYMBOL(check_object_size);
73223+
73224 size_t ksize(const void *object)
73225 {
73226 struct page *page;
73227@@ -3679,7 +3724,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
73228 int node;
73229
73230 list_add(&s->list, &slab_caches);
73231- s->refcount = -1;
73232+ atomic_set(&s->refcount, -1);
73233
73234 for_each_node_state(node, N_NORMAL_MEMORY) {
73235 struct kmem_cache_node *n = get_node(s, node);
73236@@ -3799,17 +3844,17 @@ void __init kmem_cache_init(void)
73237
73238 /* Caches that are not of the two-to-the-power-of size */
73239 if (KMALLOC_MIN_SIZE <= 32) {
73240- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
73241+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
73242 caches++;
73243 }
73244
73245 if (KMALLOC_MIN_SIZE <= 64) {
73246- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
73247+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
73248 caches++;
73249 }
73250
73251 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
73252- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
73253+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
73254 caches++;
73255 }
73256
73257@@ -3877,7 +3922,7 @@ static int slab_unmergeable(struct kmem_cache *s)
73258 /*
73259 * We may have set a slab to be unmergeable during bootstrap.
73260 */
73261- if (s->refcount < 0)
73262+ if (atomic_read(&s->refcount) < 0)
73263 return 1;
73264
73265 return 0;
73266@@ -3936,7 +3981,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73267 down_write(&slub_lock);
73268 s = find_mergeable(size, align, flags, name, ctor);
73269 if (s) {
73270- s->refcount++;
73271+ atomic_inc(&s->refcount);
73272 /*
73273 * Adjust the object sizes so that we clear
73274 * the complete object on kzalloc.
73275@@ -3945,7 +3990,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73276 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
73277
73278 if (sysfs_slab_alias(s, name)) {
73279- s->refcount--;
73280+ atomic_dec(&s->refcount);
73281 goto err;
73282 }
73283 up_write(&slub_lock);
73284@@ -4074,7 +4119,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
73285 }
73286 #endif
73287
73288-#ifdef CONFIG_SYSFS
73289+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73290 static int count_inuse(struct page *page)
73291 {
73292 return page->inuse;
73293@@ -4461,12 +4506,12 @@ static void resiliency_test(void)
73294 validate_slab_cache(kmalloc_caches[9]);
73295 }
73296 #else
73297-#ifdef CONFIG_SYSFS
73298+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73299 static void resiliency_test(void) {};
73300 #endif
73301 #endif
73302
73303-#ifdef CONFIG_SYSFS
73304+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73305 enum slab_stat_type {
73306 SL_ALL, /* All slabs */
73307 SL_PARTIAL, /* Only partially allocated slabs */
73308@@ -4709,7 +4754,7 @@ SLAB_ATTR_RO(ctor);
73309
73310 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
73311 {
73312- return sprintf(buf, "%d\n", s->refcount - 1);
73313+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
73314 }
73315 SLAB_ATTR_RO(aliases);
73316
73317@@ -5280,6 +5325,7 @@ static char *create_unique_id(struct kmem_cache *s)
73318 return name;
73319 }
73320
73321+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73322 static int sysfs_slab_add(struct kmem_cache *s)
73323 {
73324 int err;
73325@@ -5342,6 +5388,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
73326 kobject_del(&s->kobj);
73327 kobject_put(&s->kobj);
73328 }
73329+#endif
73330
73331 /*
73332 * Need to buffer aliases during bootup until sysfs becomes
73333@@ -5355,6 +5402,7 @@ struct saved_alias {
73334
73335 static struct saved_alias *alias_list;
73336
73337+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73338 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
73339 {
73340 struct saved_alias *al;
73341@@ -5377,6 +5425,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
73342 alias_list = al;
73343 return 0;
73344 }
73345+#endif
73346
73347 static int __init slab_sysfs_init(void)
73348 {
73349diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
73350index 1b7e22a..3fcd4f3 100644
73351--- a/mm/sparse-vmemmap.c
73352+++ b/mm/sparse-vmemmap.c
73353@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
73354 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
73355 if (!p)
73356 return NULL;
73357- pud_populate(&init_mm, pud, p);
73358+ pud_populate_kernel(&init_mm, pud, p);
73359 }
73360 return pud;
73361 }
73362@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
73363 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
73364 if (!p)
73365 return NULL;
73366- pgd_populate(&init_mm, pgd, p);
73367+ pgd_populate_kernel(&init_mm, pgd, p);
73368 }
73369 return pgd;
73370 }
73371diff --git a/mm/swap.c b/mm/swap.c
73372index 5c13f13..f1cfc13 100644
73373--- a/mm/swap.c
73374+++ b/mm/swap.c
73375@@ -30,6 +30,7 @@
73376 #include <linux/backing-dev.h>
73377 #include <linux/memcontrol.h>
73378 #include <linux/gfp.h>
73379+#include <linux/hugetlb.h>
73380
73381 #include "internal.h"
73382
73383@@ -70,6 +71,8 @@ static void __put_compound_page(struct page *page)
73384
73385 __page_cache_release(page);
73386 dtor = get_compound_page_dtor(page);
73387+ if (!PageHuge(page))
73388+ BUG_ON(dtor != free_compound_page);
73389 (*dtor)(page);
73390 }
73391
73392diff --git a/mm/swapfile.c b/mm/swapfile.c
73393index 38186d9..bfba6d3 100644
73394--- a/mm/swapfile.c
73395+++ b/mm/swapfile.c
73396@@ -61,7 +61,7 @@ static DEFINE_MUTEX(swapon_mutex);
73397
73398 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
73399 /* Activity counter to indicate that a swapon or swapoff has occurred */
73400-static atomic_t proc_poll_event = ATOMIC_INIT(0);
73401+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
73402
73403 static inline unsigned char swap_count(unsigned char ent)
73404 {
73405@@ -1671,7 +1671,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
73406 }
73407 filp_close(swap_file, NULL);
73408 err = 0;
73409- atomic_inc(&proc_poll_event);
73410+ atomic_inc_unchecked(&proc_poll_event);
73411 wake_up_interruptible(&proc_poll_wait);
73412
73413 out_dput:
73414@@ -1687,8 +1687,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
73415
73416 poll_wait(file, &proc_poll_wait, wait);
73417
73418- if (seq->poll_event != atomic_read(&proc_poll_event)) {
73419- seq->poll_event = atomic_read(&proc_poll_event);
73420+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
73421+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
73422 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
73423 }
73424
73425@@ -1786,7 +1786,7 @@ static int swaps_open(struct inode *inode, struct file *file)
73426 return ret;
73427
73428 seq = file->private_data;
73429- seq->poll_event = atomic_read(&proc_poll_event);
73430+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
73431 return 0;
73432 }
73433
73434@@ -2123,7 +2123,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
73435 (p->flags & SWP_DISCARDABLE) ? "D" : "");
73436
73437 mutex_unlock(&swapon_mutex);
73438- atomic_inc(&proc_poll_event);
73439+ atomic_inc_unchecked(&proc_poll_event);
73440 wake_up_interruptible(&proc_poll_wait);
73441
73442 if (S_ISREG(inode->i_mode))
73443diff --git a/mm/util.c b/mm/util.c
73444index ae962b3..0bba886 100644
73445--- a/mm/util.c
73446+++ b/mm/util.c
73447@@ -284,6 +284,12 @@ done:
73448 void arch_pick_mmap_layout(struct mm_struct *mm)
73449 {
73450 mm->mmap_base = TASK_UNMAPPED_BASE;
73451+
73452+#ifdef CONFIG_PAX_RANDMMAP
73453+ if (mm->pax_flags & MF_PAX_RANDMMAP)
73454+ mm->mmap_base += mm->delta_mmap;
73455+#endif
73456+
73457 mm->get_unmapped_area = arch_get_unmapped_area;
73458 mm->unmap_area = arch_unmap_area;
73459 }
73460diff --git a/mm/vmalloc.c b/mm/vmalloc.c
73461index 1196c77..2e608e8 100644
73462--- a/mm/vmalloc.c
73463+++ b/mm/vmalloc.c
73464@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
73465
73466 pte = pte_offset_kernel(pmd, addr);
73467 do {
73468- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
73469- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
73470+
73471+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
73472+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
73473+ BUG_ON(!pte_exec(*pte));
73474+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
73475+ continue;
73476+ }
73477+#endif
73478+
73479+ {
73480+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
73481+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
73482+ }
73483 } while (pte++, addr += PAGE_SIZE, addr != end);
73484 }
73485
73486@@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
73487 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
73488 {
73489 pte_t *pte;
73490+ int ret = -ENOMEM;
73491
73492 /*
73493 * nr is a running index into the array which helps higher level
73494@@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
73495 pte = pte_alloc_kernel(pmd, addr);
73496 if (!pte)
73497 return -ENOMEM;
73498+
73499+ pax_open_kernel();
73500 do {
73501 struct page *page = pages[*nr];
73502
73503- if (WARN_ON(!pte_none(*pte)))
73504- return -EBUSY;
73505- if (WARN_ON(!page))
73506- return -ENOMEM;
73507+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
73508+ if (pgprot_val(prot) & _PAGE_NX)
73509+#endif
73510+
73511+ if (WARN_ON(!pte_none(*pte))) {
73512+ ret = -EBUSY;
73513+ goto out;
73514+ }
73515+ if (WARN_ON(!page)) {
73516+ ret = -ENOMEM;
73517+ goto out;
73518+ }
73519 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
73520 (*nr)++;
73521 } while (pte++, addr += PAGE_SIZE, addr != end);
73522- return 0;
73523+ ret = 0;
73524+out:
73525+ pax_close_kernel();
73526+ return ret;
73527 }
73528
73529 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
73530@@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
73531 pmd_t *pmd;
73532 unsigned long next;
73533
73534- pmd = pmd_alloc(&init_mm, pud, addr);
73535+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
73536 if (!pmd)
73537 return -ENOMEM;
73538 do {
73539@@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
73540 pud_t *pud;
73541 unsigned long next;
73542
73543- pud = pud_alloc(&init_mm, pgd, addr);
73544+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
73545 if (!pud)
73546 return -ENOMEM;
73547 do {
73548@@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
73549 * and fall back on vmalloc() if that fails. Others
73550 * just put it in the vmalloc space.
73551 */
73552-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
73553+#ifdef CONFIG_MODULES
73554+#ifdef MODULES_VADDR
73555 unsigned long addr = (unsigned long)x;
73556 if (addr >= MODULES_VADDR && addr < MODULES_END)
73557 return 1;
73558 #endif
73559+
73560+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
73561+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
73562+ return 1;
73563+#endif
73564+
73565+#endif
73566+
73567 return is_vmalloc_addr(x);
73568 }
73569
73570@@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
73571
73572 if (!pgd_none(*pgd)) {
73573 pud_t *pud = pud_offset(pgd, addr);
73574+#ifdef CONFIG_X86
73575+ if (!pud_large(*pud))
73576+#endif
73577 if (!pud_none(*pud)) {
73578 pmd_t *pmd = pmd_offset(pud, addr);
73579+#ifdef CONFIG_X86
73580+ if (!pmd_large(*pmd))
73581+#endif
73582 if (!pmd_none(*pmd)) {
73583 pte_t *ptep, pte;
73584
73585@@ -332,6 +372,10 @@ static void purge_vmap_area_lazy(void);
73586 static struct vmap_area *alloc_vmap_area(unsigned long size,
73587 unsigned long align,
73588 unsigned long vstart, unsigned long vend,
73589+ int node, gfp_t gfp_mask) __size_overflow(1);
73590+static struct vmap_area *alloc_vmap_area(unsigned long size,
73591+ unsigned long align,
73592+ unsigned long vstart, unsigned long vend,
73593 int node, gfp_t gfp_mask)
73594 {
73595 struct vmap_area *va;
73596@@ -1320,6 +1364,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
73597 struct vm_struct *area;
73598
73599 BUG_ON(in_interrupt());
73600+
73601+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
73602+ if (flags & VM_KERNEXEC) {
73603+ if (start != VMALLOC_START || end != VMALLOC_END)
73604+ return NULL;
73605+ start = (unsigned long)MODULES_EXEC_VADDR;
73606+ end = (unsigned long)MODULES_EXEC_END;
73607+ }
73608+#endif
73609+
73610 if (flags & VM_IOREMAP) {
73611 int bit = fls(size);
73612
73613@@ -1552,6 +1606,11 @@ void *vmap(struct page **pages, unsigned int count,
73614 if (count > totalram_pages)
73615 return NULL;
73616
73617+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
73618+ if (!(pgprot_val(prot) & _PAGE_NX))
73619+ flags |= VM_KERNEXEC;
73620+#endif
73621+
73622 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
73623 __builtin_return_address(0));
73624 if (!area)
73625@@ -1653,6 +1712,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
73626 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
73627 goto fail;
73628
73629+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
73630+ if (!(pgprot_val(prot) & _PAGE_NX))
73631+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
73632+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
73633+ else
73634+#endif
73635+
73636 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
73637 start, end, node, gfp_mask, caller);
73638 if (!area)
73639@@ -1826,10 +1892,9 @@ EXPORT_SYMBOL(vzalloc_node);
73640 * For tight control over page level allocator and protection flags
73641 * use __vmalloc() instead.
73642 */
73643-
73644 void *vmalloc_exec(unsigned long size)
73645 {
73646- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
73647+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
73648 -1, __builtin_return_address(0));
73649 }
73650
73651@@ -2124,6 +2189,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
73652 unsigned long uaddr = vma->vm_start;
73653 unsigned long usize = vma->vm_end - vma->vm_start;
73654
73655+ BUG_ON(vma->vm_mirror);
73656+
73657 if ((PAGE_SIZE-1) & (unsigned long)addr)
73658 return -EINVAL;
73659
73660@@ -2376,8 +2443,8 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
73661 return NULL;
73662 }
73663
73664- vms = kzalloc(sizeof(vms[0]) * nr_vms, GFP_KERNEL);
73665- vas = kzalloc(sizeof(vas[0]) * nr_vms, GFP_KERNEL);
73666+ vms = kcalloc(nr_vms, sizeof(vms[0]), GFP_KERNEL);
73667+ vas = kcalloc(nr_vms, sizeof(vas[0]), GFP_KERNEL);
73668 if (!vas || !vms)
73669 goto err_free2;
73670
73671diff --git a/mm/vmstat.c b/mm/vmstat.c
73672index 7db1b9b..e9f6b07 100644
73673--- a/mm/vmstat.c
73674+++ b/mm/vmstat.c
73675@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
73676 *
73677 * vm_stat contains the global counters
73678 */
73679-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
73680+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
73681 EXPORT_SYMBOL(vm_stat);
73682
73683 #ifdef CONFIG_SMP
73684@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
73685 v = p->vm_stat_diff[i];
73686 p->vm_stat_diff[i] = 0;
73687 local_irq_restore(flags);
73688- atomic_long_add(v, &zone->vm_stat[i]);
73689+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
73690 global_diff[i] += v;
73691 #ifdef CONFIG_NUMA
73692 /* 3 seconds idle till flush */
73693@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
73694
73695 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
73696 if (global_diff[i])
73697- atomic_long_add(global_diff[i], &vm_stat[i]);
73698+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
73699 }
73700
73701 #endif
73702@@ -1208,10 +1208,20 @@ static int __init setup_vmstat(void)
73703 start_cpu_timer(cpu);
73704 #endif
73705 #ifdef CONFIG_PROC_FS
73706- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
73707- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
73708- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
73709- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
73710+ {
73711+ mode_t gr_mode = S_IRUGO;
73712+#ifdef CONFIG_GRKERNSEC_PROC_ADD
73713+ gr_mode = S_IRUSR;
73714+#endif
73715+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
73716+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
73717+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
73718+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
73719+#else
73720+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
73721+#endif
73722+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
73723+ }
73724 #endif
73725 return 0;
73726 }
73727diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
73728index efea35b..9c8dd0b 100644
73729--- a/net/8021q/vlan.c
73730+++ b/net/8021q/vlan.c
73731@@ -554,8 +554,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
73732 err = -EPERM;
73733 if (!capable(CAP_NET_ADMIN))
73734 break;
73735- if ((args.u.name_type >= 0) &&
73736- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
73737+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
73738 struct vlan_net *vn;
73739
73740 vn = net_generic(net, vlan_net_id);
73741diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
73742index fccae26..e7ece2f 100644
73743--- a/net/9p/trans_fd.c
73744+++ b/net/9p/trans_fd.c
73745@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
73746 oldfs = get_fs();
73747 set_fs(get_ds());
73748 /* The cast to a user pointer is valid due to the set_fs() */
73749- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
73750+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
73751 set_fs(oldfs);
73752
73753 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
73754diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
73755index 876fbe8..8bbea9f 100644
73756--- a/net/atm/atm_misc.c
73757+++ b/net/atm/atm_misc.c
73758@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
73759 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
73760 return 1;
73761 atm_return(vcc, truesize);
73762- atomic_inc(&vcc->stats->rx_drop);
73763+ atomic_inc_unchecked(&vcc->stats->rx_drop);
73764 return 0;
73765 }
73766 EXPORT_SYMBOL(atm_charge);
73767@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
73768 }
73769 }
73770 atm_return(vcc, guess);
73771- atomic_inc(&vcc->stats->rx_drop);
73772+ atomic_inc_unchecked(&vcc->stats->rx_drop);
73773 return NULL;
73774 }
73775 EXPORT_SYMBOL(atm_alloc_charge);
73776@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
73777
73778 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
73779 {
73780-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
73781+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
73782 __SONET_ITEMS
73783 #undef __HANDLE_ITEM
73784 }
73785@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
73786
73787 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
73788 {
73789-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
73790+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
73791 __SONET_ITEMS
73792 #undef __HANDLE_ITEM
73793 }
73794diff --git a/net/atm/lec.h b/net/atm/lec.h
73795index dfc0719..47c5322 100644
73796--- a/net/atm/lec.h
73797+++ b/net/atm/lec.h
73798@@ -48,7 +48,7 @@ struct lane2_ops {
73799 const u8 *tlvs, u32 sizeoftlvs);
73800 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
73801 const u8 *tlvs, u32 sizeoftlvs);
73802-};
73803+} __no_const;
73804
73805 /*
73806 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
73807diff --git a/net/atm/mpc.h b/net/atm/mpc.h
73808index 0919a88..a23d54e 100644
73809--- a/net/atm/mpc.h
73810+++ b/net/atm/mpc.h
73811@@ -33,7 +33,7 @@ struct mpoa_client {
73812 struct mpc_parameters parameters; /* parameters for this client */
73813
73814 const struct net_device_ops *old_ops;
73815- struct net_device_ops new_ops;
73816+ net_device_ops_no_const new_ops;
73817 };
73818
73819
73820diff --git a/net/atm/proc.c b/net/atm/proc.c
73821index 0d020de..011c7bb 100644
73822--- a/net/atm/proc.c
73823+++ b/net/atm/proc.c
73824@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
73825 const struct k_atm_aal_stats *stats)
73826 {
73827 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
73828- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
73829- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
73830- atomic_read(&stats->rx_drop));
73831+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
73832+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
73833+ atomic_read_unchecked(&stats->rx_drop));
73834 }
73835
73836 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
73837diff --git a/net/atm/resources.c b/net/atm/resources.c
73838index 23f45ce..c748f1a 100644
73839--- a/net/atm/resources.c
73840+++ b/net/atm/resources.c
73841@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
73842 static void copy_aal_stats(struct k_atm_aal_stats *from,
73843 struct atm_aal_stats *to)
73844 {
73845-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
73846+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
73847 __AAL_STAT_ITEMS
73848 #undef __HANDLE_ITEM
73849 }
73850@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
73851 static void subtract_aal_stats(struct k_atm_aal_stats *from,
73852 struct atm_aal_stats *to)
73853 {
73854-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
73855+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
73856 __AAL_STAT_ITEMS
73857 #undef __HANDLE_ITEM
73858 }
73859diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
73860index a6d5d63..1cc6c2b 100644
73861--- a/net/batman-adv/bat_iv_ogm.c
73862+++ b/net/batman-adv/bat_iv_ogm.c
73863@@ -539,7 +539,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
73864
73865 /* change sequence number to network order */
73866 batman_ogm_packet->seqno =
73867- htonl((uint32_t)atomic_read(&hard_iface->seqno));
73868+ htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
73869
73870 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
73871 batman_ogm_packet->tt_crc = htons((uint16_t)
73872@@ -559,7 +559,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
73873 else
73874 batman_ogm_packet->gw_flags = NO_FLAGS;
73875
73876- atomic_inc(&hard_iface->seqno);
73877+ atomic_inc_unchecked(&hard_iface->seqno);
73878
73879 slide_own_bcast_window(hard_iface);
73880 bat_iv_ogm_queue_add(bat_priv, hard_iface->packet_buff,
73881@@ -917,7 +917,7 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
73882 return;
73883
73884 /* could be changed by schedule_own_packet() */
73885- if_incoming_seqno = atomic_read(&if_incoming->seqno);
73886+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
73887
73888 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
73889
73890diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
73891index 3778977..f6a9450 100644
73892--- a/net/batman-adv/hard-interface.c
73893+++ b/net/batman-adv/hard-interface.c
73894@@ -328,8 +328,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
73895 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
73896 dev_add_pack(&hard_iface->batman_adv_ptype);
73897
73898- atomic_set(&hard_iface->seqno, 1);
73899- atomic_set(&hard_iface->frag_seqno, 1);
73900+ atomic_set_unchecked(&hard_iface->seqno, 1);
73901+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
73902 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
73903 hard_iface->net_dev->name);
73904
73905diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
73906index a5590f4..8d31969 100644
73907--- a/net/batman-adv/soft-interface.c
73908+++ b/net/batman-adv/soft-interface.c
73909@@ -645,7 +645,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
73910
73911 /* set broadcast sequence number */
73912 bcast_packet->seqno =
73913- htonl(atomic_inc_return(&bat_priv->bcast_seqno));
73914+ htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
73915
73916 add_bcast_packet_to_list(bat_priv, skb, 1);
73917
73918@@ -841,7 +841,7 @@ struct net_device *softif_create(const char *name)
73919 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
73920
73921 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
73922- atomic_set(&bat_priv->bcast_seqno, 1);
73923+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
73924 atomic_set(&bat_priv->ttvn, 0);
73925 atomic_set(&bat_priv->tt_local_changes, 0);
73926 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
73927diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
73928index 302efb5..1590365 100644
73929--- a/net/batman-adv/types.h
73930+++ b/net/batman-adv/types.h
73931@@ -38,8 +38,8 @@ struct hard_iface {
73932 int16_t if_num;
73933 char if_status;
73934 struct net_device *net_dev;
73935- atomic_t seqno;
73936- atomic_t frag_seqno;
73937+ atomic_unchecked_t seqno;
73938+ atomic_unchecked_t frag_seqno;
73939 unsigned char *packet_buff;
73940 int packet_len;
73941 struct kobject *hardif_obj;
73942@@ -155,7 +155,7 @@ struct bat_priv {
73943 atomic_t orig_interval; /* uint */
73944 atomic_t hop_penalty; /* uint */
73945 atomic_t log_level; /* uint */
73946- atomic_t bcast_seqno;
73947+ atomic_unchecked_t bcast_seqno;
73948 atomic_t bcast_queue_left;
73949 atomic_t batman_queue_left;
73950 atomic_t ttvn; /* translation table version number */
73951diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
73952index 676f6a6..3b4e668 100644
73953--- a/net/batman-adv/unicast.c
73954+++ b/net/batman-adv/unicast.c
73955@@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
73956 frag1->flags = UNI_FRAG_HEAD | large_tail;
73957 frag2->flags = large_tail;
73958
73959- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
73960+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
73961 frag1->seqno = htons(seqno - 1);
73962 frag2->seqno = htons(seqno);
73963
73964diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
73965index 5238b6b..c9798ce 100644
73966--- a/net/bluetooth/hci_conn.c
73967+++ b/net/bluetooth/hci_conn.c
73968@@ -233,7 +233,7 @@ void hci_le_ltk_reply(struct hci_conn *conn, u8 ltk[16])
73969 memset(&cp, 0, sizeof(cp));
73970
73971 cp.handle = cpu_to_le16(conn->handle);
73972- memcpy(cp.ltk, ltk, sizeof(ltk));
73973+ memcpy(cp.ltk, ltk, sizeof(cp.ltk));
73974
73975 hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
73976 }
73977diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
73978index 6f9c25b..d19fd66 100644
73979--- a/net/bluetooth/l2cap_core.c
73980+++ b/net/bluetooth/l2cap_core.c
73981@@ -2466,8 +2466,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
73982 break;
73983
73984 case L2CAP_CONF_RFC:
73985- if (olen == sizeof(rfc))
73986- memcpy(&rfc, (void *)val, olen);
73987+ if (olen != sizeof(rfc))
73988+ break;
73989+
73990+ memcpy(&rfc, (void *)val, olen);
73991
73992 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
73993 rfc.mode != chan->mode)
73994@@ -2585,8 +2587,10 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
73995
73996 switch (type) {
73997 case L2CAP_CONF_RFC:
73998- if (olen == sizeof(rfc))
73999- memcpy(&rfc, (void *)val, olen);
74000+ if (olen != sizeof(rfc))
74001+ break;
74002+
74003+ memcpy(&rfc, (void *)val, olen);
74004 goto done;
74005 }
74006 }
74007diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
74008index 5fe2ff3..10968b5 100644
74009--- a/net/bridge/netfilter/ebtables.c
74010+++ b/net/bridge/netfilter/ebtables.c
74011@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
74012 tmp.valid_hooks = t->table->valid_hooks;
74013 }
74014 mutex_unlock(&ebt_mutex);
74015- if (copy_to_user(user, &tmp, *len) != 0){
74016+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
74017 BUGPRINT("c2u Didn't work\n");
74018 ret = -EFAULT;
74019 break;
74020diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
74021index 5cf5222..6f704ad 100644
74022--- a/net/caif/cfctrl.c
74023+++ b/net/caif/cfctrl.c
74024@@ -9,6 +9,7 @@
74025 #include <linux/stddef.h>
74026 #include <linux/spinlock.h>
74027 #include <linux/slab.h>
74028+#include <linux/sched.h>
74029 #include <net/caif/caif_layer.h>
74030 #include <net/caif/cfpkt.h>
74031 #include <net/caif/cfctrl.h>
74032@@ -42,8 +43,8 @@ struct cflayer *cfctrl_create(void)
74033 memset(&dev_info, 0, sizeof(dev_info));
74034 dev_info.id = 0xff;
74035 cfsrvl_init(&this->serv, 0, &dev_info, false);
74036- atomic_set(&this->req_seq_no, 1);
74037- atomic_set(&this->rsp_seq_no, 1);
74038+ atomic_set_unchecked(&this->req_seq_no, 1);
74039+ atomic_set_unchecked(&this->rsp_seq_no, 1);
74040 this->serv.layer.receive = cfctrl_recv;
74041 sprintf(this->serv.layer.name, "ctrl");
74042 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
74043@@ -129,8 +130,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
74044 struct cfctrl_request_info *req)
74045 {
74046 spin_lock_bh(&ctrl->info_list_lock);
74047- atomic_inc(&ctrl->req_seq_no);
74048- req->sequence_no = atomic_read(&ctrl->req_seq_no);
74049+ atomic_inc_unchecked(&ctrl->req_seq_no);
74050+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
74051 list_add_tail(&req->list, &ctrl->list);
74052 spin_unlock_bh(&ctrl->info_list_lock);
74053 }
74054@@ -148,7 +149,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
74055 if (p != first)
74056 pr_warn("Requests are not received in order\n");
74057
74058- atomic_set(&ctrl->rsp_seq_no,
74059+ atomic_set_unchecked(&ctrl->rsp_seq_no,
74060 p->sequence_no);
74061 list_del(&p->list);
74062 goto out;
74063diff --git a/net/can/gw.c b/net/can/gw.c
74064index 3d79b12..8de85fa 100644
74065--- a/net/can/gw.c
74066+++ b/net/can/gw.c
74067@@ -96,7 +96,7 @@ struct cf_mod {
74068 struct {
74069 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
74070 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
74071- } csumfunc;
74072+ } __no_const csumfunc;
74073 };
74074
74075
74076diff --git a/net/compat.c b/net/compat.c
74077index e055708..3f80795 100644
74078--- a/net/compat.c
74079+++ b/net/compat.c
74080@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
74081 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
74082 __get_user(kmsg->msg_flags, &umsg->msg_flags))
74083 return -EFAULT;
74084- kmsg->msg_name = compat_ptr(tmp1);
74085- kmsg->msg_iov = compat_ptr(tmp2);
74086- kmsg->msg_control = compat_ptr(tmp3);
74087+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
74088+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
74089+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
74090 return 0;
74091 }
74092
74093@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74094
74095 if (kern_msg->msg_namelen) {
74096 if (mode == VERIFY_READ) {
74097- int err = move_addr_to_kernel(kern_msg->msg_name,
74098+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
74099 kern_msg->msg_namelen,
74100 kern_address);
74101 if (err < 0)
74102@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74103 kern_msg->msg_name = NULL;
74104
74105 tot_len = iov_from_user_compat_to_kern(kern_iov,
74106- (struct compat_iovec __user *)kern_msg->msg_iov,
74107+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
74108 kern_msg->msg_iovlen);
74109 if (tot_len >= 0)
74110 kern_msg->msg_iov = kern_iov;
74111@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74112
74113 #define CMSG_COMPAT_FIRSTHDR(msg) \
74114 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
74115- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
74116+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
74117 (struct compat_cmsghdr __user *)NULL)
74118
74119 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
74120 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
74121 (ucmlen) <= (unsigned long) \
74122 ((mhdr)->msg_controllen - \
74123- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
74124+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
74125
74126 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
74127 struct compat_cmsghdr __user *cmsg, int cmsg_len)
74128 {
74129 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
74130- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
74131+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
74132 msg->msg_controllen)
74133 return NULL;
74134 return (struct compat_cmsghdr __user *)ptr;
74135@@ -219,7 +219,7 @@ Efault:
74136
74137 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
74138 {
74139- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
74140+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
74141 struct compat_cmsghdr cmhdr;
74142 int cmlen;
74143
74144@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
74145
74146 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
74147 {
74148- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
74149+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
74150 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
74151 int fdnum = scm->fp->count;
74152 struct file **fp = scm->fp->fp;
74153@@ -372,7 +372,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
74154 return -EFAULT;
74155 old_fs = get_fs();
74156 set_fs(KERNEL_DS);
74157- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
74158+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
74159 set_fs(old_fs);
74160
74161 return err;
74162@@ -433,7 +433,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
74163 len = sizeof(ktime);
74164 old_fs = get_fs();
74165 set_fs(KERNEL_DS);
74166- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
74167+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
74168 set_fs(old_fs);
74169
74170 if (!err) {
74171@@ -576,7 +576,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
74172 case MCAST_JOIN_GROUP:
74173 case MCAST_LEAVE_GROUP:
74174 {
74175- struct compat_group_req __user *gr32 = (void *)optval;
74176+ struct compat_group_req __user *gr32 = (void __user *)optval;
74177 struct group_req __user *kgr =
74178 compat_alloc_user_space(sizeof(struct group_req));
74179 u32 interface;
74180@@ -597,7 +597,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
74181 case MCAST_BLOCK_SOURCE:
74182 case MCAST_UNBLOCK_SOURCE:
74183 {
74184- struct compat_group_source_req __user *gsr32 = (void *)optval;
74185+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
74186 struct group_source_req __user *kgsr = compat_alloc_user_space(
74187 sizeof(struct group_source_req));
74188 u32 interface;
74189@@ -618,7 +618,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
74190 }
74191 case MCAST_MSFILTER:
74192 {
74193- struct compat_group_filter __user *gf32 = (void *)optval;
74194+ struct compat_group_filter __user *gf32 = (void __user *)optval;
74195 struct group_filter __user *kgf;
74196 u32 interface, fmode, numsrc;
74197
74198@@ -656,7 +656,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
74199 char __user *optval, int __user *optlen,
74200 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
74201 {
74202- struct compat_group_filter __user *gf32 = (void *)optval;
74203+ struct compat_group_filter __user *gf32 = (void __user *)optval;
74204 struct group_filter __user *kgf;
74205 int __user *koptlen;
74206 u32 interface, fmode, numsrc;
74207diff --git a/net/core/datagram.c b/net/core/datagram.c
74208index e4fbfd6..6a6ac94 100644
74209--- a/net/core/datagram.c
74210+++ b/net/core/datagram.c
74211@@ -290,7 +290,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
74212 }
74213
74214 kfree_skb(skb);
74215- atomic_inc(&sk->sk_drops);
74216+ atomic_inc_unchecked(&sk->sk_drops);
74217 sk_mem_reclaim_partial(sk);
74218
74219 return err;
74220diff --git a/net/core/dev.c b/net/core/dev.c
74221index 99e1d75..adf968a 100644
74222--- a/net/core/dev.c
74223+++ b/net/core/dev.c
74224@@ -1136,9 +1136,13 @@ void dev_load(struct net *net, const char *name)
74225 if (no_module && capable(CAP_NET_ADMIN))
74226 no_module = request_module("netdev-%s", name);
74227 if (no_module && capable(CAP_SYS_MODULE)) {
74228+#ifdef CONFIG_GRKERNSEC_MODHARDEN
74229+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
74230+#else
74231 if (!request_module("%s", name))
74232 pr_err("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
74233 name);
74234+#endif
74235 }
74236 }
74237 EXPORT_SYMBOL(dev_load);
74238@@ -1602,7 +1606,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
74239 {
74240 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
74241 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
74242- atomic_long_inc(&dev->rx_dropped);
74243+ atomic_long_inc_unchecked(&dev->rx_dropped);
74244 kfree_skb(skb);
74245 return NET_RX_DROP;
74246 }
74247@@ -1612,7 +1616,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
74248 nf_reset(skb);
74249
74250 if (unlikely(!is_skb_forwardable(dev, skb))) {
74251- atomic_long_inc(&dev->rx_dropped);
74252+ atomic_long_inc_unchecked(&dev->rx_dropped);
74253 kfree_skb(skb);
74254 return NET_RX_DROP;
74255 }
74256@@ -2042,7 +2046,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
74257
74258 struct dev_gso_cb {
74259 void (*destructor)(struct sk_buff *skb);
74260-};
74261+} __no_const;
74262
74263 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
74264
74265@@ -2898,7 +2902,7 @@ enqueue:
74266
74267 local_irq_restore(flags);
74268
74269- atomic_long_inc(&skb->dev->rx_dropped);
74270+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
74271 kfree_skb(skb);
74272 return NET_RX_DROP;
74273 }
74274@@ -2970,7 +2974,7 @@ int netif_rx_ni(struct sk_buff *skb)
74275 }
74276 EXPORT_SYMBOL(netif_rx_ni);
74277
74278-static void net_tx_action(struct softirq_action *h)
74279+static void net_tx_action(void)
74280 {
74281 struct softnet_data *sd = &__get_cpu_var(softnet_data);
74282
74283@@ -3258,7 +3262,7 @@ ncls:
74284 if (pt_prev) {
74285 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
74286 } else {
74287- atomic_long_inc(&skb->dev->rx_dropped);
74288+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
74289 kfree_skb(skb);
74290 /* Jamal, now you will not able to escape explaining
74291 * me how you were going to use this. :-)
74292@@ -3818,7 +3822,7 @@ void netif_napi_del(struct napi_struct *napi)
74293 }
74294 EXPORT_SYMBOL(netif_napi_del);
74295
74296-static void net_rx_action(struct softirq_action *h)
74297+static void net_rx_action(void)
74298 {
74299 struct softnet_data *sd = &__get_cpu_var(softnet_data);
74300 unsigned long time_limit = jiffies + 2;
74301@@ -4288,8 +4292,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
74302 else
74303 seq_printf(seq, "%04x", ntohs(pt->type));
74304
74305+#ifdef CONFIG_GRKERNSEC_HIDESYM
74306+ seq_printf(seq, " %-8s %p\n",
74307+ pt->dev ? pt->dev->name : "", NULL);
74308+#else
74309 seq_printf(seq, " %-8s %pF\n",
74310 pt->dev ? pt->dev->name : "", pt->func);
74311+#endif
74312 }
74313
74314 return 0;
74315@@ -5839,7 +5848,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
74316 } else {
74317 netdev_stats_to_stats64(storage, &dev->stats);
74318 }
74319- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
74320+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
74321 return storage;
74322 }
74323 EXPORT_SYMBOL(dev_get_stats);
74324diff --git a/net/core/flow.c b/net/core/flow.c
74325index e318c7e..168b1d0 100644
74326--- a/net/core/flow.c
74327+++ b/net/core/flow.c
74328@@ -61,7 +61,7 @@ struct flow_cache {
74329 struct timer_list rnd_timer;
74330 };
74331
74332-atomic_t flow_cache_genid = ATOMIC_INIT(0);
74333+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
74334 EXPORT_SYMBOL(flow_cache_genid);
74335 static struct flow_cache flow_cache_global;
74336 static struct kmem_cache *flow_cachep __read_mostly;
74337@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
74338
74339 static int flow_entry_valid(struct flow_cache_entry *fle)
74340 {
74341- if (atomic_read(&flow_cache_genid) != fle->genid)
74342+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
74343 return 0;
74344 if (fle->object && !fle->object->ops->check(fle->object))
74345 return 0;
74346@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
74347 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
74348 fcp->hash_count++;
74349 }
74350- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
74351+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
74352 flo = fle->object;
74353 if (!flo)
74354 goto ret_object;
74355@@ -280,7 +280,7 @@ nocache:
74356 }
74357 flo = resolver(net, key, family, dir, flo, ctx);
74358 if (fle) {
74359- fle->genid = atomic_read(&flow_cache_genid);
74360+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
74361 if (!IS_ERR(flo))
74362 fle->object = flo;
74363 else
74364diff --git a/net/core/iovec.c b/net/core/iovec.c
74365index 7e7aeb0..2a998cb 100644
74366--- a/net/core/iovec.c
74367+++ b/net/core/iovec.c
74368@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
74369 if (m->msg_namelen) {
74370 if (mode == VERIFY_READ) {
74371 void __user *namep;
74372- namep = (void __user __force *) m->msg_name;
74373+ namep = (void __force_user *) m->msg_name;
74374 err = move_addr_to_kernel(namep, m->msg_namelen,
74375 address);
74376 if (err < 0)
74377@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
74378 }
74379
74380 size = m->msg_iovlen * sizeof(struct iovec);
74381- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
74382+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
74383 return -EFAULT;
74384
74385 m->msg_iov = iov;
74386diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
74387index 90430b7..0032ec0 100644
74388--- a/net/core/rtnetlink.c
74389+++ b/net/core/rtnetlink.c
74390@@ -56,7 +56,7 @@ struct rtnl_link {
74391 rtnl_doit_func doit;
74392 rtnl_dumpit_func dumpit;
74393 rtnl_calcit_func calcit;
74394-};
74395+} __no_const;
74396
74397 static DEFINE_MUTEX(rtnl_mutex);
74398
74399diff --git a/net/core/scm.c b/net/core/scm.c
74400index 611c5ef..88f6d6d 100644
74401--- a/net/core/scm.c
74402+++ b/net/core/scm.c
74403@@ -219,7 +219,7 @@ EXPORT_SYMBOL(__scm_send);
74404 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
74405 {
74406 struct cmsghdr __user *cm
74407- = (__force struct cmsghdr __user *)msg->msg_control;
74408+ = (struct cmsghdr __force_user *)msg->msg_control;
74409 struct cmsghdr cmhdr;
74410 int cmlen = CMSG_LEN(len);
74411 int err;
74412@@ -242,7 +242,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
74413 err = -EFAULT;
74414 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
74415 goto out;
74416- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
74417+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
74418 goto out;
74419 cmlen = CMSG_SPACE(len);
74420 if (msg->msg_controllen < cmlen)
74421@@ -258,7 +258,7 @@ EXPORT_SYMBOL(put_cmsg);
74422 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
74423 {
74424 struct cmsghdr __user *cm
74425- = (__force struct cmsghdr __user*)msg->msg_control;
74426+ = (struct cmsghdr __force_user *)msg->msg_control;
74427
74428 int fdmax = 0;
74429 int fdnum = scm->fp->count;
74430@@ -278,7 +278,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
74431 if (fdnum < fdmax)
74432 fdmax = fdnum;
74433
74434- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
74435+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
74436 i++, cmfptr++)
74437 {
74438 int new_fd;
74439diff --git a/net/core/sock.c b/net/core/sock.c
74440index b2e14c0..6651b32 100644
74441--- a/net/core/sock.c
74442+++ b/net/core/sock.c
74443@@ -340,7 +340,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74444 struct sk_buff_head *list = &sk->sk_receive_queue;
74445
74446 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
74447- atomic_inc(&sk->sk_drops);
74448+ atomic_inc_unchecked(&sk->sk_drops);
74449 trace_sock_rcvqueue_full(sk, skb);
74450 return -ENOMEM;
74451 }
74452@@ -350,7 +350,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74453 return err;
74454
74455 if (!sk_rmem_schedule(sk, skb->truesize)) {
74456- atomic_inc(&sk->sk_drops);
74457+ atomic_inc_unchecked(&sk->sk_drops);
74458 return -ENOBUFS;
74459 }
74460
74461@@ -370,7 +370,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74462 skb_dst_force(skb);
74463
74464 spin_lock_irqsave(&list->lock, flags);
74465- skb->dropcount = atomic_read(&sk->sk_drops);
74466+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
74467 __skb_queue_tail(list, skb);
74468 spin_unlock_irqrestore(&list->lock, flags);
74469
74470@@ -390,7 +390,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
74471 skb->dev = NULL;
74472
74473 if (sk_rcvqueues_full(sk, skb)) {
74474- atomic_inc(&sk->sk_drops);
74475+ atomic_inc_unchecked(&sk->sk_drops);
74476 goto discard_and_relse;
74477 }
74478 if (nested)
74479@@ -408,7 +408,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
74480 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
74481 } else if (sk_add_backlog(sk, skb)) {
74482 bh_unlock_sock(sk);
74483- atomic_inc(&sk->sk_drops);
74484+ atomic_inc_unchecked(&sk->sk_drops);
74485 goto discard_and_relse;
74486 }
74487
74488@@ -984,7 +984,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
74489 if (len > sizeof(peercred))
74490 len = sizeof(peercred);
74491 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
74492- if (copy_to_user(optval, &peercred, len))
74493+ if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
74494 return -EFAULT;
74495 goto lenout;
74496 }
74497@@ -997,7 +997,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
74498 return -ENOTCONN;
74499 if (lv < len)
74500 return -EINVAL;
74501- if (copy_to_user(optval, address, len))
74502+ if (len > sizeof(address) || copy_to_user(optval, address, len))
74503 return -EFAULT;
74504 goto lenout;
74505 }
74506@@ -1043,7 +1043,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
74507
74508 if (len > lv)
74509 len = lv;
74510- if (copy_to_user(optval, &v, len))
74511+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
74512 return -EFAULT;
74513 lenout:
74514 if (put_user(len, optlen))
74515@@ -2128,7 +2128,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
74516 */
74517 smp_wmb();
74518 atomic_set(&sk->sk_refcnt, 1);
74519- atomic_set(&sk->sk_drops, 0);
74520+ atomic_set_unchecked(&sk->sk_drops, 0);
74521 }
74522 EXPORT_SYMBOL(sock_init_data);
74523
74524diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
74525index b9868e1..849f809 100644
74526--- a/net/core/sock_diag.c
74527+++ b/net/core/sock_diag.c
74528@@ -16,20 +16,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
74529
74530 int sock_diag_check_cookie(void *sk, __u32 *cookie)
74531 {
74532+#ifndef CONFIG_GRKERNSEC_HIDESYM
74533 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
74534 cookie[1] != INET_DIAG_NOCOOKIE) &&
74535 ((u32)(unsigned long)sk != cookie[0] ||
74536 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
74537 return -ESTALE;
74538 else
74539+#endif
74540 return 0;
74541 }
74542 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
74543
74544 void sock_diag_save_cookie(void *sk, __u32 *cookie)
74545 {
74546+#ifdef CONFIG_GRKERNSEC_HIDESYM
74547+ cookie[0] = 0;
74548+ cookie[1] = 0;
74549+#else
74550 cookie[0] = (u32)(unsigned long)sk;
74551 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
74552+#endif
74553 }
74554 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
74555
74556diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
74557index 02e75d1..9a57a7c 100644
74558--- a/net/decnet/sysctl_net_decnet.c
74559+++ b/net/decnet/sysctl_net_decnet.c
74560@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
74561
74562 if (len > *lenp) len = *lenp;
74563
74564- if (copy_to_user(buffer, addr, len))
74565+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
74566 return -EFAULT;
74567
74568 *lenp = len;
74569@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
74570
74571 if (len > *lenp) len = *lenp;
74572
74573- if (copy_to_user(buffer, devname, len))
74574+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
74575 return -EFAULT;
74576
74577 *lenp = len;
74578diff --git a/net/econet/Kconfig b/net/econet/Kconfig
74579index 39a2d29..f39c0fe 100644
74580--- a/net/econet/Kconfig
74581+++ b/net/econet/Kconfig
74582@@ -4,7 +4,7 @@
74583
74584 config ECONET
74585 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
74586- depends on EXPERIMENTAL && INET
74587+ depends on EXPERIMENTAL && INET && BROKEN
74588 ---help---
74589 Econet is a fairly old and slow networking protocol mainly used by
74590 Acorn computers to access file and print servers. It uses native
74591diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
74592index cbe3a68..a879b75 100644
74593--- a/net/ipv4/fib_frontend.c
74594+++ b/net/ipv4/fib_frontend.c
74595@@ -969,12 +969,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
74596 #ifdef CONFIG_IP_ROUTE_MULTIPATH
74597 fib_sync_up(dev);
74598 #endif
74599- atomic_inc(&net->ipv4.dev_addr_genid);
74600+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
74601 rt_cache_flush(dev_net(dev), -1);
74602 break;
74603 case NETDEV_DOWN:
74604 fib_del_ifaddr(ifa, NULL);
74605- atomic_inc(&net->ipv4.dev_addr_genid);
74606+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
74607 if (ifa->ifa_dev->ifa_list == NULL) {
74608 /* Last address was deleted from this interface.
74609 * Disable IP.
74610@@ -1010,7 +1010,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
74611 #ifdef CONFIG_IP_ROUTE_MULTIPATH
74612 fib_sync_up(dev);
74613 #endif
74614- atomic_inc(&net->ipv4.dev_addr_genid);
74615+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
74616 rt_cache_flush(dev_net(dev), -1);
74617 break;
74618 case NETDEV_DOWN:
74619diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
74620index 8861f91..ab1e3c1 100644
74621--- a/net/ipv4/fib_semantics.c
74622+++ b/net/ipv4/fib_semantics.c
74623@@ -698,7 +698,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
74624 nh->nh_saddr = inet_select_addr(nh->nh_dev,
74625 nh->nh_gw,
74626 nh->nh_parent->fib_scope);
74627- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
74628+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
74629
74630 return nh->nh_saddr;
74631 }
74632diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
74633index 984ec65..97ac518 100644
74634--- a/net/ipv4/inet_hashtables.c
74635+++ b/net/ipv4/inet_hashtables.c
74636@@ -18,12 +18,15 @@
74637 #include <linux/sched.h>
74638 #include <linux/slab.h>
74639 #include <linux/wait.h>
74640+#include <linux/security.h>
74641
74642 #include <net/inet_connection_sock.h>
74643 #include <net/inet_hashtables.h>
74644 #include <net/secure_seq.h>
74645 #include <net/ip.h>
74646
74647+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
74648+
74649 /*
74650 * Allocate and initialize a new local port bind bucket.
74651 * The bindhash mutex for snum's hash chain must be held here.
74652@@ -530,6 +533,8 @@ ok:
74653 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
74654 spin_unlock(&head->lock);
74655
74656+ gr_update_task_in_ip_table(current, inet_sk(sk));
74657+
74658 if (tw) {
74659 inet_twsk_deschedule(tw, death_row);
74660 while (twrefcnt) {
74661diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
74662index d4d61b6..b81aec8 100644
74663--- a/net/ipv4/inetpeer.c
74664+++ b/net/ipv4/inetpeer.c
74665@@ -487,8 +487,8 @@ relookup:
74666 if (p) {
74667 p->daddr = *daddr;
74668 atomic_set(&p->refcnt, 1);
74669- atomic_set(&p->rid, 0);
74670- atomic_set(&p->ip_id_count,
74671+ atomic_set_unchecked(&p->rid, 0);
74672+ atomic_set_unchecked(&p->ip_id_count,
74673 (daddr->family == AF_INET) ?
74674 secure_ip_id(daddr->addr.a4) :
74675 secure_ipv6_id(daddr->addr.a6));
74676diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
74677index 3727e23..517f5df 100644
74678--- a/net/ipv4/ip_fragment.c
74679+++ b/net/ipv4/ip_fragment.c
74680@@ -318,7 +318,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
74681 return 0;
74682
74683 start = qp->rid;
74684- end = atomic_inc_return(&peer->rid);
74685+ end = atomic_inc_return_unchecked(&peer->rid);
74686 qp->rid = end;
74687
74688 rc = qp->q.fragments && (end - start) > max;
74689diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
74690index 2fd0fba..83fac99 100644
74691--- a/net/ipv4/ip_sockglue.c
74692+++ b/net/ipv4/ip_sockglue.c
74693@@ -1137,7 +1137,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
74694 len = min_t(unsigned int, len, opt->optlen);
74695 if (put_user(len, optlen))
74696 return -EFAULT;
74697- if (copy_to_user(optval, opt->__data, len))
74698+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
74699+ copy_to_user(optval, opt->__data, len))
74700 return -EFAULT;
74701 return 0;
74702 }
74703@@ -1268,7 +1269,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
74704 if (sk->sk_type != SOCK_STREAM)
74705 return -ENOPROTOOPT;
74706
74707- msg.msg_control = optval;
74708+ msg.msg_control = (void __force_kernel *)optval;
74709 msg.msg_controllen = len;
74710 msg.msg_flags = flags;
74711
74712diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
74713index 92ac7e7..13f93d9 100644
74714--- a/net/ipv4/ipconfig.c
74715+++ b/net/ipv4/ipconfig.c
74716@@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
74717
74718 mm_segment_t oldfs = get_fs();
74719 set_fs(get_ds());
74720- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
74721+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
74722 set_fs(oldfs);
74723 return res;
74724 }
74725@@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
74726
74727 mm_segment_t oldfs = get_fs();
74728 set_fs(get_ds());
74729- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
74730+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
74731 set_fs(oldfs);
74732 return res;
74733 }
74734@@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
74735
74736 mm_segment_t oldfs = get_fs();
74737 set_fs(get_ds());
74738- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
74739+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
74740 set_fs(oldfs);
74741 return res;
74742 }
74743diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
74744index 50009c7..5996a9f 100644
74745--- a/net/ipv4/ping.c
74746+++ b/net/ipv4/ping.c
74747@@ -838,7 +838,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
74748 sk_rmem_alloc_get(sp),
74749 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
74750 atomic_read(&sp->sk_refcnt), sp,
74751- atomic_read(&sp->sk_drops), len);
74752+ atomic_read_unchecked(&sp->sk_drops), len);
74753 }
74754
74755 static int ping_seq_show(struct seq_file *seq, void *v)
74756diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
74757index bbd604c..4d5469c 100644
74758--- a/net/ipv4/raw.c
74759+++ b/net/ipv4/raw.c
74760@@ -304,7 +304,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
74761 int raw_rcv(struct sock *sk, struct sk_buff *skb)
74762 {
74763 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
74764- atomic_inc(&sk->sk_drops);
74765+ atomic_inc_unchecked(&sk->sk_drops);
74766 kfree_skb(skb);
74767 return NET_RX_DROP;
74768 }
74769@@ -740,16 +740,20 @@ static int raw_init(struct sock *sk)
74770
74771 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
74772 {
74773+ struct icmp_filter filter;
74774+
74775 if (optlen > sizeof(struct icmp_filter))
74776 optlen = sizeof(struct icmp_filter);
74777- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
74778+ if (copy_from_user(&filter, optval, optlen))
74779 return -EFAULT;
74780+ raw_sk(sk)->filter = filter;
74781 return 0;
74782 }
74783
74784 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
74785 {
74786 int len, ret = -EFAULT;
74787+ struct icmp_filter filter;
74788
74789 if (get_user(len, optlen))
74790 goto out;
74791@@ -759,8 +763,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
74792 if (len > sizeof(struct icmp_filter))
74793 len = sizeof(struct icmp_filter);
74794 ret = -EFAULT;
74795- if (put_user(len, optlen) ||
74796- copy_to_user(optval, &raw_sk(sk)->filter, len))
74797+ filter = raw_sk(sk)->filter;
74798+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
74799 goto out;
74800 ret = 0;
74801 out: return ret;
74802@@ -988,7 +992,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
74803 sk_wmem_alloc_get(sp),
74804 sk_rmem_alloc_get(sp),
74805 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
74806- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
74807+ atomic_read(&sp->sk_refcnt),
74808+#ifdef CONFIG_GRKERNSEC_HIDESYM
74809+ NULL,
74810+#else
74811+ sp,
74812+#endif
74813+ atomic_read_unchecked(&sp->sk_drops));
74814 }
74815
74816 static int raw_seq_show(struct seq_file *seq, void *v)
74817diff --git a/net/ipv4/route.c b/net/ipv4/route.c
74818index 167ea10..4b15883 100644
74819--- a/net/ipv4/route.c
74820+++ b/net/ipv4/route.c
74821@@ -312,7 +312,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
74822
74823 static inline int rt_genid(struct net *net)
74824 {
74825- return atomic_read(&net->ipv4.rt_genid);
74826+ return atomic_read_unchecked(&net->ipv4.rt_genid);
74827 }
74828
74829 #ifdef CONFIG_PROC_FS
74830@@ -936,7 +936,7 @@ static void rt_cache_invalidate(struct net *net)
74831 unsigned char shuffle;
74832
74833 get_random_bytes(&shuffle, sizeof(shuffle));
74834- atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
74835+ atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
74836 inetpeer_invalidate_tree(AF_INET);
74837 }
74838
74839@@ -3009,7 +3009,7 @@ static int rt_fill_info(struct net *net,
74840 error = rt->dst.error;
74841 if (peer) {
74842 inet_peer_refcheck(rt->peer);
74843- id = atomic_read(&peer->ip_id_count) & 0xffff;
74844+ id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
74845 if (peer->tcp_ts_stamp) {
74846 ts = peer->tcp_ts;
74847 tsage = get_seconds() - peer->tcp_ts_stamp;
74848diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
74849index 0cb86ce..8e7fda8 100644
74850--- a/net/ipv4/tcp_ipv4.c
74851+++ b/net/ipv4/tcp_ipv4.c
74852@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
74853 EXPORT_SYMBOL(sysctl_tcp_low_latency);
74854
74855
74856+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74857+extern int grsec_enable_blackhole;
74858+#endif
74859+
74860 #ifdef CONFIG_TCP_MD5SIG
74861 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
74862 __be32 daddr, __be32 saddr, const struct tcphdr *th);
74863@@ -1641,6 +1645,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
74864 return 0;
74865
74866 reset:
74867+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74868+ if (!grsec_enable_blackhole)
74869+#endif
74870 tcp_v4_send_reset(rsk, skb);
74871 discard:
74872 kfree_skb(skb);
74873@@ -1703,12 +1710,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
74874 TCP_SKB_CB(skb)->sacked = 0;
74875
74876 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
74877- if (!sk)
74878+ if (!sk) {
74879+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74880+ ret = 1;
74881+#endif
74882 goto no_tcp_socket;
74883-
74884+ }
74885 process:
74886- if (sk->sk_state == TCP_TIME_WAIT)
74887+ if (sk->sk_state == TCP_TIME_WAIT) {
74888+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74889+ ret = 2;
74890+#endif
74891 goto do_time_wait;
74892+ }
74893
74894 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
74895 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
74896@@ -1758,6 +1772,10 @@ no_tcp_socket:
74897 bad_packet:
74898 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
74899 } else {
74900+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74901+ if (!grsec_enable_blackhole || (ret == 1 &&
74902+ (skb->dev->flags & IFF_LOOPBACK)))
74903+#endif
74904 tcp_v4_send_reset(NULL, skb);
74905 }
74906
74907@@ -2419,7 +2437,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
74908 0, /* non standard timer */
74909 0, /* open_requests have no inode */
74910 atomic_read(&sk->sk_refcnt),
74911+#ifdef CONFIG_GRKERNSEC_HIDESYM
74912+ NULL,
74913+#else
74914 req,
74915+#endif
74916 len);
74917 }
74918
74919@@ -2469,7 +2491,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
74920 sock_i_uid(sk),
74921 icsk->icsk_probes_out,
74922 sock_i_ino(sk),
74923- atomic_read(&sk->sk_refcnt), sk,
74924+ atomic_read(&sk->sk_refcnt),
74925+#ifdef CONFIG_GRKERNSEC_HIDESYM
74926+ NULL,
74927+#else
74928+ sk,
74929+#endif
74930 jiffies_to_clock_t(icsk->icsk_rto),
74931 jiffies_to_clock_t(icsk->icsk_ack.ato),
74932 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
74933@@ -2497,7 +2524,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
74934 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
74935 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
74936 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
74937- atomic_read(&tw->tw_refcnt), tw, len);
74938+ atomic_read(&tw->tw_refcnt),
74939+#ifdef CONFIG_GRKERNSEC_HIDESYM
74940+ NULL,
74941+#else
74942+ tw,
74943+#endif
74944+ len);
74945 }
74946
74947 #define TMPSZ 150
74948diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
74949index 3cabafb..640525b 100644
74950--- a/net/ipv4/tcp_minisocks.c
74951+++ b/net/ipv4/tcp_minisocks.c
74952@@ -27,6 +27,10 @@
74953 #include <net/inet_common.h>
74954 #include <net/xfrm.h>
74955
74956+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74957+extern int grsec_enable_blackhole;
74958+#endif
74959+
74960 int sysctl_tcp_syncookies __read_mostly = 1;
74961 EXPORT_SYMBOL(sysctl_tcp_syncookies);
74962
74963@@ -753,6 +757,10 @@ listen_overflow:
74964
74965 embryonic_reset:
74966 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
74967+
74968+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74969+ if (!grsec_enable_blackhole)
74970+#endif
74971 if (!(flg & TCP_FLAG_RST))
74972 req->rsk_ops->send_reset(sk, skb);
74973
74974diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
74975index a981cdc..48f4c3a 100644
74976--- a/net/ipv4/tcp_probe.c
74977+++ b/net/ipv4/tcp_probe.c
74978@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
74979 if (cnt + width >= len)
74980 break;
74981
74982- if (copy_to_user(buf + cnt, tbuf, width))
74983+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
74984 return -EFAULT;
74985 cnt += width;
74986 }
74987diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
74988index 34d4a02..3b57f86 100644
74989--- a/net/ipv4/tcp_timer.c
74990+++ b/net/ipv4/tcp_timer.c
74991@@ -22,6 +22,10 @@
74992 #include <linux/gfp.h>
74993 #include <net/tcp.h>
74994
74995+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74996+extern int grsec_lastack_retries;
74997+#endif
74998+
74999 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
75000 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
75001 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
75002@@ -196,6 +200,13 @@ static int tcp_write_timeout(struct sock *sk)
75003 }
75004 }
75005
75006+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75007+ if ((sk->sk_state == TCP_LAST_ACK) &&
75008+ (grsec_lastack_retries > 0) &&
75009+ (grsec_lastack_retries < retry_until))
75010+ retry_until = grsec_lastack_retries;
75011+#endif
75012+
75013 if (retransmits_timed_out(sk, retry_until,
75014 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
75015 /* Has it gone just too far? */
75016diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
75017index fe14105..0618260 100644
75018--- a/net/ipv4/udp.c
75019+++ b/net/ipv4/udp.c
75020@@ -87,6 +87,7 @@
75021 #include <linux/types.h>
75022 #include <linux/fcntl.h>
75023 #include <linux/module.h>
75024+#include <linux/security.h>
75025 #include <linux/socket.h>
75026 #include <linux/sockios.h>
75027 #include <linux/igmp.h>
75028@@ -109,6 +110,10 @@
75029 #include <trace/events/udp.h>
75030 #include "udp_impl.h"
75031
75032+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75033+extern int grsec_enable_blackhole;
75034+#endif
75035+
75036 struct udp_table udp_table __read_mostly;
75037 EXPORT_SYMBOL(udp_table);
75038
75039@@ -567,6 +572,9 @@ found:
75040 return s;
75041 }
75042
75043+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
75044+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
75045+
75046 /*
75047 * This routine is called by the ICMP module when it gets some
75048 * sort of error condition. If err < 0 then the socket should
75049@@ -858,9 +866,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
75050 dport = usin->sin_port;
75051 if (dport == 0)
75052 return -EINVAL;
75053+
75054+ err = gr_search_udp_sendmsg(sk, usin);
75055+ if (err)
75056+ return err;
75057 } else {
75058 if (sk->sk_state != TCP_ESTABLISHED)
75059 return -EDESTADDRREQ;
75060+
75061+ err = gr_search_udp_sendmsg(sk, NULL);
75062+ if (err)
75063+ return err;
75064+
75065 daddr = inet->inet_daddr;
75066 dport = inet->inet_dport;
75067 /* Open fast path for connected socket.
75068@@ -1102,7 +1119,7 @@ static unsigned int first_packet_length(struct sock *sk)
75069 udp_lib_checksum_complete(skb)) {
75070 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
75071 IS_UDPLITE(sk));
75072- atomic_inc(&sk->sk_drops);
75073+ atomic_inc_unchecked(&sk->sk_drops);
75074 __skb_unlink(skb, rcvq);
75075 __skb_queue_tail(&list_kill, skb);
75076 }
75077@@ -1188,6 +1205,10 @@ try_again:
75078 if (!skb)
75079 goto out;
75080
75081+ err = gr_search_udp_recvmsg(sk, skb);
75082+ if (err)
75083+ goto out_free;
75084+
75085 ulen = skb->len - sizeof(struct udphdr);
75086 copied = len;
75087 if (copied > ulen)
75088@@ -1489,7 +1510,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75089
75090 drop:
75091 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
75092- atomic_inc(&sk->sk_drops);
75093+ atomic_inc_unchecked(&sk->sk_drops);
75094 kfree_skb(skb);
75095 return -1;
75096 }
75097@@ -1508,7 +1529,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
75098 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
75099
75100 if (!skb1) {
75101- atomic_inc(&sk->sk_drops);
75102+ atomic_inc_unchecked(&sk->sk_drops);
75103 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
75104 IS_UDPLITE(sk));
75105 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
75106@@ -1677,6 +1698,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
75107 goto csum_error;
75108
75109 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
75110+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75111+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
75112+#endif
75113 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
75114
75115 /*
75116@@ -2094,8 +2118,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
75117 sk_wmem_alloc_get(sp),
75118 sk_rmem_alloc_get(sp),
75119 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75120- atomic_read(&sp->sk_refcnt), sp,
75121- atomic_read(&sp->sk_drops), len);
75122+ atomic_read(&sp->sk_refcnt),
75123+#ifdef CONFIG_GRKERNSEC_HIDESYM
75124+ NULL,
75125+#else
75126+ sp,
75127+#endif
75128+ atomic_read_unchecked(&sp->sk_drops), len);
75129 }
75130
75131 int udp4_seq_show(struct seq_file *seq, void *v)
75132diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
75133index 7d5cb97..c56564f 100644
75134--- a/net/ipv6/addrconf.c
75135+++ b/net/ipv6/addrconf.c
75136@@ -2142,7 +2142,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
75137 p.iph.ihl = 5;
75138 p.iph.protocol = IPPROTO_IPV6;
75139 p.iph.ttl = 64;
75140- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
75141+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
75142
75143 if (ops->ndo_do_ioctl) {
75144 mm_segment_t oldfs = get_fs();
75145diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
75146index 02dd203..e03fcc9 100644
75147--- a/net/ipv6/inet6_connection_sock.c
75148+++ b/net/ipv6/inet6_connection_sock.c
75149@@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
75150 #ifdef CONFIG_XFRM
75151 {
75152 struct rt6_info *rt = (struct rt6_info *)dst;
75153- rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
75154+ rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
75155 }
75156 #endif
75157 }
75158@@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
75159 #ifdef CONFIG_XFRM
75160 if (dst) {
75161 struct rt6_info *rt = (struct rt6_info *)dst;
75162- if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
75163+ if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
75164 __sk_dst_reset(sk);
75165 dst = NULL;
75166 }
75167diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
75168index 63dd1f8..e7f53ca 100644
75169--- a/net/ipv6/ipv6_sockglue.c
75170+++ b/net/ipv6/ipv6_sockglue.c
75171@@ -990,7 +990,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
75172 if (sk->sk_type != SOCK_STREAM)
75173 return -ENOPROTOOPT;
75174
75175- msg.msg_control = optval;
75176+ msg.msg_control = (void __force_kernel *)optval;
75177 msg.msg_controllen = len;
75178 msg.msg_flags = flags;
75179
75180diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
75181index 5bddea7..82d9d67 100644
75182--- a/net/ipv6/raw.c
75183+++ b/net/ipv6/raw.c
75184@@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
75185 {
75186 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
75187 skb_checksum_complete(skb)) {
75188- atomic_inc(&sk->sk_drops);
75189+ atomic_inc_unchecked(&sk->sk_drops);
75190 kfree_skb(skb);
75191 return NET_RX_DROP;
75192 }
75193@@ -405,7 +405,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
75194 struct raw6_sock *rp = raw6_sk(sk);
75195
75196 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
75197- atomic_inc(&sk->sk_drops);
75198+ atomic_inc_unchecked(&sk->sk_drops);
75199 kfree_skb(skb);
75200 return NET_RX_DROP;
75201 }
75202@@ -429,7 +429,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
75203
75204 if (inet->hdrincl) {
75205 if (skb_checksum_complete(skb)) {
75206- atomic_inc(&sk->sk_drops);
75207+ atomic_inc_unchecked(&sk->sk_drops);
75208 kfree_skb(skb);
75209 return NET_RX_DROP;
75210 }
75211@@ -602,7 +602,7 @@ out:
75212 return err;
75213 }
75214
75215-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
75216+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
75217 struct flowi6 *fl6, struct dst_entry **dstp,
75218 unsigned int flags)
75219 {
75220@@ -914,12 +914,15 @@ do_confirm:
75221 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
75222 char __user *optval, int optlen)
75223 {
75224+ struct icmp6_filter filter;
75225+
75226 switch (optname) {
75227 case ICMPV6_FILTER:
75228 if (optlen > sizeof(struct icmp6_filter))
75229 optlen = sizeof(struct icmp6_filter);
75230- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
75231+ if (copy_from_user(&filter, optval, optlen))
75232 return -EFAULT;
75233+ raw6_sk(sk)->filter = filter;
75234 return 0;
75235 default:
75236 return -ENOPROTOOPT;
75237@@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
75238 char __user *optval, int __user *optlen)
75239 {
75240 int len;
75241+ struct icmp6_filter filter;
75242
75243 switch (optname) {
75244 case ICMPV6_FILTER:
75245@@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
75246 len = sizeof(struct icmp6_filter);
75247 if (put_user(len, optlen))
75248 return -EFAULT;
75249- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
75250+ filter = raw6_sk(sk)->filter;
75251+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
75252 return -EFAULT;
75253 return 0;
75254 default:
75255@@ -1250,7 +1255,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
75256 0, 0L, 0,
75257 sock_i_uid(sp), 0,
75258 sock_i_ino(sp),
75259- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
75260+ atomic_read(&sp->sk_refcnt),
75261+#ifdef CONFIG_GRKERNSEC_HIDESYM
75262+ NULL,
75263+#else
75264+ sp,
75265+#endif
75266+ atomic_read_unchecked(&sp->sk_drops));
75267 }
75268
75269 static int raw6_seq_show(struct seq_file *seq, void *v)
75270diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
75271index 98256cf..7f16dbd 100644
75272--- a/net/ipv6/tcp_ipv6.c
75273+++ b/net/ipv6/tcp_ipv6.c
75274@@ -94,6 +94,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
75275 }
75276 #endif
75277
75278+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75279+extern int grsec_enable_blackhole;
75280+#endif
75281+
75282 static void tcp_v6_hash(struct sock *sk)
75283 {
75284 if (sk->sk_state != TCP_CLOSE) {
75285@@ -1542,6 +1546,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
75286 return 0;
75287
75288 reset:
75289+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75290+ if (!grsec_enable_blackhole)
75291+#endif
75292 tcp_v6_send_reset(sk, skb);
75293 discard:
75294 if (opt_skb)
75295@@ -1623,12 +1630,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
75296 TCP_SKB_CB(skb)->sacked = 0;
75297
75298 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
75299- if (!sk)
75300+ if (!sk) {
75301+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75302+ ret = 1;
75303+#endif
75304 goto no_tcp_socket;
75305+ }
75306
75307 process:
75308- if (sk->sk_state == TCP_TIME_WAIT)
75309+ if (sk->sk_state == TCP_TIME_WAIT) {
75310+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75311+ ret = 2;
75312+#endif
75313 goto do_time_wait;
75314+ }
75315
75316 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
75317 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
75318@@ -1676,6 +1691,10 @@ no_tcp_socket:
75319 bad_packet:
75320 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
75321 } else {
75322+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75323+ if (!grsec_enable_blackhole || (ret == 1 &&
75324+ (skb->dev->flags & IFF_LOOPBACK)))
75325+#endif
75326 tcp_v6_send_reset(NULL, skb);
75327 }
75328
75329@@ -1930,7 +1949,13 @@ static void get_openreq6(struct seq_file *seq,
75330 uid,
75331 0, /* non standard timer */
75332 0, /* open_requests have no inode */
75333- 0, req);
75334+ 0,
75335+#ifdef CONFIG_GRKERNSEC_HIDESYM
75336+ NULL
75337+#else
75338+ req
75339+#endif
75340+ );
75341 }
75342
75343 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
75344@@ -1980,7 +2005,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
75345 sock_i_uid(sp),
75346 icsk->icsk_probes_out,
75347 sock_i_ino(sp),
75348- atomic_read(&sp->sk_refcnt), sp,
75349+ atomic_read(&sp->sk_refcnt),
75350+#ifdef CONFIG_GRKERNSEC_HIDESYM
75351+ NULL,
75352+#else
75353+ sp,
75354+#endif
75355 jiffies_to_clock_t(icsk->icsk_rto),
75356 jiffies_to_clock_t(icsk->icsk_ack.ato),
75357 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
75358@@ -2015,7 +2045,13 @@ static void get_timewait6_sock(struct seq_file *seq,
75359 dest->s6_addr32[2], dest->s6_addr32[3], destp,
75360 tw->tw_substate, 0, 0,
75361 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
75362- atomic_read(&tw->tw_refcnt), tw);
75363+ atomic_read(&tw->tw_refcnt),
75364+#ifdef CONFIG_GRKERNSEC_HIDESYM
75365+ NULL
75366+#else
75367+ tw
75368+#endif
75369+ );
75370 }
75371
75372 static int tcp6_seq_show(struct seq_file *seq, void *v)
75373diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
75374index 37b0699..d323408 100644
75375--- a/net/ipv6/udp.c
75376+++ b/net/ipv6/udp.c
75377@@ -50,6 +50,10 @@
75378 #include <linux/seq_file.h>
75379 #include "udp_impl.h"
75380
75381+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75382+extern int grsec_enable_blackhole;
75383+#endif
75384+
75385 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
75386 {
75387 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
75388@@ -551,7 +555,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
75389
75390 return 0;
75391 drop:
75392- atomic_inc(&sk->sk_drops);
75393+ atomic_inc_unchecked(&sk->sk_drops);
75394 drop_no_sk_drops_inc:
75395 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
75396 kfree_skb(skb);
75397@@ -627,7 +631,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
75398 continue;
75399 }
75400 drop:
75401- atomic_inc(&sk->sk_drops);
75402+ atomic_inc_unchecked(&sk->sk_drops);
75403 UDP6_INC_STATS_BH(sock_net(sk),
75404 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
75405 UDP6_INC_STATS_BH(sock_net(sk),
75406@@ -782,6 +786,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
75407 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
75408 proto == IPPROTO_UDPLITE);
75409
75410+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75411+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
75412+#endif
75413 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
75414
75415 kfree_skb(skb);
75416@@ -798,7 +805,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
75417 if (!sock_owned_by_user(sk))
75418 udpv6_queue_rcv_skb(sk, skb);
75419 else if (sk_add_backlog(sk, skb)) {
75420- atomic_inc(&sk->sk_drops);
75421+ atomic_inc_unchecked(&sk->sk_drops);
75422 bh_unlock_sock(sk);
75423 sock_put(sk);
75424 goto discard;
75425@@ -1411,8 +1418,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
75426 0, 0L, 0,
75427 sock_i_uid(sp), 0,
75428 sock_i_ino(sp),
75429- atomic_read(&sp->sk_refcnt), sp,
75430- atomic_read(&sp->sk_drops));
75431+ atomic_read(&sp->sk_refcnt),
75432+#ifdef CONFIG_GRKERNSEC_HIDESYM
75433+ NULL,
75434+#else
75435+ sp,
75436+#endif
75437+ atomic_read_unchecked(&sp->sk_drops));
75438 }
75439
75440 int udp6_seq_show(struct seq_file *seq, void *v)
75441diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
75442index 6b9d5a0..4dffaf1 100644
75443--- a/net/irda/ircomm/ircomm_tty.c
75444+++ b/net/irda/ircomm/ircomm_tty.c
75445@@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
75446 add_wait_queue(&self->open_wait, &wait);
75447
75448 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
75449- __FILE__,__LINE__, tty->driver->name, self->open_count );
75450+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
75451
75452 /* As far as I can see, we protect open_count - Jean II */
75453 spin_lock_irqsave(&self->spinlock, flags);
75454 if (!tty_hung_up_p(filp)) {
75455 extra_count = 1;
75456- self->open_count--;
75457+ local_dec(&self->open_count);
75458 }
75459 spin_unlock_irqrestore(&self->spinlock, flags);
75460- self->blocked_open++;
75461+ local_inc(&self->blocked_open);
75462
75463 while (1) {
75464 if (tty->termios->c_cflag & CBAUD) {
75465@@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
75466 }
75467
75468 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
75469- __FILE__,__LINE__, tty->driver->name, self->open_count );
75470+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
75471
75472 schedule();
75473 }
75474@@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
75475 if (extra_count) {
75476 /* ++ is not atomic, so this should be protected - Jean II */
75477 spin_lock_irqsave(&self->spinlock, flags);
75478- self->open_count++;
75479+ local_inc(&self->open_count);
75480 spin_unlock_irqrestore(&self->spinlock, flags);
75481 }
75482- self->blocked_open--;
75483+ local_dec(&self->blocked_open);
75484
75485 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
75486- __FILE__,__LINE__, tty->driver->name, self->open_count);
75487+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
75488
75489 if (!retval)
75490 self->flags |= ASYNC_NORMAL_ACTIVE;
75491@@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
75492 }
75493 /* ++ is not atomic, so this should be protected - Jean II */
75494 spin_lock_irqsave(&self->spinlock, flags);
75495- self->open_count++;
75496+ local_inc(&self->open_count);
75497
75498 tty->driver_data = self;
75499 self->tty = tty;
75500 spin_unlock_irqrestore(&self->spinlock, flags);
75501
75502 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
75503- self->line, self->open_count);
75504+ self->line, local_read(&self->open_count));
75505
75506 /* Not really used by us, but lets do it anyway */
75507 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
75508@@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
75509 return;
75510 }
75511
75512- if ((tty->count == 1) && (self->open_count != 1)) {
75513+ if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
75514 /*
75515 * Uh, oh. tty->count is 1, which means that the tty
75516 * structure will be freed. state->count should always
75517@@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
75518 */
75519 IRDA_DEBUG(0, "%s(), bad serial port count; "
75520 "tty->count is 1, state->count is %d\n", __func__ ,
75521- self->open_count);
75522- self->open_count = 1;
75523+ local_read(&self->open_count));
75524+ local_set(&self->open_count, 1);
75525 }
75526
75527- if (--self->open_count < 0) {
75528+ if (local_dec_return(&self->open_count) < 0) {
75529 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
75530- __func__, self->line, self->open_count);
75531- self->open_count = 0;
75532+ __func__, self->line, local_read(&self->open_count));
75533+ local_set(&self->open_count, 0);
75534 }
75535- if (self->open_count) {
75536+ if (local_read(&self->open_count)) {
75537 spin_unlock_irqrestore(&self->spinlock, flags);
75538
75539 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
75540@@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
75541 tty->closing = 0;
75542 self->tty = NULL;
75543
75544- if (self->blocked_open) {
75545+ if (local_read(&self->blocked_open)) {
75546 if (self->close_delay)
75547 schedule_timeout_interruptible(self->close_delay);
75548 wake_up_interruptible(&self->open_wait);
75549@@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
75550 spin_lock_irqsave(&self->spinlock, flags);
75551 self->flags &= ~ASYNC_NORMAL_ACTIVE;
75552 self->tty = NULL;
75553- self->open_count = 0;
75554+ local_set(&self->open_count, 0);
75555 spin_unlock_irqrestore(&self->spinlock, flags);
75556
75557 wake_up_interruptible(&self->open_wait);
75558@@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
75559 seq_putc(m, '\n');
75560
75561 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
75562- seq_printf(m, "Open count: %d\n", self->open_count);
75563+ seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
75564 seq_printf(m, "Max data size: %d\n", self->max_data_size);
75565 seq_printf(m, "Max header size: %d\n", self->max_header_size);
75566
75567diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
75568index 07d7d55..541de95 100644
75569--- a/net/iucv/af_iucv.c
75570+++ b/net/iucv/af_iucv.c
75571@@ -783,10 +783,10 @@ static int iucv_sock_autobind(struct sock *sk)
75572
75573 write_lock_bh(&iucv_sk_list.lock);
75574
75575- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
75576+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
75577 while (__iucv_get_sock_by_name(name)) {
75578 sprintf(name, "%08x",
75579- atomic_inc_return(&iucv_sk_list.autobind_name));
75580+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
75581 }
75582
75583 write_unlock_bh(&iucv_sk_list.lock);
75584diff --git a/net/key/af_key.c b/net/key/af_key.c
75585index 7e5d927..cdbb54e 100644
75586--- a/net/key/af_key.c
75587+++ b/net/key/af_key.c
75588@@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
75589 static u32 get_acqseq(void)
75590 {
75591 u32 res;
75592- static atomic_t acqseq;
75593+ static atomic_unchecked_t acqseq;
75594
75595 do {
75596- res = atomic_inc_return(&acqseq);
75597+ res = atomic_inc_return_unchecked(&acqseq);
75598 } while (!res);
75599 return res;
75600 }
75601diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
75602index db8fae5..ff070cd 100644
75603--- a/net/mac80211/ieee80211_i.h
75604+++ b/net/mac80211/ieee80211_i.h
75605@@ -28,6 +28,7 @@
75606 #include <net/ieee80211_radiotap.h>
75607 #include <net/cfg80211.h>
75608 #include <net/mac80211.h>
75609+#include <asm/local.h>
75610 #include "key.h"
75611 #include "sta_info.h"
75612
75613@@ -842,7 +843,7 @@ struct ieee80211_local {
75614 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
75615 spinlock_t queue_stop_reason_lock;
75616
75617- int open_count;
75618+ local_t open_count;
75619 int monitors, cooked_mntrs;
75620 /* number of interfaces with corresponding FIF_ flags */
75621 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
75622diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
75623index 48f937e..4ccd7b8 100644
75624--- a/net/mac80211/iface.c
75625+++ b/net/mac80211/iface.c
75626@@ -222,7 +222,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75627 break;
75628 }
75629
75630- if (local->open_count == 0) {
75631+ if (local_read(&local->open_count) == 0) {
75632 res = drv_start(local);
75633 if (res)
75634 goto err_del_bss;
75635@@ -246,7 +246,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75636 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
75637
75638 if (!is_valid_ether_addr(dev->dev_addr)) {
75639- if (!local->open_count)
75640+ if (!local_read(&local->open_count))
75641 drv_stop(local);
75642 return -EADDRNOTAVAIL;
75643 }
75644@@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75645 mutex_unlock(&local->mtx);
75646
75647 if (coming_up)
75648- local->open_count++;
75649+ local_inc(&local->open_count);
75650
75651 if (hw_reconf_flags)
75652 ieee80211_hw_config(local, hw_reconf_flags);
75653@@ -360,7 +360,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75654 err_del_interface:
75655 drv_remove_interface(local, sdata);
75656 err_stop:
75657- if (!local->open_count)
75658+ if (!local_read(&local->open_count))
75659 drv_stop(local);
75660 err_del_bss:
75661 sdata->bss = NULL;
75662@@ -491,7 +491,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
75663 }
75664
75665 if (going_down)
75666- local->open_count--;
75667+ local_dec(&local->open_count);
75668
75669 switch (sdata->vif.type) {
75670 case NL80211_IFTYPE_AP_VLAN:
75671@@ -562,7 +562,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
75672
75673 ieee80211_recalc_ps(local, -1);
75674
75675- if (local->open_count == 0) {
75676+ if (local_read(&local->open_count) == 0) {
75677 if (local->ops->napi_poll)
75678 napi_disable(&local->napi);
75679 ieee80211_clear_tx_pending(local);
75680diff --git a/net/mac80211/main.c b/net/mac80211/main.c
75681index 1633648..d45ebfa 100644
75682--- a/net/mac80211/main.c
75683+++ b/net/mac80211/main.c
75684@@ -164,7 +164,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
75685 local->hw.conf.power_level = power;
75686 }
75687
75688- if (changed && local->open_count) {
75689+ if (changed && local_read(&local->open_count)) {
75690 ret = drv_config(local, changed);
75691 /*
75692 * Goal:
75693diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
75694index ef8eba1..5c63952 100644
75695--- a/net/mac80211/pm.c
75696+++ b/net/mac80211/pm.c
75697@@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
75698 struct ieee80211_sub_if_data *sdata;
75699 struct sta_info *sta;
75700
75701- if (!local->open_count)
75702+ if (!local_read(&local->open_count))
75703 goto suspend;
75704
75705 ieee80211_scan_cancel(local);
75706@@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
75707 cancel_work_sync(&local->dynamic_ps_enable_work);
75708 del_timer_sync(&local->dynamic_ps_timer);
75709
75710- local->wowlan = wowlan && local->open_count;
75711+ local->wowlan = wowlan && local_read(&local->open_count);
75712 if (local->wowlan) {
75713 int err = drv_suspend(local, wowlan);
75714 if (err < 0) {
75715@@ -128,7 +128,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
75716 }
75717
75718 /* stop hardware - this must stop RX */
75719- if (local->open_count)
75720+ if (local_read(&local->open_count))
75721 ieee80211_stop_device(local);
75722
75723 suspend:
75724diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
75725index 3313c11..bec9f17 100644
75726--- a/net/mac80211/rate.c
75727+++ b/net/mac80211/rate.c
75728@@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
75729
75730 ASSERT_RTNL();
75731
75732- if (local->open_count)
75733+ if (local_read(&local->open_count))
75734 return -EBUSY;
75735
75736 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
75737diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
75738index c97a065..ff61928 100644
75739--- a/net/mac80211/rc80211_pid_debugfs.c
75740+++ b/net/mac80211/rc80211_pid_debugfs.c
75741@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
75742
75743 spin_unlock_irqrestore(&events->lock, status);
75744
75745- if (copy_to_user(buf, pb, p))
75746+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
75747 return -EFAULT;
75748
75749 return p;
75750diff --git a/net/mac80211/util.c b/net/mac80211/util.c
75751index eb9d7c0..d34b832 100644
75752--- a/net/mac80211/util.c
75753+++ b/net/mac80211/util.c
75754@@ -1179,7 +1179,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
75755 }
75756 #endif
75757 /* everything else happens only if HW was up & running */
75758- if (!local->open_count)
75759+ if (!local_read(&local->open_count))
75760 goto wake_up;
75761
75762 /*
75763diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
75764index 0c6f67e..d02cdfc 100644
75765--- a/net/netfilter/Kconfig
75766+++ b/net/netfilter/Kconfig
75767@@ -836,6 +836,16 @@ config NETFILTER_XT_MATCH_ESP
75768
75769 To compile it as a module, choose M here. If unsure, say N.
75770
75771+config NETFILTER_XT_MATCH_GRADM
75772+ tristate '"gradm" match support'
75773+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
75774+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
75775+ ---help---
75776+ The gradm match allows to match on grsecurity RBAC being enabled.
75777+ It is useful when iptables rules are applied early on bootup to
75778+ prevent connections to the machine (except from a trusted host)
75779+ while the RBAC system is disabled.
75780+
75781 config NETFILTER_XT_MATCH_HASHLIMIT
75782 tristate '"hashlimit" match support'
75783 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
75784diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
75785index ca36765..0882e7c 100644
75786--- a/net/netfilter/Makefile
75787+++ b/net/netfilter/Makefile
75788@@ -86,6 +86,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
75789 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
75790 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
75791 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
75792+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
75793 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
75794 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
75795 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
75796diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
75797index 29fa5ba..8debc79 100644
75798--- a/net/netfilter/ipvs/ip_vs_conn.c
75799+++ b/net/netfilter/ipvs/ip_vs_conn.c
75800@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
75801 /* Increase the refcnt counter of the dest */
75802 atomic_inc(&dest->refcnt);
75803
75804- conn_flags = atomic_read(&dest->conn_flags);
75805+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
75806 if (cp->protocol != IPPROTO_UDP)
75807 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
75808 /* Bind with the destination and its corresponding transmitter */
75809@@ -869,7 +869,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
75810 atomic_set(&cp->refcnt, 1);
75811
75812 atomic_set(&cp->n_control, 0);
75813- atomic_set(&cp->in_pkts, 0);
75814+ atomic_set_unchecked(&cp->in_pkts, 0);
75815
75816 atomic_inc(&ipvs->conn_count);
75817 if (flags & IP_VS_CONN_F_NO_CPORT)
75818@@ -1149,7 +1149,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
75819
75820 /* Don't drop the entry if its number of incoming packets is not
75821 located in [0, 8] */
75822- i = atomic_read(&cp->in_pkts);
75823+ i = atomic_read_unchecked(&cp->in_pkts);
75824 if (i > 8 || i < 0) return 0;
75825
75826 if (!todrop_rate[i]) return 0;
75827diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
75828index 00bdb1d..6725a48 100644
75829--- a/net/netfilter/ipvs/ip_vs_core.c
75830+++ b/net/netfilter/ipvs/ip_vs_core.c
75831@@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
75832 ret = cp->packet_xmit(skb, cp, pd->pp);
75833 /* do not touch skb anymore */
75834
75835- atomic_inc(&cp->in_pkts);
75836+ atomic_inc_unchecked(&cp->in_pkts);
75837 ip_vs_conn_put(cp);
75838 return ret;
75839 }
75840@@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
75841 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
75842 pkts = sysctl_sync_threshold(ipvs);
75843 else
75844- pkts = atomic_add_return(1, &cp->in_pkts);
75845+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
75846
75847 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
75848 cp->protocol == IPPROTO_SCTP) {
75849diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
75850index f558998..9cdff60 100644
75851--- a/net/netfilter/ipvs/ip_vs_ctl.c
75852+++ b/net/netfilter/ipvs/ip_vs_ctl.c
75853@@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
75854 ip_vs_rs_hash(ipvs, dest);
75855 write_unlock_bh(&ipvs->rs_lock);
75856 }
75857- atomic_set(&dest->conn_flags, conn_flags);
75858+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
75859
75860 /* bind the service */
75861 if (!dest->svc) {
75862@@ -2028,7 +2028,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
75863 " %-7s %-6d %-10d %-10d\n",
75864 &dest->addr.in6,
75865 ntohs(dest->port),
75866- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
75867+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
75868 atomic_read(&dest->weight),
75869 atomic_read(&dest->activeconns),
75870 atomic_read(&dest->inactconns));
75871@@ -2039,7 +2039,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
75872 "%-7s %-6d %-10d %-10d\n",
75873 ntohl(dest->addr.ip),
75874 ntohs(dest->port),
75875- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
75876+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
75877 atomic_read(&dest->weight),
75878 atomic_read(&dest->activeconns),
75879 atomic_read(&dest->inactconns));
75880@@ -2509,7 +2509,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
75881
75882 entry.addr = dest->addr.ip;
75883 entry.port = dest->port;
75884- entry.conn_flags = atomic_read(&dest->conn_flags);
75885+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
75886 entry.weight = atomic_read(&dest->weight);
75887 entry.u_threshold = dest->u_threshold;
75888 entry.l_threshold = dest->l_threshold;
75889@@ -3042,7 +3042,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
75890 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
75891
75892 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
75893- atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
75894+ atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
75895 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
75896 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
75897 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
75898diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
75899index 8a0d6d6..90ec197 100644
75900--- a/net/netfilter/ipvs/ip_vs_sync.c
75901+++ b/net/netfilter/ipvs/ip_vs_sync.c
75902@@ -649,7 +649,7 @@ control:
75903 * i.e only increment in_pkts for Templates.
75904 */
75905 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
75906- int pkts = atomic_add_return(1, &cp->in_pkts);
75907+ int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
75908
75909 if (pkts % sysctl_sync_period(ipvs) != 1)
75910 return;
75911@@ -795,7 +795,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
75912
75913 if (opt)
75914 memcpy(&cp->in_seq, opt, sizeof(*opt));
75915- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
75916+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
75917 cp->state = state;
75918 cp->old_state = cp->state;
75919 /*
75920diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
75921index 7fd66de..e6fb361 100644
75922--- a/net/netfilter/ipvs/ip_vs_xmit.c
75923+++ b/net/netfilter/ipvs/ip_vs_xmit.c
75924@@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
75925 else
75926 rc = NF_ACCEPT;
75927 /* do not touch skb anymore */
75928- atomic_inc(&cp->in_pkts);
75929+ atomic_inc_unchecked(&cp->in_pkts);
75930 goto out;
75931 }
75932
75933@@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
75934 else
75935 rc = NF_ACCEPT;
75936 /* do not touch skb anymore */
75937- atomic_inc(&cp->in_pkts);
75938+ atomic_inc_unchecked(&cp->in_pkts);
75939 goto out;
75940 }
75941
75942diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
75943index 66b2c54..c7884e3 100644
75944--- a/net/netfilter/nfnetlink_log.c
75945+++ b/net/netfilter/nfnetlink_log.c
75946@@ -70,7 +70,7 @@ struct nfulnl_instance {
75947 };
75948
75949 static DEFINE_SPINLOCK(instances_lock);
75950-static atomic_t global_seq;
75951+static atomic_unchecked_t global_seq;
75952
75953 #define INSTANCE_BUCKETS 16
75954 static struct hlist_head instance_table[INSTANCE_BUCKETS];
75955@@ -502,7 +502,7 @@ __build_packet_message(struct nfulnl_instance *inst,
75956 /* global sequence number */
75957 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
75958 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
75959- htonl(atomic_inc_return(&global_seq)));
75960+ htonl(atomic_inc_return_unchecked(&global_seq)));
75961
75962 if (data_len) {
75963 struct nlattr *nla;
75964diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
75965new file mode 100644
75966index 0000000..6905327
75967--- /dev/null
75968+++ b/net/netfilter/xt_gradm.c
75969@@ -0,0 +1,51 @@
75970+/*
75971+ * gradm match for netfilter
75972